Skip to content

Commit

Permalink
Fix Number <-> BigNumber consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
may01 committed Jan 9, 2025
1 parent a535836 commit 9e0949c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type IGetEstimatedGasReturnType = {
};

const CACHE = {
amount: BigNumber(0),
amount: new BigNumber(0),
estimate: Promise.resolve({
fees: new BigNumber(0),
estimate: {
Expand All @@ -34,7 +34,7 @@ export const getFee = async (
aptosClient: AptosAPI,
): Promise<IGetEstimatedGasReturnType> => {
const res = {
fees: new BigNumber(DEFAULT_GAS * DEFAULT_GAS_PRICE),
fees: new BigNumber(DEFAULT_GAS).multipliedBy(DEFAULT_GAS_PRICE),
estimate: {
maxGasAmount: DEFAULT_GAS.toString(),
gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
Expand All @@ -55,10 +55,10 @@ export const getFee = async (
const simulation = await aptosClient.simulateTransaction(publicKeyEd, tx);
const completedTx = simulation[0];

gasLimit = Number(completedTx.gas_used) * ESTIMATE_GAS_MUL;
gasPrice = Number(completedTx.gas_unit_price);
gasLimit = new BigNumber(completedTx.gas_used).multipliedBy(ESTIMATE_GAS_MUL);
gasPrice = new BigNumber(completedTx.gas_unit_price);

const expectedGas = BigNumber(gasPrice * gasLimit);
const expectedGas = gasPrice.multipliedBy(gasLimit);

const isUnderMaxSpendable = transaction.amount
.plus(expectedGas)
Expand All @@ -75,7 +75,7 @@ export const getFee = async (
}
}
}
res.fees = BigNumber(gasPrice).multipliedBy(BigNumber(gasLimit));
res.fees = expectedGas;
res.estimate.maxGasAmount = gasLimit.toString();
res.estimate.gasUnitPrice = completedTx.gas_unit_price;
} catch (error: any) {
Expand Down
6 changes: 3 additions & 3 deletions libs/ledger-live-common/src/families/aptos/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
} from "./constants";
import type { AptosTransaction, TransactionOptions } from "./types";

export const DEFAULT_GAS = 200;
export const DEFAULT_GAS_PRICE = 100;
export const ESTIMATE_GAS_MUL = 1.0; // define buffer for gas estimation change here, if needed
export const DEFAULT_GAS = new BigNumber(200);
export const DEFAULT_GAS_PRICE = new BigNumber(100);
export const ESTIMATE_GAS_MUL = new BigNumber(1.0); // define buffer for gas estimation change here, if needed

const CLEAN_HEX_REGEXP = /^0x0*|^0+/;

Expand Down

0 comments on commit 9e0949c

Please sign in to comment.