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

Commit ede0028

Browse files
committed
Add script for ION reward on bsdETH and hyUSD
1 parent f833f6c commit ede0028

File tree

1 file changed

+99
-90
lines changed

1 file changed

+99
-90
lines changed

tasks/chain-specific/base/rewards.ts

Lines changed: 99 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
import { task } from "hardhat/config";
1+
import { task, types } from "hardhat/config";
22
import { Address, parseEther, zeroAddress } from "viem";
33

4-
task("market:base:add-rewards-to-existing-flywheel", "Sets caps on a market").setAction(
5-
async (_, { viem, run, deployments, getNamedAccounts }) => {
4+
task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing flywheel")
5+
.addParam("market", "address of flywheel", undefined, types.string)
6+
.addParam("rewardAmount", "address of comptroller", undefined, types.string)
7+
.addParam("reward", "address of comptroller", undefined, types.string)
8+
.setAction(
9+
async ({market, rewardAmount, reward}, { viem, run, deployments, getNamedAccounts }) => {
610
const { deployer } = await getNamedAccounts();
711
const publicClient = await viem.getPublicClient();
8-
9-
const ionbsdETH = "0x3d9669de9e3e98db41a1cbf6dc23446109945e3c";
10-
const bsdETH = "0xCb327b99fF831bF8223cCEd12B1338FF3aA322Ff";
11-
const ioneUSD = "0x9c2a4f9c5471fd36be3bbd8437a33935107215a1";
12-
const eUSD = "0xCfA3Ef56d303AE4fAabA0592388F19d7C3399FB4";
13-
const hyUSD = "0xCc7FF230365bD730eE4B352cC2492CEdAC49383e"
14-
const ionhyUSD = "0x751911bDa88eFcF412326ABE649B7A3b28c4dEDe"
15-
const ION = "0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5";
16-
const RSR = "0xab36452dbac151be02b16ca17d8919826072f64a";
17-
const pool = "0x05c9C6417F246600f8f5f49fcA9Ee991bfF73D13";
18-
const comptrollerAddress = "0x05c9C6417F246600f8f5f49fcA9Ee991bfF73D13";
19-
const markets = `${ionbsdETH}`;
20-
const reward = "2500"; // epoch will start 3 days so 25000 / 30 * 3
21-
2212
/*
2313
// Upgrade markets to the new implementation
2414
console.log(`Upgrading market: ${ionhyUSD} to CErc20RewardsDelegate`);
@@ -73,10 +63,10 @@ task("market:base:add-rewards-to-existing-flywheel", "Sets caps on a market").se
7363
*/
7464

7565
// Sending tokens
76-
const ionToken = await viem.getContractAt("EIP20Interface", ION);
77-
const balance = await ionToken.read.balanceOf([ionbsdETH]);
78-
if (balance < parseEther(reward)) {
79-
await ionToken.write.transfer([ionbsdETH, parseEther(reward)]);
66+
const ionToken = await viem.getContractAt("EIP20Interface", reward);
67+
const balance = await ionToken.read.balanceOf([market]);
68+
if (balance < parseEther(rewardAmount)) {
69+
await ionToken.write.transfer([market, parseEther(rewardAmount)]);
8070
}
8171

8272
// Approving token sepening for fwRewards contract
@@ -85,48 +75,36 @@ task("market:base:add-rewards-to-existing-flywheel", "Sets caps on a market").se
8575
(await deployments.get("IonicFlywheel_ION")).address as Address
8676
);
8777

88-
const marketAddresses = markets.split(",");
89-
for (const marketAddress of marketAddresses) {
90-
const market = await viem.getContractAt("CErc20RewardsDelegate", marketAddress);
91-
const fwRewards = await flywheel.read.flywheelRewards();
92-
const rewardToken = await flywheel.read.rewardToken();
93-
const tx = await market.write.approve([rewardToken, fwRewards]);
94-
console.log(`mining tx ${tx}`);
95-
await publicClient.waitForTransactionReceipt({ hash: tx });
96-
console.log(`approved flywheel ${flywheel.address} to pull reward tokens from market ${marketAddress}`);
97-
}
78+
const _market = await viem.getContractAt("CErc20RewardsDelegate", market);
79+
const fwRewards = await flywheel.read.flywheelRewards();
80+
const rewardToken = await flywheel.read.rewardToken();
81+
const tx = await _market.write.approve([rewardToken, fwRewards]);
82+
console.log(`mining tx ${tx}`);
83+
await publicClient.waitForTransactionReceipt({ hash: tx });
84+
console.log(`approved flywheel ${flywheel.address} to pull reward tokens from market ${market}`);
9885

9986
// Adding strategies to flywheel
10087
const allFlywheelStrategies = (await flywheel.read.getAllStrategies()) as Address[];
101-
for (const strategy of marketAddresses) {
102-
if (!allFlywheelStrategies.map((s) => s.toLowerCase()).includes(strategy.toLowerCase())) {
103-
console.log(`Adding strategy ${strategy} to flywheel ${flywheel.address}`);
104-
const addTx = await flywheel.write.addStrategyForRewards([strategy]);
105-
await publicClient.waitForTransactionReceipt({ hash: addTx });
106-
console.log(`Added strategy (${strategy}) to flywheel (${flywheel.address})`);
107-
} else console.log(`Strategy (${strategy}) was already added to flywheel (${flywheel.address})`);
108-
}
88+
if (!allFlywheelStrategies.map((s) => s.toLowerCase()).includes(market.toLowerCase())) {
89+
console.log(`Adding strategy ${market} to flywheel ${flywheel.address}`);
90+
const addTx = await flywheel.write.addStrategyForRewards([market]);
91+
await publicClient.waitForTransactionReceipt({ hash: addTx });
92+
console.log(`Added strategy (${market}) to flywheel (${flywheel.address})`);
93+
} else console.log(`Strategy (${market}) was already added to flywheel (${flywheel.address})`);
10994
}
11095
);
11196

112-
task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").setAction(
113-
async (_, { viem, run, deployments, getNamedAccounts }) => {
97+
task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
98+
.addParam("market", "address of flywheel", undefined, types.string)
99+
.addParam("rewardAmount", "address of comptroller", undefined, types.string)
100+
.addParam("reward", "address of comptroller", undefined, types.string)
101+
.addParam("epochDuration", "address of comptroller", undefined, types.string)
102+
.addParam("name", "address of comptroller", undefined, types.string)
103+
.setAction(
104+
async ({market, rewardAmount, reward, epochDuration, name}, { viem, run, deployments, getNamedAccounts }) => {
114105
const { deployer } = await getNamedAccounts();
115106
const publicClient = await viem.getPublicClient();
116107

117-
const ionbsdETH = "0x3d9669de9e3e98db41a1cbf6dc23446109945e3c";
118-
const bsdETH = "0xCb327b99fF831bF8223cCEd12B1338FF3aA322Ff";
119-
const ioneUSD = "0x9c2a4f9c5471fd36be3bbd8437a33935107215a1";
120-
const eUSD = "0xCfA3Ef56d303AE4fAabA0592388F19d7C3399FB4";
121-
const hyUSD = "0xCc7FF230365bD730eE4B352cC2492CEdAC49383e"
122-
const ionhyUSD = "0x751911bDa88eFcF412326ABE649B7A3b28c4dEDe"
123-
const ION = "0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5";
124-
const RSR = "0xab36452dbac151be02b16ca17d8919826072f64a";
125-
const pool = "0x05c9C6417F246600f8f5f49fcA9Ee991bfF73D13";
126-
const comptrollerAddress = "0x05c9C6417F246600f8f5f49fcA9Ee991bfF73D13";
127-
const markets = `${ionhyUSD}`;
128-
const reward = "1500"; // epoch will start 3 days so 15000 / 30 * 3
129-
130108
/*
131109
// Upgrade markets to the new implementation
132110
console.log(`Upgrading market: ${ionhyUSD} to CErc20RewardsDelegate`);
@@ -181,27 +159,29 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").set
181159
*/
182160

183161
// Sending tokens
184-
const ionToken = await viem.getContractAt("EIP20Interface", ION);
185-
const balance = await ionToken.read.balanceOf([ionhyUSD]);
186-
if (balance < parseEther(reward)) {
187-
await ionToken.write.transfer([ionhyUSD, parseEther(reward)]);
162+
const ionToken = await viem.getContractAt("EIP20Interface", reward);
163+
const balance = await ionToken.read.balanceOf([market]);
164+
if (balance < parseEther(rewardAmount)) {
165+
await ionToken.write.transfer([market, parseEther(rewardAmount)]);
188166
}
189167

190168
// Deploying flywheel
191-
let name = "ION";
192169
let booster = "";
193-
let rewardToken = ION;
194-
let epochDuration = 2588400; //30*(24*60*60)-60*60 29days 23 hours
195170
let flywheelBoosterAddress;
196171
let contractName;
197-
172+
const pool = "0x05c9C6417F246600f8f5f49fcA9Ee991bfF73D13";
173+
if (name.includes("Borrow")) {
174+
contractName = "IonicFlywheelBorrow";
175+
booster = "0x0e47b0fF7b5571047bb1A8b18C9444D25516e7F9";
176+
} else {
177+
contractName = "IonicFlywheel";
178+
}
179+
198180
if (booster != "") {
199181
flywheelBoosterAddress = (await deployments.get(booster)).address as Address;
200182
} else flywheelBoosterAddress = zeroAddress;
201183

202-
if (name.includes("Borrow")) {
203-
contractName = "IonicFlywheelBorrow";
204-
} else contractName = "IonicFlywheel";
184+
205185

206186
const _flywheel = await deployments.deploy(`${contractName}_${name}`, {
207187
contract: contractName,
@@ -212,7 +192,7 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").set
212192
execute: {
213193
init: {
214194
methodName: "initialize",
215-
args: [rewardToken, zeroAddress, flywheelBoosterAddress, deployer]
195+
args: [reward, zeroAddress, flywheelBoosterAddress, deployer]
216196
}
217197
},
218198
owner: deployer
@@ -223,7 +203,7 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").set
223203
console.log(`Deployed flywheel: ${_flywheel.address}`);
224204

225205
// Deploying flywheel rewards
226-
const rewards = await deployments.deploy(`IonicFlywheelDynamicRewards_${name}`, {
206+
const flywheelRewards = await deployments.deploy(`IonicFlywheelDynamicRewards_${name}`, {
227207
contract: "IonicFlywheelDynamicRewards",
228208
from: deployer,
229209
log: true,
@@ -240,22 +220,18 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").set
240220
(await deployments.get(`${contractName}_${name}`)).address as Address
241221
);
242222

243-
const tx = await flywheel.write.setFlywheelRewards([rewards.address as Address]);
244-
await publicClient.waitForTransactionReceipt({ hash: tx });
245-
console.log(`Set rewards (${rewards.address}) to flywheel (${flywheel.address})`);
223+
const txFlywheel = await flywheel.write.setFlywheelRewards([flywheelRewards.address as Address]);
224+
await publicClient.waitForTransactionReceipt({ hash: txFlywheel });
225+
console.log(`Set rewards (${flywheelRewards.address}) to flywheel (${flywheel.address})`);
246226

247227
// Adding strategies to flywheel
248-
const marketAddresses = markets.split(",");
249228
const allFlywheelStrategies = (await flywheel.read.getAllStrategies()) as Address[];
250-
for (const strategy of marketAddresses) {
251-
if (!allFlywheelStrategies.map((s) => s.toLowerCase()).includes(strategy.toLowerCase())) {
252-
console.log(`Adding strategy ${strategy} to flywheel ${flywheel.address}`);
253-
const addTx = await flywheel.write.addStrategyForRewards([strategy]);
254-
await publicClient.waitForTransactionReceipt({ hash: addTx });
255-
256-
console.log(`Added strategy (${strategy}) to flywheel (${flywheel.address})`);
257-
} else console.log(`Strategy (${strategy}) was already added to flywheel (${flywheel.address})`);
258-
}
229+
if (!allFlywheelStrategies.map((s) => s.toLowerCase()).includes(market.toLowerCase())) {
230+
console.log(`Adding strategy ${market} to flywheel ${flywheel.address}`);
231+
const addTx = await flywheel.write.addStrategyForRewards([market]);
232+
await publicClient.waitForTransactionReceipt({ hash: addTx });
233+
console.log(`Added strategy (${market}) to flywheel (${flywheel.address})`);
234+
} else console.log(`Strategy (${market}) was already added to flywheel (${flywheel.address})`);
259235

260236
// Adding flywheel to comptroller
261237
const comptroller = await viem.getContractAt("IonicComptroller", pool);
@@ -270,14 +246,47 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").set
270246
console.log(`Added flywheel (${flywheel.address}) to pool (${pool})`);
271247

272248
// Approving token sepening for fwRewards contract
273-
for (const marketAddress of marketAddresses) {
274-
const market = await viem.getContractAt("CErc20RewardsDelegate", marketAddress);
275-
const fwRewards = await flywheel.read.flywheelRewards();
276-
const rewardToken = await flywheel.read.rewardToken();
277-
const tx = await market.write.approve([rewardToken, fwRewards]);
278-
console.log(`mining tx ${tx}`);
279-
await publicClient.waitForTransactionReceipt({ hash: tx });
280-
console.log(`approved flywheel ${flywheel.address} to pull reward tokens from market ${marketAddress}`);
281-
}
249+
const _market = await viem.getContractAt("CErc20RewardsDelegate", market);
250+
const fwRewards = await flywheel.read.flywheelRewards();
251+
const rewardToken = await flywheel.read.rewardToken();
252+
const tx = await _market.write.approve([rewardToken, fwRewards]);
253+
console.log(`mining tx ${tx}`);
254+
await publicClient.waitForTransactionReceipt({ hash: tx });
255+
console.log(`approved flywheel ${flywheel.address} to pull reward tokens from market ${market}`);
282256
}
283-
);
257+
);
258+
259+
task("market:base:add-flywheel-ION-rewards-to-ionbsdETH", "Adds rewards to existing flywheel")
260+
.setAction(
261+
async (_, { viem, run, deployments, getNamedAccounts }) => {
262+
const markets = "0x3d9669de9e3e98db41a1cbf6dc23446109945e3c"; // ionbsdETH
263+
const rewardAmount = "2500"; // epoch will start 3 days so 25000 / 30 * 3
264+
const ion = "0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5";
265+
await run("market:base:add-rewards-to-existing-flywheel",
266+
{
267+
markets: markets,
268+
rewardAmount: rewardAmount,
269+
reward : ion
270+
}
271+
);
272+
});
273+
274+
task("market:base:deploy-flywheel-and-add-ION-rewards-to-ionhyUSD", "Adds rewards to existing flywheel")
275+
.setAction(
276+
async (_, { viem, run, deployments, getNamedAccounts }) => {
277+
const markets = "0x751911bDa88eFcF412326ABE649B7A3b28c4dEDe"; // ionhyUSD
278+
const rewardAmount = "1500"; // epoch will start 3 days so 15000 / 30 * 3
279+
const ion = "0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5";
280+
const name = "ION"; // For borrow flywheel use Borrow_ION for supply flywheel just ION
281+
// NOTE: Make sure that epoch duration for supply and borrow are not the same
282+
const epochDuration = 2588400; // 30*(24*60*60)-60*60 29days 23 hours
283+
await run("market:base:deploy-flywheel-and-add-rewards",
284+
{
285+
markets: markets,
286+
rewardAmount: rewardAmount,
287+
reward : ion,
288+
epochDuration : epochDuration,
289+
name : name
290+
}
291+
);
292+
});

0 commit comments

Comments
 (0)