Skip to content

Commit

Permalink
fix bridgers swap with new fee model (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
IDIDOS authored Oct 23, 2024
2 parents c04b6c9 + 0093528 commit 2fd7372
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-sdk",
"version": "5.41.2",
"version": "5.41.3",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
NotSupportedTokensError
} from 'src/common/errors';
import { PriceToken, PriceTokenAmount } from 'src/common/tokens';
import { nativeTokensList } from 'src/common/tokens/constants/native-tokens';
import {
BLOCKCHAIN_NAME,
BlockchainName,
TronBlockchainName
} from 'src/core/blockchain/models/blockchain-name';
import { BlockchainsInfo } from 'src/core/blockchain/utils/blockchains-info/blockchains-info';
import { Web3PublicSupportedBlockchain } from 'src/core/blockchain/web3-public-service/models/web3-public-storage';
import { EvmEncodeConfig } from 'src/core/blockchain/web3-pure/typed-web3-pure/evm-web3-pure/models/evm-encode-config';
import { TronTransactionConfig } from 'src/core/blockchain/web3-pure/typed-web3-pure/tron-web3-pure/models/tron-transaction-config';
import { Web3Pure } from 'src/core/blockchain/web3-pure/web3-pure';
Expand All @@ -22,6 +22,7 @@ import {
BridgersQuoteRequest,
BridgersQuoteResponse
} from 'src/features/common/providers/bridgers/models/bridgers-quote-api';
import { getFromWithoutFee } from 'src/features/common/utils/get-from-without-fee';
import { createTokenNativeAddressProxy } from 'src/features/common/utils/token-native-address-proxy';
import { RequiredCrossChainOptions } from 'src/features/cross-chain/calculation-manager/models/cross-chain-options';
import { CROSS_CHAIN_TRADE_TYPE } from 'src/features/cross-chain/calculation-manager/models/cross-chain-trade-type';
Expand All @@ -33,14 +34,12 @@ import {
import { EvmBridgersCrossChainTrade } from 'src/features/cross-chain/calculation-manager/providers/bridgers-provider/evm-bridgers-trade/evm-bridgers-cross-chain-trade';
import { TronBridgersCrossChainTrade } from 'src/features/cross-chain/calculation-manager/providers/bridgers-provider/tron-bridgers-trade/tron-bridgers-cross-chain-trade';
import { CrossChainProvider } from 'src/features/cross-chain/calculation-manager/providers/common/cross-chain-provider';
import { evmCommonCrossChainAbi } from 'src/features/cross-chain/calculation-manager/providers/common/emv-cross-chain-trade/constants/evm-common-cross-chain-abi';
import { CalculationResult } from 'src/features/cross-chain/calculation-manager/providers/common/models/calculation-result';
import { FeeInfo } from 'src/features/cross-chain/calculation-manager/providers/common/models/fee-info';
import { RubicStep } from 'src/features/cross-chain/calculation-manager/providers/common/models/rubicStep';
import { tronCommonCrossChainAbi } from 'src/features/cross-chain/calculation-manager/providers/common/tron-cross-chain-trade/constants/tron-common-cross-chain-abi';
import { AbiItem } from 'web3-utils';

import { CrossChainTrade } from '../common/cross-chain-trade';
import { ProxyCrossChainEvmTrade } from '../common/proxy-cross-chain-evm-facade/proxy-cross-chain-evm-trade';

export class BridgersCrossChainProvider extends CrossChainProvider {
public readonly type = CROSS_CHAIN_TRADE_TYPE.BRIDGERS;
Expand Down Expand Up @@ -81,25 +80,19 @@ export class BridgersCrossChainProvider extends CrossChainProvider {
try {
const useProxy = options?.useProxy?.[this.type] ?? true;

const contractAbi = BlockchainsInfo.isTronBlockchainName(fromBlockchain)
? tronCommonCrossChainAbi
: evmCommonCrossChainAbi;

let feeInfo = await this.getFeeInfo(
fromBlockchain,
options.providerAddress,
from,
false,
contractAbi
useProxy
);
const fromWithoutFee = getFromWithoutFee(
from,
feeInfo.rubicProxy?.platformFee?.percent
);
// const fromWithoutFee = getFromWithoutFee(
// from,
// feeInfo.rubicProxy?.platformFee?.percent
// );
const fromWithoutFee = from;

const fromTokenAddress = createTokenNativeAddressProxy(
from,
fromWithoutFee,
bridgersNativeAddress,
false
).address;
Expand Down Expand Up @@ -238,21 +231,17 @@ export class BridgersCrossChainProvider extends CrossChainProvider {
}

protected override async getFeeInfo(
fromBlockchain: BridgersCrossChainSupportedBlockchain,
_providerAddress: string,
_percentFeeToken: PriceTokenAmount,
_useProxy: boolean,
_contractAbi: AbiItem[]
fromBlockchain: Web3PublicSupportedBlockchain,
providerAddress: string,
percentFeeToken: PriceTokenAmount,
useProxy: boolean
): Promise<FeeInfo> {
const nativeToken = await PriceToken.createFromToken(nativeTokensList[fromBlockchain]);
return {
rubicProxy: {
fixedFee: {
amount: new BigNumber(0),
token: nativeToken
}
}
};
return ProxyCrossChainEvmTrade.getFeeInfo(
fromBlockchain,
providerAddress,
percentFeeToken,
useProxy
);
}

protected async getRoutePath(
Expand Down

0 comments on commit 2fd7372

Please sign in to comment.