@chainflip/sdk 0.1.6 → 0.1.8
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/swap.d.ts +15 -13
- package/dist/swap.js +79 -123
- package/dist/swap.mjs +80 -124
- package/package.json +1 -1
package/dist/swap.d.ts
CHANGED
|
@@ -246,25 +246,25 @@ declare const executeCallParamsSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
246
246
|
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
247
247
|
destAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"USDC">]>;
|
|
248
248
|
message: z.ZodString;
|
|
249
|
-
|
|
249
|
+
gasBudget: z.ZodString;
|
|
250
250
|
}, "strip", z.ZodTypeAny, {
|
|
251
251
|
amount: string | bigint;
|
|
252
252
|
message: string;
|
|
253
|
-
gasAmount: string;
|
|
254
253
|
srcChain: "Ethereum";
|
|
255
254
|
srcAsset: "ETH";
|
|
256
255
|
destChain: "Ethereum";
|
|
257
256
|
destAddress: `0x${string}`;
|
|
258
257
|
destAsset: "FLIP" | "USDC";
|
|
258
|
+
gasBudget: string;
|
|
259
259
|
}, {
|
|
260
260
|
amount: string | bigint;
|
|
261
261
|
message: string;
|
|
262
|
-
gasAmount: string;
|
|
263
262
|
srcChain: "Ethereum";
|
|
264
263
|
srcAsset: "ETH";
|
|
265
264
|
destChain: "Ethereum";
|
|
266
265
|
destAddress: `0x${string}`;
|
|
267
266
|
destAsset: "FLIP" | "USDC";
|
|
267
|
+
gasBudget: string;
|
|
268
268
|
}>, z.ZodUnion<[z.ZodObject<{
|
|
269
269
|
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
270
270
|
srcChain: z.ZodLiteral<"Ethereum">;
|
|
@@ -273,25 +273,25 @@ declare const executeCallParamsSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
273
273
|
srcAsset: z.ZodLiteral<"FLIP">;
|
|
274
274
|
destAsset: z.ZodUnion<[z.ZodLiteral<"USDC">, z.ZodLiteral<"ETH">]>;
|
|
275
275
|
message: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
276
|
-
|
|
276
|
+
gasBudget: z.ZodString;
|
|
277
277
|
}, "strip", z.ZodTypeAny, {
|
|
278
278
|
amount: string | bigint;
|
|
279
279
|
message: `0x${string}`;
|
|
280
|
-
gasAmount: string;
|
|
281
280
|
srcChain: "Ethereum";
|
|
282
281
|
srcAsset: "FLIP";
|
|
283
282
|
destChain: "Ethereum";
|
|
284
283
|
destAddress: `0x${string}`;
|
|
285
284
|
destAsset: "USDC" | "ETH";
|
|
285
|
+
gasBudget: string;
|
|
286
286
|
}, {
|
|
287
287
|
amount: string | bigint;
|
|
288
288
|
message: `0x${string}`;
|
|
289
|
-
gasAmount: string;
|
|
290
289
|
srcChain: "Ethereum";
|
|
291
290
|
srcAsset: "FLIP";
|
|
292
291
|
destChain: "Ethereum";
|
|
293
292
|
destAddress: `0x${string}`;
|
|
294
293
|
destAsset: "USDC" | "ETH";
|
|
294
|
+
gasBudget: string;
|
|
295
295
|
}>, z.ZodObject<{
|
|
296
296
|
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
297
297
|
srcChain: z.ZodLiteral<"Ethereum">;
|
|
@@ -300,40 +300,37 @@ declare const executeCallParamsSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
300
300
|
srcAsset: z.ZodLiteral<"USDC">;
|
|
301
301
|
destAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"ETH">]>;
|
|
302
302
|
message: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
303
|
-
|
|
303
|
+
gasBudget: z.ZodString;
|
|
304
304
|
}, "strip", z.ZodTypeAny, {
|
|
305
305
|
amount: string | bigint;
|
|
306
306
|
message: `0x${string}`;
|
|
307
|
-
gasAmount: string;
|
|
308
307
|
srcChain: "Ethereum";
|
|
309
308
|
srcAsset: "USDC";
|
|
310
309
|
destChain: "Ethereum";
|
|
311
310
|
destAddress: `0x${string}`;
|
|
312
311
|
destAsset: "FLIP" | "ETH";
|
|
312
|
+
gasBudget: string;
|
|
313
313
|
}, {
|
|
314
314
|
amount: string | bigint;
|
|
315
315
|
message: `0x${string}`;
|
|
316
|
-
gasAmount: string;
|
|
317
316
|
srcChain: "Ethereum";
|
|
318
317
|
srcAsset: "USDC";
|
|
319
318
|
destChain: "Ethereum";
|
|
320
319
|
destAddress: `0x${string}`;
|
|
321
320
|
destAsset: "FLIP" | "ETH";
|
|
321
|
+
gasBudget: string;
|
|
322
322
|
}>]>]>;
|
|
323
323
|
type ExecuteCallParams = z.infer<typeof executeCallParamsSchema>;
|
|
324
324
|
|
|
325
325
|
declare const ccmMetadataSchema: z.ZodObject<{
|
|
326
326
|
gasBudget: z.ZodUnion<[z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodNumber]>;
|
|
327
327
|
message: z.ZodUnion<[z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodString]>;
|
|
328
|
-
cfParameters: z.ZodOptional<z.ZodUnion<[z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodString]>>;
|
|
329
328
|
}, "strip", z.ZodTypeAny, {
|
|
330
329
|
message: string;
|
|
331
330
|
gasBudget: number | `0x${string}`;
|
|
332
|
-
cfParameters?: string | undefined;
|
|
333
331
|
}, {
|
|
334
332
|
message: string;
|
|
335
333
|
gasBudget: number | `0x${string}`;
|
|
336
|
-
cfParameters?: string | undefined;
|
|
337
334
|
}>;
|
|
338
335
|
type CcmMetadata = z.infer<typeof ccmMetadataSchema>;
|
|
339
336
|
declare const quoteResponseSchema: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
|
|
@@ -383,7 +380,7 @@ type AssetData = {
|
|
|
383
380
|
[K in keyof typeof chainAssets]: {
|
|
384
381
|
id: (typeof chainAssets)[K][number];
|
|
385
382
|
chain: K;
|
|
386
|
-
contractAddress: string;
|
|
383
|
+
contractAddress: string | undefined;
|
|
387
384
|
decimals: number;
|
|
388
385
|
name: string;
|
|
389
386
|
symbol: string;
|
|
@@ -432,6 +429,7 @@ type SwapStatusResponse = CommonStatusFields & ({
|
|
|
432
429
|
depositAmount: string;
|
|
433
430
|
depositReceivedAt: number;
|
|
434
431
|
depositReceivedBlockIndex: string;
|
|
432
|
+
intermediateAmount: string | undefined;
|
|
435
433
|
swapExecutedAt: number;
|
|
436
434
|
swapExecutedBlockIndex: string;
|
|
437
435
|
} | {
|
|
@@ -440,6 +438,7 @@ type SwapStatusResponse = CommonStatusFields & ({
|
|
|
440
438
|
depositAmount: string;
|
|
441
439
|
depositReceivedAt: number;
|
|
442
440
|
depositReceivedBlockIndex: string;
|
|
441
|
+
intermediateAmount: string | undefined;
|
|
443
442
|
swapExecutedAt: number;
|
|
444
443
|
swapExecutedBlockIndex: string;
|
|
445
444
|
egressAmount: string;
|
|
@@ -451,6 +450,7 @@ type SwapStatusResponse = CommonStatusFields & ({
|
|
|
451
450
|
depositAmount: string;
|
|
452
451
|
depositReceivedAt: number;
|
|
453
452
|
depositReceivedBlockIndex: string;
|
|
453
|
+
intermediateAmount: string | undefined;
|
|
454
454
|
swapExecutedAt: number;
|
|
455
455
|
swapExecutedBlockIndex: string;
|
|
456
456
|
egressAmount: string;
|
|
@@ -464,6 +464,7 @@ type SwapStatusResponse = CommonStatusFields & ({
|
|
|
464
464
|
depositAmount: string;
|
|
465
465
|
depositReceivedAt: number;
|
|
466
466
|
depositReceivedBlockIndex: string;
|
|
467
|
+
intermediateAmount: string | undefined;
|
|
467
468
|
swapExecutedAt: number;
|
|
468
469
|
swapExecutedBlockIndex: string;
|
|
469
470
|
egressAmount: string;
|
|
@@ -479,6 +480,7 @@ type SwapStatusResponse = CommonStatusFields & ({
|
|
|
479
480
|
depositAmount: string;
|
|
480
481
|
depositReceivedAt: number;
|
|
481
482
|
depositReceivedBlockIndex: string;
|
|
483
|
+
intermediateAmount: string | undefined;
|
|
482
484
|
swapExecutedAt: number;
|
|
483
485
|
swapExecutedBlockIndex: string;
|
|
484
486
|
egressAmount: string;
|
package/dist/swap.js
CHANGED
|
@@ -1861,7 +1861,7 @@ var executeSwapParamsSchema = zod.z.union([
|
|
|
1861
1861
|
var nativeCallParamsSchema = ethereumBase.extend({
|
|
1862
1862
|
destAsset: erc20,
|
|
1863
1863
|
message: zod.z.string(),
|
|
1864
|
-
|
|
1864
|
+
gasBudget: numericString
|
|
1865
1865
|
});
|
|
1866
1866
|
var tokenCallParamsSchema = zod.z.union([
|
|
1867
1867
|
ethereumBase.extend({
|
|
@@ -1871,7 +1871,7 @@ var tokenCallParamsSchema = zod.z.union([
|
|
|
1871
1871
|
zod.z.literal(Assets.ETH)
|
|
1872
1872
|
]),
|
|
1873
1873
|
message: hexString,
|
|
1874
|
-
|
|
1874
|
+
gasBudget: numericString
|
|
1875
1875
|
}),
|
|
1876
1876
|
ethereumBase.extend({
|
|
1877
1877
|
srcAsset: zod.z.literal(Assets.USDC),
|
|
@@ -1880,7 +1880,7 @@ var tokenCallParamsSchema = zod.z.union([
|
|
|
1880
1880
|
zod.z.literal(Assets.ETH)
|
|
1881
1881
|
]),
|
|
1882
1882
|
message: hexString,
|
|
1883
|
-
|
|
1883
|
+
gasBudget: numericString
|
|
1884
1884
|
})
|
|
1885
1885
|
]);
|
|
1886
1886
|
var executeCallParamsSchema = zod.z.union([
|
|
@@ -1938,7 +1938,7 @@ var executeSwap_default = executeSwap;
|
|
|
1938
1938
|
var callNative = /* @__PURE__ */ __name(async (params, { nonce, ...opts }) => {
|
|
1939
1939
|
const vaultContractAddress = opts.network === "localnet" ? opts.vaultContractAddress : getVaultManagerContractAddress(opts.network);
|
|
1940
1940
|
const vault = Vault__factory.connect(vaultContractAddress, opts.signer);
|
|
1941
|
-
const transaction = await vault.xCallNative(chainContractIds[params.destChain], params.destAddress, assetContractIds[params.destAsset], params.message, params.
|
|
1941
|
+
const transaction = await vault.xCallNative(chainContractIds[params.destChain], params.destAddress, assetContractIds[params.destAsset], params.message, params.gasBudget, [], {
|
|
1942
1942
|
value: params.amount,
|
|
1943
1943
|
nonce
|
|
1944
1944
|
});
|
|
@@ -1951,7 +1951,7 @@ var callToken = /* @__PURE__ */ __name(async (params, { signer, ...opts }) => {
|
|
|
1951
1951
|
const { isAllowable } = await checkAllowance(params.amount, vaultContractAddress, erc20Address, signer);
|
|
1952
1952
|
assert(isAllowable, "Swap amount exceeds allowance");
|
|
1953
1953
|
const vault = Vault__factory.connect(vaultContractAddress, signer);
|
|
1954
|
-
const transaction = await vault.xCallToken(chainContractIds[params.destChain], params.destAddress, assetContractIds[params.destAsset], params.message, params.
|
|
1954
|
+
const transaction = await vault.xCallToken(chainContractIds[params.destChain], params.destAddress, assetContractIds[params.destAsset], params.message, params.gasBudget, erc20Address, params.amount, [], {
|
|
1955
1955
|
nonce: opts.nonce
|
|
1956
1956
|
});
|
|
1957
1957
|
return transaction.wait(1);
|
|
@@ -1985,154 +1985,110 @@ var BACKEND_SERVICE_URLS = {
|
|
|
1985
1985
|
[ChainflipNetworks.partnernet]: "https://chainflip-swap-partnernet.chainflip.io/"
|
|
1986
1986
|
};
|
|
1987
1987
|
|
|
1988
|
-
// src/swap/
|
|
1989
|
-
var
|
|
1990
|
-
id:
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
contractAddress: "0xusdc",
|
|
2018
|
-
decimals: assetDecimals[Assets.USDC],
|
|
2019
|
-
name: "usdc",
|
|
2020
|
-
symbol: "USDC",
|
|
2021
|
-
isMainnet: true
|
|
2022
|
-
},
|
|
2023
|
-
{
|
|
2024
|
-
id: Assets.FLIP,
|
|
2025
|
-
chain: Chains.Ethereum,
|
|
2026
|
-
contractAddress: "0xflip",
|
|
2027
|
-
decimals: assetDecimals[Assets.FLIP],
|
|
2028
|
-
name: "flip",
|
|
2029
|
-
symbol: "FLIP",
|
|
2030
|
-
isMainnet: true
|
|
2031
|
-
}
|
|
2032
|
-
];
|
|
2033
|
-
var dot$ = {
|
|
1988
|
+
// src/swap/assets.ts
|
|
1989
|
+
var eth$ = /* @__PURE__ */ __name((network) => ({
|
|
1990
|
+
id: Assets.ETH,
|
|
1991
|
+
chain: Chains.Ethereum,
|
|
1992
|
+
contractAddress: void 0,
|
|
1993
|
+
decimals: assetDecimals[Assets.ETH],
|
|
1994
|
+
name: "Ether",
|
|
1995
|
+
symbol: "ETH",
|
|
1996
|
+
isMainnet: !isTestnet(network)
|
|
1997
|
+
}), "eth$");
|
|
1998
|
+
var usdc$ = /* @__PURE__ */ __name((network) => ({
|
|
1999
|
+
id: Assets.USDC,
|
|
2000
|
+
chain: Chains.Ethereum,
|
|
2001
|
+
contractAddress: getTokenContractAddress(Assets.USDC, network),
|
|
2002
|
+
decimals: assetDecimals[Assets.USDC],
|
|
2003
|
+
name: "USDC",
|
|
2004
|
+
symbol: "USDC",
|
|
2005
|
+
isMainnet: !isTestnet(network)
|
|
2006
|
+
}), "usdc$");
|
|
2007
|
+
var flip$ = /* @__PURE__ */ __name((network) => ({
|
|
2008
|
+
id: Assets.FLIP,
|
|
2009
|
+
chain: Chains.Ethereum,
|
|
2010
|
+
contractAddress: getTokenContractAddress(Assets.FLIP, network),
|
|
2011
|
+
decimals: assetDecimals[Assets.FLIP],
|
|
2012
|
+
name: "FLIP",
|
|
2013
|
+
symbol: "FLIP",
|
|
2014
|
+
isMainnet: !isTestnet(network)
|
|
2015
|
+
}), "flip$");
|
|
2016
|
+
var dot$ = /* @__PURE__ */ __name((network) => ({
|
|
2034
2017
|
id: Assets.DOT,
|
|
2035
2018
|
chain: Chains.Polkadot,
|
|
2036
|
-
contractAddress:
|
|
2019
|
+
contractAddress: void 0,
|
|
2037
2020
|
decimals: assetDecimals[Assets.DOT],
|
|
2038
|
-
name: "
|
|
2021
|
+
name: "Polkadot",
|
|
2039
2022
|
symbol: "DOT",
|
|
2040
|
-
isMainnet:
|
|
2041
|
-
};
|
|
2042
|
-
var btc$ = {
|
|
2023
|
+
isMainnet: !isTestnet(network)
|
|
2024
|
+
}), "dot$");
|
|
2025
|
+
var btc$ = /* @__PURE__ */ __name((network) => ({
|
|
2043
2026
|
id: Assets.BTC,
|
|
2044
2027
|
chain: Chains.Bitcoin,
|
|
2045
|
-
contractAddress:
|
|
2028
|
+
contractAddress: void 0,
|
|
2046
2029
|
decimals: assetDecimals[Assets.BTC],
|
|
2047
|
-
name: "
|
|
2030
|
+
name: "Bitcoin",
|
|
2048
2031
|
symbol: "BTC",
|
|
2049
|
-
isMainnet:
|
|
2050
|
-
};
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2032
|
+
isMainnet: !isTestnet(network)
|
|
2033
|
+
}), "btc$");
|
|
2034
|
+
|
|
2035
|
+
// src/swap/chains.ts
|
|
2036
|
+
var ethereum = /* @__PURE__ */ __name((network) => ({
|
|
2037
|
+
id: Chains.Ethereum,
|
|
2038
|
+
name: "Ethereum",
|
|
2039
|
+
isMainnet: !isTestnet(network)
|
|
2040
|
+
}), "ethereum");
|
|
2041
|
+
var polkadot = /* @__PURE__ */ __name((network) => ({
|
|
2042
|
+
id: Chains.Polkadot,
|
|
2043
|
+
name: "Polkadot",
|
|
2044
|
+
isMainnet: !isTestnet(network)
|
|
2045
|
+
}), "polkadot");
|
|
2046
|
+
var bitcoin = /* @__PURE__ */ __name((network) => ({
|
|
2047
|
+
id: Chains.Bitcoin,
|
|
2048
|
+
name: "Bitcoin",
|
|
2049
|
+
isMainnet: !isTestnet(network)
|
|
2050
|
+
}), "bitcoin");
|
|
2059
2051
|
|
|
2060
2052
|
// src/swap/services/ApiService.ts
|
|
2061
|
-
var getChains = /* @__PURE__ */ __name(async (network) =>
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
bitcoin
|
|
2067
|
-
]);
|
|
2068
|
-
}
|
|
2069
|
-
return [
|
|
2070
|
-
ethereum,
|
|
2071
|
-
polkadot,
|
|
2072
|
-
bitcoin
|
|
2073
|
-
];
|
|
2074
|
-
}, "getChains");
|
|
2053
|
+
var getChains = /* @__PURE__ */ __name(async (network) => [
|
|
2054
|
+
ethereum(network),
|
|
2055
|
+
polkadot(network),
|
|
2056
|
+
bitcoin(network)
|
|
2057
|
+
], "getChains");
|
|
2075
2058
|
var getPossibleDestinationChains = /* @__PURE__ */ __name(async (sourceChain, network) => {
|
|
2076
|
-
if (isTestnet(network)) {
|
|
2077
|
-
if (sourceChain === Chains.Ethereum)
|
|
2078
|
-
return testnetChains([
|
|
2079
|
-
polkadot,
|
|
2080
|
-
bitcoin
|
|
2081
|
-
]);
|
|
2082
|
-
if (sourceChain === Chains.Polkadot)
|
|
2083
|
-
return testnetChains([
|
|
2084
|
-
ethereum,
|
|
2085
|
-
bitcoin
|
|
2086
|
-
]);
|
|
2087
|
-
if (sourceChain === Chains.Bitcoin)
|
|
2088
|
-
return testnetChains([
|
|
2089
|
-
ethereum,
|
|
2090
|
-
polkadot
|
|
2091
|
-
]);
|
|
2092
|
-
throw new Error("received testnet flag but mainnet chain");
|
|
2093
|
-
}
|
|
2094
2059
|
if (sourceChain === Chains.Ethereum)
|
|
2095
2060
|
return [
|
|
2096
|
-
bitcoin,
|
|
2097
|
-
polkadot
|
|
2061
|
+
bitcoin(network),
|
|
2062
|
+
polkadot(network)
|
|
2098
2063
|
];
|
|
2099
2064
|
if (sourceChain === Chains.Polkadot)
|
|
2100
2065
|
return [
|
|
2101
|
-
ethereum,
|
|
2102
|
-
bitcoin
|
|
2066
|
+
ethereum(network),
|
|
2067
|
+
bitcoin(network)
|
|
2103
2068
|
];
|
|
2104
2069
|
if (sourceChain === Chains.Bitcoin)
|
|
2105
2070
|
return [
|
|
2106
|
-
ethereum,
|
|
2107
|
-
polkadot
|
|
2071
|
+
ethereum(network),
|
|
2072
|
+
polkadot(network)
|
|
2108
2073
|
];
|
|
2109
2074
|
throw new Error("received unknown chain");
|
|
2110
2075
|
}, "getPossibleDestinationChains");
|
|
2111
2076
|
var getAssets = /* @__PURE__ */ __name(async (chain, network) => {
|
|
2112
|
-
if (isTestnet(network)) {
|
|
2113
|
-
if (chain === Chains.Ethereum)
|
|
2114
|
-
return testnetAssets(ethereumAssets);
|
|
2115
|
-
if (chain === Chains.Polkadot)
|
|
2116
|
-
return testnetAssets([
|
|
2117
|
-
dot$
|
|
2118
|
-
]);
|
|
2119
|
-
if (chain === Chains.Bitcoin)
|
|
2120
|
-
return testnetAssets([
|
|
2121
|
-
btc$
|
|
2122
|
-
]);
|
|
2123
|
-
throw new Error("received testnet flag but mainnet chain");
|
|
2124
|
-
}
|
|
2125
2077
|
if (chain === Chains.Ethereum)
|
|
2126
|
-
return
|
|
2078
|
+
return [
|
|
2079
|
+
eth$(network),
|
|
2080
|
+
usdc$(network),
|
|
2081
|
+
flip$(network)
|
|
2082
|
+
];
|
|
2127
2083
|
if (chain === Chains.Polkadot)
|
|
2128
2084
|
return [
|
|
2129
|
-
dot$
|
|
2085
|
+
dot$(network)
|
|
2130
2086
|
];
|
|
2131
2087
|
if (chain === Chains.Bitcoin)
|
|
2132
2088
|
return [
|
|
2133
|
-
btc$
|
|
2089
|
+
btc$(network)
|
|
2134
2090
|
];
|
|
2135
|
-
throw new Error("received
|
|
2091
|
+
throw new Error("received unexpected chain");
|
|
2136
2092
|
}, "getAssets");
|
|
2137
2093
|
var getQuote = /* @__PURE__ */ __name(async (baseUrl, quoteRequest, { signal }) => {
|
|
2138
2094
|
const params = {
|
package/dist/swap.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isString, Chains, Assets, ChainflipNetworks,
|
|
1
|
+
import { isString, Chains, Assets, ChainflipNetworks, __name, assert, getVaultManagerContractAddress, approve, isTokenSwap, isTokenCall, getTokenContractAddress, checkAllowance, Vault__factory, chainContractIds, assetContractIds, assetDecimals, isTestnet } from './chunk-CMPMNSTZ.mjs';
|
|
2
2
|
export { Assets, ChainflipNetworks, Chains, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds } from './chunk-CMPMNSTZ.mjs';
|
|
3
3
|
import { encodeAddress, decodeAddress } from '@polkadot/util-crypto';
|
|
4
4
|
import * as ethers from 'ethers';
|
|
@@ -394,7 +394,7 @@ var executeSwapParamsSchema = z.union([
|
|
|
394
394
|
var nativeCallParamsSchema = ethereumBase.extend({
|
|
395
395
|
destAsset: erc20,
|
|
396
396
|
message: z.string(),
|
|
397
|
-
|
|
397
|
+
gasBudget: numericString
|
|
398
398
|
});
|
|
399
399
|
var tokenCallParamsSchema = z.union([
|
|
400
400
|
ethereumBase.extend({
|
|
@@ -404,7 +404,7 @@ var tokenCallParamsSchema = z.union([
|
|
|
404
404
|
z.literal(Assets.ETH)
|
|
405
405
|
]),
|
|
406
406
|
message: hexString,
|
|
407
|
-
|
|
407
|
+
gasBudget: numericString
|
|
408
408
|
}),
|
|
409
409
|
ethereumBase.extend({
|
|
410
410
|
srcAsset: z.literal(Assets.USDC),
|
|
@@ -413,7 +413,7 @@ var tokenCallParamsSchema = z.union([
|
|
|
413
413
|
z.literal(Assets.ETH)
|
|
414
414
|
]),
|
|
415
415
|
message: hexString,
|
|
416
|
-
|
|
416
|
+
gasBudget: numericString
|
|
417
417
|
})
|
|
418
418
|
]);
|
|
419
419
|
var executeCallParamsSchema = z.union([
|
|
@@ -471,7 +471,7 @@ var executeSwap_default = executeSwap;
|
|
|
471
471
|
var callNative = /* @__PURE__ */ __name(async (params, { nonce, ...opts }) => {
|
|
472
472
|
const vaultContractAddress = opts.network === "localnet" ? opts.vaultContractAddress : getVaultManagerContractAddress(opts.network);
|
|
473
473
|
const vault = Vault__factory.connect(vaultContractAddress, opts.signer);
|
|
474
|
-
const transaction = await vault.xCallNative(chainContractIds[params.destChain], params.destAddress, assetContractIds[params.destAsset], params.message, params.
|
|
474
|
+
const transaction = await vault.xCallNative(chainContractIds[params.destChain], params.destAddress, assetContractIds[params.destAsset], params.message, params.gasBudget, [], {
|
|
475
475
|
value: params.amount,
|
|
476
476
|
nonce
|
|
477
477
|
});
|
|
@@ -484,7 +484,7 @@ var callToken = /* @__PURE__ */ __name(async (params, { signer, ...opts }) => {
|
|
|
484
484
|
const { isAllowable } = await checkAllowance(params.amount, vaultContractAddress, erc20Address, signer);
|
|
485
485
|
assert(isAllowable, "Swap amount exceeds allowance");
|
|
486
486
|
const vault = Vault__factory.connect(vaultContractAddress, signer);
|
|
487
|
-
const transaction = await vault.xCallToken(chainContractIds[params.destChain], params.destAddress, assetContractIds[params.destAsset], params.message, params.
|
|
487
|
+
const transaction = await vault.xCallToken(chainContractIds[params.destChain], params.destAddress, assetContractIds[params.destAsset], params.message, params.gasBudget, erc20Address, params.amount, [], {
|
|
488
488
|
nonce: opts.nonce
|
|
489
489
|
});
|
|
490
490
|
return transaction.wait(1);
|
|
@@ -518,154 +518,110 @@ var BACKEND_SERVICE_URLS = {
|
|
|
518
518
|
[ChainflipNetworks.partnernet]: "https://chainflip-swap-partnernet.chainflip.io/"
|
|
519
519
|
};
|
|
520
520
|
|
|
521
|
-
// src/swap/
|
|
522
|
-
var
|
|
523
|
-
id:
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
contractAddress: "0xusdc",
|
|
551
|
-
decimals: assetDecimals[Assets.USDC],
|
|
552
|
-
name: "usdc",
|
|
553
|
-
symbol: "USDC",
|
|
554
|
-
isMainnet: true
|
|
555
|
-
},
|
|
556
|
-
{
|
|
557
|
-
id: Assets.FLIP,
|
|
558
|
-
chain: Chains.Ethereum,
|
|
559
|
-
contractAddress: "0xflip",
|
|
560
|
-
decimals: assetDecimals[Assets.FLIP],
|
|
561
|
-
name: "flip",
|
|
562
|
-
symbol: "FLIP",
|
|
563
|
-
isMainnet: true
|
|
564
|
-
}
|
|
565
|
-
];
|
|
566
|
-
var dot$ = {
|
|
521
|
+
// src/swap/assets.ts
|
|
522
|
+
var eth$ = /* @__PURE__ */ __name((network) => ({
|
|
523
|
+
id: Assets.ETH,
|
|
524
|
+
chain: Chains.Ethereum,
|
|
525
|
+
contractAddress: void 0,
|
|
526
|
+
decimals: assetDecimals[Assets.ETH],
|
|
527
|
+
name: "Ether",
|
|
528
|
+
symbol: "ETH",
|
|
529
|
+
isMainnet: !isTestnet(network)
|
|
530
|
+
}), "eth$");
|
|
531
|
+
var usdc$ = /* @__PURE__ */ __name((network) => ({
|
|
532
|
+
id: Assets.USDC,
|
|
533
|
+
chain: Chains.Ethereum,
|
|
534
|
+
contractAddress: getTokenContractAddress(Assets.USDC, network),
|
|
535
|
+
decimals: assetDecimals[Assets.USDC],
|
|
536
|
+
name: "USDC",
|
|
537
|
+
symbol: "USDC",
|
|
538
|
+
isMainnet: !isTestnet(network)
|
|
539
|
+
}), "usdc$");
|
|
540
|
+
var flip$ = /* @__PURE__ */ __name((network) => ({
|
|
541
|
+
id: Assets.FLIP,
|
|
542
|
+
chain: Chains.Ethereum,
|
|
543
|
+
contractAddress: getTokenContractAddress(Assets.FLIP, network),
|
|
544
|
+
decimals: assetDecimals[Assets.FLIP],
|
|
545
|
+
name: "FLIP",
|
|
546
|
+
symbol: "FLIP",
|
|
547
|
+
isMainnet: !isTestnet(network)
|
|
548
|
+
}), "flip$");
|
|
549
|
+
var dot$ = /* @__PURE__ */ __name((network) => ({
|
|
567
550
|
id: Assets.DOT,
|
|
568
551
|
chain: Chains.Polkadot,
|
|
569
|
-
contractAddress:
|
|
552
|
+
contractAddress: void 0,
|
|
570
553
|
decimals: assetDecimals[Assets.DOT],
|
|
571
|
-
name: "
|
|
554
|
+
name: "Polkadot",
|
|
572
555
|
symbol: "DOT",
|
|
573
|
-
isMainnet:
|
|
574
|
-
};
|
|
575
|
-
var btc$ = {
|
|
556
|
+
isMainnet: !isTestnet(network)
|
|
557
|
+
}), "dot$");
|
|
558
|
+
var btc$ = /* @__PURE__ */ __name((network) => ({
|
|
576
559
|
id: Assets.BTC,
|
|
577
560
|
chain: Chains.Bitcoin,
|
|
578
|
-
contractAddress:
|
|
561
|
+
contractAddress: void 0,
|
|
579
562
|
decimals: assetDecimals[Assets.BTC],
|
|
580
|
-
name: "
|
|
563
|
+
name: "Bitcoin",
|
|
581
564
|
symbol: "BTC",
|
|
582
|
-
isMainnet:
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
565
|
+
isMainnet: !isTestnet(network)
|
|
566
|
+
}), "btc$");
|
|
567
|
+
|
|
568
|
+
// src/swap/chains.ts
|
|
569
|
+
var ethereum = /* @__PURE__ */ __name((network) => ({
|
|
570
|
+
id: Chains.Ethereum,
|
|
571
|
+
name: "Ethereum",
|
|
572
|
+
isMainnet: !isTestnet(network)
|
|
573
|
+
}), "ethereum");
|
|
574
|
+
var polkadot = /* @__PURE__ */ __name((network) => ({
|
|
575
|
+
id: Chains.Polkadot,
|
|
576
|
+
name: "Polkadot",
|
|
577
|
+
isMainnet: !isTestnet(network)
|
|
578
|
+
}), "polkadot");
|
|
579
|
+
var bitcoin = /* @__PURE__ */ __name((network) => ({
|
|
580
|
+
id: Chains.Bitcoin,
|
|
581
|
+
name: "Bitcoin",
|
|
582
|
+
isMainnet: !isTestnet(network)
|
|
583
|
+
}), "bitcoin");
|
|
592
584
|
|
|
593
585
|
// src/swap/services/ApiService.ts
|
|
594
|
-
var getChains = /* @__PURE__ */ __name(async (network) =>
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
bitcoin
|
|
600
|
-
]);
|
|
601
|
-
}
|
|
602
|
-
return [
|
|
603
|
-
ethereum,
|
|
604
|
-
polkadot,
|
|
605
|
-
bitcoin
|
|
606
|
-
];
|
|
607
|
-
}, "getChains");
|
|
586
|
+
var getChains = /* @__PURE__ */ __name(async (network) => [
|
|
587
|
+
ethereum(network),
|
|
588
|
+
polkadot(network),
|
|
589
|
+
bitcoin(network)
|
|
590
|
+
], "getChains");
|
|
608
591
|
var getPossibleDestinationChains = /* @__PURE__ */ __name(async (sourceChain, network) => {
|
|
609
|
-
if (isTestnet(network)) {
|
|
610
|
-
if (sourceChain === Chains.Ethereum)
|
|
611
|
-
return testnetChains([
|
|
612
|
-
polkadot,
|
|
613
|
-
bitcoin
|
|
614
|
-
]);
|
|
615
|
-
if (sourceChain === Chains.Polkadot)
|
|
616
|
-
return testnetChains([
|
|
617
|
-
ethereum,
|
|
618
|
-
bitcoin
|
|
619
|
-
]);
|
|
620
|
-
if (sourceChain === Chains.Bitcoin)
|
|
621
|
-
return testnetChains([
|
|
622
|
-
ethereum,
|
|
623
|
-
polkadot
|
|
624
|
-
]);
|
|
625
|
-
throw new Error("received testnet flag but mainnet chain");
|
|
626
|
-
}
|
|
627
592
|
if (sourceChain === Chains.Ethereum)
|
|
628
593
|
return [
|
|
629
|
-
bitcoin,
|
|
630
|
-
polkadot
|
|
594
|
+
bitcoin(network),
|
|
595
|
+
polkadot(network)
|
|
631
596
|
];
|
|
632
597
|
if (sourceChain === Chains.Polkadot)
|
|
633
598
|
return [
|
|
634
|
-
ethereum,
|
|
635
|
-
bitcoin
|
|
599
|
+
ethereum(network),
|
|
600
|
+
bitcoin(network)
|
|
636
601
|
];
|
|
637
602
|
if (sourceChain === Chains.Bitcoin)
|
|
638
603
|
return [
|
|
639
|
-
ethereum,
|
|
640
|
-
polkadot
|
|
604
|
+
ethereum(network),
|
|
605
|
+
polkadot(network)
|
|
641
606
|
];
|
|
642
607
|
throw new Error("received unknown chain");
|
|
643
608
|
}, "getPossibleDestinationChains");
|
|
644
609
|
var getAssets = /* @__PURE__ */ __name(async (chain, network) => {
|
|
645
|
-
if (isTestnet(network)) {
|
|
646
|
-
if (chain === Chains.Ethereum)
|
|
647
|
-
return testnetAssets(ethereumAssets);
|
|
648
|
-
if (chain === Chains.Polkadot)
|
|
649
|
-
return testnetAssets([
|
|
650
|
-
dot$
|
|
651
|
-
]);
|
|
652
|
-
if (chain === Chains.Bitcoin)
|
|
653
|
-
return testnetAssets([
|
|
654
|
-
btc$
|
|
655
|
-
]);
|
|
656
|
-
throw new Error("received testnet flag but mainnet chain");
|
|
657
|
-
}
|
|
658
610
|
if (chain === Chains.Ethereum)
|
|
659
|
-
return
|
|
611
|
+
return [
|
|
612
|
+
eth$(network),
|
|
613
|
+
usdc$(network),
|
|
614
|
+
flip$(network)
|
|
615
|
+
];
|
|
660
616
|
if (chain === Chains.Polkadot)
|
|
661
617
|
return [
|
|
662
|
-
dot$
|
|
618
|
+
dot$(network)
|
|
663
619
|
];
|
|
664
620
|
if (chain === Chains.Bitcoin)
|
|
665
621
|
return [
|
|
666
|
-
btc$
|
|
622
|
+
btc$(network)
|
|
667
623
|
];
|
|
668
|
-
throw new Error("received
|
|
624
|
+
throw new Error("received unexpected chain");
|
|
669
625
|
}, "getAssets");
|
|
670
626
|
var getQuote = /* @__PURE__ */ __name(async (baseUrl, quoteRequest, { signal }) => {
|
|
671
627
|
const params = {
|