@subwallet/extension-base 1.3.22-0 → 1.3.24-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/background/KoniTypes.d.ts +77 -4
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/index.js +21 -4
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +57 -36
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +12 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -16
- package/cjs/koni/api/staking/index.js +3 -4
- package/cjs/koni/background/handlers/Extension.js +343 -185
- package/cjs/koni/background/handlers/State.js +17 -2
- package/cjs/koni/background/handlers/Tabs.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
- package/cjs/services/balance-service/index.js +4 -2
- package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
- package/cjs/services/balance-service/transfer/smart-contract.js +24 -3
- package/cjs/services/balance-service/transfer/token.js +4 -4
- package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
- package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
- package/cjs/services/chain-service/handler/TonApi.js +2 -5
- package/cjs/services/chain-service/index.js +40 -7
- package/cjs/services/chain-service/utils/index.js +40 -11
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/cjs/services/earning-service/service.js +6 -12
- package/cjs/services/fee-service/service.js +19 -8
- package/cjs/services/fee-service/utils/tokenPayFee.js +151 -0
- package/cjs/services/history-service/index.js +4 -6
- package/cjs/services/inapp-notification-service/index.js +12 -4
- package/cjs/services/keyring-service/context/account-context.js +17 -2
- package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
- package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
- package/cjs/services/keyring-service/utils.js +18 -0
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/cjs/services/request-service/index.js +22 -4
- package/cjs/services/setting-service/constants.js +10 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
- package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
- package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
- package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
- package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
- package/cjs/services/swap-service/index.js +31 -22
- package/cjs/services/swap-service/utils.js +21 -38
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +286 -26
- package/cjs/services/transaction-service/utils.js +5 -1
- package/cjs/types/account/info/keyring.js +12 -1
- package/cjs/types/fee/cardano.js +1 -0
- package/cjs/types/swap/index.js +7 -2
- package/cjs/utils/account/analyze.js +2 -1
- package/cjs/utils/account/common.js +29 -20
- package/cjs/utils/account/derive/info/solo.js +9 -4
- package/cjs/utils/account/derive/validate.js +36 -2
- package/cjs/utils/account/transform.js +38 -13
- package/cjs/utils/fee/transfer.js +87 -21
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/index.d.ts +6 -1
- package/constants/index.js +14 -1
- package/constants/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +33 -12
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +13 -3
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/crowdloan.js +3 -3
- package/koni/api/nft/index.js +10 -16
- package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
- package/koni/api/staking/index.js +4 -5
- package/koni/background/handlers/Extension.d.ts +9 -0
- package/koni/background/handlers/Extension.js +225 -69
- package/koni/background/handlers/State.d.ts +6 -2
- package/koni/background/handlers/State.js +18 -3
- package/koni/background/handlers/Tabs.js +1 -1
- package/package.json +76 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
- package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
- package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
- package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +23 -9
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
- package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
- package/services/balance-service/index.js +4 -2
- package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
- package/services/balance-service/transfer/cardano-transfer.js +114 -0
- package/services/balance-service/transfer/smart-contract.d.ts +4 -2
- package/services/balance-service/transfer/smart-contract.js +24 -3
- package/services/balance-service/transfer/token.d.ts +1 -1
- package/services/balance-service/transfer/token.js +2 -2
- package/services/chain-service/handler/CardanoApi.d.ts +38 -0
- package/services/chain-service/handler/CardanoApi.js +167 -0
- package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
- package/services/chain-service/handler/CardanoChainHandler.js +75 -0
- package/services/chain-service/handler/TonApi.js +3 -6
- package/services/chain-service/handler/types.d.ts +1 -0
- package/services/chain-service/index.d.ts +4 -1
- package/services/chain-service/index.js +41 -8
- package/services/chain-service/types.d.ts +9 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +32 -11
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/services/earning-service/service.js +8 -14
- package/services/fee-service/interfaces.d.ts +25 -0
- package/services/fee-service/service.js +19 -8
- package/services/fee-service/utils/tokenPayFee.d.ts +8 -0
- package/services/fee-service/utils/tokenPayFee.js +141 -0
- package/services/history-service/index.js +6 -8
- package/services/inapp-notification-service/index.d.ts +3 -4
- package/services/inapp-notification-service/index.js +14 -6
- package/services/keyring-service/context/account-context.d.ts +6 -2
- package/services/keyring-service/context/account-context.js +17 -2
- package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
- package/services/keyring-service/context/handlers/Derive.js +10 -8
- package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
- package/services/keyring-service/context/handlers/Migration.js +258 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/services/keyring-service/context/handlers/Secret.js +2 -2
- package/services/keyring-service/utils.d.ts +2 -0
- package/services/keyring-service/utils.js +11 -0
- package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
- package/services/request-service/handler/CardanoRequestHandler.js +163 -0
- package/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -1
- package/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/services/request-service/index.d.ts +7 -4
- package/services/request-service/index.js +21 -7
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
- package/services/storage-service/db-stores/InappNotification.js +6 -0
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
- package/services/swap-service/handler/asset-hub/handler.js +2 -61
- package/services/swap-service/handler/base-handler.d.ts +1 -4
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
- package/services/swap-service/handler/chainflip-handler.js +31 -280
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
- package/services/swap-service/handler/hydradx-handler.js +13 -180
- package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
- package/services/swap-service/handler/simpleswap-handler.js +5 -226
- package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
- package/services/swap-service/handler/uniswap-handler.js +323 -0
- package/services/swap-service/index.js +30 -22
- package/services/swap-service/utils.d.ts +1 -5
- package/services/swap-service/utils.js +7 -21
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +8 -2
- package/services/transaction-service/index.js +273 -17
- package/services/transaction-service/types.d.ts +7 -0
- package/services/transaction-service/utils.js +7 -2
- package/types/account/info/keyring.d.ts +4 -1
- package/types/account/info/keyring.js +9 -0
- package/types/account/info/proxy.d.ts +2 -0
- package/types/balance/index.d.ts +4 -1
- package/types/fee/base.d.ts +1 -1
- package/types/fee/cardano.d.ts +18 -0
- package/types/fee/cardano.js +1 -0
- package/types/fee/option.d.ts +1 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/swap/index.d.ts +11 -3
- package/types/swap/index.js +7 -2
- package/utils/account/analyze.js +2 -1
- package/utils/account/common.d.ts +11 -6
- package/utils/account/common.js +28 -19
- package/utils/account/derive/info/solo.js +10 -5
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +34 -1
- package/utils/account/transform.d.ts +2 -1
- package/utils/account/transform.js +37 -13
- package/utils/fee/transfer.d.ts +3 -2
- package/utils/fee/transfer.js +90 -24
- package/utils/index.js +4 -4
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/oldChainPrefix.json +1 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import * as csl from '@emurgo/cardano-serialization-lib-nodejs';
|
|
5
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
|
+
import { getAdaBelongUtxo, getCardanoTxFee, splitCardanoId } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/utils';
|
|
7
|
+
import { subwalletApiSdk } from '@subwallet/subwallet-api-sdk';
|
|
8
|
+
export async function createCardanoTransaction(params) {
|
|
9
|
+
var _tokenInfo$metadata;
|
|
10
|
+
const {
|
|
11
|
+
cardanoTtlOffset,
|
|
12
|
+
from,
|
|
13
|
+
networkKey,
|
|
14
|
+
to,
|
|
15
|
+
tokenInfo,
|
|
16
|
+
transferAll,
|
|
17
|
+
value
|
|
18
|
+
} = params;
|
|
19
|
+
const cardanoId = (_tokenInfo$metadata = tokenInfo.metadata) === null || _tokenInfo$metadata === void 0 ? void 0 : _tokenInfo$metadata.cardanoId;
|
|
20
|
+
const isNativeTransfer = tokenInfo.assetType === _AssetType.NATIVE;
|
|
21
|
+
const isSelfTransfer = from === to;
|
|
22
|
+
if (!cardanoId) {
|
|
23
|
+
throw new Error('Missing token policy id metadata');
|
|
24
|
+
}
|
|
25
|
+
const payload = await subwalletApiSdk.fetchUnsignedPayload({
|
|
26
|
+
tokenDecimals: params.tokenInfo.decimals || 0,
|
|
27
|
+
nativeTokenSymbol: params.nativeTokenInfo.symbol,
|
|
28
|
+
cardanoId,
|
|
29
|
+
from: params.from,
|
|
30
|
+
to: params.to,
|
|
31
|
+
value: params.value,
|
|
32
|
+
cardanoTtlOffset: params.cardanoTtlOffset
|
|
33
|
+
});
|
|
34
|
+
console.log('Build cardano payload successfully!', payload);
|
|
35
|
+
validatePayload(payload, params);
|
|
36
|
+
const fee = getCardanoTxFee(payload);
|
|
37
|
+
const adaBelongToCnaUtxo = isNativeTransfer || isSelfTransfer ? BigInt(0) : getAdaBelongUtxo(payload, to);
|
|
38
|
+
const tx = {
|
|
39
|
+
from,
|
|
40
|
+
to,
|
|
41
|
+
networkKey,
|
|
42
|
+
value,
|
|
43
|
+
transferAll,
|
|
44
|
+
cardanoTtlOffset,
|
|
45
|
+
estimateCardanoFee: (fee + adaBelongToCnaUtxo).toString(),
|
|
46
|
+
cardanoPayload: payload
|
|
47
|
+
};
|
|
48
|
+
return [tx, value];
|
|
49
|
+
}
|
|
50
|
+
function validatePayload(payload, params) {
|
|
51
|
+
var _params$tokenInfo$met;
|
|
52
|
+
const txInfo = JSON.parse(csl.Transaction.from_hex(payload).to_json());
|
|
53
|
+
const outputs = txInfo.body.outputs;
|
|
54
|
+
const cardanoId = (_params$tokenInfo$met = params.tokenInfo.metadata) === null || _params$tokenInfo$met === void 0 ? void 0 : _params$tokenInfo$met.cardanoId;
|
|
55
|
+
const assetType = params.tokenInfo.assetType;
|
|
56
|
+
const isSendSameAddress = params.from === params.to;
|
|
57
|
+
if (!cardanoId) {
|
|
58
|
+
throw new Error('Missing cardano id metadata');
|
|
59
|
+
}
|
|
60
|
+
const cardanoAssetMetadata = splitCardanoId(cardanoId);
|
|
61
|
+
if (isSendSameAddress) {
|
|
62
|
+
validateAllOutputsBelongToAddress(params.from, outputs);
|
|
63
|
+
validateExistOutputWithAmountSend(params.value, outputs, assetType, cardanoAssetMetadata);
|
|
64
|
+
} else {
|
|
65
|
+
const [outputsBelongToReceiver, outputsNotBelongToReceiver] = [outputs.filter(output => output.address === params.to), outputs.filter(output => output.address !== params.to)];
|
|
66
|
+
validateReceiverOutputsWithAmountSend(params.value, outputsBelongToReceiver, assetType, cardanoAssetMetadata);
|
|
67
|
+
validateAllOutputsBelongToAddress(params.from, outputsNotBelongToReceiver);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function validateAllOutputsBelongToAddress(address, outputs) {
|
|
71
|
+
const found = outputs.find(output => output.address !== address);
|
|
72
|
+
if (found) {
|
|
73
|
+
throw new Error('Transaction has invalid address information');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function validateExistOutputWithAmountSend(amount, outputs, assetType, cardanoAssetMetadata) {
|
|
77
|
+
if (assetType === _AssetType.NATIVE) {
|
|
78
|
+
const found = outputs.find(output => output.amount.coin === amount);
|
|
79
|
+
if (found) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
throw new Error('Transaction has invalid transfer amount information');
|
|
83
|
+
}
|
|
84
|
+
if (assetType === _AssetType.CIP26) {
|
|
85
|
+
const found = outputs.find(output => {
|
|
86
|
+
var _output$amount$multia;
|
|
87
|
+
return amount === ((_output$amount$multia = output.amount.multiasset[cardanoAssetMetadata.policyId]) === null || _output$amount$multia === void 0 ? void 0 : _output$amount$multia[cardanoAssetMetadata.nameHex]);
|
|
88
|
+
});
|
|
89
|
+
if (found) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
throw new Error('Transaction has invalid transfer amount information');
|
|
93
|
+
}
|
|
94
|
+
throw new Error('Invalid asset type!');
|
|
95
|
+
}
|
|
96
|
+
function validateReceiverOutputsWithAmountSend(amount, outputs, assetType, cardanoAssetMetadata) {
|
|
97
|
+
if (outputs.length !== 1) {
|
|
98
|
+
throw new Error('Transaction has invalid transfer amount information');
|
|
99
|
+
}
|
|
100
|
+
const receiverOutput = outputs[0];
|
|
101
|
+
if (assetType === _AssetType.NATIVE) {
|
|
102
|
+
if (receiverOutput.amount.coin === amount) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
throw new Error('Transaction has invalid transfer amount information');
|
|
106
|
+
}
|
|
107
|
+
if (assetType === _AssetType.CIP26) {
|
|
108
|
+
if (receiverOutput.amount.multiasset[cardanoAssetMetadata.policyId][cardanoAssetMetadata.nameHex] === amount) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
throw new Error('Transaction has invalid transfer amount information');
|
|
112
|
+
}
|
|
113
|
+
throw new Error('Invalid asset type!');
|
|
114
|
+
}
|
|
@@ -9,9 +9,10 @@ interface TransferEvmProps extends TransactionFee {
|
|
|
9
9
|
transferAll: boolean;
|
|
10
10
|
value: string;
|
|
11
11
|
evmApi: _EvmApi;
|
|
12
|
+
fallbackFee?: boolean;
|
|
12
13
|
}
|
|
13
|
-
export declare function getEVMTransactionObject({ chain, evmApi, feeCustom: _feeCustom, feeInfo: _feeInfo, feeOption, from, to, transferAll, value }: TransferEvmProps): Promise<[TransactionConfig, string]>;
|
|
14
|
-
export declare function getERC20TransactionObject({ assetAddress, evmApi, feeCustom: _feeCustom, feeInfo: _feeInfo, feeOption, from, to, transferAll, value }: TransferERC20Props): Promise<[TransactionConfig, string]>;
|
|
14
|
+
export declare function getEVMTransactionObject({ chain, evmApi, fallbackFee, feeCustom: _feeCustom, feeInfo: _feeInfo, feeOption, from, to, transferAll, value }: TransferEvmProps): Promise<[TransactionConfig, string, string]>;
|
|
15
|
+
export declare function getERC20TransactionObject({ assetAddress, chain, evmApi, fallbackFee, feeCustom: _feeCustom, feeInfo: _feeInfo, feeOption, from, to, transferAll, value }: TransferERC20Props): Promise<[TransactionConfig, string, string]>;
|
|
15
16
|
interface TransferERC20Props extends TransactionFee {
|
|
16
17
|
assetAddress: string;
|
|
17
18
|
chain: string;
|
|
@@ -21,6 +22,7 @@ interface TransferERC20Props extends TransactionFee {
|
|
|
21
22
|
to: string;
|
|
22
23
|
transferAll: boolean;
|
|
23
24
|
value: string;
|
|
25
|
+
fallbackFee?: boolean;
|
|
24
26
|
}
|
|
25
27
|
export declare function getERC721Transaction(web3Api: _EvmApi, chain: string, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string, _feeInfo: FeeInfo): Promise<TransactionConfig>;
|
|
26
28
|
export declare function getPSP34TransferExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null>;
|
|
@@ -12,6 +12,7 @@ import { t } from 'i18next';
|
|
|
12
12
|
export async function getEVMTransactionObject({
|
|
13
13
|
chain,
|
|
14
14
|
evmApi,
|
|
15
|
+
fallbackFee,
|
|
15
16
|
feeCustom: _feeCustom,
|
|
16
17
|
feeInfo: _feeInfo,
|
|
17
18
|
feeOption,
|
|
@@ -23,13 +24,22 @@ export async function getEVMTransactionObject({
|
|
|
23
24
|
const feeCustom = _feeCustom;
|
|
24
25
|
const feeInfo = _feeInfo;
|
|
25
26
|
const feeCombine = combineEthFee(feeInfo, feeOption, feeCustom);
|
|
27
|
+
let errorOnEstimateFee = '';
|
|
26
28
|
const transactionObject = {
|
|
27
29
|
to: to,
|
|
28
30
|
value: value,
|
|
29
31
|
from: from,
|
|
30
32
|
...feeCombine
|
|
31
33
|
};
|
|
32
|
-
const gasLimit = await evmApi.api.eth.estimateGas(transactionObject)
|
|
34
|
+
const gasLimit = await evmApi.api.eth.estimateGas(transactionObject).catch(e => {
|
|
35
|
+
console.log('Cannot estimate fee with native transfer on', chain, e);
|
|
36
|
+
if (fallbackFee) {
|
|
37
|
+
errorOnEstimateFee = e.message;
|
|
38
|
+
return 21000;
|
|
39
|
+
} else {
|
|
40
|
+
throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
|
|
41
|
+
}
|
|
42
|
+
});
|
|
33
43
|
transactionObject.gas = gasLimit;
|
|
34
44
|
let estimateFee;
|
|
35
45
|
if (feeCombine.maxFeePerGas) {
|
|
@@ -43,11 +53,13 @@ export async function getEVMTransactionObject({
|
|
|
43
53
|
const numberReplace = 18 - 12;
|
|
44
54
|
transactionObject.value = transactionObject.value.substring(0, transactionObject.value.length - 6) + new Array(numberReplace).fill('0').join('');
|
|
45
55
|
}
|
|
46
|
-
return [transactionObject, transactionObject.value.toString()];
|
|
56
|
+
return [transactionObject, transactionObject.value.toString(), errorOnEstimateFee];
|
|
47
57
|
}
|
|
48
58
|
export async function getERC20TransactionObject({
|
|
49
59
|
assetAddress,
|
|
60
|
+
chain,
|
|
50
61
|
evmApi,
|
|
62
|
+
fallbackFee,
|
|
51
63
|
feeCustom: _feeCustom,
|
|
52
64
|
feeInfo: _feeInfo,
|
|
53
65
|
feeOption,
|
|
@@ -60,6 +72,7 @@ export async function getERC20TransactionObject({
|
|
|
60
72
|
const feeCustom = _feeCustom;
|
|
61
73
|
let freeAmount = new BigN(0);
|
|
62
74
|
let transferValue = value;
|
|
75
|
+
let errorOnEstimateFee = '';
|
|
63
76
|
if (transferAll) {
|
|
64
77
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
65
78
|
const bal = await erc20Contract.methods.balanceOf(from).call();
|
|
@@ -74,6 +87,14 @@ export async function getERC20TransactionObject({
|
|
|
74
87
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
75
88
|
const gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
|
|
76
89
|
from
|
|
90
|
+
}).catch(e => {
|
|
91
|
+
console.log('Cannot estimate fee with token contract', assetAddress, chain, e);
|
|
92
|
+
if (fallbackFee) {
|
|
93
|
+
errorOnEstimateFee = e.message;
|
|
94
|
+
return 70000;
|
|
95
|
+
} else {
|
|
96
|
+
throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
|
|
97
|
+
}
|
|
77
98
|
});
|
|
78
99
|
const feeInfo = _feeInfo;
|
|
79
100
|
const feeCombine = combineEthFee(feeInfo, feeOption, feeCustom);
|
|
@@ -89,7 +110,7 @@ export async function getERC20TransactionObject({
|
|
|
89
110
|
transferValue = freeAmount.toFixed(0);
|
|
90
111
|
transactionObject.data = generateTransferData(to, transferValue);
|
|
91
112
|
}
|
|
92
|
-
return [transactionObject, transferValue];
|
|
113
|
+
return [transactionObject, transferValue, errorOnEstimateFee];
|
|
93
114
|
}
|
|
94
115
|
export async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId, _feeInfo) {
|
|
95
116
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
@@ -11,6 +11,6 @@ interface CreateTransferExtrinsicProps {
|
|
|
11
11
|
transferAll: boolean;
|
|
12
12
|
tokenInfo: _ChainAsset;
|
|
13
13
|
}
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const createSubstrateExtrinsic: ({ from, networkKey, substrateApi, to, tokenInfo, transferAll, value }: CreateTransferExtrinsicProps) => Promise<[SubmittableExtrinsic | null, string]>;
|
|
15
15
|
export declare const getTransferMockTxFee: (address: string, chainInfo: _ChainInfo, tokenInfo: _ChainAsset, api: _SubstrateApi | _EvmApi | _TonApi) => Promise<BigN>;
|
|
16
16
|
export {};
|
|
@@ -16,7 +16,7 @@ import { Address } from '@ton/ton';
|
|
|
16
16
|
import BigN from 'bignumber.js';
|
|
17
17
|
import { BN, u8aToHex } from '@polkadot/util';
|
|
18
18
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
19
|
-
export const
|
|
19
|
+
export const createSubstrateExtrinsic = async ({
|
|
20
20
|
from,
|
|
21
21
|
networkKey,
|
|
22
22
|
substrateApi,
|
|
@@ -148,7 +148,7 @@ export const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) =
|
|
|
148
148
|
var _paymentInfo$partialF;
|
|
149
149
|
const substrateApi = api;
|
|
150
150
|
const chainApi = await substrateApi.isReady;
|
|
151
|
-
const [mockTx] = await
|
|
151
|
+
const [mockTx] = await createSubstrateExtrinsic({
|
|
152
152
|
from: address,
|
|
153
153
|
networkKey: chainInfo.slug,
|
|
154
154
|
substrateApi: chainApi,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CardanoBalanceItem } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/types';
|
|
2
|
+
import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
3
|
+
import { _CardanoApi, _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
+
import { PromiseHandler } from '@subwallet/extension-base/utils';
|
|
5
|
+
import { BehaviorSubject } from 'rxjs';
|
|
6
|
+
export declare const API_KEY: {
|
|
7
|
+
mainnet: string;
|
|
8
|
+
testnet: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class CardanoApi implements _CardanoApi {
|
|
11
|
+
chainSlug: string;
|
|
12
|
+
apiUrl: string;
|
|
13
|
+
apiError?: string;
|
|
14
|
+
apiRetry: number;
|
|
15
|
+
readonly isApiConnectedSubject: BehaviorSubject<boolean>;
|
|
16
|
+
readonly connectionStatusSubject: BehaviorSubject<_ChainConnectionStatus>;
|
|
17
|
+
isApiReady: boolean;
|
|
18
|
+
isApiReadyOnce: boolean;
|
|
19
|
+
isReadyHandler: PromiseHandler<_CardanoApi>;
|
|
20
|
+
isTestnet: boolean;
|
|
21
|
+
private projectId;
|
|
22
|
+
providerName: string;
|
|
23
|
+
constructor(chainSlug: string, apiUrl: string, { isTestnet, providerName }: _ApiOptions);
|
|
24
|
+
get isApiConnected(): boolean;
|
|
25
|
+
get connectionStatus(): _ChainConnectionStatus;
|
|
26
|
+
private updateConnectionStatus;
|
|
27
|
+
get isReady(): Promise<_CardanoApi>;
|
|
28
|
+
updateApiUrl(apiUrl: string): Promise<void>;
|
|
29
|
+
recoverConnect(): Promise<void>;
|
|
30
|
+
connect(): void;
|
|
31
|
+
disconnect(): Promise<void>;
|
|
32
|
+
destroy(): Promise<void>;
|
|
33
|
+
onConnect(): void;
|
|
34
|
+
onDisconnect(): void;
|
|
35
|
+
getBalanceMap(address: string): Promise<CardanoBalanceItem[]>;
|
|
36
|
+
sendCardanoTxReturnHash(tx: string): Promise<string>;
|
|
37
|
+
getStatusByTxHash(txHash: string, ttl: number): Promise<boolean>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { cborToBytes, retryCardanoTxStatus } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/utils';
|
|
5
|
+
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
|
+
import { createPromiseHandler } from '@subwallet/extension-base/utils';
|
|
7
|
+
import { BehaviorSubject } from 'rxjs';
|
|
8
|
+
import { hexAddPrefix, isHex } from '@polkadot/util';
|
|
9
|
+
export const API_KEY = {
|
|
10
|
+
mainnet: process.env.BLOCKFROST_API_KEY_MAIN || '',
|
|
11
|
+
testnet: process.env.BLOCKFROST_API_KEY_PREP || ''
|
|
12
|
+
};
|
|
13
|
+
export class CardanoApi {
|
|
14
|
+
// private api: BlockFrostAPI;
|
|
15
|
+
|
|
16
|
+
apiRetry = 0;
|
|
17
|
+
isApiConnectedSubject = new BehaviorSubject(false);
|
|
18
|
+
connectionStatusSubject = new BehaviorSubject(_ChainConnectionStatus.DISCONNECTED);
|
|
19
|
+
isApiReady = false;
|
|
20
|
+
isApiReadyOnce = false;
|
|
21
|
+
constructor(chainSlug, apiUrl, {
|
|
22
|
+
isTestnet,
|
|
23
|
+
providerName
|
|
24
|
+
}) {
|
|
25
|
+
this.chainSlug = chainSlug;
|
|
26
|
+
this.apiUrl = apiUrl;
|
|
27
|
+
this.isTestnet = isTestnet !== null && isTestnet !== void 0 ? isTestnet : true;
|
|
28
|
+
this.projectId = isTestnet ? API_KEY.testnet : API_KEY.mainnet;
|
|
29
|
+
this.providerName = providerName || 'unknown';
|
|
30
|
+
// this.api = this.createProvider(isTestnet);
|
|
31
|
+
this.isReadyHandler = createPromiseHandler();
|
|
32
|
+
this.connect();
|
|
33
|
+
}
|
|
34
|
+
get isApiConnected() {
|
|
35
|
+
return this.isApiConnectedSubject.getValue();
|
|
36
|
+
}
|
|
37
|
+
get connectionStatus() {
|
|
38
|
+
return this.connectionStatusSubject.getValue();
|
|
39
|
+
}
|
|
40
|
+
updateConnectionStatus(status) {
|
|
41
|
+
const isConnected = status === _ChainConnectionStatus.CONNECTED;
|
|
42
|
+
if (isConnected !== this.isApiConnectedSubject.value) {
|
|
43
|
+
this.isApiConnectedSubject.next(isConnected);
|
|
44
|
+
}
|
|
45
|
+
if (status !== this.connectionStatusSubject.value) {
|
|
46
|
+
this.connectionStatusSubject.next(status);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
get isReady() {
|
|
50
|
+
return this.isReadyHandler.promise;
|
|
51
|
+
}
|
|
52
|
+
async updateApiUrl(apiUrl) {
|
|
53
|
+
if (this.apiUrl === apiUrl) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
await this.disconnect();
|
|
57
|
+
this.apiUrl = apiUrl;
|
|
58
|
+
// this.api = this.createProvider();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async recoverConnect() {
|
|
62
|
+
await this.disconnect();
|
|
63
|
+
this.connect();
|
|
64
|
+
await this.isReadyHandler.promise;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// private createProvider (isTestnet = true): BlockFrostAPI {
|
|
68
|
+
// const projectId = isTestnet ? API_KEY.testnet : API_KEY.mainnet;
|
|
69
|
+
//
|
|
70
|
+
// return new BlockFrostAPI({
|
|
71
|
+
// projectId
|
|
72
|
+
// });
|
|
73
|
+
// }
|
|
74
|
+
|
|
75
|
+
connect() {
|
|
76
|
+
this.updateConnectionStatus(_ChainConnectionStatus.CONNECTING);
|
|
77
|
+
// There isn't a persistent network connection underlying TonClient. Cant check connection status.
|
|
78
|
+
// this.isApiReadyOnce = true;
|
|
79
|
+
this.onConnect();
|
|
80
|
+
}
|
|
81
|
+
async disconnect() {
|
|
82
|
+
this.onDisconnect();
|
|
83
|
+
this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
|
|
84
|
+
return Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
// Todo: implement this in the future
|
|
88
|
+
return this.disconnect();
|
|
89
|
+
}
|
|
90
|
+
onConnect() {
|
|
91
|
+
if (!this.isApiConnected) {
|
|
92
|
+
console.log(`Connected to ${this.chainSlug} at ${this.apiUrl}`);
|
|
93
|
+
this.isApiReady = true;
|
|
94
|
+
if (this.isApiReadyOnce) {
|
|
95
|
+
this.isReadyHandler.resolve(this);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this.updateConnectionStatus(_ChainConnectionStatus.CONNECTED);
|
|
99
|
+
}
|
|
100
|
+
onDisconnect() {
|
|
101
|
+
this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
|
|
102
|
+
if (this.isApiConnected) {
|
|
103
|
+
console.warn(`Disconnected from ${this.chainSlug} of ${this.apiUrl}`);
|
|
104
|
+
this.isApiReady = false;
|
|
105
|
+
this.isReadyHandler = createPromiseHandler();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async getBalanceMap(address) {
|
|
109
|
+
try {
|
|
110
|
+
const url = this.isTestnet ? `https://cardano-preprod.blockfrost.io/api/v0/addresses/${address}` : `https://cardano-mainnet.blockfrost.io/api/v0/addresses/${address}`;
|
|
111
|
+
const response = await fetch(url, {
|
|
112
|
+
method: 'GET',
|
|
113
|
+
headers: {
|
|
114
|
+
Project_id: this.projectId
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const addressBalance = await response.json();
|
|
118
|
+
return addressBalance.amount;
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error('Error on getting account balance', e);
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async sendCardanoTxReturnHash(tx) {
|
|
125
|
+
try {
|
|
126
|
+
const url = this.isTestnet ? 'https://cardano-preprod.blockfrost.io/api/v0/tx/submit' : 'https://cardano-mainnet.blockfrost.io/api/v0/tx/submit';
|
|
127
|
+
const response = await fetch(url, {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
headers: {
|
|
130
|
+
Project_id: this.projectId,
|
|
131
|
+
'Content-Type': 'application/cbor'
|
|
132
|
+
},
|
|
133
|
+
body: cborToBytes(tx)
|
|
134
|
+
});
|
|
135
|
+
const hash = (await response.text()).replace(/^"|"$/g, '');
|
|
136
|
+
if (isHex(hexAddPrefix(hash))) {
|
|
137
|
+
return hash;
|
|
138
|
+
} else {
|
|
139
|
+
console.error('Error on submitting cardano tx');
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
} catch (e) {
|
|
143
|
+
console.error('Error on submitting cardano tx', e);
|
|
144
|
+
return '';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async getStatusByTxHash(txHash, ttl) {
|
|
148
|
+
const cronTime = 30000;
|
|
149
|
+
return retryCardanoTxStatus(async () => {
|
|
150
|
+
const url = this.isTestnet ? `https://cardano-preprod.blockfrost.io/api/v0/txs/${txHash}` : `https://cardano-mainnet.blockfrost.io/api/v0/txs/${txHash}`;
|
|
151
|
+
const response = await fetch(url, {
|
|
152
|
+
method: 'GET',
|
|
153
|
+
headers: {
|
|
154
|
+
Project_id: this.projectId
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const txInfo = await response.json();
|
|
158
|
+
if (txInfo.block && txInfo.hash && txInfo.index >= 0) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
throw new Error('Transaction not found');
|
|
162
|
+
}, {
|
|
163
|
+
retries: ttl / cronTime,
|
|
164
|
+
delay: cronTime
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
2
|
+
import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler';
|
|
3
|
+
import { CardanoApi } from '@subwallet/extension-base/services/chain-service/handler/CardanoApi';
|
|
4
|
+
import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
5
|
+
export declare class CardanoChainHandler extends AbstractChainHandler {
|
|
6
|
+
private cardanoApiMap;
|
|
7
|
+
constructor(parent?: ChainService);
|
|
8
|
+
getCardanoApiMap(): Record<string, CardanoApi>;
|
|
9
|
+
getCardanoApiByChain(chain: string): CardanoApi;
|
|
10
|
+
getApiByChain(chain: string): CardanoApi;
|
|
11
|
+
setCardanoApi(chain: string, cardanoApi: CardanoApi): void;
|
|
12
|
+
initApi(chainSlug: string, apiUrl: string, { isTestnet, onUpdateStatus, providerName }?: Omit<_ApiOptions, 'metadata'>): Promise<CardanoApi>;
|
|
13
|
+
recoverApi(chain: string): Promise<void>;
|
|
14
|
+
destroyCardanoApi(chain: string): void;
|
|
15
|
+
sleep(): Promise<void>;
|
|
16
|
+
wakeUp(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler';
|
|
5
|
+
import { CardanoApi } from '@subwallet/extension-base/services/chain-service/handler/CardanoApi';
|
|
6
|
+
export class CardanoChainHandler extends AbstractChainHandler {
|
|
7
|
+
cardanoApiMap = {};
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line no-useless-constructor
|
|
10
|
+
constructor(parent) {
|
|
11
|
+
super(parent);
|
|
12
|
+
}
|
|
13
|
+
getCardanoApiMap() {
|
|
14
|
+
return this.cardanoApiMap;
|
|
15
|
+
}
|
|
16
|
+
getCardanoApiByChain(chain) {
|
|
17
|
+
return this.cardanoApiMap[chain];
|
|
18
|
+
}
|
|
19
|
+
getApiByChain(chain) {
|
|
20
|
+
return this.getCardanoApiByChain(chain);
|
|
21
|
+
}
|
|
22
|
+
setCardanoApi(chain, cardanoApi) {
|
|
23
|
+
this.cardanoApiMap[chain] = cardanoApi;
|
|
24
|
+
}
|
|
25
|
+
async initApi(chainSlug, apiUrl, {
|
|
26
|
+
isTestnet,
|
|
27
|
+
onUpdateStatus,
|
|
28
|
+
providerName
|
|
29
|
+
} = {}) {
|
|
30
|
+
const existed = this.getCardanoApiByChain(chainSlug);
|
|
31
|
+
if (existed) {
|
|
32
|
+
existed.connect();
|
|
33
|
+
if (apiUrl !== existed.apiUrl) {
|
|
34
|
+
existed.updateApiUrl(apiUrl).catch(console.error);
|
|
35
|
+
}
|
|
36
|
+
return existed;
|
|
37
|
+
}
|
|
38
|
+
const apiObject = new CardanoApi(chainSlug, apiUrl, {
|
|
39
|
+
isTestnet,
|
|
40
|
+
providerName
|
|
41
|
+
});
|
|
42
|
+
apiObject.connectionStatusSubject.subscribe(this.handleConnection.bind(this, chainSlug));
|
|
43
|
+
apiObject.connectionStatusSubject.subscribe(onUpdateStatus);
|
|
44
|
+
return Promise.resolve(apiObject);
|
|
45
|
+
}
|
|
46
|
+
async recoverApi(chain) {
|
|
47
|
+
const existed = this.getCardanoApiByChain(chain);
|
|
48
|
+
if (existed && !existed.isApiReadyOnce) {
|
|
49
|
+
console.log(`Reconnect ${existed.providerName || existed.chainSlug} at ${existed.apiUrl}`);
|
|
50
|
+
return existed.recoverConnect();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
destroyCardanoApi(chain) {
|
|
54
|
+
const cardanoApi = this.getCardanoApiByChain(chain);
|
|
55
|
+
cardanoApi === null || cardanoApi === void 0 ? void 0 : cardanoApi.destroy().catch(console.error);
|
|
56
|
+
}
|
|
57
|
+
async sleep() {
|
|
58
|
+
this.isSleeping = true;
|
|
59
|
+
this.cancelAllRecover();
|
|
60
|
+
await Promise.all(Object.values(this.getCardanoApiMap()).map(cardanoApi => {
|
|
61
|
+
return cardanoApi.disconnect().catch(console.error);
|
|
62
|
+
}));
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
}
|
|
65
|
+
wakeUp() {
|
|
66
|
+
var _this$parent;
|
|
67
|
+
this.isSleeping = false;
|
|
68
|
+
const activeChains = ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.getActiveChains()) || [];
|
|
69
|
+
for (const chain of activeChains) {
|
|
70
|
+
const cardanoApi = this.getCardanoApiByChain(chain);
|
|
71
|
+
cardanoApi === null || cardanoApi === void 0 ? void 0 : cardanoApi.connect();
|
|
72
|
+
}
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { TON_CENTER_API_KEY, TON_OPCODES } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/consts';
|
|
6
|
-
import { getJettonTxStatus,
|
|
6
|
+
import { getJettonTxStatus, retryTonTxStatus } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
7
7
|
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
8
8
|
import { createPromiseHandler } from '@subwallet/extension-base/utils';
|
|
9
9
|
import { TonClient } from '@ton/ton';
|
|
@@ -50,10 +50,7 @@ export class TonApi {
|
|
|
50
50
|
|
|
51
51
|
// Create new provider and api
|
|
52
52
|
this.apiUrl = apiUrl;
|
|
53
|
-
this.api =
|
|
54
|
-
endpoint: this.getJsonRpc(this.apiUrl),
|
|
55
|
-
apiKey: TON_CENTER_API_KEY
|
|
56
|
-
});
|
|
53
|
+
this.api = this.createProvider(apiUrl);
|
|
57
54
|
}
|
|
58
55
|
async recoverConnect() {
|
|
59
56
|
await this.disconnect();
|
|
@@ -155,7 +152,7 @@ export class TonApi {
|
|
|
155
152
|
return await resp.json();
|
|
156
153
|
}
|
|
157
154
|
async getStatusByExtMsgHash(extMsgHash, extrinsicType) {
|
|
158
|
-
return
|
|
155
|
+
return retryTonTxStatus(async () => {
|
|
159
156
|
var _externalTxInfo$out_m, _externalTxInfo$out_m2;
|
|
160
157
|
// retry many times to get transaction status and transaction hex
|
|
161
158
|
const externalTxInfoRaw = await this.getTxByInMsg(extMsgHash);
|
|
@@ -22,6 +22,7 @@ export interface _ApiOptions {
|
|
|
22
22
|
metadata?: MetadataItem;
|
|
23
23
|
onUpdateStatus?: (status: _ChainConnectionStatus) => void;
|
|
24
24
|
externalApiPromise?: ApiPromise;
|
|
25
|
+
isTestnet?: boolean;
|
|
25
26
|
}
|
|
26
27
|
export declare enum _CHAIN_VALIDATION_ERROR {
|
|
27
28
|
INVALID_INFO_TYPE = "invalidInfoType",
|
|
@@ -17,6 +17,7 @@ export declare class ChainService {
|
|
|
17
17
|
private substrateChainHandler;
|
|
18
18
|
private evmChainHandler;
|
|
19
19
|
private tonChainHandler;
|
|
20
|
+
private cardanoChainHandler;
|
|
20
21
|
private mantaChainHandler;
|
|
21
22
|
refreshLatestChainDataTimeOut: NodeJS.Timer | undefined;
|
|
22
23
|
get mantaPay(): MantaPrivateHandler | undefined;
|
|
@@ -54,6 +55,8 @@ export declare class ChainService {
|
|
|
54
55
|
getSubstrateApiMap(): Record<string, _SubstrateApi>;
|
|
55
56
|
getTonApi(slug: string): import("./handler/TonApi").TonApi;
|
|
56
57
|
getTonApiMap(): Record<string, import("./handler/TonApi").TonApi>;
|
|
58
|
+
getCardanoApi(slug: string): import("./handler/CardanoApi").CardanoApi;
|
|
59
|
+
getCardanoApiMap(): Record<string, import("./handler/CardanoApi").CardanoApi>;
|
|
57
60
|
getChainCurrentProviderByKey(slug: string): {
|
|
58
61
|
endpoint: string;
|
|
59
62
|
providerName: string;
|
|
@@ -69,6 +72,7 @@ export declare class ChainService {
|
|
|
69
72
|
getMultiChainAssetMap(): Record<string, _MultiChainAsset>;
|
|
70
73
|
getSmartContractTokens(): Record<string, _ChainAsset>;
|
|
71
74
|
getAssetHubToken(): Record<string, _ChainAsset>;
|
|
75
|
+
getHydrationAssetIdMap(chain: string): Record<string, string>;
|
|
72
76
|
getChainInfoMap(): Record<string, _ChainInfo>;
|
|
73
77
|
setChainInfoMap(chainInfoMap: Record<string, _ChainInfo>): void;
|
|
74
78
|
getEvmChainInfoMap(): Record<string, _ChainInfo>;
|
|
@@ -142,7 +146,6 @@ export declare class ChainService {
|
|
|
142
146
|
private generateSlugForNativeToken;
|
|
143
147
|
refreshSubstrateApi(slug: string): void;
|
|
144
148
|
refreshEvmApi(slug: string): void;
|
|
145
|
-
refreshTonApi(slug: string): void;
|
|
146
149
|
stopAllChainApis(): Promise<void>;
|
|
147
150
|
resumeAllChainApis(): Promise<void>;
|
|
148
151
|
initAssetSettings(): Promise<void>;
|