@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.js';
8
8
  import { MerkleDistributor as MerkleDistributor$1 } from './descriptor/merkle_distributor.js';
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 };
@@ -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';
@@ -328,19 +328,6 @@ var fetchAirdropFee = async (distributorId, cluster = ICluster.Mainnet, fetchFn
328
328
  const json = await res.json();
329
329
  return json;
330
330
  };
331
- function getAirdropFeeQueryOptions(params, options) {
332
- const { staleTimeMs = 6e4, gcTimeMs = 3e5, retry = 2, refetchOnWindowFocus = false } = options ?? {};
333
- const cluster = params.cluster ?? ICluster.Mainnet;
334
- const key = ["sf", "airdrop", "fee", cluster, params.distributorId];
335
- return {
336
- queryKey: key,
337
- queryFn: () => fetchAirdropFee(params.distributorId, cluster, params.fetchFn ?? fetch),
338
- staleTime: staleTimeMs,
339
- gcTime: gcTimeMs,
340
- retry,
341
- refetchOnWindowFocus
342
- };
343
- }
344
331
 
345
332
  // solana/fees.ts
346
333
  var MAXIMUM_FEE_FALLBACK = 9900000n;
@@ -382,14 +369,43 @@ var toLamportsSOL = (value, solDecimals = 9) => {
382
369
  const scale = 10n ** BigInt(solDecimals);
383
370
  return multiplyBigIntByNumber(scale, y);
384
371
  };
