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

Commit 1062af4

Browse files
committed
fix upgrade market script
1 parent 6e213a0 commit 1062af4

File tree

1 file changed

+46
-70
lines changed

1 file changed

+46
-70
lines changed

tasks/chain-specific/base/rewards.ts

Lines changed: 46 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,10 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
1010
.setAction(async ({ market, rewardAmount, reward, name }, { viem, run, deployments, getNamedAccounts }) => {
1111
const { deployer } = await getNamedAccounts();
1212
const publicClient = await viem.getPublicClient();
13-
/*
14-
// Upgrade markets to the new implementation
15-
console.log(`Upgrading market: ${ionhyUSD} to CErc20RewardsDelegate`);
16-
await run("market:upgrade", {
17-
comptroller,
18-
underlying: hyUSD,
19-
implementationAddress: (await deployments.get("CErc20RewardsDelegate")).address,
20-
signer: deployer
21-
});
22-
23-
const publicClient = await viem.getPublicClient();
24-
const { implementationAddress, comptroller: comptrollerAddress, underlying, signer: namedSigner } = taskArgs;
2513

26-
const comptroller = await viem.getContractAt("IonicComptroller", comptrollerAddress as Address);
14+
// Upgrade markets to the new implementation
15+
console.log(`Upgrading market: ${market} to CErc20RewardsDelegate`);
16+
const comptroller = await viem.getContractAt("IonicComptroller", COMPTROLLER);
2717

2818
const allMarkets = await comptroller.read.getAllMarkets();
2919

@@ -36,12 +26,12 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
3626
let cTokenInstance;
3727
for (let index = 0; index < cTokenInstances.length; index++) {
3828
const thisUnderlying = await cTokenInstances[index].read.underlying();
39-
if (!cTokenInstance && thisUnderlying.toLowerCase() === hyUSD.toLowerCase()) {
29+
if (!cTokenInstance && thisUnderlying.toLowerCase() === market.toLowerCase()) {
4030
cTokenInstance = cTokenInstances[index];
4131
}
4232
}
4333
if (!cTokenInstance) {
44-
throw Error(`No market corresponds to this underlying: ${hyUSD}`);
34+
throw Error(`No market corresponds to this underlying: ${market}`);
4535
}
4636

4737
const implementationData = "0x";
@@ -61,13 +51,12 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
6151
console.log(
6252
`Implementation successfully set to ${implementationAddress}: ${setImplementationTx}`
6353
);
64-
*/
65-
54+
6655
// Sending tokens
6756
const ionToken = await viem.getContractAt("EIP20Interface", reward);
6857
const balance = await ionToken.read.balanceOf([market]);
6958
if (balance < parseEther(rewardAmount)) {
70-
await ionToken.write.transfer([market, parseEther(rewardAmount)]);
59+
await ionToken.write.transfer([market, parseEther(rewardAmount) - balance]);
7160
}
7261

7362
let contractName;
@@ -99,7 +88,7 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
9988
await publicClient.waitForTransactionReceipt({ hash: addTx });
10089
console.log(`Added strategy (${market}) to flywheel (${flywheel.address})`);
10190
} else console.log(`Strategy (${market}) was already added to flywheel (${flywheel.address})`);
102-
});
91+
});
10392

10493
task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
10594
.addParam("market", "market address", undefined, types.string)
@@ -112,66 +101,54 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
112101
const { deployer } = await getNamedAccounts();
113102
const publicClient = await viem.getPublicClient();
114103

