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,402 @@
|
|
|
1
|
+
import { TAddress } from '@dequanto/models/TAddress';
|
|
2
|
+
import { AbiItem } from 'web3-utils';
|
|
3
|
+
import { File } from 'atma-io';
|
|
4
|
+
import { class_Uri } from 'atma-utils';
|
|
5
|
+
import alot from 'alot';
|
|
6
|
+
import { $abiType } from '@dequanto/utils/$abiType';
|
|
7
|
+
import { $date } from '@dequanto/utils/$date';
|
|
8
|
+
import { $path } from '@dequanto/utils/$path';
|
|
9
|
+
import { $abiUtils } from '@dequanto/utils/$abiUtils';
|
|
10
|
+
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
11
|
+
|
|
12
|
+
export class GeneratorFromAbi {
|
|
13
|
+
|
|
14
|
+
static get Gen () {
|
|
15
|
+
return Gen;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async generate (abiJson: AbiItem[], opts: {
|
|
19
|
+
network: TPlatform
|
|
20
|
+
name: string
|
|
21
|
+
address: TAddress
|
|
22
|
+
output: string
|
|
23
|
+
implementation: TAddress
|
|
24
|
+
saveAbi?: boolean
|
|
25
|
+
sources?: {
|
|
26
|
+
[file: string]: { content: string }
|
|
27
|
+
}
|
|
28
|
+
}) {
|
|
29
|
+
|
|
30
|
+
let methodsArr = abiJson
|
|
31
|
+
.map(item => {
|
|
32
|
+
if (item.type === 'function') {
|
|
33
|
+
return Gen.serializeMethodTs(item);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
})
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.map(Str.formatMethod);
|
|
39
|
+
;
|
|
40
|
+
|
|
41
|
+
let eventsArr = abiJson
|
|
42
|
+
.filter(x => x.type === 'event')
|
|
43
|
+
.map(x => Gen.serializeEvent(x))
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.map(Str.formatMethod);
|
|
46
|
+
;
|
|
47
|
+
let eventsExtractorsArr = abiJson
|
|
48
|
+
.filter(x => x.type === 'event')
|
|
49
|
+
.map(x => Gen.serializeEventExtractor(x))
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
.map(Str.formatMethod);
|
|
52
|
+
|
|
53
|
+
let eventInterfaces = abiJson
|
|
54
|
+
.filter(x => x.type === 'event')
|
|
55
|
+
.map(x => Gen.serializeEventInterface(x))
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
.map(Str.formatMethod);
|
|
58
|
+
;
|
|
59
|
+
|
|
60
|
+
let methods = methodsArr.join('\n\n');
|
|
61
|
+
let events = eventsArr.join('\n\n');
|
|
62
|
+
let eventsExtractors = eventsExtractorsArr.join('\n\n');
|
|
63
|
+
|
|
64
|
+
let name = opts.name;
|
|
65
|
+
let templatePath = $path.resolve(`/src/gen/ContractTemplate.ts`);
|
|
66
|
+
let template = await File.readAsync<string>(templatePath, { skipHooks: true });
|
|
67
|
+
|
|
68
|
+
let EtherscanStr;
|
|
69
|
+
let EthWeb3ClientStr;
|
|
70
|
+
let imports = [];
|
|
71
|
+
let explorerUrl: string;
|
|
72
|
+
switch (opts.network) {
|
|
73
|
+
case 'bsc':
|
|
74
|
+
EtherscanStr = 'Bscscan';
|
|
75
|
+
EthWeb3ClientStr = 'BscWeb3Client';
|
|
76
|
+
imports = [
|
|
77
|
+
`import { Bscscan } from '@dequanto/BlockchainExplorer/Bscscan'`,
|
|
78
|
+
`import { BscWeb3Client } from '@dequanto/clients/BscWeb3Client'`,
|
|
79
|
+
];
|
|
80
|
+
explorerUrl = `https://bscscan.com/address/${opts.implementation}#code`;
|
|
81
|
+
break;
|
|
82
|
+
case 'polygon':
|
|
83
|
+
EtherscanStr = 'Polyscan';
|
|
84
|
+
EthWeb3ClientStr = 'PolyWeb3Client';
|
|
85
|
+
imports = [
|
|
86
|
+
`import { Polyscan } from '@dequanto/BlockchainExplorer/Polyscan'`,
|
|
87
|
+
`import { PolyWeb3Client } from '@dequanto/clients/PolyWeb3Client'`,
|
|
88
|
+
];
|
|
89
|
+
explorerUrl = `https://polygonscan.com/address/${opts.implementation}#code`;
|
|
90
|
+
break;
|
|
91
|
+
case 'xdai':
|
|
92
|
+
EtherscanStr = 'XDaiscan';
|
|
93
|
+
EthWeb3ClientStr = 'XDaiWeb3Client';
|
|
94
|
+
imports = [
|
|
95
|
+
`import { XDaiscan } from '@dequanto/chains/xdai/XDaiscan'`,
|
|
96
|
+
`import { XDaiWeb3Client } from '@dequanto/chains/xdai/XDaiWeb3Client'`,
|
|
97
|
+
];
|
|
98
|
+
explorerUrl = `https://blockscout.com/xdai/mainnet/address/${opts.implementation}/contracts`;
|
|
99
|
+
break;
|
|
100
|
+
case 'eth':
|
|
101
|
+
EtherscanStr = 'Etherscan';
|
|
102
|
+
EthWeb3ClientStr = 'EthWeb3Client';
|
|
103
|
+
imports = [
|
|
104
|
+
`import { Etherscan } from '@dequanto/BlockchainExplorer/Etherscan'`,
|
|
105
|
+
`import { EthWeb3Client } from '@dequanto/clients/EthWeb3Client'`,
|
|
106
|
+
];
|
|
107
|
+
explorerUrl = `https://etherscan.io/address/${opts.implementation}#code`;
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
throw new Error(`Unknown network ${opts.network}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let code = template
|
|
114
|
+
.replace(/\$Etherscan\$/g, EtherscanStr)
|
|
115
|
+
.replace(/\$EthWeb3Client\$/g, EthWeb3ClientStr)
|
|
116
|
+
.replace(`/* IMPORTS */`, imports.join('\n'))
|
|
117
|
+
.replace(`$NAME$`, Gen.toClassName(name))
|
|
118
|
+
.replace(`$ADDRESS$`, opts.address ?? '')
|
|
119
|
+
.replace(`/* METHODS */`, methods)
|
|
120
|
+
.replace(`/* EVENTS */`, events)
|
|
121
|
+
.replace(`/* EVENTS_EXTRACTORS */`, eventsExtractors)
|
|
122
|
+
.replace(`$ABI$`, JSON.stringify(abiJson))
|
|
123
|
+
.replace(`$DATE$`, $date.format(new Date(), 'yyyy-MM-dd HH:mm'))
|
|
124
|
+
.replace(`$EXPLORER_URL$`, explorerUrl)
|
|
125
|
+
.replace(`/* $EVENT_INTERFACES$ */`, eventInterfaces.join('\n'))
|
|
126
|
+
;
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
let directory = name;
|
|
130
|
+
let filename = /[^\\/]+$/.exec(name)[0];
|
|
131
|
+
|
|
132
|
+
let path = class_Uri.combine(opts.output, directory, `${filename}.ts`);
|
|
133
|
+
await File.writeAsync(path, code, { skipHooks: true });
|
|
134
|
+
|
|
135
|
+
if (opts.saveAbi) {
|
|
136
|
+
let path = class_Uri.combine(opts.output, directory, `${filename}.json`);
|
|
137
|
+
await File.writeAsync(path, abiJson);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.log(`ABI wrapper class created: ${path}`);
|
|
141
|
+
|
|
142
|
+
let sources = opts.sources;
|
|
143
|
+
let sourceFiles = [];
|
|
144
|
+
if (sources) {
|
|
145
|
+
sourceFiles = await alot.fromObject(sources).mapAsync(async entry => {
|
|
146
|
+
let sourceFilename = /\/?([^/]+$)/.exec(entry.key)[1];
|
|
147
|
+
let path = class_Uri.combine(opts.output, directory, filename, sourceFilename);
|
|
148
|
+
await File.writeAsync(path, entry.value.content, { skipHooks: true });
|
|
149
|
+
|
|
150
|
+
console.log(`Source code saved: ${path}`);
|
|
151
|
+
return path;
|
|
152
|
+
}).toArrayAsync();
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
main: path,
|
|
156
|
+
sources: sourceFiles,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
namespace Gen {
|
|
163
|
+
|
|
164
|
+
export function toClassName (name: string) {
|
|
165
|
+
let str = name.replace(/[^\w_\-\\/]/g, '');
|
|
166
|
+
str = str.replace(/[\-\\/](\w)/g, (full, letter) => {
|
|
167
|
+
return letter.toUpperCase();
|
|
168
|
+
});
|
|
169
|
+
return str[0].toUpperCase() + str.substring(1);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
export function serializeMethodTs (abi: AbiItem) {
|
|
174
|
+
let isRead = isReader(abi);
|
|
175
|
+
if (isRead) {
|
|
176
|
+
return serializeReadMethodTs(abi);
|
|
177
|
+
}
|
|
178
|
+
return serializeWriteMethodTs(abi);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function serializeEvent (abi: AbiItem) {
|
|
182
|
+
let { fnInputArguments, callInputArguments, fnResult } = serializeArgumentsTs(abi);
|
|
183
|
+
return `
|
|
184
|
+
on${abi.name} (fn: (event: EventData, ${fnInputArguments}) => void): ClientEventsStream<any> {
|
|
185
|
+
return this.$on('${abi.name}', fn);
|
|
186
|
+
}
|
|
187
|
+
`;
|
|
188
|
+
}
|
|
189
|
+
export function serializeEventExtractor (abi: AbiItem) {
|
|
190
|
+
return `
|
|
191
|
+
extractLogs${abi.name} (tx: TransactionReceipt): TLog${abi.name}[] {
|
|
192
|
+
let abi = this.$getAbiItem('event', '${abi.name}');
|
|
193
|
+
return this.$extractLogs(tx, abi) as any as TLog${abi.name}[];
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
export function serializeEventInterface (abi: AbiItem) {
|
|
198
|
+
let { fnInputArguments, callInputArguments, fnResult } = serializeArgumentsTs(abi);
|
|
199
|
+
return `
|
|
200
|
+
type TLog${abi.name} = {
|
|
201
|
+
contract: TAddress,
|
|
202
|
+
${fnInputArguments}
|
|
203
|
+
}
|
|
204
|
+
`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function isReader (abi: AbiItem) {
|
|
208
|
+
return ['view', 'pure', null].includes(abi.stateMutability);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function serializeMethodAbi(abi: AbiItem, includeNames?: boolean) {
|
|
212
|
+
let params = abi.inputs?.map(x => {
|
|
213
|
+
let param = x.type;
|
|
214
|
+
if (includeNames && x.name) {
|
|
215
|
+
param += ' ' + x.name;
|
|
216
|
+
}
|
|
217
|
+
return param;
|
|
218
|
+
}).join(', ') ?? '';
|
|
219
|
+
let returns = serializeMethodAbiReturns(abi.outputs);
|
|
220
|
+
if (returns && abi.outputs.length > 1) {
|
|
221
|
+
returns = `(${returns})`;
|
|
222
|
+
}
|
|
223
|
+
let returnsStr = returns ? `returns ${returns}` : '';
|
|
224
|
+
return `function ${abi.name}(${params}) ${returnsStr}`.trim();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function serializeReadMethodTs (abi: AbiItem) {
|
|
228
|
+
let { fnInputArguments, callInputArguments, fnResult } = serializeArgumentsTs(abi);
|
|
229
|
+
if (callInputArguments) {
|
|
230
|
+
callInputArguments = `, ${callInputArguments}`;
|
|
231
|
+
}
|
|
232
|
+
return `
|
|
233
|
+
// ${$abiUtils.getMethodSignature(abi)}
|
|
234
|
+
async ${abi.name} (${fnInputArguments}): ${fnResult} {
|
|
235
|
+
return this.$read('${serializeMethodAbi(abi)}'${callInputArguments});
|
|
236
|
+
}
|
|
237
|
+
`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function serializeWriteMethodTs (abi: AbiItem) {
|
|
241
|
+
let { fnInputArguments, callInputArguments } = serializeArgumentsTs(abi);
|
|
242
|
+
if (callInputArguments) {
|
|
243
|
+
callInputArguments = `, ${callInputArguments}`;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return `
|
|
247
|
+
// ${$abiUtils.getMethodSignature(abi)}
|
|
248
|
+
async ${abi.name} (eoa: {address: TAddress, key: string, value?: string | number | bigint }, ${fnInputArguments}): Promise<TxWriter> {
|
|
249
|
+
return this.$write(this.$getAbiItem('function', '${abi.name}'), eoa${callInputArguments});
|
|
250
|
+
}
|
|
251
|
+
`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function serializeArgumentsTs (abi: AbiItem) {
|
|
255
|
+
let inputs = abi.inputs.map((input, i) => {
|
|
256
|
+
let result = { ...input };
|
|
257
|
+
if (result.name == null || result.name === '') {
|
|
258
|
+
result.name = 'input' + i;
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
let fnInputArguments = inputs
|
|
264
|
+
?.map((input) => {
|
|
265
|
+
let tsType = $abiType.getTsType(input.type, input);
|
|
266
|
+
if (tsType == null) {
|
|
267
|
+
throw new Error(`Unknown abi type in arguments: ${input.type}`);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return `${input.name}: ${tsType}`;
|
|
271
|
+
})
|
|
272
|
+
?.join(', ') ?? '';
|
|
273
|
+
|
|
274
|
+
let callInputArguments = inputs
|
|
275
|
+
?.map(input => {
|
|
276
|
+
return `${input.name}`;
|
|
277
|
+
})
|
|
278
|
+
?.join(', ') ?? '';
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
let fnResult = serializeMethodTsReturns(abi.outputs);
|
|
282
|
+
return { fnInputArguments, callInputArguments, fnResult };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function isObjectParams (params: { name, type }[]) {
|
|
286
|
+
return params?.every(x => Boolean(x.name));
|
|
287
|
+
}
|
|
288
|
+
function serializeMethodAbiReturns (params: { name, type, components? }[]) {
|
|
289
|
+
if (params == null) {
|
|
290
|
+
return '';
|
|
291
|
+
}
|
|
292
|
+
// if (isObjectParams(params)) {
|
|
293
|
+
// return params.map(x => serializeMethodAbiReturnsSingle(x)).join(',');
|
|
294
|
+
// }
|
|
295
|
+
return params?.map(x => serializeMethodAbiReturnsSingle(x)).join(',');
|
|
296
|
+
}
|
|
297
|
+
function serializeMethodAbiReturnsSingle (param: { name, type, components? }) {
|
|
298
|
+
if (param == null) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
if (param.components) {
|
|
302
|
+
// tuple, tuple[]
|
|
303
|
+
let fields = serializeMethodAbiReturns(param.components);
|
|
304
|
+
return `[${fields}]${ param.type === 'tuple[]' ? '[]' : '' }`;
|
|
305
|
+
}
|
|
306
|
+
// if (param.name && param.type) {
|
|
307
|
+
// return `${param.type} ${param.name}`;
|
|
308
|
+
// }
|
|
309
|
+
return param.type;
|
|
310
|
+
}
|
|
311
|
+
function serializeMethodTsReturns (params: { name, type }[]) {
|
|
312
|
+
if (params == null || params.length === 0) {
|
|
313
|
+
params = [ { name: '', type: 'uint256' } ];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
let tsTypes = params.map(param => {
|
|
317
|
+
let tsType = $abiType.getTsType(param.type, param);
|
|
318
|
+
if (tsType == null) {
|
|
319
|
+
throw new Error(`(gen) Unknown abi type in return: ${param.type}`);
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
name: param.name,
|
|
323
|
+
type: tsType
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
if (params.length > 1 && isObjectParams(params)) {
|
|
328
|
+
let paramsStr = tsTypes.map(x => `${x.name}: ${x.type}`).join(', ');
|
|
329
|
+
return `Promise<{ ${paramsStr} }>`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
let fnResult = tsTypes?.map(x => x.type).join(', ');
|
|
333
|
+
if (tsTypes.length > 1) {
|
|
334
|
+
fnResult = `[ ${fnResult} ]`
|
|
335
|
+
}
|
|
336
|
+
return `Promise<${fnResult}>`;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
// const AbiTsTypes = {
|
|
341
|
+
// 'uint8': 'number',
|
|
342
|
+
// 'uint4': 'number',
|
|
343
|
+
// 'uint': 'number',
|
|
344
|
+
|
|
345
|
+
// 'bool': 'boolean',
|
|
346
|
+
|
|
347
|
+
// 'bytes': 'Buffer',
|
|
348
|
+
// 'bytes4': 'Buffer',
|
|
349
|
+
// 'bytes32': 'Buffer',
|
|
350
|
+
// 'bytes64': 'Buffer',
|
|
351
|
+
// 'bytes128': 'Buffer',
|
|
352
|
+
// 'bytes256': 'Buffer',
|
|
353
|
+
|
|
354
|
+
// 'address': 'TAddress',
|
|
355
|
+
// 'string': 'string',
|
|
356
|
+
// };
|
|
357
|
+
// const AbiTsTypesRgx = [
|
|
358
|
+
// {
|
|
359
|
+
// rgx: /uint\d+/,
|
|
360
|
+
// type: 'bigint',
|
|
361
|
+
// }
|
|
362
|
+
// ];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
namespace Str {
|
|
367
|
+
export function formatMethod (str: string) {
|
|
368
|
+
str = trim(str);
|
|
369
|
+
str = indent(str, ' ');
|
|
370
|
+
return str;
|
|
371
|
+
}
|
|
372
|
+
export function trim (str: string) {
|
|
373
|
+
let lines = str.split('\n');
|
|
374
|
+
let min = alot(lines).min(x => {
|
|
375
|
+
if (x.trim() === '') {
|
|
376
|
+
return Number.MAX_SAFE_INTEGER;
|
|
377
|
+
}
|
|
378
|
+
let match = /^\s+/.exec(x);
|
|
379
|
+
if (match == null) {
|
|
380
|
+
return Number.MAX_SAFE_INTEGER;
|
|
381
|
+
}
|
|
382
|
+
return match[0].length;
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
lines = lines.map((line, i) => {
|
|
386
|
+
let x = line.substring(min);
|
|
387
|
+
if ((i === 0) || (lines.length === i + 1)) {
|
|
388
|
+
if (x === '') {
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return x;
|
|
393
|
+
}).filter(Boolean);
|
|
394
|
+
return lines.join('\n');
|
|
395
|
+
}
|
|
396
|
+
export function indent (str: string, indent: string) {
|
|
397
|
+
return str
|
|
398
|
+
.split('\n')
|
|
399
|
+
.map(x => `${indent}${x}`)
|
|
400
|
+
.join('\n');
|
|
401
|
+
}
|
|
402
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ChainAccount } from '@dequanto/ChainAccounts';
|
|
2
|
+
import { PlatformFactory } from '@dequanto/chains/PlatformFactory';
|
|
3
|
+
import { IToken } from '@dequanto/models/IToken';
|
|
4
|
+
import { TAddress } from '@dequanto/models/TAddress';
|
|
5
|
+
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
6
|
+
import { $bigint } from '@dequanto/utils/$bigint';
|
|
7
|
+
import { $is } from '@dequanto/utils/$is';
|
|
8
|
+
import { $require } from '@dequanto/utils/$require';
|
|
9
|
+
import di from 'a-di';
|
|
10
|
+
import memd from 'memd';
|
|
11
|
+
|
|
12
|
+
export class TokenHandler {
|
|
13
|
+
constructor(public platform: TPlatform) {
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async transfer (params: {
|
|
18
|
+
from: TAddress | ChainAccount
|
|
19
|
+
to: TAddress
|
|
20
|
+
token: string | IToken
|
|
21
|
+
amount: number
|
|
22
|
+
internal?: boolean
|
|
23
|
+
}) {
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
let fromAccount:ChainAccount = await this.getAccount(params.from, true);
|
|
27
|
+
let toAccount = await this.getAccount(params.to, params.internal);
|
|
28
|
+
|
|
29
|
+
let chain = await this.chain();
|
|
30
|
+
|
|
31
|
+
let token = typeof params.token === 'string'
|
|
32
|
+
? await chain.tokens.getKnownToken(params.token)
|
|
33
|
+
: params.token;
|
|
34
|
+
|
|
35
|
+
$require.Token(token);
|
|
36
|
+
$require.notNull(fromAccount, 'FromAccount');
|
|
37
|
+
$require.notNull(toAccount, 'ToAccount');
|
|
38
|
+
|
|
39
|
+
let amountEther = params.amount;
|
|
40
|
+
if (amountEther == Infinity) {
|
|
41
|
+
let balance = await chain.transfer.getBalance(fromAccount.address, token);
|
|
42
|
+
amountEther = $bigint.toEther(balance, token.decimals);
|
|
43
|
+
}
|
|
44
|
+
console.log('Transfering: ', amountEther, token.symbol);
|
|
45
|
+
|
|
46
|
+
let service = chain.transfer
|
|
47
|
+
.$config({
|
|
48
|
+
type: 2
|
|
49
|
+
//gasFunding: ChainAccountProvider.get(PLATFORM, 'quant')
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
let txToken = params.amount === Infinity
|
|
53
|
+
? await service.transferAll(fromAccount, toAccount.address, token)
|
|
54
|
+
: await service.transfer(fromAccount, toAccount.address, token, params.amount);
|
|
55
|
+
|
|
56
|
+
return txToken;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@memd.deco.memoize({ perInstance: true })
|
|
60
|
+
private chain () {
|
|
61
|
+
return di.resolve(PlatformFactory).get(this.platform);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private async getAccount(mix: string | TAddress | ChainAccount, isPrivate?: boolean) {
|
|
65
|
+
if (typeof mix === 'object' && 'address' in mix && 'key' in mix) {
|
|
66
|
+
return mix;
|
|
67
|
+
}
|
|
68
|
+
let chain = await this.chain();
|
|
69
|
+
let account = await chain.accounts.get(mix);
|
|
70
|
+
if (account == null) {
|
|
71
|
+
if (isPrivate !== false) {
|
|
72
|
+
throw new Error(`Account ${mix} not found`);
|
|
73
|
+
}
|
|
74
|
+
return { address: mix } as any as ChainAccount;
|
|
75
|
+
}
|
|
76
|
+
return account;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BlockTransactionString } from 'web3-eth';
|
|
2
|
+
import { Transaction } from 'web3-core';
|
|
3
|
+
import { BlocksWalker } from './handlers/BlocksWalker';
|
|
4
|
+
import { Web3Client } from '@dequanto/clients/Web3Client';
|
|
5
|
+
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
6
|
+
import { Web3ClientFactory } from '@dequanto/clients/Web3ClientFactory';
|
|
7
|
+
import { $logger } from '@dequanto/utils/$logger';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export interface IBlocksTxIndexerOptions {
|
|
11
|
+
/** Name of the indexer */
|
|
12
|
+
name?: string
|
|
13
|
+
persistance?: boolean
|
|
14
|
+
loadTransactions?: boolean
|
|
15
|
+
}
|
|
16
|
+
export type TBlockListener = (client: Web3Client, block: BlockTransactionString, txs?: Transaction[]) => Promise<void>
|
|
17
|
+
|
|
18
|
+
export class BlocksTxIndexer {
|
|
19
|
+
private client: Web3Client;
|
|
20
|
+
private walker: BlocksWalker;
|
|
21
|
+
private listeners: TBlockListener[] = [];
|
|
22
|
+
|
|
23
|
+
constructor (public platform: TPlatform, public opts?: IBlocksTxIndexerOptions) {
|
|
24
|
+
|
|
25
|
+
this.client = Web3ClientFactory.get(platform, {
|
|
26
|
+
ws: true
|
|
27
|
+
});
|
|
28
|
+
this.walker = new BlocksWalker({
|
|
29
|
+
name: `${opts?.name ?? 'indexer'}_${this.platform}`,
|
|
30
|
+
client: this.client,
|
|
31
|
+
loadTransactions: opts?.loadTransactions ?? true,
|
|
32
|
+
persistance: opts?.persistance ?? true,
|
|
33
|
+
visitor: async (block, txs) => {
|
|
34
|
+
return this.indexTransactions(block, txs)
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public onBlock (cb: TBlockListener): this {
|
|
40
|
+
this.listeners.push(cb);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public stats () {
|
|
45
|
+
return this.walker.stats();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async start (from?: Date | number, to?: Date | number) {
|
|
49
|
+
await this.walker.start(from, to);
|
|
50
|
+
|
|
51
|
+
if (to == null) {
|
|
52
|
+
this.client.subscribe('newBlockHeaders', (error, blockHeader) => {
|
|
53
|
+
this.walker.processUntil(blockHeader.number);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async indexTransactions (block: BlockTransactionString, txs: Transaction[]) {
|
|
59
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
60
|
+
let indexer = this.listeners[i];
|
|
61
|
+
try {
|
|
62
|
+
await indexer(this.client, block, txs);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
$logger.log(error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { BlockTransactionString } from 'web3-eth'
|
|
2
|
+
import { Transaction } from 'web3-core';
|
|
3
|
+
import { BlocksWalker } from './handlers/BlocksWalker';
|
|
4
|
+
import { Web3Client } from '@dequanto/clients/Web3Client';
|
|
5
|
+
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
6
|
+
import { Web3ClientFactory } from '@dequanto/clients/Web3ClientFactory';
|
|
7
|
+
import { TxQueueLoader } from './handlers/TxQueueLoader';
|
|
8
|
+
import { BlocksTxIndexer } from './BlocksTxIndexer';
|
|
9
|
+
import { $number } from '@dequanto/utils/$number';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export interface IPendingTxIndexerOptions {
|
|
13
|
+
/** Name of the indexer */
|
|
14
|
+
name?: string
|
|
15
|
+
}
|
|
16
|
+
export type TPendingTxListener = (client: Web3Client, tx: Transaction) => Promise<void>
|
|
17
|
+
|
|
18
|
+
export class PendingTxIndexer {
|
|
19
|
+
|
|
20
|
+
private client: Web3Client;
|
|
21
|
+
private walker: BlocksWalker;
|
|
22
|
+
private listeners: TPendingTxListener[] = [];
|
|
23
|
+
|
|
24
|
+
//private mempool = [];
|
|
25
|
+
private mempoolHash = Object.create(null);
|
|
26
|
+
|
|
27
|
+
private loader: TxQueueLoader;
|
|
28
|
+
private blocks: BlocksTxIndexer;
|
|
29
|
+
private status = {
|
|
30
|
+
startedAt: null as number,
|
|
31
|
+
// ~ tx/s
|
|
32
|
+
txSpeed: 0,
|
|
33
|
+
|
|
34
|
+
txCount: 0,
|
|
35
|
+
txNulls: 0,
|
|
36
|
+
|
|
37
|
+
// tx not seen in mempool
|
|
38
|
+
txPrivateCount: 0,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
constructor (public platform: TPlatform, public opts?: IPendingTxIndexerOptions) {
|
|
42
|
+
|
|
43
|
+
this.client = Web3ClientFactory.get(platform, {
|
|
44
|
+
ws: true
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
let pool = Web3ClientFactory.get(platform);
|
|
49
|
+
this.loader = new TxQueueLoader(pool, tx => {
|
|
50
|
+
this.onMempoolTxLoaded(tx);
|
|
51
|
+
});
|
|
52
|
+
this.blocks = new BlocksTxIndexer(platform, {
|
|
53
|
+
name: opts.name,
|
|
54
|
+
loadTransactions: false,
|
|
55
|
+
persistance: false,
|
|
56
|
+
});
|
|
57
|
+
this.blocks.onBlock(async (client, block) => {
|
|
58
|
+
this.onBlockLoaded(block);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public onTransaction (cb: TPendingTxListener): this {
|
|
63
|
+
this.listeners.push(cb);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public stats () {
|
|
68
|
+
if (this.status.startedAt == null) {
|
|
69
|
+
return { active: false }
|
|
70
|
+
}
|
|
71
|
+
let seconds = (Date.now() - this.status.startedAt) / 1000 | 0;
|
|
72
|
+
let txSpeed = $number.round(this.status.txCount / seconds, 2);
|
|
73
|
+
return {
|
|
74
|
+
active: true,
|
|
75
|
+
txSpeed: txSpeed,
|
|
76
|
+
...this.status,
|
|
77
|
+
loader: {
|
|
78
|
+
...this.loader.stats()
|
|
79
|
+
},
|
|
80
|
+
blocks: {
|
|
81
|
+
...this.blocks.stats()
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async start () {
|
|
87
|
+
this.status.startedAt = Date.now();
|
|
88
|
+
this.client.subscribe('pendingTransactions', (error, hash) => {
|
|
89
|
+
this.status.txCount++;
|
|
90
|
+
this.mempoolHash[hash] = 1;
|
|
91
|
+
this.loader.push(hash);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
let blockNumber = await this.client.getBlockNumber();
|
|
95
|
+
this.blocks.start(blockNumber);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
private onMempoolTxLoaded (tx: Transaction) {
|
|
100
|
+
if (tx == null) {
|
|
101
|
+
this.status.txNulls++;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
105
|
+
this.listeners[i](this.client, tx);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
private onBlockLoaded (block: BlockTransactionString) {
|
|
109
|
+
for (let i = 0; i < block.transactions.length; i++) {
|
|
110
|
+
let hash = block.transactions[i];
|
|
111
|
+
|
|
112
|
+
if (hash in this.mempoolHash) {
|
|
113
|
+
delete this.mempoolHash[hash];
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
//Not seen in memhash;
|
|
117
|
+
this.status.txPrivateCount++;
|
|
118
|
+
this.status.txCount++;
|
|
119
|
+
this.mempoolHash[hash] = 1;
|
|
120
|
+
this.loader.push(hash);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|