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: add sDAI capo #50

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ deploy-bnbx-bnb :; forge script scripts/DeployBnb.s.sol:DeployBNBxBnb --rpc-url

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

deploy-sdai-mainnet :; forge script scripts/DeployEthereum.s.sol:DeploySDaiEthereum --rpc-url mainnet $(common-flags)
deploy-sdai-gnosis :; forge script scripts/DeployGnosis.s.sol:DeploySDaiGnosis --rpc-url gnosis $(common-flags)

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

# Utilities
Expand Down
26 changes: 26 additions & 0 deletions reports/sDAI_Ethereum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Capo Report

| Capped sDAI / DAI / USD | DAI / USD | Diff | Date | 7-day growth in yearly % |
| ----------------------- | ---------- | ------ | ----------- | ------------------------ |
| 1.11334971 | 0.99966482 | 10.76% | 17 Oct 2024 | 5.38% |
| 1.1136328 | 0.99977 | 10.78% | 18 Oct 2024 | 5.35% |
| 1.11383086 | 0.99979973 | 10.79% | 19 Oct 2024 | 5.35% |
| 1.11414282 | 0.99992865 | 10.81% | 20 Oct 2024 | 5.37% |
| 1.11434215 | 0.99995926 | 10.82% | 21 Oct 2024 | 5.35% |
| 1.11428835 | 0.99976 | 10.83% | 22 Oct 2024 | 5.35% |
| 1.11442294 | 0.99973188 | 10.85% | 23 Oct 2024 | 5.35% |
| 1.11455532 | 0.99970131 | 10.86% | 24 Oct 2024 | 5.35% |
| 1.11485537 | 0.99982108 | 10.88% | 25 Oct 2024 | 5.35% |
| 1.11484808 | 0.99966494 | 10.89% | 26 Oct 2024 | 5.36% |
| 1.11510009 | 0.99974234 | 10.91% | 27 Oct 2024 | 5.35% |
| 1.11544634 | 0.99990409 | 10.92% | 28 Oct 2024 | 5.35% |
| 1.11556526 | 0.99986 | 10.94% | 29 Oct 2024 | 5.35% |
| 1.1158962 | 1.00000876 | 10.95% | 30 Oct 2024 | 5.34% |

- 7-day growth is calculated as an annualized percentage relative to the value of the rate 7 days prior.

| Max Yearly % | Max Day-to-day yearly % | Max 7-day yearly % |
| ------------ | ----------------------- | ------------------ |
| 9.69% | 5.53% | 5.38% |

- Max day-to-day yearly % indicates the maximum growth between two emissions as an annualized percentage.
26 changes: 26 additions & 0 deletions reports/sDAI_Gnosis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Capo Report

| Capped sDAI / DAI / USD | DAI / USD | Diff | Date | 7-day growth in yearly % |
| ----------------------- | ---------- | ------ | ----------- | ------------------------ |
| 1.11779532 | 0.99971365 | 11.15% | 17 Oct 2024 | 6.96% |
| 1.1179241 | 0.99966346 | 11.17% | 18 Oct 2024 | 6.74% |
| 1.11822501 | 0.99976211 | 11.19% | 19 Oct 2024 | 6.70% |
| 1.11832166 | 0.999735 | 11.20% | 20 Oct 2024 | 6.31% |
| 1.1187078 | 0.99978507 | 11.23% | 21 Oct 2024 | 7.31% |
| 1.11896805 | 0.99984 | 11.24% | 22 Oct 2024 | 6.84% |
| 1.11914493 | 0.99979999 | 11.26% | 23 Oct 2024 | 6.78% |
| 1.119103 | 0.99966681 | 11.27% | 24 Oct 2024 | 6.23% |
| 1.11942566 | 0.99966508 | 11.30% | 25 Oct 2024 | 6.88% |
| 1.11978946 | 0.99980639 | 11.32% | 26 Oct 2024 | 6.94% |
| 1.11996144 | 0.99981308 | 11.34% | 27 Oct 2024 | 7.11% |
| 1.1201338 | 0.99974778 | 11.36% | 28 Oct 2024 | 6.71% |
| 1.12047981 | 0.99987 | 11.38% | 29 Oct 2024 | 6.74% |
| 1.12103936 | 1.00018123 | 11.40% | 30 Oct 2024 | 6.69% |

- 7-day growth is calculated as an annualized percentage relative to the value of the rate 7 days prior.

| Max Yearly % | Max Day-to-day yearly % | Max 7-day yearly % |
| ------------ | ----------------------- | ------------------ |
| 9.69% | 10.69% | 7.31% |

