Skip to content

Commit d299de5

Browse files
expose apiUrl and apiKey in distributor client
1 parent 6a4c6a6 commit d299de5

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

packages/distributor/solana/clients/BaseDistributorClient.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ export interface IInitOptions {
7777
programId?: string;
7878
sendRate?: number;
7979
sendThrottler?: PQueue;
80+
apiUrl?: string;
81+
apiKey?: string;
8082
}
8183

8284
export default abstract class BaseDistributorClient {
@@ -92,13 +94,19 @@ export default abstract class BaseDistributorClient {
9294

9395
protected cluster: ICluster;
9496

97+
protected apiUrl?: string;
98+
99+
protected apiKey?: string;
100+
95101
public constructor({
96102
clusterUrl,
97103
cluster = ICluster.Mainnet,
98104
commitment = "confirmed",
99105
programId = "",
100106
sendRate = 1,
101107
sendThrottler,
108+
apiUrl,
109+
apiKey,
102110
}: IInitOptions) {
103111
this.commitment = commitment;
104112
this.cluster = cluster;
@@ -109,6 +117,8 @@ export default abstract class BaseDistributorClient {
109117
...MerkleDistributorIDL,
110118
} as MerkleDistributorProgramType;
111119
this.merkleDistributorProgram = new Program(merkleDistributorProgram, { connection: this.connection });
120+
this.apiUrl = apiUrl;
121+
this.apiKey = apiKey;
112122
}
113123

114124
protected abstract getNewDistributorInstruction(
@@ -391,6 +401,8 @@ export default abstract class BaseDistributorClient {
391401
mintAccount,
392402
claimableAmount,
393403
cluster: this.cluster,
404+
apiUrl: this.apiUrl,
405+
apiKey: this.apiKey,
394406
});
395407
} catch (_) {
396408
feeLamports = MINIMUM_FEE_FALLBACK;

packages/distributor/solana/fees.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,14 @@ export async function resolveAirdropFeeLamportsUsingApi(params: {
167167
mintAccount: Mint;
168168
claimableAmount: bigint;
169169
cluster: ICluster;
170+
apiUrl?: string;
171+
apiKey?: string;
170172
}): Promise<bigint> {
171-
const { distributorAddress, mintAccount, claimableAmount, cluster } = params;
173+
const { distributorAddress, mintAccount, claimableAmount, cluster, apiUrl, apiKey } = params;
172174
let apiFeesResponse = undefined;
173175

174176
try {
175-
apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster);
177+
apiFeesResponse = await fetchAirdropFee(distributorAddress, cluster, apiUrl, apiKey);
176178
} catch (_) {
177179
// ignore and fallback
178180
}
@@ -190,7 +192,7 @@ export async function resolveAirdropFeeLamportsUsingApi(params: {
190192

191193
const response = apiFeesResponse ?? defaultAPIFeesResponse;
192194

193-
if (response?.isCustom && response.claimFee !== null && response.claimFee !== undefined) {
195+
if (response?.isCustom && !!response.claimFee) {
194196
return toLamportsSOL(response.claimFee);
195197
}
196198

packages/distributor/solana/fetchAirdropFee.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ export interface AirdropFeeQueryOptionsOverrides {
1919

2020
export const fetchAirdropFee = async (
2121
distributorId: string,
22-
cluster: ICluster = ICluster.Mainnet,
22+
cluster: ICluster,
23+
apiUrl?: string,
24+
apiKey?: string,
2325
fetchFn: typeof fetch = fetch,
2426
): Promise<AirdropFeeResponse> => {
25-
const baseUrl =
26-
cluster === ICluster.Mainnet ? "https://api.streamflow.finance" : "https://staging-api.streamflow.finance";
27+
const baseUrl = apiUrl ?? cluster === ICluster.Mainnet ? "https://api.streamflow.finance" : "https://staging-api.streamflow.finance";
2728
const url = `${baseUrl}/v2/api/airdrops/${encodeURIComponent(distributorId)}/fees`;
2829

2930
const res = await fetchFn(url, {
3031
method: "GET",
3132
headers: {
3233
"Content-Type": "application/json",
34+
...(apiKey ? { "x-api-key": apiKey } : {}),
3335
},
3436
});
3537

0 commit comments

Comments
 (0)