Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@velora-dex/sdk",
"version": "9.2.1",
"version": "9.3.0",
"main": "dist/index.js",
"module": "dist/sdk.esm.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -93,7 +93,7 @@
}
},
"dependencies": {
"@paraswap/core": "2.4.0",
"@paraswap/core": "2.4.1",
"ts-essentials": "^10.0.3",
"viem": "^2.21.0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ import {
constructGetBridgeInfo,
GetBridgeInfoFunctions,
BridgeInfo,
BridgeProtocolResponse,
} from './methods/delta/getBridgeInfo';
import {
constructIsTokenSupportedInDelta,
Expand Down Expand Up @@ -378,6 +379,7 @@ export type {
BridgeStatus,
Bridge,
BridgeInfo,
BridgeProtocolResponse,
BuildDeltaOrderDataParams,
BuildDeltaOrderFunctions,
SignableDeltaOrderData,
Expand Down
61 changes: 57 additions & 4 deletions src/methods/delta/getBridgeInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { API_URL } from '../../constants';
import { constructSearchString } from '../../helpers/misc';
import type {
Address,
ConstructFetchInput,
Expand All @@ -10,29 +11,81 @@ import type {
export type BridgeInfo = Record<number, Record<number, Address[]>>;
type BridgeInfoResponse = { supportedTokens: BridgeInfo };

type GetBridgeInfo = (requestParams?: RequestParameters) => Promise<BridgeInfo>;
type GetBridgeInfoParams = {
/** @description Include tokens that can be swapped on destChain after bridge. Default is true. */
allowBridgeAndSwap?: boolean;
/** @description Include only the specified bridges. Default is all bridges. */
bridges?: string[];
};

type BridgeInfoQuery = {
allowBridgeAndSwap?: boolean;
bridges?: string;
};

type GetBridgeInfo = (
params?: GetBridgeInfoParams,
requestParams?: RequestParameters
) => Promise<BridgeInfo>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking API change in getBridgeInfo silently ignores request params

Medium Severity

The getBridgeInfo function signature changed from (requestParams?) to (params?, requestParams?). Existing callers who pass RequestParameters (like { signal: abortController.signal }) as the first argument now have those values interpreted as GetBridgeInfoParams instead. The abort signal and other request options are silently ignored, breaking request cancellation functionality. This is a breaking change introduced in a minor version bump (9.2.1 → 9.3.0).

Additional Locations (1)

Fix in Cursor Fix in Web


export type BridgeProtocolResponse = {
protocol: string;
displayName: string;
};

type BridgeProtocolsResponse = {
bridgeProtocols: BridgeProtocolResponse[];
};

type GetBridgeProtocols = (
requestParams?: RequestParameters
) => Promise<BridgeProtocolResponse[]>;

export type GetBridgeInfoFunctions = {
getBridgeInfo: GetBridgeInfo;
getBridgeProtocols: GetBridgeProtocols;
};

export const constructGetBridgeInfo = ({
apiURL = API_URL,
fetcher,
}: ConstructFetchInput): GetBridgeInfoFunctions => {
const bridgeInfoUrl = `${apiURL}/delta/prices/bridge-info` as const;
const deltaBridgeUrl = `${apiURL}/delta/prices` as const;

const getBridgeInfo: GetBridgeInfo = async (params = {}, requestParams) => {
const { allowBridgeAndSwap, bridges } = params;
const bridgesString = bridges ? bridges.join(',') : undefined;

const search = constructSearchString<BridgeInfoQuery>({
allowBridgeAndSwap,
bridges: bridgesString,
});

const fetchURL = `${deltaBridgeUrl}/bridge-info${search}` as const;

const getBridgeInfo: GetBridgeInfo = async (requestParams) => {
const data = await fetcher<BridgeInfoResponse>({
url: bridgeInfoUrl,
url: fetchURL,
method: 'GET',
requestParams,
});

return data.supportedTokens;
};

const getBridgeProtocols: GetBridgeProtocols = async (requestParams) => {
const fetchURL = `${deltaBridgeUrl}/bridge-protocols` as const;

const data = await fetcher<BridgeProtocolsResponse>({
url: fetchURL,
method: 'GET',
requestParams,
});

return data.bridgeProtocols;
};

return {
getBridgeInfo,
getBridgeProtocols,
};
};
29 changes: 25 additions & 4 deletions src/methods/delta/getDeltaPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,22 @@ export type DeltaPriceParams = {

includeAgents?: string[];
excludeAgents?: string[];
includeBridges?: string[];
excludeBridges?: string[];

/** @description Allow swap on destChain after bridge. Default is true. */
allowBridgeAndSwap?: boolean;
};

type DeltaPriceQueryOptions = Omit<
DeltaPriceParams,
'includeAgents' | 'excludeAgents'
'includeAgents' | 'excludeAgents' | 'includeBridges' | 'excludeBridges'
> & {
chainId: number; // will return error from API on unsupported chains
includeAgents?: string;
excludeAgents?: string;
includeBridges?: string;
excludeBridges?: string;
};

// for same-chain Orders, all 0 params
Expand Down Expand Up @@ -91,9 +98,9 @@ type AvailableBridgePrice = Pick<
DeltaPrice,
| 'destToken'
| 'destAmount'
| 'destAmountBeforeFee'
| 'destAmountBeforeFee' // Available for SELL side
| 'destUSD'
| 'destUSDBeforeFee'
| 'destUSDBeforeFee' // Available for SELL side
| 'gasCostUSD'
| 'gasCost'
| 'gasCostUSDBeforeFee'
Expand Down Expand Up @@ -164,20 +171,34 @@ export const constructGetDeltaPrice = ({
options: DeltaPriceParams,
requestParams?: RequestParameters
): Promise<DeltaPrice | BridgePrice> {
const { includeAgents, excludeAgents, ...rest } = options;
const {
includeAgents,
excludeAgents,
includeBridges,
excludeBridges,
...rest
} = options;
const includeAgentsString = includeAgents
? includeAgents.join(',')
: undefined;
const excludeAgentsString = excludeAgents
? excludeAgents.join(',')
: undefined;
const includeBridgesString = includeBridges
? includeBridges.join(',')
: undefined;
const excludeBridgesString = excludeBridges
? excludeBridges.join(',')
: undefined;

const search = constructSearchString<DeltaPriceQueryOptions>({
...rest,
chainId,
side: options.side ?? SwapSide.SELL,
includeAgents: includeAgentsString,
excludeAgents: excludeAgentsString,
includeBridges: includeBridgesString,
excludeBridges: excludeBridgesString,
});

const fetchURL = `${pricesUrl}/${search}` as const;
Expand Down
16 changes: 1 addition & 15 deletions src/methods/delta/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,6 @@ export type BridgeStatus = 'pending' | 'filled' | 'expired' | 'refunded';

//// available on BridgePrice ////

// so far
type ProtocolName =
| 'Across'
| 'StargateBus'
| 'StargateTaxi'
| 'StargateOftV2'
| 'Relay'
| 'CCTPFast'
| 'CCTPStandard'
| 'Celer'
| 'Canonical'
| 'Polygon'
| 'Arbitrum';

type BridgeQuoteFee = {
feeToken: string;
amount: string;
Expand All @@ -160,7 +146,7 @@ type BridgeQuoteFee = {
};

export type BridgePriceInfo = {
protocolName: ProtocolName;
protocolName: string;
destAmountAfterBridge: string;
destUSDAfterBridge: string;
fees: BridgeQuoteFee[];
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/delta.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`Delta:methods Build Delta Order 1`] = `
"metadata": "0x",
"nonce": "dynamic_number",
"owner": "0xaC39b311DCEb2A4b2f5d8461c1cdaF756F4F7Ae9",
"partnerAndFee": "0",
"partnerAndFee": "512",
"permit": "0x",
"srcAmount": "1000000000000000000",
"srcToken": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
Expand Down Expand Up @@ -482,7 +482,7 @@ exports[`Delta:methods Submit(=build+sign+post) Delta Order 1`] = `
"metadata": "0x",
"nonce": "dynamic_number",
"owner": "0xaC39b311DCEb2A4b2f5d8461c1cdaF756F4F7Ae9",
"partnerAndFee": "0",
"partnerAndFee": "512",
"permit": "0x",
"srcAmount": "1000000000000000000",
"srcToken": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
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 @@ -4,10 +4,6 @@ exports[`Partial SDK: fetching methods: axiosFetcher Get_Adapters: Get_Adapters
[
"Bancor",
"Compound",
"DODOV1",
"DODOV2",
"TraderJoeV2.1",
"Smoothy",
"CurveV2",
"Lido",
"EtherFi",
Expand All @@ -17,7 +13,6 @@ exports[`Partial SDK: fetching methods: axiosFetcher Get_Adapters: Get_Adapters
"BalancerV2",
"UniswapV2",
"DefiSwap",
"LinkSwap",
"SushiSwap",
"ShibaSwap",
"Verse",
Expand All @@ -31,7 +26,6 @@ exports[`Partial SDK: fetching methods: axiosFetcher Get_Adapters: Get_Adapters
"Weth",
"PolygonMigrator",
"Synapse",
"SolidlyV2",
"Synthetix",
"CurveV1Factory",
"CurveV1StableNg",
Expand Down Expand Up @@ -126,10 +120,6 @@ exports[`Partial SDK: fetching methods: fetchFetcher Get_Adapters: Get_Adapters
[
"Bancor",
"Compound",
"DODOV1",
"DODOV2",
"TraderJoeV2.1",
"Smoothy",
"CurveV2",
"Lido",
"EtherFi",
Expand All @@ -139,7 +129,6 @@ exports[`Partial SDK: fetching methods: fetchFetcher Get_Adapters: Get_Adapters
"BalancerV2",
"UniswapV2",
"DefiSwap",
"LinkSwap",
"SushiSwap",
"ShibaSwap",
"Verse",
Expand All @@ -153,7 +142,6 @@ exports[`Partial SDK: fetching methods: fetchFetcher Get_Adapters: Get_Adapters
"Weth",
"PolygonMigrator",
"Synapse",
"SolidlyV2",
"Synthetix",
"CurveV1Factory",
"CurveV1StableNg",
Expand Down
12 changes: 0 additions & 12 deletions tests/__snapshots__/simpleSdk.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ exports[`Simple SDK: fetcher made with: axios Get_Adapters: Get_Adapters 1`] = `
[
"Bancor",
"Compound",
"DODOV1",
"DODOV2",
"TraderJoeV2.1",
"Smoothy",
"CurveV2",
"Lido",
"EtherFi",
Expand All @@ -20,7 +16,6 @@ exports[`Simple SDK: fetcher made with: axios Get_Adapters: Get_Adapters 1`] = `
"BalancerV3",
"UniswapV2",
"DefiSwap",
"LinkSwap",
"SushiSwap",
"ShibaSwap",
"Verse",
Expand All @@ -35,7 +30,6 @@ exports[`Simple SDK: fetcher made with: axios Get_Adapters: Get_Adapters 1`] = `
"Weth",
"PolygonMigrator",
"Synapse",
"SolidlyV2",
"Synthetix",
"CurveV1Factory",
"CurveV1StableNg",
Expand Down Expand Up @@ -151,10 +145,6 @@ exports[`Simple SDK: fetcher made with: fetch Get_Adapters: Get_Adapters 1`] = `
[
"Bancor",
"Compound",
"DODOV1",
"DODOV2",
"TraderJoeV2.1",
"Smoothy",
"CurveV2",
"Lido",
"EtherFi",
Expand All @@ -167,7 +157,6 @@ exports[`Simple SDK: fetcher made with: fetch Get_Adapters: Get_Adapters 1`] = `
"BalancerV3",
"UniswapV2",
"DefiSwap",
"LinkSwap",
"SushiSwap",
"ShibaSwap",
"Verse",
Expand All @@ -182,7 +171,6 @@ exports[`Simple SDK: fetcher made with: fetch Get_Adapters: Get_Adapters 1`] = `
"Weth",
"PolygonMigrator",
"Synapse",
"SolidlyV2",
"Synthetix",
"CurveV1Factory",
"CurveV1StableNg",
Expand Down
Loading
Loading