Skip to content

Commit ef415ff

Browse files
committed
[Issue-4321] feat: edit step amount (temp)
1 parent 2c05ed5 commit ef415ff

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

packages/extension-base/src/services/swap-service/handler/base-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ export class SwapBaseHandler {
219219

220220
if (needEditAmount) {
221221
bnSendingValue = BigN(selectedQuote.toAmount).multipliedBy(DEFAULT_EXCESS_AMOUNT_WEIGHT); // need to round
222-
} else {
222+
} else { // todo: remove
223+
console.log('The code cannot run into here, if it runs into here, pls check');
223224
bnSendingValue = BigN(selectedQuote.toAmount);
224225
}
225226
}

packages/extension-base/src/services/swap-service/handler/uniswap-handler.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/K
66
import { validateTypedSignMessageDataV3V4 } from '@subwallet/extension-base/core/logic-validation';
77
import { estimateTxFee, getERC20Allowance, getERC20SpendingApprovalTx } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
88
import { createAcrossBridgeExtrinsic, CreateXcmExtrinsicProps } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
9-
import { getAcrossQuote } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
9+
import { AcrossQuote, getAcrossQuote } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
1010
import TransactionService from '@subwallet/extension-base/services/transaction-service';
1111
import { ApproveStepMetadata, BaseStepDetail, BaseSwapStepMetadata, BasicTxErrorType, CommonOptimalSwapPath, CommonStepFeeInfo, CommonStepType, DynamicSwapType, EvmFeeInfo, FeeOptionKey, GenSwapStepFuncV2, HandleYieldStepData, OptimalSwapPathParamsV2, PermitSwapData, SwapBaseTxData, SwapFeeType, SwapProviderId, SwapStepType, SwapSubmitParams, SwapSubmitStepData, TokenSpendingApprovalParams, ValidateSwapProcessParams } from '@subwallet/extension-base/types';
1212
import { _reformatAddressWithChain } from '@subwallet/extension-base/utils';
@@ -20,6 +20,7 @@ import { _getAssetOriginChain, _getChainNativeTokenSlug, _getContractAddressOfTo
2020
import FeeService from '../../fee-service/service';
2121
import { calculateGasFeeParams } from '../../fee-service/utils';
2222
import { SwapBaseHandler, SwapBaseInterface } from './base-handler';
23+
import {DEFAULT_EXCESS_AMOUNT_WEIGHT, FEE_RATE_MULTIPLIER} from "@subwallet/extension-base/services/swap-service/utils";
2324

2425
const API_URL = 'https://trade-api.gateway.uniswap.org/v1';
2526
const headers = {
@@ -482,7 +483,7 @@ export class UniswapHandler implements SwapBaseInterface {
482483
type: SwapStepType.SWAP,
483484
// @ts-ignore
484485
metadata: {
485-
sendingValue: request.fromAmount.toString(),
486+
sendingValue: request.fromAmount.toString(), // todo: * 1.04 in case swap first
486487
expectedReceive: selectedQuote.toAmount,
487488
originTokenInfo,
488489
destinationTokenInfo,
@@ -523,7 +524,6 @@ export class UniswapHandler implements SwapBaseInterface {
523524
const toTokenInfo = this.chainService.getAssetBySlug(bridgePairInfo.pair.to);
524525
const fromChainInfo = this.chainService.getChainInfoByKey(fromTokenInfo.originChain);
525526
const toChainInfo = this.chainService.getChainInfoByKey(toTokenInfo.originChain);
526-
const isBridgeNativeToken = _isNativeToken(fromTokenInfo);
527527

528528
if (!fromChainInfo || !toChainInfo || !fromChainInfo || !toChainInfo) {
529529
throw Error('Token or chain not found');
@@ -535,15 +535,10 @@ export class UniswapHandler implements SwapBaseInterface {
535535

536536
if (isBridgeFirst) {
537537
receiverAddress = _reformatAddressWithChain(request.address, toChainInfo);
538-
539-
if (isBridgeNativeToken) {
540-
mockSendingValue = BigNumber(selectedQuote.fromAmount).multipliedBy(1.02).toFixed(0, 1);
541-
} else {
542-
mockSendingValue = selectedQuote.fromAmount;
543-
}
538+
mockSendingValue = BigNumber(selectedQuote.fromAmount).toFixed(0, 1);
544539
} else if (isBridgeSecond) {
545540
receiverAddress = _reformatAddressWithChain(request.recipient || request.address, toChainInfo);
546-
mockSendingValue = BigNumber(selectedQuote.toAmount).div(1.02).toFixed(0, 1);
541+
mockSendingValue = BigNumber(selectedQuote.toAmount).toFixed(0, 1);
547542
} else {
548543
return undefined;
549544
}
@@ -576,31 +571,20 @@ export class UniswapHandler implements SwapBaseInterface {
576571
feeInfo
577572
});
578573

579-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
580-
const destinationFee = BigNumber(mockSendingValue).minus(acrossQuote.metadata.outputAmount).toFixed(0, 1);
574+
const acrossQuoteMetadata = acrossQuote.metadata as AcrossQuote;
575+
581576
const estimatedBridgeFee = await estimateTxFee(tx, evmApi, feeInfo);
577+
const estimatedDestinationFee = BigNumber(mockSendingValue).minus(acrossQuoteMetadata.outputAmount).toFixed(0, 1); // todo: should better handle on backend and return desFee metadata instead of minus like this
582578

583579
let sendingValue;
584580
let expectedReceive;
585581

586582
if (isBridgeFirst) {
587583
expectedReceive = selectedQuote.fromAmount;
588-
sendingValue = BigNumber(destinationFee).multipliedBy(1.02).plus(expectedReceive).toFixed(0, 1);
589-
590-
// if (isBridgeNativeToken) {
591-
// sendingValue = BigNumber(expectedReceive).plus(estimatedBridgeFee).toFixed(0, 1);
592-
// } else {
593-
// sendingValue = BigNumber(expectedReceive).toFixed(0, 1);
594-
// }
584+
sendingValue = BigNumber(estimatedDestinationFee).multipliedBy(FEE_RATE_MULTIPLIER.medium).plus(selectedQuote.fromAmount).toFixed(0, 1);
595585
} else if (isBridgeSecond) {
596-
sendingValue = BigNumber(selectedQuote.toAmount).div(1.02).toFixed(0, 1);
597-
expectedReceive = BigNumber(sendingValue).minus(destinationFee).toFixed(0, 1);
598-
599-
// if (isBridgeNativeToken) {
600-
// expectedReceive = BigNumber(sendingValue).minus(estimatedBridgeFee).toFixed(0, 1);
601-
// } else {
602-
// expectedReceive = sendingValue;
603-
// }
586+
expectedReceive = selectedQuote.toAmount;
587+
sendingValue = BigNumber(selectedQuote.toAmount).multipliedBy(DEFAULT_EXCESS_AMOUNT_WEIGHT).toFixed(0, 1);
604588
} else {
605589
return undefined;
606590
}

0 commit comments

Comments
 (0)