@streamflow/distributor 10.0.3 → 11.0.0-alpha.p334.7c3dbf7

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/esm/index.js CHANGED
@@ -1,12 +1,10 @@
1
- import { PublicKey, TransactionInstruction, Connection, SystemProgram } from '@solana/web3.js';
1
+ import { PublicKey, Connection, SystemProgram } from '@solana/web3.js';
2
+ import BN from 'bn.js';
2
3
  import '@solana/wallet-adapter-base';
3
- import { ICluster, multiplyBigIntByNumber, fetchTokenPrice, signAndExecuteTransaction, ContractError, divCeilN, invariant, getNumberFromBN, getBN, buildSendThrottler, prepareBaseInstructions, getMintAndProgram, ata, prepareWrappedAccount, createAndEstimateTransaction, prepareTransaction, checkOrCreateAtaBatch, pk, unwrapExecutionParams } from '@streamflow/common';
4
- import { Program } from '@coral-xyz/anchor';
5
- import * as borsh7 from '@coral-xyz/borsh';
4
+ import { parseIdlErrors, translateError, Program } from '@coral-xyz/anchor';
5
+ import { NATIVE_MINT, getAssociatedTokenAddressSync, getTransferFeeConfig, createTransferCheckedWithFeeInstruction, createTransferCheckedInstruction } from '@solana/spl-token';
6
+ import { ICluster, multiplyBigIntByNumber, fetchTokenPrice, signAndExecuteTransaction, ContractError, divCeilN, invariant, getNumberFromBN, pk, getBN, buildPartnerOracle, buildSendThrottler, prepareBaseInstructions, getMintAndProgram, ata, prepareWrappedAccount, createAndEstimateTransaction, prepareTransaction, checkOrCreateAtaBatch, unwrapExecutionParams } from '@streamflow/common';
6
7
  import { Buffer as Buffer$1 } from 'buffer';
7
- import BN5 from 'bn.js';
8
- import { NATIVE_MINT, getTransferFeeConfig, ASSOCIATED_TOKEN_PROGRAM_ID, createTransferCheckedWithFeeInstruction, createTransferCheckedInstruction } from '@solana/spl-token';
9
- import bs58 from 'bs58';
10
8
 
11
9
  var __defProp = Object.defineProperty;
