Skip to content

Commit

Permalink
Merge pull request #208 from Cryptorubic/develop
Browse files Browse the repository at this point in the history
2.17.1 version
  • Loading branch information
ko1ebayev authored Sep 19, 2022
2 parents 126bb9a + f4e1f5b commit d5a3144
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 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": "2.17.0",
"version": "2.17.1",
"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 @@ -100,7 +100,9 @@ export class LifiCrossChainTradeProvider extends CrossChainTradeProvider {
const result = await this.lifi.getRoutes(routesRequest);
const { routes } = result;

const bestRoute = routes.find(route => !route.containsSwitchChain);
const bestRoute = routes.find(
route => route.steps.length === 1 && !route.containsSwitchChain
);

if (!bestRoute) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ContractParams } from 'src/features/cross-chain/models/contract-params'
import { commonCrossChainAbi } from 'src/features/cross-chain/providers/common/constants/common-cross-chain-abi';
import { BRIDGE_TYPE, BridgeType } from 'src/features/cross-chain/constants/bridge-type';
import { FeeInfo } from '../common/models/fee';
import { LifiTransactionRequest } from './models/lifi-transaction-request';

/**
* Calculated Celer cross chain trade.
Expand Down Expand Up @@ -197,7 +198,7 @@ export class LifiCrossChainTrade extends CrossChainTrade {
}

public async getContractParams(options: SwapTransactionOptions): Promise<ContractParams> {
const data = await this.getSwapData(options?.receiverAddress);
const { data, value } = await this.getSwapData(options?.receiverAddress);
const toChainId = BlockchainsInfo.getBlockchainByName(this.to.blockchain).id;
const fromContracts = lifiContractAddress[this.fromBlockchain];

Expand All @@ -218,20 +219,19 @@ export class LifiCrossChainTrade extends CrossChainTrade {
}
methodArguments.push(data);

const sourceValue = this.from.isNative ? this.from.stringWeiAmount : '0';
const fixedFee = Web3Pure.toWei(this.feeInfo?.fixedFee?.amount || 0);
const value = new BigNumber(sourceValue).plus(fixedFee).toFixed(0);
const msgValue = new BigNumber(value ? `${value}` : 0).plus(fixedFee).toFixed(0);

return {
contractAddress: this.fromContractAddress,
contractAbi: commonCrossChainAbi,
methodName: this.methodName,
methodArguments,
value
value: msgValue
};
}

private async getSwapData(receiverAddress?: string): Promise<string> {
private async getSwapData(receiverAddress?: string): Promise<LifiTransactionRequest> {
const firstStep = this.route.steps[0]!;
const step = {
...firstStep,
Expand All @@ -253,15 +253,12 @@ export class LifiCrossChainTrade extends CrossChainTrade {
}
};

const swapResponse: {
transactionRequest: {
data: string;
};
} = await this.httpClient.post('https://li.quest/v1/advanced/stepTransaction', {
...step
});
const swapResponse: { transactionRequest: LifiTransactionRequest } =
await this.httpClient.post('https://li.quest/v1/advanced/stepTransaction', {
...step
});

return swapResponse.transactionRequest.data;
return swapResponse.transactionRequest;
}

public getTradeAmountRatio(fromUsd: BigNumber): BigNumber {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface LifiTransactionRequest {
data: string;
value: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class ViaCrossChainTrade extends CrossChainTrade {

await this.checkProviderIsWhitelisted(providerRouter, providerGateway);

const sourceValue = this.from.isNative ? this.from.stringWeiAmount : '0';
const sourceValue = new BigNumber(swapTransaction.value || 0);
const fixedFee = Web3Pure.toWei(this.feeInfo?.fixedFee?.amount || 0);
const value = new BigNumber(sourceValue).plus(fixedFee).toFixed(0);

Expand Down

0 comments on commit d5a3144

Please sign in to comment.