Skip to content

Commit

Permalink
Feat/live 15540 aptos send receive fix when send max is toggled on th…
Browse files Browse the repository at this point in the history
…e amount sent is different in ll and device (#8763)

* Fix the transaction amount that is sent to the device for signing
* remove Gas buffer for maxGasAmount
  • Loading branch information
may01 committed Dec 30, 2024
1 parent 2dca610 commit d7cb7f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
17 changes: 2 additions & 15 deletions libs/ledger-live-common/src/families/aptos/buildTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,15 @@ import type { Account } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";
import { AptosAPI } from "./api";
import { APTOS_ASSET_ID } from "./constants";
import {
DEFAULT_GAS,
DEFAULT_GAS_PRICE,
getMaxSendBalance,
normalizeTransactionOptions,
} from "./logic";
import { normalizeTransactionOptions } from "./logic";
import type { Transaction } from "./types";

const buildTransaction = async (
account: Account,
transaction: Transaction,
aptosClient: AptosAPI,
): Promise<RawTransaction> => {
const amount = transaction.useAllAmount
? getMaxSendBalance(
account.spendableBalance,
new BigNumber(DEFAULT_GAS),
new BigNumber(DEFAULT_GAS_PRICE),
)
: transaction.amount;

const txPayload = getPayload(transaction.recipient, amount);
const txPayload = getPayload(transaction.recipient, transaction.amount);
const txOptions = normalizeTransactionOptions(transaction.options);
const tx = await aptosClient.generateTransaction(account.freshAddress, txPayload, txOptions);

Expand Down
2 changes: 1 addition & 1 deletion libs/ledger-live-common/src/families/aptos/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { AptosTransaction, Transaction } from "./types";

export const DEFAULT_GAS = 200;
export const DEFAULT_GAS_PRICE = 100;
export const ESTIMATE_GAS_MUL = 1.2; // defines buffer for gas estimation change
export const ESTIMATE_GAS_MUL = 1.0; // define buffer for gas estimation change here, if needed

const HEX_REGEXP = /^[-+]?[a-f0-9]+\.?[a-f0-9]*?$/i;
const CLEAN_HEX_REGEXP = /^0x0*|^0+/;
Expand Down
11 changes: 10 additions & 1 deletion libs/ledger-live-common/src/families/aptos/prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BigNumber from "bignumber.js";
import { AptosAPI } from "./api";
import { getEstimatedGas } from "./getFeesForTransaction";
import type { Transaction } from "./types";
import { getMaxSendBalance } from "./logic";
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";

const prepareTransaction = async (
account: Account,
Expand All @@ -25,6 +25,15 @@ const prepareTransaction = async (

const aptosClient = new AptosAPI(account.currency.id);

if (transaction.useAllAmount) {
// we will use this amount in simulation, to estimate gas
transaction.amount = getMaxSendBalance(
account.spendableBalance,
new BigNumber(DEFAULT_GAS),
new BigNumber(DEFAULT_GAS_PRICE),
);
}

const { fees, estimate, errors } = await getEstimatedGas(account, transaction, aptosClient);

const amount = transaction.useAllAmount
Expand Down

0 comments on commit d7cb7f1

Please sign in to comment.