proof-of-take-sdk 1.0.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.
- package/FINAL_USAGE.md +342 -0
- package/LIBRARY_GUIDE.md +400 -0
- package/LICENSE +22 -0
- package/README.md +370 -0
- package/dist/client.d.ts +32 -0
- package/dist/client.js +47 -0
- package/dist/constants/season.d.ts +18 -0
- package/dist/constants/season.js +22 -0
- package/dist/getters/getMiztake.d.ts +11 -0
- package/dist/getters/getMiztake.js +34 -0
- package/dist/getters/getMiztakeStatistics.d.ts +10 -0
- package/dist/getters/getMiztakeStatistics.js +20 -0
- package/dist/getters/getTokenVault.d.ts +30 -0
- package/dist/getters/getTokenVault.js +56 -0
- package/dist/getters/getUserStats.d.ts +21 -0
- package/dist/getters/getUserStats.js +43 -0
- package/dist/getters/index.d.ts +7 -0
- package/dist/getters/index.js +23 -0
- package/dist/idl/idl.d.ts +2 -0
- package/dist/idl/idl.js +8 -0
- package/dist/idl/proof_of_take.json +3803 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +92 -0
- package/dist/instructions/claimReferralPenaltyForWindow.d.ts +38 -0
- package/dist/instructions/claimReferralPenaltyForWindow.js +72 -0
- package/dist/instructions/claimWindowRewards.d.ts +48 -0
- package/dist/instructions/claimWindowRewards.js +94 -0
- package/dist/instructions/confirmedPostOnX.d.ts +51 -0
- package/dist/instructions/confirmedPostOnX.js +78 -0
- package/dist/instructions/createMiztake.d.ts +90 -0
- package/dist/instructions/createMiztake.js +166 -0
- package/dist/instructions/initializeEscrowVault.d.ts +15 -0
- package/dist/instructions/initializeEscrowVault.js +36 -0
- package/dist/instructions/initializeSeasonSettings.d.ts +20 -0
- package/dist/instructions/initializeSeasonSettings.js +39 -0
- package/dist/instructions/initializeSeasonVault.d.ts +20 -0
- package/dist/instructions/initializeSeasonVault.js +43 -0
- package/dist/instructions/initializeStatistics.d.ts +32 -0
- package/dist/instructions/initializeStatistics.js +73 -0
- package/dist/instructions/joinSeason.d.ts +50 -0
- package/dist/instructions/joinSeason.js +120 -0
- package/dist/instructions/toggleSeasonPause.d.ts +22 -0
- package/dist/instructions/toggleSeasonPause.js +42 -0
- package/dist/instructions/updateSeasonAdmin.d.ts +23 -0
- package/dist/instructions/updateSeasonAdmin.js +43 -0
- package/dist/instructions/viewCurrentSeason.d.ts +12 -0
- package/dist/instructions/viewCurrentSeason.js +30 -0
- package/dist/instructions/viewSeasonMembershipStatus.d.ts +16 -0
- package/dist/instructions/viewSeasonMembershipStatus.js +33 -0
- package/dist/instructions/viewWindowStatus.d.ts +15 -0
- package/dist/instructions/viewWindowStatus.js +28 -0
- package/dist/instructions/withdrawSeasonDeposit.d.ts +38 -0
- package/dist/instructions/withdrawSeasonDeposit.js +66 -0
- package/dist/optimistic/index.d.ts +7 -0
- package/dist/optimistic/index.js +33 -0
- package/dist/types/accountTypes.d.ts +121 -0
- package/dist/types/accountTypes.js +2 -0
- package/dist/types/instructionResults.d.ts +44 -0
- package/dist/types/instructionResults.js +2 -0
- package/dist/types/proof_of_take.d.ts +3809 -0
- package/dist/types/proof_of_take.js +2 -0
- package/dist/types.d.ts +232 -0
- package/dist/types.js +16 -0
- package/dist/utils/accountUpdates.d.ts +245 -0
- package/dist/utils/accountUpdates.js +611 -0
- package/dist/utils/anchorHelpers.d.ts +7 -0
- package/dist/utils/anchorHelpers.js +21 -0
- package/dist/utils/constants.d.ts +21 -0
- package/dist/utils/constants.js +31 -0
- package/dist/utils/conversions.d.ts +25 -0
- package/dist/utils/conversions.js +53 -0
- package/dist/utils/enumHelpers.d.ts +63 -0
- package/dist/utils/enumHelpers.js +110 -0
- package/dist/utils/index.d.ts +0 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/pdaManager.d.ts +106 -0
- package/dist/utils/pdaManager.js +89 -0
- package/dist/utils/pdas.d.ts +68 -0
- package/dist/utils/pdas.js +128 -0
- package/dist/utils/programHelpers.d.ts +9 -0
- package/dist/utils/programHelpers.js +18 -0
- package/dist/utils/signerHelpers.d.ts +17 -0
- package/dist/utils/signerHelpers.js +21 -0
- package/dist/utils/simulationHelpers.d.ts +121 -0
- package/dist/utils/simulationHelpers.js +183 -0
- package/dist/utils/tierPenalty.d.ts +9 -0
- package/dist/utils/tierPenalty.js +24 -0
- package/dist/utils/transactionBuilder.d.ts +77 -0
- package/dist/utils/transactionBuilder.js +147 -0
- package/package.json +50 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
/**
|
|
3
|
+
* Safely convert BN to number for u64 fields
|
|
4
|
+
* Throws if the BN is larger than JavaScript's MAX_SAFE_INTEGER
|
|
5
|
+
*
|
|
6
|
+
* @param bn - BN to convert
|
|
7
|
+
* @returns Safe number
|
|
8
|
+
* @throws Error if BN is too large
|
|
9
|
+
*/
|
|
10
|
+
export declare function bnToU64(bn: BN): number;
|
|
11
|
+
/**
|
|
12
|
+
* Convert BN to number with fallback for large numbers
|
|
13
|
+
* Returns undefined if number is too large to safely convert
|
|
14
|
+
*
|
|
15
|
+
* @param bn - BN to convert
|
|
16
|
+
* @returns Safe number or undefined
|
|
17
|
+
*/
|
|
18
|
+
export declare function bnToU64Safe(bn: BN): number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Convert a 64-char SHA-256 hex string to a 32-byte Uint8Array.
|
|
21
|
+
*
|
|
22
|
+
* IMPORTANT: The on-chain program uses the raw 32-byte digest as PDA seed
|
|
23
|
+
* (`seeds = [b\"miztake\", sha_hash_bytes]`), NOT the ASCII prefix of the hex string.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sha256HexToBytes32(shaHex: string): Uint8Array;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bnToU64 = bnToU64;
|
|
4
|
+
exports.bnToU64Safe = bnToU64Safe;
|
|
5
|
+
exports.sha256HexToBytes32 = sha256HexToBytes32;
|
|
6
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
|
+
/**
|
|
8
|
+
* Safely convert BN to number for u64 fields
|
|
9
|
+
* Throws if the BN is larger than JavaScript's MAX_SAFE_INTEGER
|
|
10
|
+
*
|
|
11
|
+
* @param bn - BN to convert
|
|
12
|
+
* @returns Safe number
|
|
13
|
+
* @throws Error if BN is too large
|
|
14
|
+
*/
|
|
15
|
+
function bnToU64(bn) {
|
|
16
|
+
if (bn.gt(new anchor_1.BN(Number.MAX_SAFE_INTEGER))) {
|
|
17
|
+
throw new Error(`BN too large to safely convert to number: ${bn.toString()}`);
|
|
18
|
+
}
|
|
19
|
+
return bn.toNumber();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Convert BN to number with fallback for large numbers
|
|
23
|
+
* Returns undefined if number is too large to safely convert
|
|
24
|
+
*
|
|
25
|
+
* @param bn - BN to convert
|
|
26
|
+
* @returns Safe number or undefined
|
|
27
|
+
*/
|
|
28
|
+
function bnToU64Safe(bn) {
|
|
29
|
+
if (bn.gt(new anchor_1.BN(Number.MAX_SAFE_INTEGER))) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return bn.toNumber();
|
|
33
|
+
}
|
|
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) {
|
|
41
|
+
if (typeof shaHex !== "string") {
|
|
42
|
+
throw new Error("sha256HexToBytes32: shaHex must be a string");
|
|
43
|
+
}
|
|
44
|
+
const normalized = shaHex.toLowerCase();
|
|
45
|
+
if (!/^[0-9a-f]{64}$/.test(normalized)) {
|
|
46
|
+
throw new Error("sha256HexToBytes32: expected 64-char lowercase hex string");
|
|
47
|
+
}
|
|
48
|
+
const buf = Buffer.from(normalized, "hex");
|
|
49
|
+
if (buf.length !== 32) {
|
|
50
|
+
throw new Error("sha256HexToBytes32: decoded length != 32");
|
|
51
|
+
}
|
|
52
|
+
return new Uint8Array(buf);
|
|
53
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SeasonState, WindowState } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Enum helper utilities
|
|
4
|
+
*
|
|
5
|
+
* These helpers handle the difference between:
|
|
6
|
+
* - SDK numeric enums (SeasonState.Active = 1)
|
|
7
|
+
* - Anchor deserialized object enums ({ active: {} })
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Check if a SeasonState matches a specific variant
|
|
11
|
+
*
|
|
12
|
+
* Handles both SDK numeric format and Anchor object format
|
|
13
|
+
*
|
|
14
|
+
* @param state - The season state to check (from Anchor or SDK)
|
|
15
|
+
* @param variant - The variant to check against
|
|
16
|
+
* @returns True if state matches the variant
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Works with both formats:
|
|
21
|
+
* isSeasonState(season.seasonState, SeasonState.Active) // SDK numeric
|
|
22
|
+
* isSeasonState({ active: {} }, SeasonState.Active) // Anchor object
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function isSeasonState(state: SeasonState | {
|
|
26
|
+
[key: string]: {};
|
|
27
|
+
} | number, variant: SeasonState): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a WindowState matches a specific variant
|
|
30
|
+
*
|
|
31
|
+
* Handles both SDK numeric format and Anchor object format
|
|
32
|
+
*
|
|
33
|
+
* @param state - The window state to check (from Anchor or SDK)
|
|
34
|
+
* @param variant - The variant to check against
|
|
35
|
+
* @returns True if state matches the variant
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* isWindowState(window.windowState, WindowState.Active)
|
|
40
|
+
* isWindowState({ finalized: {} }, WindowState.Finalized)
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function isWindowState(state: WindowState | {
|
|
44
|
+
[key: string]: {};
|
|
45
|
+
} | number, variant: WindowState): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Normalize SeasonState to numeric format
|
|
48
|
+
*
|
|
49
|
+
* @param state - Season state in any format
|
|
50
|
+
* @returns Numeric representation (0=Uninitialized, 1=Active, 2=Ended)
|
|
51
|
+
*/
|
|
52
|
+
export declare function normalizeSeasonState(state: SeasonState | {
|
|
53
|
+
[key: string]: {};
|
|
54
|
+
} | number): number;
|
|
55
|
+
/**
|
|
56
|
+
* Normalize WindowState to numeric format
|
|
57
|
+
*
|
|
58
|
+
* @param state - Window state in any format
|
|
59
|
+
* @returns Numeric representation (0=Uninitialized, 1=Active, 2=Finalized)
|
|
60
|
+
*/
|
|
61
|
+
export declare function normalizeWindowState(state: WindowState | {
|
|
62
|
+
[key: string]: {};
|
|
63
|
+
} | number): number;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSeasonState = isSeasonState;
|
|
4
|
+
exports.isWindowState = isWindowState;
|
|
5
|
+
exports.normalizeSeasonState = normalizeSeasonState;
|
|
6
|
+
exports.normalizeWindowState = normalizeWindowState;
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
/**
|
|
9
|
+
* Enum helper utilities
|
|
10
|
+
*
|
|
11
|
+
* These helpers handle the difference between:
|
|
12
|
+
* - SDK numeric enums (SeasonState.Active = 1)
|
|
13
|
+
* - Anchor deserialized object enums ({ active: {} })
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Check if a SeasonState matches a specific variant
|
|
17
|
+
*
|
|
18
|
+
* Handles both SDK numeric format and Anchor object format
|
|
19
|
+
*
|
|
20
|
+
* @param state - The season state to check (from Anchor or SDK)
|
|
21
|
+
* @param variant - The variant to check against
|
|
22
|
+
* @returns True if state matches the variant
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Works with both formats:
|
|
27
|
+
* isSeasonState(season.seasonState, SeasonState.Active) // SDK numeric
|
|
28
|
+
* isSeasonState({ active: {} }, SeasonState.Active) // Anchor object
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function isSeasonState(state, variant) {
|
|
32
|
+
// Map variant to string representation
|
|
33
|
+
const variantMap = {
|
|
34
|
+
[types_1.SeasonState.Uninitialized]: "uninitialized",
|
|
35
|
+
[types_1.SeasonState.Active]: "active",
|
|
36
|
+
[types_1.SeasonState.Ended]: "ended",
|
|
37
|
+
};
|
|
38
|
+
const variantName = variantMap[variant];
|
|
39
|
+
// Check if value is Anchor object format
|
|
40
|
+
if (typeof state === "object" && state !== null && !Array.isArray(state)) {
|
|
41
|
+
const key = Object.keys(state)[0];
|
|
42
|
+
return key === variantName;
|
|
43
|
+
}
|
|
44
|
+
// Otherwise compare numeric values
|
|
45
|
+
return state === variant;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if a WindowState matches a specific variant
|
|
49
|
+
*
|
|
50
|
+
* Handles both SDK numeric format and Anchor object format
|
|
51
|
+
*
|
|
52
|
+
* @param state - The window state to check (from Anchor or SDK)
|
|
53
|
+
* @param variant - The variant to check against
|
|
54
|
+
* @returns True if state matches the variant
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* isWindowState(window.windowState, WindowState.Active)
|
|
59
|
+
* isWindowState({ finalized: {} }, WindowState.Finalized)
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function isWindowState(state, variant) {
|
|
63
|
+
const variantMap = {
|
|
64
|
+
[types_1.WindowState.Uninitialized]: "uninitialized",
|
|
65
|
+
[types_1.WindowState.Active]: "active",
|
|
66
|
+
[types_1.WindowState.Finalized]: "finalized",
|
|
67
|
+
};
|
|
68
|
+
const variantName = variantMap[variant];
|
|
69
|
+
if (typeof state === "object" && state !== null && !Array.isArray(state)) {
|
|
70
|
+
const key = Object.keys(state)[0];
|
|
71
|
+
return key === variantName;
|
|
72
|
+
}
|
|
73
|
+
return state === variant;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Normalize SeasonState to numeric format
|
|
77
|
+
*
|
|
78
|
+
* @param state - Season state in any format
|
|
79
|
+
* @returns Numeric representation (0=Uninitialized, 1=Active, 2=Ended)
|
|
80
|
+
*/
|
|
81
|
+
function normalizeSeasonState(state) {
|
|
82
|
+
const map = {
|
|
83
|
+
uninitialized: 0,
|
|
84
|
+
active: 1,
|
|
85
|
+
ended: 2,
|
|
86
|
+
};
|
|
87
|
+
if (typeof state === "object" && state !== null && !Array.isArray(state)) {
|
|
88
|
+
const key = Object.keys(state)[0];
|
|
89
|
+
return map[key] ?? -1;
|
|
90
|
+
}
|
|
91
|
+
return state;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Normalize WindowState to numeric format
|
|
95
|
+
*
|
|
96
|
+
* @param state - Window state in any format
|
|
97
|
+
* @returns Numeric representation (0=Uninitialized, 1=Active, 2=Finalized)
|
|
98
|
+
*/
|
|
99
|
+
function normalizeWindowState(state) {
|
|
100
|
+
const map = {
|
|
101
|
+
uninitialized: 0,
|
|
102
|
+
active: 1,
|
|
103
|
+
finalized: 2,
|
|
104
|
+
};
|
|
105
|
+
if (typeof state === "object" && state !== null && !Array.isArray(state)) {
|
|
106
|
+
const key = Object.keys(state)[0];
|
|
107
|
+
return map[key] ?? -1;
|
|
108
|
+
}
|
|
109
|
+
return state;
|
|
110
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
/**
|
|
4
|
+
* PDA Manager for deriving related PDAs together
|
|
5
|
+
* Reduces boilerplate in instruction files
|
|
6
|
+
*/
|
|
7
|
+
export declare class PDAManager {
|
|
8
|
+
/**
|
|
9
|
+
* Derive all PDAs needed for create_miztake instruction
|
|
10
|
+
*/
|
|
11
|
+
static deriveMiztakePdas(params: {
|
|
12
|
+
shaHash: string;
|
|
13
|
+
telegramId: BN;
|
|
14
|
+
seasonNumber: BN;
|
|
15
|
+
windowNumber: BN;
|
|
16
|
+
seasonMembershipId: BN;
|
|
17
|
+
user: PublicKey;
|
|
18
|
+
}): {
|
|
19
|
+
miztake: PublicKey;
|
|
20
|
+
userStats: PublicKey;
|
|
21
|
+
miztakeStatistics: PublicKey;
|
|
22
|
+
seasonSettings: PublicKey;
|
|
23
|
+
season: PublicKey;
|
|
24
|
+
seasonMembership: PublicKey;
|
|
25
|
+
rewardWindow: PublicKey;
|
|
26
|
+
userWindowParticipation: PublicKey;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Derive PDAs for join_season instruction
|
|
30
|
+
*/
|
|
31
|
+
static deriveJoinSeasonPdas(params: {
|
|
32
|
+
user: PublicKey;
|
|
33
|
+
seasonNumber: BN;
|
|
34
|
+
seasonMembershipId: BN;
|
|
35
|
+
}): {
|
|
36
|
+
seasonSettings: PublicKey;
|
|
37
|
+
season: PublicKey;
|
|
38
|
+
seasonMembership: PublicKey;
|
|
39
|
+
seasonDepositVault: PublicKey;
|
|
40
|
+
seasonEscrowVault: PublicKey;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Derive PDAs for confirmed_post_on_x instruction
|
|
44
|
+
*/
|
|
45
|
+
static deriveConfirmedPostPdas(params: {
|
|
46
|
+
user: PublicKey;
|
|
47
|
+
seasonNumber: BN;
|
|
48
|
+
windowNumber: BN;
|
|
49
|
+
seasonMembershipId: BN;
|
|
50
|
+
/** SHA-256 hex string (64 chars) */
|
|
51
|
+
miztakeShaHash: string;
|
|
52
|
+
}): {
|
|
53
|
+
seasonSettings: PublicKey;
|
|
54
|
+
seasonMembership: PublicKey;
|
|
55
|
+
season: PublicKey;
|
|
56
|
+
rewardWindow: PublicKey;
|
|
57
|
+
userWindowParticipation: PublicKey;
|
|
58
|
+
miztake: PublicKey;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Derive PDAs for claim_window_rewards instruction
|
|
62
|
+
*/
|
|
63
|
+
static deriveClaimWindowRewardsPdas(params: {
|
|
64
|
+
user: PublicKey;
|
|
65
|
+
seasonNumber: BN;
|
|
66
|
+
windowNumber: BN;
|
|
67
|
+
seasonMembershipId: BN;
|
|
68
|
+
}): {
|
|
69
|
+
seasonSettings: PublicKey;
|
|
70
|
+
season: PublicKey;
|
|
71
|
+
rewardWindow: PublicKey;
|
|
72
|
+
userWindowParticipation: PublicKey;
|
|
73
|
+
seasonMembership: PublicKey;
|
|
74
|
+
seasonDepositVault: PublicKey;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Derive PDAs for withdraw_season_deposit instruction
|
|
78
|
+
*/
|
|
79
|
+
static deriveWithdrawDepositPdas(params: {
|
|
80
|
+
user: PublicKey;
|
|
81
|
+
seasonNumber: BN;
|
|
82
|
+
seasonMembershipId: BN;
|
|
83
|
+
}): {
|
|
84
|
+
seasonSettings: PublicKey;
|
|
85
|
+
season: PublicKey;
|
|
86
|
+
seasonMembership: PublicKey;
|
|
87
|
+
seasonDepositVault: PublicKey;
|
|
88
|
+
seasonEscrowVault: PublicKey;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Derive PDAs for claim_referral_penalty_for_window instruction
|
|
92
|
+
*/
|
|
93
|
+
static deriveClaimReferralPenaltyForWindowPdas(params: {
|
|
94
|
+
referredUser: PublicKey;
|
|
95
|
+
seasonNumber: BN;
|
|
96
|
+
windowNumber: BN;
|
|
97
|
+
referredSeasonMembershipId: BN;
|
|
98
|
+
}): {
|
|
99
|
+
seasonSettings: PublicKey;
|
|
100
|
+
season: PublicKey;
|
|
101
|
+
seasonMembership: PublicKey;
|
|
102
|
+
userWindowParticipation: PublicKey;
|
|
103
|
+
referralPenaltyClaim: PublicKey;
|
|
104
|
+
seasonDepositVault: PublicKey;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PDAManager = void 0;
|
|
4
|
+
const pdas_1 = require("./pdas");
|
|
5
|
+
/**
|
|
6
|
+
* PDA Manager for deriving related PDAs together
|
|
7
|
+
* Reduces boilerplate in instruction files
|
|
8
|
+
*/
|
|
9
|
+
class PDAManager {
|
|
10
|
+
/**
|
|
11
|
+
* Derive all PDAs needed for create_miztake instruction
|
|
12
|
+
*/
|
|
13
|
+
static deriveMiztakePdas(params) {
|
|
14
|
+
return {
|
|
15
|
+
miztake: (0, pdas_1.getMiztakePda)(params.shaHash)[0],
|
|
16
|
+
userStats: (0, pdas_1.getUserStatsPda)(params.telegramId)[0],
|
|
17
|
+
miztakeStatistics: (0, pdas_1.getMiztakeStatisticsPda)()[0],
|
|
18
|
+
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
19
|
+
season: (0, pdas_1.getSeasonPda)(params.seasonNumber)[0],
|
|
20
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(params.user, params.seasonMembershipId)[0],
|
|
21
|
+
rewardWindow: (0, pdas_1.getRewardWindowPda)(params.seasonNumber, params.windowNumber)[0],
|
|
22
|
+
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(params.user, params.seasonNumber, params.windowNumber, params.seasonMembershipId)[0],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Derive PDAs for join_season instruction
|
|
27
|
+
*/
|
|
28
|
+
static deriveJoinSeasonPdas(params) {
|
|
29
|
+
return {
|
|
30
|
+
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
31
|
+
season: (0, pdas_1.getSeasonPda)(params.seasonNumber)[0],
|
|
32
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(params.user, params.seasonMembershipId)[0],
|
|
33
|
+
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)()[0],
|
|
34
|
+
seasonEscrowVault: (0, pdas_1.getSeasonEscrowVaultPda)()[0],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Derive PDAs for confirmed_post_on_x instruction
|
|
39
|
+
*/
|
|
40
|
+
static deriveConfirmedPostPdas(params) {
|
|
41
|
+
return {
|
|
42
|
+
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
43
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(params.user, params.seasonMembershipId)[0],
|
|
44
|
+
season: (0, pdas_1.getSeasonPda)(params.seasonNumber)[0],
|
|
45
|
+
rewardWindow: (0, pdas_1.getRewardWindowPda)(params.seasonNumber, params.windowNumber)[0],
|
|
46
|
+
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(params.user, params.seasonNumber, params.windowNumber, params.seasonMembershipId)[0],
|
|
47
|
+
miztake: (0, pdas_1.getMiztakePda)(params.miztakeShaHash)[0],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Derive PDAs for claim_window_rewards instruction
|
|
52
|
+
*/
|
|
53
|
+
static deriveClaimWindowRewardsPdas(params) {
|
|
54
|
+
return {
|
|
55
|
+
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
56
|
+
season: (0, pdas_1.getSeasonPda)(params.seasonNumber)[0],
|
|
57
|
+
rewardWindow: (0, pdas_1.getRewardWindowPda)(params.seasonNumber, params.windowNumber)[0],
|
|
58
|
+
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(params.user, params.seasonNumber, params.windowNumber, params.seasonMembershipId)[0],
|
|
59
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(params.user, params.seasonMembershipId)[0],
|
|
60
|
+
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)()[0],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Derive PDAs for withdraw_season_deposit instruction
|
|
65
|
+
*/
|
|
66
|
+
static deriveWithdrawDepositPdas(params) {
|
|
67
|
+
return {
|
|
68
|
+
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
69
|
+
season: (0, pdas_1.getSeasonPda)(params.seasonNumber)[0],
|
|
70
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(params.user, params.seasonMembershipId)[0],
|
|
71
|
+
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)()[0],
|
|
72
|
+
seasonEscrowVault: (0, pdas_1.getSeasonEscrowVaultPda)()[0],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Derive PDAs for claim_referral_penalty_for_window instruction
|
|
77
|
+
*/
|
|
78
|
+
static deriveClaimReferralPenaltyForWindowPdas(params) {
|
|
79
|
+
return {
|
|
80
|
+
seasonSettings: (0, pdas_1.getSeasonSettingsPda)()[0],
|
|
81
|
+
season: (0, pdas_1.getSeasonPda)(params.seasonNumber)[0],
|
|
82
|
+
seasonMembership: (0, pdas_1.getSeasonMembershipPda)(params.referredUser, params.referredSeasonMembershipId)[0],
|
|
83
|
+
userWindowParticipation: (0, pdas_1.getUserWindowParticipationPda)(params.referredUser, params.seasonNumber, params.windowNumber, params.referredSeasonMembershipId)[0],
|
|
84
|
+
referralPenaltyClaim: (0, pdas_1.getReferralPenaltyClaimPda)(params.referredUser, params.seasonNumber, params.windowNumber, params.referredSeasonMembershipId)[0],
|
|
85
|
+
seasonDepositVault: (0, pdas_1.getSeasonDepositVaultPda)()[0],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.PDAManager = PDAManager;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
/**
|
|
4
|
+
* PDA (Program Derived Address) derivation helpers
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Derive the MiztakeStatistics PDA
|
|
8
|
+
*/
|
|
9
|
+
export declare function getMiztakeStatisticsPda(): [PublicKey, number];
|
|
10
|
+
/**
|
|
11
|
+
* Derive the Token Vault PDA
|
|
12
|
+
*/
|
|
13
|
+
export declare function getTokenVaultPda(): [PublicKey, number];
|
|
14
|
+
/**
|
|
15
|
+
* Derive the UserStats PDA for a given telegram ID
|
|
16
|
+
* @param telegramId - The user's Telegram ID
|
|
17
|
+
*/
|
|
18
|
+
export declare function getUserStatsPda(telegramId: BN): [PublicKey, number];
|
|
19
|
+
/**
|
|
20
|
+
* Derive the Miztake PDA for a given SHA hash
|
|
21
|
+
* @param shaHash - The SHA-256 hash as a 64-char hex string
|
|
22
|
+
*/
|
|
23
|
+
export declare function getMiztakePda(shaHash: string): [PublicKey, number];
|
|
24
|
+
/**
|
|
25
|
+
* Derive the SeasonSettings PDA
|
|
26
|
+
*/
|
|
27
|
+
export declare function getSeasonSettingsPda(): [PublicKey, number];
|
|
28
|
+
/**
|
|
29
|
+
* Derive the Season PDA for a given season number
|
|
30
|
+
* @param seasonNumber - The season number
|
|
31
|
+
*/
|
|
32
|
+
export declare function getSeasonPda(seasonNumber: BN): [PublicKey, number];
|
|
33
|
+
/**
|
|
34
|
+
* Derive the SeasonMembership PDA
|
|
35
|
+
* @param user - The user's public key
|
|
36
|
+
* @param seasonMembershipId - The membership ID
|
|
37
|
+
*/
|
|
38
|
+
export declare function getSeasonMembershipPda(user: PublicKey, seasonMembershipId: BN): [PublicKey, number];
|
|
39
|
+
/**
|
|
40
|
+
* Derive the RewardWindow PDA
|
|
41
|
+
* @param seasonNumber - The season number
|
|
42
|
+
* @param windowNumber - The window number
|
|
43
|
+
*/
|
|
44
|
+
export declare function getRewardWindowPda(seasonNumber: BN, windowNumber: BN): [PublicKey, number];
|
|
45
|
+
/**
|
|
46
|
+
* Derive the UserWindowParticipation PDA
|
|
47
|
+
* @param user - The user's public key
|
|
48
|
+
* @param seasonNumber - The season number
|
|
49
|
+
* @param windowNumber - The window number
|
|
50
|
+
* @param seasonMembershipId - The membership ID
|
|
51
|
+
*/
|
|
52
|
+
export declare function getUserWindowParticipationPda(user: PublicKey, seasonNumber: BN, windowNumber: BN, seasonMembershipId: BN): [PublicKey, number];
|
|
53
|
+
/**
|
|
54
|
+
* Derive the Season Deposit Vault PDA
|
|
55
|
+
*/
|
|
56
|
+
export declare function getSeasonDepositVaultPda(): [PublicKey, number];
|
|
57
|
+
/**
|
|
58
|
+
* Derive the Season Escrow Vault PDA
|
|
59
|
+
*/
|
|
60
|
+
export declare function getSeasonEscrowVaultPda(): [PublicKey, number];
|
|
61
|
+
/**
|
|
62
|
+
* Derive the ReferralPenaltyClaim PDA
|
|
63
|
+
* @param referredUser - The referred user's public key (the user who missed)
|
|
64
|
+
* @param seasonNumber - The season number
|
|
65
|
+
* @param windowNumber - The window number
|
|
66
|
+
* @param seasonMembershipId - The referred user's membership id
|
|
67
|
+
*/
|
|
68
|
+
export declare function getReferralPenaltyClaimPda(referredUser: PublicKey, seasonNumber: BN, windowNumber: BN, seasonMembershipId: BN): [PublicKey, number];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMiztakeStatisticsPda = getMiztakeStatisticsPda;
|
|
4
|
+
exports.getTokenVaultPda = getTokenVaultPda;
|
|
5
|
+
exports.getUserStatsPda = getUserStatsPda;
|
|
6
|
+
exports.getMiztakePda = getMiztakePda;
|
|
7
|
+
exports.getSeasonSettingsPda = getSeasonSettingsPda;
|
|
8
|
+
exports.getSeasonPda = getSeasonPda;
|
|
9
|
+
exports.getSeasonMembershipPda = getSeasonMembershipPda;
|
|
10
|
+
exports.getRewardWindowPda = getRewardWindowPda;
|
|
11
|
+
exports.getUserWindowParticipationPda = getUserWindowParticipationPda;
|
|
12
|
+
exports.getSeasonDepositVaultPda = getSeasonDepositVaultPda;
|
|
13
|
+
exports.getSeasonEscrowVaultPda = getSeasonEscrowVaultPda;
|
|
14
|
+
exports.getReferralPenaltyClaimPda = getReferralPenaltyClaimPda;
|
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
16
|
+
const constants_1 = require("./constants");
|
|
17
|
+
const conversions_1 = require("./conversions");
|
|
18
|
+
/**
|
|
19
|
+
* PDA (Program Derived Address) derivation helpers
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Derive the MiztakeStatistics PDA
|
|
23
|
+
*/
|
|
24
|
+
function getMiztakeStatisticsPda() {
|
|
25
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.MIZTAKE_STATISTICS_SEED)], constants_1.PROGRAM_ID);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Derive the Token Vault PDA
|
|
29
|
+
*/
|
|
30
|
+
function getTokenVaultPda() {
|
|
31
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.TOKEN_VAULT_SEED)], constants_1.PROGRAM_ID);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Derive the UserStats PDA for a given telegram ID
|
|
35
|
+
* @param telegramId - The user's Telegram ID
|
|
36
|
+
*/
|
|
37
|
+
function getUserStatsPda(telegramId) {
|
|
38
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.USER_STATS_SEED), telegramId.toArrayLike(Buffer, "le", 8)], constants_1.PROGRAM_ID);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Derive the Miztake PDA for a given SHA hash
|
|
42
|
+
* @param shaHash - The SHA-256 hash as a 64-char hex string
|
|
43
|
+
*/
|
|
44
|
+
function getMiztakePda(shaHash) {
|
|
45
|
+
const shaHashBytes = (0, conversions_1.sha256HexToBytes32)(shaHash);
|
|
46
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.MIZTAKE_SEED), shaHashBytes], constants_1.PROGRAM_ID);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Derive the SeasonSettings PDA
|
|
50
|
+
*/
|
|
51
|
+
function getSeasonSettingsPda() {
|
|
52
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("season_settings")], constants_1.PROGRAM_ID);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Derive the Season PDA for a given season number
|
|
56
|
+
* @param seasonNumber - The season number
|
|
57
|
+
*/
|
|
58
|
+
function getSeasonPda(seasonNumber) {
|
|
59
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("season"), seasonNumber.toArrayLike(Buffer, "le", 8)], constants_1.PROGRAM_ID);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Derive the SeasonMembership PDA
|
|
63
|
+
* @param user - The user's public key
|
|
64
|
+
* @param seasonMembershipId - The membership ID
|
|
65
|
+
*/
|
|
66
|
+
function getSeasonMembershipPda(user, seasonMembershipId) {
|
|
67
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
68
|
+
Buffer.from("season_membership"),
|
|
69
|
+
user.toBuffer(),
|
|
70
|
+
seasonMembershipId.toArrayLike(Buffer, "le", 8),
|
|
71
|
+
], constants_1.PROGRAM_ID);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Derive the RewardWindow PDA
|
|
75
|
+
* @param seasonNumber - The season number
|
|
76
|
+
* @param windowNumber - The window number
|
|
77
|
+
*/
|
|
78
|
+
function getRewardWindowPda(seasonNumber, windowNumber) {
|
|
79
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
80
|
+
Buffer.from("reward_window"),
|
|
81
|
+
seasonNumber.toArrayLike(Buffer, "le", 8),
|
|
82
|
+
windowNumber.toArrayLike(Buffer, "le", 8),
|
|
83
|
+
], constants_1.PROGRAM_ID);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Derive the UserWindowParticipation PDA
|
|
87
|
+
* @param user - The user's public key
|
|
88
|
+
* @param seasonNumber - The season number
|
|
89
|
+
* @param windowNumber - The window number
|
|
90
|
+
* @param seasonMembershipId - The membership ID
|
|
91
|
+
*/
|
|
92
|
+
function getUserWindowParticipationPda(user, seasonNumber, windowNumber, seasonMembershipId) {
|
|
93
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
94
|
+
Buffer.from("user_window"),
|
|
95
|
+
user.toBuffer(),
|
|
96
|
+
seasonNumber.toArrayLike(Buffer, "le", 8),
|
|
97
|
+
windowNumber.toArrayLike(Buffer, "le", 8),
|
|
98
|
+
seasonMembershipId.toArrayLike(Buffer, "le", 8),
|
|
99
|
+
], constants_1.PROGRAM_ID);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Derive the Season Deposit Vault PDA
|
|
103
|
+
*/
|
|
104
|
+
function getSeasonDepositVaultPda() {
|
|
105
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("season_deposit_vault")], constants_1.PROGRAM_ID);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Derive the Season Escrow Vault PDA
|
|
109
|
+
*/
|
|
110
|
+
function getSeasonEscrowVaultPda() {
|
|
111
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("season_escrow_vault")], constants_1.PROGRAM_ID);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Derive the ReferralPenaltyClaim PDA
|
|
115
|
+
* @param referredUser - The referred user's public key (the user who missed)
|
|
116
|
+
* @param seasonNumber - The season number
|
|
117
|
+
* @param windowNumber - The window number
|
|
118
|
+
* @param seasonMembershipId - The referred user's membership id
|
|
119
|
+
*/
|
|
120
|
+
function getReferralPenaltyClaimPda(referredUser, seasonNumber, windowNumber, seasonMembershipId) {
|
|
121
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
122
|
+
Buffer.from(constants_1.REFERRAL_PENALTY_CLAIM_SEED),
|
|
123
|
+
referredUser.toBuffer(),
|
|
124
|
+
seasonNumber.toArrayLike(Buffer, "le", 8),
|
|
125
|
+
windowNumber.toArrayLike(Buffer, "le", 8),
|
|
126
|
+
seasonMembershipId.toArrayLike(Buffer, "le", 8),
|
|
127
|
+
], constants_1.PROGRAM_ID);
|
|
128
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { Connection } from "@solana/web3.js";
|
|
3
|
+
import { ProofOfTake } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Create a program instance for the Proof of Take program
|
|
6
|
+
* @param connection - Solana connection
|
|
7
|
+
* @returns Program instance
|
|
8
|
+
*/
|
|
9
|
+
export declare function getProgram(connection: Connection): Program<ProofOfTake>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProgram = getProgram;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const idl_1 = require("../idl/idl");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const anchorHelpers_1 = require("./anchorHelpers");
|
|
8
|
+
/**
|
|
9
|
+
* Create a program instance for the Proof of Take program
|
|
10
|
+
* @param connection - Solana connection
|
|
11
|
+
* @returns Program instance
|
|
12
|
+
*/
|
|
13
|
+
function getProgram(connection) {
|
|
14
|
+
const provider = (0, anchorHelpers_1.createReadOnlyProvider)(connection);
|
|
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.IDL, constants_1.PROGRAM_ID);
|
|
17
|
+
return new anchor_1.Program(idlWithAddress, provider);
|
|
18
|
+
}
|