@chainflip/sdk 1.6.0-alpha.1 → 1.6.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-AXKJJ3VI.mjs → chunk-EHDVKR7F.mjs} +250 -2
- package/dist/funding.mjs +1 -2
- package/dist/swap.d.mts +147 -7
- package/dist/swap.d.ts +147 -7
- package/dist/swap.js +6718 -6809
- package/dist/swap.mjs +4674 -79
- package/package.json +2 -2
- package/dist/broker-KNYBSXFY.mjs +0 -87
- package/dist/chunk-EBZERIHA.mjs +0 -251
- package/dist/chunk-NKAH7KWJ.mjs +0 -4510
|
@@ -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 };
|
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
|
@@ -2,6 +2,7 @@ import { Signer } from 'ethers';
|
|
|
2
2
|
import { A as AssetAndChain, C as Chain, a as Asset, I as InternalAsset, b as AssetOfChain, c as ChainflipNetwork, T as TransactionOptions, d as ChainAssetMap, e as ChainMap } from './contracts-DmShvHR7.mjs';
|
|
3
3
|
export { g as Assets, h as ChainflipIds, i as ChainflipNetworks, f as Chains, U as UncheckedAssetAndChain, j as getChainflipId } from './contracts-DmShvHR7.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>;
|
|
@@ -153,7 +154,7 @@ interface DepositAddressResponse extends DepositAddressRequest {
|
|
|
153
154
|
interface SwapStatusRequest {
|
|
154
155
|
id: string;
|
|
155
156
|
}
|
|
156
|
-
interface SwapStatusResponseCommonFields extends ChainsAndAssets {
|
|
157
|
+
interface SwapStatusResponseCommonFields$1 extends ChainsAndAssets {
|
|
157
158
|
destAddress: string;
|
|
158
159
|
ccmDepositReceivedBlockIndex: string | undefined;
|
|
159
160
|
ccmParams: CcmParams | undefined;
|
|
@@ -166,7 +167,7 @@ interface SwapStatusResponseCommonFields extends ChainsAndAssets {
|
|
|
166
167
|
depositTransactionHash: string | undefined;
|
|
167
168
|
ccmMetadata?: CcmParams;
|
|
168
169
|
}
|
|
169
|
-
interface DepositAddressFields extends SwapStatusResponseCommonFields {
|
|
170
|
+
interface DepositAddressFields extends SwapStatusResponseCommonFields$1 {
|
|
170
171
|
depositAddress: string;
|
|
171
172
|
depositChannelCreatedAt: number;
|
|
172
173
|
depositChannelBrokerCommissionBps: number;
|
|
@@ -204,7 +205,7 @@ type EgressScheduled = {
|
|
|
204
205
|
type CopyFields<T, U> = {
|
|
205
206
|
[K in Exclude<keyof T, keyof U>]: undefined;
|
|
206
207
|
} & U;
|
|
207
|
-
type VaultSwapFields = CopyFields<DepositAddressFields, SwapStatusResponseCommonFields>;
|
|
208
|
+
type VaultSwapFields = CopyFields<DepositAddressFields, SwapStatusResponseCommonFields$1>;
|
|
208
209
|
type FailedVaultSwapStatusResponse = CopyFields<DepositAddressFields, {
|
|
209
210
|
depositAmount: string;
|
|
210
211
|
destAddress: string;
|
|
@@ -221,7 +222,7 @@ type FailedVaultSwapStatusResponse = CopyFields<DepositAddressFields, {
|
|
|
221
222
|
state: 'FAILED';
|
|
222
223
|
depositAddress: undefined;
|
|
223
224
|
}>;
|
|
224
|
-
type SwapState = {
|
|
225
|
+
type SwapState$1 = {
|
|
225
226
|
state: 'AWAITING_DEPOSIT';
|
|
226
227
|
depositAmount: string | undefined;
|
|
227
228
|
depositTransactionConfirmations: number | undefined;
|
|
@@ -308,8 +309,8 @@ type SwapState = {
|
|
|
308
309
|
egressIgnoredAt: number;
|
|
309
310
|
egressIgnoredBlockIndex: string;
|
|
310
311
|
};
|
|
311
|
-
type DepositAddressStatusResponse = DepositAddressFields & SwapState;
|
|
312
|
-
type VaultSwapStatusResponse = VaultSwapFields & SwapState;
|
|
312
|
+
type DepositAddressStatusResponse = DepositAddressFields & SwapState$1;
|
|
313
|
+
type VaultSwapStatusResponse = VaultSwapFields & SwapState$1;
|
|
313
314
|
type SwapStatusResponse = DepositAddressStatusResponse | VaultSwapStatusResponse | FailedVaultSwapStatusResponse;
|
|
314
315
|
type BoostPoolDepth = {
|
|
315
316
|
feeTierBps: number;
|
|
@@ -318,6 +319,144 @@ type BoostPoolDepth = {
|
|
|
318
319
|
chain: Chain;
|
|
319
320
|
};
|
|
320
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
|
+
interface DcaParameters {
|
|
330
|
+
numberOfChunks: number;
|
|
331
|
+
chunkIntervalBlocks: string;
|
|
332
|
+
}
|
|
333
|
+
interface Ccm {
|
|
334
|
+
message: string;
|
|
335
|
+
gasBudget: string;
|
|
336
|
+
cfParameters: string | undefined;
|
|
337
|
+
ccmDepositReceivedBlockIndex: string | undefined;
|
|
338
|
+
}
|
|
339
|
+
interface Failure {
|
|
340
|
+
failedAt: number;
|
|
341
|
+
failedAtBlockIndex: string;
|
|
342
|
+
mode: FailureMode;
|
|
343
|
+
reason: {
|
|
344
|
+
code: string;
|
|
345
|
+
message: string;
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
interface Boost {
|
|
349
|
+
maxBoostFeeBps: number;
|
|
350
|
+
effectiveBoostFeeBps: number | undefined;
|
|
351
|
+
boostedAt: number | undefined;
|
|
352
|
+
boostedBlockIndex: string | undefined;
|
|
353
|
+
skippedAt: number | undefined;
|
|
354
|
+
skippedBlockIndex: string | undefined;
|
|
355
|
+
}
|
|
356
|
+
interface DepositChannelFields {
|
|
357
|
+
createdAt: number;
|
|
358
|
+
brokerCommissionBps: number;
|
|
359
|
+
depositAddress: string;
|
|
360
|
+
srcChainExpiryBlock: string;
|
|
361
|
+
estimatedExpiryTime: number;
|
|
362
|
+
expectedDepositAmount: string;
|
|
363
|
+
isExpired: boolean;
|
|
364
|
+
openedThroughBackend: boolean;
|
|
365
|
+
affiliateBrokers: AffiliateBroker[];
|
|
366
|
+
fillOrKillParams: FillOrKillParams | undefined;
|
|
367
|
+
dcaParams: DcaParameters | undefined;
|
|
368
|
+
srcChainRequiredBlockConfirmations: number | null | undefined;
|
|
369
|
+
}
|
|
370
|
+
interface DepositFields {
|
|
371
|
+
amount: string | undefined;
|
|
372
|
+
txRef: string | undefined;
|
|
373
|
+
txConfirmations: number | undefined;
|
|
374
|
+
receivedAt: number | undefined;
|
|
375
|
+
receivedBlockIndex: string | undefined;
|
|
376
|
+
failure: Failure | undefined;
|
|
377
|
+
}
|
|
378
|
+
interface SwapChunk {
|
|
379
|
+
swapInputAmount: string;
|
|
380
|
+
swapOutputAmount: string | undefined;
|
|
381
|
+
scheduledAt: number;
|
|
382
|
+
scheduledBlockIndex: string;
|
|
383
|
+
executedAt: number | undefined;
|
|
384
|
+
executedBlockIndex: string | undefined;
|
|
385
|
+
retryCount: number;
|
|
386
|
+
latestSwapRescheduledAt: number | undefined;
|
|
387
|
+
latestSwapRescheduledBlockIndex: number | undefined;
|
|
388
|
+
fees: SwapFee[];
|
|
389
|
+
}
|
|
390
|
+
interface SwapFields {
|
|
391
|
+
totalInputAmountSwapped: string | undefined;
|
|
392
|
+
totalOutputAmountSwapped: string | undefined;
|
|
393
|
+
totalChunksExecuted: number;
|
|
394
|
+
isDcaSwap: boolean;
|
|
395
|
+
lastExecutedChunk: SwapChunk | undefined;
|
|
396
|
+
currentChunk: SwapChunk;
|
|
397
|
+
type: SwapType;
|
|
398
|
+
fees: SwapFee[];
|
|
399
|
+
}
|
|
400
|
+
interface EgressFields {
|
|
401
|
+
amount: string;
|
|
402
|
+
scheduledAt: number;
|
|
403
|
+
scheduledBlockIndex: string;
|
|
404
|
+
sentTxRef: string | undefined;
|
|
405
|
+
sentAt: number | undefined;
|
|
406
|
+
sentAtBlockIndex: string | undefined;
|
|
407
|
+
ignoredAmount: string | undefined;
|
|
408
|
+
failure: Failure | undefined;
|
|
409
|
+
}
|
|
410
|
+
interface SwapStatusResponseCommonFields extends ChainsAndAssets {
|
|
411
|
+
swapId: string;
|
|
412
|
+
destAddress: string;
|
|
413
|
+
ccm: Ccm | undefined;
|
|
414
|
+
boost: Boost | undefined;
|
|
415
|
+
estimatedDurationSeconds: number | null | undefined;
|
|
416
|
+
}
|
|
417
|
+
interface VaultSwapCommonFields extends Exclude<SwapStatusResponseCommonFields, 'boost'> {
|
|
418
|
+
}
|
|
419
|
+
interface ReceivingVaultSwap extends VaultSwapCommonFields {
|
|
420
|
+
deposit: Pick<DepositFields, 'amount' | 'txRef'>;
|
|
421
|
+
}
|
|
422
|
+
interface SwappingVaultSwap extends ReceivingVaultSwap {
|
|
423
|
+
swap: Exclude<SwapChunk, 'latestSwapRescheduledAt' | 'latestSwapRescheduledBlockIndex'> | undefined;
|
|
424
|
+
swapEgress: EgressFields | undefined;
|
|
425
|
+
}
|
|
426
|
+
interface SendingVaultSwap extends SwappingVaultSwap {
|
|
427
|
+
swapEgress: EgressFields | undefined;
|
|
428
|
+
}
|
|
429
|
+
interface DepositChannel extends SwapStatusResponseCommonFields {
|
|
430
|
+
depositChannel: DepositChannelFields;
|
|
431
|
+
}
|
|
432
|
+
interface Receiving extends DepositChannel {
|
|
433
|
+
deposit: DepositFields;
|
|
434
|
+
}
|
|
435
|
+
interface Swapping extends Receiving {
|
|
436
|
+
swap: SwapFields;
|
|
437
|
+
}
|
|
438
|
+
interface Sending extends Receiving {
|
|
439
|
+
swap: SwapFields;
|
|
440
|
+
swapEgress: EgressFields | undefined;
|
|
441
|
+
refundEgress: EgressFields | undefined;
|
|
442
|
+
}
|
|
443
|
+
type SwapState = ({
|
|
444
|
+
state: 'RECEIVING';
|
|
445
|
+
} & Receiving) | ({
|
|
446
|
+
state: 'SWAPPING';
|
|
447
|
+
} & Swapping) | ({
|
|
448
|
+
state: 'SENDING';
|
|
449
|
+
} & Sending) | ({
|
|
450
|
+
state: 'SENT';
|
|
451
|
+
} & Sending) | ({
|
|
452
|
+
state: 'COMPLETED';
|
|
453
|
+
} & Sending) | ({
|
|
454
|
+
state: 'FAILED';
|
|
455
|
+
} & Sending);
|
|
456
|
+
type DepositAddressStatusResponseV2 = SwapState;
|
|
457
|
+
type VaultSwapStatusResponseV2 = SwapState & SendingVaultSwap;
|
|
458
|
+
type SwapStatusResponseV2 = DepositAddressStatusResponseV2 | VaultSwapStatusResponseV2;
|
|
459
|
+
|
|
321
460
|
type RequestOptions = {
|
|
322
461
|
signal?: AbortSignal;
|
|
323
462
|
};
|
|
@@ -348,6 +487,7 @@ declare class SwapSDK {
|
|
|
348
487
|
getQuote(quoteRequest: QuoteRequest, options?: RequestOptions): Promise<QuoteResponse>;
|
|
349
488
|
requestDepositAddress(depositAddressRequest: DepositAddressRequest): Promise<DepositAddressResponse>;
|
|
350
489
|
getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
|
|
490
|
+
getStatusV2(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponseV2>;
|
|
351
491
|
executeSwap(params: ExecuteSwapParams, txOpts?: TransactionOptions & {
|
|
352
492
|
signer?: Signer;
|
|
353
493
|
}): Promise<TransactionHash>;
|
|
@@ -370,4 +510,4 @@ declare class SwapSDK {
|
|
|
370
510
|
}): Promise<BoostPoolDepth[]>;
|
|
371
511
|
}
|
|
372
512
|
|
|
373
|
-
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 };
|
|
513
|
+
export { Asset, type AssetData, type BoostPoolDepth, Chain, type ChainData, InternalAsset as ChainflipId, ChainflipNetwork, type ChainsAndAssets, type DepositAddressRequest, type DepositAddressResponse, type DepositAddressStatusResponse, type DepositAddressStatusResponseV2, type FailedVaultSwapStatusResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, type SwapStatusResponseV2, type VaultSwapStatusResponse, type VaultSwapStatusResponseV2 };
|
package/dist/swap.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Signer } from 'ethers';
|
|
|
2
2
|
import { A as AssetAndChain, C as Chain, a as Asset, I as InternalAsset, b as AssetOfChain, c as ChainflipNetwork, T as TransactionOptions, d as ChainAssetMap, e as ChainMap } from './contracts-DmShvHR7.js';
|
|
3
3
|
export { g as Assets, h as ChainflipIds, i as ChainflipNetworks, f as Chains, U as UncheckedAssetAndChain, j as getChainflipId } from './contracts-DmShvHR7.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>;
|
|
@@ -153,7 +154,7 @@ interface DepositAddressResponse extends DepositAddressRequest {
|
|
|
153
154
|
interface SwapStatusRequest {
|
|
154
155
|
id: string;
|
|
155
156
|
}
|
|
156
|
-
interface SwapStatusResponseCommonFields extends ChainsAndAssets {
|
|
157
|
+
interface SwapStatusResponseCommonFields$1 extends ChainsAndAssets {
|
|
157
158
|
destAddress: string;
|
|
158
159
|
ccmDepositReceivedBlockIndex: string | undefined;
|
|
159
160
|
ccmParams: CcmParams | undefined;
|
|
@@ -166,7 +167,7 @@ interface SwapStatusResponseCommonFields extends ChainsAndAssets {
|
|
|
166
167
|
depositTransactionHash: string | undefined;
|
|
167
168
|
ccmMetadata?: CcmParams;
|
|
168
169
|
}
|
|
169
|
-
interface DepositAddressFields extends SwapStatusResponseCommonFields {
|
|
170
|
+
interface DepositAddressFields extends SwapStatusResponseCommonFields$1 {
|
|
170
171
|
depositAddress: string;
|
|
171
172
|
depositChannelCreatedAt: number;
|
|
172
173
|
depositChannelBrokerCommissionBps: number;
|
|
@@ -204,7 +205,7 @@ type EgressScheduled = {
|
|
|
204
205
|
type CopyFields<T, U> = {
|
|
205
206
|
[K in Exclude<keyof T, keyof U>]: undefined;
|
|
206
207
|
} & U;
|
|
207
|
-
type VaultSwapFields = CopyFields<DepositAddressFields, SwapStatusResponseCommonFields>;
|
|
208
|
+
type VaultSwapFields = CopyFields<DepositAddressFields, SwapStatusResponseCommonFields$1>;
|
|
208
209
|
type FailedVaultSwapStatusResponse = CopyFields<DepositAddressFields, {
|
|
209
210
|
depositAmount: string;
|
|
210
211
|
destAddress: string;
|
|
@@ -221,7 +222,7 @@ type FailedVaultSwapStatusResponse = CopyFields<DepositAddressFields, {
|
|
|
221
222
|
state: 'FAILED';
|
|
222
223
|
depositAddress: undefined;
|
|
223
224
|
}>;
|
|
224
|
-
type SwapState = {
|
|
225
|
+
type SwapState$1 = {
|
|
225
226
|
state: 'AWAITING_DEPOSIT';
|
|
226
227
|
depositAmount: string | undefined;
|
|
227
228
|
depositTransactionConfirmations: number | undefined;
|
|
@@ -308,8 +309,8 @@ type SwapState = {
|
|
|
308
309
|
egressIgnoredAt: number;
|
|
309
310
|
egressIgnoredBlockIndex: string;
|
|
310
311
|
};
|
|
311
|
-
type DepositAddressStatusResponse = DepositAddressFields & SwapState;
|
|
312
|
-
type VaultSwapStatusResponse = VaultSwapFields & SwapState;
|
|
312
|
+
type DepositAddressStatusResponse = DepositAddressFields & SwapState$1;
|
|
313
|
+
type VaultSwapStatusResponse = VaultSwapFields & SwapState$1;
|
|
313
314
|
type SwapStatusResponse = DepositAddressStatusResponse | VaultSwapStatusResponse | FailedVaultSwapStatusResponse;
|
|
314
315
|
type BoostPoolDepth = {
|
|
315
316
|
feeTierBps: number;
|
|
@@ -318,6 +319,144 @@ type BoostPoolDepth = {
|
|
|
318
319
|
chain: Chain;
|
|
319
320
|
};
|
|
320
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
|
+
interface DcaParameters {
|
|
330
|
+
numberOfChunks: number;
|
|
331
|
+
chunkIntervalBlocks: string;
|
|
332
|
+
}
|
|
333
|
+
interface Ccm {
|
|
334
|
+
message: string;
|
|
335
|
+
gasBudget: string;
|
|
336
|
+
cfParameters: string | undefined;
|
|
337
|
+
ccmDepositReceivedBlockIndex: string | undefined;
|
|
338
|
+
}
|
|
339
|
+
interface Failure {
|
|
340
|
+
failedAt: number;
|
|
341
|
+
failedAtBlockIndex: string;
|
|
342
|
+
mode: FailureMode;
|
|
343
|
+
reason: {
|
|
344
|
+
code: string;
|
|
345
|
+
message: string;
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
interface Boost {
|
|
349
|
+
maxBoostFeeBps: number;
|
|
350
|
+
effectiveBoostFeeBps: number | undefined;
|
|
351
|
+
boostedAt: number | undefined;
|
|
352
|
+
boostedBlockIndex: string | undefined;
|
|
353
|
+
skippedAt: number | undefined;
|
|
354
|
+
skippedBlockIndex: string | undefined;
|
|
355
|
+
}
|
|
356
|
+
interface DepositChannelFields {
|
|
357
|
+
createdAt: number;
|
|
358
|
+
brokerCommissionBps: number;
|
|
359
|
+
depositAddress: string;
|
|
360
|
+
srcChainExpiryBlock: string;
|
|
361
|
+
estimatedExpiryTime: number;
|
|
362
|
+
expectedDepositAmount: string;
|
|
363
|
+
isExpired: boolean;
|
|
364
|
+
openedThroughBackend: boolean;
|
|
365
|
+
affiliateBrokers: AffiliateBroker[];
|
|
366
|
+
fillOrKillParams: FillOrKillParams | undefined;
|
|
367
|
+
dcaParams: DcaParameters | undefined;
|
|
368
|
+
srcChainRequiredBlockConfirmations: number | null | undefined;
|
|
369
|
+
}
|
|
370
|
+
interface DepositFields {
|
|
371
|
+
amount: string | undefined;
|
|
372
|
+
txRef: string | undefined;
|
|
373
|
+
txConfirmations: number | undefined;
|
|
374
|
+
receivedAt: number | undefined;
|
|
375
|
+
receivedBlockIndex: string | undefined;
|
|
376
|
+
failure: Failure | undefined;
|
|
377
|
+
}
|
|
378
|
+
interface SwapChunk {
|
|
379
|
+
swapInputAmount: string;
|
|
380
|
+
swapOutputAmount: string | undefined;
|
|
381
|
+
scheduledAt: number;
|
|
382
|
+
scheduledBlockIndex: string;
|
|
383
|
+
executedAt: number | undefined;
|
|
384
|
+
executedBlockIndex: string | undefined;
|
|
385
|
+
retryCount: number;
|
|
386
|
+
latestSwapRescheduledAt: number | undefined;
|
|
387
|
+
latestSwapRescheduledBlockIndex: number | undefined;
|
|
388
|
+
fees: SwapFee[];
|
|
389
|
+
}
|
|
390
|
+
interface SwapFields {
|
|
391
|
+
totalInputAmountSwapped: string | undefined;
|
|
392
|
+
totalOutputAmountSwapped: string | undefined;
|
|
393
|
+
totalChunksExecuted: number;
|
|
394
|
+
isDcaSwap: boolean;
|
|
395
|
+
lastExecutedChunk: SwapChunk | undefined;
|
|
396
|
+
currentChunk: SwapChunk;
|
|
397
|
+
type: SwapType;
|
|
398
|
+
fees: SwapFee[];
|
|
399
|
+
}
|
|
400
|
+
interface EgressFields {
|
|
401
|
+
amount: string;
|
|
402
|
+
scheduledAt: number;
|
|
403
|
+
scheduledBlockIndex: string;
|
|
404
|
+
sentTxRef: string | undefined;
|
|
405
|
+
sentAt: number | undefined;
|
|
406
|
+
sentAtBlockIndex: string | undefined;
|
|
407
|
+
ignoredAmount: string | undefined;
|
|
408
|
+
failure: Failure | undefined;
|
|
409
|
+
}
|
|
410
|
+
interface SwapStatusResponseCommonFields extends ChainsAndAssets {
|
|
411
|
+
swapId: string;
|
|
412
|
+
destAddress: string;
|
|
413
|
+
ccm: Ccm | undefined;
|
|
414
|
+
boost: Boost | undefined;
|
|
415
|
+
estimatedDurationSeconds: number | null | undefined;
|
|
416
|
+
}
|
|
417
|
+
interface VaultSwapCommonFields extends Exclude<SwapStatusResponseCommonFields, 'boost'> {
|
|
418
|
+
}
|
|
419
|
+
interface ReceivingVaultSwap extends VaultSwapCommonFields {
|
|
420
|
+
deposit: Pick<DepositFields, 'amount' | 'txRef'>;
|
|
421
|
+
}
|
|
422
|
+
interface SwappingVaultSwap extends ReceivingVaultSwap {
|
|
423
|
+
swap: Exclude<SwapChunk, 'latestSwapRescheduledAt' | 'latestSwapRescheduledBlockIndex'> | undefined;
|
|
424
|
+
swapEgress: EgressFields | undefined;
|
|
425
|
+
}
|
|
426
|
+
interface SendingVaultSwap extends SwappingVaultSwap {
|
|
427
|
+
swapEgress: EgressFields | undefined;
|
|
428
|
+
}
|
|
429
|
+
interface DepositChannel extends SwapStatusResponseCommonFields {
|
|
430
|
+
depositChannel: DepositChannelFields;
|
|
431
|
+
}
|
|
432
|
+
interface Receiving extends DepositChannel {
|
|
433
|
+
deposit: DepositFields;
|
|
434
|
+
}
|
|
435
|
+
interface Swapping extends Receiving {
|
|
436
|
+
swap: SwapFields;
|
|
437
|
+
}
|
|
438
|
+
interface Sending extends Receiving {
|
|
439
|
+
swap: SwapFields;
|
|
440
|
+
swapEgress: EgressFields | undefined;
|
|
441
|
+
refundEgress: EgressFields | undefined;
|
|
442
|
+
}
|
|
443
|
+
type SwapState = ({
|
|
444
|
+
state: 'RECEIVING';
|
|
445
|
+
} & Receiving) | ({
|
|
446
|
+
state: 'SWAPPING';
|
|
447
|
+
} & Swapping) | ({
|
|
448
|
+
state: 'SENDING';
|
|
449
|
+
} & Sending) | ({
|
|
450
|
+
state: 'SENT';
|
|
451
|
+
} & Sending) | ({
|
|
452
|
+
state: 'COMPLETED';
|
|
453
|
+
} & Sending) | ({
|
|
454
|
+
state: 'FAILED';
|
|
455
|
+
} & Sending);
|
|
456
|
+
type DepositAddressStatusResponseV2 = SwapState;
|
|
457
|
+
type VaultSwapStatusResponseV2 = SwapState & SendingVaultSwap;
|
|
458
|
+
type SwapStatusResponseV2 = DepositAddressStatusResponseV2 | VaultSwapStatusResponseV2;
|
|
459
|
+
|
|
321
460
|
type RequestOptions = {
|
|
322
461
|
signal?: AbortSignal;
|
|
323
462
|
};
|
|
@@ -348,6 +487,7 @@ declare class SwapSDK {
|
|
|
348
487
|
getQuote(quoteRequest: QuoteRequest, options?: RequestOptions): Promise<QuoteResponse>;
|
|
349
488
|
requestDepositAddress(depositAddressRequest: DepositAddressRequest): Promise<DepositAddressResponse>;
|
|
350
489
|
getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
|
|
490
|
+
getStatusV2(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponseV2>;
|
|
351
491
|
executeSwap(params: ExecuteSwapParams, txOpts?: TransactionOptions & {
|
|
352
492
|
signer?: Signer;
|
|
353
493
|
}): Promise<TransactionHash>;
|
|
@@ -370,4 +510,4 @@ declare class SwapSDK {
|
|
|
370
510
|
}): Promise<BoostPoolDepth[]>;
|
|
371
511
|
}
|
|
372
512
|
|
|
373
|
-
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 };
|
|
513
|
+
export { Asset, type AssetData, type BoostPoolDepth, Chain, type ChainData, InternalAsset as ChainflipId, ChainflipNetwork, type ChainsAndAssets, type DepositAddressRequest, type DepositAddressResponse, type DepositAddressStatusResponse, type DepositAddressStatusResponseV2, type FailedVaultSwapStatusResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, type SwapStatusResponseV2, type VaultSwapStatusResponse, type VaultSwapStatusResponseV2 };
|