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

Funding rounds script #206

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
18,015 changes: 17,973 additions & 42 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions scripts/actions/FundingBonder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ const { address } = require("../utils/helpers");
const FundingBonder =
({ user, slippage }) =>
async ({ funding, amount, token }) => {
// console.log(`User balance is: ${await token.balanceOf(address(user))} \n
// amount is: ${amount}\n
// citadelPerAsset: ${await funding.connect(user).citadelPerAsset()}
// `);
await token.connect(user).approve(address(funding), amount);

await funding.connect(user).deposit(amount, slippage);
};
module.exports = FundingBonder;
127 changes: 127 additions & 0 deletions scripts/actions/addOracleProviders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
const { address } = require("../utils/helpers");

const feeds = {
CTDL_WBTC_CURVE_POOL: "0x50f3752289e1456bfa505afd37b241bca23e685d",
WBTC_BTC_PRICE_FEED: "0xfdfd9c85ad200c506cf9e21f1fd8dd01932fbb23",
BTC_ETH_PRICE_FEED: "0xdeb288f737066589598e9214e782fa5a8ed689e8",
BTC_USD_PRICE_FEED: "0xf4030086522a5beea4988f8ca5b36dbc97bee88c",
ETH_USD_PRICE_FEED: "0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419",
WIBBTC_LP_VAULT: "0xae96ff08771a109dc6650a1bdca62f2d558e40af",
FRAX_ETH_PRICE_FEED: "0x14d04fff8d21bd62987a5ce9ce543d2f1edf5d3e",
FRAX_USD_PRICE_FEED: "0xb9e1e3a9feff48998e45fa90847ed4d467e8bcfd",
USDC_ETH_PRICE_FEED: "0x986b5e1e1755e3c2440e960477f25201b0a8bbd4",
USDC_USD_PRICE_FEED: "0x8fffffd4afb6115b954bd326cbe7b4ba576818f6",
CVX_ETH_PRICE_FEED: "0xc9cbf687f43176b302f03f5e58470b77d07c61c6",
CVX_USD_PRICE_FEED: "0xd962fc30a72a84ce50161031391756bf2876af5d",
BADGER_ETH_PRICE_FEED: "0x58921ac140522867bf50b9e009599da0ca4a2379",
BADGER_USD_PRICE_FEED: "0x66a47b7206130e6ff64854ef0e1edfa237e65339",
};

const addOracleProviders = async ({
CtdlWbtcCurveV2Provider,
CtdlBtcChainlinkProvider,
CtdlWibbtcLpVaultProvider,
CtdlEthChainlinkProvider,
CtdlAssetChainlinkProvider,
initFunds,
}) => {
const ctdlWbtcCurveV2Provider = await CtdlWbtcCurveV2Provider.deploy(
feeds.CTDL_WBTC_CURVE_POOL
);

const ctdlBtcProvider = await CtdlBtcChainlinkProvider.deploy(
feeds.CTDL_WBTC_CURVE_POOL,
feeds.WBTC_BTC_PRICE_FEED
);
await initFunds[0].citadelPerAssetOracle.addProvider(
address(ctdlWbtcCurveV2Provider)
);
await initFunds[0].citadelPerAssetOracle.addProvider(
address(ctdlBtcProvider)
);
console.log(`wbtc providers added`);

await initFunds[1].citadelPerAssetOracle.addProvider(
address(ctdlWbtcCurveV2Provider)
);
await initFunds[1].citadelPerAssetOracle.addProvider(
address(ctdlBtcProvider)
);
console.log(`renbtc providers added`);

const ctdlWibbtcProvider = await CtdlWibbtcLpVaultProvider.deploy(
feeds.CTDL_WBTC_CURVE_POOL,
feeds.WBTC_BTC_PRICE_FEED,
feeds.WIBBTC_LP_VAULT
);

await initFunds[2].citadelPerAssetOracle.addProvider(
address(ctdlWibbtcProvider)
);

console.log(`ibBTC providers added`);

const ctdlEthProvider1 = await CtdlEthChainlinkProvider.deploy(
feeds.CTDL_WBTC_CURVE_POOL,
feeds.WBTC_BTC_PRICE_FEED,
feeds.BTC_ETH_PRICE_FEED
);
const ctdlEthProvider2 = await CtdlAssetChainlinkProvider.deploy(
feeds.CTDL_WBTC_CURVE_POOL,
feeds.WBTC_BTC_PRICE_FEED,
feeds.BTC_ETH_PRICE_FEED,
feeds.ETH_USD_PRICE_FEED
);
await initFunds[3].citadelPerAssetOracle.addProvider(
address(ctdlEthProvider1)
);
await initFunds[3].citadelPerAssetOracle.addProvider(
address(ctdlEthProvider2)
);

const assetETHFeeds = [
feeds.FRAX_ETH_PRICE_FEED,
feeds.USDC_ETH_PRICE_FEED,
feeds.BADGER_ETH_PRICE_FEED,
feeds.CVX_ETH_PRICE_FEED,
feeds.CVX_ETH_PRICE_FEED,
];

const assetUsdFeeds = [
feeds.FRAX_USD_PRICE_FEED,
feeds.USDC_USD_PRICE_FEED,
feeds.BADGER_USD_PRICE_FEED,
feeds.CVX_USD_PRICE_FEED,
feeds.CVX_USD_PRICE_FEED,
];

const setProvider = async (i = 0) => {
if (!assetETHFeeds[i]) return;
const ctdlAssetProvider1 = await CtdlAssetChainlinkProvider.deploy(
feeds.CTDL_WBTC_CURVE_POOL,
feeds.WBTC_BTC_PRICE_FEED,
feeds.BTC_ETH_PRICE_FEED,
assetUsdFeeds[i]
);

const ctdlAssetProvider2 = await CtdlAssetChainlinkProvider.deploy(
feeds.CTDL_WBTC_CURVE_POOL,
feeds.WBTC_BTC_PRICE_FEED,
feeds.BTC_USD_PRICE_FEED,
assetETHFeeds[i]
);

await initFunds[4 + i].citadelPerAssetOracle.addProvider(
address(ctdlAssetProvider1)
);
await initFunds[4 + i].citadelPerAssetOracle.addProvider(
address(ctdlAssetProvider2)
);

return await setProvider(i + 1);
};

await setProvider();
};

