@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
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import {
|
|
3
|
+
AmountRequired,
|
|
4
|
+
InvalidAddress,
|
|
5
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
6
|
+
NotEnoughBalance,
|
|
7
|
+
} from "@ledgerhq/errors";
|
|
8
|
+
import TransactionModule from "../bridge/transaction";
|
|
9
|
+
import { CeloAllFundsWarning } from "../errors";
|
|
10
|
+
import type { AccountRaw, CurrenciesData, TransactionStatusCommon } from "@ledgerhq/types-live";
|
|
11
|
+
import type { Transaction } from "../types/types";
|
|
12
|
+
|
|
13
|
+
// This account is registered for staking and has available funds, locked voting funds,
|
|
14
|
+
// locked non-voting funds, and withdrawable funds.
|
|
15
|
+
const LEDGER_CELO_ACCOUNT_1 = "0xcfD48e0FAf9f19377509cE68a6A6F4D9C85ff8AB";
|
|
16
|
+
// This account has no funds and isn't registered for staking.
|
|
17
|
+
const LEDGER_CELO_ACCOUNT_2 = "0x2cC7E5913bADa8FA2895bDeF7F4C2E36C2368Abb";
|
|
18
|
+
const VALIDATOR_ACCOUNT_1 = "0x0861a61Bf679A30680510EcC238ee43B82C5e843";
|
|
19
|
+
|
|
20
|
+
const dataset: CurrenciesData<Transaction> = {
|
|
21
|
+
scanAccounts: [
|
|
22
|
+
{
|
|
23
|
+
name: "Celo 1",
|
|
24
|
+
apdus: `
|
|
25
|
+
=> e00200000d038000002c8000ce1080000000
|
|
26
|
+
<= 410453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a328383735443736394535333337363338363732386136374632463564326435666561374637356233399000
|
|
27
|
+
=> e002000015058000002c8000ce10800000000000000000000000
|
|
28
|
+
<= 4104eedca4417737f2dae0e12320edba0e845e4ced411e6e2978a9165dde3891099402ff4906ecaab03232f8273592287a94866f14f17b5e2bf6e31837278127919c28636644343865304641663966313933373735303963453638613641364634443943383566663841429000
|
|
29
|
+
=> e002000015058000002c8000ce10800000010000000000000000
|
|
30
|
+
<= 41042304dfd28a236eb03471986b90f0a3a111537b35766ae8ff78a9f588071f56ec127531a2498b36e856c759bc2734297a07f9f4b331153a8c9c21171f6488884e28326343374535393133624144613846413238393562446546374634433245333643323336384162629000
|
|
31
|
+
`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
accounts: [
|
|
35
|
+
{
|
|
36
|
+
// Ignoring the "balance is sum of ops" test since that
|
|
37
|
+
// doesn't seem to take into account staked tokens properly.
|
|
38
|
+
FIXME_tests: ["balance is sum of ops"],
|
|
39
|
+
raw: {
|
|
40
|
+
id: `js:2:celo:${LEDGER_CELO_ACCOUNT_1}:`,
|
|
41
|
+
seedIdentifier:
|
|
42
|
+
"0453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a3",
|
|
43
|
+
name: "Celo 1",
|
|
44
|
+
derivationMode: "",
|
|
45
|
+
index: 0,
|
|
46
|
+
freshAddress: LEDGER_CELO_ACCOUNT_1,
|
|
47
|
+
freshAddressPath: "44'/52752'/0'/0/0",
|
|
48
|
+
blockHeight: 0,
|
|
49
|
+
operations: [],
|
|
50
|
+
pendingOperations: [],
|
|
51
|
+
currencyId: "celo",
|
|
52
|
+
lastSyncDate: "",
|
|
53
|
+
balance: "399893159500000000",
|
|
54
|
+
celoResources: {
|
|
55
|
+
registrationStatus: true,
|
|
56
|
+
lockedBalance: "1000000",
|
|
57
|
+
nonvotingLockedBalance: "900000",
|
|
58
|
+
pendingWithdrawals: [],
|
|
59
|
+
votes: [
|
|
60
|
+
{
|
|
61
|
+
validatorGroup: VALIDATOR_ACCOUNT_1,
|
|
62
|
+
amount: "100000",
|
|
63
|
+
activatable: true,
|
|
64
|
+
revokable: true,
|
|
65
|
+
type: "active",
|
|
66
|
+
index: 0,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
electionAddress: "0x8D6677192144292870907E3Fa8A5527fE55A7ff6",
|
|
70
|
+
lockedGoldAddress: "0x6cC083Aed9e3ebe302A6336dBC7c921C9f03349E",
|
|
71
|
+
},
|
|
72
|
+
} as AccountRaw,
|
|
73
|
+
transactions: [
|
|
74
|
+
{
|
|
75
|
+
name: "Same as Recipient",
|
|
76
|
+
transaction: t => ({
|
|
77
|
+
...t,
|
|
78
|
+
amount: new BigNumber(100),
|
|
79
|
+
recipient: LEDGER_CELO_ACCOUNT_1,
|
|
80
|
+
}),
|
|
81
|
+
expectedStatus: {
|
|
82
|
+
errors: {
|
|
83
|
+
recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
|
|
84
|
+
},
|
|
85
|
+
warnings: {},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "Invalid Address",
|
|
90
|
+
transaction: t => ({
|
|
91
|
+
...t,
|
|
92
|
+
amount: new BigNumber(100),
|
|
93
|
+
recipient: "dsadasdasdasdas",
|
|
94
|
+
}),
|
|
95
|
+
expectedStatus: {
|
|
96
|
+
errors: {
|
|
97
|
+
recipient: new InvalidAddress(),
|
|
98
|
+
},
|
|
99
|
+
warnings: {},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "Amount Required",
|
|
104
|
+
transaction: TransactionModule.fromTransactionRaw({
|
|
105
|
+
family: "celo",
|
|
106
|
+
recipient: LEDGER_CELO_ACCOUNT_2,
|
|
107
|
+
amount: "0",
|
|
108
|
+
mode: "send",
|
|
109
|
+
fees: null,
|
|
110
|
+
index: 0,
|
|
111
|
+
}),
|
|
112
|
+
expectedStatus: {
|
|
113
|
+
errors: {
|
|
114
|
+
amount: new AmountRequired(),
|
|
115
|
+
},
|
|
116
|
+
warnings: {},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "Not enough balance",
|
|
121
|
+
transaction: TransactionModule.fromTransactionRaw({
|
|
122
|
+
family: "celo",
|
|
123
|
+
recipient: LEDGER_CELO_ACCOUNT_2,
|
|
124
|
+
amount: "399893159500000005",
|
|
125
|
+
mode: "send",
|
|
126
|
+
fees: null,
|
|
127
|
+
index: 0,
|
|
128
|
+
}),
|
|
129
|
+
expectedStatus: {
|
|
130
|
+
errors: {
|
|
131
|
+
amount: new NotEnoughBalance(),
|
|
132
|
+
},
|
|
133
|
+
warnings: {},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "[send] use all amount - should warn all funds",
|
|
138
|
+
transaction: t => ({
|
|
139
|
+
...t,
|
|
140
|
+
useAllAmount: true,
|
|
141
|
+
mode: "send",
|
|
142
|
+
recipient: LEDGER_CELO_ACCOUNT_2,
|
|
143
|
+
}),
|
|
144
|
+
expectedStatus: () => ({
|
|
145
|
+
errors: {},
|
|
146
|
+
warnings: {
|
|
147
|
+
amount: new CeloAllFundsWarning(),
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "Lock - success",
|
|
153
|
+
transaction: t => ({
|
|
154
|
+
...t,
|
|
155
|
+
mode: "lock",
|
|
156
|
+
amount: new BigNumber(5000),
|
|
157
|
+
}),
|
|
158
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
159
|
+
return {
|
|
160
|
+
errors: {},
|
|
161
|
+
warnings: {},
|
|
162
|
+
amount: new BigNumber(5000),
|
|
163
|
+
};
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "Unlock - success",
|
|
168
|
+
transaction: t => ({
|
|
169
|
+
...t,
|
|
170
|
+
mode: "unlock",
|
|
171
|
+
amount: new BigNumber(50000),
|
|
172
|
+
}),
|
|
173
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
174
|
+
return {
|
|
175
|
+
errors: {},
|
|
176
|
+
warnings: {},
|
|
177
|
+
amount: new BigNumber(50000),
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: "Lock - amount required",
|
|
183
|
+
transaction: t => ({
|
|
184
|
+
...t,
|
|
185
|
+
mode: "lock",
|
|
186
|
+
}),
|
|
187
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
188
|
+
return {
|
|
189
|
+
errors: {
|
|
190
|
+
amount: new AmountRequired(),
|
|
191
|
+
},
|
|
192
|
+
warnings: {},
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "Unlock - amount required",
|
|
198
|
+
transaction: t => ({
|
|
199
|
+
...t,
|
|
200
|
+
mode: "unlock",
|
|
201
|
+
}),
|
|
202
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
203
|
+
return {
|
|
204
|
+
errors: {
|
|
205
|
+
amount: new AmountRequired(),
|
|
206
|
+
},
|
|
207
|
+
warnings: {},
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "Unlock - Not enough balance",
|
|
213
|
+
transaction: t => ({
|
|
214
|
+
...t,
|
|
215
|
+
mode: "unlock",
|
|
216
|
+
amount: new BigNumber(200000000000000000),
|
|
217
|
+
}),
|
|
218
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
219
|
+
return {
|
|
220
|
+
errors: {
|
|
221
|
+
amount: new NotEnoughBalance(),
|
|
222
|
+
},
|
|
223
|
+
warnings: {},
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "Vote - success",
|
|
229
|
+
transaction: t => ({
|
|
230
|
+
...t,
|
|
231
|
+
mode: "vote",
|
|
232
|
+
useAllAmount: true,
|
|
233
|
+
recipient: VALIDATOR_ACCOUNT_1,
|
|
234
|
+
}),
|
|
235
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
236
|
+
return {
|
|
237
|
+
errors: {},
|
|
238
|
+
warnings: {},
|
|
239
|
+
amount: new BigNumber(100000000000000000),
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: "Vote - Not enough balance",
|
|
245
|
+
transaction: t => ({
|
|
246
|
+
...t,
|
|
247
|
+
mode: "vote",
|
|
248
|
+
recipient: VALIDATOR_ACCOUNT_1,
|
|
249
|
+
amount: new BigNumber(200000000000000000),
|
|
250
|
+
}),
|
|
251
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
252
|
+
return {
|
|
253
|
+
errors: {
|
|
254
|
+
amount: new NotEnoughBalance(),
|
|
255
|
+
},
|
|
256
|
+
warnings: {},
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: "Activate Vote - success",
|
|
262
|
+
transaction: t => ({
|
|
263
|
+
...t,
|
|
264
|
+
mode: "activate",
|
|
265
|
+
recipient: VALIDATOR_ACCOUNT_1,
|
|
266
|
+
}),
|
|
267
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
268
|
+
return {
|
|
269
|
+
errors: {},
|
|
270
|
+
warnings: {},
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: "Revoke Vote - success",
|
|
276
|
+
transaction: t => ({
|
|
277
|
+
...t,
|
|
278
|
+
mode: "revoke",
|
|
279
|
+
recipient: VALIDATOR_ACCOUNT_1,
|
|
280
|
+
amount: new BigNumber(9000000),
|
|
281
|
+
index: 0,
|
|
282
|
+
}),
|
|
283
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
284
|
+
return {
|
|
285
|
+
errors: {},
|
|
286
|
+
warnings: {},
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: "Revoke Vote - Not enough balance",
|
|
292
|
+
transaction: t => ({
|
|
293
|
+
...t,
|
|
294
|
+
mode: "revoke",
|
|
295
|
+
recipient: VALIDATOR_ACCOUNT_1,
|
|
296
|
+
amount: new BigNumber(20000000000000000000),
|
|
297
|
+
index: 0,
|
|
298
|
+
}),
|
|
299
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
300
|
+
return {
|
|
301
|
+
errors: {
|
|
302
|
+
amount: new NotEnoughBalance(),
|
|
303
|
+
},
|
|
304
|
+
warnings: {},
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: "Revoke Vote - voted amount should be used when revoke amount is set",
|
|
310
|
+
transaction: t => ({
|
|
311
|
+
...t,
|
|
312
|
+
mode: "revoke",
|
|
313
|
+
recipient: VALIDATOR_ACCOUNT_1,
|
|
314
|
+
useAllAmount: true,
|
|
315
|
+
index: 0,
|
|
316
|
+
}),
|
|
317
|
+
expectedStatus: (): Partial<TransactionStatusCommon> => {
|
|
318
|
+
return {
|
|
319
|
+
errors: {},
|
|
320
|
+
warnings: {},
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
FIXME_tests: ["balance is sum of ops"],
|
|
328
|
+
raw: {
|
|
329
|
+
id: `js:2:celo:${LEDGER_CELO_ACCOUNT_2}:`,
|
|
330
|
+
seedIdentifier:
|
|
331
|
+
"0453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a3",
|
|
332
|
+
name: "Celo 1",
|
|
333
|
+
derivationMode: "",
|
|
334
|
+
index: 0,
|
|
335
|
+
freshAddress: LEDGER_CELO_ACCOUNT_2,
|
|
336
|
+
freshAddressPath: "44'/52752'/0'/0/0",
|
|
337
|
+
blockHeight: 0,
|
|
338
|
+
operations: [],
|
|
339
|
+
pendingOperations: [],
|
|
340
|
+
currencyId: "celo",
|
|
341
|
+
lastSyncDate: "",
|
|
342
|
+
balance: "399893159500000000",
|
|
343
|
+
celoResources: {
|
|
344
|
+
registrationStatus: false,
|
|
345
|
+
lockedBalance: "0",
|
|
346
|
+
nonvotingLockedBalance: "0",
|
|
347
|
+
pendingWithdrawals: [],
|
|
348
|
+
votes: [],
|
|
349
|
+
electionAddress: "0x8D6677192144292870907E3Fa8A5527fE55A7ff6",
|
|
350
|
+
lockedGoldAddress: "0x6cC083Aed9e3ebe302A6336dBC7c921C9f03349E",
|
|
351
|
+
},
|
|
352
|
+
} as AccountRaw,
|
|
353
|
+
transactions: [
|
|
354
|
+
{
|
|
355
|
+
name: "Register Account - success",
|
|
356
|
+
transaction: t => ({
|
|
357
|
+
...t,
|
|
358
|
+
mode: "register",
|
|
359
|
+
}),
|
|
360
|
+
expectedStatus: {
|
|
361
|
+
errors: {},
|
|
362
|
+
warnings: {},
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
export default dataset;
|
package/src/errors.ts
ADDED
package/src/logic.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CeloAccount,
|
|
3
|
+
CeloPendingWithdrawal,
|
|
4
|
+
CeloValidatorGroup,
|
|
5
|
+
CeloVote,
|
|
6
|
+
CeloVoteStatus,
|
|
7
|
+
PendingStakingOperationAmounts,
|
|
8
|
+
} from "./types/types";
|
|
9
|
+
import { BigNumber } from "bignumber.js";
|
|
10
|
+
import { Operation } from "@ledgerhq/types-live";
|
|
11
|
+
|
|
12
|
+
export const PRELOAD_MAX_AGE = 10 * 60 * 1000; // 10 minutes, used for max age in preload strategy
|
|
13
|
+
const LEDGER_BY_FIGMENT_VALIDATOR_GROUP_ADDRESS = "0x0861a61Bf679A30680510EcC238ee43B82C5e843";
|
|
14
|
+
|
|
15
|
+
export const availablePendingWithdrawals = (account: CeloAccount): CeloPendingWithdrawal[] => {
|
|
16
|
+
const { pendingWithdrawals } = account.celoResources || {};
|
|
17
|
+
|
|
18
|
+
return (pendingWithdrawals || []).filter(
|
|
19
|
+
withdrawal => new Date(withdrawal.time.toNumber() * 1000) < new Date(),
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const withdrawableBalance = (account: CeloAccount): BigNumber =>
|
|
24
|
+
availablePendingWithdrawals(account).reduce(
|
|
25
|
+
(sum, withdrawal) => sum.plus(withdrawal.value),
|
|
26
|
+
new BigNumber(0),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const hasWithdrawableBalance = (account: CeloAccount): boolean =>
|
|
30
|
+
withdrawableBalance(account).isGreaterThan(0);
|
|
31
|
+
|
|
32
|
+
export const defaultValidatorGroupAddress = (): string => LEDGER_BY_FIGMENT_VALIDATOR_GROUP_ADDRESS;
|
|
33
|
+
|
|
34
|
+
export const isDefaultValidatorGroupAddress = (address: string): boolean =>
|
|
35
|
+
address === LEDGER_BY_FIGMENT_VALIDATOR_GROUP_ADDRESS;
|
|
36
|
+
|
|
37
|
+
export const isDefaultValidatorGroup = (validatorGroup: CeloValidatorGroup): boolean =>
|
|
38
|
+
isDefaultValidatorGroupAddress(validatorGroup.address);
|
|
39
|
+
|
|
40
|
+
export const activatableVotes = (account: CeloAccount): CeloVote[] => {
|
|
41
|
+
const { votes } = account.celoResources || {};
|
|
42
|
+
|
|
43
|
+
return (votes || []).filter(vote => vote.activatable);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const hasActivatableVotes = (account: CeloAccount): boolean =>
|
|
47
|
+
activatableVotes(account).length > 0;
|
|
48
|
+
|
|
49
|
+
export const revokableVotes = (account: CeloAccount): CeloVote[] => {
|
|
50
|
+
const { votes } = account.celoResources || {};
|
|
51
|
+
|
|
52
|
+
return (votes || []).filter(vote => vote.revokable);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const hasRevokableVotes = (account: CeloAccount): boolean =>
|
|
56
|
+
revokableVotes(account).length > 0;
|
|
57
|
+
|
|
58
|
+
export const getVote = (
|
|
59
|
+
account: CeloAccount,
|
|
60
|
+
validatorGroupAddress: string,
|
|
61
|
+
index: number | null | undefined,
|
|
62
|
+
): CeloVote | undefined => {
|
|
63
|
+
const { votes } = account.celoResources || {};
|
|
64
|
+
return votes?.find(
|
|
65
|
+
revoke => revoke.validatorGroup === validatorGroupAddress && revoke.index == index,
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const voteStatus = (vote: CeloVote): CeloVoteStatus =>
|
|
70
|
+
vote.type === "pending" && vote.activatable ? "awaitingActivation" : vote.type;
|
|
71
|
+
|
|
72
|
+
export const fallbackValidatorGroup = (address: string): CeloValidatorGroup => ({
|
|
73
|
+
address: address,
|
|
74
|
+
name: address,
|
|
75
|
+
votes: new BigNumber(0),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const isAccountRegistrationPending = (account: CeloAccount): boolean => {
|
|
79
|
+
// If there's a pending "REGISTER" operation and the
|
|
80
|
+
// account's registration status is false, then
|
|
81
|
+
// we know that the account is truly not registered yet.
|
|
82
|
+
|
|
83
|
+
const isAccountRegistrationPending =
|
|
84
|
+
!!account &&
|
|
85
|
+
account.pendingOperations.some(currentAccount => currentAccount.type === "REGISTER") &&
|
|
86
|
+
!account.celoResources?.registrationStatus;
|
|
87
|
+
|
|
88
|
+
return isAccountRegistrationPending;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const isOperationTrulyPending = (operation: Operation, activeOperations: Operation[]): boolean => {
|
|
92
|
+
return !activeOperations.some(activeOperation => activeOperation.hash === operation.hash);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const getPendingStakingOperationAmounts = (
|
|
96
|
+
account: CeloAccount,
|
|
97
|
+
): PendingStakingOperationAmounts => {
|
|
98
|
+
const operationAmounts = account.pendingOperations.reduce(
|
|
99
|
+
(acc, currentOperation) => {
|
|
100
|
+
if (currentOperation.type !== "VOTE" && currentOperation.type !== "LOCK") {
|
|
101
|
+
return acc;
|
|
102
|
+
}
|
|
103
|
+
if (isOperationTrulyPending(currentOperation, account.operations)) {
|
|
104
|
+
const value = new BigNumber(currentOperation.value);
|
|
105
|
+
switch (currentOperation.type) {
|
|
106
|
+
case "VOTE":
|
|
107
|
+
return {
|
|
108
|
+
...acc,
|
|
109
|
+
vote: acc.vote.plus(value),
|
|
110
|
+
};
|
|
111
|
+
case "LOCK":
|
|
112
|
+
return {
|
|
113
|
+
...acc,
|
|
114
|
+
lock: acc.lock.plus(value),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return acc;
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
vote: new BigNumber(0),
|
|
123
|
+
lock: new BigNumber(0),
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return operationAmounts;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const getValidatorGroupsByVotingActivity = (
|
|
131
|
+
validatorGroups: CeloValidatorGroup[],
|
|
132
|
+
votes: CeloVote[],
|
|
133
|
+
withVotes: boolean,
|
|
134
|
+
): CeloValidatorGroup[] => {
|
|
135
|
+
return validatorGroups.filter(v => votes.some(d => d.validatorGroup === v.address) === withVotes);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const getValidatorGroupsWithVotes = (
|
|
139
|
+
validatorGroups: CeloValidatorGroup[],
|
|
140
|
+
votes: CeloVote[] | null,
|
|
141
|
+
): CeloValidatorGroup[] => getValidatorGroupsByVotingActivity(validatorGroups, votes || [], true);
|
|
142
|
+
|
|
143
|
+
export const getValidatorGroupsWithoutVotes = (
|
|
144
|
+
validatorGroups: CeloValidatorGroup[],
|
|
145
|
+
votes: CeloVote[] | null = [],
|
|
146
|
+
): CeloValidatorGroup[] => getValidatorGroupsByVotingActivity(validatorGroups, votes || [], false);
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import network from "@ledgerhq/live-network/network";
|
|
2
|
+
import { OperationType } from "@ledgerhq/types-live";
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
5
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
6
|
+
import { isDefaultValidatorGroup } from "../logic";
|
|
7
|
+
import { CeloOperation, CeloValidatorGroup, FigmentIndexerTransaction } from "../types/types";
|
|
8
|
+
import { celoKit } from "../network/sdk";
|
|
9
|
+
|
|
10
|
+
const DEFAULT_TRANSACTIONS_LIMIT = 200;
|
|
11
|
+
const getUrl = (route: string): string => `${getEnv("API_CELO_INDEXER")}${route || ""}`;
|
|
12
|
+
|
|
13
|
+
// Indexer returns both account data and transactions in one call.
|
|
14
|
+
// Transactions are just limited, there's no block height offset
|
|
15
|
+
const fetchAccountDetails = async (
|
|
16
|
+
address: string,
|
|
17
|
+
transactionsLimit: number = DEFAULT_TRANSACTIONS_LIMIT,
|
|
18
|
+
) => {
|
|
19
|
+
const { data } = await network({
|
|
20
|
+
method: "GET",
|
|
21
|
+
url: getUrl(`/account_details/${address}?limit=${transactionsLimit}`),
|
|
22
|
+
});
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const fetchStatus = async () => {
|
|
27
|
+
const { data } = await network({
|
|
28
|
+
method: "GET",
|
|
29
|
+
url: getUrl(`/status`),
|
|
30
|
+
});
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const fetchValidatorGroups = async () => {
|
|
35
|
+
const { data } = await network({
|
|
36
|
+
method: "GET",
|
|
37
|
+
url: getUrl(`/validator_groups`),
|
|
38
|
+
});
|
|
39
|
+
return data.items;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const getOperationType = (type: string): OperationType => {
|
|
43
|
+
switch (type) {
|
|
44
|
+
case "InternalTransferSent":
|
|
45
|
+
return "OUT";
|
|
46
|
+
case "InternalTransferReceived":
|
|
47
|
+
return "IN";
|
|
48
|
+
case "GoldLocked":
|
|
49
|
+
return "LOCK";
|
|
50
|
+
case "GoldUnlocked":
|
|
51
|
+
return "UNLOCK";
|
|
52
|
+
case "GoldWithdrawn":
|
|
53
|
+
return "WITHDRAW";
|
|
54
|
+
case "ValidatorGroupVoteCastSent":
|
|
55
|
+
return "VOTE";
|
|
56
|
+
case "ValidatorGroupActiveVoteRevokedSent":
|
|
57
|
+
return "REVOKE";
|
|
58
|
+
case "ValidatorGroupPendingVoteRevokedSent":
|
|
59
|
+
return "REVOKE";
|
|
60
|
+
case "ValidatorGroupVoteActivatedSent":
|
|
61
|
+
return "ACTIVATE";
|
|
62
|
+
case "AccountCreated":
|
|
63
|
+
return "REGISTER";
|
|
64
|
+
case "AccountSlashed":
|
|
65
|
+
return "SLASH";
|
|
66
|
+
default:
|
|
67
|
+
return "NONE";
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const transactionToOperation = (
|
|
72
|
+
accountId: string,
|
|
73
|
+
transaction: FigmentIndexerTransaction,
|
|
74
|
+
): CeloOperation => {
|
|
75
|
+
const type: OperationType = getOperationType(transaction.kind);
|
|
76
|
+
const hasFailed = transaction.data?.success ? !transaction.data?.success : false;
|
|
77
|
+
const data = transaction.data;
|
|
78
|
+
const sender = data?.Account || data?.from;
|
|
79
|
+
const recipient = data?.Group || data?.to || data?.Raw?.address;
|
|
80
|
+
const fee = new BigNumber(transaction.data?.gas_used || 0).times(
|
|
81
|
+
new BigNumber(transaction.data?.gas_price || 0),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const value = ["LOCK", "UNLOCK", "ACTIVATE", "VOTE", "REVOKE", "REGISTER"].includes(type)
|
|
85
|
+
? new BigNumber(fee)
|
|
86
|
+
: new BigNumber(transaction.amount);
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
id: encodeOperationId(accountId, transaction.transaction_hash, type),
|
|
90
|
+
hash: transaction.transaction_hash,
|
|
91
|
+
accountId,
|
|
92
|
+
fee,
|
|
93
|
+
value,
|
|
94
|
+
type,
|
|
95
|
+
blockHeight: transaction.height,
|
|
96
|
+
date: new Date(transaction.time),
|
|
97
|
+
senders: sender ? [sender] : [],
|
|
98
|
+
recipients: recipient ? [recipient] : [],
|
|
99
|
+
hasFailed,
|
|
100
|
+
blockHash: null,
|
|
101
|
+
extra: {
|
|
102
|
+
celoOperationValue: new BigNumber(transaction.amount),
|
|
103
|
+
...(["ACTIVATE", "VOTE", "REVOKE"].includes(type)
|
|
104
|
+
? {
|
|
105
|
+
celoSourceValidator: recipient ? recipient : "",
|
|
106
|
+
}
|
|
107
|
+
: {}),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const getAccountDetails = async (
|
|
113
|
+
address: string,
|
|
114
|
+
accountId: string,
|
|
115
|
+
): Promise<{
|
|
116
|
+
blockHeight: any;
|
|
117
|
+
balance: BigNumber;
|
|
118
|
+
spendableBalance: BigNumber;
|
|
119
|
+
operations: CeloOperation[];
|
|
120
|
+
lockedBalance: BigNumber;
|
|
121
|
+
nonvotingLockedBalance: BigNumber;
|
|
122
|
+
}> => {
|
|
123
|
+
const accountDetails = await fetchAccountDetails(address);
|
|
124
|
+
const spendableBalance = new BigNumber(accountDetails.gold_balance);
|
|
125
|
+
const lockedBalance = new BigNumber(accountDetails.total_locked_gold);
|
|
126
|
+
const nonvotingLockedBalance = new BigNumber(accountDetails.total_nonvoting_locked_gold);
|
|
127
|
+
const balance = spendableBalance.plus(lockedBalance);
|
|
128
|
+
const indexerStatus = await fetchStatus();
|
|
129
|
+
const kit = celoKit();
|
|
130
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
131
|
+
|
|
132
|
+
const allTransactions = accountDetails.internal_transfers
|
|
133
|
+
.filter(
|
|
134
|
+
(transfer: { data: { to: string; from: string } }) =>
|
|
135
|
+
transfer.data?.to != lockedGold.address && transfer.data?.from != lockedGold.address,
|
|
136
|
+
)
|
|
137
|
+
.concat(accountDetails.transactions);
|
|
138
|
+
|
|
139
|
+
const operations: CeloOperation[] = allTransactions.map(
|
|
140
|
+
(transaction: FigmentIndexerTransaction) => transactionToOperation(accountId, transaction),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
blockHeight: indexerStatus.last_indexed_height,
|
|
145
|
+
balance,
|
|
146
|
+
spendableBalance,
|
|
147
|
+
operations,
|
|
148
|
+
lockedBalance,
|
|
149
|
+
nonvotingLockedBalance,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const getValidatorGroups = async (): Promise<CeloValidatorGroup[]> => {
|
|
154
|
+
const validatorGroups = await fetchValidatorGroups();
|
|
155
|
+
|
|
156
|
+
const result = validatorGroups.map(
|
|
157
|
+
(validatorGroup: {
|
|
158
|
+
address: string;
|
|
159
|
+
name: string;
|
|
160
|
+
active_votes: BigNumber.Value;
|
|
161
|
+
pending_votes: BigNumber.Value;
|
|
162
|
+
}) => ({
|
|
163
|
+
address: validatorGroup.address,
|
|
164
|
+
name: validatorGroup.name || validatorGroup.address,
|
|
165
|
+
votes: new BigNumber(validatorGroup.active_votes).plus(
|
|
166
|
+
new BigNumber(validatorGroup.pending_votes),
|
|
167
|
+
),
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
return customValidatorGroupsOrder(result);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const customValidatorGroupsOrder = (validatorGroups: any[]): CeloValidatorGroup[] => {
|
|
174
|
+
const defaultValidatorGroup = validatorGroups.find(isDefaultValidatorGroup);
|
|
175
|
+
|
|
176
|
+
const sortedValidatorGroups = [...validatorGroups]
|
|
177
|
+
.sort((a, b) => b.votes.minus(a.votes))
|
|
178
|
+
.filter(group => !isDefaultValidatorGroup(group));
|
|
179
|
+
|
|
180
|
+
return defaultValidatorGroup
|
|
181
|
+
? [defaultValidatorGroup, ...sortedValidatorGroups]
|
|
182
|
+
: sortedValidatorGroups;
|
|
183
|
+
};
|