12
10
  var __export = (target, all) => {
@@ -23,7 +21,6 @@ __export(solana_exports, {
23
21
  FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR: () => FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR,
24
22
  MAXIMUM_FEE_FALLBACK: () => MAXIMUM_FEE_FALLBACK,
25
23
  MINIMUM_FEE_FALLBACK: () => MINIMUM_FEE_FALLBACK,
26
- MerkleDistributor: () => MerkleDistributor,
27
24
  SolanaAlignedDistributorClient: () => SolanaAlignedDistributorClient,
28
25
  SolanaDistributorClient: () => SolanaDistributorClient,
29
26
  applyFeeLogic: () => applyFeeLogic,
@@ -31,24 +28,15 @@ __export(solana_exports, {
31
28
  calculateAmountWithTransferFees: () => calculateAmountWithTransferFees,
32
29
  calculateClaimableLamportsFromPrices: () => calculateClaimableLamportsFromPrices,
33
30
  calculateDynamicFeeFromSolParams: () => calculateDynamicFeeFromSolParams,
34
- claimLocked: () => claimLocked,
35
- clawback: () => clawback,
36
- closeClaim: () => closeClaim,
37
31
  constants: () => constants_exports,
38
32
  fetchAirdropFee: () => fetchAirdropFee,
39
- fromCode: () => fromCode3,
40
- fromTxError: () => fromTxError,
41
33
  getAlignedDistributorPda: () => getAlignedDistributorPda,
42
34
  getClaimantStatusPda: () => getClaimantStatusPda,
43
35
  getDistributorPda: () => getDistributorPda,
44
36
  getEventAuthorityPda: () => getEventAuthorityPda,
45
37
  getTestOraclePda: () => getTestOraclePda,
46
38
  isCompressedClaimStatus: () => isCompressedClaimStatus,
47
- newClaim: () => newClaim,
48
- newDistributor: () => newDistributor,
49
39
  resolveAirdropFeeLamportsUsingApi: () => resolveAirdropFeeLamportsUsingApi,
50
- setAdmin: () => setAdmin,
51
- setClawbackReceiver: () => setClawbackReceiver,
52
40
  toLamportsSOL: () => toLamportsSOL,
53
41
  wrappedSignAndExecuteTransaction: () => wrappedSignAndExecuteTransaction
54
42
  });
@@ -133,187 +121,12 @@ var ContractErrorCode = /* @__PURE__ */ ((ContractErrorCode2) => {
133
121
  ContractErrorCode2["ClaimsAreNotClosable"] = "ClaimsAreNotClosable";
134
122
  return ContractErrorCode2;
135
123
  })(ContractErrorCode || {});
136
- var PROGRAM_ID_CLI = new PublicKey("MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N");
137
- var PROGRAM_ID = PROGRAM_ID_CLI;
138
-
139
- // solana/generated/instructions/newDistributor.ts
140
- var layout = borsh7.struct([
141
- borsh7.u64("version"),
142
- borsh7.array(borsh7.u8(), 32, "root"),
143
- borsh7.u64("maxTotalClaim"),
144
- borsh7.u64("maxNumNodes"),
145
- borsh7.u64("unlockPeriod"),
146
- borsh7.u64("startVestingTs"),
147
- borsh7.u64("endVestingTs"),
148
- borsh7.u64("clawbackStartTs"),
149
- borsh7.bool("claimsClosableByAdmin"),
150
- borsh7.option(borsh7.bool(), "canUpdateDuration"),
151
- borsh7.option(borsh7.u64(), "totalAmountUnlocked"),
152
- borsh7.option(borsh7.u64(), "totalAmountLocked"),
153
- borsh7.option(borsh7.bool(), "claimsClosableByClaimant"),
154
- borsh7.option(borsh7.u16(), "claimsLimit")
155
- ]);
156
- function newDistributor(args, accounts, programId = PROGRAM_ID) {
157
- const keys = [
158
- { pubkey: accounts.distributor, isSigner: false, isWritable: true },
159
- { pubkey: accounts.clawbackReceiver, isSigner: false, isWritable: true },
160
- { pubkey: accounts.mint, isSigner: false, isWritable: false },
161
- { pubkey: accounts.tokenVault, isSigner: false, isWritable: true },
162
- { pubkey: accounts.admin, isSigner: true, isWritable: true },
163
- { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
164
- {
165
- pubkey: accounts.associatedTokenProgram,
166
- isSigner: false,
167
- isWritable: false
168
- },
169
- { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }
170
- ];
171
- const identifier = Buffer$1.from([32, 139, 112, 171, 0, 2, 225, 155]);
172
- const buffer = Buffer$1.alloc(1e3);
173
- const len = layout.encode(
174
- {
175
- version: args.version,
176
- root: args.root,
177
- maxTotalClaim: args.maxTotalClaim,
178
- maxNumNodes: args.maxNumNodes,
179
- unlockPeriod: args.unlockPeriod,
180
- startVestingTs: args.startVestingTs,
181
- endVestingTs: args.endVestingTs,
182
- clawbackStartTs: args.clawbackStartTs,
183
- claimsClosableByAdmin: args.claimsClosableByAdmin,
184
- canUpdateDuration: null,
185
- totalAmountUnlocked: null,
186
- totalAmountLocked: null,
187
- claimsClosableByClaimant: args.claimsClosableByClaimant ?? null,
188
- claimsLimit: args.claimsLimit ?? null
189
- },
190
- buffer
191
- );
192
- const data = Buffer$1.concat([identifier, buffer]).slice(0, 8 + len);
193
- const ix = new TransactionInstruction({ keys, programId, data });
194
- return ix;
195
- }
196
- var layout2 = borsh7.struct([
197
- borsh7.u64("amountUnlocked"),
198
- borsh7.u64("amountLocked"),
199
- borsh7.vec(borsh7.array(borsh7.u8(), 32), "proof")
200
- ]);
201
- function newClaim(args, accounts, programId = PROGRAM_ID) {
202
- const keys = [
203
- { pubkey: accounts.distributor, isSigner: false, isWritable: true },
204
- { pubkey: accounts.claimStatus, isSigner: false, isWritable: true },
205
- { pubkey: accounts.from, isSigner: false, isWritable: true },
206
- { pubkey: accounts.to, isSigner: false, isWritable: true },
207
- { pubkey: accounts.claimant, isSigner: true, isWritable: true },
208
- { pubkey: accounts.mint, isSigner: false, isWritable: false },
209
- { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
210
- { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
211
- { pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
212
- { pubkey: accounts.program, isSigner: false, isWritable: false }
213
- ];
214
- const identifier = Buffer.from([78, 177, 98, 123, 210, 21, 187, 83]);
215
- const buffer = Buffer.alloc(1e3);
216
- const len = layout2.encode(
217
- {
218
- amountUnlocked: args.amountUnlocked,
219
- amountLocked: args.amountLocked,
220
- proof: args.proof
221
- },
222
- buffer
223
- );
224
- const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len);
225
- const ix = new TransactionInstruction({ keys, programId, data });
226
- return ix;
227
- }
228
- function claimLocked(accounts, programId = PROGRAM_ID) {
229
- const keys = [
230
- { pubkey: accounts.distributor, isSigner: false, isWritable: true },
231
- { pubkey: accounts.claimStatus, isSigner: false, isWritable: true },
232
- { pubkey: accounts.from, isSigner: false, isWritable: true },
233
- { pubkey: accounts.to, isSigner: false, isWritable: true },
234
- { pubkey: accounts.claimant, isSigner: true, isWritable: true },
235
- { pubkey: accounts.mint, isSigner: false, isWritable: false },
236
- { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
237
- { pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
238
- { pubkey: accounts.program, isSigner: false, isWritable: false }
239
- ];
240
- const identifier = Buffer.from([34, 206, 181, 23, 11, 207, 147, 90]);
241
- const data = identifier;
242
- const ix = new TransactionInstruction({ keys, programId, data });
243
- return ix;
244
- }
245
- function clawback(accounts, programId = PROGRAM_ID) {
246
- const keys = [
247
- { pubkey: accounts.distributor, isSigner: false, isWritable: true },
248
- { pubkey: accounts.from, isSigner: false, isWritable: true },
249
- { pubkey: accounts.to, isSigner: false, isWritable: true },
250
- { pubkey: accounts.admin, isSigner: true, isWritable: true },
251
- { pubkey: accounts.mint, isSigner: false, isWritable: false },
252
- { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
253
- { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }
254
- ];
255
- const identifier = Buffer$1.from([111, 92, 142, 79, 33, 234, 82, 27]);
256
- const data = identifier;
257
- const ix = new TransactionInstruction({ keys, programId, data });
258
- return ix;
259
- }
260
- var layout3 = borsh7.struct([
261
- borsh7.option(borsh7.u64(), "amountUnlocked"),
262
- borsh7.option(borsh7.u64(), "amountLocked"),
263
- borsh7.option(borsh7.vec(borsh7.array(borsh7.u8(), 32)), "proof")
264
- ]);
265
- function closeClaim(args, accounts, programId = PROGRAM_ID) {
266
- const keys = [
267
- { pubkey: accounts.distributor, isSigner: false, isWritable: true },
268
- { pubkey: accounts.adminOrClaimant, isSigner: true, isWritable: true },
269
- { pubkey: accounts.payer, isSigner: true, isWritable: true },
270
- { pubkey: accounts.claimant, isSigner: false, isWritable: true },
271
- { pubkey: accounts.claimStatus, isSigner: false, isWritable: true },
272
- { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
273
- { pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
274
- { pubkey: accounts.program, isSigner: false, isWritable: false }
275
- ];
276
- const identifier = Buffer$1.from([42, 177, 165, 35, 213, 179, 211, 19]);
277
- const buffer = Buffer$1.alloc(1e3);
278
- const len = layout3.encode(
279
- {
280
- amountUnlocked: args.amountUnlocked ?? null,
281
- amountLocked: args.amountLocked ?? null,
282
- proof: args.proof ?? null
283
- },
284
- buffer
285
- );
286
- const data = Buffer$1.concat([identifier, buffer]).slice(0, 8 + len);
287
- const ix = new TransactionInstruction({ keys, programId, data });
288
- return ix;
289
- }
290
- function setClawbackReceiver(accounts, programId = PROGRAM_ID) {
291
- const keys = [
292
- { pubkey: accounts.distributor, isSigner: false, isWritable: true },
293
- { pubkey: accounts.newClawbackAccount, isSigner: false, isWritable: false },
294
- { pubkey: accounts.admin, isSigner: true, isWritable: true }
295
- ];
296
- const identifier = Buffer$1.from([153, 217, 34, 20, 19, 29, 229, 75]);
297
- const data = identifier;
298
- const ix = new TransactionInstruction({ keys, programId, data });
299
- return ix;
300
- }
301
- function setAdmin(accounts, programId = PROGRAM_ID) {
302
- const keys = [
303
- { pubkey: accounts.distributor, isSigner: false, isWritable: true },
304
- { pubkey: accounts.admin, isSigner: true, isWritable: true },
305
- { pubkey: accounts.newAdmin, isSigner: false, isWritable: true }
306
- ];
307
- const identifier = Buffer$1.from([251, 163, 0, 52, 91, 194, 187, 92]);
308
- const data = identifier;
309
- const ix = new TransactionInstruction({ keys, programId, data });
310
- return ix;
311
- }
312
124
 
313
125
  // solana/constants.ts
314
126
  var constants_exports = {};
315
127
  __export(constants_exports, {
316
128
  AIRDROP_CLAIM_FEE: () => AIRDROP_CLAIM_FEE,
129
+ ALIGNED_DISTRIBUTOR_ERRORS: () => ALIGNED_DISTRIBUTOR_ERRORS,
317
130
  ALIGNED_DISTRIBUTOR_PREFIX: () => ALIGNED_DISTRIBUTOR_PREFIX,
318
131
  ALIGNED_DISTRIBUTOR_PROGRAM_ID: () => ALIGNED_DISTRIBUTOR_PROGRAM_ID,
319
132
  ALIGNED_PRECISION_FACTOR_POW: () => ALIGNED_PRECISION_FACTOR_POW,
@@ -323,194 +136,21 @@ __export(constants_exports, {
323
136
  DISTRIBUTOR_MINT_OFFSET: () => DISTRIBUTOR_MINT_OFFSET,
324
137
  DISTRIBUTOR_PREFIX: () => DISTRIBUTOR_PREFIX,
325
138
  DISTRIBUTOR_PROGRAM_ID: () => DISTRIBUTOR_PROGRAM_ID,
139
+ FEE_CONFIG_PUBLIC_KEY: () => FEE_CONFIG_PUBLIC_KEY,
140
+ MERKLE_DISTRIBUTOR_ERRORS: () => MERKLE_DISTRIBUTOR_ERRORS,
326
141
  ONE_IN_BASIS_POINTS: () => ONE_IN_BASIS_POINTS,
142
+ PARTNER_ORACLE_PROGRAM_ID: () => PARTNER_ORACLE_PROGRAM_ID,
143
+ SOL_FEE_PROGRAM_VERSION: () => SOL_FEE_PROGRAM_VERSION,
327
144
  STREAMFLOW_TREASURY_PUBLIC_KEY: () => STREAMFLOW_TREASURY_PUBLIC_KEY,
328
145
  TEST_ORACLE_PREFIX: () => TEST_ORACLE_PREFIX
329
146
  });
330
- var ANCHOR_DISCRIMINATOR_OFFSET = 8;
331
- var DISTRIBUTOR_MINT_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 41;
332
- var DISTRIBUTOR_ADMIN_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 201;
333
- var DISTRIBUTOR_PREFIX = Buffer.from("MerkleDistributor", "utf-8");
334
- var ALIGNED_DISTRIBUTOR_PREFIX = Buffer.from("aligned-distributor", "utf-8");
335
- var TEST_ORACLE_PREFIX = Buffer.from("test-oracle", "utf-8");
336
- var CLAIM_STATUS_PREFIX = Buffer.from("ClaimStatus", "utf-8");
337
- var ALIGNED_PRECISION_FACTOR_POW = 9;
338
- var AIRDROP_CLAIM_FEE = BigInt(1e7);
339
- var STREAMFLOW_TREASURY_PUBLIC_KEY = new PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
340
- var ONE_IN_BASIS_POINTS = BigInt(1e4);
341
- var ALIGNED_DISTRIBUTOR_PROGRAM_ID = {
342
- [ICluster.Devnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
343
- [ICluster.Mainnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
344
- [ICluster.Testnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
345
- [ICluster.Local]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2"
346
- };
347
- var DISTRIBUTOR_PROGRAM_ID = {
348
- [ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
349
- [ICluster.Mainnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
350
- [ICluster.Testnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
351
- [ICluster.Local]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N"
352
- };
353
-
354
- // solana/fetchAirdropFee.ts
355
- var fetchAirdropFee = async (distributorId, apiUrl, apiKey, fetchFn = fetch) => {
356
- const url = `${apiUrl}/v2/api/airdrops/${encodeURIComponent(distributorId)}/fees`;
357
- const res = await fetchFn(url, {
358
- method: "GET",
359
- headers: {
360
- "Content-Type": "application/json",
361
- ...apiKey ? { "x-api-key": apiKey } : {}
362
- }
363
- });
364
- if (!res.ok) {
365
- const text = await res.text().catch(() => "");
366
- throw new Error(`Airdrop fee API error: ${res.status} ${res.statusText}${text ? ` - ${text}` : ""}`);
367
- }
368
- const json = await res.json();
369
- return json;
370
- };
371
-
372
- // solana/fees.ts
373
- var MAXIMUM_FEE_FALLBACK = 9900000n;
374
- var MINIMUM_FEE_FALLBACK = 5000000n;
375
- var FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR = 90n;
376
- var FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR = 100n;
377
- var LAMPORTS_PER_SOL = 1000000000n;
378
- var lamportsToSolString = (lamports) => {
379
- const int = lamports / LAMPORTS_PER_SOL;
380
- const frac = lamports % LAMPORTS_PER_SOL;
381
- if (frac === 0n) return int.toString();
382
- const fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
383
- return `${int.toString()}.${fracStr}`;
384
- };
385
- var allocationToString = (num, den) => {
386
- const SCALE = 1000000000n;
387
- const scaled = num * SCALE / den;
388
- const int = scaled / SCALE;
389
- const frac = scaled % SCALE;
390
- if (frac === 0n) return int.toString();
391
- const fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
392
- return `${int.toString()}.${fracStr}`;
393
- };
394
- var defaultAPIFeesResponse = {
395
- isCustom: false,
396
- claimFee: void 0,
397
- claimFeeDynamic: {
398
- minPrice: lamportsToSolString(MINIMUM_FEE_FALLBACK),
399
- maxPrice: lamportsToSolString(MAXIMUM_FEE_FALLBACK),
400
- allocationFactor: allocationToString(
401
- FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR,
402
- FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR
403
- )
404
- }
405
- };
406
- var toLamportsSOL = (value, solDecimals = 9) => {
407
- const y = typeof value === "bigint" ? Number(value) : typeof value === "string" ? Number(value) : value;
408
- if (!Number.isFinite(y) || y <= 0) return 0n;
409
- const scale = 10n ** BigInt(solDecimals);
410
- return multiplyBigIntByNumber(scale, y);
411
- };
412
- var applyFeeLogic = (baseLamports) => {
413
- if (baseLamports <= 0n) {
414
- return MINIMUM_FEE_FALLBACK;
415
- }
416
- const raw = baseLamports * FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR / FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR;
417
- if (raw < MINIMUM_FEE_FALLBACK) return MINIMUM_FEE_FALLBACK;
418
- if (raw > MAXIMUM_FEE_FALLBACK) return MAXIMUM_FEE_FALLBACK;
419
- return raw;
420
- };
421
- async function calculateAirdropFeeLamports(params) {
422
- const { distributorAddress, client, claimableLamports } = params;
423
- try {
424
- if (client) {
425
- const res = await client.getAirdropFee(distributorAddress);
426
- const data = res?.data;
427
- if (data?.isCustom && data.claimFee !== void 0) {
428
- return toLamportsSOL(data.claimFee);
429
- }
430
- if (data?.claimFeeDynamic && claimableLamports !== void 0) {
431
- const min = toLamportsSOL(data.claimFeeDynamic.minPrice);
432
- const max = toLamportsSOL(data.claimFeeDynamic.maxPrice);
433
- const factor = Math.max(0, Math.min(1, parseFloat(data.claimFeeDynamic.allocationFactor)));
434
- const fee = multiplyBigIntByNumber(claimableLamports, factor);
435
- if (fee < min) return min;
436
- if (fee > max) return max;
437
- return fee;
438
- }
439
- }
440
- } catch (_err) {
441
- }
442
- if (claimableLamports !== void 0) {
443
- return applyFeeLogic(claimableLamports);
444
- }
445
- return MINIMUM_FEE_FALLBACK;
446
- }
447
- function calculateClaimableLamportsFromPrices(params) {
448
- const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
449
- if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
450
- const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
451
- const SCALE = 10n ** BigInt(scaleDigits);
452
- const pScaled = multiplyBigIntByNumber(SCALE, tokenPriceUsd, scaleDigits);
453
- const sScaled = multiplyBigIntByNumber(SCALE, solPriceUsd, scaleDigits);
454
- if (pScaled <= 0n || sScaled <= 0n) return 0n;
455
- const pow10 = (n) => 10n ** BigInt(n);
456
- const numerator = claimableAmount * pow10(solDecimals) * pScaled;
457
- const denominator = pow10(tokenDecimals) * sScaled;
458
- return numerator / denominator;
459
- }
460
- function calculateDynamicFeeFromSolParams(params) {
461
- const { minPrice, maxPrice, allocationFactor, claimableLamports, solDecimals = 9 } = params;
462
- const minLamports = toLamportsSOL(minPrice, solDecimals);
463
- const maxLamports = toLamportsSOL(maxPrice, solDecimals);
464
- const factor = Math.max(0, Math.min(1, parseFloat(allocationFactor)));
465
- const raw = multiplyBigIntByNumber(claimableLamports, factor);
466
- if (raw < minLamports) return minLamports;
467
- if (raw > maxLamports) return maxLamports;
468
- return raw;
469
- }
470
- async function resolveAirdropFeeLamportsUsingApi(params) {
471
- const { distributorAddress, mintAccount, claimableAmount, cluster, apiUrl, apiKey } = params;
472
- let apiFeesResponse = void 0;
473
- try {
474
- apiFeesResponse = await fetchAirdropFee(distributorAddress, apiUrl, apiKey);
475
- } catch (_) {
476
- }
477
- let solPrice = null;
478
- let tokenPrice = null;
479
- try {
480
- [solPrice, tokenPrice] = await Promise.all([
481
- fetchTokenPrice(NATIVE_MINT.toBase58(), cluster),
482
- fetchTokenPrice(mintAccount.address.toBase58(), cluster)
483
- ]);
484
- } catch (_) {
485
- }
486
- const response = apiFeesResponse ?? defaultAPIFeesResponse;
487
- if (response?.isCustom && response.claimFee !== void 0 && response.claimFee !== null) {
488
- return toLamportsSOL(response.claimFee);
489
- }
490
- const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
491
- if (!tokenPrice?.value || !solPrice?.value) {
492
- return MINIMUM_FEE_FALLBACK;
493
- }
494
- const baseLamports = calculateClaimableLamportsFromPrices({
495
- claimableAmount,
496
- tokenPriceUsd: tokenPrice.value,
497
- solPriceUsd: solPrice.value,
498
- tokenDecimals: mintAccount.decimals
499
- });
500
- return calculateDynamicFeeFromSolParams({
501
- minPrice: claimFeeDynamic.minPrice,
502
- maxPrice: claimFeeDynamic.maxPrice,
503
- allocationFactor: claimFeeDynamic.allocationFactor,
504
- claimableLamports: baseLamports
505
- });
506
- }
507
147
 
508
148
  // solana/descriptor/idl/merkle_distributor.json
509
149
  var merkle_distributor_default = {
510
150
  address: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
511
151
  metadata: {
512
152
  name: "merkle_distributor",
513
- version: "1.5.1",
153
+ version: "2.0.0",
514
154
  spec: "0.1.0",
515
155
  description: "A Solana program for distributing tokens according to a Merkle root.",
516
156
  repository: "https://github.com/streamflow-finance/distributor"
@@ -795,16 +435,16 @@ var merkle_distributor_default = {
795
435
  args: []
796
436
  },
797
437
  {
798
- name: "clawback",
438
+ name: "claim_locked_v2",
799
439
  discriminator: [
800
- 111,
801
- 92,
802
- 142,
803
- 79,
804
- 33,
805
- 234,
806
- 82,
807
- 27
440
+ 44,
441
+ 21,
442
+ 175,
443
+ 161,
444
+ 99,
445
+ 76,
446
+ 44,
447
+ 249
808
448
  ],
809
449
  accounts: [
810
450
  {
@@ -814,17 +454,291 @@ var merkle_distributor_default = {
814
454
  ],
815
455
  writable: true
816
456
  },
457
+ {
458
+ name: "claim_status",
459
+ writable: true,
460
+ pda: {
461
+ seeds: [
462
+ {
463
+ kind: "const",
464
+ value: [
465
+ 67,
466
+ 108,
467
+ 97,
468
+ 105,
469
+ 109,
470
+ 83,
471
+ 116,
472
+ 97,
473
+ 116,
474
+ 117,
475
+ 115
476
+ ]
477
+ },
478
+ {
479
+ kind: "account",
480
+ path: "claimant"
481
+ },
482
+ {
483
+ kind: "account",
484
+ path: "distributor"
485
+ }
486
+ ]
487
+ }
488
+ },
817
489
  {
818
490
  name: "from",
819
491
  docs: [
820
492
  "Distributor ATA containing the tokens to distribute."
821
493
  ],
822
- writable: true
823
- },
824
- {
825
- name: "to",
826
- docs: [
827
- "The Clawback token account."
494
+ writable: true,
495
+ pda: {
496
+ seeds: [
497
+ {
498
+ kind: "account",
499
+ path: "distributor"
500
+ },
501
+ {
502
+ kind: "account",
503
+ path: "token_program"
504
+ },
505
+ {
506
+ kind: "account",
507
+ path: "distributor.mint",
508
+ account: "MerkleDistributor"
509
+ }
510
+ ],
511
+ program: {
512
+ kind: "const",
513
+ value: [
514
+ 140,
515
+ 151,
516
+ 37,
517
+ 143,
518
+ 78,
519
+ 36,
520
+ 137,
521
+ 241,
522
+ 187,
523
+ 61,
524
+ 16,
525
+ 41,
526
+ 20,
527
+ 142,
528
+ 13,
529
+ 131,
530
+ 11,
531
+ 90,
532
+ 19,
533
+ 153,
534
+ 218,
535
+ 255,
536
+ 16,
537
+ 132,
538
+ 4,
539
+ 142,
540
+ 123,
541
+ 216,
542
+ 219,
543
+ 233,
544
+ 248,
545
+ 89
546
+ ]
547
+ }
548
+ }
549
+ },
550
+ {
551
+ name: "to",
552
+ docs: [
553
+ "Account to send the claimed tokens to.",
554
+ "Claimant must sign the transaction and can only claim on behalf of themself"
555
+ ],
556
+ writable: true
557
+ },
558
+ {
559
+ name: "claimant",
560
+ docs: [
561
+ "Who is claiming the tokens."
562
+ ],
563
+ writable: true,
564
+ signer: true
565
+ },
566
+ {
567
+ name: "mint",
568
+ docs: [
569
+ "The mint to claim."
570
+ ],
571
+ relations: [
572
+ "distributor"
573
+ ]
574
+ },
575
+ {
576
+ name: "token_program",
577
+ docs: [
578
+ "SPL [Token] program."
579
+ ]
580
+ },
581
+ {
582
+ name: "system_program",
583
+ docs: [
584
+ "System program for fee transfers."
585
+ ],
586
+ address: "11111111111111111111111111111111"
587
+ },
588
+ {
589
+ name: "event_authority",
590
+ pda: {
591
+ seeds: [
592
+ {
593
+ kind: "const",
594
+ value: [
595
+ 95,
596
+ 95,
597
+ 101,
598
+ 118,
599
+ 101,
600
+ 110,
601
+ 116,
602
+ 95,
603
+ 97,
604
+ 117,
605
+ 116,
606
+ 104,
607
+ 111,
608
+ 114,
609
+ 105,
610
+ 116,
611
+ 121
612
+ ]
613
+ }
614
+ ]
615
+ }
616
+ },
617
+ {
618
+ name: "program"
619
+ }
620
+ ],
621
+ args: []
622
+ },
623
+ {
624
+ name: "claim_sol_fees",
625
+ discriminator: [
626
+ 127,
627
+ 0,
628
+ 119,
629
+ 89,
630
+ 193,
631
+ 27,
632
+ 209,
633
+ 142
634
+ ],
635
+ accounts: [
636
+ {
637
+ name: "distributor",
638
+ docs: [
639
+ "The [MerkleDistributor]."
640
+ ],
641
+ writable: true
642
+ },
643
+ {
644
+ name: "treasury",
645
+ writable: true,
646
+ address: "5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw"
647
+ }
648
+ ],
649
+ args: []
650
+ },
651
+ {
652
+ name: "claim_token_fees",
653
+ discriminator: [
654
+ 205,
655
+ 136,
656
+ 215,
657
+ 209,
658
+ 62,
659
+ 196,
660
+ 69,
661
+ 182
662
+ ],
663
+ accounts: [
664
+ {
665
+ name: "distributor",
666
+ docs: [
667
+ "The [MerkleDistributor]."
668
+ ],
669
+ writable: true
670
+ },
671
+ {
672
+ name: "token_vault",
673
+ docs: [
674
+ "Token vault to return clawback fee from"
675
+ ],
676
+ writable: true,
677
+ relations: [
678
+ "distributor"
679
+ ]
680
+ },
681
+ {
682
+ name: "mint",
683
+ docs: [
684
+ "Distributor mint"
685
+ ],
686
+ relations: [
687
+ "distributor"
688
+ ]
689
+ },
690
+ {
691
+ name: "treasury",
692
+ writable: true,
693
+ address: "5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw"
694
+ },
695
+ {
696
+ name: "to",
697
+ docs: [
698
+ "Account to send the clawed back fee to."
699
+ ],
700
+ writable: true
701
+ },
702
+ {
703
+ name: "token_program",
704
+ docs: [
705
+ "SPL [Token] program."
706
+ ]
707
+ }
708
+ ],
709
+ args: []
710
+ },
711
+ {
712
+ name: "clawback",
713
+ discriminator: [
714
+ 111,
715
+ 92,
716
+ 142,
717
+ 79,
718
+ 33,
719
+ 234,
720
+ 82,
721
+ 27
722
+ ],
723
+ accounts: [
724
+ {
725
+ name: "distributor",
726
+ docs: [
727
+ "The [MerkleDistributor]."
728
+ ],
729
+ writable: true
730
+ },
731
+ {
732
+ name: "from",
733
+ docs: [
734
+ "Distributor ATA containing the tokens to distribute."
735
+ ],
736
+ writable: true
737
+ },
738
+ {
739
+ name: "to",
740
+ docs: [
741
+ "The Clawback token account."
828
742
  ],
829
743
  writable: true
830
744
  },
@@ -1448,34 +1362,104 @@ var merkle_distributor_default = {
1448
1362
  docs: [
1449
1363
  "The [Token] program."
1450
1364
  ]
1451
- }
1452
- ],
1453
- args: [
1454
- {
1455
- name: "version",
1456
- type: "u64"
1457
- },
1458
- {
1459
- name: "root",
1460
- type: {
1461
- array: [
1462
- "u8",
1463
- 32
1464
- ]
1465
- }
1466
- },
1467
- {
1468
- name: "max_total_claim",
1469
- type: "u64"
1470
- },
1471
- {
1472
- name: "max_num_nodes",
1473
- type: "u64"
1474
1365
  },
1475
1366
  {
1476
- name: "unlock_period",
1477
- type: "u64"
1478
- },
1367
+ name: "partner_oracle_config",
1368
+ pda: {
1369
+ seeds: [
1370
+ {
1371
+ kind: "const",
1372
+ value: [
1373
+ 97,
1374
+ 105,
1375
+ 114,
1376
+ 100,
1377
+ 114,
1378
+ 111,
1379
+ 112,
1380
+ 95,
1381
+ 99,
1382
+ 111,
1383
+ 110,
1384
+ 102,
1385
+ 105,
1386
+ 103
1387
+ ]
1388
+ }
1389
+ ],
1390
+ program: {
1391
+ kind: "const",
1392
+ value: [
1393
+ 12,
1394
+ 48,
1395
+ 148,
1396
+ 48,
1397
+ 221,
1398
+ 89,
1399
+ 2,
1400
+ 209,
1401
+ 180,
1402
+ 126,
1403
+ 151,
1404
+ 216,
1405
+ 166,
1406
+ 3,
1407
+ 112,
1408
+ 50,
1409
+ 177,
1410
+ 192,
1411
+ 141,
1412
+ 218,
1413
+ 37,
1414
+ 78,
1415
+ 51,
1416
+ 109,
1417
+ 243,
1418
+ 106,
1419
+ 174,
1420
+ 122,
1421
+ 93,
1422
+ 121,
1423
+ 191,
1424
+ 119
1425
+ ]
1426
+ }
1427
+ }
1428
+ },
1429
+ {
1430
+ name: "partner_oracle",
1431
+ docs: [
1432
+ "Partner Oracle program that stores fees"
1433
+ ],
1434
+ address: "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa"
1435
+ }
1436
+ ],
1437
+ args: [
1438
+ {
1439
+ name: "version",
1440
+ type: "u64"
1441
+ },
1442
+ {
1443
+ name: "root",
1444
+ type: {
1445
+ array: [
1446
+ "u8",
1447
+ 32
1448
+ ]
1449
+ }
1450
+ },
1451
+ {
1452
+ name: "max_total_claim",
1453
+ type: "u64"
1454
+ },
1455
+ {
1456
+ name: "max_num_nodes",
1457
+ type: "u64"
1458
+ },
1459
+ {
1460
+ name: "unlock_period",
1461
+ type: "u64"
1462
+ },
1479
1463
  {
1480
1464
  name: "start_vesting_ts",
1481
1465
  type: "u64"
@@ -1677,6 +1661,43 @@ var merkle_distributor_default = {
1677
1661
  ],
1678
1662
  args: []
1679
1663
  },
1664
+ {
1665
+ name: "set_token_price",
1666
+ discriminator: [
1667
+ 166,
1668
+ 216,
1669
+ 142,
1670
+ 197,
1671
+ 200,
1672
+ 225,
1673
+ 253,
1674
+ 233
1675
+ ],
1676
+ accounts: [
1677
+ {
1678
+ name: "authority",
1679
+ docs: [
1680
+ "Wallet authorized to call this method"
1681
+ ],
1682
+ writable: true,
1683
+ signer: true,
1684
+ address: "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u"
1685
+ },
1686
+ {
1687
+ name: "distributor",
1688
+ docs: [
1689
+ "The [MerkleDistributor]."
1690
+ ],
1691
+ writable: true
1692
+ }
1693
+ ],
1694
+ args: [
1695
+ {
1696
+ name: "price_lamports",
1697
+ type: "u64"
1698
+ }
1699
+ ]
1700
+ },
1680
1701
  {
1681
1702
  name: "update",
1682
1703
  discriminator: [
@@ -1925,6 +1946,21 @@ var merkle_distributor_default = {
1925
1946
  code: 6023,
1926
1947
  name: "ClaimsLimitReached",
1927
1948
  msg: "Claims limit has been reached"
1949
+ },
1950
+ {
1951
+ code: 6024,
1952
+ name: "InsufficientFunds",
1953
+ msg: "Account does not have enough funds to cover fees"
1954
+ },
1955
+ {
1956
+ code: 6025,
1957
+ name: "ClaimV2Required",
1958
+ msg: "This Airdrop must be claimed via claimLockedV2"
1959
+ },
1960
+ {
1961
+ code: 6026,
1962
+ name: "NoFeesToClaim",
1963
+ msg: "No fees to claim"
1928
1964
  }
1929
1965
  ],
1930
1966
  types: [
@@ -2279,26 +2315,84 @@ var merkle_distributor_default = {
2279
2315
  type: "u16"
2280
2316
  },
2281
2317
  {
2282
- name: "buffer_2",
2318
+ name: "creation_fee",
2283
2319
  docs: [
2284
- "Buffer for additional fields"
2320
+ "Creation SOL fee"
2285
2321
  ],
2286
- type: {
2287
- array: [
2288
- "u8",
2289
- 20
2290
- ]
2291
- }
2322
+ type: "u32"
2292
2323
  },
2293
2324
  {
2294
- name: "buffer_3",
2325
+ name: "creation_fee_claimed",
2326
+ docs: [
2327
+ "Whether creation SOL was claimed"
2328
+ ],
2329
+ type: "bool"
2330
+ },
2331
+ {
2332
+ name: "claim_min_fee",
2333
+ docs: [
2334
+ "Dynamic claim fee in SOL, min"
2335
+ ],
2336
+ type: "u32"
2337
+ },
2338
+ {
2339
+ name: "claim_max_fee",
2340
+ docs: [
2341
+ "Dynamic claim fee in SOL, max"
2342
+ ],
2343
+ type: "u32"
2344
+ },
2345
+ {
2346
+ name: "allocation_factor",
2347
+ docs: [
2348
+ "Factor to multiply claimable SOL lamports by when calculating fee"
2349
+ ],
2350
+ type: "f64"
2351
+ },
2352
+ {
2353
+ name: "claim_fee_claimed",
2354
+ docs: [
2355
+ "Whether all claim fees were claimed, true by default since no claim fee is taken on creation"
2356
+ ],
2357
+ type: "bool"
2358
+ },
2359
+ {
2360
+ name: "token_price_lamports",
2361
+ docs: [
2362
+ "Last observed token price in lamports per 1 whole token for claim fee calculation"
2363
+ ],
2364
+ type: "u64"
2365
+ },
2366
+ {
2367
+ name: "clawback_token_fee_percent",
2368
+ docs: [
2369
+ "Token % fee on clawback"
2370
+ ],
2371
+ type: "f64"
2372
+ },
2373
+ {
2374
+ name: "clawback_fee_claimed",
2375
+ docs: [
2376
+ "Whether clawback token % fee has been claimed"
2377
+ ],
2378
+ type: "bool"
2379
+ },
2380
+ {
2381
+ name: "program_version",
2382
+ docs: [
2383
+ "Program version that initiated the Distributor account"
2384
+ ],
2385
+ type: "u8"
2386
+ },
2387
+ {
2388
+ name: "buffer",
2295
2389
  docs: [
2296
2390
  "Buffer for additional fields"
2297
2391
  ],
2298
2392
  type: {
2299
2393
  array: [
2300
2394
  "u8",
2301
- 32
2395
+ 13
2302
2396
  ]
2303
2397
  }
2304
2398
  }
@@ -2346,1676 +2440,13 @@ var merkle_distributor_default = {
2346
2440
  }
2347
2441
  ]
2348
2442
  };
2349
- var _MerkleDistributor = class _MerkleDistributor {
2350
- constructor(fields) {
2351
- this.bump = fields.bump;
2352
- this.version = fields.version;
2353
- this.root = fields.root;
2354
- this.mint = fields.mint;
2355
- this.tokenVault = fields.tokenVault;
2356
- this.maxTotalClaim = fields.maxTotalClaim;
2357
- this.maxNumNodes = fields.maxNumNodes;
2358
- this.unlockPeriod = fields.unlockPeriod;
2359
- this.totalAmountClaimed = fields.totalAmountClaimed;
2360
- this.numNodesClaimed = fields.numNodesClaimed;
2361
- this.startTs = fields.startTs;
2362
- this.endTs = fields.endTs;
2363
- this.clawbackStartTs = fields.clawbackStartTs;
2364
- this.clawbackReceiver = fields.clawbackReceiver;
2365
- this.admin = fields.admin;
2366
- this.clawedBack = fields.clawedBack;
2367
- this.claimsClosableByAdmin = fields.claimsClosableByAdmin;
2368
- this.canUpdateDuration = fields.canUpdateDuration;
2369
- this.totalAmountUnlocked = fields.totalAmountUnlocked;
2370
- this.totalAmountLocked = fields.totalAmountLocked;
2371
- this.lastDurationUpdateTs = fields.lastDurationUpdateTs;
2372
- this.totalClaimablePreUpdate = fields.totalClaimablePreUpdate;
2373
- this.clawedBackTs = fields.clawedBackTs;
2374
- this.claimsClosableByClaimant = fields.claimsClosableByClaimant;
2375
- this.claimsLimit = fields.claimsLimit;
2376
- this.buffer2 = fields.buffer2;
2377
- this.buffer3 = fields.buffer3;
2378
- }
2379
- static async fetch(c, address, programId = PROGRAM_ID) {
2380
- const info = await c.getAccountInfo(address);
2381
- if (info === null) {
2382
- return null;
2383
- }
2384
- if (!info.owner.equals(programId)) {
2385
- throw new Error("account doesn't belong to this program");
2386
- }
2387
- return this.decode(info.data);
2388
- }
2389
- static async fetchMultiple(c, addresses, programId = PROGRAM_ID) {
2390
- const infos = await c.getMultipleAccountsInfo(addresses);
2391
- return infos.map((info) => {
2392
- if (info === null) {
2393
- return null;
2394
- }
2395
- if (!info.owner.equals(programId)) {
2396
- throw new Error("account doesn't belong to this program");
2397
- }
2398
- return this.decode(info.data);
2399
- });
2400
- }
2401
- static decode(data) {
2402
- if (!data.slice(0, 8).equals(_MerkleDistributor.discriminator)) {
2403
- throw new Error("invalid account discriminator");
2404
- }
2405
- const dec = _MerkleDistributor.layout.decode(data.slice(8));
2406
- return new _MerkleDistributor({
2407
- bump: dec.bump,
2408
- version: dec.version,
2409
- root: dec.root,
2410
- mint: dec.mint,
2411
- tokenVault: dec.tokenVault,
2412
- maxTotalClaim: dec.maxTotalClaim,
2413
- maxNumNodes: dec.maxNumNodes,
2414
- unlockPeriod: dec.unlockPeriod,
2415
- totalAmountClaimed: dec.totalAmountClaimed,
2416
- numNodesClaimed: dec.numNodesClaimed,
2417
- startTs: dec.startTs,
2418
- endTs: dec.endTs,
2419
- clawbackStartTs: dec.clawbackStartTs,
2420
- clawbackReceiver: dec.clawbackReceiver,
2421
- admin: dec.admin,
2422
- clawedBack: dec.clawedBack,
2423
- claimsClosableByAdmin: dec.claimsClosableByAdmin,
2424
- canUpdateDuration: dec.canUpdateDuration,
2425
- totalAmountUnlocked: dec.totalAmountUnlocked,
2426
- totalAmountLocked: dec.totalAmountLocked,
2427
- lastDurationUpdateTs: dec.lastDurationUpdateTs,
2428
- totalClaimablePreUpdate: dec.totalClaimablePreUpdate,
2429
- clawedBackTs: dec.clawedBackTs,
2430
- claimsClosableByClaimant: dec.claimsClosableByClaimant,
2431
- claimsLimit: dec.claimsLimit,
2432
- buffer2: dec.buffer2,
2433
- buffer3: dec.buffer3
2434
- });
2435
- }
2436
- toJSON() {
2437
- return {
2438
- bump: this.bump,
2439
- version: this.version.toString(),
2440
- root: this.root,
2441
- mint: this.mint.toString(),
2442
- tokenVault: this.tokenVault.toString(),
2443
- maxTotalClaim: this.maxTotalClaim.toString(),
2444
- maxNumNodes: this.maxNumNodes.toString(),
2445
- unlockPeriod: this.unlockPeriod.toString(),
2446
- totalAmountClaimed: this.totalAmountClaimed.toString(),
2447
- numNodesClaimed: this.numNodesClaimed.toString(),
2448
- startTs: this.startTs.toString(),
2449
- endTs: this.endTs.toString(),
2450
- clawbackStartTs: this.clawbackStartTs.toString(),
2451
- clawbackReceiver: this.clawbackReceiver.toString(),
2452
- admin: this.admin.toString(),
2453
- clawedBack: this.clawedBack,
2454
- claimsClosableByAdmin: this.claimsClosableByAdmin,
2455
- canUpdateDuration: this.canUpdateDuration,
2456
- totalAmountUnlocked: this.totalAmountUnlocked.toString(),
2457
- totalAmountLocked: this.totalAmountLocked.toString(),
2458
- lastDurationUpdateTs: this.lastDurationUpdateTs.toString(),
2459
- totalClaimablePreUpdate: this.totalClaimablePreUpdate.toString(),
2460
- clawedBackTs: this.clawedBackTs.toString(),
2461
- claimsClosableByClaimant: this.claimsClosableByClaimant,
2462
- claimsLimit: this.claimsLimit,
2463
- buffer2: this.buffer2,
2464
- buffer3: this.buffer3
2465
- };
2466
- }
2467
- static fromJSON(obj) {
2468
- return new _MerkleDistributor({
2469
- bump: obj.bump,
2470
- version: new BN5(obj.version),
2471
- root: obj.root,
2472
- mint: new PublicKey(obj.mint),
2473
- tokenVault: new PublicKey(obj.tokenVault),
2474
- maxTotalClaim: new BN5(obj.maxTotalClaim),
2475
- maxNumNodes: new BN5(obj.maxNumNodes),
2476
- unlockPeriod: new BN5(obj.unlockPeriod),
2477
- totalAmountClaimed: new BN5(obj.totalAmountClaimed),
2478
- numNodesClaimed: new BN5(obj.numNodesClaimed),
2479
- startTs: new BN5(obj.startTs),
2480
- endTs: new BN5(obj.endTs),
2481
- clawbackStartTs: new BN5(obj.clawbackStartTs),
2482
- clawbackReceiver: new PublicKey(obj.clawbackReceiver),
2483
- admin: new PublicKey(obj.admin),
2484
- clawedBack: obj.clawedBack,
2485
- claimsClosableByAdmin: obj.claimsClosableByAdmin,
2486
- canUpdateDuration: obj.canUpdateDuration,
2487
- totalAmountUnlocked: new BN5(obj.totalAmountUnlocked),
2488
- totalAmountLocked: new BN5(obj.totalAmountLocked),
2489
- lastDurationUpdateTs: new BN5(obj.lastDurationUpdateTs),
2490
- totalClaimablePreUpdate: new BN5(obj.totalClaimablePreUpdate),
2491
- clawedBackTs: new BN5(obj.clawedBackTs),
2492
- claimsClosableByClaimant: obj.claimsClosableByClaimant,
2493
- claimsLimit: obj.claimsLimit,
2494
- buffer2: obj.buffer2,
2495
- buffer3: obj.buffer3
2496
- });
2497
- }
2498
- };
2499
- _MerkleDistributor.discriminator = Buffer.from([77, 119, 139, 70, 84, 247, 12, 26]);
2500
- _MerkleDistributor.layout = borsh7.struct([
2501
- borsh7.u8("bump"),
2502
- borsh7.u64("version"),
2503
- borsh7.array(borsh7.u8(), 32, "root"),
2504
- borsh7.publicKey("mint"),
2505
- borsh7.publicKey("tokenVault"),
2506
- borsh7.u64("maxTotalClaim"),
2507
- borsh7.u64("maxNumNodes"),
2508
- borsh7.u64("unlockPeriod"),
2509
- borsh7.u64("totalAmountClaimed"),
2510
- borsh7.u64("numNodesClaimed"),
2511
- borsh7.u64("startTs"),
2512
- borsh7.u64("endTs"),
2513
- borsh7.u64("clawbackStartTs"),
2514
- borsh7.publicKey("clawbackReceiver"),
2515
- borsh7.publicKey("admin"),
2516
- borsh7.bool("clawedBack"),
2517
- borsh7.bool("claimsClosableByAdmin"),
2518
- borsh7.bool("canUpdateDuration"),
2519
- borsh7.u64("totalAmountUnlocked"),
2520
- borsh7.u64("totalAmountLocked"),
2521
- borsh7.u64("lastDurationUpdateTs"),
2522
- borsh7.u64("totalClaimablePreUpdate"),
2523
- borsh7.u64("clawedBackTs"),
2524
- borsh7.bool("claimsClosableByClaimant"),
2525
- borsh7.u16("claimsLimit"),
2526
- borsh7.array(borsh7.u8(), 20, "buffer2"),
2527
- borsh7.array(borsh7.u8(), 32, "buffer3")
2528
- ]);
2529
- var MerkleDistributor = _MerkleDistributor;
2530
-
2531
- // solana/generated/errors/anchor.ts
2532
- var InstructionMissing = class extends Error {
2533
- constructor(logs) {
2534
- super("100: 8 byte instruction identifier not provided");
2535
- this.logs = logs;
2536
- this.code = 100;
2537
- this.name = "InstructionMissing";
2538
- this.msg = "8 byte instruction identifier not provided";
2539
- }
2540
- };
2541
- InstructionMissing.code = 100;
2542
- var InstructionFallbackNotFound = class extends Error {
2543
- constructor(logs) {
2544
- super("101: Fallback functions are not supported");
2545
- this.logs = logs;
2546
- this.code = 101;
2547
- this.name = "InstructionFallbackNotFound";
2548
- this.msg = "Fallback functions are not supported";
2549
- }
2550
- };
2551
- InstructionFallbackNotFound.code = 101;
2552
- var InstructionDidNotDeserialize = class extends Error {
2553
- constructor(logs) {
2554
- super("102: The program could not deserialize the given instruction");
2555
- this.logs = logs;
2556
- this.code = 102;
2557
- this.name = "InstructionDidNotDeserialize";
2558
- this.msg = "The program could not deserialize the given instruction";
2559
- }
2560
- };
2561
- InstructionDidNotDeserialize.code = 102;
2562
- var InstructionDidNotSerialize = class extends Error {
2563
- constructor(logs) {
2564
- super("103: The program could not serialize the given instruction");
2565
- this.logs = logs;
2566
- this.code = 103;
2567
- this.name = "InstructionDidNotSerialize";
2568
- this.msg = "The program could not serialize the given instruction";
2569
- }
2570
- };
2571
- InstructionDidNotSerialize.code = 103;
2572
- var IdlInstructionStub = class extends Error {
2573
- constructor(logs) {
2574
- super("1000: The program was compiled without idl instructions");
2575
- this.logs = logs;
2576
- this.code = 1e3;
2577
- this.name = "IdlInstructionStub";
2578
- this.msg = "The program was compiled without idl instructions";
2579
- }
2580
- };
2581
- IdlInstructionStub.code = 1e3;
2582
- var IdlInstructionInvalidProgram = class extends Error {
2583
- constructor(logs) {
2584
- super("1001: The transaction was given an invalid program for the IDL instruction");
2585
- this.logs = logs;
2586
- this.code = 1001;
2587
- this.name = "IdlInstructionInvalidProgram";
2588
- this.msg = "The transaction was given an invalid program for the IDL instruction";
2589
- }
2590
- };
2591
- IdlInstructionInvalidProgram.code = 1001;
2592
- var ConstraintMut = class extends Error {
2593
- constructor(logs) {
2594
- super("2000: A mut constraint was violated");
2595
- this.logs = logs;
2596
- this.code = 2e3;
2597
- this.name = "ConstraintMut";
2598
- this.msg = "A mut constraint was violated";
2599
- }
2600
- };
2601
- ConstraintMut.code = 2e3;
2602
- var ConstraintHasOne = class extends Error {
2603
- constructor(logs) {
2604
- super("2001: A has one constraint was violated");
2605
- this.logs = logs;
2606
- this.code = 2001;
2607
- this.name = "ConstraintHasOne";
2608
- this.msg = "A has one constraint was violated";
2609
- }
2610
- };
2611
- ConstraintHasOne.code = 2001;
2612
- var ConstraintSigner = class extends Error {
2613
- constructor(logs) {
2614
- super("2002: A signer constraint was violated");
2615
- this.logs = logs;
2616
- this.code = 2002;
2617
- this.name = "ConstraintSigner";
2618
- this.msg = "A signer constraint was violated";
2619
- }
2620
- };
2621
- ConstraintSigner.code = 2002;
2622
- var ConstraintRaw = class extends Error {
2623
- constructor(logs) {
2624
- super("2003: A raw constraint was violated");
2625
- this.logs = logs;
2626
- this.code = 2003;
2627
- this.name = "ConstraintRaw";
2628
- this.msg = "A raw constraint was violated";
2629
- }
2630
- };
2631
- ConstraintRaw.code = 2003;
2632
- var ConstraintOwner = class extends Error {
2633
- constructor(logs) {
2634
- super("2004: An owner constraint was violated");
2635
- this.logs = logs;
2636
- this.code = 2004;
2637
- this.name = "ConstraintOwner";
2638
- this.msg = "An owner constraint was violated";
2639
- }
2640
- };
2641
- ConstraintOwner.code = 2004;
2642
- var ConstraintRentExempt = class extends Error {
2643
- constructor(logs) {
2644
- super("2005: A rent exemption constraint was violated");
2645
- this.logs = logs;
2646
- this.code = 2005;
2647
- this.name = "ConstraintRentExempt";
2648
- this.msg = "A rent exemption constraint was violated";
2649
- }
2650
- };
2651
- ConstraintRentExempt.code = 2005;
2652
- var ConstraintSeeds = class extends Error {
2653
- constructor(logs) {
2654
- super("2006: A seeds constraint was violated");
2655
- this.logs = logs;
2656
- this.code = 2006;
2657
- this.name = "ConstraintSeeds";
2658
- this.msg = "A seeds constraint was violated";
2659
- }
2660
- };
2661
- ConstraintSeeds.code = 2006;
2662
- var ConstraintExecutable = class extends Error {
2663
- constructor(logs) {
2664
- super("2007: An executable constraint was violated");
2665
- this.logs = logs;
2666
- this.code = 2007;
2667
- this.name = "ConstraintExecutable";
2668
- this.msg = "An executable constraint was violated";
2669
- }
2670
- };
2671
- ConstraintExecutable.code = 2007;
2672
- var ConstraintState = class extends Error {
2673
- constructor(logs) {
2674
- super("2008: Deprecated Error, feel free to replace with something else");
2675
- this.logs = logs;
2676
- this.code = 2008;
2677
- this.name = "ConstraintState";
2678
- this.msg = "Deprecated Error, feel free to replace with something else";
2679
- }
2680
- };
2681
- ConstraintState.code = 2008;
2682
- var ConstraintAssociated = class extends Error {
2683
- constructor(logs) {
2684
- super("2009: An associated constraint was violated");
2685
- this.logs = logs;
2686
- this.code = 2009;
2687
- this.name = "ConstraintAssociated";
2688
- this.msg = "An associated constraint was violated";
2689
- }
2690
- };
2691
- ConstraintAssociated.code = 2009;
2692
- var ConstraintAssociatedInit = class extends Error {
2693
- constructor(logs) {
2694
- super("2010: An associated init constraint was violated");
2695
- this.logs = logs;
2696
- this.code = 2010;
2697
- this.name = "ConstraintAssociatedInit";
2698
- this.msg = "An associated init constraint was violated";
2699
- }
2700
- };
2701
- ConstraintAssociatedInit.code = 2010;
2702
- var ConstraintClose = class extends Error {
2703
- constructor(logs) {
2704
- super("2011: A close constraint was violated");
2705
- this.logs = logs;
2706
- this.code = 2011;
2707
- this.name = "ConstraintClose";
2708
- this.msg = "A close constraint was violated";
2709
- }
2710
- };
2711
- ConstraintClose.code = 2011;
2712
- var ConstraintAddress = class extends Error {
2713
- constructor(logs) {
2714
- super("2012: An address constraint was violated");
2715
- this.logs = logs;
2716
- this.code = 2012;
2717
- this.name = "ConstraintAddress";
2718
- this.msg = "An address constraint was violated";
2719
- }
2720
- };
2721
- ConstraintAddress.code = 2012;
2722
- var ConstraintZero = class extends Error {
2723
- constructor(logs) {
2724
- super("2013: Expected zero account discriminant");
2725
- this.logs = logs;
2726
- this.code = 2013;
2727
- this.name = "ConstraintZero";
2728
- this.msg = "Expected zero account discriminant";
2729
- }
2730
- };
2731
- ConstraintZero.code = 2013;
2732
- var ConstraintTokenMint = class extends Error {
2733
- constructor(logs) {
2734
- super("2014: A token mint constraint was violated");
2735
- this.logs = logs;
2736
- this.code = 2014;
2737
- this.name = "ConstraintTokenMint";
2738
- this.msg = "A token mint constraint was violated";
2739
- }
2740
- };
2741
- ConstraintTokenMint.code = 2014;
2742
- var ConstraintTokenOwner = class extends Error {
2743
- constructor(logs) {
2744
- super("2015: A token owner constraint was violated");
2745
- this.logs = logs;
2746
- this.code = 2015;
2747
- this.name = "ConstraintTokenOwner";
2748
- this.msg = "A token owner constraint was violated";
2749
- }
2750
- };
2751
- ConstraintTokenOwner.code = 2015;
2752
- var ConstraintMintMintAuthority = class extends Error {
2753
- constructor(logs) {
2754
- super("2016: A mint mint authority constraint was violated");
2755
- this.logs = logs;
2756
- this.code = 2016;
2757
- this.name = "ConstraintMintMintAuthority";
2758
- this.msg = "A mint mint authority constraint was violated";
2759
- }
2760
- };
2761
- ConstraintMintMintAuthority.code = 2016;
2762
- var ConstraintMintFreezeAuthority = class extends Error {
2763
- constructor(logs) {
2764
- super("2017: A mint freeze authority constraint was violated");
2765
- this.logs = logs;
2766
- this.code = 2017;
2767
- this.name = "ConstraintMintFreezeAuthority";
2768
- this.msg = "A mint freeze authority constraint was violated";
2769
- }
2770
- };
2771
- ConstraintMintFreezeAuthority.code = 2017;
2772
- var ConstraintMintDecimals = class extends Error {
2773
- constructor(logs) {
2774
- super("2018: A mint decimals constraint was violated");
2775
- this.logs = logs;
2776
- this.code = 2018;
2777
- this.name = "ConstraintMintDecimals";
2778
- this.msg = "A mint decimals constraint was violated";
2779
- }
2780
- };
2781
- ConstraintMintDecimals.code = 2018;
2782
- var ConstraintSpace = class extends Error {
2783
- constructor(logs) {
2784
- super("2019: A space constraint was violated");
2785
- this.logs = logs;
2786
- this.code = 2019;
2787
- this.name = "ConstraintSpace";
2788
- this.msg = "A space constraint was violated";
2789
- }
2790
- };
2791
- ConstraintSpace.code = 2019;
2792
- var ConstraintAccountIsNone = class extends Error {
2793
- constructor(logs) {
2794
- super("2020: A required account for the constraint is None");
2795
- this.logs = logs;
2796
- this.code = 2020;
2797
- this.name = "ConstraintAccountIsNone";
2798
- this.msg = "A required account for the constraint is None";
2799
- }
2800
- };
2801
- ConstraintAccountIsNone.code = 2020;
2802
- var RequireViolated = class extends Error {
2803
- constructor(logs) {
2804
- super("2500: A require expression was violated");
2805
- this.logs = logs;
2806
- this.code = 2500;
2807
- this.name = "RequireViolated";
2808
- this.msg = "A require expression was violated";
2809
- }
2810
- };
2811
- RequireViolated.code = 2500;
2812
- var RequireEqViolated = class extends Error {
2813
- constructor(logs) {
2814
- super("2501: A require_eq expression was violated");
2815
- this.logs = logs;
2816
- this.code = 2501;
2817
- this.name = "RequireEqViolated";
2818
- this.msg = "A require_eq expression was violated";
2819
- }
2820
- };
2821
- RequireEqViolated.code = 2501;
2822
- var RequireKeysEqViolated = class extends Error {
2823
- constructor(logs) {
2824
- super("2502: A require_keys_eq expression was violated");
2825
- this.logs = logs;
2826
- this.code = 2502;
2827
- this.name = "RequireKeysEqViolated";
2828
- this.msg = "A require_keys_eq expression was violated";
2829
- }
2830
- };
2831
- RequireKeysEqViolated.code = 2502;
2832
- var RequireNeqViolated = class extends Error {
2833
- constructor(logs) {
2834
- super("2503: A require_neq expression was violated");
2835
- this.logs = logs;
2836
- this.code = 2503;
2837
- this.name = "RequireNeqViolated";
2838
- this.msg = "A require_neq expression was violated";
2839
- }
2840
- };
2841
- RequireNeqViolated.code = 2503;
2842
- var RequireKeysNeqViolated = class extends Error {
2843
- constructor(logs) {
2844
- super("2504: A require_keys_neq expression was violated");
2845
- this.logs = logs;
2846
- this.code = 2504;
2847
- this.name = "RequireKeysNeqViolated";
2848
- this.msg = "A require_keys_neq expression was violated";
2849
- }
2850
- };
2851
- RequireKeysNeqViolated.code = 2504;
2852
- var RequireGtViolated = class extends Error {
2853
- constructor(logs) {
2854
- super("2505: A require_gt expression was violated");
2855
- this.logs = logs;
2856
- this.code = 2505;
2857
- this.name = "RequireGtViolated";
2858
- this.msg = "A require_gt expression was violated";
2859
- }
2860
- };
2861
- RequireGtViolated.code = 2505;
2862
- var RequireGteViolated = class extends Error {
2863
- constructor(logs) {
2864
- super("2506: A require_gte expression was violated");
2865
- this.logs = logs;
2866
- this.code = 2506;
2867
- this.name = "RequireGteViolated";
2868
- this.msg = "A require_gte expression was violated";
2869
- }
2870
- };
2871
- RequireGteViolated.code = 2506;
2872
- var AccountDiscriminatorAlreadySet = class extends Error {
2873
- constructor(logs) {
2874
- super("3000: The account discriminator was already set on this account");
2875
- this.logs = logs;
2876
- this.code = 3e3;
2877
- this.name = "AccountDiscriminatorAlreadySet";
2878
- this.msg = "The account discriminator was already set on this account";
2879
- }
2880
- };
2881
- AccountDiscriminatorAlreadySet.code = 3e3;
2882
- var AccountDiscriminatorNotFound = class extends Error {
2883
- constructor(logs) {
2884
- super("3001: No 8 byte discriminator was found on the account");
2885
- this.logs = logs;
2886
- this.code = 3001;
2887
- this.name = "AccountDiscriminatorNotFound";
2888
- this.msg = "No 8 byte discriminator was found on the account";
2889
- }
2890
- };
2891
- AccountDiscriminatorNotFound.code = 3001;
2892
- var AccountDiscriminatorMismatch = class extends Error {
2893
- constructor(logs) {
2894
- super("3002: 8 byte discriminator did not match what was expected");
2895
- this.logs = logs;
2896
- this.code = 3002;
2897
- this.name = "AccountDiscriminatorMismatch";
2898
- this.msg = "8 byte discriminator did not match what was expected";
2899
- }
2900
- };
2901
- AccountDiscriminatorMismatch.code = 3002;
2902
- var AccountDidNotDeserialize = class extends Error {
2903
- constructor(logs) {
2904
- super("3003: Failed to deserialize the account");
2905
- this.logs = logs;
2906
- this.code = 3003;
2907
- this.name = "AccountDidNotDeserialize";
2908
- this.msg = "Failed to deserialize the account";
2909
- }
2910
- };
2911
- AccountDidNotDeserialize.code = 3003;
2912
- var AccountDidNotSerialize = class extends Error {
2913
- constructor(logs) {
2914
- super("3004: Failed to serialize the account");
2915
- this.logs = logs;
2916
- this.code = 3004;
2917
- this.name = "AccountDidNotSerialize";
2918
- this.msg = "Failed to serialize the account";
2919
- }
2920
- };
2921
- AccountDidNotSerialize.code = 3004;
2922
- var AccountNotEnoughKeys = class extends Error {
2923
- constructor(logs) {
2924
- super("3005: Not enough account keys given to the instruction");
2925
- this.logs = logs;
2926
- this.code = 3005;
2927
- this.name = "AccountNotEnoughKeys";
2928
- this.msg = "Not enough account keys given to the instruction";
2929
- }
2930
- };
2931
- AccountNotEnoughKeys.code = 3005;
2932
- var AccountNotMutable = class extends Error {
2933
- constructor(logs) {
2934
- super("3006: The given account is not mutable");
2935
- this.logs = logs;
2936
- this.code = 3006;
2937
- this.name = "AccountNotMutable";
2938
- this.msg = "The given account is not mutable";
2939
- }
2940
- };
2941
- AccountNotMutable.code = 3006;
2942
- var AccountOwnedByWrongProgram = class extends Error {
2943
- constructor(logs) {
2944
- super("3007: The given account is owned by a different program than expected");
2945
- this.logs = logs;
2946
- this.code = 3007;
2947
- this.name = "AccountOwnedByWrongProgram";
2948
- this.msg = "The given account is owned by a different program than expected";
2949
- }
2950
- };
2951
- AccountOwnedByWrongProgram.code = 3007;
2952
- var InvalidProgramId = class extends Error {
2953
- constructor(logs) {
2954
- super("3008: Program ID was not as expected");
2955
- this.logs = logs;
2956
- this.code = 3008;
2957
- this.name = "InvalidProgramId";
2958
- this.msg = "Program ID was not as expected";
2959
- }
2960
- };
2961
- InvalidProgramId.code = 3008;
2962
- var InvalidProgramExecutable = class extends Error {
2963
- constructor(logs) {
2964
- super("3009: Program account is not executable");
2965
- this.logs = logs;
2966
- this.code = 3009;
2967
- this.name = "InvalidProgramExecutable";
2968
- this.msg = "Program account is not executable";
2969
- }
2970
- };
2971
- InvalidProgramExecutable.code = 3009;
2972
- var AccountNotSigner = class extends Error {
2973
- constructor(logs) {
2974
- super("3010: The given account did not sign");
2975
- this.logs = logs;
2976
- this.code = 3010;
2977
- this.name = "AccountNotSigner";
2978
- this.msg = "The given account did not sign";
2979
- }
2980
- };
2981
- AccountNotSigner.code = 3010;
2982
- var AccountNotSystemOwned = class extends Error {
2983
- constructor(logs) {
2984
- super("3011: The given account is not owned by the system program");
2985
- this.logs = logs;
2986
- this.code = 3011;
2987
- this.name = "AccountNotSystemOwned";
2988
- this.msg = "The given account is not owned by the system program";
2989
- }
2990
- };
2991
- AccountNotSystemOwned.code = 3011;
2992
- var AccountNotInitialized = class extends Error {
2993
- constructor(logs) {
2994
- super("3012: The program expected this account to be already initialized");
2995
- this.logs = logs;
2996
- this.code = 3012;
2997
- this.name = "AccountNotInitialized";
2998
- this.msg = "The program expected this account to be already initialized";
2999
- }
3000
- };
3001
- AccountNotInitialized.code = 3012;
3002
- var AccountNotProgramData = class extends Error {
3003
- constructor(logs) {
3004
- super("3013: The given account is not a program data account");
3005
- this.logs = logs;
3006
- this.code = 3013;
3007
- this.name = "AccountNotProgramData";
3008
- this.msg = "The given account is not a program data account";
3009
- }
3010
- };
3011
- AccountNotProgramData.code = 3013;
3012
- var AccountNotAssociatedTokenAccount = class extends Error {
3013
- constructor(logs) {
3014
- super("3014: The given account is not the associated token account");
3015
- this.logs = logs;
3016
- this.code = 3014;
3017
- this.name = "AccountNotAssociatedTokenAccount";
3018
- this.msg = "The given account is not the associated token account";
3019
- }
3020
- };
3021
- AccountNotAssociatedTokenAccount.code = 3014;
3022
- var AccountSysvarMismatch = class extends Error {
3023
- constructor(logs) {
3024
- super("3015: The given public key does not match the required sysvar");
3025
- this.logs = logs;
3026
- this.code = 3015;
3027
- this.name = "AccountSysvarMismatch";
3028
- this.msg = "The given public key does not match the required sysvar";
3029
- }
3030
- };
3031
- AccountSysvarMismatch.code = 3015;
3032
- var AccountReallocExceedsLimit = class extends Error {
3033
- constructor(logs) {
3034
- super("3016: The account reallocation exceeds the MAX_PERMITTED_DATA_INCREASE limit");
3035
- this.logs = logs;
3036
- this.code = 3016;
3037
- this.name = "AccountReallocExceedsLimit";
3038
- this.msg = "The account reallocation exceeds the MAX_PERMITTED_DATA_INCREASE limit";
3039
- }
3040
- };
3041
- AccountReallocExceedsLimit.code = 3016;
3042
- var AccountDuplicateReallocs = class extends Error {
3043
- constructor(logs) {
3044
- super("3017: The account was duplicated for more than one reallocation");
3045
- this.logs = logs;
3046
- this.code = 3017;
3047
- this.name = "AccountDuplicateReallocs";
3048
- this.msg = "The account was duplicated for more than one reallocation";
3049
- }
3050
- };
3051
- AccountDuplicateReallocs.code = 3017;
3052
- var DeclaredProgramIdMismatch = class extends Error {
3053
- constructor(logs) {
3054
- super("4100: The declared program id does not match the actual program id");
3055
- this.logs = logs;
3056
- this.code = 4100;
3057
- this.name = "DeclaredProgramIdMismatch";
3058
- this.msg = "The declared program id does not match the actual program id";
3059
- }
3060
- };
3061
- DeclaredProgramIdMismatch.code = 4100;
3062
- var Deprecated = class extends Error {
3063
- constructor(logs) {
3064
- super("5000: The API being used is deprecated and should no longer be used");
3065
- this.logs = logs;
3066
- this.code = 5e3;
3067
- this.name = "Deprecated";
3068
- this.msg = "The API being used is deprecated and should no longer be used";
3069
- }
3070
- };
3071
- Deprecated.code = 5e3;
3072
- function fromCode(code, logs) {
3073
- switch (code) {
3074
- case 100:
3075
- return new InstructionMissing(logs);
3076
- case 101:
3077
- return new InstructionFallbackNotFound(logs);
3078
- case 102:
3079
- return new InstructionDidNotDeserialize(logs);
3080
- case 103:
3081
- return new InstructionDidNotSerialize(logs);
3082
- case 1e3:
3083
- return new IdlInstructionStub(logs);
3084
- case 1001:
3085
- return new IdlInstructionInvalidProgram(logs);
3086
- case 2e3:
3087
- return new ConstraintMut(logs);
3088
- case 2001:
3089
- return new ConstraintHasOne(logs);
3090
- case 2002:
3091
- return new ConstraintSigner(logs);
3092
- case 2003:
3093
- return new ConstraintRaw(logs);
3094
- case 2004:
3095
- return new ConstraintOwner(logs);
3096
- case 2005:
3097
- return new ConstraintRentExempt(logs);
3098
- case 2006:
3099
- return new ConstraintSeeds(logs);
3100
- case 2007:
3101
- return new ConstraintExecutable(logs);
3102
- case 2008:
3103
- return new ConstraintState(logs);
3104
- case 2009:
3105
- return new ConstraintAssociated(logs);
3106
- case 2010:
3107
- return new ConstraintAssociatedInit(logs);
3108
- case 2011:
3109
- return new ConstraintClose(logs);
3110
- case 2012:
3111
- return new ConstraintAddress(logs);
3112
- case 2013:
3113
- return new ConstraintZero(logs);
3114
- case 2014:
3115
- return new ConstraintTokenMint(logs);
3116
- case 2015:
3117
- return new ConstraintTokenOwner(logs);
3118
- case 2016:
3119
- return new ConstraintMintMintAuthority(logs);
3120
- case 2017:
3121
- return new ConstraintMintFreezeAuthority(logs);
3122
- case 2018:
3123
- return new ConstraintMintDecimals(logs);
3124
- case 2019:
3125
- return new ConstraintSpace(logs);
3126
- case 2020:
3127
- return new ConstraintAccountIsNone(logs);
3128
- case 2500:
3129
- return new RequireViolated(logs);
3130
- case 2501:
3131
- return new RequireEqViolated(logs);
3132
- case 2502:
3133
- return new RequireKeysEqViolated(logs);
3134
- case 2503:
3135
- return new RequireNeqViolated(logs);
3136
- case 2504:
3137
- return new RequireKeysNeqViolated(logs);
3138
- case 2505:
3139
- return new RequireGtViolated(logs);
3140
- case 2506:
3141
- return new RequireGteViolated(logs);
3142
- case 3e3:
3143
- return new AccountDiscriminatorAlreadySet(logs);
3144
- case 3001:
3145
- return new AccountDiscriminatorNotFound(logs);
3146
- case 3002:
3147
- return new AccountDiscriminatorMismatch(logs);
3148
- case 3003:
3149
- return new AccountDidNotDeserialize(logs);
3150
- case 3004:
3151
- return new AccountDidNotSerialize(logs);
3152
- case 3005:
3153
- return new AccountNotEnoughKeys(logs);
3154
- case 3006:
3155
- return new AccountNotMutable(logs);
3156
- case 3007:
3157
- return new AccountOwnedByWrongProgram(logs);
3158
- case 3008:
3159
- return new InvalidProgramId(logs);
3160
- case 3009:
3161
- return new InvalidProgramExecutable(logs);
3162
- case 3010:
3163
- return new AccountNotSigner(logs);
3164
- case 3011:
3165
- return new AccountNotSystemOwned(logs);
3166
- case 3012:
3167
- return new AccountNotInitialized(logs);
3168
- case 3013:
3169
- return new AccountNotProgramData(logs);
3170
- case 3014:
3171
- return new AccountNotAssociatedTokenAccount(logs);
3172
- case 3015:
3173
- return new AccountSysvarMismatch(logs);
3174
- case 3016:
3175
- return new AccountReallocExceedsLimit(logs);
3176
- case 3017:
3177
- return new AccountDuplicateReallocs(logs);
3178
- case 4100:
3179
- return new DeclaredProgramIdMismatch(logs);
3180
- case 5e3:
3181
- return new Deprecated(logs);
3182
- }
3183
- return null;
3184
- }
3185
-
3186
- // solana/generated/errors/custom.ts
3187
- var InsufficientUnlockedTokens = class extends Error {
3188
- constructor(logs) {
3189
- super("6000: Insufficient unlocked tokens");
3190
- this.logs = logs;
3191
- this.code = 6e3;
3192
- this.name = "InsufficientUnlockedTokens";
3193
- this.msg = "Insufficient unlocked tokens";
3194
- }
3195
- };
3196
- InsufficientUnlockedTokens.code = 6e3;
3197
- var InvalidProof = class extends Error {
3198
- constructor(logs) {
3199
- super("6001: Invalid Merkle proof");
3200
- this.logs = logs;
3201
- this.code = 6001;
3202
- this.name = "InvalidProof";
3203
- this.msg = "Invalid Merkle proof";
3204
- }
3205
- };
3206
- InvalidProof.code = 6001;
3207
- var ExceededMaxClaim = class extends Error {
3208
- constructor(logs) {
3209
- super("6002: Exceeded maximum claim amount");
3210
- this.logs = logs;
3211
- this.code = 6002;
3212
- this.name = "ExceededMaxClaim";
3213
- this.msg = "Exceeded maximum claim amount";
3214
- }
3215
- };
3216
- ExceededMaxClaim.code = 6002;
3217
- var MaxNodesExceeded = class extends Error {
3218
- constructor(logs) {
3219
- super("6003: Exceeded maximum node count");
3220
- this.logs = logs;
3221
- this.code = 6003;
3222
- this.name = "MaxNodesExceeded";
3223
- this.msg = "Exceeded maximum node count";
3224
- }
3225
- };
3226
- MaxNodesExceeded.code = 6003;
3227
- var Unauthorized = class extends Error {
3228
- constructor(logs) {
3229
- super("6004: Account is not authorized to execute this instruction");
3230
- this.logs = logs;
3231
- this.code = 6004;
3232
- this.name = "Unauthorized";
3233
- this.msg = "Account is not authorized to execute this instruction";
3234
- }
3235
- };
3236
- Unauthorized.code = 6004;
3237
- var OwnerMismatch = class extends Error {
3238
- constructor(logs) {
3239
- super("6005: Token account owner did not match intended owner");
3240
- this.logs = logs;
3241
- this.code = 6005;
3242
- this.name = "OwnerMismatch";
3243
- this.msg = "Token account owner did not match intended owner";
3244
- }
3245
- };
3246
- OwnerMismatch.code = 6005;
3247
- var ClawbackBeforeStart = class extends Error {
3248
- constructor(logs) {
3249
- super("6006: Attempted clawback before start");
3250
- this.logs = logs;
3251
- this.code = 6006;
3252
- this.name = "ClawbackBeforeStart";
3253
- this.msg = "Attempted clawback before start";
3254
- }
3255
- };
3256
- ClawbackBeforeStart.code = 6006;
3257
- var ClawbackAlreadyClaimed = class extends Error {
3258
- constructor(logs) {
3259
- super("6007: Clawback already claimed");
3260
- this.logs = logs;
3261
- this.code = 6007;
3262
- this.name = "ClawbackAlreadyClaimed";
3263
- this.msg = "Clawback already claimed";
3264
- }
3265
- };
3266
- ClawbackAlreadyClaimed.code = 6007;
3267
- var SameClawbackReceiver = class extends Error {
3268
- constructor(logs) {
3269
- super("6008: New and old Clawback receivers are identical");
3270
- this.logs = logs;
3271
- this.code = 6008;
3272
- this.name = "SameClawbackReceiver";
3273
- this.msg = "New and old Clawback receivers are identical";
3274
- }
3275
- };
3276
- SameClawbackReceiver.code = 6008;
3277
- var ClawbackReceiverIsTokenVault = class extends Error {
3278
- constructor(logs) {
3279
- super("6009: Clawback receiver can not be the Token Vault");
3280
- this.logs = logs;
3281
- this.code = 6009;
3282
- this.name = "ClawbackReceiverIsTokenVault";
3283
- this.msg = "Clawback receiver can not be the Token Vault";
3284
- }
3285
- };
3286
- ClawbackReceiverIsTokenVault.code = 6009;
3287
- var SameAdmin = class extends Error {
3288
- constructor(logs) {
3289
- super("6010: New and old admin are identical");
3290
- this.logs = logs;
3291
- this.code = 6010;
3292
- this.name = "SameAdmin";
3293
- this.msg = "New and old admin are identical";
3294
- }
3295
- };
3296
- SameAdmin.code = 6010;
3297
- var ClaimExpired = class extends Error {
3298
- constructor(logs) {
3299
- super("6011: Claim window expired");
3300
- this.logs = logs;
3301
- this.code = 6011;
3302
- this.name = "ClaimExpired";
3303
- this.msg = "Claim window expired";
3304
- }
3305
- };
3306
- ClaimExpired.code = 6011;
3307
- var ArithmeticError = class extends Error {
3308
- constructor(logs) {
3309
- super("6012: Arithmetic Error (overflow/underflow)");
3310
- this.logs = logs;
3311
- this.code = 6012;
3312
- this.name = "ArithmeticError";
3313
- this.msg = "Arithmetic Error (overflow/underflow)";
3314
- }
3315
- };
3316
- ArithmeticError.code = 6012;
3317
- var StartTimestampAfterEnd = class extends Error {
3318
- constructor(logs) {
3319
- super("6013: Start Timestamp cannot be after end Timestamp");
3320
- this.logs = logs;
3321
- this.code = 6013;
3322
- this.name = "StartTimestampAfterEnd";
3323
- this.msg = "Start Timestamp cannot be after end Timestamp";
3324
- }
3325
- };
3326
- StartTimestampAfterEnd.code = 6013;
3327
- var TimestampsNotInFuture = class extends Error {
3328
- constructor(logs) {
3329
- super("6014: Timestamps cannot be in the past");
3330
- this.logs = logs;
3331
- this.code = 6014;
3332
- this.name = "TimestampsNotInFuture";
3333
- this.msg = "Timestamps cannot be in the past";
3334
- }
3335
- };
3336
- TimestampsNotInFuture.code = 6014;
3337
- var InvalidMint = class extends Error {
3338
- constructor(logs) {
3339
- super("6015: Invalid Mint");
3340
- this.logs = logs;
3341
- this.code = 6015;
3342
- this.name = "InvalidMint";
3343
- this.msg = "Invalid Mint";
3344
- }
3345
- };
3346
- InvalidMint.code = 6015;
3347
- var ClaimIsClosed = class extends Error {
3348
- constructor(logs) {
3349
- super("6016: Claim is closed");
3350
- this.logs = logs;
3351
- this.code = 6016;
3352
- this.name = "ClaimIsClosed";
3353
- this.msg = "Claim is closed";
3354
- }
3355
- };
3356
- ClaimIsClosed.code = 6016;
3357
- var ClaimsAreNotClosable = class extends Error {
3358
- constructor(logs) {
3359
- super("6017: Claims are not closable");
3360
- this.logs = logs;
3361
- this.code = 6017;
3362
- this.name = "ClaimsAreNotClosable";
3363
- this.msg = "Claims are not closable";
3364
- }
3365
- };
3366
- ClaimsAreNotClosable.code = 6017;
3367
- var InvalidUnlockPeriod = class extends Error {
3368
- constructor(logs) {
3369
- super("6018: Invalid unlock period");
3370
- this.logs = logs;
3371
- this.code = 6018;
3372
- this.name = "InvalidUnlockPeriod";
3373
- this.msg = "Invalid unlock period";
3374
- }
3375
- };
3376
- InvalidUnlockPeriod.code = 6018;
3377
- var DurationUpdateNotAllowed = class extends Error {
3378
- constructor(logs) {
3379
- super("6019: Duration update is not allowed");
3380
- this.logs = logs;
3381
- this.code = 6019;
3382
- this.name = "DurationUpdateNotAllowed";
3383
- this.msg = "Duration update is not allowed";
3384
- }
3385
- };
3386
- DurationUpdateNotAllowed.code = 6019;
3387
- var NoVestingAmount = class extends Error {
3388
- constructor(logs) {
3389
- super("6020: Vesting amounts are not set");
3390
- this.logs = logs;
3391
- this.code = 6020;
3392
- this.name = "NoVestingAmount";
3393
- this.msg = "Vesting amounts are not set";
3394
- }
3395
- };
3396
- NoVestingAmount.code = 6020;
3397
- var VestingAlreadyFinished = class extends Error {
3398
- constructor(logs) {
3399
- super("6021: Vesting already finished");
3400
- this.logs = logs;
3401
- this.code = 6021;
3402
- this.name = "VestingAlreadyFinished";
3403
- this.msg = "Vesting already finished";
3404
- }
3405
- };
3406
- VestingAlreadyFinished.code = 6021;
3407
- var InvalidAmounts = class extends Error {
3408
- constructor(logs) {
3409
- super("6022: Provided amounts are invalid");
3410
- this.logs = logs;
3411
- this.code = 6022;
3412
- this.name = "InvalidAmounts";
3413
- this.msg = "Provided amounts are invalid";
3414
- }
3415
- };
3416
- InvalidAmounts.code = 6022;
3417
- var ClaimsLimitReached = class extends Error {
3418
- constructor(logs) {
3419
- super("6023: Claims limit has been reached");
3420
- this.logs = logs;
3421
- this.code = 6023;
3422
- this.name = "ClaimsLimitReached";
3423
- this.msg = "Claims limit has been reached";
3424
- }
3425
- };
3426
- ClaimsLimitReached.code = 6023;
3427
- function fromCode2(code, logs) {
3428
- switch (code) {
3429
- case 6e3:
3430
- return new InsufficientUnlockedTokens(logs);
3431
- case 6001:
3432
- return new InvalidProof(logs);
3433
- case 6002:
3434
- return new ExceededMaxClaim(logs);
3435
- case 6003:
3436
- return new MaxNodesExceeded(logs);
3437
- case 6004:
3438
- return new Unauthorized(logs);
3439
- case 6005:
3440
- return new OwnerMismatch(logs);
3441
- case 6006:
3442
- return new ClawbackBeforeStart(logs);
3443
- case 6007:
3444
- return new ClawbackAlreadyClaimed(logs);
3445
- case 6008:
3446
- return new SameClawbackReceiver(logs);
3447
- case 6009:
3448
- return new ClawbackReceiverIsTokenVault(logs);
3449
- case 6010:
3450
- return new SameAdmin(logs);
3451
- case 6011:
3452
- return new ClaimExpired(logs);
3453
- case 6012:
3454
- return new ArithmeticError(logs);
3455
- case 6013:
3456
- return new StartTimestampAfterEnd(logs);
3457
- case 6014:
3458
- return new TimestampsNotInFuture(logs);
3459
- case 6015:
3460
- return new InvalidMint(logs);
3461
- case 6016:
3462
- return new ClaimIsClosed(logs);
3463
- case 6017:
3464
- return new ClaimsAreNotClosable(logs);
3465
- case 6018:
3466
- return new InvalidUnlockPeriod(logs);
3467
- case 6019:
3468
- return new DurationUpdateNotAllowed(logs);
3469
- case 6020:
3470
- return new NoVestingAmount(logs);
3471
- case 6021:
3472
- return new VestingAlreadyFinished(logs);
3473
- case 6022:
3474
- return new InvalidAmounts(logs);
3475
- case 6023:
3476
- return new ClaimsLimitReached(logs);
3477
- }
3478
- return null;
3479
- }
3480
-
3481
- // solana/generated/errors/index.ts
3482
- function fromCode3(code, logs) {
3483
- return code >= 6e3 ? fromCode2(code, logs) : fromCode(code, logs);
3484
- }
3485
- function hasOwnProperty(obj, prop) {
3486
- return Object.hasOwnProperty.call(obj, prop);
3487
- }
3488
- var errorRe = /Program (\w+) failed: custom program error: (\w+)/;
3489
- function fromTxError(err, programId = PROGRAM_ID) {
3490
- if (typeof err !== "object" || err === null || !hasOwnProperty(err, "logs") || !Array.isArray(err.logs)) {
3491
- return null;
3492
- }
3493
- let firstMatch = null;
3494
- for (const logLine of err.logs) {
3495
- firstMatch = errorRe.exec(logLine);
3496
- if (firstMatch !== null) {
3497
- break;
3498
- }
3499
- }
3500
- if (firstMatch === null) {
3501
- return null;
3502
- }
3503
- const [programIdRaw, codeRaw] = firstMatch.slice(1);
3504
- if (programIdRaw !== programId.toString()) {
3505
- return null;
3506
- }
3507
- let errorCode;
3508
- try {
3509
- errorCode = parseInt(codeRaw, 16);
3510
- } catch (parseErr) {
3511
- return null;
3512
- }
3513
- return fromCode3(errorCode, err.logs);
3514
- }
3515
-
3516
- // solana/utils.ts
3517
- var getAlignedDistributorPda = (programId, distributor) => {
3518
- return PublicKey.findProgramAddressSync([ALIGNED_DISTRIBUTOR_PREFIX, distributor.toBuffer()], programId)[0];
3519
- };
3520
- var getTestOraclePda = (programId, mint, creator) => {
3521
- return PublicKey.findProgramAddressSync([TEST_ORACLE_PREFIX, mint.toBuffer(), creator.toBuffer()], programId)[0];
3522
- };
3523
- function getDistributorPda(programId, mint, version) {
3524
- const seeds = [
3525
- DISTRIBUTOR_PREFIX,
3526
- mint.toBuffer(),
3527
- Buffer$1.from(new Uint8Array(new BigUint64Array([BigInt(version)]).buffer))
3528
- ];
3529
- return PublicKey.findProgramAddressSync(seeds, programId)[0];
3530
- }
3531
- function getClaimantStatusPda(programId, distributor, claimant) {
3532
- const seeds = [CLAIM_STATUS_PREFIX, claimant.toBuffer(), distributor.toBuffer()];
3533
- return PublicKey.findProgramAddressSync(seeds, programId)[0];
3534
- }
3535
- function getEventAuthorityPda(programId) {
3536
- const seeds = [Buffer$1.from("__event_authority")];
3537
- return PublicKey.findProgramAddressSync(seeds, programId)[0];
3538
- }
3539
- var isCompressedClaimStatus = (status) => {
3540
- return !!status && "state" in status;
3541
- };
3542
- async function wrappedSignAndExecuteTransaction(...args) {
3543
- try {
3544
- return await signAndExecuteTransaction(...args);
3545
- } catch (err) {
3546
- if (err instanceof Error) {
3547
- const parsed = fromTxError(err);
3548
- if (parsed) {
3549
- throw new ContractError(err, parsed.name, parsed.msg);
3550
- }
3551
- }
3552
- throw err;
3553
- }
3554
- }
3555
- async function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
3556
- const epoch = await connection.getEpochInfo();
3557
- const transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch ? transferFeeConfig.newerTransferFee : transferFeeConfig.olderTransferFee;
3558
- const transferFeeBasisPoints = BigInt(transferFee.transferFeeBasisPoints);
3559
- let feeCharged = BigInt(0);
3560
- if (transferFeeBasisPoints !== BigInt(0)) {
3561
- const numerator = transferAmount * ONE_IN_BASIS_POINTS;
3562
- const denominator = ONE_IN_BASIS_POINTS - transferFeeBasisPoints;
3563
- const rawPreFeeAmount = divCeilN(numerator, denominator);
3564
- const fee = rawPreFeeAmount - transferAmount;
3565
- transferAmount = rawPreFeeAmount;
3566
- feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
3567
- }
3568
- return { transferAmount, feeCharged };
3569
- }
3570
-
3571
- // solana/clients/BaseDistributorClient.ts
3572
- var BaseDistributorClient = class {
3573
- constructor({
3574
- clusterUrl,
3575
- cluster = ICluster.Mainnet,
3576
- commitment = "confirmed",
3577
- programId = "",
3578
- sendRate = 1,
3579
- sendThrottler,
3580
- apiUrl,
3581
- apiKey
3582
- }) {
3583
- this.commitment = commitment;
3584
- this.cluster = cluster;
3585
- this.connection = new Connection(clusterUrl, this.commitment);
3586
- this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(DISTRIBUTOR_PROGRAM_ID[cluster]);
3587
- this.sendThrottler = sendThrottler ?? buildSendThrottler(sendRate);
3588
- const merkleDistributorProgram = {
3589
- ...merkle_distributor_default
3590
- };
3591
- this.merkleDistributorProgram = new Program(merkleDistributorProgram, { connection: this.connection });
3592
- this.apiUrl = apiUrl;
3593
- this.apiKey = apiKey;
3594
- }
3595
- getConnection() {
3596
- return this.connection;
3597
- }
3598
- getCommitment() {
3599
- return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
3600
- }
3601
- getDistributorProgramId() {
3602
- return this.programId;
3603
- }
3604
- async prepareCreateInstructions(data, extParams) {
3605
- if (!extParams.invoker.publicKey) {
3606
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
3607
- }
3608
- const { version, mint } = data;
3609
- const ixs = prepareBaseInstructions(this.connection, extParams);
3610
- const mintPublicKey = extParams.isNative ? NATIVE_MINT : new PublicKey(mint);
3611
- const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
3612
- const transferFeeConfig = getTransferFeeConfig(mintAccount);
3613
- const distributorPublicKey = getDistributorPda(this.programId, mintPublicKey, version);
3614
- const tokenVault = await ata(mintPublicKey, distributorPublicKey, tokenProgramId);
3615
- const senderTokens = await ata(mintPublicKey, extParams.invoker.publicKey, tokenProgramId);
3616
- const accounts = {
3617
- distributor: distributorPublicKey,
3618
- clawbackReceiver: senderTokens,
3619
- mint: mintPublicKey,
3620
- tokenVault,
3621
- admin: extParams.invoker.publicKey,
3622
- systemProgram: SystemProgram.programId,
3623
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
3624
- tokenProgram: tokenProgramId
3625
- };
3626
- if (extParams.isNative) {
3627
- ixs.push(
3628
- ...await prepareWrappedAccount(this.connection, extParams.invoker.publicKey, new BN5(data.maxTotalClaim))
3629
- );
3630
- }
3631
- const newDistributorInstruction = await this.getNewDistributorInstruction(data, accounts);
3632
- ixs.push(newDistributorInstruction);
3633
- if (transferFeeConfig) {
3634
- const { transferAmount, feeCharged } = await calculateAmountWithTransferFees(
3635
- this.connection,
3636
- transferFeeConfig,
3637
- BigInt(data.maxTotalClaim.toString())
3638
- );
3639
- ixs.push(
3640
- createTransferCheckedWithFeeInstruction(
3641
- senderTokens,
3642
- mintPublicKey,
3643
- tokenVault,
3644
- extParams.invoker.publicKey,
3645
- transferAmount,
3646
- mintAccount.decimals,
3647
- feeCharged,
3648
- void 0,
3649
- tokenProgramId
3650
- )
3651
- );
3652
- } else {
3653
- ixs.push(
3654
- createTransferCheckedInstruction(
3655
- senderTokens,
3656
- mintPublicKey,
3657
- tokenVault,
3658
- extParams.invoker.publicKey,
3659
- BigInt(data.maxTotalClaim.toString()),
3660
- mintAccount.decimals,
3661
- void 0,
3662
- tokenProgramId
3663
- )
3664
- );
3665
- }
3666
- return { distributorPublicKey, ixs };
3667
- }
3668
- async create(data, extParams) {
3669
- const invoker = extParams.invoker.publicKey;
3670
- invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3671
- const executionParams = this.unwrapExecutionParams(extParams);
3672
- const { ixs, distributorPublicKey } = await createAndEstimateTransaction(
3673
- (params) => this.prepareCreateInstructions(data, params),
3674
- executionParams,
3675
- (q) => q.ixs
3676
- );
3677
- const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
3678
- const signature = await wrappedSignAndExecuteTransaction(
3679
- this.connection,
3680
- extParams.invoker,
3681
- tx,
3682
- {
3683
- hash,
3684
- context,
3685
- commitment: this.getCommitment()
3686
- },
3687
- { sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation }
3688
- );
3689
- return {
3690
- ixs,
3691
- txId: signature,
3692
- metadataId: distributorPublicKey.toBase58()
3693
- };
3694
- }
3695
- async claim(data, extParams, _serviceTransfer) {
3696
- const executionParams = this.unwrapExecutionParams(extParams);
3697
- const invoker = executionParams.invoker.publicKey;
3698
- invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3699
- const ixs = await createAndEstimateTransaction(
3700
- (params) => this.prepareClaimInstructions(data, params, _serviceTransfer),
3701
- executionParams
3702
- );
3703
- const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker);
3704
- const signature = await wrappedSignAndExecuteTransaction(
3705
- this.connection,
3706
- executionParams.invoker,
3707
- tx,
3708
- {
3709
- hash,
3710
- context,
3711
- commitment: this.getCommitment()
3712
- },
3713
- { sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation }
3714
- );
3715
- return { ixs, txId: signature };
3716
- }
3717
- async prepareClaimInstructions(data, extParams, _serviceTransfer) {
3718
- if (!extParams.invoker.publicKey) {
3719
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
3720
- }
3721
- const distributorPublicKey = new PublicKey(data.id);
3722
- const distributor = await MerkleDistributor.fetch(this.connection, distributorPublicKey);
3723
- if (!distributor) {
3724
- throw new Error("Couldn't get account info");
3725
- }
3726
- const { tokenProgramId } = await getMintAndProgram(this.connection, distributor.mint);
3727
- const ixs = prepareBaseInstructions(this.connection, extParams);
3728
- ixs.push(
3729
- ...await checkOrCreateAtaBatch(
3730
- this.connection,
3731
- [extParams.invoker.publicKey],
3732
- distributor.mint,
3733
- extParams.invoker,
3734
- tokenProgramId,
3735
- extParams.feePayer
3736
- )
3737
- );
3738
- const invokerTokens = await ata(distributor.mint, extParams.invoker.publicKey, tokenProgramId);
3739
- const claimStatusPublicKey = getClaimantStatusPda(
3740
- this.programId,
3741
- distributorPublicKey,
3742
- extParams.invoker.publicKey
3743
- );
3744
- const eventAuthorityPublicKey = getEventAuthorityPda(this.programId);
3745
- const claimStatus = await this.getClaim(claimStatusPublicKey);
3746
- const accounts = {
3747
- distributor: distributorPublicKey,
3748
- claimStatus: claimStatusPublicKey,
3749
- from: distributor.tokenVault,
3750
- to: invokerTokens,
3751
- claimant: extParams.invoker.publicKey,
3752
- mint: distributor.mint,
3753
- tokenProgram: tokenProgramId,
3754
- systemProgram: SystemProgram.programId,
3755
- eventAuthority: eventAuthorityPublicKey,
3756
- program: this.programId
3757
- };
3758
- if (!claimStatus) {
3759
- const args = {
3760
- amountLocked: new BN5(data.amountLocked),
3761
- amountUnlocked: new BN5(data.amountUnlocked),
3762
- proof: data.proof
3763
- };
3764
- ixs.push(newClaim(args, accounts, this.programId));
3765
- }
3766
- const nowTs = new BN5(Math.floor(Date.now() / 1e3));
3767
- if (claimStatus || new BN5(data.amountLocked).gtn(0) && nowTs.sub(distributor.startTs).gte(distributor.unlockPeriod)) {
3768
- ixs.push(claimLocked(accounts, this.programId));
3769
- }
3770
- let feeLamports = typeof _serviceTransfer === "bigint" ? _serviceTransfer : void 0;
3771
- if (!feeLamports) {
3772
- try {
3773
- const { mint: mintAccount } = await getMintAndProgram(this.connection, distributor.mint);
3774
- const claimableAmountRaw = data?.claimableAmount;
3775
- const unlockedRaw = data?.amountUnlocked;
3776
- const lockedRaw = data?.amountLocked;
3777
- const unlocked = unlockedRaw != null ? new BN5(unlockedRaw) : new BN5(0);
3778
- const locked = lockedRaw != null ? new BN5(lockedRaw) : new BN5(0);
3779
- const computedFallback = unlocked.add(locked);
3780
- const claimableAmount = claimableAmountRaw != null ? BigInt(claimableAmountRaw.toString()) : BigInt(computedFallback.toString());
3781
- feeLamports = await resolveAirdropFeeLamportsUsingApi({
3782
- distributorAddress: distributorPublicKey.toBase58(),
3783
- mintAccount,
3784
- claimableAmount,
3785
- cluster: this.cluster,
3786
- apiUrl: this.apiUrl,
3787
- apiKey: this.apiKey
3788
- });
3789
- } catch (_) {
3790
- feeLamports = MINIMUM_FEE_FALLBACK;
3791
- }
3792
- }
3793
- ixs.push(this.prepareClaimFeeInstruction(extParams.feePayer ?? extParams.invoker.publicKey, feeLamports));
3794
- return ixs;
3795
- }
3796
- async closeClaim(data, extParams) {
3797
- const executionParams = this.unwrapExecutionParams(extParams);
3798
- const invoker = executionParams.invoker.publicKey;
3799
- invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3800
- const ixs = await createAndEstimateTransaction(
3801
- (params) => this.prepareCloseClaimInstructions(data, params),
3802
- executionParams
3803
- );
3804
- const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker);
3805
- const signature = await wrappedSignAndExecuteTransaction(
3806
- this.connection,
3807
- executionParams.invoker,
3808
- tx,
3809
- {
3810
- hash,
3811
- context,
3812
- commitment: this.getCommitment()
3813
- },
3814
- { sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation }
3815
- );
3816
- return { ixs, txId: signature };
3817
- }
3818
- async prepareCloseClaimInstructions(data, extParams) {
3819
- if (!extParams.invoker.publicKey) {
3820
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
3821
- }
3822
- const distributorPublicKey = new PublicKey(data.id);
3823
- const distributor = await MerkleDistributor.fetch(this.connection, distributorPublicKey);
3824
- const claimantPublicKey = pk(data.claimant);
3825
- if (!distributor) {
3826
- throw new Error("Couldn't get distributor account info");
3827
- }
3828
- const ixs = prepareBaseInstructions(this.connection, extParams);
3829
- const claimStatusPublicKey = getClaimantStatusPda(this.programId, distributorPublicKey, claimantPublicKey);
3830
- const eventAuthorityPublicKey = getEventAuthorityPda(this.programId);
3831
- const closeClaimAccounts = {
3832
- adminOrClaimant: extParams.invoker.publicKey,
3833
- payer: extParams.invoker.publicKey,
3834
- distributor: distributorPublicKey,
3835
- claimStatus: claimStatusPublicKey,
3836
- claimant: claimantPublicKey,
3837
- systemProgram: SystemProgram.programId,
3838
- eventAuthority: eventAuthorityPublicKey,
3839
- program: this.programId
3840
- };
3841
- const closeClaimArgs = {
3842
- amountLocked: data.amountLocked ? new BN5(data.amountLocked) : void 0,
3843
- amountUnlocked: data.amountUnlocked ? new BN5(data.amountUnlocked) : void 0,
3844
- proof: data.proof
3845
- };
3846
- ixs.push(closeClaim(closeClaimArgs, closeClaimAccounts, this.programId));
3847
- return ixs;
3848
- }
3849
- async prepareClawbackInstructions(data, extParams) {
3850
- if (!extParams.invoker.publicKey) {
3851
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
3852
- }
3853
- const distributorPublicKey = new PublicKey(data.id);
3854
- const distributor = await MerkleDistributor.fetch(this.connection, distributorPublicKey);
3855
- if (!distributor) {
3856
- throw new Error("Couldn't get account info");
3857
- }
3858
- const { tokenProgramId } = await getMintAndProgram(this.connection, distributor.mint);
3859
- const ixs = prepareBaseInstructions(this.connection, extParams);
3860
- ixs.push(
3861
- ...await checkOrCreateAtaBatch(
3862
- this.connection,
3863
- [extParams.invoker.publicKey],
3864
- distributor.mint,
3865
- extParams.invoker,
3866
- tokenProgramId,
3867
- extParams.feePayer
3868
- )
3869
- );
3870
- const accounts = {
3871
- distributor: distributorPublicKey,
3872
- from: distributor.tokenVault,
3873
- to: distributor.clawbackReceiver,
3874
- admin: extParams.invoker.publicKey,
3875
- mint: distributor.mint,
3876
- systemProgram: SystemProgram.programId,
3877
- tokenProgram: tokenProgramId
3878
- };
3879
- const clawbackInstruction = await this.getClawbackInstruction(accounts);
3880
- ixs.push(clawbackInstruction);
3881
- return ixs;
3882
- }
3883
- async clawback(data, extParams) {
3884
- const executionParams = this.unwrapExecutionParams(extParams);
3885
- const invoker = executionParams.invoker.publicKey;
3886
- invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3887
- const ixs = await createAndEstimateTransaction(
3888
- (params) => this.prepareClawbackInstructions(data, params),
3889
- executionParams
3890
- );
3891
- const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker);
3892
- const signature = await wrappedSignAndExecuteTransaction(
3893
- this.connection,
3894
- executionParams.invoker,
3895
- tx,
3896
- {
3897
- hash,
3898
- context,
3899
- commitment: this.getCommitment()
3900
- },
3901
- { sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation }
3902
- );
3903
- return { ixs, txId: signature };
3904
- }
3905
- async getClaim(claimStatus) {
3906
- return this.connection.getAccountInfo(pk(claimStatus)).then((account) => this.decodeClaimStatus(account));
3907
- }
3908
- async getClaims(data) {
3909
- const claimStatusPublicKeys = data.map(({ id, recipient }) => {
3910
- return getClaimantStatusPda(this.programId, new PublicKey(id), new PublicKey(recipient));
3911
- });
3912
- return this.connection.getMultipleAccountsInfo(claimStatusPublicKeys).then((accounts) => {
3913
- return accounts.map((account) => this.decodeClaimStatus(account));
3914
- });
3915
- }
3916
- async getDistributors(data) {
3917
- const distributorPublicKeys = data.ids.map((distributorId) => new PublicKey(distributorId));
3918
- return MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
3919
- }
3920
- async searchDistributors(data) {
3921
- const filters = [{ memcmp: { offset: 0, bytes: bs58.encode(MerkleDistributor.discriminator) } }];
3922
- if (data.mint) {
3923
- filters.push({
3924
- memcmp: {
3925
- offset: DISTRIBUTOR_MINT_OFFSET,
3926
- bytes: data.mint
3927
- }
3928
- });
3929
- }
3930
- if (data.admin) {
3931
- filters.push({
3932
- memcmp: {
3933
- offset: DISTRIBUTOR_ADMIN_OFFSET,
3934
- bytes: data.admin
3935
- }
3936
- });
3937
- }
3938
- const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
3939
- return accounts.map(({ pubkey, account }) => ({
3940
- publicKey: pubkey,
3941
- account: MerkleDistributor.decode(account.data)
3942
- }));
3943
- }
3944
- prepareClaimFeeInstruction(payer, fee = AIRDROP_CLAIM_FEE) {
3945
- return SystemProgram.transfer({
3946
- fromPubkey: payer,
3947
- toPubkey: STREAMFLOW_TREASURY_PUBLIC_KEY,
3948
- lamports: fee
3949
- });
3950
- }
3951
- getNewDistributorArgs(data) {
3952
- const args = {
3953
- version: new BN5(data.version),
3954
- root: data.root,
3955
- maxTotalClaim: new BN5(data.maxTotalClaim),
3956
- maxNumNodes: new BN5(data.maxNumNodes),
3957
- unlockPeriod: new BN5(data.unlockPeriod),
3958
- startVestingTs: new BN5(data.startVestingTs),
3959
- endVestingTs: new BN5(data.endVestingTs),
3960
- clawbackStartTs: new BN5(data.clawbackStartTs),
3961
- claimsClosableByAdmin: data.claimsClosableByAdmin,
3962
- claimsClosableByClaimant: data.claimsClosableByClaimant,
3963
- claimsLimit: data.claimsLimit
3964
- };
3965
- const nowTs = new BN5(Math.floor(Date.now() / 1e3));
3966
- const endVestingTs = args.endVestingTs.isZero() ? nowTs : args.endVestingTs;
3967
- const startVestingTs = args.startVestingTs.isZero() ? nowTs : args.startVestingTs;
3968
- if (endVestingTs.gt(startVestingTs) && endVestingTs.sub(startVestingTs).lt(args.unlockPeriod)) {
3969
- throw new Error("The unlock period cannot be longer than the total vesting duration!");
3970
- }
3971
- return args;
3972
- }
3973
- unwrapExecutionParams(extParams) {
3974
- return unwrapExecutionParams(extParams, this.connection);
3975
- }
3976
- decodeClaimStatus(account) {
3977
- if (!account) {
3978
- return null;
3979
- }
3980
- try {
3981
- return decode(this.merkleDistributorProgram, "claimStatus", account.data);
3982
- } catch (baseClaimStatusError) {
3983
- try {
3984
- return decode(this.merkleDistributorProgram, "compressedClaimStatus", account.data);
3985
- } catch (compressedClaimStatusError) {
3986
- throw new Error("Couldn't decode claim status");
3987
- }
3988
- }
3989
- }
3990
- };
3991
- function decode(program, accountName, accInfo, programKey) {
3992
- const programId = program.programId?.toBase58() ?? "N/A";
3993
- invariant(program, `Decoding program with key ${programId} is not available`);
3994
- const accountEntity = program.idl.accounts?.find((acc) => acc.name === accountName);
3995
- invariant(
3996
- !!accountEntity,
3997
- `Decoding program with key ${programId} doesn't specify account with name ${String(accountName)}`
3998
- );
3999
- return program.coder.accounts.decode(accountName, accInfo);
4000
- }
4001
-
4002
- // solana/clients/SolanaDistributorClient.ts
4003
- var SolanaDistributorClient = class extends BaseDistributorClient {
4004
- async getNewDistributorInstruction(data, accounts) {
4005
- const args = this.getNewDistributorArgs(data);
4006
- return newDistributor(args, accounts, this.programId);
4007
- }
4008
- async getClawbackInstruction(accounts) {
4009
- return clawback(accounts, this.programId);
4010
- }
4011
- };
4012
2443
 
4013
2444
  // solana/descriptor/idl/aligned_distributor.json
4014
2445
  var aligned_distributor_default = {
4015
2446
  address: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
4016
2447
  metadata: {
4017
2448
  name: "aligned_distributor",
4018
- version: "1.5.1",
2449
+ version: "2.0.0",
4019
2450
  spec: "0.1.0",
4020
2451
  description: "Proxy for merkle distributor that updates Vesting duration according to token market performance."
4021
2452
  },
@@ -4063,6 +2494,34 @@ var aligned_distributor_default = {
4063
2494
  }
4064
2495
  ]
4065
2496
  },
2497
+ {
2498
+ name: "claim_sol_fees",
2499
+ discriminator: [
2500
+ 127,
2501
+ 0,
2502
+ 119,
2503
+ 89,
2504
+ 193,
2505
+ 27,
2506
+ 209,
2507
+ 142
2508
+ ],
2509
+ accounts: [
2510
+ {
2511
+ name: "aligned_distributor",
2512
+ docs: [
2513
+ "The [MerkleDistributor]."
2514
+ ],
2515
+ writable: true
2516
+ },
2517
+ {
2518
+ name: "treasury",
2519
+ writable: true,
2520
+ address: "5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw"
2521
+ }
2522
+ ],
2523
+ args: []
2524
+ },
4066
2525
  {
4067
2526
  name: "clawback",
4068
2527
  discriminator: [
@@ -4566,6 +3025,76 @@ var aligned_distributor_default = {
4566
3025
  docs: [
4567
3026
  "The [Token] program."
4568
3027
  ]
3028
+ },
3029
+ {
3030
+ name: "partner_oracle_config",
3031
+ pda: {
3032
+ seeds: [
3033
+ {
3034
+ kind: "const",
3035
+ value: [
3036
+ 97,
3037
+ 105,
3038
+ 114,
3039
+ 100,
3040
+ 114,
3041
+ 111,
3042
+ 112,
3043
+ 95,
3044
+ 99,
3045
+ 111,
3046
+ 110,
3047
+ 102,
3048
+ 105,
3049
+ 103
3050
+ ]
3051
+ }
3052
+ ],
3053
+ program: {
3054
+ kind: "const",
3055
+ value: [
3056
+ 12,
3057
+ 48,
3058
+ 148,
3059
+ 48,
3060
+ 221,
3061
+ 89,
3062
+ 2,
3063
+ 209,
3064
+ 180,
3065
+ 126,
3066
+ 151,
3067
+ 216,
3068
+ 166,
3069
+ 3,
3070
+ 112,
3071
+ 50,
3072
+ 177,
3073
+ 192,
3074
+ 141,
3075
+ 218,
3076
+ 37,
3077
+ 78,
3078
+ 51,
3079
+ 109,
3080
+ 243,
3081
+ 106,
3082
+ 174,
3083
+ 122,
3084
+ 93,
3085
+ 121,
3086
+ 191,
3087
+ 119
3088
+ ]
3089
+ }
3090
+ }
3091
+ },
3092
+ {
3093
+ name: "partner_oracle",
3094
+ docs: [
3095
+ "Partner Oracle program that stores fees"
3096
+ ],
3097
+ address: "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa"
4569
3098
  }
4570
3099
  ],
4571
3100
  args: [
@@ -4941,6 +3470,11 @@ var aligned_distributor_default = {
4941
3470
  code: 6013,
4942
3471
  name: "InvalidMint",
4943
3472
  msg: "Invalid Mint"
3473
+ },
3474
+ {
3475
+ code: 6014,
3476
+ name: "NoFeesToClaim",
3477
+ msg: "No fees to claim"
4944
3478
  }
4945
3479
  ],
4946
3480
  types: [
@@ -5089,6 +3623,20 @@ var aligned_distributor_default = {
5089
3623
  ],
5090
3624
  type: "pubkey"
5091
3625
  },
3626
+ {
3627
+ name: "price_oracle_fee",
3628
+ docs: [
3629
+ "Fee for custom price oracle used in dynamic airdrops"
3630
+ ],
3631
+ type: "u32"
3632
+ },
3633
+ {
3634
+ name: "price_oracle_fee_claimed",
3635
+ docs: [
3636
+ "Whether fee for the price oracle has been claimed"
3637
+ ],
3638
+ type: "bool"
3639
+ },
5092
3640
  {
5093
3641
  name: "buffer_2",
5094
3642
  docs: [
@@ -5097,7 +3645,7 @@ var aligned_distributor_default = {
5097
3645
  type: {
5098
3646
  array: [
5099
3647
  "u8",
5100
- 32
3648
+ 27
5101
3649
  ]
5102
3650
  }
5103
3651
  },
@@ -5284,87 +3832,145 @@ var aligned_distributor_default = {
5284
3832
  {
5285
3833
  name: "claims_closable_by_admin",
5286
3834
  docs: [
5287
- "Whether claims are closable by the admin or not"
3835
+ "Whether claims are closable by the admin or not"
3836
+ ],
3837
+ type: "bool"
3838
+ },
3839
+ {
3840
+ name: "can_update_duration",
3841
+ docs: [
3842
+ "Whether admin can update vesting duration"
3843
+ ],
3844
+ type: "bool"
3845
+ },
3846
+ {
3847
+ name: "total_amount_unlocked",
3848
+ docs: [
3849
+ "Total amount of funds unlocked (cliff/instant)"
3850
+ ],
3851
+ type: "u64"
3852
+ },
3853
+ {
3854
+ name: "total_amount_locked",
3855
+ docs: [
3856
+ "Total amount of funds locked (vested)"
3857
+ ],
3858
+ type: "u64"
3859
+ },
3860
+ {
3861
+ name: "last_duration_update_ts",
3862
+ docs: [
3863
+ "Timestamp when update was last called"
3864
+ ],
3865
+ type: "u64"
3866
+ },
3867
+ {
3868
+ name: "total_claimable_pre_update",
3869
+ docs: [
3870
+ "Total amount of locked amount claimable as of last duration update, ever increasing total, accumulates with each update"
3871
+ ],
3872
+ type: "u64"
3873
+ },
3874
+ {
3875
+ name: "clawed_back_ts",
3876
+ docs: [
3877
+ "Timestamp when funds were clawed back"
3878
+ ],
3879
+ type: "u64"
3880
+ },
3881
+ {
3882
+ name: "claims_closable_by_claimant",
3883
+ docs: [
3884
+ "Whether claims are closable by claimant or not"
3885
+ ],
3886
+ type: "bool"
3887
+ },
3888
+ {
3889
+ name: "claims_limit",
3890
+ docs: [
3891
+ "Limit number of claims"
3892
+ ],
3893
+ type: "u16"
3894
+ },
3895
+ {
3896
+ name: "creation_fee",
3897
+ docs: [
3898
+ "Creation SOL fee"
5288
3899
  ],
5289
- type: "bool"
3900
+ type: "u32"
5290
3901
  },
5291
3902
  {
5292
- name: "can_update_duration",
3903
+ name: "creation_fee_claimed",
5293
3904
  docs: [
5294
- "Whether admin can update vesting duration"
3905
+ "Whether creation SOL was claimed"
5295
3906
  ],
5296
3907
  type: "bool"
5297
3908
  },
5298
3909
  {
5299
- name: "total_amount_unlocked",
3910
+ name: "claim_min_fee",
5300
3911
  docs: [
5301
- "Total amount of funds unlocked (cliff/instant)"
3912
+ "Dynamic claim fee in SOL, min"
5302
3913
  ],
5303
- type: "u64"
3914
+ type: "u32"
5304
3915
  },
5305
3916
  {
5306
- name: "total_amount_locked",
3917
+ name: "claim_max_fee",
5307
3918
  docs: [
5308
- "Total amount of funds locked (vested)"
3919
+ "Dynamic claim fee in SOL, max"
5309
3920
  ],
5310
- type: "u64"
3921
+ type: "u32"
5311
3922
  },
5312
3923
  {
5313
- name: "last_duration_update_ts",
3924
+ name: "allocation_factor",
5314
3925
  docs: [
5315
- "Timestamp when update was last called"
3926
+ "Factor to multiply claimable SOL lamports by when calculating fee"
5316
3927
  ],
5317
- type: "u64"
3928
+ type: "f64"
5318
3929
  },
5319
3930
  {
5320
- name: "total_claimable_pre_update",
3931
+ name: "claim_fee_claimed",
5321
3932
  docs: [
5322
- "Total amount of locked amount claimable as of last duration update, ever increasing total, accumulates with each update"
3933
+ "Whether all claim fees were claimed, true by default since no claim fee is taken on creation"
5323
3934
  ],
5324
- type: "u64"
3935
+ type: "bool"
5325
3936
  },
5326
3937
  {
5327
- name: "clawed_back_ts",
3938
+ name: "token_price_lamports",
5328
3939
  docs: [
5329
- "Timestamp when funds were clawed back"
3940
+ "Last observed token price in lamports per 1 whole token for claim fee calculation"
5330
3941
  ],
5331
3942
  type: "u64"
5332
3943
  },
5333
3944
  {
5334
- name: "claims_closable_by_claimant",
3945
+ name: "clawback_token_fee_percent",
5335
3946
  docs: [
5336
- "Whether claims are closable by claimant or not"
3947
+ "Token % fee on clawback"
5337
3948
  ],
5338
- type: "bool"
3949
+ type: "f64"
5339
3950
  },
5340
3951
  {
5341
- name: "claims_limit",
3952
+ name: "clawback_fee_claimed",
5342
3953
  docs: [
5343
- "Limit number of claims"
3954
+ "Whether clawback token % fee has been claimed"
5344
3955
  ],
5345
- type: "u16"
3956
+ type: "bool"
5346
3957
  },
5347
3958
  {
5348
- name: "buffer_2",
3959
+ name: "program_version",
5349
3960
  docs: [
5350
- "Buffer for additional fields"
3961
+ "Program version that initiated the Distributor account"
5351
3962
  ],
5352
- type: {
5353
- array: [
5354
- "u8",
5355
- 20
5356
- ]
5357
- }
3963
+ type: "u8"
5358
3964
  },
5359
3965
  {
5360
- name: "buffer_3",
3966
+ name: "buffer",
5361
3967
  docs: [
5362
3968
  "Buffer for additional fields"
5363
3969
  ],
5364
3970
  type: {
5365
3971
  array: [
5366
3972
  "u8",
5367
- 32
3973
+ 13
5368
3974
  ]
5369
3975
  }
5370
3976
  }
@@ -5483,73 +4089,805 @@ var aligned_distributor_default = {
5483
4089
  }
5484
4090
  ]
5485
4091
  }
5486
- },
5487
- {
5488
- name: "TestOracle",
5489
- type: {
5490
- kind: "struct",
5491
- fields: [
5492
- {
5493
- name: "price",
5494
- type: "u64"
5495
- },
5496
- {
5497
- name: "expo",
5498
- type: "i32"
5499
- },
5500
- {
5501
- name: "conf",
5502
- type: "u64"
5503
- },
5504
- {
5505
- name: "publish_time",
5506
- type: "i64"
5507
- },
5508
- {
5509
- name: "creator",
5510
- type: "pubkey"
5511
- },
5512
- {
5513
- name: "authority",
5514
- type: "pubkey"
5515
- },
5516
- {
5517
- name: "mint",
5518
- type: "pubkey"
5519
- }
5520
- ]
4092
+ },
4093
+ {
4094
+ name: "TestOracle",
4095
+ type: {
4096
+ kind: "struct",
4097
+ fields: [
4098
+ {
4099
+ name: "price",
4100
+ type: "u64"
4101
+ },
4102
+ {
4103
+ name: "expo",
4104
+ type: "i32"
4105
+ },
4106
+ {
4107
+ name: "conf",
4108
+ type: "u64"
4109
+ },
4110
+ {
4111
+ name: "publish_time",
4112
+ type: "i64"
4113
+ },
4114
+ {
4115
+ name: "creator",
4116
+ type: "pubkey"
4117
+ },
4118
+ {
4119
+ name: "authority",
4120
+ type: "pubkey"
4121
+ },
4122
+ {
4123
+ name: "mint",
4124
+ type: "pubkey"
4125
+ }
4126
+ ]
4127
+ }
4128
+ },
4129
+ {
4130
+ name: "UpdateTestOracleParams",
4131
+ type: {
4132
+ kind: "struct",
4133
+ fields: [
4134
+ {
4135
+ name: "price",
4136
+ type: "u64"
4137
+ },
4138
+ {
4139
+ name: "expo",
4140
+ type: "i32"
4141
+ },
4142
+ {
4143
+ name: "conf",
4144
+ type: "u64"
4145
+ },
4146
+ {
4147
+ name: "publish_time",
4148
+ type: "i64"
4149
+ }
4150
+ ]
4151
+ }
4152
+ }
4153
+ ]
4154
+ };
4155
+
4156
+ // solana/constants.ts
4157
+ var MERKLE_DISTRIBUTOR_ERRORS = parseIdlErrors(merkle_distributor_default);
4158
+ var ALIGNED_DISTRIBUTOR_ERRORS = parseIdlErrors(aligned_distributor_default);
4159
+ var ANCHOR_DISCRIMINATOR_OFFSET = 8;
4160
+ var DISTRIBUTOR_MINT_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 41;
4161
+ var DISTRIBUTOR_ADMIN_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 201;
4162
+ var DISTRIBUTOR_PREFIX = Buffer.from("MerkleDistributor", "utf-8");
4163
+ var ALIGNED_DISTRIBUTOR_PREFIX = Buffer.from("aligned-distributor", "utf-8");
4164
+ var TEST_ORACLE_PREFIX = Buffer.from("test-oracle", "utf-8");
4165
+ var CLAIM_STATUS_PREFIX = Buffer.from("ClaimStatus", "utf-8");
4166
+ var ALIGNED_PRECISION_FACTOR_POW = 9;
4167
+ var AIRDROP_CLAIM_FEE = BigInt(1e7);
4168
+ var STREAMFLOW_TREASURY_PUBLIC_KEY = new PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
4169
+ var ONE_IN_BASIS_POINTS = BigInt(1e4);
4170
+ var SOL_FEE_PROGRAM_VERSION = 1;
4171
+ var ALIGNED_DISTRIBUTOR_PROGRAM_ID = {
4172
+ [ICluster.Devnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
4173
+ [ICluster.Mainnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
4174
+ [ICluster.Testnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
4175
+ [ICluster.Local]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2"
4176
+ };
4177
+ var DISTRIBUTOR_PROGRAM_ID = {
4178
+ [ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
4179
+ [ICluster.Mainnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
4180
+ [ICluster.Testnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
4181
+ [ICluster.Local]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N"
4182
+ };
4183
+ var PARTNER_ORACLE_PROGRAM_ID = {
4184
+ [ICluster.Devnet]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3",
4185
+ [ICluster.Mainnet]: "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa",
4186
+ [ICluster.Testnet]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3",
4187
+ [ICluster.Local]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3"
4188
+ };
4189
+ var FEE_CONFIG_PUBLIC_KEY = {
4190
+ [ICluster.Devnet]: "5HCju3fLTQGNNPZyZwaWGQqRcTRKE1VEdr7HFZKc7NhB",
4191
+ [ICluster.Mainnet]: "5WHEQeA5uX7zJ8r7yAzsxomF7LTnX9acQy3V8oWXHa8b",
4192
+ [ICluster.Testnet]: "5HCju3fLTQGNNPZyZwaWGQqRcTRKE1VEdr7HFZKc7NhB",
4193
+ [ICluster.Local]: "5HCju3fLTQGNNPZyZwaWGQqRcTRKE1VEdr7HFZKc7NhB"
4194
+ };
4195
+
4196
+ // solana/fetchAirdropFee.ts
4197
+ var fetchAirdropFee = async (distributorId, apiUrl, apiKey, fetchFn = fetch) => {
4198
+ const url = `${apiUrl}/v2/api/airdrops/${encodeURIComponent(distributorId)}/fees`;
4199
+ const res = await fetchFn(url, {
4200
+ method: "GET",
4201
+ headers: {
4202
+ "Content-Type": "application/json",
4203
+ ...apiKey ? { "x-api-key": apiKey } : {}
4204
+ }
4205
+ });
4206
+ if (!res.ok) {
4207
+ const text = await res.text().catch(() => "");
4208
+ throw new Error(`Airdrop fee API error: ${res.status} ${res.statusText}${text ? ` - ${text}` : ""}`);
4209
+ }
4210
+ const json = await res.json();
4211
+ return json;
4212
+ };
4213
+
4214
+ // solana/fees.ts
4215
+ var MAXIMUM_FEE_FALLBACK = 9900000n;
4216
+ var MINIMUM_FEE_FALLBACK = 5000000n;
4217
+ var FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR = 90n;
4218
+ var FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR = 100n;
4219
+ var LAMPORTS_PER_SOL = 1000000000n;
4220
+ var lamportsToSolString = (lamports) => {
4221
+ const int = lamports / LAMPORTS_PER_SOL;
4222
+ const frac = lamports % LAMPORTS_PER_SOL;
4223
+ if (frac === 0n) return int.toString();
4224
+ const fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
4225
+ return `${int.toString()}.${fracStr}`;
4226
+ };
4227
+ var allocationToString = (num, den) => {
4228
+ const SCALE = 1000000000n;
4229
+ const scaled = num * SCALE / den;
4230
+ const int = scaled / SCALE;
4231
+ const frac = scaled % SCALE;
4232
+ if (frac === 0n) return int.toString();
4233
+ const fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
4234
+ return `${int.toString()}.${fracStr}`;
4235
+ };
4236
+ var defaultAPIFeesResponse = {
4237
+ isCustom: false,
4238
+ claimFee: void 0,
4239
+ claimFeeDynamic: {
4240
+ minPrice: lamportsToSolString(MINIMUM_FEE_FALLBACK),
4241
+ maxPrice: lamportsToSolString(MAXIMUM_FEE_FALLBACK),
4242
+ allocationFactor: allocationToString(
4243
+ FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR,
4244
+ FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR
4245
+ )
4246
+ }
4247
+ };
4248
+ var toLamportsSOL = (value, solDecimals = 9) => {
4249
+ const y = typeof value === "bigint" ? Number(value) : typeof value === "string" ? Number(value) : value;
4250
+ if (!Number.isFinite(y) || y <= 0) return 0n;
4251
+ const scale = 10n ** BigInt(solDecimals);
4252
+ return multiplyBigIntByNumber(scale, y);
4253
+ };
4254
+ var applyFeeLogic = (baseLamports) => {
4255
+ if (baseLamports <= 0n) {
4256
+ return MINIMUM_FEE_FALLBACK;
4257
+ }
4258
+ const raw = baseLamports * FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR / FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR;
4259
+ if (raw < MINIMUM_FEE_FALLBACK) return MINIMUM_FEE_FALLBACK;
4260
+ if (raw > MAXIMUM_FEE_FALLBACK) return MAXIMUM_FEE_FALLBACK;
4261
+ return raw;
4262
+ };
4263
+ async function calculateAirdropFeeLamports(params) {
4264
+ const { distributorAddress, client, claimableLamports } = params;
4265
+ try {
4266
+ if (client) {
4267
+ const res = await client.getAirdropFee(distributorAddress);
4268
+ const data = res?.data;
4269
+ if (data?.isCustom && data.claimFee !== void 0) {
4270
+ return toLamportsSOL(data.claimFee);
4271
+ }
4272
+ if (data?.claimFeeDynamic && claimableLamports !== void 0) {
4273
+ const min = toLamportsSOL(data.claimFeeDynamic.minPrice);
4274
+ const max = toLamportsSOL(data.claimFeeDynamic.maxPrice);
4275
+ const factor = Math.max(0, Math.min(1, parseFloat(data.claimFeeDynamic.allocationFactor)));
4276
+ const fee = multiplyBigIntByNumber(claimableLamports, factor);
4277
+ if (fee < min) return min;
4278
+ if (fee > max) return max;
4279
+ return fee;
4280
+ }
4281
+ }
4282
+ } catch (_err) {
4283
+ }
4284
+ if (claimableLamports !== void 0) {
4285
+ return applyFeeLogic(claimableLamports);
4286
+ }
4287
+ return MINIMUM_FEE_FALLBACK;
4288
+ }
4289
+ function calculateClaimableLamportsFromPrices(params) {
4290
+ const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
4291
+ if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
4292
+ const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
4293
+ const SCALE = 10n ** BigInt(scaleDigits);
4294
+ const pScaled = multiplyBigIntByNumber(SCALE, tokenPriceUsd, scaleDigits);
4295
+ const sScaled = multiplyBigIntByNumber(SCALE, solPriceUsd, scaleDigits);
4296
+ if (pScaled <= 0n || sScaled <= 0n) return 0n;
4297
+ const pow10 = (n) => 10n ** BigInt(n);
4298
+ const numerator = claimableAmount * pow10(solDecimals) * pScaled;
4299
+ const denominator = pow10(tokenDecimals) * sScaled;
4300
+ return numerator / denominator;
4301
+ }
4302
+ function calculateDynamicFeeFromSolParams(params) {
4303
+ const { minPrice, maxPrice, allocationFactor, claimableLamports, solDecimals = 9 } = params;
4304
+ const minLamports = toLamportsSOL(minPrice, solDecimals);
4305
+ const maxLamports = toLamportsSOL(maxPrice, solDecimals);
4306
+ const factor = Math.max(0, Math.min(1, parseFloat(allocationFactor)));
4307
+ const raw = multiplyBigIntByNumber(claimableLamports, factor);
4308
+ if (raw < minLamports) return minLamports;
4309
+ if (raw > maxLamports) return maxLamports;
4310
+ return raw;
4311
+ }
4312
+ async function resolveAirdropFeeLamportsUsingApi(params) {
4313
+ const { distributorAddress, mintAccount, claimableAmount, cluster, apiUrl, apiKey } = params;
4314
+ let apiFeesResponse = void 0;
4315
+ try {
4316
+ apiFeesResponse = await fetchAirdropFee(distributorAddress, apiUrl, apiKey);
4317
+ } catch (_) {
4318
+ }
4319
+ let solPrice = null;
4320
+ let tokenPrice = null;
4321
+ try {
4322
+ [solPrice, tokenPrice] = await Promise.all([
4323
+ fetchTokenPrice(NATIVE_MINT.toBase58(), cluster),
4324
+ fetchTokenPrice(mintAccount.address.toBase58(), cluster)
4325
+ ]);
4326
+ } catch (_) {
4327
+ }
4328
+ const response = apiFeesResponse ?? defaultAPIFeesResponse;
4329
+ if (response?.isCustom && response.claimFee !== void 0 && response.claimFee !== null) {
4330
+ return toLamportsSOL(response.claimFee);
4331
+ }
4332
+ const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
4333
+ if (!tokenPrice?.value || !solPrice?.value) {
4334
+ return MINIMUM_FEE_FALLBACK;
4335
+ }
4336
+ const baseLamports = calculateClaimableLamportsFromPrices({
4337
+ claimableAmount,
4338
+ tokenPriceUsd: tokenPrice.value,
4339
+ solPriceUsd: solPrice.value,
4340
+ tokenDecimals: mintAccount.decimals
4341
+ });
4342
+ return calculateDynamicFeeFromSolParams({
4343
+ minPrice: claimFeeDynamic.minPrice,
4344
+ maxPrice: claimFeeDynamic.maxPrice,
4345
+ allocationFactor: claimFeeDynamic.allocationFactor,
4346
+ claimableLamports: baseLamports
4347
+ });
4348
+ }
4349
+ var getAlignedDistributorPda = (programId, distributor) => {
4350
+ return PublicKey.findProgramAddressSync([ALIGNED_DISTRIBUTOR_PREFIX, distributor.toBuffer()], programId)[0];
4351
+ };
4352
+ var getTestOraclePda = (programId, mint, creator) => {
4353
+ return PublicKey.findProgramAddressSync([TEST_ORACLE_PREFIX, mint.toBuffer(), creator.toBuffer()], programId)[0];
4354
+ };
4355
+ function getDistributorPda(programId, mint, version) {
4356
+ const seeds = [
4357
+ DISTRIBUTOR_PREFIX,
4358
+ mint.toBuffer(),
4359
+ Buffer$1.from(new Uint8Array(new BigUint64Array([BigInt(version)]).buffer))
4360
+ ];
4361
+ return PublicKey.findProgramAddressSync(seeds, programId)[0];
4362
+ }
4363
+ function getClaimantStatusPda(programId, distributor, claimant) {
4364
+ const seeds = [CLAIM_STATUS_PREFIX, claimant.toBuffer(), distributor.toBuffer()];
4365
+ return PublicKey.findProgramAddressSync(seeds, programId)[0];
4366
+ }
4367
+ function getEventAuthorityPda(programId) {
4368
+ const seeds = [Buffer$1.from("__event_authority")];
4369
+ return PublicKey.findProgramAddressSync(seeds, programId)[0];
4370
+ }
4371
+ var isCompressedClaimStatus = (status) => {
4372
+ return !!status && "state" in status;
4373
+ };
4374
+ async function wrappedSignAndExecuteTransaction(...args) {
4375
+ try {
4376
+ return await signAndExecuteTransaction(...args);
4377
+ } catch (err) {
4378
+ if (err instanceof Error) {
4379
+ const parsed = translateError(err, MERKLE_DISTRIBUTOR_ERRORS);
4380
+ if ("error" in parsed) {
4381
+ throw new ContractError(err, parsed.error.errorCode?.code, parsed.error.errorMessage);
4382
+ }
4383
+ }
4384
+ throw err;
4385
+ }
4386
+ }
4387
+ async function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
4388
+ const epoch = await connection.getEpochInfo();
4389
+ const transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch ? transferFeeConfig.newerTransferFee : transferFeeConfig.olderTransferFee;
4390
+ const transferFeeBasisPoints = BigInt(transferFee.transferFeeBasisPoints);
4391
+ let feeCharged = BigInt(0);
4392
+ if (transferFeeBasisPoints !== BigInt(0)) {
4393
+ const numerator = transferAmount * ONE_IN_BASIS_POINTS;
4394
+ const denominator = ONE_IN_BASIS_POINTS - transferFeeBasisPoints;
4395
+ const rawPreFeeAmount = divCeilN(numerator, denominator);
4396
+ const fee = rawPreFeeAmount - transferAmount;
4397
+ transferAmount = rawPreFeeAmount;
4398
+ feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
4399
+ }
4400
+ return { transferAmount, feeCharged };
4401
+ }
4402
+
4403
+ // solana/clients/BaseDistributorClient.ts
4404
+ var BaseDistributorClient = class {
4405
+ constructor({
4406
+ clusterUrl,
4407
+ cluster = ICluster.Mainnet,
4408
+ commitment = "confirmed",
4409
+ programId = "",
4410
+ sendRate = 1,
4411
+ sendThrottler,
4412
+ apiUrl,
4413
+ apiKey
4414
+ }) {
4415
+ this.commitment = commitment;
4416
+ this.cluster = cluster;
4417
+ this.connection = new Connection(clusterUrl, this.commitment);
4418
+ this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(DISTRIBUTOR_PROGRAM_ID[cluster]);
4419
+ this.partnerOracleProgramId = new PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster]);
4420
+ this.partnerOracle = buildPartnerOracle(this.connection);
4421
+ this.feeConfigPublicKey = new PublicKey(FEE_CONFIG_PUBLIC_KEY[cluster]);
4422
+ this.sendThrottler = sendThrottler ?? buildSendThrottler(sendRate);
4423
+ const merkleDistributorProgram = {
4424
+ ...merkle_distributor_default
4425
+ };
4426
+ this.merkleDistributorProgram = new Program(merkleDistributorProgram, { connection: this.connection });
4427
+ this.apiUrl = apiUrl;
4428
+ this.apiKey = apiKey;
4429
+ }
4430
+ getConnection() {
4431
+ return this.connection;
4432
+ }
4433
+ getCommitment() {
4434
+ return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
4435
+ }
4436
+ getDistributorProgramId() {
4437
+ return this.programId;
4438
+ }
4439
+ async prepareCreateInstructions(data, extParams) {
4440
+ if (!extParams.invoker.publicKey) {
4441
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
4442
+ }
4443
+ const { version, mint } = data;
4444
+ const ixs = prepareBaseInstructions(this.connection, extParams);
4445
+ const mintPublicKey = extParams.isNative ? NATIVE_MINT : new PublicKey(mint);
4446
+ const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
4447
+ const transferFeeConfig = getTransferFeeConfig(mintAccount);
4448
+ const distributorPublicKey = getDistributorPda(this.programId, mintPublicKey, version);
4449
+ const tokenVault = await ata(mintPublicKey, distributorPublicKey, tokenProgramId);
4450
+ const senderTokens = await ata(mintPublicKey, extParams.invoker.publicKey, tokenProgramId);
4451
+ const accounts = {
4452
+ clawbackReceiver: senderTokens,
4453
+ mint: mintPublicKey,
4454
+ admin: extParams.invoker.publicKey,
4455
+ tokenProgram: tokenProgramId
4456
+ };
4457
+ if (extParams.isNative) {
4458
+ ixs.push(
4459
+ ...await prepareWrappedAccount(this.connection, extParams.invoker.publicKey, new BN(data.maxTotalClaim))
4460
+ );
4461
+ }
4462
+ const newDistributorInstruction = await this.getNewDistributorInstruction(data, accounts);
4463
+ ixs.push(newDistributorInstruction);
4464
+ if (transferFeeConfig) {
4465
+ const { transferAmount, feeCharged } = await calculateAmountWithTransferFees(
4466
+ this.connection,
4467
+ transferFeeConfig,
4468
+ BigInt(data.maxTotalClaim.toString())
4469
+ );
4470
+ ixs.push(
4471
+ createTransferCheckedWithFeeInstruction(
4472
+ senderTokens,
4473
+ mintPublicKey,
4474
+ tokenVault,
4475
+ extParams.invoker.publicKey,
4476
+ transferAmount,
4477
+ mintAccount.decimals,
4478
+ feeCharged,
4479
+ void 0,
4480
+ tokenProgramId
4481
+ )
4482
+ );
4483
+ } else {
4484
+ ixs.push(
4485
+ createTransferCheckedInstruction(
4486
+ senderTokens,
4487
+ mintPublicKey,
4488
+ tokenVault,
4489
+ extParams.invoker.publicKey,
4490
+ BigInt(data.maxTotalClaim.toString()),
4491
+ mintAccount.decimals,
4492
+ void 0,
4493
+ tokenProgramId
4494
+ )
4495
+ );
4496
+ }
4497
+ return { distributorPublicKey, ixs };
4498
+ }
4499
+ async create(data, extParams) {
4500
+ const invoker = extParams.invoker.publicKey;
4501
+ invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
4502
+ const executionParams = this.unwrapExecutionParams(extParams);
4503
+ const { ixs, distributorPublicKey } = await createAndEstimateTransaction(
4504
+ (params) => this.prepareCreateInstructions(data, params),
4505
+ executionParams,
4506
+ (q) => q.ixs
4507
+ );
4508
+ const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
4509
+ const signature = await wrappedSignAndExecuteTransaction(
4510
+ this.connection,
4511
+ extParams.invoker,
4512
+ tx,
4513
+ {
4514
+ hash,
4515
+ context,
4516
+ commitment: this.getCommitment()
4517
+ },
4518
+ { sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation }
4519
+ );
4520
+ return {
4521
+ ixs,
4522
+ txId: signature,
4523
+ metadataId: distributorPublicKey.toBase58()
4524
+ };
4525
+ }
4526
+ async claim(data, extParams, _serviceTransfer) {
4527
+ const executionParams = this.unwrapExecutionParams(extParams);
4528
+ const invoker = executionParams.invoker.publicKey;
4529
+ invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
4530
+ const ixs = await createAndEstimateTransaction(
4531
+ (params) => this.prepareClaimInstructions(data, params, _serviceTransfer),
4532
+ executionParams
4533
+ );
4534
+ const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker);
4535
+ const signature = await wrappedSignAndExecuteTransaction(
4536
+ this.connection,
4537
+ executionParams.invoker,
4538
+ tx,
4539
+ {
4540
+ hash,
4541
+ context,
4542
+ commitment: this.getCommitment()
4543
+ },
4544
+ { sendThrottler: this.sendThrottler, skipSimulation: true }
4545
+ );
4546
+ return { ixs, txId: signature };
4547
+ }
4548
+ async prepareClaimInstructions(data, extParams, _serviceTransfer) {
4549
+ if (!extParams.invoker.publicKey) {
4550
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
4551
+ }
4552
+ const distributorPublicKey = new PublicKey(data.id);
4553
+ const distributor = await this.merkleDistributorProgram.account.merkleDistributor.fetch(distributorPublicKey);
4554
+ if (!distributor) {
4555
+ throw new Error("Couldn't get account info");
4556
+ }
4557
+ const { tokenProgramId } = await getMintAndProgram(this.connection, distributor.mint);
4558
+ const ixs = prepareBaseInstructions(this.connection, extParams);
4559
+ ixs.push(
4560
+ ...await checkOrCreateAtaBatch(
4561
+ this.connection,
4562
+ [extParams.invoker.publicKey],
4563
+ distributor.mint,
4564
+ extParams.invoker,
4565
+ tokenProgramId,
4566
+ extParams.feePayer
4567
+ )
4568
+ );
4569
+ const invokerTokens = await ata(distributor.mint, extParams.invoker.publicKey, tokenProgramId);
4570
+ const claimStatusPublicKey = getClaimantStatusPda(
4571
+ this.programId,
4572
+ distributorPublicKey,
4573
+ extParams.invoker.publicKey
4574
+ );
4575
+ const claimStatus = await this.getClaim(claimStatusPublicKey);
4576
+ if (!claimStatus) {
4577
+ ixs.push(
4578
+ await this.merkleDistributorProgram.methods.newClaim(new BN(data.amountUnlocked), new BN(data.amountLocked), data.proof).accounts({
4579
+ distributor: distributorPublicKey,
4580
+ to: invokerTokens,
4581
+ claimant: extParams.invoker.publicKey,
4582
+ tokenProgram: tokenProgramId,
4583
+ program: this.programId
4584
+ }).instruction()
4585
+ );
4586
+ }
4587
+ const nowTs = new BN(Math.floor(Date.now() / 1e3));
4588
+ if (claimStatus || new BN(data.amountLocked).gtn(0) && nowTs.sub(distributor.startTs).gte(distributor.unlockPeriod)) {
4589
+ const claimMethod = distributor.programVersion >= SOL_FEE_PROGRAM_VERSION ? this.merkleDistributorProgram.methods.claimLockedV2 : this.merkleDistributorProgram.methods.claimLocked;
4590
+ ixs.push(
4591
+ await claimMethod().accounts({
4592
+ distributor: distributorPublicKey,
4593
+ to: invokerTokens,
4594
+ claimant: extParams.invoker.publicKey,
4595
+ tokenProgram: tokenProgramId,
4596
+ program: this.programId
4597
+ }).instruction()
4598
+ );
4599
+ }
4600
+ if (distributor.programVersion >= SOL_FEE_PROGRAM_VERSION) {
4601
+ return ixs;
4602
+ }
4603
+ let feeLamports = typeof _serviceTransfer === "bigint" ? _serviceTransfer : void 0;
4604
+ if (!feeLamports) {
4605
+ try {
4606
+ const { mint: mintAccount } = await getMintAndProgram(this.connection, distributor.mint);
4607
+ const claimableAmountRaw = data?.claimableAmount;
4608
+ const unlockedRaw = data?.amountUnlocked;
4609
+ const lockedRaw = data?.amountLocked;
4610
+ const unlocked = unlockedRaw != null ? new BN(unlockedRaw) : new BN(0);
4611
+ const locked = lockedRaw != null ? new BN(lockedRaw) : new BN(0);
4612
+ const computedFallback = unlocked.add(locked);
4613
+ const claimableAmount = claimableAmountRaw != null ? BigInt(claimableAmountRaw.toString()) : BigInt(computedFallback.toString());
4614
+ feeLamports = await resolveAirdropFeeLamportsUsingApi({
4615
+ distributorAddress: distributorPublicKey.toBase58(),
4616
+ mintAccount,
4617
+ claimableAmount,
4618
+ cluster: this.cluster,
4619
+ apiUrl: this.apiUrl,
4620
+ apiKey: this.apiKey
4621
+ });
4622
+ } catch (_) {
4623
+ feeLamports = MINIMUM_FEE_FALLBACK;
5521
4624
  }
5522
- },
5523
- {
5524
- name: "UpdateTestOracleParams",
5525
- type: {
5526
- kind: "struct",
5527
- fields: [
5528
- {
5529
- name: "price",
5530
- type: "u64"
5531
- },
5532
- {
5533
- name: "expo",
5534
- type: "i32"
5535
- },
5536
- {
5537
- name: "conf",
5538
- type: "u64"
5539
- },
5540
- {
5541
- name: "publish_time",
5542
- type: "i64"
5543
- }
5544
- ]
4625
+ }
4626
+ ixs.push(this.prepareClaimFeeInstruction(extParams.feePayer ?? extParams.invoker.publicKey, feeLamports));
4627
+ return ixs;
4628
+ }
4629
+ async closeClaim(data, extParams) {
4630
+ const executionParams = this.unwrapExecutionParams(extParams);
4631
+ const invoker = executionParams.invoker.publicKey;
4632
+ invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
4633
+ const ixs = await createAndEstimateTransaction(
4634
+ (params) => this.prepareCloseClaimInstructions(data, params),
4635
+ executionParams
4636
+ );
4637
+ const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker);
4638
+ const signature = await wrappedSignAndExecuteTransaction(
4639
+ this.connection,
4640
+ executionParams.invoker,
4641
+ tx,
4642
+ {
4643
+ hash,
4644
+ context,
4645
+ commitment: this.getCommitment()
4646
+ },
4647
+ { sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation }
4648
+ );
4649
+ return { ixs, txId: signature };
4650
+ }
4651
+ async prepareCloseClaimInstructions(data, extParams) {
4652
+ if (!extParams.invoker.publicKey) {
4653
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
4654
+ }
4655
+ const distributorPublicKey = new PublicKey(data.id);
4656
+ const distributor = await this.merkleDistributorProgram.account.merkleDistributor.fetch(distributorPublicKey);
4657
+ const claimantPublicKey = pk(data.claimant);
4658
+ if (!distributor) {
4659
+ throw new Error("Couldn't get distributor account info");
4660
+ }
4661
+ const ixs = prepareBaseInstructions(this.connection, extParams);
4662
+ ixs.push(
4663
+ await this.merkleDistributorProgram.methods.closeClaim(
4664
+ data.amountUnlocked ? new BN(data.amountUnlocked) : null,
4665
+ data.amountLocked ? new BN(data.amountLocked) : null,
4666
+ data.proof ?? null
4667
+ ).accounts({
4668
+ adminOrClaimant: extParams.invoker.publicKey,
4669
+ payer: extParams.invoker.publicKey,
4670
+ distributor: distributorPublicKey,
4671
+ claimant: claimantPublicKey,
4672
+ program: this.programId
4673
+ }).instruction()
4674
+ );
4675
+ return ixs;
4676
+ }
4677
+ async prepareClawbackInstructions(data, extParams) {
4678
+ if (!extParams.invoker.publicKey) {
4679
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
4680
+ }
4681
+ const distributorPublicKey = new PublicKey(data.id);
4682
+ const distributor = await this.merkleDistributorProgram.account.merkleDistributor.fetch(distributorPublicKey);
4683
+ if (!distributor) {
4684
+ throw new Error("Couldn't get account info");
4685
+ }
4686
+ const { tokenProgramId } = await getMintAndProgram(this.connection, distributor.mint);
4687
+ const ixs = prepareBaseInstructions(this.connection, extParams);
4688
+ ixs.push(
4689
+ ...await checkOrCreateAtaBatch(
4690
+ this.connection,
4691
+ [extParams.invoker.publicKey],
4692
+ distributor.mint,
4693
+ extParams.invoker,
4694
+ tokenProgramId,
4695
+ extParams.feePayer
4696
+ )
4697
+ );
4698
+ const accounts = {
4699
+ distributor: distributorPublicKey,
4700
+ from: distributor.tokenVault,
4701
+ to: distributor.clawbackReceiver,
4702
+ admin: extParams.invoker.publicKey,
4703
+ mint: distributor.mint,
4704
+ tokenProgram: tokenProgramId
4705
+ };
4706
+ const clawbackInstruction = await this.getClawbackInstruction(accounts);
4707
+ ixs.push(clawbackInstruction);
4708
+ return ixs;
4709
+ }
4710
+ async clawback(data, extParams) {
4711
+ const executionParams = this.unwrapExecutionParams(extParams);
4712
+ const invoker = executionParams.invoker.publicKey;
4713
+ invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
4714
+ const ixs = await createAndEstimateTransaction(
4715
+ (params) => this.prepareClawbackInstructions(data, params),
4716
+ executionParams
4717
+ );
4718
+ const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker);
4719
+ const signature = await wrappedSignAndExecuteTransaction(
4720
+ this.connection,
4721
+ executionParams.invoker,
4722
+ tx,
4723
+ {
4724
+ hash,
4725
+ context,
4726
+ commitment: this.getCommitment()
4727
+ },
4728
+ { sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation }
4729
+ );
4730
+ return { ixs, txId: signature };
4731
+ }
4732
+ async getClaim(claimStatus) {
4733
+ return this.connection.getAccountInfo(pk(claimStatus)).then((account) => this.decodeClaimStatus(account));
4734
+ }
4735
+ async getClaims(data) {
4736
+ const claimStatusPublicKeys = data.map(({ id, recipient }) => {
4737
+ return getClaimantStatusPda(this.programId, new PublicKey(id), new PublicKey(recipient));
4738
+ });
4739
+ return this.connection.getMultipleAccountsInfo(claimStatusPublicKeys).then((accounts) => {
4740
+ return accounts.map((account) => this.decodeClaimStatus(account));
4741
+ });
4742
+ }
4743
+ async getDistributors(data) {
4744
+ const distributorPublicKeys = data.ids.map((distributorId) => new PublicKey(distributorId));
4745
+ return this.merkleDistributorProgram.account.merkleDistributor.fetchMultiple(distributorPublicKeys);
4746
+ }
4747
+ async searchDistributors(data) {
4748
+ const filters = [];
4749
+ if (data.mint) {
4750
+ filters.push({
4751
+ memcmp: {
4752
+ offset: DISTRIBUTOR_MINT_OFFSET,
4753
+ bytes: data.mint
4754
+ }
4755
+ });
4756
+ }
4757
+ if (data.admin) {
4758
+ filters.push({
4759
+ memcmp: {
4760
+ offset: DISTRIBUTOR_ADMIN_OFFSET,
4761
+ bytes: data.admin
4762
+ }
4763
+ });
4764
+ }
4765
+ return this.merkleDistributorProgram.account.merkleDistributor.all(filters);
4766
+ }
4767
+ /**
4768
+ * Fetch Fee Config for the Airdrop protocol from Partner Oracle.
4769
+ */
4770
+ async getFeeConfig() {
4771
+ const accInfo = await this.connection.getAccountInfo(this.feeConfigPublicKey);
4772
+ if (!accInfo) {
4773
+ throw new Error("Fee config is not initialized!");
4774
+ }
4775
+ return decode(this.partnerOracle, "airdropConfig", accInfo.data);
4776
+ }
4777
+ /**
4778
+ * Get all defaults fees applied by the protocol.
4779
+ */
4780
+ async getDefaultFees() {
4781
+ const feeConfig = await this.getFeeConfig();
4782
+ return {
4783
+ pubkey: PublicKey.default,
4784
+ creationFee: feeConfig.creationFee,
4785
+ priceOracleFee: feeConfig.priceOracleFee,
4786
+ claimMinFee: feeConfig.claimMinFee,
4787
+ claimMaxFee: feeConfig.claimMaxFee,
4788
+ allocationFactor: feeConfig.allocationFactor,
4789
+ clawbackTokenFeePercent: feeConfig.clawbackTokenFeePercent
4790
+ };
4791
+ }
4792
+ /**
4793
+ * Get fees for a given wallet.
4794
+ *
4795
+ * @param pubkey partner to search fees for
4796
+ */
4797
+ async getFees(pubkey) {
4798
+ const feeConfig = await this.getFeeConfig();
4799
+ const nowTs = new BN(Math.trunc(Date.now() / 1e3));
4800
+ const filteredPartners = feeConfig.partners.filter(
4801
+ (partner) => partner.pubkey.equals(pubkey) && (partner.expiryTs.eqn(0) || partner.expiryTs.gt(nowTs))
4802
+ );
4803
+ if (filteredPartners.length > 1) {
4804
+ throw new Error("More than one partner found, fees fetching is not possible.");
4805
+ }
4806
+ return filteredPartners[0] ?? null;
4807
+ }
4808
+ prepareClaimFeeInstruction(payer, fee = AIRDROP_CLAIM_FEE) {
4809
+ return SystemProgram.transfer({
4810
+ fromPubkey: payer,
4811
+ toPubkey: STREAMFLOW_TREASURY_PUBLIC_KEY,
4812
+ lamports: fee
4813
+ });
4814
+ }
4815
+ validateDistributorArgs(data) {
4816
+ const nowTs = Math.floor(Date.now() / 1e3);
4817
+ const endVestingTs = data.endVestingTs === 0 ? nowTs : data.endVestingTs;
4818
+ const startVestingTs = data.startVestingTs === 0 ? nowTs : data.startVestingTs;
4819
+ if (endVestingTs > startVestingTs && endVestingTs - startVestingTs < data.unlockPeriod) {
4820
+ throw new Error("The unlock period cannot be longer than the total vesting duration!");
4821
+ }
4822
+ }
4823
+ unwrapExecutionParams(extParams) {
4824
+ return unwrapExecutionParams(extParams, this.connection);
4825
+ }
4826
+ decodeClaimStatus(account) {
4827
+ if (!account) {
4828
+ return null;
4829
+ }
4830
+ try {
4831
+ return decode(this.merkleDistributorProgram, "claimStatus", account.data);
4832
+ } catch (baseClaimStatusError) {
4833
+ try {
4834
+ return decode(this.merkleDistributorProgram, "compressedClaimStatus", account.data);
4835
+ } catch (compressedClaimStatusError) {
4836
+ throw new Error("Couldn't decode claim status");
5545
4837
  }
5546
4838
  }
5547
- ]
4839
+ }
5548
4840
  };
4841
+ function decode(program, accountName, accInfo, programKey) {
4842
+ const programId = program.programId?.toBase58() ?? "N/A";
4843
+ invariant(program, `Decoding program with key ${programId} is not available`);
4844
+ const accountEntity = program.idl.accounts?.find((acc) => acc.name === accountName);
4845
+ invariant(
4846
+ !!accountEntity,
4847
+ `Decoding program with key ${programId} doesn't specify account with name ${String(accountName)}`
4848
+ );
4849
+ return program.coder.accounts.decode(accountName, accInfo);
4850
+ }
5549
4851
 
5550
- // solana/clients/SolanaAlignedDistributorClient.ts
4852
+ // solana/clients/SolanaDistributorClient.ts
4853
+ var SolanaDistributorClient = class extends BaseDistributorClient {
4854
+ async getNewDistributorInstruction(data, accounts) {
4855
+ this.validateDistributorArgs(data);
4856
+ return this.merkleDistributorProgram.methods.newDistributor(
4857
+ new BN(data.version),
4858
+ data.root,
4859
+ new BN(data.maxTotalClaim),
4860
+ new BN(data.maxNumNodes),
4861
+ new BN(data.unlockPeriod),
4862
+ new BN(data.startVestingTs),
4863
+ new BN(data.endVestingTs),
4864
+ new BN(data.clawbackStartTs),
4865
+ data.claimsClosableByAdmin,
4866
+ null,
4867
+ // can_update_duration
4868
+ null,
4869
+ // total_amount_unlocked
4870
+ null,
4871
+ // total_amount_locked
4872
+ data.claimsClosableByClaimant ?? null,
4873
+ data.claimsLimit ?? null
4874
+ ).accounts(accounts).instruction();
4875
+ }
4876
+ async getClawbackInstruction(accounts) {
4877
+ return this.merkleDistributorProgram.methods.clawback().accounts(accounts).instruction();
4878
+ }
4879
+ };
5551
4880
  var SolanaAlignedDistributorClient = class extends BaseDistributorClient {
5552
- constructor({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler, apiUrl, apiKey }) {
4881
+ constructor({
4882
+ clusterUrl,
4883
+ cluster,
4884
+ commitment,
4885
+ programId,
4886
+ sendRate,
4887
+ sendThrottler,
4888
+ apiUrl,
4889
+ apiKey
4890
+ }) {
5553
4891
  super({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler, apiUrl, apiKey });
5554
4892
  const alignedAirdropsProgram = {
5555
4893
  ...aligned_distributor_default
@@ -5585,38 +4923,42 @@ var SolanaAlignedDistributorClient = class extends BaseDistributorClient {
5585
4923
  };
5586
4924
  }
5587
4925
  async getNewDistributorInstruction(data, accounts) {
5588
- const { distributor, mint, clawbackReceiver, tokenProgram, tokenVault, admin } = accounts;
5589
- const baseArgs = this.getNewDistributorArgs(data);
4926
+ const { mint, clawbackReceiver, tokenProgram, admin } = accounts;
4927
+ const distributorKey = getDistributorPda(this.merkleDistributorProgram.programId, pk(accounts.mint), data.version);
4928
+ const tokenVaultKey = getAssociatedTokenAddressSync(pk(mint), pk(admin), true, pk(tokenProgram));
4929
+ this.validateDistributorArgs(data);
5590
4930
  const alignedArgs = this.getNewAlignedDistributorArgs(data);
5591
- const oracle = data.oracleAddress ? new PublicKey(data.oracleAddress) : getTestOraclePda(this.alignedProxyProgram.programId, mint, admin);
5592
- const newDistributorIx = await this.alignedProxyProgram.methods.newDistributor({
5593
- claimsClosable: baseArgs.claimsClosableByAdmin,
5594
- version: baseArgs.version,
5595
- root: baseArgs.root,
5596
- maxTotalClaim: baseArgs.maxTotalClaim,
5597
- maxNumNodes: baseArgs.maxNumNodes,
5598
- unlockPeriod: baseArgs.unlockPeriod,
5599
- startVestingTs: baseArgs.startVestingTs,
5600
- endVestingTs: baseArgs.endVestingTs,
5601
- clawbackStartTs: baseArgs.clawbackStartTs,
4931
+ const oracle = data.oracleAddress ? new PublicKey(data.oracleAddress) : getTestOraclePda(this.alignedProxyProgram.programId, pk(mint), pk(admin));
4932
+ return this.alignedProxyProgram.methods.newDistributor({
4933
+ claimsClosable: data.claimsClosableByAdmin,
4934
+ version: new BN(data.version),
4935
+ root: data.root,
4936
+ maxTotalClaim: new BN(data.maxTotalClaim),
4937
+ maxNumNodes: new BN(data.maxNumNodes),
4938
+ unlockPeriod: new BN(data.unlockPeriod),
4939
+ startVestingTs: new BN(data.startVestingTs),
4940
+ endVestingTs: new BN(data.endVestingTs),
4941
+ clawbackStartTs: new BN(data.clawbackStartTs),
5602
4942
  ...alignedArgs
5603
4943
  }).accounts({
5604
4944
  admin,
5605
- tokenVault,
5606
- distributor,
4945
+ tokenVault: tokenVaultKey,
4946
+ distributor: distributorKey,
5607
4947
  clawbackReceiver,
5608
4948
  mint,
5609
4949
  tokenProgram,
5610
4950
  priceOracle: oracle
5611
4951
  }).instruction();
5612
- return newDistributorIx;
5613
4952
  }
5614
4953
  async getClawbackInstruction(accounts) {
5615
4954
  const { distributor, from, to, mint, tokenProgram, admin } = accounts;
5616
- const alignedDistributorKey = getAlignedDistributorPda(this.alignedProxyProgram.programId, distributor);
4955
+ const alignedDistributorKey = getAlignedDistributorPda(
4956
+ this.alignedProxyProgram.programId,
4957
+ pk(accounts.distributor)
4958
+ );
5617
4959
  const alignedProxy = await this.alignedProxyProgram.account.alignedDistributor.fetch(alignedDistributorKey);
5618
4960
  invariant(alignedProxy, "Aligned Distributor proxy account not found");
5619
- const clawbackInstruction = await this.alignedProxyProgram.methods.clawback().accounts({
4961
+ return this.alignedProxyProgram.methods.clawback().accounts({
5620
4962
  admin,
5621
4963
  distributor,
5622
4964
  from,
@@ -5624,7 +4966,6 @@ var SolanaAlignedDistributorClient = class extends BaseDistributorClient {
5624
4966
  mint,
5625
4967
  tokenProgram
5626
4968
  }).instruction();
5627
- return clawbackInstruction;
5628
4969
  }
5629
4970
  getNewAlignedDistributorArgs(data) {
5630
4971
  const {
@@ -5640,16 +4981,16 @@ var SolanaAlignedDistributorClient = class extends BaseDistributorClient {
5640
4981
  unlockPeriod
5641
4982
  } = data;
5642
4983
  return {
5643
- totalAmountLocked: new BN5(totalAmountLocked),
5644
- totalAmountUnlocked: new BN5(totalAmountUnlocked),
4984
+ totalAmountLocked: new BN(totalAmountLocked),
4985
+ totalAmountUnlocked: new BN(totalAmountUnlocked),
5645
4986
  oracleType: !!oracleType ? { [oracleType]: {} } : { none: {} },
5646
4987
  minPrice: getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW),
5647
4988
  maxPrice: getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW),
5648
4989
  minPercentage: getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW),
5649
4990
  maxPercentage: getBN(maxPercentage, ALIGNED_PRECISION_FACTOR_POW),
5650
- tickSize: new BN5(tickSize || 1),
4991
+ tickSize: new BN(tickSize || 1),
5651
4992
  skipInitial: skipInitial ?? false,
5652
- updatePeriod: unlockPeriod < 30 ? new BN5(30) : new BN5(unlockPeriod)
4993
+ updatePeriod: unlockPeriod < 30 ? new BN(30) : new BN(unlockPeriod)
5653
4994
  };
5654
4995
  }
5655
4996
  };