module.exports = addOracleProviders;
23 changes: 0 additions & 23 deletions scripts/actions/approveFundingTokens.js

This file was deleted.

91 changes: 79 additions & 12 deletions scripts/actions/bondTokenForXCTDL.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ const { formatUnits, parseUnits } = ethers.utils;

const FundingBonder = require("./FundingBonder");

const { getTokensPrices } = require("../utils/getTokensPrice");

const feeds = {
CTDL_WBTC_CURVE_POOL: "0x50f3752289e1456bfa505afd37b241bca23e685d",
WBTC_BTC_PRICE_FEED: "0xfdfd9c85ad200c506cf9e21f1fd8dd01932fbb23",
BTC_ETH_PRICE_FEED: "0xdeb288f737066589598e9214e782fa5a8ed689e8",
BTC_USD_PRICE_FEED: "0xf4030086522a5beea4988f8ca5b36dbc97bee88c",
ETH_USD_PRICE_FEED: "0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419",
WIBBTC_LP_VAULT: "0xae96ff08771a109dc6650a1bdca62f2d558e40af",
FRAX_ETH_PRICE_FEED: "0x14d04fff8d21bd62987a5ce9ce543d2f1edf5d3e",
FRAX_USD_PRICE_FEED: "0xb9e1e3a9feff48998e45fa90847ed4d467e8bcfd",
USDC_ETH_PRICE_FEED: "0x986b5e1e1755e3c2440e960477f25201b0a8bbd4",
USDC_USD_PRICE_FEED: "0x8fffffd4afb6115b954bd326cbe7b4ba576818f6",
CVX_ETH_PRICE_FEED: "0xc9cbf687f43176b302f03f5e58470b77d07c61c6",
CVX_USD_PRICE_FEED: "0xd962fc30a72a84ce50161031391756bf2876af5d",
BADGER_ETH_PRICE_FEED: "0x58921ac140522867bf50b9e009599da0ca4a2379",
BADGER_USD_PRICE_FEED: "0x66a47b7206130e6ff64854ef0e1edfa237e65339",
};

