@ledgerhq/coin-vechain 2.9.1 → 2.9.2-nightly.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +16 -4
- package/CHANGELOG.md +19 -0
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +2 -3
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/broadcast.test.d.ts +2 -0
- package/lib/bridge/broadcast.test.d.ts.map +1 -0
- package/lib/bridge/broadcast.test.js +188 -0
- package/lib/bridge/broadcast.test.js.map +1 -0
- package/lib/bridge/buildOptimisticOperatioin.test.d.ts +2 -0
- package/lib/bridge/buildOptimisticOperatioin.test.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperatioin.test.js +286 -0
- package/lib/bridge/buildOptimisticOperatioin.test.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -1
- package/lib/bridge/createTransaction.js +2 -1
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/createTransaction.test.d.ts +2 -0
- package/lib/bridge/createTransaction.test.d.ts.map +1 -0
- package/lib/bridge/createTransaction.test.js +167 -0
- package/lib/bridge/createTransaction.test.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.test.d.ts +2 -0
- package/lib/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.test.js +269 -0
- package/lib/bridge/estimateMaxSpendable.test.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +3 -1
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.test.js +282 -0
- package/lib/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib/bridge/helpers.test.d.ts +2 -0
- package/lib/bridge/helpers.test.d.ts.map +1 -0
- package/lib/bridge/helpers.test.js +298 -0
- package/lib/bridge/helpers.test.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +10 -3
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.test.js +277 -0
- package/lib/bridge/prepareTransaction.test.js.map +1 -0
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +3 -3
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/signOperation.test.d.ts +2 -0
- package/lib/bridge/signOperation.test.d.ts.map +1 -0
- package/lib/bridge/signOperation.test.js +295 -0
- package/lib/bridge/signOperation.test.js.map +1 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +2 -2
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/bridge/transaction.test.d.ts +2 -0
- package/lib/bridge/transaction.test.d.ts.map +1 -0
- package/lib/bridge/transaction.test.js +353 -0
- package/lib/bridge/transaction.test.js.map +1 -0
- package/lib/common-logic/calculateClauses.d.ts +5 -0
- package/lib/common-logic/calculateClauses.d.ts.map +1 -0
- package/lib/common-logic/{logic.js → calculateClauses.js} +7 -10
- package/lib/common-logic/calculateClauses.js.map +1 -0
- package/lib/common-logic/calculateClauses.test.d.ts +2 -0
- package/lib/common-logic/calculateClauses.test.d.ts.map +1 -0
- package/lib/common-logic/calculateClauses.test.js +156 -0
- package/lib/common-logic/calculateClauses.test.js.map +1 -0
- package/lib/common-logic/calculateGasFees.d.ts +9 -0
- package/lib/common-logic/calculateGasFees.d.ts.map +1 -0
- package/lib/common-logic/calculateGasFees.js +39 -0
- package/lib/common-logic/calculateGasFees.js.map +1 -0
- package/lib/common-logic/calculateGasFees.test.d.ts +2 -0
- package/lib/common-logic/calculateGasFees.test.d.ts.map +1 -0
- package/lib/common-logic/calculateGasFees.test.js +279 -0
- package/lib/common-logic/calculateGasFees.test.js.map +1 -0
- package/lib/common-logic/calculateTransactionInfo.d.ts +10 -0
- package/lib/common-logic/calculateTransactionInfo.d.ts.map +1 -0
- package/lib/common-logic/calculateTransactionInfo.js +81 -0
- package/lib/common-logic/calculateTransactionInfo.js.map +1 -0
- package/lib/common-logic/calculateTransactionInfo.test.d.ts +2 -0
- package/lib/common-logic/calculateTransactionInfo.test.d.ts.map +1 -0
- package/lib/common-logic/calculateTransactionInfo.test.js +314 -0
- package/lib/common-logic/calculateTransactionInfo.test.js.map +1 -0
- package/lib/common-logic/estimateGas.d.ts +10 -0
- package/lib/common-logic/estimateGas.d.ts.map +1 -0
- package/lib/common-logic/estimateGas.js +17 -0
- package/lib/common-logic/estimateGas.js.map +1 -0
- package/lib/common-logic/estimateGas.test.d.ts +2 -0
- package/lib/common-logic/estimateGas.test.d.ts.map +1 -0
- package/lib/common-logic/estimateGas.test.js +129 -0
- package/lib/common-logic/estimateGas.test.js.map +1 -0
- package/lib/common-logic/fixPrefixCase.d.ts +2 -0
- package/lib/common-logic/fixPrefixCase.d.ts.map +1 -0
- package/lib/common-logic/fixPrefixCase.js +9 -0
- package/lib/common-logic/fixPrefixCase.js.map +1 -0
- package/lib/common-logic/fixPrefixCase.test.d.ts +2 -0
- package/lib/common-logic/fixPrefixCase.test.d.ts.map +1 -0
- package/lib/common-logic/fixPrefixCase.test.js +46 -0
- package/lib/common-logic/fixPrefixCase.test.js.map +1 -0
- package/lib/common-logic/generateNonce.d.ts +6 -0
- package/lib/common-logic/generateNonce.d.ts.map +1 -0
- package/lib/common-logic/generateNonce.js +13 -0
- package/lib/common-logic/generateNonce.js.map +1 -0
- package/lib/common-logic/generateNonce.test.d.ts +2 -0
- package/lib/common-logic/generateNonce.test.d.ts.map +1 -0
- package/lib/common-logic/generateNonce.test.js +59 -0
- package/lib/common-logic/generateNonce.test.js.map +1 -0
- package/lib/common-logic/getThorClient.d.ts +7 -0
- package/lib/common-logic/getThorClient.d.ts.map +1 -0
- package/lib/common-logic/getThorClient.js +14 -0
- package/lib/common-logic/getThorClient.js.map +1 -0
- package/lib/common-logic/getThorClient.test.d.ts +2 -0
- package/lib/common-logic/getThorClient.test.d.ts.map +1 -0
- package/lib/common-logic/getThorClient.test.js +53 -0
- package/lib/common-logic/getThorClient.test.js.map +1 -0
- package/lib/common-logic/index.d.ts +8 -6
- package/lib/common-logic/index.d.ts.map +1 -1
- package/lib/common-logic/index.js +8 -6
- package/lib/common-logic/index.js.map +1 -1
- package/lib/common-logic/{mapping-utils.d.ts → mapTransfersToOperations.d.ts} +2 -2
- package/lib/common-logic/mapTransfersToOperations.d.ts.map +1 -0
- package/lib/common-logic/{mapping-utils.js → mapTransfersToOperations.js} +26 -19
- package/lib/common-logic/mapTransfersToOperations.js.map +1 -0
- package/lib/common-logic/mapTransfersToOperations.test.d.ts +2 -0
- package/lib/common-logic/mapTransfersToOperations.test.d.ts.map +1 -0
- package/lib/common-logic/mapTransfersToOperations.test.js +274 -0
- package/lib/common-logic/mapTransfersToOperations.test.js.map +1 -0
- package/lib/common-logic/{pad-address.d.ts → padAddress.d.ts} +1 -1
- package/lib/common-logic/padAddress.d.ts.map +1 -0
- package/lib/common-logic/{pad-address.js → padAddress.js} +1 -1
- package/lib/common-logic/padAddress.js.map +1 -0
- package/lib/common-logic/padAddress.test.d.ts +2 -0
- package/lib/common-logic/padAddress.test.d.ts.map +1 -0
- package/lib/common-logic/padAddress.test.js +59 -0
- package/lib/common-logic/padAddress.test.js.map +1 -0
- package/lib/common-logic/parseAddress.d.ts +7 -0
- package/lib/common-logic/parseAddress.d.ts.map +1 -0
- package/lib/common-logic/parseAddress.js +15 -0
- package/lib/common-logic/parseAddress.js.map +1 -0
- package/lib/common-logic/parseAddress.test.d.ts +2 -0
- package/lib/common-logic/parseAddress.test.d.ts.map +1 -0
- package/lib/common-logic/parseAddress.test.js +97 -0
- package/lib/common-logic/parseAddress.test.js.map +1 -0
- package/lib/constants/env.d.ts +2 -0
- package/lib/constants/env.d.ts.map +1 -0
- package/lib/constants/env.js +6 -0
- package/lib/constants/env.js.map +1 -0
- package/lib/constants/index.d.ts +2 -0
- package/lib/constants/index.d.ts.map +1 -0
- package/lib/constants/index.js +18 -0
- package/lib/constants/index.js.map +1 -0
- package/lib/network/sdk.d.ts +3 -10
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.js +15 -30
- package/lib/network/sdk.js.map +1 -1
- package/lib/signer/getAddress.test.d.ts +2 -0
- package/lib/signer/getAddress.test.d.ts.map +1 -0
- package/lib/signer/getAddress.test.js +357 -0
- package/lib/signer/getAddress.test.js.map +1 -0
- package/lib/signer/signMessage.d.ts.map +1 -1
- package/lib/signer/signMessage.js +3 -3
- package/lib/signer/signMessage.js.map +1 -1
- package/lib/signer/signMessage.test.d.ts +2 -0
- package/lib/signer/signMessage.test.d.ts.map +1 -0
- package/lib/signer/signMessage.test.js +242 -0
- package/lib/signer/signMessage.test.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +79 -53
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/cli.d.ts.map +1 -1
- package/lib/test/cli.js +5 -4
- package/lib/test/cli.js.map +1 -1
- package/lib/types/bridge.d.ts +11 -3
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/bridge.js +3 -0
- package/lib/types/bridge.js.map +1 -1
- package/lib/types/constants.d.ts +0 -3
- package/lib/types/constants.d.ts.map +1 -1
- package/lib/types/constants.js +1 -4
- package/lib/types/constants.js.map +1 -1
- package/lib/types/signer.d.ts +0 -2
- package/lib/types/signer.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +2 -3
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/broadcast.test.d.ts +2 -0
- package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.test.js +183 -0
- package/lib-es/bridge/broadcast.test.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperatioin.test.d.ts +2 -0
- package/lib-es/bridge/buildOptimisticOperatioin.test.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperatioin.test.js +281 -0
- package/lib-es/bridge/buildOptimisticOperatioin.test.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -1
- package/lib-es/bridge/createTransaction.js +3 -2
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/createTransaction.test.d.ts +2 -0
- package/lib-es/bridge/createTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.test.js +162 -0
- package/lib-es/bridge/createTransaction.test.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.test.d.ts +2 -0
- package/lib-es/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.test.js +264 -0
- package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +4 -2
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.js +277 -0
- package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib-es/bridge/helpers.test.d.ts +2 -0
- package/lib-es/bridge/helpers.test.d.ts.map +1 -0
- package/lib-es/bridge/helpers.test.js +293 -0
- package/lib-es/bridge/helpers.test.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +11 -4
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.js +272 -0
- package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +3 -3
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/signOperation.test.d.ts +2 -0
- package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.test.js +290 -0
- package/lib-es/bridge/signOperation.test.js.map +1 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +1 -1
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/bridge/transaction.test.d.ts +2 -0
- package/lib-es/bridge/transaction.test.d.ts.map +1 -0
- package/lib-es/bridge/transaction.test.js +347 -0
- package/lib-es/bridge/transaction.test.js.map +1 -0
- package/lib-es/common-logic/calculateClauses.d.ts +5 -0
- package/lib-es/common-logic/calculateClauses.d.ts.map +1 -0
- package/lib-es/common-logic/{logic.js → calculateClauses.js} +6 -6
- package/lib-es/common-logic/calculateClauses.js.map +1 -0
- package/lib-es/common-logic/calculateClauses.test.d.ts +2 -0
- package/lib-es/common-logic/calculateClauses.test.d.ts.map +1 -0
- package/lib-es/common-logic/calculateClauses.test.js +151 -0
- package/lib-es/common-logic/calculateClauses.test.js.map +1 -0
- package/lib-es/common-logic/calculateGasFees.d.ts +9 -0
- package/lib-es/common-logic/calculateGasFees.d.ts.map +1 -0
- package/lib-es/common-logic/calculateGasFees.js +32 -0
- package/lib-es/common-logic/calculateGasFees.js.map +1 -0
- package/lib-es/common-logic/calculateGasFees.test.d.ts +2 -0
- package/lib-es/common-logic/calculateGasFees.test.d.ts.map +1 -0
- package/lib-es/common-logic/calculateGasFees.test.js +274 -0
- package/lib-es/common-logic/calculateGasFees.test.js.map +1 -0
- package/lib-es/common-logic/calculateTransactionInfo.d.ts +10 -0
- package/lib-es/common-logic/calculateTransactionInfo.d.ts.map +1 -0
- package/lib-es/common-logic/calculateTransactionInfo.js +74 -0
- package/lib-es/common-logic/calculateTransactionInfo.js.map +1 -0
- package/lib-es/common-logic/calculateTransactionInfo.test.d.ts +2 -0
- package/lib-es/common-logic/calculateTransactionInfo.test.d.ts.map +1 -0
- package/lib-es/common-logic/calculateTransactionInfo.test.js +309 -0
- package/lib-es/common-logic/calculateTransactionInfo.test.js.map +1 -0
- package/lib-es/common-logic/estimateGas.d.ts +10 -0
- package/lib-es/common-logic/estimateGas.d.ts.map +1 -0
- package/lib-es/common-logic/estimateGas.js +13 -0
- package/lib-es/common-logic/estimateGas.js.map +1 -0
- package/lib-es/common-logic/estimateGas.test.d.ts +2 -0
- package/lib-es/common-logic/estimateGas.test.d.ts.map +1 -0
- package/lib-es/common-logic/estimateGas.test.js +127 -0
- package/lib-es/common-logic/estimateGas.test.js.map +1 -0
- package/lib-es/common-logic/fixPrefixCase.d.ts +2 -0
- package/lib-es/common-logic/fixPrefixCase.d.ts.map +1 -0
- package/lib-es/common-logic/fixPrefixCase.js +5 -0
- package/lib-es/common-logic/fixPrefixCase.js.map +1 -0
- package/lib-es/common-logic/fixPrefixCase.test.d.ts +2 -0
- package/lib-es/common-logic/fixPrefixCase.test.d.ts.map +1 -0
- package/lib-es/common-logic/fixPrefixCase.test.js +44 -0
- package/lib-es/common-logic/fixPrefixCase.test.js.map +1 -0
- package/lib-es/common-logic/generateNonce.d.ts +6 -0
- package/lib-es/common-logic/generateNonce.d.ts.map +1 -0
- package/lib-es/common-logic/generateNonce.js +9 -0
- package/lib-es/common-logic/generateNonce.js.map +1 -0
- package/lib-es/common-logic/generateNonce.test.d.ts +2 -0
- package/lib-es/common-logic/generateNonce.test.d.ts.map +1 -0
- package/lib-es/common-logic/generateNonce.test.js +57 -0
- package/lib-es/common-logic/generateNonce.test.js.map +1 -0
- package/lib-es/common-logic/getThorClient.d.ts +7 -0
- package/lib-es/common-logic/getThorClient.d.ts.map +1 -0
- package/lib-es/common-logic/getThorClient.js +10 -0
- package/lib-es/common-logic/getThorClient.js.map +1 -0
- package/lib-es/common-logic/getThorClient.test.d.ts +2 -0
- package/lib-es/common-logic/getThorClient.test.d.ts.map +1 -0
- package/lib-es/common-logic/getThorClient.test.js +51 -0
- package/lib-es/common-logic/getThorClient.test.js.map +1 -0
- package/lib-es/common-logic/index.d.ts +8 -6
- package/lib-es/common-logic/index.d.ts.map +1 -1
- package/lib-es/common-logic/index.js +8 -6
- package/lib-es/common-logic/index.js.map +1 -1
- package/lib-es/common-logic/{mapping-utils.d.ts → mapTransfersToOperations.d.ts} +2 -2
- package/lib-es/common-logic/mapTransfersToOperations.d.ts.map +1 -0
- package/lib-es/common-logic/mapTransfersToOperations.js +51 -0
- package/lib-es/common-logic/mapTransfersToOperations.js.map +1 -0
- package/lib-es/common-logic/mapTransfersToOperations.test.d.ts +2 -0
- package/lib-es/common-logic/mapTransfersToOperations.test.d.ts.map +1 -0
- package/lib-es/common-logic/mapTransfersToOperations.test.js +269 -0
- package/lib-es/common-logic/mapTransfersToOperations.test.js.map +1 -0
- package/lib-es/common-logic/{pad-address.d.ts → padAddress.d.ts} +1 -1
- package/lib-es/common-logic/padAddress.d.ts.map +1 -0
- package/lib-es/common-logic/{pad-address.js → padAddress.js} +1 -1
- package/lib-es/common-logic/padAddress.js.map +1 -0
- package/lib-es/common-logic/padAddress.test.d.ts +2 -0
- package/lib-es/common-logic/padAddress.test.d.ts.map +1 -0
- package/lib-es/common-logic/padAddress.test.js +57 -0
- package/lib-es/common-logic/padAddress.test.js.map +1 -0
- package/lib-es/common-logic/parseAddress.d.ts +7 -0
- package/lib-es/common-logic/parseAddress.d.ts.map +1 -0
- package/lib-es/common-logic/parseAddress.js +11 -0
- package/lib-es/common-logic/parseAddress.js.map +1 -0
- package/lib-es/common-logic/parseAddress.test.d.ts +2 -0
- package/lib-es/common-logic/parseAddress.test.d.ts.map +1 -0
- package/lib-es/common-logic/parseAddress.test.js +95 -0
- package/lib-es/common-logic/parseAddress.test.js.map +1 -0
- package/lib-es/constants/env.d.ts +2 -0
- package/lib-es/constants/env.d.ts.map +1 -0
- package/lib-es/constants/env.js +3 -0
- package/lib-es/constants/env.js.map +1 -0
- package/lib-es/constants/index.d.ts +2 -0
- package/lib-es/constants/index.d.ts.map +1 -0
- package/lib-es/constants/index.js +2 -0
- package/lib-es/constants/index.js.map +1 -0
- package/lib-es/network/sdk.d.ts +3 -10
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.js +5 -19
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/signer/getAddress.test.d.ts +2 -0
- package/lib-es/signer/getAddress.test.d.ts.map +1 -0
- package/lib-es/signer/getAddress.test.js +352 -0
- package/lib-es/signer/getAddress.test.js.map +1 -0
- package/lib-es/signer/signMessage.d.ts.map +1 -1
- package/lib-es/signer/signMessage.js +3 -3
- package/lib-es/signer/signMessage.js.map +1 -1
- package/lib-es/signer/signMessage.test.d.ts +2 -0
- package/lib-es/signer/signMessage.test.d.ts.map +1 -0
- package/lib-es/signer/signMessage.test.js +240 -0
- package/lib-es/signer/signMessage.test.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +80 -54
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/cli.d.ts.map +1 -1
- package/lib-es/test/cli.js +4 -3
- package/lib-es/test/cli.js.map +1 -1
- package/lib-es/types/bridge.d.ts +11 -3
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/bridge.js +6 -1
- package/lib-es/types/bridge.js.map +1 -1
- package/lib-es/types/constants.d.ts +0 -3
- package/lib-es/types/constants.d.ts.map +1 -1
- package/lib-es/types/constants.js +0 -3
- package/lib-es/types/constants.js.map +1 -1
- package/lib-es/types/signer.d.ts +0 -2
- package/lib-es/types/signer.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/bridge/broadcast.test.ts +236 -0
- package/src/bridge/broadcast.ts +4 -5
- package/src/bridge/buildOptimisticOperatioin.test.ts +364 -0
- package/src/bridge/createTransaction.test.ts +201 -0
- package/src/bridge/createTransaction.ts +3 -2
- package/src/bridge/estimateMaxSpendable.test.ts +319 -0
- package/src/bridge/getTransactionStatus.test.ts +353 -0
- package/src/bridge/getTransactionStatus.ts +4 -2
- package/src/bridge/helpers.test.ts +356 -0
- package/src/bridge/prepareTransaction.test.ts +345 -0
- package/src/bridge/prepareTransaction.ts +20 -10
- package/src/bridge/signOperation.test.ts +354 -0
- package/src/bridge/signOperation.ts +6 -3
- package/src/bridge/synchronisation.ts +1 -1
- package/src/bridge/transaction.test.ts +440 -0
- package/src/common-logic/calculateClauses.test.ts +186 -0
- package/src/common-logic/calculateClauses.ts +44 -0
- package/src/common-logic/calculateGasFees.test.ts +363 -0
- package/src/common-logic/calculateGasFees.ts +45 -0
- package/src/common-logic/calculateTransactionInfo.test.ts +396 -0
- package/src/common-logic/calculateTransactionInfo.ts +96 -0
- package/src/common-logic/estimateGas.test.ts +162 -0
- package/src/common-logic/estimateGas.ts +18 -0
- package/src/common-logic/fixPrefixCase.test.ts +51 -0
- package/src/common-logic/fixPrefixCase.ts +5 -0
- package/src/common-logic/generateNonce.test.ts +72 -0
- package/src/common-logic/generateNonce.ts +9 -0
- package/src/common-logic/getThorClient.test.ts +66 -0
- package/src/common-logic/getThorClient.ts +10 -0
- package/src/common-logic/index.ts +8 -6
- package/src/common-logic/mapTransfersToOperations.test.ts +342 -0
- package/src/common-logic/mapTransfersToOperations.ts +77 -0
- package/src/common-logic/padAddress.test.ts +65 -0
- package/src/common-logic/parseAddress.test.ts +130 -0
- package/src/common-logic/parseAddress.ts +11 -0
- package/src/constants/env.ts +3 -0
- package/src/constants/index.ts +1 -0
- package/src/network/sdk.ts +22 -30
- package/src/signer/getAddress.test.ts +454 -0
- package/src/signer/signMessage.test.ts +329 -0
- package/src/signer/signMessage.ts +4 -5
- package/src/test/bridgeDatasetTest.ts +86 -58
- package/src/test/cli.ts +4 -3
- package/src/types/bridge.ts +16 -3
- package/src/types/constants.ts +0 -3
- package/lib/common-logic/address-utils.d.ts +0 -2
- package/lib/common-logic/address-utils.d.ts.map +0 -1
- package/lib/common-logic/address-utils.js +0 -19
- package/lib/common-logic/address-utils.js.map +0 -1
- package/lib/common-logic/hex-utils.d.ts +0 -8
- package/lib/common-logic/hex-utils.d.ts.map +0 -1
- package/lib/common-logic/hex-utils.js +0 -52
- package/lib/common-logic/hex-utils.js.map +0 -1
- package/lib/common-logic/logic.d.ts +0 -5
- package/lib/common-logic/logic.d.ts.map +0 -1
- package/lib/common-logic/logic.js.map +0 -1
- package/lib/common-logic/mapping-utils.d.ts.map +0 -1
- package/lib/common-logic/mapping-utils.js.map +0 -1
- package/lib/common-logic/pad-address.d.ts.map +0 -1
- package/lib/common-logic/pad-address.js.map +0 -1
- package/lib/common-logic/transaction-utils.d.ts +0 -30
- package/lib/common-logic/transaction-utils.d.ts.map +0 -1
- package/lib/common-logic/transaction-utils.js +0 -161
- package/lib/common-logic/transaction-utils.js.map +0 -1
- package/lib/contracts/abis/VIP180.d.ts +0 -17
- package/lib/contracts/abis/VIP180.d.ts.map +0 -1
- package/lib/contracts/abis/VIP180.js +0 -265
- package/lib/contracts/abis/VIP180.js.map +0 -1
- package/lib/contracts/abis/params.d.ts +0 -8
- package/lib/contracts/abis/params.d.ts.map +0 -1
- package/lib/contracts/abis/params.js +0 -69
- package/lib/contracts/abis/params.js.map +0 -1
- package/lib/contracts/constants.d.ts +0 -6
- package/lib/contracts/constants.d.ts.map +0 -1
- package/lib/contracts/constants.js +0 -10
- package/lib/contracts/constants.js.map +0 -1
- package/lib-es/common-logic/address-utils.d.ts +0 -2
- package/lib-es/common-logic/address-utils.d.ts.map +0 -1
- package/lib-es/common-logic/address-utils.js +0 -12
- package/lib-es/common-logic/address-utils.js.map +0 -1
- package/lib-es/common-logic/hex-utils.d.ts +0 -8
- package/lib-es/common-logic/hex-utils.d.ts.map +0 -1
- package/lib-es/common-logic/hex-utils.js +0 -50
- package/lib-es/common-logic/hex-utils.js.map +0 -1
- package/lib-es/common-logic/logic.d.ts +0 -5
- package/lib-es/common-logic/logic.d.ts.map +0 -1
- package/lib-es/common-logic/logic.js.map +0 -1
- package/lib-es/common-logic/mapping-utils.d.ts.map +0 -1
- package/lib-es/common-logic/mapping-utils.js +0 -44
- package/lib-es/common-logic/mapping-utils.js.map +0 -1
- package/lib-es/common-logic/pad-address.d.ts.map +0 -1
- package/lib-es/common-logic/pad-address.js.map +0 -1
- package/lib-es/common-logic/transaction-utils.d.ts +0 -30
- package/lib-es/common-logic/transaction-utils.d.ts.map +0 -1
- package/lib-es/common-logic/transaction-utils.js +0 -150
- package/lib-es/common-logic/transaction-utils.js.map +0 -1
- package/lib-es/contracts/abis/VIP180.d.ts +0 -17
- package/lib-es/contracts/abis/VIP180.d.ts.map +0 -1
- package/lib-es/contracts/abis/VIP180.js +0 -263
- package/lib-es/contracts/abis/VIP180.js.map +0 -1
- package/lib-es/contracts/abis/params.d.ts +0 -8
- package/lib-es/contracts/abis/params.d.ts.map +0 -1
- package/lib-es/contracts/abis/params.js +0 -67
- package/lib-es/contracts/abis/params.js.map +0 -1
- package/lib-es/contracts/constants.d.ts +0 -6
- package/lib-es/contracts/constants.d.ts.map +0 -1
- package/lib-es/contracts/constants.js +0 -7
- package/lib-es/contracts/constants.js.map +0 -1
- package/src/common-logic/address-utils.ts +0 -11
- package/src/common-logic/hex-utils.ts +0 -53
- package/src/common-logic/logic.ts +0 -44
- package/src/common-logic/mapping-utils.ts +0 -67
- package/src/common-logic/transaction-utils.ts +0 -190
- package/src/contracts/abis/VIP180.ts +0 -265
- package/src/contracts/abis/params.ts +0 -70
- package/src/contracts/constants.ts +0 -11
- /package/src/common-logic/{pad-address.ts → padAddress.ts} +0 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
3
|
+
import { calculateTransactionInfo } from "./calculateTransactionInfo";
|
|
4
|
+
import { Transaction } from "../types";
|
|
5
|
+
import { ImpossibleToCalculateAmountAndFees } from "../errors";
|
|
6
|
+
import { calculateGasFees } from "./calculateGasFees";
|
|
7
|
+
|
|
8
|
+
// Mock dependencies
|
|
9
|
+
jest.mock("./calculateGasFees");
|
|
10
|
+
|
|
11
|
+
const mockedCalculateGasFees = jest.mocked(calculateGasFees);
|
|
12
|
+
|
|
13
|
+
describe("calculateTransactionInfo", () => {
|
|
14
|
+
const mockAccount: Account = {
|
|
15
|
+
type: "Account",
|
|
16
|
+
id: "vechain:1:0x123:",
|
|
17
|
+
seedIdentifier: "seed123",
|
|
18
|
+
derivationMode: "" as any,
|
|
19
|
+
index: 0,
|
|
20
|
+
freshAddress: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
|
|
21
|
+
freshAddressPath: "44'/818'/0'/0/0",
|
|
22
|
+
used: true,
|
|
23
|
+
balance: new BigNumber("5000000000000000000"), // 5 VET
|
|
24
|
+
spendableBalance: new BigNumber("5000000000000000000"),
|
|
25
|
+
creationDate: new Date("2022-01-01"),
|
|
26
|
+
blockHeight: 12345,
|
|
27
|
+
currency: {} as any,
|
|
28
|
+
operationsCount: 10,
|
|
29
|
+
operations: [],
|
|
30
|
+
pendingOperations: [],
|
|
31
|
+
lastSyncDate: new Date("2022-01-01"),
|
|
32
|
+
balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
|
|
33
|
+
swapHistory: [],
|
|
34
|
+
subAccounts: [],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const mockTokenAccount: TokenAccount = {
|
|
38
|
+
type: "TokenAccount",
|
|
39
|
+
id: "vechain:1:0x123:+0x0000000000000000000000000000456e65726779",
|
|
40
|
+
parentId: "vechain:1:0x123:",
|
|
41
|
+
token: {} as any,
|
|
42
|
+
balance: new BigNumber("1000000000000000000000"), // 1000 VTHO
|
|
43
|
+
spendableBalance: new BigNumber("1000000000000000000000"),
|
|
44
|
+
creationDate: new Date("2022-01-01"),
|
|
45
|
+
operationsCount: 5,
|
|
46
|
+
operations: [],
|
|
47
|
+
pendingOperations: [],
|
|
48
|
+
balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
|
|
49
|
+
swapHistory: [],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const mockBaseTransaction: Transaction = {
|
|
53
|
+
family: "vechain",
|
|
54
|
+
recipient: "0x456789012345678901234567890123456789abcd",
|
|
55
|
+
amount: new BigNumber("1000000000000000000"), // 1 VET/VTHO
|
|
56
|
+
estimatedFees: "0",
|
|
57
|
+
body: {},
|
|
58
|
+
} as Transaction;
|
|
59
|
+
|
|
60
|
+
const mockGasFeesResult = {
|
|
61
|
+
estimatedGas: 21000,
|
|
62
|
+
estimatedGasFees: new BigNumber("210000000000000000"), // 0.21 VET
|
|
63
|
+
maxFeePerGas: 10000000000000,
|
|
64
|
+
maxPriorityFeePerGas: 1000000000000,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
jest.clearAllMocks();
|
|
69
|
+
mockedCalculateGasFees.mockResolvedValue(mockGasFeesResult);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("VET transactions", () => {
|
|
73
|
+
it("should calculate transaction info for normal VET transaction", async () => {
|
|
74
|
+
const result = await calculateTransactionInfo(mockAccount, mockBaseTransaction);
|
|
75
|
+
|
|
76
|
+
expect(result).toEqual({
|
|
77
|
+
isTokenAccount: false,
|
|
78
|
+
amount: new BigNumber("1000000000000000000"),
|
|
79
|
+
spendableBalance: new BigNumber("5000000000000000000"),
|
|
80
|
+
balance: new BigNumber("5000000000000000000"),
|
|
81
|
+
tokenAccount: undefined,
|
|
82
|
+
estimatedFees: "210000000000000000",
|
|
83
|
+
estimatedGas: 21000,
|
|
84
|
+
maxFeePerGas: 10000000000000,
|
|
85
|
+
maxPriorityFeePerGas: 1000000000000,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should handle useAllAmount for VET transaction", async () => {
|
|
90
|
+
const useAllAmountTransaction: Transaction = {
|
|
91
|
+
...mockBaseTransaction,
|
|
92
|
+
useAllAmount: true,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const result = await calculateTransactionInfo(mockAccount, useAllAmountTransaction);
|
|
96
|
+
|
|
97
|
+
expect(result.amount).toEqual(new BigNumber("5000000000000000000"));
|
|
98
|
+
expect(result.spendableBalance).toEqual(new BigNumber("5000000000000000000"));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should call calculateGasFees with correct parameters for VET", async () => {
|
|
102
|
+
await calculateTransactionInfo(mockAccount, mockBaseTransaction);
|
|
103
|
+
|
|
104
|
+
expect(mockedCalculateGasFees).toHaveBeenCalledWith(
|
|
105
|
+
expect.objectContaining({
|
|
106
|
+
amount: new BigNumber("1000000000000000000"),
|
|
107
|
+
}),
|
|
108
|
+
false,
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("Token transactions", () => {
|
|
114
|
+
const mockAccountWithToken: Account = {
|
|
115
|
+
...mockAccount,
|
|
116
|
+
subAccounts: [mockTokenAccount],
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const mockTokenTransaction: Transaction = {
|
|
120
|
+
...mockBaseTransaction,
|
|
121
|
+
subAccountId: "vechain:1:0x123:+0x0000000000000000000000000000456e65726779",
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
it("should calculate transaction info for normal token transaction", async () => {
|
|
125
|
+
const result = await calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction);
|
|
126
|
+
|
|
127
|
+
expect(result).toEqual({
|
|
128
|
+
isTokenAccount: true,
|
|
129
|
+
amount: new BigNumber("1000000000000000000"),
|
|
130
|
+
spendableBalance: new BigNumber("999790000000000000000"), // token balance - gas fees
|
|
131
|
+
balance: new BigNumber("1000000000000000000000"),
|
|
132
|
+
tokenAccount: mockTokenAccount,
|
|
133
|
+
estimatedFees: "210000000000000000",
|
|
134
|
+
estimatedGas: 21000,
|
|
135
|
+
maxFeePerGas: 10000000000000,
|
|
136
|
+
maxPriorityFeePerGas: 1000000000000,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("should handle useAllAmount for token transaction", async () => {
|
|
141
|
+
const useAllAmountTokenTransaction: Transaction = {
|
|
142
|
+
...mockTokenTransaction,
|
|
143
|
+
useAllAmount: true,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const result = await calculateTransactionInfo(
|
|
147
|
+
mockAccountWithToken,
|
|
148
|
+
useAllAmountTokenTransaction,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
expect(result.amount).toEqual(new BigNumber("999790000000000000000"));
|
|
152
|
+
expect(result.spendableBalance).toEqual(new BigNumber("999790000000000000000"));
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("should handle token transaction when gas fees exceed balance", async () => {
|
|
156
|
+
const highGasResult = {
|
|
157
|
+
...mockGasFeesResult,
|
|
158
|
+
estimatedGasFees: new BigNumber("2000000000000000000000"), // 2000 VET (more than token balance)
|
|
159
|
+
};
|
|
160
|
+
mockedCalculateGasFees.mockResolvedValue(highGasResult);
|
|
161
|
+
|
|
162
|
+
const result = await calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction);
|
|
163
|
+
|
|
164
|
+
expect(result.spendableBalance).toEqual(new BigNumber("0"));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("should call calculateGasFees with correct parameters for token", async () => {
|
|
168
|
+
await calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction);
|
|
169
|
+
|
|
170
|
+
expect(mockedCalculateGasFees).toHaveBeenCalledWith(
|
|
171
|
+
expect.objectContaining({
|
|
172
|
+
amount: new BigNumber("1000000000000000000"),
|
|
173
|
+
}),
|
|
174
|
+
true,
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("should handle missing token account", async () => {
|
|
179
|
+
const transactionWithNonExistentToken: Transaction = {
|
|
180
|
+
...mockTokenTransaction,
|
|
181
|
+
subAccountId: "vechain:1:0x123:+nonexistent",
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const result = await calculateTransactionInfo(
|
|
185
|
+
mockAccountWithToken,
|
|
186
|
+
transactionWithNonExistentToken,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
expect(result.isTokenAccount).toBe(false);
|
|
190
|
+
expect(result.tokenAccount).toBeUndefined();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("Fixed gas fees", () => {
|
|
195
|
+
const fixedGasFees = {
|
|
196
|
+
estimatedGas: 50000,
|
|
197
|
+
estimatedGasFees: new BigNumber("500000000000000000"),
|
|
198
|
+
maxFeePerGas: 20000000000000,
|
|
199
|
+
maxPriorityFeePerGas: 2000000000000,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
it("should use fixed gas fees when provided", async () => {
|
|
203
|
+
const result = await calculateTransactionInfo(mockAccount, mockBaseTransaction, fixedGasFees);
|
|
204
|
+
|
|
205
|
+
expect(mockedCalculateGasFees).not.toHaveBeenCalled();
|
|
206
|
+
expect(result.estimatedFees).toBe("500000000000000000");
|
|
207
|
+
expect(result.estimatedGas).toBe(50000);
|
|
208
|
+
expect(result.maxFeePerGas).toBe(20000000000000);
|
|
209
|
+
expect(result.maxPriorityFeePerGas).toBe(2000000000000);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("should use fixed gas fees for token transactions", async () => {
|
|
213
|
+
const mockAccountWithToken: Account = {
|
|
214
|
+
...mockAccount,
|
|
215
|
+
subAccounts: [mockTokenAccount],
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const mockTokenTransaction: Transaction = {
|
|
219
|
+
...mockBaseTransaction,
|
|
220
|
+
subAccountId: "vechain:1:0x123:+0x0000000000000000000000000000456e65726779",
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const result = await calculateTransactionInfo(
|
|
224
|
+
mockAccountWithToken,
|
|
225
|
+
mockTokenTransaction,
|
|
226
|
+
fixedGasFees,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
expect(mockedCalculateGasFees).not.toHaveBeenCalled();
|
|
230
|
+
expect(result.estimatedFees).toBe("500000000000000000");
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe("Circular dependency resolution", () => {
|
|
235
|
+
it("should handle iterative calculation when useAllAmount changes values", async () => {
|
|
236
|
+
// Mock calculateGasFees to return different values based on amount
|
|
237
|
+
mockedCalculateGasFees
|
|
238
|
+
.mockResolvedValueOnce({
|
|
239
|
+
estimatedGas: 21000,
|
|
240
|
+
estimatedGasFees: new BigNumber("210000000000000000"),
|
|
241
|
+
maxFeePerGas: 10000000000000,
|
|
242
|
+
maxPriorityFeePerGas: 1000000000000,
|
|
243
|
+
})
|
|
244
|
+
.mockResolvedValueOnce({
|
|
245
|
+
estimatedGas: 21000,
|
|
246
|
+
estimatedGasFees: new BigNumber("210000000000000000"),
|
|
247
|
+
maxFeePerGas: 10000000000000,
|
|
248
|
+
maxPriorityFeePerGas: 1000000000000,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const useAllAmountTransaction: Transaction = {
|
|
252
|
+
...mockBaseTransaction,
|
|
253
|
+
useAllAmount: true,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const result = await calculateTransactionInfo(mockAccount, useAllAmountTransaction);
|
|
257
|
+
|
|
258
|
+
expect(result.amount).toEqual(new BigNumber("5000000000000000000"));
|
|
259
|
+
expect(mockedCalculateGasFees).toHaveBeenCalledTimes(2);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("should throw error when max iterations reached", async () => {
|
|
263
|
+
// Create a token account scenario where gas fees can affect spendableBalance
|
|
264
|
+
const mockAccountWithToken: Account = {
|
|
265
|
+
...mockAccount,
|
|
266
|
+
subAccounts: [mockTokenAccount],
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const mockTokenTransaction: Transaction = {
|
|
270
|
+
...mockBaseTransaction,
|
|
271
|
+
subAccountId: "vechain:1:0x123:+0x0000000000000000000000000000456e65726779",
|
|
272
|
+
useAllAmount: true,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// Mock calculateGasFees to always return incrementally higher fees
|
|
276
|
+
let callCount = 0;
|
|
277
|
+
mockedCalculateGasFees.mockImplementation(() => {
|
|
278
|
+
callCount++;
|
|
279
|
+
return Promise.resolve({
|
|
280
|
+
estimatedGas: 21000,
|
|
281
|
+
estimatedGasFees: new BigNumber(`${100000000000000000 + callCount * 100000000000000000}`), // Incremental fees
|
|
282
|
+
maxFeePerGas: 10000000000000,
|
|
283
|
+
maxPriorityFeePerGas: 1000000000000,
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
await expect(
|
|
288
|
+
calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction),
|
|
289
|
+
).rejects.toThrow(ImpossibleToCalculateAmountAndFees);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("should stop iterating when amount stabilizes", async () => {
|
|
293
|
+
const constantGasResult = {
|
|
294
|
+
estimatedGas: 21000,
|
|
295
|
+
estimatedGasFees: new BigNumber("210000000000000000"),
|
|
296
|
+
maxFeePerGas: 10000000000000,
|
|
297
|
+
maxPriorityFeePerGas: 1000000000000,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
mockedCalculateGasFees.mockResolvedValue(constantGasResult);
|
|
301
|
+
|
|
302
|
+
const useAllAmountTransaction: Transaction = {
|
|
303
|
+
...mockBaseTransaction,
|
|
304
|
+
useAllAmount: true,
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
await calculateTransactionInfo(mockAccount, useAllAmountTransaction);
|
|
308
|
+
|
|
309
|
+
// Should be called at least once, might be called twice in the loop
|
|
310
|
+
expect(mockedCalculateGasFees).toHaveBeenCalledTimes(2);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe("NaN amount handling", () => {
|
|
315
|
+
it("should handle NaN amount without calling calculateGasFees", async () => {
|
|
316
|
+
const nanAmountTransaction: Transaction = {
|
|
317
|
+
...mockBaseTransaction,
|
|
318
|
+
amount: new BigNumber(NaN),
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const result = await calculateTransactionInfo(mockAccount, nanAmountTransaction);
|
|
322
|
+
|
|
323
|
+
expect(mockedCalculateGasFees).not.toHaveBeenCalled();
|
|
324
|
+
expect(result.amount.isNaN()).toBe(true);
|
|
325
|
+
expect(result.estimatedFees).toBe("0");
|
|
326
|
+
expect(result.estimatedGas).toBe(0);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("should use account balance and spendableBalance for NaN amount", async () => {
|
|
330
|
+
const nanAmountTransaction: Transaction = {
|
|
331
|
+
...mockBaseTransaction,
|
|
332
|
+
amount: new BigNumber(NaN),
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const result = await calculateTransactionInfo(mockAccount, nanAmountTransaction);
|
|
336
|
+
|
|
337
|
+
expect(result.balance).toEqual(mockAccount.balance);
|
|
338
|
+
expect(result.spendableBalance).toEqual(mockAccount.balance);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
describe("Edge cases", () => {
|
|
343
|
+
it("should handle account without subAccounts", async () => {
|
|
344
|
+
const accountWithoutSubAccounts: Account = {
|
|
345
|
+
...mockAccount,
|
|
346
|
+
subAccounts: [],
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const result = await calculateTransactionInfo(accountWithoutSubAccounts, mockBaseTransaction);
|
|
350
|
+
|
|
351
|
+
expect(result.isTokenAccount).toBe(false);
|
|
352
|
+
expect(result.tokenAccount).toBeUndefined();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("should handle empty subAccounts array", async () => {
|
|
356
|
+
const accountWithEmptySubAccounts: Account = {
|
|
357
|
+
...mockAccount,
|
|
358
|
+
subAccounts: [],
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const tokenTransaction: Transaction = {
|
|
362
|
+
...mockBaseTransaction,
|
|
363
|
+
subAccountId: "some-id",
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const result = await calculateTransactionInfo(accountWithEmptySubAccounts, tokenTransaction);
|
|
367
|
+
|
|
368
|
+
expect(result.isTokenAccount).toBe(false);
|
|
369
|
+
expect(result.tokenAccount).toBeUndefined();
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("should handle zero balance account", async () => {
|
|
373
|
+
const zeroBalanceAccount: Account = {
|
|
374
|
+
...mockAccount,
|
|
375
|
+
balance: new BigNumber("0"),
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const result = await calculateTransactionInfo(zeroBalanceAccount, mockBaseTransaction);
|
|
379
|
+
|
|
380
|
+
expect(result.balance).toEqual(new BigNumber("0"));
|
|
381
|
+
expect(result.spendableBalance).toEqual(new BigNumber("0"));
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("should handle zero amount transaction", async () => {
|
|
385
|
+
const zeroAmountTransaction: Transaction = {
|
|
386
|
+
...mockBaseTransaction,
|
|
387
|
+
amount: new BigNumber("0"),
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const result = await calculateTransactionInfo(mockAccount, zeroAmountTransaction);
|
|
391
|
+
|
|
392
|
+
expect(result.amount).toEqual(new BigNumber("0"));
|
|
393
|
+
expect(mockedCalculateGasFees).toHaveBeenCalled();
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
3
|
+
import { Transaction, TransactionInfo } from "../types";
|
|
4
|
+
import { ImpossibleToCalculateAmountAndFees } from "../errors";
|
|
5
|
+
import { calculateGasFees } from "./calculateGasFees";
|
|
6
|
+
|
|
7
|
+
// Here there is a circular dependency between values, that is why we need the do-while loop
|
|
8
|
+
// dependencies are:
|
|
9
|
+
// useAllAmount: USER
|
|
10
|
+
// amount: useAllAmount & spendableBalance
|
|
11
|
+
// fees: amount
|
|
12
|
+
// spendableBalance: fees & balance
|
|
13
|
+
// balance: USER
|
|
14
|
+
// circular dependency is:
|
|
15
|
+
// amount -> spendableBalance -> fees -> amount
|
|
16
|
+
|
|
17
|
+
export const calculateTransactionInfo = async (
|
|
18
|
+
account: Account,
|
|
19
|
+
transaction: Transaction,
|
|
20
|
+
fixedMaxTokenFees?: {
|
|
21
|
+
estimatedGas: number;
|
|
22
|
+
estimatedGasFees: BigNumber;
|
|
23
|
+
maxFeePerGas: number;
|
|
24
|
+
maxPriorityFeePerGas: number;
|
|
25
|
+
},
|
|
26
|
+
): Promise<TransactionInfo> => {
|
|
27
|
+
const { subAccounts } = account;
|
|
28
|
+
const { amount: oldAmount, subAccountId, useAllAmount } = transaction;
|
|
29
|
+
|
|
30
|
+
const tokenAccount =
|
|
31
|
+
subAccountId && subAccounts
|
|
32
|
+
? (subAccounts.find(subAccount => {
|
|
33
|
+
return subAccount.id === subAccountId;
|
|
34
|
+
}) as TokenAccount)
|
|
35
|
+
: undefined;
|
|
36
|
+
const isTokenAccount = !!tokenAccount;
|
|
37
|
+
|
|
38
|
+
let amount = oldAmount;
|
|
39
|
+
let amountBackup;
|
|
40
|
+
let tempTransaction = { ...transaction, amount };
|
|
41
|
+
let balance = account.balance;
|
|
42
|
+
let spendableBalance = account.balance;
|
|
43
|
+
let maxEstimatedGasFees = new BigNumber(0);
|
|
44
|
+
let maxEstimatedGas = 0;
|
|
45
|
+
let maxFeePerGas = 0;
|
|
46
|
+
let maxPriorityFeePerGas = 0;
|
|
47
|
+
|
|
48
|
+
if (!amount.isNaN()) {
|
|
49
|
+
const MAX_ITERATIONS = 5; // it should never reach more than 2 iterations, but just in case
|
|
50
|
+
let iterations = 0;
|
|
51
|
+
do {
|
|
52
|
+
amountBackup = amount;
|
|
53
|
+
|
|
54
|
+
const estimatedGasAndFees =
|
|
55
|
+
fixedMaxTokenFees || (await calculateGasFees(tempTransaction, isTokenAccount));
|
|
56
|
+
|
|
57
|
+
maxEstimatedGasFees = estimatedGasAndFees.estimatedGasFees;
|
|
58
|
+
maxEstimatedGas = estimatedGasAndFees.estimatedGas;
|
|
59
|
+
maxFeePerGas = estimatedGasAndFees.maxFeePerGas;
|
|
60
|
+
maxPriorityFeePerGas = estimatedGasAndFees.maxPriorityFeePerGas;
|
|
61
|
+
|
|
62
|
+
if (isTokenAccount && tokenAccount) {
|
|
63
|
+
balance = tokenAccount.balance;
|
|
64
|
+
spendableBalance = tokenAccount.balance.minus(maxEstimatedGasFees).gt(0)
|
|
65
|
+
? tokenAccount.balance.minus(maxEstimatedGasFees)
|
|
66
|
+
: new BigNumber(0);
|
|
67
|
+
} else {
|
|
68
|
+
balance = account.balance;
|
|
69
|
+
spendableBalance = account.balance;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
amount = useAllAmount ? spendableBalance : oldAmount;
|
|
73
|
+
|
|
74
|
+
tempTransaction = {
|
|
75
|
+
...tempTransaction,
|
|
76
|
+
amount,
|
|
77
|
+
};
|
|
78
|
+
iterations++;
|
|
79
|
+
} while (!amountBackup.isEqualTo(amount) && iterations < MAX_ITERATIONS);
|
|
80
|
+
if (iterations === MAX_ITERATIONS) {
|
|
81
|
+
throw new ImpossibleToCalculateAmountAndFees();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
isTokenAccount,
|
|
87
|
+
amount,
|
|
88
|
+
spendableBalance,
|
|
89
|
+
balance,
|
|
90
|
+
tokenAccount,
|
|
91
|
+
estimatedFees: maxEstimatedGasFees.toString(),
|
|
92
|
+
estimatedGas: maxEstimatedGas,
|
|
93
|
+
maxFeePerGas: maxFeePerGas,
|
|
94
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { estimateGas } from "./estimateGas";
|
|
2
|
+
import { getThorClient } from "./getThorClient";
|
|
3
|
+
import { TransactionClause } from "@vechain/sdk-core";
|
|
4
|
+
import { EstimateGasResult } from "@vechain/sdk-network";
|
|
5
|
+
|
|
6
|
+
// Mock dependencies
|
|
7
|
+
jest.mock("./getThorClient");
|
|
8
|
+
|
|
9
|
+
const mockedGetThorClient = jest.mocked(getThorClient);
|
|
10
|
+
|
|
11
|
+
describe("estimateGas", () => {
|
|
12
|
+
const mockClauses: TransactionClause[] = [
|
|
13
|
+
{
|
|
14
|
+
to: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
|
|
15
|
+
value: "1000000000000000000",
|
|
16
|
+
data: "0x",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
to: "0x123456789012345678901234567890123456789a",
|
|
20
|
+
value: "2000000000000000000",
|
|
21
|
+
data: "0xa9059cbb000000000000000000000000742d35cc6634c0532925a3b8d0b251d8c1743ec40000000000000000000000000000000000000000000000000de0b6b3a7640000",
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const mockOrigin = "0x5034aa590125b64023a0262112b98d72e3c8e40e";
|
|
26
|
+
|
|
27
|
+
const mockEstimateGasResult: EstimateGasResult = {
|
|
28
|
+
totalGas: 21000,
|
|
29
|
+
reverted: false,
|
|
30
|
+
revertReasons: [],
|
|
31
|
+
vmErrors: [],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const mockThorClient = {
|
|
35
|
+
gas: {
|
|
36
|
+
estimateGas: jest.fn(),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
jest.clearAllMocks();
|
|
42
|
+
mockedGetThorClient.mockReturnValue(mockThorClient as any);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should estimate gas for transaction clauses", async () => {
|
|
46
|
+
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
47
|
+
|
|
48
|
+
const result = await estimateGas(mockClauses, mockOrigin);
|
|
49
|
+
|
|
50
|
+
expect(mockedGetThorClient).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(mockClauses, mockOrigin);
|
|
52
|
+
expect(result).toEqual(mockEstimateGasResult);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should handle single clause", async () => {
|
|
56
|
+
const singleClause: TransactionClause[] = [mockClauses[0]];
|
|
57
|
+
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
58
|
+
|
|
59
|
+
const result = await estimateGas(singleClause, mockOrigin);
|
|
60
|
+
|
|
61
|
+
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(singleClause, mockOrigin);
|
|
62
|
+
expect(result).toEqual(mockEstimateGasResult);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should handle empty clauses array", async () => {
|
|
66
|
+
const emptyClauses: TransactionClause[] = [];
|
|
67
|
+
mockThorClient.gas.estimateGas.mockResolvedValue({
|
|
68
|
+
totalGas: 0,
|
|
69
|
+
reverted: false,
|
|
70
|
+
revertReasons: [],
|
|
71
|
+
vmErrors: [],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const result = await estimateGas(emptyClauses, mockOrigin);
|
|
75
|
+
|
|
76
|
+
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(emptyClauses, mockOrigin);
|
|
77
|
+
expect(result.totalGas).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should handle gas estimation with revert", async () => {
|
|
81
|
+
const revertedResult: EstimateGasResult = {
|
|
82
|
+
totalGas: 0,
|
|
83
|
+
reverted: true,
|
|
84
|
+
revertReasons: ["insufficient balance"],
|
|
85
|
+
vmErrors: ["VM error: out of gas"],
|
|
86
|
+
};
|
|
87
|
+
mockThorClient.gas.estimateGas.mockResolvedValue(revertedResult);
|
|
88
|
+
|
|
89
|
+
const result = await estimateGas(mockClauses, mockOrigin);
|
|
90
|
+
|
|
91
|
+
expect(result).toEqual(revertedResult);
|
|
92
|
+
expect(result.reverted).toBe(true);
|
|
93
|
+
expect(result.revertReasons).toContain("insufficient balance");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should handle high gas estimation", async () => {
|
|
97
|
+
const highGasResult: EstimateGasResult = {
|
|
98
|
+
totalGas: 500000,
|
|
99
|
+
reverted: false,
|
|
100
|
+
revertReasons: [],
|
|
101
|
+
vmErrors: [],
|
|
102
|
+
};
|
|
103
|
+
mockThorClient.gas.estimateGas.mockResolvedValue(highGasResult);
|
|
104
|
+
|
|
105
|
+
const result = await estimateGas(mockClauses, mockOrigin);
|
|
106
|
+
|
|
107
|
+
expect(result.totalGas).toBe(500000);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should propagate errors from thor client", async () => {
|
|
111
|
+
const errorMessage = "Network error";
|
|
112
|
+
mockThorClient.gas.estimateGas.mockRejectedValue(new Error(errorMessage));
|
|
113
|
+
|
|
114
|
+
await expect(estimateGas(mockClauses, mockOrigin)).rejects.toThrow(errorMessage);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should handle clauses with data for token transfers", async () => {
|
|
118
|
+
const tokenTransferClause: TransactionClause[] = [
|
|
119
|
+
{
|
|
120
|
+
to: "0x0000000000000000000000000000456e65726779",
|
|
121
|
+
value: "0",
|
|
122
|
+
data: "0xa9059cbb000000000000000000000000742d35cc6634c0532925a3b8d0b251d8c1743ec40000000000000000000000000000000000000000000000000de0b6b3a7640000",
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
const tokenGasResult: EstimateGasResult = {
|
|
127
|
+
totalGas: 37000,
|
|
128
|
+
reverted: false,
|
|
129
|
+
revertReasons: [],
|
|
130
|
+
vmErrors: [],
|
|
131
|
+
};
|
|
132
|
+
mockThorClient.gas.estimateGas.mockResolvedValue(tokenGasResult);
|
|
133
|
+
|
|
134
|
+
const result = await estimateGas(tokenTransferClause, mockOrigin);
|
|
135
|
+
|
|
136
|
+
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(tokenTransferClause, mockOrigin);
|
|
137
|
+
expect(result.totalGas).toBe(37000);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("should get a new thor client instance for each call", async () => {
|
|
141
|
+
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
142
|
+
|
|
143
|
+
await estimateGas(mockClauses, mockOrigin);
|
|
144
|
+
await estimateGas(mockClauses, mockOrigin);
|
|
145
|
+
|
|
146
|
+
expect(mockedGetThorClient).toHaveBeenCalledTimes(2);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should return the exact result from thor client", async () => {
|
|
150
|
+
const exactResult: EstimateGasResult = {
|
|
151
|
+
totalGas: 123456,
|
|
152
|
+
reverted: false,
|
|
153
|
+
revertReasons: [],
|
|
154
|
+
vmErrors: [],
|
|
155
|
+
};
|
|
156
|
+
mockThorClient.gas.estimateGas.mockResolvedValue(exactResult);
|
|
157
|
+
|
|
158
|
+
const result = await estimateGas(mockClauses, mockOrigin);
|
|
159
|
+
|
|
160
|
+
expect(result).toBe(exactResult);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TransactionClause } from "@vechain/sdk-core";
|
|
2
|
+
import { getThorClient } from "./getThorClient";
|
|
3
|
+
import { EstimateGasResult } from "@vechain/sdk-network";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Estimates gas fees for transaction clauses
|
|
7
|
+
* @param {TransactionClause[]} clauses - Array of transaction clauses
|
|
8
|
+
* @param {string} origin - Origin address for the transaction
|
|
9
|
+
* @return {Promise<EstimateGasResult>} Estimated gas result
|
|
10
|
+
*/
|
|
11
|
+
export const estimateGas = async (
|
|
12
|
+
clauses: TransactionClause[],
|
|
13
|
+
origin: string,
|
|
14
|
+
): Promise<EstimateGasResult> => {
|
|
15
|
+
const thorClient = getThorClient();
|
|
16
|
+
const gasResult = await thorClient.gas.estimateGas(clauses, origin);
|
|
17
|
+
return gasResult;
|
|
18
|
+
};
|