Skip to content

Commit

Permalink
fix: apply halving on CRNs
Browse files Browse the repository at this point in the history
  • Loading branch information
amalcaraz committed Mar 21, 2024
1 parent b6efa1a commit 5eab0d4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/components/common/CRNRewardsCell/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const CRNRewardsCell = ({ node }: { node: CRN }) => {
// @todo: Refactor this (use singleton)
const rewardManager = new StakeManager()

const rewards = rewardManager.CRNRewardsPerDay(node)
const rewards = rewardManager.CRNRewardsPerDay(node) * (365 / 12)
const isNotFullyLinked = useMemo(() => !node.parent, [node])

return (
Expand All @@ -18,6 +18,7 @@ export const CRNRewardsCell = ({ node }: { node: CRN }) => {
) : (
<div tw="inline-flex gap-2 items-center">
~ <Price value={rewards} />
/M
</div>
)}
</>
Expand Down
11 changes: 9 additions & 2 deletions src/components/common/EstimatedNodeRewardsChart/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ export const EstimatedNodeRewardsChart = ({
const theme = useTheme()

const data = useMemo(() => {
const activeNodes = stakeManager.activeNodes(nodes || [])
let perDayRewards = 0

if (nodes) {
const activeNodes = stakeManager.activeNodes(nodes)
const totalPerDay = stakeManager.totalPerDay(nodes)
// const totalPerDay = StakeManager.dailyCCNRewardsPool / activeNodes.length

perDayRewards = totalPerDay / activeNodes.length
}

const perDayRewards = StakeManager.dailyRewardsPool / activeNodes.length
const perMonthRewards = perDayRewards * 30
const total = perMonthRewards + perDayRewards

Expand Down
21 changes: 15 additions & 6 deletions src/domain/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export type RewardsResponse = {
}

export class StakeManager {
// @todo: Calculate halving automatically using dates
static dailyRewardsPool = 15_000 / 2
static dailyCCNRewardsPool = 15_000
static dailyCRNRewardsBase = 250 / (365 / 12)
static dailyCRNRewardsVariable = 1250 / (365 / 12)

static minStakeToActivateNode = 200_000
static minLinkedNodesForPenalty = 3

Expand Down Expand Up @@ -178,7 +180,9 @@ export class StakeManager {
if (!activeNodes) return 0

// @note: https://medium.com/aleph-im/aleph-im-staking-go-live-part-2-stakers-tokenomics-663164b5ec78
return StakeManager.dailyRewardsPool * ((Math.log10(activeNodes) + 1) / 3)
return (
StakeManager.dailyCCNRewardsPool * ((Math.log10(activeNodes) + 1) / 3)
)
}

totalPerAlephPerDay(nodes: CCN[]): number {
Expand Down Expand Up @@ -229,7 +233,7 @@ export class StakeManager {
if (!node.score) return 0

const activeNodes = this.activeNodes(nodes).length
const nodePool = StakeManager.dailyRewardsPool / activeNodes
const nodePool = StakeManager.dailyCCNRewardsPool / activeNodes
const normalizedScore = normalizeValue(node.score, 0.2, 0.8, 0, 1)
const linkedCRNPenalty = this.totalLinkedCRNPenaltyFactor(node)

Expand All @@ -241,8 +245,13 @@ export class StakeManager {
if (!node.score || !node.decentralization) return 0

const { decentralization, score } = node
const maxRewards = 500 + decentralization * 2500

return maxRewards * normalizeValue(score, 0.2, 0.8, 0, 1)
const maxRewards =
StakeManager.dailyCRNRewardsBase +
StakeManager.dailyCRNRewardsVariable * decentralization

const normalizedScore = normalizeValue(score, 0.2, 0.8, 0, 1)

return maxRewards * normalizedScore
}
}

0 comments on commit 5eab0d4

Please sign in to comment.