@streamflow/distributor 9.0.0-alpha.p308.8fcedb9 → 9.0.1

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.
@@ -7,7 +7,7 @@ import { IdlTypes, Program } from '@coral-xyz/anchor';
7
7
  import { AlignedDistributor } from './descriptor/aligned_distributor.cjs';
8
8
  import { MerkleDistributor as MerkleDistributor$1 } from './descriptor/merkle_distributor.cjs';
9
9
  import PQueue from 'p-queue';
10
- import { TransferFeeConfig } from '@solana/spl-token';
10
+ import { TransferFeeConfig, Mint } from '@solana/spl-token';
11
11
 
12
12
  type MerkleDistributorAccountTypes = IdlTypes<MerkleDistributor$1>;
13
13
  /**
@@ -1388,29 +1388,76 @@ type AirdropFeeResponse = {
1388
1388
  };
1389
1389
  isCustom: boolean;
1390
1390
  };
1391
-
1392
- declare const fetchAirdropFee: (distributorId: string, cluster?: ICluster, fetchFn?: typeof fetch) => Promise<AirdropFeeResponse>;
1393
1391
  interface AirdropFeeQueryOptionsOverrides {
1394
1392
  staleTimeMs?: number;
1395
1393
  gcTimeMs?: number;
1396
1394
  retry?: number | boolean;
1397
1395
  refetchOnWindowFocus?: boolean;
1398
1396
  }
1399
- declare function getAirdropFeeQueryOptions(params: {
1400
- distributorId: string;
1401
- cluster?: ICluster;
1402
- fetchFn?: typeof fetch;
1403
- }, options?: AirdropFeeQueryOptionsOverrides): {
1404
- queryKey: string[];
1405
- queryFn: () => Promise<AirdropFeeResponse>;
1406
- staleTime: number;
1407
- gcTime: number;
1408
- retry: number | boolean;
1409
- refetchOnWindowFocus: boolean;
1397
+ declare const fetchAirdropFee: (distributorId: string, cluster?: ICluster, fetchFn?: typeof fetch) => Promise<AirdropFeeResponse>;
1398
+
1399
+ type AirdropFeeDynamic = {
1400
+ minPrice: string;
1401
+ maxPrice: string;
1402
+ allocationFactor: string;
1403
+ };
1404
+ type AirdropFeeServiceResponse = {
1405
+ isCustom?: boolean;
1406
+ claimFee?: string | number;
1407
+ claimFeeDynamic?: AirdropFeeDynamic;
1410
1408
  };
1409
+ type AirdropFeeClient = {
1410
+ getAirdropFee: (distributorAddress: string) => Promise<{
1411
+ data?: AirdropFeeServiceResponse;
1412
+ }>;
1413
+ };
1414
+ declare const MAXIMUM_FEE_FALLBACK = 9900000n;
1415
+ declare const MINIMUM_FEE_FALLBACK = 5000000n;
1416
+ declare const FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR = 90n;
1417
+ declare const FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR = 100n;
1418
+ declare const toLamportsSOL: (value: string | number | bigint, solDecimals?: number) => bigint;
1419
+ declare const applyFeeLogic: (baseLamports: bigint) => bigint;
1420
+ declare function calculateAirdropFeeLamports(params: {
1421
+ distributorAddress: string;
1422
+ client?: AirdropFeeClient;
1423
+ claimableLamports?: bigint;
1424
+ }): Promise<bigint>;
1425
+ /**
1426
+ * Calculates claimable SOL lamports from:
1427
+ * - claimable token amount in the token's base units (BN or bigint)
1428
+ * - token USD price and SOL USD price
1429
+ * - token decimals
1430
+ */
1431
+ declare function calculateClaimableLamportsFromPrices(params: {
1432
+ claimableAmount: bigint;
1433
+ tokenPriceUsd: number;
1434
+ solPriceUsd: number;
1435
+ tokenDecimals: number;
1436
+ solDecimals?: number;
1437
+ }): bigint;
1438
+ /**
1439
+ * Calculates lamport fee using dynamic SOL parameters coming from backend
1440
+ * minPrice/maxPrice/allocationFactor are strings from API; prices are in SOL units
1441
+ */
1442
+ declare function calculateDynamicFeeFromSolParams(params: {
1443
+ minPrice: string;
1444
+ maxPrice: string;
1445
+ allocationFactor: string;
1446
+ claimableLamports: bigint;
1447
+ solDecimals?: number;
1448
+ }): bigint;
1449
+ declare function resolveAirdropFeeLamportsUsingApi(params: {
1450
+ distributorAddress: string;
1451
+ mintAccount: Mint;
1452
+ claimableAmount: bigint;
1453
+ cluster: ICluster;
1454
+ }): Promise<bigint>;
1411
1455
 
