@velora-dex/sdk 8.0.0 → 8.1.1-dev.0

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.
Files changed (66) hide show
  1. package/README.md +73 -11
  2. package/dist/examples/helpers/delta.d.ts +5 -0
  3. package/dist/examples/helpers/delta.d.ts.map +1 -0
  4. package/dist/helpers/misc.d.ts +4 -0
  5. package/dist/helpers/misc.d.ts.map +1 -1
  6. package/dist/helpers/providers/viem.d.ts +1 -1
  7. package/dist/helpers/providers/viem.d.ts.map +1 -1
  8. package/dist/index.d.ts +3 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/methods/delta/buildCrosschainOrderBridge.d.ts +1 -1
  11. package/dist/methods/delta/buildCrosschainOrderBridge.d.ts.map +1 -1
  12. package/dist/methods/delta/buildDeltaOrder.d.ts +9 -6
  13. package/dist/methods/delta/buildDeltaOrder.d.ts.map +1 -1
  14. package/dist/methods/delta/cancelDeltaOrder.d.ts +22 -0
  15. package/dist/methods/delta/cancelDeltaOrder.d.ts.map +1 -0
  16. package/dist/methods/delta/getDeltaOrders.d.ts +11 -1
  17. package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
  18. package/dist/methods/delta/getDeltaPrice.d.ts +28 -9
  19. package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
  20. package/dist/methods/delta/helpers/across.d.ts +3 -6
  21. package/dist/methods/delta/helpers/across.d.ts.map +1 -1
  22. package/dist/methods/delta/helpers/buildCancelDeltaOrderData.d.ts +25 -0
  23. package/dist/methods/delta/helpers/buildCancelDeltaOrderData.d.ts.map +1 -0
  24. package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts +3 -3
  25. package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts.map +1 -1
  26. package/dist/methods/delta/helpers/misc.d.ts +1 -1
  27. package/dist/methods/delta/helpers/misc.d.ts.map +1 -1
  28. package/dist/methods/delta/helpers/types.d.ts +34 -6
  29. package/dist/methods/delta/helpers/types.d.ts.map +1 -1
  30. package/dist/methods/delta/index.d.ts +7 -5
  31. package/dist/methods/delta/index.d.ts.map +1 -1
  32. package/dist/methods/delta/postDeltaOrder.d.ts +9 -1
  33. package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -1
  34. package/dist/methods/quote/getQuote.d.ts +27 -6
  35. package/dist/methods/quote/getQuote.d.ts.map +1 -1
  36. package/dist/sdk.cjs.development.js +364 -490
  37. package/dist/sdk.cjs.development.js.map +1 -1
  38. package/dist/sdk.cjs.production.min.js +1 -1
  39. package/dist/sdk.cjs.production.min.js.map +1 -1
  40. package/dist/sdk.esm.js +364 -491
  41. package/dist/sdk.esm.js.map +1 -1
  42. package/docs/DELTA.md +69 -7
  43. package/package.json +1 -1
  44. package/src/examples/delta.ts +5 -10
  45. package/src/examples/helpers/delta.ts +39 -0
  46. package/src/examples/quote.ts +6 -8
  47. package/src/examples/simpleQuote.ts +3 -5
  48. package/src/helpers/misc.ts +8 -0
  49. package/src/helpers/providers/viem.ts +4 -1
  50. package/src/index.ts +6 -0
  51. package/src/methods/delta/buildCrosschainOrderBridge.ts +25 -13
  52. package/src/methods/delta/buildDeltaOrder.ts +36 -66
  53. package/src/methods/delta/cancelDeltaOrder.ts +111 -0
  54. package/src/methods/delta/getDeltaOrders.ts +38 -0
  55. package/src/methods/delta/getDeltaPrice.ts +59 -14
  56. package/src/methods/delta/helpers/across.ts +26 -92
  57. package/src/methods/delta/helpers/buildCancelDeltaOrderData.ts +48 -0
  58. package/src/methods/delta/helpers/buildDeltaOrderData.ts +36 -11
  59. package/src/methods/delta/helpers/misc.ts +6 -2
  60. package/src/methods/delta/helpers/types.ts +55 -7
  61. package/src/methods/delta/index.ts +19 -4
  62. package/src/methods/delta/postDeltaOrder.ts +11 -1
  63. package/src/methods/quote/getQuote.ts +60 -9
  64. package/dist/methods/delta/helpers/composePermit.d.ts +0 -5
  65. package/dist/methods/delta/helpers/composePermit.d.ts.map +0 -1
  66. package/src/methods/delta/helpers/composePermit.ts +0 -76
