@subwallet/extension-base 1.2.8-1 → 1.2.10-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 +7 -3
- package/background/KoniTypes.js +1 -1
- package/cjs/background/KoniTypes.js +1 -1
- package/cjs/core/logic-validation/transfer.js +22 -2
- package/cjs/core/substrate/foreign-asset-pallet.js +16 -0
- package/cjs/core/substrate/xcm-parser.js +26 -4
- package/cjs/koni/api/contract-handler/evm/web3.js +58 -0
- package/cjs/{services/chain-service/helper → koni/api/contract-handler/utils}/index.js +19 -2
- package/cjs/koni/api/contract-handler/wasm/index.js +49 -0
- package/cjs/koni/api/nft/evm_nft/index.js +6 -6
- package/cjs/koni/api/nft/wasm_nft/index.js +16 -16
- package/cjs/koni/api/yield/helper/utils.js +1 -22
- package/cjs/koni/background/handlers/Extension.js +128 -64
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/index.js +11 -0
- package/cjs/services/balance-service/helpers/process.js +50 -0
- package/cjs/services/balance-service/helpers/subscribe/evm.js +11 -3
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +10 -24
- package/cjs/services/balance-service/index.js +20 -0
- package/cjs/{koni/api/tokens/evm/transfer.js → services/balance-service/transfer/smart-contract.js} +33 -38
- package/cjs/{koni/api/dotsama/transfer.js → services/balance-service/transfer/token.js} +3 -3
- package/cjs/{koni/api → services/balance-service/transfer}/xcm/index.js +26 -6
- package/cjs/{koni/api → services/balance-service/transfer}/xcm/polkadotXcm.js +2 -2
- package/cjs/services/balance-service/transfer/xcm/snowBridge.js +60 -0
- package/cjs/{koni/api → services/balance-service/transfer}/xcm/xTokens.js +1 -1
- package/cjs/{koni/api → services/balance-service/transfer}/xcm/xcmPallet.js +1 -1
- package/cjs/services/chain-service/handler/EvmChainHandler.js +3 -3
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +4 -4
- package/cjs/services/chain-service/health-check/utils/asset-info.js +18 -18
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +16 -35
- package/cjs/services/earning-service/handlers/special.js +1 -1
- package/cjs/services/history-service/subscan-history.js +1 -1
- package/cjs/services/swap-service/handler/base-handler.js +3 -2
- package/cjs/services/swap-service/handler/chainflip-handler.js +10 -9
- package/cjs/services/swap-service/handler/hydradx-handler.js +12 -11
- package/cjs/services/swap-service/index.js +3 -2
- package/cjs/services/swap-service/utils.js +1 -13
- package/cjs/services/transaction-service/index.js +2 -2
- package/cjs/types/service-base.js +30 -1
- package/cjs/types/swap/index.js +0 -4
- package/cjs/utils/eth/parseTransaction/index.js +10 -10
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +22 -3
- package/core/substrate/foreign-asset-pallet.d.ts +8 -0
- package/core/substrate/foreign-asset-pallet.js +9 -0
- package/core/substrate/xcm-parser.d.ts +3 -1
- package/core/substrate/xcm-parser.js +25 -5
- package/koni/api/contract-handler/evm/web3.d.ts +8 -0
- package/koni/api/contract-handler/evm/web3.js +45 -0
- package/{services/chain-service/helper → koni/api/contract-handler/utils}/index.d.ts +4 -0
- package/{services/chain-service/helper → koni/api/contract-handler/utils}/index.js +15 -1
- package/koni/api/contract-handler/utils/snowbridge_gateway_abi.json +1122 -0
- package/koni/api/{tokens → contract-handler}/wasm/index.d.ts +0 -2
- package/koni/api/{tokens → contract-handler}/wasm/index.js +1 -25
- package/koni/api/nft/evm_nft/index.js +1 -1
- package/koni/api/nft/wasm_nft/index.js +2 -2
- package/koni/api/yield/helper/utils.d.ts +1 -5
- package/koni/api/yield/helper/utils.js +0 -16
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +82 -18
- package/package.json +85 -79
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/index.d.ts +1 -0
- package/services/balance-service/helpers/index.js +2 -1
- package/services/balance-service/helpers/process.d.ts +13 -0
- package/services/balance-service/helpers/process.js +43 -0
- package/services/balance-service/helpers/subscribe/evm.js +11 -3
- package/services/balance-service/helpers/subscribe/substrate/index.js +11 -25
- package/services/balance-service/index.d.ts +3 -0
- package/services/balance-service/index.js +21 -1
- package/services/balance-service/transfer/smart-contract.d.ts +7 -0
- package/{koni/api/tokens/evm/transfer.js → services/balance-service/transfer/smart-contract.js} +28 -31
- package/{koni/api/dotsama/transfer.js → services/balance-service/transfer/token.js} +4 -4
- package/{koni/api → services/balance-service/transfer}/xcm/index.d.ts +9 -3
- package/{koni/api → services/balance-service/transfer}/xcm/index.js +21 -3
- package/{koni/api → services/balance-service/transfer}/xcm/polkadotXcm.js +3 -3
- package/services/balance-service/transfer/xcm/snowBridge.d.ts +4 -0
- package/services/balance-service/transfer/xcm/snowBridge.js +54 -0
- package/{koni/api → services/balance-service/transfer}/xcm/xTokens.js +1 -1
- package/{koni/api → services/balance-service/transfer}/xcm/xcmPallet.js +1 -1
- package/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +2 -2
- package/services/chain-service/health-check/utils/asset-info.js +3 -3
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +16 -35
- package/services/earning-service/handlers/special.js +1 -1
- package/services/history-service/subscan-history.js +1 -1
- package/services/swap-service/handler/base-handler.d.ts +5 -5
- package/services/swap-service/handler/base-handler.js +4 -3
- package/services/swap-service/handler/chainflip-handler.d.ts +4 -4
- package/services/swap-service/handler/chainflip-handler.js +7 -6
- package/services/swap-service/handler/hydradx-handler.d.ts +6 -6
- package/services/swap-service/handler/hydradx-handler.js +12 -11
- package/services/swap-service/index.d.ts +3 -2
- package/services/swap-service/index.js +4 -3
- package/services/swap-service/utils.d.ts +1 -3
- package/services/swap-service/utils.js +1 -11
- package/services/transaction-service/index.js +2 -2
- package/types/service-base.d.ts +31 -3
- package/types/service-base.js +23 -1
- package/types/swap/index.d.ts +8 -30
- package/types/swap/index.js +0 -4
- package/types/yield/actions/join/submit.d.ts +7 -4
- package/utils/eth/parseTransaction/index.js +1 -1
- package/cjs/koni/api/tokens/evm/balance.js +0 -18
- package/cjs/koni/api/tokens/evm/web3.js +0 -17
- package/cjs/koni/api/tokens/index.js +0 -17
- package/cjs/koni/api/tokens/wasm/index.js +0 -74
- package/koni/api/tokens/evm/balance.d.ts +0 -2
- package/koni/api/tokens/evm/balance.js +0 -12
- package/koni/api/tokens/evm/transfer.d.ts +0 -17
- package/koni/api/tokens/evm/web3.d.ts +0 -3
- package/koni/api/tokens/evm/web3.js +0 -9
- package/koni/api/tokens/index.d.ts +0 -1
- package/koni/api/tokens/index.js +0 -11
- /package/cjs/koni/api/{tokens → contract-handler}/wasm/utils.js +0 -0
- /package/cjs/{koni/api → services/balance-service/transfer}/xcm/utils.js +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/azero_domain_registry_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/erc20_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/erc721_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/neuroguns_psp34_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/pink_psp34_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/psp22_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/psp34_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/test_erc721_abi.json +0 -0
- /package/koni/api/{tokens → contract-handler}/wasm/utils.d.ts +0 -0
- /package/koni/api/{tokens → contract-handler}/wasm/utils.js +0 -0
- /package/{koni/api/dotsama/transfer.d.ts → services/balance-service/transfer/token.d.ts} +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/polkadotXcm.d.ts +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/utils.d.ts +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/utils.js +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/xTokens.d.ts +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/xcmPallet.d.ts +0 -0
|
@@ -14,21 +14,23 @@ var _subscriptions = require("@subwallet/extension-base/background/handlers/subs
|
|
|
14
14
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
15
15
|
var _constants = require("@subwallet/extension-base/constants");
|
|
16
16
|
var _transfer = require("@subwallet/extension-base/core/logic-validation/transfer");
|
|
17
|
+
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
17
18
|
var _defaults = require("@subwallet/extension-base/defaults");
|
|
19
|
+
var _web = require("@subwallet/extension-base/koni/api/contract-handler/evm/web3");
|
|
20
|
+
var _utils = require("@subwallet/extension-base/koni/api/contract-handler/utils");
|
|
18
21
|
var _domain = require("@subwallet/extension-base/koni/api/dotsama/domain");
|
|
19
22
|
var _parseTransaction = require("@subwallet/extension-base/koni/api/dotsama/parseTransaction");
|
|
20
|
-
var _transfer2 = require("@subwallet/extension-base/koni/api/
|
|
21
|
-
var _transfer3 = require("@subwallet/extension-base/koni/api/nft/transfer");
|
|
23
|
+
var _transfer2 = require("@subwallet/extension-base/koni/api/nft/transfer");
|
|
22
24
|
var _bonding = require("@subwallet/extension-base/koni/api/staking/bonding");
|
|
23
25
|
var _paraChain = require("@subwallet/extension-base/koni/api/staking/bonding/paraChain");
|
|
24
26
|
var _relayChain = require("@subwallet/extension-base/koni/api/staking/bonding/relayChain");
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
27
|
+
var _utils2 = require("@subwallet/extension-base/koni/api/yield/helper/utils");
|
|
28
|
+
var _smartContract = require("@subwallet/extension-base/services/balance-service/transfer/smart-contract");
|
|
29
|
+
var _token = require("@subwallet/extension-base/services/balance-service/transfer/token");
|
|
30
|
+
var _xcm = require("@subwallet/extension-base/services/balance-service/transfer/xcm");
|
|
29
31
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
30
32
|
var _types = require("@subwallet/extension-base/services/chain-service/types");
|
|
31
|
-
var
|
|
33
|
+
var _utils3 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
32
34
|
var _constants3 = require("@subwallet/extension-base/services/request-service/constants");
|
|
33
35
|
var _constants4 = require("@subwallet/extension-base/services/setting-service/constants");
|
|
34
36
|
var _constants5 = require("@subwallet/extension-base/services/wallet-connect-service/constants");
|
|
@@ -36,11 +38,11 @@ var _helpers2 = require("@subwallet/extension-base/services/wallet-connect-servi
|
|
|
36
38
|
var _storage = require("@subwallet/extension-base/storage");
|
|
37
39
|
var _stores = require("@subwallet/extension-base/stores");
|
|
38
40
|
var _types2 = require("@subwallet/extension-base/types");
|
|
39
|
-
var
|
|
41
|
+
var _utils4 = require("@subwallet/extension-base/utils");
|
|
40
42
|
var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
41
43
|
var _keyring = require("@subwallet/keyring");
|
|
42
44
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
43
|
-
var
|
|
45
|
+
var _utils5 = require("@walletconnect/utils");
|
|
44
46
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
45
47
|
var _i18next = require("i18next");
|
|
46
48
|
var _rxjs = require("rxjs");
|
|
@@ -565,7 +567,7 @@ class KoniExtension {
|
|
|
565
567
|
const _cb = (0, _subscriptions.createSubscription)(id, port);
|
|
566
568
|
let old = '';
|
|
567
569
|
const subscription = this.#koniState.keyringService.addressesSubject.subscribe(subjectInfo => {
|
|
568
|
-
const addresses = (0,
|
|
570
|
+
const addresses = (0, _utils4.convertSubjectInfoToAddresses)(subjectInfo);
|
|
569
571
|
const _new = JSON.stringify(addresses);
|
|
570
572
|
if (old !== _new) {
|
|
571
573
|
_cb({
|
|
@@ -580,7 +582,7 @@ class KoniExtension {
|
|
|
580
582
|
});
|
|
581
583
|
const subjectInfo = this.#koniState.keyringService.addresses;
|
|
582
584
|
return {
|
|
583
|
-
addresses: (0,
|
|
585
|
+
addresses: (0, _utils4.convertSubjectInfoToAddresses)(subjectInfo)
|
|
584
586
|
};
|
|
585
587
|
}
|
|
586
588
|
saveRecentAccount(_ref22) {
|
|
@@ -589,7 +591,7 @@ class KoniExtension {
|
|
|
589
591
|
chain
|
|
590
592
|
} = _ref22;
|
|
591
593
|
if ((0, _utilCrypto.isAddress)(accountId)) {
|
|
592
|
-
const address = (0,
|
|
594
|
+
const address = (0, _utils4.reformatAddress)(accountId);
|
|
593
595
|
const account = _uiKeyring.keyring.getAccount(address);
|
|
594
596
|
const contact = _uiKeyring.keyring.getAddress(address, 'address');
|
|
595
597
|
if (account) {
|
|
@@ -631,7 +633,7 @@ class KoniExtension {
|
|
|
631
633
|
meta
|
|
632
634
|
} = _ref23;
|
|
633
635
|
if ((0, _utilCrypto.isAddress)(address)) {
|
|
634
|
-
const _address = (0,
|
|
636
|
+
const _address = (0, _utils4.reformatAddress)(address);
|
|
635
637
|
_uiKeyring.keyring.saveAddress(_address, meta);
|
|
636
638
|
return true;
|
|
637
639
|
} else {
|
|
@@ -643,7 +645,7 @@ class KoniExtension {
|
|
|
643
645
|
address
|
|
644
646
|
} = _ref24;
|
|
645
647
|
if ((0, _utilCrypto.isAddress)(address)) {
|
|
646
|
-
const _address = (0,
|
|
648
|
+
const _address = (0, _utils4.reformatAddress)(address);
|
|
647
649
|
_uiKeyring.keyring.forgetAddress(_address);
|
|
648
650
|
return true;
|
|
649
651
|
} else {
|
|
@@ -1573,7 +1575,7 @@ class KoniExtension {
|
|
|
1573
1575
|
const addresses = _uiKeyring.keyring.getAccounts().map(a => a.address);
|
|
1574
1576
|
|
|
1575
1577
|
// Re-filter
|
|
1576
|
-
cb(histories.filter(item => addresses.some(address => (0,
|
|
1578
|
+
cb(histories.filter(item => addresses.some(address => (0, _utils4.isSameAddress)(item.address, address))));
|
|
1577
1579
|
});
|
|
1578
1580
|
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
1579
1581
|
port.onDisconnect.addListener(() => {
|
|
@@ -1582,7 +1584,7 @@ class KoniExtension {
|
|
|
1582
1584
|
const addresses = _uiKeyring.keyring.getAccounts().map(a => a.address);
|
|
1583
1585
|
|
|
1584
1586
|
// Re-filter
|
|
1585
|
-
return historySubject.getValue().filter(item => addresses.some(address => (0,
|
|
1587
|
+
return historySubject.getValue().filter(item => addresses.some(address => (0, _utils4.isSameAddress)(item.address, address)));
|
|
1586
1588
|
}
|
|
1587
1589
|
subscribeHistoryByChainAndAddress(_ref46, id, port) {
|
|
1588
1590
|
let {
|
|
@@ -1600,6 +1602,38 @@ class KoniExtension {
|
|
|
1600
1602
|
items: subscribeHistoriesResponse.value
|
|
1601
1603
|
};
|
|
1602
1604
|
}
|
|
1605
|
+
async getOptimalTransferProcess(params) {
|
|
1606
|
+
return this.#koniState.balanceService.getOptimalTransferProcess(params);
|
|
1607
|
+
}
|
|
1608
|
+
async approveSpending(params) {
|
|
1609
|
+
const {
|
|
1610
|
+
amount,
|
|
1611
|
+
chain,
|
|
1612
|
+
contractAddress,
|
|
1613
|
+
owner,
|
|
1614
|
+
spenderAddress
|
|
1615
|
+
} = params;
|
|
1616
|
+
if (!(0, _utils.isSnowBridgeGatewayContract)(spenderAddress)) {
|
|
1617
|
+
throw new Error('Only SnowBridge is supported'); // todo: support all ERC20 spending approval
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
const evmApi = this.#koniState.getEvmApi(chain);
|
|
1621
|
+
const transactionConfig = await (0, _web.getERC20SpendingApprovalTx)(spenderAddress, owner, contractAddress, evmApi, amount);
|
|
1622
|
+
return this.#koniState.transactionService.handleTransaction({
|
|
1623
|
+
errors: [],
|
|
1624
|
+
warnings: [],
|
|
1625
|
+
address: owner,
|
|
1626
|
+
chain,
|
|
1627
|
+
chainType: _KoniTypes.ChainType.EVM,
|
|
1628
|
+
transferNativeAmount: '0',
|
|
1629
|
+
transaction: transactionConfig,
|
|
1630
|
+
data: params,
|
|
1631
|
+
resolveOnDone: true,
|
|
1632
|
+
// todo: double-check this for other transactions
|
|
1633
|
+
extrinsicType: _KoniTypes.ExtrinsicType.TOKEN_SPENDING_APPROVAL,
|
|
1634
|
+
isTransferAll: false
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1603
1637
|
async makeTransfer(inputData) {
|
|
1604
1638
|
const {
|
|
1605
1639
|
from,
|
|
@@ -1621,8 +1655,8 @@ class KoniExtension {
|
|
|
1621
1655
|
let chainType = _KoniTypes.ChainType.SUBSTRATE;
|
|
1622
1656
|
const transferAmount = {
|
|
1623
1657
|
value: '0',
|
|
1624
|
-
symbol: (0,
|
|
1625
|
-
decimals: (0,
|
|
1658
|
+
symbol: (0, _utils3._getAssetSymbol)(transferTokenInfo),
|
|
1659
|
+
decimals: (0, _utils3._getAssetDecimals)(transferTokenInfo)
|
|
1626
1660
|
};
|
|
1627
1661
|
let transaction;
|
|
1628
1662
|
const transferTokenAvailable = await this.getAddressTransferableBalance({
|
|
@@ -1632,23 +1666,23 @@ class KoniExtension {
|
|
|
1632
1666
|
extrinsicType
|
|
1633
1667
|
});
|
|
1634
1668
|
try {
|
|
1635
|
-
if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to) && (0,
|
|
1669
|
+
if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to) && (0, _utils3._isTokenTransferredByEvm)(transferTokenInfo)) {
|
|
1636
1670
|
chainType = _KoniTypes.ChainType.EVM;
|
|
1637
1671
|
const txVal = transferAll ? transferTokenAvailable.value : value || '0';
|
|
1638
1672
|
const evmApi = evmApiMap[networkKey];
|
|
1639
1673
|
|
|
1640
1674
|
// Estimate with EVM API
|
|
1641
|
-
if ((0,
|
|
1642
|
-
[transaction, transferAmount.value] = await (0,
|
|
1675
|
+
if ((0, _utils3._isTokenEvmSmartContract)(transferTokenInfo) || (0, _utils3._isLocalToken)(transferTokenInfo)) {
|
|
1676
|
+
[transaction, transferAmount.value] = await (0, _smartContract.getERC20TransactionObject)((0, _utils3._getContractAddressOfToken)(transferTokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApi);
|
|
1643
1677
|
} else {
|
|
1644
|
-
[transaction, transferAmount.value] = await (0,
|
|
1678
|
+
[transaction, transferAmount.value] = await (0, _smartContract.getEVMTransactionObject)(chainInfo, from, to, txVal, !!transferAll, evmApi);
|
|
1645
1679
|
}
|
|
1646
|
-
} else if ((0,
|
|
1680
|
+
} else if ((0, _utils3._isMantaZkAsset)(transferTokenInfo)) {
|
|
1647
1681
|
transaction = undefined;
|
|
1648
1682
|
transferAmount.value = '0';
|
|
1649
1683
|
} else {
|
|
1650
1684
|
const substrateApi = this.#koniState.getSubstrateApi(networkKey);
|
|
1651
|
-
[transaction, transferAmount.value] = await (0,
|
|
1685
|
+
[transaction, transferAmount.value] = await (0, _token.createTransferExtrinsic)({
|
|
1652
1686
|
transferAll: !!transferAll,
|
|
1653
1687
|
value: value || '0',
|
|
1654
1688
|
from: from,
|
|
@@ -1726,19 +1760,33 @@ class KoniExtension {
|
|
|
1726
1760
|
if (errors.length > 0) {
|
|
1727
1761
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(errors);
|
|
1728
1762
|
}
|
|
1763
|
+
const chainInfoMap = this.#koniState.getChainInfoMap();
|
|
1764
|
+
const isFromSnowBridgeXcm = (0, _utils3._isPureEvmChain)(chainInfoMap[originNetworkKey]) && (0, _xcmParser._isSnowBridgeXcm)(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]);
|
|
1729
1765
|
let additionalValidator;
|
|
1730
1766
|
let eventsHandler;
|
|
1731
1767
|
if (fromKeyPair && destinationTokenInfo) {
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1768
|
+
if (isFromSnowBridgeXcm) {
|
|
1769
|
+
const evmApi = this.#koniState.getEvmApi(originNetworkKey);
|
|
1770
|
+
extrinsic = await (0, _xcm.createSnowBridgeExtrinsic)({
|
|
1771
|
+
destinationTokenInfo,
|
|
1772
|
+
originTokenInfo,
|
|
1773
|
+
sendingValue: value,
|
|
1774
|
+
sender: from,
|
|
1775
|
+
recipient: to,
|
|
1776
|
+
chainInfoMap,
|
|
1777
|
+
evmApi
|
|
1778
|
+
});
|
|
1779
|
+
} else {
|
|
1780
|
+
const substrateApi = this.#koniState.getSubstrateApi(originNetworkKey);
|
|
1781
|
+
extrinsic = await (0, _xcm.createXcmExtrinsic)({
|
|
1782
|
+
destinationTokenInfo,
|
|
1783
|
+
originTokenInfo,
|
|
1784
|
+
sendingValue: value,
|
|
1785
|
+
recipient: to,
|
|
1786
|
+
chainInfoMap,
|
|
1787
|
+
substrateApi
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1742
1790
|
additionalValidator = async inputTransaction => {
|
|
1743
1791
|
const {
|
|
1744
1792
|
value: senderTransferable
|
|
@@ -1747,7 +1795,19 @@ class KoniExtension {
|
|
|
1747
1795
|
networkKey: originNetworkKey,
|
|
1748
1796
|
token: originTokenInfo.slug
|
|
1749
1797
|
});
|
|
1750
|
-
const
|
|
1798
|
+
const isSnowBridge = (0, _xcmParser._isSnowBridgeXcm)(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]);
|
|
1799
|
+
let recipientNativeBalance = '0';
|
|
1800
|
+
if (isSnowBridge) {
|
|
1801
|
+
const {
|
|
1802
|
+
value
|
|
1803
|
+
} = await this.getAddressTransferableBalance({
|
|
1804
|
+
address: to,
|
|
1805
|
+
networkKey: destinationNetworkKey,
|
|
1806
|
+
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_BALANCE
|
|
1807
|
+
});
|
|
1808
|
+
recipientNativeBalance = value;
|
|
1809
|
+
}
|
|
1810
|
+
const [warning, error] = (0, _transfer.additionalValidateXcmTransfer)(originTokenInfo, destinationTokenInfo, value, senderTransferable, recipientNativeBalance, chainInfoMap[destinationNetworkKey], isSnowBridge);
|
|
1751
1811
|
error && inputTransaction.errors.push(error);
|
|
1752
1812
|
warning && inputTransaction.warnings.push(warning);
|
|
1753
1813
|
};
|
|
@@ -1775,8 +1835,8 @@ class KoniExtension {
|
|
|
1775
1835
|
transaction: extrinsic,
|
|
1776
1836
|
data: inputData,
|
|
1777
1837
|
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
|
|
1778
|
-
chainType: _KoniTypes.ChainType.SUBSTRATE,
|
|
1779
|
-
transferNativeAmount: (0,
|
|
1838
|
+
chainType: !isFromSnowBridgeXcm ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM,
|
|
1839
|
+
transferNativeAmount: (0, _utils3._isNativeToken)(originTokenInfo) ? value : '0',
|
|
1780
1840
|
ignoreWarnings: inputData.transferAll,
|
|
1781
1841
|
isTransferAll: inputData.transferAll,
|
|
1782
1842
|
errors,
|
|
@@ -1793,7 +1853,7 @@ class KoniExtension {
|
|
|
1793
1853
|
} = inputData;
|
|
1794
1854
|
const contractAddress = params.contractAddress;
|
|
1795
1855
|
const tokenId = params.tokenId;
|
|
1796
|
-
const transaction = await (0,
|
|
1856
|
+
const transaction = await (0, _smartContract.getERC721Transaction)(this.#koniState.getEvmApi(networkKey), networkKey, contractAddress, senderAddress, recipientAddress, tokenId);
|
|
1797
1857
|
|
|
1798
1858
|
// this.addContact(recipientAddress);
|
|
1799
1859
|
|
|
@@ -1860,10 +1920,10 @@ class KoniExtension {
|
|
|
1860
1920
|
}
|
|
1861
1921
|
async deleteCustomAsset(assetSlug) {
|
|
1862
1922
|
const assetInfo = this.#koniState.getAssetBySlug(assetSlug);
|
|
1863
|
-
if (assetInfo && (0,
|
|
1864
|
-
if ((0,
|
|
1923
|
+
if (assetInfo && (0, _utils3._isCustomAsset)(assetSlug)) {
|
|
1924
|
+
if ((0, _utils3._isAssetSmartContractNft)(assetInfo)) {
|
|
1865
1925
|
// check if deleting a smart contract NFT
|
|
1866
|
-
await this.#koniState.deleteNftCollection(assetInfo.originChain, (0,
|
|
1926
|
+
await this.#koniState.deleteNftCollection(assetInfo.originChain, (0, _utils3._getContractAddressOfToken)(assetInfo));
|
|
1867
1927
|
}
|
|
1868
1928
|
this.#koniState.deleteCustomAssets([assetSlug]);
|
|
1869
1929
|
return true;
|
|
@@ -1897,7 +1957,7 @@ class KoniExtension {
|
|
|
1897
1957
|
token
|
|
1898
1958
|
} = _ref50;
|
|
1899
1959
|
const tokenInfo = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(networkKey);
|
|
1900
|
-
if (!(0,
|
|
1960
|
+
if (!(0, _utils3._isNativeToken)(tokenInfo)) {
|
|
1901
1961
|
return await this.getAddressTransferableBalance({
|
|
1902
1962
|
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
|
|
1903
1963
|
address,
|
|
@@ -1913,7 +1973,7 @@ class KoniExtension {
|
|
|
1913
1973
|
maxTransferable = await this.getNativeTokenMaxTransferable(tokenInfo, networkKey, address);
|
|
1914
1974
|
}
|
|
1915
1975
|
return {
|
|
1916
|
-
value: maxTransferable.gt(
|
|
1976
|
+
value: maxTransferable.gt(_utils4.BN_ZERO) ? maxTransferable.toFixed(0) || '0' : '0',
|
|
1917
1977
|
decimals: tokenInfo.decimals,
|
|
1918
1978
|
symbol: tokenInfo.symbol
|
|
1919
1979
|
};
|
|
@@ -1941,10 +2001,10 @@ class KoniExtension {
|
|
|
1941
2001
|
}
|
|
1942
2002
|
async getNativeTokenMaxTransferable(tokenInfo, networkKey, address) {
|
|
1943
2003
|
const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
|
|
1944
|
-
const api = (0,
|
|
2004
|
+
const api = (0, _utils3._isChainEvmCompatible)(chainInfo) && (0, _utils3._isTokenTransferredByEvm)(tokenInfo) ? this.#koniState.chainService.getEvmApi(networkKey) : this.#koniState.chainService.getSubstrateApi(networkKey);
|
|
1945
2005
|
const [mockTxFee, {
|
|
1946
2006
|
value
|
|
1947
|
-
}] = await Promise.all([(0,
|
|
2007
|
+
}] = await Promise.all([(0, _token.getTransferMockTxFee)(address, chainInfo, tokenInfo, api), this.getAddressTransferableBalance({
|
|
1948
2008
|
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_BALANCE,
|
|
1949
2009
|
address,
|
|
1950
2010
|
networkKey,
|
|
@@ -1984,13 +2044,13 @@ class KoniExtension {
|
|
|
1984
2044
|
recipientAddress,
|
|
1985
2045
|
senderAddress
|
|
1986
2046
|
} = inputData;
|
|
1987
|
-
const isSendingSelf = (0,
|
|
2047
|
+
const isSendingSelf = (0, _transfer2.isRecipientSelf)(senderAddress, recipientAddress);
|
|
1988
2048
|
|
|
1989
2049
|
// TODO: do better to detect tokenType
|
|
1990
2050
|
const isPSP34 = params === null || params === void 0 ? void 0 : params.isPsp34;
|
|
1991
2051
|
const networkKey = params === null || params === void 0 ? void 0 : params.networkKey;
|
|
1992
2052
|
const apiProps = this.#koniState.getSubstrateApi(networkKey);
|
|
1993
|
-
const extrinsic = !isPSP34 ? await (0,
|
|
2053
|
+
const extrinsic = !isPSP34 ? await (0, _transfer2.getNftTransferExtrinsic)(networkKey, apiProps, senderAddress, recipientAddress, params || {}) : await (0, _smartContract.getPSP34TransferExtrinsic)(apiProps, senderAddress, recipientAddress, params || {});
|
|
1994
2054
|
|
|
1995
2055
|
// this.addContact(recipientAddress);
|
|
1996
2056
|
|
|
@@ -2069,9 +2129,9 @@ class KoniExtension {
|
|
|
2069
2129
|
let _gen = '';
|
|
2070
2130
|
if (genesisHash) {
|
|
2071
2131
|
for (const network of Object.values(chainInfoMap)) {
|
|
2072
|
-
if ((0,
|
|
2132
|
+
if ((0, _utils3._getEvmChainId)(network) === parseInt(genesisHash)) {
|
|
2073
2133
|
// TODO: pure EVM chains do not have genesisHash
|
|
2074
|
-
_gen = (0,
|
|
2134
|
+
_gen = (0, _utils3._getSubstrateGenesisHash)(network);
|
|
2075
2135
|
}
|
|
2076
2136
|
}
|
|
2077
2137
|
}
|
|
@@ -2355,7 +2415,7 @@ class KoniExtension {
|
|
|
2355
2415
|
continue;
|
|
2356
2416
|
}
|
|
2357
2417
|
const networkInfo = chainInfoMap[n];
|
|
2358
|
-
if ((0,
|
|
2418
|
+
if ((0, _utils3._isChainEvmCompatible)(networkInfo)) {
|
|
2359
2419
|
return networkInfo;
|
|
2360
2420
|
}
|
|
2361
2421
|
}
|
|
@@ -2366,7 +2426,7 @@ class KoniExtension {
|
|
|
2366
2426
|
continue;
|
|
2367
2427
|
}
|
|
2368
2428
|
const networkInfo = chainInfoMap[n];
|
|
2369
|
-
if ((0,
|
|
2429
|
+
if ((0, _utils3._getEvmChainId)(networkInfo) === chainId) {
|
|
2370
2430
|
return networkInfo;
|
|
2371
2431
|
}
|
|
2372
2432
|
}
|
|
@@ -2408,7 +2468,7 @@ class KoniExtension {
|
|
|
2408
2468
|
withType: true
|
|
2409
2469
|
})));
|
|
2410
2470
|
const network = this.#koniState.getChainInfo(networkKey);
|
|
2411
|
-
if ((0,
|
|
2471
|
+
if ((0, _utils3._isChainEvmCompatible)(network)) {
|
|
2412
2472
|
signed = signed.substring(2);
|
|
2413
2473
|
}
|
|
2414
2474
|
return {
|
|
@@ -2444,7 +2504,7 @@ class KoniExtension {
|
|
|
2444
2504
|
signed = await pair.evmSigner.signMessage(data, 'personal_sign');
|
|
2445
2505
|
} else {
|
|
2446
2506
|
var _signedTranaction$r, _signedTranaction$s, _signedTranaction$v;
|
|
2447
|
-
const tx = (0,
|
|
2507
|
+
const tx = (0, _utils4.createTransactionFromRLP)(message);
|
|
2448
2508
|
if (!tx) {
|
|
2449
2509
|
throw new Error((0, _i18next.t)('Failed to decode data. Please use a valid QR code'));
|
|
2450
2510
|
}
|
|
@@ -2458,8 +2518,8 @@ class KoniExtension {
|
|
|
2458
2518
|
};
|
|
2459
2519
|
const common = _common.Common.custom({
|
|
2460
2520
|
name: network.name,
|
|
2461
|
-
networkId: (0,
|
|
2462
|
-
chainId: (0,
|
|
2521
|
+
networkId: (0, _utils3._getEvmChainId)(network),
|
|
2522
|
+
chainId: (0, _utils3._getEvmChainId)(network)
|
|
2463
2523
|
}, {
|
|
2464
2524
|
hardfork: 'petersburg'
|
|
2465
2525
|
});
|
|
@@ -2469,7 +2529,7 @@ class KoniExtension {
|
|
|
2469
2529
|
common
|
|
2470
2530
|
});
|
|
2471
2531
|
const signedTranaction = _tx.LegacyTransaction.fromSerializedTx((0, _util.hexToU8a)(pair.evmSigner.signTransaction(transaction)));
|
|
2472
|
-
signed = (0,
|
|
2532
|
+
signed = (0, _utils4.signatureToHex)({
|
|
2473
2533
|
r: ((_signedTranaction$r = signedTranaction.r) === null || _signedTranaction$r === void 0 ? void 0 : _signedTranaction$r.toString(16)) || '',
|
|
2474
2534
|
s: ((_signedTranaction$s = signedTranaction.s) === null || _signedTranaction$s === void 0 ? void 0 : _signedTranaction$s.toString(16)) || '',
|
|
2475
2535
|
v: ((_signedTranaction$v = signedTranaction.v) === null || _signedTranaction$v === void 0 ? void 0 : _signedTranaction$v.toString(16)) || ''
|
|
@@ -2518,7 +2578,7 @@ class KoniExtension {
|
|
|
2518
2578
|
}
|
|
2519
2579
|
const {
|
|
2520
2580
|
decimals
|
|
2521
|
-
} = (0,
|
|
2581
|
+
} = (0, _utils3._getChainNativeTokenBasicInfo)(chainInfo);
|
|
2522
2582
|
return await (0, _bonding.getValidatorsInfo)(chain, apiProps, decimals, chainStakingMetadata);
|
|
2523
2583
|
}
|
|
2524
2584
|
async getNominationPoolOptions(chain) {
|
|
@@ -2723,7 +2783,7 @@ class KoniExtension {
|
|
|
2723
2783
|
const chainInfo = this.#koniState.getChainInfo(networkKey);
|
|
2724
2784
|
const {
|
|
2725
2785
|
decimals
|
|
2726
|
-
} = (0,
|
|
2786
|
+
} = (0, _utils3._getChainNativeTokenBasicInfo)(chainInfo);
|
|
2727
2787
|
const parsedAccountMinimum = parseFloat(accountMinimum) * 10 ** decimals;
|
|
2728
2788
|
const extrinsic = await (0, _paraChain.getTuringCompoundExtrinsic)(dotSamaApi, address, collatorAddress, parsedAccountMinimum.toString(), bondedAmount);
|
|
2729
2789
|
return await this.#koniState.transactionService.handleTransaction({
|
|
@@ -2985,7 +3045,7 @@ class KoniExtension {
|
|
|
2985
3045
|
}
|
|
2986
3046
|
}
|
|
2987
3047
|
if (chainInfo) {
|
|
2988
|
-
isEvm = (0,
|
|
3048
|
+
isEvm = (0, _utils3._isChainEvmCompatible)(chainInfo);
|
|
2989
3049
|
}
|
|
2990
3050
|
}
|
|
2991
3051
|
const result = request.sign(registry, pair);
|
|
@@ -3394,12 +3454,12 @@ class KoniExtension {
|
|
|
3394
3454
|
if (namespace.chains) {
|
|
3395
3455
|
const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
|
|
3396
3456
|
if (unSupportChains.length) {
|
|
3397
|
-
throw new Error((0,
|
|
3457
|
+
throw new Error((0, _utils5.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
|
|
3398
3458
|
}
|
|
3399
3459
|
availableNamespaces[key] = namespace;
|
|
3400
3460
|
}
|
|
3401
3461
|
} else {
|
|
3402
|
-
throw new Error((0,
|
|
3462
|
+
throw new Error((0, _utils5.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
|
|
3403
3463
|
}
|
|
3404
3464
|
});
|
|
3405
3465
|
Object.entries(optionalNamespaces).forEach(_ref83 => {
|
|
@@ -3431,7 +3491,7 @@ class KoniExtension {
|
|
|
3431
3491
|
let [key, namespace] = _ref84;
|
|
3432
3492
|
if (namespace.chains) {
|
|
3433
3493
|
const accounts = [];
|
|
3434
|
-
const chains = (0,
|
|
3494
|
+
const chains = (0, _utils4.uniqueStringArray)(namespace.chains);
|
|
3435
3495
|
chains.forEach(chain => {
|
|
3436
3496
|
accounts.push(...selectedAccounts.filter(address => (0, _utilCrypto.isEthereumAddress)(address) === (key === _constants5.WALLET_CONNECT_EIP155_NAMESPACE)).map(address => `${chain}:${address}`));
|
|
3437
3497
|
});
|
|
@@ -3573,7 +3633,7 @@ class KoniExtension {
|
|
|
3573
3633
|
}
|
|
3574
3634
|
async initSyncMantaPay(address) {
|
|
3575
3635
|
var _this$koniState$chain3, _this$koniState$chain4, _this$koniState$chain5, _this$koniState$chain6;
|
|
3576
|
-
if ((_this$koniState$chain3 = this.#koniState.chainService) !== null && _this$koniState$chain3 !== void 0 && (_this$koniState$chain4 = _this$koniState$chain3.mantaPay) !== null && _this$koniState$chain4 !== void 0 && _this$koniState$chain4.getSyncState().isSyncing || !
|
|
3636
|
+
if ((_this$koniState$chain3 = this.#koniState.chainService) !== null && _this$koniState$chain3 !== void 0 && (_this$koniState$chain4 = _this$koniState$chain3.mantaPay) !== null && _this$koniState$chain4 !== void 0 && _this$koniState$chain4.getSyncState().isSyncing || !_utils4.MODULE_SUPPORT.MANTA_ZK) {
|
|
3577
3637
|
return;
|
|
3578
3638
|
}
|
|
3579
3639
|
this.#skipAutoLock = true;
|
|
@@ -3722,7 +3782,7 @@ class KoniExtension {
|
|
|
3722
3782
|
txData
|
|
3723
3783
|
} = await this.#koniState.earningService.handleYieldJoin(inputData);
|
|
3724
3784
|
const isPoolSupportAlternativeFee = this.#koniState.earningService.isPoolSupportAlternativeFee(inputData.data.slug);
|
|
3725
|
-
const isMintingStep =
|
|
3785
|
+
const isMintingStep = _utils2.YIELD_EXTRINSIC_TYPES.includes(extrinsicType);
|
|
3726
3786
|
return await this.#koniState.transactionService.handleTransaction({
|
|
3727
3787
|
address,
|
|
3728
3788
|
chain: txChain,
|
|
@@ -4430,6 +4490,10 @@ class KoniExtension {
|
|
|
4430
4490
|
return await this.makeTransfer(request);
|
|
4431
4491
|
case 'pri(accounts.crossChainTransfer)':
|
|
4432
4492
|
return await this.makeCrossChainTransfer(request);
|
|
4493
|
+
case 'pri(accounts.getOptimalTransferProcess)':
|
|
4494
|
+
return await this.getOptimalTransferProcess(request);
|
|
4495
|
+
case 'pri(accounts.approveSpending)':
|
|
4496
|
+
return await this.approveSpending(request);
|
|
4433
4497
|
|
|
4434
4498
|
/// Sign QR
|
|
4435
4499
|
case 'pri(qr.transaction.parse.substrate)':
|
package/cjs/packageInfo.js
CHANGED
|
@@ -24,4 +24,15 @@ Object.keys(_subscribe).forEach(function (key) {
|
|
|
24
24
|
return _subscribe[key];
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
+
});
|
|
28
|
+
var _process = require("./process");
|
|
29
|
+
Object.keys(_process).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _process[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _process[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
27
38
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultTransferProcess = getDefaultTransferProcess;
|
|
7
|
+
exports.getSnowbridgeTransferProcessFromEvm = getSnowbridgeTransferProcessFromEvm;
|
|
8
|
+
var _chainList = require("@subwallet/chain-list");
|
|
9
|
+
var _serviceBase = require("@subwallet/extension-base/types/service-base");
|
|
10
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
function getDefaultTransferProcess() {
|
|
14
|
+
return {
|
|
15
|
+
totalFee: [_serviceBase.MOCK_STEP_FEE, _serviceBase.MOCK_STEP_FEE],
|
|
16
|
+
steps: [_serviceBase.DEFAULT_FIRST_STEP, {
|
|
17
|
+
id: 1,
|
|
18
|
+
type: _serviceBase.CommonStepType.TRANSFER,
|
|
19
|
+
name: 'Transfer'
|
|
20
|
+
}]
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function getSnowbridgeTransferProcessFromEvm(address, evmApi, tokenInfo, amount) {
|
|
24
|
+
if (![_chainList.COMMON_CHAIN_SLUGS.ETHEREUM, _chainList.COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA].includes(tokenInfo.originChain)) {
|
|
25
|
+
throw new Error('Snowbridge only has support for Ethereum');
|
|
26
|
+
}
|
|
27
|
+
const result = {
|
|
28
|
+
totalFee: [_serviceBase.MOCK_STEP_FEE],
|
|
29
|
+
steps: [_serviceBase.DEFAULT_FIRST_STEP]
|
|
30
|
+
};
|
|
31
|
+
// const allowance = await getERC20Allowance(getSnowBridgeGatewayContract(evmApi.chainSlug), address, _getContractAddressOfToken(tokenInfo), evmApi);
|
|
32
|
+
|
|
33
|
+
result.steps.push({
|
|
34
|
+
// always approve spending because sometimes allowance check fails
|
|
35
|
+
id: result.steps.length,
|
|
36
|
+
type: _serviceBase.CommonStepType.TOKEN_APPROVAL,
|
|
37
|
+
name: 'Approve spending'
|
|
38
|
+
});
|
|
39
|
+
result.totalFee.push(_serviceBase.MOCK_STEP_FEE);
|
|
40
|
+
// if (!allowance || BigInt(allowance) < BigInt(amount)) {
|
|
41
|
+
// }
|
|
42
|
+
|
|
43
|
+
result.steps.push({
|
|
44
|
+
id: result.steps.length,
|
|
45
|
+
type: _serviceBase.CommonStepType.TRANSFER,
|
|
46
|
+
name: 'Transfer'
|
|
47
|
+
});
|
|
48
|
+
result.totalFee.push(_serviceBase.MOCK_STEP_FEE);
|
|
49
|
+
return Promise.resolve(result);
|
|
50
|
+
}
|
|
@@ -8,8 +8,7 @@ exports.subscribeEVMBalance = subscribeEVMBalance;
|
|
|
8
8
|
var _types = require("@subwallet/chain-list/types");
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
10
|
var _constants = require("@subwallet/extension-base/constants");
|
|
11
|
-
var
|
|
12
|
-
var _web = require("@subwallet/extension-base/koni/api/tokens/evm/web3");
|
|
11
|
+
var _web = require("@subwallet/extension-base/koni/api/contract-handler/evm/web3");
|
|
13
12
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
14
13
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
15
14
|
var _util = require("@polkadot/util");
|
|
@@ -65,6 +64,15 @@ function subscribeERC20Interval(_ref) {
|
|
|
65
64
|
clearInterval(interval);
|
|
66
65
|
};
|
|
67
66
|
}
|
|
67
|
+
async function getEVMBalance(addresses, web3Api) {
|
|
68
|
+
return await Promise.all(addresses.map(async address => {
|
|
69
|
+
try {
|
|
70
|
+
return await web3Api.api.eth.getBalance(address);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return '0';
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
68
76
|
function subscribeEVMBalance(params) {
|
|
69
77
|
var _Object$values$;
|
|
70
78
|
const {
|
|
@@ -78,7 +86,7 @@ function subscribeEVMBalance(params) {
|
|
|
78
86
|
const nativeTokenInfo = (0, _utils2.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.NATIVE]);
|
|
79
87
|
const nativeTokenSlug = ((_Object$values$ = Object.values(nativeTokenInfo)[0]) === null || _Object$values$ === void 0 ? void 0 : _Object$values$.slug) || '';
|
|
80
88
|
function getBalance() {
|
|
81
|
-
|
|
89
|
+
getEVMBalance(addresses, evmApi).then(balances => {
|
|
82
90
|
return balances.map((balance, index) => {
|
|
83
91
|
return {
|
|
84
92
|
address: addresses[index],
|
|
@@ -9,10 +9,11 @@ var _api = require("@gear-js/api");
|
|
|
9
9
|
var _types = require("@subwallet/chain-list/types");
|
|
10
10
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
11
11
|
var _constants = require("@subwallet/extension-base/constants");
|
|
12
|
+
var _foreignAssetPallet = require("@subwallet/extension-base/core/substrate/foreign-asset-pallet");
|
|
12
13
|
var _nominationpoolsPallet = require("@subwallet/extension-base/core/substrate/nominationpools-pallet");
|
|
13
14
|
var _systemPallet = require("@subwallet/extension-base/core/substrate/system-pallet");
|
|
14
|
-
var _wasm = require("@subwallet/extension-base/koni/api/
|
|
15
|
-
var _utils = require("@subwallet/extension-base/koni/api/
|
|
15
|
+
var _wasm = require("@subwallet/extension-base/koni/api/contract-handler/wasm");
|
|
16
|
+
var _utils = require("@subwallet/extension-base/koni/api/contract-handler/wasm/utils");
|
|
16
17
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
17
18
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
18
19
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
@@ -66,7 +67,7 @@ const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substra
|
|
|
66
67
|
unsubLocalToken = await subscribeOrmlTokensPallet(substrateParams);
|
|
67
68
|
}
|
|
68
69
|
if (_constants2._BALANCE_CHAIN_GROUP.supportBridged.includes(chain)) {
|
|
69
|
-
unsubBridgedToken = await
|
|
70
|
+
unsubBridgedToken = await subscribeForeignAssetBalance(substrateParams);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
/**
|
|
@@ -160,7 +161,7 @@ const subscribeWithSystemAccountPallet = async _ref => {
|
|
|
160
161
|
subscription.unsubscribe();
|
|
161
162
|
};
|
|
162
163
|
};
|
|
163
|
-
const
|
|
164
|
+
const subscribeForeignAssetBalance = async _ref3 => {
|
|
164
165
|
let {
|
|
165
166
|
addresses,
|
|
166
167
|
assetMap,
|
|
@@ -176,30 +177,15 @@ const subscribeBridgedBalance = async _ref3 => {
|
|
|
176
177
|
try {
|
|
177
178
|
const isBridgedToken = (0, _utils2._isBridgedToken)(tokenInfo);
|
|
178
179
|
if (isBridgedToken) {
|
|
179
|
-
const
|
|
180
|
-
return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [
|
|
180
|
+
const assetLocation = (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getXcmAssetMultilocation)(tokenInfo);
|
|
181
|
+
return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [assetLocation, address]), balances => {
|
|
181
182
|
const items = balances.map((balance, index) => {
|
|
182
|
-
const
|
|
183
|
-
let frozen = _util.BN_ZERO;
|
|
184
|
-
let total = _util.BN_ZERO;
|
|
185
|
-
if (bdata) {
|
|
186
|
-
// @ts-ignore
|
|
187
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
|
|
188
|
-
const addressBalance = new _util.BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0');
|
|
189
|
-
|
|
190
|
-
// @ts-ignore
|
|
191
|
-
if (bdata !== null && bdata !== void 0 && bdata.isFrozen) {
|
|
192
|
-
frozen = addressBalance;
|
|
193
|
-
} else {
|
|
194
|
-
total = addressBalance;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const free = total.sub(frozen);
|
|
183
|
+
const accountInfo = balance === null || balance === void 0 ? void 0 : balance.toPrimitive();
|
|
198
184
|
return {
|
|
199
185
|
address: addresses[index],
|
|
200
186
|
tokenSlug: tokenInfo.slug,
|
|
201
|
-
free:
|
|
202
|
-
locked:
|
|
187
|
+
free: accountInfo ? (0, _foreignAssetPallet._getForeignAssetPalletTransferable)(accountInfo).toString() : '0',
|
|
188
|
+
locked: accountInfo ? (0, _foreignAssetPallet._getForeignAssetPalletLockedBalance)(accountInfo).toString() : '0',
|
|
203
189
|
state: _KoniTypes.APIItemState.READY
|
|
204
190
|
};
|
|
205
191
|
});
|