1456
+ type index_AirdropFeeClient = AirdropFeeClient;
1457
+ type index_AirdropFeeDynamic = AirdropFeeDynamic;
1412
1458
  type index_AirdropFeeQueryOptionsOverrides = AirdropFeeQueryOptionsOverrides;
1413
1459
  type index_AirdropFeeResponse = AirdropFeeResponse;
1460
+ type index_AirdropFeeServiceResponse = AirdropFeeServiceResponse;
1414
1461
  type index_AlignedDistributorData = AlignedDistributorData;
1415
1462
  type index_AnchorErrorCode = AnchorErrorCode;
1416
1463
  declare const index_AnchorErrorCode: typeof AnchorErrorCode;
@@ -1422,6 +1469,8 @@ type index_CloseClaimAccounts = CloseClaimAccounts;
1422
1469
  type index_CompressedClaimStatus = CompressedClaimStatus;
1423
1470
  type index_ContractErrorCode = ContractErrorCode;
1424
1471
  declare const index_ContractErrorCode: typeof ContractErrorCode;
1472
+ declare const index_FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR: typeof FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR;
1473
+ declare const index_FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR: typeof FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR;
1425
1474
  type index_IClaimData = IClaimData;
1426
1475
  type index_IClawbackData = IClawbackData;
1427
1476
  type index_ICloseClaimData = ICloseClaimData;
@@ -1435,6 +1484,8 @@ type index_IInteractSolanaExt = IInteractSolanaExt;
1435
1484
  type index_ISearchDistributors = ISearchDistributors;
1436
1485
  type index_ISetClawbackReceiverData = ISetClawbackReceiverData;
1437
1486
  type index_ISetDataAdmin = ISetDataAdmin;
1487
+ declare const index_MAXIMUM_FEE_FALLBACK: typeof MAXIMUM_FEE_FALLBACK;
1488
+ declare const index_MINIMUM_FEE_FALLBACK: typeof MINIMUM_FEE_FALLBACK;
1438
1489
  type index_MerkleDistributor = MerkleDistributor;
1439
1490
  declare const index_MerkleDistributor: typeof MerkleDistributor;
1440
1491
  type index_MerkleDistributorAccountTypes = MerkleDistributorAccountTypes;
@@ -1453,7 +1504,11 @@ type index_SolanaAlignedDistributorClient = SolanaAlignedDistributorClient;
1453
1504
  declare const index_SolanaAlignedDistributorClient: typeof SolanaAlignedDistributorClient;
1454
1505
  type index_SolanaDistributorClient = SolanaDistributorClient;
1455
1506
  declare const index_SolanaDistributorClient: typeof SolanaDistributorClient;
1507
+ declare const index_applyFeeLogic: typeof applyFeeLogic;
1508
+ declare const index_calculateAirdropFeeLamports: typeof calculateAirdropFeeLamports;
1456
1509
  declare const index_calculateAmountWithTransferFees: typeof calculateAmountWithTransferFees;
1510
+ declare const index_calculateClaimableLamportsFromPrices: typeof calculateClaimableLamportsFromPrices;
1511
+ declare const index_calculateDynamicFeeFromSolParams: typeof calculateDynamicFeeFromSolParams;
1457
1512
  declare const index_claimLocked: typeof claimLocked;
