@streamflow/distributor 9.0.0-alpha.0 → 9.0.0-alpha.p308.791571f

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 };
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, 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';
@@ -31,7 +31,6 @@ __export(solana_exports, {
31
31
  fetchAirdropFee: () => fetchAirdropFee,
32
32
  fromCode: () => fromCode3,
33
33
  fromTxError: () => fromTxError,
34
- getAirdropFeeQueryOptions: () => getAirdropFeeQueryOptions,
35
34
  getAlignedDistributorPda: () => getAlignedDistributorPda,
36
35
  getClaimantStatusPda: () => getClaimantStatusPda,
37
36
  getDistributorPda: () => getDistributorPda,
@@ -358,19 +357,6 @@ var fetchAirdropFee = async (distributorId, cluster = ICluster.Mainnet, fetchFn
358
357
  const json = await res.json();
359
358
  return json;
360
359
  };
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
360
 
375
361
  // solana/fees.ts
376
362
  var MAXIMUM_FEE_FALLBACK = 9900000n;
@@ -413,13 +399,7 @@ var toLamportsSOL = (value, solDecimals = 9) => {
413
399
  return multiplyBigIntByNumber(scale, y);
414
400
  };
415
401
  function calculateClaimableLamportsFromPrices(params) {
416
- const {
417
- claimableAmount,
418
- tokenPriceUsd,
419
- solPriceUsd,
420
- tokenDecimals,
421
- solDecimals = 9
422
- } = params;
402
+ const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
423
403
  if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
424
404
  const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
425
405
  const SCALE = 10n ** BigInt(scaleDigits);
@@ -441,16 +421,8 @@ function calculateDynamicFeeFromSolParams(params) {
441
421
  if (raw > maxLamports) return maxLamports;
442
422
  return raw;
443
423
  }
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
424
  async function resolveAirdropFeeLamportsUsingApi(params) {
453
- const { distributorAddress, mintAccount, claimableAmount, cluster, fetchFn } = params;
425
+ const { distributorAddress, mintAccount, claimableAmount, cluster } = params;
454
426
  let apiFeesResponse = void 0;
455
427
  try {
456
428
  apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster);
@@ -460,8 +432,8 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
460
432
  let tokenPrice = null;
461
433
  try {
462
434
  [solPrice, tokenPrice] = await Promise.all([
463
- fetchTokenPriceUsd("So11111111111111111111111111111111111111112", cluster, fetchFn),
464
- fetchTokenPriceUsd(mintAccount.address.toBase58(), cluster, fetchFn)
435
+ fetchTokenPrice(NATIVE_MINT.toBase58(), cluster),
436
+ fetchTokenPrice(mintAccount.address.toBase58(), cluster)
465
437
  ]);
466
438
  } catch (_) {
467
439
  }
@@ -470,13 +442,13 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
470
442
  return toLamportsSOL(response.claimFee);
471
443
  }
472
444
  const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
473
- if (!tokenPrice || !solPrice) {
445
+ if (!tokenPrice?.value || !solPrice?.value) {
474
446
  return MINIMUM_FEE_FALLBACK;
475
447
  }
476
448
  const baseLamports = calculateClaimableLamportsFromPrices({
477
449
  claimableAmount,
478
- tokenPriceUsd: tokenPrice,
479
- solPriceUsd: solPrice,
450
+ tokenPriceUsd: tokenPrice.value,
451
+ solPriceUsd: solPrice.value,
480
452
  tokenDecimals: mintAccount.decimals
481
453
  });
482
454
  return calculateDynamicFeeFromSolParams({
@@ -3749,10 +3721,17 @@ var BaseDistributorClient = class {
3749
3721
  if (!feeLamports) {
3750
3722
  try {
3751
3723
  const { mint: mintAccount } = await getMintAndProgram(this.connection, distributor.mint);
3724
+ const claimableAmountRaw = data?.claimableAmount;
3725
+ const unlockedRaw = data?.amountUnlocked;
3726
+ const lockedRaw = data?.amountLocked;
3727
+ const unlocked = unlockedRaw != null ? new BN5(unlockedRaw) : new BN5(0);
3728
+ const locked = lockedRaw != null ? new BN5(lockedRaw) : new BN5(0);
3729
+ const computedFallback = unlocked.add(locked);
3730
+ const claimableAmount = claimableAmountRaw != null ? BigInt(claimableAmountRaw.toString()) : BigInt(computedFallback.toString());
3752
3731
  feeLamports = await resolveAirdropFeeLamportsUsingApi({
3753
3732
  distributorAddress: distributorPublicKey.toBase58(),
3754
3733
  mintAccount,
3755
- claimableAmount: BigInt(data.claimableAmount.toString()),
3734
+ claimableAmount,
3756
3735
  cluster: this.cluster
3757
3736
  });
3758
3737
  } catch (_) {