|
| 1 | +import { zeroAddress, Hash, Address } from "viem"; |
| 2 | + |
| 3 | +import { FuseFlywheelDeployFnParams } from ".."; |
| 4 | + |
| 5 | +export const deployFlywheelWithDynamicRewards = async ({ |
| 6 | + viem, |
| 7 | + getNamedAccounts, |
| 8 | + deployments, |
| 9 | + deployConfig |
| 10 | +}: FuseFlywheelDeployFnParams): Promise<Array<string>> => { |
| 11 | + const { deployer } = await getNamedAccounts(); |
| 12 | + const publicClient = await viem.getPublicClient(); |
| 13 | + |
| 14 | + const dynamicFlywheels = []; |
| 15 | + |
| 16 | + for (const config of deployConfig.dynamicFlywheels!) { |
| 17 | + if (config) { |
| 18 | + console.log(`Deploying IonicFlywheel & ReplacingFlywheelDynamicRewards for ${config.rewardToken} reward token`); |
| 19 | + const flywheelBooster = await viem.getContractAt( |
| 20 | + "LooplessFlywheelBooster", |
| 21 | + (await deployments.get("LooplessFlywheelBooster")).address as Address |
| 22 | + ); |
| 23 | + const flywheelToReplace = config.flywheelToReplace ? config.flywheelToReplace : zeroAddress; |
| 24 | + |
| 25 | + //// IonicFlywheelCore with Dynamic Rewards |
| 26 | + const fwc = await deployments.deploy(`IonicFlywheel_${config.name}`, { |
| 27 | + contract: "IonicFlywheel", |
| 28 | + from: deployer, |
| 29 | + log: true, |
| 30 | + proxy: { |
| 31 | + execute: { |
| 32 | + init: { |
| 33 | + methodName: "initialize", |
| 34 | + args: [config.rewardToken, zeroAddress, flywheelBooster.address, deployer] |
| 35 | + } |
| 36 | + }, |
| 37 | + proxyContract: "OpenZeppelinTransparentProxy", |
| 38 | + owner: deployer |
| 39 | + }, |
| 40 | + waitConfirmations: 1 |
| 41 | + }); |
| 42 | + if (fwc.transactionHash) { |
| 43 | + await publicClient.waitForTransactionReceipt({ hash: fwc.transactionHash as Hash }); |
| 44 | + } |
| 45 | + console.log("IonicFlywheel: ", fwc.address); |
| 46 | + |
| 47 | + const fdr = await deployments.deploy(`ReplacingFlywheelDynamicRewards_${config.name}`, { |
| 48 | + contract: "ReplacingFlywheelDynamicRewards", |
| 49 | + from: deployer, |
| 50 | + args: [flywheelToReplace, fwc.address, config.cycleLength], |
| 51 | + log: true, |
| 52 | + waitConfirmations: 1 |
| 53 | + }); |
| 54 | + if (fdr.transactionHash) { |
| 55 | + await publicClient.waitForTransactionReceipt({ hash: fdr.transactionHash as Hash }); |
| 56 | + } |
| 57 | + console.log("ReplacingFlywheelDynamicRewards: ", fdr.address); |
| 58 | + |
| 59 | + const flywheelCore = await viem.getContractAt( |
| 60 | + `IonicFlywheel_${config.name}`, |
| 61 | + (await deployments.get(`IonicFlywheel_${config.name}`)).address as Address |
| 62 | + ); |
| 63 | + const currentRewards = await flywheelCore.read.flywheelRewards(); |
| 64 | + if (currentRewards != fdr.address) { |
| 65 | + const hash = await flywheelCore.write.setFlywheelRewards([fdr.address]); |
| 66 | + await publicClient.waitForTransactionReceipt({ hash }); |
| 67 | + console.log("setFlywheelRewards: ", hash); |
| 68 | + } else { |
| 69 | + console.log(`rewards contract already set`); |
| 70 | + } |
| 71 | + |
| 72 | + dynamicFlywheels.push(fwc.address); |
| 73 | + } |
| 74 | + } |
| 75 | + return dynamicFlywheels; |
| 76 | +}; |
0 commit comments