@subwallet/extension-base 1.1.53-beta.0 → 1.1.55-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 +12 -0
- package/background/types.d.ts +2 -0
- package/cjs/koni/background/handlers/Extension.js +129 -102
- package/cjs/koni/background/handlers/State.js +3 -20
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/index.js +5 -9
- package/cjs/services/chain-service/utils/index.js +8 -2
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
- package/cjs/services/migration-service/scripts/index.js +3 -3
- package/cjs/services/swap-service/handler/base-handler.js +20 -2
- package/cjs/services/swap-service/handler/hydradx-handler.js +106 -19
- package/cjs/services/swap-service/index.js +1 -0
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +26 -0
- package/koni/background/handlers/State.js +4 -21
- package/package.json +10 -10
- package/packageInfo.js +1 -1
- package/services/chain-service/index.d.ts +1 -1
- package/services/chain-service/index.js +6 -10
- package/services/chain-service/utils/index.d.ts +1 -0
- package/services/chain-service/utils/index.js +4 -0
- package/services/chain-service/utils/patch.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
- package/services/migration-service/scripts/index.js +3 -3
- package/services/swap-service/handler/base-handler.js +20 -2
- package/services/swap-service/handler/hydradx-handler.d.ts +2 -2
- package/services/swap-service/handler/hydradx-handler.js +106 -19
- package/services/swap-service/index.js +1 -0
- package/types/swap/index.d.ts +2 -0
- package/cjs/koni/api/dotsama/balance.js +0 -464
- package/cjs/koni/api/nft/ordinal_nft/utils.js +0 -41
- package/cjs/services/balance-service/helpers/subscribe/balance.js +0 -140
- package/cjs/services/chain-service/utils.js +0 -506
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
- package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
- package/cjs/services/storage-service/index.js +0 -241
- package/cjs/types/balance.js +0 -1
- package/cjs/types.js +0 -1
- package/cjs/utils/address.js +0 -34
- package/cjs/utils/keyring.js +0 -57
|
@@ -1227,34 +1227,17 @@ class KoniState {
|
|
|
1227
1227
|
maxFeePerGas: autoFormatNumber(transactionParams.maxFeePerGas),
|
|
1228
1228
|
data: transactionParams.data
|
|
1229
1229
|
};
|
|
1230
|
-
const getTransactionGas = async () => {
|
|
1231
|
-
try {
|
|
1232
|
-
transaction.gas = await web3.eth.estimateGas({
|
|
1233
|
-
...transaction
|
|
1234
|
-
});
|
|
1235
|
-
} catch (e) {
|
|
1236
|
-
// @ts-ignore
|
|
1237
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1238
|
-
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
1230
|
|
|
1242
1231
|
// Calculate transaction data
|
|
1243
1232
|
try {
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
await getTransactionGas();
|
|
1248
|
-
}
|
|
1249
|
-
})]);
|
|
1233
|
+
transaction.gas = await web3.eth.estimateGas({
|
|
1234
|
+
...transaction
|
|
1235
|
+
});
|
|
1250
1236
|
} catch (e) {
|
|
1251
1237
|
// @ts-ignore
|
|
1252
1238
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1253
1239
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1254
1240
|
}
|
|
1255
|
-
if (!transaction.gas) {
|
|
1256
|
-
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS);
|
|
1257
|
-
}
|
|
1258
1241
|
let estimateGas;
|
|
1259
1242
|
|
|
1260
1243
|
// TODO: Review, If not override, transaction maybe fail because fee too low
|
package/cjs/packageInfo.js
CHANGED
|
@@ -631,15 +631,6 @@ class ChainService {
|
|
|
631
631
|
}
|
|
632
632
|
}));
|
|
633
633
|
}
|
|
634
|
-
async initSingleApi(slug) {
|
|
635
|
-
const chainInfoMap = this.getChainInfoMap();
|
|
636
|
-
const chainStateMap = this.getChainStateMap();
|
|
637
|
-
if (!chainStateMap[slug].active) {
|
|
638
|
-
return false;
|
|
639
|
-
}
|
|
640
|
-
await this.initApiForChain(chainInfoMap[slug]);
|
|
641
|
-
return true;
|
|
642
|
-
}
|
|
643
634
|
async initApiForChain(chainInfo) {
|
|
644
635
|
const {
|
|
645
636
|
endpoint,
|
|
@@ -1658,5 +1649,10 @@ class ChainService {
|
|
|
1658
1649
|
}
|
|
1659
1650
|
return result;
|
|
1660
1651
|
}
|
|
1652
|
+
getFeeTokensByChain(chainSlug) {
|
|
1653
|
+
return Object.values(this.getAssetRegistry()).filter(chainAsset => {
|
|
1654
|
+
return chainAsset.originChain === chainSlug && (chainAsset.assetType === _types._AssetType.NATIVE || (0, _utils._isAssetCanPayTxFee)(chainAsset));
|
|
1655
|
+
}).map(chainAsset => chainAsset.slug);
|
|
1656
|
+
}
|
|
1661
1657
|
}
|
|
1662
1658
|
exports.ChainService = ChainService;
|
|
@@ -74,6 +74,7 @@ var _exportNames = {
|
|
|
74
74
|
findChainInfoByChainId: true,
|
|
75
75
|
_isMantaZkAsset: true,
|
|
76
76
|
randomizeProvider: true,
|
|
77
|
+
_isAssetCanPayTxFee: true,
|
|
77
78
|
updateLatestChainInfo: true
|
|
78
79
|
};
|
|
79
80
|
exports._checkSmartContractSupportByChain = _checkSmartContractSupportByChain;
|
|
@@ -110,6 +111,7 @@ exports._getXcmAssetMultilocation = _getXcmAssetMultilocation;
|
|
|
110
111
|
exports._getXcmAssetType = _getXcmAssetType;
|
|
111
112
|
exports._getXcmTransferType = _getXcmTransferType;
|
|
112
113
|
exports._isAssetAutoEnable = void 0;
|
|
114
|
+
exports._isAssetCanPayTxFee = _isAssetCanPayTxFee;
|
|
113
115
|
exports._isAssetFungibleToken = _isAssetFungibleToken;
|
|
114
116
|
exports._isAssetSmartContractNft = _isAssetSmartContractNft;
|
|
115
117
|
exports._isAssetValuable = _isAssetValuable;
|
|
@@ -562,6 +564,10 @@ function randomizeProvider(providers, excludedKeys) {
|
|
|
562
564
|
providerValue: selectedProviderValue
|
|
563
565
|
};
|
|
564
566
|
}
|
|
567
|
+
function _isAssetCanPayTxFee(chainAsset) {
|
|
568
|
+
var _ref, _chainAsset$metadata;
|
|
569
|
+
return (_ref = (_chainAsset$metadata = chainAsset.metadata) === null || _chainAsset$metadata === void 0 ? void 0 : _chainAsset$metadata.canPayTxFee) !== null && _ref !== void 0 ? _ref : false;
|
|
570
|
+
}
|
|
565
571
|
function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
|
|
566
572
|
const currentChainInfoMap = currentDataMap.chainInfoMap;
|
|
567
573
|
const currentChainStateMap = currentDataMap.chainStateMap;
|
|
@@ -574,8 +580,8 @@ function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
|
|
|
574
580
|
let needUpdate = false;
|
|
575
581
|
if (currentChainInfo && currentChainState) {
|
|
576
582
|
const preservedProvider = {};
|
|
577
|
-
Object.entries(currentChainInfo.providers).forEach(
|
|
578
|
-
let [providerKey, providerValue] =
|
|
583
|
+
Object.entries(currentChainInfo.providers).forEach(_ref2 => {
|
|
584
|
+
let [providerKey, providerValue] = _ref2;
|
|
579
585
|
if (providerValue !== null && providerValue !== void 0 && providerValue.startsWith('light') || providerKey !== null && providerKey !== void 0 && providerKey.startsWith(_types2._CUSTOM_PREFIX)) {
|
|
580
586
|
preservedProvider[providerKey] = providerValue;
|
|
581
587
|
}
|
|
@@ -12,7 +12,7 @@ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
|
12
12
|
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
13
13
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
14
14
|
const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
|
|
15
|
-
const ChainListVersion = '0.2.55
|
|
15
|
+
const ChainListVersion = '0.2.55';
|
|
16
16
|
async function fetchPatchData(slug) {
|
|
17
17
|
try {
|
|
18
18
|
const fetchPromise = (0, _crossFetch.default)(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
|
|
@@ -14,23 +14,10 @@ class MigrateTransactionHistoryBySymbol extends _Base.default {
|
|
|
14
14
|
const state = this.state;
|
|
15
15
|
try {
|
|
16
16
|
const changeSlugsMap = {
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'moonriver-LOCAL-xcaUSD': 'moonriver-LOCAL-xcaSeed',
|
|
22
|
-
'moonriver-LOCAL-xckBTC': 'moonriver-LOCAL-xcKBTC',
|
|
23
|
-
'bifrost-LOCAL-aUSD': 'bifrost-LOCAL-KUSD',
|
|
24
|
-
'calamari-LOCAL-aUSD': 'calamari-LOCAL-AUSD',
|
|
25
|
-
'shiden-LOCAL-aUSD': 'shiden-LOCAL-aSEED',
|
|
26
|
-
'shidenEvm-ERC20-aUSD-0xfFFfFFfF00000000000000010000000000000000': 'shidenEvm-ERC20-aSEED-0xfFFfFFfF00000000000000010000000000000000',
|
|
27
|
-
'ethereum_goerli-NATIVE-GoerliETH': 'ethereum_goerli-NATIVE-ETH',
|
|
28
|
-
'binance_test-NATIVE-BNB': 'binance_test-NATIVE-tBNB',
|
|
29
|
-
'pangolin-LOCAL-CKTON': 'pangolin-LOCAL-PKTON',
|
|
30
|
-
'zeta_test-NATIVE-aZETA': 'zeta_test-NATIVE-ZETA',
|
|
31
|
-
'origintrail-NATIVE-OTP': 'origintrail-NATIVE-NEURO',
|
|
32
|
-
'moonbeam-LOCAL-xciBTC': 'moonbeam-LOCAL-xcIBTC',
|
|
33
|
-
'tomochain-NATIVE-TOMO': 'tomochain-NATIVE-VIC'
|
|
17
|
+
'moonbeam-LOCAL-xcaUSD': 'moonbeam-LOCAL-xcaSEED',
|
|
18
|
+
'calamari-LOCAL-AUSD': 'calamari-LOCAL-aSEED',
|
|
19
|
+
'moonriver-LOCAL-xcaSeed': 'moonriver-LOCAL-xcaSEED',
|
|
20
|
+
'bifrost-LOCAL-KUSD': 'bifrost-LOCAL-aSEED'
|
|
34
21
|
};
|
|
35
22
|
const allTxs = [];
|
|
36
23
|
await Promise.all(Object.entries(changeSlugsMap).map(async (_ref, i) => {
|
|
@@ -13,23 +13,10 @@ class MigrateAssetSetting extends _Base.default {
|
|
|
13
13
|
async run() {
|
|
14
14
|
try {
|
|
15
15
|
const changeSlugsMap = {
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'moonriver-LOCAL-xcaUSD': 'moonriver-LOCAL-xcaSeed',
|
|
21
|
-
'moonriver-LOCAL-xckBTC': 'moonriver-LOCAL-xcKBTC',
|
|
22
|
-
'bifrost-LOCAL-aUSD': 'bifrost-LOCAL-KUSD',
|
|
23
|
-
'calamari-LOCAL-aUSD': 'calamari-LOCAL-AUSD',
|
|
24
|
-
'shiden-LOCAL-aUSD': 'shiden-LOCAL-aSEED',
|
|
25
|
-
'shidenEvm-ERC20-aUSD-0xfFFfFFfF00000000000000010000000000000000': 'shidenEvm-ERC20-aSEED-0xfFFfFFfF00000000000000010000000000000000',
|
|
26
|
-
'ethereum_goerli-NATIVE-GoerliETH': 'ethereum_goerli-NATIVE-ETH',
|
|
27
|
-
'binance_test-NATIVE-BNB': 'binance_test-NATIVE-tBNB',
|
|
28
|
-
'pangolin-LOCAL-CKTON': 'pangolin-LOCAL-PKTON',
|
|
29
|
-
'zeta_test-NATIVE-aZETA': 'zeta_test-NATIVE-ZETA',
|
|
30
|
-
'origintrail-NATIVE-OTP': 'origintrail-NATIVE-NEURO',
|
|
31
|
-
'moonbeam-LOCAL-xciBTC': 'moonbeam-LOCAL-xcIBTC',
|
|
32
|
-
'tomochain-NATIVE-TOMO': 'tomochain-NATIVE-VIC'
|
|
16
|
+
'moonbeam-LOCAL-xcaUSD': 'moonbeam-LOCAL-xcaSEED',
|
|
17
|
+
'calamari-LOCAL-AUSD': 'calamari-LOCAL-aSEED',
|
|
18
|
+
'moonriver-LOCAL-xcaSeed': 'moonriver-LOCAL-xcaSEED',
|
|
19
|
+
'bifrost-LOCAL-KUSD': 'bifrost-LOCAL-aSEED'
|
|
33
20
|
};
|
|
34
21
|
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
35
22
|
const migratedAssetSetting = {};
|
|
@@ -55,9 +55,9 @@ var _default = {
|
|
|
55
55
|
'1.1.26-01': _MigratePolygonUSDCProvider.default,
|
|
56
56
|
'1.1.28-01': _MigrateEarningVersion.default,
|
|
57
57
|
'1.1.41-01': _DeleteChainStaking.default,
|
|
58
|
-
'1.1.
|
|
59
|
-
'1.1.
|
|
60
|
-
'1.1.
|
|
58
|
+
'1.1.46-01': _AutoEnableSomeTokens.default,
|
|
59
|
+
'1.1.53-01': _MigrateAssetSetting.default,
|
|
60
|
+
'1.1.53-02': _MigrateTransactionHistoryBySymbol.default
|
|
61
61
|
// [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
|
|
62
62
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
63
63
|
};
|
|
@@ -104,7 +104,19 @@ class SwapBaseHandler {
|
|
|
104
104
|
return Promise.resolve([]);
|
|
105
105
|
}
|
|
106
106
|
async validateSetFeeTokenStep(params, stepIndex) {
|
|
107
|
-
|
|
107
|
+
if (!params.selectedQuote) {
|
|
108
|
+
return Promise.resolve([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)]);
|
|
109
|
+
}
|
|
110
|
+
const feeInfo = params.process.totalFee[stepIndex];
|
|
111
|
+
const feeAmount = feeInfo.feeComponent[0];
|
|
112
|
+
const feeTokenInfo = this.chainService.getAssetBySlug(feeInfo.defaultFeeToken);
|
|
113
|
+
const feeTokenBalance = await this.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenInfo.slug);
|
|
114
|
+
const bnFeeTokenBalance = new _bignumber.default(feeTokenBalance.value);
|
|
115
|
+
const bnFeeAmount = new _bignumber.default(feeAmount.amount);
|
|
116
|
+
if (bnFeeAmount.gte(bnFeeTokenBalance)) {
|
|
117
|
+
return Promise.resolve([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.NOT_ENOUGH_BALANCE)]);
|
|
118
|
+
}
|
|
119
|
+
return [];
|
|
108
120
|
}
|
|
109
121
|
async validateSwapStep(params, isXcmOk, stepIndex) {
|
|
110
122
|
if (!params.selectedQuote) {
|
|
@@ -127,9 +139,15 @@ class SwapBaseHandler {
|
|
|
127
139
|
const [feeTokenBalance, fromAssetBalance] = await Promise.all([this.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenInfo.slug), this.balanceService.getTokenFreeBalance(params.address, fromAsset.originChain, fromAsset.slug)]);
|
|
128
140
|
const bnFeeTokenBalance = new _bignumber.default(feeTokenBalance.value);
|
|
129
141
|
const bnFromAssetBalance = new _bignumber.default(fromAssetBalance.value);
|
|
130
|
-
|
|
142
|
+
const bnFeeAmount = new _bignumber.default(networkFee.amount);
|
|
143
|
+
if (bnFeeTokenBalance.lte(bnFeeAmount)) {
|
|
131
144
|
return Promise.resolve([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.NOT_ENOUGH_BALANCE, `You don't have enough ${feeTokenInfo.symbol} (${feeTokenChain.name}) to pay transaction fee`)]);
|
|
132
145
|
}
|
|
146
|
+
if (fromAsset.slug === feeTokenInfo.slug) {
|
|
147
|
+
if (bnFromAssetBalance.lte(bnFeeAmount.plus(bnAmount))) {
|
|
148
|
+
return Promise.resolve([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromAsset.symbol} and try again.`)]);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
133
151
|
if (params.selectedQuote.minSwap) {
|
|
134
152
|
const minProtocolSwap = new _bignumber.default(params.selectedQuote.minSwap);
|
|
135
153
|
if (!isXcmOk && bnFromAssetBalance.lte(minProtocolSwap)) {
|
|
@@ -26,10 +26,10 @@ const HYDRADX_SUBWALLET_REFERRAL_ACCOUNT = '7PCsCpkgsHdNaZhv79wCCQ5z97uxVbSeSCtD
|
|
|
26
26
|
const HYDRADX_TESTNET_SUBWALLET_REFERRAL_CODE = 'ASSETHUB';
|
|
27
27
|
const HYDRADX_TESTNET_SUBWALLET_REFERRAL_ACCOUNT = '7LCt6dFqtxzdKVB2648jWW9d85doiFfLSbZJDNAMVJNxh5rJ';
|
|
28
28
|
class HydradxHandler {
|
|
29
|
+
isTestnet = true;
|
|
29
30
|
isReady = false;
|
|
30
31
|
constructor(chainService, balanceService) {
|
|
31
32
|
let isTestnet = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
32
|
-
// todo: pass in baseHandler from service
|
|
33
33
|
this.swapBaseHandler = new _baseHandler.SwapBaseHandler({
|
|
34
34
|
balanceService,
|
|
35
35
|
chainService,
|
|
@@ -39,24 +39,24 @@ class HydradxHandler {
|
|
|
39
39
|
this.isTestnet = isTestnet;
|
|
40
40
|
}
|
|
41
41
|
async init() {
|
|
42
|
-
const chainState = this.chainService.getChainStateByKey(this.chain);
|
|
42
|
+
const chainState = this.chainService.getChainStateByKey(this.chain());
|
|
43
43
|
if (!chainState.active) {
|
|
44
|
-
await this.chainService.enableChain(this.chain);
|
|
44
|
+
await this.chainService.enableChain(this.chain());
|
|
45
45
|
}
|
|
46
|
-
const substrateApi = this.chainService.getSubstrateApi(this.chain);
|
|
46
|
+
const substrateApi = this.chainService.getSubstrateApi(this.chain());
|
|
47
47
|
await substrateApi.api.isReady;
|
|
48
48
|
const poolService = new _sdk.PoolService(substrateApi.api);
|
|
49
49
|
this.tradeRouter = new _sdk.TradeRouter(poolService);
|
|
50
50
|
this.isReady = true;
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
chain = () => {
|
|
53
53
|
// TODO: check origin chain of tokens in swap pair to determine support
|
|
54
54
|
if (!this.isTestnet) {
|
|
55
55
|
return _chainList.COMMON_CHAIN_SLUGS.HYDRADX;
|
|
56
56
|
} else {
|
|
57
57
|
return _chainList.COMMON_CHAIN_SLUGS.HYDRADX_TESTNET;
|
|
58
58
|
}
|
|
59
|
-
}
|
|
59
|
+
};
|
|
60
60
|
get chainService() {
|
|
61
61
|
return this.swapBaseHandler.chainService;
|
|
62
62
|
}
|
|
@@ -128,7 +128,44 @@ class HydradxHandler {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
async getFeeOptionStep(params) {
|
|
131
|
-
|
|
131
|
+
if (!params.selectedQuote) {
|
|
132
|
+
return Promise.resolve(undefined);
|
|
133
|
+
}
|
|
134
|
+
const selectedFeeToken = params.selectedQuote.feeInfo.selectedFeeToken;
|
|
135
|
+
if (!selectedFeeToken) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
const feeStep = {
|
|
139
|
+
name: 'Set fee token',
|
|
140
|
+
type: _swap.SwapStepType.SET_FEE_TOKEN
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
const substrateApi = this.chainService.getSubstrateApi(this.chain());
|
|
144
|
+
const chainApi = await substrateApi.isReady;
|
|
145
|
+
const _currentFeeAssetId = await chainApi.api.query.multiTransactionPayment.accountCurrencyMap(params.request.address);
|
|
146
|
+
const currentFeeAssetId = _currentFeeAssetId.toString();
|
|
147
|
+
const selectedFeeAsset = this.chainService.getAssetBySlug(selectedFeeToken);
|
|
148
|
+
const assetId = (0, _utils._getTokenOnChainAssetId)(selectedFeeAsset);
|
|
149
|
+
if (currentFeeAssetId === assetId) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const setFeeTx = chainApi.api.tx.multiTransactionPayment.setCurrency(assetId);
|
|
153
|
+
const _txFee = await setFeeTx.paymentInfo(params.request.address);
|
|
154
|
+
const txFee = _txFee.toPrimitive();
|
|
155
|
+
const fee = {
|
|
156
|
+
feeComponent: [{
|
|
157
|
+
feeType: _swap.SwapFeeType.NETWORK_FEE,
|
|
158
|
+
amount: Math.round(txFee.partialFee).toString(),
|
|
159
|
+
tokenSlug: selectedFeeAsset.slug
|
|
160
|
+
}],
|
|
161
|
+
selectedFeeToken: selectedFeeAsset.slug,
|
|
162
|
+
defaultFeeToken: selectedFeeAsset.slug,
|
|
163
|
+
feeOptions: [selectedFeeAsset.slug]
|
|
164
|
+
};
|
|
165
|
+
return [feeStep, fee];
|
|
166
|
+
} catch (e) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
132
169
|
}
|
|
133
170
|
async getSubmitStep(params) {
|
|
134
171
|
if (params.selectedQuote) {
|
|
@@ -141,7 +178,9 @@ class HydradxHandler {
|
|
|
141
178
|
return Promise.resolve(undefined);
|
|
142
179
|
}
|
|
143
180
|
generateOptimalProcess(params) {
|
|
144
|
-
return this.swapBaseHandler.generateOptimalProcess(params, [this.getXcmStep,
|
|
181
|
+
return this.swapBaseHandler.generateOptimalProcess(params, [this.getXcmStep,
|
|
182
|
+
// this.getFeeOptionStep.bind(this),
|
|
183
|
+
this.getSubmitStep]);
|
|
145
184
|
}
|
|
146
185
|
getSwapPathErrors(swapList) {
|
|
147
186
|
return swapList.reduce((prev, current) => {
|
|
@@ -149,7 +188,7 @@ class HydradxHandler {
|
|
|
149
188
|
}, []);
|
|
150
189
|
}
|
|
151
190
|
parseSwapPath(swapList) {
|
|
152
|
-
const swapAssets = this.chainService.getAssetByChainAndType(this.chain, [_types._AssetType.NATIVE, _types._AssetType.LOCAL]);
|
|
191
|
+
const swapAssets = this.chainService.getAssetByChainAndType(this.chain(), [_types._AssetType.NATIVE, _types._AssetType.LOCAL]);
|
|
153
192
|
const swapAssetIdMap = Object.values(swapAssets).reduce((accumulator, asset) => {
|
|
154
193
|
return {
|
|
155
194
|
...accumulator,
|
|
@@ -193,7 +232,7 @@ class HydradxHandler {
|
|
|
193
232
|
const toAmount = quoteResponse.amountOut;
|
|
194
233
|
const minReceive = toAmount.times(1 - request.slippage).integerValue();
|
|
195
234
|
const txHex = quoteResponse.toTx(minReceive).hex;
|
|
196
|
-
const substrateApi = this.chainService.getSubstrateApi(this.chain);
|
|
235
|
+
const substrateApi = this.chainService.getSubstrateApi(this.chain());
|
|
197
236
|
const extrinsic = substrateApi.api.tx(txHex);
|
|
198
237
|
const paymentInfo = await extrinsic.paymentInfo(request.address);
|
|
199
238
|
const networkFee = {
|
|
@@ -225,6 +264,16 @@ class HydradxHandler {
|
|
|
225
264
|
return new _SwapError.SwapError(_swap.SwapErrorType.NOT_ENOUGH_LIQUIDITY);
|
|
226
265
|
}
|
|
227
266
|
}
|
|
267
|
+
|
|
268
|
+
// const feeTokenOptions = this.chainService.getFeeTokensByChain(this.chain());
|
|
269
|
+
const feeTokenOptions = [fromChainNativeTokenSlug];
|
|
270
|
+
|
|
271
|
+
// if (request.feeToken && !feeTokenOptions.includes(request.feeToken)) {
|
|
272
|
+
// return new SwapError(SwapErrorType.UNKNOWN);
|
|
273
|
+
// }
|
|
274
|
+
|
|
275
|
+
// const selectedFeeToken = request.feeToken || fromChainNativeTokenSlug;
|
|
276
|
+
const selectedFeeToken = fromChainNativeTokenSlug;
|
|
228
277
|
return {
|
|
229
278
|
pair: request.pair,
|
|
230
279
|
fromAmount: request.fromAmount,
|
|
@@ -235,9 +284,10 @@ class HydradxHandler {
|
|
|
235
284
|
feeInfo: {
|
|
236
285
|
feeComponent: [networkFee, tradeFee],
|
|
237
286
|
defaultFeeToken: fromChainNativeTokenSlug,
|
|
238
|
-
feeOptions:
|
|
287
|
+
feeOptions: feeTokenOptions,
|
|
288
|
+
// TODO: enable fee options
|
|
289
|
+
selectedFeeToken
|
|
239
290
|
},
|
|
240
|
-
|
|
241
291
|
isLowLiquidity: Math.abs(quoteResponse.priceImpactPct) >= HYDRADX_LOW_LIQUIDITY_THRESHOLD,
|
|
242
292
|
route: swapRoute,
|
|
243
293
|
metadata: txHex
|
|
@@ -289,10 +339,34 @@ class HydradxHandler {
|
|
|
289
339
|
txData: xcmData
|
|
290
340
|
};
|
|
291
341
|
}
|
|
342
|
+
async handleSetFeeStep(params) {
|
|
343
|
+
var _swapFeeInfo$selected;
|
|
344
|
+
const substrateApi = this.chainService.getSubstrateApi(this.chain());
|
|
345
|
+
const chainApi = await substrateApi.isReady;
|
|
346
|
+
const swapStepIndex = params.process.steps.findIndex(step => step.type === _swap.SwapStepType.SWAP);
|
|
347
|
+
if (swapStepIndex <= -1) {
|
|
348
|
+
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR));
|
|
349
|
+
}
|
|
350
|
+
const swapFeeInfo = params.process.totalFee[swapStepIndex];
|
|
351
|
+
const selectedFeeTokenSlug = (_swapFeeInfo$selected = swapFeeInfo.selectedFeeToken) !== null && _swapFeeInfo$selected !== void 0 ? _swapFeeInfo$selected : swapFeeInfo.defaultFeeToken;
|
|
352
|
+
const selectedFeeAsset = this.chainService.getAssetBySlug(selectedFeeTokenSlug);
|
|
353
|
+
const extrinsic = chainApi.api.tx.multiTransactionPayment.setCurrency((0, _utils._getTokenOnChainAssetId)(selectedFeeAsset));
|
|
354
|
+
const txData = {
|
|
355
|
+
selectedFeeToken: selectedFeeTokenSlug
|
|
356
|
+
};
|
|
357
|
+
return {
|
|
358
|
+
txChain: this.chain(),
|
|
359
|
+
extrinsic,
|
|
360
|
+
// extrinsicType: ExtrinsicType.SET_FEE_TOKEN,
|
|
361
|
+
extrinsicType: _KoniTypes.ExtrinsicType.SWAP,
|
|
362
|
+
chainType: _KoniTypes.ChainType.SUBSTRATE,
|
|
363
|
+
txData
|
|
364
|
+
};
|
|
365
|
+
}
|
|
292
366
|
async handleSubmitStep(params) {
|
|
293
367
|
const txHex = params.quote.metadata;
|
|
294
368
|
const fromAsset = this.chainService.getAssetBySlug(params.quote.pair.from);
|
|
295
|
-
const substrateApi = this.chainService.getSubstrateApi(this.chain);
|
|
369
|
+
const substrateApi = this.chainService.getSubstrateApi(this.chain());
|
|
296
370
|
const chainApi = await substrateApi.isReady;
|
|
297
371
|
const txData = {
|
|
298
372
|
provider: this.providerInfo,
|
|
@@ -303,12 +377,25 @@ class HydradxHandler {
|
|
|
303
377
|
process: params.process
|
|
304
378
|
};
|
|
305
379
|
let extrinsic;
|
|
380
|
+
const txList = [];
|
|
381
|
+
const swapTx = chainApi.api.tx(txHex);
|
|
306
382
|
const _referral = await chainApi.api.query.referrals.linkedAccounts(params.address);
|
|
307
383
|
const referral = _referral === null || _referral === void 0 ? void 0 : _referral.toString();
|
|
308
|
-
|
|
309
|
-
|
|
384
|
+
const needSetReferral = !referral || referral === '';
|
|
385
|
+
const steps = params.process.steps.map(step => step.type);
|
|
386
|
+
const needSetFeeToken = steps.includes(_swap.SwapStepType.SET_FEE_TOKEN);
|
|
387
|
+
if (!needSetReferral && !needSetFeeToken) {
|
|
388
|
+
extrinsic = swapTx;
|
|
310
389
|
} else {
|
|
311
|
-
|
|
390
|
+
if (needSetReferral) {
|
|
391
|
+
txList.push(chainApi.api.tx.referrals.linkCode(this.referralCode));
|
|
392
|
+
}
|
|
393
|
+
if (needSetFeeToken) {
|
|
394
|
+
const nativeTokenInfo = this.chainService.getNativeTokenInfo(this.chain());
|
|
395
|
+
txList.push(chainApi.api.tx.multiTransactionPayment.setCurrency((0, _utils._getTokenOnChainAssetId)(nativeTokenInfo)));
|
|
396
|
+
}
|
|
397
|
+
txList.push(swapTx);
|
|
398
|
+
extrinsic = chainApi.api.tx.utility.batchAll(txList);
|
|
312
399
|
}
|
|
313
400
|
return {
|
|
314
401
|
txChain: fromAsset.originChain,
|
|
@@ -332,7 +419,7 @@ class HydradxHandler {
|
|
|
332
419
|
case _swap.SwapStepType.XCM:
|
|
333
420
|
return this.handleXcmStep(params);
|
|
334
421
|
case _swap.SwapStepType.SET_FEE_TOKEN:
|
|
335
|
-
return
|
|
422
|
+
return this.handleSetFeeStep(params);
|
|
336
423
|
case _swap.SwapStepType.SWAP:
|
|
337
424
|
return this.handleSubmitStep(params);
|
|
338
425
|
default:
|
|
@@ -401,7 +488,7 @@ class HydradxHandler {
|
|
|
401
488
|
error: _swap.SwapErrorType.ASSET_NOT_SUPPORTED
|
|
402
489
|
};
|
|
403
490
|
}
|
|
404
|
-
if (!(fromAsset.originChain === this.chain && toAsset.originChain === this.chain)) {
|
|
491
|
+
if (!(fromAsset.originChain === this.chain() && toAsset.originChain === this.chain())) {
|
|
405
492
|
return {
|
|
406
493
|
error: _swap.SwapErrorType.ASSET_NOT_SUPPORTED
|
|
407
494
|
};
|
|
@@ -419,7 +506,7 @@ class HydradxHandler {
|
|
|
419
506
|
}
|
|
420
507
|
return {
|
|
421
508
|
metadata: {
|
|
422
|
-
chain: this.chainService.getChainInfoByKey(this.chain)
|
|
509
|
+
chain: this.chainService.getChainInfoByKey(this.chain())
|
|
423
510
|
}
|
|
424
511
|
};
|
|
425
512
|
} catch (e) {
|
|
@@ -1393,6 +1393,26 @@ export default class KoniExtension {
|
|
|
1393
1393
|
throw new Error(t('Wrong password'));
|
|
1394
1394
|
}
|
|
1395
1395
|
}
|
|
1396
|
+
async batchExportV2({
|
|
1397
|
+
addresses,
|
|
1398
|
+
password
|
|
1399
|
+
}) {
|
|
1400
|
+
try {
|
|
1401
|
+
if (addresses && !addresses.length) {
|
|
1402
|
+
throw new Error(t('No accounts found to export'));
|
|
1403
|
+
}
|
|
1404
|
+
return {
|
|
1405
|
+
exportedJson: await keyring.backupAccounts(password, addresses)
|
|
1406
|
+
};
|
|
1407
|
+
} catch (e) {
|
|
1408
|
+
const error = e;
|
|
1409
|
+
if (error.message === 'Invalid master password') {
|
|
1410
|
+
throw new Error(t('Wrong password'));
|
|
1411
|
+
} else {
|
|
1412
|
+
throw error;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1396
1416
|
getNftCollection() {
|
|
1397
1417
|
return this.#koniState.getNftCollection();
|
|
1398
1418
|
}
|
|
@@ -4000,6 +4020,9 @@ export default class KoniExtension {
|
|
|
4000
4020
|
txChain,
|
|
4001
4021
|
txData
|
|
4002
4022
|
} = await this.#koniState.swapService.handleSwapProcess(inputData);
|
|
4023
|
+
// const chosenFeeToken = process.steps.findIndex((step) => step.type === SwapStepType.SET_FEE_TOKEN) > -1;
|
|
4024
|
+
// const allowSkipValidation = [ExtrinsicType.SET_FEE_TOKEN, ExtrinsicType.SWAP].includes(extrinsicType);
|
|
4025
|
+
|
|
4003
4026
|
return await this.#koniState.transactionService.handleTransaction({
|
|
4004
4027
|
address,
|
|
4005
4028
|
chain: txChain,
|
|
@@ -4011,6 +4034,7 @@ export default class KoniExtension {
|
|
|
4011
4034
|
chainType,
|
|
4012
4035
|
resolveOnDone: !isLastStep,
|
|
4013
4036
|
transferNativeAmount
|
|
4037
|
+
// skipFeeValidation: chosenFeeToken && allowSkipValidation
|
|
4014
4038
|
});
|
|
4015
4039
|
}
|
|
4016
4040
|
/* Swap service */
|
|
@@ -4146,6 +4170,8 @@ export default class KoniExtension {
|
|
|
4146
4170
|
return this.subscribeCrowdloan(id, port);
|
|
4147
4171
|
case 'pri(derivation.createV2)':
|
|
4148
4172
|
return this.derivationCreateV2(request);
|
|
4173
|
+
case 'pri(accounts.batchExportV2)':
|
|
4174
|
+
return this.batchExportV2(request);
|
|
4149
4175
|
case 'pri(json.restoreV2)':
|
|
4150
4176
|
return this.jsonRestoreV2(request);
|
|
4151
4177
|
case 'pri(json.batchRestoreV2)':
|
|
@@ -32,7 +32,7 @@ import { SwapService } from '@subwallet/extension-base/services/swap-service';
|
|
|
32
32
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
33
33
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
34
34
|
import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
|
|
35
|
-
import { isAccountAll, stripUrl, TARGET_ENV
|
|
35
|
+
import { isAccountAll, stripUrl, TARGET_ENV } from '@subwallet/extension-base/utils';
|
|
36
36
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
37
37
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
38
38
|
import { decodePair } from '@subwallet/keyring/pair/decode';
|
|
@@ -1204,34 +1204,17 @@ export default class KoniState {
|
|
|
1204
1204
|
maxFeePerGas: autoFormatNumber(transactionParams.maxFeePerGas),
|
|
1205
1205
|
data: transactionParams.data
|
|
1206
1206
|
};
|
|
1207
|
-
const getTransactionGas = async () => {
|
|
1208
|
-
try {
|
|
1209
|
-
transaction.gas = await web3.eth.estimateGas({
|
|
1210
|
-
...transaction
|
|
1211
|
-
});
|
|
1212
|
-
} catch (e) {
|
|
1213
|
-
// @ts-ignore
|
|
1214
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1215
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1216
|
-
}
|
|
1217
|
-
};
|
|
1218
1207
|
|
|
1219
1208
|
// Calculate transaction data
|
|
1220
1209
|
try {
|
|
1221
|
-
await
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
await getTransactionGas();
|
|
1225
|
-
}
|
|
1226
|
-
})]);
|
|
1210
|
+
transaction.gas = await web3.eth.estimateGas({
|
|
1211
|
+
...transaction
|
|
1212
|
+
});
|
|
1227
1213
|
} catch (e) {
|
|
1228
1214
|
// @ts-ignore
|
|
1229
1215
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1230
1216
|
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1231
1217
|
}
|
|
1232
|
-
if (!transaction.gas) {
|
|
1233
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS);
|
|
1234
|
-
}
|
|
1235
1218
|
let estimateGas;
|
|
1236
1219
|
|
|
1237
1220
|
// TODO: Review, If not override, transaction maybe fail because fee too low
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.55-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -1851,7 +1851,7 @@
|
|
|
1851
1851
|
"@ethereumjs/common": "^4.1.0",
|
|
1852
1852
|
"@ethereumjs/tx": "^5.1.0",
|
|
1853
1853
|
"@ethersproject/abi": "^5.7.0",
|
|
1854
|
-
"@galacticcouncil/sdk": "^
|
|
1854
|
+
"@galacticcouncil/sdk": "^2.1.0",
|
|
1855
1855
|
"@json-rpc-tools/utils": "^1.7.6",
|
|
1856
1856
|
"@metamask/safe-event-emitter": "^2.0.0",
|
|
1857
1857
|
"@metaverse-network-sdk/type-definitions": "^0.0.1-13",
|
|
@@ -1873,13 +1873,13 @@
|
|
|
1873
1873
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1874
1874
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1875
1875
|
"@substrate/connect": "^0.7.26",
|
|
1876
|
-
"@subwallet/chain-list": "0.2.55
|
|
1877
|
-
"@subwallet/extension-base": "^1.1.
|
|
1878
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1879
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1880
|
-
"@subwallet/extension-inject": "^1.1.
|
|
1881
|
-
"@subwallet/keyring": "^0.1.
|
|
1882
|
-
"@subwallet/ui-keyring": "^0.1.
|
|
1876
|
+
"@subwallet/chain-list": "0.2.55",
|
|
1877
|
+
"@subwallet/extension-base": "^1.1.55-0",
|
|
1878
|
+
"@subwallet/extension-chains": "^1.1.55-0",
|
|
1879
|
+
"@subwallet/extension-dapp": "^1.1.55-0",
|
|
1880
|
+
"@subwallet/extension-inject": "^1.1.55-0",
|
|
1881
|
+
"@subwallet/keyring": "^0.1.5",
|
|
1882
|
+
"@subwallet/ui-keyring": "^0.1.5",
|
|
1883
1883
|
"@walletconnect/sign-client": "^2.8.4",
|
|
1884
1884
|
"@walletconnect/types": "^2.8.4",
|
|
1885
1885
|
"@walletconnect/utils": "^2.8.4",
|
|
@@ -1914,4 +1914,4 @@
|
|
|
1914
1914
|
"web3-eth-contract": "^1.10.0",
|
|
1915
1915
|
"web3-utils": "^1.10.0"
|
|
1916
1916
|
}
|
|
1917
|
-
}
|
|
1917
|
+
}
|
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.1.
|
|
10
|
+
version: '1.1.55-0'
|
|
11
11
|
};
|
|
@@ -93,7 +93,6 @@ export declare class ChainService {
|
|
|
93
93
|
autoEnableTokens(): Promise<void>;
|
|
94
94
|
handleLatestData(): void;
|
|
95
95
|
private initApis;
|
|
96
|
-
initSingleApi(slug: string): Promise<boolean>;
|
|
97
96
|
private initApiForChain;
|
|
98
97
|
private destroyApiForChain;
|
|
99
98
|
enableChain(chainSlug: string): Promise<boolean>;
|
|
@@ -143,4 +142,5 @@ export declare class ChainService {
|
|
|
143
142
|
getMetadataByHash(hash: string): import("dexie").PromiseExtended<IMetadataItem | undefined>;
|
|
144
143
|
getSubscanChainMap(reverse?: boolean): Record<string, string>;
|
|
145
144
|
get detectBalanceChainSlugMap(): Record<string, string>;
|
|
145
|
+
getFeeTokensByChain(chainSlug: string): string[];
|
|
146
146
|
}
|