1458
1513
  declare const index_clawback: typeof clawback;
1459
1514
  declare const index_closeClaim: typeof closeClaim;
@@ -1461,7 +1516,6 @@ declare const index_constants: typeof constants;
1461
1516
  declare const index_fetchAirdropFee: typeof fetchAirdropFee;
1462
1517
  declare const index_fromCode: typeof fromCode;
1463
1518
  declare const index_fromTxError: typeof fromTxError;
1464
- declare const index_getAirdropFeeQueryOptions: typeof getAirdropFeeQueryOptions;
1465
1519
  declare const index_getAlignedDistributorPda: typeof getAlignedDistributorPda;
1466
1520
  declare const index_getClaimantStatusPda: typeof getClaimantStatusPda;
1467
1521
  declare const index_getDistributorPda: typeof getDistributorPda;
@@ -1470,11 +1524,13 @@ declare const index_getTestOraclePda: typeof getTestOraclePda;
1470
1524
  declare const index_isCompressedClaimStatus: typeof isCompressedClaimStatus;
1471
1525
  declare const index_newClaim: typeof newClaim;
1472
1526
  declare const index_newDistributor: typeof newDistributor;
1527
+ declare const index_resolveAirdropFeeLamportsUsingApi: typeof resolveAirdropFeeLamportsUsingApi;
1473
1528
  declare const index_setAdmin: typeof setAdmin;
1474
1529
  declare const index_setClawbackReceiver: typeof setClawbackReceiver;
1530
+ declare const index_toLamportsSOL: typeof toLamportsSOL;
1475
1531
  declare const index_wrappedSignAndExecuteTransaction: typeof wrappedSignAndExecuteTransaction;
