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

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.
@@ -1388,26 +1388,13 @@ 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;
1410
- };
1397
+ declare const fetchAirdropFee: (distributorId: string, cluster?: ICluster, fetchFn?: typeof fetch) => Promise<AirdropFeeResponse>;
1411
1398
 
1412
1399
  type index_AirdropFeeQueryOptionsOverrides = AirdropFeeQueryOptionsOverrides;
1413
1400
  type index_AirdropFeeResponse = AirdropFeeResponse;
@@ -1461,7 +1448,6 @@ declare const index_constants: typeof constants;
1461
1448
  declare const index_fetchAirdropFee: typeof fetchAirdropFee;
1462
1449
  declare const index_fromCode: typeof fromCode;
1463
1450
  declare const index_fromTxError: typeof fromTxError;
1464
- declare const index_getAirdropFeeQueryOptions: typeof getAirdropFeeQueryOptions;
1465
1451
  declare const index_getAlignedDistributorPda: typeof getAlignedDistributorPda;
1466
1452
  declare const index_getClaimantStatusPda: typeof getClaimantStatusPda;
1467
1453
  declare const index_getDistributorPda: typeof getDistributorPda;
@@ -1474,7 +1460,7 @@ declare const index_setAdmin: typeof setAdmin;
1474
1460
  declare const index_setClawbackReceiver: typeof setClawbackReceiver;
1475
1461
  declare const index_wrappedSignAndExecuteTransaction: typeof wrappedSignAndExecuteTransaction;
1476
1462
  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 };
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 };
1478
1464
  }
1479
1465
 
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 };
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 };
@@ -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, ContractError, divCeilN, invariant, getNumberFromBN, getBN, fetchTokenPrice, multiplyBigIntByNumber } 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;
@@ -383,13 +370,7 @@ var toLamportsSOL = (value, solDecimals = 9) => {
383
370
  return multiplyBigIntByNumber(scale, y);
384
371
  };
385
372
  function calculateClaimableLamportsFromPrices(params) {
386
- const {
387
- claimableAmount,
388
- tokenPriceUsd,
389
- solPriceUsd,
390
- tokenDecimals,
391
- solDecimals = 9
392
- } = params;
373
+ const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
393
374
  if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
394
375
  const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
395
376
  const SCALE = 10n ** BigInt(scaleDigits);
@@ -411,16 +392,8 @@ function calculateDynamicFeeFromSolParams(params) {
411
392
  if (raw > maxLamports) return maxLamports;
412
393
  return raw;
413
394
  }
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
395
  async function resolveAirdropFeeLamportsUsingApi(params) {
423
- const { distributorAddress, mintAccount, claimableAmount, cluster, fetchFn } = params;
396
+ const { distributorAddress, mintAccount, claimableAmount, cluster } = params;
424
397
  let apiFeesResponse = void 0;
425
398
  try {
426
399
  apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster);
@@ -430,8 +403,8 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
430
403
  let tokenPrice = null;
431
404
  try {
432
405
  [solPrice, tokenPrice] = await Promise.all([
433
- fetchTokenPriceUsd("So11111111111111111111111111111111111111112", cluster, fetchFn),
434
- fetchTokenPriceUsd(mintAccount.address.toBase58(), cluster, fetchFn)
406
+ fetchTokenPrice(NATIVE_MINT.toBase58(), cluster),
407
+ fetchTokenPrice(mintAccount.address.toBase58(), cluster)
435
408
  ]);
436
409
  } catch (_) {
437
410
  }
@@ -440,13 +413,13 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
440
413
  return toLamportsSOL(response.claimFee);
441
414
  }
442
415
  const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
443
- if (!tokenPrice || !solPrice) {
416
+ if (!tokenPrice?.value || !solPrice?.value) {
444
417
  return MINIMUM_FEE_FALLBACK;
445
418
  }
446
419
  const baseLamports = calculateClaimableLamportsFromPrices({
447
420
  claimableAmount,
448
- tokenPriceUsd: tokenPrice,
449
- solPriceUsd: solPrice,
421
+ tokenPriceUsd: tokenPrice.value,
422
+ solPriceUsd: solPrice.value,
450
423
  tokenDecimals: mintAccount.decimals
451
424
  });
452
425
  return calculateDynamicFeeFromSolParams({
@@ -3719,10 +3692,17 @@ var BaseDistributorClient = class {
3719
3692
  if (!feeLamports) {
3720
3693
  try {
3721
3694
  const { mint: mintAccount } = await getMintAndProgram(this.connection, distributor.mint);
3695
+ const claimableAmountRaw = data?.claimableAmount;
3696
+ const unlockedRaw = data?.amountUnlocked;
3697
+ const lockedRaw = data?.amountLocked;
3698
+ const unlocked = unlockedRaw != null ? new BN5(unlockedRaw) : new BN5(0);
3699
+ const locked = lockedRaw != null ? new BN5(lockedRaw) : new BN5(0);
3700
+ const computedFallback = unlocked.add(locked);
3701
+ const claimableAmount = claimableAmountRaw != null ? BigInt(claimableAmountRaw.toString()) : BigInt(computedFallback.toString());
3722
3702
  feeLamports = await resolveAirdropFeeLamportsUsingApi({
3723
3703
  distributorAddress: distributorPublicKey.toBase58(),
3724
3704
  mintAccount,
3725
- claimableAmount: BigInt(data.claimableAmount.toString()),
3705
+ claimableAmount,
3726
3706
  cluster: this.cluster
3727
3707
  });
3728
3708
  } catch (_) {
@@ -5593,6 +5573,6 @@ var SolanaAlignedDistributorClient = class extends BaseDistributorClient {
5593
5573
  }
5594
5574
  };
5595
5575
 
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 };
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 };
5597
5577
  //# sourceMappingURL=index.js.map
5598
5578
  //# sourceMappingURL=index.js.map