proof-of-take-sdk 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,4 @@
4
4
  * This module contains all optimistic update logic separated from instruction building.
5
5
  * Each function mirrors the on-chain logic to predict state changes before confirmation.
6
6
  */
7
- export { getCurrentTimestamp, createEmptyUserStats, initializeUserStats, updateUserStatsForMiztakeCreation, updateMiztakeStatisticsForCreation, initializeUserWindowParticipation, initializeRewardWindow, updateMiztakeForSeasonUse, initializeSeasonMembership, updateSeasonForJoin, updateWindowForConfirmation, updateParticipationForConfirmation, updateMembershipForConfirmation, updateSeasonForConfirmation, updateWindowForFinalization, updateParticipationForClaim, updateMembershipForClaim, initializeReferralPenaltyClaim, calculateWithdrawalAmount, updateSeasonSettingsForPauseToggle, updateSeasonSettingsForAdminUpdate, } from "../utils/accountUpdates";
7
+ export { getCurrentTimestamp, expectedToBeLazyInitialized, createEmptyUserStats, initializeUserStats, updateUserStatsForMiztakeCreation, updateMiztakeStatisticsForCreation, initializeUserWindowParticipation, initializeRewardWindow, updateMiztakeForSeasonUse, initializeSeasonMembership, updateSeasonForJoin, updateWindowForConfirmation, updateParticipationForConfirmation, updateMembershipForConfirmation, updateSeasonForConfirmation, updateWindowForFinalization, updateParticipationForClaim, updateMembershipForClaim, initializeReferralPenaltyClaim, calculateWithdrawalAmount, updateSeasonSettingsForPauseToggle, updateSeasonSettingsForAdminUpdate, } from "../utils/accountUpdates";
@@ -6,11 +6,12 @@
6
6
  * Each function mirrors the on-chain logic to predict state changes before confirmation.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.updateSeasonSettingsForAdminUpdate = exports.updateSeasonSettingsForPauseToggle = exports.calculateWithdrawalAmount = exports.initializeReferralPenaltyClaim = exports.updateMembershipForClaim = exports.updateParticipationForClaim = exports.updateWindowForFinalization = exports.updateSeasonForConfirmation = exports.updateMembershipForConfirmation = exports.updateParticipationForConfirmation = exports.updateWindowForConfirmation = exports.updateSeasonForJoin = exports.initializeSeasonMembership = exports.updateMiztakeForSeasonUse = exports.initializeRewardWindow = exports.initializeUserWindowParticipation = exports.updateMiztakeStatisticsForCreation = exports.updateUserStatsForMiztakeCreation = exports.initializeUserStats = exports.createEmptyUserStats = exports.getCurrentTimestamp = void 0;
9
+ exports.updateSeasonSettingsForAdminUpdate = exports.updateSeasonSettingsForPauseToggle = exports.calculateWithdrawalAmount = exports.initializeReferralPenaltyClaim = exports.updateMembershipForClaim = exports.updateParticipationForClaim = exports.updateWindowForFinalization = exports.updateSeasonForConfirmation = exports.updateMembershipForConfirmation = exports.updateParticipationForConfirmation = exports.updateWindowForConfirmation = exports.updateSeasonForJoin = exports.initializeSeasonMembership = exports.updateMiztakeForSeasonUse = exports.initializeRewardWindow = exports.initializeUserWindowParticipation = exports.updateMiztakeStatisticsForCreation = exports.updateUserStatsForMiztakeCreation = exports.initializeUserStats = exports.createEmptyUserStats = exports.expectedToBeLazyInitialized = exports.getCurrentTimestamp = void 0;
10
10
  // Re-export all optimistic update functions from accountUpdates
11
11
  // This provides a cleaner separation of concerns
12
12
  var accountUpdates_1 = require("../utils/accountUpdates");
13
13
  Object.defineProperty(exports, "getCurrentTimestamp", { enumerable: true, get: function () { return accountUpdates_1.getCurrentTimestamp; } });
14
+ Object.defineProperty(exports, "expectedToBeLazyInitialized", { enumerable: true, get: function () { return accountUpdates_1.expectedToBeLazyInitialized; } });
14
15
  Object.defineProperty(exports, "createEmptyUserStats", { enumerable: true, get: function () { return accountUpdates_1.createEmptyUserStats; } });
15
16
  Object.defineProperty(exports, "initializeUserStats", { enumerable: true, get: function () { return accountUpdates_1.initializeUserStats; } });
16
17
  Object.defineProperty(exports, "updateUserStatsForMiztakeCreation", { enumerable: true, get: function () { return accountUpdates_1.updateUserStatsForMiztakeCreation; } });
