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,236 @@
|
|
|
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.TokensService = void 0;
|
|
13
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
14
|
+
const alot_1 = __importDefault(require("alot"));
|
|
15
|
+
const memd_1 = __importDefault(require("memd"));
|
|
16
|
+
const TPSushiswap_1 = require("./TokenProviders/TPSushiswap");
|
|
17
|
+
const TPCoinmarketcap_1 = require("./TokenProviders/TPCoinmarketcap");
|
|
18
|
+
const TPOneInch_1 = require("./TokenProviders/TPOneInch");
|
|
19
|
+
const TPChain_1 = require("./TokenProviders/TPChain");
|
|
20
|
+
const ERC20_1 = require("@dequanto/contracts/common/ERC20");
|
|
21
|
+
const Web3ClientFactory_1 = require("@dequanto/clients/Web3ClientFactory");
|
|
22
|
+
const BlockChainExplorerProvider_1 = require("@dequanto/BlockchainExplorer/BlockChainExplorerProvider");
|
|
23
|
+
const _address_1 = require("@dequanto/utils/$address");
|
|
24
|
+
const ArbTokenProvider_1 = require("@dequanto/chains/arbitrum/ArbTokenProvider");
|
|
25
|
+
const _require_1 = require("@dequanto/utils/$require");
|
|
26
|
+
class TokensService {
|
|
27
|
+
constructor(platform, explorer) {
|
|
28
|
+
this.platform = platform;
|
|
29
|
+
this.explorer = explorer;
|
|
30
|
+
this.providers = [
|
|
31
|
+
new TPOneInch_1.TPOneInch(),
|
|
32
|
+
new TPSushiswap_1.TPSushiswap(),
|
|
33
|
+
// @TODO uniswap thegraph api doesn't work any more
|
|
34
|
+
// new TPUniswap(),
|
|
35
|
+
new TPCoinmarketcap_1.TPCoinmarketcap(),
|
|
36
|
+
new ArbTokenProvider_1.ArbTokenProvider(),
|
|
37
|
+
new TPChain_1.TPChain(this.platform, this.explorer),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
async getTokenOrDefault(address, chainLookup = true) {
|
|
41
|
+
return await this.getToken(address, chainLookup) ?? this.default(address);
|
|
42
|
+
}
|
|
43
|
+
async getToken(mix, chainLookup = true) {
|
|
44
|
+
let [token, provider] = mix.startsWith('0x')
|
|
45
|
+
? await this.getTokenByAddress(mix, chainLookup)
|
|
46
|
+
: await this.getTokenBySymbol(mix, chainLookup);
|
|
47
|
+
return token;
|
|
48
|
+
}
|
|
49
|
+
async getKnownToken(mix) {
|
|
50
|
+
let [token, provider] = mix.startsWith('0x')
|
|
51
|
+
? await this.getTokenByAddress(mix, false)
|
|
52
|
+
: await this.getTokenBySymbol(mix, false);
|
|
53
|
+
if (token == null) {
|
|
54
|
+
throw new Error(`Token ${mix} not found`);
|
|
55
|
+
}
|
|
56
|
+
return token;
|
|
57
|
+
}
|
|
58
|
+
isNative(mix) {
|
|
59
|
+
_require_1.$require.notNull(mix, `Token is undefined`);
|
|
60
|
+
if (typeof mix === 'object') {
|
|
61
|
+
return this.isNative(mix.symbol ?? mix.address);
|
|
62
|
+
}
|
|
63
|
+
if (mix.startsWith('0x')) {
|
|
64
|
+
return NativeTokens.isNativeByAddress(mix);
|
|
65
|
+
}
|
|
66
|
+
return NativeTokens.isNativeBySymbol(this.platform, mix);
|
|
67
|
+
}
|
|
68
|
+
getNative(platform) {
|
|
69
|
+
return NativeTokens.getNative(platform);
|
|
70
|
+
}
|
|
71
|
+
/** Download tokens with various exchange/swap providers and merge them into one collection. */
|
|
72
|
+
async redownload() {
|
|
73
|
+
return await (0, alot_1.default)(this.providers)
|
|
74
|
+
.forEachAsync(async (x, i) => {
|
|
75
|
+
console.log(`Get from #${i} Provider`);
|
|
76
|
+
await x.redownloadTokens();
|
|
77
|
+
console.log(`Get from #${i} Provider DONE`);
|
|
78
|
+
})
|
|
79
|
+
.toArrayAsync();
|
|
80
|
+
}
|
|
81
|
+
async getTokenByAddress(address, chainLookup = true) {
|
|
82
|
+
let [token, provider] = await (0, alot_1.default)(this.providers)
|
|
83
|
+
.mapAsync(async (provider) => {
|
|
84
|
+
if (provider instanceof TPChain_1.TPChain && chainLookup === false) {
|
|
85
|
+
return [null, null];
|
|
86
|
+
;
|
|
87
|
+
}
|
|
88
|
+
return [await provider.getByAddress(this.platform, address), provider];
|
|
89
|
+
})
|
|
90
|
+
.firstAsync(([token]) => token != null) ?? [];
|
|
91
|
+
if (!token?.symbol && NativeTokens.isNativeByAddress(address)) {
|
|
92
|
+
token = NativeTokens.getNative(this.platform);
|
|
93
|
+
}
|
|
94
|
+
return [token, provider];
|
|
95
|
+
}
|
|
96
|
+
async getTokenBySymbol(symbol, chainLookup = true) {
|
|
97
|
+
let [token, provider] = await (0, alot_1.default)(this.providers)
|
|
98
|
+
.mapAsync(async (provider) => {
|
|
99
|
+
if (provider instanceof TPChain_1.TPChain && chainLookup === false) {
|
|
100
|
+
return [null, null];
|
|
101
|
+
}
|
|
102
|
+
return [await provider.getBySymbol(this.platform, symbol), provider];
|
|
103
|
+
})
|
|
104
|
+
.firstAsync(([token]) => token != null) ?? [];
|
|
105
|
+
if (!token?.symbol && NativeTokens.isNativeBySymbol(this.platform, symbol)) {
|
|
106
|
+
token = NativeTokens.getNative(this.platform);
|
|
107
|
+
}
|
|
108
|
+
return [token, provider];
|
|
109
|
+
}
|
|
110
|
+
default(address) {
|
|
111
|
+
return {
|
|
112
|
+
platform: this.platform,
|
|
113
|
+
symbol: address,
|
|
114
|
+
name: address,
|
|
115
|
+
address: address,
|
|
116
|
+
decimals: 18,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
static async erc20(token, platform) {
|
|
120
|
+
let client = Web3ClientFactory_1.Web3ClientFactory.get(platform);
|
|
121
|
+
let explorer = BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(platform);
|
|
122
|
+
if (typeof token === 'string') {
|
|
123
|
+
let service = a_di_1.default.resolve(TokensService, platform, explorer);
|
|
124
|
+
token = await service.getToken(token);
|
|
125
|
+
}
|
|
126
|
+
if (token == null) {
|
|
127
|
+
throw new Error(`Token not found: ${arguments[0]}`);
|
|
128
|
+
}
|
|
129
|
+
return new ERC20_1.ERC20(token.address, client, explorer);
|
|
130
|
+
}
|
|
131
|
+
async erc20(token) {
|
|
132
|
+
let client = Web3ClientFactory_1.Web3ClientFactory.get(this.platform);
|
|
133
|
+
let explorer = BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.platform);
|
|
134
|
+
let t = typeof token === 'string'
|
|
135
|
+
? await this.getToken(token)
|
|
136
|
+
: token;
|
|
137
|
+
if (t == null) {
|
|
138
|
+
if (typeof token === 'string' && _address_1.$address.isValid(token)) {
|
|
139
|
+
t = {
|
|
140
|
+
address: token,
|
|
141
|
+
decimals: 18,
|
|
142
|
+
platform: this.platform
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
throw new Error(`Token not found: ${arguments[0]}`);
|
|
146
|
+
}
|
|
147
|
+
return new ERC20_1.ERC20(t.address, client, explorer);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
__decorate([
|
|
151
|
+
memd_1.default.deco.memoize({ perInstance: true })
|
|
152
|
+
], TokensService.prototype, "getToken", null);
|
|
153
|
+
__decorate([
|
|
154
|
+
memd_1.default.deco.memoize({ perInstance: true })
|
|
155
|
+
], TokensService.prototype, "getKnownToken", null);
|
|
156
|
+
__decorate([
|
|
157
|
+
memd_1.default.deco.memoize()
|
|
158
|
+
], TokensService.prototype, "erc20", null);
|
|
159
|
+
__decorate([
|
|
160
|
+
memd_1.default.deco.memoize()
|
|
161
|
+
], TokensService, "erc20", null);
|
|
162
|
+
exports.TokensService = TokensService;
|
|
163
|
+
var NativeTokens;
|
|
164
|
+
(function (NativeTokens) {
|
|
165
|
+
const T1 = `0x0000000000000000000000000000000000000000`;
|
|
166
|
+
const T2 = `0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee`;
|
|
167
|
+
const tokens = {
|
|
168
|
+
'ETH': {
|
|
169
|
+
name: 'Ethereum Native Token',
|
|
170
|
+
symbol: 'ETH',
|
|
171
|
+
decimals: 18,
|
|
172
|
+
icon: null,
|
|
173
|
+
platform: 'eth',
|
|
174
|
+
address: T2,
|
|
175
|
+
},
|
|
176
|
+
'BNB': {
|
|
177
|
+
name: 'BSC Native Token',
|
|
178
|
+
symbol: 'BNB',
|
|
179
|
+
decimals: 18,
|
|
180
|
+
icon: null,
|
|
181
|
+
platform: 'bsc',
|
|
182
|
+
address: T1,
|
|
183
|
+
},
|
|
184
|
+
'MATIC': {
|
|
185
|
+
name: 'Polygon Native Token',
|
|
186
|
+
symbol: 'MATIC',
|
|
187
|
+
decimals: 18,
|
|
188
|
+
icon: null,
|
|
189
|
+
platform: 'polygon',
|
|
190
|
+
address: T2,
|
|
191
|
+
},
|
|
192
|
+
'XDAI': {
|
|
193
|
+
name: 'xDai Native Token',
|
|
194
|
+
symbol: 'XDAI',
|
|
195
|
+
decimals: 18,
|
|
196
|
+
icon: null,
|
|
197
|
+
platform: 'xdai',
|
|
198
|
+
address: T1,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
const PLATFORMS = {
|
|
202
|
+
'eth': 'ETH',
|
|
203
|
+
'bsc': 'BNB',
|
|
204
|
+
'polygon': 'MATIC',
|
|
205
|
+
'xdai': 'xDAI',
|
|
206
|
+
};
|
|
207
|
+
function isNativeBySymbol(platform, symbol) {
|
|
208
|
+
if (symbol == null) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
symbol = symbol.toUpperCase();
|
|
212
|
+
return symbol in tokens;
|
|
213
|
+
}
|
|
214
|
+
NativeTokens.isNativeBySymbol = isNativeBySymbol;
|
|
215
|
+
function isNativeByAddress(address) {
|
|
216
|
+
const check = address.toLowerCase();
|
|
217
|
+
return _address_1.$address.eq(T1, check) || _address_1.$address.eq(T2, check);
|
|
218
|
+
}
|
|
219
|
+
NativeTokens.isNativeByAddress = isNativeByAddress;
|
|
220
|
+
function toNativeByAddress(platform, address) {
|
|
221
|
+
const token = tokens[platform?.toUpperCase()];
|
|
222
|
+
return {
|
|
223
|
+
...token,
|
|
224
|
+
address: address
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
NativeTokens.toNativeByAddress = toNativeByAddress;
|
|
228
|
+
function getNative(platform) {
|
|
229
|
+
let symbol = PLATFORMS[platform];
|
|
230
|
+
if (symbol == null) {
|
|
231
|
+
throw new Error(`${platform} platform is not support`);
|
|
232
|
+
}
|
|
233
|
+
return tokens[symbol.toUpperCase()];
|
|
234
|
+
}
|
|
235
|
+
NativeTokens.getNative = getNative;
|
|
236
|
+
})(NativeTokens || (NativeTokens = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
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.TokensServiceBsc = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const TokensService_1 = require("./TokensService");
|
|
9
|
+
const Bscscan_1 = require("@dequanto/BlockchainExplorer/Bscscan");
|
|
10
|
+
class TokensServiceBsc extends TokensService_1.TokensService {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('bsc', a_di_1.default.resolve(Bscscan_1.Bscscan));
|
|
13
|
+
}
|
|
14
|
+
static async erc20(mix) {
|
|
15
|
+
return TokensService_1.TokensService.erc20(mix, 'bsc');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.TokensServiceBsc = TokensServiceBsc;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.TokensServiceEth = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const TokensService_1 = require("./TokensService");
|
|
9
|
+
const Etherscan_1 = require("@dequanto/BlockchainExplorer/Etherscan");
|
|
10
|
+
class TokensServiceEth extends TokensService_1.TokensService {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('eth', a_di_1.default.resolve(Etherscan_1.Etherscan));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.TokensServiceEth = TokensServiceEth;
|
|
@@ -0,0 +1,29 @@
|
|
|
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.TokensServiceFactory = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const TokensServiceBsc_1 = require("./TokensServiceBsc");
|
|
9
|
+
const TokensServiceEth_1 = require("./TokensServiceEth");
|
|
10
|
+
const TokensServicePolygon_1 = require("./TokensServicePolygon");
|
|
11
|
+
const TokensServiceXDai_1 = require("./TokensServiceXDai");
|
|
12
|
+
var TokensServiceFactory;
|
|
13
|
+
(function (TokensServiceFactory) {
|
|
14
|
+
function get(platform) {
|
|
15
|
+
switch (platform) {
|
|
16
|
+
case 'bsc':
|
|
17
|
+
return a_di_1.default.resolve(TokensServiceBsc_1.TokensServiceBsc);
|
|
18
|
+
case 'eth':
|
|
19
|
+
return a_di_1.default.resolve(TokensServiceEth_1.TokensServiceEth);
|
|
20
|
+
case 'polygon':
|
|
21
|
+
return a_di_1.default.resolve(TokensServicePolygon_1.TokensServicePolygon);
|
|
22
|
+
case 'xdai':
|
|
23
|
+
return a_di_1.default.resolve(TokensServiceXDai_1.TokensServiceXDai);
|
|
24
|
+
default:
|
|
25
|
+
throw new Error(`Unsupported platform ${platform} for TokensService`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
TokensServiceFactory.get = get;
|
|
29
|
+
})(TokensServiceFactory = exports.TokensServiceFactory || (exports.TokensServiceFactory = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
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.TokensServicePolygon = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const TokensService_1 = require("./TokensService");
|
|
9
|
+
const Polyscan_1 = require("@dequanto/BlockchainExplorer/Polyscan");
|
|
10
|
+
class TokensServicePolygon extends TokensService_1.TokensService {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('polygon', a_di_1.default.resolve(Polyscan_1.Polyscan));
|
|
13
|
+
}
|
|
14
|
+
static async erc20(mix) {
|
|
15
|
+
return TokensService_1.TokensService.erc20(mix, 'polygon');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.TokensServicePolygon = TokensServicePolygon;
|
|
@@ -0,0 +1,24 @@
|
|
|
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.TokensServiceXDai = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const TokensService_1 = require("./TokensService");
|
|
9
|
+
const XDaiscan_1 = require("@dequanto/chains/xdai/XDaiscan");
|
|
10
|
+
class TokensServiceXDai extends TokensService_1.TokensService {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('xdai', a_di_1.default.resolve(XDaiscan_1.XDaiscan));
|
|
13
|
+
}
|
|
14
|
+
static async erc20(mix) {
|
|
15
|
+
return TokensService_1.TokensService.erc20(mix, 'xdai');
|
|
16
|
+
}
|
|
17
|
+
async getTokenBySymbol(symbol, chainLookup = true) {
|
|
18
|
+
if (symbol === 'DAI') {
|
|
19
|
+
symbol = 'wxDAI';
|
|
20
|
+
}
|
|
21
|
+
return super.getTokenBySymbol(symbol, chainLookup);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TokensServiceXDai = TokensServiceXDai;
|
|
@@ -0,0 +1,135 @@
|
|
|
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.Paraswap = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const TokensServiceFactory_1 = require("@dequanto/tokens/TokensServiceFactory");
|
|
9
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
10
|
+
const paraswap_1 = require("paraswap");
|
|
11
|
+
const paraswap_core_1 = require("paraswap-core");
|
|
12
|
+
const TxWriter_1 = require("@dequanto/txs/TxWriter");
|
|
13
|
+
const TxDataBuilder_1 = require("@dequanto/txs/TxDataBuilder");
|
|
14
|
+
const PolyWeb3Client_1 = require("@dequanto/clients/PolyWeb3Client");
|
|
15
|
+
const TokensService_1 = require("@dequanto/tokens/TokensService");
|
|
16
|
+
class Paraswap {
|
|
17
|
+
constructor(platform, client = a_di_1.default.resolve(PolyWeb3Client_1.PolyWeb3Client)) {
|
|
18
|
+
this.platform = platform;
|
|
19
|
+
this.client = client;
|
|
20
|
+
this.tokensProvider = TokensServiceFactory_1.TokensServiceFactory.get(this.platform);
|
|
21
|
+
}
|
|
22
|
+
async balanceOf(address, token) {
|
|
23
|
+
let erc20 = await TokensService_1.TokensService.erc20(token, this.client.platform);
|
|
24
|
+
let balance = await erc20.balanceOf(address);
|
|
25
|
+
return balance;
|
|
26
|
+
}
|
|
27
|
+
async swap(account, params) {
|
|
28
|
+
const [fromToken, toToken] = await this.getTokens(params.from, params.to);
|
|
29
|
+
let approveTx = await this.ensureApproved(account, fromToken, params.fromAmount);
|
|
30
|
+
if (approveTx) {
|
|
31
|
+
await approveTx.onCompleted;
|
|
32
|
+
}
|
|
33
|
+
let txData = await this.getSwapTransaction({
|
|
34
|
+
from: fromToken,
|
|
35
|
+
to: toToken,
|
|
36
|
+
userAddress: account.address,
|
|
37
|
+
fromAmount: params.fromAmount,
|
|
38
|
+
});
|
|
39
|
+
let tx = await this.sendTx(account, txData);
|
|
40
|
+
return tx;
|
|
41
|
+
}
|
|
42
|
+
async ensureApproved(account, token, amount) {
|
|
43
|
+
token = await this.getToken(token);
|
|
44
|
+
const SPENDER = `0x216b4b4ba9f3e719726886d34a177484278bfcae`;
|
|
45
|
+
const erc20 = await TokensService_1.TokensService.erc20(token.address, this.client.platform);
|
|
46
|
+
let approved = await erc20
|
|
47
|
+
.allowance(account.address, SPENDER);
|
|
48
|
+
let toApprove = typeof amount === 'bigint'
|
|
49
|
+
? amount
|
|
50
|
+
: _bigint_1.$bigint.toWei(amount, token.decimals);
|
|
51
|
+
if ((toApprove * 2n) > approved) {
|
|
52
|
+
return await erc20.approve(account, SPENDER, toApprove * 2n);
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
async getSwapTransaction(params) {
|
|
57
|
+
let [from, to] = await this.getTokens(params.from, params.to);
|
|
58
|
+
const srcAmount = typeof params.fromAmount === 'bigint'
|
|
59
|
+
? String(params.fromAmount)
|
|
60
|
+
: String(BigInt(params.fromAmount) * 10n ** BigInt(from.decimals));
|
|
61
|
+
const swapper = a_di_1.default.resolve(Swapper, this.platform);
|
|
62
|
+
const priceRoute = await swapper.getRate({
|
|
63
|
+
from: from,
|
|
64
|
+
to: to,
|
|
65
|
+
userAddress: params.userAddress,
|
|
66
|
+
fromAmount: srcAmount,
|
|
67
|
+
});
|
|
68
|
+
const slippage = params.slippage ?? 1;
|
|
69
|
+
const minAmount = _bigint_1.$bigint
|
|
70
|
+
.multWithFloat(BigInt(priceRoute.destAmount), 1 - slippage / 100)
|
|
71
|
+
.toString();
|
|
72
|
+
const transactionRequest = await swapper.buildSwap({
|
|
73
|
+
from: from,
|
|
74
|
+
to: to,
|
|
75
|
+
fromAmount: srcAmount,
|
|
76
|
+
toMinAmount: minAmount,
|
|
77
|
+
priceRoute: priceRoute,
|
|
78
|
+
userAddress: params.userAddress,
|
|
79
|
+
receiver: params.receiver,
|
|
80
|
+
partner: params.partner
|
|
81
|
+
});
|
|
82
|
+
return transactionRequest;
|
|
83
|
+
}
|
|
84
|
+
async sendTx(account, calldata) {
|
|
85
|
+
let txData = TxDataBuilder_1.TxDataBuilder.normalize(calldata);
|
|
86
|
+
let $txData = txData;
|
|
87
|
+
let gas = $txData.gas;
|
|
88
|
+
delete $txData.gas;
|
|
89
|
+
$txData.gasLimit = BigInt(gas) * 2n;
|
|
90
|
+
let txBuilder = new TxDataBuilder_1.TxDataBuilder(this.client, account, txData);
|
|
91
|
+
await txBuilder.setNonce();
|
|
92
|
+
return TxWriter_1.TxWriter.write(this.client, txBuilder, account);
|
|
93
|
+
}
|
|
94
|
+
async getTokens(from, to) {
|
|
95
|
+
return await Promise.all([
|
|
96
|
+
this.getToken(from),
|
|
97
|
+
this.getToken(to)
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
async getToken(mix) {
|
|
101
|
+
let token = typeof mix === 'string'
|
|
102
|
+
? await this.tokensProvider.getKnownToken(mix)
|
|
103
|
+
: mix;
|
|
104
|
+
if (token == null || token.address == null) {
|
|
105
|
+
throw new Error(`Address undefined: ${token}`);
|
|
106
|
+
}
|
|
107
|
+
return token;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.Paraswap = Paraswap;
|
|
111
|
+
const NETWORK_IDS = {
|
|
112
|
+
'polygon': 137,
|
|
113
|
+
};
|
|
114
|
+
class Swapper {
|
|
115
|
+
constructor(platform) {
|
|
116
|
+
this.platform = platform;
|
|
117
|
+
this.paraswap = new paraswap_1.ParaSwap(NETWORK_IDS[this.platform]);
|
|
118
|
+
}
|
|
119
|
+
async getRate(params) {
|
|
120
|
+
const priceRouteOrError = await this.paraswap.getRate(params.from.address, params.to.address, params.fromAmount, params.userAddress, paraswap_core_1.SwapSide.SELL, { partner: params.partner }, params.from.decimals, params.to.decimals);
|
|
121
|
+
if ('message' in priceRouteOrError) {
|
|
122
|
+
throw new Error(priceRouteOrError.message);
|
|
123
|
+
}
|
|
124
|
+
return priceRouteOrError;
|
|
125
|
+
}
|
|
126
|
+
;
|
|
127
|
+
async buildSwap(params) {
|
|
128
|
+
const transactionRequestOrError = await this.paraswap.buildTx(params.from.address, params.to.address, params.fromAmount, params.toMinAmount, params.priceRoute, params.userAddress, params.partner, undefined, undefined, params.receiver);
|
|
129
|
+
if ('message' in transactionRequestOrError) {
|
|
130
|
+
throw new Error(transactionRequestOrError.message);
|
|
131
|
+
}
|
|
132
|
+
return transactionRequestOrError;
|
|
133
|
+
}
|
|
134
|
+
;
|
|
135
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* dequanto
|
|
4
|
+
* name: WETHBase
|
|
5
|
+
* platform: eth
|
|
6
|
+
* source.abi: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
7
|
+
* output: ./contracts/gen/eth/
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.WETH = void 0;
|
|
11
|
+
const WETHBase_1 = require("@dequanto-contracts/gen/eth/WETHBase");
|
|
12
|
+
class WETH extends WETHBase_1.WETHBase {
|
|
13
|
+
}
|
|
14
|
+
exports.WETH = WETH;
|
|
@@ -0,0 +1,66 @@
|
|
|
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.TokenUtils = void 0;
|
|
7
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
8
|
+
const _number_1 = require("@dequanto/utils/$number");
|
|
9
|
+
const alot_1 = __importDefault(require("alot"));
|
|
10
|
+
var TokenUtils;
|
|
11
|
+
(function (TokenUtils) {
|
|
12
|
+
function isStable(symbol) {
|
|
13
|
+
return /^[tb]?usd[tc]?$/i.test(symbol) || /^(dai)$/i.test(symbol);
|
|
14
|
+
}
|
|
15
|
+
TokenUtils.isStable = isStable;
|
|
16
|
+
function calcUsdIfStable(amount, token) {
|
|
17
|
+
if (isStable(token.symbol) === false) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
let tokenBase = 10n ** BigInt(token.decimals);
|
|
21
|
+
return _bigint_1.$bigint.divToFloat(amount, tokenBase, 10n ** 8n);
|
|
22
|
+
}
|
|
23
|
+
TokenUtils.calcUsdIfStable = calcUsdIfStable;
|
|
24
|
+
function calcPrice(amount, token, usd) {
|
|
25
|
+
if (usd == null) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
let tokenBase = 10n ** BigInt(token.decimals);
|
|
29
|
+
let tokenAmount = _bigint_1.$bigint.divToFloat(amount, tokenBase, 10n ** 8n);
|
|
30
|
+
return _number_1.$number.div(usd, tokenAmount);
|
|
31
|
+
}
|
|
32
|
+
TokenUtils.calcPrice = calcPrice;
|
|
33
|
+
function calcTotal(token, amount, price) {
|
|
34
|
+
if (price == null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
let tokenBase = 10n ** BigInt(token.decimals);
|
|
38
|
+
let tokenAmount = _bigint_1.$bigint.divToFloat(amount, tokenBase, 10n ** 8n);
|
|
39
|
+
return tokenAmount * price;
|
|
40
|
+
}
|
|
41
|
+
TokenUtils.calcTotal = calcTotal;
|
|
42
|
+
function merge(...tokens) {
|
|
43
|
+
let all = (0, alot_1.default)(tokens)
|
|
44
|
+
.mapMany(arr => arr)
|
|
45
|
+
.groupBy(x => x.symbol)
|
|
46
|
+
.map(group => {
|
|
47
|
+
let logo = group.values.find(x => x.logo)?.logo;
|
|
48
|
+
let token = group.values[0];
|
|
49
|
+
return {
|
|
50
|
+
symbol: token.symbol,
|
|
51
|
+
name: token.name,
|
|
52
|
+
logo: logo,
|
|
53
|
+
platforms: group.values.map(t => {
|
|
54
|
+
return {
|
|
55
|
+
address: t.address,
|
|
56
|
+
decimals: t.decimals,
|
|
57
|
+
platform: t.platform,
|
|
58
|
+
};
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
})
|
|
62
|
+
.toArray();
|
|
63
|
+
return all;
|
|
64
|
+
}
|
|
65
|
+
TokenUtils.merge = merge;
|
|
66
|
+
})(TokenUtils = exports.TokenUtils || (exports.TokenUtils = {}));
|