proof-of-take-sdk 3.0.7 → 3.0.8

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 (48) hide show
  1. package/dist/idl/proof_of_take.json +132 -12
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/instructions/claimReferralPenaltyForWindow.d.ts +1 -1
  5. package/dist/instructions/claimReferralPenaltyForWindow.js +2 -1
  6. package/dist/instructions/claimWindowRewards.d.ts +1 -1
  7. package/dist/instructions/claimWindowRewards.js +2 -1
  8. package/dist/instructions/closeAuxiliaryAccounts.js +19 -12
  9. package/dist/instructions/confirmedPostOnX.d.ts +1 -1
  10. package/dist/instructions/confirmedPostOnX.js +5 -1
  11. package/dist/instructions/createMiztake.d.ts +1 -1
  12. package/dist/instructions/createMiztake.js +7 -3
  13. package/dist/instructions/initializeEscrowVault.js +5 -4
  14. package/dist/instructions/initializeRewardWindow.js +5 -4
  15. package/dist/instructions/initializeSeasonSettings.js +6 -7
  16. package/dist/instructions/initializeSeasonVault.js +6 -7
  17. package/dist/instructions/initializeStatistics.js +5 -5
  18. package/dist/instructions/joinSeason.d.ts +1 -1
  19. package/dist/instructions/joinSeason.js +20 -5
  20. package/dist/instructions/toggleSeasonPause.js +6 -7
  21. package/dist/instructions/updateSeasonAdmin.js +6 -7
  22. package/dist/instructions/viewSeasonMembershipStatus.d.ts +1 -1
  23. package/dist/instructions/viewSeasonMembershipStatus.js +1 -1
  24. package/dist/instructions/withdrawSeasonDeposit.d.ts +1 -1
  25. package/dist/instructions/withdrawSeasonDeposit.js +2 -1
  26. package/dist/types/accountTypes.d.ts +3 -0
  27. package/dist/types/proof_of_take.d.ts +132 -12
  28. package/dist/types.d.ts +4 -2
  29. package/dist/utils/accountConverters.js +1 -0
  30. package/dist/utils/accountUpdates.d.ts +3 -3
  31. package/dist/utils/accountUpdates.js +4 -3
  32. package/dist/utils/instructionResultHelpers.d.ts +7 -0
  33. package/dist/utils/instructionResultHelpers.js +9 -0
  34. package/dist/utils/pdas.d.ts +4 -4
  35. package/dist/utils/pdas.js +8 -7
  36. package/dist/utils/programErrors.d.ts +13 -0
  37. package/dist/utils/programErrors.js +47 -0
  38. package/dist/utils/remainingAccounts.d.ts +17 -0
  39. package/dist/utils/remainingAccounts.js +38 -0
  40. package/dist/utils/signerHelpers.d.ts +20 -0
  41. package/dist/utils/signerHelpers.js +64 -5
  42. package/dist/utils/tierPenalty.d.ts +2 -2
  43. package/dist/utils/tierPenalty.js +9 -9
  44. package/dist/utils/tierSeeds.d.ts +8 -0
  45. package/dist/utils/tierSeeds.js +14 -0
  46. package/dist/utils/transactionBuilder.d.ts +1 -0
  47. package/dist/utils/transactionBuilder.js +11 -9
  48. package/package.json +1 -1
@@ -7,6 +7,26 @@ export interface SignerInfo {
7
7
  publicKey: PublicKey;
8
8
  role: SignerRole;
9
9
  }