package/docs/DELTA.md CHANGED
@@ -80,10 +80,41 @@ const deltaAuction = await deltaSDK.submitDeltaOrder({
80
80
 
81
81
  ```ts
82
82
  // poll if necessary
83
- const auction = await deltaSDK.getDeltaOrderById(deltaAuction.id);
84
- if (auction?.status === 'EXECUTED') {
85
- console.log('Auction was executed');
83
+ function isExecutedDeltaAuction(
84
+ auction: Omit<DeltaAuction, 'signature'>,
85
+ waitForCrosschain = true // only consider executed when destChain work is done
86
+ ) {
87
+ if (auction.status !== 'EXECUTED') return false;
88
+
89
+ // crosschain Order is executed on destChain if bridgeStatus is filled
90
+ if (waitForCrosschain && auction.order.bridge.destinationChainId !== 0) {
91
+ return auction.bridgeStatus === 'filled';
92
+ }
93
+
94
+ return true;
86
95
  }
96
+
97
+ function fetchOrderPeriodically(auctionId: string) {
98
+ const intervalId = setInterval(async () => {
99
+ const auction = await simpleSDK.delta.getDeltaOrderById(auctionId);
100
+ console.log('checks: ', auction); // Handle or log the fetched auction as needed
101
+
102
+ if (isExecutedDeltaAuction(auction)) {
103
+ clearInterval(intervalId); // Stop interval if completed
104
+ console.log('Order completed');
105
+ }
106
+ }, 3000);
107
+ console.log('Order Pending');
108
+ // Return intervalId to enable clearing the interval if needed externally
109
+ return intervalId;
110
+ }
111
+
112
+ function startStatusCheck(auctionId: string) {
113
+ const intervalId = fetchOrderPeriodically(auctionId);
114
+ setTimeout(() => clearInterval(intervalId), 60000 * 5); // Stop after 5 minutes
115
+ }
116
+
117
+ startStatusCheck(deltaAuction.id);
87
118
  ```
88
119
 
89
120
  #### A more detailed example of Delta Order usage can be found in [examples/delta](./src/examples/delta.ts)
@@ -200,8 +231,39 @@ This is necessary because Across, the service facilitating crosschain bridging,
200
231
 
201
232
  ```ts
202
233
  // poll if necessary
203
- const auction = await deltaSDK.getDeltaOrderById(deltaAuction.id);
204
- if (auction?.status === 'EXECUTED' && auction.bridgeStatus === "filled") {
205
- console.log('Auction was executed');
234
+ function isExecutedDeltaAuction(
235
+ auction: Omit<DeltaAuction, 'signature'>,
236
+ waitForCrosschain = true // only consider executed when destChain work is done
237
+ ) {
238
+ if (auction.status !== 'EXECUTED') return false;
239
+
240
+ // crosschain Order is executed on destChain if bridgeStatus is filled
241
+ if (waitForCrosschain && auction.order.bridge.destinationChainId !== 0) {
242
+ return auction.bridgeStatus === 'filled';
243
+ }
244
+
245
+ return true;
206
246
  }
207
- ```
247
+
248
+ function fetchOrderPeriodically(auctionId: string) {
249
+ const intervalId = setInterval(async () => {
250
+ const auction = await simpleSDK.delta.getDeltaOrderById(auctionId);
251
+ console.log('checks: ', auction); // Handle or log the fetched auction as needed
252
+
253
+ if (isExecutedDeltaAuction(auction)) {
254
+ clearInterval(intervalId); // Stop interval if completed
255
+ console.log('Order completed');
256
+ }
257
+ }, 3000);
258
+ console.log('Order Pending');
259
+ // Return intervalId to enable clearing the interval if needed externally
260
+ return intervalId;
261
+ }
262
+
263
+ function startStatusCheck(auctionId: string) {
264
+ const intervalId = fetchOrderPeriodically(auctionId);
265
+ setTimeout(() => clearInterval(intervalId), 60000 * 5); // Stop after 5 minutes
266
+ }
267
+
268
+ startStatusCheck(deltaAuction.id);
269
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velora-dex/sdk",
3
- "version": "8.0.0",
3
+ "version": "8.1.1-dev.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/sdk.esm.js",
6
6
  "typings": "dist/index.d.ts",
@@ -7,6 +7,7 @@ import {
7
7
  constructAxiosFetcher,
8
8
  constructAllDeltaOrdersHandlers,
9
9
  } from '..';
10
+ import { startStatusCheck } from './helpers/delta';
10
11
 
11
12
  const fetcher = constructAxiosFetcher(axios);
12
13
 
@@ -40,7 +41,7 @@ async function simpleDeltaFlow() {
40
41
  amount,
41
42
  userAddress: account,
42
43
  srcDecimals: 18,
43
- destDecimals: 18,
44
+ destDecimals: 6,
44
45
  // partner: "..." // if available
45
46
  });
46
47
 
@@ -70,10 +71,7 @@ async function simpleDeltaFlow() {
70
71
  });