1476
1532
  declare namespace index {
1477
- export { type index_AirdropFeeQueryOptionsOverrides as AirdropFeeQueryOptionsOverrides, type index_AirdropFeeResponse as AirdropFeeResponse, type index_AlignedDistributorData as AlignedDistributorData, index_AnchorErrorCode as AnchorErrorCode, type index_AnyClaimStatus as AnyClaimStatus, type index_ClaimLockedAccounts as ClaimLockedAccounts, type index_ClaimStatus as ClaimStatus, type index_ClawbackAccounts as ClawbackAccounts, type index_CloseClaimAccounts as CloseClaimAccounts, type index_CompressedClaimStatus as CompressedClaimStatus, index_ContractErrorCode as ContractErrorCode, type index_IClaimData as IClaimData, type index_IClawbackData as IClawbackData, type index_ICloseClaimData as ICloseClaimData, type index_ICreateAlignedDistributorData as ICreateAlignedDistributorData, type index_ICreateDistributorData as ICreateDistributorData, type index_ICreateDistributorResult as ICreateDistributorResult, type index_ICreateSolanaExt as ICreateSolanaExt, type index_IGetClaimData as IGetClaimData, type index_IGetDistributors as IGetDistributors, type index_IInteractSolanaExt as IInteractSolanaExt, type index_ISearchDistributors as ISearchDistributors, type index_ISetClawbackReceiverData as ISetClawbackReceiverData, type index_ISetDataAdmin as ISetDataAdmin, index_MerkleDistributor as MerkleDistributor, type index_MerkleDistributorAccountTypes as MerkleDistributorAccountTypes, type index_MerkleDistributorFields as MerkleDistributorFields, type index_MerkleDistributorJSON as MerkleDistributorJSON, type index_NewAlignedDistributorArgs as NewAlignedDistributorArgs, type index_NewClaimAccounts as NewClaimAccounts, type index_NewClaimArgs as NewClaimArgs, type index_NewDistributorAccounts as NewDistributorAccounts, type index_NewDistributorArgs as NewDistributorArgs, type index_OracleType as OracleType, type index_OracleTypeName as OracleTypeName, type index_SetAdminAccounts as SetAdminAccounts, type index_SetClawbackReceiverAccounts as SetClawbackReceiverAccounts, index_SolanaAlignedDistributorClient as SolanaAlignedDistributorClient, index_SolanaDistributorClient as SolanaDistributorClient, index_calculateAmountWithTransferFees as calculateAmountWithTransferFees, index_claimLocked as claimLocked, index_clawback as clawback, index_closeClaim as closeClaim, index_constants as constants, index_fetchAirdropFee as fetchAirdropFee, index_fromCode as fromCode, index_fromTxError as fromTxError, index_getAirdropFeeQueryOptions as getAirdropFeeQueryOptions, index_getAlignedDistributorPda as getAlignedDistributorPda, index_getClaimantStatusPda as getClaimantStatusPda, index_getDistributorPda as getDistributorPda, index_getEventAuthorityPda as getEventAuthorityPda, index_getTestOraclePda as getTestOraclePda, index_isCompressedClaimStatus as isCompressedClaimStatus, index_newClaim as newClaim, index_newDistributor as newDistributor, index_setAdmin as setAdmin, index_setClawbackReceiver as setClawbackReceiver, index_wrappedSignAndExecuteTransaction as wrappedSignAndExecuteTransaction };
1533
+ export { type index_AirdropFeeClient as AirdropFeeClient, type index_AirdropFeeDynamic as AirdropFeeDynamic, type index_AirdropFeeQueryOptionsOverrides as AirdropFeeQueryOptionsOverrides, type index_AirdropFeeResponse as AirdropFeeResponse, type index_AirdropFeeServiceResponse as AirdropFeeServiceResponse, type index_AlignedDistributorData as AlignedDistributorData, index_AnchorErrorCode as AnchorErrorCode, type index_AnyClaimStatus as AnyClaimStatus, type index_ClaimLockedAccounts as ClaimLockedAccounts, type index_ClaimStatus as ClaimStatus, type index_ClawbackAccounts as ClawbackAccounts, type index_CloseClaimAccounts as CloseClaimAccounts, type index_CompressedClaimStatus as CompressedClaimStatus, index_ContractErrorCode as ContractErrorCode, index_FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR as FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR, index_FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR as FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR, type index_IClaimData as IClaimData, type index_IClawbackData as IClawbackData, type index_ICloseClaimData as ICloseClaimData, type index_ICreateAlignedDistributorData as ICreateAlignedDistributorData, type index_ICreateDistributorData as ICreateDistributorData, type index_ICreateDistributorResult as ICreateDistributorResult, type index_ICreateSolanaExt as ICreateSolanaExt, type index_IGetClaimData as IGetClaimData, type index_IGetDistributors as IGetDistributors, type index_IInteractSolanaExt as IInteractSolanaExt, type index_ISearchDistributors as ISearchDistributors, type index_ISetClawbackReceiverData as ISetClawbackReceiverData, type index_ISetDataAdmin as ISetDataAdmin, index_MAXIMUM_FEE_FALLBACK as MAXIMUM_FEE_FALLBACK, index_MINIMUM_FEE_FALLBACK as MINIMUM_FEE_FALLBACK, index_MerkleDistributor as MerkleDistributor, type index_MerkleDistributorAccountTypes as MerkleDistributorAccountTypes, type index_MerkleDistributorFields as MerkleDistributorFields, type index_MerkleDistributorJSON as MerkleDistributorJSON, type index_NewAlignedDistributorArgs as NewAlignedDistributorArgs, type index_NewClaimAccounts as NewClaimAccounts, type index_NewClaimArgs as NewClaimArgs, type index_NewDistributorAccounts as NewDistributorAccounts, type index_NewDistributorArgs as NewDistributorArgs, type index_OracleType as OracleType, type index_OracleTypeName as OracleTypeName, type index_SetAdminAccounts as SetAdminAccounts, type index_SetClawbackReceiverAccounts as SetClawbackReceiverAccounts, index_SolanaAlignedDistributorClient as SolanaAlignedDistributorClient, index_SolanaDistributorClient as SolanaDistributorClient, index_applyFeeLogic as applyFeeLogic, index_calculateAirdropFeeLamports as calculateAirdropFeeLamports, index_calculateAmountWithTransferFees as calculateAmountWithTransferFees, index_calculateClaimableLamportsFromPrices as calculateClaimableLamportsFromPrices, index_calculateDynamicFeeFromSolParams as calculateDynamicFeeFromSolParams, index_claimLocked as claimLocked, index_clawback as clawback, index_closeClaim as closeClaim, index_constants as constants, index_fetchAirdropFee as fetchAirdropFee, index_fromCode as fromCode, index_fromTxError as fromTxError, index_getAlignedDistributorPda as getAlignedDistributorPda, index_getClaimantStatusPda as getClaimantStatusPda, index_getDistributorPda as getDistributorPda, index_getEventAuthorityPda as getEventAuthorityPda, index_getTestOraclePda as getTestOraclePda, index_isCompressedClaimStatus as isCompressedClaimStatus, index_newClaim as newClaim, index_newDistributor as newDistributor, index_resolveAirdropFeeLamportsUsingApi as resolveAirdropFeeLamportsUsingApi, index_setAdmin as setAdmin, index_setClawbackReceiver as setClawbackReceiver, index_toLamportsSOL as toLamportsSOL, index_wrappedSignAndExecuteTransaction as wrappedSignAndExecuteTransaction };
1478
1534
  }
