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,430 @@
|
|
|
1
|
+
import di from 'a-di';
|
|
2
|
+
import { BlockChainExplorerProvider } from '@dequanto/BlockchainExplorer/BlockChainExplorerProvider';
|
|
3
|
+
import { ChainAccount } from '@dequanto/ChainAccounts';
|
|
4
|
+
import { Web3ClientFactory } from '@dequanto/clients/Web3ClientFactory';
|
|
5
|
+
import { IToken } from '@dequanto/models/IToken';
|
|
6
|
+
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
7
|
+
import { TokenService } from '@dequanto/tokens/TokenService';
|
|
8
|
+
import { TokensServiceFactory } from '@dequanto/tokens/TokensServiceFactory';
|
|
9
|
+
import { $bigint } from '@dequanto/utils/$bigint';
|
|
10
|
+
import { $date } from '@dequanto/utils/$date';
|
|
11
|
+
import { networks } from '@hop-protocol/core/networks/mainnet';
|
|
12
|
+
import { Hop, Chain } from '@hop-protocol/sdk';
|
|
13
|
+
import { Wallet, providers } from 'ethers'
|
|
14
|
+
import { class_Dfr } from 'atma-utils';
|
|
15
|
+
import { Dai_l2AmmWrapperContract } from './contracts/polygon/Dai_l2AmmWrapperContract';
|
|
16
|
+
import { HopAddresses } from './HopAddresses';
|
|
17
|
+
import { Dai_l2BridgeContract } from './contracts/polygon/Dai_l2BridgeContract';
|
|
18
|
+
import { $fn } from '@dequanto/utils/$fn';
|
|
19
|
+
import { TransactionReceipt } from 'web3-core';
|
|
20
|
+
import { IBridge } from '../models/IBridge';
|
|
21
|
+
import { TAddress } from '@dequanto/models/TAddress';
|
|
22
|
+
import { TokensService } from '@dequanto/tokens/TokensService';
|
|
23
|
+
import { PlatformFactory } from '@dequanto/chains/PlatformFactory';
|
|
24
|
+
import { $require } from '@dequanto/utils/$require';
|
|
25
|
+
import { Dai_l2SaddleSwapContract } from './contracts/polygon/Dai_l2SaddleSwapContract';
|
|
26
|
+
import { ITxConfig } from '@dequanto/txs/ITxConfig';
|
|
27
|
+
import { ITxWriterOptions } from '@dequanto/txs/TxWriter';
|
|
28
|
+
import { $address } from '@dequanto/utils/$address';
|
|
29
|
+
|
|
30
|
+
type THopAddresses = typeof HopAddresses;
|
|
31
|
+
|
|
32
|
+
export class HopBridge implements IBridge {
|
|
33
|
+
|
|
34
|
+
name = 'hop'
|
|
35
|
+
|
|
36
|
+
// tested and used chains
|
|
37
|
+
private SUPPORTED_CHAINS: TPlatform[] = [ 'polygon', 'xdai' ]
|
|
38
|
+
|
|
39
|
+
async withdraw (account: ChainAccount, platform: TPlatform, symbol: string, params?: {
|
|
40
|
+
config?: ITxConfig
|
|
41
|
+
amount?: number
|
|
42
|
+
}) {
|
|
43
|
+
$require.oneOf(platform, this.SUPPORTED_CHAINS, 'Supporting only tested chains');
|
|
44
|
+
$require.match(/^h/i, symbol, 'We can withdraw hop wrapped tokens, like "hDAI"');
|
|
45
|
+
|
|
46
|
+
symbol = symbol.substring(1).toUpperCase();
|
|
47
|
+
|
|
48
|
+
let addresses = HopAddresses.bridges[symbol]?.[platform] as THopAddresses['bridges']['DAI']['polygon'];
|
|
49
|
+
if (addresses == null) {
|
|
50
|
+
throw new Error(`No bridge addresses for symbol ${symbol} and platform ${platform}`);
|
|
51
|
+
}
|
|
52
|
+
let swapAddress = addresses.l2SaddleSwap;
|
|
53
|
+
$require.Address(swapAddress, `Swap Address undefined for ${symbol} and ${platform}`);
|
|
54
|
+
|
|
55
|
+
let bridgeTokenAddress = addresses.l2HopBridgeToken;
|
|
56
|
+
$require.Address(bridgeTokenAddress, `Bridge Token undefined for ${symbol} and ${platform}`);
|
|
57
|
+
|
|
58
|
+
let chain = await di.resolve(PlatformFactory).get(platform);
|
|
59
|
+
let swapContract = new Dai_l2SaddleSwapContract(
|
|
60
|
+
swapAddress,
|
|
61
|
+
chain.client,
|
|
62
|
+
chain.explorer,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
let tokens = await Promise.all([
|
|
66
|
+
swapContract.getToken(0),
|
|
67
|
+
swapContract.getToken(1),
|
|
68
|
+
]);
|
|
69
|
+
let hTokenAddr = tokens.find(x => $address.eq(x, bridgeTokenAddress));
|
|
70
|
+
$require.notNull(hTokenAddr, `Bridge Token (${bridgeTokenAddress}) not found in ${tokens}`);
|
|
71
|
+
|
|
72
|
+
let hTokenIndex = tokens.indexOf(hTokenAddr);
|
|
73
|
+
let hToken = {
|
|
74
|
+
decimals: 18,
|
|
75
|
+
address: hTokenAddr,
|
|
76
|
+
platform,
|
|
77
|
+
symbol: 'hDAI'
|
|
78
|
+
};
|
|
79
|
+
let hTokenContract = await chain.tokens.erc20(hToken);
|
|
80
|
+
let amount = await hTokenContract.balanceOf(account.address);
|
|
81
|
+
console.log(amount);
|
|
82
|
+
|
|
83
|
+
let txApprove = await chain.token.ensureApproved(account, hToken, swapContract.address, amount);
|
|
84
|
+
if (txApprove) {
|
|
85
|
+
await txApprove.onCompleted;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let tx = await swapContract
|
|
89
|
+
.$config(params?.config ?? {})
|
|
90
|
+
.swap(
|
|
91
|
+
account,
|
|
92
|
+
hTokenIndex,
|
|
93
|
+
hTokenIndex === 0 ? 1 : 0,
|
|
94
|
+
amount,
|
|
95
|
+
$bigint.multWithFloat(amount, .97),
|
|
96
|
+
BigInt($date.tool().add('24h').toUnixTimestamp())
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return tx;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async canTransfer (account: TAddress, amount: null | number | bigint, symbol: string, fromPlatform: TPlatform, toPlatform: TPlatform): Promise<{error: Error | null}> {
|
|
103
|
+
const client = Web3ClientFactory.get(fromPlatform);
|
|
104
|
+
const tokenService = di.resolve(TokenService, client);
|
|
105
|
+
const tokensService = TokensServiceFactory.get(fromPlatform);
|
|
106
|
+
const TokenBridges = this.getTokenBridges(symbol);
|
|
107
|
+
|
|
108
|
+
this.checkPlatforms(fromPlatform, toPlatform, symbol, TokenBridges);
|
|
109
|
+
|
|
110
|
+
let token = await this.getToken(tokensService, symbol, fromPlatform);
|
|
111
|
+
let balance = await tokenService.balanceOf(account, token);
|
|
112
|
+
if (balance === 0n) {
|
|
113
|
+
return { error: new Error(`Balance is empty to transfer`) };
|
|
114
|
+
}
|
|
115
|
+
if (amount != null) {
|
|
116
|
+
let amountWei = this.getAmount(amount, token);
|
|
117
|
+
if (balance < amountWei) {
|
|
118
|
+
return { error: new Error(`Invalid balance to transfer`) };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { error: null }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async transfer (account: ChainAccount, amount: number | bigint, symbol: string, fromPlatform: TPlatform, toPlatform: TPlatform) {
|
|
125
|
+
const chainFrom = await di.resolve(PlatformFactory).get(fromPlatform);
|
|
126
|
+
|
|
127
|
+
// const client = Web3ClientFactory.get(fromPlatform);
|
|
128
|
+
// const tokenService = di.resolve(TokenService, client);
|
|
129
|
+
// const tokensService = TokensServiceFactory.get(fromPlatform);
|
|
130
|
+
|
|
131
|
+
let token = await this.getToken(chainFrom.tokens, symbol, fromPlatform);
|
|
132
|
+
let amountWei = this.getAmount(amount, token);
|
|
133
|
+
|
|
134
|
+
let TokenBridges = this.getTokenBridges(symbol);
|
|
135
|
+
|
|
136
|
+
this.checkPlatforms(fromPlatform, toPlatform, symbol, TokenBridges);
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
const url = await chainFrom.client.getNodeURL({ ws: false });
|
|
140
|
+
const provider = new providers.JsonRpcProvider(url, Utils.getChainId(fromPlatform));
|
|
141
|
+
|
|
142
|
+
// WORKAROUND: make hop sdk to use our RPC.
|
|
143
|
+
networks[fromPlatform].publicRpcUrl = url;
|
|
144
|
+
|
|
145
|
+
const signer = new Wallet(account.key, provider);
|
|
146
|
+
const hop = new Hop('mainnet', signer);
|
|
147
|
+
const bridge = hop.bridge(symbol);
|
|
148
|
+
|
|
149
|
+
let BridgeAddresses = this.getBridgeAddresses(fromPlatform, symbol, TokenBridges);
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
const l2AmmWrapperAddr = BridgeAddresses.l2AmmWrapper;
|
|
153
|
+
const l2BridgeAddr = BridgeAddresses.l2Bridge;
|
|
154
|
+
let withRemainder = amountWei < 0;
|
|
155
|
+
let balance: bigint = null;
|
|
156
|
+
let remainder: bigint = null;
|
|
157
|
+
if (withRemainder) {
|
|
158
|
+
remainder = amountWei * -1n;
|
|
159
|
+
balance = await chainFrom.token.balanceOf(account.address, token);
|
|
160
|
+
amountWei = balance + amountWei;
|
|
161
|
+
|
|
162
|
+
let gasPrice = await chainFrom.client.getGasPrice();
|
|
163
|
+
let gasLimit = 300_000n;
|
|
164
|
+
amountWei -= gasPrice.price * gasLimit;
|
|
165
|
+
console.log(`Estimated GAS Price: ${ $bigint.toGweiFromWei(gasPrice.price) }GWEI; Total: ${ $bigint.toGweiFromWei(gasPrice.price * gasLimit) }GWEI`);
|
|
166
|
+
if (amountWei < 0) {
|
|
167
|
+
throw new Error(`Not enough amount to be left on chain. Balance ${balance}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const isNative = chainFrom.tokens.isNative(token);
|
|
172
|
+
if (isNative === false) {
|
|
173
|
+
// ERC20, check approval
|
|
174
|
+
let txApprove = await chainFrom.token.ensureApproved(account, token, l2AmmWrapperAddr, amountWei);
|
|
175
|
+
if (txApprove) {
|
|
176
|
+
await txApprove.onCompleted;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// console.log(
|
|
181
|
+
// 'Hop.transfer',
|
|
182
|
+
// symbol, l2AmmWrapperAddr,
|
|
183
|
+
// chainFrom.client.platform,
|
|
184
|
+
// fromPlatform,
|
|
185
|
+
// toPlatform,
|
|
186
|
+
// url
|
|
187
|
+
// );
|
|
188
|
+
|
|
189
|
+
let depositContract = new Dai_l2AmmWrapperContract(
|
|
190
|
+
l2AmmWrapperAddr,
|
|
191
|
+
chainFrom.client,
|
|
192
|
+
BlockChainExplorerProvider.get(fromPlatform)
|
|
193
|
+
);
|
|
194
|
+
let bridgeContract = new Dai_l2BridgeContract(
|
|
195
|
+
l2BridgeAddr,
|
|
196
|
+
chainFrom.client,
|
|
197
|
+
BlockChainExplorerProvider.get(fromPlatform)
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
let deadline = bridge.defaultDeadlineSeconds; // BigInt($date.tool().add(`${bridge.defaultDeadlineSeconds}s`).toUnixTimestamp());
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
let sendData = await bridge.getSendData(
|
|
204
|
+
amountWei.toString(),
|
|
205
|
+
Utils.getChain(fromPlatform),
|
|
206
|
+
Utils.getChain(toPlatform),
|
|
207
|
+
);
|
|
208
|
+
let params = {
|
|
209
|
+
bonderFee: BigInt(sendData.adjustedBonderFee.toString()),
|
|
210
|
+
txFee: BigInt(sendData.adjustedDestinationTxFee.toString()),
|
|
211
|
+
|
|
212
|
+
totalFee: BigInt(sendData.totalFee.toString()),
|
|
213
|
+
estimatedReceived: BigInt(sendData.estimatedReceived.toString()),
|
|
214
|
+
amountOut: BigInt(sendData.amountOut.toString())
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
let txWriter = await depositContract
|
|
218
|
+
.$config({
|
|
219
|
+
gasLimit: 300_000,
|
|
220
|
+
gasLimitRatio: 1,
|
|
221
|
+
})
|
|
222
|
+
.swapAndSend(
|
|
223
|
+
{
|
|
224
|
+
...account,
|
|
225
|
+
value: isNative ? amountWei : 0n
|
|
226
|
+
},
|
|
227
|
+
BigInt(Utils.getChainId(toPlatform)),
|
|
228
|
+
account.address,
|
|
229
|
+
amountWei,
|
|
230
|
+
params.totalFee,
|
|
231
|
+
params.amountOut - $bigint.toWei(.15, token.decimals),
|
|
232
|
+
BigInt(deadline),
|
|
233
|
+
params.estimatedReceived - $bigint.toWei(.15, token.decimals),
|
|
234
|
+
BigInt(deadline)
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
let result = {
|
|
238
|
+
txWriter: txWriter,
|
|
239
|
+
txReceipt: new class_Dfr<TransactionReceipt>(),
|
|
240
|
+
txTransferId: new class_Dfr<string>()
|
|
241
|
+
};
|
|
242
|
+
(async function () {
|
|
243
|
+
try {
|
|
244
|
+
let receipt = await txWriter.onCompleted;
|
|
245
|
+
result.txReceipt.resolve(receipt);
|
|
246
|
+
|
|
247
|
+
let [ event ] = bridgeContract.extractLogsTransferSent(receipt);
|
|
248
|
+
if (event == null) {
|
|
249
|
+
throw new Error(`TransferSent Event was not parsed`);
|
|
250
|
+
}
|
|
251
|
+
result.txTransferId.resolve(event.transferId as string);
|
|
252
|
+
|
|
253
|
+
} catch (error) {
|
|
254
|
+
result.txTransferId.reject(error);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
}());
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async waitForTransfer (transferId: string, symbol: string, toPlatform: TPlatform, toAccount: TAddress): Promise<void> {
|
|
262
|
+
|
|
263
|
+
let r = await $fn.waitForObject(async () => {
|
|
264
|
+
let val = await this.status(transferId, symbol, toPlatform);
|
|
265
|
+
console.log(`${ $date.format(new Date(), 'HH:mm') } Checked for bridge transfer completion: ${val}`);
|
|
266
|
+
if (val) {
|
|
267
|
+
return [ null, {} ]
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}, {
|
|
271
|
+
intervalMs: 20000,
|
|
272
|
+
timeoutMs: 5 * 60 * 60 * 1000,
|
|
273
|
+
timeoutMessage: `Waiting the Transfer to be Completed timeouted`
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async status (transferId: string, symbol: string, toPlatform: TPlatform): Promise<boolean> {
|
|
278
|
+
symbol = symbol.toUpperCase();
|
|
279
|
+
|
|
280
|
+
if (symbol === 'XDAI') {
|
|
281
|
+
symbol = 'DAI';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
let TokenBridges = HopAddresses.bridges[ symbol ];
|
|
285
|
+
if (TokenBridges == null) {
|
|
286
|
+
throw new Error(`Token ${symbol} is not supported by the HOP Protocol`);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
let bridgeToPlatform = getBridgePlatform(toPlatform);
|
|
290
|
+
if (bridgeToPlatform in TokenBridges === false) {
|
|
291
|
+
throw new Error(`Unsupported chain ("${toPlatform}") to transfer ${symbol} token to`);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
let BridgeAddresses = TokenBridges[bridgeToPlatform];
|
|
295
|
+
if (BridgeAddresses == null) {
|
|
296
|
+
throw new Error(`No BridgeAddresses for ${toPlatform} and token ${symbol}`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const l2BridgeAddr = BridgeAddresses.l2Bridge;
|
|
300
|
+
const client = Web3ClientFactory.get(toPlatform);
|
|
301
|
+
|
|
302
|
+
let bridgeContract = new Dai_l2BridgeContract(
|
|
303
|
+
l2BridgeAddr,
|
|
304
|
+
client,
|
|
305
|
+
BlockChainExplorerProvider.get(toPlatform)
|
|
306
|
+
);
|
|
307
|
+
return bridgeContract.isTransferIdSpent(transferId);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async transferWithSDK (account: ChainAccount, amount: number | bigint, token: IToken, fromPlatform: TPlatform, toPlatform: TPlatform) {
|
|
311
|
+
if (typeof amount === 'number') {
|
|
312
|
+
amount = $bigint.toWei(amount, token.decimals);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const client = Web3ClientFactory.get(fromPlatform);
|
|
316
|
+
const url = await client.getNodeURL({ ws: false });
|
|
317
|
+
const provider = new providers.JsonRpcProvider(url);
|
|
318
|
+
const signer = new Wallet(account.key, provider);
|
|
319
|
+
const hop = new Hop('mainnet', signer);
|
|
320
|
+
const bridge = hop.bridge(token.symbol);
|
|
321
|
+
const tx = await bridge.approveAndSend(
|
|
322
|
+
amount.toString(),
|
|
323
|
+
Utils.getChain(fromPlatform),
|
|
324
|
+
Utils.getChain(toPlatform),
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
console.log(tx);
|
|
329
|
+
return tx;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
private checkPlatforms (fromPlatform: TPlatform, toPlatform: TPlatform, symbol: string, TokenBridges) {
|
|
334
|
+
if (this.SUPPORTED_CHAINS.includes(fromPlatform) === false) {
|
|
335
|
+
throw new Error(`From ${fromPlatform} platform is not tested yet`);
|
|
336
|
+
}
|
|
337
|
+
if (this.SUPPORTED_CHAINS.includes(toPlatform) === false) {
|
|
338
|
+
throw new Error(`To ${toPlatform} platform is not tested yet`);
|
|
339
|
+
}
|
|
340
|
+
/** throws if invalid */
|
|
341
|
+
this.getBridgePlatform(fromPlatform, symbol, TokenBridges);
|
|
342
|
+
/** throws if invalid */
|
|
343
|
+
this.getBridgePlatform(toPlatform, symbol, TokenBridges);
|
|
344
|
+
/** throws if invalid */
|
|
345
|
+
this.getBridgeAddresses(fromPlatform, symbol, TokenBridges);
|
|
346
|
+
}
|
|
347
|
+
private getAmount (amount: number | bigint, token: IToken): bigint {
|
|
348
|
+
if (typeof amount === 'number') {
|
|
349
|
+
return $bigint.toWei(amount, token.decimals);
|
|
350
|
+
}
|
|
351
|
+
return amount;
|
|
352
|
+
}
|
|
353
|
+
private async getToken (tokensService: TokensService, symbol: string, fromPlatform: TPlatform): Promise<IToken> {
|
|
354
|
+
if (fromPlatform === 'xdai') {
|
|
355
|
+
if (symbol === 'DAI') {
|
|
356
|
+
symbol = 'XDAI';
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
let token = await tokensService.getKnownToken(symbol);
|
|
361
|
+
if (token.platform !== fromPlatform) {
|
|
362
|
+
throw new Error(`Token ${symbol} has wrong chain: ${token.platform}. Transfering from ${fromPlatform}`);
|
|
363
|
+
}
|
|
364
|
+
return token;
|
|
365
|
+
}
|
|
366
|
+
private getTokenBridges (symbol: string) {
|
|
367
|
+
let TokenBridges = HopAddresses.bridges[ symbol ] as THopAddresses['bridges']['USDC'];
|
|
368
|
+
if (TokenBridges == null) {
|
|
369
|
+
throw new Error(`Token ${symbol} is not supported by the HOP Protocol`);
|
|
370
|
+
}
|
|
371
|
+
return TokenBridges;
|
|
372
|
+
}
|
|
373
|
+
private getBridgePlatform (platform: TPlatform, symbol, TokenBridges): string {
|
|
374
|
+
let bridgePlatform = getBridgePlatform(platform);
|
|
375
|
+
if (bridgePlatform in TokenBridges === false) {
|
|
376
|
+
throw new Error(`Unsupported chain ("${platform}") to transfer ${symbol} token from`);
|
|
377
|
+
}
|
|
378
|
+
return bridgePlatform;
|
|
379
|
+
}
|
|
380
|
+
private getBridgeAddresses (platform: TPlatform, symbol: string, TokenBridges) {
|
|
381
|
+
let bridgePlatform = this.getBridgePlatform(platform, symbol, TokenBridges);
|
|
382
|
+
|
|
383
|
+
let BridgeAddresses = TokenBridges[bridgePlatform];
|
|
384
|
+
if (BridgeAddresses == null) {
|
|
385
|
+
throw new Error(`No BridgeAddresses for ${platform} and token ${symbol}`);
|
|
386
|
+
}
|
|
387
|
+
return BridgeAddresses;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
namespace Utils {
|
|
393
|
+
export function getChain (platform: TPlatform) {
|
|
394
|
+
switch (platform) {
|
|
395
|
+
case 'eth':
|
|
396
|
+
return Chain.Ethereum;
|
|
397
|
+
case 'bsc':
|
|
398
|
+
break;
|
|
399
|
+
case 'polygon':
|
|
400
|
+
return Chain.Polygon;
|
|
401
|
+
case 'xdai':
|
|
402
|
+
return Chain.xDai;
|
|
403
|
+
case 'arbitrum':
|
|
404
|
+
return Chain.Arbitrum;
|
|
405
|
+
}
|
|
406
|
+
throw new Error(`Not supported "${platform}" chain`);
|
|
407
|
+
}
|
|
408
|
+
export function getChainId (platform: TPlatform) {
|
|
409
|
+
switch (platform) {
|
|
410
|
+
case 'eth':
|
|
411
|
+
return 1;
|
|
412
|
+
case 'bsc':
|
|
413
|
+
return 56;
|
|
414
|
+
case 'polygon':
|
|
415
|
+
return 137;
|
|
416
|
+
case 'xdai':
|
|
417
|
+
return 100;
|
|
418
|
+
case 'arbitrum':
|
|
419
|
+
return 42161;
|
|
420
|
+
}
|
|
421
|
+
throw new Error(`Not supported "${platform}" chain`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function getBridgePlatform (platform: TPlatform): string {
|
|
426
|
+
switch (platform) {
|
|
427
|
+
case 'eth': return 'ethereum';
|
|
428
|
+
default: return platform;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BlockChainExplorerProvider } from '@dequanto/BlockchainExplorer/BlockChainExplorerProvider';
|
|
2
|
+
import { IBlockChainExplorer } from '@dequanto/BlockchainExplorer/IBlockChainExplorer';
|
|
3
|
+
import { Generator } from '@dequanto/gen/Generator';
|
|
4
|
+
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
5
|
+
import alot from 'alot';
|
|
6
|
+
import { UAction } from 'atma-utest';
|
|
7
|
+
import { HopAddresses } from '../HopAddresses';
|
|
8
|
+
|
|
9
|
+
UAction.create({
|
|
10
|
+
async 'generate contracts' () {
|
|
11
|
+
const GENERATE_FOR = ['l2AmmWrapper', 'l2Bridge', 'l2SaddleSwap'];
|
|
12
|
+
|
|
13
|
+
await alot.fromObject(HopAddresses.bridges).forEachAsync(async tokenEntry => {
|
|
14
|
+
|
|
15
|
+
let tokenSymbol = tokenEntry.key.replace(/(\w)(\w+)/g, (full, firstLetter, rest) => `${firstLetter}${rest.toLowerCase()}`)
|
|
16
|
+
|
|
17
|
+
await alot.fromObject(tokenEntry.value).forEachAsync(async chainEntry => {
|
|
18
|
+
|
|
19
|
+
let scan: IBlockChainExplorer;
|
|
20
|
+
let platform: TPlatform;
|
|
21
|
+
if (chainEntry.key === 'polygon') {
|
|
22
|
+
platform = 'polygon';
|
|
23
|
+
scan = BlockChainExplorerProvider.get('polygon');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (scan != null) {
|
|
27
|
+
|
|
28
|
+
await alot.fromObject(chainEntry.value)
|
|
29
|
+
.filter(x => GENERATE_FOR.includes(x.key))
|
|
30
|
+
.forEachAsync(async contractEntry => {
|
|
31
|
+
|
|
32
|
+
let name = `${tokenSymbol}_${contractEntry.key}Contract`;
|
|
33
|
+
let opts = {
|
|
34
|
+
platform: platform,
|
|
35
|
+
name: name,
|
|
36
|
+
source: {
|
|
37
|
+
abi: contractEntry.value,
|
|
38
|
+
},
|
|
39
|
+
output: `./dequanto/src/bridges/hop/contracts/${platform}/`
|
|
40
|
+
};
|
|
41
|
+
let generator = new Generator(opts);
|
|
42
|
+
await generator.generate();
|
|
43
|
+
|
|
44
|
+
}).toArrayAsync();
|
|
45
|
+
}
|
|
46
|
+
}).toArrayAsync();
|
|
47
|
+
|
|
48
|
+
}).toArrayAsync();
|
|
49
|
+
}
|
|
50
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-Generated Class: 2022-01-08 23:50
|
|
3
|
+
* Implementation: https://polygonscan.com/address/0x28529fec439cfF6d7D1D5917e956dEE62Cd3BE5c#code
|
|
4
|
+
*/
|
|
5
|
+
import di from 'a-di';
|
|
6
|
+
import { TAddress } from '@dequanto/models/TAddress';
|
|
7
|
+
import { ClientEventsStream } from '@dequanto/clients/ClientEventsStream';
|
|
8
|
+
import { ContractBase } from '@dequanto/contracts/ContractBase';
|
|
9
|
+
import { AbiItem } from 'web3-utils';
|
|
10
|
+
import { TransactionReceipt } from 'web3-core';
|
|
11
|
+
import { EventData } from 'web3-eth-contract';
|
|
12
|
+
import { TxWriter } from '@dequanto/txs/TxWriter';
|
|
13
|
+
import { Web3Client } from '@dequanto/clients/Web3Client';
|
|
14
|
+
import { IBlockChainExplorer } from '@dequanto/BlockchainExplorer/IBlockChainExplorer';
|
|
15
|
+
|
|
16
|
+
import { Polyscan } from '@dequanto/BlockchainExplorer/Polyscan'
|
|
17
|
+
import { PolyWeb3Client } from '@dequanto/clients/PolyWeb3Client'
|
|
18
|
+
export class Dai_l2AmmWrapperContract extends ContractBase {
|
|
19
|
+
constructor(
|
|
20
|
+
public address: TAddress = '0x28529fec439cfF6d7D1D5917e956dEE62Cd3BE5c',
|
|
21
|
+
public client: Web3Client = di.resolve(PolyWeb3Client),
|
|
22
|
+
public explorer: IBlockChainExplorer = di.resolve(Polyscan)
|
|
23
|
+
) {
|
|
24
|
+
super(address, client, explorer)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 0x676c5ef6
|
|
28
|
+
async attemptSwap (eoa: {address: TAddress, key: string, value?: string | number | bigint }, recipient: TAddress, amount: bigint, amountOutMin: bigint, deadline: bigint): Promise<TxWriter> {
|
|
29
|
+
return this.$write(this.$getAbiItem('function', 'attemptSwap'), eoa, recipient, amount, amountOutMin, deadline);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 0xe78cea92
|
|
33
|
+
async bridge (): Promise<TAddress> {
|
|
34
|
+
return this.$read('function bridge() returns address');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 0x9cd01605
|
|
38
|
+
async exchangeAddress (): Promise<TAddress> {
|
|
39
|
+
return this.$read('function exchangeAddress() returns address');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 0xfc6e3b3b
|
|
43
|
+
async hToken (): Promise<TAddress> {
|
|
44
|
+
return this.$read('function hToken() returns address');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 0x1ee1bf67
|
|
48
|
+
async l2CanonicalToken (): Promise<TAddress> {
|
|
49
|
+
return this.$read('function l2CanonicalToken() returns address');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 0x28555125
|
|
53
|
+
async l2CanonicalTokenIsEth (): Promise<boolean> {
|
|
54
|
+
return this.$read('function l2CanonicalTokenIsEth() returns bool');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 0xeea0d7b2
|
|
58
|
+
async swapAndSend (eoa: {address: TAddress, key: string, value?: string | number | bigint }, chainId: bigint, recipient: TAddress, amount: bigint, bonderFee: bigint, amountOutMin: bigint, deadline: bigint, destinationAmountOutMin: bigint, destinationDeadline: bigint): Promise<TxWriter> {
|
|
59
|
+
return this.$write(this.$getAbiItem('function', 'swapAndSend'), eoa, chainId, recipient, amount, bonderFee, amountOutMin, deadline, destinationAmountOutMin, destinationDeadline);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
abi = [{"inputs":[{"internalType":"contract L2_Bridge","name":"_bridge","type":"address"},{"internalType":"contract IERC20","name":"_l2CanonicalToken","type":"address"},{"internalType":"bool","name":"_l2CanonicalTokenIsEth","type":"bool"},{"internalType":"contract IERC20","name":"_hToken","type":"address"},{"internalType":"contract Swap","name":"_exchangeAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"attemptSwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"bridge","outputs":[{"internalType":"contract L2_Bridge","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exchangeAddress","outputs":[{"internalType":"contract Swap","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2CanonicalToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2CanonicalTokenIsEth","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"bonderFee","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"destinationAmountOutMin","type":"uint256"},{"internalType":"uint256","name":"destinationDeadline","type":"uint256"}],"name":"swapAndSend","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|