@ledgerhq/coin-vechain 2.2.0-next.0
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/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +74 -0
- package/CHANGELOG.md +1186 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/account.d.ts +7 -0
- package/lib/account.d.ts.map +1 -0
- package/lib/account.js +19 -0
- package/lib/account.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +8 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +27 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperatioin.d.ts +4 -0
- package/lib/bridge/buildOptimisticOperatioin.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperatioin.js +56 -0
- package/lib/bridge/buildOptimisticOperatioin.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +9 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +36 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +29 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +5 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +76 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +10 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +64 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +10 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +38 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +8 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +43 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/synchronisation.d.ts +4 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -0
- package/lib/bridge/synchronisation.js +84 -0
- package/lib/bridge/synchronisation.js.map +1 -0
- package/lib/bridge/transaction.d.ts +17 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +56 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/common-logic/address-utils.d.ts +2 -0
- package/lib/common-logic/address-utils.d.ts.map +1 -0
- package/lib/common-logic/address-utils.js +19 -0
- package/lib/common-logic/address-utils.js.map +1 -0
- package/lib/common-logic/hex-utils.d.ts +8 -0
- package/lib/common-logic/hex-utils.d.ts.map +1 -0
- package/lib/common-logic/hex-utils.js +52 -0
- package/lib/common-logic/hex-utils.js.map +1 -0
- package/lib/common-logic/index.d.ts +7 -0
- package/lib/common-logic/index.d.ts.map +1 -0
- package/lib/common-logic/index.js +23 -0
- package/lib/common-logic/index.js.map +1 -0
- package/lib/common-logic/logic.d.ts +5 -0
- package/lib/common-logic/logic.d.ts.map +1 -0
- package/lib/common-logic/logic.js +46 -0
- package/lib/common-logic/logic.js.map +1 -0
- package/lib/common-logic/mapping-utils.d.ts +5 -0
- package/lib/common-logic/mapping-utils.d.ts.map +1 -0
- package/lib/common-logic/mapping-utils.js +61 -0
- package/lib/common-logic/mapping-utils.js.map +1 -0
- package/lib/common-logic/pad-address.d.ts +2 -0
- package/lib/common-logic/pad-address.d.ts.map +1 -0
- package/lib/common-logic/pad-address.js +13 -0
- package/lib/common-logic/pad-address.js.map +1 -0
- package/lib/common-logic/transaction-utils.d.ts +30 -0
- package/lib/common-logic/transaction-utils.d.ts.map +1 -0
- package/lib/common-logic/transaction-utils.js +164 -0
- package/lib/common-logic/transaction-utils.js.map +1 -0
- package/lib/config.d.ts +5 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +17 -0
- package/lib/config.js.map +1 -0
- package/lib/contracts/abis/VIP180.d.ts +17 -0
- package/lib/contracts/abis/VIP180.d.ts.map +1 -0
- package/lib/contracts/abis/VIP180.js +265 -0
- package/lib/contracts/abis/VIP180.js.map +1 -0
- package/lib/contracts/abis/params.d.ts +8 -0
- package/lib/contracts/abis/params.d.ts.map +1 -0
- package/lib/contracts/abis/params.js +69 -0
- package/lib/contracts/abis/params.js.map +1 -0
- package/lib/contracts/constants.d.ts +6 -0
- package/lib/contracts/constants.d.ts.map +1 -0
- package/lib/contracts/constants.js +10 -0
- package/lib/contracts/constants.js.map +1 -0
- package/lib/datasets/index.d.ts +3 -0
- package/lib/datasets/index.d.ts.map +1 -0
- package/lib/datasets/index.js +23 -0
- package/lib/datasets/index.js.map +1 -0
- package/lib/datasets/vechain.d.ts +5 -0
- package/lib/datasets/vechain.d.ts.map +1 -0
- package/lib/datasets/vechain.js +91 -0
- package/lib/datasets/vechain.js.map +1 -0
- package/lib/datasets/vechain.scanAccounts.1.d.ts +6 -0
- package/lib/datasets/vechain.scanAccounts.1.d.ts.map +1 -0
- package/lib/datasets/vechain.scanAccounts.1.js +16 -0
- package/lib/datasets/vechain.scanAccounts.1.js.map +1 -0
- package/lib/errors.d.ts +10 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +8 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/mock.d.ts +9 -0
- package/lib/mock.d.ts.map +1 -0
- package/lib/mock.js +13 -0
- package/lib/mock.js.map +1 -0
- package/lib/network/index.d.ts +3 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +22 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/sdk.d.ts +47 -0
- package/lib/network/sdk.d.ts.map +1 -0
- package/lib/network/sdk.js +164 -0
- package/lib/network/sdk.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +32 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +4 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +23 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/signer/signMessage.d.ts +4 -0
- package/lib/signer/signMessage.d.ts.map +1 -0
- package/lib/signer/signMessage.js +31 -0
- package/lib/signer/signMessage.js.map +1 -0
- package/lib/test/bot-deviceActions.d.ts +7 -0
- package/lib/test/bot-deviceActions.d.ts.map +1 -0
- package/lib/test/bot-deviceActions.js +23 -0
- package/lib/test/bot-deviceActions.js.map +1 -0
- package/lib/test/bot-specs.d.ts +8 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +161 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +252 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +17 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +51 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +6 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/types/bridge.d.ts +25 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +3 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/constants.d.ts +6 -0
- package/lib/types/constants.d.ts.map +1 -0
- package/lib/types/constants.js +9 -0
- package/lib/types/constants.js.map +1 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +21 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/network.d.ts +71 -0
- package/lib/types/network.d.ts.map +1 -0
- package/lib/types/network.js +3 -0
- package/lib/types/network.js.map +1 -0
- package/lib/types/signer.d.ts +12 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/account.d.ts +7 -0
- package/lib-es/account.d.ts.map +1 -0
- package/lib-es/account.js +17 -0
- package/lib-es/account.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +8 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +23 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperatioin.d.ts +4 -0
- package/lib-es/bridge/buildOptimisticOperatioin.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperatioin.js +49 -0
- package/lib-es/bridge/buildOptimisticOperatioin.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +9 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +29 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +22 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +5 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +69 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +10 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +55 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +10 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +34 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +8 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +39 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/synchronisation.d.ts +4 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -0
- package/lib-es/bridge/synchronisation.js +77 -0
- package/lib-es/bridge/synchronisation.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +17 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +48 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/common-logic/address-utils.d.ts +2 -0
- package/lib-es/common-logic/address-utils.d.ts.map +1 -0
- package/lib-es/common-logic/address-utils.js +12 -0
- package/lib-es/common-logic/address-utils.js.map +1 -0
- package/lib-es/common-logic/hex-utils.d.ts +8 -0
- package/lib-es/common-logic/hex-utils.d.ts.map +1 -0
- package/lib-es/common-logic/hex-utils.js +50 -0
- package/lib-es/common-logic/hex-utils.js.map +1 -0
- package/lib-es/common-logic/index.d.ts +7 -0
- package/lib-es/common-logic/index.d.ts.map +1 -0
- package/lib-es/common-logic/index.js +7 -0
- package/lib-es/common-logic/index.js.map +1 -0
- package/lib-es/common-logic/logic.d.ts +5 -0
- package/lib-es/common-logic/logic.d.ts.map +1 -0
- package/lib-es/common-logic/logic.js +38 -0
- package/lib-es/common-logic/logic.js.map +1 -0
- package/lib-es/common-logic/mapping-utils.d.ts +5 -0
- package/lib-es/common-logic/mapping-utils.d.ts.map +1 -0
- package/lib-es/common-logic/mapping-utils.js +53 -0
- package/lib-es/common-logic/mapping-utils.js.map +1 -0
- package/lib-es/common-logic/pad-address.d.ts +2 -0
- package/lib-es/common-logic/pad-address.d.ts.map +1 -0
- package/lib-es/common-logic/pad-address.js +9 -0
- package/lib-es/common-logic/pad-address.js.map +1 -0
- package/lib-es/common-logic/transaction-utils.d.ts +30 -0
- package/lib-es/common-logic/transaction-utils.d.ts.map +1 -0
- package/lib-es/common-logic/transaction-utils.js +153 -0
- package/lib-es/common-logic/transaction-utils.js.map +1 -0
- package/lib-es/config.d.ts +5 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +12 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/contracts/abis/VIP180.d.ts +17 -0
- package/lib-es/contracts/abis/VIP180.d.ts.map +1 -0
- package/lib-es/contracts/abis/VIP180.js +263 -0
- package/lib-es/contracts/abis/VIP180.js.map +1 -0
- package/lib-es/contracts/abis/params.d.ts +8 -0
- package/lib-es/contracts/abis/params.d.ts.map +1 -0
- package/lib-es/contracts/abis/params.js +67 -0
- package/lib-es/contracts/abis/params.js.map +1 -0
- package/lib-es/contracts/constants.d.ts +6 -0
- package/lib-es/contracts/constants.d.ts.map +1 -0
- package/lib-es/contracts/constants.js +7 -0
- package/lib-es/contracts/constants.js.map +1 -0
- package/lib-es/datasets/index.d.ts +3 -0
- package/lib-es/datasets/index.d.ts.map +1 -0
- package/lib-es/datasets/index.js +3 -0
- package/lib-es/datasets/index.js.map +1 -0
- package/lib-es/datasets/vechain.d.ts +5 -0
- package/lib-es/datasets/vechain.d.ts.map +1 -0
- package/lib-es/datasets/vechain.js +88 -0
- package/lib-es/datasets/vechain.js.map +1 -0
- package/lib-es/datasets/vechain.scanAccounts.1.d.ts +6 -0
- package/lib-es/datasets/vechain.scanAccounts.1.d.ts.map +1 -0
- package/lib-es/datasets/vechain.scanAccounts.1.js +14 -0
- package/lib-es/datasets/vechain.scanAccounts.1.js.map +1 -0
- package/lib-es/errors.d.ts +10 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +5 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/index.d.ts +2 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +2 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/mock.d.ts +9 -0
- package/lib-es/mock.d.ts.map +1 -0
- package/lib-es/mock.js +11 -0
- package/lib-es/mock.js.map +1 -0
- package/lib-es/network/index.d.ts +3 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +3 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/sdk.d.ts +47 -0
- package/lib-es/network/sdk.d.ts.map +1 -0
- package/lib-es/network/sdk.js +150 -0
- package/lib-es/network/sdk.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +27 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +4 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +4 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/signer/signMessage.d.ts +4 -0
- package/lib-es/signer/signMessage.d.ts.map +1 -0
- package/lib-es/signer/signMessage.js +27 -0
- package/lib-es/signer/signMessage.js.map +1 -0
- package/lib-es/test/bot-deviceActions.d.ts +7 -0
- package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
- package/lib-es/test/bot-deviceActions.js +21 -0
- package/lib-es/test/bot-deviceActions.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +8 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +156 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +246 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +17 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +45 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +6 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/types/bridge.d.ts +25 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +2 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/constants.d.ts +6 -0
- package/lib-es/types/constants.d.ts.map +1 -0
- package/lib-es/types/constants.js +6 -0
- package/lib-es/types/constants.js.map +1 -0
- package/lib-es/types/index.d.ts +5 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +5 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/network.d.ts +71 -0
- package/lib-es/types/network.d.ts.map +1 -0
- package/lib-es/types/network.js +2 -0
- package/lib-es/types/network.js.map +1 -0
- package/lib-es/types/signer.d.ts +12 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +120 -0
- package/src/__snapshots__/bridge.integration.test.ts.snap +146 -0
- package/src/account.ts +22 -0
- package/src/bridge/broadcast.ts +23 -0
- package/src/bridge/buildOptimisticOperatioin.ts +46 -0
- package/src/bridge/createTransaction.ts +31 -0
- package/src/bridge/estimateMaxSpendable.ts +18 -0
- package/src/bridge/getTransactionStatus.ts +76 -0
- package/src/bridge/index.ts +63 -0
- package/src/bridge/prepareTransaction.ts +41 -0
- package/src/bridge/signOperation.ts +53 -0
- package/src/bridge/synchronisation.ts +86 -0
- package/src/bridge/transaction.ts +79 -0
- package/src/common-logic/address-utils.ts +11 -0
- package/src/common-logic/hex-utils.ts +53 -0
- package/src/common-logic/index.ts +6 -0
- package/src/common-logic/logic.ts +44 -0
- package/src/common-logic/mapping-utils.ts +67 -0
- package/src/common-logic/pad-address.ts +8 -0
- package/src/common-logic/transaction-utils.ts +190 -0
- package/src/config.ts +18 -0
- package/src/contracts/abis/VIP180.ts +265 -0
- package/src/contracts/abis/params.ts +70 -0
- package/src/contracts/constants.ts +11 -0
- package/src/datasets/index.ts +2 -0
- package/src/datasets/vechain.scanAccounts.1.ts +13 -0
- package/src/datasets/vechain.ts +92 -0
- package/src/errors.ts +7 -0
- package/src/index.ts +1 -0
- package/src/mock.ts +14 -0
- package/src/network/index.ts +2 -0
- package/src/network/sdk.ts +177 -0
- package/src/signer/getAddress.ts +25 -0
- package/src/signer/index.ts +4 -0
- package/src/signer/signMessage.ts +22 -0
- package/src/test/bot-deviceActions.ts +24 -0
- package/src/test/bot-specs.ts +210 -0
- package/src/test/bridgeDatasetTest.ts +262 -0
- package/src/test/cli.ts +86 -0
- package/src/test/index.ts +6 -0
- package/src/types/bridge.ts +35 -0
- package/src/types/constants.ts +5 -0
- package/src/types/index.ts +4 -0
- package/src/types/network.ts +81 -0
- package/src/types/signer.ts +10 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Transaction as ThorTransaction } from "thor-devkit";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { VechainSigner } from "../types";
|
|
4
|
+
|
|
5
|
+
export const signMessage =
|
|
6
|
+
(signerContext: SignerContext<VechainSigner>) =>
|
|
7
|
+
async (deviceId: string, path: string, message: string, rawMessage: string) => {
|
|
8
|
+
let messageObj;
|
|
9
|
+
let unsigned: ThorTransaction;
|
|
10
|
+
try {
|
|
11
|
+
if (message) messageObj = JSON.parse(message);
|
|
12
|
+
else messageObj = JSON.parse(rawMessage);
|
|
13
|
+
unsigned = new ThorTransaction(messageObj);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
throw new Error("Message is not a valid JSON object");
|
|
16
|
+
}
|
|
17
|
+
const result = await signerContext(deviceId, signer =>
|
|
18
|
+
signer.signTransaction(path, unsigned.encode().toString("hex")),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return result.toString("hex");
|
|
22
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SpeculosButton, deviceActionFlow } from "@ledgerhq/coin-framework/bot/specs";
|
|
2
|
+
import type { Transaction } from "../types";
|
|
3
|
+
import { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
|
|
4
|
+
|
|
5
|
+
const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
6
|
+
steps: [
|
|
7
|
+
{
|
|
8
|
+
title: "Review",
|
|
9
|
+
button: SpeculosButton.RIGHT,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
title: "Amount",
|
|
13
|
+
button: SpeculosButton.RIGHT,
|
|
14
|
+
},
|
|
15
|
+
{ title: "Address", button: SpeculosButton.RIGHT },
|
|
16
|
+
{ title: "Max Fees", button: SpeculosButton.RIGHT },
|
|
17
|
+
{
|
|
18
|
+
title: "Accept",
|
|
19
|
+
button: SpeculosButton.BOTH,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export default { acceptTransaction };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import invariant from "invariant";
|
|
3
|
+
import type {
|
|
4
|
+
AppSpec,
|
|
5
|
+
TransactionArg,
|
|
6
|
+
TransactionRes,
|
|
7
|
+
TransactionTestInput,
|
|
8
|
+
SpeculosTransport,
|
|
9
|
+
} from "@ledgerhq/coin-framework/bot/types";
|
|
10
|
+
import type { Transaction } from "../types";
|
|
11
|
+
import { pickSiblings, botTest, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
|
|
12
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
13
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
14
|
+
import speculosDeviceActions from "./bot-deviceActions";
|
|
15
|
+
|
|
16
|
+
const MIN_VET_TRANSACTION_AMOUNT = 1000000000000000000;
|
|
17
|
+
const MAX_VTHO_FEE_FOR_VTHO_TRANSACTION = 1040000000000000000;
|
|
18
|
+
const MAX_VTHO_FEE_FOR_VET_TRANSACTION = 420000000000000000;
|
|
19
|
+
|
|
20
|
+
const vechainTest = {
|
|
21
|
+
currency: getCryptoCurrencyById("vechain"),
|
|
22
|
+
appQuery: {
|
|
23
|
+
model: DeviceModelId.nanoSP,
|
|
24
|
+
appName: "VeChain",
|
|
25
|
+
appVersion: "1.1.1",
|
|
26
|
+
},
|
|
27
|
+
allowEmptyAccounts: true,
|
|
28
|
+
testTimeout: 60 * 1000, // 1 minute
|
|
29
|
+
genericDeviceAction: speculosDeviceActions.acceptTransaction,
|
|
30
|
+
onSpeculosDeviceCreated: async ({ transport }: { transport: SpeculosTransport }) => {
|
|
31
|
+
// enable contract data
|
|
32
|
+
await transport.button(SpeculosButton.RIGHT);
|
|
33
|
+
await transport.button(SpeculosButton.BOTH);
|
|
34
|
+
await transport.button(SpeculosButton.BOTH);
|
|
35
|
+
await transport.button(SpeculosButton.RIGHT);
|
|
36
|
+
await transport.button(SpeculosButton.BOTH);
|
|
37
|
+
// enable multi-clause
|
|
38
|
+
await transport.button(SpeculosButton.RIGHT);
|
|
39
|
+
await transport.button(SpeculosButton.BOTH);
|
|
40
|
+
await transport.button(SpeculosButton.RIGHT);
|
|
41
|
+
await transport.button(SpeculosButton.BOTH);
|
|
42
|
+
await transport.button(SpeculosButton.RIGHT);
|
|
43
|
+
await transport.button(SpeculosButton.BOTH);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const vet: AppSpec<Transaction> = {
|
|
48
|
+
name: "VeChain VET",
|
|
49
|
+
...vechainTest,
|
|
50
|
+
mutations: [
|
|
51
|
+
{
|
|
52
|
+
name: "move ~50% VET",
|
|
53
|
+
maxRun: 1,
|
|
54
|
+
transaction: ({
|
|
55
|
+
account,
|
|
56
|
+
siblings,
|
|
57
|
+
bridge,
|
|
58
|
+
maxSpendable,
|
|
59
|
+
}: TransactionArg<Transaction>): TransactionRes<Transaction> => {
|
|
60
|
+
if (!account.subAccounts?.[0]) throw new Error("no VTHO account");
|
|
61
|
+
invariant(account.balance.gt(MIN_VET_TRANSACTION_AMOUNT), "Vechain: VET balance is empty");
|
|
62
|
+
invariant(
|
|
63
|
+
account.subAccounts[0].balance.gt(MAX_VTHO_FEE_FOR_VET_TRANSACTION),
|
|
64
|
+
"Vechain: VTHO balance is not enough",
|
|
65
|
+
);
|
|
66
|
+
const sibling = pickSiblings(siblings, 2);
|
|
67
|
+
const recipient = sibling.freshAddress;
|
|
68
|
+
const transaction = bridge.createTransaction(account);
|
|
69
|
+
const amount = maxSpendable.div(2).integerValue();
|
|
70
|
+
const updates = [{ amount }, { recipient }];
|
|
71
|
+
return {
|
|
72
|
+
transaction,
|
|
73
|
+
updates,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
test: ({
|
|
77
|
+
account,
|
|
78
|
+
accountBeforeTransaction,
|
|
79
|
+
operation,
|
|
80
|
+
}: TransactionTestInput<Transaction>): void | undefined => {
|
|
81
|
+
botTest("account balance decreased with operation value", () =>
|
|
82
|
+
expect(account.balance.toString()).toBe(
|
|
83
|
+
accountBeforeTransaction.balance.minus(operation.value).toString(),
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "move all VET",
|
|
90
|
+
maxRun: 1,
|
|
91
|
+
transaction: ({
|
|
92
|
+
account,
|
|
93
|
+
siblings,
|
|
94
|
+
bridge,
|
|
95
|
+
}: TransactionArg<Transaction>): TransactionRes<Transaction> => {
|
|
96
|
+
if (!account.subAccounts?.[0]) throw new Error("no VTHO account");
|
|
97
|
+
invariant(account.balance.gt(MIN_VET_TRANSACTION_AMOUNT), "Vechain: VET balance is empty");
|
|
98
|
+
invariant(
|
|
99
|
+
account.subAccounts?.[0].balance.gt(MAX_VTHO_FEE_FOR_VET_TRANSACTION),
|
|
100
|
+
"Vechain: VTHO balance is not enough",
|
|
101
|
+
);
|
|
102
|
+
const sibling = pickSiblings(siblings, 4);
|
|
103
|
+
const recipient = sibling.freshAddress;
|
|
104
|
+
const transaction = bridge.createTransaction(account);
|
|
105
|
+
const updates = [{ useAllAmount: true }, { recipient }];
|
|
106
|
+
return {
|
|
107
|
+
transaction,
|
|
108
|
+
updates,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
test: ({ account }: TransactionTestInput<Transaction>): void | undefined => {
|
|
112
|
+
botTest("account balance decreased with operation value", () =>
|
|
113
|
+
expect(account.balance.toString()).toBe(new BigNumber(0).toString()),
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const vtho: AppSpec<Transaction> = {
|
|
121
|
+
name: "VeChain VTHO",
|
|
122
|
+
...vechainTest,
|
|
123
|
+
skipOperationHistory: true,
|
|
124
|
+
mutations: [
|
|
125
|
+
{
|
|
126
|
+
name: "move ~50% VTHO",
|
|
127
|
+
maxRun: 1,
|
|
128
|
+
transaction: ({
|
|
129
|
+
account,
|
|
130
|
+
siblings,
|
|
131
|
+
bridge,
|
|
132
|
+
}: TransactionArg<Transaction>): TransactionRes<Transaction> => {
|
|
133
|
+
if (!account.subAccounts?.[0]) throw new Error("no VTHO account");
|
|
134
|
+
invariant(
|
|
135
|
+
account.subAccounts?.[0].balance.gt(MAX_VTHO_FEE_FOR_VTHO_TRANSACTION * 2),
|
|
136
|
+
"Vechain: VTHO balance is not enough",
|
|
137
|
+
);
|
|
138
|
+
const sibling = pickSiblings(siblings, 2);
|
|
139
|
+
const recipient = sibling.freshAddress;
|
|
140
|
+
if (
|
|
141
|
+
!account.subAccounts ||
|
|
142
|
+
!account.subAccounts[0] ||
|
|
143
|
+
!(account.subAccounts[0].type == "TokenAccount")
|
|
144
|
+
)
|
|
145
|
+
throw new Error("no VTHO account");
|
|
146
|
+
const tokenAccount = account.subAccounts[0];
|
|
147
|
+
const transaction = bridge.createTransaction(tokenAccount);
|
|
148
|
+
const amount = tokenAccount.balance.div(2).integerValue();
|
|
149
|
+
const updates = [{ amount }, { recipient }, { subAccountId: tokenAccount.id }];
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
transaction,
|
|
153
|
+
updates,
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
test: ({
|
|
157
|
+
account,
|
|
158
|
+
accountBeforeTransaction,
|
|
159
|
+
}: TransactionTestInput<Transaction>): void | undefined => {
|
|
160
|
+
botTest("account balance decreased with operation value", () =>
|
|
161
|
+
expect(account?.subAccounts?.[0].balance.toString()).toBe(
|
|
162
|
+
new BigNumber(accountBeforeTransaction?.subAccounts?.[0].balance || 0)
|
|
163
|
+
.div(2)
|
|
164
|
+
.toString(),
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: "move all VTHO",
|
|
171
|
+
maxRun: 1,
|
|
172
|
+
transaction: ({
|
|
173
|
+
account,
|
|
174
|
+
siblings,
|
|
175
|
+
bridge,
|
|
176
|
+
}: TransactionArg<Transaction>): TransactionRes<Transaction> => {
|
|
177
|
+
if (!account.subAccounts?.[0]) throw new Error("no VTHO account");
|
|
178
|
+
invariant(
|
|
179
|
+
account.subAccounts?.[0].balance.gt(MAX_VTHO_FEE_FOR_VTHO_TRANSACTION),
|
|
180
|
+
"Vechain: VTHO balance is not enough",
|
|
181
|
+
);
|
|
182
|
+
const sibling = pickSiblings(siblings, 4);
|
|
183
|
+
const recipient = sibling.freshAddress;
|
|
184
|
+
if (
|
|
185
|
+
!account.subAccounts ||
|
|
186
|
+
!account.subAccounts[0] ||
|
|
187
|
+
!(account.subAccounts[0].type == "TokenAccount")
|
|
188
|
+
)
|
|
189
|
+
throw new Error("no VTHO account");
|
|
190
|
+
const transaction = bridge.createTransaction(account);
|
|
191
|
+
const updates = [
|
|
192
|
+
{ useAllAmount: true },
|
|
193
|
+
{ recipient },
|
|
194
|
+
{ subAccountId: account.subAccounts[0].id },
|
|
195
|
+
];
|
|
196
|
+
return {
|
|
197
|
+
transaction,
|
|
198
|
+
updates,
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
test: ({ account }: TransactionTestInput<Transaction>): void | undefined => {
|
|
202
|
+
botTest("account balance decreased with operation value", () =>
|
|
203
|
+
expect(account?.subAccounts?.[0].balance.toString()).toBe(new BigNumber(0).toString()),
|
|
204
|
+
);
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export default { vtho, vet };
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import type { AccountRaw, CurrenciesData, DatasetTest } from "@ledgerhq/types-live";
|
|
3
|
+
import type { Transaction } from "../types";
|
|
4
|
+
import { fromTransactionRaw } from "../bridge/transaction";
|
|
5
|
+
import { DEFAULT_GAS_COEFFICIENT, MAINNET_CHAIN_TAG } from "../types";
|
|
6
|
+
import { vechain1, vechain3 } from "../datasets";
|
|
7
|
+
import { generateNonce } from "../common-logic";
|
|
8
|
+
|
|
9
|
+
import vechainScanAccounts1 from "../datasets/vechain.scanAccounts.1";
|
|
10
|
+
import { AmountRequired, NotEnoughBalance } from "@ledgerhq/errors";
|
|
11
|
+
import VIP180 from "../contracts/abis/VIP180";
|
|
12
|
+
import { CryptoCurrencyId } from "@ledgerhq/types-cryptoassets";
|
|
13
|
+
import { NotEnoughVTHO } from "../errors";
|
|
14
|
+
import {
|
|
15
|
+
listSupportedCurrencies,
|
|
16
|
+
setSupportedCurrencies,
|
|
17
|
+
} from "@ledgerhq/coin-framework/currencies/index";
|
|
18
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
19
|
+
|
|
20
|
+
const listSupported = listSupportedCurrencies();
|
|
21
|
+
listSupported.push(getCryptoCurrencyById("vechain"));
|
|
22
|
+
setSupportedCurrencies(listSupported.map(c => c.id) as CryptoCurrencyId[]);
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
|
+
const vechain: CurrenciesData<Transaction> = {
|
|
26
|
+
FIXME_ignoreAccountFields: ["balance", "spendableBalance", "estimateMaxSpendable"], // the balance depends on VTHO and it's earned without operations
|
|
27
|
+
scanAccounts: vechainScanAccounts1,
|
|
28
|
+
|
|
29
|
+
accounts: [
|
|
30
|
+
{
|
|
31
|
+
raw: vechain1 as AccountRaw,
|
|
32
|
+
transactions: [
|
|
33
|
+
{
|
|
34
|
+
name: "Send VET",
|
|
35
|
+
transaction: fromTransactionRaw({
|
|
36
|
+
family: "vechain",
|
|
37
|
+
estimatedFees: "210000000000000000",
|
|
38
|
+
recipient: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
39
|
+
amount: "1000000000000000000",
|
|
40
|
+
body: {
|
|
41
|
+
chainTag: MAINNET_CHAIN_TAG,
|
|
42
|
+
blockRef: "0x00634a0c856ec1db",
|
|
43
|
+
expiration: 18,
|
|
44
|
+
clauses: [
|
|
45
|
+
{
|
|
46
|
+
to: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
47
|
+
value: "1000000000000000000",
|
|
48
|
+
data: "0x",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
gasPriceCoef: DEFAULT_GAS_COEFFICIENT,
|
|
52
|
+
gas: "0",
|
|
53
|
+
dependsOn: null,
|
|
54
|
+
nonce: generateNonce(),
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
expectedStatus: {
|
|
58
|
+
amount: new BigNumber("1000000000000000000"),
|
|
59
|
+
estimatedFees: new BigNumber("210000000000000000"),
|
|
60
|
+
totalSpent: new BigNumber("1000000000000000000"),
|
|
61
|
+
errors: {},
|
|
62
|
+
warnings: {},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "Send VTHO",
|
|
67
|
+
transaction: fromTransactionRaw({
|
|
68
|
+
family: "vechain",
|
|
69
|
+
subAccountId:
|
|
70
|
+
"js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain+vechain%2Fvip180%2Fvtho",
|
|
71
|
+
estimatedFees: "515180000000000000",
|
|
72
|
+
recipient: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
73
|
+
amount: "1000000000000000000",
|
|
74
|
+
body: {
|
|
75
|
+
chainTag: MAINNET_CHAIN_TAG,
|
|
76
|
+
blockRef: "0x00634a0c856ec1db",
|
|
77
|
+
expiration: 18,
|
|
78
|
+
clauses: [
|
|
79
|
+
{
|
|
80
|
+
to: "0x0000000000000000000000000000456e65726779",
|
|
81
|
+
value: 0,
|
|
82
|
+
data: VIP180.transfer.encode(
|
|
83
|
+
"0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
84
|
+
"9000000000000000000",
|
|
85
|
+
),
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
gasPriceCoef: DEFAULT_GAS_COEFFICIENT,
|
|
89
|
+
gas: "0",
|
|
90
|
+
dependsOn: null,
|
|
91
|
+
nonce: generateNonce(),
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
expectedStatus: {
|
|
95
|
+
amount: new BigNumber("1000000000000000000"),
|
|
96
|
+
estimatedFees: new BigNumber("515180000000000000"),
|
|
97
|
+
totalSpent: new BigNumber("1515180000000000000"),
|
|
98
|
+
errors: {},
|
|
99
|
+
warnings: {},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "Amount required",
|
|
104
|
+
transaction: fromTransactionRaw({
|
|
105
|
+
family: "vechain",
|
|
106
|
+
estimatedFees: "0",
|
|
107
|
+
recipient: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
108
|
+
amount: "",
|
|
109
|
+
body: {
|
|
110
|
+
chainTag: MAINNET_CHAIN_TAG,
|
|
111
|
+
blockRef: "0x00634a0c856ec1db",
|
|
112
|
+
expiration: 18,
|
|
113
|
+
clauses: [{ to: "", value: 0, data: "0x" }],
|
|
114
|
+
gasPriceCoef: DEFAULT_GAS_COEFFICIENT,
|
|
115
|
+
gas: "0",
|
|
116
|
+
dependsOn: null,
|
|
117
|
+
nonce: generateNonce(),
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
expectedStatus: {
|
|
121
|
+
errors: {
|
|
122
|
+
amount: new AmountRequired(),
|
|
123
|
+
},
|
|
124
|
+
warnings: {},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "VET balance not enough",
|
|
129
|
+
transaction: fromTransactionRaw({
|
|
130
|
+
family: "vechain",
|
|
131
|
+
estimatedFees: "210000000000000000",
|
|
132
|
+
recipient: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
133
|
+
amount: "20000000000000000000",
|
|
134
|
+
body: {
|
|
135
|
+
chainTag: MAINNET_CHAIN_TAG,
|
|
136
|
+
blockRef: "0x00634a0c856ec1db",
|
|
137
|
+
expiration: 18,
|
|
138
|
+
clauses: [
|
|
139
|
+
{
|
|
140
|
+
to: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
141
|
+
value: "20000000000000000000",
|
|
142
|
+
data: "0x",
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
gasPriceCoef: DEFAULT_GAS_COEFFICIENT,
|
|
146
|
+
gas: "0",
|
|
147
|
+
dependsOn: null,
|
|
148
|
+
nonce: generateNonce(),
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
expectedStatus: {
|
|
152
|
+
amount: new BigNumber("20000000000000000000"),
|
|
153
|
+
errors: {
|
|
154
|
+
amount: new NotEnoughBalance(),
|
|
155
|
+
},
|
|
156
|
+
warnings: {},
|
|
157
|
+
totalSpent: new BigNumber("20000000000000000000"),
|
|
158
|
+
estimatedFees: new BigNumber("210000000000000000"),
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "VTHO balance not enough",
|
|
163
|
+
transaction: fromTransactionRaw({
|
|
164
|
+
family: "vechain",
|
|
165
|
+
subAccountId:
|
|
166
|
+
"js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain+vechain%2Fvip180%2Fvtho",
|
|
167
|
+
estimatedFees: "515820000000000000",
|
|
168
|
+
recipient: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
169
|
+
amount: "20000000000000000000",
|
|
170
|
+
body: {
|
|
171
|
+
chainTag: MAINNET_CHAIN_TAG,
|
|
172
|
+
blockRef: "0x00634a0c856ec1db",
|
|
173
|
+
expiration: 18,
|
|
174
|
+
clauses: [
|
|
175
|
+
{
|
|
176
|
+
to: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
177
|
+
value: "20000000000000000000",
|
|
178
|
+
data: "0x",
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
gasPriceCoef: DEFAULT_GAS_COEFFICIENT,
|
|
182
|
+
gas: "0",
|
|
183
|
+
dependsOn: null,
|
|
184
|
+
nonce: generateNonce(),
|
|
185
|
+
},
|
|
186
|
+
}),
|
|
187
|
+
expectedStatus: {
|
|
188
|
+
amount: new BigNumber("20000000000000000000"),
|
|
189
|
+
errors: {
|
|
190
|
+
amount: new NotEnoughBalance(),
|
|
191
|
+
},
|
|
192
|
+
warnings: {},
|
|
193
|
+
totalSpent: new BigNumber("20515820000000000000"),
|
|
194
|
+
estimatedFees: new BigNumber("515820000000000000"),
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
FIXME_tests: [
|
|
199
|
+
"balance is sum of ops", // the balance depends on VTHO and it's earned without operations
|
|
200
|
+
"empty transaction is equals to itself", //nonce is not deterministic
|
|
201
|
+
"ref stability on self transaction", //blockref is not deterministic
|
|
202
|
+
"can be run in parallel and all yield same results", //blockref is not deterministic
|
|
203
|
+
],
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
raw: vechain3 as AccountRaw,
|
|
207
|
+
transactions: [
|
|
208
|
+
{
|
|
209
|
+
name: "Not enough VTHO to pay fees",
|
|
210
|
+
transaction: fromTransactionRaw({
|
|
211
|
+
family: "vechain",
|
|
212
|
+
estimatedFees: "210000000000000000",
|
|
213
|
+
recipient: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
214
|
+
amount: "1000000000000000000",
|
|
215
|
+
body: {
|
|
216
|
+
chainTag: MAINNET_CHAIN_TAG,
|
|
217
|
+
blockRef: "0x00634a0c856ec1db",
|
|
218
|
+
expiration: 18,
|
|
219
|
+
clauses: [
|
|
220
|
+
{
|
|
221
|
+
to: "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
|
|
222
|
+
value: "1000000000000000000",
|
|
223
|
+
data: "0x",
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
gasPriceCoef: DEFAULT_GAS_COEFFICIENT,
|
|
227
|
+
gas: "0",
|
|
228
|
+
dependsOn: null,
|
|
229
|
+
nonce: generateNonce(),
|
|
230
|
+
},
|
|
231
|
+
}),
|
|
232
|
+
expectedStatus: {
|
|
233
|
+
amount: new BigNumber("1000000000000000000"),
|
|
234
|
+
estimatedFees: new BigNumber("210000000000000000"),
|
|
235
|
+
totalSpent: new BigNumber("1000000000000000000"),
|
|
236
|
+
errors: {
|
|
237
|
+
amount: new NotEnoughVTHO(),
|
|
238
|
+
},
|
|
239
|
+
warnings: {},
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
FIXME_tests: [
|
|
244
|
+
"balance is sum of ops", // the balance depends on VTHO and it's earned without operations
|
|
245
|
+
"empty transaction is equals to itself", //nonce is not deterministic
|
|
246
|
+
"ref stability on self transaction", //blockref is not deterministic
|
|
247
|
+
"can be run in parallel and all yield same results", //blockref is not deterministic
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// describe("VeChain Bridge", () => {
|
|
254
|
+
// test.todo("sample test");
|
|
255
|
+
// });
|
|
256
|
+
|
|
257
|
+
export const dataset: DatasetTest<Transaction> = {
|
|
258
|
+
implementations: ["js", "mock"],
|
|
259
|
+
currencies: {
|
|
260
|
+
vechain,
|
|
261
|
+
},
|
|
262
|
+
};
|
package/src/test/cli.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import flatMap from "lodash/flatMap";
|
|
2
|
+
import { Transaction, Transaction as VechainTransaction } from "../types";
|
|
3
|
+
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
4
|
+
import { VTHO_ADDRESS } from "../contracts/constants";
|
|
5
|
+
import VIP180 from "../contracts/abis/VIP180";
|
|
6
|
+
import { MustBeVechain } from "../errors";
|
|
7
|
+
|
|
8
|
+
type CliTools = {
|
|
9
|
+
options: Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
type: any;
|
|
12
|
+
desc: string;
|
|
13
|
+
}>;
|
|
14
|
+
inferTransactions: (
|
|
15
|
+
transactions: Array<{
|
|
16
|
+
account: AccountLike;
|
|
17
|
+
transaction: Transaction;
|
|
18
|
+
mainAccount: Account;
|
|
19
|
+
}>,
|
|
20
|
+
opts: Record<string, any>,
|
|
21
|
+
) => Transaction[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type Clauses = {
|
|
25
|
+
to: string;
|
|
26
|
+
data: string;
|
|
27
|
+
value: string | number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const options = [
|
|
31
|
+
{
|
|
32
|
+
name: "vechainCurrency",
|
|
33
|
+
type: String,
|
|
34
|
+
desc: 'select between sending VET or VTHO using "VET" or "VTHO" strings',
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
function inferTransactions(
|
|
39
|
+
transactions: Array<{
|
|
40
|
+
account: AccountLike;
|
|
41
|
+
transaction: Transaction;
|
|
42
|
+
mainAccount: Account;
|
|
43
|
+
}>,
|
|
44
|
+
opts: Record<string, any>,
|
|
45
|
+
): Transaction[] {
|
|
46
|
+
return flatMap(transactions, ({ transaction, account }) => {
|
|
47
|
+
let subAccountId =
|
|
48
|
+
account.type == "Account" && account.subAccounts ? account.subAccounts[0].id : "";
|
|
49
|
+
|
|
50
|
+
if (account.type === "TokenAccount") {
|
|
51
|
+
subAccountId = account.id;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const clauses: Array<Clauses> = [];
|
|
55
|
+
|
|
56
|
+
if (opts.vechainCurrency == "VET") {
|
|
57
|
+
clauses.push({
|
|
58
|
+
to: transaction.recipient,
|
|
59
|
+
value: "0x" + transaction.amount.toString(16),
|
|
60
|
+
data: "0x",
|
|
61
|
+
});
|
|
62
|
+
} else if (opts.vechainCurrency == "VTHO") {
|
|
63
|
+
clauses.push({
|
|
64
|
+
value: 0,
|
|
65
|
+
to: VTHO_ADDRESS,
|
|
66
|
+
data: VIP180.transfer.encode(transaction.recipient, transaction.amount.toFixed()),
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
throw new MustBeVechain();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
...transaction,
|
|
74
|
+
family: "vechain",
|
|
75
|
+
subAccountId: opts.vechainCurrency == "VTHO" ? subAccountId : "",
|
|
76
|
+
body: { ...(transaction as VechainTransaction).body, clauses },
|
|
77
|
+
} as VechainTransaction;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default function makeCliTools(): CliTools {
|
|
82
|
+
return {
|
|
83
|
+
options,
|
|
84
|
+
inferTransactions,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TokenAccount,
|
|
3
|
+
TransactionCommon,
|
|
4
|
+
TransactionCommonRaw,
|
|
5
|
+
TransactionStatusCommon,
|
|
6
|
+
TransactionStatusCommonRaw,
|
|
7
|
+
} from "@ledgerhq/types-live";
|
|
8
|
+
import BigNumber from "bignumber.js";
|
|
9
|
+
import { Transaction as ThorTransaction } from "thor-devkit";
|
|
10
|
+
|
|
11
|
+
export type Transaction = TransactionCommon & {
|
|
12
|
+
family: "vechain";
|
|
13
|
+
estimatedFees: string;
|
|
14
|
+
body: ThorTransaction.Body;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
18
|
+
family: "vechain";
|
|
19
|
+
estimatedFees: string;
|
|
20
|
+
body: ThorTransaction.Body;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
24
|
+
|
|
25
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
26
|
+
|
|
27
|
+
export type TransactionInfo = {
|
|
28
|
+
isTokenAccount: boolean;
|
|
29
|
+
amount: BigNumber;
|
|
30
|
+
balance: BigNumber;
|
|
31
|
+
spendableBalance: BigNumber;
|
|
32
|
+
tokenAccount: TokenAccount | undefined;
|
|
33
|
+
estimatedFees: string;
|
|
34
|
+
estimatedGas: number;
|
|
35
|
+
};
|