@zcomb/programs-sdk 1.6.0 → 1.8.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/dist/futarchy/client.d.ts +132 -5
- package/dist/futarchy/client.js +80 -21
- package/dist/futarchy/instructions.d.ts +109 -1
- package/dist/futarchy/instructions.js +17 -3
- package/dist/generated/idls/futarchy.json +112 -0
- package/dist/generated/types/futarchy.d.ts +112 -0
- package/dist/generated/types/futarchy.js +1 -1
- package/package.json +1 -2
- package/src/amm/client.ts +0 -485
- package/src/amm/constants.ts +0 -31
- package/src/amm/index.ts +0 -5
- package/src/amm/instructions.ts +0 -139
- package/src/amm/types.ts +0 -62
- package/src/amm/utils.ts +0 -263
- package/src/futarchy/client.ts +0 -1032
- package/src/futarchy/constants.ts +0 -28
- package/src/futarchy/index.ts +0 -5
- package/src/futarchy/instructions.ts +0 -235
- package/src/futarchy/types.ts +0 -54
- package/src/futarchy/utils.ts +0 -108
- package/src/generated/idls/amm.json +0 -1252
- package/src/generated/idls/futarchy.json +0 -1763
- package/src/generated/idls/index.ts +0 -4
- package/src/generated/idls/svault.json +0 -2228
- package/src/generated/idls/vault.json +0 -1501
- package/src/generated/types/amm.ts +0 -1258
- package/src/generated/types/futarchy.ts +0 -1769
- package/src/generated/types/index.ts +0 -4
- package/src/generated/types/svault.ts +0 -2234
- package/src/generated/types/vault.ts +0 -1507
- package/src/index.ts +0 -163
- package/src/svault/client.ts +0 -401
- package/src/svault/constants.ts +0 -23
- package/src/svault/index.ts +0 -5
- package/src/svault/instructions.ts +0 -258
- package/src/svault/types.ts +0 -45
- package/src/svault/utils.ts +0 -145
- package/src/utils.ts +0 -41
- package/src/vault/client.ts +0 -333
- package/src/vault/constants.ts +0 -23
- package/src/vault/index.ts +0 -5
- package/src/vault/instructions.ts +0 -170
- package/src/vault/types.ts +0 -54
- package/src/vault/utils.ts +0 -70
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Low-level instruction builders for the SVault program.
|
|
3
|
-
* These are thin wrappers around the program methods - use SVaultClient for higher-level operations.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Program, BN } from "@coral-xyz/anchor";
|
|
7
|
-
import { PublicKey } from "@solana/web3.js";
|
|
8
|
-
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
9
|
-
import { Svault } from "./types";
|
|
10
|
-
import {
|
|
11
|
-
deriveStakingConfigPDA,
|
|
12
|
-
deriveUserStakePDA,
|
|
13
|
-
deriveStakeVaultPDA,
|
|
14
|
-
deriveRewardVaultPDA,
|
|
15
|
-
deriveDelegatePDA,
|
|
16
|
-
} from "./utils";
|
|
17
|
-
|
|
18
|
-
/* Fee Authority (same as AMM program) */
|
|
19
|
-
export const FEE_AUTHORITY = new PublicKey("FEEnkcCNE2623LYCPtLf63LFzXpCFigBLTu4qZovRGZC");
|
|
20
|
-
|
|
21
|
-
export function initializeStakingVault(
|
|
22
|
-
program: Program<Svault>,
|
|
23
|
-
admin: PublicKey,
|
|
24
|
-
tokenMint: PublicKey,
|
|
25
|
-
unstakingPeriod: BN | number,
|
|
26
|
-
volumeWindow: BN | number,
|
|
27
|
-
nonce: number
|
|
28
|
-
) {
|
|
29
|
-
const unstakingPeriodBN = typeof unstakingPeriod === "number" ? new BN(unstakingPeriod) : unstakingPeriod;
|
|
30
|
-
const volumeWindowBN = typeof volumeWindow === "number" ? new BN(volumeWindow) : volumeWindow;
|
|
31
|
-
|
|
32
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
33
|
-
const [stakeVault] = deriveStakeVaultPDA(configPda, program.programId);
|
|
34
|
-
const [rewardVault] = deriveRewardVaultPDA(configPda, program.programId);
|
|
35
|
-
|
|
36
|
-
return program.methods
|
|
37
|
-
.initializeStakingVault(unstakingPeriodBN, volumeWindowBN, nonce)
|
|
38
|
-
.accountsPartial({
|
|
39
|
-
admin,
|
|
40
|
-
tokenMint,
|
|
41
|
-
config: configPda,
|
|
42
|
-
stakeVault,
|
|
43
|
-
rewardVault,
|
|
44
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function stake(
|
|
49
|
-
program: Program<Svault>,
|
|
50
|
-
user: PublicKey,
|
|
51
|
-
tokenMint: PublicKey,
|
|
52
|
-
nonce: number,
|
|
53
|
-
amount: BN | number
|
|
54
|
-
) {
|
|
55
|
-
const amountBN = typeof amount === "number" ? new BN(amount) : amount;
|
|
56
|
-
|
|
57
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
58
|
-
const [userStakePda] = deriveUserStakePDA(configPda, user, program.programId);
|
|
59
|
-
const [stakeVault] = deriveStakeVaultPDA(configPda, program.programId);
|
|
60
|
-
const userTokenAccount = getAssociatedTokenAddressSync(tokenMint, user);
|
|
61
|
-
|
|
62
|
-
return program.methods.stake(amountBN).accountsPartial({
|
|
63
|
-
user,
|
|
64
|
-
tokenMint,
|
|
65
|
-
config: configPda,
|
|
66
|
-
userStake: userStakePda,
|
|
67
|
-
stakeVault,
|
|
68
|
-
userTokenAccount,
|
|
69
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function initiateUnstake(
|
|
74
|
-
program: Program<Svault>,
|
|
75
|
-
user: PublicKey,
|
|
76
|
-
tokenMint: PublicKey,
|
|
77
|
-
nonce: number,
|
|
78
|
-
amount: BN | number
|
|
79
|
-
) {
|
|
80
|
-
const amountBN = typeof amount === "number" ? new BN(amount) : amount;
|
|
81
|
-
|
|
82
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
83
|
-
const [userStakePda] = deriveUserStakePDA(configPda, user, program.programId);
|
|
84
|
-
|
|
85
|
-
return program.methods.initiateUnstake(amountBN).accountsPartial({
|
|
86
|
-
user,
|
|
87
|
-
tokenMint,
|
|
88
|
-
config: configPda,
|
|
89
|
-
userStake: userStakePda,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function withdraw(
|
|
94
|
-
program: Program<Svault>,
|
|
95
|
-
user: PublicKey,
|
|
96
|
-
tokenMint: PublicKey,
|
|
97
|
-
nonce: number
|
|
98
|
-
) {
|
|
99
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
100
|
-
const [userStakePda] = deriveUserStakePDA(configPda, user, program.programId);
|
|
101
|
-
const [stakeVault] = deriveStakeVaultPDA(configPda, program.programId);
|
|
102
|
-
const userTokenAccount = getAssociatedTokenAddressSync(tokenMint, user);
|
|
103
|
-
|
|
104
|
-
return program.methods.withdraw().accountsPartial({
|
|
105
|
-
user,
|
|
106
|
-
tokenMint,
|
|
107
|
-
config: configPda,
|
|
108
|
-
userStake: userStakePda,
|
|
109
|
-
stakeVault,
|
|
110
|
-
userTokenAccount,
|
|
111
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function postRewards(
|
|
116
|
-
program: Program<Svault>,
|
|
117
|
-
admin: PublicKey,
|
|
118
|
-
tokenMint: PublicKey,
|
|
119
|
-
nonce: number,
|
|
120
|
-
merkleRoot: number[],
|
|
121
|
-
totalAmount: BN | number
|
|
122
|
-
) {
|
|
123
|
-
const merkleRootArray = merkleRoot as number[];
|
|
124
|
-
const totalAmountBN = typeof totalAmount === "number" ? new BN(totalAmount) : totalAmount;
|
|
125
|
-
|
|
126
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
127
|
-
const [rewardVault] = deriveRewardVaultPDA(configPda, program.programId);
|
|
128
|
-
const adminTokenAccount = getAssociatedTokenAddressSync(tokenMint, admin);
|
|
129
|
-
|
|
130
|
-
return program.methods
|
|
131
|
-
.postRewards(merkleRootArray, totalAmountBN)
|
|
132
|
-
.accountsPartial({
|
|
133
|
-
admin,
|
|
134
|
-
tokenMint,
|
|
135
|
-
config: configPda,
|
|
136
|
-
rewardVault,
|
|
137
|
-
adminTokenAccount,
|
|
138
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function claimRewards(
|
|
143
|
-
program: Program<Svault>,
|
|
144
|
-
user: PublicKey,
|
|
145
|
-
tokenMint: PublicKey,
|
|
146
|
-
nonce: number,
|
|
147
|
-
cumulativeAmount: BN | number,
|
|
148
|
-
proof: number[][]
|
|
149
|
-
) {
|
|
150
|
-
const cumulativeAmountBN = typeof cumulativeAmount === "number" ? new BN(cumulativeAmount) : cumulativeAmount;
|
|
151
|
-
|
|
152
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
153
|
-
const [userStakePda] = deriveUserStakePDA(configPda, user, program.programId);
|
|
154
|
-
const [rewardVault] = deriveRewardVaultPDA(configPda, program.programId);
|
|
155
|
-
const userTokenAccount = getAssociatedTokenAddressSync(tokenMint, user);
|
|
156
|
-
|
|
157
|
-
return program.methods
|
|
158
|
-
.claimRewards(cumulativeAmountBN, proof)
|
|
159
|
-
.accountsPartial({
|
|
160
|
-
user,
|
|
161
|
-
tokenMint,
|
|
162
|
-
config: configPda,
|
|
163
|
-
userStake: userStakePda,
|
|
164
|
-
rewardVault,
|
|
165
|
-
userTokenAccount,
|
|
166
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function setConfig(
|
|
171
|
-
program: Program<Svault>,
|
|
172
|
-
admin: PublicKey,
|
|
173
|
-
tokenMint: PublicKey,
|
|
174
|
-
nonce: number,
|
|
175
|
-
unstakingPeriod: BN | number | null,
|
|
176
|
-
volumeWindow: BN | number | null
|
|
177
|
-
) {
|
|
178
|
-
const unstakingPeriodArg = unstakingPeriod === null
|
|
179
|
-
? null
|
|
180
|
-
: typeof unstakingPeriod === "number"
|
|
181
|
-
? new BN(unstakingPeriod)
|
|
182
|
-
: unstakingPeriod;
|
|
183
|
-
|
|
184
|
-
const volumeWindowArg = volumeWindow === null
|
|
185
|
-
? null
|
|
186
|
-
: typeof volumeWindow === "number"
|
|
187
|
-
? new BN(volumeWindow)
|
|
188
|
-
: volumeWindow;
|
|
189
|
-
|
|
190
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
191
|
-
|
|
192
|
-
return program.methods
|
|
193
|
-
.setConfig(unstakingPeriodArg, volumeWindowArg)
|
|
194
|
-
.accountsPartial({
|
|
195
|
-
admin,
|
|
196
|
-
config: configPda,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function slash(
|
|
201
|
-
program: Program<Svault>,
|
|
202
|
-
admin: PublicKey,
|
|
203
|
-
tokenMint: PublicKey,
|
|
204
|
-
nonce: number,
|
|
205
|
-
userStakePda: PublicKey,
|
|
206
|
-
basisPoints: number
|
|
207
|
-
) {
|
|
208
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
209
|
-
const [stakeVault] = deriveStakeVaultPDA(configPda, program.programId);
|
|
210
|
-
const feeVault = getAssociatedTokenAddressSync(tokenMint, FEE_AUTHORITY);
|
|
211
|
-
|
|
212
|
-
return program.methods.slash(basisPoints).accountsPartial({
|
|
213
|
-
admin,
|
|
214
|
-
tokenMint,
|
|
215
|
-
config: configPda,
|
|
216
|
-
userStake: userStakePda,
|
|
217
|
-
stakeVault,
|
|
218
|
-
feeVault,
|
|
219
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function addDelegate(
|
|
224
|
-
program: Program<Svault>,
|
|
225
|
-
staker: PublicKey,
|
|
226
|
-
delegateWallet: PublicKey,
|
|
227
|
-
tokenMint: PublicKey,
|
|
228
|
-
nonce: number
|
|
229
|
-
) {
|
|
230
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
231
|
-
const [userStakePda] = deriveUserStakePDA(configPda, staker, program.programId);
|
|
232
|
-
const [delegatePda] = deriveDelegatePDA(configPda, delegateWallet, program.programId);
|
|
233
|
-
|
|
234
|
-
return program.methods.addDelegate().accountsPartial({
|
|
235
|
-
staker,
|
|
236
|
-
delegateWallet,
|
|
237
|
-
config: configPda,
|
|
238
|
-
userStake: userStakePda,
|
|
239
|
-
delegate: delegatePda,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function removeDelegate(
|
|
244
|
-
program: Program<Svault>,
|
|
245
|
-
staker: PublicKey,
|
|
246
|
-
delegateWallet: PublicKey,
|
|
247
|
-
tokenMint: PublicKey,
|
|
248
|
-
nonce: number
|
|
249
|
-
) {
|
|
250
|
-
const [configPda] = deriveStakingConfigPDA(tokenMint, nonce, program.programId);
|
|
251
|
-
const [delegatePda] = deriveDelegatePDA(configPda, delegateWallet, program.programId);
|
|
252
|
-
|
|
253
|
-
return program.methods.removeDelegate().accountsPartial({
|
|
254
|
-
staker,
|
|
255
|
-
config: configPda,
|
|
256
|
-
delegate: delegatePda,
|
|
257
|
-
});
|
|
258
|
-
}
|
package/src/svault/types.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Type definitions for the SVault program.
|
|
3
|
-
* Exports IDL-derived types and SDK-friendly enums.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { IdlAccounts, IdlEvents } from "@coral-xyz/anchor";
|
|
7
|
-
import { TxOptions } from "../utils";
|
|
8
|
-
|
|
9
|
-
export { Svault } from "../generated/types";
|
|
10
|
-
import type { Svault } from "../generated/types";
|
|
11
|
-
|
|
12
|
-
/* IDL-derived Account Types */
|
|
13
|
-
|
|
14
|
-
export type StakingConfigAccount = IdlAccounts<Svault>["stakingConfig"];
|
|
15
|
-
export type UserStakeAccount = IdlAccounts<Svault>["userStake"];
|
|
16
|
-
export type DelegateAccount = IdlAccounts<Svault>["delegate"];
|
|
17
|
-
|
|
18
|
-
/* IDL-derived Event Types */
|
|
19
|
-
|
|
20
|
-
export type StakingVaultInitializedEvent = IdlEvents<Svault>["stakingVaultInitialized"];
|
|
21
|
-
export type StakedEvent = IdlEvents<Svault>["staked"];
|
|
22
|
-
export type UnstakeInitiatedEvent = IdlEvents<Svault>["unstakeInitiated"];
|
|
23
|
-
export type WithdrawnEvent = IdlEvents<Svault>["withdrawn"];
|
|
24
|
-
export type RewardsPostedEvent = IdlEvents<Svault>["rewardsPosted"];
|
|
25
|
-
export type RewardsClaimedEvent = IdlEvents<Svault>["rewardsClaimed"];
|
|
26
|
-
export type SlashedEvent = IdlEvents<Svault>["slashed"];
|
|
27
|
-
export type DelegateAddedEvent = IdlEvents<Svault>["delegateAdded"];
|
|
28
|
-
export type DelegateRemovedEvent = IdlEvents<Svault>["delegateRemoved"];
|
|
29
|
-
|
|
30
|
-
/* Event Union Type */
|
|
31
|
-
|
|
32
|
-
export type SVaultEvent =
|
|
33
|
-
| { name: "StakingVaultInitialized"; data: StakingVaultInitializedEvent }
|
|
34
|
-
| { name: "Staked"; data: StakedEvent }
|
|
35
|
-
| { name: "UnstakeInitiated"; data: UnstakeInitiatedEvent }
|
|
36
|
-
| { name: "Withdrawn"; data: WithdrawnEvent }
|
|
37
|
-
| { name: "RewardsPosted"; data: RewardsPostedEvent }
|
|
38
|
-
| { name: "RewardsClaimed"; data: RewardsClaimedEvent }
|
|
39
|
-
| { name: "Slashed"; data: SlashedEvent }
|
|
40
|
-
| { name: "DelegateAdded"; data: DelegateAddedEvent }
|
|
41
|
-
| { name: "DelegateRemoved"; data: DelegateRemovedEvent };
|
|
42
|
-
|
|
43
|
-
/* Client Options */
|
|
44
|
-
|
|
45
|
-
export interface SVaultTxOptions extends TxOptions {}
|
package/src/svault/utils.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Utility functions for the SVault program.
|
|
3
|
-
* PDA derivation, state parsing, and account fetching.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Program } from "@coral-xyz/anchor";
|
|
7
|
-
import { PublicKey } from "@solana/web3.js";
|
|
8
|
-
import {
|
|
9
|
-
STAKING_CONFIG_SEED,
|
|
10
|
-
USER_STAKE_SEED,
|
|
11
|
-
STAKE_VAULT_SEED,
|
|
12
|
-
REWARD_VAULT_SEED,
|
|
13
|
-
PROGRAM_ID,
|
|
14
|
-
SECONDS_PER_DAY,
|
|
15
|
-
} from "./constants";
|
|
16
|
-
import { Svault, StakingConfigAccount, UserStakeAccount, DelegateAccount } from "./types";
|
|
17
|
-
|
|
18
|
-
/* PDA Derivation */
|
|
19
|
-
|
|
20
|
-
export function deriveStakingConfigPDA(
|
|
21
|
-
tokenMint: PublicKey,
|
|
22
|
-
nonce: number,
|
|
23
|
-
programId: PublicKey = PROGRAM_ID
|
|
24
|
-
): [PublicKey, number] {
|
|
25
|
-
const nonceBuffer = Buffer.alloc(2);
|
|
26
|
-
nonceBuffer.writeUInt16LE(nonce);
|
|
27
|
-
return PublicKey.findProgramAddressSync(
|
|
28
|
-
[STAKING_CONFIG_SEED, tokenMint.toBuffer(), nonceBuffer],
|
|
29
|
-
programId
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function deriveUserStakePDA(
|
|
34
|
-
stakingConfig: PublicKey,
|
|
35
|
-
user: PublicKey,
|
|
36
|
-
programId: PublicKey = PROGRAM_ID
|
|
37
|
-
): [PublicKey, number] {
|
|
38
|
-
return PublicKey.findProgramAddressSync(
|
|
39
|
-
[USER_STAKE_SEED, stakingConfig.toBuffer(), user.toBuffer()],
|
|
40
|
-
programId
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function deriveDelegatePDA(
|
|
45
|
-
stakingConfig: PublicKey,
|
|
46
|
-
delegate: PublicKey,
|
|
47
|
-
programId: PublicKey = PROGRAM_ID
|
|
48
|
-
): [PublicKey, number] {
|
|
49
|
-
// Uses USER_STAKE_SEED to prevent delegate from also being a staker
|
|
50
|
-
return PublicKey.findProgramAddressSync(
|
|
51
|
-
[USER_STAKE_SEED, stakingConfig.toBuffer(), delegate.toBuffer()],
|
|
52
|
-
programId
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function deriveStakeVaultPDA(
|
|
57
|
-
stakingConfig: PublicKey,
|
|
58
|
-
programId: PublicKey = PROGRAM_ID
|
|
59
|
-
): [PublicKey, number] {
|
|
60
|
-
return PublicKey.findProgramAddressSync(
|
|
61
|
-
[STAKE_VAULT_SEED, stakingConfig.toBuffer()],
|
|
62
|
-
programId
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function deriveRewardVaultPDA(
|
|
67
|
-
stakingConfig: PublicKey,
|
|
68
|
-
programId: PublicKey = PROGRAM_ID
|
|
69
|
-
): [PublicKey, number] {
|
|
70
|
-
return PublicKey.findProgramAddressSync(
|
|
71
|
-
[REWARD_VAULT_SEED, stakingConfig.toBuffer()],
|
|
72
|
-
programId
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/* Fetchers */
|
|
77
|
-
|
|
78
|
-
export async function fetchStakingConfigAccount(
|
|
79
|
-
program: Program<Svault>,
|
|
80
|
-
pda: PublicKey
|
|
81
|
-
): Promise<StakingConfigAccount> {
|
|
82
|
-
return program.account.stakingConfig.fetch(pda);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export async function fetchUserStakeAccount(
|
|
86
|
-
program: Program<Svault>,
|
|
87
|
-
pda: PublicKey
|
|
88
|
-
): Promise<UserStakeAccount> {
|
|
89
|
-
return program.account.userStake.fetch(pda);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function fetchDelegateAccount(
|
|
93
|
-
program: Program<Svault>,
|
|
94
|
-
pda: PublicKey
|
|
95
|
-
): Promise<DelegateAccount> {
|
|
96
|
-
return program.account.delegate.fetch(pda);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/* Helpers */
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Compute when withdrawal will be available based on unstake initiation time.
|
|
103
|
-
* @param unstakeInitiatedAt Unix timestamp when unstake was initiated (seconds)
|
|
104
|
-
* @param unstakingPeriodDays Number of days in unstaking period
|
|
105
|
-
* @returns Date when withdrawal becomes available
|
|
106
|
-
*/
|
|
107
|
-
export function computeWithdrawAvailableAt(
|
|
108
|
-
unstakeInitiatedAt: number,
|
|
109
|
-
unstakingPeriodDays: number
|
|
110
|
-
): Date {
|
|
111
|
-
const availableAtSeconds = unstakeInitiatedAt + unstakingPeriodDays * SECONDS_PER_DAY;
|
|
112
|
-
return new Date(availableAtSeconds * 1000);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Check if withdrawal is currently available.
|
|
117
|
-
* @param unstakeInitiatedAt Unix timestamp when unstake was initiated (seconds)
|
|
118
|
-
* @param unstakingPeriodDays Number of days in unstaking period
|
|
119
|
-
* @returns true if unstaking period has elapsed
|
|
120
|
-
*/
|
|
121
|
-
export function isWithdrawAvailable(
|
|
122
|
-
unstakeInitiatedAt: number,
|
|
123
|
-
unstakingPeriodDays: number
|
|
124
|
-
): boolean {
|
|
125
|
-
if (unstakeInitiatedAt === 0) return false;
|
|
126
|
-
const now = Math.floor(Date.now() / 1000);
|
|
127
|
-
const availableAt = unstakeInitiatedAt + unstakingPeriodDays * SECONDS_PER_DAY;
|
|
128
|
-
return now >= availableAt;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Compute the time remaining until withdrawal is available.
|
|
133
|
-
* @param unstakeInitiatedAt Unix timestamp when unstake was initiated (seconds)
|
|
134
|
-
* @param unstakingPeriodDays Number of days in unstaking period
|
|
135
|
-
* @returns Seconds remaining, or 0 if already available
|
|
136
|
-
*/
|
|
137
|
-
export function getTimeUntilWithdraw(
|
|
138
|
-
unstakeInitiatedAt: number,
|
|
139
|
-
unstakingPeriodDays: number
|
|
140
|
-
): number {
|
|
141
|
-
if (unstakeInitiatedAt === 0) return 0;
|
|
142
|
-
const now = Math.floor(Date.now() / 1000);
|
|
143
|
-
const availableAt = unstakeInitiatedAt + unstakingPeriodDays * SECONDS_PER_DAY;
|
|
144
|
-
return Math.max(0, availableAt - now);
|
|
145
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Shared utilities for parsing IDL values and common types.
|
|
3
|
-
* Used across program SDKs.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/* Transaction Options */
|
|
7
|
-
|
|
8
|
-
export interface TxOptions {
|
|
9
|
-
includeCuBudget?: boolean; // Include compute budget instruction (default: true)
|
|
10
|
-
computeUnits?: number; // Override default compute units
|
|
11
|
-
/**
|
|
12
|
-
* Pre-create conditional token ATAs before launch to avoid exceeding
|
|
13
|
-
* Solana's 64 instruction trace limit. Default: true for 3+ options.
|
|
14
|
-
* Set to false if you've already created ATAs or want to manage them manually.
|
|
15
|
-
*/
|
|
16
|
-
ensureATAs?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
* Parse IDL bytes value string to Buffer.
|
|
21
|
-
* e.g., "[99, 109, 105, 110, 116]" → Buffer.from([99, 109, 105, 110, 116])
|
|
22
|
-
*/
|
|
23
|
-
export function parseIdlBytes(value: string): Buffer {
|
|
24
|
-
const bytes = JSON.parse(value) as number[];
|
|
25
|
-
return Buffer.from(bytes);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/*
|
|
29
|
-
* Get a constant from an IDL by name.
|
|
30
|
-
* Throws if the constant is not found (helps catch mismatches after IDL sync).
|
|
31
|
-
*/
|
|
32
|
-
export function getIdlConstant(
|
|
33
|
-
idl: { constants: Array<{ name: string; value: string }> },
|
|
34
|
-
name: string
|
|
35
|
-
) {
|
|
36
|
-
const constant = idl.constants.find((c) => c.name === name);
|
|
37
|
-
if (!constant) {
|
|
38
|
-
throw new Error(`IDL missing constant: ${name}`);
|
|
39
|
-
}
|
|
40
|
-
return constant.value;
|
|
41
|
-
}
|