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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proof of Take SDK
|
|
3
|
+
*
|
|
4
|
+
* TypeScript/JavaScript library for interacting with the Proof of Take Solana program
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { createMiztake, getMiztakePdaForParams, } from "./instructions/createMiztake";
|
|
9
|
+
export type { CreateMiztakeOptions, CreateMiztakeResult, } from "./instructions/createMiztake";
|
|
10
|
+
export { initializeStatistics } from "./instructions/initializeStatistics";
|
|
11
|
+
export { initializeSeasonSettings } from "./instructions/initializeSeasonSettings";
|
|
12
|
+
export { initializeSeasonVault } from "./instructions/initializeSeasonVault";
|
|
13
|
+
export { initializeEscrowVault } from "./instructions/initializeEscrowVault";
|
|
14
|
+
export { joinSeason } from "./instructions/joinSeason";
|
|
15
|
+
export type { JoinSeasonOptions } from "./instructions/joinSeason";
|
|
16
|
+
export { confirmedPostOnX } from "./instructions/confirmedPostOnX";
|
|
17
|
+
export type { ConfirmedPostOnXOptions } from "./instructions/confirmedPostOnX";
|
|
18
|
+
export { claimWindowRewards } from "./instructions/claimWindowRewards";
|
|
19
|
+
export type { ClaimWindowRewardsOptions } from "./instructions/claimWindowRewards";
|
|
20
|
+
export { claimReferralPenaltyForWindow } from "./instructions/claimReferralPenaltyForWindow";
|
|
21
|
+
export type { ClaimReferralPenaltyForWindowOptions } from "./instructions/claimReferralPenaltyForWindow";
|
|
22
|
+
export { withdrawSeasonDeposit } from "./instructions/withdrawSeasonDeposit";
|
|
23
|
+
export type { WithdrawSeasonDepositOptions } from "./instructions/withdrawSeasonDeposit";
|
|
24
|
+
export { toggleSeasonPause } from "./instructions/toggleSeasonPause";
|
|
25
|
+
export { updateSeasonAdmin } from "./instructions/updateSeasonAdmin";
|
|
26
|
+
export { viewSeasonMembershipStatus } from "./instructions/viewSeasonMembershipStatus";
|
|
27
|
+
export { viewWindowStatus } from "./instructions/viewWindowStatus";
|
|
28
|
+
export { viewCurrentSeason } from "./instructions/viewCurrentSeason";
|
|
29
|
+
export * from "./utils/pdas";
|
|
30
|
+
export * from "./utils/constants";
|
|
31
|
+
export * from "./utils/accountUpdates";
|
|
32
|
+
export * from "./utils/programHelpers";
|
|
33
|
+
export * from "./utils/signerHelpers";
|
|
34
|
+
export * from "./utils/conversions";
|
|
35
|
+
export * from "./utils/transactionBuilder";
|
|
36
|
+
export * from "./utils/simulationHelpers";
|
|
37
|
+
export * from "./utils/enumHelpers";
|
|
38
|
+
export { PDAManager } from "./utils/pdaManager";
|
|
39
|
+
export * from "./optimistic";
|
|
40
|
+
export * from "./constants/season";
|
|
41
|
+
export * from "./types";
|
|
42
|
+
export * from "./types/instructionResults";
|
|
43
|
+
export * from "./types/accountTypes";
|
|
44
|
+
export type { ProofOfTake } from "./types/proof_of_take";
|
|
45
|
+
export { IDL } from "./idl/idl";
|
|
46
|
+
export { createProgram, createProgramWithId, getProgramReadOnly, } from "./client";
|
|
47
|
+
export * from "./getters";
|
|
48
|
+
export declare const VERSION = "1.0.0";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Proof of Take SDK
|
|
4
|
+
*
|
|
5
|
+
* TypeScript/JavaScript library for interacting with the Proof of Take Solana program
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.VERSION = exports.getProgramReadOnly = exports.createProgramWithId = exports.createProgram = exports.IDL = exports.PDAManager = exports.viewCurrentSeason = exports.viewWindowStatus = exports.viewSeasonMembershipStatus = exports.updateSeasonAdmin = exports.toggleSeasonPause = exports.withdrawSeasonDeposit = exports.claimReferralPenaltyForWindow = exports.claimWindowRewards = exports.confirmedPostOnX = exports.joinSeason = exports.initializeEscrowVault = exports.initializeSeasonVault = exports.initializeSeasonSettings = exports.initializeStatistics = exports.getMiztakePdaForParams = exports.createMiztake = void 0;
|
|
25
|
+
// Export all instructions
|
|
26
|
+
// Core miztake instructions
|
|
27
|
+
var createMiztake_1 = require("./instructions/createMiztake");
|
|
28
|
+
Object.defineProperty(exports, "createMiztake", { enumerable: true, get: function () { return createMiztake_1.createMiztake; } });
|
|
29
|
+
Object.defineProperty(exports, "getMiztakePdaForParams", { enumerable: true, get: function () { return createMiztake_1.getMiztakePdaForParams; } });
|
|
30
|
+
var initializeStatistics_1 = require("./instructions/initializeStatistics");
|
|
31
|
+
Object.defineProperty(exports, "initializeStatistics", { enumerable: true, get: function () { return initializeStatistics_1.initializeStatistics; } });
|
|
32
|
+
// Season initialization instructions
|
|
33
|
+
var initializeSeasonSettings_1 = require("./instructions/initializeSeasonSettings");
|
|
34
|
+
Object.defineProperty(exports, "initializeSeasonSettings", { enumerable: true, get: function () { return initializeSeasonSettings_1.initializeSeasonSettings; } });
|
|
35
|
+
var initializeSeasonVault_1 = require("./instructions/initializeSeasonVault");
|
|
36
|
+
Object.defineProperty(exports, "initializeSeasonVault", { enumerable: true, get: function () { return initializeSeasonVault_1.initializeSeasonVault; } });
|
|
37
|
+
var initializeEscrowVault_1 = require("./instructions/initializeEscrowVault");
|
|
38
|
+
Object.defineProperty(exports, "initializeEscrowVault", { enumerable: true, get: function () { return initializeEscrowVault_1.initializeEscrowVault; } });
|
|
39
|
+
// Season membership instructions
|
|
40
|
+
var joinSeason_1 = require("./instructions/joinSeason");
|
|
41
|
+
Object.defineProperty(exports, "joinSeason", { enumerable: true, get: function () { return joinSeason_1.joinSeason; } });
|
|
42
|
+
var confirmedPostOnX_1 = require("./instructions/confirmedPostOnX");
|
|
43
|
+
Object.defineProperty(exports, "confirmedPostOnX", { enumerable: true, get: function () { return confirmedPostOnX_1.confirmedPostOnX; } });
|
|
44
|
+
var claimWindowRewards_1 = require("./instructions/claimWindowRewards");
|
|
45
|
+
Object.defineProperty(exports, "claimWindowRewards", { enumerable: true, get: function () { return claimWindowRewards_1.claimWindowRewards; } });
|
|
46
|
+
var claimReferralPenaltyForWindow_1 = require("./instructions/claimReferralPenaltyForWindow");
|
|
47
|
+
Object.defineProperty(exports, "claimReferralPenaltyForWindow", { enumerable: true, get: function () { return claimReferralPenaltyForWindow_1.claimReferralPenaltyForWindow; } });
|
|
48
|
+
var withdrawSeasonDeposit_1 = require("./instructions/withdrawSeasonDeposit");
|
|
49
|
+
Object.defineProperty(exports, "withdrawSeasonDeposit", { enumerable: true, get: function () { return withdrawSeasonDeposit_1.withdrawSeasonDeposit; } });
|
|
50
|
+
// Season admin instructions
|
|
51
|
+
var toggleSeasonPause_1 = require("./instructions/toggleSeasonPause");
|
|
52
|
+
Object.defineProperty(exports, "toggleSeasonPause", { enumerable: true, get: function () { return toggleSeasonPause_1.toggleSeasonPause; } });
|
|
53
|
+
var updateSeasonAdmin_1 = require("./instructions/updateSeasonAdmin");
|
|
54
|
+
Object.defineProperty(exports, "updateSeasonAdmin", { enumerable: true, get: function () { return updateSeasonAdmin_1.updateSeasonAdmin; } });
|
|
55
|
+
// View instructions (read-only)
|
|
56
|
+
var viewSeasonMembershipStatus_1 = require("./instructions/viewSeasonMembershipStatus");
|
|
57
|
+
Object.defineProperty(exports, "viewSeasonMembershipStatus", { enumerable: true, get: function () { return viewSeasonMembershipStatus_1.viewSeasonMembershipStatus; } });
|
|
58
|
+
var viewWindowStatus_1 = require("./instructions/viewWindowStatus");
|
|
59
|
+
Object.defineProperty(exports, "viewWindowStatus", { enumerable: true, get: function () { return viewWindowStatus_1.viewWindowStatus; } });
|
|
60
|
+
var viewCurrentSeason_1 = require("./instructions/viewCurrentSeason");
|
|
61
|
+
Object.defineProperty(exports, "viewCurrentSeason", { enumerable: true, get: function () { return viewCurrentSeason_1.viewCurrentSeason; } });
|
|
62
|
+
// Export utilities
|
|
63
|
+
__exportStar(require("./utils/pdas"), exports);
|
|
64
|
+
__exportStar(require("./utils/constants"), exports);
|
|
65
|
+
__exportStar(require("./utils/accountUpdates"), exports);
|
|
66
|
+
__exportStar(require("./utils/programHelpers"), exports);
|
|
67
|
+
__exportStar(require("./utils/signerHelpers"), exports);
|
|
68
|
+
__exportStar(require("./utils/conversions"), exports);
|
|
69
|
+
__exportStar(require("./utils/transactionBuilder"), exports);
|
|
70
|
+
__exportStar(require("./utils/simulationHelpers"), exports);
|
|
71
|
+
__exportStar(require("./utils/enumHelpers"), exports);
|
|
72
|
+
var pdaManager_1 = require("./utils/pdaManager");
|
|
73
|
+
Object.defineProperty(exports, "PDAManager", { enumerable: true, get: function () { return pdaManager_1.PDAManager; } });
|
|
74
|
+
// Export optimistic updates
|
|
75
|
+
__exportStar(require("./optimistic"), exports);
|
|
76
|
+
// Export constants
|
|
77
|
+
__exportStar(require("./constants/season"), exports);
|
|
78
|
+
// Export types
|
|
79
|
+
__exportStar(require("./types"), exports);
|
|
80
|
+
__exportStar(require("./types/instructionResults"), exports);
|
|
81
|
+
__exportStar(require("./types/accountTypes"), exports);
|
|
82
|
+
var idl_1 = require("./idl/idl");
|
|
83
|
+
Object.defineProperty(exports, "IDL", { enumerable: true, get: function () { return idl_1.IDL; } });
|
|
84
|
+
// Export client helpers
|
|
85
|
+
var client_1 = require("./client");
|
|
86
|
+
Object.defineProperty(exports, "createProgram", { enumerable: true, get: function () { return client_1.createProgram; } });
|
|
87
|
+
Object.defineProperty(exports, "createProgramWithId", { enumerable: true, get: function () { return client_1.createProgramWithId; } });
|
|
88
|
+
Object.defineProperty(exports, "getProgramReadOnly", { enumerable: true, get: function () { return client_1.getProgramReadOnly; } });
|
|
89
|
+
// Export getters
|
|
90
|
+
__exportStar(require("./getters"), exports);
|
|
91
|
+
// Version
|
|
92
|
+
exports.VERSION = "1.0.0";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import { SignerInfo } from "../utils/signerHelpers";
|
|
4
|
+
import { ReferralPenaltyClaim, SeasonMembership, UserWindowParticipation } from "../types";
|
|
5
|
+
export interface ClaimReferralPenaltyForWindowOptions {
|
|
6
|
+
connection: Connection;
|
|
7
|
+
/** Referrer (or root admin if no referrer) */
|
|
8
|
+
claimant: PublicKey;
|
|
9
|
+
/** Token account owned by claimant (receives the 20% payout) */
|
|
10
|
+
recipientTokenAccount: PublicKey;
|
|
11
|
+
referredUser: PublicKey;
|
|
12
|
+
seasonNumber: BN;
|
|
13
|
+
windowNumber: BN;
|
|
14
|
+
seasonMembershipId: BN;
|
|
15
|
+
feePayer?: PublicKey;
|
|
16
|
+
/**
|
|
17
|
+
* Optional timestamp override (Unix seconds) for optimistic `claimedAt`.
|
|
18
|
+
* If omitted, SDK uses `Date.now()` (seconds).
|
|
19
|
+
*/
|
|
20
|
+
now?: BN;
|
|
21
|
+
/**
|
|
22
|
+
* Current on-chain account snapshots for optimistic updates.
|
|
23
|
+
* If provided, SDK returns `updatedAccounts` that should match on-chain results.
|
|
24
|
+
*/
|
|
25
|
+
currentAccounts?: {
|
|
26
|
+
seasonMembership?: SeasonMembership;
|
|
27
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare function claimReferralPenaltyForWindow(options: ClaimReferralPenaltyForWindowOptions): Promise<{
|
|
31
|
+
instructions: TransactionInstruction[];
|
|
32
|
+
signers: SignerInfo[];
|
|
33
|
+
updatedAccounts?: {
|
|
34
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
35
|
+
referralPenaltyClaim?: ReferralPenaltyClaim;
|
|
36
|
+
seasonMembership?: SeasonMembership;
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.claimReferralPenaltyForWindow = claimReferralPenaltyForWindow;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
7
|
+
const pdaManager_1 = require("../utils/pdaManager");
|
|
8
|
+
const constants_1 = require("../utils/constants");
|
|
9
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
10
|
+
const signerHelpers_1 = require("../utils/signerHelpers");
|
|
11
|
+
const optimistic_1 = require("../optimistic");
|
|
12
|
+
const tierPenalty_1 = require("../utils/tierPenalty");
|
|
13
|
+
async function claimReferralPenaltyForWindow(options) {
|
|
14
|
+
const program = (0, programHelpers_1.getProgram)(options.connection);
|
|
15
|
+
const pdas = pdaManager_1.PDAManager.deriveClaimReferralPenaltyForWindowPdas({
|
|
16
|
+
referredUser: options.referredUser,
|
|
17
|
+
seasonNumber: options.seasonNumber,
|
|
18
|
+
windowNumber: options.windowNumber,
|
|
19
|
+
referredSeasonMembershipId: options.seasonMembershipId,
|
|
20
|
+
});
|
|
21
|
+
const accounts = {
|
|
22
|
+
seasonSettings: pdas.seasonSettings,
|
|
23
|
+
season: pdas.season,
|
|
24
|
+
seasonMembership: pdas.seasonMembership,
|
|
25
|
+
userWindowParticipation: pdas.userWindowParticipation,
|
|
26
|
+
referralPenaltyClaim: pdas.referralPenaltyClaim,
|
|
27
|
+
seasonDepositVault: pdas.seasonDepositVault,
|
|
28
|
+
mizdMint: constants_1.MIZD_TOKEN_MINT,
|
|
29
|
+
recipientTokenAccount: options.recipientTokenAccount,
|
|
30
|
+
claimant: options.claimant,
|
|
31
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
32
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
33
|
+
};
|
|
34
|
+
const instruction = await program.methods
|
|
35
|
+
.claimReferralPenaltyForWindow(
|
|
36
|
+
// Anchor expects BN for u64 args.
|
|
37
|
+
options.seasonNumber, options.windowNumber, options.referredUser, options.seasonMembershipId)
|
|
38
|
+
.accounts(accounts)
|
|
39
|
+
.instruction();
|
|
40
|
+
const signers = (0, signerHelpers_1.buildSigners)([{ publicKey: options.claimant, role: "claimant" }], options.feePayer);
|
|
41
|
+
// OPTIMISTIC UPDATES
|
|
42
|
+
let updatedAccounts = undefined;
|
|
43
|
+
const curr = options.currentAccounts;
|
|
44
|
+
if (curr?.seasonMembership) {
|
|
45
|
+
const claimedAt = (0, optimistic_1.getCurrentTimestamp)(options.now);
|
|
46
|
+
// The program `init_if_needed` for participation; if caller doesn't provide it, assume it doesn't exist.
|
|
47
|
+
const participation = curr.userWindowParticipation ??
|
|
48
|
+
(0, optimistic_1.initializeUserWindowParticipation)(options.referredUser, options.seasonNumber, options.windowNumber, options.seasonMembershipId, new anchor_1.BN(0) // miztake_id = 0 for total no-show windows
|
|
49
|
+
);
|
|
50
|
+
// Keep this in sync with on-chain: membership.deposit_tier.penalty_per_window_amount()
|
|
51
|
+
const perWindowPenalty = (0, tierPenalty_1.getTierPenaltyPerWindow)(curr.seasonMembership.depositTier);
|
|
52
|
+
const claim = (0, optimistic_1.initializeReferralPenaltyClaim)({
|
|
53
|
+
referredUser: options.referredUser,
|
|
54
|
+
seasonNumber: options.seasonNumber,
|
|
55
|
+
windowNumber: options.windowNumber,
|
|
56
|
+
seasonMembershipId: options.seasonMembershipId,
|
|
57
|
+
claimant: options.claimant,
|
|
58
|
+
perWindowPenalty,
|
|
59
|
+
claimedAt,
|
|
60
|
+
});
|
|
61
|
+
updatedAccounts = {
|
|
62
|
+
seasonMembership: curr.seasonMembership,
|
|
63
|
+
userWindowParticipation: participation,
|
|
64
|
+
referralPenaltyClaim: claim,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
instructions: [instruction],
|
|
69
|
+
signers,
|
|
70
|
+
...(updatedAccounts && { updatedAccounts }),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import { SeasonSettings, Season, RewardWindow, UserWindowParticipation, SeasonMembership } from "../types";
|
|
4
|
+
import { SignerInfo } from "../utils/signerHelpers";
|
|
5
|
+
type ClaimWindowRewardsUpdatedAccounts = {
|
|
6
|
+
seasonSettings?: SeasonSettings;
|
|
7
|
+
season?: Season;
|
|
8
|
+
rewardWindow?: RewardWindow;
|
|
9
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
10
|
+
seasonMembership?: SeasonMembership;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Options for claimWindowRewards instruction
|
|
14
|
+
*/
|
|
15
|
+
export interface ClaimWindowRewardsOptions {
|
|
16
|
+
connection: Connection;
|
|
17
|
+
user: PublicKey;
|
|
18
|
+
userTokenAccount: PublicKey;
|
|
19
|
+
/** Referrer token account to receive referral share (only used when membership.referrer != default) */
|
|
20
|
+
referrerTokenAccount?: PublicKey;
|
|
21
|
+
seasonNumber: BN;
|
|
22
|
+
windowNumber: BN;
|
|
23
|
+
seasonMembershipId: BN;
|
|
24
|
+
feePayer?: PublicKey;
|
|
25
|
+
currentAccounts?: {
|
|
26
|
+
seasonSettings?: SeasonSettings;
|
|
27
|
+
season?: Season;
|
|
28
|
+
rewardWindow?: RewardWindow;
|
|
29
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
30
|
+
seasonMembership?: SeasonMembership;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Claim window rewards
|
|
35
|
+
*
|
|
36
|
+
* Single signer: user
|
|
37
|
+
* Transfers reward tokens from vault to user
|
|
38
|
+
* May finalize window on first claim
|
|
39
|
+
*
|
|
40
|
+
* @param options - Claim window rewards options
|
|
41
|
+
* @returns Instructions, signers, and optimistically updated accounts
|
|
42
|
+
*/
|
|
43
|
+
export declare function claimWindowRewards(options: ClaimWindowRewardsOptions): Promise<{
|
|
44
|
+
instructions: TransactionInstruction[];
|
|
45
|
+
signers: SignerInfo[];
|
|
46
|
+
updatedAccounts?: ClaimWindowRewardsUpdatedAccounts;
|
|
47
|
+
}>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.claimWindowRewards = claimWindowRewards;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
7
|
+
const pdaManager_1 = require("../utils/pdaManager");
|
|
8
|
+
const constants_1 = require("../utils/constants");
|
|
9
|
+
const tierPenalty_1 = require("../utils/tierPenalty");
|
|
10
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
11
|
+
const signerHelpers_1 = require("../utils/signerHelpers");
|
|
12
|
+
const optimistic_1 = require("../optimistic");
|
|
13
|
+
/**
|
|
14
|
+
* Claim window rewards
|
|
15
|
+
*
|
|
16
|
+
* Single signer: user
|
|
17
|
+
* Transfers reward tokens from vault to user
|
|
18
|
+
* May finalize window on first claim
|
|
19
|
+
*
|
|
20
|
+
* @param options - Claim window rewards options
|
|
21
|
+
* @returns Instructions, signers, and optimistically updated accounts
|
|
22
|
+
*/
|
|
23
|
+
async function claimWindowRewards(options) {
|
|
24
|
+
const program = (0, programHelpers_1.getProgram)(options.connection);
|
|
25
|
+
const pdas = pdaManager_1.PDAManager.deriveClaimWindowRewardsPdas({
|
|
26
|
+
user: options.user,
|
|
27
|
+
seasonNumber: options.seasonNumber,
|
|
28
|
+
windowNumber: options.windowNumber,
|
|
29
|
+
seasonMembershipId: options.seasonMembershipId,
|
|
30
|
+
});
|
|
31
|
+
const accounts = {
|
|
32
|
+
seasonSettings: pdas.seasonSettings,
|
|
33
|
+
season: pdas.season,
|
|
34
|
+
rewardWindow: pdas.rewardWindow,
|
|
35
|
+
userWindowParticipation: pdas.userWindowParticipation,
|
|
36
|
+
seasonMembership: pdas.seasonMembership,
|
|
37
|
+
seasonDepositVault: pdas.seasonDepositVault,
|
|
38
|
+
mizdMint: constants_1.MIZD_TOKEN_MINT,
|
|
39
|
+
userTokenAccount: options.userTokenAccount,
|
|
40
|
+
// Always provide something; on-chain will only validate/use when referrer exists.
|
|
41
|
+
referrerTokenAccount: options.referrerTokenAccount ?? options.userTokenAccount,
|
|
42
|
+
user: options.user,
|
|
43
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
44
|
+
};
|
|
45
|
+
const instruction = await program.methods
|
|
46
|
+
// Anchor expects BN for u64 args.
|
|
47
|
+
.claimWindowRewards(options.seasonNumber, options.windowNumber)
|
|
48
|
+
.accounts(accounts)
|
|
49
|
+
.instruction();
|
|
50
|
+
const signers = (0, signerHelpers_1.buildSigners)([{ publicKey: options.user, role: "user" }], options.feePayer);
|
|
51
|
+
// OPTIMISTIC UPDATES
|
|
52
|
+
const curr = options.currentAccounts || {};
|
|
53
|
+
let updatedAccounts = undefined;
|
|
54
|
+
if (curr.rewardWindow && curr.seasonSettings && curr.season) {
|
|
55
|
+
const idx = options.windowNumber.toNumber();
|
|
56
|
+
const eligibleStakeX = curr.season.eligibleStakePerWindow[idx] ?? new anchor_1.BN(0);
|
|
57
|
+
const updatedRewardWindow = !curr.rewardWindow.isFinalized
|
|
58
|
+
? (0, optimistic_1.updateWindowForFinalization)(curr.rewardWindow, eligibleStakeX)
|
|
59
|
+
: curr.rewardWindow;
|
|
60
|
+
const rewardAmount = updatedRewardWindow.rewardPerPoster;
|
|
61
|
+
const hasReferrer = !!curr.seasonMembership &&
|
|
62
|
+
!curr.seasonMembership.referrer.equals(web3_js_1.PublicKey.default);
|
|
63
|
+
const tierPenaltyPerWindow = curr.seasonMembership
|
|
64
|
+
? (0, tierPenalty_1.getTierPenaltyPerWindow)(curr.seasonMembership.depositTier)
|
|
65
|
+
: new anchor_1.BN(0);
|
|
66
|
+
const bonus = rewardAmount.gt(tierPenaltyPerWindow)
|
|
67
|
+
? rewardAmount.sub(tierPenaltyPerWindow)
|
|
68
|
+
: new anchor_1.BN(0);
|
|
69
|
+
const referralCut = hasReferrer ? bonus.divn(10) : new anchor_1.BN(0);
|
|
70
|
+
const userRewardAmount = rewardAmount.sub(referralCut);
|
|
71
|
+
const updatedSeason = !curr.rewardWindow.isFinalized
|
|
72
|
+
? {
|
|
73
|
+
...curr.season,
|
|
74
|
+
totalPenaltiesCollected: curr.season.totalPenaltiesCollected.add(updatedRewardWindow.penaltyPool),
|
|
75
|
+
}
|
|
76
|
+
: curr.season;
|
|
77
|
+
updatedAccounts = {
|
|
78
|
+
...(curr.seasonSettings && { seasonSettings: curr.seasonSettings }),
|
|
79
|
+
season: updatedSeason,
|
|
80
|
+
rewardWindow: updatedRewardWindow,
|
|
81
|
+
...(curr.userWindowParticipation && {
|
|
82
|
+
userWindowParticipation: (0, optimistic_1.updateParticipationForClaim)(curr.userWindowParticipation, userRewardAmount),
|
|
83
|
+
}),
|
|
84
|
+
...(curr.seasonMembership && {
|
|
85
|
+
seasonMembership: (0, optimistic_1.updateMembershipForClaim)(curr.seasonMembership, userRewardAmount),
|
|
86
|
+
}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
instructions: [instruction],
|
|
91
|
+
signers,
|
|
92
|
+
...(updatedAccounts && { updatedAccounts }),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import { SeasonSettings, SeasonMembership, Season, RewardWindow, UserWindowParticipation, Miztake } from "../types";
|
|
4
|
+
import { SignerInfo } from "../utils/signerHelpers";
|
|
5
|
+
type ConfirmedPostOnXUpdatedAccounts = {
|
|
6
|
+
seasonSettings?: SeasonSettings;
|
|
7
|
+
seasonMembership?: SeasonMembership;
|
|
8
|
+
season?: Season;
|
|
9
|
+
rewardWindow?: RewardWindow;
|
|
10
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
11
|
+
miztake?: Miztake;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Options for confirmedPostOnX instruction
|
|
15
|
+
*/
|
|
16
|
+
export interface ConfirmedPostOnXOptions {
|
|
17
|
+
connection: Connection;
|
|
18
|
+
adminKey: PublicKey;
|
|
19
|
+
user: PublicKey;
|
|
20
|
+
seasonMembershipId: BN;
|
|
21
|
+
windowNumber: BN;
|
|
22
|
+
/** SHA-256 hex string (64 chars). On-chain expects the raw 32-byte digest. */
|
|
23
|
+
miztakeShaHash: string;
|
|
24
|
+
feePayer?: PublicKey;
|
|
25
|
+
/** Whether the post is on time (needed for optimistic updates) */
|
|
26
|
+
isOnTime?: boolean;
|
|
27
|
+
currentAccounts?: {
|
|
28
|
+
seasonSettings?: SeasonSettings;
|
|
29
|
+
seasonMembership?: SeasonMembership;
|
|
30
|
+
season?: Season;
|
|
31
|
+
rewardWindow?: RewardWindow;
|
|
32
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
33
|
+
miztake?: Miztake;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Confirm a post on X (Twitter)
|
|
38
|
+
*
|
|
39
|
+
* Single signer: admin (season admin, not root admin)
|
|
40
|
+
* No token transfers
|
|
41
|
+
* Updates multiple accounts based on whether post was on time
|
|
42
|
+
*
|
|
43
|
+
* @param options - Confirmed post on X options
|
|
44
|
+
* @returns Instructions, signers, and optimistically updated accounts
|
|
45
|
+
*/
|
|
46
|
+
export declare function confirmedPostOnX(options: ConfirmedPostOnXOptions): Promise<{
|
|
47
|
+
instructions: TransactionInstruction[];
|
|
48
|
+
signers: SignerInfo[];
|
|
49
|
+
updatedAccounts?: ConfirmedPostOnXUpdatedAccounts;
|
|
50
|
+
}>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.confirmedPostOnX = confirmedPostOnX;
|
|
4
|
+
const pdaManager_1 = require("../utils/pdaManager");
|
|
5
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
const signerHelpers_1 = require("../utils/signerHelpers");
|
|
7
|
+
const conversions_1 = require("../utils/conversions");
|
|
8
|
+
const tierPenalty_1 = require("../utils/tierPenalty");
|
|
9
|
+
const optimistic_1 = require("../optimistic");
|
|
10
|
+
/**
|
|
11
|
+
* Confirm a post on X (Twitter)
|
|
12
|
+
*
|
|
13
|
+
* Single signer: admin (season admin, not root admin)
|
|
14
|
+
* No token transfers
|
|
15
|
+
* Updates multiple accounts based on whether post was on time
|
|
16
|
+
*
|
|
17
|
+
* @param options - Confirmed post on X options
|
|
18
|
+
* @returns Instructions, signers, and optimistically updated accounts
|
|
19
|
+
*/
|
|
20
|
+
async function confirmedPostOnX(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 confirmedPostOnX");
|
|
25
|
+
}
|
|
26
|
+
const seasonNumber = curr.seasonMembership.seasonNumber;
|
|
27
|
+
const pdas = pdaManager_1.PDAManager.deriveConfirmedPostPdas({
|
|
28
|
+
user: options.user,
|
|
29
|
+
seasonNumber,
|
|
30
|
+
windowNumber: options.windowNumber,
|
|
31
|
+
seasonMembershipId: options.seasonMembershipId,
|
|
32
|
+
miztakeShaHash: options.miztakeShaHash,
|
|
33
|
+
});
|
|
34
|
+
const accounts = {
|
|
35
|
+
seasonSettings: pdas.seasonSettings,
|
|
36
|
+
seasonMembership: pdas.seasonMembership,
|
|
37
|
+
season: pdas.season,
|
|
38
|
+
rewardWindow: pdas.rewardWindow,
|
|
39
|
+
userWindowParticipation: pdas.userWindowParticipation,
|
|
40
|
+
miztake: pdas.miztake,
|
|
41
|
+
admin: options.adminKey,
|
|
42
|
+
};
|
|
43
|
+
const instruction = await program.methods
|
|
44
|
+
.confirmedPostOnX(options.user,
|
|
45
|
+
// Anchor expects BN for u64 args.
|
|
46
|
+
options.seasonMembershipId, options.windowNumber, Array.from((0, conversions_1.sha256HexToBytes32)(options.miztakeShaHash)))
|
|
47
|
+
.accounts(accounts)
|
|
48
|
+
.instruction();
|
|
49
|
+
const signers = (0, signerHelpers_1.buildSigners)([{ publicKey: options.adminKey, role: "admin" }], options.feePayer);
|
|
50
|
+
// OPTIMISTIC UPDATES
|
|
51
|
+
let updatedAccounts = undefined;
|
|
52
|
+
if (options.isOnTime !== undefined && curr.seasonSettings) {
|
|
53
|
+
const stakeAmount = (0, tierPenalty_1.getTierPenaltyPerWindow)(curr.seasonMembership.depositTier);
|
|
54
|
+
updatedAccounts = {
|
|
55
|
+
...(curr.seasonSettings && { seasonSettings: curr.seasonSettings }),
|
|
56
|
+
...(curr.rewardWindow && {
|
|
57
|
+
rewardWindow: (0, optimistic_1.updateWindowForConfirmation)(curr.rewardWindow, options.isOnTime, stakeAmount),
|
|
58
|
+
}),
|
|
59
|
+
...(curr.userWindowParticipation && {
|
|
60
|
+
userWindowParticipation: (0, optimistic_1.updateParticipationForConfirmation)(curr.userWindowParticipation, options.isOnTime),
|
|
61
|
+
}),
|
|
62
|
+
...(curr.seasonMembership && {
|
|
63
|
+
seasonMembership: (0, optimistic_1.updateMembershipForConfirmation)(curr.seasonMembership, options.isOnTime, stakeAmount),
|
|
64
|
+
}),
|
|
65
|
+
...(curr.season && {
|
|
66
|
+
season: (0, optimistic_1.updateSeasonForConfirmation)(curr.season, options.isOnTime, stakeAmount),
|
|
67
|
+
}),
|
|
68
|
+
...(curr.miztake && {
|
|
69
|
+
miztake: (0, optimistic_1.updateMiztakeForSeasonUse)(curr.miztake, seasonNumber, options.windowNumber),
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
instructions: [instruction],
|
|
75
|
+
signers,
|
|
76
|
+
...(updatedAccounts && { updatedAccounts }),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { CreateMiztakeParams, Miztake, UserStats, MiztakeStatistics, SeasonSettings, Season, SeasonMembership, RewardWindow, UserWindowParticipation } from "../types";
|
|
4
|
+
import { SignerInfo } from "../utils/signerHelpers";
|
|
5
|
+
/**
|
|
6
|
+
* Options for createMiztake instruction
|
|
7
|
+
*/
|
|
8
|
+
export interface CreateMiztakeOptions {
|
|
9
|
+
connection: Connection;
|
|
10
|
+
params: CreateMiztakeParams;
|
|
11
|
+
user: PublicKey;
|
|
12
|
+
admin: PublicKey;
|
|
13
|
+
seasonNumber: BN;
|
|
14
|
+
windowNumber: BN;
|
|
15
|
+
seasonMembershipId: BN;
|
|
16
|
+
/** Optional injected timestamp (seconds) for optimistic state calculation */
|
|
17
|
+
now?: BN;
|
|
18
|
+
feePayer?: PublicKey;
|
|
19
|
+
currentAccounts?: {
|
|
20
|
+
userStats?: UserStats;
|
|
21
|
+
miztakeStatistics?: MiztakeStatistics;
|
|
22
|
+
seasonSettings?: SeasonSettings;
|
|
23
|
+
season?: Season;
|
|
24
|
+
seasonMembership?: SeasonMembership;
|
|
25
|
+
rewardWindow?: RewardWindow;
|
|
26
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Result from createMiztake instruction
|
|
31
|
+
*/
|
|
32
|
+
export interface CreateMiztakeResult {
|
|
33
|
+
instructions: import("@solana/web3.js").TransactionInstruction[];
|
|
34
|
+
signers: SignerInfo[];
|
|
35
|
+
pdas: {
|
|
36
|
+
miztake: PublicKey;
|
|
37
|
+
userStats: PublicKey;
|
|
38
|
+
miztakeStatistics: PublicKey;
|
|
39
|
+
seasonSettings: PublicKey;
|
|
40
|
+
season: PublicKey;
|
|
41
|
+
seasonMembership: PublicKey;
|
|
42
|
+
rewardWindow: PublicKey;
|
|
43
|
+
userWindowParticipation: PublicKey;
|
|
44
|
+
};
|
|
45
|
+
updatedAccounts: {
|
|
46
|
+
miztake: Miztake;
|
|
47
|
+
userStats?: UserStats;
|
|
48
|
+
miztakeStatistics?: MiztakeStatistics;
|
|
49
|
+
seasonSettings?: SeasonSettings;
|
|
50
|
+
season?: Season;
|
|
51
|
+
seasonMembership?: SeasonMembership;
|
|
52
|
+
rewardWindow?: RewardWindow;
|
|
53
|
+
userWindowParticipation?: UserWindowParticipation;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a new miztake
|
|
58
|
+
*
|
|
59
|
+
* Requires dual signature: user + admin
|
|
60
|
+
* User pays for miztake, user_stats, and user_window_participation accounts
|
|
61
|
+
* Admin pays for reward_window account (if needed)
|
|
62
|
+
*
|
|
63
|
+
* @param options - Create miztake options
|
|
64
|
+
* @returns Instructions, signers, PDAs, and optimistically updated accounts
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const result = await createMiztake({
|
|
69
|
+
* connection,
|
|
70
|
+
* params,
|
|
71
|
+
* user: userWallet.publicKey,
|
|
72
|
+
* admin: adminWallet.publicKey,
|
|
73
|
+
* seasonNumber: new BN(1),
|
|
74
|
+
* windowNumber: new BN(5),
|
|
75
|
+
* seasonMembershipId: new BN(123),
|
|
76
|
+
* currentAccounts: {
|
|
77
|
+
* userStats: currentUserStats,
|
|
78
|
+
* miztakeStatistics: currentStats,
|
|
79
|
+
* season: currentSeason,
|
|
80
|
+
* seasonSettings: settings,
|
|
81
|
+
* }
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function createMiztake(options: CreateMiztakeOptions): Promise<CreateMiztakeResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Get the miztake PDA that would be created for given parameters
|
|
88
|
+
* Useful for checking if a miztake already exists
|
|
89
|
+
*/
|
|
90
|
+
export declare function getMiztakePdaForParams(params: CreateMiztakeParams): PublicKey;
|