@subwallet/extension-base 1.3.3-0 → 1.3.5-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 +14 -1
- package/background/KoniTypes.js +1 -0
- package/cjs/background/KoniTypes.js +1 -0
- package/cjs/constants/blocked-actions-list.js +1 -2
- package/cjs/constants/index.js +16 -1
- package/cjs/constants/remind-notification-time.js +14 -0
- package/cjs/core/logic-validation/transfer.js +12 -6
- package/cjs/core/substrate/xcm-parser.js +13 -1
- package/cjs/koni/api/contract-handler/utils/index.js +20 -1
- package/cjs/koni/api/nft/config.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -0
- package/cjs/koni/api/nft/rari/index.js +87 -0
- package/cjs/koni/api/yield/helper/utils.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +110 -23
- package/cjs/koni/background/handlers/State.js +5 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +2 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +5 -0
- package/cjs/services/balance-service/index.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +198 -0
- package/cjs/services/balance-service/transfer/xcm/index.js +50 -5
- package/cjs/services/chain-service/constants.js +2 -1
- package/cjs/services/chain-service/handler/EvmApi.js +12 -21
- package/cjs/services/chain-service/handler/EvmChainHandler.js +0 -2
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +73 -40
- package/cjs/services/chain-service/index.js +44 -13
- package/cjs/services/chain-service/utils/index.js +20 -0
- package/cjs/services/earning-service/handlers/base.js +12 -3
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +11 -3
- package/cjs/services/earning-service/handlers/native-staking/astar.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +3 -1
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +3 -1
- package/cjs/services/earning-service/handlers/native-staking/tao.js +11 -3
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +14 -12
- package/cjs/services/earning-service/service.js +5 -0
- package/cjs/services/inapp-notification-service/consts.js +31 -0
- package/cjs/services/inapp-notification-service/index.js +260 -0
- package/cjs/services/inapp-notification-service/interfaces.js +32 -0
- package/cjs/services/inapp-notification-service/utils.js +197 -0
- package/cjs/services/keyring-service/context/account-context.js +9 -0
- package/cjs/services/keyring-service/context/state.js +4 -0
- package/cjs/services/setting-service/SettingService.js +9 -1
- package/cjs/services/setting-service/constants.js +16 -1
- package/cjs/services/storage-service/DatabaseService.js +42 -3
- package/cjs/services/storage-service/databases/index.js +3 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +81 -0
- package/cjs/services/transaction-service/index.js +18 -4
- package/cjs/types/avail-bridge/index.js +1 -0
- package/cjs/types/notification/index.js +1 -0
- package/cjs/utils/account/transform.js +9 -5
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/blocked-actions-list.js +1 -2
- package/constants/index.d.ts +2 -0
- package/constants/index.js +3 -1
- package/constants/remind-notification-time.d.ts +2 -0
- package/constants/remind-notification-time.js +7 -0
- package/core/logic-validation/transfer.js +12 -6
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +12 -1
- package/koni/api/contract-handler/utils/avail_bridge_abi.json +1659 -0
- package/koni/api/contract-handler/utils/avail_test_bridge_abi.json +1692 -0
- package/koni/api/contract-handler/utils/index.d.ts +7 -2
- package/koni/api/contract-handler/utils/index.js +15 -0
- package/koni/api/nft/config.js +1 -1
- package/koni/api/nft/index.js +9 -0
- package/koni/api/nft/rari/index.d.ts +7 -0
- package/koni/api/nft/rari/index.js +80 -0
- package/koni/api/yield/helper/utils.js +1 -1
- package/koni/background/handlers/Extension.d.ts +7 -0
- package/koni/background/handlers/Extension.js +112 -25
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +5 -2
- package/package.json +59 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.js +2 -1
- package/services/balance-service/helpers/subscribe/index.js +5 -0
- package/services/balance-service/index.js +2 -2
- package/services/balance-service/transfer/xcm/availBridge.d.ts +45 -0
- package/services/balance-service/transfer/xcm/availBridge.js +186 -0
- package/services/balance-service/transfer/xcm/index.d.ts +8 -8
- package/services/balance-service/transfer/xcm/index.js +46 -5
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +2 -1
- package/services/chain-service/handler/EvmApi.js +12 -21
- package/services/chain-service/handler/EvmChainHandler.js +0 -2
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +3 -2
- package/services/chain-service/handler/SubstrateChainHandler.js +73 -40
- package/services/chain-service/index.d.ts +2 -0
- package/services/chain-service/index.js +45 -14
- package/services/chain-service/types.d.ts +2 -1
- package/services/chain-service/utils/index.d.ts +3 -0
- package/services/chain-service/utils/index.js +14 -0
- package/services/earning-service/handlers/base.d.ts +2 -0
- package/services/earning-service/handlers/base.js +9 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +11 -3
- package/services/earning-service/handlers/native-staking/astar.js +1 -1
- package/services/earning-service/handlers/native-staking/para-chain.js +3 -1
- package/services/earning-service/handlers/native-staking/relay-chain.js +3 -1
- package/services/earning-service/handlers/native-staking/tao.d.ts +4 -0
- package/services/earning-service/handlers/native-staking/tao.js +6 -2
- package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
- package/services/earning-service/handlers/nomination-pool/index.js +14 -12
- package/services/earning-service/service.d.ts +2 -0
- package/services/earning-service/service.js +5 -0
- package/services/inapp-notification-service/consts.d.ts +18 -0
- package/services/inapp-notification-service/consts.js +22 -0
- package/services/inapp-notification-service/index.d.ts +37 -0
- package/services/inapp-notification-service/index.js +252 -0
- package/services/inapp-notification-service/interfaces.d.ts +77 -0
- package/services/inapp-notification-service/interfaces.js +24 -0
- package/services/inapp-notification-service/utils.d.ts +55 -0
- package/services/inapp-notification-service/utils.js +173 -0
- package/services/keyring-service/context/account-context.d.ts +3 -0
- package/services/keyring-service/context/account-context.js +9 -0
- package/services/keyring-service/context/state.d.ts +1 -0
- package/services/keyring-service/context/state.js +4 -0
- package/services/setting-service/SettingService.js +9 -1
- package/services/setting-service/constants.d.ts +2 -0
- package/services/setting-service/constants.js +15 -0
- package/services/storage-service/DatabaseService.d.ts +15 -0
- package/services/storage-service/DatabaseService.js +42 -3
- package/services/storage-service/databases/index.d.ts +2 -0
- package/services/storage-service/databases/index.js +3 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +14 -0
- package/services/storage-service/db-stores/InappNotification.js +73 -0
- package/services/transaction-service/index.js +18 -4
- package/types/avail-bridge/index.d.ts +6 -0
- package/types/avail-bridge/index.js +1 -0
- package/types/notification/index.d.ts +9 -0
- package/types/notification/index.js +1 -0
- package/utils/account/transform.js +9 -5
- package/utils/staticData/index.d.ts +5 -1
- package/utils/staticData/index.js +5 -2
- package/utils/staticData/remindNotificationTime.json +1 -0
|
@@ -23,6 +23,7 @@ var _eventService = require("@subwallet/extension-base/services/event-service");
|
|
|
23
23
|
var _service2 = _interopRequireDefault(require("@subwallet/extension-base/services/fee-service/service"));
|
|
24
24
|
var _utils2 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
25
25
|
var _historyService = require("@subwallet/extension-base/services/history-service");
|
|
26
|
+
var _inappNotificationService = require("@subwallet/extension-base/services/inapp-notification-service");
|
|
26
27
|
var _keyringService = require("@subwallet/extension-base/services/keyring-service");
|
|
27
28
|
var _migrationService = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service"));
|
|
28
29
|
var _mintCampaignService = _interopRequireDefault(require("@subwallet/extension-base/services/mint-campaign-service"));
|
|
@@ -110,6 +111,7 @@ class KoniState {
|
|
|
110
111
|
this.earningService = new _service.default(this);
|
|
111
112
|
this.feeService = new _service2.default(this);
|
|
112
113
|
this.swapService = new _swapService.SwapService(this);
|
|
114
|
+
this.inappNotificationService = new _inappNotificationService.InappNotificationService(this.dbService, this.keyringService, this.eventService, this.chainService);
|
|
113
115
|
this.subscription = new _subscription.KoniSubscription(this, this.dbService);
|
|
114
116
|
this.cron = new _cron.KoniCron(this, this.subscription, this.dbService);
|
|
115
117
|
this.logger = (0, _util.logger)('State');
|
|
@@ -212,6 +214,7 @@ class KoniState {
|
|
|
212
214
|
await this.balanceService.init();
|
|
213
215
|
await this.earningService.init();
|
|
214
216
|
await this.swapService.init();
|
|
217
|
+
await this.inappNotificationService.init();
|
|
215
218
|
this.onReady();
|
|
216
219
|
this.onAccountAdd();
|
|
217
220
|
this.onAccountRemove();
|
|
@@ -1200,7 +1203,7 @@ class KoniState {
|
|
|
1200
1203
|
this.campaignService.stop();
|
|
1201
1204
|
await Promise.all([this.cron.stop(), this.subscription.stop()]);
|
|
1202
1205
|
await this.pauseAllNetworks(undefined, 'IDLE mode');
|
|
1203
|
-
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.earningService.stop(), this.swapService.stop()]);
|
|
1206
|
+
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.earningService.stop(), this.swapService.stop(), this.inappNotificationService.stop()]);
|
|
1204
1207
|
|
|
1205
1208
|
// Complete sleeping
|
|
1206
1209
|
sleeping.resolve();
|
|
@@ -1233,7 +1236,7 @@ class KoniState {
|
|
|
1233
1236
|
}
|
|
1234
1237
|
|
|
1235
1238
|
// Start services
|
|
1236
|
-
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start(), this.swapService.start()]);
|
|
1239
|
+
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start(), this.swapService.start(), this.inappNotificationService.start()]);
|
|
1237
1240
|
|
|
1238
1241
|
// Complete starting
|
|
1239
1242
|
starting.resolve();
|
package/cjs/packageInfo.js
CHANGED
|
@@ -21,8 +21,9 @@ function getDefaultTransferProcess() {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
async function getSnowbridgeTransferProcessFromEvm(address, evmApi, tokenInfo, amount) {
|
|
24
|
+
// todo: refactor, AvailBridge also go into this function
|
|
24
25
|
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
|
+
throw new Error('Snowbridge or AvailBridge only has support for Ethereum');
|
|
26
27
|
}
|
|
27
28
|
const result = {
|
|
28
29
|
totalFee: [_serviceBase.MOCK_STEP_FEE],
|
|
@@ -138,6 +138,11 @@ function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoM
|
|
|
138
138
|
tonApi
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
|
+
|
|
142
|
+
// If the chain is not ready, return pending state
|
|
143
|
+
if (!substrateApiMap[chainSlug].isApiReady) {
|
|
144
|
+
handleUnsupportedOrPendingAddresses(useAddresses, chainSlug, chainAssetMap, _KoniTypes.APIItemState.PENDING, callback);
|
|
145
|
+
}
|
|
141
146
|
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
142
147
|
return (0, _substrate.subscribeSubstrateBalance)(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
|
|
143
148
|
});
|
|
@@ -199,7 +199,7 @@ class BalanceService {
|
|
|
199
199
|
let unsub = _util.noop;
|
|
200
200
|
unsub = (0, _helpers.subscribeBalance)([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, result => {
|
|
201
201
|
const rs = result[0];
|
|
202
|
-
if (rs.tokenSlug === tSlug) {
|
|
202
|
+
if (rs.tokenSlug === tSlug && rs.state !== _KoniTypes.APIItemState.PENDING) {
|
|
203
203
|
hasError = false;
|
|
204
204
|
const balance = {
|
|
205
205
|
value: rs.free,
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AvailBridgeConfig = void 0;
|
|
7
|
+
exports.getAvailBridgeExtrinsicFromAvail = getAvailBridgeExtrinsicFromAvail;
|
|
8
|
+
exports.getAvailBridgeTxFromEth = getAvailBridgeTxFromEth;
|
|
9
|
+
exports.getClaimTxOnAvail = getClaimTxOnAvail;
|
|
10
|
+
exports.getClaimTxOnEthereum = getClaimTxOnEthereum;
|
|
11
|
+
exports.isAvailChainBridge = isAvailChainBridge;
|
|
12
|
+
var _chainList = require("@subwallet/chain-list");
|
|
13
|
+
var _web = require("@subwallet/extension-base/koni/api/contract-handler/evm/web3");
|
|
14
|
+
var _utils = require("@subwallet/extension-base/koni/api/contract-handler/utils");
|
|
15
|
+
var _utils2 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
16
|
+
var _utils3 = require("@subwallet/extension-base/services/inapp-notification-service/utils");
|
|
17
|
+
var _keyring = require("@subwallet/keyring");
|
|
18
|
+
var _util = require("@polkadot/util");
|
|
19
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
20
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
|
|
22
|
+
const AvailBridgeConfig = {
|
|
23
|
+
ASSET_ID: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
24
|
+
ETHEREUM_DOMAIN: 2,
|
|
25
|
+
// todo: check if these config can change later
|
|
26
|
+
AVAIL_DOMAIN: 1
|
|
27
|
+
};
|
|
28
|
+
exports.AvailBridgeConfig = AvailBridgeConfig;
|
|
29
|
+
async function getAvailBridgeTxFromEth(originChainInfo, sender, recipient, value, evmApi) {
|
|
30
|
+
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
31
|
+
const availBridgeContractAddress = (0, _utils.getAvailBridgeGatewayContract)(originChainInfo.slug);
|
|
32
|
+
const ABI = getAvailBridgeAbi(originChainInfo.slug);
|
|
33
|
+
const availBridgeContract = (0, _web.getWeb3Contract)(availBridgeContractAddress, evmApi, ABI);
|
|
34
|
+
const _address = (0, _util.u8aToHex)((0, _keyring.decodeAddress)(recipient));
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
36
|
+
const sendAvail = availBridgeContract.methods.sendAVAIL(_address, value);
|
|
37
|
+
const transferData = sendAvail.encodeABI();
|
|
38
|
+
const priority = await (0, _utils2.calculateGasFeeParams)(evmApi, evmApi.chainSlug);
|
|
39
|
+
const gasLimit = await sendAvail.estimateGas({
|
|
40
|
+
from: sender
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
from: sender,
|
|
44
|
+
to: availBridgeContractAddress,
|
|
45
|
+
value: '0',
|
|
46
|
+
data: transferData,
|
|
47
|
+
gasPrice: priority.gasPrice,
|
|
48
|
+
maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
|
|
49
|
+
maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString(),
|
|
50
|
+
gas: gasLimit
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function getAvailBridgeExtrinsicFromAvail(recipient, sendingValue, substrateApi) {
|
|
54
|
+
const data = {
|
|
55
|
+
message: {
|
|
56
|
+
FungibleToken: {
|
|
57
|
+
assetId: AvailBridgeConfig.ASSET_ID,
|
|
58
|
+
amount: BigInt(sendingValue)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
to: `${recipient.padEnd(66, '0')}`,
|
|
62
|
+
domain: AvailBridgeConfig.ETHEREUM_DOMAIN
|
|
63
|
+
};
|
|
64
|
+
const chainApi = await substrateApi.isReady;
|
|
65
|
+
return chainApi.api.tx.vector.sendMessage(data.message, data.to, data.domain);
|
|
66
|
+
}
|
|
67
|
+
async function getClaimTxOnAvail(notification, substrateApi) {
|
|
68
|
+
const chainApi = await substrateApi.isReady;
|
|
69
|
+
const chainSlug = chainApi.chainSlug;
|
|
70
|
+
const metadata = notification.metadata;
|
|
71
|
+
const lastestEthHeadSlot = await getLastestEthHeadSlot(chainSlug);
|
|
72
|
+
const lastestBlockHash = await getLastestBlockHash(chainSlug, lastestEthHeadSlot);
|
|
73
|
+
const proof = await getClaimProofOnAvail(chainSlug, lastestBlockHash, metadata.messageId);
|
|
74
|
+
return chainApi.api.tx.vector.execute(lastestEthHeadSlot, getAddressMessage(notification), proof.accountProof, proof.storageProof);
|
|
75
|
+
}
|
|
76
|
+
async function getLastestEthHeadSlot(chainSlug) {
|
|
77
|
+
try {
|
|
78
|
+
const api = getAvailBridgeApi(chainSlug);
|
|
79
|
+
const rawResponse = await fetch(`${api}/eth/head`);
|
|
80
|
+
const response = await rawResponse.json();
|
|
81
|
+
return response.slot;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.error(e);
|
|
84
|
+
throw e;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function getLastestBlockHash(chainSlug, slot) {
|
|
88
|
+
try {
|
|
89
|
+
const api = getAvailBridgeApi(chainSlug);
|
|
90
|
+
const rawResponse = await fetch(`${api}/beacon/slot/${slot}`);
|
|
91
|
+
const response = await rawResponse.json();
|
|
92
|
+
return response.blockHash;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
console.error(e);
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function getClaimProofOnAvail(chainSlug, blockHash, messageId) {
|
|
99
|
+
try {
|
|
100
|
+
const api = getAvailBridgeApi(chainSlug);
|
|
101
|
+
const rawResponse = await fetch(`${api}/avl/proof/${blockHash}/${messageId}`);
|
|
102
|
+
return await rawResponse.json();
|
|
103
|
+
} catch (e) {
|
|
104
|
+
console.error(e);
|
|
105
|
+
throw e;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function getClaimProofOnEthereum(chainSlug, blockHash, transactionIndex) {
|
|
109
|
+
try {
|
|
110
|
+
const api = getAvailBridgeApi(chainSlug);
|
|
111
|
+
const rawResponse = await fetch(`${api}/eth/proof/${blockHash}?index=${transactionIndex}`);
|
|
112
|
+
return await rawResponse.json();
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.error(e);
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function getAvailBridgeApi(chainSlug) {
|
|
119
|
+
if (chainSlug === 'avail_mainnet' || chainSlug === _chainList.COMMON_CHAIN_SLUGS.ETHEREUM) {
|
|
120
|
+
// todo: add COMMON_CHAIN_SLUGS for AVAIL, AVAIL TURING
|
|
121
|
+
return _utils3.AVAIL_BRIDGE_API.AVAIL_MAINNET;
|
|
122
|
+
}
|
|
123
|
+
return _utils3.AVAIL_BRIDGE_API.AVAIL_TESTNET;
|
|
124
|
+
}
|
|
125
|
+
async function getClaimTxOnEthereum(chainSlug, notification, evmApi) {
|
|
126
|
+
var _priority$maxFeePerGa2, _priority$maxPriority2;
|
|
127
|
+
const availBridgeContractAddress = (0, _utils.getAvailBridgeGatewayContract)(chainSlug);
|
|
128
|
+
const ABI = getAvailBridgeAbi(chainSlug);
|
|
129
|
+
const availBridgeContract = (0, _web.getWeb3Contract)(availBridgeContractAddress, evmApi, ABI);
|
|
130
|
+
const metadata = notification.metadata;
|
|
131
|
+
const merkleProof = await getClaimProofOnEthereum(chainSlug, metadata.sourceBlockHash, metadata.sourceTransactionIndex);
|
|
132
|
+
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
134
|
+
const transfer = availBridgeContract.methods.receiveAVAIL({
|
|
135
|
+
messageType: '0x02',
|
|
136
|
+
from: merkleProof.message.from,
|
|
137
|
+
to: merkleProof.message.to,
|
|
138
|
+
originDomain: merkleProof.message.originDomain,
|
|
139
|
+
destinationDomain: merkleProof.message.destinationDomain,
|
|
140
|
+
data: evmApi.api.eth.abi.encodeParameters([{
|
|
141
|
+
name: 'assetId',
|
|
142
|
+
type: 'bytes32'
|
|
143
|
+
}, {
|
|
144
|
+
name: 'amount',
|
|
145
|
+
type: 'uint256'
|
|
146
|
+
}], [merkleProof.message.message.fungibleToken.asset_id, BigInt(merkleProof.message.message.fungibleToken.amount)]),
|
|
147
|
+
messageId: merkleProof.message.id
|
|
148
|
+
}, {
|
|
149
|
+
dataRootProof: merkleProof.dataRootProof,
|
|
150
|
+
leafProof: merkleProof.leafProof,
|
|
151
|
+
rangeHash: merkleProof.rangeHash,
|
|
152
|
+
dataRootIndex: merkleProof.dataRootIndex,
|
|
153
|
+
blobRoot: merkleProof.blobRoot,
|
|
154
|
+
bridgeRoot: merkleProof.bridgeRoot,
|
|
155
|
+
leaf: merkleProof.leaf,
|
|
156
|
+
leafIndex: merkleProof.leafIndex
|
|
157
|
+
});
|
|
158
|
+
const transferData = transfer.encodeABI();
|
|
159
|
+
const gasLimit = await transfer.estimateGas({
|
|
160
|
+
from: metadata.receiverAddress
|
|
161
|
+
});
|
|
162
|
+
const priority = await (0, _utils2.calculateGasFeeParams)(evmApi, evmApi.chainSlug);
|
|
163
|
+
return {
|
|
164
|
+
from: metadata.receiverAddress,
|
|
165
|
+
to: availBridgeContractAddress,
|
|
166
|
+
value: '0',
|
|
167
|
+
data: transferData,
|
|
168
|
+
gasPrice: priority.gasPrice,
|
|
169
|
+
maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
|
|
170
|
+
maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString(),
|
|
171
|
+
gas: gasLimit
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function getAddressMessage(notification) {
|
|
175
|
+
const metadata = notification.metadata;
|
|
176
|
+
return {
|
|
177
|
+
message: {
|
|
178
|
+
FungibleToken: {
|
|
179
|
+
assetId: AvailBridgeConfig.ASSET_ID,
|
|
180
|
+
amount: metadata.amount
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
from: `${metadata.depositorAddress.padEnd(66, '0')}`,
|
|
184
|
+
to: (0, _util.u8aToHex)((0, _keyring.decodeAddress)(metadata.receiverAddress)),
|
|
185
|
+
originDomain: AvailBridgeConfig.ETHEREUM_DOMAIN,
|
|
186
|
+
destinationDomain: AvailBridgeConfig.AVAIL_DOMAIN,
|
|
187
|
+
id: metadata.messageId
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function getAvailBridgeAbi(chainSlug) {
|
|
191
|
+
if (chainSlug === _chainList.COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
|
|
192
|
+
return _utils._AVAIL_TEST_BRIDGE_GATEWAY_ABI;
|
|
193
|
+
}
|
|
194
|
+
return _utils._AVAIL_BRIDGE_GATEWAY_ABI;
|
|
195
|
+
}
|
|
196
|
+
function isAvailChainBridge(chainSlug) {
|
|
197
|
+
return ['avail_mainnet', 'availTuringTest'].includes(chainSlug);
|
|
198
|
+
}
|
|
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.getXcmMockTxFee = exports.createXcmExtrinsic = exports.createSnowBridgeExtrinsic = void 0;
|
|
7
|
+
exports.getXcmMockTxFee = exports.createXcmExtrinsic = exports.createSnowBridgeExtrinsic = exports.createAvailBridgeTxFromEth = exports.createAvailBridgeExtrinsicFromAvail = void 0;
|
|
8
8
|
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
9
|
+
var _availBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge");
|
|
9
10
|
var _polkadotXcm = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm");
|
|
10
11
|
var _snowBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge");
|
|
11
12
|
var _xcmPallet = require("@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet");
|
|
@@ -33,6 +34,12 @@ const createSnowBridgeExtrinsic = async _ref => {
|
|
|
33
34
|
if (!(0, _xcmParser._isSnowBridgeXcm)(originChainInfo, destinationChainInfo)) {
|
|
34
35
|
throw new Error('This is not a valid SnowBridge transfer');
|
|
35
36
|
}
|
|
37
|
+
if (!evmApi) {
|
|
38
|
+
throw Error('Evm API is not available');
|
|
39
|
+
}
|
|
40
|
+
if (!sender) {
|
|
41
|
+
throw Error('Sender is required');
|
|
42
|
+
}
|
|
36
43
|
return (0, _snowBridge.getSnowBridgeEvmTransfer)(originTokenInfo, originChainInfo, destinationChainInfo, sender, recipient, sendingValue, evmApi);
|
|
37
44
|
};
|
|
38
45
|
exports.createSnowBridgeExtrinsic = createSnowBridgeExtrinsic;
|
|
@@ -47,6 +54,9 @@ const createXcmExtrinsic = async _ref2 => {
|
|
|
47
54
|
} = _ref2;
|
|
48
55
|
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
49
56
|
const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
57
|
+
if (!substrateApi) {
|
|
58
|
+
throw Error('Substrate API is not available');
|
|
59
|
+
}
|
|
50
60
|
const chainApi = await substrateApi.isReady;
|
|
51
61
|
const api = chainApi.api;
|
|
52
62
|
const polkadotXcmSpecialCases = _constants._XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChainInfo.slug) && (0, _utils._isNativeToken)(originTokenInfo);
|
|
@@ -59,24 +69,59 @@ const createXcmExtrinsic = async _ref2 => {
|
|
|
59
69
|
return (0, _xTokens.getExtrinsicByXtokensPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
60
70
|
};
|
|
61
71
|
exports.createXcmExtrinsic = createXcmExtrinsic;
|
|
72
|
+
const createAvailBridgeTxFromEth = _ref3 => {
|
|
73
|
+
let {
|
|
74
|
+
chainInfoMap,
|
|
75
|
+
evmApi,
|
|
76
|
+
originTokenInfo,
|
|
77
|
+
recipient,
|
|
78
|
+
sender,
|
|
79
|
+
sendingValue
|
|
80
|
+
} = _ref3;
|
|
81
|
+
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
82
|
+
if (!evmApi) {
|
|
83
|
+
throw Error('Evm API is not available');
|
|
84
|
+
}
|
|
85
|
+
if (!sender) {
|
|
86
|
+
throw Error('Sender is required');
|
|
87
|
+
}
|
|
88
|
+
return (0, _availBridge.getAvailBridgeTxFromEth)(originChainInfo, sender, recipient, sendingValue, evmApi);
|
|
89
|
+
};
|
|
90
|
+
exports.createAvailBridgeTxFromEth = createAvailBridgeTxFromEth;
|
|
91
|
+
const createAvailBridgeExtrinsicFromAvail = async _ref4 => {
|
|
92
|
+
let {
|
|
93
|
+
recipient,
|
|
94
|
+
sendingValue,
|
|
95
|
+
substrateApi
|
|
96
|
+
} = _ref4;
|
|
97
|
+
if (!substrateApi) {
|
|
98
|
+
throw Error('Substrate API is not available');
|
|
99
|
+
}
|
|
100
|
+
return await (0, _availBridge.getAvailBridgeExtrinsicFromAvail)(recipient, sendingValue, substrateApi);
|
|
101
|
+
};
|
|
102
|
+
exports.createAvailBridgeExtrinsicFromAvail = createAvailBridgeExtrinsicFromAvail;
|
|
62
103
|
const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
|
|
63
104
|
try {
|
|
64
105
|
var _paymentInfo$partialF;
|
|
65
106
|
const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
66
107
|
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
67
|
-
const
|
|
108
|
+
const fakeAddress = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
|
|
109
|
+
const substrateAddress = fakeAddress; // todo: move this
|
|
110
|
+
const evmAddress = (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(fakeAddress)); // todo: move this
|
|
68
111
|
|
|
69
112
|
// mock receiving account from sender
|
|
70
|
-
const
|
|
113
|
+
const sender = (0, _utils._isChainEvmCompatible)(originChainInfo) ? evmAddress : substrateAddress;
|
|
114
|
+
const recipient = (0, _utils._isChainEvmCompatible)(destChainInfo) ? evmAddress : substrateAddress;
|
|
71
115
|
const mockTx = await createXcmExtrinsic({
|
|
72
116
|
chainInfoMap,
|
|
73
117
|
destinationTokenInfo,
|
|
74
118
|
originTokenInfo,
|
|
75
|
-
|
|
119
|
+
sender,
|
|
120
|
+
recipient,
|
|
76
121
|
sendingValue: '1000000000000000000',
|
|
77
122
|
substrateApi
|
|
78
123
|
});
|
|
79
|
-
const paymentInfo = await mockTx.paymentInfo(
|
|
124
|
+
const paymentInfo = await mockTx.paymentInfo(fakeAddress);
|
|
80
125
|
return new _bignumber.default((paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0');
|
|
81
126
|
} catch (e) {
|
|
82
127
|
console.error('error mocking xcm tx fee', e);
|
|
@@ -65,7 +65,8 @@ const _NFT_CHAIN_GROUP = {
|
|
|
65
65
|
bitcountry: ['bitcountry', 'pioneer', 'continuum_network'],
|
|
66
66
|
vara: ['vara_network'],
|
|
67
67
|
avail: ['avail_mainnet'],
|
|
68
|
-
ternoa: ['ternoa', 'ternoa_alphanet']
|
|
68
|
+
ternoa: ['ternoa', 'ternoa_alphanet'],
|
|
69
|
+
rari: ['rari']
|
|
69
70
|
};
|
|
70
71
|
|
|
71
72
|
// Staking--------------------------------------------------------------------------------------------------------------
|
|
@@ -80,15 +80,11 @@ class EvmApi {
|
|
|
80
80
|
createIntervalCheckApi() {
|
|
81
81
|
this.clearIntervalCheckApi();
|
|
82
82
|
return setInterval(() => {
|
|
83
|
-
|
|
84
|
-
this.api.eth.net.isListening().then(() => {
|
|
85
|
-
this.onConnect();
|
|
86
|
-
}).catch(() => {
|
|
87
|
-
this.onDisconnect();
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
83
|
+
this.api.eth.getChainId().then(() => {
|
|
90
84
|
this.onConnect();
|
|
91
|
-
}
|
|
85
|
+
}).catch(() => {
|
|
86
|
+
this.onDisconnect();
|
|
87
|
+
});
|
|
92
88
|
}, 10000);
|
|
93
89
|
}
|
|
94
90
|
clearIntervalCheckApi() {
|
|
@@ -101,21 +97,16 @@ class EvmApi {
|
|
|
101
97
|
this.updateConnectionStatus(_types._ChainConnectionStatus.CONNECTING);
|
|
102
98
|
|
|
103
99
|
// Check if api is ready
|
|
104
|
-
|
|
105
|
-
this.api.eth.net.isListening().then(() => {
|
|
106
|
-
this.isApiReadyOnce = true;
|
|
107
|
-
this.onConnect();
|
|
108
|
-
}).catch(error => {
|
|
109
|
-
this.isApiReadyOnce = false;
|
|
110
|
-
this.isApiReady = false;
|
|
111
|
-
this.isReadyHandler.reject(error);
|
|
112
|
-
this.updateConnectionStatus(_types._ChainConnectionStatus.DISCONNECTED);
|
|
113
|
-
console.warn(`Can not connect to ${this.chainSlug} (EVM) at ${this.apiUrl}`);
|
|
114
|
-
});
|
|
115
|
-
} else {
|
|
100
|
+
this.api.eth.getChainId().then(() => {
|
|
116
101
|
this.isApiReadyOnce = true;
|
|
117
102
|
this.onConnect();
|
|
118
|
-
}
|
|
103
|
+
}).catch(error => {
|
|
104
|
+
this.isApiReadyOnce = false;
|
|
105
|
+
this.isApiReady = false;
|
|
106
|
+
this.isReadyHandler.reject(error);
|
|
107
|
+
this.updateConnectionStatus(_types._ChainConnectionStatus.DISCONNECTED);
|
|
108
|
+
console.warn(`Can not connect to ${this.chainSlug} (EVM) at ${this.apiUrl}`);
|
|
109
|
+
});
|
|
119
110
|
|
|
120
111
|
// Interval to check connecting status
|
|
121
112
|
this.intervalCheckApi = this.createIntervalCheckApi();
|
|
@@ -118,7 +118,6 @@ class EvmChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
118
118
|
const evmApi = this.getEvmApiByChain(originChain);
|
|
119
119
|
try {
|
|
120
120
|
if (tokenType === _types._AssetType.ERC721) {
|
|
121
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
122
121
|
tokenContract = new evmApi.api.eth.Contract(_utils._ERC721_ABI, contractAddress);
|
|
123
122
|
const [_name, _symbol] = await Promise.all([
|
|
124
123
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
@@ -128,7 +127,6 @@ class EvmChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
128
127
|
name = _name;
|
|
129
128
|
symbol = _symbol;
|
|
130
129
|
} else {
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
132
130
|
tokenContract = new evmApi.api.eth.Contract(_utils._ERC20_ABI, contractAddress);
|
|
133
131
|
const [_decimals, _symbol, _name] = await Promise.all([
|
|
134
132
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
@@ -114,6 +114,12 @@ class SubstrateChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
114
114
|
}
|
|
115
115
|
async getPsp22TokenInfo(apiPromise, contractAddress, contractCaller) {
|
|
116
116
|
const tokenContract = new _apiContract.ContractPromise(apiPromise, _utils3._PSP22_ABI, contractAddress);
|
|
117
|
+
const tokenSmartContract = {
|
|
118
|
+
name: '',
|
|
119
|
+
decimals: -1,
|
|
120
|
+
symbol: '',
|
|
121
|
+
contractError: false
|
|
122
|
+
};
|
|
117
123
|
const [nameResp, symbolResp, decimalsResp] = await Promise.all([tokenContract.query['psp22Metadata::tokenName'](contractCaller || contractAddress, {
|
|
118
124
|
gasLimit: (0, _utils.getDefaultWeightV2)(apiPromise)
|
|
119
125
|
}),
|
|
@@ -124,91 +130,118 @@ class SubstrateChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
124
130
|
gasLimit: (0, _utils.getDefaultWeightV2)(apiPromise)
|
|
125
131
|
})]);
|
|
126
132
|
if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
|
|
127
|
-
|
|
133
|
+
tokenSmartContract.contractError = true;
|
|
134
|
+
return tokenSmartContract;
|
|
128
135
|
} else {
|
|
129
136
|
var _symbolResp$output, _decimalsResp$output, _nameResp$output;
|
|
130
|
-
let contractError = false;
|
|
131
137
|
const symbolObj = (_symbolResp$output = symbolResp.output) === null || _symbolResp$output === void 0 ? void 0 : _symbolResp$output.toHuman();
|
|
132
138
|
const decimalsObj = (_decimalsResp$output = decimalsResp.output) === null || _decimalsResp$output === void 0 ? void 0 : _decimalsResp$output.toHuman();
|
|
133
139
|
const nameObj = (_nameResp$output = nameResp.output) === null || _nameResp$output === void 0 ? void 0 : _nameResp$output.toHuman();
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (!name || !symbol || typeof name === 'object' || typeof symbol === 'object') {
|
|
138
|
-
contractError = true;
|
|
140
|
+
tokenSmartContract.name = nameResp.output ? nameObj.Ok || nameObj.ok : '';
|
|
141
|
+
tokenSmartContract.decimals = decimalsResp.output ? new _util.BN(decimalsObj.Ok || decimalsObj.ok).toNumber() : 0;
|
|
142
|
+
tokenSmartContract.symbol = decimalsResp.output ? symbolObj.Ok || symbolObj.ok : '';
|
|
143
|
+
if (!tokenSmartContract.name || !tokenSmartContract.symbol || typeof tokenSmartContract.name === 'object' || typeof tokenSmartContract.symbol === 'object') {
|
|
144
|
+
tokenSmartContract.contractError = true;
|
|
139
145
|
}
|
|
140
|
-
return
|
|
146
|
+
return tokenSmartContract;
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
async getPsp34TokenInfo(apiPromise, contractAddress, contractCaller) {
|
|
144
150
|
const tokenContract = new _apiContract.ContractPromise(apiPromise, _utils3._PSP34_ABI, contractAddress);
|
|
151
|
+
const tokenSmartContract = {
|
|
152
|
+
name: '',
|
|
153
|
+
decimals: -1,
|
|
154
|
+
symbol: '',
|
|
155
|
+
contractError: false
|
|
156
|
+
};
|
|
145
157
|
const collectionIdResp = await tokenContract.query['psp34::collectionId'](contractCaller || contractAddress, {
|
|
146
158
|
gasLimit: (0, _utils.getDefaultWeightV2)(apiPromise)
|
|
147
159
|
}); // read-only operation so no gas limit
|
|
148
160
|
|
|
149
161
|
if (!collectionIdResp.result.isOk || !collectionIdResp.output) {
|
|
150
|
-
|
|
162
|
+
tokenSmartContract.contractError = true;
|
|
163
|
+
return tokenSmartContract;
|
|
151
164
|
} else {
|
|
152
165
|
var _collectionIdResp$out;
|
|
153
|
-
let contractError = false;
|
|
154
166
|
const collectionIdDict = (_collectionIdResp$out = collectionIdResp.output) === null || _collectionIdResp$out === void 0 ? void 0 : _collectionIdResp$out.toHuman();
|
|
155
167
|
if (collectionIdDict.Bytes === '') {
|
|
156
|
-
contractError = true;
|
|
168
|
+
tokenSmartContract.contractError = true;
|
|
157
169
|
}
|
|
158
|
-
return
|
|
170
|
+
return tokenSmartContract;
|
|
159
171
|
}
|
|
160
172
|
}
|
|
161
|
-
async
|
|
173
|
+
async getVaraFungibleTokenInfo(apiPromise, contractAddress, tokenType) {
|
|
174
|
+
const tokenSmartContract = {
|
|
175
|
+
name: '',
|
|
176
|
+
decimals: -1,
|
|
177
|
+
symbol: '',
|
|
178
|
+
contractError: false
|
|
179
|
+
};
|
|
162
180
|
if (!(apiPromise instanceof _api.GearApi)) {
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
if (tokenType === _types._AssetType.GRC20) {
|
|
182
|
+
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
183
|
+
} else if (tokenType === _types._AssetType.VFT) {
|
|
184
|
+
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
185
|
+
}
|
|
186
|
+
tokenSmartContract.contractError = true;
|
|
187
|
+
return tokenSmartContract;
|
|
165
188
|
}
|
|
166
|
-
|
|
167
|
-
const tokenContract = (0, _utils2.getGRC20ContractPromise)(apiPromise, contractAddress);
|
|
189
|
+
const tokenContract = tokenType === _types._AssetType.GRC20 ? (0, _utils2.getGRC20ContractPromise)(apiPromise, contractAddress) : (0, _utils2.getVFTContractPromise)(apiPromise, contractAddress);
|
|
168
190
|
const [nameRes, symbolRes, decimalsRes] = await Promise.all([tokenContract.service.name(_utils2.GEAR_DEFAULT_ADDRESS), tokenContract.service.symbol(_utils2.GEAR_DEFAULT_ADDRESS), tokenContract.service.decimals(_utils2.GEAR_DEFAULT_ADDRESS)]);
|
|
169
|
-
const decimals =
|
|
191
|
+
const decimals = parseInt(decimalsRes.toString());
|
|
192
|
+
tokenSmartContract.name = nameRes;
|
|
193
|
+
tokenSmartContract.decimals = decimals;
|
|
194
|
+
tokenSmartContract.symbol = symbolRes;
|
|
170
195
|
if (!nameRes || !symbolRes) {
|
|
171
|
-
contractError = true;
|
|
196
|
+
tokenSmartContract.contractError = true;
|
|
172
197
|
}
|
|
173
|
-
return
|
|
198
|
+
return tokenSmartContract;
|
|
174
199
|
}
|
|
175
|
-
async
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
200
|
+
async getLocalTokenInfo(apiPromise, assetId) {
|
|
201
|
+
const _metadata = await apiPromise.query.assets.metadata(assetId);
|
|
202
|
+
const metadata = _metadata.toPrimitive();
|
|
203
|
+
let idError = false;
|
|
204
|
+
if (!metadata.name || !metadata.symbol) {
|
|
205
|
+
idError = true;
|
|
179
206
|
}
|
|
180
|
-
|
|
181
|
-
const tokenContract = (0, _utils2.getVFTContractPromise)(apiPromise, contractAddress);
|
|
182
|
-
const [nameRes, symbolRes, decimalsRes] = await Promise.all([tokenContract.service.name(_utils2.GEAR_DEFAULT_ADDRESS), tokenContract.service.symbol(_utils2.GEAR_DEFAULT_ADDRESS), tokenContract.service.decimals(_utils2.GEAR_DEFAULT_ADDRESS)]);
|
|
183
|
-
const decimals = typeof decimalsRes === 'string' ? parseInt(decimalsRes) : decimalsRes;
|
|
184
|
-
if (!nameRes || !symbolRes) {
|
|
185
|
-
contractError = true;
|
|
186
|
-
}
|
|
187
|
-
return [nameRes, decimals, symbolRes, contractError];
|
|
207
|
+
return [metadata.name, metadata.decimals, metadata.symbol, idError];
|
|
188
208
|
}
|
|
189
209
|
async getSubstrateContractTokenInfo(contractAddress, tokenType, originChain, contractCaller) {
|
|
190
210
|
// todo: improve this funtion later
|
|
191
211
|
|
|
192
|
-
let
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
212
|
+
let tokenSmartContract = {
|
|
213
|
+
name: '',
|
|
214
|
+
decimals: -1,
|
|
215
|
+
symbol: '',
|
|
216
|
+
contractError: false
|
|
217
|
+
};
|
|
196
218
|
const apiPromise = this.getSubstrateApiByChain(originChain).api;
|
|
197
219
|
try {
|
|
198
220
|
switch (tokenType) {
|
|
199
221
|
case _types._AssetType.PSP22:
|
|
200
|
-
|
|
222
|
+
tokenSmartContract = await this.getPsp22TokenInfo(apiPromise, contractAddress, contractCaller);
|
|
201
223
|
break;
|
|
202
224
|
case _types._AssetType.PSP34:
|
|
203
|
-
|
|
225
|
+
tokenSmartContract = await this.getPsp34TokenInfo(apiPromise, contractAddress, contractCaller);
|
|
204
226
|
break;
|
|
205
227
|
case _types._AssetType.GRC20:
|
|
206
|
-
|
|
228
|
+
tokenSmartContract = await this.getVaraFungibleTokenInfo(apiPromise, contractAddress, tokenType);
|
|
207
229
|
break;
|
|
208
230
|
case _types._AssetType.VFT:
|
|
209
|
-
|
|
231
|
+
tokenSmartContract = await this.getVaraFungibleTokenInfo(apiPromise, contractAddress, tokenType);
|
|
210
232
|
break;
|
|
211
233
|
}
|
|
234
|
+
return tokenSmartContract;
|
|
235
|
+
} catch (e) {
|
|
236
|
+
this.logger.error(e);
|
|
237
|
+
tokenSmartContract.contractError = true;
|
|
238
|
+
return tokenSmartContract;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async getSubstrateAssetIdTokenInfo(assetId, originChain) {
|
|
242
|
+
const apiPromise = this.getSubstrateApiByChain(originChain).api;
|
|
243
|
+
try {
|
|
244
|
+
const [name, decimals, symbol, contractError] = await this.getLocalTokenInfo(apiPromise, assetId);
|
|
212
245
|
return {
|
|
213
246
|
name,
|
|
214
247
|
decimals,
|