@streamflow/distributor 9.0.0 → 9.0.2

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.
@@ -46,10 +46,18 @@ var solana_exports = {};
46
46
  __export(solana_exports, {
47
47
  AnchorErrorCode: () => AnchorErrorCode,
48
48
  ContractErrorCode: () => ContractErrorCode,
49
+ FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR: () => FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR,
50
+ FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR: () => FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR,
51
+ MAXIMUM_FEE_FALLBACK: () => MAXIMUM_FEE_FALLBACK,
52
+ MINIMUM_FEE_FALLBACK: () => MINIMUM_FEE_FALLBACK,
49
53
  MerkleDistributor: () => MerkleDistributor,
50
54
  SolanaAlignedDistributorClient: () => SolanaAlignedDistributorClient,
51
55
  SolanaDistributorClient: () => SolanaDistributorClient,
56
+ applyFeeLogic: () => applyFeeLogic,
57
+ calculateAirdropFeeLamports: () => calculateAirdropFeeLamports,
52
58
  calculateAmountWithTransferFees: () => calculateAmountWithTransferFees,
59
+ calculateClaimableLamportsFromPrices: () => calculateClaimableLamportsFromPrices,
60
+ calculateDynamicFeeFromSolParams: () => calculateDynamicFeeFromSolParams,
53
61
  claimLocked: () => claimLocked,
54
62
  clawback: () => clawback,
55
63
  closeClaim: () => closeClaim,
@@ -65,8 +73,10 @@ __export(solana_exports, {
65
73
  isCompressedClaimStatus: () => isCompressedClaimStatus,
66
74
  newClaim: () => newClaim,
67
75
  newDistributor: () => newDistributor,
76
+ resolveAirdropFeeLamportsUsingApi: () => resolveAirdropFeeLamportsUsingApi,
68
77
  setAdmin: () => setAdmin,
69
78
  setClawbackReceiver: () => setClawbackReceiver,
79
+ toLamportsSOL: () => toLamportsSOL,
70
80
  wrappedSignAndExecuteTransaction: () => wrappedSignAndExecuteTransaction
71
81
  });
72
82
  var AnchorErrorCode = /* @__PURE__ */ ((AnchorErrorCode2) => {
@@ -424,6 +434,41 @@ var toLamportsSOL = (value, solDecimals = 9) => {
424
434
  const scale = 10n ** BigInt(solDecimals);
425
435
  return common.multiplyBigIntByNumber(scale, y);
426
436
  };
437
+ var applyFeeLogic = (baseLamports) => {
438
+ if (baseLamports <= 0n) {
439
+ return MINIMUM_FEE_FALLBACK;
440
+ }
441
+ const raw = baseLamports * FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR / FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR;
442
+ if (raw < MINIMUM_FEE_FALLBACK) return MINIMUM_FEE_FALLBACK;
443
+ if (raw > MAXIMUM_FEE_FALLBACK) return MAXIMUM_FEE_FALLBACK;
444
+ return raw;
445
+ };
446
+ async function calculateAirdropFeeLamports(params) {
447
+ const { distributorAddress, client, claimableLamports } = params;
448
+ try {
449
+ if (client) {
450
+ const res = await client.getAirdropFee(distributorAddress);
451
+ const data = res?.data;
452
+ if (data?.isCustom && data.claimFee !== void 0) {
453
+ return toLamportsSOL(data.claimFee);
454
+ }
455
+ if (data?.claimFeeDynamic && claimableLamports !== void 0) {
456
+ const min = toLamportsSOL(data.claimFeeDynamic.minPrice);
457
+ const max = toLamportsSOL(data.claimFeeDynamic.maxPrice);
458
+ const factor = Math.max(0, Math.min(1, parseFloat(data.claimFeeDynamic.allocationFactor)));
459
+ const fee = common.multiplyBigIntByNumber(claimableLamports, factor);
460
+ if (fee < min) return min;
461
+ if (fee > max) return max;
462
+ return fee;
463
+ }
464
+ }
465
+ } catch (_err) {
466
+ }
467
+ if (claimableLamports !== void 0) {
468
+ return applyFeeLogic(claimableLamports);
469
+ }
470
+ return MINIMUM_FEE_FALLBACK;
471
+ }
427
472
  function calculateClaimableLamportsFromPrices(params) {
428
473
  const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
429
474
  if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;