1479
1535
 
1480
- export { type AirdropFeeQueryOptionsOverrides, type AirdropFeeResponse, type AlignedDistributorData, AnchorErrorCode, type AnyClaimStatus, type ClaimLockedAccounts, type ClaimStatus, type ClawbackAccounts, type CloseClaimAccounts, type CompressedClaimStatus, ContractErrorCode, type IClaimData, type IClawbackData, type ICloseClaimData, type ICreateAlignedDistributorData, type ICreateDistributorData, type ICreateDistributorResult, type ICreateSolanaExt, type IGetClaimData, type IGetDistributors, type IInteractSolanaExt, type ISearchDistributors, type ISetClawbackReceiverData, type ISetDataAdmin, MerkleDistributor, type MerkleDistributorAccountTypes, type MerkleDistributorFields, type MerkleDistributorJSON, type NewAlignedDistributorArgs, type NewClaimAccounts, type NewClaimArgs, type NewDistributorAccounts, type NewDistributorArgs, type OracleType, type OracleTypeName, type SetAdminAccounts, type SetClawbackReceiverAccounts, SolanaAlignedDistributorClient, SolanaDistributorClient, calculateAmountWithTransferFees, claimLocked, clawback, closeClaim, constants, fetchAirdropFee, fromCode, fromTxError, getAirdropFeeQueryOptions, getAlignedDistributorPda, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, getTestOraclePda, index as i, isCompressedClaimStatus, newClaim, newDistributor, setAdmin, setClawbackReceiver, wrappedSignAndExecuteTransaction };
1536
+ export { type AirdropFeeClient, type AirdropFeeDynamic, type AirdropFeeQueryOptionsOverrides, type AirdropFeeResponse, type AirdropFeeServiceResponse, type AlignedDistributorData, AnchorErrorCode, type AnyClaimStatus, type ClaimLockedAccounts, type ClaimStatus, type ClawbackAccounts, type CloseClaimAccounts, type CompressedClaimStatus, ContractErrorCode, FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR, FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR, type IClaimData, type IClawbackData, type ICloseClaimData, type ICreateAlignedDistributorData, type ICreateDistributorData, type ICreateDistributorResult, type ICreateSolanaExt, type IGetClaimData, type IGetDistributors, type IInteractSolanaExt, type ISearchDistributors, type ISetClawbackReceiverData, type ISetDataAdmin, MAXIMUM_FEE_FALLBACK, MINIMUM_FEE_FALLBACK, MerkleDistributor, type MerkleDistributorAccountTypes, type MerkleDistributorFields, type MerkleDistributorJSON, type NewAlignedDistributorArgs, type NewClaimAccounts, type NewClaimArgs, type NewDistributorAccounts, type NewDistributorArgs, type OracleType, type OracleTypeName, type SetAdminAccounts, type SetClawbackReceiverAccounts, SolanaAlignedDistributorClient, SolanaDistributorClient, applyFeeLogic, calculateAirdropFeeLamports, calculateAmountWithTransferFees, calculateClaimableLamportsFromPrices, calculateDynamicFeeFromSolParams, claimLocked, clawback, closeClaim, constants, fetchAirdropFee, fromCode, fromTxError, getAlignedDistributorPda, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, getTestOraclePda, index as i, isCompressedClaimStatus, newClaim, newDistributor, resolveAirdropFeeLamportsUsingApi, setAdmin, setClawbackReceiver, toLamportsSOL, wrappedSignAndExecuteTransaction };
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PublicKey, TransactionInstruction, Connection, SystemProgram } from '@solana/web3.js';
2
2
  import '@solana/wallet-adapter-base';
