@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.
@@ -354,19 +354,6 @@ var fetchAirdropFee = async (distributorId, cluster = common.ICluster.Mainnet, f
354
354
  const json = await res.json();
355
355
  return json;
356
356
  };
357
- function getAirdropFeeQueryOptions(params, options) {
358
- const { staleTimeMs = 6e4, gcTimeMs = 3e5, retry = 2, refetchOnWindowFocus = false } = options ?? {};
359
- const cluster = params.cluster ?? common.ICluster.Mainnet;
360
- const key = ["sf", "airdrop", "fee", cluster, params.distributorId];
361
- return {
362
- queryKey: key,
363
- queryFn: () => fetchAirdropFee(params.distributorId, cluster, params.fetchFn ?? fetch),
364
- staleTime: staleTimeMs,
365
- gcTime: gcTimeMs,
366
- retry,
367
- refetchOnWindowFocus
368
- };
369
- }
370
357
 
371
358
  // solana/fees.ts
372
359
  var MAXIMUM_FEE_FALLBACK = 9900000n;
@@ -409,13 +396,7 @@ var toLamportsSOL = (value, solDecimals = 9) => {
409
396
  return common.multiplyBigIntByNumber(scale, y);
410
397
  };
411
398
  function calculateClaimableLamportsFromPrices(params) {
412
- const {
413
- claimableAmount,
414
- tokenPriceUsd,
415
- solPriceUsd,
416
- tokenDecimals,
417
- solDecimals = 9
418
- } = params;
399
+ const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
419
400
  if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
420
401
  const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
421
402
  const SCALE = 10n ** BigInt(scaleDigits);
@@ -437,16 +418,8 @@ function calculateDynamicFeeFromSolParams(params) {
437
418
  if (raw > maxLamports) return maxLamports;
438
419
  return raw;
439
420
  }
440
- async function fetchTokenPriceUsd(mintId, cluster, fetchFn = fetch) {
441
- const url = `https://token-api.streamflow.finance/price?ids=${encodeURIComponent(mintId)}&cluster=${encodeURIComponent(cluster)}`;
442
- const res = await fetchFn(url, { headers: { "Content-Type": "application/json" } });
443
- if (!res.ok) return null;
444
- const json = await res.json();
445
- const val = json?.data?.[mintId]?.value;
446
- return typeof val === "number" ? val : null;
447
- }
448
421
  async function resolveAirdropFeeLamportsUsingApi(params) {
449
- const { distributorAddress, mintAccount, claimableAmount, cluster, fetchFn } = params;
422
+ const { distributorAddress, mintAccount, claimableAmount, cluster } = params;
450
423
  let apiFeesResponse = void 0;
451
424
  try {
452
425
  apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster);
@@ -456,8 +429,8 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
456
429
  let tokenPrice = null;
457
430
  try {
458
431
  [solPrice, tokenPrice] = await Promise.all([
459
- fetchTokenPriceUsd("So11111111111111111111111111111111111111112", cluster, fetchFn),
460
- fetchTokenPriceUsd(mintAccount.address.toBase58(), cluster, fetchFn)
432
+ common.fetchTokenPrice(splToken.NATIVE_MINT.toBase58(), cluster),
433
+ common.fetchTokenPrice(mintAccount.address.toBase58(), cluster)
461
434
  ]);
462
435
  } catch (_) {
463
436
  }
@@ -466,13 +439,13 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
466
439
  return toLamportsSOL(response.claimFee);
467
440
  }
468
441
  const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
469
- if (!tokenPrice || !solPrice) {
442
+ if (!tokenPrice?.value || !solPrice?.value) {
470
443
  return MINIMUM_FEE_FALLBACK;
471
444
  }
472
445
  const baseLamports = calculateClaimableLamportsFromPrices({
473
446
  claimableAmount,
474
- tokenPriceUsd: tokenPrice,
475
- solPriceUsd: solPrice,
447
+ tokenPriceUsd: tokenPrice.value,
448
+ solPriceUsd: solPrice.value,
476
449
  tokenDecimals: mintAccount.decimals
477
450
  });
478
451
  return calculateDynamicFeeFromSolParams({
@@ -3745,10 +3718,17 @@ var BaseDistributorClient = class {
3745
3718
  if (!feeLamports) {
3746
3719
  try {
3747
3720
  const { mint: mintAccount } = await solana.getMintAndProgram(this.connection, distributor.mint);
3721
+ const claimableAmountRaw = data?.claimableAmount;
3722
+ const unlockedRaw = data?.amountUnlocked;
3723
+ const lockedRaw = data?.amountLocked;
3724
+ const unlocked = unlockedRaw != null ? new BN5__default.default(unlockedRaw) : new BN5__default.default(0);
3725
+ const locked = lockedRaw != null ? new BN5__default.default(lockedRaw) : new BN5__default.default(0);
3726
+ const computedFallback = unlocked.add(locked);
3727
+ const claimableAmount = claimableAmountRaw != null ? BigInt(claimableAmountRaw.toString()) : BigInt(computedFallback.toString());
3748
3728
  feeLamports = await resolveAirdropFeeLamportsUsingApi({
3749
3729
  distributorAddress: distributorPublicKey.toBase58(),
3750
3730
  mintAccount,
3751
- claimableAmount: BigInt(data.claimableAmount.toString()),
3731
+ claimableAmount,
3752
3732
  cluster: this.cluster
3753
3733
  });
3754
3734
  } catch (_) {
@@ -5632,7 +5612,6 @@ exports.constants = constants_exports;
5632
5612
  exports.fetchAirdropFee = fetchAirdropFee;
5633
5613
  exports.fromCode = fromCode3;
5634
5614
  exports.fromTxError = fromTxError;
5635
- exports.getAirdropFeeQueryOptions = getAirdropFeeQueryOptions;
5636
5615
  exports.getAlignedDistributorPda = getAlignedDistributorPda;
5637
5616
  exports.getClaimantStatusPda = getClaimantStatusPda;
5638
5617
  exports.getDistributorPda = getDistributorPda;