115-
/*
116-
// Upgrade markets to the new implementation
117-
console.log(`Upgrading market: ${ionhyUSD} to CErc20RewardsDelegate`);
118-
await run("market:upgrade", {
119-
comptroller,
120-
underlying: hyUSD,
121-
implementationAddress: (await deployments.get("CErc20RewardsDelegate")).address,
122-
signer: deployer
123-
});
104+
const comptroller = await viem.getContractAt("IonicComptroller", COMPTROLLER);
124105

125-
const publicClient = await viem.getPublicClient();
126-
const { implementationAddress, comptroller: comptrollerAddress, underlying, signer: namedSigner } = taskArgs;
106+
// Upgrade markets to the new implementation
107+
console.log(`Upgrading market: ${market} to CErc20RewardsDelegate`);
108+
const allMarkets = await comptroller.read.getAllMarkets();
127109

128-
const comptroller = await viem.getContractAt("IonicComptroller", comptrollerAddress as Address);
110+
const cTokenInstances = await Promise.all(
111+
allMarkets.map(async (marketAddress) => {
112+
return await viem.getContractAt("ICErc20PluginRewards", marketAddress);
113+
})
114+
);
129115

130-
const allMarkets = await comptroller.read.getAllMarkets();
116+
let cTokenInstance;
117+
for (let index = 0; index < cTokenInstances.length; index++) {
118+
const thisUnderlying = await cTokenInstances[index].read.underlying();
119+
if (!cTokenInstance && thisUnderlying.toLowerCase() === market.toLowerCase()) {
120+
cTokenInstance = cTokenInstances[index];
121+
}
122+
}
123+
if (!cTokenInstance) {
124+
throw Error(`No market corresponds to this underlying: ${market}`);
125+
}
131126

132-
const cTokenInstances = await Promise.all(
133-
allMarkets.map(async (marketAddress) => {
134-
return await viem.getContractAt("ICErc20PluginRewards", marketAddress);
135-
})
136-
);
127+
const implementationData = "0x";
128+
const implementationAddress = (await deployments.get("CErc20RewardsDelegate")).address;
129+
console.log(`Setting implementation to ${implementationAddress}`);
130+
const setImplementationTx = await cTokenInstance.write._setImplementationSafe([
131+
implementationAddress,
132+
implementationData
133+
]);
137134

138-
let cTokenInstance;
139-
for (let index = 0; index < cTokenInstances.length; index++) {
140-
const thisUnderlying = await cTokenInstances[index].read.underlying();
141-
if (!cTokenInstance && thisUnderlying.toLowerCase() === hyUSD.toLowerCase()) {
142-
cTokenInstance = cTokenInstances[index];
135+
const receipt = await publicClient.waitForTransactionReceipt({
136+
hash: setImplementationTx
137+
});
138+
if (receipt.status !== "success") {
139+
throw `Failed set implementation to ${implementationAddress}`;
143140
}
144-
}
145-
if (!cTokenInstance) {
146-
throw Error(`No market corresponds to this underlying: ${hyUSD}`);
147-
}
148-
149-
const implementationData = "0x";
150-
const implementationAddress = (await deployments.get("CErc20RewardsDelegate")).address;
151-
console.log(`Setting implementation to ${implementationAddress}`);
152-
const setImplementationTx = await cTokenInstance.write._setImplementationSafe([
153-
implementationAddress,
154-
implementationData
155-
]);
141+
console.log(
142+
`Implementation successfully set to ${implementationAddress}: ${setImplementationTx}`
143+
);
156144

157-
const receipt = await publicClient.waitForTransactionReceipt({
158-
hash: setImplementationTx
159-
});
160-
if (receipt.status !== "success") {
161-
throw `Failed set implementation to ${implementationAddress}`;
162-
}
163-
console.log(
164-
`Implementation successfully set to ${implementationAddress}: ${setImplementationTx}`
165-
);
166-
*/
167-
/*
168145
// Sending tokens
169146
const ionToken = await viem.getContractAt("EIP20Interface", reward);
170147
const balance = await ionToken.read.balanceOf([market]);
171148
if (balance < parseEther(rewardAmount)) {
172-
await ionToken.write.transfer([market, parseEther(rewardAmount)]);
149+
await ionToken.write.transfer([market, parseEther(rewardAmount) - balance]);
173150
}
174-
*/
151+
175152
// Deploying flywheel
176153
let booster = "";
177154
let flywheelBoosterAddress;
@@ -247,7 +224,6 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
247224
} else console.log(`Strategy (${market}) was already added to flywheel (${flywheel.address})`);
248225

249226
// Adding flywheel to comptroller
250-
const comptroller = await viem.getContractAt("IonicComptroller", COMPTROLLER);
251227
const rewardsDistributors = (await comptroller.read.getRewardsDistributors()) as Address[];
252228
if (!rewardsDistributors.map((s) => s.toLowerCase()).includes(flywheel.address.toLowerCase())) {
253229
const addTx = await comptroller.write._addRewardsDistributor([flywheel.address]);
@@ -266,8 +242,8 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
266242
console.log(`mining tx ${tx}`);
267243
await publicClient.waitForTransactionReceipt({ hash: tx });
268244
console.log(`approved flywheel ${flywheel.address} to pull reward tokens from market ${market}`);
269-
}
270-
);
245+
}
246+
);
271247

272248
task("market:base:add-flywheel-ION-rewards-to-ionbsdETH", "Adds rewards to existing flywheel").setAction(
273249
async (_, { viem, run, deployments, getNamedAccounts }) => {

0 commit comments

Comments
 (0)