@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,363 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { calculateGasFees } from "./calculateGasFees";
|
|
3
|
+
import { Transaction } from "../types";
|
|
4
|
+
import { parseAddress } from "./parseAddress";
|
|
5
|
+
import { calculateClausesVet, calculateClausesVtho } from "./calculateClauses";
|
|
6
|
+
import { estimateGas } from "./estimateGas";
|
|
7
|
+
import { getThorClient } from "./getThorClient";
|
|
8
|
+
|
|
9
|
+
// Mock all dependencies
|
|
10
|
+
jest.mock("./parseAddress");
|
|
11
|
+
jest.mock("./calculateClauses");
|
|
12
|
+
jest.mock("./estimateGas");
|
|
13
|
+
jest.mock("./getThorClient");
|
|
14
|
+
|
|
15
|
+
const mockedParseAddress = jest.mocked(parseAddress);
|
|
16
|
+
const mockedCalculateClausesVet = jest.mocked(calculateClausesVet);
|
|
17
|
+
const mockedCalculateClausesVtho = jest.mocked(calculateClausesVtho);
|
|
18
|
+
const mockedEstimateGas = jest.mocked(estimateGas);
|
|
19
|
+
const mockedGetThorClient = jest.mocked(getThorClient);
|
|
20
|
+
|
|
21
|
+
describe("calculateGasFees", () => {
|
|
22
|
+
const mockTransaction: Transaction = {
|
|
23
|
+
family: "vechain",
|
|
24
|
+
recipient: "0x1234567890123456789012345678901234567890",
|
|
25
|
+
amount: new BigNumber("1000000000000000000"), // 1 VET/VTHO
|
|
26
|
+
estimatedFees: "0",
|
|
27
|
+
body: {},
|
|
28
|
+
} as Transaction;
|
|
29
|
+
|
|
30
|
+
const mockClauses = [
|
|
31
|
+
{
|
|
32
|
+
to: "0x1234567890123456789012345678901234567890",
|
|
33
|
+
value: "1000000000000000000",
|
|
34
|
+
data: "0x",
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const mockGasEstimation = {
|
|
39
|
+
totalGas: 21000,
|
|
40
|
+
reverted: false,
|
|
41
|
+
revertReasons: [],
|
|
42
|
+
vmErrors: [],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const mockThorClient = {
|
|
46
|
+
transactions: {
|
|
47
|
+
buildTransactionBody: jest.fn(),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const mockTransactionBody = {
|
|
52
|
+
maxFeePerGas: "20000000000", // 20 gwei
|
|
53
|
+
maxPriorityFeePerGas: "1000000000", // 1 gwei
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
jest.clearAllMocks();
|
|
58
|
+
// Setup default mocks
|
|
59
|
+
mockedGetThorClient.mockReturnValue(mockThorClient as any);
|
|
60
|
+
mockThorClient.transactions.buildTransactionBody.mockResolvedValue(mockTransactionBody);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("Valid VET transactions (isTokenAccount = false)", () => {
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
mockedParseAddress.mockReturnValue(true);
|
|
66
|
+
mockedCalculateClausesVet.mockResolvedValue(mockClauses);
|
|
67
|
+
mockedEstimateGas.mockResolvedValue(mockGasEstimation);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should calculate gas fees for VET transfer", async () => {
|
|
71
|
+
const result = await calculateGasFees(mockTransaction, false);
|
|
72
|
+
|
|
73
|
+
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
74
|
+
expect(mockedCalculateClausesVet).toHaveBeenCalledWith(
|
|
75
|
+
mockTransaction.recipient,
|
|
76
|
+
mockTransaction.amount,
|
|
77
|
+
);
|
|
78
|
+
expect(mockedCalculateClausesVtho).not.toHaveBeenCalled();
|
|
79
|
+
expect(mockedEstimateGas).toHaveBeenCalledWith(mockClauses, mockTransaction.recipient);
|
|
80
|
+
expect(mockThorClient.transactions.buildTransactionBody).toHaveBeenCalledWith(
|
|
81
|
+
mockClauses,
|
|
82
|
+
mockGasEstimation.totalGas,
|
|
83
|
+
{},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(result).toEqual({
|
|
87
|
+
estimatedGas: 21000,
|
|
88
|
+
estimatedGasFees: new BigNumber("420000000000000"), // 21000 * 20000000000
|
|
89
|
+
maxFeePerGas: 20000000000,
|
|
90
|
+
maxPriorityFeePerGas: 1000000000,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should handle transaction body with null gas values", async () => {
|
|
95
|
+
mockThorClient.transactions.buildTransactionBody.mockResolvedValue({
|
|
96
|
+
maxFeePerGas: null,
|
|
97
|
+
maxPriorityFeePerGas: null,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const result = await calculateGasFees(mockTransaction, false);
|
|
101
|
+
|
|
102
|
+
expect(result).toEqual({
|
|
103
|
+
estimatedGas: 21000,
|
|
104
|
+
estimatedGasFees: new BigNumber("0"), // 21000 * 0
|
|
105
|
+
maxFeePerGas: 0,
|
|
106
|
+
maxPriorityFeePerGas: 0,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should handle transaction body with undefined gas values", async () => {
|
|
111
|
+
mockThorClient.transactions.buildTransactionBody.mockResolvedValue({});
|
|
112
|
+
|
|
113
|
+
const result = await calculateGasFees(mockTransaction, false);
|
|
114
|
+
|
|
115
|
+
expect(result).toEqual({
|
|
116
|
+
estimatedGas: 21000,
|
|
117
|
+
estimatedGasFees: new BigNumber("0"), // 21000 * 0
|
|
118
|
+
maxFeePerGas: 0,
|
|
119
|
+
maxPriorityFeePerGas: 0,
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should handle different gas estimation values", async () => {
|
|
124
|
+
const customGasEstimation = {
|
|
125
|
+
totalGas: 50000,
|
|
126
|
+
reverted: false,
|
|
127
|
+
revertReasons: [],
|
|
128
|
+
vmErrors: [],
|
|
129
|
+
};
|
|
130
|
+
mockedEstimateGas.mockResolvedValue(customGasEstimation);
|
|
131
|
+
|
|
132
|
+
const result = await calculateGasFees(mockTransaction, false);
|
|
133
|
+
|
|
134
|
+
expect(result).toEqual({
|
|
135
|
+
estimatedGas: 50000,
|
|
136
|
+
estimatedGasFees: new BigNumber("1000000000000000"), // 50000 * 20000000000
|
|
137
|
+
maxFeePerGas: 20000000000,
|
|
138
|
+
maxPriorityFeePerGas: 1000000000,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("Valid VTHO transactions (isTokenAccount = true)", () => {
|
|
144
|
+
beforeEach(() => {
|
|
145
|
+
mockedParseAddress.mockReturnValue(true);
|
|
146
|
+
mockedCalculateClausesVtho.mockResolvedValue(mockClauses);
|
|
147
|
+
mockedEstimateGas.mockResolvedValue(mockGasEstimation);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("should calculate gas fees for VTHO transfer", async () => {
|
|
151
|
+
const result = await calculateGasFees(mockTransaction, true);
|
|
152
|
+
|
|
153
|
+
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
154
|
+
expect(mockedCalculateClausesVtho).toHaveBeenCalledWith(
|
|
155
|
+
mockTransaction.recipient,
|
|
156
|
+
mockTransaction.amount,
|
|
157
|
+
);
|
|
158
|
+
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
159
|
+
expect(mockedEstimateGas).toHaveBeenCalledWith(mockClauses, mockTransaction.recipient);
|
|
160
|
+
expect(mockThorClient.transactions.buildTransactionBody).toHaveBeenCalledWith(
|
|
161
|
+
mockClauses,
|
|
162
|
+
mockGasEstimation.totalGas,
|
|
163
|
+
{},
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
expect(result).toEqual({
|
|
167
|
+
estimatedGas: 21000,
|
|
168
|
+
estimatedGasFees: new BigNumber("420000000000000"), // 21000 * 20000000000
|
|
169
|
+
maxFeePerGas: 20000000000,
|
|
170
|
+
maxPriorityFeePerGas: 1000000000,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("should handle large amounts correctly", async () => {
|
|
175
|
+
const largeAmountTransaction = {
|
|
176
|
+
...mockTransaction,
|
|
177
|
+
amount: new BigNumber("999999999999999999999999"),
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const result = await calculateGasFees(largeAmountTransaction, true);
|
|
181
|
+
|
|
182
|
+
expect(mockedCalculateClausesVtho).toHaveBeenCalledWith(
|
|
183
|
+
largeAmountTransaction.recipient,
|
|
184
|
+
largeAmountTransaction.amount,
|
|
185
|
+
);
|
|
186
|
+
expect(result.estimatedGas).toBe(21000);
|
|
187
|
+
expect(result.estimatedGasFees).toEqual(new BigNumber("420000000000000"));
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe("Invalid recipient scenarios", () => {
|
|
192
|
+
it("should return zero values when recipient is undefined", async () => {
|
|
193
|
+
const transactionWithoutRecipient = {
|
|
194
|
+
...mockTransaction,
|
|
195
|
+
recipient: undefined,
|
|
196
|
+
} as any;
|
|
197
|
+
|
|
198
|
+
const result = await calculateGasFees(transactionWithoutRecipient, false);
|
|
199
|
+
|
|
200
|
+
expect(mockedParseAddress).not.toHaveBeenCalled();
|
|
201
|
+
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
202
|
+
expect(mockedCalculateClausesVtho).not.toHaveBeenCalled();
|
|
203
|
+
expect(mockedEstimateGas).not.toHaveBeenCalled();
|
|
204
|
+
|
|
205
|
+
expect(result).toEqual({
|
|
206
|
+
estimatedGas: 0,
|
|
207
|
+
estimatedGasFees: new BigNumber(0),
|
|
208
|
+
maxFeePerGas: 0,
|
|
209
|
+
maxPriorityFeePerGas: 0,
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("should return zero values when recipient is null", async () => {
|
|
214
|
+
const transactionWithNullRecipient = {
|
|
215
|
+
...mockTransaction,
|
|
216
|
+
recipient: null,
|
|
217
|
+
} as any;
|
|
218
|
+
|
|
219
|
+
const result = await calculateGasFees(transactionWithNullRecipient, false);
|
|
220
|
+
|
|
221
|
+
expect(result).toEqual({
|
|
222
|
+
estimatedGas: 0,
|
|
223
|
+
estimatedGasFees: new BigNumber(0),
|
|
224
|
+
maxFeePerGas: 0,
|
|
225
|
+
maxPriorityFeePerGas: 0,
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should return zero values when parseAddress returns null/undefined", async () => {
|
|
230
|
+
mockedParseAddress.mockReturnValue(false);
|
|
231
|
+
|
|
232
|
+
const result = await calculateGasFees(mockTransaction, false);
|
|
233
|
+
|
|
234
|
+
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
235
|
+
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
236
|
+
expect(mockedCalculateClausesVtho).not.toHaveBeenCalled();
|
|
237
|
+
expect(mockedEstimateGas).not.toHaveBeenCalled();
|
|
238
|
+
|
|
239
|
+
expect(result).toEqual({
|
|
240
|
+
estimatedGas: 0,
|
|
241
|
+
estimatedGasFees: new BigNumber(0),
|
|
242
|
+
maxFeePerGas: 0,
|
|
243
|
+
maxPriorityFeePerGas: 0,
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("should return zero values when parseAddress returns empty string", async () => {
|
|
248
|
+
mockedParseAddress.mockReturnValue(false);
|
|
249
|
+
|
|
250
|
+
const result = await calculateGasFees(mockTransaction, false);
|
|
251
|
+
|
|
252
|
+
expect(result).toEqual({
|
|
253
|
+
estimatedGas: 0,
|
|
254
|
+
estimatedGasFees: new BigNumber(0),
|
|
255
|
+
maxFeePerGas: 0,
|
|
256
|
+
maxPriorityFeePerGas: 0,
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe("Error handling", () => {
|
|
262
|
+
beforeEach(() => {
|
|
263
|
+
mockedParseAddress.mockReturnValue(true);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("should throw error when calculateClausesVet fails", async () => {
|
|
267
|
+
const error = new Error("Failed to calculate VET clauses");
|
|
268
|
+
mockedCalculateClausesVet.mockRejectedValue(error);
|
|
269
|
+
|
|
270
|
+
await expect(calculateGasFees(mockTransaction, false)).rejects.toThrow(
|
|
271
|
+
"Failed to calculate VET clauses",
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("should throw error when calculateClausesVtho fails", async () => {
|
|
276
|
+
const error = new Error("Failed to calculate VTHO clauses");
|
|
277
|
+
mockedCalculateClausesVtho.mockRejectedValue(error);
|
|
278
|
+
|
|
279
|
+
await expect(calculateGasFees(mockTransaction, true)).rejects.toThrow(
|
|
280
|
+
"Failed to calculate VTHO clauses",
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("should throw error when estimateGas fails", async () => {
|
|
285
|
+
mockedCalculateClausesVet.mockResolvedValue(mockClauses);
|
|
286
|
+
const error = new Error("Failed to estimate gas");
|
|
287
|
+
mockedEstimateGas.mockRejectedValue(error);
|
|
288
|
+
|
|
289
|
+
await expect(calculateGasFees(mockTransaction, false)).rejects.toThrow(
|
|
290
|
+
"Failed to estimate gas",
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("should throw error when buildTransactionBody fails", async () => {
|
|
295
|
+
mockedCalculateClausesVet.mockResolvedValue(mockClauses);
|
|
296
|
+
mockedEstimateGas.mockResolvedValue(mockGasEstimation);
|
|
297
|
+
const error = new Error("Failed to build transaction body");
|
|
298
|
+
mockThorClient.transactions.buildTransactionBody.mockRejectedValue(error);
|
|
299
|
+
|
|
300
|
+
await expect(calculateGasFees(mockTransaction, false)).rejects.toThrow(
|
|
301
|
+
"Failed to build transaction body",
|
|
302
|
+
);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe("Edge cases", () => {
|
|
307
|
+
beforeEach(() => {
|
|
308
|
+
mockedParseAddress.mockReturnValue(true);
|
|
309
|
+
mockedCalculateClausesVet.mockResolvedValue(mockClauses);
|
|
310
|
+
mockedEstimateGas.mockResolvedValue(mockGasEstimation);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("should handle zero amount transactions", async () => {
|
|
314
|
+
const zeroAmountTransaction = {
|
|
315
|
+
...mockTransaction,
|
|
316
|
+
amount: new BigNumber("0"),
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const result = await calculateGasFees(zeroAmountTransaction, false);
|
|
320
|
+
|
|
321
|
+
expect(mockedCalculateClausesVet).toHaveBeenCalledWith(
|
|
322
|
+
zeroAmountTransaction.recipient,
|
|
323
|
+
new BigNumber("0"),
|
|
324
|
+
);
|
|
325
|
+
expect(result.estimatedGas).toBe(21000);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("should handle zero gas estimation", async () => {
|
|
329
|
+
mockedEstimateGas.mockResolvedValue({
|
|
330
|
+
totalGas: 0,
|
|
331
|
+
reverted: false,
|
|
332
|
+
revertReasons: [],
|
|
333
|
+
vmErrors: [],
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
const result = await calculateGasFees(mockTransaction, false);
|
|
337
|
+
|
|
338
|
+
expect(result).toEqual({
|
|
339
|
+
estimatedGas: 0,
|
|
340
|
+
estimatedGasFees: new BigNumber("0"), // 0 * 20000000000
|
|
341
|
+
maxFeePerGas: 20000000000,
|
|
342
|
+
maxPriorityFeePerGas: 1000000000,
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("should handle very high gas prices", async () => {
|
|
347
|
+
const highGasTransactionBody = {
|
|
348
|
+
maxFeePerGas: "1000000000000", // 1000 gwei
|
|
349
|
+
maxPriorityFeePerGas: "100000000000", // 100 gwei
|
|
350
|
+
};
|
|
351
|
+
mockThorClient.transactions.buildTransactionBody.mockResolvedValue(highGasTransactionBody);
|
|
352
|
+
|
|
353
|
+
const result = await calculateGasFees(mockTransaction, false);
|
|
354
|
+
|
|
355
|
+
expect(result).toEqual({
|
|
356
|
+
estimatedGas: 21000,
|
|
357
|
+
estimatedGasFees: new BigNumber("21000000000000000"), // 21000 * 1000000000000
|
|
358
|
+
maxFeePerGas: 1000000000000,
|
|
359
|
+
maxPriorityFeePerGas: 100000000000,
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Transaction } from "../types";
|
|
3
|
+
import { parseAddress } from "./parseAddress";
|
|
4
|
+
import { calculateClausesVet, calculateClausesVtho } from "./calculateClauses";
|
|
5
|
+
import { estimateGas } from "./estimateGas";
|
|
6
|
+
import { getThorClient } from "./getThorClient";
|
|
7
|
+
|
|
8
|
+
export const calculateGasFees = async (
|
|
9
|
+
transaction: Transaction,
|
|
10
|
+
isTokenAccount: boolean,
|
|
11
|
+
): Promise<{
|
|
12
|
+
estimatedGas: number;
|
|
13
|
+
estimatedGasFees: BigNumber;
|
|
14
|
+
maxFeePerGas: number;
|
|
15
|
+
maxPriorityFeePerGas: number;
|
|
16
|
+
}> => {
|
|
17
|
+
if (transaction.recipient && parseAddress(transaction.recipient)) {
|
|
18
|
+
let clauses;
|
|
19
|
+
if (isTokenAccount) {
|
|
20
|
+
clauses = await calculateClausesVtho(transaction.recipient, transaction.amount);
|
|
21
|
+
} else {
|
|
22
|
+
clauses = await calculateClausesVet(transaction.recipient, transaction.amount);
|
|
23
|
+
}
|
|
24
|
+
const gasEstimation = await estimateGas(clauses, transaction.recipient);
|
|
25
|
+
const thorClient = getThorClient();
|
|
26
|
+
const body = await thorClient.transactions.buildTransactionBody(
|
|
27
|
+
clauses,
|
|
28
|
+
gasEstimation.totalGas,
|
|
29
|
+
{},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
estimatedGas: gasEstimation.totalGas,
|
|
34
|
+
estimatedGasFees: new BigNumber(body.maxFeePerGas ?? "0").times(gasEstimation.totalGas),
|
|
35
|
+
maxFeePerGas: Number(body.maxFeePerGas ?? "0"),
|
|
36
|
+
maxPriorityFeePerGas: Number(body.maxPriorityFeePerGas ?? "0"),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
estimatedGas: 0,
|
|
41
|
+
estimatedGasFees: new BigNumber(0),
|
|
42
|
+
maxFeePerGas: 0,
|
|
43
|
+
maxPriorityFeePerGas: 0,
|
|
44
|
+
};
|
|
45
|
+
};
|