3
- import { ICluster, ContractError, divCeilN, invariant, getNumberFromBN, getBN, multiplyBigIntByNumber } from '@streamflow/common';
3
+ import { ICluster, multiplyBigIntByNumber, fetchTokenPrice, ContractError, divCeilN, invariant, getNumberFromBN, getBN } from '@streamflow/common';
4
4
  import { signAndExecuteTransaction, buildSendThrottler, prepareBaseInstructions, getMintAndProgram, ata, prepareWrappedAccount, createAndEstimateTransaction, prepareTransaction, checkOrCreateAtaBatch, pk, unwrapExecutionParams } from '@streamflow/common/solana';
5
5
  import { Program } from '@coral-xyz/anchor';
6
6
  import * as borsh7 from '@coral-xyz/borsh';
@@ -20,10 +20,18 @@ var solana_exports = {};
20
20
  __export(solana_exports, {
21
21
  AnchorErrorCode: () => AnchorErrorCode,
22
22
  ContractErrorCode: () => ContractErrorCode,
23
+ FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR: () => FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR,
24
+ FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR: () => FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR,
25
+ MAXIMUM_FEE_FALLBACK: () => MAXIMUM_FEE_FALLBACK,
26
+ MINIMUM_FEE_FALLBACK: () => MINIMUM_FEE_FALLBACK,
23
27
  MerkleDistributor: () => MerkleDistributor,
24
28
  SolanaAlignedDistributorClient: () => SolanaAlignedDistributorClient,
25
29
  SolanaDistributorClient: () => SolanaDistributorClient,
30
+ applyFeeLogic: () => applyFeeLogic,
31
+ calculateAirdropFeeLamports: () => calculateAirdropFeeLamports,
26
32
  calculateAmountWithTransferFees: () => calculateAmountWithTransferFees,
33
+ calculateClaimableLamportsFromPrices: () => calculateClaimableLamportsFromPrices,
34
+ calculateDynamicFeeFromSolParams: () => calculateDynamicFeeFromSolParams,
27
35
  claimLocked: () => claimLocked,
28
36
  clawback: () => clawback,
29
37
  closeClaim: () => closeClaim,
@@ -31,7 +39,6 @@ __export(solana_exports, {
31
39
  fetchAirdropFee: () => fetchAirdropFee,
32
40
  fromCode: () => fromCode3,
33
41
  fromTxError: () => fromTxError,
34
- getAirdropFeeQueryOptions: () => getAirdropFeeQueryOptions,
35
42
  getAlignedDistributorPda: () => getAlignedDistributorPda,
36
43
  getClaimantStatusPda: () => getClaimantStatusPda,
37
44
  getDistributorPda: () => getDistributorPda,
@@ -40,8 +47,10 @@ __export(solana_exports, {
40
47
  isCompressedClaimStatus: () => isCompressedClaimStatus,
41
48
  newClaim: () => newClaim,
42
49
  newDistributor: () => newDistributor,
50
+ resolveAirdropFeeLamportsUsingApi: () => resolveAirdropFeeLamportsUsingApi,
43
51
  setAdmin: () => setAdmin,
44
52
  setClawbackReceiver: () => setClawbackReceiver,
53
+ toLamportsSOL: () => toLamportsSOL,
45
54
  wrappedSignAndExecuteTransaction: () => wrappedSignAndExecuteTransaction
46
55
  });
47
56
  var AnchorErrorCode = /* @__PURE__ */ ((AnchorErrorCode2) => {
@@ -358,19 +367,6 @@ var fetchAirdropFee = async (distributorId, cluster = ICluster.Mainnet, fetchFn
358
367
  const json = await res.json();
359
368
  return json;
360
369
  };
361
- function getAirdropFeeQueryOptions(params, options) {
362
- const { staleTimeMs = 6e4, gcTimeMs = 3e5, retry = 2, refetchOnWindowFocus = false } = options ?? {};
363
- const cluster = params.cluster ?? ICluster.Mainnet;
364
- const key = ["sf", "airdrop", "fee", cluster, params.distributorId];
365
- return {
366
- queryKey: key,
367
- queryFn: () => fetchAirdropFee(params.distributorId, cluster, params.fetchFn ?? fetch),
368
- staleTime: staleTimeMs,
369
- gcTime: gcTimeMs,
370
- retry,
371
- refetchOnWindowFocus
372
- };
373
- }
374
370
 
375
371
  // solana/fees.ts
376
372
  var MAXIMUM_FEE_FALLBACK = 9900000n;
@@ -412,14 +408,43 @@ var toLamportsSOL = (value, solDecimals = 9) => {
412
408
  const scale = 10n ** BigInt(solDecimals);
413
409
  return multiplyBigIntByNumber(scale, y);
414
410
  };
411
+ var applyFeeLogic = (baseLamports) => {
412
+ if (baseLamports <= 0n) {
413
+ return MINIMUM_FEE_FALLBACK;
414
+ }
415
+ const raw = baseLamports * FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR / FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR;
416
+ if (raw < MINIMUM_FEE_FALLBACK) return MINIMUM_FEE_FALLBACK;
417
+ if (raw > MAXIMUM_FEE_FALLBACK) return MAXIMUM_FEE_FALLBACK;
418
+ return raw;
419
+ };
420
+ async function calculateAirdropFeeLamports(params) {
421
+ const { distributorAddress, client, claimableLamports } = params;
422
+ try {
423
+ if (client) {
424
+ const res = await client.getAirdropFee(distributorAddress);
425
+ const data = res?.data;
426
+ if (data?.isCustom && data.claimFee !== void 0) {
427
+ return toLamportsSOL(data.claimFee);
428
+ }
429
+ if (data?.claimFeeDynamic && claimableLamports !== void 0) {
430
+ const min = toLamportsSOL(data.claimFeeDynamic.minPrice);
431
+ const max = toLamportsSOL(data.claimFeeDynamic.maxPrice);
432
+ const factor = Math.max(0, Math.min(1, parseFloat(data.claimFeeDynamic.allocationFactor)));
433
+ const fee = multiplyBigIntByNumber(claimableLamports, factor);
434
+ if (fee < min) return min;
435
+ if (fee > max) return max;
436
+ return fee;
437
+ }
438
+ }
439
+ } catch (_err) {
440
+ }
441
+ if (claimableLamports !== void 0) {
442
+ return applyFeeLogic(claimableLamports);
443
+ }
444
+ return MINIMUM_FEE_FALLBACK;
445
+ }
415
446
  function calculateClaimableLamportsFromPrices(params) {
416
- const {
417
- claimableAmount,
418
- tokenPriceUsd,
419
- solPriceUsd,
420
- tokenDecimals,
421
- solDecimals = 9
422
- } = params;
447
+ const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
423
448
  if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
424
449
  const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
425
450
  const SCALE = 10n ** BigInt(scaleDigits);
@@ -441,16 +466,8 @@ function calculateDynamicFeeFromSolParams(params) {
441
466
  if (raw > maxLamports) return maxLamports;
442
467
  return raw;
443
468
  }
444
- async function fetchTokenPriceUsd(mintId, cluster, fetchFn = fetch) {
445
- const url = `https://token-api.streamflow.finance/price?ids=${encodeURIComponent(mintId)}&cluster=${encodeURIComponent(cluster)}`;
446
- const res = await fetchFn(url, { headers: { "Content-Type": "application/json" } });
447
- if (!res.ok) return null;
448
- const json = await res.json();
449
- const val = json?.data?.[mintId]?.value;
450
- return typeof val === "number" ? val : null;
451
- }
452
469
  async function resolveAirdropFeeLamportsUsingApi(params) {
453
- const { distributorAddress, mintAccount, claimableAmount, cluster, fetchFn } = params;
470
+ const { distributorAddress, mintAccount, claimableAmount, cluster } = params;
454
471
  let apiFeesResponse = void 0;
455
472
  try {
456
473
  apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster);
@@ -460,8 +477,8 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
460
477
  let tokenPrice = null;
461
478
  try {
462
479
  [solPrice, tokenPrice] = await Promise.all([
463
- fetchTokenPriceUsd("So11111111111111111111111111111111111111112", cluster, fetchFn),
464
- fetchTokenPriceUsd(mintAccount.address.toBase58(), cluster, fetchFn)
480
+ fetchTokenPrice(NATIVE_MINT.toBase58(), cluster),
481
+ fetchTokenPrice(mintAccount.address.toBase58(), cluster)
465
482
  ]);
466
483
  } catch (_) {
467
484
  }
@@ -470,13 +487,13 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
470
487
  return toLamportsSOL(response.claimFee);
471
488
  }
472
489
  const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
473
- if (!tokenPrice || !solPrice) {
490
+ if (!tokenPrice?.value || !solPrice?.value) {
474
491
  return MINIMUM_FEE_FALLBACK;
475
492
  }
476
493
  const baseLamports = calculateClaimableLamportsFromPrices({
477
494
  claimableAmount,
478
- tokenPriceUsd: tokenPrice,
479
- solPriceUsd: solPrice,
495
+ tokenPriceUsd: tokenPrice.value,
496
+ solPriceUsd: solPrice.value,
480
497
  tokenDecimals: mintAccount.decimals
481
498
  });
482
499
  return calculateDynamicFeeFromSolParams({
@@ -3749,10 +3766,17 @@ var BaseDistributorClient = class {
3749
3766
  if (!feeLamports) {
3750
3767
  try {
3751
3768
  const { mint: mintAccount } = await getMintAndProgram(this.connection, distributor.mint);
3769
+ const claimableAmountRaw = data?.claimableAmount;
3770
+ const unlockedRaw = data?.amountUnlocked;
3771
+ const lockedRaw = data?.amountLocked;
3772
+ const unlocked = unlockedRaw != null ? new BN5(unlockedRaw) : new BN5(0);
3773
+ const locked = lockedRaw != null ? new BN5(lockedRaw) : new BN5(0);
3774
+ const computedFallback = unlocked.add(locked);
3775
+ const claimableAmount = claimableAmountRaw != null ? BigInt(claimableAmountRaw.toString()) : BigInt(computedFallback.toString());
3752
3776
  feeLamports = await resolveAirdropFeeLamportsUsingApi({
3753
3777
  distributorAddress: distributorPublicKey.toBase58(),
3754
3778
  mintAccount,
3755
- claimableAmount: BigInt(data.claimableAmount.toString()),
3779
+ claimableAmount,
3756
3780
  cluster: this.cluster
3757
3781
  });
3758
3782
  } catch (_) {