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,296 @@
|
|
|
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.JsonArrayStore = void 0;
|
|
13
|
+
const atma_io_1 = require("atma-io");
|
|
14
|
+
const atma_utils_1 = require("atma-utils");
|
|
15
|
+
const memd_1 = __importDefault(require("memd"));
|
|
16
|
+
const alot_1 = __importDefault(require("alot"));
|
|
17
|
+
const class_json_1 = require("class-json");
|
|
18
|
+
class JsonArrayStore {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.fs = new JsonArrayFs(this.options.path, this.options.Type, this.options.map, this.options.format);
|
|
22
|
+
let keyFn = this.options.key;
|
|
23
|
+
if (keyFn == null) {
|
|
24
|
+
throw new Error('Key getter must be defined');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async query() {
|
|
28
|
+
let arr = await this.getAll();
|
|
29
|
+
return (0, alot_1.default)(arr);
|
|
30
|
+
}
|
|
31
|
+
async getAll(opts) {
|
|
32
|
+
if (this.fs.errored != null) {
|
|
33
|
+
throw this.fs.errored;
|
|
34
|
+
}
|
|
35
|
+
if (this.array == null) {
|
|
36
|
+
await this.restore();
|
|
37
|
+
}
|
|
38
|
+
let arr = this.array;
|
|
39
|
+
if (opts?.cloned) {
|
|
40
|
+
arr = class_json_1.JsonConvert.fromJSON(class_json_1.JsonConvert.toJSON(arr));
|
|
41
|
+
}
|
|
42
|
+
return arr;
|
|
43
|
+
}
|
|
44
|
+
async getDict() {
|
|
45
|
+
if (this.fs.errored != null) {
|
|
46
|
+
throw this.fs.errored;
|
|
47
|
+
}
|
|
48
|
+
if (this.hash != null) {
|
|
49
|
+
return this.hash;
|
|
50
|
+
}
|
|
51
|
+
await this.restore();
|
|
52
|
+
return this.hash;
|
|
53
|
+
}
|
|
54
|
+
async getSingle(key) {
|
|
55
|
+
if (this.fs.errored != null) {
|
|
56
|
+
throw this.fs.errored;
|
|
57
|
+
}
|
|
58
|
+
if (this.hash == null) {
|
|
59
|
+
await this.restore();
|
|
60
|
+
}
|
|
61
|
+
return this.hash[String(key)];
|
|
62
|
+
}
|
|
63
|
+
async saveAll(arr) {
|
|
64
|
+
let keyFn = this.options.key;
|
|
65
|
+
this.array = arr;
|
|
66
|
+
this.hash = (0, alot_1.default)(arr).toDictionary(x => String(keyFn(x)), x => x);
|
|
67
|
+
await this.fs.write(arr);
|
|
68
|
+
return arr;
|
|
69
|
+
}
|
|
70
|
+
async upsert(x) {
|
|
71
|
+
if (this.hash == null) {
|
|
72
|
+
await this.restore();
|
|
73
|
+
}
|
|
74
|
+
let entry = this.upsertSync(x);
|
|
75
|
+
await this.flush();
|
|
76
|
+
return entry;
|
|
77
|
+
}
|
|
78
|
+
async remove(key) {
|
|
79
|
+
if (this.hash == null) {
|
|
80
|
+
await this.restore();
|
|
81
|
+
}
|
|
82
|
+
let entry = this.removeSync(key);
|
|
83
|
+
await this.flush();
|
|
84
|
+
return entry;
|
|
85
|
+
}
|
|
86
|
+
async upsertMany(arr) {
|
|
87
|
+
if (this.hash == null) {
|
|
88
|
+
await this.restore();
|
|
89
|
+
}
|
|
90
|
+
let entries = arr.map(x => this.upsertSync(x));
|
|
91
|
+
await this.flush();
|
|
92
|
+
return entries;
|
|
93
|
+
}
|
|
94
|
+
getLock() {
|
|
95
|
+
return this.fs.lock;
|
|
96
|
+
}
|
|
97
|
+
async restore() {
|
|
98
|
+
let arr = await this.fs.read();
|
|
99
|
+
let keyFn = this.options.key;
|
|
100
|
+
if (this.array != null) {
|
|
101
|
+
// write was called inbetween
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.array = arr;
|
|
105
|
+
this.hash = (0, alot_1.default)(arr).toDictionary(x => String(keyFn(x)), x => x);
|
|
106
|
+
}
|
|
107
|
+
async flush() {
|
|
108
|
+
return await this.fs.write(this.array);
|
|
109
|
+
}
|
|
110
|
+
/** without flush */
|
|
111
|
+
upsertSync(x) {
|
|
112
|
+
let keyFn = this.options.key;
|
|
113
|
+
let key = String(keyFn(x));
|
|
114
|
+
if (key == null) {
|
|
115
|
+
throw new Error(`Key is undefined in ${JSON.stringify(x)}`);
|
|
116
|
+
}
|
|
117
|
+
let current = this.hash[key];
|
|
118
|
+
if (current) {
|
|
119
|
+
for (let prop in x) {
|
|
120
|
+
current[prop] = x[prop];
|
|
121
|
+
}
|
|
122
|
+
return current;
|
|
123
|
+
}
|
|
124
|
+
let entry = x;
|
|
125
|
+
let Type = this.options.Type;
|
|
126
|
+
if (Type != null && entry instanceof Type === false) {
|
|
127
|
+
entry = new Type(x);
|
|
128
|
+
}
|
|
129
|
+
this.array.push(entry);
|
|
130
|
+
this.hash[key] = entry;
|
|
131
|
+
return entry;
|
|
132
|
+
}
|
|
133
|
+
removeSync(key) {
|
|
134
|
+
let current = this.hash[key];
|
|
135
|
+
if (current == null) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
delete this.hash[key];
|
|
139
|
+
let i = this.array.indexOf(current);
|
|
140
|
+
if (i > -1) {
|
|
141
|
+
this.array.splice(i, 1);
|
|
142
|
+
}
|
|
143
|
+
return current;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.JsonArrayStore = JsonArrayStore;
|
|
147
|
+
class JsonArrayFs {
|
|
148
|
+
constructor(path, Type, mapFn, format) {
|
|
149
|
+
this.path = path;
|
|
150
|
+
this.Type = Type;
|
|
151
|
+
this.mapFn = mapFn;
|
|
152
|
+
this.format = format;
|
|
153
|
+
this.errored = null;
|
|
154
|
+
this.listeners = [];
|
|
155
|
+
this.version = 0;
|
|
156
|
+
this.busy = false;
|
|
157
|
+
this.pathBak = this.path + '.bak';
|
|
158
|
+
this.pathFilename = this.path.substring(this.path.lastIndexOf('/') + 1);
|
|
159
|
+
this.lock = new atma_utils_1.class_Dfr;
|
|
160
|
+
this.lock.resolve();
|
|
161
|
+
}
|
|
162
|
+
write(arr) {
|
|
163
|
+
this.array = arr;
|
|
164
|
+
let dfr = new atma_utils_1.class_Dfr;
|
|
165
|
+
this.listeners.push({
|
|
166
|
+
version: ++this.version,
|
|
167
|
+
promise: dfr
|
|
168
|
+
});
|
|
169
|
+
if (this.busy === true) {
|
|
170
|
+
this.pending = arr;
|
|
171
|
+
return dfr;
|
|
172
|
+
}
|
|
173
|
+
this.busy = true;
|
|
174
|
+
this.lock.defer();
|
|
175
|
+
this.writeInner(arr);
|
|
176
|
+
return dfr;
|
|
177
|
+
}
|
|
178
|
+
async read() {
|
|
179
|
+
if (this.array != null) {
|
|
180
|
+
return Promise.resolve(this.array);
|
|
181
|
+
}
|
|
182
|
+
let arr = await this.readInner();
|
|
183
|
+
return this.array = arr;
|
|
184
|
+
}
|
|
185
|
+
async readInner() {
|
|
186
|
+
let existsBak = await atma_io_1.File.existsAsync(this.pathBak);
|
|
187
|
+
if (existsBak) {
|
|
188
|
+
let arr = await Fs.read(this.pathBak);
|
|
189
|
+
if (this.array) {
|
|
190
|
+
// When `write` was called inbetween `exists` check and now
|
|
191
|
+
return this.array;
|
|
192
|
+
}
|
|
193
|
+
if (arr) {
|
|
194
|
+
await atma_io_1.File.renameAsync(this.pathBak, this.pathFilename);
|
|
195
|
+
return arr;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
await atma_io_1.File.removeAsync(this.pathBak);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
let exists = await atma_io_1.File.existsAsync(this.path);
|
|
202
|
+
if (exists === false) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
if (!this.path) {
|
|
206
|
+
throw new Error(`Read inner: ${this.path}/${this.pathBak} is undefined`);
|
|
207
|
+
}
|
|
208
|
+
let arr = await atma_io_1.File.readAsync(this.path);
|
|
209
|
+
if (this.Type) {
|
|
210
|
+
let rgx = Math.round(Math.random() * 100000);
|
|
211
|
+
let key = `JsonArray.Type ${rgx}`;
|
|
212
|
+
console.time(key);
|
|
213
|
+
arr = arr.map(x => class_json_1.JsonConvert.fromJSON(x, { Type: this.Type }));
|
|
214
|
+
console.timeEnd(key);
|
|
215
|
+
}
|
|
216
|
+
if (this.mapFn) {
|
|
217
|
+
arr = arr.map(this.mapFn);
|
|
218
|
+
}
|
|
219
|
+
return arr;
|
|
220
|
+
}
|
|
221
|
+
async writeInner(arr) {
|
|
222
|
+
try {
|
|
223
|
+
let v = this.version;
|
|
224
|
+
let data = Fs.serialize(arr, this.Type, this.format);
|
|
225
|
+
await atma_io_1.File.writeAsync(this.pathBak, data);
|
|
226
|
+
await atma_io_1.File.renameAsync(this.pathBak, this.pathFilename);
|
|
227
|
+
this.callWriteListeners(v, null);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
console.error(`JsonArrayStore.WriteInner`, error);
|
|
231
|
+
this.errored = error;
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
if (this.pending == null) {
|
|
235
|
+
this.busy = false;
|
|
236
|
+
this.lock.resolve();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
let next = this.pending;
|
|
240
|
+
this.pending = null;
|
|
241
|
+
this.writeInner(next);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
callWriteListeners(v, error = null) {
|
|
245
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
246
|
+
let x = this.listeners[i];
|
|
247
|
+
if (x.version <= v) {
|
|
248
|
+
try {
|
|
249
|
+
if (error != null) {
|
|
250
|
+
x.promise.reject(error);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
x.promise.resolve();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
this.listeners.splice(i, 1);
|
|
258
|
+
i--;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
__decorate([
|
|
265
|
+
memd_1.default.deco.memoize({ perInstance: true })
|
|
266
|
+
], JsonArrayFs.prototype, "readInner", null);
|
|
267
|
+
var Fs;
|
|
268
|
+
(function (Fs) {
|
|
269
|
+
function serialize(arr, Type, format) {
|
|
270
|
+
if (Type) {
|
|
271
|
+
arr = arr.map(x => class_json_1.JsonConvert.toJSON(x));
|
|
272
|
+
}
|
|
273
|
+
return JSON.stringify(arr, null, format ? ' ' : null);
|
|
274
|
+
}
|
|
275
|
+
Fs.serialize = serialize;
|
|
276
|
+
function parse(str) {
|
|
277
|
+
return JSON.parse(str);
|
|
278
|
+
}
|
|
279
|
+
Fs.parse = parse;
|
|
280
|
+
async function read(path) {
|
|
281
|
+
if (!path) {
|
|
282
|
+
throw new Error(`${path} is undefined`);
|
|
283
|
+
}
|
|
284
|
+
let str = await atma_io_1.File.readAsync(path, { skipHooks: true, encoding: 'utf8' });
|
|
285
|
+
if (str.length === 0) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
return JSON.parse(str);
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
Fs.read = read;
|
|
296
|
+
})(Fs || (Fs = {}));
|
|
@@ -0,0 +1,214 @@
|
|
|
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.JsonObjectStore = void 0;
|
|
13
|
+
const memd_1 = __importDefault(require("memd"));
|
|
14
|
+
const atma_io_1 = require("atma-io");
|
|
15
|
+
const atma_utils_1 = require("atma-utils");
|
|
16
|
+
const class_json_1 = require("class-json");
|
|
17
|
+
const _csv_1 = require("@dequanto/utils/$csv");
|
|
18
|
+
class JsonObjectStore {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.fs = new JsonFs(this.options.path, this.options.Type, this.options.map, this.options.format);
|
|
22
|
+
}
|
|
23
|
+
async get(opts) {
|
|
24
|
+
if (this.fs.errored != null) {
|
|
25
|
+
throw this.fs.errored;
|
|
26
|
+
}
|
|
27
|
+
if (this.data == null) {
|
|
28
|
+
await this.restore();
|
|
29
|
+
}
|
|
30
|
+
let arr = this.data;
|
|
31
|
+
if (opts?.cloned) {
|
|
32
|
+
arr = class_json_1.JsonConvert.fromJSON(class_json_1.JsonConvert.toJSON(arr));
|
|
33
|
+
}
|
|
34
|
+
return arr;
|
|
35
|
+
}
|
|
36
|
+
async save(arr) {
|
|
37
|
+
this.data = arr;
|
|
38
|
+
await this.fs.write(arr);
|
|
39
|
+
return arr;
|
|
40
|
+
}
|
|
41
|
+
getLock() {
|
|
42
|
+
return this.fs.lock;
|
|
43
|
+
}
|
|
44
|
+
async restore() {
|
|
45
|
+
let data = await this.fs.read(this.options.default);
|
|
46
|
+
if (this.data != null) {
|
|
47
|
+
// write was called inbetween
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.data = data;
|
|
51
|
+
}
|
|
52
|
+
async flush() {
|
|
53
|
+
return await this.fs.write(this.data);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.JsonObjectStore = JsonObjectStore;
|
|
57
|
+
class JsonFs {
|
|
58
|
+
constructor(path, Type, mapFn, format) {
|
|
59
|
+
this.path = path;
|
|
60
|
+
this.Type = Type;
|
|
61
|
+
this.mapFn = mapFn;
|
|
62
|
+
this.format = format;
|
|
63
|
+
this.errored = null;
|
|
64
|
+
this.listeners = [];
|
|
65
|
+
this.version = 0;
|
|
66
|
+
this.busy = false;
|
|
67
|
+
// private pathBak = this.path + '.bak';
|
|
68
|
+
// private pathFilename = this.path.substring(this.path.lastIndexOf('/') + 1);
|
|
69
|
+
this.lock = new atma_utils_1.class_Dfr;
|
|
70
|
+
this._file = new atma_io_1.File(this.path, { threadSafe: true });
|
|
71
|
+
}
|
|
72
|
+
write(value) {
|
|
73
|
+
this.value = value;
|
|
74
|
+
let dfr = new atma_utils_1.class_Dfr;
|
|
75
|
+
this.listeners.push({
|
|
76
|
+
version: ++this.version,
|
|
77
|
+
promise: dfr
|
|
78
|
+
});
|
|
79
|
+
if (this.busy === true) {
|
|
80
|
+
this.pending = value;
|
|
81
|
+
return dfr;
|
|
82
|
+
}
|
|
83
|
+
this.busy = true;
|
|
84
|
+
this.lock.defer();
|
|
85
|
+
this.writeInner(value);
|
|
86
|
+
return dfr;
|
|
87
|
+
}
|
|
88
|
+
async read($default) {
|
|
89
|
+
if (this.value != null) {
|
|
90
|
+
return Promise.resolve(this.value);
|
|
91
|
+
}
|
|
92
|
+
let arr = await this.readInner();
|
|
93
|
+
return this.value = arr ?? $default ?? {};
|
|
94
|
+
}
|
|
95
|
+
async readInner() {
|
|
96
|
+
if (await this._file.existsAsync() === false) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
let str = await this._file.readAsync({ skipHooks: true });
|
|
100
|
+
let data = JsonUtil.fromString(str, {}, this.Type, this._file.uri.toLocalFile());
|
|
101
|
+
if (this.mapFn) {
|
|
102
|
+
data = Array.isArray(data)
|
|
103
|
+
? data.map(this.mapFn)
|
|
104
|
+
: this.mapFn(data);
|
|
105
|
+
}
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
async writeInner(value) {
|
|
109
|
+
try {
|
|
110
|
+
let v = this.version;
|
|
111
|
+
let str = JsonUtil.toString(value, this.Type, this.format, this._file.uri.toLocalFile());
|
|
112
|
+
await this._file.writeAsync(str);
|
|
113
|
+
this.callWriteListeners(v, null);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error(`JsonArrayStore.WriteInner`, error);
|
|
117
|
+
this.errored = error;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (this.pending == null) {
|
|
121
|
+
this.busy = false;
|
|
122
|
+
this.lock.resolve();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
let next = this.pending;
|
|
126
|
+
this.pending = null;
|
|
127
|
+
this.writeInner(next);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
callWriteListeners(v, error = null) {
|
|
131
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
132
|
+
let x = this.listeners[i];
|
|
133
|
+
if (x.version <= v) {
|
|
134
|
+
try {
|
|
135
|
+
if (error != null) {
|
|
136
|
+
x.promise.reject(error);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
x.promise.resolve();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
this.listeners.splice(i, 1);
|
|
144
|
+
i--;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
__decorate([
|
|
151
|
+
memd_1.default.deco.memoize({ perInstance: true })
|
|
152
|
+
], JsonFs.prototype, "readInner", null);
|
|
153
|
+
var JsonUtil;
|
|
154
|
+
(function (JsonUtil) {
|
|
155
|
+
function mapToJson(data, Type) {
|
|
156
|
+
if (Type == null) {
|
|
157
|
+
return data;
|
|
158
|
+
}
|
|
159
|
+
return Array.isArray(data)
|
|
160
|
+
? data.map(x => class_json_1.JsonConvert.toJSON(x, { Type }))
|
|
161
|
+
: class_json_1.JsonConvert.toJSON(data, { Type });
|
|
162
|
+
}
|
|
163
|
+
JsonUtil.mapToJson = mapToJson;
|
|
164
|
+
function mapFromJson(json, Type) {
|
|
165
|
+
if (Type == null) {
|
|
166
|
+
return json;
|
|
167
|
+
}
|
|
168
|
+
return Array.isArray(json)
|
|
169
|
+
? json.map(x => class_json_1.JsonConvert.fromJSON(x, { Type }))
|
|
170
|
+
: class_json_1.JsonConvert.fromJSON(json, { Type });
|
|
171
|
+
}
|
|
172
|
+
JsonUtil.mapFromJson = mapFromJson;
|
|
173
|
+
function toString(data, Type, format, path) {
|
|
174
|
+
if (data == null) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
let json = mapToJson(data, Type);
|
|
178
|
+
return path.endsWith('.csv')
|
|
179
|
+
? CSV.stringify(json)
|
|
180
|
+
: JSON.stringify(json, null, format ? ' ' : null);
|
|
181
|
+
}
|
|
182
|
+
JsonUtil.toString = toString;
|
|
183
|
+
function fromString(str, $default, Type, path) {
|
|
184
|
+
if (str == null) {
|
|
185
|
+
if (Type) {
|
|
186
|
+
return class_json_1.JsonConvert.fromJSON($default, { Type });
|
|
187
|
+
}
|
|
188
|
+
return $default;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
let json = path.endsWith('.csv')
|
|
192
|
+
? CSV.parse(str)
|
|
193
|
+
: JSON.parse(str);
|
|
194
|
+
return mapFromJson(json, Type);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
return $default;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
JsonUtil.fromString = fromString;
|
|
201
|
+
})(JsonUtil || (JsonUtil = {}));
|
|
202
|
+
var CSV;
|
|
203
|
+
(function (CSV) {
|
|
204
|
+
function parse(str) {
|
|
205
|
+
return _csv_1.$csv.parseToRows(str);
|
|
206
|
+
}
|
|
207
|
+
CSV.parse = parse;
|
|
208
|
+
function stringify(rows) {
|
|
209
|
+
return _csv_1.$csv.stringify({
|
|
210
|
+
rows: rows
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
CSV.stringify = stringify;
|
|
214
|
+
})(CSV || (CSV = {}));
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const atma_io_1 = require("atma-io");
|
|
4
|
+
const JsonArrayStore_1 = require("./JsonArrayStore");
|
|
5
|
+
const JsonObjectStore_1 = require("./JsonObjectStore");
|
|
6
|
+
let pathArr = '/test/tmp/jsonstore-arr.json';
|
|
7
|
+
let pathObj = '/test/tmp/jsonstore-obj.json';
|
|
8
|
+
UTest({
|
|
9
|
+
'array': {
|
|
10
|
+
$before() {
|
|
11
|
+
atma_io_1.File.exists(pathArr) && atma_io_1.File.remove(pathArr);
|
|
12
|
+
},
|
|
13
|
+
async 'should handle multiple'() {
|
|
14
|
+
let store = new JsonArrayStore_1.JsonArrayStore({ path: pathArr, key: x => x.id });
|
|
15
|
+
let tick = Date.now();
|
|
16
|
+
store.upsert({ id: 1, letter: 'A', tick });
|
|
17
|
+
store.upsert({ id: 1, letter: 'B' });
|
|
18
|
+
store.upsert({ id: 1, letter: 'C' });
|
|
19
|
+
store.upsert({ id: 1, letter: 'D' });
|
|
20
|
+
await store.upsert({ id: 1, letter: 'E' });
|
|
21
|
+
let arr = await store.getAll();
|
|
22
|
+
eq_(arr.length, 1);
|
|
23
|
+
eq_(arr[0].letter, 'E');
|
|
24
|
+
eq_(arr[0].tick, tick);
|
|
25
|
+
store.upsert({ id: 1, letter: 'F' });
|
|
26
|
+
await store.upsert({ id: 1, letter: 'G' });
|
|
27
|
+
arr = await store.getAll();
|
|
28
|
+
eq_(arr.length, 1);
|
|
29
|
+
eq_(arr[0].letter, 'G');
|
|
30
|
+
await store.getLock();
|
|
31
|
+
let existsBak = await atma_io_1.File.existsAsync(pathArr + '.bak');
|
|
32
|
+
eq_(existsBak, false);
|
|
33
|
+
let str = await atma_io_1.File.readAsync(pathArr, { skipHooks: true, cache: false });
|
|
34
|
+
eq_(str[0], '[');
|
|
35
|
+
let json = JSON.parse(str);
|
|
36
|
+
deepEq_(json, arr);
|
|
37
|
+
},
|
|
38
|
+
'should load file and then write': {
|
|
39
|
+
async $before() {
|
|
40
|
+
await atma_io_1.File.writeAsync(pathArr, [
|
|
41
|
+
{ id: 'foo', letter: 'F' },
|
|
42
|
+
{ id: 'bar', letter: 'B' }
|
|
43
|
+
]);
|
|
44
|
+
atma_io_1.File.clearCache();
|
|
45
|
+
},
|
|
46
|
+
async 'load and upsert'() {
|
|
47
|
+
let store = new JsonArrayStore_1.JsonArrayStore({
|
|
48
|
+
path: pathArr,
|
|
49
|
+
key: x => x.id,
|
|
50
|
+
map: (x) => {
|
|
51
|
+
x.letter = x.letter.toLowerCase();
|
|
52
|
+
return x;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
let all = await store.getAll();
|
|
56
|
+
let tick = Date.now();
|
|
57
|
+
eq_(all.length, 2);
|
|
58
|
+
all[0].tick = tick;
|
|
59
|
+
all[1].tick = tick;
|
|
60
|
+
await store.upsertMany(all);
|
|
61
|
+
atma_io_1.File.clearCache();
|
|
62
|
+
let arr = await atma_io_1.File.readAsync(pathArr);
|
|
63
|
+
eq_(arr.length, 2);
|
|
64
|
+
eq_(arr[0].tick, tick);
|
|
65
|
+
eq_(arr[0].letter, 'f');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
'object': {
|
|
70
|
+
$before() {
|
|
71
|
+
atma_io_1.File.exists(pathObj) && atma_io_1.File.remove(pathObj);
|
|
72
|
+
},
|
|
73
|
+
async 'should handle multiple'() {
|
|
74
|
+
let store = new JsonObjectStore_1.JsonObjectStore({ path: pathObj });
|
|
75
|
+
let tick = Date.now();
|
|
76
|
+
await store.save({ tick });
|
|
77
|
+
let obj = await store.get();
|
|
78
|
+
eq_(obj.tick, tick);
|
|
79
|
+
let obj1 = await atma_io_1.File.readAsync(pathObj, { cache: false });
|
|
80
|
+
eq_(obj1.tick, tick);
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerService = void 0;
|
|
4
|
+
const everlog_1 = require("everlog");
|
|
5
|
+
class LoggerService {
|
|
6
|
+
constructor(name = 'journal') {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.channel = everlog_1.Everlog.createChannel(this.name, {
|
|
9
|
+
directory: './logs/dequanto/',
|
|
10
|
+
columns: [
|
|
11
|
+
{ type: 'date', name: 'Date' },
|
|
12
|
+
{ type: 'string', name: 'Level' },
|
|
13
|
+
{ type: 'string', name: 'Message' },
|
|
14
|
+
]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
warn(message) {
|
|
18
|
+
this.write([new Date(), 'Warn', message]);
|
|
19
|
+
}
|
|
20
|
+
error(message) {
|
|
21
|
+
this.write([new Date(), 'Error', message]);
|
|
22
|
+
}
|
|
23
|
+
info(message) {
|
|
24
|
+
this.write([new Date(), 'Info', message]);
|
|
25
|
+
}
|
|
26
|
+
write(row) {
|
|
27
|
+
let arr = typeof row === 'string' ? [row] : row;
|
|
28
|
+
arr.unshift(new Date());
|
|
29
|
+
this.channel.writeRow(arr);
|
|
30
|
+
console.log(Array.isArray(row) ? row.join(' ') : row);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.LoggerService = LoggerService;
|