@subwallet/extension-base 1.3.49-0 → 1.3.51-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/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +3 -1
- package/cjs/services/swap-service/handler/base-handler.js +5 -2
- package/cjs/services/swap-service/handler/chainflip-handler.js +40 -15
- package/cjs/utils/account/common.js +1 -0
- package/cjs/utils/account/transform.js +1 -1
- package/package.json +6 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/handler/bitcoin/BitcoinApi.js +3 -1
- package/services/swap-service/handler/base-handler.js +6 -3
- package/services/swap-service/handler/chainflip-handler.js +39 -16
- package/types/swap/index.d.ts +2 -0
- package/utils/account/common.js +1 -0
- package/utils/account/transform.js +1 -1
package/cjs/packageInfo.js
CHANGED
|
@@ -37,10 +37,11 @@ class BitcoinApi {
|
|
|
37
37
|
return this.isApiConnectedSubject.getValue();
|
|
38
38
|
}
|
|
39
39
|
createApiStrategy(apiUrl) {
|
|
40
|
+
const _apiUrl = 'https://blockstream.info/testnet/api/'; // todo: for test
|
|
40
41
|
const isTestnet = apiUrl.includes('testnet');
|
|
41
42
|
const isBlockstreamUrl = apiUrl.includes('blockstream');
|
|
42
43
|
if (isTestnet) {
|
|
43
|
-
return isBlockstreamUrl ? new _BlockStreamTestnet.BlockStreamTestnetRequestStrategy(
|
|
44
|
+
return isBlockstreamUrl ? new _BlockStreamTestnet.BlockStreamTestnetRequestStrategy(_apiUrl) : new _BlockStreamTestnet.MempoolTestnetRequestStrategy(_apiUrl);
|
|
44
45
|
}
|
|
45
46
|
return new _SubWalletMainnet.SubWalletMainnetRequestStrategy(apiUrl);
|
|
46
47
|
}
|
|
@@ -57,6 +58,7 @@ class BitcoinApi {
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
get isReady() {
|
|
61
|
+
// todo: recheck if bitcoinApi need this
|
|
60
62
|
return this.isReadyHandler.promise;
|
|
61
63
|
}
|
|
62
64
|
async updateApiUrl(apiUrl) {
|
|
@@ -21,6 +21,7 @@ var _serviceBase = require("@subwallet/extension-base/types/service-base");
|
|
|
21
21
|
var _swap = require("@subwallet/extension-base/types/swap");
|
|
22
22
|
var _utils5 = require("@subwallet/extension-base/utils");
|
|
23
23
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
24
|
+
var _validate = require("@subwallet/keyring/utils/address/validate");
|
|
24
25
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
25
26
|
var _i18next = require("i18next");
|
|
26
27
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
@@ -380,8 +381,10 @@ class SwapBaseHandler {
|
|
|
380
381
|
if (recipient) {
|
|
381
382
|
const isEvmAddress = (0, _utilCrypto.isEthereumAddress)(recipient);
|
|
382
383
|
const isEvmDestChain = (0, _utils3._isChainEvmCompatible)(swapToChain);
|
|
383
|
-
|
|
384
|
-
|
|
384
|
+
const isBtcAddress = (0, _validate.isBitcoinAddress)(recipient);
|
|
385
|
+
const isBtcDestChain = (0, _utils3._isPureBitcoinChain)(swapToChain);
|
|
386
|
+
if (isEvmAddress !== isEvmDestChain || isBtcAddress !== isBtcDestChain) {
|
|
387
|
+
// todo: update condition if support swap chain # EVM, Substrate, Bitcoin
|
|
385
388
|
return [new _TransactionError.TransactionError(_swap.SwapErrorType.INVALID_RECIPIENT)];
|
|
386
389
|
}
|
|
387
390
|
}
|
|
@@ -8,6 +8,7 @@ exports.ChainflipSwapHandler = void 0;
|
|
|
8
8
|
var _chainList = require("@subwallet/chain-list");
|
|
9
9
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
10
10
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
11
|
+
var _bitcoinTransfer = require("@subwallet/extension-base/services/balance-service/transfer/bitcoin-transfer");
|
|
11
12
|
var _smartContract = require("@subwallet/extension-base/services/balance-service/transfer/smart-contract");
|
|
12
13
|
var _token = require("@subwallet/extension-base/services/balance-service/transfer/token");
|
|
13
14
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
@@ -17,6 +18,9 @@ var _environment = require("@subwallet/extension-base/types/environment");
|
|
|
17
18
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
18
19
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
19
20
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
21
|
+
var bitcoin = _interopRequireWildcard(require("bitcoinjs-lib"));
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
24
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
21
25
|
// SPDX-License-Identifier: Apache-2.0
|
|
22
26
|
|
|
@@ -66,22 +70,23 @@ class ChainflipSwapHandler {
|
|
|
66
70
|
async handleSubmitStep(params) {
|
|
67
71
|
const {
|
|
68
72
|
address,
|
|
73
|
+
currentStep,
|
|
74
|
+
process,
|
|
69
75
|
quote,
|
|
70
76
|
recipient,
|
|
71
77
|
slippage
|
|
72
78
|
} = params;
|
|
73
79
|
const pair = quote.pair;
|
|
74
80
|
const fromAsset = this.chainService.getAssetBySlug(pair.from);
|
|
75
|
-
const toAsset = this.chainService.getAssetBySlug(pair.to);
|
|
76
81
|
const chainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
|
|
77
82
|
const toChainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
|
|
78
|
-
const chainType = (0, _utils._isChainSubstrateCompatible)(chainInfo) ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM;
|
|
83
|
+
const chainType = (0, _utils._isChainSubstrateCompatible)(chainInfo) ? _KoniTypes.ChainType.SUBSTRATE : (0, _utils._isPureBitcoinChain)(chainInfo) ? _KoniTypes.ChainType.BITCOIN : _KoniTypes.ChainType.EVM; // todo: improve throw error for unknown chain
|
|
79
84
|
const receiver = (0, _utils2._reformatAddressWithChain)(recipient !== null && recipient !== void 0 ? recipient : address, toChainInfo);
|
|
80
|
-
const fromAssetId = (0, _utils._getAssetSymbol)(fromAsset);
|
|
81
|
-
const toAssetId = (0, _utils._getAssetSymbol)(toAsset);
|
|
82
85
|
const minReceive = new _bignumber.default(quote.rate).times(1 - slippage).toString();
|
|
83
|
-
const processMetadata =
|
|
86
|
+
const processMetadata = process.steps[currentStep].metadata;
|
|
84
87
|
const quoteMetadata = processMetadata;
|
|
88
|
+
const fromAssetId = quoteMetadata.fromAssetId;
|
|
89
|
+
const toAssetId = quoteMetadata.toAssetId;
|
|
85
90
|
if (!processMetadata || !quoteMetadata) {
|
|
86
91
|
throw new Error('Metadata for Chainflip not found');
|
|
87
92
|
}
|
|
@@ -114,6 +119,7 @@ class ChainflipSwapHandler {
|
|
|
114
119
|
method: 'GET'
|
|
115
120
|
}, this.isTestnet);
|
|
116
121
|
const data = await response.json();
|
|
122
|
+
console.log('Chainflip channel info:', data);
|
|
117
123
|
if (!data.id || !data.address || data.address === '' || !data.issuedBlock || !data.network || !data.channelId) {
|
|
118
124
|
throw new Error('Error get Chainflip data');
|
|
119
125
|
}
|
|
@@ -122,17 +128,17 @@ class ChainflipSwapHandler {
|
|
|
122
128
|
const txData = {
|
|
123
129
|
address,
|
|
124
130
|
provider: this.providerInfo,
|
|
125
|
-
quote
|
|
126
|
-
slippage
|
|
131
|
+
quote,
|
|
132
|
+
slippage,
|
|
127
133
|
recipient,
|
|
128
|
-
depositChannelId
|
|
129
|
-
depositAddress
|
|
130
|
-
process
|
|
134
|
+
depositChannelId,
|
|
135
|
+
depositAddress,
|
|
136
|
+
process
|
|
131
137
|
};
|
|
132
138
|
let extrinsic;
|
|
133
139
|
if (chainType === _KoniTypes.ChainType.SUBSTRATE) {
|
|
134
|
-
const
|
|
135
|
-
const substrateApi = await
|
|
140
|
+
const _substrateApi = this.chainService.getSubstrateApi(chainInfo.slug);
|
|
141
|
+
const substrateApi = await _substrateApi.isReady;
|
|
136
142
|
const [submittableExtrinsic] = await (0, _token.createSubstrateExtrinsic)({
|
|
137
143
|
from: address,
|
|
138
144
|
networkKey: chainInfo.slug,
|
|
@@ -144,9 +150,8 @@ class ChainflipSwapHandler {
|
|
|
144
150
|
value: quote.fromAmount
|
|
145
151
|
});
|
|
146
152
|
extrinsic = submittableExtrinsic;
|
|
147
|
-
} else {
|
|
148
|
-
const
|
|
149
|
-
const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee(id, chainInfo.slug, 'evm');
|
|
153
|
+
} else if (chainType === _KoniTypes.ChainType.EVM) {
|
|
154
|
+
const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee((0, _getId.getId)(), chainInfo.slug, 'evm');
|
|
150
155
|
if ((0, _utils._isNativeToken)(fromAsset)) {
|
|
151
156
|
const [transactionConfig] = await (0, _smartContract.getEVMTransactionObject)({
|
|
152
157
|
chain: chainInfo.slug,
|
|
@@ -171,6 +176,24 @@ class ChainflipSwapHandler {
|
|
|
171
176
|
});
|
|
172
177
|
extrinsic = transactionConfig;
|
|
173
178
|
}
|
|
179
|
+
} else if (chainType === _KoniTypes.ChainType.BITCOIN) {
|
|
180
|
+
const bitcoinApi = this.chainService.getBitcoinApi(chainInfo.slug);
|
|
181
|
+
const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee((0, _getId.getId)(), chainInfo.slug, 'bitcoin');
|
|
182
|
+
const network = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
|
|
183
|
+
const [transaction] = await (0, _bitcoinTransfer.createBitcoinTransaction)({
|
|
184
|
+
bitcoinApi,
|
|
185
|
+
chain: chainInfo.slug,
|
|
186
|
+
from: address,
|
|
187
|
+
feeInfo,
|
|
188
|
+
to: depositAddress,
|
|
189
|
+
transferAll: false,
|
|
190
|
+
value: quote.fromAmount,
|
|
191
|
+
network
|
|
192
|
+
});
|
|
193
|
+
extrinsic = transaction;
|
|
194
|
+
} else {
|
|
195
|
+
// todo: update this when support new chainType rather than substrate, evm, bitcoin
|
|
196
|
+
throw new Error('Unknown swap chain type');
|
|
174
197
|
}
|
|
175
198
|
return {
|
|
176
199
|
txChain: fromAsset.originChain,
|
|
@@ -223,6 +246,8 @@ class ChainflipSwapHandler {
|
|
|
223
246
|
receiver: (0, _utils2._reformatAddressWithChain)(params.request.recipient || params.request.address, destinationChain),
|
|
224
247
|
srcChain: metadata.srcChain,
|
|
225
248
|
destChain: metadata.destChain,
|
|
249
|
+
fromAssetId: metadata.fromAssetId,
|
|
250
|
+
toAssetId: metadata.toAssetId,
|
|
226
251
|
version: 2
|
|
227
252
|
}
|
|
228
253
|
};
|
|
@@ -177,7 +177,7 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
|
|
|
177
177
|
case _types2.AccountChainType.CARDANO:
|
|
178
178
|
return [...BASE_TRANSFER_ACTIONS];
|
|
179
179
|
case _types2.AccountChainType.BITCOIN:
|
|
180
|
-
return [...BASE_TRANSFER_ACTIONS];
|
|
180
|
+
return [...BASE_TRANSFER_ACTIONS, _KoniTypes.ExtrinsicType.SWAP];
|
|
181
181
|
}
|
|
182
182
|
} else if (signMode === _types2.AccountSignMode.QR) {
|
|
183
183
|
switch (networkType) {
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.51-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2866,12 +2866,12 @@
|
|
|
2866
2866
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2867
2867
|
"@substrate/connect": "^0.8.9",
|
|
2868
2868
|
"@subwallet/chain-list": "0.2.110",
|
|
2869
|
-
"@subwallet/extension-base": "^1.3.
|
|
2870
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2871
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2872
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2869
|
+
"@subwallet/extension-base": "^1.3.51-0",
|
|
2870
|
+
"@subwallet/extension-chains": "^1.3.51-0",
|
|
2871
|
+
"@subwallet/extension-dapp": "^1.3.51-0",
|
|
2872
|
+
"@subwallet/extension-inject": "^1.3.51-0",
|
|
2873
2873
|
"@subwallet/keyring": "^0.1.12",
|
|
2874
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2874
|
+
"@subwallet/subwallet-api-sdk": "^1.3.51-0",
|
|
2875
2875
|
"@subwallet/ui-keyring": "^0.1.12",
|
|
2876
2876
|
"@ton/core": "^0.56.3",
|
|
2877
2877
|
"@ton/crypto": "^3.2.0",
|
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.3.
|
|
10
|
+
version: '1.3.51-0'
|
|
11
11
|
};
|
|
@@ -31,10 +31,11 @@ export class BitcoinApi {
|
|
|
31
31
|
return this.isApiConnectedSubject.getValue();
|
|
32
32
|
}
|
|
33
33
|
createApiStrategy(apiUrl) {
|
|
34
|
+
const _apiUrl = 'https://blockstream.info/testnet/api/'; // todo: for test
|
|
34
35
|
const isTestnet = apiUrl.includes('testnet');
|
|
35
36
|
const isBlockstreamUrl = apiUrl.includes('blockstream');
|
|
36
37
|
if (isTestnet) {
|
|
37
|
-
return isBlockstreamUrl ? new BlockStreamTestnetRequestStrategy(
|
|
38
|
+
return isBlockstreamUrl ? new BlockStreamTestnetRequestStrategy(_apiUrl) : new MempoolTestnetRequestStrategy(_apiUrl);
|
|
38
39
|
}
|
|
39
40
|
return new SubWalletMainnetRequestStrategy(apiUrl);
|
|
40
41
|
}
|
|
@@ -51,6 +52,7 @@ export class BitcoinApi {
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
get isReady() {
|
|
55
|
+
// todo: recheck if bitcoinApi need this
|
|
54
56
|
return this.isReadyHandler.promise;
|
|
55
57
|
}
|
|
56
58
|
async updateApiUrl(apiUrl) {
|
|
@@ -10,13 +10,14 @@ import { _isSufficientToken } from '@subwallet/extension-base/core/utils';
|
|
|
10
10
|
import { createXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
11
11
|
import { _isAcrossChainBridge, AcrossErrorMsg } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
|
|
12
12
|
import { estimateXcmFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
13
|
-
import { _getAssetDecimals, _getAssetOriginChain, _getAssetSymbol, _getChainNativeTokenSlug, _getTokenMinAmount, _isChainEvmCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
|
+
import { _getAssetDecimals, _getAssetOriginChain, _getAssetSymbol, _getChainNativeTokenSlug, _getTokenMinAmount, _isChainEvmCompatible, _isNativeToken, _isPureBitcoinChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
14
|
import { DEFAULT_EXCESS_AMOUNT_WEIGHT, FEE_RATE_MULTIPLIER } from '@subwallet/extension-base/services/swap-service/utils';
|
|
15
15
|
import { BasicTxErrorType, SwapStepType, TransferTxErrorType } from '@subwallet/extension-base/types';
|
|
16
16
|
import { CommonStepType, DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
|
|
17
17
|
import { DynamicSwapType, SwapErrorType, SwapFeeType } from '@subwallet/extension-base/types/swap';
|
|
18
18
|
import { _reformatAddressWithChain, balanceFormatter, formatNumber } from '@subwallet/extension-base/utils';
|
|
19
19
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
20
|
+
import { isBitcoinAddress } from '@subwallet/keyring/utils/address/validate';
|
|
20
21
|
import BigN from 'bignumber.js';
|
|
21
22
|
import { t } from 'i18next';
|
|
22
23
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
@@ -372,8 +373,10 @@ export class SwapBaseHandler {
|
|
|
372
373
|
if (recipient) {
|
|
373
374
|
const isEvmAddress = isEthereumAddress(recipient);
|
|
374
375
|
const isEvmDestChain = _isChainEvmCompatible(swapToChain);
|
|
375
|
-
|
|
376
|
-
|
|
376
|
+
const isBtcAddress = isBitcoinAddress(recipient);
|
|
377
|
+
const isBtcDestChain = _isPureBitcoinChain(swapToChain);
|
|
378
|
+
if (isEvmAddress !== isEvmDestChain || isBtcAddress !== isBtcDestChain) {
|
|
379
|
+
// todo: update condition if support swap chain # EVM, Substrate, Bitcoin
|
|
377
380
|
return [new TransactionError(SwapErrorType.INVALID_RECIPIENT)];
|
|
378
381
|
}
|
|
379
382
|
}
|
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
import { COMMON_ASSETS } from '@subwallet/chain-list';
|
|
5
5
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
6
6
|
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
|
+
import { createBitcoinTransaction } from '@subwallet/extension-base/services/balance-service/transfer/bitcoin-transfer';
|
|
7
8
|
import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
|
|
8
9
|
import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
9
|
-
import {
|
|
10
|
+
import { _getContractAddressOfToken, _isChainSubstrateCompatible, _isNativeToken, _isPureBitcoinChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
11
|
import { SwapBaseHandler } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
|
|
11
12
|
import { BasicTxErrorType, CommonStepType, DynamicSwapType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types';
|
|
12
13
|
import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
|
|
13
14
|
import { _reformatAddressWithChain, fetchFromProxyService } from '@subwallet/extension-base/utils';
|
|
14
15
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
15
16
|
import BigNumber from 'bignumber.js';
|
|
17
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
16
18
|
const INTERMEDIARY_MAINNET_ASSET_SLUG = COMMON_ASSETS.USDC_ETHEREUM;
|
|
17
19
|
const INTERMEDIARY_TESTNET_ASSET_SLUG = COMMON_ASSETS.USDC_SEPOLIA;
|
|
18
20
|
export class ChainflipSwapHandler {
|
|
@@ -58,22 +60,23 @@ export class ChainflipSwapHandler {
|
|
|
58
60
|
async handleSubmitStep(params) {
|
|
59
61
|
const {
|
|
60
62
|
address,
|
|
63
|
+
currentStep,
|
|
64
|
+
process,
|
|
61
65
|
quote,
|
|
62
66
|
recipient,
|
|
63
67
|
slippage
|
|
64
68
|
} = params;
|
|
65
69
|
const pair = quote.pair;
|
|
66
70
|
const fromAsset = this.chainService.getAssetBySlug(pair.from);
|
|
67
|
-
const toAsset = this.chainService.getAssetBySlug(pair.to);
|
|
68
71
|
const chainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
|
|
69
72
|
const toChainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
|
|
70
|
-
const chainType = _isChainSubstrateCompatible(chainInfo) ? ChainType.SUBSTRATE : ChainType.EVM;
|
|
73
|
+
const chainType = _isChainSubstrateCompatible(chainInfo) ? ChainType.SUBSTRATE : _isPureBitcoinChain(chainInfo) ? ChainType.BITCOIN : ChainType.EVM; // todo: improve throw error for unknown chain
|
|
71
74
|
const receiver = _reformatAddressWithChain(recipient !== null && recipient !== void 0 ? recipient : address, toChainInfo);
|
|
72
|
-
const fromAssetId = _getAssetSymbol(fromAsset);
|
|
73
|
-
const toAssetId = _getAssetSymbol(toAsset);
|
|
74
75
|
const minReceive = new BigNumber(quote.rate).times(1 - slippage).toString();
|
|
75
|
-
const processMetadata =
|
|
76
|
+
const processMetadata = process.steps[currentStep].metadata;
|
|
76
77
|
const quoteMetadata = processMetadata;
|
|
78
|
+
const fromAssetId = quoteMetadata.fromAssetId;
|
|
79
|
+
const toAssetId = quoteMetadata.toAssetId;
|
|
77
80
|
if (!processMetadata || !quoteMetadata) {
|
|
78
81
|
throw new Error('Metadata for Chainflip not found');
|
|
79
82
|
}
|
|
@@ -106,6 +109,7 @@ export class ChainflipSwapHandler {
|
|
|
106
109
|
method: 'GET'
|
|
107
110
|
}, this.isTestnet);
|
|
108
111
|
const data = await response.json();
|
|
112
|
+
console.log('Chainflip channel info:', data);
|
|
109
113
|
if (!data.id || !data.address || data.address === '' || !data.issuedBlock || !data.network || !data.channelId) {
|
|
110
114
|
throw new Error('Error get Chainflip data');
|
|
111
115
|
}
|
|
@@ -114,17 +118,17 @@ export class ChainflipSwapHandler {
|
|
|
114
118
|
const txData = {
|
|
115
119
|
address,
|
|
116
120
|
provider: this.providerInfo,
|
|
117
|
-
quote
|
|
118
|
-
slippage
|
|
121
|
+
quote,
|
|
122
|
+
slippage,
|
|
119
123
|
recipient,
|
|
120
|
-
depositChannelId
|
|
121
|
-
depositAddress
|
|
122
|
-
process
|
|
124
|
+
depositChannelId,
|
|
125
|
+
depositAddress,
|
|
126
|
+
process
|
|
123
127
|
};
|
|
124
128
|
let extrinsic;
|
|
125
129
|
if (chainType === ChainType.SUBSTRATE) {
|
|
126
|
-
const
|
|
127
|
-
const substrateApi = await
|
|
130
|
+
const _substrateApi = this.chainService.getSubstrateApi(chainInfo.slug);
|
|
131
|
+
const substrateApi = await _substrateApi.isReady;
|
|
128
132
|
const [submittableExtrinsic] = await createSubstrateExtrinsic({
|
|
129
133
|
from: address,
|
|
130
134
|
networkKey: chainInfo.slug,
|
|
@@ -136,9 +140,8 @@ export class ChainflipSwapHandler {
|
|
|
136
140
|
value: quote.fromAmount
|
|
137
141
|
});
|
|
138
142
|
extrinsic = submittableExtrinsic;
|
|
139
|
-
} else {
|
|
140
|
-
const
|
|
141
|
-
const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee(id, chainInfo.slug, 'evm');
|
|
143
|
+
} else if (chainType === ChainType.EVM) {
|
|
144
|
+
const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee(getId(), chainInfo.slug, 'evm');
|
|
142
145
|
if (_isNativeToken(fromAsset)) {
|
|
143
146
|
const [transactionConfig] = await getEVMTransactionObject({
|
|
144
147
|
chain: chainInfo.slug,
|
|
@@ -163,6 +166,24 @@ export class ChainflipSwapHandler {
|
|
|
163
166
|
});
|
|
164
167
|
extrinsic = transactionConfig;
|
|
165
168
|
}
|
|
169
|
+
} else if (chainType === ChainType.BITCOIN) {
|
|
170
|
+
const bitcoinApi = this.chainService.getBitcoinApi(chainInfo.slug);
|
|
171
|
+
const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee(getId(), chainInfo.slug, 'bitcoin');
|
|
172
|
+
const network = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
|
|
173
|
+
const [transaction] = await createBitcoinTransaction({
|
|
174
|
+
bitcoinApi,
|
|
175
|
+
chain: chainInfo.slug,
|
|
176
|
+
from: address,
|
|
177
|
+
feeInfo,
|
|
178
|
+
to: depositAddress,
|
|
179
|
+
transferAll: false,
|
|
180
|
+
value: quote.fromAmount,
|
|
181
|
+
network
|
|
182
|
+
});
|
|
183
|
+
extrinsic = transaction;
|
|
184
|
+
} else {
|
|
185
|
+
// todo: update this when support new chainType rather than substrate, evm, bitcoin
|
|
186
|
+
throw new Error('Unknown swap chain type');
|
|
166
187
|
}
|
|
167
188
|
return {
|
|
168
189
|
txChain: fromAsset.originChain,
|
|
@@ -215,6 +236,8 @@ export class ChainflipSwapHandler {
|
|
|
215
236
|
receiver: _reformatAddressWithChain(params.request.recipient || params.request.address, destinationChain),
|
|
216
237
|
srcChain: metadata.srcChain,
|
|
217
238
|
destChain: metadata.destChain,
|
|
239
|
+
fromAssetId: metadata.fromAssetId,
|
|
240
|
+
toAssetId: metadata.toAssetId,
|
|
218
241
|
version: 2
|
|
219
242
|
}
|
|
220
243
|
};
|
package/types/swap/index.d.ts
CHANGED
package/utils/account/common.js
CHANGED
|
@@ -166,7 +166,7 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
166
166
|
case AccountChainType.CARDANO:
|
|
167
167
|
return [...BASE_TRANSFER_ACTIONS];
|
|
168
168
|
case AccountChainType.BITCOIN:
|
|
169
|
-
return [...BASE_TRANSFER_ACTIONS];
|
|
169
|
+
return [...BASE_TRANSFER_ACTIONS, ExtrinsicType.SWAP];
|
|
170
170
|
}
|
|
171
171
|
} else if (signMode === AccountSignMode.QR) {
|
|
172
172
|
switch (networkType) {
|