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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection, PublicKey
|
|
2
|
-
import {
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { StandardInstructionResult } from "../types/instructionResults";
|
|
3
3
|
/**
|
|
4
4
|
* Close a Miztake account
|
|
5
5
|
*/
|
|
@@ -8,10 +8,7 @@ export declare function closeMiztake(options: {
|
|
|
8
8
|
admin: PublicKey;
|
|
9
9
|
accountToClose: PublicKey;
|
|
10
10
|
feePayer?: PublicKey;
|
|
11
|
-
}): Promise<
|
|
12
|
-
instructions: TransactionInstruction[];
|
|
13
|
-
signers: SignerInfo[];
|
|
14
|
-
}>;
|
|
11
|
+
}): Promise<StandardInstructionResult>;
|
|
15
12
|
/**
|
|
16
13
|
* Close a UserStats account
|
|
17
14
|
*/
|
|
@@ -20,10 +17,7 @@ export declare function closeUserStats(options: {
|
|
|
20
17
|
admin: PublicKey;
|
|
21
18
|
accountToClose: PublicKey;
|
|
22
19
|
feePayer?: PublicKey;
|
|
23
|
-
}): Promise<
|
|
24
|
-
instructions: TransactionInstruction[];
|
|
25
|
-
signers: SignerInfo[];
|
|
26
|
-
}>;
|
|
20
|
+
}): Promise<StandardInstructionResult>;
|
|
27
21
|
/**
|
|
28
22
|
* Close a SeasonMembership account
|
|
29
23
|
*/
|
|
@@ -32,10 +26,7 @@ export declare function closeSeasonMembership(options: {
|
|
|
32
26
|
admin: PublicKey;
|
|
33
27
|
accountToClose: PublicKey;
|
|
34
28
|
feePayer?: PublicKey;
|
|
35
|
-
}): Promise<
|
|
36
|
-
instructions: TransactionInstruction[];
|
|
37
|
-
signers: SignerInfo[];
|
|
38
|
-
}>;
|
|
29
|
+
}): Promise<StandardInstructionResult>;
|
|
39
30
|
/**
|
|
40
31
|
* Close a RewardWindow account
|
|
41
32
|
*/
|
|
@@ -44,10 +35,7 @@ export declare function closeRewardWindow(options: {
|
|
|
44
35
|
admin: PublicKey;
|
|
45
36
|
accountToClose: PublicKey;
|
|
46
37
|
feePayer?: PublicKey;
|
|
47
|
-
}): Promise<
|
|
48
|
-
instructions: TransactionInstruction[];
|
|
49
|
-
signers: SignerInfo[];
|
|
50
|
-
}>;
|
|
38
|
+
}): Promise<StandardInstructionResult>;
|
|
51
39
|
/**
|
|
52
40
|
* Close a UserWindowParticipation account
|
|
53
41
|
*/
|
|
@@ -56,10 +44,7 @@ export declare function closeUserWindowParticipation(options: {
|
|
|
56
44
|
admin: PublicKey;
|
|
57
45
|
accountToClose: PublicKey;
|
|
58
46
|
feePayer?: PublicKey;
|
|
59
|
-
}): Promise<
|
|
60
|
-
instructions: TransactionInstruction[];
|
|
61
|
-
signers: SignerInfo[];
|
|
62
|
-
}>;
|
|
47
|
+
}): Promise<StandardInstructionResult>;
|
|
63
48
|
/**
|
|
64
49
|
* Close a ReferralPenaltyClaim account
|
|
65
50
|
*/
|
|
@@ -68,7 +53,4 @@ export declare function closeReferralPenaltyClaim(options: {
|
|
|
68
53
|
admin: PublicKey;
|
|
69
54
|
accountToClose: PublicKey;
|
|
70
55
|
feePayer?: PublicKey;
|
|
71
|
-
}): Promise<
|
|
72
|
-
instructions: TransactionInstruction[];
|
|
73
|
-
signers: SignerInfo[];
|
|
74
|
-
}>;
|
|
56
|
+
}): Promise<StandardInstructionResult>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BN } from "@coral-xyz/anchor";
|
|
2
|
-
import { Connection, PublicKey
|
|
3
|
-
import { SeasonSettings, SeasonMembership, Season, RewardWindow, UserWindowParticipation, Miztake } from "../types";
|
|
4
|
-
import {
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { SeasonSettings, SeasonMembership, Season, RewardWindow, UserWindowParticipation, Miztake, TierNumber, Sha256HexString, WindowNumberLike } from "../types";
|
|
4
|
+
import { StandardInstructionResultWithPdas } from "../types/instructionResults";
|
|
5
5
|
type ConfirmedPostOnXUpdatedAccounts = {
|
|
6
6
|
seasonSettings?: SeasonSettings;
|
|
7
7
|
seasonMembership?: SeasonMembership;
|
|
@@ -19,10 +19,10 @@ export interface ConfirmedPostOnXOptions {
|
|
|
19
19
|
user: PublicKey;
|
|
20
20
|
seasonNumber: BN;
|
|
21
21
|
/** Tier number: 1=copper, 2=silver, 3=gold, 4=platinum, 5=mithril */
|
|
22
|
-
tier:
|
|
23
|
-
windowNumber:
|
|
22
|
+
tier: TierNumber;
|
|
23
|
+
windowNumber: WindowNumberLike;
|
|
24
24
|
/** SHA-256 hex string (64 chars). On-chain expects the raw 32-byte digest. */
|
|
25
|
-
miztakeShaHash: string;
|
|
25
|
+
miztakeShaHash: Sha256HexString | string;
|
|
26
26
|
feePayer?: PublicKey;
|
|
27
27
|
/** Whether the post is on time (needed for optimistic updates) */
|
|
28
28
|
isOnTime?: boolean;
|
|
@@ -45,9 +45,12 @@ export interface ConfirmedPostOnXOptions {
|
|
|
45
45
|
* @param options - Confirmed post on X options
|
|
46
46
|
* @returns Instructions, signers, and optimistically updated accounts
|
|
47
47
|
*/
|
|
48
|
-
export declare function confirmedPostOnX(options: ConfirmedPostOnXOptions): Promise<{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
export declare function confirmedPostOnX(options: ConfirmedPostOnXOptions): Promise<StandardInstructionResultWithPdas<{
|
|
49
|
+
seasonSettings: PublicKey;
|
|
50
|
+
seasonMembership: PublicKey;
|
|
51
|
+
season: PublicKey;
|
|
52
|
+
rewardWindow: PublicKey;
|
|
53
|
+
userWindowParticipation: PublicKey;
|
|
54
|
+
miztake: PublicKey;
|
|
55
|
+
}, ConfirmedPostOnXUpdatedAccounts>>;
|
|
53
56
|
export {};
|
|
@@ -18,12 +18,14 @@ const optimistic_1 = require("../optimistic");
|
|
|
18
18
|
* @returns Instructions, signers, and optimistically updated accounts
|
|
19
19
|
*/
|
|
20
20
|
async function confirmedPostOnX(options) {
|
|
21
|
+
// Guardrail: this program uses a 21-window schedule (0..20).
|
|
22
|
+
const windowNumber = (0, conversions_1.toWindowNumberBn)(options.windowNumber);
|
|
21
23
|
const program = (0, programHelpers_1.getProgram)(options.connection);
|
|
22
24
|
const curr = options.currentAccounts || {};
|
|
23
25
|
const pdas = pdaManager_1.PDAManager.deriveConfirmedPostPdas({
|
|
24
26
|
user: options.user,
|
|
25
27
|
seasonNumber: options.seasonNumber,
|
|
26
|
-
windowNumber
|
|
28
|
+
windowNumber,
|
|
27
29
|
tier: options.tier,
|
|
28
30
|
miztakeShaHash: options.miztakeShaHash,
|
|
29
31
|
});
|
|
@@ -37,13 +39,15 @@ async function confirmedPostOnX(options) {
|
|
|
37
39
|
admin: options.adminKey,
|
|
38
40
|
};
|
|
39
41
|
const instruction = await program.methods
|
|
40
|
-
.confirmedPostOnX(options.user, options.tier,
|
|
42
|
+
.confirmedPostOnX(options.user, options.tier, windowNumber, Array.from((0, conversions_1.sha256HexToBytes32)(options.miztakeShaHash)))
|
|
41
43
|
.accounts(accounts)
|
|
42
44
|
.instruction();
|
|
43
45
|
const signers = (0, signerHelpers_1.buildSigners)([{ publicKey: options.adminKey, role: "admin" }], options.feePayer);
|
|
44
46
|
// OPTIMISTIC UPDATES
|
|
45
47
|
let updatedAccounts = undefined;
|
|
46
|
-
if (options.isOnTime !== undefined &&
|
|
48
|
+
if (options.isOnTime !== undefined &&
|
|
49
|
+
curr.seasonSettings &&
|
|
50
|
+
curr.seasonMembership) {
|
|
47
51
|
const stakeAmount = (0, tierPenalty_1.getTierPenaltyPerWindow)(curr.seasonMembership.depositTier);
|
|
48
52
|
updatedAccounts = {
|
|
49
53
|
...(curr.seasonSettings && { seasonSettings: curr.seasonSettings }),
|
|
@@ -67,6 +71,7 @@ async function confirmedPostOnX(options) {
|
|
|
67
71
|
return {
|
|
68
72
|
instructions: [instruction],
|
|
69
73
|
signers,
|
|
74
|
+
pdas,
|
|
70
75
|
...(updatedAccounts && { updatedAccounts }),
|
|
71
76
|
};
|
|
72
77
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BN } from "@coral-xyz/anchor";
|
|
2
2
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
-
import { CreateMiztakeParams, Miztake, UserStats, MiztakeStatistics, SeasonSettings, Season, SeasonMembership, RewardWindow, UserWindowParticipation } from "../types";
|
|
4
|
-
import {
|
|
3
|
+
import { CreateMiztakeParams, Miztake, UserStats, MiztakeStatistics, SeasonSettings, Season, SeasonMembership, RewardWindow, UserWindowParticipation, TierNumber, WindowNumberLike } from "../types";
|
|
4
|
+
import { StandardInstructionResultWithPdasAndAccounts } from "../types/instructionResults";
|
|
5
5
|
/**
|
|
6
6
|
* Options for createMiztake instruction
|
|
7
7
|
*/
|
|
@@ -11,9 +11,9 @@ export interface CreateMiztakeOptions {
|
|
|
11
11
|
user: PublicKey;
|
|
12
12
|
admin: PublicKey;
|
|
13
13
|
seasonNumber: BN;
|
|
14
|
-
windowNumber:
|
|
14
|
+
windowNumber: WindowNumberLike;
|
|
15
15
|
/** Tier number: 1=copper, 2=silver, 3=gold, 4=platinum, 5=mithril */
|
|
16
|
-
tier:
|
|
16
|
+
tier: TierNumber;
|
|
17
17
|
/** Optional injected timestamp (seconds) for optimistic state calculation */
|
|
18
18
|
now?: BN;
|
|
19
19
|
feePayer?: PublicKey;
|
|
@@ -30,30 +30,27 @@ export interface CreateMiztakeOptions {
|
|
|
30
30
|
/**
|
|
31
31
|
* Result from createMiztake instruction
|
|
32
32
|
*/
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
userWindowParticipation?: UserWindowParticipation;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
33
|
+
export type CreateMiztakePdas = {
|
|
34
|
+
miztake: PublicKey;
|
|
35
|
+
userStats: PublicKey;
|
|
36
|
+
miztakeStatistics: PublicKey;
|
|
37
|
+
seasonSettings: PublicKey;
|
|
38
|
+
season: PublicKey;
|
|
39
|
+
seasonMembership: PublicKey;
|
|
40
|
+
rewardWindow: PublicKey;
|
|
41
|
+
userWindowParticipation: PublicKey;
|
|
42
|
+
};
|
|
43
|
+
export type CreateMiztakeUpdatedAccounts = {
|
|
44
|
+
miztake: Miztake;
|
|
45
|
+
userStats?: UserStats;
|
|
46
|
+
miztakeStatistics?: MiztakeStatistics;
|
|
47
|
+
seasonSettings?: SeasonSettings;
|
|
48
|
+
season?: Season;
|
|
49
|
+
seasonMembership?: SeasonMembership;
|
|
50
|
+
rewardWindow?: RewardWindow;
|
|
51
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
52
|
+
};
|
|
53
|
+
export type CreateMiztakeResult = StandardInstructionResultWithPdasAndAccounts<CreateMiztakePdas, CreateMiztakeUpdatedAccounts>;
|
|
57
54
|
/**
|
|
58
55
|
* Create a new miztake
|
|
59
56
|
*
|
|
@@ -42,12 +42,15 @@ const enumHelpers_1 = require("../utils/enumHelpers");
|
|
|
42
42
|
*/
|
|
43
43
|
async function createMiztake(options) {
|
|
44
44
|
const program = (0, programHelpers_1.getProgram)(options.connection);
|
|
45
|
+
// Guardrail: this program uses a 21-window schedule (0..20).
|
|
46
|
+
const windowNumber = (0, conversions_1.toWindowNumberBn)(options.windowNumber);
|
|
47
|
+
const shaHash = (0, conversions_1.toSha256HexString)(options.params.shaHash);
|
|
45
48
|
// Derive all PDAs using PDAManager
|
|
46
49
|
const pdas = pdaManager_1.PDAManager.deriveMiztakePdas({
|
|
47
|
-
shaHash
|
|
50
|
+
shaHash,
|
|
48
51
|
telegramId: options.params.telegramId,
|
|
49
52
|
seasonNumber: options.seasonNumber,
|
|
50
|
-
windowNumber
|
|
53
|
+
windowNumber,
|
|
51
54
|
user: options.user,
|
|
52
55
|
tier: options.tier,
|
|
53
56
|
});
|
|
@@ -66,11 +69,11 @@ async function createMiztake(options) {
|
|
|
66
69
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
67
70
|
};
|
|
68
71
|
// Build instruction
|
|
69
|
-
const shaHashBytes = (0, conversions_1.sha256HexToBytes32)(
|
|
72
|
+
const shaHashBytes = (0, conversions_1.sha256HexToBytes32)(shaHash);
|
|
70
73
|
const instruction = await program.methods
|
|
71
74
|
.createMiztake(
|
|
72
75
|
// Anchor expects BN for u64 args.
|
|
73
|
-
options.params.telegramId, options.params.telegramUsername, options.params.perceptualHash, options.params.averageHash, options.params.differenceHash, options.params.waveletHash,
|
|
76
|
+
options.params.telegramId, options.params.telegramUsername, options.params.perceptualHash, options.params.averageHash, options.params.differenceHash, options.params.waveletHash, shaHash, Array.from(shaHashBytes), options.params.computedAt, options.seasonNumber, windowNumber, options.tier)
|
|
74
77
|
.accounts(accounts)
|
|
75
78
|
.instruction();
|
|
76
79
|
// Build signers
|
|
@@ -97,7 +100,7 @@ async function createMiztake(options) {
|
|
|
97
100
|
newMiztakeId = new anchor_1.BN(1); // Placeholder
|
|
98
101
|
}
|
|
99
102
|
// 3. Initialize UserWindowParticipation
|
|
100
|
-
const updatedUserWindowParticipation = (0, optimistic_1.initializeUserWindowParticipation)(options.user, options.seasonNumber,
|
|
103
|
+
const updatedUserWindowParticipation = (0, optimistic_1.initializeUserWindowParticipation)(options.user, options.seasonNumber, windowNumber, options.tier, newMiztakeId);
|
|
101
104
|
// 4. Initialize RewardWindow if needed
|
|
102
105
|
let updatedRewardWindow;
|
|
103
106
|
if (curr.rewardWindow) {
|
|
@@ -105,14 +108,14 @@ async function createMiztake(options) {
|
|
|
105
108
|
if ((0, enumHelpers_1.isWindowState)(curr.rewardWindow.windowState, types_1.WindowState.Uninitialized) &&
|
|
106
109
|
curr.season &&
|
|
107
110
|
curr.seasonSettings) {
|
|
108
|
-
updatedRewardWindow = (0, optimistic_1.initializeRewardWindow)(options.seasonNumber,
|
|
111
|
+
updatedRewardWindow = (0, optimistic_1.initializeRewardWindow)(options.seasonNumber, windowNumber, curr.season, curr.seasonSettings.windowDuration);
|
|
109
112
|
}
|
|
110
113
|
else {
|
|
111
114
|
updatedRewardWindow = curr.rewardWindow;
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
else if (curr.season && curr.seasonSettings) {
|
|
115
|
-
updatedRewardWindow = (0, optimistic_1.initializeRewardWindow)(options.seasonNumber,
|
|
118
|
+
updatedRewardWindow = (0, optimistic_1.initializeRewardWindow)(options.seasonNumber, windowNumber, curr.season, curr.seasonSettings.windowDuration);
|
|
116
119
|
}
|
|
117
120
|
// 5. Build expected Miztake object
|
|
118
121
|
const miztake = {
|
|
@@ -123,7 +126,7 @@ async function createMiztake(options) {
|
|
|
123
126
|
averageHash: options.params.averageHash,
|
|
124
127
|
differenceHash: options.params.differenceHash,
|
|
125
128
|
waveletHash: options.params.waveletHash,
|
|
126
|
-
shaHash
|
|
129
|
+
shaHash,
|
|
127
130
|
computedAt: options.params.computedAt,
|
|
128
131
|
creator: options.user,
|
|
129
132
|
userStats: pdas.userStats,
|
|
@@ -156,7 +159,7 @@ async function createMiztake(options) {
|
|
|
156
159
|
*/
|
|
157
160
|
function getMiztakePdaForParams(params) {
|
|
158
161
|
return pdaManager_1.PDAManager.deriveMiztakePdas({
|
|
159
|
-
shaHash: params.shaHash,
|
|
162
|
+
shaHash: (0, conversions_1.toSha256HexString)(params.shaHash),
|
|
160
163
|
telegramId: params.telegramId,
|
|
161
164
|
seasonNumber: new anchor_1.BN(0),
|
|
162
165
|
windowNumber: new anchor_1.BN(0),
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { Connection, PublicKey
|
|
2
|
-
import { SignerInfo } from "../utils/signerHelpers";
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
2
|
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
import { StandardInstructionResultWithPdas } from "../types/instructionResults";
|
|
4
4
|
/**
|
|
5
5
|
* Initialize season escrow vault
|
|
6
6
|
*
|
|
7
7
|
* Single signer: admin (pays for account creation)
|
|
8
8
|
* This initializes the token vault for escrowed (protected) deposits.
|
|
9
9
|
*/
|
|
10
|
-
export declare function initializeEscrowVault(connection: Connection, admin: PublicKey, seasonNumber: BN, feePayer?: PublicKey): Promise<{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
pdas: {
|
|
14
|
-
vault: PublicKey;
|
|
15
|
-
};
|
|
16
|
-
}>;
|
|
10
|
+
export declare function initializeEscrowVault(connection: Connection, admin: PublicKey, seasonNumber: BN, feePayer?: PublicKey): Promise<StandardInstructionResultWithPdas<{
|
|
11
|
+
vault: PublicKey;
|
|
12
|
+
}>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection, PublicKey
|
|
2
|
-
import {
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { StandardInstructionResultWithPdas } from "../types/instructionResults";
|
|
3
3
|
/**
|
|
4
4
|
* Initialize season settings
|
|
5
5
|
*
|
|
@@ -11,10 +11,6 @@ import { SignerInfo } from "../utils/signerHelpers";
|
|
|
11
11
|
* @param feePayer - Optional separate fee payer for transaction fees
|
|
12
12
|
* @returns Instructions, signers array, and season settings PDA
|
|
13
13
|
*/
|
|
14
|
-
export declare function initializeSeasonSettings(connection: Connection, admin: PublicKey, feePayer?: PublicKey): Promise<{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
pdas: {
|
|
18
|
-
seasonSettings: PublicKey;
|
|
19
|
-
};
|
|
20
|
-
}>;
|
|
14
|
+
export declare function initializeSeasonSettings(connection: Connection, admin: PublicKey, feePayer?: PublicKey): Promise<StandardInstructionResultWithPdas<{
|
|
15
|
+
seasonSettings: PublicKey;
|
|
16
|
+
}>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Connection, PublicKey
|
|
2
|
-
import { SignerInfo } from "../utils/signerHelpers";
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
2
|
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
import { StandardInstructionResultWithPdas } from "../types/instructionResults";
|
|
4
4
|
/**
|
|
5
5
|
* Initialize season deposit vault
|
|
6
6
|
*
|
|
@@ -12,10 +12,6 @@ import { BN } from "@coral-xyz/anchor";
|
|
|
12
12
|
* @param feePayer - Optional separate fee payer for transaction fees
|
|
13
13
|
* @returns Instructions, signers array, and vault PDA
|
|
14
14
|
*/
|
|
15
|
-
export declare function initializeSeasonVault(connection: Connection, admin: PublicKey, seasonNumber: BN, feePayer?: PublicKey): Promise<{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
pdas: {
|
|
19
|
-
vault: PublicKey;
|
|
20
|
-
};
|
|
21
|
-
}>;
|
|
15
|
+
export declare function initializeSeasonVault(connection: Connection, admin: PublicKey, seasonNumber: BN, feePayer?: PublicKey): Promise<StandardInstructionResultWithPdas<{
|
|
16
|
+
vault: PublicKey;
|
|
17
|
+
}>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Connection, PublicKey
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { StandardInstructionResultWithPdas } from "../types/instructionResults";
|
|
2
3
|
/**
|
|
3
4
|
* Initialize the global statistics PDA
|
|
4
5
|
*
|
|
@@ -18,12 +19,10 @@ import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
|
18
19
|
* );
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
export declare function initializeStatistics(connection: Connection, admin: PublicKey, payer?: PublicKey): Promise<{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
role: string;
|
|
26
|
-
}[];
|
|
22
|
+
export declare function initializeStatistics(connection: Connection, admin: PublicKey, payer?: PublicKey): Promise<StandardInstructionResultWithPdas<{
|
|
23
|
+
miztakeStatistics: PublicKey;
|
|
24
|
+
}> & {
|
|
25
|
+
/** Back-compat alias (same as `pdas.miztakeStatistics`) */
|
|
27
26
|
miztakeStatisticsPda: PublicKey;
|
|
28
27
|
}>;
|
|
29
28
|
/**
|
|
@@ -7,6 +7,7 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
7
7
|
const pdas_1 = require("../utils/pdas");
|
|
8
8
|
const idl_1 = require("../idl/idl");
|
|
9
9
|
const anchorHelpers_1 = require("../utils/anchorHelpers");
|
|
10
|
+
const signerHelpers_1 = require("../utils/signerHelpers");
|
|
10
11
|
/**
|
|
11
12
|
* Initialize the global statistics PDA
|
|
12
13
|
*
|
|
@@ -29,7 +30,7 @@ const anchorHelpers_1 = require("../utils/anchorHelpers");
|
|
|
29
30
|
async function initializeStatistics(connection, admin, payer) {
|
|
30
31
|
// Create program instance
|
|
31
32
|
const provider = (0, anchorHelpers_1.createReadOnlyProvider)(connection);
|
|
32
|
-
const program = new anchor_1.Program(idl_1.
|
|
33
|
+
const program = new anchor_1.Program(idl_1.ANCHOR_IDL, provider);
|
|
33
34
|
const actualPayer = payer || admin;
|
|
34
35
|
// Derive PDA
|
|
35
36
|
const [miztakeStatisticsPda] = (0, pdas_1.getMiztakeStatisticsPda)();
|
|
@@ -44,15 +45,17 @@ async function initializeStatistics(connection, admin, payer) {
|
|
|
44
45
|
.initializeStatistics()
|
|
45
46
|
.accounts(accounts)
|
|
46
47
|
.instruction();
|
|
47
|
-
// Build signers list
|
|
48
|
-
const
|
|
49
|
-
if (actualPayer.
|
|
50
|
-
|
|
48
|
+
// Build signers list (admin always; payer if distinct)
|
|
49
|
+
const required = [{ publicKey: admin, role: "admin" }];
|
|
50
|
+
if (!actualPayer.equals(admin)) {
|
|
51
|
+
required.push({ publicKey: actualPayer, role: "payer" });
|
|
51
52
|
}
|
|
53
|
+
const signers = (0, signerHelpers_1.buildSigners)(required);
|
|
52
54
|
return {
|
|
53
55
|
instructions: [instruction],
|
|
54
56
|
signers,
|
|
55
|
-
|
|
57
|
+
pdas: { miztakeStatistics: miztakeStatisticsPda },
|
|
58
|
+
miztakeStatisticsPda, // Back-compat alias
|
|
56
59
|
};
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
@@ -62,9 +65,10 @@ async function isInitialized(connection) {
|
|
|
62
65
|
try {
|
|
63
66
|
// Create program instance
|
|
64
67
|
const provider = (0, anchorHelpers_1.createReadOnlyProvider)(connection);
|
|
65
|
-
const program = new anchor_1.Program(idl_1.
|
|
68
|
+
const program = new anchor_1.Program(idl_1.ANCHOR_IDL, provider);
|
|
66
69
|
const [statisticsPda] = (0, pdas_1.getMiztakeStatisticsPda)();
|
|
67
|
-
await program.account.miztakeStatistics.fetch(statisticsPda);
|
|
70
|
+
const stats = await program.account.miztakeStatistics.fetch(statisticsPda);
|
|
71
|
+
void stats;
|
|
68
72
|
return true;
|
|
69
73
|
}
|
|
70
74
|
catch {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BN } from "@coral-xyz/anchor";
|
|
2
|
-
import { Connection, PublicKey
|
|
3
|
-
import { Season, SeasonMembership, SeasonSettings } from "../types";
|
|
4
|
-
import {
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { Season, SeasonMembership, SeasonSettings, TierNumber } from "../types";
|
|
4
|
+
import { StandardInstructionResultWithPdas } from "../types/instructionResults";
|
|
5
5
|
/**
|
|
6
6
|
* Options for joinSeason instruction
|
|
7
7
|
*/
|
|
@@ -11,7 +11,7 @@ export interface JoinSeasonOptions {
|
|
|
11
11
|
userTokenAccount: PublicKey;
|
|
12
12
|
seasonNumber: BN;
|
|
13
13
|
/** Tier number: 1=copper, 2=silver, 3=gold, 4=platinum, 5=mithril */
|
|
14
|
-
tier:
|
|
14
|
+
tier: TierNumber;
|
|
15
15
|
/** Optional referrer (PublicKey.default means no referrer) */
|
|
16
16
|
referrer?: PublicKey;
|
|
17
17
|
/** Optional injected timestamp (seconds) for optimistic state calculation */
|
|
@@ -22,6 +22,18 @@ export interface JoinSeasonOptions {
|
|
|
22
22
|
season?: Season;
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
+
type JoinSeasonPdas = {
|
|
26
|
+
seasonSettings: PublicKey;
|
|
27
|
+
season: PublicKey;
|
|
28
|
+
seasonMembership: PublicKey;
|
|
29
|
+
seasonDepositVault: PublicKey;
|
|
30
|
+
seasonEscrowVault: PublicKey;
|
|
31
|
+
};
|
|
32
|
+
type JoinSeasonUpdatedAccounts = {
|
|
33
|
+
seasonSettings?: SeasonSettings;
|
|
34
|
+
season?: Season;
|
|
35
|
+
seasonMembership?: SeasonMembership;
|
|
36
|
+
};
|
|
25
37
|
/**
|
|
26
38
|
* Join a season
|
|
27
39
|
*
|
|
@@ -32,19 +44,5 @@ export interface JoinSeasonOptions {
|
|
|
32
44
|
* @param options - Join season options
|
|
33
45
|
* @returns Instructions, signers, PDAs, and optimistically created/updated accounts
|
|
34
46
|
*/
|
|
35
|
-
export declare function joinSeason(options: JoinSeasonOptions): Promise<
|
|
36
|
-
|
|
37
|
-
signers: SignerInfo[];
|
|
38
|
-
pdas: {
|
|
39
|
-
seasonSettings: PublicKey;
|
|
40
|
-
season: PublicKey;
|
|
41
|
-
seasonMembership: PublicKey;
|
|
42
|
-
seasonDepositVault: PublicKey;
|
|
43
|
-
seasonEscrowVault: PublicKey;
|
|
44
|
-
};
|
|
45
|
-
updatedAccounts?: {
|
|
46
|
-
seasonSettings?: SeasonSettings;
|
|
47
|
-
season?: Season;
|
|
48
|
-
seasonMembership?: SeasonMembership;
|
|
49
|
-
};
|
|
50
|
-
}>;
|
|
47
|
+
export declare function joinSeason(options: JoinSeasonOptions): Promise<StandardInstructionResultWithPdas<JoinSeasonPdas, JoinSeasonUpdatedAccounts>>;
|
|
48
|
+
export {};
|
|
@@ -12,6 +12,7 @@ const signerHelpers_1 = require("../utils/signerHelpers");
|
|
|
12
12
|
const optimistic_1 = require("../optimistic");
|
|
13
13
|
const pdas_1 = require("../utils/pdas");
|
|
14
14
|
const tierPenalty_1 = require("../utils/tierPenalty");
|
|
15
|
+
const enumHelpers_1 = require("../utils/enumHelpers");
|
|
15
16
|
/**
|
|
16
17
|
* Join a season
|
|
17
18
|
*
|
|
@@ -63,7 +64,7 @@ async function joinSeason(options) {
|
|
|
63
64
|
const depositFull = perWindowPenalty.muln(totalWindows);
|
|
64
65
|
let joinedWindowNumber = new anchor_1.BN(0);
|
|
65
66
|
if (curr.season) {
|
|
66
|
-
if (curr.season.seasonState
|
|
67
|
+
if ((0, enumHelpers_1.isSeasonState)(curr.season.seasonState, types_1.SeasonState.Uninitialized)) {
|
|
67
68
|
// On-chain: season is initialized with started_at = now, so elapsed = 0 -> current_window = 0
|
|
68
69
|
joinedWindowNumber = new anchor_1.BN(0);
|
|
69
70
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Connection, PublicKey
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { SeasonSettings } from "../types";
|
|
3
|
-
import {
|
|
3
|
+
import { StandardInstructionResultWithPdas } from "../types/instructionResults";
|
|
4
4
|
/**
|
|
5
5
|
* Toggle season system pause
|
|
6
6
|
*
|
|
@@ -13,10 +13,8 @@ import { SignerInfo } from "../utils/signerHelpers";
|
|
|
13
13
|
* @param seasonSettings - Optional season settings (returns updated version)
|
|
14
14
|
* @returns Instructions, signers, and optimistically updated settings
|
|
15
15
|
*/
|
|
16
|
-
export declare function toggleSeasonPause(connection: Connection, admin: PublicKey, feePayer?: PublicKey, seasonSettings?: SeasonSettings): Promise<{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
}>;
|
|
16
|
+
export declare function toggleSeasonPause(connection: Connection, admin: PublicKey, feePayer?: PublicKey, seasonSettings?: SeasonSettings): Promise<StandardInstructionResultWithPdas<{
|
|
17
|
+
seasonSettings: PublicKey;
|
|
18
|
+
}, {
|
|
19
|
+
seasonSettings: SeasonSettings;
|
|
20
|
+
}>>;
|
|
@@ -35,6 +35,7 @@ async function toggleSeasonPause(connection, admin, feePayer, seasonSettings) {
|
|
|
35
35
|
return {
|
|
36
36
|
instructions: [instruction],
|
|
37
37
|
signers,
|
|
38
|
+
pdas: { seasonSettings: seasonSettingsPda },
|
|
38
39
|
...(updatedSettings && {
|
|
39
40
|
updatedAccounts: { seasonSettings: updatedSettings },
|
|
40
41
|
}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Connection, PublicKey
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { SeasonSettings } from "../types";
|
|
3
|
-
import {
|
|
3
|
+
import { StandardInstructionResultWithPdas } from "../types/instructionResults";
|
|
4
4
|
/**
|
|
5
5
|
* Update season admin
|
|
6
6
|
*
|
|
@@ -14,10 +14,8 @@ import { SignerInfo } from "../utils/signerHelpers";
|
|
|
14
14
|
* @param seasonSettings - Optional season settings (returns updated version)
|
|
15
15
|
* @returns Instructions, signers, and optimistically updated settings
|
|
16
16
|
*/
|
|
17
|
-
export declare function updateSeasonAdmin(connection: Connection, currentAdmin: PublicKey, newAdmin: PublicKey, feePayer?: PublicKey, seasonSettings?: SeasonSettings): Promise<{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
}>;
|
|
17
|
+
export declare function updateSeasonAdmin(connection: Connection, currentAdmin: PublicKey, newAdmin: PublicKey, feePayer?: PublicKey, seasonSettings?: SeasonSettings): Promise<StandardInstructionResultWithPdas<{
|
|
18
|
+
seasonSettings: PublicKey;
|
|
19
|
+
}, {
|
|
20
|
+
seasonSettings: SeasonSettings;
|
|
21
|
+
}>>;
|
|
@@ -36,6 +36,7 @@ async function updateSeasonAdmin(connection, currentAdmin, newAdmin, feePayer, s
|
|
|
36
36
|
return {
|
|
37
37
|
instructions: [instruction],
|
|
38
38
|
signers,
|
|
39
|
+
pdas: { seasonSettings: seasonSettingsPda },
|
|
39
40
|
...(updatedSettings && {
|
|
40
41
|
updatedAccounts: { seasonSettings: updatedSettings },
|
|
41
42
|
}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { BN } from "@coral-xyz/anchor";
|
|
3
|
-
import { SeasonMembershipStatusView } from "../types";
|
|
3
|
+
import { SeasonMembershipStatusView, TierNumber } from "../types";
|
|
4
4
|
/**
|
|
5
5
|
* View season membership status (read-only)
|
|
6
6
|
*
|
|
@@ -13,4 +13,4 @@ import { SeasonMembershipStatusView } from "../types";
|
|
|
13
13
|
* @param tier - Tier number: 1=copper, 2=silver, 3=gold, 4=platinum, 5=mithril
|
|
14
14
|
* @returns View data with membership status
|
|
15
15
|
*/
|
|
16
|
-
export declare function viewSeasonMembershipStatus(connection: Connection, user: PublicKey, seasonNumber: BN, tier:
|
|
16
|
+
export declare function viewSeasonMembershipStatus(connection: Connection, user: PublicKey, seasonNumber: BN, tier: TierNumber): Promise<SeasonMembershipStatusView>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection } from "@solana/web3.js";
|
|
2
2
|
import { BN } from "@coral-xyz/anchor";
|
|
3
|
-
import { WindowStatusView } from "../types";
|
|
3
|
+
import { WindowNumberLike, WindowStatusView } from "../types";
|
|
4
4
|
/**
|
|
5
5
|
* View window status (read-only)
|
|
6
6
|
*
|
|
@@ -12,4 +12,4 @@ import { WindowStatusView } from "../types";
|
|
|
12
12
|
* @param windowNumber - Window number
|
|
13
13
|
* @returns View data with window status
|
|
14
14
|
*/
|
|
15
|
-
export declare function viewWindowStatus(connection: Connection, seasonNumber: BN, windowNumber:
|
|
15
|
+
export declare function viewWindowStatus(connection: Connection, seasonNumber: BN, windowNumber: WindowNumberLike): Promise<WindowStatusView>;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.viewWindowStatus = viewWindowStatus;
|
|
4
4
|
const pdas_1 = require("../utils/pdas");
|
|
5
5
|
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
const conversions_1 = require("../utils/conversions");
|
|
6
7
|
/**
|
|
7
8
|
* View window status (read-only)
|
|
8
9
|
*
|
|
@@ -16,7 +17,8 @@ const programHelpers_1 = require("../utils/programHelpers");
|
|
|
16
17
|
*/
|
|
17
18
|
async function viewWindowStatus(connection, seasonNumber, windowNumber) {
|
|
18
19
|
const program = (0, programHelpers_1.getProgram)(connection);
|
|
19
|
-
const
|
|
20
|
+
const windowBn = (0, conversions_1.toWindowNumberBn)(windowNumber);
|
|
21
|
+
const [rewardWindowPda] = (0, pdas_1.getRewardWindowPda)(seasonNumber, windowBn);
|
|
20
22
|
const accounts = {
|
|
21
23
|
rewardWindow: rewardWindowPda,
|
|
22
24
|
};
|