@velora-dex/sdk 9.0.0 → 9.2.0-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 (63) hide show
  1. package/dist/examples/wagmi.d.ts +121 -10
  2. package/dist/examples/wagmi.d.ts.map +1 -1
  3. package/dist/helpers/providers/helpers.d.ts +1 -1
  4. package/dist/helpers/providers/helpers.d.ts.map +1 -1
  5. package/dist/index.d.ts +4 -5
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/methods/common/orders/types.d.ts +0 -2
  8. package/dist/methods/common/orders/types.d.ts.map +1 -1
  9. package/dist/methods/delta/buildDeltaOrder.d.ts +3 -5
  10. package/dist/methods/delta/buildDeltaOrder.d.ts.map +1 -1
  11. package/dist/methods/delta/getDeltaOrders.d.ts +15 -4
  12. package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
  13. package/dist/methods/delta/getDeltaPrice.d.ts +15 -0
  14. package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
  15. package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts +6 -0
  16. package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts.map +1 -1
  17. package/dist/methods/delta/helpers/types.d.ts +3 -2
  18. package/dist/methods/delta/helpers/types.d.ts.map +1 -1
  19. package/dist/methods/delta/index.d.ts +2 -3
  20. package/dist/methods/delta/index.d.ts.map +1 -1
  21. package/dist/methods/delta/preSignDeltaOrder.d.ts +17 -0
  22. package/dist/methods/delta/preSignDeltaOrder.d.ts.map +1 -0
  23. package/dist/methods/delta/signDeltaOrder.d.ts +0 -3
  24. package/dist/methods/delta/signDeltaOrder.d.ts.map +1 -1
  25. package/dist/methods/limitOrders/helpers/types.d.ts +2 -4
  26. package/dist/methods/limitOrders/helpers/types.d.ts.map +1 -1
  27. package/dist/methods/nftOrders/helpers/types.d.ts +2 -4
  28. package/dist/methods/nftOrders/helpers/types.d.ts.map +1 -1
  29. package/dist/sdk/partial.d.ts +3 -1
  30. package/dist/sdk/partial.d.ts.map +1 -1
  31. package/dist/sdk/simple.d.ts +1 -3
  32. package/dist/sdk/simple.d.ts.map +1 -1
  33. package/dist/sdk.cjs.development.js +184 -115
  34. package/dist/sdk.cjs.development.js.map +1 -1
  35. package/dist/sdk.cjs.production.min.js +1 -1
  36. package/dist/sdk.cjs.production.min.js.map +1 -1
  37. package/dist/sdk.esm.js +184 -114
  38. package/dist/sdk.esm.js.map +1 -1
  39. package/package.json +5 -4
  40. package/src/helpers/providers/helpers.ts +5 -5
  41. package/src/index.ts +8 -18
  42. package/src/methods/common/orders/types.ts +0 -7
  43. package/src/methods/delta/buildDeltaOrder.ts +37 -23
  44. package/src/methods/delta/getDeltaOrders.ts +31 -6
  45. package/src/methods/delta/getDeltaPrice.ts +28 -0
  46. package/src/methods/delta/helpers/buildDeltaOrderData.ts +1 -1
  47. package/src/methods/delta/helpers/types.ts +14 -1
  48. package/src/methods/delta/index.ts +8 -16
  49. package/src/methods/delta/preSignDeltaOrder.ts +157 -0
  50. package/src/methods/delta/signDeltaOrder.ts +0 -6
  51. package/src/methods/limitOrders/helpers/types.ts +2 -4
  52. package/src/methods/nftOrders/helpers/types.ts +2 -4
  53. package/src/sdk/partial.ts +3 -1
  54. package/src/sdk/simple.ts +0 -12
  55. package/dist/methods/delta/buildCrosschainOrderBridge.d.ts +0 -23
  56. package/dist/methods/delta/buildCrosschainOrderBridge.d.ts.map +0 -1
  57. package/dist/methods/delta/getMulticallHandlers.d.ts +0 -9
  58. package/dist/methods/delta/getMulticallHandlers.d.ts.map +0 -1
  59. package/dist/methods/delta/helpers/across.d.ts +0 -19
  60. package/dist/methods/delta/helpers/across.d.ts.map +0 -1
  61. package/src/methods/delta/buildCrosschainOrderBridge.ts +0 -96
  62. package/src/methods/delta/getMulticallHandlers.ts +0 -44
  63. package/src/methods/delta/helpers/across.ts +0 -189
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velora-dex/sdk",
3
- "version": "9.0.0",
3
+ "version": "9.2.0-dev.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/sdk.esm.js",
6
6
  "typings": "dist/index.d.ts",
