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,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BlockChainExplorerFactory = void 0;
|
|
13
|
+
const alot_1 = __importDefault(require("alot"));
|
|
14
|
+
const memd_1 = __importDefault(require("memd"));
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const _logger_1 = require("@dequanto/utils/$logger");
|
|
17
|
+
const _promise_1 = require("@dequanto/utils/$promise");
|
|
18
|
+
var BlockChainExplorerFactory;
|
|
19
|
+
(function (BlockChainExplorerFactory) {
|
|
20
|
+
function create(opts) {
|
|
21
|
+
const client = new Client();
|
|
22
|
+
return class {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.localDb = opts.CONTRACTS;
|
|
25
|
+
this.config = opts.getConfig();
|
|
26
|
+
this.getContractAbi = memd_1.default.fn.memoize(this.getContractAbi, {
|
|
27
|
+
trackRef: true,
|
|
28
|
+
persistance: new memd_1.default.FsTransport({
|
|
29
|
+
path: opts.ABI_CACHE
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
this.getContractSource = memd_1.default.fn.memoize(this.getContractSource, {
|
|
33
|
+
trackRef: true,
|
|
34
|
+
persistance: new memd_1.default.FsTransport({
|
|
35
|
+
path: opts.ABI_CACHE.replace('.json', '-source.json')
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async getContractMeta(q) {
|
|
40
|
+
q = q.toLowerCase();
|
|
41
|
+
let info = this.localDb.find(x => x.address.toLowerCase() === q || x.name?.toLowerCase() === q);
|
|
42
|
+
return info;
|
|
43
|
+
}
|
|
44
|
+
async getContractAbi(address, params) {
|
|
45
|
+
let info = await this.getContractMeta(address);
|
|
46
|
+
if (info?.proxy) {
|
|
47
|
+
address = info.proxy;
|
|
48
|
+
}
|
|
49
|
+
let url = `${this.config.host}/api?module=contract&action=getabi&address=${address}&apikey=${this.config.key}`;
|
|
50
|
+
let abi = await client.get(url);
|
|
51
|
+
let abiJson = JSON.parse(abi);
|
|
52
|
+
if (params?.implementation) {
|
|
53
|
+
if (/0x.{64}/.test(params.implementation)) {
|
|
54
|
+
let web3 = opts.getWeb3();
|
|
55
|
+
let stat = await web3.getNodeInfos();
|
|
56
|
+
//-let x = (BigInt($contract.keccak256("eip1967.proxy.implementation")) - 1n).toString(16);
|
|
57
|
+
let uin256Hex = await web3.getStorageAt('0x5a58505a96d1dbf8df91cb21b54419fc36e93fde', `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`);
|
|
58
|
+
let hex = uin256Hex.replace(/0x0+/, '0x');
|
|
59
|
+
return this.getContractAbi(hex);
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`Implement ${params.implementation} support`);
|
|
62
|
+
}
|
|
63
|
+
if (isOpenZeppelinProxy(abiJson)) {
|
|
64
|
+
let web3 = opts.getWeb3();
|
|
65
|
+
let uin256Hex = await web3.getStorageAt(address, `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`);
|
|
66
|
+
let hex = uin256Hex.replace(/0x0+/, '0x');
|
|
67
|
+
return this.getContractAbi(hex);
|
|
68
|
+
}
|
|
69
|
+
if (hasImplementationSlot(abiJson)) {
|
|
70
|
+
let web3 = opts.getWeb3();
|
|
71
|
+
let uin256Hex = await web3.readContract({
|
|
72
|
+
address: address,
|
|
73
|
+
abi: abiJson,
|
|
74
|
+
method: 'implementation',
|
|
75
|
+
arguments: []
|
|
76
|
+
});
|
|
77
|
+
let hex = uin256Hex.replace(/0x0+/, '0x');
|
|
78
|
+
return this.getContractAbi(hex);
|
|
79
|
+
}
|
|
80
|
+
if (hasTargetSlot(abiJson)) {
|
|
81
|
+
let web3 = opts.getWeb3();
|
|
82
|
+
let uin256Hex = await web3.readContract({
|
|
83
|
+
address: address,
|
|
84
|
+
abi: abiJson,
|
|
85
|
+
method: 'getTarget',
|
|
86
|
+
arguments: []
|
|
87
|
+
});
|
|
88
|
+
let hex = uin256Hex.replace(/0x0+/, '0x');
|
|
89
|
+
return this.getContractAbi(hex);
|
|
90
|
+
}
|
|
91
|
+
return { abi, implementation: address };
|
|
92
|
+
}
|
|
93
|
+
async getContractSource(address) {
|
|
94
|
+
let url = `${this.config.host}/api?module=contract&action=getsourcecode&address=${address}&apikey=${this.config.key}`;
|
|
95
|
+
let result = await client.get(url);
|
|
96
|
+
return Array.isArray(result) ? result[0] : result;
|
|
97
|
+
}
|
|
98
|
+
async getTransactions(addr, params) {
|
|
99
|
+
return this.loadTxs('txlist', addr, params);
|
|
100
|
+
}
|
|
101
|
+
async getTransactionsAll(addr) {
|
|
102
|
+
return this.loadTxsAll('txlist', addr);
|
|
103
|
+
}
|
|
104
|
+
async getInternalTransactions(addr, params) {
|
|
105
|
+
return this.loadTxs('txlistinternal', addr, params);
|
|
106
|
+
}
|
|
107
|
+
async getInternalTransactionsAll(addr) {
|
|
108
|
+
return this.loadTxsAll('txlistinternal', addr);
|
|
109
|
+
}
|
|
110
|
+
async getErc20Transfers(addr, fromBlockNumber) {
|
|
111
|
+
let events = await this.loadTxs('tokentx', addr, { fromBlockNumber });
|
|
112
|
+
events.forEach(transfer => {
|
|
113
|
+
transfer.timeStamp = new Date((Number(transfer.timeStamp) * 1000));
|
|
114
|
+
transfer.value = BigInt(transfer.value);
|
|
115
|
+
transfer.blockNumber = Number(transfer.blockNumber);
|
|
116
|
+
transfer.tokenDecimal = Number(transfer.tokenDecimal);
|
|
117
|
+
});
|
|
118
|
+
return events;
|
|
119
|
+
}
|
|
120
|
+
async getErc20TransfersAll(addr, fromBlockNumber) {
|
|
121
|
+
let events = await this.loadTxsAll('tokentx', addr);
|
|
122
|
+
events.forEach(transfer => {
|
|
123
|
+
transfer.timeStamp = new Date((Number(transfer.timeStamp) * 1000));
|
|
124
|
+
transfer.value = BigInt(transfer.value);
|
|
125
|
+
transfer.blockNumber = Number(transfer.blockNumber);
|
|
126
|
+
transfer.tokenDecimal = Number(transfer.tokenDecimal);
|
|
127
|
+
});
|
|
128
|
+
return events;
|
|
129
|
+
}
|
|
130
|
+
async loadTxs(type, address, params) {
|
|
131
|
+
let url = `${this.config.host}/api?module=account&action=${type}&address=${address}&sort=${params.sort ?? 'desc'}&apikey=${this.config.key}`;
|
|
132
|
+
if (params.fromBlockNumber != null) {
|
|
133
|
+
url += `&startblock=${params.fromBlockNumber}`;
|
|
134
|
+
}
|
|
135
|
+
if (params.page != null) {
|
|
136
|
+
url += `&page=${params.page}`;
|
|
137
|
+
}
|
|
138
|
+
if (params.size != null) {
|
|
139
|
+
url += `&offset=${params.size}`;
|
|
140
|
+
}
|
|
141
|
+
let txs = await client.get(url);
|
|
142
|
+
return txs;
|
|
143
|
+
}
|
|
144
|
+
async loadTxsAll(type, address) {
|
|
145
|
+
let page = 1;
|
|
146
|
+
let size = 1000;
|
|
147
|
+
let out = [];
|
|
148
|
+
let fromBlockNumber = null;
|
|
149
|
+
while (true) {
|
|
150
|
+
let arr = await this.loadTxs(type, address, { fromBlockNumber, sort: 'asc' });
|
|
151
|
+
out.push(...arr);
|
|
152
|
+
_logger_1.$logger.log(`Got transactions(${type}) for ${address}. Page: ${arr.length}; Received: ${out.length}. Latest Block: ${fromBlockNumber}`);
|
|
153
|
+
if (arr.length < size) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
page++;
|
|
157
|
+
fromBlockNumber = Number(arr[arr.length - 1].blockNumber);
|
|
158
|
+
}
|
|
159
|
+
return (0, alot_1.default)(out).distinctBy(x => x.hash).toArray();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
BlockChainExplorerFactory.create = create;
|
|
164
|
+
})(BlockChainExplorerFactory = exports.BlockChainExplorerFactory || (exports.BlockChainExplorerFactory = {}));
|
|
165
|
+
function isOpenZeppelinProxy(abi) {
|
|
166
|
+
let $interface = ['upgradeTo', 'implementation'];
|
|
167
|
+
return $interface.every(name => {
|
|
168
|
+
return abi.some(item => item.type === 'function' && item.name === name);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function hasImplementationSlot(abi) {
|
|
172
|
+
let $interface = ['proxyOwner', 'implementation'];
|
|
173
|
+
return $interface.every(name => {
|
|
174
|
+
return abi.some(item => item.type === 'function' && item.name === name);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function hasTargetSlot(abi) {
|
|
178
|
+
let $interface = ['upgrade', 'getTarget'];
|
|
179
|
+
return $interface.every(name => {
|
|
180
|
+
return abi.some(item => item.type === 'function' && item.name === name);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
class Client {
|
|
184
|
+
async get(url) {
|
|
185
|
+
return this.getInner(url);
|
|
186
|
+
}
|
|
187
|
+
async getPaged(url) {
|
|
188
|
+
let arr = [];
|
|
189
|
+
let page = 1;
|
|
190
|
+
let size = 200;
|
|
191
|
+
while (true) {
|
|
192
|
+
let path = `${url}&page=${page}&offset=${size}`;
|
|
193
|
+
let pageArr = await this.get(path);
|
|
194
|
+
arr = arr.concat(pageArr);
|
|
195
|
+
if (pageArr.length < size) {
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
page++;
|
|
199
|
+
}
|
|
200
|
+
return arr;
|
|
201
|
+
}
|
|
202
|
+
async getInner(url, opts) {
|
|
203
|
+
let resp = await axios_1.default.get(url);
|
|
204
|
+
let data = resp.data;
|
|
205
|
+
if (data.message === 'NOTOK') {
|
|
206
|
+
let str = data.result;
|
|
207
|
+
if (/Max rate/i.test(str)) {
|
|
208
|
+
let count = opts?.retryCount ?? 3;
|
|
209
|
+
if (--count === 0) {
|
|
210
|
+
throw new Error(str);
|
|
211
|
+
}
|
|
212
|
+
await _promise_1.$promise.wait(200);
|
|
213
|
+
return this.getInner(url, {
|
|
214
|
+
retryCount: count
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
throw new Error(str);
|
|
218
|
+
}
|
|
219
|
+
if (data.result == null) {
|
|
220
|
+
console.warn(`Blockchain "${url}" explorer returned empty result`, data);
|
|
221
|
+
}
|
|
222
|
+
return data.result;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
__decorate([
|
|
226
|
+
memd_1.default.deco.queued({ throttle: 1000 / 5 })
|
|
227
|
+
], Client.prototype, "get", null);
|
|
@@ -0,0 +1,32 @@
|
|
|
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.BlockChainExplorerProvider = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const Arbiscan_1 = require("@dequanto/chains/arbitrum/Arbiscan");
|
|
9
|
+
const Bscscan_1 = require("./Bscscan");
|
|
10
|
+
const Etherscan_1 = require("./Etherscan");
|
|
11
|
+
const Polyscan_1 = require("./Polyscan");
|
|
12
|
+
const XDaiscan_1 = require("@dequanto/chains/xdai/XDaiscan");
|
|
13
|
+
var BlockChainExplorerProvider;
|
|
14
|
+
(function (BlockChainExplorerProvider) {
|
|
15
|
+
function get(platform) {
|
|
16
|
+
switch (platform) {
|
|
17
|
+
case 'bsc':
|
|
18
|
+
return a_di_1.default.resolve(Bscscan_1.Bscscan);
|
|
19
|
+
case 'eth':
|
|
20
|
+
return a_di_1.default.resolve(Etherscan_1.Etherscan);
|
|
21
|
+
case 'polygon':
|
|
22
|
+
return a_di_1.default.resolve(Polyscan_1.Polyscan);
|
|
23
|
+
case 'arbitrum':
|
|
24
|
+
return a_di_1.default.resolve(Arbiscan_1.Arbiscan);
|
|
25
|
+
case 'xdai':
|
|
26
|
+
return a_di_1.default.resolve(XDaiscan_1.XDaiscan);
|
|
27
|
+
default:
|
|
28
|
+
throw new Error(`Unsupported platform ${platform} for block chain explorer`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
BlockChainExplorerProvider.get = get;
|
|
32
|
+
})(BlockChainExplorerProvider = exports.BlockChainExplorerProvider || (exports.BlockChainExplorerProvider = {}));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockNumberCache = void 0;
|
|
4
|
+
const Web3ClientFactory_1 = require("@dequanto/clients/Web3ClientFactory");
|
|
5
|
+
const JsonArrayStore_1 = require("@dequanto/json/JsonArrayStore");
|
|
6
|
+
class BlockNumberCache {
|
|
7
|
+
constructor(platform, name) {
|
|
8
|
+
this.platform = platform;
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.store = new JsonArrayStore_1.JsonArrayStore({
|
|
11
|
+
path: `/cache/${platform}/blockNumber-${name}.json`,
|
|
12
|
+
key: x => x.address
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async getCached(address) {
|
|
16
|
+
let entry = await this.store.getSingle(address);
|
|
17
|
+
return entry ?? {
|
|
18
|
+
address: address,
|
|
19
|
+
blockNumber: null,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async saveCached(cache) {
|
|
23
|
+
await this.store.upsert(cache);
|
|
24
|
+
}
|
|
25
|
+
async updateCache(cache) {
|
|
26
|
+
let client = Web3ClientFactory_1.Web3ClientFactory.get(this.platform);
|
|
27
|
+
let toleranz = 5;
|
|
28
|
+
let number = await client.getBlockNumberCached() - toleranz;
|
|
29
|
+
cache.blockNumber = Math.max(number, cache.blockNumber);
|
|
30
|
+
await this.store.upsert(cache);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.BlockNumberCache = BlockNumberCache;
|
|
@@ -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.Bscscan = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const BlockChainExplorerFactory_1 = require("./BlockChainExplorerFactory");
|
|
9
|
+
const _config_1 = require("@dequanto/utils/$config");
|
|
10
|
+
const BscWeb3Client_1 = require("@dequanto/clients/BscWeb3Client");
|
|
11
|
+
const contracts = _config_1.$config.get('contracts.bsc', []);
|
|
12
|
+
class Bscscan extends BlockChainExplorerFactory_1.BlockChainExplorerFactory.create({
|
|
13
|
+
ABI_CACHE: `./cache/bsc/abis.json`,
|
|
14
|
+
CONTRACTS: contracts,
|
|
15
|
+
getWeb3() {
|
|
16
|
+
return a_di_1.default.resolve(BscWeb3Client_1.BscWeb3Client);
|
|
17
|
+
},
|
|
18
|
+
getConfig() {
|
|
19
|
+
const config = _config_1.$config.get('blockchainExplorer.bsc');
|
|
20
|
+
return {
|
|
21
|
+
key: config?.key,
|
|
22
|
+
host: config?.host,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}) {
|
|
26
|
+
}
|
|
27
|
+
exports.Bscscan = Bscscan;
|
|
@@ -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.Etherscan = void 0;
|
|
7
|
+
const BlockChainExplorerFactory_1 = require("./BlockChainExplorerFactory");
|
|
8
|
+
const _config_1 = require("@dequanto/utils/$config");
|
|
9
|
+
const EthWeb3Client_1 = require("@dequanto/clients/EthWeb3Client");
|
|
10
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
11
|
+
const contracts = _config_1.$config.get('contracts.eth', []);
|
|
12
|
+
class Etherscan extends BlockChainExplorerFactory_1.BlockChainExplorerFactory.create({
|
|
13
|
+
ABI_CACHE: `./cache/eth/abis.json`,
|
|
14
|
+
CONTRACTS: contracts,
|
|
15
|
+
getWeb3() {
|
|
16
|
+
return a_di_1.default.resolve(EthWeb3Client_1.EthWeb3Client);
|
|
17
|
+
},
|
|
18
|
+
getConfig() {
|
|
19
|
+
const config = _config_1.$config.get('blockchainExplorer.eth');
|
|
20
|
+
return {
|
|
21
|
+
key: config?.key,
|
|
22
|
+
host: config?.host,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}) {
|
|
26
|
+
}
|
|
27
|
+
exports.Etherscan = Etherscan;
|
|
@@ -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.Polyscan = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const BlockChainExplorerFactory_1 = require("./BlockChainExplorerFactory");
|
|
9
|
+
const _config_1 = require("@dequanto/utils/$config");
|
|
10
|
+
const PolyWeb3Client_1 = require("@dequanto/clients/PolyWeb3Client");
|
|
11
|
+
const contracts = _config_1.$config.get('contracts.polygon', []);
|
|
12
|
+
class Polyscan extends BlockChainExplorerFactory_1.BlockChainExplorerFactory.create({
|
|
13
|
+
ABI_CACHE: `./cache/poly/abis.json`,
|
|
14
|
+
CONTRACTS: contracts,
|
|
15
|
+
getWeb3() {
|
|
16
|
+
return a_di_1.default.resolve(PolyWeb3Client_1.PolyWeb3Client);
|
|
17
|
+
},
|
|
18
|
+
getConfig() {
|
|
19
|
+
const config = _config_1.$config.get('blockchainExplorer.polygon');
|
|
20
|
+
return {
|
|
21
|
+
key: config?.key,
|
|
22
|
+
host: config?.host,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}) {
|
|
26
|
+
}
|
|
27
|
+
exports.Polyscan = Polyscan;
|
|
@@ -0,0 +1,69 @@
|
|
|
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.ChainAccountProvider = exports.ChainAccount = void 0;
|
|
7
|
+
const _config_1 = require("./utils/$config");
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
const _address_1 = require("./utils/$address");
|
|
11
|
+
class ChainAccount {
|
|
12
|
+
}
|
|
13
|
+
exports.ChainAccount = ChainAccount;
|
|
14
|
+
const accounts = _config_1.$config.get('accounts');
|
|
15
|
+
var ChainAccountProvider;
|
|
16
|
+
(function (ChainAccountProvider) {
|
|
17
|
+
function get(platform, name) {
|
|
18
|
+
let acc = accounts?.[platform]?.[name];
|
|
19
|
+
if (acc == null) {
|
|
20
|
+
throw new Error(`Account not resolved by name: ${name} in ${platform}`);
|
|
21
|
+
}
|
|
22
|
+
acc.name = name;
|
|
23
|
+
acc.platform = platform;
|
|
24
|
+
return acc;
|
|
25
|
+
}
|
|
26
|
+
ChainAccountProvider.get = get;
|
|
27
|
+
function tryGet(mix, platform) {
|
|
28
|
+
let all = this.getAll();
|
|
29
|
+
let accounts = all.filter(x => (_address_1.$address.eq(mix, x.address) || x.name == mix));
|
|
30
|
+
if (accounts.length === 0) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
let acc = accounts[0];
|
|
34
|
+
return {
|
|
35
|
+
...acc,
|
|
36
|
+
platform: platform ?? acc.platform
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
ChainAccountProvider.tryGet = tryGet;
|
|
40
|
+
function getAll() {
|
|
41
|
+
let out = [];
|
|
42
|
+
for (let platform in accounts) {
|
|
43
|
+
for (let name in accounts[platform]) {
|
|
44
|
+
let account = accounts[platform][name];
|
|
45
|
+
account.name = name;
|
|
46
|
+
account.platform = platform;
|
|
47
|
+
out.push(account);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
ChainAccountProvider.getAll = getAll;
|
|
53
|
+
function getAddressFromKey(key) {
|
|
54
|
+
const bytes = Buffer.from(key, 'hex');
|
|
55
|
+
const wallet = new ethers_1.Wallet(bytes);
|
|
56
|
+
return wallet.address;
|
|
57
|
+
}
|
|
58
|
+
ChainAccountProvider.getAddressFromKey = getAddressFromKey;
|
|
59
|
+
function generate(opts) {
|
|
60
|
+
const bytes = crypto_1.default.randomBytes(32);
|
|
61
|
+
const wallet = new ethers_1.Wallet(bytes);
|
|
62
|
+
return {
|
|
63
|
+
...(opts ?? {}),
|
|
64
|
+
address: wallet.address,
|
|
65
|
+
key: bytes.toString('hex'),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
ChainAccountProvider.generate = generate;
|
|
69
|
+
})(ChainAccountProvider = exports.ChainAccountProvider || (exports.ChainAccountProvider = {}));
|
|
@@ -0,0 +1,75 @@
|
|
|
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.ChainAccountsService = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const alot_1 = __importDefault(require("alot"));
|
|
9
|
+
const ChainAccounts_1 = require("./ChainAccounts");
|
|
10
|
+
const JsonArrayStore_1 = require("./json/JsonArrayStore");
|
|
11
|
+
const _address_1 = require("./utils/$address");
|
|
12
|
+
class ChainAccountsService {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.store = a_di_1.default.resolve(Store);
|
|
15
|
+
this.config = ChainAccounts_1.ChainAccountProvider;
|
|
16
|
+
}
|
|
17
|
+
async get(mix, platform) {
|
|
18
|
+
let acc = this.config.tryGet(mix, platform);
|
|
19
|
+
return acc ?? this.store.get(mix);
|
|
20
|
+
}
|
|
21
|
+
async getAll() {
|
|
22
|
+
return this.store.getAll();
|
|
23
|
+
}
|
|
24
|
+
async generate(opts) {
|
|
25
|
+
let current = await this.get(opts.name, opts.platform);
|
|
26
|
+
if (current) {
|
|
27
|
+
return current;
|
|
28
|
+
}
|
|
29
|
+
let account = this.config.generate(opts);
|
|
30
|
+
await this.store.save(account);
|
|
31
|
+
return account;
|
|
32
|
+
}
|
|
33
|
+
async generateMany(names, platform) {
|
|
34
|
+
let newAccounts = [];
|
|
35
|
+
let accounts = await (0, alot_1.default)(names).mapAsync(async (name) => {
|
|
36
|
+
let current = await this.get(name, platform);
|
|
37
|
+
if (current) {
|
|
38
|
+
return current;
|
|
39
|
+
}
|
|
40
|
+
let account = this.config.generate({ name, platform });
|
|
41
|
+
newAccounts.push(account);
|
|
42
|
+
return account;
|
|
43
|
+
}).toArrayAsync();
|
|
44
|
+
if (newAccounts.length > 0) {
|
|
45
|
+
await this.store.saveMany(newAccounts);
|
|
46
|
+
}
|
|
47
|
+
return accounts;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ChainAccountsService = ChainAccountsService;
|
|
51
|
+
class Store {
|
|
52
|
+
constructor() {
|
|
53
|
+
this.fs = new JsonArrayStore_1.JsonArrayStore({
|
|
54
|
+
path: './db/accounts/accounts.json',
|
|
55
|
+
key: x => (x.key ?? x.address),
|
|
56
|
+
format: true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async get(mix) {
|
|
60
|
+
let accounts = await this.fs.getAll();
|
|
61
|
+
if (_address_1.$address.isValid(mix)) {
|
|
62
|
+
return accounts.find(x => _address_1.$address.eq(mix, x.address));
|
|
63
|
+
}
|
|
64
|
+
return accounts.find(x => x.name === mix);
|
|
65
|
+
}
|
|
66
|
+
async getAll() {
|
|
67
|
+
return await this.fs.getAll();
|
|
68
|
+
}
|
|
69
|
+
async save(account) {
|
|
70
|
+
await this.fs.upsert(account);
|
|
71
|
+
}
|
|
72
|
+
async saveMany(accounts) {
|
|
73
|
+
await this.fs.upsertMany(accounts);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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.BlockDateResolver = void 0;
|
|
7
|
+
const _block_1 = require("@dequanto/utils/$block");
|
|
8
|
+
const alot_1 = __importDefault(require("alot"));
|
|
9
|
+
class BlockDateResolver {
|
|
10
|
+
constructor(client) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
this.AVG_INITIAL = {
|
|
13
|
+
eth: 12 * 1000,
|
|
14
|
+
bsc: 3 * 1000,
|
|
15
|
+
polygon: 3 * 1000,
|
|
16
|
+
};
|
|
17
|
+
this.known = [];
|
|
18
|
+
}
|
|
19
|
+
async getBlockNumberFor(date) {
|
|
20
|
+
this.q = date;
|
|
21
|
+
let avg = this.AVG_INITIAL[this.client.platform];
|
|
22
|
+
if (avg == null) {
|
|
23
|
+
throw new Error(`AVG Block Time not defined for ${this.client.platform}`);
|
|
24
|
+
}
|
|
25
|
+
let now = new Date();
|
|
26
|
+
let topBlock = {
|
|
27
|
+
blockNumber: await this.client.getBlockNumberCached(),
|
|
28
|
+
date: now,
|
|
29
|
+
avg,
|
|
30
|
+
};
|
|
31
|
+
this.known.push(topBlock);
|
|
32
|
+
return await this.moveNext(date);
|
|
33
|
+
}
|
|
34
|
+
async moveNext(date) {
|
|
35
|
+
let closestIndex = this.getClosest(date);
|
|
36
|
+
let block = this.known[closestIndex];
|
|
37
|
+
let timeDiff = this.diffTime(block.date, date);
|
|
38
|
+
let timeDistance = Math.abs(timeDiff);
|
|
39
|
+
const BLOCKS_TOLERANCE = 2;
|
|
40
|
+
if (timeDistance <= block.avg * BLOCKS_TOLERANCE) {
|
|
41
|
+
return block.blockNumber;
|
|
42
|
+
}
|
|
43
|
+
if (this.closestTime != null && timeDistance >= this.closestTime) {
|
|
44
|
+
let b = this.known[this.closestIdx];
|
|
45
|
+
return b.blockNumber;
|
|
46
|
+
}
|
|
47
|
+
this.closestTime = timeDistance;
|
|
48
|
+
this.closestIdx = closestIndex;
|
|
49
|
+
let nextInfo = await this.checkPoint(block, timeDiff);
|
|
50
|
+
if (nextInfo == null) {
|
|
51
|
+
return block.blockNumber;
|
|
52
|
+
}
|
|
53
|
+
return this.moveNext(date);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns index of the first known block, which is most near to specified block (it can be before or after the specified date).
|
|
57
|
+
*/
|
|
58
|
+
getClosest(date) {
|
|
59
|
+
let entry = (0, alot_1.default)(this.known).map(x => [
|
|
60
|
+
this.diffTimeAbs(x.date, date),
|
|
61
|
+
x
|
|
62
|
+
]).minItem(x => x[0])[1];
|
|
63
|
+
let i = this.known.indexOf(entry);
|
|
64
|
+
return i;
|
|
65
|
+
}
|
|
66
|
+
async checkPoint(anchor, diffTime) {
|
|
67
|
+
let diffCount = Math.round(diffTime / anchor.avg);
|
|
68
|
+
if (diffCount === 0) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
let blockNumber = anchor.blockNumber + diffCount;
|
|
72
|
+
let date = await this.getBlockDate(blockNumber);
|
|
73
|
+
let info = {
|
|
74
|
+
blockNumber: blockNumber,
|
|
75
|
+
date: date,
|
|
76
|
+
};
|
|
77
|
+
this.push(info);
|
|
78
|
+
this.refineAvg();
|
|
79
|
+
return info;
|
|
80
|
+
}
|
|
81
|
+
push(info) {
|
|
82
|
+
for (let i = 0; i < this.known.length; i++) {
|
|
83
|
+
let x = this.known[i];
|
|
84
|
+
if (info.date < x.date) {
|
|
85
|
+
this.known.splice(i, 0, info);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
this.known.push(info);
|
|
90
|
+
}
|
|
91
|
+
/** Loads the block and gets the Date of the block */
|
|
92
|
+
async getBlockDate(blockNumber) {
|
|
93
|
+
let block = await this.client.getBlock(blockNumber);
|
|
94
|
+
if (block == null) {
|
|
95
|
+
throw new Error(`Block not loaded: ${blockNumber}`);
|
|
96
|
+
}
|
|
97
|
+
let date = _block_1.$block.getDate(block);
|
|
98
|
+
return date;
|
|
99
|
+
}
|
|
100
|
+
/** Returns SIGNED time in milliseconds between two dates. Negative values when t2 < t1 */
|
|
101
|
+
diffTime(t1, t2) {
|
|
102
|
+
return (t2.getTime() - t1.getTime());
|
|
103
|
+
}
|
|
104
|
+
/** Returns ABSOLUTE time in milliseconds between two dates. */
|
|
105
|
+
diffTimeAbs(t1, t2) {
|
|
106
|
+
return Math.abs(this.diffTime(t1, t2));
|
|
107
|
+
}
|
|
108
|
+
/** Returns AVG block count between two dates */
|
|
109
|
+
getAvgBlockCountBetween(b1, b2) {
|
|
110
|
+
let diff = this.diffTimeAbs(b1.date, b2.date);
|
|
111
|
+
return Math.round(diff / Math.abs(b2.blockNumber - b1.blockNumber));
|
|
112
|
+
}
|
|
113
|
+
/** Having N>1 blocks we can better find out the AVG block time */
|
|
114
|
+
refineAvg() {
|
|
115
|
+
for (let i = 1; i < this.known.length; i++) {
|
|
116
|
+
let info = this.known[i];
|
|
117
|
+
let prev = this.known[i - 1];
|
|
118
|
+
info.avg = this.getAvgBlockCountBetween(prev, info);
|
|
119
|
+
if (i === 1) {
|
|
120
|
+
this.known[0].avg = info.avg;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.BlockDateResolver = BlockDateResolver;
|