Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync notify reward calls #104

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const pools = [
];

// Two decimals of precision -> 615 = 6.15
const distro = [
1959, 1980, 1999, 2020, 2042,
];
const distro = [1959, 1980, 1999, 2020, 2042];

const initTime = 1725386400; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 18:00:00 GMT
const initTime = 1725375600; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 15:00:00 GMT

let UnipoolTokenDistributor, currentTime, nonce;
async function main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* 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/4434
amount: "1510975",
}, // Garden Unipool
];

// Two decimals of precision -> 615 = 6.15
const distro = [1959, 1980, 1999, 2020, 2042];

const initTime = 1725375600; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 15:00:00 GMT

let UnipoolTokenDistributor, currentTime, nonce;
async function main() {
console.log("Trying to call notifyRewardAmount...", {
date: new Date().toString(),
});
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();

// 4 hours of precision
if (periodFinish < currentTime + 60 * 60 * 24) {
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_sep_2024.js",
transactionHash: tx.transactionHash,
amount,
});
} else {
console.log(
"UnipoolTokenDistributor - notifyRewardAmount:",
pool.address,
"already set",
);
}
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const pools = [
];

// Two decimals of precision -> 615 = 6.15
const distro = [
1959, 1980, 1999, 2020, 2042,
];
const distro = [1959, 1980, 1999, 2020, 2042];

const initTime = 1725386400; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 18:00:00 GMT
const initTime = 1725375600; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 15:00:00 GMT

let UnipoolTokenDistributor, currentTime, nonce;
async function main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* 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/4434
amount: "1510975",
}, // Garden Unipool
];

// Two decimals of precision -> 615 = 6.15
const distro = [1959, 1980, 1999, 2020, 2042];

const initTime = 1725375600; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 15:00:00 GMT

let UnipoolTokenDistributor, currentTime, nonce;
async function main() {
try {
console.log("Trying to call notifyRewardAmount...", {
date: new Date().toString(),
});
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]);
} catch (e) {
console.log("error when calling notifyRewardAmount:", e);
throw e;
}
}

async function notifyRewardAmount(pool) {
const unipoolTokenDistributor = await UnipoolTokenDistributor.attach(
pool.address,
);
const periodFinish = await unipoolTokenDistributor.periodFinish();
const duration = await unipoolTokenDistributor.duration();

// 24 hours of precision
if (periodFinish < currentTime + 60 * 60 * 24) {
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_extended_sep_2024.js",
transactionHash: tx.transactionHash,
amount,
});
} else {
console.log(
"UnipoolTokenDistributor - notifyRewardAmount:",
pool.address,
"already set",
);
}
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const pools = [
];

// Two decimals of precision -> 615 = 6.15
const distro = [
1959, 1980, 1999, 2020, 2042,
];
const distro = [1959, 1980, 1999, 2020, 2042];

const initTime = 1725386400; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 18:00:00 GMT
const initTime = 1725375600; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 15:00:00 GMT

let UnipoolTokenDistributor, currentTime, nonce;
async function main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* eslint-disable no-use-before-define */
const hre = require("hardhat");
const { sendReportEmail } = require("../../mailService/mailService");
const { ethers } = hre;

const pools = [
{
address: "0xc790f82bf6f8709aa4a56dc11afad7af7c2a9867",

// https://github.com/Giveth/giveth-dapps-v2/issues/4434
amount: "159050",
}, // Garden Unipool
];

// Two decimals of precision -> 615 = 6.15
const distro = [1959, 1980, 1999, 2020, 2042];

const initTime = 1725375600; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 15:00:00 GMT

let UnipoolTokenDistributor, currentTime, nonce;
async function main() {
console.log("Trying to call notifyRewardAmount...", {
date: new Date().toString(),
});
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();

// 24 hours of precision
if (periodFinish < currentTime + 60 * 60 * 24) {
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: "ZKEVM mainnet",
pool: pool.address,
round: pos + 1,
script: "givpower_distribute_extended_sep_2024.js",
transactionHash: tx.transactionHash,
amount,
});
} else {
console.log(
"UnipoolTokenDistributor - notifyRewardAmount:",
pool.address,
"already set",
);
}
}

main();
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
"distributor:xDAI:givPower:extended:oct2023": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_oct_2023.js",
"distributor:xDAI:givPower:extended:may2024": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_may_2024.js",
"distributor:xDAI:givPower:extended:sep2024": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_sep_2024.js",
"distributor:xDAI:givPower:extended:sep2024Temp": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_sep_2024Temp.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:optimismMainnet:givPower:extended:sep2024": "HARDHAT_NETWORK=optimismMainnet ts-node deployments/notifyRewardAmount/optimism/givpower_distribute_extended_sep_2024.js",
"distributor:optimismMainnet:givPower:extended:sep2024Temp": "HARDHAT_NETWORK=optimismMainnet ts-node deployments/notifyRewardAmount/optimism/givpower_distribute_extended_sep_2024Temp.js",
"distributor:zkevm:givPower:extended:sep2024": "HARDHAT_NETWORK=zkEVM ts-node deployments/notifyRewardAmount/zkevm/givpower_distribute_extended_sep_2024.js",
"distributor:zkevm:givPower:extended:sep2024Temp": "HARDHAT_NETWORK=zkEVM ts-node deployments/notifyRewardAmount/zkevm/givpower_distribute_extended_sep_2024.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",
Expand Down
Loading