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.
Files changed (477) hide show
  1. package/.vscode/settings.json +11 -0
  2. package/actions/gen.act.ts +38 -0
  3. package/actions/tokens.act.ts +12 -0
  4. package/configs/dequanto.yml +51 -0
  5. package/contracts/abi/erc20.abi.json +222 -0
  6. package/contracts/gen/amm/AmmFactoryV2ContractBase.ts +66 -0
  7. package/contracts/gen/amm/AmmMasterChefV2ContractBase.ts +158 -0
  8. package/contracts/gen/amm/AmmPairContractV2Base.ts +158 -0
  9. package/contracts/gen/amm/AmmPairContractV3Base.ts +125 -0
  10. package/contracts/gen/amm/AmmRouterV2ContractBase.ts +124 -0
  11. package/contracts/gen/amm/AmmVaultV2ContractBase.ts +214 -0
  12. package/contracts/gen/base/ERC20Base.ts +90 -0
  13. package/contracts/gen/bsc/OneInchRouterV3Base.ts +57 -0
  14. package/contracts/gen/eth/WETHBase/WETHBase.sol +756 -0
  15. package/contracts/gen/eth/WETHBase.ts +136 -0
  16. package/contracts/gen/polygon/ERC20PolygonBase.ts +305 -0
  17. package/contracts/gen/polygon/WormholeBridgeContractBase/Address.sol +216 -0
  18. package/contracts/gen/polygon/WormholeBridgeContractBase/BeaconProxy.sol +61 -0
  19. package/contracts/gen/polygon/WormholeBridgeContractBase/Bridge.sol +437 -0
  20. package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeGetters.sol +70 -0
  21. package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeGovernance.sol +142 -0
  22. package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeImplementation.sol +34 -0
  23. package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeSetters.sol +57 -0
  24. package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeState.sol +52 -0
  25. package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeStructs.sol +66 -0
  26. package/contracts/gen/polygon/WormholeBridgeContractBase/BytesLib.sol +510 -0
  27. package/contracts/gen/polygon/WormholeBridgeContractBase/Context.sol +23 -0
  28. package/contracts/gen/polygon/WormholeBridgeContractBase/ERC1967Proxy.sol +32 -0
  29. package/contracts/gen/polygon/WormholeBridgeContractBase/ERC1967Upgrade.sol +193 -0
  30. package/contracts/gen/polygon/WormholeBridgeContractBase/IBeacon.sol +15 -0
  31. package/contracts/gen/polygon/WormholeBridgeContractBase/IERC20.sol +81 -0
  32. package/contracts/gen/polygon/WormholeBridgeContractBase/IWormhole.sol +42 -0
  33. package/contracts/gen/polygon/WormholeBridgeContractBase/Ownable.sol +71 -0
  34. package/contracts/gen/polygon/WormholeBridgeContractBase/Proxy.sol +85 -0
  35. package/contracts/gen/polygon/WormholeBridgeContractBase/SafeERC20.sol +98 -0
  36. package/contracts/gen/polygon/WormholeBridgeContractBase/StorageSlot.sol +83 -0
  37. package/contracts/gen/polygon/WormholeBridgeContractBase/Structs.sol +40 -0
  38. package/contracts/gen/polygon/WormholeBridgeContractBase/Token.sol +12 -0
  39. package/contracts/gen/polygon/WormholeBridgeContractBase/TokenBridge.sol +15 -0
  40. package/contracts/gen/polygon/WormholeBridgeContractBase/TokenImplementation.sol +177 -0
  41. package/contracts/gen/polygon/WormholeBridgeContractBase/TokenState.sol +31 -0
  42. package/contracts/gen/polygon/WormholeBridgeContractBase.ts +231 -0
  43. package/contracts/gen/xdai/WXDaiTokenContractBase.ts +136 -0
  44. package/data/cex/eth.csv +356 -0
  45. package/data/tokens/1inch.json +16557 -0
  46. package/data/tokens/arbitrum.json +1 -0
  47. package/data/tokens/sushi.json +56388 -0
  48. package/dist/contracts/gen/amm/AmmFactoryV2ContractBase.js +53 -0
  49. package/dist/contracts/gen/amm/AmmMasterChefV2ContractBase.js +122 -0
  50. package/dist/contracts/gen/amm/AmmPairContractV2Base.js +122 -0
  51. package/dist/contracts/gen/amm/AmmPairContractV3Base.js +98 -0
  52. package/dist/contracts/gen/amm/AmmRouterV2ContractBase.js +95 -0
  53. package/dist/contracts/gen/amm/AmmVaultV2ContractBase.js +164 -0
  54. package/dist/contracts/gen/base/ERC20Base.js +64 -0
  55. package/dist/contracts/gen/bsc/OneInchRouterV3Base.js +47 -0
  56. package/dist/contracts/gen/eth/WETHBase.js +96 -0
  57. package/dist/contracts/gen/polygon/ERC20PolygonBase.js +233 -0
  58. package/dist/contracts/gen/polygon/WormholeBridgeContractBase.js +172 -0
  59. package/dist/contracts/gen/xdai/WXDaiTokenContractBase.js +96 -0
  60. package/dist/src/BlockchainExplorer/BlockChainExplorerFactory.js +227 -0
  61. package/dist/src/BlockchainExplorer/BlockChainExplorerProvider.js +32 -0
  62. package/dist/src/BlockchainExplorer/BlockNumberCache.js +33 -0
  63. package/dist/src/BlockchainExplorer/Bscscan.js +27 -0
  64. package/dist/src/BlockchainExplorer/Etherscan.js +27 -0
  65. package/dist/src/BlockchainExplorer/IAbiProvider.js +2 -0
  66. package/dist/src/BlockchainExplorer/IBlockChainExplorer.js +2 -0
  67. package/dist/src/BlockchainExplorer/Polyscan.js +27 -0
  68. package/dist/src/ChainAccounts.js +69 -0
  69. package/dist/src/ChainAccountsService.js +75 -0
  70. package/dist/src/Config.js +7 -0
  71. package/dist/src/blocks/BlockDateResolver.js +125 -0
  72. package/dist/src/bridges/BridgeFactory.js +19 -0
  73. package/dist/src/bridges/hop/HopAddresses.js +520 -0
  74. package/dist/src/bridges/hop/HopBridge.js +327 -0
  75. package/dist/src/bridges/hop/contracts/gen.act.js +43 -0
  76. package/dist/src/bridges/hop/contracts/polygon/Dai_l2AmmWrapperContract.js +52 -0
  77. package/dist/src/bridges/hop/contracts/polygon/Dai_l2BridgeContract.js +319 -0
  78. package/dist/src/bridges/hop/contracts/polygon/Dai_l2SaddleSwapContract.js +178 -0
  79. package/dist/src/bridges/hop/contracts/polygon/Eth_l2AmmWrapperContract.js +52 -0
  80. package/dist/src/bridges/hop/contracts/polygon/Eth_l2BridgeContract.js +319 -0
  81. package/dist/src/bridges/hop/contracts/polygon/Eth_l2SaddleSwapContract.js +178 -0
  82. package/dist/src/bridges/hop/contracts/polygon/Matic_l2AmmWrapperContract.js +52 -0
  83. package/dist/src/bridges/hop/contracts/polygon/Matic_l2BridgeContract.js +319 -0
  84. package/dist/src/bridges/hop/contracts/polygon/Matic_l2SaddleSwapContract.js +178 -0
  85. package/dist/src/bridges/hop/contracts/polygon/Usdc_l2AmmWrapperContract.js +52 -0
  86. package/dist/src/bridges/hop/contracts/polygon/Usdc_l2BridgeContract.js +319 -0
  87. package/dist/src/bridges/hop/contracts/polygon/Usdc_l2SaddleSwapContract.js +178 -0
  88. package/dist/src/bridges/hop/contracts/polygon/Usdt_l2AmmWrapperContract.js +52 -0
  89. package/dist/src/bridges/hop/contracts/polygon/Usdt_l2BridgeContract.js +319 -0
  90. package/dist/src/bridges/hop/contracts/polygon/Usdt_l2SaddleSwapContract.js +178 -0
  91. package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2AmmWrapperContract.js +52 -0
  92. package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2BridgeContract.js +319 -0
  93. package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2SaddleSwapContract.js +178 -0
  94. package/dist/src/bridges/models/IBridge.js +2 -0
  95. package/dist/src/bridges/wormhole/contracts/WormholeBridgeContract.js +15 -0
  96. package/dist/src/chains/PlatformFactory.js +42 -0
  97. package/dist/src/chains/arbitrum/ArbTokenProvider.js +40 -0
  98. package/dist/src/chains/arbitrum/ArbWeb3Client.js +39 -0
  99. package/dist/src/chains/arbitrum/Arbiscan.js +27 -0
  100. package/dist/src/chains/boba/BobaWeb3Client.js +47 -0
  101. package/dist/src/chains/boba/Bobascan.js +28 -0
  102. package/dist/src/chains/xdai/XDaiWeb3Client.js +87 -0
  103. package/dist/src/chains/xdai/XDaiscan.js +27 -0
  104. package/dist/src/chains/xdai/tokens/WXDaiTokenContract.js +15 -0
  105. package/dist/src/clients/BscWeb3Client.js +38 -0
  106. package/dist/src/clients/ClientEventsStream.js +34 -0
  107. package/dist/src/clients/ClientPool.js +560 -0
  108. package/dist/src/clients/ClientPoolStats.js +52 -0
  109. package/dist/src/clients/EthWeb3Client.js +35 -0
  110. package/dist/src/clients/HardhatWeb3Client.js +56 -0
  111. package/dist/src/clients/PolyWeb3Client.js +77 -0
  112. package/dist/src/clients/Web3Client.js +186 -0
  113. package/dist/src/clients/Web3ClientFactory.js +32 -0
  114. package/dist/src/clients/interfaces/IWeb3Client.js +2 -0
  115. package/dist/src/clients/interfaces/IWeb3ClientStatus.js +2 -0
  116. package/dist/src/clients/interfaces/IWeb3EndpointOptions.js +2 -0
  117. package/dist/src/clients/model/ClientStatus.js +9 -0
  118. package/dist/src/clients/model/PromiEventWrap.js +52 -0
  119. package/dist/src/clients/model/SubscriptionWrap.js +42 -0
  120. package/dist/src/clients/utils/ClientEndpoints.js +27 -0
  121. package/dist/src/clients/utils/ClientErrorUtil.js +30 -0
  122. package/dist/src/clients/utils/TxFactory.js +14 -0
  123. package/dist/src/contracts/BscContract.js +30 -0
  124. package/dist/src/contracts/Contract.js +90 -0
  125. package/dist/src/contracts/ContractBase.js +139 -0
  126. package/dist/src/contracts/ContractFactory.js +17 -0
  127. package/dist/src/contracts/ContractProvider.js +40 -0
  128. package/dist/src/contracts/ContractReader.js +76 -0
  129. package/dist/src/contracts/ContractStream.js +20 -0
  130. package/dist/src/contracts/ContractWriter.js +62 -0
  131. package/dist/src/contracts/EthContract.js +31 -0
  132. package/dist/src/contracts/TxContract.js +37 -0
  133. package/dist/src/contracts/common/ERC20.js +14 -0
  134. package/dist/src/contracts/common/ERC20Polygon.js +14 -0
  135. package/dist/src/contracts/common/PoolPair.js +23 -0
  136. package/dist/src/contracts/utils/AbiDeserializer.js +89 -0
  137. package/dist/src/contracts/utils/ConvertUtils.js +21 -0
  138. package/dist/src/contracts/utils/InputDataUtils.js +87 -0
  139. package/dist/src/contracts/utils/TypeUtils.js +24 -0
  140. package/dist/src/defi/OneInch/OneInchRouter.js +14 -0
  141. package/dist/src/env/BigIntSerializer.js +19 -0
  142. package/dist/src/gen/Ast.js +12 -0
  143. package/dist/src/gen/ContractTemplate.js +27 -0
  144. package/dist/src/gen/Generator.js +180 -0
  145. package/dist/src/gen/GeneratorFromAbi.js +361 -0
  146. package/dist/src/handlers/TokenHandler.js +69 -0
  147. package/dist/src/indexer/BlocksTxIndexer.js +52 -0
  148. package/dist/src/indexer/PendingTxIndexer.js +96 -0
  149. package/dist/src/indexer/handlers/BlocksWalker.js +306 -0
  150. package/dist/src/indexer/handlers/TxQueueLoader.js +117 -0
  151. package/dist/src/json/JsonArrayStore.js +296 -0
  152. package/dist/src/json/JsonObjectStore.js +214 -0
  153. package/dist/src/json/JsonStore.spec.js +83 -0
  154. package/dist/src/loggers/ILogger.js +2 -0
  155. package/dist/src/loggers/LoggerService.js +34 -0
  156. package/dist/src/loggers/TxLoggerService.js +122 -0
  157. package/dist/src/models/IContractDetails.js +2 -0
  158. package/dist/src/models/IToken.js +2 -0
  159. package/dist/src/models/ITokenGlob.js +6 -0
  160. package/dist/src/models/ITransactionDetails.js +2 -0
  161. package/dist/src/models/TAddress.js +2 -0
  162. package/dist/src/models/TBufferLike.js +2 -0
  163. package/dist/src/models/THex.js +2 -0
  164. package/dist/src/models/TPlatform.js +2 -0
  165. package/dist/src/models/TResult.js +2 -0
  166. package/dist/src/ns/NameService.js +19 -0
  167. package/dist/src/ns/providers/EnsProvider.js +41 -0
  168. package/dist/src/ns/providers/INsProvider.js +2 -0
  169. package/dist/src/ns/providers/UDProvider.js +39 -0
  170. package/dist/src/ns/utils/$ns.js +17 -0
  171. package/dist/src/structs/PackedRanges.js +186 -0
  172. package/dist/src/structs/PackedRanges.spec.js +30 -0
  173. package/dist/src/tokens/TokenExchangeService.js +110 -0
  174. package/dist/src/tokens/TokenExchanges/AmmBase/AmmUtilts.js +17 -0
  175. package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmFactoryV2Contract.js +15 -0
  176. package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmMasterChefV2Contract.js +15 -0
  177. package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Contract.js +16 -0
  178. package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Service.js +144 -0
  179. package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmRouterV2Contract.js +15 -0
  180. package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmVaultV2Contract.js +15 -0
  181. package/dist/src/tokens/TokenExchanges/AmmBase/V3/AmmPairV3Contract.js +22 -0
  182. package/dist/src/tokens/TokenExchanges/AmmV2ExchangeBase.js +194 -0
  183. package/dist/src/tokens/TokenExchanges/OneInchExchange.js +92 -0
  184. package/dist/src/tokens/TokenExchanges/PancakeswapExchange.js +28 -0
  185. package/dist/src/tokens/TokenExchanges/SushiswapPolygonExchange.js +28 -0
  186. package/dist/src/tokens/TokenExchanges/UniswapExchange.js +28 -0
  187. package/dist/src/tokens/TokenOracles/AmmPriceV2Oracle.js +319 -0
  188. package/dist/src/tokens/TokenOracles/TokenPriceStore.js +108 -0
  189. package/dist/src/tokens/TokenPriceService.js +196 -0
  190. package/dist/src/tokens/TokenPriceServiceProvider.js +31 -0
  191. package/dist/src/tokens/TokenProviders/ATokenProvider.js +38 -0
  192. package/dist/src/tokens/TokenProviders/ITokenProvider.js +2 -0
  193. package/dist/src/tokens/TokenProviders/TPChain.js +35 -0
  194. package/dist/src/tokens/TokenProviders/TPCoinmarketcap.js +63 -0
  195. package/dist/src/tokens/TokenProviders/TPOneInch.js +65 -0
  196. package/dist/src/tokens/TokenProviders/TPSushiswap.js +89 -0
  197. package/dist/src/tokens/TokenProviders/TPUniswap.js +84 -0
  198. package/dist/src/tokens/TokenService.js +115 -0
  199. package/dist/src/tokens/TokenSwapService.js +37 -0
  200. package/dist/src/tokens/TokenTransferService.js +189 -0
  201. package/dist/src/tokens/TokensService.js +236 -0
  202. package/dist/src/tokens/TokensServiceBsc.js +18 -0
  203. package/dist/src/tokens/TokensServiceEth.js +15 -0
  204. package/dist/src/tokens/TokensServiceFactory.js +29 -0
  205. package/dist/src/tokens/TokensServicePolygon.js +18 -0
  206. package/dist/src/tokens/TokensServiceXDai.js +24 -0
  207. package/dist/src/tokens/defi/ISwapService.js +2 -0
  208. package/dist/src/tokens/defi/paraswap/Paraswap.js +135 -0
  209. package/dist/src/tokens/erc20/eth/WETH.js +14 -0
  210. package/dist/src/tokens/utils/TokenUtils.js +66 -0
  211. package/dist/src/txs/ITxConfig.js +2 -0
  212. package/dist/src/txs/TxDataBuilder.js +159 -0
  213. package/dist/src/txs/TxLogger.js +119 -0
  214. package/dist/src/txs/TxProvider.js +73 -0
  215. package/dist/src/txs/TxService.js +19 -0
  216. package/dist/src/txs/TxWriter.js +287 -0
  217. package/dist/src/txs/conditional/GasWatcherLogger.js +61 -0
  218. package/dist/src/txs/conditional/GasWatcherService.js +103 -0
  219. package/dist/src/txs/conditional/GasWatcherStore.js +25 -0
  220. package/dist/src/txs/conditional/GasWatcherTx.js +126 -0
  221. package/dist/src/txs/receipt/ITxLogItem.js +2 -0
  222. package/dist/src/txs/receipt/TxLogParser.js +27 -0
  223. package/dist/src/txs/receipt/TxLogsTransfer.js +50 -0
  224. package/dist/src/txs/receipt/TxTopicInMemoryProvider.js +41 -0
  225. package/dist/src/txs/receipt/TxTopicProvider.js +25 -0
  226. package/dist/src/utils/$abiParser.js +159 -0
  227. package/dist/src/utils/$abiType.js +77 -0
  228. package/dist/src/utils/$abiUtils.js +43 -0
  229. package/dist/src/utils/$address.js +41 -0
  230. package/dist/src/utils/$array.js +60 -0
  231. package/dist/src/utils/$bigint.js +130 -0
  232. package/dist/src/utils/$block.js +10 -0
  233. package/dist/src/utils/$class.js +13 -0
  234. package/dist/src/utils/$config.js +18 -0
  235. package/dist/src/utils/$contract.js +67 -0
  236. package/dist/src/utils/$csv.js +79 -0
  237. package/dist/src/utils/$date.js +496 -0
  238. package/dist/src/utils/$fn.js +117 -0
  239. package/dist/src/utils/$is.js +40 -0
  240. package/dist/src/utils/$logger.js +15 -0
  241. package/dist/src/utils/$number.js +95 -0
  242. package/dist/src/utils/$object.js +82 -0
  243. package/dist/src/utils/$path.js +33 -0
  244. package/dist/src/utils/$promise.js +13 -0
  245. package/dist/src/utils/$require.js +127 -0
  246. package/dist/src/utils/$sign.js +35 -0
  247. package/dist/src/utils/$signSerializer.js +264 -0
  248. package/dist/src/utils/$wallet.js +13 -0
  249. package/dist/src/utils/types.js +2 -0
  250. package/dist/src/wallets/Wallet.js +26 -0
  251. package/dist/src/wallets/WalletBsc.js +17 -0
  252. package/dist/src/wallets/WalletService.js +35 -0
  253. package/dist/src/www/utils/BlockChainExplorerFormatter.js +15 -0
  254. package/hardhat.config.js +6 -0
  255. package/package.json +52 -0
  256. package/readme.md +76 -0
  257. package/src/BlockchainExplorer/BlockChainExplorerFactory.ts +273 -0
  258. package/src/BlockchainExplorer/BlockChainExplorerProvider.ts +26 -0
  259. package/src/BlockchainExplorer/BlockNumberCache.ts +46 -0
  260. package/src/BlockchainExplorer/Bscscan.ts +23 -0
  261. package/src/BlockchainExplorer/Etherscan.ts +25 -0
  262. package/src/BlockchainExplorer/IAbiProvider.ts +5 -0
  263. package/src/BlockchainExplorer/IBlockChainExplorer.ts +37 -0
  264. package/src/BlockchainExplorer/Polyscan.ts +23 -0
  265. package/src/ChainAccounts.ts +72 -0
  266. package/src/ChainAccountsService.ts +74 -0
  267. package/src/Config.ts +34 -0
  268. package/src/blocks/BlockDateResolver.ts +149 -0
  269. package/src/bridges/BridgeFactory.ts +16 -0
  270. package/src/bridges/hop/HopAddresses.ts +518 -0
  271. package/src/bridges/hop/HopBridge.ts +430 -0
  272. package/src/bridges/hop/contracts/gen.act.ts +50 -0
  273. package/src/bridges/hop/contracts/polygon/Dai_l2AmmWrapperContract.ts +69 -0
  274. package/src/bridges/hop/contracts/polygon/Dai_l2BridgeContract.ts +453 -0
  275. package/src/bridges/hop/contracts/polygon/Dai_l2SaddleSwapContract.ts +264 -0
  276. package/src/bridges/hop/contracts/polygon/Eth_l2AmmWrapperContract.ts +69 -0
  277. package/src/bridges/hop/contracts/polygon/Eth_l2BridgeContract.ts +453 -0
  278. package/src/bridges/hop/contracts/polygon/Eth_l2SaddleSwapContract.ts +264 -0
  279. package/src/bridges/hop/contracts/polygon/Matic_l2AmmWrapperContract.ts +69 -0
  280. package/src/bridges/hop/contracts/polygon/Matic_l2BridgeContract.ts +453 -0
  281. package/src/bridges/hop/contracts/polygon/Matic_l2SaddleSwapContract.ts +264 -0
  282. package/src/bridges/hop/contracts/polygon/Usdc_l2AmmWrapperContract.ts +69 -0
  283. package/src/bridges/hop/contracts/polygon/Usdc_l2BridgeContract.ts +453 -0
  284. package/src/bridges/hop/contracts/polygon/Usdc_l2SaddleSwapContract.ts +264 -0
  285. package/src/bridges/hop/contracts/polygon/Usdt_l2AmmWrapperContract.ts +69 -0
  286. package/src/bridges/hop/contracts/polygon/Usdt_l2BridgeContract.ts +453 -0
  287. package/src/bridges/hop/contracts/polygon/Usdt_l2SaddleSwapContract.ts +264 -0
  288. package/src/bridges/hop/contracts/polygon/Wbtc_l2AmmWrapperContract.ts +69 -0
  289. package/src/bridges/hop/contracts/polygon/Wbtc_l2BridgeContract.ts +453 -0
  290. package/src/bridges/hop/contracts/polygon/Wbtc_l2SaddleSwapContract.ts +264 -0
  291. package/src/bridges/models/IBridge.ts +43 -0
  292. package/src/bridges/wormhole/contracts/WormholeBridgeContract.ts +14 -0
  293. package/src/chains/PlatformFactory.ts +45 -0
  294. package/src/chains/arbitrum/ArbTokenProvider.ts +39 -0
  295. package/src/chains/arbitrum/ArbWeb3Client.ts +39 -0
  296. package/src/chains/arbitrum/Arbiscan.ts +24 -0
  297. package/src/chains/boba/BobaWeb3Client.ts +49 -0
  298. package/src/chains/boba/Bobascan.ts +25 -0
  299. package/src/chains/xdai/XDaiWeb3Client.ts +82 -0
  300. package/src/chains/xdai/XDaiscan.ts +24 -0
  301. package/src/chains/xdai/tokens/WXDaiTokenContract.json +279 -0
  302. package/src/chains/xdai/tokens/WXDaiTokenContract.ts +14 -0
  303. package/src/clients/BscWeb3Client.ts +38 -0
  304. package/src/clients/ClientEventsStream.ts +33 -0
  305. package/src/clients/ClientPool.ts +673 -0
  306. package/src/clients/ClientPoolStats.ts +64 -0
  307. package/src/clients/EthWeb3Client.ts +36 -0
  308. package/src/clients/HardhatWeb3Client.ts +60 -0
  309. package/src/clients/PolyWeb3Client.ts +91 -0
  310. package/src/clients/Web3Client.ts +228 -0
  311. package/src/clients/Web3ClientFactory.ts +28 -0
  312. package/src/clients/interfaces/IWeb3Client.ts +14 -0
  313. package/src/clients/interfaces/IWeb3ClientStatus.ts +23 -0
  314. package/src/clients/interfaces/IWeb3EndpointOptions.ts +9 -0
  315. package/src/clients/model/ClientStatus.ts +5 -0
  316. package/src/clients/model/PromiEventWrap.ts +61 -0
  317. package/src/clients/model/SubscriptionWrap.ts +53 -0
  318. package/src/clients/utils/ClientEndpoints.ts +26 -0
  319. package/src/clients/utils/ClientErrorUtil.ts +26 -0
  320. package/src/clients/utils/TxFactory.ts +17 -0
  321. package/src/contracts/BscContract.ts +28 -0
  322. package/src/contracts/Contract.ts +126 -0
  323. package/src/contracts/ContractBase.ts +158 -0
  324. package/src/contracts/ContractFactory.ts +19 -0
  325. package/src/contracts/ContractProvider.ts +55 -0
  326. package/src/contracts/ContractReader.ts +87 -0
  327. package/src/contracts/ContractStream.ts +18 -0
  328. package/src/contracts/ContractWriter.ts +97 -0
  329. package/src/contracts/EthContract.ts +29 -0
  330. package/src/contracts/TxContract.ts +43 -0
  331. package/src/contracts/common/ERC20.ts +13 -0
  332. package/src/contracts/common/ERC20Polygon.ts +13 -0
  333. package/src/contracts/common/PoolPair.ts +22 -0
  334. package/src/contracts/utils/AbiDeserializer.ts +98 -0
  335. package/src/contracts/utils/ConvertUtils.ts +16 -0
  336. package/src/contracts/utils/InputDataUtils.ts +93 -0
  337. package/src/contracts/utils/TypeUtils.ts +21 -0
  338. package/src/defi/OneInch/OneInchRouter.ts +13 -0
  339. package/src/env/BigIntSerializer.ts +18 -0
  340. package/src/gen/Ast.ts +12 -0
  341. package/src/gen/ContractTemplate.ts +36 -0
  342. package/src/gen/Generator.ts +227 -0
  343. package/src/gen/GeneratorFromAbi.ts +402 -0
  344. package/src/handlers/TokenHandler.ts +78 -0
  345. package/src/indexer/BlocksTxIndexer.ts +69 -0
  346. package/src/indexer/PendingTxIndexer.ts +124 -0
  347. package/src/indexer/handlers/BlocksWalker.ts +390 -0
  348. package/src/indexer/handlers/TxQueueLoader.ts +143 -0
  349. package/src/json/JsonArrayStore.ts +310 -0
  350. package/src/json/JsonObjectStore.ts +239 -0
  351. package/src/json/JsonStore.spec.ts +98 -0
  352. package/src/loggers/ILogger.ts +3 -0
  353. package/src/loggers/LoggerService.ts +39 -0
  354. package/src/loggers/TxLoggerService.ts +146 -0
  355. package/src/models/IContractDetails.ts +8 -0
  356. package/src/models/IToken.ts +11 -0
  357. package/src/models/ITokenGlob.ts +14 -0
  358. package/src/models/ITransactionDetails.ts +11 -0
  359. package/src/models/TAddress.ts +1 -0
  360. package/src/models/TBufferLike.ts +2 -0
  361. package/src/models/THex.ts +1 -0
  362. package/src/models/TPlatform.ts +1 -0
  363. package/src/models/TResult.ts +6 -0
  364. package/src/ns/NameService.ts +21 -0
  365. package/src/ns/providers/EnsProvider.ts +45 -0
  366. package/src/ns/providers/INsProvider.ts +6 -0
  367. package/src/ns/providers/UDProvider.ts +49 -0
  368. package/src/ns/utils/$ns.ts +15 -0
  369. package/src/structs/PackedRanges.spec.ts +38 -0
  370. package/src/structs/PackedRanges.ts +207 -0
  371. package/src/tokens/TokenExchangeService.ts +126 -0
  372. package/src/tokens/TokenExchanges/AmmBase/AmmUtilts.ts +16 -0
  373. package/src/tokens/TokenExchanges/AmmBase/V2/AmmFactoryV2Contract.ts +15 -0
  374. package/src/tokens/TokenExchanges/AmmBase/V2/AmmMasterChefV2Contract.ts +15 -0
  375. package/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Contract.ts +17 -0
  376. package/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Service.ts +208 -0
  377. package/src/tokens/TokenExchanges/AmmBase/V2/AmmRouterV2Contract.ts +15 -0
  378. package/src/tokens/TokenExchanges/AmmBase/V2/AmmVaultV2Contract.ts +15 -0
  379. package/src/tokens/TokenExchanges/AmmBase/V3/AmmPairV3Contract.ts +24 -0
  380. package/src/tokens/TokenExchanges/AmmV2ExchangeBase.ts +242 -0
  381. package/src/tokens/TokenExchanges/OneInchExchange.ts +111 -0
  382. package/src/tokens/TokenExchanges/PancakeswapExchange.ts +30 -0
  383. package/src/tokens/TokenExchanges/SushiswapPolygonExchange.ts +30 -0
  384. package/src/tokens/TokenExchanges/UniswapExchange.ts +31 -0
  385. package/src/tokens/TokenOracles/AmmPriceV2Oracle.ts +440 -0
  386. package/src/tokens/TokenOracles/TokenPriceStore.ts +129 -0
  387. package/src/tokens/TokenPriceService.ts +276 -0
  388. package/src/tokens/TokenPriceServiceProvider.ts +36 -0
  389. package/src/tokens/TokenProviders/ATokenProvider.ts +42 -0
  390. package/src/tokens/TokenProviders/ITokenProvider.ts +9 -0
  391. package/src/tokens/TokenProviders/TPChain.ts +41 -0
  392. package/src/tokens/TokenProviders/TPCoinmarketcap.ts +82 -0
  393. package/src/tokens/TokenProviders/TPOneInch.ts +71 -0
  394. package/src/tokens/TokenProviders/TPSushiswap.ts +96 -0
  395. package/src/tokens/TokenProviders/TPUniswap.ts +85 -0
  396. package/src/tokens/TokenService.ts +128 -0
  397. package/src/tokens/TokenSwapService.ts +47 -0
  398. package/src/tokens/TokenTransferService.ts +216 -0
  399. package/src/tokens/TokensService.ts +252 -0
  400. package/src/tokens/TokensServiceBsc.ts +17 -0
  401. package/src/tokens/TokensServiceEth.ts +9 -0
  402. package/src/tokens/TokensServiceFactory.ts +24 -0
  403. package/src/tokens/TokensServicePolygon.ts +17 -0
  404. package/src/tokens/TokensServiceXDai.ts +26 -0
  405. package/src/tokens/defi/ISwapService.ts +12 -0
  406. package/src/tokens/defi/paraswap/Paraswap.ts +244 -0
  407. package/src/tokens/erc20/eth/WETH.ts +13 -0
  408. package/src/tokens/utils/TokenUtils.ts +63 -0
  409. package/src/txs/ITxConfig.ts +27 -0
  410. package/src/txs/TxDataBuilder.ts +207 -0
  411. package/src/txs/TxLogger.ts +121 -0
  412. package/src/txs/TxProvider.ts +68 -0
  413. package/src/txs/TxService.ts +19 -0
  414. package/src/txs/TxWriter.ts +370 -0
  415. package/src/txs/conditional/GasWatcherLogger.ts +57 -0
  416. package/src/txs/conditional/GasWatcherService.ts +117 -0
  417. package/src/txs/conditional/GasWatcherStore.ts +40 -0
  418. package/src/txs/conditional/GasWatcherTx.ts +143 -0
  419. package/src/txs/receipt/ITxLogItem.ts +25 -0
  420. package/src/txs/receipt/TxLogParser.ts +29 -0
  421. package/src/txs/receipt/TxLogsTransfer.ts +61 -0
  422. package/src/txs/receipt/TxTopicInMemoryProvider.ts +45 -0
  423. package/src/txs/receipt/TxTopicProvider.ts +29 -0
  424. package/src/utils/$abiParser.ts +179 -0
  425. package/src/utils/$abiType.ts +85 -0
  426. package/src/utils/$abiUtils.ts +38 -0
  427. package/src/utils/$address.ts +37 -0
  428. package/src/utils/$array.ts +57 -0
  429. package/src/utils/$bigint.ts +127 -0
  430. package/src/utils/$block.ts +7 -0
  431. package/src/utils/$class.ts +8 -0
  432. package/src/utils/$config.ts +17 -0
  433. package/src/utils/$contract.ts +67 -0
  434. package/src/utils/$csv.ts +54 -0
  435. package/src/utils/$date.ts +473 -0
  436. package/src/utils/$fn.ts +134 -0
  437. package/src/utils/$is.ts +37 -0
  438. package/src/utils/$logger.ts +10 -0
  439. package/src/utils/$number.ts +89 -0
  440. package/src/utils/$object.ts +95 -0
  441. package/src/utils/$path.ts +32 -0
  442. package/src/utils/$promise.ts +7 -0
  443. package/src/utils/$require.ts +118 -0
  444. package/src/utils/$sign.ts +36 -0
  445. package/src/utils/$signSerializer.ts +339 -0
  446. package/src/utils/$wallet.ts +10 -0
  447. package/src/utils/types.ts +29 -0
  448. package/src/wallets/Wallet.ts +33 -0
  449. package/src/wallets/WalletBsc.ts +13 -0
  450. package/src/wallets/WalletService.ts +43 -0
  451. package/src/www/utils/BlockChainExplorerFormatter.ts +13 -0
  452. package/test/ChainAccount.spec.ts +9 -0
  453. package/test/client.spec.ts +59 -0
  454. package/test/fixtures/DaiTokenContract.ts +13 -0
  455. package/test/fixtures/receipts/swap.json +94 -0
  456. package/test/generate/class.spec.ts +27 -0
  457. package/test/hardhat/TestNode.ts +61 -0
  458. package/test/ns.spec.ts +30 -0
  459. package/test/receipt.spec.ts +27 -0
  460. package/test/utils/abi-parser.spec.ts +117 -0
  461. package/test/utils/bigint.spec.ts +40 -0
  462. package/test/utils/date.spec.ts +8 -0
  463. package/test/utils/fn.spec.ts +39 -0
  464. package/test/utils/number.spec.ts +41 -0
  465. package/test/utils/sign.spec.ts +22 -0
  466. package/tsconfig-build.json +24 -0
  467. package/tsconfig-src.json +36 -0
  468. package/tsconfig.json +27 -0
  469. package/typings/globals/assertion/index.d.ts +159 -0
  470. package/typings/globals/assertion/typings.json +10 -0
  471. package/typings/globals/atma-utest/index.d.ts +53 -0
  472. package/typings/globals/atma-utest/typings.json +10 -0
  473. package/typings/globals/axios/index.d.ts +6 -0
  474. package/typings/globals/mask/index.d.ts +6 -0
  475. package/typings/globals/mask/typings.json +9 -0
  476. package/typings/index.d.ts +6 -0
  477. package/typings.json +6 -0
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GasWatcherLogger = void 0;
4
+ const _bigint_1 = require("@dequanto/utils/$bigint");
5
+ const _date_1 = require("@dequanto/utils/$date");
6
+ const _logger_1 = require("@dequanto/utils/$logger");
7
+ const everlog_1 = require("everlog");
8
+ class GasWatcherLogger {
9
+ constructor() {
10
+ this.channels = {
11
+ prices: everlog_1.Everlog.createChannel('gaswatcher-prices', {
12
+ columns: [
13
+ {
14
+ type: 'date',
15
+ name: 'Date'
16
+ },
17
+ {
18
+ type: 'number',
19
+ name: 'Price(Gwei)'
20
+ },
21
+ ]
22
+ }),
23
+ txs: everlog_1.Everlog.createChannel('gaswatcher-txs', {
24
+ columns: [
25
+ {
26
+ type: 'date',
27
+ name: 'Date'
28
+ },
29
+ {
30
+ type: 'string',
31
+ name: 'ID'
32
+ },
33
+ {
34
+ type: 'string',
35
+ name: 'Message'
36
+ }
37
+ ]
38
+ }),
39
+ };
40
+ }
41
+ logPrice(gasPrice, block) {
42
+ let date = new Date();
43
+ let gwei = _bigint_1.$bigint.toGweiFromWei(gasPrice);
44
+ _logger_1.$logger.log(`Gas ${block || ''} ${_date_1.$date.format(date, 'HH:mm')} ${gwei} GWEI`);
45
+ this.channels.prices.writeRow([
46
+ date,
47
+ gwei,
48
+ ]);
49
+ }
50
+ logTx(id, message) {
51
+ let date = new Date();
52
+ let str = `Tx ${_date_1.$date.format(date, 'HH:mm')} ${message}`;
53
+ _logger_1.$logger.log(str);
54
+ this.channels.txs.writeRow([
55
+ date,
56
+ id,
57
+ str
58
+ ]);
59
+ }
60
+ }
61
+ exports.GasWatcherLogger = GasWatcherLogger;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GasWatcherService = void 0;
7
+ const _bigint_1 = require("@dequanto/utils/$bigint");
8
+ const alot_1 = __importDefault(require("alot"));
9
+ const GasWatcherLogger_1 = require("./GasWatcherLogger");
10
+ const GasWatcherStore_1 = require("./GasWatcherStore");
11
+ const GasWatcherTx_1 = require("./GasWatcherTx");
12
+ class GasWatcherService {
13
+ constructor(client, store) {
14
+ this.client = client;
15
+ this.store = store;
16
+ this.pending = [];
17
+ this.logger = new GasWatcherLogger_1.GasWatcherLogger();
18
+ }
19
+ static async load(client, store = new GasWatcherStore_1.GasWatcherStore(client.platform)) {
20
+ let service = new GasWatcherService(client, store);
21
+ await service.loadTxs();
22
+ return service;
23
+ }
24
+ start() {
25
+ this.tick();
26
+ //setInterval(() => this.tick(), ms);
27
+ }
28
+ async tick() {
29
+ let start = Date.now();
30
+ let [block, priceInfo] = await Promise.all([
31
+ this.client.getBlockNumber(),
32
+ this.client.getGasPrice()
33
+ ]);
34
+ let price = priceInfo.price;
35
+ this.logger.logPrice(price, block);
36
+ await this.store.savePrice({ date: new Date(), price });
37
+ await (0, alot_1.default)(this.pending)
38
+ .forEachAsync(async (entry) => {
39
+ await entry.tick(price);
40
+ })
41
+ .toArrayAsync();
42
+ // let end = Date.now();
43
+ // console.log(`Gas tick completed in ${$date.formatTimespan(end - start)}`);
44
+ let ms = 30000;
45
+ if (this.pending.length > 0) {
46
+ let expectPrice = (0, alot_1.default)(this.pending).max(x => x.condition.price);
47
+ if (expectPrice < price && price - expectPrice < 10) {
48
+ ms = 15000;
49
+ }
50
+ }
51
+ // if (expectPrice < price) {
52
+ // ms *= Number(price) / Number(expectPrice) * .5;
53
+ // }
54
+ setTimeout(() => {
55
+ this.tick();
56
+ }, ms);
57
+ }
58
+ async add(writer, condition) {
59
+ let writerJson = writer.toJSON();
60
+ let exists = this.pending.some(pending => {
61
+ let currentData = writer.builder.data;
62
+ let pendingData = pending.txWriter.builder.data;
63
+ let currentTo = currentData.to;
64
+ let pendingTo = pendingData.to;
65
+ if (currentTo !== pendingTo) {
66
+ return false;
67
+ }
68
+ let currentFrom = writer.account.address;
69
+ let pendingFrom = pending.txWriter.account.address;
70
+ if (currentFrom !== pendingFrom) {
71
+ return false;
72
+ }
73
+ if (currentData.data !== pendingData.data) {
74
+ return false;
75
+ }
76
+ // similar
77
+ return true;
78
+ });
79
+ if (exists) {
80
+ return;
81
+ }
82
+ let gasWatcherWriter = await GasWatcherTx_1.GasWatcherTx.fromJSON(condition, writerJson, this.logger);
83
+ this.pending.push(gasWatcherWriter);
84
+ let id = gasWatcherWriter.txWriter.id;
85
+ let gwei = _bigint_1.$bigint.toGweiFromWei(gasWatcherWriter.condition.price);
86
+ this.logger.logTx(id, `Transaction was added to listed for ${gwei} gas gwei`);
87
+ // Ensure completed txs are removed
88
+ this.pending = this.pending.filter(x => x.txWriter.receipt == null);
89
+ await this.saveTxs();
90
+ }
91
+ async loadTxs() {
92
+ let jsons = await this.store.loadTxs();
93
+ let pending = await (0, alot_1.default)(jsons)
94
+ .mapAsync(x => GasWatcherTx_1.GasWatcherTx.fromJSON(x.condition, x.writer, this.logger))
95
+ .toArrayAsync();
96
+ this.pending = pending;
97
+ }
98
+ async saveTxs() {
99
+ let jsons = this.pending.map(x => x.toJSON());
100
+ await this.store.saveTxs(jsons);
101
+ }
102
+ }
103
+ exports.GasWatcherService = GasWatcherService;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GasWatcherStore = void 0;
4
+ const JsonObjectStore_1 = require("@dequanto/json/JsonObjectStore");
5
+ class GasWatcherStore {
6
+ constructor(name = '') {
7
+ this.name = name;
8
+ this.jsonStore = new JsonObjectStore_1.JsonObjectStore({
9
+ path: `./db/gaswatcher/txs${this.name}.json`,
10
+ format: true,
11
+ });
12
+ }
13
+ async savePrice(enty) {
14
+ }
15
+ async loadPrices(from, toDate) {
16
+ return [];
17
+ }
18
+ async saveTxs(txs) {
19
+ return this.jsonStore.save(txs);
20
+ }
21
+ async loadTxs() {
22
+ return this.jsonStore.get();
23
+ }
24
+ }
25
+ exports.GasWatcherStore = GasWatcherStore;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GasWatcherTx = void 0;
4
+ const _bigint_1 = require("@dequanto/utils/$bigint");
5
+ const _logger_1 = require("@dequanto/utils/$logger");
6
+ const TxWriter_1 = require("../TxWriter");
7
+ class GasWatcherTx {
8
+ constructor(condition, txWriter, logger) {
9
+ this.condition = condition;
10
+ this.txWriter = txWriter;
11
+ this.logger = logger;
12
+ txWriter.on('log', message => this.log(message));
13
+ }
14
+ static async fromJSON(conditionJson, writerJson, logger) {
15
+ let writer = await TxWriter_1.TxWriter.fromJSON(writerJson);
16
+ return new GasWatcherTx({
17
+ price: BigInt(conditionJson.price)
18
+ }, writer, logger);
19
+ }
20
+ toJSON() {
21
+ return {
22
+ condition: this.condition,
23
+ writer: this.txWriter.toJSON(),
24
+ };
25
+ }
26
+ async tick(gasPrice) {
27
+ if (gasPrice > this.condition.price) {
28
+ // condition not matched
29
+ return;
30
+ }
31
+ if (this.txWriter.receipt != null) {
32
+ this.log(`Tx was already mined: ${this.txWriter.receipt.transactionHash}`);
33
+ return;
34
+ }
35
+ let tx = this.txWriter.tx;
36
+ if (tx == null) {
37
+ this.send(gasPrice);
38
+ return;
39
+ }
40
+ let timeEllipsedS = (Date.now() - tx.timestamp) / 1000 | 0;
41
+ if (tx.hash == null) {
42
+ if (timeEllipsedS > 30) {
43
+ // tx was not accepted for 30s
44
+ this.log(`Tx was not accepted for 30s. Resend`);
45
+ this.send(gasPrice);
46
+ }
47
+ // otherwise let wait for a hash
48
+ return;
49
+ }
50
+ let hash = tx.hash;
51
+ let client = this.txWriter.client;
52
+ let txData = await client.getTransaction(hash);
53
+ if (this.txWriter.receipt) {
54
+ // was mined inbetween
55
+ return;
56
+ }
57
+ if (txData == null) {
58
+ if (timeEllipsedS > 45) {
59
+ this.log(`Tx not in a pending block: ${hash}. Resend`);
60
+ // tx not in a pending block
61
+ this.send(gasPrice);
62
+ }
63
+ // otherwise let wait to be included into the pending block
64
+ return;
65
+ }
66
+ if (timeEllipsedS > 60 * 5) {
67
+ this.log(`Tx 5mins not mined: ${hash}. Resend`);
68
+ // 5mins not mined;
69
+ this.send(gasPrice);
70
+ }
71
+ }
72
+ async send(gasPrice) {
73
+ let writer = this.txWriter;
74
+ let builder = writer.builder;
75
+ let data = builder.data;
76
+ if (data.nonce == null) {
77
+ throw new Error(`Nonce should be already set on initial tx creating`);
78
+ await builder.setNonce();
79
+ }
80
+ if (writer.tx && data.gasPrice) {
81
+ // re-submitting
82
+ let currentGas = BigInt(data.gasPrice.toString());
83
+ if (currentGas >= gasPrice) {
84
+ // we can't resubmit with less gas
85
+ gasPrice = currentGas + _bigint_1.$bigint.toWeiFromGwei(.1);
86
+ }
87
+ }
88
+ await builder.setGas({
89
+ price: gasPrice,
90
+ priceRatio: 1,
91
+ gasLimit: data.gasLimit,
92
+ });
93
+ writer.tx = null;
94
+ writer.on('transactionHash', hash => {
95
+ let pendingCount = 0;
96
+ let nullCount = 0;
97
+ let interval = setInterval(async () => {
98
+ let tx = await writer.client.getTransaction(hash);
99
+ _logger_1.$logger.log('Check', hash, 'Block', tx?.blockNumber);
100
+ if (tx == null) {
101
+ if (++nullCount > 8) {
102
+ clearInterval(interval);
103
+ }
104
+ return;
105
+ }
106
+ if (tx.blockNumber) {
107
+ // was mined;
108
+ _logger_1.$logger.log(`${hash} Mined`);
109
+ clearInterval(interval);
110
+ return;
111
+ }
112
+ if (++pendingCount > 15) {
113
+ clearInterval(interval);
114
+ return;
115
+ }
116
+ }, 5000);
117
+ });
118
+ writer.send({
119
+ timeout: false
120
+ });
121
+ }
122
+ log(message) {
123
+ this.logger.logTx(this.txWriter.id, message);
124
+ }
125
+ }
126
+ exports.GasWatcherTx = GasWatcherTx;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TxLogParser = void 0;
7
+ const alot_1 = __importDefault(require("alot"));
8
+ const _contract_1 = require("@dequanto/utils/$contract");
9
+ const TxTopicProvider_1 = require("./TxTopicProvider");
10
+ class TxLogParser {
11
+ constructor(topics = new TxTopicProvider_1.TxTopicProvider()) {
12
+ this.topics = topics;
13
+ }
14
+ async parse(receipt) {
15
+ let logs = await (0, alot_1.default)(receipt.logs).mapAsync(async (log) => {
16
+ let topic = await this.topics.get(log.topics[0]);
17
+ if (topic == null) {
18
+ return null;
19
+ }
20
+ let { abi, formatter } = topic;
21
+ let parsed = _contract_1.$contract.parseLogWithAbi(log, abi);
22
+ return parsed;
23
+ }).toArrayAsync();
24
+ return logs;
25
+ }
26
+ }
27
+ exports.TxLogParser = TxLogParser;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TxLogsTransfer = void 0;
7
+ const alot_1 = __importDefault(require("alot"));
8
+ const TokensServiceFactory_1 = require("@dequanto/tokens/TokensServiceFactory");
9
+ const TxLogParser_1 = require("./TxLogParser");
10
+ class TxLogsTransfer {
11
+ async extractFromWriter(writer) {
12
+ let receipt = await writer.onCompleted;
13
+ let knownLogs = writer.tx?.knownLogs ?? [];
14
+ return this.extractFromParsed(knownLogs, writer.client.platform);
15
+ }
16
+ async extractFromParsed(knownLogs, platform) {
17
+ let transfers = knownLogs.filter(x => x.name === 'Transfer');
18
+ let tokenService = TokensServiceFactory_1.TokensServiceFactory.get(platform);
19
+ return (0, alot_1.default)(transfers).mapAsync(async (transfer) => {
20
+ let erc20Address = transfer.contract;
21
+ let token = await tokenService.getTokenOrDefault(erc20Address);
22
+ let [from, to, amount] = transfer.arguments;
23
+ return {
24
+ token,
25
+ from: from.value,
26
+ to: to.value,
27
+ amount: amount.value
28
+ };
29
+ }).toArrayAsync();
30
+ }
31
+ async extractFromReceipt(receipt, platform) {
32
+ let parser = new TxLogParser_1.TxLogParser();
33
+ let logs = await parser.parse(receipt);
34
+ logs = logs.filter(x => x != null);
35
+ return this.extractFromParsed(logs, platform);
36
+ }
37
+ async extract(transfer, platform) {
38
+ let tokenService = TokensServiceFactory_1.TokensServiceFactory.get(platform);
39
+ let erc20Address = transfer.contract;
40
+ let token = await tokenService.getTokenOrDefault(erc20Address);
41
+ let [from, to, amount] = transfer.arguments;
42
+ return {
43
+ token,
44
+ from: from.value,
45
+ to: to.value,
46
+ amount: amount.value
47
+ };
48
+ }
49
+ }
50
+ exports.TxLogsTransfer = TxLogsTransfer;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TxTopicInMemoryProvider = void 0;
4
+ const _abiParser_1 = require("@dequanto/utils/$abiParser");
5
+ const _abiUtils_1 = require("@dequanto/utils/$abiUtils");
6
+ class TxTopicInMemoryProvider {
7
+ constructor() {
8
+ this.hash = Object.create(null);
9
+ }
10
+ register(mix) {
11
+ if (mix == null) {
12
+ return this;
13
+ }
14
+ if (Array.isArray(mix)) {
15
+ mix.forEach(x => this.register(x));
16
+ return this;
17
+ }
18
+ let abi;
19
+ let formatter;
20
+ if (typeof mix !== 'string' && 'abi' in mix && 'formatter' in mix) {
21
+ abi = mix.abi;
22
+ formatter = mix.formatter;
23
+ }
24
+ else {
25
+ abi = mix;
26
+ }
27
+ if (typeof abi === 'string') {
28
+ abi = _abiParser_1.$abiParser.parseMethod(abi);
29
+ }
30
+ let hash = _abiUtils_1.$abiUtils.getMethodHash(abi);
31
+ this.hash[hash] = {
32
+ abi,
33
+ formatter
34
+ };
35
+ return this;
36
+ }
37
+ async get(topicHash) {
38
+ return this.hash[topicHash];
39
+ }
40
+ }
41
+ exports.TxTopicInMemoryProvider = TxTopicInMemoryProvider;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TxTopicProvider = void 0;
4
+ //import { TxLogsTransfer } from './TxLogsTransfer';
5
+ const TxTopicInMemoryProvider_1 = require("./TxTopicInMemoryProvider");
6
+ class TxTopicProvider {
7
+ constructor() {
8
+ this.default = new TxTopicInMemoryProvider_1.TxTopicInMemoryProvider();
9
+ this.register([
10
+ 'event Transfer(address from, address to, uint256 amount)'
11
+ // {
12
+ // abi: 'event Transfer(address from, address to, uint256 amount)',
13
+ // formatter: di.resolve(TxLogsTransfer)
14
+ // }
15
+ ]);
16
+ }
17
+ async get(topicHash) {
18
+ return this.default.get(topicHash);
19
+ }
20
+ register(mix) {
21
+ this.default.register(mix);
22
+ return this;
23
+ }
24
+ }
25
+ exports.TxTopicProvider = TxTopicProvider;
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.$abiParser = void 0;
4
+ var $abiParser;
5
+ (function ($abiParser) {
6
+ function getReturnType(abi) {
7
+ let outputs = abi.outputs;
8
+ if (outputs == null || outputs.length == 0) {
9
+ return 'uint256';
10
+ }
11
+ if (outputs.length === 1 && !outputs[0].name) {
12
+ return outputs[0].type;
13
+ }
14
+ let hasKeys = outputs.every(x => Boolean(x.name));
15
+ if (hasKeys) {
16
+ return 'object';
17
+ }
18
+ return 'array';
19
+ }
20
+ $abiParser.getReturnType = getReturnType;
21
+ function getReturnTypeFromTypes(outputs) {
22
+ if (outputs == null || outputs.length == 0) {
23
+ return 'uint256';
24
+ }
25
+ if (outputs.length === 1 && !outputs[0].name) {
26
+ return outputs[0].type;
27
+ }
28
+ let hasKeys = outputs.every(x => Boolean(x.name));
29
+ if (hasKeys) {
30
+ return 'object';
31
+ }
32
+ return 'array';
33
+ }
34
+ $abiParser.getReturnTypeFromTypes = getReturnTypeFromTypes;
35
+ const methodRgx = /^((?<type>function|event)\s+)?(?<methodName>\w+)\s*\((?<params>[^)]+)?\)\s*((:|returns)(?<return>.+))?$/;
36
+ /**
37
+ * foo(uint256):address
38
+ * function foo(uint256): (address account, uint256 value)
39
+ * function foo(uint256) returns (address)
40
+ */
41
+ function parseMethod(methodAbi) {
42
+ let outputs;
43
+ let match = methodRgx.exec(methodAbi);
44
+ if (match == null) {
45
+ throw new Error(`Invalid method abi ${methodAbi}. Expect like 'foo(uint256):address'`);
46
+ }
47
+ let fnName = match.groups.methodName;
48
+ let $return = match.groups.return?.trim() ?? 'uint256';
49
+ outputs = parseArguments($return);
50
+ let inputs = Parse.parametersLine(match.groups.params ?? '');
51
+ return {
52
+ constant: false,
53
+ payable: false,
54
+ //"stateMutability": "view",
55
+ name: fnName,
56
+ inputs: inputs,
57
+ outputs: outputs,
58
+ type: match.groups.type ?? 'function',
59
+ };
60
+ }
61
+ $abiParser.parseMethod = parseMethod;
62
+ // uint256
63
+ // address[]
64
+ // (uint256, uint256)
65
+ // (uint256 foo, uint256 bar)
66
+ // (uint256 foo, uint256 bar)[]
67
+ function parseArguments(line) {
68
+ line = line?.trim();
69
+ if (!line || line === '()') {
70
+ return [];
71
+ }
72
+ let c = line[0];
73
+ if (c === '{') {
74
+ throw new Error(`${line} is not supported, use (...) or [...] declarations`);
75
+ }
76
+ if (c === '[' || c === '(') {
77
+ let end = Parse.goToClosing(line, 0, c);
78
+ let parametersLine = line.substring(1, end);
79
+ let isArray = line.endsWith('[]');
80
+ let params = Parse.parametersLine(parametersLine);
81
+ let isTuple = params.every(x => Boolean(x.name));
82
+ if (isTuple && isArray) {
83
+ return [
84
+ {
85
+ name: '',
86
+ type: `tuple[]`,
87
+ components: params
88
+ }
89
+ ];
90
+ }
91
+ if (params.length === 1) {
92
+ line = params[0].type;
93
+ params = [
94
+ {
95
+ name: "",
96
+ type: line,
97
+ },
98
+ ];
99
+ }
100
+ return params;
101
+ }
102
+ // if (c === '{') {
103
+ // let params = line.substring(1, line.length - 1);
104
+ // outputs = params.split(',').map(x => x.trim()).map(param => {
105
+ // let [_type, _name] = param.split(/[\s+:]/).map(x => x.trim()).filter(Boolean);
106
+ // return {
107
+ // name: _name ?? '',
108
+ // type: _type.trim()
109
+ // };
110
+ // });
111
+ // }
112
+ return [
113
+ {
114
+ name: '',
115
+ type: line,
116
+ },
117
+ ];
118
+ }
119
+ $abiParser.parseArguments = parseArguments;
120
+ })($abiParser = exports.$abiParser || (exports.$abiParser = {}));
121
+ var Parse;
122
+ (function (Parse) {
123
+ // uint256 foo, uint bar, address qux
124
+ function parametersLine(paramsStr) {
125
+ return paramsStr
126
+ .split(',')
127
+ .map(x => x.trim())
128
+ .filter(Boolean)
129
+ .map(param => {
130
+ let [_type, _name] = param.split(/\s+/).map(x => x.trim()).filter(Boolean);
131
+ return {
132
+ name: _name ?? '',
133
+ type: _type.trim()
134
+ };
135
+ });
136
+ }
137
+ Parse.parametersLine = parametersLine;
138
+ function goToClosing(str, startI, openChar, closeChar) {
139
+ closeChar = closeChar ?? CLOSE_CHARS[openChar];
140
+ let count = 0;
141
+ for (let i = startI; i < str.length; i++) {
142
+ if (str[i] === openChar) {
143
+ count++;
144
+ }
145
+ if (str[i] === closeChar) {
146
+ count--;
147
+ }
148
+ if (count === 0) {
149
+ return i;
150
+ }
151
+ }
152
+ throw new Error(`Unmatched closing chars ${openChar} ${closeChar} in ${str}`);
153
+ }
154
+ Parse.goToClosing = goToClosing;
155
+ const CLOSE_CHARS = {
156
+ '[': ']',
157
+ '(': ')'
158
+ };
159
+ })(Parse || (Parse = {}));