Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: weeth adapter #17

Merged
merged 16 commits into from
Apr 5, 2024
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ deploy-optimism :; forge script scripts/DeployOptimism.s.sol:DeployOptimism --rp
deploy-polygon :; forge script scripts/DeployPolygon.s.sol:DeployPolygon --rpc-url polygon $(common-flags)
deploy-scroll :; forge script scripts/DeployScroll.s.sol:DeployScroll --rpc-url scroll $(common-flags)

deploy-weeth-mainnet :; forge script scripts/DeployEthereum.s.sol:DeployWeEthEthereum --rpc-url mainnet $(common-flags)


# Utilities
download :; cast etherscan-source --chain ${chain} -d src/etherscan/${chain}_${address} ${address}
Expand Down
2 changes: 1 addition & 1 deletion lib/aave-address-book
Submodule aave-address-book updated 92 files
+1 −3 .github/workflows/release-please.yml
+19 −0 .github/workflows/test-release-alpha.yml
+33 −0 CHANGELOG.md
+0 −1 assets/aToken/ageur.svg
+1 −0 assets/aToken/eura.svg
+0 −1 assets/stataToken/ageur.svg
+1 −0 assets/stataToken/eura.svg
+0 −1 assets/underlying/ageur.svg
+1 −1 assets/underlying/bpt.svg
+1 −0 assets/underlying/eura.svg
+8 −10 package.json
+0 −16 scripts/configs/governance/ethereum.ts
+2 −0 scripts/configs/networks/ethereum.ts
+0 −27 scripts/configs/pools/ethereum.ts
+7 −9 scripts/generateAddresses.ts
+22 −7 scripts/generator/generateTokenList.ts
+47 −0 scripts/generator/protocolV1Generator.ts
+11 −0 scripts/generator/protocolV2Generator.ts
+14 −3 scripts/generator/protocolV3Generator.ts
+1 −3 src/AaveAddressBook.sol
+14 −0 src/AaveV1.sol
+73 −67 src/AaveV2Avalanche.sol
+6 −0 src/AaveV2Ethereum.sol
+6 −0 src/AaveV2EthereumAMM.sol
+6 −0 src/AaveV2EthereumArc.sol
+48 −42 src/AaveV2Fuji.sol
+6 −0 src/AaveV2Mumbai.sol
+6 −0 src/AaveV2Polygon.sol
+24 −18 src/AaveV3Arbitrum.sol
+6 −0 src/AaveV3ArbitrumSepolia.sol
+125 −119 src/AaveV3Avalanche.sol
+12 −6 src/AaveV3BNB.sol
+14 −8 src/AaveV3Base.sol
+6 −0 src/AaveV3BaseSepolia.sol
+28 −22 src/AaveV3Ethereum.sol
+6 −0 src/AaveV3Fantom.sol
+6 −0 src/AaveV3FantomTestnet.sol
+72 −66 src/AaveV3Fuji.sol
+12 −6 src/AaveV3Gnosis.sol
+12 −6 src/AaveV3Metis.sol
+6 −0 src/AaveV3Mumbai.sol
+27 −18 src/AaveV3Optimism.sol
+6 −0 src/AaveV3OptimismSepolia.sol
+33 −24 src/AaveV3Polygon.sol
+6 −0 src/AaveV3PolygonZkEvm.sol
+13 −4 src/AaveV3Scroll.sol
+6 −0 src/AaveV3ScrollSepolia.sol
+6 −0 src/AaveV3Sepolia.sol
+9 −9 src/GovernanceV3Avalanche.sol
+6 −6 src/GovernanceV3Fuji.sol
+6 −6 src/MiscAvalanche.sol
+3 −0 src/MiscEthereum.sol
+2 −4 src/ts/AaveAddressBook.ts
+11 −0 src/ts/AaveV1.ts
+31 −25 src/ts/AaveV2Avalanche.ts
+6 −0 src/ts/AaveV2Ethereum.ts
+6 −0 src/ts/AaveV2EthereumAMM.ts
+6 −0 src/ts/AaveV2EthereumArc.ts
+24 −18 src/ts/AaveV2Fuji.ts
+0 −238 src/ts/AaveV2Goerli.ts
+6 −0 src/ts/AaveV2Mumbai.ts
+6 −0 src/ts/AaveV2Polygon.ts
+15 −9 src/ts/AaveV3Arbitrum.ts
+6 −0 src/ts/AaveV3ArbitrumSepolia.ts
+41 −35 src/ts/AaveV3Avalanche.ts
+9 −3 src/ts/AaveV3BNB.ts
+10 −4 src/ts/AaveV3Base.ts
+6 −0 src/ts/AaveV3BaseSepolia.ts
+17 −11 src/ts/AaveV3Ethereum.ts
+6 −0 src/ts/AaveV3Fantom.ts
+6 −0 src/ts/AaveV3FantomTestnet.ts
+24 −18 src/ts/AaveV3Fuji.ts
+9 −3 src/ts/AaveV3Gnosis.ts
+0 −116 src/ts/AaveV3GoerliGho.ts
+9 −3 src/ts/AaveV3Metis.ts
+6 −0 src/ts/AaveV3Mumbai.ts
+16 −9 src/ts/AaveV3Optimism.ts
+6 −0 src/ts/AaveV3OptimismSepolia.ts
+16 −9 src/ts/AaveV3Polygon.ts
+6 −0 src/ts/AaveV3PolygonZkEvm.ts
+11 −2 src/ts/AaveV3Scroll.ts
+6 −0 src/ts/AaveV3ScrollSepolia.ts
+6 −0 src/ts/AaveV3Sepolia.ts
+9 −9 src/ts/GovernanceV3Avalanche.ts
+6 −6 src/ts/GovernanceV3Fuji.ts
+0 −40 src/ts/GovernanceV3Goerli.ts
+6 −6 src/ts/MiscAvalanche.ts
+3 −0 src/ts/MiscEthereum.ts
+5,778 −0 src/ts/tokenlist.ts
+915 −3,093 tokenlist.json
+1 −1 tsup.config.ts
+17 −27 yarn.lock
26 changes: 26 additions & 0 deletions scripts/DeployEthereum.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {RETHPriceCapAdapter} from '../src/contracts/RETHPriceCapAdapter.sol';
import {WstETHPriceCapAdapter} from '../src/contracts/WstETHPriceCapAdapter.sol';
import {SDAIPriceCapAdapter} from '../src/contracts/SDAIPriceCapAdapter.sol';
import {stEURPriceCapAdapter} from '../src/contracts/stEURPriceCapAdapter.sol';
import {WeETHPriceCapAdapter} from '../src/contracts/WeETHPriceCapAdapter.sol';
import {AaveV3EthereumPayload} from '../src/contracts/payloads/AaveV3EthereumPayload.sol';

