Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit 6b1a16c

Browse files
committed
Add flywheel deploy script
1 parent 1a6156c commit 6b1a16c

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

deploy/18-deploy-ionic-flywheel.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { DeployFunction } from "hardhat-deploy/types";
2+
import { Address } from "viem";
3+
4+
const func: DeployFunction = async ({ run, viem, getNamedAccounts, deployments }) => {
5+
const publicClient = await viem.getPublicClient();
6+
7+
const { deployer } = await getNamedAccounts();
8+
9+
const fpd = await viem.getContractAt("PoolDirectory", (await deployments.get("PoolDirectory")).address as Address);
10+
11+
// NOTE: not all markets should be approved, so we hardcode market for which flywheel is deployed
12+
//const comptroller = await viem.getContractAt("Comptroller", (await deployments.get("Comptroller")).address as Address);
13+
//const markets = await comptroller.read.getAllMarkets();
14+
const markets = "MARKET1_ADDRESS,MARKET2_ADDRESS..."
15+
16+
// NOTE: change name and reward token
17+
await run("flywheel:deploy-dynamic-rewards-fw", { name: "RSR", rewardToken: "RSR_TOKEN_ADDRESS", booster: "", strategies: markets, pool: fpd.address });
18+
19+
const flywheel = await viem.getContractAt("IonicFlywheel", (await deployments.get("IonicFlywheel")).address as Address);
20+
await run("approve-market-flywheel", { fwAddress: flywheel.address, markets: markets });
21+
22+
const tx = await flywheel.write.updateFeeSettings([0, deployer.address]);
23+
await publicClient.waitForTransactionReceipt({ hash: tx });
24+
25+
const booster = await run("flywheel:deploy-borrow-booster", { name: "Booster" });
26+
27+
// NOTE: change name and reward token
28+
await run("flywheel:deploy-dynamic-rewards-fw", { name: "Borrow_RSR", rewardToken: "RSR_TOKEN_ADDRESS", booster: booster.address, strategies: markets, pool: fpd.address });
29+
30+
const flywheelBorrow = await viem.getContractAt("IonicFlywheelBorrow", (await deployments.get("IonicFlywheelBorrow")).address as Address);
31+
await run("approve-market-flywheel", { fwAddress: flywheelBorrow.address, markets: markets });
32+
33+
const txBorrow = await flywheelBorrow.write.updateFeeSettings([0, deployer.address]);
34+
await publicClient.waitForTransactionReceipt({ hash: txBorrow });
35+
};
36+
37+
func.tags = ["prod", "deploy-ionic-flywheel"];
38+
39+
export default func;

