Skip to content

Commit

Permalink
deployment + verification scripts for sFRAX (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrent authored Nov 8, 2023
1 parent 5dadd2c commit 714de4d
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 7 deletions.
1 change: 0 additions & 1 deletion .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: 18329921
FORK_NETWORK: mainnet
- run: yarn deploy:run --network localhost
env:
Expand Down
7 changes: 4 additions & 3 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function main() {
// See `confirm.ts` for part 2

// Phase 1- Implementations
let scripts = [
const scripts = [
'phase1-common/0_setup_deployments.ts',
'phase1-common/1_deploy_libraries.ts',
'phase1-common/2_deploy_implementations.ts',
Expand Down Expand Up @@ -61,7 +61,8 @@ async function main() {
'phase2-assets/collaterals/deploy_dsr_sdai.ts',
'phase2-assets/collaterals/deploy_cbeth_collateral.ts',
'phase2-assets/collaterals/deploy_morpho_aavev2_plugin.ts',
'phase2-assets/collaterals/deploy_aave_v3_usdc.ts'
'phase2-assets/collaterals/deploy_aave_v3_usdc.ts',
'phase2-assets/collaterals/deploy_sfrax.ts'
)
} else if (chainId == '8453' || chainId == '84531') {
// Base L2 chains
Expand All @@ -73,7 +74,7 @@ async function main() {
'phase2-assets/collaterals/deploy_ctokenv3_usdbc_collateral.ts',
'phase2-assets/collaterals/deploy_aave_v3_usdbc.ts',
'phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts',
'phase2-assets/assets/deploy_stg.ts',
'phase2-assets/assets/deploy_stg.ts'
)
}

Expand Down
83 changes: 83 additions & 0 deletions scripts/deployment/phase2-assets/collaterals/deploy_sfrax.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import fs from 'fs'
import hre from 'hardhat'
import { getChainId } from '../../../../common/blockchain-utils'
import { networkConfig } from '../../../../common/configuration'
import { bn, fp } from '../../../../common/numbers'
import { expect } from 'chai'
import { CollateralStatus } from '../../../../common/constants'
import {
getDeploymentFile,
getAssetCollDeploymentFilename,
IAssetCollDeployments,
getDeploymentFilename,
fileExists,
} from '../../common'
import { priceTimeout, oracleTimeout } from '../../utils'
import { SFraxCollateral } from '../../../../typechain'
import { ContractFactory } from 'ethers'

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

const deployedCollateral: string[] = []

/******** Deploy SFRAX Collateral - sFRAX **************************/

const SFraxCollateralFactory: ContractFactory = await hre.ethers.getContractFactory(
'SFraxCollateral'
)

const collateral = <SFraxCollateral>await SFraxCollateralFactory.connect(deployer).deploy(
{
priceTimeout: priceTimeout.toString(),
chainlinkFeed: networkConfig[chainId].chainlinkFeeds.FRAX,
oracleError: fp('0.01').toString(), // 1%
erc20: networkConfig[chainId].tokens.sFRAX,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: fp('0.02').toString(), // 2% = 1% oracleError + 1% buffer
delayUntilDefault: bn('86400').toString(), // 24h
},
'0' // revenueHiding = 0
)
await collateral.deployed()

console.log(`Deployed sFRAX to ${hre.network.name} (${chainId}): ${collateral.address}`)
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

assetCollDeployments.collateral.sFRAX = collateral.address
assetCollDeployments.erc20s.sFRAX = networkConfig[chainId].tokens.sFRAX
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
})
53 changes: 53 additions & 0 deletions scripts/verification/collateral-plugins/verify_sfrax.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import hre from 'hardhat'
import { getChainId } from '../../../common/blockchain-utils'
import { developmentChains, networkConfig } from '../../../common/configuration'
import { fp, bn } from '../../../common/numbers'
import {
getDeploymentFile,
getAssetCollDeploymentFilename,
IAssetCollDeployments,
} from '../../deployment/common'
import { priceTimeout, oracleTimeout, verifyContract } 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)

/******** Verify sFRAX **************************/
await verifyContract(
chainId,
deployments.collateral.sFRAX,
[
{
priceTimeout: priceTimeout.toString(),
chainlinkFeed: networkConfig[chainId].chainlinkFeeds.FRAX,
oracleError: fp('0.01').toString(), // 1%
erc20: networkConfig[chainId].tokens.sFRAX,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: fp('0.02').toString(), // 2%
delayUntilDefault: bn('86400').toString(), // 24h
},
'0', // revenueHiding = 0
],
'contracts/plugins/assets/frax/SFraxCollateral.sol:SFraxCollateral'
)
}

main().catch((error) => {
console.error(error)
process.exitCode = 1
})
5 changes: 3 additions & 2 deletions scripts/verify_etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function main() {
// even if some portions have already been verified

// Phase 1- Common
let scripts = [
const scripts = [
'0_verify_libraries.ts',
'1_verify_implementations.ts',
'2_verify_rsrAsset.ts',
Expand All @@ -61,7 +61,8 @@ async function main() {
'collateral-plugins/verify_cbeth.ts',
'collateral-plugins/verify_sdai.ts',
'collateral-plugins/verify_morpho.ts',
'collateral-plugins/verify_aave_v3_usdc.ts'
'collateral-plugins/verify_aave_v3_usdc.ts',
'collateral-plugins/verify_sfrax.ts'
)
} else if (chainId == '8453' || chainId == '84531') {
// Base L2 chains
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fork-block-numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const forkBlockNumber = {
'mainnet-deployment': 15690042, // Ethereum
'flux-finance': 16836855, // Ethereum
'mainnet-2.0': 17522362, // Ethereum
default: 16934828, // Ethereum
default: 18522901, // Ethereum
}

export default forkBlockNumber

0 comments on commit 714de4d

Please sign in to comment.