372
+ var applyFeeLogic = (baseLamports) => {
373
+ if (baseLamports <= 0n) {
374
+ return MINIMUM_FEE_FALLBACK;
375
+ }
376
+ const raw = baseLamports * FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR / FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR;
377
+ if (raw < MINIMUM_FEE_FALLBACK) return MINIMUM_FEE_FALLBACK;
378
+ if (raw > MAXIMUM_FEE_FALLBACK) return MAXIMUM_FEE_FALLBACK;
379
+ return raw;
380
+ };
381
+ async function calculateAirdropFeeLamports(params) {
382
+ const { distributorAddress, client, claimableLamports } = params;
383
+ try {
384
+ if (client) {
385
+ const res = await client.getAirdropFee(distributorAddress);
386
+ const data = res?.data;
387
+ if (data?.isCustom && data.claimFee !== void 0) {
388
+ return toLamportsSOL(data.claimFee);
389
+ }
390
+ if (data?.claimFeeDynamic && claimableLamports !== void 0) {
391
+ const min = toLamportsSOL(data.claimFeeDynamic.minPrice);
392
+ const max = toLamportsSOL(data.claimFeeDynamic.maxPrice);
393
+ const factor = Math.max(0, Math.min(1, parseFloat(data.claimFeeDynamic.allocationFactor)));
394
+ const fee = multiplyBigIntByNumber(claimableLamports, factor);
395
+ if (fee < min) return min;
396
+ if (fee > max) return max;
397
+ return fee;
398
+ }
399
+ }
400
+ } catch (_err) {
401
+ }
402
+ if (claimableLamports !== void 0) {
403
+ return applyFeeLogic(claimableLamports);
404
+ }
405
+ return MINIMUM_FEE_FALLBACK;
406
+ }
385
407
  function calculateClaimableLamportsFromPrices(params) {
386
- const {
387
- claimableAmount,
388
- tokenPriceUsd,
389
- solPriceUsd,
390
- tokenDecimals,
391
- solDecimals = 9
392
- } = params;
408
+ const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
393
409
  if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
394
410
  const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
395
411
  const SCALE = 10n ** BigInt(scaleDigits);
@@ -411,16 +427,8 @@ function calculateDynamicFeeFromSolParams(params) {
411
427
  if (raw > maxLamports) return maxLamports;
412
428
  return raw;
413
429
  }
414
- async function fetchTokenPriceUsd(mintId, cluster, fetchFn = fetch) {
415
- const url = `https://token-api.streamflow.finance/price?ids=${encodeURIComponent(mintId)}&cluster=${encodeURIComponent(cluster)}`;
416
- const res = await fetchFn(url, { headers: { "Content-Type": "application/json" } });
417
- if (!res.ok) return null;
418
- const json = await res.json();
419
- const val = json?.data?.[mintId]?.value;
420
- return typeof val === "number" ? val : null;
421
- }
422
430
  async function resolveAirdropFeeLamportsUsingApi(params) {
423
- const { distributorAddress, mintAccount, claimableAmount, cluster, fetchFn } = params;
431
+ const { distributorAddress, mintAccount, claimableAmount, cluster } = params;
424
432
  let apiFeesResponse = void 0;
425
433
  try {
426
434
  apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster);
@@ -430,8 +438,8 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
430
438
  let tokenPrice = null;
431
439
  try {
432
440
  [solPrice, tokenPrice] = await Promise.all([
433
- fetchTokenPriceUsd("So11111111111111111111111111111111111111112", cluster, fetchFn),
434
- fetchTokenPriceUsd(mintAccount.address.toBase58(), cluster, fetchFn)
441
+ fetchTokenPrice(NATIVE_MINT.toBase58(), cluster),
442
+ fetchTokenPrice(mintAccount.address.toBase58(), cluster)
435
443
  ]);
436
444
  } catch (_) {
437
445
  }
@@ -440,13 +448,13 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
440
448
  return toLamportsSOL(response.claimFee);
441
449
  }
442
450
  const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
443
- if (!tokenPrice || !solPrice) {
451
+ if (!tokenPrice?.value || !solPrice?.value) {
444
452
  return MINIMUM_FEE_FALLBACK;
445
453
  }
446
454
  const baseLamports = calculateClaimableLamportsFromPrices({
447
455
  claimableAmount,
448
- tokenPriceUsd: tokenPrice,
449
- solPriceUsd: solPrice,
456
+ tokenPriceUsd: tokenPrice.value,
457
+ solPriceUsd: solPrice.value,
450
458
  tokenDecimals: mintAccount.decimals
451
459
  });
452
460
  return calculateDynamicFeeFromSolParams({
@@ -3719,10 +3727,17 @@ var BaseDistributorClient = class {
3719
3727
  if (!feeLamports) {
3720
3728
  try {
3721
3729
  const { mint: mintAccount } = await getMintAndProgram(this.connection, distributor.mint);
3730
+ const claimableAmountRaw = data?.claimableAmount;
3731
+ const unlockedRaw = data?.amountUnlocked;
3732
+ const lockedRaw = data?.amountLocked;
3733
+ const unlocked = unlockedRaw != null ? new BN5(unlockedRaw) : new BN5(0);
3734
+ const locked = lockedRaw != null ? new BN5(lockedRaw) : new BN5(0);
3735
+ const computedFallback = unlocked.add(locked);
3736
+ const claimableAmount = claimableAmountRaw != null ? BigInt(claimableAmountRaw.toString()) : BigInt(computedFallback.toString());
3722
3737
  feeLamports = await resolveAirdropFeeLamportsUsingApi({
3723
3738
  distributorAddress: distributorPublicKey.toBase58(),
3724
3739
  mintAccount,
3725
- claimableAmount: BigInt(data.claimableAmount.toString()),
3740
+ claimableAmount,
3726
3741
  cluster: this.cluster
3727
3742
  });
3728
3743
  } catch (_) {
@@ -5593,6 +5608,6 @@ var SolanaAlignedDistributorClient = class extends BaseDistributorClient {
5593
5608
  }
5594
5609
  };
5595
5610
 
5596
- export { AnchorErrorCode, ContractErrorCode, MerkleDistributor, SolanaAlignedDistributorClient, SolanaDistributorClient, calculateAmountWithTransferFees, claimLocked, clawback, closeClaim, constants_exports as constants, fetchAirdropFee, fromCode3 as fromCode, fromTxError, getAirdropFeeQueryOptions, getAlignedDistributorPda, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, getTestOraclePda, isCompressedClaimStatus, newClaim, newDistributor, setAdmin, setClawbackReceiver, wrappedSignAndExecuteTransaction };
5611
+ export { AnchorErrorCode, ContractErrorCode, FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR, FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR, MAXIMUM_FEE_FALLBACK, MINIMUM_FEE_FALLBACK, MerkleDistributor, SolanaAlignedDistributorClient, SolanaDistributorClient, applyFeeLogic, calculateAirdropFeeLamports, calculateAmountWithTransferFees, calculateClaimableLamportsFromPrices, calculateDynamicFeeFromSolParams, claimLocked, clawback, closeClaim, constants_exports as constants, fetchAirdropFee, fromCode3 as fromCode, fromTxError, getAlignedDistributorPda, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, getTestOraclePda, isCompressedClaimStatus, newClaim, newDistributor, resolveAirdropFeeLamportsUsingApi, setAdmin, setClawbackReceiver, toLamportsSOL, wrappedSignAndExecuteTransaction };
5597
5612
  //# sourceMappingURL=index.js.map
5598
5613
  //# sourceMappingURL=index.js.map