@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { BalanceError } from '@subwallet/extension-base/background/errors/BalanceError';
|
|
5
|
-
import { BalanceErrorType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { APIItemState, BalanceErrorType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { _isXcmWithinSameConsensus } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
8
8
|
import { getDefaultTransferProcess, getSnowbridgeTransferProcessFromEvm } from '@subwallet/extension-base/services/balance-service/helpers/process';
|
|
@@ -193,7 +193,7 @@ export class BalanceService {
|
|
|
193
193
|
let unsub = noop;
|
|
194
194
|
unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, result => {
|
|
195
195
|
const rs = result[0];
|
|
196
|
-
if (rs.tokenSlug === tSlug) {
|
|
196
|
+
if (rs.tokenSlug === tSlug && rs.state !== APIItemState.PENDING) {
|
|
197
197
|
hasError = false;
|
|
198
198
|
const balance = {
|
|
199
199
|
value: rs.free,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
+
import { _NotificationInfo } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
|
|
4
|
+
import { TransactionConfig } from 'web3-core';
|
|
5
|
+
export declare const AvailBridgeConfig: {
|
|
6
|
+
ASSET_ID: string;
|
|
7
|
+
ETHEREUM_DOMAIN: number;
|
|
8
|
+
AVAIL_DOMAIN: number;
|
|
9
|
+
};
|
|
10
|
+
export interface merkleProof {
|
|
11
|
+
blobRoot: string;
|
|
12
|
+
blockHash: string;
|
|
13
|
+
bridgeRoot: string;
|
|
14
|
+
dataRoot: string;
|
|
15
|
+
dataRootCommitment: string;
|
|
16
|
+
dataRootIndex: number;
|
|
17
|
+
dataRootProof: DataRootProof;
|
|
18
|
+
leaf: string;
|
|
19
|
+
leafIndex: number;
|
|
20
|
+
leafProof: LeafProof;
|
|
21
|
+
message: Message;
|
|
22
|
+
rangeHash: string;
|
|
23
|
+
}
|
|
24
|
+
declare type DataRootProof = `0x${string}`[];
|
|
25
|
+
declare type LeafProof = `0x${string}`[];
|
|
26
|
+
declare type Message = {
|
|
27
|
+
destinationDomain: number;
|
|
28
|
+
from: string;
|
|
29
|
+
id: number;
|
|
30
|
+
message: {
|
|
31
|
+
fungibleToken: {
|
|
32
|
+
amount: bigint;
|
|
33
|
+
asset_id: `0x${string}`;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
originDomain: number;
|
|
37
|
+
to: string;
|
|
38
|
+
messageType: string;
|
|
39
|
+
};
|
|
40
|
+
export declare function getAvailBridgeTxFromEth(originChainInfo: _ChainInfo, sender: string, recipient: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
|
|
41
|
+
export declare function getAvailBridgeExtrinsicFromAvail(recipient: string, sendingValue: string, substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
42
|
+
export declare function getClaimTxOnAvail(notification: _NotificationInfo, substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
43
|
+
export declare function getClaimTxOnEthereum(chainSlug: string, notification: _NotificationInfo, evmApi: _EvmApi): Promise<TransactionConfig>;
|
|
44
|
+
export declare function isAvailChainBridge(chainSlug: string): boolean;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
|
+
import { getWeb3Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
6
|
+
import { _AVAIL_BRIDGE_GATEWAY_ABI, _AVAIL_TEST_BRIDGE_GATEWAY_ABI, getAvailBridgeGatewayContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
7
|
+
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
8
|
+
import { AVAIL_BRIDGE_API } from '@subwallet/extension-base/services/inapp-notification-service/utils';
|
|
9
|
+
import { decodeAddress } from '@subwallet/keyring';
|
|
10
|
+
import { u8aToHex } from '@polkadot/util';
|
|
11
|
+
export const AvailBridgeConfig = {
|
|
12
|
+
ASSET_ID: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
13
|
+
ETHEREUM_DOMAIN: 2,
|
|
14
|
+
// todo: check if these config can change later
|
|
15
|
+
AVAIL_DOMAIN: 1
|
|
16
|
+
};
|
|
17
|
+
export async function getAvailBridgeTxFromEth(originChainInfo, sender, recipient, value, evmApi) {
|
|
18
|
+
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
19
|
+
const availBridgeContractAddress = getAvailBridgeGatewayContract(originChainInfo.slug);
|
|
20
|
+
const ABI = getAvailBridgeAbi(originChainInfo.slug);
|
|
21
|
+
const availBridgeContract = getWeb3Contract(availBridgeContractAddress, evmApi, ABI);
|
|
22
|
+
const _address = u8aToHex(decodeAddress(recipient));
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
24
|
+
const sendAvail = availBridgeContract.methods.sendAVAIL(_address, value);
|
|
25
|
+
const transferData = sendAvail.encodeABI();
|
|
26
|
+
const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
|
|
27
|
+
const gasLimit = await sendAvail.estimateGas({
|
|
28
|
+
from: sender
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
from: sender,
|
|
32
|
+
to: availBridgeContractAddress,
|
|
33
|
+
value: '0',
|
|
34
|
+
data: transferData,
|
|
35
|
+
gasPrice: priority.gasPrice,
|
|
36
|
+
maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
|
|
37
|
+
maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString(),
|
|
38
|
+
gas: gasLimit
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export async function getAvailBridgeExtrinsicFromAvail(recipient, sendingValue, substrateApi) {
|
|
42
|
+
const data = {
|
|
43
|
+
message: {
|
|
44
|
+
FungibleToken: {
|
|
45
|
+
assetId: AvailBridgeConfig.ASSET_ID,
|
|
46
|
+
amount: BigInt(sendingValue)
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
to: `${recipient.padEnd(66, '0')}`,
|
|
50
|
+
domain: AvailBridgeConfig.ETHEREUM_DOMAIN
|
|
51
|
+
};
|
|
52
|
+
const chainApi = await substrateApi.isReady;
|
|
53
|
+
return chainApi.api.tx.vector.sendMessage(data.message, data.to, data.domain);
|
|
54
|
+
}
|
|
55
|
+
export async function getClaimTxOnAvail(notification, substrateApi) {
|
|
56
|
+
const chainApi = await substrateApi.isReady;
|
|
57
|
+
const chainSlug = chainApi.chainSlug;
|
|
58
|
+
const metadata = notification.metadata;
|
|
59
|
+
const lastestEthHeadSlot = await getLastestEthHeadSlot(chainSlug);
|
|
60
|
+
const lastestBlockHash = await getLastestBlockHash(chainSlug, lastestEthHeadSlot);
|
|
61
|
+
const proof = await getClaimProofOnAvail(chainSlug, lastestBlockHash, metadata.messageId);
|
|
62
|
+
return chainApi.api.tx.vector.execute(lastestEthHeadSlot, getAddressMessage(notification), proof.accountProof, proof.storageProof);
|
|
63
|
+
}
|
|
64
|
+
async function getLastestEthHeadSlot(chainSlug) {
|
|
65
|
+
try {
|
|
66
|
+
const api = getAvailBridgeApi(chainSlug);
|
|
67
|
+
const rawResponse = await fetch(`${api}/eth/head`);
|
|
68
|
+
const response = await rawResponse.json();
|
|
69
|
+
return response.slot;
|
|
70
|
+
} catch (e) {
|
|
71
|
+
console.error(e);
|
|
72
|
+
throw e;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function getLastestBlockHash(chainSlug, slot) {
|
|
76
|
+
try {
|
|
77
|
+
const api = getAvailBridgeApi(chainSlug);
|
|
78
|
+
const rawResponse = await fetch(`${api}/beacon/slot/${slot}`);
|
|
79
|
+
const response = await rawResponse.json();
|
|
80
|
+
return response.blockHash;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.error(e);
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function getClaimProofOnAvail(chainSlug, blockHash, messageId) {
|
|
87
|
+
try {
|
|
88
|
+
const api = getAvailBridgeApi(chainSlug);
|
|
89
|
+
const rawResponse = await fetch(`${api}/avl/proof/${blockHash}/${messageId}`);
|
|
90
|
+
return await rawResponse.json();
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.error(e);
|
|
93
|
+
throw e;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function getClaimProofOnEthereum(chainSlug, blockHash, transactionIndex) {
|
|
97
|
+
try {
|
|
98
|
+
const api = getAvailBridgeApi(chainSlug);
|
|
99
|
+
const rawResponse = await fetch(`${api}/eth/proof/${blockHash}?index=${transactionIndex}`);
|
|
100
|
+
return await rawResponse.json();
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error(e);
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function getAvailBridgeApi(chainSlug) {
|
|
107
|
+
if (chainSlug === 'avail_mainnet' || chainSlug === COMMON_CHAIN_SLUGS.ETHEREUM) {
|
|
108
|
+
// todo: add COMMON_CHAIN_SLUGS for AVAIL, AVAIL TURING
|
|
109
|
+
return AVAIL_BRIDGE_API.AVAIL_MAINNET;
|
|
110
|
+
}
|
|
111
|
+
return AVAIL_BRIDGE_API.AVAIL_TESTNET;
|
|
112
|
+
}
|
|
113
|
+
export async function getClaimTxOnEthereum(chainSlug, notification, evmApi) {
|
|
114
|
+
var _priority$maxFeePerGa2, _priority$maxPriority2;
|
|
115
|
+
const availBridgeContractAddress = getAvailBridgeGatewayContract(chainSlug);
|
|
116
|
+
const ABI = getAvailBridgeAbi(chainSlug);
|
|
117
|
+
const availBridgeContract = getWeb3Contract(availBridgeContractAddress, evmApi, ABI);
|
|
118
|
+
const metadata = notification.metadata;
|
|
119
|
+
const merkleProof = await getClaimProofOnEthereum(chainSlug, metadata.sourceBlockHash, metadata.sourceTransactionIndex);
|
|
120
|
+
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
122
|
+
const transfer = availBridgeContract.methods.receiveAVAIL({
|
|
123
|
+
messageType: '0x02',
|
|
124
|
+
from: merkleProof.message.from,
|
|
125
|
+
to: merkleProof.message.to,
|
|
126
|
+
originDomain: merkleProof.message.originDomain,
|
|
127
|
+
destinationDomain: merkleProof.message.destinationDomain,
|
|
128
|
+
data: evmApi.api.eth.abi.encodeParameters([{
|
|
129
|
+
name: 'assetId',
|
|
130
|
+
type: 'bytes32'
|
|
131
|
+
}, {
|
|
132
|
+
name: 'amount',
|
|
133
|
+
type: 'uint256'
|
|
134
|
+
}], [merkleProof.message.message.fungibleToken.asset_id, BigInt(merkleProof.message.message.fungibleToken.amount)]),
|
|
135
|
+
messageId: merkleProof.message.id
|
|
136
|
+
}, {
|
|
137
|
+
dataRootProof: merkleProof.dataRootProof,
|
|
138
|
+
leafProof: merkleProof.leafProof,
|
|
139
|
+
rangeHash: merkleProof.rangeHash,
|
|
140
|
+
dataRootIndex: merkleProof.dataRootIndex,
|
|
141
|
+
blobRoot: merkleProof.blobRoot,
|
|
142
|
+
bridgeRoot: merkleProof.bridgeRoot,
|
|
143
|
+
leaf: merkleProof.leaf,
|
|
144
|
+
leafIndex: merkleProof.leafIndex
|
|
145
|
+
});
|
|
146
|
+
const transferData = transfer.encodeABI();
|
|
147
|
+
const gasLimit = await transfer.estimateGas({
|
|
148
|
+
from: metadata.receiverAddress
|
|
149
|
+
});
|
|
150
|
+
const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
|
|
151
|
+
return {
|
|
152
|
+
from: metadata.receiverAddress,
|
|
153
|
+
to: availBridgeContractAddress,
|
|
154
|
+
value: '0',
|
|
155
|
+
data: transferData,
|
|
156
|
+
gasPrice: priority.gasPrice,
|
|
157
|
+
maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
|
|
158
|
+
maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString(),
|
|
159
|
+
gas: gasLimit
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function getAddressMessage(notification) {
|
|
163
|
+
const metadata = notification.metadata;
|
|
164
|
+
return {
|
|
165
|
+
message: {
|
|
166
|
+
FungibleToken: {
|
|
167
|
+
assetId: AvailBridgeConfig.ASSET_ID,
|
|
168
|
+
amount: metadata.amount
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
from: `${metadata.depositorAddress.padEnd(66, '0')}`,
|
|
172
|
+
to: u8aToHex(decodeAddress(metadata.receiverAddress)),
|
|
173
|
+
originDomain: AvailBridgeConfig.ETHEREUM_DOMAIN,
|
|
174
|
+
destinationDomain: AvailBridgeConfig.AVAIL_DOMAIN,
|
|
175
|
+
id: metadata.messageId
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function getAvailBridgeAbi(chainSlug) {
|
|
179
|
+
if (chainSlug === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
|
|
180
|
+
return _AVAIL_TEST_BRIDGE_GATEWAY_ABI;
|
|
181
|
+
}
|
|
182
|
+
return _AVAIL_BRIDGE_GATEWAY_ABI;
|
|
183
|
+
}
|
|
184
|
+
export function isAvailChainBridge(chainSlug) {
|
|
185
|
+
return ['avail_mainnet', 'availTuringTest'].includes(chainSlug);
|
|
186
|
+
}
|
|
@@ -3,19 +3,19 @@ import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain
|
|
|
3
3
|
import BigN from 'bignumber.js';
|
|
4
4
|
import { TransactionConfig } from 'web3-core';
|
|
5
5
|
import { SubmittableExtrinsic } from '@polkadot/api/types';
|
|
6
|
-
declare type CreateXcmExtrinsicProps = {
|
|
6
|
+
export declare type CreateXcmExtrinsicProps = {
|
|
7
7
|
originTokenInfo: _ChainAsset;
|
|
8
8
|
destinationTokenInfo: _ChainAsset;
|
|
9
9
|
recipient: string;
|
|
10
10
|
sendingValue: string;
|
|
11
|
-
|
|
11
|
+
evmApi?: _EvmApi;
|
|
12
|
+
substrateApi?: _SubstrateApi;
|
|
12
13
|
chainInfoMap: Record<string, _ChainInfo>;
|
|
14
|
+
sender?: string;
|
|
13
15
|
};
|
|
14
|
-
declare type
|
|
15
|
-
|
|
16
|
-
sender: string;
|
|
17
|
-
};
|
|
18
|
-
export declare const createSnowBridgeExtrinsic: ({ chainInfoMap, destinationTokenInfo, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateSnowBridgeExtrinsicProps) => Promise<TransactionConfig>;
|
|
16
|
+
export declare type FunctionCreateXcmExtrinsic = (props: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | TransactionConfig>;
|
|
17
|
+
export declare const createSnowBridgeExtrinsic: ({ chainInfoMap, destinationTokenInfo, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
19
18
|
export declare const createXcmExtrinsic: ({ chainInfoMap, destinationTokenInfo, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
19
|
+
export declare const createAvailBridgeTxFromEth: ({ chainInfoMap, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
20
|
+
export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
20
21
|
export declare const getXcmMockTxFee: (substrateApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>, originTokenInfo: _ChainAsset, destinationTokenInfo: _ChainAsset) => Promise<BigN>;
|
|
21
|
-
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
+
import { getAvailBridgeExtrinsicFromAvail, getAvailBridgeTxFromEth } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
5
6
|
import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
|
|
6
7
|
import { getSnowBridgeEvmTransfer } from '@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge';
|
|
7
8
|
import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet';
|
|
@@ -10,7 +11,7 @@ import { _XCM_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-servi
|
|
|
10
11
|
import { _isChainEvmCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
11
12
|
import BigN from 'bignumber.js';
|
|
12
13
|
import { u8aToHex } from '@polkadot/util';
|
|
13
|
-
import { addressToEvm
|
|
14
|
+
import { addressToEvm } from '@polkadot/util-crypto';
|
|
14
15
|
export const createSnowBridgeExtrinsic = async ({
|
|
15
16
|
chainInfoMap,
|
|
16
17
|
destinationTokenInfo,
|
|
@@ -25,6 +26,12 @@ export const createSnowBridgeExtrinsic = async ({
|
|
|
25
26
|
if (!_isSnowBridgeXcm(originChainInfo, destinationChainInfo)) {
|
|
26
27
|
throw new Error('This is not a valid SnowBridge transfer');
|
|
27
28
|
}
|
|
29
|
+
if (!evmApi) {
|
|
30
|
+
throw Error('Evm API is not available');
|
|
31
|
+
}
|
|
32
|
+
if (!sender) {
|
|
33
|
+
throw Error('Sender is required');
|
|
34
|
+
}
|
|
28
35
|
return getSnowBridgeEvmTransfer(originTokenInfo, originChainInfo, destinationChainInfo, sender, recipient, sendingValue, evmApi);
|
|
29
36
|
};
|
|
30
37
|
export const createXcmExtrinsic = async ({
|
|
@@ -37,6 +44,9 @@ export const createXcmExtrinsic = async ({
|
|
|
37
44
|
}) => {
|
|
38
45
|
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
39
46
|
const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
47
|
+
if (!substrateApi) {
|
|
48
|
+
throw Error('Substrate API is not available');
|
|
49
|
+
}
|
|
40
50
|
const chainApi = await substrateApi.isReady;
|
|
41
51
|
const api = chainApi.api;
|
|
42
52
|
const polkadotXcmSpecialCases = _XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChainInfo.slug) && _isNativeToken(originTokenInfo);
|
|
@@ -48,24 +58,55 @@ export const createXcmExtrinsic = async ({
|
|
|
48
58
|
}
|
|
49
59
|
return getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
50
60
|
};
|
|
61
|
+
export const createAvailBridgeTxFromEth = ({
|
|
62
|
+
chainInfoMap,
|
|
63
|
+
evmApi,
|
|
64
|
+
originTokenInfo,
|
|
65
|
+
recipient,
|
|
66
|
+
sender,
|
|
67
|
+
sendingValue
|
|
68
|
+
}) => {
|
|
69
|
+
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
70
|
+
if (!evmApi) {
|
|
71
|
+
throw Error('Evm API is not available');
|
|
72
|
+
}
|
|
73
|
+
if (!sender) {
|
|
74
|
+
throw Error('Sender is required');
|
|
75
|
+
}
|
|
76
|
+
return getAvailBridgeTxFromEth(originChainInfo, sender, recipient, sendingValue, evmApi);
|
|
77
|
+
};
|
|
78
|
+
export const createAvailBridgeExtrinsicFromAvail = async ({
|
|
79
|
+
recipient,
|
|
80
|
+
sendingValue,
|
|
81
|
+
substrateApi
|
|
82
|
+
}) => {
|
|
83
|
+
if (!substrateApi) {
|
|
84
|
+
throw Error('Substrate API is not available');
|
|
85
|
+
}
|
|
86
|
+
return await getAvailBridgeExtrinsicFromAvail(recipient, sendingValue, substrateApi);
|
|
87
|
+
};
|
|
51
88
|
export const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
|
|
52
89
|
try {
|
|
53
90
|
var _paymentInfo$partialF;
|
|
54
91
|
const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
55
92
|
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
56
|
-
const
|
|
93
|
+
const fakeAddress = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
|
|
94
|
+
const substrateAddress = fakeAddress; // todo: move this
|
|
95
|
+
const evmAddress = u8aToHex(addressToEvm(fakeAddress)); // todo: move this
|
|
57
96
|
|
|
58
97
|
// mock receiving account from sender
|
|
59
|
-
const
|
|
98
|
+
const sender = _isChainEvmCompatible(originChainInfo) ? evmAddress : substrateAddress;
|
|
99
|
+
const recipient = _isChainEvmCompatible(destChainInfo) ? evmAddress : substrateAddress;
|
|
60
100
|
const mockTx = await createXcmExtrinsic({
|
|
61
101
|
chainInfoMap,
|
|
62
102
|
destinationTokenInfo,
|
|
63
103
|
originTokenInfo,
|
|
64
|
-
|
|
104
|
+
sender,
|
|
105
|
+
recipient,
|
|
65
106
|
sendingValue: '1000000000000000000',
|
|
66
107
|
substrateApi
|
|
67
108
|
});
|
|
68
|
-
const paymentInfo = await mockTx.paymentInfo(
|
|
109
|
+
const paymentInfo = await mockTx.paymentInfo(fakeAddress);
|
|
69
110
|
return new BigN((paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0');
|
|
70
111
|
} catch (e) {
|
|
71
112
|
console.error('error mocking xcm tx fee', e);
|
|
@@ -37,6 +37,7 @@ export declare const _NFT_CHAIN_GROUP: {
|
|
|
37
37
|
vara: string[];
|
|
38
38
|
avail: string[];
|
|
39
39
|
ternoa: string[];
|
|
40
|
+
rari: string[];
|
|
40
41
|
};
|
|
41
42
|
export declare const _STAKING_ERA_LENGTH_MAP: Record<string, number>;
|
|
42
43
|
export declare const _EXPECTED_BLOCK_TIME: Record<string, number>;
|
|
@@ -52,7 +52,8 @@ export const _NFT_CHAIN_GROUP = {
|
|
|
52
52
|
bitcountry: ['bitcountry', 'pioneer', 'continuum_network'],
|
|
53
53
|
vara: ['vara_network'],
|
|
54
54
|
avail: ['avail_mainnet'],
|
|
55
|
-
ternoa: ['ternoa', 'ternoa_alphanet']
|
|
55
|
+
ternoa: ['ternoa', 'ternoa_alphanet'],
|
|
56
|
+
rari: ['rari']
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
// Staking--------------------------------------------------------------------------------------------------------------
|
|
@@ -72,15 +72,11 @@ export class EvmApi {
|
|
|
72
72
|
createIntervalCheckApi() {
|
|
73
73
|
this.clearIntervalCheckApi();
|
|
74
74
|
return setInterval(() => {
|
|
75
|
-
|
|
76
|
-
this.api.eth.net.isListening().then(() => {
|
|
77
|
-
this.onConnect();
|
|
78
|
-
}).catch(() => {
|
|
79
|
-
this.onDisconnect();
|
|
80
|
-
});
|
|
81
|
-
} else {
|
|
75
|
+
this.api.eth.getChainId().then(() => {
|
|
82
76
|
this.onConnect();
|
|
83
|
-
}
|
|
77
|
+
}).catch(() => {
|
|
78
|
+
this.onDisconnect();
|
|
79
|
+
});
|
|
84
80
|
}, 10000);
|
|
85
81
|
}
|
|
86
82
|
clearIntervalCheckApi() {
|
|
@@ -93,21 +89,16 @@ export class EvmApi {
|
|
|
93
89
|
this.updateConnectionStatus(_ChainConnectionStatus.CONNECTING);
|
|
94
90
|
|
|
95
91
|
// Check if api is ready
|
|
96
|
-
|
|
97
|
-
this.api.eth.net.isListening().then(() => {
|
|
98
|
-
this.isApiReadyOnce = true;
|
|
99
|
-
this.onConnect();
|
|
100
|
-
}).catch(error => {
|
|
101
|
-
this.isApiReadyOnce = false;
|
|
102
|
-
this.isApiReady = false;
|
|
103
|
-
this.isReadyHandler.reject(error);
|
|
104
|
-
this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
|
|
105
|
-
console.warn(`Can not connect to ${this.chainSlug} (EVM) at ${this.apiUrl}`);
|
|
106
|
-
});
|
|
107
|
-
} else {
|
|
92
|
+
this.api.eth.getChainId().then(() => {
|
|
108
93
|
this.isApiReadyOnce = true;
|
|
109
94
|
this.onConnect();
|
|
110
|
-
}
|
|
95
|
+
}).catch(error => {
|
|
96
|
+
this.isApiReadyOnce = false;
|
|
97
|
+
this.isApiReady = false;
|
|
98
|
+
this.isReadyHandler.reject(error);
|
|
99
|
+
this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
|
|
100
|
+
console.warn(`Can not connect to ${this.chainSlug} (EVM) at ${this.apiUrl}`);
|
|
101
|
+
});
|
|
111
102
|
|
|
112
103
|
// Interval to check connecting status
|
|
113
104
|
this.intervalCheckApi = this.createIntervalCheckApi();
|
|
@@ -110,7 +110,6 @@ export class EvmChainHandler extends AbstractChainHandler {
|
|
|
110
110
|
const evmApi = this.getEvmApiByChain(originChain);
|
|
111
111
|
try {
|
|
112
112
|
if (tokenType === _AssetType.ERC721) {
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
114
113
|
tokenContract = new evmApi.api.eth.Contract(_ERC721_ABI, contractAddress);
|
|
115
114
|
const [_name, _symbol] = await Promise.all([
|
|
116
115
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
@@ -120,7 +119,6 @@ export class EvmChainHandler extends AbstractChainHandler {
|
|
|
120
119
|
name = _name;
|
|
121
120
|
symbol = _symbol;
|
|
122
121
|
} else {
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
124
122
|
tokenContract = new evmApi.api.eth.Contract(_ERC20_ABI, contractAddress);
|
|
125
123
|
const [_decimals, _symbol, _name] = await Promise.all([
|
|
126
124
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
@@ -17,9 +17,10 @@ export declare class SubstrateChainHandler extends AbstractChainHandler {
|
|
|
17
17
|
getChainSpec(substrateApi: _SubstrateApi): Promise<_SubstrateChainSpec>;
|
|
18
18
|
private getPsp22TokenInfo;
|
|
19
19
|
private getPsp34TokenInfo;
|
|
20
|
-
private
|
|
21
|
-
private
|
|
20
|
+
private getVaraFungibleTokenInfo;
|
|
21
|
+
private getLocalTokenInfo;
|
|
22
22
|
getSubstrateContractTokenInfo(contractAddress: string, tokenType: _AssetType, originChain: string, contractCaller?: string): Promise<_SmartContractTokenInfo>;
|
|
23
|
+
getSubstrateAssetIdTokenInfo(assetId: string, originChain: string): Promise<_SmartContractTokenInfo>;
|
|
23
24
|
setSubstrateApi(chainSlug: string, substrateApi: _SubstrateApi): void;
|
|
24
25
|
destroySubstrateApi(chainSlug: string): void;
|
|
25
26
|
initApi(chainSlug: string, apiUrl: string, { externalApiPromise, onUpdateStatus, providerName }?: Omit<_ApiOptions, 'metadata'>): Promise<_SubstrateApi>;
|
|
@@ -107,6 +107,12 @@ export class SubstrateChainHandler extends AbstractChainHandler {
|
|
|
107
107
|
}
|
|
108
108
|
async getPsp22TokenInfo(apiPromise, contractAddress, contractCaller) {
|
|
109
109
|
const tokenContract = new ContractPromise(apiPromise, _PSP22_ABI, contractAddress);
|
|
110
|
+
const tokenSmartContract = {
|
|
111
|
+
name: '',
|
|
112
|
+
decimals: -1,
|
|
113
|
+
symbol: '',
|
|
114
|
+
contractError: false
|
|
115
|
+
};
|
|
110
116
|
const [nameResp, symbolResp, decimalsResp] = await Promise.all([tokenContract.query['psp22Metadata::tokenName'](contractCaller || contractAddress, {
|
|
111
117
|
gasLimit: getDefaultWeightV2(apiPromise)
|
|
112
118
|
}),
|
|
@@ -117,91 +123,118 @@ export class SubstrateChainHandler extends AbstractChainHandler {
|
|
|
117
123
|
gasLimit: getDefaultWeightV2(apiPromise)
|
|
118
124
|
})]);
|
|
119
125
|
if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
|
|
120
|
-
|
|
126
|
+
tokenSmartContract.contractError = true;
|
|
127
|
+
return tokenSmartContract;
|
|
121
128
|
} else {
|
|
122
129
|
var _symbolResp$output, _decimalsResp$output, _nameResp$output;
|
|
123
|
-
let contractError = false;
|
|
124
130
|
const symbolObj = (_symbolResp$output = symbolResp.output) === null || _symbolResp$output === void 0 ? void 0 : _symbolResp$output.toHuman();
|
|
125
131
|
const decimalsObj = (_decimalsResp$output = decimalsResp.output) === null || _decimalsResp$output === void 0 ? void 0 : _decimalsResp$output.toHuman();
|
|
126
132
|
const nameObj = (_nameResp$output = nameResp.output) === null || _nameResp$output === void 0 ? void 0 : _nameResp$output.toHuman();
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!name || !symbol || typeof name === 'object' || typeof symbol === 'object') {
|
|
131
|
-
contractError = true;
|
|
133
|
+
tokenSmartContract.name = nameResp.output ? nameObj.Ok || nameObj.ok : '';
|
|
134
|
+
tokenSmartContract.decimals = decimalsResp.output ? new BN(decimalsObj.Ok || decimalsObj.ok).toNumber() : 0;
|
|
135
|
+
tokenSmartContract.symbol = decimalsResp.output ? symbolObj.Ok || symbolObj.ok : '';
|
|
136
|
+
if (!tokenSmartContract.name || !tokenSmartContract.symbol || typeof tokenSmartContract.name === 'object' || typeof tokenSmartContract.symbol === 'object') {
|
|
137
|
+
tokenSmartContract.contractError = true;
|
|
132
138
|
}
|
|
133
|
-
return
|
|
139
|
+
return tokenSmartContract;
|
|
134
140
|
}
|
|
135
141
|
}
|
|
136
142
|
async getPsp34TokenInfo(apiPromise, contractAddress, contractCaller) {
|
|
137
143
|
const tokenContract = new ContractPromise(apiPromise, _PSP34_ABI, contractAddress);
|
|
144
|
+
const tokenSmartContract = {
|
|
145
|
+
name: '',
|
|
146
|
+
decimals: -1,
|
|
147
|
+
symbol: '',
|
|
148
|
+
contractError: false
|
|
149
|
+
};
|
|
138
150
|
const collectionIdResp = await tokenContract.query['psp34::collectionId'](contractCaller || contractAddress, {
|
|
139
151
|
gasLimit: getDefaultWeightV2(apiPromise)
|
|
140
152
|
}); // read-only operation so no gas limit
|
|
141
153
|
|
|
142
154
|
if (!collectionIdResp.result.isOk || !collectionIdResp.output) {
|
|
143
|
-
|
|
155
|
+
tokenSmartContract.contractError = true;
|
|
156
|
+
return tokenSmartContract;
|
|
144
157
|
} else {
|
|
145
158
|
var _collectionIdResp$out;
|
|
146
|
-
let contractError = false;
|
|
147
159
|
const collectionIdDict = (_collectionIdResp$out = collectionIdResp.output) === null || _collectionIdResp$out === void 0 ? void 0 : _collectionIdResp$out.toHuman();
|
|
148
160
|
if (collectionIdDict.Bytes === '') {
|
|
149
|
-
contractError = true;
|
|
161
|
+
tokenSmartContract.contractError = true;
|
|
150
162
|
}
|
|
151
|
-
return
|
|
163
|
+
return tokenSmartContract;
|
|
152
164
|
}
|
|
153
165
|
}
|
|
154
|
-
async
|
|
166
|
+
async getVaraFungibleTokenInfo(apiPromise, contractAddress, tokenType) {
|
|
167
|
+
const tokenSmartContract = {
|
|
168
|
+
name: '',
|
|
169
|
+
decimals: -1,
|
|
170
|
+
symbol: '',
|
|
171
|
+
contractError: false
|
|
172
|
+
};
|
|
155
173
|
if (!(apiPromise instanceof GearApi)) {
|
|
156
|
-
|
|
157
|
-
|
|
174
|
+
if (tokenType === _AssetType.GRC20) {
|
|
175
|
+
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
176
|
+
} else if (tokenType === _AssetType.VFT) {
|
|
177
|
+
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
178
|
+
}
|
|
179
|
+
tokenSmartContract.contractError = true;
|
|
180
|
+
return tokenSmartContract;
|
|
158
181
|
}
|
|
159
|
-
|
|
160
|
-
const tokenContract = getGRC20ContractPromise(apiPromise, contractAddress);
|
|
182
|
+
const tokenContract = tokenType === _AssetType.GRC20 ? getGRC20ContractPromise(apiPromise, contractAddress) : getVFTContractPromise(apiPromise, contractAddress);
|
|
161
183
|
const [nameRes, symbolRes, decimalsRes] = await Promise.all([tokenContract.service.name(GEAR_DEFAULT_ADDRESS), tokenContract.service.symbol(GEAR_DEFAULT_ADDRESS), tokenContract.service.decimals(GEAR_DEFAULT_ADDRESS)]);
|
|
162
|
-
const decimals =
|
|
184
|
+
const decimals = parseInt(decimalsRes.toString());
|
|
185
|
+
tokenSmartContract.name = nameRes;
|
|
186
|
+
tokenSmartContract.decimals = decimals;
|
|
187
|
+
tokenSmartContract.symbol = symbolRes;
|
|
163
188
|
if (!nameRes || !symbolRes) {
|
|
164
|
-
contractError = true;
|
|
189
|
+
tokenSmartContract.contractError = true;
|
|
165
190
|
}
|
|
166
|
-
return
|
|
191
|
+
return tokenSmartContract;
|
|
167
192
|
}
|
|
168
|
-
async
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
193
|
+
async getLocalTokenInfo(apiPromise, assetId) {
|
|
194
|
+
const _metadata = await apiPromise.query.assets.metadata(assetId);
|
|
195
|
+
const metadata = _metadata.toPrimitive();
|
|
196
|
+
let idError = false;
|
|
197
|
+
if (!metadata.name || !metadata.symbol) {
|
|
198
|
+
idError = true;
|
|
172
199
|
}
|
|
173
|
-
|
|
174
|
-
const tokenContract = getVFTContractPromise(apiPromise, contractAddress);
|
|
175
|
-
const [nameRes, symbolRes, decimalsRes] = await Promise.all([tokenContract.service.name(GEAR_DEFAULT_ADDRESS), tokenContract.service.symbol(GEAR_DEFAULT_ADDRESS), tokenContract.service.decimals(GEAR_DEFAULT_ADDRESS)]);
|
|
176
|
-
const decimals = typeof decimalsRes === 'string' ? parseInt(decimalsRes) : decimalsRes;
|
|
177
|
-
if (!nameRes || !symbolRes) {
|
|
178
|
-
contractError = true;
|
|
179
|
-
}
|
|
180
|
-
return [nameRes, decimals, symbolRes, contractError];
|
|
200
|
+
return [metadata.name, metadata.decimals, metadata.symbol, idError];
|
|
181
201
|
}
|
|
182
202
|
async getSubstrateContractTokenInfo(contractAddress, tokenType, originChain, contractCaller) {
|
|
183
203
|
// todo: improve this funtion later
|
|
184
204
|
|
|
185
|
-
let
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
205
|
+
let tokenSmartContract = {
|
|
206
|
+
name: '',
|
|
207
|
+
decimals: -1,
|
|
208
|
+
symbol: '',
|
|
209
|
+
contractError: false
|
|
210
|
+
};
|
|
189
211
|
const apiPromise = this.getSubstrateApiByChain(originChain).api;
|
|
190
212
|
try {
|
|
191
213
|
switch (tokenType) {
|
|
192
214
|
case _AssetType.PSP22:
|
|
193
|
-
|
|
215
|
+
tokenSmartContract = await this.getPsp22TokenInfo(apiPromise, contractAddress, contractCaller);
|
|
194
216
|
break;
|
|
195
217
|
case _AssetType.PSP34:
|
|
196
|
-
|
|
218
|
+
tokenSmartContract = await this.getPsp34TokenInfo(apiPromise, contractAddress, contractCaller);
|
|
197
219
|
break;
|
|
198
220
|
case _AssetType.GRC20:
|
|
199
|
-
|
|
221
|
+
tokenSmartContract = await this.getVaraFungibleTokenInfo(apiPromise, contractAddress, tokenType);
|
|
200
222
|
break;
|
|
201
223
|
case _AssetType.VFT:
|
|
202
|
-
|
|
224
|
+
tokenSmartContract = await this.getVaraFungibleTokenInfo(apiPromise, contractAddress, tokenType);
|
|
203
225
|
break;
|
|
204
226
|
}
|
|
227
|
+
return tokenSmartContract;
|
|
228
|
+
} catch (e) {
|
|
229
|
+
this.logger.error(e);
|
|
230
|
+
tokenSmartContract.contractError = true;
|
|
231
|
+
return tokenSmartContract;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async getSubstrateAssetIdTokenInfo(assetId, originChain) {
|
|
235
|
+
const apiPromise = this.getSubstrateApiByChain(originChain).api;
|
|
236
|
+
try {
|
|
237
|
+
const [name, decimals, symbol, contractError] = await this.getLocalTokenInfo(apiPromise, assetId);
|
|
205
238
|
return {
|
|
206
239
|
name,
|
|
207
240
|
decimals,
|