@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
|
@@ -24,12 +24,16 @@ const parseUnifiedSuriToDerivationPath = (suri, type) => {
|
|
|
24
24
|
return `m/44'/60'/0'/0/${first}/${secondIndex}`;
|
|
25
25
|
} else if (type === 'ton') {
|
|
26
26
|
return `m/44'/607'/${first}'/${secondIndex}'`;
|
|
27
|
+
} else if (type === 'cardano') {
|
|
28
|
+
return `m/1852'/1815'/${first}'/${secondIndex}'`;
|
|
27
29
|
}
|
|
28
30
|
} else {
|
|
29
31
|
if (type === 'ethereum') {
|
|
30
32
|
return `m/44'/60'/0'/0/${first}`;
|
|
31
33
|
} else if (type === 'ton') {
|
|
32
34
|
return `m/44'/607'/${first}'`;
|
|
35
|
+
} else if (type === 'cardano') {
|
|
36
|
+
return `m/1852'/1815'/${first}'`;
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
if (_types.SubstrateKeypairTypes.includes(type)) {
|
|
@@ -48,7 +52,7 @@ const getSoloDerivationInfo = function (type) {
|
|
|
48
52
|
} = metadata;
|
|
49
53
|
if (suri) {
|
|
50
54
|
if (derivePath) {
|
|
51
|
-
const validateTypeFunc = type === 'ethereum' ? _validate.validateEvmDerivationPath : type === 'ton' ? _validate.validateTonDerivationPath : () => undefined;
|
|
55
|
+
const validateTypeFunc = type === 'ethereum' ? _validate.validateEvmDerivationPath : type === 'ton' ? _validate.validateTonDerivationPath : type === 'cardano' ? _validate.validateCardanoDerivationPath : () => undefined;
|
|
52
56
|
const validateTypeRs = validateTypeFunc(derivePath);
|
|
53
57
|
if (validateTypeRs) {
|
|
54
58
|
return {
|
|
@@ -105,7 +109,7 @@ const getSoloDerivationInfo = function (type) {
|
|
|
105
109
|
}
|
|
106
110
|
} else {
|
|
107
111
|
if (derivePath) {
|
|
108
|
-
const validateTypeFunc = type === 'ethereum' ? _validate.validateEvmDerivationPath : type === 'ton' ? _validate.validateTonDerivationPath : () => undefined;
|
|
112
|
+
const validateTypeFunc = type === 'ethereum' ? _validate.validateEvmDerivationPath : type === 'ton' ? _validate.validateTonDerivationPath : type === 'cardano' ? _validate.validateCardanoDerivationPath : () => undefined;
|
|
109
113
|
const validateTypeRs = validateTypeFunc(derivePath);
|
|
110
114
|
if (validateTypeRs) {
|
|
111
115
|
return {
|
|
@@ -224,6 +228,7 @@ const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
|
224
228
|
}
|
|
225
229
|
const isEvm = _types.EthereumKeypairTypes.includes(parentPair.type);
|
|
226
230
|
const isTon = parentPair.type === 'ton';
|
|
231
|
+
const isCardano = parentPair.type === 'cardano';
|
|
227
232
|
const meta = {
|
|
228
233
|
name,
|
|
229
234
|
parentAddress: parentPair.address,
|
|
@@ -234,8 +239,8 @@ const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
|
234
239
|
if (isTon && (_parentPair$ton = parentPair.ton) !== null && _parentPair$ton !== void 0 && _parentPair$ton.contractVersion) {
|
|
235
240
|
meta.tonContractVersion = parentPair.ton.contractVersion;
|
|
236
241
|
}
|
|
237
|
-
if (derivationPath && (isEvm || isTon)) {
|
|
238
|
-
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : parentPair.ton.deriveCustom(derivationPath, meta);
|
|
242
|
+
if (derivationPath && (isEvm || isTon || isCardano)) {
|
|
243
|
+
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : isTon ? parentPair.ton.deriveCustom(derivationPath, meta) : parentPair.cardano.deriveCustom(derivationPath, meta);
|
|
239
244
|
} else {
|
|
240
245
|
return parentPair.substrate.derive(suri, meta);
|
|
241
246
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.validateUnifiedDerivationPath = exports.validateTonDerivationPath = exports.validateSr25519DerivationPath = exports.validateOtherSubstrateDerivationPath = exports.validateEvmDerivationPath = exports.validateDerivationPath = void 0;
|
|
6
|
+
exports.validateUnifiedDerivationPath = exports.validateTonDerivationPath = exports.validateSr25519DerivationPath = exports.validateOtherSubstrateDerivationPath = exports.validateEvmDerivationPath = exports.validateDerivationPath = exports.validateCardanoDerivationPath = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
|
|
@@ -105,6 +105,38 @@ const validateTonDerivationPath = raw => {
|
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
exports.validateTonDerivationPath = validateTonDerivationPath;
|
|
108
|
+
const validateCardanoDerivationPath = raw => {
|
|
109
|
+
const reg = /^m\/1852'\/1815'\/(\d+)'(\/\d+')?$/;
|
|
110
|
+
if (raw.match(reg)) {
|
|
111
|
+
const [, firstIndex, secondData] = raw.match(reg);
|
|
112
|
+
const first = parseInt(firstIndex, 10);
|
|
113
|
+
const autoIndexes = [first];
|
|
114
|
+
let depth;
|
|
115
|
+
let suri = `//${first}`;
|
|
116
|
+
if (first === 0) {
|
|
117
|
+
depth = 0;
|
|
118
|
+
} else {
|
|
119
|
+
depth = 1;
|
|
120
|
+
}
|
|
121
|
+
if (secondData) {
|
|
122
|
+
const [, secondIndex] = secondData.match(/\/(\d+)/);
|
|
123
|
+
const second = parseInt(secondIndex, 10);
|
|
124
|
+
autoIndexes.push(second);
|
|
125
|
+
depth = 2;
|
|
126
|
+
suri += `//${second}`;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
depth,
|
|
130
|
+
type: 'cardano',
|
|
131
|
+
suri,
|
|
132
|
+
derivationPath: raw,
|
|
133
|
+
autoIndexes
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
exports.validateCardanoDerivationPath = validateCardanoDerivationPath;
|
|
108
140
|
const validateSr25519DerivationPath = raw => {
|
|
109
141
|
const reg = /\/(\/?)([^/]+)/g;
|
|
110
142
|
const parts = raw.match(reg);
|
|
@@ -167,11 +199,13 @@ const validateDerivationPath = (raw, type) => {
|
|
|
167
199
|
return validateSr25519DerivationPath(raw);
|
|
168
200
|
} else if (type === 'ed25519' || type === 'ecdsa') {
|
|
169
201
|
return validateOtherSubstrateDerivationPath(raw, type);
|
|
202
|
+
} else if (type === 'cardano') {
|
|
203
|
+
return validateCardanoDerivationPath(raw);
|
|
170
204
|
} else {
|
|
171
205
|
return undefined;
|
|
172
206
|
}
|
|
173
207
|
} else {
|
|
174
|
-
return validateUnifiedDerivationPath(raw) || validateEvmDerivationPath(raw) || validateTonDerivationPath(raw) || validateSr25519DerivationPath(raw);
|
|
208
|
+
return validateUnifiedDerivationPath(raw) || validateEvmDerivationPath(raw) || validateTonDerivationPath(raw) || validateSr25519DerivationPath(raw) || validateCardanoDerivationPath(raw);
|
|
175
209
|
}
|
|
176
210
|
};
|
|
177
211
|
exports.validateDerivationPath = validateDerivationPath;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.transformAddresses = exports.transformAddress = exports.transformAccounts = exports.transformAccount = exports.singleAddressToAccount = exports.pairToAccount = exports.getAccountTransactionActions = exports.getAccountTokenTypes = exports.getAccountSignMode = exports.
|
|
6
|
+
exports.transformAddresses = exports.transformAddress = exports.transformAccounts = exports.transformAccount = exports.singleAddressToAccount = exports.pairToAccount = exports.getDefaultKeypairTypeFromAccountChainType = exports.getAccountTransactionActions = exports.getAccountTokenTypes = exports.getAccountSignMode = exports.getAccountChainTypeFromKeypairType = exports.getAccountActions = exports.createAccountProxyId = exports.convertAccountProxyType = exports.combineAllAccountProxy = exports.combineAccountsWithSubjectInfo = exports.combineAccountsWithKeyPair = exports._combineAccounts = void 0;
|
|
7
7
|
var _types = require("@subwallet/chain-list/types");
|
|
8
8
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
9
|
var _constants = require("@subwallet/extension-base/constants");
|
|
@@ -39,10 +39,24 @@ const createAccountProxyId = (_suri, derivationPath) => {
|
|
|
39
39
|
return (0, _utilCrypto.blake2AsHex)(data, 256);
|
|
40
40
|
};
|
|
41
41
|
exports.createAccountProxyId = createAccountProxyId;
|
|
42
|
-
const
|
|
43
|
-
return type ? _types3.EthereumKeypairTypes.includes(type) ? _types2.AccountChainType.ETHEREUM : _types3.TonKeypairTypes.includes(type) ? _types2.AccountChainType.TON : _types3.BitcoinKeypairTypes.includes(type) ? _types2.AccountChainType.BITCOIN : _types2.AccountChainType.SUBSTRATE : _types2.AccountChainType.SUBSTRATE;
|
|
42
|
+
const getAccountChainTypeFromKeypairType = type => {
|
|
43
|
+
return type ? _types3.EthereumKeypairTypes.includes(type) ? _types2.AccountChainType.ETHEREUM : _types3.TonKeypairTypes.includes(type) ? _types2.AccountChainType.TON : _types3.BitcoinKeypairTypes.includes(type) ? _types2.AccountChainType.BITCOIN : _types3.CardanoKeypairTypes.includes(type) ? _types2.AccountChainType.CARDANO : _types2.AccountChainType.SUBSTRATE : _types2.AccountChainType.SUBSTRATE;
|
|
44
44
|
};
|
|
45
|
-
exports.
|
|
45
|
+
exports.getAccountChainTypeFromKeypairType = getAccountChainTypeFromKeypairType;
|
|
46
|
+
const getDefaultKeypairTypeFromAccountChainType = type => {
|
|
47
|
+
if (type === _types2.AccountChainType.ETHEREUM) {
|
|
48
|
+
return 'ethereum';
|
|
49
|
+
} else if (type === _types2.AccountChainType.TON) {
|
|
50
|
+
return 'ton';
|
|
51
|
+
} else if (type === _types2.AccountChainType.BITCOIN) {
|
|
52
|
+
return 'bitcoin-84';
|
|
53
|
+
} else if (type === _types2.AccountChainType.CARDANO) {
|
|
54
|
+
return 'cardano';
|
|
55
|
+
} else {
|
|
56
|
+
return 'sr25519';
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.getDefaultKeypairTypeFromAccountChainType = getDefaultKeypairTypeFromAccountChainType;
|
|
46
60
|
const getAccountSignMode = (address, _meta) => {
|
|
47
61
|
const meta = _meta;
|
|
48
62
|
if (!address || !meta) {
|
|
@@ -77,6 +91,7 @@ const getAccountActions = (signMode, networkType, type, _meta, parentAccount) =>
|
|
|
77
91
|
const result = [];
|
|
78
92
|
const meta = _meta;
|
|
79
93
|
|
|
94
|
+
// todo: check this function for Cardano
|
|
80
95
|
// JSON
|
|
81
96
|
if (signMode === _types2.AccountSignMode.PASSWORD) {
|
|
82
97
|
result.push(_types2.AccountActions.EXPORT_JSON);
|
|
@@ -156,6 +171,8 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
|
|
|
156
171
|
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...OTHER_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...EVM_ACTIONS];
|
|
157
172
|
case _types2.AccountChainType.TON:
|
|
158
173
|
return [...BASE_TRANSFER_ACTIONS];
|
|
174
|
+
case _types2.AccountChainType.CARDANO:
|
|
175
|
+
return [...BASE_TRANSFER_ACTIONS];
|
|
159
176
|
}
|
|
160
177
|
} else if (signMode === _types2.AccountSignMode.QR) {
|
|
161
178
|
switch (networkType) {
|
|
@@ -165,6 +182,8 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
|
|
|
165
182
|
return [...(_constants.isProductionMode ? [] : [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OTHER_ACTIONS, ...EVM_ACTIONS])];
|
|
166
183
|
case _types2.AccountChainType.TON:
|
|
167
184
|
return [];
|
|
185
|
+
case _types2.AccountChainType.CARDANO:
|
|
186
|
+
return [];
|
|
168
187
|
}
|
|
169
188
|
} else if (signMode === _types2.AccountSignMode.GENERIC_LEDGER) {
|
|
170
189
|
switch (networkType) {
|
|
@@ -180,6 +199,8 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
|
|
|
180
199
|
_KoniTypes.ExtrinsicType.SEND_NFT, _KoniTypes.ExtrinsicType.SWAP];
|
|
181
200
|
case _types2.AccountChainType.TON:
|
|
182
201
|
return [...BASE_TRANSFER_ACTIONS];
|
|
202
|
+
case _types2.AccountChainType.CARDANO:
|
|
203
|
+
return [];
|
|
183
204
|
}
|
|
184
205
|
} else if (signMode === _types2.AccountSignMode.LEGACY_LEDGER) {
|
|
185
206
|
// Only for Substrate
|
|
@@ -240,6 +261,8 @@ const getAccountTokenTypes = type => {
|
|
|
240
261
|
case 'bitcoin-86':
|
|
241
262
|
case 'bittest-86':
|
|
242
263
|
return [_types._AssetType.NATIVE, _types._AssetType.RUNE, _types._AssetType.BRC20];
|
|
264
|
+
case 'cardano':
|
|
265
|
+
return [_types._AssetType.NATIVE, _types._AssetType.CIP26];
|
|
243
266
|
default:
|
|
244
267
|
return [];
|
|
245
268
|
}
|
|
@@ -265,7 +288,7 @@ exports.getAccountTokenTypes = getAccountTokenTypes;
|
|
|
265
288
|
const transformAccount = (address, _type, meta, chainInfoMap, parentAccount) => {
|
|
266
289
|
const signMode = getAccountSignMode(address, meta);
|
|
267
290
|
const type = _type || (0, _keyring.getKeypairTypeByAddress)(address);
|
|
268
|
-
const chainType =
|
|
291
|
+
const chainType = getAccountChainTypeFromKeypairType(type);
|
|
269
292
|
let specialChain;
|
|
270
293
|
if (!chainInfoMap) {
|
|
271
294
|
return {
|
|
@@ -329,7 +352,7 @@ const transformAccounts = accounts => Object.values(accounts).map(data => single
|
|
|
329
352
|
exports.transformAccounts = transformAccounts;
|
|
330
353
|
const transformAddress = (address, meta) => {
|
|
331
354
|
const type = (0, _keyring.getKeypairTypeByAddress)(address);
|
|
332
|
-
const chainType =
|
|
355
|
+
const chainType = getAccountChainTypeFromKeypairType(type);
|
|
333
356
|
return {
|
|
334
357
|
address,
|
|
335
358
|
...meta,
|
|
@@ -411,6 +434,7 @@ const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
|
411
434
|
let tokenTypes = [];
|
|
412
435
|
let accountActions = [];
|
|
413
436
|
let specialChain;
|
|
437
|
+
let isNeedMigrateUnifiedAccount;
|
|
414
438
|
if (value.accounts.length > 1) {
|
|
415
439
|
accountType = _types2.AccountProxyType.UNIFIED;
|
|
416
440
|
chainTypes = Array.from(value.accounts.reduce((rs, account) => rs.add(account.chainType), new Set()));
|
|
@@ -420,6 +444,9 @@ const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
|
420
444
|
}
|
|
421
445
|
return rs;
|
|
422
446
|
}, new Set()));
|
|
447
|
+
if (chainTypes.length < _types2.SUPPORTED_ACCOUNT_CHAIN_TYPES.length) {
|
|
448
|
+
isNeedMigrateUnifiedAccount = true;
|
|
449
|
+
}
|
|
423
450
|
|
|
424
451
|
/* Account actions */
|
|
425
452
|
|
|
@@ -451,6 +478,9 @@ const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
|
451
478
|
if (account.chainType === _types2.AccountChainType.TON) {
|
|
452
479
|
accountActions = accountActions.filter(action => action !== _types2.AccountActions.DERIVE);
|
|
453
480
|
}
|
|
481
|
+
if (chainTypes.length === 1 && accountActions.includes(_types2.AccountActions.EXPORT_MNEMONIC) && account.isMasterAccount && account.type !== 'ton-native') {
|
|
482
|
+
isNeedMigrateUnifiedAccount = true;
|
|
483
|
+
}
|
|
454
484
|
switch (account.signMode) {
|
|
455
485
|
case _types2.AccountSignMode.GENERIC_LEDGER:
|
|
456
486
|
case _types2.AccountSignMode.LEGACY_LEDGER:
|
|
@@ -464,7 +494,8 @@ const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
|
464
494
|
chainTypes,
|
|
465
495
|
specialChain,
|
|
466
496
|
tokenTypes,
|
|
467
|
-
accountActions
|
|
497
|
+
accountActions,
|
|
498
|
+
isNeedMigrateUnifiedAccount
|
|
468
499
|
}];
|
|
469
500
|
}));
|
|
470
501
|
const deepSearchParentId = parentId => {
|
|
@@ -543,15 +574,9 @@ const combineAllAccountProxy = accountProxies => {
|
|
|
543
574
|
const tokenTypes = new Set();
|
|
544
575
|
const specialChain = accountProxies.length === 1 ? accountProxies[0].specialChain : undefined;
|
|
545
576
|
for (const accountProxy of accountProxies) {
|
|
546
|
-
// Have 4 network types, but at the moment, we only support 3 network types
|
|
547
|
-
if (chainTypes.size === 3) {
|
|
548
|
-
break;
|
|
549
|
-
}
|
|
550
577
|
for (const chainType of accountProxy.chainTypes) {
|
|
551
578
|
chainTypes.add(chainType);
|
|
552
579
|
}
|
|
553
|
-
}
|
|
554
|
-
for (const accountProxy of accountProxies) {
|
|
555
580
|
for (const tokenType of accountProxy.tokenTypes) {
|
|
556
581
|
tokenTypes.add(tokenType);
|
|
557
582
|
}
|
|
@@ -4,9 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.detectTransferTxType = exports.
|
|
7
|
+
exports.detectTransferTxType = exports.calculateXcmMaxTransferable = exports.calculateTransferMaxTransferable = exports.calculateMaxTransferable = void 0;
|
|
8
8
|
var _constants = require("@subwallet/extension-base/constants");
|
|
9
9
|
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
10
|
+
var _consts = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/consts");
|
|
11
|
+
var _cardanoTransfer = require("@subwallet/extension-base/services/balance-service/transfer/cardano-transfer");
|
|
10
12
|
var _smartContract = require("@subwallet/extension-base/services/balance-service/transfer/smart-contract");
|
|
11
13
|
var _token = require("@subwallet/extension-base/services/balance-service/transfer/token");
|
|
12
14
|
var _tonTransfer = require("@subwallet/extension-base/services/balance-service/transfer/ton-transfer");
|
|
@@ -16,6 +18,7 @@ var _polygonBridge = require("@subwallet/extension-base/services/balance-service
|
|
|
16
18
|
var _posBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge");
|
|
17
19
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
18
20
|
var _utils2 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
21
|
+
var _tokenPayFee = require("@subwallet/extension-base/services/fee-service/utils/tokenPayFee");
|
|
19
22
|
var _helpers = require("@subwallet/extension-base/services/transaction-service/helpers");
|
|
20
23
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
21
24
|
var _keyring = require("@subwallet/keyring");
|
|
@@ -39,6 +42,8 @@ const detectTransferTxType = (srcToken, srcChain, destChain) => {
|
|
|
39
42
|
return 'evm';
|
|
40
43
|
} else if ((0, _utils._isChainTonCompatible)(srcChain) && (0, _utils._isTokenTransferredByTon)(srcToken)) {
|
|
41
44
|
return 'ton';
|
|
45
|
+
} else if ((0, _utils._isChainCardanoCompatible)(srcChain) && (0, _utils._isTokenTransferredByCardano)(srcToken)) {
|
|
46
|
+
return 'cardano';
|
|
42
47
|
} else {
|
|
43
48
|
return 'substrate';
|
|
44
49
|
}
|
|
@@ -53,7 +58,13 @@ const calculateMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
53
58
|
const isXcmTransfer = srcChain.slug !== destChain.slug;
|
|
54
59
|
let maxTransferableAmount;
|
|
55
60
|
if (isXcmTransfer) {
|
|
56
|
-
|
|
61
|
+
const _request = {
|
|
62
|
+
// todo: temp not support pay local fee with xcm
|
|
63
|
+
...request,
|
|
64
|
+
isTransferLocalTokenAndPayThatTokenAsFee: false,
|
|
65
|
+
isTransferNativeTokenAndPayLocalTokenAsFee: false
|
|
66
|
+
};
|
|
67
|
+
maxTransferableAmount = await calculateXcmMaxTransferable(id, _request, freeBalance, fee);
|
|
57
68
|
} else {
|
|
58
69
|
maxTransferableAmount = await calculateTransferMaxTransferable(id, request, freeBalance, fee);
|
|
59
70
|
}
|
|
@@ -64,6 +75,7 @@ exports.calculateMaxTransferable = calculateMaxTransferable;
|
|
|
64
75
|
const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
65
76
|
const {
|
|
66
77
|
address,
|
|
78
|
+
cardanoApi,
|
|
67
79
|
destChain,
|
|
68
80
|
evmApi,
|
|
69
81
|
feeCustom,
|
|
@@ -92,7 +104,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
92
104
|
// todo: refactor: merge getERC20TransactionObject & getEVMTransactionObject
|
|
93
105
|
// Estimate with EVM API
|
|
94
106
|
if ((0, _utils._isTokenEvmSmartContract)(srcToken) || (0, _utils._isLocalToken)(srcToken)) {
|
|
95
|
-
[transaction] = await (0, _smartContract.getERC20TransactionObject)({
|
|
107
|
+
[transaction,, error] = await (0, _smartContract.getERC20TransactionObject)({
|
|
96
108
|
assetAddress: (0, _utils._getContractAddressOfToken)(srcToken),
|
|
97
109
|
chain: srcChain.slug,
|
|
98
110
|
evmApi,
|
|
@@ -102,10 +114,11 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
102
114
|
from: address,
|
|
103
115
|
to: recipient,
|
|
104
116
|
transferAll: false,
|
|
105
|
-
value: '0'
|
|
117
|
+
value: '0',
|
|
118
|
+
fallbackFee: true
|
|
106
119
|
});
|
|
107
120
|
} else {
|
|
108
|
-
[transaction] = await (0, _smartContract.getEVMTransactionObject)({
|
|
121
|
+
[transaction,, error] = await (0, _smartContract.getEVMTransactionObject)({
|
|
109
122
|
chain: srcChain.slug,
|
|
110
123
|
evmApi,
|
|
111
124
|
feeCustom,
|
|
@@ -114,7 +127,8 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
114
127
|
from: address,
|
|
115
128
|
to: recipient,
|
|
116
129
|
transferAll: false,
|
|
117
|
-
value: '0'
|
|
130
|
+
value: '0',
|
|
131
|
+
fallbackFee: true
|
|
118
132
|
});
|
|
119
133
|
}
|
|
120
134
|
} else if ((0, _keyring.isTonAddress)(address) && (0, _utils._isTokenTransferredByTon)(srcToken)) {
|
|
@@ -128,8 +142,21 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
128
142
|
// currently not used
|
|
129
143
|
tonApi
|
|
130
144
|
});
|
|
145
|
+
} else if ((0, _keyring.isCardanoAddress)(address) && (0, _utils._isTokenTransferredByCardano)(srcToken)) {
|
|
146
|
+
const isTransferNativeToken = (0, _utils._isNativeToken)(srcToken);
|
|
147
|
+
[transaction] = await (0, _cardanoTransfer.createCardanoTransaction)({
|
|
148
|
+
tokenInfo: srcToken,
|
|
149
|
+
from: address,
|
|
150
|
+
to: address,
|
|
151
|
+
networkKey: srcChain.slug,
|
|
152
|
+
value: isTransferNativeToken ? '1000000' : '1',
|
|
153
|
+
cardanoTtlOffset: _consts.DEFAULT_CARDANO_TTL_OFFSET,
|
|
154
|
+
transferAll: false,
|
|
155
|
+
cardanoApi,
|
|
156
|
+
nativeTokenInfo: nativeToken
|
|
157
|
+
});
|
|
131
158
|
} else {
|
|
132
|
-
[transaction] = await (0, _token.
|
|
159
|
+
[transaction] = await (0, _token.createSubstrateExtrinsic)({
|
|
133
160
|
transferAll: false,
|
|
134
161
|
value: '0',
|
|
135
162
|
from: address,
|
|
@@ -174,12 +201,27 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
174
201
|
estimatedFee
|
|
175
202
|
};
|
|
176
203
|
} else {
|
|
177
|
-
if (transaction
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
204
|
+
if (transaction) {
|
|
205
|
+
if ((0, _helpers.isTonTransaction)(transaction)) {
|
|
206
|
+
estimatedFee = transaction.estimateFee;
|
|
207
|
+
feeOptions = {
|
|
208
|
+
...fee,
|
|
209
|
+
estimatedFee: estimatedFee
|
|
210
|
+
};
|
|
211
|
+
} else if ((0, _helpers.isCardanoTransaction)(transaction)) {
|
|
212
|
+
estimatedFee = transaction.estimateCardanoFee;
|
|
213
|
+
feeOptions = {
|
|
214
|
+
...fee,
|
|
215
|
+
estimatedFee: estimatedFee
|
|
216
|
+
};
|
|
217
|
+
} else {
|
|
218
|
+
// Not implemented yet
|
|
219
|
+
estimatedFee = '0';
|
|
220
|
+
feeOptions = {
|
|
221
|
+
...fee,
|
|
222
|
+
estimatedFee: '0'
|
|
223
|
+
};
|
|
224
|
+
}
|
|
183
225
|
} else {
|
|
184
226
|
// Not implemented yet
|
|
185
227
|
estimatedFee = '0';
|
|
@@ -207,9 +249,21 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
207
249
|
console.warn('Unable to estimate fee', e);
|
|
208
250
|
}
|
|
209
251
|
if (isTransferLocalTokenAndPayThatTokenAsFee && feeChainType === 'substrate') {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
252
|
+
if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
253
|
+
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(_utils2.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
254
|
+
const estimatedFeeLocal = await (0, _utils2.calculateToAmountByReservePool)(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
255
|
+
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
256
|
+
} else if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
257
|
+
const rate = await (0, _tokenPayFee.getHydrationRate)(address, nativeToken, srcToken);
|
|
258
|
+
if (rate) {
|
|
259
|
+
const estimatedFeeLocal = new _bignumber.default(estimatedFee).multipliedBy(rate).integerValue(_bignumber.default.ROUND_UP).toString();
|
|
260
|
+
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
261
|
+
} else {
|
|
262
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
266
|
+
}
|
|
213
267
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
214
268
|
maxTransferable = (0, _bignumber.default)(freeBalance.value);
|
|
215
269
|
} else {
|
|
@@ -228,7 +282,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
228
282
|
};
|
|
229
283
|
};
|
|
230
284
|
exports.calculateTransferMaxTransferable = calculateTransferMaxTransferable;
|
|
231
|
-
const
|
|
285
|
+
const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
232
286
|
const {
|
|
233
287
|
address,
|
|
234
288
|
destChain,
|
|
@@ -351,9 +405,21 @@ const calculateXCMMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
351
405
|
if (!destToken) {
|
|
352
406
|
maxTransferable = _utils3.BN_ZERO;
|
|
353
407
|
} else if (isTransferLocalTokenAndPayThatTokenAsFee && feeChainType === 'substrate') {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
408
|
+
if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
409
|
+
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(_utils2.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
410
|
+
const estimatedFeeLocal = await (0, _utils2.calculateToAmountByReservePool)(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
411
|
+
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
412
|
+
} else if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
413
|
+
const rate = await (0, _tokenPayFee.getHydrationRate)(address, nativeToken, srcToken);
|
|
414
|
+
if (rate) {
|
|
415
|
+
const estimatedFeeLocal = new _bignumber.default(estimatedFee).multipliedBy(rate).integerValue(_bignumber.default.ROUND_UP).toString();
|
|
416
|
+
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
417
|
+
} else {
|
|
418
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
419
|
+
}
|
|
420
|
+
} else {
|
|
421
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
422
|
+
}
|
|
357
423
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
358
424
|
maxTransferable = (0, _bignumber.default)(freeBalance.value);
|
|
359
425
|
} else {
|
|
@@ -371,4 +437,4 @@ const calculateXCMMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
371
437
|
error
|
|
372
438
|
};
|
|
373
439
|
};
|
|
374
|
-
exports.
|
|
440
|
+
exports.calculateXcmMaxTransferable = calculateXcmMaxTransferable;
|
package/cjs/utils/index.js
CHANGED
|
@@ -577,8 +577,8 @@ function isAddressAndChainCompatible(address, chain) {
|
|
|
577
577
|
const isEvmCompatible = (0, _utilCrypto.isEthereumAddress)(address) && (0, _utils._isChainEvmCompatible)(chain);
|
|
578
578
|
const isTonCompatible = (0, _keyring.isTonAddress)(address) && (0, _utils._isChainTonCompatible)(chain);
|
|
579
579
|
const isSubstrateCompatible = !(0, _utilCrypto.isEthereumAddress)(address) && !(0, _keyring.isTonAddress)(address) && (0, _utils._isChainSubstrateCompatible)(chain); // todo: need isSubstrateAddress util function to check exactly
|
|
580
|
-
|
|
581
|
-
return isEvmCompatible || isSubstrateCompatible || isTonCompatible;
|
|
580
|
+
const isCardanoCompatible = (0, _keyring.isCardanoAddress)(address) && (0, _utils._isChainCardanoCompatible)(chain);
|
|
581
|
+
return isEvmCompatible || isSubstrateCompatible || isTonCompatible || isCardanoCompatible;
|
|
582
582
|
}
|
|
583
583
|
function getDomainFromUrl(url) {
|
|
584
584
|
return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.termAndCondition = exports.staticData = exports.remindNotificationTime = exports.marketingCampaigns = exports.currencySymbol = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.blockedActionsFeatures = exports.blockedActions = exports.StaticKey = void 0;
|
|
6
|
+
exports.termAndCondition = exports.staticData = exports.remindNotificationTime = exports.oldChainPrefix = exports.marketingCampaigns = exports.currencySymbol = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.blockedActionsFeatures = exports.blockedActions = exports.StaticKey = void 0;
|
|
7
7
|
var _chainList = require("@subwallet/chain-list");
|
|
8
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
9
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -36,7 +36,10 @@ const remindNotificationTime = require('./remindNotificationTime.json');
|
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
37
37
|
exports.remindNotificationTime = remindNotificationTime;
|
|
38
38
|
const blockedActions = require('./blockedActions.json');
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
39
40
|
exports.blockedActions = blockedActions;
|
|
41
|
+
const oldChainPrefix = require('./oldChainPrefix.json');
|
|
42
|
+
exports.oldChainPrefix = oldChainPrefix;
|
|
40
43
|
let StaticKey;
|
|
41
44
|
exports.StaticKey = StaticKey;
|
|
42
45
|
(function (StaticKey) {
|
|
@@ -50,6 +53,7 @@ exports.StaticKey = StaticKey;
|
|
|
50
53
|
StaticKey["BLOCKED_ACTIONS_FEATURES"] = "blocked-actions-features";
|
|
51
54
|
StaticKey["REMIND_NOTIFICATION_TIME"] = "remind-notification-time";
|
|
52
55
|
StaticKey["BLOCKED_ACTIONS"] = "blocked-actions";
|
|
56
|
+
StaticKey["OLD_CHAIN_PREFIX"] = "old-chain-prefix";
|
|
53
57
|
})(StaticKey || (exports.StaticKey = StaticKey = {}));
|
|
54
58
|
const staticData = {
|
|
55
59
|
[StaticKey.CHAINS]: Object.values(_chainList.ChainInfoMap),
|
|
@@ -61,6 +65,7 @@ const staticData = {
|
|
|
61
65
|
[StaticKey.BUY_TOKEN_CONFIGS]: buyTokenConfigs,
|
|
62
66
|
[StaticKey.BLOCKED_ACTIONS_FEATURES]: blockedActionsFeatures,
|
|
63
67
|
[StaticKey.REMIND_NOTIFICATION_TIME]: remindNotificationTime,
|
|
64
|
-
[StaticKey.BLOCKED_ACTIONS]: blockedActions
|
|
68
|
+
[StaticKey.BLOCKED_ACTIONS]: blockedActions,
|
|
69
|
+
[StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix
|
|
65
70
|
};
|
|
66
71
|
exports.staticData = staticData;
|
package/constants/environment.js
CHANGED
|
@@ -3,4 +3,5 @@
|
|
|
3
3
|
|
|
4
4
|
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
5
5
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
6
|
-
export const isProductionMode = PRODUCTION_BRANCHES.indexOf(branchName) > -1;
|
|
6
|
+
export const isProductionMode = PRODUCTION_BRANCHES.indexOf(branchName) > -1;
|
|
7
|
+
export const BACKEND_API_URL = process.env.SUBWALLET_API || (isProductionMode ? 'https://sw-services.subwallet.app/api' : 'https://be-dev.subwallet.app/api');
|
package/constants/index.d.ts
CHANGED
|
@@ -35,7 +35,12 @@ export declare const NETWORK_MULTI_GAS_FEE: string[];
|
|
|
35
35
|
export declare const ORDINAL_COLLECTION = "__Ordinal__";
|
|
36
36
|
export declare const ORDINAL_METHODS: string[];
|
|
37
37
|
export declare const PERMISSIONS_TO_REVOKE: string[];
|
|
38
|
-
export declare const
|
|
38
|
+
export declare const _SUPPORT_TOKEN_PAY_FEE_GROUP: {
|
|
39
|
+
assetHub: string[];
|
|
40
|
+
hydration: string[];
|
|
41
|
+
};
|
|
42
|
+
export declare const getSupportTokenPayFeeChain: () => string[];
|
|
43
|
+
export declare const isChainSupportTokenPayFee: (chainSlug: string) => boolean;
|
|
39
44
|
export * from './blocked-actions';
|
|
40
45
|
export * from './environment';
|
|
41
46
|
export * from './signing';
|
package/constants/index.js
CHANGED
|
@@ -37,7 +37,20 @@ export const NETWORK_MULTI_GAS_FEE = ['*'];
|
|
|
37
37
|
export const ORDINAL_COLLECTION = '__Ordinal__';
|
|
38
38
|
export const ORDINAL_METHODS = ['drc-20', 'pol-20'];
|
|
39
39
|
export const PERMISSIONS_TO_REVOKE = ['eth_accounts'];
|
|
40
|
-
export const
|
|
40
|
+
export const _SUPPORT_TOKEN_PAY_FEE_GROUP = {
|
|
41
|
+
assetHub: ['paseo_assethub', 'westend_assethub', 'rococo_assethub', 'statemine', 'statemint'],
|
|
42
|
+
hydration: ['hydradx_main', 'hydradx_rococo']
|
|
43
|
+
};
|
|
44
|
+
export const getSupportTokenPayFeeChain = () => {
|
|
45
|
+
return Object.values(_SUPPORT_TOKEN_PAY_FEE_GROUP).flat();
|
|
46
|
+
};
|
|
47
|
+
export const isChainSupportTokenPayFee = chainSlug => {
|
|
48
|
+
if (!chainSlug) {
|
|
49
|
+
console.error('You must provide chain slug!');
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return getSupportTokenPayFeeChain().includes(chainSlug);
|
|
53
|
+
};
|
|
41
54
|
export * from "./blocked-actions.js";
|
|
42
55
|
export * from "./environment.js";
|
|
43
56
|
export * from "./signing.js";
|
package/constants/signing.js
CHANGED
|
@@ -6,10 +6,14 @@ import { AccountChainType } from '@subwallet/extension-base/types';
|
|
|
6
6
|
export const SIGNING_COMPATIBLE_MAP = {
|
|
7
7
|
[ChainType.SUBSTRATE]: [AccountChainType.SUBSTRATE, AccountChainType.ETHEREUM],
|
|
8
8
|
[ChainType.EVM]: [AccountChainType.ETHEREUM],
|
|
9
|
-
[ChainType.
|
|
9
|
+
[ChainType.BITCOIN]: [AccountChainType.BITCOIN],
|
|
10
|
+
[ChainType.TON]: [AccountChainType.TON],
|
|
11
|
+
[ChainType.CARDANO]: [AccountChainType.CARDANO]
|
|
10
12
|
};
|
|
11
13
|
export const LEDGER_SIGNING_COMPATIBLE_MAP = {
|
|
12
14
|
[ChainType.SUBSTRATE]: [AccountChainType.SUBSTRATE],
|
|
13
15
|
[ChainType.EVM]: [AccountChainType.ETHEREUM],
|
|
14
|
-
[ChainType.
|
|
16
|
+
[ChainType.BITCOIN]: [AccountChainType.BITCOIN],
|
|
17
|
+
[ChainType.TON]: [AccountChainType.TON],
|
|
18
|
+
[ChainType.CARDANO]: [AccountChainType.CARDANO]
|
|
15
19
|
};
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ActionType, ValidationCondition } from '@subwallet/extension-base/core/types';
|
|
5
|
-
import { _isAddress, _isNotDuplicateAddress, _isNotNull, _isSupportLedgerAccount, _isValidAddressForEcosystem, _isValidSubstrateAddressFormat, _isValidTonAddressFormat } from '@subwallet/extension-base/core/utils';
|
|
5
|
+
import { _isAddress, _isNotDuplicateAddress, _isNotNull, _isSupportLedgerAccount, _isValidAddressForEcosystem, _isValidCardanoAddressFormat, _isValidSubstrateAddressFormat, _isValidTonAddressFormat } from '@subwallet/extension-base/core/utils';
|
|
6
6
|
import { AccountSignMode } from '@subwallet/extension-base/types';
|
|
7
7
|
import { detectTranslate } from '@subwallet/extension-base/utils';
|
|
8
|
-
import { isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
8
|
+
import { isCardanoAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
9
9
|
function getConditions(validateRecipientParams) {
|
|
10
10
|
const {
|
|
11
11
|
account,
|
|
@@ -27,7 +27,10 @@ function getConditions(validateRecipientParams) {
|
|
|
27
27
|
if (isTonAddress(toAddress)) {
|
|
28
28
|
conditions.push(ValidationCondition.IS_VALID_TON_ADDRESS_FORMAT);
|
|
29
29
|
}
|
|
30
|
-
if (
|
|
30
|
+
if (isCardanoAddress(toAddress)) {
|
|
31
|
+
conditions.push(ValidationCondition.IS_VALID_CARDANO_ADDRESS_FORMAT);
|
|
32
|
+
}
|
|
33
|
+
if (srcChain === destChainInfo.slug && isSendAction && !destChainInfo.tonInfo && !destChainInfo.cardanoInfo) {
|
|
31
34
|
conditions.push(ValidationCondition.IS_NOT_DUPLICATE_ADDRESS);
|
|
32
35
|
}
|
|
33
36
|
if (account !== null && account !== void 0 && account.isHardware) {
|
|
@@ -67,6 +70,11 @@ function getValidationFunctions(conditions) {
|
|
|
67
70
|
validationFunctions.push(_isValidTonAddressFormat);
|
|
68
71
|
break;
|
|
69
72
|
}
|
|
73
|
+
case ValidationCondition.IS_VALID_CARDANO_ADDRESS_FORMAT:
|
|
74
|
+
{
|
|
75
|
+
validationFunctions.push(_isValidCardanoAddressFormat);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
70
78
|
case ValidationCondition.IS_NOT_DUPLICATE_ADDRESS:
|
|
71
79
|
{
|
|
72
80
|
validationFunctions.push(_isNotDuplicateAddress);
|
|
@@ -14,7 +14,7 @@ export declare function additionalValidateXcmTransfer(originTokenInfo: _ChainAss
|
|
|
14
14
|
export declare function checkSupportForFeature(validationResponse: SWTransactionResponse, blockedFeaturesList: string[], chainInfo: _ChainInfo): void;
|
|
15
15
|
export declare function checkSupportForAction(validationResponse: SWTransactionResponse, blockedActionsMap: Record<ExtrinsicType, string[]>): void;
|
|
16
16
|
export declare function checkSupportForTransaction(validationResponse: SWTransactionResponse, transaction: OptionalSWTransaction): void;
|
|
17
|
-
export declare function estimateFeeForTransaction(validationResponse: SWTransactionResponse, transaction: OptionalSWTransaction, chainInfo: _ChainInfo, evmApi: _EvmApi, substrateApi: _SubstrateApi, feeInfo: EvmFeeInfo, nativeTokenInfo: _ChainAsset,
|
|
17
|
+
export declare function estimateFeeForTransaction(validationResponse: SWTransactionResponse, transaction: OptionalSWTransaction, chainInfo: _ChainInfo, evmApi: _EvmApi, substrateApi: _SubstrateApi, priceMap: Record<string, number>, feeInfo: EvmFeeInfo, nativeTokenInfo: _ChainAsset, nonNativeTokenPayFeeInfo: _ChainAsset | undefined, isTransferLocalTokenAndPayThatTokenAsFee: boolean | undefined): Promise<FeeData>;
|
|
18
18
|
export declare function checkSigningAccountForTransaction(validationResponse: SWTransactionResponse, chainInfoMap: Record<string, _ChainInfo>): void;
|
|
19
19
|
export declare function checkBalanceWithTransactionFee(validationResponse: SWTransactionResponse, transactionInput: SWTransactionInput, nativeTokenInfo: _ChainAsset, nativeTokenAvailable: AmountData): void;
|
|
20
20
|
export declare function checkTonAddressBounceableAndAccountNotActive(tonApi: _TonApi, validationResponse: SWTransactionResponse): Promise<void>;
|