From 927d2fa1783c8016bbda8ce09b8dd7fc16391ed3 Mon Sep 17 00:00:00 2001 From: ianflexa Date: Mon, 4 Nov 2024 05:55:44 -0400 Subject: [PATCH] feat: weETH, sUSDS, USDSe capo --- scripts/DeployZkSync.s.sol | 90 +++++++++++++++++++ src/contracts/CLRatePriceCapAdapter.sol | 2 +- tests/utils/GetExchangeRatesTest.t.sol | 22 +++++ .../USDePriceCapAdapterZkSyncTest.t.sol | 32 +++++++ .../sUSDePriceCapAdapterZkSyncTest.t.sol | 46 ++++++++++ .../weETHPriceCapAdapterZkSyncTest.t.sol | 46 ++++++++++ 6 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 scripts/DeployZkSync.s.sol create mode 100644 tests/zksync/USDePriceCapAdapterZkSyncTest.t.sol create mode 100644 tests/zksync/sUSDePriceCapAdapterZkSyncTest.t.sol create mode 100644 tests/zksync/weETHPriceCapAdapterZkSyncTest.t.sol diff --git a/scripts/DeployZkSync.s.sol b/scripts/DeployZkSync.s.sol new file mode 100644 index 0000000..b6c94ec --- /dev/null +++ b/scripts/DeployZkSync.s.sol @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.0; +import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol'; +import {ZkSyncScript} from 'solidity-utils/contracts/utils/ScriptUtils.sol'; +import {CLRatePriceCapAdapter} from '../src/contracts/CLRatePriceCapAdapter.sol'; +import {AaveV3ZkSync, AaveV3ZkSyncAssets} from 'aave-address-book/AaveV3ZkSync.sol'; +import {PriceCapAdapterStable} from '../src/contracts/PriceCapAdapterStable.sol'; +import {IPriceCapAdapterStable} from '../src/interfaces/IPriceCapAdapterStable.sol'; +import {IPriceCapAdapter, IChainlinkAggregator} from '../src/interfaces/IPriceCapAdapter.sol'; + +library CapAdaptersCodeZkSync { + address public constant weETH_eETH_AGGREGATOR = 0x8D3184a992f93729b249407C33F1e78abE0d650e; + address public constant sUSDe_USDe_AGGREGATOR = 0x97920183c36B022B46D6C14b9dA36c5f31A98C6A; + address public constant USDe_PRICE_FEED = 0x4899faF0b6c36620168D00e3DbD4CB9361244c4d; + + function weETHAdapterCode() internal pure returns (bytes memory) { + return + abi.encode( + IPriceCapAdapter.CapAdapterParams({ + aclManager: AaveV3ZkSync.ACL_MANAGER, + baseAggregatorAddress: AaveV3ZkSyncAssets.WETH_ORACLE, + ratioProviderAddress: weETH_eETH_AGGREGATOR, + pairDescription: 'Capped weETH / eETH(ETH) / USD', + minimumSnapshotDelay: 7 days, + priceCapParams: IPriceCapAdapter.PriceCapUpdateParams({ + snapshotRatio: 1_050999130243073606, + snapshotTimestamp: 1729748180, // 24th of October 2024 + maxYearlyRatioGrowthPercent: 8_75 + }) + }) + ); + } + + function sUSDeAdapterCode() internal pure returns (bytes memory) { + return + abi.encode( + IPriceCapAdapter.CapAdapterParams({ + aclManager: AaveV3ZkSync.ACL_MANAGER, + baseAggregatorAddress: USDe_PRICE_FEED, + ratioProviderAddress: sUSDe_USDe_AGGREGATOR, + pairDescription: 'Capped sUSDe / USDe / USD', + minimumSnapshotDelay: 14 days, + priceCapParams: IPriceCapAdapter.PriceCapUpdateParams({ + snapshotRatio: 1_108087487354065863, + snapshotTimestamp: 1729101653, // 16th of October 2024 + maxYearlyRatioGrowthPercent: 50_00 + }) + }) + ); + } + + function USDeAdapterCode() internal pure returns (bytes memory) { + return + abi.encode( + IPriceCapAdapterStable.CapAdapterStableParams({ + aclManager: AaveV3ZkSync.ACL_MANAGER, + assetToUsdAggregator: IChainlinkAggregator(USDe_PRICE_FEED), + adapterDescription: 'Capped USDe / USD', + priceCap: int256(1.04 * 1e8) + }) + ); + } +} + +contract DeployWeEthZkSync is ZkSyncScript { + function run() external broadcast { + new CLRatePriceCapAdapter{salt: 'capo'}( + abi.decode(CapAdaptersCodeZkSync.weETHAdapterCode(), (IPriceCapAdapter.CapAdapterParams)) + ); + } +} + +contract DeploySUSDeZkSync is ZkSyncScript { + function run() external broadcast { + new CLRatePriceCapAdapter{salt: 'capo'}( + abi.decode(CapAdaptersCodeZkSync.sUSDeAdapterCode(), (IPriceCapAdapter.CapAdapterParams)) + ); + } +} + +contract DeployUSDeZkSync is ZkSyncScript { + function run() external broadcast { + new PriceCapAdapterStable{salt: 'capo'}( + abi.decode( + CapAdaptersCodeZkSync.USDeAdapterCode(), + (IPriceCapAdapterStable.CapAdapterStableParams) + ) + ); + } +} diff --git a/src/contracts/CLRatePriceCapAdapter.sol b/src/contracts/CLRatePriceCapAdapter.sol index d4e6a54..95cef2d 100644 --- a/src/contracts/CLRatePriceCapAdapter.sol +++ b/src/contracts/CLRatePriceCapAdapter.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {IACLManager} from 'aave-address-book/AaveV3.sol'; import {IChainlinkAggregator} from 'cl-synchronicity-price-adapter/interfaces/IChainlinkAggregator.sol'; diff --git a/tests/utils/GetExchangeRatesTest.t.sol b/tests/utils/GetExchangeRatesTest.t.sol index 6f28bdc..3fa331a 100644 --- a/tests/utils/GetExchangeRatesTest.t.sol +++ b/tests/utils/GetExchangeRatesTest.t.sol @@ -37,6 +37,7 @@ import {CapAdaptersCodeArbitrum} from '../../scripts/DeployArbitrumWeEth.s.sol'; import {CapAdaptersCodeBase} from '../../scripts/DeployBase.s.sol'; import {CapAdaptersCodeScroll} from '../../scripts/DeployScroll.s.sol'; import {CapAdaptersCodeBNB} from '../../scripts/DeployBnb.s.sol'; +import {CapAdaptersCodeZkSync} from '../../scripts/DeployZkSync.s.sol'; contract ExchangeRatesEth is Test { function setUp() public { @@ -259,3 +260,24 @@ contract ExchangeRatesBNB is Test { console.log(block.timestamp); } } + +contract ExchangeRatesZKSync is Test { + function setUp() public { + vm.createSelectFork(vm.rpcUrl('zksync'), 47270341); // Oct-16-2024 + } + + function test_getExchangeRate() public view { + uint256 weETHRate = uint256( + IChainlinkAggregator(CapAdaptersCodeZkSync.weETH_eETH_AGGREGATOR).latestAnswer() + ); + + uint256 sUSDeRate = uint256( + IChainlinkAggregator(CapAdaptersCodeZkSync.sUSDe_USDe_AGGREGATOR).latestAnswer() + ); + + console.log('ZkSync'); + console.log('weETHRate', weETHRate); + console.log('sUSDeRate', sUSDeRate); + console.log(block.timestamp); + } +} diff --git a/tests/zksync/USDePriceCapAdapterZkSyncTest.t.sol b/tests/zksync/USDePriceCapAdapterZkSyncTest.t.sol new file mode 100644 index 0000000..38cd0df --- /dev/null +++ b/tests/zksync/USDePriceCapAdapterZkSyncTest.t.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.0; + +import '../BaseStableTest.sol'; +import {PriceCapAdapterStable, IChainlinkAggregator} from '../../src/contracts/PriceCapAdapterStable.sol'; +import {CapAdaptersCodeZkSync} from '../../scripts/DeployZkSync.s.sol'; +import {AaveV3ZkSync} from 'aave-address-book/AaveV3ZkSync.sol'; + +contract USDePriceCapAdapterZKSyncTest is BaseStableTest { + constructor() + BaseStableTest( + CapAdaptersCodeZkSync.USDeAdapterCode(), + 10, + ForkParams({network: 'zksync', blockNumber: 47910214}) + ) + {} + + function _capAdapterParams() + internal + pure + override + returns (IPriceCapAdapterStable.CapAdapterStableParams memory) + { + return + IPriceCapAdapterStable.CapAdapterStableParams({ + aclManager: AaveV3ZkSync.ACL_MANAGER, + assetToUsdAggregator: IChainlinkAggregator(CapAdaptersCodeZkSync.USDe_PRICE_FEED), + adapterDescription: 'Capped USDe / USD', + priceCap: int256(1.04 * 1e8) + }); + } +} diff --git a/tests/zksync/sUSDePriceCapAdapterZkSyncTest.t.sol b/tests/zksync/sUSDePriceCapAdapterZkSyncTest.t.sol new file mode 100644 index 0000000..1122907 --- /dev/null +++ b/tests/zksync/sUSDePriceCapAdapterZkSyncTest.t.sol @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.0; + +import '../BaseTest.sol'; + +import {CLRatePriceCapAdapter} from '../../src/contracts/CLRatePriceCapAdapter.sol'; +import {CapAdaptersCodeZkSync} from '../../scripts/DeployZkSync.s.sol'; +import {AaveV3ZkSync} from 'aave-address-book/AaveV3ZkSync.sol'; + +contract sUSDePriceCapAdapterZkSyncTest is BaseTest { + constructor() + BaseTest( + CapAdaptersCodeZkSync.sUSDeAdapterCode(), + 8, + ForkParams({network: 'zksync', blockNumber: 47910214}), + 'sUSDe_ZkSync' + ) + {} + + function _createAdapter( + IPriceCapAdapter.CapAdapterParams memory capAdapterParams + ) internal override returns (IPriceCapAdapter) { + return new CLRatePriceCapAdapter{salt: 'test'}(capAdapterParams); + } + + function _capAdapterParams() + internal + pure + override + returns (IPriceCapAdapter.CapAdapterParams memory) + { + return + IPriceCapAdapter.CapAdapterParams({ + aclManager: AaveV3ZkSync.ACL_MANAGER, + baseAggregatorAddress: CapAdaptersCodeZkSync.USDe_PRICE_FEED, + ratioProviderAddress: CapAdaptersCodeZkSync.sUSDe_USDe_AGGREGATOR, + pairDescription: 'Capped sUSDe / USDe / USD', + minimumSnapshotDelay: 14 days, + priceCapParams: IPriceCapAdapter.PriceCapUpdateParams({ + snapshotRatio: 1_108087487354065863, + snapshotTimestamp: 1729101653, // 16th of October 2024 + maxYearlyRatioGrowthPercent: 50_00 + }) + }); + } +} diff --git a/tests/zksync/weETHPriceCapAdapterZkSyncTest.t.sol b/tests/zksync/weETHPriceCapAdapterZkSyncTest.t.sol new file mode 100644 index 0000000..3c9dd37 --- /dev/null +++ b/tests/zksync/weETHPriceCapAdapterZkSyncTest.t.sol @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.0; + +import '../BaseTest.sol'; + +import {CLRatePriceCapAdapter} from '../../src/contracts/CLRatePriceCapAdapter.sol'; +import {CapAdaptersCodeZkSync} from '../../scripts/DeployZkSync.s.sol'; +import {AaveV3ZkSync, AaveV3ZkSyncAssets} from 'aave-address-book/AaveV3ZkSync.sol'; + +contract weETHPriceCapAdapterZkSyncTest is BaseTest { + constructor() + BaseTest( + CapAdaptersCodeZkSync.weETHAdapterCode(), + 8, + ForkParams({network: 'zksync', blockNumber: 47840214}), + 'weETH_ZkSync' + ) + {} + + function _createAdapter( + IPriceCapAdapter.CapAdapterParams memory capAdapterParams + ) internal override returns (IPriceCapAdapter) { + return new CLRatePriceCapAdapter{salt: 'test'}(capAdapterParams); + } + + function _capAdapterParams() + internal + pure + override + returns (IPriceCapAdapter.CapAdapterParams memory) + { + return + IPriceCapAdapter.CapAdapterParams({ + aclManager: AaveV3ZkSync.ACL_MANAGER, + baseAggregatorAddress: AaveV3ZkSyncAssets.WETH_ORACLE, + ratioProviderAddress: CapAdaptersCodeZkSync.weETH_eETH_AGGREGATOR, + pairDescription: 'Capped weETH / eETH(ETH) / USD', + minimumSnapshotDelay: 7 days, + priceCapParams: IPriceCapAdapter.PriceCapUpdateParams({ + snapshotRatio: 1_050999130243073606, + snapshotTimestamp: 1729748180, // 24th of October 2024 + maxYearlyRatioGrowthPercent: 8_75 + }) + }); + } +}