Skip to content

Commit

Permalink
Merge pull request #42 from AaveChan/aavechan/SUSD
Browse files Browse the repository at this point in the history
feat: CAPO for USDS & sUSDS
  • Loading branch information
eboadom authored Sep 13, 2024
2 parents e9fae75 + d4bd2b3 commit 1d8ec34
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ deploy-ethx-mainnet :; forge script scripts/DeployEthereum.s.sol:DeployEthXEther

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

deploy-susds-mainnet :
forge script scripts/DeployEthereum.s.sol:DeployUSDSEthereum --rpc-url mainnet $(common-flags)
forge script scripts/DeployEthereum.s.sol:DeploysUSDSEthereum --rpc-url mainnet $(common-flags)

# Utilities
download :; cast etherscan-source --chain ${chain} -d src/etherscan/${chain}_${address} ${address}
git-diff :
Expand Down
52 changes: 52 additions & 0 deletions scripts/DeployEthereum.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import {WeETHPriceCapAdapter} from '../src/contracts/lst-adapters/WeETHPriceCapA
import {OsETHPriceCapAdapter} from '../src/contracts/lst-adapters/OsETHPriceCapAdapter.sol';
import {EthXPriceCapAdapter} from '../src/contracts/lst-adapters/EthXPriceCapAdapter.sol';
import {SUSDePriceCapAdapter} from '../src/contracts/lst-adapters/SUSDePriceCapAdapter.sol';
import {sUSDSPriceCapAdapter} from '../src/contracts/lst-adapters/sUSDSPriceCapAdapter.sol';

library CapAdaptersCodeEthereum {
address public constant weETH = 0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee;
address public constant osETH_VAULT_CONTROLLER = 0x2A261e60FB14586B474C208b1B7AC6D0f5000306;
address public constant USDe_PRICE_FEED = 0xa569d910839Ae8865Da8F8e70FfFb0cBA869F961;
address public constant STADER_STAKE_POOLS_MANAGER = 0xcf5EA1b38380f6aF39068375516Daf40Ed70D299;
address public constant sUSDe = 0x9D39A5DE30e57443BfF2A8307A4256c8797A3497;
address public constant DAI_PRICE_FEED = 0xAed0c38402a5d19df6E4c03F4E2DceD6e29c1ee9;
address public constant sUSDS = 0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD;

function weETHAdapterCode() internal pure returns (bytes memory) {
return
Expand Down Expand Up @@ -117,6 +120,42 @@ library CapAdaptersCodeEthereum {
)
);
}

function USDSAdapterCode() internal pure returns (bytes memory) {
return
abi.encodePacked(
type(PriceCapAdapterStable).creationCode,
abi.encode(
IPriceCapAdapterStable.CapAdapterStableParams({
aclManager: AaveV3Ethereum.ACL_MANAGER,
assetToUsdAggregator: IChainlinkAggregator(DAI_PRICE_FEED),
adapterDescription: 'Capped USDS <-> DAI / USD',
priceCap: int256(1.04 * 1e18)
})
)
);
}

function sUSDSAdapterCode() internal pure returns (bytes memory) {
return
abi.encodePacked(
type(sUSDSPriceCapAdapter).creationCode,
abi.encode(
IPriceCapAdapter.CapAdapterParams({
aclManager: AaveV3Ethereum.ACL_MANAGER,
baseAggregatorAddress: GovV3Helpers.predictDeterministicAddress(USDSAdapterCode()),
ratioProviderAddress: sUSDS,
pairDescription: 'Capped sUSDS / USDS <-> DAI / USD',
minimumSnapshotDelay: 4 days,
priceCapParams: IPriceCapAdapter.PriceCapUpdateParams({
snapshotRatio: 1000000000000000000,
snapshotTimestamp: 1725455495,
maxYearlyRatioGrowthPercent: 15_00
})
})
)
);
}
}

contract DeployWeEthEthereum is EthereumScript {
Expand Down Expand Up @@ -148,3 +187,16 @@ contract DeploySUSDeEthereum is EthereumScript {
GovV3Helpers.deployDeterministic(CapAdaptersCodeEthereum.sUSDeAdapterCode());
}
}

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

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

