Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NonPeggedFeederPool deploy task #262

Merged
merged 12 commits into from
Nov 2, 2021
23 changes: 23 additions & 0 deletions contracts/peripheral/RAI/IRedemptionPriceSnap.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.6;
pragma experimental ABIEncoderV2;

interface IRedemptionPriceSnap {
function TEN_THOUSAND() external view returns (uint256);

function addAuthorization(address account) external;

function authorizedAccounts(address) external view returns (uint256);

function modifyParameters(bytes32 parameter, address data) external;

function oracleRelayer() external view returns (address);

function removeAuthorization(address account) external;

function snappedRedemptionPrice() external view returns (uint256);

function updateAndGetSnappedPrice() external returns (uint256);

function updateSnappedPrice() external;
}
43 changes: 43 additions & 0 deletions tasks/deployFeeders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@ task("deployFeederPool", "Deploy Feeder Pool")
await deployFeederPool(signer, poolData, hre)
})

// hh --config tasks-fork.config.ts --network hardhat deployNonPeggedFeederPool --masset mUSD --fasset RAI
task("deployNonPeggedFeederPool", "Deploy Non Pegged Feeder Pool")
.addParam("masset", "Token symbol of mAsset. eg mUSD or PmUSD for Polygon", "mUSD", types.string)
.addParam("fasset", "Token symbol of Feeder Pool asset. eg GUSD, WBTC, PFRAX for Polygon", "alUSD", types.string)
.addOptionalParam("a", "Amplitude coefficient (A)", 100, types.int)
.addOptionalParam("min", "Minimum asset weight of the basket as a percentage. eg 10 for 10% of the basket.", 10, types.int)
.addOptionalParam("max", "Maximum asset weight of the basket as a percentage. eg 90 for 90% of the basket.", 90, types.int)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const signer = await getSigner(hre, taskArgs.speed)
const chain = getChain(hre)

const mAsset = resolveToken(taskArgs.masset, chain)
const fAsset = resolveToken(taskArgs.fasset, chain)

if (taskArgs.a < 10 || taskArgs.min > 5000) throw Error(`Invalid amplitude coefficient (A) ${taskArgs.a}`)
if (taskArgs.min < 0 || taskArgs.min > 50) throw Error(`Invalid min limit ${taskArgs.min}`)
if (taskArgs.max < 50 || taskArgs.max > 100) throw Error(`Invalid max limit ${taskArgs.min}`)

if (!fAsset.priceGetter) throw Error(`Token ${fAsset.symbol} does not have a priceGetter`)

const poolData: FeederData = {
mAsset,
fAsset,
fAssetRedemptionPriceGetter: fAsset.priceGetter,
name: `${mAsset.symbol}/${fAsset.symbol} Feeder Pool`,
symbol: `fP${mAsset.symbol}/${fAsset.symbol}`,
config: {
a: taskArgs.a,
limits: {
min: simpleToExactAmount(taskArgs.min, 16),
max: simpleToExactAmount(taskArgs.max, 16),
},
},
}

// Deploy Feeder Pool
await deployFeederPool(signer, poolData, hre)
})

task("deployAlcxInt", "Deploy Alchemix integration contract for alUSD Feeder Pool")
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
Expand All @@ -78,6 +118,9 @@ task("deployAlcxInt", "Deploy Alchemix integration contract for alUSD Feeder Poo
console.log(`migrateBassets data:\n${migrateData}`)
})

