@streamflow/distributor 9.0.0 → 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
  /**
@@ -1396,8 +1396,68 @@ interface AirdropFeeQueryOptionsOverrides {
1396
1396
  }
1397
1397
  declare const fetchAirdropFee: (distributorId: string, cluster?: ICluster, fetchFn?: typeof fetch) => Promise<AirdropFeeResponse>;
1398
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;
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>;
1455
+
1456
+ type index_AirdropFeeClient = AirdropFeeClient;
1457
+ type index_AirdropFeeDynamic = AirdropFeeDynamic;
1399
1458
  type index_AirdropFeeQueryOptionsOverrides = AirdropFeeQueryOptionsOverrides;
1400
1459
  type index_AirdropFeeResponse = AirdropFeeResponse;
1460
+ type index_AirdropFeeServiceResponse = AirdropFeeServiceResponse;
1401
1461
  type index_AlignedDistributorData = AlignedDistributorData;
1402
1462
  type index_AnchorErrorCode = AnchorErrorCode;
1403
1463
  declare const index_AnchorErrorCode: typeof AnchorErrorCode;
@@ -1409,6 +1469,8 @@ type index_CloseClaimAccounts = CloseClaimAccounts;
1409
1469
  type index_CompressedClaimStatus = CompressedClaimStatus;
1410
1470
  type index_ContractErrorCode = ContractErrorCode;
1411
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;
1412
1474
  type index_IClaimData = IClaimData;
1413
1475
  type index_IClawbackData = IClawbackData;
1414
1476
  type index_ICloseClaimData = ICloseClaimData;
@@ -1422,6 +1484,8 @@ type index_IInteractSolanaExt = IInteractSolanaExt;
1422
1484
  type index_ISearchDistributors = ISearchDistributors;
1423
1485
  type index_ISetClawbackReceiverData = ISetClawbackReceiverData;
1424
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;
1425
1489
  type index_MerkleDistributor = MerkleDistributor;
1426
1490
  declare const index_MerkleDistributor: typeof MerkleDistributor;
1427
1491
  type index_MerkleDistributorAccountTypes = MerkleDistributorAccountTypes;
@@ -1440,7 +1504,11 @@ type index_SolanaAlignedDistributorClient = SolanaAlignedDistributorClient;
1440
1504
  declare const index_SolanaAlignedDistributorClient: typeof SolanaAlignedDistributorClient;
1441
1505
  type index_SolanaDistributorClient = SolanaDistributorClient;
1442
1506
  declare const index_SolanaDistributorClient: typeof SolanaDistributorClient;
1507
+ declare const index_applyFeeLogic: typeof applyFeeLogic;
1508
+ declare const index_calculateAirdropFeeLamports: typeof calculateAirdropFeeLamports;
1443
1509
  declare const index_calculateAmountWithTransferFees: typeof calculateAmountWithTransferFees;
1510
+ declare const index_calculateClaimableLamportsFromPrices: typeof calculateClaimableLamportsFromPrices;
1511
+ declare const index_calculateDynamicFeeFromSolParams: typeof calculateDynamicFeeFromSolParams;
1444
1512
  declare const index_claimLocked: typeof claimLocked;
1445
1513
  declare const index_clawback: typeof clawback;
1446
1514
  declare const index_closeClaim: typeof closeClaim;
@@ -1456,11 +1524,13 @@ declare const index_getTestOraclePda: typeof getTestOraclePda;
1456
1524
  declare const index_isCompressedClaimStatus: typeof isCompressedClaimStatus;
1457
1525
  declare const index_newClaim: typeof newClaim;
1458
1526
  declare const index_newDistributor: typeof newDistributor;
1527
+ declare const index_resolveAirdropFeeLamportsUsingApi: typeof resolveAirdropFeeLamportsUsingApi;
1459
1528
  declare const index_setAdmin: typeof setAdmin;
1460
1529
  declare const index_setClawbackReceiver: typeof setClawbackReceiver;
1530
+ declare const index_toLamportsSOL: typeof toLamportsSOL;
1461
1531
  declare const index_wrappedSignAndExecuteTransaction: typeof wrappedSignAndExecuteTransaction;
1462
1532
  declare namespace index {
1463
- 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_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 };
1464
1534
  }
1465
1535
 
1466
- 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, 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, fetchTokenPrice, 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';
@@ -369,6 +369,41 @@ var toLamportsSOL = (value, solDecimals = 9) => {
369
369
  const scale = 10n ** BigInt(solDecimals);
370
370
  return multiplyBigIntByNumber(scale, y);
371
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
+ }
372
407
  function calculateClaimableLamportsFromPrices(params) {
373
408
  const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
374
409
  if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
@@ -5573,6 +5608,6 @@ var SolanaAlignedDistributorClient = class extends BaseDistributorClient {
5573
5608
  }
5574
5609
  };
5575
5610
 
5576
- export { AnchorErrorCode, ContractErrorCode, MerkleDistributor, SolanaAlignedDistributorClient, SolanaDistributorClient, calculateAmountWithTransferFees, claimLocked, clawback, closeClaim, constants_exports as constants, fetchAirdropFee, fromCode3 as fromCode, fromTxError, 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 };
5577
5612
  //# sourceMappingURL=index.js.map
5578
5613
  //# sourceMappingURL=index.js.map