lfx-reward-back-sdk 0.1.0 → 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/dist/client.d.ts +11 -2
- package/dist/client.js +22 -2
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -41,10 +41,19 @@ export declare class LfxRewardBackClient {
|
|
|
41
41
|
/**
|
|
42
42
|
* Admin: withdraw_tokens
|
|
43
43
|
*
|
|
44
|
-
*
|
|
45
|
-
* Caller must pass the recipient ATA (for withdrawal_wallet).
|
|
44
|
+
* Low-level instruction builder. Use buildWithdrawTokensIxs for automatic ATA creation.
|
|
46
45
|
*/
|
|
47
46
|
withdrawTokensIx(recipientTokenAccount: web3.PublicKey, tokenMint: web3.PublicKey, amount: bigint | number): web3.TransactionInstruction;
|
|
47
|
+
/**
|
|
48
|
+
* Admin: withdraw_tokens (high-level helper)
|
|
49
|
+
*
|
|
50
|
+
* Automatically calculates withdrawal wallet's ATA and includes ATA creation instruction if needed.
|
|
51
|
+
* Reads withdrawal_wallet from GlobalInfo and derives its ATA for the token mint.
|
|
52
|
+
*/
|
|
53
|
+
buildWithdrawTokensIxs(withdrawalWallet: web3.PublicKey, tokenMint: web3.PublicKey, amount: bigint | number): Promise<{
|
|
54
|
+
ixs: web3.TransactionInstruction[];
|
|
55
|
+
recipientTokenAccount: web3.PublicKey;
|
|
56
|
+
}>;
|
|
48
57
|
/**
|
|
49
58
|
* Admin: start_withdrawal_vote
|
|
50
59
|
*/
|
package/dist/client.js
CHANGED
|
@@ -202,8 +202,7 @@ class LfxRewardBackClient {
|
|
|
202
202
|
/**
|
|
203
203
|
* Admin: withdraw_tokens
|
|
204
204
|
*
|
|
205
|
-
*
|
|
206
|
-
* Caller must pass the recipient ATA (for withdrawal_wallet).
|
|
205
|
+
* Low-level instruction builder. Use buildWithdrawTokensIxs for automatic ATA creation.
|
|
207
206
|
*/
|
|
208
207
|
withdrawTokensIx(recipientTokenAccount, tokenMint, amount) {
|
|
209
208
|
const [globalInfoPda] = this.getGlobalInfoPDA();
|
|
@@ -227,6 +226,27 @@ class LfxRewardBackClient {
|
|
|
227
226
|
data,
|
|
228
227
|
});
|
|
229
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Admin: withdraw_tokens (high-level helper)
|
|
231
|
+
*
|
|
232
|
+
* Automatically calculates withdrawal wallet's ATA and includes ATA creation instruction if needed.
|
|
233
|
+
* Reads withdrawal_wallet from GlobalInfo and derives its ATA for the token mint.
|
|
234
|
+
*/
|
|
235
|
+
async buildWithdrawTokensIxs(withdrawalWallet, tokenMint, amount) {
|
|
236
|
+
const ixs = [];
|
|
237
|
+
// Automatically calculate withdrawal wallet's ATA
|
|
238
|
+
const recipientTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(tokenMint, withdrawalWallet, false, spl_token_1.TOKEN_2022_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
239
|
+
// Ensure ATA exists (processed commitment for fast UX)
|
|
240
|
+
const ataInfo = await this.connection.getAccountInfo(recipientTokenAccount, 'processed');
|
|
241
|
+
if (!ataInfo) {
|
|
242
|
+
ixs.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.wallet.publicKey, // payer (admin)
|
|
243
|
+
recipientTokenAccount, withdrawalWallet, // owner
|
|
244
|
+
tokenMint, spl_token_1.TOKEN_2022_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID));
|
|
245
|
+
}
|
|
246
|
+
// Append withdraw_tokens ix
|
|
247
|
+
ixs.push(this.withdrawTokensIx(recipientTokenAccount, tokenMint, amount));
|
|
248
|
+
return { ixs, recipientTokenAccount };
|
|
249
|
+
}
|
|
230
250
|
/**
|
|
231
251
|
* Admin: start_withdrawal_vote
|
|
232
252
|
*/
|