@@ -10,20 +10,10 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
10
10
. setAction ( async ( { market, rewardAmount, reward, name } , { viem, run, deployments, getNamedAccounts } ) => {
11
11
const { deployer } = await getNamedAccounts ( ) ;
12
12
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;
25
13
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 ) ;
27
17
28
18
const allMarkets = await comptroller . read . getAllMarkets ( ) ;
29
19
@@ -36,12 +26,12 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
36
26
let cTokenInstance ;
37
27
for ( let index = 0 ; index < cTokenInstances . length ; index ++ ) {
38
28
const thisUnderlying = await cTokenInstances [ index ] . read . underlying ( ) ;
39
- if (!cTokenInstance && thisUnderlying.toLowerCase() === hyUSD .toLowerCase()) {
29
+ if ( ! cTokenInstance && thisUnderlying . toLowerCase ( ) === market . toLowerCase ( ) ) {
40
30
cTokenInstance = cTokenInstances [ index ] ;
41
31
}
42
32
}
43
33
if ( ! cTokenInstance ) {
44
- throw Error(`No market corresponds to this underlying: ${hyUSD }`);
34
+ throw Error ( `No market corresponds to this underlying: ${ market } ` ) ;
45
35
}
46
36
47
37
const implementationData = "0x" ;
@@ -61,13 +51,12 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
61
51
console . log (
62
52
`Implementation successfully set to ${ implementationAddress } : ${ setImplementationTx } `
63
53
) ;
64
- */
65
-
54
+
66
55
// Sending tokens
67
56
const ionToken = await viem . getContractAt ( "EIP20Interface" , reward ) ;
68
57
const balance = await ionToken . read . balanceOf ( [ market ] ) ;
69
58
if ( balance < parseEther ( rewardAmount ) ) {
70
- await ionToken . write . transfer ( [ market , parseEther ( rewardAmount ) ] ) ;
59
+ await ionToken . write . transfer ( [ market , parseEther ( rewardAmount ) - balance ] ) ;
71
60
}
72
61
73
62
let contractName ;
@@ -99,7 +88,7 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
99
88
await publicClient . waitForTransactionReceipt ( { hash : addTx } ) ;
100
89
console . log ( `Added strategy (${ market } ) to flywheel (${ flywheel . address } )` ) ;
101
90
} else console . log ( `Strategy (${ market } ) was already added to flywheel (${ flywheel . address } )` ) ;
102
- } ) ;
91
+ } ) ;
103
92
104
93
task ( "market:base:deploy-flywheel-and-add-rewards" , "Sets caps on a market" )
105
94
. addParam ( "market" , "market address" , undefined , types . string )
@@ -112,66 +101,54 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
112
101
const { deployer } = await getNamedAccounts ( ) ;
113
102
const publicClient = await viem . getPublicClient ( ) ;
114
103
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 ) ;
124
105
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 ( ) ;
127
109
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
+ ) ;
129
115
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
+ }
131
126
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
+ ] ) ;
137
134
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 } ` ;
143
140
}
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
+ ) ;
156
144
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
- /*
168
145
// Sending tokens
169
146
const ionToken = await viem . getContractAt ( "EIP20Interface" , reward ) ;
170
147
const balance = await ionToken . read . balanceOf ( [ market ] ) ;
171
148
if ( balance < parseEther ( rewardAmount ) ) {
172
- await ionToken.write.transfer([market, parseEther(rewardAmount)]);
149
+ await ionToken . write . transfer ( [ market , parseEther ( rewardAmount ) - balance ] ) ;
173
150
}
174
- */
151
+
175
152
// Deploying flywheel
176
153
let booster = "" ;
177
154
let flywheelBoosterAddress ;
@@ -247,7 +224,6 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
247
224
} else console . log ( `Strategy (${ market } ) was already added to flywheel (${ flywheel . address } )` ) ;
248
225
249
226
// Adding flywheel to comptroller
250
- const comptroller = await viem . getContractAt ( "IonicComptroller" , COMPTROLLER ) ;
251
227
const rewardsDistributors = ( await comptroller . read . getRewardsDistributors ( ) ) as Address [ ] ;
252
228
if ( ! rewardsDistributors . map ( ( s ) => s . toLowerCase ( ) ) . includes ( flywheel . address . toLowerCase ( ) ) ) {
253
229
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")
266
242
console . log ( `mining tx ${ tx } ` ) ;
267
243
await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
268
244
console . log ( `approved flywheel ${ flywheel . address } to pull reward tokens from market ${ market } ` ) ;
269
- }
270
- ) ;
245
+ }
246
+ ) ;
271
247
272
248
task ( "market:base:add-flywheel-ION-rewards-to-ionbsdETH" , "Adds rewards to existing flywheel" ) . setAction (
273
249
async ( _ , { viem, run, deployments, getNamedAccounts } ) => {
0 commit comments