@subwallet/extension-base 1.3.29-1 → 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 +1 -1
- 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/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 +1 -1
- 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/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
|
@@ -4,16 +4,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports._PROVIDER_TO_SUPPORTED_PAIR_MAP = exports.SWAP_QUOTE_TIMEOUT_MAP = exports.SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = exports.SIMPLE_SWAP_EXPLORER = exports.FEE_RATE_MULTIPLIER = exports.CHAIN_FLIP_TESTNET_EXPLORER = exports.CHAIN_FLIP_MAINNET_EXPLORER = void 0;
|
|
7
|
+
exports._PROVIDER_TO_SUPPORTED_PAIR_MAP = exports.SWAP_QUOTE_TIMEOUT_MAP = exports.SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = exports.SIMPLE_SWAP_EXPLORER = exports.FEE_RATE_MULTIPLIER = exports.DEFAULT_EXCESS_AMOUNT_WEIGHT = exports.CHAIN_FLIP_TESTNET_EXPLORER = exports.CHAIN_FLIP_MAINNET_EXPLORER = void 0;
|
|
8
8
|
exports.calculateSwapRate = calculateSwapRate;
|
|
9
9
|
exports.convertSwapRate = convertSwapRate;
|
|
10
|
-
exports.
|
|
10
|
+
exports.findAllBridgeDestinations = findAllBridgeDestinations;
|
|
11
|
+
exports.findBridgeTransitDestination = findBridgeTransitDestination;
|
|
12
|
+
exports.findSwapTransitDestination = findSwapTransitDestination;
|
|
13
|
+
exports.getAmountAfterSlippage = getAmountAfterSlippage;
|
|
11
14
|
exports.getBridgeStep = getBridgeStep;
|
|
15
|
+
exports.getChainRouteFromSteps = getChainRouteFromSteps;
|
|
12
16
|
exports.getChainflipBroker = getChainflipBroker;
|
|
13
17
|
exports.getChainflipOptions = getChainflipOptions;
|
|
14
18
|
exports.getChainflipSwap = getChainflipSwap;
|
|
19
|
+
exports.getFirstAmountFromSteps = getFirstAmountFromSteps;
|
|
20
|
+
exports.getLastAmountFromSteps = getLastAmountFromSteps;
|
|
21
|
+
exports.getSupportSwapChain = getSupportSwapChain;
|
|
15
22
|
exports.getSwapAltToken = getSwapAltToken;
|
|
16
23
|
exports.getSwapAlternativeAsset = getSwapAlternativeAsset;
|
|
24
|
+
exports.getSwapChainsFromPath = getSwapChainsFromPath;
|
|
17
25
|
exports.getSwapStep = getSwapStep;
|
|
18
26
|
exports.getTokenPairFromStep = getTokenPairFromStep;
|
|
19
27
|
exports.isChainsHasSameProvider = isChainsHasSameProvider;
|
|
@@ -21,7 +29,6 @@ var _chainList = require("@subwallet/chain-list");
|
|
|
21
29
|
var _types = require("@subwallet/chain-list/types");
|
|
22
30
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
23
31
|
var _chainflipHandler = require("@subwallet/extension-base/services/swap-service/handler/chainflip-handler");
|
|
24
|
-
var _interface = require("@subwallet/extension-base/services/swap-service/interface");
|
|
25
32
|
var _types2 = require("@subwallet/extension-base/types");
|
|
26
33
|
var _swap = require("@subwallet/extension-base/types/swap");
|
|
27
34
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
@@ -44,7 +51,7 @@ const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = {
|
|
|
44
51
|
exports.SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING;
|
|
45
52
|
const SWAP_QUOTE_TIMEOUT_MAP = {
|
|
46
53
|
// in milliseconds
|
|
47
|
-
default:
|
|
54
|
+
default: 90000,
|
|
48
55
|
[_swap.SwapProviderId.CHAIN_FLIP_TESTNET]: 30000,
|
|
49
56
|
[_swap.SwapProviderId.CHAIN_FLIP_MAINNET]: 30000
|
|
50
57
|
};
|
|
@@ -69,6 +76,9 @@ const FEE_RATE_MULTIPLIER = {
|
|
|
69
76
|
high: 2
|
|
70
77
|
};
|
|
71
78
|
exports.FEE_RATE_MULTIPLIER = FEE_RATE_MULTIPLIER;
|
|
79
|
+
function getSupportSwapChain() {
|
|
80
|
+
return [...new Set(Object.values(_PROVIDER_TO_SUPPORTED_PAIR_MAP).flat())];
|
|
81
|
+
}
|
|
72
82
|
function getSwapAlternativeAsset(swapPair) {
|
|
73
83
|
var _swapPair$metadata;
|
|
74
84
|
return swapPair === null || swapPair === void 0 ? void 0 : (_swapPair$metadata = swapPair.metadata) === null || _swapPair$metadata === void 0 ? void 0 : _swapPair$metadata.alternativeAsset;
|
|
@@ -78,15 +88,15 @@ function getSwapAltToken(chainAsset) {
|
|
|
78
88
|
return (_chainAsset$metadata = chainAsset.metadata) === null || _chainAsset$metadata === void 0 ? void 0 : _chainAsset$metadata.alternativeSwapAsset;
|
|
79
89
|
}
|
|
80
90
|
function calculateSwapRate(fromAmount, toAmount, fromAsset, toAsset) {
|
|
81
|
-
const bnFromAmount =
|
|
82
|
-
const bnToAmount =
|
|
91
|
+
const bnFromAmount = (0, _bignumber.default)(fromAmount);
|
|
92
|
+
const bnToAmount = (0, _bignumber.default)(toAmount);
|
|
83
93
|
const decimalDiff = (0, _utils._getAssetDecimals)(toAsset) - (0, _utils._getAssetDecimals)(fromAsset);
|
|
84
94
|
const bnRate = bnFromAmount.div(bnToAmount);
|
|
85
95
|
return 1 / bnRate.times(10 ** decimalDiff).toNumber();
|
|
86
96
|
}
|
|
87
97
|
function convertSwapRate(rate, fromAsset, toAsset) {
|
|
88
98
|
const decimalDiff = (0, _utils._getAssetDecimals)(toAsset) - (0, _utils._getAssetDecimals)(fromAsset);
|
|
89
|
-
const bnRate =
|
|
99
|
+
const bnRate = (0, _bignumber.default)(rate);
|
|
90
100
|
return bnRate.times(10 ** decimalDiff).pow(-1).toNumber();
|
|
91
101
|
}
|
|
92
102
|
function getChainflipOptions(isTestnet) {
|
|
@@ -124,9 +134,10 @@ function getChainflipSwap(isTestnet) {
|
|
|
124
134
|
}
|
|
125
135
|
function getBridgeStep(from, to) {
|
|
126
136
|
return {
|
|
127
|
-
action:
|
|
137
|
+
action: _types2.DynamicSwapType.BRIDGE,
|
|
128
138
|
pair: {
|
|
129
139
|
slug: `${from}___${to}`,
|
|
140
|
+
// todo: recheck with assetRef format from chain list
|
|
130
141
|
from,
|
|
131
142
|
to
|
|
132
143
|
}
|
|
@@ -134,21 +145,36 @@ function getBridgeStep(from, to) {
|
|
|
134
145
|
}
|
|
135
146
|
function getSwapStep(from, to) {
|
|
136
147
|
return {
|
|
137
|
-
action:
|
|
148
|
+
action: _types2.DynamicSwapType.SWAP,
|
|
138
149
|
pair: {
|
|
139
150
|
slug: `${from}___${to}`,
|
|
151
|
+
// todo: recheck with assetRef format from chain list
|
|
140
152
|
from,
|
|
141
153
|
to
|
|
142
154
|
}
|
|
143
155
|
};
|
|
144
156
|
}
|
|
145
|
-
function
|
|
146
|
-
const foundAssetRef = Object.values(assetRefMap).find(assetRef => assetRef.srcAsset ===
|
|
157
|
+
function findBridgeTransitDestination(assetRefMap, fromToken, toToken) {
|
|
158
|
+
const foundAssetRef = Object.values(assetRefMap).find(assetRef => assetRef.srcAsset === fromToken.slug && assetRef.destChain === (0, _utils._getAssetOriginChain)(toToken) && assetRef.path === _types._AssetRefPath.XCM);
|
|
147
159
|
if (foundAssetRef) {
|
|
148
160
|
return foundAssetRef.destAsset;
|
|
149
161
|
}
|
|
150
162
|
return undefined;
|
|
151
163
|
}
|
|
164
|
+
function findSwapTransitDestination(assetRefMap, fromToken, toToken) {
|
|
165
|
+
const foundAssetRef = Object.values(assetRefMap).find(assetRef => assetRef.destAsset === toToken.slug && assetRef.srcChain === (0, _utils._getAssetOriginChain)(fromToken) && assetRef.path === _types._AssetRefPath.XCM);
|
|
166
|
+
if (foundAssetRef) {
|
|
167
|
+
return foundAssetRef.srcAsset;
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
function findAllBridgeDestinations(assetRefMap, fromToken) {
|
|
172
|
+
const foundAssetRefs = Object.values(assetRefMap).filter(assetRef => assetRef.srcAsset === fromToken.slug && assetRef.path === _types._AssetRefPath.XCM);
|
|
173
|
+
return foundAssetRefs.map(assetRef => assetRef.destAsset);
|
|
174
|
+
}
|
|
175
|
+
function getAmountAfterSlippage(amount, slippage) {
|
|
176
|
+
return (0, _bignumber.default)(amount).multipliedBy((0, _bignumber.default)(1).minus((0, _bignumber.default)(slippage))).integerValue(_bignumber.default.ROUND_DOWN).toString();
|
|
177
|
+
}
|
|
152
178
|
function isChainsHasSameProvider(fromChain, toChain) {
|
|
153
179
|
// todo: a provider may support multiple chains but not cross-chain swaps
|
|
154
180
|
for (const group of Object.values(_PROVIDER_TO_SUPPORTED_PAIR_MAP)) {
|
|
@@ -158,27 +184,91 @@ function isChainsHasSameProvider(fromChain, toChain) {
|
|
|
158
184
|
}
|
|
159
185
|
return false;
|
|
160
186
|
}
|
|
161
|
-
function
|
|
187
|
+
function getLastAmountFromSteps(steps) {
|
|
188
|
+
var _lastStep$metadata;
|
|
189
|
+
const lastStep = steps[steps.length - 1]; // last step
|
|
190
|
+
const lastAmount = lastStep === null || lastStep === void 0 ? void 0 : (_lastStep$metadata = lastStep.metadata) === null || _lastStep$metadata === void 0 ? void 0 : _lastStep$metadata.destinationValue;
|
|
191
|
+
return lastAmount !== null && lastAmount !== void 0 ? lastAmount : undefined;
|
|
192
|
+
}
|
|
193
|
+
function getFirstAmountFromSteps(steps) {
|
|
194
|
+
var _firstStep$metadata;
|
|
195
|
+
const firstStep = steps[1]; // first step after default step
|
|
196
|
+
const firstAmount = firstStep === null || firstStep === void 0 ? void 0 : (_firstStep$metadata = firstStep.metadata) === null || _firstStep$metadata === void 0 ? void 0 : _firstStep$metadata.sendingValue;
|
|
197
|
+
return firstAmount !== null && firstAmount !== void 0 ? firstAmount : undefined;
|
|
198
|
+
}
|
|
199
|
+
function getChainRouteFromSteps(steps) {
|
|
200
|
+
// todo: handle metadata for other providers than hydra & pah. Also add validate metadata.
|
|
162
201
|
const mainSteps = steps.filter(step => step.type !== _types2.CommonStepType.DEFAULT);
|
|
202
|
+
return mainSteps.reduce((chainRoute, currentStep, currentIndex) => {
|
|
203
|
+
const metadata = currentStep.metadata;
|
|
204
|
+
if (!metadata) {
|
|
205
|
+
console.error('Step has no metadata');
|
|
206
|
+
return chainRoute;
|
|
207
|
+
}
|
|
208
|
+
if (currentIndex === 0) {
|
|
209
|
+
chainRoute.push(metadata.originTokenInfo.originChain);
|
|
210
|
+
chainRoute.push(metadata.destinationTokenInfo.originChain);
|
|
211
|
+
} else {
|
|
212
|
+
chainRoute.push(metadata.destinationTokenInfo.originChain);
|
|
213
|
+
}
|
|
214
|
+
return chainRoute;
|
|
215
|
+
}, []);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// note: this function may return undefined if metadata version is < 2 or does not exist
|
|
219
|
+
function getTokenPairFromStep(steps) {
|
|
220
|
+
// todo: review this
|
|
221
|
+
const mainSteps = steps.filter(step => step.type !== _types2.CommonStepType.DEFAULT && step.type !== _types2.CommonStepType.TOKEN_APPROVAL && step.type !== _types2.SwapStepType.PERMIT);
|
|
163
222
|
if (!mainSteps.length) {
|
|
164
223
|
return undefined;
|
|
165
224
|
}
|
|
225
|
+
const isStepValidIfSwap = step => {
|
|
226
|
+
const metadata = step.metadata;
|
|
227
|
+
return step.type !== _types2.SwapStepType.SWAP || !!(metadata !== null && metadata !== void 0 && metadata.version) && (metadata === null || metadata === void 0 ? void 0 : metadata.version) >= 2;
|
|
228
|
+
};
|
|
166
229
|
if (mainSteps.length === 1) {
|
|
167
|
-
|
|
168
|
-
|
|
230
|
+
if (!isStepValidIfSwap(mainSteps[0])) {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
const metadata = mainSteps[0].metadata;
|
|
234
|
+
if (!metadata) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
169
237
|
return {
|
|
170
238
|
from: metadata.originTokenInfo.slug,
|
|
171
239
|
to: metadata.destinationTokenInfo.slug,
|
|
172
|
-
slug:
|
|
240
|
+
slug: (0, _utils._parseAssetRefKey)(metadata.originTokenInfo.slug, metadata.destinationTokenInfo.slug)
|
|
173
241
|
};
|
|
174
242
|
}
|
|
175
243
|
const firstStep = mainSteps[0];
|
|
176
244
|
const lastStep = mainSteps[mainSteps.length - 1];
|
|
245
|
+
if (!isStepValidIfSwap(firstStep) || !isStepValidIfSwap(lastStep)) {
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
177
248
|
const firstMetadata = firstStep.metadata;
|
|
178
249
|
const lastMetadata = lastStep.metadata;
|
|
250
|
+
if (!firstMetadata || !lastMetadata) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
179
253
|
return {
|
|
180
254
|
from: firstMetadata.originTokenInfo.slug,
|
|
181
255
|
to: lastMetadata.destinationTokenInfo.slug,
|
|
182
|
-
slug:
|
|
256
|
+
slug: (0, _utils._parseAssetRefKey)(firstMetadata.originTokenInfo.slug, lastMetadata.destinationTokenInfo.slug)
|
|
183
257
|
};
|
|
184
|
-
}
|
|
258
|
+
}
|
|
259
|
+
function getSwapChainsFromPath(path) {
|
|
260
|
+
const swapChains = [];
|
|
261
|
+
path.forEach(pathElement => {
|
|
262
|
+
const fromAssetOriginChain = (0, _utils._getOriginChainOfAsset)(pathElement.pair.from);
|
|
263
|
+
const toAssetOriginChain = (0, _utils._getOriginChainOfAsset)(pathElement.pair.to);
|
|
264
|
+
if (swapChains.at(-1) !== fromAssetOriginChain) {
|
|
265
|
+
swapChains.push(fromAssetOriginChain);
|
|
266
|
+
}
|
|
267
|
+
if (swapChains.at(-1) !== toAssetOriginChain) {
|
|
268
|
+
swapChains.push(toAssetOriginChain);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
return swapChains;
|
|
272
|
+
}
|
|
273
|
+
const DEFAULT_EXCESS_AMOUNT_WEIGHT = 1.04; // add 2%
|
|
274
|
+
exports.DEFAULT_EXCESS_AMOUNT_WEIGHT = DEFAULT_EXCESS_AMOUNT_WEIGHT;
|
|
@@ -87,7 +87,7 @@ class TransactionService {
|
|
|
87
87
|
const blockedConfigObjects = await (0, _constants.fetchBlockedConfigObjects)();
|
|
88
88
|
const currentConfig = this.state.settingService.getEnvironmentSetting();
|
|
89
89
|
const passBlockedConfigId = (0, _constants.getPassConfigId)(currentConfig, blockedConfigObjects);
|
|
90
|
-
const blockedActionsFeaturesMaps = await (0, _constants.
|
|
90
|
+
const blockedActionsFeaturesMaps = await (0, _constants.fetchLatestBlockedActionsAndFeatures)(passBlockedConfigId);
|
|
91
91
|
for (const blockedActionsFeaturesMap of blockedActionsFeaturesMaps) {
|
|
92
92
|
const {
|
|
93
93
|
blockedActionsMap,
|
package/cjs/types/swap/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports._SUPPORTED_SWAP_PROVIDERS = exports.SwapStepType = exports.SwapProviderId = exports.SwapFeeType = exports.SwapErrorType = exports.SIMPLE_SWAP_SLIPPAGE = exports.CHAINFLIP_SLIPPAGE = void 0;
|
|
6
|
+
exports._SUPPORTED_SWAP_PROVIDERS = exports.SwapStepType = exports.SwapProviderId = exports.SwapFeeType = exports.SwapErrorType = exports.SIMPLE_SWAP_SLIPPAGE = exports.DynamicSwapType = exports.CHAINFLIP_SLIPPAGE = exports.BridgeStepPosition = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
// core
|
|
@@ -58,6 +58,18 @@ exports.SwapFeeType = SwapFeeType;
|
|
|
58
58
|
SwapFeeType["NETWORK_FEE"] = "NETWORK_FEE";
|
|
59
59
|
SwapFeeType["WALLET_FEE"] = "WALLET_FEE";
|
|
60
60
|
})(SwapFeeType || (exports.SwapFeeType = SwapFeeType = {}));
|
|
61
|
+
let DynamicSwapType;
|
|
62
|
+
exports.DynamicSwapType = DynamicSwapType;
|
|
63
|
+
(function (DynamicSwapType) {
|
|
64
|
+
DynamicSwapType["SWAP"] = "SWAP";
|
|
65
|
+
DynamicSwapType["BRIDGE"] = "BRIDGE";
|
|
66
|
+
})(DynamicSwapType || (exports.DynamicSwapType = DynamicSwapType = {}));
|
|
67
|
+
let BridgeStepPosition;
|
|
68
|
+
exports.BridgeStepPosition = BridgeStepPosition;
|
|
69
|
+
(function (BridgeStepPosition) {
|
|
70
|
+
BridgeStepPosition[BridgeStepPosition["FIRST"] = 0] = "FIRST";
|
|
71
|
+
BridgeStepPosition[BridgeStepPosition["AFTER_SWAP"] = 1] = "AFTER_SWAP";
|
|
72
|
+
})(BridgeStepPosition || (exports.BridgeStepPosition = BridgeStepPosition = {}));
|
|
61
73
|
const CHAINFLIP_SLIPPAGE = 0.02; // Example: 0.01 for 1%
|
|
62
74
|
exports.CHAINFLIP_SLIPPAGE = CHAINFLIP_SLIPPAGE;
|
|
63
75
|
const SIMPLE_SWAP_SLIPPAGE = 0.05;
|
package/cjs/utils/swap.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.swapCustomFormatter = exports.formatNumberString = void 0;
|
|
7
|
+
exports.swapNumberMetadata = exports.swapCustomFormatter = exports.formatNumberString = void 0;
|
|
8
8
|
var _number = require("@subwallet/extension-base/utils/number");
|
|
9
9
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
10
10
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -25,6 +25,10 @@ const NUM_1B = new _bignumber.default(1e9);
|
|
|
25
25
|
const BLIM = new _bignumber.default(1e14);
|
|
26
26
|
const NUM_1M = new _bignumber.default(1e6);
|
|
27
27
|
const NUM_100M = new _bignumber.default(1e8);
|
|
28
|
+
const swapNumberMetadata = {
|
|
29
|
+
minNumberFormat: 4
|
|
30
|
+
};
|
|
31
|
+
exports.swapNumberMetadata = swapNumberMetadata;
|
|
28
32
|
const swapCustomFormatter = (input, metadata) => {
|
|
29
33
|
const minNumberFormat = 2;
|
|
30
34
|
const maxNumberFormat = (metadata === null || metadata === void 0 ? void 0 : metadata.maxNumberFormat) || 6;
|
|
@@ -25,5 +25,5 @@ export interface OSConfig {
|
|
|
25
25
|
declare type BlockedConfigObjects = Record<string, EnvConfig>;
|
|
26
26
|
export declare function fetchBlockedConfigObjects(): Promise<BlockedConfigObjects>;
|
|
27
27
|
export declare function getPassConfigId(currentConfig: EnvConfig, blockedConfigObjects: BlockedConfigObjects): string[];
|
|
28
|
-
export declare function
|
|
28
|
+
export declare function fetchLatestBlockedActionsAndFeatures(ids: string[]): Promise<BlockedActionsFeaturesMap[]>;
|
|
29
29
|
export {};
|
|
@@ -87,7 +87,7 @@ function isPassVersion(versionStr, versionCondition) {
|
|
|
87
87
|
const versionConditionStr = versionCondition.trim();
|
|
88
88
|
return versionStr === versionConditionStr;
|
|
89
89
|
}
|
|
90
|
-
export async function
|
|
90
|
+
export async function fetchLatestBlockedActionsAndFeatures(ids) {
|
|
91
91
|
if (ids.length === 0) {
|
|
92
92
|
return [staticData[StaticKey.BLOCKED_ACTIONS_FEATURES]];
|
|
93
93
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { NotificationActionType } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const fetchLatestRemindNotificationTime: () => Promise<Record<NotificationActionType, number>>;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { fetchStaticData } from '@subwallet/extension-base/utils';
|
|
5
|
-
export const
|
|
5
|
+
export const fetchLatestRemindNotificationTime = async () => {
|
|
6
6
|
return await fetchStaticData('config/remind-notification-time');
|
|
7
7
|
};
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
|
|
3
3
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
4
|
+
import { SwapQuote } from '@subwallet/extension-base/types';
|
|
4
5
|
import { AssetHubPreValidationMetadata, ChainflipPreValidationMetadata, HydradxPreValidationMetadata, SimpleSwapValidationMetadata, SwapErrorType } from '@subwallet/extension-base/types/swap';
|
|
6
|
+
interface RequestValidateSwap {
|
|
7
|
+
chainInfo: _ChainInfo;
|
|
8
|
+
fromToken: _ChainAsset;
|
|
9
|
+
fromTokenBalance: string;
|
|
10
|
+
feeToken: _ChainAsset;
|
|
11
|
+
feeTokenBalance: string;
|
|
12
|
+
feeAmount: string;
|
|
13
|
+
swapAmount: string;
|
|
14
|
+
minSwapAmount?: string;
|
|
15
|
+
}
|
|
5
16
|
export declare function _validateBalanceToSwapOnAssetHub(fromToken: _ChainAsset, feeToken: _ChainAsset, feeTokenChainInfo: _ChainInfo, feeAmount: string, fromTokenBalance: string, feeTokenBalance: string, swapAmount: string, isXcmOk: boolean, minSwap?: string): TransactionError | undefined;
|
|
6
17
|
export declare function _validateBalanceToSwap(fromToken: _ChainAsset, feeToken: _ChainAsset, feeTokenChainInfo: _ChainInfo, feeAmount: string, fromTokenBalance: string, feeTokenBalance: string, swapAmount: string, isXcmOk: boolean, minSwap?: string): TransactionError | undefined;
|
|
7
18
|
export declare function _validateSwapRecipient(destChainInfo: _ChainInfo, recipient: string): TransactionError | undefined;
|
|
@@ -9,3 +20,7 @@ export declare function _getChainflipEarlyValidationError(error: SwapErrorType,
|
|
|
9
20
|
export declare function _getEarlyHydradxValidationError(error: SwapErrorType, metadata: HydradxPreValidationMetadata): SwapError;
|
|
10
21
|
export declare function _getEarlyAssetHubValidationError(error: SwapErrorType, metadata: AssetHubPreValidationMetadata): SwapError;
|
|
11
22
|
export declare function _getSimpleSwapEarlyValidationError(error: SwapErrorType, metadata: SimpleSwapValidationMetadata): SwapError;
|
|
23
|
+
export declare function _validateQuoteV2(selectedQuote: SwapQuote): TransactionError | undefined;
|
|
24
|
+
export declare function _validateBalanceToSwapV2(request: RequestValidateSwap): TransactionError | undefined;
|
|
25
|
+
export declare function _validateSwapRecipientV2(destChainInfo: _ChainInfo, recipient: string | undefined): TransactionError | undefined;
|
|
26
|
+
export {};
|
|
@@ -100,7 +100,7 @@ export function _getChainflipEarlyValidationError(error, metadata) {
|
|
|
100
100
|
case SwapErrorType.UNKNOWN:
|
|
101
101
|
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
102
102
|
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
103
|
-
return new SwapError(error, 'No swap quote found.
|
|
103
|
+
return new SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
104
104
|
default:
|
|
105
105
|
return new SwapError(error);
|
|
106
106
|
}
|
|
@@ -116,7 +116,7 @@ export function _getEarlyHydradxValidationError(error, metadata) {
|
|
|
116
116
|
case SwapErrorType.UNKNOWN:
|
|
117
117
|
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
118
118
|
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
119
|
-
return new SwapError(error, 'No swap quote found.
|
|
119
|
+
return new SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
120
120
|
default:
|
|
121
121
|
return new SwapError(error);
|
|
122
122
|
}
|
|
@@ -130,7 +130,7 @@ export function _getEarlyAssetHubValidationError(error, metadata) {
|
|
|
130
130
|
case SwapErrorType.UNKNOWN:
|
|
131
131
|
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
132
132
|
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
133
|
-
return new SwapError(error, 'No swap quote found.
|
|
133
|
+
return new SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
134
134
|
case SwapErrorType.MAKE_POOL_NOT_ENOUGH_EXISTENTIAL_DEPOSIT:
|
|
135
135
|
return new SwapError(error, 'You swap too much. It make pool not enough existential deposit');
|
|
136
136
|
// TODO: i18n this
|
|
@@ -159,8 +159,64 @@ export function _getSimpleSwapEarlyValidationError(error, metadata) {
|
|
|
159
159
|
case SwapErrorType.UNKNOWN:
|
|
160
160
|
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
161
161
|
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
162
|
-
return new SwapError(error, 'No swap quote found.
|
|
162
|
+
return new SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
163
163
|
default:
|
|
164
164
|
return new SwapError(error);
|
|
165
165
|
}
|
|
166
|
+
}
|
|
167
|
+
export function _validateQuoteV2(selectedQuote) {
|
|
168
|
+
if (!selectedQuote) {
|
|
169
|
+
return new TransactionError(BasicTxErrorType.INTERNAL_ERROR);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Check swapQuote alive
|
|
173
|
+
if (selectedQuote.aliveUntil <= +Date.now()) {
|
|
174
|
+
return new TransactionError(SwapErrorType.QUOTE_TIMEOUT);
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
export function _validateBalanceToSwapV2(request) {
|
|
179
|
+
const {
|
|
180
|
+
chainInfo,
|
|
181
|
+
feeAmount,
|
|
182
|
+
feeToken,
|
|
183
|
+
feeTokenBalance,
|
|
184
|
+
fromToken,
|
|
185
|
+
fromTokenBalance,
|
|
186
|
+
minSwapAmount,
|
|
187
|
+
swapAmount
|
|
188
|
+
} = request;
|
|
189
|
+
const bnFromTokenBalance = BigN(fromTokenBalance);
|
|
190
|
+
if (new BigN(feeTokenBalance).lte(feeAmount)) {
|
|
191
|
+
return new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, `You don't have enough ${feeToken.symbol} (${chainInfo.name}) to pay transaction fee`);
|
|
192
|
+
}
|
|
193
|
+
if (fromToken.slug === feeToken.slug) {
|
|
194
|
+
// todo: need review and refactor
|
|
195
|
+
if (bnFromTokenBalance.lte(BigN(feeAmount).plus(swapAmount))) {
|
|
196
|
+
return new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
if (bnFromTokenBalance.lt(swapAmount)) {
|
|
200
|
+
return new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (minSwapAmount) {
|
|
204
|
+
if (bnFromTokenBalance.lte(minSwapAmount)) {
|
|
205
|
+
const parsedMinSwapValue = formatNumber(minSwapAmount, _getAssetDecimals(fromToken));
|
|
206
|
+
return new TransactionError(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?
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
export function _validateSwapRecipientV2(destChainInfo, recipient) {
|
|
213
|
+
if (!recipient) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
const isEvmAddress = isEthereumAddress(recipient);
|
|
217
|
+
const isEvmDestChain = _isChainEvmCompatible(destChainInfo);
|
|
218
|
+
if (isEvmAddress && !isEvmDestChain || !isEvmAddress && isEvmDestChain) {
|
|
219
|
+
return new TransactionError(SwapErrorType.INVALID_RECIPIENT);
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
166
222
|
}
|
package/core/utils.js
CHANGED
|
@@ -146,7 +146,7 @@ export const _isSufficientToken = async (tokenInfo, substrateApi) => {
|
|
|
146
146
|
queryParams.module = 'assets';
|
|
147
147
|
}
|
|
148
148
|
const metadata = await substrateApi.makeRpcQuery(queryParams);
|
|
149
|
-
return metadata.isSufficient;
|
|
149
|
+
return (metadata === null || metadata === void 0 ? void 0 : metadata.isSufficient) || false;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// todo
|
|
@@ -255,7 +255,6 @@ export default class KoniExtension {
|
|
|
255
255
|
private subscribeBuyTokens;
|
|
256
256
|
private subscribeBuyServices;
|
|
257
257
|
private subscribeSwapPairs;
|
|
258
|
-
private getOptimalSwapProcessOnSelectQuote;
|
|
259
258
|
private handleSwapRequest;
|
|
260
259
|
private handleSwapRequestV2;
|
|
261
260
|
private getLatestSwapQuote;
|
|
@@ -43,7 +43,7 @@ import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setti
|
|
|
43
43
|
import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
44
44
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
45
45
|
import { AccountsStore } from '@subwallet/extension-base/stores';
|
|
46
|
-
import { AccountSignMode, BasicTxErrorType, BasicTxWarningCode, CommonStepType, EarningProcessType, ProcessType, StakingTxErrorType, StepStatus, SwapFeeType,
|
|
46
|
+
import { AccountSignMode, BasicTxErrorType, BasicTxWarningCode, CommonStepType, EarningProcessType, ProcessType, StakingTxErrorType, StepStatus, SwapFeeType, YieldPoolType, YieldStepType } from '@subwallet/extension-base/types';
|
|
47
47
|
import { _analyzeAddress, calculateMaxTransferable, combineAllAccountProxy, createTransactionFromRLP, detectTransferTxType, getAccountSignMode, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, transformAccounts, transformAddresses, uniqueStringArray } from '@subwallet/extension-base/utils';
|
|
48
48
|
import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
49
49
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
@@ -278,7 +278,6 @@ export default class KoniExtension {
|
|
|
278
278
|
const transformedAccounts = Object.values(accountProxies);
|
|
279
279
|
responseData.accounts = transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [combineAllAccountProxy(transformedAccounts), ...transformedAccounts] : [];
|
|
280
280
|
responseData.currentAccountProxy = currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.proxyId;
|
|
281
|
-
console.debug('subscriptionAccountGroups', responseData);
|
|
282
281
|
cb(responseData);
|
|
283
282
|
});
|
|
284
283
|
this.createUnsubscriptionHandle(id, () => {
|
|
@@ -3617,11 +3616,9 @@ export default class KoniExtension {
|
|
|
3617
3616
|
ready = true;
|
|
3618
3617
|
return this.#koniState.swapService.getSwapPairs();
|
|
3619
3618
|
}
|
|
3620
|
-
async getOptimalSwapProcessOnSelectQuote(request) {
|
|
3621
|
-
return this.#koniState.swapService.generateOptimalProcessWithoutPath(request);
|
|
3622
|
-
}
|
|
3623
3619
|
async handleSwapRequest(request) {
|
|
3624
|
-
|
|
3620
|
+
// @ts-ignore
|
|
3621
|
+
return Promise.resolve(null);
|
|
3625
3622
|
}
|
|
3626
3623
|
async handleSwapRequestV2(request) {
|
|
3627
3624
|
return this.#koniState.swapService.handleSwapRequestV2(request);
|
|
@@ -3633,7 +3630,7 @@ export default class KoniExtension {
|
|
|
3633
3630
|
return swapQuoteResponse;
|
|
3634
3631
|
}
|
|
3635
3632
|
async validateSwapProcess(params) {
|
|
3636
|
-
return this.#koniState.swapService.
|
|
3633
|
+
return this.#koniState.swapService.validateSwapProcessV2(params);
|
|
3637
3634
|
}
|
|
3638
3635
|
async handleSwapStep(inputData) {
|
|
3639
3636
|
const {
|
|
@@ -3663,7 +3660,7 @@ export default class KoniExtension {
|
|
|
3663
3660
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
|
|
3664
3661
|
}
|
|
3665
3662
|
const isLastStep = inputData.currentStep + 1 === process.steps.length;
|
|
3666
|
-
const swapValidations = await this.#koniState.swapService.
|
|
3663
|
+
const swapValidations = await this.#koniState.swapService.validateSwapProcessV2({
|
|
3667
3664
|
address,
|
|
3668
3665
|
process,
|
|
3669
3666
|
selectedQuote: quote,
|
|
@@ -3687,9 +3684,9 @@ export default class KoniExtension {
|
|
|
3687
3684
|
status: StepStatus.FAILED
|
|
3688
3685
|
});
|
|
3689
3686
|
}
|
|
3687
|
+
console.log('Error handling process step', e);
|
|
3690
3688
|
throw e;
|
|
3691
3689
|
}
|
|
3692
|
-
console.log('swap data', submitData);
|
|
3693
3690
|
|
|
3694
3691
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
3695
3692
|
const {
|
|
@@ -3701,17 +3698,12 @@ export default class KoniExtension {
|
|
|
3701
3698
|
txChain,
|
|
3702
3699
|
txData
|
|
3703
3700
|
} = submitData;
|
|
3704
|
-
|
|
3705
|
-
// const chosenFeeToken = process.steps.findIndex((step) => step.type === SwapStepType.SET_FEE_TOKEN) > -1;
|
|
3706
|
-
// const allowSkipValidation = [ExtrinsicType.SET_FEE_TOKEN, ExtrinsicType.SWAP].includes(extrinsicType);
|
|
3707
|
-
|
|
3708
3701
|
const eventsHandler = eventEmitter => {
|
|
3709
3702
|
if (onSend) {
|
|
3710
3703
|
eventEmitter.on('send', onSend);
|
|
3711
3704
|
}
|
|
3712
3705
|
};
|
|
3713
3706
|
if (processId) {
|
|
3714
|
-
const _step = process.steps[inputData.currentStep];
|
|
3715
3707
|
if (!this.#koniState.transactionService.checkProcessExist(processId) && step) {
|
|
3716
3708
|
const combineInfo = {
|
|
3717
3709
|
provider: quote.provider,
|
|
@@ -3729,23 +3721,6 @@ export default class KoniExtension {
|
|
|
3729
3721
|
combineInfo,
|
|
3730
3722
|
steps: inputData.process.steps.map((step, index) => {
|
|
3731
3723
|
const fee = inputData.process.totalFee[index];
|
|
3732
|
-
if (step.type === SwapStepType.SWAP) {
|
|
3733
|
-
const metadata = {
|
|
3734
|
-
pair: quote.pair,
|
|
3735
|
-
aliveUntil: quote.aliveUntil,
|
|
3736
|
-
fromAmount: quote.fromAmount,
|
|
3737
|
-
rate: quote.rate,
|
|
3738
|
-
provider: quote.provider,
|
|
3739
|
-
route: quote.route,
|
|
3740
|
-
toAmount: quote.toAmount
|
|
3741
|
-
};
|
|
3742
|
-
return {
|
|
3743
|
-
...step,
|
|
3744
|
-
status: StepStatus.QUEUED,
|
|
3745
|
-
fee,
|
|
3746
|
-
metadata: metadata
|
|
3747
|
-
};
|
|
3748
|
-
}
|
|
3749
3724
|
return {
|
|
3750
3725
|
...step,
|
|
3751
3726
|
fee,
|
|
@@ -3755,34 +3730,6 @@ export default class KoniExtension {
|
|
|
3755
3730
|
status: StepStatus.QUEUED
|
|
3756
3731
|
});
|
|
3757
3732
|
}
|
|
3758
|
-
const isLastStep = inputData.currentStep === process.steps.length - 1;
|
|
3759
|
-
if (isLastStep) {
|
|
3760
|
-
const metadata = {
|
|
3761
|
-
pair: quote.pair,
|
|
3762
|
-
aliveUntil: quote.aliveUntil,
|
|
3763
|
-
fromAmount: quote.fromAmount,
|
|
3764
|
-
rate: quote.rate,
|
|
3765
|
-
provider: quote.provider,
|
|
3766
|
-
route: quote.route,
|
|
3767
|
-
toAmount: quote.toAmount
|
|
3768
|
-
};
|
|
3769
|
-
const step = {
|
|
3770
|
-
..._step,
|
|
3771
|
-
// In case one sign, status already set to prepare before
|
|
3772
|
-
status: process.steps.length > 2 ? StepStatus.PREPARE : StepStatus.QUEUED,
|
|
3773
|
-
fee: process.totalFee[inputData.currentStep],
|
|
3774
|
-
metadata: metadata
|
|
3775
|
-
};
|
|
3776
|
-
const combineInfo = {
|
|
3777
|
-
provider: quote.provider,
|
|
3778
|
-
slippage: inputData.slippage,
|
|
3779
|
-
address,
|
|
3780
|
-
recipient,
|
|
3781
|
-
quote,
|
|
3782
|
-
process
|
|
3783
|
-
};
|
|
3784
|
-
await this.#koniState.transactionService.updateProcessInfo(processId, combineInfo, step);
|
|
3785
|
-
}
|
|
3786
3733
|
}
|
|
3787
3734
|
if (isPermit) {
|
|
3788
3735
|
return await this.#koniState.transactionService.handlePermitTransaction({
|
|
@@ -4014,32 +3961,10 @@ export default class KoniExtension {
|
|
|
4014
3961
|
nextTxType: ExtrinsicType.SWAP
|
|
4015
3962
|
};
|
|
4016
3963
|
submitData = async (step, callback) => {
|
|
4017
|
-
const isLastStep = step === stepNums - 1;
|
|
4018
3964
|
const isPassConfirmation = !callback;
|
|
4019
3965
|
const onSend = callback
|
|
4020
3966
|
// eslint-disable-next-line node/no-callback-literal
|
|
4021
3967
|
? rs => callback(rs) : undefined;
|
|
4022
|
-
const specialCaseForUniswap = data.quote.provider.id === SwapProviderId.UNISWAP && !!data.process.steps.find(step => step.type === SwapStepType.PERMIT);
|
|
4023
|
-
if (stepNums > 2 && isLastStep && !specialCaseForUniswap) {
|
|
4024
|
-
const quote = data.quote;
|
|
4025
|
-
const latestSwapQuote = await this.getLatestSwapQuote({
|
|
4026
|
-
address: data.address,
|
|
4027
|
-
currentQuote: quote.provider,
|
|
4028
|
-
feeToken: quote.feeInfo.selectedFeeToken,
|
|
4029
|
-
recipient: data.recipient,
|
|
4030
|
-
pair: quote.pair,
|
|
4031
|
-
fromAmount: quote.fromAmount,
|
|
4032
|
-
slippage: data.slippage
|
|
4033
|
-
});
|
|
4034
|
-
return this.handleSwapStep({
|
|
4035
|
-
...data,
|
|
4036
|
-
quote: latestSwapQuote.optimalQuote || data.quote,
|
|
4037
|
-
currentStep: step,
|
|
4038
|
-
isPassConfirmation,
|
|
4039
|
-
errorOnTimeOut: true,
|
|
4040
|
-
processId
|
|
4041
|
-
});
|
|
4042
|
-
}
|
|
4043
3968
|
return this.handleSwapStep({
|
|
4044
3969
|
...data,
|
|
4045
3970
|
currentStep: step,
|
|
@@ -4740,8 +4665,6 @@ export default class KoniExtension {
|
|
|
4740
4665
|
/* Swap service */
|
|
4741
4666
|
case 'pri(swapService.subscribePairs)':
|
|
4742
4667
|
return this.subscribeSwapPairs(id, port);
|
|
4743
|
-
case 'pri(swapService.getOptimalProcessOnSelectQuote)':
|
|
4744
|
-
return this.getOptimalSwapProcessOnSelectQuote(request);
|
|
4745
4668
|
case 'pri(swapService.handleSwapRequest)':
|
|
4746
4669
|
return this.handleSwapRequest(request);
|
|
4747
4670
|
case 'pri(swapService.handleSwapRequestV2)':
|