@subwallet/extension-base 1.3.77-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 +5 -3
- package/cjs/core/logic-validation/index.js +1 -13
- package/cjs/core/substrate/xcm-parser.js +10 -1
- package/cjs/koni/background/handlers/Extension.js +41 -9
- package/cjs/koni/background/handlers/State.js +20 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/evm.js +85 -6
- package/cjs/services/balance-service/helpers/subscribe/index.js +2 -1
- package/cjs/services/balance-service/index.js +6 -2
- package/cjs/services/balance-service/transfer/token.js +15 -0
- package/cjs/services/balance-service/transfer/xcm/bittensorBridge/index.js +27 -0
- package/cjs/services/balance-service/transfer/xcm/bittensorBridge/nativeTokenBridge.js +58 -0
- package/cjs/services/balance-service/transfer/xcm/bittensorBridge/utils.js +36 -0
- package/cjs/services/balance-service/transfer/xcm/index.js +61 -2
- package/cjs/services/balance-service/transfer/xcm/utils.js +103 -15
- package/cjs/services/chain-service/constants.js +4 -2
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/constants/chains.js +4 -2
- 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 +89 -65
- package/cjs/services/earning-service/service.js +1 -0
- 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/bittensor-handler.js +197 -0
- package/cjs/services/swap-service/handler/hydradx-handler.js +9 -5
- package/cjs/services/swap-service/index.js +12 -4
- package/cjs/services/transaction-service/index.js +1 -0
- package/cjs/types/balance/index.js +1 -0
- package/cjs/types/swap/index.js +7 -10
- package/cjs/utils/account/common.js +44 -8
- package/cjs/utils/fee/transfer.js +20 -5
- package/core/logic-validation/index.d.ts +0 -1
- package/core/logic-validation/index.js +1 -2
- package/core/substrate/xcm-parser.d.ts +2 -0
- package/core/substrate/xcm-parser.js +8 -1
- package/koni/background/handlers/Extension.d.ts +3 -0
- package/koni/background/handlers/Extension.js +42 -10
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +20 -0
- package/package.json +26 -11
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/evm.d.ts +1 -0
- package/services/balance-service/helpers/subscribe/evm.js +76 -1
- package/services/balance-service/helpers/subscribe/index.js +2 -1
- package/services/balance-service/index.js +6 -2
- package/services/balance-service/transfer/token.d.ts +2 -1
- package/services/balance-service/transfer/token.js +15 -0
- package/services/balance-service/transfer/xcm/bittensorBridge/index.d.ts +2 -0
- package/services/balance-service/transfer/xcm/bittensorBridge/index.js +5 -0
- package/services/balance-service/transfer/xcm/bittensorBridge/nativeTokenBridge.d.ts +6 -0
- package/services/balance-service/transfer/xcm/bittensorBridge/nativeTokenBridge.js +50 -0
- package/services/balance-service/transfer/xcm/bittensorBridge/utils.d.ts +8 -0
- package/services/balance-service/transfer/xcm/bittensorBridge/utils.js +29 -0
- package/services/balance-service/transfer/xcm/index.d.ts +5 -0
- package/services/balance-service/transfer/xcm/index.js +57 -2
- package/services/balance-service/transfer/xcm/utils.d.ts +3 -2
- package/services/balance-service/transfer/xcm/utils.js +96 -10
- package/services/chain-service/constants.d.ts +2 -0
- package/services/chain-service/constants.js +4 -2
- package/services/chain-service/utils/patch.d.ts +1 -1
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +2 -1
- 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.d.ts +1 -1
- package/services/earning-service/handlers/special.js +92 -68
- package/services/earning-service/service.js +1 -0
- 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/bittensor-handler.d.ts +21 -0
- package/services/swap-service/handler/bittensor-handler.js +189 -0
- package/services/swap-service/handler/hydradx-handler.js +9 -5
- package/services/swap-service/index.js +12 -4
- package/services/transaction-service/index.js +1 -0
- package/services/transaction-service/types.d.ts +4 -3
- package/types/balance/index.d.ts +3 -1
- package/types/balance/index.js +1 -0
- package/types/balance/transfer.d.ts +7 -0
- package/types/fee/base.d.ts +1 -0
- package/types/swap/index.d.ts +10 -36
- package/types/swap/index.js +6 -9
- package/types/yield/actions/join/step.d.ts +7 -0
- package/types/yield/actions/join/submit.d.ts +3 -1
- package/utils/account/common.d.ts +22 -1
- package/utils/account/common.js +44 -8
- package/utils/fee/transfer.d.ts +1 -0
- package/utils/fee/transfer.js +21 -6
- 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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
|
+
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import { BasicTxErrorType, CommonStepType, DynamicSwapType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types';
|
|
7
|
+
import { _reformatAddressWithChain, toBNString } from '@subwallet/extension-base/utils';
|
|
8
|
+
import BigNumber from 'bignumber.js';
|
|
9
|
+
import { _getAssetDecimals, _isNativeTokenBySlug } from "../../chain-service/utils/index.js";
|
|
10
|
+
import { SwapBaseHandler } from "./base-handler.js";
|
|
11
|
+
export class BittensorSwapHandler {
|
|
12
|
+
isReady = false;
|
|
13
|
+
constructor(chainService, balanceService, feeService, isTestnet) {
|
|
14
|
+
this.swapBaseHandler = new SwapBaseHandler({
|
|
15
|
+
chainService,
|
|
16
|
+
balanceService,
|
|
17
|
+
feeService,
|
|
18
|
+
providerName: isTestnet ? 'Bittensor Testnet' : 'Bittensor',
|
|
19
|
+
providerSlug: isTestnet ? SwapProviderId.BITTENSOR_TESTNET : SwapProviderId.BITTENSOR
|
|
20
|
+
});
|
|
21
|
+
this.providerSlug = isTestnet ? SwapProviderId.BITTENSOR_TESTNET : SwapProviderId.BITTENSOR;
|
|
22
|
+
}
|
|
23
|
+
get chainService() {
|
|
24
|
+
return this.swapBaseHandler.chainService;
|
|
25
|
+
}
|
|
26
|
+
get providerInfo() {
|
|
27
|
+
return this.swapBaseHandler.providerInfo;
|
|
28
|
+
}
|
|
29
|
+
generateOptimalProcessV2(params) {
|
|
30
|
+
return this.swapBaseHandler.generateOptimalProcessV2(params, [this.getSubmitStep.bind(this)]);
|
|
31
|
+
}
|
|
32
|
+
async getSubmitStep(params) {
|
|
33
|
+
if (!params.selectedQuote) {
|
|
34
|
+
return Promise.resolve(undefined);
|
|
35
|
+
}
|
|
36
|
+
const originTokenInfo = this.chainService.getAssetBySlug(params.selectedQuote.pair.from);
|
|
37
|
+
const destinationTokenInfo = this.chainService.getAssetBySlug(params.selectedQuote.pair.to);
|
|
38
|
+
const originChain = this.chainService.getChainInfoByKey(originTokenInfo.originChain);
|
|
39
|
+
const destinationChain = this.chainService.getChainInfoByKey(destinationTokenInfo.originChain);
|
|
40
|
+
const submitStep = {
|
|
41
|
+
name: 'Swap',
|
|
42
|
+
type: SwapStepType.SWAP,
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
metadata: {
|
|
45
|
+
sendingValue: params.request.fromAmount.toString(),
|
|
46
|
+
expectedReceive: params.selectedQuote.toAmount,
|
|
47
|
+
originTokenInfo,
|
|
48
|
+
destinationTokenInfo,
|
|
49
|
+
sender: _reformatAddressWithChain(params.request.address, originChain),
|
|
50
|
+
receiver: _reformatAddressWithChain(params.request.recipient || params.request.address, destinationChain),
|
|
51
|
+
version: 2
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return Promise.resolve([submitStep, params.selectedQuote.feeInfo]);
|
|
55
|
+
}
|
|
56
|
+
async validateSwapProcessV2(params) {
|
|
57
|
+
// todo: recheck address and recipient format in params
|
|
58
|
+
const {
|
|
59
|
+
process,
|
|
60
|
+
selectedQuote
|
|
61
|
+
} = params; // todo: review flow, currentStep param.
|
|
62
|
+
|
|
63
|
+
// todo: validate path with optimalProcess
|
|
64
|
+
// todo: review error message in case many step swap
|
|
65
|
+
if (BigNumber(selectedQuote.fromAmount).lte(0)) {
|
|
66
|
+
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')];
|
|
67
|
+
}
|
|
68
|
+
const actionList = JSON.stringify(process.path.map(step => step.action));
|
|
69
|
+
const swap = actionList === JSON.stringify([DynamicSwapType.SWAP]);
|
|
70
|
+
const swapXcm = actionList === JSON.stringify([DynamicSwapType.SWAP, DynamicSwapType.BRIDGE]);
|
|
71
|
+
const xcmSwap = actionList === JSON.stringify([DynamicSwapType.BRIDGE, DynamicSwapType.SWAP]);
|
|
72
|
+
const xcmSwapXcm = actionList === JSON.stringify([DynamicSwapType.BRIDGE, DynamicSwapType.SWAP, DynamicSwapType.BRIDGE]);
|
|
73
|
+
const swapIndex = params.process.steps.findIndex(step => step.type === SwapStepType.SWAP); // todo
|
|
74
|
+
|
|
75
|
+
if (swapIndex <= -1) {
|
|
76
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
77
|
+
}
|
|
78
|
+
if (swap) {
|
|
79
|
+
return this.swapBaseHandler.validateSwapOnlyProcess(params, swapIndex); // todo: create interface for input request
|
|
80
|
+
}
|
|
81
|
+
if (swapXcm) {
|
|
82
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
83
|
+
}
|
|
84
|
+
if (xcmSwap) {
|
|
85
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
86
|
+
}
|
|
87
|
+
if (xcmSwapXcm) {
|
|
88
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
89
|
+
}
|
|
90
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
91
|
+
}
|
|
92
|
+
async handleSwapProcess(params) {
|
|
93
|
+
const {
|
|
94
|
+
currentStep,
|
|
95
|
+
process
|
|
96
|
+
} = params;
|
|
97
|
+
const type = process.steps[currentStep].type;
|
|
98
|
+
switch (type) {
|
|
99
|
+
case CommonStepType.DEFAULT:
|
|
100
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
101
|
+
case SwapStepType.SWAP:
|
|
102
|
+
return this.handleSubmitStep(params);
|
|
103
|
+
default:
|
|
104
|
+
return this.handleSubmitStep(params);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async handleSubmitStep(params) {
|
|
108
|
+
var _fromAsset$metadata, _toAsset$metadata;
|
|
109
|
+
const {
|
|
110
|
+
address,
|
|
111
|
+
quote
|
|
112
|
+
} = params;
|
|
113
|
+
const pair = quote.pair;
|
|
114
|
+
const fromAsset = this.chainService.getAssetBySlug(pair.from);
|
|
115
|
+
const toAsset = this.chainService.getAssetBySlug(pair.to);
|
|
116
|
+
const chainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
|
|
117
|
+
const fromNetuid = _isNativeTokenBySlug(fromAsset.slug) ? 0 : (_fromAsset$metadata = fromAsset.metadata) === null || _fromAsset$metadata === void 0 ? void 0 : _fromAsset$metadata.netuid;
|
|
118
|
+
const toNetuid = _isNativeTokenBySlug(toAsset.slug) ? 0 : (_toAsset$metadata = toAsset.metadata) === null || _toAsset$metadata === void 0 ? void 0 : _toAsset$metadata.netuid;
|
|
119
|
+
if (fromNetuid == null || toNetuid == null || fromNetuid === toNetuid) {
|
|
120
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
121
|
+
}
|
|
122
|
+
const txData = {
|
|
123
|
+
address,
|
|
124
|
+
provider: this.providerInfo,
|
|
125
|
+
quote: params.quote,
|
|
126
|
+
slippage: params.slippage,
|
|
127
|
+
process: params.process
|
|
128
|
+
};
|
|
129
|
+
const chainApi = this.chainService.getSubstrateApi(chainInfo.slug);
|
|
130
|
+
const substrateApi = await chainApi.isReady;
|
|
131
|
+
const _stakeInfo = await substrateApi.api.call.stakeInfoRuntimeApi.getStakeInfoForColdkey(address);
|
|
132
|
+
const stakeInfo = _stakeInfo.toPrimitive();
|
|
133
|
+
|
|
134
|
+
// TAO/ALPHA ratio
|
|
135
|
+
const priceRatio = new BigNumber(toBNString(quote.rate, _getAssetDecimals(fromAsset)));
|
|
136
|
+
const limitPrice = priceRatio.multipliedBy(new BigNumber(1).minus(params.slippage)).integerValue(BigNumber.ROUND_DOWN).toFixed();
|
|
137
|
+
const calls = this.buildSwapCalls({
|
|
138
|
+
stakeInfo,
|
|
139
|
+
fromNetuid,
|
|
140
|
+
toNetuid,
|
|
141
|
+
amount: new BigNumber(quote.fromAmount),
|
|
142
|
+
limitPrice
|
|
143
|
+
}, substrateApi.api);
|
|
144
|
+
let extrinsic;
|
|
145
|
+
if (calls.length === 1) {
|
|
146
|
+
extrinsic = calls[0];
|
|
147
|
+
} else {
|
|
148
|
+
extrinsic = substrateApi.api.tx.utility.batchAll(calls);
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
txChain: fromAsset.originChain,
|
|
152
|
+
extrinsic,
|
|
153
|
+
txData,
|
|
154
|
+
extrinsicType: ExtrinsicType.SWAP,
|
|
155
|
+
chainType: ChainType.SUBSTRATE
|
|
156
|
+
// using staked balance so we do not need transferNativeAmount
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Sort hotkeys by stake descending
|
|
161
|
+
getHotkeysByNetuidDesc(stakeInfo, fromNetuid) {
|
|
162
|
+
return stakeInfo.filter(i => i.netuid === fromNetuid && new BigNumber(i.stake).gt(0)).sort((a, b) => new BigNumber(b.stake).minus(a.stake).toNumber());
|
|
163
|
+
}
|
|
164
|
+
buildSwapCalls(params, api) {
|
|
165
|
+
const {
|
|
166
|
+
amount,
|
|
167
|
+
fromNetuid,
|
|
168
|
+
limitPrice,
|
|
169
|
+
stakeInfo,
|
|
170
|
+
toNetuid
|
|
171
|
+
} = params;
|
|
172
|
+
const hotkeys = this.getHotkeysByNetuidDesc(stakeInfo, fromNetuid);
|
|
173
|
+
let remaining = amount;
|
|
174
|
+
const calls = [];
|
|
175
|
+
for (const item of hotkeys) {
|
|
176
|
+
if (remaining.lte(0)) {
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
const stake = new BigNumber(item.stake);
|
|
180
|
+
if (stake.lte(0)) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const swapAmount = BigNumber.minimum(stake, remaining);
|
|
184
|
+
calls.push(api.tx.subtensorModule.swapStakeLimit(item.hotkey, fromNetuid, toNetuid, swapAmount.toFixed(), limitPrice, false));
|
|
185
|
+
remaining = remaining.minus(swapAmount);
|
|
186
|
+
}
|
|
187
|
+
return calls;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -108,7 +108,11 @@ export class HydradxHandler {
|
|
|
108
108
|
const {
|
|
109
109
|
path,
|
|
110
110
|
request: {
|
|
111
|
-
|
|
111
|
+
address,
|
|
112
|
+
alternativeAddress,
|
|
113
|
+
fromAmount,
|
|
114
|
+
recipient,
|
|
115
|
+
slippage
|
|
112
116
|
},
|
|
113
117
|
selectedQuote
|
|
114
118
|
} = params;
|
|
@@ -127,8 +131,8 @@ export class HydradxHandler {
|
|
|
127
131
|
const destinationTokenInfo = this.chainService.getAssetBySlug(swapPairInfo.to);
|
|
128
132
|
const originChain = this.chainService.getChainInfoByKey(originTokenInfo.originChain);
|
|
129
133
|
const destinationChain = this.chainService.getChainInfoByKey(destinationTokenInfo.originChain);
|
|
130
|
-
const sender = _reformatAddressWithChain(
|
|
131
|
-
let receiver = _reformatAddressWithChain(
|
|
134
|
+
const sender = _reformatAddressWithChain(address, originChain, alternativeAddress);
|
|
135
|
+
let receiver = _reformatAddressWithChain(recipient || address, destinationChain);
|
|
132
136
|
const actionList = JSON.stringify(path.map(step => step.action));
|
|
133
137
|
const xcmSwapXcm = actionList === JSON.stringify([DynamicSwapType.BRIDGE, DynamicSwapType.SWAP, DynamicSwapType.BRIDGE]);
|
|
134
138
|
const swapXcm = actionList === JSON.stringify([DynamicSwapType.SWAP, DynamicSwapType.BRIDGE]);
|
|
@@ -152,7 +156,7 @@ export class HydradxHandler {
|
|
|
152
156
|
slug: swapPairInfo.slug
|
|
153
157
|
},
|
|
154
158
|
fromAmount: bnSendingValue.toFixed(0, 1),
|
|
155
|
-
slippage:
|
|
159
|
+
slippage: slippage
|
|
156
160
|
});
|
|
157
161
|
} catch (error) {
|
|
158
162
|
throw new Error(`Failed to fetch swap quote: ${error.message}`);
|
|
@@ -163,7 +167,7 @@ export class HydradxHandler {
|
|
|
163
167
|
}
|
|
164
168
|
const overrideQuote = quoteAskResponse.quote;
|
|
165
169
|
txHex = overrideQuote.metadata;
|
|
166
|
-
receiver = _reformatAddressWithChain(
|
|
170
|
+
receiver = _reformatAddressWithChain(address, destinationChain, alternativeAddress);
|
|
167
171
|
}
|
|
168
172
|
if (!txHex || !isHex(txHex)) {
|
|
169
173
|
return Promise.resolve(undefined);
|
|
@@ -20,6 +20,7 @@ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
|
|
|
20
20
|
import BigN from 'bignumber.js';
|
|
21
21
|
import { t } from 'i18next';
|
|
22
22
|
import { BehaviorSubject } from 'rxjs';
|
|
23
|
+
import { BittensorSwapHandler } from "./handler/bittensor-handler.js";
|
|
23
24
|
import { KyberHandler } from "./handler/kyber-handler.js";
|
|
24
25
|
import { SimpleSwapHandler } from "./handler/simpleswap-handler.js";
|
|
25
26
|
import { UniswapHandler } from "./handler/uniswap-handler.js";
|
|
@@ -102,8 +103,7 @@ export class SwapService {
|
|
|
102
103
|
if (!params.selectedQuote) {
|
|
103
104
|
return this.getDefaultProcessV2(params);
|
|
104
105
|
} else {
|
|
105
|
-
|
|
106
|
-
const providerId = ((_params$request$curre = params.request.currentQuote) === null || _params$request$curre === void 0 ? void 0 : _params$request$curre.id) || params.selectedQuote.provider.id;
|
|
106
|
+
const providerId = params.selectedQuote.provider.id;
|
|
107
107
|
const handler = this.handlers[providerId];
|
|
108
108
|
if (handler) {
|
|
109
109
|
// todo: handle error response from generateOptimalProcess
|
|
@@ -128,6 +128,8 @@ export class SwapService {
|
|
|
128
128
|
console.group('Swap Logger');
|
|
129
129
|
console.log('path', path);
|
|
130
130
|
console.log('swapQuoteResponse', swapQuoteResponse);
|
|
131
|
+
|
|
132
|
+
// Just to log routing type for Uniswap Quote
|
|
131
133
|
if (swapQuoteResponse.optimalQuote && swapQuoteResponse.optimalQuote.metadata) {
|
|
132
134
|
const routing = swapQuoteResponse.optimalQuote.metadata.routing;
|
|
133
135
|
if (routing) {
|
|
@@ -146,7 +148,7 @@ export class SwapService {
|
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
// override fee for quote because some cases need estimate network fee on Extension (i.e. Optimex)
|
|
149
|
-
if (swapQuoteResponse.optimalQuote) {
|
|
151
|
+
if (swapQuoteResponse.optimalQuote && [SwapProviderId.OPTIMEX, SwapProviderId.OPTIMEX_TESTNET].includes(swapQuoteResponse.optimalQuote.provider.id)) {
|
|
150
152
|
const swapIndex = optimalProcess.steps.findIndex(step => step.type === SwapStepType.SWAP);
|
|
151
153
|
swapQuoteResponse.optimalQuote.feeInfo.feeComponent = optimalProcess.totalFee[swapIndex].feeComponent;
|
|
152
154
|
}
|
|
@@ -189,7 +191,7 @@ export class SwapService {
|
|
|
189
191
|
const swapAction = path.find(step => step.action === DynamicSwapType.SWAP);
|
|
190
192
|
const directSwapRequest = swapAction ? {
|
|
191
193
|
...request,
|
|
192
|
-
address: _reformatAddressWithChain(request.address, this.chainService.getChainInfoByKey(_getAssetOriginChain(this.chainService.getAssetBySlug(swapAction.pair.from)))),
|
|
194
|
+
address: _reformatAddressWithChain(request.address, this.chainService.getChainInfoByKey(_getAssetOriginChain(this.chainService.getAssetBySlug(swapAction.pair.from))), request.alternativeAddress),
|
|
193
195
|
pair: swapAction.pair
|
|
194
196
|
} : undefined;
|
|
195
197
|
if (!directSwapRequest) {
|
|
@@ -289,6 +291,12 @@ export class SwapService {
|
|
|
289
291
|
case SwapProviderId.OPTIMEX_TESTNET:
|
|
290
292
|
this.handlers[providerId] = new OptimexHandler(this.chainService, this.state.balanceService, this.state.feeService, true);
|
|
291
293
|
break;
|
|
294
|
+
case SwapProviderId.BITTENSOR:
|
|
295
|
+
this.handlers[providerId] = new BittensorSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, false);
|
|
296
|
+
break;
|
|
297
|
+
case SwapProviderId.BITTENSOR_TESTNET:
|
|
298
|
+
this.handlers[providerId] = new BittensorSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, true);
|
|
299
|
+
break;
|
|
292
300
|
default:
|
|
293
301
|
throw new Error('Unsupported provider');
|
|
294
302
|
}
|
|
@@ -930,6 +930,7 @@ export default class TransactionService {
|
|
|
930
930
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
931
931
|
startBlock: startBlock || 0,
|
|
932
932
|
processId: (_transaction$step3 = transaction.step) === null || _transaction$step3 === void 0 ? void 0 : _transaction$step3.processId,
|
|
933
|
+
crossChainFeeInfo: transaction === null || transaction === void 0 ? void 0 : transaction.xcmDestinationFee,
|
|
933
934
|
substrateProxyAddresses: []
|
|
934
935
|
};
|
|
935
936
|
const substrateProxyHistories = [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainType, ExtrinsicDataTypeMap, ExtrinsicStatus, ExtrinsicType, FeeData, ValidateTransactionResponse } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
|
+
import { AmountData, ChainType, ExtrinsicDataTypeMap, ExtrinsicStatus, ExtrinsicType, FeeData, ValidateTransactionResponse } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { SignTypedDataMessageV3V4 } from '@subwallet/extension-base/core/logic-validation';
|
|
3
3
|
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
4
4
|
import { UniswapOrderInfo } from '@subwallet/extension-base/services/swap-service/handler/uniswap-handler';
|
|
@@ -23,6 +23,7 @@ export interface SWTransactionBase extends ValidateTransactionResponse, Partial<
|
|
|
23
23
|
updatedAt: number;
|
|
24
24
|
estimateFee?: FeeData;
|
|
25
25
|
xcmFeeDryRun?: string;
|
|
26
|
+
xcmDestinationFee?: AmountData;
|
|
26
27
|
transaction: any;
|
|
27
28
|
additionalValidator?: (inputTransaction: SWTransactionResponse) => Promise<void>;
|
|
28
29
|
eventsHandler?: (eventEmitter: TransactionEmitter) => void;
|
|
@@ -75,7 +76,7 @@ export interface SWTransactionEmitter {
|
|
|
75
76
|
emitterTransaction?: TransactionEmitter;
|
|
76
77
|
}
|
|
77
78
|
declare type SwInputBase = Pick<SWTransactionBase, 'address' | 'url' | 'data' | 'extrinsicType' | 'chain' | 'chainType' | 'ignoreWarnings' | 'transferNativeAmount'> & Partial<Pick<SWTransactionBase, 'additionalValidator' | 'eventsHandler'>>;
|
|
78
|
-
export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransactionBase, 'estimateFee' | 'signAfterCreate' | 'isPassConfirmation' | 'step' | 'errorOnTimeOut' | 'xcmFeeDryRun' | 'wrappingStatus'>>, TransactionFee {
|
|
79
|
+
export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransactionBase, 'estimateFee' | 'signAfterCreate' | 'isPassConfirmation' | 'step' | 'errorOnTimeOut' | 'xcmFeeDryRun' | 'xcmDestinationFee' | 'wrappingStatus'>>, TransactionFee {
|
|
79
80
|
id?: string;
|
|
80
81
|
transaction?: SWTransactionBase['transaction'] | null;
|
|
81
82
|
warnings?: SWTransactionBase['warnings'];
|
|
@@ -94,7 +95,7 @@ export interface SWPermitTransactionInput extends Omit<SWTransactionInput, 'tran
|
|
|
94
95
|
export interface SWDutchTransactionInput extends Omit<SWTransactionInput, 'transaction'> {
|
|
95
96
|
transaction?: SWDutchTransaction['transaction'] | null;
|
|
96
97
|
}
|
|
97
|
-
export declare type SWTransactionResponse = SwInputBase & Pick<SWTransactionBase, 'warnings' | 'errors'> & Partial<Pick<SWTransactionBase, 'id' | 'extrinsicHash' | 'status' | 'estimateFee' | 'xcmFeeDryRun' | 'wrappingStatus'>> & TransactionFee & {
|
|
98
|
+
export declare type SWTransactionResponse = SwInputBase & Pick<SWTransactionBase, 'warnings' | 'errors'> & Partial<Pick<SWTransactionBase, 'id' | 'extrinsicHash' | 'status' | 'estimateFee' | 'xcmFeeDryRun' | 'xcmDestinationFee' | 'wrappingStatus'>> & TransactionFee & {
|
|
98
99
|
processId?: string;
|
|
99
100
|
};
|
|
100
101
|
export declare type BitcoinTransactionData = {
|
package/types/balance/index.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ export declare enum BalanceType {
|
|
|
12
12
|
TRANSFERABLE = "transferable",
|
|
13
13
|
TOTAL = "total",
|
|
14
14
|
TOTAL_MINUS_RESERVED = "totalMinusReserved",
|
|
15
|
-
KEEP_ALIVE = "keepAlive"
|
|
15
|
+
KEEP_ALIVE = "keepAlive",
|
|
16
|
+
STAKING = "staking"
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Balance info of a token on an address
|
|
@@ -62,6 +63,7 @@ export interface SubscribeSubstratePalletBalance extends SubscribeBasePalletBala
|
|
|
62
63
|
}
|
|
63
64
|
export interface SubscribeEvmPalletBalance extends SubscribeBasePalletBalance {
|
|
64
65
|
evmApi: _EvmApi;
|
|
66
|
+
substrateApiMap?: Record<string, _SubstrateApi>;
|
|
65
67
|
}
|
|
66
68
|
export interface SubscribeTonPalletBalance extends SubscribeBasePalletBalance {
|
|
67
69
|
tonApi: _TonApi;
|
package/types/balance/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export let BalanceType;
|
|
|
18
18
|
BalanceType["TOTAL"] = "total";
|
|
19
19
|
BalanceType["TOTAL_MINUS_RESERVED"] = "totalMinusReserved";
|
|
20
20
|
BalanceType["KEEP_ALIVE"] = "keepAlive";
|
|
21
|
+
BalanceType["STAKING"] = "staking";
|
|
21
22
|
})(BalanceType || (BalanceType = {}));
|
|
22
23
|
/** Balance info of all tokens on an address */
|
|
23
24
|
// Key is tokenSlug
|
|
@@ -9,6 +9,7 @@ export interface RequestSubscribeTransfer extends TransactionFee {
|
|
|
9
9
|
token: string;
|
|
10
10
|
destChain: string;
|
|
11
11
|
transferAll?: boolean;
|
|
12
|
+
metadata?: Record<string, any>;
|
|
12
13
|
}
|
|
13
14
|
export interface ResponseSubscribeTransfer {
|
|
14
15
|
id: string;
|
|
@@ -26,6 +27,11 @@ export interface RequestSubmitTransferWithId extends RequestSubmitTransfer {
|
|
|
26
27
|
export interface ResponseSubscribeTransferConfirmation extends Omit<ResponseSubscribeTransfer, 'maxTransferable'> {
|
|
27
28
|
error?: string;
|
|
28
29
|
}
|
|
30
|
+
export interface AlphaTokenTransferMetadata {
|
|
31
|
+
netuid: number;
|
|
32
|
+
fromValidator: string;
|
|
33
|
+
toValidator: string;
|
|
34
|
+
}
|
|
29
35
|
export interface RequestSubmitTransfer extends BaseRequestSign, TransactionFee {
|
|
30
36
|
chain: string;
|
|
31
37
|
from: string;
|
|
@@ -37,6 +43,7 @@ export interface RequestSubmitTransfer extends BaseRequestSign, TransactionFee {
|
|
|
37
43
|
isSubstrateECDSATransaction?: boolean;
|
|
38
44
|
maxTransferableWithoutFee?: string;
|
|
39
45
|
maxTransferable?: string;
|
|
46
|
+
metadata?: Record<string, any>;
|
|
40
47
|
}
|
|
41
48
|
export interface RequestSubmitSignPsbtTransfer extends BaseRequestSign {
|
|
42
49
|
id: string;
|
package/types/fee/base.d.ts
CHANGED
package/types/swap/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ChainAsset
|
|
1
|
+
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
2
|
import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
|
|
3
|
-
import {
|
|
3
|
+
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { BaseStepDetail, BaseStepType, CommonOptimalSwapPath, CommonStepFeeInfo } from '@subwallet/extension-base/types/service-base';
|
|
5
5
|
import BigN from 'bignumber.js';
|
|
6
6
|
import { BaseProcessRequestSign, TransactionData } from '../transaction';
|
|
@@ -65,13 +65,14 @@ export declare enum SwapProviderId {
|
|
|
65
65
|
UNISWAP = "UNISWAP",
|
|
66
66
|
KYBER = "KYBER",
|
|
67
67
|
OPTIMEX = "OPTIMEX",
|
|
68
|
-
OPTIMEX_TESTNET = "OPTIMEX_TESTNET"
|
|
68
|
+
OPTIMEX_TESTNET = "OPTIMEX_TESTNET",
|
|
69
|
+
BITTENSOR = "BITTENSOR",
|
|
70
|
+
BITTENSOR_TESTNET = "BITTENSOR_TESTNET"
|
|
69
71
|
}
|
|
70
72
|
export declare const _SUPPORTED_SWAP_PROVIDERS: SwapProviderId[];
|
|
71
73
|
export interface SwapProvider {
|
|
72
74
|
id: SwapProviderId;
|
|
73
75
|
name: string;
|
|
74
|
-
faq?: string;
|
|
75
76
|
}
|
|
76
77
|
export declare enum SwapFeeType {
|
|
77
78
|
PLATFORM_FEE = "PLATFORM_FEE",
|
|
@@ -99,30 +100,13 @@ export interface HydradxSwapTxData extends SwapBaseTxData {
|
|
|
99
100
|
txHex: string;
|
|
100
101
|
}
|
|
101
102
|
export declare type GenSwapStepFuncV2 = (params: OptimalSwapPathParamsV2, stepIndex: number) => Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
102
|
-
export interface ChainflipPreValidationMetadata {
|
|
103
|
-
minSwap: AmountData;
|
|
104
|
-
maxSwap?: AmountData;
|
|
105
|
-
chain: _ChainInfo;
|
|
106
|
-
}
|
|
107
|
-
export interface HydradxPreValidationMetadata {
|
|
108
|
-
maxSwap: AmountData;
|
|
109
|
-
chain: _ChainInfo;
|
|
110
|
-
}
|
|
111
|
-
export interface AssetHubPreValidationMetadata {
|
|
112
|
-
chain: _ChainInfo;
|
|
113
|
-
toAmount: string;
|
|
114
|
-
quoteRate: string;
|
|
115
|
-
priceImpactPct?: string;
|
|
116
|
-
}
|
|
117
|
-
export interface SimpleSwapValidationMetadata {
|
|
118
|
-
minSwap: AmountData;
|
|
119
|
-
maxSwap: AmountData;
|
|
120
|
-
chain: _ChainInfo;
|
|
121
|
-
}
|
|
122
103
|
export interface ProcessedQuoteAskResponse {
|
|
123
104
|
quote?: SwapQuote;
|
|
124
105
|
error?: SwapError;
|
|
125
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use interface `SwapRequestV2` instead.
|
|
109
|
+
*/
|
|
126
110
|
export interface SwapRequest {
|
|
127
111
|
address: string;
|
|
128
112
|
pair: SwapPair;
|
|
@@ -134,6 +118,7 @@ export interface SwapRequest {
|
|
|
134
118
|
}
|
|
135
119
|
export interface SwapRequestV2 {
|
|
136
120
|
address: string;
|
|
121
|
+
alternativeAddress?: string;
|
|
137
122
|
pair: SwapPair;
|
|
138
123
|
fromAmount: string;
|
|
139
124
|
slippage: number;
|
|
@@ -180,22 +165,11 @@ export interface DynamicSwapAction {
|
|
|
180
165
|
action: DynamicSwapType;
|
|
181
166
|
pair: ActionPair;
|
|
182
167
|
}
|
|
183
|
-
export declare const enum BridgeStepPosition {
|
|
184
|
-
FIRST = 0,
|
|
185
|
-
AFTER_SWAP = 1
|
|
186
|
-
}
|
|
187
168
|
export interface OptimalSwapPathParamsV2 {
|
|
188
|
-
request:
|
|
169
|
+
request: SwapRequestV2;
|
|
189
170
|
selectedQuote?: SwapQuote;
|
|
190
171
|
path: DynamicSwapAction[];
|
|
191
172
|
}
|
|
192
|
-
export interface SwapEarlyValidation {
|
|
193
|
-
error?: SwapErrorType;
|
|
194
|
-
metadata?: ChainflipPreValidationMetadata | HydradxPreValidationMetadata | AssetHubPreValidationMetadata;
|
|
195
|
-
}
|
|
196
|
-
export interface AssetHubSwapEarlyValidation extends SwapEarlyValidation {
|
|
197
|
-
metadata: AssetHubPreValidationMetadata;
|
|
198
|
-
}
|
|
199
173
|
export interface ValidateSwapProcessParams {
|
|
200
174
|
address: string;
|
|
201
175
|
process: CommonOptimalSwapPath;
|
package/types/swap/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
// core
|
|
5
|
-
|
|
6
4
|
export let SwapErrorType;
|
|
7
5
|
(function (SwapErrorType) {
|
|
8
6
|
SwapErrorType["ERROR_FETCHING_QUOTE"] = "ERROR_FETCHING_QUOTE";
|
|
@@ -42,9 +40,10 @@ export let SwapProviderId;
|
|
|
42
40
|
SwapProviderId["KYBER"] = "KYBER";
|
|
43
41
|
SwapProviderId["OPTIMEX"] = "OPTIMEX";
|
|
44
42
|
SwapProviderId["OPTIMEX_TESTNET"] = "OPTIMEX_TESTNET";
|
|
43
|
+
SwapProviderId["BITTENSOR"] = "BITTENSOR";
|
|
44
|
+
SwapProviderId["BITTENSOR_TESTNET"] = "BITTENSOR_TESTNET";
|
|
45
45
|
})(SwapProviderId || (SwapProviderId = {}));
|
|
46
|
-
export 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];
|
|
47
|
-
// process handling
|
|
46
|
+
export 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];
|
|
48
47
|
export let SwapFeeType;
|
|
49
48
|
(function (SwapFeeType) {
|
|
50
49
|
SwapFeeType["PLATFORM_FEE"] = "PLATFORM_FEE";
|
|
@@ -52,15 +51,13 @@ export let SwapFeeType;
|
|
|
52
51
|
SwapFeeType["WALLET_FEE"] = "WALLET_FEE";
|
|
53
52
|
})(SwapFeeType || (SwapFeeType = {})); // todo: will be more
|
|
54
53
|
// parameters & responses
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use interface `SwapRequestV2` instead.
|
|
56
|
+
*/
|
|
55
57
|
export let DynamicSwapType;
|
|
56
58
|
(function (DynamicSwapType) {
|
|
57
59
|
DynamicSwapType["SWAP"] = "SWAP";
|
|
58
60
|
DynamicSwapType["BRIDGE"] = "BRIDGE";
|
|
59
61
|
})(DynamicSwapType || (DynamicSwapType = {}));
|
|
60
|
-
export let BridgeStepPosition;
|
|
61
|
-
(function (BridgeStepPosition) {
|
|
62
|
-
BridgeStepPosition[BridgeStepPosition["FIRST"] = 0] = "FIRST";
|
|
63
|
-
BridgeStepPosition[BridgeStepPosition["AFTER_SWAP"] = 1] = "AFTER_SWAP";
|
|
64
|
-
})(BridgeStepPosition || (BridgeStepPosition = {}));
|
|
65
62
|
export const CHAINFLIP_SLIPPAGE = 0.02; // Example: 0.01 for 1%
|
|
66
63
|
export const SIMPLE_SWAP_SLIPPAGE = 0.05;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
1
2
|
import { YieldPoolTarget } from '@subwallet/extension-base/types';
|
|
2
3
|
/**
|
|
3
4
|
* @interface RequestEarlyValidateYield
|
|
@@ -95,3 +96,9 @@ export interface OptimalYieldPath {
|
|
|
95
96
|
connectionError?: string;
|
|
96
97
|
}
|
|
97
98
|
export declare type GenStepFunction = (params: OptimalYieldPathParams) => Promise<YieldStepBaseInfo | undefined>;
|
|
99
|
+
export interface XcmStepMetadataForLiqStaking {
|
|
100
|
+
sendingValue: string;
|
|
101
|
+
xcmDestinationFee?: string;
|
|
102
|
+
originTokenInfo: _ChainAsset;
|
|
103
|
+
destinationTokenInfo: _ChainAsset;
|
|
104
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _Address, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
|
+
import { _Address, AmountData, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { BaseProcessRequestSign, BaseRequestSign, InternalRequestSign, TransactionData } from '../../../transaction';
|
|
3
3
|
import { BittensorRootClaimType, NominationPoolInfo, ValidatorInfo, YieldPoolType, YieldPositionInfo } from '../../info';
|
|
4
4
|
import { OptimalYieldPath } from './step';
|
|
@@ -9,6 +9,8 @@ export interface HandleYieldStepData {
|
|
|
9
9
|
chainType: ChainType;
|
|
10
10
|
txData: any;
|
|
11
11
|
transferNativeAmount: string;
|
|
12
|
+
xcmStepFee?: string;
|
|
13
|
+
xcmDestinationFee?: AmountData;
|
|
12
14
|
}
|
|
13
15
|
export interface AbstractSubmitYieldJoinData {
|
|
14
16
|
slug: string;
|
|
@@ -3,7 +3,28 @@ import { ChainType } from '@subwallet/extension-base/background/KoniTypes';
|
|
|
3
3
|
import { AccountChainType, AccountJson } from '@subwallet/extension-base/types';
|
|
4
4
|
export declare function isAccountAll(address?: string): boolean;
|
|
5
5
|
export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean, ignoreError?: boolean): string;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @private
|
|
8
|
+
* Reformats a wallet address based on the provided chain information.
|
|
9
|
+
*
|
|
10
|
+
* This function checks the chain type (Substrate, TON, Cardano, or others)
|
|
11
|
+
* and applies the corresponding formatting logic:
|
|
12
|
+
* 1. **Substrate**: Reformats the Substrate address using the chain's specific prefix.
|
|
13
|
+
* If the current `address` is an EVM address, it attempts to use the `alternativeAddress`
|
|
14
|
+
* (which is currently **always** expected to be the Substrate address) for Substrate
|
|
15
|
+
* formatting, as direct EVM-to-Substrate reformatting is not possible here.
|
|
16
|
+
* 2. **TON/Cardano**: Uses a simple prefix logic based on whether the chain is a testnet or a mainnet.
|
|
17
|
+
* 3. **Default (EVM/Others)**: Returns the original address without reformatting.
|
|
18
|
+
*
|
|
19
|
+
* @param address The current wallet address string.
|
|
20
|
+
* @param chainInfo An object containing chain details (e.g., chain type, testnet status, prefix).
|
|
21
|
+
* @param alternativeAddress An optional alternative address, which is currently expected to be the Substrate
|
|
22
|
+
* address associated with the account. It is used as a fallback for Substrate formatting when the main `address` is EVM.
|
|
23
|
+
* @returns The reformatted wallet address, or the original address if no reformatting is needed or possible.
|
|
24
|
+
*
|
|
25
|
+
* @todo This function currently lacks logic to reformat a Substrate address into an EVM address format.
|
|
26
|
+
*/
|
|
27
|
+
export declare const _reformatAddressWithChain: (address: string, chainInfo: _ChainInfo, alternativeAddress?: string) => string;
|
|
7
28
|
export declare const getAccountChainTypeForAddress: (address: string) => AccountChainType;
|
|
8
29
|
declare type AddressesByChainType = {
|
|
9
30
|
[key in ChainType]: string[];
|
package/utils/account/common.js
CHANGED
|
@@ -40,17 +40,53 @@ export function reformatAddress(address, networkPrefix = 42, isEthereum = false,
|
|
|
40
40
|
return address;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
* Reformats a wallet address based on the provided chain information.
|
|
47
|
+
*
|
|
48
|
+
* This function checks the chain type (Substrate, TON, Cardano, or others)
|
|
49
|
+
* and applies the corresponding formatting logic:
|
|
50
|
+
* 1. **Substrate**: Reformats the Substrate address using the chain's specific prefix.
|
|
51
|
+
* If the current `address` is an EVM address, it attempts to use the `alternativeAddress`
|
|
52
|
+
* (which is currently **always** expected to be the Substrate address) for Substrate
|
|
53
|
+
* formatting, as direct EVM-to-Substrate reformatting is not possible here.
|
|
54
|
+
* 2. **TON/Cardano**: Uses a simple prefix logic based on whether the chain is a testnet or a mainnet.
|
|
55
|
+
* 3. **Default (EVM/Others)**: Returns the original address without reformatting.
|
|
56
|
+
*
|
|
57
|
+
* @param address The current wallet address string.
|
|
58
|
+
* @param chainInfo An object containing chain details (e.g., chain type, testnet status, prefix).
|
|
59
|
+
* @param alternativeAddress An optional alternative address, which is currently expected to be the Substrate
|
|
60
|
+
* address associated with the account. It is used as a fallback for Substrate formatting when the main `address` is EVM.
|
|
61
|
+
* @returns The reformatted wallet address, or the original address if no reformatting is needed or possible.
|
|
62
|
+
*
|
|
63
|
+
* @todo This function currently lacks logic to reformat a Substrate address into an EVM address format.
|
|
64
|
+
*/
|
|
65
|
+
export const _reformatAddressWithChain = (address, chainInfo, alternativeAddress) => {
|
|
44
66
|
const chainType = _chainInfoToAccountChainType(chainInfo);
|
|
45
67
|
if (chainType === AccountChainType.SUBSTRATE) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
const addressPrefix = _getChainSubstrateAddressPrefix(chainInfo);
|
|
69
|
+
if (addressPrefix < 0) {
|
|
70
|
+
// not a valid address prefix for substrate chain type
|
|
71
|
+
return address;
|
|
72
|
+
}
|
|
73
|
+
if (isEthereumAddress(address)) {
|
|
74
|
+
if (alternativeAddress) {
|
|
75
|
+
// reformat using alternativeAddress of that account. Because can not reformat from evm address to substrate address
|
|
76
|
+
return reformatAddress(alternativeAddress, addressPrefix);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// can not reformat without substrateAddress info
|
|
80
|
+
return address;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// reformat as usual with substrate address
|
|
84
|
+
return reformatAddress(address, addressPrefix);
|
|
85
|
+
}
|
|
86
|
+
if (chainType === AccountChainType.TON || chainType === AccountChainType.CARDANO) {
|
|
87
|
+
return reformatAddress(address, chainInfo.isTestnet ? 0 : 1);
|
|
53
88
|
}
|
|
89
|
+
return address;
|
|
54
90
|
};
|
|
55
91
|
export const getAccountChainTypeForAddress = address => {
|
|
56
92
|
const type = getKeypairTypeByAddress(address);
|
package/utils/fee/transfer.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface CalculateMaxTransferable extends TransactionFee {
|
|
|
20
20
|
isTransferNativeTokenAndPayLocalTokenAsFee: boolean;
|
|
21
21
|
nativeToken: _ChainAsset;
|
|
22
22
|
transferAll?: boolean;
|
|
23
|
+
metadata?: Record<string, any>;
|
|
23
24
|
}
|
|
24
25
|
export declare const detectTransferTxType: (srcToken: _ChainAsset, srcChain: _ChainInfo, destChain: _ChainInfo) => FeeChainType;
|
|
25
26
|
export declare const calculateMaxTransferable: (id: string, request: CalculateMaxTransferable, freeBalance: AmountData, fee: FeeInfo) => Promise<ResponseSubscribeTransfer>;
|