Skip to content

Commit

Permalink
feat: weETH, sUSDS, USDSe capo
Browse files Browse the repository at this point in the history
  • Loading branch information
ianflexa committed Nov 4, 2024
1 parent e70a9a2 commit 927d2fa
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 1 deletion.
90 changes: 90 additions & 0 deletions scripts/DeployZkSync.s.sol
Original file line number Diff line number Diff line change
@@ -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)
)
);
}
}
2 changes: 1 addition & 1 deletion src/contracts/CLRatePriceCapAdapter.sol
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
22 changes: 22 additions & 0 deletions tests/utils/GetExchangeRatesTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
32 changes: 32 additions & 0 deletions tests/zksync/USDePriceCapAdapterZkSyncTest.t.sol
Original file line number Diff line number Diff line change
@@ -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)
});
}
}
46 changes: 46 additions & 0 deletions tests/zksync/sUSDePriceCapAdapterZkSyncTest.t.sol
Original file line number Diff line number Diff line change
@@ -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
})
});
}
}
46 changes: 46 additions & 0 deletions tests/zksync/weETHPriceCapAdapterZkSyncTest.t.sol
Original file line number Diff line number Diff line change
@@ -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
})
});
}
}

0 comments on commit 927d2fa

Please sign in to comment.