@velora-dex/sdk 9.3.0-dev.2 → 9.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velora-dex/sdk",
3
- "version": "9.3.0-dev.2",
3
+ "version": "9.3.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/sdk.esm.js",
6
6
  "typings": "dist/index.d.ts",
@@ -93,7 +93,7 @@
93
93
  }
94
94
  },
95
95
  "dependencies": {
96
- "@paraswap/core": "2.4.0",
96
+ "@paraswap/core": "2.4.1",
97
97
  "ts-essentials": "^10.0.3",
98
98
  "viem": "^2.21.0"
99
99
  },
@@ -65,6 +65,9 @@ export type BuildDeltaOrderDataParams = {
65
65
  /** @description take surplus */
66
66
  partnerTakesSurplus?: boolean;
67
67
 
68
+ /** @description A boolean indicating whether the surplus should be capped. True by default */
69
+ capSurplus?: boolean;
70
+
68
71
  /** @description The side of the order. Default is SELL */
69
72
  side?: SwapSideUnion;
70
73
  /** @description Metadata for the order, hex string */
@@ -164,6 +167,8 @@ export const constructBuildDeltaOrder = (
164
167
  partnerTakesSurplus,
165
168
  partnerFeeBps,
166
169
 
170
+ capSurplus: options.capSurplus,
171
+
167
172
  bridge: options.deltaPrice.bridge, // ZERO_BRIDGE for same-chain Orders
168
173
  };
169
174
 
@@ -31,7 +31,7 @@ type GetBridgeInfo = (
31
31
  export type BridgeProtocolResponse = {
32
32
  protocol: string;
33
33
  displayName: string;
34
- icon: string; // CDN URL
34
+ icon: string;
35
35
  };
36
36
 
37
37
  type BridgeProtocolsResponse = {
@@ -58,7 +58,7 @@ export const constructGetBridgeInfo = ({
58
58
  const bridgesString = bridges ? bridges.join(',') : undefined;
59
59
 
60
60
  const search = constructSearchString<BridgeInfoQuery>({
61
- allowBridgeAndSwap: !!allowBridgeAndSwap,
61
+ allowBridgeAndSwap,
62
62
  bridges: bridgesString,
63
63
  });
64
64
 
@@ -94,6 +94,7 @@ export type BuildDeltaOrderDataInput = MarkOptional<
94
94
  paraswapDeltaAddress: string;
95
95
  partnerFeeBps: number;
96
96
  partnerTakesSurplus?: boolean;
97
+ capSurplus?: boolean;
97
98
  chainId: number;
98
99
  bridge: Bridge;
99
100
  };
@@ -122,6 +123,7 @@ export function buildDeltaSignableOrderData({
122
123
  partnerAddress,
123
124
  partnerFeeBps,
124
125
  partnerTakesSurplus = false,
126
+ capSurplus = true,
125
127
 
126
128
  chainId,
127
129
  paraswapDeltaAddress,
@@ -142,6 +144,7 @@ export function buildDeltaSignableOrderData({
142
144
  partnerFeeBps,
143
145
  partnerAddress,
144
146
  partnerTakesSurplus,
147
+ capSurplus,
145
148
  }),
146
149
  bridge,
147
150
  kind,
@@ -159,6 +162,7 @@ type ProducePartnerAndFeeInput = {
159
162
  partnerFeeBps: number;
160
163
  partnerAddress: string;
161
164
  partnerTakesSurplus: boolean;
165
+ capSurplus: boolean;
162
166
  };
163
167
 
164
168
  // fee and address are encoded together
@@ -166,13 +170,18 @@ function producePartnerAndFee({
166
170
  partnerFeeBps,
167
171
  partnerAddress,
168
172
  partnerTakesSurplus,
173
+ capSurplus,
169
174
  }: ProducePartnerAndFeeInput): string {
170
- if (partnerAddress === ZERO_ADDRESS) return '0';
171
-
172
- const partnerAndFee =
173
- (BigInt(partnerAddress) << BigInt(96)) |
174
- BigInt(partnerFeeBps.toFixed(0)) |
175
- (BigInt(partnerTakesSurplus) << BigInt(8));
176
-
177
- return partnerAndFee.toString(10);
175
+ const capSurplusShifted = BigInt(capSurplus) << BigInt(9);
176
+ if (partnerAddress === ZERO_ADDRESS) {
177
+ return capSurplusShifted.toString(10);
178
+ } else {
179
+ const partnerAndFee =
180
+ (BigInt(partnerAddress) << BigInt(96)) |
181
+ BigInt(partnerFeeBps.toFixed(0)) |
182
+ (BigInt(partnerTakesSurplus) << BigInt(8)) |
183
+ capSurplusShifted;
184
+
185
+ return partnerAndFee.toString(10);
186
+ }
178
187
  }
@@ -29,6 +29,10 @@ export type QuoteParams<M extends TradeMode = TradeMode> = {
29
29
  userAddress?: string;
30
30
  /** @description Partner string */
31
31
  partner?: string;
32
+ /** @description Maximum price impact (in percentage) acceptable for the trade */
33
+ maxImpact?: number;
34
+ /** @description Maximum price impact (in USD) acceptable for the trade */
35
+ maxUSDImpact?: number;
32
36
  /** @description Preferred mode for the trade. In case of "all", Delta pricing is returned, with Market as a fallback */
33
37
  mode: M;
34
38
  };
@@ -15,7 +15,7 @@ export type GetAdaptersFunctions = {
15
15
  };
16
16
 
17
17
  type SearchStringParams = {
18
- network: number;
18
+ chainId: number;
19
19
  version?: APIVersion;
20
20
  };
21
21
 
@@ -30,7 +30,7 @@ export const constructGetAdapters = ({
30
30
  ): Promise<AdaptersAsStrings> => {
31
31
  // always pass explicit type to make sure UrlSearchParams are correct
32
32
  const query = constructSearchString<SearchStringParams>({
33
- network: chainId,
33
+ chainId,
34
34
  version,
35
35
  });
36
36
 
@@ -42,9 +42,9 @@ type RateQueryParams = {
42
42
  side?: 'SELL' | 'BUY';
43
43
 
44
44
  /**
45
- * @description Network ID. (Mainnet - 1, Optimism - 10, BSC - 56, Polygon - 137, Fantom - 250, zkEVM - 1101, Base - 8453, Arbitrum - 42161, Avalanche - 43114). Default: `1`.
45
+ * @description Chain ID. (Mainnet - 1, Optimism - 10, BSC - 56, Polygon - 137, Base - 8453, Arbitrum - 42161, Avalanche - 43114, Gnosis - 100, Unichain - 130, Sonic - 146). Default: `1`.
46
46
  */
47
- network?: number;
47
+ chainId?: number;
48
48
 
49
49
  /**
50
50
  * @description If provided, **others** object is filled in the response with price quotes from other exchanges _(if available for comparison)_. Default: `false`.
@@ -221,7 +221,7 @@ export const constructGetRate = ({
221
221
  const search = constructSearchString<Omit<RateQueryParams, 'route'>>({
222
222
  srcToken,
223
223
  destToken,
224
- network: chainId,
224
+ chainId,
225
225
  version,
226
226
  ...parsedOptions,
227
227
  });
@@ -253,7 +253,7 @@ export const constructGetRate = ({
253
253
  Omit<RateQueryParams, 'srcToken' | 'destToken'>
254
254
  >({
255
255
  route: _route, // route can be used in place of srcToken+destToken
256
- network: chainId,
256
+ chainId,
257
257
  version,
258
258
  ...parsedOptions,
259
259
  });
@@ -36,8 +36,8 @@ export const constructGetSpender = ({
36
36
  chainId,
37
37
  fetcher,
38
38
  }: ConstructFetchInput): GetSpenderFunctions => {
39
- const search = constructSearchString<{ network: number; version: string }>({
40
- network: chainId,
39
+ const search = constructSearchString<{ chainId: number; version: string }>({
40
+ chainId,
41
41
  version,
42
42
  });
43
43
 
@@ -41,9 +41,9 @@ type SwapQueryParams = {
41
41
  side: 'SELL' | 'BUY';
42
42
 
43
43
  /**
44
- * @description Network ID. (Mainnet - 1, Optimism - 10, BSC - 56, Polygon - 137, Fantom - 250, zkEVM - 1101, Base - 8453, Arbitrum - 42161, Avalanche - 43114). Default: `1`.
44
+ * @description Chain ID. (Mainnet - 1, Optimism - 10, BSC - 56, Polygon - 137, Base - 8453, Arbitrum - 42161, Avalanche - 43114, Gnosis - 100, Unichain - 130, Sonic - 146). Default: `1`.
45
45
  */
46
- network?: number;
46
+ chainId?: number;
47
47
 
48
48
  /**
49
49
  * @description Comma Separated List of DEXs to include. **Supported DEXs:** Uniswap, Kyber, Bancor, AugustusRFQ, Oasis, Compound, Fulcrum, 0x, MakerDAO, Chai, Aave, Aave2, MultiPath, MegaPath, Curve, Curve3, Saddle, IronV2, BDai, idle, Weth, Beth, UniswapV2, Balancer, 0xRFQt, SushiSwap, LINKSWAP, Synthetix, DefiSwap, Swerve, CoFiX, Shell, DODOV1, DODOV2, OnChainPricing, PancakeSwap, PancakeSwapV2, ApeSwap, Wbnb, acryptos, streetswap, bakeryswap, julswap, vswap, vpegswap, beltfi, ellipsis, QuickSwap, COMETH, Wmatic, Nerve, Dfyn, UniswapV3, Smoothy, PantherSwap, OMM1, OneInchLP, CurveV2, mStable, WaultFinance, MDEX, ShibaSwap, CoinSwap, SakeSwap, JetSwap, Biswap, BProtocol eg: `UniswapV3,0x`.
@@ -179,7 +179,7 @@ type SwapTxInputListFields =
179
179
 
180
180
  type SwapRateOptions = Omit<
181
181
  SwapQueryParams,
182
- SwapTxInputFields | SwapTxInputListFields | 'network' | 'version'
182
+ SwapTxInputFields | SwapTxInputListFields | 'chainId' | 'version'
183
183
  > & {
184
184
  /**
185
185
  * @description List of DEXs to include. **Supported DEXs:** Uniswap, Kyber, Bancor, AugustusRFQ, Oasis, Compound, Fulcrum, 0x, MakerDAO, Chai, Aave, Aave2, MultiPath, MegaPath, Curve, Curve3, Saddle, IronV2, BDai, idle, Weth, Beth, UniswapV2, Balancer, 0xRFQt, SushiSwap, LINKSWAP, Synthetix, DefiSwap, Swerve, CoFiX, Shell, DODOV1, DODOV2, OnChainPricing, PancakeSwap, PancakeSwapV2, ApeSwap, Wbnb, acryptos, streetswap, bakeryswap, julswap, vswap, vpegswap, beltfi, ellipsis, QuickSwap, COMETH, Wmatic, Nerve, Dfyn, UniswapV3, Smoothy, PantherSwap, OMM1, OneInchLP, CurveV2, mStable, WaultFinance, MDEX, ShibaSwap, CoinSwap, SakeSwap, JetSwap, Biswap, BProtocol eg: `UniswapV3,0x`.
@@ -244,7 +244,7 @@ export const constructSwapTx = ({
244
244
  srcToken,
245
245
  destToken,
246
246
  route: _route,
247
- network: chainId,
247
+ chainId,
248
248
  version,
249
249
  ...parsedOptions,
250
250
  });