@ledgerhq/coin-sui 0.2.0-nightly.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 +23 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +19 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +9 -0
- package/jest.integ.config.js +7 -0
- package/lib/api/chain/index.d.ts +16 -0
- package/lib/api/chain/index.d.ts.map +1 -0
- package/lib/api/chain/index.js +3 -0
- package/lib/api/chain/index.js.map +1 -0
- package/lib/bridge/bridge.integration.test.d.ts +4 -0
- package/lib/bridge/bridge.integration.test.d.ts.map +1 -0
- package/lib/bridge/bridge.integration.test.js +136 -0
- package/lib/bridge/bridge.integration.test.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +12 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +20 -0
- package/lib/bridge/broadcast.js.map +1 -0
- 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 +48 -0
- package/lib/bridge/broadcast.test.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +76 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.test.d.ts +2 -0
- package/lib/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.test.js +52 -0
- package/lib/bridge/buildOptimisticOperation.test.js.map +1 -0
- package/lib/bridge/buildTransaction.d.ts +9 -0
- package/lib/bridge/buildTransaction.d.ts.map +1 -0
- package/lib/bridge/buildTransaction.js +19 -0
- package/lib/bridge/buildTransaction.js.map +1 -0
- package/lib/bridge/buildTransaction.test.d.ts +2 -0
- package/lib/bridge/buildTransaction.test.d.ts.map +1 -0
- package/lib/bridge/buildTransaction.test.js +17 -0
- package/lib/bridge/buildTransaction.test.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +10 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +24 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +14 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +44 -0
- package/lib/bridge/estimateMaxSpendable.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 +25 -0
- package/lib/bridge/estimateMaxSpendable.test.js.map +1 -0
- package/lib/bridge/formatters.d.ts +10 -0
- package/lib/bridge/formatters.d.ts.map +1 -0
- package/lib/bridge/formatters.js +24 -0
- package/lib/bridge/formatters.js.map +1 -0
- package/lib/bridge/formatters.test.d.ts +2 -0
- package/lib/bridge/formatters.test.d.ts.map +1 -0
- package/lib/bridge/formatters.test.js +18 -0
- package/lib/bridge/formatters.test.js.map +1 -0
- package/lib/bridge/getFeesForTransaction.d.ts +15 -0
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib/bridge/getFeesForTransaction.js +32 -0
- package/lib/bridge/getFeesForTransaction.js.map +1 -0
- package/lib/bridge/getFeesForTransaction.test.d.ts +2 -0
- package/lib/bridge/getFeesForTransaction.test.d.ts.map +1 -0
- package/lib/bridge/getFeesForTransaction.test.js +35 -0
- package/lib/bridge/getFeesForTransaction.test.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +12 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +59 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- 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 +48 -0
- package/lib/bridge/getTransactionStatus.test.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 +63 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/preload.d.ts +11 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +41 -0
- package/lib/bridge/preload.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +13 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +43 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- 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 +45 -0
- package/lib/bridge/prepareTransaction.test.js.map +1 -0
- package/lib/bridge/serialization.d.ts +7 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +27 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/serialization.test.d.ts +2 -0
- package/lib/bridge/serialization.test.d.ts.map +1 -0
- package/lib/bridge/serialization.test.js +131 -0
- package/lib/bridge/serialization.test.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +9 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +72 -0
- package/lib/bridge/signOperation.js.map +1 -0
- 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 +76 -0
- package/lib/bridge/signOperation.test.js.map +1 -0
- package/lib/bridge/synchronisation.d.ts +21 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -0
- package/lib/bridge/synchronisation.js +65 -0
- package/lib/bridge/synchronisation.js.map +1 -0
- package/lib/bridge/synchronisation.test.d.ts +2 -0
- package/lib/bridge/synchronisation.test.d.ts.map +1 -0
- package/lib/bridge/synchronisation.test.js +118 -0
- package/lib/bridge/synchronisation.test.js.map +1 -0
- package/lib/bridge/transaction.d.ts +15 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +55 -0
- package/lib/bridge/transaction.js.map +1 -0
- 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 +65 -0
- package/lib/bridge/transaction.test.js.map +1 -0
- package/lib/bridge/utils.d.ts +27 -0
- package/lib/bridge/utils.d.ts.map +1 -0
- package/lib/bridge/utils.js +57 -0
- package/lib/bridge/utils.js.map +1 -0
- package/lib/config.d.ts +15 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +9 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/logic/broadcast.d.ts +9 -0
- package/lib/logic/broadcast.d.ts.map +1 -0
- package/lib/logic/broadcast.js +26 -0
- package/lib/logic/broadcast.js.map +1 -0
- package/lib/logic/craftTransaction.d.ts +17 -0
- package/lib/logic/craftTransaction.d.ts.map +1 -0
- package/lib/logic/craftTransaction.js +22 -0
- package/lib/logic/craftTransaction.js.map +1 -0
- package/lib/logic/estimateFees.d.ts +10 -0
- package/lib/logic/estimateFees.d.ts.map +1 -0
- package/lib/logic/estimateFees.js +20 -0
- package/lib/logic/estimateFees.js.map +1 -0
- package/lib/logic/index.d.ts +4 -0
- package/lib/logic/index.d.ts.map +1 -0
- package/lib/logic/index.js +10 -0
- package/lib/logic/index.js.map +1 -0
- package/lib/network/index.d.ts +18 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +17 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/sdk.d.ts +61 -0
- package/lib/network/sdk.d.ts.map +1 -0
- package/lib/network/sdk.integration.test.d.ts +2 -0
- package/lib/network/sdk.integration.test.d.ts.map +1 -0
- package/lib/network/sdk.integration.test.js +70 -0
- package/lib/network/sdk.integration.test.js.map +1 -0
- package/lib/network/sdk.js +205 -0
- package/lib/network/sdk.js.map +1 -0
- package/lib/network/sdk.test.d.ts +2 -0
- package/lib/network/sdk.test.d.ts.map +1 -0
- package/lib/network/sdk.test.js +166 -0
- package/lib/network/sdk.test.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 +20 -0
- package/lib/signer/getAddress.js.map +1 -0
- 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 +106 -0
- package/lib/signer/getAddress.test.js.map +1 -0
- package/lib/signer/index.d.ts +6 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +11 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/cli.d.ts +16 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +16 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/types/bridge.d.ts +72 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.fixture.d.ts +30 -0
- package/lib/types/bridge.fixture.d.ts.map +1 -0
- package/lib/types/bridge.fixture.js +86 -0
- package/lib/types/bridge.fixture.js.map +1 -0
- package/lib/types/bridge.js +3 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +20 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/model.d.ts +6 -0
- package/lib/types/model.d.ts.map +1 -0
- package/lib/types/model.js +3 -0
- package/lib/types/model.js.map +1 -0
- package/lib/types/signer.d.ts +13 -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/utils.d.ts +7 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +13 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/api/chain/index.d.ts +16 -0
- package/lib-es/api/chain/index.d.ts.map +1 -0
- package/lib-es/api/chain/index.js +2 -0
- package/lib-es/api/chain/index.js.map +1 -0
- package/lib-es/bridge/bridge.integration.test.d.ts +4 -0
- package/lib-es/bridge/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/bridge/bridge.integration.test.js +130 -0
- package/lib-es/bridge/bridge.integration.test.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +12 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +16 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- 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 +46 -0
- package/lib-es/bridge/broadcast.test.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +69 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.test.d.ts +2 -0
- package/lib-es/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.test.js +47 -0
- package/lib-es/bridge/buildOptimisticOperation.test.js.map +1 -0
- package/lib-es/bridge/buildTransaction.d.ts +9 -0
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
- package/lib-es/bridge/buildTransaction.js +11 -0
- package/lib-es/bridge/buildTransaction.js.map +1 -0
- package/lib-es/bridge/buildTransaction.test.d.ts +2 -0
- package/lib-es/bridge/buildTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/buildTransaction.test.js +15 -0
- package/lib-es/bridge/buildTransaction.test.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +10 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +20 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +14 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +37 -0
- package/lib-es/bridge/estimateMaxSpendable.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 +23 -0
- package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -0
- package/lib-es/bridge/formatters.d.ts +10 -0
- package/lib-es/bridge/formatters.d.ts.map +1 -0
- package/lib-es/bridge/formatters.js +19 -0
- package/lib-es/bridge/formatters.js.map +1 -0
- package/lib-es/bridge/formatters.test.d.ts +2 -0
- package/lib-es/bridge/formatters.test.d.ts.map +1 -0
- package/lib-es/bridge/formatters.test.js +16 -0
- package/lib-es/bridge/formatters.test.js.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts +15 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.js +29 -0
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.test.d.ts +2 -0
- package/lib-es/bridge/getFeesForTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.test.js +30 -0
- package/lib-es/bridge/getFeesForTransaction.test.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +12 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +55 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- 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 +43 -0
- package/lib-es/bridge/getTransactionStatus.test.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 +56 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/preload.d.ts +11 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +32 -0
- package/lib-es/bridge/preload.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +13 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +36 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- 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 +40 -0
- package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
- package/lib-es/bridge/serialization.d.ts +7 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +20 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/serialization.test.d.ts +2 -0
- package/lib-es/bridge/serialization.test.d.ts.map +1 -0
- package/lib-es/bridge/serialization.test.js +126 -0
- package/lib-es/bridge/serialization.test.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +9 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +68 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- 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 +71 -0
- package/lib-es/bridge/signOperation.test.js.map +1 -0
- package/lib-es/bridge/synchronisation.d.ts +21 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -0
- package/lib-es/bridge/synchronisation.js +61 -0
- package/lib-es/bridge/synchronisation.js.map +1 -0
- package/lib-es/bridge/synchronisation.test.d.ts +2 -0
- package/lib-es/bridge/synchronisation.test.d.ts.map +1 -0
- package/lib-es/bridge/synchronisation.test.js +113 -0
- package/lib-es/bridge/synchronisation.test.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +15 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +49 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- 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 +63 -0
- package/lib-es/bridge/transaction.test.js.map +1 -0
- package/lib-es/bridge/utils.d.ts +27 -0
- package/lib-es/bridge/utils.d.ts.map +1 -0
- package/lib-es/bridge/utils.js +51 -0
- package/lib-es/bridge/utils.js.map +1 -0
- package/lib-es/config.d.ts +15 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/index.d.ts +3 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +3 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/logic/broadcast.d.ts +9 -0
- package/lib-es/logic/broadcast.d.ts.map +1 -0
- package/lib-es/logic/broadcast.js +19 -0
- package/lib-es/logic/broadcast.js.map +1 -0
- package/lib-es/logic/craftTransaction.d.ts +17 -0
- package/lib-es/logic/craftTransaction.d.ts.map +1 -0
- package/lib-es/logic/craftTransaction.js +15 -0
- package/lib-es/logic/craftTransaction.js.map +1 -0
- package/lib-es/logic/estimateFees.d.ts +10 -0
- package/lib-es/logic/estimateFees.d.ts.map +1 -0
- package/lib-es/logic/estimateFees.js +13 -0
- package/lib-es/logic/estimateFees.js.map +1 -0
- package/lib-es/logic/index.d.ts +4 -0
- package/lib-es/logic/index.d.ts.map +1 -0
- package/lib-es/logic/index.js +4 -0
- package/lib-es/logic/index.js.map +1 -0
- package/lib-es/network/index.d.ts +18 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +10 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/sdk.d.ts +61 -0
- package/lib-es/network/sdk.d.ts.map +1 -0
- package/lib-es/network/sdk.integration.test.d.ts +2 -0
- package/lib-es/network/sdk.integration.test.d.ts.map +1 -0
- package/lib-es/network/sdk.integration.test.js +65 -0
- package/lib-es/network/sdk.integration.test.js.map +1 -0
- package/lib-es/network/sdk.js +189 -0
- package/lib-es/network/sdk.js.map +1 -0
- package/lib-es/network/sdk.test.d.ts +2 -0
- package/lib-es/network/sdk.test.d.ts.map +1 -0
- package/lib-es/network/sdk.test.js +164 -0
- package/lib-es/network/sdk.test.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 +18 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- 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 +101 -0
- package/lib-es/signer/getAddress.test.js.map +1 -0
- package/lib-es/signer/index.d.ts +6 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +6 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/cli.d.ts +16 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +13 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/types/bridge.d.ts +72 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.fixture.d.ts +30 -0
- package/lib-es/types/bridge.fixture.d.ts.map +1 -0
- package/lib-es/types/bridge.fixture.js +80 -0
- package/lib-es/types/bridge.fixture.js.map +1 -0
- package/lib-es/types/bridge.js +2 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +4 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/model.d.ts +6 -0
- package/lib-es/types/model.d.ts.map +1 -0
- package/lib-es/types/model.js +2 -0
- package/lib-es/types/model.js.map +1 -0
- package/lib-es/types/signer.d.ts +13 -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/lib-es/utils.d.ts +7 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +9 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +152 -0
- package/src/api/chain/index.ts +17 -0
- package/src/bridge/bridge.integration.test.ts +140 -0
- package/src/bridge/broadcast.test.ts +52 -0
- package/src/bridge/broadcast.ts +21 -0
- package/src/bridge/buildOptimisticOperation.test.ts +53 -0
- package/src/bridge/buildOptimisticOperation.ts +105 -0
- package/src/bridge/buildTransaction.test.ts +17 -0
- package/src/bridge/buildTransaction.ts +14 -0
- package/src/bridge/createTransaction.ts +23 -0
- package/src/bridge/estimateMaxSpendable.test.ts +27 -0
- package/src/bridge/estimateMaxSpendable.ts +46 -0
- package/src/bridge/formatters.test.ts +17 -0
- package/src/bridge/formatters.ts +26 -0
- package/src/bridge/getFeesForTransaction.test.ts +36 -0
- package/src/bridge/getFeesForTransaction.ts +37 -0
- package/src/bridge/getTransactionStatus.test.ts +57 -0
- package/src/bridge/getTransactionStatus.ts +73 -0
- package/src/bridge/index.ts +77 -0
- package/src/bridge/preload.ts +46 -0
- package/src/bridge/prepareTransaction.test.ts +47 -0
- package/src/bridge/prepareTransaction.ts +44 -0
- package/src/bridge/serialization.test.ts +135 -0
- package/src/bridge/serialization.ts +24 -0
- package/src/bridge/signOperation.test.ts +80 -0
- package/src/bridge/signOperation.ts +101 -0
- package/src/bridge/synchronisation.test.ts +140 -0
- package/src/bridge/synchronisation.ts +75 -0
- package/src/bridge/transaction.test.ts +73 -0
- package/src/bridge/transaction.ts +61 -0
- package/src/bridge/utils.ts +69 -0
- package/src/config.ts +19 -0
- package/src/index.ts +3 -0
- package/src/logic/broadcast.ts +19 -0
- package/src/logic/craftTransaction.ts +28 -0
- package/src/logic/estimateFees.ts +14 -0
- package/src/logic/index.ts +3 -0
- package/src/network/index.ts +17 -0
- package/src/network/sdk.integration.test.ts +75 -0
- package/src/network/sdk.test.ts +203 -0
- package/src/network/sdk.ts +262 -0
- package/src/signer/getAddress.test.ts +119 -0
- package/src/signer/getAddress.ts +26 -0
- package/src/signer/index.ts +7 -0
- package/src/test/cli.ts +21 -0
- package/src/types/bridge.fixture.ts +84 -0
- package/src/types/bridge.ts +95 -0
- package/src/types/index.ts +3 -0
- package/src/types/model.ts +7 -0
- package/src/types/signer.ts +12 -0
- package/src/utils.ts +8 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
3
|
+
import { broadcast as logicBroadcast } from "../logic";
|
|
4
|
+
import { SuiSignedOperation, Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Broadcast the signed transaction
|
|
8
|
+
* @param {Object} params - The parameters for broadcasting the transaction.
|
|
9
|
+
* @param {Object} params.signedOperation - The signed operation to be broadcasted.
|
|
10
|
+
* @param {Object} params.signedOperation.operation - The operation details.
|
|
11
|
+
* @param {Object} params.signedOperation.rawData - The raw data of the signed operation.
|
|
12
|
+
* @returns {Promise<Object>} The operation with the hash of the transaction.
|
|
13
|
+
*/
|
|
14
|
+
export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({ signedOperation }) => {
|
|
15
|
+
const {
|
|
16
|
+
operation,
|
|
17
|
+
rawData: { unsigned, serializedSignature },
|
|
18
|
+
} = signedOperation as unknown as SuiSignedOperation;
|
|
19
|
+
const hash = await logicBroadcast(unsigned, serializedSignature);
|
|
20
|
+
return patchOperationWithHash(operation, hash);
|
|
21
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
|
|
3
|
+
import { buildOptimisticOperation } from "./buildOptimisticOperation";
|
|
4
|
+
import { SuiAccount, Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
describe("buildOptimisticOperation", () => {
|
|
7
|
+
it("should build optimistic operation for transfer", () => {
|
|
8
|
+
// GIVEN
|
|
9
|
+
const account: SuiAccount = createFixtureAccount();
|
|
10
|
+
const transaction: Transaction = createFixtureTransaction();
|
|
11
|
+
const fee = new BigNumber(10);
|
|
12
|
+
|
|
13
|
+
// WHEN
|
|
14
|
+
const result = buildOptimisticOperation(account, transaction, fee);
|
|
15
|
+
|
|
16
|
+
// THEN
|
|
17
|
+
expect(result).toEqual({
|
|
18
|
+
id: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui--OUT",
|
|
19
|
+
hash: "",
|
|
20
|
+
type: "OUT",
|
|
21
|
+
value: transaction.amount.plus(fee), // amount + fee
|
|
22
|
+
fee: new BigNumber(10),
|
|
23
|
+
senders: ["0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0"],
|
|
24
|
+
recipients: ["0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24"],
|
|
25
|
+
accountId: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui",
|
|
26
|
+
date: expect.any(Date),
|
|
27
|
+
blockHash: null,
|
|
28
|
+
blockHeight: null,
|
|
29
|
+
extra: {
|
|
30
|
+
transferAmount: new BigNumber(3000000000),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should calculate correct value for OUT type", () => {
|
|
36
|
+
// GIVEN
|
|
37
|
+
const account: SuiAccount = createFixtureAccount();
|
|
38
|
+
const transaction: Transaction = createFixtureTransaction();
|
|
39
|
+
const amount = new BigNumber(500);
|
|
40
|
+
const fee = new BigNumber(50);
|
|
41
|
+
const tx = {
|
|
42
|
+
...transaction,
|
|
43
|
+
amount,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// WHEN
|
|
47
|
+
const result = buildOptimisticOperation(account, tx, fee);
|
|
48
|
+
|
|
49
|
+
// THEN
|
|
50
|
+
expect(result.value).toEqual(amount.plus(fee));
|
|
51
|
+
expect(result.fee).toEqual(fee);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import type { Account, OperationType } from "@ledgerhq/types-live";
|
|
3
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
4
|
+
import {
|
|
5
|
+
CommandDescriptor,
|
|
6
|
+
SuiAccount,
|
|
7
|
+
SuiOperation,
|
|
8
|
+
SuiOperationExtra,
|
|
9
|
+
SuiOperationMode,
|
|
10
|
+
Transaction,
|
|
11
|
+
} from "../types";
|
|
12
|
+
import { assertUnreachable } from "./utils";
|
|
13
|
+
|
|
14
|
+
const MODE_TO_TYPE: Record<SuiOperationMode | "default", OperationType> = {
|
|
15
|
+
send: "OUT",
|
|
16
|
+
default: "OUT",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getExtra = (type: string, transaction: Transaction): SuiOperationExtra => {
|
|
20
|
+
const extra: SuiOperationExtra = {};
|
|
21
|
+
|
|
22
|
+
switch (type) {
|
|
23
|
+
case "OUT":
|
|
24
|
+
return { ...extra, transferAmount: new BigNumber(transaction.amount) };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return extra;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const buildOptimisticOperation = (
|
|
31
|
+
account: SuiAccount,
|
|
32
|
+
transaction: Transaction,
|
|
33
|
+
fee: BigNumber,
|
|
34
|
+
): SuiOperation => {
|
|
35
|
+
const commandDescriptor: CommandDescriptor = {
|
|
36
|
+
command: {
|
|
37
|
+
kind: "transfer" as const,
|
|
38
|
+
sender: account.freshAddress,
|
|
39
|
+
recipient: transaction.recipient,
|
|
40
|
+
amount: transaction.amount.toNumber(),
|
|
41
|
+
},
|
|
42
|
+
fee: fee.toNumber(),
|
|
43
|
+
warnings: {},
|
|
44
|
+
errors: {},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const optimisticOperation = buildOptimisticOperationForCommand(
|
|
48
|
+
account,
|
|
49
|
+
transaction,
|
|
50
|
+
commandDescriptor,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return optimisticOperation;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function buildOptimisticOperationForCommand(
|
|
57
|
+
account: Account,
|
|
58
|
+
transaction: Transaction,
|
|
59
|
+
commandDescriptor: CommandDescriptor,
|
|
60
|
+
): SuiOperation {
|
|
61
|
+
const { command } = commandDescriptor;
|
|
62
|
+
switch (command.kind) {
|
|
63
|
+
case "transfer":
|
|
64
|
+
return optimisticOpForTransfer(account, transaction, commandDescriptor);
|
|
65
|
+
default:
|
|
66
|
+
// @ts-expect-error Seem like a bug in TS, remove once more commands are added
|
|
67
|
+
return assertUnreachable(command);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function optimisticOpForTransfer(
|
|
72
|
+
account: Account,
|
|
73
|
+
transaction: Transaction,
|
|
74
|
+
commandDescriptor: CommandDescriptor,
|
|
75
|
+
): SuiOperation {
|
|
76
|
+
const type = MODE_TO_TYPE.default;
|
|
77
|
+
const value =
|
|
78
|
+
type === "OUT"
|
|
79
|
+
? new BigNumber(transaction.amount).plus(commandDescriptor.fee)
|
|
80
|
+
: new BigNumber(commandDescriptor.fee);
|
|
81
|
+
const extra = getExtra(type, transaction);
|
|
82
|
+
|
|
83
|
+
const commons = optimisticOpcommons(commandDescriptor);
|
|
84
|
+
return {
|
|
85
|
+
...commons,
|
|
86
|
+
id: encodeOperationId(account.id, "", type),
|
|
87
|
+
type,
|
|
88
|
+
value,
|
|
89
|
+
senders: [account.freshAddress],
|
|
90
|
+
recipients: [transaction.recipient].filter(Boolean),
|
|
91
|
+
accountId: account.id,
|
|
92
|
+
date: new Date(),
|
|
93
|
+
extra,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function optimisticOpcommons(commandDescriptor: CommandDescriptor) {
|
|
98
|
+
return {
|
|
99
|
+
hash: "",
|
|
100
|
+
fee: new BigNumber(commandDescriptor.fee),
|
|
101
|
+
blockHash: null,
|
|
102
|
+
blockHeight: null,
|
|
103
|
+
extra: {},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { buildTransaction } from "./buildTransaction";
|
|
2
|
+
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
|
|
3
|
+
|
|
4
|
+
describe("buildTransaction", () => {
|
|
5
|
+
it("returns unsigned tx bytes for given tx", async () => {
|
|
6
|
+
// GIVEN
|
|
7
|
+
const account = createFixtureAccount();
|
|
8
|
+
const transaction = createFixtureTransaction();
|
|
9
|
+
|
|
10
|
+
// WHEN
|
|
11
|
+
const result = await buildTransaction(account, transaction);
|
|
12
|
+
|
|
13
|
+
// THEN
|
|
14
|
+
expect(result).not.toBeNull();
|
|
15
|
+
expect(result.unsigned).toBeInstanceOf(Uint8Array);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import pick from "lodash/pick";
|
|
2
|
+
import type { SuiAccount, Transaction } from "../types";
|
|
3
|
+
import { craftTransaction, type CreateExtrinsicArg } from "../logic";
|
|
4
|
+
|
|
5
|
+
export const extractExtrinsicArg = (transaction: Transaction): CreateExtrinsicArg =>
|
|
6
|
+
pick(transaction, ["mode", "amount", "recipient", "useAllAmount"]);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {Account} account
|
|
10
|
+
* @param {Transaction} transaction
|
|
11
|
+
*/
|
|
12
|
+
export const buildTransaction = async (account: SuiAccount, transaction: Transaction) => {
|
|
13
|
+
return craftTransaction(account.freshAddress, extractExtrinsicArg(transaction));
|
|
14
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { Transaction } from "../types";
|
|
3
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create an empty transaction
|
|
7
|
+
*
|
|
8
|
+
* @returns {Transaction}
|
|
9
|
+
*/
|
|
10
|
+
export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => {
|
|
11
|
+
const transaction: Transaction = {
|
|
12
|
+
family: "sui" as const,
|
|
13
|
+
mode: "send",
|
|
14
|
+
amount: new BigNumber(0),
|
|
15
|
+
recipient: "",
|
|
16
|
+
useAllAmount: false,
|
|
17
|
+
fees: null,
|
|
18
|
+
errors: {},
|
|
19
|
+
};
|
|
20
|
+
return transaction;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default createTransaction;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
3
|
+
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
|
|
4
|
+
import { SuiAccount, Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
const mockEstimateFees = jest.fn();
|
|
7
|
+
jest.mock("../logic", () => ({
|
|
8
|
+
estimateFees: () => mockEstimateFees(),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
describe("estimateMaxSpendable", () => {
|
|
12
|
+
it("should return the correct spendable amount when fees are deducted", async () => {
|
|
13
|
+
// GIVEN
|
|
14
|
+
const balance = new BigNumber(100);
|
|
15
|
+
const account: SuiAccount = createFixtureAccount({ spendableBalance: balance });
|
|
16
|
+
const transaction: Transaction = createFixtureTransaction();
|
|
17
|
+
const fees = new BigNumber(10);
|
|
18
|
+
mockEstimateFees.mockResolvedValue(fees);
|
|
19
|
+
|
|
20
|
+
// WHEN
|
|
21
|
+
const result = await estimateMaxSpendable({ account, transaction });
|
|
22
|
+
|
|
23
|
+
// THEN
|
|
24
|
+
expect(mockEstimateFees).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(result).toEqual(balance.minus(fees));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
3
|
+
import type { SuiAccount, Transaction } from "../types";
|
|
4
|
+
import getFeesForTransaction from "./getFeesForTransaction";
|
|
5
|
+
import createTransaction from "./createTransaction";
|
|
6
|
+
import { BigNumber } from "bignumber.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns the maximum possible amount for transaction
|
|
10
|
+
* @typedef {Object} EstimateMaxSpendableParams
|
|
11
|
+
* @property {SuiAccount} account - The account from which to estimate the maximum spendable amount.
|
|
12
|
+
* @property {SuiAccount} [parentAccount] - The parent account, if applicable.
|
|
13
|
+
* @property {Transaction} transaction - The transaction details for which to estimate the maximum spendable amount.
|
|
14
|
+
*
|
|
15
|
+
* @returns {Promise<BigNumber>} The estimated maximum spendable amount.
|
|
16
|
+
*/
|
|
17
|
+
export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
|
|
18
|
+
account,
|
|
19
|
+
parentAccount,
|
|
20
|
+
transaction,
|
|
21
|
+
}) => {
|
|
22
|
+
try {
|
|
23
|
+
const mainAccount = getMainAccount(account, parentAccount) as SuiAccount;
|
|
24
|
+
|
|
25
|
+
const estimatedTransaction = {
|
|
26
|
+
...createTransaction(account),
|
|
27
|
+
...transaction,
|
|
28
|
+
useAllAmount: true,
|
|
29
|
+
};
|
|
30
|
+
const fees = await getFeesForTransaction({
|
|
31
|
+
account: mainAccount,
|
|
32
|
+
transaction: estimatedTransaction,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
let spendableBalance = mainAccount.spendableBalance;
|
|
36
|
+
if (fees) {
|
|
37
|
+
spendableBalance = BigNumber.max(spendableBalance.minus(fees), 0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return spendableBalance;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return new BigNumber(0);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default estimateMaxSpendable;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fromOperationExtraRaw, toOperationExtraRaw } from "./formatters";
|
|
2
|
+
|
|
3
|
+
describe("formatters", () => {
|
|
4
|
+
describe("fromOperationExtraRaw", () => {
|
|
5
|
+
it("should return an empty object when no extraRaw is provided", () => {
|
|
6
|
+
const result = fromOperationExtraRaw(undefined);
|
|
7
|
+
expect(result).toEqual({});
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe("toOperationExtraRaw", () => {
|
|
12
|
+
it("should return an empty object when no extra is provided", () => {
|
|
13
|
+
const result = toOperationExtraRaw(undefined);
|
|
14
|
+
expect(result).toEqual({});
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { OperationExtra, OperationExtraRaw } from "@ledgerhq/types-live";
|
|
2
|
+
import type { SuiOperationExtra, SuiOperationExtraRaw } from "../types";
|
|
3
|
+
|
|
4
|
+
export function fromOperationExtraRaw(extraRaw: OperationExtraRaw) {
|
|
5
|
+
if (extraRaw) {
|
|
6
|
+
// reserved for future use
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const extra: SuiOperationExtra = {};
|
|
10
|
+
|
|
11
|
+
return extra;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function toOperationExtraRaw(extra: OperationExtra) {
|
|
15
|
+
if (extra) {
|
|
16
|
+
// reserved for future use
|
|
17
|
+
}
|
|
18
|
+
const extraRaw: SuiOperationExtraRaw = {};
|
|
19
|
+
|
|
20
|
+
return extraRaw;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
fromOperationExtraRaw,
|
|
25
|
+
toOperationExtraRaw,
|
|
26
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import getEstimatedFees from "./getFeesForTransaction";
|
|
2
|
+
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
|
|
3
|
+
|
|
4
|
+
const estimateFees = jest.fn();
|
|
5
|
+
|
|
6
|
+
jest.mock("../logic", () => {
|
|
7
|
+
return {
|
|
8
|
+
estimateFees: (arg: any) => estimateFees(arg),
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe("getEstimatedFees", () => {
|
|
13
|
+
const transaction = createFixtureTransaction();
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
estimateFees.mockClear();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("returns fees estimation by sui sdk", async () => {
|
|
20
|
+
// GIVEN
|
|
21
|
+
const account = createFixtureAccount();
|
|
22
|
+
const gasBudget = BigInt("3976000");
|
|
23
|
+
estimateFees.mockResolvedValue(gasBudget);
|
|
24
|
+
|
|
25
|
+
// WHEN
|
|
26
|
+
const result = await getEstimatedFees({
|
|
27
|
+
account,
|
|
28
|
+
transaction,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// THEN
|
|
32
|
+
expect(estimateFees).toHaveBeenCalledTimes(1);
|
|
33
|
+
expect(estimateFees.mock.lastCall).not.toBeNull();
|
|
34
|
+
expect(result.toString()).toEqual(gasBudget.toString());
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets";
|
|
3
|
+
import type { SuiAccount, Transaction } from "../types";
|
|
4
|
+
import { calculateAmount } from "./utils";
|
|
5
|
+
import { estimateFees } from "../logic";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Fetch the transaction fees for a transaction
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} params
|
|
11
|
+
* @param {SuiAccount} params.account - The account to estimate fees for
|
|
12
|
+
* @param {Transaction} params.transaction - The transaction to estimate fees for
|
|
13
|
+
* @returns {Promise<BigNumber>} The estimated fees
|
|
14
|
+
*/
|
|
15
|
+
export default async function getEstimatedFees({
|
|
16
|
+
account,
|
|
17
|
+
transaction,
|
|
18
|
+
}: {
|
|
19
|
+
account: SuiAccount;
|
|
20
|
+
transaction: Transaction;
|
|
21
|
+
}): Promise<BigNumber> {
|
|
22
|
+
const t = {
|
|
23
|
+
...transaction,
|
|
24
|
+
recipient: getAbandonSeedAddress(account.currency.id),
|
|
25
|
+
// Always use a fake recipient to estimate fees
|
|
26
|
+
amount: calculateAmount({
|
|
27
|
+
account,
|
|
28
|
+
transaction: {
|
|
29
|
+
...transaction,
|
|
30
|
+
fees: new BigNumber(transaction.fees || 0),
|
|
31
|
+
},
|
|
32
|
+
}), // Remove fees if present since we are fetching fees
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const fees = await estimateFees(account.freshAddress, t);
|
|
36
|
+
return new BigNumber(fees.toString());
|
|
37
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NotEnoughBalance,
|
|
3
|
+
RecipientRequired,
|
|
4
|
+
InvalidAddress,
|
|
5
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
6
|
+
AmountRequired,
|
|
7
|
+
FeeNotLoaded,
|
|
8
|
+
} from "@ledgerhq/errors";
|
|
9
|
+
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
|
|
10
|
+
import getTransactionStatus from "./getTransactionStatus";
|
|
11
|
+
|
|
12
|
+
const account = createFixtureAccount();
|
|
13
|
+
|
|
14
|
+
describe("getTransactionStatus", () => {
|
|
15
|
+
it("should return errors if recipient empty", async () => {
|
|
16
|
+
const transaction = createFixtureTransaction({ recipient: null });
|
|
17
|
+
const result = await getTransactionStatus(account, transaction);
|
|
18
|
+
|
|
19
|
+
const expected = { recipient: new RecipientRequired() };
|
|
20
|
+
expect(result.errors).toEqual(expected);
|
|
21
|
+
});
|
|
22
|
+
it("should return errors if recipient is invalid sui adress", async () => {
|
|
23
|
+
const transaction = createFixtureTransaction({ recipient: "notValidSuiAddress" });
|
|
24
|
+
const result = await getTransactionStatus(account, transaction);
|
|
25
|
+
|
|
26
|
+
const expected = { recipient: new InvalidAddress() };
|
|
27
|
+
expect(result.errors).toEqual(expected);
|
|
28
|
+
});
|
|
29
|
+
it("should return errors if recipient equals to sender", async () => {
|
|
30
|
+
const transaction = createFixtureTransaction({ recipient: account.freshAddress });
|
|
31
|
+
const result = await getTransactionStatus(account, transaction);
|
|
32
|
+
|
|
33
|
+
const expected = { recipient: new InvalidAddressBecauseDestinationIsAlsoSource() };
|
|
34
|
+
expect(result.errors).toEqual(expected);
|
|
35
|
+
});
|
|
36
|
+
it("should return errors if amount not provided", async () => {
|
|
37
|
+
const transaction = createFixtureTransaction({ amount: null });
|
|
38
|
+
const result = await getTransactionStatus(account, transaction);
|
|
39
|
+
|
|
40
|
+
const expected = { amount: new AmountRequired() };
|
|
41
|
+
expect(result.errors).toEqual(expected);
|
|
42
|
+
});
|
|
43
|
+
it("should return errors if amount exceeds balance", async () => {
|
|
44
|
+
const transaction = createFixtureTransaction({ amount: account.balance.plus(1) });
|
|
45
|
+
const result = await getTransactionStatus(account, transaction);
|
|
46
|
+
|
|
47
|
+
const expected = { amount: new NotEnoughBalance() };
|
|
48
|
+
expect(result.errors).toEqual(expected);
|
|
49
|
+
});
|
|
50
|
+
it("should return errors if amount exceeds balance", async () => {
|
|
51
|
+
const transaction = createFixtureTransaction({ fees: null });
|
|
52
|
+
const result = await getTransactionStatus(account, transaction);
|
|
53
|
+
|
|
54
|
+
const expected = { fees: new FeeNotLoaded() };
|
|
55
|
+
expect(result.errors).toEqual(expected);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import {
|
|
3
|
+
NotEnoughBalance,
|
|
4
|
+
RecipientRequired,
|
|
5
|
+
InvalidAddress,
|
|
6
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
7
|
+
AmountRequired,
|
|
8
|
+
FeeNotLoaded,
|
|
9
|
+
FeeTooHigh,
|
|
10
|
+
} from "@ledgerhq/errors";
|
|
11
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
12
|
+
import type { SuiAccount, Transaction, TransactionStatus } from "../types";
|
|
13
|
+
import { isValidSuiAddress } from "@mysten/sui/utils";
|
|
14
|
+
import { ensureAddressFormat } from "../utils";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get the status of a transaction.
|
|
18
|
+
* @function getTransactionStatus
|
|
19
|
+
* @param {SuiAccount} account - The account associated with the transaction.
|
|
20
|
+
* @param {Transaction} transaction - The transaction object containing details such as amount, fees, and recipient.
|
|
21
|
+
* @returns {Promise<Object>} A promise that resolves to an object containing the transaction status, including errors, warnings, estimated fees, amount, and total spent.
|
|
22
|
+
*/
|
|
23
|
+
export const getTransactionStatus: AccountBridge<
|
|
24
|
+
Transaction,
|
|
25
|
+
SuiAccount,
|
|
26
|
+
TransactionStatus
|
|
27
|
+
>["getTransactionStatus"] = async (account, transaction) => {
|
|
28
|
+
const errors: Record<string, Error> = {};
|
|
29
|
+
const warnings: Record<string, Error> = {};
|
|
30
|
+
const amount = new BigNumber(transaction?.amount || 0);
|
|
31
|
+
const estimatedFees = new BigNumber(transaction?.fees || 0);
|
|
32
|
+
const totalSpent = amount.plus(estimatedFees);
|
|
33
|
+
|
|
34
|
+
if (amount.lte(0)) {
|
|
35
|
+
errors.amount = new AmountRequired();
|
|
36
|
+
} else if (estimatedFees.times(10).gt(amount)) {
|
|
37
|
+
warnings.feeTooHigh = new FeeTooHigh();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (transaction) {
|
|
41
|
+
if (!transaction.recipient) {
|
|
42
|
+
errors.recipient = new RecipientRequired();
|
|
43
|
+
} else if (!isValidSuiAddress(transaction.recipient)) {
|
|
44
|
+
errors.recipient = new InvalidAddress(undefined, {
|
|
45
|
+
currencyName: account.currency.name,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (ensureAddressFormat(account.freshAddress) === ensureAddressFormat(transaction.recipient)) {
|
|
50
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (totalSpent.eq(0) && transaction.useAllAmount) {
|
|
54
|
+
errors.amount = new NotEnoughBalance();
|
|
55
|
+
}
|
|
56
|
+
if (totalSpent.gt(account.balance)) {
|
|
57
|
+
errors.amount = new NotEnoughBalance();
|
|
58
|
+
}
|
|
59
|
+
if (!transaction.fees) {
|
|
60
|
+
errors.fees = new FeeNotLoaded();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
errors,
|
|
66
|
+
warnings,
|
|
67
|
+
estimatedFees,
|
|
68
|
+
amount: amount.lt(0) ? new BigNumber(0) : amount,
|
|
69
|
+
totalSpent,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default getTransactionStatus;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import {
|
|
3
|
+
getSerializedAddressParameters,
|
|
4
|
+
updateTransaction,
|
|
5
|
+
makeAccountBridgeReceive,
|
|
6
|
+
makeScanAccounts,
|
|
7
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
8
|
+
import { CoinConfig } from "@ledgerhq/coin-framework/config";
|
|
9
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
10
|
+
import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
11
|
+
import suiConfig, { type SuiCoinConfig } from "../config";
|
|
12
|
+
import signerGetAddress from "../signer";
|
|
13
|
+
import { SuiAccount, SuiSigner, TransactionStatus, type Transaction } from "../types";
|
|
14
|
+
import { broadcast } from "./broadcast";
|
|
15
|
+
import { createTransaction } from "./createTransaction";
|
|
16
|
+
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
17
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
18
|
+
import { getPreloadStrategy, hydrate, preload } from "./preload";
|
|
19
|
+
import { prepareTransaction } from "./prepareTransaction";
|
|
20
|
+
import { assignFromAccountRaw, assignToAccountRaw } from "./serialization";
|
|
21
|
+
import { fromOperationExtraRaw, toOperationExtraRaw } from "./formatters";
|
|
22
|
+
import { buildSignOperation } from "./signOperation";
|
|
23
|
+
import { getAccountShape, sync } from "./synchronisation";
|
|
24
|
+
|
|
25
|
+
function buildCurrencyBridge(signerContext: SignerContext<SuiSigner>): CurrencyBridge {
|
|
26
|
+
const getAddress = signerGetAddress(signerContext);
|
|
27
|
+
|
|
28
|
+
const scanAccounts = makeScanAccounts({
|
|
29
|
+
getAccountShape,
|
|
30
|
+
getAddressFn: getAddressWrapper(getAddress),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
getPreloadStrategy,
|
|
35
|
+
preload,
|
|
36
|
+
hydrate,
|
|
37
|
+
scanAccounts,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function buildAccountBridge(
|
|
42
|
+
signerContext: SignerContext<SuiSigner>,
|
|
43
|
+
): AccountBridge<Transaction, SuiAccount, TransactionStatus> {
|
|
44
|
+
const getAddress = signerGetAddress(signerContext);
|
|
45
|
+
|
|
46
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
47
|
+
const signOperation = buildSignOperation(signerContext);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
estimateMaxSpendable,
|
|
51
|
+
createTransaction,
|
|
52
|
+
updateTransaction,
|
|
53
|
+
getTransactionStatus,
|
|
54
|
+
prepareTransaction,
|
|
55
|
+
sync,
|
|
56
|
+
receive,
|
|
57
|
+
signOperation,
|
|
58
|
+
broadcast,
|
|
59
|
+
assignFromAccountRaw,
|
|
60
|
+
assignToAccountRaw,
|
|
61
|
+
fromOperationExtraRaw,
|
|
62
|
+
toOperationExtraRaw,
|
|
63
|
+
getSerializedAddressParameters,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function createBridges(
|
|
68
|
+
signerContext: SignerContext<SuiSigner>,
|
|
69
|
+
coinConfig: CoinConfig<SuiCoinConfig>,
|
|
70
|
+
) {
|
|
71
|
+
suiConfig.setCoinConfig(coinConfig);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
75
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
76
|
+
};
|
|
77
|
+
}
|