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,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientEventsStream = void 0;
|
|
4
|
+
class ClientEventsStream {
|
|
5
|
+
constructor(contract, eventAbi, stream) {
|
|
6
|
+
this.contract = contract;
|
|
7
|
+
this.eventAbi = eventAbi;
|
|
8
|
+
this.stream = stream;
|
|
9
|
+
}
|
|
10
|
+
onData(cb) {
|
|
11
|
+
this.stream.on('data', (event) => {
|
|
12
|
+
let inputs = this.eventAbi.inputs.map(arg => {
|
|
13
|
+
let val = event.returnValues[arg.name];
|
|
14
|
+
return val;
|
|
15
|
+
});
|
|
16
|
+
cb(event, ...inputs);
|
|
17
|
+
});
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
onConnected(cb) {
|
|
21
|
+
this.stream.on('connected', data => {
|
|
22
|
+
console.log('CONNECTED', data);
|
|
23
|
+
cb(data);
|
|
24
|
+
});
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
onError(cb) {
|
|
28
|
+
this.stream.on('error', error => {
|
|
29
|
+
cb(error);
|
|
30
|
+
});
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.ClientEventsStream = ClientEventsStream;
|
|
@@ -0,0 +1,560 @@
|
|
|
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.ClientPool = void 0;
|
|
13
|
+
const alot_1 = __importDefault(require("alot"));
|
|
14
|
+
const memd_1 = __importDefault(require("memd"));
|
|
15
|
+
const web3_1 = __importDefault(require("web3"));
|
|
16
|
+
const _date_1 = require("@dequanto/utils/$date");
|
|
17
|
+
const _number_1 = require("@dequanto/utils/$number");
|
|
18
|
+
const PromiEventWrap_1 = require("./model/PromiEventWrap");
|
|
19
|
+
const ClientStatus_1 = require("./model/ClientStatus");
|
|
20
|
+
const ClientPoolStats_1 = require("./ClientPoolStats");
|
|
21
|
+
const atma_utils_1 = require("atma-utils");
|
|
22
|
+
const ClientEventsStream_1 = require("./ClientEventsStream");
|
|
23
|
+
const ClientErrorUtil_1 = require("./utils/ClientErrorUtil");
|
|
24
|
+
const _fn_1 = require("@dequanto/utils/$fn");
|
|
25
|
+
class ClientPool {
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.discoveredPartial = false;
|
|
29
|
+
this.discoveredFull = false;
|
|
30
|
+
this.clients = this.config.map(cfg => new WClient(cfg));
|
|
31
|
+
if (this.clients.length < 2) {
|
|
32
|
+
this.discoveredPartial = true;
|
|
33
|
+
this.discoveredFull = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
callSync(fn) {
|
|
37
|
+
let arr = this.clients.filter(x => x.status === 'ok');
|
|
38
|
+
let wClient = arr[_number_1.$number.randomInt(0, arr.length)];
|
|
39
|
+
let { status, result } = wClient.callSync(fn);
|
|
40
|
+
if (status == ClientStatus_1.ClientStatus.Ok) {
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
throw result;
|
|
44
|
+
}
|
|
45
|
+
async call(fn, opts) {
|
|
46
|
+
let used = new Map();
|
|
47
|
+
let errors = [];
|
|
48
|
+
while (true) {
|
|
49
|
+
let wClient = await this.next(used, opts);
|
|
50
|
+
if (wClient == null) {
|
|
51
|
+
let error = errors.pop();
|
|
52
|
+
if (error == null) {
|
|
53
|
+
let urls = this
|
|
54
|
+
.clients
|
|
55
|
+
.map(x => ` ${x.config.url}`)
|
|
56
|
+
.join('\n');
|
|
57
|
+
error = new Error(`Live clients not found in \n${urls}`);
|
|
58
|
+
}
|
|
59
|
+
throw ClientPoolStats_1.ClientPoolTraceError.create(error, opts?.trace);
|
|
60
|
+
}
|
|
61
|
+
let { status, result, error, time } = await wClient.call(fn);
|
|
62
|
+
opts
|
|
63
|
+
?.trace
|
|
64
|
+
?.onComplete({ status, error, time, url: wClient.config.url });
|
|
65
|
+
used.set(wClient, 1);
|
|
66
|
+
errors.push(error ?? result);
|
|
67
|
+
if (status == ClientStatus_1.ClientStatus.Ok) {
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
if (status === ClientStatus_1.ClientStatus.CallError) {
|
|
71
|
+
let error = ClientPoolStats_1.ClientPoolTraceError.create(errors.pop(), opts?.trace);
|
|
72
|
+
//console.log(`Errored ${error.message}`);
|
|
73
|
+
throw error;
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async getWeb3(options) {
|
|
79
|
+
let wClient = await this.next(null, options);
|
|
80
|
+
if (wClient == null) {
|
|
81
|
+
throw new Error(`Not client found in ${this.clients.length} Clients`);
|
|
82
|
+
}
|
|
83
|
+
return wClient?.web3;
|
|
84
|
+
}
|
|
85
|
+
async getNodeURL(options) {
|
|
86
|
+
let wClient = await this.next(null, options);
|
|
87
|
+
if (wClient == null) {
|
|
88
|
+
throw new Error(`Not client found in ${this.clients.length} Clients`);
|
|
89
|
+
}
|
|
90
|
+
return wClient?.config.url;
|
|
91
|
+
}
|
|
92
|
+
async releaseWeb3() {
|
|
93
|
+
}
|
|
94
|
+
callPromiEvent(fn, opts, used = new Map(), errors = [], root) {
|
|
95
|
+
root = root ?? new PromiEventWrap_1.PromiEventWrap();
|
|
96
|
+
(async () => {
|
|
97
|
+
let wClient = await this.next(used, opts);
|
|
98
|
+
if (wClient == null) {
|
|
99
|
+
if (opts?.silent) {
|
|
100
|
+
return root;
|
|
101
|
+
}
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
let urls = this
|
|
104
|
+
.clients
|
|
105
|
+
.map(x => ` ${x.config.url}`)
|
|
106
|
+
.join('\n');
|
|
107
|
+
let error = new Error(`Live clients not found in \n${urls}`);
|
|
108
|
+
root.emit('error', error);
|
|
109
|
+
root.reject(error);
|
|
110
|
+
});
|
|
111
|
+
return root;
|
|
112
|
+
}
|
|
113
|
+
let promiEvent = wClient.callPromiEvent(fn);
|
|
114
|
+
root.bind(promiEvent);
|
|
115
|
+
promiEvent.on('error', async (error) => {
|
|
116
|
+
console.log('!!client ERROR', error);
|
|
117
|
+
error.message += ` (RPC: ${wClient.config.url})`;
|
|
118
|
+
if (ClientErrorUtil_1.ClientErrorUtil.isConnectionFailed(error)) {
|
|
119
|
+
this.callPromiEvent(fn, opts, used, errors, root);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (ClientErrorUtil_1.ClientErrorUtil.isAlreadyKnown(error)) {
|
|
123
|
+
console.log(`TxWriter ERROR ${error.message}. Check pending...`);
|
|
124
|
+
let web3 = await this.getWeb3();
|
|
125
|
+
let txs = await web3.eth.getPendingTransactions();
|
|
126
|
+
console.log('PENDING ', txs?.map(x => x.hash));
|
|
127
|
+
// throw anyways
|
|
128
|
+
// this.callPromiEvent(
|
|
129
|
+
// fn, opts, used, errors, root
|
|
130
|
+
// );
|
|
131
|
+
// return;
|
|
132
|
+
}
|
|
133
|
+
root.emit('error', error);
|
|
134
|
+
root.reject(error);
|
|
135
|
+
});
|
|
136
|
+
promiEvent.catch(error => {
|
|
137
|
+
console.log('!!client CATCH', error);
|
|
138
|
+
//root.reject(error);
|
|
139
|
+
});
|
|
140
|
+
used.set(wClient, 1);
|
|
141
|
+
if (typeof opts?.parallel === 'number') {
|
|
142
|
+
while (--opts.parallel > 0) {
|
|
143
|
+
this.callPromiEvent(fn, {
|
|
144
|
+
...opts,
|
|
145
|
+
distinct: true,
|
|
146
|
+
parallel: null,
|
|
147
|
+
silent: true
|
|
148
|
+
}, used, errors, root);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
})();
|
|
152
|
+
return root;
|
|
153
|
+
}
|
|
154
|
+
getEventStream(address, abi, event) {
|
|
155
|
+
if (this.ws == null) {
|
|
156
|
+
this.ws = this.clients.find(x => x.config.url.startsWith('ws'));
|
|
157
|
+
}
|
|
158
|
+
let stream = this.ws.getEventStream(address, abi, event);
|
|
159
|
+
return stream;
|
|
160
|
+
}
|
|
161
|
+
getNodeStats() {
|
|
162
|
+
return this
|
|
163
|
+
.clients
|
|
164
|
+
.filter(client => client.getRequestCount() > 0)
|
|
165
|
+
.map(client => {
|
|
166
|
+
return {
|
|
167
|
+
url: client.config.url,
|
|
168
|
+
...client.requests
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async getNodeInfos() {
|
|
173
|
+
let nodes = await (0, alot_1.default)(this.clients).mapAsync(async (wClient, idx) => {
|
|
174
|
+
let url = wClient.config.url;
|
|
175
|
+
try {
|
|
176
|
+
let start = Date.now();
|
|
177
|
+
let [syncing, blockNumber, peers] = await Promise.all([
|
|
178
|
+
wClient.eth.isSyncing(),
|
|
179
|
+
wClient.eth.getBlockNumber(),
|
|
180
|
+
/** @TODO Public nodes smt. do not allow net_peerCount methods. Allow to switch this on/off on node-url-config level */
|
|
181
|
+
wClient.eth.net.getPeerCount(),
|
|
182
|
+
]);
|
|
183
|
+
let ping = Math.round((Date.now() - start) / 3);
|
|
184
|
+
let syncData = typeof syncing === 'boolean' ? null : syncing;
|
|
185
|
+
return {
|
|
186
|
+
url: url,
|
|
187
|
+
status: 'live',
|
|
188
|
+
syncing: syncData,
|
|
189
|
+
blockNumber: blockNumber,
|
|
190
|
+
blockNumberBehind: 0,
|
|
191
|
+
peers: peers,
|
|
192
|
+
pingMs: ping,
|
|
193
|
+
i: idx,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
return {
|
|
198
|
+
url,
|
|
199
|
+
status: 'error',
|
|
200
|
+
error: error,
|
|
201
|
+
peers: 0,
|
|
202
|
+
i: idx,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}).toArrayAsync();
|
|
206
|
+
let max = (0, alot_1.default)(nodes).max(x => x.syncing?.highestBlock ?? x.syncing?.HighestBlock ?? x.blockNumber);
|
|
207
|
+
nodes.forEach(node => {
|
|
208
|
+
node.blockNumberBehind = node.blockNumber - max;
|
|
209
|
+
});
|
|
210
|
+
return nodes;
|
|
211
|
+
}
|
|
212
|
+
// callSubscribtion <TResult> (
|
|
213
|
+
// event: any
|
|
214
|
+
// , cb: (error, result) => void
|
|
215
|
+
// , opts?: { preferSafe?: boolean }
|
|
216
|
+
// , used: Map<WClient, number> = new Map<WClient, number>()
|
|
217
|
+
// , errors = []
|
|
218
|
+
// , root?: PromiEventWrap
|
|
219
|
+
// ) {
|
|
220
|
+
// root = root ?? new PromiEventWrap();
|
|
221
|
+
// let wClient = this.next(used);
|
|
222
|
+
// if (wClient == null) {
|
|
223
|
+
// setTimeout(() => {
|
|
224
|
+
// let error = new Error('Clients not found');
|
|
225
|
+
// root.emit('error', error);
|
|
226
|
+
// root.reject(error);
|
|
227
|
+
// });
|
|
228
|
+
// return root as any as TResult;
|
|
229
|
+
// }
|
|
230
|
+
// let promiEvent = wClient.callSubscription(fn);
|
|
231
|
+
// root.bind(promiEvent);
|
|
232
|
+
// promiEvent.on('error', error => {
|
|
233
|
+
// if (ErrorUtil.isConnectionFailed(error)) {
|
|
234
|
+
// this.callPromiEvent(
|
|
235
|
+
// fn, opts, used, errors, root
|
|
236
|
+
// );
|
|
237
|
+
// return;
|
|
238
|
+
// }
|
|
239
|
+
// root.emit('error', error);
|
|
240
|
+
// root.reject(error);
|
|
241
|
+
// });
|
|
242
|
+
// used.set(wClient, 1);
|
|
243
|
+
// return root as any as TResult;
|
|
244
|
+
// }
|
|
245
|
+
async next(used, opts) {
|
|
246
|
+
if (opts?.ws === true) {
|
|
247
|
+
if (this.ws == null) {
|
|
248
|
+
this.ws = this.clients.find(x => x.config.url.startsWith('ws'));
|
|
249
|
+
}
|
|
250
|
+
return this.ws;
|
|
251
|
+
}
|
|
252
|
+
let clients = this.clients;
|
|
253
|
+
if (opts?.ws === false) {
|
|
254
|
+
clients = this.clients.filter(x => x.config.url.startsWith('http'));
|
|
255
|
+
}
|
|
256
|
+
if (this.discoveredPartial === false) {
|
|
257
|
+
await this.discoverLive().ready;
|
|
258
|
+
this.discoveredPartial = true;
|
|
259
|
+
}
|
|
260
|
+
// we check OK clients first
|
|
261
|
+
let okClients = clients.filter(x => x.status === 'ok');
|
|
262
|
+
if (okClients.length === 0) {
|
|
263
|
+
// then switch to at least not off
|
|
264
|
+
let notOffClients = clients.filter(x => x.status !== 'off');
|
|
265
|
+
if (notOffClients) {
|
|
266
|
+
clients = notOffClients;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
clients = okClients;
|
|
271
|
+
}
|
|
272
|
+
let available = used == null
|
|
273
|
+
? clients
|
|
274
|
+
: clients.filter(x => used.has(x) === false);
|
|
275
|
+
if (available.length === 0) {
|
|
276
|
+
if (this.discoveredFull === false) {
|
|
277
|
+
await this.discoverLive().completed;
|
|
278
|
+
this.discoveredFull = true;
|
|
279
|
+
return this.next(used, opts);
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
let healthy = available.filter(x => x.healthy());
|
|
284
|
+
if (opts?.preferSafe === true) {
|
|
285
|
+
let safe = healthy.filter(x => x.config.safe === true);
|
|
286
|
+
if (safe.length > 0) {
|
|
287
|
+
healthy = safe;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (opts?.distinct === true) {
|
|
291
|
+
let safe = healthy.filter(x => x.config.distinct === true);
|
|
292
|
+
if (safe.length > 0) {
|
|
293
|
+
healthy = safe;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
let arr = healthy.length > 0
|
|
297
|
+
? healthy
|
|
298
|
+
: available;
|
|
299
|
+
let i = _number_1.$number.randomInt(0, arr.length);
|
|
300
|
+
let client = arr[i];
|
|
301
|
+
return client;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* We may have tens of Nodes to communicate with. Discover LIVE and operating nodes.
|
|
305
|
+
* Resolves when first 3 active nodes are discovered, to prevent waiting for all of them.
|
|
306
|
+
* @returns
|
|
307
|
+
* - Ready Promise - in case 3 clients look good
|
|
308
|
+
* - Complete Promise - when all clients are resolved
|
|
309
|
+
*/
|
|
310
|
+
discoverLive() {
|
|
311
|
+
this.clients.forEach(x => x.status = 'ping');
|
|
312
|
+
let ready = new atma_utils_1.class_Dfr();
|
|
313
|
+
let completed = new atma_utils_1.class_Dfr();
|
|
314
|
+
let clientInfos = [];
|
|
315
|
+
let isReady = false;
|
|
316
|
+
let isCompleted = false;
|
|
317
|
+
let clients = this.clients;
|
|
318
|
+
(async () => {
|
|
319
|
+
let nodeInfosAsync = clients.map(async (wClient, idx) => {
|
|
320
|
+
try {
|
|
321
|
+
let clientInfo = {
|
|
322
|
+
i: idx,
|
|
323
|
+
error: null,
|
|
324
|
+
status: null,
|
|
325
|
+
blockNumberBehind: 0,
|
|
326
|
+
blockNumber: await _fn_1.$fn.timeoutPromise(wClient.eth.getBlockNumber(), 20000)
|
|
327
|
+
};
|
|
328
|
+
onIntermediateSuccess(clientInfo);
|
|
329
|
+
return clientInfo;
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
return {
|
|
333
|
+
i: idx,
|
|
334
|
+
error: error,
|
|
335
|
+
status: 'off',
|
|
336
|
+
blockNumberBehind: 0,
|
|
337
|
+
blockNumber: 0
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
let nodeInfos = await Promise.all(nodeInfosAsync);
|
|
342
|
+
let hasLive = nodeInfos.some(x => x.status === 'ok');
|
|
343
|
+
if (hasLive === false) {
|
|
344
|
+
let messages = nodeInfos.map(x => {
|
|
345
|
+
let url = clients[x.i]?.config.url;
|
|
346
|
+
let message = x.error?.message;
|
|
347
|
+
return ` ${url}: ${message}`;
|
|
348
|
+
}).join('\n');
|
|
349
|
+
let fullMessage = `No live nodes found: \n ${messages}`;
|
|
350
|
+
let error = new Error(fullMessage);
|
|
351
|
+
completed.reject(error);
|
|
352
|
+
ready.reject(error);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const blockLatest = (0, alot_1.default)(nodeInfos).max(x => x.blockNumber);
|
|
356
|
+
nodeInfos.forEach(node => {
|
|
357
|
+
node.blockNumberBehind = node.blockNumber - blockLatest;
|
|
358
|
+
});
|
|
359
|
+
nodeInfos.forEach(info => {
|
|
360
|
+
this.clients[info.i].status = isOk(info);
|
|
361
|
+
});
|
|
362
|
+
isCompleted = true;
|
|
363
|
+
completed.resolve();
|
|
364
|
+
if (isReady !== true) {
|
|
365
|
+
isReady = true;
|
|
366
|
+
ready.resolve();
|
|
367
|
+
}
|
|
368
|
+
})();
|
|
369
|
+
function isOk(info) {
|
|
370
|
+
if (info.error) {
|
|
371
|
+
return 'off';
|
|
372
|
+
}
|
|
373
|
+
if (isNaN(info.blockNumber) || info.blockNumberBehind < -200) {
|
|
374
|
+
return 'off';
|
|
375
|
+
}
|
|
376
|
+
return 'ok';
|
|
377
|
+
}
|
|
378
|
+
function onIntermediateSuccess(info) {
|
|
379
|
+
const TOLERATE_BLOCK_COUNT = 5;
|
|
380
|
+
const WAIT_POOL_OK = Math.min(3, clientInfos.length);
|
|
381
|
+
if (isReady === true) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (clientInfos.push(info) < WAIT_POOL_OK) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
let maxBlockNumber = (0, alot_1.default)(clientInfos).max(x => x.blockNumber);
|
|
388
|
+
let ok = [];
|
|
389
|
+
for (let info of clientInfos) {
|
|
390
|
+
let diff = Math.abs(info.blockNumber - maxBlockNumber);
|
|
391
|
+
if (diff <= TOLERATE_BLOCK_COUNT) {
|
|
392
|
+
ok.push(info);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (ok.length >= WAIT_POOL_OK) {
|
|
396
|
+
ok.forEach(info => {
|
|
397
|
+
clients[info.i].status = 'ok';
|
|
398
|
+
});
|
|
399
|
+
isReady = true;
|
|
400
|
+
ready.resolve();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return { ready, completed };
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
__decorate([
|
|
407
|
+
memd_1.default.deco.memoize({ perInstance: true })
|
|
408
|
+
], ClientPool.prototype, "discoverLive", null);
|
|
409
|
+
exports.ClientPool = ClientPool;
|
|
410
|
+
class WClient {
|
|
411
|
+
constructor(config) {
|
|
412
|
+
this.config = config;
|
|
413
|
+
this.lastStatus = 0;
|
|
414
|
+
this.lastDate = new Date(2000);
|
|
415
|
+
this.status = 'ok';
|
|
416
|
+
this.requests = {
|
|
417
|
+
success: 0,
|
|
418
|
+
fail: 0,
|
|
419
|
+
ping: 0
|
|
420
|
+
};
|
|
421
|
+
this.web3 = new web3_1.default(config.url);
|
|
422
|
+
this.web3.eth.handleRevert = true;
|
|
423
|
+
this.eth = this.web3.eth;
|
|
424
|
+
}
|
|
425
|
+
healthy() {
|
|
426
|
+
if (this.getRequestCount() === 0) {
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
if (this.requests.fail === 0) {
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
let health = this.requests.fail / this.getRequestCount();
|
|
433
|
+
if (health > .5) {
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
if (Date.now() - this.lastDate.getTime() > _date_1.$date.parseTimespan('10m')) {
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
async send(fn) {
|
|
442
|
+
return new Promise((resolve, reject) => {
|
|
443
|
+
let result = fn(this.web3);
|
|
444
|
+
result.then(_ => {
|
|
445
|
+
this.lastStatus = ClientStatus_1.ClientStatus.Ok;
|
|
446
|
+
this.requests.success++;
|
|
447
|
+
resolve({ status: ClientStatus_1.ClientStatus.Ok, result });
|
|
448
|
+
}, error => {
|
|
449
|
+
if (ClientErrorUtil_1.ClientErrorUtil.isConnectionFailed(error)) {
|
|
450
|
+
this.lastStatus = ClientStatus_1.ClientStatus.NetworkError;
|
|
451
|
+
this.requests.fail++;
|
|
452
|
+
resolve({ status: ClientStatus_1.ClientStatus.NetworkError, error });
|
|
453
|
+
}
|
|
454
|
+
return resolve({ status: ClientStatus_1.ClientStatus.CallError, result: error });
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
// async call <TResult> (fn: (web3: Web3) => Promise<TResult> ): Promise<{ status: number, result?: TResult }> {
|
|
459
|
+
// try {
|
|
460
|
+
// let result = await fn(this.web3);
|
|
461
|
+
// this.lastStatus = Status.Ok;
|
|
462
|
+
// this.requests.success++;
|
|
463
|
+
// return { status: Status.Ok, result };
|
|
464
|
+
// } catch (error) {
|
|
465
|
+
// console.log(error);
|
|
466
|
+
// if (this.isConnectionFailed (error)) {
|
|
467
|
+
// this.lastStatus = Status.NetworkError;
|
|
468
|
+
// this.requests.fail++;
|
|
469
|
+
// return { status: Status.NetworkError, result: error };
|
|
470
|
+
// }
|
|
471
|
+
// return { status: Status.CallError, result: error }
|
|
472
|
+
// }
|
|
473
|
+
// }
|
|
474
|
+
async call(fn) {
|
|
475
|
+
return new Promise((resolve, reject) => {
|
|
476
|
+
let start = Date.now();
|
|
477
|
+
let result = fn(this.web3);
|
|
478
|
+
result.then(_ => {
|
|
479
|
+
let time = Date.now() - start;
|
|
480
|
+
let status = ClientStatus_1.ClientStatus.Ok;
|
|
481
|
+
this.onComplete(status, time);
|
|
482
|
+
resolve({ status, result, time });
|
|
483
|
+
}, error => {
|
|
484
|
+
let time = Date.now() - start;
|
|
485
|
+
let status = ClientStatus_1.ClientStatus.CallError;
|
|
486
|
+
if (ClientErrorUtil_1.ClientErrorUtil.isConnectionFailed(error)) {
|
|
487
|
+
status = ClientStatus_1.ClientStatus.NetworkError;
|
|
488
|
+
}
|
|
489
|
+
this.onComplete(status, time);
|
|
490
|
+
resolve({ status, error, time });
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
callPromiEvent(fn) {
|
|
495
|
+
let result = fn(this.web3);
|
|
496
|
+
result.on('error', error => {
|
|
497
|
+
if (ClientErrorUtil_1.ClientErrorUtil.isConnectionFailed(error)) {
|
|
498
|
+
this.lastStatus = ClientStatus_1.ClientStatus.NetworkError;
|
|
499
|
+
this.requests.fail++;
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
result.on('transactionHash', hash => {
|
|
503
|
+
this.lastStatus = ClientStatus_1.ClientStatus.Ok;
|
|
504
|
+
this.requests.success++;
|
|
505
|
+
});
|
|
506
|
+
return result;
|
|
507
|
+
}
|
|
508
|
+
callSubscription(fn) {
|
|
509
|
+
let result = fn(this.web3);
|
|
510
|
+
result.on('error', error => {
|
|
511
|
+
if (ClientErrorUtil_1.ClientErrorUtil.isConnectionFailed(error)) {
|
|
512
|
+
this.lastStatus = ClientStatus_1.ClientStatus.NetworkError;
|
|
513
|
+
this.requests.fail++;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
result.on('transactionHash', hash => {
|
|
517
|
+
this.lastStatus = ClientStatus_1.ClientStatus.Ok;
|
|
518
|
+
this.requests.success++;
|
|
519
|
+
});
|
|
520
|
+
return result;
|
|
521
|
+
}
|
|
522
|
+
getEventStream(address, abi, event, options = {}) {
|
|
523
|
+
let eventAbi = abi.find(x => x.type === 'event' && x.name === event);
|
|
524
|
+
if (eventAbi == null) {
|
|
525
|
+
let events = abi.filter(x => x.type === 'event').map(x => x.name).join(', ');
|
|
526
|
+
throw new Error(`Event "${event}" not present in ABI. Events: ${events}`);
|
|
527
|
+
}
|
|
528
|
+
const contract = new this.eth.Contract(abi, address);
|
|
529
|
+
const stream = contract
|
|
530
|
+
.events[event](options);
|
|
531
|
+
const worker = new ClientEventsStream_1.ClientEventsStream(contract, eventAbi, stream);
|
|
532
|
+
return worker;
|
|
533
|
+
}
|
|
534
|
+
callSync(fn) {
|
|
535
|
+
try {
|
|
536
|
+
let result = fn(this.web3);
|
|
537
|
+
return { status: ClientStatus_1.ClientStatus.Ok, result };
|
|
538
|
+
}
|
|
539
|
+
catch (error) {
|
|
540
|
+
return { status: ClientStatus_1.ClientStatus.CallError, result: error };
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
onComplete(status, timeMs) {
|
|
544
|
+
let callCount = this.getRequestCount();
|
|
545
|
+
let ping = this.requests.ping;
|
|
546
|
+
this.lastStatus = status;
|
|
547
|
+
switch (status) {
|
|
548
|
+
case ClientStatus_1.ClientStatus.Ok:
|
|
549
|
+
this.requests.success++;
|
|
550
|
+
break;
|
|
551
|
+
default:
|
|
552
|
+
this.requests.fail++;
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
this.requests.ping = (ping * callCount + timeMs) / (callCount + 1);
|
|
556
|
+
}
|
|
557
|
+
getRequestCount() {
|
|
558
|
+
return this.requests.success + this.requests.fail;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientPoolStats = exports.ClientPoolTrace = exports.ClientPoolTraceError = void 0;
|
|
4
|
+
const _logger_1 = require("@dequanto/utils/$logger");
|
|
5
|
+
class ClientPoolStatsHandler {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.calls = [];
|
|
8
|
+
}
|
|
9
|
+
addCall(log) {
|
|
10
|
+
this.calls.push(log);
|
|
11
|
+
}
|
|
12
|
+
log() {
|
|
13
|
+
_logger_1.$logger.log(this.calls);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class ClientPoolTraceError extends Error {
|
|
17
|
+
static create($error, trace) {
|
|
18
|
+
let traceLog = trace?.toString() ?? '';
|
|
19
|
+
return {
|
|
20
|
+
name: $error.name,
|
|
21
|
+
stack: $error.stack,
|
|
22
|
+
message: traceLog + '\n' + $error.message
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ClientPoolTraceError = ClientPoolTraceError;
|
|
27
|
+
class ClientPoolTrace {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.calls = [];
|
|
30
|
+
}
|
|
31
|
+
onComplete(log) {
|
|
32
|
+
this.calls.push(log);
|
|
33
|
+
}
|
|
34
|
+
toString() {
|
|
35
|
+
return [
|
|
36
|
+
`${this.action} using clients:`,
|
|
37
|
+
...this.calls.map(call => {
|
|
38
|
+
return [
|
|
39
|
+
`${call.url} ${call.status} ${call.time}ms`,
|
|
40
|
+
`${call.error?.message}`
|
|
41
|
+
].join('\n');
|
|
42
|
+
})
|
|
43
|
+
].join('\n');
|
|
44
|
+
}
|
|
45
|
+
static createContractCall(address, methodName, ...args) {
|
|
46
|
+
let trace = new ClientPoolTrace();
|
|
47
|
+
trace.action = `Contact: ${address} ${methodName}(${args.join(', ')})`;
|
|
48
|
+
return trace;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ClientPoolTrace = ClientPoolTrace;
|
|
52
|
+
exports.ClientPoolStats = new ClientPoolStatsHandler();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EthWeb3Client = void 0;
|
|
7
|
+
const _config_1 = require("@dequanto/utils/$config");
|
|
8
|
+
const tx_1 = require("@ethereumjs/tx");
|
|
9
|
+
const common_1 = __importDefault(require("@ethereumjs/common"));
|
|
10
|
+
const Web3Client_1 = require("./Web3Client");
|
|
11
|
+
const ClientEndpoints_1 = require("./utils/ClientEndpoints");
|
|
12
|
+
class EthWeb3Client extends Web3Client_1.Web3Client {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super(ClientEndpoints_1.ClientEndpoints.filterEndpoints(_config_1.$config.get('web3.eth.endpoints'), opts));
|
|
15
|
+
this.platform = 'eth';
|
|
16
|
+
this.chainId = 1;
|
|
17
|
+
this.chainToken = 'ETH';
|
|
18
|
+
this.TIMEOUT = 15 * 60 * 1000;
|
|
19
|
+
this.defaultGasLimit = 2000000;
|
|
20
|
+
//let host = `192.168.1.220`;
|
|
21
|
+
// let host = `localhost`;
|
|
22
|
+
// this.web3 = new Web3(`ws://${host}:8546`);
|
|
23
|
+
// this.eth = this.web3.eth;
|
|
24
|
+
}
|
|
25
|
+
sign(txData, privateKey) {
|
|
26
|
+
const key = Buffer.from(privateKey, 'hex');
|
|
27
|
+
const common = new common_1.default({
|
|
28
|
+
chain: 'mainnet'
|
|
29
|
+
});
|
|
30
|
+
const tx = tx_1.Transaction.fromTxData(txData, { common });
|
|
31
|
+
const signedTx = tx.sign(key);
|
|
32
|
+
return signedTx.serialize();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.EthWeb3Client = EthWeb3Client;
|