// vault:
// // hh --config tasks-fork.config.ts --network hardhat deployVault --name "mUSD/RAI fPool Vault" --symbol v-fPmUSD/RAI
// --boosted true --stakingToken mUSD --rewardToken MTA --dualRewardToken FLX --price ?
task("deployVault", "Deploy Feeder Pool with boosted dual vault")
.addParam("name", "Token name of the vault. eg mUSD/alUSD fPool Vault", undefined, types.string)
.addParam("symbol", "Token symbol of the vault. eg v-fPmUSD/alUSD", undefined, types.string)
Expand Down
18 changes: 16 additions & 2 deletions tasks/utils/feederUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { formatEther } from "ethers/lib/utils"
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime"
import {
FeederPool,
NonPeggedFeederPool,
BoostedVault,
MockERC20__factory,
MockInitializableToken__factory,
AssetProxy__factory,
MockERC20,
FeederPool__factory,
NonPeggedFeederPool__factory,
BoostedVault__factory,
Masset__factory,
BoostedDualVault,
Expand All @@ -21,6 +23,7 @@ import {
BoostedDualVault__factory,
StakingRewardsWithPlatformToken__factory,
StakingRewards__factory,
IRedemptionPriceSnap__factory,
} from "types/generated"
import { deployContract } from "./deploy-utils"
import { verifyEtherscan } from "./etherscan"
Expand All @@ -39,6 +42,7 @@ interface Config {
export interface FeederData {
mAsset: Token
fAsset: Token
fAssetRedemptionPriceGetter?: string
name: string
symbol: string
config: Config
Expand Down Expand Up @@ -85,8 +89,18 @@ export const deployFeederPool = async (signer: Signer, feederData: FeederData, h
"contracts/feeders/FeederManager.sol:FeederManager": feederManagerAddress,
}

const fpConstructorArgs = [getChainAddress("Nexus", chain), feederData.mAsset.address]
const impl = await deployContract(new FeederPool__factory(linkedAddress, signer), "FeederPool", fpConstructorArgs)
let impl: FeederPool | NonPeggedFeederPool
let fpConstructorArgs: Array<string>

if (feederData.fAssetRedemptionPriceGetter) {
// Update fAssetRedemptionPriceGetter price oracle
await IRedemptionPriceSnap__factory.connect(feederData.fAssetRedemptionPriceGetter, signer).updateSnappedPrice()
fpConstructorArgs = [getChainAddress("Nexus", chain), feederData.mAsset.address, feederData.fAssetRedemptionPriceGetter]
impl = await deployContract(new NonPeggedFeederPool__factory(linkedAddress, signer), "NonPeggedFeederPool", fpConstructorArgs)
} else {
fpConstructorArgs = [getChainAddress("Nexus", chain), feederData.mAsset.address]
impl = await deployContract(new FeederPool__factory(linkedAddress, signer), "FeederPool", fpConstructorArgs)
}

await verifyEtherscan(hre, {
address: impl.address,
Expand Down
28 changes: 28 additions & 0 deletions tasks/utils/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Token {
vault?: string
savings?: string // interest-bearing savings contracts
platformTokenVendor?: string // hold WMATIC on Polygon's v-imUSD vault
priceGetter?: string // Contract for price of asset, used for NonPeggedFeederPool
}

export function isToken(asset: unknown): asset is Token {
Expand Down Expand Up @@ -209,6 +210,31 @@ export const BUSD: Token = {
vault: "0xD124B55f70D374F58455c8AEdf308E52Cf2A6207",
}

// NonPeggedFeederPool contains priceGetter
export const RAI: Token = {
symbol: "RAI",
address: "0x03ab458634910aad20ef5f1c8ee96f1d6ac54919",
chain: Chain.mainnet,
platform: Platform.Aave,
integrator: "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to deploy an integrator and link the address here in order for it to be deposited onto AAVE.

liquidityProvider: "0xc9bc48c72154ef3e5425641a3c747242112a46af", // aRAI,
decimals: 18,
quantityFormatter: "USD",
parent: "mUSD",
feederPool: "",
vault: "",
priceGetter: "0x07210B8871073228626AB79c296d9b22238f63cE",
}

// FLX token for RAI
export const FLX: Token = {
symbol: "FLX",
address: "0x6243d8cea23066d098a15582d81a598b4e8391f4",
chain: Chain.mainnet,
decimals: 18,
quantityFormatter: "USD",
}

// USD Feeder Pool Assets on Mainnet
export const FRAX: Token = {
symbol: "FRAX",
Expand Down Expand Up @@ -452,6 +478,8 @@ export const tokens = [
DAI,
GUSD,
BUSD,
RAI,
FLX,
renBTC,
sBTC,
WBTC,
Expand Down