library CapAdaptersStablesCodeEthereum {
Expand Down Expand Up @@ -166,6 +167,25 @@ library CapAdaptersCodeEthereum {
})
)
);

function weETHAdapterCode() internal pure returns (bytes memory) {
return
abi.encodePacked(
type(WeETHPriceCapAdapter).creationCode,
abi.encode(
AaveV3Ethereum.ACL_MANAGER,
AaveV3EthereumAssets.WETH_ORACLE,
MiscEthereum.weETH_RATIO_PROVIDER,
'Capped weETH / eETH(ETH) / USD',
7 days,
IPriceCapAdapter.PriceCapUpdateParams({
snapshotRatio: 1034656878645040505,
snapshotTimestamp: 1711416299, // 26-03-2024
maxYearlyRatioGrowthPercent: 8_75
})
)
);
}
}

library stEURCapAdapters {
Expand Down Expand Up @@ -251,3 +271,9 @@ contract DeployEthereum is EthereumScript, DeployEthereumAdaptersAndPayload {
_deploy();
}
}

contract DeployWeEthEthereum is EthereumScript {
function run() external broadcast {
GovV3Helpers.deployDeterministic(CapAdaptersCodeEthereum.weETHAdapterCode());
}
}
47 changes: 47 additions & 0 deletions src/contracts/WeETHPriceCapAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;

import {IACLManager} from 'aave-address-book/AaveV3.sol';
import {IWeEth} from '../interfaces/IWeEth.sol';

import {PriceCapAdapterBase, IPriceCapAdapter} from './PriceCapAdapterBase.sol';