const bondTokenForXCTDL = async ({
fundingWbtc,
fundingCvx,
Expand All @@ -15,26 +34,74 @@ const bondTokenForXCTDL = async ({
cvx,
apeCvxAmount,
apeWbtcAmount,
apeGeneral,
fundingRegistry,
Funding,
ERC20Upgradeable,
keeper,
MedianOracle,
tokenIns,
}) => {
// bond some WBTC and CVX to get xCTDL

const fundingBonder = FundingBonder({ user, slippage: 0 });

await fundingBonder({
funding: fundingWbtc,
amount: apeWbtcAmount,
token: wbtc,
});
const fundingsList = await fundingRegistry.getAllFundings();

const targetProvider = "0xA967Ba66Fb284EC18bbe59f65bcf42dD11BA8128";

const provider = await ethers.getSigner(targetProvider);

const allFundingsBonder = async (i = 0) => {
const currentFunding = fundingsList[i]
? Funding.attach(fundingsList[i])
: undefined;
if (!currentFunding) return;

const asset = ERC20Upgradeable.attach(await currentFunding.asset());

const tokensPrices = await getTokensPrices(
tokenIns.map((token) => token.priceAddress)
);
const targetPrice = 21;

const assetAddress = await currentFunding.asset();

const initFundPriceAsset = tokenIns.find(
(tI) => tI.address.toLowerCase() === assetAddress.toLowerCase()
).priceAddress;

const priceToReport = parseUnits(
String(tokensPrices[initFundPriceAsset].usd / targetPrice),
18
);

const oracleAddress = await currentFunding.citadelPerAssetOracle();

const currentOracle = await MedianOracle.attach(oracleAddress);

await currentOracle.connect(provider).pushReport(priceToReport);

// console.log("Oracle Address: ", currentOracle.address);
// console.log(await currentOracle.callStatic.getData());

await currentFunding.connect(keeper).updateCitadelPerAsset();

//console.log("?????");

await fundingBonder({
funding: currentFunding,
amount: apeGeneral,
token: asset,
});

return await allFundingsBonder(i + 1);
};

await fundingBonder({
funding: fundingCvx,
amount: apeCvxAmount,
token: cvx,
});
await allFundingsBonder();

// user should be getting ~200 xCTDL
console.log(
`balance of xCTDL after two deposits: ${formatUnits(
`balance of xCTDL after deposits: ${formatUnits(
await xCitadel.balanceOf(address(user)),
18
)}`
Expand Down
44 changes: 27 additions & 17 deletions scripts/actions/citadelMinterSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ const citadelMinterSetup = async ({
schedule,
citadelMinter,
policyOps,
fundingWbtc,
fundingCvx,
citadel,
fundingRegistry,
Funding,
}) => {
const blockNumBefore = await ethers.provider.getBlockNumber();
const blockBefore = await ethers.provider.getBlock(blockNumBefore);
const scheduleStartTime = blockBefore.timestamp + 6;
await schedule.connect(governance).setMintingStart(scheduleStartTime);

// control the time to fast forward
const depositTokenTime = scheduleStartTime + 1 * 86400;
const depositTokenTime = scheduleStartTime + 1 * 20 * 86400;
await changeBlockTimestamp(depositTokenTime);

// set distribution split
Expand All @@ -28,24 +28,34 @@ const citadelMinterSetup = async ({
.setCitadelDistributionSplit(4000, 3000, 2000, 1000);

// set funding pool rate
await citadelMinter
.connect(policyOps)
.setFundingPoolWeight(address(fundingWbtc), 5000);
await citadelMinter
.connect(policyOps)
.setFundingPoolWeight(address(fundingCvx), 5000);
const fundingsList = await fundingRegistry.getAllFundings();

const setAllPoolWieght = async (i = 0) => {
const currentFunding = fundingsList[i]
? Funding.attach(fundingsList[i])
: undefined;
if (!currentFunding) return;

console.log(
"setting up minter funding pool weight: ",
currentFunding.address
);

await citadelMinter
.connect(policyOps)
.setFundingPoolWeight(address(currentFunding), 5000);

return await setAllPoolWieght(i + 1);
};

await setAllPoolWieght();

// mint and distribute xCTDL to the staking contract
await citadelMinter.connect(policyOps).mintAndDistribute();

console.log(
`supply of CTDL in WBTC Funding pool: ${formatUnits(
await citadel.balanceOf(address(fundingWbtc)),
18
)}`
);
console.log(
`supply of CTDL in CVX Funding pool: ${formatUnits(
await citadel.balanceOf(address(fundingCvx)),
`supply of CTDL in each funding pool: ${formatUnits(
await citadel.balanceOf(fundingsList[0]),
18
)}`
);
Expand Down
Loading