Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export interface ITokens {
ETHPLUS?: string
bsdETH?: string
KNOX?: string

RLUSD?: string
aEthRLUSD?: string
saEthRLUSD?: string
}

export type ITokensKeys = Array<keyof ITokens>
Expand Down Expand Up @@ -295,6 +299,8 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
USDS: '0xdC035D45d973E3EC169d2276DDab16f1e407384F',
sUSDS: '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD',
wOETH: '0xDcEe70654261AF21C44c093C300eD3Bb97b78192',
RLUSD: '0x8292Bb45bf1Ee4d140127049757C2E0fF06317eD',
aEthRLUSD: '0xFa82580c16A31D0c1bC632A36F82e83EfEF3Eec0',
},
chainlinkFeeds: {
RSR: '0x759bBC1be8F90eE6457C44abc7d443842a976d02',
Expand Down Expand Up @@ -326,6 +332,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
USDe: '0xa569d910839Ae8865Da8F8e70FfFb0cBA869F961',
USDS: '0xfF30586cD0F29eD462364C7e81375FC0C71219b1',
OETHETH: '0x703118C4CbccCBF2AB31913e0f8075fbbb15f563', // OETH/ETH
RLUSD: '0x26C46B7aD0012cA71F2298ada567dC9Af14E7f2A',
},
AAVE_INCENTIVES: '0xd784927Ff2f95ba542BfC824c8a8a98F3495f6b5',
AAVE_EMISSIONS_MGR: '0xEE56e2B3D491590B5b31738cC34d5232F378a8D5',
Expand Down
1 change: 1 addition & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ async function main() {
'phase2-assets/collaterals/deploy_aave_v3_usdc.ts',
'phase2-assets/collaterals/deploy_aave_v3_usdt.ts',
'phase2-assets/collaterals/deploy_aave_v3_pyusd.ts',
'phase2-assets/collaterals/deploy_aave_v3_rlusd.ts',
'phase2-assets/collaterals/deploy_yearn_v2_curve_usdc.ts',
'phase2-assets/collaterals/deploy_yearn_v2_curve_usdp.ts',
'phase2-assets/collaterals/deploy_sfrax.ts',
Expand Down
111 changes: 111 additions & 0 deletions scripts/deployment/phase2-assets/collaterals/deploy_aave_v3_rlusd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import fs from 'fs'
import hre, { ethers } from 'hardhat'
import { getChainId } from '../../../../common/blockchain-utils'
import { baseL2Chains, networkConfig } from '../../../../common/configuration'
import { expect } from 'chai'
import { CollateralStatus } from '../../../../common/constants'
import {
getDeploymentFile,
getAssetCollDeploymentFilename,
IAssetCollDeployments,
getDeploymentFilename,
fileExists,
} from '../../common'
import { bn, fp } from '#/common/numbers'
import { AaveV3FiatCollateral } from '../../../../typechain'
import { priceTimeout, revenueHiding } from '../../utils'
import {
RLUSD_MAINNET_MAX_TRADE_VOLUME,
RLUSD_MAINNET_ORACLE_ERROR,
RLUSD_MAINNET_ORACLE_TIMEOUT,
} from '../../../../test/plugins/individual-collateral/aave-v3/constants'

// This file specifically deploys Aave V3 RLUSD collateral on Mainnet

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}`)
}

// Only exists on Mainnet
if (baseL2Chains.includes(hre.network.name)) {
throw new Error(`Invalid network ${hre.network.name} - only available on Mainnet`)
}

// 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 = <IAssetCollDeployments>getDeploymentFile(assetCollDeploymentFilename)

const deployedCollateral: string[] = []

const CollateralFactory = await ethers.getContractFactory('AaveV3FiatCollateral')
const StaticATokenFactory = await hre.ethers.getContractFactory('StaticATokenV3LM')

/******** Deploy Aave V3 RLUSD ERC20 **************************/

const erc20 = await StaticATokenFactory.deploy(
networkConfig[chainId].AAVE_V3_POOL!,
networkConfig[chainId].AAVE_V3_INCENTIVES_CONTROLLER!
)
await erc20.deployed()
await (
await erc20.initialize(
networkConfig[chainId].tokens.aEthRLUSD!,
'Static Aave Ethereum RLUSD',
'saEthRLUSD'
)
).wait()

/******** Deploy Aave V3 RLUSD collateral plugin **************************/

const collateral = <AaveV3FiatCollateral>await CollateralFactory.connect(deployer).deploy(
{
priceTimeout: priceTimeout,
chainlinkFeed: networkConfig[chainId].chainlinkFeeds.RLUSD!,
oracleError: RLUSD_MAINNET_ORACLE_ERROR,
erc20: erc20.address,
maxTradeVolume: RLUSD_MAINNET_MAX_TRADE_VOLUME,
oracleTimeout: RLUSD_MAINNET_ORACLE_TIMEOUT,
targetName: ethers.utils.formatBytes32String('USD'),
defaultThreshold: fp('0.01').add(RLUSD_MAINNET_ORACLE_ERROR),
delayUntilDefault: bn('86400'),
},
revenueHiding
)
await collateral.deployed()
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

console.log(
`Deployed Aave V3 RLUSD collateral to ${hre.network.name} (${chainId}): ${collateral.address}`
)

assetCollDeployments.erc20s.saEthRLUSD = erc20.address
assetCollDeployments.collateral.saEthRLUSD = collateral.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
})
74 changes: 74 additions & 0 deletions scripts/verification/collateral-plugins/verify_aave_v3_rlusd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import hre, { ethers } from 'hardhat'
import { getChainId } from '../../../common/blockchain-utils'
import { developmentChains, networkConfig } from '../../../common/configuration'
import {
getDeploymentFile,
getAssetCollDeploymentFilename,
IAssetCollDeployments,
} from '../../deployment/common'
import { fp } from '../../../common/numbers'
import { priceTimeout, verifyContract, 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 = <IAssetCollDeployments>getDeploymentFile(assetCollDeploymentFilename)

const erc20s: { [key: string]: string } = {
'1': deployments.erc20s.saEthRLUSD!,
}
const erc20 = await ethers.getContractAt('ERC20Mock', erc20s[chainId])

const collaterals: { [key: string]: string } = {
'1': deployments.collateral.saEthRLUSD!,
}
const collateral = await ethers.getContractAt('AaveV3FiatCollateral', collaterals[chainId])

/******** Verify Aave V3 RLUSD ERC20 **************************/
await verifyContract(
chainId,
erc20.address,
[networkConfig[chainId].AAVE_V3_POOL!, networkConfig[chainId].AAVE_V3_INCENTIVES_CONTROLLER!],
'contracts/plugins/assets/aave-v3/vendor/StaticATokenV3LM.sol:StaticATokenV3LM'
)

/******** Verify Aave V3 RLUSD plugin **************************/

await verifyContract(
chainId,
collateral.address,
[
{
erc20: await collateral.erc20(),
targetName: ethers.utils.formatBytes32String('USD'),
priceTimeout: priceTimeout.toString(),
chainlinkFeed: await collateral.chainlinkFeed(),
oracleError: await collateral.oracleError(),
oracleTimeout: await collateral.oracleTimeout(),
maxTradeVolume: await collateral.maxTradeVolume(),
defaultThreshold: fp('0.01')
.add(await collateral.oracleError())
.toString(),
delayUntilDefault: await collateral.delayUntilDefault(),
},
revenueHiding.toString(),
],
'contracts/plugins/assets/aave-v3/AaveV3FiatCollateral.sol:AaveV3FiatCollateral'
)
}

main().catch((error) => {
console.error(error)
process.exitCode = 1
})
1 change: 1 addition & 0 deletions scripts/verify_etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async function main() {
'collateral-plugins/verify_morpho.ts',
'collateral-plugins/verify_aave_v3_usdc.ts',
'collateral-plugins/verify_aave_v3_usdt.ts',
'collateral-plugins/verify_aave_v3_rlusd.ts',
'collateral-plugins/verify_yearn_v2_curve_usdc.ts',
'collateral-plugins/verify_yearn_v2_curve_usdp.ts',
'collateral-plugins/verify_sfrax.ts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import {
USDT_MAINNET_MAX_TRADE_VOLUME,
USDT_MAINNET_ORACLE_TIMEOUT,
USDT_MAINNET_ORACLE_ERROR,
RLUSD_MAINNET_MAX_TRADE_VOLUME,
RLUSD_MAINNET_ORACLE_TIMEOUT,
RLUSD_MAINNET_ORACLE_ERROR,
} from './constants'

// Mainnet - USDC
Expand Down Expand Up @@ -121,6 +124,30 @@ makeTests(
}
)

// Mainnet - RLUSD
makeTests(
{
priceTimeout: PRICE_TIMEOUT,
chainlinkFeed: networkConfig[1].chainlinkFeeds['RLUSD']!,
oracleError: RLUSD_MAINNET_ORACLE_ERROR,
erc20: '', // to be set
maxTradeVolume: RLUSD_MAINNET_MAX_TRADE_VOLUME,
oracleTimeout: RLUSD_MAINNET_ORACLE_TIMEOUT,
targetName: ethers.utils.formatBytes32String('USD'),
defaultThreshold: fp('0.01').add(RLUSD_MAINNET_ORACLE_TIMEOUT),
delayUntilDefault: bn('86400'),
},
{
testName: 'RLUSD - Mainnet',
aaveIncentivesController: networkConfig[1].AAVE_V3_INCENTIVES_CONTROLLER!,
aavePool: networkConfig[1].AAVE_V3_POOL!,
aToken: networkConfig[1].tokens['aEthRLUSD']!,
whaleTokenHolder: '0x1073d55Dfb892ed86151015402DB8B1CDb6edE78',
forkBlock: 23726585,
targetNetwork: 'mainnet',
}
)

// Arbitrum - USDC
makeTests(
{
Expand Down
7 changes: 2 additions & 5 deletions test/plugins/individual-collateral/aave-v3/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ export const makeTests = (defaultCollateralOpts: CollateralParams, altParams: Al
user: SignerWithAddress,
recipient: string
) => {
const requiredCollat = await ctx.staticWrapper.previewMint(amount)

// Impersonate holder
await whileImpersonating(altParams.whaleTokenHolder, async (signer) => {
await ctx.baseToken.connect(signer).approve(ctx.staticWrapper.address, 0) // required for usdt
Expand All @@ -131,9 +129,8 @@ export const makeTests = (defaultCollateralOpts: CollateralParams, altParams: Al
.connect(signer)
.approve(ctx.staticWrapper.address, ethers.constants.MaxUint256)

await ctx.staticWrapper
.connect(signer)
['deposit(uint256,address,uint16,bool)'](requiredCollat, recipient, 0, true)
// Use mint() for exact shares without rounding loss
await ctx.staticWrapper.connect(signer)['mint(uint256,address)'](amount, recipient)
})
}

Expand Down
4 changes: 4 additions & 0 deletions test/plugins/individual-collateral/aave-v3/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ export const USDT_MAINNET_ORACLE_ERROR = fp('0.0025')
export const USDT_ARBITRUM_MAX_TRADE_VOLUME = fp('1e6')
export const USDT_ARBITRUM_ORACLE_TIMEOUT = bn('86400')
export const USDT_ARBITRUM_ORACLE_ERROR = fp('0.001')

export const RLUSD_MAINNET_MAX_TRADE_VOLUME = fp('1e6')
export const RLUSD_MAINNET_ORACLE_TIMEOUT = bn('86400')
export const RLUSD_MAINNET_ORACLE_ERROR = fp('0.003')
Loading