Skip to content

Commit

Permalink
Feat/live 15542 aptos send receive fix send funds simulation failed w…
Browse files Browse the repository at this point in the history
…hen amount to send is slightly above max spendable amount (#8766)

* Add amount check on unclassified errors
* Fix cached gas that blocked valid transaction

---------

Co-authored-by: João Martins <[email protected]>
  • Loading branch information
may01 and joaoccmartins authored Dec 31, 2024
1 parent e9a6561 commit 089a7da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ export const getFee = async (
const simulation = await aptosClient.simulateTransaction(publicKeyEd, tx);
const completedTx = simulation[0];

if (!completedTx.success) {
const expectedGas = BigNumber(gasLimit * gasPrice);
const isUnderMaxSpendable = !transaction.amount
.plus(expectedGas)
.isGreaterThan(account.spendableBalance);

if (isUnderMaxSpendable && !completedTx.success) {
switch (true) {
case completedTx.vm_status.includes("SEQUENCE_NUMBER"): {
res.errors.sequenceNumber = completedTx.vm_status;
Expand Down Expand Up @@ -97,14 +102,7 @@ export const getFee = async (
res.estimate.sequenceNumber = sequenceNumber.toString();
res.estimate.maxGasAmount = gasLimit.toString();

if (transaction.firstEmulation) {
res.fees = res.fees.plus(BigNumber(gasPrice)).multipliedBy(BigNumber(gasLimit));
} else {
res.fees = res.fees
.plus(transaction.options.gasUnitPrice)
.multipliedBy(BigNumber(transaction.options.maxGasAmount));
}

res.fees = res.fees.plus(BigNumber(gasPrice)).multipliedBy(BigNumber(gasLimit));
CACHE.delete(getCacheKey(transaction));
return res;
};
Expand Down
10 changes: 7 additions & 3 deletions libs/ledger-live-common/src/families/aptos/prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ const prepareTransaction = async (
: transaction.amount;
transaction.amount = amount;

if (transaction.firstEmulation) {
transaction.options.maxGasAmount = estimate.maxGasAmount;
}
transaction.options = {
...transaction.options,
maxGasAmount: estimate.maxGasAmount,
gasUnitPrice: estimate.gasUnitPrice,
sequenceNumber: estimate.sequenceNumber,
expirationTimestampSecs: estimate.expirationTimestampSecs,
};

transaction.fees = fees;
transaction.estimate = estimate;
Expand Down

0 comments on commit 089a7da

Please sign in to comment.