@subwallet/extension-base 1.3.29-0 → 1.3.30-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +4 -4
- package/background/errors/SwapError.js +1 -1
- package/cjs/background/errors/SwapError.js +1 -1
- package/cjs/constants/blocked-actions.js +2 -2
- package/cjs/constants/remind-notification-time.js +3 -3
- package/cjs/core/logic-validation/swap.js +63 -4
- package/cjs/core/utils.js +9 -3
- package/cjs/koni/background/handlers/Extension.js +5 -82
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/earning-service/handlers/base.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -1
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +68 -50
- package/cjs/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/cjs/services/earning-service/service.js +2 -1
- package/cjs/services/fee-service/utils/index.js +16 -4
- package/cjs/services/inapp-notification-service/index.js +19 -13
- package/cjs/services/swap-service/handler/asset-hub/handler.js +61 -314
- package/cjs/services/swap-service/handler/base-handler.js +393 -231
- package/cjs/services/swap-service/handler/chainflip-handler.js +18 -40
- package/cjs/services/swap-service/handler/hydradx-handler.js +77 -269
- package/cjs/services/swap-service/handler/simpleswap-handler.js +27 -48
- package/cjs/services/swap-service/handler/uniswap-handler.js +33 -54
- package/cjs/services/swap-service/index.js +154 -143
- package/cjs/services/swap-service/utils.js +107 -17
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/types/swap/index.js +13 -1
- package/cjs/utils/swap.js +5 -1
- package/constants/blocked-actions.d.ts +1 -1
- package/constants/blocked-actions.js +1 -1
- package/constants/remind-notification-time.d.ts +1 -1
- package/constants/remind-notification-time.js +1 -1
- package/core/logic-validation/swap.d.ts +15 -0
- package/core/logic-validation/swap.js +60 -4
- package/core/utils.js +9 -3
- package/koni/background/handlers/Extension.d.ts +0 -1
- package/koni/background/handlers/Extension.js +6 -83
- package/package.json +6 -12
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/services/base/types.d.ts +0 -4
- package/services/chain-service/constants.js +1 -1
- package/services/earning-service/handlers/base.d.ts +4 -3
- package/services/earning-service/handlers/base.js +6 -4
- package/services/earning-service/handlers/native-staking/base.js +4 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +9 -6
- package/services/earning-service/handlers/native-staking/dtao.js +69 -48
- package/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +2 -1
- package/services/fee-service/utils/index.d.ts +1 -0
- package/services/fee-service/utils/index.js +14 -4
- package/services/inapp-notification-service/index.js +13 -7
- package/services/swap-service/handler/asset-hub/handler.d.ts +2 -9
- package/services/swap-service/handler/asset-hub/handler.js +64 -317
- package/services/swap-service/handler/base-handler.d.ts +6 -9
- package/services/swap-service/handler/base-handler.js +391 -229
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -4
- package/services/swap-service/handler/chainflip-handler.js +15 -37
- package/services/swap-service/handler/hydradx-handler.d.ts +3 -10
- package/services/swap-service/handler/hydradx-handler.js +78 -270
- package/services/swap-service/handler/simpleswap-handler.d.ts +2 -4
- package/services/swap-service/handler/simpleswap-handler.js +24 -45
- package/services/swap-service/handler/uniswap-handler.d.ts +4 -6
- package/services/swap-service/handler/uniswap-handler.js +25 -46
- package/services/swap-service/index.d.ts +8 -14
- package/services/swap-service/index.js +141 -129
- package/services/swap-service/utils.d.ts +11 -3
- package/services/swap-service/utils.js +96 -15
- package/services/transaction-service/index.js +2 -2
- package/types/service-base.d.ts +2 -3
- package/types/swap/index.d.ts +25 -9
- package/types/swap/index.js +10 -0
- package/types/transaction/process.d.ts +19 -0
- package/types/yield/actions/join/submit.d.ts +4 -1
- package/types/yield/actions/others.d.ts +2 -0
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +3 -0
- package/cjs/services/swap-service/interface.js +0 -14
- package/services/swap-service/interface.d.ts +0 -9
- package/services/swap-service/interface.js +0 -8
|
@@ -12,7 +12,6 @@ var _smartContract = require("@subwallet/extension-base/services/balance-service
|
|
|
12
12
|
var _token = require("@subwallet/extension-base/services/balance-service/transfer/token");
|
|
13
13
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
14
14
|
var _baseHandler = require("@subwallet/extension-base/services/swap-service/handler/base-handler");
|
|
15
|
-
var _interface = require("@subwallet/extension-base/services/swap-service/interface");
|
|
16
15
|
var _utils2 = require("@subwallet/extension-base/services/swap-service/utils");
|
|
17
16
|
var _types = require("@subwallet/extension-base/types");
|
|
18
17
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
@@ -61,33 +60,6 @@ class ChainflipSwapHandler {
|
|
|
61
60
|
return INTERMEDIARY_MAINNET_ASSET_SLUG;
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
|
-
async validateSwapProcess(params) {
|
|
65
|
-
const amount = params.selectedQuote.fromAmount;
|
|
66
|
-
const bnAmount = new _bignumber.default(amount);
|
|
67
|
-
if (bnAmount.lte(0)) {
|
|
68
|
-
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')];
|
|
69
|
-
}
|
|
70
|
-
let isXcmOk = false;
|
|
71
|
-
for (const [index, step] of params.process.steps.entries()) {
|
|
72
|
-
const getErrors = async () => {
|
|
73
|
-
switch (step.type) {
|
|
74
|
-
case _types.CommonStepType.DEFAULT:
|
|
75
|
-
return Promise.resolve([]);
|
|
76
|
-
case _types.CommonStepType.TOKEN_APPROVAL:
|
|
77
|
-
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
|
|
78
|
-
default:
|
|
79
|
-
return this.swapBaseHandler.validateSwapStep(params, isXcmOk, index);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const errors = await getErrors();
|
|
83
|
-
if (errors.length) {
|
|
84
|
-
return errors;
|
|
85
|
-
} else if (step.type === _types.CommonStepType.XCM) {
|
|
86
|
-
isXcmOk = true;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
63
|
async handleSubmitStep(params) {
|
|
92
64
|
const {
|
|
93
65
|
address,
|
|
@@ -106,7 +78,7 @@ class ChainflipSwapHandler {
|
|
|
106
78
|
const toAssetId = (0, _utils._getAssetSymbol)(toAsset);
|
|
107
79
|
const minReceive = new _bignumber.default(quote.rate).times(1 - slippage).toString();
|
|
108
80
|
const processMetadata = params.process.steps[params.currentStep].metadata;
|
|
109
|
-
const quoteMetadata =
|
|
81
|
+
const quoteMetadata = processMetadata;
|
|
110
82
|
if (!processMetadata || !quoteMetadata) {
|
|
111
83
|
throw new Error('Metadata for Chainflip not found');
|
|
112
84
|
}
|
|
@@ -214,7 +186,7 @@ class ChainflipSwapHandler {
|
|
|
214
186
|
return this.handleSubmitStep(params);
|
|
215
187
|
}
|
|
216
188
|
}
|
|
217
|
-
async getSubmitStep(params) {
|
|
189
|
+
async getSubmitStep(params, stepIndex) {
|
|
218
190
|
var _params$selectedQuote;
|
|
219
191
|
const metadata = (_params$selectedQuote = params.selectedQuote) === null || _params$selectedQuote === void 0 ? void 0 : _params$selectedQuote.metadata;
|
|
220
192
|
if (!params.selectedQuote) {
|
|
@@ -223,22 +195,28 @@ class ChainflipSwapHandler {
|
|
|
223
195
|
if (!metadata || !metadata.srcChain || !metadata.destChain) {
|
|
224
196
|
return Promise.resolve(undefined);
|
|
225
197
|
}
|
|
198
|
+
const originTokenInfo = this.chainService.getAssetBySlug(params.selectedQuote.pair.from);
|
|
199
|
+
const destinationTokenInfo = this.chainService.getAssetBySlug(params.selectedQuote.pair.to);
|
|
200
|
+
const originChain = this.chainService.getChainInfoByKey(originTokenInfo.originChain);
|
|
201
|
+
const destinationChain = this.chainService.getChainInfoByKey(destinationTokenInfo.originChain);
|
|
226
202
|
const submitStep = {
|
|
227
203
|
name: 'Swap',
|
|
228
204
|
type: _types.SwapStepType.SWAP,
|
|
205
|
+
// @ts-ignore
|
|
229
206
|
metadata: {
|
|
230
207
|
sendingValue: params.request.fromAmount.toString(),
|
|
231
|
-
|
|
232
|
-
|
|
208
|
+
expectedReceive: params.selectedQuote.toAmount,
|
|
209
|
+
originTokenInfo,
|
|
210
|
+
destinationTokenInfo,
|
|
211
|
+
sender: (0, _utils3._reformatAddressWithChain)(params.request.address, originChain),
|
|
212
|
+
receiver: (0, _utils3._reformatAddressWithChain)(params.request.recipient || params.request.address, destinationChain),
|
|
233
213
|
srcChain: metadata.srcChain,
|
|
234
|
-
destChain: metadata.destChain
|
|
214
|
+
destChain: metadata.destChain,
|
|
215
|
+
version: 2
|
|
235
216
|
}
|
|
236
217
|
};
|
|
237
218
|
return Promise.resolve([submitStep, params.selectedQuote.feeInfo]);
|
|
238
219
|
}
|
|
239
|
-
generateOptimalProcess(params) {
|
|
240
|
-
return this.swapBaseHandler.generateOptimalProcess(params, [this.getSubmitStep.bind(this)]);
|
|
241
|
-
}
|
|
242
220
|
generateOptimalProcessV2(params) {
|
|
243
221
|
return this.swapBaseHandler.generateOptimalProcessV2(params, [this.getSubmitStep.bind(this)]);
|
|
244
222
|
}
|
|
@@ -255,10 +233,10 @@ class ChainflipSwapHandler {
|
|
|
255
233
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')];
|
|
256
234
|
}
|
|
257
235
|
const actionList = JSON.stringify(process.path.map(step => step.action));
|
|
258
|
-
const swap = actionList === JSON.stringify([
|
|
259
|
-
const swapXcm = actionList === JSON.stringify([
|
|
260
|
-
const xcmSwap = actionList === JSON.stringify([
|
|
261
|
-
const xcmSwapXcm = actionList === JSON.stringify([
|
|
236
|
+
const swap = actionList === JSON.stringify([_types.DynamicSwapType.SWAP]);
|
|
237
|
+
const swapXcm = actionList === JSON.stringify([_types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
238
|
+
const xcmSwap = actionList === JSON.stringify([_types.DynamicSwapType.BRIDGE, _types.DynamicSwapType.SWAP]);
|
|
239
|
+
const xcmSwapXcm = actionList === JSON.stringify([_types.DynamicSwapType.BRIDGE, _types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
262
240
|
const swapIndex = params.process.steps.findIndex(step => step.type === _types.SwapStepType.SWAP); // todo
|
|
263
241
|
|
|
264
242
|
if (swapIndex <= -1) {
|
|
@@ -5,21 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.HydradxHandler = void 0;
|
|
8
|
-
var _sdk = require("@galacticcouncil/sdk");
|
|
9
8
|
var _chainList = require("@subwallet/chain-list");
|
|
10
9
|
var _SwapError = require("@subwallet/extension-base/background/errors/SwapError");
|
|
11
10
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
12
11
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
13
|
-
var _constants = require("@subwallet/extension-base/constants");
|
|
14
|
-
var _xcm = require("@subwallet/extension-base/services/balance-service/transfer/xcm");
|
|
15
12
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
16
13
|
var _baseHandler = require("@subwallet/extension-base/services/swap-service/handler/base-handler");
|
|
17
|
-
var _interface = require("@subwallet/extension-base/services/swap-service/interface");
|
|
18
14
|
var _utils2 = require("@subwallet/extension-base/services/swap-service/utils");
|
|
19
15
|
var _types = require("@subwallet/extension-base/types");
|
|
20
16
|
var _serviceBase = require("@subwallet/extension-base/types/service-base");
|
|
21
17
|
var _swap = require("@subwallet/extension-base/types/swap");
|
|
22
|
-
var
|
|
18
|
+
var _utils3 = require("@subwallet/extension-base/utils");
|
|
19
|
+
var _subwalletApiSdk = _interopRequireDefault(require("@subwallet/subwallet-api-sdk"));
|
|
23
20
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
24
21
|
var _util = require("@polkadot/util");
|
|
25
22
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
@@ -49,10 +46,6 @@ class HydradxHandler {
|
|
|
49
46
|
if (!chainState.active) {
|
|
50
47
|
await this.chainService.enableChain(this.chain());
|
|
51
48
|
}
|
|
52
|
-
const substrateApi = this.chainService.getSubstrateApi(this.chain());
|
|
53
|
-
await substrateApi.api.isReady;
|
|
54
|
-
const poolService = new _sdk.PoolService(substrateApi.api);
|
|
55
|
-
this.tradeRouter = new _sdk.TradeRouter(poolService);
|
|
56
49
|
this.isReady = true;
|
|
57
50
|
}
|
|
58
51
|
chain = () => {
|
|
@@ -78,75 +71,6 @@ class HydradxHandler {
|
|
|
78
71
|
get slug() {
|
|
79
72
|
return this.swapBaseHandler.slug;
|
|
80
73
|
}
|
|
81
|
-
async getXcmStep(params) {
|
|
82
|
-
const bnAmount = new _bignumber.default(params.request.fromAmount);
|
|
83
|
-
const fromAsset = this.chainService.getAssetBySlug(params.request.pair.from);
|
|
84
|
-
const fromAssetBalance = await this.balanceService.getTransferableBalance(params.request.address, fromAsset.originChain, fromAsset.slug);
|
|
85
|
-
const bnFromAssetBalance = new _bignumber.default(fromAssetBalance.value);
|
|
86
|
-
if (bnFromAssetBalance.gte(bnAmount)) {
|
|
87
|
-
return undefined; // enough balance, no need to xcm
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const alternativeAssetSlug = (0, _utils2.getSwapAlternativeAsset)(params.request.pair);
|
|
91
|
-
if (!alternativeAssetSlug) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
const alternativeAsset = this.chainService.getAssetBySlug(alternativeAssetSlug);
|
|
95
|
-
const alternativeAssetBalance = await this.balanceService.getTransferableBalance(params.request.address, alternativeAsset.originChain, alternativeAsset.slug);
|
|
96
|
-
const bnAlternativeAssetBalance = new _bignumber.default(alternativeAssetBalance.value);
|
|
97
|
-
if (bnAlternativeAssetBalance.lte(0)) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
const alternativeChainInfo = this.chainService.getChainInfoByKey(alternativeAsset.originChain);
|
|
102
|
-
const destChainInfo = this.chainService.getChainInfoByKey(this.chain());
|
|
103
|
-
const xcmOriginSubstrateApi = await this.chainService.getSubstrateApi(alternativeAsset.originChain).isReady;
|
|
104
|
-
const id = (0, _getId.getId)();
|
|
105
|
-
const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee(id, alternativeAsset.originChain, 'substrate');
|
|
106
|
-
const xcmTransfer = await (0, _xcm.createXcmExtrinsic)({
|
|
107
|
-
originTokenInfo: alternativeAsset,
|
|
108
|
-
destinationTokenInfo: fromAsset,
|
|
109
|
-
// Mock sending value to get payment info
|
|
110
|
-
sendingValue: bnAmount.toString(),
|
|
111
|
-
recipient: params.request.address,
|
|
112
|
-
substrateApi: xcmOriginSubstrateApi,
|
|
113
|
-
sender: params.request.address,
|
|
114
|
-
destinationChain: destChainInfo,
|
|
115
|
-
originChain: alternativeChainInfo,
|
|
116
|
-
feeInfo
|
|
117
|
-
});
|
|
118
|
-
const _xcmFeeInfo = await xcmTransfer.paymentInfo(params.request.address);
|
|
119
|
-
const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
|
|
120
|
-
const fee = {
|
|
121
|
-
feeComponent: [{
|
|
122
|
-
feeType: _swap.SwapFeeType.NETWORK_FEE,
|
|
123
|
-
amount: Math.round(xcmFeeInfo.partialFee * _constants.XCM_MIN_AMOUNT_RATIO).toString(),
|
|
124
|
-
tokenSlug: (0, _utils._getChainNativeTokenSlug)(alternativeChainInfo)
|
|
125
|
-
}],
|
|
126
|
-
defaultFeeToken: (0, _utils._getChainNativeTokenSlug)(alternativeChainInfo),
|
|
127
|
-
feeOptions: [(0, _utils._getChainNativeTokenSlug)(alternativeChainInfo)]
|
|
128
|
-
};
|
|
129
|
-
let bnTransferAmount = bnAmount.minus(bnFromAssetBalance);
|
|
130
|
-
if ((0, _utils._isNativeToken)(alternativeAsset)) {
|
|
131
|
-
const bnXcmFee = new _bignumber.default(fee.feeComponent[0].amount); // xcm fee is paid in native token but swap token is not always native token
|
|
132
|
-
|
|
133
|
-
bnTransferAmount = bnTransferAmount.plus(bnXcmFee);
|
|
134
|
-
}
|
|
135
|
-
const step = {
|
|
136
|
-
metadata: {
|
|
137
|
-
sendingValue: bnTransferAmount.toString(),
|
|
138
|
-
originTokenInfo: alternativeAsset,
|
|
139
|
-
destinationTokenInfo: fromAsset
|
|
140
|
-
},
|
|
141
|
-
name: `Transfer ${alternativeAsset.symbol} from ${alternativeChainInfo.name}`,
|
|
142
|
-
type: _serviceBase.CommonStepType.XCM
|
|
143
|
-
};
|
|
144
|
-
return [step, fee];
|
|
145
|
-
} catch (e) {
|
|
146
|
-
console.error('Error creating xcm step', e);
|
|
147
|
-
return undefined;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
74
|
async getFeeOptionStep(params) {
|
|
151
75
|
if (!params.selectedQuote) {
|
|
152
76
|
return Promise.resolve(undefined);
|
|
@@ -187,173 +111,94 @@ class HydradxHandler {
|
|
|
187
111
|
return undefined;
|
|
188
112
|
}
|
|
189
113
|
}
|
|
190
|
-
async getSubmitStep(params) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
// todo: improve this function for Round 2
|
|
203
|
-
|
|
204
|
-
const xcmPairInfo = (_params$path$find = params.path.find((step, i) => i === 0 && step.action === _interface.DynamicSwapType.BRIDGE)) === null || _params$path$find === void 0 ? void 0 : _params$path$find.pair;
|
|
205
|
-
if (!xcmPairInfo) {
|
|
206
|
-
return undefined;
|
|
207
|
-
}
|
|
208
|
-
const fromTokenInfo = this.chainService.getAssetBySlug(xcmPairInfo.from);
|
|
209
|
-
const toTokenInfo = this.chainService.getAssetBySlug(xcmPairInfo.to);
|
|
210
|
-
const fromChainInfo = this.chainService.getChainInfoByKey(fromTokenInfo.originChain);
|
|
211
|
-
const toChainInfo = this.chainService.getChainInfoByKey(toTokenInfo.originChain);
|
|
212
|
-
if (!fromChainInfo || !toChainInfo || !fromChainInfo || !toChainInfo) {
|
|
213
|
-
throw Error('Token and chain not found');
|
|
214
|
-
}
|
|
215
|
-
try {
|
|
216
|
-
const substrateApi = await this.chainService.getSubstrateApi(fromTokenInfo.originChain).isReady;
|
|
217
|
-
const id = (0, _getId.getId)();
|
|
218
|
-
const [feeInfo, toTokenBalance] = await Promise.all([this.swapBaseHandler.feeService.subscribeChainFee(id, fromTokenInfo.originChain, 'substrate'), this.balanceService.getTotalBalance(params.request.address, toTokenInfo.originChain, toTokenInfo.slug, _KoniTypes.ExtrinsicType.TRANSFER_BALANCE)]);
|
|
219
|
-
const xcmTransfer = await (0, _xcm.createXcmExtrinsic)({
|
|
220
|
-
originTokenInfo: fromTokenInfo,
|
|
221
|
-
destinationTokenInfo: toTokenInfo,
|
|
222
|
-
// Mock sending value to get payment info
|
|
223
|
-
sendingValue: params.request.fromAmount,
|
|
224
|
-
recipient: params.request.address,
|
|
225
|
-
substrateApi: substrateApi,
|
|
226
|
-
sender: params.request.address,
|
|
227
|
-
originChain: fromChainInfo,
|
|
228
|
-
destinationChain: toChainInfo,
|
|
229
|
-
feeInfo
|
|
230
|
-
});
|
|
231
|
-
const _xcmFeeInfo = await xcmTransfer.paymentInfo(params.request.address);
|
|
232
|
-
const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
|
|
233
|
-
const fee = {
|
|
234
|
-
feeComponent: [{
|
|
235
|
-
feeType: _swap.SwapFeeType.NETWORK_FEE,
|
|
236
|
-
amount: Math.ceil(xcmFeeInfo.partialFee * _utils2.FEE_RATE_MULTIPLIER.high).toString(),
|
|
237
|
-
tokenSlug: (0, _utils._getChainNativeTokenSlug)(fromChainInfo)
|
|
238
|
-
}],
|
|
239
|
-
defaultFeeToken: (0, _utils._getChainNativeTokenSlug)(fromChainInfo),
|
|
240
|
-
feeOptions: [(0, _utils._getChainNativeTokenSlug)(fromChainInfo)]
|
|
241
|
-
};
|
|
242
|
-
let bnTransferAmount = new _bignumber.default(params.request.fromAmount);
|
|
243
|
-
|
|
244
|
-
// todo: increase transfer amount when XCM local token
|
|
245
|
-
if ((0, _utils._isNativeToken)(fromTokenInfo)) {
|
|
246
|
-
// xcm fee is paid in native token but swap token is not always native token
|
|
247
|
-
// add amount of fee into sending value to ensure has enough token to swap
|
|
248
|
-
const bnXcmFee = new _bignumber.default(fee.feeComponent[0].amount);
|
|
249
|
-
bnTransferAmount = bnTransferAmount.plus(bnXcmFee);
|
|
250
|
-
} else {
|
|
251
|
-
bnTransferAmount = bnTransferAmount.plus((0, _bignumber.default)((0, _utils._getTokenMinAmount)(toTokenInfo)).multipliedBy(_utils2.FEE_RATE_MULTIPLIER.medium));
|
|
252
|
-
}
|
|
253
|
-
if ((0, _bignumber.default)(toTokenBalance.value).lte(0)) {
|
|
254
|
-
bnTransferAmount = bnTransferAmount.plus((0, _utils._getTokenMinAmount)(toTokenInfo));
|
|
255
|
-
}
|
|
256
|
-
const step = {
|
|
257
|
-
metadata: {
|
|
258
|
-
sendingValue: bnTransferAmount.toString(),
|
|
259
|
-
originTokenInfo: fromTokenInfo,
|
|
260
|
-
destinationTokenInfo: toTokenInfo
|
|
261
|
-
},
|
|
262
|
-
name: `Transfer ${fromTokenInfo.symbol} from ${fromChainInfo.name}`,
|
|
263
|
-
type: _serviceBase.CommonStepType.XCM
|
|
264
|
-
};
|
|
265
|
-
return [step, fee];
|
|
266
|
-
} catch (e) {
|
|
267
|
-
console.error('Error creating xcm step', e);
|
|
268
|
-
return undefined;
|
|
114
|
+
async getSubmitStep(params, stepIndex) {
|
|
115
|
+
var _params$selectedQuote;
|
|
116
|
+
const {
|
|
117
|
+
path,
|
|
118
|
+
request: {
|
|
119
|
+
fromAmount
|
|
120
|
+
},
|
|
121
|
+
selectedQuote
|
|
122
|
+
} = params;
|
|
123
|
+
const stepData = path[stepIndex];
|
|
124
|
+
if (stepData.action !== _types.DynamicSwapType.SWAP) {
|
|
125
|
+
return Promise.resolve(undefined);
|
|
269
126
|
}
|
|
270
|
-
|
|
271
|
-
async getSwapStepV2(params) {
|
|
272
|
-
var _params$path$find2;
|
|
273
|
-
const swapPairInfo = (_params$path$find2 = params.path.find(step => step.action === _interface.DynamicSwapType.SWAP)) === null || _params$path$find2 === void 0 ? void 0 : _params$path$find2.pair;
|
|
274
|
-
if (!swapPairInfo) {
|
|
127
|
+
if (!selectedQuote) {
|
|
275
128
|
return Promise.resolve(undefined);
|
|
276
129
|
}
|
|
277
|
-
|
|
130
|
+
const swapPairInfo = stepData.pair;
|
|
131
|
+
if (!swapPairInfo || !selectedQuote) {
|
|
278
132
|
return Promise.resolve(undefined);
|
|
279
133
|
}
|
|
280
|
-
const
|
|
134
|
+
const originTokenInfo = this.chainService.getAssetBySlug(swapPairInfo.from);
|
|
135
|
+
const destinationTokenInfo = this.chainService.getAssetBySlug(swapPairInfo.to);
|
|
136
|
+
const originChain = this.chainService.getChainInfoByKey(originTokenInfo.originChain);
|
|
137
|
+
const destinationChain = this.chainService.getChainInfoByKey(destinationTokenInfo.originChain);
|
|
138
|
+
const sender = (0, _utils3._reformatAddressWithChain)(params.request.address, originChain);
|
|
139
|
+
let receiver = (0, _utils3._reformatAddressWithChain)(params.request.recipient || params.request.address, destinationChain);
|
|
140
|
+
const actionList = JSON.stringify(path.map(step => step.action));
|
|
141
|
+
const xcmSwapXcm = actionList === JSON.stringify([_types.DynamicSwapType.BRIDGE, _types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
142
|
+
const swapXcm = actionList === JSON.stringify([_types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
143
|
+
const needModifyData = swapXcm || xcmSwapXcm;
|
|
144
|
+
let txHex = (_params$selectedQuote = params.selectedQuote) === null || _params$selectedQuote === void 0 ? void 0 : _params$selectedQuote.metadata;
|
|
145
|
+
let bnSendingValue = (0, _bignumber.default)(fromAmount);
|
|
146
|
+
let bnExpectedReceive = (0, _bignumber.default)(selectedQuote.toAmount);
|
|
147
|
+
if (needModifyData) {
|
|
148
|
+
var _subwalletApiSdk$swap;
|
|
149
|
+
// override info if xcm-swap-xcm
|
|
150
|
+
bnSendingValue = bnSendingValue.multipliedBy(_utils2.DEFAULT_EXCESS_AMOUNT_WEIGHT);
|
|
151
|
+
bnExpectedReceive = bnExpectedReceive.multipliedBy(_utils2.DEFAULT_EXCESS_AMOUNT_WEIGHT);
|
|
152
|
+
const quotes = await ((_subwalletApiSdk$swap = _subwalletApiSdk.default.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.fetchSwapQuoteData({
|
|
153
|
+
address: sender,
|
|
154
|
+
pair: {
|
|
155
|
+
from: swapPairInfo.from,
|
|
156
|
+
to: swapPairInfo.to,
|
|
157
|
+
slug: swapPairInfo.slug
|
|
158
|
+
},
|
|
159
|
+
fromAmount: bnSendingValue.toFixed(0, 1),
|
|
160
|
+
slippage: params.request.slippage
|
|
161
|
+
}));
|
|
162
|
+
const quoteAskResponse = quotes === null || quotes === void 0 ? void 0 : quotes.find(quote => quote.provider === this.providerSlug);
|
|
163
|
+
if (!quoteAskResponse || !quoteAskResponse.quote) {
|
|
164
|
+
return Promise.resolve(undefined);
|
|
165
|
+
}
|
|
166
|
+
const overrideQuote = quoteAskResponse.quote;
|
|
167
|
+
txHex = overrideQuote.metadata;
|
|
168
|
+
receiver = (0, _utils3._reformatAddressWithChain)(params.request.address, destinationChain);
|
|
169
|
+
}
|
|
281
170
|
if (!txHex || !(0, _util.isHex)(txHex)) {
|
|
282
171
|
return Promise.resolve(undefined);
|
|
283
172
|
}
|
|
284
|
-
const metadata = {
|
|
285
|
-
sendingValue: params.request.fromAmount.toString(),
|
|
286
|
-
originTokenInfo: this.chainService.getAssetBySlug(swapPairInfo.from),
|
|
287
|
-
destinationTokenInfo: this.chainService.getAssetBySlug(swapPairInfo.to),
|
|
288
|
-
txHex
|
|
289
|
-
};
|
|
290
173
|
const submitStep = {
|
|
291
174
|
name: 'Swap',
|
|
292
175
|
type: _swap.SwapStepType.SWAP,
|
|
293
176
|
// @ts-ignore
|
|
294
|
-
metadata
|
|
177
|
+
metadata: {
|
|
178
|
+
sendingValue: bnSendingValue.toFixed(0, 1),
|
|
179
|
+
expectedReceive: bnExpectedReceive.toFixed(0, 1),
|
|
180
|
+
originTokenInfo,
|
|
181
|
+
destinationTokenInfo,
|
|
182
|
+
sender,
|
|
183
|
+
receiver,
|
|
184
|
+
txHex,
|
|
185
|
+
version: 2
|
|
186
|
+
}
|
|
295
187
|
};
|
|
296
|
-
return Promise.resolve([submitStep,
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
generateOptimalProcess(params) {
|
|
300
|
-
return this.swapBaseHandler.generateOptimalProcess(params, [this.getXcmStep.bind(this),
|
|
301
|
-
// this.getFeeOptionStep.bind(this),
|
|
302
|
-
this.getSubmitStep.bind(this)]);
|
|
188
|
+
return Promise.resolve([submitStep, selectedQuote.feeInfo]);
|
|
303
189
|
}
|
|
304
190
|
generateOptimalProcessV2(params) {
|
|
305
191
|
const stepFuncList = params.path.map(step => {
|
|
306
|
-
if (step.action ===
|
|
307
|
-
return this.
|
|
192
|
+
if (step.action === _types.DynamicSwapType.SWAP) {
|
|
193
|
+
return this.getSubmitStep.bind(this);
|
|
308
194
|
}
|
|
309
|
-
if (step.action ===
|
|
310
|
-
return this.
|
|
195
|
+
if (step.action === _types.DynamicSwapType.BRIDGE) {
|
|
196
|
+
return this.swapBaseHandler.getBridgeStep.bind(this.swapBaseHandler);
|
|
311
197
|
}
|
|
312
198
|
throw new Error(`Error generating optimal process: Action ${step.action} is not supported`);
|
|
313
199
|
});
|
|
314
200
|
return this.swapBaseHandler.generateOptimalProcessV2(params, stepFuncList);
|
|
315
201
|
}
|
|
316
|
-
async handleXcmStep(params) {
|
|
317
|
-
const briefXcmStep = params.process.steps[params.currentStep].metadata;
|
|
318
|
-
if (!briefXcmStep || !briefXcmStep.originTokenInfo || !briefXcmStep.destinationTokenInfo || !briefXcmStep.sendingValue) {
|
|
319
|
-
throw new Error('XCM metadata error');
|
|
320
|
-
}
|
|
321
|
-
const originAsset = briefXcmStep.originTokenInfo;
|
|
322
|
-
const destinationAsset = briefXcmStep.destinationTokenInfo;
|
|
323
|
-
const originChain = this.chainService.getChainInfoByKey(originAsset.originChain);
|
|
324
|
-
const destinationChain = this.chainService.getChainInfoByKey(destinationAsset.originChain);
|
|
325
|
-
const substrateApi = this.chainService.getSubstrateApi(originAsset.originChain);
|
|
326
|
-
const chainApi = await substrateApi.isReady;
|
|
327
|
-
const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee((0, _getId.getId)(), originAsset.originChain, 'substrate');
|
|
328
|
-
const xcmTransfer = await (0, _xcm.createXcmExtrinsic)({
|
|
329
|
-
originTokenInfo: originAsset,
|
|
330
|
-
destinationTokenInfo: destinationAsset,
|
|
331
|
-
sendingValue: briefXcmStep.sendingValue,
|
|
332
|
-
recipient: params.address,
|
|
333
|
-
substrateApi: chainApi,
|
|
334
|
-
sender: params.address,
|
|
335
|
-
destinationChain,
|
|
336
|
-
originChain,
|
|
337
|
-
feeInfo
|
|
338
|
-
});
|
|
339
|
-
const xcmData = {
|
|
340
|
-
originNetworkKey: originAsset.originChain,
|
|
341
|
-
destinationNetworkKey: destinationAsset.originChain,
|
|
342
|
-
from: params.address,
|
|
343
|
-
to: params.address,
|
|
344
|
-
value: briefXcmStep.sendingValue,
|
|
345
|
-
tokenSlug: originAsset.slug,
|
|
346
|
-
showExtraWarning: true
|
|
347
|
-
};
|
|
348
|
-
return {
|
|
349
|
-
txChain: originAsset.originChain,
|
|
350
|
-
extrinsic: xcmTransfer,
|
|
351
|
-
transferNativeAmount: (0, _utils._isNativeToken)(originAsset) ? briefXcmStep.sendingValue : '0',
|
|
352
|
-
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
|
|
353
|
-
chainType: _KoniTypes.ChainType.SUBSTRATE,
|
|
354
|
-
txData: xcmData
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
202
|
async handleSetFeeStep(params) {
|
|
358
203
|
var _swapFeeInfo$selected;
|
|
359
204
|
const substrateApi = this.chainService.getSubstrateApi(this.chain());
|
|
@@ -380,7 +225,7 @@ class HydradxHandler {
|
|
|
380
225
|
}
|
|
381
226
|
async handleSubmitStep(params) {
|
|
382
227
|
const metadata = params.process.steps[params.currentStep].metadata;
|
|
383
|
-
const txHex =
|
|
228
|
+
const txHex = metadata.txHex;
|
|
384
229
|
if (!txHex || !(0, _util.isHex)(txHex)) {
|
|
385
230
|
return new _SwapError.SwapError(_swap.SwapErrorType.UNKNOWN);
|
|
386
231
|
}
|
|
@@ -388,7 +233,7 @@ class HydradxHandler {
|
|
|
388
233
|
throw new Error('Swap metadata error');
|
|
389
234
|
}
|
|
390
235
|
const fromAsset = metadata.originTokenInfo;
|
|
391
|
-
if (!this.isReady
|
|
236
|
+
if (!this.isReady) {
|
|
392
237
|
return new _SwapError.SwapError(_swap.SwapErrorType.UNKNOWN);
|
|
393
238
|
}
|
|
394
239
|
const substrateApi = this.chainService.getSubstrateApi(this.chain());
|
|
@@ -441,7 +286,7 @@ class HydradxHandler {
|
|
|
441
286
|
case _serviceBase.CommonStepType.DEFAULT:
|
|
442
287
|
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
|
|
443
288
|
case _serviceBase.CommonStepType.XCM:
|
|
444
|
-
return this.
|
|
289
|
+
return this.swapBaseHandler.handleBridgeStep(params);
|
|
445
290
|
case _serviceBase.CommonStepType.SET_FEE_TOKEN:
|
|
446
291
|
return this.handleSetFeeStep(params);
|
|
447
292
|
case _swap.SwapStepType.SWAP:
|
|
@@ -450,43 +295,6 @@ class HydradxHandler {
|
|
|
450
295
|
return this.handleSubmitStep(params);
|
|
451
296
|
}
|
|
452
297
|
}
|
|
453
|
-
async validateSwapProcess(params) {
|
|
454
|
-
const amount = params.selectedQuote.fromAmount;
|
|
455
|
-
const bnAmount = new _bignumber.default(amount);
|
|
456
|
-
if (bnAmount.lte(0)) {
|
|
457
|
-
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')];
|
|
458
|
-
}
|
|
459
|
-
const swapStep = params.process.steps.find(item => item.type === _swap.SwapStepType.SWAP);
|
|
460
|
-
if (!swapStep) {
|
|
461
|
-
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR, 'Swap step not found')];
|
|
462
|
-
}
|
|
463
|
-
let isXcmOk = false;
|
|
464
|
-
const currentStep = params.currentStep;
|
|
465
|
-
for (const [index, step] of params.process.steps.entries()) {
|
|
466
|
-
if (currentStep > index) {
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
const getErrors = async () => {
|
|
470
|
-
switch (step.type) {
|
|
471
|
-
case _serviceBase.CommonStepType.DEFAULT:
|
|
472
|
-
return Promise.resolve([]);
|
|
473
|
-
case _serviceBase.CommonStepType.XCM:
|
|
474
|
-
return this.swapBaseHandler.validateXcmStepV2(params, index);
|
|
475
|
-
case _serviceBase.CommonStepType.SET_FEE_TOKEN:
|
|
476
|
-
return this.swapBaseHandler.validateSetFeeTokenStep(params, index);
|
|
477
|
-
default:
|
|
478
|
-
return this.swapBaseHandler.validateSwapStep(params, isXcmOk, index);
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
const errors = await getErrors();
|
|
482
|
-
if (errors.length) {
|
|
483
|
-
return errors;
|
|
484
|
-
} else if (step.type === _serviceBase.CommonStepType.XCM) {
|
|
485
|
-
isXcmOk = true;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
return [];
|
|
489
|
-
}
|
|
490
298
|
async validateSwapProcessV2(params) {
|
|
491
299
|
// todo: recheck address and recipient format in params
|
|
492
300
|
const {
|
|
@@ -500,22 +308,22 @@ class HydradxHandler {
|
|
|
500
308
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')];
|
|
501
309
|
}
|
|
502
310
|
const actionList = JSON.stringify(process.path.map(step => step.action));
|
|
503
|
-
const swap = actionList === JSON.stringify([
|
|
504
|
-
const swapXcm = actionList === JSON.stringify([
|
|
505
|
-
const xcmSwap = actionList === JSON.stringify([
|
|
506
|
-
const xcmSwapXcm = actionList === JSON.stringify([
|
|
311
|
+
const swap = actionList === JSON.stringify([_types.DynamicSwapType.SWAP]);
|
|
312
|
+
const swapXcm = actionList === JSON.stringify([_types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
313
|
+
const xcmSwap = actionList === JSON.stringify([_types.DynamicSwapType.BRIDGE, _types.DynamicSwapType.SWAP]);
|
|
314
|
+
const xcmSwapXcm = actionList === JSON.stringify([_types.DynamicSwapType.BRIDGE, _types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
507
315
|
if (swap) {
|
|
508
316
|
return this.swapBaseHandler.validateSwapOnlyProcess(params, 1); // todo: create interface for input request
|
|
509
317
|
}
|
|
510
318
|
|
|
511
319
|
if (swapXcm) {
|
|
512
|
-
return
|
|
320
|
+
return this.swapBaseHandler.validateSwapXcmProcess(params, 1, 2);
|
|
513
321
|
}
|
|
514
322
|
if (xcmSwap) {
|
|
515
323
|
return this.swapBaseHandler.validateXcmSwapProcess(params, 2, 1);
|
|
516
324
|
}
|
|
517
325
|
if (xcmSwapXcm) {
|
|
518
|
-
return
|
|
326
|
+
return this.swapBaseHandler.validateXcmSwapXcmProcess(params, 2, 1, 3);
|
|
519
327
|
}
|
|
520
328
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR)];
|
|
521
329
|
}
|
|
@@ -8,7 +8,6 @@ var _SwapError = require("@subwallet/extension-base/background/errors/SwapError"
|
|
|
8
8
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
10
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
11
|
-
var _interface = require("@subwallet/extension-base/services/swap-service/interface");
|
|
12
11
|
var _types = require("@subwallet/extension-base/types");
|
|
13
12
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
14
13
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
@@ -70,33 +69,6 @@ class SimpleSwapHandler {
|
|
|
70
69
|
});
|
|
71
70
|
this.providerSlug = _types.SwapProviderId.SIMPLE_SWAP;
|
|
72
71
|
}
|
|
73
|
-
async validateSwapProcess(params) {
|
|
74
|
-
const amount = params.selectedQuote.fromAmount;
|
|
75
|
-
const bnAmount = BigInt(amount);
|
|
76
|
-
if (bnAmount <= BigInt(0)) {
|
|
77
|
-
return Promise.resolve([new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')]);
|
|
78
|
-
}
|
|
79
|
-
let isXcmOk = false;
|
|
80
|
-
for (const [index, step] of params.process.steps.entries()) {
|
|
81
|
-
const getErrors = async () => {
|
|
82
|
-
switch (step.type) {
|
|
83
|
-
case _types.CommonStepType.DEFAULT:
|
|
84
|
-
return Promise.resolve([]);
|
|
85
|
-
case _types.CommonStepType.TOKEN_APPROVAL:
|
|
86
|
-
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
|
|
87
|
-
default:
|
|
88
|
-
return this.swapBaseHandler.validateSwapStep(params, isXcmOk, index);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
const errors = await getErrors();
|
|
92
|
-
if (errors.length) {
|
|
93
|
-
return errors;
|
|
94
|
-
} else if (step.type === _types.CommonStepType.XCM) {
|
|
95
|
-
isXcmOk = true;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
72
|
get chainService() {
|
|
101
73
|
return this.swapBaseHandler.chainService;
|
|
102
74
|
}
|
|
@@ -112,26 +84,32 @@ class SimpleSwapHandler {
|
|
|
112
84
|
get slug() {
|
|
113
85
|
return this.swapBaseHandler.slug;
|
|
114
86
|
}
|
|
115
|
-
generateOptimalProcess(params) {
|
|
116
|
-
return this.swapBaseHandler.generateOptimalProcess(params, [this.getSubmitStep.bind(this)]);
|
|
117
|
-
}
|
|
118
87
|
generateOptimalProcessV2(params) {
|
|
119
88
|
return this.swapBaseHandler.generateOptimalProcessV2(params, [this.getSubmitStep.bind(this)]);
|
|
120
89
|
}
|
|
121
|
-
async getSubmitStep(params) {
|
|
122
|
-
if (params.selectedQuote) {
|
|
123
|
-
|
|
124
|
-
name: 'Swap',
|
|
125
|
-
type: _types.SwapStepType.SWAP,
|
|
126
|
-
metadata: {
|
|
127
|
-
sendingValue: params.request.fromAmount.toString(),
|
|
128
|
-
originTokenInfo: this.chainService.getAssetBySlug(params.selectedQuote.pair.from),
|
|
129
|
-
destinationTokenInfo: this.chainService.getAssetBySlug(params.selectedQuote.pair.to)
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
return Promise.resolve([submitStep, params.selectedQuote.feeInfo]);
|
|
90
|
+
async getSubmitStep(params, stepIndex) {
|
|
91
|
+
if (!params.selectedQuote) {
|
|
92
|
+
return Promise.resolve(undefined);
|
|
133
93
|
}
|
|
134
|
-
|
|
94
|
+
const originTokenInfo = this.chainService.getAssetBySlug(params.selectedQuote.pair.from);
|
|
95
|
+
const destinationTokenInfo = this.chainService.getAssetBySlug(params.selectedQuote.pair.to);
|
|
96
|
+
const originChain = this.chainService.getChainInfoByKey(originTokenInfo.originChain);
|
|
97
|
+
const destinationChain = this.chainService.getChainInfoByKey(destinationTokenInfo.originChain);
|
|
98
|
+
const submitStep = {
|
|
99
|
+
name: 'Swap',
|
|
100
|
+
type: _types.SwapStepType.SWAP,
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
metadata: {
|
|
103
|
+
sendingValue: params.request.fromAmount.toString(),
|
|
104
|
+
expectedReceive: params.selectedQuote.toAmount,
|
|
105
|
+
originTokenInfo,
|
|
106
|
+
destinationTokenInfo,
|
|
107
|
+
sender: (0, _utils2._reformatAddressWithChain)(params.request.address, originChain),
|
|
108
|
+
receiver: (0, _utils2._reformatAddressWithChain)(params.request.recipient || params.request.address, destinationChain),
|
|
109
|
+
version: 2
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return Promise.resolve([submitStep, params.selectedQuote.feeInfo]);
|
|
135
113
|
}
|
|
136
114
|
async handleSwapProcess(params) {
|
|
137
115
|
const {
|
|
@@ -180,6 +158,7 @@ class SimpleSwapHandler {
|
|
|
180
158
|
sender,
|
|
181
159
|
toAsset
|
|
182
160
|
});
|
|
161
|
+
console.log('simpleswap data', id, addressFrom);
|
|
183
162
|
if (!id || id.length === 0 || !addressFrom || addressFrom.length === 0) {
|
|
184
163
|
throw new _SwapError.SwapError(_types.SwapErrorType.UNKNOWN);
|
|
185
164
|
}
|
|
@@ -264,10 +243,10 @@ class SimpleSwapHandler {
|
|
|
264
243
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')];
|
|
265
244
|
}
|
|
266
245
|
const actionList = JSON.stringify(process.path.map(step => step.action));
|
|
267
|
-
const swap = actionList === JSON.stringify([
|
|
268
|
-
const swapXcm = actionList === JSON.stringify([
|
|
269
|
-
const xcmSwap = actionList === JSON.stringify([
|
|
270
|
-
const xcmSwapXcm = actionList === JSON.stringify([
|
|
246
|
+
const swap = actionList === JSON.stringify([_types.DynamicSwapType.SWAP]);
|
|
247
|
+
const swapXcm = actionList === JSON.stringify([_types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
248
|
+
const xcmSwap = actionList === JSON.stringify([_types.DynamicSwapType.BRIDGE, _types.DynamicSwapType.SWAP]);
|
|
249
|
+
const xcmSwapXcm = actionList === JSON.stringify([_types.DynamicSwapType.BRIDGE, _types.DynamicSwapType.SWAP, _types.DynamicSwapType.BRIDGE]);
|
|
271
250
|
const swapIndex = params.process.steps.findIndex(step => step.type === _types.SwapStepType.SWAP); // todo
|
|
272
251
|
|
|
273
252
|
if (swapIndex <= -1) {
|