Skip to content

Commit

Permalink
Paypool scripts (#1092)
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick McKelvy <[email protected]>
  • Loading branch information
tbrent and pmckelvy1 authored Mar 15, 2024
1 parent 3100d72 commit 22f280f
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface IFeeds {
export interface IPools {
cvxCrvUSDUSDC?: string
cvx3Pool?: string
cvxPayPool?: string
cvxeUSDFRAXBP?: string
cvxTriCrypto?: string
cvxMIM3Pool?: string
Expand Down
1 change: 1 addition & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function main() {
'phase2-assets/collaterals/deploy_flux_finance_collateral.ts',
'phase2-assets/collaterals/deploy_ctokenv3_usdc_collateral.ts',
'phase2-assets/collaterals/deploy_convex_3pool_collateral.ts',
'phase2-assets/collaterals/deploy_convex_paypool_collateral.ts',
'phase2-assets/collaterals/deploy_convex_crvusd_usdc_collateral.ts',
'phase2-assets/collaterals/deploy_convex_rToken_metapool_plugin.ts',
'phase2-assets/collaterals/deploy_convex_stable_metapool_plugin.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import fs from 'fs'
import hre, { ethers } from 'hardhat'
import { getChainId } from '../../../../common/blockchain-utils'
import { networkConfig } from '../../../../common/configuration'
import { bn } from '../../../../common/numbers'
import { expect } from 'chai'
import { CollateralStatus, ONE_ADDRESS } from '../../../../common/constants'
import {
getDeploymentFile,
getAssetCollDeploymentFilename,
IAssetCollDeployments,
getDeploymentFilename,
fileExists,
} from '../../common'
import { CurveStableCollateral } from '../../../../typechain'
import { revenueHiding } from '../../utils'
import {
CurvePoolType,
pyUSD_ORACLE_ERROR,
pyUSD_ORACLE_TIMEOUT,
pyUSD_USD_FEED,
DEFAULT_THRESHOLD,
DELAY_UNTIL_DEFAULT,
MAX_TRADE_VOL,
PRICE_TIMEOUT,
PayPool,
PayPool_POOL_ID,
USDC_ORACLE_ERROR,
USDC_ORACLE_TIMEOUT,
USDC_USD_FEED,
} from '../../../../test/plugins/individual-collateral/curve/constants'

// Convex Stable Plugin: paypool

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 Convex Stable Pool for 3pool **************************/

const CurveStableCollateralFactory = await hre.ethers.getContractFactory('CurveStableCollateral')
const ConvexStakingWrapperFactory = await ethers.getContractFactory('ConvexStakingWrapper')

const payPool = await ConvexStakingWrapperFactory.deploy()
await payPool.deployed()
await (await payPool.initialize(PayPool_POOL_ID)).wait()

console.log(
`Deployed wrapper for Convex Stable PayPool on ${hre.network.name} (${chainId}): ${payPool.address} `
)

const collateral = <CurveStableCollateral>await CurveStableCollateralFactory.connect(
deployer
).deploy(
{
erc20: payPool.address,
targetName: ethers.utils.formatBytes32String('USD'),
priceTimeout: PRICE_TIMEOUT,
chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero
oracleError: bn('1'), // unused but cannot be zero
oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts
maxTradeVolume: MAX_TRADE_VOL,
defaultThreshold: DEFAULT_THRESHOLD,
delayUntilDefault: DELAY_UNTIL_DEFAULT,
},
revenueHiding.toString(),
{
nTokens: 2,
curvePool: PayPool,
poolType: CurvePoolType.Plain,
feeds: [[pyUSD_USD_FEED], [USDC_USD_FEED]],
oracleTimeouts: [[pyUSD_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT]],
oracleErrors: [[pyUSD_ORACLE_ERROR], [USDC_ORACLE_ERROR]],
lpToken: PayPool,
}
)
await collateral.deployed()
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

console.log(
`Deployed Convex Stable Collateral for PayPool to ${hre.network.name} (${chainId}): ${collateral.address}`
)

assetCollDeployments.collateral.cvxPayPool = collateral.address
assetCollDeployments.erc20s.cvxPayPool = payPool.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
})
92 changes: 92 additions & 0 deletions scripts/verification/collateral-plugins/verify_convex_paypool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import hre, { ethers } from 'hardhat'
import { getChainId } from '../../../common/blockchain-utils'
import { developmentChains, networkConfig } from '../../../common/configuration'
import { bn } from '../../../common/numbers'
import { ONE_ADDRESS } from '../../../common/constants'
import {
getDeploymentFile,
getAssetCollDeploymentFilename,
IAssetCollDeployments,
} from '../../deployment/common'
import { verifyContract } from '../../deployment/utils'
import { revenueHiding } from '../../deployment/utils'
import {
CurvePoolType,
pyUSD_ORACLE_ERROR,
pyUSD_ORACLE_TIMEOUT,
pyUSD_USD_FEED,
DEFAULT_THRESHOLD,
DELAY_UNTIL_DEFAULT,
MAX_TRADE_VOL,
PRICE_TIMEOUT,
PayPool,
USDC_ORACLE_ERROR,
USDC_ORACLE_TIMEOUT,
USDC_USD_FEED,
} from '../../../test/plugins/individual-collateral/curve/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)

const w3PoolCollateral = await ethers.getContractAt(
'CurveStableCollateral',
deployments.collateral.cvxPayPool as string
)

/******** Verify ConvexStakingWrapper **************************/

await verifyContract(
chainId,
await w3PoolCollateral.erc20(),
[],
'contracts/plugins/assets/curve/cvx/vendor/ConvexStakingWrapper.sol:ConvexStakingWrapper'
)

/******** Verify PayPool plugin **************************/
await verifyContract(
chainId,
deployments.collateral.cvxPayPool,
[
{
erc20: await w3PoolCollateral.erc20(),
targetName: ethers.utils.formatBytes32String('USD'),
priceTimeout: PRICE_TIMEOUT,
chainlinkFeed: ONE_ADDRESS, // unused but cannot be zero
oracleError: bn('1'), // unused but cannot be zero
oracleTimeout: USDC_ORACLE_TIMEOUT, // max of oracleTimeouts
maxTradeVolume: MAX_TRADE_VOL,
defaultThreshold: DEFAULT_THRESHOLD,
delayUntilDefault: DELAY_UNTIL_DEFAULT,
},
revenueHiding.toString(),
{
nTokens: 2,
curvePool: PayPool,
poolType: CurvePoolType.Plain,
feeds: [[pyUSD_USD_FEED], [USDC_USD_FEED]],
oracleTimeouts: [[pyUSD_ORACLE_TIMEOUT], [USDC_ORACLE_TIMEOUT]],
oracleErrors: [[pyUSD_ORACLE_ERROR], [USDC_ORACLE_ERROR]],
lpToken: PayPool,
},
],
'contracts/plugins/assets/curve/CurveStableCollateral.sol:CurveStableCollateral'
)
}

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 @@ -51,6 +51,7 @@ async function main() {
scripts.push(
'collateral-plugins/verify_convex_crvusd_usdc.ts',
'collateral-plugins/verify_convex_3pool.ts',
'collateral-plugins/verify_convex_paypool.ts',
'collateral-plugins/verify_convex_stable_metapool.ts',
'collateral-plugins/verify_convex_stable_rtoken_metapool.ts',
'collateral-plugins/verify_curve_stable.ts',
Expand Down

0 comments on commit 22f280f

Please sign in to comment.