Skip to content

Commit

Permalink
add deployment and verification scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmrodri committed Oct 7, 2024
1 parent 11f1313 commit cd4d156
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 2 deletions.
3 changes: 2 additions & 1 deletion scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ async function main() {
'phase2-assets/collaterals/deploy_USDe.ts',
'phase2-assets/assets/deploy_crv.ts',
'phase2-assets/assets/deploy_cvx.ts',
'phase2-assets/collaterals/deploy_pyusd.ts'
'phase2-assets/collaterals/deploy_pyusd.ts',
'phase2-assets/collaterals/deploy_sky_susds.ts'
)
} else if (chainId == '8453' || chainId == '84531') {
// Base L2 chains
Expand Down
84 changes: 84 additions & 0 deletions scripts/deployment/phase2-assets/collaterals/deploy_sky_susds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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 } from '../../utils'
import { SUSDSCollateral } from '../../../../typechain'
import { ContractFactory } from 'ethers'
import { ORACLE_ERROR, ORACLE_TIMEOUT } from '#/test/plugins/individual-collateral/sky/constants'

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 SUSDS Collateral - sUSDS **************************/

const SUSDSCollateralFactory: ContractFactory = await hre.ethers.getContractFactory(
'SUSDSCollateral'
)

const collateral = <SUSDSCollateral>await SUSDSCollateralFactory.connect(deployer).deploy(
{
priceTimeout: priceTimeout.toString(),
chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDS,
oracleError: ORACLE_ERROR.toString(), // 0.3%
erc20: networkConfig[chainId].tokens.sUSDS,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: ORACLE_TIMEOUT.toString(), // 24h
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: ORACLE_ERROR.add(fp('0.01')).toString(), // 1.3%
delayUntilDefault: bn('86400').toString(), // 24h
},
bn(0)
)
await collateral.deployed()

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

assetCollDeployments.collateral.sUSDS = collateral.address
assetCollDeployments.erc20s.sUSDS = networkConfig[chainId].tokens.sUSDS
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
})
57 changes: 57 additions & 0 deletions scripts/verification/collateral-plugins/verify_susds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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, verifyContract } from '../../deployment/utils'
import {
ORACLE_ERROR,
ORACLE_TIMEOUT,
} from '../../../test/plugins/individual-collateral/sky/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 = <IAssetCollDeployments>getDeploymentFile(assetCollDeploymentFilename)

/******** Verify sUSDS **************************/
await verifyContract(
chainId,
deployments.collateral.sUSDS,
[
{
priceTimeout: priceTimeout.toString(),
chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDS,
oracleError: ORACLE_ERROR.toString(), // 0.3%
erc20: networkConfig[chainId].tokens.sUSDS,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: ORACLE_TIMEOUT.toString(), // 24h
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: ORACLE_ERROR.add(fp('0.01')).toString(), // 1.3%
delayUntilDefault: bn('86400').toString(), // 24h
},
bn(0),
],
'contracts/plugins/assets/sky/SUSDSCollateral.sol:SUSDSCollateral'
)
}

main().catch((error) => {
console.error(error)
process.exitCode = 1
})
3 changes: 2 additions & 1 deletion scripts/verify_etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ async function main() {
'collateral-plugins/verify_ethx.ts',
'collateral-plugins/verify_apxeth.ts',
'collateral-plugins/verify_USDe.ts',
'collateral-plugins/verify_pyusd.ts'
'collateral-plugins/verify_pyusd.ts',
'collateral-plugins/verify_susds.ts'
)
} else if (chainId == '8453' || chainId == '84531') {
// Base L2 chains
Expand Down

0 comments on commit cd4d156

Please sign in to comment.