@velora-dex/sdk 9.4.2 → 9.4.3-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/dist/examples/wagmi.d.ts.map +1 -1
- package/dist/index.d.ts +11 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/methods/delta/buildDeltaOrder.d.ts +2 -2
- package/dist/methods/delta/buildDeltaOrder.d.ts.map +1 -1
- package/dist/methods/delta/buildExternalDeltaOrder.d.ts +2 -2
- package/dist/methods/delta/buildExternalDeltaOrder.d.ts.map +1 -1
- package/dist/methods/delta/buildTWAPDeltaOrder.d.ts +65 -0
- package/dist/methods/delta/buildTWAPDeltaOrder.d.ts.map +1 -0
- package/dist/methods/delta/deltaTokenModule.d.ts +7 -1
- package/dist/methods/delta/deltaTokenModule.d.ts.map +1 -1
- package/dist/methods/delta/helpers/buildTWAPOrderData.d.ts +74 -0
- package/dist/methods/delta/helpers/buildTWAPOrderData.d.ts.map +1 -0
- package/dist/methods/delta/helpers/misc.d.ts +10 -2
- package/dist/methods/delta/helpers/misc.d.ts.map +1 -1
- package/dist/methods/delta/helpers/types.d.ts +47 -6
- package/dist/methods/delta/helpers/types.d.ts.map +1 -1
- package/dist/methods/delta/index.d.ts +17 -1
- package/dist/methods/delta/index.d.ts.map +1 -1
- package/dist/methods/delta/postTWAPDeltaOrder.d.ts +16 -0
- package/dist/methods/delta/postTWAPDeltaOrder.d.ts.map +1 -0
- package/dist/methods/delta/preSignTWAPDeltaOrder.d.ts +20 -0
- package/dist/methods/delta/preSignTWAPDeltaOrder.d.ts.map +1 -0
- package/dist/methods/delta/signTWAPDeltaOrder.d.ts +9 -0
- package/dist/methods/delta/signTWAPDeltaOrder.d.ts.map +1 -0
- package/dist/sdk/partial.d.ts +3 -1
- package/dist/sdk/partial.d.ts.map +1 -1
- package/dist/sdk.cjs.development.js +985 -132
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +981 -133
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +63 -0
- package/src/methods/delta/buildDeltaOrder.ts +2 -2
- package/src/methods/delta/buildExternalDeltaOrder.ts +2 -2
- package/src/methods/delta/buildTWAPDeltaOrder.ts +187 -0
- package/src/methods/delta/deltaTokenModule.ts +229 -1
- package/src/methods/delta/helpers/buildTWAPOrderData.ts +233 -0
- package/src/methods/delta/helpers/misc.ts +39 -3
- package/src/methods/delta/helpers/types.ts +59 -9
- package/src/methods/delta/index.ts +80 -1
- package/src/methods/delta/postTWAPDeltaOrder.ts +57 -0
- package/src/methods/delta/preSignTWAPDeltaOrder.ts +170 -0
- package/src/methods/delta/signTWAPDeltaOrder.ts +32 -0
- package/src/sdk/partial.ts +3 -1
- package/src/constants.js +0 -3
- package/src/gas.js +0 -1
- package/src/index.js +0 -73
- package/src/types.js +0 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -141,12 +141,20 @@ import type {
|
|
|
141
141
|
DeltaAuctionOrder,
|
|
142
142
|
DeltaAuction,
|
|
143
143
|
DeltaAuctionStatus,
|
|
144
|
+
DeltaAuctionTransaction,
|
|
144
145
|
BridgeMetadata,
|
|
145
146
|
BridgeStatus,
|
|
146
147
|
Bridge,
|
|
147
148
|
ExternalDeltaOrder,
|
|
149
|
+
TWAPDeltaOrder,
|
|
150
|
+
TWAPBuyDeltaOrder,
|
|
151
|
+
TWAPOnChainOrderType,
|
|
148
152
|
OnChainOrderType,
|
|
149
153
|
SwapSideUnion,
|
|
154
|
+
DeltaAmountsWithSlippage,
|
|
155
|
+
DeltaAmountsSellSlippage,
|
|
156
|
+
DeltaAmountsBuySlippage,
|
|
157
|
+
DeltaAmountsExplicit,
|
|
150
158
|
} from './methods/delta/helpers/types';
|
|
151
159
|
import {
|
|
152
160
|
BuildDeltaOrderDataParams,
|
|
@@ -156,6 +164,7 @@ import {
|
|
|
156
164
|
} from './methods/delta/buildDeltaOrder';
|
|
157
165
|
import {
|
|
158
166
|
constructPostDeltaOrder,
|
|
167
|
+
DeltaOrderToPost,
|
|
159
168
|
PostDeltaOrderFunctions,
|
|
160
169
|
PostDeltaOrderParams,
|
|
161
170
|
} from './methods/delta/postDeltaOrder';
|
|
@@ -224,6 +233,28 @@ import {
|
|
|
224
233
|
PreSignExternalDeltaOrderFunctions,
|
|
225
234
|
} from './methods/delta/preSignExternalDeltaOrder';
|
|
226
235
|
|
|
236
|
+
import {
|
|
237
|
+
BuildTWAPDeltaOrderParams,
|
|
238
|
+
BuildTWAPSellOrderParams,
|
|
239
|
+
BuildTWAPBuyOrderParams,
|
|
240
|
+
BuildTWAPDeltaOrderFunctions,
|
|
241
|
+
constructBuildTWAPDeltaOrder,
|
|
242
|
+
} from './methods/delta/buildTWAPDeltaOrder';
|
|
243
|
+
import type { SignableTWAPOrderData } from './methods/delta/helpers/buildTWAPOrderData';
|
|
244
|
+
import {
|
|
245
|
+
constructSignTWAPDeltaOrder,
|
|
246
|
+
SignTWAPDeltaOrderFunctions,
|
|
247
|
+
} from './methods/delta/signTWAPDeltaOrder';
|
|
248
|
+
import {
|
|
249
|
+
constructPostTWAPDeltaOrder,
|
|
250
|
+
PostTWAPDeltaOrderFunctions,
|
|
251
|
+
PostTWAPDeltaOrderParams,
|
|
252
|
+
} from './methods/delta/postTWAPDeltaOrder';
|
|
253
|
+
import {
|
|
254
|
+
constructPreSignTWAPDeltaOrder,
|
|
255
|
+
PreSignTWAPDeltaOrderFunctions,
|
|
256
|
+
} from './methods/delta/preSignTWAPDeltaOrder';
|
|
257
|
+
|
|
227
258
|
import {
|
|
228
259
|
constructGetQuote,
|
|
229
260
|
GetQuoteFunctions,
|
|
@@ -244,6 +275,10 @@ import {
|
|
|
244
275
|
DepositNativeAndPreSignParams,
|
|
245
276
|
DepositNativeAndPreSignDeltaOrderParams,
|
|
246
277
|
} from './methods/delta/deltaTokenModule';
|
|
278
|
+
import {
|
|
279
|
+
CancelDeltaOrderData,
|
|
280
|
+
SignableCancelDeltaOrderData,
|
|
281
|
+
} from './methods/delta/helpers/buildCancelDeltaOrderData';
|
|
247
282
|
|
|
248
283
|
export { constructSwapSDK, SwapSDKMethods } from './methods/swap';
|
|
249
284
|
|
|
@@ -257,9 +292,11 @@ export {
|
|
|
257
292
|
constructAllDeltaOrdersHandlers,
|
|
258
293
|
constructSubmitDeltaOrder,
|
|
259
294
|
constructSubmitExternalDeltaOrder,
|
|
295
|
+
constructSubmitTWAPDeltaOrder,
|
|
260
296
|
DeltaOrderHandlers,
|
|
261
297
|
SubmitDeltaOrderParams,
|
|
262
298
|
SubmitExternalDeltaOrderParams,
|
|
299
|
+
SubmitTWAPDeltaOrderParams,
|
|
263
300
|
} from './methods/delta';
|
|
264
301
|
|
|
265
302
|
export type {
|
|
@@ -337,6 +374,11 @@ export {
|
|
|
337
374
|
constructSignExternalDeltaOrder,
|
|
338
375
|
constructPostExternalDeltaOrder,
|
|
339
376
|
constructPreSignExternalDeltaOrder,
|
|
377
|
+
// TWAP Delta methods
|
|
378
|
+
constructBuildTWAPDeltaOrder,
|
|
379
|
+
constructSignTWAPDeltaOrder,
|
|
380
|
+
constructPostTWAPDeltaOrder,
|
|
381
|
+
constructPreSignTWAPDeltaOrder,
|
|
340
382
|
// Quote methods
|
|
341
383
|
constructGetQuote,
|
|
342
384
|
// different helpers
|
|
@@ -409,8 +451,11 @@ export type {
|
|
|
409
451
|
DeltaAuctionOrder,
|
|
410
452
|
DeltaAuction,
|
|
411
453
|
DeltaAuctionStatus,
|
|
454
|
+
DeltaAuctionTransaction,
|
|
412
455
|
DeltaOrderFilterByStatus,
|
|
413
456
|
DeltaOrderFromAPI,
|
|
457
|
+
CancelDeltaOrderData,
|
|
458
|
+
SignableCancelDeltaOrderData,
|
|
414
459
|
// bridge part of DeltaOrder
|
|
415
460
|
BridgeMetadata,
|
|
416
461
|
BridgeStatus,
|
|
@@ -421,6 +466,7 @@ export type {
|
|
|
421
466
|
BuildDeltaOrderDataParams,
|
|
422
467
|
BuildDeltaOrderFunctions,
|
|
423
468
|
SignableDeltaOrderData,
|
|
469
|
+
DeltaOrderToPost,
|
|
424
470
|
PostDeltaOrderFunctions,
|
|
425
471
|
PostDeltaOrderParams,
|
|
426
472
|
SignDeltaOrderFunctions,
|
|
@@ -436,7 +482,14 @@ export type {
|
|
|
436
482
|
DepositNativeAndPreSignDeltaOrderParams,
|
|
437
483
|
// External Delta types
|
|
438
484
|
ExternalDeltaOrder,
|
|
485
|
+
TWAPDeltaOrder,
|
|
486
|
+
TWAPBuyDeltaOrder,
|
|
487
|
+
TWAPOnChainOrderType,
|
|
439
488
|
OnChainOrderType,
|
|
489
|
+
DeltaAmountsWithSlippage,
|
|
490
|
+
DeltaAmountsSellSlippage,
|
|
491
|
+
DeltaAmountsBuySlippage,
|
|
492
|
+
DeltaAmountsExplicit,
|
|
440
493
|
SignableExternalOrderData,
|
|
441
494
|
BuildExternalDeltaOrderParams,
|
|
442
495
|
BuildExternalDeltaOrderFunctions,
|
|
@@ -444,6 +497,16 @@ export type {
|
|
|
444
497
|
PostExternalDeltaOrderFunctions,
|
|
445
498
|
PostExternalDeltaOrderParams,
|
|
446
499
|
PreSignExternalDeltaOrderFunctions,
|
|
500
|
+
// TWAP Delta types
|
|
501
|
+
BuildTWAPDeltaOrderParams,
|
|
502
|
+
BuildTWAPSellOrderParams,
|
|
503
|
+
BuildTWAPBuyOrderParams,
|
|
504
|
+
BuildTWAPDeltaOrderFunctions,
|
|
505
|
+
SignableTWAPOrderData,
|
|
506
|
+
SignTWAPDeltaOrderFunctions,
|
|
507
|
+
PostTWAPDeltaOrderFunctions,
|
|
508
|
+
PostTWAPDeltaOrderParams,
|
|
509
|
+
PreSignTWAPDeltaOrderFunctions,
|
|
447
510
|
// types for Quote methods
|
|
448
511
|
GetQuoteFunctions,
|
|
449
512
|
QuoteParams,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type BuildDeltaOrderDataInput,
|
|
8
8
|
type SignableDeltaOrderData,
|
|
9
9
|
} from './helpers/buildDeltaOrderData';
|
|
10
|
-
import type {
|
|
10
|
+
import type { DeltaAmountsWithSlippage } from './helpers/types';
|
|
11
11
|
import { SwapSideToOrderKind } from './helpers/types';
|
|
12
12
|
import { resolvePartnerFee, resolveAmounts } from './helpers/misc';
|
|
13
13
|
import type { MarkOptional } from 'ts-essentials';
|
|
@@ -63,7 +63,7 @@ type BuildDeltaOrderDataParamsBase = {
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
export type BuildDeltaOrderDataParams = BuildDeltaOrderDataParamsBase &
|
|
66
|
-
|
|
66
|
+
DeltaAmountsWithSlippage;
|
|
67
67
|
|
|
68
68
|
type BuildDeltaOrder = (
|
|
69
69
|
buildOrderParams: BuildDeltaOrderDataParams,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type BuildExternalOrderDataInput,
|
|
8
8
|
type SignableExternalOrderData,
|
|
9
9
|
} from './helpers/buildExternalOrderData';
|
|
10
|
-
import type {
|
|
10
|
+
import type { DeltaAmountsWithSlippage } from './helpers/types';
|
|
11
11
|
import { SwapSideToOrderKind } from './helpers/types';
|
|
12
12
|
import type { MarkOptional } from 'ts-essentials';
|
|
13
13
|
import { resolvePartnerFee, resolveAmounts } from './helpers/misc';
|
|
@@ -54,7 +54,7 @@ type BuildExternalDeltaOrderParamsBase = {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export type BuildExternalDeltaOrderParams = BuildExternalDeltaOrderParamsBase &
|
|
57
|
-
|
|
57
|
+
DeltaAmountsWithSlippage;
|
|
58
58
|
|
|
59
59
|
type BuildExternalDeltaOrder = (
|
|
60
60
|
buildOrderParams: BuildExternalDeltaOrderParams,
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { ConstructFetchInput, RequestParameters } from '../../types';
|
|
2
|
+
import { DEFAULT_BRIDGE } from './constants';
|
|
3
|
+
import { constructGetDeltaContract } from './getDeltaContract';
|
|
4
|
+
import type { BridgePrice } from './getDeltaPrice';
|
|
5
|
+
import { constructGetPartnerFee } from './getPartnerFee';
|
|
6
|
+
import {
|
|
7
|
+
buildTWAPSignableOrderData,
|
|
8
|
+
TWAPOrderCommonInput,
|
|
9
|
+
type BuildTWAPOrderDataInput,
|
|
10
|
+
type SignableTWAPOrderData,
|
|
11
|
+
} from './helpers/buildTWAPOrderData';
|
|
12
|
+
import { applySlippage, resolvePartnerFee } from './helpers/misc';
|
|
13
|
+
import type { MarkOptional } from 'ts-essentials';
|
|
14
|
+
export type { SignableTWAPOrderData } from './helpers/buildTWAPOrderData';
|
|
15
|
+
|
|
16
|
+
type BuildTWAPDeltaOrderParamsBase = {
|
|
17
|
+
/** @description The address of the order owner */
|
|
18
|
+
owner: string;
|
|
19
|
+
/** @description The address of the order beneficiary */
|
|
20
|
+
beneficiary?: string;
|
|
21
|
+
/** @description The address of the src token */
|
|
22
|
+
srcToken: string;
|
|
23
|
+
/** @description The address of the dest token. For Crosschain Order - destination token on the destination chain */
|
|
24
|
+
destToken: string;
|
|
25
|
+
/** @description The deadline for the order */
|
|
26
|
+
deadline?: number;
|
|
27
|
+
/** @description The nonce of the order */
|
|
28
|
+
nonce?: number | string;
|
|
29
|
+
/** @description Optional permit signature for the src token */
|
|
30
|
+
permit?: string;
|
|
31
|
+
/** @description Partner string */
|
|
32
|
+
partner?: string;
|
|
33
|
+
/** @description Destination Chain ID for Crosschain Orders */
|
|
34
|
+
destChainId?: number;
|
|
35
|
+
/** @description Seconds between slice executions (min 60) */
|
|
36
|
+
interval: number;
|
|
37
|
+
/** @description Number of slices (min 2) */
|
|
38
|
+
numSlices: number;
|
|
39
|
+
/** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5% */
|
|
40
|
+
slippage?: number;
|
|
41
|
+
|
|
42
|
+
/** @description price response received from /delta/prices (getDeltaPrice method) for a single slice */
|
|
43
|
+
deltaPrice: MarkOptional<
|
|
44
|
+
Pick<
|
|
45
|
+
BridgePrice,
|
|
46
|
+
| 'destAmount'
|
|
47
|
+
| 'partner'
|
|
48
|
+
| 'partnerFee'
|
|
49
|
+
| 'destToken'
|
|
50
|
+
| 'srcAmount'
|
|
51
|
+
| 'bridge'
|
|
52
|
+
>,
|
|
53
|
+
'partner' | 'partnerFee'
|
|
54
|
+
>;
|
|
55
|
+
|
|
56
|
+
/** @description partner fee in basis points (bps), 50bps=0.5% */
|
|
57
|
+
partnerFeeBps?: number;
|
|
58
|
+
/** @description partner address */
|
|
59
|
+
partnerAddress?: string;
|
|
60
|
+
/** @description take surplus */
|
|
61
|
+
partnerTakesSurplus?: boolean;
|
|
62
|
+
/** @description A boolean indicating whether the surplus should be capped. True by default */
|
|
63
|
+
capSurplus?: boolean;
|
|
64
|
+
/** @description Metadata for the order, hex string */
|
|
65
|
+
metadata?: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type BuildTWAPSellOrderParams = BuildTWAPDeltaOrderParamsBase & {
|
|
69
|
+
/** @description Must be "TWAPOrder" for sell orders */
|
|
70
|
+
onChainOrderType: 'TWAPOrder';
|
|
71
|
+
/** @description Total source token amount across all slices */
|
|
72
|
+
totalSrcAmount: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type BuildTWAPBuyOrderParams = BuildTWAPDeltaOrderParamsBase & {
|
|
76
|
+
/** @description Must be "TWAPBuyOrder" for buy orders */
|
|
77
|
+
onChainOrderType: 'TWAPBuyOrder';
|
|
78
|
+
/** @description Total destination token amount to buy across all slices */
|
|
79
|
+
totalDestAmount: string;
|
|
80
|
+
/** @description Maximum source token amount willing to spend */
|
|
81
|
+
maxSrcAmount: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type BuildTWAPDeltaOrderParams =
|
|
85
|
+
| BuildTWAPSellOrderParams
|
|
86
|
+
| BuildTWAPBuyOrderParams;
|
|
87
|
+
|
|
88
|
+
type BuildTWAPDeltaOrder = (
|
|
89
|
+
buildOrderParams: BuildTWAPDeltaOrderParams,
|
|
90
|
+
requestParams?: RequestParameters
|
|
91
|
+
) => Promise<SignableTWAPOrderData>;
|
|
92
|
+
|
|
93
|
+
export type BuildTWAPDeltaOrderFunctions = {
|
|
94
|
+
/** @description Build TWAP Orders (sell or buy) to be posted to Delta API for execution */
|
|
95
|
+
buildTWAPDeltaOrder: BuildTWAPDeltaOrder;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const constructBuildTWAPDeltaOrder = (
|
|
99
|
+
options: ConstructFetchInput
|
|
100
|
+
): BuildTWAPDeltaOrderFunctions => {
|
|
101
|
+
const { chainId } = options;
|
|
102
|
+
|
|
103
|
+
const { getDeltaContract } = constructGetDeltaContract(options);
|
|
104
|
+
const { getPartnerFee } = constructGetPartnerFee(options);
|
|
105
|
+
|
|
106
|
+
const buildTWAPDeltaOrder: BuildTWAPDeltaOrder = async (
|
|
107
|
+
params,
|
|
108
|
+
requestParams
|
|
109
|
+
) => {
|
|
110
|
+
const ParaswapDelta = await getDeltaContract(requestParams);
|
|
111
|
+
if (!ParaswapDelta) {
|
|
112
|
+
throw new Error(`Delta is not available on chain ${chainId}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const { partnerAddress, partnerFeeBps, partnerTakesSurplus } =
|
|
116
|
+
await resolvePartnerFee(params, getPartnerFee, requestParams);
|
|
117
|
+
|
|
118
|
+
const commonInput: TWAPOrderCommonInput = {
|
|
119
|
+
owner: params.owner,
|
|
120
|
+
beneficiary: params.beneficiary,
|
|
121
|
+
srcToken: params.srcToken,
|
|
122
|
+
destToken: params.deltaPrice.destToken,
|
|
123
|
+
deadline: params.deadline,
|
|
124
|
+
nonce: params.nonce?.toString(10),
|
|
125
|
+
permit: params.permit,
|
|
126
|
+
metadata: params.metadata,
|
|
127
|
+
interval: params.interval,
|
|
128
|
+
numSlices: params.numSlices,
|
|
129
|
+
bridge: {
|
|
130
|
+
...params.deltaPrice.bridge,
|
|
131
|
+
// TWAP child orders get their bridge data at execution time
|
|
132
|
+
protocolData: DEFAULT_BRIDGE.protocolData,
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
chainId,
|
|
136
|
+
paraswapDeltaAddress: ParaswapDelta,
|
|
137
|
+
partnerAddress,
|
|
138
|
+
partnerTakesSurplus,
|
|
139
|
+
partnerFeeBps,
|
|
140
|
+
capSurplus: params.capSurplus,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
let input: BuildTWAPOrderDataInput;
|
|
144
|
+
|
|
145
|
+
if (params.onChainOrderType === 'TWAPOrder') {
|
|
146
|
+
const slippage = params.slippage ?? 0;
|
|
147
|
+
const destAmountPerSlice =
|
|
148
|
+
slippage > 0
|
|
149
|
+
? applySlippage({
|
|
150
|
+
amount: params.deltaPrice.destAmount,
|
|
151
|
+
slippageBps: slippage,
|
|
152
|
+
increase: false,
|
|
153
|
+
})
|
|
154
|
+
: params.deltaPrice.destAmount;
|
|
155
|
+
|
|
156
|
+
input = {
|
|
157
|
+
...commonInput,
|
|
158
|
+
onChainOrderType: 'TWAPOrder',
|
|
159
|
+
destAmountPerSlice,
|
|
160
|
+
totalSrcAmount: params.totalSrcAmount,
|
|
161
|
+
};
|
|
162
|
+
} else {
|
|
163
|
+
const slippage = params.slippage ?? 0;
|
|
164
|
+
const maxSrcAmount =
|
|
165
|
+
slippage > 0
|
|
166
|
+
? applySlippage({
|
|
167
|
+
amount: params.maxSrcAmount,
|
|
168
|
+
slippageBps: slippage,
|
|
169
|
+
increase: true,
|
|
170
|
+
})
|
|
171
|
+
: params.maxSrcAmount;
|
|
172
|
+
|
|
173
|
+
input = {
|
|
174
|
+
...commonInput,
|
|
175
|
+
onChainOrderType: 'TWAPBuyOrder',
|
|
176
|
+
totalDestAmount: params.totalDestAmount,
|
|
177
|
+
maxSrcAmount,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return buildTWAPSignableOrderData(input);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
buildTWAPDeltaOrder,
|
|
186
|
+
};
|
|
187
|
+
};
|
|
@@ -8,7 +8,11 @@ import { sanitizeDeltaOrderData } from './helpers/misc';
|
|
|
8
8
|
import { SignableDeltaOrderData } from './helpers/buildDeltaOrderData';
|
|
9
9
|
import { produceDeltaOrderHash } from './preSignDeltaOrder';
|
|
10
10
|
import type { ExtractAbiMethodNames } from '../../helpers/misc';
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
DeltaAuctionOrder,
|
|
13
|
+
TWAPDeltaOrder,
|
|
14
|
+
TWAPBuyDeltaOrder,
|
|
15
|
+
} from './helpers/types';
|
|
12
16
|
import { DEFAULT_BRIDGE } from './constants';
|
|
13
17
|
|
|
14
18
|
export type CancelAndWithdrawDeltaOrderParams = {
|
|
@@ -41,6 +45,18 @@ export type DepositNativeAndPreSign<T> = (
|
|
|
41
45
|
requestParams?: RequestParameters
|
|
42
46
|
) => Promise<T>;
|
|
43
47
|
|
|
48
|
+
export type CancelTWAPAndWithdrawDeltaOrder<T> = (
|
|
49
|
+
order: TWAPDeltaOrder,
|
|
50
|
+
overrides?: TxSendOverrides,
|
|
51
|
+
requestParams?: RequestParameters
|
|
52
|
+
) => Promise<T>;
|
|
53
|
+
|
|
54
|
+
export type CancelTWAPBuyAndWithdrawDeltaOrder<T> = (
|
|
55
|
+
order: TWAPBuyDeltaOrder,
|
|
56
|
+
overrides?: TxSendOverrides,
|
|
57
|
+
requestParams?: RequestParameters
|
|
58
|
+
) => Promise<T>;
|
|
59
|
+
|
|
44
60
|
export type DepositNativeAndPreSignDeltaOrderParams = Pick<
|
|
45
61
|
DepositNativeAndPreSignParams,
|
|
46
62
|
'depositAmount'
|
|
@@ -63,6 +79,10 @@ export type DeltaTokenModuleFunctions<T> = {
|
|
|
63
79
|
depositNativeAndPreSign: DepositNativeAndPreSign<T>;
|
|
64
80
|
/** @description Deposit native ETH and pre-sign a Delta order from signable order data */
|
|
65
81
|
depositNativeAndPreSignDeltaOrder: DepositNativeAndPreSignDeltaOrder<T>;
|
|
82
|
+
/** @description Cancel a TWAP sell order on-chain and withdraw native ETH back to the owner */
|
|
83
|
+
cancelTWAPAndWithdrawDeltaOrder: CancelTWAPAndWithdrawDeltaOrder<T>;
|
|
84
|
+
/** @description Cancel a TWAP buy order on-chain and withdraw native ETH back to the owner */
|
|
85
|
+
cancelTWAPBuyAndWithdrawDeltaOrder: CancelTWAPBuyAndWithdrawDeltaOrder<T>;
|
|
66
86
|
};
|
|
67
87
|
|
|
68
88
|
const DeltaTokenModuleAbi = [
|
|
@@ -217,6 +237,174 @@ const DeltaTokenModuleAbi = [
|
|
|
217
237
|
outputs: [],
|
|
218
238
|
stateMutability: 'nonpayable',
|
|
219
239
|
},
|
|
240
|
+
{
|
|
241
|
+
type: 'function',
|
|
242
|
+
name: 'cancelTWAPAndWithdraw',
|
|
243
|
+
inputs: [
|
|
244
|
+
{
|
|
245
|
+
name: 'order',
|
|
246
|
+
type: 'tuple',
|
|
247
|
+
internalType: 'struct TWAPOrder',
|
|
248
|
+
components: [
|
|
249
|
+
{ name: 'owner', type: 'address', internalType: 'address' },
|
|
250
|
+
{
|
|
251
|
+
name: 'beneficiary',
|
|
252
|
+
type: 'address',
|
|
253
|
+
internalType: 'address',
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: 'srcToken',
|
|
257
|
+
type: 'address',
|
|
258
|
+
internalType: 'address',
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: 'destToken',
|
|
262
|
+
type: 'address',
|
|
263
|
+
internalType: 'address',
|
|
264
|
+
},
|
|
265
|
+
{ name: 'nonce', type: 'uint256', internalType: 'uint256' },
|
|
266
|
+
{
|
|
267
|
+
name: 'partnerAndFee',
|
|
268
|
+
type: 'uint256',
|
|
269
|
+
internalType: 'uint256',
|
|
270
|
+
},
|
|
271
|
+
{ name: 'deadline', type: 'uint64', internalType: 'uint64' },
|
|
272
|
+
{ name: 'interval', type: 'uint64', internalType: 'uint64' },
|
|
273
|
+
{ name: 'numSlices', type: 'uint32', internalType: 'uint32' },
|
|
274
|
+
{
|
|
275
|
+
name: 'destAmountPerSlice',
|
|
276
|
+
type: 'uint256',
|
|
277
|
+
internalType: 'uint256',
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: 'totalSrcAmount',
|
|
281
|
+
type: 'uint256',
|
|
282
|
+
internalType: 'uint256',
|
|
283
|
+
},
|
|
284
|
+
{ name: 'permit', type: 'bytes', internalType: 'bytes' },
|
|
285
|
+
{ name: 'metadata', type: 'bytes', internalType: 'bytes' },
|
|
286
|
+
{
|
|
287
|
+
name: 'bridge',
|
|
288
|
+
type: 'tuple',
|
|
289
|
+
internalType: 'struct Bridge',
|
|
290
|
+
components: [
|
|
291
|
+
{
|
|
292
|
+
name: 'protocolSelector',
|
|
293
|
+
type: 'bytes4',
|
|
294
|
+
internalType: 'bytes4',
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: 'destinationChainId',
|
|
298
|
+
type: 'uint256',
|
|
299
|
+
internalType: 'uint256',
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: 'outputToken',
|
|
303
|
+
type: 'address',
|
|
304
|
+
internalType: 'address',
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: 'scalingFactor',
|
|
308
|
+
type: 'int8',
|
|
309
|
+
internalType: 'int8',
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
name: 'protocolData',
|
|
313
|
+
type: 'bytes',
|
|
314
|
+
internalType: 'bytes',
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
outputs: [],
|
|
322
|
+
stateMutability: 'nonpayable',
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
type: 'function',
|
|
326
|
+
name: 'cancelTWAPBuyAndWithdraw',
|
|
327
|
+
inputs: [
|
|
328
|
+
{
|
|
329
|
+
name: 'order',
|
|
330
|
+
type: 'tuple',
|
|
331
|
+
internalType: 'struct TWAPBuyOrder',
|
|
332
|
+
components: [
|
|
333
|
+
{ name: 'owner', type: 'address', internalType: 'address' },
|
|
334
|
+
{
|
|
335
|
+
name: 'beneficiary',
|
|
336
|
+
type: 'address',
|
|
337
|
+
internalType: 'address',
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: 'srcToken',
|
|
341
|
+
type: 'address',
|
|
342
|
+
internalType: 'address',
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
name: 'destToken',
|
|
346
|
+
type: 'address',
|
|
347
|
+
internalType: 'address',
|
|
348
|
+
},
|
|
349
|
+
{ name: 'nonce', type: 'uint256', internalType: 'uint256' },
|
|
350
|
+
{
|
|
351
|
+
name: 'partnerAndFee',
|
|
352
|
+
type: 'uint256',
|
|
353
|
+
internalType: 'uint256',
|
|
354
|
+
},
|
|
355
|
+
{ name: 'deadline', type: 'uint64', internalType: 'uint64' },
|
|
356
|
+
{ name: 'interval', type: 'uint64', internalType: 'uint64' },
|
|
357
|
+
{ name: 'numSlices', type: 'uint32', internalType: 'uint32' },
|
|
358
|
+
{
|
|
359
|
+
name: 'totalDestAmount',
|
|
360
|
+
type: 'uint256',
|
|
361
|
+
internalType: 'uint256',
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: 'maxSrcAmount',
|
|
365
|
+
type: 'uint256',
|
|
366
|
+
internalType: 'uint256',
|
|
367
|
+
},
|
|
368
|
+
{ name: 'permit', type: 'bytes', internalType: 'bytes' },
|
|
369
|
+
{ name: 'metadata', type: 'bytes', internalType: 'bytes' },
|
|
370
|
+
{
|
|
371
|
+
name: 'bridge',
|
|
372
|
+
type: 'tuple',
|
|
373
|
+
internalType: 'struct Bridge',
|
|
374
|
+
components: [
|
|
375
|
+
{
|
|
376
|
+
name: 'protocolSelector',
|
|
377
|
+
type: 'bytes4',
|
|
378
|
+
internalType: 'bytes4',
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: 'destinationChainId',
|
|
382
|
+
type: 'uint256',
|
|
383
|
+
internalType: 'uint256',
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
name: 'outputToken',
|
|
387
|
+
type: 'address',
|
|
388
|
+
internalType: 'address',
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
name: 'scalingFactor',
|
|
392
|
+
type: 'int8',
|
|
393
|
+
internalType: 'int8',
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
name: 'protocolData',
|
|
397
|
+
type: 'bytes',
|
|
398
|
+
internalType: 'bytes',
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
},
|
|
402
|
+
],
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
outputs: [],
|
|
406
|
+
stateMutability: 'nonpayable',
|
|
407
|
+
},
|
|
220
408
|
{
|
|
221
409
|
type: 'function',
|
|
222
410
|
name: 'withdrawNative',
|
|
@@ -358,10 +546,50 @@ export const constructDeltaTokenModule = <T>(
|
|
|
358
546
|
return res;
|
|
359
547
|
};
|
|
360
548
|
|
|
549
|
+
const cancelTWAPAndWithdrawDeltaOrder: CancelTWAPAndWithdrawDeltaOrder<
|
|
550
|
+
T
|
|
551
|
+
> = async (order, overrides = {}, requestParams) => {
|
|
552
|
+
const ParaswapDelta = await getDeltaContract(requestParams);
|
|
553
|
+
if (!ParaswapDelta) {
|
|
554
|
+
throw new Error(`Delta is not available on chain ${options.chainId}`);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const res = await options.contractCaller.transactCall<AvailableMethods>({
|
|
558
|
+
address: ParaswapDelta,
|
|
559
|
+
abi: DeltaTokenModuleAbi,
|
|
560
|
+
contractMethod: 'cancelTWAPAndWithdraw',
|
|
561
|
+
args: [order],
|
|
562
|
+
overrides,
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
return res;
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
const cancelTWAPBuyAndWithdrawDeltaOrder: CancelTWAPBuyAndWithdrawDeltaOrder<
|
|
569
|
+
T
|
|
570
|
+
> = async (order, overrides = {}, requestParams) => {
|
|
571
|
+
const ParaswapDelta = await getDeltaContract(requestParams);
|
|
572
|
+
if (!ParaswapDelta) {
|
|
573
|
+
throw new Error(`Delta is not available on chain ${options.chainId}`);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const res = await options.contractCaller.transactCall<AvailableMethods>({
|
|
577
|
+
address: ParaswapDelta,
|
|
578
|
+
abi: DeltaTokenModuleAbi,
|
|
579
|
+
contractMethod: 'cancelTWAPBuyAndWithdraw',
|
|
580
|
+
args: [order],
|
|
581
|
+
overrides,
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
return res;
|
|
585
|
+
};
|
|
586
|
+
|
|
361
587
|
return {
|
|
362
588
|
cancelAndWithdrawDeltaOrder,
|
|
363
589
|
withdrawDeltaNative,
|
|
364
590
|
depositNativeAndPreSign,
|
|
365
591
|
depositNativeAndPreSignDeltaOrder,
|
|
592
|
+
cancelTWAPAndWithdrawDeltaOrder,
|
|
593
|
+
cancelTWAPBuyAndWithdrawDeltaOrder,
|
|
366
594
|
};
|
|
367
595
|
};
|