@@ -68,8 +68,8 @@
68
68
  "typedoc-plugin-missing-exports": "^3.0.0",
69
69
  "typedoc-plugin-replace-text": "^4.0.0",
70
70
  "typescript": "^5.6.3",
71
- "viem": "^2.21.39",
72
- "wagmi": "^2.12.25",
71
+ "viem": "^2.39.0",
72
+ "wagmi": "^2.19.4",
73
73
  "web3": "^4.14.0"
74
74
  },
75
75
  "peerDependencies": {
@@ -94,7 +94,8 @@
94
94
  },
95
95
  "dependencies": {
96
96
  "@paraswap/core": "2.4.0",
97
- "ts-essentials": "^10.0.3"
97
+ "ts-essentials": "^10.0.3",
98
+ "viem": "^2.21.0"
98
99
  },
99
100
  "author": "Velora",
100
101
  "description": "Velora SDK",
@@ -5,10 +5,10 @@ import { TypedDataField } from '../../methods/common/orders/buildOrderData';
5
5
  // may be overly strict, but reliable
6
6
  const baseTypeRegex = /^([^\x5b]*)(\x5b|$)/;
7
7
 
8
- export function findPrimaryType(
9
- types: Record<string, TypedDataField[]>
10
- ): string {
11
- const candidates = Object.keys(types);
8
+ export function findPrimaryType<P extends string>(
9
+ types: Record<P, TypedDataField[]>
10
+ ): P {
11
+ const candidates = Object.keys(types) as P[];
12
12
  const candidatesSet = new Set(candidates);
13
13
 
14
14
  candidates.forEach((candidate) => {
@@ -21,7 +21,7 @@ export function findPrimaryType(
21
21
  if (!baseType) return;
22
22
 
23
23
  // if type was referred to as a child of another type, it can't be the primaryType
24
- candidatesSet.delete(baseType);
24
+ candidatesSet.delete(baseType as P);
25
25
  });
26
26
  });
27
27
 
package/src/index.ts CHANGED
@@ -151,12 +151,6 @@ import {
151
151
  SignableDeltaOrderData,
152
152
  SwapSideUnion,
153
153
  } from './methods/delta/buildDeltaOrder';
154
- import {
155
- constructBuildCrosschainOrderBridge,
156
- BuildCrosschainOrderBridgeFunctions,
157
- BuildCrosschainOrderBridgeParams,
158
- CrosschainOrderBridgeAndChanges,
159
- } from './methods/delta/buildCrosschainOrderBridge';
160
154
  import {
161
155
  constructPostDeltaOrder,
162
156
  DeltaOrderApiResponse,
@@ -167,6 +161,10 @@ import {
167
161
  constructSignDeltaOrder,
168
162
  SignDeltaOrderFunctions,
169
163
  } from './methods/delta/signDeltaOrder';
164
+ import {
165
+ constructPreSignDeltaOrder,
166
+ PreSignDeltaOrderFunctions,
167
+ } from './methods/delta/preSignDeltaOrder';
170
168
  import {
171
169
  GetDeltaContractFunctions,
172
170
  constructGetDeltaContract,
@@ -181,6 +179,7 @@ import {
181
179
  import {
182
180
  constructGetDeltaOrders,
183
181
  GetDeltaOrdersFunctions,
182
+ DeltaOrderFilterByStatus,
184
183
  DeltaOrderFromAPI,
185
184
  } from './methods/delta/getDeltaOrders';
186
185
  import {
@@ -196,11 +195,6 @@ import {
196
195
  GetBridgeInfoFunctions,
197
196
  BridgeInfo,
198
197
  } from './methods/delta/getBridgeInfo';
199
- import {
200
- constructGetMulticallHandlers,
201
- GetMulticallHandlersFunctions,
202
- MulticallHandlersResponse,
203
- } from './methods/delta/getMulticallHandlers';
204
198
  import {
205
199
  constructIsTokenSupportedInDelta,
206
200
  IsTokenSupportedInDeltaFunctions,
@@ -296,9 +290,9 @@ export {
296
290
  constructBuildNFTOrderTx,
297
291
  // Delta methods
298
292
  constructBuildDeltaOrder,
299
- constructBuildCrosschainOrderBridge,
300
293
  constructPostDeltaOrder,
301
294
  constructSignDeltaOrder,
295
+ constructPreSignDeltaOrder,
302
296
  constructGetDeltaContract,
303
297
  constructGetDeltaPrice,
304
298
  constructGetDeltaOrders,
@@ -310,7 +304,6 @@ export {
310
304
  constructGetPartnerFee,
311
305
  constructGetBridgeInfo,
312
306
  constructIsTokenSupportedInDelta,
313
- constructGetMulticallHandlers,
314
307
  constructEthersContractCaller, // same as constructEthersV5ContractCaller for backwards compatibility
315
308
  constructEthersV5ContractCaller,
316
309
  constructEthersV6ContractCaller,
@@ -377,6 +370,7 @@ export type {
377
370
  DeltaAuctionOrder,
378
371
  DeltaAuction,
379
372
  DeltaAuctionStatus,
373
+ DeltaOrderFilterByStatus,
380
374
  DeltaOrderApiResponse,
381
375
  DeltaOrderFromAPI,
382
376
  // bridge part of DeltaOrder
@@ -387,12 +381,10 @@ export type {
387
381
  BuildDeltaOrderDataParams,
388
382
  BuildDeltaOrderFunctions,
389
383
  SignableDeltaOrderData,
390
- BuildCrosschainOrderBridgeFunctions,
391
- BuildCrosschainOrderBridgeParams,
392
- CrosschainOrderBridgeAndChanges,
393
384
  PostDeltaOrderFunctions,
394
385
  PostDeltaOrderParams,
395
386
  SignDeltaOrderFunctions,
387
+ PreSignDeltaOrderFunctions,
396
388
  GetDeltaContractFunctions,
397
389
  GetDeltaPriceFunctions,
398
390
  GetDeltaOrdersFunctions,
@@ -413,8 +405,6 @@ export type {
413
405
  GetPartnerFeeFunctions,
414
406
  GetBridgeInfoFunctions,
415
407
  IsTokenSupportedInDeltaFunctions,
416
- GetMulticallHandlersFunctions,
417
- MulticallHandlersResponse,
418
408
  Token,
419
409
  Address,
420
410
  AddressOrSymbol,
@@ -4,10 +4,3 @@ export type OrderTransaction = {
4
4
  };
5
5
 
6
6
  export type OrderType = 'LIMIT' | 'P2P';
7
-
8
- // display states such as EXPIRED and PARTIALLY_FILLLED derived on client side
9
- // returned by API but can be calculated too, EXPIRED == order.expiry < Date.now()/1000
10
- // PARTIALLY_FILLED == order.fillableBalance < order.makerAmount && order.fillableBalance !== '0'
11
- export type OrderState = 'PENDING' | 'FULFILLED' | 'CANCELLED' | 'EXPIRED';
12
-
13
- export type BeneficiaryType = 'EOA' | 'SmartContract';
@@ -4,7 +4,7 @@ import type {
4
4
  RequestParameters,
5
5
  } from '../../types';
6
6
  import { constructGetDeltaContract } from './getDeltaContract';
7
- import { BridgePrice } from './getDeltaPrice';
7
+ import type { BridgePrice } from './getDeltaPrice';
8
8
  import { constructGetPartnerFee } from './getPartnerFee';
9
9
  import {
10
10
  buildDeltaSignableOrderData,
@@ -12,8 +12,9 @@ import {
12
12
  type SignableDeltaOrderData,
13
13
  } from './helpers/buildDeltaOrderData';
14
14
  import { SwapSideToOrderKind } from './helpers/types';
15
- import { BeneficiaryType } from '../common/orders/types';
16
15
  import { SwapSide } from '../../constants';
16
+ import type { MarkOptional } from 'ts-essentials';
17
+ import { ZERO_ADDRESS } from '../common/orders/buildOrderData';
17
18
  export type { SignableDeltaOrderData } from './helpers/buildDeltaOrderData';
18
19
 
19
20
  export type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
@@ -42,18 +43,19 @@ export type BuildDeltaOrderDataParams = {
42
43
 
43
44
  /** @description Destination Chain ID for Crosschain Orders */
44
45
  destChainId?: number;
45
- /** @description Whether the beneficiary is a contract. Needed to automatically fill in crosschain Bridge */
46
- beneficiaryType?: BeneficiaryType;
47
46
 
48
47
  /** @description price response received from /delta/prices (getDeltaPrice method) */
49
- deltaPrice: Pick<
50
- BridgePrice,
51
- | 'destAmount'
52
- | 'partner'
53
- | 'partnerFee'
54
- | 'destToken'
55
- | 'srcAmount'
56
- | 'bridge'
48
+ deltaPrice: MarkOptional<
49
+ Pick<
50
+ BridgePrice,
51
+ | 'destAmount'
52
+ | 'partner'
53
+ | 'partnerFee'
54
+ | 'destToken'
55
+ | 'srcAmount'
56
+ | 'bridge'
57
+ >,
58
+ 'partner' | 'partnerFee'
57
59
  >;
58
60
 
59
61
  /** @description partner fee in basis points (bps), 50bps=0.5% */
@@ -100,7 +102,10 @@ export const constructBuildDeltaOrder = (
100
102
  // externally supplied partner fee data takes precedence
101
103
  let partnerAddress = options.partnerAddress;
102
104
  let partnerFeeBps =
103
- options.partnerFeeBps ?? options.deltaPrice.partnerFee * 100;
105
+ options.partnerFeeBps ??
106
+ (options.deltaPrice.partnerFee
107
+ ? options.deltaPrice.partnerFee * 100
108
+ : undefined);
104
109
  let partnerTakesSurplus = options.partnerTakesSurplus;
105
110
 
106
111
  // if fee given, takeSurplus is ignored
@@ -109,18 +114,27 @@ export const constructBuildDeltaOrder = (
109
114
 
110
115
  if (partnerAddress === undefined || feeOrTakeSurplusSupplied) {
111
116
  const partner = options.partner || options.deltaPrice.partner;
112
- const partnerFeeResponse = await getPartnerFee(
113
- { partner },
114
- requestParams
115
- );
116
-
117
- partnerAddress = partnerAddress ?? partnerFeeResponse.partnerAddress;
118
- // deltaPrice.partnerFee and partnerFeeResponse.partnerFee should be the same, but give priority to externally provided
119
- partnerFeeBps = partnerFeeBps ?? partnerFeeResponse.partnerFee;
120
- partnerTakesSurplus =
121
- partnerTakesSurplus ?? partnerFeeResponse.takeSurplus;
117
+ if (!partner) {
118
+ // if no partner given in options or deltaPrice, default partnerAddress to zero,
119
+ // unless supplied explicitly
120
+ partnerAddress = partnerAddress ?? ZERO_ADDRESS;
121
+ } else {
122
+ const partnerFeeResponse = await getPartnerFee(
123
+ { partner },
124
+ requestParams
125
+ );
126
+
127
+ partnerAddress = partnerAddress ?? partnerFeeResponse.partnerAddress;
128
+ // deltaPrice.partnerFee and partnerFeeResponse.partnerFee should be the same, but give priority to externally provided
129
+ partnerFeeBps = partnerFeeBps ?? partnerFeeResponse.partnerFee;
130
+ partnerTakesSurplus =
131
+ partnerTakesSurplus ?? partnerFeeResponse.takeSurplus;
132
+ }
122
133
  }
123
134
 
135
+ partnerFeeBps = partnerFeeBps ?? 0;
136
+ partnerTakesSurplus = partnerTakesSurplus ?? false;
137
+
124
138
  const swapSide = options.side ?? SwapSide.SELL;
125
139
 
126
140
  const expectedAmount =
@@ -5,10 +5,18 @@ import type {
5
5
  ConstructFetchInput,
6
6
  RequestParameters,
7
7
  } from '../../types';
8
- import type { DeltaAuction } from './helpers/types';
8
+ import type { DeltaAuction, DeltaAuctionStatus } from './helpers/types';
9
9
 
10
10
  export type DeltaOrderFromAPI = Omit<DeltaAuction, 'signature'>;
11
11
 
12
+ export type DeltaOrderFilterByStatus =
13
+ | DeltaAuctionStatus
14
+ | 'INSUFFICIENT_BALANCE'
15
+ | 'INSUFFICIENT_ALLOWANCE'
16
+ | 'INVALIDATED'
17
+ | 'ACTIVE'
18
+ | 'INACTIVE';
19
+
12
20
  type GetDeltaOrderById = (
13
21
  orderId: string,
14
22
  requestParams?: RequestParameters
@@ -27,11 +35,24 @@ type OrdersFilter = {
27
35
  /** @description Pagination option, limit. Default 100 */
28
36
  limit?: number;
29
37
  /** @description Filter by chainId, without this filter, orders from all chains are returned */
30
- chainId?: number; // @TODO currently not working
31
- /** @description Filter by type. MARKET, LIMIT, or ALL. Default is ALL */
32
- type?: 'MARKET' | 'LIMIT' | 'ALL';
38
+ chainId?: number[];
39
+ /**
40
+ * @description
41
+ * Filter by any known DeltaAuctionStatus and some custom statuses:
42
+ * - **INSUFFICIENT_BALANCE** — returned as SUSPENDED from API
43
+ * - **INSUFFICIENT_ALLOWANCE** — returned as SUSPENDED from API
44
+ * - **INVALIDATED** — returned as FAILED from API
45
+ * - **ACTIVE** — All orders with NOT_STARTED, RUNNING, EXECUTING or SUSPENDED statuses.
46
+ * - **INACTIVE** — All orders with EXECUTED, FAILED, EXPIRED, CANCELLED or INVALIDATED statuses.
47
+ */
48
+ status?: DeltaOrderFilterByStatus[];
49
+ /** @description Filter by type. MARKET, LIMIT. Orders with both types are returned if not specified */
50
+ type?: 'MARKET' | 'LIMIT';
51
+ };
52
+ type OrderFiltersQuery = Omit<OrdersFilter, 'chainId' | 'status'> & {
53
+ chainId?: string;
54
+ status?: string;
33
55
  };
34
- type OrderFiltersQuery = OrdersFilter;
35
56
 
36
57
  type GetDeltaOrders = (
37
58
  options: OrdersFilter,
@@ -93,12 +114,16 @@ export const constructGetDeltaOrders = ({
93
114
  };
94
115
 
95
116
  const getDeltaOrders: GetDeltaOrders = async (options, requestParams) => {
117
+ const chainIdString = options.chainId?.join(',');
118
+ const statusString = options.status?.join(',');
119
+
96
120
  const search = constructSearchString<OrderFiltersQuery>({
97
121
  userAddress: options.userAddress,
98
122
  page: options.page,
99
123
  limit: options.limit,
100
- chainId: options.chainId,
101
124
  type: options.type,
125
+ chainId: chainIdString,
126
+ status: statusString,
102
127
  });
103
128
 
104
129
  const fetchURL = `${baseUrl}${search}` as const;
@@ -64,6 +64,13 @@ export type DeltaPrice = {
64
64
  destAmount: string;
65
65
  /** @description Available for SELL side */
66
66
  destAmountBeforeFee?: string;
67
+ /** @description amount of the final outcome token */
68
+ receivedDestAmount: string;
69
+ receivedDestUSD: string;
70
+ /** @description Available for SELL side */
71
+ receivedDestAmountBeforeFee?: string;
72
+ /** @description Available for SELL side */
73
+ receivedDestUSDBeforeFee?: string;
67
74
  gasCost: string;
68
75
  gasCostBeforeFee: string;
69
76
  gasCostUSD: string;
@@ -80,6 +87,26 @@ export type DeltaPrice = {
80
87
  bridge: Bridge; // for single-chain DeltaPrice, it's DEFAULT_BRIDGE
81
88
  };
82
89
 
90
+ type AvailableBridgePrice = Pick<
91
+ DeltaPrice,
92
+ | 'destToken'
93
+ | 'destAmount'
94
+ | 'destAmountBeforeFee'
95
+ | 'destUSD'
96
+ | 'destUSDBeforeFee'
97
+ | 'gasCostUSD'
98
+ | 'gasCost'
99
+ | 'gasCostUSDBeforeFee'
100
+ | 'gasCostBeforeFee'
101
+ >;
102
+
103
+ type AvailableBridge = AvailableBridgePrice & {
104
+ bridgeParams: {
105
+ bridge: Bridge;
106
+ bridgeInfo: BridgePriceInfo;
107
+ }[];
108
+ };
109
+
83
110
  export type BridgePrice = Omit<DeltaPrice, 'bridge'> & {
84
111
  // destAmountAfterBridge: string; // became bridgeInfo.destAmountAfterBridge
85
112
  // destUSDAfterBridge: string; // became bridgeInfo.destUSDAfterBridge
@@ -88,6 +115,7 @@ export type BridgePrice = Omit<DeltaPrice, 'bridge'> & {
88
115
  // poolAddress: string;
89
116
  bridge: Bridge;
90
117
  bridgeInfo: BridgePriceInfo;
118
+ availableBridges: AvailableBridge[];
91
119
  };
92
120
 
93
121
  type DeltaPriceResponse = {
@@ -59,7 +59,7 @@ type SignDeltaOrderInput = {
59
59
  chainId: number;
60
60
  };
61
61
 
62
- function produceDeltaOrderTypedData({
62
+ export function produceDeltaOrderTypedData({
63
63
  orderInput,
64
64
  chainId,
65
65
  paraswapDeltaAddress,
@@ -54,6 +54,7 @@ export type Bridge = {
54
54
 
55
55
  export type DeltaAuctionStatus =
56
56
  | 'NOT_STARTED'
57
+ | 'AWAITING_PRE_SIGNATURE'
57
58
  | 'RUNNING'
58
59
  | 'EXECUTING'
59
60
  | 'EXECUTED'
@@ -69,6 +70,7 @@ type DeltaAuctionTransaction = {
69
70
  bidId: string | null;
70
71
  blockNumber: number;
71
72
  blockHash: string;
73
+ blockTimestamp: string | null; // ISO string, null for older Orders
72
74
  gasUsed: bigint;
73
75
  gasPrice: bigint;
74
76
  blobGasUsed: bigint;
@@ -137,7 +139,18 @@ export type BridgeStatus = 'pending' | 'filled' | 'expired' | 'refunded';
137
139
  //// available on BridgePrice ////
138
140
 
139
141
  // so far
140
- type ProtocolName = 'Across' | 'StargateBus' | 'StargateTaxi';
142
+ type ProtocolName =
143
+ | 'Across'
144
+ | 'StargateBus'
145
+ | 'StargateTaxi'
146
+ | 'StargateOftV2'
147
+ | 'Relay'
148
+ | 'CCTPFast'
149
+ | 'CCTPStandard'
150
+ | 'Celer'
151
+ | 'Canonical'
152
+ | 'Polygon'
153
+ | 'Arbitrum';
141
154
 
142
155
  type BridgeQuoteFee = {
143
156
  feeToken: string;
@@ -38,22 +38,18 @@ import {
38
38
  constructGetBridgeInfo,
39
39
  GetBridgeInfoFunctions,
40
40
  } from './getBridgeInfo';
41
- import {
42
- constructGetMulticallHandlers,
43
- GetMulticallHandlersFunctions,
44
- } from './getMulticallHandlers';
45
41
  import {
46
42
  constructIsTokenSupportedInDelta,
47
43
  IsTokenSupportedInDeltaFunctions,
48
44
  } from './isTokenSupportedInDelta';
49
- import {
50
- BuildCrosschainOrderBridgeFunctions,
51
- constructBuildCrosschainOrderBridge,
52
- } from './buildCrosschainOrderBridge';
53
45
  import {
54
46
  CancelDeltaOrderFunctions,
55
47
  constructCancelDeltaOrder,
56
48
  } from './cancelDeltaOrder';
49
+ import {
50
+ constructPreSignDeltaOrder,
51
+ PreSignDeltaOrderFunctions,
52
+ } from './preSignDeltaOrder';
57
53
 
58
54
  export type SubmitDeltaOrderParams = BuildDeltaOrderDataParams & {
59
55
  /** @description designates the Order as being able to be partially filled, as opposed to fill-or-kill */
@@ -74,6 +70,7 @@ export const constructSubmitDeltaOrder = (
74
70
  options: ConstructProviderFetchInput<any, 'signTypedDataCall'>
75
71
  ): SubmitDeltaOrderFuncs => {
76
72
  const { buildDeltaOrder } = constructBuildDeltaOrder(options);
73
+ // in the normal submitOrderFlow preSign tx is not involved
77
74
  const { signDeltaOrder } = constructSignDeltaOrder(options);
78
75
  const { postDeltaOrder } = constructPostDeltaOrder(options);
79
76
 
@@ -101,16 +98,15 @@ export const constructSubmitDeltaOrder = (
101
98
  export type DeltaOrderHandlers<T> = SubmitDeltaOrderFuncs &
102
99
  ApproveTokenForDeltaFunctions<T> &
103
100
  BuildDeltaOrderFunctions &
104
- BuildCrosschainOrderBridgeFunctions &
105
101
  GetDeltaOrdersFunctions &
106
102
  GetDeltaPriceFunctions &
107
103
  GetDeltaContractFunctions &
108
104
  GetPartnerFeeFunctions &
109
- GetMulticallHandlersFunctions &
110
105
  GetBridgeInfoFunctions &
111
106
  IsTokenSupportedInDeltaFunctions &
112
107
  PostDeltaOrderFunctions &
113
108
  SignDeltaOrderFunctions &
109
+ PreSignDeltaOrderFunctions<T> &
114
110
  CancelDeltaOrderFunctions;
115
111
 
116
112
  /** @description construct SDK with every Delta Order-related method, fetching from API and Order signing */
@@ -127,17 +123,14 @@ export const constructAllDeltaOrdersHandlers = <TxResponse>(
127
123
  const partnerFee = constructGetPartnerFee(options);
128
124
  const bridgeInfo = constructGetBridgeInfo(options);
129
125
  const isTokenSupportedInDelta = constructIsTokenSupportedInDelta(options);
130
- const multicallHandlers = constructGetMulticallHandlers(options);
131
126
 
132
127
  const approveTokenForDelta = constructApproveTokenForDelta(options);
133
128
 
134
129
  const deltaOrdersSubmit = constructSubmitDeltaOrder(options);
135
130
 
136
- const buildCrosschainOrderBridge =
137
- constructBuildCrosschainOrderBridge(options);
138
-
139
131
  const deltaOrdersBuild = constructBuildDeltaOrder(options);
140
132
  const deltaOrdersSign = constructSignDeltaOrder(options);
133
+ const deltaOrdersPreSign = constructPreSignDeltaOrder(options);
141
134
  const deltaOrdersPost = constructPostDeltaOrder(options);
142
135
 
143
136
  const deltaOrdersCancel = constructCancelDeltaOrder(options);
@@ -149,13 +142,12 @@ export const constructAllDeltaOrdersHandlers = <TxResponse>(
149
142
  ...partnerFee,
150
143
  ...bridgeInfo,
151
144
  ...isTokenSupportedInDelta,
152
- ...multicallHandlers,
153
145
  ...approveTokenForDelta,
154
146
  ...deltaOrdersSubmit,
155
147
  ...deltaOrdersBuild,
156
148
  ...deltaOrdersSign,
149
+ ...deltaOrdersPreSign,
157
150
  ...deltaOrdersPost,
158
151
  ...deltaOrdersCancel,
159
- ...buildCrosschainOrderBridge,
160
152
  };
161
153
  };
@@ -0,0 +1,157 @@
1
+ import { hashTypedData } from 'viem/utils';
2
+ import type {
3
+ ConstructProviderFetchInput,
4
+ RequestParameters,
5
+ TxSendOverrides,
6
+ } from '../../types';
7
+ import {
8
+ produceDeltaOrderTypedData,
9
+ SignableDeltaOrderData,
10
+ } from './helpers/buildDeltaOrderData';
11
+ import { sanitizeDeltaOrderData } from './helpers/misc';
12
+ import { constructGetDeltaContract, DeltaAuctionOrder } from '../..';
13
+ import { ExtractAbiMethodNames } from '../../helpers/misc';
14
+ import { findPrimaryType } from '../../helpers/providers/helpers';
15
+
16
+ type HashDeltaOrderTypedData = (
17
+ signableOrderData: SignableDeltaOrderData
18
+ ) => string;
19
+
20
+ type HashDeltaOrder = (
21
+ orderData: DeltaAuctionOrder,
22
+ requestParams?: RequestParameters
23
+ ) => Promise<string>;
24
+
25
+ export type SetDeltaOrderPreSignature<T> = (
26
+ orderHash: string,
27
+ overrides?: TxSendOverrides,
28
+ requestParams?: RequestParameters
29
+ ) => Promise<T>;
30
+
31
+ export type PreSignDeltaOrder<T> = (
32
+ signableOrderData: SignableDeltaOrderData,
33
+ overrides?: TxSendOverrides,
34
+ requestParams?: RequestParameters
35
+ ) => Promise<T>;
36
+
37
+ export type PreSignDeltaOrderFunctions<T> = {
38
+ hashDeltaOrderTypedData: HashDeltaOrderTypedData;
39
+ hashDeltaOrder: HashDeltaOrder;
40
+ setDeltaOrderPreSignature: SetDeltaOrderPreSignature<T>;
41
+ preSignDeltaOrder: PreSignDeltaOrder<T>;
42
+ };
43
+
44
+ const PreSignatureModuleAbi = [
45
+ {
46
+ inputs: [
47
+ {
48
+ internalType: 'bytes32',
49
+ name: 'orderHash',
50
+ type: 'bytes32',
51
+ },
52
+ {
53
+ internalType: 'bool',
54
+ name: 'preSigned',
55
+ type: 'bool',
56
+ },
57
+ ],
58
+ name: 'setPreSignature',
59
+ outputs: [],
60
+ stateMutability: 'nonpayable',
61
+ type: 'function',
62
+ },
63
+ ] as const;
64
+
65
+ type AvailableMethods = ExtractAbiMethodNames<typeof PreSignatureModuleAbi>;
66
+
67
+ // returns whatever `contractCaller` returns
68
+ // to allow for better versatility
69
+ export const constructPreSignDeltaOrder = <T>(
70
+ options: ConstructProviderFetchInput<T, 'transactCall'>
71
+ ): PreSignDeltaOrderFunctions<T> => {
72
+ const hashDeltaOrderTypedData: HashDeltaOrderTypedData = (typedData) => {
73
+ // types allow to pass OrderData & extra_stuff, but tx will break like that
74
+ const typedDataOnly: SignableDeltaOrderData = {
75
+ ...typedData,
76
+ data: sanitizeDeltaOrderData(typedData.data),
77
+ };
78
+
79
+ const orderHash = produceDeltaOrderHash(typedDataOnly);
80
+
81
+ return orderHash;
82
+ };
83
+ // cached internally
84
+ const { getDeltaContract } = constructGetDeltaContract(options);
85
+
86
+ const hashDeltaOrder: HashDeltaOrder = async (orderData, requestParams) => {
87
+ const ParaswapDelta = await getDeltaContract(requestParams);
88
+ if (!ParaswapDelta) {
89
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
90
+ }
91
+
92
+ const typedData = produceDeltaOrderTypedData({
93
+ orderInput: orderData,
94
+ chainId: options.chainId,
95
+ paraswapDeltaAddress: ParaswapDelta,
96
+ });
97
+ return hashDeltaOrderTypedData(typedData);
98
+ };
99
+
100
+ const setDeltaOrderPreSignature: SetDeltaOrderPreSignature<T> = async (
101
+ orderHash,
102
+ overrides = {},
103
+ requestParams
104
+ ) => {
105
+ const ParaswapDelta = await getDeltaContract(requestParams);
106
+ if (!ParaswapDelta) {
107
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
108
+ }
109
+
110
+ const res = await options.contractCaller.transactCall<AvailableMethods>({
111
+ address: ParaswapDelta,
112
+ abi: PreSignatureModuleAbi,
113
+ contractMethod: 'setPreSignature',
114
+ args: [orderHash, true],
115
+ overrides,
116
+ });
117
+
118
+ return res;
119
+ };
120
+
121
+ const preSignDeltaOrder: PreSignDeltaOrder<T> = async (
122
+ signableOrderData,
123
+ overrides = {},
124
+ requestParams
125
+ ) => {
126
+ const orderHash = hashDeltaOrderTypedData(signableOrderData);
127
+ const res = await setDeltaOrderPreSignature(
128
+ orderHash,
129
+ overrides,
130
+ requestParams
131
+ );
132
+ return res;
133
+ };
134
+
135
+ return {
136
+ hashDeltaOrderTypedData,
137
+ hashDeltaOrder,
138
+ setDeltaOrderPreSignature,
139
+ preSignDeltaOrder,
140
+ };
141
+ };
142
+
143
+ export function produceDeltaOrderHash(
144
+ typedData: SignableDeltaOrderData
145
+ ): string {
146
+ return hashTypedData({
147
+ domain: {
148
+ name: typedData.domain.name,
149
+ version: typedData.domain.version,
150
+ chainId: typedData.domain.chainId,
151
+ verifyingContract: typedData.domain.verifyingContract as `0x${string}`,
152
+ },
153
+ types: typedData.types,
154
+ primaryType: findPrimaryType(typedData.types),
155
+ message: typedData.data,
156
+ });
157
+ }
@@ -2,12 +2,6 @@ import type { ConstructProviderFetchInput } from '../../types';
2
2
  import { SignableDeltaOrderData } from './helpers/buildDeltaOrderData';
3
3
  import { sanitizeDeltaOrderData } from './helpers/misc';
4
4
 
5
- export type SignLimitOrderFunctions = {
6
- signLimitOrder: (
7
- signableOrderData: SignableDeltaOrderData
8
- ) => Promise<string>;
9
- };
10
-
11
5
  type SignDeltaOrder = (
12
6
  signableOrderData: SignableDeltaOrderData
13
7
  ) => Promise<string>;