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,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GasWatcherLogger = void 0;
|
|
4
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
5
|
+
const _date_1 = require("@dequanto/utils/$date");
|
|
6
|
+
const _logger_1 = require("@dequanto/utils/$logger");
|
|
7
|
+
const everlog_1 = require("everlog");
|
|
8
|
+
class GasWatcherLogger {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.channels = {
|
|
11
|
+
prices: everlog_1.Everlog.createChannel('gaswatcher-prices', {
|
|
12
|
+
columns: [
|
|
13
|
+
{
|
|
14
|
+
type: 'date',
|
|
15
|
+
name: 'Date'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: 'number',
|
|
19
|
+
name: 'Price(Gwei)'
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
}),
|
|
23
|
+
txs: everlog_1.Everlog.createChannel('gaswatcher-txs', {
|
|
24
|
+
columns: [
|
|
25
|
+
{
|
|
26
|
+
type: 'date',
|
|
27
|
+
name: 'Date'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'string',
|
|
31
|
+
name: 'ID'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'string',
|
|
35
|
+
name: 'Message'
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
logPrice(gasPrice, block) {
|
|
42
|
+
let date = new Date();
|
|
43
|
+
let gwei = _bigint_1.$bigint.toGweiFromWei(gasPrice);
|
|
44
|
+
_logger_1.$logger.log(`Gas ${block || ''} ${_date_1.$date.format(date, 'HH:mm')} ${gwei} GWEI`);
|
|
45
|
+
this.channels.prices.writeRow([
|
|
46
|
+
date,
|
|
47
|
+
gwei,
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
logTx(id, message) {
|
|
51
|
+
let date = new Date();
|
|
52
|
+
let str = `Tx ${_date_1.$date.format(date, 'HH:mm')} ${message}`;
|
|
53
|
+
_logger_1.$logger.log(str);
|
|
54
|
+
this.channels.txs.writeRow([
|
|
55
|
+
date,
|
|
56
|
+
id,
|
|
57
|
+
str
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.GasWatcherLogger = GasWatcherLogger;
|
|
@@ -0,0 +1,103 @@
|
|
|
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.GasWatcherService = void 0;
|
|
7
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
8
|
+
const alot_1 = __importDefault(require("alot"));
|
|
9
|
+
const GasWatcherLogger_1 = require("./GasWatcherLogger");
|
|
10
|
+
const GasWatcherStore_1 = require("./GasWatcherStore");
|
|
11
|
+
const GasWatcherTx_1 = require("./GasWatcherTx");
|
|
12
|
+
class GasWatcherService {
|
|
13
|
+
constructor(client, store) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.store = store;
|
|
16
|
+
this.pending = [];
|
|
17
|
+
this.logger = new GasWatcherLogger_1.GasWatcherLogger();
|
|
18
|
+
}
|
|
19
|
+
static async load(client, store = new GasWatcherStore_1.GasWatcherStore(client.platform)) {
|
|
20
|
+
let service = new GasWatcherService(client, store);
|
|
21
|
+
await service.loadTxs();
|
|
22
|
+
return service;
|
|
23
|
+
}
|
|
24
|
+
start() {
|
|
25
|
+
this.tick();
|
|
26
|
+
//setInterval(() => this.tick(), ms);
|
|
27
|
+
}
|
|
28
|
+
async tick() {
|
|
29
|
+
let start = Date.now();
|
|
30
|
+
let [block, priceInfo] = await Promise.all([
|
|
31
|
+
this.client.getBlockNumber(),
|
|
32
|
+
this.client.getGasPrice()
|
|
33
|
+
]);
|
|
34
|
+
let price = priceInfo.price;
|
|
35
|
+
this.logger.logPrice(price, block);
|
|
36
|
+
await this.store.savePrice({ date: new Date(), price });
|
|
37
|
+
await (0, alot_1.default)(this.pending)
|
|
38
|
+
.forEachAsync(async (entry) => {
|
|
39
|
+
await entry.tick(price);
|
|
40
|
+
})
|
|
41
|
+
.toArrayAsync();
|
|
42
|
+
// let end = Date.now();
|
|
43
|
+
// console.log(`Gas tick completed in ${$date.formatTimespan(end - start)}`);
|
|
44
|
+
let ms = 30000;
|
|
45
|
+
if (this.pending.length > 0) {
|
|
46
|
+
let expectPrice = (0, alot_1.default)(this.pending).max(x => x.condition.price);
|
|
47
|
+
if (expectPrice < price && price - expectPrice < 10) {
|
|
48
|
+
ms = 15000;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// if (expectPrice < price) {
|
|
52
|
+
// ms *= Number(price) / Number(expectPrice) * .5;
|
|
53
|
+
// }
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
this.tick();
|
|
56
|
+
}, ms);
|
|
57
|
+
}
|
|
58
|
+
async add(writer, condition) {
|
|
59
|
+
let writerJson = writer.toJSON();
|
|
60
|
+
let exists = this.pending.some(pending => {
|
|
61
|
+
let currentData = writer.builder.data;
|
|
62
|
+
let pendingData = pending.txWriter.builder.data;
|
|
63
|
+
let currentTo = currentData.to;
|
|
64
|
+
let pendingTo = pendingData.to;
|
|
65
|
+
if (currentTo !== pendingTo) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
let currentFrom = writer.account.address;
|
|
69
|
+
let pendingFrom = pending.txWriter.account.address;
|
|
70
|
+
if (currentFrom !== pendingFrom) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (currentData.data !== pendingData.data) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
// similar
|
|
77
|
+
return true;
|
|
78
|
+
});
|
|
79
|
+
if (exists) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
let gasWatcherWriter = await GasWatcherTx_1.GasWatcherTx.fromJSON(condition, writerJson, this.logger);
|
|
83
|
+
this.pending.push(gasWatcherWriter);
|
|
84
|
+
let id = gasWatcherWriter.txWriter.id;
|
|
85
|
+
let gwei = _bigint_1.$bigint.toGweiFromWei(gasWatcherWriter.condition.price);
|
|
86
|
+
this.logger.logTx(id, `Transaction was added to listed for ${gwei} gas gwei`);
|
|
87
|
+
// Ensure completed txs are removed
|
|
88
|
+
this.pending = this.pending.filter(x => x.txWriter.receipt == null);
|
|
89
|
+
await this.saveTxs();
|
|
90
|
+
}
|
|
91
|
+
async loadTxs() {
|
|
92
|
+
let jsons = await this.store.loadTxs();
|
|
93
|
+
let pending = await (0, alot_1.default)(jsons)
|
|
94
|
+
.mapAsync(x => GasWatcherTx_1.GasWatcherTx.fromJSON(x.condition, x.writer, this.logger))
|
|
95
|
+
.toArrayAsync();
|
|
96
|
+
this.pending = pending;
|
|
97
|
+
}
|
|
98
|
+
async saveTxs() {
|
|
99
|
+
let jsons = this.pending.map(x => x.toJSON());
|
|
100
|
+
await this.store.saveTxs(jsons);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.GasWatcherService = GasWatcherService;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GasWatcherStore = void 0;
|
|
4
|
+
const JsonObjectStore_1 = require("@dequanto/json/JsonObjectStore");
|
|
5
|
+
class GasWatcherStore {
|
|
6
|
+
constructor(name = '') {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.jsonStore = new JsonObjectStore_1.JsonObjectStore({
|
|
9
|
+
path: `./db/gaswatcher/txs${this.name}.json`,
|
|
10
|
+
format: true,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async savePrice(enty) {
|
|
14
|
+
}
|
|
15
|
+
async loadPrices(from, toDate) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
async saveTxs(txs) {
|
|
19
|
+
return this.jsonStore.save(txs);
|
|
20
|
+
}
|
|
21
|
+
async loadTxs() {
|
|
22
|
+
return this.jsonStore.get();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.GasWatcherStore = GasWatcherStore;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GasWatcherTx = void 0;
|
|
4
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
5
|
+
const _logger_1 = require("@dequanto/utils/$logger");
|
|
6
|
+
const TxWriter_1 = require("../TxWriter");
|
|
7
|
+
class GasWatcherTx {
|
|
8
|
+
constructor(condition, txWriter, logger) {
|
|
9
|
+
this.condition = condition;
|
|
10
|
+
this.txWriter = txWriter;
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
txWriter.on('log', message => this.log(message));
|
|
13
|
+
}
|
|
14
|
+
static async fromJSON(conditionJson, writerJson, logger) {
|
|
15
|
+
let writer = await TxWriter_1.TxWriter.fromJSON(writerJson);
|
|
16
|
+
return new GasWatcherTx({
|
|
17
|
+
price: BigInt(conditionJson.price)
|
|
18
|
+
}, writer, logger);
|
|
19
|
+
}
|
|
20
|
+
toJSON() {
|
|
21
|
+
return {
|
|
22
|
+
condition: this.condition,
|
|
23
|
+
writer: this.txWriter.toJSON(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async tick(gasPrice) {
|
|
27
|
+
if (gasPrice > this.condition.price) {
|
|
28
|
+
// condition not matched
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (this.txWriter.receipt != null) {
|
|
32
|
+
this.log(`Tx was already mined: ${this.txWriter.receipt.transactionHash}`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let tx = this.txWriter.tx;
|
|
36
|
+
if (tx == null) {
|
|
37
|
+
this.send(gasPrice);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let timeEllipsedS = (Date.now() - tx.timestamp) / 1000 | 0;
|
|
41
|
+
if (tx.hash == null) {
|
|
42
|
+
if (timeEllipsedS > 30) {
|
|
43
|
+
// tx was not accepted for 30s
|
|
44
|
+
this.log(`Tx was not accepted for 30s. Resend`);
|
|
45
|
+
this.send(gasPrice);
|
|
46
|
+
}
|
|
47
|
+
// otherwise let wait for a hash
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
let hash = tx.hash;
|
|
51
|
+
let client = this.txWriter.client;
|
|
52
|
+
let txData = await client.getTransaction(hash);
|
|
53
|
+
if (this.txWriter.receipt) {
|
|
54
|
+
// was mined inbetween
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (txData == null) {
|
|
58
|
+
if (timeEllipsedS > 45) {
|
|
59
|
+
this.log(`Tx not in a pending block: ${hash}. Resend`);
|
|
60
|
+
// tx not in a pending block
|
|
61
|
+
this.send(gasPrice);
|
|
62
|
+
}
|
|
63
|
+
// otherwise let wait to be included into the pending block
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (timeEllipsedS > 60 * 5) {
|
|
67
|
+
this.log(`Tx 5mins not mined: ${hash}. Resend`);
|
|
68
|
+
// 5mins not mined;
|
|
69
|
+
this.send(gasPrice);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async send(gasPrice) {
|
|
73
|
+
let writer = this.txWriter;
|
|
74
|
+
let builder = writer.builder;
|
|
75
|
+
let data = builder.data;
|
|
76
|
+
if (data.nonce == null) {
|
|
77
|
+
throw new Error(`Nonce should be already set on initial tx creating`);
|
|
78
|
+
await builder.setNonce();
|
|
79
|
+
}
|
|
80
|
+
if (writer.tx && data.gasPrice) {
|
|
81
|
+
// re-submitting
|
|
82
|
+
let currentGas = BigInt(data.gasPrice.toString());
|
|
83
|
+
if (currentGas >= gasPrice) {
|
|
84
|
+
// we can't resubmit with less gas
|
|
85
|
+
gasPrice = currentGas + _bigint_1.$bigint.toWeiFromGwei(.1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
await builder.setGas({
|
|
89
|
+
price: gasPrice,
|
|
90
|
+
priceRatio: 1,
|
|
91
|
+
gasLimit: data.gasLimit,
|
|
92
|
+
});
|
|
93
|
+
writer.tx = null;
|
|
94
|
+
writer.on('transactionHash', hash => {
|
|
95
|
+
let pendingCount = 0;
|
|
96
|
+
let nullCount = 0;
|
|
97
|
+
let interval = setInterval(async () => {
|
|
98
|
+
let tx = await writer.client.getTransaction(hash);
|
|
99
|
+
_logger_1.$logger.log('Check', hash, 'Block', tx?.blockNumber);
|
|
100
|
+
if (tx == null) {
|
|
101
|
+
if (++nullCount > 8) {
|
|
102
|
+
clearInterval(interval);
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (tx.blockNumber) {
|
|
107
|
+
// was mined;
|
|
108
|
+
_logger_1.$logger.log(`${hash} Mined`);
|
|
109
|
+
clearInterval(interval);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (++pendingCount > 15) {
|
|
113
|
+
clearInterval(interval);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}, 5000);
|
|
117
|
+
});
|
|
118
|
+
writer.send({
|
|
119
|
+
timeout: false
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
log(message) {
|
|
123
|
+
this.logger.logTx(this.txWriter.id, message);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.GasWatcherTx = GasWatcherTx;
|
|
@@ -0,0 +1,27 @@
|
|
|
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.TxLogParser = void 0;
|
|
7
|
+
const alot_1 = __importDefault(require("alot"));
|
|
8
|
+
const _contract_1 = require("@dequanto/utils/$contract");
|
|
9
|
+
const TxTopicProvider_1 = require("./TxTopicProvider");
|
|
10
|
+
class TxLogParser {
|
|
11
|
+
constructor(topics = new TxTopicProvider_1.TxTopicProvider()) {
|
|
12
|
+
this.topics = topics;
|
|
13
|
+
}
|
|
14
|
+
async parse(receipt) {
|
|
15
|
+
let logs = await (0, alot_1.default)(receipt.logs).mapAsync(async (log) => {
|
|
16
|
+
let topic = await this.topics.get(log.topics[0]);
|
|
17
|
+
if (topic == null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
let { abi, formatter } = topic;
|
|
21
|
+
let parsed = _contract_1.$contract.parseLogWithAbi(log, abi);
|
|
22
|
+
return parsed;
|
|
23
|
+
}).toArrayAsync();
|
|
24
|
+
return logs;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TxLogParser = TxLogParser;
|
|
@@ -0,0 +1,50 @@
|
|
|
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.TxLogsTransfer = void 0;
|
|
7
|
+
const alot_1 = __importDefault(require("alot"));
|
|
8
|
+
const TokensServiceFactory_1 = require("@dequanto/tokens/TokensServiceFactory");
|
|
9
|
+
const TxLogParser_1 = require("./TxLogParser");
|
|
10
|
+
class TxLogsTransfer {
|
|
11
|
+
async extractFromWriter(writer) {
|
|
12
|
+
let receipt = await writer.onCompleted;
|
|
13
|
+
let knownLogs = writer.tx?.knownLogs ?? [];
|
|
14
|
+
return this.extractFromParsed(knownLogs, writer.client.platform);
|
|
15
|
+
}
|
|
16
|
+
async extractFromParsed(knownLogs, platform) {
|
|
17
|
+
let transfers = knownLogs.filter(x => x.name === 'Transfer');
|
|
18
|
+
let tokenService = TokensServiceFactory_1.TokensServiceFactory.get(platform);
|
|
19
|
+
return (0, alot_1.default)(transfers).mapAsync(async (transfer) => {
|
|
20
|
+
let erc20Address = transfer.contract;
|
|
21
|
+
let token = await tokenService.getTokenOrDefault(erc20Address);
|
|
22
|
+
let [from, to, amount] = transfer.arguments;
|
|
23
|
+
return {
|
|
24
|
+
token,
|
|
25
|
+
from: from.value,
|
|
26
|
+
to: to.value,
|
|
27
|
+
amount: amount.value
|
|
28
|
+
};
|
|
29
|
+
}).toArrayAsync();
|
|
30
|
+
}
|
|
31
|
+
async extractFromReceipt(receipt, platform) {
|
|
32
|
+
let parser = new TxLogParser_1.TxLogParser();
|
|
33
|
+
let logs = await parser.parse(receipt);
|
|
34
|
+
logs = logs.filter(x => x != null);
|
|
35
|
+
return this.extractFromParsed(logs, platform);
|
|
36
|
+
}
|
|
37
|
+
async extract(transfer, platform) {
|
|
38
|
+
let tokenService = TokensServiceFactory_1.TokensServiceFactory.get(platform);
|
|
39
|
+
let erc20Address = transfer.contract;
|
|
40
|
+
let token = await tokenService.getTokenOrDefault(erc20Address);
|
|
41
|
+
let [from, to, amount] = transfer.arguments;
|
|
42
|
+
return {
|
|
43
|
+
token,
|
|
44
|
+
from: from.value,
|
|
45
|
+
to: to.value,
|
|
46
|
+
amount: amount.value
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.TxLogsTransfer = TxLogsTransfer;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TxTopicInMemoryProvider = void 0;
|
|
4
|
+
const _abiParser_1 = require("@dequanto/utils/$abiParser");
|
|
5
|
+
const _abiUtils_1 = require("@dequanto/utils/$abiUtils");
|
|
6
|
+
class TxTopicInMemoryProvider {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.hash = Object.create(null);
|
|
9
|
+
}
|
|
10
|
+
register(mix) {
|
|
11
|
+
if (mix == null) {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(mix)) {
|
|
15
|
+
mix.forEach(x => this.register(x));
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
let abi;
|
|
19
|
+
let formatter;
|
|
20
|
+
if (typeof mix !== 'string' && 'abi' in mix && 'formatter' in mix) {
|
|
21
|
+
abi = mix.abi;
|
|
22
|
+
formatter = mix.formatter;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
abi = mix;
|
|
26
|
+
}
|
|
27
|
+
if (typeof abi === 'string') {
|
|
28
|
+
abi = _abiParser_1.$abiParser.parseMethod(abi);
|
|
29
|
+
}
|
|
30
|
+
let hash = _abiUtils_1.$abiUtils.getMethodHash(abi);
|
|
31
|
+
this.hash[hash] = {
|
|
32
|
+
abi,
|
|
33
|
+
formatter
|
|
34
|
+
};
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
async get(topicHash) {
|
|
38
|
+
return this.hash[topicHash];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.TxTopicInMemoryProvider = TxTopicInMemoryProvider;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TxTopicProvider = void 0;
|
|
4
|
+
//import { TxLogsTransfer } from './TxLogsTransfer';
|
|
5
|
+
const TxTopicInMemoryProvider_1 = require("./TxTopicInMemoryProvider");
|
|
6
|
+
class TxTopicProvider {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.default = new TxTopicInMemoryProvider_1.TxTopicInMemoryProvider();
|
|
9
|
+
this.register([
|
|
10
|
+
'event Transfer(address from, address to, uint256 amount)'
|
|
11
|
+
// {
|
|
12
|
+
// abi: 'event Transfer(address from, address to, uint256 amount)',
|
|
13
|
+
// formatter: di.resolve(TxLogsTransfer)
|
|
14
|
+
// }
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
async get(topicHash) {
|
|
18
|
+
return this.default.get(topicHash);
|
|
19
|
+
}
|
|
20
|
+
register(mix) {
|
|
21
|
+
this.default.register(mix);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.TxTopicProvider = TxTopicProvider;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.$abiParser = void 0;
|
|
4
|
+
var $abiParser;
|
|
5
|
+
(function ($abiParser) {
|
|
6
|
+
function getReturnType(abi) {
|
|
7
|
+
let outputs = abi.outputs;
|
|
8
|
+
if (outputs == null || outputs.length == 0) {
|
|
9
|
+
return 'uint256';
|
|
10
|
+
}
|
|
11
|
+
if (outputs.length === 1 && !outputs[0].name) {
|
|
12
|
+
return outputs[0].type;
|
|
13
|
+
}
|
|
14
|
+
let hasKeys = outputs.every(x => Boolean(x.name));
|
|
15
|
+
if (hasKeys) {
|
|
16
|
+
return 'object';
|
|
17
|
+
}
|
|
18
|
+
return 'array';
|
|
19
|
+
}
|
|
20
|
+
$abiParser.getReturnType = getReturnType;
|
|
21
|
+
function getReturnTypeFromTypes(outputs) {
|
|
22
|
+
if (outputs == null || outputs.length == 0) {
|
|
23
|
+
return 'uint256';
|
|
24
|
+
}
|
|
25
|
+
if (outputs.length === 1 && !outputs[0].name) {
|
|
26
|
+
return outputs[0].type;
|
|
27
|
+
}
|
|
28
|
+
let hasKeys = outputs.every(x => Boolean(x.name));
|
|
29
|
+
if (hasKeys) {
|
|
30
|
+
return 'object';
|
|
31
|
+
}
|
|
32
|
+
return 'array';
|
|
33
|
+
}
|
|
34
|
+
$abiParser.getReturnTypeFromTypes = getReturnTypeFromTypes;
|
|
35
|
+
const methodRgx = /^((?<type>function|event)\s+)?(?<methodName>\w+)\s*\((?<params>[^)]+)?\)\s*((:|returns)(?<return>.+))?$/;
|
|
36
|
+
/**
|
|
37
|
+
* foo(uint256):address
|
|
38
|
+
* function foo(uint256): (address account, uint256 value)
|
|
39
|
+
* function foo(uint256) returns (address)
|
|
40
|
+
*/
|
|
41
|
+
function parseMethod(methodAbi) {
|
|
42
|
+
let outputs;
|
|
43
|
+
let match = methodRgx.exec(methodAbi);
|
|
44
|
+
if (match == null) {
|
|
45
|
+
throw new Error(`Invalid method abi ${methodAbi}. Expect like 'foo(uint256):address'`);
|
|
46
|
+
}
|
|
47
|
+
let fnName = match.groups.methodName;
|
|
48
|
+
let $return = match.groups.return?.trim() ?? 'uint256';
|
|
49
|
+
outputs = parseArguments($return);
|
|
50
|
+
let inputs = Parse.parametersLine(match.groups.params ?? '');
|
|
51
|
+
return {
|
|
52
|
+
constant: false,
|
|
53
|
+
payable: false,
|
|
54
|
+
//"stateMutability": "view",
|
|
55
|
+
name: fnName,
|
|
56
|
+
inputs: inputs,
|
|
57
|
+
outputs: outputs,
|
|
58
|
+
type: match.groups.type ?? 'function',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
$abiParser.parseMethod = parseMethod;
|
|
62
|
+
// uint256
|
|
63
|
+
// address[]
|
|
64
|
+
// (uint256, uint256)
|
|
65
|
+
// (uint256 foo, uint256 bar)
|
|
66
|
+
// (uint256 foo, uint256 bar)[]
|
|
67
|
+
function parseArguments(line) {
|
|
68
|
+
line = line?.trim();
|
|
69
|
+
if (!line || line === '()') {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
let c = line[0];
|
|
73
|
+
if (c === '{') {
|
|
74
|
+
throw new Error(`${line} is not supported, use (...) or [...] declarations`);
|
|
75
|
+
}
|
|
76
|
+
if (c === '[' || c === '(') {
|
|
77
|
+
let end = Parse.goToClosing(line, 0, c);
|
|
78
|
+
let parametersLine = line.substring(1, end);
|
|
79
|
+
let isArray = line.endsWith('[]');
|
|
80
|
+
let params = Parse.parametersLine(parametersLine);
|
|
81
|
+
let isTuple = params.every(x => Boolean(x.name));
|
|
82
|
+
if (isTuple && isArray) {
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
name: '',
|
|
86
|
+
type: `tuple[]`,
|
|
87
|
+
components: params
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
if (params.length === 1) {
|
|
92
|
+
line = params[0].type;
|
|
93
|
+
params = [
|
|
94
|
+
{
|
|
95
|
+
name: "",
|
|
96
|
+
type: line,
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
return params;
|
|
101
|
+
}
|
|
102
|
+
// if (c === '{') {
|
|
103
|
+
// let params = line.substring(1, line.length - 1);
|
|
104
|
+
// outputs = params.split(',').map(x => x.trim()).map(param => {
|
|
105
|
+
// let [_type, _name] = param.split(/[\s+:]/).map(x => x.trim()).filter(Boolean);
|
|
106
|
+
// return {
|
|
107
|
+
// name: _name ?? '',
|
|
108
|
+
// type: _type.trim()
|
|
109
|
+
// };
|
|
110
|
+
// });
|
|
111
|
+
// }
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
name: '',
|
|
115
|
+
type: line,
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
$abiParser.parseArguments = parseArguments;
|
|
120
|
+
})($abiParser = exports.$abiParser || (exports.$abiParser = {}));
|
|
121
|
+
var Parse;
|
|
122
|
+
(function (Parse) {
|
|
123
|
+
// uint256 foo, uint bar, address qux
|
|
124
|
+
function parametersLine(paramsStr) {
|
|
125
|
+
return paramsStr
|
|
126
|
+
.split(',')
|
|
127
|
+
.map(x => x.trim())
|
|
128
|
+
.filter(Boolean)
|
|
129
|
+
.map(param => {
|
|
130
|
+
let [_type, _name] = param.split(/\s+/).map(x => x.trim()).filter(Boolean);
|
|
131
|
+
return {
|
|
132
|
+
name: _name ?? '',
|
|
133
|
+
type: _type.trim()
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
Parse.parametersLine = parametersLine;
|
|
138
|
+
function goToClosing(str, startI, openChar, closeChar) {
|
|
139
|
+
closeChar = closeChar ?? CLOSE_CHARS[openChar];
|
|
140
|
+
let count = 0;
|
|
141
|
+
for (let i = startI; i < str.length; i++) {
|
|
142
|
+
if (str[i] === openChar) {
|
|
143
|
+
count++;
|
|
144
|
+
}
|
|
145
|
+
if (str[i] === closeChar) {
|
|
146
|
+
count--;
|
|
147
|
+
}
|
|
148
|
+
if (count === 0) {
|
|
149
|
+
return i;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`Unmatched closing chars ${openChar} ${closeChar} in ${str}`);
|
|
153
|
+
}
|
|
154
|
+
Parse.goToClosing = goToClosing;
|
|
155
|
+
const CLOSE_CHARS = {
|
|
156
|
+
'[': ']',
|
|
157
|
+
'(': ')'
|
|
158
|
+
};
|
|
159
|
+
})(Parse || (Parse = {}));
|