proof-of-take-sdk 3.0.1 → 3.0.3

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.
Files changed (77) hide show
  1. package/dist/client.js +3 -3
  2. package/dist/getters/getMiztake.d.ts +2 -2
  3. package/dist/getters/getMiztake.js +2 -15
  4. package/dist/getters/getMiztakeStatistics.js +2 -2
  5. package/dist/getters/getReferralPenaltyClaim.d.ts +9 -0
  6. package/dist/getters/getReferralPenaltyClaim.js +20 -0
  7. package/dist/getters/getRewardWindow.d.ts +9 -0
  8. package/dist/getters/getRewardWindow.js +20 -0
  9. package/dist/getters/getSeason.d.ts +8 -0
  10. package/dist/getters/getSeason.js +20 -0
  11. package/dist/getters/getSeasonMembership.d.ts +9 -0
  12. package/dist/getters/getSeasonMembership.js +18 -0
  13. package/dist/getters/getSeasonSettings.d.ts +8 -0
  14. package/dist/getters/getSeasonSettings.js +18 -0
  15. package/dist/getters/getUserStats.js +3 -10
  16. package/dist/getters/getUserWindowParticipation.d.ts +9 -0
  17. package/dist/getters/getUserWindowParticipation.js +20 -0
  18. package/dist/getters/index.d.ts +6 -0
  19. package/dist/getters/index.js +6 -0
  20. package/dist/idl/idl.d.ts +5 -0
  21. package/dist/idl/idl.js +5 -1
  22. package/dist/index.d.ts +5 -0
  23. package/dist/index.js +3 -0
  24. package/dist/instructions/claimReferralPenaltyForWindow.d.ts +17 -14
  25. package/dist/instructions/claimReferralPenaltyForWindow.js +7 -4
  26. package/dist/instructions/claimWindowRewards.d.ts +14 -10
  27. package/dist/instructions/claimWindowRewards.js +6 -3
  28. package/dist/instructions/closeAuxiliaryAccounts.d.ts +8 -26
  29. package/dist/instructions/confirmedPostOnX.d.ts +14 -11
  30. package/dist/instructions/confirmedPostOnX.js +8 -3
  31. package/dist/instructions/createMiztake.d.ts +25 -28
  32. package/dist/instructions/createMiztake.js +12 -9
  33. package/dist/instructions/initializeEscrowVault.d.ts +5 -9
  34. package/dist/instructions/initializeSeasonSettings.d.ts +5 -9
  35. package/dist/instructions/initializeSeasonVault.d.ts +5 -9
  36. package/dist/instructions/initializeStatistics.d.ts +6 -7
  37. package/dist/instructions/initializeStatistics.js +12 -8
  38. package/dist/instructions/joinSeason.d.ts +18 -20
  39. package/dist/instructions/joinSeason.js +2 -1
  40. package/dist/instructions/toggleSeasonPause.d.ts +7 -9
  41. package/dist/instructions/toggleSeasonPause.js +1 -0
  42. package/dist/instructions/updateSeasonAdmin.d.ts +7 -9
  43. package/dist/instructions/updateSeasonAdmin.js +1 -0
  44. package/dist/instructions/viewSeasonMembershipStatus.d.ts +2 -2
  45. package/dist/instructions/viewWindowStatus.d.ts +2 -2
  46. package/dist/instructions/viewWindowStatus.js +3 -1
  47. package/dist/instructions/withdrawSeasonDeposit.d.ts +2 -2
  48. package/dist/types/anchorAccounts.d.ts +18 -0
  49. package/dist/types/anchorAccounts.js +2 -0
  50. package/dist/types/anchorViews.d.ts +11 -0
  51. package/dist/types/anchorViews.js +2 -0
  52. package/dist/types/instructionResults.d.ts +18 -19
  53. package/dist/types.d.ts +53 -5
  54. package/dist/utils/accountConverters.d.ts +19 -0
  55. package/dist/utils/accountConverters.js +153 -0
  56. package/dist/utils/accountUpdates.d.ts +3 -3
  57. package/dist/utils/accountUpdates.js +40 -31
  58. package/dist/utils/conversions.d.ts +21 -1
  59. package/dist/utils/conversions.js +57 -9
  60. package/dist/utils/depositTier.d.ts +3 -0
  61. package/dist/utils/depositTier.js +21 -0
  62. package/dist/utils/enumHelpers.d.ts +5 -13
  63. package/dist/utils/enumHelpers.js +8 -0
  64. package/dist/utils/fetchAccount.d.ts +11 -0
  65. package/dist/utils/fetchAccount.js +23 -0
  66. package/dist/utils/index.js +1 -0
  67. package/dist/utils/pdaManager.d.ts +15 -14
  68. package/dist/utils/pdaManager.js +33 -26
  69. package/dist/utils/pdas.d.ts +9 -8
  70. package/dist/utils/pdas.js +24 -20
  71. package/dist/utils/programHelpers.js +1 -1
  72. package/dist/utils/signerHelpers.d.ts +2 -1
  73. package/dist/utils/simulationHelpers.js +7 -6
  74. package/dist/utils/tierPenalty.d.ts +2 -2
  75. package/dist/utils/tierPenalty.js +13 -11
  76. package/dist/utils/transactionBuilder.js +9 -7
  77. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { BN } from "@coral-xyz/anchor";
