@ledgerhq/coin-evm 0.2.1 → 0.2.2-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +11 -46
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +29 -1
- package/lib/__tests__/adapters.unit.test.d.ts +2 -0
- package/lib/__tests__/adapters.unit.test.d.ts.map +1 -0
- package/lib/__tests__/adapters.unit.test.js +455 -0
- package/lib/__tests__/adapters.unit.test.js.map +1 -0
- package/lib/__tests__/broadcast.unit.test.d.ts +2 -0
- package/lib/__tests__/broadcast.unit.test.d.ts.map +1 -0
- package/lib/__tests__/broadcast.unit.test.js +181 -0
- package/lib/__tests__/broadcast.unit.test.js.map +1 -0
- package/lib/__tests__/buildOptimisticOperation.unit.test.d.ts +2 -0
- package/lib/__tests__/buildOptimisticOperation.unit.test.d.ts.map +1 -0
- package/lib/__tests__/buildOptimisticOperation.unit.test.js +166 -0
- package/lib/__tests__/buildOptimisticOperation.unit.test.js.map +1 -0
- package/lib/__tests__/createTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/createTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/createTransaction.unit.test.js +50 -0
- package/lib/__tests__/createTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/deviceTransactionConfig.unit.test.d.ts +2 -0
- package/lib/__tests__/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib/__tests__/deviceTransactionConfig.unit.test.js +231 -0
- package/lib/__tests__/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib/__tests__/estimateMaxSpendable.unit.test.d.ts +2 -0
- package/lib/__tests__/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib/__tests__/estimateMaxSpendable.unit.test.js +145 -0
- package/lib/__tests__/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib/__tests__/gasTracker/index.unit.test.d.ts +2 -0
- package/lib/__tests__/gasTracker/index.unit.test.d.ts.map +1 -0
- package/lib/__tests__/gasTracker/index.unit.test.js +35 -0
- package/lib/__tests__/gasTracker/index.unit.test.js.map +1 -0
- package/lib/__tests__/gasTracker/ledger.unit.test.d.ts +2 -0
- package/lib/__tests__/gasTracker/ledger.unit.test.d.ts.map +1 -0
- package/lib/__tests__/gasTracker/ledger.unit.test.js +110 -0
- package/lib/__tests__/gasTracker/ledger.unit.test.js.map +1 -0
- package/lib/__tests__/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib/__tests__/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/__tests__/getTransactionStatus.unit.test.js +216 -0
- package/lib/__tests__/getTransactionStatus.unit.test.js.map +1 -0
- package/lib/__tests__/hw-getAddress.unit.test.d.ts +2 -0
- package/lib/__tests__/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/hw-getAddress.unit.test.js +47 -0
- package/lib/__tests__/hw-getAddress.unit.test.js.map +1 -0
- package/lib/__tests__/logic.unit.test.d.ts +2 -0
- package/lib/__tests__/logic.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic.unit.test.js +296 -0
- package/lib/__tests__/logic.unit.test.js.map +1 -0
- package/lib/__tests__/preload.unit.test.d.ts +2 -0
- package/lib/__tests__/preload.unit.test.d.ts.map +1 -0
- package/lib/__tests__/preload.unit.test.js +149 -0
- package/lib/__tests__/preload.unit.test.js.map +1 -0
- package/lib/__tests__/prepareTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/prepareTransaction.unit.test.js +248 -0
- package/lib/__tests__/prepareTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/rpc.unit.test.d.ts +2 -0
- package/lib/__tests__/rpc.unit.test.d.ts.map +1 -0
- package/lib/__tests__/rpc.unit.test.js +444 -0
- package/lib/__tests__/rpc.unit.test.js.map +1 -0
- package/lib/__tests__/signOperation.unit.test.d.ts +2 -0
- package/lib/__tests__/signOperation.unit.test.d.ts.map +1 -0
- package/lib/__tests__/signOperation.unit.test.js +160 -0
- package/lib/__tests__/signOperation.unit.test.js.map +1 -0
- package/lib/__tests__/synchronization.unit.test.d.ts +2 -0
- package/lib/__tests__/synchronization.unit.test.d.ts.map +1 -0
- package/lib/__tests__/synchronization.unit.test.js +499 -0
- package/lib/__tests__/synchronization.unit.test.js.map +1 -0
- package/lib/__tests__/transaction.unit.test.d.ts +2 -0
- package/lib/__tests__/transaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/transaction.unit.test.js +201 -0
- package/lib/__tests__/transaction.unit.test.js.map +1 -0
- package/lib/abis/erc20.abi.json +222 -0
- package/lib/abis/optimismGasPriceOracle.abi.json +252 -0
- package/lib/adapters.d.ts +21 -0
- package/lib/adapters.d.ts.map +1 -0
- package/lib/adapters.js +118 -0
- package/lib/adapters.js.map +1 -0
- package/lib/api/explorer/etherscan.d.ts +24 -0
- package/lib/api/explorer/etherscan.d.ts.map +1 -0
- package/lib/api/explorer/etherscan.js +90 -0
- package/lib/api/explorer/etherscan.js.map +1 -0
- package/lib/api/explorer/index.d.ts +26 -0
- package/lib/api/explorer/index.d.ts.map +1 -0
- package/lib/api/explorer/index.js +23 -0
- package/lib/api/explorer/index.js.map +1 -0
- package/lib/api/gasTracker/index.d.ts +13 -0
- package/lib/api/gasTracker/index.d.ts.map +1 -0
- package/lib/api/gasTracker/index.js +21 -0
- package/lib/api/gasTracker/index.js.map +1 -0
- package/lib/api/gasTracker/ledger.d.ts +9 -0
- package/lib/api/gasTracker/ledger.d.ts.map +1 -0
- package/lib/api/gasTracker/ledger.js +90 -0
- package/lib/api/gasTracker/ledger.js.map +1 -0
- package/lib/api/rpc/index.d.ts +3 -0
- package/lib/api/rpc/index.d.ts.map +1 -0
- package/lib/api/rpc/index.js +32 -0
- package/lib/api/rpc/index.js.map +1 -0
- package/lib/api/rpc/rpc.common.d.ts +93 -0
- package/lib/api/rpc/rpc.common.d.ts.map +1 -0
- package/lib/api/rpc/rpc.common.js +284 -0
- package/lib/api/rpc/rpc.common.js.map +1 -0
- package/lib/api/rpc/rpc.native.d.ts +6 -0
- package/lib/api/rpc/rpc.native.d.ts.map +1 -0
- package/lib/api/rpc/rpc.native.js +35 -0
- package/lib/api/rpc/rpc.native.js.map +1 -0
- package/lib/bridge/js.d.ts +11 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +58 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/bridge.integration.test.d.ts +14 -0
- package/lib/bridge.integration.test.d.ts.map +1 -0
- package/lib/bridge.integration.test.js +85 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/broadcast.d.ts +8 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +25 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/buildOptimisticOperation.d.ts +16 -0
- package/lib/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/buildOptimisticOperation.js +80 -0
- package/lib/buildOptimisticOperation.js.map +1 -0
- package/lib/cli-transaction.d.ts +2 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +9 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/createTransaction.d.ts +9 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +32 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/datasets/ethereum.scanAccounts.1.d.ts +7 -0
- package/lib/datasets/ethereum.scanAccounts.1.d.ts.map +1 -0
- package/lib/datasets/ethereum.scanAccounts.1.js +51 -0
- package/lib/datasets/ethereum.scanAccounts.1.js.map +1 -0
- package/lib/datasets/ethereum1.d.ts +3 -0
- package/lib/datasets/ethereum1.d.ts.map +1 -0
- package/lib/datasets/ethereum1.js +22 -0
- package/lib/datasets/ethereum1.js.map +1 -0
- package/lib/datasets/ethereum2.d.ts +3 -0
- package/lib/datasets/ethereum2.d.ts.map +1 -0
- package/lib/datasets/ethereum2.js +22 -0
- package/lib/datasets/ethereum2.js.map +1 -0
- package/lib/datasets/ethereum_classic.d.ts +5 -0
- package/lib/datasets/ethereum_classic.d.ts.map +1 -0
- package/lib/datasets/ethereum_classic.js +69 -0
- package/lib/datasets/ethereum_classic.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +15 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +44 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +16 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +11 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +4 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +23 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +23 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +132 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +28 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/logic.d.ts +31 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +131 -0
- package/lib/logic.js.map +1 -0
- package/lib/preload.d.ts +6 -0
- package/lib/preload.d.ts.map +1 -0
- package/lib/preload.js +58 -0
- package/lib/preload.js.map +1 -0
- package/lib/prepareTransaction.d.ts +26 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +128 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/signOperation.d.ts +18 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +88 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +27 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +3 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +238 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +8 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +66 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronization.d.ts +27 -0
- package/lib/synchronization.d.ts.map +1 -0
- package/lib/synchronization.js +220 -0
- package/lib/synchronization.js.map +1 -0
- package/lib/testUtils.d.ts +6 -0
- package/lib/testUtils.d.ts.map +1 -0
- package/lib/testUtils.js +111 -0
- package/lib/testUtils.js.map +1 -0
- package/lib/transaction.d.ts +43 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +124 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +111 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib-es/__tests__/adapters.unit.test.d.ts +2 -0
- package/lib-es/__tests__/adapters.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/adapters.unit.test.js +450 -0
- package/lib-es/__tests__/adapters.unit.test.js.map +1 -0
- package/lib-es/__tests__/broadcast.unit.test.d.ts +2 -0
- package/lib-es/__tests__/broadcast.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/broadcast.unit.test.js +153 -0
- package/lib-es/__tests__/broadcast.unit.test.js.map +1 -0
- package/lib-es/__tests__/buildOptimisticOperation.unit.test.d.ts +2 -0
- package/lib-es/__tests__/buildOptimisticOperation.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/buildOptimisticOperation.unit.test.js +161 -0
- package/lib-es/__tests__/buildOptimisticOperation.unit.test.js.map +1 -0
- package/lib-es/__tests__/createTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/createTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/createTransaction.unit.test.js +45 -0
- package/lib-es/__tests__/createTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/deviceTransactionConfig.unit.test.d.ts +2 -0
- package/lib-es/__tests__/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/deviceTransactionConfig.unit.test.js +226 -0
- package/lib-es/__tests__/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib-es/__tests__/estimateMaxSpendable.unit.test.d.ts +2 -0
- package/lib-es/__tests__/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/estimateMaxSpendable.unit.test.js +117 -0
- package/lib-es/__tests__/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib-es/__tests__/gasTracker/index.unit.test.d.ts +2 -0
- package/lib-es/__tests__/gasTracker/index.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/gasTracker/index.unit.test.js +33 -0
- package/lib-es/__tests__/gasTracker/index.unit.test.js.map +1 -0
- package/lib-es/__tests__/gasTracker/ledger.unit.test.d.ts +2 -0
- package/lib-es/__tests__/gasTracker/ledger.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/gasTracker/ledger.unit.test.js +105 -0
- package/lib-es/__tests__/gasTracker/ledger.unit.test.js.map +1 -0
- package/lib-es/__tests__/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib-es/__tests__/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/getTransactionStatus.unit.test.js +211 -0
- package/lib-es/__tests__/getTransactionStatus.unit.test.js.map +1 -0
- package/lib-es/__tests__/hw-getAddress.unit.test.d.ts +2 -0
- package/lib-es/__tests__/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/hw-getAddress.unit.test.js +42 -0
- package/lib-es/__tests__/hw-getAddress.unit.test.js.map +1 -0
- package/lib-es/__tests__/logic.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic.unit.test.js +268 -0
- package/lib-es/__tests__/logic.unit.test.js.map +1 -0
- package/lib-es/__tests__/preload.unit.test.d.ts +2 -0
- package/lib-es/__tests__/preload.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/preload.unit.test.js +121 -0
- package/lib-es/__tests__/preload.unit.test.js.map +1 -0
- package/lib-es/__tests__/prepareTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/prepareTransaction.unit.test.js +220 -0
- package/lib-es/__tests__/prepareTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/rpc.unit.test.d.ts +2 -0
- package/lib-es/__tests__/rpc.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/rpc.unit.test.js +416 -0
- package/lib-es/__tests__/rpc.unit.test.js.map +1 -0
- package/lib-es/__tests__/signOperation.unit.test.d.ts +2 -0
- package/lib-es/__tests__/signOperation.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/signOperation.unit.test.js +132 -0
- package/lib-es/__tests__/signOperation.unit.test.js.map +1 -0
- package/lib-es/__tests__/synchronization.unit.test.d.ts +2 -0
- package/lib-es/__tests__/synchronization.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/synchronization.unit.test.js +471 -0
- package/lib-es/__tests__/synchronization.unit.test.js.map +1 -0
- package/lib-es/__tests__/transaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/transaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/transaction.unit.test.js +173 -0
- package/lib-es/__tests__/transaction.unit.test.js.map +1 -0
- package/lib-es/abis/erc20.abi.json +222 -0
- package/lib-es/abis/optimismGasPriceOracle.abi.json +252 -0
- package/lib-es/adapters.d.ts +21 -0
- package/lib-es/adapters.d.ts.map +1 -0
- package/lib-es/adapters.js +109 -0
- package/lib-es/adapters.js.map +1 -0
- package/lib-es/api/explorer/etherscan.d.ts +24 -0
- package/lib-es/api/explorer/etherscan.d.ts.map +1 -0
- package/lib-es/api/explorer/etherscan.js +84 -0
- package/lib-es/api/explorer/etherscan.js.map +1 -0
- package/lib-es/api/explorer/index.d.ts +26 -0
- package/lib-es/api/explorer/index.d.ts.map +1 -0
- package/lib-es/api/explorer/index.js +16 -0
- package/lib-es/api/explorer/index.js.map +1 -0
- package/lib-es/api/gasTracker/index.d.ts +13 -0
- package/lib-es/api/gasTracker/index.d.ts.map +1 -0
- package/lib-es/api/gasTracker/index.js +17 -0
- package/lib-es/api/gasTracker/index.js.map +1 -0
- package/lib-es/api/gasTracker/ledger.d.ts +9 -0
- package/lib-es/api/gasTracker/ledger.d.ts.map +1 -0
- package/lib-es/api/gasTracker/ledger.js +83 -0
- package/lib-es/api/gasTracker/ledger.js.map +1 -0
- package/lib-es/api/rpc/index.d.ts +3 -0
- package/lib-es/api/rpc/index.d.ts.map +1 -0
- package/lib-es/api/rpc/index.js +4 -0
- package/lib-es/api/rpc/index.js.map +1 -0
- package/lib-es/api/rpc/rpc.common.d.ts +93 -0
- package/lib-es/api/rpc/rpc.common.d.ts.map +1 -0
- package/lib-es/api/rpc/rpc.common.js +267 -0
- package/lib-es/api/rpc/rpc.common.js.map +1 -0
- package/lib-es/api/rpc/rpc.native.d.ts +6 -0
- package/lib-es/api/rpc/rpc.native.d.ts.map +1 -0
- package/lib-es/api/rpc/rpc.native.js +7 -0
- package/lib-es/api/rpc/rpc.native.js.map +1 -0
- package/lib-es/bridge/js.d.ts +11 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +49 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/bridge.integration.test.d.ts +14 -0
- package/lib-es/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/bridge.integration.test.js +79 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/broadcast.d.ts +8 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +21 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/buildOptimisticOperation.d.ts +16 -0
- package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/buildOptimisticOperation.js +71 -0
- package/lib-es/buildOptimisticOperation.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +2 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +6 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/createTransaction.d.ts +9 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +25 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/datasets/ethereum.scanAccounts.1.d.ts +7 -0
- package/lib-es/datasets/ethereum.scanAccounts.1.d.ts.map +1 -0
- package/lib-es/datasets/ethereum.scanAccounts.1.js +49 -0
- package/lib-es/datasets/ethereum.scanAccounts.1.js.map +1 -0
- package/lib-es/datasets/ethereum1.d.ts +3 -0
- package/lib-es/datasets/ethereum1.d.ts.map +1 -0
- package/lib-es/datasets/ethereum1.js +19 -0
- package/lib-es/datasets/ethereum1.js.map +1 -0
- package/lib-es/datasets/ethereum2.d.ts +3 -0
- package/lib-es/datasets/ethereum2.d.ts.map +1 -0
- package/lib-es/datasets/ethereum2.js +19 -0
- package/lib-es/datasets/ethereum2.js.map +1 -0
- package/lib-es/datasets/ethereum_classic.d.ts +5 -0
- package/lib-es/datasets/ethereum_classic.d.ts.map +1 -0
- package/lib-es/datasets/ethereum_classic.js +67 -0
- package/lib-es/datasets/ethereum_classic.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +15 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +42 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/errors.d.ts +16 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +8 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +4 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +19 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +23 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +125 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +23 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/logic.d.ts +31 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +119 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/preload.d.ts +6 -0
- package/lib-es/preload.d.ts.map +1 -0
- package/lib-es/preload.js +49 -0
- package/lib-es/preload.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +26 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +118 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/signOperation.d.ts +18 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +83 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +27 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +3 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +233 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +8 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +63 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronization.d.ts +27 -0
- package/lib-es/synchronization.d.ts.map +1 -0
- package/lib-es/synchronization.js +212 -0
- package/lib-es/synchronization.js.map +1 -0
- package/lib-es/testUtils.d.ts +6 -0
- package/lib-es/testUtils.d.ts.map +1 -0
- package/lib-es/testUtils.js +102 -0
- package/lib-es/testUtils.js.map +1 -0
- package/lib-es/transaction.d.ts +43 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +112 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types.d.ts +111 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +2 -0
- package/lib-es/types.js.map +1 -0
- package/package.json +8 -23
- package/src/__tests__/adapters.unit.test.ts +22 -52
- package/src/__tests__/broadcast.unit.test.ts +9 -27
- package/src/__tests__/buildOptimisticOperation.unit.test.ts +4 -4
- package/src/__tests__/deviceTransactionConfig.unit.test.ts +7 -7
- package/src/__tests__/estimateMaxSpendable.unit.test.ts +2 -4
- package/src/__tests__/gasTracker/index.unit.test.ts +36 -0
- package/src/__tests__/gasTracker/ledger.unit.test.ts +108 -0
- package/src/__tests__/getTransactionStatus.unit.test.ts +35 -40
- package/src/__tests__/hw-getAddress.unit.test.ts +15 -2
- package/src/__tests__/logic.unit.test.ts +25 -72
- package/src/__tests__/preload.unit.test.ts +3 -9
- package/src/__tests__/prepareTransaction.unit.test.ts +131 -76
- package/src/__tests__/rpc.unit.test.ts +46 -80
- package/src/__tests__/signOperation.unit.test.ts +27 -25
- package/src/__tests__/synchronization.unit.test.ts +101 -153
- package/src/__tests__/transaction.unit.test.ts +6 -14
- package/src/adapters.ts +8 -18
- package/src/api/{etherscan.ts → explorer/etherscan.ts} +14 -29
- package/src/api/explorer/index.ts +34 -0
- package/src/api/gasTracker/index.ts +31 -0
- package/src/api/gasTracker/ledger.ts +103 -0
- package/src/api/{rpc.common.ts → rpc/rpc.common.ts} +41 -64
- package/src/bridge/js.ts +15 -22
- package/src/bridge.integration.test.ts +3 -10
- package/src/broadcast.ts +3 -7
- package/src/buildOptimisticOperation.ts +7 -17
- package/src/cli-transaction.ts +1 -7
- package/src/createTransaction.ts +14 -15
- package/src/deviceTransactionConfig.ts +1 -1
- package/src/errors.ts +6 -0
- package/src/estimateMaxSpendable.ts +14 -11
- package/src/getTransactionStatus.ts +41 -52
- package/src/hw-getAddress.ts +18 -19
- package/src/logic.ts +5 -15
- package/src/preload.ts +6 -16
- package/src/prepareTransaction.ts +30 -31
- package/src/signOperation.ts +57 -69
- package/src/signer.ts +35 -0
- package/src/specs.ts +27 -52
- package/src/speculos-deviceActions.ts +56 -65
- package/src/synchronization.ts +21 -60
- package/src/testUtils.ts +5 -19
- package/src/transaction.ts +6 -10
- package/src/types.ts +6 -0
- /package/src/api/{rpc.ts → rpc/index.ts} +0 -0
- /package/src/api/{rpc.native.ts → rpc/rpc.native.ts} +0 -0
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { ethers } from "ethers";
|
|
3
3
|
import { transactionToEthersTransaction } from "../adapters";
|
|
4
|
-
import * as rpcAPI from "../api/rpc.common";
|
|
5
|
-
import {
|
|
6
|
-
fromTransactionRaw,
|
|
7
|
-
getSerializedTransaction,
|
|
8
|
-
toTransactionRaw,
|
|
9
|
-
} from "../transaction";
|
|
4
|
+
import * as rpcAPI from "../api/rpc/rpc.common";
|
|
5
|
+
import { fromTransactionRaw, getSerializedTransaction, toTransactionRaw } from "../transaction";
|
|
10
6
|
import {
|
|
11
7
|
Transaction as EvmTransaction,
|
|
12
8
|
EvmTransactionEIP1559,
|
|
@@ -134,17 +130,13 @@ describe("EVM Family", () => {
|
|
|
134
130
|
gasPrice: ethers.BigNumber.from(10000),
|
|
135
131
|
};
|
|
136
132
|
|
|
137
|
-
expect(transactionToEthersTransaction(legacyTx)).toEqual(
|
|
138
|
-
legacyEthersTx
|
|
139
|
-
);
|
|
133
|
+
expect(transactionToEthersTransaction(legacyTx)).toEqual(legacyEthersTx);
|
|
140
134
|
});
|
|
141
135
|
});
|
|
142
136
|
|
|
143
137
|
describe("getSerializedTransaction", () => {
|
|
144
138
|
beforeAll(() => {
|
|
145
|
-
jest
|
|
146
|
-
.spyOn(rpcAPI, "getTransactionCount")
|
|
147
|
-
.mockImplementation(() => Promise.resolve(0));
|
|
139
|
+
jest.spyOn(rpcAPI, "getTransactionCount").mockImplementation(() => Promise.resolve(0));
|
|
148
140
|
});
|
|
149
141
|
|
|
150
142
|
it("should serialize a type 0 transaction", async () => {
|
|
@@ -165,7 +157,7 @@ describe("EVM Family", () => {
|
|
|
165
157
|
const serializedTx = await getSerializedTransaction(transactionLegacy);
|
|
166
158
|
|
|
167
159
|
expect(serializedTx).toBe(
|
|
168
|
-
"0xdf8064825208946775e49108cb77cda06fc3bef51bcd497602ad886480018080"
|
|
160
|
+
"0xdf8064825208946775e49108cb77cda06fc3bef51bcd497602ad886480018080",
|
|
169
161
|
);
|
|
170
162
|
});
|
|
171
163
|
|
|
@@ -188,7 +180,7 @@ describe("EVM Family", () => {
|
|
|
188
180
|
const serializedTx = await getSerializedTransaction(transactionEIP1559);
|
|
189
181
|
|
|
190
182
|
expect(serializedTx).toBe(
|
|
191
|
-
"0x02df01806464825208946775e49108cb77cda06fc3bef51bcd497602ad886480c0"
|
|
183
|
+
"0x02df01806464825208946775e49108cb77cda06fc3bef51bcd497602ad886480c0",
|
|
192
184
|
);
|
|
193
185
|
});
|
|
194
186
|
});
|
package/src/adapters.ts
CHANGED
|
@@ -4,10 +4,7 @@ import BigNumber from "bignumber.js";
|
|
|
4
4
|
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
5
|
import { Operation, OperationType } from "@ledgerhq/types-live";
|
|
6
6
|
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
|
|
7
|
-
import {
|
|
8
|
-
decodeAccountId,
|
|
9
|
-
encodeTokenAccountId,
|
|
10
|
-
} from "@ledgerhq/coin-framework/account/index";
|
|
7
|
+
import { decodeAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
11
8
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
12
9
|
import {
|
|
13
10
|
Transaction as EvmTransaction,
|
|
@@ -20,9 +17,7 @@ import {
|
|
|
20
17
|
/**
|
|
21
18
|
* Adapter to convert a Ledger Live transaction to an Ethers transaction
|
|
22
19
|
*/
|
|
23
|
-
export const transactionToEthersTransaction = (
|
|
24
|
-
tx: EvmTransaction
|
|
25
|
-
): ethers.Transaction => {
|
|
20
|
+
export const transactionToEthersTransaction = (tx: EvmTransaction): ethers.Transaction => {
|
|
26
21
|
const ethersTx = {
|
|
27
22
|
to: tx.recipient,
|
|
28
23
|
value: ethers.BigNumber.from(tx.amount.toFixed()),
|
|
@@ -36,16 +31,14 @@ export const transactionToEthersTransaction = (
|
|
|
36
31
|
// is EIP-1559 transaction (type 2)
|
|
37
32
|
if (tx.type === 2) {
|
|
38
33
|
ethersTx.maxFeePerGas = ethers.BigNumber.from(
|
|
39
|
-
(tx as EvmTransactionEIP1559).maxFeePerGas.toFixed()
|
|
34
|
+
(tx as EvmTransactionEIP1559).maxFeePerGas.toFixed(),
|
|
40
35
|
);
|
|
41
36
|
ethersTx.maxPriorityFeePerGas = ethers.BigNumber.from(
|
|
42
|
-
(tx as EvmTransactionEIP1559).maxPriorityFeePerGas.toFixed()
|
|
37
|
+
(tx as EvmTransactionEIP1559).maxPriorityFeePerGas.toFixed(),
|
|
43
38
|
);
|
|
44
39
|
} else {
|
|
45
40
|
// is Legacy transaction (type 0)
|
|
46
|
-
ethersTx.gasPrice = ethers.BigNumber.from(
|
|
47
|
-
(tx as EvmTransactionLegacy).gasPrice.toFixed()
|
|
48
|
-
);
|
|
41
|
+
ethersTx.gasPrice = ethers.BigNumber.from((tx as EvmTransactionLegacy).gasPrice.toFixed());
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
return ethersTx as ethers.Transaction;
|
|
@@ -56,7 +49,7 @@ export const transactionToEthersTransaction = (
|
|
|
56
49
|
*/
|
|
57
50
|
export const etherscanOperationToOperation = (
|
|
58
51
|
accountId: string,
|
|
59
|
-
tx: EtherscanOperation
|
|
52
|
+
tx: EtherscanOperation,
|
|
60
53
|
): Operation => {
|
|
61
54
|
const { xpubOrAddress: address } = decodeAccountId(accountId);
|
|
62
55
|
const checksummedAddress = eip55.encode(address);
|
|
@@ -99,13 +92,10 @@ export const etherscanOperationToOperation = (
|
|
|
99
92
|
*/
|
|
100
93
|
export const etherscanERC20EventToOperation = (
|
|
101
94
|
accountId: string,
|
|
102
|
-
event: EtherscanERC20Event
|
|
95
|
+
event: EtherscanERC20Event,
|
|
103
96
|
): { tokenCurrency: TokenCurrency; operation: Operation } | null => {
|
|
104
97
|
const { currencyId, xpubOrAddress: address } = decodeAccountId(accountId);
|
|
105
|
-
const tokenCurrency = findTokenByAddressInCurrency(
|
|
106
|
-
event.contractAddress,
|
|
107
|
-
currencyId
|
|
108
|
-
);
|
|
98
|
+
const tokenCurrency = findTokenByAddressInCurrency(event.contractAddress, currencyId);
|
|
109
99
|
if (!tokenCurrency) return null;
|
|
110
100
|
|
|
111
101
|
const tokenAccountId = encodeTokenAccountId(accountId, tokenCurrency);
|
|
@@ -3,19 +3,16 @@ import { Operation } from "@ledgerhq/types-live";
|
|
|
3
3
|
import axios, { AxiosRequestConfig } from "axios";
|
|
4
4
|
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
5
|
import { makeLRUCache } from "@ledgerhq/live-network/cache";
|
|
6
|
-
import { EtherscanERC20Event, EtherscanOperation } from "
|
|
7
|
-
import { EtherscanAPIError } from "
|
|
8
|
-
import {
|
|
9
|
-
etherscanERC20EventToOperation,
|
|
10
|
-
etherscanOperationToOperation,
|
|
11
|
-
} from "../adapters";
|
|
6
|
+
import { EtherscanERC20Event, EtherscanOperation } from "../../types";
|
|
7
|
+
import { EtherscanAPIError } from "../../errors";
|
|
8
|
+
import { etherscanERC20EventToOperation, etherscanOperationToOperation } from "../../adapters";
|
|
12
9
|
|
|
13
10
|
export const ETHERSCAN_TIMEOUT = 5000; // 5 seconds between 2 calls
|
|
14
11
|
export const DEFAULT_RETRIES_API = 8;
|
|
15
12
|
|
|
16
13
|
async function fetchWithRetries<T>(
|
|
17
14
|
params: AxiosRequestConfig,
|
|
18
|
-
retries = DEFAULT_RETRIES_API
|
|
15
|
+
retries = DEFAULT_RETRIES_API,
|
|
19
16
|
): Promise<T> {
|
|
20
17
|
try {
|
|
21
18
|
const { data } = await axios.request<{
|
|
@@ -25,10 +22,10 @@ async function fetchWithRetries<T>(
|
|
|
25
22
|
}>(params);
|
|
26
23
|
|
|
27
24
|
if (!Number(data.status) && data.message === "NOTOK") {
|
|
28
|
-
throw new EtherscanAPIError(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
25
|
+
throw new EtherscanAPIError("Error while fetching data from Etherscan like API", {
|
|
26
|
+
params,
|
|
27
|
+
data,
|
|
28
|
+
});
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
return data.result;
|
|
@@ -47,12 +44,7 @@ async function fetchWithRetries<T>(
|
|
|
47
44
|
* Get all the last "normal" transactions (no tokens / NFTs)
|
|
48
45
|
*/
|
|
49
46
|
export const getLastCoinOperations = makeLRUCache<
|
|
50
|
-
[
|
|
51
|
-
currency: CryptoCurrency,
|
|
52
|
-
address: string,
|
|
53
|
-
accountId: string,
|
|
54
|
-
fromBlock: number
|
|
55
|
-
],
|
|
47
|
+
[currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
|
|
56
48
|
Operation[]
|
|
57
49
|
>(
|
|
58
50
|
async (currency, address, accountId, fromBlock) => {
|
|
@@ -72,23 +64,18 @@ export const getLastCoinOperations = makeLRUCache<
|
|
|
72
64
|
});
|
|
73
65
|
|
|
74
66
|
return ops
|
|
75
|
-
.map(
|
|
67
|
+
.map(tx => etherscanOperationToOperation(accountId, tx))
|
|
76
68
|
.filter(Boolean) as Operation[];
|
|
77
69
|
},
|
|
78
70
|
(currency, address, accountId, fromBlock) => accountId + fromBlock,
|
|
79
|
-
{ ttl: 5 * 1000 }
|
|
71
|
+
{ ttl: 5 * 1000 },
|
|
80
72
|
);
|
|
81
73
|
|
|
82
74
|
/**
|
|
83
75
|
* Get all the last ERC20 transactions
|
|
84
76
|
*/
|
|
85
77
|
export const getLastTokenOperations = makeLRUCache<
|
|
86
|
-
[
|
|
87
|
-
currency: CryptoCurrency,
|
|
88
|
-
address: string,
|
|
89
|
-
accountId: string,
|
|
90
|
-
fromBlock: number
|
|
91
|
-
],
|
|
78
|
+
[currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
|
|
92
79
|
{ tokenCurrency: TokenCurrency; operation: Operation }[]
|
|
93
80
|
>(
|
|
94
81
|
async (currency, address, accountId, fromBlock) => {
|
|
@@ -107,15 +94,13 @@ export const getLastTokenOperations = makeLRUCache<
|
|
|
107
94
|
url,
|
|
108
95
|
});
|
|
109
96
|
|
|
110
|
-
return ops
|
|
111
|
-
.map((event) => etherscanERC20EventToOperation(accountId, event))
|
|
112
|
-
.filter(Boolean) as {
|
|
97
|
+
return ops.map(event => etherscanERC20EventToOperation(accountId, event)).filter(Boolean) as {
|
|
113
98
|
tokenCurrency: TokenCurrency;
|
|
114
99
|
operation: Operation;
|
|
115
100
|
}[];
|
|
116
101
|
},
|
|
117
102
|
(currency, address, accountId, fromBlock) => accountId + fromBlock,
|
|
118
|
-
{ ttl: 5 * 1000 }
|
|
103
|
+
{ ttl: 5 * 1000 },
|
|
119
104
|
);
|
|
120
105
|
|
|
121
106
|
export default {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CacheRes } from "@ledgerhq/live-network/cache";
|
|
2
|
+
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { Operation } from "@ledgerhq/types-live";
|
|
4
|
+
import etherscanLikeApi from "./etherscan";
|
|
5
|
+
|
|
6
|
+
type ExplorerApi = {
|
|
7
|
+
getLastCoinOperations: CacheRes<
|
|
8
|
+
[currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
|
|
9
|
+
Operation[]
|
|
10
|
+
>;
|
|
11
|
+
getLastTokenOperations: CacheRes<
|
|
12
|
+
[currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
|
|
13
|
+
{
|
|
14
|
+
tokenCurrency: TokenCurrency;
|
|
15
|
+
operation: Operation;
|
|
16
|
+
}[]
|
|
17
|
+
>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Switch to select one of the compatible explorer
|
|
22
|
+
*/
|
|
23
|
+
export const getExplorerApi = (currency: CryptoCurrency): ExplorerApi => {
|
|
24
|
+
const apiType = currency.ethereumLikeInfo?.explorer?.type;
|
|
25
|
+
|
|
26
|
+
switch (apiType) {
|
|
27
|
+
case "etherscan":
|
|
28
|
+
case "blockscout":
|
|
29
|
+
return etherscanLikeApi;
|
|
30
|
+
|
|
31
|
+
default:
|
|
32
|
+
throw new Error(`No explorer found for currency "${currency.id}"`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { GasOptions } from "../../types";
|
|
3
|
+
import { getGasOptions as ledgerGetGasOptions } from "./ledger";
|
|
4
|
+
|
|
5
|
+
type GasTrackerApi = {
|
|
6
|
+
getGasOptions: ({
|
|
7
|
+
currency,
|
|
8
|
+
options,
|
|
9
|
+
}: {
|
|
10
|
+
currency: CryptoCurrency;
|
|
11
|
+
options?: {
|
|
12
|
+
useEIP1559: boolean;
|
|
13
|
+
};
|
|
14
|
+
}) => Promise<GasOptions>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getGasTracker = (currency: CryptoCurrency): GasTrackerApi | null => {
|
|
18
|
+
switch (currency.ethereumLikeInfo?.gasTracker?.type) {
|
|
19
|
+
case "ledger":
|
|
20
|
+
return {
|
|
21
|
+
getGasOptions: ledgerGetGasOptions,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* We return null instead of throwing an error because not having a gas tracker
|
|
26
|
+
* is not necessarily an error.
|
|
27
|
+
*/
|
|
28
|
+
default:
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
2
|
+
import network from "@ledgerhq/live-network/network";
|
|
3
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
4
|
+
import { BigNumber } from "bignumber.js";
|
|
5
|
+
import { GasOptions } from "../../types";
|
|
6
|
+
import { GasTrackerDoesNotSupportEIP1559, NoGasTrackerFound } from "../../errors";
|
|
7
|
+
|
|
8
|
+
type GasTracker = {
|
|
9
|
+
explorerId: string;
|
|
10
|
+
compatibilty: {
|
|
11
|
+
eip1559: boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// FIXME: how to know if a Ledger gasTracker supports EIP1559?
|
|
16
|
+
// Shouldn't this be a dynamic / remote config? For example if there is an
|
|
17
|
+
// update of the explorer backend to support EIP1559, we should be able to
|
|
18
|
+
// update this config without having to release a new version of the app?
|
|
19
|
+
const currencyIdGasTrackerMap = new Map<CryptoCurrency["id"], GasTracker>([
|
|
20
|
+
["avalanche_c_chain", { explorerId: "avax", compatibilty: { eip1559: false } }],
|
|
21
|
+
["bsc", { explorerId: "bnb", compatibilty: { eip1559: false } }],
|
|
22
|
+
["ethereum", { explorerId: "eth", compatibilty: { eip1559: true } }],
|
|
23
|
+
["ethereum_classic", { explorerId: "etc", compatibilty: { eip1559: false } }],
|
|
24
|
+
["polygon", { explorerId: "matic", compatibilty: { eip1559: true } }],
|
|
25
|
+
["ethereum_ropsten", { explorerId: "eth_ropsten", compatibilty: { eip1559: true } }],
|
|
26
|
+
["ethereum_goerli", { explorerId: "eth_goerli", compatibilty: { eip1559: true } }],
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
export const getGasOptions = async ({
|
|
30
|
+
currency,
|
|
31
|
+
options,
|
|
32
|
+
}: {
|
|
33
|
+
currency: CryptoCurrency;
|
|
34
|
+
options?: {
|
|
35
|
+
useEIP1559: boolean;
|
|
36
|
+
};
|
|
37
|
+
}): Promise<GasOptions> => {
|
|
38
|
+
const gasTrackerConfig = currencyIdGasTrackerMap.get(currency.id);
|
|
39
|
+
|
|
40
|
+
if (!gasTrackerConfig) {
|
|
41
|
+
throw new NoGasTrackerFound(`No gas tracker found for ${currency.id}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { useEIP1559 = false } = options || {};
|
|
45
|
+
|
|
46
|
+
if (useEIP1559 && !gasTrackerConfig.compatibilty.eip1559) {
|
|
47
|
+
throw new GasTrackerDoesNotSupportEIP1559(
|
|
48
|
+
`Gas tracker does not support EIP1559 for ${currency.id}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { low, medium, high, next_base } = await network({
|
|
53
|
+
method: "GET",
|
|
54
|
+
url: `${getEnv("EXPLORER")}/blockchain/v4/${gasTrackerConfig.explorerId}/gastracker/barometer${
|
|
55
|
+
useEIP1559 ? "?display=eip1559" : ""
|
|
56
|
+
}`,
|
|
57
|
+
}).then(({ data }) => ({
|
|
58
|
+
low: new BigNumber(data.low),
|
|
59
|
+
medium: new BigNumber(data.medium),
|
|
60
|
+
high: new BigNumber(data.high),
|
|
61
|
+
next_base: new BigNumber(data.next_base),
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
const EIP1559_BASE_FEE_MULTIPLIER: number = getEnv("EIP1559_BASE_FEE_MULTIPLIER");
|
|
65
|
+
|
|
66
|
+
if (useEIP1559) {
|
|
67
|
+
return {
|
|
68
|
+
slow: {
|
|
69
|
+
maxFeePerGas: next_base.times(EIP1559_BASE_FEE_MULTIPLIER).plus(low),
|
|
70
|
+
maxPriorityFeePerGas: low,
|
|
71
|
+
gasPrice: null,
|
|
72
|
+
},
|
|
73
|
+
medium: {
|
|
74
|
+
maxFeePerGas: next_base.times(EIP1559_BASE_FEE_MULTIPLIER).plus(medium),
|
|
75
|
+
maxPriorityFeePerGas: medium,
|
|
76
|
+
gasPrice: null,
|
|
77
|
+
},
|
|
78
|
+
fast: {
|
|
79
|
+
maxFeePerGas: next_base.times(EIP1559_BASE_FEE_MULTIPLIER).plus(high),
|
|
80
|
+
maxPriorityFeePerGas: high,
|
|
81
|
+
gasPrice: null,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
slow: {
|
|
88
|
+
gasPrice: low,
|
|
89
|
+
maxFeePerGas: null,
|
|
90
|
+
maxPriorityFeePerGas: null,
|
|
91
|
+
},
|
|
92
|
+
medium: {
|
|
93
|
+
gasPrice: medium,
|
|
94
|
+
maxFeePerGas: null,
|
|
95
|
+
maxPriorityFeePerGas: null,
|
|
96
|
+
},
|
|
97
|
+
fast: {
|
|
98
|
+
gasPrice: high,
|
|
99
|
+
maxFeePerGas: null,
|
|
100
|
+
maxPriorityFeePerGas: null,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -6,12 +6,12 @@ import { delay } from "@ledgerhq/live-promise";
|
|
|
6
6
|
import { Account } from "@ledgerhq/types-live";
|
|
7
7
|
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
8
8
|
import { makeLRUCache } from "@ledgerhq/live-network/cache";
|
|
9
|
-
import OptimismGasPriceOracleAbi from "
|
|
10
|
-
import { FeeData, FeeHistory, Transaction as EvmTransaction } from "
|
|
11
|
-
import { GasEstimationError, InsufficientFunds } from "
|
|
12
|
-
import { transactionToEthersTransaction } from "
|
|
13
|
-
import { getSerializedTransaction } from "
|
|
14
|
-
import ERC20Abi from "
|
|
9
|
+
import OptimismGasPriceOracleAbi from "../../abis/optimismGasPriceOracle.abi.json";
|
|
10
|
+
import { FeeData, FeeHistory, Transaction as EvmTransaction } from "../../types";
|
|
11
|
+
import { GasEstimationError, InsufficientFunds } from "../../errors";
|
|
12
|
+
import { transactionToEthersTransaction } from "../../adapters";
|
|
13
|
+
import { getSerializedTransaction } from "../../transaction";
|
|
14
|
+
import ERC20Abi from "../../abis/erc20.abi.json";
|
|
15
15
|
|
|
16
16
|
export const RPC_TIMEOUT = 5000; // wait 5 sec after a fail
|
|
17
17
|
export const DEFAULT_RETRIES_RPC_METHODS = 3;
|
|
@@ -22,8 +22,7 @@ export const DEFAULT_RETRIES_RPC_METHODS = 3;
|
|
|
22
22
|
* at instanciation which could result in rate limits being reached
|
|
23
23
|
* on some specific nodes (E.g. the main Optimism RPC)
|
|
24
24
|
*/
|
|
25
|
-
const PROVIDERS_BY_RPC: Record<string, ethers.providers.StaticJsonRpcProvider> =
|
|
26
|
-
{};
|
|
25
|
+
const PROVIDERS_BY_RPC: Record<string, ethers.providers.StaticJsonRpcProvider> = {};
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* Connects to RPC Node
|
|
@@ -36,7 +35,7 @@ const PROVIDERS_BY_RPC: Record<string, ethers.providers.StaticJsonRpcProvider> =
|
|
|
36
35
|
export async function withApi<T>(
|
|
37
36
|
currency: CryptoCurrency,
|
|
38
37
|
execute: (api: ethers.providers.StaticJsonRpcProvider) => Promise<T>,
|
|
39
|
-
retries = DEFAULT_RETRIES_RPC_METHODS
|
|
38
|
+
retries = DEFAULT_RETRIES_RPC_METHODS,
|
|
40
39
|
): Promise<T> {
|
|
41
40
|
if (!currency?.ethereumLikeInfo?.rpc) {
|
|
42
41
|
throw new Error("Currency doesn't have an RPC node provided");
|
|
@@ -44,10 +43,9 @@ export async function withApi<T>(
|
|
|
44
43
|
|
|
45
44
|
try {
|
|
46
45
|
if (!PROVIDERS_BY_RPC[currency.ethereumLikeInfo.rpc]) {
|
|
47
|
-
PROVIDERS_BY_RPC[currency.ethereumLikeInfo.rpc] =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
46
|
+
PROVIDERS_BY_RPC[currency.ethereumLikeInfo.rpc] = new ethers.providers.StaticJsonRpcProvider(
|
|
47
|
+
currency.ethereumLikeInfo.rpc,
|
|
48
|
+
);
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
const provider = PROVIDERS_BY_RPC[currency.ethereumLikeInfo.rpc];
|
|
@@ -68,12 +66,9 @@ export async function withApi<T>(
|
|
|
68
66
|
*/
|
|
69
67
|
export const getBalanceAndBlock: (
|
|
70
68
|
currency: CryptoCurrency,
|
|
71
|
-
addr: string
|
|
72
|
-
) => Promise<{ blockHeight: number; balance: BigNumber }> = async (
|
|
73
|
-
currency,
|
|
74
|
-
addr
|
|
75
|
-
) =>
|
|
76
|
-
withApi(currency, async (api) => {
|
|
69
|
+
addr: string,
|
|
70
|
+
) => Promise<{ blockHeight: number; balance: BigNumber }> = async (currency, addr) =>
|
|
71
|
+
withApi(currency, async api => {
|
|
77
72
|
const [balance, blockHeight] = await Promise.all([
|
|
78
73
|
getCoinBalance(currency, addr),
|
|
79
74
|
api.getBlockNumber(),
|
|
@@ -90,20 +85,17 @@ export const getBalanceAndBlock: (
|
|
|
90
85
|
*/
|
|
91
86
|
export const getTransaction = (
|
|
92
87
|
currency: CryptoCurrency,
|
|
93
|
-
hash: string
|
|
88
|
+
hash: string,
|
|
94
89
|
): Promise<ethers.providers.TransactionResponse> =>
|
|
95
|
-
withApi(currency,
|
|
90
|
+
withApi(currency, api => {
|
|
96
91
|
return api.getTransaction(hash);
|
|
97
92
|
});
|
|
98
93
|
|
|
99
94
|
/**
|
|
100
95
|
* Get the balance of an address
|
|
101
96
|
*/
|
|
102
|
-
export const getCoinBalance = (
|
|
103
|
-
currency
|
|
104
|
-
address: string
|
|
105
|
-
): Promise<BigNumber> =>
|
|
106
|
-
withApi(currency, async (api) => {
|
|
97
|
+
export const getCoinBalance = (currency: CryptoCurrency, address: string): Promise<BigNumber> =>
|
|
98
|
+
withApi(currency, async api => {
|
|
107
99
|
const balance = await api.getBalance(address);
|
|
108
100
|
return new BigNumber(balance.toString());
|
|
109
101
|
});
|
|
@@ -114,9 +106,9 @@ export const getCoinBalance = (
|
|
|
114
106
|
export const getTokenBalance = (
|
|
115
107
|
currency: CryptoCurrency,
|
|
116
108
|
address: string,
|
|
117
|
-
contractAddress: string
|
|
109
|
+
contractAddress: string,
|
|
118
110
|
): Promise<BigNumber> =>
|
|
119
|
-
withApi(currency, async
|
|
111
|
+
withApi(currency, async api => {
|
|
120
112
|
const erc20 = new ethers.Contract(contractAddress, ERC20Abi, api);
|
|
121
113
|
const balance = await erc20.balanceOf(address);
|
|
122
114
|
return new BigNumber(balance.toString());
|
|
@@ -125,11 +117,8 @@ export const getTokenBalance = (
|
|
|
125
117
|
/**
|
|
126
118
|
* Get account nonce
|
|
127
119
|
*/
|
|
128
|
-
export const getTransactionCount = (
|
|
129
|
-
currency
|
|
130
|
-
addr: string
|
|
131
|
-
): Promise<number> =>
|
|
132
|
-
withApi(currency, async (api) => {
|
|
120
|
+
export const getTransactionCount = (currency: CryptoCurrency, addr: string): Promise<number> =>
|
|
121
|
+
withApi(currency, async api => {
|
|
133
122
|
return api.getTransactionCount(addr);
|
|
134
123
|
});
|
|
135
124
|
|
|
@@ -138,9 +127,9 @@ export const getTransactionCount = (
|
|
|
138
127
|
*/
|
|
139
128
|
export const getGasEstimation = (
|
|
140
129
|
account: Account,
|
|
141
|
-
transaction: EvmTransaction
|
|
130
|
+
transaction: EvmTransaction,
|
|
142
131
|
): Promise<BigNumber> =>
|
|
143
|
-
withApi(account.currency, async
|
|
132
|
+
withApi(account.currency, async api => {
|
|
144
133
|
const { to, value, data } = transactionToEthersTransaction(transaction);
|
|
145
134
|
|
|
146
135
|
try {
|
|
@@ -162,7 +151,7 @@ export const getGasEstimation = (
|
|
|
162
151
|
* Get an estimation of fees on the network
|
|
163
152
|
*/
|
|
164
153
|
export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
|
|
165
|
-
withApi(currency, async
|
|
154
|
+
withApi(currency, async api => {
|
|
166
155
|
const block = await api.getBlock("latest");
|
|
167
156
|
const currencySupports1559 = Boolean(block.baseFeePerGas);
|
|
168
157
|
|
|
@@ -175,10 +164,7 @@ export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
|
|
|
175
164
|
]);
|
|
176
165
|
// Taking the average priority fee used on the last 5 blocks
|
|
177
166
|
const maxPriorityFeeAverage = feeHistory.reward
|
|
178
|
-
.reduce(
|
|
179
|
-
(acc, [curr]) => acc.plus(new BigNumber(curr)),
|
|
180
|
-
new BigNumber(0)
|
|
181
|
-
)
|
|
167
|
+
.reduce((acc, [curr]) => acc.plus(new BigNumber(curr)), new BigNumber(0))
|
|
182
168
|
.dividedToIntegerBy(feeHistory.reward.length);
|
|
183
169
|
|
|
184
170
|
// A maxPriorityFeePerGas too low might make a transaction stuck forever
|
|
@@ -189,7 +175,7 @@ export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
|
|
|
189
175
|
: maxPriorityFeeAverage;
|
|
190
176
|
|
|
191
177
|
const nextBaseFee = new BigNumber(
|
|
192
|
-
feeHistory.baseFeePerGas[feeHistory.baseFeePerGas.length - 1]
|
|
178
|
+
feeHistory.baseFeePerGas[feeHistory.baseFeePerGas.length - 1],
|
|
193
179
|
);
|
|
194
180
|
|
|
195
181
|
return {
|
|
@@ -206,15 +192,11 @@ export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
|
|
|
206
192
|
})();
|
|
207
193
|
|
|
208
194
|
return {
|
|
209
|
-
maxFeePerGas: feeData.maxFeePerGas
|
|
210
|
-
? new BigNumber(feeData.maxFeePerGas.toString())
|
|
211
|
-
: null,
|
|
195
|
+
maxFeePerGas: feeData.maxFeePerGas ? new BigNumber(feeData.maxFeePerGas.toString()) : null,
|
|
212
196
|
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas
|
|
213
197
|
? new BigNumber(feeData.maxPriorityFeePerGas.toString())
|
|
214
198
|
: null,
|
|
215
|
-
gasPrice: feeData.gasPrice
|
|
216
|
-
? new BigNumber(feeData.gasPrice.toString())
|
|
217
|
-
: null,
|
|
199
|
+
gasPrice: feeData.gasPrice ? new BigNumber(feeData.gasPrice.toString()) : null,
|
|
218
200
|
};
|
|
219
201
|
});
|
|
220
202
|
|
|
@@ -223,11 +205,11 @@ export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
|
|
|
223
205
|
*/
|
|
224
206
|
export const broadcastTransaction = (
|
|
225
207
|
currency: CryptoCurrency,
|
|
226
|
-
signedTxHex: string
|
|
208
|
+
signedTxHex: string,
|
|
227
209
|
): Promise<ethers.providers.TransactionResponse> =>
|
|
228
210
|
withApi(
|
|
229
211
|
currency,
|
|
230
|
-
async
|
|
212
|
+
async api => {
|
|
231
213
|
try {
|
|
232
214
|
return await api.sendTransaction(signedTxHex);
|
|
233
215
|
} catch (e) {
|
|
@@ -238,7 +220,7 @@ export const broadcastTransaction = (
|
|
|
238
220
|
throw e;
|
|
239
221
|
}
|
|
240
222
|
},
|
|
241
|
-
0
|
|
223
|
+
0,
|
|
242
224
|
);
|
|
243
225
|
|
|
244
226
|
/**
|
|
@@ -246,9 +228,9 @@ export const broadcastTransaction = (
|
|
|
246
228
|
*/
|
|
247
229
|
export const getBlock = (
|
|
248
230
|
currency: CryptoCurrency,
|
|
249
|
-
blockHeight: number
|
|
231
|
+
blockHeight: number,
|
|
250
232
|
): Promise<ethers.providers.Block> =>
|
|
251
|
-
withApi(currency, async
|
|
233
|
+
withApi(currency, async api => {
|
|
252
234
|
return api.getBlock(blockHeight);
|
|
253
235
|
});
|
|
254
236
|
|
|
@@ -257,13 +239,13 @@ export const getBlock = (
|
|
|
257
239
|
*/
|
|
258
240
|
export const getSubAccount: (
|
|
259
241
|
currency: CryptoCurrency,
|
|
260
|
-
addr: string
|
|
242
|
+
addr: string,
|
|
261
243
|
) => Promise<{
|
|
262
244
|
blockHeight: number;
|
|
263
245
|
balance: BigNumber;
|
|
264
246
|
nonce: number;
|
|
265
247
|
}> = async (currency, addr) =>
|
|
266
|
-
withApi(currency, async
|
|
248
|
+
withApi(currency, async api => {
|
|
267
249
|
const [balance, nonce, blockHeight] = await Promise.all([
|
|
268
250
|
getCoinBalance(currency, addr),
|
|
269
251
|
getTransactionCount(currency, addr),
|
|
@@ -286,12 +268,9 @@ export const getSubAccount: (
|
|
|
286
268
|
*
|
|
287
269
|
* @see https://help.optimism.io/hc/en-us/articles/4411895794715-How-do-transaction-fees-on-Optimism-work-
|
|
288
270
|
*/
|
|
289
|
-
export const getOptimismAdditionalFees = makeLRUCache<
|
|
290
|
-
[CryptoCurrency, EvmTransaction],
|
|
291
|
-
BigNumber
|
|
292
|
-
>(
|
|
271
|
+
export const getOptimismAdditionalFees = makeLRUCache<[CryptoCurrency, EvmTransaction], BigNumber>(
|
|
293
272
|
async (currency, transaction) =>
|
|
294
|
-
withApi(currency, async
|
|
273
|
+
withApi(currency, async api => {
|
|
295
274
|
if (!["optimism", "optimism_goerli"].includes(currency.id)) {
|
|
296
275
|
return new BigNumber(0);
|
|
297
276
|
}
|
|
@@ -317,11 +296,9 @@ export const getOptimismAdditionalFees = makeLRUCache<
|
|
|
317
296
|
// @see https://community.optimism.io/docs/developers/build/transaction-fees/#displaying-fees-to-users
|
|
318
297
|
"0x420000000000000000000000000000000000000F",
|
|
319
298
|
OptimismGasPriceOracleAbi,
|
|
320
|
-
api
|
|
321
|
-
);
|
|
322
|
-
const additionalL1Fees = await optimismGasOracle.getL1Fee(
|
|
323
|
-
serializedTransaction
|
|
299
|
+
api,
|
|
324
300
|
);
|
|
301
|
+
const additionalL1Fees = await optimismGasOracle.getL1Fee(serializedTransaction);
|
|
325
302
|
return new BigNumber(additionalL1Fees.toString());
|
|
326
303
|
}),
|
|
327
304
|
(currency, transaction) => {
|
|
@@ -335,7 +312,7 @@ export const getOptimismAdditionalFees = makeLRUCache<
|
|
|
335
312
|
|
|
336
313
|
return "getOptimismL1BaseFee_" + currency.id + "_" + serializedTransaction;
|
|
337
314
|
},
|
|
338
|
-
{ ttl: 15 * 1000 } // preventing rate limit by caching this for at least 15sec
|
|
315
|
+
{ ttl: 15 * 1000 }, // preventing rate limit by caching this for at least 15sec
|
|
339
316
|
);
|
|
340
317
|
|
|
341
318
|
export default {
|