39 changes: 39 additions & 0 deletions src/contracts/lst-adapters/sUSDSPriceCapAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;

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

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

/**
* @title sUSDSPriceCapAdapter
* @author BGD Labs
* @notice Price capped adapter to calculate price of (sUSDS / USD) pair by using
* @notice Capped adapter for (USDS <-> DAI / USD) and (sUSDS / USDS) ratio.
*/
contract sUSDSPriceCapAdapter 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));
}
}
16 changes: 16 additions & 0 deletions tests/ethereum/USDSPriceCapAdapterTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import '../BaseStableTest.sol';
import {PriceCapAdapterStable} from '../../src/contracts/PriceCapAdapterStable.sol';
import {CapAdaptersCodeEthereum} from '../../scripts/DeployEthereum.s.sol';

contract USDSPriceCapAdapterTest is BaseStableTest {
constructor()
BaseStableTest(
CapAdaptersCodeEthereum.USDSAdapterCode(),
10,
ForkParams({network: 'mainnet', blockNumber: 20729672})
)
{}
}
51 changes: 51 additions & 0 deletions tests/ethereum/sUSDSPriceCapAdapterTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';
import '../BaseTest.sol';

import {AaveV3Ethereum, AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';
import {sUSDSPriceCapAdapter} from '../../src/contracts/lst-adapters/sUSDSPriceCapAdapter.sol';
import {CapAdaptersCodeEthereum} from '../../scripts/DeployEthereum.s.sol';

contract sUSDSPriceCapAdapterTest is BaseTest {
constructor()
BaseTest(
CapAdaptersCodeEthereum.sUSDSAdapterCode(),
3,
ForkParams({network: 'mainnet', blockNumber: 20729672}),
'sUSDS_Ethereum'
)
{
}

function test_latestAnswer() public override {
GovV3Helpers.deployDeterministic(CapAdaptersCodeEthereum.USDSAdapterCode());
IPriceCapAdapter adapter = IPriceCapAdapter(GovV3Helpers.deployDeterministic(deploymentCode));

int256 price = adapter.latestAnswer();
int256 priceOfReferenceAdapter = adapter.BASE_TO_USD_AGGREGATOR().latestAnswer();

assertFalse(adapter.isCapped());
assertGe(
price,
priceOfReferenceAdapter,
'lst price is not greater than the reference adapter price'
);
}

function test_latestAnswerRetrospective() public override {
assert(true);
}

function test_cappedLatestAnswer() public override pure {
assert(true);
}

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

contract ExchangeRatesEth is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('mainnet'), 20024431); // 5th of June
vm.createSelectFork(vm.rpcUrl('mainnet'), 20677435); // 2024-09-04: Deployment of sUSDS
}

function test_getExchangeRate() public view {
Expand All @@ -52,6 +52,7 @@ contract ExchangeRatesEth is Test {
.convertToAssets(10 ** 18);
uint256 ethXRate = IEthX(CapAdaptersCodeEthereum.STADER_STAKE_POOLS_MANAGER).getExchangeRate();
uint256 sUSDeRate = IERC4626(CapAdaptersCodeEthereum.sUSDe).convertToAssets(10 ** 18);
uint256 sUSDSRate = IERC4626(CapAdaptersCodeEthereum.sUSDS).convertToAssets(10 ** 18);

console.log('cbEthRate', cbEthRate);
console.log('rEthRate', rEthRate);
Expand All @@ -61,7 +62,8 @@ contract ExchangeRatesEth is Test {
console.log('weEthRate', weEthRate);
console.log('osEthRate', osEthRate);
console.log('ethXRate', ethXRate);
console.log('usUSDe', sUSDeRate);
console.log('sUSDe', sUSDeRate);
console.log('sUSDS', sUSDSRate);

console.log(block.timestamp);
}
Expand Down

0 comments on commit 1d8ec34

Please sign in to comment.