71
72
 
72
73
  // poll if necessary
73
- const auction = await deltaSDK.getDeltaOrderById(deltaAuction.id);
74
- if (auction?.status === 'EXECUTED') {
75
- console.log('Auction was executed');
76
- }
74
+ startStatusCheck(() => deltaSDK.getDeltaOrderById(deltaAuction.id));
77
75
  }
78
76
  async function manualDeltaFlow() {
79
77
  const amount = '1000000000000'; // wei
@@ -84,7 +82,7 @@ async function manualDeltaFlow() {
84
82
  amount,
85
83
  userAddress: account,
86
84
  srcDecimals: 18,
87
- destDecimals: 18,
85
+ destDecimals: 6,
88
86
  // partner: "..." // if available
89
87
  });
90
88
 
@@ -120,8 +118,5 @@ async function manualDeltaFlow() {
120
118
  });
121
119
 
122
120
  // poll if necessary
123
- const auction = await deltaSDK.getDeltaOrderById(deltaAuction.id);
124
- if (auction?.status === 'EXECUTED') {
125
- console.log('Auction was executed');
126
- }
121
+ startStatusCheck(() => deltaSDK.getDeltaOrderById(deltaAuction.id));
127
122
  }
@@ -0,0 +1,39 @@
1
+ import { DeltaAuction, GetDeltaOrdersFunctions } from '../..';
2
+
3
+ function isExecutedDeltaAuction(
4
+ auction: Omit<DeltaAuction, 'signature'>,
5
+ waitForCrosschain = true // only consider executed when destChain work is done
6
+ ) {
7
+ if (auction.status !== 'EXECUTED') return false;
8
+
9
+ // crosschain Order is executed on destChain if bridgeStatus is filled
10
+ if (waitForCrosschain && auction.order.bridge.destinationChainId !== 0) {
11
+ return auction.bridgeStatus === 'filled';
12
+ }
13
+
14
+ return true;
15
+ }
16
+
17
+ type GetDeltaOrderFn = () => ReturnType<
18
+ GetDeltaOrdersFunctions['getDeltaOrderById']
19
+ >;
20
+
21
+ function fetchOrderPeriodically(getDeltaOrder: GetDeltaOrderFn) {
22
+ const intervalId = setInterval(async () => {
23
+ const auction = await getDeltaOrder();
24
+ console.log('checks: ', auction); // Handle or log the fetched auction as needed
25
+
26
+ if (isExecutedDeltaAuction(auction)) {
27
+ clearInterval(intervalId); // Stop interval if completed
28
+ console.log('Order completed');
29
+ }
30
+ }, 3000);
31
+ console.log('Order Pending');
32
+ // Return intervalId to enable clearing the interval if needed externally
33
+ return intervalId;
34
+ }
35
+
36
+ export function startStatusCheck(getDeltaOrder: GetDeltaOrderFn) {
37
+ const intervalId = fetchOrderPeriodically(getDeltaOrder);
38
+ setTimeout(() => clearInterval(intervalId), 60000 * 5); // Stop after 5 minutes
39
+ }
@@ -12,6 +12,7 @@ import {
12
12
  DeltaPrice,
13
13
  isFetcherError,
14
14
  } from '..';
15
+ import { startStatusCheck } from './helpers/delta';
15
16
 
16
17
  const fetcher = constructAxiosFetcher(axios);
17
18
 