2
2
  import { Connection, PublicKey } from "@solana/web3.js";
3
- import { SeasonSettings, Season, SeasonMembership } from "../types";
3
+ import { SeasonSettings, Season, SeasonMembership, TierNumber } from "../types";
4
4
  import { StandardInstructionResult } from "../types/instructionResults";
5
5
  type WithdrawSeasonDepositUpdatedAccounts = {
6
6
  seasonSettings?: SeasonSettings;
@@ -16,7 +16,7 @@ export interface WithdrawSeasonDepositOptions {
16
16
  userTokenAccount: PublicKey;
17
17
  seasonNumber: BN;
18
18
  /** Tier number: 1=copper, 2=silver, 3=gold, 4=platinum, 5=mithril */
19
- tier: number;
19
+ tier: TierNumber;
20
20
  feePayer?: PublicKey;
21
21
  currentAccounts?: {
22
22
  seasonSettings?: SeasonSettings;
@@ -0,0 +1,18 @@
1
+ import type { IdlAccounts } from "@coral-xyz/anchor";
2
+ import type { ProofOfTake } from "./proof_of_take";
3
+ /**
4
+ * Anchor-decoded on-chain account types derived from the IDL.
5
+ *
6
+ * Use these when dealing with `program.account.*.fetch()` results.
7
+ * (They reflect the exact current IDL, so drift is caught at compile time.)
8
+ */
9
+ export type ProofOfTakeIdlAccounts = IdlAccounts<ProofOfTake>;
10
+ export type AnchorMiztake = ProofOfTakeIdlAccounts["miztake"];
11
+ export type AnchorMiztakeStatistics = ProofOfTakeIdlAccounts["miztakeStatistics"];
12
+ export type AnchorUserStats = ProofOfTakeIdlAccounts["userStats"];
13
+ export type AnchorSeasonSettings = ProofOfTakeIdlAccounts["seasonSettings"];
14
+ export type AnchorSeason = ProofOfTakeIdlAccounts["season"];
15
+ export type AnchorSeasonMembership = ProofOfTakeIdlAccounts["seasonMembership"];
16
+ export type AnchorRewardWindow = ProofOfTakeIdlAccounts["rewardWindow"];
17
+ export type AnchorUserWindowParticipation = ProofOfTakeIdlAccounts["userWindowParticipation"];
18
+ export type AnchorReferralPenaltyClaim = ProofOfTakeIdlAccounts["referralPenaltyClaim"];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import type { IdlTypes } from "@coral-xyz/anchor";
2
+ import type { ProofOfTake } from "./proof_of_take";
3
+ /**
4
+ * Anchor `.view()` return struct types derived from the IDL.
5
+ *
6
+ * Use these for `program.methods.*.view()` results.
7
+ */
8
+ export type ProofOfTakeIdlTypes = IdlTypes<ProofOfTake>;
9
+ export type AnchorCurrentSeasonView = ProofOfTakeIdlTypes["currentSeasonView"];
10
+ export type AnchorSeasonMembershipStatusView = ProofOfTakeIdlTypes["seasonMembershipStatusView"];
11
+ export type AnchorWindowStatusView = ProofOfTakeIdlTypes["windowStatusView"];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -12,7 +12,7 @@ export interface InstructionResult {
12
12
  * Standard instruction result with PDAs and optional updated accounts
13
13
  * This is the unified return type for all instructions
14
14
  */
15
- export interface StandardInstructionResult<TPdas extends Record<string, PublicKey> = Record<string, PublicKey>, TAccounts = Record<string, unknown>, TMeta = Record<string, unknown>> extends InstructionResult {
15
+ export interface StandardInstructionResult<TPdas extends Record<string, PublicKey> = Record<string, PublicKey>, TAccounts = never, TMeta = never> extends InstructionResult {
16
16
  /** Program-derived addresses created or used by this instruction */
17
17
  pdas?: TPdas;
18
18
  /** Optimistically updated account states (if current accounts were provided) */
@@ -21,24 +21,23 @@ export interface StandardInstructionResult<TPdas extends Record<string, PublicKe
21
21
  metadata?: TMeta;
22
22
  }
23
23
  /**
24
- * Legacy: Instruction result with PDA addresses
25
- * @deprecated Use StandardInstructionResult instead
24
+ * Helper type: same as StandardInstructionResult, but with required `pdas`.
25
+ * (Most instruction builders always compute/return their PDAs.)
26
26
  */
27
- export interface InstructionResultWithPdas extends InstructionResult {
28
- pdas: Record<string, PublicKey>;
29
- }
27
+ export type StandardInstructionResultWithPdas<TPdas extends Record<string, PublicKey>, TAccounts = never, TMeta = never> = StandardInstructionResult<TPdas, TAccounts, TMeta> & {
28
+ pdas: TPdas;
29
+ };
30
30
  /**
31
- * Legacy: Instruction result with optimistically updated accounts
32
- * @deprecated Use StandardInstructionResult instead
31
+ * Helper type: required `pdas` and required `updatedAccounts`.
32
+ * (Used by builders that always provide optimistic updates, like createMiztake.)
33
33
  */
34
- export interface InstructionResultWithAccounts<T = Record<string, unknown>> extends InstructionResult {
35
- updatedAccounts?: T;
36
- }
37
- /**
38
- * Legacy: Full instruction result with both PDAs and updated accounts
39
- * @deprecated Use StandardInstructionResult instead
40
- */
41
- export interface FullInstructionResult<T = Record<string, unknown>> extends InstructionResult {
42
- pdas: Record<string, PublicKey>;
43
- updatedAccounts?: T;
44
- }
34
+ export type StandardInstructionResultWithPdasAndAccounts<TPdas extends Record<string, PublicKey>, TAccounts, TMeta = never> = StandardInstructionResult<TPdas, TAccounts, TMeta> & {
35
+ pdas: TPdas;
36
+ updatedAccounts: TAccounts;
37
+ };
38
+ /** @deprecated Use StandardInstructionResultWithPdas instead */
39
+ export type InstructionResultWithPdas = StandardInstructionResultWithPdas<Record<string, PublicKey>>;
40
+ /** @deprecated Use StandardInstructionResult instead */
41
+ export type InstructionResultWithAccounts<T = unknown> = StandardInstructionResult<Record<string, PublicKey>, T>;
42
+ /** @deprecated Use StandardInstructionResultWithPdas instead */
43
+ export type FullInstructionResult<T = unknown> = StandardInstructionResultWithPdas<Record<string, PublicKey>, T>;
package/dist/types.d.ts CHANGED
@@ -4,6 +4,35 @@ import { BN } from "@coral-xyz/anchor";
4
4
  * Type definitions for Proof of Take SDK
5
5
  */
6
6
  export type { ProofOfTake } from "./types/proof_of_take";
7
+ export type { ProofOfTakeIdlAccounts, AnchorMiztake, AnchorMiztakeStatistics, AnchorUserStats, AnchorSeasonSettings, AnchorSeason, AnchorSeasonMembership, AnchorRewardWindow, AnchorUserWindowParticipation, AnchorReferralPenaltyClaim, } from "./types/anchorAccounts";
8
+ export type { ProofOfTakeIdlTypes, AnchorCurrentSeasonView, AnchorSeasonMembershipStatusView, AnchorWindowStatusView, } from "./types/anchorViews";
9
+ /**
10
+ * Helper for Anchor "unit enum" variants.
11
+ *
12
+ * Anchor represents enums as an object with a single key, e.g. `{ active: {} }`.
13
+ */
14
+ type AnchorEnumVariant<K extends string> = {
15
+ [P in K]: Record<string, never>;
16
+ };
17
+ /**
18
+ * Tier number used across the program (and PDA seeds).
19
+ * 1=copper, 2=silver, 3=gold, 4=platinum, 5=mithril
20
+ */
21
+ export type TierNumber = 1 | 2 | 3 | 4 | 5;
22
+ /**
23
+ * Branded types for common on-chain invariants.
24
+ */
25
+ export type Sha256HexString = string & {
26
+ readonly __brand: "Sha256HexString";
27
+ };
28
+ export type Bytes32 = Uint8Array & {
29
+ readonly __brand: "Bytes32";
30
+ };
31
+ /** Window index within a season schedule (0..20) */
32
+ export type WindowIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20;
33
+ export type WindowNumberLike = BN | WindowIndex;
34
+ export type DepositTierName = "copper" | "silver" | "gold" | "platinum" | "mithril";
35
+ export type SeasonNumberLike = BN | number;
7
36
  export interface CreateMiztakeParams {
8
37
  telegramId: BN;
9
38
  telegramUsername: string;
@@ -11,7 +40,8 @@ export interface CreateMiztakeParams {
11
40
  averageHash: string;
12
41
  differenceHash: string;
13
42
  waveletHash: string;
14
- shaHash: string;
43
+ /** Accepts either a validated branded hash or a raw 64-char hex string (will be normalized). */
44
+ shaHash: Sha256HexString | string;
15
45
  computedAt: string;
16
46
  }
17
47
  export interface ClaimRewardParams {
@@ -51,7 +81,7 @@ export interface Miztake {
51
81
  averageHash: string;
52
82
  differenceHash: string;
53
83
  waveletHash: string;
54
- shaHash: string;
84
+ shaHash: Sha256HexString;
55
85
  computedAt: string;
56
86
  creator: PublicKey;
57
87
  userStats: PublicKey;
@@ -70,6 +100,14 @@ export declare enum WindowState {
70
100
  Active = 1,
71
101
  Finalized = 2
72
102
  }
103
+ /**
104
+ * Anchor enum formats returned by account fetches.
105
+ * We accept both the SDK numeric enums and Anchor object enums throughout the SDK.
106
+ */
107
+ export type SeasonStateAnchor = AnchorEnumVariant<"uninitialized"> | AnchorEnumVariant<"active"> | AnchorEnumVariant<"ended">;
108
+ export type WindowStateAnchor = AnchorEnumVariant<"uninitialized"> | AnchorEnumVariant<"active"> | AnchorEnumVariant<"finalized">;
109
+ export type SeasonStateLike = SeasonState | SeasonStateAnchor | number;
110
+ export type WindowStateLike = WindowState | WindowStateAnchor | number;
73
111
  /**
74
112
  * Season deposit tier (Anchor enum representation)
75
113
  *
@@ -87,6 +125,15 @@ export type SeasonDepositTier = {
87
125
  } | {
88
126
  mithril: Record<string, never>;
89
127
  };
128
+ /**
129
+ * Fixed-length array helper for on-chain fixed-size arrays.
130
+ * (Used to tighten `[u64; 21]` schedule fields without forcing tuple literals everywhere.)
131
+ */
132
+ export type FixedLengthArray<T, N extends number> = T[] & {
133
+ length: N;
134
+ };
135
+ /** On-chain `eligible_stake_per_window: [u64; 21]` */
136
+ export type EligibleStakePerWindow = FixedLengthArray<BN, 21>;
90
137
  export interface SeasonSettings {
91
138
  completedSeasons: BN;
92
139
  seasonDuration: BN;
@@ -102,7 +149,7 @@ export interface SeasonSettings {
102
149
  }
103
150
  export interface Season {
104
151
  seasonNumber: BN;
105
- seasonState: SeasonState;
152
+ seasonState: SeasonStateLike;
106
153
  startedAt: BN;
107
154
  endsAt: BN;
108
155
  totalWindows: number;
@@ -112,10 +159,11 @@ export interface Season {
112
159
  goldMembersCount: BN;
113
160
  platinumMembersCount: BN;
114
161
  mithrilMembersCount: BN;
115
- eligibleStakePerWindow: BN[];
162
+ eligibleStakePerWindow: EligibleStakePerWindow;
116
163
  totalDepositsHeld: BN;
117
164
  totalSuccessfulPosts: BN;
118
165
  totalPenaltiesCollected: BN;
166
+ totalUnallocatedFunds: BN;
119
167
  bump: number;
120
168
  }
121
169
  export interface SeasonMembership {
@@ -139,7 +187,7 @@ export interface SeasonMembership {
139
187
  export interface RewardWindow {
140
188
  seasonNumber: BN;
141
189
  windowNumber: BN;
142
- windowState: WindowState;
190
+ windowState: WindowStateLike;
143
191
  startedAt: BN;
144
192
  endsAt: BN;
145
193
  totalMembersInSeason: BN;
@@ -0,0 +1,19 @@
1
+ import { BN } from "@coral-xyz/anchor";
2
+ import type { EligibleStakePerWindow, Miztake, MiztakeStatistics, ReferralPenaltyClaim, RewardWindow, Season, SeasonMembership, SeasonSettings, UserStats, UserWindowParticipation } from "../types";
3
+ import type { AnchorMiztake, AnchorMiztakeStatistics, AnchorReferralPenaltyClaim, AnchorRewardWindow, AnchorSeason, AnchorSeasonMembership, AnchorSeasonSettings, AnchorUserStats, AnchorUserWindowParticipation } from "../types";
4
+ /**
5
+ * Converters from Anchor-decoded account shapes (IDL-derived) to SDK-facing types.
6
+ *
7
+ * Why: it centralizes any representation differences (e.g. fixed arrays, enums),
8
+ * and makes IDL/account drift surface as compile errors in one place.
9
+ */
10
+ export declare function toSdkMiztake(a: AnchorMiztake): Miztake;
11
+ export declare function toSdkMiztakeStatistics(a: AnchorMiztakeStatistics): MiztakeStatistics;
12
+ export declare function toSdkUserStats(a: AnchorUserStats): UserStats;
13
+ export declare function toSdkSeasonSettings(a: AnchorSeasonSettings): SeasonSettings;
14
+ export declare function toSdkSeason(a: AnchorSeason): Season;
15
+ export declare function toSdkSeasonMembership(a: AnchorSeasonMembership): SeasonMembership;
16
+ export declare function toSdkRewardWindow(a: AnchorRewardWindow): RewardWindow;
17
+ export declare function toSdkUserWindowParticipation(a: AnchorUserWindowParticipation): UserWindowParticipation;
18
+ export declare function toSdkReferralPenaltyClaim(a: AnchorReferralPenaltyClaim): ReferralPenaltyClaim;
19
+ export declare function getEligibleStakeAtIndex(eligibleStakePerWindow: EligibleStakePerWindow, idx: number): BN;
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toSdkMiztake = toSdkMiztake;
4
+ exports.toSdkMiztakeStatistics = toSdkMiztakeStatistics;
5
+ exports.toSdkUserStats = toSdkUserStats;
6
+ exports.toSdkSeasonSettings = toSdkSeasonSettings;
7
+ exports.toSdkSeason = toSdkSeason;
8
+ exports.toSdkSeasonMembership = toSdkSeasonMembership;
9
+ exports.toSdkRewardWindow = toSdkRewardWindow;
10
+ exports.toSdkUserWindowParticipation = toSdkUserWindowParticipation;
11
+ exports.toSdkReferralPenaltyClaim = toSdkReferralPenaltyClaim;
12
+ exports.getEligibleStakeAtIndex = getEligibleStakeAtIndex;
13
+ const anchor_1 = require("@coral-xyz/anchor");
14
+ const conversions_1 = require("./conversions");
15
+ /**
16
+ * Converters from Anchor-decoded account shapes (IDL-derived) to SDK-facing types.
17
+ *
18
+ * Why: it centralizes any representation differences (e.g. fixed arrays, enums),
19
+ * and makes IDL/account drift surface as compile errors in one place.
20
+ */
21
+ function toSdkMiztake(a) {
22
+ return {
23
+ id: a.id,
24
+ telegramId: a.telegramId,
25
+ telegramUsername: a.telegramUsername,
26
+ perceptualHash: a.perceptualHash,
27
+ averageHash: a.averageHash,
28
+ differenceHash: a.differenceHash,
29
+ waveletHash: a.waveletHash,
30
+ shaHash: (0, conversions_1.toSha256HexString)(a.shaHash),
31
+ computedAt: a.computedAt,
32
+ creator: a.creator,
33
+ userStats: a.userStats,
34
+ userKey: a.userKey,
35
+ onchainCreatedAt: a.onchainCreatedAt,
36
+ usedInSeason: a.usedInSeason,
37
+ usedInWindow: a.usedInWindow,
38
+ };
39
+ }
40
+ function toSdkMiztakeStatistics(a) {
41
+ return {
42
+ totalMiztakes: a.totalMiztakes,
43
+ bump: a.bump,
44
+ };
45
+ }
46
+ function toSdkUserStats(a) {
47
+ return {
48
+ telegramId: a.telegramId,
49
+ totalNumberOfMiztakes: a.totalNumberOfMiztakes,
50
+ onchainFirstMiztakeAt: a.onchainFirstMiztakeAt,
51
+ onchainLastMiztakeAt: a.onchainLastMiztakeAt,
52
+ bump: a.bump,
53
+ };
54
+ }
55
+ function toSdkSeasonSettings(a) {
56
+ return {
57
+ completedSeasons: a.completedSeasons,
58
+ seasonDuration: a.seasonDuration,
59
+ windowDuration: a.windowDuration,
60
+ totalWindowsPerSeason: a.totalWindowsPerSeason,
61
+ canInitializeNextSeason: a.canInitializeNextSeason,
62
+ lastSeasonEndsAt: a.lastSeasonEndsAt,
63
+ currentSeasonNumber: a.currentSeasonNumber,
64
+ admin: a.admin,
65
+ isPaused: a.isPaused,
66
+ maxMembersPerSeason: a.maxMembersPerSeason,
67
+ bump: a.bump,
68
+ };
69
+ }
70
+ function toSdkSeason(a) {
71
+ const eligibleStakePerWindow = (0, conversions_1.toEligibleStakePerWindow)(a.eligibleStakePerWindow);
72
+ return {
73
+ seasonNumber: a.seasonNumber,
74
+ seasonState: a.seasonState,
75
+ startedAt: a.startedAt,
76
+ endsAt: a.endsAt,
77
+ totalWindows: a.totalWindows,
78
+ totalMembers: a.totalMembers,
79
+ copperMembersCount: a.copperMembersCount,
80
+ silverMembersCount: a.silverMembersCount,
81
+ goldMembersCount: a.goldMembersCount,
82
+ platinumMembersCount: a.platinumMembersCount,
83
+ mithrilMembersCount: a.mithrilMembersCount,
84
+ eligibleStakePerWindow,
85
+ totalDepositsHeld: a.totalDepositsHeld,
86
+ totalSuccessfulPosts: a.totalSuccessfulPosts,
87
+ totalPenaltiesCollected: a.totalPenaltiesCollected,
88
+ totalUnallocatedFunds: a.totalUnallocatedFunds,
89
+ bump: a.bump,
90
+ };
91
+ }
92
+ function toSdkSeasonMembership(a) {
93
+ return {
94
+ owner: a.owner,
95
+ referrer: a.referrer,
96
+ seasonNumber: a.seasonNumber,
97
+ depositTier: a.depositTier,
98
+ depositAmount: a.depositAmount,
99
+ depositEscrowedAmount: a.depositEscrowedAmount,
100
+ joinedAt: a.joinedAt,
101
+ joinedWindowNumber: a.joinedWindowNumber,
102
+ successfulPostsCount: a.successfulPostsCount,
103
+ totalRewardsClaimed: a.totalRewardsClaimed,
104
+ totalPenaltiesPaid: a.totalPenaltiesPaid,
105
+ depositWithdrawn: a.depositWithdrawn,
106
+ isActive: a.isActive,
107
+ bump: a.bump,
108
+ };
109
+ }
110
+ function toSdkRewardWindow(a) {
111
+ return {
112
+ seasonNumber: a.seasonNumber,
113
+ windowNumber: a.windowNumber,
114
+ windowState: a.windowState,
115
+ startedAt: a.startedAt,
116
+ endsAt: a.endsAt,
117
+ totalMembersInSeason: a.totalMembersInSeason,
118
+ penaltyPool: a.penaltyPool,
119
+ successfulPostersCount: a.successfulPostersCount,
120
+ successfulStakeTotal: a.successfulStakeTotal,
121
+ rewardPerPoster: a.rewardPerPoster,
122
+ isFinalized: a.isFinalized,
123
+ bump: a.bump,
124
+ };
125
+ }
126
+ function toSdkUserWindowParticipation(a) {
127
+ return {
128
+ user: a.user,
129
+ seasonNumber: a.seasonNumber,
130
+ windowNumber: a.windowNumber,
131
+ postedSuccessfully: a.postedSuccessfully,
132
+ claimedReward: a.claimedReward,
133
+ rewardAmount: a.rewardAmount,
134
+ miztakeId: a.miztakeId,
135
+ bump: a.bump,
136
+ };
137
+ }
138
+ function toSdkReferralPenaltyClaim(a) {
139
+ return {
140
+ referredUser: a.referredUser,
141
+ seasonNumber: a.seasonNumber,
142
+ windowNumber: a.windowNumber,
143
+ claimant: a.claimant,
144
+ amount: a.amount,
145
+ claimedAt: a.claimedAt,
146
+ claimed: a.claimed,
147
+ bump: a.bump,
148
+ };
149
+ }
150
+ // Convenience for `[u64; 21]` arithmetic call sites
151
+ function getEligibleStakeAtIndex(eligibleStakePerWindow, idx) {
152
+ return eligibleStakePerWindow[idx] ?? new anchor_1.BN(0);
153
+ }
@@ -1,6 +1,6 @@
1
1
  import { BN } from "@coral-xyz/anchor";
2
2
  import { PublicKey } from "@solana/web3.js";
3
- import { Miztake, UserStats, MiztakeStatistics, SeasonSettings, Season, SeasonMembership, RewardWindow, UserWindowParticipation, SeasonDepositTier, ReferralPenaltyClaim } from "../types";
3
+ import { Miztake, UserStats, MiztakeStatistics, SeasonSettings, Season, SeasonMembership, RewardWindow, UserWindowParticipation, SeasonDepositTier, ReferralPenaltyClaim, TierNumber } from "../types";
4
4
  /**
5
5
  * Get current Unix timestamp in SECONDS as BN
6
6
  *
@@ -98,7 +98,7 @@ export declare function updateMiztakeStatisticsForCreation(statistics: MiztakeSt
98
98
  * @param miztakeId - The miztake ID to associate
99
99
  * @returns Initialized/Updated UserWindowParticipation object
100
100
  */
101
- export declare function initializeUserWindowParticipation(user: PublicKey, seasonNumber: BN, windowNumber: BN, tier: number, miztakeId: BN): UserWindowParticipation;
101
+ export declare function initializeUserWindowParticipation(user: PublicKey, seasonNumber: BN, windowNumber: BN, tier: TierNumber, miztakeId: BN): UserWindowParticipation;
102
102
  /**
103
103
  * Initialize RewardWindow
104
104
  * Mirrors the logic from season_helpers::initialize_window
@@ -234,7 +234,7 @@ export declare function initializeReferralPenaltyClaim(params: {
234
234
  referredUser: PublicKey;
235
235
  seasonNumber: BN;
236
236
  windowNumber: BN;
237
- tier: number;
237
+ tier: TierNumber;
238
238
  claimant: PublicKey;
239
239
  perWindowPenalty: BN;
240
240
  claimedAt?: BN;
@@ -24,7 +24,9 @@ exports.updateSeasonSettingsForPauseToggle = updateSeasonSettingsForPauseToggle;
24
24
  exports.updateSeasonSettingsForAdminUpdate = updateSeasonSettingsForAdminUpdate;
25
25
  const anchor_1 = require("@coral-xyz/anchor");
26
26
  const types_1 = require("../types");
27
+ const depositTier_1 = require("./depositTier");
27
28
  const tierPenalty_1 = require("./tierPenalty");
29
+ const conversions_1 = require("./conversions");
28
30
  const pdas_1 = require("./pdas");
29
31
  const enumHelpers_1 = require("./enumHelpers");
30
32
  /**
@@ -89,6 +91,7 @@ function expectedToBeLazyInitialized(params) {
89
91
  totalDepositsHeld: new anchor_1.BN(0),
90
92
  totalSuccessfulPosts: new anchor_1.BN(0),
91
93
  totalPenaltiesCollected: new anchor_1.BN(0),
94
+ totalUnallocatedFunds: new anchor_1.BN(0),
92
95
  bump,
93
96
  };
94
97
  }
@@ -309,9 +312,9 @@ function updateSeasonForJoin(season, depositActive, depositTier, joinedWindowNum
309
312
  ? seasonLike.totalWindows
310
313
  : 21;
311
314
  const scheduleLen = existingSchedule?.length ?? inferredTotalWindows;
312
- const schedule = existingSchedule
315
+ const schedule = (existingSchedule
313
316
  ? existingSchedule.slice()
314
- : Array.from({ length: scheduleLen }, () => new anchor_1.BN(0));
317
+ : Array.from({ length: scheduleLen }, () => new anchor_1.BN(0)));
315
318
  const next = {
316
319
  ...season,
317
320
  totalMembers: season.totalMembers.add(new anchor_1.BN(1)),
@@ -319,7 +322,14 @@ function updateSeasonForJoin(season, depositActive, depositTier, joinedWindowNum
319
322
  eligibleStakePerWindow: schedule,
320
323
  };
321
324
  const perWindowStake = (0, tierPenalty_1.getTierPenaltyPerWindow)(depositTier);
322
- const startIdx = joinedWindowNumber.toNumber();
325
+ // Don't throw in optimistic flows if something is off; just skip schedule mutation.
326
+ let startIdx = scheduleLen; // default: no updates
327
+ try {
328
+ startIdx = (0, conversions_1.assertWindowIndex)(joinedWindowNumber);
329
+ }
330
+ catch {
331
+ startIdx = scheduleLen;
332
+ }
323
333
  const endExclusive = Math.min(inferredTotalWindows, next.eligibleStakePerWindow.length);
324
334
  // If inputs are out of range, don't try to mutate schedule (avoid throwing in optimistic path).
325
335
  const updatedSchedule = next.eligibleStakePerWindow.map((v, i) => {
@@ -331,34 +341,33 @@ function updateSeasonForJoin(season, depositActive, depositTier, joinedWindowNum
331
341
  ...next,
332
342
  eligibleStakePerWindow: updatedSchedule,
333
343
  };
334
- if ("copper" in depositTier)
335
- return {
336
- ...nextWithSchedule,
337
- copperMembersCount: season.copperMembersCount.add(new anchor_1.BN(1)),
338
- };
339
- if ("silver" in depositTier)
340
- return {
341
- ...nextWithSchedule,
342
- silverMembersCount: season.silverMembersCount.add(new anchor_1.BN(1)),
343
- };
344
- if ("gold" in depositTier)
345
- return {
346
- ...nextWithSchedule,
347
- goldMembersCount: season.goldMembersCount.add(new anchor_1.BN(1)),
348
- };
349
- if ("platinum" in depositTier)
350
- return {
351
- ...nextWithSchedule,
352
- platinumMembersCount: season.platinumMembersCount.add(new anchor_1.BN(1)),
353
- };
354
- if ("mithril" in depositTier)
355
- return {
356
- ...nextWithSchedule,
357
- mithrilMembersCount: season.mithrilMembersCount.add(new anchor_1.BN(1)),
358
- };
359
- return {
360
- ...nextWithSchedule,
361
- };
344
+ switch ((0, depositTier_1.getDepositTierName)(depositTier)) {
345
+ case "copper":
346
+ return {
347
+ ...nextWithSchedule,
348
+ copperMembersCount: season.copperMembersCount.add(new anchor_1.BN(1)),
349
+ };
350
+ case "silver":
351
+ return {
352
+ ...nextWithSchedule,
353
+ silverMembersCount: season.silverMembersCount.add(new anchor_1.BN(1)),
354
+ };
355
+ case "gold":
356
+ return {
357
+ ...nextWithSchedule,
358
+ goldMembersCount: season.goldMembersCount.add(new anchor_1.BN(1)),
359
+ };
360
+ case "platinum":
361
+ return {
362
+ ...nextWithSchedule,
363
+ platinumMembersCount: season.platinumMembersCount.add(new anchor_1.BN(1)),
364
+ };
365
+ case "mithril":
366
+ return {
367
+ ...nextWithSchedule,
368
+ mithrilMembersCount: season.mithrilMembersCount.add(new anchor_1.BN(1)),
369
+ };
370
+ }
362
371
  }
363
372
  /**
364
373
  * Update RewardWindow after post confirmation
@@ -1,4 +1,5 @@
1
1
  import { BN } from "@coral-xyz/anchor";
2
+ import type { Bytes32, Sha256HexString, EligibleStakePerWindow, WindowIndex, WindowNumberLike, SeasonNumberLike } from "../types";
2
3
  /**
3
4
  * Safely convert BN to number for u64 fields
4
5
  * Throws if the BN is larger than JavaScript's MAX_SAFE_INTEGER
@@ -22,4 +23,23 @@ export declare function bnToU64Safe(bn: BN): number | undefined;
22
23
  * IMPORTANT: The on-chain program uses the raw 32-byte digest as PDA seed
23
24
  * (`seeds = [b\"miztake\", sha_hash_bytes]`), NOT the ASCII prefix of the hex string.
24
25
  */
25
- export declare function sha256HexToBytes32(shaHex: string): Uint8Array;
26
+ export declare function toSha256HexString(shaHex: Sha256HexString): Sha256HexString;
27
+ export declare function toSha256HexString(shaHex: string): Sha256HexString;
28
+ export declare function isSha256HexString(value: unknown): value is Sha256HexString;
29
+ export declare function sha256HexToBytes32(shaHex: Sha256HexString | string): Bytes32;
30
+ /**
31
+ * Validate a window index (0..20).
32
+ * Accepts BN (u64) or number; returns a narrowed WindowIndex.
33
+ */
34
+ export declare function assertWindowIndex(value: BN | number): WindowIndex;
35
+ /**
36
+ * Normalize a window number-like input to BN and validate it's within 0..20.
37
+ */
38
+ export declare function toWindowNumberBn(value: WindowNumberLike): BN;
39
+ /**
40
+ * Runtime check + safe cast for the on-chain `[u64; 21]` schedule.
41
+ *
42
+ * This avoids `as unknown as ...` casts at call sites.
43
+ */
44
+ export declare function toEligibleStakePerWindow(value: readonly BN[]): EligibleStakePerWindow;
45
+ export declare function toSeasonNumberBn(value: SeasonNumberLike): BN;
@@ -2,7 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bnToU64 = bnToU64;
4
4
  exports.bnToU64Safe = bnToU64Safe;
5
+ exports.toSha256HexString = toSha256HexString;
6
+ exports.isSha256HexString = isSha256HexString;
5
7
  exports.sha256HexToBytes32 = sha256HexToBytes32;
8
+ exports.assertWindowIndex = assertWindowIndex;
9
+ exports.toWindowNumberBn = toWindowNumberBn;
10
+ exports.toEligibleStakePerWindow = toEligibleStakePerWindow;
11
+ exports.toSeasonNumberBn = toSeasonNumberBn;
6
12
  const anchor_1 = require("@coral-xyz/anchor");
7
13
  /**
8
14
  * Safely convert BN to number for u64 fields
@@ -31,23 +37,65 @@ function bnToU64Safe(bn) {
31
37
  }
32
38
  return bn.toNumber();
33
39
  }
34
- /**
35
- * Convert a 64-char SHA-256 hex string to a 32-byte Uint8Array.
36
- *
37
- * IMPORTANT: The on-chain program uses the raw 32-byte digest as PDA seed
38
- * (`seeds = [b\"miztake\", sha_hash_bytes]`), NOT the ASCII prefix of the hex string.
39
- */
40
- function sha256HexToBytes32(shaHex) {
40
+ function toSha256HexString(shaHex) {
41
41
  if (typeof shaHex !== "string") {
42
- throw new Error("sha256HexToBytes32: shaHex must be a string");
42
+ throw new Error("toSha256HexString: shaHex must be a string");
43
43
  }
44
44
  const normalized = shaHex.toLowerCase();
45
45
  if (!/^[0-9a-f]{64}$/.test(normalized)) {
46
- throw new Error("sha256HexToBytes32: expected 64-char lowercase hex string");
46
+ throw new Error("toSha256HexString: expected 64-char hex string");
47
47
  }
48
+ return normalized;
49
+ }
50
+ function isSha256HexString(value) {
51
+ return (typeof value === "string" &&
52
+ /^[0-9a-f]{64}$/.test(value.toLowerCase()));
53
+ }
54
+ function sha256HexToBytes32(shaHex) {
55
+ const normalized = typeof shaHex === "string" ? toSha256HexString(shaHex) : shaHex;
48
56
  const buf = Buffer.from(normalized, "hex");
49
57
  if (buf.length !== 32) {
50
58
  throw new Error("sha256HexToBytes32: decoded length != 32");
51
59
  }
52
60
  return new Uint8Array(buf);
53
61
  }
62
+ /**
63
+ * Validate a window index (0..20).
64
+ * Accepts BN (u64) or number; returns a narrowed WindowIndex.
65
+ */
66
+ function assertWindowIndex(value) {
67
+ const n = typeof value === "number"
68
+ ? value
69
+ : value.toNumber(); // safe: window index is small in this program
70
+ if (!Number.isInteger(n) || n < 0 || n > 20) {
71
+ throw new Error("Invalid window index: must be an integer between 0 and 20");
72
+ }
73
+ return n;
74
+ }
75
+ /**
76
+ * Normalize a window number-like input to BN and validate it's within 0..20.
77
+ */
78
+ function toWindowNumberBn(value) {
79
+ const bn = typeof value === "number" ? new anchor_1.BN(value) : value;
80
+ assertWindowIndex(bn);
81
+ return bn;
82
+ }
83
+ /**
84
+ * Runtime check + safe cast for the on-chain `[u64; 21]` schedule.
85
+ *
86
+ * This avoids `as unknown as ...` casts at call sites.
87
+ */
88
+ function toEligibleStakePerWindow(value) {
89
+ if (value.length !== 21) {
90
+ throw new Error(`Invalid eligibleStakePerWindow length: expected 21, got ${value.length}`);
91
+ }
92
+ // We intentionally cast after validation.
93
+ return value;
94
+ }
95
+ function toSeasonNumberBn(value) {
96
+ const bn = typeof value === "number" ? new anchor_1.BN(value) : value;
97
+ if (bn.isNeg()) {
98
+ throw new Error("Invalid season number: must be >= 0");
99
+ }
100
+ return bn;
101
+ }
@@ -0,0 +1,3 @@
1
+ import { DepositTierName, SeasonDepositTier } from "../types";
2
+ export declare function getDepositTierName(tier: SeasonDepositTier): DepositTierName;
3
+ export declare function isDepositTier(tier: SeasonDepositTier, name: DepositTierName): boolean;