@velora-dex/sdk 9.3.4-dev.1 → 9.3.4-dev.2

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.
@@ -1,343 +0,0 @@
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
- };