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.
- package/dist/client.js +3 -3
- package/dist/getters/getMiztake.d.ts +2 -2
- package/dist/getters/getMiztake.js +2 -15
- package/dist/getters/getMiztakeStatistics.js +2 -2
- package/dist/getters/getReferralPenaltyClaim.d.ts +9 -0
- package/dist/getters/getReferralPenaltyClaim.js +20 -0
- package/dist/getters/getRewardWindow.d.ts +9 -0
- package/dist/getters/getRewardWindow.js +20 -0
- package/dist/getters/getSeason.d.ts +8 -0
- package/dist/getters/getSeason.js +20 -0
- package/dist/getters/getSeasonMembership.d.ts +9 -0
- package/dist/getters/getSeasonMembership.js +18 -0
- package/dist/getters/getSeasonSettings.d.ts +8 -0
- package/dist/getters/getSeasonSettings.js +18 -0
- package/dist/getters/getUserStats.js +3 -10
- package/dist/getters/getUserWindowParticipation.d.ts +9 -0
- package/dist/getters/getUserWindowParticipation.js +20 -0
- package/dist/getters/index.d.ts +6 -0
- package/dist/getters/index.js +6 -0
- package/dist/idl/idl.d.ts +5 -0
- package/dist/idl/idl.js +5 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3 -0
- package/dist/instructions/claimReferralPenaltyForWindow.d.ts +17 -14
- package/dist/instructions/claimReferralPenaltyForWindow.js +7 -4
- package/dist/instructions/claimWindowRewards.d.ts +14 -10
- package/dist/instructions/claimWindowRewards.js +6 -3
- package/dist/instructions/closeAuxiliaryAccounts.d.ts +8 -26
- package/dist/instructions/confirmedPostOnX.d.ts +14 -11
- package/dist/instructions/confirmedPostOnX.js +8 -3
- package/dist/instructions/createMiztake.d.ts +25 -28
- package/dist/instructions/createMiztake.js +12 -9
- package/dist/instructions/initializeEscrowVault.d.ts +5 -9
- package/dist/instructions/initializeSeasonSettings.d.ts +5 -9
- package/dist/instructions/initializeSeasonVault.d.ts +5 -9
- package/dist/instructions/initializeStatistics.d.ts +6 -7
- package/dist/instructions/initializeStatistics.js +12 -8
- package/dist/instructions/joinSeason.d.ts +18 -20
- package/dist/instructions/joinSeason.js +2 -1
- package/dist/instructions/toggleSeasonPause.d.ts +7 -9
- package/dist/instructions/toggleSeasonPause.js +1 -0
- package/dist/instructions/updateSeasonAdmin.d.ts +7 -9
- package/dist/instructions/updateSeasonAdmin.js +1 -0
- package/dist/instructions/viewSeasonMembershipStatus.d.ts +2 -2
- package/dist/instructions/viewWindowStatus.d.ts +2 -2
- package/dist/instructions/viewWindowStatus.js +3 -1
- package/dist/instructions/withdrawSeasonDeposit.d.ts +2 -2
- package/dist/types/anchorAccounts.d.ts +18 -0
- package/dist/types/anchorAccounts.js +2 -0
- package/dist/types/anchorViews.d.ts +11 -0
- package/dist/types/anchorViews.js +2 -0
- package/dist/types/instructionResults.d.ts +18 -19
- package/dist/types.d.ts +53 -5
- package/dist/utils/accountConverters.d.ts +19 -0
- package/dist/utils/accountConverters.js +153 -0
- package/dist/utils/accountUpdates.d.ts +3 -3
- package/dist/utils/accountUpdates.js +40 -31
- package/dist/utils/conversions.d.ts +21 -1
- package/dist/utils/conversions.js +57 -9
- package/dist/utils/depositTier.d.ts +3 -0
- package/dist/utils/depositTier.js +21 -0
- package/dist/utils/enumHelpers.d.ts +5 -13
- package/dist/utils/enumHelpers.js +8 -0
- package/dist/utils/fetchAccount.d.ts +11 -0
- package/dist/utils/fetchAccount.js +23 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/pdaManager.d.ts +15 -14
- package/dist/utils/pdaManager.js +33 -26
- package/dist/utils/pdas.d.ts +9 -8
- package/dist/utils/pdas.js +24 -20
- package/dist/utils/programHelpers.js +1 -1
- package/dist/utils/signerHelpers.d.ts +2 -1
- package/dist/utils/simulationHelpers.js +7 -6
- package/dist/utils/tierPenalty.d.ts +2 -2
- package/dist/utils/tierPenalty.js +13 -11
- package/dist/utils/transactionBuilder.js +9 -7
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDepositTierName = getDepositTierName;
|
|
4
|
+
exports.isDepositTier = isDepositTier;
|
|
5
|
+
function getDepositTierName(tier) {
|
|
6
|
+
if ("copper" in tier)
|
|
7
|
+
return "copper";
|
|
8
|
+
if ("silver" in tier)
|
|
9
|
+
return "silver";
|
|
10
|
+
if ("gold" in tier)
|
|
11
|
+
return "gold";
|
|
12
|
+
if ("platinum" in tier)
|
|
13
|
+
return "platinum";
|
|
14
|
+
if ("mithril" in tier)
|
|
15
|
+
return "mithril";
|
|
16
|
+
// Exhaustiveness fallback (should be unreachable if SeasonDepositTier stays in sync)
|
|
17
|
+
throw new Error("Unknown depositTier");
|
|
18
|
+
}
|
|
19
|
+
function isDepositTier(tier, name) {
|
|
20
|
+
return getDepositTierName(tier) === name;
|
|
21
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SeasonState, WindowState } from "../types";
|
|
1
|
+
import { SeasonState, WindowState, SeasonStateLike, WindowStateLike } from "../types";
|
|
2
2
|
/**
|
|
3
3
|
* Enum helper utilities
|
|
4
4
|
*
|
|
@@ -22,9 +22,7 @@ import { SeasonState, WindowState } from "../types";
|
|
|
22
22
|
* isSeasonState({ active: {} }, SeasonState.Active) // Anchor object
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export declare function isSeasonState(state: SeasonState
|
|
26
|
-
[key: string]: {};
|
|
27
|
-
} | number, variant: SeasonState): boolean;
|
|
25
|
+
export declare function isSeasonState(state: SeasonStateLike, variant: SeasonState): boolean;
|
|
28
26
|
/**
|
|
29
27
|
* Check if a WindowState matches a specific variant
|
|
30
28
|
*
|
|
@@ -40,24 +38,18 @@ export declare function isSeasonState(state: SeasonState | {
|
|
|
40
38
|
* isWindowState({ finalized: {} }, WindowState.Finalized)
|
|
41
39
|
* ```
|
|
42
40
|
*/
|
|
43
|
-
export declare function isWindowState(state: WindowState
|
|
44
|
-
[key: string]: {};
|
|
45
|
-
} | number, variant: WindowState): boolean;
|
|
41
|
+
export declare function isWindowState(state: WindowStateLike, variant: WindowState): boolean;
|
|
46
42
|
/**
|
|
47
43
|
* Normalize SeasonState to numeric format
|
|
48
44
|
*
|
|
49
45
|
* @param state - Season state in any format
|
|
50
46
|
* @returns Numeric representation (0=Uninitialized, 1=Active, 2=Ended)
|
|
51
47
|
*/
|
|
52
|
-
export declare function normalizeSeasonState(state:
|
|
53
|
-
[key: string]: {};
|
|
54
|
-
} | number): number;
|
|
48
|
+
export declare function normalizeSeasonState(state: SeasonStateLike): number;
|
|
55
49
|
/**
|
|
56
50
|
* Normalize WindowState to numeric format
|
|
57
51
|
*
|
|
58
52
|
* @param state - Window state in any format
|
|
59
53
|
* @returns Numeric representation (0=Uninitialized, 1=Active, 2=Finalized)
|
|
60
54
|
*/
|
|
61
|
-
export declare function normalizeWindowState(state:
|
|
62
|
-
[key: string]: {};
|
|
63
|
-
} | number): number;
|
|
55
|
+
export declare function normalizeWindowState(state: WindowStateLike): number;
|
|
@@ -39,6 +39,8 @@ function isSeasonState(state, variant) {
|
|
|
39
39
|
// Check if value is Anchor object format
|
|
40
40
|
if (typeof state === "object" && state !== null && !Array.isArray(state)) {
|
|
41
41
|
const key = Object.keys(state)[0];
|
|
42
|
+
if (!key)
|
|
43
|
+
return false;
|
|
42
44
|
return key === variantName;
|
|
43
45
|
}
|
|
44
46
|
// Otherwise compare numeric values
|
|
@@ -68,6 +70,8 @@ function isWindowState(state, variant) {
|
|
|
68
70
|
const variantName = variantMap[variant];
|
|
69
71
|
if (typeof state === "object" && state !== null && !Array.isArray(state)) {
|
|
70
72
|
const key = Object.keys(state)[0];
|
|
73
|
+
if (!key)
|
|
74
|
+
return false;
|
|
71
75
|
return key === variantName;
|
|
72
76
|
}
|
|
73
77
|
return state === variant;
|
|
@@ -86,6 +90,8 @@ function normalizeSeasonState(state) {
|
|
|
86
90
|
};
|
|
87
91
|
if (typeof state === "object" && state !== null && !Array.isArray(state)) {
|
|
88
92
|
const key = Object.keys(state)[0];
|
|
93
|
+
if (!key)
|
|
94
|
+
return -1;
|
|
89
95
|
return map[key] ?? -1;
|
|
90
96
|
}
|
|
91
97
|
return state;
|
|
@@ -104,6 +110,8 @@ function normalizeWindowState(state) {
|
|
|
104
110
|
};
|
|
105
111
|
if (typeof state === "object" && state !== null && !Array.isArray(state)) {
|
|
106
112
|
const key = Object.keys(state)[0];
|
|
113
|
+
if (!key)
|
|
114
|
+
return -1;
|
|
107
115
|
return map[key] ?? -1;
|
|
108
116
|
}
|
|
109
117
|
return state;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import type { PublicKey } from "@solana/web3.js";
|
|
3
|
+
/**
|
|
4
|
+
* Typed fetch helper: returns null if the account does not exist / can't be decoded.
|
|
5
|
+
* Keeps callers out of try/catch ladders.
|
|
6
|
+
*/
|
|
7
|
+
export declare function fetchAccountOrNull<T>(fetcher: (address: PublicKey) => Promise<T>, address: PublicKey): Promise<T | null>;
|
|
8
|
+
/**
|
|
9
|
+
* Convenience wrapper for Anchor `program.account.<name>.fetch`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function fetchProgramAccountOrNull<T>(program: Program, fetcher: (address: PublicKey) => Promise<T>, address: PublicKey): Promise<T | null>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchAccountOrNull = fetchAccountOrNull;
|
|
4
|
+
exports.fetchProgramAccountOrNull = fetchProgramAccountOrNull;
|
|
5
|
+
/**
|
|
6
|
+
* Typed fetch helper: returns null if the account does not exist / can't be decoded.
|
|
7
|
+
* Keeps callers out of try/catch ladders.
|
|
8
|
+
*/
|
|
9
|
+
async function fetchAccountOrNull(fetcher, address) {
|
|
10
|
+
try {
|
|
11
|
+
return await fetcher(address);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convenience wrapper for Anchor `program.account.<name>.fetch`.
|
|
19
|
+
*/
|
|
20
|
+
async function fetchProgramAccountOrNull(program, fetcher, address) {
|
|
21
|
+
void program; // keeps signature stable if we want to extend later
|
|
22
|
+
return await fetchAccountOrNull(fetcher, address);
|
|
23
|
+
}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
import type { SeasonNumberLike, Sha256HexString, TierNumber } from "../types";
|
|
3
4
|
/**
|
|
4
5
|
* PDA Manager for deriving related PDAs together
|
|
5
6
|
* Reduces boilerplate in instruction files
|
|
@@ -9,12 +10,12 @@ export declare class PDAManager {
|
|
|
9
10
|
* Derive all PDAs needed for create_miztake instruction
|
|
10
11
|
*/
|
|
11
12
|
static deriveMiztakePdas(params: {
|
|
12
|
-
shaHash: string;
|
|
13
|
+
shaHash: Sha256HexString | string;
|
|
13
14
|
telegramId: BN;
|
|
14
|
-
seasonNumber:
|
|
15
|
+
seasonNumber: SeasonNumberLike;
|
|
15
16
|
windowNumber: BN;
|
|
16
17
|
user: PublicKey;
|
|
17
|
-
tier:
|
|
18
|
+
tier: TierNumber;
|
|
18
19
|
}): {
|
|
19
20
|
miztake: PublicKey;
|
|
20
21
|
userStats: PublicKey;
|
|
@@ -30,8 +31,8 @@ export declare class PDAManager {
|
|
|
30
31
|
*/
|
|
31
32
|
static deriveJoinSeasonPdas(params: {
|
|
32
33
|
user: PublicKey;
|
|
33
|
-
seasonNumber:
|
|
34
|
-
tier:
|
|
34
|
+
seasonNumber: SeasonNumberLike;
|
|
35
|
+
tier: TierNumber;
|
|
35
36
|
}): {
|
|
36
37
|
seasonSettings: PublicKey;
|
|
37
38
|
season: PublicKey;
|
|
@@ -44,11 +45,11 @@ export declare class PDAManager {
|
|
|
44
45
|
*/
|
|
45
46
|
static deriveConfirmedPostPdas(params: {
|
|
46
47
|
user: PublicKey;
|
|
47
|
-
seasonNumber:
|
|
48
|
+
seasonNumber: SeasonNumberLike;
|
|
48
49
|
windowNumber: BN;
|
|
49
|
-
tier:
|
|
50
|
+
tier: TierNumber;
|
|
50
51
|
/** SHA-256 hex string (64 chars) */
|
|
51
|
-
miztakeShaHash: string;
|
|
52
|
+
miztakeShaHash: Sha256HexString | string;
|
|
52
53
|
}): {
|
|
53
54
|
seasonSettings: PublicKey;
|
|
54
55
|
seasonMembership: PublicKey;
|
|
@@ -62,9 +63,9 @@ export declare class PDAManager {
|
|
|
62
63
|
*/
|
|
63
64
|
static deriveClaimWindowRewardsPdas(params: {
|
|
64
65
|
user: PublicKey;
|
|
65
|
-
seasonNumber:
|
|
66
|
+
seasonNumber: SeasonNumberLike;
|
|
66
67
|
windowNumber: BN;
|
|
67
|
-
tier:
|
|
68
|
+
tier: TierNumber;
|
|
68
69
|
}): {
|
|
69
70
|
seasonSettings: PublicKey;
|
|
70
71
|
season: PublicKey;
|
|
@@ -78,8 +79,8 @@ export declare class PDAManager {
|
|
|
78
79
|
*/
|
|
79
80
|
static deriveWithdrawDepositPdas(params: {
|
|
80
81
|
user: PublicKey;
|
|
81
|
-
seasonNumber:
|
|
82
|
-
tier:
|
|
82
|
+
seasonNumber: SeasonNumberLike;
|
|
83
|
+
tier: TierNumber;
|
|
83
84
|
}): {
|
|
84
85
|
seasonSettings: PublicKey;
|
|
85
86
|
season: PublicKey;
|
|
@@ -92,9 +93,9 @@ export declare class PDAManager {
|
|
|
92
93
|
*/
|
|
93
94
|
static deriveClaimReferralPenaltyForWindowPdas(params: {
|
|
94
95
|
referredUser: PublicKey;
|
|
95
|
-
seasonNumber:
|
|
96
|
+
seasonNumber: SeasonNumberLike;
|
|
96
97
|
windowNumber: BN;
|
|
97
|
-
tier:
|
|
98
|
+
tier: TierNumber;
|
|
98
99
|
}): {
|
|
99
100
|
seasonSettings: PublicKey;
|
|
100
101
|
season: PublicKey;
|
package/dist/utils/pdaManager.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PDAManager = void 0;
|
|
4
|
+
const conversions_1 = require("./conversions");
|
|
4
5
|
const pdas_1 = require("./pdas");
|
|
5
6
|
/**
|
|
6
7
|
* PDA Manager for deriving related PDAs together
|
|
@@ -11,39 +12,42 @@ class PDAManager {
|
|
|
11
12
|
* Derive all PDAs needed for create_miztake instruction
|
|
12
13
|
*/
|
|
13
14
|
static deriveMiztakePdas(params) {
|
|
15
|
+
const seasonNumber = (0, conversions_1.toSeasonNumberBn)(params.seasonNumber);
|
|
14
16
|
return {
|
|
15
17
|
miztake: (0, pdas_1.getMiztakePda)(params.shaHash)[0],
|
|
16
18
|
userStats: (0, pdas_1.getUserStatsPda)(params.telegramId)[0],
|
|
17
19
|
miztakeStatistics: (0, pdas_1.getMiztakeStatisticsPda)()[0],
|
|
18
20
|
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
19
|
-
season: (0, pdas_1.getSeasonPda)(
|
|
20
|
-
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(
|
|
21
|
-
rewardWindow: (0, pdas_1.getRewardWindowPda)(
|
|
22
|
-
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(
|
|
21
|
+
season: (0, pdas_1.getSeasonPda)(seasonNumber)[0],
|
|
22
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(seasonNumber, params.user, params.tier)[0],
|
|
23
|
+
rewardWindow: (0, pdas_1.getRewardWindowPda)(seasonNumber, params.windowNumber)[0],
|
|
24
|
+
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(seasonNumber, params.user, params.tier, params.windowNumber)[0],
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Derive PDAs for join_season instruction
|
|
27
29
|
*/
|
|
28
30
|
static deriveJoinSeasonPdas(params) {
|
|
31
|
+
const seasonNumber = (0, conversions_1.toSeasonNumberBn)(params.seasonNumber);
|
|
29
32
|
return {
|
|
30
33
|
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
31
|
-
season: (0, pdas_1.getSeasonPda)(
|
|
32
|
-
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(
|
|
33
|
-
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)(
|
|
34
|
-
seasonEscrowVault: (0, pdas_1.getSeasonEscrowVaultPda)(
|
|
34
|
+
season: (0, pdas_1.getSeasonPda)(seasonNumber)[0],
|
|
35
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(seasonNumber, params.user, params.tier)[0],
|
|
36
|
+
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)(seasonNumber)[0],
|
|
37
|
+
seasonEscrowVault: (0, pdas_1.getSeasonEscrowVaultPda)(seasonNumber)[0],
|
|
35
38
|
};
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* Derive PDAs for confirmed_post_on_x instruction
|
|
39
42
|
*/
|
|
40
43
|
static deriveConfirmedPostPdas(params) {
|
|
44
|
+
const seasonNumber = (0, conversions_1.toSeasonNumberBn)(params.seasonNumber);
|
|
41
45
|
return {
|
|
42
46
|
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
43
|
-
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(
|
|
44
|
-
season: (0, pdas_1.getSeasonPda)(
|
|
45
|
-
rewardWindow: (0, pdas_1.getRewardWindowPda)(
|
|
46
|
-
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(
|
|
47
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(seasonNumber, params.user, params.tier)[0],
|
|
48
|
+
season: (0, pdas_1.getSeasonPda)(seasonNumber)[0],
|
|
49
|
+
rewardWindow: (0, pdas_1.getRewardWindowPda)(seasonNumber, params.windowNumber)[0],
|
|
50
|
+
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(seasonNumber, params.user, params.tier, params.windowNumber)[0],
|
|
47
51
|
miztake: (0, pdas_1.getMiztakePda)(params.miztakeShaHash)[0],
|
|
48
52
|
};
|
|
49
53
|
}
|
|
@@ -51,38 +55,41 @@ class PDAManager {
|
|
|
51
55
|
* Derive PDAs for claim_window_rewards instruction
|
|
52
56
|
*/
|
|
53
57
|
static deriveClaimWindowRewardsPdas(params) {
|
|
58
|
+
const seasonNumber = (0, conversions_1.toSeasonNumberBn)(params.seasonNumber);
|
|
54
59
|
return {
|
|
55
60
|
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
56
|
-
season: (0, pdas_1.getSeasonPda)(
|
|
57
|
-
rewardWindow: (0, pdas_1.getRewardWindowPda)(
|
|
58
|
-
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(
|
|
59
|
-
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(
|
|
60
|
-
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)(
|
|
61
|
+
season: (0, pdas_1.getSeasonPda)(seasonNumber)[0],
|
|
62
|
+
rewardWindow: (0, pdas_1.getRewardWindowPda)(seasonNumber, params.windowNumber)[0],
|
|
63
|
+
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(seasonNumber, params.user, params.tier, params.windowNumber)[0],
|
|
64
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(seasonNumber, params.user, params.tier)[0],
|
|
65
|
+
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)(seasonNumber)[0],
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
/**
|
|
64
69
|
* Derive PDAs for withdraw_season_deposit instruction
|
|
65
70
|
*/
|
|
66
71
|
static deriveWithdrawDepositPdas(params) {
|
|
72
|
+
const seasonNumber = (0, conversions_1.toSeasonNumberBn)(params.seasonNumber);
|
|
67
73
|
return {
|
|
68
74
|
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
69
|
-
season: (0, pdas_1.getSeasonPda)(
|
|
70
|
-
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(
|
|
71
|
-
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)(
|
|
72
|
-
seasonEscrowVault: (0, pdas_1.getSeasonEscrowVaultPda)(
|
|
75
|
+
season: (0, pdas_1.getSeasonPda)(seasonNumber)[0],
|
|
76
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(seasonNumber, params.user, params.tier)[0],
|
|
77
|
+
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)(seasonNumber)[0],
|
|
78
|
+
seasonEscrowVault: (0, pdas_1.getSeasonEscrowVaultPda)(seasonNumber)[0],
|
|
73
79
|
};
|
|
74
80
|
}
|
|
75
81
|
/**
|
|
76
82
|
* Derive PDAs for claim_referral_penalty_for_window instruction
|
|
77
83
|
*/
|
|
78
84
|
static deriveClaimReferralPenaltyForWindowPdas(params) {
|
|
85
|
+
const seasonNumber = (0, conversions_1.toSeasonNumberBn)(params.seasonNumber);
|
|
79
86
|
return {
|
|
80
87
|
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
81
|
-
season: (0, pdas_1.getSeasonPda)(
|
|
82
|
-
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(
|
|
83
|
-
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(
|
|
84
|
-
referralPenaltyClaim: (0, pdas_1.getReferralPenaltyClaimPda)(
|
|
85
|
-
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)(
|
|
88
|
+
season: (0, pdas_1.getSeasonPda)(seasonNumber)[0],
|
|
89
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(seasonNumber, params.referredUser, params.tier)[0],
|
|
90
|
+
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(seasonNumber, params.referredUser, params.tier, params.windowNumber)[0],
|
|
91
|
+
referralPenaltyClaim: (0, pdas_1.getReferralPenaltyClaimPda)(seasonNumber, params.referredUser, params.tier, params.windowNumber)[0],
|
|
92
|
+
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)(seasonNumber)[0],
|
|
86
93
|
};
|
|
87
94
|
}
|
|
88
95
|
}
|
package/dist/utils/pdas.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
import type { SeasonNumberLike, Sha256HexString, TierNumber } from "../types";
|
|
3
4
|
/**
|
|
4
5
|
* PDA (Program Derived Address) derivation helpers
|
|
5
6
|
*/
|
|
@@ -16,7 +17,7 @@ export declare function getUserStatsPda(telegramId: BN): [PublicKey, number];
|
|
|
16
17
|
* Derive the Miztake PDA for a given SHA hash
|
|
17
18
|
* @param shaHash - The SHA-256 hash as a 64-char hex string
|
|
18
19
|
*/
|
|
19
|
-
export declare function getMiztakePda(shaHash: string): [PublicKey, number];
|
|
20
|
+
export declare function getMiztakePda(shaHash: Sha256HexString | string): [PublicKey, number];
|
|
20
21
|
/**
|
|
21
22
|
* Derive the SeasonSettings PDA
|
|
22
23
|
*/
|
|
@@ -25,7 +26,7 @@ export declare function getSeasonSettingsPda(): [PublicKey, number];
|
|
|
25
26
|
* Derive the Season PDA for a given season number
|
|
26
27
|
* @param seasonNumber - The season number
|
|
27
28
|
*/
|
|
28
|
-
export declare function getSeasonPda(seasonNumber:
|
|
29
|
+
export declare function getSeasonPda(seasonNumber: SeasonNumberLike): [PublicKey, number];
|
|
29
30
|
/**
|
|
30
31
|
* Derive the SeasonMembership PDA
|
|
31
32
|
* PDA model:
|
|
@@ -38,13 +39,13 @@ export declare function getSeasonPda(seasonNumber: BN): [PublicKey, number];
|
|
|
38
39
|
* @param user - The user's public key
|
|
39
40
|
* @param tier - Tier number (1..=5)
|
|
40
41
|
*/
|
|
41
|
-
export declare function getSeasonMembershipPda(seasonNumber:
|
|
42
|
+
export declare function getSeasonMembershipPda(seasonNumber: SeasonNumberLike, user: PublicKey, tier: TierNumber): [PublicKey, number];
|
|
42
43
|
/**
|
|
43
44
|
* Derive the RewardWindow PDA
|
|
44
45
|
* @param seasonNumber - The season number
|
|
45
46
|
* @param windowNumber - The window number
|
|
46
47
|
*/
|
|
47
|
-
export declare function getRewardWindowPda(seasonNumber:
|
|
48
|
+
export declare function getRewardWindowPda(seasonNumber: SeasonNumberLike, windowNumber: BN): [PublicKey, number];
|
|
48
49
|
/**
|
|
49
50
|
* Derive the UserWindowParticipation PDA
|
|
50
51
|
* PDA model:
|
|
@@ -55,15 +56,15 @@ export declare function getRewardWindowPda(seasonNumber: BN, windowNumber: BN):
|
|
|
55
56
|
* @param tier - Tier number (1..=5)
|
|
56
57
|
* @param windowNumber - The window number
|
|
57
58
|
*/
|
|
58
|
-
export declare function getUserWindowParticipationPda(seasonNumber:
|
|
59
|
+
export declare function getUserWindowParticipationPda(seasonNumber: SeasonNumberLike, user: PublicKey, tier: TierNumber, windowNumber: BN): [PublicKey, number];
|
|
59
60
|
/**
|
|
60
61
|
* Derive the Season Deposit Vault PDA
|
|
61
62
|
*/
|
|
62
|
-
export declare function getSeasonDepositVaultPda(seasonNumber:
|
|
63
|
+
export declare function getSeasonDepositVaultPda(seasonNumber: SeasonNumberLike): [PublicKey, number];
|
|
63
64
|
/**
|
|
64
65
|
* Derive the Season Escrow Vault PDA
|
|
65
66
|
*/
|
|
66
|
-
export declare function getSeasonEscrowVaultPda(seasonNumber:
|
|
67
|
+
export declare function getSeasonEscrowVaultPda(seasonNumber: SeasonNumberLike): [PublicKey, number];
|
|
67
68
|
/**
|
|
68
69
|
* Derive the ReferralPenaltyClaim PDA
|
|
69
70
|
* PDA model:
|
|
@@ -74,4 +75,4 @@ export declare function getSeasonEscrowVaultPda(seasonNumber: BN): [PublicKey, n
|
|
|
74
75
|
* @param tier - Tier number (1..=5)
|
|
75
76
|
* @param windowNumber - The window number
|
|
76
77
|
*/
|
|
77
|
-
export declare function getReferralPenaltyClaimPda(seasonNumber:
|
|
78
|
+
export declare function getReferralPenaltyClaimPda(seasonNumber: SeasonNumberLike, referredUser: PublicKey, tier: TierNumber, windowNumber: BN): [PublicKey, number];
|
package/dist/utils/pdas.js
CHANGED
|
@@ -14,6 +14,8 @@ exports.getReferralPenaltyClaimPda = getReferralPenaltyClaimPda;
|
|
|
14
14
|
const web3_js_1 = require("@solana/web3.js");
|
|
15
15
|
const constants_1 = require("./constants");
|
|
16
16
|
const conversions_1 = require("./conversions");
|
|
17
|
+
const tierPenalty_1 = require("./tierPenalty");
|
|
18
|
+
const conversions_2 = require("./conversions");
|
|
17
19
|
/**
|
|
18
20
|
* PDA (Program Derived Address) derivation helpers
|
|
19
21
|
*/
|
|
@@ -35,7 +37,8 @@ function getUserStatsPda(telegramId) {
|
|
|
35
37
|
* @param shaHash - The SHA-256 hash as a 64-char hex string
|
|
36
38
|
*/
|
|
37
39
|
function getMiztakePda(shaHash) {
|
|
38
|
-
const
|
|
40
|
+
const normalized = typeof shaHash === "string" ? (0, conversions_1.toSha256HexString)(shaHash) : shaHash;
|
|
41
|
+
const shaHashBytes = (0, conversions_1.sha256HexToBytes32)(normalized);
|
|
39
42
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.MIZTAKE_SEED), shaHashBytes], constants_1.PROGRAM_ID);
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
@@ -49,7 +52,8 @@ function getSeasonSettingsPda() {
|
|
|
49
52
|
* @param seasonNumber - The season number
|
|
50
53
|
*/
|
|
51
54
|
function getSeasonPda(seasonNumber) {
|
|
52
|
-
|
|
55
|
+
const seasonBn = (0, conversions_2.toSeasonNumberBn)(seasonNumber);
|
|
56
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("season"), seasonBn.toArrayLike(Buffer, "le", 8)], constants_1.PROGRAM_ID);
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
55
59
|
* Derive the SeasonMembership PDA
|
|
@@ -64,14 +68,13 @@ function getSeasonPda(seasonNumber) {
|
|
|
64
68
|
* @param tier - Tier number (1..=5)
|
|
65
69
|
*/
|
|
66
70
|
function getSeasonMembershipPda(seasonNumber, user, tier) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
71
|
+
const t = (0, tierPenalty_1.assertValidTierNumber)(tier);
|
|
72
|
+
const seasonBn = (0, conversions_2.toSeasonNumberBn)(seasonNumber);
|
|
70
73
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
71
74
|
Buffer.from("season_membership"),
|
|
72
|
-
|
|
75
|
+
seasonBn.toArrayLike(Buffer, "le", 8),
|
|
73
76
|
user.toBuffer(),
|
|
74
|
-
Buffer.from([
|
|
77
|
+
Buffer.from([t]),
|
|
75
78
|
], constants_1.PROGRAM_ID);
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
@@ -80,9 +83,10 @@ function getSeasonMembershipPda(seasonNumber, user, tier) {
|
|
|
80
83
|
* @param windowNumber - The window number
|
|
81
84
|
*/
|
|
82
85
|
function getRewardWindowPda(seasonNumber, windowNumber) {
|
|
86
|
+
const seasonBn = (0, conversions_2.toSeasonNumberBn)(seasonNumber);
|
|
83
87
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
84
88
|
Buffer.from("reward_window"),
|
|
85
|
-
|
|
89
|
+
seasonBn.toArrayLike(Buffer, "le", 8),
|
|
86
90
|
windowNumber.toArrayLike(Buffer, "le", 8),
|
|
87
91
|
], constants_1.PROGRAM_ID);
|
|
88
92
|
}
|
|
@@ -97,14 +101,13 @@ function getRewardWindowPda(seasonNumber, windowNumber) {
|
|
|
97
101
|
* @param windowNumber - The window number
|
|
98
102
|
*/
|
|
99
103
|
function getUserWindowParticipationPda(seasonNumber, user, tier, windowNumber) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
104
|
+
const t = (0, tierPenalty_1.assertValidTierNumber)(tier);
|
|
105
|
+
const seasonBn = (0, conversions_2.toSeasonNumberBn)(seasonNumber);
|
|
103
106
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
104
107
|
Buffer.from("user_window"),
|
|
105
|
-
|
|
108
|
+
seasonBn.toArrayLike(Buffer, "le", 8),
|
|
106
109
|
user.toBuffer(),
|
|
107
|
-
Buffer.from([
|
|
110
|
+
Buffer.from([t]),
|
|
108
111
|
windowNumber.toArrayLike(Buffer, "le", 8),
|
|
109
112
|
], constants_1.PROGRAM_ID);
|
|
110
113
|
}
|
|
@@ -112,13 +115,15 @@ function getUserWindowParticipationPda(seasonNumber, user, tier, windowNumber) {
|
|
|
112
115
|
* Derive the Season Deposit Vault PDA
|
|
113
116
|
*/
|
|
114
117
|
function getSeasonDepositVaultPda(seasonNumber) {
|
|
115
|
-
|
|
118
|
+
const seasonBn = (0, conversions_2.toSeasonNumberBn)(seasonNumber);
|
|
119
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("season_deposit_vault"), seasonBn.toArrayLike(Buffer, "le", 8)], constants_1.PROGRAM_ID);
|
|
116
120
|
}
|
|
117
121
|
/**
|
|
118
122
|
* Derive the Season Escrow Vault PDA
|
|
119
123
|
*/
|
|
120
124
|
function getSeasonEscrowVaultPda(seasonNumber) {
|
|
121
|
-
|
|
125
|
+
const seasonBn = (0, conversions_2.toSeasonNumberBn)(seasonNumber);
|
|
126
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("season_escrow_vault"), seasonBn.toArrayLike(Buffer, "le", 8)], constants_1.PROGRAM_ID);
|
|
122
127
|
}
|
|
123
128
|
/**
|
|
124
129
|
* Derive the ReferralPenaltyClaim PDA
|
|
@@ -131,14 +136,13 @@ function getSeasonEscrowVaultPda(seasonNumber) {
|
|
|
131
136
|
* @param windowNumber - The window number
|
|
132
137
|
*/
|
|
133
138
|
function getReferralPenaltyClaimPda(seasonNumber, referredUser, tier, windowNumber) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
139
|
+
const t = (0, tierPenalty_1.assertValidTierNumber)(tier);
|
|
140
|
+
const seasonBn = (0, conversions_2.toSeasonNumberBn)(seasonNumber);
|
|
137
141
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
138
142
|
Buffer.from(constants_1.REFERRAL_PENALTY_CLAIM_SEED),
|
|
139
|
-
|
|
143
|
+
seasonBn.toArrayLike(Buffer, "le", 8),
|
|
140
144
|
referredUser.toBuffer(),
|
|
141
|
-
Buffer.from([
|
|
145
|
+
Buffer.from([t]),
|
|
142
146
|
windowNumber.toArrayLike(Buffer, "le", 8),
|
|
143
147
|
], constants_1.PROGRAM_ID);
|
|
144
148
|
}
|
|
@@ -13,6 +13,6 @@ const anchorHelpers_1 = require("./anchorHelpers");
|
|
|
13
13
|
function getProgram(connection) {
|
|
14
14
|
const provider = (0, anchorHelpers_1.createReadOnlyProvider)(connection);
|
|
15
15
|
// Ensure a stable program id even if the bundled IDL JSON was generated without `address`.
|
|
16
|
-
const idlWithAddress = (0, anchorHelpers_1.withIdlAddress)(idl_1.
|
|
16
|
+
const idlWithAddress = (0, anchorHelpers_1.withIdlAddress)(idl_1.ANCHOR_IDL, constants_1.PROGRAM_ID);
|
|
17
17
|
return new anchor_1.Program(idlWithAddress, provider);
|
|
18
18
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
export type SignerRole = "admin" | "user" | "payer" | "feePayer" | "claimant" | "currentAdmin";
|
|
2
3
|
/**
|
|
3
4
|
* Signer information
|
|
4
5
|
*/
|
|
5
6
|
export interface SignerInfo {
|
|
6
7
|
publicKey: PublicKey;
|
|
7
|
-
role:
|
|
8
|
+
role: SignerRole;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Build signers array with optional fee payer
|
|
@@ -43,15 +43,16 @@ async function simulateInstruction(connection, instructions, signers, feePayer)
|
|
|
43
43
|
transaction.recentBlockhash = blockhash;
|
|
44
44
|
try {
|
|
45
45
|
const simulation = await connection.simulateTransaction(transaction, undefined, [...signers.map((s) => s.publicKey)]);
|
|
46
|
+
const error = simulation.value.err !== null ? JSON.stringify(simulation.value.err) : undefined;
|
|
47
|
+
const returnData = simulation.value.returnData ?? undefined;
|
|
48
|
+
const accounts = simulation.value.accounts ?? undefined;
|
|
46
49
|
return {
|
|
47
50
|
success: simulation.value.err === null,
|
|
48
51
|
logs: simulation.value.logs || [],
|
|
49
52
|
unitsConsumed: simulation.value.unitsConsumed || 0,
|
|
50
|
-
error:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
returnData: simulation.value.returnData || undefined,
|
|
54
|
-
accounts: simulation.value.accounts || undefined,
|
|
53
|
+
...(error !== undefined ? { error } : {}),
|
|
54
|
+
...(returnData !== undefined ? { returnData } : {}),
|
|
55
|
+
...(accounts !== undefined ? { accounts } : {}),
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
catch (error) {
|
|
@@ -143,9 +144,9 @@ async function dryRun(connection, instructions, signers) {
|
|
|
143
144
|
const result = await simulateInstruction(connection, instructions, signers);
|
|
144
145
|
return {
|
|
145
146
|
willSucceed: result.success,
|
|
146
|
-
error: result.error,
|
|
147
147
|
logs: result.logs,
|
|
148
148
|
unitsConsumed: result.unitsConsumed,
|
|
149
|
+
...(result.error !== undefined ? { error: result.error } : {}),
|
|
149
150
|
};
|
|
150
151
|
}
|
|
151
152
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BN } from "@coral-xyz/anchor";
|
|
2
|
-
import { SeasonDepositTier } from "../types";
|
|
2
|
+
import { SeasonDepositTier, TierNumber } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* Validate and normalize a tier number (1..=5).
|
|
5
5
|
*/
|
|
6
|
-
export declare function assertValidTierNumber(tier: number):
|
|
6
|
+
export declare function assertValidTierNumber(tier: number): TierNumber;
|
|
7
7
|
/**
|
|
8
8
|
* Convert numeric tier (1..=5) to the Anchor enum representation.
|
|
9
9
|
*/
|
|
@@ -4,6 +4,7 @@ exports.assertValidTierNumber = assertValidTierNumber;
|
|
|
4
4
|
exports.tierNumberToDepositTier = tierNumberToDepositTier;
|
|
5
5
|
exports.getTierPenaltyPerWindow = getTierPenaltyPerWindow;
|
|
6
6
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
|
+
const depositTier_1 = require("./depositTier");
|
|
7
8
|
/**
|
|
8
9
|
* Validate and normalize a tier number (1..=5).
|
|
9
10
|
*/
|
|
@@ -40,15 +41,16 @@ function tierNumberToDepositTier(tier) {
|
|
|
40
41
|
*/
|
|
41
42
|
function getTierPenaltyPerWindow(tier) {
|
|
42
43
|
// Base units (7 decimals): 1 MIZD = 10_000_000
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
switch ((0, depositTier_1.getDepositTierName)(tier)) {
|
|
45
|
+
case "copper":
|
|
46
|
+
return new anchor_1.BN(1000000); // 0.1 MIZD
|
|
47
|
+
case "silver":
|
|
48
|
+
return new anchor_1.BN(10000000); // 1 MIZD
|
|
49
|
+
case "gold":
|
|
50
|
+
return new anchor_1.BN(100000000); // 10 MIZD
|
|
51
|
+
case "platinum":
|
|
52
|
+
return new anchor_1.BN(1000000000); // 100 MIZD
|
|
53
|
+
case "mithril":
|
|
54
|
+
return new anchor_1.BN(10000000000); // 1,000 MIZD
|
|
55
|
+
}
|
|
54
56
|
}
|