tasks/flywheel/deploy.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,101 @@ task("flywheel:add-to-pool", "Create pool if does not exist")
128128
await publicClient.waitForTransactionReceipt({ hash: addTx });
129129
console.log({ addTx });
130130
});
131+
132+
task("flywheel:deploy-dynamic-rewards-fw", "Deploy dynamic rewards flywheel for LM rewards")
133+
.addParam("name", "String to append to the flywheel contract name", undefined, types.string)
134+
.addParam("rewardToken", "Reward token of flywheel", undefined, types.string)
135+
.addParam("booster", "Kind of booster flywheel to use", "IonicFlywheelBorrowBooster", undefined, types.string)
136+
.addParam("strategies", "address of strategy for which to enable the flywheel", undefined, types.string)
137+
.addParam("pool", "comptroller to which to add the flywheel", undefined, types.string)
138+
.setAction(
139+
async ({ signer, name, rewardToken, strategies, pool, booster }, { viem, deployments, run, getNamedAccounts }) => {
140+
const { deployer } = await getNamedAccounts();
141+
const publicClient = await viem.getPublicClient();
142+
let flywheelBooster;
143+
let contractName;
144+
if (booster != "") {
145+
flywheelBooster = await viem.getContractAt(booster, (await deployments.get(booster)).address as Address);
146+
}
147+
else flywheelBooster = zeroAddress;
148+
149+
if (name.includes("Borrow")) {
150+
contractName = "IonicFlywheelBorrow";
151+
}
152+
else contractName = "IonicFlywheel"
153+
154+
console.log({ signer, name, rewardToken, booster, strategies, pool });
155+
const flywheel = await deployments.deploy(`${contractName}_${name}`, {
156+
contract: contractName,
157+
from: deployer,
158+
log: true,
159+
proxy: {
160+
proxyContract: "OpenZeppelinTransparentProxy",
161+
execute: {
162+
init: {
163+
methodName: "initialize",
164+
args: [rewardToken, zeroAddress, flywheelBooster, deployer]
165+
}
166+
},
167+
owner: deployer
168+
},
169+
waitConfirmations: 1
170+
});
171+
172+
console.log(`Deployed flywheel: ${flywheel.address}`);
173+
const rewards = await run("flywheel:deploy-dynamic-rewards", { name: name, flywheel: flywheel.address });
174+
console.log(`Deployed rewards: ${rewards.address}`);
175+
const _flywheel = await viem.getContractAt(`${contractName}`, flywheel.address as Address);
176+
const tx = await _flywheel.write.setFlywheelRewards([rewards.address]);
177+
await publicClient.waitForTransactionReceipt({ hash: tx });
178+
179+
console.log(`Set rewards (${rewards.address}) to flywheel (${flywheel.address})`);
180+
const strategyAddresses = strategies.split(",");
181+
for (const strategy of strategyAddresses) {
182+
console.log(`Adding strategy ${strategy} to flywheel ${flywheel.address}`);
183+
await run("flywheel:add-strategy-for-rewards", { flywheel: flywheel.address, strategy });
184+
console.log(`Added strategy (${strategy}) to flywheel (${flywheel.address})`);
185+
}
186+
await run("flywheel:add-to-pool", { flywheel: flywheel.address, pool });
187+
console.log(`Added flywheel (${flywheel.address}) to pool (${pool})`);
188+
}
189+
);
190+
191+
task("flywheel:deploy-dynamic-rewards", "Deploy dynamic rewards flywheel for LM rewards")
192+
.addParam("name", "String to append to the flywheel contract name", undefined, types.string)
193+
.addParam("flywheel", "flywheel to which to add the rewards contract", undefined, types.string)
194+
.setAction(async ({ name, flywheel }, { deployments, getNamedAccounts }) => {
195+
const { deployer } = await getNamedAccounts();
196+
const rewards = await deployments.deploy(`IonicFlywheelDynamicRewards_${name}`, {
197+
contract: "IonicFlywheelDynamicRewards",
198+
from: deployer,
199+
log: true,
200+
args: [
201+
flywheel, // flywheel
202+
2592000 // owner
203+
],
204+
waitConfirmations: 1
205+
});
206+
207+
const ionicSdkModule = await import("../ionicSdk");
208+
const sdk = await ionicSdkModule.getOrCreateIonic(deployer);
209+
210+
const tx = await sdk.setFlywheelRewards(flywheel, rewards.address);
211+
await tx.wait();
212+
return rewards;
213+
});
214+
215+
task("flywheel:deploy-borrow-booster", "Deploy flywheel borrow bosster for LM rewards")
216+
.addParam("name", "String to append to the flywheel contract name", undefined, types.string)
217+
.setAction(async ({ name, flywheel }, { deployments, getNamedAccounts }) => {
218+
const { deployer } = await getNamedAccounts();
219+
const booster = await deployments.deploy(`IonicFlywheelBorrowBooster_${name}`, {
220+
contract: "IonicFlywheelBorrowBooster",
221+
from: deployer,
222+
log: true,
223+
args: [],
224+
waitConfirmations: 1
225+
});
226+
227+
return booster;
228+
});

0 commit comments

Comments
 (0)