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

Feat/turn off xp points #4

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/lrt/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const primeLaunchDate = new Date('2024-02-05 12:00 PM PST')

const eth = (val: bigint) => val * 1_000000000_000000000n

export const xpEndTimestamp = 1724785200000 // 2024-08-27 12:00 PM PST

export interface PointCondition {
name: string
// The multiplier the point condition will apply.
Expand Down
12 changes: 12 additions & 0 deletions src/lrt/logic/points.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LRTPointRecipientHistory, LRTSummary } from '../../model'
import { Block, Context } from '../../processor'
import { xpEndTimestamp } from '../config'
import { getLastSummary, state } from '../state'
import { campaigns } from './campaigns'
import { updateEigenPoints } from './eigen-points'
Expand Down Expand Up @@ -61,6 +62,17 @@ const createSummary = async (ctx: Context, block: Block) => {
points: totalPoints,
elPoints: lastSummary?.elPoints ?? 0n,
})
if (
lastSummary &&
block.header.timestamp >= xpEndTimestamp &&
lastSummary?.timestamp.valueOf() >= xpEndTimestamp &&
summary.points > lastSummary?.points
) {
throw new Error(
`Points should no longer be accruing after ${xpEndTimestamp}`,
)
}

state.summaries.set(summary.id, summary)

return { summary, recipients }
Expand Down
4 changes: 4 additions & 0 deletions src/lrt/logic/prime-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
pointConditions,
pointInterval,
referralConditions,
xpEndTimestamp,
} from '../config'
import { state } from '../state'
import { encodeAddress } from '../utils/encoding'
Expand Down Expand Up @@ -39,6 +40,9 @@ export const updateRecipientsPoints = async (
}
>(), // Who have we already calculated in this self-referencing function?
) => {
if (timestamp >= xpEndTimestamp) {
return { totalReferralPoints: [], count: memo.size }
}
const totalReferralPoints: ReferralPointData[] = []
for (const recipient of recipients) {
if (memo.has(recipient.id)) {
Expand Down
8 changes: 4 additions & 4 deletions src/lrt/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const getLastSummary = async (ctxOrEm: Context | EntityManager) => {
return await find(ctxOrEm, LRTSummary, {
take: 1,
order: { id: 'desc' },
}).then((r) => r[0])
}).then((r) => r[0] as LRTSummary | undefined)
}

export const getSummary = async (
Expand All @@ -156,9 +156,9 @@ export const getSummary = async (
id,
timestamp: new Date(block.header.timestamp),
blockNumber: block.header.height,
balance: lastSummary.balance ?? 0n,
points: lastSummary.points ?? 0n,
elPoints: lastSummary.elPoints ?? 0n,
balance: lastSummary?.balance ?? 0n,
points: lastSummary?.points ?? 0n,
elPoints: lastSummary?.elPoints ?? 0n,
})
}
return summary
Expand Down