@@ -50,7 +51,7 @@ async function deltaQuote() {
50
51
  amount,
51
52
  userAddress: account,
52
53
  srcDecimals: 18,
53
- destDecimals: 18,
54
+ destDecimals: 6,
54
55
  mode: 'delta',
55
56
  side: 'SELL',
56
57
  // partner: "..." // if available
@@ -79,7 +80,7 @@ async function marketQuote() {
79
80
  amount,
80
81
  userAddress: account,
81
82
  srcDecimals: 18,
82
- destDecimals: 18,
83
+ destDecimals: 6,
83
84
  mode: 'market',
84
85
  side: 'SELL',
85
86
  // partner: "..." // if available
@@ -115,7 +116,7 @@ async function allQuote() {
115
116
  amount,
116
117
  userAddress: account,
117
118
  srcDecimals: 18,
118
- destDecimals: 18,
119
+ destDecimals: 6,
119
120
  mode: 'all',
120
121
  side: 'SELL',
121
122
  // partner: "..." // if available
@@ -170,12 +171,9 @@ async function handleDeltaQuote({
170
171
  });
171
172
 
172
173
  // poll if necessary
173
- const auction = await quoteSDK.getDeltaOrderById(deltaAuction.id);
174
- if (auction?.status === 'EXECUTED') {
175
- console.log('Auction was executed');
176
- }
174
+ startStatusCheck(() => quoteSDK.getDeltaOrderById(deltaAuction.id));
177
175
 
178
- return auction;
176
+ return deltaAuction;
179
177
  }
180
178
 
181
179
  async function handleMarketQuote({
@@ -2,6 +2,7 @@
2
2
  import axios from 'axios';
3
3
  import { ethers } from 'ethersV5';
4
4
  import { constructSimpleSDK } from '..';
5
+ import { startStatusCheck } from './helpers/delta';
5
6
 
6
7
  const DAI_TOKEN = '0x6b175474e89094c44da98b954eedeac495271d0f';
7
8
  const USDC_TOKEN = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
@@ -31,7 +32,7 @@ async function allQuote() {
31
32
  amount,
32
33
  userAddress: account,
33
34
  srcDecimals: 18,
34
- destDecimals: 18,
35
+ destDecimals: 6,
35
36
  mode: 'all', // Delta quote if possible, with fallback to Market price
36
37
  side: 'SELL',
37
38
  // partner: "..." // if available
@@ -68,10 +69,7 @@ async function allQuote() {
68
69
  });
69
70
 
70
71
  // poll if necessary
71
- const auction = await simpleSDK.delta.getDeltaOrderById(deltaAuction.id);
72
- if (auction?.status === 'EXECUTED') {
73
- console.log('Auction was executed');
74
- }
72
+ startStatusCheck(() => simpleSDK.delta.getDeltaOrderById(deltaAuction.id));
75
73
  } else {
76
74
  console.log(
77
75
  `Delta Quote failed: ${quote.fallbackReason.errorType} - ${quote.fallbackReason.details}`
@@ -90,6 +90,9 @@ export class FetcherError extends Error implements FetcherErrorInterface {
90
90
  const { data, status } = response;
91
91
  this.status = status;
92
92
  this.message = isDataWithError(data) ? data.error : message;
93
+ this.message = isDataWithError2(data)
94
+ ? `${data.errorType}${data.description ? `: ${data.description}` : ''}`
95
+ : this.message;
93
96
  }
94
97
  }
95
98
  // to turn `object -> Record` for indexed variable access
@@ -100,6 +103,11 @@ function isObject(obj: unknown): obj is Record<string | symbol, any> {
100
103
  export function isDataWithError(data: unknown): data is { error: string } {
101
104
  return isObject(data) && typeof data['error'] === 'string';
102
105
  }
106
+ export function isDataWithError2(
107
+ data: unknown
108
+ ): data is { errorType: string; description?: string } {
109
+ return isObject(data) && typeof data['errorType'] === 'string';
110
+ }
103
111
 
104
112
  export type ExtractAbiMethodNames<T extends readonly { name: string }[]> =
105
113
  T[number]['name'];
@@ -23,7 +23,10 @@ import { TransactionParams } from '../../methods/swap/transaction';
23
23
 
24
24
  export type MinViemClient = Partial<
25
25
  Pick<PublicActions<Transport, Chain>, 'readContract'> &
26
- Pick<WalletActions<Chain>, 'writeContract' | 'signTypedData'>
26
+ Pick<
27
+ WalletActions<Chain>,
28
+ 'writeContract' | 'signTypedData' | 'signMessage'
29
+ >
27
30
  > & { account?: Account };
28
31
 
29
32
  export const constructContractCaller = (
package/src/index.ts CHANGED
@@ -206,6 +206,10 @@ import {
206
206
  QuoteWithMarketPrice,
207
207
  QuoteWithMarketPriceAsFallback,
208
208
  } from './methods/quote/getQuote';
209
+ import {
210
+ CancelDeltaOrderFunctions,
211
+ constructCancelDeltaOrder,
212
+ } from './methods/delta/cancelDeltaOrder';
209
213
 
210
214
  export { constructSwapSDK, SwapSDKMethods } from './methods/swap';
211
215
 
@@ -289,6 +293,7 @@ export {
289
293
  constructGetDeltaContract,
290
294
  constructGetDeltaPrice,
291
295
  constructGetDeltaOrders,
296
+ constructCancelDeltaOrder,
292
297
  constructApproveTokenForDelta,
293
298
  // Quote methods
294
299
  constructGetQuote,
@@ -378,6 +383,7 @@ export type {
378
383
  GetDeltaPriceFunctions,
379
384
  GetDeltaOrdersFunctions,
380
385
  ApproveTokenForDeltaFunctions,
386
+ CancelDeltaOrderFunctions,
381
387
  // types for Quote methods
382
388
  GetQuoteFunctions,
383
389
  QuoteParams,
@@ -1,9 +1,9 @@
1
1
  import { assert } from 'ts-essentials';
2
2
  import type { ConstructFetchInput, RequestParameters } from '../../types';
3
3
  import { BridgePrice } from './getDeltaPrice';
4
- import { constructGetMulticallHandlers } from './getMulticallHandlers';
4
+ // import { constructGetMulticallHandlers } from './getMulticallHandlers';
5
5
  import {
6
- getDeltaBridgeAndDestToken,
6
+ // getDeltaBridge,
7
7
  GetDeltaBridgeAndDestTokenOutput,
8
8
  } from './helpers/across';
9
9
  import { BeneficiaryType } from '../common/orders/types';
@@ -18,7 +18,7 @@ export type BuildCrosschainOrderBridgeParams = {
18
18
  beneficiaryType: BeneficiaryType;
19
19
 
20
20
  /** @description price response received from /delta/prices (getDeltaPrice method) */
21
- deltaPrice: Pick<BridgePrice, 'bridgeFee' | 'destToken'>;
21
+ deltaPrice: BridgePrice;
22
22
  };
23
23
 
24
24
  type BuildCrosschainOrderBridge = (
@@ -39,18 +39,23 @@ export const constructBuildCrosschainOrderBridge = (
39
39
  const { chainId } = options;
40
40
 
41
41
  // cached internally for `multicall` contracts
42
- const { getMulticallHandlers } = constructGetMulticallHandlers(options);
42
+ // const { getMulticallHandlers } = constructGetMulticallHandlers(options);
43
43
 
44
44
  const buildCrosschainOrderBridge: BuildCrosschainOrderBridge = async (
45
45
  { destToken, destChainId, beneficiaryType, deltaPrice },
46
46
  requestParams
47
47
  ) => {
48
48
  assert(
49
- chainId !== destChainId,
50
- '`destChainId` must be different from `chainId` for crosschain Order.bridge'
49
+ chainId !== deltaPrice.bridge.destinationChainId,
50
+ '`deltaPrice.bridge.destinationChainId` must be different from `chainId` for crosschain Order.bridge'
51
51
  );
52
52
 
53
- const getMulticallHandler = async (chainId: number) => {
53
+ assert(
54
+ destChainId === deltaPrice.bridge.destinationChainId,
55
+ '`destChainId` must match `deltaPrice.bridge.destinationChainId` for crosschain Order.bridge'
56
+ );
57
+
58
+ /* const getMulticallHandler = async (chainId: number) => {
54
59
  const multicallHandlersMap = await getMulticallHandlers(requestParams);
55
60
  const multicallHandler = multicallHandlersMap[chainId];
56
61
 
@@ -62,19 +67,26 @@ export const constructBuildCrosschainOrderBridge = (
62
67
  return multicallHandler;
63
68
  };
64
69
 
65
- const { bridge, orderChanges } = await getDeltaBridgeAndDestToken({
70
+ const { bridge } = await getDeltaBridge({
66
71
  destTokenDestChain: destToken,
67
- destChainId: destChainId,
68
- destTokenSrcChain: deltaPrice.destToken,
69
- srcChainId: chainId,
72
+ destChainId,
70
73
  bridgeFee: deltaPrice.bridgeFee,
74
+ bridgeOutputToken: deltaPrice.bridge.outputToken,
71
75
  beneficiaryType,
72
76
  getMulticallHandler,
73
- });
77
+ }); */
78
+
79
+ // @TODO remove the whole buildCrosschainOrderBridge() when API provides BridgePrice.bridge = whole Bridge object
80
+ const bridge = {
81
+ protocolSelector: '0x00000000',
82
+ scalingFactor: 0,
83
+ protocolData: '0x',
84
+ destinationChainId: deltaPrice.bridge.destinationChainId,
85
+ outputToken: deltaPrice.bridge.outputToken,
86
+ };
74
87
 
75
88
  return {
76
89
  bridge,
77
- orderChanges,
78
90
  };
79
91
  };
80
92
 
@@ -1,19 +1,23 @@
1
- import { assert } from 'ts-essentials';
2
- import type { ConstructFetchInput, RequestParameters } from '../../types';
3
- import { ZERO_ADDRESS } from '../common/orders/buildOrderData';
1
+ import type {
2
+ ConstructFetchInput,
3
+ EnumerateLiteral,
4
+ RequestParameters,
5
+ } from '../../types';
4
6
  import { constructGetDeltaContract } from './getDeltaContract';
5
- import { BridgePrice, DeltaPrice } from './getDeltaPrice';
7
+ import { BridgePrice } from './getDeltaPrice';
6
8
  import { constructGetPartnerFee } from './getPartnerFee';
7
9
  import {
8
10
  buildDeltaSignableOrderData,
9
11
  type BuildDeltaOrderDataInput,
10
12
  type SignableDeltaOrderData,
11
13
  } from './helpers/buildDeltaOrderData';
12
- import { Bridge, DeltaAuctionOrder } from './helpers/types';
13
- import { constructBuildCrosschainOrderBridge } from './buildCrosschainOrderBridge';
14
+ import { SwapSideToOrderKind } from './helpers/types';
14
15
  import { BeneficiaryType } from '../common/orders/types';
16
+ import { SwapSide } from '../../constants';
15
17
  export type { SignableDeltaOrderData } from './helpers/buildDeltaOrderData';
16
18
 
19
+ type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
20
+
17
21
  export type BuildDeltaOrderDataParams = {
18
22
  /** @description The address of the order owner */
19
23
  owner: string;
@@ -36,8 +40,6 @@ export type BuildDeltaOrderDataParams = {
36
40
  /** @description Partner string. */
37
41
  partner?: string;
38
42
 
39
- /** @description The bridge input */
40
- bridge?: Bridge;
41
43
  /** @description Destination Chain ID for Crosschain Orders */
42
44
  destChainId?: number;
43
45
  /** @description Whether the beneficiary is a contract. Needed to automatically fill in crosschain Bridge */
@@ -45,10 +47,14 @@ export type BuildDeltaOrderDataParams = {
45
47
 
46
48
  /** @description price response received from /delta/prices (getDeltaPrice method) */
47
49
  deltaPrice: Pick<
48
- DeltaPrice,
49
- 'destAmount' | 'partner' | 'partnerFee' | 'destToken'
50
- > &
51
- Partial<Pick<BridgePrice, 'bridgeFee'>>;
50
+ BridgePrice,
51
+ | 'destAmount'
52
+ | 'partner'
53
+ | 'partnerFee'
54
+ | 'destToken'
55
+ | 'srcAmount'
56
+ | 'bridge'
57
+ >;
52
58
 
53
59
  /** @description partner fee in basis points (bps), 50bps=0.5% */
54
60
  partnerFeeBps?: number;
@@ -56,6 +62,11 @@ export type BuildDeltaOrderDataParams = {
56
62
  partnerAddress?: string;
57
63
  /** @description take surplus */
58
64
  partnerTakesSurplus?: boolean;
65
+
66
+ /** @description The side of the order. Default is SELL */
67
+ side?: SwapSideUnion;
68
+ /** @description Metadata for the order, hex string */
69
+ metadata?: string;
59
70
  };
60
71
 
61
72
  type BuildDeltaOrder = (
@@ -68,14 +79,6 @@ export type BuildDeltaOrderFunctions = {
68
79
  buildDeltaOrder: BuildDeltaOrder;
69
80
  };
70
81
 
71
- // for same-chain Orders, all 0 params
72
- const DEFAULT_BRIDGE: Bridge = {
73
- maxRelayerFee: '0',
74
- destinationChainId: 0,
75
- outputToken: ZERO_ADDRESS,
76
- multiCallHandler: ZERO_ADDRESS,
77
- };
78
-
79
82
  export const constructBuildDeltaOrder = (
80
83
  options: ConstructFetchInput
81
84
  ): BuildDeltaOrderFunctions => {
@@ -86,9 +89,6 @@ export const constructBuildDeltaOrder = (
86
89
  // cached internally for `partner`
87
90
  const { getPartnerFee } = constructGetPartnerFee(options);
88
91
 
89
- const { buildCrosschainOrderBridge } =
90
- constructBuildCrosschainOrderBridge(options);
91
-
92
92
  const buildDeltaOrder: BuildDeltaOrder = async (options, requestParams) => {
93
93
  const ParaswapDelta = await getDeltaContract(requestParams);
94
94
  if (!ParaswapDelta) {
@@ -121,58 +121,28 @@ export const constructBuildDeltaOrder = (
121
121
  partnerTakesSurplus ?? partnerFeeResponse.takeSurplus;
122
122
  }
123
123
 
124
- ////// Bridge logic //////
125
-
126
- // Bridge is necessary for Crosschain Delta Orders
127
- let bridge = options.bridge;
128
- let partialChangedOrder: Pick<DeltaAuctionOrder, 'destToken'> | null = null;
129
-
130
- // give preference to user-provided bridge
131
- if (!bridge) {
132
- // no bridge passed in input
133
-
134
- if (options.destChainId && chainId !== options.destChainId) {
135
- // crosschain Delta Order
136
- const deltaPrice = options.deltaPrice;
137
- assert(
138
- deltaPrice.bridgeFee,
139
- '`bridgeFee` is required in `deltaPrice` for crosschain Delta Orders'
140
- );
141
-
142
- const { bridge: constructedBridge, orderChanges } =
143
- await buildCrosschainOrderBridge(
144
- {
145
- destToken: options.destToken,
146
- destChainId: options.destChainId,
147
- beneficiaryType: options.beneficiaryType ?? 'EOA',
148
- deltaPrice: {
149
- bridgeFee: deltaPrice.bridgeFee,
150
- destToken: deltaPrice.destToken,
151
- },
152
- },
153
- requestParams
154
- );
155
-
156
- bridge = constructedBridge;
157
- partialChangedOrder = orderChanges;
158
- } else {
159
- // 0-values bridge for same-chain Orders
160
- bridge = DEFAULT_BRIDGE;
161
- }
162
- }
124
+ const swapSide = options.side ?? SwapSide.SELL;
125
+
126
+ const expectedAmount =
127
+ swapSide === SwapSide.SELL
128
+ ? options.deltaPrice.destAmount
129
+ : options.deltaPrice.srcAmount;
163
130
 
164
131
  const input: BuildDeltaOrderDataInput = {
165
132
  owner: options.owner,
166
133
  beneficiary: options.beneficiary,
167
134
  srcToken: options.srcToken,
168
- // for some cases of WETH<->ETH crosschain swaps, the destToken is to WETH or ETH
169
- destToken: partialChangedOrder?.destToken ?? options.destToken,
135
+ // for some cases of WETH->ETH crosschain swaps, the destToken is changed to WETH or ETH,
136
+ // this is already reflected in deltaPrice
137
+ destToken: options.deltaPrice.destToken,
170
138
  srcAmount: options.srcAmount,
171
139
  destAmount: options.destAmount,
172
- expectedDestAmount: options.deltaPrice.destAmount,
140
+ expectedAmount,
173
141
  deadline: options.deadline,
174
142
  nonce: options.nonce?.toString(10),
175
143
  permit: options.permit,
144
+ kind: SwapSideToOrderKind[swapSide],
145
+ metadata: options.metadata,
176
146
 
177
147
  chainId,
178
148
  paraswapDeltaAddress: ParaswapDelta,
@@ -180,7 +150,7 @@ export const constructBuildDeltaOrder = (
180
150
  partnerTakesSurplus,
181
151
  partnerFeeBps,
182
152
 
183
- bridge,
153
+ bridge: options.deltaPrice.bridge, // ZERO_BRIDGE for same-chain Orders
184
154
  };
185
155
 
186
156
  return buildDeltaSignableOrderData(input);