@streamflow/distributor 8.9.0-alpha.p308.94c0898 → 9.0.0-alpha.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 +162 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/solana/index.cjs +162 -6
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +38 -2
- package/dist/esm/index.js +163 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +38 -2
- package/dist/esm/solana/index.js +162 -8
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +4 -4
- package/LICENSE +0 -674
|
@@ -91,6 +91,7 @@ interface IClaimData {
|
|
|
91
91
|
id: string;
|
|
92
92
|
amountUnlocked: BN;
|
|
93
93
|
amountLocked: BN;
|
|
94
|
+
claimableAmount: BN;
|
|
94
95
|
proof: Array<Array<number>>;
|
|
95
96
|
}
|
|
96
97
|
interface ICloseClaimData extends Partial<Omit<IClaimData, "id">> {
|
|
@@ -634,6 +635,7 @@ declare abstract class BaseDistributorClient {
|
|
|
634
635
|
protected commitment: Commitment | ConnectionConfig;
|
|
635
636
|
protected sendThrottler: PQueue;
|
|
636
637
|
merkleDistributorProgram: Program<MerkleDistributor$1>;
|
|
638
|
+
protected cluster: ICluster;
|
|
637
639
|
constructor({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler, }: IInitOptions);
|
|
638
640
|
protected abstract getNewDistributorInstruction(data: ICreateDistributorData | ICreateAlignedDistributorData, accounts: NewDistributorAccounts): Promise<TransactionInstruction>;
|
|
639
641
|
protected abstract getClawbackInstruction(account: ClawbackAccounts): Promise<TransactionInstruction>;
|
|
@@ -1377,6 +1379,38 @@ declare namespace constants {
|
|
|
1377
1379
|
export { constants_AIRDROP_CLAIM_FEE as AIRDROP_CLAIM_FEE, constants_ALIGNED_DISTRIBUTOR_PREFIX as ALIGNED_DISTRIBUTOR_PREFIX, constants_ALIGNED_DISTRIBUTOR_PROGRAM_ID as ALIGNED_DISTRIBUTOR_PROGRAM_ID, constants_ALIGNED_PRECISION_FACTOR_POW as ALIGNED_PRECISION_FACTOR_POW, constants_ANCHOR_DISCRIMINATOR_OFFSET as ANCHOR_DISCRIMINATOR_OFFSET, constants_CLAIM_STATUS_PREFIX as CLAIM_STATUS_PREFIX, constants_DISTRIBUTOR_ADMIN_OFFSET as DISTRIBUTOR_ADMIN_OFFSET, constants_DISTRIBUTOR_MINT_OFFSET as DISTRIBUTOR_MINT_OFFSET, constants_DISTRIBUTOR_PREFIX as DISTRIBUTOR_PREFIX, constants_DISTRIBUTOR_PROGRAM_ID as DISTRIBUTOR_PROGRAM_ID, constants_ONE_IN_BASIS_POINTS as ONE_IN_BASIS_POINTS, constants_STREAMFLOW_TREASURY_PUBLIC_KEY as STREAMFLOW_TREASURY_PUBLIC_KEY, constants_TEST_ORACLE_PREFIX as TEST_ORACLE_PREFIX };
|
|
1378
1380
|
}
|
|
1379
1381
|
|
|
1382
|
+
type AirdropFeeResponse = {
|
|
1383
|
+
claimFee: string | number;
|
|
1384
|
+
claimFeeDynamic?: {
|
|
1385
|
+
minPrice: string;
|
|
1386
|
+
maxPrice: string;
|
|
1387
|
+
allocationFactor: string;
|
|
1388
|
+
};
|
|
1389
|
+
isCustom: boolean;
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
declare const fetchAirdropFee: (distributorId: string, cluster?: ICluster, fetchFn?: typeof fetch) => Promise<AirdropFeeResponse>;
|
|
1393
|
+
interface AirdropFeeQueryOptionsOverrides {
|
|
1394
|
+
staleTimeMs?: number;
|
|
1395
|
+
gcTimeMs?: number;
|
|
1396
|
+
retry?: number | boolean;
|
|
1397
|
+
refetchOnWindowFocus?: boolean;
|
|
1398
|
+
}
|
|
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
|
+
};
|
|
1411
|
+
|
|
1412
|
+
type index_AirdropFeeQueryOptionsOverrides = AirdropFeeQueryOptionsOverrides;
|
|
1413
|
+
type index_AirdropFeeResponse = AirdropFeeResponse;
|
|
1380
1414
|
type index_AlignedDistributorData = AlignedDistributorData;
|
|
1381
1415
|
type index_AnchorErrorCode = AnchorErrorCode;
|
|
1382
1416
|
declare const index_AnchorErrorCode: typeof AnchorErrorCode;
|
|
@@ -1424,8 +1458,10 @@ declare const index_claimLocked: typeof claimLocked;
|
|
|
1424
1458
|
declare const index_clawback: typeof clawback;
|
|
1425
1459
|
declare const index_closeClaim: typeof closeClaim;
|
|
1426
1460
|
declare const index_constants: typeof constants;
|
|
1461
|
+
declare const index_fetchAirdropFee: typeof fetchAirdropFee;
|
|
1427
1462
|
declare const index_fromCode: typeof fromCode;
|
|
1428
1463
|
declare const index_fromTxError: typeof fromTxError;
|
|
1464
|
+
declare const index_getAirdropFeeQueryOptions: typeof getAirdropFeeQueryOptions;
|
|
1429
1465
|
declare const index_getAlignedDistributorPda: typeof getAlignedDistributorPda;
|
|
1430
1466
|
declare const index_getClaimantStatusPda: typeof getClaimantStatusPda;
|
|
1431
1467
|
declare const index_getDistributorPda: typeof getDistributorPda;
|
|
@@ -1438,7 +1474,7 @@ declare const index_setAdmin: typeof setAdmin;
|
|
|
1438
1474
|
declare const index_setClawbackReceiver: typeof setClawbackReceiver;
|
|
1439
1475
|
declare const index_wrappedSignAndExecuteTransaction: typeof wrappedSignAndExecuteTransaction;
|
|
1440
1476
|
declare namespace index {
|
|
1441
|
-
export { 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_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 };
|
|
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 };
|
|
1442
1478
|
}
|
|
1443
1479
|
|
|
1444
|
-
export { 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, fromCode, fromTxError, getAlignedDistributorPda, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, getTestOraclePda, index as i, isCompressedClaimStatus, newClaim, newDistributor, setAdmin, setClawbackReceiver, wrappedSignAndExecuteTransaction };
|
|
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 };
|
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 } from '@streamflow/common';
|
|
3
|
+
import { ICluster, ContractError, divCeilN, invariant, getNumberFromBN, getBN, 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';
|
|
@@ -28,8 +28,10 @@ __export(solana_exports, {
|
|
|
28
28
|
clawback: () => clawback,
|
|
29
29
|
closeClaim: () => closeClaim,
|
|
30
30
|
constants: () => constants_exports,
|
|
31
|
+
fetchAirdropFee: () => fetchAirdropFee,
|
|
31
32
|
fromCode: () => fromCode3,
|
|
32
33
|
fromTxError: () => fromTxError,
|
|
34
|
+
getAirdropFeeQueryOptions: () => getAirdropFeeQueryOptions,
|
|
33
35
|
getAlignedDistributorPda: () => getAlignedDistributorPda,
|
|
34
36
|
getClaimantStatusPda: () => getClaimantStatusPda,
|
|
35
37
|
getDistributorPda: () => getDistributorPda,
|
|
@@ -340,6 +342,150 @@ var DISTRIBUTOR_PROGRAM_ID = {
|
|
|
340
342
|
[ICluster.Testnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
341
343
|
[ICluster.Local]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N"
|
|
342
344
|
};
|
|
345
|
+
var fetchAirdropFee = async (distributorId, cluster = ICluster.Mainnet, fetchFn = fetch) => {
|
|
346
|
+
const baseUrl = cluster === ICluster.Mainnet ? "https://api.streamflow.finance" : "https://staging-api.streamflow.finance";
|
|
347
|
+
const url = `${baseUrl}/v2/api/airdrops/${encodeURIComponent(distributorId)}/fees`;
|
|
348
|
+
const res = await fetchFn(url, {
|
|
349
|
+
method: "GET",
|
|
350
|
+
headers: {
|
|
351
|
+
"Content-Type": "application/json"
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
if (!res.ok) {
|
|
355
|
+
const text = await res.text().catch(() => "");
|
|
356
|
+
throw new Error(`Airdrop fee API error: ${res.status} ${res.statusText}${text ? ` - ${text}` : ""}`);
|
|
357
|
+
}
|
|
358
|
+
const json = await res.json();
|
|
359
|
+
return json;
|
|
360
|
+
};
|
|
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
|
+
|
|
375
|
+
// solana/fees.ts
|
|
376
|
+
var MAXIMUM_FEE_FALLBACK = 9900000n;
|
|
377
|
+
var MINIMUM_FEE_FALLBACK = 5000000n;
|
|
378
|
+
var FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR = 90n;
|
|
379
|
+
var FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR = 100n;
|
|
380
|
+
var LAMPORTS_PER_SOL = 1000000000n;
|
|
381
|
+
var lamportsToSolString = (lamports) => {
|
|
382
|
+
const int = lamports / LAMPORTS_PER_SOL;
|
|
383
|
+
const frac = lamports % LAMPORTS_PER_SOL;
|
|
384
|
+
if (frac === 0n) return int.toString();
|
|
385
|
+
const fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
|
|
386
|
+
return `${int.toString()}.${fracStr}`;
|
|
387
|
+
};
|
|
388
|
+
var allocationToString = (num, den) => {
|
|
389
|
+
const SCALE = 1000000000n;
|
|
390
|
+
const scaled = num * SCALE / den;
|
|
391
|
+
const int = scaled / SCALE;
|
|
392
|
+
const frac = scaled % SCALE;
|
|
393
|
+
if (frac === 0n) return int.toString();
|
|
394
|
+
const fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
|
|
395
|
+
return `${int.toString()}.${fracStr}`;
|
|
396
|
+
};
|
|
397
|
+
var defaultAPIFeesResponse = {
|
|
398
|
+
isCustom: false,
|
|
399
|
+
claimFee: void 0,
|
|
400
|
+
claimFeeDynamic: {
|
|
401
|
+
minPrice: lamportsToSolString(MINIMUM_FEE_FALLBACK),
|
|
402
|
+
maxPrice: lamportsToSolString(MAXIMUM_FEE_FALLBACK),
|
|
403
|
+
allocationFactor: allocationToString(
|
|
404
|
+
FEE_ALLOCATION_FACTOR_FALLBACK_NUMERATOR,
|
|
405
|
+
FEE_ALLOCATION_FACTOR_FALLBACK_DENOMINATOR
|
|
406
|
+
)
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
var toLamportsSOL = (value, solDecimals = 9) => {
|
|
410
|
+
const y = typeof value === "bigint" ? Number(value) : typeof value === "string" ? Number(value) : value;
|
|
411
|
+
if (!Number.isFinite(y) || y <= 0) return 0n;
|
|
412
|
+
const scale = 10n ** BigInt(solDecimals);
|
|
413
|
+
return multiplyBigIntByNumber(scale, y);
|
|
414
|
+
};
|
|
415
|
+
function calculateClaimableLamportsFromPrices(params) {
|
|
416
|
+
const {
|
|
417
|
+
claimableAmount,
|
|
418
|
+
tokenPriceUsd,
|
|
419
|
+
solPriceUsd,
|
|
420
|
+
tokenDecimals,
|
|
421
|
+
solDecimals = 9
|
|
422
|
+
} = params;
|
|
423
|
+
if (tokenPriceUsd <= 0 || solPriceUsd <= 0) return 0n;
|
|
424
|
+
const scaleDigits = Math.min(18, Math.max(0, tokenDecimals));
|
|
425
|
+
const SCALE = 10n ** BigInt(scaleDigits);
|
|
426
|
+
const pScaled = multiplyBigIntByNumber(SCALE, tokenPriceUsd, scaleDigits);
|
|
427
|
+
const sScaled = multiplyBigIntByNumber(SCALE, solPriceUsd, scaleDigits);
|
|
428
|
+
if (pScaled <= 0n || sScaled <= 0n) return 0n;
|
|
429
|
+
const pow10 = (n) => 10n ** BigInt(n);
|
|
430
|
+
const numerator = claimableAmount * pow10(solDecimals) * pScaled;
|
|
431
|
+
const denominator = pow10(tokenDecimals) * sScaled;
|
|
432
|
+
return numerator / denominator;
|
|
433
|
+
}
|
|
434
|
+
function calculateDynamicFeeFromSolParams(params) {
|
|
435
|
+
const { minPrice, maxPrice, allocationFactor, claimableLamports, solDecimals = 9 } = params;
|
|
436
|
+
const minLamports = toLamportsSOL(minPrice, solDecimals);
|
|
437
|
+
const maxLamports = toLamportsSOL(maxPrice, solDecimals);
|
|
438
|
+
const factor = Math.max(0, Math.min(1, parseFloat(allocationFactor)));
|
|
439
|
+
const raw = multiplyBigIntByNumber(claimableLamports, factor);
|
|
440
|
+
if (raw < minLamports) return minLamports;
|
|
441
|
+
if (raw > maxLamports) return maxLamports;
|
|
442
|
+
return raw;
|
|
443
|
+
}
|
|
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
|
+
async function resolveAirdropFeeLamportsUsingApi(params) {
|
|
453
|
+
const { distributorAddress, mintAccount, claimableAmount, cluster, fetchFn } = params;
|
|
454
|
+
let apiFeesResponse = void 0;
|
|
455
|
+
try {
|
|
456
|
+
apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster);
|
|
457
|
+
} catch (_) {
|
|
458
|
+
}
|
|
459
|
+
let solPrice = null;
|
|
460
|
+
let tokenPrice = null;
|
|
461
|
+
try {
|
|
462
|
+
[solPrice, tokenPrice] = await Promise.all([
|
|
463
|
+
fetchTokenPriceUsd("So11111111111111111111111111111111111111112", cluster, fetchFn),
|
|
464
|
+
fetchTokenPriceUsd(mintAccount.address.toBase58(), cluster, fetchFn)
|
|
465
|
+
]);
|
|
466
|
+
} catch (_) {
|
|
467
|
+
}
|
|
468
|
+
const response = apiFeesResponse ?? defaultAPIFeesResponse;
|
|
469
|
+
if (response?.isCustom && response.claimFee !== void 0) {
|
|
470
|
+
return toLamportsSOL(response.claimFee);
|
|
471
|
+
}
|
|
472
|
+
const claimFeeDynamic = response?.claimFeeDynamic ?? defaultAPIFeesResponse.claimFeeDynamic;
|
|
473
|
+
if (!tokenPrice || !solPrice) {
|
|
474
|
+
return MINIMUM_FEE_FALLBACK;
|
|
475
|
+
}
|
|
476
|
+
const baseLamports = calculateClaimableLamportsFromPrices({
|
|
477
|
+
claimableAmount,
|
|
478
|
+
tokenPriceUsd: tokenPrice,
|
|
479
|
+
solPriceUsd: solPrice,
|
|
480
|
+
tokenDecimals: mintAccount.decimals
|
|
481
|
+
});
|
|
482
|
+
return calculateDynamicFeeFromSolParams({
|
|
483
|
+
minPrice: claimFeeDynamic.minPrice,
|
|
484
|
+
maxPrice: claimFeeDynamic.maxPrice,
|
|
485
|
+
allocationFactor: claimFeeDynamic.allocationFactor,
|
|
486
|
+
claimableLamports: baseLamports
|
|
487
|
+
});
|
|
488
|
+
}
|
|
343
489
|
|
|
344
490
|
// solana/descriptor/idl/merkle_distributor.json
|
|
345
491
|
var merkle_distributor_default = {
|
|
@@ -3415,6 +3561,7 @@ var BaseDistributorClient = class {
|
|
|
3415
3561
|
sendThrottler
|
|
3416
3562
|
}) {
|
|
3417
3563
|
this.commitment = commitment;
|
|
3564
|
+
this.cluster = cluster;
|
|
3418
3565
|
this.connection = new Connection(clusterUrl, this.commitment);
|
|
3419
3566
|
this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(DISTRIBUTOR_PROGRAM_ID[cluster]);
|
|
3420
3567
|
this.sendThrottler = sendThrottler ?? buildSendThrottler(sendRate);
|
|
@@ -3598,12 +3745,21 @@ var BaseDistributorClient = class {
|
|
|
3598
3745
|
if (claimStatus || new BN5(data.amountLocked).gtn(0) && nowTs.sub(distributor.startTs).gte(distributor.unlockPeriod)) {
|
|
3599
3746
|
ixs.push(claimLocked(accounts, this.programId));
|
|
3600
3747
|
}
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3748
|
+
let feeLamports = typeof _serviceTransfer === "bigint" ? _serviceTransfer : void 0;
|
|
3749
|
+
if (!feeLamports) {
|
|
3750
|
+
try {
|
|
3751
|
+
const { mint: mintAccount } = await getMintAndProgram(this.connection, distributor.mint);
|
|
3752
|
+
feeLamports = await resolveAirdropFeeLamportsUsingApi({
|
|
3753
|
+
distributorAddress: distributorPublicKey.toBase58(),
|
|
3754
|
+
mintAccount,
|
|
3755
|
+
claimableAmount: BigInt(data.claimableAmount.toString()),
|
|
3756
|
+
cluster: this.cluster
|
|
3757
|
+
});
|
|
3758
|
+
} catch (_) {
|
|
3759
|
+
feeLamports = MINIMUM_FEE_FALLBACK;
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
ixs.push(this.prepareClaimFeeInstruction(extParams.feePayer ?? extParams.invoker.publicKey, feeLamports));
|
|
3607
3763
|
return ixs;
|
|
3608
3764
|
}
|
|
3609
3765
|
async closeClaim(data, extParams) {
|