1
- import { task } from "hardhat/config" ;
1
+ import { task , types } from "hardhat/config" ;
2
2
import { Address , parseEther , zeroAddress } from "viem" ;
3
3
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 } ) => {
6
10
const { deployer } = await getNamedAccounts ( ) ;
7
11
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
-
22
12
/*
23
13
// Upgrade markets to the new implementation
24
14
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
73
63
*/
74
64
75
65
// 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 ) ] ) ;
80
70
}
81
71
82
72
// Approving token sepening for fwRewards contract
@@ -85,48 +75,36 @@ task("market:base:add-rewards-to-existing-flywheel", "Sets caps on a market").se
85
75
( await deployments . get ( "IonicFlywheel_ION" ) ) . address as Address
86
76
) ;
87
77
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 } ` ) ;
98
85
99
86
// Adding strategies to flywheel
100
87
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 } )` ) ;
109
94
}
110
95
) ;
111
96
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 } ) => {
114
105
const { deployer } = await getNamedAccounts ( ) ;
115
106
const publicClient = await viem . getPublicClient ( ) ;
116
107
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
-
130
108
/*
131
109
// Upgrade markets to the new implementation
132
110
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
181
159
*/
182
160
183
161
// 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 ) ] ) ;
188
166
}
189
167
190
168
// Deploying flywheel
191
- let name = "ION" ;
192
169
let booster = "" ;
193
- let rewardToken = ION ;
194
- let epochDuration = 2588400 ; //30*(24*60*60)-60*60 29days 23 hours
195
170
let flywheelBoosterAddress ;
196
171
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
+
198
180
if ( booster != "" ) {
199
181
flywheelBoosterAddress = ( await deployments . get ( booster ) ) . address as Address ;
200
182
} else flywheelBoosterAddress = zeroAddress ;
201
183
202
- if ( name . includes ( "Borrow" ) ) {
203
- contractName = "IonicFlywheelBorrow" ;
204
- } else contractName = "IonicFlywheel" ;
184
+
205
185
206
186
const _flywheel = await deployments . deploy ( `${ contractName } _${ name } ` , {
207
187
contract : contractName ,
@@ -212,7 +192,7 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").set
212
192
execute : {
213
193
init : {
214
194
methodName : "initialize" ,
215
- args : [ rewardToken , zeroAddress , flywheelBoosterAddress , deployer ]
195
+ args : [ reward , zeroAddress , flywheelBoosterAddress , deployer ]
216
196
}
217
197
} ,
218
198
owner : deployer
@@ -223,7 +203,7 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").set
223
203
console . log ( `Deployed flywheel: ${ _flywheel . address } ` ) ;
224
204
225
205
// Deploying flywheel rewards
226
- const rewards = await deployments . deploy ( `IonicFlywheelDynamicRewards_${ name } ` , {
206
+ const flywheelRewards = await deployments . deploy ( `IonicFlywheelDynamicRewards_${ name } ` , {
227
207
contract : "IonicFlywheelDynamicRewards" ,
228
208
from : deployer ,
229
209
log : true ,
@@ -240,22 +220,18 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market").set
240
220
( await deployments . get ( `${ contractName } _${ name } ` ) ) . address as Address
241
221
) ;
242
222
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 } )` ) ;
246
226
247
227
// Adding strategies to flywheel
248
- const marketAddresses = markets . split ( "," ) ;
249
228
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 } )` ) ;
259
235
260
236
// Adding flywheel to comptroller
261
237
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
270
246
console . log ( `Added flywheel (${ flywheel . address } ) to pool (${ pool } )` ) ;
271
247
272
248
// 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 } ` ) ;
282
256
}
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