@subwallet/extension-base 1.3.22-0 → 1.3.24-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 +77 -4
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/index.js +21 -4
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +57 -36
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +12 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -16
- package/cjs/koni/api/staking/index.js +3 -4
- package/cjs/koni/background/handlers/Extension.js +343 -185
- package/cjs/koni/background/handlers/State.js +17 -2
- package/cjs/koni/background/handlers/Tabs.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
- package/cjs/services/balance-service/index.js +4 -2
- package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
- package/cjs/services/balance-service/transfer/smart-contract.js +24 -3
- package/cjs/services/balance-service/transfer/token.js +4 -4
- package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
- package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
- package/cjs/services/chain-service/handler/TonApi.js +2 -5
- package/cjs/services/chain-service/index.js +40 -7
- package/cjs/services/chain-service/utils/index.js +40 -11
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/cjs/services/earning-service/service.js +6 -12
- package/cjs/services/fee-service/service.js +19 -8
- package/cjs/services/fee-service/utils/tokenPayFee.js +151 -0
- package/cjs/services/history-service/index.js +4 -6
- package/cjs/services/inapp-notification-service/index.js +12 -4
- package/cjs/services/keyring-service/context/account-context.js +17 -2
- package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
- package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
- package/cjs/services/keyring-service/utils.js +18 -0
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/cjs/services/request-service/index.js +22 -4
- package/cjs/services/setting-service/constants.js +10 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
- package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
- package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
- package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
- package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
- package/cjs/services/swap-service/index.js +31 -22
- package/cjs/services/swap-service/utils.js +21 -38
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +286 -26
- package/cjs/services/transaction-service/utils.js +5 -1
- package/cjs/types/account/info/keyring.js +12 -1
- package/cjs/types/fee/cardano.js +1 -0
- package/cjs/types/swap/index.js +7 -2
- package/cjs/utils/account/analyze.js +2 -1
- package/cjs/utils/account/common.js +29 -20
- package/cjs/utils/account/derive/info/solo.js +9 -4
- package/cjs/utils/account/derive/validate.js +36 -2
- package/cjs/utils/account/transform.js +38 -13
- package/cjs/utils/fee/transfer.js +87 -21
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/index.d.ts +6 -1
- package/constants/index.js +14 -1
- package/constants/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +33 -12
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +13 -3
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/crowdloan.js +3 -3
- package/koni/api/nft/index.js +10 -16
- package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
- package/koni/api/staking/index.js +4 -5
- package/koni/background/handlers/Extension.d.ts +9 -0
- package/koni/background/handlers/Extension.js +225 -69
- package/koni/background/handlers/State.d.ts +6 -2
- package/koni/background/handlers/State.js +18 -3
- package/koni/background/handlers/Tabs.js +1 -1
- package/package.json +76 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
- package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
- package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
- package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +23 -9
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
- package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
- package/services/balance-service/index.js +4 -2
- package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
- package/services/balance-service/transfer/cardano-transfer.js +114 -0
- package/services/balance-service/transfer/smart-contract.d.ts +4 -2
- package/services/balance-service/transfer/smart-contract.js +24 -3
- package/services/balance-service/transfer/token.d.ts +1 -1
- package/services/balance-service/transfer/token.js +2 -2
- package/services/chain-service/handler/CardanoApi.d.ts +38 -0
- package/services/chain-service/handler/CardanoApi.js +167 -0
- package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
- package/services/chain-service/handler/CardanoChainHandler.js +75 -0
- package/services/chain-service/handler/TonApi.js +3 -6
- package/services/chain-service/handler/types.d.ts +1 -0
- package/services/chain-service/index.d.ts +4 -1
- package/services/chain-service/index.js +41 -8
- package/services/chain-service/types.d.ts +9 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +32 -11
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/services/earning-service/service.js +8 -14
- package/services/fee-service/interfaces.d.ts +25 -0
- package/services/fee-service/service.js +19 -8
- package/services/fee-service/utils/tokenPayFee.d.ts +8 -0
- package/services/fee-service/utils/tokenPayFee.js +141 -0
- package/services/history-service/index.js +6 -8
- package/services/inapp-notification-service/index.d.ts +3 -4
- package/services/inapp-notification-service/index.js +14 -6
- package/services/keyring-service/context/account-context.d.ts +6 -2
- package/services/keyring-service/context/account-context.js +17 -2
- package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
- package/services/keyring-service/context/handlers/Derive.js +10 -8
- package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
- package/services/keyring-service/context/handlers/Migration.js +258 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/services/keyring-service/context/handlers/Secret.js +2 -2
- package/services/keyring-service/utils.d.ts +2 -0
- package/services/keyring-service/utils.js +11 -0
- package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
- package/services/request-service/handler/CardanoRequestHandler.js +163 -0
- package/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -1
- package/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/services/request-service/index.d.ts +7 -4
- package/services/request-service/index.js +21 -7
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
- package/services/storage-service/db-stores/InappNotification.js +6 -0
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
- package/services/swap-service/handler/asset-hub/handler.js +2 -61
- package/services/swap-service/handler/base-handler.d.ts +1 -4
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
- package/services/swap-service/handler/chainflip-handler.js +31 -280
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
- package/services/swap-service/handler/hydradx-handler.js +13 -180
- package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
- package/services/swap-service/handler/simpleswap-handler.js +5 -226
- package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
- package/services/swap-service/handler/uniswap-handler.js +323 -0
- package/services/swap-service/index.js +30 -22
- package/services/swap-service/utils.d.ts +1 -5
- package/services/swap-service/utils.js +7 -21
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +8 -2
- package/services/transaction-service/index.js +273 -17
- package/services/transaction-service/types.d.ts +7 -0
- package/services/transaction-service/utils.js +7 -2
- package/types/account/info/keyring.d.ts +4 -1
- package/types/account/info/keyring.js +9 -0
- package/types/account/info/proxy.d.ts +2 -0
- package/types/balance/index.d.ts +4 -1
- package/types/fee/base.d.ts +1 -1
- package/types/fee/cardano.d.ts +18 -0
- package/types/fee/cardano.js +1 -0
- package/types/fee/option.d.ts +1 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/swap/index.d.ts +11 -3
- package/types/swap/index.js +7 -2
- package/utils/account/analyze.js +2 -1
- package/utils/account/common.d.ts +11 -6
- package/utils/account/common.js +28 -19
- package/utils/account/derive/info/solo.js +10 -5
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +34 -1
- package/utils/account/transform.d.ts +2 -1
- package/utils/account/transform.js +37 -13
- package/utils/fee/transfer.d.ts +3 -2
- package/utils/fee/transfer.js +90 -24
- package/utils/index.js +4 -4
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/oldChainPrefix.json +1 -0
|
@@ -5,9 +5,9 @@ import { _AssetType } from '@subwallet/chain-list/types';
|
|
|
5
5
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { ALL_ACCOUNT_KEY, isProductionMode } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { _getSubstrateGenesisHash } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
-
import { AccountActions, AccountChainType, AccountProxyType, AccountSignMode } from '@subwallet/extension-base/types';
|
|
8
|
+
import { AccountActions, AccountChainType, AccountProxyType, AccountSignMode, SUPPORTED_ACCOUNT_CHAIN_TYPES } from '@subwallet/extension-base/types';
|
|
9
9
|
import { getKeypairTypeByAddress, tonMnemonicToEntropy } from '@subwallet/keyring';
|
|
10
|
-
import { BitcoinKeypairTypes, EthereumKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
10
|
+
import { BitcoinKeypairTypes, CardanoKeypairTypes, EthereumKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
11
11
|
import { tonMnemonicValidate } from '@subwallet/keyring/utils';
|
|
12
12
|
import { hexStripPrefix, u8aToHex } from '@polkadot/util';
|
|
13
13
|
import { blake2AsHex, mnemonicToEntropy, mnemonicValidate } from '@polkadot/util-crypto';
|
|
@@ -32,8 +32,21 @@ export const createAccountProxyId = (_suri, derivationPath) => {
|
|
|
32
32
|
}
|
|
33
33
|
return blake2AsHex(data, 256);
|
|
34
34
|
};
|
|
35
|
-
export const
|
|
36
|
-
return type ? EthereumKeypairTypes.includes(type) ? AccountChainType.ETHEREUM : TonKeypairTypes.includes(type) ? AccountChainType.TON : BitcoinKeypairTypes.includes(type) ? AccountChainType.BITCOIN : AccountChainType.SUBSTRATE : AccountChainType.SUBSTRATE;
|
|
35
|
+
export const getAccountChainTypeFromKeypairType = type => {
|
|
36
|
+
return type ? EthereumKeypairTypes.includes(type) ? AccountChainType.ETHEREUM : TonKeypairTypes.includes(type) ? AccountChainType.TON : BitcoinKeypairTypes.includes(type) ? AccountChainType.BITCOIN : CardanoKeypairTypes.includes(type) ? AccountChainType.CARDANO : AccountChainType.SUBSTRATE : AccountChainType.SUBSTRATE;
|
|
37
|
+
};
|
|
38
|
+
export const getDefaultKeypairTypeFromAccountChainType = type => {
|
|
39
|
+
if (type === AccountChainType.ETHEREUM) {
|
|
40
|
+
return 'ethereum';
|
|
41
|
+
} else if (type === AccountChainType.TON) {
|
|
42
|
+
return 'ton';
|
|
43
|
+
} else if (type === AccountChainType.BITCOIN) {
|
|
44
|
+
return 'bitcoin-84';
|
|
45
|
+
} else if (type === AccountChainType.CARDANO) {
|
|
46
|
+
return 'cardano';
|
|
47
|
+
} else {
|
|
48
|
+
return 'sr25519';
|
|
49
|
+
}
|
|
37
50
|
};
|
|
38
51
|
export const getAccountSignMode = (address, _meta) => {
|
|
39
52
|
const meta = _meta;
|
|
@@ -68,6 +81,7 @@ export const getAccountActions = (signMode, networkType, type, _meta, parentAcco
|
|
|
68
81
|
const result = [];
|
|
69
82
|
const meta = _meta;
|
|
70
83
|
|
|
84
|
+
// todo: check this function for Cardano
|
|
71
85
|
// JSON
|
|
72
86
|
if (signMode === AccountSignMode.PASSWORD) {
|
|
73
87
|
result.push(AccountActions.EXPORT_JSON);
|
|
@@ -146,6 +160,8 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
146
160
|
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...OTHER_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...EVM_ACTIONS];
|
|
147
161
|
case AccountChainType.TON:
|
|
148
162
|
return [...BASE_TRANSFER_ACTIONS];
|
|
163
|
+
case AccountChainType.CARDANO:
|
|
164
|
+
return [...BASE_TRANSFER_ACTIONS];
|
|
149
165
|
}
|
|
150
166
|
} else if (signMode === AccountSignMode.QR) {
|
|
151
167
|
switch (networkType) {
|
|
@@ -155,6 +171,8 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
155
171
|
return [...(isProductionMode ? [] : [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OTHER_ACTIONS, ...EVM_ACTIONS])];
|
|
156
172
|
case AccountChainType.TON:
|
|
157
173
|
return [];
|
|
174
|
+
case AccountChainType.CARDANO:
|
|
175
|
+
return [];
|
|
158
176
|
}
|
|
159
177
|
} else if (signMode === AccountSignMode.GENERIC_LEDGER) {
|
|
160
178
|
switch (networkType) {
|
|
@@ -170,6 +188,8 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
170
188
|
ExtrinsicType.SEND_NFT, ExtrinsicType.SWAP];
|
|
171
189
|
case AccountChainType.TON:
|
|
172
190
|
return [...BASE_TRANSFER_ACTIONS];
|
|
191
|
+
case AccountChainType.CARDANO:
|
|
192
|
+
return [];
|
|
173
193
|
}
|
|
174
194
|
} else if (signMode === AccountSignMode.LEGACY_LEDGER) {
|
|
175
195
|
// Only for Substrate
|
|
@@ -229,6 +249,8 @@ export const getAccountTokenTypes = type => {
|
|
|
229
249
|
case 'bitcoin-86':
|
|
230
250
|
case 'bittest-86':
|
|
231
251
|
return [_AssetType.NATIVE, _AssetType.RUNE, _AssetType.BRC20];
|
|
252
|
+
case 'cardano':
|
|
253
|
+
return [_AssetType.NATIVE, _AssetType.CIP26];
|
|
232
254
|
default:
|
|
233
255
|
return [];
|
|
234
256
|
}
|
|
@@ -253,7 +275,7 @@ export const getAccountTokenTypes = type => {
|
|
|
253
275
|
export const transformAccount = (address, _type, meta, chainInfoMap, parentAccount) => {
|
|
254
276
|
const signMode = getAccountSignMode(address, meta);
|
|
255
277
|
const type = _type || getKeypairTypeByAddress(address);
|
|
256
|
-
const chainType =
|
|
278
|
+
const chainType = getAccountChainTypeFromKeypairType(type);
|
|
257
279
|
let specialChain;
|
|
258
280
|
if (!chainInfoMap) {
|
|
259
281
|
return {
|
|
@@ -307,7 +329,7 @@ export const pairToAccount = ({
|
|
|
307
329
|
export const transformAccounts = accounts => Object.values(accounts).map(data => singleAddressToAccount(data));
|
|
308
330
|
export const transformAddress = (address, meta) => {
|
|
309
331
|
const type = getKeypairTypeByAddress(address);
|
|
310
|
-
const chainType =
|
|
332
|
+
const chainType = getAccountChainTypeFromKeypairType(type);
|
|
311
333
|
return {
|
|
312
334
|
address,
|
|
313
335
|
...meta,
|
|
@@ -382,6 +404,7 @@ export const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
|
382
404
|
let tokenTypes = [];
|
|
383
405
|
let accountActions = [];
|
|
384
406
|
let specialChain;
|
|
407
|
+
let isNeedMigrateUnifiedAccount;
|
|
385
408
|
if (value.accounts.length > 1) {
|
|
386
409
|
accountType = AccountProxyType.UNIFIED;
|
|
387
410
|
chainTypes = Array.from(value.accounts.reduce((rs, account) => rs.add(account.chainType), new Set()));
|
|
@@ -391,6 +414,9 @@ export const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
|
391
414
|
}
|
|
392
415
|
return rs;
|
|
393
416
|
}, new Set()));
|
|
417
|
+
if (chainTypes.length < SUPPORTED_ACCOUNT_CHAIN_TYPES.length) {
|
|
418
|
+
isNeedMigrateUnifiedAccount = true;
|
|
419
|
+
}
|
|
394
420
|
|
|
395
421
|
/* Account actions */
|
|
396
422
|
|
|
@@ -422,6 +448,9 @@ export const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
|
422
448
|
if (account.chainType === AccountChainType.TON) {
|
|
423
449
|
accountActions = accountActions.filter(action => action !== AccountActions.DERIVE);
|
|
424
450
|
}
|
|
451
|
+
if (chainTypes.length === 1 && accountActions.includes(AccountActions.EXPORT_MNEMONIC) && account.isMasterAccount && account.type !== 'ton-native') {
|
|
452
|
+
isNeedMigrateUnifiedAccount = true;
|
|
453
|
+
}
|
|
425
454
|
switch (account.signMode) {
|
|
426
455
|
case AccountSignMode.GENERIC_LEDGER:
|
|
427
456
|
case AccountSignMode.LEGACY_LEDGER:
|
|
@@ -435,7 +464,8 @@ export const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
|
435
464
|
chainTypes,
|
|
436
465
|
specialChain,
|
|
437
466
|
tokenTypes,
|
|
438
|
-
accountActions
|
|
467
|
+
accountActions,
|
|
468
|
+
isNeedMigrateUnifiedAccount
|
|
439
469
|
}];
|
|
440
470
|
}));
|
|
441
471
|
const deepSearchParentId = parentId => {
|
|
@@ -511,15 +541,9 @@ export const combineAllAccountProxy = accountProxies => {
|
|
|
511
541
|
const tokenTypes = new Set();
|
|
512
542
|
const specialChain = accountProxies.length === 1 ? accountProxies[0].specialChain : undefined;
|
|
513
543
|
for (const accountProxy of accountProxies) {
|
|
514
|
-
// Have 4 network types, but at the moment, we only support 3 network types
|
|
515
|
-
if (chainTypes.size === 3) {
|
|
516
|
-
break;
|
|
517
|
-
}
|
|
518
544
|
for (const chainType of accountProxy.chainTypes) {
|
|
519
545
|
chainTypes.add(chainType);
|
|
520
546
|
}
|
|
521
|
-
}
|
|
522
|
-
for (const accountProxy of accountProxies) {
|
|
523
547
|
for (const tokenType of accountProxy.tokenTypes) {
|
|
524
548
|
tokenTypes.add(tokenType);
|
|
525
549
|
}
|
package/utils/fee/transfer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { AmountData } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
-
import { _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
+
import { _CardanoApi, _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
4
|
import { FeeChainType, FeeInfo, TransactionFee } from '@subwallet/extension-base/types';
|
|
5
5
|
import { ResponseSubscribeTransfer } from '@subwallet/extension-base/types/balance/transfer';
|
|
6
6
|
export interface CalculateMaxTransferable extends TransactionFee {
|
|
@@ -12,6 +12,7 @@ export interface CalculateMaxTransferable extends TransactionFee {
|
|
|
12
12
|
substrateApi: _SubstrateApi;
|
|
13
13
|
evmApi: _EvmApi;
|
|
14
14
|
tonApi: _TonApi;
|
|
15
|
+
cardanoApi: _CardanoApi;
|
|
15
16
|
isTransferLocalTokenAndPayThatTokenAsFee: boolean;
|
|
16
17
|
isTransferNativeTokenAndPayLocalTokenAsFee: boolean;
|
|
17
18
|
nativeToken: _ChainAsset;
|
|
@@ -19,4 +20,4 @@ export interface CalculateMaxTransferable extends TransactionFee {
|
|
|
19
20
|
export declare const detectTransferTxType: (srcToken: _ChainAsset, srcChain: _ChainInfo, destChain: _ChainInfo) => FeeChainType;
|
|
20
21
|
export declare const calculateMaxTransferable: (id: string, request: CalculateMaxTransferable, freeBalance: AmountData, fee: FeeInfo) => Promise<ResponseSubscribeTransfer>;
|
|
21
22
|
export declare const calculateTransferMaxTransferable: (id: string, request: CalculateMaxTransferable, freeBalance: AmountData, fee: FeeInfo) => Promise<ResponseSubscribeTransfer>;
|
|
22
|
-
export declare const
|
|
23
|
+
export declare const calculateXcmMaxTransferable: (id: string, request: CalculateMaxTransferable, freeBalance: AmountData, fee: FeeInfo) => Promise<ResponseSubscribeTransfer>;
|
package/utils/fee/transfer.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { XCM_FEE_RATIO } from '@subwallet/extension-base/constants';
|
|
4
|
+
import { _SUPPORT_TOKEN_PAY_FEE_GROUP, XCM_FEE_RATIO } from '@subwallet/extension-base/constants';
|
|
5
5
|
import { _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
6
|
+
import { DEFAULT_CARDANO_TTL_OFFSET } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/consts';
|
|
7
|
+
import { createCardanoTransaction } from '@subwallet/extension-base/services/balance-service/transfer/cardano-transfer';
|
|
6
8
|
import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
|
|
7
|
-
import {
|
|
9
|
+
import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
8
10
|
import { createTonTransaction } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
9
11
|
import { createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic, createXcmExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
10
12
|
import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
11
13
|
import { _isPolygonChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
12
14
|
import { _isPosChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
|
|
13
|
-
import { _getContractAddressOfToken, _isChainEvmCompatible, _isChainTonCompatible, _isLocalToken, _isNativeToken, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
|
|
15
|
+
import { _getContractAddressOfToken, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainTonCompatible, _isLocalToken, _isNativeToken, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByCardano, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
16
|
import { calculateToAmountByReservePool, FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE } from '@subwallet/extension-base/services/fee-service/utils';
|
|
15
|
-
import {
|
|
17
|
+
import { getHydrationRate } from '@subwallet/extension-base/services/fee-service/utils/tokenPayFee';
|
|
18
|
+
import { isCardanoTransaction, isTonTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
16
19
|
import { BN_ZERO } from '@subwallet/extension-base/utils';
|
|
17
|
-
import { isTonAddress } from '@subwallet/keyring';
|
|
20
|
+
import { isCardanoAddress, isTonAddress } from '@subwallet/keyring';
|
|
18
21
|
import BigN from 'bignumber.js';
|
|
19
22
|
import { u8aToHex } from '@polkadot/util';
|
|
20
23
|
import { addressToEvm, isEthereumAddress } from '@polkadot/util-crypto';
|
|
@@ -32,6 +35,8 @@ export const detectTransferTxType = (srcToken, srcChain, destChain) => {
|
|
|
32
35
|
return 'evm';
|
|
33
36
|
} else if (_isChainTonCompatible(srcChain) && _isTokenTransferredByTon(srcToken)) {
|
|
34
37
|
return 'ton';
|
|
38
|
+
} else if (_isChainCardanoCompatible(srcChain) && _isTokenTransferredByCardano(srcToken)) {
|
|
39
|
+
return 'cardano';
|
|
35
40
|
} else {
|
|
36
41
|
return 'substrate';
|
|
37
42
|
}
|
|
@@ -45,7 +50,13 @@ export const calculateMaxTransferable = async (id, request, freeBalance, fee) =>
|
|
|
45
50
|
const isXcmTransfer = srcChain.slug !== destChain.slug;
|
|
46
51
|
let maxTransferableAmount;
|
|
47
52
|
if (isXcmTransfer) {
|
|
48
|
-
|
|
53
|
+
const _request = {
|
|
54
|
+
// todo: temp not support pay local fee with xcm
|
|
55
|
+
...request,
|
|
56
|
+
isTransferLocalTokenAndPayThatTokenAsFee: false,
|
|
57
|
+
isTransferNativeTokenAndPayLocalTokenAsFee: false
|
|
58
|
+
};
|
|
59
|
+
maxTransferableAmount = await calculateXcmMaxTransferable(id, _request, freeBalance, fee);
|
|
49
60
|
} else {
|
|
50
61
|
maxTransferableAmount = await calculateTransferMaxTransferable(id, request, freeBalance, fee);
|
|
51
62
|
}
|
|
@@ -55,6 +66,7 @@ export const calculateMaxTransferable = async (id, request, freeBalance, fee) =>
|
|
|
55
66
|
export const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
56
67
|
const {
|
|
57
68
|
address,
|
|
69
|
+
cardanoApi,
|
|
58
70
|
destChain,
|
|
59
71
|
evmApi,
|
|
60
72
|
feeCustom,
|
|
@@ -83,7 +95,7 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
83
95
|
// todo: refactor: merge getERC20TransactionObject & getEVMTransactionObject
|
|
84
96
|
// Estimate with EVM API
|
|
85
97
|
if (_isTokenEvmSmartContract(srcToken) || _isLocalToken(srcToken)) {
|
|
86
|
-
[transaction] = await getERC20TransactionObject({
|
|
98
|
+
[transaction,, error] = await getERC20TransactionObject({
|
|
87
99
|
assetAddress: _getContractAddressOfToken(srcToken),
|
|
88
100
|
chain: srcChain.slug,
|
|
89
101
|
evmApi,
|
|
@@ -93,10 +105,11 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
93
105
|
from: address,
|
|
94
106
|
to: recipient,
|
|
95
107
|
transferAll: false,
|
|
96
|
-
value: '0'
|
|
108
|
+
value: '0',
|
|
109
|
+
fallbackFee: true
|
|
97
110
|
});
|
|
98
111
|
} else {
|
|
99
|
-
[transaction] = await getEVMTransactionObject({
|
|
112
|
+
[transaction,, error] = await getEVMTransactionObject({
|
|
100
113
|
chain: srcChain.slug,
|
|
101
114
|
evmApi,
|
|
102
115
|
feeCustom,
|
|
@@ -105,7 +118,8 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
105
118
|
from: address,
|
|
106
119
|
to: recipient,
|
|
107
120
|
transferAll: false,
|
|
108
|
-
value: '0'
|
|
121
|
+
value: '0',
|
|
122
|
+
fallbackFee: true
|
|
109
123
|
});
|
|
110
124
|
}
|
|
111
125
|
} else if (isTonAddress(address) && _isTokenTransferredByTon(srcToken)) {
|
|
@@ -119,8 +133,21 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
119
133
|
// currently not used
|
|
120
134
|
tonApi
|
|
121
135
|
});
|
|
136
|
+
} else if (isCardanoAddress(address) && _isTokenTransferredByCardano(srcToken)) {
|
|
137
|
+
const isTransferNativeToken = _isNativeToken(srcToken);
|
|
138
|
+
[transaction] = await createCardanoTransaction({
|
|
139
|
+
tokenInfo: srcToken,
|
|
140
|
+
from: address,
|
|
141
|
+
to: address,
|
|
142
|
+
networkKey: srcChain.slug,
|
|
143
|
+
value: isTransferNativeToken ? '1000000' : '1',
|
|
144
|
+
cardanoTtlOffset: DEFAULT_CARDANO_TTL_OFFSET,
|
|
145
|
+
transferAll: false,
|
|
146
|
+
cardanoApi,
|
|
147
|
+
nativeTokenInfo: nativeToken
|
|
148
|
+
});
|
|
122
149
|
} else {
|
|
123
|
-
[transaction] = await
|
|
150
|
+
[transaction] = await createSubstrateExtrinsic({
|
|
124
151
|
transferAll: false,
|
|
125
152
|
value: '0',
|
|
126
153
|
from: address,
|
|
@@ -165,12 +192,27 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
165
192
|
estimatedFee
|
|
166
193
|
};
|
|
167
194
|
} else {
|
|
168
|
-
if (transaction
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
195
|
+
if (transaction) {
|
|
196
|
+
if (isTonTransaction(transaction)) {
|
|
197
|
+
estimatedFee = transaction.estimateFee;
|
|
198
|
+
feeOptions = {
|
|
199
|
+
...fee,
|
|
200
|
+
estimatedFee: estimatedFee
|
|
201
|
+
};
|
|
202
|
+
} else if (isCardanoTransaction(transaction)) {
|
|
203
|
+
estimatedFee = transaction.estimateCardanoFee;
|
|
204
|
+
feeOptions = {
|
|
205
|
+
...fee,
|
|
206
|
+
estimatedFee: estimatedFee
|
|
207
|
+
};
|
|
208
|
+
} else {
|
|
209
|
+
// Not implemented yet
|
|
210
|
+
estimatedFee = '0';
|
|
211
|
+
feeOptions = {
|
|
212
|
+
...fee,
|
|
213
|
+
estimatedFee: '0'
|
|
214
|
+
};
|
|
215
|
+
}
|
|
174
216
|
} else {
|
|
175
217
|
// Not implemented yet
|
|
176
218
|
estimatedFee = '0';
|
|
@@ -198,9 +240,21 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
198
240
|
console.warn('Unable to estimate fee', e);
|
|
199
241
|
}
|
|
200
242
|
if (isTransferLocalTokenAndPayThatTokenAsFee && feeChainType === 'substrate') {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
243
|
+
if (_SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
244
|
+
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
245
|
+
const estimatedFeeLocal = await calculateToAmountByReservePool(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
246
|
+
maxTransferable = BigN(freeBalance.value).minus(estimatedFeeLocal);
|
|
247
|
+
} else if (_SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
248
|
+
const rate = await getHydrationRate(address, nativeToken, srcToken);
|
|
249
|
+
if (rate) {
|
|
250
|
+
const estimatedFeeLocal = new BigN(estimatedFee).multipliedBy(rate).integerValue(BigN.ROUND_UP).toString();
|
|
251
|
+
maxTransferable = BigN(freeBalance.value).minus(estimatedFeeLocal);
|
|
252
|
+
} else {
|
|
253
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
257
|
+
}
|
|
204
258
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
205
259
|
maxTransferable = BigN(freeBalance.value);
|
|
206
260
|
} else {
|
|
@@ -218,7 +272,7 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
218
272
|
error
|
|
219
273
|
};
|
|
220
274
|
};
|
|
221
|
-
export const
|
|
275
|
+
export const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
222
276
|
const {
|
|
223
277
|
address,
|
|
224
278
|
destChain,
|
|
@@ -341,9 +395,21 @@ export const calculateXCMMaxTransferable = async (id, request, freeBalance, fee)
|
|
|
341
395
|
if (!destToken) {
|
|
342
396
|
maxTransferable = BN_ZERO;
|
|
343
397
|
} else if (isTransferLocalTokenAndPayThatTokenAsFee && feeChainType === 'substrate') {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
398
|
+
if (_SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
399
|
+
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
400
|
+
const estimatedFeeLocal = await calculateToAmountByReservePool(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
401
|
+
maxTransferable = BigN(freeBalance.value).minus(estimatedFeeLocal);
|
|
402
|
+
} else if (_SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
403
|
+
const rate = await getHydrationRate(address, nativeToken, srcToken);
|
|
404
|
+
if (rate) {
|
|
405
|
+
const estimatedFeeLocal = new BigN(estimatedFee).multipliedBy(rate).integerValue(BigN.ROUND_UP).toString();
|
|
406
|
+
maxTransferable = BigN(freeBalance.value).minus(estimatedFeeLocal);
|
|
407
|
+
} else {
|
|
408
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
409
|
+
}
|
|
410
|
+
} else {
|
|
411
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
412
|
+
}
|
|
347
413
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
348
414
|
maxTransferable = BigN(freeBalance.value);
|
|
349
415
|
} else {
|
package/utils/index.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
import { CrowdloanParaState } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { getRandomIpfsGateway, SUBWALLET_IPFS } from '@subwallet/extension-base/koni/api/nft/config';
|
|
6
|
-
import { _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import { _isChainCardanoCompatible, _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
7
|
import { reformatAddress } from '@subwallet/extension-base/utils/account';
|
|
8
|
-
import { decodeAddress, encodeAddress, isTonAddress } from '@subwallet/keyring';
|
|
8
|
+
import { decodeAddress, encodeAddress, isCardanoAddress, isTonAddress } from '@subwallet/keyring';
|
|
9
9
|
import { t } from 'i18next';
|
|
10
10
|
import { assert, BN, hexToU8a, isHex } from '@polkadot/util';
|
|
11
11
|
import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
|
|
@@ -254,8 +254,8 @@ export function isAddressAndChainCompatible(address, chain) {
|
|
|
254
254
|
const isEvmCompatible = isEthereumAddress(address) && _isChainEvmCompatible(chain);
|
|
255
255
|
const isTonCompatible = isTonAddress(address) && _isChainTonCompatible(chain);
|
|
256
256
|
const isSubstrateCompatible = !isEthereumAddress(address) && !isTonAddress(address) && _isChainSubstrateCompatible(chain); // todo: need isSubstrateAddress util function to check exactly
|
|
257
|
-
|
|
258
|
-
return isEvmCompatible || isSubstrateCompatible || isTonCompatible;
|
|
257
|
+
const isCardanoCompatible = isCardanoAddress(address) && _isChainCardanoCompatible(chain);
|
|
258
|
+
return isEvmCompatible || isSubstrateCompatible || isTonCompatible || isCardanoCompatible;
|
|
259
259
|
}
|
|
260
260
|
export function getDomainFromUrl(url) {
|
|
261
261
|
return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
|
|
@@ -9,6 +9,7 @@ export declare const currencySymbol: Record<string, unknown>;
|
|
|
9
9
|
export declare const blockedActionsFeatures: BlockedActionsFeaturesMap;
|
|
10
10
|
export declare const remindNotificationTime: Record<NotificationActionType, number>;
|
|
11
11
|
export declare const blockedActions: Record<string, EnvConfig>;
|
|
12
|
+
export declare const oldChainPrefix: Record<string, EnvConfig>;
|
|
12
13
|
export declare enum StaticKey {
|
|
13
14
|
BUY_SERVICE_INFOS = "buy-service-infos",
|
|
14
15
|
CHAINS = "chains",
|
|
@@ -19,7 +20,8 @@ export declare enum StaticKey {
|
|
|
19
20
|
BUY_TOKEN_CONFIGS = "buy-token-configs",
|
|
20
21
|
BLOCKED_ACTIONS_FEATURES = "blocked-actions-features",
|
|
21
22
|
REMIND_NOTIFICATION_TIME = "remind-notification-time",
|
|
22
|
-
BLOCKED_ACTIONS = "blocked-actions"
|
|
23
|
+
BLOCKED_ACTIONS = "blocked-actions",
|
|
24
|
+
OLD_CHAIN_PREFIX = "old-chain-prefix"
|
|
23
25
|
}
|
|
24
26
|
export declare const staticData: {
|
|
25
27
|
chains: import("@subwallet/chain-list/types")._ChainInfo[];
|
|
@@ -32,4 +34,5 @@ export declare const staticData: {
|
|
|
32
34
|
"blocked-actions-features": BlockedActionsFeaturesMap;
|
|
33
35
|
"remind-notification-time": Record<NotificationActionType, number>;
|
|
34
36
|
"blocked-actions": Record<string, EnvConfig>;
|
|
37
|
+
"old-chain-prefix": Record<string, EnvConfig>;
|
|
35
38
|
};
|
|
@@ -21,6 +21,8 @@ export const blockedActionsFeatures = require("./blockedActionsFeatures.json");
|
|
|
21
21
|
export const remindNotificationTime = require("./remindNotificationTime.json");
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
23
23
|
export const blockedActions = require("./blockedActions.json");
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
25
|
+
export const oldChainPrefix = require("./oldChainPrefix.json");
|
|
24
26
|
export let StaticKey;
|
|
25
27
|
(function (StaticKey) {
|
|
26
28
|
StaticKey["BUY_SERVICE_INFOS"] = "buy-service-infos";
|
|
@@ -33,6 +35,7 @@ export let StaticKey;
|
|
|
33
35
|
StaticKey["BLOCKED_ACTIONS_FEATURES"] = "blocked-actions-features";
|
|
34
36
|
StaticKey["REMIND_NOTIFICATION_TIME"] = "remind-notification-time";
|
|
35
37
|
StaticKey["BLOCKED_ACTIONS"] = "blocked-actions";
|
|
38
|
+
StaticKey["OLD_CHAIN_PREFIX"] = "old-chain-prefix";
|
|
36
39
|
})(StaticKey || (StaticKey = {}));
|
|
37
40
|
export const staticData = {
|
|
38
41
|
[StaticKey.CHAINS]: Object.values(ChainInfoMap),
|
|
@@ -44,5 +47,6 @@ export const staticData = {
|
|
|
44
47
|
[StaticKey.BUY_TOKEN_CONFIGS]: buyTokenConfigs,
|
|
45
48
|
[StaticKey.BLOCKED_ACTIONS_FEATURES]: blockedActionsFeatures,
|
|
46
49
|
[StaticKey.REMIND_NOTIFICATION_TIME]: remindNotificationTime,
|
|
47
|
-
[StaticKey.BLOCKED_ACTIONS]: blockedActions
|
|
50
|
+
[StaticKey.BLOCKED_ACTIONS]: blockedActions,
|
|
51
|
+
[StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix
|
|
48
52
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|