10
+ /**
11
+ * Resolve fee payer for this SDK.
12
+ *
13
+ * Policy:
14
+ * - If `feePayer` is provided, use it.
15
+ * - Else if an instruction-specific `admin` key is provided, use it.
16
+ * - Else fall back to global `ADMIN_PUBLIC_KEY`.
17
+ */
18
+ export declare function resolveFeePayer(params?: {
19
+ feePayer?: PublicKey | undefined;
20
+ admin?: PublicKey | undefined;
21
+ }): PublicKey;
22
+ /** Back-compat alias (admin pays by default). */
23
+ export declare function getDefaultFeePayer(feePayer?: PublicKey): PublicKey;
24
+ export declare const asAdminSigner: (publicKey: PublicKey) => SignerInfo;
25
+ export declare const asUserSigner: (publicKey: PublicKey) => SignerInfo;
26
+ export declare const asClaimantSigner: (publicKey: PublicKey) => SignerInfo;
27
+ export declare const asCurrentAdminSigner: (publicKey: PublicKey) => SignerInfo;
28
+ export declare const asFeePayerSigner: (publicKey: PublicKey) => SignerInfo;
29
+ export declare const asPayerSigner: (publicKey: PublicKey) => SignerInfo;
10
30
  /**
11
31
  * Build signers array with optional fee payer
12
32
  * Automatically deduplicates if fee payer is already in required signers
@@ -1,6 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asPayerSigner = exports.asFeePayerSigner = exports.asCurrentAdminSigner = exports.asClaimantSigner = exports.asUserSigner = exports.asAdminSigner = void 0;
4
+ exports.resolveFeePayer = resolveFeePayer;
5
+ exports.getDefaultFeePayer = getDefaultFeePayer;
3
6
  exports.buildSigners = buildSigners;
7
+ const constants_1 = require("./constants");
8
+ /**
9
+ * Resolve fee payer for this SDK.
10
+ *
11
+ * Policy:
12
+ * - If `feePayer` is provided, use it.
13
+ * - Else if an instruction-specific `admin` key is provided, use it.
14
+ * - Else fall back to global `ADMIN_PUBLIC_KEY`.
15
+ */
16
+ function resolveFeePayer(params) {
17
+ return params?.feePayer ?? params?.admin ?? constants_1.ADMIN_PUBLIC_KEY;
18
+ }
19
+ /** Back-compat alias (admin pays by default). */
20
+ function getDefaultFeePayer(feePayer) {
21
+ return resolveFeePayer({ feePayer });
22
+ }
23
+ // ---- Signer constructors (to avoid ad-hoc role strings) ----
24
+ const asAdminSigner = (publicKey) => ({
25
+ publicKey,
26
+ role: "admin",
27
+ });
28
+ exports.asAdminSigner = asAdminSigner;
29
+ const asUserSigner = (publicKey) => ({
30
+ publicKey,
31
+ role: "user",
32
+ });
33
+ exports.asUserSigner = asUserSigner;
34
+ const asClaimantSigner = (publicKey) => ({
35
+ publicKey,
36
+ role: "claimant",
37
+ });
38
+ exports.asClaimantSigner = asClaimantSigner;
39
+ const asCurrentAdminSigner = (publicKey) => ({
40
+ publicKey,
41
+ role: "currentAdmin",
42
+ });
43
+ exports.asCurrentAdminSigner = asCurrentAdminSigner;
44
+ const asFeePayerSigner = (publicKey) => ({
45
+ publicKey,
46
+ role: "feePayer",
47
+ });
48
+ exports.asFeePayerSigner = asFeePayerSigner;
49
+ const asPayerSigner = (publicKey) => ({
50
+ publicKey,
51
+ role: "payer",
52
+ });
53
+ exports.asPayerSigner = asPayerSigner;
4
54
  /**
5
55
  * Build signers array with optional fee payer
6
56
  * Automatically deduplicates if fee payer is already in required signers
@@ -11,11 +61,20 @@ exports.buildSigners = buildSigners;
11
61
  */
