-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Iimprove token incentive scripts (#139)
* feat: Iimprove token incentive scripts * lint
- Loading branch information
1 parent
48f0398
commit ce47d94
Showing
5 changed files
with
235 additions
and
106 deletions.
There are no files selected for viewing
118 changes: 12 additions & 106 deletions
118
packages/zevm-app-contracts/scripts/liquidity-incentives/add-reward.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/zevm-app-contracts/scripts/liquidity-incentives/deploy-default-rewards.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { BigNumber } from "@ethersproject/bignumber"; | ||
import { isProtocolNetworkName } from "@zetachain/protocol-contracts"; | ||
import { parseEther } from "ethers/lib/utils"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { RewardDistributorFactory__factory, SystemContract__factory } from "../../typechain-types"; | ||
import { getSystemContractAddress, getZEVMAppAddress } from "../address.helpers"; | ||
import { addReward, deployRewardByNetwork } from "./helpers"; | ||
|
||
const REWARD_DURATION = BigNumber.from("604800").mul(8); // 1 week * 8 | ||
const REWARDS_AMOUNT = parseEther("500"); | ||
|
||
const main = async () => { | ||
const [deployer] = await ethers.getSigners(); | ||
const networkName = network.name; | ||
|
||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
const systemContractAddress = getSystemContractAddress(); | ||
const systemContract = await SystemContract__factory.connect(systemContractAddress, deployer); | ||
|
||
const factoryContractAddress = getZEVMAppAddress("rewardDistributorFactory"); | ||
|
||
const rewardDistributorFactory = RewardDistributorFactory__factory.connect(factoryContractAddress, deployer); | ||
let rewardContractAddress = ""; | ||
// @dev: you can write your own address here to add reward to an existing contract | ||
// rewardContractAddress = "0x0dee8b6e2d2035a798b67c68d47f941718a62263"; | ||
rewardContractAddress = await deployRewardByNetwork( | ||
deployer, | ||
systemContract, | ||
"goerli_testnet", | ||
rewardDistributorFactory | ||
); | ||
await addReward(deployer, systemContract, rewardContractAddress, REWARD_DURATION, REWARDS_AMOUNT); | ||
|
||
rewardContractAddress = await deployRewardByNetwork( | ||
deployer, | ||
systemContract, | ||
"bsc_testnet", | ||
rewardDistributorFactory | ||
); | ||
await addReward(deployer, systemContract, rewardContractAddress, REWARD_DURATION, REWARDS_AMOUNT); | ||
rewardContractAddress = await deployRewardByNetwork( | ||
deployer, | ||
systemContract, | ||
"btc_testnet", | ||
rewardDistributorFactory | ||
); | ||
await addReward(deployer, systemContract, rewardContractAddress, REWARD_DURATION, REWARDS_AMOUNT); | ||
rewardContractAddress = await deployRewardByNetwork( | ||
deployer, | ||
systemContract, | ||
"mumbai_testnet", | ||
rewardDistributorFactory | ||
); | ||
await addReward(deployer, systemContract, rewardContractAddress, REWARD_DURATION, REWARDS_AMOUNT); | ||
}; | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/zevm-app-contracts/scripts/liquidity-incentives/deploy-token-reward.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { BigNumber } from "@ethersproject/bignumber"; | ||
import { isProtocolNetworkName } from "@zetachain/protocol-contracts"; | ||
import { parseEther } from "ethers/lib/utils"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { RewardDistributorFactory__factory, SystemContract__factory } from "../../typechain-types"; | ||
import { getSystemContractAddress, getZEVMAppAddress } from "../address.helpers"; | ||
import { addReward, deployRewardByToken } from "./helpers"; | ||
|
||
const REWARD_DURATION = BigNumber.from("604800").mul(8); // 1 week * 8 | ||
const REWARDS_AMOUNT = parseEther("500"); | ||
const TOKEN_ADDRESS = "0x0dee8b6e2d2035a798b67c68d47f941718a62263"; | ||
|
||
const main = async () => { | ||
const [deployer] = await ethers.getSigners(); | ||
const networkName = network.name; | ||
|
||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
|
||
const systemContractAddress = getSystemContractAddress(); | ||
const systemContract = await SystemContract__factory.connect(systemContractAddress, deployer); | ||
|
||
const factoryContractAddress = getZEVMAppAddress("rewardDistributorFactory"); | ||
|
||
const rewardDistributorFactory = RewardDistributorFactory__factory.connect(factoryContractAddress, deployer); | ||
|
||
const rewardContractAddress = await deployRewardByToken( | ||
deployer, | ||
systemContract, | ||
TOKEN_ADDRESS, | ||
rewardDistributorFactory | ||
); | ||
await addReward(deployer, systemContract, rewardContractAddress, REWARD_DURATION, REWARDS_AMOUNT); | ||
}; | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/zevm-app-contracts/scripts/liquidity-incentives/deploy-zrc20-reward.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { BigNumber } from "@ethersproject/bignumber"; | ||
import { isProtocolNetworkName } from "@zetachain/protocol-contracts"; | ||
import { parseEther } from "ethers/lib/utils"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { RewardDistributorFactory__factory, SystemContract__factory } from "../../typechain-types"; | ||
import { getSystemContractAddress, getZEVMAppAddress } from "../address.helpers"; | ||
import { addReward, deployRewardByNetwork } from "./helpers"; | ||
|
||
const REWARD_DURATION = BigNumber.from("604800").mul(8); // 1 week * 8 | ||
const REWARDS_AMOUNT = parseEther("500"); | ||
const NETWORK_NAME = "goerli_testnet"; // @dev: change to your network name | ||
|
||
const main = async () => { | ||
const [deployer] = await ethers.getSigners(); | ||
const networkName = network.name; | ||
|
||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
|
||
const systemContractAddress = getSystemContractAddress(); | ||
const systemContract = await SystemContract__factory.connect(systemContractAddress, deployer); | ||
|
||
const factoryContractAddress = getZEVMAppAddress("rewardDistributorFactory"); | ||
|
||
const rewardDistributorFactory = RewardDistributorFactory__factory.connect(factoryContractAddress, deployer); | ||
|
||
const rewardContractAddress = await deployRewardByNetwork( | ||
deployer, | ||
systemContract, | ||
NETWORK_NAME, | ||
rewardDistributorFactory | ||
); | ||
await addReward(deployer, systemContract, rewardContractAddress, REWARD_DURATION, REWARDS_AMOUNT); | ||
}; | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
84 changes: 84 additions & 0 deletions
84
packages/zevm-app-contracts/scripts/liquidity-incentives/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { BigNumber } from "@ethersproject/bignumber"; | ||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; | ||
import { ZetaProtocolNetwork } from "@zetachain/protocol-contracts"; | ||
import { parseEther } from "ethers/lib/utils"; | ||
|
||
import { | ||
ERC20__factory, | ||
RewardDistributor__factory, | ||
RewardDistributorFactory, | ||
SystemContract, | ||
} from "../../typechain-types"; | ||
import { getChainId } from "../address.helpers"; | ||
|
||
export const deployRewardByToken = async ( | ||
deployer: SignerWithAddress, | ||
systemContract: SystemContract, | ||
tokenAddress: string, | ||
rewardDistributorFactory: RewardDistributorFactory | ||
) => { | ||
const zetaTokenAddress = await systemContract.wZetaContractAddress(); | ||
|
||
const tx = await rewardDistributorFactory.createTokenIncentive( | ||
deployer.address, | ||
deployer.address, | ||
zetaTokenAddress, | ||
// @dev: now we send both tokens so contract calculate internaly LP address | ||
zetaTokenAddress, | ||
tokenAddress | ||
); | ||
|
||
const receipt = await tx.wait(); | ||
|
||
const event = receipt.events?.find((e) => e.event === "RewardDistributorCreated"); | ||
|
||
const { rewardDistributorContract: rewardDistributorContractAddress } = event?.args as any; | ||
|
||
console.log("RewardDistributor deployed to:", rewardDistributorContractAddress); | ||
|
||
return rewardDistributorContractAddress; | ||
}; | ||
|
||
const getZRC20Address = async (systemContract: SystemContract, network: ZetaProtocolNetwork) => { | ||
const tokenAddress = await systemContract.gasCoinZRC20ByChainId(getChainId(network)); | ||
return tokenAddress; | ||
}; | ||
|
||
export const deployRewardByNetwork = async ( | ||
deployer: SignerWithAddress, | ||
systemContract: SystemContract, | ||
networkName: ZetaProtocolNetwork, | ||
rewardDistributorFactory: RewardDistributorFactory | ||
) => { | ||
const tokenAddress = await getZRC20Address(systemContract, networkName); | ||
const rewardContractAddress = await deployRewardByToken( | ||
deployer, | ||
systemContract, | ||
tokenAddress, | ||
rewardDistributorFactory | ||
); | ||
return rewardContractAddress; | ||
}; | ||
|
||
export const addReward = async ( | ||
deployer: SignerWithAddress, | ||
systemContract: SystemContract, | ||
rewardDistributorContractAddress: string, | ||
rewardAmount: BigNumber = parseEther("500"), | ||
rewardDuration: BigNumber = BigNumber.from("604800").mul(8) // 1 week * 8 | ||
) => { | ||
const zetaTokenAddress = await systemContract.wZetaContractAddress(); | ||
|
||
const rewardDistributorContract = await RewardDistributor__factory.connect( | ||
rewardDistributorContractAddress, | ||
deployer | ||
); | ||
|
||
const ZETA = ERC20__factory.connect(zetaTokenAddress, deployer); | ||
const tx = await ZETA.transfer(rewardDistributorContract.address, rewardAmount.mul(1)); | ||
await tx.wait(); | ||
await rewardDistributorContract.setRewardsDuration(rewardDuration); | ||
await rewardDistributorContract.notifyRewardAmount(rewardAmount); | ||
|
||
console.log("Reward added to:", rewardDistributorContract.address); | ||
}; |