Skip to content

Commit

Permalink
Delete ad-hoc calculations for Legacy Nu
Browse files Browse the repository at this point in the history
  • Loading branch information
manumonti committed Jan 2, 2024
1 parent c121680 commit be1c1ac
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions src/scripts/gen_rewards_dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const ethers = require("ethers")
const Subgraph = require("./pre-rewards/subgraph.js")
const Rewards = require("./pre-rewards/rewards.js")
const MerkleDist = require("./merkle_dist/merkle_dist.js")
const BigNumber = require("bignumber.js")

// The following parameters must be modified for each distribution
const bonusWeight = 0.0
Expand Down Expand Up @@ -77,56 +76,15 @@ async function main() {
endTime
)
earnedPreRewards = Rewards.calculatePreRewards(preStakes, preWeight)
console.log("======= EARNED PRE REWARDS =======")
console.log(earnedPreRewards)
}

// Special case: Dec 8th 23 distribution. ###################################
// Nov 22nd 23, legacy stakes (i.e. T stakes that originally came from Keep
// and Nu staking contracts) were deactivated. There is a period in which
// these stakers can migrate to T and stake their tokens without losing the
// rewards associated to this migration period.
// This period ended for the legacy Nu stakers at Dec 8th 23 00:00.
// So, if a legacy stake migrated their legacy Nu (nuInT) tokens before
// the deadline, the period in which their tokens weren't staked (Nov 22nd -
// Dec 8th) will not be considered, so they will earn the corresponding
// rewards as there was no disruption in the staking.
//
// In addition, no rewards were distributed for stakes that had legacy
// staking, even if part of the staking was in tStake and not in legacy stake
// (nuInT, keepInT). So

// More info can be found here:
// https://github.com/threshold-network/solidity-contracts/issues/141
// https://forum.threshold.network/t/transition-guide-for-legacy-stakers/719
// https://etherscan.io/tx/0x68ddee6b5651d5348a40555b0079b5066d05a63196e3832323afafae0095a656
// https://github.com/threshold-network/merkle-distribution/pull/111

// We need the legacy stakes to delete the Keep legacy stakes
const blockNumber = 18624792 // Block height in which legacy stakes were deac
const legacyStakes = await Subgraph.getLegacyStakes(
graphqlApi,
blockNumber - 1
)

const legacyNuRewards = await Subgraph.getLegacyNuRewards(graphqlApi)
console.log("======= LEGACY NU REWARDS =======")
console.log(legacyNuRewards)

Object.keys(legacyNuRewards).map((stake) => {
// Caution: we are assuming that each legacyNuReward stake will have the
// same stake in earnedPreRewardAmount. This is true for this time
const stakeAdd = ethers.utils.getAddress(stake)
const earnedPreRewardAmount = BigNumber(earnedPreRewards[stakeAdd].amount)
const legacyNuRewardAmount = BigNumber(legacyNuRewards[stake])
earnedPreRewards[stakeAdd].amount = earnedPreRewardAmount
.plus(legacyNuRewardAmount)
.toFixed(0)
})

console.log("======= LEGACY NU + PRE REWARDS =======")
console.log(earnedPreRewards)

// tBTCv2 rewards calculation
if (tbtcv2Weight > 0) {
console.log("Calculating tBTCv2 rewards...")
Expand All @@ -138,8 +96,6 @@ async function main() {
tbtcv2RewardsRaw,
tbtcv2Weight
)
console.log("======= EARNED TBTC REWARDS BEFORE LEGACY REMOVE =======")
console.log(earnedTbtcv2Rewards)
}

// Delete the Keep legacy stakes in earned rewards
Expand All @@ -148,17 +104,11 @@ async function main() {
delete earnedTbtcv2Rewards[legacyStakeAddress]
})

console.log("======= EARNED TBTC REWARDS AFTER LEGACY REMOVE =======")
console.log(earnedTbtcv2Rewards)

// Delete the Keep legacy stakes in rewards details file
const rewardsDetailsPath =
"distributions/2023-12-08/tBTCv2-rewards-details/1701388800-1701993600.json"
const rewardsDetails = JSON.parse(fs.readFileSync(rewardsDetailsPath))

console.log("======= REWARDS DETAILS BEFORE LEGACY REMOVE =======")
console.log(JSON.stringify(rewardsDetails, null, 4))

const rewardsDetailsFiltered = rewardsDetails.filter((rewardDetail) => {
const rewardStakingProvider = Object.keys(rewardDetail)[0].toLowerCase()
const legacyStakesStakingProviders = Object.keys(legacyStakes)
Expand All @@ -170,9 +120,6 @@ async function main() {
JSON.stringify(rewardsDetailsFiltered, null, 4)
)

console.log("======= REWARDS DETAILS AFTER LEGACY REMOVE =======")
console.log(JSON.stringify(rewardsDetailsFiltered, null, 4))

// Add rewards earned to cumulative totals
try {
bonusRewards = JSON.parse(
Expand Down

0 comments on commit be1c1ac

Please sign in to comment.