@@ -6,7 +6,7 @@ import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/K
6
6
import { validateTypedSignMessageDataV3V4 } from '@subwallet/extension-base/core/logic-validation' ;
7
7
import { estimateTxFee , getERC20Allowance , getERC20SpendingApprovalTx } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3' ;
8
8
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' ;
10
10
import TransactionService from '@subwallet/extension-base/services/transaction-service' ;
11
11
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' ;
12
12
import { _reformatAddressWithChain } from '@subwallet/extension-base/utils' ;
@@ -20,6 +20,7 @@ import { _getAssetOriginChain, _getChainNativeTokenSlug, _getContractAddressOfTo
20
20
import FeeService from '../../fee-service/service' ;
21
21
import { calculateGasFeeParams } from '../../fee-service/utils' ;
22
22
import { SwapBaseHandler , SwapBaseInterface } from './base-handler' ;
23
+ import { DEFAULT_EXCESS_AMOUNT_WEIGHT , FEE_RATE_MULTIPLIER } from "@subwallet/extension-base/services/swap-service/utils" ;
23
24
24
25
const API_URL = 'https://trade-api.gateway.uniswap.org/v1' ;
25
26
const headers = {
@@ -482,7 +483,7 @@ export class UniswapHandler implements SwapBaseInterface {
482
483
type : SwapStepType . SWAP ,
483
484
// @ts -ignore
484
485
metadata : {
485
- sendingValue : request . fromAmount . toString ( ) ,
486
+ sendingValue : request . fromAmount . toString ( ) , // todo: * 1.04 in case swap first
486
487
expectedReceive : selectedQuote . toAmount ,
487
488
originTokenInfo,
488
489
destinationTokenInfo,
@@ -523,7 +524,6 @@ export class UniswapHandler implements SwapBaseInterface {
523
524
const toTokenInfo = this . chainService . getAssetBySlug ( bridgePairInfo . pair . to ) ;
524
525
const fromChainInfo = this . chainService . getChainInfoByKey ( fromTokenInfo . originChain ) ;
525
526
const toChainInfo = this . chainService . getChainInfoByKey ( toTokenInfo . originChain ) ;
526
- const isBridgeNativeToken = _isNativeToken ( fromTokenInfo ) ;
527
527
528
528
if ( ! fromChainInfo || ! toChainInfo || ! fromChainInfo || ! toChainInfo ) {
529
529
throw Error ( 'Token or chain not found' ) ;
@@ -535,15 +535,10 @@ export class UniswapHandler implements SwapBaseInterface {
535
535
536
536
if ( isBridgeFirst ) {
537
537
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 ) ;
544
539
} else if ( isBridgeSecond ) {
545
540
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 ) ;
547
542
} else {
548
543
return undefined ;
549
544
}
@@ -576,31 +571,20 @@ export class UniswapHandler implements SwapBaseInterface {
576
571
feeInfo
577
572
} ) ;
578
573
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
+
581
576
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
582
578
583
579
let sendingValue ;
584
580
let expectedReceive ;
585
581
586
582
if ( isBridgeFirst ) {
587
583
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 ) ;
595
585
} 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 ) ;
604
588
} else {
605
589
return undefined ;
606
590
}
0 commit comments