@velora-dex/sdk 9.4.2 → 9.5.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.
- 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 +986 -133
- 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 +982 -134
- 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 +231 -3
- 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
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { Domain } from '../../common/orders/buildOrderData';
|
|
2
|
+
import {
|
|
3
|
+
Bridge,
|
|
4
|
+
TWAPDeltaOrder,
|
|
5
|
+
TWAPBuyDeltaOrder,
|
|
6
|
+
TWAPOnChainOrderType,
|
|
7
|
+
OnChainOrderMap,
|
|
8
|
+
} from './types';
|
|
9
|
+
import { DELTA_DEFAULT_EXPIRY, producePartnerAndFee } from './misc';
|
|
10
|
+
|
|
11
|
+
const BRIDGE_EIP_712_TYPE = [
|
|
12
|
+
{ name: 'protocolSelector', type: 'bytes4' },
|
|
13
|
+
{ name: 'destinationChainId', type: 'uint256' },
|
|
14
|
+
{ name: 'outputToken', type: 'address' },
|
|
15
|
+
{ name: 'scalingFactor', type: 'int8' },
|
|
16
|
+
{ name: 'protocolData', type: 'bytes' },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const TWAP_ORDER_EIP_712_TYPES = {
|
|
20
|
+
TWAPOrder: [
|
|
21
|
+
{ name: 'owner', type: 'address' },
|
|
22
|
+
{ name: 'beneficiary', type: 'address' },
|
|
23
|
+
{ name: 'srcToken', type: 'address' },
|
|
24
|
+
{ name: 'destToken', type: 'address' },
|
|
25
|
+
{ name: 'nonce', type: 'uint256' },
|
|
26
|
+
{ name: 'partnerAndFee', type: 'uint256' },
|
|
27
|
+
{ name: 'deadline', type: 'uint64' },
|
|
28
|
+
{ name: 'interval', type: 'uint64' },
|
|
29
|
+
{ name: 'numSlices', type: 'uint32' },
|
|
30
|
+
{ name: 'destAmountPerSlice', type: 'uint256' },
|
|
31
|
+
{ name: 'totalSrcAmount', type: 'uint256' },
|
|
32
|
+
{ name: 'permit', type: 'bytes' },
|
|
33
|
+
{ name: 'metadata', type: 'bytes' },
|
|
34
|
+
{ name: 'bridge', type: 'Bridge' },
|
|
35
|
+
],
|
|
36
|
+
Bridge: BRIDGE_EIP_712_TYPE,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const TWAP_BUY_ORDER_EIP_712_TYPES = {
|
|
40
|
+
TWAPBuyOrder: [
|
|
41
|
+
{ name: 'owner', type: 'address' },
|
|
42
|
+
{ name: 'beneficiary', type: 'address' },
|
|
43
|
+
{ name: 'srcToken', type: 'address' },
|
|
44
|
+
{ name: 'destToken', type: 'address' },
|
|
45
|
+
{ name: 'nonce', type: 'uint256' },
|
|
46
|
+
{ name: 'partnerAndFee', type: 'uint256' },
|
|
47
|
+
{ name: 'deadline', type: 'uint64' },
|
|
48
|
+
{ name: 'interval', type: 'uint64' },
|
|
49
|
+
{ name: 'numSlices', type: 'uint32' },
|
|
50
|
+
{ name: 'totalDestAmount', type: 'uint256' },
|
|
51
|
+
{ name: 'maxSrcAmount', type: 'uint256' },
|
|
52
|
+
{ name: 'permit', type: 'bytes' },
|
|
53
|
+
{ name: 'metadata', type: 'bytes' },
|
|
54
|
+
{ name: 'bridge', type: 'Bridge' },
|
|
55
|
+
],
|
|
56
|
+
Bridge: BRIDGE_EIP_712_TYPE,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type SignableTWAPSellOrderData = {
|
|
60
|
+
types: typeof TWAP_ORDER_EIP_712_TYPES;
|
|
61
|
+
domain: Domain;
|
|
62
|
+
data: TWAPDeltaOrder;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type SignableTWAPBuyOrderData = {
|
|
66
|
+
types: typeof TWAP_BUY_ORDER_EIP_712_TYPES;
|
|
67
|
+
domain: Domain;
|
|
68
|
+
data: TWAPBuyDeltaOrder;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type SignableTWAPOrderData =
|
|
72
|
+
| SignableTWAPSellOrderData
|
|
73
|
+
| SignableTWAPBuyOrderData;
|
|
74
|
+
|
|
75
|
+
type ProduceTWAPOrderTypedDataInput<T extends TWAPOnChainOrderType> = {
|
|
76
|
+
orderInput: OnChainOrderMap[T];
|
|
77
|
+
paraswapDeltaAddress: string;
|
|
78
|
+
chainId: number;
|
|
79
|
+
onChainOrderType: T;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function produceTWAPOrderTypedData(
|
|
83
|
+
params: ProduceTWAPOrderTypedDataInput<'TWAPOrder'>
|
|
84
|
+
): SignableTWAPSellOrderData;
|
|
85
|
+
export function produceTWAPOrderTypedData(
|
|
86
|
+
params: ProduceTWAPOrderTypedDataInput<'TWAPBuyOrder'>
|
|
87
|
+
): SignableTWAPBuyOrderData;
|
|
88
|
+
export function produceTWAPOrderTypedData({
|
|
89
|
+
orderInput,
|
|
90
|
+
chainId,
|
|
91
|
+
paraswapDeltaAddress,
|
|
92
|
+
onChainOrderType,
|
|
93
|
+
}: ProduceTWAPOrderTypedDataInput<TWAPOnChainOrderType>) {
|
|
94
|
+
const domain: Domain = {
|
|
95
|
+
name: 'Portikus',
|
|
96
|
+
version: '2.0.0',
|
|
97
|
+
chainId,
|
|
98
|
+
verifyingContract: paraswapDeltaAddress,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
if (onChainOrderType === 'TWAPOrder') {
|
|
102
|
+
return {
|
|
103
|
+
types: TWAP_ORDER_EIP_712_TYPES,
|
|
104
|
+
domain,
|
|
105
|
+
data: orderInput,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
types: TWAP_BUY_ORDER_EIP_712_TYPES,
|
|
111
|
+
domain,
|
|
112
|
+
data: orderInput,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type TWAPOrderCommonInput = {
|
|
117
|
+
owner: string;
|
|
118
|
+
beneficiary?: string;
|
|
119
|
+
srcToken: string;
|
|
120
|
+
destToken: string;
|
|
121
|
+
nonce?: string;
|
|
122
|
+
deadline?: number;
|
|
123
|
+
permit?: string;
|
|
124
|
+
metadata?: string;
|
|
125
|
+
interval: number;
|
|
126
|
+
numSlices: number;
|
|
127
|
+
bridge: Bridge;
|
|
128
|
+
|
|
129
|
+
partnerAddress: string;
|
|
130
|
+
paraswapDeltaAddress: string;
|
|
131
|
+
partnerFeeBps: number;
|
|
132
|
+
partnerTakesSurplus?: boolean;
|
|
133
|
+
capSurplus?: boolean;
|
|
134
|
+
chainId: number;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type BuildTWAPSellOrderDataInput = TWAPOrderCommonInput & {
|
|
138
|
+
onChainOrderType: 'TWAPOrder';
|
|
139
|
+
destAmountPerSlice: string;
|
|
140
|
+
totalSrcAmount: string;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export type BuildTWAPBuyOrderDataInput = TWAPOrderCommonInput & {
|
|
144
|
+
onChainOrderType: 'TWAPBuyOrder';
|
|
145
|
+
totalDestAmount: string;
|
|
146
|
+
maxSrcAmount: string;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export type BuildTWAPOrderDataInput =
|
|
150
|
+
| BuildTWAPSellOrderDataInput
|
|
151
|
+
| BuildTWAPBuyOrderDataInput;
|
|
152
|
+
|
|
153
|
+
export function buildTWAPSignableOrderData(
|
|
154
|
+
input: BuildTWAPOrderDataInput
|
|
155
|
+
): SignableTWAPOrderData {
|
|
156
|
+
const {
|
|
157
|
+
owner,
|
|
158
|
+
beneficiary = owner,
|
|
159
|
+
srcToken,
|
|
160
|
+
destToken,
|
|
161
|
+
nonce = Date.now().toString(10),
|
|
162
|
+
permit = '0x',
|
|
163
|
+
metadata = '0x',
|
|
164
|
+
interval,
|
|
165
|
+
numSlices,
|
|
166
|
+
bridge,
|
|
167
|
+
|
|
168
|
+
partnerAddress,
|
|
169
|
+
partnerFeeBps,
|
|
170
|
+
partnerTakesSurplus = false,
|
|
171
|
+
capSurplus = true,
|
|
172
|
+
chainId,
|
|
173
|
+
paraswapDeltaAddress,
|
|
174
|
+
onChainOrderType,
|
|
175
|
+
} = input;
|
|
176
|
+
|
|
177
|
+
const deadline =
|
|
178
|
+
input.deadline ??
|
|
179
|
+
// all slices must execute before the deadline,
|
|
180
|
+
// so we add the total duration of the TWAP (interval * numSlices) to the current time,
|
|
181
|
+
// plus a buffer defined by DELTA_DEFAULT_EXPIRY
|
|
182
|
+
Math.floor(Date.now() / 1000 + interval * numSlices + DELTA_DEFAULT_EXPIRY);
|
|
183
|
+
|
|
184
|
+
const partnerAndFee = producePartnerAndFee({
|
|
185
|
+
partnerFeeBps,
|
|
186
|
+
partnerAddress,
|
|
187
|
+
partnerTakesSurplus,
|
|
188
|
+
capSurplus,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const commonFields = {
|
|
192
|
+
owner,
|
|
193
|
+
beneficiary,
|
|
194
|
+
srcToken,
|
|
195
|
+
destToken,
|
|
196
|
+
nonce,
|
|
197
|
+
partnerAndFee,
|
|
198
|
+
deadline,
|
|
199
|
+
interval,
|
|
200
|
+
numSlices,
|
|
201
|
+
permit,
|
|
202
|
+
metadata,
|
|
203
|
+
bridge,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
if (onChainOrderType === 'TWAPOrder') {
|
|
207
|
+
const orderInput: TWAPDeltaOrder = {
|
|
208
|
+
...commonFields,
|
|
209
|
+
destAmountPerSlice: input.destAmountPerSlice,
|
|
210
|
+
totalSrcAmount: input.totalSrcAmount,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
return produceTWAPOrderTypedData({
|
|
214
|
+
orderInput,
|
|
215
|
+
chainId,
|
|
216
|
+
paraswapDeltaAddress,
|
|
217
|
+
onChainOrderType: 'TWAPOrder',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const orderInput: TWAPBuyDeltaOrder = {
|
|
222
|
+
...commonFields,
|
|
223
|
+
totalDestAmount: input.totalDestAmount,
|
|
224
|
+
maxSrcAmount: input.maxSrcAmount,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
return produceTWAPOrderTypedData({
|
|
228
|
+
orderInput,
|
|
229
|
+
chainId,
|
|
230
|
+
paraswapDeltaAddress,
|
|
231
|
+
onChainOrderType: 'TWAPBuyOrder',
|
|
232
|
+
});
|
|
233
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ZERO_ADDRESS } from '../../common/orders/buildOrderData';
|
|
2
2
|
import type { SignableDeltaOrderData } from './buildDeltaOrderData';
|
|
3
3
|
import type { SignableExternalOrderData } from './buildExternalOrderData';
|
|
4
|
+
import type { SignableTWAPOrderData } from './buildTWAPOrderData';
|
|
4
5
|
import type { GetPartnerFeeFunctions } from '../getPartnerFee';
|
|
5
6
|
import type { RequestParameters } from '../../../types';
|
|
6
|
-
import type {
|
|
7
|
+
import type { DeltaAmountsWithSlippage, SwapSideUnion } from './types';
|
|
7
8
|
import { SwapSide } from '../../../constants';
|
|
8
9
|
import { assert } from 'ts-essentials';
|
|
9
10
|
|
|
@@ -44,7 +45,7 @@ type ApplySlippageInput = {
|
|
|
44
45
|
increase: boolean;
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
function applySlippage({
|
|
48
|
+
export function applySlippage({
|
|
48
49
|
amount,
|
|
49
50
|
slippageBps,
|
|
50
51
|
increase,
|
|
@@ -122,7 +123,7 @@ export async function resolvePartnerFee(
|
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
export type ResolveAmountsInput =
|
|
126
|
+
export type ResolveAmountsInput = DeltaAmountsWithSlippage & {
|
|
126
127
|
deltaPrice: { destAmount: string; srcAmount: string };
|
|
127
128
|
};
|
|
128
129
|
|
|
@@ -244,3 +245,38 @@ export function sanitizeExternalOrderData({
|
|
|
244
245
|
data,
|
|
245
246
|
};
|
|
246
247
|
}
|
|
248
|
+
|
|
249
|
+
export function sanitizeTWAPOrderData(
|
|
250
|
+
orderData: SignableTWAPOrderData['data']
|
|
251
|
+
): SignableTWAPOrderData['data'] {
|
|
252
|
+
const common = {
|
|
253
|
+
owner: orderData.owner,
|
|
254
|
+
beneficiary: orderData.beneficiary,
|
|
255
|
+
srcToken: orderData.srcToken,
|
|
256
|
+
destToken: orderData.destToken,
|
|
257
|
+
nonce: orderData.nonce,
|
|
258
|
+
partnerAndFee: orderData.partnerAndFee,
|
|
259
|
+
deadline: orderData.deadline,
|
|
260
|
+
interval: orderData.interval,
|
|
261
|
+
numSlices: orderData.numSlices,
|
|
262
|
+
permit: orderData.permit,
|
|
263
|
+
metadata: orderData.metadata,
|
|
264
|
+
bridge: orderData.bridge,
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
if ('destAmountPerSlice' in orderData) {
|
|
268
|
+
// TWAPOrder (SELL)
|
|
269
|
+
return {
|
|
270
|
+
...common,
|
|
271
|
+
destAmountPerSlice: orderData.destAmountPerSlice,
|
|
272
|
+
totalSrcAmount: orderData.totalSrcAmount,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// TWAPBuyOrder (BUY)
|
|
277
|
+
return {
|
|
278
|
+
...common,
|
|
279
|
+
totalDestAmount: orderData.totalDestAmount,
|
|
280
|
+
maxSrcAmount: orderData.maxSrcAmount,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
@@ -4,7 +4,7 @@ import { SwapSide } from '../../../constants';
|
|
|
4
4
|
export type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
|
|
5
5
|
|
|
6
6
|
/** @description SELL with slippage: srcAmount provided, destAmount auto-computed from deltaPrice.destAmount */
|
|
7
|
-
export type
|
|
7
|
+
export type DeltaAmountsSellSlippage = {
|
|
8
8
|
/** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5% */
|
|
9
9
|
slippage: number;
|
|
10
10
|
/** @description The amount of src token to swap */
|
|
@@ -14,7 +14,7 @@ export type AmountsSellSlippage = {
|
|
|
14
14
|
side?: 'SELL';
|
|
15
15
|
};
|
|
16
16
|
/** @description BUY with slippage: destAmount provided, srcAmount auto-computed from deltaPrice.srcAmount */
|
|
17
|
-
export type
|
|
17
|
+
export type DeltaAmountsBuySlippage = {
|
|
18
18
|
/** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5% */
|
|
19
19
|
slippage: number;
|
|
20
20
|
/** @description The minimum amount of dest token to receive */
|
|
@@ -24,7 +24,7 @@ export type AmountsBuySlippage = {
|
|
|
24
24
|
side?: 'BUY';
|
|
25
25
|
};
|
|
26
26
|
/** @description Explicit amounts, no slippage (backward-compatible) */
|
|
27
|
-
export type
|
|
27
|
+
export type DeltaAmountsExplicit = {
|
|
28
28
|
slippage?: never;
|
|
29
29
|
/** @description The amount of src token to swap */
|
|
30
30
|
srcAmount: string;
|
|
@@ -34,10 +34,10 @@ export type AmountsExplicit = {
|
|
|
34
34
|
side?: SwapSideUnion;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export type
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
37
|
+
export type DeltaAmountsWithSlippage =
|
|
38
|
+
| DeltaAmountsSellSlippage
|
|
39
|
+
| DeltaAmountsBuySlippage
|
|
40
|
+
| DeltaAmountsExplicit;
|
|
41
41
|
|
|
42
42
|
enum OrderKind {
|
|
43
43
|
Sell = 0,
|
|
@@ -122,6 +122,48 @@ export type ExternalDeltaOrder = {
|
|
|
122
122
|
data: string;
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
+
type TWAPDeltaOrderBase = {
|
|
126
|
+
/** @description The address of the order owner */
|
|
127
|
+
owner: string;
|
|
128
|
+
/** @description The address of the order beneficiary */
|
|
129
|
+
beneficiary: string; // beneficiary==owner if no transferTo
|
|
130
|
+
/** @description The address of the src token */
|
|
131
|
+
srcToken: string; // lowercase
|
|
132
|
+
/** @description The address of the dest token */
|
|
133
|
+
destToken: string; // lowercase
|
|
134
|
+
/** @description The nonce of the order */
|
|
135
|
+
nonce: string; // can be random, can even be Date.now()
|
|
136
|
+
/** @description Encoded partner address, fee bps, and flags for the order. partnerAndFee = (partner << 96) | (partnerTakesSurplus << 8) | fee in bps (max fee is 2%) */
|
|
137
|
+
partnerAndFee: string;
|
|
138
|
+
/** @description The deadline for the order */
|
|
139
|
+
deadline: number; // seconds
|
|
140
|
+
/** @description The interval between each slice execution */
|
|
141
|
+
interval: number; // seconds
|
|
142
|
+
/** @description The number of slices to execute */
|
|
143
|
+
numSlices: number;
|
|
144
|
+
/** @description Optional permit signature for the src token */
|
|
145
|
+
permit: string; //can be "0x"
|
|
146
|
+
/** @description Metadata for the order, hex string */
|
|
147
|
+
metadata: string;
|
|
148
|
+
/** @description The bridge input */
|
|
149
|
+
bridge: Bridge;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export type TWAPDeltaOrder = TWAPDeltaOrderBase & {
|
|
153
|
+
/** @description The amount of dest token to receive per slice */
|
|
154
|
+
destAmountPerSlice: string; // wei
|
|
155
|
+
/** @description The total amount of src token to swap */
|
|
156
|
+
totalSrcAmount: string; // wei
|
|
157
|
+
/** @description Optional permit signature for the src token */
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type TWAPBuyDeltaOrder = TWAPDeltaOrderBase & {
|
|
161
|
+
/** @description The total amount of dest token to buy across all slices */
|
|
162
|
+
totalDestAmount: string; // wei
|
|
163
|
+
/** @description The maximum amount of src token willing to spend */
|
|
164
|
+
maxSrcAmount: string; // wei
|
|
165
|
+
};
|
|
166
|
+
|
|
125
167
|
export type DeltaAuctionStatus =
|
|
126
168
|
| 'NOT_STARTED'
|
|
127
169
|
| 'AWAITING_PRE_SIGNATURE'
|
|
@@ -135,7 +177,7 @@ export type DeltaAuctionStatus =
|
|
|
135
177
|
| 'SUSPENDED'
|
|
136
178
|
| 'REFUNDED';
|
|
137
179
|
|
|
138
|
-
type DeltaAuctionTransaction = {
|
|
180
|
+
export type DeltaAuctionTransaction = {
|
|
139
181
|
id: string;
|
|
140
182
|
hash: string;
|
|
141
183
|
orderId: string;
|
|
@@ -165,6 +207,8 @@ type DeltaAuctionTransaction = {
|
|
|
165
207
|
export type OnChainOrderMap = {
|
|
166
208
|
Order: DeltaAuctionOrder;
|
|
167
209
|
ExternalOrder: ExternalDeltaOrder;
|
|
210
|
+
TWAPOrder: TWAPDeltaOrder;
|
|
211
|
+
TWAPBuyOrder: TWAPBuyDeltaOrder;
|
|
168
212
|
};
|
|
169
213
|
|
|
170
214
|
type DeltaAuctionBase = {
|
|
@@ -215,7 +259,13 @@ export type BridgeMetadata = {
|
|
|
215
259
|
// refunded is basically failed
|
|
216
260
|
export type BridgeStatus = 'pending' | 'filled' | 'expired' | 'refunded';
|
|
217
261
|
|
|
218
|
-
export type OnChainOrderType =
|
|
262
|
+
export type OnChainOrderType =
|
|
263
|
+
| 'Order'
|
|
264
|
+
| 'ExternalOrder'
|
|
265
|
+
| 'TWAPOrder'
|
|
266
|
+
| 'TWAPBuyOrder';
|
|
267
|
+
|
|
268
|
+
export type TWAPOnChainOrderType = 'TWAPOrder' | 'TWAPBuyOrder';
|
|
219
269
|
|
|
220
270
|
//// available on BridgePrice ////
|
|
221
271
|
|
|
@@ -71,6 +71,23 @@ import {
|
|
|
71
71
|
constructPreSignExternalDeltaOrder,
|
|
72
72
|
PreSignExternalDeltaOrderFunctions,
|
|
73
73
|
} from './preSignExternalDeltaOrder';
|
|
74
|
+
import {
|
|
75
|
+
BuildTWAPDeltaOrderParams,
|
|
76
|
+
BuildTWAPDeltaOrderFunctions,
|
|
77
|
+
constructBuildTWAPDeltaOrder,
|
|
78
|
+
} from './buildTWAPDeltaOrder';
|
|
79
|
+
import {
|
|
80
|
+
constructSignTWAPDeltaOrder,
|
|
81
|
+
SignTWAPDeltaOrderFunctions,
|
|
82
|
+
} from './signTWAPDeltaOrder';
|
|
83
|
+
import {
|
|
84
|
+
constructPostTWAPDeltaOrder,
|
|
85
|
+
PostTWAPDeltaOrderFunctions,
|
|
86
|
+
} from './postTWAPDeltaOrder';
|
|
87
|
+
import {
|
|
88
|
+
constructPreSignTWAPDeltaOrder,
|
|
89
|
+
PreSignTWAPDeltaOrderFunctions,
|
|
90
|
+
} from './preSignTWAPDeltaOrder';
|
|
74
91
|
|
|
75
92
|
export type SubmitDeltaOrderParams = BuildDeltaOrderDataParams & {
|
|
76
93
|
/** @description designates the Order as being able to be partially filled, as opposed to fill-or-kill */
|
|
@@ -163,6 +180,52 @@ export const constructSubmitExternalDeltaOrder = (
|
|
|
163
180
|
return { submitExternalDeltaOrder };
|
|
164
181
|
};
|
|
165
182
|
|
|
183
|
+
export type SubmitTWAPDeltaOrderParams = BuildTWAPDeltaOrderParams & {
|
|
184
|
+
/** @description designates the Order as being able to be partially filled, as opposed to fill-or-kill */
|
|
185
|
+
partiallyFillable?: boolean;
|
|
186
|
+
/** @description Referrer address */
|
|
187
|
+
referrerAddress?: string;
|
|
188
|
+
degenMode?: boolean;
|
|
189
|
+
} & Pick<DeltaOrderToPost, 'type' | 'includeAgents' | 'excludeAgents'>;
|
|
190
|
+
|
|
191
|
+
type SubmitTWAPDeltaOrder = (
|
|
192
|
+
orderParams: SubmitTWAPDeltaOrderParams
|
|
193
|
+
) => Promise<DeltaAuction<'TWAPOrder'> | DeltaAuction<'TWAPBuyOrder'>>;
|
|
194
|
+
|
|
195
|
+
export type SubmitTWAPDeltaOrderFuncs = {
|
|
196
|
+
submitTWAPDeltaOrder: SubmitTWAPDeltaOrder;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export const constructSubmitTWAPDeltaOrder = (
|
|
200
|
+
options: ConstructProviderFetchInput<any, 'signTypedDataCall'>
|
|
201
|
+
): SubmitTWAPDeltaOrderFuncs => {
|
|
202
|
+
const { buildTWAPDeltaOrder } = constructBuildTWAPDeltaOrder(options);
|
|
203
|
+
const { signTWAPDeltaOrder } = constructSignTWAPDeltaOrder(options);
|
|
204
|
+
const { postTWAPDeltaOrder } = constructPostTWAPDeltaOrder(options);
|
|
205
|
+
|
|
206
|
+
const submitTWAPDeltaOrder: SubmitTWAPDeltaOrder = async (orderParams) => {
|
|
207
|
+
const orderData = await buildTWAPDeltaOrder(orderParams);
|
|
208
|
+
const signature = await signTWAPDeltaOrder(orderData);
|
|
209
|
+
|
|
210
|
+
const response = await postTWAPDeltaOrder({
|
|
211
|
+
signature,
|
|
212
|
+
partner: orderParams.partner,
|
|
213
|
+
order: orderData.data,
|
|
214
|
+
onChainOrderType: orderParams.onChainOrderType,
|
|
215
|
+
partiallyFillable: orderParams.partiallyFillable,
|
|
216
|
+
referrerAddress: orderParams.referrerAddress,
|
|
217
|
+
type: orderParams.type,
|
|
218
|
+
includeAgents: orderParams.includeAgents,
|
|
219
|
+
excludeAgents: orderParams.excludeAgents,
|
|
220
|
+
degenMode: orderParams.degenMode,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
return response;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
return { submitTWAPDeltaOrder };
|
|
227
|
+
};
|
|
228
|
+
|
|
166
229
|
export type DeltaOrderHandlers<T> = SubmitDeltaOrderFuncs &
|
|
167
230
|
ApproveTokenForDeltaFunctions<T> &
|
|
168
231
|
BuildDeltaOrderFunctions &
|
|
@@ -181,7 +244,12 @@ export type DeltaOrderHandlers<T> = SubmitDeltaOrderFuncs &
|
|
|
181
244
|
BuildExternalDeltaOrderFunctions &
|
|
182
245
|
SignExternalDeltaOrderFunctions &
|
|
183
246
|
PostExternalDeltaOrderFunctions &
|
|
184
|
-
PreSignExternalDeltaOrderFunctions<T
|
|
247
|
+
PreSignExternalDeltaOrderFunctions<T> &
|
|
248
|
+
SubmitTWAPDeltaOrderFuncs &
|
|
249
|
+
BuildTWAPDeltaOrderFunctions &
|
|
250
|
+
SignTWAPDeltaOrderFunctions &
|
|
251
|
+
PostTWAPDeltaOrderFunctions &
|
|
252
|
+
PreSignTWAPDeltaOrderFunctions<T>;
|
|
185
253
|
|
|
186
254
|
/** @description construct SDK with every Delta Order-related method, fetching from API and Order signing */
|
|
187
255
|
export const constructAllDeltaOrdersHandlers = <TxResponse>(
|
|
@@ -218,6 +286,12 @@ export const constructAllDeltaOrdersHandlers = <TxResponse>(
|
|
|
218
286
|
const externalDeltaOrdersPreSign =
|
|
219
287
|
constructPreSignExternalDeltaOrder(options);
|
|
220
288
|
|
|
289
|
+
const twapDeltaOrdersSubmit = constructSubmitTWAPDeltaOrder(options);
|
|
290
|
+
const twapDeltaOrdersBuild = constructBuildTWAPDeltaOrder(options);
|
|
291
|
+
const twapDeltaOrdersSign = constructSignTWAPDeltaOrder(options);
|
|
292
|
+
const twapDeltaOrdersPost = constructPostTWAPDeltaOrder(options);
|
|
293
|
+
const twapDeltaOrdersPreSign = constructPreSignTWAPDeltaOrder(options);
|
|
294
|
+
|
|
221
295
|
return {
|
|
222
296
|
...deltaOrdersGetters,
|
|
223
297
|
...deltaOrdersContractGetter,
|
|
@@ -238,5 +312,10 @@ export const constructAllDeltaOrdersHandlers = <TxResponse>(
|
|
|
238
312
|
...externalDeltaOrdersSign,
|
|
239
313
|
...externalDeltaOrdersPost,
|
|
240
314
|
...externalDeltaOrdersPreSign,
|
|
315
|
+
...twapDeltaOrdersSubmit,
|
|
316
|
+
...twapDeltaOrdersBuild,
|
|
317
|
+
...twapDeltaOrdersSign,
|
|
318
|
+
...twapDeltaOrdersPost,
|
|
319
|
+
...twapDeltaOrdersPreSign,
|
|
241
320
|
};
|
|
242
321
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Prettify } from 'ts-essentials';
|
|
2
|
+
import { API_URL } from '../../constants';
|
|
3
|
+
import type { ConstructFetchInput, RequestParameters } from '../../types';
|
|
4
|
+
import type { DeltaAuction, TWAPOnChainOrderType } from './helpers/types';
|
|
5
|
+
import type { DeltaOrderToPost } from './postDeltaOrder';
|
|
6
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
7
|
+
|
|
8
|
+
export type PostTWAPDeltaOrderParams = Prettify<
|
|
9
|
+
Omit<
|
|
10
|
+
DeltaOrderToPost<'TWAPOrder'> | DeltaOrderToPost<'TWAPBuyOrder'>,
|
|
11
|
+
'chainId'
|
|
12
|
+
> & {
|
|
13
|
+
/** @description Must be "TWAPOrder" or "TWAPBuyOrder" */
|
|
14
|
+
onChainOrderType: TWAPOnChainOrderType;
|
|
15
|
+
degenMode?: boolean;
|
|
16
|
+
}
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
type PostTWAPDeltaOrder = (
|
|
20
|
+
postData: PostTWAPDeltaOrderParams,
|
|
21
|
+
requestParams?: RequestParameters
|
|
22
|
+
) => Promise<DeltaAuction<'TWAPOrder'> | DeltaAuction<'TWAPBuyOrder'>>;
|
|
23
|
+
|
|
24
|
+
export type PostTWAPDeltaOrderFunctions = {
|
|
25
|
+
postTWAPDeltaOrder: PostTWAPDeltaOrder;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const constructPostTWAPDeltaOrder = ({
|
|
29
|
+
apiURL = API_URL,
|
|
30
|
+
chainId,
|
|
31
|
+
fetcher,
|
|
32
|
+
}: ConstructFetchInput): PostTWAPDeltaOrderFunctions => {
|
|
33
|
+
const postOrderUrl = `${apiURL}/delta/orders` as const;
|
|
34
|
+
|
|
35
|
+
const postTWAPDeltaOrder: PostTWAPDeltaOrder = (_postData, requestParams) => {
|
|
36
|
+
const { degenMode, ...postData } = _postData;
|
|
37
|
+
const deltaOrderToPost: DeltaOrderToPost<'TWAPOrder' | 'TWAPBuyOrder'> = {
|
|
38
|
+
...postData,
|
|
39
|
+
chainId,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const search = constructSearchString<{ degenMode?: boolean }>({
|
|
43
|
+
degenMode,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const fetchURL = `${postOrderUrl}/${search}` as const;
|
|
47
|
+
|
|
48
|
+
return fetcher<DeltaAuction<'TWAPOrder'> | DeltaAuction<'TWAPBuyOrder'>>({
|
|
49
|
+
url: fetchURL,
|
|
50
|
+
method: 'POST',
|
|
51
|
+
data: deltaOrderToPost,
|
|
52
|
+
requestParams,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return { postTWAPDeltaOrder };
|
|
57
|
+
};
|