-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add notify reward script for gnosis, optimism, zkevm sep 2024 #103
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
deployments/notifyRewardAmount/optimism/givpower_distribute_extended_sep_2024.js
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,82 @@ | ||
/* 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 = 1725386400; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 18: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(); | ||
|
||
// 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_sep_2024.js", | ||
transactionHash: tx.transactionHash, | ||
amount, | ||
}); | ||
} else { | ||
console.log( | ||
"UnipoolTokenDistributor - notifyRewardAmount:", | ||
pool.address, | ||
"already set", | ||
); | ||
} | ||
} | ||
|
||
main(); |
86 changes: 86 additions & 0 deletions
86
deployments/notifyRewardAmount/xDAI/givpower_distribute_extended_sep_2024.js
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,86 @@ | ||
/* 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 = 1725386400; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 18: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(); | ||
|
||
// 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_extended_sep_2024.js", | ||
transactionHash: tx.transactionHash, | ||
amount, | ||
}); | ||
} else { | ||
console.log( | ||
"UnipoolTokenDistributor - notifyRewardAmount:", | ||
pool.address, | ||
"already set", | ||
); | ||
} | ||
} | ||
|
||
main(); |
82 changes: 82 additions & 0 deletions
82
deployments/notifyRewardAmount/zkevm/givpower_distribute_extended_sep_2024.js
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,82 @@ | ||
/* 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 = 1725386400; // Timestamp of first round in seconds: Tuesday, SEP 3, 2024 18: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(); | ||
|
||
// 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: "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(); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?! in purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just used the last notifyReward script and changed the params and addresses, .. , didn't change the code logic, WDYT should we delete it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may have put that condition in place due to some special situation we had with optimism. If the current OP rewarding program ends around the the start of the new program, we don't need that condition.