Skip to content

Commit 5663d95

Browse files
authored
Merge pull request #222 from VeloraDEX/chore/fetcher_extras
Chore/fetcher extra params
2 parents c47b68b + aa81ba5 commit 5663d95

File tree

16 files changed

+58
-45
lines changed

16 files changed

+58
-45
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@velora-dex/sdk",
3-
"version": "9.3.1",
3+
"version": "9.3.2",
44
"main": "dist/index.js",
55
"module": "dist/sdk.esm.js",
66
"typings": "dist/index.d.ts",

src/helpers/fetchers/axios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export const constructFetcher =
1212
// adding apiKey to headers if it's provided
1313
const headers = extra?.apiKey
1414
? {
15+
...extra.headers,
1516
'X-API-KEY': extra.apiKey,
1617
...rest.headers,
1718
...requestParams?.headers,
1819
}
19-
: { ...rest.headers, ...requestParams?.headers };
20+
: { ...extra?.headers, ...rest.headers, ...requestParams?.headers };
2021

2122
const allParams = { ...rest, ...requestParams, headers };
2223

src/helpers/fetchers/fetch.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { FetcherError } from '../misc';
55
type Fetch = typeof fetch;
66

77
export const constructFetcher =
8-
(fetch: Fetch, extra?: ExtraFetchParams): FetcherFunction =>
8+
(
9+
fetch: Fetch,
10+
extra?: ExtraFetchParams & { keepalive?: boolean }
11+
): FetcherFunction =>
912
async (params) => {
1013
try {
1114
const { url, method, requestParams } = params;
@@ -25,8 +28,13 @@ export const constructFetcher =
2528

2629
// all headers combined
2730
const headers =
28-
POSTheaders || apiHeaders || params.headers || requestParams?.headers
31+
POSTheaders ||
32+
apiHeaders ||
33+
params.headers ||
34+
requestParams?.headers ||
35+
extra?.headers
2936
? {
37+
...extra?.headers,
3038
...apiHeaders,
3139
...POSTheaders,
3240
...params.headers,
@@ -37,6 +45,7 @@ export const constructFetcher =
3745
const response = await fetch(url, {
3846
method,
3947
body,
48+
keepalive: extra?.keepalive,
4049
...requestParams,
4150
headers,
4251
});

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ import type {
134134
OptimalRate,
135135
OptionalRate,
136136
APIVersion,
137+
ExtraFetchParams,
137138
} from './types';
138139

139140
import type {
@@ -420,6 +421,7 @@ export type {
420421
FetcherErrorInterface,
421422
APIVersion,
422423
SwapSideUnion,
424+
ExtraFetchParams,
423425
};
424426

425427
export { SDKConfig, constructPartialSDK } from './sdk/partial';

src/methods/delta/getDeltaPrice.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export type DeltaPriceParams = {
2929
beneficiary?: string; // beneficiary==owner if no transferTo
3030
/** @description Partner string. */
3131
partner?: string;
32+
/** @description Used together with `partner` if provided. Represented in basis points, 50bps=0.5% */
33+
partnerFeeBps?: number;
3234
/** @description Destination Chain ID for Crosschain Orders */
3335
destChainId?: number;
3436
/** @description SELL or BUY, default is SELL */

src/methods/quote/getQuote.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export type QuoteParams<M extends TradeMode = TradeMode> = {
2929
userAddress?: string;
3030
/** @description Partner string */
3131
partner?: string;
32+
/** @description Used together with `partner` if provided. Represented in basis points, 50bps=0.5% */
33+
partnerFeeBps?: number;
3234
/** @description Maximum price impact (in percentage) acceptable for the trade */
3335
maxImpact?: number;
3436
/** @description Maximum price impact (in USD) acceptable for the trade */

src/methods/swap/rates.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ type RateQueryParams = {
122122
destTokenDexTransferFee?: string;
123123

124124
/**
125-
* @description To specify the protocol version. **Values:** 5 or 6.2 **Default**: 5.
125+
* @description To specify the protocol version. **Values:** 5 or 6.2 **Default**: 6.2.
126126
*/
127127
version?: number | string;
128128

@@ -149,6 +149,8 @@ export type RateOptions = {
149149
excludeContractMethods?: ContractMethodByName[];
150150
includeContractMethods?: ContractMethodByName[];
151151
partner?: string;
152+
/** @description Used together with `partner` if provided. Represented in basis points, 50bps=0.5% */
153+
partnerFeeBps?: number;
152154
/** @description In %. It's a way to bypass the API price impact check (default = 15%) */
153155
maxImpact?: number;
154156
maxUSDImpact?: number;

src/sdk/simple.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,16 @@ const constructFetcher = (options: FetcherOptions): FetcherFunction => {
214214
// adding apiKey to headers if it's provided
215215
const headers = options?.apiKey
216216
? {
217+
...options.headers,
217218
'X-API-KEY': options.apiKey,
218219
...params.headers,
219220
...params.requestParams?.headers,
220221
}
221-
: params.headers;
222+
: {
223+
...options.headers,
224+
...params.headers,
225+
...params.requestParams?.headers,
226+
};
222227

223228
return options.fetcher({ ...params, headers });
224229
};

src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export type FetcherFunction = <T, URL extends string = string>(
6262
) => Promise<T>;
6363

6464
// authentication or some other params required in `fetcher`
65-
export type ExtraFetchParams = { apiKey?: string };
65+
export type ExtraFetchParams = {
66+
apiKey?: string;
67+
headers?: Record<string, string>;
68+
};
6669

6770
export interface ConstructFetchInput extends ConstructBaseInput {
6871
fetcher: FetcherFunction;

tests/__snapshots__/delta.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ exports[`Delta:methods Get Delta Price 1`] = `
336336
"gasCostUSDBeforeFee": "dynamic_number",
337337
"hmac": "dynamic_string",
338338
"partner": "anon",
339-
"partnerFee": 0,
339+
"partnerFee": NaN,
340340
"receivedDestAmount": "dynamic_number",
341341
"receivedDestAmountBeforeFee": "dynamic_number",
342342
"receivedDestUSD": "dynamic_number",
@@ -378,7 +378,7 @@ exports[`Delta:methods Get Delta Price Crosschain Get Delta Price Crosschain/des
378378
"gasCostUSDBeforeFee": "dynamic_number",
379379
"hmac": "dynamic_string",
380380
"partner": "anon",
381-
"partnerFee": 0,
381+
"partnerFee": NaN,
382382
"receivedDestAmount": "dynamic_number",
383383
"receivedDestAmountBeforeFee": "dynamic_number",
384384
"receivedDestUSD": "dynamic_number",
@@ -420,7 +420,7 @@ exports[`Delta:methods Get Delta Price Crosschain Get Delta Price Crosschain/des
420420
"gasCostUSDBeforeFee": "dynamic_number",
421421
"hmac": "dynamic_string",
422422
"partner": "anon",
423-
"partnerFee": 0,
423+
"partnerFee": NaN,
424424
"receivedDestAmount": "dynamic_number",
425425
"receivedDestAmountBeforeFee": "dynamic_number",
426426
"receivedDestUSD": "dynamic_number",
@@ -462,7 +462,7 @@ exports[`Delta:methods Get Delta Price Crosschain Get Delta Price Crosschain/des
462462
"gasCostUSDBeforeFee": "dynamic_number",
463463
"hmac": "dynamic_string",
464464
"partner": "anon",
465-
"partnerFee": 0,
465+
"partnerFee": NaN,
466466
"receivedDestAmount": "dynamic_number",
467467
"receivedDestAmountBeforeFee": "dynamic_number",
468468
"receivedDestUSD": "dynamic_number",

0 commit comments

Comments
 (0)