@@ -13,6 +13,34 @@ import { Miztake, UserStats, MiztakeStatistics, SeasonSettings, Season, SeasonMe
13
13
  * @returns Current Unix timestamp in seconds
14
14
  */
15
15
  export declare function getCurrentTimestamp(now?: BN): BN;
16
+ /**
17
+ * Build the Season account object that is expected to be created by on-chain lazy initialization.
18
+ *
19
+ * This is a PURE helper (no RPC). It mirrors `season_helpers::initialize_season`:
20
+ * - `season_state = Active`
21
+ * - `started_at = current_time`
22
+ * - `ends_at = current_time + season_duration`
23
+ * - all counters and totals initialized to zero
24
+ * - schedule `eligible_stake_per_window` initialized to 21 zeros
25
+ * - PDA bump derived locally from seeds (no RPC)
26
+ *
27
+ * IMPORTANT:
28
+ * To match on-chain state exactly, you must supply the same `startedAt` that the transaction
29
+ * will observe on-chain (i.e. `Clock::get()?.unix_timestamp` at execution time) and the same
30
+ * season duration as stored in SeasonSettings at that moment. If you don't have settings locally,
31
+ * we fall back to the canonical defaults (7 days, 21 windows).
32
+ */
33
+ export declare function expectedToBeLazyInitialized(params: {
34
+ /** Season number to initialize. */
35
+ seasonNumber: BN;
36
+ /** Unix timestamp in seconds used as `started_at` (i64 on-chain). */
37
+ startedAt: BN;
38
+ /**
39
+ * Optional settings snapshot (recommended) to compute `endsAt` and `totalWindows`.
40
+ * Providing this avoids drift if settings ever change.
41
+ */
42
+ seasonSettings?: Pick<SeasonSettings, "seasonDuration" | "totalWindowsPerSeason" | "lastSeasonEndsAt">;
43
+ }): Season;
16
44
  /**
17
45
  * Create an empty/initialized UserStats object
18
46
  * Used when initializing a new user stats account
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCurrentTimestamp = getCurrentTimestamp;
4
+ exports.expectedToBeLazyInitialized = expectedToBeLazyInitialized;
4
5
  exports.createEmptyUserStats = createEmptyUserStats;
5
6
  exports.initializeUserStats = initializeUserStats;
6
7
  exports.updateUserStatsForMiztakeCreation = updateUserStatsForMiztakeCreation;
@@ -42,6 +43,55 @@ function getCurrentTimestamp(now) {
42
43
  return now;
43
44
  return new anchor_1.BN(Math.floor(Date.now() / 1000)); // Convert JS milliseconds → seconds
44
45
  }
46
+ /**
47
+ * Build the Season account object that is expected to be created by on-chain lazy initialization.
48
+ *
49
+ * This is a PURE helper (no RPC). It mirrors `season_helpers::initialize_season`:
50
+ * - `season_state = Active`
51
+ * - `started_at = current_time`
52
+ * - `ends_at = current_time + season_duration`
53
+ * - all counters and totals initialized to zero
54
+ * - schedule `eligible_stake_per_window` initialized to 21 zeros
55
+ * - PDA bump derived locally from seeds (no RPC)
56
+ *
57
+ * IMPORTANT:
58
+ * To match on-chain state exactly, you must supply the same `startedAt` that the transaction
59
+ * will observe on-chain (i.e. `Clock::get()?.unix_timestamp` at execution time) and the same
60
+ * season duration as stored in SeasonSettings at that moment. If you don't have settings locally,
61
+ * we fall back to the canonical defaults (7 days, 21 windows).
62
+ */
63
+ function expectedToBeLazyInitialized(params) {
64
+ const seasonDuration = params.seasonSettings?.seasonDuration ?? new anchor_1.BN(604800); // 7 days
65
+ const totalWindows = params.seasonSettings?.totalWindowsPerSeason ?? 21;
66
+ // Derive bump seed locally (mirrors Anchor ctx.bumps.season).
67
+ const [, bump] = (0, pdas_1.getSeasonPda)(params.seasonNumber);
68
+ const lastSeasonEndsAt = params.seasonSettings?.lastSeasonEndsAt ?? new anchor_1.BN(0);
69
+ // If lastSeasonEndsAt is 0 (first season), use params.startedAt.
70
+ // Otherwise, use lastSeasonEndsAt exactly (gapless).
71
+ // Note: We ignore params.startedAt in the gapless case to match on-chain logic,
72
+ // but in practice the caller should ideally pass the correct gapless time.
73
+ const effectiveStartedAt = lastSeasonEndsAt.isZero()
74
+ ? params.startedAt
75
+ : lastSeasonEndsAt;
76
+ return {
77
+ seasonNumber: params.seasonNumber,
78
+ seasonState: types_1.SeasonState.Active,
79
+ startedAt: effectiveStartedAt,
80
+ endsAt: effectiveStartedAt.add(seasonDuration),
81
+ totalWindows,
82
+ totalMembers: new anchor_1.BN(0),
83
+ copperMembersCount: new anchor_1.BN(0),
84
+ silverMembersCount: new anchor_1.BN(0),
85
+ goldMembersCount: new anchor_1.BN(0),
86
+ platinumMembersCount: new anchor_1.BN(0),
87
+ mithrilMembersCount: new anchor_1.BN(0),
88
+ eligibleStakePerWindow: Array.from({ length: 21 }, () => new anchor_1.BN(0)),
89
+ totalDepositsHeld: new anchor_1.BN(0),
90
+ totalSuccessfulPosts: new anchor_1.BN(0),
91
+ totalPenaltiesCollected: new anchor_1.BN(0),
92
+ bump,
93
+ };
94
+ }
45
95
  /**
46
96
  * Create an empty/initialized UserStats object
47
97
  * Used when initializing a new user stats account
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proof-of-take-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "TypeScript SDK for Proof of Take Solana program",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",