@@ -6,23 +6,14 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
66 . addParam ( "market" , "market address" , undefined , types . string )
77 . addParam ( "rewardAmount" , "the amount of tokens streamed to first epoch" , undefined , types . string )
88 . 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 } ) => {
1011 const { deployer } = await getNamedAccounts ( ) ;
1112 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- });
2113
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 ) ;
2617
2718 const allMarkets = await comptroller . read . getAllMarkets ( ) ;
2819
@@ -35,12 +26,12 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
3526 let cTokenInstance ;
3627 for ( let index = 0 ; index < cTokenInstances . length ; index ++ ) {
3728 const thisUnderlying = await cTokenInstances [ index ] . read . underlying ( ) ;
38- if (!cTokenInstance && thisUnderlying.toLowerCase() === hyUSD .toLowerCase()) {
29+ if ( ! cTokenInstance && thisUnderlying . toLowerCase ( ) === market . toLowerCase ( ) ) {
3930 cTokenInstance = cTokenInstances [ index ] ;
4031 }
4132 }
4233 if ( ! cTokenInstance ) {
43- throw Error(`No market corresponds to this underlying: ${hyUSD }`);
34+ throw Error ( `No market corresponds to this underlying: ${ market } ` ) ;
4435 }
4536
4637 const implementationData = "0x" ;
@@ -60,19 +51,25 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
6051 console . log (
6152 `Implementation successfully set to ${ implementationAddress } : ${ setImplementationTx } `
6253 ) ;
63- */
64- /*
54+
6555 // Sending tokens
6656 const ionToken = await viem . getContractAt ( "EIP20Interface" , reward ) ;
6757 const balance = await ionToken . read . balanceOf ( [ market ] ) ;
6858 if ( balance < parseEther ( rewardAmount ) ) {
69- await ionToken.write.transfer([market, parseEther(rewardAmount)]);
59+ await ionToken . write . transfer ( [ market , parseEther ( rewardAmount ) - balance ] ) ;
7060 }
71- */
61+
62+ let contractName ;
63+ if ( name . includes ( "Borrow" ) ) {
64+ contractName = "IonicFlywheelBorrow" ;
65+ } else {
66+ contractName = "IonicFlywheel" ;
67+ }
68+
7269 // Approving token sepening for fwRewards contract
7370 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
7673 ) ;
7774
7875 const _market = await viem . getContractAt ( "CErc20RewardsDelegate" , market ) ;
@@ -91,7 +88,7 @@ task("market:base:add-rewards-to-existing-flywheel", "Adds rewards to existing f
9188 await publicClient . waitForTransactionReceipt ( { hash : addTx } ) ;
9289 console . log ( `Added strategy (${ market } ) to flywheel (${ flywheel . address } )` ) ;
9390 } else console . log ( `Strategy (${ market } ) was already added to flywheel (${ flywheel . address } )` ) ;
94- } ) ;
91+ } ) ;
9592
9693task ( "market:base:deploy-flywheel-and-add-rewards" , "Sets caps on a market" )
9794 . addParam ( "market" , "market address" , undefined , types . string )
@@ -104,66 +101,54 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
104101 const { deployer } = await getNamedAccounts ( ) ;
105102 const publicClient = await viem . getPublicClient ( ) ;
106103
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 ) ;
116105
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 ( ) ;
119109
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+ ) ;
121115
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+ }
123126
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+ ] ) ;
129134
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 } ` ;
135140 }
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+ ) ;
148144
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- /*
160145 // Sending tokens
161146 const ionToken = await viem . getContractAt ( "EIP20Interface" , reward ) ;
162147 const balance = await ionToken . read . balanceOf ( [ market ] ) ;
163148 if ( balance < parseEther ( rewardAmount ) ) {
164- await ionToken.write.transfer([market, parseEther(rewardAmount)]);
149+ await ionToken . write . transfer ( [ market , parseEther ( rewardAmount ) - balance ] ) ;
165150 }
166- */
151+
167152 // Deploying flywheel
168153 let booster = "" ;
169154 let flywheelBoosterAddress ;
@@ -179,9 +164,9 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
179164 flywheelBoosterAddress = ( await deployments . get ( booster ) ) . address as Address ;
180165 } else flywheelBoosterAddress = zeroAddress ;
181166
182- let _flywheel = await deployments . getOrNull ( `${ contractName } _${ name } _v3 ` ) ;
167+ let _flywheel = await deployments . getOrNull ( `${ contractName } _${ name } ` ) ;
183168 if ( ! _flywheel ) {
184- _flywheel = await deployments . deploy ( `${ contractName } _${ name } _v3 ` , {
169+ _flywheel = await deployments . deploy ( `${ contractName } _${ name } ` , {
185170 contract : contractName ,
186171 from : deployer ,
187172 log : true ,
@@ -205,14 +190,14 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
205190 // Deploying flywheel rewards
206191 const flywheel = await viem . getContractAt (
207192 `${ contractName } ` ,
208- ( await deployments . get ( `${ contractName } _${ name } _v3 ` ) ) . address as Address
193+ ( await deployments . get ( `${ contractName } _${ name } ` ) ) . address as Address
209194 ) ;
210195
211- let flywheelRewards = await deployments . getOrNull ( `IonicFlywheelDynamicRewards_${ name } _v3 ` ) ;
196+ let flywheelRewards = await deployments . getOrNull ( `IonicFlywheelDynamicRewards_${ name } ` ) ;
212197 if ( flywheelRewards ) {
213198 console . log ( `Flywheel rewards ${ name } already deployed at ${ flywheelRewards . address } ` ) ;
214199 } else {
215- flywheelRewards = await deployments . deploy ( `IonicFlywheelDynamicRewards_${ name } _v3 ` , {
200+ flywheelRewards = await deployments . deploy ( `IonicFlywheelDynamicRewards_${ name } ` , {
216201 contract : "IonicFlywheelDynamicRewards" ,
217202 from : deployer ,
218203 log : true ,
@@ -239,7 +224,6 @@ task("market:base:deploy-flywheel-and-add-rewards", "Sets caps on a market")
239224 } else console . log ( `Strategy (${ market } ) was already added to flywheel (${ flywheel . address } )` ) ;
240225
241226 // Adding flywheel to comptroller
242- const comptroller = await viem . getContractAt ( "IonicComptroller" , COMPTROLLER ) ;
243227 const rewardsDistributors = ( await comptroller . read . getRewardsDistributors ( ) ) as Address [ ] ;
244228 if ( ! rewardsDistributors . map ( ( s ) => s . toLowerCase ( ) ) . includes ( flywheel . address . toLowerCase ( ) ) ) {
245229 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")
258242 console . log ( `mining tx ${ tx } ` ) ;
259243 await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
260244 console . log ( `approved flywheel ${ flywheel . address } to pull reward tokens from market ${ market } ` ) ;
261- }
262- ) ;
245+ }
246+ ) ;
263247
264248task ( "market:base:add-flywheel-ION-rewards-to-ionbsdETH" , "Adds rewards to existing flywheel" ) . setAction (
265249 async ( _ , { viem, run, deployments, getNamedAccounts } ) => {
266250 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
268252 const ion = "0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5" ;
253+ const name = "ION" ; // For borrow flywheel use Borrow_ION for supply flywheel just ION
269254 await run ( "market:base:add-rewards-to-existing-flywheel" , {
270255 market,
271256 rewardAmount,
272- reward : ion
257+ reward : ion ,
258+ name : name
273259 } ) ;
274260 }
275261) ;
276262
277263task ( "market:base:deploy-flywheel-and-add-ION-rewards-to-ionhyUSD" , "Deploys flywheel and adds rewards" ) . setAction (
278264 async ( _ , { viem, run, deployments, getNamedAccounts } ) => {
279265 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
281267 const ion = "0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5" ;
282268 const name = "ION" ; // For borrow flywheel use Borrow_ION for supply flywheel just ION
283269 // NOTE: Make sure that epoch duration for supply and borrow are not the same
0 commit comments