/**
* @title WeETHPriceCapAdapter
* @author BGD Labs
* @notice Price capped adapter to calculate price of (weETH / USD) pair by using
* @notice Chainlink data feed for (ETH / USD) and (weETH / eETH) ratio.
*/
contract WeETHPriceCapAdapter is PriceCapAdapterBase {
/**
* @param aclManager ACL manager contract
* @param ethToBaseAggregatorAddress the address of (ETH / USD) feed
* @param weEthAddress the address of the weETH contract, the (weETH / ETH) ratio
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address ethToBaseAggregatorAddress,
address weEthAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
ethToBaseAggregatorAddress,
weEthAddress,
pairName,
18,
minimumSnapshotDelay,
priceCapParams
)
{}

/// @inheritdoc IPriceCapAdapter
function getRatio() public view override returns (int256) {
return int256(IWeEth(RATIO_PROVIDER).getRate());
}
}
10 changes: 10 additions & 0 deletions src/interfaces/IWeEth.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @notice A simple version of the IWeEth interface allowing to get exchange ratio with eETH
interface IWeEth {
/**
* @return the current exchange ratio of the weETH to the eEth
*/
function getRate() external view returns (uint256);
}
2 changes: 1 addition & 1 deletion tests/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ abstract contract BaseTest is Test {
setCapParameters(adapter, 1, 1, 1);
}