12
62
  function buildSigners(requiredSigners, feePayer) {
13
63
  const signers = [...requiredSigners];
14
- if (feePayer) {
15
- const alreadyIncluded = signers.some((s) => s.publicKey.equals(feePayer));
16
- if (!alreadyIncluded) {
17
- signers.push({ publicKey: feePayer, role: "feePayer" });
18
- }
64
+ if (!feePayer) {
65
+ return signers;
66
+ }
67
+ // If fee payer is already among required signers (e.g. admin), move that signer to the front
68
+ // while preserving its original role. This ensures builders that default to signers[0] will
69
+ // still behave correctly, and avoids requiring a separate "feePayer" wallet mapping.
70
+ const existingIdx = signers.findIndex((s) => s.publicKey.equals(feePayer));
71
+ if (existingIdx >= 0) {
72
+ const existing = signers.splice(existingIdx, 1)[0];
73
+ signers.unshift(existing);
74
+ return signers;
19
75
  }
76
+ // Otherwise, include an explicit fee payer signer (callers must provide a wallet for role "feePayer").
77
+ const role = feePayer.equals(constants_1.ADMIN_PUBLIC_KEY) ? "admin" : "feePayer";
78
+ signers.unshift({ publicKey: feePayer, role });
20
79
  return signers;
21
80
  }
@@ -1,11 +1,11 @@
1
1
  import { BN } from "@coral-xyz/anchor";
2
2
  import { SeasonDepositTier, TierNumber } from "../types";
3
3
  /**
4
- * Validate and normalize a tier number (1..=5).
4
+ * Validate and normalize a tier number (0..=4).
5
5
  */
6
6
  export declare function assertValidTierNumber(tier: number): TierNumber;
7
7
  /**
8
- * Convert numeric tier (1..=5) to the Anchor enum representation.
8
+ * Convert numeric tier (0..=4) to the Anchor enum representation.
9
9
  */
10
10
  export declare function tierNumberToDepositTier(tier: number): SeasonDepositTier;
11
11
  /**
@@ -6,28 +6,28 @@ exports.getTierPenaltyPerWindow = getTierPenaltyPerWindow;
6
6
  const anchor_1 = require("@coral-xyz/anchor");
7
7
  const depositTier_1 = require("./depositTier");
8
8
  /**
9
- * Validate and normalize a tier number (1..=5).
9
+ * Validate and normalize a tier number (0..=4).
10
10
  */
11
11
  function assertValidTierNumber(tier) {
12
- if (!Number.isInteger(tier) || tier < 1 || tier > 5) {
13
- throw new Error("Invalid tier: must be an integer between 1 and 5");
12
+ if (!Number.isInteger(tier) || tier < 0 || tier > 4) {
13
+ throw new Error("Invalid tier: must be an integer between 0 and 4");
14
14
  }
15
15
  return tier;
16
16
  }
17
17
  /**
18
- * Convert numeric tier (1..=5) to the Anchor enum representation.
18
+ * Convert numeric tier (0..=4) to the Anchor enum representation.
19
19
  */
20
20
  function tierNumberToDepositTier(tier) {
21
21
  switch (assertValidTierNumber(tier)) {
22
- case 1:
22
+ case 0:
23
23
  return { copper: {} };
24
- case 2:
24
+ case 1:
25
25
  return { silver: {} };
26
- case 3:
26
+ case 2:
27
27
  return { gold: {} };
28
- case 4:
28
+ case 3:
29
29
  return { platinum: {} };
30
- case 5:
30
+ case 4:
31
31
  return { mithril: {} };
32
32
  }
33
33
  // unreachable
@@ -0,0 +1,8 @@
1
+ import type { TierNumber } from "../types";
2
+ /**
3
+ * Canonical tier encoding used for PDA seeds across the program.
4
+ *
5
+ * IMPORTANT: The tier byte is part of PDA seeds for several accounts (e.g. SeasonMembership,
6
+ * UserWindowParticipation, ReferralPenaltyClaim). Changing this mapping changes addresses.
7
+ */
8
+ export declare function toTierSeedByte(tier: TierNumber): number;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toTierSeedByte = toTierSeedByte;
4
+ /**
5
+ * Canonical tier encoding used for PDA seeds across the program.
6
+ *
7
+ * IMPORTANT: The tier byte is part of PDA seeds for several accounts (e.g. SeasonMembership,
8
+ * UserWindowParticipation, ReferralPenaltyClaim). Changing this mapping changes addresses.
9
+ */
10
+ function toTierSeedByte(tier) {
11
+ // Currently the TierNumber union is already the canonical seed byte (0..4),
12
+ // but keeping this indirection makes future tier encoding changes a 1-line edit.
13
+ return tier;
14
+ }
@@ -35,6 +35,7 @@ export declare class TransactionBuilder {
35
35
  private connection;
36
36
  private wallets;
37
37
  constructor(connection: Connection, wallets: Map<string, WalletAdapter>);
38
+ private getFeePayerFromSigners;
38
39
  /**
39
40
  * Build a transaction from instructions
40
41
  */
@@ -12,6 +12,14 @@ class TransactionBuilder {
12
12
  this.connection = connection;
13
13
  this.wallets = wallets;
14
14
  }
15
+ getFeePayerFromSigners(signers) {
16
+ const explicit = signers.find((s) => s.role === "feePayer")?.publicKey;
17
+ const fallback = signers[0]?.publicKey;
18
+ if (!explicit && !fallback) {
19
+ throw new Error("At least one signer required");
20
+ }
21
+ return explicit ?? fallback;
22
+ }
15
23
  /**
16
24
  * Build a transaction from instructions
17
25
  */
@@ -60,11 +68,8 @@ class TransactionBuilder {
60
68
  * Build, sign, and send a transaction
61
69
  */
62
70
  async buildSignAndSend(instructions, signers, options) {
63
- // Determine fee payer (first signer by default)
64
- const feePayer = signers[0]?.publicKey;
65
- if (!feePayer) {
66
- throw new Error("At least one signer required");
67
- }
71
+ // Determine fee payer (explicit feePayer role preferred; else first signer)
72
+ const feePayer = this.getFeePayerFromSigners(signers);
68
73
  // Build transaction
69
74
  const transaction = await this.buildTransaction(instructions, feePayer, options);
70
75
  // Sign transaction
@@ -84,10 +89,7 @@ class TransactionBuilder {
84
89
  * Simulate a transaction without sending
85
90
  */
86
91
  async simulate(instructions, signers) {
87
- const feePayer = signers[0]?.publicKey;
88
- if (!feePayer) {
89
- throw new Error("At least one signer required for simulation");
90
- }
92
+ const feePayer = this.getFeePayerFromSigners(signers);
91
93
  const transaction = await this.buildTransaction(instructions, feePayer);
92
94
  try {
93
95
  const simulation = await this.connection.simulateTransaction(transaction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proof-of-take-sdk",
3
- "version": "3.0.7",
3
+ "version": "3.0.8",
4
4
  "description": "TypeScript SDK for Proof of Take Solana program",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",