diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 62e19d8665..8c1d16e8da 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: 18329921 FORK_NETWORK: mainnet - run: yarn deploy:run --network localhost env: diff --git a/scripts/deploy.ts b/scripts/deploy.ts index 37166ba82a..eb9d82f713 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -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', @@ -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 @@ -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' ) } diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_sfrax.ts b/scripts/deployment/phase2-assets/collaterals/deploy_sfrax.ts new file mode 100644 index 0000000000..1510377f20 --- /dev/null +++ b/scripts/deployment/phase2-assets/collaterals/deploy_sfrax.ts @@ -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 = getDeploymentFile(assetCollDeploymentFilename) + + const deployedCollateral: string[] = [] + + /******** Deploy SFRAX Collateral - sFRAX **************************/ + + const SFraxCollateralFactory: ContractFactory = await hre.ethers.getContractFactory( + 'SFraxCollateral' + ) + + const collateral = 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 +}) diff --git a/scripts/verification/collateral-plugins/verify_sfrax.ts b/scripts/verification/collateral-plugins/verify_sfrax.ts new file mode 100644 index 0000000000..5e4be4fc45 --- /dev/null +++ b/scripts/verification/collateral-plugins/verify_sfrax.ts @@ -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 = 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 +}) diff --git a/scripts/verify_etherscan.ts b/scripts/verify_etherscan.ts index f9b9d28265..a0a69c2281 100644 --- a/scripts/verify_etherscan.ts +++ b/scripts/verify_etherscan.ts @@ -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', @@ -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 diff --git a/test/integration/fork-block-numbers.ts b/test/integration/fork-block-numbers.ts index cf5b9d0336..c575f48e3d 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: 18522901, // Ethereum } export default forkBlockNumber