function test_latestAnswer1() public virtual {
function test_latestAnswer() public virtual {
IPriceCapAdapter adapter = IPriceCapAdapter(GovV3Helpers.deployDeterministic(deploymentCode));

_mockExistingOracleExchangeRate();
Expand Down
102 changes: 102 additions & 0 deletions tests/ethereum/weETHPriceCapAdapterTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import '../BaseTest.sol';

import {AaveV3Ethereum, AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';

import {WeETHPriceCapAdapter, IWeEth} from '../../src/contracts/WeETHPriceCapAdapter.sol';
import {CapAdaptersCodeEthereum} from '../../scripts/DeployEthereum.s.sol';

contract weETHPriceCapAdapterTest is BaseTest {
constructor()
BaseTest(
address(0),
CapAdaptersCodeEthereum.weETHAdapterCode(),
ForkParams({network: 'mainnet', blockNumber: 19575450}),
RetrospectionParams({
maxYearlyRatioGrowthPercent: 8_75,
minimumSnapshotDelay: 7 days,
startBlock: 18061286,
finishBlock: 19368742,
delayInBlocks: 50200,
step: 20000
}),
CapParams({maxYearlyRatioGrowthPercent: 2_00, startBlock: 19183379, finishBlock: 19575450})
)
{}

function createAdapter(
IACLManager aclManager,
address baseAggregatorAddress,
address ratioProviderAddress,
string memory pairDescription,
uint48 minimumSnapshotDelay,
IPriceCapAdapter.PriceCapUpdateParams memory priceCapParams
) public override returns (IPriceCapAdapter) {
return
new WeETHPriceCapAdapter(
aclManager,
baseAggregatorAddress,
ratioProviderAddress,
pairDescription,
minimumSnapshotDelay,
priceCapParams
);
}

function createAdapterSimple(
uint48 minimumSnapshotDelay,
uint104 currentRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
) public override returns (IPriceCapAdapter) {
return
createAdapter(
AaveV3Ethereum.ACL_MANAGER,
AaveV3EthereumAssets.WETH_ORACLE,
MiscEthereum.weETH_RATIO_PROVIDER,
'weETH / eETH (ETH) / USD',
minimumSnapshotDelay,
currentRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
);
}

function getCurrentRatio() public view override returns (uint104) {
return uint104(IWeEth(MiscEthereum.weETH_RATIO_PROVIDER).getRate());
}

function test_latestAnswer() public override {}

function test_latestAnswerRetrospective() public override {}

function test_cappedLatestAnswer() public override {
vm.createSelectFork(vm.rpcUrl(forkParams.network), capParams.startBlock);

// create adapter with initial parameters
IPriceCapAdapter adapter = createAdapterSimple(
7 days,
uint40(block.timestamp - 8 days),
capParams.maxYearlyRatioGrowthPercent
);

skip(1);

// persist adapter
vm.makePersistent(address(adapter));

// roll fork to the finish block
vm.createSelectFork(vm.rpcUrl(forkParams.network), capParams.finishBlock);

bool isCapped = adapter.isCapped();

// compare prices
assertTrue(isCapped, 'price is not capped');

vm.revokePersistent(address(adapter));
vm.createSelectFork(vm.rpcUrl(forkParams.network), capParams.finishBlock);
}
}
12 changes: 11 additions & 1 deletion tests/payloads/AaveV3ArbitrumPayloadTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';
import {AaveV3Arbitrum, AaveV3ArbitrumAssets} from 'aave-address-book/AaveV3Arbitrum.sol';

import {DeployArbitrumAdaptersAndPayload, CapAdaptersCodeArbitrum} from '../../scripts/DeployArbitrum.s.sol';
import {IPriceCapAdapter} from '../../src/interfaces/IPriceCapAdapter.sol';
import {IPriceCapAdapterStable} from '../../src/interfaces/IPriceCapAdapterStable.sol';

contract AaveV3ArbitrumPayloadTest is Test, DeployArbitrumAdaptersAndPayload {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('arbitrum'), 183394362);
vm.createSelectFork(vm.rpcUrl('arbitrum'), 190587971);
}

function test_AaveV3ArbitrumPayload() public {
Expand Down Expand Up @@ -44,28 +46,36 @@ contract AaveV3ArbitrumPayloadTest is Test, DeployArbitrumAdaptersAndPayload {

address usdtNew = AaveV3Arbitrum.ORACLE.getSourceOfAsset(AaveV3ArbitrumAssets.USDT_UNDERLYING);
assertEq(usdtNew, usdtPredicted);
assertFalse(IPriceCapAdapterStable(usdtNew).isCapped());

address usdcNew = AaveV3Arbitrum.ORACLE.getSourceOfAsset(AaveV3ArbitrumAssets.USDC_UNDERLYING);
assertEq(usdcNew, usdcPredicted);
assertFalse(IPriceCapAdapterStable(usdcNew).isCapped());

address daiNew = AaveV3Arbitrum.ORACLE.getSourceOfAsset(AaveV3ArbitrumAssets.DAI_UNDERLYING);
assertEq(daiNew, daiPredicted);
assertFalse(IPriceCapAdapterStable(daiNew).isCapped());

address lusdNew = AaveV3Arbitrum.ORACLE.getSourceOfAsset(AaveV3ArbitrumAssets.LUSD_UNDERLYING);
assertEq(lusdNew, lusdPredicted);
assertFalse(IPriceCapAdapterStable(lusdNew).isCapped());

address fraxNew = AaveV3Arbitrum.ORACLE.getSourceOfAsset(AaveV3ArbitrumAssets.FRAX_UNDERLYING);
assertEq(fraxNew, fraxPredicted);
assertFalse(IPriceCapAdapterStable(fraxNew).isCapped());

address maiNew = AaveV3Arbitrum.ORACLE.getSourceOfAsset(AaveV3ArbitrumAssets.MAI_UNDERLYING);
assertEq(maiNew, maiPredicted);
assertFalse(IPriceCapAdapterStable(maiNew).isCapped());

address rethNew = AaveV3Arbitrum.ORACLE.getSourceOfAsset(AaveV3ArbitrumAssets.rETH_UNDERLYING);
assertEq(rethNew, rethPredicted);
assertFalse(IPriceCapAdapter(rethNew).isCapped());

address wstEthNew = AaveV3Arbitrum.ORACLE.getSourceOfAsset(
AaveV3ArbitrumAssets.wstETH_UNDERLYING
);
assertEq(wstEthNew, wstEthPredicted);
assertFalse(IPriceCapAdapter(wstEthNew).isCapped());
}
}
10 changes: 9 additions & 1 deletion tests/payloads/AaveV3AvalanchePayloadTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';
import {AaveV3Avalanche, AaveV3AvalancheAssets} from 'aave-address-book/AaveV3Avalanche.sol';

import {DeployAvalancheAdaptersAndPayload, CapAdaptersCodeAvalanche} from '../../scripts/DeployAvalanche.s.sol';
import {IPriceCapAdapter} from '../../src/interfaces/IPriceCapAdapter.sol';
import {IPriceCapAdapterStable} from '../../src/interfaces/IPriceCapAdapterStable.sol';

contract AaveV3AvalanchePayloadTest is Test, DeployAvalancheAdaptersAndPayload {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('avalanche'), 42013694);
vm.createSelectFork(vm.rpcUrl('avalanche'), 42926104);
}

function test_AaveV3AvalanchePayload() public {
Expand Down Expand Up @@ -45,28 +47,34 @@ contract AaveV3AvalanchePayloadTest is Test, DeployAvalancheAdaptersAndPayload {
AaveV3AvalancheAssets.USDt_UNDERLYING
);
assertEq(usdtNew, usdtPredicted);
assertFalse(IPriceCapAdapterStable(usdtNew).isCapped());

address usdcNew = AaveV3Avalanche.ORACLE.getSourceOfAsset(
AaveV3AvalancheAssets.USDC_UNDERLYING
);
assertEq(usdcNew, usdcPredicted);
assertFalse(IPriceCapAdapterStable(usdcNew).isCapped());

address daieNew = AaveV3Avalanche.ORACLE.getSourceOfAsset(
AaveV3AvalancheAssets.DAIe_UNDERLYING
);
assertEq(daieNew, daiePredicted);
assertFalse(IPriceCapAdapterStable(daieNew).isCapped());

address fraxNew = AaveV3Avalanche.ORACLE.getSourceOfAsset(
AaveV3AvalancheAssets.FRAX_UNDERLYING
);
assertEq(fraxNew, fraxPredicted);
assertFalse(IPriceCapAdapterStable(fraxNew).isCapped());

address maiNew = AaveV3Avalanche.ORACLE.getSourceOfAsset(AaveV3AvalancheAssets.MAI_UNDERLYING);
assertEq(maiNew, maiPredicted);
assertFalse(IPriceCapAdapterStable(maiNew).isCapped());

address savaxNew = AaveV3Avalanche.ORACLE.getSourceOfAsset(
AaveV3AvalancheAssets.sAVAX_UNDERLYING
);
assertEq(savaxNew, savaxPredicted);
assertFalse(IPriceCapAdapter(savaxNew).isCapped());
}
}
7 changes: 6 additions & 1 deletion tests/payloads/AaveV3BasePayloadTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';
import {AaveV3Base, AaveV3BaseAssets} from 'aave-address-book/AaveV3Base.sol';

