@velora-dex/sdk 8.0.0 → 8.1.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 (33) 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/methods/delta/buildCrosschainOrderBridge.d.ts +1 -1
  7. package/dist/methods/delta/buildCrosschainOrderBridge.d.ts.map +1 -1
  8. package/dist/methods/delta/buildDeltaOrder.d.ts +1 -1
  9. package/dist/methods/delta/buildDeltaOrder.d.ts.map +1 -1
  10. package/dist/methods/delta/getDeltaPrice.d.ts +2 -0
  11. package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
  12. package/dist/methods/delta/helpers/across.d.ts +3 -6
  13. package/dist/methods/delta/helpers/across.d.ts.map +1 -1
  14. package/dist/methods/quote/getQuote.d.ts +25 -4
  15. package/dist/methods/quote/getQuote.d.ts.map +1 -1
  16. package/dist/sdk.cjs.development.js +67 -143
  17. package/dist/sdk.cjs.development.js.map +1 -1
  18. package/dist/sdk.cjs.production.min.js +1 -1
  19. package/dist/sdk.cjs.production.min.js.map +1 -1
  20. package/dist/sdk.esm.js +67 -143
  21. package/dist/sdk.esm.js.map +1 -1
  22. package/docs/DELTA.md +69 -7
  23. package/package.json +1 -1
  24. package/src/examples/delta.ts +5 -10
  25. package/src/examples/helpers/delta.ts +39 -0
  26. package/src/examples/quote.ts +6 -8
  27. package/src/examples/simpleQuote.ts +3 -5
  28. package/src/helpers/misc.ts +8 -0
  29. package/src/methods/delta/buildCrosschainOrderBridge.ts +12 -9
  30. package/src/methods/delta/buildDeltaOrder.ts +20 -18
  31. package/src/methods/delta/getDeltaPrice.ts +2 -0
  32. package/src/methods/delta/helpers/across.ts +25 -91
  33. package/src/methods/quote/getQuote.ts +59 -5
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.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'];
@@ -3,7 +3,7 @@ import type { ConstructFetchInput, RequestParameters } from '../../types';
3
3
  import { BridgePrice } from './getDeltaPrice';
4
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: Pick<BridgePrice, 'bridgeFee' | 'bridge'>;
22
22
  };
23
23
 
24
24
  type BuildCrosschainOrderBridge = (
@@ -46,8 +46,13 @@ export const constructBuildCrosschainOrderBridge = (
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
+ );
52
+
53
+ assert(
54
+ destChainId === deltaPrice.bridge.destinationChainId,
55
+ '`destChainId` must match `deltaPrice.bridge.destinationChainId` for crosschain Order.bridge'
51
56
  );
52
57
 
53
58
  const getMulticallHandler = async (chainId: number) => {
@@ -62,19 +67,17 @@ 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
  });
74
78
 
75
79
  return {
76
80
  bridge,
77
- orderChanges,
78
81
  };
79
82
  };
80
83
 
@@ -9,7 +9,7 @@ import {
9
9
  type BuildDeltaOrderDataInput,
10
10
  type SignableDeltaOrderData,
11
11
  } from './helpers/buildDeltaOrderData';
12
- import { Bridge, DeltaAuctionOrder } from './helpers/types';
12
+ import { Bridge } from './helpers/types';
13
13
  import { constructBuildCrosschainOrderBridge } from './buildCrosschainOrderBridge';
14
14
  import { BeneficiaryType } from '../common/orders/types';
15
15
  export type { SignableDeltaOrderData } from './helpers/buildDeltaOrderData';
