From d7cb7f161ae9d19eeaf1397d5eb9c28d2334a74c Mon Sep 17 00:00:00 2001 From: Oleksii Date: Mon, 30 Dec 2024 17:33:50 +0000 Subject: [PATCH] Feat/live 15540 aptos send receive fix when send max is toggled on the 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 --- .../src/families/aptos/buildTransaction.ts | 17 ++--------------- .../src/families/aptos/logic.ts | 2 +- .../src/families/aptos/prepareTransaction.ts | 11 ++++++++++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/libs/ledger-live-common/src/families/aptos/buildTransaction.ts b/libs/ledger-live-common/src/families/aptos/buildTransaction.ts index 8e24d6a0b699..b0cc76af3249 100644 --- a/libs/ledger-live-common/src/families/aptos/buildTransaction.ts +++ b/libs/ledger-live-common/src/families/aptos/buildTransaction.ts @@ -3,12 +3,7 @@ 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 ( @@ -16,15 +11,7 @@ const buildTransaction = async ( transaction: Transaction, aptosClient: AptosAPI, ): Promise => { - 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); diff --git a/libs/ledger-live-common/src/families/aptos/logic.ts b/libs/ledger-live-common/src/families/aptos/logic.ts index 39f9ba7ceb8f..9d7c554c1355 100644 --- a/libs/ledger-live-common/src/families/aptos/logic.ts +++ b/libs/ledger-live-common/src/families/aptos/logic.ts @@ -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+/; diff --git a/libs/ledger-live-common/src/families/aptos/prepareTransaction.ts b/libs/ledger-live-common/src/families/aptos/prepareTransaction.ts index d32884f0a231..03e16465421e 100644 --- a/libs/ledger-live-common/src/families/aptos/prepareTransaction.ts +++ b/libs/ledger-live-common/src/families/aptos/prepareTransaction.ts @@ -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, @@ -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