@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,101 @@
|
|
|
1
|
+
import { ContractKit, newKit } from "@celo/contractkit";
|
|
2
|
+
import { makeLRUCache } from "@ledgerhq/live-network/cache";
|
|
3
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
4
|
+
import { CeloVote } from "../types/types";
|
|
5
|
+
import { CeloTx } from "@celo/connect";
|
|
6
|
+
|
|
7
|
+
let kit: ContractKit;
|
|
8
|
+
export const celoKit = () => {
|
|
9
|
+
if (!kit) kit = newKit(getEnv("API_CELO_NODE"));
|
|
10
|
+
return kit;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fetch account registered status. To lock any Celo, account needs to be registered first
|
|
15
|
+
*/
|
|
16
|
+
export const getAccountRegistrationStatus = async (address: string): Promise<boolean> => {
|
|
17
|
+
const accounts = await celoKit().contracts.getAccounts();
|
|
18
|
+
return await accounts.isAccount(address);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const determineFees = async (txParams: CeloTx): Promise<void> => {
|
|
22
|
+
const {
|
|
23
|
+
connection: { setFeeMarketGas },
|
|
24
|
+
} = celoKit();
|
|
25
|
+
|
|
26
|
+
await setFeeMarketGas(txParams);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Fetch pending withdrawals, with an index
|
|
31
|
+
*/
|
|
32
|
+
export const getPendingWithdrawals = async (address: string) => {
|
|
33
|
+
const lockedGold = await celoKit().contracts.getLockedGold();
|
|
34
|
+
const pendingWithdrawals = await lockedGold.getPendingWithdrawals(address);
|
|
35
|
+
const pendingWithdrawalsWithIndexes = pendingWithdrawals
|
|
36
|
+
.map((withdrawal, index) => ({
|
|
37
|
+
...withdrawal,
|
|
38
|
+
index,
|
|
39
|
+
}))
|
|
40
|
+
.sort((a, b) => a.time.minus(b.time).toNumber());
|
|
41
|
+
return pendingWithdrawalsWithIndexes;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Fetch all votes
|
|
46
|
+
*/
|
|
47
|
+
export const getVotes = async (address: string): Promise<CeloVote[]> => {
|
|
48
|
+
const election = await celoKit().contracts.getElection();
|
|
49
|
+
const voter = await election.getVoter(await voteSignerAccount(address));
|
|
50
|
+
const activates = await getActivateTransactionObjects(address);
|
|
51
|
+
const activatableValidatorGroups = activates.map(activate => activate.txo.arguments[0]);
|
|
52
|
+
|
|
53
|
+
const votes: CeloVote[] = [];
|
|
54
|
+
voter.votes.forEach(vote => {
|
|
55
|
+
let activeVoteRevokable = true;
|
|
56
|
+
if (vote.pending.gt(0)) {
|
|
57
|
+
// If there's a pending vote, it has to be revoked first
|
|
58
|
+
activeVoteRevokable = false;
|
|
59
|
+
votes.push({
|
|
60
|
+
validatorGroup: vote.group,
|
|
61
|
+
amount: vote.pending,
|
|
62
|
+
// Not all pending votes can be activated, 24h has to pass
|
|
63
|
+
activatable: activatableValidatorGroups.includes(vote.group),
|
|
64
|
+
revokable: true,
|
|
65
|
+
index: 0,
|
|
66
|
+
type: "pending",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (vote.active.gt(0))
|
|
70
|
+
votes.push({
|
|
71
|
+
validatorGroup: vote.group,
|
|
72
|
+
amount: vote.active,
|
|
73
|
+
activatable: false,
|
|
74
|
+
revokable: activeVoteRevokable,
|
|
75
|
+
index: 1,
|
|
76
|
+
type: "active",
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return votes;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const getActivateTransactionObjects = async (address: string) => {
|
|
84
|
+
const election = await celoKit().contracts.getElection();
|
|
85
|
+
return await election.activate(await voteSignerAccount(address));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Fetch and cache address of a vote signer account
|
|
90
|
+
* Cache it for 1h since vote signer is usually the same account as our address
|
|
91
|
+
*/
|
|
92
|
+
export const voteSignerAccount = makeLRUCache(
|
|
93
|
+
async (address: string): Promise<string> => {
|
|
94
|
+
const accounts = await celoKit().contracts.getAccounts();
|
|
95
|
+
return await accounts.voteSignerToAccount(address);
|
|
96
|
+
},
|
|
97
|
+
address => address,
|
|
98
|
+
{
|
|
99
|
+
ttl: 60 * 60 * 1000, // 1 hour
|
|
100
|
+
},
|
|
101
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getValidatorGroups } from ".";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import eip55 from "eip55";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
4
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
5
|
+
import { CeloSigner } from ".";
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
NOTE: we should use the evm resolver for celo, but due to the signer types conflicting for now
|
|
9
|
+
we are using a separate resolver
|
|
10
|
+
*/
|
|
11
|
+
const resolver = (signerContext: SignerContext<CeloSigner>): GetAddressFn => {
|
|
12
|
+
return async (deviceId: string, { path, verify, currency }: GetAddressOptions) => {
|
|
13
|
+
const { address, publicKey } = await signerContext(deviceId, signer => {
|
|
14
|
+
/* istanbul ignore next: optional chaining + undefined is a valid value */
|
|
15
|
+
const chainId = currency?.ethereumLikeInfo?.chainId.toString();
|
|
16
|
+
return signer.getAddress(path, verify, false, chainId);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
address: eip55.encode(address),
|
|
21
|
+
publicKey,
|
|
22
|
+
path,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default resolver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./signer";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CeloTx, RLPEncodedTx, LegacyEncodedTx } from "../types";
|
|
2
|
+
import { EvmSignature, EvmAddress } from "@ledgerhq/coin-evm/types/signer";
|
|
3
|
+
import { LoadConfig, ResolutionConfig } from "@ledgerhq/hw-app-eth/lib/services/types";
|
|
4
|
+
import { EIP712Message } from "@ledgerhq/types-live";
|
|
5
|
+
|
|
6
|
+
// TODO: this should use EvmSigner
|
|
7
|
+
export interface CeloSigner {
|
|
8
|
+
getAddress: (
|
|
9
|
+
path: string,
|
|
10
|
+
boolDisplay?: boolean,
|
|
11
|
+
boolChaincode?: boolean,
|
|
12
|
+
chainId?: string,
|
|
13
|
+
) => Promise<EvmAddress>;
|
|
14
|
+
signTransaction: (path: string, rawTxHex: string, resolution?: any) => Promise<EvmSignature>;
|
|
15
|
+
signPersonalMessage: (path: string, messageHex: string) => Promise<EvmSignature>;
|
|
16
|
+
signEIP712Message(
|
|
17
|
+
path: string,
|
|
18
|
+
jsonMessage: EIP712Message,
|
|
19
|
+
fullImplem?: boolean,
|
|
20
|
+
): Promise<EvmSignature>;
|
|
21
|
+
setLoadConfig: (config: LoadConfig) => void;
|
|
22
|
+
clearSignTransaction: (
|
|
23
|
+
path: string,
|
|
24
|
+
rawTxHex: string,
|
|
25
|
+
resolutionConfig: ResolutionConfig,
|
|
26
|
+
throwOnError: boolean,
|
|
27
|
+
) => Promise<EvmSignature>;
|
|
28
|
+
signEIP712HashedMessage: (
|
|
29
|
+
path: string,
|
|
30
|
+
domainSeparatorHex: string,
|
|
31
|
+
hashStructMessageHex: string,
|
|
32
|
+
) => Promise<EvmSignature>;
|
|
33
|
+
// Celo specific
|
|
34
|
+
verifyTokenInfo(to: string, chainId: number): Promise<void>;
|
|
35
|
+
rlpEncodedTxForLedger(txParams: CeloTx): Promise<RLPEncodedTx | LegacyEncodedTx>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
2
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
3
|
+
import {
|
|
4
|
+
minimalAmount,
|
|
5
|
+
createLockMutation,
|
|
6
|
+
createRegisterAccountMutation,
|
|
7
|
+
createSend50PercentMutation,
|
|
8
|
+
createSendMaxMutation,
|
|
9
|
+
createUnlockMutation,
|
|
10
|
+
createVoteMutation,
|
|
11
|
+
createActivateVoteMutation,
|
|
12
|
+
createRevokeVoteMutation,
|
|
13
|
+
createWithdrawMutation,
|
|
14
|
+
} from "./specs/index";
|
|
15
|
+
import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
16
|
+
import type { Transaction } from "../types";
|
|
17
|
+
import { acceptTransaction } from "./speculos-deviceActions";
|
|
18
|
+
|
|
19
|
+
const currency = getCryptoCurrencyById("celo");
|
|
20
|
+
const send50PercentMutation = createSend50PercentMutation();
|
|
21
|
+
const sendMaxMutation = createSendMaxMutation();
|
|
22
|
+
const registerAccountMutation = createRegisterAccountMutation();
|
|
23
|
+
const unlockMutation = createUnlockMutation();
|
|
24
|
+
const lockMutation = createLockMutation();
|
|
25
|
+
const voteMutation = createVoteMutation();
|
|
26
|
+
const activateVoteMutation = createActivateVoteMutation();
|
|
27
|
+
const revokeVoteMutation = createRevokeVoteMutation();
|
|
28
|
+
const withdrawMutation = createWithdrawMutation();
|
|
29
|
+
|
|
30
|
+
const celo: AppSpec<Transaction> = {
|
|
31
|
+
name: "Celo",
|
|
32
|
+
currency,
|
|
33
|
+
appQuery: {
|
|
34
|
+
model: DeviceModelId.nanoS,
|
|
35
|
+
appName: "Celo",
|
|
36
|
+
},
|
|
37
|
+
testTimeout: 4 * 60 * 1000,
|
|
38
|
+
genericDeviceAction: acceptTransaction,
|
|
39
|
+
minViableAmount: minimalAmount,
|
|
40
|
+
mutations: [
|
|
41
|
+
send50PercentMutation,
|
|
42
|
+
sendMaxMutation,
|
|
43
|
+
registerAccountMutation,
|
|
44
|
+
unlockMutation,
|
|
45
|
+
lockMutation,
|
|
46
|
+
voteMutation,
|
|
47
|
+
activateVoteMutation,
|
|
48
|
+
revokeVoteMutation,
|
|
49
|
+
withdrawMutation,
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default {
|
|
54
|
+
celo,
|
|
55
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import celo from "../datasets/celo.scanAccounts.1";
|
|
2
|
+
import type { Transaction } from "../types";
|
|
3
|
+
import type { DatasetTest } from "@ledgerhq/types-live";
|
|
4
|
+
|
|
5
|
+
export const dataset: DatasetTest<Transaction> = {
|
|
6
|
+
implementations: ["js"],
|
|
7
|
+
currencies: {
|
|
8
|
+
celo,
|
|
9
|
+
},
|
|
10
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Account, AccountLike, AccountLikeArray } from "@ledgerhq/types-live";
|
|
2
|
+
|
|
3
|
+
import { from } from "rxjs";
|
|
4
|
+
import { map } from "rxjs/operators";
|
|
5
|
+
import { getValidatorGroups } from "../network";
|
|
6
|
+
import invariant from "invariant";
|
|
7
|
+
import flatMap from "lodash/flatMap";
|
|
8
|
+
import type { Transaction } from "../types";
|
|
9
|
+
|
|
10
|
+
const options = [
|
|
11
|
+
{
|
|
12
|
+
name: "mode",
|
|
13
|
+
type: String,
|
|
14
|
+
desc: "mode of transaction: send, lock, unlock, withdraw, vote, revoke, activate, register",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "transactionIndex",
|
|
18
|
+
type: String,
|
|
19
|
+
desc: "transaction index of a pending withdraw in case of withdraw mode",
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
function inferAccounts(account: Account): AccountLikeArray {
|
|
24
|
+
invariant(account.currency.family === "celo", "celo family");
|
|
25
|
+
|
|
26
|
+
const accounts: Account[] = [account];
|
|
27
|
+
return accounts;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function inferTransactions(
|
|
31
|
+
transactions: Array<{
|
|
32
|
+
account: AccountLike;
|
|
33
|
+
transaction: Transaction;
|
|
34
|
+
mainAccount: Account;
|
|
35
|
+
}>,
|
|
36
|
+
opts: Record<string, any>,
|
|
37
|
+
): Transaction[] {
|
|
38
|
+
const mode = opts.mode || "send";
|
|
39
|
+
invariant(
|
|
40
|
+
["send", "lock", "unlock", "withdraw", "vote", "revoke", "activate", "register"].includes(mode),
|
|
41
|
+
`Unexpected mode: ${mode}`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return flatMap(transactions, ({ transaction }) => {
|
|
45
|
+
invariant(transaction.family === "celo", "celo family");
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
...transaction,
|
|
49
|
+
family: "celo",
|
|
50
|
+
mode,
|
|
51
|
+
index: opts.transactionIndex || null,
|
|
52
|
+
} as Transaction;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const celoValidatorGroups = {
|
|
57
|
+
args: [],
|
|
58
|
+
job: () => from(getValidatorGroups()).pipe(map(validatorGroup => JSON.stringify(validatorGroup))),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default function makeCliTools() {
|
|
62
|
+
return {
|
|
63
|
+
options,
|
|
64
|
+
inferAccounts,
|
|
65
|
+
inferTransactions,
|
|
66
|
+
commands: {
|
|
67
|
+
celoValidatorGroups,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
3
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/parseCurrencyUnit";
|
|
4
|
+
import { MutationSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
5
|
+
import type { CeloAccount, Transaction } from "../../types";
|
|
6
|
+
|
|
7
|
+
const currency = getCryptoCurrencyById("celo");
|
|
8
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
9
|
+
|
|
10
|
+
export const createActivateVoteMutation = (): MutationSpec<Transaction> => ({
|
|
11
|
+
name: "Celo: Activate Vote",
|
|
12
|
+
feature: "staking",
|
|
13
|
+
maxRun: 1,
|
|
14
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
15
|
+
const { celoResources } = account as CeloAccount;
|
|
16
|
+
invariant(celoResources?.registrationStatus, "Celo: Activate Vote | Account is not registered");
|
|
17
|
+
invariant(maxSpendable.gt(minimalAmount), "Celo: Activate Vote | balance is too low");
|
|
18
|
+
|
|
19
|
+
const activatableVote = celoResources?.votes?.find(vote => vote.activatable);
|
|
20
|
+
|
|
21
|
+
invariant(!!activatableVote, "Celo: Activate Vote | No activatable votes");
|
|
22
|
+
|
|
23
|
+
const transaction = {
|
|
24
|
+
recipient: activatableVote!.validatorGroup,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
transaction: bridge.createTransaction(account),
|
|
29
|
+
updates: [
|
|
30
|
+
{
|
|
31
|
+
mode: "activate",
|
|
32
|
+
},
|
|
33
|
+
transaction,
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
3
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/parseCurrencyUnit";
|
|
4
|
+
import { MutationSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
5
|
+
import type { CeloAccount, Transaction } from "../../types";
|
|
6
|
+
|
|
7
|
+
const currency = getCryptoCurrencyById("celo");
|
|
8
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.005");
|
|
9
|
+
|
|
10
|
+
export const createLockMutation = (): MutationSpec<Transaction> => ({
|
|
11
|
+
name: "Celo: Lock",
|
|
12
|
+
feature: "staking",
|
|
13
|
+
maxRun: 1,
|
|
14
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
15
|
+
const { celoResources } = account as CeloAccount;
|
|
16
|
+
invariant(celoResources?.registrationStatus, "Celo: Lock Vote | Account is not registered");
|
|
17
|
+
|
|
18
|
+
invariant(maxSpendable.gt(minimalAmount), "Celo: Lock | balance is too low");
|
|
19
|
+
|
|
20
|
+
const amount = minimalAmount.times(Math.random()).integerValue().precision(8);
|
|
21
|
+
|
|
22
|
+
invariant(amount.gt(0), "Celo: Lock | Not enough funds to lock tokens");
|
|
23
|
+
|
|
24
|
+
const transaction = {
|
|
25
|
+
amount,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
transaction: bridge.createTransaction(account),
|
|
30
|
+
updates: [
|
|
31
|
+
{
|
|
32
|
+
mode: "lock",
|
|
33
|
+
},
|
|
34
|
+
transaction,
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
3
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/parseCurrencyUnit";
|
|
4
|
+
import { MutationSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
5
|
+
import type { CeloAccount, Transaction } from "../../types";
|
|
6
|
+
|
|
7
|
+
const currency = getCryptoCurrencyById("celo");
|
|
8
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
9
|
+
|
|
10
|
+
export const createRegisterAccountMutation = (): MutationSpec<Transaction> => ({
|
|
11
|
+
name: "Celo: Register Account",
|
|
12
|
+
feature: "staking",
|
|
13
|
+
maxRun: 1,
|
|
14
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
15
|
+
const { celoResources } = account as CeloAccount;
|
|
16
|
+
|
|
17
|
+
invariant(
|
|
18
|
+
!celoResources?.registrationStatus,
|
|
19
|
+
"Celo: Register Account | Celo account is already registered",
|
|
20
|
+
);
|
|
21
|
+
invariant(
|
|
22
|
+
maxSpendable.gt(minimalAmount),
|
|
23
|
+
"Celo: Register Account | Celo account balance is too low to register account",
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
transaction: bridge.createTransaction(account),
|
|
28
|
+
updates: [
|
|
29
|
+
{
|
|
30
|
+
mode: "register",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
3
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/parseCurrencyUnit";
|
|
4
|
+
import { MutationSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
5
|
+
import type { CeloAccount, Transaction } from "../../types";
|
|
6
|
+
|
|
7
|
+
const currency = getCryptoCurrencyById("celo");
|
|
8
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
9
|
+
|
|
10
|
+
export const createRevokeVoteMutation = (): MutationSpec<Transaction> => ({
|
|
11
|
+
name: "Celo: RevokeVote",
|
|
12
|
+
feature: "staking",
|
|
13
|
+
maxRun: 1,
|
|
14
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
15
|
+
invariant(maxSpendable.gt(minimalAmount), "Celo: Revoke Vote | balance is too low");
|
|
16
|
+
|
|
17
|
+
const { celoResources } = account as CeloAccount;
|
|
18
|
+
invariant(celoResources?.registrationStatus, "Celo: RevokeVote | Account is not registered");
|
|
19
|
+
|
|
20
|
+
const revokableVote = celoResources?.votes?.find(vote => vote.revokable);
|
|
21
|
+
|
|
22
|
+
invariant(!!revokableVote, "Celo: RevokeVote | Revokable vote not found");
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
transaction: bridge.createTransaction(account),
|
|
26
|
+
updates: [
|
|
27
|
+
{
|
|
28
|
+
mode: "revoke",
|
|
29
|
+
recipient: revokableVote!.validatorGroup,
|
|
30
|
+
group: revokableVote!.validatorGroup,
|
|
31
|
+
address: (account as CeloAccount).celoResources?.electionAddress,
|
|
32
|
+
index: revokableVote!.index,
|
|
33
|
+
amount: revokableVote!.amount,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
3
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/parseCurrencyUnit";
|
|
4
|
+
import { pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
|
|
5
|
+
import { MutationSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
6
|
+
import type { Transaction } from "../../types";
|
|
7
|
+
|
|
8
|
+
const maxAccount = 10;
|
|
9
|
+
const currency = getCryptoCurrencyById("celo");
|
|
10
|
+
export const minimalAmount = parseCurrencyUnit(currency.units[0], "0.01");
|
|
11
|
+
|
|
12
|
+
export const createSend50PercentMutation = (): MutationSpec<Transaction> => ({
|
|
13
|
+
name: "Celo: Move 50% to another account",
|
|
14
|
+
feature: "send",
|
|
15
|
+
maxRun: 1,
|
|
16
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
17
|
+
invariant(maxSpendable.gt(minimalAmount), "Celo: Move 50% | balance is too low");
|
|
18
|
+
const sibling = pickSiblings(siblings, maxAccount);
|
|
19
|
+
const recipient = sibling.freshAddress;
|
|
20
|
+
const amount = maxSpendable.div(2).integerValue();
|
|
21
|
+
return {
|
|
22
|
+
transaction: bridge.createTransaction(account),
|
|
23
|
+
updates: [{ recipient }, { amount }],
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const createSendMaxMutation = (): MutationSpec<Transaction> => ({
|
|
29
|
+
name: "Celo: Send max to another account",
|
|
30
|
+
feature: "sendMax",
|
|
31
|
+
maxRun: 1,
|
|
32
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
33
|
+
invariant(maxSpendable.gt(minimalAmount), "Celo: Send Max | Balance is too low");
|
|
34
|
+
const sibling = pickSiblings(siblings, maxAccount);
|
|
35
|
+
const recipient = sibling.freshAddress;
|
|
36
|
+
return {
|
|
37
|
+
transaction: bridge.createTransaction(account),
|
|
38
|
+
updates: [{ recipient }, { useAllAmount: true }],
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
3
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/parseCurrencyUnit";
|
|
4
|
+
import { MutationSpec } from "@ledgerhq/coin-framework/lib-es/bot/types";
|
|
5
|
+
import type { CeloAccount, Transaction } from "../../types";
|
|
6
|
+
import BigNumber from "bignumber.js";
|
|
7
|
+
|
|
8
|
+
const currency = getCryptoCurrencyById("celo");
|
|
9
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
10
|
+
|
|
11
|
+
export const createUnlockMutation = (): MutationSpec<Transaction> => ({
|
|
12
|
+
name: "Celo: Unlock",
|
|
13
|
+
feature: "staking",
|
|
14
|
+
maxRun: 1,
|
|
15
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
16
|
+
invariant(maxSpendable.gt(minimalAmount), "Celo: Unlock | balance is too low");
|
|
17
|
+
|
|
18
|
+
const { celoResources } = account as CeloAccount;
|
|
19
|
+
invariant(celoResources?.registrationStatus, "Celo: Unlock | Account is not registered");
|
|
20
|
+
const nonvotingLockedBalance = celoResources?.nonvotingLockedBalance || new BigNumber(0);
|
|
21
|
+
invariant(nonvotingLockedBalance.gt(0), "Celo: Unlock | No non voting locked balance");
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
transaction: bridge.createTransaction(account),
|
|
25
|
+
updates: [
|
|
26
|
+
{
|
|
27
|
+
mode: "unlock",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
amount: nonvotingLockedBalance.dividedBy(2).integerValue(),
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import sampleSize from "lodash/sampleSize";
|
|
4
|
+
import { MutationSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
5
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
6
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/parseCurrencyUnit";
|
|
7
|
+
import { getCurrentCeloPreloadData } from "../../bridge/preload";
|
|
8
|
+
import { getValidatorGroupsWithoutVotes } from "../../logic";
|
|
9
|
+
import type { CeloAccount, CeloResources, Transaction } from "../../types";
|
|
10
|
+
|
|
11
|
+
const currency = getCryptoCurrencyById("celo");
|
|
12
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
13
|
+
|
|
14
|
+
export const createVoteMutation = (): MutationSpec<Transaction> => ({
|
|
15
|
+
name: "Celo: Vote",
|
|
16
|
+
feature: "staking",
|
|
17
|
+
maxRun: 1,
|
|
18
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
19
|
+
invariant(maxSpendable.gt(minimalAmount), "Celo: Vote | balance is too low");
|
|
20
|
+
|
|
21
|
+
const { celoResources } = account as CeloAccount;
|
|
22
|
+
invariant(celoResources?.registrationStatus, "Celo: Vote | Account is not registered");
|
|
23
|
+
|
|
24
|
+
const nonvotingLockedBalance = celoResources?.nonvotingLockedBalance || new BigNumber(0);
|
|
25
|
+
invariant(nonvotingLockedBalance.gt(0), "Celo: Vote | No non voting locked balance");
|
|
26
|
+
|
|
27
|
+
const votes = (celoResources as CeloResources).votes || [];
|
|
28
|
+
const { validatorGroups } = getCurrentCeloPreloadData();
|
|
29
|
+
|
|
30
|
+
// Get a random validator group that the account does not have locked tokens for.
|
|
31
|
+
const validatorGroupWithoutVotes = sampleSize(
|
|
32
|
+
getValidatorGroupsWithoutVotes(validatorGroups, votes),
|
|
33
|
+
1,
|
|
34
|
+
)[0];
|
|
35
|
+
|
|
36
|
+
const amount = nonvotingLockedBalance.times(0.5).precision(8).integerValue();
|
|
37
|
+
|
|
38
|
+
invariant(amount.gt(0), "Celo: Vote | Not enough funds to vote");
|
|
39
|
+
|
|
40
|
+
const transaction = {
|
|
41
|
+
recipient: validatorGroupWithoutVotes.address,
|
|
42
|
+
amount,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
transaction: bridge.createTransaction(account),
|
|
47
|
+
updates: [
|
|
48
|
+
{
|
|
49
|
+
mode: "vote",
|
|
50
|
+
},
|
|
51
|
+
transaction,
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { MutationSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
3
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
4
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/parseCurrencyUnit";
|
|
5
|
+
import { availablePendingWithdrawals } from "../../logic";
|
|
6
|
+
import type { CeloAccount, Transaction } from "../../types";
|
|
7
|
+
|
|
8
|
+
const currency = getCryptoCurrencyById("celo");
|
|
9
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
10
|
+
|
|
11
|
+
export const createWithdrawMutation = (): MutationSpec<Transaction> => ({
|
|
12
|
+
name: "Celo: Withdraw",
|
|
13
|
+
feature: "staking",
|
|
14
|
+
maxRun: 1,
|
|
15
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
16
|
+
const celoAccount = account as CeloAccount;
|
|
17
|
+
const { celoResources } = celoAccount;
|
|
18
|
+
invariant(celoResources?.registrationStatus, "Celo: Withdraw | Account is not registered");
|
|
19
|
+
|
|
20
|
+
const pendingWithdrawals = availablePendingWithdrawals(celoAccount);
|
|
21
|
+
|
|
22
|
+
invariant(pendingWithdrawals.length > 0, "Celo: Withdraw | No withdrawable balance");
|
|
23
|
+
|
|
24
|
+
invariant(maxSpendable.gt(minimalAmount), "Celo: Withdraw Vote | balance is too low");
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
transaction: bridge.createTransaction(celoAccount),
|
|
28
|
+
updates: [
|
|
29
|
+
{
|
|
30
|
+
mode: "withdraw",
|
|
31
|
+
recipient: celoAccount.celoResources!.lockedGoldAddress!,
|
|
32
|
+
index: pendingWithdrawals[0].index,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./createSendMutation";
|
|
2
|
+
export * from "./createLockMutation";
|
|
3
|
+
export * from "./createUnlockMutation";
|
|
4
|
+
export * from "./createRegisterAccountMutation";
|
|
5
|
+
export * from "./createVoteMutation";
|
|
6
|
+
export * from "./createActivateVoteMutation";
|
|
7
|
+
export * from "./createRevokeVoteMutation";
|
|
8
|
+
export * from "./createWithdrawMutation";
|