Skip to content

Commit

Permalink
Merge pull request #73 from Giveth/f_1354_reward_for_august
Browse files Browse the repository at this point in the history
reward for august 2022
  • Loading branch information
mohammadranjbarz authored Aug 16, 2022
2 parents 075c8f2 + 2f7f787 commit bc13002
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
83 changes: 83 additions & 0 deletions deployments/notifyRewardAmount/mainnet/distributor_extended2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* eslint-disable no-use-before-define */
const hre = require("hardhat");
const { ethers } = hre;

// https://github.com/Giveth/giveth-dapps-v2/issues/1353

const pools = [
{
address: "0xc0dbDcA66a0636236fAbe1B3C16B1bD4C84bB1E1",
amount: " 900000", // 75000 * 6 (rounds) * 2 (weeks) = 900,000,
}, // BAL GIV/ETH
];

// Two decimals of precision -> 1666 = 16.66
const distro = [1666, 1666, 1666, 1666, 1666, 1666];

/* START TIME
* GIVeconomy start time + last reward round (17 * 2 weeks)
* 1640361600 + 17 * 2 * 7 * 24 * 3600 = 1660924800
*/
const initTime = 1660924800;

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) {
console.log("notifyReward has been called for", pool.address);
const unipoolTokenDistributor = await UnipoolTokenDistributor.attach(
pool.address,
);
const periodFinish = await unipoolTokenDistributor.periodFinish();
const duration = await unipoolTokenDistributor.duration();
// 1 hour of precision
if (periodFinish < currentTime + 3600) {
const pos = Math.floor((currentTime - initTime) / duration);
console.log("pos:", pos);
if (pos < 0) {
console.log("The currentTime is lower than initTime ", {
currentTime,
initTime,
});
return;
}
if (pos >= distro.length) {
console.log("There is no distro for this pool", {
pos,
poolAddress: pool.address,
});
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);
} else {
console.log(
"UnipoolTokenDistributor - notifyRewardAmount:",
pool.address,
"already set",
);
}
}

main();
85 changes: 85 additions & 0 deletions deployments/notifyRewardAmount/xDAI/distributor_extended2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* eslint-disable no-use-before-define */

// https://github.com/Giveth/giveth-dapps-v2/issues/1353

const hre = require("hardhat");
const { ethers } = hre;

const pools = [
{
address: "0xD93d3bDBa18ebcB3317a57119ea44ed2Cf41C2F2",
amount: "800000", // 100000 * 4 (rounds) * 2 (weeks) = 800,000
}, // $GIV
];

// Two decimals of precision -> 2500 = 25.00
const distro = [2500, 2500, 2500, 2500];

/* START TIME
* GIVeconomy start time + last reward round (17 * 2 weeks)
* 1640361600 + 17 * 2 * 7 * 24 * 3600 = 1656086400
*/
const initTime = 1660924800;

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) {
console.log("notifyReward has been called for", pool.address);
const unipoolTokenDistributor = await UnipoolTokenDistributor.attach(
pool.address,
);
const periodFinish = await unipoolTokenDistributor.periodFinish();
const duration = await unipoolTokenDistributor.duration();

// 1 hour of precision
if (periodFinish < currentTime + 3600) {
const pos = Math.floor((currentTime - initTime) / duration);
console.log("pos:", pos);
if (pos < 0) {
console.log("The currentTime is lower than initTime ", {
currentTime,
initTime,
});
return;
}
if (pos >= distro.length) {
console.log("There is no distro for this pool", {
pos,
poolAddress: pool.address,
});
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);
} else {
console.log(
"UnipoolTokenDistributor - notifyRewardAmount:",
pool.address,
"already set",
);
}
}

main();
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"distributor:mainnet": "HARDHAT_NETWORK=mainnet ts-node deployments/notifyRewardAmount/mainnet/distributor.js",
"distributor:kovan": "HARDHAT_NETWORK=kovan ts-node deployments/notifyRewardAmount/mainnet/distributor.js",
"distributor:xDAI:extended": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/distributor_extended.js",
"distributor:xDAI:extended2": "HARDHAT_NETWORK=xDAI ts-node deployments/notifyRewardAmount/xDAI/distributor_extended2.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",
"distributor:kovan:angelVault": "HARDHAT_NETWORK=kovan ts-node deployments/notifyRewardAmount/mainnet/giveth_angel_vault_distributor.js",
"distributor:mainnet:angelVault": "HARDHAT_NETWORK=mainnet ts-node deployments/notifyRewardAmount/mainnet/giveth_angel_vault_distributor.js",
Expand Down

0 comments on commit bc13002

Please sign in to comment.