@subwallet/extension-base 1.3.78-0 → 1.3.79-1
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 +3 -3
- package/cjs/core/logic-validation/index.js +0 -12
- package/cjs/koni/background/handlers/Extension.js +7 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/utils.js +9 -9
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +13 -13
- package/cjs/services/earning-service/handlers/native-staking/tao.js +16 -10
- package/cjs/services/earning-service/handlers/special.js +9 -2
- package/cjs/services/swap-service/handler/asset-hub/handler.js +7 -4
- package/cjs/services/swap-service/handler/asset-hub/router.js +2 -66
- package/cjs/services/swap-service/handler/base-handler.js +4 -3
- package/cjs/services/swap-service/handler/hydradx-handler.js +9 -5
- package/cjs/services/swap-service/index.js +5 -4
- package/cjs/types/swap/index.js +4 -9
- package/cjs/utils/account/common.js +44 -8
- package/core/logic-validation/index.d.ts +0 -1
- package/core/logic-validation/index.js +0 -1
- package/koni/background/handlers/Extension.d.ts +3 -0
- package/koni/background/handlers/Extension.js +7 -2
- package/package.json +5 -10
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/xcm/utils.js +9 -9
- package/services/earning-service/handlers/native-staking/dtao.js +12 -13
- package/services/earning-service/handlers/native-staking/tao.d.ts +2 -1
- package/services/earning-service/handlers/native-staking/tao.js +15 -10
- package/services/earning-service/handlers/special.js +9 -2
- package/services/swap-service/handler/asset-hub/handler.js +7 -4
- package/services/swap-service/handler/asset-hub/router.d.ts +0 -4
- package/services/swap-service/handler/asset-hub/router.js +1 -64
- package/services/swap-service/handler/base-handler.js +4 -3
- package/services/swap-service/handler/hydradx-handler.js +9 -5
- package/services/swap-service/index.js +5 -4
- package/types/swap/index.d.ts +7 -35
- package/types/swap/index.js +3 -8
- package/types/yield/actions/join/step.d.ts +1 -0
- package/types/yield/actions/join/submit.d.ts +2 -1
- package/utils/account/common.d.ts +22 -1
- package/utils/account/common.js +44 -8
- package/cjs/core/logic-validation/swap.js +0 -235
- package/core/logic-validation/swap.d.ts +0 -26
- package/core/logic-validation/swap.js +0 -219
|
@@ -17,7 +17,7 @@ import { AuthUrls } from '@subwallet/extension-base/services/request-service/typ
|
|
|
17
17
|
import { CrowdloanContributionsResponse } from '@subwallet/extension-base/services/subscan-service/types';
|
|
18
18
|
import { BitcoinTransactionData, SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
|
|
19
19
|
import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
|
|
20
|
-
import { AccountChainType, AccountJson, AccountsWithCurrentAddress, AddressJson, BalanceJson, BalanceType, BaseRequestSign, BuyServiceInfo, BuyTokenInfo, CommonOptimalTransferPath, CurrentAccountInfo, EarningRewardHistoryItem, EarningRewardJson, EarningStatus, HandleSubstrateProxyWrappedTxResponse, HandleYieldStepParams, InternalRequestSign, LeavePoolAdditionalData, NominationPoolInfo, OptimalYieldPath, OptimalYieldPathParams, RequestAccountBatchExportV2, RequestAccountCreateSuriV2, RequestAccountNameValidate, RequestAccountProxyEdit, RequestAccountProxyForget, RequestBatchJsonGetAccountInfo, RequestBatchRestoreV2, RequestBounceableValidate, RequestChangeAllowOneSign, RequestChangeBittensorRootClaimType, RequestChangeTonWalletContractVersion, RequestCheckCrossChainTransfer, RequestCheckPublicAndSecretKey, RequestCheckTransfer, RequestCrossChainTransfer, RequestDeriveCreateMultiple, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestEarlyValidateYield, RequestEarningImpact, 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, SubmitChangeValidatorStaking, SubmitYieldJoinData, SubmitYieldStepData, SubnetYieldPositionInfo, SwapPair, SwapQuoteResponse,
|
|
20
|
+
import { AccountChainType, AccountJson, AccountsWithCurrentAddress, AddressJson, BalanceJson, BalanceType, BaseRequestSign, BuyServiceInfo, BuyTokenInfo, CommonOptimalTransferPath, CurrentAccountInfo, EarningRewardHistoryItem, EarningRewardJson, EarningStatus, HandleSubstrateProxyWrappedTxResponse, HandleYieldStepParams, InternalRequestSign, LeavePoolAdditionalData, NominationPoolInfo, OptimalYieldPath, OptimalYieldPathParams, RequestAccountBatchExportV2, RequestAccountCreateSuriV2, RequestAccountNameValidate, RequestAccountProxyEdit, RequestAccountProxyForget, RequestBatchJsonGetAccountInfo, RequestBatchRestoreV2, RequestBounceableValidate, RequestChangeAllowOneSign, RequestChangeBittensorRootClaimType, RequestChangeTonWalletContractVersion, RequestCheckCrossChainTransfer, RequestCheckPublicAndSecretKey, RequestCheckTransfer, RequestCrossChainTransfer, RequestDeriveCreateMultiple, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestEarlyValidateYield, RequestEarningImpact, 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, SubmitChangeValidatorStaking, SubmitYieldJoinData, SubmitYieldStepData, SubnetYieldPositionInfo, SwapPair, SwapQuoteResponse, SwapRequestResult, SwapRequestV2, SwapSubmitParams, SwapTxData, TokenSpendingApprovalParams, UnlockDotTransactionNft, UnstakingStatus, ValidateSwapProcessParams, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolType, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
21
21
|
import { RequestSubmitSignPsbtTransfer, RequestSubmitTransfer, RequestSubmitTransferWithId, RequestSubscribeTransfer, ResponseSubscribeTransfer, ResponseSubscribeTransferConfirmation } from '@subwallet/extension-base/types/balance/transfer';
|
|
22
22
|
import { RequestClaimBridge } from '@subwallet/extension-base/types/bridge';
|
|
23
23
|
import { ApprovePendingTxRequest, CancelPendingTxRequest, ExecutePendingTxRequest, InitMultisigTxRequest, InitMultisigTxResponse, PrepareMultisigSignRequest, PrepareMultisigSignResponse, RequestGetSignableAccountInfos, ResponseGetSignableAccountInfos } from '@subwallet/extension-base/types/multisig';
|
|
@@ -2117,10 +2117,10 @@ export interface KoniRequestSignatures {
|
|
|
2117
2117
|
'pri(database.setLocalStorage)': [StorageDataInterface, boolean];
|
|
2118
2118
|
'pri(database.getLocalStorage)': [string, string | null];
|
|
2119
2119
|
'pri(swapService.subscribePairs)': [null, SwapPair[], SwapPair[]];
|
|
2120
|
-
'pri(swapService.handleSwapRequest)': [
|
|
2120
|
+
'pri(swapService.handleSwapRequest)': [SwapRequestV2, SwapRequestResult];
|
|
2121
2121
|
'pri(swapService.handleSwapRequestV2)': [SwapRequestV2, SwapRequestResult];
|
|
2122
2122
|
'pri(swapService.handleSwapStep)': [SwapSubmitParams, SWTransactionResponse];
|
|
2123
|
-
'pri(swapService.getLatestQuote)': [
|
|
2123
|
+
'pri(swapService.getLatestQuote)': [SwapRequestV2, SwapQuoteResponse];
|
|
2124
2124
|
'pri(swapService.validateSwapProcess)': [ValidateSwapProcessParams, TransactionError[]];
|
|
2125
2125
|
'pri(inappNotification.subscribeUnreadNotificationCountMap)': [null, Record<string, number>, Record<string, number>];
|
|
2126
2126
|
'pri(inappNotification.markAllReadNotification)': [MarkAllReadParams, null];
|
|
@@ -11,18 +11,6 @@ var _TransactionError = require("@subwallet/extension-base/background/errors/Tra
|
|
|
11
11
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
12
12
|
var _types = require("@subwallet/extension-base/types");
|
|
13
13
|
var _i18next = require("i18next");
|
|
14
|
-
var _swap = require("./swap");
|
|
15
|
-
Object.keys(_swap).forEach(function (key) {
|
|
16
|
-
if (key === "default" || key === "__esModule") return;
|
|
17
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
18
|
-
if (key in exports && exports[key] === _swap[key]) return;
|
|
19
|
-
Object.defineProperty(exports, key, {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return _swap[key];
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
14
|
var _request = require("./request");
|
|
27
15
|
Object.keys(_request).forEach(function (key) {
|
|
28
16
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1008,7 +1008,7 @@ class KoniExtension {
|
|
|
1008
1008
|
this.#koniState.eventService.emit('asset.updateState', params.tokenSlug);
|
|
1009
1009
|
return true;
|
|
1010
1010
|
} catch (e) {
|
|
1011
|
-
console.error(e);
|
|
1011
|
+
console.error('[updateAssetSetting] Error:', e);
|
|
1012
1012
|
return false;
|
|
1013
1013
|
}
|
|
1014
1014
|
}
|
|
@@ -4636,7 +4636,8 @@ class KoniExtension {
|
|
|
4636
4636
|
...this.createPassConfirmationParams(isPassConfirmation),
|
|
4637
4637
|
eventsHandler,
|
|
4638
4638
|
step,
|
|
4639
|
-
xcmFeeDryRun: extrinsicType === _KoniTypes.ExtrinsicType.TRANSFER_XCM ? submitData.xcmStepFee : undefined
|
|
4639
|
+
xcmFeeDryRun: extrinsicType === _KoniTypes.ExtrinsicType.TRANSFER_XCM ? submitData.xcmStepFee : undefined,
|
|
4640
|
+
xcmDestinationFee: submitData.xcmDestinationFee
|
|
4640
4641
|
});
|
|
4641
4642
|
}
|
|
4642
4643
|
async handleYieldLeave(params) {
|
|
@@ -5019,6 +5020,10 @@ class KoniExtension {
|
|
|
5019
5020
|
ready = true;
|
|
5020
5021
|
return this.#koniState.swapService.getSwapPairs();
|
|
5021
5022
|
}
|
|
5023
|
+
|
|
5024
|
+
/**
|
|
5025
|
+
* @deprecated Use function `handleSwapRequestV2` instead.
|
|
5026
|
+
*/
|
|
5022
5027
|
async handleSwapRequest(request) {
|
|
5023
5028
|
// @ts-ignore
|
|
5024
5029
|
return Promise.resolve(null);
|
package/cjs/packageInfo.js
CHANGED
|
@@ -27,7 +27,7 @@ var _bittensorBridge = require("./bittensorBridge");
|
|
|
27
27
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
28
28
|
// SPDX-License-Identifier: Apache-2.0
|
|
29
29
|
|
|
30
|
-
const version = '/
|
|
30
|
+
const version = '/v1';
|
|
31
31
|
const paraSpellApi = {
|
|
32
32
|
buildXcm: `${version}/x-transfer`,
|
|
33
33
|
feeXcm: `${version}/xcm-fee`,
|
|
@@ -107,8 +107,8 @@ async function buildXcm(request) {
|
|
|
107
107
|
}
|
|
108
108
|
const paraSpellChainMap = await (0, _paraspellChainMap.fetchParaSpellChainMap)();
|
|
109
109
|
const bodyData = {
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
sender,
|
|
111
|
+
recipient,
|
|
112
112
|
from: paraSpellChainMap[originChain.slug],
|
|
113
113
|
to: paraSpellChainMap[destinationChain.slug],
|
|
114
114
|
currency: createParaSpellCurrency(paraSpellIdentifyV4, sendingValue),
|
|
@@ -148,8 +148,8 @@ async function dryRunXcm(request) {
|
|
|
148
148
|
throw new Error('Token is not support XCM at this time');
|
|
149
149
|
}
|
|
150
150
|
const bodyData = {
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
sender,
|
|
152
|
+
recipient,
|
|
153
153
|
from: paraSpellChainMap[originChain.slug],
|
|
154
154
|
to: paraSpellChainMap[destinationChain.slug],
|
|
155
155
|
currency: createParaSpellCurrency(paraSpellIdentifyV4, sendingValue),
|
|
@@ -192,8 +192,8 @@ async function dryRunPreviewXcm(request) {
|
|
|
192
192
|
throw new Error('Token is not support XCM at this time');
|
|
193
193
|
}
|
|
194
194
|
const bodyData = {
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
sender,
|
|
196
|
+
recipient,
|
|
197
197
|
from: paraSpellChainMap[originChain.slug],
|
|
198
198
|
to: paraSpellChainMap[destinationChain.slug],
|
|
199
199
|
currency: createParaSpellCurrency(paraSpellIdentifyV4, sendingValue),
|
|
@@ -240,8 +240,8 @@ async function estimateXcmFee(request) {
|
|
|
240
240
|
return undefined;
|
|
241
241
|
}
|
|
242
242
|
const bodyData = {
|
|
243
|
-
|
|
244
|
-
|
|
243
|
+
sender,
|
|
244
|
+
recipient,
|
|
245
245
|
from: paraSpellChainMap[fromChainInfo.slug],
|
|
246
246
|
to: paraSpellChainMap[toChainInfo.slug],
|
|
247
247
|
currency: createParaSpellCurrency(paraSpellIdentifyV4, requestValue),
|
|
@@ -17,20 +17,20 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
17
17
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
18
18
|
// SPDX-License-Identifier: Apache-2.0
|
|
19
19
|
|
|
20
|
-
const getAlphaToTaoRateMap = async substrateApi
|
|
21
|
-
|
|
22
|
-
if (!allSubnets || allSubnets.length === 0) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
20
|
+
const getAlphaToTaoRateMap = async function (substrateApi) {
|
|
21
|
+
let priceScaleDecimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 9;
|
|
25
22
|
const result = Object.create(null);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const PRICE_SCALE = new _bignumber.default(10).pow(priceScaleDecimals);
|
|
24
|
+
const allSubnetPrices = (await substrateApi.api.call.swapRuntimeApi.currentAlphaPriceAll()).toJSON();
|
|
25
|
+
if (allSubnetPrices && allSubnetPrices.length > 0) {
|
|
26
|
+
for (const subnetPrice of allSubnetPrices) {
|
|
27
|
+
const netuid = subnetPrice === null || subnetPrice === void 0 ? void 0 : subnetPrice.netuid;
|
|
28
|
+
if (netuid === undefined) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const rawPrice = subnetPrice !== null && subnetPrice !== void 0 && subnetPrice.price ? new _bignumber.default(subnetPrice.price) : new _bignumber.default(0);
|
|
32
|
+
result[netuid] = netuid === 0 ? '1' : rawPrice.dividedBy(PRICE_SCALE).toFixed();
|
|
30
33
|
}
|
|
31
|
-
const taoIn = subnet !== null && subnet !== void 0 && subnet.taoIn ? new _bignumber.default(subnet.taoIn) : new _bignumber.default(0);
|
|
32
|
-
const alphaIn = subnet !== null && subnet !== void 0 && subnet.alphaIn ? new _bignumber.default(subnet.alphaIn) : new _bignumber.default(0);
|
|
33
|
-
result[netuid] = netuid === 0 || alphaIn.lte(0) ? '1' : taoIn.dividedBy(alphaIn).toString();
|
|
34
34
|
}
|
|
35
35
|
return result;
|
|
36
36
|
};
|
|
@@ -213,7 +213,7 @@ class SubnetTaoStakingPoolHandler extends _tao.default {
|
|
|
213
213
|
const getPoolPosition = async () => {
|
|
214
214
|
const rawDelegateStateInfos = await substrateApi.api.call.stakeInfoRuntimeApi.getStakeInfoForColdkeys(useAddresses);
|
|
215
215
|
const delegateStateInfos = rawDelegateStateInfos.toPrimitive();
|
|
216
|
-
const alphaToTaoRateMap = await getAlphaToTaoRateMap(this.substrateApi);
|
|
216
|
+
const alphaToTaoRateMap = await getAlphaToTaoRateMap(this.substrateApi, this.getAlphaPriceScaleDecimals());
|
|
217
217
|
if (!delegateStateInfos || delegateStateInfos.length === 0) {
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
@@ -122,14 +122,17 @@ class BittensorCache {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
exports.BittensorCache = BittensorCache;
|
|
125
|
-
const getAlphaToTaoRate = async (substrateApi, netuid)
|
|
126
|
-
|
|
127
|
-
if (
|
|
125
|
+
const getAlphaToTaoRate = async function (substrateApi, netuid) {
|
|
126
|
+
let priceScaleDecimals = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 9;
|
|
127
|
+
if (netuid === 0) {
|
|
128
128
|
return '1';
|
|
129
129
|
}
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
|
|
130
|
+
const [rawSubnetPrice, rawRootPrice] = await Promise.all([substrateApi.api.call.swapRuntimeApi.currentAlphaPrice(netuid), substrateApi.api.call.swapRuntimeApi.currentAlphaPrice(0)]);
|
|
131
|
+
const subnetPrice = new _bignumber.default(rawSubnetPrice.toString());
|
|
132
|
+
const defaultScale = new _bignumber.default(10).pow(priceScaleDecimals);
|
|
133
|
+
const rootPrice = new _bignumber.default(rawRootPrice.toString());
|
|
134
|
+
const priceScale = rootPrice.lte(0) ? defaultScale : rootPrice;
|
|
135
|
+
return subnetPrice.lte(0) ? '0' : subnetPrice.dividedBy(priceScale).toFixed();
|
|
133
136
|
};
|
|
134
137
|
exports.getAlphaToTaoRate = getAlphaToTaoRate;
|
|
135
138
|
class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
@@ -142,6 +145,9 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
142
145
|
claimReward: false,
|
|
143
146
|
changeValidator: true
|
|
144
147
|
};
|
|
148
|
+
getAlphaPriceScaleDecimals() {
|
|
149
|
+
return (0, _utils2._getAssetDecimals)(this.nativeToken);
|
|
150
|
+
}
|
|
145
151
|
async getMinBond(netuid) {
|
|
146
152
|
var _cachedPool$metadata2, _cachedPool$statistic, _cachedPool$statistic2, _onlinePool$metadata2, _onlinePool$statistic, _onlinePool$statistic2;
|
|
147
153
|
// @ts-ignore
|
|
@@ -483,7 +489,7 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
483
489
|
const hotkey = selectedValidatorInfo.address;
|
|
484
490
|
const netuid = (_subnetData$netuid = subnetData === null || subnetData === void 0 ? void 0 : subnetData.netuid) !== null && _subnetData$netuid !== void 0 ? _subnetData$netuid : 0;
|
|
485
491
|
const slippage = (_subnetData$slippage = subnetData === null || subnetData === void 0 ? void 0 : subnetData.slippage) !== null && _subnetData$slippage !== void 0 ? _subnetData$slippage : DEFAULT_BITTENSOR_SLIPPAGE;
|
|
486
|
-
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid));
|
|
492
|
+
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid, this.getAlphaPriceScaleDecimals()));
|
|
487
493
|
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** (0, _utils2._getAssetDecimals)(this.nativeToken)).multipliedBy(1 + slippage);
|
|
488
494
|
const BNlimitPrice = new _bignumber.default(limitPrice.integerValue(_bignumber.default.ROUND_CEIL).toFixed());
|
|
489
495
|
const extrinsic = chainApi.api.tx.subtensorModule.addStakeLimit(hotkey, netuid, binaryAmount.toFixed(), BNlimitPrice.toFixed(), false);
|
|
@@ -527,7 +533,7 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
527
533
|
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS));
|
|
528
534
|
}
|
|
529
535
|
const binaryAmount = new _bignumber.default(amount);
|
|
530
|
-
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid));
|
|
536
|
+
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid, this.getAlphaPriceScaleDecimals()));
|
|
531
537
|
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** (0, _utils2._getAssetDecimals)(this.nativeToken)).multipliedBy(1 - slippage);
|
|
532
538
|
const BNlimitPrice = new _bignumber.default(limitPrice.integerValue(_bignumber.default.ROUND_CEIL).toFixed());
|
|
533
539
|
const extrinsic = apiPromise.api.tx.subtensorModule.removeStakeLimit(selectedTarget, netuid, binaryAmount.toFixed(), BNlimitPrice.toFixed(), false);
|
|
@@ -543,7 +549,7 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
543
549
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS)];
|
|
544
550
|
}
|
|
545
551
|
const netuid = (_poolInfo$metadata$su = poolInfo.metadata.subnetData) === null || _poolInfo$metadata$su === void 0 ? void 0 : _poolInfo$metadata$su.netuid;
|
|
546
|
-
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid || 0));
|
|
552
|
+
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid || 0, this.getAlphaPriceScaleDecimals()));
|
|
547
553
|
const minDelegatorStake = await this.getMinBond(netuid);
|
|
548
554
|
const minUnstake = minDelegatorStake.dividedBy(alphaToTaoPrice);
|
|
549
555
|
if (new _bignumber.default(amount).lt(minUnstake)) {
|
|
@@ -583,7 +589,7 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
583
589
|
if (originValidator === destValidator) {
|
|
584
590
|
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, (0, _i18next.t)('bg.EARNING.services.service.earning.nativeStaking.tao.fromValidatorSameAsTo')));
|
|
585
591
|
}
|
|
586
|
-
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid));
|
|
592
|
+
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid, this.getAlphaPriceScaleDecimals()));
|
|
587
593
|
const bnMinStake = await this.getMinBond(netuid);
|
|
588
594
|
const minUnstake = bnMinStake.dividedBy(alphaToTaoPrice);
|
|
589
595
|
const formattedMinUnstake = minUnstake.dividedBy(1000000).integerValue(_bignumber.default.ROUND_CEIL).dividedBy(1000);
|
|
@@ -255,6 +255,7 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
255
255
|
}
|
|
256
256
|
const metadata = {
|
|
257
257
|
sendingValue,
|
|
258
|
+
xcmDestinationFee,
|
|
258
259
|
originTokenInfo: altInputTokenInfo,
|
|
259
260
|
destinationTokenInfo: inputTokenInfo
|
|
260
261
|
};
|
|
@@ -466,7 +467,8 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
466
467
|
const {
|
|
467
468
|
destinationTokenInfo,
|
|
468
469
|
originTokenInfo,
|
|
469
|
-
sendingValue
|
|
470
|
+
sendingValue,
|
|
471
|
+
xcmDestinationFee
|
|
470
472
|
} = metadata;
|
|
471
473
|
const originChainInfo = this.state.getChainInfo(originTokenInfo.originChain);
|
|
472
474
|
const originTokenSlug = (0, _utils3._getChainNativeTokenSlug)(originChainInfo);
|
|
@@ -504,7 +506,12 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
504
506
|
txData: xcmData,
|
|
505
507
|
transferNativeAmount: sendingValue,
|
|
506
508
|
chainType: _KoniTypes.ChainType.SUBSTRATE,
|
|
507
|
-
xcmStepFee
|
|
509
|
+
xcmStepFee,
|
|
510
|
+
xcmDestinationFee: xcmDestinationFee ? {
|
|
511
|
+
decimals: (0, _utils3._getAssetDecimals)(destinationTokenInfo),
|
|
512
|
+
symbol: (0, _utils3._getAssetSymbol)(destinationTokenInfo),
|
|
513
|
+
value: xcmDestinationFee
|
|
514
|
+
} : undefined
|
|
508
515
|
};
|
|
509
516
|
}
|
|
510
517
|
handleYieldJoin(data, path, currentStep) {
|
|
@@ -71,7 +71,10 @@ class AssetHubSwapHandler {
|
|
|
71
71
|
const {
|
|
72
72
|
path,
|
|
73
73
|
request: {
|
|
74
|
-
|
|
74
|
+
address,
|
|
75
|
+
alternativeAddress,
|
|
76
|
+
fromAmount,
|
|
77
|
+
recipient
|
|
75
78
|
},
|
|
76
79
|
selectedQuote
|
|
77
80
|
} = params;
|
|
@@ -93,12 +96,12 @@ class AssetHubSwapHandler {
|
|
|
93
96
|
const needModifyData = swapXcm || xcmSwapXcm;
|
|
94
97
|
let bnSendingValue = (0, _bignumber.default)(fromAmount);
|
|
95
98
|
let bnExpectedReceive = (0, _bignumber.default)(selectedQuote.toAmount);
|
|
96
|
-
const sender = (0, _utils3._reformatAddressWithChain)(
|
|
97
|
-
let receiver = (0, _utils3._reformatAddressWithChain)(
|
|
99
|
+
const sender = (0, _utils3._reformatAddressWithChain)(address, originChain, alternativeAddress);
|
|
100
|
+
let receiver = (0, _utils3._reformatAddressWithChain)(recipient || address, destinationChain);
|
|
98
101
|
if (needModifyData) {
|
|
99
102
|
bnSendingValue = bnSendingValue.multipliedBy(_utils2.DEFAULT_EXCESS_AMOUNT_WEIGHT);
|
|
100
103
|
bnExpectedReceive = bnExpectedReceive.multipliedBy(_utils2.DEFAULT_EXCESS_AMOUNT_WEIGHT);
|
|
101
|
-
receiver = (0, _utils3._reformatAddressWithChain)(
|
|
104
|
+
receiver = (0, _utils3._reformatAddressWithChain)(address, destinationChain, alternativeAddress);
|
|
102
105
|
}
|
|
103
106
|
const submitStep = {
|
|
104
107
|
name: 'Swap',
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.AssetHubRouter = void 0;
|
|
8
|
-
var _utils = require("@subwallet/extension-base/services/
|
|
9
|
-
var _utils2 = require("@subwallet/extension-base/services/swap-service/handler/asset-hub/utils");
|
|
10
|
-
var _swap = require("@subwallet/extension-base/types/swap");
|
|
11
|
-
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
7
|
+
var _utils = require("@subwallet/extension-base/services/swap-service/handler/asset-hub/utils");
|
|
12
8
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
13
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
10
|
|
|
@@ -23,70 +19,10 @@ class AssetHubRouter {
|
|
|
23
19
|
get nativeToken() {
|
|
24
20
|
return this.chainService.getNativeTokenInfo(this.chain);
|
|
25
21
|
}
|
|
26
|
-
buildPath(pair) {
|
|
27
|
-
// const nativeToken = this.nativeToken;
|
|
28
|
-
// const nativeTokenSlug = nativeToken.slug;
|
|
29
|
-
|
|
30
|
-
const assetFrom = this.chainService.getAssetBySlug(pair.from);
|
|
31
|
-
const assetTo = this.chainService.getAssetBySlug(pair.to);
|
|
32
|
-
return [assetFrom, assetTo];
|
|
33
|
-
// if (pair.from === nativeTokenSlug || pair.to === nativeTokenSlug) {
|
|
34
|
-
// return [assetFrom, assetTo];
|
|
35
|
-
// } else {
|
|
36
|
-
// return [assetFrom, nativeToken, assetTo];
|
|
37
|
-
// }
|
|
38
|
-
}
|
|
39
|
-
async earlyValidateSwapValidation(request) {
|
|
40
|
-
const substrateApi = await this.substrateApi.isReady;
|
|
41
|
-
const paths = this.buildPath(request.pair);
|
|
42
|
-
const api = await substrateApi.api.isReady;
|
|
43
|
-
const amount = request.fromAmount;
|
|
44
|
-
const reserves = await (0, _utils2.getReserveForPath)(api, paths);
|
|
45
|
-
const amounts = (0, _utils2.estimateTokensForPath)(amount, reserves);
|
|
46
|
-
const marketRate = (0, _utils2.estimateRateForPath)(reserves);
|
|
47
|
-
const marketRateAfter = (0, _utils2.estimateRateAfterForPath)(amount, reserves);
|
|
48
|
-
const priceImpactPct = (0, _utils2.estimatePriceImpactPct)(marketRate, marketRateAfter);
|
|
49
|
-
const errors = [];
|
|
50
|
-
|
|
51
|
-
// Check liquidity
|
|
52
|
-
const liquidityError = (0, _utils2.checkLiquidityForPath)(amounts, reserves);
|
|
53
|
-
if (liquidityError) {
|
|
54
|
-
errors.push(liquidityError);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Check amount token in pool after swap
|
|
58
|
-
const minAmounts = paths.map(asset => (0, _utils._getTokenMinAmount)(asset));
|
|
59
|
-
const minAmountAfterSwapError = (0, _utils2.checkMinAmountForPath)(reserves, amounts, minAmounts);
|
|
60
|
-
if (minAmountAfterSwapError) {
|
|
61
|
-
errors.push(minAmountAfterSwapError);
|
|
62
|
-
}
|
|
63
|
-
const bnAmount = new _bignumber.default(request.fromAmount);
|
|
64
|
-
if (bnAmount.lte(0)) {
|
|
65
|
-
errors.push(_swap.SwapErrorType.AMOUNT_CANNOT_BE_ZERO);
|
|
66
|
-
}
|
|
67
|
-
const metadata = {
|
|
68
|
-
chain: this.chainService.getChainInfoByKey(this.chain),
|
|
69
|
-
toAmount: amounts[amounts.length - 1],
|
|
70
|
-
quoteRate: marketRate,
|
|
71
|
-
priceImpactPct: priceImpactPct
|
|
72
|
-
};
|
|
73
|
-
return {
|
|
74
|
-
error: errors[0],
|
|
75
|
-
metadata
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
async estimateAmountOut(pair, amountIn) {
|
|
79
|
-
const substrateApi = await this.substrateApi.isReady;
|
|
80
|
-
const paths = this.buildPath(pair);
|
|
81
|
-
const api = await substrateApi.api.isReady;
|
|
82
|
-
const reserves = await (0, _utils2.getReserveForPath)(api, paths);
|
|
83
|
-
const amounts = (0, _utils2.estimateTokensForPath)(amountIn, reserves);
|
|
84
|
-
return amounts[amounts.length - 1];
|
|
85
|
-
}
|
|
86
22
|
async buildSwapExtrinsic(path, recipient, amountIn, amountOutMin) {
|
|
87
23
|
const substrateApi = await this.substrateApi.isReady;
|
|
88
24
|
const api = await substrateApi.api.isReady;
|
|
89
|
-
return (0,
|
|
25
|
+
return (0, _utils.buildSwapExtrinsic)(api, path, recipient, amountIn, amountOutMin);
|
|
90
26
|
}
|
|
91
27
|
}
|
|
92
28
|
exports.AssetHubRouter = AssetHubRouter;
|
|
@@ -79,6 +79,7 @@ class SwapBaseHandler {
|
|
|
79
79
|
path,
|
|
80
80
|
request: {
|
|
81
81
|
address,
|
|
82
|
+
alternativeAddress,
|
|
82
83
|
fromAmount,
|
|
83
84
|
recipient
|
|
84
85
|
},
|
|
@@ -102,12 +103,12 @@ class SwapBaseHandler {
|
|
|
102
103
|
throw Error('Token or chain not found');
|
|
103
104
|
}
|
|
104
105
|
let recipientAddress;
|
|
105
|
-
const senderAddress = (0, _utils5._reformatAddressWithChain)(address, fromChainInfo);
|
|
106
|
+
const senderAddress = (0, _utils5._reformatAddressWithChain)(address, fromChainInfo, alternativeAddress);
|
|
106
107
|
if (stepIndex === 0) {
|
|
107
|
-
recipientAddress = (0, _utils5._reformatAddressWithChain)(address, toChainInfo);
|
|
108
|
+
recipientAddress = (0, _utils5._reformatAddressWithChain)(address, toChainInfo, alternativeAddress);
|
|
108
109
|
} else {
|
|
109
110
|
// bridge after swap
|
|
110
|
-
recipientAddress = (0, _utils5._reformatAddressWithChain)(recipient || address, toChainInfo);
|
|
111
|
+
recipientAddress = (0, _utils5._reformatAddressWithChain)(recipient || address, toChainInfo, alternativeAddress);
|
|
111
112
|
}
|
|
112
113
|
if (!(0, _xcmParser._isXcmWithinSameConsensus)(fromChainInfo, toChainInfo) || (0, _xcmParser._isSnowBridgeXcm)(fromChainInfo, toChainInfo) || (0, _xcmParser._isAcrossBridgeXcm)(fromChainInfo, toChainInfo)) {
|
|
113
114
|
return undefined;
|
|
@@ -116,7 +116,11 @@ class HydradxHandler {
|
|
|
116
116
|
const {
|
|
117
117
|
path,
|
|
118
118
|
request: {
|
|
119
|
-
|
|
119
|
+
address,
|
|
120
|
+
alternativeAddress,
|
|
121
|
+
fromAmount,
|
|
122
|
+
recipient,
|
|
123
|
+
slippage
|
|
120
124
|
},
|
|
121
125
|
selectedQuote
|
|
122
126
|
} = params;
|
|
@@ -135,8 +139,8 @@ class HydradxHandler {
|
|
|
135
139
|
const destinationTokenInfo = this.chainService.getAssetBySlug(swapPairInfo.to);
|
|
136
140
|
const originChain = this.chainService.getChainInfoByKey(originTokenInfo.originChain);
|
|
137
141
|
const destinationChain = this.chainService.getChainInfoByKey(destinationTokenInfo.originChain);
|
|
138
|
-
const sender = (0, _utils3._reformatAddressWithChain)(
|
|
139
|
-
let receiver = (0, _utils3._reformatAddressWithChain)(
|
|
142
|
+
const sender = (0, _utils3._reformatAddressWithChain)(address, originChain, alternativeAddress);
|
|
143
|
+
let receiver = (0, _utils3._reformatAddressWithChain)(recipient || address, destinationChain);
|
|
140
144
|
const actionList = JSON.stringify(path.map(step => step.action));
|
|
141
145
|
const xcmSwapXcm = actionList === JSON.stringify([_types.DynamicSwapType.BRIDGE, _types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
142
146
|
const swapXcm = actionList === JSON.stringify([_types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
@@ -160,7 +164,7 @@ class HydradxHandler {
|
|
|
160
164
|
slug: swapPairInfo.slug
|
|
161
165
|
},
|
|
162
166
|
fromAmount: bnSendingValue.toFixed(0, 1),
|
|
163
|
-
slippage:
|
|
167
|
+
slippage: slippage
|
|
164
168
|
});
|
|
165
169
|
} catch (error) {
|
|
166
170
|
throw new Error(`Failed to fetch swap quote: ${error.message}`);
|
|
@@ -171,7 +175,7 @@ class HydradxHandler {
|
|
|
171
175
|
}
|
|
172
176
|
const overrideQuote = quoteAskResponse.quote;
|
|
173
177
|
txHex = overrideQuote.metadata;
|
|
174
|
-
receiver = (0, _utils3._reformatAddressWithChain)(
|
|
178
|
+
receiver = (0, _utils3._reformatAddressWithChain)(address, destinationChain, alternativeAddress);
|
|
175
179
|
}
|
|
176
180
|
if (!txHex || !(0, _util.isHex)(txHex)) {
|
|
177
181
|
return Promise.resolve(undefined);
|
|
@@ -110,8 +110,7 @@ class SwapService {
|
|
|
110
110
|
if (!params.selectedQuote) {
|
|
111
111
|
return this.getDefaultProcessV2(params);
|
|
112
112
|
} else {
|
|
113
|
-
|
|
114
|
-
const providerId = ((_params$request$curre = params.request.currentQuote) === null || _params$request$curre === void 0 ? void 0 : _params$request$curre.id) || params.selectedQuote.provider.id;
|
|
113
|
+
const providerId = params.selectedQuote.provider.id;
|
|
115
114
|
const handler = this.handlers[providerId];
|
|
116
115
|
if (handler) {
|
|
117
116
|
// todo: handle error response from generateOptimalProcess
|
|
@@ -136,6 +135,8 @@ class SwapService {
|
|
|
136
135
|
console.group('Swap Logger');
|
|
137
136
|
console.log('path', path);
|
|
138
137
|
console.log('swapQuoteResponse', swapQuoteResponse);
|
|
138
|
+
|
|
139
|
+
// Just to log routing type for Uniswap Quote
|
|
139
140
|
if (swapQuoteResponse.optimalQuote && swapQuoteResponse.optimalQuote.metadata) {
|
|
140
141
|
const routing = swapQuoteResponse.optimalQuote.metadata.routing;
|
|
141
142
|
if (routing) {
|
|
@@ -154,7 +155,7 @@ class SwapService {
|
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
// override fee for quote because some cases need estimate network fee on Extension (i.e. Optimex)
|
|
157
|
-
if (swapQuoteResponse.optimalQuote) {
|
|
158
|
+
if (swapQuoteResponse.optimalQuote && [_swap.SwapProviderId.OPTIMEX, _swap.SwapProviderId.OPTIMEX_TESTNET].includes(swapQuoteResponse.optimalQuote.provider.id)) {
|
|
158
159
|
const swapIndex = optimalProcess.steps.findIndex(step => step.type === _swap.SwapStepType.SWAP);
|
|
159
160
|
swapQuoteResponse.optimalQuote.feeInfo.feeComponent = optimalProcess.totalFee[swapIndex].feeComponent;
|
|
160
161
|
}
|
|
@@ -197,7 +198,7 @@ class SwapService {
|
|
|
197
198
|
const swapAction = path.find(step => step.action === _types2.DynamicSwapType.SWAP);
|
|
198
199
|
const directSwapRequest = swapAction ? {
|
|
199
200
|
...request,
|
|
200
|
-
address: (0, _utils3._reformatAddressWithChain)(request.address, this.chainService.getChainInfoByKey((0, _utils._getAssetOriginChain)(this.chainService.getAssetBySlug(swapAction.pair.from)))),
|
|
201
|
+
address: (0, _utils3._reformatAddressWithChain)(request.address, this.chainService.getChainInfoByKey((0, _utils._getAssetOriginChain)(this.chainService.getAssetBySlug(swapAction.pair.from))), request.alternativeAddress),
|
|
201
202
|
pair: swapAction.pair
|
|
202
203
|
} : undefined;
|
|
203
204
|
if (!directSwapRequest) {
|
package/cjs/types/swap/index.js
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
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.DynamicSwapType = exports.CHAINFLIP_SLIPPAGE =
|
|
6
|
+
exports._SUPPORTED_SWAP_PROVIDERS = exports.SwapStepType = exports.SwapProviderId = exports.SwapFeeType = exports.SwapErrorType = exports.SIMPLE_SWAP_SLIPPAGE = exports.DynamicSwapType = exports.CHAINFLIP_SLIPPAGE = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
// core
|
|
10
9
|
let SwapErrorType;
|
|
11
10
|
exports.SwapErrorType = SwapErrorType;
|
|
12
11
|
(function (SwapErrorType) {
|
|
@@ -50,7 +49,6 @@ exports.SwapProviderId = SwapProviderId;
|
|
|
50
49
|
})(SwapProviderId || (exports.SwapProviderId = SwapProviderId = {}));
|
|
51
50
|
const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET, SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB, SwapProviderId.SIMPLE_SWAP, SwapProviderId.UNISWAP, SwapProviderId.KYBER, SwapProviderId.OPTIMEX, SwapProviderId.OPTIMEX_TESTNET, SwapProviderId.BITTENSOR, SwapProviderId.BITTENSOR_TESTNET];
|
|
52
51
|
exports._SUPPORTED_SWAP_PROVIDERS = _SUPPORTED_SWAP_PROVIDERS;
|
|
53
|
-
// process handling
|
|
54
52
|
let SwapFeeType;
|
|
55
53
|
exports.SwapFeeType = SwapFeeType;
|
|
56
54
|
(function (SwapFeeType) {
|
|
@@ -59,18 +57,15 @@ exports.SwapFeeType = SwapFeeType;
|
|
|
59
57
|
SwapFeeType["WALLET_FEE"] = "WALLET_FEE";
|
|
60
58
|
})(SwapFeeType || (exports.SwapFeeType = SwapFeeType = {})); // todo: will be more
|
|
61
59
|
// parameters & responses
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use interface `SwapRequestV2` instead.
|
|
62
|
+
*/
|
|
62
63
|
let DynamicSwapType;
|
|
63
64
|
exports.DynamicSwapType = DynamicSwapType;
|
|
64
65
|
(function (DynamicSwapType) {
|
|
65
66
|
DynamicSwapType["SWAP"] = "SWAP";
|
|
66
67
|
DynamicSwapType["BRIDGE"] = "BRIDGE";
|
|
67
68
|
})(DynamicSwapType || (exports.DynamicSwapType = DynamicSwapType = {}));
|
|
68
|
-
let BridgeStepPosition;
|
|
69
|
-
exports.BridgeStepPosition = BridgeStepPosition;
|
|
70
|
-
(function (BridgeStepPosition) {
|
|
71
|
-
BridgeStepPosition[BridgeStepPosition["FIRST"] = 0] = "FIRST";
|
|
72
|
-
BridgeStepPosition[BridgeStepPosition["AFTER_SWAP"] = 1] = "AFTER_SWAP";
|
|
73
|
-
})(BridgeStepPosition || (exports.BridgeStepPosition = BridgeStepPosition = {}));
|
|
74
69
|
const CHAINFLIP_SLIPPAGE = 0.02; // Example: 0.01 for 1%
|
|
75
70
|
exports.CHAINFLIP_SLIPPAGE = CHAINFLIP_SLIPPAGE;
|
|
76
71
|
const SIMPLE_SWAP_SLIPPAGE = 0.05;
|
|
@@ -54,17 +54,53 @@ function reformatAddress(address) {
|
|
|
54
54
|
return address;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @private
|
|
60
|
+
* Reformats a wallet address based on the provided chain information.
|
|
61
|
+
*
|
|
62
|
+
* This function checks the chain type (Substrate, TON, Cardano, or others)
|
|
63
|
+
* and applies the corresponding formatting logic:
|
|
64
|
+
* 1. **Substrate**: Reformats the Substrate address using the chain's specific prefix.
|
|
65
|
+
* If the current `address` is an EVM address, it attempts to use the `alternativeAddress`
|
|
66
|
+
* (which is currently **always** expected to be the Substrate address) for Substrate
|
|
67
|
+
* formatting, as direct EVM-to-Substrate reformatting is not possible here.
|
|
68
|
+
* 2. **TON/Cardano**: Uses a simple prefix logic based on whether the chain is a testnet or a mainnet.
|
|
69
|
+
* 3. **Default (EVM/Others)**: Returns the original address without reformatting.
|
|
70
|
+
*
|
|
71
|
+
* @param address The current wallet address string.
|
|
72
|
+
* @param chainInfo An object containing chain details (e.g., chain type, testnet status, prefix).
|
|
73
|
+
* @param alternativeAddress An optional alternative address, which is currently expected to be the Substrate
|
|
74
|
+
* address associated with the account. It is used as a fallback for Substrate formatting when the main `address` is EVM.
|
|
75
|
+
* @returns The reformatted wallet address, or the original address if no reformatting is needed or possible.
|
|
76
|
+
*
|
|
77
|
+
* @todo This function currently lacks logic to reformat a Substrate address into an EVM address format.
|
|
78
|
+
*/
|
|
79
|
+
const _reformatAddressWithChain = (address, chainInfo, alternativeAddress) => {
|
|
58
80
|
const chainType = (0, _utils._chainInfoToAccountChainType)(chainInfo);
|
|
59
81
|
if (chainType === _types.AccountChainType.SUBSTRATE) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
const addressPrefix = (0, _utils._getChainSubstrateAddressPrefix)(chainInfo);
|
|
83
|
+
if (addressPrefix < 0) {
|
|
84
|
+
// not a valid address prefix for substrate chain type
|
|
85
|
+
return address;
|
|
86
|
+
}
|
|
87
|
+
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
88
|
+
if (alternativeAddress) {
|
|
89
|
+
// reformat using alternativeAddress of that account. Because can not reformat from evm address to substrate address
|
|
90
|
+
return reformatAddress(alternativeAddress, addressPrefix);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// can not reformat without substrateAddress info
|
|
94
|
+
return address;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// reformat as usual with substrate address
|
|
98
|
+
return reformatAddress(address, addressPrefix);
|
|
99
|
+
}
|
|
100
|
+
if (chainType === _types.AccountChainType.TON || chainType === _types.AccountChainType.CARDANO) {
|
|
101
|
+
return reformatAddress(address, chainInfo.isTestnet ? 0 : 1);
|
|
67
102
|
}
|
|
103
|
+
return address;
|
|
68
104
|
};
|
|
69
105
|
exports._reformatAddressWithChain = _reformatAddressWithChain;
|
|
70
106
|
const getAccountChainTypeForAddress = address => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
2
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
3
|
import BigN from 'bignumber.js';
|
|
4
|
-
export * from './swap';
|
|
5
4
|
export * from './request';
|
|
6
5
|
export * from './earning';
|
|
7
6
|
export * from './transfer';
|
|
@@ -5,7 +5,6 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
5
5
|
import { _getTokenMinAmount, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { BasicTxErrorType } from '@subwallet/extension-base/types';
|
|
7
7
|
import { t } from 'i18next';
|
|
8
|
-
export * from "./swap.js";
|
|
9
8
|
export * from "./request.js";
|
|
10
9
|
export * from "./earning.js";
|
|
11
10
|
export * from "./transfer.js";
|
|
@@ -297,6 +297,9 @@ export default class KoniExtension {
|
|
|
297
297
|
private subscribeBuyTokens;
|
|
298
298
|
private subscribeBuyServices;
|
|
299
299
|
private subscribeSwapPairs;
|
|
300
|
+
/**
|
|
301
|
+
* @deprecated Use function `handleSwapRequestV2` instead.
|
|
302
|
+
*/
|
|
300
303
|
private handleSwapRequest;
|
|
301
304
|
private handleSwapRequestV2;
|
|
302
305
|
private getLatestSwapQuote;
|