@subwallet/extension-base 1.3.29-0 → 1.3.30-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 +4 -4
- package/background/errors/SwapError.js +1 -1
- package/cjs/background/errors/SwapError.js +1 -1
- package/cjs/constants/blocked-actions.js +2 -2
- package/cjs/constants/remind-notification-time.js +3 -3
- package/cjs/core/logic-validation/swap.js +63 -4
- package/cjs/core/utils.js +9 -3
- package/cjs/koni/background/handlers/Extension.js +5 -82
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/earning-service/handlers/base.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -1
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +68 -50
- package/cjs/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/cjs/services/earning-service/service.js +2 -1
- package/cjs/services/fee-service/utils/index.js +16 -4
- package/cjs/services/inapp-notification-service/index.js +19 -13
- package/cjs/services/swap-service/handler/asset-hub/handler.js +61 -314
- package/cjs/services/swap-service/handler/base-handler.js +393 -231
- package/cjs/services/swap-service/handler/chainflip-handler.js +18 -40
- package/cjs/services/swap-service/handler/hydradx-handler.js +77 -269
- package/cjs/services/swap-service/handler/simpleswap-handler.js +27 -48
- package/cjs/services/swap-service/handler/uniswap-handler.js +33 -54
- package/cjs/services/swap-service/index.js +154 -143
- package/cjs/services/swap-service/utils.js +107 -17
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/types/swap/index.js +13 -1
- package/cjs/utils/swap.js +5 -1
- package/constants/blocked-actions.d.ts +1 -1
- package/constants/blocked-actions.js +1 -1
- package/constants/remind-notification-time.d.ts +1 -1
- package/constants/remind-notification-time.js +1 -1
- package/core/logic-validation/swap.d.ts +15 -0
- package/core/logic-validation/swap.js +60 -4
- package/core/utils.js +9 -3
- package/koni/background/handlers/Extension.d.ts +0 -1
- package/koni/background/handlers/Extension.js +6 -83
- package/package.json +6 -12
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/services/base/types.d.ts +0 -4
- package/services/chain-service/constants.js +1 -1
- package/services/earning-service/handlers/base.d.ts +4 -3
- package/services/earning-service/handlers/base.js +6 -4
- package/services/earning-service/handlers/native-staking/base.js +4 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +9 -6
- package/services/earning-service/handlers/native-staking/dtao.js +69 -48
- package/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +2 -1
- package/services/fee-service/utils/index.d.ts +1 -0
- package/services/fee-service/utils/index.js +14 -4
- package/services/inapp-notification-service/index.js +13 -7
- package/services/swap-service/handler/asset-hub/handler.d.ts +2 -9
- package/services/swap-service/handler/asset-hub/handler.js +64 -317
- package/services/swap-service/handler/base-handler.d.ts +6 -9
- package/services/swap-service/handler/base-handler.js +391 -229
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -4
- package/services/swap-service/handler/chainflip-handler.js +15 -37
- package/services/swap-service/handler/hydradx-handler.d.ts +3 -10
- package/services/swap-service/handler/hydradx-handler.js +78 -270
- package/services/swap-service/handler/simpleswap-handler.d.ts +2 -4
- package/services/swap-service/handler/simpleswap-handler.js +24 -45
- package/services/swap-service/handler/uniswap-handler.d.ts +4 -6
- package/services/swap-service/handler/uniswap-handler.js +25 -46
- package/services/swap-service/index.d.ts +8 -14
- package/services/swap-service/index.js +141 -129
- package/services/swap-service/utils.d.ts +11 -3
- package/services/swap-service/utils.js +96 -15
- package/services/transaction-service/index.js +2 -2
- package/types/service-base.d.ts +2 -3
- package/types/swap/index.d.ts +25 -9
- package/types/swap/index.js +10 -0
- package/types/transaction/process.d.ts +19 -0
- package/types/yield/actions/join/submit.d.ts +4 -1
- package/types/yield/actions/others.d.ts +2 -0
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +3 -0
- package/cjs/services/swap-service/interface.js +0 -14
- package/services/swap-service/interface.d.ts +0 -9
- package/services/swap-service/interface.js +0 -8
|
@@ -15,7 +15,7 @@ import { AuthUrls } from '@subwallet/extension-base/services/request-service/typ
|
|
|
15
15
|
import { CrowdloanContributionsResponse } from '@subwallet/extension-base/services/subscan-service/types';
|
|
16
16
|
import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
|
|
17
17
|
import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
|
|
18
|
-
import { AccountChainType, AccountJson, AccountsWithCurrentAddress, AddressJson, BalanceJson, BaseRequestSign, BuyServiceInfo, BuyTokenInfo,
|
|
18
|
+
import { AccountChainType, AccountJson, AccountsWithCurrentAddress, AddressJson, BalanceJson, BaseRequestSign, BuyServiceInfo, BuyTokenInfo, CommonOptimalTransferPath, CurrentAccountInfo, EarningRewardHistoryItem, EarningRewardJson, EarningStatus, HandleYieldStepParams, InternalRequestSign, LeavePoolAdditionalData, NominationPoolInfo, OptimalYieldPath, OptimalYieldPathParams, RequestAccountBatchExportV2, RequestAccountCreateSuriV2, RequestAccountNameValidate, RequestAccountProxyEdit, RequestAccountProxyForget, RequestBatchJsonGetAccountInfo, RequestBatchRestoreV2, RequestBounceableValidate, RequestChangeAllowOneSign, RequestChangeTonWalletContractVersion, RequestCheckCrossChainTransfer, RequestCheckPublicAndSecretKey, RequestCheckTransfer, RequestCrossChainTransfer, RequestDeriveCreateMultiple, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestEarlyValidateYield, RequestEarningSlippage, RequestExportAccountProxyMnemonic, RequestGetAllTonWalletContractVersion, RequestGetAmountForPair, RequestGetDeriveAccounts, RequestGetDeriveSuggestion, RequestGetTokensCanPayFee, RequestGetYieldPoolTargets, RequestInputAccountSubscribe, RequestJsonGetAccountInfo, RequestJsonRestoreV2, RequestMetadataHash, RequestMnemonicCreateV2, RequestMnemonicValidateV2, RequestPrivateKeyValidateV2, RequestShortenMetadata, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestSubmitProcessTransaction, RequestSubscribeProcessById, RequestTransfer, RequestUnlockDotCheckCanMint, RequestUnlockDotSubscribeMintedData, RequestYieldLeave, RequestYieldStepSubmit, RequestYieldWithdrawal, ResponseAccountBatchExportV2, ResponseAccountCreateSuriV2, ResponseAccountNameValidate, ResponseBatchJsonGetAccountInfo, ResponseCheckPublicAndSecretKey, ResponseDeriveValidateV2, ResponseEarlyValidateYield, ResponseExportAccountProxyMnemonic, ResponseGetAllTonWalletContractVersion, ResponseGetDeriveAccounts, ResponseGetDeriveSuggestion, ResponseGetYieldPoolTargets, ResponseInputAccountSubscribe, ResponseJsonGetAccountInfo, ResponseMetadataHash, ResponseMnemonicCreateV2, ResponseMnemonicValidateV2, ResponsePrivateKeyValidateV2, ResponseShortenMetadata, ResponseSubscribeProcessAlive, ResponseSubscribeProcessById, StorageDataInterface, SubmitYieldStepData, SubnetYieldPositionInfo, SwapPair, SwapQuoteResponse, SwapRequest, SwapRequestResult, SwapRequestV2, SwapSubmitParams, SwapTxData, TokenSpendingApprovalParams, UnlockDotTransactionNft, UnstakingStatus, ValidateSwapProcessParams, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolType, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
19
19
|
import { RequestSubmitTransfer, RequestSubscribeTransfer, ResponseSubscribeTransfer } from '@subwallet/extension-base/types/balance/transfer';
|
|
20
20
|
import { RequestClaimBridge } from '@subwallet/extension-base/types/bridge';
|
|
21
21
|
import { GetNotificationParams, RequestIsClaimedPolygonBridge, RequestSwitchStatusParams } from '@subwallet/extension-base/types/notification';
|
|
@@ -31,6 +31,7 @@ import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers';
|
|
|
31
31
|
import { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
|
|
32
32
|
import { SignerResult } from '@polkadot/types/types/extrinsic';
|
|
33
33
|
import { HexString } from '@polkadot/util/types';
|
|
34
|
+
import { EarningSlippageResult } from '../services/earning-service/handlers/native-staking/dtao';
|
|
34
35
|
import { TransactionWarning } from './warnings/TransactionWarning';
|
|
35
36
|
export declare enum RuntimeEnvironment {
|
|
36
37
|
Web = "Web",
|
|
@@ -1692,7 +1693,7 @@ export interface KoniRequestSignatures {
|
|
|
1692
1693
|
'pri(yield.withdraw.submit)': [RequestYieldWithdrawal, SWTransactionResponse];
|
|
1693
1694
|
'pri(yield.cancelWithdrawal.submit)': [RequestStakeCancelWithdrawal, SWTransactionResponse];
|
|
1694
1695
|
'pri(yield.claimReward.submit)': [RequestStakeClaimReward, SWTransactionResponse];
|
|
1695
|
-
'pri(yield.getEarningSlippage)': [RequestEarningSlippage,
|
|
1696
|
+
'pri(yield.getEarningSlippage)': [RequestEarningSlippage, EarningSlippageResult];
|
|
1696
1697
|
'pri(transaction.history.getSubscription)': [null, TransactionHistoryItem[], TransactionHistoryItem[]];
|
|
1697
1698
|
'pri(transaction.history.subscribe)': [RequestSubscribeHistory, ResponseSubscribeHistory, TransactionHistoryItem[]];
|
|
1698
1699
|
'pri(transfer.getMaxTransferable)': [RequestMaxTransferable, AmountData];
|
|
@@ -1784,9 +1785,8 @@ export interface KoniRequestSignatures {
|
|
|
1784
1785
|
'pri(database.setLocalStorage)': [StorageDataInterface, boolean];
|
|
1785
1786
|
'pri(database.getLocalStorage)': [string, string | null];
|
|
1786
1787
|
'pri(swapService.subscribePairs)': [null, SwapPair[], SwapPair[]];
|
|
1787
|
-
'pri(swapService.getOptimalProcessOnSelectQuote)': [OptimalSwapPathParamsV2, CommonOptimalSwapPath];
|
|
1788
1788
|
'pri(swapService.handleSwapRequest)': [SwapRequest, SwapRequestResult];
|
|
1789
|
-
'pri(swapService.handleSwapRequestV2)': [
|
|
1789
|
+
'pri(swapService.handleSwapRequestV2)': [SwapRequestV2, SwapRequestResult];
|
|
1790
1790
|
'pri(swapService.handleSwapStep)': [SwapSubmitParams, SWTransactionResponse];
|
|
1791
1791
|
'pri(swapService.getLatestQuote)': [SwapRequest, SwapQuoteResponse];
|
|
1792
1792
|
'pri(swapService.validateSwapProcess)': [ValidateSwapProcessParams, TransactionError[]];
|
|
@@ -5,7 +5,7 @@ import { SWError } from '@subwallet/extension-base/background/errors/SWError';
|
|
|
5
5
|
import { detectTranslate } from '@subwallet/extension-base/utils';
|
|
6
6
|
const defaultErrorMap = {
|
|
7
7
|
ERROR_FETCHING_QUOTE: {
|
|
8
|
-
message: detectTranslate('No swap quote found.
|
|
8
|
+
message: detectTranslate('No swap quote found. Change your network endpoint or adjust amount and try again'),
|
|
9
9
|
code: undefined
|
|
10
10
|
},
|
|
11
11
|
NOT_MEET_MIN_SWAP: {
|
|
@@ -11,7 +11,7 @@ var _utils = require("@subwallet/extension-base/utils");
|
|
|
11
11
|
|
|
12
12
|
const defaultErrorMap = {
|
|
13
13
|
ERROR_FETCHING_QUOTE: {
|
|
14
|
-
message: (0, _utils.detectTranslate)('No swap quote found.
|
|
14
|
+
message: (0, _utils.detectTranslate)('No swap quote found. Change your network endpoint or adjust amount and try again'),
|
|
15
15
|
code: undefined
|
|
16
16
|
},
|
|
17
17
|
NOT_MEET_MIN_SWAP: {
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.APP_VER = exports.APP_ENV = void 0;
|
|
7
7
|
exports.fetchBlockedConfigObjects = fetchBlockedConfigObjects;
|
|
8
|
-
exports.
|
|
8
|
+
exports.fetchLatestBlockedActionsAndFeatures = fetchLatestBlockedActionsAndFeatures;
|
|
9
9
|
exports.getPassConfigId = getPassConfigId;
|
|
10
10
|
var _extensionBase = require("@subwallet/extension-base");
|
|
11
11
|
var _utils = require("@subwallet/extension-base/utils");
|
|
@@ -99,7 +99,7 @@ function isPassVersion(versionStr, versionCondition) {
|
|
|
99
99
|
const versionConditionStr = versionCondition.trim();
|
|
100
100
|
return versionStr === versionConditionStr;
|
|
101
101
|
}
|
|
102
|
-
async function
|
|
102
|
+
async function fetchLatestBlockedActionsAndFeatures(ids) {
|
|
103
103
|
if (ids.length === 0) {
|
|
104
104
|
return [_staticData.staticData[_staticData.StaticKey.BLOCKED_ACTIONS_FEATURES]];
|
|
105
105
|
}
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchLatestRemindNotificationTime = void 0;
|
|
7
7
|
var _utils = require("@subwallet/extension-base/utils");
|
|
8
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
9
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const fetchLatestRemindNotificationTime = async () => {
|
|
12
12
|
return await (0, _utils.fetchStaticData)('config/remind-notification-time');
|
|
13
13
|
};
|
|
14
|
-
exports.
|
|
14
|
+
exports.fetchLatestRemindNotificationTime = fetchLatestRemindNotificationTime;
|
|
@@ -10,7 +10,10 @@ exports._getEarlyHydradxValidationError = _getEarlyHydradxValidationError;
|
|
|
10
10
|
exports._getSimpleSwapEarlyValidationError = _getSimpleSwapEarlyValidationError;
|
|
11
11
|
exports._validateBalanceToSwap = _validateBalanceToSwap;
|
|
12
12
|
exports._validateBalanceToSwapOnAssetHub = _validateBalanceToSwapOnAssetHub;
|
|
13
|
+
exports._validateBalanceToSwapV2 = _validateBalanceToSwapV2;
|
|
14
|
+
exports._validateQuoteV2 = _validateQuoteV2;
|
|
13
15
|
exports._validateSwapRecipient = _validateSwapRecipient;
|
|
16
|
+
exports._validateSwapRecipientV2 = _validateSwapRecipientV2;
|
|
14
17
|
var _SwapError = require("@subwallet/extension-base/background/errors/SwapError");
|
|
15
18
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
16
19
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
@@ -113,7 +116,7 @@ function _getChainflipEarlyValidationError(error, metadata) {
|
|
|
113
116
|
case _swap.SwapErrorType.UNKNOWN:
|
|
114
117
|
return new _SwapError.SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
115
118
|
case _swap.SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
116
|
-
return new _SwapError.SwapError(error, 'No swap quote found.
|
|
119
|
+
return new _SwapError.SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
117
120
|
default:
|
|
118
121
|
return new _SwapError.SwapError(error);
|
|
119
122
|
}
|
|
@@ -129,7 +132,7 @@ function _getEarlyHydradxValidationError(error, metadata) {
|
|
|
129
132
|
case _swap.SwapErrorType.UNKNOWN:
|
|
130
133
|
return new _SwapError.SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
131
134
|
case _swap.SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
132
|
-
return new _SwapError.SwapError(error, 'No swap quote found.
|
|
135
|
+
return new _SwapError.SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
133
136
|
default:
|
|
134
137
|
return new _SwapError.SwapError(error);
|
|
135
138
|
}
|
|
@@ -143,7 +146,7 @@ function _getEarlyAssetHubValidationError(error, metadata) {
|
|
|
143
146
|
case _swap.SwapErrorType.UNKNOWN:
|
|
144
147
|
return new _SwapError.SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
145
148
|
case _swap.SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
146
|
-
return new _SwapError.SwapError(error, 'No swap quote found.
|
|
149
|
+
return new _SwapError.SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
147
150
|
case _swap.SwapErrorType.MAKE_POOL_NOT_ENOUGH_EXISTENTIAL_DEPOSIT:
|
|
148
151
|
return new _SwapError.SwapError(error, 'You swap too much. It make pool not enough existential deposit');
|
|
149
152
|
// TODO: i18n this
|
|
@@ -172,8 +175,64 @@ function _getSimpleSwapEarlyValidationError(error, metadata) {
|
|
|
172
175
|
case _swap.SwapErrorType.UNKNOWN:
|
|
173
176
|
return new _SwapError.SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
174
177
|
case _swap.SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
175
|
-
return new _SwapError.SwapError(error, 'No swap quote found.
|
|
178
|
+
return new _SwapError.SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
176
179
|
default:
|
|
177
180
|
return new _SwapError.SwapError(error);
|
|
178
181
|
}
|
|
182
|
+
}
|
|
183
|
+
function _validateQuoteV2(selectedQuote) {
|
|
184
|
+
if (!selectedQuote) {
|
|
185
|
+
return new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Check swapQuote alive
|
|
189
|
+
if (selectedQuote.aliveUntil <= +Date.now()) {
|
|
190
|
+
return new _TransactionError.TransactionError(_swap.SwapErrorType.QUOTE_TIMEOUT);
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
function _validateBalanceToSwapV2(request) {
|
|
195
|
+
const {
|
|
196
|
+
chainInfo,
|
|
197
|
+
feeAmount,
|
|
198
|
+
feeToken,
|
|
199
|
+
feeTokenBalance,
|
|
200
|
+
fromToken,
|
|
201
|
+
fromTokenBalance,
|
|
202
|
+
minSwapAmount,
|
|
203
|
+
swapAmount
|
|
204
|
+
} = request;
|
|
205
|
+
const bnFromTokenBalance = (0, _bignumber.default)(fromTokenBalance);
|
|
206
|
+
if (new _bignumber.default(feeTokenBalance).lte(feeAmount)) {
|
|
207
|
+
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `You don't have enough ${feeToken.symbol} (${chainInfo.name}) to pay transaction fee`);
|
|
208
|
+
}
|
|
209
|
+
if (fromToken.slug === feeToken.slug) {
|
|
210
|
+
// todo: need review and refactor
|
|
211
|
+
if (bnFromTokenBalance.lte((0, _bignumber.default)(feeAmount).plus(swapAmount))) {
|
|
212
|
+
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
if (bnFromTokenBalance.lt(swapAmount)) {
|
|
216
|
+
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (minSwapAmount) {
|
|
220
|
+
if (bnFromTokenBalance.lte(minSwapAmount)) {
|
|
221
|
+
const parsedMinSwapValue = (0, _utils2.formatNumber)(minSwapAmount, (0, _utils._getAssetDecimals)(fromToken));
|
|
222
|
+
return new _TransactionError.TransactionError(_swap.SwapErrorType.SWAP_NOT_ENOUGH_BALANCE, `Insufficient balance. You need more than ${parsedMinSwapValue} ${fromToken.symbol} to start swapping. Deposit ${fromToken.symbol} and try again.`); // todo: min swap or amount?
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
function _validateSwapRecipientV2(destChainInfo, recipient) {
|
|
229
|
+
if (!recipient) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
const isEvmAddress = (0, _utilCrypto.isEthereumAddress)(recipient);
|
|
233
|
+
const isEvmDestChain = (0, _utils._isChainEvmCompatible)(destChainInfo);
|
|
234
|
+
if (isEvmAddress && !isEvmDestChain || !isEvmAddress && isEvmDestChain) {
|
|
235
|
+
return new _TransactionError.TransactionError(_swap.SwapErrorType.INVALID_RECIPIENT);
|
|
236
|
+
}
|
|
237
|
+
return undefined;
|
|
179
238
|
}
|
package/cjs/core/utils.js
CHANGED
|
@@ -151,6 +151,7 @@ function _isSupportLedgerAccount(validateRecipientParams) {
|
|
|
151
151
|
return '';
|
|
152
152
|
}
|
|
153
153
|
const _isSufficientToken = async (tokenInfo, substrateApi) => {
|
|
154
|
+
// todo: remove const and detect by pallets instead
|
|
154
155
|
if (_constants.SUFFICIENT_CHAIN.includes(tokenInfo.originChain) && tokenInfo.assetType !== _types._AssetType.NATIVE) {
|
|
155
156
|
const assetId = (0, _utils2._isBridgedToken)(tokenInfo) ? (0, _utils2._getXcmAssetMultilocation)(tokenInfo) : (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
156
157
|
const queryParams = {
|
|
@@ -163,9 +164,14 @@ const _isSufficientToken = async (tokenInfo, substrateApi) => {
|
|
|
163
164
|
queryParams.module = 'assets';
|
|
164
165
|
}
|
|
165
166
|
const metadata = await substrateApi.makeRpcQuery(queryParams);
|
|
166
|
-
return metadata.isSufficient;
|
|
167
|
-
} else {
|
|
168
|
-
return false;
|
|
167
|
+
return (metadata === null || metadata === void 0 ? void 0 : metadata.isSufficient) || false;
|
|
169
168
|
}
|
|
169
|
+
|
|
170
|
+
// todo
|
|
171
|
+
// if (tokenInfo.metadata?.isSufficient) {
|
|
172
|
+
// return tokenInfo.metadata?.isSufficient;
|
|
173
|
+
// }
|
|
174
|
+
|
|
175
|
+
return false;
|
|
170
176
|
};
|
|
171
177
|
exports._isSufficientToken = _isSufficientToken;
|
|
@@ -293,7 +293,6 @@ class KoniExtension {
|
|
|
293
293
|
const transformedAccounts = Object.values(accountProxies);
|
|
294
294
|
responseData.accounts = transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [(0, _utils7.combineAllAccountProxy)(transformedAccounts), ...transformedAccounts] : [];
|
|
295
295
|
responseData.currentAccountProxy = currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.proxyId;
|
|
296
|
-
console.debug('subscriptionAccountGroups', responseData);
|
|
297
296
|
cb(responseData);
|
|
298
297
|
});
|
|
299
298
|
this.createUnsubscriptionHandle(id, () => {
|
|
@@ -3699,11 +3698,9 @@ class KoniExtension {
|
|
|
3699
3698
|
ready = true;
|
|
3700
3699
|
return this.#koniState.swapService.getSwapPairs();
|
|
3701
3700
|
}
|
|
3702
|
-
async getOptimalSwapProcessOnSelectQuote(request) {
|
|
3703
|
-
return this.#koniState.swapService.generateOptimalProcessWithoutPath(request);
|
|
3704
|
-
}
|
|
3705
3701
|
async handleSwapRequest(request) {
|
|
3706
|
-
|
|
3702
|
+
// @ts-ignore
|
|
3703
|
+
return Promise.resolve(null);
|
|
3707
3704
|
}
|
|
3708
3705
|
async handleSwapRequestV2(request) {
|
|
3709
3706
|
return this.#koniState.swapService.handleSwapRequestV2(request);
|
|
@@ -3715,7 +3712,7 @@ class KoniExtension {
|
|
|
3715
3712
|
return swapQuoteResponse;
|
|
3716
3713
|
}
|
|
3717
3714
|
async validateSwapProcess(params) {
|
|
3718
|
-
return this.#koniState.swapService.
|
|
3715
|
+
return this.#koniState.swapService.validateSwapProcessV2(params);
|
|
3719
3716
|
}
|
|
3720
3717
|
async handleSwapStep(inputData) {
|
|
3721
3718
|
const {
|
|
@@ -3745,7 +3742,7 @@ class KoniExtension {
|
|
|
3745
3742
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_types3.BasicTxErrorType.INTERNAL_ERROR)]);
|
|
3746
3743
|
}
|
|
3747
3744
|
const isLastStep = inputData.currentStep + 1 === process.steps.length;
|
|
3748
|
-
const swapValidations = await this.#koniState.swapService.
|
|
3745
|
+
const swapValidations = await this.#koniState.swapService.validateSwapProcessV2({
|
|
3749
3746
|
address,
|
|
3750
3747
|
process,
|
|
3751
3748
|
selectedQuote: quote,
|
|
@@ -3769,9 +3766,9 @@ class KoniExtension {
|
|
|
3769
3766
|
status: _types3.StepStatus.FAILED
|
|
3770
3767
|
});
|
|
3771
3768
|
}
|
|
3769
|
+
console.log('Error handling process step', e);
|
|
3772
3770
|
throw e;
|
|
3773
3771
|
}
|
|
3774
|
-
console.log('swap data', submitData);
|
|
3775
3772
|
|
|
3776
3773
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
3777
3774
|
const {
|
|
@@ -3783,17 +3780,12 @@ class KoniExtension {
|
|
|
3783
3780
|
txChain,
|
|
3784
3781
|
txData
|
|
3785
3782
|
} = submitData;
|
|
3786
|
-
|
|
3787
|
-
// const chosenFeeToken = process.steps.findIndex((step) => step.type === SwapStepType.SET_FEE_TOKEN) > -1;
|
|
3788
|
-
// const allowSkipValidation = [ExtrinsicType.SET_FEE_TOKEN, ExtrinsicType.SWAP].includes(extrinsicType);
|
|
3789
|
-
|
|
3790
3783
|
const eventsHandler = eventEmitter => {
|
|
3791
3784
|
if (onSend) {
|
|
3792
3785
|
eventEmitter.on('send', onSend);
|
|
3793
3786
|
}
|
|
3794
3787
|
};
|
|
3795
3788
|
if (processId) {
|
|
3796
|
-
const _step = process.steps[inputData.currentStep];
|
|
3797
3789
|
if (!this.#koniState.transactionService.checkProcessExist(processId) && step) {
|
|
3798
3790
|
const combineInfo = {
|
|
3799
3791
|
provider: quote.provider,
|
|
@@ -3811,23 +3803,6 @@ class KoniExtension {
|
|
|
3811
3803
|
combineInfo,
|
|
3812
3804
|
steps: inputData.process.steps.map((step, index) => {
|
|
3813
3805
|
const fee = inputData.process.totalFee[index];
|
|
3814
|
-
if (step.type === _types3.SwapStepType.SWAP) {
|
|
3815
|
-
const metadata = {
|
|
3816
|
-
pair: quote.pair,
|
|
3817
|
-
aliveUntil: quote.aliveUntil,
|
|
3818
|
-
fromAmount: quote.fromAmount,
|
|
3819
|
-
rate: quote.rate,
|
|
3820
|
-
provider: quote.provider,
|
|
3821
|
-
route: quote.route,
|
|
3822
|
-
toAmount: quote.toAmount
|
|
3823
|
-
};
|
|
3824
|
-
return {
|
|
3825
|
-
...step,
|
|
3826
|
-
status: _types3.StepStatus.QUEUED,
|
|
3827
|
-
fee,
|
|
3828
|
-
metadata: metadata
|
|
3829
|
-
};
|
|
3830
|
-
}
|
|
3831
3806
|
return {
|
|
3832
3807
|
...step,
|
|
3833
3808
|
fee,
|
|
@@ -3837,34 +3812,6 @@ class KoniExtension {
|
|
|
3837
3812
|
status: _types3.StepStatus.QUEUED
|
|
3838
3813
|
});
|
|
3839
3814
|
}
|
|
3840
|
-
const isLastStep = inputData.currentStep === process.steps.length - 1;
|
|
3841
|
-
if (isLastStep) {
|
|
3842
|
-
const metadata = {
|
|
3843
|
-
pair: quote.pair,
|
|
3844
|
-
aliveUntil: quote.aliveUntil,
|
|
3845
|
-
fromAmount: quote.fromAmount,
|
|
3846
|
-
rate: quote.rate,
|
|
3847
|
-
provider: quote.provider,
|
|
3848
|
-
route: quote.route,
|
|
3849
|
-
toAmount: quote.toAmount
|
|
3850
|
-
};
|
|
3851
|
-
const step = {
|
|
3852
|
-
..._step,
|
|
3853
|
-
// In case one sign, status already set to prepare before
|
|
3854
|
-
status: process.steps.length > 2 ? _types3.StepStatus.PREPARE : _types3.StepStatus.QUEUED,
|
|
3855
|
-
fee: process.totalFee[inputData.currentStep],
|
|
3856
|
-
metadata: metadata
|
|
3857
|
-
};
|
|
3858
|
-
const combineInfo = {
|
|
3859
|
-
provider: quote.provider,
|
|
3860
|
-
slippage: inputData.slippage,
|
|
3861
|
-
address,
|
|
3862
|
-
recipient,
|
|
3863
|
-
quote,
|
|
3864
|
-
process
|
|
3865
|
-
};
|
|
3866
|
-
await this.#koniState.transactionService.updateProcessInfo(processId, combineInfo, step);
|
|
3867
|
-
}
|
|
3868
3815
|
}
|
|
3869
3816
|
if (isPermit) {
|
|
3870
3817
|
return await this.#koniState.transactionService.handlePermitTransaction({
|
|
@@ -4096,32 +4043,10 @@ class KoniExtension {
|
|
|
4096
4043
|
nextTxType: _KoniTypes.ExtrinsicType.SWAP
|
|
4097
4044
|
};
|
|
4098
4045
|
submitData = async (step, callback) => {
|
|
4099
|
-
const isLastStep = step === stepNums - 1;
|
|
4100
4046
|
const isPassConfirmation = !callback;
|
|
4101
4047
|
const onSend = callback
|
|
4102
4048
|
// eslint-disable-next-line node/no-callback-literal
|
|
4103
4049
|
? rs => callback(rs) : undefined;
|
|
4104
|
-
const specialCaseForUniswap = data.quote.provider.id === _types3.SwapProviderId.UNISWAP && !!data.process.steps.find(step => step.type === _types3.SwapStepType.PERMIT);
|
|
4105
|
-
if (stepNums > 2 && isLastStep && !specialCaseForUniswap) {
|
|
4106
|
-
const quote = data.quote;
|
|
4107
|
-
const latestSwapQuote = await this.getLatestSwapQuote({
|
|
4108
|
-
address: data.address,
|
|
4109
|
-
currentQuote: quote.provider,
|
|
4110
|
-
feeToken: quote.feeInfo.selectedFeeToken,
|
|
4111
|
-
recipient: data.recipient,
|
|
4112
|
-
pair: quote.pair,
|
|
4113
|
-
fromAmount: quote.fromAmount,
|
|
4114
|
-
slippage: data.slippage
|
|
4115
|
-
});
|
|
4116
|
-
return this.handleSwapStep({
|
|
4117
|
-
...data,
|
|
4118
|
-
quote: latestSwapQuote.optimalQuote || data.quote,
|
|
4119
|
-
currentStep: step,
|
|
4120
|
-
isPassConfirmation,
|
|
4121
|
-
errorOnTimeOut: true,
|
|
4122
|
-
processId
|
|
4123
|
-
});
|
|
4124
|
-
}
|
|
4125
4050
|
return this.handleSwapStep({
|
|
4126
4051
|
...data,
|
|
4127
4052
|
currentStep: step,
|
|
@@ -4824,8 +4749,6 @@ class KoniExtension {
|
|
|
4824
4749
|
/* Swap service */
|
|
4825
4750
|
case 'pri(swapService.subscribePairs)':
|
|
4826
4751
|
return this.subscribeSwapPairs(id, port);
|
|
4827
|
-
case 'pri(swapService.getOptimalProcessOnSelectQuote)':
|
|
4828
|
-
return this.getOptimalSwapProcessOnSelectQuote(request);
|
|
4829
4752
|
case 'pri(swapService.handleSwapRequest)':
|
|
4830
4753
|
return this.handleSwapRequest(request);
|
|
4831
4754
|
case 'pri(swapService.handleSwapRequestV2)':
|
package/cjs/packageInfo.js
CHANGED
|
@@ -67,12 +67,12 @@ async function getClaimTxOnAvail(notification, substrateApi) {
|
|
|
67
67
|
const chainApi = await substrateApi.isReady;
|
|
68
68
|
const chainSlug = chainApi.chainSlug;
|
|
69
69
|
const metadata = notification.metadata;
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const proof = await getClaimProofOnAvail(chainSlug,
|
|
73
|
-
return chainApi.api.tx.vector.execute(
|
|
70
|
+
const latestEthHeadSlot = await getLatestEthHeadSlot(chainSlug);
|
|
71
|
+
const latestBlockHash = await getLatestBlockHash(chainSlug, latestEthHeadSlot);
|
|
72
|
+
const proof = await getClaimProofOnAvail(chainSlug, latestBlockHash, metadata.messageId);
|
|
73
|
+
return chainApi.api.tx.vector.execute(latestEthHeadSlot, getAddressMessage(notification), proof.accountProof, proof.storageProof);
|
|
74
74
|
}
|
|
75
|
-
async function
|
|
75
|
+
async function getLatestEthHeadSlot(chainSlug) {
|
|
76
76
|
try {
|
|
77
77
|
const api = getAvailBridgeApi(chainSlug);
|
|
78
78
|
const rawResponse = await fetch(`${api}/eth/head`);
|
|
@@ -83,7 +83,7 @@ async function getLastestEthHeadSlot(chainSlug) {
|
|
|
83
83
|
throw e;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
async function
|
|
86
|
+
async function getLatestBlockHash(chainSlug, slot) {
|
|
87
87
|
try {
|
|
88
88
|
const api = getAvailBridgeApi(chainSlug);
|
|
89
89
|
const rawResponse = await fetch(`${api}/beacon/slot/${slot}`);
|
|
@@ -300,7 +300,7 @@ const _XCM_CHAIN_GROUP = {
|
|
|
300
300
|
// default is xTokens pallet
|
|
301
301
|
};
|
|
302
302
|
exports._XCM_CHAIN_GROUP = _XCM_CHAIN_GROUP;
|
|
303
|
-
const SUFFICIENT_CHAIN = ['astar', 'calamari', 'parallel', 'darwinia2', 'crabParachain', 'pangolin', 'statemint', 'moonriver', 'shiden', 'moonbeam', 'statemine', 'liberland', 'dentnet', 'phala', 'crust', 'dbcchain', 'rococo_assethub'
|
|
303
|
+
const SUFFICIENT_CHAIN = ['astar', 'calamari', 'parallel', 'darwinia2', 'crabParachain', 'pangolin', 'statemint', 'moonriver', 'shiden', 'moonbeam', 'statemine', 'liberland', 'dentnet', 'phala', 'crust', 'dbcchain', 'rococo_assethub'];
|
|
304
304
|
exports.SUFFICIENT_CHAIN = SUFFICIENT_CHAIN;
|
|
305
305
|
const _XCM_TYPE = {
|
|
306
306
|
RP: `${_types._SubstrateChainType.RELAYCHAIN}-${_types._SubstrateChainType.PARACHAIN}`,
|
|
@@ -256,11 +256,11 @@ class BasePoolHandler {
|
|
|
256
256
|
/** Validate param to join the pool */
|
|
257
257
|
|
|
258
258
|
/** Create `transaction` to leave the pool */
|
|
259
|
-
async handleYieldLeave(fastLeave, amount, address, selectedTarget, netuid) {
|
|
259
|
+
async handleYieldLeave(fastLeave, amount, address, selectedTarget, netuid, slippage) {
|
|
260
260
|
if (fastLeave) {
|
|
261
261
|
return this.handleYieldRedeem(amount, address, selectedTarget);
|
|
262
262
|
} else {
|
|
263
|
-
return this.handleYieldUnstake(amount, address, selectedTarget, netuid);
|
|
263
|
+
return this.handleYieldUnstake(amount, address, selectedTarget, netuid, slippage);
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -275,7 +275,10 @@ class BasePoolHandler {
|
|
|
275
275
|
return this.slug === slug;
|
|
276
276
|
}
|
|
277
277
|
getEarningSlippage(params) {
|
|
278
|
-
return Promise.resolve(
|
|
278
|
+
return Promise.resolve({
|
|
279
|
+
slippage: 0,
|
|
280
|
+
rate: 1
|
|
281
|
+
});
|
|
279
282
|
}
|
|
280
283
|
/* Other actions */
|
|
281
284
|
}
|
|
@@ -110,7 +110,10 @@ class BaseNativeStakingPoolHandler extends _base.default {
|
|
|
110
110
|
address,
|
|
111
111
|
slug,
|
|
112
112
|
selectedValidators,
|
|
113
|
-
|
|
113
|
+
subnetData: {
|
|
114
|
+
netuid: netuid || 0,
|
|
115
|
+
slippage: 0
|
|
116
|
+
}
|
|
114
117
|
};
|
|
115
118
|
const positionInfo = await this.getPoolPosition(address);
|
|
116
119
|
const [, fee] = await this.createJoinExtrinsic(data, positionInfo);
|