@subwallet/extension-base 1.2.29-0 → 1.2.30-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/cjs/koni/background/handlers/Extension.js +3 -3
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +2 -2
- package/cjs/services/balance-service/helpers/subscribe/substrate/gear.js +6 -4
- package/cjs/services/swap-service/handler/chainflip-handler.js +12 -6
- package/cjs/services/swap-service/utils.js +29 -0
- package/koni/background/handlers/Extension.js +3 -3
- package/package.json +7 -7
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/index.js +2 -2
- package/services/balance-service/helpers/subscribe/substrate/gear.js +6 -4
- package/services/swap-service/handler/chainflip-handler.d.ts +3 -2
- package/services/swap-service/handler/chainflip-handler.js +11 -6
- package/services/swap-service/utils.d.ts +12 -0
- package/services/swap-service/utils.js +27 -0
|
@@ -2003,8 +2003,9 @@ class KoniExtension {
|
|
|
2003
2003
|
const substrateApi = this.#koniState.chainService.getSubstrateApi(originTokenInfo.originChain);
|
|
2004
2004
|
const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
|
|
2005
2005
|
const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, originTokenInfo.slug);
|
|
2006
|
+
const existentialDeposit = originTokenInfo.minAmount || '0';
|
|
2006
2007
|
if (destinationTokenInfo) {
|
|
2007
|
-
const [
|
|
2008
|
+
const [bnMockExecutionFee, {
|
|
2008
2009
|
value
|
|
2009
2010
|
}] = await Promise.all([(0, _xcm.getXcmMockTxFee)(substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo), this.getAddressTransferableBalance({
|
|
2010
2011
|
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
|
|
@@ -2013,8 +2014,7 @@ class KoniExtension {
|
|
|
2013
2014
|
token: originTokenInfo.slug
|
|
2014
2015
|
})]);
|
|
2015
2016
|
const bnMaxTransferable = new _bignumber.default(value);
|
|
2016
|
-
const estimatedFee =
|
|
2017
|
-
|
|
2017
|
+
const estimatedFee = bnMockExecutionFee.multipliedBy(_constants.XCM_FEE_RATIO).plus(new _bignumber.default(existentialDeposit));
|
|
2018
2018
|
return bnMaxTransferable.minus(estimatedFee);
|
|
2019
2019
|
}
|
|
2020
2020
|
return new _bignumber.default(0);
|
package/cjs/packageInfo.js
CHANGED
|
@@ -123,10 +123,10 @@ function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoM
|
|
|
123
123
|
evmApi
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
127
|
+
if (!substrateApi.isApiReady) {
|
|
127
128
|
handleUnsupportedOrPendingAddresses(useAddresses, chainSlug, chainAssetMap, _KoniTypes.APIItemState.PENDING, callback);
|
|
128
129
|
}
|
|
129
|
-
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
130
130
|
return (0, _substrate.subscribeSubstrateBalance)(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
|
|
131
131
|
});
|
|
132
132
|
return () => {
|
|
@@ -23,7 +23,8 @@ const subscribeGRC20Balance = _ref => {
|
|
|
23
23
|
chainInfo,
|
|
24
24
|
substrateApi
|
|
25
25
|
} = _ref;
|
|
26
|
-
|
|
26
|
+
const apiPromise = substrateApi.api;
|
|
27
|
+
if (!(apiPromise instanceof _api.GearApi)) {
|
|
27
28
|
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
28
29
|
return _util.noop;
|
|
29
30
|
}
|
|
@@ -32,7 +33,7 @@ const subscribeGRC20Balance = _ref => {
|
|
|
32
33
|
const tokenList = (0, _utils2.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.GRC20]);
|
|
33
34
|
Object.entries(tokenList).forEach(_ref2 => {
|
|
34
35
|
let [slug, tokenInfo] = _ref2;
|
|
35
|
-
grc20ContractMap[slug] = (0, _utils2.getGRC20ContractPromise)(
|
|
36
|
+
grc20ContractMap[slug] = (0, _utils2.getGRC20ContractPromise)(apiPromise, (0, _utils._getContractAddressOfToken)(tokenInfo));
|
|
36
37
|
});
|
|
37
38
|
const getTokenBalances = () => {
|
|
38
39
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -82,7 +83,8 @@ const subscribeVftBalance = _ref3 => {
|
|
|
82
83
|
chainInfo,
|
|
83
84
|
substrateApi
|
|
84
85
|
} = _ref3;
|
|
85
|
-
|
|
86
|
+
const apiPromise = substrateApi.api;
|
|
87
|
+
if (!(apiPromise instanceof _api.GearApi)) {
|
|
86
88
|
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
87
89
|
return _util.noop;
|
|
88
90
|
}
|
|
@@ -91,7 +93,7 @@ const subscribeVftBalance = _ref3 => {
|
|
|
91
93
|
const tokenList = (0, _utils2.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.VFT]);
|
|
92
94
|
Object.entries(tokenList).forEach(_ref4 => {
|
|
93
95
|
let [slug, tokenInfo] = _ref4;
|
|
94
|
-
vftContractMap[slug] = (0, _utils2.getVFTContractPromise)(
|
|
96
|
+
vftContractMap[slug] = (0, _utils2.getVFTContractPromise)(apiPromise, (0, _utils._getContractAddressOfToken)(tokenInfo));
|
|
95
97
|
});
|
|
96
98
|
const getTokenBalances = () => {
|
|
97
99
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.ChainflipSwapHandler = void 0;
|
|
7
|
+
exports.ChainflipSwapHandler = exports.CHAINFLIP_BROKER_API = void 0;
|
|
8
8
|
var _swap = require("@chainflip/sdk/swap");
|
|
9
9
|
var _chainList = require("@subwallet/chain-list");
|
|
10
10
|
var _SwapError = require("@subwallet/extension-base/background/errors/SwapError");
|
|
@@ -26,10 +26,13 @@ var ChainflipFeeType;
|
|
|
26
26
|
ChainflipFeeType["INGRESS"] = "INGRESS";
|
|
27
27
|
ChainflipFeeType["NETWORK"] = "NETWORK";
|
|
28
28
|
ChainflipFeeType["EGRESS"] = "EGRESS";
|
|
29
|
-
ChainflipFeeType["
|
|
29
|
+
ChainflipFeeType["BOOST"] = "BOOST";
|
|
30
|
+
ChainflipFeeType["BROKER"] = "BROKER";
|
|
30
31
|
})(ChainflipFeeType || (ChainflipFeeType = {}));
|
|
31
32
|
const INTERMEDIARY_MAINNET_ASSET_SLUG = _chainList.COMMON_ASSETS.USDC_ETHEREUM;
|
|
32
33
|
const INTERMEDIARY_TESTNET_ASSET_SLUG = _chainList.COMMON_ASSETS.USDC_SEPOLIA;
|
|
34
|
+
const CHAINFLIP_BROKER_API = process.env.CHAINFLIP_BROKER_API || '';
|
|
35
|
+
exports.CHAINFLIP_BROKER_API = CHAINFLIP_BROKER_API;
|
|
33
36
|
var CHAINFLIP_QUOTE_ERROR;
|
|
34
37
|
(function (CHAINFLIP_QUOTE_ERROR) {
|
|
35
38
|
CHAINFLIP_QUOTE_ERROR["InsufficientLiquidity"] = "InsufficientLiquidity";
|
|
@@ -47,9 +50,9 @@ class ChainflipSwapHandler {
|
|
|
47
50
|
});
|
|
48
51
|
this.isTestnet = isTestnet;
|
|
49
52
|
this.providerSlug = isTestnet ? _swap3.SwapProviderId.CHAIN_FLIP_TESTNET : _swap3.SwapProviderId.CHAIN_FLIP_MAINNET;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
this.swapSdk = new _swap.SwapSDK((0, _utils2.getChainflipOptions)(isTestnet));
|
|
53
56
|
}
|
|
54
57
|
get chainService() {
|
|
55
58
|
return this.swapBaseHandler.chainService;
|
|
@@ -235,7 +238,10 @@ class ChainflipSwapHandler {
|
|
|
235
238
|
case ChainflipFeeType.NETWORK:
|
|
236
239
|
|
|
237
240
|
// eslint-disable-next-line no-fallthrough
|
|
238
|
-
case ChainflipFeeType.
|
|
241
|
+
case ChainflipFeeType.BOOST:
|
|
242
|
+
|
|
243
|
+
// eslint-disable-next-line no-fallthrough
|
|
244
|
+
case ChainflipFeeType.BROKER:
|
|
239
245
|
{
|
|
240
246
|
const tokenSlug = Object.keys(this.assetMapping).find(assetSlug => this.assetMapping[assetSlug] === fee.asset);
|
|
241
247
|
feeComponent.push({
|
|
@@ -7,11 +7,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports._PROVIDER_TO_SUPPORTED_PAIR_MAP = exports.SWAP_QUOTE_TIMEOUT_MAP = exports.CHAIN_FLIP_TESTNET_EXPLORER = exports.CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING = exports.CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING = exports.CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING = exports.CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING = exports.CHAIN_FLIP_MAINNET_EXPLORER = void 0;
|
|
8
8
|
exports.calculateSwapRate = calculateSwapRate;
|
|
9
9
|
exports.convertSwapRate = convertSwapRate;
|
|
10
|
+
exports.getChainflipBroker = getChainflipBroker;
|
|
11
|
+
exports.getChainflipOptions = getChainflipOptions;
|
|
10
12
|
exports.getSwapAltToken = getSwapAltToken;
|
|
11
13
|
exports.getSwapAlternativeAsset = getSwapAlternativeAsset;
|
|
12
14
|
var _swap = require("@chainflip/sdk/swap");
|
|
13
15
|
var _chainList = require("@subwallet/chain-list");
|
|
14
16
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
17
|
+
var _chainflipHandler = require("@subwallet/extension-base/services/swap-service/handler/chainflip-handler");
|
|
15
18
|
var _swap2 = require("@subwallet/extension-base/types/swap");
|
|
16
19
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
17
20
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
@@ -79,4 +82,30 @@ function convertSwapRate(rate, fromAsset, toAsset) {
|
|
|
79
82
|
const decimalDiff = (0, _utils._getAssetDecimals)(toAsset) - (0, _utils._getAssetDecimals)(fromAsset);
|
|
80
83
|
const bnRate = new _bignumber.default(rate);
|
|
81
84
|
return bnRate.times(10 ** decimalDiff).pow(-1).toNumber();
|
|
85
|
+
}
|
|
86
|
+
function getChainflipOptions(isTestnet) {
|
|
87
|
+
if (isTestnet) {
|
|
88
|
+
return {
|
|
89
|
+
network: getChainflipNetwork(isTestnet)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
network: getChainflipNetwork(isTestnet),
|
|
94
|
+
broker: getChainflipBroker(isTestnet)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function getChainflipNetwork(isTestnet) {
|
|
98
|
+
return isTestnet ? 'perseverance' : 'mainnet';
|
|
99
|
+
}
|
|
100
|
+
function getChainflipBroker(isTestnet) {
|
|
101
|
+
// noted: currently not use testnet broker
|
|
102
|
+
if (isTestnet) {
|
|
103
|
+
return {
|
|
104
|
+
url: `https://perseverance.chainflip-broker.io/rpc/${_chainflipHandler.CHAINFLIP_BROKER_API}`
|
|
105
|
+
};
|
|
106
|
+
} else {
|
|
107
|
+
return {
|
|
108
|
+
url: `https://chainflip-broker.io/rpc/${_chainflipHandler.CHAINFLIP_BROKER_API}`
|
|
109
|
+
};
|
|
110
|
+
}
|
|
82
111
|
}
|
|
@@ -1940,8 +1940,9 @@ export default class KoniExtension {
|
|
|
1940
1940
|
const substrateApi = this.#koniState.chainService.getSubstrateApi(originTokenInfo.originChain);
|
|
1941
1941
|
const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
|
|
1942
1942
|
const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, originTokenInfo.slug);
|
|
1943
|
+
const existentialDeposit = originTokenInfo.minAmount || '0';
|
|
1943
1944
|
if (destinationTokenInfo) {
|
|
1944
|
-
const [
|
|
1945
|
+
const [bnMockExecutionFee, {
|
|
1945
1946
|
value
|
|
1946
1947
|
}] = await Promise.all([getXcmMockTxFee(substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo), this.getAddressTransferableBalance({
|
|
1947
1948
|
extrinsicType: ExtrinsicType.TRANSFER_XCM,
|
|
@@ -1950,8 +1951,7 @@ export default class KoniExtension {
|
|
|
1950
1951
|
token: originTokenInfo.slug
|
|
1951
1952
|
})]);
|
|
1952
1953
|
const bnMaxTransferable = new BigN(value);
|
|
1953
|
-
const estimatedFee =
|
|
1954
|
-
|
|
1954
|
+
const estimatedFee = bnMockExecutionFee.multipliedBy(XCM_FEE_RATIO).plus(new BigN(existentialDeposit));
|
|
1955
1955
|
return bnMaxTransferable.minus(estimatedFee);
|
|
1956
1956
|
}
|
|
1957
1957
|
return new BigN(0);
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.2.
|
|
20
|
+
"version": "1.2.30-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2038,7 +2038,7 @@
|
|
|
2038
2038
|
"@acala-network/api": "^5.0.2",
|
|
2039
2039
|
"@apollo/client": "^3.7.14",
|
|
2040
2040
|
"@azns/resolver-core": "^1.4.0",
|
|
2041
|
-
"@chainflip/sdk": "^1.
|
|
2041
|
+
"@chainflip/sdk": "^1.5.2",
|
|
2042
2042
|
"@equilab/api": "~1.14.25",
|
|
2043
2043
|
"@ethereumjs/common": "^4.1.0",
|
|
2044
2044
|
"@ethereumjs/tx": "^5.1.0",
|
|
@@ -2070,11 +2070,11 @@
|
|
|
2070
2070
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2071
2071
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2072
2072
|
"@substrate/connect": "^0.8.9",
|
|
2073
|
-
"@subwallet/chain-list": "0.2.
|
|
2074
|
-
"@subwallet/extension-base": "^1.2.
|
|
2075
|
-
"@subwallet/extension-chains": "^1.2.
|
|
2076
|
-
"@subwallet/extension-dapp": "^1.2.
|
|
2077
|
-
"@subwallet/extension-inject": "^1.2.
|
|
2073
|
+
"@subwallet/chain-list": "0.2.87",
|
|
2074
|
+
"@subwallet/extension-base": "^1.2.30-0",
|
|
2075
|
+
"@subwallet/extension-chains": "^1.2.30-0",
|
|
2076
|
+
"@subwallet/extension-dapp": "^1.2.30-0",
|
|
2077
|
+
"@subwallet/extension-inject": "^1.2.30-0",
|
|
2078
2078
|
"@subwallet/keyring": "^0.1.6",
|
|
2079
2079
|
"@subwallet/ui-keyring": "^0.1.6",
|
|
2080
2080
|
"@walletconnect/keyvaluestorage": "^1.1.1",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.2.
|
|
10
|
+
version: '1.2.30-0'
|
|
11
11
|
};
|
|
@@ -109,10 +109,10 @@ export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _cha
|
|
|
109
109
|
evmApi
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
113
|
+
if (!substrateApi.isApiReady) {
|
|
113
114
|
handleUnsupportedOrPendingAddresses(useAddresses, chainSlug, chainAssetMap, APIItemState.PENDING, callback);
|
|
114
115
|
}
|
|
115
|
-
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
116
116
|
return subscribeSubstrateBalance(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
|
|
117
117
|
});
|
|
118
118
|
return () => {
|
|
@@ -16,7 +16,8 @@ export const subscribeGRC20Balance = ({
|
|
|
16
16
|
chainInfo,
|
|
17
17
|
substrateApi
|
|
18
18
|
}) => {
|
|
19
|
-
|
|
19
|
+
const apiPromise = substrateApi.api;
|
|
20
|
+
if (!(apiPromise instanceof GearApi)) {
|
|
20
21
|
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
21
22
|
return noop;
|
|
22
23
|
}
|
|
@@ -24,7 +25,7 @@ export const subscribeGRC20Balance = ({
|
|
|
24
25
|
const grc20ContractMap = {};
|
|
25
26
|
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.GRC20]);
|
|
26
27
|
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
27
|
-
grc20ContractMap[slug] = getGRC20ContractPromise(
|
|
28
|
+
grc20ContractMap[slug] = getGRC20ContractPromise(apiPromise, _getContractAddressOfToken(tokenInfo));
|
|
28
29
|
});
|
|
29
30
|
const getTokenBalances = () => {
|
|
30
31
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -72,7 +73,8 @@ export const subscribeVftBalance = ({
|
|
|
72
73
|
chainInfo,
|
|
73
74
|
substrateApi
|
|
74
75
|
}) => {
|
|
75
|
-
|
|
76
|
+
const apiPromise = substrateApi.api;
|
|
77
|
+
if (!(apiPromise instanceof GearApi)) {
|
|
76
78
|
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
77
79
|
return noop;
|
|
78
80
|
}
|
|
@@ -80,7 +82,7 @@ export const subscribeVftBalance = ({
|
|
|
80
82
|
const vftContractMap = {};
|
|
81
83
|
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.VFT]);
|
|
82
84
|
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
83
|
-
vftContractMap[slug] = getVFTContractPromise(
|
|
85
|
+
vftContractMap[slug] = getVFTContractPromise(apiPromise, _getContractAddressOfToken(tokenInfo));
|
|
84
86
|
});
|
|
85
87
|
const getTokenBalances = () => {
|
|
86
88
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -6,6 +6,7 @@ import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
|
6
6
|
import { SwapBaseInterface } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
|
|
7
7
|
import { BaseStepDetail, CommonOptimalPath, CommonStepFeeInfo } from '@subwallet/extension-base/types/service-base';
|
|
8
8
|
import { OptimalSwapPathParams, SwapEarlyValidation, SwapProviderId, SwapQuote, SwapRequest, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
|
|
9
|
+
export declare const CHAINFLIP_BROKER_API: string;
|
|
9
10
|
export declare class ChainflipSwapHandler implements SwapBaseInterface {
|
|
10
11
|
private swapSdk;
|
|
11
12
|
private readonly isTestnet;
|
|
@@ -17,8 +18,8 @@ export declare class ChainflipSwapHandler implements SwapBaseInterface {
|
|
|
17
18
|
get providerInfo(): import("@subwallet/extension-base/types/swap").SwapProvider;
|
|
18
19
|
get name(): string;
|
|
19
20
|
get slug(): string;
|
|
20
|
-
get assetMapping(): Record<string, import("@chainflip/sdk/dist/contracts-
|
|
21
|
-
get chainMapping(): Record<string, import("@chainflip/sdk/dist/contracts-
|
|
21
|
+
get assetMapping(): Record<string, import("@chainflip/sdk/dist/contracts-Cb-5VdIi").a>;
|
|
22
|
+
get chainMapping(): Record<string, import("@chainflip/sdk/dist/contracts-Cb-5VdIi").C>;
|
|
22
23
|
get intermediaryAssetSlug(): COMMON_ASSETS.USDC_ETHEREUM | COMMON_ASSETS.USDC_SEPOLIA;
|
|
23
24
|
validateSwapRequest(request: SwapRequest): Promise<SwapEarlyValidation>;
|
|
24
25
|
private parseSwapPath;
|
|
@@ -11,7 +11,7 @@ import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/e
|
|
|
11
11
|
import { createTransferExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
12
12
|
import { _getAssetDecimals, _getChainNativeTokenSlug, _getContractAddressOfToken, _isNativeToken, _isSubstrateChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
13
|
import { SwapBaseHandler } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
|
|
14
|
-
import { calculateSwapRate, CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING, SWAP_QUOTE_TIMEOUT_MAP } from '@subwallet/extension-base/services/swap-service/utils';
|
|
14
|
+
import { calculateSwapRate, CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING, getChainflipOptions, SWAP_QUOTE_TIMEOUT_MAP } from '@subwallet/extension-base/services/swap-service/utils';
|
|
15
15
|
import { CommonStepType } from '@subwallet/extension-base/types/service-base';
|
|
16
16
|
import { SwapErrorType, SwapFeeType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
|
|
17
17
|
import BigNumber from 'bignumber.js';
|
|
@@ -20,10 +20,12 @@ var ChainflipFeeType;
|
|
|
20
20
|
ChainflipFeeType["INGRESS"] = "INGRESS";
|
|
21
21
|
ChainflipFeeType["NETWORK"] = "NETWORK";
|
|
22
22
|
ChainflipFeeType["EGRESS"] = "EGRESS";
|
|
23
|
-
ChainflipFeeType["
|
|
23
|
+
ChainflipFeeType["BOOST"] = "BOOST";
|
|
24
|
+
ChainflipFeeType["BROKER"] = "BROKER";
|
|
24
25
|
})(ChainflipFeeType || (ChainflipFeeType = {}));
|
|
25
26
|
const INTERMEDIARY_MAINNET_ASSET_SLUG = COMMON_ASSETS.USDC_ETHEREUM;
|
|
26
27
|
const INTERMEDIARY_TESTNET_ASSET_SLUG = COMMON_ASSETS.USDC_SEPOLIA;
|
|
28
|
+
export const CHAINFLIP_BROKER_API = process.env.CHAINFLIP_BROKER_API || '';
|
|
27
29
|
var CHAINFLIP_QUOTE_ERROR;
|
|
28
30
|
(function (CHAINFLIP_QUOTE_ERROR) {
|
|
29
31
|
CHAINFLIP_QUOTE_ERROR["InsufficientLiquidity"] = "InsufficientLiquidity";
|
|
@@ -40,9 +42,9 @@ export class ChainflipSwapHandler {
|
|
|
40
42
|
});
|
|
41
43
|
this.isTestnet = isTestnet;
|
|
42
44
|
this.providerSlug = isTestnet ? SwapProviderId.CHAIN_FLIP_TESTNET : SwapProviderId.CHAIN_FLIP_MAINNET;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
this.swapSdk = new SwapSDK(getChainflipOptions(isTestnet));
|
|
46
48
|
}
|
|
47
49
|
get chainService() {
|
|
48
50
|
return this.swapBaseHandler.chainService;
|
|
@@ -228,7 +230,10 @@ export class ChainflipSwapHandler {
|
|
|
228
230
|
case ChainflipFeeType.NETWORK:
|
|
229
231
|
|
|
230
232
|
// eslint-disable-next-line no-fallthrough
|
|
231
|
-
case ChainflipFeeType.
|
|
233
|
+
case ChainflipFeeType.BOOST:
|
|
234
|
+
|
|
235
|
+
// eslint-disable-next-line no-fallthrough
|
|
236
|
+
case ChainflipFeeType.BROKER:
|
|
232
237
|
{
|
|
233
238
|
const tokenSlug = Object.keys(this.assetMapping).find(assetSlug => this.assetMapping[assetSlug] === fee.asset);
|
|
234
239
|
feeComponent.push({
|
|
@@ -13,3 +13,15 @@ export declare function getSwapAlternativeAsset(swapPair: SwapPair): string | un
|
|
|
13
13
|
export declare function getSwapAltToken(chainAsset: _ChainAsset): string | undefined;
|
|
14
14
|
export declare function calculateSwapRate(fromAmount: string, toAmount: string, fromAsset: _ChainAsset, toAsset: _ChainAsset): number;
|
|
15
15
|
export declare function convertSwapRate(rate: string, fromAsset: _ChainAsset, toAsset: _ChainAsset): number;
|
|
16
|
+
export declare function getChainflipOptions(isTestnet: boolean): {
|
|
17
|
+
network: string;
|
|
18
|
+
broker?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
network: string;
|
|
21
|
+
broker: {
|
|
22
|
+
url: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare function getChainflipBroker(isTestnet: boolean): {
|
|
26
|
+
url: string;
|
|
27
|
+
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Assets, Chains } from '@chainflip/sdk/swap';
|
|
5
5
|
import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
6
6
|
import { _getAssetDecimals } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { CHAINFLIP_BROKER_API } from '@subwallet/extension-base/services/swap-service/handler/chainflip-handler';
|
|
7
8
|
import { SwapProviderId } from '@subwallet/extension-base/types/swap';
|
|
8
9
|
import BigN from 'bignumber.js';
|
|
9
10
|
export const CHAIN_FLIP_TESTNET_EXPLORER = 'https://blocks-perseverance.chainflip.io';
|
|
@@ -60,4 +61,30 @@ export function convertSwapRate(rate, fromAsset, toAsset) {
|
|
|
60
61
|
const decimalDiff = _getAssetDecimals(toAsset) - _getAssetDecimals(fromAsset);
|
|
61
62
|
const bnRate = new BigN(rate);
|
|
62
63
|
return bnRate.times(10 ** decimalDiff).pow(-1).toNumber();
|
|
64
|
+
}
|
|
65
|
+
export function getChainflipOptions(isTestnet) {
|
|
66
|
+
if (isTestnet) {
|
|
67
|
+
return {
|
|
68
|
+
network: getChainflipNetwork(isTestnet)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
network: getChainflipNetwork(isTestnet),
|
|
73
|
+
broker: getChainflipBroker(isTestnet)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getChainflipNetwork(isTestnet) {
|
|
77
|
+
return isTestnet ? 'perseverance' : 'mainnet';
|
|
78
|
+
}
|
|
79
|
+
export function getChainflipBroker(isTestnet) {
|
|
80
|
+
// noted: currently not use testnet broker
|
|
81
|
+
if (isTestnet) {
|
|
82
|
+
return {
|
|
83
|
+
url: `https://perseverance.chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
|
|
84
|
+
};
|
|
85
|
+
} else {
|
|
86
|
+
return {
|
|
87
|
+
url: `https://chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
|
|
88
|
+
};
|
|
89
|
+
}
|
|
63
90
|
}
|