@chainflip/sdk 1.6.0-alpha.0 → 1.6.0-alpha.3
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/{chunk-AXKJJ3VI.mjs → chunk-EHDVKR7F.mjs} +250 -2
- package/dist/{contracts-DmShvHR7.d.mts → contracts-50KY1eSc.d.mts} +1 -1
- package/dist/{contracts-DmShvHR7.d.ts → contracts-50KY1eSc.d.ts} +1 -1
- package/dist/funding.d.mts +1 -1
- package/dist/funding.d.ts +1 -1
- package/dist/funding.mjs +1 -2
- package/dist/swap.d.mts +152 -3
- package/dist/swap.d.ts +152 -3
- package/dist/swap.js +6684 -8343
- package/dist/swap.mjs +4674 -79
- package/package.json +3 -3
- package/dist/broker-3IL43N6H.mjs +0 -80
- package/dist/chunk-EBZERIHA.mjs +0 -251
- package/dist/chunk-WBBIC5T3.mjs +0 -6013
|
@@ -1,7 +1,255 @@
|
|
|
1
|
-
import { getInternalAsset, __name, __publicField, ChainflipNetworks, Chains, InternalAssets } from './chunk-EBZERIHA.mjs';
|
|
2
1
|
import { constants, HttpClient } from '@chainflip/rpc';
|
|
3
2
|
import { Interface, Contract } from 'ethers';
|
|
4
3
|
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
|
|
9
|
+
// ../shared/src/enums.ts
|
|
10
|
+
var arrayToMap = /* @__PURE__ */ __name((array) => Object.fromEntries(array.map((key) => [
|
|
11
|
+
key,
|
|
12
|
+
key
|
|
13
|
+
])), "arrayToMap");
|
|
14
|
+
var InternalAssets = arrayToMap([
|
|
15
|
+
"Flip",
|
|
16
|
+
"Usdc",
|
|
17
|
+
"Dot",
|
|
18
|
+
"Eth",
|
|
19
|
+
"Btc",
|
|
20
|
+
"Usdt",
|
|
21
|
+
"ArbUsdc",
|
|
22
|
+
"ArbEth",
|
|
23
|
+
"Sol",
|
|
24
|
+
"SolUsdc"
|
|
25
|
+
]);
|
|
26
|
+
var Chains = arrayToMap([
|
|
27
|
+
"Bitcoin",
|
|
28
|
+
"Ethereum",
|
|
29
|
+
"Polkadot",
|
|
30
|
+
"Arbitrum",
|
|
31
|
+
"Solana"
|
|
32
|
+
]);
|
|
33
|
+
var Assets = arrayToMap([
|
|
34
|
+
"FLIP",
|
|
35
|
+
"USDC",
|
|
36
|
+
"DOT",
|
|
37
|
+
"ETH",
|
|
38
|
+
"BTC",
|
|
39
|
+
"USDT",
|
|
40
|
+
"SOL"
|
|
41
|
+
]);
|
|
42
|
+
var ChainflipNetworks = arrayToMap([
|
|
43
|
+
"backspin",
|
|
44
|
+
"sisyphos",
|
|
45
|
+
"perseverance",
|
|
46
|
+
"mainnet"
|
|
47
|
+
]);
|
|
48
|
+
var isTestnet = /* @__PURE__ */ __name((network) => network !== ChainflipNetworks.mainnet, "isTestnet");
|
|
49
|
+
var assetConstants = {
|
|
50
|
+
[InternalAssets.Eth]: {
|
|
51
|
+
chain: Chains.Ethereum,
|
|
52
|
+
asset: Assets.ETH,
|
|
53
|
+
name: "Ether",
|
|
54
|
+
decimals: 18,
|
|
55
|
+
contractId: 1
|
|
56
|
+
},
|
|
57
|
+
[InternalAssets.Flip]: {
|
|
58
|
+
chain: Chains.Ethereum,
|
|
59
|
+
asset: Assets.FLIP,
|
|
60
|
+
name: "FLIP",
|
|
61
|
+
decimals: 18,
|
|
62
|
+
contractId: 2
|
|
63
|
+
},
|
|
64
|
+
[InternalAssets.Usdc]: {
|
|
65
|
+
chain: Chains.Ethereum,
|
|
66
|
+
asset: Assets.USDC,
|
|
67
|
+
name: "USDC",
|
|
68
|
+
decimals: 6,
|
|
69
|
+
contractId: 3
|
|
70
|
+
},
|
|
71
|
+
[InternalAssets.Usdt]: {
|
|
72
|
+
chain: Chains.Ethereum,
|
|
73
|
+
asset: Assets.USDT,
|
|
74
|
+
name: "USDT",
|
|
75
|
+
decimals: 6,
|
|
76
|
+
contractId: 8
|
|
77
|
+
},
|
|
78
|
+
[InternalAssets.Dot]: {
|
|
79
|
+
chain: Chains.Polkadot,
|
|
80
|
+
asset: Assets.DOT,
|
|
81
|
+
name: "Polkadot",
|
|
82
|
+
decimals: 10,
|
|
83
|
+
contractId: 4
|
|
84
|
+
},
|
|
85
|
+
[InternalAssets.Btc]: {
|
|
86
|
+
chain: Chains.Bitcoin,
|
|
87
|
+
asset: Assets.BTC,
|
|
88
|
+
name: "Bitcoin",
|
|
89
|
+
decimals: 8,
|
|
90
|
+
contractId: 5
|
|
91
|
+
},
|
|
92
|
+
[InternalAssets.ArbEth]: {
|
|
93
|
+
chain: Chains.Arbitrum,
|
|
94
|
+
asset: Assets.ETH,
|
|
95
|
+
name: "Arbitrum Ether",
|
|
96
|
+
decimals: 18,
|
|
97
|
+
contractId: 6
|
|
98
|
+
},
|
|
99
|
+
[InternalAssets.ArbUsdc]: {
|
|
100
|
+
chain: Chains.Arbitrum,
|
|
101
|
+
asset: Assets.USDC,
|
|
102
|
+
name: "Arbitrum USDC",
|
|
103
|
+
decimals: 6,
|
|
104
|
+
contractId: 7
|
|
105
|
+
},
|
|
106
|
+
[InternalAssets.Sol]: {
|
|
107
|
+
chain: Chains.Solana,
|
|
108
|
+
asset: Assets.SOL,
|
|
109
|
+
name: "Solana",
|
|
110
|
+
decimals: 9,
|
|
111
|
+
contractId: 9
|
|
112
|
+
},
|
|
113
|
+
[InternalAssets.SolUsdc]: {
|
|
114
|
+
chain: Chains.Solana,
|
|
115
|
+
asset: Assets.USDC,
|
|
116
|
+
name: "Solana USDC",
|
|
117
|
+
decimals: 6,
|
|
118
|
+
contractId: 10
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var chainConstants = {
|
|
122
|
+
[Chains.Ethereum]: {
|
|
123
|
+
assets: [
|
|
124
|
+
Assets.ETH,
|
|
125
|
+
Assets.FLIP,
|
|
126
|
+
Assets.USDC,
|
|
127
|
+
Assets.USDT
|
|
128
|
+
],
|
|
129
|
+
gasAsset: Assets.ETH,
|
|
130
|
+
contractId: 1,
|
|
131
|
+
blockTimeSeconds: 12
|
|
132
|
+
},
|
|
133
|
+
[Chains.Polkadot]: {
|
|
134
|
+
assets: [
|
|
135
|
+
Assets.DOT
|
|
136
|
+
],
|
|
137
|
+
gasAsset: Assets.DOT,
|
|
138
|
+
contractId: 2,
|
|
139
|
+
blockTimeSeconds: 6
|
|
140
|
+
},
|
|
141
|
+
[Chains.Bitcoin]: {
|
|
142
|
+
assets: [
|
|
143
|
+
Assets.BTC
|
|
144
|
+
],
|
|
145
|
+
gasAsset: Assets.BTC,
|
|
146
|
+
contractId: 3,
|
|
147
|
+
blockTimeSeconds: 10 * 60
|
|
148
|
+
},
|
|
149
|
+
[Chains.Arbitrum]: {
|
|
150
|
+
assets: [
|
|
151
|
+
Assets.ETH,
|
|
152
|
+
Assets.USDC
|
|
153
|
+
],
|
|
154
|
+
gasAsset: Assets.ETH,
|
|
155
|
+
contractId: 4,
|
|
156
|
+
blockTimeSeconds: 0.26
|
|
157
|
+
},
|
|
158
|
+
[Chains.Solana]: {
|
|
159
|
+
assets: [
|
|
160
|
+
Assets.SOL,
|
|
161
|
+
Assets.USDC
|
|
162
|
+
],
|
|
163
|
+
gasAsset: Assets.SOL,
|
|
164
|
+
contractId: 5,
|
|
165
|
+
blockTimeSeconds: (400 + 800) / 2 / 1e3
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
function isValidAssetAndChain(assetAndChain) {
|
|
169
|
+
const { asset, chain } = assetAndChain;
|
|
170
|
+
if (!(chain in Chains)) return false;
|
|
171
|
+
const validAssets = chainConstants[chain].assets;
|
|
172
|
+
return validAssets.includes(asset);
|
|
173
|
+
}
|
|
174
|
+
__name(isValidAssetAndChain, "isValidAssetAndChain");
|
|
175
|
+
var readChainAssetValue = /* @__PURE__ */ __name((map, asset) => {
|
|
176
|
+
const { chain, asset: symbol } = assetConstants[asset];
|
|
177
|
+
const chainValues = map[chain];
|
|
178
|
+
return chainValues[symbol];
|
|
179
|
+
}, "readChainAssetValue");
|
|
180
|
+
function getInternalAsset(asset, assert2 = true) {
|
|
181
|
+
if (!isValidAssetAndChain(asset)) {
|
|
182
|
+
if (assert2) {
|
|
183
|
+
throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset)}`);
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const map = {
|
|
188
|
+
[Chains.Ethereum]: {
|
|
189
|
+
[Assets.USDC]: InternalAssets.Usdc,
|
|
190
|
+
[Assets.FLIP]: InternalAssets.Flip,
|
|
191
|
+
[Assets.ETH]: InternalAssets.Eth,
|
|
192
|
+
[Assets.USDT]: InternalAssets.Usdt
|
|
193
|
+
},
|
|
194
|
+
[Chains.Bitcoin]: {
|
|
195
|
+
[Assets.BTC]: InternalAssets.Btc
|
|
196
|
+
},
|
|
197
|
+
[Chains.Polkadot]: {
|
|
198
|
+
[Assets.DOT]: InternalAssets.Dot
|
|
199
|
+
},
|
|
200
|
+
[Chains.Arbitrum]: {
|
|
201
|
+
[Assets.USDC]: InternalAssets.ArbUsdc,
|
|
202
|
+
[Assets.ETH]: InternalAssets.ArbEth
|
|
203
|
+
},
|
|
204
|
+
[Chains.Solana]: {
|
|
205
|
+
[Assets.SOL]: InternalAssets.Sol,
|
|
206
|
+
[Assets.USDC]: InternalAssets.SolUsdc
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
const chain = map[asset.chain];
|
|
210
|
+
return chain[asset.asset];
|
|
211
|
+
}
|
|
212
|
+
__name(getInternalAsset, "getInternalAsset");
|
|
213
|
+
function getInternalAssets({ srcAsset, srcChain, destAsset, destChain }, assert2 = true) {
|
|
214
|
+
return {
|
|
215
|
+
srcAsset: getInternalAsset({
|
|
216
|
+
asset: srcAsset,
|
|
217
|
+
chain: srcChain
|
|
218
|
+
}, assert2),
|
|
219
|
+
destAsset: getInternalAsset({
|
|
220
|
+
asset: destAsset,
|
|
221
|
+
chain: destChain
|
|
222
|
+
}, assert2)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
__name(getInternalAssets, "getInternalAssets");
|
|
226
|
+
function getAssetAndChain(internalAsset, prefix) {
|
|
227
|
+
const { chain, asset } = assetConstants[internalAsset];
|
|
228
|
+
if (prefix) {
|
|
229
|
+
return {
|
|
230
|
+
[`${prefix}Asset`]: asset,
|
|
231
|
+
[`${prefix}Chain`]: chain
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
chain,
|
|
236
|
+
asset
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
__name(getAssetAndChain, "getAssetAndChain");
|
|
240
|
+
|
|
241
|
+
// ../shared/src/guards.ts
|
|
242
|
+
var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
|
|
243
|
+
var isNotNullish = /* @__PURE__ */ __name((value) => value !== null && value !== void 0, "isNotNullish");
|
|
244
|
+
function assert(condition, message) {
|
|
245
|
+
if (condition) return;
|
|
246
|
+
const error = new Error(message);
|
|
247
|
+
if (error.stack) {
|
|
248
|
+
error.stack = error.stack.replace(/\n.+/, "\n");
|
|
249
|
+
}
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
__name(assert, "assert");
|
|
5
253
|
var camelCase = /* @__PURE__ */ __name((str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase()), "camelCase");
|
|
6
254
|
var camelCaseKeys = /* @__PURE__ */ __name((obj) => {
|
|
7
255
|
if (typeof obj !== "object" || obj === null) return obj;
|
|
@@ -2127,4 +2375,4 @@ var getFlipBalance = /* @__PURE__ */ __name(async (network, signer) => {
|
|
|
2127
2375
|
return flip.balanceOf(await signer.getAddress());
|
|
2128
2376
|
}, "getFlipBalance");
|
|
2129
2377
|
|
|
2130
|
-
export { StateChainGateway__factory, Vault__factory, approve, checkAllowance, extractOverrides, getAllBoostPoolsDepth, getEnvironment, getEvmChainId, getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, getSupportedAssets, getTokenContractAddress, getVaultContractAddress };
|
|
2378
|
+
export { Assets, ChainflipNetworks, Chains, InternalAssets, StateChainGateway__factory, Vault__factory, __name, __publicField, approve, assert, assetConstants, chainConstants, checkAllowance, extractOverrides, getAllBoostPoolsDepth, getAssetAndChain, getEnvironment, getEvmChainId, getFlipBalance, getFundingEnvironment, getInternalAsset, getInternalAssets, getStateChainGatewayContractAddress, getSupportedAssets, getTokenContractAddress, getVaultContractAddress, isNotNullish, isString, isTestnet, isValidAssetAndChain, readChainAssetValue };
|
|
@@ -75,4 +75,4 @@ type TransactionOptions = {
|
|
|
75
75
|
wait?: number;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
export { type
|
|
78
|
+
export { type Asset as A, type Chain as C, type InternalAsset as I, type TransactionOptions as T, type UncheckedAssetAndChain as U, type AssetAndChain as a, type AssetOfChain as b, type ChainflipNetwork as c, type ChainAssetMap as d, type ChainMap as e, Chains as f, Assets as g, InternalAssets as h, ChainflipNetworks as i, getInternalAsset as j };
|
|
@@ -75,4 +75,4 @@ type TransactionOptions = {
|
|
|
75
75
|
wait?: number;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
export { type
|
|
78
|
+
export { type Asset as A, type Chain as C, type InternalAsset as I, type TransactionOptions as T, type UncheckedAssetAndChain as U, type AssetAndChain as a, type AssetOfChain as b, type ChainflipNetwork as c, type ChainAssetMap as d, type ChainMap as e, Chains as f, Assets as g, InternalAssets as h, ChainflipNetworks as i, getInternalAsset as j };
|
package/dist/funding.d.mts
CHANGED
package/dist/funding.d.ts
CHANGED
package/dist/funding.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, approve, getTokenContractAddress, checkAllowance, extractOverrides, StateChainGateway__factory } from './chunk-
|
|
2
|
-
import { __name, __publicField, ChainflipNetworks, InternalAssets, assert } from './chunk-EBZERIHA.mjs';
|
|
1
|
+
import { __name, __publicField, ChainflipNetworks, getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, approve, getTokenContractAddress, InternalAssets, checkAllowance, assert, extractOverrides, StateChainGateway__factory } from './chunk-EHDVKR7F.mjs';
|
|
3
2
|
|
|
4
3
|
// ../shared/src/stateChainGateway/utils.ts
|
|
5
4
|
var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
|
package/dist/swap.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
export { g as Assets, h as ChainflipIds, i as ChainflipNetworks, f as Chains, U as UncheckedAssetAndChain, j as getChainflipId } from './contracts-
|
|
2
|
+
import { C as Chain, A as Asset, a as AssetAndChain, I as InternalAsset, b as AssetOfChain, c as ChainflipNetwork, T as TransactionOptions, d as ChainAssetMap, e as ChainMap } from './contracts-50KY1eSc.mjs';
|
|
3
|
+
export { g as Assets, h as ChainflipIds, i as ChainflipNetworks, f as Chains, U as UncheckedAssetAndChain, j as getChainflipId } from './contracts-50KY1eSc.mjs';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
+
import { SwapType } from '.prisma/client';
|
|
5
6
|
|
|
6
7
|
declare const ccmParamsSchema: z.ZodObject<{
|
|
7
8
|
gasBudget: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, `0x${string}`, string>;
|
|
@@ -51,6 +52,10 @@ type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
|
|
|
51
52
|
type FillOrKillParams = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
|
|
52
53
|
minPrice: string;
|
|
53
54
|
};
|
|
55
|
+
type DcaParams = {
|
|
56
|
+
numberOfChunks: number;
|
|
57
|
+
chunkInterval: number;
|
|
58
|
+
};
|
|
54
59
|
type Fee<T> = {
|
|
55
60
|
type: T;
|
|
56
61
|
chain: Chain;
|
|
@@ -134,6 +139,7 @@ interface DepositAddressRequest extends QuoteRequest {
|
|
|
134
139
|
maxBoostFeeBps?: number;
|
|
135
140
|
srcAddress?: string;
|
|
136
141
|
fillOrKillParams?: FillOrKillParams;
|
|
142
|
+
dcaParams?: DcaParams;
|
|
137
143
|
ccmMetadata?: CcmParams;
|
|
138
144
|
}
|
|
139
145
|
interface DepositAddressResponse extends DepositAddressRequest {
|
|
@@ -313,6 +319,148 @@ type BoostPoolDepth = {
|
|
|
313
319
|
chain: Chain;
|
|
314
320
|
};
|
|
315
321
|
|
|
322
|
+
declare enum FailureMode {
|
|
323
|
+
IngressIgnored = "DEPOSIT_TOO_SMALL",
|
|
324
|
+
SwapEgressIgnored = "SWAP_OUTPUT_TOO_SMALL",
|
|
325
|
+
RefundEgressIgnored = "REFUND_OUTPUT_TOO_SMALL",
|
|
326
|
+
BroadcastAborted = "SENDING_FAILED"
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
declare namespace SwapV2 {
|
|
330
|
+
interface DcaParameters {
|
|
331
|
+
numberOfChunks: number;
|
|
332
|
+
chunkIntervalBlocks: string;
|
|
333
|
+
}
|
|
334
|
+
interface Ccm {
|
|
335
|
+
message: string;
|
|
336
|
+
gasBudget: string;
|
|
337
|
+
cfParameters: string | undefined;
|
|
338
|
+
ccmDepositReceivedBlockIndex: string | undefined;
|
|
339
|
+
}
|
|
340
|
+
interface Failure {
|
|
341
|
+
failedAt: number;
|
|
342
|
+
failedAtBlockIndex: string;
|
|
343
|
+
mode: FailureMode;
|
|
344
|
+
reason: {
|
|
345
|
+
code: string;
|
|
346
|
+
message: string;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
interface Boost {
|
|
350
|
+
maxBoostFeeBps: number;
|
|
351
|
+
effectiveBoostFeeBps: number | undefined;
|
|
352
|
+
boostedAt: number | undefined;
|
|
353
|
+
boostedBlockIndex: string | undefined;
|
|
354
|
+
skippedAt: number | undefined;
|
|
355
|
+
skippedBlockIndex: string | undefined;
|
|
356
|
+
}
|
|
357
|
+
interface DepositChannelFields {
|
|
358
|
+
createdAt: number;
|
|
359
|
+
brokerCommissionBps: number;
|
|
360
|
+
depositAddress: string;
|
|
361
|
+
srcChainExpiryBlock: string;
|
|
362
|
+
estimatedExpiryTime: number;
|
|
363
|
+
expectedDepositAmount: string;
|
|
364
|
+
isExpired: boolean;
|
|
365
|
+
openedThroughBackend: boolean;
|
|
366
|
+
affiliateBrokers: AffiliateBroker[];
|
|
367
|
+
fillOrKillParams: FillOrKillParams | undefined;
|
|
368
|
+
dcaParams: DcaParameters | undefined;
|
|
369
|
+
srcChainRequiredBlockConfirmations: number | null | undefined;
|
|
370
|
+
}
|
|
371
|
+
interface DepositFields {
|
|
372
|
+
amount: string | undefined;
|
|
373
|
+
txRef: string | undefined;
|
|
374
|
+
txConfirmations: number | undefined;
|
|
375
|
+
receivedAt: number | undefined;
|
|
376
|
+
receivedBlockIndex: string | undefined;
|
|
377
|
+
failure: Failure | undefined;
|
|
378
|
+
}
|
|
379
|
+
interface SwapChunk {
|
|
380
|
+
swapInputAmount: string;
|
|
381
|
+
swapOutputAmount: string | undefined;
|
|
382
|
+
scheduledAt: number;
|
|
383
|
+
scheduledBlockIndex: string;
|
|
384
|
+
executedAt: number | undefined;
|
|
385
|
+
executedBlockIndex: string | undefined;
|
|
386
|
+
retryCount: number;
|
|
387
|
+
latestSwapRescheduledAt: number | undefined;
|
|
388
|
+
latestSwapRescheduledBlockIndex: number | undefined;
|
|
389
|
+
fees: SwapFee[];
|
|
390
|
+
}
|
|
391
|
+
interface SwapFields {
|
|
392
|
+
totalInputAmountSwapped: string | undefined;
|
|
393
|
+
totalOutputAmountSwapped: string | undefined;
|
|
394
|
+
totalChunksExecuted: number;
|
|
395
|
+
isDcaSwap: boolean;
|
|
396
|
+
lastExecutedChunk: SwapChunk | undefined;
|
|
397
|
+
currentChunk: SwapChunk;
|
|
398
|
+
type: SwapType;
|
|
399
|
+
fees: SwapFee[];
|
|
400
|
+
}
|
|
401
|
+
interface EgressFields {
|
|
402
|
+
amount: string;
|
|
403
|
+
scheduledAt: number;
|
|
404
|
+
scheduledBlockIndex: string;
|
|
405
|
+
sentTxRef: string | undefined;
|
|
406
|
+
sentAt: number | undefined;
|
|
407
|
+
sentAtBlockIndex: string | undefined;
|
|
408
|
+
ignoredAmount: string | undefined;
|
|
409
|
+
failure: Failure | undefined;
|
|
410
|
+
}
|
|
411
|
+
interface SwapStatusResponseCommonFields extends ChainsAndAssets {
|
|
412
|
+
swapId: string;
|
|
413
|
+
destAddress: string;
|
|
414
|
+
depositChannel: DepositChannelFields;
|
|
415
|
+
ccm: Ccm | undefined;
|
|
416
|
+
boost: Boost | undefined;
|
|
417
|
+
estimatedDurationSeconds: number | null | undefined;
|
|
418
|
+
}
|
|
419
|
+
interface VaultSwapCommonFields extends Exclude<SwapStatusResponseCommonFields, 'depositChannel' | 'boost'> {
|
|
420
|
+
}
|
|
421
|
+
interface ReceivingVaultSwap extends VaultSwapCommonFields {
|
|
422
|
+
deposit: Pick<DepositFields, 'amount' | 'txRef'>;
|
|
423
|
+
}
|
|
424
|
+
interface SwappingVaultSwap extends ReceivingVaultSwap {
|
|
425
|
+
swap: Exclude<SwapChunk, 'latestSwapRescheduledAt' | 'latestSwapRescheduledBlockIndex'> | undefined;
|
|
426
|
+
swapEgress: EgressFields | undefined;
|
|
427
|
+
}
|
|
428
|
+
interface SendingVaultSwap extends SwappingVaultSwap {
|
|
429
|
+
swapEgress: EgressFields | undefined;
|
|
430
|
+
}
|
|
431
|
+
interface DepositChannel extends SwapStatusResponseCommonFields {
|
|
432
|
+
depositChannel: DepositChannelFields;
|
|
433
|
+
}
|
|
434
|
+
interface Receiving extends DepositChannel {
|
|
435
|
+
deposit: DepositFields;
|
|
436
|
+
}
|
|
437
|
+
interface Swapping extends Receiving {
|
|
438
|
+
swap: SwapFields;
|
|
439
|
+
}
|
|
440
|
+
interface Sending extends Receiving {
|
|
441
|
+
swap: SwapFields;
|
|
442
|
+
swapEgress: EgressFields | undefined;
|
|
443
|
+
refundEgress: EgressFields | undefined;
|
|
444
|
+
}
|
|
445
|
+
type SwapState = ({
|
|
446
|
+
state: 'RECEIVING';
|
|
447
|
+
} & Receiving) | ({
|
|
448
|
+
state: 'SWAPPING';
|
|
449
|
+
} & Swapping) | ({
|
|
450
|
+
state: 'SENDING';
|
|
451
|
+
} & Sending) | ({
|
|
452
|
+
state: 'SENT';
|
|
453
|
+
} & Sending) | ({
|
|
454
|
+
state: 'COMPLETED';
|
|
455
|
+
} & Sending) | ({
|
|
456
|
+
state: 'FAILED';
|
|
457
|
+
} & Sending);
|
|
458
|
+
export type DepositAddressStatusResponse = SwapState;
|
|
459
|
+
export type VaultSwapStatusResponse = SwapState & SendingVaultSwap;
|
|
460
|
+
export type SwapStatusResponse = DepositAddressStatusResponse | VaultSwapStatusResponse;
|
|
461
|
+
export { };
|
|
462
|
+
}
|
|
463
|
+
|
|
316
464
|
type RequestOptions = {
|
|
317
465
|
signal?: AbortSignal;
|
|
318
466
|
};
|
|
@@ -343,6 +491,7 @@ declare class SwapSDK {
|
|
|
343
491
|
getQuote(quoteRequest: QuoteRequest, options?: RequestOptions): Promise<QuoteResponse>;
|
|
344
492
|
requestDepositAddress(depositAddressRequest: DepositAddressRequest): Promise<DepositAddressResponse>;
|
|
345
493
|
getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
|
|
494
|
+
getStatusV2(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapV2.SwapStatusResponse>;
|
|
346
495
|
executeSwap(params: ExecuteSwapParams, txOpts?: TransactionOptions & {
|
|
347
496
|
signer?: Signer;
|
|
348
497
|
}): Promise<TransactionHash>;
|
|
@@ -365,4 +514,4 @@ declare class SwapSDK {
|
|
|
365
514
|
}): Promise<BoostPoolDepth[]>;
|
|
366
515
|
}
|
|
367
516
|
|
|
368
|
-
export { Asset, type AssetData, type BoostPoolDepth, Chain, type ChainData, InternalAsset as ChainflipId, ChainflipNetwork, type DepositAddressRequest, type DepositAddressResponse, type DepositAddressStatusResponse, type FailedVaultSwapStatusResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, type VaultSwapStatusResponse };
|
|
517
|
+
export { Asset, type AssetData, type BoostPoolDepth, Chain, type ChainData, InternalAsset as ChainflipId, ChainflipNetwork, type ChainsAndAssets, type DepositAddressRequest, type DepositAddressResponse, type DepositAddressStatusResponse, type FailedVaultSwapStatusResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, SwapV2, type VaultSwapStatusResponse };
|
package/dist/swap.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
export { g as Assets, h as ChainflipIds, i as ChainflipNetworks, f as Chains, U as UncheckedAssetAndChain, j as getChainflipId } from './contracts-
|
|
2
|
+
import { C as Chain, A as Asset, a as AssetAndChain, I as InternalAsset, b as AssetOfChain, c as ChainflipNetwork, T as TransactionOptions, d as ChainAssetMap, e as ChainMap } from './contracts-50KY1eSc.js';
|
|
3
|
+
export { g as Assets, h as ChainflipIds, i as ChainflipNetworks, f as Chains, U as UncheckedAssetAndChain, j as getChainflipId } from './contracts-50KY1eSc.js';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
+
import { SwapType } from '.prisma/client';
|
|
5
6
|
|
|
6
7
|
declare const ccmParamsSchema: z.ZodObject<{
|
|
7
8
|
gasBudget: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, `0x${string}`, string>;
|
|
@@ -51,6 +52,10 @@ type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
|
|
|
51
52
|
type FillOrKillParams = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
|
|
52
53
|
minPrice: string;
|
|
53
54
|
};
|
|
55
|
+
type DcaParams = {
|
|
56
|
+
numberOfChunks: number;
|
|
57
|
+
chunkInterval: number;
|
|
58
|
+
};
|
|
54
59
|
type Fee<T> = {
|
|
55
60
|
type: T;
|
|
56
61
|
chain: Chain;
|
|
@@ -134,6 +139,7 @@ interface DepositAddressRequest extends QuoteRequest {
|
|
|
134
139
|
maxBoostFeeBps?: number;
|
|
135
140
|
srcAddress?: string;
|
|
136
141
|
fillOrKillParams?: FillOrKillParams;
|
|
142
|
+
dcaParams?: DcaParams;
|
|
137
143
|
ccmMetadata?: CcmParams;
|
|
138
144
|
}
|
|
139
145
|
interface DepositAddressResponse extends DepositAddressRequest {
|
|
@@ -313,6 +319,148 @@ type BoostPoolDepth = {
|
|
|
313
319
|
chain: Chain;
|
|
314
320
|
};
|
|
315
321
|
|
|
322
|
+
declare enum FailureMode {
|
|
323
|
+
IngressIgnored = "DEPOSIT_TOO_SMALL",
|
|
324
|
+
SwapEgressIgnored = "SWAP_OUTPUT_TOO_SMALL",
|
|
325
|
+
RefundEgressIgnored = "REFUND_OUTPUT_TOO_SMALL",
|
|
326
|
+
BroadcastAborted = "SENDING_FAILED"
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
declare namespace SwapV2 {
|
|
330
|
+
interface DcaParameters {
|
|
331
|
+
numberOfChunks: number;
|
|
332
|
+
chunkIntervalBlocks: string;
|
|
333
|
+
}
|
|
334
|
+
interface Ccm {
|
|
335
|
+
message: string;
|
|
336
|
+
gasBudget: string;
|
|
337
|
+
cfParameters: string | undefined;
|
|
338
|
+
ccmDepositReceivedBlockIndex: string | undefined;
|
|
339
|
+
}
|
|
340
|
+
interface Failure {
|
|
341
|
+
failedAt: number;
|
|
342
|
+
failedAtBlockIndex: string;
|
|
343
|
+
mode: FailureMode;
|
|
344
|
+
reason: {
|
|
345
|
+
code: string;
|
|
346
|
+
message: string;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
interface Boost {
|
|
350
|
+
maxBoostFeeBps: number;
|
|
351
|
+
effectiveBoostFeeBps: number | undefined;
|
|
352
|
+
boostedAt: number | undefined;
|
|
353
|
+
boostedBlockIndex: string | undefined;
|
|
354
|
+
skippedAt: number | undefined;
|
|
355
|
+
skippedBlockIndex: string | undefined;
|
|
356
|
+
}
|
|
357
|
+
interface DepositChannelFields {
|
|
358
|
+
createdAt: number;
|
|
359
|
+
brokerCommissionBps: number;
|
|
360
|
+
depositAddress: string;
|
|
361
|
+
srcChainExpiryBlock: string;
|
|
362
|
+
estimatedExpiryTime: number;
|
|
363
|
+
expectedDepositAmount: string;
|
|
364
|
+
isExpired: boolean;
|
|
365
|
+
openedThroughBackend: boolean;
|
|
366
|
+
affiliateBrokers: AffiliateBroker[];
|
|
367
|
+
fillOrKillParams: FillOrKillParams | undefined;
|
|
368
|
+
dcaParams: DcaParameters | undefined;
|
|
369
|
+
srcChainRequiredBlockConfirmations: number | null | undefined;
|
|
370
|
+
}
|
|
371
|
+
interface DepositFields {
|
|
372
|
+
amount: string | undefined;
|
|
373
|
+
txRef: string | undefined;
|
|
374
|
+
txConfirmations: number | undefined;
|
|
375
|
+
receivedAt: number | undefined;
|
|
376
|
+
receivedBlockIndex: string | undefined;
|
|
377
|
+
failure: Failure | undefined;
|
|
378
|
+
}
|
|
379
|
+
interface SwapChunk {
|
|
380
|
+
swapInputAmount: string;
|
|
381
|
+
swapOutputAmount: string | undefined;
|
|
382
|
+
scheduledAt: number;
|
|
383
|
+
scheduledBlockIndex: string;
|
|
384
|
+
executedAt: number | undefined;
|
|
385
|
+
executedBlockIndex: string | undefined;
|
|
386
|
+
retryCount: number;
|
|
387
|
+
latestSwapRescheduledAt: number | undefined;
|
|
388
|
+
latestSwapRescheduledBlockIndex: number | undefined;
|
|
389
|
+
fees: SwapFee[];
|
|
390
|
+
}
|
|
391
|
+
interface SwapFields {
|
|
392
|
+
totalInputAmountSwapped: string | undefined;
|
|
393
|
+
totalOutputAmountSwapped: string | undefined;
|
|
394
|
+
totalChunksExecuted: number;
|
|
395
|
+
isDcaSwap: boolean;
|
|
396
|
+
lastExecutedChunk: SwapChunk | undefined;
|
|
397
|
+
currentChunk: SwapChunk;
|
|
398
|
+
type: SwapType;
|
|
399
|
+
fees: SwapFee[];
|
|
400
|
+
}
|
|
401
|
+
interface EgressFields {
|
|
402
|
+
amount: string;
|
|
403
|
+
scheduledAt: number;
|
|
404
|
+
scheduledBlockIndex: string;
|
|
405
|
+
sentTxRef: string | undefined;
|
|
406
|
+
sentAt: number | undefined;
|
|
407
|
+
sentAtBlockIndex: string | undefined;
|
|
408
|
+
ignoredAmount: string | undefined;
|
|
409
|
+
failure: Failure | undefined;
|
|
410
|
+
}
|
|
411
|
+
interface SwapStatusResponseCommonFields extends ChainsAndAssets {
|
|
412
|
+
swapId: string;
|
|
413
|
+
destAddress: string;
|
|
414
|
+
depositChannel: DepositChannelFields;
|
|
415
|
+
ccm: Ccm | undefined;
|
|
416
|
+
boost: Boost | undefined;
|
|
417
|
+
estimatedDurationSeconds: number | null | undefined;
|
|
418
|
+
}
|
|
419
|
+
interface VaultSwapCommonFields extends Exclude<SwapStatusResponseCommonFields, 'depositChannel' | 'boost'> {
|
|
420
|
+
}
|
|
421
|
+
interface ReceivingVaultSwap extends VaultSwapCommonFields {
|
|
422
|
+
deposit: Pick<DepositFields, 'amount' | 'txRef'>;
|
|
423
|
+
}
|
|
424
|
+
interface SwappingVaultSwap extends ReceivingVaultSwap {
|
|
425
|
+
swap: Exclude<SwapChunk, 'latestSwapRescheduledAt' | 'latestSwapRescheduledBlockIndex'> | undefined;
|
|
426
|
+
swapEgress: EgressFields | undefined;
|
|
427
|
+
}
|
|
428
|
+
interface SendingVaultSwap extends SwappingVaultSwap {
|
|
429
|
+
swapEgress: EgressFields | undefined;
|
|
430
|
+
}
|
|
431
|
+
interface DepositChannel extends SwapStatusResponseCommonFields {
|
|
432
|
+
depositChannel: DepositChannelFields;
|
|
433
|
+
}
|
|
434
|
+
interface Receiving extends DepositChannel {
|
|
435
|
+
deposit: DepositFields;
|
|
436
|
+
}
|
|
437
|
+
interface Swapping extends Receiving {
|
|
438
|
+
swap: SwapFields;
|
|
439
|
+
}
|
|
440
|
+
interface Sending extends Receiving {
|
|
441
|
+
swap: SwapFields;
|
|
442
|
+
swapEgress: EgressFields | undefined;
|
|
443
|
+
refundEgress: EgressFields | undefined;
|
|
444
|
+
}
|
|
445
|
+
type SwapState = ({
|
|
446
|
+
state: 'RECEIVING';
|
|
447
|
+
} & Receiving) | ({
|
|
448
|
+
state: 'SWAPPING';
|
|
449
|
+
} & Swapping) | ({
|
|
450
|
+
state: 'SENDING';
|
|
451
|
+
} & Sending) | ({
|
|
452
|
+
state: 'SENT';
|
|
453
|
+
} & Sending) | ({
|
|
454
|
+
state: 'COMPLETED';
|
|
455
|
+
} & Sending) | ({
|
|
456
|
+
state: 'FAILED';
|
|
457
|
+
} & Sending);
|
|
458
|
+
export type DepositAddressStatusResponse = SwapState;
|
|
459
|
+
export type VaultSwapStatusResponse = SwapState & SendingVaultSwap;
|
|
460
|
+
export type SwapStatusResponse = DepositAddressStatusResponse | VaultSwapStatusResponse;
|
|
461
|
+
export { };
|
|
462
|
+
}
|
|
463
|
+
|
|
316
464
|
type RequestOptions = {
|
|
317
465
|
signal?: AbortSignal;
|
|
318
466
|
};
|
|
@@ -343,6 +491,7 @@ declare class SwapSDK {
|
|
|
343
491
|
getQuote(quoteRequest: QuoteRequest, options?: RequestOptions): Promise<QuoteResponse>;
|
|
344
492
|
requestDepositAddress(depositAddressRequest: DepositAddressRequest): Promise<DepositAddressResponse>;
|
|
345
493
|
getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
|
|
494
|
+
getStatusV2(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapV2.SwapStatusResponse>;
|
|
346
495
|
executeSwap(params: ExecuteSwapParams, txOpts?: TransactionOptions & {
|
|
347
496
|
signer?: Signer;
|
|
348
497
|
}): Promise<TransactionHash>;
|
|
@@ -365,4 +514,4 @@ declare class SwapSDK {
|
|
|
365
514
|
}): Promise<BoostPoolDepth[]>;
|
|
366
515
|
}
|
|
367
516
|
|
|
368
|
-
export { Asset, type AssetData, type BoostPoolDepth, Chain, type ChainData, InternalAsset as ChainflipId, ChainflipNetwork, type DepositAddressRequest, type DepositAddressResponse, type DepositAddressStatusResponse, type FailedVaultSwapStatusResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, type VaultSwapStatusResponse };
|
|
517
|
+
export { Asset, type AssetData, type BoostPoolDepth, Chain, type ChainData, InternalAsset as ChainflipId, ChainflipNetwork, type ChainsAndAssets, type DepositAddressRequest, type DepositAddressResponse, type DepositAddressStatusResponse, type FailedVaultSwapStatusResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, SwapV2, type VaultSwapStatusResponse };
|