From e0536c5e27a2036919abd0fd182765b32ea0112e Mon Sep 17 00:00:00 2001 From: Samy Rabah Date: Sat, 14 Sep 2024 00:18:29 +0200 Subject: [PATCH] LIVE-12535 fix: add safety margin to estimated fees for hedera (#7798) * fix: add safety margin to estimated fees for hedera * update snap file and add FIXME test --------- Co-authored-by: Tim Schmidt --- .changeset/dry-weeks-bow.md | 5 + .../bridge.integration.test.ts.snap | 92 ++----------------- .../hedera/bridge.integration.test.ts | 3 + .../src/families/hedera/utils.ts | 3 +- 4 files changed, 18 insertions(+), 85 deletions(-) create mode 100644 .changeset/dry-weeks-bow.md diff --git a/.changeset/dry-weeks-bow.md b/.changeset/dry-weeks-bow.md new file mode 100644 index 000000000000..035ace8892aa --- /dev/null +++ b/.changeset/dry-weeks-bow.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/live-common": minor +--- + +Add safety margin to Hedera fee estimates diff --git a/libs/ledger-live-common/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap index a741912274f1..478343849ec2 100644 --- a/libs/ledger-live-common/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap @@ -3,17 +3,17 @@ exports[`hedera currency bridge scanAccounts hedera seed 1 1`] = ` [ { - "balance": "89208179", + "balance": "88059590", "currencyId": "hedera", "derivationMode": "hederaBip44", "freshAddress": "0.0.1040977", "freshAddressPath": "44/3030", "id": "js:2:hedera:0.0.1040977:hederaBip44", "index": 0, - "operationsCount": 5, + "operationsCount": 1, "pendingOperations": [], "seedIdentifier": "9e92a312233d5fd6b5a723875aeea2cea81a8e48ffc00341cff6dffcfd3ab7f2", - "spendableBalance": "89208179", + "spendableBalance": "88059590", "swapHistory": [], "syncHash": undefined, "used": true, @@ -29,87 +29,11 @@ exports[`hedera currency bridge scanAccounts hedera seed 1 2`] = ` "blockHash": null, "blockHeight": 5, "extra": { - "consensusTimestamp": "1704213295.949352003", + "consensusTimestamp": "1721982048.841299095", }, - "fee": "103989", - "hash": "H_sVqT3WhqNwX5Iw-Y_TaIiMy-C_jLTPNCg2fLcyUQqh2prPzMhQsawCmwcN5E_p", - "id": "js:2:hedera:0.0.1040977:hederaBip44-H_sVqT3WhqNwX5Iw-Y_TaIiMy-C_jLTPNCg2fLcyUQqh2prPzMhQsawCmwcN5E_p-OUT", - "recipients": [ - "0.0.98", - ], - "senders": [ - "0.0.1040977", - ], - "type": "OUT", - "value": "103989", - }, - { - "accountId": "js:2:hedera:0.0.1040977:hederaBip44", - "blockHash": null, - "blockHeight": 5, - "extra": { - "consensusTimestamp": "1697645669.026204003", - }, - "fee": "210184", - "hash": "hW0dnb0rNVpglweGCKaPaHlHxr3RqXpoMC9Juz86wDJHZ9e1Hp5WfmfqdzxkWeQC", - "id": "js:2:hedera:0.0.1040977:hederaBip44-hW0dnb0rNVpglweGCKaPaHlHxr3RqXpoMC9Juz86wDJHZ9e1Hp5WfmfqdzxkWeQC-OUT", - "recipients": [ - "0.0.98", - ], - "senders": [ - "0.0.1040977", - ], - "type": "OUT", - "value": "210184", - }, - { - "accountId": "js:2:hedera:0.0.1040977:hederaBip44", - "blockHash": null, - "blockHeight": 5, - "extra": { - "consensusTimestamp": "1657021403.368076000", - }, - "fee": "163081", - "hash": "iQ_oLq-PEMlwmoSEZBXpeK_J9ENApLJnz-uGB3_1XVqtRnMU-0VvdKmJV3E8ig5J", - "id": "js:2:hedera:0.0.1040977:hederaBip44-iQ_oLq-PEMlwmoSEZBXpeK_J9ENApLJnz-uGB3_1XVqtRnMU-0VvdKmJV3E8ig5J-IN", - "recipients": [ - "0.0.1040977", - ], - "senders": [ - "0.0.880760", - ], - "type": "IN", - "value": "99870000", - }, - { - "accountId": "js:2:hedera:0.0.1040977:hederaBip44", - "blockHash": null, - "blockHeight": 5, - "extra": { - "consensusTimestamp": "1669565599.465640003", - }, - "fee": "199161", - "hash": "sBvHuXD8K0xKtonpe7r5WhuM_-0aTZ5up4LEha6buC3jjM_T3v645lxF96XyAKDA", - "id": "js:2:hedera:0.0.1040977:hederaBip44-sBvHuXD8K0xKtonpe7r5WhuM_-0aTZ5up4LEha6buC3jjM_T3v645lxF96XyAKDA-OUT", - "recipients": [ - "0.0.98", - ], - "senders": [ - "0.0.1040977", - ], - "type": "OUT", - "value": "199161", - }, - { - "accountId": "js:2:hedera:0.0.1040977:hederaBip44", - "blockHash": null, - "blockHeight": 5, - "extra": { - "consensusTimestamp": "1701941251.224927003", - }, - "fee": "148487", - "hash": "Zvr0zFzL2meSIoGWe0JlEOhBVetvj3IXH3OJ5Jy7k7zS4xLEIjqV6txRuPYgw3gw", - "id": "js:2:hedera:0.0.1040977:hederaBip44-Zvr0zFzL2meSIoGWe0JlEOhBVetvj3IXH3OJ5Jy7k7zS4xLEIjqV6txRuPYgw3gw-OUT", + "fee": "148589", + "hash": "n0oMavzcRvdYLyQVq0u-yXBIiLftalIoEVknXlNJDG6alDab16np8mcWt9lDg-Hh", + "id": "js:2:hedera:0.0.1040977:hederaBip44-n0oMavzcRvdYLyQVq0u-yXBIiLftalIoEVknXlNJDG6alDab16np8mcWt9lDg-Hh-OUT", "recipients": [ "0.0.2024333", ], @@ -118,7 +42,7 @@ exports[`hedera currency bridge scanAccounts hedera seed 1 2`] = ` "0.0.1040977", ], "type": "OUT", - "value": "10148487", + "value": "1148589", }, ], ] diff --git a/libs/ledger-live-common/src/families/hedera/bridge.integration.test.ts b/libs/ledger-live-common/src/families/hedera/bridge.integration.test.ts index 3275811b32e1..241460636b3a 100644 --- a/libs/ledger-live-common/src/families/hedera/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/hedera/bridge.integration.test.ts @@ -23,6 +23,9 @@ const hedera: CurrenciesData = { ], accounts: [ { + FIXME_tests: [ + "balance is sum of ops", + ], raw: { id: `js:2:hedera:0.0.751515:`, seedIdentifier: "", diff --git a/libs/ledger-live-common/src/families/hedera/utils.ts b/libs/ledger-live-common/src/families/hedera/utils.ts index f1c483476b14..c87b399099e9 100644 --- a/libs/ledger-live-common/src/families/hedera/utils.ts +++ b/libs/ledger-live-common/src/families/hedera/utils.ts @@ -20,7 +20,8 @@ export async function getEstimatedFees(account: Account): Promise { if (data[0]) { return new BigNumber(10000) .dividedBy(new BigNumber(data[0])) - .integerValue(BigNumber.ROUND_CEIL); + .integerValue(BigNumber.ROUND_CEIL) + .multipliedBy(estimatedFeeSafetyRate); } // eslint-disable-next-line no-empty } catch {}