diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ca7fc0ee6..8c1d16e8d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,7 +22,6 @@ jobs: - run: yarn devchain & env: MAINNET_RPC_URL: https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161 - FORK_BLOCK: 18114118 FORK_NETWORK: mainnet - run: yarn deploy:run --network localhost env: @@ -65,7 +64,7 @@ jobs: TS_NODE_SKIP_IGNORE: true MAINNET_RPC_URL: https://eth-mainnet.alchemyapi.io/v2/${{ secrets.ALCHEMY_MAINNET_KEY }} FORK_NETWORK: mainnet - + plugin-tests-base: name: 'Plugin Tests (Base)' runs-on: ubuntu-latest @@ -84,7 +83,7 @@ jobs: restore-keys: | hardhat-network-fork-${{ runner.os }}- hardhat-network-fork- - - run: npx hardhat test ./test/plugins/individual-collateral/cbeth/*.test.ts + - run: npx hardhat test ./test/plugins/individual-collateral/{cbeth,aave-v3,compoundv3,stargate}/*.test.ts env: NODE_OPTIONS: '--max-old-space-size=8192' TS_NODE_SKIP_IGNORE: true diff --git a/.openzeppelin/mainnet.json b/.openzeppelin/mainnet.json index cb33be385..8ae572183 100644 --- a/.openzeppelin/mainnet.json +++ b/.openzeppelin/mainnet.json @@ -3747,7 +3747,10 @@ }, "t_enum(TradeKind)25002": { "label": "enum TradeKind", - "members": ["DUTCH_AUCTION", "BATCH_AUCTION"], + "members": [ + "DUTCH_AUCTION", + "BATCH_AUCTION" + ], "numberOfBytes": "1" }, "t_mapping(t_contract(IERC20)15191,t_contract(ITrade)27151)": { @@ -4040,7 +4043,11 @@ }, "t_enum(CollateralStatus)24460": { "label": "enum CollateralStatus", - "members": ["SOUND", "IFFY", "DISABLED"], + "members": [ + "SOUND", + "IFFY", + "DISABLED" + ], "numberOfBytes": "1" }, "t_mapping(t_bytes32,t_bytes32)": { @@ -6025,6 +6032,626 @@ } } } + }, + "3b1dde5cc620e2ea43113b74fad027134074d4a72f87ddc30eb639812531857a": { + "address": "0xBbC532A80DD141449330c1232C953Da6801Aed01", + "txHash": "0xfd804f0edbb9ac92c5829b542e8dc8a97490d1fcaed4987343d9901225a6b732", + "layout": { + "solcVersion": "0.8.19", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:62", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:67" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36" + }, + { + "label": "__gap", + "offset": 0, + "slot": "51", + "type": "t_array(t_uint256)50_storage", + "contract": "ERC1967UpgradeUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol:211" + }, + { + "label": "__gap", + "offset": 0, + "slot": "101", + "type": "t_array(t_uint256)50_storage", + "contract": "UUPSUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:107" + }, + { + "label": "main", + "offset": 0, + "slot": "151", + "type": "t_contract(IMain)19008", + "contract": "ComponentP1", + "src": "contracts/p1/mixins/Component.sol:21" + }, + { + "label": "__gap", + "offset": 0, + "slot": "152", + "type": "t_array(t_uint256)49_storage", + "contract": "ComponentP1", + "src": "contracts/p1/mixins/Component.sol:69" + }, + { + "label": "_status", + "offset": 0, + "slot": "201", + "type": "t_uint256", + "contract": "ReentrancyGuardUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol:38" + }, + { + "label": "__gap", + "offset": 0, + "slot": "202", + "type": "t_array(t_uint256)49_storage", + "contract": "ReentrancyGuardUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol:74" + }, + { + "label": "broker", + "offset": 0, + "slot": "251", + "type": "t_contract(IBroker)17878", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:28" + }, + { + "label": "trades", + "offset": 0, + "slot": "252", + "type": "t_mapping(t_contract(IERC20)11113,t_contract(ITrade)19704)", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:31" + }, + { + "label": "tradesOpen", + "offset": 0, + "slot": "253", + "type": "t_uint48", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:32" + }, + { + "label": "maxTradeSlippage", + "offset": 6, + "slot": "253", + "type": "t_uint192", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:35" + }, + { + "label": "minTradeVolume", + "offset": 0, + "slot": "254", + "type": "t_uint192", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:36" + }, + { + "label": "tradesNonce", + "offset": 0, + "slot": "255", + "type": "t_uint256", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:39" + }, + { + "label": "__gap", + "offset": 0, + "slot": "256", + "type": "t_array(t_uint256)45_storage", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:160" + }, + { + "label": "assetRegistry", + "offset": 0, + "slot": "301", + "type": "t_contract(IAssetRegistry)17420", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:30" + }, + { + "label": "basketHandler", + "offset": 0, + "slot": "302", + "type": "t_contract(IBasketHandler)17729", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:31" + }, + { + "label": "distributor", + "offset": 0, + "slot": "303", + "type": "t_contract(IDistributor)18192", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:32" + }, + { + "label": "rToken", + "offset": 0, + "slot": "304", + "type": "t_contract(IRToken)19228", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:33" + }, + { + "label": "rsr", + "offset": 0, + "slot": "305", + "type": "t_contract(IERC20)11113", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:34" + }, + { + "label": "stRSR", + "offset": 0, + "slot": "306", + "type": "t_contract(IStRSR)19569", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:35" + }, + { + "label": "rsrTrader", + "offset": 0, + "slot": "307", + "type": "t_contract(IRevenueTrader)19357", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:36" + }, + { + "label": "rTokenTrader", + "offset": 0, + "slot": "308", + "type": "t_contract(IRevenueTrader)19357", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:37" + }, + { + "label": "tradingDelay", + "offset": 20, + "slot": "308", + "type": "t_uint48", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:41" + }, + { + "label": "backingBuffer", + "offset": 0, + "slot": "309", + "type": "t_uint192", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:42" + }, + { + "label": "furnace", + "offset": 0, + "slot": "310", + "type": "t_contract(IFurnace)18564", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:45" + }, + { + "label": "tradeEnd", + "offset": 0, + "slot": "311", + "type": "t_mapping(t_enum(TradeKind)17751,t_uint48)", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:46" + }, + { + "label": "__gap", + "offset": 0, + "slot": "312", + "type": "t_array(t_uint256)39_storage", + "contract": "BackingManagerP1", + "src": "contracts/p1/BackingManager.sol:310" + } + ], + "types": { + "t_array(t_uint256)39_storage": { + "label": "uint256[39]", + "numberOfBytes": "1248" + }, + "t_array(t_uint256)45_storage": { + "label": "uint256[45]", + "numberOfBytes": "1440" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_contract(IAssetRegistry)17420": { + "label": "contract IAssetRegistry", + "numberOfBytes": "20" + }, + "t_contract(IBasketHandler)17729": { + "label": "contract IBasketHandler", + "numberOfBytes": "20" + }, + "t_contract(IBroker)17878": { + "label": "contract IBroker", + "numberOfBytes": "20" + }, + "t_contract(IDistributor)18192": { + "label": "contract IDistributor", + "numberOfBytes": "20" + }, + "t_contract(IERC20)11113": { + "label": "contract IERC20", + "numberOfBytes": "20" + }, + "t_contract(IFurnace)18564": { + "label": "contract IFurnace", + "numberOfBytes": "20" + }, + "t_contract(IMain)19008": { + "label": "contract IMain", + "numberOfBytes": "20" + }, + "t_contract(IRToken)19228": { + "label": "contract IRToken", + "numberOfBytes": "20" + }, + "t_contract(IRevenueTrader)19357": { + "label": "contract IRevenueTrader", + "numberOfBytes": "20" + }, + "t_contract(IStRSR)19569": { + "label": "contract IStRSR", + "numberOfBytes": "20" + }, + "t_contract(ITrade)19704": { + "label": "contract ITrade", + "numberOfBytes": "20" + }, + "t_enum(TradeKind)17751": { + "label": "enum TradeKind", + "members": [ + "DUTCH_AUCTION", + "BATCH_AUCTION" + ], + "numberOfBytes": "1" + }, + "t_mapping(t_contract(IERC20)11113,t_contract(ITrade)19704)": { + "label": "mapping(contract IERC20 => contract ITrade)", + "numberOfBytes": "32" + }, + "t_mapping(t_enum(TradeKind)17751,t_uint48)": { + "label": "mapping(enum TradeKind => uint48)", + "numberOfBytes": "32" + }, + "t_uint192": { + "label": "uint192", + "numberOfBytes": "24" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint48": { + "label": "uint48", + "numberOfBytes": "6" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + } + } + }, + "7c15ec8db2e19d549d8d3c16622ef1159b0b2d57e4c276018be8aed2cfbabcc3": { + "address": "0x5e3e13d3d2a0adfe16f8EF5E7a2992A88E9e65AF", + "txHash": "0x74f0c8120f6b59c5c5c493325aa6f6c5633db83bab754a79495dba762c0d0db1", + "layout": { + "solcVersion": "0.8.19", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:62", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:67" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36" + }, + { + "label": "__gap", + "offset": 0, + "slot": "51", + "type": "t_array(t_uint256)50_storage", + "contract": "ERC1967UpgradeUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol:211" + }, + { + "label": "__gap", + "offset": 0, + "slot": "101", + "type": "t_array(t_uint256)50_storage", + "contract": "UUPSUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:107" + }, + { + "label": "main", + "offset": 0, + "slot": "151", + "type": "t_contract(IMain)19008", + "contract": "ComponentP1", + "src": "contracts/p1/mixins/Component.sol:21" + }, + { + "label": "__gap", + "offset": 0, + "slot": "152", + "type": "t_array(t_uint256)49_storage", + "contract": "ComponentP1", + "src": "contracts/p1/mixins/Component.sol:69" + }, + { + "label": "_status", + "offset": 0, + "slot": "201", + "type": "t_uint256", + "contract": "ReentrancyGuardUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol:38" + }, + { + "label": "__gap", + "offset": 0, + "slot": "202", + "type": "t_array(t_uint256)49_storage", + "contract": "ReentrancyGuardUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol:74" + }, + { + "label": "broker", + "offset": 0, + "slot": "251", + "type": "t_contract(IBroker)17878", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:28" + }, + { + "label": "trades", + "offset": 0, + "slot": "252", + "type": "t_mapping(t_contract(IERC20)11113,t_contract(ITrade)19704)", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:31" + }, + { + "label": "tradesOpen", + "offset": 0, + "slot": "253", + "type": "t_uint48", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:32" + }, + { + "label": "maxTradeSlippage", + "offset": 6, + "slot": "253", + "type": "t_uint192", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:35" + }, + { + "label": "minTradeVolume", + "offset": 0, + "slot": "254", + "type": "t_uint192", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:36" + }, + { + "label": "tradesNonce", + "offset": 0, + "slot": "255", + "type": "t_uint256", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:39" + }, + { + "label": "__gap", + "offset": 0, + "slot": "256", + "type": "t_array(t_uint256)45_storage", + "contract": "TradingP1", + "src": "contracts/p1/mixins/Trading.sol:160" + }, + { + "label": "tokenToBuy", + "offset": 0, + "slot": "301", + "type": "t_contract(IERC20)11113", + "contract": "RevenueTraderP1", + "src": "contracts/p1/RevenueTrader.sol:19" + }, + { + "label": "assetRegistry", + "offset": 0, + "slot": "302", + "type": "t_contract(IAssetRegistry)17420", + "contract": "RevenueTraderP1", + "src": "contracts/p1/RevenueTrader.sol:20" + }, + { + "label": "distributor", + "offset": 0, + "slot": "303", + "type": "t_contract(IDistributor)18192", + "contract": "RevenueTraderP1", + "src": "contracts/p1/RevenueTrader.sol:21" + }, + { + "label": "backingManager", + "offset": 0, + "slot": "304", + "type": "t_contract(IBackingManager)17482", + "contract": "RevenueTraderP1", + "src": "contracts/p1/RevenueTrader.sol:22" + }, + { + "label": "furnace", + "offset": 0, + "slot": "305", + "type": "t_contract(IFurnace)18564", + "contract": "RevenueTraderP1", + "src": "contracts/p1/RevenueTrader.sol:23" + }, + { + "label": "rToken", + "offset": 0, + "slot": "306", + "type": "t_contract(IRToken)19228", + "contract": "RevenueTraderP1", + "src": "contracts/p1/RevenueTrader.sol:24" + }, + { + "label": "rsr", + "offset": 0, + "slot": "307", + "type": "t_contract(IERC20)11113", + "contract": "RevenueTraderP1", + "src": "contracts/p1/RevenueTrader.sol:25" + }, + { + "label": "__gap", + "offset": 0, + "slot": "308", + "type": "t_array(t_uint256)43_storage", + "contract": "RevenueTraderP1", + "src": "contracts/p1/RevenueTrader.sol:193" + } + ], + "types": { + "t_array(t_uint256)43_storage": { + "label": "uint256[43]", + "numberOfBytes": "1376" + }, + "t_array(t_uint256)45_storage": { + "label": "uint256[45]", + "numberOfBytes": "1440" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_contract(IAssetRegistry)17420": { + "label": "contract IAssetRegistry", + "numberOfBytes": "20" + }, + "t_contract(IBackingManager)17482": { + "label": "contract IBackingManager", + "numberOfBytes": "20" + }, + "t_contract(IBroker)17878": { + "label": "contract IBroker", + "numberOfBytes": "20" + }, + "t_contract(IDistributor)18192": { + "label": "contract IDistributor", + "numberOfBytes": "20" + }, + "t_contract(IERC20)11113": { + "label": "contract IERC20", + "numberOfBytes": "20" + }, + "t_contract(IFurnace)18564": { + "label": "contract IFurnace", + "numberOfBytes": "20" + }, + "t_contract(IMain)19008": { + "label": "contract IMain", + "numberOfBytes": "20" + }, + "t_contract(IRToken)19228": { + "label": "contract IRToken", + "numberOfBytes": "20" + }, + "t_contract(ITrade)19704": { + "label": "contract ITrade", + "numberOfBytes": "20" + }, + "t_mapping(t_contract(IERC20)11113,t_contract(ITrade)19704)": { + "label": "mapping(contract IERC20 => contract ITrade)", + "numberOfBytes": "32" + }, + "t_uint192": { + "label": "uint192", + "numberOfBytes": "24" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint48": { + "label": "uint48", + "numberOfBytes": "6" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + } + } } } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b73a106a..da54bc365 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,12 @@ Then, call `Broker.cacheComponents()`. - Remove `lotPrice()` - Alter `price().high` to decay upwards to 3x over the price timeout +# 3.0.1 + +### Upgrade steps + +Update `BackingManager`, both `RevenueTraders` (rTokenTrader/rsrTrader), and call `Broker.setBatchTradeImplementation()` passing in the new `GnosisTrade` address. + # 3.0.0 Bump solidity version to 0.8.19 diff --git a/common/configuration.ts b/common/configuration.ts index c9b10de79..f17059cb0 100644 --- a/common/configuration.ts +++ b/common/configuration.ts @@ -62,10 +62,13 @@ export interface ITokens { cbETH?: string STG?: string sUSDC?: string + sUSDbC?: string sUSDT?: string sETH?: string MORPHO?: string astETH?: string + wsgUSDC?: string + wsgUSDbC?: string // Morpho Aave maUSDC?: string @@ -110,8 +113,12 @@ interface INetworkConfig { MORPHO_REWARDS_DISTRIBUTOR?: string MORPHO_AAVE_LENS?: string COMET_REWARDS?: string + COMET_CONFIGURATOR?: string + COMET_PROXY_ADMIN?: string + COMET_EXT?: string AAVE_V3_INCENTIVES_CONTROLLER?: string AAVE_V3_POOL?: string + STARGATE_STAKING_CONTRACT?: string } export const networkConfig: { [key: string]: INetworkConfig } = { @@ -216,8 +223,12 @@ export const networkConfig: { [key: string]: INetworkConfig } = { MORPHO_AAVE_CONTROLLER: '0x777777c9898D384F785Ee44Acfe945efDFf5f3E0', MORPHO_REWARDS_DISTRIBUTOR: '0x3b14e5c73e0a56d607a8688098326fd4b4292135', COMET_REWARDS: '0x1B0e765F6224C21223AeA2af16c1C46E38885a40', + COMET_CONFIGURATOR: '0x316f9708bB98af7dA9c68C1C3b5e79039cD336E3', + COMET_PROXY_ADMIN: '0x1EC63B5883C3481134FD50D5DAebc83Ecd2E8779', + COMET_EXT: '0x285617313887d43256F852cAE0Ee4de4b68D45B0', AAVE_V3_POOL: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', AAVE_V3_INCENTIVES_CONTROLLER: '0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb', + STARGATE_STAKING_CONTRACT: '0xB0D502E938ed5f4df2E681fE6E419ff29631d62b' }, '1': { name: 'mainnet', @@ -311,8 +322,12 @@ export const networkConfig: { [key: string]: INetworkConfig } = { MORPHO_AAVE_CONTROLLER: '0x777777c9898D384F785Ee44Acfe945efDFf5f3E0', MORPHO_REWARDS_DISTRIBUTOR: '0x3b14e5c73e0a56d607a8688098326fd4b4292135', COMET_REWARDS: '0x1B0e765F6224C21223AeA2af16c1C46E38885a40', + COMET_CONFIGURATOR: '0x316f9708bB98af7dA9c68C1C3b5e79039cD336E3', + COMET_PROXY_ADMIN: '0x1EC63B5883C3481134FD50D5DAebc83Ecd2E8779', + COMET_EXT: '0x285617313887d43256F852cAE0Ee4de4b68D45B0', AAVE_V3_POOL: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', AAVE_V3_INCENTIVES_CONTROLLER: '0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb', + STARGATE_STAKING_CONTRACT: '0xB0D502E938ed5f4df2E681fE6E419ff29631d62b' }, '3': { name: 'tenderly', @@ -406,8 +421,12 @@ export const networkConfig: { [key: string]: INetworkConfig } = { MORPHO_AAVE_CONTROLLER: '0x777777c9898D384F785Ee44Acfe945efDFf5f3E0', MORPHO_REWARDS_DISTRIBUTOR: '0x3b14e5c73e0a56d607a8688098326fd4b4292135', COMET_REWARDS: '0x1B0e765F6224C21223AeA2af16c1C46E38885a40', + COMET_CONFIGURATOR: '0x316f9708bB98af7dA9c68C1C3b5e79039cD336E3', + COMET_PROXY_ADMIN: '0x1EC63B5883C3481134FD50D5DAebc83Ecd2E8779', + COMET_EXT: '0x285617313887d43256F852cAE0Ee4de4b68D45B0', AAVE_V3_POOL: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', AAVE_V3_INCENTIVES_CONTROLLER: '0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb', + STARGATE_STAKING_CONTRACT: '0xB0D502E938ed5f4df2E681fE6E419ff29631d62b' }, '5': { name: 'goerli', @@ -510,6 +529,8 @@ export const networkConfig: { [key: string]: INetworkConfig } = { aBasUSDbC: '0x0a1d576f3eFeF75b330424287a95A366e8281D54', aWETHv3: '0xD4a0e0b9149BCee3C920d2E00b5dE09138fd8bb7', acbETHv3: '0xcf3D55c10DB69f28fD1A75Bd73f3D8A2d9c595ad', + sUSDbC: '0x4c80e24119cfb836cdf0a6b53dc23f04f7e652ca', + STG: '0xE3B53AF74a4BF62Ae5511055290838050bf764Df' }, chainlinkFeeds: { DAI: '0x591e79239a7d679378ec8c847e5038150364c78f', // 0.3%, 24hr @@ -525,8 +546,12 @@ export const networkConfig: { [key: string]: INetworkConfig } = { }, GNOSIS_EASY_AUCTION: '0xb1875Feaeea32Bbb02DE83D81772e07E37A40f02', // mock COMET_REWARDS: '0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1', + COMET_CONFIGURATOR: '0x45939657d1CA34A8FA39A924B71D28Fe8431e581', + COMET_PROXY_ADMIN: '0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d', + COMET_EXT: '0x2F9E3953b2Ef89fA265f2a32ed9F80D00229125B', AAVE_V3_POOL: '0xA238Dd80C259a72e81d7e4664a9801593F98d1c5', AAVE_V3_INCENTIVES_CONTROLLER: '0xf9cc4F0D883F1a1eb2c253bdb46c254Ca51E1F44', + STARGATE_STAKING_CONTRACT: '0x06Eb48763f117c7Be887296CDcdfad2E4092739C' }, } @@ -650,7 +675,7 @@ export const MAX_THROTTLE_PCT_RATE = BigNumber.from(10).pow(18) export const GNOSIS_MAX_TOKENS = BigNumber.from(7).mul(BigNumber.from(10).pow(28)) // Timestamps -export const MAX_ORACLE_TIMEOUT = BigNumber.from(2).pow(48).sub(1) +export const MAX_ORACLE_TIMEOUT = BigNumber.from(2).pow(48).sub(1).sub(300) export const MAX_TRADING_DELAY = 31536000 // 1 year export const MIN_WARMUP_PERIOD = 60 // 1 minute export const MAX_WARMUP_PERIOD = 31536000 // 1 year diff --git a/contracts/forknet/ForkedOracle.sol b/contracts/forknet/ForkedOracle.sol new file mode 100644 index 000000000..cb0f4b0d9 --- /dev/null +++ b/contracts/forknet/ForkedOracle.sol @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: BlueOak-1.0.0 +pragma solidity 0.8.19; + +interface AggregatorV3MixedInterface { + function decimals() external view returns (uint8); + + function description() external view returns (string memory); + + function latestRoundData() + external + view + returns ( + uint80 roundId, + int256 answer, + uint256 startedAt, + uint256 updatedAt, + uint80 answeredInRound + ); + + function aggregator() external view returns (address); +} + +contract ForkedOracle is AggregatorV3MixedInterface { + address public constant aggregator = address(0x1); + string public constant description = "FORKED"; + + uint8 public decimals; + int256 private answerInternal; + + function setData(uint8 _decimals, int256 _answer) external { + decimals = _decimals; + answerInternal = _answer; + } + + function latestRoundData() + external + view + returns ( + uint80 roundId, + int256 answer, + uint256 startedAt, + uint256 updatedAt, + uint80 answeredInRound + ) + { + roundId = 1; + answer = answerInternal; + startedAt = 0; + updatedAt = block.timestamp - 1; + answeredInRound = 1; + } +} diff --git a/contracts/libraries/Allowance.sol b/contracts/libraries/Allowance.sol new file mode 100644 index 000000000..c3e5f62e5 --- /dev/null +++ b/contracts/libraries/Allowance.sol @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: BlueOak-1.0.0 +pragma solidity 0.8.19; + +interface IERC20ApproveOnly { + function approve(address spender, uint256 value) external; + + function allowance(address owner, address spender) external view returns (uint256); +} + +library AllowanceLib { + /// An approve helper that: + /// 1. Sets initial allowance to 0 + /// 2. Tries to set the provided allowance + /// 3. Falls back to setting a maximum allowance, if (2) fails + /// Context: Some new-age ERC20s think it's a good idea to revert for allowances + /// that are > 0 but < type(uint256).max. + function safeApproveFallbackToMax( + address tokenAddress, + address spender, + uint256 value + ) internal { + IERC20ApproveOnly token = IERC20ApproveOnly(tokenAddress); + + // 1. Set initial allowance to 0 + token.approve(spender, 0); + require(token.allowance(address(this), spender) == 0, "allowance not 0"); + + if (value == 0) return; + + // 2. Try to set the provided allowance + bool success; // bool success = false; + try token.approve(spender, value) { + success = token.allowance(address(this), spender) == value; + // solhint-disable-next-line no-empty-blocks + } catch {} + + // 3. Fall-back to setting a maximum allowance + if (!success) { + token.approve(spender, type(uint256).max); + require(token.allowance(address(this), spender) >= value, "allowance missing"); + } + } +} diff --git a/contracts/p0/BackingManager.sol b/contracts/p0/BackingManager.sol index 2d4bb0de2..946534141 100644 --- a/contracts/p0/BackingManager.sol +++ b/contracts/p0/BackingManager.sol @@ -164,6 +164,7 @@ contract BackingManagerP0 is TradingP0, IBackingManager { uint256 rsrBal = main.rsr().balanceOf(address(this)); if (rsrBal > 0) { main.rsr().safeTransfer(address(main.stRSR()), rsrBal); + main.stRSR().payoutRewards(); } // Mint revenue RToken diff --git a/contracts/p0/Distributor.sol b/contracts/p0/Distributor.sol index 8c5f429b6..9f43240c5 100644 --- a/contracts/p0/Distributor.sol +++ b/contracts/p0/Distributor.sol @@ -70,6 +70,8 @@ contract DistributorP0 is ComponentP0, IDistributor { // Evenly distribute revenue tokens per distribution share. // This rounds "early", and that's deliberate! + bool accountRewards = false; + for (uint256 i = 0; i < destinations.length(); i++) { address addrTo = destinations.at(i); @@ -81,12 +83,23 @@ contract DistributorP0 is ComponentP0, IDistributor { if (addrTo == FURNACE) { addrTo = address(main.furnace()); + if (transferAmt > 0) accountRewards = true; } else if (addrTo == ST_RSR) { addrTo = address(main.stRSR()); + if (transferAmt > 0) accountRewards = true; } erc20.safeTransferFrom(_msgSender(), addrTo, transferAmt); } emit RevenueDistributed(erc20, _msgSender(), amount); + + // Perform reward accounting + if (accountRewards) { + if (isRSR) { + main.stRSR().payoutRewards(); + } else { + main.furnace().melt(); + } + } } /// Returns the rsr + rToken shareTotals diff --git a/contracts/p0/RevenueTrader.sol b/contracts/p0/RevenueTrader.sol index 21fa3994a..8fecf2eb7 100644 --- a/contracts/p0/RevenueTrader.sol +++ b/contracts/p0/RevenueTrader.sol @@ -138,6 +138,9 @@ contract RevenueTraderP0 is TradingP0, IRevenueTrader { uint256 bal = tokenToBuy.balanceOf(address(this)); tokenToBuy.safeApprove(address(main.distributor()), 0); tokenToBuy.safeApprove(address(main.distributor()), bal); + // do not need to use AllowanceLib.safeApproveFallbackToCustom here because + // tokenToBuy can be assumed to be either RSR or the RToken + main.distributor().distribute(tokenToBuy, bal); } } diff --git a/contracts/p0/mixins/Trading.sol b/contracts/p0/mixins/Trading.sol index b49aee3f1..52fc993ee 100644 --- a/contracts/p0/mixins/Trading.sol +++ b/contracts/p0/mixins/Trading.sol @@ -6,6 +6,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "../../interfaces/IBroker.sol"; import "../../interfaces/IMain.sol"; import "../../interfaces/ITrade.sol"; +import "../../libraries/Allowance.sol"; import "../../libraries/Fixed.sol"; import "./Rewardable.sol"; @@ -68,8 +69,16 @@ abstract contract TradingP0 is RewardableP0, ITrading { IBroker broker = main.broker(); assert(address(trades[req.sell.erc20()]) == address(0)); - req.sell.erc20().safeApprove(address(broker), 0); - req.sell.erc20().safeApprove(address(broker), req.sellAmount); + // Set allowance via custom approval -- first sets allowance to 0, then sets allowance + // to either the requested amount or the maximum possible amount, if that fails. + // + // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve + // amount is > 0 and < type(uint256).max. + AllowanceLib.safeApproveFallbackToMax( + address(req.sell.erc20()), + address(broker), + req.sellAmount + ); trade = broker.openTrade(kind, req, prices); trades[req.sell.erc20()] = trade; diff --git a/contracts/p1/BackingManager.sol b/contracts/p1/BackingManager.sol index da8473e66..7763ddb77 100644 --- a/contracts/p1/BackingManager.sol +++ b/contracts/p1/BackingManager.sol @@ -210,10 +210,12 @@ contract BackingManagerP1 is TradingP1, IBackingManager { * RToken traders according to the distribution totals. */ - // Forward any RSR held to StRSR pool; RSR should never be sold for RToken yield + // Forward any RSR held to StRSR pool and payout rewards + // RSR should never be sold for RToken yield if (rsr.balanceOf(address(this)) > 0) { // For CEI, this is an interaction "within our system" even though RSR is already live IERC20(address(rsr)).safeTransfer(address(stRSR), rsr.balanceOf(address(this))); + stRSR.payoutRewards(); } // Mint revenue RToken diff --git a/contracts/p1/Distributor.sol b/contracts/p1/Distributor.sol index bce53c5ef..04fedb57e 100644 --- a/contracts/p1/Distributor.sol +++ b/contracts/p1/Distributor.sol @@ -112,6 +112,8 @@ contract DistributorP1 is ComponentP1, IDistributor { address furnaceAddr = furnace; // gas-saver address stRSRAddr = stRSR; // gas-saver + bool accountRewards = false; + for (uint256 i = 0; i < destinations.length(); ++i) { address addrTo = destinations.at(i); @@ -123,8 +125,10 @@ contract DistributorP1 is ComponentP1, IDistributor { if (addrTo == FURNACE) { addrTo = furnaceAddr; + if (transferAmt > 0) accountRewards = true; } else if (addrTo == ST_RSR) { addrTo = stRSRAddr; + if (transferAmt > 0) accountRewards = true; } transfers[numTransfers] = Transfer({ @@ -141,6 +145,15 @@ contract DistributorP1 is ComponentP1, IDistributor { Transfer memory t = transfers[i]; IERC20Upgradeable(address(t.erc20)).safeTransferFrom(caller, t.addrTo, t.amount); } + + // Perform reward accounting + if (accountRewards) { + if (isRSR) { + main.stRSR().payoutRewards(); + } else { + main.furnace().melt(); + } + } } /// The rsr and rToken shareTotals diff --git a/contracts/p1/RevenueTrader.sol b/contracts/p1/RevenueTrader.sol index a220e6ca1..998bdc951 100644 --- a/contracts/p1/RevenueTrader.sol +++ b/contracts/p1/RevenueTrader.sol @@ -188,6 +188,9 @@ contract RevenueTraderP1 is TradingP1, IRevenueTrader { uint256 bal = tokenToBuy.balanceOf(address(this)); tokenToBuy.safeApprove(address(distributor), 0); tokenToBuy.safeApprove(address(distributor), bal); + + // do not need to use AllowanceLib.safeApproveFallbackToCustom here because + // tokenToBuy can be assumed to be either RSR or the RToken distributor.distribute(tokenToBuy, bal); } diff --git a/contracts/p1/mixins/Trading.sol b/contracts/p1/mixins/Trading.sol index 387bf2d7f..7b38c7c30 100644 --- a/contracts/p1/mixins/Trading.sol +++ b/contracts/p1/mixins/Trading.sol @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/Multicall.sol"; import "../../interfaces/ITrade.sol"; import "../../interfaces/ITrading.sol"; +import "../../libraries/Allowance.sol"; import "../../libraries/Fixed.sol"; import "./Component.sol"; import "./RewardableLib.sol"; @@ -120,8 +121,12 @@ abstract contract TradingP1 is Multicall, ComponentP1, ReentrancyGuardUpgradeabl IERC20 sell = req.sell.erc20(); assert(address(trades[sell]) == address(0)); // ensure calling class has checked this - IERC20Upgradeable(address(sell)).safeApprove(address(broker), 0); - IERC20Upgradeable(address(sell)).safeApprove(address(broker), req.sellAmount); + // Set allowance via custom approval -- first sets allowance to 0, then sets allowance + // to either the requested amount or the maximum possible amount, if that fails. + // + // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve + // amount is > 0 and < type(uint256).max. + AllowanceLib.safeApproveFallbackToMax(address(sell), address(broker), req.sellAmount); trade = broker.openTrade(kind, req, prices); trades[sell] = trade; diff --git a/contracts/plugins/assets/AppreciatingFiatCollateral.sol b/contracts/plugins/assets/AppreciatingFiatCollateral.sol index bf7cef602..60e575cf7 100644 --- a/contracts/plugins/assets/AppreciatingFiatCollateral.sol +++ b/contracts/plugins/assets/AppreciatingFiatCollateral.sol @@ -88,7 +88,7 @@ abstract contract AppreciatingFiatCollateral is FiatCollateral { // uint192(<) is equivalent to Fix.lt if (underlyingRefPerTok < exposedReferencePrice) { - exposedReferencePrice = hiddenReferencePrice; + exposedReferencePrice = underlyingRefPerTok; markStatus(CollateralStatus.DISABLED); } else if (hiddenReferencePrice > exposedReferencePrice) { exposedReferencePrice = hiddenReferencePrice; diff --git a/contracts/plugins/assets/Asset.sol b/contracts/plugins/assets/Asset.sol index ed98e9a1d..3b858a9ea 100644 --- a/contracts/plugins/assets/Asset.sol +++ b/contracts/plugins/assets/Asset.sol @@ -7,6 +7,8 @@ import "../../interfaces/IAsset.sol"; import "./OracleLib.sol"; import "./VersionedAsset.sol"; +uint48 constant ORACLE_TIMEOUT_BUFFER = 300; // {s} 5 minutes + contract Asset is IAsset, VersionedAsset { using FixLib for uint192; using OracleLib for AggregatorV3Interface; @@ -62,7 +64,7 @@ contract Asset is IAsset, VersionedAsset { erc20 = erc20_; erc20Decimals = erc20.decimals(); maxTradeVolume = maxTradeVolume_; - oracleTimeout = oracleTimeout_; + oracleTimeout = oracleTimeout_ + ORACLE_TIMEOUT_BUFFER; // add 300s as a buffer } /// Can revert, used by other contract functions in order to catch errors diff --git a/contracts/plugins/assets/L2LSDCollateral.sol b/contracts/plugins/assets/L2LSDCollateral.sol index c2d7cd3cd..60b0bd832 100644 --- a/contracts/plugins/assets/L2LSDCollateral.sol +++ b/contracts/plugins/assets/L2LSDCollateral.sol @@ -53,7 +53,7 @@ abstract contract L2LSDCollateral is AppreciatingFiatCollateral { // uint192(<) is equivalent to Fix.lt if (underlyingRefPerTok < exposedReferencePrice) { - exposedReferencePrice = hiddenReferencePrice; + exposedReferencePrice = underlyingRefPerTok; markStatus(CollateralStatus.DISABLED); } else if (hiddenReferencePrice > exposedReferencePrice) { exposedReferencePrice = hiddenReferencePrice; diff --git a/contracts/plugins/assets/compoundv2/CTokenWrapper.sol b/contracts/plugins/assets/compoundv2/CTokenWrapper.sol index 534de316a..286787d42 100644 --- a/contracts/plugins/assets/compoundv2/CTokenWrapper.sol +++ b/contracts/plugins/assets/compoundv2/CTokenWrapper.sol @@ -35,7 +35,9 @@ contract CTokenWrapper is RewardableERC20Wrapper { // === Overrides === function _claimAssetRewards() internal virtual override { - comptroller.claimComp(address(this)); + address[] memory cTokens = new address[](1); + cTokens[0] = address(underlying); + comptroller.claimComp(address(this), cTokens); } // No overrides of _deposit()/_withdraw() necessary: no staking required diff --git a/contracts/plugins/assets/compoundv2/ICToken.sol b/contracts/plugins/assets/compoundv2/ICToken.sol index 384ba8498..9dafd86c8 100644 --- a/contracts/plugins/assets/compoundv2/ICToken.sol +++ b/contracts/plugins/assets/compoundv2/ICToken.sol @@ -35,7 +35,7 @@ interface ICToken is IERC20Metadata { interface IComptroller { /// Claim comp for an account, to an account - function claimComp(address account) external; + function claimComp(address account, address[] memory cTokens) external; /// @return The address for COMP token function getCompAddress() external view returns (address); diff --git a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol index 281688968..92f8a2d20 100644 --- a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol +++ b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol @@ -77,7 +77,7 @@ contract CTokenV3Collateral is AppreciatingFiatCollateral { // uint192(<) is equivalent to Fix.lt if (underlyingRefPerTok < exposedReferencePrice) { - exposedReferencePrice = hiddenReferencePrice; + exposedReferencePrice = underlyingRefPerTok; markStatus(CollateralStatus.DISABLED); } else if (hiddenReferencePrice > exposedReferencePrice) { exposedReferencePrice = hiddenReferencePrice; diff --git a/contracts/plugins/assets/curve/CurveStableCollateral.sol b/contracts/plugins/assets/curve/CurveStableCollateral.sol index f5706f75e..8a21dfda9 100644 --- a/contracts/plugins/assets/curve/CurveStableCollateral.sol +++ b/contracts/plugins/assets/curve/CurveStableCollateral.sol @@ -88,7 +88,7 @@ contract CurveStableCollateral is AppreciatingFiatCollateral, PoolTokens { // uint192(<) is equivalent to Fix.lt if (underlyingRefPerTok < exposedReferencePrice) { - exposedReferencePrice = hiddenReferencePrice; + exposedReferencePrice = underlyingRefPerTok; markStatus(CollateralStatus.DISABLED); } else if (hiddenReferencePrice > exposedReferencePrice) { exposedReferencePrice = hiddenReferencePrice; diff --git a/contracts/plugins/assets/stargate/StargateRewardableWrapper.sol b/contracts/plugins/assets/stargate/StargateRewardableWrapper.sol index 9252a9985..838695d18 100644 --- a/contracts/plugins/assets/stargate/StargateRewardableWrapper.sol +++ b/contracts/plugins/assets/stargate/StargateRewardableWrapper.sol @@ -23,7 +23,12 @@ contract StargateRewardableWrapper is RewardableERC20Wrapper { address(pool_) != address(0), "Invalid address" ); - require(address(stargate_) == address(stakingContract_.stargate()), "Wrong stargate"); + try stakingContract_.stargate() returns (address stargateAddress) { + require(stargateAddress == address(stargate_), "Wrong stargate"); + } catch { + // using LPStakingTime contract instead + require(stakingContract_.eToken() == address(stargate_), "Wrong stargate"); + } uint256 poolLength = stakingContract_.poolLength(); uint256 pid = type(uint256).max; diff --git a/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol b/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol index 1dada23b0..dc9e62ff5 100644 --- a/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol +++ b/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol @@ -6,7 +6,9 @@ import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IStargateLPStaking { function poolLength() external view returns (uint256); - function stargate() external view returns (IERC20); + function stargate() external view returns (address); + + function eToken() external view returns (address); // Info of each pool. struct PoolInfo { diff --git a/contracts/plugins/assets/stargate/mocks/StargateLPStakingMock.sol b/contracts/plugins/assets/stargate/mocks/StargateLPStakingMock.sol index 3ab789869..2123564b6 100644 --- a/contracts/plugins/assets/stargate/mocks/StargateLPStakingMock.sol +++ b/contracts/plugins/assets/stargate/mocks/StargateLPStakingMock.sol @@ -10,13 +10,15 @@ contract StargateLPStakingMock is IStargateLPStaking { mapping(uint256 => mapping(address => uint256)) poolToUserBalance; ERC20Mock public immutable stargateMock; - IERC20 public immutable stargate; + address public immutable stargate; + address public immutable eToken; uint256 public totalAllocPoint = 0; constructor(ERC20Mock stargateMock_) { stargateMock = stargateMock_; - stargate = stargateMock_; + stargate = address(stargateMock_); + eToken = address(stargateMock_); } function poolLength() external view override returns (uint256) { diff --git a/contracts/plugins/mocks/BadERC20.sol b/contracts/plugins/mocks/BadERC20.sol index 99c7791e8..11570a4e4 100644 --- a/contracts/plugins/mocks/BadERC20.sol +++ b/contracts/plugins/mocks/BadERC20.sol @@ -11,6 +11,7 @@ contract BadERC20 is ERC20Mock { uint8 private _decimals; uint192 public transferFee; // {1} bool public revertDecimals; + bool public revertApprove; // if true, reverts for any approve > 0 and < type(uint256).max mapping(address => bool) public censored; @@ -34,6 +35,10 @@ contract BadERC20 is ERC20Mock { censored[account] = val; } + function setRevertApprove(bool newRevertApprove) external { + revertApprove = newRevertApprove; + } + function decimals() public view override returns (uint8) { bytes memory data = abi.encodePacked((bytes4(keccak256("absentDecimalsFn()")))); @@ -42,6 +47,11 @@ contract BadERC20 is ERC20Mock { return _decimals; } + function approve(address spender, uint256 amount) public virtual override returns (bool) { + if (revertApprove && amount > 0 && amount < type(uint256).max) revert("revertApprove"); + return super.approve(spender, amount); + } + function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); if (censored[owner] || censored[to]) revert("censored"); diff --git a/contracts/plugins/mocks/CTokenWrapperMock.sol b/contracts/plugins/mocks/CTokenWrapperMock.sol index 7ada69cb2..c0cd0922a 100644 --- a/contracts/plugins/mocks/CTokenWrapperMock.sol +++ b/contracts/plugins/mocks/CTokenWrapperMock.sol @@ -42,7 +42,9 @@ contract CTokenWrapperMock is ERC20Mock, IRewardable { revert("reverting claim rewards"); } uint256 oldBal = comp.balanceOf(msg.sender); - comptroller.claimComp(msg.sender); + address[] memory cTokens = new address[](1); + cTokens[0] = address(underlying); + comptroller.claimComp(msg.sender, cTokens); emit RewardsClaimed(IERC20(address(comp)), comp.balanceOf(msg.sender) - oldBal); } diff --git a/contracts/plugins/mocks/ComptrollerMock.sol b/contracts/plugins/mocks/ComptrollerMock.sol index 8e0d12850..9f9572647 100644 --- a/contracts/plugins/mocks/ComptrollerMock.sol +++ b/contracts/plugins/mocks/ComptrollerMock.sol @@ -19,7 +19,7 @@ contract ComptrollerMock is IComptroller { compBalances[recipient] = amount; } - function claimComp(address holder) external { + function claimComp(address holder, address[] memory) external { // Mint amount and update internal balances if (address(compToken) != address(0)) { uint256 amount = compBalances[holder]; diff --git a/contracts/plugins/trading/GnosisTrade.sol b/contracts/plugins/trading/GnosisTrade.sol index e8413c5fe..9f52e6387 100644 --- a/contracts/plugins/trading/GnosisTrade.sol +++ b/contracts/plugins/trading/GnosisTrade.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; +import "../../libraries/Allowance.sol"; import "../../libraries/Fixed.sol"; import "../../interfaces/IBroker.sol"; import "../../interfaces/IGnosis.sol"; @@ -130,9 +131,12 @@ contract GnosisTrade is ITrade { // == Interactions == - // Set allowance (two safeApprove calls to support USDT) - IERC20Upgradeable(address(sell)).safeApprove(address(gnosis), 0); - IERC20Upgradeable(address(sell)).safeApprove(address(gnosis), initBal); + // Set allowance via custom approval -- first sets allowance to 0, then sets allowance + // to either the requested amount or the maximum possible amount, if that fails. + // + // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve + // amount is > 0 and < type(uint256).max. + AllowanceLib.safeApproveFallbackToMax(address(sell), address(gnosis), initBal); auctionId = gnosis.initiateAuction( sell, diff --git a/hardhat.config.ts b/hardhat.config.ts index 7b540748d..9dddd006b 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -38,7 +38,7 @@ const config: HardhatUserConfig = { // network for tests/in-process stuff forking: useEnv('FORK') ? { - url: forkRpcs[(useEnv('FORK_NETWORK') ?? 'mainnet') as Network], + url: forkRpcs[useEnv('FORK_NETWORK', 'mainnet') as Network], blockNumber: Number(useEnv(`FORK_BLOCK`, forkBlockNumber['default'].toString())), } : undefined, diff --git a/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json b/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json index ec42edd11..60168a94a 100644 --- a/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json +++ b/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json @@ -8,7 +8,8 @@ "USDbC": "0x6490D66B17A1E9a460Ab54131165C8F921aCcDeB", "cbETH": "0x5fE248625aC2AB0e17A115fef288f17AF1952402", "cUSDbCv3": "0xa372EC846131FBf9AE8b589efa3D041D9a94dF41", - "aBasUSDbC": "0x1DdB7dfdC5D26FE1f2aD02d9972f12481346Ae9b" + "aBasUSDbC": "0x1DdB7dfdC5D26FE1f2aD02d9972f12481346Ae9b", + "wsgUSDbC": "0x15395aCCbF8c6b28671fe41624D599624709a2D6" }, "erc20s": { "COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0", @@ -17,6 +18,7 @@ "USDbC": "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA", "cbETH": "0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22", "cUSDbCv3": "0xbC0033679AEf41Fb9FeB553Fdf55a8Bb2fC5B29e", - "aBasUSDbC": "0x308447562442Cc43978f8274fA722C9C14BafF8b" + "aBasUSDbC": "0x308447562442Cc43978f8274fA722C9C14BafF8b", + "wsgUSDbC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D" } -} +} \ No newline at end of file diff --git a/scripts/addresses/base-3.0.1/8453-tmp-assets-collateral.json b/scripts/addresses/base-3.0.1/8453-tmp-assets-collateral.json new file mode 100644 index 000000000..ec42edd11 --- /dev/null +++ b/scripts/addresses/base-3.0.1/8453-tmp-assets-collateral.json @@ -0,0 +1,22 @@ +{ + "assets": { + "COMP": "0x277FD5f51fE53a9B3707a0383bF930B149C74ABf" + }, + "collateral": { + "DAI": "0x5EBE8927e5495e0A7731888C81AF463cD63602fb", + "WETH": "0x42D0fA25d6d5bff01aC050c0F5aB0B2C9D01b4a3", + "USDbC": "0x6490D66B17A1E9a460Ab54131165C8F921aCcDeB", + "cbETH": "0x5fE248625aC2AB0e17A115fef288f17AF1952402", + "cUSDbCv3": "0xa372EC846131FBf9AE8b589efa3D041D9a94dF41", + "aBasUSDbC": "0x1DdB7dfdC5D26FE1f2aD02d9972f12481346Ae9b" + }, + "erc20s": { + "COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0", + "DAI": "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb", + "WETH": "0x4200000000000000000000000000000000000006", + "USDbC": "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA", + "cbETH": "0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22", + "cUSDbCv3": "0xbC0033679AEf41Fb9FeB553Fdf55a8Bb2fC5B29e", + "aBasUSDbC": "0x308447562442Cc43978f8274fA722C9C14BafF8b" + } +} diff --git a/scripts/addresses/base-3.0.1/8453-tmp-deployments.json b/scripts/addresses/base-3.0.1/8453-tmp-deployments.json new file mode 100644 index 000000000..51e21b3e9 --- /dev/null +++ b/scripts/addresses/base-3.0.1/8453-tmp-deployments.json @@ -0,0 +1,35 @@ +{ + "prerequisites": { + "RSR": "0xaB36452DbAC151bE02b16Ca17d8919826072f64a", + "RSR_FEED": "0xAa98aE504658766Dfe11F31c5D95a0bdcABDe0b1", + "GNOSIS_EASY_AUCTION": "0xb1875Feaeea32Bbb02DE83D81772e07E37A40f02" + }, + "tradingLib": "0x4E01677488384B851EeAa09C8b8F6Dd0b16d7E9B", + "cvxMiningLib": "", + "facadeRead": "0xe1aa15DA8b993c6312BAeD91E0b470AE405F91BF", + "facadeAct": "0x3d6D679c863858E89e35c925F937F5814ca687F3", + "facadeWriteLib": "0x13B63e7094B61CCbe79CAe3fb602DFd12D59314a", + "basketLib": "0x199E12d58B36deE2D2B3dD2b91aD7bb25c787a71", + "facadeWrite": "0x46c600CB3Fb7Bf386F8f53952D64aC028e289AFb", + "deployer": "0x9C75314AFD011F22648ca9C655b61674e27bA4AC", + "rsrAsset": "0x23b57479327f9BccE6A1F6Be65F3dAa3C9Db797B", + "implementations": { + "main": "0x1D6d0B74E7A701aE5C2E11967b242E9861275143", + "trading": { + "gnosisTrade": "0xcD033976a011F41D2AB6ef47984041568F818E73", + "dutchTrade": "0xDfCc89cf76aC93D113A21Da8fbfA63365b1E3DC7" + }, + "components": { + "assetRegistry": "0x9c387fc258061bd3E02c851F36aE227DB03a396C", + "backingManager": "0x8569D60Df34354CDd1115b90de832845b31C28d2", + "basketHandler": "0x25E92785C1AC01B397224E0534f3D626868A1Cbf", + "broker": "0x12c3BB1B0da85fDaE0137aE8fDe901F7D0e106ba", + "distributor": "0xd31de64957b79435bfc702044590ac417e02c19B", + "furnace": "0x45D7dFE976cdF80962d863A66918346a457b87Bd", + "rsrTrader": "0xf4C5d33DABb9D4681ED9b83618d629BA1006AE16", + "rTokenTrader": "0xf4C5d33DABb9D4681ED9b83618d629BA1006AE16", + "rToken": "0xA42850A760151bb3ACF17E7f8643EB4d864bF7a6", + "stRSR": "0x53321f03A7cce52413515DFD0527e0163ec69A46" + } + } +} \ No newline at end of file diff --git a/scripts/addresses/mainnet-3.0.0/1-tmp-assets-collateral.json b/scripts/addresses/mainnet-3.0.0/1-tmp-assets-collateral.json index 7cb86310e..d03e35446 100644 --- a/scripts/addresses/mainnet-3.0.0/1-tmp-assets-collateral.json +++ b/scripts/addresses/mainnet-3.0.0/1-tmp-assets-collateral.json @@ -17,12 +17,12 @@ "aUSDT": "0xe39188ddd4eb27d1d25f5f58cc6a5fd9228eedef", "aBUSD": "0xeB1A036E83aD95f0a28d0c8E2F20bf7f1B299F05", "aUSDP": "0x0d61Ce1801A460eB683b5ed1b6C7965d31b769Fd", - "cDAI": "0x440A634DdcFb890BCF8b0Bf07Ef2AaBB37dd5F8C", - "cUSDC": "0x50a9d529EA175CdE72525Eaa809f5C3c47dAA1bB", - "cUSDT": "0x5757fF814da66a2B4f9D11d48570d742e246CfD9", - "cUSDP": "0x99bD63BF7e2a69822cD73A82d42cF4b5501e5E50", - "cWBTC": "0x688c95461d611Ecfc423A8c87caCE163C6B40384", - "cETH": "0x357d4dB0c2179886334cC33B8528048F7E1D3Fe3", + "cDAI": "0x33A8d92B2BE84755441C2b6e39715c4b8938242c", + "cUSDC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D", + "cUSDT": "0x0EEa20c426EcE7D3dA5b73946bb1626697aA7c59", + "cUSDP": "0xA7eCF508CdF5a88ae93b899DE4fcACcB43112Ce8", + "cWBTC": "0xa570BF93FC51406809dBf52aB898913541C91C20", + "cETH": "0xeC12e8412a7AE4598d754f4016D487c269719856", "WBTC": "0x87A959e0377C68A50b08a91ae5ab3aFA7F41ACA4", "WETH": "0x6B87142C7e6cA80aa3E6ead0351673C45c8990e3", "EURT": "0xEBD07CE38e2f46031c982136012472A4D24AE070", @@ -65,12 +65,12 @@ "aUSDT": "0x21fe646D1Ed0733336F2D4d9b2FE67790a6099D9", "aBUSD": "0xe639d53Aa860757D7fe9cD4ebF9C8b92b8DedE7D", "aUSDP": "0x80A574cC2B369dc496af6655f57a16a4f180BfAF", - "cDAI": "0x3043be171e846c33D5f06864Cc045d9Fc799aF52", - "cUSDC": "0xf579F9885f1AEa0d3F8bE0F18AfED28c92a43022", - "cUSDT": "0x4Be33630F92661afD646081BC29079A38b879aA0", - "cUSDP": "0xF69c995129CC16d0F577C303091a400cC1879fFa", - "cWBTC": "0xF2A309bc36A504c772B416a4950d5d0021219745", - "cETH": "0xbF6E8F64547Bdec55bc3FBb0664722465FCC2F0F", + "cDAI": "0xD048934408bb0e39F23c7ff5C1ac5F773D16D2df", + "cUSDC": "0x1c21E28F6cd7C4Be734cb60f9c6451484803924d", + "cUSDT": "0xD971Fd59e90E836eCF2b8adE76374102025084A1", + "cUSDP": "0xbe7B053E820c5FBe70a0f075DA0C931aD8816e4F", + "cWBTC": "0xb120c3429900DDF665b34882d7685e39BB01897B", + "cETH": "0xd0cb758e918ac6973a2959343ECa4F333d8d25B1", "WBTC": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", "WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "EURT": "0xC581b735A1688071A1746c968e0798D642EDE491", diff --git a/scripts/addresses/mainnet-3.0.1/1-tmp-assets-collateral.json b/scripts/addresses/mainnet-3.0.1/1-tmp-assets-collateral.json new file mode 100644 index 000000000..d03e35446 --- /dev/null +++ b/scripts/addresses/mainnet-3.0.1/1-tmp-assets-collateral.json @@ -0,0 +1,100 @@ +{ + "assets": { + "stkAAVE": "0x6647c880Eb8F57948AF50aB45fca8FE86C154D24", + "COMP": "0xCFA67f42A0fDe4F0Fb612ea5e66170B0465B84c1", + "CRV": "0x45B950AF443281c5F67c2c7A1d9bBc325ECb8eEA", + "CVX": "0x4024c00bBD0C420E719527D88781bc1543e63dd5" + }, + "collateral": { + "DAI": "0xf7d1C6eE4C0D84C6B530D53A897daa1E9eB56833", + "USDC": "0xBE9D23040fe22E8Bd8A88BF5101061557355cA04", + "USDT": "0x58D7bF13D3572b08dE5d96373b8097d94B1325ad", + "USDP": "0x2f98bA77a8ca1c630255c4517b1b3878f6e60C89", + "TUSD": "0x7F9999B2C9D310a5f48dfD070eb5129e1e8565E2", + "BUSD": "0xCBcd605088D5A5Da9ceEb3618bc01BFB87387423", + "aDAI": "0x256b89658bD831CC40283F42e85B1fa8973Db0c9", + "aUSDC": "0x7cd9ca6401f743b38b3b16ea314bbab8e9c1ac51", + "aUSDT": "0xe39188ddd4eb27d1d25f5f58cc6a5fd9228eedef", + "aBUSD": "0xeB1A036E83aD95f0a28d0c8E2F20bf7f1B299F05", + "aUSDP": "0x0d61Ce1801A460eB683b5ed1b6C7965d31b769Fd", + "cDAI": "0x33A8d92B2BE84755441C2b6e39715c4b8938242c", + "cUSDC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D", + "cUSDT": "0x0EEa20c426EcE7D3dA5b73946bb1626697aA7c59", + "cUSDP": "0xA7eCF508CdF5a88ae93b899DE4fcACcB43112Ce8", + "cWBTC": "0xa570BF93FC51406809dBf52aB898913541C91C20", + "cETH": "0xeC12e8412a7AE4598d754f4016D487c269719856", + "WBTC": "0x87A959e0377C68A50b08a91ae5ab3aFA7F41ACA4", + "WETH": "0x6B87142C7e6cA80aa3E6ead0351673C45c8990e3", + "EURT": "0xEBD07CE38e2f46031c982136012472A4D24AE070", + "wstETH": "0x29F2EB4A0D3dC211BB488E9aBe12740cafBCc49C", + "rETH": "0x1103851D1FCDD3f88096fbed812c8FF01949cF9d", + "fUSDC": "0x3C0a9143063Fc306F7D3cBB923ff4879d70Cf1EA", + "fUSDT": "0xbe6Fb2b2908D85179e34ee0D996e32fa2BF4410A", + "fDAI": "0x33C1665Eb1b3673213Daa5f068ae1026fC8D5875", + "fFRAX": "0xaAeF84f6FfDE4D0390E14DA9c527d1a1ABf28B92", + "cUSDCv3": "0x85b256e9051B781A0BC0A987857AD6166C94040a", + "cvx3Pool": "0x62C394620f674e85768a7618a6C202baE7fB8Dd1", + "cvxeUSDFRAXBP": "0x890FAa00C16EAD6AA76F18A1A7fe9C40838F9122", + "cvxMIM3Pool": "0xCBE084C44e7A2223F76362Dcc4EbDacA5Fb1cbA7", + "crv3Pool": "0x8Af118a89c5023Bb2B03C70f70c8B396aE71963D", + "crveUSDFRAXBP": "0xC87CDFFD680D57BF50De4C364BF4277B8A90098E", + "crvMIM3Pool": "0x14c443d8BdbE9A65F3a23FA4e199d8741D5B38Fa", + "sDAI": "0xde0e2f0c9792617d3908d92a024caa846354cea2", + "cbETH": "0x3962695aCce0Efce11cFf997890f3D1D7467ec40", + "maUSDT": "0xd000a79bd2a07eb6d2e02ecad73437de40e52d69", + "maUSDC": "0x2304E98cD1E2F0fd3b4E30A1Bc6E9594dE2ea9b7", + "maDAI": "0x9d38BFF9Af50738DF92a54Ceab2a2C2322BB1FAB", + "maWBTC": "0x49A44d50d3B1E098DAC9402c4aF8D0C0E499F250", + "maWETH": "0x878b995bDD2D9900BEE896Bd78ADd877672e1637", + "maStETH": "0x33E840e5711549358f6d4D11F9Ab2896B36E9822", + "aEthUSDC": "0x12c3BB1B0da85fDaE0137aE8fDe901F7D0e106ba" + }, + "erc20s": { + "stkAAVE": "0x4da27a545c0c5B758a6BA100e3a049001de870f5", + "COMP": "0xc00e94Cb662C3520282E6f5717214004A7f26888", + "CRV": "0xD533a949740bb3306d119CC777fa900bA034cd52", + "CVX": "0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B", + "DAI": "0x6B175474E89094C44Da98b954EedeAC495271d0F", + "USDC": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", + "USDT": "0xdAC17F958D2ee523a2206206994597C13D831ec7", + "USDP": "0x8E870D67F660D95d5be530380D0eC0bd388289E1", + "TUSD": "0x0000000000085d4780B73119b644AE5ecd22b376", + "BUSD": "0x4Fabb145d64652a948d72533023f6E7A623C7C53", + "aDAI": "0xafd16aFdE22D42038223A6FfDF00ee49c8fDa985", + "aUSDC": "0x60C384e226b120d93f3e0F4C502957b2B9C32B15", + "aUSDT": "0x21fe646D1Ed0733336F2D4d9b2FE67790a6099D9", + "aBUSD": "0xe639d53Aa860757D7fe9cD4ebF9C8b92b8DedE7D", + "aUSDP": "0x80A574cC2B369dc496af6655f57a16a4f180BfAF", + "cDAI": "0xD048934408bb0e39F23c7ff5C1ac5F773D16D2df", + "cUSDC": "0x1c21E28F6cd7C4Be734cb60f9c6451484803924d", + "cUSDT": "0xD971Fd59e90E836eCF2b8adE76374102025084A1", + "cUSDP": "0xbe7B053E820c5FBe70a0f075DA0C931aD8816e4F", + "cWBTC": "0xb120c3429900DDF665b34882d7685e39BB01897B", + "cETH": "0xd0cb758e918ac6973a2959343ECa4F333d8d25B1", + "WBTC": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", + "WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", + "EURT": "0xC581b735A1688071A1746c968e0798D642EDE491", + "wstETH": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", + "rETH": "0xae78736Cd615f374D3085123A210448E74Fc6393", + "fUSDC": "0x465a5a630482f3abD6d3b84B39B29b07214d19e5", + "fUSDT": "0x81994b9607e06ab3d5cF3AffF9a67374f05F27d7", + "fDAI": "0xe2bA8693cE7474900A045757fe0efCa900F6530b", + "fFRAX": "0x1C9A2d6b33B4826757273D47ebEe0e2DddcD978B", + "cUSDCv3": "0x7e1e077b289c0153b5ceAD9F264d66215341c9Ab", + "cvx3Pool": "0xaBd7E7a5C846eD497681a590feBED99e7157B6a3", + "cvxeUSDFRAXBP": "0x3BECE5EC596331033726E5C6C188c313Ff4E3fE5", + "cvxMIM3Pool": "0x9FF9c353136e86EFe02ADD177E7c9769f8a5A77F", + "crv3Pool": "0xC9c37FC53682207844B058026024853A9C0b8c7B", + "crveUSDFRAXBP": "0x27F672aAf061cb0b2640a4DFCCBd799cD1a7309A", + "crvMIM3Pool": "0xe8461dB45A7430AA7aB40346E68821284980FdFD", + "sDAI": "0x83f20f44975d03b1b09e64809b757c47f942beea", + "cbETH": "0xBe9895146f7AF43049ca1c1AE358B0541Ea49704", + "maUSDT": "0xaA91d24c2F7DBb6487f61869cD8cd8aFd5c5Cab2", + "maUSDC": "0x7f7b77e49d5b30445f222764a794afe14af062eb", + "maDAI": "0xE2b16e14dB6216e33082D5A8Be1Ef01DF7511bBb", + "maWBTC": "0xe0E1d3c6f09DA01399e84699722B11308607BBfC", + "maWETH": "0x291ed25eB61fcc074156eE79c5Da87e5DA94198F", + "maStETH": "0x97F9d5ed17A0C99B279887caD5254d15fb1B619B", + "aEthUSDC": "0x63e12c3b2DBCaeF1835Bb99Ac1Fdb0Ebe1bE69bE" + } +} \ No newline at end of file diff --git a/scripts/addresses/mainnet-3.0.1/1-tmp-deployments.json b/scripts/addresses/mainnet-3.0.1/1-tmp-deployments.json new file mode 100644 index 000000000..33f966462 --- /dev/null +++ b/scripts/addresses/mainnet-3.0.1/1-tmp-deployments.json @@ -0,0 +1,35 @@ +{ + "prerequisites": { + "RSR": "0x320623b8e4ff03373931769a31fc52a4e78b5d70", + "RSR_FEED": "0x759bBC1be8F90eE6457C44abc7d443842a976d02", + "GNOSIS_EASY_AUCTION": "0x0b7fFc1f4AD541A4Ed16b40D8c37f0929158D101" + }, + "tradingLib": "0xB81a1fa9A497953CEC7f370CACFA5cc364871A73", + "cvxMiningLib": "0xeA4ecB9519Bae14bf343ddde0406C2D6108c1472", + "facadeRead": "0x81b9Ae0740CcA7cDc5211b2737de735FBC4BeB3C", + "facadeAct": "0x801fF27bacc7C00fBef17FC901504c79D59E845C", + "facadeWriteLib": "0x908Cd3B4B4B6c60d5EB7d1Ca7ECda0e7ceCd6dB1", + "basketLib": "0xA87e9DAe6E9EA5B2Be858686CC6c21B953BfE0B8", + "facadeWrite": "0x3312507BC3F22430B34D5841A472c767DC5C36e4", + "deployer": "0x43587CAA7dE69C3c2aD0fb73D4C9da67A8E35b0b", + "rsrAsset": "0x7edD40933DfdA0ecEe1ad3E61a5044962284e1A6", + "implementations": { + "main": "0xF5366f67FF66A3CefcB18809a762D5b5931FebF8", + "trading": { + "gnosisTrade": "0x4e9B97957a0d1F4c25E42Ccc69E4d2665433FEA3", + "dutchTrade": "0x2387C22727ACb91519b80A15AEf393ad40dFdb2F" + }, + "components": { + "assetRegistry": "0x773cf50adCF1730964D4A9b664BaEd4b9FFC2450", + "backingManager": "0xBbC532A80DD141449330c1232C953Da6801Aed01", + "basketHandler": "0x5ccca36CbB66a4E4033B08b4F6D7bAc96bA55cDc", + "broker": "0x9A5F8A9bB91a868b7501139eEdB20dC129D28F04", + "distributor": "0x0e8439a17bA5cBb2D9823c03a02566B9dd5d96Ac", + "furnace": "0x99580Fc649c02347eBc7750524CAAe5cAcf9d34c", + "rsrTrader": "0x5e3e13d3d2a0adfe16f8EF5E7a2992A88E9e65AF", + "rTokenTrader": "0x5e3e13d3d2a0adfe16f8EF5E7a2992A88E9e65AF", + "rToken": "0xb6f01Aa21defA4a4DE33Bed16BcC06cfd23b6A6F", + "stRSR": "0xC98eaFc9F249D90e3E35E729e3679DD75A899c10" + } + } +} \ No newline at end of file diff --git a/scripts/deploy.ts b/scripts/deploy.ts index 12e104aee..db067c336 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -47,6 +47,7 @@ async function main() { 'phase2-assets/assets/deploy_crv.ts', 'phase2-assets/assets/deploy_cvx.ts', 'phase2-assets/2_deploy_collateral.ts', + 'phase2-assets/collaterals/deploy_compound_v2_collateral.ts', 'phase2-assets/collaterals/deploy_lido_wsteth_collateral.ts', 'phase2-assets/collaterals/deploy_rocket_pool_reth_collateral.ts', 'phase2-assets/collaterals/deploy_flux_finance_collateral.ts', diff --git a/scripts/deployment/phase1-common/3_deploy_rsrAsset.ts b/scripts/deployment/phase1-common/3_deploy_rsrAsset.ts index e67a33f60..f33da05e8 100644 --- a/scripts/deployment/phase1-common/3_deploy_rsrAsset.ts +++ b/scripts/deployment/phase1-common/3_deploy_rsrAsset.ts @@ -6,7 +6,7 @@ import { networkConfig } from '../../../common/configuration' import { ZERO_ADDRESS } from '../../../common/constants' import { fp } from '../../../common/numbers' import { getDeploymentFile, getDeploymentFilename, IDeployments } from '../../deployment/common' -import { priceTimeout, oracleTimeout, validateImplementations } from '../../deployment/utils' +import { priceTimeout, validateImplementations } from '../../deployment/utils' import { Asset } from '../../../typechain' let rsrAsset: Asset @@ -36,7 +36,7 @@ async function main() { tokenAddress: deployments.prerequisites.RSR, rewardToken: ZERO_ADDRESS, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24h + oracleTimeout: '86400', // 24h }) rsrAsset = await ethers.getContractAt('Asset', rsrAssetAddr) diff --git a/scripts/deployment/phase2-assets/1_deploy_assets.ts b/scripts/deployment/phase2-assets/1_deploy_assets.ts index cab49a551..93a8a6939 100644 --- a/scripts/deployment/phase2-assets/1_deploy_assets.ts +++ b/scripts/deployment/phase2-assets/1_deploy_assets.ts @@ -10,7 +10,7 @@ import { IAssetCollDeployments, fileExists, } from '../../deployment/common' -import { priceTimeout, oracleTimeout } from '../../deployment/utils' +import { priceTimeout } from '../../deployment/utils' import { Asset } from '../../../typechain' async function main() { @@ -44,7 +44,7 @@ async function main() { oracleError: fp('0.01').toString(), // 1% tokenAddress: networkConfig[chainId].tokens.stkAAVE, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr }) await (await ethers.getContractAt('Asset', stkAAVEAsset)).refresh() @@ -60,7 +60,7 @@ async function main() { oracleError: fp('0.01').toString(), // 1% tokenAddress: networkConfig[chainId].tokens.COMP, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr }) await (await ethers.getContractAt('Asset', compAsset)).refresh() diff --git a/scripts/deployment/phase2-assets/2_deploy_collateral.ts b/scripts/deployment/phase2-assets/2_deploy_collateral.ts index b232dc5ed..5a58c3bea 100644 --- a/scripts/deployment/phase2-assets/2_deploy_collateral.ts +++ b/scripts/deployment/phase2-assets/2_deploy_collateral.ts @@ -12,7 +12,7 @@ import { getDeploymentFilename, fileExists, } from '../common' -import { combinedError, priceTimeout, oracleTimeout, revenueHiding } from '../utils' +import { combinedError, priceTimeout, revenueHiding } from '../utils' import { ICollateral, ATokenMock, StaticATokenLM } from '../../../typechain' async function main() { @@ -43,7 +43,7 @@ async function main() { let collateral: ICollateral /******** Deploy Fiat Collateral - DAI **************************/ - const daiOracleTimeout = baseL2Chains.includes(hre.network.name) ? 86400 : 3600 // 24 hr (Base) or 1 hour + const daiOracleTimeout = baseL2Chains.includes(hre.network.name) ? '86400' : '3600' // 24 hr (Base) or 1 hour const daiOracleError = baseL2Chains.includes(hre.network.name) ? fp('0.003') : fp('0.0025') // 0.3% (Base) or 0.25% if (networkConfig[chainId].tokens.DAI && networkConfig[chainId].chainlinkFeeds.DAI) { @@ -53,7 +53,7 @@ async function main() { oracleError: daiOracleError.toString(), tokenAddress: networkConfig[chainId].tokens.DAI, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, daiOracleTimeout).toString(), + oracleTimeout: daiOracleTimeout, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(daiOracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h @@ -69,7 +69,7 @@ async function main() { fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) } - const usdcOracleTimeout = 86400 // 24 hr + const usdcOracleTimeout = '86400' // 24 hr const usdcOracleError = baseL2Chains.includes(hre.network.name) ? fp('0.003') : fp('0.0025') // 0.3% (Base) or 0.25% /******** Deploy Fiat Collateral - USDC **************************/ @@ -80,7 +80,7 @@ async function main() { oracleError: usdcOracleError.toString(), tokenAddress: networkConfig[chainId].tokens.USDC, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout).toString(), // 24 hr + oracleTimeout: usdcOracleTimeout, // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdcOracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h @@ -97,7 +97,7 @@ async function main() { } /******** Deploy Fiat Collateral - USDT **************************/ - const usdtOracleTimeout = 86400 // 24 hr + const usdtOracleTimeout = '86400' // 24 hr const usdtOracleError = baseL2Chains.includes(hre.network.name) ? fp('0.003') : fp('0.0025') // 0.3% (Base) or 0.25% if (networkConfig[chainId].tokens.USDT && networkConfig[chainId].chainlinkFeeds.USDT) { @@ -107,7 +107,7 @@ async function main() { oracleError: usdtOracleError.toString(), tokenAddress: networkConfig[chainId].tokens.USDT, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, usdtOracleTimeout).toString(), // 24 hr + oracleTimeout: usdtOracleTimeout, // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdtOracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h @@ -132,7 +132,7 @@ async function main() { oracleError: fp('0.01').toString(), // 1% tokenAddress: networkConfig[chainId].tokens.USDP, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.02').toString(), // 2% delayUntilDefault: bn('86400').toString(), // 24h @@ -156,7 +156,7 @@ async function main() { oracleError: fp('0.003').toString(), // 0.3% tokenAddress: networkConfig[chainId].tokens.TUSD, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.013').toString(), // 1.3% delayUntilDefault: bn('86400').toString(), // 24h @@ -179,7 +179,7 @@ async function main() { oracleError: fp('0.005').toString(), // 0.5% tokenAddress: networkConfig[chainId].tokens.BUSD, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.015').toString(), // 1.5% delayUntilDefault: bn('86400').toString(), // 24h @@ -203,7 +203,7 @@ async function main() { oracleError: usdcOracleError.toString(), tokenAddress: networkConfig[chainId].tokens.USDbC, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout).toString(), // 24 hr + oracleTimeout: usdcOracleTimeout, // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdcOracleError).toString(), // 1.3% delayUntilDefault: bn('86400').toString(), // 24h @@ -249,7 +249,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% staticAToken: adaiStaticToken.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -293,7 +293,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% staticAToken: ausdcStaticToken.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -337,7 +337,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% staticAToken: ausdtStaticToken.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -380,7 +380,7 @@ async function main() { oracleError: fp('0.005').toString(), // 0.5% staticAToken: abusdStaticToken.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.015').toString(), // 1.5% delayUntilDefault: bn('86400').toString(), // 24h @@ -424,7 +424,7 @@ async function main() { oracleError: fp('0.01').toString(), // 1% staticAToken: ausdpStaticToken.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.02').toString(), // 2% delayUntilDefault: bn('86400').toString(), // 24h @@ -470,7 +470,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% cToken: cDaiVault.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -508,7 +508,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% cToken: cUsdcVault.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -546,7 +546,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% cToken: cUsdtVault.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -584,7 +584,7 @@ async function main() { oracleError: fp('0.01').toString(), // 1% cToken: cUsdpVault.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.02').toString(), // 2% delayUntilDefault: bn('86400').toString(), // 24h @@ -623,8 +623,8 @@ async function main() { combinedOracleError: combinedBTCWBTCError.toString(), cToken: cWBTCVault.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr - targetUnitOracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '86400', // 24 hr + targetUnitOracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('BTC'), defaultThreshold: fp('0.01').add(combinedBTCWBTCError).toString(), // ~3.5% delayUntilDefault: bn('86400').toString(), // 24h @@ -664,7 +664,7 @@ async function main() { oracleError: fp('0.005').toString(), // 0.5% cToken: cETHVault.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('ETH'), revenueHiding: revenueHiding.toString(), referenceERC20Decimals: '18', @@ -694,8 +694,8 @@ async function main() { combinedOracleError: combinedBTCWBTCError.toString(), tokenAddress: networkConfig[chainId].tokens.WBTC, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr - targetUnitOracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '86400', // 24 hr + targetUnitOracleTimeout: '3600', // 1 hr targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: fp('0.01').add(combinedBTCWBTCError).toString(), // ~3.5% delayUntilDefault: bn('86400').toString(), // 24h @@ -713,7 +713,7 @@ async function main() { /******** Deploy Self Referential Collateral - wETH **************************/ if (networkConfig[chainId].tokens.WETH && networkConfig[chainId].chainlinkFeeds.ETH) { - const ethOracleTimeout = baseL2Chains.includes(hre.network.name) ? 1200 : 3600 // 20 min (Base) or 1 hr + const ethOracleTimeout = baseL2Chains.includes(hre.network.name) ? '1200' : '3600' // 20 min (Base) or 1 hr const ethOracleError = baseL2Chains.includes(hre.network.name) ? fp('0.0015') : fp('0.005') // 0.15% (Base) or 0.5% const { collateral: wETHCollateral } = await hre.run('deploy-selfreferential-collateral', { @@ -722,7 +722,7 @@ async function main() { oracleError: ethOracleError.toString(), tokenAddress: networkConfig[chainId].tokens.WETH, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, ethOracleTimeout).toString(), + oracleTimeout: ethOracleTimeout, targetName: hre.ethers.utils.formatBytes32String('ETH'), }) collateral = await ethers.getContractAt('ICollateral', wETHCollateral) @@ -751,8 +751,8 @@ async function main() { oracleError: eurtError.toString(), // 2% tokenAddress: networkConfig[chainId].tokens.EURT, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr - targetUnitOracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr + targetUnitOracleTimeout: '86400', // 24 hr targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: fp('0.03').toString(), // 3% delayUntilDefault: bn('86400').toString(), // 24h diff --git a/scripts/deployment/phase2-assets/assets/deploy_crv.ts b/scripts/deployment/phase2-assets/assets/deploy_crv.ts index f0db202b9..80eb3f6c1 100644 --- a/scripts/deployment/phase2-assets/assets/deploy_crv.ts +++ b/scripts/deployment/phase2-assets/assets/deploy_crv.ts @@ -10,7 +10,7 @@ import { IAssetCollDeployments, fileExists, } from '../../../deployment/common' -import { priceTimeout, oracleTimeout } from '../../../deployment/utils' +import { priceTimeout } from '../../../deployment/utils' import { Asset } from '../../../../typechain' async function main() { @@ -43,7 +43,7 @@ async function main() { oracleError: fp('0.01').toString(), // 1% tokenAddress: networkConfig[chainId].tokens.CRV, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr }) await (await ethers.getContractAt('Asset', crvAsset)).refresh() diff --git a/scripts/deployment/phase2-assets/assets/deploy_cvx.ts b/scripts/deployment/phase2-assets/assets/deploy_cvx.ts index 1c5aaa57c..cb7eb2d5d 100644 --- a/scripts/deployment/phase2-assets/assets/deploy_cvx.ts +++ b/scripts/deployment/phase2-assets/assets/deploy_cvx.ts @@ -10,7 +10,7 @@ import { IAssetCollDeployments, fileExists, } from '../../../deployment/common' -import { priceTimeout, oracleTimeout } from '../../../deployment/utils' +import { priceTimeout } from '../../../deployment/utils' import { Asset } from '../../../../typechain' async function main() { @@ -43,7 +43,7 @@ async function main() { oracleError: fp('0.02').toString(), // 2% tokenAddress: networkConfig[chainId].tokens.CVX, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr }) await (await ethers.getContractAt('Asset', cvxAsset)).refresh() diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_usdbc.ts b/scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_usdbc.ts index e7fbc9851..f930201a2 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_usdbc.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_usdbc.ts @@ -13,7 +13,7 @@ import { } from '../../common' import { bn, fp } from '#/common/numbers' import { AaveV3FiatCollateral } from '../../../../typechain' -import { priceTimeout, revenueHiding, oracleTimeout } from '../../utils' +import { priceTimeout, revenueHiding } from '../../utils' // This file specifically deploys Aave V3 USDC collateral @@ -77,7 +77,7 @@ async function main() { oracleError: fp('0.003'), // 3% erc20: erc20.address, maxTradeVolume: fp('1e6'), - oracleTimeout: oracleTimeout(chainId, bn('86400')), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.013'), delayUntilDefault: bn('86400'), diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_usdc.ts b/scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_usdc.ts index 2d56f9d3f..2d4eb8112 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_usdc.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_usdc.ts @@ -13,7 +13,7 @@ import { } from '../../common' import { bn, fp } from '#/common/numbers' import { AaveV3FiatCollateral } from '../../../../typechain' -import { priceTimeout, revenueHiding, oracleTimeout } from '../../utils' +import { priceTimeout, revenueHiding } from '../../utils' // This file specifically deploys Aave V3 USDC collateral @@ -68,7 +68,7 @@ async function main() { ) /******** Deploy Aave V3 USDC collateral plugin **************************/ - const usdcOracleTimeout = 86400 // 24 hr + const usdcOracleTimeout = '86400' // 24 hr const usdcOracleError = baseL2Chains.includes(hre.network.name) ? fp('0.003') : fp('0.0025') // 0.3% (Base) or 0.25% const CollateralFactory = await ethers.getContractFactory('AaveV3FiatCollateral') @@ -79,7 +79,7 @@ async function main() { oracleError: usdcOracleError, erc20: erc20.address, maxTradeVolume: fp('1e6'), - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout), + oracleTimeout: usdcOracleTimeout, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdcOracleError), delayUntilDefault: bn('86400'), diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_cbeth_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_cbeth_collateral.ts index eab685015..18984099f 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_cbeth_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_cbeth_collateral.ts @@ -12,7 +12,7 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { priceTimeout, oracleTimeout, combinedError } from '../../utils' +import { priceTimeout, combinedError } from '../../utils' import { CBEthCollateral, CBEthCollateralL2, @@ -62,14 +62,14 @@ async function main() { oracleError: oracleError.toString(), // 0.5% & 2%, erc20: networkConfig[chainId].tokens.cbETH!, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr, + oracleTimeout: '3600', // 1 hr, targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.02').add(oracleError).toString(), // ~4.5% delayUntilDefault: bn('86400').toString(), // 24h }, fp('1e-4').toString(), // revenueHiding = 0.01% networkConfig[chainId].chainlinkFeeds.cbETH!, // refPerTokChainlinkFeed - oracleTimeout(chainId, '86400').toString() // refPerTokChainlinkTimeout + '86400' // refPerTokChainlinkTimeout ) await collateral.deployed() await (await collateral.refresh()).wait() @@ -89,16 +89,16 @@ async function main() { oracleError: oracleError.toString(), // 0.15% & 0.5%, erc20: networkConfig[chainId].tokens.cbETH!, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '1200').toString(), // 20 min + oracleTimeout: '1200', // 20 min targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.02').add(oracleError).toString(), // ~2.5% delayUntilDefault: bn('86400').toString(), // 24h }, fp('1e-4').toString(), // revenueHiding = 0.01% networkConfig[chainId].chainlinkFeeds.cbETH!, // refPerTokChainlinkFeed - oracleTimeout(chainId, '86400').toString(), // refPerTokChainlinkTimeout + '86400', // refPerTokChainlinkTimeout networkConfig[chainId].chainlinkFeeds.cbETHETHexr!, // exchangeRateChainlinkFeed - oracleTimeout(chainId, '86400').toString() // exchangeRateChainlinkTimeout + '86400' // exchangeRateChainlinkTimeout ) await collateral.deployed() await (await collateral.refresh()).wait() diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_compound_v2_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_compound_v2_collateral.ts new file mode 100644 index 000000000..89b2464c5 --- /dev/null +++ b/scripts/deployment/phase2-assets/collaterals/deploy_compound_v2_collateral.ts @@ -0,0 +1,293 @@ +import fs from 'fs' +import hre, { ethers } from 'hardhat' +import { expect } from 'chai' +import { getChainId } from '../../../../common/blockchain-utils' +import { baseL2Chains, networkConfig } from '../../../../common/configuration' +import { bn, fp } from '../../../../common/numbers' +import { CollateralStatus } from '../../../../common/constants' +import { + getDeploymentFile, + getAssetCollDeploymentFilename, + IAssetCollDeployments, + getDeploymentFilename, + fileExists, +} from '../../common' +import { combinedError, priceTimeout, revenueHiding } from '../../utils' +import { ICollateral } from '../../../../typechain' + +async function main() { + // ==== Read Configuration ==== + const [burner] = await hre.ethers.getSigners() + + const chainId = await getChainId(hre) + + console.log(`Deploying Collateral to network ${hre.network.name} (${chainId}) + with burner account: ${burner.address}`) + + if (!networkConfig[chainId]) { + throw new Error(`Missing network configuration for ${hre.network.name}`) + } + + // Get phase1 deployment + const phase1File = getDeploymentFilename(chainId) + if (!fileExists(phase1File)) { + throw new Error(`${phase1File} doesn't exist yet. Run phase 1`) + } + // Check previous step completed + const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) + const assetCollDeployments = getDeploymentFile(assetCollDeploymentFilename) + + // Get Oracle Lib address if previously deployed (can override with arbitrary address) + const deployedCollateral: string[] = [] + + let collateral: ICollateral + + const wbtcOracleError = fp('0.02') // 2% + const btcOracleError = fp('0.005') // 0.5% + const combinedBTCWBTCError = combinedError(wbtcOracleError, btcOracleError) + + /*** Compound V2 not available in Base L2s */ + if (!baseL2Chains.includes(hre.network.name)) { + /******** Deploy CToken Fiat Collateral - cDAI **************************/ + const CTokenFactory = await ethers.getContractFactory('CTokenWrapper') + const cDai = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cDAI!) + + const cDaiVault = await CTokenFactory.deploy( + networkConfig[chainId].tokens.cDAI!, + `${await cDai.name()} Vault`, + `${await cDai.symbol()}-VAULT`, + networkConfig[chainId].COMPTROLLER! + ) + + await cDaiVault.deployed() + + console.log( + `Deployed Vault for cDAI on ${hre.network.name} (${chainId}): ${cDaiVault.address} ` + ) + + const { collateral: cDaiCollateral } = await hre.run('deploy-ctoken-fiat-collateral', { + priceTimeout: priceTimeout.toString(), + priceFeed: networkConfig[chainId].chainlinkFeeds.DAI, + oracleError: fp('0.0025').toString(), // 0.25% + cToken: cDaiVault.address, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: '3600', // 1 hr + targetName: hre.ethers.utils.formatBytes32String('USD'), + defaultThreshold: fp('0.0125').toString(), // 1.25% + delayUntilDefault: bn('86400').toString(), // 24h + revenueHiding: revenueHiding.toString(), + }) + collateral = await ethers.getContractAt('ICollateral', cDaiCollateral) + await (await collateral.refresh()).wait() + expect(await collateral.status()).to.equal(CollateralStatus.SOUND) + + assetCollDeployments.collateral.cDAI = cDaiCollateral + assetCollDeployments.erc20s.cDAI = cDaiVault.address + deployedCollateral.push(cDaiCollateral.toString()) + + fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) + + /******** Deploy CToken Fiat Collateral - cUSDC **************************/ + const cUsdc = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cUSDC!) + + const cUsdcVault = await CTokenFactory.deploy( + networkConfig[chainId].tokens.cUSDC!, + `${await cUsdc.name()} Vault`, + `${await cUsdc.symbol()}-VAULT`, + networkConfig[chainId].COMPTROLLER! + ) + + await cUsdcVault.deployed() + + console.log( + `Deployed Vault for cUSDC on ${hre.network.name} (${chainId}): ${cUsdcVault.address} ` + ) + + const { collateral: cUsdcCollateral } = await hre.run('deploy-ctoken-fiat-collateral', { + priceTimeout: priceTimeout.toString(), + priceFeed: networkConfig[chainId].chainlinkFeeds.USDC, + oracleError: fp('0.0025').toString(), // 0.25% + cToken: cUsdcVault.address, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: '86400', // 24 hr + targetName: hre.ethers.utils.formatBytes32String('USD'), + defaultThreshold: fp('0.0125').toString(), // 1.25% + delayUntilDefault: bn('86400').toString(), // 24h + revenueHiding: revenueHiding.toString(), + }) + collateral = await ethers.getContractAt('ICollateral', cUsdcCollateral) + await (await collateral.refresh()).wait() + expect(await collateral.status()).to.equal(CollateralStatus.SOUND) + + assetCollDeployments.collateral.cUSDC = cUsdcCollateral + assetCollDeployments.erc20s.cUSDC = cUsdcVault.address + deployedCollateral.push(cUsdcCollateral.toString()) + + fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) + + /******** Deploy CToken Fiat Collateral - cUSDT **************************/ + const cUsdt = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cUSDT!) + + const cUsdtVault = await CTokenFactory.deploy( + networkConfig[chainId].tokens.cUSDT!, + `${await cUsdt.name()} Vault`, + `${await cUsdt.symbol()}-VAULT`, + networkConfig[chainId].COMPTROLLER! + ) + + await cUsdtVault.deployed() + + console.log( + `Deployed Vault for cUSDT on ${hre.network.name} (${chainId}): ${cUsdtVault.address} ` + ) + + const { collateral: cUsdtCollateral } = await hre.run('deploy-ctoken-fiat-collateral', { + priceTimeout: priceTimeout.toString(), + priceFeed: networkConfig[chainId].chainlinkFeeds.USDT, + oracleError: fp('0.0025').toString(), // 0.25% + cToken: cUsdtVault.address, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: '86400', // 24 hr + targetName: hre.ethers.utils.formatBytes32String('USD'), + defaultThreshold: fp('0.0125').toString(), // 1.25% + delayUntilDefault: bn('86400').toString(), // 24h + revenueHiding: revenueHiding.toString(), + }) + collateral = await ethers.getContractAt('ICollateral', cUsdtCollateral) + await (await collateral.refresh()).wait() + expect(await collateral.status()).to.equal(CollateralStatus.SOUND) + + assetCollDeployments.collateral.cUSDT = cUsdtCollateral + assetCollDeployments.erc20s.cUSDT = cUsdtVault.address + deployedCollateral.push(cUsdtCollateral.toString()) + + fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) + + /******** Deploy CToken Fiat Collateral - cUSDP **************************/ + const cUsdp = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cUSDP!) + + const cUsdpVault = await CTokenFactory.deploy( + networkConfig[chainId].tokens.cUSDP!, + `${await cUsdp.name()} Vault`, + `${await cUsdp.symbol()}-VAULT`, + networkConfig[chainId].COMPTROLLER! + ) + + await cUsdpVault.deployed() + + console.log( + `Deployed Vault for cUSDP on ${hre.network.name} (${chainId}): ${cUsdpVault.address} ` + ) + + const { collateral: cUsdpCollateral } = await hre.run('deploy-ctoken-fiat-collateral', { + priceTimeout: priceTimeout.toString(), + priceFeed: networkConfig[chainId].chainlinkFeeds.USDP, + oracleError: fp('0.01').toString(), // 1% + cToken: cUsdpVault.address, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: '3600', // 1 hr + targetName: hre.ethers.utils.formatBytes32String('USD'), + defaultThreshold: fp('0.02').toString(), // 2% + delayUntilDefault: bn('86400').toString(), // 24h + revenueHiding: revenueHiding.toString(), + }) + collateral = await ethers.getContractAt('ICollateral', cUsdpCollateral) + await (await collateral.refresh()).wait() + expect(await collateral.status()).to.equal(CollateralStatus.SOUND) + + assetCollDeployments.collateral.cUSDP = cUsdpCollateral + assetCollDeployments.erc20s.cUSDP = cUsdpVault.address + deployedCollateral.push(cUsdpCollateral.toString()) + + fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) + + /******** Deploy CToken Non-Fiat Collateral - cWBTC **************************/ + const cWBTC = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cWBTC!) + + const cWBTCVault = await CTokenFactory.deploy( + networkConfig[chainId].tokens.cWBTC!, + `${await cWBTC.name()} Vault`, + `${await cWBTC.symbol()}-VAULT`, + networkConfig[chainId].COMPTROLLER! + ) + + await cWBTCVault.deployed() + + console.log( + `Deployed Vault for cWBTC on ${hre.network.name} (${chainId}): ${cWBTCVault.address} ` + ) + + const { collateral: cWBTCCollateral } = await hre.run('deploy-ctoken-nonfiat-collateral', { + priceTimeout: priceTimeout.toString(), + referenceUnitFeed: networkConfig[chainId].chainlinkFeeds.WBTC, + targetUnitFeed: networkConfig[chainId].chainlinkFeeds.BTC, + combinedOracleError: combinedBTCWBTCError.toString(), + cToken: cWBTCVault.address, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: '86400', // 24 hr + targetUnitOracleTimeout: '3600', // 1 hr + targetName: hre.ethers.utils.formatBytes32String('BTC'), + defaultThreshold: fp('0.01').add(combinedBTCWBTCError).toString(), // ~3.5% + delayUntilDefault: bn('86400').toString(), // 24h + revenueHiding: revenueHiding.toString(), + }) + collateral = await ethers.getContractAt('ICollateral', cWBTCCollateral) + await (await collateral.refresh()).wait() + expect(await collateral.status()).to.equal(CollateralStatus.SOUND) + + assetCollDeployments.collateral.cWBTC = cWBTCCollateral + assetCollDeployments.erc20s.cWBTC = cWBTCVault.address + deployedCollateral.push(cWBTCCollateral.toString()) + + fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) + + /******** Deploy CToken Self-Referential Collateral - cETH **************************/ + const cETH = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cETH!) + + const cETHVault = await CTokenFactory.deploy( + networkConfig[chainId].tokens.cETH!, + `${await cETH.name()} Vault`, + `${await cETH.symbol()}-VAULT`, + networkConfig[chainId].COMPTROLLER! + ) + + await cETHVault.deployed() + + console.log( + `Deployed Vault for cETH on ${hre.network.name} (${chainId}): ${cETHVault.address} ` + ) + + const { collateral: cETHCollateral } = await hre.run( + 'deploy-ctoken-selfreferential-collateral', + { + priceTimeout: priceTimeout.toString(), + priceFeed: networkConfig[chainId].chainlinkFeeds.ETH, + oracleError: fp('0.005').toString(), // 0.5% + cToken: cETHVault.address, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: '3600', // 1 hr + targetName: hre.ethers.utils.formatBytes32String('ETH'), + revenueHiding: revenueHiding.toString(), + referenceERC20Decimals: '18', + } + ) + collateral = await ethers.getContractAt('ICollateral', cETHCollateral) + await (await collateral.refresh()).wait() + expect(await collateral.status()).to.equal(CollateralStatus.SOUND) + + assetCollDeployments.collateral.cETH = cETHCollateral + assetCollDeployments.erc20s.cETH = cETHVault.address + deployedCollateral.push(cETHCollateral.toString()) + + fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) + } + + console.log(`Deployed collateral to ${hre.network.name} (${chainId}) + New deployments: ${deployedCollateral} + Deployment file: ${assetCollDeploymentFilename}`) +} + +main().catch((error) => { + console.error(error) + process.exitCode = 1 +}) diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_convex_rToken_metapool_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_convex_rToken_metapool_plugin.ts index dae7875b3..e7b53d4f5 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_convex_rToken_metapool_plugin.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_convex_rToken_metapool_plugin.ts @@ -14,7 +14,7 @@ import { fileExists, } from '../../common' import { CurveStableRTokenMetapoolCollateral } from '../../../../typechain' -import { revenueHiding, oracleTimeout } from '../../utils' +import { revenueHiding } from '../../utils' import { CurvePoolType, DEFAULT_THRESHOLD, @@ -87,7 +87,7 @@ async function main() { priceTimeout: PRICE_TIMEOUT, chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDC_ORACLE_TIMEOUT), // max of oracleTimeouts + oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts maxTradeVolume: MAX_TRADE_VOL, defaultThreshold: DEFAULT_THRESHOLD, // 2%: 1% error on FRAX oracle + 1% base defaultThreshold delayUntilDefault: RTOKEN_DELAY_UNTIL_DEFAULT, @@ -98,10 +98,7 @@ async function main() { curvePool: FRAX_BP, poolType: CurvePoolType.Plain, feeds: [[FRAX_USD_FEED], [USDC_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, FRAX_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[FRAX_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT]], oracleErrors: [[FRAX_ORACLE_ERROR], [USDC_ORACLE_ERROR]], lpToken: FRAX_BP_TOKEN, }, diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_convex_stable_metapool_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_convex_stable_metapool_plugin.ts index 72d0f7deb..4a2c1c6ea 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_convex_stable_metapool_plugin.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_convex_stable_metapool_plugin.ts @@ -13,7 +13,7 @@ import { fileExists, } from '../../common' import { CurveStableMetapoolCollateral } from '../../../../typechain' -import { revenueHiding, oracleTimeout } from '../../utils' +import { revenueHiding } from '../../utils' import { CurvePoolType, DELAY_UNTIL_DEFAULT, @@ -105,11 +105,7 @@ async function main() { curvePool: THREE_POOL, poolType: CurvePoolType.Plain, feeds: [[DAI_USD_FEED], [USDC_USD_FEED], [USDT_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, DAI_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[DAI_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT], [USDT_ORACLE_TIMEOUT]], oracleErrors: [[DAI_ORACLE_ERROR], [USDC_ORACLE_ERROR], [USDT_ORACLE_ERROR]], lpToken: THREE_POOL_TOKEN, }, diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_convex_stable_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_convex_stable_plugin.ts index 97a8fc4f2..bc52c467c 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_convex_stable_plugin.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_convex_stable_plugin.ts @@ -14,7 +14,7 @@ import { fileExists, } from '../../common' import { CurveStableCollateral } from '../../../../typechain' -import { revenueHiding, oracleTimeout } from '../../utils' +import { revenueHiding } from '../../utils' import { CurvePoolType, DAI_ORACLE_ERROR, @@ -88,7 +88,7 @@ async function main() { priceTimeout: PRICE_TIMEOUT, chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDC_ORACLE_TIMEOUT), // max of oracleTimeouts + oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts maxTradeVolume: MAX_TRADE_VOL, defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -99,11 +99,7 @@ async function main() { curvePool: THREE_POOL, poolType: CurvePoolType.Plain, feeds: [[DAI_USD_FEED], [USDC_USD_FEED], [USDT_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, DAI_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[DAI_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT], [USDT_ORACLE_TIMEOUT]], oracleErrors: [[DAI_ORACLE_ERROR], [USDC_ORACLE_ERROR], [USDT_ORACLE_ERROR]], lpToken: THREE_POOL_TOKEN, } diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_convex_volatile_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_convex_volatile_plugin.ts deleted file mode 100644 index ab7131667..000000000 --- a/scripts/deployment/phase2-assets/collaterals/deploy_convex_volatile_plugin.ts +++ /dev/null @@ -1,142 +0,0 @@ -import fs from 'fs' -import hre, { ethers } from 'hardhat' -import { getChainId } from '../../../../common/blockchain-utils' -import { networkConfig } from '../../../../common/configuration' -import { bn } from '../../../../common/numbers' -import { expect } from 'chai' -import { CollateralStatus, ONE_ADDRESS } from '../../../../common/constants' -import { - getDeploymentFile, - getAssetCollDeploymentFilename, - IAssetCollDeployments, - IDeployments, - getDeploymentFilename, - fileExists, -} from '../../common' -import { CurveVolatileCollateral } from '../../../../typechain' -import { revenueHiding, oracleTimeout } from '../../utils' -import { - CurvePoolType, - BTC_USD_ORACLE_ERROR, - BTC_ORACLE_TIMEOUT, - BTC_USD_FEED, - DEFAULT_THRESHOLD, - DELAY_UNTIL_DEFAULT, - MAX_TRADE_VOL, - PRICE_TIMEOUT, - TRI_CRYPTO, - TRI_CRYPTO_TOKEN, - TRI_CRYPTO_CVX_POOL_ID, - WBTC_BTC_ORACLE_ERROR, - WETH_ORACLE_TIMEOUT, - WBTC_BTC_FEED, - WBTC_ORACLE_TIMEOUT, - WETH_USD_FEED, - WETH_ORACLE_ERROR, - USDT_ORACLE_ERROR, - USDT_ORACLE_TIMEOUT, - USDT_USD_FEED, -} from '../../../../test/plugins/individual-collateral/curve/constants' - -// This file specifically deploys Convex Volatile Plugin for Tricrypto - -async function main() { - // ==== Read Configuration ==== - const [deployer] = await hre.ethers.getSigners() - - const chainId = await getChainId(hre) - - console.log(`Deploying Collateral to network ${hre.network.name} (${chainId}) - with burner account: ${deployer.address}`) - - if (!networkConfig[chainId]) { - throw new Error(`Missing network configuration for ${hre.network.name}`) - } - - // Get phase1 deployment - const phase1File = getDeploymentFilename(chainId) - if (!fileExists(phase1File)) { - throw new Error(`${phase1File} doesn't exist yet. Run phase 1`) - } - const deployments = getDeploymentFile(phase1File) - - // Check previous step completed - const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) - const assetCollDeployments = getDeploymentFile(assetCollDeploymentFilename) - - const deployedCollateral: string[] = [] - - /******** Deploy Convex Volatile Pool for 3pool **************************/ - - const CvxMining = await ethers.getContractAt('CvxMining', deployments.cvxMiningLib) - const CurveVolatileCollateralFactory = await hre.ethers.getContractFactory( - 'CurveVolatileCollateral' - ) - const ConvexStakingWrapperFactory = await ethers.getContractFactory('ConvexStakingWrapper', { - libraries: { CvxMining: CvxMining.address }, - }) - - const w3Pool = await ConvexStakingWrapperFactory.deploy() - await w3Pool.deployed() - await (await w3Pool.initialize(TRI_CRYPTO_CVX_POOL_ID)).wait() - - console.log( - `Deployed wrapper for Convex Volatile TriCrypto on ${hre.network.name} (${chainId}): ${w3Pool.address} ` - ) - - const collateral = await CurveVolatileCollateralFactory.connect( - deployer - ).deploy( - { - erc20: w3Pool.address, - targetName: ethers.utils.formatBytes32String('TRICRYPTO'), - priceTimeout: PRICE_TIMEOUT, - chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero - oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDT_ORACLE_TIMEOUT), // max of oracleTimeouts - maxTradeVolume: MAX_TRADE_VOL, - defaultThreshold: DEFAULT_THRESHOLD, - delayUntilDefault: DELAY_UNTIL_DEFAULT, - }, - revenueHiding.toString(), - { - nTokens: 3, - curvePool: TRI_CRYPTO, - poolType: CurvePoolType.Plain, - feeds: [[USDT_USD_FEED], [WBTC_BTC_FEED, BTC_USD_FEED], [WETH_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, WBTC_ORACLE_TIMEOUT), oracleTimeout(chainId, BTC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, WETH_ORACLE_TIMEOUT)], - ], - oracleErrors: [ - [USDT_ORACLE_ERROR], - [WBTC_BTC_ORACLE_ERROR, BTC_USD_ORACLE_ERROR], - [WETH_ORACLE_ERROR], - ], - lpToken: TRI_CRYPTO_TOKEN, - } - ) - await collateral.deployed() - await (await collateral.refresh()).wait() - expect(await collateral.status()).to.equal(CollateralStatus.SOUND) - - console.log( - `Deployed Convex Volatile Collateral to ${hre.network.name} (${chainId}): ${collateral.address}` - ) - - assetCollDeployments.collateral.cvxTriCrypto = collateral.address - assetCollDeployments.erc20s.cvxTriCrypto = w3Pool.address - deployedCollateral.push(collateral.address.toString()) - - fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) - - console.log(`Deployed collateral to ${hre.network.name} (${chainId}) - New deployments: ${deployedCollateral} - Deployment file: ${assetCollDeploymentFilename}`) -} - -main().catch((error) => { - console.error(error) - process.exitCode = 1 -}) diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_ctokenv3_usdbc_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_ctokenv3_usdbc_collateral.ts index 3f4755ff7..21e78893a 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_ctokenv3_usdbc_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_ctokenv3_usdbc_collateral.ts @@ -12,7 +12,7 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { priceTimeout, oracleTimeout, revenueHiding } from '../../utils' +import { priceTimeout, revenueHiding } from '../../utils' import { CTokenV3Collateral } from '../../../../typechain' import { ContractFactory } from 'ethers' @@ -61,7 +61,7 @@ async function main() { const CTokenV3Factory: ContractFactory = await hre.ethers.getContractFactory('CTokenV3Collateral') - const usdcOracleTimeout = 86400 // 24 hr + const usdcOracleTimeout = '86400' // 24 hr const usdcOracleError = fp('0.003') // 0.3% (Base) const collateral = await CTokenV3Factory.connect(deployer).deploy( @@ -71,7 +71,7 @@ async function main() { oracleError: usdcOracleError.toString(), erc20: erc20.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout).toString(), // 24h hr, + oracleTimeout: usdcOracleTimeout, // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdcOracleError).toString(), // 1% + 0.3% delayUntilDefault: bn('86400').toString(), // 24h diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_ctokenv3_usdc_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_ctokenv3_usdc_collateral.ts index 873b8fbcc..a05ac5bbc 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_ctokenv3_usdc_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_ctokenv3_usdc_collateral.ts @@ -12,7 +12,7 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { priceTimeout, oracleTimeout, revenueHiding } from '../../utils' +import { priceTimeout, revenueHiding } from '../../utils' import { CTokenV3Collateral } from '../../../../typechain' import { ContractFactory } from 'ethers' @@ -59,7 +59,7 @@ async function main() { const CTokenV3Factory: ContractFactory = await hre.ethers.getContractFactory('CTokenV3Collateral') - const usdcOracleTimeout = 86400 // 24 hr + const usdcOracleTimeout = '86400' // 24 hr const usdcOracleError = baseL2Chains.includes(hre.network.name) ? fp('0.003') : fp('0.0025') // 0.3% (Base) or 0.25% const collateral = await CTokenV3Factory.connect(deployer).deploy( @@ -69,7 +69,7 @@ async function main() { oracleError: usdcOracleError.toString(), erc20: erc20.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout).toString(), // 24h hr, + oracleTimeout: usdcOracleTimeout, // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdcOracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_curve_rToken_metapool_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_curve_rToken_metapool_plugin.ts index e886d6d80..c2d760a2f 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_curve_rToken_metapool_plugin.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_curve_rToken_metapool_plugin.ts @@ -13,7 +13,7 @@ import { fileExists, } from '../../common' import { CurveStableRTokenMetapoolCollateral } from '../../../../typechain' -import { revenueHiding, oracleTimeout } from '../../utils' +import { revenueHiding } from '../../utils' import { CRV, CurvePoolType, @@ -88,7 +88,7 @@ async function main() { priceTimeout: PRICE_TIMEOUT, chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDC_ORACLE_TIMEOUT), // max of oracleTimeouts + oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts maxTradeVolume: MAX_TRADE_VOL, defaultThreshold: DEFAULT_THRESHOLD, // 2%: 1% error on FRAX oracle + 1% base defaultThreshold delayUntilDefault: RTOKEN_DELAY_UNTIL_DEFAULT, @@ -99,10 +99,7 @@ async function main() { curvePool: FRAX_BP, poolType: CurvePoolType.Plain, feeds: [[FRAX_USD_FEED], [USDC_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, FRAX_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[FRAX_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT]], oracleErrors: [[FRAX_ORACLE_ERROR], [USDC_ORACLE_ERROR]], lpToken: FRAX_BP_TOKEN, }, diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_curve_stable_metapool_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_curve_stable_metapool_plugin.ts index f97882d21..e62840d7e 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_curve_stable_metapool_plugin.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_curve_stable_metapool_plugin.ts @@ -12,7 +12,7 @@ import { fileExists, } from '../../common' import { CurveStableMetapoolCollateral } from '../../../../typechain' -import { revenueHiding, oracleTimeout } from '../../utils' +import { revenueHiding } from '../../utils' import { CRV, CurvePoolType, @@ -105,11 +105,7 @@ async function main() { curvePool: THREE_POOL, poolType: CurvePoolType.Plain, feeds: [[DAI_USD_FEED], [USDC_USD_FEED], [USDT_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, DAI_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[DAI_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT], [USDT_ORACLE_TIMEOUT]], oracleErrors: [[DAI_ORACLE_ERROR], [USDC_ORACLE_ERROR], [USDT_ORACLE_ERROR]], lpToken: THREE_POOL_TOKEN, }, diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_curve_stable_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_curve_stable_plugin.ts index b2d6462d6..6b9f415d0 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_curve_stable_plugin.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_curve_stable_plugin.ts @@ -13,7 +13,7 @@ import { fileExists, } from '../../common' import { CurveStableCollateral } from '../../../../typechain' -import { revenueHiding, oracleTimeout } from '../../utils' +import { revenueHiding } from '../../utils' import { CRV, CurvePoolType, @@ -89,7 +89,7 @@ async function main() { priceTimeout: PRICE_TIMEOUT, chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDC_ORACLE_TIMEOUT), // max of oracleTimeouts + oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts maxTradeVolume: MAX_TRADE_VOL, defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -100,11 +100,7 @@ async function main() { curvePool: THREE_POOL, poolType: CurvePoolType.Plain, feeds: [[DAI_USD_FEED], [USDC_USD_FEED], [USDT_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, DAI_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[DAI_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT], [USDT_ORACLE_TIMEOUT]], oracleErrors: [[DAI_ORACLE_ERROR], [USDC_ORACLE_ERROR], [USDT_ORACLE_ERROR]], lpToken: THREE_POOL_TOKEN, } diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_curve_volatile_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_curve_volatile_plugin.ts deleted file mode 100644 index f3b6e3e61..000000000 --- a/scripts/deployment/phase2-assets/collaterals/deploy_curve_volatile_plugin.ts +++ /dev/null @@ -1,142 +0,0 @@ -import fs from 'fs' -import hre, { ethers } from 'hardhat' -import { getChainId } from '../../../../common/blockchain-utils' -import { networkConfig } from '../../../../common/configuration' -import { bn } from '../../../../common/numbers' -import { expect } from 'chai' -import { CollateralStatus, ONE_ADDRESS } from '../../../../common/constants' -import { - getDeploymentFile, - getAssetCollDeploymentFilename, - IAssetCollDeployments, - getDeploymentFilename, - fileExists, -} from '../../common' -import { CurveVolatileCollateral } from '../../../../typechain' -import { revenueHiding, oracleTimeout } from '../../utils' -import { - CRV, - CurvePoolType, - BTC_USD_ORACLE_ERROR, - BTC_ORACLE_TIMEOUT, - BTC_USD_FEED, - DEFAULT_THRESHOLD, - DELAY_UNTIL_DEFAULT, - MAX_TRADE_VOL, - PRICE_TIMEOUT, - TRI_CRYPTO, - TRI_CRYPTO_TOKEN, - TRI_CRYPTO_GAUGE, - WBTC_BTC_ORACLE_ERROR, - WETH_ORACLE_TIMEOUT, - WBTC_BTC_FEED, - WBTC_ORACLE_TIMEOUT, - WETH_USD_FEED, - WETH_ORACLE_ERROR, - USDT_ORACLE_ERROR, - USDT_ORACLE_TIMEOUT, - USDT_USD_FEED, -} from '../../../../test/plugins/individual-collateral/curve/constants' - -// Deploy Curve Volatile Plugin for Tricrypto - -async function main() { - // ==== Read Configuration ==== - const [deployer] = await hre.ethers.getSigners() - - const chainId = await getChainId(hre) - - console.log(`Deploying Collateral to network ${hre.network.name} (${chainId}) - with burner account: ${deployer.address}`) - - if (!networkConfig[chainId]) { - throw new Error(`Missing network configuration for ${hre.network.name}`) - } - - // Get phase1 deployment - const phase1File = getDeploymentFilename(chainId) - if (!fileExists(phase1File)) { - throw new Error(`${phase1File} doesn't exist yet. Run phase 1`) - } - - // Check previous step completed - const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) - const assetCollDeployments = getDeploymentFile(assetCollDeploymentFilename) - - const deployedCollateral: string[] = [] - - /******** Deploy Curve Volatile Pool for 3pool **************************/ - - const CurveVolatileCollateralFactory = await hre.ethers.getContractFactory( - 'CurveVolatileCollateral' - ) - const CurveStakingWrapperFactory = await ethers.getContractFactory('CurveGaugeWrapper') - const w3Pool = await CurveStakingWrapperFactory.deploy( - TRI_CRYPTO_TOKEN, - 'Wrapped Curve.fi USD-BTC-ETH', - 'wcrv3crypto', - CRV, - TRI_CRYPTO_GAUGE - ) - await w3Pool.deployed() - - console.log( - `Deployed wrapper for Curve Volatile TriCrypto on ${hre.network.name} (${chainId}): ${w3Pool.address} ` - ) - - const collateral = await CurveVolatileCollateralFactory.connect( - deployer - ).deploy( - { - erc20: w3Pool.address, - targetName: ethers.utils.formatBytes32String('TRICRYPTO'), - priceTimeout: PRICE_TIMEOUT, - chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero - oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDT_ORACLE_TIMEOUT), // max of oracleTimeouts - maxTradeVolume: MAX_TRADE_VOL, - defaultThreshold: DEFAULT_THRESHOLD, - delayUntilDefault: DELAY_UNTIL_DEFAULT, - }, - revenueHiding.toString(), - { - nTokens: 3, - curvePool: TRI_CRYPTO, - poolType: CurvePoolType.Plain, - feeds: [[USDT_USD_FEED], [WBTC_BTC_FEED, BTC_USD_FEED], [WETH_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, WBTC_ORACLE_TIMEOUT), oracleTimeout(chainId, BTC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, WETH_ORACLE_TIMEOUT)], - ], - oracleErrors: [ - [USDT_ORACLE_ERROR], - [WBTC_BTC_ORACLE_ERROR, BTC_USD_ORACLE_ERROR], - [WETH_ORACLE_ERROR], - ], - lpToken: TRI_CRYPTO_TOKEN, - } - ) - await collateral.deployed() - await (await collateral.refresh()).wait() - expect(await collateral.status()).to.equal(CollateralStatus.SOUND) - - console.log( - `Deployed Curve Volatile Collateral to ${hre.network.name} (${chainId}): ${collateral.address}` - ) - - assetCollDeployments.collateral.crvTriCrypto = collateral.address - assetCollDeployments.erc20s.crvTriCrypto = w3Pool.address - deployedCollateral.push(collateral.address.toString()) - - fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) - - console.log(`Deployed collateral to ${hre.network.name} (${chainId}) - New deployments: ${deployedCollateral} - Deployment file: ${assetCollDeploymentFilename}`) -} - -main().catch((error) => { - console.error(error) - process.exitCode = 1 -}) diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_dsr_sdai.ts b/scripts/deployment/phase2-assets/collaterals/deploy_dsr_sdai.ts index 26ab8341a..d06853b7c 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_dsr_sdai.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_dsr_sdai.ts @@ -13,7 +13,7 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { priceTimeout, oracleTimeout } from '../../utils' +import { priceTimeout } from '../../utils' import { SDaiCollateral } from '../../../../typechain' import { ContractFactory } from 'ethers' @@ -54,7 +54,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% erc20: networkConfig[chainId].tokens.sDAI, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_flux_finance_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_flux_finance_collateral.ts index af7258ec4..6acbcccf8 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_flux_finance_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_flux_finance_collateral.ts @@ -12,7 +12,7 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { priceTimeout, oracleTimeout, revenueHiding } from '../../utils' +import { priceTimeout, revenueHiding } from '../../utils' import { ICollateral } from '../../../../typechain' async function main() { @@ -49,7 +49,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% cToken: fUsdc.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -74,7 +74,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% cToken: fUsdt.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -99,7 +99,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% cToken: fDai.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -124,7 +124,7 @@ async function main() { oracleError: fp('0.01').toString(), // 1% cToken: fFrax.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.02').toString(), // 2% delayUntilDefault: bn('86400').toString(), // 24h diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_lido_wsteth_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_lido_wsteth_collateral.ts index bc6a8b160..30884eae2 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_lido_wsteth_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_lido_wsteth_collateral.ts @@ -12,7 +12,7 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { priceTimeout, oracleTimeout } from '../../utils' +import { priceTimeout } from '../../utils' import { LidoStakedEthCollateral } from '../../../../typechain' import { ContractFactory } from 'ethers' @@ -79,14 +79,14 @@ async function main() { oracleError: fp('0.01').toString(), // 1%: only for stETHUSD feed erc20: networkConfig[chainId].tokens.wstETH, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr, + oracleTimeout: '3600', // 1 hr, targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.025').toString(), // 2.5% = 2% + 0.5% stethEth feed oracleError delayUntilDefault: bn('86400').toString(), // 24h }, fp('1e-4').toString(), // revenueHiding = 0.01% stethEthOracleAddress, // targetPerRefChainlinkFeed - oracleTimeout(chainId, '86400').toString() // targetPerRefChainlinkTimeout + '86400' // targetPerRefChainlinkTimeout ) await collateral.deployed() await (await collateral.refresh()).wait() diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_morpho_aavev2_plugin.ts b/scripts/deployment/phase2-assets/collaterals/deploy_morpho_aavev2_plugin.ts index 19962dd88..4c7457465 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_morpho_aavev2_plugin.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_morpho_aavev2_plugin.ts @@ -11,7 +11,7 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { priceTimeout, oracleTimeout, combinedError } from '../../utils' +import { priceTimeout, combinedError } from '../../utils' async function main() { // ==== Read Configuration ==== @@ -126,7 +126,7 @@ async function main() { priceTimeout: priceTimeout.toString(), oracleError: stablesOracleError.toString(), maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 1 hr + oracleTimeout: '86400', // 1 hr targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: stablesOracleError.add(fp('0.01')), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -184,7 +184,7 @@ async function main() { priceTimeout: priceTimeout, oracleError: combinedBTCWBTCError, maxTradeVolume: fp('1e6'), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600'), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: fp('0.01').add(combinedBTCWBTCError), // ~3.5% delayUntilDefault: bn('86400'), // 24h @@ -193,7 +193,7 @@ async function main() { }, revenueHiding, networkConfig[chainId].chainlinkFeeds.WBTC!, // {target/ref} - oracleTimeout(chainId, '86400').toString() // 1 hr + '86400' // 1 hr ) assetCollDeployments.collateral.maWBTC = collateral.address deployedCollateral.push(collateral.address.toString()) @@ -207,7 +207,7 @@ async function main() { priceTimeout: priceTimeout, oracleError: fp('0.005'), maxTradeVolume: fp('1e6'), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600'), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0'), // 0% -- no soft default for self-referential collateral delayUntilDefault: bn('86400'), // 24h @@ -236,7 +236,7 @@ async function main() { priceTimeout: priceTimeout, oracleError: combinedOracleErrors, maxTradeVolume: fp('1e6'), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600'), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.01').add(combinedOracleErrors), // ~1.5% delayUntilDefault: bn('86400'), // 24h @@ -245,7 +245,7 @@ async function main() { }, revenueHiding, networkConfig[chainId].chainlinkFeeds.stETHETH!, // {target/ref} - oracleTimeout(chainId, '86400').toString() // 1 hr + '86400' // 1 hr ) assetCollDeployments.collateral.maStETH = collateral.address deployedCollateral.push(collateral.address.toString()) diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_rocket_pool_reth_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_rocket_pool_reth_collateral.ts index 6d3925906..d90520b97 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_rocket_pool_reth_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_rocket_pool_reth_collateral.ts @@ -12,8 +12,8 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { priceTimeout, oracleTimeout, combinedError } from '../../utils' -import { MockV3Aggregator, RethCollateral } from '../../../../typechain' +import { priceTimeout, combinedError } from '../../utils' +import { RethCollateral } from '../../../../typechain' import { ContractFactory } from 'ethers' async function main() { @@ -70,14 +70,14 @@ async function main() { oracleError: oracleError.toString(), // 0.5% & 2% erc20: networkConfig[chainId].tokens.rETH, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr, + oracleTimeout: '3600', // 1 hr, targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.02').add(oracleError).toString(), // ~4.5% delayUntilDefault: bn('86400').toString(), // 24h }, fp('1e-4').toString(), // revenueHiding = 0.01% rethOracleAddress, // refPerTokChainlinkFeed - oracleTimeout(chainId, '86400').toString() // refPerTokChainlinkTimeout + '86400' // refPerTokChainlinkTimeout ) await collateral.deployed() await (await collateral.refresh()).wait() diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts index 6ba2fee7b..dfd837767 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts @@ -12,17 +12,13 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { revenueHiding, priceTimeout, oracleTimeout } from '../../utils' +import { revenueHiding, priceTimeout } from '../../utils' import { StargatePoolFiatCollateral, StargatePoolFiatCollateral__factory, } from '../../../../typechain' import { ContractFactory } from 'ethers' - -import { - STAKING_CONTRACT, - SUSDC, -} from '../../../../test/plugins/individual-collateral/stargate/constants' +import { useEnv } from '#/utils/env' async function main() { // ==== Read Configuration ==== @@ -50,19 +46,36 @@ async function main() { /******** Deploy Stargate USDC Wrapper **************************/ - const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory('StargatePoolWrapper') + const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory( + 'StargateRewardableWrapper' + ) + const chainIdKey = useEnv('FORK_NETWORK', 'mainnet') == 'mainnet' ? '1' : '8453' + let USDC_NAME = 'USDC' + let name = 'Wrapped Stargate USDC' + let symbol = 'wsgUSDC' + let sUSDC = networkConfig[chainIdKey].tokens.sUSDC + let oracleError = fp('0.0025') + + if (chainIdKey == '8453') { + USDC_NAME = 'USDbC' + name = 'Wrapped Stargate USDbC' + symbol = 'wsgUSDbC' + sUSDC = networkConfig[chainIdKey].tokens.sUSDbC + + oracleError = fp('0.003') + } const erc20 = await WrapperFactory.deploy( - 'Wrapped Stargate USDC', - 'wSTG-USDC', - networkConfig[chainId].tokens.STG, - STAKING_CONTRACT, - SUSDC + name, + symbol, + networkConfig[chainIdKey].tokens.STG, + networkConfig[chainIdKey].STARGATE_STAKING_CONTRACT, + sUSDC ) await erc20.deployed() console.log( - `Deployed Wrapper for Stargate USDC on ${hre.network.name} (${chainId}): ${erc20.address} ` + `Deployed Wrapper for Stargate ${USDC_NAME} on ${hre.network.name} (${chainIdKey}): ${erc20.address} ` ) const StargateCollateralFactory: StargatePoolFiatCollateral__factory = @@ -73,13 +86,13 @@ async function main() { ).deploy( { priceTimeout: priceTimeout.toString(), - chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC!, - oracleError: fp('0.0025').toString(), // 0.25%, + chainlinkFeed: networkConfig[chainIdKey].chainlinkFeeds.USDC!, + oracleError: oracleError.toString(), erc20: erc20.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24h hr, + oracleTimeout: '86400', // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), - defaultThreshold: fp('0.0125').toString(), // 1.25% + defaultThreshold: fp('0.01').add(oracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h }, revenueHiding.toString() @@ -88,10 +101,17 @@ async function main() { await (await collateral.refresh()).wait() expect(await collateral.status()).to.equal(CollateralStatus.SOUND) - console.log(`Deployed Stargate USDC to ${hre.network.name} (${chainId}): ${collateral.address}`) + console.log( + `Deployed Stargate ${USDC_NAME} to ${hre.network.name} (${chainIdKey}): ${collateral.address}` + ) - assetCollDeployments.collateral.sUSDC = collateral.address - assetCollDeployments.erc20s.sUSDC = erc20.address + if (chainIdKey == '8453') { + assetCollDeployments.collateral.wsgUSDbC = collateral.address + assetCollDeployments.erc20s.wsgUSDbC = erc20.address + } else { + assetCollDeployments.collateral.wsgUSDC = collateral.address + assetCollDeployments.erc20s.wsgUSDC = erc20.address + } deployedCollateral.push(collateral.address.toString()) fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdt_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdt_collateral.ts index 2d317a40c..4ac4e4c6c 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdt_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdt_collateral.ts @@ -12,7 +12,7 @@ import { getDeploymentFilename, fileExists, } from '../../common' -import { revenueHiding, priceTimeout, oracleTimeout } from '../../utils' +import { revenueHiding, priceTimeout } from '../../utils' import { StargatePoolFiatCollateral, StargatePoolFiatCollateral__factory, @@ -50,7 +50,7 @@ async function main() { /******** Deploy Stargate USDT Wrapper **************************/ - const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory('StargatePoolWrapper') + const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory('StargateRewardableWrapper') const erc20 = await WrapperFactory.deploy( 'Wrapped Stargate USDT', @@ -77,7 +77,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25%, erc20: erc20.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24h hr, + oracleTimeout: '86400', // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h diff --git a/scripts/deployment/utils.ts b/scripts/deployment/utils.ts index 84dad2be5..a8c2083e0 100644 --- a/scripts/deployment/utils.ts +++ b/scripts/deployment/utils.ts @@ -2,7 +2,7 @@ import hre, { tenderly } from 'hardhat' import * as readline from 'readline' import axios from 'axios' import { exec } from 'child_process' -import { BigNumber, BigNumberish } from 'ethers' +import { BigNumber } from 'ethers' import { bn, fp } from '../../common/numbers' import { IComponents, baseL2Chains } from '../../common/configuration' import { isValidContract } from '../../common/blockchain-utils' @@ -13,13 +13,6 @@ export const priceTimeout = bn('604800') // 1 week export const revenueHiding = fp('1e-6') // 1 part in a million -export const longOracleTimeout = bn('4294967296') - -// Returns the base plus 1 minute -export const oracleTimeout = (chainId: string, base: BigNumberish) => { - return chainId == '1' || chainId == '8453' ? bn('60').add(base) : longOracleTimeout -} - export const combinedError = (x: BigNumber, y: BigNumber): BigNumber => { return fp('1').add(x).mul(fp('1').add(y)).div(fp('1')).sub(fp('1')) } diff --git a/scripts/replaceOracles.ts b/scripts/replaceOracles.ts new file mode 100644 index 000000000..e9a72a822 --- /dev/null +++ b/scripts/replaceOracles.ts @@ -0,0 +1,60 @@ +import hre, { ethers } from 'hardhat' + +const supportedNodes = ['anvil', 'hardhat'] +const oracleList = [ + '0x759bbc1be8f90ee6457c44abc7d443842a976d02', + '0xAed0c38402a5d19df6E4c03F4E2DceD6e29c1ee9', + '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6', + '0x3E7d1eAB13ad0104d2750B8863b489D65364e32D', + '0x833D8Eb16D306ed1FbB5D7A2E019e106B960965A', + '0x09023c0DA49Aaf8fc3fA3ADF34C6A7016D38D5e3', + '0xec746eCF986E2927Abd291a2A1716c940100f8Ba', + '0xad35Bd71b9aFE6e4bDc266B345c198eaDEf9Ad94', + '0xB9E1E3A9feFf48998E45Fa90847ed4D467E8BcfD', + '0x7A364e8770418566e3eb2001A96116E6138Eb32F', + '0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419', + '0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c', + '0x01D391A48f4F7339aC64CA2c83a07C22F95F587a', + '0xb49f677943BC038e9857d61E7d053CaA2C1734C1', + '0x86392dc19c0b719886221c78ab11eb8cf5c52812', + '0xCfE54B5cD566aB89272946F602D76Ea879CAb4a8', + '0x536218f9E9Eb48863970252233c8F271f554C2d0', + '0xf017fcb346a1885194689ba23eff2fe6fa5c483b', + '0xfdFD9C85aD200c506Cf9e21F1FD8dd01932FBB23', +] + +async function main() { + const clientVersion = await hre.ethers.provider.send('web3_clientVersion', []) + const isSupported = supportedNodes.some((node) => clientVersion.toLowerCase().includes(node)) + console.log({ clientVersion, isSupported }) + + if (!isSupported) { + throw Error('Unsupported Network') + } + + const forkedOracleArtifact = await hre.artifacts.readArtifact('ForkedOracle') + + for (const oracleAddress of oracleList) { + const oracle = await hre.ethers.getContractAt('ForkedOracle', oracleAddress) + + const description = await oracle.description() + const decimals = await oracle.decimals() + const roundData = await oracle.latestRoundData() + + console.log(`-------- Updating ${description} (${oracle.address}) Oracle...`) + console.log(`>>>> Current Answer:`, ethers.utils.formatUnits(roundData.answer, decimals)) + + console.log('>>>> Updating code...') + await hre.ethers.provider.send('hardhat_setCode', [ + oracle.address, + forkedOracleArtifact.deployedBytecode, + ]) + console.log('>>>> Updating data...') + await oracle.setData(decimals, roundData.answer, { + gasLimit: 10_000_000, + }) + console.log('>>>> Done!') + } +} + +main().catch((e) => console.error(e)) diff --git a/scripts/verification/6_verify_collateral.ts b/scripts/verification/6_verify_collateral.ts index 9da0d9791..fbcfe84d2 100644 --- a/scripts/verification/6_verify_collateral.ts +++ b/scripts/verification/6_verify_collateral.ts @@ -8,13 +8,7 @@ import { getAssetCollDeploymentFilename, IAssetCollDeployments, } from '../deployment/common' -import { - combinedError, - priceTimeout, - oracleTimeout, - revenueHiding, - verifyContract, -} from '../deployment/utils' +import { combinedError, priceTimeout, revenueHiding, verifyContract } from '../deployment/utils' import { ATokenMock, ATokenFiatCollateral, ICToken, CTokenFiatCollateral } from '../../typechain' let deployments: IAssetCollDeployments @@ -47,7 +41,7 @@ async function main() { oracleError: daiOracleError.toString(), erc20: networkConfig[chainId].tokens.DAI, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, daiOracleTimeout).toString(), + oracleTimeout: daiOracleTimeout, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(daiOracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h @@ -71,7 +65,7 @@ async function main() { oracleError: usdcOracleError.toString(), erc20: networkConfig[chainId].tokens.USDbC, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout).toString(), + oracleTimeout: usdcOracleTimeout, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdcOracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h @@ -112,7 +106,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% erc20: await aTokenCollateral.erc20(), maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -151,7 +145,7 @@ async function main() { oracleError: fp('0.0025').toString(), // 0.25% erc20: deployments.erc20s.cDAI, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -176,13 +170,13 @@ async function main() { oracleError: combinedBTCWBTCError.toString(), erc20: deployments.erc20s.cWBTC, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr + oracleTimeout: '86400', // 24 hr targetName: hre.ethers.utils.formatBytes32String('BTC'), defaultThreshold: fp('0.01').add(combinedBTCWBTCError).toString(), // ~3.5% delayUntilDefault: bn('86400').toString(), // 24h }, networkConfig[chainId].chainlinkFeeds.BTC, - oracleTimeout(chainId, '3600').toString(), + '3600', revenueHiding.toString(), ], 'contracts/plugins/assets/compoundv2/CTokenNonFiatCollateral.sol:CTokenNonFiatCollateral' @@ -198,7 +192,7 @@ async function main() { oracleError: fp('0.005').toString(), // 0.5% erc20: deployments.erc20s.cETH, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: '0', delayUntilDefault: '0', @@ -219,13 +213,13 @@ async function main() { oracleError: combinedBTCWBTCError.toString(), erc20: networkConfig[chainId].tokens.WBTC, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), + oracleTimeout: '86400', // 24h targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: fp('0.01').add(combinedBTCWBTCError).toString(), // ~3.5% delayUntilDefault: bn('86400').toString(), // 24h }, networkConfig[chainId].chainlinkFeeds.BTC, - oracleTimeout(chainId, '3600').toString(), + '3600', ], 'contracts/plugins/assets/NonFiatCollateral.sol:NonFiatCollateral' ) @@ -244,7 +238,7 @@ async function main() { oracleError: ethOracleError.toString(), // 0.5% erc20: networkConfig[chainId].tokens.WETH, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, ethOracleTimeout).toString(), + oracleTimeout: ethOracleTimeout, targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: '0', delayUntilDefault: '0', @@ -264,13 +258,13 @@ async function main() { oracleError: fp('0.02').toString(), // 2% erc20: networkConfig[chainId].tokens.EURT, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), + oracleTimeout: '86400', // 24hr targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: fp('0.03').toString(), // 3% delayUntilDefault: bn('86400').toString(), // 24h }, networkConfig[chainId].chainlinkFeeds.EUR, - oracleTimeout(chainId, '86400').toString(), + '86400', ], 'contracts/plugins/assets/EURFiatCollateral.sol:EURFiatCollateral' ) diff --git a/scripts/verification/collateral-plugins/verify_aave_v3_usdbc.ts b/scripts/verification/collateral-plugins/verify_aave_v3_usdbc.ts index edb092d1a..3a373573d 100644 --- a/scripts/verification/collateral-plugins/verify_aave_v3_usdbc.ts +++ b/scripts/verification/collateral-plugins/verify_aave_v3_usdbc.ts @@ -7,7 +7,7 @@ import { IAssetCollDeployments, } from '../../deployment/common' import { fp, bn } from '../../../common/numbers' -import { priceTimeout, oracleTimeout, verifyContract, revenueHiding } from '../../deployment/utils' +import { priceTimeout, verifyContract, revenueHiding } from '../../deployment/utils' let deployments: IAssetCollDeployments @@ -54,7 +54,7 @@ async function main() { priceTimeout: priceTimeout.toString(), chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC!, oracleError: fp('0.003').toString(), // 3% - oracleTimeout: oracleTimeout(chainId, bn('86400')).toString(), // 24 hr + oracleTimeout: '86400', // 24 hr maxTradeVolume: fp('1e6').toString(), defaultThreshold: fp('0.013').toString(), delayUntilDefault: bn('86400').toString(), diff --git a/scripts/verification/collateral-plugins/verify_aave_v3_usdc.ts b/scripts/verification/collateral-plugins/verify_aave_v3_usdc.ts index 1486c37ca..3ffce9a0a 100644 --- a/scripts/verification/collateral-plugins/verify_aave_v3_usdc.ts +++ b/scripts/verification/collateral-plugins/verify_aave_v3_usdc.ts @@ -7,7 +7,7 @@ import { IAssetCollDeployments, } from '../../deployment/common' import { fp, bn } from '../../../common/numbers' -import { priceTimeout, oracleTimeout, verifyContract, revenueHiding } from '../../deployment/utils' +import { priceTimeout, verifyContract, revenueHiding } from '../../deployment/utils' let deployments: IAssetCollDeployments @@ -39,7 +39,7 @@ async function main() { ) /******** Verify Aave V3 USDC plugin **************************/ - const usdcOracleTimeout = 86400 // 24 hr + const usdcOracleTimeout = '86400' // 24 hr const usdcOracleError = baseL2Chains.includes(hre.network.name) ? fp('0.003') : fp('0.0025') // 0.3% (Base) or 0.25% await verifyContract( @@ -52,7 +52,7 @@ async function main() { priceTimeout: priceTimeout.toString(), chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC!, oracleError: usdcOracleError.toString(), - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout).toString(), // 24 hr + oracleTimeout: usdcOracleTimeout, // 24 hr maxTradeVolume: fp('1e6').toString(), defaultThreshold: fp('0.01').add(usdcOracleError).toString(), delayUntilDefault: bn('86400').toString(), diff --git a/scripts/verification/collateral-plugins/verify_cbeth.ts b/scripts/verification/collateral-plugins/verify_cbeth.ts index 4e58ad88d..9b52d6323 100644 --- a/scripts/verification/collateral-plugins/verify_cbeth.ts +++ b/scripts/verification/collateral-plugins/verify_cbeth.ts @@ -7,7 +7,7 @@ import { getAssetCollDeploymentFilename, IAssetCollDeployments, } from '../../deployment/common' -import { priceTimeout, oracleTimeout, verifyContract, combinedError } from '../../deployment/utils' +import { priceTimeout, verifyContract, combinedError } from '../../deployment/utils' let deployments: IAssetCollDeployments @@ -40,14 +40,14 @@ async function main() { oracleError: oracleError.toString(), // 0.5% & 2% erc20: networkConfig[chainId].tokens.cbETH!, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.02').add(oracleError).toString(), // ~4.5% delayUntilDefault: bn('86400').toString(), // 24h }, fp('1e-4'), // revenueHiding = 0.01% networkConfig[chainId].chainlinkFeeds.cbETH!, // refPerTokChainlinkFeed - oracleTimeout(chainId, '86400').toString(), // refPerTokChainlinkTimeout + '86400', // refPerTokChainlinkTimeout ], 'contracts/plugins/assets/cbeth/CBETHCollateral.sol:CBEthCollateral' ) @@ -63,16 +63,16 @@ async function main() { oracleError: oracleError.toString(), // 0.15% & 0.5%, erc20: networkConfig[chainId].tokens.cbETH!, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '1200').toString(), // 20 min + oracleTimeout: '1200', // 20 min targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.02').add(oracleError).toString(), // ~2.5% delayUntilDefault: bn('86400').toString(), // 24h }, fp('1e-4'), // revenueHiding = 0.01% networkConfig[chainId].chainlinkFeeds.cbETH!, // refPerTokChainlinkFeed - oracleTimeout(chainId, '86400').toString(), // refPerTokChainlinkTimeout + '86400', // refPerTokChainlinkTimeout networkConfig[chainId].chainlinkFeeds.cbETHETHexr!, // exchangeRateChainlinkFeed - oracleTimeout(chainId, '86400').toString(), // exchangeRateChainlinkTimeout + '86400', // exchangeRateChainlinkTimeout ], 'contracts/plugins/assets/cbeth/CBETHCollateralL2.sol:CBEthCollateralL2' ) diff --git a/scripts/verification/collateral-plugins/verify_convex_stable.ts b/scripts/verification/collateral-plugins/verify_convex_stable.ts index 3c22ae255..cd7ffc0e8 100644 --- a/scripts/verification/collateral-plugins/verify_convex_stable.ts +++ b/scripts/verification/collateral-plugins/verify_convex_stable.ts @@ -11,7 +11,7 @@ import { IDeployments, } from '../../deployment/common' import { verifyContract } from '../../deployment/utils' -import { revenueHiding, oracleTimeout } from '../../deployment/utils' +import { revenueHiding } from '../../deployment/utils' import { CurvePoolType, DAI_ORACLE_ERROR, @@ -85,7 +85,7 @@ async function main() { priceTimeout: PRICE_TIMEOUT, chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDC_ORACLE_TIMEOUT), // max of oracleTimeouts + oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts maxTradeVolume: MAX_TRADE_VOL, defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -96,11 +96,7 @@ async function main() { curvePool: THREE_POOL, poolType: CurvePoolType.Plain, feeds: [[DAI_USD_FEED], [USDC_USD_FEED], [USDT_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, DAI_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[DAI_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT], [USDT_ORACLE_TIMEOUT]], oracleErrors: [[DAI_ORACLE_ERROR], [USDC_ORACLE_ERROR], [USDT_ORACLE_ERROR]], lpToken: THREE_POOL_TOKEN, }, diff --git a/scripts/verification/collateral-plugins/verify_convex_stable_metapool.ts b/scripts/verification/collateral-plugins/verify_convex_stable_metapool.ts index 440f8854b..fedb2d418 100644 --- a/scripts/verification/collateral-plugins/verify_convex_stable_metapool.ts +++ b/scripts/verification/collateral-plugins/verify_convex_stable_metapool.ts @@ -7,7 +7,7 @@ import { IAssetCollDeployments, } from '../../deployment/common' import { verifyContract } from '../../deployment/utils' -import { revenueHiding, oracleTimeout } from '../../deployment/utils' +import { revenueHiding } from '../../deployment/utils' import { CurvePoolType, DAI_ORACLE_ERROR, @@ -75,11 +75,7 @@ async function main() { curvePool: THREE_POOL, poolType: CurvePoolType.Plain, feeds: [[DAI_USD_FEED], [USDC_USD_FEED], [USDT_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, DAI_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[DAI_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT], [USDT_ORACLE_TIMEOUT]], oracleErrors: [[DAI_ORACLE_ERROR], [USDC_ORACLE_ERROR], [USDT_ORACLE_ERROR]], lpToken: THREE_POOL_TOKEN, }, diff --git a/scripts/verification/collateral-plugins/verify_convex_stable_rtoken_metapool.ts b/scripts/verification/collateral-plugins/verify_convex_stable_rtoken_metapool.ts index 771f6bc76..400c23d10 100644 --- a/scripts/verification/collateral-plugins/verify_convex_stable_rtoken_metapool.ts +++ b/scripts/verification/collateral-plugins/verify_convex_stable_rtoken_metapool.ts @@ -9,7 +9,7 @@ import { IAssetCollDeployments, } from '../../deployment/common' import { verifyContract } from '../../deployment/utils' -import { revenueHiding, oracleTimeout } from '../../deployment/utils' +import { revenueHiding } from '../../deployment/utils' import { CurvePoolType, DEFAULT_THRESHOLD, @@ -59,7 +59,7 @@ async function main() { priceTimeout: PRICE_TIMEOUT, chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDC_ORACLE_TIMEOUT), + oracleTimeout: USDC_ORACLE_TIMEOUT, maxTradeVolume: MAX_TRADE_VOL, defaultThreshold: DEFAULT_THRESHOLD, // 2%: 1% error on FRAX oracle + 1% base defaultThreshold delayUntilDefault: RTOKEN_DELAY_UNTIL_DEFAULT, @@ -70,10 +70,7 @@ async function main() { curvePool: FRAX_BP, poolType: CurvePoolType.Plain, feeds: [[FRAX_USD_FEED], [USDC_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, FRAX_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[FRAX_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT]], oracleErrors: [[FRAX_ORACLE_ERROR], [USDC_ORACLE_ERROR]], lpToken: FRAX_BP_TOKEN, }, diff --git a/scripts/verification/collateral-plugins/verify_convex_volatile.ts b/scripts/verification/collateral-plugins/verify_convex_volatile.ts deleted file mode 100644 index 8c48da0e5..000000000 --- a/scripts/verification/collateral-plugins/verify_convex_volatile.ts +++ /dev/null @@ -1,98 +0,0 @@ -import hre, { ethers } from 'hardhat' -import { getChainId } from '../../../common/blockchain-utils' -import { developmentChains, networkConfig } from '../../../common/configuration' -import { bn } from '../../../common/numbers' -import { ONE_ADDRESS } from '../../../common/constants' -import { - getDeploymentFile, - getAssetCollDeploymentFilename, - IAssetCollDeployments, -} from '../../deployment/common' -import { verifyContract } from '../../deployment/utils' -import { revenueHiding, oracleTimeout } from '../../deployment/utils' -import { - CurvePoolType, - BTC_USD_ORACLE_ERROR, - BTC_ORACLE_TIMEOUT, - BTC_USD_FEED, - DEFAULT_THRESHOLD, - DELAY_UNTIL_DEFAULT, - MAX_TRADE_VOL, - PRICE_TIMEOUT, - TRI_CRYPTO, - TRI_CRYPTO_TOKEN, - WBTC_BTC_ORACLE_ERROR, - WETH_ORACLE_TIMEOUT, - WBTC_BTC_FEED, - WBTC_ORACLE_TIMEOUT, - WETH_USD_FEED, - WETH_ORACLE_ERROR, - USDT_ORACLE_ERROR, - USDT_ORACLE_TIMEOUT, - USDT_USD_FEED, -} from '../../../test/plugins/individual-collateral/curve/constants' - -let deployments: IAssetCollDeployments - -async function main() { - // ********** Read config ********** - const chainId = await getChainId(hre) - if (!networkConfig[chainId]) { - throw new Error(`Missing network configuration for ${hre.network.name}`) - } - - if (developmentChains.includes(hre.network.name)) { - throw new Error(`Cannot verify contracts for development chain ${hre.network.name}`) - } - - const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) - deployments = getDeploymentFile(assetCollDeploymentFilename) - - const wTriCrypto = await ethers.getContractAt( - 'CurveVolatileCollateral', - deployments.collateral.cvxTriCrypto as string - ) - - /******** Verify TriCrypto plugin **************************/ - await verifyContract( - chainId, - deployments.collateral.cvxTriCrypto, - [ - { - erc20: await wTriCrypto.erc20(), - targetName: ethers.utils.formatBytes32String('TRICRYPTO'), - priceTimeout: PRICE_TIMEOUT, - chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero - oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: bn('1'), // unused but cannot be zero - maxTradeVolume: MAX_TRADE_VOL, - defaultThreshold: DEFAULT_THRESHOLD, - delayUntilDefault: DELAY_UNTIL_DEFAULT, - }, - revenueHiding.toString(), - { - nTokens: 3, - curvePool: TRI_CRYPTO, - poolType: CurvePoolType.Plain, - feeds: [[USDT_USD_FEED], [WBTC_BTC_FEED, BTC_USD_FEED], [WETH_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, WBTC_ORACLE_TIMEOUT), oracleTimeout(chainId, BTC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, WETH_ORACLE_TIMEOUT)], - ], - oracleErrors: [ - [USDT_ORACLE_ERROR], - [WBTC_BTC_ORACLE_ERROR, BTC_USD_ORACLE_ERROR], - [WETH_ORACLE_ERROR], - ], - lpToken: TRI_CRYPTO_TOKEN, - }, - ], - 'contracts/plugins/assets/convex/CurveVolatileCollateral.sol:CurveVolatileCollateral' - ) -} - -main().catch((error) => { - console.error(error) - process.exitCode = 1 -}) diff --git a/scripts/verification/collateral-plugins/verify_curve_stable.ts b/scripts/verification/collateral-plugins/verify_curve_stable.ts index ce1120f61..3f4b66190 100644 --- a/scripts/verification/collateral-plugins/verify_curve_stable.ts +++ b/scripts/verification/collateral-plugins/verify_curve_stable.ts @@ -9,7 +9,7 @@ import { IAssetCollDeployments, } from '../../deployment/common' import { verifyContract } from '../../deployment/utils' -import { revenueHiding, oracleTimeout } from '../../deployment/utils' +import { revenueHiding } from '../../deployment/utils' import { CRV, CurvePoolType, @@ -72,7 +72,7 @@ async function main() { priceTimeout: PRICE_TIMEOUT, chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDC_ORACLE_TIMEOUT), // max of oracleTimeouts + oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts maxTradeVolume: MAX_TRADE_VOL, defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -83,11 +83,7 @@ async function main() { curvePool: THREE_POOL, poolType: CurvePoolType.Plain, feeds: [[DAI_USD_FEED], [USDC_USD_FEED], [USDT_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, DAI_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[DAI_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT], [USDT_ORACLE_TIMEOUT]], oracleErrors: [[DAI_ORACLE_ERROR], [USDC_ORACLE_ERROR], [USDT_ORACLE_ERROR]], lpToken: THREE_POOL_TOKEN, }, diff --git a/scripts/verification/collateral-plugins/verify_curve_stable_metapool.ts b/scripts/verification/collateral-plugins/verify_curve_stable_metapool.ts index 60be29f1e..e1b433bbd 100644 --- a/scripts/verification/collateral-plugins/verify_curve_stable_metapool.ts +++ b/scripts/verification/collateral-plugins/verify_curve_stable_metapool.ts @@ -7,7 +7,7 @@ import { IAssetCollDeployments, } from '../../deployment/common' import { verifyContract } from '../../deployment/utils' -import { revenueHiding, oracleTimeout } from '../../deployment/utils' +import { revenueHiding } from '../../deployment/utils' import { CurvePoolType, DAI_ORACLE_ERROR, @@ -75,11 +75,7 @@ async function main() { curvePool: THREE_POOL, poolType: CurvePoolType.Plain, feeds: [[DAI_USD_FEED], [USDC_USD_FEED], [USDT_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, DAI_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[DAI_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT], [USDT_ORACLE_TIMEOUT]], oracleErrors: [[DAI_ORACLE_ERROR], [USDC_ORACLE_ERROR], [USDT_ORACLE_ERROR]], lpToken: THREE_POOL_TOKEN, }, diff --git a/scripts/verification/collateral-plugins/verify_curve_stable_rtoken_metapool.ts b/scripts/verification/collateral-plugins/verify_curve_stable_rtoken_metapool.ts index a48df02d1..43d2172f1 100644 --- a/scripts/verification/collateral-plugins/verify_curve_stable_rtoken_metapool.ts +++ b/scripts/verification/collateral-plugins/verify_curve_stable_rtoken_metapool.ts @@ -9,7 +9,7 @@ import { IAssetCollDeployments, } from '../../deployment/common' import { verifyContract } from '../../deployment/utils' -import { revenueHiding, oracleTimeout } from '../../deployment/utils' +import { revenueHiding } from '../../deployment/utils' import { CurvePoolType, DEFAULT_THRESHOLD, @@ -59,7 +59,7 @@ async function main() { priceTimeout: PRICE_TIMEOUT, chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: oracleTimeout(chainId, USDC_ORACLE_TIMEOUT), // max of oracleTimeouts + oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts maxTradeVolume: MAX_TRADE_VOL, defaultThreshold: DEFAULT_THRESHOLD, // 2%: 1% error on FRAX oracle + 1% base defaultThreshold delayUntilDefault: RTOKEN_DELAY_UNTIL_DEFAULT, @@ -70,10 +70,7 @@ async function main() { curvePool: FRAX_BP, poolType: CurvePoolType.Plain, feeds: [[FRAX_USD_FEED], [USDC_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, FRAX_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, USDC_ORACLE_TIMEOUT)], - ], + oracleTimeouts: [[FRAX_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT]], oracleErrors: [[FRAX_ORACLE_ERROR], [USDC_ORACLE_ERROR]], lpToken: FRAX_BP_TOKEN, }, diff --git a/scripts/verification/collateral-plugins/verify_curve_volatile.ts b/scripts/verification/collateral-plugins/verify_curve_volatile.ts deleted file mode 100644 index 2f5c53b2c..000000000 --- a/scripts/verification/collateral-plugins/verify_curve_volatile.ts +++ /dev/null @@ -1,98 +0,0 @@ -import hre, { ethers } from 'hardhat' -import { getChainId } from '../../../common/blockchain-utils' -import { developmentChains, networkConfig } from '../../../common/configuration' -import { bn } from '../../../common/numbers' -import { ONE_ADDRESS } from '../../../common/constants' -import { - getDeploymentFile, - getAssetCollDeploymentFilename, - IAssetCollDeployments, -} from '../../deployment/common' -import { verifyContract } from '../../deployment/utils' -import { revenueHiding, oracleTimeout } from '../../deployment/utils' -import { - CurvePoolType, - BTC_USD_ORACLE_ERROR, - BTC_ORACLE_TIMEOUT, - BTC_USD_FEED, - DEFAULT_THRESHOLD, - DELAY_UNTIL_DEFAULT, - MAX_TRADE_VOL, - PRICE_TIMEOUT, - TRI_CRYPTO, - TRI_CRYPTO_TOKEN, - WBTC_BTC_ORACLE_ERROR, - WETH_ORACLE_TIMEOUT, - WBTC_BTC_FEED, - WBTC_ORACLE_TIMEOUT, - WETH_USD_FEED, - WETH_ORACLE_ERROR, - USDT_ORACLE_ERROR, - USDT_ORACLE_TIMEOUT, - USDT_USD_FEED, -} from '../../../test/plugins/individual-collateral/curve/constants' - -let deployments: IAssetCollDeployments - -async function main() { - // ********** Read config ********** - const chainId = await getChainId(hre) - if (!networkConfig[chainId]) { - throw new Error(`Missing network configuration for ${hre.network.name}`) - } - - if (developmentChains.includes(hre.network.name)) { - throw new Error(`Cannot verify contracts for development chain ${hre.network.name}`) - } - - const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) - deployments = getDeploymentFile(assetCollDeploymentFilename) - - const wTriCrypto = await ethers.getContractAt( - 'CurveVolatileCollateral', - deployments.collateral.crvTriCrypto as string - ) - - /******** Verify TriCrypto plugin **************************/ - await verifyContract( - chainId, - deployments.collateral.crvTriCrypto, - [ - { - erc20: await wTriCrypto.erc20(), - targetName: ethers.utils.formatBytes32String('TRICRYPTO'), - priceTimeout: PRICE_TIMEOUT, - chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero - oracleError: bn('1'), // unused but cannot be zero - oracleTimeout: bn('1'), // unused but cannot be zero - maxTradeVolume: MAX_TRADE_VOL, - defaultThreshold: DEFAULT_THRESHOLD, - delayUntilDefault: DELAY_UNTIL_DEFAULT, - }, - revenueHiding.toString(), - { - nTokens: 3, - curvePool: TRI_CRYPTO, - poolType: CurvePoolType.Plain, - feeds: [[USDT_USD_FEED], [WBTC_BTC_FEED, BTC_USD_FEED], [WETH_USD_FEED]], - oracleTimeouts: [ - [oracleTimeout(chainId, USDT_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, WBTC_ORACLE_TIMEOUT), oracleTimeout(chainId, BTC_ORACLE_TIMEOUT)], - [oracleTimeout(chainId, WETH_ORACLE_TIMEOUT)], - ], - oracleErrors: [ - [USDT_ORACLE_ERROR], - [WBTC_BTC_ORACLE_ERROR, BTC_USD_ORACLE_ERROR], - [WETH_ORACLE_ERROR], - ], - lpToken: TRI_CRYPTO_TOKEN, - }, - ], - 'contracts/plugins/assets/convex/CurveVolatileCollateral.sol:CurveVolatileCollateral' - ) -} - -main().catch((error) => { - console.error(error) - process.exitCode = 1 -}) diff --git a/scripts/verification/collateral-plugins/verify_cusdbcv3.ts b/scripts/verification/collateral-plugins/verify_cusdbcv3.ts index c3a6cb314..d0eb672ef 100644 --- a/scripts/verification/collateral-plugins/verify_cusdbcv3.ts +++ b/scripts/verification/collateral-plugins/verify_cusdbcv3.ts @@ -7,7 +7,7 @@ import { getAssetCollDeploymentFilename, IAssetCollDeployments, } from '../../deployment/common' -import { priceTimeout, oracleTimeout, verifyContract, revenueHiding } from '../../deployment/utils' +import { priceTimeout, verifyContract, revenueHiding } from '../../deployment/utils' let deployments: IAssetCollDeployments @@ -50,7 +50,7 @@ async function main() { /******** Verify Collateral - wcUSDbCv3 **************************/ - const usdcOracleTimeout = 86400 // 24 hr + const usdcOracleTimeout = '86400' // 24 hr const usdcOracleError = fp('0.003') // 0.3% (Base) await verifyContract( @@ -63,7 +63,7 @@ async function main() { oracleError: usdcOracleError.toString(), erc20: await collateral.erc20(), maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout).toString(), // 24h hr, + oracleTimeout: usdcOracleTimeout, // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdcOracleError).toString(), // 1% + 0.3% delayUntilDefault: bn('86400').toString(), // 24h diff --git a/scripts/verification/collateral-plugins/verify_cusdcv3.ts b/scripts/verification/collateral-plugins/verify_cusdcv3.ts index 62c138928..09a6eceb3 100644 --- a/scripts/verification/collateral-plugins/verify_cusdcv3.ts +++ b/scripts/verification/collateral-plugins/verify_cusdcv3.ts @@ -7,7 +7,7 @@ import { getAssetCollDeploymentFilename, IAssetCollDeployments, } from '../../deployment/common' -import { priceTimeout, oracleTimeout, verifyContract, revenueHiding } from '../../deployment/utils' +import { priceTimeout, verifyContract, revenueHiding } from '../../deployment/utils' let deployments: IAssetCollDeployments @@ -45,7 +45,7 @@ async function main() { /******** Verify Collateral - wcUSDCv3 **************************/ - const usdcOracleTimeout = 86400 // 24 hr + const usdcOracleTimeout = '86400' // 24 hr const usdcOracleError = baseL2Chains.includes(hre.network.name) ? fp('0.003') : fp('0.0025') // 0.3% (Base) or 0.25% await verifyContract( @@ -58,7 +58,7 @@ async function main() { oracleError: usdcOracleError.toString(), erc20: await collateral.erc20(), maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, usdcOracleTimeout).toString(), // 24h hr, + oracleTimeout: usdcOracleTimeout, // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01').add(usdcOracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h diff --git a/scripts/verification/collateral-plugins/verify_morpho.ts b/scripts/verification/collateral-plugins/verify_morpho.ts index ba7658f5a..4f9e6d832 100644 --- a/scripts/verification/collateral-plugins/verify_morpho.ts +++ b/scripts/verification/collateral-plugins/verify_morpho.ts @@ -7,13 +7,7 @@ import { getAssetCollDeploymentFilename, IAssetCollDeployments, } from '../../deployment/common' -import { - combinedError, - priceTimeout, - oracleTimeout, - verifyContract, - revenueHiding, -} from '../../deployment/utils' +import { combinedError, priceTimeout, verifyContract, revenueHiding } from '../../deployment/utils' let deployments: IAssetCollDeployments @@ -64,7 +58,7 @@ async function main() { priceTimeout: priceTimeout.toString(), oracleError: fp('0.0025').toString(), // 0.25% maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 1 hr + oracleTimeout: '86400', // 1 hr targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0025').add(fp('0.01')).toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -92,7 +86,7 @@ async function main() { priceTimeout: priceTimeout.toString(), oracleError: combinedBTCWBTCError.toString(), // 0.25% maxTradeVolume: fp('1e6'), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600'), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: fp('0.01').add(combinedBTCWBTCError), // ~3.5% delayUntilDefault: bn('86400'), // 24h @@ -101,7 +95,7 @@ async function main() { }, revenueHiding, networkConfig[chainId].chainlinkFeeds.WBTC!, - oracleTimeout(chainId, '86400').toString(), // 1 hr + '86400', // 1 hr ], 'contracts/plugins/assets/morpho-aave/MorphoNonFiatCollateral.sol:MorphoNonFiatCollateral' ) @@ -121,7 +115,7 @@ async function main() { priceTimeout: priceTimeout, oracleError: fp('0.005'), maxTradeVolume: fp('1e6'), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600'), // 1 hr + oracleTimeout: '3600', // 1 hr targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0'), // 0% -- no soft default for self-referential collateral delayUntilDefault: bn('86400'), // 24h diff --git a/scripts/verification/collateral-plugins/verify_reth.ts b/scripts/verification/collateral-plugins/verify_reth.ts index 324a08185..077cc76e0 100644 --- a/scripts/verification/collateral-plugins/verify_reth.ts +++ b/scripts/verification/collateral-plugins/verify_reth.ts @@ -7,7 +7,7 @@ import { getAssetCollDeploymentFilename, IAssetCollDeployments, } from '../../deployment/common' -import { priceTimeout, oracleTimeout, verifyContract, combinedError } from '../../deployment/utils' +import { priceTimeout, verifyContract, combinedError } from '../../deployment/utils' let deployments: IAssetCollDeployments @@ -37,14 +37,14 @@ async function main() { oracleError: oracleError.toString(), // 0.5% & 2%, erc20: networkConfig[chainId].tokens.rETH, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr, + oracleTimeout: '3600', // 1 hr, targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.02').add(oracleError).toString(), // ~4.5% delayUntilDefault: bn('86400').toString(), // 24h }, fp('1e-4'), // revenueHiding = 0.01% networkConfig[chainId].chainlinkFeeds.rETH, // refPerTokChainlinkFeed - oracleTimeout(chainId, '86400').toString(), // refPerTokChainlinkTimeout + '86400', // refPerTokChainlinkTimeout ], 'contracts/plugins/assets/rocket-eth/RethCollateral.sol:RethCollateral' ) diff --git a/scripts/verification/collateral-plugins/verify_stargate_usdc.ts b/scripts/verification/collateral-plugins/verify_stargate_usdc.ts new file mode 100644 index 000000000..3973a5ee5 --- /dev/null +++ b/scripts/verification/collateral-plugins/verify_stargate_usdc.ts @@ -0,0 +1,114 @@ +import hre from 'hardhat' +import { getChainId } from '../../../common/blockchain-utils' +import { baseL2Chains, developmentChains, networkConfig } from '../../../common/configuration' +import { fp, bn } from '../../../common/numbers' +import { + getDeploymentFile, + getAssetCollDeploymentFilename, + IAssetCollDeployments, +} from '../../deployment/common' +import { priceTimeout, oracleTimeout, verifyContract, combinedError, revenueHiding } from '../../deployment/utils' + +let deployments: IAssetCollDeployments + +async function main() { + // ********** Read config ********** + const chainId = await getChainId(hre) + if (!networkConfig[chainId]) { + throw new Error(`Missing network configuration for ${hre.network.name}`) + } + + if (developmentChains.includes(hre.network.name)) { + throw new Error(`Cannot verify contracts for development chain ${hre.network.name}`) + } + + const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) + deployments = getDeploymentFile(assetCollDeploymentFilename) + + /******** Verify Stargate USDC - wsgUSDC **************************/ + + if (!baseL2Chains.includes(hre.network.name)) { + const name = 'Wrapped Stargate USDC' + const symbol = 'wsgUSDC' + const sUSDC = networkConfig[chainId].tokens.sUSDC + + await verifyContract( + chainId, + deployments.erc20s.wsgUSDC, + [ + name, + symbol, + networkConfig[chainId].tokens.STG, + networkConfig[chainId].STARGATE_STAKING_CONTRACT, + sUSDC + ], + 'contracts/plugins/assets/stargate/StargateRewardableWrapper.sol:StargateRewardableWrapper' + ) + + const oracleError = fp('0.0025') // 0.25% + + await verifyContract( + chainId, + deployments.collateral.wsgUSDC, + [ + { + priceTimeout: priceTimeout.toString(), + chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC!, + oracleError: oracleError, // 0.25% + erc20: deployments.erc20s.wsgUSDC!, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: oracleTimeout(chainId, '1200').toString(), // 20 min + targetName: hre.ethers.utils.formatBytes32String('USD'), + defaultThreshold: fp('0.01').add(oracleError).toString(), + delayUntilDefault: bn('86400').toString(), // 24h + }, + revenueHiding.toString() + ], + 'contracts/plugins/assets/stargate/StargatePoolFiatCollateral.sol:StargatePoolFiatCollateral' + ) + } else if (chainId == '8453' || chainId == '84531') { + const name = 'Wrapped Stargate USDbC' + const symbol = 'wsgUSDbC' + const sUSDC = networkConfig[chainId].tokens.sUSDbC + + await verifyContract( + chainId, + deployments.erc20s.wsgUSDbC, + [ + name, + symbol, + networkConfig[chainId].tokens.STG, + networkConfig[chainId].STARGATE_STAKING_CONTRACT, + sUSDC + ], + 'contracts/plugins/assets/stargate/StargateRewardableWrapper.sol:StargateRewardableWrapper' + ) + + const oracleError = fp('0.003') // 0.3% + + await verifyContract( + chainId, + deployments.collateral.wsgUSDbC, + [ + { + priceTimeout: priceTimeout.toString(), + chainlinkFeed: networkConfig['8453'].chainlinkFeeds.USDC!, + oracleError: oracleError.toString(), + erc20: deployments.erc20s.wsgUSDbC!, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: oracleTimeout('8453', '86400').toString(), // 24h hr, + targetName: hre.ethers.utils.formatBytes32String('USD'), + defaultThreshold: fp('0.01').add(oracleError).toString(), // ~2.5% + delayUntilDefault: bn('86400').toString(), // 24h + }, + revenueHiding.toString() + ], + 'contracts/plugins/assets/stargate/StargatePoolFiatCollateral.sol:StargatePoolFiatCollateral' + ) + } +} + +main().catch((error) => { + console.error(error) + process.exitCode = 1 +}) diff --git a/scripts/verification/collateral-plugins/verify_wsteth.ts b/scripts/verification/collateral-plugins/verify_wsteth.ts index c0b73b2fb..b84c9aad5 100644 --- a/scripts/verification/collateral-plugins/verify_wsteth.ts +++ b/scripts/verification/collateral-plugins/verify_wsteth.ts @@ -7,7 +7,7 @@ import { getAssetCollDeploymentFilename, IAssetCollDeployments, } from '../../deployment/common' -import { priceTimeout, oracleTimeout, verifyContract } from '../../deployment/utils' +import { priceTimeout, verifyContract } from '../../deployment/utils' let deployments: IAssetCollDeployments @@ -38,14 +38,14 @@ async function main() { oracleError: fp('0.01').toString(), // 1%: only for stETHUSD feed erc20: networkConfig[chainId].tokens.wstETH, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr, + oracleTimeout: '3600', // 1 hr, targetName: hre.ethers.utils.formatBytes32String('ETH'), defaultThreshold: fp('0.025').toString(), // 2.5% = 2% + 0.5% stethETH feed oracleError delayUntilDefault: bn('86400').toString(), // 24h }, fp('1e-4'), // revenueHiding = 0.01% networkConfig[chainId].chainlinkFeeds.stETHETH, // targetPerRefChainlinkFeed - oracleTimeout(chainId, '86400').toString(), // targetPerRefChainlinkTimeout + '86400', // targetPerRefChainlinkTimeout ], 'contracts/plugins/assets/lido/LidoStakedEthCollateral.sol:LidoStakedEthCollateral' ) diff --git a/test/Broker.test.ts b/test/Broker.test.ts index 251d0e1a5..633d1fed4 100644 --- a/test/Broker.test.ts +++ b/test/Broker.test.ts @@ -42,7 +42,7 @@ import { Implementation, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, SLOW, } from './fixtures' @@ -1251,7 +1251,7 @@ describe(`BrokerP${IMPLEMENTATION} contract #fast`, () => { oracleError: ORACLE_ERROR, erc20: token0.address, maxTradeVolume: bn(500), - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -1416,7 +1416,7 @@ describe(`BrokerP${IMPLEMENTATION} contract #fast`, () => { oracleError: bn('1'), // minimize erc20: sellTok.address, maxTradeVolume: MAX_UINT192, - oracleTimeout: MAX_UINT48, + oracleTimeout: MAX_UINT48.sub(300), targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01'), // shouldn't matter delayUntilDefault: bn('604800'), // shouldn't matter @@ -1428,7 +1428,7 @@ describe(`BrokerP${IMPLEMENTATION} contract #fast`, () => { oracleError: bn('1'), // minimize erc20: buyTok.address, maxTradeVolume: MAX_UINT192, - oracleTimeout: MAX_UINT48, + oracleTimeout: MAX_UINT48.sub(300), targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01'), // shouldn't matter delayUntilDefault: bn('604800'), // shouldn't matter diff --git a/test/Main.test.ts b/test/Main.test.ts index 755620008..de7d519b7 100644 --- a/test/Main.test.ts +++ b/test/Main.test.ts @@ -71,6 +71,7 @@ import { IMPLEMENTATION, ORACLE_ERROR, ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, REVENUE_HIDING, } from './fixtures' @@ -1181,7 +1182,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: newToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral0.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: await ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral0.delayUntilDefault(), @@ -1203,7 +1204,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: newToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral0.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: await ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral0.delayUntilDefault(), @@ -1229,7 +1230,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: await gasGuzzlingColl.erc20(), maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral0.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: await ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral0.delayUntilDefault(), @@ -1628,7 +1629,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: erc20s[5].address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral2.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral2.delayUntilDefault(), @@ -1724,7 +1725,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: eurToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral0.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral1.delayUntilDefault(), @@ -1947,7 +1948,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: await collateral0.erc20(), maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral0.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('NEW_TARGET'), defaultThreshold: fp('0.01'), delayUntilDefault: await collateral0.delayUntilDefault(), @@ -2802,7 +2803,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: await collateral2.erc20(), maxTradeVolume: await collateral2.maxTradeVolume(), - oracleTimeout: await collateral2.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral2.delayUntilDefault(), @@ -2837,7 +2838,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: await collateral2.erc20(), maxTradeVolume: await collateral2.maxTradeVolume(), - oracleTimeout: await collateral2.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral2.delayUntilDefault(), @@ -2862,7 +2863,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: await collateral2.erc20(), maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral2.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral2.delayUntilDefault(), @@ -3084,7 +3085,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: await collateral2.erc20(), maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral2.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral2.delayUntilDefault(), @@ -3128,7 +3129,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: await collateral2.erc20(), maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral2.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral2.delayUntilDefault(), @@ -3158,7 +3159,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: token0.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: await collateral0.oracleTimeout(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: await ethers.utils.formatBytes32String('NEW TARGET'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral0.delayUntilDefault(), diff --git a/test/RTokenExtremes.test.ts b/test/RTokenExtremes.test.ts index 229960812..f5c8afa99 100644 --- a/test/RTokenExtremes.test.ts +++ b/test/RTokenExtremes.test.ts @@ -21,7 +21,7 @@ import { IMPLEMENTATION, ORACLE_ERROR, SLOW, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, defaultFixtureNoBasket, } from './fixtures' @@ -66,7 +66,7 @@ describe(`RTokenP${IMPLEMENTATION} contract`, () => { oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: fp('1e36'), - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01'), delayUntilDefault: bn(86400), diff --git a/test/Recollateralization.test.ts b/test/Recollateralization.test.ts index 37cfe6955..30796f9b8 100644 --- a/test/Recollateralization.test.ts +++ b/test/Recollateralization.test.ts @@ -51,6 +51,7 @@ import { IMPLEMENTATION, ORACLE_ERROR, ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, } from './fixtures' import snapshotGasCost from './utils/snapshotGasCost' @@ -643,7 +644,7 @@ describe(`Recollateralization - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: token1.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await collateral1.delayUntilDefault(), @@ -656,7 +657,7 @@ describe(`Recollateralization - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: backupToken1.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await backupCollateral1.delayUntilDefault(), @@ -2145,7 +2146,7 @@ describe(`Recollateralization - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: token0.address, maxTradeVolume: fp('25'), - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: await backupCollateral1.delayUntilDefault(), @@ -3248,7 +3249,6 @@ describe(`Recollateralization - P${IMPLEMENTATION}`, () => { collateral1.address, collateral0.address, issueAmount, - config.minTradeVolume, config.maxTradeSlippage ), bn('1e12') @@ -3312,7 +3312,6 @@ describe(`Recollateralization - P${IMPLEMENTATION}`, () => { collateral0.address, collateral1.address, issueAmount, - config.minTradeVolume, config.maxTradeSlippage ), bn('1e12') // decimals diff --git a/test/Revenues.test.ts b/test/Revenues.test.ts index d631a6f2e..1c7ad79df 100644 --- a/test/Revenues.test.ts +++ b/test/Revenues.test.ts @@ -13,6 +13,7 @@ import { CollateralStatus, TradeKind, MAX_UINT192, + ONE_PERIOD, } from '../common/constants' import { expectEvents } from '../common/events' import { bn, divCeil, fp, near } from '../common/numbers' @@ -59,6 +60,7 @@ import { REVENUE_HIDING, ORACLE_ERROR, ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, } from './fixtures' import { expectRTokenPrice, setOraclePrice } from './utils/oracles' @@ -554,7 +556,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { ) }) - it('Should forward RSR revenue directly to StRSR', async () => { + it('Should forward RSR revenue directly to StRSR and call payoutRewards()', async () => { const amount = bn('2000e18') await rsr.connect(owner).mint(backingManager.address, amount) expect(await rsr.balanceOf(backingManager.address)).to.equal(amount) @@ -562,7 +564,23 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { expect(await rsr.balanceOf(rsrTrader.address)).to.equal(0) expect(await rsr.balanceOf(rTokenTrader.address)).to.equal(0) - await expect(backingManager.forwardRevenue([rsr.address])).to.emit(rsr, 'Transfer') + // Advance to the end of noop period + await advanceTime(Number(ONE_PERIOD)) + + await expectEvents(backingManager.forwardRevenue([rsr.address]), [ + { + contract: rsr, + name: 'Transfer', + args: [backingManager.address, stRSR.address, amount], + emitted: true, + }, + { + contract: stRSR, + name: 'RewardsPaid', + emitted: true, + }, + ]) + expect(await rsr.balanceOf(backingManager.address)).to.equal(0) expect(await rsr.balanceOf(stRSR.address)).to.equal(amount) expect(await rsr.balanceOf(rsrTrader.address)).to.equal(0) @@ -688,6 +706,33 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { expect(newRTokenTotal).equal(bn(0)) }) + it('Should account rewards when distributing tokenToBuy', async () => { + // 1. StRSR.payoutRewards() + const stRSRBal = await rsr.balanceOf(stRSR.address) + await rsr.connect(owner).mint(rsrTrader.address, issueAmount) + await advanceTime(Number(ONE_PERIOD)) + await expect(rsrTrader.distributeTokenToBuy()).to.emit(stRSR, 'RewardsPaid') + const expectedAmountStRSR = stRSRBal.add(issueAmount) + expect(await rsr.balanceOf(stRSR.address)).to.be.closeTo(expectedAmountStRSR, 100) + + // 2. Furnace.melt() + // Transfer RTokens to Furnace (to trigger melting later) + const hndAmt: BigNumber = bn('10e18') + await rToken.connect(addr1).transfer(furnace.address, hndAmt) + await advanceTime(Number(ONE_PERIOD)) + await furnace.melt() + + // Transfer and distribute tokens in Trader (will melt) + await advanceTime(Number(ONE_PERIOD)) + await rToken.connect(addr1).transfer(rTokenTrader.address, hndAmt) + await expect(rTokenTrader.distributeTokenToBuy()).to.emit(rToken, 'Melted') + const expectedAmountFurnace = hndAmt.mul(2) + expect(await rToken.balanceOf(furnace.address)).to.be.closeTo( + expectedAmountFurnace, + expectedAmountFurnace.div(1000) + ) // within 0.1% + }) + it('Should update distribution even if distributeTokenToBuy() reverts', async () => { // Check initial status const [rTokenTotal, rsrTotal] = await distributor.totals() @@ -1170,7 +1215,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { ORACLE_ERROR, aaveToken.address, bn(606), // 2 qTok auction at $300 (after accounting for price.high) - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) // Set a very high price @@ -1251,7 +1296,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { ORACLE_ERROR, aaveToken.address, MAX_UINT192, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -1262,7 +1307,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { ORACLE_ERROR, rsr.address, MAX_UINT192, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -1430,7 +1475,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { ORACLE_ERROR, aaveToken.address, fp('1'), - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -1629,7 +1674,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { ORACLE_ERROR, aaveToken.address, fp('1'), - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -1828,7 +1873,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { ORACLE_ERROR, aaveToken.address, fp('1'), - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -3332,7 +3377,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: token2.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.05'), delayUntilDefault: await collateral2.delayUntilDefault(), @@ -4534,7 +4579,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { ORACLE_ERROR, compToken.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) diff --git a/test/__snapshots__/Broker.test.ts.snap b/test/__snapshots__/Broker.test.ts.snap index 635ba04aa..ceb61ab16 100644 --- a/test/__snapshots__/Broker.test.ts.snap +++ b/test/__snapshots__/Broker.test.ts.snap @@ -10,12 +10,12 @@ exports[`BrokerP1 contract #fast Gas Reporting DutchTrade Open Trade 3`] = `371 exports[`BrokerP1 contract #fast Gas Reporting DutchTrade Settle Trade 1`] = `63333`; -exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Initialize Trade 1`] = `451427`; +exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Initialize Trade 1`] = `449950`; -exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Open Trade 1`] = `541279`; +exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Open Trade 1`] = `539802`; -exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Open Trade 2`] = `529117`; +exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Open Trade 2`] = `527640`; -exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Open Trade 3`] = `531255`; +exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Open Trade 3`] = `529778`; -exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Settle Trade 1`] = `113056`; +exports[`BrokerP1 contract #fast Gas Reporting GnosisTrade Settle Trade 1`] = `113028`; diff --git a/test/__snapshots__/FacadeWrite.test.ts.snap b/test/__snapshots__/FacadeWrite.test.ts.snap index 143651b3a..71ba5454b 100644 --- a/test/__snapshots__/FacadeWrite.test.ts.snap +++ b/test/__snapshots__/FacadeWrite.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`FacadeWrite contract Deployment Process Gas Reporting Phase 1 - RToken Deployment 1`] = `8572904`; +exports[`FacadeWrite contract Deployment Process Gas Reporting Phase 1 - RToken Deployment 1`] = `8532211`; exports[`FacadeWrite contract Deployment Process Gas Reporting Phase 2 - Deploy governance 1`] = `5464253`; diff --git a/test/__snapshots__/Main.test.ts.snap b/test/__snapshots__/Main.test.ts.snap index ffecb35bc..80025274f 100644 --- a/test/__snapshots__/Main.test.ts.snap +++ b/test/__snapshots__/Main.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`MainP1 contract Gas Reporting Asset Registry - Refresh 1`] = `393837`; +exports[`MainP1 contract Gas Reporting Asset Registry - Refresh 1`] = `393877`; exports[`MainP1 contract Gas Reporting Asset Registry - Register Asset 1`] = `195889`; diff --git a/test/__snapshots__/RToken.test.ts.snap b/test/__snapshots__/RToken.test.ts.snap index c725eeb99..78da6ac50 100644 --- a/test/__snapshots__/RToken.test.ts.snap +++ b/test/__snapshots__/RToken.test.ts.snap @@ -1,10 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`RTokenP1 contract Gas Reporting Issuance: within block 1`] = `782158`; +exports[`RTokenP1 contract Gas Reporting Issuance: within block 1`] = `782198`; -exports[`RTokenP1 contract Gas Reporting Issuance: within block 2`] = `609158`; +exports[`RTokenP1 contract Gas Reporting Issuance: within block 2`] = `609198`; -exports[`RTokenP1 contract Gas Reporting Redemption 1`] = `583862`; +exports[`RTokenP1 contract Gas Reporting Redemption 1`] = `583902`; exports[`RTokenP1 contract Gas Reporting Transfer 1`] = `56658`; diff --git a/test/__snapshots__/Recollateralization.test.ts.snap b/test/__snapshots__/Recollateralization.test.ts.snap index ddde5b4fe..6b70c5b36 100644 --- a/test/__snapshots__/Recollateralization.test.ts.snap +++ b/test/__snapshots__/Recollateralization.test.ts.snap @@ -1,19 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Recollateralization - P1 Gas Reporting rebalance() - DutchTrade 1`] = `1365473`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - DutchTrade 1`] = `1363847`; -exports[`Recollateralization - P1 Gas Reporting rebalance() - DutchTrade 2`] = `1500861`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - DutchTrade 2`] = `1499568`; -exports[`Recollateralization - P1 Gas Reporting rebalance() - DutchTrade 3`] = `755062`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - DutchTrade 3`] = `738601`; -exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 1`] = `1659319`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 1`] = `1656950`; -exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 2`] = `174808`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 2`] = `174781`; -exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 3`] = `1602220`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 3`] = `1599095`; -exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 4`] = `174808`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 4`] = `174781`; -exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 5`] = `1689982`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 5`] = `1687568`; -exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 6`] = `202908`; +exports[`Recollateralization - P1 Gas Reporting rebalance() - GnosisTrade 6`] = `202854`; diff --git a/test/__snapshots__/Revenues.test.ts.snap b/test/__snapshots__/Revenues.test.ts.snap index bb7a77e72..ac389f42c 100644 --- a/test/__snapshots__/Revenues.test.ts.snap +++ b/test/__snapshots__/Revenues.test.ts.snap @@ -1,27 +1,27 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 1`] = `164974`; +exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 1`] = `168005`; -exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 2`] = `165027`; +exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 2`] = `168058`; -exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 3`] = `165027`; +exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 3`] = `168058`; -exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 4`] = `208624`; +exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 4`] = `211655`; -exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 5`] = `229377`; +exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 5`] = `232408`; -exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 6`] = `212277`; +exports[`Revenues - P1 Gas Reporting Claim and Sweep Rewards 6`] = `215308`; -exports[`Revenues - P1 Gas Reporting Selling RToken 1`] = `1020522`; +exports[`Revenues - P1 Gas Reporting Selling RToken 1`] = `1044877`; -exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 1`] = `774070`; +exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 1`] = `796514`; -exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 2`] = `1175816`; +exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 2`] = `1198554`; -exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 3`] = `311446`; +exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 3`] = `367726`; -exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 4`] = `266512`; +exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 4`] = `317915`; -exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 5`] = `739870`; +exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 5`] = `762314`; -exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 6`] = `242306`; +exports[`Revenues - P1 Gas Reporting Settle Trades / Manage Funds 6`] = `284933`; diff --git a/test/__snapshots__/ZZStRSR.test.ts.snap b/test/__snapshots__/ZZStRSR.test.ts.snap index 63500d716..08449237d 100644 --- a/test/__snapshots__/ZZStRSR.test.ts.snap +++ b/test/__snapshots__/ZZStRSR.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`StRSRP1 contract Gas Reporting Stake 1`] = `139717`; +exports[`StRSRP1 contract Gas Reporting Stake 1`] = `156559`; exports[`StRSRP1 contract Gas Reporting Stake 2`] = `134917`; @@ -10,10 +10,10 @@ exports[`StRSRP1 contract Gas Reporting Transfer 2`] = `41509`; exports[`StRSRP1 contract Gas Reporting Transfer 3`] = `58621`; -exports[`StRSRP1 contract Gas Reporting Unstake 1`] = `222609`; +exports[`StRSRP1 contract Gas Reporting Unstake 1`] = `241951`; exports[`StRSRP1 contract Gas Reporting Unstake 2`] = `139758`; -exports[`StRSRP1 contract Gas Reporting Withdraw 1`] = `606273`; +exports[`StRSRP1 contract Gas Reporting Withdraw 1`] = `606313`; -exports[`StRSRP1 contract Gas Reporting Withdraw 2`] = `536407`; +exports[`StRSRP1 contract Gas Reporting Withdraw 2`] = `536447`; diff --git a/test/fixtures.ts b/test/fixtures.ts index 366e08f5b..a5730b13c 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -71,14 +71,20 @@ export const SLOW = !!useEnv('SLOW') export const PRICE_TIMEOUT = bn('604800') // 1 week -export const ORACLE_TIMEOUT = bn('281474976710655').div(100) // type(uint48).max / 100 +export const ORACLE_TIMEOUT_PRE_BUFFER = bn('281474976710655').div(100) // type(uint48).max / 100 + +export const ORACLE_TIMEOUT = ORACLE_TIMEOUT_PRE_BUFFER.add(300) export const ORACLE_ERROR = fp('0.01') // 1% oracle error export const REVENUE_HIDING = fp('0') // no revenue hiding by default; test individually // This will have to be updated on each release +<<<<<<< HEAD export const VERSION = '3.1.0' +======= +export const VERSION = '3.0.1' +>>>>>>> 3.1.0 export type Collateral = | FiatCollateral @@ -183,7 +189,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: defaultThreshold, delayUntilDefault: delayUntilDefault, @@ -203,7 +209,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: defaultThreshold, delayUntilDefault: delayUntilDefault, @@ -223,7 +229,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: defaultThreshold, delayUntilDefault: delayUntilDefault, @@ -252,7 +258,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: defaultThreshold, delayUntilDefault: delayUntilDefault, @@ -280,7 +286,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: defaultThreshold, delayUntilDefault: delayUntilDefault, @@ -499,7 +505,7 @@ const makeDefaultFixture = async (setBasket: boolean): Promise = ORACLE_ERROR, rsr.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) await rsrAsset.refresh() @@ -631,7 +637,7 @@ const makeDefaultFixture = async (setBasket: boolean): Promise = ORACLE_ERROR, aaveToken.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) await aaveAsset.refresh() @@ -646,7 +652,7 @@ const makeDefaultFixture = async (setBasket: boolean): Promise = ORACLE_ERROR, compToken.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) await compAsset.refresh() diff --git a/test/integration/AssetPlugins.test.ts b/test/integration/AssetPlugins.test.ts index 1729c21c9..71ae4bf11 100644 --- a/test/integration/AssetPlugins.test.ts +++ b/test/integration/AssetPlugins.test.ts @@ -8,6 +8,7 @@ import { IMPLEMENTATION, ORACLE_ERROR, ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, REVENUE_HIDING, } from '../fixtures' @@ -1122,7 +1123,7 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, ORACLE_ERROR, networkConfig[chainId].tokens.stkAAVE || '', config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) await setOraclePrice(zeroPriceAsset.address, bn('1e10')) @@ -1202,7 +1203,7 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, oracleError: ORACLE_ERROR, erc20: dai.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -1288,7 +1289,7 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, oracleError: ORACLE_ERROR, erc20: cDaiVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -1376,7 +1377,7 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, oracleError: ORACLE_ERROR, erc20: stataDai.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -1455,13 +1456,13 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, oracleError: ORACLE_ERROR, erc20: wbtc.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold, delayUntilDefault, }, mockChainlinkFeed.address, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) await setOraclePrice(zeroPriceNonFiatCollateral.address, bn('1e10')) await zeroPriceNonFiatCollateral.refresh() @@ -1535,13 +1536,13 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, oracleError: ORACLE_ERROR, erc20: cWBTCVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold, delayUntilDefault, }, mockChainlinkFeed.address, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, REVENUE_HIDING ) ) @@ -1610,7 +1611,7 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, oracleError: ORACLE_ERROR, erc20: weth.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: bn('0'), delayUntilDefault, @@ -1693,7 +1694,7 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, oracleError: ORACLE_ERROR, erc20: cETHVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: bn('0'), delayUntilDefault, @@ -1776,13 +1777,13 @@ describeFork(`Asset Plugins - Integration - Mainnet Forking P${IMPLEMENTATION}`, oracleError: ORACLE_ERROR, erc20: eurt.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold, delayUntilDefault, }, mockChainlinkFeed.address, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) await setOraclePrice(invalidPriceEURCollateral.address, bn('1e10')) await invalidPriceEURCollateral.refresh() diff --git a/test/integration/CTokenVaultGas.test.ts b/test/integration/CTokenVaultGas.test.ts new file mode 100644 index 000000000..9bf568772 --- /dev/null +++ b/test/integration/CTokenVaultGas.test.ts @@ -0,0 +1,235 @@ +import { useEnv } from '#/utils/env' +import { BigNumber } from 'ethers' +import { defaultFixtureNoBasket } from './fixtures' +import { loadFixture } from '@nomicfoundation/hardhat-network-helpers' +import { CTokenFiatCollateral } from '@typechain/CTokenFiatCollateral' +import { IConfig, networkConfig } from '#/common/configuration' +import { TestIRToken } from '@typechain/TestIRToken' +import snapshotGasCost from '../utils/snapshotGasCost' +import { ethers } from 'hardhat' +import { advanceTime, getLatestBlockTimestamp, setNextBlockTimestamp } from '../utils/time' +import { CTokenWrapper } from '@typechain/CTokenWrapper' +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' +import { ICToken } from '@typechain/ICToken' +import { bn, fp } from '#/common/numbers' +import { + Collateral, + IMPLEMENTATION, + Implementation, + ORACLE_ERROR, + ORACLE_TIMEOUT, + PRICE_TIMEOUT, + REVENUE_HIDING, +} from '../fixtures' +import { IERC20Metadata } from '@typechain/IERC20Metadata' +import { TestIBasketHandler } from '@typechain/TestIBasketHandler' +import { TestIBackingManager } from '@typechain/TestIBackingManager' +import { IAssetRegistry } from '@typechain/IAssetRegistry' +import { whileImpersonating } from '../utils/impersonation' + +const describeGas = + IMPLEMENTATION == Implementation.P1 && useEnv('REPORT_GAS') ? describe.only : describe.skip + +describe(`CTokenVault contract`, () => { + let owner: SignerWithAddress + let addr1: SignerWithAddress + let addr2: SignerWithAddress + + // Tokens and Assets + let initialBal: BigNumber + let cTokenUnwrapped: ICToken + let cTokenWrapped: CTokenWrapper + + let cTokenCollateralUnwrapped: Collateral + let cTokenCollateralWrapped: Collateral + + // Config values + let config: IConfig + + // Main + let rToken: TestIRToken + let assetRegistry: IAssetRegistry + let backingManager: TestIBackingManager + let basketHandler: TestIBasketHandler + + beforeEach(async () => { + ;[owner, addr1, addr2] = await ethers.getSigners() + + // Deploy fixture + ;({ assetRegistry, backingManager, basketHandler, config, rToken } = await loadFixture( + defaultFixtureNoBasket + )) + + const defaultThreshold = fp('0.01') // 1% + const delayUntilDefault = bn('86400') // 24h + const CTokenCollateralFactory = await ethers.getContractFactory('CTokenFiatCollateral') + cTokenCollateralUnwrapped = await CTokenCollateralFactory.deploy( + { + priceTimeout: PRICE_TIMEOUT, + chainlinkFeed: networkConfig['31337'].chainlinkFeeds.DAI!, + oracleError: ORACLE_ERROR, + erc20: networkConfig['31337'].tokens.cDAI!, + maxTradeVolume: config.rTokenMaxTradeVolume, + oracleTimeout: ORACLE_TIMEOUT, + targetName: ethers.utils.formatBytes32String('USD'), + defaultThreshold, + delayUntilDefault, + }, + REVENUE_HIDING + ) + await cTokenCollateralUnwrapped.refresh() + + const CTokenWrapperFactory = await ethers.getContractFactory('CTokenWrapper') + const erc20: IERC20Metadata = ( + await ethers.getContractAt('ICToken', networkConfig['31337'].tokens.cDAI!) + ) + cTokenWrapped = await CTokenWrapperFactory.deploy( + erc20.address, + `${await erc20.name()} Vault`, + `${await erc20.symbol()}-VAULT`, + networkConfig['31337'].COMPTROLLER! + ) + cTokenCollateralWrapped = await CTokenCollateralFactory.deploy( + { + priceTimeout: PRICE_TIMEOUT, + chainlinkFeed: networkConfig['31337'].chainlinkFeeds.DAI!, + oracleError: ORACLE_ERROR, + erc20: cTokenWrapped.address, + maxTradeVolume: config.rTokenMaxTradeVolume, + oracleTimeout: ORACLE_TIMEOUT, + targetName: ethers.utils.formatBytes32String('USD'), + defaultThreshold, + delayUntilDefault, + }, + REVENUE_HIDING + ) + await cTokenCollateralWrapped.refresh() + + // Advance time post warmup period + await advanceTime(Number(config.warmupPeriod) + 1) + + // Mint initial balances + const dai = await ethers.getContractAt('ERC20Mock', networkConfig['31337'].tokens.DAI!) + cTokenUnwrapped = await ethers.getContractAt('ICToken', networkConfig['31337'].tokens.cDAI!) + const holderDAI = '0x16b34ce9a6a6f7fc2dd25ba59bf7308e7b38e186' + initialBal = fp('1e7') // 10x the issuance throttle amount + await whileImpersonating(holderDAI, async (daiSigner) => { + await dai.connect(daiSigner).transfer(addr1.address, initialBal) + }) + await dai.connect(addr1).approve(cTokenUnwrapped.address, initialBal) + await cTokenUnwrapped.connect(addr1).mint(initialBal) + }) + + describeGas('Gas Reporting, cTokens', () => { + const initialBal = fp('1e7') + + describe('Unwrapped', () => { + let tokenBal: BigNumber + + beforeEach(async () => { + await assetRegistry.connect(owner).register(cTokenCollateralUnwrapped.address) + + const basketsNeededAmts = [fp('1.0')] + await basketHandler + .connect(owner) + .setPrimeBasket([cTokenUnwrapped.address], basketsNeededAmts) + await basketHandler.connect(owner).refreshBasket() + + // Set up allowances + await backingManager.grantRTokenAllowance(cTokenUnwrapped.address) + + // Charge throttle + await setNextBlockTimestamp(Number(await getLatestBlockTimestamp()) + 3600) + + tokenBal = await cTokenUnwrapped.balanceOf(addr1.address) + + // Provide approvals + await cTokenUnwrapped.connect(addr1).approve(rToken.address, initialBal) + }) + + it('Transfer', async () => { + // Transfer + await snapshotGasCost( + cTokenUnwrapped.connect(addr1).transfer(addr2.address, tokenBal.div(10)) + ) + + // Transfer again + await snapshotGasCost( + cTokenUnwrapped.connect(addr1).transfer(addr2.address, tokenBal.div(10)) + ) + + // Transfer back + await snapshotGasCost( + cTokenUnwrapped.connect(addr2).transfer(addr1.address, tokenBal.div(10)) + ) + }) + + it('Issue RToken', async () => { + // Issue rTokens twice within block + await snapshotGasCost(rToken.connect(addr1).issue(tokenBal.div(10))) + await snapshotGasCost(rToken.connect(addr1).issue(tokenBal.div(10))) + }) + + it('Redeem RToken', async () => { + await rToken.connect(addr1).issue(tokenBal.div(10)) + await snapshotGasCost(rToken.connect(addr1).redeem(tokenBal.div(10))) + }) + }) + + describe('Wrapped', () => { + let tokenBal: BigNumber + + beforeEach(async () => { + const unwrappedBal = await cTokenUnwrapped.balanceOf(addr1.address) + await cTokenUnwrapped.connect(addr1).approve(cTokenWrapped.address, unwrappedBal) + await cTokenWrapped.connect(addr1).deposit(unwrappedBal, addr1.address) + await assetRegistry.connect(owner).register(cTokenCollateralWrapped.address) + + const basketsNeededAmts = [fp('1.0')] + await basketHandler + .connect(owner) + .setPrimeBasket([cTokenWrapped.address], basketsNeededAmts) + await basketHandler.connect(owner).refreshBasket() + + // Set up allowances + await backingManager.grantRTokenAllowance(cTokenWrapped.address) + + // Charge throttle + await setNextBlockTimestamp(Number(await getLatestBlockTimestamp()) + 3600) + + tokenBal = await cTokenWrapped.balanceOf(addr1.address) + + // Provide approvals + await cTokenWrapped.connect(addr1).approve(rToken.address, initialBal) + }) + + it('Transfer', async () => { + // Transfer + await snapshotGasCost( + cTokenWrapped.connect(addr1).transfer(addr2.address, tokenBal.div(10)) + ) + + // Transfer again + await snapshotGasCost( + cTokenWrapped.connect(addr1).transfer(addr2.address, tokenBal.div(10)) + ) + + // Transfer back + await snapshotGasCost( + cTokenWrapped.connect(addr2).transfer(addr1.address, tokenBal.div(10)) + ) + }) + + it('Issue RToken', async () => { + // Issue rTokens twice within block + await snapshotGasCost(rToken.connect(addr1).issue(tokenBal.div(10))) + await snapshotGasCost(rToken.connect(addr1).issue(tokenBal.div(10))) + }) + + it('Redeem RToken', async () => { + await rToken.connect(addr1).issue(tokenBal.div(10)) + await snapshotGasCost(rToken.connect(addr1).redeem(tokenBal.div(10))) + }) + }) + }) +}) diff --git a/test/integration/EasyAuction.test.ts b/test/integration/EasyAuction.test.ts index af2f43904..355d92f00 100644 --- a/test/integration/EasyAuction.test.ts +++ b/test/integration/EasyAuction.test.ts @@ -753,7 +753,7 @@ describeFork(`Gnosis EasyAuction Mainnet Forking - P${IMPLEMENTATION}`, function oracleError: ORACLE_ERROR, // shouldn't matter erc20: sellTok.address, maxTradeVolume: MAX_UINT192, - oracleTimeout: MAX_UINT48, + oracleTimeout: MAX_UINT48.sub(300), targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01'), // shouldn't matter delayUntilDefault: bn('604800'), // shouldn't matter @@ -765,7 +765,7 @@ describeFork(`Gnosis EasyAuction Mainnet Forking - P${IMPLEMENTATION}`, function oracleError: ORACLE_ERROR, // shouldn't matter erc20: buyTok.address, maxTradeVolume: MAX_UINT192, - oracleTimeout: MAX_UINT48, + oracleTimeout: MAX_UINT48.sub(300), targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.01'), // shouldn't matter delayUntilDefault: bn('604800'), // shouldn't matter diff --git a/test/integration/fixtures.ts b/test/integration/fixtures.ts index fa2a57358..206cfb2af 100644 --- a/test/integration/fixtures.ts +++ b/test/integration/fixtures.ts @@ -60,7 +60,7 @@ import { Implementation, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, REVENUE_HIDING, } from '../fixtures' @@ -146,7 +146,7 @@ interface CollateralFixture { basketsNeededAmts: BigNumber[] // reference amounts } -async function collateralFixture( +export async function collateralFixture( comptroller: ComptrollerMock, aaveLendingPool: AaveLendingPoolMock, config: IConfig @@ -190,7 +190,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -219,7 +219,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: vault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -254,7 +254,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: staticErc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -280,13 +280,13 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String(targetName), defaultThreshold, delayUntilDefault, }, targetUnitOracleAddr, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) await coll.refresh() return [erc20, coll] @@ -314,13 +314,13 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: vault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String(targetName), defaultThreshold, delayUntilDefault, }, targetUnitOracleAddr, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, REVENUE_HIDING ) await coll.refresh() @@ -339,7 +339,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String(targetName), defaultThreshold: bn(0), delayUntilDefault, @@ -371,7 +371,7 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: vault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String(targetName), defaultThreshold: bn(0), delayUntilDefault, @@ -399,13 +399,13 @@ async function collateralFixture( oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String(targetName), defaultThreshold, delayUntilDefault, }, targetUnitOracleAddr, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) await coll.refresh() return [erc20, coll] @@ -696,7 +696,7 @@ const makeDefaultFixture = async (setBasket: boolean): Promise = ORACLE_ERROR, rsr.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) await rsrAsset.refresh() @@ -820,7 +820,7 @@ const makeDefaultFixture = async (setBasket: boolean): Promise = ORACLE_ERROR, aaveToken.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) await aaveAsset.refresh() @@ -834,7 +834,7 @@ const makeDefaultFixture = async (setBasket: boolean): Promise = ORACLE_ERROR, compToken.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) await compAsset.refresh() diff --git a/test/integration/fork-block-numbers.ts b/test/integration/fork-block-numbers.ts index cf5b9d033..30df303ed 100644 --- a/test/integration/fork-block-numbers.ts +++ b/test/integration/fork-block-numbers.ts @@ -5,7 +5,7 @@ const forkBlockNumber = { 'mainnet-deployment': 15690042, // Ethereum 'flux-finance': 16836855, // Ethereum 'mainnet-2.0': 17522362, // Ethereum - default: 16934828, // Ethereum + default: 18371215, // Ethereum } export default forkBlockNumber diff --git a/test/plugins/Asset.test.ts b/test/plugins/Asset.test.ts index 95ad7cd34..4dd32dc76 100644 --- a/test/plugins/Asset.test.ts +++ b/test/plugins/Asset.test.ts @@ -45,6 +45,7 @@ import { IMPLEMENTATION, Implementation, ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, ORACLE_ERROR, PRICE_TIMEOUT, VERSION, @@ -430,7 +431,7 @@ describe('Assets contracts #fast', () => { oracleError: ORACLE_ERROR, erc20: await collateral0.erc20(), maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -467,7 +468,7 @@ describe('Assets contracts #fast', () => { oracleError: ORACLE_ERROR, erc20: await collateral0.erc20(), maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -555,7 +556,7 @@ describe('Assets contracts #fast', () => { ORACLE_ERROR, rsr.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -640,7 +641,7 @@ describe('Assets contracts #fast', () => { ORACLE_ERROR, rsr.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) diff --git a/test/plugins/Collateral.test.ts b/test/plugins/Collateral.test.ts index f7337177e..e52458f39 100644 --- a/test/plugins/Collateral.test.ts +++ b/test/plugins/Collateral.test.ts @@ -52,6 +52,7 @@ import { Collateral, defaultFixture, ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, ORACLE_ERROR, PRICE_TIMEOUT, REVENUE_HIDING, @@ -254,7 +255,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: token.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.constants.HashZero, defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -272,7 +273,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: aToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -290,7 +291,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -308,7 +309,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: token.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: bn(0), @@ -324,7 +325,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: aToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: bn(0), @@ -342,7 +343,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: bn(0), @@ -360,7 +361,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: token.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: MAX_DELAY_UNTIL_DEFAULT + 1, @@ -376,7 +377,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: aToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: MAX_DELAY_UNTIL_DEFAULT + 1, @@ -394,7 +395,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: MAX_DELAY_UNTIL_DEFAULT + 1, @@ -413,7 +414,7 @@ describe('Collateral contracts', () => { oracleError: bn('0'), erc20: token.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -429,7 +430,7 @@ describe('Collateral contracts', () => { oracleError: bn('0'), erc20: aToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -447,7 +448,7 @@ describe('Collateral contracts', () => { oracleError: bn('0'), erc20: cToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: bn(0), @@ -466,7 +467,7 @@ describe('Collateral contracts', () => { oracleError: fp('1'), erc20: token.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -482,7 +483,7 @@ describe('Collateral contracts', () => { oracleError: fp('1'), erc20: aToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -500,7 +501,7 @@ describe('Collateral contracts', () => { oracleError: fp('1'), erc20: cToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -521,7 +522,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: aToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -539,7 +540,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -775,7 +776,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: aToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -1180,13 +1181,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: nonFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, targetUnitOracle.address, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) await nonFiatCollateral.refresh() @@ -1203,13 +1204,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: nonFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: bn(0), }, targetUnitOracle.address, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ).to.be.revertedWith('delayUntilDefault zero') }) @@ -1223,13 +1224,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: nonFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, ZERO_ADDRESS, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ).to.be.revertedWith('missing targetUnit feed') }) @@ -1243,13 +1244,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: nonFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, targetUnitOracle.address, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ).to.be.revertedWith('missing chainlink feed') }) @@ -1263,7 +1264,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: nonFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -1283,13 +1284,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: nonFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, }, targetUnitOracle.address, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ).to.be.revertedWith('defaultThreshold zero') }) @@ -1379,13 +1380,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: nonFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, targetUnitOracle.address, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -1407,13 +1408,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: nonFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, invalidChainlinkFeed.address, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) // Reverting with no reason @@ -1468,13 +1469,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, targetUnitOracle.address, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, REVENUE_HIDING ) await cTokenNonFiatCollateral.refresh() @@ -1492,13 +1493,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: bn(0), }, targetUnitOracle.address, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, REVENUE_HIDING ) ).to.be.revertedWith('delayUntilDefault zero') @@ -1513,13 +1514,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, targetUnitOracle.address, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, fp('1') ) ).to.be.revertedWith('revenueHiding out of range') @@ -1534,13 +1535,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, targetUnitOracle.address, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, REVENUE_HIDING ) ).to.be.revertedWith('missing chainlink feed') @@ -1555,13 +1556,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, }, ZERO_ADDRESS, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, REVENUE_HIDING ) ).to.be.revertedWith('missing targetUnit feed') @@ -1576,7 +1577,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -1597,13 +1598,13 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, }, targetUnitOracle.address, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, REVENUE_HIDING ) ).to.be.revertedWith('defaultThreshold zero') @@ -1816,7 +1817,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -1845,7 +1846,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cNonFiatTokenVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -1887,7 +1888,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: selfRefToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: 0, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -1927,7 +1928,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: selfRefToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: bn(100), delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -1992,7 +1993,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: selfRefToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: 0, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2042,7 +2043,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cSelfRefToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: 0, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2066,7 +2067,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cSelfRefToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2086,7 +2087,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cSelfRefToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2106,7 +2107,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cSelfRefToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: bn(200), delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2301,7 +2302,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: cSelfRefToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: 0, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2351,7 +2352,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: eurFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2374,7 +2375,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: eurFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: bn(0), @@ -2394,7 +2395,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: eurFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2414,7 +2415,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: eurFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2434,7 +2435,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: eurFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2454,7 +2455,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: eurFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2557,7 +2558,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: eurFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -2585,7 +2586,7 @@ describe('Collateral contracts', () => { oracleError: ORACLE_ERROR, erc20: eurFiatToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, diff --git a/test/plugins/individual-collateral/aave-v3/AaveV3FiatCollateral.test.ts b/test/plugins/individual-collateral/aave-v3/AaveV3FiatCollateral.test.ts index 687ab7a07..a15ac37a2 100644 --- a/test/plugins/individual-collateral/aave-v3/AaveV3FiatCollateral.test.ts +++ b/test/plugins/individual-collateral/aave-v3/AaveV3FiatCollateral.test.ts @@ -13,11 +13,17 @@ import { expect } from 'chai' import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' import { noop } from 'lodash' import { PRICE_TIMEOUT } from '#/test/fixtures' -import { networkConfig } from '#/common/configuration' -import { getResetFork } from '../helpers' +import { resetFork } from './helpers' import { whileImpersonating } from '#/test/utils/impersonation' -import { AAVE_V3_USDC_POOL, AAVE_V3_INCENTIVES_CONTROLLER } from './constants' import { pushOracleForward } from '../../../utils/oracles' +import { + forkNetwork, + AUSDC_V3, + AAVE_V3_USDC_POOL, + AAVE_V3_INCENTIVES_CONTROLLER, + USDC_USD_PRICE_FEED, + USDC_HOLDER, +} from './constants' interface AaveV3FiatCollateralFixtureContext extends CollateralFixtureContext { staticWrapper: MockStaticATokenV3LM @@ -35,7 +41,7 @@ type CollateralParams = Parameters[0] & // This defines options for the Aave V3 USDC Market export const defaultCollateralOpts: CollateralParams = { priceTimeout: PRICE_TIMEOUT, - chainlinkFeed: networkConfig[1].chainlinkFeeds.USDC!, + chainlinkFeed: USDC_USD_PRICE_FEED, oracleError: fp('0.0025'), erc20: '', // to be set maxTradeVolume: fp('1e6'), @@ -53,11 +59,7 @@ export const deployCollateral = async (opts: Partial = {}) => const V3LMFactory = await ethers.getContractFactory('MockStaticATokenV3LM') const staticWrapper = await V3LMFactory.deploy(AAVE_V3_USDC_POOL, AAVE_V3_INCENTIVES_CONTROLLER) await staticWrapper.deployed() - await staticWrapper.initialize( - networkConfig[1].tokens.aEthUSDC!, - 'Static Aave Ethereum USDC', - 'saEthUSDC' - ) + await staticWrapper.initialize(AUSDC_V3, 'Static Aave Ethereum USDC', 'saEthUSDC') combinedOpts.erc20 = staticWrapper.address } @@ -128,8 +130,8 @@ const mintCollateralTo: MintCollateralFunc = ) => { const requiredCollat = await ctx.staticWrapper.previewMint(amount) - // USDC Richie Rich - await whileImpersonating('0x0A59649758aa4d66E25f08Dd01271e891fe52199', async (signer) => { + // Impersonate holder + await whileImpersonating(USDC_HOLDER, async (signer) => { await ctx.baseToken .connect(signer) .approve(ctx.staticWrapper.address, ethers.constants.MaxUint256) @@ -204,7 +206,7 @@ export const stableOpts = { mintCollateralTo, reduceRefPerTok, increaseRefPerTok, - resetFork: getResetFork(18000000), + resetFork, collateralName: 'Aave V3 Fiat Collateral (USDC)', reduceTargetPerRef, increaseTargetPerRef, @@ -219,6 +221,7 @@ export const stableOpts = { itChecksPriceChanges: it, getExpectedPrice, toleranceDivisor: bn('1e9'), // 1e15 adjusted for ((x + 1)/x) timestamp precision + targetNetwork: forkNetwork, } collateralTests(stableOpts) diff --git a/test/plugins/individual-collateral/aave-v3/__snapshots__/AaveV3FiatCollateral.test.ts.snap b/test/plugins/individual-collateral/aave-v3/__snapshots__/AaveV3FiatCollateral.test.ts.snap index 990036897..75cffdf3e 100644 --- a/test/plugins/individual-collateral/aave-v3/__snapshots__/AaveV3FiatCollateral.test.ts.snap +++ b/test/plugins/individual-collateral/aave-v3/__snapshots__/AaveV3FiatCollateral.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: Aave V3 Fiat Collateral (USDC) collateral functionality Gas Reporting ERC20 transfer 1`] = `53509`; + +exports[`Collateral: Aave V3 Fiat Collateral (USDC) collateral functionality Gas Reporting ERC20 transfer 2`] = `36409`; + exports[`Collateral: Aave V3 Fiat Collateral (USDC) collateral functionality Gas Reporting refresh() after full price timeout 1`] = `69288`; exports[`Collateral: Aave V3 Fiat Collateral (USDC) collateral functionality Gas Reporting refresh() after full price timeout 2`] = `67620`; @@ -22,4 +26,4 @@ exports[`Collateral: Aave V3 Fiat Collateral (USDC) collateral functionality Gas exports[`Collateral: Aave V3 Fiat Collateral (USDC) collateral functionality Gas Reporting refresh() during soft default 1`] = `89634`; -exports[`Collateral: Aave V3 Fiat Collateral (USDC) collateral functionality Gas Reporting refresh() during soft default 2`] = `87966`; +exports[`Collateral: Aave V3 Fiat Collateral (USDC) collateral functionality Gas Reporting refresh() during soft default 2`] = `88040`; diff --git a/test/plugins/individual-collateral/aave-v3/constants.ts b/test/plugins/individual-collateral/aave-v3/constants.ts index 37e6c70f7..0de2aef4f 100644 --- a/test/plugins/individual-collateral/aave-v3/constants.ts +++ b/test/plugins/individual-collateral/aave-v3/constants.ts @@ -1,2 +1,32 @@ -export const AAVE_V3_USDC_POOL = '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2' -export const AAVE_V3_INCENTIVES_CONTROLLER = '0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb' +import { networkConfig } from '../../../../common/configuration' +import { useEnv } from '#/utils/env' + +export const forkNetwork = useEnv('FORK_NETWORK') ?? 'mainnet' +let chainId + +switch (forkNetwork) { + case 'mainnet': + chainId = '1' + break + case 'base': + chainId = '8453' + break + default: + chainId = '1' + break +} + +const aUSDC_NAME = chainId == '8453' ? 'aBasUSDbC' : 'aEthUSDC' + +export const AUSDC_V3 = networkConfig[chainId].tokens[aUSDC_NAME]! +export const USDC_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['USDC']! // currently same key for USDC and USDbC + +export const USDC_HOLDER = + chainId == '8453' + ? '0x4c80E24119CFB836cdF0a6b53dc23F04F7e652CA' + : '0x0A59649758aa4d66E25f08Dd01271e891fe52199' + +export const AAVE_V3_USDC_POOL = networkConfig[chainId].AAVE_V3_POOL! +export const AAVE_V3_INCENTIVES_CONTROLLER = networkConfig[chainId].AAVE_V3_INCENTIVES_CONTROLLER! + +export const FORK_BLOCK = chainId == '8453' ? 4446300 : 18000000 diff --git a/test/plugins/individual-collateral/aave-v3/helpers.ts b/test/plugins/individual-collateral/aave-v3/helpers.ts new file mode 100644 index 000000000..c6c430bc8 --- /dev/null +++ b/test/plugins/individual-collateral/aave-v3/helpers.ts @@ -0,0 +1,4 @@ +import { getResetFork } from '../helpers' +import { FORK_BLOCK } from './constants' + +export const resetFork = getResetFork(FORK_BLOCK) diff --git a/test/plugins/individual-collateral/aave/ATokenFiatCollateral.test.ts b/test/plugins/individual-collateral/aave/ATokenFiatCollateral.test.ts index 91713c469..0ba9baf74 100644 --- a/test/plugins/individual-collateral/aave/ATokenFiatCollateral.test.ts +++ b/test/plugins/individual-collateral/aave/ATokenFiatCollateral.test.ts @@ -10,7 +10,13 @@ import { PRICE_TIMEOUT, REVENUE_HIDING, } from '../../../fixtures' -import { DefaultFixture, Fixture, getDefaultFixture, ORACLE_TIMEOUT } from '../fixtures' +import { + DefaultFixture, + Fixture, + getDefaultFixture, + ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, +} from '../fixtures' import { getChainId } from '../../../../common/blockchain-utils' import forkBlockNumber from '../../../integration/fork-block-numbers' import { @@ -209,7 +215,7 @@ describeFork(`ATokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi ORACLE_ERROR, stkAave.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -233,7 +239,7 @@ describeFork(`ATokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: staticAToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -437,7 +443,7 @@ describeFork(`ATokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: ZERO_ADDRESS, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -455,7 +461,7 @@ describeFork(`ATokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: staticAToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: bn(0), delayUntilDefault, @@ -699,7 +705,7 @@ describeFork(`ATokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: staticAToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -724,7 +730,7 @@ describeFork(`ATokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: staticAToken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -1039,5 +1045,12 @@ describeFork(`ATokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi await snapshotGasCost(newADaiCollateral.refresh()) // 2nd refresh can be different than 1st }) }) + + context('ERC20 Wrapper', () => { + it('transfer', async () => { + await snapshotGasCost(staticAToken.connect(addr1).transfer(aDaiCollateral.address, bn('1'))) + await snapshotGasCost(staticAToken.connect(addr1).transfer(aDaiCollateral.address, bn('1'))) + }) + }) }) }) diff --git a/test/plugins/individual-collateral/aave/__snapshots__/ATokenFiatCollateral.test.ts.snap b/test/plugins/individual-collateral/aave/__snapshots__/ATokenFiatCollateral.test.ts.snap index 579773bc8..236eb477f 100644 --- a/test/plugins/individual-collateral/aave/__snapshots__/ATokenFiatCollateral.test.ts.snap +++ b/test/plugins/individual-collateral/aave/__snapshots__/ATokenFiatCollateral.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting ERC20 Wrapper transfer 1`] = `66986`; + +exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting ERC20 Wrapper transfer 2`] = `53409`; + exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after full price timeout 1`] = `74354`; exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after full price timeout 2`] = `72686`; @@ -12,14 +16,14 @@ exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after oracle timeout 2`] = `72686`; -exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after soft default 1`] = `91147`; +exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after soft default 1`] = `91073`; -exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after soft default 2`] = `91147`; +exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after soft default 2`] = `91073`; -exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() during SOUND 1`] = `92211`; +exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() during SOUND 1`] = `92285`; -exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() during SOUND 2`] = `92285`; +exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() during SOUND 2`] = `92211`; -exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() during soft default 1`] = `127356`; +exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() during soft default 1`] = `127282`; -exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() during soft default 2`] = `91488`; +exports[`ATokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() during soft default 2`] = `91414`; diff --git a/test/plugins/individual-collateral/ankr/__snapshots__/AnkrEthCollateralTestSuite.test.ts.snap b/test/plugins/individual-collateral/ankr/__snapshots__/AnkrEthCollateralTestSuite.test.ts.snap index 01c0ef597..64458dcd1 100644 --- a/test/plugins/individual-collateral/ankr/__snapshots__/AnkrEthCollateralTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/ankr/__snapshots__/AnkrEthCollateralTestSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: AnkrStakedETH collateral functionality Gas Reporting ERC20 transfer 1`] = `61094`; + +exports[`Collateral: AnkrStakedETH collateral functionality Gas Reporting ERC20 transfer 2`] = `43994`; + exports[`Collateral: AnkrStakedETH collateral functionality Gas Reporting refresh() after full price timeout 1`] = `60326`; exports[`Collateral: AnkrStakedETH collateral functionality Gas Reporting refresh() after full price timeout 2`] = `55857`; diff --git a/test/plugins/individual-collateral/cbeth/__snapshots__/CBETHCollateral.test.ts.snap b/test/plugins/individual-collateral/cbeth/__snapshots__/CBETHCollateral.test.ts.snap index 0bde8f543..f7366a3fb 100644 --- a/test/plugins/individual-collateral/cbeth/__snapshots__/CBETHCollateral.test.ts.snap +++ b/test/plugins/individual-collateral/cbeth/__snapshots__/CBETHCollateral.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: CBEthCollateral collateral functionality Gas Reporting ERC20 transfer 1`] = `65479`; + +exports[`Collateral: CBEthCollateral collateral functionality Gas Reporting ERC20 transfer 2`] = `48379`; + exports[`Collateral: CBEthCollateral collateral functionality Gas Reporting refresh() after full price timeout 1`] = `59813`; exports[`Collateral: CBEthCollateral collateral functionality Gas Reporting refresh() after full price timeout 2`] = `55344`; diff --git a/test/plugins/individual-collateral/collateralTests.ts b/test/plugins/individual-collateral/collateralTests.ts index 9de866af6..e077f3567 100644 --- a/test/plugins/individual-collateral/collateralTests.ts +++ b/test/plugins/individual-collateral/collateralTests.ts @@ -171,13 +171,17 @@ export default function fn( itClaimsRewards('claims rewards (via collateral.claimRewards())', async () => { const amount = bn('20').mul(bn(10).pow(await ctx.tok.decimals())) - await mintCollateralTo(ctx, amount, alice, collateral.address) + await mintCollateralTo(ctx, amount, alice, ctx.collateral.address) await advanceBlocks(1000) await setNextBlockTimestamp((await getLatestBlockTimestamp()) + 12000) - const balBefore = await (ctx.rewardToken as IERC20Metadata).balanceOf(collateral.address) - await expect(collateral.claimRewards()).to.emit(ctx.tok, 'RewardsClaimed') - const balAfter = await (ctx.rewardToken as IERC20Metadata).balanceOf(collateral.address) + const balBefore = await (ctx.rewardToken as IERC20Metadata).balanceOf( + ctx.collateral.address + ) + await expect(ctx.collateral.claimRewards()).to.emit(ctx.tok, 'RewardsClaimed') + const balAfter = await (ctx.rewardToken as IERC20Metadata).balanceOf( + ctx.collateral.address + ) expect(balAfter).gt(balBefore) }) @@ -339,14 +343,29 @@ export default function fn( }) // Should remain SOUND after a 1% decrease + let refPerTok = await ctx.collateral.refPerTok() await reduceRefPerTok(ctx, 1) // 1% decrease await ctx.collateral.refresh() expect(await ctx.collateral.status()).to.equal(CollateralStatus.SOUND) + // refPerTok should be unchanged + expect(await ctx.collateral.refPerTok()).to.be.closeTo( + refPerTok, + refPerTok.div(bn('1e3')) + ) // within 1-part-in-1-thousand + // Should become DISABLED if drops more than that + refPerTok = await ctx.collateral.refPerTok() await reduceRefPerTok(ctx, 1) // another 1% decrease await ctx.collateral.refresh() expect(await ctx.collateral.status()).to.equal(CollateralStatus.DISABLED) + + // refPerTok should have fallen 1% + refPerTok = refPerTok.sub(refPerTok.div(100)) + expect(await ctx.collateral.refPerTok()).to.be.closeTo( + refPerTok, + refPerTok.div(bn('1e3')) + ) // within 1-part-in-1-thousand }) it('reverts if Chainlink feed reverts or runs out of gas, maintains status', async () => { @@ -574,6 +593,16 @@ export default function fn( await reduceRefPerTok(ctx, 5) }) }) + + context('ERC20', () => { + it('transfer', async () => { + const decimals = await ctx.tok.decimals() + const amount = bn('20').mul(bn(10).pow(decimals)) + await mintCollateralTo(ctx, amount, alice, alice.address) + await snapshotGasCost(ctx.tok.connect(alice).transfer(collateral.address, bn('1e6'))) + await snapshotGasCost(ctx.tok.connect(alice).transfer(collateral.address, bn('1e6'))) + }) + }) }) }) }) diff --git a/test/plugins/individual-collateral/compoundv2/CTokenFiatCollateral.test.ts b/test/plugins/individual-collateral/compoundv2/CTokenFiatCollateral.test.ts index 3725338de..aefae34d5 100644 --- a/test/plugins/individual-collateral/compoundv2/CTokenFiatCollateral.test.ts +++ b/test/plugins/individual-collateral/compoundv2/CTokenFiatCollateral.test.ts @@ -10,7 +10,13 @@ import { PRICE_TIMEOUT, REVENUE_HIDING, } from '../../../fixtures' -import { DefaultFixture, Fixture, getDefaultFixture, ORACLE_TIMEOUT } from '../fixtures' +import { + DefaultFixture, + Fixture, + getDefaultFixture, + ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, +} from '../fixtures' import { getChainId } from '../../../../common/blockchain-utils' import forkBlockNumber from '../../../integration/fork-block-numbers' import { @@ -212,7 +218,7 @@ describeFork(`CTokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi ORACLE_ERROR, compToken.address, config.rTokenMaxTradeVolume, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) @@ -235,7 +241,7 @@ describeFork(`CTokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: cDaiVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -430,7 +436,7 @@ describeFork(`CTokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: ZERO_ADDRESS, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -466,7 +472,7 @@ describeFork(`CTokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: vault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -484,7 +490,7 @@ describeFork(`CTokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: cDaiVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: bn(0), delayUntilDefault, @@ -712,7 +718,7 @@ describeFork(`CTokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: cDaiVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -737,7 +743,7 @@ describeFork(`CTokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi oracleError: ORACLE_ERROR, erc20: cDaiVault.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold, delayUntilDefault, @@ -1133,5 +1139,12 @@ describeFork(`CTokenFiatCollateral - Mainnet Forking P${IMPLEMENTATION}`, functi await snapshotGasCost(newCDaiCollateral.refresh()) // 2nd refresh can be different than 1st }) }) + + context('ERC20', () => { + it('transfer', async () => { + await snapshotGasCost(cDaiVault.connect(addr1).transfer(cDaiCollateral.address, bn('1'))) + await snapshotGasCost(cDaiVault.connect(addr1).transfer(cDaiCollateral.address, bn('1'))) + }) + }) }) }) diff --git a/test/plugins/individual-collateral/compoundv2/__snapshots__/CTokenFiatCollateral.test.ts.snap b/test/plugins/individual-collateral/compoundv2/__snapshots__/CTokenFiatCollateral.test.ts.snap index 053ccfb3b..23638304f 100644 --- a/test/plugins/individual-collateral/compoundv2/__snapshots__/CTokenFiatCollateral.test.ts.snap +++ b/test/plugins/individual-collateral/compoundv2/__snapshots__/CTokenFiatCollateral.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`CTokenFiatCollateral - Mainnet Forking P1 Gas Reporting ERC20 transfer 1`] = `309933`; + +exports[`CTokenFiatCollateral - Mainnet Forking P1 Gas Reporting ERC20 transfer 2`] = `173113`; + exports[`CTokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after full price timeout 1`] = `119350`; exports[`CTokenFiatCollateral - Mainnet Forking P1 Gas Reporting refresh() after full price timeout 2`] = `117681`; diff --git a/test/plugins/individual-collateral/compoundv3/CometTestSuite.test.ts b/test/plugins/individual-collateral/compoundv3/CometTestSuite.test.ts index 66af76499..7c91bd206 100644 --- a/test/plugins/individual-collateral/compoundv3/CometTestSuite.test.ts +++ b/test/plugins/individual-collateral/compoundv3/CometTestSuite.test.ts @@ -34,6 +34,7 @@ import { setNextBlockTimestamp, } from '../../../utils/time' import { + forkNetwork, ORACLE_ERROR, ORACLE_TIMEOUT, PRICE_TIMEOUT, @@ -356,6 +357,7 @@ const collateralSpecificStatusTests = () => { }) // Should remain SOUND after a 1% decrease + let refPerTok = await collateral.refPerTok() let currentExchangeRate = await wcusdcV3Mock.exchangeRate() await wcusdcV3Mock.setMockExchangeRate( true, @@ -364,7 +366,11 @@ const collateralSpecificStatusTests = () => { await collateral.refresh() expect(await collateral.status()).to.equal(CollateralStatus.SOUND) + // refPerTok should be unchanged + expect(await collateral.refPerTok()).to.be.closeTo(refPerTok, refPerTok.div(bn('1e3'))) // within 1-part-in-1-thousand + // Should become DISABLED if drops more than that + refPerTok = await collateral.refPerTok() currentExchangeRate = await wcusdcV3Mock.exchangeRate() await wcusdcV3Mock.setMockExchangeRate( true, @@ -372,6 +378,10 @@ const collateralSpecificStatusTests = () => { ) await collateral.refresh() expect(await collateral.status()).to.equal(CollateralStatus.DISABLED) + + // refPerTok should have fallen 1% + refPerTok = refPerTok.sub(refPerTok.div(100)) + expect(await collateral.refPerTok()).to.be.closeTo(refPerTok, refPerTok.div(bn('1e3'))) // within 1-part-in-1-thousand }) } @@ -405,6 +415,7 @@ const opts = { resetFork, collateralName: 'CompoundV3USDC', chainlinkDefaultAnswer, + targetNetwork: forkNetwork, } collateralTests(opts) diff --git a/test/plugins/individual-collateral/compoundv3/CusdcV3Wrapper.test.ts b/test/plugins/individual-collateral/compoundv3/CusdcV3Wrapper.test.ts index 8a44e447a..b47b71bff 100644 --- a/test/plugins/individual-collateral/compoundv3/CusdcV3Wrapper.test.ts +++ b/test/plugins/individual-collateral/compoundv3/CusdcV3Wrapper.test.ts @@ -5,7 +5,7 @@ import { useEnv } from '#/utils/env' import { whileImpersonating } from '../../../utils/impersonation' import { advanceTime, advanceBlocks } from '../../../utils/time' import { allocateUSDC, enableRewardsAccrual, mintWcUSDC, makewCSUDC, resetFork } from './helpers' -import { COMP, REWARDS } from './constants' +import { forkNetwork, COMP, REWARDS } from './constants' import { ERC20Mock, CometInterface, @@ -20,6 +20,8 @@ import { MAX_UINT256, ZERO_ADDRESS } from '../../../../common/constants' const describeFork = useEnv('FORK') ? describe : describe.skip +const itL1 = forkNetwork != 'base' ? it : it.skip + describeFork('Wrapped CUSDCv3', () => { let bob: SignerWithAddress let charles: SignerWithAddress @@ -555,7 +557,7 @@ describeFork('Wrapped CUSDCv3', () => { const baseIndexScale = await cusdcV3.baseIndexScale() const expectedExchangeRate = totalsBasic.baseSupplyIndex.mul(bn('1e6')).div(baseIndexScale) expect(await cusdcV3.balanceOf(wcusdcV3.address)).to.equal(0) - expect(await wcusdcV3.exchangeRate()).to.equal(expectedExchangeRate) + expect(await wcusdcV3.exchangeRate()).to.be.closeTo(expectedExchangeRate, 1) }) it('returns the correct exchange rate with a positive balance', async () => { @@ -639,15 +641,16 @@ describeFork('Wrapped CUSDCv3', () => { await advanceBlocks(1) expect(await compToken.balanceOf(bob.address)).to.be.greaterThan(0) - expect(await compToken.balanceOf(bob.address)).to.equal( - await compToken.balanceOf(don.address) - ) + const balanceBob = await compToken.balanceOf(bob.address) + const balanceDon = await compToken.balanceOf(don.address) + expect(balanceDon).lessThanOrEqual(balanceBob) + expect(balanceBob).to.be.closeTo(balanceDon, balanceBob.mul(5).div(1000)) // within 0.5% }) // In this forked block, rewards accrual is not yet enabled in Comet - it('claims no rewards when rewards accrual is not enabled', async () => { + // Only applies to Mainnet forks (L1) + itL1('claims no rewards when rewards accrual is not enabled', async () => { const compToken = await ethers.getContractAt('ERC20Mock', COMP) - await advanceTime(1000) await wcusdcV3.connect(bob).claimTo(bob.address, bob.address) expect(await compToken.balanceOf(bob.address)).to.equal(0) diff --git a/test/plugins/individual-collateral/compoundv3/__snapshots__/CometTestSuite.test.ts.snap b/test/plugins/individual-collateral/compoundv3/__snapshots__/CometTestSuite.test.ts.snap index 45d7e08f7..68d964d67 100644 --- a/test/plugins/individual-collateral/compoundv3/__snapshots__/CometTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/compoundv3/__snapshots__/CometTestSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: CompoundV3USDC collateral functionality Gas Reporting ERC20 transfer 1`] = `107621`; + +exports[`Collateral: CompoundV3USDC collateral functionality Gas Reporting ERC20 transfer 2`] = `90521`; + exports[`Collateral: CompoundV3USDC collateral functionality Gas Reporting refresh() after full price timeout 1`] = `109052`; exports[`Collateral: CompoundV3USDC collateral functionality Gas Reporting refresh() after full price timeout 2`] = `104315`; diff --git a/test/plugins/individual-collateral/compoundv3/constants.ts b/test/plugins/individual-collateral/compoundv3/constants.ts index 0847fe2ae..f6cbb6ff4 100644 --- a/test/plugins/individual-collateral/compoundv3/constants.ts +++ b/test/plugins/individual-collateral/compoundv3/constants.ts @@ -1,17 +1,39 @@ import { bn, fp } from '../../../../common/numbers' import { networkConfig } from '../../../../common/configuration' +import { useEnv } from '#/utils/env' + +export const forkNetwork = useEnv('FORK_NETWORK') ?? 'mainnet' +let chainId + +switch (forkNetwork) { + case 'mainnet': + chainId = '1' + break + case 'base': + chainId = '8453' + break + default: + chainId = '1' + break +} + +const USDC_NAME = chainId == '8453' ? 'USDbC' : 'USDC' +const CUSDC_NAME = chainId == '8453' ? 'cUSDbCv3' : 'cUSDCv3' // Mainnet Addresses -export const RSR = networkConfig['31337'].tokens.RSR as string -export const USDC_USD_PRICE_FEED = networkConfig['31337'].chainlinkFeeds.USDC as string -export const CUSDC_V3 = networkConfig['31337'].tokens.cUSDCv3 as string -export const COMP = networkConfig['31337'].tokens.COMP as string -export const REWARDS = '0x1B0e765F6224C21223AeA2af16c1C46E38885a40' -export const USDC = networkConfig['31337'].tokens.USDC as string -export const USDC_HOLDER = '0x0a59649758aa4d66e25f08dd01271e891fe52199' -export const COMET_CONFIGURATOR = '0x316f9708bB98af7dA9c68C1C3b5e79039cD336E3' -export const COMET_PROXY_ADMIN = '0x1EC63B5883C3481134FD50D5DAebc83Ecd2E8779' -export const COMET_EXT = '0x285617313887d43256F852cAE0Ee4de4b68D45B0' +export const RSR = networkConfig[chainId].tokens.RSR as string +export const USDC_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds.USDC as string +export const CUSDC_V3 = networkConfig[chainId].tokens[CUSDC_NAME]! +export const COMP = networkConfig[chainId].tokens.COMP as string +export const REWARDS = networkConfig[chainId].COMET_REWARDS! +export const USDC = networkConfig[chainId].tokens[USDC_NAME]! +export const USDC_HOLDER = + chainId == '8453' + ? '0x4c80E24119CFB836cdF0a6b53dc23F04F7e652CA' + : '0x0a59649758aa4d66e25f08dd01271e891fe52199' +export const COMET_CONFIGURATOR = networkConfig[chainId].COMET_CONFIGURATOR! +export const COMET_PROXY_ADMIN = networkConfig[chainId].COMET_PROXY_ADMIN! +export const COMET_EXT = networkConfig[chainId].COMET_EXT! export const PRICE_TIMEOUT = bn(604800) // 1 week export const ORACLE_TIMEOUT = bn(86400) // 24 hours in seconds @@ -21,4 +43,4 @@ export const DELAY_UNTIL_DEFAULT = bn(86400) export const MAX_TRADE_VOL = bn(1000000) export const USDC_DECIMALS = bn(6) -export const FORK_BLOCK = 15850930 +export const FORK_BLOCK = chainId == '8453' ? 4446300 : 15850930 diff --git a/test/plugins/individual-collateral/curve/collateralTests.ts b/test/plugins/individual-collateral/curve/collateralTests.ts index 33285835f..3f9628fc7 100644 --- a/test/plugins/individual-collateral/curve/collateralTests.ts +++ b/test/plugins/individual-collateral/curve/collateralTests.ts @@ -638,6 +638,7 @@ export default function fn( expect(await ctx.collateral.whenDefault()).to.equal(MAX_UINT48) // Decrease refPerTok by 1 part in a million + const refPerTok = await ctx.collateral.refPerTok() const currentExchangeRate = await ctx.curvePool.get_virtual_price() const newVirtualPrice = currentExchangeRate.sub(currentExchangeRate.div(bn('1e6'))) await ctx.curvePool.setVirtualPrice(newVirtualPrice) @@ -650,11 +651,17 @@ export default function fn( expect(await ctx.collateral.status()).to.equal(CollateralStatus.SOUND) expect(await ctx.collateral.whenDefault()).to.equal(MAX_UINT48) + // refPerTok should be unchanged + expect(await ctx.collateral.refPerTok()).to.equal(refPerTok) + // One quanta more of decrease results in default await ctx.curvePool.setVirtualPrice(newVirtualPrice.sub(2)) // sub 2 to compenstate for rounding await expect(ctx.collateral.refresh()).to.emit(ctx.collateral, 'CollateralStatusChanged') expect(await ctx.collateral.status()).to.equal(CollateralStatus.DISABLED) expect(await ctx.collateral.whenDefault()).to.equal(await getLatestBlockTimestamp()) + + // refPerTok should have fallen exactly 2e-18 + expect(await ctx.collateral.refPerTok()).to.equal(refPerTok.sub(2)) }) describe('collateral-specific tests', collateralSpecificStatusTests) @@ -714,6 +721,18 @@ export default function fn( await ctx.curvePool.setVirtualPrice(currentExchangeRate.sub(1e3)).then((e) => e.wait()) }) }) + + context('ERC20 Wrapper', () => { + it('transfer', async () => { + await mintCollateralTo(ctx, bn('2'), ctx.alice, ctx.alice.address) + await snapshotGasCost( + ctx.wrapper.connect(ctx.alice).transfer(ctx.collateral.address, bn('1')) + ) + await snapshotGasCost( + ctx.wrapper.connect(ctx.alice).transfer(ctx.collateral.address, bn('1')) + ) + }) + }) }) }) }) diff --git a/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableMetapoolSuite.test.ts.snap b/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableMetapoolSuite.test.ts.snap index cc198f1a9..0181aff18 100644 --- a/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableMetapoolSuite.test.ts.snap +++ b/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableMetapoolSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: CurveStableMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 1`] = `382837`; + +exports[`Collateral: CurveStableMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 2`] = `360937`; + exports[`Collateral: CurveStableMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after full price timeout 1`] = `52713`; exports[`Collateral: CurveStableMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after full price timeout 2`] = `48245`; diff --git a/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableRTokenMetapoolTestSuite.test.ts.snap b/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableRTokenMetapoolTestSuite.test.ts.snap index 1023f3eb4..d4cbecc6e 100644 --- a/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableRTokenMetapoolTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableRTokenMetapoolTestSuite.test.ts.snap @@ -1,25 +1,29 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after full price timeout 1`] = `104049`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 1`] = `407643`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after full price timeout 2`] = `99581`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 2`] = `385743`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after hard default 1`] = `226544`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after full price timeout 1`] = `485294`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after hard default 2`] = `221662`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after full price timeout 2`] = `480900`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after oracle timeout 1`] = `101430`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after hard default 1`] = `594808`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after oracle timeout 2`] = `96962`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after hard default 2`] = `589778`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after soft default 1`] = `96621`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after oracle timeout 1`] = `478472`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after soft default 2`] = `96621`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after oracle timeout 2`] = `474078`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() during SOUND 1`] = `221659`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after soft default 1`] = `544737`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() during SOUND 2`] = `221659`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after soft default 2`] = `536931`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() during soft default 1`] = `209203`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() during SOUND 1`] = `713285`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() during soft default 2`] = `201935`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() during SOUND 2`] = `713507`; + +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() during soft default 1`] = `701199`; + +exports[`Collateral: CurveStableRTokenMetapoolCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() during soft default 2`] = `693635`; diff --git a/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableTestSuite.test.ts.snap b/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableTestSuite.test.ts.snap index 69fbe0cd6..ffa84bf24 100644 --- a/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/curve/crv/__snapshots__/CrvStableTestSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: CurveStableCollateral - CurveGaugeWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 1`] = `391352`; + +exports[`Collateral: CurveStableCollateral - CurveGaugeWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 2`] = `369452`; + exports[`Collateral: CurveStableCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after full price timeout 1`] = `61884`; exports[`Collateral: CurveStableCollateral - CurveGaugeWrapper collateral functionality Gas Reporting refresh() after full price timeout 2`] = `57416`; diff --git a/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableMetapoolSuite.test.ts.snap b/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableMetapoolSuite.test.ts.snap index 85b990337..9b9c0827d 100644 --- a/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableMetapoolSuite.test.ts.snap +++ b/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableMetapoolSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: CurveStableMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 1`] = `194451`; + +exports[`Collateral: CurveStableMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 2`] = `172551`; + exports[`Collateral: CurveStableMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after full price timeout 1`] = `52713`; exports[`Collateral: CurveStableMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after full price timeout 2`] = `48245`; diff --git a/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableRTokenMetapoolTestSuite.test.ts.snap b/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableRTokenMetapoolTestSuite.test.ts.snap index c5b919127..c1e15dc5e 100644 --- a/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableRTokenMetapoolTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableRTokenMetapoolTestSuite.test.ts.snap @@ -1,25 +1,29 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after full price timeout 1`] = `104049`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 1`] = `197088`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after full price timeout 2`] = `99581`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 2`] = `175188`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after hard default 1`] = `226544`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after full price timeout 1`] = `485294`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after hard default 2`] = `221662`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after full price timeout 2`] = `480826`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after oracle timeout 1`] = `101430`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after hard default 1`] = `594734`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after oracle timeout 2`] = `96962`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after hard default 2`] = `589852`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after soft default 1`] = `96621`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after oracle timeout 1`] = `478546`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after soft default 2`] = `96621`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after oracle timeout 2`] = `474078`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() during SOUND 1`] = `221659`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after soft default 1`] = `544811`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() during SOUND 2`] = `221659`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after soft default 2`] = `536931`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() during soft default 1`] = `209203`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() during SOUND 1`] = `713211`; -exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() during soft default 2`] = `201935`; +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() during SOUND 2`] = `713581`; + +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() during soft default 1`] = `701125`; + +exports[`Collateral: CurveStableRTokenMetapoolCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() during soft default 2`] = `693635`; diff --git a/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableTestSuite.test.ts.snap b/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableTestSuite.test.ts.snap index ba0b229d7..80285bbb1 100644 --- a/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/curve/cvx/__snapshots__/CvxStableTestSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: CurveStableCollateral - ConvexStakingWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 1`] = `145605`; + +exports[`Collateral: CurveStableCollateral - ConvexStakingWrapper collateral functionality Gas Reporting ERC20 Wrapper transfer 2`] = `123705`; + exports[`Collateral: CurveStableCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after full price timeout 1`] = `61884`; exports[`Collateral: CurveStableCollateral - ConvexStakingWrapper collateral functionality Gas Reporting refresh() after full price timeout 2`] = `57416`; diff --git a/test/plugins/individual-collateral/dsr/__snapshots__/SDaiCollateralTestSuite.test.ts.snap b/test/plugins/individual-collateral/dsr/__snapshots__/SDaiCollateralTestSuite.test.ts.snap index eb9ff1862..c999a57b9 100644 --- a/test/plugins/individual-collateral/dsr/__snapshots__/SDaiCollateralTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/dsr/__snapshots__/SDaiCollateralTestSuite.test.ts.snap @@ -1,6 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Collateral: SDaiCollateral collateral functionality Gas Reporting refresh() after full price timeout 1`] = `116848`; +exports[`Collateral: SDaiCollateral collateral functionality Gas Reporting ERC20 transfer 1`] = `51359`; + +exports[`Collateral: SDaiCollateral collateral functionality Gas Reporting ERC20 transfer 2`] = `34259`; + +exports[`Collateral: SDaiCollateral collateral functionality Gas Reporting refresh() after full price timeout 1`] = `116743`; exports[`Collateral: SDaiCollateral collateral functionality Gas Reporting refresh() after full price timeout 2`] = `108431`; diff --git a/test/plugins/individual-collateral/fixtures.ts b/test/plugins/individual-collateral/fixtures.ts index b1b5e9e1f..19897cfd9 100644 --- a/test/plugins/individual-collateral/fixtures.ts +++ b/test/plugins/individual-collateral/fixtures.ts @@ -31,7 +31,9 @@ import { RecollateralizationLibP1, } from '../../../typechain' -export const ORACLE_TIMEOUT = bn('500000000') // 5700d - large for tests only +export const ORACLE_TIMEOUT_PRE_BUFFER = bn('500000000') // 5700d - large for tests only + +export const ORACLE_TIMEOUT = ORACLE_TIMEOUT_PRE_BUFFER.add(300) export type Fixture = () => Promise diff --git a/test/plugins/individual-collateral/flux-finance/__snapshots__/FTokenFiatCollateral.test.ts.snap b/test/plugins/individual-collateral/flux-finance/__snapshots__/FTokenFiatCollateral.test.ts.snap index fdf917917..e9d415b72 100644 --- a/test/plugins/individual-collateral/flux-finance/__snapshots__/FTokenFiatCollateral.test.ts.snap +++ b/test/plugins/individual-collateral/flux-finance/__snapshots__/FTokenFiatCollateral.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: fDAI Collateral collateral functionality Gas Reporting ERC20 transfer 1`] = `142854`; + +exports[`Collateral: fDAI Collateral collateral functionality Gas Reporting ERC20 transfer 2`] = `105831`; + exports[`Collateral: fDAI Collateral collateral functionality Gas Reporting refresh() after full price timeout 1`] = `117350`; exports[`Collateral: fDAI Collateral collateral functionality Gas Reporting refresh() after full price timeout 2`] = `115681`; @@ -24,6 +28,10 @@ exports[`Collateral: fDAI Collateral collateral functionality Gas Reporting refr exports[`Collateral: fDAI Collateral collateral functionality Gas Reporting refresh() during soft default 2`] = `139511`; +exports[`Collateral: fFRAX Collateral collateral functionality Gas Reporting ERC20 transfer 1`] = `142854`; + +exports[`Collateral: fFRAX Collateral collateral functionality Gas Reporting ERC20 transfer 2`] = `105831`; + exports[`Collateral: fFRAX Collateral collateral functionality Gas Reporting refresh() after full price timeout 1`] = `117542`; exports[`Collateral: fFRAX Collateral collateral functionality Gas Reporting refresh() after full price timeout 2`] = `115873`; @@ -48,6 +56,10 @@ exports[`Collateral: fFRAX Collateral collateral functionality Gas Reporting ref exports[`Collateral: fFRAX Collateral collateral functionality Gas Reporting refresh() during soft default 2`] = `139693`; +exports[`Collateral: fUSDC Collateral collateral functionality Gas Reporting ERC20 transfer 1`] = `142854`; + +exports[`Collateral: fUSDC Collateral collateral functionality Gas Reporting ERC20 transfer 2`] = `105831`; + exports[`Collateral: fUSDC Collateral collateral functionality Gas Reporting refresh() after full price timeout 1`] = `125832`; exports[`Collateral: fUSDC Collateral collateral functionality Gas Reporting refresh() after full price timeout 2`] = `124163`; @@ -72,6 +84,10 @@ exports[`Collateral: fUSDC Collateral collateral functionality Gas Reporting ref exports[`Collateral: fUSDC Collateral collateral functionality Gas Reporting refresh() during soft default 2`] = `148475`; +exports[`Collateral: fUSDT Collateral collateral functionality Gas Reporting ERC20 transfer 1`] = `142854`; + +exports[`Collateral: fUSDT Collateral collateral functionality Gas Reporting ERC20 transfer 2`] = `105831`; + exports[`Collateral: fUSDT Collateral collateral functionality Gas Reporting refresh() after full price timeout 1`] = `120480`; exports[`Collateral: fUSDT Collateral collateral functionality Gas Reporting refresh() after full price timeout 2`] = `118811`; diff --git a/test/plugins/individual-collateral/frax-eth/SFrxEthTestSuite.test.ts b/test/plugins/individual-collateral/frax-eth/SFrxEthTestSuite.test.ts index 681f53ae1..7ac77c01d 100644 --- a/test/plugins/individual-collateral/frax-eth/SFrxEthTestSuite.test.ts +++ b/test/plugins/individual-collateral/frax-eth/SFrxEthTestSuite.test.ts @@ -198,7 +198,7 @@ const collateralSpecificConstructorTests = () => {} // eslint-disable-next-line @typescript-eslint/no-empty-function const collateralSpecificStatusTests = () => { - it('does revenue hiding', async () => { + it('does revenue hiding correctly', async () => { const MockFactory = await ethers.getContractFactory('SfraxEthMock') const erc20 = (await MockFactory.deploy()) as SfraxEthMock let currentPPS = await (await ethers.getContractAt('IsfrxEth', SFRX_ETH)).pricePerShare() @@ -215,14 +215,24 @@ const collateralSpecificStatusTests = () => { }) // Should remain SOUND after a 1% decrease - await erc20.setPricePerShare(currentPPS.sub(currentPPS.div(100))) + let refPerTok = await collateral.refPerTok() + const newPPS = currentPPS.sub(currentPPS.div(100)) + await erc20.setPricePerShare(newPPS) await collateral.refresh() expect(await collateral.status()).to.equal(CollateralStatus.SOUND) - // Should become DISABLED if drops more than that - await erc20.setPricePerShare(currentPPS.sub(currentPPS.div(99))) + // refPerTok should be unchanged + expect(await collateral.refPerTok()).to.be.closeTo(refPerTok, refPerTok.div(bn('1e3'))) // within 1-part-in-1-thousand + + // Should become DISABLED if drops another 1% + refPerTok = await collateral.refPerTok() + await erc20.setPricePerShare(newPPS.sub(newPPS.div(100))) await collateral.refresh() expect(await collateral.status()).to.equal(CollateralStatus.DISABLED) + + // refPerTok should have fallen 1% + refPerTok = refPerTok.sub(refPerTok.div(100)) + expect(await collateral.refPerTok()).to.be.closeTo(refPerTok, refPerTok.div(bn('1e3'))) // within 1-part-in-1-thousand }) } diff --git a/test/plugins/individual-collateral/frax-eth/__snapshots__/SFrxEthTestSuite.test.ts.snap b/test/plugins/individual-collateral/frax-eth/__snapshots__/SFrxEthTestSuite.test.ts.snap index a4797620c..58a27e831 100644 --- a/test/plugins/individual-collateral/frax-eth/__snapshots__/SFrxEthTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/frax-eth/__snapshots__/SFrxEthTestSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: SFraxEthCollateral collateral functionality Gas Reporting ERC20 transfer 1`] = `51304`; + +exports[`Collateral: SFraxEthCollateral collateral functionality Gas Reporting ERC20 transfer 2`] = `34204`; + exports[`Collateral: SFraxEthCollateral collateral functionality Gas Reporting refresh() after full price timeout 1`] = `58984`; exports[`Collateral: SFraxEthCollateral collateral functionality Gas Reporting refresh() after full price timeout 2`] = `54247`; diff --git a/test/plugins/individual-collateral/lido/__snapshots__/LidoStakedEthTestSuite.test.ts.snap b/test/plugins/individual-collateral/lido/__snapshots__/LidoStakedEthTestSuite.test.ts.snap index 97b5bdc2e..7abbfa805 100644 --- a/test/plugins/individual-collateral/lido/__snapshots__/LidoStakedEthTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/lido/__snapshots__/LidoStakedEthTestSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: LidoStakedETH collateral functionality Gas Reporting ERC20 transfer 1`] = `51664`; + +exports[`Collateral: LidoStakedETH collateral functionality Gas Reporting ERC20 transfer 2`] = `34564`; + exports[`Collateral: LidoStakedETH collateral functionality Gas Reporting refresh() after full price timeout 1`] = `88033`; exports[`Collateral: LidoStakedETH collateral functionality Gas Reporting refresh() after full price timeout 2`] = `83564`; diff --git a/test/plugins/individual-collateral/morpho-aave/MorphoAaveV2TokenisedDeposit.test.ts b/test/plugins/individual-collateral/morpho-aave/MorphoAaveV2TokenisedDeposit.test.ts index 20d9a1406..e40322631 100644 --- a/test/plugins/individual-collateral/morpho-aave/MorphoAaveV2TokenisedDeposit.test.ts +++ b/test/plugins/individual-collateral/morpho-aave/MorphoAaveV2TokenisedDeposit.test.ts @@ -7,6 +7,8 @@ import { formatUnits, parseUnits } from 'ethers/lib/utils' import { expect } from 'chai' import { loadFixture } from '@nomicfoundation/hardhat-network-helpers' import { bn } from '#/common/numbers' +import { getResetFork } from '../helpers' +import { FORK_BLOCK } from './constants' type ITokenSymbol = keyof ITokens const networkConfigToUse = networkConfig[31337] @@ -179,7 +181,8 @@ const execTestForToken = ({ type ITestContext = ReturnType extends Promise ? U : never let context: ITestContext - // const resetFork = getResetFork(17591000) + before(getResetFork(FORK_BLOCK)) + beforeEach(async () => { context = await loadFixture(beforeEachFn) }) diff --git a/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVEFiatCollateral.test.ts.snap b/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVEFiatCollateral.test.ts.snap index 1dc9e48d2..48f07dc32 100644 --- a/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVEFiatCollateral.test.ts.snap +++ b/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVEFiatCollateral.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: MorphoAAVEV2FiatCollateral - DAI collateral functionality Gas Reporting ERC20 transfer 1`] = `73881`; + +exports[`Collateral: MorphoAAVEV2FiatCollateral - DAI collateral functionality Gas Reporting ERC20 transfer 2`] = `56781`; + exports[`Collateral: MorphoAAVEV2FiatCollateral - DAI collateral functionality Gas Reporting refresh() after full price timeout 1`] = `134211`; exports[`Collateral: MorphoAAVEV2FiatCollateral - DAI collateral functionality Gas Reporting refresh() after full price timeout 2`] = `129742`; @@ -24,6 +28,10 @@ exports[`Collateral: MorphoAAVEV2FiatCollateral - DAI collateral functionality G exports[`Collateral: MorphoAAVEV2FiatCollateral - DAI collateral functionality Gas Reporting refresh() during soft default 2`] = `172408`; +exports[`Collateral: MorphoAAVEV2FiatCollateral - USDC collateral functionality Gas Reporting ERC20 transfer 1`] = `73881`; + +exports[`Collateral: MorphoAAVEV2FiatCollateral - USDC collateral functionality Gas Reporting ERC20 transfer 2`] = `56781`; + exports[`Collateral: MorphoAAVEV2FiatCollateral - USDC collateral functionality Gas Reporting refresh() after full price timeout 1`] = `134414`; exports[`Collateral: MorphoAAVEV2FiatCollateral - USDC collateral functionality Gas Reporting refresh() after full price timeout 2`] = `129945`; @@ -48,6 +56,10 @@ exports[`Collateral: MorphoAAVEV2FiatCollateral - USDC collateral functionality exports[`Collateral: MorphoAAVEV2FiatCollateral - USDC collateral functionality Gas Reporting refresh() during soft default 2`] = `172814`; +exports[`Collateral: MorphoAAVEV2FiatCollateral - USDT collateral functionality Gas Reporting ERC20 transfer 1`] = `73881`; + +exports[`Collateral: MorphoAAVEV2FiatCollateral - USDT collateral functionality Gas Reporting ERC20 transfer 2`] = `56781`; + exports[`Collateral: MorphoAAVEV2FiatCollateral - USDT collateral functionality Gas Reporting refresh() after full price timeout 1`] = `133567`; exports[`Collateral: MorphoAAVEV2FiatCollateral - USDT collateral functionality Gas Reporting refresh() after full price timeout 2`] = `129098`; diff --git a/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVENonFiatCollateral.test.ts.snap b/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVENonFiatCollateral.test.ts.snap index f767cb565..a89c7240b 100644 --- a/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVENonFiatCollateral.test.ts.snap +++ b/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVENonFiatCollateral.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: MorphoAAVEV2NonFiatCollateral - WBTC collateral functionality Gas Reporting ERC20 transfer 1`] = `73881`; + +exports[`Collateral: MorphoAAVEV2NonFiatCollateral - WBTC collateral functionality Gas Reporting ERC20 transfer 2`] = `56781`; + exports[`Collateral: MorphoAAVEV2NonFiatCollateral - WBTC collateral functionality Gas Reporting refresh() after full price timeout 1`] = `133634`; exports[`Collateral: MorphoAAVEV2NonFiatCollateral - WBTC collateral functionality Gas Reporting refresh() after full price timeout 2`] = `129165`; @@ -24,6 +28,10 @@ exports[`Collateral: MorphoAAVEV2NonFiatCollateral - WBTC collateral functionali exports[`Collateral: MorphoAAVEV2NonFiatCollateral - WBTC collateral functionality Gas Reporting refresh() during soft default 2`] = `192406`; +exports[`Collateral: MorphoAAVEV2NonFiatCollateral - stETH collateral functionality Gas Reporting ERC20 transfer 1`] = `73881`; + +exports[`Collateral: MorphoAAVEV2NonFiatCollateral - stETH collateral functionality Gas Reporting ERC20 transfer 2`] = `56781`; + exports[`Collateral: MorphoAAVEV2NonFiatCollateral - stETH collateral functionality Gas Reporting refresh() after full price timeout 1`] = `167266`; exports[`Collateral: MorphoAAVEV2NonFiatCollateral - stETH collateral functionality Gas Reporting refresh() after full price timeout 2`] = `162797`; diff --git a/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVESelfReferentialCollateral.test.ts.snap b/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVESelfReferentialCollateral.test.ts.snap index c0751869d..a420cba2b 100644 --- a/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVESelfReferentialCollateral.test.ts.snap +++ b/test/plugins/individual-collateral/morpho-aave/__snapshots__/MorphoAAVESelfReferentialCollateral.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: MorphoAAVEV2SelfReferentialCollateral - WETH collateral functionality Gas Reporting ERC20 transfer 1`] = `73881`; + +exports[`Collateral: MorphoAAVEV2SelfReferentialCollateral - WETH collateral functionality Gas Reporting ERC20 transfer 2`] = `56781`; + exports[`Collateral: MorphoAAVEV2SelfReferentialCollateral - WETH collateral functionality Gas Reporting refresh() after full price timeout 1`] = `201552`; exports[`Collateral: MorphoAAVEV2SelfReferentialCollateral - WETH collateral functionality Gas Reporting refresh() after full price timeout 2`] = `197083`; diff --git a/test/plugins/individual-collateral/rocket-eth/__snapshots__/RethCollateralTestSuite.test.ts.snap b/test/plugins/individual-collateral/rocket-eth/__snapshots__/RethCollateralTestSuite.test.ts.snap index 1827ad33b..93f294ae7 100644 --- a/test/plugins/individual-collateral/rocket-eth/__snapshots__/RethCollateralTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/rocket-eth/__snapshots__/RethCollateralTestSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: RocketPoolETH collateral functionality Gas Reporting ERC20 transfer 1`] = `59421`; + +exports[`Collateral: RocketPoolETH collateral functionality Gas Reporting ERC20 transfer 2`] = `42321`; + exports[`Collateral: RocketPoolETH collateral functionality Gas Reporting refresh() after full price timeout 1`] = `70876`; exports[`Collateral: RocketPoolETH collateral functionality Gas Reporting refresh() after full price timeout 2`] = `66407`; diff --git a/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts b/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts index e6353d174..f3f81e978 100644 --- a/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts +++ b/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts @@ -12,6 +12,7 @@ import { IStargateLPStaking, StargateRewardableWrapper, StargateRewardableWrapper__factory, + IStargatePool, } from '@typechain/index' import { pushOracleForward } from '../../../utils/oracles' import { bn, fp } from '#/common/numbers' @@ -26,15 +27,20 @@ import { SUSDC, ORACLE_TIMEOUT, ORACLE_ERROR, + STAKING_CONTRACT, + STARGATE_ROUTER, + USDC_NAME, } from './constants' import { noop } from 'lodash' +import { whileImpersonating } from '#/test/utils/impersonation' +import { useEnv } from '#/utils/env' /* Define interfaces */ interface StargateCollateralFixtureContext extends CollateralFixtureContext { - pool: StargatePoolMock + pool: StargatePoolMock | IStargatePool wpool: StargateRewardableWrapper stargate: ERC20Mock stakingContract: IStargateLPStaking @@ -138,6 +144,7 @@ const deployCollateralStargateMockContext = async ( const StargateRewardableWrapperFactory = ( await ethers.getContractFactory('StargateRewardableWrapper') ) + const stargate = await ( await ethers.getContractFactory('ERC20Mock') ).deploy('Stargate Mocked token', 'S*MT') @@ -150,12 +157,14 @@ const deployCollateralStargateMockContext = async ( await stakingContract.add(bn('5000'), mockPool.address) await mockPool.mint(stakingContract.address, bn(1e6)) await mockPool.setExchangeRate(fp(1)) + const pool = mockPool + const wrapper = await StargateRewardableWrapperFactory.deploy( - 'wMocked Pool', - 'wMSP', + 'Wrapped Stargate USDC TEST', + 'wsgUSDbC-TEST', stargate.address, stakingContract.address, - mockPool.address + pool.address ) collateralOpts.erc20 = wrapper.address collateralOpts.rewardERC20 = stargate.address @@ -169,7 +178,7 @@ const deployCollateralStargateMockContext = async ( chainlinkFeed, tok: wrapper, rewardToken, - pool: mockPool, + pool, wpool: wrapper, stargate, stakingContract, @@ -188,13 +197,15 @@ const mintCollateralTo: MintCollateralFunc = a ) => { const currentExchangeRate = await ctx.collateral.refPerTok() - // ctx.stakingContract - + await whileImpersonating(STARGATE_ROUTER, async (router) => { + await ctx.pool.connect(router).mint(user.address, amount) + }) await ctx.pool.connect(user).approve(ctx.wpool.address, ethers.constants.MaxUint256) - await ctx.pool.mint(user.address, amount) await ctx.wpool.connect(user).deposit(amount, user.address) await ctx.wpool.connect(user).transfer(recipient, amount) - await ctx.pool.setExchangeRate(currentExchangeRate.add(fp('0.000001'))) + if (ctx.pool.address != SUSDC) { + ctx.pool.setExchangeRate(currentExchangeRate.add(fp('0.000001'))) + } } const reduceRefPerTok = async ( @@ -247,6 +258,41 @@ const increaseTargetPerRef = async ( await ctx.chainlinkFeed.updateAnswer(nextAnswer) } +const beforeEachRewardsTest = async (ctx: StargateCollateralFixtureContext) => { + // switch to propoer network rewards setup + + const stargate = await ethers.getContractAt('ERC20Mock', STARGATE) + const stakingContract = ( + await ethers.getContractAt('IStargateLPStaking', STAKING_CONTRACT) + ) + const pool: StargatePoolMock | IStargatePool = await ethers.getContractAt('IStargatePool', SUSDC) + + const StargateRewardableWrapperFactory = ( + await ethers.getContractFactory('StargateRewardableWrapper') + ) + + const wrapper = await StargateRewardableWrapperFactory.deploy( + 'Wrapped Stargate USDC TEST', + 'wsgUSDbC-TEST', + stargate.address, + stakingContract.address, + pool.address + ) + const opts = { + erc20: wrapper.address, + rewardERC20: stargate.address, + } + + const collateral = await deployCollateral(opts) + + ctx.collateral = collateral + ctx.pool = pool + ctx.stakingContract = stakingContract + ctx.stargate = stargate + ctx.tok = wrapper + ctx.wpool = wrapper +} + /* Run the test suite */ @@ -255,16 +301,16 @@ export const stableOpts = { deployCollateral, collateralSpecificConstructorTests: noop, collateralSpecificStatusTests: noop, - beforeEachRewardsTest: noop, + beforeEachRewardsTest, makeCollateralFixtureContext, mintCollateralTo, reduceRefPerTok, increaseRefPerTok, resetFork, - collateralName: 'Stargate USDC Pool', + collateralName: `Stargate ${USDC_NAME} Pool`, reduceTargetPerRef, increaseTargetPerRef, - itClaimsRewards: it.skip, // reward growth not supported in mock + itClaimsRewards: it, // reward growth not supported in mock itChecksTargetPerRefDefault: it, itChecksRefPerTokDefault: it, itChecksNonZeroDefaultThreshold: it, @@ -273,6 +319,7 @@ export const stableOpts = { chainlinkDefaultAnswer: 1e8, itChecksPriceChanges: it, getExpectedPrice, + targetNetwork: useEnv('FORK_NETWORK') ?? 'mainnet', } collateralTests(stableOpts) diff --git a/test/plugins/individual-collateral/stargate/__snapshots__/StargateUSDCTestSuite.test.ts.snap b/test/plugins/individual-collateral/stargate/__snapshots__/StargateUSDCTestSuite.test.ts.snap index fc27356e8..3afcb28f2 100644 --- a/test/plugins/individual-collateral/stargate/__snapshots__/StargateUSDCTestSuite.test.ts.snap +++ b/test/plugins/individual-collateral/stargate/__snapshots__/StargateUSDCTestSuite.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Collateral: Stargate USDC Pool collateral functionality Gas Reporting ERC20 transfer 1`] = `109345`; + +exports[`Collateral: Stargate USDC Pool collateral functionality Gas Reporting ERC20 transfer 2`] = `92245`; + exports[`Collateral: Stargate USDC Pool collateral functionality Gas Reporting refresh() after full price timeout 1`] = `56094`; exports[`Collateral: Stargate USDC Pool collateral functionality Gas Reporting refresh() after full price timeout 2`] = `51626`; diff --git a/test/plugins/individual-collateral/stargate/constants.ts b/test/plugins/individual-collateral/stargate/constants.ts index 0407dcdc9..fa88507d3 100644 --- a/test/plugins/individual-collateral/stargate/constants.ts +++ b/test/plugins/individual-collateral/stargate/constants.ts @@ -1,19 +1,50 @@ import { bn, fp } from '#/common/numbers' import { networkConfig } from '#/common/configuration' +import { useEnv } from '#/utils/env' -export const STARGATE = networkConfig['1'].tokens['STG']! -export const STAKING_CONTRACT = '0xB0D502E938ed5f4df2E681fE6E419ff29631d62b' -export const SUSDC = networkConfig['1'].tokens['sUSDC']! -export const SUSDT = networkConfig['1'].tokens['sUSDT']! -export const SETH = networkConfig['1'].tokens['sETH']! -export const USDC = networkConfig['1'].tokens['USDC']! -export const USDT = networkConfig['1'].tokens['USDT']! -export const USDC_HOLDER = '0x0a59649758aa4d66e25f08dd01271e891fe52199' -export const USDC_USD_PRICE_FEED = networkConfig['1'].chainlinkFeeds['USDC']! -export const ETH_USD_PRICE_FEED = networkConfig['1'].chainlinkFeeds['ETH']! +const forkNetwork = useEnv('FORK_NETWORK') ?? 'mainnet' +let chainId + +switch (forkNetwork) { + case 'mainnet': + chainId = '1' + break + case 'base': + chainId = '8453' + break + default: + chainId = '1' + break +} + +export const USDC_NAME = chainId == '8453' ? 'USDbC' : 'USDC' +const sUSDC_NAME = chainId == '8453' ? 'sUSDbC' : 'sUSDC' + +export const STARGATE = networkConfig[chainId].tokens['STG']! +export const STAKING_CONTRACT = networkConfig[chainId].STARGATE_STAKING_CONTRACT! +export const SUSDC = networkConfig[chainId].tokens[sUSDC_NAME]! +export const SUSDT = networkConfig[chainId].tokens['sUSDT']! +export const SETH = networkConfig[chainId].tokens['sETH']! +export const USDC = networkConfig[chainId].tokens[USDC_NAME]! +export const USDT = networkConfig[chainId].tokens['USDT']! +export const USDC_HOLDER = + chainId == '8453' + ? '0x4c80e24119cfb836cdf0a6b53dc23f04f7e652ca' + : '0x0a59649758aa4d66e25f08dd01271e891fe52199' +export const USDC_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['USDC']! // currently same key for USDC and USDbC +export const ETH_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['ETH']! export const SUSDC_POOL_ID = bn('1') export const WSUSDC_NAME = 'Wrapped S*USDC' export const WSUSDC_SYMBOL = 'wS*USDC' +export const STARGATE_ROUTER = + chainId == '8453' + ? '0x45f1A95A4D3f3836523F5c83673c797f4d4d263B' + : '0x8731d54E9D02c286767d56ac03e8037C07e01e98' + +export const USDbC = networkConfig[chainId].tokens['USDbC']! +export const SUSDbC = networkConfig[chainId].tokens['sUSDbC']! +export const USDbC_HOLDER = '0x4c80e24119cfb836cdf0a6b53dc23f04f7e652ca' +// export const USDbC_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['USDbC']! export const ORACLE_TIMEOUT = bn(86400) // 24 hours in seconds export const ORACLE_ERROR = fp('0.005') @@ -22,4 +53,4 @@ export const DELAY_UNTIL_DEFAULT = bn(86400) export const MAX_TRADE_VOL = bn(1000000) export const USDC_DECIMALS = bn(6) -export const FORK_BLOCK = 18170484 +export const FORK_BLOCK = chainId == '8453' ? 4873094 : 17289300 diff --git a/test/scenario/BadCollateralPlugin.test.ts b/test/scenario/BadCollateralPlugin.test.ts index ec2e04c0e..9745c962b 100644 --- a/test/scenario/BadCollateralPlugin.test.ts +++ b/test/scenario/BadCollateralPlugin.test.ts @@ -27,7 +27,7 @@ import { defaultFixtureNoBasket, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, REVENUE_HIDING, } from '../fixtures' @@ -104,7 +104,7 @@ describe(`Bad Collateral Plugin - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: token0.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, diff --git a/test/scenario/BadERC20.test.ts b/test/scenario/BadERC20.test.ts index 6874a021c..220ed60d0 100644 --- a/test/scenario/BadERC20.test.ts +++ b/test/scenario/BadERC20.test.ts @@ -396,4 +396,39 @@ describe(`Bad ERC20 - P${IMPLEMENTATION}`, () => { ) }) }) + + describe('with fussy approvals', function () { + let issueAmt: BigNumber + + beforeEach(async () => { + issueAmt = initialBal.div(100) + await token0.connect(addr1).approve(rToken.address, issueAmt) + await token0.setRevertApprove(true) + await rToken.connect(addr1).issue(issueAmt) + }) + + context('Regression tests wcUSDCv3 10/10/2023', () => { + it('should not revert during recollateralization', async () => { + await basketHandler.setPrimeBasket( + [token0.address, backupToken.address], + [fp('0.5'), fp('0.5')] + ) + await basketHandler.refreshBasket() + + // Should launch recollateralization auction successfully + await expect(backingManager.rebalance(TradeKind.BATCH_AUCTION)) + .to.emit(backingManager, 'TradeStarted') + .withArgs(anyValue, token0.address, backupToken.address, anyValue, anyValue) + }) + + it('should not revert during revenue auction', async () => { + await token0.mint(rsrTrader.address, issueAmt) + + // Should launch revenue auction successfully + await expect(rsrTrader.manageTokens([token0.address], [TradeKind.BATCH_AUCTION])) + .to.emit(rsrTrader, 'TradeStarted') + .withArgs(anyValue, token0.address, rsr.address, anyValue, anyValue) + }) + }) + }) }) diff --git a/test/scenario/ComplexBasket.test.ts b/test/scenario/ComplexBasket.test.ts index 9dd384a82..6b7479212 100644 --- a/test/scenario/ComplexBasket.test.ts +++ b/test/scenario/ComplexBasket.test.ts @@ -34,7 +34,7 @@ import { defaultFixtureNoBasket, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, REVENUE_HIDING, } from '../fixtures' @@ -172,7 +172,7 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { ORACLE_ERROR, rsr.address, MAX_TRADE_VOLUME, - ORACLE_TIMEOUT + ORACLE_TIMEOUT_PRE_BUFFER ) ) await assetRegistry.connect(owner).swapRegistered(newRSRAsset.address) @@ -203,7 +203,7 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR.toString(), tokenAddress: usdToken.address, // DAI Token maxTradeVolume: MAX_TRADE_VOLUME.toString(), - oracleTimeout: ORACLE_TIMEOUT.toString(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD.toString(), delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(), @@ -227,8 +227,8 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR.toString(), tokenAddress: eurToken.address, maxTradeVolume: MAX_TRADE_VOLUME.toString(), - oracleTimeout: ORACLE_TIMEOUT.toString(), - targetUnitOracleTimeout: ORACLE_TIMEOUT.toString(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), + targetUnitOracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), targetName: ethers.utils.formatBytes32String('EUR'), defaultThreshold: DEFAULT_THRESHOLD.toString(), delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(), @@ -248,7 +248,7 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR.toString(), cToken: cUSDTokenVault.address, maxTradeVolume: MAX_TRADE_VOLUME.toString(), - oracleTimeout: ORACLE_TIMEOUT.toString(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD.toString(), delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(), @@ -269,7 +269,7 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR.toString(), staticAToken: aUSDToken.address, maxTradeVolume: MAX_TRADE_VOLUME.toString(), - oracleTimeout: ORACLE_TIMEOUT.toString(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD.toString(), delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(), @@ -293,8 +293,8 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { combinedOracleError: ORACLE_ERROR.toString(), tokenAddress: wbtc.address, maxTradeVolume: MAX_TRADE_VOLUME.toString(), - oracleTimeout: ORACLE_TIMEOUT.toString(), - targetUnitOracleTimeout: ORACLE_TIMEOUT.toString(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), + targetUnitOracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), targetName: ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD.toString(), delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(), @@ -323,8 +323,8 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { combinedOracleError: ORACLE_ERROR.toString(), cToken: cWBTCVault.address, maxTradeVolume: MAX_TRADE_VOLUME.toString(), - oracleTimeout: ORACLE_TIMEOUT.toString(), - targetUnitOracleTimeout: ORACLE_TIMEOUT.toString(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), + targetUnitOracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), targetName: hre.ethers.utils.formatBytes32String('BTC'), defaultThreshold: DEFAULT_THRESHOLD.toString(), delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(), @@ -349,7 +349,7 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR.toString(), tokenAddress: weth.address, maxTradeVolume: MAX_TRADE_VOLUME.toString(), - oracleTimeout: ORACLE_TIMEOUT.toString(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), targetName: hre.ethers.utils.formatBytes32String('ETH'), noOutput: true, }) @@ -380,7 +380,7 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR.toString(), cToken: cETHVault.address, maxTradeVolume: MAX_TRADE_VOLUME.toString(), - oracleTimeout: ORACLE_TIMEOUT.toString(), + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER.toString(), targetName: hre.ethers.utils.formatBytes32String('ETH'), revenueHiding: REVENUE_HIDING.toString(), referenceERC20Decimals: bn(18).toString(), diff --git a/test/scenario/MaxBasketSize.test.ts b/test/scenario/MaxBasketSize.test.ts index a3ab63214..f1380b63f 100644 --- a/test/scenario/MaxBasketSize.test.ts +++ b/test/scenario/MaxBasketSize.test.ts @@ -28,7 +28,7 @@ import { defaultFixtureNoBasket, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, REVENUE_HIDING, } from '../fixtures' @@ -158,7 +158,7 @@ describe(`Max Basket Size - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: erc20.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -198,7 +198,7 @@ describe(`Max Basket Size - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: atoken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -245,7 +245,7 @@ describe(`Max Basket Size - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: ctoken.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, diff --git a/test/scenario/NestedRTokens.test.ts b/test/scenario/NestedRTokens.test.ts index 6386b158f..38b11aba2 100644 --- a/test/scenario/NestedRTokens.test.ts +++ b/test/scenario/NestedRTokens.test.ts @@ -22,7 +22,7 @@ import { DefaultFixture, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, REVENUE_HIDING, } from '../fixtures' @@ -119,7 +119,7 @@ describe(`Nested RTokens - P${IMPLEMENTATION}`, () => { oracleError: ORACLE_ERROR, erc20: staticATokenERC20.address, maxTradeVolume: one.config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, diff --git a/test/scenario/NontrivialPeg.test.ts b/test/scenario/NontrivialPeg.test.ts index 70e0fa263..c247b1cf9 100644 --- a/test/scenario/NontrivialPeg.test.ts +++ b/test/scenario/NontrivialPeg.test.ts @@ -23,7 +23,7 @@ import { defaultFixtureNoBasket, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, } from '../fixtures' @@ -82,7 +82,7 @@ describe(`The peg (target/ref) should be arbitrary - P${IMPLEMENTATION}`, () => oracleError: ORACLE_ERROR, erc20: token1.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -124,7 +124,7 @@ describe(`The peg (target/ref) should be arbitrary - P${IMPLEMENTATION}`, () => oracleError: ORACLE_ERROR, erc20: token0.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, diff --git a/test/scenario/RevenueHiding.test.ts b/test/scenario/RevenueHiding.test.ts index 8b1cfa00f..815ff2f7f 100644 --- a/test/scenario/RevenueHiding.test.ts +++ b/test/scenario/RevenueHiding.test.ts @@ -25,7 +25,7 @@ import { defaultFixtureNoBasket, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, } from '../fixtures' @@ -116,7 +116,7 @@ describe(`RevenueHiding basket collateral (/w CTokenFiatCollateral) - P${IMPLEME oracleError: ORACLE_ERROR, erc20: cDAI.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('USD'), defaultThreshold: DEFAULT_THRESHOLD, delayUntilDefault: DELAY_UNTIL_DEFAULT, diff --git a/test/scenario/SetProtocol.test.ts b/test/scenario/SetProtocol.test.ts index a2a67dd94..a9021be24 100644 --- a/test/scenario/SetProtocol.test.ts +++ b/test/scenario/SetProtocol.test.ts @@ -25,7 +25,7 @@ import { defaultFixtureNoBasket, IMPLEMENTATION, ORACLE_ERROR, - ORACLE_TIMEOUT, + ORACLE_TIMEOUT_PRE_BUFFER, PRICE_TIMEOUT, } from '../fixtures' @@ -91,7 +91,7 @@ describe(`Linear combination of self-referential collateral - P${IMPLEMENTATION} oracleError: ORACLE_ERROR, erc20: token0.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('ETH'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -106,7 +106,7 @@ describe(`Linear combination of self-referential collateral - P${IMPLEMENTATION} oracleError: ORACLE_ERROR, erc20: token1.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('MKR'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, @@ -121,7 +121,7 @@ describe(`Linear combination of self-referential collateral - P${IMPLEMENTATION} oracleError: ORACLE_ERROR, erc20: token2.address, maxTradeVolume: config.rTokenMaxTradeVolume, - oracleTimeout: ORACLE_TIMEOUT, + oracleTimeout: ORACLE_TIMEOUT_PRE_BUFFER, targetName: ethers.utils.formatBytes32String('COMP'), defaultThreshold: bn(0), delayUntilDefault: DELAY_UNTIL_DEFAULT, diff --git a/test/scenario/__snapshots__/MaxBasketSize.test.ts.snap b/test/scenario/__snapshots__/MaxBasketSize.test.ts.snap index 156f63233..73f9cbd31 100644 --- a/test/scenario/__snapshots__/MaxBasketSize.test.ts.snap +++ b/test/scenario/__snapshots__/MaxBasketSize.test.ts.snap @@ -1,19 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Max Basket Size - P1 ATokens/CTokens Should Issue/Redeem with max basket correctly 1`] = `12082293`; +exports[`Max Basket Size - P1 ATokens/CTokens Should Issue/Redeem with max basket correctly 1`] = `12082333`; -exports[`Max Basket Size - P1 ATokens/CTokens Should Issue/Redeem with max basket correctly 2`] = `9836895`; +exports[`Max Basket Size - P1 ATokens/CTokens Should Issue/Redeem with max basket correctly 2`] = `9823929`; -exports[`Max Basket Size - P1 ATokens/CTokens Should claim rewards correctly 1`] = `2281990`; +exports[`Max Basket Size - P1 ATokens/CTokens Should claim rewards correctly 1`] = `2436571`; -exports[`Max Basket Size - P1 ATokens/CTokens Should switch basket correctly 1`] = `13653640`; +exports[`Max Basket Size - P1 ATokens/CTokens Should switch basket correctly 1`] = `13653680`; -exports[`Max Basket Size - P1 ATokens/CTokens Should switch basket correctly 2`] = `20688663`; +exports[`Max Basket Size - P1 ATokens/CTokens Should switch basket correctly 2`] = `20685978`; -exports[`Max Basket Size - P1 Fiatcoins Should Issue/Redeem with max basket correctly 1`] = `10984043`; +exports[`Max Basket Size - P1 Fiatcoins Should Issue/Redeem with max basket correctly 1`] = `10984083`; -exports[`Max Basket Size - P1 Fiatcoins Should Issue/Redeem with max basket correctly 2`] = `8707789`; +exports[`Max Basket Size - P1 Fiatcoins Should Issue/Redeem with max basket correctly 2`] = `8720835`; -exports[`Max Basket Size - P1 Fiatcoins Should switch basket correctly 1`] = `6592417`; +exports[`Max Basket Size - P1 Fiatcoins Should switch basket correctly 1`] = `6592449`; -exports[`Max Basket Size - P1 Fiatcoins Should switch basket correctly 2`] = `14441485`; +exports[`Max Basket Size - P1 Fiatcoins Should switch basket correctly 2`] = `14438756`;