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,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TxDataBuilder = void 0;
|
|
4
|
+
const InputDataUtils_1 = require("@dequanto/contracts/utils/InputDataUtils");
|
|
5
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
6
|
+
class TxDataBuilder {
|
|
7
|
+
constructor(client, account, data, config = null) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
this.account = account;
|
|
10
|
+
this.data = data;
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.data.value = this.data.value ?? 0;
|
|
13
|
+
}
|
|
14
|
+
setInputDataWithTypes(types, paramaters) {
|
|
15
|
+
this.data.data = InputDataUtils_1.InputDataUtils.encodeWithTypes(this.client, types, paramaters);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
setInputDataWithABI(IFunctionABI, ...params) {
|
|
19
|
+
try {
|
|
20
|
+
this.data.data = InputDataUtils_1.InputDataUtils.encodeWithABI(IFunctionABI, ...params);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
error.message = `${JSON.stringify(IFunctionABI)}\n${error.message}`;
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
setValue(value) {
|
|
29
|
+
if (value == null) {
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'number') {
|
|
33
|
+
value = _bigint_1.$bigint.toWei(value);
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === 'bigint') {
|
|
36
|
+
this.data.value = `0x${value.toString(16)}`;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
this.data.value = value;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
setConfig(config) {
|
|
43
|
+
this.config = config;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
async setNonce(opts) {
|
|
47
|
+
let nonce;
|
|
48
|
+
if (opts?.nonce != null) {
|
|
49
|
+
nonce = opts.nonce;
|
|
50
|
+
}
|
|
51
|
+
else if (opts?.overriding) {
|
|
52
|
+
nonce = await this.client.getTransactionCount(this.account.address);
|
|
53
|
+
// override first pending TX:
|
|
54
|
+
}
|
|
55
|
+
else if (opts?.noncePending != null) {
|
|
56
|
+
let pendingIndex = opts.noncePending - 1;
|
|
57
|
+
let submited = await this.client.getTransactionCount(this.account.address);
|
|
58
|
+
let next = pendingIndex;
|
|
59
|
+
if (next > 0) {
|
|
60
|
+
let total = await this.client.getTransactionCount(this.account.address, 'pending');
|
|
61
|
+
let pendingCount = total - submited;
|
|
62
|
+
if (pendingCount > 0 && next > pendingCount - 1) {
|
|
63
|
+
next = pendingCount - 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
nonce = submited + next;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
nonce = await this.client.getTransactionCount(this.account.address, 'pending');
|
|
70
|
+
}
|
|
71
|
+
// let count = opts?.nonce ?? (
|
|
72
|
+
// opts?.overriding === true
|
|
73
|
+
// ? await this.client.getTransactionCount(this.account.address)
|
|
74
|
+
// : await this.client.getTransactionCount(this.account.address, 'pending')
|
|
75
|
+
// );
|
|
76
|
+
//let nonce = count;
|
|
77
|
+
this.data.nonce = nonce;
|
|
78
|
+
}
|
|
79
|
+
async setGas({ price, priceRatio, gasLimitRatio, gasLimit, gasEstimation, from, type, } = {}) {
|
|
80
|
+
let [gasPrice, gasUsage] = await Promise.all([
|
|
81
|
+
price != null ?
|
|
82
|
+
{ price, base: price, priority: 10n ** 9n }
|
|
83
|
+
: this.client.getGasPrice(),
|
|
84
|
+
gasEstimation
|
|
85
|
+
? this.client.getGasEstimation(from, this.data)
|
|
86
|
+
: (gasLimit ?? this.client.defaultGasLimit ?? 2000000)
|
|
87
|
+
]);
|
|
88
|
+
let hasPriceRatio = priceRatio != null;
|
|
89
|
+
let hasPriceFixed = price != null;
|
|
90
|
+
let $priceRatio = 1;
|
|
91
|
+
if (hasPriceRatio) {
|
|
92
|
+
$priceRatio = priceRatio;
|
|
93
|
+
}
|
|
94
|
+
else if (hasPriceFixed === false) {
|
|
95
|
+
$priceRatio = 1.4;
|
|
96
|
+
}
|
|
97
|
+
if (type === 1) {
|
|
98
|
+
let $baseFee = _bigint_1.$bigint.multWithFloat(gasPrice.price, $priceRatio);
|
|
99
|
+
this.data.gasPrice = _bigint_1.$bigint.toHex($baseFee);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
let $baseFee = _bigint_1.$bigint.multWithFloat(gasPrice.base ?? gasPrice.price, $priceRatio);
|
|
103
|
+
let $priorityFee = gasPrice.priority ?? 10n ** 9n;
|
|
104
|
+
this.data.maxFeePerGas = _bigint_1.$bigint.toHex($baseFee + $priorityFee);
|
|
105
|
+
this.data.maxPriorityFeePerGas = _bigint_1.$bigint.toHex($priorityFee);
|
|
106
|
+
this.data.type = '0x02';
|
|
107
|
+
}
|
|
108
|
+
let hasLimitRatio = gasLimitRatio != null;
|
|
109
|
+
let hasLimitFixed = gasLimit != null;
|
|
110
|
+
let $gasLimitRatio = 1;
|
|
111
|
+
if (hasLimitRatio) {
|
|
112
|
+
$gasLimitRatio = gasLimitRatio;
|
|
113
|
+
}
|
|
114
|
+
else if (hasLimitFixed === false) {
|
|
115
|
+
$gasLimitRatio = 1.5;
|
|
116
|
+
}
|
|
117
|
+
this.data.gasLimit = gasLimit ?? Math.floor(Number(gasUsage) * $gasLimitRatio);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
increaseGas(ratio) {
|
|
121
|
+
let gasPrice = this.data.gasPrice;
|
|
122
|
+
if (gasPrice == null) {
|
|
123
|
+
throw new Error(`Not possible to increase the gas price, the price not set yet`);
|
|
124
|
+
}
|
|
125
|
+
let price = BigInt(this.data.gasPrice);
|
|
126
|
+
let priceNew = _bigint_1.$bigint.multWithFloat(price, ratio);
|
|
127
|
+
this.data.gasPrice = _bigint_1.$bigint.toHex(priceNew);
|
|
128
|
+
}
|
|
129
|
+
signToBuffer(privateKey) {
|
|
130
|
+
return this.client.sign(this.data, privateKey);
|
|
131
|
+
}
|
|
132
|
+
signToString(privateKey) {
|
|
133
|
+
if (privateKey.startsWith('0x')) {
|
|
134
|
+
privateKey = privateKey.substring(2);
|
|
135
|
+
}
|
|
136
|
+
let buffer = this.signToBuffer(privateKey);
|
|
137
|
+
return '0x' + buffer.toString('hex');
|
|
138
|
+
}
|
|
139
|
+
toJSON() {
|
|
140
|
+
return {
|
|
141
|
+
config: this.config,
|
|
142
|
+
data: this.data,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
static fromJSON(client, account, json) {
|
|
146
|
+
return new TxDataBuilder(client, account, json.data, json.config);
|
|
147
|
+
}
|
|
148
|
+
static normalize(data) {
|
|
149
|
+
for (let key in data) {
|
|
150
|
+
let v = data[key];
|
|
151
|
+
if (typeof v === 'string' && /^\d+$/.test(v)) {
|
|
152
|
+
data[key] = BigInt(v);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return data;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.TxDataBuilder = TxDataBuilder;
|
|
159
|
+
TxDataBuilder.nonce = -1;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TxLogger = void 0;
|
|
4
|
+
const _logger_1 = require("@dequanto/utils/$logger");
|
|
5
|
+
const everlog_1 = require("everlog");
|
|
6
|
+
class TxLogger {
|
|
7
|
+
constructor(id, from, builder) {
|
|
8
|
+
this.id = id;
|
|
9
|
+
this.from = from;
|
|
10
|
+
this.builder = builder;
|
|
11
|
+
}
|
|
12
|
+
log(message) {
|
|
13
|
+
_logger_1.$logger.log('TxLog:', message);
|
|
14
|
+
channels.log.writeRow([
|
|
15
|
+
new Date(),
|
|
16
|
+
'LOG',
|
|
17
|
+
this.id,
|
|
18
|
+
message
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
logStart() {
|
|
22
|
+
channels.start.writeRow([
|
|
23
|
+
new Date(),
|
|
24
|
+
this.id,
|
|
25
|
+
this.from,
|
|
26
|
+
this.builder.data.to,
|
|
27
|
+
this.builder.data.data?.toString()
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
logReceipt(receipt, time) {
|
|
31
|
+
channels.receipt.writeRow([
|
|
32
|
+
new Date(),
|
|
33
|
+
this.id,
|
|
34
|
+
receipt.transactionHash,
|
|
35
|
+
receipt.status,
|
|
36
|
+
time,
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
logError(error) {
|
|
40
|
+
_logger_1.$logger.log('TxError:', error.message);
|
|
41
|
+
channels.log.writeRow([
|
|
42
|
+
new Date(),
|
|
43
|
+
'ERROR',
|
|
44
|
+
this.id,
|
|
45
|
+
error.message
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.TxLogger = TxLogger;
|
|
50
|
+
const channels = {
|
|
51
|
+
start: everlog_1.Monit.createChannel('tx-starts', {
|
|
52
|
+
columns: [
|
|
53
|
+
{
|
|
54
|
+
type: 'date',
|
|
55
|
+
name: 'Date'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: 'string',
|
|
59
|
+
name: 'ID'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: 'string',
|
|
63
|
+
name: 'From'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'string',
|
|
67
|
+
name: 'To'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'string',
|
|
71
|
+
name: 'Method'
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}),
|
|
75
|
+
log: everlog_1.Monit.createChannel('tx-logs', {
|
|
76
|
+
columns: [
|
|
77
|
+
{
|
|
78
|
+
type: 'date',
|
|
79
|
+
name: 'Date'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'string',
|
|
83
|
+
name: 'Level'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: 'string',
|
|
87
|
+
name: 'TxID'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: 'string',
|
|
91
|
+
name: 'Error'
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}),
|
|
95
|
+
receipt: everlog_1.Monit.createChannel('tx-receipts', {
|
|
96
|
+
columns: [
|
|
97
|
+
{
|
|
98
|
+
type: 'date',
|
|
99
|
+
name: 'Date'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: 'string',
|
|
103
|
+
name: 'ID'
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
type: 'string',
|
|
107
|
+
name: 'TxHash'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: 'string',
|
|
111
|
+
name: 'Status'
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
type: 'number',
|
|
115
|
+
name: 'Duration'
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}),
|
|
119
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
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.TxProvider = void 0;
|
|
13
|
+
const EthWeb3Client_1 = require("@dequanto/clients/EthWeb3Client");
|
|
14
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
15
|
+
const memd_1 = __importDefault(require("memd"));
|
|
16
|
+
class TxProvider {
|
|
17
|
+
constructor(client = a_di_1.default.resolve(EthWeb3Client_1.EthWeb3Client)) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
this.cache = CacheProvider.create(`./cache/${this.client.platform}/txs.json`);
|
|
20
|
+
}
|
|
21
|
+
async loadTransaction(txHash) {
|
|
22
|
+
let tx = await this.client.getTransaction(txHash);
|
|
23
|
+
return tx;
|
|
24
|
+
}
|
|
25
|
+
async loadTransactionCached(txHash) {
|
|
26
|
+
return this.fromCache(`tx.${txHash}`, () => this.loadTransaction(txHash));
|
|
27
|
+
}
|
|
28
|
+
async loadTransactionReceipt(txHash) {
|
|
29
|
+
let receipt = await this.client.getTransactionReceipt(txHash);
|
|
30
|
+
return receipt;
|
|
31
|
+
}
|
|
32
|
+
async loadTransactionReceiptCached(txHash) {
|
|
33
|
+
return this.fromCache(`receipt.${txHash}`, () => this.loadTransactionReceipt(txHash));
|
|
34
|
+
}
|
|
35
|
+
async loadBlock(blockNumber) {
|
|
36
|
+
let block = await this.client.getBlock(blockNumber);
|
|
37
|
+
return block;
|
|
38
|
+
}
|
|
39
|
+
async loadBlockCached(blockNumber) {
|
|
40
|
+
return this.fromCache(`block.${blockNumber}`, () => this.loadBlock(blockNumber));
|
|
41
|
+
}
|
|
42
|
+
async fromCache(key, fn) {
|
|
43
|
+
let cached = await this.cache.getAsync(key);
|
|
44
|
+
if (cached) {
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
let val = await fn();
|
|
48
|
+
await this.cache.setAsync(key, val);
|
|
49
|
+
return val;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
__decorate([
|
|
53
|
+
memd_1.default.deco.memoize()
|
|
54
|
+
], TxProvider.prototype, "loadTransactionCached", null);
|
|
55
|
+
__decorate([
|
|
56
|
+
memd_1.default.deco.memoize()
|
|
57
|
+
], TxProvider.prototype, "loadTransactionReceiptCached", null);
|
|
58
|
+
__decorate([
|
|
59
|
+
memd_1.default.deco.memoize()
|
|
60
|
+
], TxProvider.prototype, "loadBlockCached", null);
|
|
61
|
+
exports.TxProvider = TxProvider;
|
|
62
|
+
class CacheProvider {
|
|
63
|
+
static create(path) {
|
|
64
|
+
let cache = new memd_1.default.Cache({
|
|
65
|
+
persistance: new memd_1.default.FsTransport({ path }),
|
|
66
|
+
trackRef: true
|
|
67
|
+
});
|
|
68
|
+
return cache;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
__decorate([
|
|
72
|
+
memd_1.default.deco.memoize()
|
|
73
|
+
], CacheProvider, "create", null);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TxService = void 0;
|
|
4
|
+
class TxService {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async cancelTx(hash) {
|
|
9
|
+
let tx = await this.client.getTransaction(hash);
|
|
10
|
+
if (tx == null) {
|
|
11
|
+
throw new Error(`Tx ${hash} not found`);
|
|
12
|
+
}
|
|
13
|
+
if (tx.blockNumber) {
|
|
14
|
+
throw new Error(`Tx ${hash} was already mined in block ${tx.blockNumber}`);
|
|
15
|
+
}
|
|
16
|
+
console.log(tx);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.TxService = TxService;
|
|
@@ -0,0 +1,287 @@
|
|
|
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.TxWriter = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const atma_utils_1 = require("atma-utils");
|
|
9
|
+
const TxDataBuilder_1 = require("./TxDataBuilder");
|
|
10
|
+
const TxLogger_1 = require("./TxLogger");
|
|
11
|
+
require("../env/BigIntSerializer");
|
|
12
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
13
|
+
const ChainAccountsService_1 = require("@dequanto/ChainAccountsService");
|
|
14
|
+
const Web3ClientFactory_1 = require("@dequanto/clients/Web3ClientFactory");
|
|
15
|
+
const _promise_1 = require("@dequanto/utils/$promise");
|
|
16
|
+
const ClientErrorUtil_1 = require("@dequanto/clients/utils/ClientErrorUtil");
|
|
17
|
+
const _logger_1 = require("@dequanto/utils/$logger");
|
|
18
|
+
const TxLogParser_1 = require("./receipt/TxLogParser");
|
|
19
|
+
class TxWriter extends atma_utils_1.class_EventEmitter {
|
|
20
|
+
constructor(client, builder, account) {
|
|
21
|
+
super();
|
|
22
|
+
this.client = client;
|
|
23
|
+
this.builder = builder;
|
|
24
|
+
this.account = account;
|
|
25
|
+
this.onSent = new atma_utils_1.class_Dfr();
|
|
26
|
+
this.onCompleted = new atma_utils_1.class_Dfr();
|
|
27
|
+
this.id = Math.round(Math.random() * 10 ** 10) + '';
|
|
28
|
+
this.tx = null;
|
|
29
|
+
this.txs = [];
|
|
30
|
+
this.logger = new TxLogger_1.TxLogger(this.id, this.account.name ?? this.account.key, this.builder);
|
|
31
|
+
this.confirmationAwaiters = [];
|
|
32
|
+
}
|
|
33
|
+
onConfirmed(waitForCount) {
|
|
34
|
+
let promise = new atma_utils_1.class_Dfr();
|
|
35
|
+
if (this.tx.confirmations >= waitForCount) {
|
|
36
|
+
promise.resolve(this.tx.hash);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.confirmationAwaiters.push({
|
|
40
|
+
count: waitForCount,
|
|
41
|
+
promise
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return promise;
|
|
45
|
+
}
|
|
46
|
+
send(options) {
|
|
47
|
+
if (this.tx == null) {
|
|
48
|
+
this.logger.logStart();
|
|
49
|
+
this.onCompleted.defer();
|
|
50
|
+
this.onSent.defer();
|
|
51
|
+
// was not sent
|
|
52
|
+
this.options = options;
|
|
53
|
+
this.sendTxInner();
|
|
54
|
+
}
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
write(options) {
|
|
58
|
+
if (this.builder?.config?.send !== 'manual') {
|
|
59
|
+
this.send(options);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
sendTxInner() {
|
|
63
|
+
let time = Date.now();
|
|
64
|
+
let signedTxBuffer = this.builder.signToString(this.account.key);
|
|
65
|
+
let tx = {
|
|
66
|
+
timestamp: Date.now(),
|
|
67
|
+
confirmations: 0,
|
|
68
|
+
hash: null,
|
|
69
|
+
receipt: null,
|
|
70
|
+
timeout: null,
|
|
71
|
+
};
|
|
72
|
+
tx.timeout = this.startTimer(tx);
|
|
73
|
+
this.tx = tx;
|
|
74
|
+
this.txs.push(tx);
|
|
75
|
+
let promiEvent = this
|
|
76
|
+
.client
|
|
77
|
+
.sendSignedTransaction(signedTxBuffer)
|
|
78
|
+
.once('transactionHash', hash => {
|
|
79
|
+
if (tx.hash && tx.timeout) {
|
|
80
|
+
// network has reaccepted the tx, restart previous timeout
|
|
81
|
+
this.clearTimer(tx);
|
|
82
|
+
tx.timeout = this.startTimer(tx);
|
|
83
|
+
}
|
|
84
|
+
tx.hash = hash;
|
|
85
|
+
this.onSent.resolve(hash);
|
|
86
|
+
this.emit('transactionHash', hash);
|
|
87
|
+
this.emit('log', `Tx hash received: ${hash}`);
|
|
88
|
+
})
|
|
89
|
+
.once('receipt', receipt => {
|
|
90
|
+
tx.receipt = receipt;
|
|
91
|
+
tx.hash = receipt.transactionHash ?? tx.hash;
|
|
92
|
+
this.receipt = receipt;
|
|
93
|
+
this.clearTimer(tx);
|
|
94
|
+
this.logger.logReceipt(receipt, Date.now() - time);
|
|
95
|
+
this.onSent.resolve();
|
|
96
|
+
this.emit('receipt', receipt);
|
|
97
|
+
this.emit('log', `Tx receipt received for ${receipt.transactionHash}. Status: ${receipt.status}`);
|
|
98
|
+
})
|
|
99
|
+
// .on('confirmation', (confNumber, receipt) => {
|
|
100
|
+
// tx.hash = receipt.transactionHash ?? tx.hash;
|
|
101
|
+
// this.onSent.resolve();
|
|
102
|
+
// this.emit('confirmation', confNumber, receipt);
|
|
103
|
+
// this.emit('log', `Tx confirmation received for ${tx.hash}. Confirmations: ${confNumber}`);
|
|
104
|
+
// let arr = this.confirmationAwaiters;
|
|
105
|
+
// for (let i = 0; i < arr.length; i++) {
|
|
106
|
+
// if (confNumber >= arr[i].count) {
|
|
107
|
+
// arr[i].promise.resolve();
|
|
108
|
+
// arr.splice(i, 1);
|
|
109
|
+
// i--;
|
|
110
|
+
// }
|
|
111
|
+
// }
|
|
112
|
+
// })
|
|
113
|
+
.on('error', error => {
|
|
114
|
+
this.clearTimer(tx);
|
|
115
|
+
this.logger.logError(error);
|
|
116
|
+
this.emit('error', error);
|
|
117
|
+
this.emit('log', `Tx ERROR "${error.message}"`);
|
|
118
|
+
})
|
|
119
|
+
.then(async (receipt) => {
|
|
120
|
+
this.clearTimer(tx);
|
|
121
|
+
try {
|
|
122
|
+
await this.extractLogs(receipt, tx);
|
|
123
|
+
}
|
|
124
|
+
catch (error) { }
|
|
125
|
+
this.onCompleted.resolve(receipt);
|
|
126
|
+
}, async (err) => {
|
|
127
|
+
this.clearTimer(tx);
|
|
128
|
+
tx.error = err;
|
|
129
|
+
const options = this.options ?? {};
|
|
130
|
+
if (err.receipt?.status === false) {
|
|
131
|
+
// read reason
|
|
132
|
+
// let client = await this.client.getWeb3();
|
|
133
|
+
// let tx = await this.client.getTransaction(err.receipt.transactionHash);
|
|
134
|
+
// console.log('RECEIPT', err.receipt, tx);
|
|
135
|
+
// try {
|
|
136
|
+
// let result = await client.eth.call(tx, tx.blockNumber);
|
|
137
|
+
// console.log('RESULT', result);
|
|
138
|
+
// } catch (err) {
|
|
139
|
+
// console.log('CALL ERROR', err);
|
|
140
|
+
// }
|
|
141
|
+
// throw new Error('asd');
|
|
142
|
+
}
|
|
143
|
+
if (ClientErrorUtil_1.ClientErrorUtil.IsInsufficientFunds(err)) {
|
|
144
|
+
if (this.builder.config?.gasFunding) {
|
|
145
|
+
this.fundAccountAndResend().catch(err => {
|
|
146
|
+
this.onCompleted.reject(err);
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (options.retries == null) {
|
|
151
|
+
options.retries = 1;
|
|
152
|
+
options.retryDelay = 5000;
|
|
153
|
+
// If insufficient funds this is can be due to the blockchain hasn't confirmed some incomming transactions
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (ClientErrorUtil_1.ClientErrorUtil.IsNonceTooLow(err)) {
|
|
157
|
+
if (options.retries == null) {
|
|
158
|
+
options.retries = 1;
|
|
159
|
+
}
|
|
160
|
+
let nonce = this.builder.data.nonce;
|
|
161
|
+
// reset nonce
|
|
162
|
+
await this.builder.setNonce();
|
|
163
|
+
this.logger.log(`Nonce was ${Number(nonce)} too low. Reetries left: ${options.retries}. New nonce: ${Number(this.builder.data.nonce)}`);
|
|
164
|
+
}
|
|
165
|
+
let submitsCount = this.txs.length;
|
|
166
|
+
let submitsMax = (options.retries ?? 0) + 1;
|
|
167
|
+
if (submitsCount < submitsMax) {
|
|
168
|
+
let ms = options.retryDelay ?? 3000;
|
|
169
|
+
let waitMs = ms * submitsCount;
|
|
170
|
+
_logger_1.$logger.log(`Tx retry in ${waitMs}ms`);
|
|
171
|
+
await _promise_1.$promise.wait(waitMs);
|
|
172
|
+
let onErrorRebuild = options.onErrorRebuild;
|
|
173
|
+
if (onErrorRebuild != null) {
|
|
174
|
+
let txBuilder = await onErrorRebuild(this, err, submitsCount);
|
|
175
|
+
if (txBuilder != null) {
|
|
176
|
+
this.builder = txBuilder;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
this.resubmit({ increaseGas: false });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.onCompleted.reject(err);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async extractLogs(receipt, tx) {
|
|
186
|
+
let parser = a_di_1.default.resolve(TxLogParser_1.TxLogParser);
|
|
187
|
+
let logs = await parser.parse(receipt);
|
|
188
|
+
tx.knownLogs = logs.filter(x => x != null);
|
|
189
|
+
}
|
|
190
|
+
async fundAccountAndResend() {
|
|
191
|
+
let account = this.builder.config.gasFunding;
|
|
192
|
+
await this.builder.setGas({
|
|
193
|
+
gasEstimation: true,
|
|
194
|
+
from: this.account.address
|
|
195
|
+
});
|
|
196
|
+
let { gasPrice, gasLimit } = this.builder.data;
|
|
197
|
+
let LITTLE_BIT_MORE = 1.3;
|
|
198
|
+
let wei = _bigint_1.$bigint.multWithFloat(BigInt(gasPrice) * BigInt(gasLimit), LITTLE_BIT_MORE);
|
|
199
|
+
let fundTx = await this.transferNative(account, this.account.address, wei);
|
|
200
|
+
await fundTx.onCompleted;
|
|
201
|
+
// account was funded resubmit the tx
|
|
202
|
+
this.resubmit();
|
|
203
|
+
}
|
|
204
|
+
startTimer(tx) {
|
|
205
|
+
let timeout = this.options?.timeout;
|
|
206
|
+
let ms;
|
|
207
|
+
if (typeof timeout === 'boolean') {
|
|
208
|
+
if (timeout === false) {
|
|
209
|
+
// Timeout was disabled
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
ms = this.client.TIMEOUT;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
ms = timeout ?? this.client.TIMEOUT;
|
|
216
|
+
}
|
|
217
|
+
return setTimeout(() => {
|
|
218
|
+
if (this.txs.length > 3) {
|
|
219
|
+
let hashes = this.txs.map(x => x.hash).join(', ');
|
|
220
|
+
this.onCompleted.reject(new Error(`${this.txs.length} retries timeouted, with hashes: ${hashes}`));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
tx.error = new Error(`Timeouted ${ms}ms`);
|
|
224
|
+
this.resubmit();
|
|
225
|
+
}, ms);
|
|
226
|
+
}
|
|
227
|
+
clearTimer(tx) {
|
|
228
|
+
if (tx.timeout) {
|
|
229
|
+
clearTimeout(tx.timeout);
|
|
230
|
+
tx.timeout = null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
resubmit({ increaseGas = true } = {}) {
|
|
234
|
+
if (increaseGas !== false) {
|
|
235
|
+
this.builder.increaseGas(1.1);
|
|
236
|
+
}
|
|
237
|
+
this.sendTxInner();
|
|
238
|
+
}
|
|
239
|
+
/** Use this transfer in case of additional account funding */
|
|
240
|
+
async transferNative(from, to, amount) {
|
|
241
|
+
let txBuilder = new TxDataBuilder_1.TxDataBuilder(this.client, from, {
|
|
242
|
+
to: to,
|
|
243
|
+
value: _bigint_1.$bigint.toHex(amount)
|
|
244
|
+
});
|
|
245
|
+
let GAS = 21000;
|
|
246
|
+
await Promise.all([
|
|
247
|
+
txBuilder.setGas({ gasLimit: GAS }),
|
|
248
|
+
txBuilder.setNonce(),
|
|
249
|
+
]);
|
|
250
|
+
return TxWriter.write(this.client, txBuilder, from);
|
|
251
|
+
}
|
|
252
|
+
toJSON() {
|
|
253
|
+
return {
|
|
254
|
+
id: this.id,
|
|
255
|
+
platform: this.client.platform,
|
|
256
|
+
options: this.options,
|
|
257
|
+
account: this.account.address,
|
|
258
|
+
txs: this.txs,
|
|
259
|
+
builder: this.builder.toJSON(),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
static async fromJSON(json, client) {
|
|
263
|
+
client = client ?? Web3ClientFactory_1.Web3ClientFactory.get(json.platform);
|
|
264
|
+
let service = a_di_1.default.resolve(ChainAccountsService_1.ChainAccountsService);
|
|
265
|
+
let account = await service.get(json.account, json.platform);
|
|
266
|
+
let builder = TxDataBuilder_1.TxDataBuilder.fromJSON(client, account, {
|
|
267
|
+
config: json.builder.config,
|
|
268
|
+
data: json.builder.data,
|
|
269
|
+
});
|
|
270
|
+
let writer = TxWriter.create(client, builder, account, json.options);
|
|
271
|
+
let txs = json.txs;
|
|
272
|
+
writer.id = json.id;
|
|
273
|
+
writer.tx = txs[txs.length - 1];
|
|
274
|
+
writer.txs = txs;
|
|
275
|
+
writer.receipt = txs.find(x => x.receipt)?.receipt;
|
|
276
|
+
return writer;
|
|
277
|
+
}
|
|
278
|
+
static write(client, builder, account, options) {
|
|
279
|
+
let writer = new TxWriter(client, builder, account);
|
|
280
|
+
writer.write(options);
|
|
281
|
+
return writer;
|
|
282
|
+
}
|
|
283
|
+
static create(client, builder, account, options) {
|
|
284
|
+
return new TxWriter(client, builder, account);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
exports.TxWriter = TxWriter;
|