@ledgerhq/coin-evm 0.3.0 → 0.4.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/CHANGELOG.md +31 -0
- package/jest.config.js +4 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts +9 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
- package/lib/{testUtils.js → __tests__/fixtures/common.fixtures.js} +40 -9
- package/lib/__tests__/fixtures/common.fixtures.js.map +1 -0
- package/lib/__tests__/fixtures/etherscan.fixtures.d.ts +86 -0
- package/lib/__tests__/fixtures/etherscan.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/etherscan.fixtures.js +267 -0
- package/lib/__tests__/fixtures/etherscan.fixtures.js.map +1 -0
- package/lib/__tests__/fixtures/prepareTransaction.fixtures.d.ts +10 -0
- package/lib/__tests__/fixtures/prepareTransaction.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/prepareTransaction.fixtures.js +69 -0
- package/lib/__tests__/fixtures/prepareTransaction.fixtures.js.map +1 -0
- package/lib/__tests__/fixtures/synchronization.fixtures.d.ts +44 -0
- package/lib/__tests__/fixtures/synchronization.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/synchronization.fixtures.js +219 -0
- package/lib/__tests__/fixtures/synchronization.fixtures.js.map +1 -0
- package/lib/__tests__/fixtures/transaction.fixtures.d.ts +47 -0
- package/lib/__tests__/fixtures/transaction.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/transaction.fixtures.js +182 -0
- package/lib/__tests__/fixtures/transaction.fixtures.js.map +1 -0
- package/lib/__tests__/integration/bridge.integration.test.d.ts +7 -0
- package/lib/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
- package/lib/__tests__/integration/bridge.integration.test.js +74 -0
- package/lib/__tests__/integration/bridge.integration.test.js.map +1 -0
- package/lib/__tests__/unit/adapters.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/adapters.unit.test.js +989 -0
- package/lib/__tests__/unit/adapters.unit.test.js.map +1 -0
- package/lib/__tests__/unit/api/explorer/etherscan.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/api/explorer/etherscan.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/api/explorer/etherscan.unit.test.js +430 -0
- package/lib/__tests__/unit/api/explorer/etherscan.unit.test.js.map +1 -0
- package/lib/__tests__/unit/api/explorer/index.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/api/explorer/index.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/api/explorer/index.unit.test.js +49 -0
- package/lib/__tests__/unit/api/explorer/index.unit.test.js.map +1 -0
- package/lib/__tests__/unit/api/gasTracker/index.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/api/gasTracker/index.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{gasTracker → unit/api/gasTracker}/index.unit.test.js +3 -3
- package/lib/__tests__/unit/api/gasTracker/index.unit.test.js.map +1 -0
- package/lib/__tests__/unit/api/gasTracker/ledger.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{gasTracker → unit/api/gasTracker}/ledger.unit.test.js +2 -2
- package/lib/__tests__/unit/api/gasTracker/ledger.unit.test.js.map +1 -0
- package/lib/__tests__/unit/api/rpc/rpc.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{rpc.unit.test.js → unit/api/rpc/rpc.unit.test.js} +14 -14
- package/lib/__tests__/unit/api/rpc/rpc.unit.test.js.map +1 -0
- package/lib/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/broadcast.unit.test.js +335 -0
- package/lib/__tests__/unit/broadcast.unit.test.js.map +1 -0
- package/lib/__tests__/unit/buildOptimisticOperation.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{buildOptimisticOperation.unit.test.js → unit/buildOptimisticOperation.unit.test.js} +132 -6
- package/lib/__tests__/unit/buildOptimisticOperation.unit.test.js.map +1 -0
- package/lib/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{createTransaction.unit.test.js → unit/createTransaction.unit.test.js} +5 -5
- package/lib/__tests__/unit/createTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{deviceTransactionConfig.unit.test.js → unit/deviceTransactionConfig.unit.test.js} +123 -6
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{estimateMaxSpendable.unit.test.js → unit/estimateMaxSpendable.unit.test.js} +6 -6
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{getTransactionStatus.unit.test.js → unit/getTransactionStatus.unit.test.js} +76 -6
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{hw-getAddress.unit.test.js → unit/hw-getAddress.unit.test.js} +5 -1
- package/lib/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
- package/lib/__tests__/unit/hw-signMessage.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/hw-signMessage.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/hw-signMessage.unit.test.js +188 -0
- package/lib/__tests__/unit/hw-signMessage.unit.test.js.map +1 -0
- package/lib/__tests__/unit/logic.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{logic.unit.test.js → unit/logic.unit.test.js} +111 -20
- package/lib/__tests__/unit/logic.unit.test.js.map +1 -0
- package/lib/__tests__/unit/nftResolvers.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/nftResolvers.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/nftResolvers.unit.test.js +163 -0
- package/lib/__tests__/unit/nftResolvers.unit.test.js.map +1 -0
- package/lib/__tests__/unit/preload.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{preload.unit.test.js → unit/preload.unit.test.js} +3 -3
- package/lib/__tests__/unit/preload.unit.test.js.map +1 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.js +300 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{signOperation.unit.test.js → unit/signOperation.unit.test.js} +14 -17
- package/lib/__tests__/unit/signOperation.unit.test.js.map +1 -0
- package/lib/__tests__/unit/synchronization.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{synchronization.unit.test.js → unit/synchronization.unit.test.js} +139 -231
- package/lib/__tests__/unit/synchronization.unit.test.js.map +1 -0
- package/lib/__tests__/unit/transaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/{transaction.unit.test.js → unit/transaction.unit.test.js} +48 -80
- package/lib/__tests__/unit/transaction.unit.test.js.map +1 -0
- package/lib/abis/erc1155.abi.json +314 -0
- package/lib/abis/erc721.abi.json +346 -0
- package/lib/adapters.d.ts +18 -7
- package/lib/adapters.d.ts.map +1 -1
- package/lib/adapters.js +131 -46
- package/lib/adapters.js.map +1 -1
- package/lib/api/explorer/etherscan.d.ts +39 -11
- package/lib/api/explorer/etherscan.d.ts.map +1 -1
- package/lib/api/explorer/etherscan.js +151 -9
- package/lib/api/explorer/etherscan.js.map +1 -1
- package/lib/api/explorer/index.d.ts +7 -16
- package/lib/api/explorer/index.d.ts.map +1 -1
- package/lib/api/explorer/index.js.map +1 -1
- package/lib/api/nft/index.d.ts +24 -0
- package/lib/api/nft/index.d.ts.map +1 -0
- package/lib/api/nft/index.js +54 -0
- package/lib/api/nft/index.js.map +1 -0
- package/lib/api/rpc/index.native.d.ts.map +1 -1
- package/lib/api/rpc/index.native.js +1 -0
- package/lib/api/rpc/index.native.js.map +1 -1
- package/lib/api/rpc/rpc.common.d.ts +2 -2
- package/lib/api/rpc/rpc.common.d.ts.map +1 -1
- package/lib/api/rpc/rpc.common.js +3 -3
- package/lib/api/rpc/rpc.common.js.map +1 -1
- package/lib/bridge/js.d.ts +1 -1
- package/lib/bridge/js.d.ts.map +1 -1
- package/lib/bridge/js.js +10 -10
- package/lib/bridge/js.js.map +1 -1
- package/lib/broadcast.d.ts.map +1 -1
- package/lib/broadcast.js +9 -2
- package/lib/broadcast.js.map +1 -1
- package/lib/buildOptimisticOperation.d.ts +5 -1
- package/lib/buildOptimisticOperation.d.ts.map +1 -1
- package/lib/buildOptimisticOperation.js +46 -4
- package/lib/buildOptimisticOperation.js.map +1 -1
- package/lib/cli-transaction.d.ts.map +1 -1
- package/lib/cli-transaction.js +1 -0
- package/lib/cli-transaction.js.map +1 -1
- package/lib/datasets/ethereum1.d.ts.map +1 -1
- package/lib/datasets/ethereum1.js +3 -2
- package/lib/datasets/ethereum1.js.map +1 -1
- package/lib/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/deviceTransactionConfig.js +50 -0
- package/lib/deviceTransactionConfig.js.map +1 -1
- package/lib/errors.d.ts +9 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +7 -1
- package/lib/errors.js.map +1 -1
- package/lib/getTransactionStatus.d.ts +1 -0
- package/lib/getTransactionStatus.d.ts.map +1 -1
- package/lib/getTransactionStatus.js +25 -3
- package/lib/getTransactionStatus.js.map +1 -1
- package/lib/hw-signMessage.d.ts +15 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +86 -0
- package/lib/hw-signMessage.js.map +1 -0
- package/lib/logic.d.ts +63 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/logic.js +98 -2
- package/lib/logic.js.map +1 -1
- package/lib/nftResolvers.d.ts +19 -0
- package/lib/nftResolvers.d.ts.map +1 -0
- package/lib/nftResolvers.js +58 -0
- package/lib/nftResolvers.js.map +1 -0
- package/lib/preload.d.ts.map +1 -1
- package/lib/preload.js +7 -3
- package/lib/preload.js.map +1 -1
- package/lib/prepareTransaction.d.ts +6 -1
- package/lib/prepareTransaction.d.ts.map +1 -1
- package/lib/prepareTransaction.js +69 -18
- package/lib/prepareTransaction.js.map +1 -1
- package/lib/signOperation.d.ts +1 -1
- package/lib/signOperation.d.ts.map +1 -1
- package/lib/signOperation.js +17 -6
- package/lib/signOperation.js.map +1 -1
- package/lib/signer.d.ts +24 -1
- package/lib/signer.d.ts.map +1 -1
- package/lib/specs.d.ts +3 -1
- package/lib/specs.d.ts.map +1 -1
- package/lib/specs.js +3 -3
- package/lib/specs.js.map +1 -1
- package/lib/speculos-deviceActions.d.ts.map +1 -1
- package/lib/speculos-deviceActions.js +2 -1
- package/lib/speculos-deviceActions.js.map +1 -1
- package/lib/synchronization.d.ts +7 -2
- package/lib/synchronization.d.ts.map +1 -1
- package/lib/synchronization.js +45 -45
- package/lib/synchronization.js.map +1 -1
- package/lib/transaction.d.ts +3 -4
- package/lib/transaction.d.ts.map +1 -1
- package/lib/transaction.js +58 -12
- package/lib/transaction.js.map +1 -1
- package/lib/types.d.ts +85 -10
- package/lib/types.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts +9 -0
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
- package/lib-es/{testUtils.js → __tests__/fixtures/common.fixtures.js} +36 -8
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -0
- package/lib-es/__tests__/fixtures/etherscan.fixtures.d.ts +86 -0
- package/lib-es/__tests__/fixtures/etherscan.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/etherscan.fixtures.js +264 -0
- package/lib-es/__tests__/fixtures/etherscan.fixtures.js.map +1 -0
- package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.d.ts +10 -0
- package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.js +62 -0
- package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.js.map +1 -0
- package/lib-es/__tests__/fixtures/synchronization.fixtures.d.ts +44 -0
- package/lib-es/__tests__/fixtures/synchronization.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/synchronization.fixtures.js +190 -0
- package/lib-es/__tests__/fixtures/synchronization.fixtures.js.map +1 -0
- package/lib-es/__tests__/fixtures/transaction.fixtures.d.ts +47 -0
- package/lib-es/__tests__/fixtures/transaction.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/transaction.fixtures.js +176 -0
- package/lib-es/__tests__/fixtures/transaction.fixtures.js.map +1 -0
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts +7 -0
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/__tests__/integration/bridge.integration.test.js +71 -0
- package/lib-es/__tests__/integration/bridge.integration.test.js.map +1 -0
- package/lib-es/__tests__/unit/adapters.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/adapters.unit.test.js +984 -0
- package/lib-es/__tests__/unit/adapters.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/api/explorer/etherscan.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/api/explorer/etherscan.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/api/explorer/etherscan.unit.test.js +402 -0
- package/lib-es/__tests__/unit/api/explorer/etherscan.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/api/explorer/index.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/api/explorer/index.unit.test.js +44 -0
- package/lib-es/__tests__/unit/api/explorer/index.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/api/gasTracker/index.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{gasTracker → unit/api/gasTracker}/index.unit.test.js +3 -3
- package/lib-es/__tests__/unit/api/gasTracker/index.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/api/gasTracker/ledger.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{gasTracker → unit/api/gasTracker}/ledger.unit.test.js +2 -2
- package/lib-es/__tests__/unit/api/gasTracker/ledger.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/api/rpc/rpc.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{rpc.unit.test.js → unit/api/rpc/rpc.unit.test.js} +13 -13
- package/lib-es/__tests__/unit/api/rpc/rpc.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.js +307 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/buildOptimisticOperation.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{buildOptimisticOperation.unit.test.js → unit/buildOptimisticOperation.unit.test.js} +130 -4
- package/lib-es/__tests__/unit/buildOptimisticOperation.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{createTransaction.unit.test.js → unit/createTransaction.unit.test.js} +3 -3
- package/lib-es/__tests__/unit/createTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{deviceTransactionConfig.unit.test.js → unit/deviceTransactionConfig.unit.test.js} +121 -4
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{estimateMaxSpendable.unit.test.js → unit/estimateMaxSpendable.unit.test.js} +4 -4
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{getTransactionStatus.unit.test.js → unit/getTransactionStatus.unit.test.js} +74 -4
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{hw-getAddress.unit.test.js → unit/hw-getAddress.unit.test.js} +5 -1
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/hw-signMessage.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/hw-signMessage.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/hw-signMessage.unit.test.js +186 -0
- package/lib-es/__tests__/unit/hw-signMessage.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/logic.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{logic.unit.test.js → unit/logic.unit.test.js} +97 -6
- package/lib-es/__tests__/unit/logic.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/nftResolvers.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/nftResolvers.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/nftResolvers.unit.test.js +158 -0
- package/lib-es/__tests__/unit/nftResolvers.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/preload.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{preload.unit.test.js → unit/preload.unit.test.js} +3 -3
- package/lib-es/__tests__/unit/preload.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{prepareTransaction.unit.test.js → unit/prepareTransaction.unit.test.js} +134 -82
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{signOperation.unit.test.js → unit/signOperation.unit.test.js} +13 -16
- package/lib-es/__tests__/unit/signOperation.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/synchronization.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{synchronization.unit.test.js → unit/synchronization.unit.test.js} +115 -207
- package/lib-es/__tests__/unit/synchronization.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/transaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/{transaction.unit.test.js → unit/transaction.unit.test.js} +40 -72
- package/lib-es/__tests__/unit/transaction.unit.test.js.map +1 -0
- package/lib-es/abis/erc1155.abi.json +314 -0
- package/lib-es/abis/erc721.abi.json +346 -0
- package/lib-es/adapters.d.ts +18 -7
- package/lib-es/adapters.d.ts.map +1 -1
- package/lib-es/adapters.js +127 -44
- package/lib-es/adapters.js.map +1 -1
- package/lib-es/api/explorer/etherscan.d.ts +39 -11
- package/lib-es/api/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/api/explorer/etherscan.js +146 -10
- package/lib-es/api/explorer/etherscan.js.map +1 -1
- package/lib-es/api/explorer/index.d.ts +7 -16
- package/lib-es/api/explorer/index.d.ts.map +1 -1
- package/lib-es/api/explorer/index.js.map +1 -1
- package/lib-es/api/nft/index.d.ts +24 -0
- package/lib-es/api/nft/index.d.ts.map +1 -0
- package/lib-es/api/nft/index.js +46 -0
- package/lib-es/api/nft/index.js.map +1 -0
- package/lib-es/api/rpc/index.native.d.ts.map +1 -1
- package/lib-es/api/rpc/index.native.js +1 -0
- package/lib-es/api/rpc/index.native.js.map +1 -1
- package/lib-es/api/rpc/rpc.common.d.ts +2 -2
- package/lib-es/api/rpc/rpc.common.d.ts.map +1 -1
- package/lib-es/api/rpc/rpc.common.js +3 -3
- package/lib-es/api/rpc/rpc.common.js.map +1 -1
- package/lib-es/bridge/js.d.ts +1 -1
- package/lib-es/bridge/js.d.ts.map +1 -1
- package/lib-es/bridge/js.js +10 -10
- package/lib-es/bridge/js.js.map +1 -1
- package/lib-es/broadcast.d.ts.map +1 -1
- package/lib-es/broadcast.js +9 -2
- package/lib-es/broadcast.js.map +1 -1
- package/lib-es/buildOptimisticOperation.d.ts +5 -1
- package/lib-es/buildOptimisticOperation.d.ts.map +1 -1
- package/lib-es/buildOptimisticOperation.js +45 -4
- package/lib-es/buildOptimisticOperation.js.map +1 -1
- package/lib-es/cli-transaction.d.ts.map +1 -1
- package/lib-es/cli-transaction.js +1 -0
- package/lib-es/cli-transaction.js.map +1 -1
- package/lib-es/datasets/ethereum1.d.ts.map +1 -1
- package/lib-es/datasets/ethereum1.js +3 -2
- package/lib-es/datasets/ethereum1.js.map +1 -1
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/deviceTransactionConfig.js +50 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -1
- package/lib-es/errors.d.ts +9 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +6 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/getTransactionStatus.d.ts +1 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/getTransactionStatus.js +23 -2
- package/lib-es/getTransactionStatus.js.map +1 -1
- package/lib-es/hw-signMessage.d.ts +15 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +81 -0
- package/lib-es/hw-signMessage.js.map +1 -0
- package/lib-es/logic.d.ts +63 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/logic.js +95 -1
- package/lib-es/logic.js.map +1 -1
- package/lib-es/nftResolvers.d.ts +19 -0
- package/lib-es/nftResolvers.d.ts.map +1 -0
- package/lib-es/nftResolvers.js +50 -0
- package/lib-es/nftResolvers.js.map +1 -0
- package/lib-es/preload.d.ts.map +1 -1
- package/lib-es/preload.js +7 -3
- package/lib-es/preload.js.map +1 -1
- package/lib-es/prepareTransaction.d.ts +6 -1
- package/lib-es/prepareTransaction.d.ts.map +1 -1
- package/lib-es/prepareTransaction.js +68 -18
- package/lib-es/prepareTransaction.js.map +1 -1
- package/lib-es/signOperation.d.ts +1 -1
- package/lib-es/signOperation.d.ts.map +1 -1
- package/lib-es/signOperation.js +17 -6
- package/lib-es/signOperation.js.map +1 -1
- package/lib-es/signer.d.ts +24 -1
- package/lib-es/signer.d.ts.map +1 -1
- package/lib-es/specs.d.ts +3 -1
- package/lib-es/specs.d.ts.map +1 -1
- package/lib-es/specs.js +3 -3
- package/lib-es/specs.js.map +1 -1
- package/lib-es/speculos-deviceActions.d.ts.map +1 -1
- package/lib-es/speculos-deviceActions.js +2 -1
- package/lib-es/speculos-deviceActions.js.map +1 -1
- package/lib-es/synchronization.d.ts +7 -2
- package/lib-es/synchronization.d.ts.map +1 -1
- package/lib-es/synchronization.js +46 -46
- package/lib-es/synchronization.js.map +1 -1
- package/lib-es/transaction.d.ts +3 -4
- package/lib-es/transaction.d.ts.map +1 -1
- package/lib-es/transaction.js +58 -12
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/types.d.ts +85 -10
- package/lib-es/types.d.ts.map +1 -1
- package/package.json +13 -12
- package/src/{testUtils.ts → __tests__/fixtures/common.fixtures.ts} +78 -11
- package/src/__tests__/fixtures/etherscan.fixtures.ts +266 -0
- package/src/__tests__/fixtures/prepareTransaction.fixtures.ts +86 -0
- package/src/__tests__/fixtures/synchronization.fixtures.ts +229 -0
- package/src/__tests__/fixtures/transaction.fixtures.ts +229 -0
- package/src/__tests__/integration/bridge.integration.test.ts +74 -0
- package/src/__tests__/unit/adapters.unit.test.ts +1076 -0
- package/src/__tests__/unit/api/explorer/etherscan.unit.test.ts +563 -0
- package/src/__tests__/unit/api/explorer/index.unit.test.ts +36 -0
- package/src/__tests__/{gasTracker → unit/api/gasTracker}/index.unit.test.ts +3 -3
- package/src/__tests__/{gasTracker → unit/api/gasTracker}/ledger.unit.test.ts +3 -3
- package/src/__tests__/{rpc.unit.test.ts → unit/api/rpc/rpc.unit.test.ts} +17 -14
- package/src/__tests__/unit/broadcast.unit.test.ts +332 -0
- package/src/__tests__/{buildOptimisticOperation.unit.test.ts → unit/buildOptimisticOperation.unit.test.ts} +144 -5
- package/src/__tests__/{createTransaction.unit.test.ts → unit/createTransaction.unit.test.ts} +4 -4
- package/src/__tests__/{deviceTransactionConfig.unit.test.ts → unit/deviceTransactionConfig.unit.test.ts} +130 -5
- package/src/__tests__/{estimateMaxSpendable.unit.test.ts → unit/estimateMaxSpendable.unit.test.ts} +5 -5
- package/src/__tests__/{getTransactionStatus.unit.test.ts → unit/getTransactionStatus.unit.test.ts} +121 -5
- package/src/__tests__/{hw-getAddress.unit.test.ts → unit/hw-getAddress.unit.test.ts} +6 -2
- package/src/__tests__/unit/hw-signMessage.unit.test.ts +192 -0
- package/src/__tests__/{logic.unit.test.ts → unit/logic.unit.test.ts} +143 -8
- package/src/__tests__/unit/nftResolvers.unit.test.ts +179 -0
- package/src/__tests__/{preload.unit.test.ts → unit/preload.unit.test.ts} +4 -4
- package/src/__tests__/{prepareTransaction.unit.test.ts → unit/prepareTransaction.unit.test.ts} +284 -109
- package/src/__tests__/{signOperation.unit.test.ts → unit/signOperation.unit.test.ts} +18 -20
- package/src/__tests__/{synchronization.unit.test.ts → unit/synchronization.unit.test.ts} +202 -280
- package/src/__tests__/unit/transaction.unit.test.ts +198 -0
- package/src/abis/erc1155.abi.json +314 -0
- package/src/abis/erc20.abi.json +4 -12
- package/src/abis/erc721.abi.json +346 -0
- package/src/adapters.ts +177 -64
- package/src/api/explorer/etherscan.ts +265 -49
- package/src/api/explorer/index.ts +24 -10
- package/src/api/nft/index.ts +49 -0
- package/src/api/rpc/index.native.ts +2 -0
- package/src/api/rpc/rpc.common.ts +3 -3
- package/src/bridge/js.ts +13 -16
- package/src/broadcast.ts +29 -2
- package/src/buildOptimisticOperation.ts +71 -6
- package/src/cli-transaction.ts +2 -0
- package/src/datasets/ethereum1.ts +4 -2
- package/src/deviceTransactionConfig.ts +65 -0
- package/src/errors.ts +8 -0
- package/src/getTransactionStatus.ts +26 -0
- package/src/hw-signMessage.ts +92 -0
- package/src/logic.ts +118 -2
- package/src/nftResolvers.ts +71 -0
- package/src/preload.ts +9 -3
- package/src/prepareTransaction.ts +102 -24
- package/src/signOperation.ts +21 -8
- package/src/signer.ts +44 -1
- package/src/specs.ts +11 -6
- package/src/speculos-deviceActions.ts +3 -1
- package/src/synchronization.ts +73 -59
- package/src/transaction.ts +68 -15
- package/src/types.ts +108 -10
- package/.eslintrc.js +0 -22
- package/lib/__tests__/adapters.unit.test.d.ts.map +0 -1
- package/lib/__tests__/adapters.unit.test.js +0 -455
- package/lib/__tests__/adapters.unit.test.js.map +0 -1
- package/lib/__tests__/broadcast.unit.test.d.ts.map +0 -1
- package/lib/__tests__/broadcast.unit.test.js +0 -181
- package/lib/__tests__/broadcast.unit.test.js.map +0 -1
- package/lib/__tests__/buildOptimisticOperation.unit.test.d.ts.map +0 -1
- package/lib/__tests__/buildOptimisticOperation.unit.test.js.map +0 -1
- package/lib/__tests__/createTransaction.unit.test.d.ts.map +0 -1
- package/lib/__tests__/createTransaction.unit.test.js.map +0 -1
- package/lib/__tests__/deviceTransactionConfig.unit.test.d.ts.map +0 -1
- package/lib/__tests__/deviceTransactionConfig.unit.test.js.map +0 -1
- package/lib/__tests__/estimateMaxSpendable.unit.test.d.ts.map +0 -1
- package/lib/__tests__/estimateMaxSpendable.unit.test.js.map +0 -1
- package/lib/__tests__/gasTracker/index.unit.test.d.ts.map +0 -1
- package/lib/__tests__/gasTracker/index.unit.test.js.map +0 -1
- package/lib/__tests__/gasTracker/ledger.unit.test.d.ts.map +0 -1
- package/lib/__tests__/gasTracker/ledger.unit.test.js.map +0 -1
- package/lib/__tests__/getTransactionStatus.unit.test.d.ts.map +0 -1
- package/lib/__tests__/getTransactionStatus.unit.test.js.map +0 -1
- package/lib/__tests__/hw-getAddress.unit.test.d.ts.map +0 -1
- package/lib/__tests__/hw-getAddress.unit.test.js.map +0 -1
- package/lib/__tests__/logic.unit.test.d.ts.map +0 -1
- package/lib/__tests__/logic.unit.test.js.map +0 -1
- package/lib/__tests__/preload.unit.test.d.ts.map +0 -1
- package/lib/__tests__/preload.unit.test.js.map +0 -1
- package/lib/__tests__/prepareTransaction.unit.test.d.ts.map +0 -1
- package/lib/__tests__/prepareTransaction.unit.test.js +0 -248
- package/lib/__tests__/prepareTransaction.unit.test.js.map +0 -1
- package/lib/__tests__/rpc.unit.test.d.ts.map +0 -1
- package/lib/__tests__/rpc.unit.test.js.map +0 -1
- package/lib/__tests__/signOperation.unit.test.d.ts.map +0 -1
- package/lib/__tests__/signOperation.unit.test.js.map +0 -1
- package/lib/__tests__/synchronization.unit.test.d.ts.map +0 -1
- package/lib/__tests__/synchronization.unit.test.js.map +0 -1
- package/lib/__tests__/transaction.unit.test.d.ts.map +0 -1
- package/lib/__tests__/transaction.unit.test.js.map +0 -1
- package/lib/bridge.integration.test.d.ts +0 -14
- package/lib/bridge.integration.test.d.ts.map +0 -1
- package/lib/bridge.integration.test.js +0 -85
- package/lib/bridge.integration.test.js.map +0 -1
- package/lib/datasets/ethereum.scanAccounts.1.d.ts +0 -7
- package/lib/datasets/ethereum.scanAccounts.1.d.ts.map +0 -1
- package/lib/datasets/ethereum.scanAccounts.1.js +0 -51
- package/lib/datasets/ethereum.scanAccounts.1.js.map +0 -1
- package/lib/datasets/ethereum2.d.ts +0 -3
- package/lib/datasets/ethereum2.d.ts.map +0 -1
- package/lib/datasets/ethereum2.js +0 -22
- package/lib/datasets/ethereum2.js.map +0 -1
- package/lib/datasets/ethereum_classic.d.ts +0 -5
- package/lib/datasets/ethereum_classic.d.ts.map +0 -1
- package/lib/datasets/ethereum_classic.js +0 -69
- package/lib/datasets/ethereum_classic.js.map +0 -1
- package/lib/testUtils.d.ts +0 -6
- package/lib/testUtils.d.ts.map +0 -1
- package/lib/testUtils.js.map +0 -1
- package/lib-es/__tests__/adapters.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/adapters.unit.test.js +0 -450
- package/lib-es/__tests__/adapters.unit.test.js.map +0 -1
- package/lib-es/__tests__/broadcast.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/broadcast.unit.test.js +0 -153
- package/lib-es/__tests__/broadcast.unit.test.js.map +0 -1
- package/lib-es/__tests__/buildOptimisticOperation.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/buildOptimisticOperation.unit.test.js.map +0 -1
- package/lib-es/__tests__/createTransaction.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/createTransaction.unit.test.js.map +0 -1
- package/lib-es/__tests__/deviceTransactionConfig.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/deviceTransactionConfig.unit.test.js.map +0 -1
- package/lib-es/__tests__/estimateMaxSpendable.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/estimateMaxSpendable.unit.test.js.map +0 -1
- package/lib-es/__tests__/gasTracker/index.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/gasTracker/index.unit.test.js.map +0 -1
- package/lib-es/__tests__/gasTracker/ledger.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/gasTracker/ledger.unit.test.js.map +0 -1
- package/lib-es/__tests__/getTransactionStatus.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/getTransactionStatus.unit.test.js.map +0 -1
- package/lib-es/__tests__/hw-getAddress.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/hw-getAddress.unit.test.js.map +0 -1
- package/lib-es/__tests__/logic.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/logic.unit.test.js.map +0 -1
- package/lib-es/__tests__/preload.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/preload.unit.test.js.map +0 -1
- package/lib-es/__tests__/prepareTransaction.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/prepareTransaction.unit.test.js.map +0 -1
- package/lib-es/__tests__/rpc.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/rpc.unit.test.js.map +0 -1
- package/lib-es/__tests__/signOperation.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/signOperation.unit.test.js.map +0 -1
- package/lib-es/__tests__/synchronization.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/synchronization.unit.test.js.map +0 -1
- package/lib-es/__tests__/transaction.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/transaction.unit.test.js.map +0 -1
- package/lib-es/bridge.integration.test.d.ts +0 -14
- package/lib-es/bridge.integration.test.d.ts.map +0 -1
- package/lib-es/bridge.integration.test.js +0 -79
- package/lib-es/bridge.integration.test.js.map +0 -1
- package/lib-es/datasets/ethereum.scanAccounts.1.d.ts +0 -7
- package/lib-es/datasets/ethereum.scanAccounts.1.d.ts.map +0 -1
- package/lib-es/datasets/ethereum.scanAccounts.1.js +0 -49
- package/lib-es/datasets/ethereum.scanAccounts.1.js.map +0 -1
- package/lib-es/datasets/ethereum2.d.ts +0 -3
- package/lib-es/datasets/ethereum2.d.ts.map +0 -1
- package/lib-es/datasets/ethereum2.js +0 -19
- package/lib-es/datasets/ethereum2.js.map +0 -1
- package/lib-es/datasets/ethereum_classic.d.ts +0 -5
- package/lib-es/datasets/ethereum_classic.d.ts.map +0 -1
- package/lib-es/datasets/ethereum_classic.js +0 -67
- package/lib-es/datasets/ethereum_classic.js.map +0 -1
- package/lib-es/testUtils.d.ts +0 -6
- package/lib-es/testUtils.d.ts.map +0 -1
- package/lib-es/testUtils.js.map +0 -1
- package/src/__tests__/adapters.unit.test.ts +0 -497
- package/src/__tests__/broadcast.unit.test.ts +0 -163
- package/src/__tests__/transaction.unit.test.ts +0 -188
- package/src/bridge.integration.test.ts +0 -86
- package/src/datasets/ethereum.scanAccounts.1.ts +0 -48
- package/src/datasets/ethereum2.ts +0 -20
- package/src/datasets/ethereum_classic.ts +0 -68
- /package/lib/__tests__/{adapters.unit.test.d.ts → unit/adapters.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{gasTracker → unit/api/gasTracker}/ledger.unit.test.d.ts +0 -0
- /package/lib/__tests__/{rpc.unit.test.d.ts → unit/api/rpc/rpc.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{broadcast.unit.test.d.ts → unit/broadcast.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{buildOptimisticOperation.unit.test.d.ts → unit/buildOptimisticOperation.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{createTransaction.unit.test.d.ts → unit/createTransaction.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{deviceTransactionConfig.unit.test.d.ts → unit/deviceTransactionConfig.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{estimateMaxSpendable.unit.test.d.ts → unit/estimateMaxSpendable.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{getTransactionStatus.unit.test.d.ts → unit/getTransactionStatus.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{hw-getAddress.unit.test.d.ts → unit/hw-getAddress.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{logic.unit.test.d.ts → unit/logic.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{preload.unit.test.d.ts → unit/preload.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{prepareTransaction.unit.test.d.ts → unit/prepareTransaction.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{signOperation.unit.test.d.ts → unit/signOperation.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{synchronization.unit.test.d.ts → unit/synchronization.unit.test.d.ts} +0 -0
- /package/lib/__tests__/{transaction.unit.test.d.ts → unit/transaction.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{adapters.unit.test.d.ts → unit/adapters.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{gasTracker → unit/api/explorer}/index.unit.test.d.ts +0 -0
- /package/{lib/__tests__ → lib-es/__tests__/unit/api}/gasTracker/index.unit.test.d.ts +0 -0
- /package/lib-es/__tests__/{gasTracker → unit/api/gasTracker}/ledger.unit.test.d.ts +0 -0
- /package/lib-es/__tests__/{rpc.unit.test.d.ts → unit/api/rpc/rpc.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{broadcast.unit.test.d.ts → unit/broadcast.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{buildOptimisticOperation.unit.test.d.ts → unit/buildOptimisticOperation.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{createTransaction.unit.test.d.ts → unit/createTransaction.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{deviceTransactionConfig.unit.test.d.ts → unit/deviceTransactionConfig.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{estimateMaxSpendable.unit.test.d.ts → unit/estimateMaxSpendable.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{getTransactionStatus.unit.test.d.ts → unit/getTransactionStatus.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{hw-getAddress.unit.test.d.ts → unit/hw-getAddress.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{logic.unit.test.d.ts → unit/logic.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{preload.unit.test.d.ts → unit/preload.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{prepareTransaction.unit.test.d.ts → unit/prepareTransaction.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{signOperation.unit.test.d.ts → unit/signOperation.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{synchronization.unit.test.d.ts → unit/synchronization.unit.test.d.ts} +0 -0
- /package/lib-es/__tests__/{transaction.unit.test.d.ts → unit/transaction.unit.test.d.ts} +0 -0
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { delay } from "@ledgerhq/live-promise";
|
|
2
2
|
import { Operation } from "@ledgerhq/types-live";
|
|
3
3
|
import axios, { AxiosRequestConfig } from "axios";
|
|
4
|
-
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
4
|
import { makeLRUCache } from "@ledgerhq/live-network/cache";
|
|
6
|
-
import {
|
|
5
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
6
|
+
import { isNFTActive } from "@ledgerhq/coin-framework/nft/support";
|
|
7
7
|
import { EtherscanAPIError } from "../../errors";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
etherscanOperationToOperations,
|
|
10
|
+
etherscanERC20EventToOperations,
|
|
11
|
+
etherscanERC721EventToOperations,
|
|
12
|
+
etherscanERC1155EventToOperations,
|
|
13
|
+
} from "../../adapters";
|
|
14
|
+
import {
|
|
15
|
+
EtherscanERC1155Event,
|
|
16
|
+
EtherscanERC20Event,
|
|
17
|
+
EtherscanERC721Event,
|
|
18
|
+
EtherscanOperation,
|
|
19
|
+
} from "../../types";
|
|
9
20
|
|
|
10
21
|
export const ETHERSCAN_TIMEOUT = 5000; // 5 seconds between 2 calls
|
|
11
22
|
export const DEFAULT_RETRIES_API = 8;
|
|
12
23
|
|
|
13
|
-
async function fetchWithRetries<T>(
|
|
24
|
+
export async function fetchWithRetries<T>(
|
|
14
25
|
params: AxiosRequestConfig,
|
|
15
26
|
retries = DEFAULT_RETRIES_API,
|
|
16
27
|
): Promise<T> {
|
|
@@ -43,67 +54,272 @@ async function fetchWithRetries<T>(
|
|
|
43
54
|
/**
|
|
44
55
|
* Get all the last "normal" transactions (no tokens / NFTs)
|
|
45
56
|
*/
|
|
46
|
-
export const getLastCoinOperations =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
export const getLastCoinOperations = async (
|
|
58
|
+
currency: CryptoCurrency,
|
|
59
|
+
address: string,
|
|
60
|
+
accountId: string,
|
|
61
|
+
fromBlock: number,
|
|
62
|
+
toBlock?: number,
|
|
63
|
+
): Promise<Operation[]> => {
|
|
64
|
+
const apiDomain = currency.ethereumLikeInfo?.explorer?.uri;
|
|
65
|
+
if (!apiDomain) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
55
68
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
let url = `${apiDomain}/api?module=account&action=txlist&address=${address}&tag=latest&page=1&sort=desc`;
|
|
70
|
+
if (fromBlock) {
|
|
71
|
+
url += `&startBlock=${fromBlock}`;
|
|
72
|
+
}
|
|
73
|
+
if (toBlock) {
|
|
74
|
+
url += `&endBlock=${toBlock}`;
|
|
75
|
+
}
|
|
60
76
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
const ops = await fetchWithRetries<EtherscanOperation[]>({
|
|
78
|
+
method: "GET",
|
|
79
|
+
url,
|
|
80
|
+
});
|
|
65
81
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.filter(Boolean) as Operation[];
|
|
69
|
-
},
|
|
70
|
-
(currency, address, accountId, fromBlock) => accountId + fromBlock,
|
|
71
|
-
{ ttl: 5 * 1000 },
|
|
72
|
-
);
|
|
82
|
+
return ops.map(tx => etherscanOperationToOperations(accountId, tx)).flat();
|
|
83
|
+
};
|
|
73
84
|
|
|
74
85
|
/**
|
|
75
86
|
* Get all the last ERC20 transactions
|
|
76
87
|
*/
|
|
77
|
-
export const getLastTokenOperations =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
export const getLastTokenOperations = async (
|
|
89
|
+
currency: CryptoCurrency,
|
|
90
|
+
address: string,
|
|
91
|
+
accountId: string,
|
|
92
|
+
fromBlock: number,
|
|
93
|
+
toBlock?: number,
|
|
94
|
+
): Promise<Operation[]> => {
|
|
95
|
+
const apiDomain = currency.ethereumLikeInfo?.explorer?.uri;
|
|
96
|
+
if (!apiDomain) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let url = `${apiDomain}/api?module=account&action=tokentx&address=${address}&tag=latest&page=1&sort=desc`;
|
|
101
|
+
if (fromBlock) {
|
|
102
|
+
url += `&startBlock=${fromBlock}`;
|
|
103
|
+
}
|
|
104
|
+
if (toBlock) {
|
|
105
|
+
url += `&endBlock=${toBlock}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const ops = await fetchWithRetries<EtherscanERC20Event[]>({
|
|
109
|
+
method: "GET",
|
|
110
|
+
url,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Why this thing ?
|
|
114
|
+
// Multiple events can be fired by the same transactions and
|
|
115
|
+
// those transfer events can go from anyone to anyone, which
|
|
116
|
+
// means that multiple events could be sent to or from the
|
|
117
|
+
// same address during the same transaction.
|
|
118
|
+
//
|
|
119
|
+
// To make sure every event (transformed into an operation here)
|
|
120
|
+
// has a unique id, we're groupping them by transaction hash
|
|
121
|
+
// and using the index for each event fired.
|
|
122
|
+
const opsByHash: Record<string, EtherscanERC20Event[]> = {};
|
|
123
|
+
for (const op of ops) {
|
|
124
|
+
if (!opsByHash[op.hash]) {
|
|
125
|
+
opsByHash[op.hash] = [];
|
|
126
|
+
}
|
|
127
|
+
opsByHash[op.hash].push(op);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return Object.values(opsByHash)
|
|
131
|
+
.map(events =>
|
|
132
|
+
events.map((event, index) => etherscanERC20EventToOperations(accountId, event, index)),
|
|
133
|
+
)
|
|
134
|
+
.flat(2);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get all the last ERC721 transactions
|
|
139
|
+
*/
|
|
140
|
+
export const getLastERC721Operations = async (
|
|
141
|
+
currency: CryptoCurrency,
|
|
142
|
+
address: string,
|
|
143
|
+
accountId: string,
|
|
144
|
+
fromBlock: number,
|
|
145
|
+
toBlock?: number,
|
|
146
|
+
): Promise<Operation[]> => {
|
|
147
|
+
const apiDomain = currency.ethereumLikeInfo?.explorer?.uri;
|
|
148
|
+
if (!apiDomain) {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let url = `${apiDomain}/api?module=account&action=tokennfttx&address=${address}&tag=latest&page=1&sort=desc`;
|
|
153
|
+
if (fromBlock) {
|
|
154
|
+
url += `&startBlock=${fromBlock}`;
|
|
155
|
+
}
|
|
156
|
+
if (toBlock) {
|
|
157
|
+
url += `&endBlock=${toBlock}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const ops = await fetchWithRetries<EtherscanERC721Event[]>({
|
|
161
|
+
method: "GET",
|
|
162
|
+
url,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Why this thing ?
|
|
166
|
+
// Multiple events can be fired by the same transactions and
|
|
167
|
+
// those transfer events can go from anyone to anyone, which
|
|
168
|
+
// means that multiple events could be sent to or from the
|
|
169
|
+
// same address during the same transaction.
|
|
170
|
+
//
|
|
171
|
+
// To make sure every event (transformed into an operation here)
|
|
172
|
+
// has a unique id, we're groupping them by transaction hash
|
|
173
|
+
// and using the index for each event fired.
|
|
174
|
+
const opsByHash: Record<string, EtherscanERC721Event[]> = {};
|
|
175
|
+
for (const op of ops) {
|
|
176
|
+
if (!opsByHash[op.hash]) {
|
|
177
|
+
opsByHash[op.hash] = [];
|
|
85
178
|
}
|
|
179
|
+
opsByHash[op.hash].push(op);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return Object.values(opsByHash)
|
|
183
|
+
.map(events =>
|
|
184
|
+
events.map((event, index) => etherscanERC721EventToOperations(accountId, event, index)),
|
|
185
|
+
)
|
|
186
|
+
.flat(2);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get all the last ERC71155 transactions
|
|
191
|
+
*/
|
|
192
|
+
export const getLastERC1155Operations = async (
|
|
193
|
+
currency: CryptoCurrency,
|
|
194
|
+
address: string,
|
|
195
|
+
accountId: string,
|
|
196
|
+
fromBlock: number,
|
|
197
|
+
toBlock?: number,
|
|
198
|
+
): Promise<Operation[]> => {
|
|
199
|
+
const apiDomain = currency.ethereumLikeInfo?.explorer?.uri;
|
|
200
|
+
if (!apiDomain) {
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
86
203
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
204
|
+
let url = `${apiDomain}/api?module=account&action=token1155tx&address=${address}&tag=latest&page=1&sort=desc`;
|
|
205
|
+
if (fromBlock) {
|
|
206
|
+
url += `&startBlock=${fromBlock}`;
|
|
207
|
+
}
|
|
208
|
+
if (toBlock) {
|
|
209
|
+
url += `&endBlock=${toBlock}`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const ops = await fetchWithRetries<EtherscanERC1155Event[]>({
|
|
213
|
+
method: "GET",
|
|
214
|
+
url,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Why this thing ?
|
|
218
|
+
// Multiple events can be fired by the same transactions and
|
|
219
|
+
// those transfer events can go from anyone to anyone, which
|
|
220
|
+
// means that multiple events could be sent to or from the
|
|
221
|
+
// same address during the same transaction.
|
|
222
|
+
//
|
|
223
|
+
// To make sure every event (transformed into an operation here)
|
|
224
|
+
// has a unique id, we're groupping them by transaction hash
|
|
225
|
+
// and using the index for each event fired.
|
|
226
|
+
const opsByHash: Record<string, EtherscanERC1155Event[]> = {};
|
|
227
|
+
for (const op of ops) {
|
|
228
|
+
if (!opsByHash[op.hash]) {
|
|
229
|
+
opsByHash[op.hash] = [];
|
|
90
230
|
}
|
|
231
|
+
opsByHash[op.hash].push(op);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return Object.values(opsByHash)
|
|
235
|
+
.map(events =>
|
|
236
|
+
events.map((event, index) => etherscanERC1155EventToOperations(accountId, event, index)),
|
|
237
|
+
)
|
|
238
|
+
.flat(2);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Get all NFT related operations (ERC721 + ERC1155)
|
|
243
|
+
*/
|
|
244
|
+
export const getLastNftOperations = async (
|
|
245
|
+
currency: CryptoCurrency,
|
|
246
|
+
address: string,
|
|
247
|
+
accountId: string,
|
|
248
|
+
fromBlock: number,
|
|
249
|
+
toBlock?: number,
|
|
250
|
+
): Promise<Operation[]> => {
|
|
251
|
+
const erc721Ops = await getLastERC721Operations(currency, address, accountId, fromBlock, toBlock);
|
|
252
|
+
const erc1155Ops = await getLastERC1155Operations(
|
|
253
|
+
currency,
|
|
254
|
+
address,
|
|
255
|
+
accountId,
|
|
256
|
+
fromBlock,
|
|
257
|
+
toBlock,
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return [...erc721Ops, ...erc1155Ops].sort(
|
|
261
|
+
// sorting DESC order
|
|
262
|
+
(a, b) => b.date.getTime() - a.date.getTime(),
|
|
263
|
+
);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Wrapper around all operation types' requests
|
|
268
|
+
*
|
|
269
|
+
* ⚠ The lack of parallelization is on purpose,
|
|
270
|
+
* do not use a Promise.all here, it would
|
|
271
|
+
* break because of the rate limits
|
|
272
|
+
*/
|
|
273
|
+
export const getLastOperations = makeLRUCache<
|
|
274
|
+
[
|
|
275
|
+
currency: CryptoCurrency,
|
|
276
|
+
address: string,
|
|
277
|
+
accountId: string,
|
|
278
|
+
fromBlock: number,
|
|
279
|
+
toBlock?: number,
|
|
280
|
+
],
|
|
281
|
+
{
|
|
282
|
+
lastCoinOperations: Operation[];
|
|
283
|
+
lastTokenOperations: Operation[];
|
|
284
|
+
lastNftOperations: Operation[];
|
|
285
|
+
}
|
|
286
|
+
>(
|
|
287
|
+
async (currency, address, accountId, fromBlock, toBlock) => {
|
|
288
|
+
const lastCoinOperations = await getLastCoinOperations(
|
|
289
|
+
currency,
|
|
290
|
+
address,
|
|
291
|
+
accountId,
|
|
292
|
+
fromBlock,
|
|
293
|
+
toBlock,
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
const lastTokenOperations = await getLastTokenOperations(
|
|
297
|
+
currency,
|
|
298
|
+
address,
|
|
299
|
+
accountId,
|
|
300
|
+
fromBlock,
|
|
301
|
+
toBlock,
|
|
302
|
+
);
|
|
91
303
|
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
304
|
+
const lastNftOperations = isNFTActive(currency)
|
|
305
|
+
? await getLastNftOperations(currency, address, accountId, fromBlock, toBlock)
|
|
306
|
+
: [];
|
|
96
307
|
|
|
97
|
-
return
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
308
|
+
return {
|
|
309
|
+
lastCoinOperations,
|
|
310
|
+
lastTokenOperations,
|
|
311
|
+
lastNftOperations,
|
|
312
|
+
};
|
|
101
313
|
},
|
|
102
|
-
(currency, address, accountId, fromBlock) => accountId + fromBlock,
|
|
103
|
-
{ ttl:
|
|
314
|
+
(currency, address, accountId, fromBlock, toBlock) => accountId + fromBlock + toBlock,
|
|
315
|
+
{ ttl: ETHERSCAN_TIMEOUT },
|
|
104
316
|
);
|
|
105
317
|
|
|
106
318
|
export default {
|
|
107
319
|
getLastCoinOperations,
|
|
108
320
|
getLastTokenOperations,
|
|
321
|
+
getLastERC721Operations,
|
|
322
|
+
getLastERC1155Operations,
|
|
323
|
+
getLastNftOperations,
|
|
324
|
+
getLastOperations,
|
|
109
325
|
};
|
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
import { CacheRes } from "@ledgerhq/live-network/cache";
|
|
2
|
-
import { CryptoCurrency
|
|
2
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
3
|
import { Operation } from "@ledgerhq/types-live";
|
|
4
4
|
import etherscanLikeApi from "./etherscan";
|
|
5
5
|
|
|
6
|
+
type ExplorerBasicRequest = (
|
|
7
|
+
currency: CryptoCurrency,
|
|
8
|
+
address: string,
|
|
9
|
+
accountId: string,
|
|
10
|
+
fromBlock: number,
|
|
11
|
+
toBlock?: number,
|
|
12
|
+
) => Promise<Operation[]>;
|
|
13
|
+
|
|
6
14
|
type ExplorerApi = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Operation[]
|
|
10
|
-
>;
|
|
11
|
-
getLastTokenOperations: CacheRes<
|
|
12
|
-
[currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
|
|
15
|
+
getLastOperations: CacheRes<
|
|
16
|
+
Parameters<ExplorerBasicRequest>,
|
|
13
17
|
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
lastCoinOperations: Operation[];
|
|
19
|
+
lastTokenOperations: Operation[];
|
|
20
|
+
lastNftOperations: Operation[];
|
|
21
|
+
}
|
|
17
22
|
>;
|
|
23
|
+
// For now every other exported function should be considered as internal
|
|
24
|
+
// methods as they're unecessary to the synchronization it self.
|
|
25
|
+
// This can be updated with new sync requirements.
|
|
26
|
+
// & { [key in
|
|
27
|
+
// | "getLastCoinOperations"
|
|
28
|
+
// | "getLastTokenOperations"
|
|
29
|
+
// | "getLastERC721Operations"
|
|
30
|
+
// | "getLastERC1155Operations"
|
|
31
|
+
// | "getLastNftOperations"]: ExplorerBasicRequest; }
|
|
18
32
|
};
|
|
19
33
|
|
|
20
34
|
/**
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
2
|
+
import network from "@ledgerhq/live-network/network";
|
|
3
|
+
import { NFTCollectionMetadataResponse, NFTMetadataResponse } from "@ledgerhq/types-live";
|
|
4
|
+
import { CollectionMetadataInput, NftMetadataInput } from "@ledgerhq/coin-framework/nft/types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Batched request of nft metadata on the "ethereum" protocol
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ ethereum protocol doesn't mean ethereum chain, you can see this
|
|
10
|
+
* as the evm protocol instead, and you can specify a chainId
|
|
11
|
+
* to request the metadata on any evm chain supported
|
|
12
|
+
*/
|
|
13
|
+
export const getNftMetadata = async (
|
|
14
|
+
input: NftMetadataInput[],
|
|
15
|
+
chainId: number,
|
|
16
|
+
): Promise<NFTMetadataResponse[]> => {
|
|
17
|
+
const { data }: { data: NFTMetadataResponse[] } = await network({
|
|
18
|
+
method: "POST",
|
|
19
|
+
url: `${getEnv("NFT_ETH_METADATA_SERVICE")}/v1/ethereum/${chainId}/contracts/tokens/infos`,
|
|
20
|
+
data: input,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Batched request of nft collection metadata on the "ethereum" protocol
|
|
28
|
+
*
|
|
29
|
+
* ⚠️ ethereum protocol doesn't mean ethereum chain, you can see this
|
|
30
|
+
* as the evm protocol instead, and you can specify a chainId
|
|
31
|
+
* to request the metadata on any evm chain supported
|
|
32
|
+
*/
|
|
33
|
+
export const getNftCollectionMetadata = async (
|
|
34
|
+
input: CollectionMetadataInput[],
|
|
35
|
+
chainId: number,
|
|
36
|
+
): Promise<NFTCollectionMetadataResponse[]> => {
|
|
37
|
+
const { data }: { data: NFTCollectionMetadataResponse[] } = await network({
|
|
38
|
+
method: "POST",
|
|
39
|
+
url: `${getEnv("NFT_ETH_METADATA_SERVICE")}/v1/ethereum/${chainId}/contracts/infos`,
|
|
40
|
+
data: input,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return data;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
getNftMetadata,
|
|
48
|
+
getNftCollectionMetadata,
|
|
49
|
+
};
|
|
@@ -13,8 +13,8 @@ import { transactionToEthersTransaction } from "../../adapters";
|
|
|
13
13
|
import { getSerializedTransaction } from "../../transaction";
|
|
14
14
|
import ERC20Abi from "../../abis/erc20.abi.json";
|
|
15
15
|
|
|
16
|
-
export const RPC_TIMEOUT = 5000; // wait 5 sec after a fail
|
|
17
|
-
export const DEFAULT_RETRIES_RPC_METHODS = 3;
|
|
16
|
+
export const RPC_TIMEOUT = process.env.NODE_ENV === "test" ? 100 : 5000; // wait 5 sec after a fail
|
|
17
|
+
export const DEFAULT_RETRIES_RPC_METHODS = process.env.NODE_ENV === "test" ? 1 : 3;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Cache for RPC providers to avoid recreating the connection on every usage of `withApi`
|
|
@@ -119,7 +119,7 @@ export const getTokenBalance = (
|
|
|
119
119
|
*/
|
|
120
120
|
export const getTransactionCount = (currency: CryptoCurrency, addr: string): Promise<number> =>
|
|
121
121
|
withApi(currency, async api => {
|
|
122
|
-
return api.getTransactionCount(addr);
|
|
122
|
+
return api.getTransactionCount(addr, "pending");
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
/**
|
package/src/bridge/js.ts
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
/* istanbul ignore file: pure exports, bridge tested by live-common with bridge.integration.test.ts */
|
|
2
2
|
import {
|
|
3
|
+
defaultUpdateTransaction,
|
|
3
4
|
makeAccountBridgeReceive,
|
|
4
5
|
makeScanAccounts,
|
|
5
6
|
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
6
7
|
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
7
8
|
import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
9
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
10
|
+
import type { Transaction as EvmTransaction, Transaction } from "../types";
|
|
11
|
+
import { EvmAddress, EvmSignature, EvmSigner } from "../signer";
|
|
10
12
|
import { estimateMaxSpendable } from "../estimateMaxSpendable";
|
|
11
13
|
import { getTransactionStatus } from "../getTransactionStatus";
|
|
12
|
-
import
|
|
13
|
-
import { hydrate, preload } from "../preload";
|
|
14
|
+
import { getAccountShape, sync } from "../synchronization";
|
|
14
15
|
import { prepareTransaction } from "../prepareTransaction";
|
|
16
|
+
import { createTransaction } from "../createTransaction";
|
|
15
17
|
import { buildSignOperation } from "../signOperation";
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
const updateTransaction: AccountBridge<EvmTransaction>["updateTransaction"] = (
|
|
21
|
-
transaction,
|
|
22
|
-
patch,
|
|
23
|
-
) => {
|
|
24
|
-
return { ...transaction, ...patch } as EvmTransaction;
|
|
25
|
-
};
|
|
18
|
+
import { hydrate, preload } from "../preload";
|
|
19
|
+
import nftResolvers from "../nftResolvers";
|
|
20
|
+
import { broadcast } from "../broadcast";
|
|
21
|
+
import resolver from "../hw-getAddress";
|
|
26
22
|
|
|
27
23
|
export function buildCurrencyBridge(
|
|
28
24
|
signerContext: SignerContext<EvmSigner, EvmAddress | EvmSignature>,
|
|
@@ -38,6 +34,7 @@ export function buildCurrencyBridge(
|
|
|
38
34
|
preload,
|
|
39
35
|
hydrate,
|
|
40
36
|
scanAccounts,
|
|
37
|
+
nftResolvers,
|
|
41
38
|
};
|
|
42
39
|
}
|
|
43
40
|
|
|
@@ -51,7 +48,7 @@ export function buildAccountBridge(
|
|
|
51
48
|
|
|
52
49
|
return {
|
|
53
50
|
createTransaction,
|
|
54
|
-
updateTransaction
|
|
51
|
+
updateTransaction: defaultUpdateTransaction<EvmTransaction>,
|
|
55
52
|
prepareTransaction,
|
|
56
53
|
getTransactionStatus,
|
|
57
54
|
sync,
|
package/src/broadcast.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
encodeERC1155OperationId,
|
|
3
|
+
encodeERC721OperationId,
|
|
4
|
+
} from "@ledgerhq/coin-framework/nft/nftOperationId";
|
|
5
|
+
import { encodeNftId } from "@ledgerhq/coin-framework/nft/nftId";
|
|
2
6
|
import type { AccountBridge, Operation } from "@ledgerhq/types-live";
|
|
3
|
-
import {
|
|
7
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
4
8
|
import { Transaction as EvmTransaction } from "./types";
|
|
9
|
+
import { broadcastTransaction } from "./api/rpc";
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Broadcast a transaction and update the operation linked
|
|
@@ -30,6 +35,28 @@ export const broadcast: AccountBridge<EvmTransaction>["broadcast"] = async ({
|
|
|
30
35
|
blockHash: txResponse.blockHash,
|
|
31
36
|
date: new Date(txResponse.timestamp ? txResponse.timestamp * 1000 : Date.now()),
|
|
32
37
|
})) || [],
|
|
38
|
+
nftOperations:
|
|
39
|
+
operation.nftOperations?.map(nftOp => {
|
|
40
|
+
const nftId = encodeNftId(
|
|
41
|
+
nftOp.accountId,
|
|
42
|
+
nftOp.contract || "",
|
|
43
|
+
nftOp.tokenId || "",
|
|
44
|
+
account.currency.id,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
...nftOp,
|
|
49
|
+
id:
|
|
50
|
+
nftOp.standard === "ERC721"
|
|
51
|
+
? encodeERC721OperationId(nftId, txResponse.hash, nftOp.type, 0)
|
|
52
|
+
: encodeERC1155OperationId(nftId, txResponse.hash, nftOp.type, 0),
|
|
53
|
+
hash: txResponse.hash,
|
|
54
|
+
blockNumber: txResponse.blockNumber,
|
|
55
|
+
blockHeight: txResponse.blockNumber,
|
|
56
|
+
blockHash: txResponse.blockHash,
|
|
57
|
+
date: new Date(txResponse.timestamp ? txResponse.timestamp * 1000 : Date.now()),
|
|
58
|
+
};
|
|
59
|
+
}) || [],
|
|
33
60
|
} as Operation;
|
|
34
61
|
};
|
|
35
62
|
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { findSubAccountById } from "@ledgerhq/coin-framework/account/index";
|
|
2
|
-
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
3
|
-
import { Account, Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
|
|
4
|
-
import BigNumber from "bignumber.js";
|
|
5
1
|
import eip55 from "eip55";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import { Account, Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
|
|
4
|
+
import {
|
|
5
|
+
encodeERC1155OperationId,
|
|
6
|
+
encodeERC721OperationId,
|
|
7
|
+
} from "@ledgerhq/coin-framework/nft/nftOperationId";
|
|
8
|
+
import { encodeNftId } from "@ledgerhq/coin-framework/nft/nftId";
|
|
9
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
10
|
+
import { findSubAccountById } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { EvmNftTransaction, Transaction as EvmTransaction } from "./types";
|
|
12
|
+
import { getEstimatedFees, isNftTransaction } from "./logic";
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Build an optimistic operation for the coin of the integration (e.g. Ether for Ethereum)
|
|
@@ -85,6 +90,62 @@ export const buildOptimisticTokenOperation = (
|
|
|
85
90
|
return operation;
|
|
86
91
|
};
|
|
87
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Build an optimistic operation for an ERC721 or ERC1155 transaction
|
|
95
|
+
*/
|
|
96
|
+
export const buildOptimisticNftOperation = (
|
|
97
|
+
account: Account,
|
|
98
|
+
transaction: EvmNftTransaction & EvmTransaction,
|
|
99
|
+
): Operation => {
|
|
100
|
+
const type = "NFT_OUT";
|
|
101
|
+
const estimatedFees = getEstimatedFees(transaction);
|
|
102
|
+
const { nft } = transaction;
|
|
103
|
+
const value = nft.quantity;
|
|
104
|
+
|
|
105
|
+
const coinOperation = buildOptimisticCoinOperation(
|
|
106
|
+
account,
|
|
107
|
+
{
|
|
108
|
+
...transaction,
|
|
109
|
+
recipient: nft.contract,
|
|
110
|
+
amount: new BigNumber(0),
|
|
111
|
+
},
|
|
112
|
+
"FEES",
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const nftId = encodeNftId(account.id, nft.contract, nft.tokenId, account.currency.id);
|
|
116
|
+
const nftOpId =
|
|
117
|
+
transaction.mode === "erc721"
|
|
118
|
+
? encodeERC721OperationId(nftId, "", type, 0)
|
|
119
|
+
: encodeERC1155OperationId(nftId, "", type, 0);
|
|
120
|
+
|
|
121
|
+
// keys marked with a <-- will be updated by the broadcast method
|
|
122
|
+
const operation: Operation = {
|
|
123
|
+
...coinOperation,
|
|
124
|
+
nftOperations: [
|
|
125
|
+
{
|
|
126
|
+
id: nftOpId, // <--
|
|
127
|
+
hash: "", // <--
|
|
128
|
+
type,
|
|
129
|
+
value,
|
|
130
|
+
fee: estimatedFees,
|
|
131
|
+
blockHash: null, // <--
|
|
132
|
+
blockHeight: null, // <--
|
|
133
|
+
senders: [eip55.encode(account.freshAddress)],
|
|
134
|
+
recipients: [eip55.encode(transaction.recipient)],
|
|
135
|
+
accountId: account.id,
|
|
136
|
+
transactionSequenceNumber: transaction.nonce,
|
|
137
|
+
date: new Date(), // <--
|
|
138
|
+
extra: {},
|
|
139
|
+
contract: nft.contract,
|
|
140
|
+
standard: transaction.mode.toUpperCase(),
|
|
141
|
+
tokenId: nft.tokenId,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return operation;
|
|
147
|
+
};
|
|
148
|
+
|
|
88
149
|
/**
|
|
89
150
|
* Create a temporary operation to use until it's confirmed by the blockchain
|
|
90
151
|
*/
|
|
@@ -92,6 +153,10 @@ export const buildOptimisticOperation = (
|
|
|
92
153
|
account: Account,
|
|
93
154
|
transaction: EvmTransaction,
|
|
94
155
|
): Operation => {
|
|
156
|
+
if (isNftTransaction(transaction)) {
|
|
157
|
+
return buildOptimisticNftOperation(account, transaction);
|
|
158
|
+
}
|
|
159
|
+
|
|
95
160
|
const subAccount = findSubAccountById(account, transaction?.subAccountId || "");
|
|
96
161
|
const isTokenTransaction = subAccount?.type === "TokenAccount";
|
|
97
162
|
|