@ledgerhq/coin-celo 1.1.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 +22 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +56 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/jest.integ.config.js +8 -0
- package/lib/bridge/broadcast.d.ts +5 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +13 -0
- package/lib/bridge/broadcast.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 +49 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/buildTransaction.d.ts +5 -0
- package/lib/bridge/buildTransaction.d.ts.map +1 -0
- package/lib/bridge/buildTransaction.js +142 -0
- package/lib/bridge/buildTransaction.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +5 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +16 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +4 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +16 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +23 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getFeesForTransaction.d.ts +8 -0
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib/bridge/getFeesForTransaction.js +93 -0
- package/lib/bridge/getFeesForTransaction.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 +98 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +11 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +62 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/preload.d.ts +10 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +72 -0
- package/lib/bridge/preload.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +5 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +28 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/serialization.d.ts +9 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +92 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +10 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +77 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/synchronisation.d.ts +5 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -0
- package/lib/bridge/synchronisation.js +49 -0
- package/lib/bridge/synchronisation.js.map +1 -0
- package/lib/bridge/transaction.d.ts +14 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +47 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +14 -0
- package/lib/config.js.map +1 -0
- package/lib/datasets/celo.scanAccounts.1.d.ts +5 -0
- package/lib/datasets/celo.scanAccounts.1.d.ts.map +1 -0
- package/lib/datasets/celo.scanAccounts.1.js +364 -0
- package/lib/datasets/celo.scanAccounts.1.js.map +1 -0
- package/lib/errors.d.ts +4 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +6 -0
- package/lib/errors.js.map +1 -0
- package/lib/logic.d.ts +21 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +97 -0
- package/lib/logic.js.map +1 -0
- package/lib/network/hubble.d.ts +12 -0
- package/lib/network/hubble.d.ts.map +1 -0
- package/lib/network/hubble.js +141 -0
- package/lib/network/hubble.js.map +1 -0
- package/lib/network/index.d.ts +4 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +23 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/sdk.d.ts +27 -0
- package/lib/network/sdk.d.ts.map +1 -0
- package/lib/network/sdk.js +93 -0
- package/lib/network/sdk.js.map +1 -0
- package/lib/network/validators.d.ts +2 -0
- package/lib/network/validators.d.ts.map +1 -0
- package/lib/network/validators.js +6 -0
- package/lib/network/validators.js.map +1 -0
- package/lib/signer/hw-getAddress.d.ts +6 -0
- package/lib/signer/hw-getAddress.d.ts.map +1 -0
- package/lib/signer/hw-getAddress.js +26 -0
- package/lib/signer/hw-getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +2 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +18 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/signer/signer.d.ts +16 -0
- package/lib/signer/signer.d.ts.map +1 -0
- package/lib/signer/signer.js +3 -0
- package/lib/signer/signer.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +42 -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 +14 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli-transaction.d.ts +25 -0
- package/lib/test/cli-transaction.d.ts.map +1 -0
- package/lib/test/cli-transaction.js +56 -0
- package/lib/test/cli-transaction.js.map +1 -0
- package/lib/test/please-add-coverage.test.d.ts +2 -0
- package/lib/test/please-add-coverage.test.d.ts.map +1 -0
- package/lib/test/please-add-coverage.test.js +6 -0
- package/lib/test/please-add-coverage.test.js.map +1 -0
- package/lib/test/specs/createActivateVoteMutation.d.ts +4 -0
- package/lib/test/specs/createActivateVoteMutation.d.ts.map +1 -0
- package/lib/test/specs/createActivateVoteMutation.js +37 -0
- package/lib/test/specs/createActivateVoteMutation.js.map +1 -0
- package/lib/test/specs/createLockMutation.d.ts +4 -0
- package/lib/test/specs/createLockMutation.d.ts.map +1 -0
- package/lib/test/specs/createLockMutation.js +37 -0
- package/lib/test/specs/createLockMutation.js.map +1 -0
- package/lib/test/specs/createRegisterAccountMutation.d.ts +4 -0
- package/lib/test/specs/createRegisterAccountMutation.d.ts.map +1 -0
- package/lib/test/specs/createRegisterAccountMutation.js +31 -0
- package/lib/test/specs/createRegisterAccountMutation.js.map +1 -0
- package/lib/test/specs/createRevokeVoteMutation.d.ts +4 -0
- package/lib/test/specs/createRevokeVoteMutation.d.ts.map +1 -0
- package/lib/test/specs/createRevokeVoteMutation.js +38 -0
- package/lib/test/specs/createRevokeVoteMutation.js.map +1 -0
- package/lib/test/specs/createSendMutation.d.ts +6 -0
- package/lib/test/specs/createSendMutation.d.ts.map +1 -0
- package/lib/test/specs/createSendMutation.js +45 -0
- package/lib/test/specs/createSendMutation.js.map +1 -0
- package/lib/test/specs/createUnlockMutation.d.ts +4 -0
- package/lib/test/specs/createUnlockMutation.d.ts.map +1 -0
- package/lib/test/specs/createUnlockMutation.js +37 -0
- package/lib/test/specs/createUnlockMutation.js.map +1 -0
- package/lib/test/specs/createVoteMutation.d.ts +4 -0
- package/lib/test/specs/createVoteMutation.d.ts.map +1 -0
- package/lib/test/specs/createVoteMutation.js +48 -0
- package/lib/test/specs/createVoteMutation.js.map +1 -0
- package/lib/test/specs/createWithdrawMutation.d.ts +4 -0
- package/lib/test/specs/createWithdrawMutation.d.ts.map +1 -0
- package/lib/test/specs/createWithdrawMutation.js +37 -0
- package/lib/test/specs/createWithdrawMutation.js.map +1 -0
- package/lib/test/specs/index.d.ts +9 -0
- package/lib/test/specs/index.d.ts.map +1 -0
- package/lib/test/specs/index.js +25 -0
- package/lib/test/specs/index.js.map +1 -0
- package/lib/test/speculos-deviceActions.d.ts +4 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib/test/speculos-deviceActions.js +58 -0
- package/lib/test/speculos-deviceActions.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 +19 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/types.d.ts +126 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +11 -0
- package/lib/types/types.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +5 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +9 -0
- package/lib-es/bridge/broadcast.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 +42 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/buildTransaction.d.ts +5 -0
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
- package/lib-es/bridge/buildTransaction.js +140 -0
- package/lib-es/bridge/buildTransaction.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +5 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +12 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +4 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +14 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +16 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts +8 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.js +91 -0
- package/lib-es/bridge/getFeesForTransaction.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 +94 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +11 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +54 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/preload.d.ts +10 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +64 -0
- package/lib-es/bridge/preload.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +5 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +21 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/serialization.d.ts +9 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +84 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +10 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +70 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/synchronisation.d.ts +5 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -0
- package/lib-es/bridge/synchronisation.js +45 -0
- package/lib-es/bridge/synchronisation.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +14 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +42 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/config.d.ts +3 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/datasets/celo.scanAccounts.1.d.ts +5 -0
- package/lib-es/datasets/celo.scanAccounts.1.d.ts.map +1 -0
- package/lib-es/datasets/celo.scanAccounts.1.js +359 -0
- package/lib-es/datasets/celo.scanAccounts.1.js.map +1 -0
- package/lib-es/errors.d.ts +4 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +3 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/logic.d.ts +21 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +77 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/network/hubble.d.ts +12 -0
- package/lib-es/network/hubble.d.ts.map +1 -0
- package/lib-es/network/hubble.js +133 -0
- package/lib-es/network/hubble.js.map +1 -0
- package/lib-es/network/index.d.ts +4 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +4 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/sdk.d.ts +27 -0
- package/lib-es/network/sdk.d.ts.map +1 -0
- package/lib-es/network/sdk.js +85 -0
- package/lib-es/network/sdk.js.map +1 -0
- package/lib-es/network/validators.d.ts +2 -0
- package/lib-es/network/validators.d.ts.map +1 -0
- package/lib-es/network/validators.js +2 -0
- package/lib-es/network/validators.js.map +1 -0
- package/lib-es/signer/hw-getAddress.d.ts +6 -0
- package/lib-es/signer/hw-getAddress.d.ts.map +1 -0
- package/lib-es/signer/hw-getAddress.js +21 -0
- package/lib-es/signer/hw-getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +2 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +2 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/signer/signer.d.ts +16 -0
- package/lib-es/signer/signer.d.ts.map +1 -0
- package/lib-es/signer/signer.js +2 -0
- package/lib-es/signer/signer.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +40 -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 +8 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli-transaction.d.ts +25 -0
- package/lib-es/test/cli-transaction.d.ts.map +1 -0
- package/lib-es/test/cli-transaction.js +50 -0
- package/lib-es/test/cli-transaction.js.map +1 -0
- package/lib-es/test/please-add-coverage.test.d.ts +1 -0
- package/lib-es/test/please-add-coverage.test.d.ts.map +1 -0
- package/lib-es/test/please-add-coverage.test.js +5 -0
- package/lib-es/test/please-add-coverage.test.js.map +1 -0
- package/lib-es/test/specs/createActivateVoteMutation.d.ts +4 -0
- package/lib-es/test/specs/createActivateVoteMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createActivateVoteMutation.js +30 -0
- package/lib-es/test/specs/createActivateVoteMutation.js.map +1 -0
- package/lib-es/test/specs/createLockMutation.d.ts +4 -0
- package/lib-es/test/specs/createLockMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createLockMutation.js +30 -0
- package/lib-es/test/specs/createLockMutation.js.map +1 -0
- package/lib-es/test/specs/createRegisterAccountMutation.d.ts +4 -0
- package/lib-es/test/specs/createRegisterAccountMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createRegisterAccountMutation.js +24 -0
- package/lib-es/test/specs/createRegisterAccountMutation.js.map +1 -0
- package/lib-es/test/specs/createRevokeVoteMutation.d.ts +4 -0
- package/lib-es/test/specs/createRevokeVoteMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createRevokeVoteMutation.js +31 -0
- package/lib-es/test/specs/createRevokeVoteMutation.js.map +1 -0
- package/lib-es/test/specs/createSendMutation.d.ts +6 -0
- package/lib-es/test/specs/createSendMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createSendMutation.js +37 -0
- package/lib-es/test/specs/createSendMutation.js.map +1 -0
- package/lib-es/test/specs/createUnlockMutation.d.ts +4 -0
- package/lib-es/test/specs/createUnlockMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createUnlockMutation.js +30 -0
- package/lib-es/test/specs/createUnlockMutation.js.map +1 -0
- package/lib-es/test/specs/createVoteMutation.d.ts +4 -0
- package/lib-es/test/specs/createVoteMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createVoteMutation.js +41 -0
- package/lib-es/test/specs/createVoteMutation.js.map +1 -0
- package/lib-es/test/specs/createWithdrawMutation.d.ts +4 -0
- package/lib-es/test/specs/createWithdrawMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createWithdrawMutation.js +30 -0
- package/lib-es/test/specs/createWithdrawMutation.js.map +1 -0
- package/lib-es/test/specs/index.d.ts +9 -0
- package/lib-es/test/specs/index.d.ts.map +1 -0
- package/lib-es/test/specs/index.js +9 -0
- package/lib-es/test/specs/index.js.map +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts +4 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/test/speculos-deviceActions.js +55 -0
- package/lib-es/test/speculos-deviceActions.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 +3 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/types.d.ts +126 -0
- package/lib-es/types/types.d.ts.map +1 -0
- package/lib-es/types/types.js +7 -0
- package/lib-es/types/types.js.map +1 -0
- package/package.json +156 -0
- package/src/bridge/broadcast.ts +14 -0
- package/src/bridge/buildOptimisticOperation.ts +53 -0
- package/src/bridge/buildTransaction.ts +154 -0
- package/src/bridge/createTransaction.ts +15 -0
- package/src/bridge/deviceTransactionConfig.ts +19 -0
- package/src/bridge/estimateMaxSpendable.ts +22 -0
- package/src/bridge/getFeesForTransaction.ts +115 -0
- package/src/bridge/getTransactionStatus.ts +120 -0
- package/src/bridge/index.ts +77 -0
- package/src/bridge/preload.ts +75 -0
- package/src/bridge/prepareTransaction.ts +33 -0
- package/src/bridge/serialization.ts +114 -0
- package/src/bridge/signOperation.ts +121 -0
- package/src/bridge/synchronisation.ts +60 -0
- package/src/bridge/transaction.ts +53 -0
- package/src/config.ts +12 -0
- package/src/datasets/celo.scanAccounts.1.ts +370 -0
- package/src/errors.ts +3 -0
- package/src/logic.ts +146 -0
- package/src/network/hubble.ts +183 -0
- package/src/network/index.ts +3 -0
- package/src/network/sdk.ts +101 -0
- package/src/network/validators.ts +1 -0
- package/src/signer/hw-getAddress.ts +27 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/signer.ts +36 -0
- package/src/test/bot-specs.ts +55 -0
- package/src/test/bridgeDatasetTest.ts +10 -0
- package/src/test/cli-transaction.ts +70 -0
- package/src/test/please-add-coverage.test.ts +3 -0
- package/src/test/specs/createActivateVoteMutation.ts +37 -0
- package/src/test/specs/createLockMutation.ts +38 -0
- package/src/test/specs/createRegisterAccountMutation.ts +35 -0
- package/src/test/specs/createRevokeVoteMutation.ts +38 -0
- package/src/test/specs/createSendMutation.ts +41 -0
- package/src/test/specs/createUnlockMutation.ts +35 -0
- package/src/test/specs/createVoteMutation.ts +55 -0
- package/src/test/specs/createWithdrawMutation.ts +37 -0
- package/src/test/specs/index.ts +8 -0
- package/src/test/speculos-deviceActions.ts +63 -0
- package/src/types/index.ts +3 -0
- package/src/types/types.ts +155 -0
- package/tsconfig.json +12 -0
package/package.json
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ledgerhq/coin-celo",
|
|
3
|
+
"version": "1.1.0-next.0",
|
|
4
|
+
"description": "celo coin integration",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ledger",
|
|
7
|
+
"LedgerWallet",
|
|
8
|
+
"Celo",
|
|
9
|
+
"Hardware Wallet"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-celo",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"typesVersions": {
|
|
23
|
+
"*": {
|
|
24
|
+
"lib/*": [
|
|
25
|
+
"lib/*"
|
|
26
|
+
],
|
|
27
|
+
"lib-es/*": [
|
|
28
|
+
"lib-es/*"
|
|
29
|
+
],
|
|
30
|
+
"deviceTransactionConfig": [
|
|
31
|
+
"lib/bridge/deviceTransactionConfig"
|
|
32
|
+
],
|
|
33
|
+
"specs": [
|
|
34
|
+
"lib/test/bot-specs"
|
|
35
|
+
],
|
|
36
|
+
"transaction": [
|
|
37
|
+
"lib/bridge/transaction"
|
|
38
|
+
],
|
|
39
|
+
"types": [
|
|
40
|
+
"lib/types/index"
|
|
41
|
+
],
|
|
42
|
+
"*": [
|
|
43
|
+
"lib/*",
|
|
44
|
+
"lib/bridge/*",
|
|
45
|
+
"lib/logic/*",
|
|
46
|
+
"lib/signer/*",
|
|
47
|
+
"lib/test/*",
|
|
48
|
+
"lib/types/*"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"exports": {
|
|
53
|
+
"./lib/*": "./lib/*.js",
|
|
54
|
+
"./lib-es/*": "./lib-es/*.js",
|
|
55
|
+
"./api": {
|
|
56
|
+
"require": "./lib/api/index.js",
|
|
57
|
+
"default": "./lib-es/api/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./transaction": {
|
|
60
|
+
"require": "./lib/bridge/transaction.js",
|
|
61
|
+
"default": "./lib-es/bridge/transaction.js"
|
|
62
|
+
},
|
|
63
|
+
"./cli-transaction": {
|
|
64
|
+
"require": "./lib/test/cli-transaction.js",
|
|
65
|
+
"default": "./lib-es/test/cli-transaction.js"
|
|
66
|
+
},
|
|
67
|
+
"./hw-getAddress": {
|
|
68
|
+
"require": "./lib/signer/hw-getAddress.js",
|
|
69
|
+
"default": "./lib-es/signer/hw-getAddress.js"
|
|
70
|
+
},
|
|
71
|
+
"./preload": {
|
|
72
|
+
"require": "./lib/bridge/preload.js",
|
|
73
|
+
"default": "./lib-es/bridge/preload.js"
|
|
74
|
+
},
|
|
75
|
+
"./deviceTransactionConfig": {
|
|
76
|
+
"require": "./lib/bridge/deviceTransactionConfig.js",
|
|
77
|
+
"default": "./lib-es/bridge/deviceTransactionConfig.js"
|
|
78
|
+
},
|
|
79
|
+
"./types": {
|
|
80
|
+
"require": "./lib/types/index.js",
|
|
81
|
+
"default": "./lib-es/types/index.js"
|
|
82
|
+
},
|
|
83
|
+
"./bridge": {
|
|
84
|
+
"require": "./lib/bridge/index.js",
|
|
85
|
+
"default": "./lib-es/bridge/index.js"
|
|
86
|
+
},
|
|
87
|
+
"./signer": {
|
|
88
|
+
"require": "./lib/signer/index.js",
|
|
89
|
+
"default": "./lib-es/signer/index.js"
|
|
90
|
+
},
|
|
91
|
+
"./specs": {
|
|
92
|
+
"require": "./lib/test/bot-specs.js",
|
|
93
|
+
"default": "./lib-es/test/bot-specs.js"
|
|
94
|
+
},
|
|
95
|
+
"./*": {
|
|
96
|
+
"require": "./lib/*.js",
|
|
97
|
+
"default": "./lib-es/*.js"
|
|
98
|
+
},
|
|
99
|
+
".": {
|
|
100
|
+
"require": "./lib/index.js",
|
|
101
|
+
"default": "./lib-es/index.js"
|
|
102
|
+
},
|
|
103
|
+
"./package.json": "./package.json"
|
|
104
|
+
},
|
|
105
|
+
"license": "Apache-2.0",
|
|
106
|
+
"dependencies": {
|
|
107
|
+
"bignumber.js": "^9.1.2",
|
|
108
|
+
"invariant": "^2.2.4",
|
|
109
|
+
"eip55": "^2.1.1",
|
|
110
|
+
"lodash": "^4.17.21",
|
|
111
|
+
"rxjs": "^7.8.1",
|
|
112
|
+
"@celo/connect": "^6.0.2",
|
|
113
|
+
"@celo/contractkit": "^8.3.1",
|
|
114
|
+
"@celo/utils": "^7.0.0",
|
|
115
|
+
"@celo/wallet-base": "^6.0.3",
|
|
116
|
+
"@celo/wallet-ledger": "^6.0.3",
|
|
117
|
+
"@ledgerhq/coin-framework": "^3.0.1-next.0",
|
|
118
|
+
"@ledgerhq/coin-evm": "^2.19.0-next.0",
|
|
119
|
+
"@ledgerhq/cryptoassets": "^13.15.0",
|
|
120
|
+
"@ledgerhq/devices": "^8.4.4",
|
|
121
|
+
"@ledgerhq/errors": "^6.19.1",
|
|
122
|
+
"@ledgerhq/live-network": "^2.0.7",
|
|
123
|
+
"@ledgerhq/live-env": "^2.8.0",
|
|
124
|
+
"@ledgerhq/logs": "^6.12.0",
|
|
125
|
+
"@ledgerhq/types-live": "^6.68.0-next.0",
|
|
126
|
+
"@ledgerhq/hw-app-eth": "^6.45.2-next.0",
|
|
127
|
+
"@ledgerhq/live-config": "^3.1.0"
|
|
128
|
+
},
|
|
129
|
+
"devDependencies": {
|
|
130
|
+
"@types/lodash": "^4.14.179",
|
|
131
|
+
"@types/invariant": "^2.2.37",
|
|
132
|
+
"@types/jest": "^29.5.12",
|
|
133
|
+
"dotenv": "^16.4.5",
|
|
134
|
+
"expect": "^27.4.6",
|
|
135
|
+
"jest": "^29.7.0",
|
|
136
|
+
"ts-jest": "^29.1.1",
|
|
137
|
+
"typescript": "^5.4.5",
|
|
138
|
+
"@ledgerhq/types-cryptoassets": "^7.22.0"
|
|
139
|
+
},
|
|
140
|
+
"scripts": {
|
|
141
|
+
"clean": "rimraf lib lib-es",
|
|
142
|
+
"build": "tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es",
|
|
143
|
+
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-celo.json",
|
|
144
|
+
"prewatch": "pnpm build",
|
|
145
|
+
"watch": "tsc --watch",
|
|
146
|
+
"watch:es": "tsc --watch -m esnext --moduleResolution bundler --outDir lib-es",
|
|
147
|
+
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
148
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
149
|
+
"lint:fix": "pnpm lint --fix",
|
|
150
|
+
"test": "jest",
|
|
151
|
+
"test-integ": "jest --config=jest.integ.config.js",
|
|
152
|
+
"test-integ:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --config=jest.integ.config.js",
|
|
153
|
+
"typecheck": "tsc --noEmit",
|
|
154
|
+
"unimported": "unimported"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
3
|
+
import { Transaction } from "../types";
|
|
4
|
+
import { celoKit } from "../network/sdk";
|
|
5
|
+
|
|
6
|
+
export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
|
|
7
|
+
signedOperation: { operation, signature },
|
|
8
|
+
}) => {
|
|
9
|
+
const kit = celoKit();
|
|
10
|
+
const { transactionHash } = await kit.web3.eth.sendSignedTransaction(signature);
|
|
11
|
+
return patchOperationWithHash(operation, transactionHash);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default broadcast;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { OperationType } from "@ledgerhq/types-live";
|
|
3
|
+
import { CeloAccount, CeloOperation, CeloOperationMode, Transaction } from "../types";
|
|
4
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
5
|
+
|
|
6
|
+
const MODE_TO_TYPE: { [key in CeloOperationMode | "default"]: OperationType } = {
|
|
7
|
+
send: "OUT",
|
|
8
|
+
lock: "LOCK",
|
|
9
|
+
unlock: "UNLOCK",
|
|
10
|
+
withdraw: "WITHDRAW",
|
|
11
|
+
vote: "VOTE",
|
|
12
|
+
revoke: "REVOKE",
|
|
13
|
+
activate: "ACTIVATE",
|
|
14
|
+
register: "REGISTER",
|
|
15
|
+
default: "FEES",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const buildOptimisticOperation = (
|
|
19
|
+
account: CeloAccount,
|
|
20
|
+
transaction: Transaction,
|
|
21
|
+
fee: BigNumber,
|
|
22
|
+
): CeloOperation => {
|
|
23
|
+
const type = MODE_TO_TYPE[transaction.mode] ?? MODE_TO_TYPE.default;
|
|
24
|
+
|
|
25
|
+
const value =
|
|
26
|
+
type === "OUT" || type === "LOCK"
|
|
27
|
+
? new BigNumber(transaction.amount).plus(fee)
|
|
28
|
+
: new BigNumber(transaction.amount);
|
|
29
|
+
|
|
30
|
+
const operation: CeloOperation = {
|
|
31
|
+
id: encodeOperationId(account.id, "", type),
|
|
32
|
+
hash: "",
|
|
33
|
+
type,
|
|
34
|
+
value,
|
|
35
|
+
fee,
|
|
36
|
+
blockHash: null,
|
|
37
|
+
blockHeight: null,
|
|
38
|
+
senders: [account.freshAddress],
|
|
39
|
+
recipients: [transaction.recipient].filter(Boolean),
|
|
40
|
+
accountId: account.id,
|
|
41
|
+
date: new Date(),
|
|
42
|
+
extra: {
|
|
43
|
+
celoOperationValue: new BigNumber(transaction.amount),
|
|
44
|
+
...(["ACTIVATE", "VOTE", "REVOKE"].includes(type)
|
|
45
|
+
? {
|
|
46
|
+
celoSourceValidator: transaction.recipient,
|
|
47
|
+
}
|
|
48
|
+
: {}),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return operation;
|
|
53
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { CeloAccount, Transaction } from "../types";
|
|
2
|
+
import { CeloTx } from "@celo/connect";
|
|
3
|
+
import { celoKit } from "../network/sdk";
|
|
4
|
+
import { BigNumber } from "bignumber.js";
|
|
5
|
+
import { getPendingStakingOperationAmounts, getVote } from "../logic";
|
|
6
|
+
|
|
7
|
+
const buildTransaction = async (account: CeloAccount, transaction: Transaction) => {
|
|
8
|
+
const kit = celoKit();
|
|
9
|
+
|
|
10
|
+
const value = transactionValue(account, transaction);
|
|
11
|
+
|
|
12
|
+
let celoTransaction: CeloTx;
|
|
13
|
+
|
|
14
|
+
if (transaction.mode === "lock") {
|
|
15
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
16
|
+
celoTransaction = {
|
|
17
|
+
from: account.freshAddress,
|
|
18
|
+
value: value.toFixed(),
|
|
19
|
+
to: lockedGold.address,
|
|
20
|
+
data: lockedGold.lock().txo.encodeABI(),
|
|
21
|
+
gas: await lockedGold.lock().txo.estimateGas({
|
|
22
|
+
from: account.freshAddress,
|
|
23
|
+
value: value.toFixed(),
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
} else if (transaction.mode === "unlock") {
|
|
27
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
28
|
+
celoTransaction = {
|
|
29
|
+
from: account.freshAddress,
|
|
30
|
+
to: lockedGold.address,
|
|
31
|
+
data: lockedGold.unlock(value).txo.encodeABI(),
|
|
32
|
+
gas: await lockedGold.unlock(value).txo.estimateGas({
|
|
33
|
+
from: account.freshAddress,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
} else if (transaction.mode === "withdraw") {
|
|
37
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
38
|
+
|
|
39
|
+
celoTransaction = {
|
|
40
|
+
from: account.freshAddress,
|
|
41
|
+
to: lockedGold.address,
|
|
42
|
+
data: lockedGold.withdraw(transaction.index || 0).txo.encodeABI(),
|
|
43
|
+
gas: await lockedGold.withdraw(transaction.index || 0).txo.estimateGas({
|
|
44
|
+
from: account.freshAddress,
|
|
45
|
+
value: value.toFixed(),
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
} else if (transaction.mode === "vote") {
|
|
49
|
+
const election = await kit.contracts.getElection();
|
|
50
|
+
const vote = await election.vote(transaction.recipient, new BigNumber(value));
|
|
51
|
+
|
|
52
|
+
celoTransaction = {
|
|
53
|
+
from: account.freshAddress,
|
|
54
|
+
to: election.address,
|
|
55
|
+
data: vote.txo.encodeABI(),
|
|
56
|
+
gas: await vote.txo.estimateGas({ from: account.freshAddress }),
|
|
57
|
+
};
|
|
58
|
+
} else if (transaction.mode === "revoke") {
|
|
59
|
+
const election = await kit.contracts.getElection();
|
|
60
|
+
const accounts = await kit.contracts.getAccounts();
|
|
61
|
+
const voteSignerAccount = await accounts.voteSignerToAccount(account.freshAddress);
|
|
62
|
+
|
|
63
|
+
const revokes = await election.revoke(
|
|
64
|
+
voteSignerAccount,
|
|
65
|
+
transaction.recipient,
|
|
66
|
+
new BigNumber(value),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const revoke = revokes.find(transactionObject => {
|
|
70
|
+
return (
|
|
71
|
+
(transactionObject.txo as any)._method.name ===
|
|
72
|
+
(transaction.index === 0 ? "revokePending" : "revokeActive")
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
if (!revoke) throw new Error("No votes to revoke");
|
|
76
|
+
|
|
77
|
+
celoTransaction = {
|
|
78
|
+
from: account.freshAddress,
|
|
79
|
+
to: election.address,
|
|
80
|
+
data: revoke.txo.encodeABI(),
|
|
81
|
+
gas: await revoke.txo.estimateGas({ from: account.freshAddress }),
|
|
82
|
+
};
|
|
83
|
+
} else if (transaction.mode === "activate") {
|
|
84
|
+
const election = await kit.contracts.getElection();
|
|
85
|
+
const accounts = await kit.contracts.getAccounts();
|
|
86
|
+
const voteSignerAccount = await accounts.voteSignerToAccount(account.freshAddress);
|
|
87
|
+
|
|
88
|
+
const activates = await election.activate(voteSignerAccount);
|
|
89
|
+
const activate = activates.find(a => a.txo.arguments[0] === transaction.recipient);
|
|
90
|
+
if (!activate) throw new Error("No votes to activate");
|
|
91
|
+
|
|
92
|
+
celoTransaction = {
|
|
93
|
+
from: account.freshAddress,
|
|
94
|
+
to: election.address,
|
|
95
|
+
data: activate.txo.encodeABI(),
|
|
96
|
+
gas: await activate.txo.estimateGas({
|
|
97
|
+
from: account.freshAddress,
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
} else if (transaction.mode === "register") {
|
|
101
|
+
const accounts = await kit.contracts.getAccounts();
|
|
102
|
+
celoTransaction = {
|
|
103
|
+
from: account.freshAddress,
|
|
104
|
+
to: accounts.address,
|
|
105
|
+
data: accounts.createAccount().txo.encodeABI(),
|
|
106
|
+
gas: await accounts.createAccount().txo.estimateGas({ from: account.freshAddress }),
|
|
107
|
+
};
|
|
108
|
+
} else {
|
|
109
|
+
// Send
|
|
110
|
+
|
|
111
|
+
celoTransaction = {
|
|
112
|
+
from: account.freshAddress,
|
|
113
|
+
to: transaction.recipient,
|
|
114
|
+
value: value.toFixed(),
|
|
115
|
+
};
|
|
116
|
+
const gas = await kit.connection.estimateGasWithInflationFactor(celoTransaction);
|
|
117
|
+
|
|
118
|
+
celoTransaction = {
|
|
119
|
+
...celoTransaction,
|
|
120
|
+
gas,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const tx: CeloTx = {
|
|
124
|
+
...celoTransaction,
|
|
125
|
+
chainId: await kit.connection.chainId(),
|
|
126
|
+
nonce: await kit.connection.nonce(account.freshAddress),
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return tx;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const transactionValue = (account: CeloAccount, transaction: Transaction): BigNumber => {
|
|
133
|
+
let value = transaction.amount;
|
|
134
|
+
|
|
135
|
+
if (transaction.useAllAmount) {
|
|
136
|
+
if ((transaction.mode === "unlock" || transaction.mode === "vote") && account.celoResources) {
|
|
137
|
+
// Deduct the amount of pending vote transactions from
|
|
138
|
+
// the total non-voting locked balance to get the true non-voting locked balance.
|
|
139
|
+
const pendingOperationAmounts = getPendingStakingOperationAmounts(account);
|
|
140
|
+
const pendingOperationAmount =
|
|
141
|
+
transaction.mode === "vote" ? pendingOperationAmounts.vote : new BigNumber(0);
|
|
142
|
+
value = account.celoResources.nonvotingLockedBalance.minus(pendingOperationAmount);
|
|
143
|
+
} else if (transaction.mode === "revoke" && account.celoResources) {
|
|
144
|
+
const revoke = getVote(account, transaction.recipient, transaction.index);
|
|
145
|
+
if (revoke?.amount) value = revoke.amount;
|
|
146
|
+
} else {
|
|
147
|
+
value = account.spendableBalance.minus(transaction.fees || 0);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return value;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export default buildTransaction;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { Transaction } from "../types";
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
|
|
5
|
+
export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => ({
|
|
6
|
+
family: "celo",
|
|
7
|
+
amount: new BigNumber(0),
|
|
8
|
+
recipient: "",
|
|
9
|
+
useAllAmount: false,
|
|
10
|
+
fees: null,
|
|
11
|
+
mode: "send",
|
|
12
|
+
index: null,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export default createTransaction;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
2
|
+
|
|
3
|
+
function getDeviceTransactionConfig(): Array<DeviceTransactionField> {
|
|
4
|
+
const fields: Array<DeviceTransactionField> = [];
|
|
5
|
+
|
|
6
|
+
fields.push({
|
|
7
|
+
type: "amount",
|
|
8
|
+
label: "Amount",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
fields.push({
|
|
12
|
+
type: "fees",
|
|
13
|
+
label: "Fees",
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return fields;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default getDeviceTransactionConfig;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { CeloAccount, Transaction } from "../types";
|
|
3
|
+
import getTransactionStatus from "./getTransactionStatus";
|
|
4
|
+
import prepareTransaction from "./prepareTransaction";
|
|
5
|
+
import createTransaction from "./createTransaction";
|
|
6
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/helpers";
|
|
7
|
+
|
|
8
|
+
export const estimateMaxSpendable: AccountBridge<
|
|
9
|
+
Transaction,
|
|
10
|
+
CeloAccount
|
|
11
|
+
>["estimateMaxSpendable"] = async ({ account, parentAccount, transaction }) => {
|
|
12
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
13
|
+
const t = await prepareTransaction(mainAccount, {
|
|
14
|
+
...createTransaction(account),
|
|
15
|
+
...transaction,
|
|
16
|
+
useAllAmount: true,
|
|
17
|
+
});
|
|
18
|
+
const { amount } = await getTransactionStatus(mainAccount, t);
|
|
19
|
+
return amount;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default estimateMaxSpendable;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { CeloAccount, Transaction } from "../types";
|
|
3
|
+
import { celoKit } from "../network/sdk";
|
|
4
|
+
import { getPendingStakingOperationAmounts, getVote } from "../logic";
|
|
5
|
+
|
|
6
|
+
const getFeesForTransaction = async ({
|
|
7
|
+
account,
|
|
8
|
+
transaction,
|
|
9
|
+
}: {
|
|
10
|
+
account: CeloAccount;
|
|
11
|
+
transaction: Transaction;
|
|
12
|
+
}): Promise<BigNumber> => {
|
|
13
|
+
const { amount, index } = transaction;
|
|
14
|
+
const kit = celoKit();
|
|
15
|
+
|
|
16
|
+
// A workaround - estimating gas throws an error if value > funds
|
|
17
|
+
let value: BigNumber = new BigNumber(0);
|
|
18
|
+
|
|
19
|
+
const pendingOperationAmounts = getPendingStakingOperationAmounts(account);
|
|
20
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
21
|
+
const nonvotingLockedGoldBalance = await lockedGold.getAccountNonvotingLockedGold(
|
|
22
|
+
account.freshAddress,
|
|
23
|
+
);
|
|
24
|
+
// Deduct pending vote operations from the non-voting locked balance
|
|
25
|
+
const totalNonVotingLockedBalance = nonvotingLockedGoldBalance.minus(
|
|
26
|
+
pendingOperationAmounts.vote,
|
|
27
|
+
);
|
|
28
|
+
// Deduct pending lock operations from the spendable balance
|
|
29
|
+
const totalSpendableBalance = account.spendableBalance.minus(pendingOperationAmounts.lock);
|
|
30
|
+
|
|
31
|
+
if ((transaction.mode === "unlock" || transaction.mode === "vote") && account.celoResources) {
|
|
32
|
+
value = transaction.useAllAmount
|
|
33
|
+
? totalNonVotingLockedBalance
|
|
34
|
+
: BigNumber.minimum(amount, totalNonVotingLockedBalance);
|
|
35
|
+
} else if (transaction.mode === "revoke" && account.celoResources) {
|
|
36
|
+
const vote = getVote(account, transaction.recipient, transaction.index);
|
|
37
|
+
if (vote) {
|
|
38
|
+
value = transaction.useAllAmount ? vote.amount : BigNumber.minimum(amount, vote.amount);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
value = transaction.useAllAmount
|
|
42
|
+
? totalSpendableBalance
|
|
43
|
+
: BigNumber.minimum(amount, totalSpendableBalance);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let gas: number | null = null;
|
|
47
|
+
if (transaction.mode === "lock") {
|
|
48
|
+
gas = await lockedGold
|
|
49
|
+
.lock()
|
|
50
|
+
.txo.estimateGas({ from: account.freshAddress, value: value.toFixed() });
|
|
51
|
+
} else if (transaction.mode === "unlock") {
|
|
52
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
53
|
+
|
|
54
|
+
gas = await lockedGold.unlock(value).txo.estimateGas({ from: account.freshAddress });
|
|
55
|
+
} else if (transaction.mode === "withdraw") {
|
|
56
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
57
|
+
|
|
58
|
+
gas = await lockedGold.withdraw(index || 0).txo.estimateGas({ from: account.freshAddress });
|
|
59
|
+
} else if (transaction.mode === "vote") {
|
|
60
|
+
const election = await kit.contracts.getElection();
|
|
61
|
+
|
|
62
|
+
const vote = await election.vote(transaction.recipient, new BigNumber(value));
|
|
63
|
+
|
|
64
|
+
gas = await vote.txo.estimateGas({ from: account.freshAddress });
|
|
65
|
+
} else if (transaction.mode === "revoke") {
|
|
66
|
+
const election = await kit.contracts.getElection();
|
|
67
|
+
const accounts = await kit.contracts.getAccounts();
|
|
68
|
+
const voteSignerAccount = await accounts.voteSignerToAccount(account.freshAddress);
|
|
69
|
+
const revokeTxs = await election.revoke(
|
|
70
|
+
voteSignerAccount,
|
|
71
|
+
transaction.recipient,
|
|
72
|
+
new BigNumber(value),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const revokeTx = revokeTxs.find(transactionObject => {
|
|
76
|
+
return (
|
|
77
|
+
(transactionObject.txo as any)._method.name ===
|
|
78
|
+
(transaction.index === 0 ? "revokePending" : "revokeActive")
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
if (!revokeTx) return new BigNumber(0);
|
|
82
|
+
|
|
83
|
+
gas = await revokeTx.txo.estimateGas({ from: account.freshAddress });
|
|
84
|
+
} else if (transaction.mode === "activate") {
|
|
85
|
+
const election = await kit.contracts.getElection();
|
|
86
|
+
const accounts = await kit.contracts.getAccounts();
|
|
87
|
+
const voteSignerAccount = await accounts.voteSignerToAccount(account.freshAddress);
|
|
88
|
+
|
|
89
|
+
const activates = await election.activate(voteSignerAccount);
|
|
90
|
+
|
|
91
|
+
const activate = activates.find(a => a.txo.arguments[0] === transaction.recipient);
|
|
92
|
+
if (!activate) return new BigNumber(0);
|
|
93
|
+
|
|
94
|
+
gas = await activate.txo.estimateGas({ from: account.freshAddress });
|
|
95
|
+
} else if (transaction.mode === "register") {
|
|
96
|
+
const accounts = await kit.contracts.getAccounts();
|
|
97
|
+
|
|
98
|
+
gas = await accounts.createAccount().txo.estimateGas({ from: account.freshAddress });
|
|
99
|
+
} else {
|
|
100
|
+
const celoToken = await kit.contracts.getGoldToken();
|
|
101
|
+
|
|
102
|
+
const celoTransaction = {
|
|
103
|
+
from: account.freshAddress,
|
|
104
|
+
to: celoToken.address,
|
|
105
|
+
data: celoToken.transfer(transaction.recipient, value.toFixed()).txo.encodeABI(),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
gas = await kit.connection.estimateGasWithInflationFactor(celoTransaction);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const gasPrice = new BigNumber(await kit.connection.gasPrice());
|
|
112
|
+
return gasPrice.times(gas);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export default getFeesForTransaction;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AmountRequired,
|
|
3
|
+
FeeNotLoaded,
|
|
4
|
+
InvalidAddress,
|
|
5
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
6
|
+
NotEnoughBalance,
|
|
7
|
+
RecipientRequired,
|
|
8
|
+
} from "@ledgerhq/errors";
|
|
9
|
+
import { BigNumber } from "bignumber.js";
|
|
10
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
11
|
+
import { isValidAddress } from "@celo/utils/lib/address";
|
|
12
|
+
import { getPendingStakingOperationAmounts, getVote } from "../logic";
|
|
13
|
+
import { CeloAccount, Transaction, TransactionStatus } from "../types";
|
|
14
|
+
import { CeloAllFundsWarning } from "../errors";
|
|
15
|
+
import { celoKit } from "../network/sdk";
|
|
16
|
+
|
|
17
|
+
const kit = celoKit();
|
|
18
|
+
|
|
19
|
+
// Arbitrary buffer for paying fees of next transactions. 0.05 Celo for ~100 transactions
|
|
20
|
+
const FEES_SAFETY_BUFFER = new BigNumber(5000000000000000);
|
|
21
|
+
|
|
22
|
+
export const getTransactionStatus: AccountBridge<
|
|
23
|
+
Transaction,
|
|
24
|
+
CeloAccount,
|
|
25
|
+
TransactionStatus
|
|
26
|
+
>["getTransactionStatus"] = async (account, transaction) => {
|
|
27
|
+
const errors: Record<string, Error> = {};
|
|
28
|
+
const warnings: Record<string, Error> = {};
|
|
29
|
+
const useAllAmount = !!transaction.useAllAmount;
|
|
30
|
+
|
|
31
|
+
if (account.freshAddress === transaction.recipient) {
|
|
32
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!transaction.fees || !transaction.fees.gt(0)) {
|
|
36
|
+
errors.fees = new FeeNotLoaded();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const pendingOperationAmounts = getPendingStakingOperationAmounts(account);
|
|
40
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
41
|
+
const nonvotingLockedGoldBalance = await lockedGold.getAccountNonvotingLockedGold(
|
|
42
|
+
account.freshAddress,
|
|
43
|
+
);
|
|
44
|
+
// Deduct pending vote operations from the non-voting locked balance
|
|
45
|
+
const totalNonVotingLockedBalance = nonvotingLockedGoldBalance.minus(
|
|
46
|
+
pendingOperationAmounts.vote,
|
|
47
|
+
);
|
|
48
|
+
// Deduct pending lock operations from the spendable balance
|
|
49
|
+
const totalSpendableBalance = account.spendableBalance.minus(pendingOperationAmounts.lock);
|
|
50
|
+
const estimatedFees = transaction.fees || new BigNumber(0);
|
|
51
|
+
|
|
52
|
+
let amount: BigNumber = new BigNumber(0);
|
|
53
|
+
if (useAllAmount && (transaction.mode === "unlock" || transaction.mode === "vote")) {
|
|
54
|
+
amount = totalNonVotingLockedBalance ?? new BigNumber(0);
|
|
55
|
+
} else if (useAllAmount && transaction.mode === "revoke") {
|
|
56
|
+
const revoke = getVote(account, transaction.recipient, transaction.index);
|
|
57
|
+
if (revoke?.amount) amount = revoke.amount;
|
|
58
|
+
} else if (useAllAmount) {
|
|
59
|
+
amount = totalSpendableBalance.minus(estimatedFees);
|
|
60
|
+
} else {
|
|
61
|
+
amount = new BigNumber(transaction.amount);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (amount.lt(0)) amount = new BigNumber(0);
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
(account.celoResources?.lockedBalance.gt(0) ||
|
|
68
|
+
!!account.celoResources?.pendingWithdrawals?.length) &&
|
|
69
|
+
(transaction.useAllAmount || totalSpendableBalance.minus(amount).lt(FEES_SAFETY_BUFFER)) &&
|
|
70
|
+
["send", "lock"].includes(transaction.mode)
|
|
71
|
+
) {
|
|
72
|
+
warnings.amount = new CeloAllFundsWarning();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!["register", "withdraw", "activate"].includes(transaction.mode)) {
|
|
76
|
+
if (!errors.amount && amount.lte(0) && !useAllAmount) {
|
|
77
|
+
errors.amount = new AmountRequired();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const totalSpent = amount.plus(estimatedFees);
|
|
82
|
+
|
|
83
|
+
if (transaction.mode === "unlock" || transaction.mode === "vote") {
|
|
84
|
+
if (!errors.amount && totalNonVotingLockedBalance && amount.gt(totalNonVotingLockedBalance)) {
|
|
85
|
+
errors.amount = new NotEnoughBalance();
|
|
86
|
+
}
|
|
87
|
+
} else if (transaction.mode === "revoke") {
|
|
88
|
+
const revoke = getVote(account, transaction.recipient, transaction.index);
|
|
89
|
+
if (!errors.amount && revoke?.amount && amount.gt(revoke.amount))
|
|
90
|
+
errors.amount = new NotEnoughBalance();
|
|
91
|
+
} else {
|
|
92
|
+
if (!errors.amount && totalSpent.gt(totalSpendableBalance)) {
|
|
93
|
+
errors.amount = new NotEnoughBalance();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!errors.amount && totalSpendableBalance.lt(estimatedFees)) {
|
|
98
|
+
errors.amount = new NotEnoughBalance();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (transaction.mode === "send") {
|
|
102
|
+
if (!transaction.recipient) {
|
|
103
|
+
errors.recipient = new RecipientRequired();
|
|
104
|
+
} else if (!isValidAddress(transaction.recipient)) {
|
|
105
|
+
errors.recipient = new InvalidAddress("", {
|
|
106
|
+
currencyName: account.currency.name,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
errors,
|
|
113
|
+
warnings,
|
|
114
|
+
estimatedFees,
|
|
115
|
+
amount,
|
|
116
|
+
totalSpent,
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default getTransactionStatus;
|