@subwallet/extension-base 1.3.7-0 → 1.3.9-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 +11 -5
- package/background/KoniTypes.js +1 -1
- package/cjs/background/KoniTypes.js +1 -1
- package/cjs/core/logic-validation/transfer.js +35 -24
- package/cjs/core/substrate/system-pallet.js +1 -1
- package/cjs/core/substrate/xcm-parser.js +16 -2
- package/cjs/core/utils.js +2 -2
- package/cjs/koni/api/contract-handler/utils/index.js +15 -1
- package/cjs/koni/background/handlers/Extension.js +158 -86
- package/cjs/koni/background/handlers/State.js +11 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/index.js +24 -2
- package/cjs/services/balance-service/transfer/smart-contract.js +16 -5
- package/cjs/services/balance-service/transfer/xcm/index.js +31 -1
- package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +108 -0
- package/cjs/services/chain-online-service/constants.js +32 -0
- package/cjs/services/chain-online-service/index.js +190 -0
- package/cjs/services/chain-service/constants.js +3 -1
- package/cjs/services/chain-service/index.js +87 -127
- package/cjs/services/chain-service/utils/index.js +0 -2
- package/cjs/services/chain-service/utils/patch.js +7 -3
- package/cjs/services/fee-service/utils/index.js +14 -0
- package/cjs/services/inapp-notification-service/consts.js +6 -4
- package/cjs/services/inapp-notification-service/index.js +110 -6
- package/cjs/services/inapp-notification-service/interfaces.js +9 -1
- package/cjs/services/inapp-notification-service/utils/avail.js +88 -0
- package/cjs/services/inapp-notification-service/{utils.js → utils/common.js} +1 -84
- package/cjs/services/inapp-notification-service/utils/index.js +38 -0
- package/cjs/services/inapp-notification-service/utils/polygon.js +66 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +37 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/setting-service/SettingService.js +8 -0
- package/cjs/services/setting-service/constants.js +2 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/stores/ChainlistStore.js +18 -0
- package/cjs/types/index.js +11 -0
- package/cjs/types/transaction/error.js +1 -0
- package/cjs/utils/account/transform.js +1 -1
- package/core/logic-validation/transfer.d.ts +2 -1
- package/core/logic-validation/transfer.js +36 -25
- package/core/substrate/system-pallet.js +1 -1
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +15 -2
- package/core/types.d.ts +1 -0
- package/core/utils.js +2 -2
- package/koni/api/contract-handler/utils/index.d.ts +2 -0
- package/koni/api/contract-handler/utils/index.js +12 -0
- package/koni/api/contract-handler/utils/polygon_bridge_abi.json +1004 -0
- package/koni/background/handlers/Extension.d.ts +4 -0
- package/koni/background/handlers/Extension.js +93 -22
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +11 -2
- package/package.json +56 -14
- package/packageInfo.js +1 -1
- package/services/balance-service/index.d.ts +3 -0
- package/services/balance-service/index.js +21 -2
- package/services/balance-service/transfer/smart-contract.js +16 -5
- package/services/balance-service/transfer/xcm/index.d.ts +1 -0
- package/services/balance-service/transfer/xcm/index.js +29 -1
- package/services/balance-service/transfer/xcm/polygonBridge.d.ts +22 -0
- package/services/balance-service/transfer/xcm/polygonBridge.js +95 -0
- package/services/chain-online-service/constants.d.ts +4 -0
- package/services/chain-online-service/constants.js +23 -0
- package/services/chain-online-service/index.d.ts +22 -0
- package/services/chain-online-service/index.js +182 -0
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +1 -0
- package/services/chain-service/index.d.ts +6 -7
- package/services/chain-service/index.js +78 -116
- package/services/chain-service/utils/index.js +0 -2
- package/services/chain-service/utils/patch.d.ts +16 -1
- package/services/chain-service/utils/patch.js +7 -3
- package/services/fee-service/utils/index.js +14 -0
- package/services/inapp-notification-service/consts.d.ts +3 -1
- package/services/inapp-notification-service/consts.js +6 -4
- package/services/inapp-notification-service/index.d.ts +10 -2
- package/services/inapp-notification-service/index.js +111 -7
- package/services/inapp-notification-service/interfaces.d.ts +27 -3
- package/services/inapp-notification-service/interfaces.js +7 -0
- package/services/inapp-notification-service/utils/avail.d.ts +40 -0
- package/services/inapp-notification-service/utils/avail.js +73 -0
- package/services/inapp-notification-service/utils/common.d.ts +11 -0
- package/services/inapp-notification-service/{utils.js → utils/common.js} +1 -72
- package/services/inapp-notification-service/utils/index.d.ts +3 -0
- package/services/inapp-notification-service/utils/index.js +6 -0
- package/services/inapp-notification-service/utils/polygon.d.ts +71 -0
- package/services/inapp-notification-service/utils/polygon.js +54 -0
- package/services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +29 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/setting-service/SettingService.d.ts +4 -0
- package/services/setting-service/SettingService.js +8 -0
- package/services/setting-service/constants.js +2 -1
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/transaction-service/index.js +1 -1
- package/stores/ChainlistStore.d.ts +7 -0
- package/stores/ChainlistStore.js +10 -0
- package/types/{avail-bridge → bridge}/index.d.ts +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/notification/index.d.ts +5 -0
- package/types/transaction/error.d.ts +2 -1
- package/types/transaction/error.js +1 -0
- package/utils/account/transform.js +1 -1
- package/services/inapp-notification-service/utils.d.ts +0 -55
- /package/cjs/types/{avail-bridge → bridge}/index.js +0 -0
- /package/types/{avail-bridge → bridge}/index.js +0 -0
|
@@ -129,9 +129,11 @@ export default class KoniExtension {
|
|
|
129
129
|
private recoverDotSamaApi;
|
|
130
130
|
private validateERC721Token;
|
|
131
131
|
private upsertCustomToken;
|
|
132
|
+
private isSufficientToken;
|
|
132
133
|
private deleteCustomAsset;
|
|
133
134
|
private validateCustomAsset;
|
|
134
135
|
private getAddressTransferableBalance;
|
|
136
|
+
private getAddressTotalBalance;
|
|
135
137
|
private getMaxTransferable;
|
|
136
138
|
private getXcmMaxTransferable;
|
|
137
139
|
private getNativeTokenMaxTransferable;
|
|
@@ -257,6 +259,8 @@ export default class KoniExtension {
|
|
|
257
259
|
private fetchInappNotifications;
|
|
258
260
|
private getInappNotification;
|
|
259
261
|
private submitClaimAvailBridge;
|
|
262
|
+
private getIsClaimedPolygonBridge;
|
|
263
|
+
private submitClaimPolygonBridge;
|
|
260
264
|
private subscribeLedgerGenericAllowChains;
|
|
261
265
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
|
|
262
266
|
}
|
|
@@ -9,7 +9,7 @@ import { withErrorLog } from '@subwallet/extension-base/background/handlers/help
|
|
|
9
9
|
import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
10
10
|
import { CampaignDataType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, MantaPayEnableMessage, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
11
11
|
import { ALL_ACCOUNT_KEY, LATEST_SESSION, XCM_FEE_RATIO } from '@subwallet/extension-base/constants';
|
|
12
|
-
import {
|
|
12
|
+
import { additionalValidateTransferForRecipient, additionalValidateXcmTransfer, validateTransferRequest, validateXcmTransferRequest } from '@subwallet/extension-base/core/logic-validation/transfer';
|
|
13
13
|
import { _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
14
14
|
import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
|
|
15
15
|
import { getERC20SpendingApprovalTx } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
@@ -26,14 +26,14 @@ import { isBounceableAddress } from '@subwallet/extension-base/services/balance-
|
|
|
26
26
|
import { getERC20TransactionObject, getERC721Transaction, getEVMTransactionObject, getPSP34TransferExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
|
|
27
27
|
import { createTransferExtrinsic, getTransferMockTxFee } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
28
28
|
import { createTonTransaction } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
29
|
-
import { createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createSnowBridgeExtrinsic, createXcmExtrinsic, getXcmMockTxFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
29
|
+
import { createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic, createXcmExtrinsic, getXcmMockTxFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
30
30
|
import { getClaimTxOnAvail, getClaimTxOnEthereum, isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
31
|
-
import {
|
|
31
|
+
import { _isPolygonChainBridge, getClaimPolygonBridge, isClaimedPolygonBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
32
|
+
import { _API_OPTIONS_CHAIN_GROUP, _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX, SUFFICIENT_CHAIN } from '@subwallet/extension-base/services/chain-service/constants';
|
|
32
33
|
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
33
|
-
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _isAssetSmartContractNft, _isChainEvmCompatible, _isChainTonCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
|
|
34
|
+
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getTokenOnChainAssetId, _getXcmAssetMultilocation, _isAssetSmartContractNft, _isBridgedToken, _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
|
|
34
35
|
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
35
36
|
import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
|
|
36
|
-
import { WALLET_CONNECT_EIP155_NAMESPACE } from '@subwallet/extension-base/services/wallet-connect-service/constants';
|
|
37
37
|
import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
38
38
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
39
39
|
import { AccountsStore } from '@subwallet/extension-base/stores';
|
|
@@ -1178,35 +1178,41 @@ export default class KoniExtension {
|
|
|
1178
1178
|
}
|
|
1179
1179
|
const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
|
|
1180
1180
|
const additionalValidator = async inputTransaction => {
|
|
1181
|
-
let
|
|
1182
|
-
let
|
|
1181
|
+
let senderSendingTokenTransferable;
|
|
1182
|
+
let receiverSystemAccountInfo;
|
|
1183
|
+
if (!_isChainSubstrateCompatible(chainInfo)) {
|
|
1184
|
+
return undefined;
|
|
1185
|
+
}
|
|
1183
1186
|
|
|
1184
1187
|
// Check ed for sender
|
|
1185
1188
|
if (!isTransferNativeToken) {
|
|
1186
|
-
const [
|
|
1189
|
+
const [_senderSendingTokenTransferable, _receiverNativeTotal] = await Promise.all([this.getAddressTransferableBalance({
|
|
1187
1190
|
address: from,
|
|
1188
1191
|
networkKey,
|
|
1189
1192
|
token: tokenSlug,
|
|
1190
1193
|
extrinsicType
|
|
1191
|
-
}), this.
|
|
1194
|
+
}), this.getAddressTotalBalance({
|
|
1192
1195
|
address: to,
|
|
1193
1196
|
networkKey,
|
|
1194
1197
|
token: nativeTokenSlug,
|
|
1195
1198
|
extrinsicType: ExtrinsicType.TRANSFER_BALANCE
|
|
1196
1199
|
})]);
|
|
1197
|
-
|
|
1198
|
-
|
|
1200
|
+
senderSendingTokenTransferable = BigInt(_senderSendingTokenTransferable.value);
|
|
1201
|
+
receiverSystemAccountInfo = _receiverNativeTotal.metadata;
|
|
1199
1202
|
}
|
|
1200
1203
|
const {
|
|
1201
|
-
value:
|
|
1202
|
-
} = await this.
|
|
1204
|
+
value: _receiverSendingTokenKeepAliveBalance
|
|
1205
|
+
} = await this.getAddressTotalBalance({
|
|
1203
1206
|
address: to,
|
|
1204
1207
|
networkKey,
|
|
1205
1208
|
token: tokenSlug,
|
|
1206
1209
|
extrinsicType
|
|
1207
1210
|
}); // todo: shouldn't be just transferable, locked also counts
|
|
1208
|
-
|
|
1209
|
-
const
|
|
1211
|
+
const receiverSendingTokenKeepAliveBalance = BigInt(_receiverSendingTokenKeepAliveBalance);
|
|
1212
|
+
const amount = BigInt(transferAmount.value);
|
|
1213
|
+
const substrateApi = this.#koniState.getSubstrateApi(networkKey);
|
|
1214
|
+
const isSendingTokenSufficient = await this.isSufficientToken(transferTokenInfo, substrateApi);
|
|
1215
|
+
const [warnings, errors] = additionalValidateTransferForRecipient(transferTokenInfo, nativeTokenInfo, extrinsicType, receiverSendingTokenKeepAliveBalance, amount, senderSendingTokenTransferable, receiverSystemAccountInfo, isSendingTokenSufficient);
|
|
1210
1216
|
warnings.length && inputTransaction.warnings.push(...warnings);
|
|
1211
1217
|
errors.length && inputTransaction.errors.push(...errors);
|
|
1212
1218
|
};
|
|
@@ -1255,6 +1261,7 @@ export default class KoniExtension {
|
|
|
1255
1261
|
const isAvailBridgeFromEvm = _isPureEvmChain(chainInfoMap[originNetworkKey]) && isAvailChainBridge(destinationNetworkKey);
|
|
1256
1262
|
const isAvailBridgeFromAvail = isAvailChainBridge(originNetworkKey) && _isPureEvmChain(chainInfoMap[destinationNetworkKey]);
|
|
1257
1263
|
const isSnowBridgeEvmTransfer = _isPureEvmChain(chainInfoMap[originNetworkKey]) && _isSnowBridgeXcm(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]) && !isAvailBridgeFromEvm;
|
|
1264
|
+
const isPolygonBridgeTransfer = _isPolygonChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1258
1265
|
let additionalValidator;
|
|
1259
1266
|
let eventsHandler;
|
|
1260
1267
|
if (fromKeyPair && destinationTokenInfo) {
|
|
@@ -1271,7 +1278,9 @@ export default class KoniExtension {
|
|
|
1271
1278
|
evmApi
|
|
1272
1279
|
};
|
|
1273
1280
|
let funcCreateExtrinsic;
|
|
1274
|
-
if (
|
|
1281
|
+
if (isPolygonBridgeTransfer) {
|
|
1282
|
+
funcCreateExtrinsic = createPolygonBridgeExtrinsic;
|
|
1283
|
+
} else if (isSnowBridgeEvmTransfer) {
|
|
1275
1284
|
funcCreateExtrinsic = createSnowBridgeExtrinsic;
|
|
1276
1285
|
} else if (isAvailBridgeFromEvm) {
|
|
1277
1286
|
funcCreateExtrinsic = createAvailBridgeTxFromEth;
|
|
@@ -1336,7 +1345,7 @@ export default class KoniExtension {
|
|
|
1336
1345
|
transaction: extrinsic,
|
|
1337
1346
|
data: inputData,
|
|
1338
1347
|
extrinsicType: ExtrinsicType.TRANSFER_XCM,
|
|
1339
|
-
chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm ? ChainType.SUBSTRATE : ChainType.EVM,
|
|
1348
|
+
chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
|
|
1340
1349
|
transferNativeAmount: _isNativeToken(originTokenInfo) ? value : '0',
|
|
1341
1350
|
ignoreWarnings,
|
|
1342
1351
|
isTransferAll: transferAll,
|
|
@@ -1462,6 +1471,25 @@ export default class KoniExtension {
|
|
|
1462
1471
|
};
|
|
1463
1472
|
}
|
|
1464
1473
|
}
|
|
1474
|
+
async isSufficientToken(tokenInfo, substrateApi) {
|
|
1475
|
+
let metadata;
|
|
1476
|
+
if (SUFFICIENT_CHAIN.includes(tokenInfo.originChain) && tokenInfo.assetType !== _AssetType.NATIVE) {
|
|
1477
|
+
const assetId = _isBridgedToken(tokenInfo) ? _getXcmAssetMultilocation(tokenInfo) : _getTokenOnChainAssetId(tokenInfo);
|
|
1478
|
+
const queryParams = {
|
|
1479
|
+
section: 'query',
|
|
1480
|
+
module: 'foreignAssets',
|
|
1481
|
+
method: 'asset',
|
|
1482
|
+
args: [assetId]
|
|
1483
|
+
};
|
|
1484
|
+
if (!_isBridgedToken(tokenInfo)) {
|
|
1485
|
+
queryParams.module = 'assets';
|
|
1486
|
+
}
|
|
1487
|
+
metadata = await substrateApi.makeRpcQuery(queryParams);
|
|
1488
|
+
} else {
|
|
1489
|
+
return false;
|
|
1490
|
+
}
|
|
1491
|
+
return metadata.isSufficient;
|
|
1492
|
+
}
|
|
1465
1493
|
async deleteCustomAsset(assetSlug) {
|
|
1466
1494
|
const assetInfo = this.#koniState.getAssetBySlug(assetSlug);
|
|
1467
1495
|
if (assetInfo && _isCustomAsset(assetSlug)) {
|
|
@@ -1491,6 +1519,14 @@ export default class KoniExtension {
|
|
|
1491
1519
|
}
|
|
1492
1520
|
return await this.#koniState.balanceService.getTransferableBalance(address, networkKey, token, extrinsicType);
|
|
1493
1521
|
}
|
|
1522
|
+
async getAddressTotalBalance({
|
|
1523
|
+
address,
|
|
1524
|
+
extrinsicType,
|
|
1525
|
+
networkKey,
|
|
1526
|
+
token
|
|
1527
|
+
}) {
|
|
1528
|
+
return await this.#koniState.balanceService.getTotalBalance(address, networkKey, token, extrinsicType);
|
|
1529
|
+
}
|
|
1494
1530
|
async getMaxTransferable({
|
|
1495
1531
|
address,
|
|
1496
1532
|
destChain,
|
|
@@ -2611,11 +2647,11 @@ export default class KoniExtension {
|
|
|
2611
2647
|
});
|
|
2612
2648
|
Object.entries(availableNamespaces).forEach(([key, namespace]) => {
|
|
2613
2649
|
if (namespace.chains) {
|
|
2614
|
-
const accounts =
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
accounts.push(...selectedAccounts.filter(address => isEthereumAddress(address) === (key === WALLET_CONNECT_EIP155_NAMESPACE)).map(address => `${chain}:${address}`));
|
|
2650
|
+
const accounts = selectedAccounts.filter(address => {
|
|
2651
|
+
const [_namespace] = address.split(':');
|
|
2652
|
+
return _namespace === key;
|
|
2618
2653
|
});
|
|
2654
|
+
const chains = uniqueStringArray(namespace.chains);
|
|
2619
2655
|
namespaces[key] = {
|
|
2620
2656
|
accounts,
|
|
2621
2657
|
methods: namespace.methods,
|
|
@@ -3375,7 +3411,7 @@ export default class KoniExtension {
|
|
|
3375
3411
|
chain,
|
|
3376
3412
|
notification
|
|
3377
3413
|
} = data;
|
|
3378
|
-
const extrinsicType = ExtrinsicType.
|
|
3414
|
+
const extrinsicType = ExtrinsicType.CLAIM_BRIDGE;
|
|
3379
3415
|
let transaction = null;
|
|
3380
3416
|
let chainType;
|
|
3381
3417
|
if (isSubstrateAddress(address)) {
|
|
@@ -3396,6 +3432,32 @@ export default class KoniExtension {
|
|
|
3396
3432
|
chainType
|
|
3397
3433
|
});
|
|
3398
3434
|
}
|
|
3435
|
+
async getIsClaimedPolygonBridge(data) {
|
|
3436
|
+
const evmApi = this.#koniState.getEvmApi(data.chainslug);
|
|
3437
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
3438
|
+
const isClaimed = await isClaimedPolygonBridge(data.chainslug, data.counter, data.sourceNetwork, evmApi);
|
|
3439
|
+
return isClaimed;
|
|
3440
|
+
}
|
|
3441
|
+
async submitClaimPolygonBridge(data) {
|
|
3442
|
+
const {
|
|
3443
|
+
address,
|
|
3444
|
+
chain,
|
|
3445
|
+
notification
|
|
3446
|
+
} = data;
|
|
3447
|
+
const extrinsicType = ExtrinsicType.CLAIM_BRIDGE;
|
|
3448
|
+
let transaction = null;
|
|
3449
|
+
const evmApi = this.#koniState.getEvmApi(chain);
|
|
3450
|
+
transaction = await getClaimPolygonBridge(chain, notification, evmApi);
|
|
3451
|
+
const chainType = ChainType.EVM;
|
|
3452
|
+
return await this.#koniState.transactionService.handleTransaction({
|
|
3453
|
+
address,
|
|
3454
|
+
chain,
|
|
3455
|
+
transaction,
|
|
3456
|
+
data,
|
|
3457
|
+
extrinsicType,
|
|
3458
|
+
chainType
|
|
3459
|
+
});
|
|
3460
|
+
}
|
|
3399
3461
|
|
|
3400
3462
|
/* Ledger */
|
|
3401
3463
|
|
|
@@ -3983,6 +4045,8 @@ export default class KoniExtension {
|
|
|
3983
4045
|
return this.fetchInappNotifications(request);
|
|
3984
4046
|
case 'pri(inappNotification.get)':
|
|
3985
4047
|
return this.getInappNotification(request);
|
|
4048
|
+
case 'pri(inappNotification.isClaimedPolygonBridge)':
|
|
4049
|
+
return this.getIsClaimedPolygonBridge(request);
|
|
3986
4050
|
/* Notification service */
|
|
3987
4051
|
|
|
3988
4052
|
/* Avail Bridge */
|
|
@@ -3990,6 +4054,13 @@ export default class KoniExtension {
|
|
|
3990
4054
|
return this.submitClaimAvailBridge(request);
|
|
3991
4055
|
/* Avail Bridge */
|
|
3992
4056
|
|
|
4057
|
+
/* Polygon Bridge */
|
|
4058
|
+
|
|
4059
|
+
case 'pri(polygonBridge.submitClaimPolygonBridge)':
|
|
4060
|
+
return this.submitClaimPolygonBridge(request);
|
|
4061
|
+
|
|
4062
|
+
/* Polygon Bridge */
|
|
4063
|
+
|
|
3993
4064
|
/* Ledger */
|
|
3994
4065
|
case 'pri(ledger.generic.allow)':
|
|
3995
4066
|
return this.subscribeLedgerGenericAllowChains(id, port);
|
|
@@ -6,6 +6,7 @@ import { EnvConfig } from '@subwallet/extension-base/constants';
|
|
|
6
6
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
7
7
|
import BuyService from '@subwallet/extension-base/services/buy-service';
|
|
8
8
|
import CampaignService from '@subwallet/extension-base/services/campaign-service';
|
|
9
|
+
import { ChainOnlineService } from '@subwallet/extension-base/services/chain-online-service';
|
|
9
10
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
10
11
|
import { _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest } from '@subwallet/extension-base/services/chain-service/types';
|
|
11
12
|
import EarningService from '@subwallet/extension-base/services/earning-service/service';
|
|
@@ -76,6 +77,7 @@ export default class KoniState {
|
|
|
76
77
|
readonly feeService: FeeService;
|
|
77
78
|
readonly swapService: SwapService;
|
|
78
79
|
readonly inappNotificationService: InappNotificationService;
|
|
80
|
+
readonly chainOnlineService: ChainOnlineService;
|
|
79
81
|
private generalStatus;
|
|
80
82
|
private waitSleeping;
|
|
81
83
|
private waitStarting;
|
|
@@ -11,6 +11,7 @@ import { BalanceService } from '@subwallet/extension-base/services/balance-servi
|
|
|
11
11
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
12
12
|
import BuyService from '@subwallet/extension-base/services/buy-service';
|
|
13
13
|
import CampaignService from '@subwallet/extension-base/services/campaign-service';
|
|
14
|
+
import { ChainOnlineService } from '@subwallet/extension-base/services/chain-online-service';
|
|
14
15
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
15
16
|
import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
|
|
16
17
|
import { _getEvmChainId, _getSubstrateGenesisHash, _getTokenOnChainAssetId, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
|
|
@@ -105,6 +106,7 @@ export default class KoniState {
|
|
|
105
106
|
this.feeService = new FeeService(this);
|
|
106
107
|
this.swapService = new SwapService(this);
|
|
107
108
|
this.inappNotificationService = new InappNotificationService(this.dbService, this.keyringService, this.eventService, this.chainService);
|
|
109
|
+
this.chainOnlineService = new ChainOnlineService(this.chainService, this.settingService, this.eventService, this.dbService);
|
|
108
110
|
this.subscription = new KoniSubscription(this, this.dbService);
|
|
109
111
|
this.cron = new KoniCron(this, this.subscription, this.dbService);
|
|
110
112
|
this.logger = createLogger('State');
|
|
@@ -198,7 +200,6 @@ export default class KoniState {
|
|
|
198
200
|
async init() {
|
|
199
201
|
await this.eventService.waitCryptoReady;
|
|
200
202
|
await this.chainService.init();
|
|
201
|
-
this.afterChainServiceInit();
|
|
202
203
|
await this.migrationService.run();
|
|
203
204
|
this.campaignService.init();
|
|
204
205
|
this.mktCampaignService.init();
|
|
@@ -214,7 +215,11 @@ export default class KoniState {
|
|
|
214
215
|
// TODO: consider moving this to a separate service
|
|
215
216
|
await this.dbService.stores.crowdloan.removeEndedCrowdloans();
|
|
216
217
|
await this.startSubscription();
|
|
218
|
+
this.chainOnlineService.checkLatestData();
|
|
217
219
|
this.chainService.checkLatestData();
|
|
220
|
+
this.chainService.subscribeChainInfoMap().subscribe(() => {
|
|
221
|
+
this.afterChainServiceInit();
|
|
222
|
+
});
|
|
218
223
|
}
|
|
219
224
|
async initMantaPay(password) {
|
|
220
225
|
var _this$chainService, _this$chainService$ma;
|
|
@@ -779,6 +784,7 @@ export default class KoniState {
|
|
|
779
784
|
return this.chainService.stopAllChainApis();
|
|
780
785
|
}
|
|
781
786
|
async resumeAllNetworks() {
|
|
787
|
+
this.chainOnlineService.checkLatestData();
|
|
782
788
|
return this.chainService.resumeAllChainApis();
|
|
783
789
|
}
|
|
784
790
|
publishCrowdloan(reset) {
|
|
@@ -1331,8 +1337,11 @@ export default class KoniState {
|
|
|
1331
1337
|
this.chainService.resetWallet(resetAll);
|
|
1332
1338
|
await this.walletConnectService.resetWallet(resetAll);
|
|
1333
1339
|
await this.chainService.init();
|
|
1334
|
-
this.
|
|
1340
|
+
this.chainOnlineService.checkLatestData();
|
|
1335
1341
|
this.chainService.checkLatestData();
|
|
1342
|
+
this.chainService.subscribeChainInfoMap().subscribe(() => {
|
|
1343
|
+
this.afterChainServiceInit();
|
|
1344
|
+
});
|
|
1336
1345
|
}
|
|
1337
1346
|
async enableMantaPay(updateStore, address, password, seedPhrase) {
|
|
1338
1347
|
var _this$chainService3, _this$chainService3$m, _this$chainService4, _this$chainService4$m, _this$chainService4$m2, _this$chainService11, _this$chainService11$, _this$chainService11$2;
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.9-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -271,6 +271,7 @@
|
|
|
271
271
|
"./koni/api/contract-handler/utils/erc721_abi.json": "./koni/api/contract-handler/utils/erc721_abi.json",
|
|
272
272
|
"./koni/api/contract-handler/utils/neuroguns_psp34_abi.json": "./koni/api/contract-handler/utils/neuroguns_psp34_abi.json",
|
|
273
273
|
"./koni/api/contract-handler/utils/pink_psp34_abi.json": "./koni/api/contract-handler/utils/pink_psp34_abi.json",
|
|
274
|
+
"./koni/api/contract-handler/utils/polygon_bridge_abi.json": "./koni/api/contract-handler/utils/polygon_bridge_abi.json",
|
|
274
275
|
"./koni/api/contract-handler/utils/psp22_abi.json": "./koni/api/contract-handler/utils/psp22_abi.json",
|
|
275
276
|
"./koni/api/contract-handler/utils/psp34_abi.json": "./koni/api/contract-handler/utils/psp34_abi.json",
|
|
276
277
|
"./koni/api/contract-handler/utils/snowbridge_gateway_abi.json": "./koni/api/contract-handler/utils/snowbridge_gateway_abi.json",
|
|
@@ -716,6 +717,11 @@
|
|
|
716
717
|
"require": "./cjs/services/balance-service/transfer/xcm/polkadotXcm.js",
|
|
717
718
|
"default": "./services/balance-service/transfer/xcm/polkadotXcm.js"
|
|
718
719
|
},
|
|
720
|
+
"./services/balance-service/transfer/xcm/polygonBridge": {
|
|
721
|
+
"types": "./services/balance-service/transfer/xcm/polygonBridge.d.ts",
|
|
722
|
+
"require": "./cjs/services/balance-service/transfer/xcm/polygonBridge.js",
|
|
723
|
+
"default": "./services/balance-service/transfer/xcm/polygonBridge.js"
|
|
724
|
+
},
|
|
719
725
|
"./services/balance-service/transfer/xcm/snowBridge": {
|
|
720
726
|
"types": "./services/balance-service/transfer/xcm/snowBridge.d.ts",
|
|
721
727
|
"require": "./cjs/services/balance-service/transfer/xcm/snowBridge.js",
|
|
@@ -776,6 +782,16 @@
|
|
|
776
782
|
"require": "./cjs/services/campaign-service/types.js",
|
|
777
783
|
"default": "./services/campaign-service/types.js"
|
|
778
784
|
},
|
|
785
|
+
"./services/chain-online-service": {
|
|
786
|
+
"types": "./services/chain-online-service/index.d.ts",
|
|
787
|
+
"require": "./cjs/services/chain-online-service/index.js",
|
|
788
|
+
"default": "./services/chain-online-service/index.js"
|
|
789
|
+
},
|
|
790
|
+
"./services/chain-online-service/constants": {
|
|
791
|
+
"types": "./services/chain-online-service/constants.d.ts",
|
|
792
|
+
"require": "./cjs/services/chain-online-service/constants.js",
|
|
793
|
+
"default": "./services/chain-online-service/constants.js"
|
|
794
|
+
},
|
|
779
795
|
"./services/chain-service": {
|
|
780
796
|
"types": "./services/chain-service/index.d.ts",
|
|
781
797
|
"require": "./cjs/services/chain-service/index.js",
|
|
@@ -1124,9 +1140,24 @@
|
|
|
1124
1140
|
"default": "./services/inapp-notification-service/interfaces.js"
|
|
1125
1141
|
},
|
|
1126
1142
|
"./services/inapp-notification-service/utils": {
|
|
1127
|
-
"types": "./services/inapp-notification-service/utils.d.ts",
|
|
1128
|
-
"require": "./cjs/services/inapp-notification-service/utils.js",
|
|
1129
|
-
"default": "./services/inapp-notification-service/utils.js"
|
|
1143
|
+
"types": "./services/inapp-notification-service/utils/index.d.ts",
|
|
1144
|
+
"require": "./cjs/services/inapp-notification-service/utils/index.js",
|
|
1145
|
+
"default": "./services/inapp-notification-service/utils/index.js"
|
|
1146
|
+
},
|
|
1147
|
+
"./services/inapp-notification-service/utils/avail": {
|
|
1148
|
+
"types": "./services/inapp-notification-service/utils/avail.d.ts",
|
|
1149
|
+
"require": "./cjs/services/inapp-notification-service/utils/avail.js",
|
|
1150
|
+
"default": "./services/inapp-notification-service/utils/avail.js"
|
|
1151
|
+
},
|
|
1152
|
+
"./services/inapp-notification-service/utils/common": {
|
|
1153
|
+
"types": "./services/inapp-notification-service/utils/common.d.ts",
|
|
1154
|
+
"require": "./cjs/services/inapp-notification-service/utils/common.js",
|
|
1155
|
+
"default": "./services/inapp-notification-service/utils/common.js"
|
|
1156
|
+
},
|
|
1157
|
+
"./services/inapp-notification-service/utils/polygon": {
|
|
1158
|
+
"types": "./services/inapp-notification-service/utils/polygon.d.ts",
|
|
1159
|
+
"require": "./cjs/services/inapp-notification-service/utils/polygon.js",
|
|
1160
|
+
"default": "./services/inapp-notification-service/utils/polygon.js"
|
|
1130
1161
|
},
|
|
1131
1162
|
"./services/keyring-service": {
|
|
1132
1163
|
"types": "./services/keyring-service/index.d.ts",
|
|
@@ -1358,6 +1389,11 @@
|
|
|
1358
1389
|
"require": "./cjs/services/migration-service/scripts/MigrateTransactionHistory.js",
|
|
1359
1390
|
"default": "./services/migration-service/scripts/MigrateTransactionHistory.js"
|
|
1360
1391
|
},
|
|
1392
|
+
"./services/migration-service/scripts/MigrateTransactionHistoryBridge": {
|
|
1393
|
+
"types": "./services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts",
|
|
1394
|
+
"require": "./cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js",
|
|
1395
|
+
"default": "./services/migration-service/scripts/MigrateTransactionHistoryBridge.js"
|
|
1396
|
+
},
|
|
1361
1397
|
"./services/migration-service/scripts/MigrateTransactionHistoryBySymbol": {
|
|
1362
1398
|
"types": "./services/migration-service/scripts/MigrateTransactionHistoryBySymbol.d.ts",
|
|
1363
1399
|
"require": "./cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js",
|
|
@@ -1848,6 +1884,11 @@
|
|
|
1848
1884
|
"require": "./cjs/stores/Base.js",
|
|
1849
1885
|
"default": "./stores/Base.js"
|
|
1850
1886
|
},
|
|
1887
|
+
"./stores/ChainlistStore": {
|
|
1888
|
+
"types": "./stores/ChainlistStore.d.ts",
|
|
1889
|
+
"require": "./cjs/stores/ChainlistStore.js",
|
|
1890
|
+
"default": "./stores/ChainlistStore.js"
|
|
1891
|
+
},
|
|
1851
1892
|
"./stores/CurrentAccountStore": {
|
|
1852
1893
|
"types": "./stores/CurrentAccountStore.d.ts",
|
|
1853
1894
|
"require": "./cjs/stores/CurrentAccountStore.js",
|
|
@@ -2008,16 +2049,16 @@
|
|
|
2008
2049
|
"require": "./cjs/types/account/info/proxy.js",
|
|
2009
2050
|
"default": "./types/account/info/proxy.js"
|
|
2010
2051
|
},
|
|
2011
|
-
"./types/avail-bridge": {
|
|
2012
|
-
"types": "./types/avail-bridge/index.d.ts",
|
|
2013
|
-
"require": "./cjs/types/avail-bridge/index.js",
|
|
2014
|
-
"default": "./types/avail-bridge/index.js"
|
|
2015
|
-
},
|
|
2016
2052
|
"./types/balance": {
|
|
2017
2053
|
"types": "./types/balance/index.d.ts",
|
|
2018
2054
|
"require": "./cjs/types/balance/index.js",
|
|
2019
2055
|
"default": "./types/balance/index.js"
|
|
2020
2056
|
},
|
|
2057
|
+
"./types/bridge": {
|
|
2058
|
+
"types": "./types/bridge/index.d.ts",
|
|
2059
|
+
"require": "./cjs/types/bridge/index.js",
|
|
2060
|
+
"default": "./types/bridge/index.js"
|
|
2061
|
+
},
|
|
2021
2062
|
"./types/buy": {
|
|
2022
2063
|
"types": "./types/buy.d.ts",
|
|
2023
2064
|
"require": "./cjs/types/buy.js",
|
|
@@ -2450,11 +2491,11 @@
|
|
|
2450
2491
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2451
2492
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2452
2493
|
"@substrate/connect": "^0.8.9",
|
|
2453
|
-
"@subwallet/chain-list": "0.2.95-beta.
|
|
2454
|
-
"@subwallet/extension-base": "^1.3.
|
|
2455
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2456
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2457
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2494
|
+
"@subwallet/chain-list": "0.2.95-beta.1",
|
|
2495
|
+
"@subwallet/extension-base": "^1.3.9-0",
|
|
2496
|
+
"@subwallet/extension-chains": "^1.3.9-0",
|
|
2497
|
+
"@subwallet/extension-dapp": "^1.3.9-0",
|
|
2498
|
+
"@subwallet/extension-inject": "^1.3.9-0",
|
|
2458
2499
|
"@subwallet/keyring": "^0.1.8-beta.0",
|
|
2459
2500
|
"@subwallet/ui-keyring": "^0.1.8-beta.0",
|
|
2460
2501
|
"@ton/core": "^0.56.3",
|
|
@@ -2488,6 +2529,7 @@
|
|
|
2488
2529
|
"protobufjs": "^7.2.4",
|
|
2489
2530
|
"rxjs": "^7.8.1",
|
|
2490
2531
|
"sails-js": "^0.1.6",
|
|
2532
|
+
"ts-md5": "^1.3.1",
|
|
2491
2533
|
"tweetnacl": "^1.0.3",
|
|
2492
2534
|
"uuid": "^9.0.0",
|
|
2493
2535
|
"web3": "^1.10.0",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.3.
|
|
10
|
+
version: '1.3.9-0'
|
|
11
11
|
};
|
|
@@ -47,7 +47,9 @@ export declare class BalanceService implements StoppableServiceInterface {
|
|
|
47
47
|
getBalanceDetectCache(update: (value: DetectBalanceCache) => void): void;
|
|
48
48
|
setBalanceDetectCache(addresses: string[]): void;
|
|
49
49
|
/** Subscribe token free balance of an address on chain */
|
|
50
|
+
subscribeBalance(address: string, chain: string, tokenSlug: string | undefined, balanceType?: 'transferable' | 'total' | 'keepAlive', extrinsicType?: ExtrinsicType, callback?: (rs: AmountData) => void): Promise<[() => void, AmountData]>;
|
|
50
51
|
subscribeTransferableBalance(address: string, chain: string, tokenSlug: string | undefined, extrinsicType?: ExtrinsicType, callback?: (rs: AmountData) => void): Promise<[() => void, AmountData]>;
|
|
52
|
+
subscribeTotalBalance(address: string, chain: string, tokenSlug: string | undefined, extrinsicType?: ExtrinsicType, callback?: (rs: AmountData) => void): Promise<[() => void, AmountData]>;
|
|
51
53
|
/**
|
|
52
54
|
* @public
|
|
53
55
|
* @async
|
|
@@ -60,6 +62,7 @@ export declare class BalanceService implements StoppableServiceInterface {
|
|
|
60
62
|
* @return {Promise<AmountData>} - Free token balance of address on chain
|
|
61
63
|
*/
|
|
62
64
|
getTransferableBalance(address: string, chain: string, tokenSlug?: string, extrinsicType?: ExtrinsicType): Promise<AmountData>;
|
|
65
|
+
getTotalBalance(address: string, chain: string, tokenSlug?: string, extrinsicType?: ExtrinsicType): Promise<AmountData>;
|
|
63
66
|
/** Remove balance from the subject object by addresses */
|
|
64
67
|
removeBalanceByAddresses(addresses: string[]): void;
|
|
65
68
|
/** Remove inactive asset from the balance map */
|
|
@@ -13,6 +13,7 @@ import { addLazy, createPromiseHandler, isAccountAll, waitTimeout } from '@subwa
|
|
|
13
13
|
import { getKeypairTypeByAddress } from '@subwallet/keyring';
|
|
14
14
|
import { EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
|
|
15
15
|
import keyring from '@subwallet/ui-keyring';
|
|
16
|
+
import BigN from 'bignumber.js';
|
|
16
17
|
import { t } from 'i18next';
|
|
17
18
|
import { BehaviorSubject } from 'rxjs';
|
|
18
19
|
import { noop } from '@polkadot/util';
|
|
@@ -164,7 +165,7 @@ export class BalanceService {
|
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
/** Subscribe token free balance of an address on chain */
|
|
167
|
-
async
|
|
168
|
+
async subscribeBalance(address, chain, tokenSlug, balanceType = 'transferable', extrinsicType, callback) {
|
|
168
169
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
169
170
|
const chainState = this.state.chainService.getChainStateByKey(chain);
|
|
170
171
|
if (!chainInfo || !chainState || !chainState.active) {
|
|
@@ -193,10 +194,18 @@ export class BalanceService {
|
|
|
193
194
|
let unsub = noop;
|
|
194
195
|
unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, result => {
|
|
195
196
|
const rs = result[0];
|
|
197
|
+
let value;
|
|
198
|
+
switch (balanceType) {
|
|
199
|
+
case 'total':
|
|
200
|
+
value = new BigN(rs.free).plus(new BigN(rs.locked)).toFixed();
|
|
201
|
+
break;
|
|
202
|
+
default:
|
|
203
|
+
value = rs.free;
|
|
204
|
+
}
|
|
196
205
|
if (rs.tokenSlug === tSlug && rs.state !== APIItemState.PENDING) {
|
|
197
206
|
hasError = false;
|
|
198
207
|
const balance = {
|
|
199
|
-
value
|
|
208
|
+
value,
|
|
200
209
|
decimals: tokenInfo.decimals || 0,
|
|
201
210
|
symbol: tokenInfo.symbol,
|
|
202
211
|
metadata: rs.metadata
|
|
@@ -220,6 +229,12 @@ export class BalanceService {
|
|
|
220
229
|
}, 9999);
|
|
221
230
|
});
|
|
222
231
|
}
|
|
232
|
+
async subscribeTransferableBalance(address, chain, tokenSlug, extrinsicType, callback) {
|
|
233
|
+
return this.subscribeBalance(address, chain, tokenSlug, 'transferable', extrinsicType, callback);
|
|
234
|
+
}
|
|
235
|
+
async subscribeTotalBalance(address, chain, tokenSlug, extrinsicType, callback) {
|
|
236
|
+
return this.subscribeBalance(address, chain, tokenSlug, 'total', extrinsicType, callback);
|
|
237
|
+
}
|
|
223
238
|
|
|
224
239
|
/**
|
|
225
240
|
* @public
|
|
@@ -236,6 +251,10 @@ export class BalanceService {
|
|
|
236
251
|
const [, balance] = await this.subscribeTransferableBalance(address, chain, tokenSlug, extrinsicType);
|
|
237
252
|
return balance;
|
|
238
253
|
}
|
|
254
|
+
async getTotalBalance(address, chain, tokenSlug, extrinsicType) {
|
|
255
|
+
const [, balance] = await this.subscribeTotalBalance(address, chain, tokenSlug, extrinsicType);
|
|
256
|
+
return balance;
|
|
257
|
+
}
|
|
239
258
|
|
|
240
259
|
/** Remove balance from the subject object by addresses */
|
|
241
260
|
removeBalanceByAddresses(addresses) {
|
|
@@ -8,6 +8,7 @@ import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/cont
|
|
|
8
8
|
import { EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
9
9
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
10
10
|
import BigN from 'bignumber.js';
|
|
11
|
+
import { t } from 'i18next';
|
|
11
12
|
export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, web3Api) {
|
|
12
13
|
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
13
14
|
const networkKey = chainInfo.slug;
|
|
@@ -78,11 +79,21 @@ export async function getERC721Transaction(web3Api, chain, contractAddress, send
|
|
|
78
79
|
var _priority$maxFeePerGa3, _priority$maxPriority3;
|
|
79
80
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
80
81
|
const contract = new web3Api.api.eth.Contract(_ERC721_ABI, contractAddress);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
let gasLimit;
|
|
83
|
+
let priority;
|
|
84
|
+
try {
|
|
85
|
+
[gasLimit, priority] = await Promise.all([
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
87
|
+
contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).estimateGas({
|
|
88
|
+
from: senderAddress
|
|
89
|
+
}), calculateGasFeeParams(web3Api, chain)]);
|
|
90
|
+
} catch (e) {
|
|
91
|
+
const error = e;
|
|
92
|
+
if (error.message.includes('transfer to non ERC721Receiver implementer')) {
|
|
93
|
+
error.message = t('Unable to send. NFT not supported on recipient address');
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
86
97
|
return {
|
|
87
98
|
from: senderAddress,
|
|
88
99
|
gasPrice: priority.gasPrice,
|
|
@@ -18,4 +18,5 @@ export declare const createSnowBridgeExtrinsic: ({ chainInfoMap, destinationToke
|
|
|
18
18
|
export declare const createXcmExtrinsic: ({ chainInfoMap, destinationTokenInfo, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
19
19
|
export declare const createAvailBridgeTxFromEth: ({ chainInfoMap, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
20
20
|
export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
21
|
+
export declare const createPolygonBridgeExtrinsic: ({ chainInfoMap, destinationTokenInfo, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
21
22
|
export declare const getXcmMockTxFee: (substrateApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>, originTokenInfo: _ChainAsset, destinationTokenInfo: _ChainAsset) => Promise<BigN>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
4
|
+
import { _isPolygonBridgeXcm, _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
5
|
import { getAvailBridgeExtrinsicFromAvail, getAvailBridgeTxFromEth } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
6
6
|
import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
|
|
7
|
+
import { _createPolygonBridgeL1toL2Extrinsic, _createPolygonBridgeL2toL1Extrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
7
8
|
import { getSnowBridgeEvmTransfer } from '@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge';
|
|
8
9
|
import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet';
|
|
9
10
|
import { getExtrinsicByXtokensPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens';
|
|
@@ -85,6 +86,33 @@ export const createAvailBridgeExtrinsicFromAvail = async ({
|
|
|
85
86
|
}
|
|
86
87
|
return await getAvailBridgeExtrinsicFromAvail(recipient, sendingValue, substrateApi);
|
|
87
88
|
};
|
|
89
|
+
export const createPolygonBridgeExtrinsic = async ({
|
|
90
|
+
chainInfoMap,
|
|
91
|
+
destinationTokenInfo,
|
|
92
|
+
evmApi,
|
|
93
|
+
originTokenInfo,
|
|
94
|
+
recipient,
|
|
95
|
+
sender,
|
|
96
|
+
sendingValue
|
|
97
|
+
}) => {
|
|
98
|
+
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
99
|
+
const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
100
|
+
if (!_isPolygonBridgeXcm(originChainInfo, destinationChainInfo)) {
|
|
101
|
+
throw new Error('This is not a valid PolygonBridge transfer');
|
|
102
|
+
}
|
|
103
|
+
if (!evmApi) {
|
|
104
|
+
throw Error('Evm API is not available');
|
|
105
|
+
}
|
|
106
|
+
if (!sender) {
|
|
107
|
+
throw Error('Sender is required');
|
|
108
|
+
}
|
|
109
|
+
const sourceChain = originChainInfo.slug;
|
|
110
|
+
if (sourceChain === 'polygonzkEvm_cardona' || sourceChain === 'polygonZkEvm') {
|
|
111
|
+
return _createPolygonBridgeL2toL1Extrinsic(originTokenInfo, originChainInfo, sender, recipient, sendingValue, evmApi);
|
|
112
|
+
} else {
|
|
113
|
+
return _createPolygonBridgeL1toL2Extrinsic(originTokenInfo, originChainInfo, sender, recipient, sendingValue, evmApi);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
88
116
|
export const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
|
|
89
117
|
try {
|
|
90
118
|
var _paymentInfo$partialF;
|