diff --git a/deployments/notifyRewardAmount/optimism/givpower_distribute_extended_oct_2023.js b/deployments/notifyRewardAmount/optimism/givpower_distribute_extended_oct_2023.js new file mode 100644 index 0000000..6aedfd8 --- /dev/null +++ b/deployments/notifyRewardAmount/optimism/givpower_distribute_extended_oct_2023.js @@ -0,0 +1,79 @@ +/* eslint-disable no-use-before-define */ +const hre = require("hardhat"); +const { sendReportEmail } = require("../../mailService/mailService"); +const { ethers } = hre; + +const pools = [ + { + address: "0x301C739CF6bfb6B47A74878BdEB13f92F13Ae5E7", + + // https://github.com/Giveth/giveth-dapps-v2/issues/3402 + amount: "3125000", + }, // Garden Unipool +]; + +// Two decimals of precision -> 615 = 6.15 +const distro = [ + 615, 630, 645, 661, 676, 691, 706, 722, 738, 753, 768, 783, 798, 814, +]; + +const initTime = 1698775200; // Timestamp of first round in seconds: Tuesday, OCT 31, 2023 18:00:00 GMT + +let UnipoolTokenDistributor, currentTime, nonce; +async function main() { + currentTime = Math.floor(Date.now() / 1000); + const [signer, ...addrs] = await ethers.getSigners(); + nonce = await signer.getTransactionCount(); + UnipoolTokenDistributor = await ethers.getContractFactory( + "UnipoolTokenDistributor", + ); + await notifyRewardAmount(pools[0]); +} + +async function notifyRewardAmount(pool) { + const unipoolTokenDistributor = await UnipoolTokenDistributor.attach( + pool.address, + ); + const periodFinish = await unipoolTokenDistributor.periodFinish(); + const duration = await unipoolTokenDistributor.duration(); + + // 10 minutes of precision + if (periodFinish < currentTime + 60 * 10) { + const pos = Math.floor((currentTime - initTime) / duration); + console.log("pos:", pos); + if (pos < 0) return; + if (distro[pos] === 0) return; + const amount = ethers.utils + .parseEther(pool.amount) + .mul(distro[pos]) + .div(10000); + console.log( + "UnipoolTokenDistributor - notifyRewardAmount:", + pool.address, + "->", + ethers.utils.formatEther(amount.toString()), + ); + const tx = await ( + await unipoolTokenDistributor.notifyRewardAmount(amount, { nonce }) + ).wait(); + nonce += 1; + console.log("tx:", tx); + await sendReportEmail({ + farm: "Giv power", + network: "Optimisim mainnet", + pool: pool.address, + round: pos + 1, + script: "givpower_distribute_extended.js", + transactionHash: tx.transactionHash, + amount, + }); + } else { + console.log( + "UnipoolTokenDistributor - notifyRewardAmount:", + pool.address, + "already set", + ); + } +} + +main(); diff --git a/deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_oct_2023.js b/deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_oct_2023.js new file mode 100644 index 0000000..bb8c33e --- /dev/null +++ b/deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_oct_2023.js @@ -0,0 +1,78 @@ +/* eslint-disable no-use-before-define */ +const hre = require("hardhat"); +const { sendReportEmail } = require("../../mailService/mailService"); +const { ethers } = hre; + +const pools = [ + { + address: "0xD93d3bDBa18ebcB3317a57119ea44ed2Cf41C2F2", + + // https://github.com/Giveth/giveth-dapps-v2/issues/3402 + amount: " 9375000", + }, // Garden Unipool +]; + +// Two decimals of precision -> 615 = 6.15 +const distro = [ + 615, 630, 645, 661, 676, 691, 706, 722, 738, 753, 768, 783, 798, 814, +]; + +const initTime = 1698775200; // Timestamp of first round in seconds: Tuesday, OCT 31, 2023 18:00:00 GMT + +let UnipoolTokenDistributor, currentTime, nonce; +async function main() { + currentTime = Math.floor(Date.now() / 1000); + const [signer, ...addrs] = await ethers.getSigners(); + nonce = await signer.getTransactionCount(); + UnipoolTokenDistributor = await ethers.getContractFactory( + "UnipoolTokenDistributor", + ); + await notifyRewardAmount(pools[0]); +} + +async function notifyRewardAmount(pool) { + const unipoolTokenDistributor = await UnipoolTokenDistributor.attach( + pool.address, + ); + const periodFinish = await unipoolTokenDistributor.periodFinish(); + const duration = await unipoolTokenDistributor.duration(); + + // 10 minutes of precision + if (periodFinish < currentTime + 60 * 10) { + const pos = Math.floor((currentTime - initTime) / duration); + console.log("pos:", pos); + if (pos < 0) return; + const amount = ethers.utils + .parseEther(pool.amount) + .mul(distro[pos]) + .div(10000); + console.log( + "UnipoolTokenDistributor - notifyRewardAmount:", + pool.address, + "->", + ethers.utils.formatEther(amount.toString()), + ); + const tx = await ( + await unipoolTokenDistributor.notifyRewardAmount(amount, { nonce }) + ).wait(); + nonce += 1; + console.log("tx:", tx); + await sendReportEmail({ + farm: "Giv power", + network: "Gnosis", + pool: pool.address, + round: pos + 1, + script: "givpower_distribute.js", + transactionHash: tx.transactionHash, + amount, + }); + } else { + console.log( + "UnipoolTokenDistributor - notifyRewardAmount:", + pool.address, + "already set", + ); + } +} + +main(); diff --git a/package.json b/package.json index 4403399..c75bf39 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,9 @@ "distributor:xDAI:extended2": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/distributor_extended2.js", "distributor:xDAI:givPower": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/givpower_distribute.js", "distributor:xDAI:givPower:extended": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/givpower_distribute_extended.js", + "distributor:xDAI:givPower:extended:oct2023": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_oct_2023.js", "distributor:optimismMainnet:givPower:extended": "HARDHAT_NETWORK=optimismMainnet ts-node deployments/notifyRewardAmount/optimism/givpower_distribute_extended.js", + "distributor:optimismMainnet:givPower:extended:oct2023": "HARDHAT_NETWORK=optimismMainnet ts-node deployments/notifyRewardAmount/optimism/givpower_distribute_extended_oct_2023.js", "distributor:mainnet:extended": "HARDHAT_NETWORK=mainnet ts-node deployments/notifyRewardAmount/mainnet/distributor_extended.js", "distributor:mainnet:extended2": "HARDHAT_NETWORK=mainnet ts-node deployments/notifyRewardAmount/mainnet/distributor_extended2.js", "distributor:kovan:extended": "HARDHAT_NETWORK=kovan ts-node deployments/notifyRewardAmount/mainnet/distributor_extended.js",