- Max day-to-day yearly % indicates the maximum growth between two emissions as an annualized percentage.
32 changes: 31 additions & 1 deletion scripts/DeployEthereum.s.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';
import {EthereumScript} from 'solidity-utils/contracts/utils/ScriptUtils.sol';
import {AaveV3Ethereum, AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {AaveV3EthereumLido, AaveV3EthereumLidoAssets} from 'aave-address-book/AaveV3EthereumLido.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';

import {PriceCapAdapterStable} from '../src/contracts/PriceCapAdapterStable.sol';
import {IPriceCapAdapter, IChainlinkAggregator} from '../src/interfaces/IPriceCapAdapter.sol';
Expand All @@ -14,6 +16,7 @@ import {EthXPriceCapAdapter} from '../src/contracts/lst-adapters/EthXPriceCapAda
import {SUSDePriceCapAdapter} from '../src/contracts/lst-adapters/SUSDePriceCapAdapter.sol';
import {sUSDSPriceCapAdapter} from '../src/contracts/lst-adapters/sUSDSPriceCapAdapter.sol';
import {EzETHPriceCapAdapter} from '../src/contracts/lst-adapters/EzETHPriceCapAdapter.sol';
import {sDAIMainnetPriceCapAdapter} from '../src/contracts/lst-adapters/sDAIMainnetPriceCapAdapter.sol';
import {RsETHPriceCapAdapter} from '../src/contracts/lst-adapters/RsETHPriceCapAdapter.sol';

library CapAdaptersCodeEthereum {
Expand Down Expand Up @@ -126,6 +129,27 @@ library CapAdaptersCodeEthereum {
);
}

function sDAIAdapterCode() internal pure returns (bytes memory) {
return
abi.encodePacked(
type(sDAIMainnetPriceCapAdapter).creationCode,
abi.encode(
IPriceCapAdapter.CapAdapterParams({
aclManager: AaveV3Ethereum.ACL_MANAGER,
baseAggregatorAddress: DAI_PRICE_FEED,
ratioProviderAddress: MiscEthereum.sDAI_POT,
pairDescription: 'Capped sDAI / DAI / USD',
minimumSnapshotDelay: 7 days,
priceCapParams: IPriceCapAdapter.PriceCapUpdateParams({
snapshotRatio: 1_114312383890349337561189736,
snapshotTimestamp: 1729467251,
maxYearlyRatioGrowthPercent: 9_69
})
})
)
);
}

function USDSAdapterCode() internal pure returns (bytes memory) {
return
abi.encodePacked(
Expand Down Expand Up @@ -253,8 +277,14 @@ contract DeployEzEthEthereum is EthereumScript {
}
}

contract DeploySDaiEthereum is EthereumScript {
function run() external broadcast {
GovV3Helpers.deployDeterministic(CapAdaptersCodeEthereum.sDAIAdapterCode());
}
}

contract DeployRsEthEthereum is EthereumScript {
function run() external broadcast {
GovV3Helpers.deployDeterministic(CapAdaptersCodeEthereum.rsETHAdapterCode());
}
}
}
40 changes: 40 additions & 0 deletions scripts/DeployGnosis.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';
import {GnosisScript} from 'solidity-utils/contracts/utils/ScriptUtils.sol';
import {AaveV3Gnosis, AaveV3GnosisAssets} from 'aave-address-book/AaveV3Gnosis.sol';

import {sDAIGnosisPriceCapAdapter} from '../src/contracts/lst-adapters/sDAIGnosisPriceCapAdapter.sol';
import {IPriceCapAdapter} from '../src/interfaces/IPriceCapAdapter.sol';

library CapAdaptersCodeGnosis {
address public constant DAI_PRICE_FEED = 0x678df3415fc31947dA4324eC63212874be5a82f8;

function sDAIAdapterCode() internal pure returns (bytes memory) {
return
abi.encodePacked(
type(sDAIGnosisPriceCapAdapter).creationCode,
abi.encode(
IPriceCapAdapter.CapAdapterParams({
aclManager: AaveV3Gnosis.ACL_MANAGER,
baseAggregatorAddress: DAI_PRICE_FEED,
ratioProviderAddress: AaveV3GnosisAssets.sDAI_UNDERLYING,
pairDescription: 'Capped sDAI / DAI / USD',
minimumSnapshotDelay: 7 days,
priceCapParams: IPriceCapAdapter.PriceCapUpdateParams({
snapshotRatio: 1_118618102334074883,
snapshotTimestamp: 1729423540,
maxYearlyRatioGrowthPercent: 9_69
})
})
)
);
}
}

contract DeploySDaiGnosis is GnosisScript {
function run() external broadcast {
GovV3Helpers.deployDeterministic(CapAdaptersCodeGnosis.sDAIAdapterCode());
}
}
37 changes: 37 additions & 0 deletions src/contracts/lst-adapters/sDAIGnosisPriceCapAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;

import {IERC4626} from 'forge-std/interfaces/IERC4626.sol';
import {PriceCapAdapterBase, IPriceCapAdapter} from '../PriceCapAdapterBase.sol';

/**
* @title sDAIGnosisPriceCapAdapter
* @author BGD Labs
* @notice Price capped adapter to calculate price of (sDAI / USD) pair by using
* @notice Chainlink data feed for (DAI / USD) and (sDAI / DAI) ratio on Gnosis network.
*/
contract sDAIGnosisPriceCapAdapter is PriceCapAdapterBase {
/**
* @param capAdapterParams parameters to create cap adapter
*/
constructor(
CapAdapterParams memory capAdapterParams
)
PriceCapAdapterBase(
CapAdapterBaseParams({
aclManager: capAdapterParams.aclManager,
baseAggregatorAddress: capAdapterParams.baseAggregatorAddress,
ratioProviderAddress: capAdapterParams.ratioProviderAddress,
pairDescription: capAdapterParams.pairDescription,
ratioDecimals: 18,
minimumSnapshotDelay: capAdapterParams.minimumSnapshotDelay,
priceCapParams: capAdapterParams.priceCapParams
})
)
{}

/// @inheritdoc IPriceCapAdapter
function getRatio() public view override returns (int256) {
return int256(IERC4626(RATIO_PROVIDER).convertToAssets(10 ** RATIO_DECIMALS));
}
}
37 changes: 37 additions & 0 deletions src/contracts/lst-adapters/sDAIMainnetPriceCapAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;

import {PriceCapAdapterBase, IPriceCapAdapter} from '../PriceCapAdapterBase.sol';
import {IPot} from 'cl-synchronicity-price-adapter/interfaces/IPot.sol';

/**
* @title sDAIMainnetPriceCapAdapter
* @author BGD Labs
* @notice Price capped adapter to calculate price of (sDAI / USD) pair by using
* @notice Chainlink data feed for (DAI / USD) and (sDAI / DAI) ratio on Ethereum network.
*/
contract sDAIMainnetPriceCapAdapter is PriceCapAdapterBase {
/**
* @param capAdapterParams parameters to create cap adapter
*/
constructor(
CapAdapterParams memory capAdapterParams
)
PriceCapAdapterBase(
CapAdapterBaseParams({
aclManager: capAdapterParams.aclManager,
baseAggregatorAddress: capAdapterParams.baseAggregatorAddress,
ratioProviderAddress: capAdapterParams.ratioProviderAddress,
pairDescription: capAdapterParams.pairDescription,
ratioDecimals: 27,
minimumSnapshotDelay: capAdapterParams.minimumSnapshotDelay,
priceCapParams: capAdapterParams.priceCapParams
})
)
{}

/// @inheritdoc IPriceCapAdapter
function getRatio() public view override returns (int256) {
return int256(IPot(RATIO_PROVIDER).chi());
}
}
23 changes: 23 additions & 0 deletions tests/ethereum/sDAIMainnetPriceCapAdapterTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import '../BaseTest.sol';
import {sDAIMainnetPriceCapAdapter} from '../../src/contracts/lst-adapters/sDAIMainnetPriceCapAdapter.sol';
import {CapAdaptersCodeEthereum} from '../../scripts/DeployEthereum.s.sol';

contract sDAIMainnetPriceCapAdapterTest is BaseTest {
constructor()
BaseTest(
CapAdaptersCodeEthereum.sDAIAdapterCode(),
20,
ForkParams({network: 'mainnet', blockNumber: 21079105}),
'sDAI_Ethereum'
)
{}

function _createAdapter(
IPriceCapAdapter.CapAdapterParams memory capAdapterParams
) internal override returns (IPriceCapAdapter) {
return new sDAIMainnetPriceCapAdapter(capAdapterParams);
}
}
23 changes: 23 additions & 0 deletions tests/gnosis/sDAIGnosisPriceCapAdapter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import '../BaseTest.sol';
import {sDAIGnosisPriceCapAdapter} from '../../src/contracts/lst-adapters/sDAIGnosisPriceCapAdapter.sol';
import {CapAdaptersCodeGnosis} from '../../scripts/DeployGnosis.s.sol';

contract sDAIGnosisPriceCapAdapterTest is BaseTest {
constructor()
BaseTest(
CapAdaptersCodeGnosis.sDAIAdapterCode(),
20,
ForkParams({network: 'gnosis', blockNumber: 36769758}),
'sDAI_Gnosis'
)
{}

function _createAdapter(
IPriceCapAdapter.CapAdapterParams memory capAdapterParams
) internal override returns (IPriceCapAdapter) {
return new sDAIGnosisPriceCapAdapter(capAdapterParams);
}
}
4 changes: 2 additions & 2 deletions tests/utils/GetExchangeRatesTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {CapAdaptersCodeBNB} from '../../scripts/DeployBnb.s.sol';

contract ExchangeRatesEth is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('mainnet'), 20963424); // 14th of October
vm.createSelectFork(vm.rpcUrl('mainnet'), 21010101); // Oct-20-2024
}

function test_getExchangeRate() public view {
Expand Down Expand Up @@ -147,7 +147,7 @@ contract ExchangeRatesBase is Test {

contract ExchangeRatesGnosis is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('gnosis'), 32462055); // 15th of February
vm.createSelectFork(vm.rpcUrl('gnosis'), 36600000); // Oct-20-2024
}

function test_getExchangeRate() public view {
Expand Down
Loading