dequanto 0.0.1
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/.vscode/settings.json +11 -0
- package/actions/gen.act.ts +38 -0
- package/actions/tokens.act.ts +12 -0
- package/configs/dequanto.yml +51 -0
- package/contracts/abi/erc20.abi.json +222 -0
- package/contracts/gen/amm/AmmFactoryV2ContractBase.ts +66 -0
- package/contracts/gen/amm/AmmMasterChefV2ContractBase.ts +158 -0
- package/contracts/gen/amm/AmmPairContractV2Base.ts +158 -0
- package/contracts/gen/amm/AmmPairContractV3Base.ts +125 -0
- package/contracts/gen/amm/AmmRouterV2ContractBase.ts +124 -0
- package/contracts/gen/amm/AmmVaultV2ContractBase.ts +214 -0
- package/contracts/gen/base/ERC20Base.ts +90 -0
- package/contracts/gen/bsc/OneInchRouterV3Base.ts +57 -0
- package/contracts/gen/eth/WETHBase/WETHBase.sol +756 -0
- package/contracts/gen/eth/WETHBase.ts +136 -0
- package/contracts/gen/polygon/ERC20PolygonBase.ts +305 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/Address.sol +216 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/BeaconProxy.sol +61 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/Bridge.sol +437 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeGetters.sol +70 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeGovernance.sol +142 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeImplementation.sol +34 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeSetters.sol +57 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeState.sol +52 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeStructs.sol +66 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/BytesLib.sol +510 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/Context.sol +23 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/ERC1967Proxy.sol +32 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/ERC1967Upgrade.sol +193 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/IBeacon.sol +15 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/IERC20.sol +81 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/IWormhole.sol +42 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/Ownable.sol +71 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/Proxy.sol +85 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/SafeERC20.sol +98 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/StorageSlot.sol +83 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/Structs.sol +40 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/Token.sol +12 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/TokenBridge.sol +15 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/TokenImplementation.sol +177 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase/TokenState.sol +31 -0
- package/contracts/gen/polygon/WormholeBridgeContractBase.ts +231 -0
- package/contracts/gen/xdai/WXDaiTokenContractBase.ts +136 -0
- package/data/cex/eth.csv +356 -0
- package/data/tokens/1inch.json +16557 -0
- package/data/tokens/arbitrum.json +1 -0
- package/data/tokens/sushi.json +56388 -0
- package/dist/contracts/gen/amm/AmmFactoryV2ContractBase.js +53 -0
- package/dist/contracts/gen/amm/AmmMasterChefV2ContractBase.js +122 -0
- package/dist/contracts/gen/amm/AmmPairContractV2Base.js +122 -0
- package/dist/contracts/gen/amm/AmmPairContractV3Base.js +98 -0
- package/dist/contracts/gen/amm/AmmRouterV2ContractBase.js +95 -0
- package/dist/contracts/gen/amm/AmmVaultV2ContractBase.js +164 -0
- package/dist/contracts/gen/base/ERC20Base.js +64 -0
- package/dist/contracts/gen/bsc/OneInchRouterV3Base.js +47 -0
- package/dist/contracts/gen/eth/WETHBase.js +96 -0
- package/dist/contracts/gen/polygon/ERC20PolygonBase.js +233 -0
- package/dist/contracts/gen/polygon/WormholeBridgeContractBase.js +172 -0
- package/dist/contracts/gen/xdai/WXDaiTokenContractBase.js +96 -0
- package/dist/src/BlockchainExplorer/BlockChainExplorerFactory.js +227 -0
- package/dist/src/BlockchainExplorer/BlockChainExplorerProvider.js +32 -0
- package/dist/src/BlockchainExplorer/BlockNumberCache.js +33 -0
- package/dist/src/BlockchainExplorer/Bscscan.js +27 -0
- package/dist/src/BlockchainExplorer/Etherscan.js +27 -0
- package/dist/src/BlockchainExplorer/IAbiProvider.js +2 -0
- package/dist/src/BlockchainExplorer/IBlockChainExplorer.js +2 -0
- package/dist/src/BlockchainExplorer/Polyscan.js +27 -0
- package/dist/src/ChainAccounts.js +69 -0
- package/dist/src/ChainAccountsService.js +75 -0
- package/dist/src/Config.js +7 -0
- package/dist/src/blocks/BlockDateResolver.js +125 -0
- package/dist/src/bridges/BridgeFactory.js +19 -0
- package/dist/src/bridges/hop/HopAddresses.js +520 -0
- package/dist/src/bridges/hop/HopBridge.js +327 -0
- package/dist/src/bridges/hop/contracts/gen.act.js +43 -0
- package/dist/src/bridges/hop/contracts/polygon/Dai_l2AmmWrapperContract.js +52 -0
- package/dist/src/bridges/hop/contracts/polygon/Dai_l2BridgeContract.js +319 -0
- package/dist/src/bridges/hop/contracts/polygon/Dai_l2SaddleSwapContract.js +178 -0
- package/dist/src/bridges/hop/contracts/polygon/Eth_l2AmmWrapperContract.js +52 -0
- package/dist/src/bridges/hop/contracts/polygon/Eth_l2BridgeContract.js +319 -0
- package/dist/src/bridges/hop/contracts/polygon/Eth_l2SaddleSwapContract.js +178 -0
- package/dist/src/bridges/hop/contracts/polygon/Matic_l2AmmWrapperContract.js +52 -0
- package/dist/src/bridges/hop/contracts/polygon/Matic_l2BridgeContract.js +319 -0
- package/dist/src/bridges/hop/contracts/polygon/Matic_l2SaddleSwapContract.js +178 -0
- package/dist/src/bridges/hop/contracts/polygon/Usdc_l2AmmWrapperContract.js +52 -0
- package/dist/src/bridges/hop/contracts/polygon/Usdc_l2BridgeContract.js +319 -0
- package/dist/src/bridges/hop/contracts/polygon/Usdc_l2SaddleSwapContract.js +178 -0
- package/dist/src/bridges/hop/contracts/polygon/Usdt_l2AmmWrapperContract.js +52 -0
- package/dist/src/bridges/hop/contracts/polygon/Usdt_l2BridgeContract.js +319 -0
- package/dist/src/bridges/hop/contracts/polygon/Usdt_l2SaddleSwapContract.js +178 -0
- package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2AmmWrapperContract.js +52 -0
- package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2BridgeContract.js +319 -0
- package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2SaddleSwapContract.js +178 -0
- package/dist/src/bridges/models/IBridge.js +2 -0
- package/dist/src/bridges/wormhole/contracts/WormholeBridgeContract.js +15 -0
- package/dist/src/chains/PlatformFactory.js +42 -0
- package/dist/src/chains/arbitrum/ArbTokenProvider.js +40 -0
- package/dist/src/chains/arbitrum/ArbWeb3Client.js +39 -0
- package/dist/src/chains/arbitrum/Arbiscan.js +27 -0
- package/dist/src/chains/boba/BobaWeb3Client.js +47 -0
- package/dist/src/chains/boba/Bobascan.js +28 -0
- package/dist/src/chains/xdai/XDaiWeb3Client.js +87 -0
- package/dist/src/chains/xdai/XDaiscan.js +27 -0
- package/dist/src/chains/xdai/tokens/WXDaiTokenContract.js +15 -0
- package/dist/src/clients/BscWeb3Client.js +38 -0
- package/dist/src/clients/ClientEventsStream.js +34 -0
- package/dist/src/clients/ClientPool.js +560 -0
- package/dist/src/clients/ClientPoolStats.js +52 -0
- package/dist/src/clients/EthWeb3Client.js +35 -0
- package/dist/src/clients/HardhatWeb3Client.js +56 -0
- package/dist/src/clients/PolyWeb3Client.js +77 -0
- package/dist/src/clients/Web3Client.js +186 -0
- package/dist/src/clients/Web3ClientFactory.js +32 -0
- package/dist/src/clients/interfaces/IWeb3Client.js +2 -0
- package/dist/src/clients/interfaces/IWeb3ClientStatus.js +2 -0
- package/dist/src/clients/interfaces/IWeb3EndpointOptions.js +2 -0
- package/dist/src/clients/model/ClientStatus.js +9 -0
- package/dist/src/clients/model/PromiEventWrap.js +52 -0
- package/dist/src/clients/model/SubscriptionWrap.js +42 -0
- package/dist/src/clients/utils/ClientEndpoints.js +27 -0
- package/dist/src/clients/utils/ClientErrorUtil.js +30 -0
- package/dist/src/clients/utils/TxFactory.js +14 -0
- package/dist/src/contracts/BscContract.js +30 -0
- package/dist/src/contracts/Contract.js +90 -0
- package/dist/src/contracts/ContractBase.js +139 -0
- package/dist/src/contracts/ContractFactory.js +17 -0
- package/dist/src/contracts/ContractProvider.js +40 -0
- package/dist/src/contracts/ContractReader.js +76 -0
- package/dist/src/contracts/ContractStream.js +20 -0
- package/dist/src/contracts/ContractWriter.js +62 -0
- package/dist/src/contracts/EthContract.js +31 -0
- package/dist/src/contracts/TxContract.js +37 -0
- package/dist/src/contracts/common/ERC20.js +14 -0
- package/dist/src/contracts/common/ERC20Polygon.js +14 -0
- package/dist/src/contracts/common/PoolPair.js +23 -0
- package/dist/src/contracts/utils/AbiDeserializer.js +89 -0
- package/dist/src/contracts/utils/ConvertUtils.js +21 -0
- package/dist/src/contracts/utils/InputDataUtils.js +87 -0
- package/dist/src/contracts/utils/TypeUtils.js +24 -0
- package/dist/src/defi/OneInch/OneInchRouter.js +14 -0
- package/dist/src/env/BigIntSerializer.js +19 -0
- package/dist/src/gen/Ast.js +12 -0
- package/dist/src/gen/ContractTemplate.js +27 -0
- package/dist/src/gen/Generator.js +180 -0
- package/dist/src/gen/GeneratorFromAbi.js +361 -0
- package/dist/src/handlers/TokenHandler.js +69 -0
- package/dist/src/indexer/BlocksTxIndexer.js +52 -0
- package/dist/src/indexer/PendingTxIndexer.js +96 -0
- package/dist/src/indexer/handlers/BlocksWalker.js +306 -0
- package/dist/src/indexer/handlers/TxQueueLoader.js +117 -0
- package/dist/src/json/JsonArrayStore.js +296 -0
- package/dist/src/json/JsonObjectStore.js +214 -0
- package/dist/src/json/JsonStore.spec.js +83 -0
- package/dist/src/loggers/ILogger.js +2 -0
- package/dist/src/loggers/LoggerService.js +34 -0
- package/dist/src/loggers/TxLoggerService.js +122 -0
- package/dist/src/models/IContractDetails.js +2 -0
- package/dist/src/models/IToken.js +2 -0
- package/dist/src/models/ITokenGlob.js +6 -0
- package/dist/src/models/ITransactionDetails.js +2 -0
- package/dist/src/models/TAddress.js +2 -0
- package/dist/src/models/TBufferLike.js +2 -0
- package/dist/src/models/THex.js +2 -0
- package/dist/src/models/TPlatform.js +2 -0
- package/dist/src/models/TResult.js +2 -0
- package/dist/src/ns/NameService.js +19 -0
- package/dist/src/ns/providers/EnsProvider.js +41 -0
- package/dist/src/ns/providers/INsProvider.js +2 -0
- package/dist/src/ns/providers/UDProvider.js +39 -0
- package/dist/src/ns/utils/$ns.js +17 -0
- package/dist/src/structs/PackedRanges.js +186 -0
- package/dist/src/structs/PackedRanges.spec.js +30 -0
- package/dist/src/tokens/TokenExchangeService.js +110 -0
- package/dist/src/tokens/TokenExchanges/AmmBase/AmmUtilts.js +17 -0
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmFactoryV2Contract.js +15 -0
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmMasterChefV2Contract.js +15 -0
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Contract.js +16 -0
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Service.js +144 -0
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmRouterV2Contract.js +15 -0
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmVaultV2Contract.js +15 -0
- package/dist/src/tokens/TokenExchanges/AmmBase/V3/AmmPairV3Contract.js +22 -0
- package/dist/src/tokens/TokenExchanges/AmmV2ExchangeBase.js +194 -0
- package/dist/src/tokens/TokenExchanges/OneInchExchange.js +92 -0
- package/dist/src/tokens/TokenExchanges/PancakeswapExchange.js +28 -0
- package/dist/src/tokens/TokenExchanges/SushiswapPolygonExchange.js +28 -0
- package/dist/src/tokens/TokenExchanges/UniswapExchange.js +28 -0
- package/dist/src/tokens/TokenOracles/AmmPriceV2Oracle.js +319 -0
- package/dist/src/tokens/TokenOracles/TokenPriceStore.js +108 -0
- package/dist/src/tokens/TokenPriceService.js +196 -0
- package/dist/src/tokens/TokenPriceServiceProvider.js +31 -0
- package/dist/src/tokens/TokenProviders/ATokenProvider.js +38 -0
- package/dist/src/tokens/TokenProviders/ITokenProvider.js +2 -0
- package/dist/src/tokens/TokenProviders/TPChain.js +35 -0
- package/dist/src/tokens/TokenProviders/TPCoinmarketcap.js +63 -0
- package/dist/src/tokens/TokenProviders/TPOneInch.js +65 -0
- package/dist/src/tokens/TokenProviders/TPSushiswap.js +89 -0
- package/dist/src/tokens/TokenProviders/TPUniswap.js +84 -0
- package/dist/src/tokens/TokenService.js +115 -0
- package/dist/src/tokens/TokenSwapService.js +37 -0
- package/dist/src/tokens/TokenTransferService.js +189 -0
- package/dist/src/tokens/TokensService.js +236 -0
- package/dist/src/tokens/TokensServiceBsc.js +18 -0
- package/dist/src/tokens/TokensServiceEth.js +15 -0
- package/dist/src/tokens/TokensServiceFactory.js +29 -0
- package/dist/src/tokens/TokensServicePolygon.js +18 -0
- package/dist/src/tokens/TokensServiceXDai.js +24 -0
- package/dist/src/tokens/defi/ISwapService.js +2 -0
- package/dist/src/tokens/defi/paraswap/Paraswap.js +135 -0
- package/dist/src/tokens/erc20/eth/WETH.js +14 -0
- package/dist/src/tokens/utils/TokenUtils.js +66 -0
- package/dist/src/txs/ITxConfig.js +2 -0
- package/dist/src/txs/TxDataBuilder.js +159 -0
- package/dist/src/txs/TxLogger.js +119 -0
- package/dist/src/txs/TxProvider.js +73 -0
- package/dist/src/txs/TxService.js +19 -0
- package/dist/src/txs/TxWriter.js +287 -0
- package/dist/src/txs/conditional/GasWatcherLogger.js +61 -0
- package/dist/src/txs/conditional/GasWatcherService.js +103 -0
- package/dist/src/txs/conditional/GasWatcherStore.js +25 -0
- package/dist/src/txs/conditional/GasWatcherTx.js +126 -0
- package/dist/src/txs/receipt/ITxLogItem.js +2 -0
- package/dist/src/txs/receipt/TxLogParser.js +27 -0
- package/dist/src/txs/receipt/TxLogsTransfer.js +50 -0
- package/dist/src/txs/receipt/TxTopicInMemoryProvider.js +41 -0
- package/dist/src/txs/receipt/TxTopicProvider.js +25 -0
- package/dist/src/utils/$abiParser.js +159 -0
- package/dist/src/utils/$abiType.js +77 -0
- package/dist/src/utils/$abiUtils.js +43 -0
- package/dist/src/utils/$address.js +41 -0
- package/dist/src/utils/$array.js +60 -0
- package/dist/src/utils/$bigint.js +130 -0
- package/dist/src/utils/$block.js +10 -0
- package/dist/src/utils/$class.js +13 -0
- package/dist/src/utils/$config.js +18 -0
- package/dist/src/utils/$contract.js +67 -0
- package/dist/src/utils/$csv.js +79 -0
- package/dist/src/utils/$date.js +496 -0
- package/dist/src/utils/$fn.js +117 -0
- package/dist/src/utils/$is.js +40 -0
- package/dist/src/utils/$logger.js +15 -0
- package/dist/src/utils/$number.js +95 -0
- package/dist/src/utils/$object.js +82 -0
- package/dist/src/utils/$path.js +33 -0
- package/dist/src/utils/$promise.js +13 -0
- package/dist/src/utils/$require.js +127 -0
- package/dist/src/utils/$sign.js +35 -0
- package/dist/src/utils/$signSerializer.js +264 -0
- package/dist/src/utils/$wallet.js +13 -0
- package/dist/src/utils/types.js +2 -0
- package/dist/src/wallets/Wallet.js +26 -0
- package/dist/src/wallets/WalletBsc.js +17 -0
- package/dist/src/wallets/WalletService.js +35 -0
- package/dist/src/www/utils/BlockChainExplorerFormatter.js +15 -0
- package/hardhat.config.js +6 -0
- package/package.json +52 -0
- package/readme.md +76 -0
- package/src/BlockchainExplorer/BlockChainExplorerFactory.ts +273 -0
- package/src/BlockchainExplorer/BlockChainExplorerProvider.ts +26 -0
- package/src/BlockchainExplorer/BlockNumberCache.ts +46 -0
- package/src/BlockchainExplorer/Bscscan.ts +23 -0
- package/src/BlockchainExplorer/Etherscan.ts +25 -0
- package/src/BlockchainExplorer/IAbiProvider.ts +5 -0
- package/src/BlockchainExplorer/IBlockChainExplorer.ts +37 -0
- package/src/BlockchainExplorer/Polyscan.ts +23 -0
- package/src/ChainAccounts.ts +72 -0
- package/src/ChainAccountsService.ts +74 -0
- package/src/Config.ts +34 -0
- package/src/blocks/BlockDateResolver.ts +149 -0
- package/src/bridges/BridgeFactory.ts +16 -0
- package/src/bridges/hop/HopAddresses.ts +518 -0
- package/src/bridges/hop/HopBridge.ts +430 -0
- package/src/bridges/hop/contracts/gen.act.ts +50 -0
- package/src/bridges/hop/contracts/polygon/Dai_l2AmmWrapperContract.ts +69 -0
- package/src/bridges/hop/contracts/polygon/Dai_l2BridgeContract.ts +453 -0
- package/src/bridges/hop/contracts/polygon/Dai_l2SaddleSwapContract.ts +264 -0
- package/src/bridges/hop/contracts/polygon/Eth_l2AmmWrapperContract.ts +69 -0
- package/src/bridges/hop/contracts/polygon/Eth_l2BridgeContract.ts +453 -0
- package/src/bridges/hop/contracts/polygon/Eth_l2SaddleSwapContract.ts +264 -0
- package/src/bridges/hop/contracts/polygon/Matic_l2AmmWrapperContract.ts +69 -0
- package/src/bridges/hop/contracts/polygon/Matic_l2BridgeContract.ts +453 -0
- package/src/bridges/hop/contracts/polygon/Matic_l2SaddleSwapContract.ts +264 -0
- package/src/bridges/hop/contracts/polygon/Usdc_l2AmmWrapperContract.ts +69 -0
- package/src/bridges/hop/contracts/polygon/Usdc_l2BridgeContract.ts +453 -0
- package/src/bridges/hop/contracts/polygon/Usdc_l2SaddleSwapContract.ts +264 -0
- package/src/bridges/hop/contracts/polygon/Usdt_l2AmmWrapperContract.ts +69 -0
- package/src/bridges/hop/contracts/polygon/Usdt_l2BridgeContract.ts +453 -0
- package/src/bridges/hop/contracts/polygon/Usdt_l2SaddleSwapContract.ts +264 -0
- package/src/bridges/hop/contracts/polygon/Wbtc_l2AmmWrapperContract.ts +69 -0
- package/src/bridges/hop/contracts/polygon/Wbtc_l2BridgeContract.ts +453 -0
- package/src/bridges/hop/contracts/polygon/Wbtc_l2SaddleSwapContract.ts +264 -0
- package/src/bridges/models/IBridge.ts +43 -0
- package/src/bridges/wormhole/contracts/WormholeBridgeContract.ts +14 -0
- package/src/chains/PlatformFactory.ts +45 -0
- package/src/chains/arbitrum/ArbTokenProvider.ts +39 -0
- package/src/chains/arbitrum/ArbWeb3Client.ts +39 -0
- package/src/chains/arbitrum/Arbiscan.ts +24 -0
- package/src/chains/boba/BobaWeb3Client.ts +49 -0
- package/src/chains/boba/Bobascan.ts +25 -0
- package/src/chains/xdai/XDaiWeb3Client.ts +82 -0
- package/src/chains/xdai/XDaiscan.ts +24 -0
- package/src/chains/xdai/tokens/WXDaiTokenContract.json +279 -0
- package/src/chains/xdai/tokens/WXDaiTokenContract.ts +14 -0
- package/src/clients/BscWeb3Client.ts +38 -0
- package/src/clients/ClientEventsStream.ts +33 -0
- package/src/clients/ClientPool.ts +673 -0
- package/src/clients/ClientPoolStats.ts +64 -0
- package/src/clients/EthWeb3Client.ts +36 -0
- package/src/clients/HardhatWeb3Client.ts +60 -0
- package/src/clients/PolyWeb3Client.ts +91 -0
- package/src/clients/Web3Client.ts +228 -0
- package/src/clients/Web3ClientFactory.ts +28 -0
- package/src/clients/interfaces/IWeb3Client.ts +14 -0
- package/src/clients/interfaces/IWeb3ClientStatus.ts +23 -0
- package/src/clients/interfaces/IWeb3EndpointOptions.ts +9 -0
- package/src/clients/model/ClientStatus.ts +5 -0
- package/src/clients/model/PromiEventWrap.ts +61 -0
- package/src/clients/model/SubscriptionWrap.ts +53 -0
- package/src/clients/utils/ClientEndpoints.ts +26 -0
- package/src/clients/utils/ClientErrorUtil.ts +26 -0
- package/src/clients/utils/TxFactory.ts +17 -0
- package/src/contracts/BscContract.ts +28 -0
- package/src/contracts/Contract.ts +126 -0
- package/src/contracts/ContractBase.ts +158 -0
- package/src/contracts/ContractFactory.ts +19 -0
- package/src/contracts/ContractProvider.ts +55 -0
- package/src/contracts/ContractReader.ts +87 -0
- package/src/contracts/ContractStream.ts +18 -0
- package/src/contracts/ContractWriter.ts +97 -0
- package/src/contracts/EthContract.ts +29 -0
- package/src/contracts/TxContract.ts +43 -0
- package/src/contracts/common/ERC20.ts +13 -0
- package/src/contracts/common/ERC20Polygon.ts +13 -0
- package/src/contracts/common/PoolPair.ts +22 -0
- package/src/contracts/utils/AbiDeserializer.ts +98 -0
- package/src/contracts/utils/ConvertUtils.ts +16 -0
- package/src/contracts/utils/InputDataUtils.ts +93 -0
- package/src/contracts/utils/TypeUtils.ts +21 -0
- package/src/defi/OneInch/OneInchRouter.ts +13 -0
- package/src/env/BigIntSerializer.ts +18 -0
- package/src/gen/Ast.ts +12 -0
- package/src/gen/ContractTemplate.ts +36 -0
- package/src/gen/Generator.ts +227 -0
- package/src/gen/GeneratorFromAbi.ts +402 -0
- package/src/handlers/TokenHandler.ts +78 -0
- package/src/indexer/BlocksTxIndexer.ts +69 -0
- package/src/indexer/PendingTxIndexer.ts +124 -0
- package/src/indexer/handlers/BlocksWalker.ts +390 -0
- package/src/indexer/handlers/TxQueueLoader.ts +143 -0
- package/src/json/JsonArrayStore.ts +310 -0
- package/src/json/JsonObjectStore.ts +239 -0
- package/src/json/JsonStore.spec.ts +98 -0
- package/src/loggers/ILogger.ts +3 -0
- package/src/loggers/LoggerService.ts +39 -0
- package/src/loggers/TxLoggerService.ts +146 -0
- package/src/models/IContractDetails.ts +8 -0
- package/src/models/IToken.ts +11 -0
- package/src/models/ITokenGlob.ts +14 -0
- package/src/models/ITransactionDetails.ts +11 -0
- package/src/models/TAddress.ts +1 -0
- package/src/models/TBufferLike.ts +2 -0
- package/src/models/THex.ts +1 -0
- package/src/models/TPlatform.ts +1 -0
- package/src/models/TResult.ts +6 -0
- package/src/ns/NameService.ts +21 -0
- package/src/ns/providers/EnsProvider.ts +45 -0
- package/src/ns/providers/INsProvider.ts +6 -0
- package/src/ns/providers/UDProvider.ts +49 -0
- package/src/ns/utils/$ns.ts +15 -0
- package/src/structs/PackedRanges.spec.ts +38 -0
- package/src/structs/PackedRanges.ts +207 -0
- package/src/tokens/TokenExchangeService.ts +126 -0
- package/src/tokens/TokenExchanges/AmmBase/AmmUtilts.ts +16 -0
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmFactoryV2Contract.ts +15 -0
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmMasterChefV2Contract.ts +15 -0
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Contract.ts +17 -0
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Service.ts +208 -0
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmRouterV2Contract.ts +15 -0
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmVaultV2Contract.ts +15 -0
- package/src/tokens/TokenExchanges/AmmBase/V3/AmmPairV3Contract.ts +24 -0
- package/src/tokens/TokenExchanges/AmmV2ExchangeBase.ts +242 -0
- package/src/tokens/TokenExchanges/OneInchExchange.ts +111 -0
- package/src/tokens/TokenExchanges/PancakeswapExchange.ts +30 -0
- package/src/tokens/TokenExchanges/SushiswapPolygonExchange.ts +30 -0
- package/src/tokens/TokenExchanges/UniswapExchange.ts +31 -0
- package/src/tokens/TokenOracles/AmmPriceV2Oracle.ts +440 -0
- package/src/tokens/TokenOracles/TokenPriceStore.ts +129 -0
- package/src/tokens/TokenPriceService.ts +276 -0
- package/src/tokens/TokenPriceServiceProvider.ts +36 -0
- package/src/tokens/TokenProviders/ATokenProvider.ts +42 -0
- package/src/tokens/TokenProviders/ITokenProvider.ts +9 -0
- package/src/tokens/TokenProviders/TPChain.ts +41 -0
- package/src/tokens/TokenProviders/TPCoinmarketcap.ts +82 -0
- package/src/tokens/TokenProviders/TPOneInch.ts +71 -0
- package/src/tokens/TokenProviders/TPSushiswap.ts +96 -0
- package/src/tokens/TokenProviders/TPUniswap.ts +85 -0
- package/src/tokens/TokenService.ts +128 -0
- package/src/tokens/TokenSwapService.ts +47 -0
- package/src/tokens/TokenTransferService.ts +216 -0
- package/src/tokens/TokensService.ts +252 -0
- package/src/tokens/TokensServiceBsc.ts +17 -0
- package/src/tokens/TokensServiceEth.ts +9 -0
- package/src/tokens/TokensServiceFactory.ts +24 -0
- package/src/tokens/TokensServicePolygon.ts +17 -0
- package/src/tokens/TokensServiceXDai.ts +26 -0
- package/src/tokens/defi/ISwapService.ts +12 -0
- package/src/tokens/defi/paraswap/Paraswap.ts +244 -0
- package/src/tokens/erc20/eth/WETH.ts +13 -0
- package/src/tokens/utils/TokenUtils.ts +63 -0
- package/src/txs/ITxConfig.ts +27 -0
- package/src/txs/TxDataBuilder.ts +207 -0
- package/src/txs/TxLogger.ts +121 -0
- package/src/txs/TxProvider.ts +68 -0
- package/src/txs/TxService.ts +19 -0
- package/src/txs/TxWriter.ts +370 -0
- package/src/txs/conditional/GasWatcherLogger.ts +57 -0
- package/src/txs/conditional/GasWatcherService.ts +117 -0
- package/src/txs/conditional/GasWatcherStore.ts +40 -0
- package/src/txs/conditional/GasWatcherTx.ts +143 -0
- package/src/txs/receipt/ITxLogItem.ts +25 -0
- package/src/txs/receipt/TxLogParser.ts +29 -0
- package/src/txs/receipt/TxLogsTransfer.ts +61 -0
- package/src/txs/receipt/TxTopicInMemoryProvider.ts +45 -0
- package/src/txs/receipt/TxTopicProvider.ts +29 -0
- package/src/utils/$abiParser.ts +179 -0
- package/src/utils/$abiType.ts +85 -0
- package/src/utils/$abiUtils.ts +38 -0
- package/src/utils/$address.ts +37 -0
- package/src/utils/$array.ts +57 -0
- package/src/utils/$bigint.ts +127 -0
- package/src/utils/$block.ts +7 -0
- package/src/utils/$class.ts +8 -0
- package/src/utils/$config.ts +17 -0
- package/src/utils/$contract.ts +67 -0
- package/src/utils/$csv.ts +54 -0
- package/src/utils/$date.ts +473 -0
- package/src/utils/$fn.ts +134 -0
- package/src/utils/$is.ts +37 -0
- package/src/utils/$logger.ts +10 -0
- package/src/utils/$number.ts +89 -0
- package/src/utils/$object.ts +95 -0
- package/src/utils/$path.ts +32 -0
- package/src/utils/$promise.ts +7 -0
- package/src/utils/$require.ts +118 -0
- package/src/utils/$sign.ts +36 -0
- package/src/utils/$signSerializer.ts +339 -0
- package/src/utils/$wallet.ts +10 -0
- package/src/utils/types.ts +29 -0
- package/src/wallets/Wallet.ts +33 -0
- package/src/wallets/WalletBsc.ts +13 -0
- package/src/wallets/WalletService.ts +43 -0
- package/src/www/utils/BlockChainExplorerFormatter.ts +13 -0
- package/test/ChainAccount.spec.ts +9 -0
- package/test/client.spec.ts +59 -0
- package/test/fixtures/DaiTokenContract.ts +13 -0
- package/test/fixtures/receipts/swap.json +94 -0
- package/test/generate/class.spec.ts +27 -0
- package/test/hardhat/TestNode.ts +61 -0
- package/test/ns.spec.ts +30 -0
- package/test/receipt.spec.ts +27 -0
- package/test/utils/abi-parser.spec.ts +117 -0
- package/test/utils/bigint.spec.ts +40 -0
- package/test/utils/date.spec.ts +8 -0
- package/test/utils/fn.spec.ts +39 -0
- package/test/utils/number.spec.ts +41 -0
- package/test/utils/sign.spec.ts +22 -0
- package/tsconfig-build.json +24 -0
- package/tsconfig-src.json +36 -0
- package/tsconfig.json +27 -0
- package/typings/globals/assertion/index.d.ts +159 -0
- package/typings/globals/assertion/typings.json +10 -0
- package/typings/globals/atma-utest/index.d.ts +53 -0
- package/typings/globals/atma-utest/typings.json +10 -0
- package/typings/globals/axios/index.d.ts +6 -0
- package/typings/globals/mask/index.d.ts +6 -0
- package/typings/globals/mask/typings.json +9 -0
- package/typings/index.d.ts +6 -0
- package/typings.json +6 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TokenHandler = void 0;
|
|
13
|
+
const PlatformFactory_1 = require("@dequanto/chains/PlatformFactory");
|
|
14
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
15
|
+
const _require_1 = require("@dequanto/utils/$require");
|
|
16
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
17
|
+
const memd_1 = __importDefault(require("memd"));
|
|
18
|
+
class TokenHandler {
|
|
19
|
+
constructor(platform) {
|
|
20
|
+
this.platform = platform;
|
|
21
|
+
}
|
|
22
|
+
async transfer(params) {
|
|
23
|
+
let fromAccount = await this.getAccount(params.from, true);
|
|
24
|
+
let toAccount = await this.getAccount(params.to, params.internal);
|
|
25
|
+
let chain = await this.chain();
|
|
26
|
+
let token = typeof params.token === 'string'
|
|
27
|
+
? await chain.tokens.getKnownToken(params.token)
|
|
28
|
+
: params.token;
|
|
29
|
+
_require_1.$require.Token(token);
|
|
30
|
+
_require_1.$require.notNull(fromAccount, 'FromAccount');
|
|
31
|
+
_require_1.$require.notNull(toAccount, 'ToAccount');
|
|
32
|
+
let amountEther = params.amount;
|
|
33
|
+
if (amountEther == Infinity) {
|
|
34
|
+
let balance = await chain.transfer.getBalance(fromAccount.address, token);
|
|
35
|
+
amountEther = _bigint_1.$bigint.toEther(balance, token.decimals);
|
|
36
|
+
}
|
|
37
|
+
console.log('Transfering: ', amountEther, token.symbol);
|
|
38
|
+
let service = chain.transfer
|
|
39
|
+
.$config({
|
|
40
|
+
type: 2
|
|
41
|
+
//gasFunding: ChainAccountProvider.get(PLATFORM, 'quant')
|
|
42
|
+
});
|
|
43
|
+
let txToken = params.amount === Infinity
|
|
44
|
+
? await service.transferAll(fromAccount, toAccount.address, token)
|
|
45
|
+
: await service.transfer(fromAccount, toAccount.address, token, params.amount);
|
|
46
|
+
return txToken;
|
|
47
|
+
}
|
|
48
|
+
chain() {
|
|
49
|
+
return a_di_1.default.resolve(PlatformFactory_1.PlatformFactory).get(this.platform);
|
|
50
|
+
}
|
|
51
|
+
async getAccount(mix, isPrivate) {
|
|
52
|
+
if (typeof mix === 'object' && 'address' in mix && 'key' in mix) {
|
|
53
|
+
return mix;
|
|
54
|
+
}
|
|
55
|
+
let chain = await this.chain();
|
|
56
|
+
let account = await chain.accounts.get(mix);
|
|
57
|
+
if (account == null) {
|
|
58
|
+
if (isPrivate !== false) {
|
|
59
|
+
throw new Error(`Account ${mix} not found`);
|
|
60
|
+
}
|
|
61
|
+
return { address: mix };
|
|
62
|
+
}
|
|
63
|
+
return account;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
__decorate([
|
|
67
|
+
memd_1.default.deco.memoize({ perInstance: true })
|
|
68
|
+
], TokenHandler.prototype, "chain", null);
|
|
69
|
+
exports.TokenHandler = TokenHandler;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlocksTxIndexer = void 0;
|
|
4
|
+
const BlocksWalker_1 = require("./handlers/BlocksWalker");
|
|
5
|
+
const Web3ClientFactory_1 = require("@dequanto/clients/Web3ClientFactory");
|
|
6
|
+
const _logger_1 = require("@dequanto/utils/$logger");
|
|
7
|
+
class BlocksTxIndexer {
|
|
8
|
+
constructor(platform, opts) {
|
|
9
|
+
this.platform = platform;
|
|
10
|
+
this.opts = opts;
|
|
11
|
+
this.listeners = [];
|
|
12
|
+
this.client = Web3ClientFactory_1.Web3ClientFactory.get(platform, {
|
|
13
|
+
ws: true
|
|
14
|
+
});
|
|
15
|
+
this.walker = new BlocksWalker_1.BlocksWalker({
|
|
16
|
+
name: `${opts?.name ?? 'indexer'}_${this.platform}`,
|
|
17
|
+
client: this.client,
|
|
18
|
+
loadTransactions: opts?.loadTransactions ?? true,
|
|
19
|
+
persistance: opts?.persistance ?? true,
|
|
20
|
+
visitor: async (block, txs) => {
|
|
21
|
+
return this.indexTransactions(block, txs);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
onBlock(cb) {
|
|
26
|
+
this.listeners.push(cb);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
stats() {
|
|
30
|
+
return this.walker.stats();
|
|
31
|
+
}
|
|
32
|
+
async start(from, to) {
|
|
33
|
+
await this.walker.start(from, to);
|
|
34
|
+
if (to == null) {
|
|
35
|
+
this.client.subscribe('newBlockHeaders', (error, blockHeader) => {
|
|
36
|
+
this.walker.processUntil(blockHeader.number);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async indexTransactions(block, txs) {
|
|
41
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
42
|
+
let indexer = this.listeners[i];
|
|
43
|
+
try {
|
|
44
|
+
await indexer(this.client, block, txs);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
_logger_1.$logger.log(error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.BlocksTxIndexer = BlocksTxIndexer;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PendingTxIndexer = void 0;
|
|
4
|
+
const Web3ClientFactory_1 = require("@dequanto/clients/Web3ClientFactory");
|
|
5
|
+
const TxQueueLoader_1 = require("./handlers/TxQueueLoader");
|
|
6
|
+
const BlocksTxIndexer_1 = require("./BlocksTxIndexer");
|
|
7
|
+
const _number_1 = require("@dequanto/utils/$number");
|
|
8
|
+
class PendingTxIndexer {
|
|
9
|
+
constructor(platform, opts) {
|
|
10
|
+
this.platform = platform;
|
|
11
|
+
this.opts = opts;
|
|
12
|
+
this.listeners = [];
|
|
13
|
+
//private mempool = [];
|
|
14
|
+
this.mempoolHash = Object.create(null);
|
|
15
|
+
this.status = {
|
|
16
|
+
startedAt: null,
|
|
17
|
+
// ~ tx/s
|
|
18
|
+
txSpeed: 0,
|
|
19
|
+
txCount: 0,
|
|
20
|
+
txNulls: 0,
|
|
21
|
+
// tx not seen in mempool
|
|
22
|
+
txPrivateCount: 0,
|
|
23
|
+
};
|
|
24
|
+
this.client = Web3ClientFactory_1.Web3ClientFactory.get(platform, {
|
|
25
|
+
ws: true
|
|
26
|
+
});
|
|
27
|
+
let pool = Web3ClientFactory_1.Web3ClientFactory.get(platform);
|
|
28
|
+
this.loader = new TxQueueLoader_1.TxQueueLoader(pool, tx => {
|
|
29
|
+
this.onMempoolTxLoaded(tx);
|
|
30
|
+
});
|
|
31
|
+
this.blocks = new BlocksTxIndexer_1.BlocksTxIndexer(platform, {
|
|
32
|
+
name: opts.name,
|
|
33
|
+
loadTransactions: false,
|
|
34
|
+
persistance: false,
|
|
35
|
+
});
|
|
36
|
+
this.blocks.onBlock(async (client, block) => {
|
|
37
|
+
this.onBlockLoaded(block);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
onTransaction(cb) {
|
|
41
|
+
this.listeners.push(cb);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
stats() {
|
|
45
|
+
if (this.status.startedAt == null) {
|
|
46
|
+
return { active: false };
|
|
47
|
+
}
|
|
48
|
+
let seconds = (Date.now() - this.status.startedAt) / 1000 | 0;
|
|
49
|
+
let txSpeed = _number_1.$number.round(this.status.txCount / seconds, 2);
|
|
50
|
+
return {
|
|
51
|
+
active: true,
|
|
52
|
+
txSpeed: txSpeed,
|
|
53
|
+
...this.status,
|
|
54
|
+
loader: {
|
|
55
|
+
...this.loader.stats()
|
|
56
|
+
},
|
|
57
|
+
blocks: {
|
|
58
|
+
...this.blocks.stats()
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async start() {
|
|
63
|
+
this.status.startedAt = Date.now();
|
|
64
|
+
this.client.subscribe('pendingTransactions', (error, hash) => {
|
|
65
|
+
this.status.txCount++;
|
|
66
|
+
this.mempoolHash[hash] = 1;
|
|
67
|
+
this.loader.push(hash);
|
|
68
|
+
});
|
|
69
|
+
let blockNumber = await this.client.getBlockNumber();
|
|
70
|
+
this.blocks.start(blockNumber);
|
|
71
|
+
}
|
|
72
|
+
onMempoolTxLoaded(tx) {
|
|
73
|
+
if (tx == null) {
|
|
74
|
+
this.status.txNulls++;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
78
|
+
this.listeners[i](this.client, tx);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
onBlockLoaded(block) {
|
|
82
|
+
for (let i = 0; i < block.transactions.length; i++) {
|
|
83
|
+
let hash = block.transactions[i];
|
|
84
|
+
if (hash in this.mempoolHash) {
|
|
85
|
+
delete this.mempoolHash[hash];
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
//Not seen in memhash;
|
|
89
|
+
this.status.txPrivateCount++;
|
|
90
|
+
this.status.txCount++;
|
|
91
|
+
this.mempoolHash[hash] = 1;
|
|
92
|
+
this.loader.push(hash);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.PendingTxIndexer = PendingTxIndexer;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BlocksWalker = void 0;
|
|
13
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
14
|
+
const alot_1 = __importDefault(require("alot"));
|
|
15
|
+
const memd_1 = __importDefault(require("memd"));
|
|
16
|
+
const _array_1 = require("@dequanto/utils/$array");
|
|
17
|
+
const atma_io_1 = require("atma-io");
|
|
18
|
+
const PackedRanges_1 = require("../../structs/PackedRanges");
|
|
19
|
+
const everlog_1 = require("everlog");
|
|
20
|
+
const BlockDateResolver_1 = require("@dequanto/blocks/BlockDateResolver");
|
|
21
|
+
const _date_1 = require("@dequanto/utils/$date");
|
|
22
|
+
const atma_utils_1 = require("atma-utils");
|
|
23
|
+
const _is_1 = require("@dequanto/utils/$is");
|
|
24
|
+
const _logger_1 = require("@dequanto/utils/$logger");
|
|
25
|
+
class BlocksWalker {
|
|
26
|
+
constructor(params) {
|
|
27
|
+
this.params = params;
|
|
28
|
+
this.client = this.params.client;
|
|
29
|
+
this.visitor = this.params.visitor;
|
|
30
|
+
this.status = {
|
|
31
|
+
blockLoadTime: 0
|
|
32
|
+
};
|
|
33
|
+
this.cachedState = new atma_io_1.FileSafe(`./db/block-indexers/${this.params.name}.json`);
|
|
34
|
+
this.fs = everlog_1.Everlog.createChannel(`indexer-${this.params.name}`, {
|
|
35
|
+
fields: [
|
|
36
|
+
{ name: 'Date', type: 'date' },
|
|
37
|
+
{ name: 'Total', type: 'number' },
|
|
38
|
+
{ name: 'Processed', type: 'number' },
|
|
39
|
+
{ name: 'AvgTime', type: 'number' },
|
|
40
|
+
{ name: 'BlockLoadTime', type: 'number' },
|
|
41
|
+
{ name: 'Error', type: 'string' },
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
this.ranges = new PackedRanges_1.PackedRanges({
|
|
45
|
+
...this.params.blocks,
|
|
46
|
+
});
|
|
47
|
+
this.isRestored = false;
|
|
48
|
+
}
|
|
49
|
+
async start(from, to) {
|
|
50
|
+
if (this.isRestored === false) {
|
|
51
|
+
await this.restore();
|
|
52
|
+
}
|
|
53
|
+
let onlyIncoming = from == null && to == null;
|
|
54
|
+
if (onlyIncoming) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (from == null) {
|
|
58
|
+
throw new Error(`FromBlock should be set while ToBlock(${to}) is present`);
|
|
59
|
+
}
|
|
60
|
+
this.walker.setFrom(await this.getBlockNumber(from));
|
|
61
|
+
this.walker.setTo(await this.getBlockNumber(to));
|
|
62
|
+
_is_1.$is.Number(this.ranges.from, 'From should be a number');
|
|
63
|
+
_is_1.$is.Number(this.ranges.to, 'To should be a number');
|
|
64
|
+
this.walker.process();
|
|
65
|
+
_logger_1.$logger.log(`BlocksWalker starting. Processing: ${this.ranges.from}-${to}. Completed: ${this.ranges.totalAdded()}; ToDo: ${this.ranges.totalLeft()}`);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Can be called each time we get a new block from blockchain,
|
|
69
|
+
* the walker will process its current blocks and up until the specified number
|
|
70
|
+
*/
|
|
71
|
+
async processUntil(nr) {
|
|
72
|
+
if (this.isRestored === false) {
|
|
73
|
+
await this.restore();
|
|
74
|
+
}
|
|
75
|
+
this.walker.process(nr);
|
|
76
|
+
return this.onEndPromise = new atma_utils_1.class_Dfr;
|
|
77
|
+
}
|
|
78
|
+
stats() {
|
|
79
|
+
return {
|
|
80
|
+
...(this.walker?.stats() ?? {}),
|
|
81
|
+
...(this.status),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async restore() {
|
|
85
|
+
try {
|
|
86
|
+
if (this.params.persistance !== false) {
|
|
87
|
+
let json = await this.cachedState.readAsync();
|
|
88
|
+
let ranges = JSON.parse(json);
|
|
89
|
+
if (ranges != null) {
|
|
90
|
+
this.ranges.set(ranges);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) { }
|
|
95
|
+
this.walker = new RangeWalker({
|
|
96
|
+
range: this.ranges,
|
|
97
|
+
onVisit: (nr) => this.processBlock(nr),
|
|
98
|
+
onResult: (error, nr) => {
|
|
99
|
+
this.save();
|
|
100
|
+
this.log();
|
|
101
|
+
},
|
|
102
|
+
onComplete: () => {
|
|
103
|
+
this.onEndPromise?.resolve();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
this.isRestored = true;
|
|
107
|
+
}
|
|
108
|
+
// private async setFromBlockNumber (nr: number): Promise<this> {
|
|
109
|
+
// this.walker.setFrom(nr);
|
|
110
|
+
// return this;
|
|
111
|
+
// }
|
|
112
|
+
// private async setFromBlockDate(date: Date): Promise<this> {
|
|
113
|
+
// let dateResolver = di.resolve(BlockDateResolver, this.client)
|
|
114
|
+
// let nr = await dateResolver.getBlockNumberFor(date);
|
|
115
|
+
// return this.setFromBlockNumber(nr);
|
|
116
|
+
// }
|
|
117
|
+
// private async setToBlockNumber (nr: number): Promise<this> {
|
|
118
|
+
// if (this.isRestored === false) {
|
|
119
|
+
// await this.restore();
|
|
120
|
+
// }
|
|
121
|
+
// this.walker.setTo(nr);
|
|
122
|
+
// return this;
|
|
123
|
+
// }
|
|
124
|
+
// private async setToBlockDate(date: Date): Promise<this> {
|
|
125
|
+
// let dateResolver = di.resolve(BlockDateResolver, this.client)
|
|
126
|
+
// let nr = await dateResolver.getBlockNumberFor(date);
|
|
127
|
+
// return this.setToBlockNumber(nr);
|
|
128
|
+
// }
|
|
129
|
+
async getBlockNumber(mix) {
|
|
130
|
+
if (mix == null) {
|
|
131
|
+
return this.client.getBlockNumber();
|
|
132
|
+
}
|
|
133
|
+
if (typeof mix === 'number') {
|
|
134
|
+
return mix;
|
|
135
|
+
}
|
|
136
|
+
if (mix instanceof Date) {
|
|
137
|
+
let dateResolver = a_di_1.default.resolve(BlockDateResolver_1.BlockDateResolver, this.client);
|
|
138
|
+
return await dateResolver.getBlockNumberFor(mix);
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Invalid getBlockNumber param: ${mix}`);
|
|
141
|
+
}
|
|
142
|
+
async processBlock(nr) {
|
|
143
|
+
// reading block and transactions
|
|
144
|
+
let start = Date.now();
|
|
145
|
+
let block = await this.client.getBlock(nr);
|
|
146
|
+
let txs = null;
|
|
147
|
+
if (this.params.loadTransactions !== false) {
|
|
148
|
+
let hashes = block.transactions;
|
|
149
|
+
txs = await (0, alot_1.default)(hashes).mapAsync(async (hash) => {
|
|
150
|
+
return this.client.getTransaction(hash);
|
|
151
|
+
}).toArrayAsync({ threads: 8 });
|
|
152
|
+
}
|
|
153
|
+
this.status.blockLoadTime = Date.now() - start;
|
|
154
|
+
await this.visitor(block, txs);
|
|
155
|
+
}
|
|
156
|
+
async save() {
|
|
157
|
+
if (this.params.persistance !== false) {
|
|
158
|
+
let json = this.ranges.serialize();
|
|
159
|
+
await this.cachedState?.writeAsync(json);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async log() {
|
|
163
|
+
let error = this.walker.pluckLastErrorMessage();
|
|
164
|
+
let row = [
|
|
165
|
+
new Date().toISOString(),
|
|
166
|
+
this.walker.range.total(),
|
|
167
|
+
this.walker.range.totalLeft(),
|
|
168
|
+
`${this.walker.status.avgTime}ms`,
|
|
169
|
+
this.walker.avgTimeLeft(),
|
|
170
|
+
`${this.status.blockLoadTime}ms`,
|
|
171
|
+
this.walker.status.errors,
|
|
172
|
+
error,
|
|
173
|
+
];
|
|
174
|
+
this.fs.writeRow(row);
|
|
175
|
+
_logger_1.$logger.log(row.join());
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
__decorate([
|
|
179
|
+
memd_1.default.deco.memoize()
|
|
180
|
+
], BlocksWalker.prototype, "restore", null);
|
|
181
|
+
__decorate([
|
|
182
|
+
memd_1.default.deco.throttle(1000 * 4)
|
|
183
|
+
], BlocksWalker.prototype, "save", null);
|
|
184
|
+
__decorate([
|
|
185
|
+
memd_1.default.deco.throttle(1000 * 5)
|
|
186
|
+
], BlocksWalker.prototype, "log", null);
|
|
187
|
+
exports.BlocksWalker = BlocksWalker;
|
|
188
|
+
class RangeWalker {
|
|
189
|
+
constructor(params) {
|
|
190
|
+
this.opts = {
|
|
191
|
+
threads: 1,
|
|
192
|
+
timeout: 20000,
|
|
193
|
+
// log every N ms
|
|
194
|
+
logTimeWindow: 5000,
|
|
195
|
+
};
|
|
196
|
+
this.status = {
|
|
197
|
+
errors: 0,
|
|
198
|
+
processed: 0,
|
|
199
|
+
avgTime: 0,
|
|
200
|
+
};
|
|
201
|
+
this.busy = [];
|
|
202
|
+
this.errors = [];
|
|
203
|
+
this.range = params.range;
|
|
204
|
+
this.onVisit = params.onVisit;
|
|
205
|
+
this.onResult = params.onResult;
|
|
206
|
+
this.onComplete = params.onComplete;
|
|
207
|
+
}
|
|
208
|
+
stats() {
|
|
209
|
+
return {
|
|
210
|
+
...this.status,
|
|
211
|
+
busy: this.busy,
|
|
212
|
+
errors: this.errors,
|
|
213
|
+
from: this.range.from,
|
|
214
|
+
to: this.range.to,
|
|
215
|
+
totalLeft: this.range.totalLeft(),
|
|
216
|
+
totalTimeLeft: this.avgTimeLeft()
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
setFrom(nr) {
|
|
220
|
+
this.range.from = nr;
|
|
221
|
+
}
|
|
222
|
+
setTo(nr) {
|
|
223
|
+
let { from } = this.range;
|
|
224
|
+
if (from != null && from > nr) {
|
|
225
|
+
throw new Error(`To (${nr}) should be greater then From (${from})`);
|
|
226
|
+
}
|
|
227
|
+
this.range.to = nr;
|
|
228
|
+
}
|
|
229
|
+
process(toBlock) {
|
|
230
|
+
if (toBlock != null) {
|
|
231
|
+
let to = Math.max(toBlock, this.range.to ?? 0);
|
|
232
|
+
this.range.to = to;
|
|
233
|
+
if (this.range.from == null) {
|
|
234
|
+
// In case we started the walker by listening to incoming mined blocks
|
|
235
|
+
this.range.from = to;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
this.onCompleted = new atma_utils_1.class_Dfr;
|
|
239
|
+
let i = Math.max(this.opts.threads - this.busy.length, 0);
|
|
240
|
+
while (--i > -1) {
|
|
241
|
+
this.tick();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
pluckLastError() {
|
|
245
|
+
let err = this.lastError;
|
|
246
|
+
this.lastError = null;
|
|
247
|
+
return err;
|
|
248
|
+
}
|
|
249
|
+
pluckLastErrorMessage() {
|
|
250
|
+
let err = this.pluckLastError();
|
|
251
|
+
if (err == null) {
|
|
252
|
+
return '';
|
|
253
|
+
}
|
|
254
|
+
return `Date: ${new Date(err.startedAt).toISOString()} Nr: ${err.nr}. Duration: ${err.duration}ms; Error: ${err.error.message}`;
|
|
255
|
+
}
|
|
256
|
+
avgTimeLeft() {
|
|
257
|
+
let avgTime = this.status.avgTime;
|
|
258
|
+
let leftBlocks = this.range.totalLeft();
|
|
259
|
+
let ms = avgTime * leftBlocks;
|
|
260
|
+
return _date_1.$date.formatTimespan(ms);
|
|
261
|
+
}
|
|
262
|
+
async tick() {
|
|
263
|
+
if (this.busy.length > this.opts.threads) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
let next = this.range.next();
|
|
267
|
+
if (next == null) {
|
|
268
|
+
this.onComplete?.();
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
let workerData = {
|
|
272
|
+
nr: next,
|
|
273
|
+
startedAt: Date.now()
|
|
274
|
+
};
|
|
275
|
+
let error = null;
|
|
276
|
+
try {
|
|
277
|
+
this.busy.push(workerData);
|
|
278
|
+
await this.onVisit(next);
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
_logger_1.$logger.log('BlocksWalker.tick error', err);
|
|
282
|
+
error = err;
|
|
283
|
+
}
|
|
284
|
+
this.onResult?.(error, workerData.nr);
|
|
285
|
+
this.onTickComplete(workerData, error);
|
|
286
|
+
}
|
|
287
|
+
onTickComplete(workerData, error) {
|
|
288
|
+
if (error != null) {
|
|
289
|
+
this.lastError = {
|
|
290
|
+
...workerData,
|
|
291
|
+
duration: Date.now() - workerData.startedAt,
|
|
292
|
+
error
|
|
293
|
+
};
|
|
294
|
+
this.errors.push(this.lastError);
|
|
295
|
+
this.status.errors += 1;
|
|
296
|
+
_logger_1.$logger.log(error);
|
|
297
|
+
}
|
|
298
|
+
let time = Date.now() - workerData.startedAt;
|
|
299
|
+
let prevAvgTime = this.status.avgTime;
|
|
300
|
+
let prevTotal = this.status.processed;
|
|
301
|
+
this.status.avgTime = Math.round((prevAvgTime * prevTotal + time) / (prevTotal + 1));
|
|
302
|
+
this.status.processed += 1;
|
|
303
|
+
_array_1.$array.remove(this.busy, workerData);
|
|
304
|
+
this.tick();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TxQueueLoader = void 0;
|
|
4
|
+
const _number_1 = require("@dequanto/utils/$number");
|
|
5
|
+
class TxQueueLoader {
|
|
6
|
+
constructor(client, cb) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
this.opts = {
|
|
10
|
+
threads: 4,
|
|
11
|
+
timeout: 20000,
|
|
12
|
+
// log every N ms
|
|
13
|
+
logTimeWindow: 5000,
|
|
14
|
+
};
|
|
15
|
+
this.status = {
|
|
16
|
+
errors: 0,
|
|
17
|
+
processed: 0,
|
|
18
|
+
avgLoadTime: 0,
|
|
19
|
+
};
|
|
20
|
+
this.busy = [];
|
|
21
|
+
this.errors = [];
|
|
22
|
+
this.queue = [];
|
|
23
|
+
this.seen = [];
|
|
24
|
+
}
|
|
25
|
+
push(hash) {
|
|
26
|
+
if (this.seen.includes(hash) === false) {
|
|
27
|
+
this.queue.push(hash);
|
|
28
|
+
this.seen.unshift(hash);
|
|
29
|
+
if (this.seen.length > 2000) {
|
|
30
|
+
this.seen = this.seen.slice(0, 1000);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
this.tick();
|
|
34
|
+
}
|
|
35
|
+
stats() {
|
|
36
|
+
return {
|
|
37
|
+
counts: {
|
|
38
|
+
loading: this.busy.length,
|
|
39
|
+
pending: this.queue.length,
|
|
40
|
+
processed: this.status.processed,
|
|
41
|
+
errors: this.status.errors,
|
|
42
|
+
},
|
|
43
|
+
errors: this.errors,
|
|
44
|
+
error: this.errors.length > 0
|
|
45
|
+
? this.errors[this.errors.length - 1]?.error?.message
|
|
46
|
+
: null,
|
|
47
|
+
avgLoadTime: this.status.avgLoadTime,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
tick() {
|
|
51
|
+
if (this.busy.length >= this.opts.threads) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (this.queue.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let hash = this.queue.shift();
|
|
58
|
+
let loader = new TxLoader(this.client, hash);
|
|
59
|
+
this.busy.push(loader);
|
|
60
|
+
loader
|
|
61
|
+
.load()
|
|
62
|
+
.then(tx => {
|
|
63
|
+
this.onSuccess(tx);
|
|
64
|
+
this.onCompleted(loader);
|
|
65
|
+
}, err => {
|
|
66
|
+
this.onError(err, hash);
|
|
67
|
+
this.onCompleted(loader);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
onSuccess(tx) {
|
|
71
|
+
this.cb(tx);
|
|
72
|
+
}
|
|
73
|
+
onCompleted(loader) {
|
|
74
|
+
let i = this.busy.indexOf(loader);
|
|
75
|
+
this.busy.splice(i, 1);
|
|
76
|
+
let totalCount = this.status.processed;
|
|
77
|
+
let totalSeconds = this.status.avgLoadTime * totalCount;
|
|
78
|
+
this.status.avgLoadTime = _number_1.$number.round((totalSeconds * totalCount + loader.seconds) / (totalCount + 1));
|
|
79
|
+
this.status.processed++;
|
|
80
|
+
this.tick();
|
|
81
|
+
}
|
|
82
|
+
onError(err, hash) {
|
|
83
|
+
this.status.errors++;
|
|
84
|
+
this.status.processed++;
|
|
85
|
+
let error = {
|
|
86
|
+
hash,
|
|
87
|
+
date: new Date(),
|
|
88
|
+
error: err
|
|
89
|
+
};
|
|
90
|
+
this.errors.push(error);
|
|
91
|
+
this.lastError = error;
|
|
92
|
+
const MAX_ERRORS = 200;
|
|
93
|
+
if (this.errors.length > 200) {
|
|
94
|
+
this.errors.splice(0, MAX_ERRORS / 2);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.TxQueueLoader = TxQueueLoader;
|
|
99
|
+
class TxLoader {
|
|
100
|
+
constructor(client, hash) {
|
|
101
|
+
this.client = client;
|
|
102
|
+
this.hash = hash;
|
|
103
|
+
}
|
|
104
|
+
async load() {
|
|
105
|
+
this.started = Date.now();
|
|
106
|
+
try {
|
|
107
|
+
let tx = await this.client.getTransaction(this.hash, { ws: false });
|
|
108
|
+
return tx;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
this.seconds = (Date.now() - this.started) / 1000 | 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|