@@ -6,23 +6,14 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
6
6
. addParam ( "market" , "market address" , undefined , types . string )
7
7
. addParam ( "rewardAmount" , "the amount of tokens streamed to first epoch" , undefined , types . string )
8
8
. addParam ( "reward" , "token address of reward token" , undefined , types . string )
9
- . setAction ( async ( { market, rewardAmount, reward } , { viem, run, deployments, getNamedAccounts } ) => {
9
+ . addParam ( "name" , "name of deployment" , undefined , types . string )
10
+ . setAction ( async ( { market, rewardAmount, reward, name } , { viem, run, deployments, getNamedAccounts } ) => {
10
11
const { deployer } = await getNamedAccounts ( ) ;
11
12
const publicClient = await viem . getPublicClient ( ) ;
12
- /*
13
- // Upgrade markets to the new implementation
14
- console.log(`Upgrading market: ${ionhyUSD} to CErc20RewardsDelegate`);
15
- await run("market:upgrade", {
16
- comptroller,
17
- underlying: hyUSD,
18
- implementationAddress: (await deployments.get("CErc20RewardsDelegate")).address,
19
- signer: deployer
20
- });
21
13
22
- const publicClient = await viem.getPublicClient();
23
- const { implementationAddress, comptroller: comptrollerAddress, underlying, signer: namedSigner } = taskArgs;
24
-
25
- 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 ) ;
26
17
27
18
const allMarkets = await comptroller . read . getAllMarkets ( ) ;
28
19
@@ -35,12 +26,12 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
35
26
let cTokenInstance ;
36
27
for ( let index = 0 ; index < cTokenInstances . length ; index ++ ) {
37
28
const thisUnderlying = await cTokenInstances [ index ] . read . underlying ( ) ;
38
- if (!cTokenInstance && thisUnderlying.toLowerCase() === hyUSD .toLowerCase()) {
29
+ if ( ! cTokenInstance && thisUnderlying . toLowerCase ( ) === market . toLowerCase ( ) ) {
39
30
cTokenInstance = cTokenInstances [ index ] ;
40
31
}
41
32
}
42
33
if ( ! cTokenInstance ) {
43
- throw Error(`No market corresponds to this underlying: ${hyUSD }`);
34
+ throw Error ( `No market corresponds to this underlying: ${ market } ` ) ;
44
35
}
45
36
46
37
const implementationData = "0x" ;
@@ -60,19 +51,25 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
60
51
console . log (
61
52
`Implementation successfully set to ${ implementationAddress } : ${ setImplementationTx } `
62
53
) ;
63
- */
64
- /*
54
+
65
55
// Sending tokens
66
56
const ionToken = await viem . getContractAt ( "EIP20Interface" , reward ) ;
67
57
const balance = await ionToken . read . balanceOf ( [ market ] ) ;
68
58
if ( balance < parseEther ( rewardAmount ) ) {
69
- await ionToken.write.transfer([market, parseEther(rewardAmount)]);
59
+ await ionToken . write . transfer ( [ market , parseEther ( rewardAmount ) - balance ] ) ;
70
60
}
71
- */
61
+
62
+ let contractName ;
63
+ if ( name . includes ( "Borrow" ) ) {
64
+ contractName = "IonicFlywheelBorrow" ;
65
+ } else {
66
+ contractName = "IonicFlywheel" ;
67
+ }
68
+
72
69
// Approving token sepening for fwRewards contract
73
70
const flywheel = await viem . getContractAt (
74
- "IonicFlywheel" ,
75
- ( await deployments . get ( "IonicFlywheel_ION_v3" ) ) . address as Address
71
+ ` ${ contractName } ` ,
72
+ ( await deployments . get ( ` ${ contractName } _ ${ name } ` ) ) . address as Address
76
73
) ;
77
74
78
75
const _market = await viem . getContractAt ( "CErc20RewardsDelegate" , market ) ;
@@ -91,7 +88,7 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
91
88
await publicClient . waitForTransactionReceipt ( { hash : addTx } ) ;
92
89
console . log ( `Added strategy (${ market } ) to flywheel (${ flywheel . address } )` ) ;
93
90
} else console . log ( `Strategy (${ market } ) was already added to flywheel (${ flywheel . address } )` ) ;
94
- } ) ;
91
+ } ) ;
95
92
96
93
task ( "market:base:deploy-flywheel-and-add-rewards" , "Sets caps on a market" )
97
94
. addParam ( "market" , "market address" , undefined , types . string )
@@ -104,66 +101,54 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
104
101
const { deployer } = await getNamedAccounts ( ) ;
105
102
const publicClient = await viem . getPublicClient ( ) ;
106
103
107
- /*
108
- // Upgrade markets to the new implementation
109
- console.log(`Upgrading market: ${ionhyUSD} to CErc20RewardsDelegate`);
110
- await run("market:upgrade", {
111
- comptroller,
112
- underlying: hyUSD,
113
- implementationAddress: (await deployments.get("CErc20RewardsDelegate")).address,
114
- signer: deployer
115
- });
104
+ const comptroller = await viem . getContractAt ( "IonicComptroller" , COMPTROLLER ) ;
116
105
117
- const publicClient = await viem.getPublicClient();
118
- 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 ( ) ;
119
109
120
- 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
+ ) ;
121
115
122
- 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
+ }
123
126
124
- const cTokenInstances = await Promise.all(
125
- allMarkets.map(async (marketAddress) => {
126
- return await viem.getContractAt("ICErc20PluginRewards", marketAddress);
127
- })
128
- );
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
+ ] ) ;
129
134
130
- let cTokenInstance;
131
- for (let index = 0; index < cTokenInstances.length; index++) {
132
- const thisUnderlying = await cTokenInstances[index].read.underlying( );
133
- if (!cTokenInstance && thisUnderlying.toLowerCase() === hyUSD.toLowerCase() ) {
134
- 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 } ` ;
135
140
}
136
- }
137
- if (!cTokenInstance) {
138
- throw Error(`No market corresponds to this underlying: ${hyUSD}`);
139
- }
140
-
141
- const implementationData = "0x";
142
- const implementationAddress = (await deployments.get("CErc20RewardsDelegate")).address;
143
- console.log(`Setting implementation to ${implementationAddress}`);
144
- const setImplementationTx = await cTokenInstance.write._setImplementationSafe([
145
- implementationAddress,
146
- implementationData
147
- ]);
141
+ console . log (
142
+ `Implementation successfully set to ${ implementationAddress } : ${ setImplementationTx } `
143
+ ) ;
148
144
149
- const receipt = await publicClient.waitForTransactionReceipt({
150
- hash: setImplementationTx
151
- });
152
- if (receipt.status !== "success") {
153
- throw `Failed set implementation to ${implementationAddress}`;
154
- }
155
- console.log(
156
- `Implementation successfully set to ${implementationAddress}: ${setImplementationTx}`
157
- );
158
- */
159
- /*
160
145
// Sending tokens
161
146
const ionToken = await viem . getContractAt ( "EIP20Interface" , reward ) ;
162
147
const balance = await ionToken . read . balanceOf ( [ market ] ) ;
163
148
if ( balance < parseEther ( rewardAmount ) ) {
164
- await ionToken.write.transfer([market, parseEther(rewardAmount)]);
149
+ await ionToken . write . transfer ( [ market , parseEther ( rewardAmount ) - balance ] ) ;
165
150
}
166
- */
151
+
167
152
// Deploying flywheel
168
153
let booster = "" ;
169
154
let flywheelBoosterAddress ;
@@ -179,9 +164,9 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
179
164
flywheelBoosterAddress = ( await deployments . get ( booster ) ) . address as Address ;
180
165
} else flywheelBoosterAddress = zeroAddress ;
181
166
182
- let _flywheel = await deployments . getOrNull ( `${ contractName } _${ name } _v3 ` ) ;
167
+ let _flywheel = await deployments . getOrNull ( `${ contractName } _${ name } ` ) ;
183
168
if ( ! _flywheel ) {
184
- _flywheel = await deployments . deploy ( `${ contractName } _${ name } _v3 ` , {
169
+ _flywheel = await deployments . deploy ( `${ contractName } _${ name } ` , {
185
170
contract : contractName ,
186
171
from : deployer ,
187
172
log : true ,
@@ -205,14 +190,14 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
205
190
// Deploying flywheel rewards
206
191
const flywheel = await viem . getContractAt (
207
192
`${ contractName } ` ,
208
- ( await deployments . get ( `${ contractName } _${ name } _v3 ` ) ) . address as Address
193
+ ( await deployments . get ( `${ contractName } _${ name } ` ) ) . address as Address
209
194
) ;
210
195
211
- let flywheelRewards = await deployments . getOrNull ( `IonicFlywheelDynamicRewards_${ name } _v3 ` ) ;
196
+ let flywheelRewards = await deployments . getOrNull ( `IonicFlywheelDynamicRewards_${ name } ` ) ;
212
197
if ( flywheelRewards ) {
213
198
console . log ( `Flywheel rewards ${ name } already deployed at ${ flywheelRewards . address } ` ) ;
214
199
} else {
215
- flywheelRewards = await deployments . deploy ( `IonicFlywheelDynamicRewards_${ name } _v3 ` , {
200
+ flywheelRewards = await deployments . deploy ( `IonicFlywheelDynamicRewards_${ name } ` , {
216
201
contract : "IonicFlywheelDynamicRewards" ,
217
202
from : deployer ,
218
203
log : true ,
@@ -239,7 +224,6 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
239
224
} else console . log ( `Strategy (${ market } ) was already added to flywheel (${ flywheel . address } )` ) ;
240
225
241
226
// Adding flywheel to comptroller
242
- const comptroller = await viem . getContractAt ( "IonicComptroller" , COMPTROLLER ) ;
243
227
const rewardsDistributors = ( await comptroller . read . getRewardsDistributors ( ) ) as Address [ ] ;
244
228
if ( ! rewardsDistributors . map ( ( s ) => s . toLowerCase ( ) ) . includes ( flywheel . address . toLowerCase ( ) ) ) {
245
229
const addTx = await comptroller . write . _addRewardsDistributor ( [ flywheel . address ] ) ;
@@ -258,26 +242,28 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
258
242
console . log ( `mining tx ${ tx } ` ) ;
259
243
await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
260
244
console . log ( `approved flywheel ${ flywheel . address } to pull reward tokens from market ${ market } ` ) ;
261
- }
262
- ) ;
245
+ }
246
+ ) ;
263
247
264
248
task ( "market:base:add-flywheel-ION-rewards-to-ionbsdETH" , "Adds rewards to existing flywheel" ) . setAction (
265
249
async ( _ , { viem, run, deployments, getNamedAccounts } ) => {
266
250
const market = "0x3d9669de9e3e98db41a1cbf6dc23446109945e3c" ; // ionbsdETH
267
- const rewardAmount = "23334" ; // epoch will start 2 days so 25000 / 30 * 2
251
+ const rewardAmount = "23334" ; // epoch will last for 28 days so 25000 / 30 * 28
268
252
const ion = "0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5" ;
253
+ const name = "ION" ; // For borrow flywheel use Borrow_ION for supply flywheel just ION
269
254
await run ( "market:base:add-rewards-to-existing-flywheel" , {
270
255
market,
271
256
rewardAmount,
272
- reward : ion
257
+ reward : ion ,
258
+ name : name
273
259
} ) ;
274
260
}
275
261
) ;
276
262
277
263
task ( "market:base:deploy-flywheel-and-add-ION-rewards-to-ionhyUSD" , "Deploys flywheel and adds rewards" ) . setAction (
278
264
async ( _ , { viem, run, deployments, getNamedAccounts } ) => {
279
265
const market = "0x751911bDa88eFcF412326ABE649B7A3b28c4dEDe" ; // ionhyUSD
280
- const rewardAmount = "14000" ; // epoch will start 2 days so 15000 / 30 * 2
266
+ const rewardAmount = "14000" ; // epoch will last for 28 days so 15000 / 30 * 28
281
267
const ion = "0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5" ;
282
268
const name = "ION" ; // For borrow flywheel use Borrow_ION for supply flywheel just ION
283
269
// NOTE: Make sure that epoch duration for supply and borrow are not the same
0 commit comments