Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Trst m 14 #982

Merged
merged 13 commits into from
Oct 24, 2023
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,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
Expand Down
4 changes: 3 additions & 1 deletion contracts/plugins/assets/Asset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/deployment/phase1-common/3_deploy_rsrAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = <Asset>await ethers.getContractAt('Asset', rsrAssetAddr)
Expand Down
6 changes: 3 additions & 3 deletions scripts/deployment/phase2-assets/1_deploy_assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 (<Asset>await ethers.getContractAt('Asset', stkAAVEAsset)).refresh()

Expand All @@ -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 (<Asset>await ethers.getContractAt('Asset', compAsset)).refresh()

Expand Down
58 changes: 29 additions & 29 deletions scripts/deployment/phase2-assets/2_deploy_collateral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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 **************************/
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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', {
Expand All @@ -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 = <ICollateral>await ethers.getContractAt('ICollateral', wETHCollateral)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/deployment/phase2-assets/assets/deploy_crv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 (<Asset>await ethers.getContractAt('Asset', crvAsset)).refresh()

Expand Down
4 changes: 2 additions & 2 deletions scripts/deployment/phase2-assets/assets/deploy_cvx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 (<Asset>await ethers.getContractAt('Asset', cvxAsset)).refresh()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'),
Expand Down
Loading