@velora-dex/sdk 9.3.4-dev.3 → 9.3.4

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.4-dev.3",
3
+ "version": "9.3.4",
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,13 @@ import {
216
216
  CancelDeltaOrderFunctions,
217
217
  constructCancelDeltaOrder,
218
218
  } from './methods/delta/cancelDeltaOrder';
219
+ import {
220
+ DeltaTokenModuleFunctions,
221
+ CancelAndWithdrawDeltaOrderParams,
222
+ constructDeltaTokenModule,
223
+ DepositNativeAndPreSignParams,
224
+ DepositNativeAndPreSignDeltaOrderParams,
225
+ } from './methods/delta/deltaTokenModule';
219
226
 
220
227
  export { constructSwapSDK, SwapSDKMethods } from './methods/swap';
221
228
 
@@ -300,6 +307,7 @@ export {
300
307
  constructGetDeltaPrice,
301
308
  constructGetDeltaOrders,
302
309
  constructCancelDeltaOrder,
310
+ constructDeltaTokenModule,
303
311
  constructApproveTokenForDelta,
304
312
  // Quote methods
305
313
  constructGetQuote,
@@ -395,6 +403,10 @@ export type {
395
403
  GetDeltaOrdersFunctions,
396
404
  ApproveTokenForDeltaFunctions,
397
405
  CancelDeltaOrderFunctions,
406
+ DeltaTokenModuleFunctions,
407
+ CancelAndWithdrawDeltaOrderParams,
408
+ DepositNativeAndPreSignParams,
409
+ DepositNativeAndPreSignDeltaOrderParams,
398
410
  // types for Quote methods
399
411
  GetQuoteFunctions,
400
412
  QuoteParams,
@@ -0,0 +1,11 @@
1
+ import { ZERO_ADDRESS } from '../common/orders/buildOrderData';
2
+ import { Bridge } from './helpers/types';
3
+
4
+ // for same-chain Orders, all 0 params
5
+ export const DEFAULT_BRIDGE = {
6
+ protocolSelector: '0x00000000', // 4 bytes
7
+ destinationChainId: 0,
8
+ outputToken: ZERO_ADDRESS,
9
+ scalingFactor: 0,
10
+ protocolData: '0x',
11
+ } as const satisfies Bridge;
@@ -0,0 +1,367 @@
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 { DeltaAuctionOrder } from './helpers/types';
12
+ import { DEFAULT_BRIDGE } from './constants';
13
+
14
+ export type CancelAndWithdrawDeltaOrderParams = {
15
+ order: DeltaAuctionOrder;
16
+ signature: string;
17
+ /** @description A boolean indicating whether the order is a fillable order. False by default */
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 DepositNativeAndPreSignParams = {
34
+ orderHash: string;
35
+ depositAmount: string;
36
+ };
37
+
38
+ export type DepositNativeAndPreSign<T> = (
39
+ params: DepositNativeAndPreSignParams,
40
+ overrides?: Omit<TxSendOverrides, 'value'>, // value is set internally based on depositAmount
41
+ requestParams?: RequestParameters
42
+ ) => Promise<T>;
43
+
44
+ export type DepositNativeAndPreSignDeltaOrderParams = Pick<
45
+ DepositNativeAndPreSignParams,
46
+ 'depositAmount'
47
+ > & {
48
+ signableOrderData: SignableDeltaOrderData;
49
+ };
50
+
51
+ export type DepositNativeAndPreSignDeltaOrder<T> = (
52
+ params: DepositNativeAndPreSignDeltaOrderParams,
53
+ overrides?: Omit<TxSendOverrides, 'value'>, // value is set internally based on depositAmount
54
+ requestParams?: RequestParameters
55
+ ) => Promise<T>;
56
+
57
+ export type DeltaTokenModuleFunctions<T> = {
58
+ /** @description Cancel an order on-chain and withdraw native ETH back to the owner */
59
+ cancelAndWithdrawDeltaOrder: CancelAndWithdrawDeltaOrder<T>;
60
+ /** @description Withdraw Delta Wrapped Native tokens as native ETH */
61
+ withdrawDeltaNative: WithdrawDeltaNative<T>;
62
+ /** @description Deposit native ETH and pre-sign a Delta order */
63
+ depositNativeAndPreSign: DepositNativeAndPreSign<T>;
64
+ /** @description Deposit native ETH and pre-sign a Delta order from signable order data */
65
+ depositNativeAndPreSignDeltaOrder: DepositNativeAndPreSignDeltaOrder<T>;
66
+ };
67
+
68
+ const DeltaTokenModuleAbi = [
69
+ {
70
+ type: 'function',
71
+ name: 'cancelAndWithdraw',
72
+ inputs: [
73
+ {
74
+ name: 'orderWithSig',
75
+ type: 'tuple',
76
+ internalType: 'struct OrderWithSig',
77
+ components: [
78
+ {
79
+ name: 'order',
80
+ type: 'tuple',
81
+ internalType: 'struct Order',
82
+ components: [
83
+ {
84
+ name: 'owner',
85
+ type: 'address',
86
+ internalType: 'address',
87
+ },
88
+ {
89
+ name: 'beneficiary',
90
+ type: 'address',
91
+ internalType: 'address',
92
+ },
93
+ {
94
+ name: 'srcToken',
95
+ type: 'address',
96
+ internalType: 'address',
97
+ },
98
+ {
99
+ name: 'destToken',
100
+ type: 'address',
101
+ internalType: 'address',
102
+ },
103
+ {
104
+ name: 'srcAmount',
105
+ type: 'uint256',
106
+ internalType: 'uint256',
107
+ },
108
+ {
109
+ name: 'destAmount',
110
+ type: 'uint256',
111
+ internalType: 'uint256',
112
+ },
113
+ {
114
+ name: 'expectedAmount',
115
+ type: 'uint256',
116
+ internalType: 'uint256',
117
+ },
118
+ {
119
+ name: 'deadline',
120
+ type: 'uint256',
121
+ internalType: 'uint256',
122
+ },
123
+ {
124
+ name: 'kind',
125
+ type: 'uint8',
126
+ internalType: 'enum OrderKind',
127
+ },
128
+ {
129
+ name: 'nonce',
130
+ type: 'uint256',
131
+ internalType: 'uint256',
132
+ },
133
+ {
134
+ name: 'partnerAndFee',
135
+ type: 'uint256',
136
+ internalType: 'uint256',
137
+ },
138
+ {
139
+ name: 'permit',
140
+ type: 'bytes',
141
+ internalType: 'bytes',
142
+ },
143
+ {
144
+ name: 'metadata',
145
+ type: 'bytes',
146
+ internalType: 'bytes',
147
+ },
148
+ {
149
+ name: 'bridge',
150
+ type: 'tuple',
151
+ internalType: 'struct Bridge',
152
+ components: [
153
+ {
154
+ name: 'protocolSelector',
155
+ type: 'bytes4',
156
+ internalType: 'bytes4',
157
+ },
158
+ {
159
+ name: 'destinationChainId',
160
+ type: 'uint256',
161
+ internalType: 'uint256',
162
+ },
163
+ {
164
+ name: 'outputToken',
165
+ type: 'address',
166
+ internalType: 'address',
167
+ },
168
+ {
169
+ name: 'scalingFactor',
170
+ type: 'int8',
171
+ internalType: 'int8',
172
+ },
173
+ {
174
+ name: 'protocolData',
175
+ type: 'bytes',
176
+ internalType: 'bytes',
177
+ },
178
+ ],
179
+ },
180
+ ],
181
+ },
182
+ {
183
+ name: 'signature',
184
+ type: 'bytes',
185
+ internalType: 'bytes',
186
+ },
187
+ {
188
+ name: 'bridgeOverride',
189
+ type: 'tuple',
190
+ internalType: 'struct BridgeOverride',
191
+ components: [
192
+ {
193
+ name: 'protocolSelector',
194
+ type: 'bytes4',
195
+ internalType: 'bytes4',
196
+ },
197
+ {
198
+ name: 'protocolData',
199
+ type: 'bytes',
200
+ internalType: 'bytes',
201
+ },
202
+ ],
203
+ },
204
+ {
205
+ name: 'cosignature',
206
+ type: 'bytes',
207
+ internalType: 'bytes',
208
+ },
209
+ ],
210
+ },
211
+ {
212
+ name: 'isFillable',
213
+ type: 'bool',
214
+ internalType: 'bool',
215
+ },
216
+ ],
217
+ outputs: [],
218
+ stateMutability: 'nonpayable',
219
+ },
220
+ {
221
+ type: 'function',
222
+ name: 'withdrawNative',
223
+ inputs: [
224
+ {
225
+ name: 'amount',
226
+ type: 'uint256',
227
+ internalType: 'uint256',
228
+ },
229
+ ],
230
+ outputs: [],
231
+ stateMutability: 'nonpayable',
232
+ },
233
+ {
234
+ type: 'function',
235
+ name: 'depositNativeAndPreSign',
236
+ inputs: [
237
+ {
238
+ name: 'orderHash',
239
+ type: 'bytes32',
240
+ internalType: 'bytes32',
241
+ },
242
+ ],
243
+ outputs: [],
244
+ stateMutability: 'payable',
245
+ },
246
+ ] as const;
247
+
248
+ type AvailableMethods = ExtractAbiMethodNames<typeof DeltaTokenModuleAbi>;
249
+
250
+ // returns whatever `contractCaller` returns
251
+ // to allow for better versatility
252
+ export const constructDeltaTokenModule = <T>(
253
+ options: Pick<
254
+ ConstructProviderFetchInput<T, 'transactCall'>,
255
+ 'contractCaller' | 'fetcher' | 'apiURL' | 'chainId'
256
+ >
257
+ ): DeltaTokenModuleFunctions<T> => {
258
+ // cached internally
259
+ const { getDeltaContract } = constructGetDeltaContract(options);
260
+
261
+ const cancelAndWithdrawDeltaOrder: CancelAndWithdrawDeltaOrder<T> = async (
262
+ { order, signature, isFillable = false },
263
+ overrides = {},
264
+ requestParams
265
+ ) => {
266
+ const ParaswapDelta = await getDeltaContract(requestParams);
267
+ if (!ParaswapDelta) {
268
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
269
+ }
270
+
271
+ const orderWithSig = {
272
+ order,
273
+ signature,
274
+ // bridgeOverride and cosignature are not used by the contract,
275
+ // can always provide defaults
276
+ bridgeOverride: {
277
+ protocolData: DEFAULT_BRIDGE.protocolData,
278
+ protocolSelector: DEFAULT_BRIDGE.protocolSelector,
279
+ },
280
+ cosignature: '0x',
281
+ };
282
+
283
+ const res = await options.contractCaller.transactCall<AvailableMethods>({
284
+ address: ParaswapDelta,
285
+ abi: DeltaTokenModuleAbi,
286
+ contractMethod: 'cancelAndWithdraw',
287
+ args: [orderWithSig, isFillable],
288
+ overrides,
289
+ });
290
+
291
+ return res;
292
+ };
293
+
294
+ const withdrawDeltaNative: WithdrawDeltaNative<T> = async (
295
+ amount,
296
+ overrides = {},
297
+ requestParams
298
+ ) => {
299
+ const ParaswapDelta = await getDeltaContract(requestParams);
300
+ if (!ParaswapDelta) {
301
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
302
+ }
303
+
304
+ const res = await options.contractCaller.transactCall<AvailableMethods>({
305
+ address: ParaswapDelta,
306
+ abi: DeltaTokenModuleAbi,
307
+ contractMethod: 'withdrawNative',
308
+ args: [amount],
309
+ overrides,
310
+ });
311
+
312
+ return res;
313
+ };
314
+
315
+ const depositNativeAndPreSign: DepositNativeAndPreSign<T> = async (
316
+ { orderHash, depositAmount },
317
+ overrides = {},
318
+ requestParams
319
+ ) => {
320
+ const ParaswapDelta = await getDeltaContract(requestParams);
321
+ if (!ParaswapDelta) {
322
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
323
+ }
324
+
325
+ const res = await options.contractCaller.transactCall<AvailableMethods>({
326
+ address: ParaswapDelta,
327
+ abi: DeltaTokenModuleAbi,
328
+ contractMethod: 'depositNativeAndPreSign',
329
+ args: [orderHash],
330
+ overrides: {
331
+ ...overrides,
332
+ value: depositAmount,
333
+ },
334
+ });
335
+
336
+ return res;
337
+ };
338
+
339
+ const depositNativeAndPreSignDeltaOrder: DepositNativeAndPreSignDeltaOrder<
340
+ T
341
+ > = async (
342
+ { signableOrderData, depositAmount },
343
+ overrides = {},
344
+ requestParams
345
+ ) => {
346
+ // types allow to pass OrderData & extra_stuff, but tx will break like that
347
+ const typedDataOnly: SignableDeltaOrderData = {
348
+ ...signableOrderData,
349
+ data: sanitizeDeltaOrderData(signableOrderData.data),
350
+ };
351
+
352
+ const orderHash = produceDeltaOrderHash(typedDataOnly);
353
+ const res = await depositNativeAndPreSign(
354
+ { orderHash, depositAmount },
355
+ overrides,
356
+ requestParams
357
+ );
358
+ return res;
359
+ };
360
+
361
+ return {
362
+ cancelAndWithdrawDeltaOrder,
363
+ withdrawDeltaNative,
364
+ depositNativeAndPreSign,
365
+ depositNativeAndPreSignDeltaOrder,
366
+ };
367
+ };
@@ -7,7 +7,6 @@ import type {
7
7
  EnumerateLiteral,
8
8
  RequestParameters,
9
9
  } from '../../types';
10
- import { ZERO_ADDRESS } from '../common/orders/buildOrderData';
11
10
  import { BridgePriceInfo } from './helpers/types';
12
11
 
13
12
  type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
@@ -56,15 +55,6 @@ type DeltaPriceQueryOptions = Omit<
56
55
  excludeBridges?: string;
57
56
  };
58
57
 
59
- // for same-chain Orders, all 0 params
60
- export const DEFAULT_BRIDGE = {
61
- protocolSelector: '0x00000000', // 4 bytes
62
- destinationChainId: 0,
63
- outputToken: ZERO_ADDRESS,
64
- scalingFactor: 0,
65
- protocolData: '0x',
66
- } as const satisfies Bridge;
67
-
68
58
  export type DeltaPrice = {
69
59
  srcToken: string;
70
60
  destToken: string;
@@ -99,10 +89,6 @@ export type DeltaPrice = {
99
89
 
100
90
  type AvailableBridgePrice = Pick<
101
91
  DeltaPrice,
102
- | 'srcAmount'
103
- | 'srcAmountBeforeFee' // Available for BUY side
104
- | 'srcUSD'
105
- | 'srcUSDBeforeFee' // Available for BUY side
106
92
  | 'destToken'
107
93
  | 'destAmount'
108
94
  | 'destAmountBeforeFee' // Available for SELL side
@@ -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
  >