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,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toggleSeasonPause = toggleSeasonPause;
|
|
4
|
+
const pdas_1 = require("../utils/pdas");
|
|
5
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
const signerHelpers_1 = require("../utils/signerHelpers");
|
|
7
|
+
const optimistic_1 = require("../optimistic");
|
|
8
|
+
/**
|
|
9
|
+
* Toggle season system pause
|
|
10
|
+
*
|
|
11
|
+
* Single signer: admin (season admin)
|
|
12
|
+
* Toggles the isPaused flag on season settings
|
|
13
|
+
*
|
|
14
|
+
* @param connection - Solana connection
|
|
15
|
+
* @param admin - Season admin's public key
|
|
16
|
+
* @param feePayer - Optional separate fee payer for transaction fees
|
|
17
|
+
* @param seasonSettings - Optional season settings (returns updated version)
|
|
18
|
+
* @returns Instructions, signers, and optimistically updated settings
|
|
19
|
+
*/
|
|
20
|
+
async function toggleSeasonPause(connection, admin, feePayer, seasonSettings) {
|
|
21
|
+
const program = (0, programHelpers_1.getProgram)(connection);
|
|
22
|
+
const [seasonSettingsPda] = (0, pdas_1.getSeasonSettingsPda)();
|
|
23
|
+
const accounts = {
|
|
24
|
+
seasonSettings: seasonSettingsPda,
|
|
25
|
+
admin: admin,
|
|
26
|
+
};
|
|
27
|
+
const instruction = await program.methods
|
|
28
|
+
.toggleSeasonPause()
|
|
29
|
+
.accounts(accounts)
|
|
30
|
+
.instruction();
|
|
31
|
+
const signers = (0, signerHelpers_1.buildSigners)([{ publicKey: admin, role: "admin" }], feePayer);
|
|
32
|
+
const updatedSettings = seasonSettings
|
|
33
|
+
? (0, optimistic_1.updateSeasonSettingsForPauseToggle)(seasonSettings)
|
|
34
|
+
: undefined;
|
|
35
|
+
return {
|
|
36
|
+
instructions: [instruction],
|
|
37
|
+
signers,
|
|
38
|
+
...(updatedSettings && {
|
|
39
|
+
updatedAccounts: { seasonSettings: updatedSettings },
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { SeasonSettings } from "../types";
|
|
3
|
+
import { SignerInfo } from "../utils/signerHelpers";
|
|
4
|
+
/**
|
|
5
|
+
* Update season admin
|
|
6
|
+
*
|
|
7
|
+
* Single signer: current admin
|
|
8
|
+
* Updates the admin field on season settings
|
|
9
|
+
*
|
|
10
|
+
* @param connection - Solana connection
|
|
11
|
+
* @param currentAdmin - Current season admin's public key
|
|
12
|
+
* @param newAdmin - New admin public key
|
|
13
|
+
* @param feePayer - Optional separate fee payer for transaction fees
|
|
14
|
+
* @param seasonSettings - Optional season settings (returns updated version)
|
|
15
|
+
* @returns Instructions, signers, and optimistically updated settings
|
|
16
|
+
*/
|
|
17
|
+
export declare function updateSeasonAdmin(connection: Connection, currentAdmin: PublicKey, newAdmin: PublicKey, feePayer?: PublicKey, seasonSettings?: SeasonSettings): Promise<{
|
|
18
|
+
instructions: TransactionInstruction[];
|
|
19
|
+
signers: SignerInfo[];
|
|
20
|
+
updatedAccounts?: {
|
|
21
|
+
seasonSettings: SeasonSettings;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateSeasonAdmin = updateSeasonAdmin;
|
|
4
|
+
const pdas_1 = require("../utils/pdas");
|
|
5
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
const signerHelpers_1 = require("../utils/signerHelpers");
|
|
7
|
+
const optimistic_1 = require("../optimistic");
|
|
8
|
+
/**
|
|
9
|
+
* Update season admin
|
|
10
|
+
*
|
|
11
|
+
* Single signer: current admin
|
|
12
|
+
* Updates the admin field on season settings
|
|
13
|
+
*
|
|
14
|
+
* @param connection - Solana connection
|
|
15
|
+
* @param currentAdmin - Current season admin's public key
|
|
16
|
+
* @param newAdmin - New admin public key
|
|
17
|
+
* @param feePayer - Optional separate fee payer for transaction fees
|
|
18
|
+
* @param seasonSettings - Optional season settings (returns updated version)
|
|
19
|
+
* @returns Instructions, signers, and optimistically updated settings
|
|
20
|
+
*/
|
|
21
|
+
async function updateSeasonAdmin(connection, currentAdmin, newAdmin, feePayer, seasonSettings) {
|
|
22
|
+
const program = (0, programHelpers_1.getProgram)(connection);
|
|
23
|
+
const [seasonSettingsPda] = (0, pdas_1.getSeasonSettingsPda)();
|
|
24
|
+
const accounts = {
|
|
25
|
+
seasonSettings: seasonSettingsPda,
|
|
26
|
+
currentAdmin: currentAdmin,
|
|
27
|
+
};
|
|
28
|
+
const instruction = await program.methods
|
|
29
|
+
.updateSeasonAdmin(newAdmin)
|
|
30
|
+
.accounts(accounts)
|
|
31
|
+
.instruction();
|
|
32
|
+
const signers = (0, signerHelpers_1.buildSigners)([{ publicKey: currentAdmin, role: "currentAdmin" }], feePayer);
|
|
33
|
+
const updatedSettings = seasonSettings
|
|
34
|
+
? (0, optimistic_1.updateSeasonSettingsForAdminUpdate)(seasonSettings, newAdmin)
|
|
35
|
+
: undefined;
|
|
36
|
+
return {
|
|
37
|
+
instructions: [instruction],
|
|
38
|
+
signers,
|
|
39
|
+
...(updatedSettings && {
|
|
40
|
+
updatedAccounts: { seasonSettings: updatedSettings },
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Connection } from "@solana/web3.js";
|
|
2
|
+
import { CurrentSeasonView } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* View current season (read-only)
|
|
5
|
+
*
|
|
6
|
+
* No signers required
|
|
7
|
+
* Returns view struct with current season details
|
|
8
|
+
*
|
|
9
|
+
* @param connection - Solana connection
|
|
10
|
+
* @returns View data with current season info
|
|
11
|
+
*/
|
|
12
|
+
export declare function viewCurrentSeason(connection: Connection): Promise<CurrentSeasonView>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.viewCurrentSeason = viewCurrentSeason;
|
|
4
|
+
const pdas_1 = require("../utils/pdas");
|
|
5
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
/**
|
|
7
|
+
* View current season (read-only)
|
|
8
|
+
*
|
|
9
|
+
* No signers required
|
|
10
|
+
* Returns view struct with current season details
|
|
11
|
+
*
|
|
12
|
+
* @param connection - Solana connection
|
|
13
|
+
* @returns View data with current season info
|
|
14
|
+
*/
|
|
15
|
+
async function viewCurrentSeason(connection) {
|
|
16
|
+
const program = (0, programHelpers_1.getProgram)(connection);
|
|
17
|
+
const [seasonSettingsPda] = (0, pdas_1.getSeasonSettingsPda)();
|
|
18
|
+
// The view requires the Season account as well; derive it from SeasonSettings.currentSeasonNumber.
|
|
19
|
+
const seasonSettings = await program.account.seasonSettings.fetch(seasonSettingsPda);
|
|
20
|
+
const [seasonPda] = (0, pdas_1.getSeasonPda)(seasonSettings.currentSeasonNumber);
|
|
21
|
+
const accounts = {
|
|
22
|
+
seasonSettings: seasonSettingsPda,
|
|
23
|
+
season: seasonPda,
|
|
24
|
+
};
|
|
25
|
+
const result = await program.methods
|
|
26
|
+
.viewCurrentSeason()
|
|
27
|
+
.accounts(accounts)
|
|
28
|
+
.view();
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
import { SeasonMembershipStatusView } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* View season membership status (read-only)
|
|
6
|
+
*
|
|
7
|
+
* No signers required
|
|
8
|
+
* Returns view struct with membership details
|
|
9
|
+
*
|
|
10
|
+
* @param connection - Solana connection
|
|
11
|
+
* @param user - User's public key
|
|
12
|
+
* @param seasonMembershipId - Membership ID
|
|
13
|
+
* @param seasonNumber - Season number
|
|
14
|
+
* @returns View data with membership status
|
|
15
|
+
*/
|
|
16
|
+
export declare function viewSeasonMembershipStatus(connection: Connection, user: PublicKey, seasonMembershipId: BN, seasonNumber: BN): Promise<SeasonMembershipStatusView>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.viewSeasonMembershipStatus = viewSeasonMembershipStatus;
|
|
4
|
+
const pdas_1 = require("../utils/pdas");
|
|
5
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
/**
|
|
7
|
+
* View season membership status (read-only)
|
|
8
|
+
*
|
|
9
|
+
* No signers required
|
|
10
|
+
* Returns view struct with membership details
|
|
11
|
+
*
|
|
12
|
+
* @param connection - Solana connection
|
|
13
|
+
* @param user - User's public key
|
|
14
|
+
* @param seasonMembershipId - Membership ID
|
|
15
|
+
* @param seasonNumber - Season number
|
|
16
|
+
* @returns View data with membership status
|
|
17
|
+
*/
|
|
18
|
+
async function viewSeasonMembershipStatus(connection, user, seasonMembershipId, seasonNumber) {
|
|
19
|
+
const program = (0, programHelpers_1.getProgram)(connection);
|
|
20
|
+
const [seasonSettingsPda] = (0, pdas_1.getSeasonSettingsPda)();
|
|
21
|
+
const [seasonMembershipPda] = (0, pdas_1.getSeasonMembershipPda)(user, seasonMembershipId);
|
|
22
|
+
const [seasonPda] = (0, pdas_1.getSeasonPda)(seasonNumber);
|
|
23
|
+
const accounts = {
|
|
24
|
+
seasonSettings: seasonSettingsPda,
|
|
25
|
+
seasonMembership: seasonMembershipPda,
|
|
26
|
+
season: seasonPda,
|
|
27
|
+
};
|
|
28
|
+
const result = await program.methods
|
|
29
|
+
.viewSeasonMembershipStatus()
|
|
30
|
+
.accounts(accounts)
|
|
31
|
+
.view();
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Connection } from "@solana/web3.js";
|
|
2
|
+
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
import { WindowStatusView } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* View window status (read-only)
|
|
6
|
+
*
|
|
7
|
+
* No signers required
|
|
8
|
+
* Returns view struct with window details
|
|
9
|
+
*
|
|
10
|
+
* @param connection - Solana connection
|
|
11
|
+
* @param seasonNumber - Season number
|
|
12
|
+
* @param windowNumber - Window number
|
|
13
|
+
* @returns View data with window status
|
|
14
|
+
*/
|
|
15
|
+
export declare function viewWindowStatus(connection: Connection, seasonNumber: BN, windowNumber: BN): Promise<WindowStatusView>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.viewWindowStatus = viewWindowStatus;
|
|
4
|
+
const pdas_1 = require("../utils/pdas");
|
|
5
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
/**
|
|
7
|
+
* View window status (read-only)
|
|
8
|
+
*
|
|
9
|
+
* No signers required
|
|
10
|
+
* Returns view struct with window details
|
|
11
|
+
*
|
|
12
|
+
* @param connection - Solana connection
|
|
13
|
+
* @param seasonNumber - Season number
|
|
14
|
+
* @param windowNumber - Window number
|
|
15
|
+
* @returns View data with window status
|
|
16
|
+
*/
|
|
17
|
+
async function viewWindowStatus(connection, seasonNumber, windowNumber) {
|
|
18
|
+
const program = (0, programHelpers_1.getProgram)(connection);
|
|
19
|
+
const [rewardWindowPda] = (0, pdas_1.getRewardWindowPda)(seasonNumber, windowNumber);
|
|
20
|
+
const accounts = {
|
|
21
|
+
rewardWindow: rewardWindowPda,
|
|
22
|
+
};
|
|
23
|
+
const result = await program.methods
|
|
24
|
+
.viewWindowStatus()
|
|
25
|
+
.accounts(accounts)
|
|
26
|
+
.view();
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { SeasonSettings, Season, SeasonMembership } from "../types";
|
|
4
|
+
import { StandardInstructionResult } from "../types/instructionResults";
|
|
5
|
+
type WithdrawSeasonDepositUpdatedAccounts = {
|
|
6
|
+
seasonSettings?: SeasonSettings;
|
|
7
|
+
season?: Season;
|
|
8
|
+
seasonMembership?: SeasonMembership;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Options for withdrawSeasonDeposit instruction
|
|
12
|
+
*/
|
|
13
|
+
export interface WithdrawSeasonDepositOptions {
|
|
14
|
+
connection: Connection;
|
|
15
|
+
user: PublicKey;
|
|
16
|
+
userTokenAccount: PublicKey;
|
|
17
|
+
seasonMembershipId: BN;
|
|
18
|
+
feePayer?: PublicKey;
|
|
19
|
+
currentAccounts?: {
|
|
20
|
+
seasonSettings?: SeasonSettings;
|
|
21
|
+
season?: Season;
|
|
22
|
+
seasonMembership?: SeasonMembership;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Withdraw season deposit
|
|
27
|
+
*
|
|
28
|
+
* Single signer: user
|
|
29
|
+
* Transfers remaining deposit from vault to user
|
|
30
|
+
* May finalize season on first withdrawal
|
|
31
|
+
*
|
|
32
|
+
* @param options - Withdraw season deposit options
|
|
33
|
+
* @returns Instructions, signers, withdrawal amount, and optimistically updated accounts
|
|
34
|
+
*/
|
|
35
|
+
export declare function withdrawSeasonDeposit(options: WithdrawSeasonDepositOptions): Promise<StandardInstructionResult<Record<string, PublicKey>, WithdrawSeasonDepositUpdatedAccounts, {
|
|
36
|
+
withdrawalAmount: BN;
|
|
37
|
+
}>>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withdrawSeasonDeposit = withdrawSeasonDeposit;
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const pdaManager_1 = require("../utils/pdaManager");
|
|
6
|
+
const constants_1 = require("../utils/constants");
|
|
7
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
8
|
+
const signerHelpers_1 = require("../utils/signerHelpers");
|
|
9
|
+
const optimistic_1 = require("../optimistic");
|
|
10
|
+
/**
|
|
11
|
+
* Withdraw season deposit
|
|
12
|
+
*
|
|
13
|
+
* Single signer: user
|
|
14
|
+
* Transfers remaining deposit from vault to user
|
|
15
|
+
* May finalize season on first withdrawal
|
|
16
|
+
*
|
|
17
|
+
* @param options - Withdraw season deposit options
|
|
18
|
+
* @returns Instructions, signers, withdrawal amount, and optimistically updated accounts
|
|
19
|
+
*/
|
|
20
|
+
async function withdrawSeasonDeposit(options) {
|
|
21
|
+
const program = (0, programHelpers_1.getProgram)(options.connection);
|
|
22
|
+
const curr = options.currentAccounts || {};
|
|
23
|
+
if (!curr.seasonMembership) {
|
|
24
|
+
throw new Error("seasonMembership required for withdrawSeasonDeposit");
|
|
25
|
+
}
|
|
26
|
+
const seasonNumber = curr.seasonMembership.seasonNumber;
|
|
27
|
+
const pdas = pdaManager_1.PDAManager.deriveWithdrawDepositPdas({
|
|
28
|
+
user: options.user,
|
|
29
|
+
seasonNumber,
|
|
30
|
+
seasonMembershipId: options.seasonMembershipId,
|
|
31
|
+
});
|
|
32
|
+
const accounts = {
|
|
33
|
+
seasonSettings: pdas.seasonSettings,
|
|
34
|
+
season: pdas.season,
|
|
35
|
+
seasonMembership: pdas.seasonMembership,
|
|
36
|
+
seasonDepositVault: pdas.seasonDepositVault,
|
|
37
|
+
seasonEscrowVault: pdas.seasonEscrowVault,
|
|
38
|
+
mizdMint: constants_1.MIZD_TOKEN_MINT,
|
|
39
|
+
userTokenAccount: options.userTokenAccount,
|
|
40
|
+
user: options.user,
|
|
41
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
42
|
+
};
|
|
43
|
+
const instruction = await program.methods
|
|
44
|
+
.withdrawSeasonDeposit()
|
|
45
|
+
.accounts(accounts)
|
|
46
|
+
.instruction();
|
|
47
|
+
const signers = (0, signerHelpers_1.buildSigners)([{ publicKey: options.user, role: "user" }], options.feePayer);
|
|
48
|
+
// OPTIMISTIC UPDATES
|
|
49
|
+
let withdrawalAmount;
|
|
50
|
+
let updatedAccounts = undefined;
|
|
51
|
+
if (curr.seasonMembership && curr.season && curr.seasonSettings) {
|
|
52
|
+
const result = (0, optimistic_1.calculateWithdrawalAmount)(curr.seasonMembership, curr.season, curr.seasonSettings);
|
|
53
|
+
withdrawalAmount = result.withdrawalAmount;
|
|
54
|
+
updatedAccounts = {
|
|
55
|
+
seasonSettings: result.updatedSettings,
|
|
56
|
+
season: result.updatedSeason,
|
|
57
|
+
seasonMembership: result.updatedMembership,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
instructions: [instruction],
|
|
62
|
+
signers,
|
|
63
|
+
...(updatedAccounts && { updatedAccounts }),
|
|
64
|
+
...(withdrawalAmount && { metadata: { withdrawalAmount } }),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimistic account updates
|
|
3
|
+
*
|
|
4
|
+
* This module contains all optimistic update logic separated from instruction building.
|
|
5
|
+
* Each function mirrors the on-chain logic to predict state changes before confirmation.
|
|
6
|
+
*/
|
|
7
|
+
export { getCurrentTimestamp, createEmptyUserStats, initializeUserStats, updateUserStatsForMiztakeCreation, updateMiztakeStatisticsForCreation, initializeUserWindowParticipation, initializeRewardWindow, updateMiztakeForSeasonUse, initializeSeasonMembership, updateSeasonForJoin, updateWindowForConfirmation, updateParticipationForConfirmation, updateMembershipForConfirmation, updateSeasonForConfirmation, updateWindowForFinalization, updateParticipationForClaim, updateMembershipForClaim, initializeReferralPenaltyClaim, calculateWithdrawalAmount, updateSeasonSettingsForPauseToggle, updateSeasonSettingsForAdminUpdate, } from "../utils/accountUpdates";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Optimistic account updates
|
|
4
|
+
*
|
|
5
|
+
* This module contains all optimistic update logic separated from instruction building.
|
|
6
|
+
* Each function mirrors the on-chain logic to predict state changes before confirmation.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.updateSeasonSettingsForAdminUpdate = exports.updateSeasonSettingsForPauseToggle = exports.calculateWithdrawalAmount = exports.initializeReferralPenaltyClaim = exports.updateMembershipForClaim = exports.updateParticipationForClaim = exports.updateWindowForFinalization = exports.updateSeasonForConfirmation = exports.updateMembershipForConfirmation = exports.updateParticipationForConfirmation = exports.updateWindowForConfirmation = exports.updateSeasonForJoin = exports.initializeSeasonMembership = exports.updateMiztakeForSeasonUse = exports.initializeRewardWindow = exports.initializeUserWindowParticipation = exports.updateMiztakeStatisticsForCreation = exports.updateUserStatsForMiztakeCreation = exports.initializeUserStats = exports.createEmptyUserStats = exports.getCurrentTimestamp = void 0;
|
|
10
|
+
// Re-export all optimistic update functions from accountUpdates
|
|
11
|
+
// This provides a cleaner separation of concerns
|
|
12
|
+
var accountUpdates_1 = require("../utils/accountUpdates");
|
|
13
|
+
Object.defineProperty(exports, "getCurrentTimestamp", { enumerable: true, get: function () { return accountUpdates_1.getCurrentTimestamp; } });
|
|
14
|
+
Object.defineProperty(exports, "createEmptyUserStats", { enumerable: true, get: function () { return accountUpdates_1.createEmptyUserStats; } });
|
|
15
|
+
Object.defineProperty(exports, "initializeUserStats", { enumerable: true, get: function () { return accountUpdates_1.initializeUserStats; } });
|
|
16
|
+
Object.defineProperty(exports, "updateUserStatsForMiztakeCreation", { enumerable: true, get: function () { return accountUpdates_1.updateUserStatsForMiztakeCreation; } });
|
|
17
|
+
Object.defineProperty(exports, "updateMiztakeStatisticsForCreation", { enumerable: true, get: function () { return accountUpdates_1.updateMiztakeStatisticsForCreation; } });
|
|
18
|
+
Object.defineProperty(exports, "initializeUserWindowParticipation", { enumerable: true, get: function () { return accountUpdates_1.initializeUserWindowParticipation; } });
|
|
19
|
+
Object.defineProperty(exports, "initializeRewardWindow", { enumerable: true, get: function () { return accountUpdates_1.initializeRewardWindow; } });
|
|
20
|
+
Object.defineProperty(exports, "updateMiztakeForSeasonUse", { enumerable: true, get: function () { return accountUpdates_1.updateMiztakeForSeasonUse; } });
|
|
21
|
+
Object.defineProperty(exports, "initializeSeasonMembership", { enumerable: true, get: function () { return accountUpdates_1.initializeSeasonMembership; } });
|
|
22
|
+
Object.defineProperty(exports, "updateSeasonForJoin", { enumerable: true, get: function () { return accountUpdates_1.updateSeasonForJoin; } });
|
|
23
|
+
Object.defineProperty(exports, "updateWindowForConfirmation", { enumerable: true, get: function () { return accountUpdates_1.updateWindowForConfirmation; } });
|
|
24
|
+
Object.defineProperty(exports, "updateParticipationForConfirmation", { enumerable: true, get: function () { return accountUpdates_1.updateParticipationForConfirmation; } });
|
|
25
|
+
Object.defineProperty(exports, "updateMembershipForConfirmation", { enumerable: true, get: function () { return accountUpdates_1.updateMembershipForConfirmation; } });
|
|
26
|
+
Object.defineProperty(exports, "updateSeasonForConfirmation", { enumerable: true, get: function () { return accountUpdates_1.updateSeasonForConfirmation; } });
|
|
27
|
+
Object.defineProperty(exports, "updateWindowForFinalization", { enumerable: true, get: function () { return accountUpdates_1.updateWindowForFinalization; } });
|
|
28
|
+
Object.defineProperty(exports, "updateParticipationForClaim", { enumerable: true, get: function () { return accountUpdates_1.updateParticipationForClaim; } });
|
|
29
|
+
Object.defineProperty(exports, "updateMembershipForClaim", { enumerable: true, get: function () { return accountUpdates_1.updateMembershipForClaim; } });
|
|
30
|
+
Object.defineProperty(exports, "initializeReferralPenaltyClaim", { enumerable: true, get: function () { return accountUpdates_1.initializeReferralPenaltyClaim; } });
|
|
31
|
+
Object.defineProperty(exports, "calculateWithdrawalAmount", { enumerable: true, get: function () { return accountUpdates_1.calculateWithdrawalAmount; } });
|
|
32
|
+
Object.defineProperty(exports, "updateSeasonSettingsForPauseToggle", { enumerable: true, get: function () { return accountUpdates_1.updateSeasonSettingsForPauseToggle; } });
|
|
33
|
+
Object.defineProperty(exports, "updateSeasonSettingsForAdminUpdate", { enumerable: true, get: function () { return accountUpdates_1.updateSeasonSettingsForAdminUpdate; } });
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Typed account interfaces for Anchor instructions
|
|
4
|
+
* These match the account structures in the Rust program
|
|
5
|
+
*/
|
|
6
|
+
export interface CreateMiztakeAccounts {
|
|
7
|
+
miztake: PublicKey;
|
|
8
|
+
userStats: PublicKey;
|
|
9
|
+
miztakeStatistics: PublicKey;
|
|
10
|
+
seasonSettings: PublicKey;
|
|
11
|
+
season: PublicKey;
|
|
12
|
+
seasonMembership: PublicKey;
|
|
13
|
+
rewardWindow: PublicKey;
|
|
14
|
+
userWindowParticipation: PublicKey;
|
|
15
|
+
user: PublicKey;
|
|
16
|
+
admin: PublicKey;
|
|
17
|
+
systemProgram: PublicKey;
|
|
18
|
+
}
|
|
19
|
+
export interface InitializeSeasonSettingsAccounts {
|
|
20
|
+
seasonSettings: PublicKey;
|
|
21
|
+
admin: PublicKey;
|
|
22
|
+
systemProgram: PublicKey;
|
|
23
|
+
}
|
|
24
|
+
export interface InitializeSeasonVaultAccounts {
|
|
25
|
+
seasonDepositVault: PublicKey;
|
|
26
|
+
mizdMint: PublicKey;
|
|
27
|
+
admin: PublicKey;
|
|
28
|
+
tokenProgram: PublicKey;
|
|
29
|
+
systemProgram: PublicKey;
|
|
30
|
+
}
|
|
31
|
+
export interface InitializeEscrowVaultAccounts {
|
|
32
|
+
seasonEscrowVault: PublicKey;
|
|
33
|
+
mizdMint: PublicKey;
|
|
34
|
+
admin: PublicKey;
|
|
35
|
+
tokenProgram: PublicKey;
|
|
36
|
+
systemProgram: PublicKey;
|
|
37
|
+
}
|
|
38
|
+
export interface InitializeStatisticsAccounts {
|
|
39
|
+
miztakeStatistics: PublicKey;
|
|
40
|
+
admin: PublicKey;
|
|
41
|
+
payer: PublicKey;
|
|
42
|
+
systemProgram: PublicKey;
|
|
43
|
+
}
|
|
44
|
+
export interface JoinSeasonAccounts {
|
|
45
|
+
seasonSettings: PublicKey;
|
|
46
|
+
season: PublicKey;
|
|
47
|
+
seasonMembership: PublicKey;
|
|
48
|
+
seasonDepositVault: PublicKey;
|
|
49
|
+
seasonEscrowVault: PublicKey;
|
|
50
|
+
mizdMint: PublicKey;
|
|
51
|
+
userTokenAccount: PublicKey;
|
|
52
|
+
user: PublicKey;
|
|
53
|
+
tokenProgram: PublicKey;
|
|
54
|
+
systemProgram: PublicKey;
|
|
55
|
+
}
|
|
56
|
+
export interface ConfirmedPostOnXAccounts {
|
|
57
|
+
seasonSettings: PublicKey;
|
|
58
|
+
seasonMembership: PublicKey;
|
|
59
|
+
season: PublicKey;
|
|
60
|
+
rewardWindow: PublicKey;
|
|
61
|
+
userWindowParticipation: PublicKey;
|
|
62
|
+
miztake: PublicKey;
|
|
63
|
+
admin: PublicKey;
|
|
64
|
+
}
|
|
65
|
+
export interface ClaimWindowRewardsAccounts {
|
|
66
|
+
seasonSettings: PublicKey;
|
|
67
|
+
season: PublicKey;
|
|
68
|
+
rewardWindow: PublicKey;
|
|
69
|
+
userWindowParticipation: PublicKey;
|
|
70
|
+
seasonMembership: PublicKey;
|
|
71
|
+
seasonDepositVault: PublicKey;
|
|
72
|
+
mizdMint: PublicKey;
|
|
73
|
+
userTokenAccount: PublicKey;
|
|
74
|
+
referrerTokenAccount: PublicKey;
|
|
75
|
+
user: PublicKey;
|
|
76
|
+
tokenProgram: PublicKey;
|
|
77
|
+
}
|
|
78
|
+
export interface ClaimReferralPenaltyForWindowAccounts {
|
|
79
|
+
seasonSettings: PublicKey;
|
|
80
|
+
season: PublicKey;
|
|
81
|
+
seasonMembership: PublicKey;
|
|
82
|
+
userWindowParticipation: PublicKey;
|
|
83
|
+
referralPenaltyClaim: PublicKey;
|
|
84
|
+
seasonDepositVault: PublicKey;
|
|
85
|
+
mizdMint: PublicKey;
|
|
86
|
+
recipientTokenAccount: PublicKey;
|
|
87
|
+
claimant: PublicKey;
|
|
88
|
+
tokenProgram: PublicKey;
|
|
89
|
+
systemProgram: PublicKey;
|
|
90
|
+
}
|
|
91
|
+
export interface WithdrawSeasonDepositAccounts {
|
|
92
|
+
seasonSettings: PublicKey;
|
|
93
|
+
season: PublicKey;
|
|
94
|
+
seasonMembership: PublicKey;
|
|
95
|
+
seasonDepositVault: PublicKey;
|
|
96
|
+
seasonEscrowVault: PublicKey;
|
|
97
|
+
mizdMint: PublicKey;
|
|
98
|
+
userTokenAccount: PublicKey;
|
|
99
|
+
user: PublicKey;
|
|
100
|
+
tokenProgram: PublicKey;
|
|
101
|
+
}
|
|
102
|
+
export interface ToggleSeasonPauseAccounts {
|
|
103
|
+
seasonSettings: PublicKey;
|
|
104
|
+
admin: PublicKey;
|
|
105
|
+
}
|
|
106
|
+
export interface UpdateSeasonAdminAccounts {
|
|
107
|
+
seasonSettings: PublicKey;
|
|
108
|
+
currentAdmin: PublicKey;
|
|
109
|
+
}
|
|
110
|
+
export interface ViewSeasonMembershipStatusAccounts {
|
|
111
|
+
seasonSettings: PublicKey;
|
|
112
|
+
season: PublicKey;
|
|
113
|
+
seasonMembership: PublicKey;
|
|
114
|
+
}
|
|
115
|
+
export interface ViewWindowStatusAccounts {
|
|
116
|
+
rewardWindow: PublicKey;
|
|
117
|
+
}
|
|
118
|
+
export interface ViewCurrentSeasonAccounts {
|
|
119
|
+
seasonSettings: PublicKey;
|
|
120
|
+
season: PublicKey;
|
|
121
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TransactionInstruction, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { SignerInfo } from "../utils/signerHelpers";
|
|
3
|
+
/**
|
|
4
|
+
* Base instruction result
|
|
5
|
+
* All instruction functions return this standardized structure
|
|
6
|
+
*/
|
|
7
|
+
export interface InstructionResult {
|
|
8
|
+
instructions: TransactionInstruction[];
|
|
9
|
+
signers: SignerInfo[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Standard instruction result with PDAs and optional updated accounts
|
|
13
|
+
* This is the unified return type for all instructions
|
|
14
|
+
*/
|
|
15
|
+
export interface StandardInstructionResult<TPdas extends Record<string, PublicKey> = Record<string, PublicKey>, TAccounts = Record<string, unknown>, TMeta = Record<string, unknown>> extends InstructionResult {
|
|
16
|
+
/** Program-derived addresses created or used by this instruction */
|
|
17
|
+
pdas?: TPdas;
|
|
18
|
+
/** Optimistically updated account states (if current accounts were provided) */
|
|
19
|
+
updatedAccounts?: TAccounts;
|
|
20
|
+
/** Additional metadata (e.g., calculated amounts, derived values) */
|
|
21
|
+
metadata?: TMeta;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Legacy: Instruction result with PDA addresses
|
|
25
|
+
* @deprecated Use StandardInstructionResult instead
|
|
26
|
+
*/
|
|
27
|
+
export interface InstructionResultWithPdas extends InstructionResult {
|
|
28
|
+
pdas: Record<string, PublicKey>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Legacy: Instruction result with optimistically updated accounts
|
|
32
|
+
* @deprecated Use StandardInstructionResult instead
|
|
33
|
+
*/
|
|
34
|
+
export interface InstructionResultWithAccounts<T = Record<string, unknown>> extends InstructionResult {
|
|
35
|
+
updatedAccounts?: T;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Legacy: Full instruction result with both PDAs and updated accounts
|
|
39
|
+
* @deprecated Use StandardInstructionResult instead
|
|
40
|
+
*/
|
|
41
|
+
export interface FullInstructionResult<T = Record<string, unknown>> extends InstructionResult {
|
|
42
|
+
pdas: Record<string, PublicKey>;
|
|
43
|
+
updatedAccounts?: T;
|
|
44
|
+
}
|