Skip to content
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@velora-dex/sdk",
"version": "9.3.1",
"version": "9.3.2",
"main": "dist/index.js",
"module": "dist/sdk.esm.js",
"typings": "dist/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/fetchers/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ export const constructFetcher =
// adding apiKey to headers if it's provided
const headers = extra?.apiKey
? {
...extra.headers,
'X-API-KEY': extra.apiKey,
...rest.headers,
...requestParams?.headers,
}
: { ...rest.headers, ...requestParams?.headers };
: { ...extra?.headers, ...rest.headers, ...requestParams?.headers };

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

Expand Down
13 changes: 11 additions & 2 deletions src/helpers/fetchers/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { FetcherError } from '../misc';
type Fetch = typeof fetch;

export const constructFetcher =
(fetch: Fetch, extra?: ExtraFetchParams): FetcherFunction =>
(
fetch: Fetch,
extra?: ExtraFetchParams & { keepalive?: boolean }
): FetcherFunction =>
async (params) => {
try {
const { url, method, requestParams } = params;
Expand All @@ -25,8 +28,13 @@ export const constructFetcher =

// all headers combined
const headers =
POSTheaders || apiHeaders || params.headers || requestParams?.headers
POSTheaders ||
apiHeaders ||
params.headers ||
requestParams?.headers ||
extra?.headers
? {
...extra?.headers,
...apiHeaders,
...POSTheaders,
...params.headers,
Expand All @@ -37,6 +45,7 @@ export const constructFetcher =
const response = await fetch(url, {
method,
body,
keepalive: extra?.keepalive,
...requestParams,
headers,
});
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import type {
OptimalRate,
OptionalRate,
APIVersion,
ExtraFetchParams,
} from './types';

import type {
Expand Down Expand Up @@ -420,6 +421,7 @@ export type {
FetcherErrorInterface,
APIVersion,
SwapSideUnion,
ExtraFetchParams,
};

export { SDKConfig, constructPartialSDK } from './sdk/partial';
Expand Down
2 changes: 2 additions & 0 deletions src/methods/delta/getDeltaPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type DeltaPriceParams = {
beneficiary?: string; // beneficiary==owner if no transferTo
/** @description Partner string. */
partner?: string;
/** @description Used together with `partner` if provided. Represented in basis points, 50bps=0.5% */
partnerFeeBps?: number;
/** @description Destination Chain ID for Crosschain Orders */
destChainId?: number;
/** @description SELL or BUY, default is SELL */
Expand Down
2 changes: 2 additions & 0 deletions src/methods/quote/getQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type QuoteParams<M extends TradeMode = TradeMode> = {
userAddress?: string;
/** @description Partner string */
partner?: string;
/** @description Used together with `partner` if provided. Represented in basis points, 50bps=0.5% */
partnerFeeBps?: number;
/** @description Maximum price impact (in percentage) acceptable for the trade */
maxImpact?: number;
/** @description Maximum price impact (in USD) acceptable for the trade */
Expand Down
4 changes: 3 additions & 1 deletion src/methods/swap/rates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type RateQueryParams = {
destTokenDexTransferFee?: string;

/**
* @description To specify the protocol version. **Values:** 5 or 6.2 **Default**: 5.
* @description To specify the protocol version. **Values:** 5 or 6.2 **Default**: 6.2.
*/
version?: number | string;

Expand All @@ -149,6 +149,8 @@ export type RateOptions = {
excludeContractMethods?: ContractMethodByName[];
includeContractMethods?: ContractMethodByName[];
partner?: string;
/** @description Used together with `partner` if provided. Represented in basis points, 50bps=0.5% */
partnerFeeBps?: number;
/** @description In %. It's a way to bypass the API price impact check (default = 15%) */
maxImpact?: number;
maxUSDImpact?: number;
Expand Down
7 changes: 6 additions & 1 deletion src/sdk/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,16 @@ const constructFetcher = (options: FetcherOptions): FetcherFunction => {
// adding apiKey to headers if it's provided
const headers = options?.apiKey
? {
...options.headers,
'X-API-KEY': options.apiKey,
...params.headers,
...params.requestParams?.headers,
}
: params.headers;
: {
...options.headers,
...params.headers,
...params.requestParams?.headers,
};

return options.fetcher({ ...params, headers });
};
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export type FetcherFunction = <T, URL extends string = string>(
) => Promise<T>;

// authentication or some other params required in `fetcher`
export type ExtraFetchParams = { apiKey?: string };
export type ExtraFetchParams = {
apiKey?: string;
headers?: Record<string, string>;
};

export interface ConstructFetchInput extends ConstructBaseInput {
fetcher: FetcherFunction;
Expand Down
8 changes: 4 additions & 4 deletions tests/__snapshots__/delta.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ exports[`Delta:methods Get Delta Price 1`] = `
"gasCostUSDBeforeFee": "dynamic_number",
"hmac": "dynamic_string",
"partner": "anon",
"partnerFee": 0,
"partnerFee": NaN,
"receivedDestAmount": "dynamic_number",
"receivedDestAmountBeforeFee": "dynamic_number",
"receivedDestUSD": "dynamic_number",
Expand Down Expand Up @@ -378,7 +378,7 @@ exports[`Delta:methods Get Delta Price Crosschain Get Delta Price Crosschain/des
"gasCostUSDBeforeFee": "dynamic_number",
"hmac": "dynamic_string",
"partner": "anon",
"partnerFee": 0,
"partnerFee": NaN,
"receivedDestAmount": "dynamic_number",
"receivedDestAmountBeforeFee": "dynamic_number",
"receivedDestUSD": "dynamic_number",
Expand Down Expand Up @@ -420,7 +420,7 @@ exports[`Delta:methods Get Delta Price Crosschain Get Delta Price Crosschain/des
"gasCostUSDBeforeFee": "dynamic_number",
"hmac": "dynamic_string",
"partner": "anon",
"partnerFee": 0,
"partnerFee": NaN,
"receivedDestAmount": "dynamic_number",
"receivedDestAmountBeforeFee": "dynamic_number",
"receivedDestUSD": "dynamic_number",
Expand Down Expand Up @@ -462,7 +462,7 @@ exports[`Delta:methods Get Delta Price Crosschain Get Delta Price Crosschain/des
"gasCostUSDBeforeFee": "dynamic_number",
"hmac": "dynamic_string",
"partner": "anon",
"partnerFee": 0,
"partnerFee": NaN,
"receivedDestAmount": "dynamic_number",
"receivedDestAmountBeforeFee": "dynamic_number",
"receivedDestUSD": "dynamic_number",
Expand Down
12 changes: 0 additions & 12 deletions tests/__snapshots__/partialSdk.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

exports[`Partial SDK: fetching methods: axiosFetcher Get_Adapters: Get_Adapters 1`] = `
[
"Bancor",
"Compound",
"CurveV2",
"Lido",
"EtherFi",
"CurveV1",
"Swerve",
"BalancerV1",
"BalancerV2",
"UniswapV2",
Expand All @@ -20,7 +17,6 @@ exports[`Partial SDK: fetching methods: axiosFetcher Get_Adapters: Get_Adapters
"SushiSwapV3",
"PancakeSwapV2",
"PancakeswapV3",
"AaveV2",
"AaveV3",
"AaveV3Lido",
"Weth",
Expand All @@ -36,11 +32,9 @@ exports[`Partial SDK: fetching methods: axiosFetcher Get_Adapters: Get_Adapters
"AngleStakedStableUSD",
"AngleStakedStableEUR",
"SolidlyV3",
"Wombat",
"Swell",
"Spark",
"sUSDS",
"RingV2",
"AugustusRFQ",
]
`;
Expand Down Expand Up @@ -118,13 +112,10 @@ exports[`Partial SDK: fetching methods: axiosFetcher Get_SwapTxData: Get_SwapTxD

exports[`Partial SDK: fetching methods: fetchFetcher Get_Adapters: Get_Adapters 1`] = `
[
"Bancor",
"Compound",
"CurveV2",
"Lido",
"EtherFi",
"CurveV1",
"Swerve",
"BalancerV1",
"BalancerV2",
"UniswapV2",
Expand All @@ -136,7 +127,6 @@ exports[`Partial SDK: fetching methods: fetchFetcher Get_Adapters: Get_Adapters
"SushiSwapV3",
"PancakeSwapV2",
"PancakeswapV3",
"AaveV2",
"AaveV3",
"AaveV3Lido",
"Weth",
Expand All @@ -152,11 +142,9 @@ exports[`Partial SDK: fetching methods: fetchFetcher Get_Adapters: Get_Adapters
"AngleStakedStableUSD",
"AngleStakedStableEUR",
"SolidlyV3",
"Wombat",
"Swell",
"Spark",
"sUSDS",
"RingV2",
"AugustusRFQ",
]
`;
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/quote.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ exports[`Quote:methods Get Quote for market 1`] = `
"maxImpactReached": false,
"network": 1,
"partner": "anon",
"partnerFee": 0,
"partnerFee": NaN,
"side": "SELL",
"srcAmount": "100000000000",
"srcDecimals": 6,
Expand Down
16 changes: 0 additions & 16 deletions tests/__snapshots__/simpleSdk.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

exports[`Simple SDK: fetcher made with: axios Get_Adapters: Get_Adapters 1`] = `
[
"Bancor",
"Compound",
"CurveV2",
"Lido",
"EtherFi",
"Stader",
"Bebop",
"CurveV1",
"Swerve",
"BalancerV1",
"BalancerV2",
"BalancerV3",
Expand All @@ -24,7 +20,6 @@ exports[`Simple SDK: fetcher made with: axios Get_Adapters: Get_Adapters 1`] = `
"UniswapV4",
"PancakeSwapV2",
"PancakeswapV3",
"AaveV2",
"AaveV3",
"AaveV3Lido",
"Weth",
Expand All @@ -34,7 +29,6 @@ exports[`Simple SDK: fetcher made with: axios Get_Adapters: Get_Adapters 1`] = `
"CurveV1Factory",
"CurveV1StableNg",
"wstETH",
"wUSDM",
"wUSDL",
"sUSDe",
"stcUSD",
Expand All @@ -47,14 +41,12 @@ exports[`Simple SDK: fetcher made with: axios Get_Adapters: Get_Adapters 1`] = `
"AngleStakedStableUSD",
"AngleStakedStableEUR",
"SolidlyV3",
"Wombat",
"Swell",
"Spark",
"sUSDS",
"AaveV3Stata",
"AaveV3StataV2",
"OSwap",
"ConcentratorArusd",
"FxProtocolRusd",
"AaveGsm",
"LitePsm",
Expand Down Expand Up @@ -143,15 +135,11 @@ exports[`Simple SDK: fetcher made with: axios Get_SwapTxData: Get_SwapTxData::tx

exports[`Simple SDK: fetcher made with: fetch Get_Adapters: Get_Adapters 1`] = `
[
"Bancor",
"Compound",
"CurveV2",
"Lido",
"EtherFi",
"Stader",
"Bebop",
"CurveV1",
"Swerve",
"BalancerV1",
"BalancerV2",
"BalancerV3",
Expand All @@ -165,7 +153,6 @@ exports[`Simple SDK: fetcher made with: fetch Get_Adapters: Get_Adapters 1`] = `
"UniswapV4",
"PancakeSwapV2",
"PancakeswapV3",
"AaveV2",
"AaveV3",
"AaveV3Lido",
"Weth",
Expand All @@ -175,7 +162,6 @@ exports[`Simple SDK: fetcher made with: fetch Get_Adapters: Get_Adapters 1`] = `
"CurveV1Factory",
"CurveV1StableNg",
"wstETH",
"wUSDM",
"wUSDL",
"sUSDe",
"stcUSD",
Expand All @@ -188,14 +174,12 @@ exports[`Simple SDK: fetcher made with: fetch Get_Adapters: Get_Adapters 1`] = `
"AngleStakedStableUSD",
"AngleStakedStableEUR",
"SolidlyV3",
"Wombat",
"Swell",
"Spark",
"sUSDS",
"AaveV3Stata",
"AaveV3StataV2",
"OSwap",
"ConcentratorArusd",
"FxProtocolRusd",
"AaveGsm",
"LitePsm",
Expand Down
Loading
Loading