@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.
- package/dist/cjs/index.cjs +15 -36
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/solana/index.cjs +15 -36
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +3 -17
- package/dist/esm/index.js +16 -37
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +3 -17
- package/dist/esm/solana/index.js +17 -37
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cjs/index.cjs
CHANGED
|
@@ -57,7 +57,6 @@ __export(solana_exports, {
|
|
|
57
57
|
fetchAirdropFee: () => fetchAirdropFee,
|
|
58
58
|
fromCode: () => fromCode3,
|
|
59
59
|
fromTxError: () => fromTxError,
|
|
60
|
-
getAirdropFeeQueryOptions: () => getAirdropFeeQueryOptions,
|
|
61
60
|
getAlignedDistributorPda: () => getAlignedDistributorPda,
|
|
62
61
|
getClaimantStatusPda: () => getClaimantStatusPda,
|
|
63
62
|
getDistributorPda: () => getDistributorPda,
|
|
@@ -384,19 +383,6 @@ var fetchAirdropFee = async (distributorId, cluster = common.ICluster.Mainnet, f
|
|
|
384
383
|
const json = await res.json();
|
|
385
384
|
return json;
|
|
386
385
|
};
|
|
387
|
-
function getAirdropFeeQueryOptions(params, options) {
|
|
388
|
-
const { staleTimeMs = 6e4, gcTimeMs = 3e5, retry = 2, refetchOnWindowFocus = false } = options ?? {};
|
|
389
|
-
const cluster = params.cluster ?? common.ICluster.Mainnet;
|
|
390
|
-
const key = ["sf", "airdrop", "fee", cluster, params.distributorId];
|
|
391
|
-
return {
|
|
392
|
-
queryKey: key,
|
|
393
|
-
queryFn: () => fetchAirdropFee(params.distributorId, cluster, params.fetchFn ?? fetch),
|
|
394
|
-
staleTime: staleTimeMs,
|
|
395
|
-
gcTime: gcTimeMs,
|
|
396
|
-
retry,
|
|
397
|
-
refetchOnWindowFocus
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
386
|
|
|
401
387
|
// solana/fees.ts
|
|
402
388
|
var MAXIMUM_FEE_FALLBACK = 9900000n;
|
|
@@ -439,13 +425,7 @@ var toLamportsSOL = (value, solDecimals = 9) => {
|
|
|
439
425
|
return common.multiplyBigIntByNumber(scale, y);
|
|
440
426
|
};
|
|
441
427
|
function calculateClaimableLamportsFromPrices(params) {
|
|
442
|
-
const {
|
|
443
|
-
claimableAmount,
|
|
444
|
-
tokenPriceUsd,
|
|
445
|
-
solPriceUsd,
|
|
446
|
-
tokenDecimals,
|
|
447
|
-
solDecimals = 9
|
|
448
|
-
} = params;
|
|
428
|
+
const { claimableAmount, tokenPriceUsd, solPriceUsd, tokenDecimals, solDecimals = 9 } = params;
|
|
449
429
|
if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
|
|
450
430
|
const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
|
|
451
431
|
const SCALE = 10n ** BigInt(scaleDigits);
|
|
@@ -467,16 +447,8 @@ function calculateDynamicFeeFromSolParams(params) {
|
|
|
467
447
|
if (raw > maxLamports) return maxLamports;
|
|
468
448
|
return raw;
|
|
469
449
|
}
|
|
470
|
-
async function fetchTokenPriceUsd(mintId, cluster, fetchFn = fetch) {
|
|
471
|
-
const url = `https://token-api.streamflow.finance/price?ids=${encodeURIComponent(mintId)}&cluster=${encodeURIComponent(cluster)}`;
|
|
472
|
-
const res = await fetchFn(url, { headers: { "Content-Type": "application/json" } });
|
|
473
|
-
if (!res.ok) return null;
|
|
474
|
-
const json = await res.json();
|
|
475
|
-
const val = json?.data?.[mintId]?.value;
|
|
476
|
-
return typeof val === "number" ? val : null;
|
|
477
|
-
}
|
|
478
450
|
async function resolveAirdropFeeLamportsUsingApi(params) {
|
|
479
|
-
const { distributorAddress, mintAccount, claimableAmount, cluster
|
|
451
|
+
const { distributorAddress, mintAccount, claimableAmount, cluster } = params;
|
|
480
452
|
let apiFeesResponse = void 0;
|
|
481
453
|
try {
|
|
482
454
|
apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster);
|
|
@@ -486,8 +458,8 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
|
|
|
486
458
|
let tokenPrice = null;
|
|
487
459
|
try {
|
|
488
460
|
[solPrice, tokenPrice] = await Promise.all([
|
|
489
|
-
|
|
490
|
-
|
|
461
|
+
common.fetchTokenPrice(splToken.NATIVE_MINT.toBase58(), cluster),
|
|
462
|
+
common.fetchTokenPrice(mintAccount.address.toBase58(), cluster)
|
|
491
463
|
]);
|
|
492
464
|
} catch (_) {
|
|
493
465
|
}
|
|
@@ -496,13 +468,13 @@ async function resolveAirdropFeeLamportsUsingApi(params) {
|
|
|
496
468
|
return toLamportsSOL(response.claimFee);
|
|
497
469
|
}
|
|
498
470
|
const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
|
|
499
|
-
if (!tokenPrice || !solPrice) {
|
|
471
|
+
if (!tokenPrice?.value || !solPrice?.value) {
|
|
500
472
|
return MINIMUM_FEE_FALLBACK;
|
|
501
473
|
}
|
|
502
474
|
const baseLamports = calculateClaimableLamportsFromPrices({
|
|
503
475
|
claimableAmount,
|
|
504
|
-
tokenPriceUsd: tokenPrice,
|
|
505
|
-
solPriceUsd: solPrice,
|
|
476
|
+
tokenPriceUsd: tokenPrice.value,
|
|
477
|
+
solPriceUsd: solPrice.value,
|
|
506
478
|
tokenDecimals: mintAccount.decimals
|
|
507
479
|
});
|
|
508
480
|
return calculateDynamicFeeFromSolParams({
|
|
@@ -3775,10 +3747,17 @@ var BaseDistributorClient = class {
|
|
|
3775
3747
|
if (!feeLamports) {
|
|
3776
3748
|
try {
|
|
3777
3749
|
const { mint: mintAccount } = await solana.getMintAndProgram(this.connection, distributor.mint);
|
|
3750
|
+
const claimableAmountRaw = data?.claimableAmount;
|
|
3751
|
+
const unlockedRaw = data?.amountUnlocked;
|
|
3752
|
+
const lockedRaw = data?.amountLocked;
|
|
3753
|
+
const unlocked = unlockedRaw != null ? new BN5__default.default(unlockedRaw) : new BN5__default.default(0);
|
|
3754
|
+
const locked = lockedRaw != null ? new BN5__default.default(lockedRaw) : new BN5__default.default(0);
|
|
3755
|
+
const computedFallback = unlocked.add(locked);
|
|
3756
|
+
const claimableAmount = claimableAmountRaw != null ? BigInt(claimableAmountRaw.toString()) : BigInt(computedFallback.toString());
|
|
3778
3757
|
feeLamports = await resolveAirdropFeeLamportsUsingApi({
|
|
3779
3758
|
distributorAddress: distributorPublicKey.toBase58(),
|
|
3780
3759
|
mintAccount,
|
|
3781
|
-
claimableAmount
|
|
3760
|
+
claimableAmount,
|
|
3782
3761
|
cluster: this.cluster
|
|
3783
3762
|
});
|
|
3784
3763
|
} catch (_) {
|