@velora-dex/sdk 9.3.3-dev.2 → 9.3.4-dev.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.3-dev.2",
3
+ "version": "9.3.4-dev.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/sdk.esm.js",
6
6
  "typings": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -216,6 +216,11 @@ import {
216
216
  CancelDeltaOrderFunctions,
217
217
  constructCancelDeltaOrder,
218
218
  } from './methods/delta/cancelDeltaOrder';
219
+ import {
220
+ DeltaTokenModuleFunctions,
221
+ CancelAndWithdrawDeltaOrderParams,
222
+ constructDeltaTokenModule,
223
+ } from './methods/delta/deltaTokenModule';
219
224
 
220
225
  export { constructSwapSDK, SwapSDKMethods } from './methods/swap';
221
226
 
@@ -300,6 +305,7 @@ export {
300
305
  constructGetDeltaPrice,
301
306
  constructGetDeltaOrders,
302
307
  constructCancelDeltaOrder,
308
+ constructDeltaTokenModule,
303
309
  constructApproveTokenForDelta,
304
310
  // Quote methods
305
311
  constructGetQuote,
@@ -395,6 +401,8 @@ export type {
395
401
  GetDeltaOrdersFunctions,
396
402
  ApproveTokenForDeltaFunctions,
397
403
  CancelDeltaOrderFunctions,
404
+ DeltaTokenModuleFunctions,
405
+ CancelAndWithdrawDeltaOrderParams,
398
406
  // types for Quote methods
399
407
  GetQuoteFunctions,
400
408
  QuoteParams,
@@ -37,6 +37,8 @@ export type CancelDeltaOrderFunctions = {
37
37
  cancelLimitDeltaOrders: CancelDeltaOrder;
38
38
  };
39
39
 
40
+ // returns whatever `contractCaller` returns
41
+ // to allow for better versatility
40
42
  export const constructCancelDeltaOrder = (
41
43
  options: Pick<
42
44
  ConstructProviderFetchInput<any, 'signTypedDataCall'>,
@@ -0,0 +1,343 @@
1
+ import type {
2
+ ConstructProviderFetchInput,
3
+ RequestParameters,
4
+ TxSendOverrides,
5
+ } from '../../types';
6
+ import { constructGetDeltaContract } from './getDeltaContract';
7
+ import { sanitizeDeltaOrderData } from './helpers/misc';
8
+ import { SignableDeltaOrderData } from './helpers/buildDeltaOrderData';
9
+ import { produceDeltaOrderHash } from './preSignDeltaOrder';
10
+ import type { ExtractAbiMethodNames } from '../../helpers/misc';
11
+ import type { Bridge, DeltaAuctionOrder } from './helpers/types';
12
+
13
+ export type CancelAndWithdrawDeltaOrderParams = {
14
+ order: DeltaAuctionOrder;
15
+ signature: string;
16
+ bridgeOverride: Pick<Bridge, 'protocolSelector' | 'protocolData'>;
17
+ cosignature: string;
18
+ isFillable: boolean;
19
+ };
20
+
21
+ export type CancelAndWithdrawDeltaOrder<T> = (
22
+ params: CancelAndWithdrawDeltaOrderParams,
23
+ overrides?: TxSendOverrides,
24
+ requestParams?: RequestParameters
25
+ ) => Promise<T>;
26
+
27
+ export type WithdrawDeltaNative<T> = (
28
+ amount: string,
29
+ overrides?: TxSendOverrides,
30
+ requestParams?: RequestParameters
31
+ ) => Promise<T>;
32
+
33
+ export type DepositNativeAndPreSign<T> = (
34
+ orderHash: string,
35
+ overrides?: TxSendOverrides,
36
+ requestParams?: RequestParameters
37
+ ) => Promise<T>;
38
+
39
+ export type DepositNativeAndPreSignDeltaOrder<T> = (
40
+ signableOrderData: SignableDeltaOrderData,
41
+ overrides?: TxSendOverrides,
42
+ requestParams?: RequestParameters
43
+ ) => Promise<T>;
44
+
45
+ export type DeltaTokenModuleFunctions<T> = {
46
+ /** @description Cancel an order on-chain and withdraw native ETH back to the owner */
47
+ cancelAndWithdrawDeltaOrder: CancelAndWithdrawDeltaOrder<T>;
48
+ /** @description Withdraw Delta Wrapped Native tokens as native ETH */
49
+ withdrawDeltaNative: WithdrawDeltaNative<T>;
50
+ /** @description Deposit native ETH and pre-sign a Delta order */
51
+ depositNativeAndPreSign: DepositNativeAndPreSign<T>;
52
+ /** @description Deposit native ETH and pre-sign a Delta order from signable order data */
53
+ depositNativeAndPreSignDeltaOrder: DepositNativeAndPreSignDeltaOrder<T>;
54
+ };
55
+
56
+ const DeltaTokenModuleAbi = [
57
+ {
58
+ type: 'function',
59
+ name: 'cancelAndWithdraw',
60
+ inputs: [
61
+ {
62
+ name: 'orderWithSig',
63
+ type: 'tuple',
64
+ internalType: 'struct OrderWithSig',
65
+ components: [
66
+ {
67
+ name: 'order',
68
+ type: 'tuple',
69
+ internalType: 'struct Order',
70
+ components: [
71
+ {
72
+ name: 'owner',
73
+ type: 'address',
74
+ internalType: 'address',
75
+ },
76
+ {
77
+ name: 'beneficiary',
78
+ type: 'address',
79
+ internalType: 'address',
80
+ },
81
+ {
82
+ name: 'srcToken',
83
+ type: 'address',
84
+ internalType: 'address',
85
+ },
86
+ {
87
+ name: 'destToken',
88
+ type: 'address',
89
+ internalType: 'address',
90
+ },
91
+ {
92
+ name: 'srcAmount',
93
+ type: 'uint256',
94
+ internalType: 'uint256',
95
+ },
96
+ {
97
+ name: 'destAmount',
98
+ type: 'uint256',
99
+ internalType: 'uint256',
100
+ },
101
+ {
102
+ name: 'expectedAmount',
103
+ type: 'uint256',
104
+ internalType: 'uint256',
105
+ },
106
+ {
107
+ name: 'deadline',
108
+ type: 'uint256',
109
+ internalType: 'uint256',
110
+ },
111
+ {
112
+ name: 'kind',
113
+ type: 'uint8',
114
+ internalType: 'enum OrderKind',
115
+ },
116
+ {
117
+ name: 'nonce',
118
+ type: 'uint256',
119
+ internalType: 'uint256',
120
+ },
121
+ {
122
+ name: 'partnerAndFee',
123
+ type: 'uint256',
124
+ internalType: 'uint256',
125
+ },
126
+ {
127
+ name: 'permit',
128
+ type: 'bytes',
129
+ internalType: 'bytes',
130
+ },
131
+ {
132
+ name: 'metadata',
133
+ type: 'bytes',
134
+ internalType: 'bytes',
135
+ },
136
+ {
137
+ name: 'bridge',
138
+ type: 'tuple',
139
+ internalType: 'struct Bridge',
140
+ components: [
141
+ {
142
+ name: 'protocolSelector',
143
+ type: 'bytes4',
144
+ internalType: 'bytes4',
145
+ },
146
+ {
147
+ name: 'destinationChainId',
148
+ type: 'uint256',
149
+ internalType: 'uint256',
150
+ },
151
+ {
152
+ name: 'outputToken',
153
+ type: 'address',
154
+ internalType: 'address',
155
+ },
156
+ {
157
+ name: 'scalingFactor',
158
+ type: 'int8',
159
+ internalType: 'int8',
160
+ },
161
+ {
162
+ name: 'protocolData',
163
+ type: 'bytes',
164
+ internalType: 'bytes',
165
+ },
166
+ ],
167
+ },
168
+ ],
169
+ },
170
+ {
171
+ name: 'signature',
172
+ type: 'bytes',
173
+ internalType: 'bytes',
174
+ },
175
+ {
176
+ name: 'bridgeOverride',
177
+ type: 'tuple',
178
+ internalType: 'struct BridgeOverride',
179
+ components: [
180
+ {
181
+ name: 'protocolSelector',
182
+ type: 'bytes4',
183
+ internalType: 'bytes4',
184
+ },
185
+ {
186
+ name: 'protocolData',
187
+ type: 'bytes',
188
+ internalType: 'bytes',
189
+ },
190
+ ],
191
+ },
192
+ {
193
+ name: 'cosignature',
194
+ type: 'bytes',
195
+ internalType: 'bytes',
196
+ },
197
+ ],
198
+ },
199
+ {
200
+ name: 'isFillable',
201
+ type: 'bool',
202
+ internalType: 'bool',
203
+ },
204
+ ],
205
+ outputs: [],
206
+ stateMutability: 'nonpayable',
207
+ },
208
+ {
209
+ type: 'function',
210
+ name: 'withdrawNative',
211
+ inputs: [
212
+ {
213
+ name: 'amount',
214
+ type: 'uint256',
215
+ internalType: 'uint256',
216
+ },
217
+ ],
218
+ outputs: [],
219
+ stateMutability: 'nonpayable',
220
+ },
221
+ {
222
+ type: 'function',
223
+ name: 'depositNativeAndPreSign',
224
+ inputs: [
225
+ {
226
+ name: 'orderHash',
227
+ type: 'bytes32',
228
+ internalType: 'bytes32',
229
+ },
230
+ ],
231
+ outputs: [],
232
+ stateMutability: 'payable',
233
+ },
234
+ ] as const;
235
+
236
+ type AvailableMethods = ExtractAbiMethodNames<typeof DeltaTokenModuleAbi>;
237
+
238
+ // returns whatever `contractCaller` returns
239
+ // to allow for better versatility
240
+ export const constructDeltaTokenModule = <T>(
241
+ options: Pick<
242
+ ConstructProviderFetchInput<T, 'transactCall'>,
243
+ 'contractCaller' | 'fetcher' | 'apiURL' | 'chainId'
244
+ >
245
+ ): DeltaTokenModuleFunctions<T> => {
246
+ // cached internally
247
+ const { getDeltaContract } = constructGetDeltaContract(options);
248
+
249
+ const cancelAndWithdrawDeltaOrder: CancelAndWithdrawDeltaOrder<T> = async (
250
+ { order, signature, bridgeOverride, cosignature, isFillable },
251
+ overrides = {},
252
+ requestParams
253
+ ) => {
254
+ const ParaswapDelta = await getDeltaContract(requestParams);
255
+ if (!ParaswapDelta) {
256
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
257
+ }
258
+
259
+ const orderWithSig = {
260
+ order,
261
+ signature,
262
+ bridgeOverride,
263
+ cosignature,
264
+ };
265
+
266
+ const res = await options.contractCaller.transactCall<AvailableMethods>({
267
+ address: ParaswapDelta,
268
+ abi: DeltaTokenModuleAbi,
269
+ contractMethod: 'cancelAndWithdraw',
270
+ args: [orderWithSig, isFillable],
271
+ overrides,
272
+ });
273
+
274
+ return res;
275
+ };
276
+
277
+ const withdrawDeltaNative: WithdrawDeltaNative<T> = async (
278
+ amount,
279
+ overrides = {},
280
+ requestParams
281
+ ) => {
282
+ const ParaswapDelta = await getDeltaContract(requestParams);
283
+ if (!ParaswapDelta) {
284
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
285
+ }
286
+
287
+ const res = await options.contractCaller.transactCall<AvailableMethods>({
288
+ address: ParaswapDelta,
289
+ abi: DeltaTokenModuleAbi,
290
+ contractMethod: 'withdrawNative',
291
+ args: [amount],
292
+ overrides,
293
+ });
294
+
295
+ return res;
296
+ };
297
+
298
+ const depositNativeAndPreSign: DepositNativeAndPreSign<T> = async (
299
+ orderHash,
300
+ overrides = {},
301
+ requestParams
302
+ ) => {
303
+ const ParaswapDelta = await getDeltaContract(requestParams);
304
+ if (!ParaswapDelta) {
305
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
306
+ }
307
+
308
+ const res = await options.contractCaller.transactCall<AvailableMethods>({
309
+ address: ParaswapDelta,
310
+ abi: DeltaTokenModuleAbi,
311
+ contractMethod: 'depositNativeAndPreSign',
312
+ args: [orderHash],
313
+ overrides,
314
+ });
315
+
316
+ return res;
317
+ };
318
+
319
+ const depositNativeAndPreSignDeltaOrder: DepositNativeAndPreSignDeltaOrder<
320
+ T
321
+ > = async (signableOrderData, overrides = {}, requestParams) => {
322
+ // types allow to pass OrderData & extra_stuff, but tx will break like that
323
+ const typedDataOnly: SignableDeltaOrderData = {
324
+ ...signableOrderData,
325
+ data: sanitizeDeltaOrderData(signableOrderData.data),
326
+ };
327
+
328
+ const orderHash = produceDeltaOrderHash(typedDataOnly);
329
+ const res = await depositNativeAndPreSign(
330
+ orderHash,
331
+ overrides,
332
+ requestParams
333
+ );
334
+ return res;
335
+ };
336
+
337
+ return {
338
+ cancelAndWithdrawDeltaOrder,
339
+ withdrawDeltaNative,
340
+ depositNativeAndPreSign,
341
+ depositNativeAndPreSignDeltaOrder,
342
+ };
343
+ };
@@ -50,6 +50,10 @@ import {
50
50
  constructPreSignDeltaOrder,
51
51
  PreSignDeltaOrderFunctions,
52
52
  } from './preSignDeltaOrder';
53
+ import {
54
+ DeltaTokenModuleFunctions,
55
+ constructDeltaTokenModule,
56
+ } from './deltaTokenModule';
53
57
 
54
58
  export type SubmitDeltaOrderParams = BuildDeltaOrderDataParams & {
55
59
  /** @description designates the Order as being able to be partially filled, as opposed to fill-or-kill */
@@ -107,7 +111,8 @@ export type DeltaOrderHandlers<T> = SubmitDeltaOrderFuncs &
107
111
  PostDeltaOrderFunctions &
108
112
  SignDeltaOrderFunctions &
109
113
  PreSignDeltaOrderFunctions<T> &
110
- CancelDeltaOrderFunctions;
114
+ CancelDeltaOrderFunctions &
115
+ DeltaTokenModuleFunctions<T>;
111
116
 
112
117
  /** @description construct SDK with every Delta Order-related method, fetching from API and Order signing */
113
118
  export const constructAllDeltaOrdersHandlers = <TxResponse>(
@@ -135,6 +140,8 @@ export const constructAllDeltaOrdersHandlers = <TxResponse>(
135
140
 
136
141
  const deltaOrdersCancel = constructCancelDeltaOrder(options);
137
142
 
143
+ const deltaTokenModule = constructDeltaTokenModule(options);
144
+
138
145
  return {
139
146
  ...deltaOrdersGetters,
140
147
  ...deltaOrdersContractGetter,
@@ -149,5 +156,6 @@ export const constructAllDeltaOrdersHandlers = <TxResponse>(
149
156
  ...deltaOrdersPreSign,
150
157
  ...deltaOrdersPost,
151
158
  ...deltaOrdersCancel,
159
+ ...deltaTokenModule,
152
160
  };
153
161
  };
@@ -13,6 +13,7 @@ import type { ApproveTokenForNFTOrderFunctions } from '../methods/nftOrders/appr
13
13
  import type { FillOrderDirectlyFunctions } from '../methods/limitOrders/fillOrderDirectly';
14
14
  import type { ApproveTokenForDeltaFunctions } from '../methods/delta/approveForDelta';
15
15
  import type { PreSignDeltaOrderFunctions } from '../methods/delta/preSignDeltaOrder';
16
+ import type { DeltaTokenModuleFunctions } from '../methods/delta/deltaTokenModule';
16
17
  import { API_URL, DEFAULT_VERSION } from '../constants';
17
18
 
18
19
  export type SDKConfig<TxResponse = any> = ConstructProviderFetchInput<
@@ -52,7 +53,8 @@ type InferWithTxResponse<
52
53
  CancelNFTOrderFunctions<TxResponse>,
53
54
  ApproveTokenForNFTOrderFunctions<TxResponse>,
54
55
  ApproveTokenForDeltaFunctions<TxResponse>,
55
- PreSignDeltaOrderFunctions<TxResponse>
56
+ PreSignDeltaOrderFunctions<TxResponse>,
57
+ DeltaTokenModuleFunctions<TxResponse>
56
58
  ]
57
59
  // then merge IntersectionOfReturns<Funcs> with them recursively
58
60
  >