@@ -48,7 +48,7 @@ export type BuildDeltaOrderDataParams = {
48
48
  DeltaPrice,
49
49
  'destAmount' | 'partner' | 'partnerFee' | 'destToken'
50
50
  > &
51
- Partial<Pick<BridgePrice, 'bridgeFee'>>;
51
+ Partial<Pick<BridgePrice, 'bridgeFee' | 'bridge'>>;
52
52
 
53
53
  /** @description partner fee in basis points (bps), 50bps=0.5% */
54
54
  partnerFeeBps?: number;
@@ -125,7 +125,6 @@ export const constructBuildDeltaOrder = (
125
125
 
126
126
  // Bridge is necessary for Crosschain Delta Orders
127
127
  let bridge = options.bridge;
128
- let partialChangedOrder: Pick<DeltaAuctionOrder, 'destToken'> | null = null;
129
128
 
130
129
  // give preference to user-provided bridge
131
130
  if (!bridge) {
@@ -138,23 +137,25 @@ export const constructBuildDeltaOrder = (
138
137
  deltaPrice.bridgeFee,
139
138
  '`bridgeFee` is required in `deltaPrice` for crosschain Delta Orders'
140
139
  );
140
+ assert(
141
+ deltaPrice.bridge,
142
+ '`bridge` is required in `deltaPrice` for crosschain Delta Orders'
143
+ );
141
144
 
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
- },
145
+ const { bridge: constructedBridge } = await buildCrosschainOrderBridge(
146
+ {
147
+ destToken: options.destToken,
148
+ destChainId: options.destChainId,
149
+ beneficiaryType: options.beneficiaryType ?? 'EOA',
150
+ deltaPrice: {
151
+ bridgeFee: deltaPrice.bridgeFee,
152
+ bridge: deltaPrice.bridge, // already contains destChainId and outputToken
152
153
  },
153
- requestParams
154
- );
154
+ },
155
+ requestParams
156
+ );
155
157
 
156
158
  bridge = constructedBridge;
157
- partialChangedOrder = orderChanges;
158
159
  } else {
159
160
  // 0-values bridge for same-chain Orders
160
161
  bridge = DEFAULT_BRIDGE;
@@ -165,8 +166,9 @@ export const constructBuildDeltaOrder = (
165
166
  owner: options.owner,
166
167
  beneficiary: options.beneficiary,
167
168
  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,
169
+ // for some cases of WETH->ETH crosschain swaps, the destToken is changed to WETH or ETH,
170
+ // this is already reflected in deltaPrice
171
+ destToken: options.deltaPrice.destToken,
170
172
  srcAmount: options.srcAmount,
171
173
  destAmount: options.destAmount,
172
174
  expectedDestAmount: options.deltaPrice.destAmount,
@@ -1,3 +1,4 @@
1
+ import { Bridge } from '../..';
1
2
  import { API_URL, SwapSide } from '../../constants';
2
3
  import { constructSearchString } from '../../helpers/misc';
3
4
  import type { ConstructFetchInput, RequestParameters } from '../../types';
@@ -51,6 +52,7 @@ export type BridgePrice = DeltaPrice & {
51
52
  bridgeFee: string;
52
53
  bridgeFeeUSD: string;
53
54
  poolAddress: string;
55
+ bridge: Pick<Bridge, 'destinationChainId' | 'outputToken'>;
54
56
  };
55
57
 
56
58
  type DeltaPriceResponse = {
@@ -1,7 +1,7 @@
1
1
  import { assert } from 'ts-essentials';
2
2
  import { ZERO_ADDRESS } from '../../common/orders/buildOrderData';
3
3
  import { BeneficiaryType } from '../../common/orders/types';
4
- import { Bridge, DeltaAuctionOrder } from './types';
4
+ import { Bridge } from './types';
5
5
 
6
6
  export const ACROSS_WETH_ADDRESSES_MAP: Record<number, string> = {
7
7
  // Mainnet
@@ -32,6 +32,8 @@ export const ACROSS_WETH_ADDRESSES_MAP: Record<number, string> = {
32
32
  81457: '0x4300000000000000000000000000000000000004',
33
33
  // Blast Sepolia
34
34
  168587773: '0x4200000000000000000000000000000000000023',
35
+ // BSC
36
+ 56: '0x2170Ed0880ac9A755fd29B2688956BD959F933F8',
35
37
  // Ink
36
38
  57073: '0x4200000000000000000000000000000000000006',
37
39
  // Ink Sepolia
@@ -98,11 +100,10 @@ export function isETHaddress(tokenAddress: string): boolean {
98
100
  // https://developers.velora.xyz/api/velora-api/velora-delta-api/build-a-delta-order-to-sign
99
101
 
100
102
  export type GetDeltaBridgeAndDestTokenInput = {
101
- destTokenDestChain: string;
103
+ destTokenDestChain: string; // the token user wants to ultimately receive
102
104
  destChainId: number;
103
- destTokenSrcChain: string;
104
- srcChainId: number;
105
105
  bridgeFee: string;
106
+ bridgeOutputToken: string; // the token on the destination chain, in case of WETH -> ETH, will be different from destTokenDestChain and unwrapped
106
107
  beneficiaryType: BeneficiaryType;
107
108
  getMulticallHandler: (chainId: number) => Promise<string>;
108
109
  };
@@ -110,16 +111,13 @@ export type GetDeltaBridgeAndDestTokenInput = {
110
111
  export type GetDeltaBridgeAndDestTokenOutput = {
111
112
  /** @description The bridge object to be used for Order.bridge */
112
113
  bridge: Bridge;
113
- /** @description The changes to be made to the Order */
114
- orderChanges: Pick<DeltaAuctionOrder, 'destToken'>;
115
114
  };
116
115
 
117
- export async function getDeltaBridgeAndDestToken({
116
+ export async function getDeltaBridge({
118
117
  destTokenDestChain,
119
118
  destChainId,
120
- destTokenSrcChain,
121
- srcChainId,
122
119
  bridgeFee,
120
+ bridgeOutputToken,
123
121
  beneficiaryType,
124
122
  getMulticallHandler,
125
123
  }: GetDeltaBridgeAndDestTokenInput): Promise<GetDeltaBridgeAndDestTokenOutput> {
@@ -127,48 +125,20 @@ export async function getDeltaBridgeAndDestToken({
127
125
  beneficiaryType === 'EOA' || beneficiaryType === 'SmartContract',
128
126
  'beneficiaryType must be EOA or SmartContract'
129
127
  );
130
- const WETH_SRC_CHAIN = ACROSS_WETH_ADDRESSES_MAP[srcChainId];
131
-
132
- const WETH_DEST_CHAIN = ACROSS_WETH_ADDRESSES_MAP[destChainId];
133
-
134
- if (!WETH_SRC_CHAIN || !WETH_DEST_CHAIN) {
135
- // this should never happen as we only expect crosschain Delta Orders for supported chains
136
- const bridge: Bridge = {
137
- maxRelayerFee: bridgeFee,
138
- destinationChainId: destChainId,
139
- outputToken: destTokenDestChain,
140
- multiCallHandler: ZERO_ADDRESS,
141
- };
142
-
143
- return {
144
- bridge,
145
- orderChanges: {
146
- destToken: destTokenSrcChain,
147
- },
148
- };
149
- }
128
+
129
+ const outputToken = bridgeOutputToken.toLowerCase(); // for uniformity
130
+
131
+ let multiCallHandler: string = ZERO_ADDRESS;
150
132
 
151
133
  if (beneficiaryType === 'EOA' && isETHaddress(destTokenDestChain)) {
152
134
  /*
153
135
  if beneficiary is an EOA and destToken on destChain = ETH
154
- order.destToken=ETH
155
- order.bridge.outputToken=WETH_DEST_CHAIN
136
+ order.destToken=ETH (deltaPrice already contains correct destToken)
137
+ order.bridge.outputToken=WETH_DEST_CHAIN (deltaPrice already contains correct bridge.outputToken)
156
138
  order.bridge.multiCallHandler=NULL_ADDRESS
157
139
  */
158
140
 
159
- const bridge: Bridge = {
160
- maxRelayerFee: bridgeFee,
161
- destinationChainId: destChainId,
162
- outputToken: WETH_DEST_CHAIN,
163
- multiCallHandler: ZERO_ADDRESS,
164
- };
165
-
166
- return {
167
- bridge,
168
- orderChanges: {
169
- destToken: ETH_ADDRESS,
170
- },
171
- };
141
+ multiCallHandler = ZERO_ADDRESS;
172
142
  }
173
143
  if (
174
144
  beneficiaryType === 'EOA' &&
@@ -176,43 +146,21 @@ export async function getDeltaBridgeAndDestToken({
176
146
  ) {
177
147
  /*
178
148
  if beneficiary is an EOA and destToken on destChain = WETH
179
- order.destToken=WETH
180
- order.bridge.outputToken=WETH_DEST_CHAIN
149
+ order.destToken=WETH (deltaPrice already contains correct destToken)
150
+ order.bridge.outputToken=WETH_DEST_CHAIN (deltaPrice already contains correct bridge.outputToken)
181
151
  order.bridge.multiCallHandler=MULTI_CALL_HANDLER
182
152
  */
183
- const bridge: Bridge = {
184
- maxRelayerFee: bridgeFee,
185
- destinationChainId: destChainId,
186
- outputToken: WETH_DEST_CHAIN,
187
- multiCallHandler: await getMulticallHandler(destChainId),
188
- };
189
- return {
190
- bridge,
191
- orderChanges: {
192
- destToken: WETH_SRC_CHAIN,
193
- },
194
- };
153
+ multiCallHandler = await getMulticallHandler(destChainId);
195
154
  }
196
155
 
197
156
  if (beneficiaryType === 'SmartContract' && isETHaddress(destTokenDestChain)) {
198
157
  /*
199
158
  if beneficiary is a contract and destToken on destChain = ETH
200
- order.destToken=ETH
201
- order.bridge.outputToken=WETH_DEST_CHAIN
159
+ order.destToken=ETH (deltaPrice already contains correct destToken)
160
+ order.bridge.outputToken=WETH_DEST_CHAIN (deltaPrice already contains correct bridge.outputToken)
202
161
  order.bridge.multiCallHandler=MULTI_CALL_HANDLER
203
162
  */
204
- const bridge: Bridge = {
205
- maxRelayerFee: bridgeFee,
206
- destinationChainId: destChainId,
207
- outputToken: WETH_DEST_CHAIN,
208
- multiCallHandler: await getMulticallHandler(destChainId),
209
- };
210
- return {
211
- bridge,
212
- orderChanges: {
213
- destToken: ETH_ADDRESS,
214
- },
215
- };
163
+ multiCallHandler = await getMulticallHandler(destChainId);
216
164
  }
217
165
 
218
166
  if (
@@ -221,35 +169,21 @@ export async function getDeltaBridgeAndDestToken({
221
169
  ) {
222
170
  /*
223
171
  if beneficiary is a contract and destToken on destChain = WETH
224
- order.destToken=WETH
225
- order.bridge.outputToken=WETH_DEST_CHAIN
172
+ order.destToken=WETH (deltaPrice already contains correct destToken)
173
+ order.bridge.outputToken=WETH_DEST_CHAIN (deltaPrice already contains correct bridge.outputToken)
226
174
  order.bridge.multiCallHandler=NULL_ADDRESS
227
175
  */
228
- const bridge: Bridge = {
229
- maxRelayerFee: bridgeFee,
230
- destinationChainId: destChainId,
231
- outputToken: WETH_DEST_CHAIN,
232
- multiCallHandler: ZERO_ADDRESS,
233
- };
234
- return {
235
- bridge,
236
- orderChanges: {
237
- destToken: WETH_SRC_CHAIN,
238
- },
239
- };
176
+ multiCallHandler = ZERO_ADDRESS;
240
177
  }
241
178
 
242
179
  const bridge: Bridge = {
243
180
  maxRelayerFee: bridgeFee,
244
181
  destinationChainId: destChainId,
245
- outputToken: destTokenDestChain,
246
- multiCallHandler: ZERO_ADDRESS,
182
+ outputToken,
183
+ multiCallHandler,
247
184
  };
248
185
 
249
186
  return {
250
187
  bridge,
251
- orderChanges: {
252
- destToken: destTokenSrcChain,
253
- },
254
188
  };
255
189
  }