import {DeployBaseAdaptersAndPayload, CapAdaptersCodeBase} from '../../scripts/DeployBase.s.sol';
import {IPriceCapAdapter} from '../../src/interfaces/IPriceCapAdapter.sol';
import {IPriceCapAdapterStable} from '../../src/interfaces/IPriceCapAdapterStable.sol';

contract AaveV3BasePayloadTest is Test, DeployBaseAdaptersAndPayload {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('base'), 10915170);
vm.createSelectFork(vm.rpcUrl('base'), 11853884);
}

function test_AaveV3BasePayload() public {
Expand All @@ -31,11 +33,14 @@ contract AaveV3BasePayloadTest is Test, DeployBaseAdaptersAndPayload {

address usdcNew = AaveV3Base.ORACLE.getSourceOfAsset(AaveV3BaseAssets.USDC_UNDERLYING);
assertEq(usdcNew, usdcPredicted);
assertFalse(IPriceCapAdapterStable(usdcNew).isCapped());

address wstETHNew = AaveV3Base.ORACLE.getSourceOfAsset(AaveV3BaseAssets.wstETH_UNDERLYING);
assertEq(wstETHNew, wstETHPredicted);
assertFalse(IPriceCapAdapter(wstETHNew).isCapped());

address cbETHNew = AaveV3Base.ORACLE.getSourceOfAsset(AaveV3BaseAssets.cbETH_UNDERLYING);
assertEq(cbETHNew, cbETHPredicted);
assertFalse(IPriceCapAdapter(cbETHNew).isCapped());
}
}
7 changes: 6 additions & 1 deletion tests/payloads/AaveV3BnbPayloadTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';
import {AaveV3BNB, AaveV3BNBAssets} from 'aave-address-book/AaveV3BNB.sol';

import {DeployBnbAdaptersAndPayload, CapAdaptersCodeBnb} from '../../scripts/DeployBnb.s.sol';
import {IPriceCapAdapter} from '../../src/interfaces/IPriceCapAdapter.sol';
import {IPriceCapAdapterStable} from '../../src/interfaces/IPriceCapAdapterStable.sol';

contract AaveV3BnbPayloadTest is Test, DeployBnbAdaptersAndPayload {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('bnb'), 36363097);
vm.createSelectFork(vm.rpcUrl('bnb'), 36987594);
}

function test_AaveV3BnbPayload() public {
Expand All @@ -31,11 +33,14 @@ contract AaveV3BnbPayloadTest is Test, DeployBnbAdaptersAndPayload {

address usdtNew = AaveV3BNB.ORACLE.getSourceOfAsset(AaveV3BNBAssets.USDT_UNDERLYING);
assertEq(usdtNew, usdtPredicted);
assertFalse(IPriceCapAdapterStable(usdtNew).isCapped());

address usdcNew = AaveV3BNB.ORACLE.getSourceOfAsset(AaveV3BNBAssets.USDC_UNDERLYING);
assertEq(usdcNew, usdcPredicted);
assertFalse(IPriceCapAdapterStable(usdcNew).isCapped());

address fdusdNew = AaveV3BNB.ORACLE.getSourceOfAsset(AaveV3BNBAssets.FDUSD_UNDERLYING);
assertEq(fdusdNew, fdusdPredicted);
assertFalse(IPriceCapAdapterStable(fdusdNew).isCapped());
}
}
Loading
Loading