@nosana/kit 1.0.8 → 1.0.10
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.
|
@@ -98,4 +98,18 @@ export declare class MerkleDistributorProgram extends BaseProgram {
|
|
|
98
98
|
target: ClaimTarget;
|
|
99
99
|
claimant?: KeyPairSigner;
|
|
100
100
|
}): Promise<ReturnType<typeof programClient.getNewClaimInstruction>>;
|
|
101
|
+
/**
|
|
102
|
+
* Clawback tokens from a merkle distributor.
|
|
103
|
+
* This function creates a clawback instruction to transfer tokens from the distributor's token vault to the clawback receiver.
|
|
104
|
+
*
|
|
105
|
+
* @param params Parameters for clawback
|
|
106
|
+
* @param params.distributor The address of the merkle distributor
|
|
107
|
+
* @param params.claimant Optional claimant signer. If not provided, uses the wallet.
|
|
108
|
+
* @returns The clawback instruction
|
|
109
|
+
* @throws Error if wallet is not set and claimant is not provided
|
|
110
|
+
*/
|
|
111
|
+
clawback(params: {
|
|
112
|
+
distributor: Address;
|
|
113
|
+
claimant?: KeyPairSigner;
|
|
114
|
+
}): Promise<ReturnType<typeof programClient.getClawbackInstruction>>;
|
|
101
115
|
}
|
|
@@ -293,4 +293,45 @@ export class MerkleDistributorProgram extends BaseProgram {
|
|
|
293
293
|
throw err;
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Clawback tokens from a merkle distributor.
|
|
298
|
+
* This function creates a clawback instruction to transfer tokens from the distributor's token vault to the clawback receiver.
|
|
299
|
+
*
|
|
300
|
+
* @param params Parameters for clawback
|
|
301
|
+
* @param params.distributor The address of the merkle distributor
|
|
302
|
+
* @param params.claimant Optional claimant signer. If not provided, uses the wallet.
|
|
303
|
+
* @returns The clawback instruction
|
|
304
|
+
* @throws Error if wallet is not set and claimant is not provided
|
|
305
|
+
*/
|
|
306
|
+
async clawback(params) {
|
|
307
|
+
// Determine claimant signer
|
|
308
|
+
let claimantSigner;
|
|
309
|
+
if (params.claimant) {
|
|
310
|
+
claimantSigner = params.claimant;
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
if (!this.sdk.wallet) {
|
|
314
|
+
throw new Error('Wallet not set. Please set a wallet or provide a claimant signer.');
|
|
315
|
+
}
|
|
316
|
+
claimantSigner = this.sdk.wallet;
|
|
317
|
+
}
|
|
318
|
+
try {
|
|
319
|
+
// Get the distributor account to find tokenVault and clawbackReceiver
|
|
320
|
+
const distributorAccount = await this.client.fetchMerkleDistributor(this.sdk.solana.rpc, params.distributor);
|
|
321
|
+
// Create clawback instruction
|
|
322
|
+
const clawbackInstruction = this.client.getClawbackInstruction({
|
|
323
|
+
distributor: params.distributor,
|
|
324
|
+
from: distributorAccount.data.tokenVault,
|
|
325
|
+
to: distributorAccount.data.clawbackReceiver,
|
|
326
|
+
claimant: claimantSigner,
|
|
327
|
+
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
328
|
+
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
329
|
+
}, { programAddress: this.getProgramId() });
|
|
330
|
+
return clawbackInstruction;
|
|
331
|
+
}
|
|
332
|
+
catch (err) {
|
|
333
|
+
this.sdk.logger.error(`Failed to create clawback instruction: ${err}`);
|
|
334
|
+
throw err;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
296
337
|
}
|
|
@@ -17,7 +17,29 @@ export class SolanaService {
|
|
|
17
17
|
const addressEncoder = getAddressEncoder();
|
|
18
18
|
const [pda] = await getProgramDerivedAddress({
|
|
19
19
|
programAddress: programId,
|
|
20
|
-
seeds: seeds.map((seed) =>
|
|
20
|
+
seeds: seeds.map((seed) => {
|
|
21
|
+
// Address is a branded string type, so typeof will return 'string'
|
|
22
|
+
// We need to encode Address types to bytes for PDA seeds
|
|
23
|
+
// Try to encode if it looks like an address (base58, 32-44 chars), otherwise pass as-is
|
|
24
|
+
if (typeof seed === 'string') {
|
|
25
|
+
// Check if it's likely an address (base58 encoded addresses are 32-44 chars)
|
|
26
|
+
// Short strings like 'ClaimStatus' should be passed as-is
|
|
27
|
+
if (seed.length >= 32 && seed.length <= 44) {
|
|
28
|
+
try {
|
|
29
|
+
// Try to encode as Address - if it's a valid address, this will work
|
|
30
|
+
return addressEncoder.encode(seed);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// If encoding fails, it's not a valid address, pass as-is (e.g., 'ClaimStatus')
|
|
34
|
+
return seed;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Short strings pass as-is
|
|
38
|
+
return seed;
|
|
39
|
+
}
|
|
40
|
+
// Non-string types should be encoded
|
|
41
|
+
return addressEncoder.encode(seed);
|
|
42
|
+
}),
|
|
21
43
|
});
|
|
22
44
|
return pda;
|
|
23
45
|
}
|