@subwallet/extension-base 1.3.29-1 → 1.3.31-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 +16 -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/paraspell-chain-map.js +13 -0
- package/cjs/constants/remind-notification-time.js +3 -3
- package/cjs/core/logic-validation/swap.js +63 -4
- package/cjs/core/logic-validation/transfer.js +13 -1
- package/cjs/core/substrate/xcm-parser.js +5 -1
- package/cjs/core/utils.js +36 -15
- package/cjs/koni/background/handlers/Extension.js +141 -172
- package/cjs/koni/background/handlers/State.js +8 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +27 -0
- package/cjs/services/balance-service/index.js +9 -0
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +229 -0
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/cjs/services/balance-service/transfer/xcm/index.js +96 -7
- package/cjs/services/balance-service/transfer/xcm/utils.js +213 -0
- package/cjs/services/chain-service/constants.js +2 -4
- package/cjs/services/chain-service/index.js +71 -17
- package/cjs/services/chain-service/utils/patch.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/handlers/special.js +18 -9
- 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/keyring-service/context/handlers/Ledger.js +1 -1
- package/cjs/services/keyring-service/context/state.js +3 -0
- package/cjs/services/migration-service/scripts/DisableZeroBalanceTokens.js +60 -0
- package/cjs/services/migration-service/scripts/EnableChain.js +1 -1
- package/cjs/services/migration-service/scripts/index.js +3 -2
- package/cjs/services/swap-service/handler/asset-hub/handler.js +61 -314
- package/cjs/services/swap-service/handler/base-handler.js +406 -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/services/transaction-service/utils.js +38 -14
- package/cjs/types/swap/index.js +13 -1
- package/cjs/utils/fee/transfer.js +52 -28
- package/cjs/utils/staticData/index.js +7 -2
- package/cjs/utils/swap.js +5 -1
- package/constants/blocked-actions.d.ts +1 -1
- package/constants/blocked-actions.js +1 -1
- package/constants/paraspell-chain-map.d.ts +1 -0
- package/constants/paraspell-chain-map.js +7 -0
- 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/logic-validation/transfer.d.ts +1 -0
- package/core/logic-validation/transfer.js +12 -1
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +4 -1
- package/core/utils.d.ts +2 -2
- package/core/utils.js +36 -15
- package/koni/background/handlers/Extension.d.ts +1 -1
- package/koni/background/handlers/Extension.js +66 -98
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +7 -1
- package/package.json +23 -13
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +2 -1
- package/services/balance-service/helpers/process.js +26 -0
- package/services/balance-service/index.js +11 -2
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +15 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +216 -0
- package/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/services/balance-service/transfer/xcm/index.d.ts +5 -1
- package/services/balance-service/transfer/xcm/index.js +85 -1
- package/services/balance-service/transfer/xcm/utils.d.ts +11 -0
- package/services/balance-service/transfer/xcm/utils.js +208 -0
- package/services/base/types.d.ts +0 -4
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +1 -2
- package/services/chain-service/index.d.ts +9 -2
- package/services/chain-service/index.js +72 -18
- package/services/chain-service/utils/patch.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/handlers/special.js +19 -10
- 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/keyring-service/context/handlers/Ledger.js +1 -1
- package/services/keyring-service/context/state.d.ts +1 -0
- package/services/keyring-service/context/state.js +3 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.d.ts +4 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.js +51 -0
- package/services/migration-service/scripts/EnableChain.js +1 -1
- package/services/migration-service/scripts/index.js +3 -2
- 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 +405 -230
- 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/services/transaction-service/types.d.ts +3 -2
- package/services/transaction-service/utils.d.ts +1 -0
- package/services/transaction-service/utils.js +38 -15
- package/types/balance/transfer.d.ts +1 -0
- 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/transaction/request.d.ts +7 -0
- package/types/yield/actions/join/submit.d.ts +4 -1
- package/types/yield/actions/others.d.ts +2 -0
- package/utils/fee/transfer.d.ts +1 -0
- package/utils/fee/transfer.js +54 -30
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/paraSpellChainMap.json +1 -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,
|
|
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getChainflipExplorerLink = getChainflipExplorerLink;
|
|
7
7
|
exports.getExplorerLink = getExplorerLink;
|
|
8
8
|
exports.getSimpleSwapExplorerLink = getSimpleSwapExplorerLink;
|
|
9
|
+
exports.getTransactionId = getTransactionId;
|
|
9
10
|
exports.parseTransactionData = parseTransactionData;
|
|
10
11
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
11
12
|
var _utils2 = require("@subwallet/extension-base/services/swap-service/utils");
|
|
12
13
|
var _util = require("@polkadot/util");
|
|
14
|
+
var _utilCrypto = require("@polkadot/util-crypto");
|
|
13
15
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
14
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
17
|
|
|
@@ -32,19 +34,7 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
32
34
|
if (explorerLink.includes('3dpscan.io')) {
|
|
33
35
|
return 'account';
|
|
34
36
|
}
|
|
35
|
-
if (explorerLink.includes('
|
|
36
|
-
return 'account';
|
|
37
|
-
}
|
|
38
|
-
if (explorerLink.includes('invarch.statescan.io')) {
|
|
39
|
-
return '#/accounts';
|
|
40
|
-
}
|
|
41
|
-
if (explorerLink.includes('tangle.statescan.io')) {
|
|
42
|
-
return '#/accounts';
|
|
43
|
-
}
|
|
44
|
-
if (explorerLink.includes('laos.statescan.io')) {
|
|
45
|
-
return '#/accounts';
|
|
46
|
-
}
|
|
47
|
-
if (explorerLink.includes('polimec.statescan.io')) {
|
|
37
|
+
if (explorerLink.includes('statescan.io')) {
|
|
48
38
|
return '#/accounts';
|
|
49
39
|
}
|
|
50
40
|
if (explorerLink.includes('explorer.zkverify.io')) {
|
|
@@ -68,15 +58,38 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
68
58
|
if (['aventus', 'deeper_network'].includes(chainInfo.slug)) {
|
|
69
59
|
return 'transaction';
|
|
70
60
|
}
|
|
71
|
-
|
|
61
|
+
const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
|
|
62
|
+
if (explorerLink && explorerLink.includes('statescan.io')) {
|
|
72
63
|
return '#/extrinsics';
|
|
73
64
|
}
|
|
74
65
|
return 'extrinsic';
|
|
75
66
|
}
|
|
67
|
+
function getTransactionId(value) {
|
|
68
|
+
const query = `
|
|
69
|
+
query ExtrinsicQuery {
|
|
70
|
+
extrinsics(where: {hash_eq: ${value}}, limit: 1) {
|
|
71
|
+
id
|
|
72
|
+
}
|
|
73
|
+
}`;
|
|
74
|
+
const apiUrl = 'https://archive-explorer.truth-network.io/graphql';
|
|
75
|
+
return fetch(apiUrl, {
|
|
76
|
+
method: 'POST',
|
|
77
|
+
headers: {
|
|
78
|
+
'Content-Type': 'application/json'
|
|
79
|
+
},
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
query
|
|
82
|
+
})
|
|
83
|
+
}).then(response => response.json()).then(result => result.data.extrinsics[0].id);
|
|
84
|
+
}
|
|
76
85
|
function getExplorerLink(chainInfo, value, type) {
|
|
77
86
|
const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
|
|
78
87
|
if (explorerLink && type === 'account') {
|
|
79
88
|
const route = getBlockExplorerAccountRoute(explorerLink);
|
|
89
|
+
if (chainInfo.slug === 'truth_network') {
|
|
90
|
+
const address = (0, _util.u8aToHex)((0, _utilCrypto.decodeAddress)(value));
|
|
91
|
+
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${address}`;
|
|
92
|
+
}
|
|
80
93
|
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
|
|
81
94
|
}
|
|
82
95
|
if (explorerLink && (0, _util.isHex)((0, _util.hexAddPrefix)(value))) {
|
|
@@ -84,6 +97,17 @@ function getExplorerLink(chainInfo, value, type) {
|
|
|
84
97
|
if (chainInfo.slug === 'tangle') {
|
|
85
98
|
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${value}${route}/${value}`;
|
|
86
99
|
}
|
|
100
|
+
if (chainInfo.slug === 'truth_network') {
|
|
101
|
+
// getTransactionId(value)
|
|
102
|
+
// .then((transactionId) => {
|
|
103
|
+
// return (`${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${transactionId}`);
|
|
104
|
+
// })
|
|
105
|
+
// .catch((err) => {
|
|
106
|
+
// console.error(err);
|
|
107
|
+
// });
|
|
108
|
+
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
87
111
|
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
|
|
88
112
|
}
|
|
89
113
|
return undefined;
|
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;
|
|
@@ -13,6 +13,7 @@ var _smartContract = require("@subwallet/extension-base/services/balance-service
|
|
|
13
13
|
var _token = require("@subwallet/extension-base/services/balance-service/transfer/token");
|
|
14
14
|
var _tonTransfer = require("@subwallet/extension-base/services/balance-service/transfer/ton-transfer");
|
|
15
15
|
var _xcm = require("@subwallet/extension-base/services/balance-service/transfer/xcm");
|
|
16
|
+
var _acrossBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge");
|
|
16
17
|
var _availBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge");
|
|
17
18
|
var _polygonBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge");
|
|
18
19
|
var _posBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge");
|
|
@@ -36,7 +37,8 @@ const detectTransferTxType = (srcToken, srcChain, destChain) => {
|
|
|
36
37
|
const isSnowBridgeEvmTransfer = (0, _utils._isPureEvmChain)(srcChain) && (0, _xcmParser._isSnowBridgeXcm)(srcChain, destChain) && !isAvailBridgeFromEvm;
|
|
37
38
|
const isPolygonBridgeTransfer = (0, _polygonBridge._isPolygonChainBridge)(srcChain.slug, destChain.slug);
|
|
38
39
|
const isPosBridgeTransfer = (0, _posBridge._isPosChainBridge)(srcChain.slug, destChain.slug);
|
|
39
|
-
|
|
40
|
+
const isAcrossBridgeTransfer = (0, _acrossBridge._isAcrossChainBridge)(srcChain.slug, destChain.slug);
|
|
41
|
+
return isAvailBridgeFromEvm || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer || isAcrossBridgeTransfer ? 'evm' : 'substrate';
|
|
40
42
|
} else {
|
|
41
43
|
if ((0, _utils._isChainEvmCompatible)(srcChain) && (0, _utils._isTokenTransferredByEvm)(srcToken)) {
|
|
42
44
|
return 'evm';
|
|
@@ -86,7 +88,8 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
86
88
|
srcChain,
|
|
87
89
|
srcToken,
|
|
88
90
|
substrateApi,
|
|
89
|
-
tonApi
|
|
91
|
+
tonApi,
|
|
92
|
+
value
|
|
90
93
|
} = request;
|
|
91
94
|
const feeChainType = fee.type;
|
|
92
95
|
let estimatedFee;
|
|
@@ -114,7 +117,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
114
117
|
from: address,
|
|
115
118
|
to: recipient,
|
|
116
119
|
transferAll: false,
|
|
117
|
-
value
|
|
120
|
+
value,
|
|
118
121
|
fallbackFee: true
|
|
119
122
|
});
|
|
120
123
|
} else {
|
|
@@ -127,7 +130,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
127
130
|
from: address,
|
|
128
131
|
to: recipient,
|
|
129
132
|
transferAll: false,
|
|
130
|
-
value
|
|
133
|
+
value,
|
|
131
134
|
fallbackFee: true
|
|
132
135
|
});
|
|
133
136
|
}
|
|
@@ -137,19 +140,18 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
137
140
|
from: address,
|
|
138
141
|
to: address,
|
|
139
142
|
networkKey: srcChain.slug,
|
|
140
|
-
value
|
|
143
|
+
value,
|
|
141
144
|
transferAll: false,
|
|
142
145
|
// currently not used
|
|
143
146
|
tonApi
|
|
144
147
|
});
|
|
145
148
|
} else if ((0, _keyring.isCardanoAddress)(address) && (0, _utils._isTokenTransferredByCardano)(srcToken)) {
|
|
146
|
-
const isTransferNativeToken = (0, _utils._isNativeToken)(srcToken);
|
|
147
149
|
[transaction] = await (0, _cardanoTransfer.createCardanoTransaction)({
|
|
148
150
|
tokenInfo: srcToken,
|
|
149
151
|
from: address,
|
|
150
152
|
to: address,
|
|
151
153
|
networkKey: srcChain.slug,
|
|
152
|
-
value
|
|
154
|
+
value,
|
|
153
155
|
cardanoTtlOffset: _consts.DEFAULT_CARDANO_TTL_OFFSET,
|
|
154
156
|
transferAll: false,
|
|
155
157
|
cardanoApi,
|
|
@@ -158,7 +160,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
158
160
|
} else {
|
|
159
161
|
[transaction] = await (0, _token.createSubstrateExtrinsic)({
|
|
160
162
|
transferAll: false,
|
|
161
|
-
value
|
|
163
|
+
value,
|
|
162
164
|
from: address,
|
|
163
165
|
networkKey: srcChain.slug,
|
|
164
166
|
tokenInfo: srcToken,
|
|
@@ -295,10 +297,11 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
295
297
|
nativeToken,
|
|
296
298
|
srcChain,
|
|
297
299
|
srcToken,
|
|
298
|
-
substrateApi
|
|
300
|
+
substrateApi,
|
|
301
|
+
value
|
|
299
302
|
} = request;
|
|
300
303
|
const feeChainType = fee.type;
|
|
301
|
-
let estimatedFee;
|
|
304
|
+
let estimatedFee = '0';
|
|
302
305
|
let feeOptions;
|
|
303
306
|
let maxTransferable;
|
|
304
307
|
let error;
|
|
@@ -307,20 +310,22 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
307
310
|
const isSnowBridgeEvmTransfer = (0, _utils._isPureEvmChain)(srcChain) && (0, _xcmParser._isSnowBridgeXcm)(srcChain, destChain) && !isAvailBridgeFromEvm;
|
|
308
311
|
const isPolygonBridgeTransfer = (0, _polygonBridge._isPolygonChainBridge)(srcChain.slug, destChain.slug);
|
|
309
312
|
const isPosBridgeTransfer = (0, _posBridge._isPosChainBridge)(srcChain.slug, destChain.slug);
|
|
313
|
+
const isAcrossBridgeTransfer = (0, _acrossBridge._isAcrossChainBridge)(srcChain.slug, destChain.slug);
|
|
314
|
+
const isSubstrateXcm = !(isAvailBridgeFromEvm || isAvailBridgeFromAvail || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer || isAcrossBridgeTransfer);
|
|
310
315
|
const fakeAddress = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
|
|
311
316
|
const substrateAddress = fakeAddress; // todo: move this
|
|
312
317
|
const evmAddress = (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(fakeAddress)); // todo: move this
|
|
313
|
-
|
|
318
|
+
const bnFreeBalance = new _bignumber.default(freeBalance.value);
|
|
314
319
|
const recipient = (0, _utils._isChainEvmCompatible)(destChain) ? evmAddress : substrateAddress;
|
|
320
|
+
if (!destToken) {
|
|
321
|
+
throw Error('Destination token is not available');
|
|
322
|
+
}
|
|
315
323
|
try {
|
|
316
|
-
if (!destToken) {
|
|
317
|
-
throw Error('Destination token is not available');
|
|
318
|
-
}
|
|
319
324
|
const params = {
|
|
320
325
|
destinationTokenInfo: destToken,
|
|
321
326
|
originTokenInfo: srcToken,
|
|
322
327
|
// If value is 0, substrate will throw error when estimating fee
|
|
323
|
-
sendingValue:
|
|
328
|
+
sendingValue: value,
|
|
324
329
|
sender: address,
|
|
325
330
|
recipient,
|
|
326
331
|
destinationChain: destChain,
|
|
@@ -334,6 +339,13 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
334
339
|
let funcCreateExtrinsic;
|
|
335
340
|
if (isPosBridgeTransfer || isPolygonBridgeTransfer) {
|
|
336
341
|
funcCreateExtrinsic = _xcm.createPolygonBridgeExtrinsic;
|
|
342
|
+
} else if (isAcrossBridgeTransfer) {
|
|
343
|
+
funcCreateExtrinsic = _xcm.createAcrossBridgeExtrinsic;
|
|
344
|
+
if ((0, _acrossBridge._isAcrossTestnetBridge)(srcChain.slug)) {
|
|
345
|
+
params.sendingValue = (0, _bignumber.default)(0.0037).shiftedBy((0, _utils._getAssetDecimals)(srcToken)).toFixed(0, 1);
|
|
346
|
+
} else {
|
|
347
|
+
params.sendingValue = (0, _bignumber.default)(1).shiftedBy((0, _utils._getAssetDecimals)(srcToken)).toFixed(0, 1);
|
|
348
|
+
}
|
|
337
349
|
} else if (isSnowBridgeEvmTransfer) {
|
|
338
350
|
funcCreateExtrinsic = _xcm.createSnowBridgeExtrinsic;
|
|
339
351
|
} else if (isAvailBridgeFromEvm) {
|
|
@@ -341,9 +353,12 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
341
353
|
} else if (isAvailBridgeFromAvail) {
|
|
342
354
|
funcCreateExtrinsic = _xcm.createAvailBridgeExtrinsicFromAvail;
|
|
343
355
|
} else {
|
|
344
|
-
funcCreateExtrinsic = _xcm.
|
|
356
|
+
funcCreateExtrinsic = _xcm.createXcmExtrinsicV2;
|
|
357
|
+
params.sendingValue = '1';
|
|
345
358
|
}
|
|
346
359
|
const extrinsic = await funcCreateExtrinsic(params);
|
|
360
|
+
|
|
361
|
+
// todo: refactor condition
|
|
347
362
|
if (feeChainType === 'evm') {
|
|
348
363
|
var _tx$gas2;
|
|
349
364
|
// Calculate fee for evm transaction
|
|
@@ -363,12 +378,17 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
363
378
|
};
|
|
364
379
|
} else if (feeChainType === 'substrate') {
|
|
365
380
|
// Calculate fee for substrate transaction
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
381
|
+
if (isSubstrateXcm) {
|
|
382
|
+
const estimatedFeeByDryRun = await (0, _xcm.dryRunXcmExtrinsicV2)(params);
|
|
383
|
+
estimatedFee = estimatedFeeByDryRun.fee || '0';
|
|
384
|
+
} else {
|
|
385
|
+
try {
|
|
386
|
+
var _paymentInfo$partialF2;
|
|
387
|
+
const paymentInfo = await extrinsic.paymentInfo(address);
|
|
388
|
+
estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
|
|
389
|
+
} catch (e) {
|
|
390
|
+
estimatedFee = '0';
|
|
391
|
+
}
|
|
372
392
|
}
|
|
373
393
|
const _feeCustom = feeCustom;
|
|
374
394
|
const tip = (0, _combine.combineSubstrateFee)(fee, feeOption, _feeCustom).tip;
|
|
@@ -408,12 +428,12 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
408
428
|
if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
409
429
|
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(_utils2.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
410
430
|
const estimatedFeeLocal = await (0, _utils2.calculateToAmountByReservePool)(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
411
|
-
maxTransferable =
|
|
431
|
+
maxTransferable = bnFreeBalance.minus(estimatedFeeLocal);
|
|
412
432
|
} else if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
413
433
|
const rate = await (0, _tokenPayFee.getHydrationRate)(address, nativeToken, srcToken);
|
|
414
434
|
if (rate) {
|
|
415
435
|
const estimatedFeeLocal = new _bignumber.default(estimatedFee).multipliedBy(rate).integerValue(_bignumber.default.ROUND_UP).toString();
|
|
416
|
-
maxTransferable =
|
|
436
|
+
maxTransferable = bnFreeBalance.minus(estimatedFeeLocal);
|
|
417
437
|
} else {
|
|
418
438
|
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
419
439
|
}
|
|
@@ -421,16 +441,20 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
421
441
|
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
422
442
|
}
|
|
423
443
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
424
|
-
maxTransferable =
|
|
444
|
+
maxTransferable = bnFreeBalance;
|
|
425
445
|
} else {
|
|
426
446
|
if (!(0, _utils._isNativeToken)(srcToken)) {
|
|
427
|
-
maxTransferable =
|
|
447
|
+
maxTransferable = bnFreeBalance;
|
|
428
448
|
} else {
|
|
429
|
-
maxTransferable = (0, _bignumber.default)(
|
|
449
|
+
maxTransferable = bnFreeBalance.minus((0, _bignumber.default)(estimatedFee).multipliedBy(_constants.XCM_FEE_RATIO));
|
|
430
450
|
}
|
|
431
451
|
}
|
|
452
|
+
if (isAvailBridgeFromAvail) {
|
|
453
|
+
const addedAmount = (0, _bignumber.default)(1).shiftedBy((0, _utils._getAssetDecimals)(srcToken));
|
|
454
|
+
maxTransferable = maxTransferable.minus(addedAmount);
|
|
455
|
+
}
|
|
432
456
|
return {
|
|
433
|
-
maxTransferable: maxTransferable.gt(_utils3.BN_ZERO) ? maxTransferable.toFixed(0)
|
|
457
|
+
maxTransferable: maxTransferable.gt(_utils3.BN_ZERO) ? maxTransferable.toFixed(0) : '0',
|
|
434
458
|
feeOptions: feeOptions,
|
|
435
459
|
feeType: feeChainType,
|
|
436
460
|
id: id,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.termAndCondition = exports.staticData = exports.remindNotificationTime = exports.oldChainPrefix = exports.marketingCampaigns = exports.currencySymbol = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.blockedActionsFeatures = exports.blockedActions = exports.StaticKey = void 0;
|
|
6
|
+
exports.termAndCondition = exports.staticData = exports.remindNotificationTime = exports.paraSpellChainMap = exports.oldChainPrefix = exports.marketingCampaigns = exports.currencySymbol = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.blockedActionsFeatures = exports.blockedActions = exports.StaticKey = void 0;
|
|
7
7
|
var _chainList = require("@subwallet/chain-list");
|
|
8
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
9
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -39,7 +39,10 @@ const blockedActions = require('./blockedActions.json');
|
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
40
40
|
exports.blockedActions = blockedActions;
|
|
41
41
|
const oldChainPrefix = require('./oldChainPrefix.json');
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
42
43
|
exports.oldChainPrefix = oldChainPrefix;
|
|
44
|
+
const paraSpellChainMap = require('./paraSpellChainMap.json');
|
|
45
|
+
exports.paraSpellChainMap = paraSpellChainMap;
|
|
43
46
|
let StaticKey;
|
|
44
47
|
exports.StaticKey = StaticKey;
|
|
45
48
|
(function (StaticKey) {
|
|
@@ -54,6 +57,7 @@ exports.StaticKey = StaticKey;
|
|
|
54
57
|
StaticKey["REMIND_NOTIFICATION_TIME"] = "remind-notification-time";
|
|
55
58
|
StaticKey["BLOCKED_ACTIONS"] = "blocked-actions";
|
|
56
59
|
StaticKey["OLD_CHAIN_PREFIX"] = "old-chain-prefix";
|
|
60
|
+
StaticKey["PARASPELL_CHAIN_MAP"] = "paraspell-chain-map";
|
|
57
61
|
})(StaticKey || (exports.StaticKey = StaticKey = {}));
|
|
58
62
|
const staticData = {
|
|
59
63
|
[StaticKey.CHAINS]: Object.values(_chainList.ChainInfoMap),
|
|
@@ -66,6 +70,7 @@ const staticData = {
|
|
|
66
70
|
[StaticKey.BLOCKED_ACTIONS_FEATURES]: blockedActionsFeatures,
|
|
67
71
|
[StaticKey.REMIND_NOTIFICATION_TIME]: remindNotificationTime,
|
|
68
72
|
[StaticKey.BLOCKED_ACTIONS]: blockedActions,
|
|
69
|
-
[StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix
|
|
73
|
+
[StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix,
|
|
74
|
+
[StaticKey.PARASPELL_CHAIN_MAP]: paraSpellChainMap
|
|
70
75
|
};
|
|
71
76
|
exports.staticData = staticData;
|
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
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fetchParaSpellChainMap(): Promise<Record<string, string>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { fetchStaticData } from '@subwallet/extension-base/utils';
|
|
5
|
+
export async function fetchParaSpellChainMap() {
|
|
6
|
+
return await fetchStaticData('paraspell-chain-map');
|
|
7
|
+
}
|
|
@@ -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>>;
|