@subwallet/extension-base 1.2.15-0 → 1.2.16-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 +6 -1
- package/cjs/koni/background/handlers/Extension.js +33 -7
- package/cjs/koni/background/handlers/State.js +11 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/gear.js +135 -0
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +9 -62
- package/cjs/services/balance-service/transfer/token.js +4 -3
- package/cjs/services/chain-service/handler/SubstrateApi.js +3 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +21 -26
- package/cjs/services/chain-service/index.js +48 -3
- package/cjs/services/chain-service/types.js +1 -1
- package/cjs/services/chain-service/utils/index.js +18 -12
- package/cjs/services/earning-service/service.js +3 -0
- package/cjs/services/migration-service/scripts/databases/ClearMetadataDatabase.js +16 -0
- package/cjs/services/migration-service/scripts/index.js +7 -7
- package/cjs/services/transaction-service/index.js +12 -7
- package/cjs/utils/gear/combine.js +28 -0
- package/cjs/utils/gear/grc20.js +56 -49
- package/cjs/utils/gear/index.js +22 -0
- package/cjs/utils/gear/vft.js +173 -0
- package/cjs/utils/metadata.js +45 -34
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +25 -1
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +11 -1
- package/package.json +24 -8
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/index.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/gear.d.ts +4 -0
- package/services/balance-service/helpers/subscribe/substrate/gear.js +123 -0
- package/services/balance-service/helpers/subscribe/substrate/index.js +10 -61
- package/services/balance-service/transfer/token.js +5 -4
- package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
- package/services/chain-service/handler/SubstrateApi.js +3 -1
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -0
- package/services/chain-service/handler/SubstrateChainHandler.js +22 -27
- package/services/chain-service/index.d.ts +4 -0
- package/services/chain-service/index.js +49 -4
- package/services/chain-service/types.d.ts +1 -0
- package/services/chain-service/types.js +1 -1
- package/services/chain-service/utils/index.d.ts +1 -0
- package/services/chain-service/utils/index.js +16 -12
- package/services/earning-service/service.js +3 -0
- package/services/migration-service/scripts/databases/ClearMetadataDatabase.js +16 -0
- package/services/migration-service/scripts/index.js +7 -7
- package/services/transaction-service/index.js +13 -8
- package/types/metadata.d.ts +9 -2
- package/utils/gear/combine.d.ts +10 -0
- package/utils/gear/combine.js +18 -0
- package/utils/gear/grc20.d.ts +18 -20
- package/utils/gear/grc20.js +53 -45
- package/utils/gear/index.d.ts +2 -0
- package/utils/gear/index.js +3 -1
- package/utils/gear/vft.d.ts +36 -0
- package/utils/gear/vft.js +162 -0
- package/utils/metadata.d.ts +7 -2
- package/utils/metadata.js +41 -31
|
@@ -6,9 +6,8 @@ import { _AssetType } from '@subwallet/chain-list/types';
|
|
|
6
6
|
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
7
7
|
import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler';
|
|
8
8
|
import { SubstrateApi } from '@subwallet/extension-base/services/chain-service/handler/SubstrateApi';
|
|
9
|
-
import {
|
|
9
|
+
import { cacheMetadata, GEAR_DEFAULT_ADDRESS, getGRC20ContractPromise, getVFTContractPromise } from '@subwallet/extension-base/utils';
|
|
10
10
|
import { ContractPromise } from '@polkadot/api-contract';
|
|
11
|
-
import { getSpecExtensions, getSpecTypes } from '@polkadot/types-known';
|
|
12
11
|
import { BN } from '@polkadot/util';
|
|
13
12
|
import { logger as createLogger } from '@polkadot/util/logger';
|
|
14
13
|
import { _PSP22_ABI, _PSP34_ABI } from "../../../koni/api/contract-handler/utils/index.js";
|
|
@@ -137,12 +136,26 @@ export class SubstrateChainHandler extends AbstractChainHandler {
|
|
|
137
136
|
}
|
|
138
137
|
async getGrc20TokenInfo(apiPromise, contractAddress) {
|
|
139
138
|
if (!(apiPromise instanceof GearApi)) {
|
|
140
|
-
console.warn('Cannot subscribe
|
|
139
|
+
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
141
140
|
return ['', -1, '', true];
|
|
142
141
|
}
|
|
143
142
|
let contractError = false;
|
|
144
143
|
const tokenContract = getGRC20ContractPromise(apiPromise, contractAddress);
|
|
145
|
-
const [nameRes, symbolRes, decimalsRes] = await Promise.all([tokenContract.name(
|
|
144
|
+
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)]);
|
|
145
|
+
const decimals = typeof decimalsRes === 'string' ? parseInt(decimalsRes) : decimalsRes;
|
|
146
|
+
if (!nameRes || !symbolRes) {
|
|
147
|
+
contractError = true;
|
|
148
|
+
}
|
|
149
|
+
return [nameRes, decimals, symbolRes, contractError];
|
|
150
|
+
}
|
|
151
|
+
async getVftTokenInfo(apiPromise, contractAddress) {
|
|
152
|
+
if (!(apiPromise instanceof GearApi)) {
|
|
153
|
+
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
154
|
+
return ['', -1, '', true];
|
|
155
|
+
}
|
|
156
|
+
let contractError = false;
|
|
157
|
+
const tokenContract = getVFTContractPromise(apiPromise, contractAddress);
|
|
158
|
+
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)]);
|
|
146
159
|
const decimals = typeof decimalsRes === 'string' ? parseInt(decimalsRes) : decimalsRes;
|
|
147
160
|
if (!nameRes || !symbolRes) {
|
|
148
161
|
contractError = true;
|
|
@@ -168,6 +181,9 @@ export class SubstrateChainHandler extends AbstractChainHandler {
|
|
|
168
181
|
case _AssetType.GRC20:
|
|
169
182
|
[name, decimals, symbol, contractError] = await this.getGrc20TokenInfo(apiPromise, contractAddress);
|
|
170
183
|
break;
|
|
184
|
+
case _AssetType.VFT:
|
|
185
|
+
[name, decimals, symbol, contractError] = await this.getVftTokenInfo(apiPromise, contractAddress);
|
|
186
|
+
break;
|
|
171
187
|
}
|
|
172
188
|
return {
|
|
173
189
|
name,
|
|
@@ -199,31 +215,9 @@ export class SubstrateChainHandler extends AbstractChainHandler {
|
|
|
199
215
|
} = {}) {
|
|
200
216
|
var _this$parent2;
|
|
201
217
|
const existed = this.substrateApiMap[chainSlug];
|
|
202
|
-
const metadata = await ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.getMetadata(chainSlug));
|
|
203
218
|
const updateMetadata = substrateApi => {
|
|
204
219
|
// Update metadata to database with async methods
|
|
205
|
-
|
|
206
|
-
var _this$parent3;
|
|
207
|
-
const currentSpecVersion = api.runtimeVersion.specVersion.toString();
|
|
208
|
-
const genesisHash = api.genesisHash.toHex();
|
|
209
|
-
|
|
210
|
-
// Avoid date existed metadata
|
|
211
|
-
if (metadata && metadata.specVersion === currentSpecVersion && metadata.genesisHash === genesisHash) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
const systemChain = await api.rpc.system.chain();
|
|
215
|
-
// const _metadata: Option<OpaqueMetadata> = await api.call.metadata.metadataAtVersion(15);
|
|
216
|
-
// const metadataHex = _metadata.isSome ? _metadata.unwrap().toHex().slice(2) : ''; // Need unwrap to create metadata object
|
|
217
|
-
|
|
218
|
-
(_this$parent3 = this.parent) === null || _this$parent3 === void 0 ? void 0 : _this$parent3.upsertMetadata(chainSlug, {
|
|
219
|
-
chain: chainSlug,
|
|
220
|
-
genesisHash: genesisHash,
|
|
221
|
-
specVersion: currentSpecVersion,
|
|
222
|
-
hexValue: api.runtimeMetadata.toHex(),
|
|
223
|
-
types: getSpecTypes(api.registry, systemChain, api.runtimeVersion.specName, api.runtimeVersion.specVersion),
|
|
224
|
-
userExtensions: getSpecExtensions(api.registry, systemChain, api.runtimeVersion.specName)
|
|
225
|
-
}).catch(console.error);
|
|
226
|
-
}).catch(console.error);
|
|
220
|
+
cacheMetadata(chainSlug, substrateApi, this.parent);
|
|
227
221
|
};
|
|
228
222
|
|
|
229
223
|
// Return existed to avoid re-init metadata
|
|
@@ -237,6 +231,7 @@ export class SubstrateChainHandler extends AbstractChainHandler {
|
|
|
237
231
|
updateMetadata(existed);
|
|
238
232
|
return existed;
|
|
239
233
|
}
|
|
234
|
+
const metadata = await ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.getMetadata(chainSlug));
|
|
240
235
|
const apiObject = new SubstrateApi(chainSlug, apiUrl, {
|
|
241
236
|
providerName,
|
|
242
237
|
metadata,
|
|
@@ -7,6 +7,7 @@ import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
|
7
7
|
import { IMetadataItem } from '@subwallet/extension-base/services/storage-service/databases';
|
|
8
8
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
9
9
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
10
|
+
import { ExtraInfo } from '@polkadot-api/merkleize-metadata';
|
|
10
11
|
export declare class ChainService {
|
|
11
12
|
private dataMap;
|
|
12
13
|
private dbService;
|
|
@@ -141,6 +142,9 @@ export declare class ChainService {
|
|
|
141
142
|
getMetadata(chain: string): import("dexie").PromiseExtended<IMetadataItem | undefined>;
|
|
142
143
|
upsertMetadata(chain: string, metadata: IMetadataItem): import("dexie").PromiseExtended<unknown>;
|
|
143
144
|
getMetadataByHash(hash: string): import("dexie").PromiseExtended<IMetadataItem | undefined>;
|
|
145
|
+
getExtraInfo(chain: string): Omit<ExtraInfo, 'specVersion' | 'specName'>;
|
|
146
|
+
calculateMetadataHash(chain: string): Promise<string | undefined>;
|
|
147
|
+
shortenMetadata(chain: string, txBlob: string): Promise<string | undefined>;
|
|
144
148
|
getSubscanChainMap(reverse?: boolean): Record<string, string>;
|
|
145
149
|
get detectBalanceChainSlugMap(): Record<string, string>;
|
|
146
150
|
getFeeTokensByChain(chainSlug: string): string[];
|
|
@@ -11,14 +11,14 @@ import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chai
|
|
|
11
11
|
import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
|
|
12
12
|
import { _isAssetAutoEnable, _isAssetCanPayTxFee, _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, fetchPatchData, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
13
|
import AssetSettingStore from '@subwallet/extension-base/stores/AssetSetting';
|
|
14
|
-
import { addLazy, fetchStaticData, filterAssetsByChainAndType, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
|
|
14
|
+
import { addLazy, calculateMetadataHash, fetchStaticData, filterAssetsByChainAndType, getShortMetadata, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
|
|
15
15
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
16
16
|
import Web3 from 'web3';
|
|
17
17
|
import { logger as createLogger } from '@polkadot/util/logger';
|
|
18
18
|
const filterChainInfoMap = (data, ignoredChains) => {
|
|
19
19
|
return Object.fromEntries(Object.entries(data).filter(([slug, info]) => !info.bitcoinInfo && !ignoredChains.includes(slug)));
|
|
20
20
|
};
|
|
21
|
-
const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet'];
|
|
21
|
+
const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet', 'core', 'satoshivm', 'satoshivm_testnet'];
|
|
22
22
|
const filterAssetInfoMap = (chainInfo, assets) => {
|
|
23
23
|
return Object.fromEntries(Object.entries(assets).filter(([, info]) => chainInfo[info.originChain]));
|
|
24
24
|
};
|
|
@@ -233,7 +233,7 @@ export class ChainService {
|
|
|
233
233
|
return Object.entries(this.dataMap.chainStateMap).filter(([, chainState]) => _isChainEnabled(chainState)).map(([key]) => key);
|
|
234
234
|
}
|
|
235
235
|
getSupportedSmartContractTypes() {
|
|
236
|
-
return [_AssetType.ERC20, _AssetType.ERC721, _AssetType.PSP22, _AssetType.PSP34, _AssetType.GRC20, _AssetType.GRC721];
|
|
236
|
+
return [_AssetType.ERC20, _AssetType.ERC721, _AssetType.PSP22, _AssetType.PSP34, _AssetType.GRC20, _AssetType.GRC721, _AssetType.VFT];
|
|
237
237
|
}
|
|
238
238
|
getActiveChainInfoMap() {
|
|
239
239
|
const result = {};
|
|
@@ -1449,7 +1449,7 @@ export class ChainService {
|
|
|
1449
1449
|
async getSmartContractTokenInfo(contractAddress, tokenType, originChain, contractCaller) {
|
|
1450
1450
|
if ([_AssetType.ERC721, _AssetType.ERC20].includes(tokenType)) {
|
|
1451
1451
|
return await this.evmChainHandler.getEvmContractTokenInfo(contractAddress, tokenType, originChain);
|
|
1452
|
-
} else if ([_AssetType.PSP34, _AssetType.PSP22, _AssetType.GRC20].includes(tokenType)) {
|
|
1452
|
+
} else if ([_AssetType.PSP34, _AssetType.PSP22, _AssetType.GRC20, _AssetType.VFT].includes(tokenType)) {
|
|
1453
1453
|
return await this.substrateChainHandler.getSubstrateContractTokenInfo(contractAddress, tokenType, originChain, contractCaller);
|
|
1454
1454
|
}
|
|
1455
1455
|
return {
|
|
@@ -1667,6 +1667,9 @@ export class ChainService {
|
|
|
1667
1667
|
this.deleteCustomAssets(customToken);
|
|
1668
1668
|
}
|
|
1669
1669
|
}
|
|
1670
|
+
|
|
1671
|
+
/* Metadata */
|
|
1672
|
+
|
|
1670
1673
|
getMetadata(chain) {
|
|
1671
1674
|
return this.dbService.stores.metadata.getMetadata(chain);
|
|
1672
1675
|
}
|
|
@@ -1676,6 +1679,48 @@ export class ChainService {
|
|
|
1676
1679
|
getMetadataByHash(hash) {
|
|
1677
1680
|
return this.dbService.stores.metadata.getMetadataByGenesisHash(hash);
|
|
1678
1681
|
}
|
|
1682
|
+
getExtraInfo(chain) {
|
|
1683
|
+
var _chainInfo$substrateI2, _chainInfo$substrateI3, _chainInfo$substrateI4, _chainInfo$substrateI5, _chainInfo$substrateI6, _chainInfo$substrateI7;
|
|
1684
|
+
const chainInfo = this.getChainInfoByKey(chain);
|
|
1685
|
+
return {
|
|
1686
|
+
decimals: (_chainInfo$substrateI2 = (_chainInfo$substrateI3 = chainInfo.substrateInfo) === null || _chainInfo$substrateI3 === void 0 ? void 0 : _chainInfo$substrateI3.decimals) !== null && _chainInfo$substrateI2 !== void 0 ? _chainInfo$substrateI2 : 0,
|
|
1687
|
+
tokenSymbol: (_chainInfo$substrateI4 = (_chainInfo$substrateI5 = chainInfo.substrateInfo) === null || _chainInfo$substrateI5 === void 0 ? void 0 : _chainInfo$substrateI5.symbol) !== null && _chainInfo$substrateI4 !== void 0 ? _chainInfo$substrateI4 : 'Unit',
|
|
1688
|
+
base58Prefix: (_chainInfo$substrateI6 = (_chainInfo$substrateI7 = chainInfo.substrateInfo) === null || _chainInfo$substrateI7 === void 0 ? void 0 : _chainInfo$substrateI7.addressPrefix) !== null && _chainInfo$substrateI6 !== void 0 ? _chainInfo$substrateI6 : 42
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
async calculateMetadataHash(chain) {
|
|
1692
|
+
const metadata = await this.getMetadata(chain);
|
|
1693
|
+
if (!metadata || !metadata.hexV15) {
|
|
1694
|
+
return undefined;
|
|
1695
|
+
}
|
|
1696
|
+
const extraInfo = this.getExtraInfo(chain);
|
|
1697
|
+
const specVersion = parseInt(metadata.specVersion);
|
|
1698
|
+
const specName = metadata.specName;
|
|
1699
|
+
const hexV15 = metadata.hexV15;
|
|
1700
|
+
return calculateMetadataHash({
|
|
1701
|
+
...extraInfo,
|
|
1702
|
+
specVersion,
|
|
1703
|
+
specName
|
|
1704
|
+
}, hexV15);
|
|
1705
|
+
}
|
|
1706
|
+
async shortenMetadata(chain, txBlob) {
|
|
1707
|
+
const metadata = await this.getMetadata(chain);
|
|
1708
|
+
if (!metadata || !metadata.hexV15) {
|
|
1709
|
+
return undefined;
|
|
1710
|
+
}
|
|
1711
|
+
const extraInfo = this.getExtraInfo(chain);
|
|
1712
|
+
const specVersion = parseInt(metadata.specVersion);
|
|
1713
|
+
const specName = metadata.specName;
|
|
1714
|
+
const hexV15 = metadata.hexV15;
|
|
1715
|
+
return getShortMetadata(txBlob, {
|
|
1716
|
+
...extraInfo,
|
|
1717
|
+
specVersion,
|
|
1718
|
+
specName
|
|
1719
|
+
}, hexV15);
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/* Metadata */
|
|
1723
|
+
|
|
1679
1724
|
getSubscanChainMap(reverse) {
|
|
1680
1725
|
const result = {};
|
|
1681
1726
|
const chainInfoMap = this.getChainInfoMap();
|
|
@@ -71,6 +71,7 @@ export interface _SubstrateApiState {
|
|
|
71
71
|
export interface _SubstrateApi extends _SubstrateApiState, _ChainBaseApi {
|
|
72
72
|
api: ApiPromise;
|
|
73
73
|
isReady: Promise<_SubstrateApi>;
|
|
74
|
+
connect: (_callbackUpdateMetadata?: (substrateApi: _SubstrateApi) => void) => void;
|
|
74
75
|
specName: string;
|
|
75
76
|
specVersion: string;
|
|
76
77
|
systemChain: string;
|
|
@@ -12,6 +12,6 @@ export let _ChainConnectionStatus;
|
|
|
12
12
|
_ChainConnectionStatus["CONNECTING"] = "CONNECTING";
|
|
13
13
|
})(_ChainConnectionStatus || (_ChainConnectionStatus = {}));
|
|
14
14
|
export const _CUSTOM_PREFIX = 'custom-';
|
|
15
|
-
export const _FUNGIBLE_CONTRACT_STANDARDS = [_AssetType.ERC20, _AssetType.PSP22, _AssetType.GRC20];
|
|
15
|
+
export const _FUNGIBLE_CONTRACT_STANDARDS = [_AssetType.ERC20, _AssetType.PSP22, _AssetType.GRC20, _AssetType.VFT];
|
|
16
16
|
export const _NFT_CONTRACT_STANDARDS = [_AssetType.PSP34, _AssetType.ERC721];
|
|
17
17
|
export const _SMART_CONTRACT_STANDARDS = [..._FUNGIBLE_CONTRACT_STANDARDS, ..._NFT_CONTRACT_STANDARDS];
|
|
@@ -48,6 +48,7 @@ export declare function _isChainSupportWasmNft(chainInfo: _ChainInfo): boolean;
|
|
|
48
48
|
export declare function _isChainSupportEvmERC20(chainInfo: _ChainInfo): boolean;
|
|
49
49
|
export declare function _isChainSupportWasmPSP22(chainInfo: _ChainInfo): boolean;
|
|
50
50
|
export declare function _isChainSupportGRC20(chainInfo: _ChainInfo): boolean;
|
|
51
|
+
export declare function _isChainSupportVFT(chainInfo: _ChainInfo): boolean;
|
|
51
52
|
export declare const _isSupportOrdinal: (chain: string) => boolean;
|
|
52
53
|
export declare function _getNftTypesSupportedByChain(chainInfo: _ChainInfo): _AssetType[];
|
|
53
54
|
export declare function _getTokenTypesSupportedByChain(chainInfo: _ChainInfo): _AssetType[];
|
|
@@ -181,6 +181,10 @@ export function _isChainSupportGRC20(chainInfo) {
|
|
|
181
181
|
var _chainInfo$substrateI12, _chainInfo$substrateI13;
|
|
182
182
|
return ((_chainInfo$substrateI12 = chainInfo.substrateInfo) === null || _chainInfo$substrateI12 === void 0 ? void 0 : (_chainInfo$substrateI13 = _chainInfo$substrateI12.supportSmartContract) === null || _chainInfo$substrateI13 === void 0 ? void 0 : _chainInfo$substrateI13.includes(_AssetType.GRC20)) || false;
|
|
183
183
|
}
|
|
184
|
+
export function _isChainSupportVFT(chainInfo) {
|
|
185
|
+
var _chainInfo$substrateI14, _chainInfo$substrateI15;
|
|
186
|
+
return ((_chainInfo$substrateI14 = chainInfo.substrateInfo) === null || _chainInfo$substrateI14 === void 0 ? void 0 : (_chainInfo$substrateI15 = _chainInfo$substrateI14.supportSmartContract) === null || _chainInfo$substrateI15 === void 0 ? void 0 : _chainInfo$substrateI15.includes(_AssetType.VFT)) || false;
|
|
187
|
+
}
|
|
184
188
|
export const _isSupportOrdinal = chain => {
|
|
185
189
|
const chains = ['polkadot', 'astar', 'bifrost_dot', 'moonbeam'];
|
|
186
190
|
return chains.includes(chain);
|
|
@@ -207,7 +211,7 @@ export function _getTokenTypesSupportedByChain(chainInfo) {
|
|
|
207
211
|
const result = [];
|
|
208
212
|
if (chainInfo.substrateInfo && chainInfo.substrateInfo.supportSmartContract) {
|
|
209
213
|
chainInfo.substrateInfo.supportSmartContract.forEach(assetType => {
|
|
210
|
-
if ([_AssetType.PSP22, _AssetType.GRC20].includes(assetType)) {
|
|
214
|
+
if ([_AssetType.PSP22, _AssetType.GRC20, _AssetType.VFT].includes(assetType)) {
|
|
211
215
|
result.push(assetType);
|
|
212
216
|
}
|
|
213
217
|
});
|
|
@@ -264,7 +268,7 @@ export function _isAssetSmartContractNft(assetInfo) {
|
|
|
264
268
|
return [_AssetType.PSP34, _AssetType.ERC721].includes(assetInfo.assetType);
|
|
265
269
|
}
|
|
266
270
|
export function _isTokenGearSmartContract(tokenInfo) {
|
|
267
|
-
return [_AssetType.GRC20, _AssetType.GRC721].includes(tokenInfo.assetType);
|
|
271
|
+
return [_AssetType.GRC20, _AssetType.GRC721, _AssetType.VFT].includes(tokenInfo.assetType);
|
|
268
272
|
}
|
|
269
273
|
export function _parseAssetRefKey(originTokenSlug, destinationTokenSlug) {
|
|
270
274
|
return `${originTokenSlug}___${destinationTokenSlug}`;
|
|
@@ -296,12 +300,12 @@ export function _isRelayChain(chainInfo) {
|
|
|
296
300
|
return _isSubstrateRelayChain(chainInfo) || _isPureEvmChain(chainInfo);
|
|
297
301
|
}
|
|
298
302
|
export function _isSubstrateRelayChain(chainInfo) {
|
|
299
|
-
var _chainInfo$
|
|
300
|
-
return ((_chainInfo$
|
|
303
|
+
var _chainInfo$substrateI16;
|
|
304
|
+
return ((_chainInfo$substrateI16 = chainInfo.substrateInfo) === null || _chainInfo$substrateI16 === void 0 ? void 0 : _chainInfo$substrateI16.chainType) === _SubstrateChainType.RELAYCHAIN;
|
|
301
305
|
}
|
|
302
306
|
export function _isSubstrateParaChain(chainInfo) {
|
|
303
|
-
var _chainInfo$
|
|
304
|
-
return chainInfo.substrateInfo !== null && chainInfo.substrateInfo.paraId !== null && ((_chainInfo$
|
|
307
|
+
var _chainInfo$substrateI17;
|
|
308
|
+
return chainInfo.substrateInfo !== null && chainInfo.substrateInfo.paraId !== null && ((_chainInfo$substrateI17 = chainInfo.substrateInfo) === null || _chainInfo$substrateI17 === void 0 ? void 0 : _chainInfo$substrateI17.chainType) === _SubstrateChainType.PARACHAIN;
|
|
305
309
|
}
|
|
306
310
|
export function _getEvmAbiExplorer(chainInfo) {
|
|
307
311
|
var _chainInfo$evmInfo4;
|
|
@@ -346,8 +350,8 @@ export function _getBlockExplorerFromChain(chainInfo) {
|
|
|
346
350
|
var _chainInfo$evmInfo5;
|
|
347
351
|
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo5 = chainInfo.evmInfo) === null || _chainInfo$evmInfo5 === void 0 ? void 0 : _chainInfo$evmInfo5.blockExplorer;
|
|
348
352
|
} else {
|
|
349
|
-
var _chainInfo$
|
|
350
|
-
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$
|
|
353
|
+
var _chainInfo$substrateI18;
|
|
354
|
+
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.blockExplorer;
|
|
351
355
|
}
|
|
352
356
|
if (!blockExplorer) {
|
|
353
357
|
return undefined;
|
|
@@ -373,8 +377,8 @@ export const _isAssetAutoEnable = chainAsset => {
|
|
|
373
377
|
return chainAsset.metadata ? !!chainAsset.metadata.autoEnable : false;
|
|
374
378
|
};
|
|
375
379
|
export function _getCrowdloanUrlFromChain(chainInfo) {
|
|
376
|
-
var _chainInfo$
|
|
377
|
-
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$
|
|
380
|
+
var _chainInfo$substrateI19;
|
|
381
|
+
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI19 = chainInfo.substrateInfo) === null || _chainInfo$substrateI19 === void 0 ? void 0 : _chainInfo$substrateI19.crowdloanUrl) || '';
|
|
378
382
|
}
|
|
379
383
|
export function _isCustomProvider(providerKey) {
|
|
380
384
|
return providerKey.startsWith(_CUSTOM_PREFIX);
|
|
@@ -410,8 +414,8 @@ export function _isMantaZkAsset(chainAsset) {
|
|
|
410
414
|
return _MANTA_ZK_CHAIN_GROUP.includes(chainAsset.originChain) && chainAsset.symbol.startsWith(_ZK_ASSET_PREFIX);
|
|
411
415
|
}
|
|
412
416
|
export function _getChainExistentialDeposit(chainInfo) {
|
|
413
|
-
var _chainInfo$
|
|
414
|
-
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$
|
|
417
|
+
var _chainInfo$substrateI20;
|
|
418
|
+
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI20 = chainInfo.substrateInfo) === null || _chainInfo$substrateI20 === void 0 ? void 0 : _chainInfo$substrateI20.existentialDeposit) || '0';
|
|
415
419
|
}
|
|
416
420
|
export function randomizeProvider(providers, excludedKeys) {
|
|
417
421
|
if (Object.keys(providers).length === 0) {
|
|
@@ -137,6 +137,9 @@ export default class EarningService {
|
|
|
137
137
|
if (event.type === 'account.remove') {
|
|
138
138
|
removedAddresses.push(event.data[0]);
|
|
139
139
|
}
|
|
140
|
+
if (event.type === 'account.add') {
|
|
141
|
+
delayReload = true;
|
|
142
|
+
}
|
|
140
143
|
if (event.type === 'chain.updateState') {
|
|
141
144
|
const chainState = this.state.getChainStateByKey(event.data[0]);
|
|
142
145
|
if (chainState && !_isChainEnabled(chainState)) {
|
|
@@ -2,10 +2,26 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
import { cacheMetadata, waitTimeout } from '@subwallet/extension-base/utils';
|
|
5
6
|
export default class ClearMetadataDatabase extends BaseMigrationJob {
|
|
6
7
|
async run() {
|
|
7
8
|
// Clear all old metadata data
|
|
8
9
|
await this.state.dbService.stores.metadata.clear();
|
|
10
|
+
const activeChains = this.state.chainService.getActiveChains();
|
|
11
|
+
const chainInfoMap = this.state.chainService.getChainInfoMap();
|
|
12
|
+
const reloadChains = activeChains.filter(chain => {
|
|
13
|
+
var _chainInfoMap$chain$s;
|
|
14
|
+
return !!((_chainInfoMap$chain$s = chainInfoMap[chain].substrateInfo) !== null && _chainInfoMap$chain$s !== void 0 && _chainInfoMap$chain$s.genesisHash);
|
|
15
|
+
});
|
|
16
|
+
for (const chain of reloadChains) {
|
|
17
|
+
const substrateApi = this.state.chainService.getSubstrateApi(chain);
|
|
18
|
+
const callback = substrateApi => {
|
|
19
|
+
cacheMetadata(chain, substrateApi, this.state.chainService);
|
|
20
|
+
};
|
|
21
|
+
Promise.race([substrateApi.isReady, waitTimeout(2000)]).finally(() => {
|
|
22
|
+
substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.connect(callback);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
9
25
|
return Promise.resolve();
|
|
10
26
|
}
|
|
11
27
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import AutoEnableSomeTokens from
|
|
5
|
-
import ReloadMetadata from '@subwallet/extension-base/services/migration-service/scripts/databases/ReloadMetadata';
|
|
6
|
-
import DeleteEarningData from '@subwallet/extension-base/services/migration-service/scripts/DeleteEarningData';
|
|
7
|
-
import MigrateRemoveGenesisHash from '@subwallet/extension-base/services/migration-service/scripts/MigrateRemoveGenesisHash';
|
|
8
|
-
import MigrateTransactionHistoryBySymbol from '@subwallet/extension-base/services/migration-service/scripts/MigrateTransactionHistoryBySymbol';
|
|
4
|
+
import AutoEnableSomeTokens from "./databases/AutoEnableSomeTokens.js";
|
|
9
5
|
import ClearMetadataDatabase from "./databases/ClearMetadataDatabase.js";
|
|
10
6
|
import MigrateAssetSetting from "./databases/MigrateAssetSetting.js";
|
|
11
7
|
import MigrateEarningVersion from "./databases/MigrateEarningVersion.js";
|
|
8
|
+
import ReloadMetadata from "./databases/ReloadMetadata.js";
|
|
12
9
|
import MigrateEthProvider from "./providers/MigrateEthProvider.js";
|
|
13
10
|
import MigratePioneerProvider from "./providers/MigratePioneerProvider.js";
|
|
14
11
|
import MigrateProvidersV1M1P24 from "./providers/MigrateProvidersV1M1P24.js";
|
|
@@ -16,6 +13,7 @@ import MigratePolygonUSDCProvider from "./tokens/MigratePolygonUSDCProvider.js";
|
|
|
16
13
|
import AutoEnableChainsTokens from "./AutoEnableChainsTokens.js";
|
|
17
14
|
import DeleteChain from "./DeleteChain.js";
|
|
18
15
|
import DeleteChainStaking from "./DeleteChainStaking.js";
|
|
16
|
+
import DeleteEarningData from "./DeleteEarningData.js";
|
|
19
17
|
import EnableVaraChain from "./EnableVaraChain.js";
|
|
20
18
|
import MigrateAuthUrls from "./MigrateAuthUrls.js";
|
|
21
19
|
import MigrateAutoLock from "./MigrateAutoLock.js";
|
|
@@ -24,9 +22,11 @@ import MigrateImportedToken from "./MigrateImportedToken.js";
|
|
|
24
22
|
import MigrateLedgerAccount from "./MigrateLedgerAccount.js";
|
|
25
23
|
import MigrateLedgerAccountV2 from "./MigrateLedgerAccountV2.js";
|
|
26
24
|
import MigrateNetworkSettings from "./MigrateNetworkSettings.js";
|
|
25
|
+
import MigrateRemoveGenesisHash from "./MigrateRemoveGenesisHash.js";
|
|
27
26
|
import MigrateSettings from "./MigrateSettings.js";
|
|
28
27
|
import MigrateTokenDecimals from "./MigrateTokenDecimals.js";
|
|
29
28
|
import MigrateTransactionHistory from "./MigrateTransactionHistory.js";
|
|
29
|
+
import MigrateTransactionHistoryBySymbol from "./MigrateTransactionHistoryBySymbol.js";
|
|
30
30
|
import MigrateWalletReference from "./MigrateWalletReference.js";
|
|
31
31
|
export const EVERYTIME = '__everytime__';
|
|
32
32
|
export default {
|
|
@@ -56,8 +56,8 @@ export default {
|
|
|
56
56
|
'1.1.69-03': MigrateAssetSetting,
|
|
57
57
|
'1.1.69-02': MigrateTransactionHistoryBySymbol,
|
|
58
58
|
'1.2.69-01': MigrateRemoveGenesisHash,
|
|
59
|
-
'1.2.
|
|
60
|
-
'1.2.
|
|
59
|
+
'1.2.13-01': ReloadMetadata,
|
|
60
|
+
'1.2.14-01': ClearMetadataDatabase
|
|
61
61
|
// [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
|
|
62
62
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
63
63
|
};
|
|
@@ -14,7 +14,7 @@ import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction } from
|
|
|
14
14
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
15
15
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
16
16
|
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
17
|
-
import { _isRuntimeUpdated, anyNumberToBN,
|
|
17
|
+
import { _isRuntimeUpdated, anyNumberToBN, reformatAddress } from '@subwallet/extension-base/utils';
|
|
18
18
|
import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
|
|
19
19
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
20
20
|
import { BN_ZERO } from '@subwallet/extension-base/utils/number';
|
|
@@ -1030,20 +1030,25 @@ export default class TransactionService {
|
|
|
1030
1030
|
const signerOption = {
|
|
1031
1031
|
signer: {
|
|
1032
1032
|
signPayload: async payload => {
|
|
1033
|
-
const
|
|
1033
|
+
const {
|
|
1034
|
+
signature,
|
|
1035
|
+
signedTransaction
|
|
1036
|
+
} = await this.state.requestService.signInternalTransaction(id, address, url || EXTENSION_REQUEST_URL, payload);
|
|
1034
1037
|
return {
|
|
1035
1038
|
id: new Date().getTime(),
|
|
1036
|
-
signature
|
|
1039
|
+
signature,
|
|
1040
|
+
signedTransaction
|
|
1037
1041
|
};
|
|
1038
1042
|
}
|
|
1039
|
-
}
|
|
1043
|
+
},
|
|
1044
|
+
withSignedTransaction: true
|
|
1040
1045
|
};
|
|
1041
1046
|
if (_isRuntimeUpdated(signedExtensions)) {
|
|
1042
|
-
|
|
1043
|
-
|
|
1047
|
+
const metadataHash = await this.state.chainService.calculateMetadataHash(chain);
|
|
1048
|
+
if (metadataHash) {
|
|
1044
1049
|
signerOption.mode = 1;
|
|
1045
|
-
signerOption.metadataHash =
|
|
1046
|
-
}
|
|
1050
|
+
signerOption.metadataHash = metadataHash;
|
|
1051
|
+
}
|
|
1047
1052
|
}
|
|
1048
1053
|
extrinsic.signAsync(address, signerOption).then(async rs => {
|
|
1049
1054
|
// Emit signed event
|
package/types/metadata.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
|
|
1
|
+
export interface RequestMetadataHash {
|
|
2
|
+
chain: string;
|
|
3
3
|
}
|
|
4
4
|
export interface ResponseMetadataHash {
|
|
5
5
|
metadataHash: string;
|
|
6
6
|
}
|
|
7
|
+
export interface RequestShortenMetadata {
|
|
8
|
+
chain: string;
|
|
9
|
+
txBlob: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ResponseShortenMetadata {
|
|
12
|
+
txMetadata: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import { GRC20 } from './grc20';
|
|
3
|
+
import { VFT } from './vft';
|
|
4
|
+
export declare const DEFAULT_GEAR_ADDRESS: {
|
|
5
|
+
ALICE: string;
|
|
6
|
+
BOB: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const GEAR_DEFAULT_ADDRESS = "5EYCAe5ijiYfAXEth5DGRKiKuVjTXQKr877tUPz6eLz2t9aG";
|
|
9
|
+
export declare function getGRC20ContractPromise(apiPromise: ApiPromise, contractAddress: string): GRC20;
|
|
10
|
+
export declare function getVFTContractPromise(apiPromise: ApiPromise, contractAddress: string): VFT;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { GRC20 } from "./grc20.js";
|
|
5
|
+
import { VFT } from "./vft.js";
|
|
6
|
+
export const DEFAULT_GEAR_ADDRESS = {
|
|
7
|
+
ALICE: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
|
|
8
|
+
BOB: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'
|
|
9
|
+
};
|
|
10
|
+
export const GEAR_DEFAULT_ADDRESS = '5EYCAe5ijiYfAXEth5DGRKiKuVjTXQKr877tUPz6eLz2t9aG';
|
|
11
|
+
export function getGRC20ContractPromise(apiPromise, contractAddress) {
|
|
12
|
+
const gearApi = apiPromise;
|
|
13
|
+
return new GRC20(gearApi, contractAddress);
|
|
14
|
+
}
|
|
15
|
+
export function getVFTContractPromise(apiPromise, contractAddress) {
|
|
16
|
+
const gearApi = apiPromise;
|
|
17
|
+
return new VFT(gearApi, contractAddress);
|
|
18
|
+
}
|
package/utils/gear/grc20.d.ts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { GearApi } from '@gear-js/api';
|
|
3
|
-
import { TransactionBuilder } from 'sails-js';
|
|
4
|
-
import {
|
|
5
|
-
export declare type ActorId = `0x${string}`;
|
|
6
|
-
export declare type U256 = bigint;
|
|
7
|
-
export declare const DEFAULT_GEAR_ADDRESS: {
|
|
8
|
-
ALICE: string;
|
|
9
|
-
BOB: string;
|
|
10
|
-
};
|
|
3
|
+
import { ActorId, TransactionBuilder } from 'sails-js';
|
|
4
|
+
import { TypeRegistry } from '@polkadot/types';
|
|
11
5
|
export declare class GRC20 {
|
|
12
6
|
api: GearApi;
|
|
13
7
|
programId: `0x${string}`;
|
|
14
|
-
|
|
8
|
+
readonly registry: TypeRegistry;
|
|
9
|
+
readonly service: Grc20Service;
|
|
15
10
|
constructor(api: GearApi, programId?: `0x${string}`);
|
|
16
|
-
newCtorFromCode(code: Uint8Array | Buffer, name: string, symbol: string, decimals: number
|
|
17
|
-
newCtorFromCodeId(codeId: `0x${string}`, name: string, symbol: string, decimals: number
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
newCtorFromCode(code: Uint8Array | Buffer, name: string, symbol: string, decimals: number): TransactionBuilder<null>;
|
|
12
|
+
newCtorFromCodeId(codeId: `0x${string}`, name: string, symbol: string, decimals: number): TransactionBuilder<null>;
|
|
13
|
+
}
|
|
14
|
+
export declare class Grc20Service {
|
|
15
|
+
private _program;
|
|
16
|
+
constructor(_program: GRC20);
|
|
17
|
+
approve(spender: ActorId, value: number | string | bigint): TransactionBuilder<boolean>;
|
|
18
|
+
fromTransfer(from: ActorId, to: ActorId, value: number | string | bigint): TransactionBuilder<boolean>;
|
|
19
|
+
setBalance(newBalance: number | string | bigint): TransactionBuilder<boolean>;
|
|
20
|
+
transfer(to: ActorId, value: number | string | bigint): TransactionBuilder<boolean>;
|
|
21
|
+
allowance(owner: ActorId, spender: ActorId, originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<bigint>;
|
|
22
|
+
balanceOf(owner: ActorId, originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<bigint>;
|
|
23
|
+
decimals(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<number>;
|
|
25
24
|
name(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<string>;
|
|
26
25
|
symbol(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<string>;
|
|
27
|
-
totalSupply(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<
|
|
26
|
+
totalSupply(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<bigint>;
|
|
28
27
|
}
|
|
29
|
-
export declare function getGRC20ContractPromise(apiPromise: ApiPromise, contractAddress: string): GRC20;
|