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,327 @@
|
|
|
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.HopBridge = void 0;
|
|
7
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
8
|
+
const BlockChainExplorerProvider_1 = require("@dequanto/BlockchainExplorer/BlockChainExplorerProvider");
|
|
9
|
+
const Web3ClientFactory_1 = require("@dequanto/clients/Web3ClientFactory");
|
|
10
|
+
const TokenService_1 = require("@dequanto/tokens/TokenService");
|
|
11
|
+
const TokensServiceFactory_1 = require("@dequanto/tokens/TokensServiceFactory");
|
|
12
|
+
const _bigint_1 = require("@dequanto/utils/$bigint");
|
|
13
|
+
const _date_1 = require("@dequanto/utils/$date");
|
|
14
|
+
const mainnet_1 = require("@hop-protocol/core/networks/mainnet");
|
|
15
|
+
const sdk_1 = require("@hop-protocol/sdk");
|
|
16
|
+
const ethers_1 = require("ethers");
|
|
17
|
+
const atma_utils_1 = require("atma-utils");
|
|
18
|
+
const Dai_l2AmmWrapperContract_1 = require("./contracts/polygon/Dai_l2AmmWrapperContract");
|
|
19
|
+
const HopAddresses_1 = require("./HopAddresses");
|
|
20
|
+
const Dai_l2BridgeContract_1 = require("./contracts/polygon/Dai_l2BridgeContract");
|
|
21
|
+
const _fn_1 = require("@dequanto/utils/$fn");
|
|
22
|
+
const PlatformFactory_1 = require("@dequanto/chains/PlatformFactory");
|
|
23
|
+
const _require_1 = require("@dequanto/utils/$require");
|
|
24
|
+
const Dai_l2SaddleSwapContract_1 = require("./contracts/polygon/Dai_l2SaddleSwapContract");
|
|
25
|
+
const _address_1 = require("@dequanto/utils/$address");
|
|
26
|
+
class HopBridge {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.name = 'hop';
|
|
29
|
+
// tested and used chains
|
|
30
|
+
this.SUPPORTED_CHAINS = ['polygon', 'xdai'];
|
|
31
|
+
}
|
|
32
|
+
async withdraw(account, platform, symbol, params) {
|
|
33
|
+
_require_1.$require.oneOf(platform, this.SUPPORTED_CHAINS, 'Supporting only tested chains');
|
|
34
|
+
_require_1.$require.match(/^h/i, symbol, 'We can withdraw hop wrapped tokens, like "hDAI"');
|
|
35
|
+
symbol = symbol.substring(1).toUpperCase();
|
|
36
|
+
let addresses = HopAddresses_1.HopAddresses.bridges[symbol]?.[platform];
|
|
37
|
+
if (addresses == null) {
|
|
38
|
+
throw new Error(`No bridge addresses for symbol ${symbol} and platform ${platform}`);
|
|
39
|
+
}
|
|
40
|
+
let swapAddress = addresses.l2SaddleSwap;
|
|
41
|
+
_require_1.$require.Address(swapAddress, `Swap Address undefined for ${symbol} and ${platform}`);
|
|
42
|
+
let bridgeTokenAddress = addresses.l2HopBridgeToken;
|
|
43
|
+
_require_1.$require.Address(bridgeTokenAddress, `Bridge Token undefined for ${symbol} and ${platform}`);
|
|
44
|
+
let chain = await a_di_1.default.resolve(PlatformFactory_1.PlatformFactory).get(platform);
|
|
45
|
+
let swapContract = new Dai_l2SaddleSwapContract_1.Dai_l2SaddleSwapContract(swapAddress, chain.client, chain.explorer);
|
|
46
|
+
let tokens = await Promise.all([
|
|
47
|
+
swapContract.getToken(0),
|
|
48
|
+
swapContract.getToken(1),
|
|
49
|
+
]);
|
|
50
|
+
let hTokenAddr = tokens.find(x => _address_1.$address.eq(x, bridgeTokenAddress));
|
|
51
|
+
_require_1.$require.notNull(hTokenAddr, `Bridge Token (${bridgeTokenAddress}) not found in ${tokens}`);
|
|
52
|
+
let hTokenIndex = tokens.indexOf(hTokenAddr);
|
|
53
|
+
let hToken = {
|
|
54
|
+
decimals: 18,
|
|
55
|
+
address: hTokenAddr,
|
|
56
|
+
platform,
|
|
57
|
+
symbol: 'hDAI'
|
|
58
|
+
};
|
|
59
|
+
let hTokenContract = await chain.tokens.erc20(hToken);
|
|
60
|
+
let amount = await hTokenContract.balanceOf(account.address);
|
|
61
|
+
console.log(amount);
|
|
62
|
+
let txApprove = await chain.token.ensureApproved(account, hToken, swapContract.address, amount);
|
|
63
|
+
if (txApprove) {
|
|
64
|
+
await txApprove.onCompleted;
|
|
65
|
+
}
|
|
66
|
+
let tx = await swapContract
|
|
67
|
+
.$config(params?.config ?? {})
|
|
68
|
+
.swap(account, hTokenIndex, hTokenIndex === 0 ? 1 : 0, amount, _bigint_1.$bigint.multWithFloat(amount, .97), BigInt(_date_1.$date.tool().add('24h').toUnixTimestamp()));
|
|
69
|
+
return tx;
|
|
70
|
+
}
|
|
71
|
+
async canTransfer(account, amount, symbol, fromPlatform, toPlatform) {
|
|
72
|
+
const client = Web3ClientFactory_1.Web3ClientFactory.get(fromPlatform);
|
|
73
|
+
const tokenService = a_di_1.default.resolve(TokenService_1.TokenService, client);
|
|
74
|
+
const tokensService = TokensServiceFactory_1.TokensServiceFactory.get(fromPlatform);
|
|
75
|
+
const TokenBridges = this.getTokenBridges(symbol);
|
|
76
|
+
this.checkPlatforms(fromPlatform, toPlatform, symbol, TokenBridges);
|
|
77
|
+
let token = await this.getToken(tokensService, symbol, fromPlatform);
|
|
78
|
+
let balance = await tokenService.balanceOf(account, token);
|
|
79
|
+
if (balance === 0n) {
|
|
80
|
+
return { error: new Error(`Balance is empty to transfer`) };
|
|
81
|
+
}
|
|
82
|
+
if (amount != null) {
|
|
83
|
+
let amountWei = this.getAmount(amount, token);
|
|
84
|
+
if (balance < amountWei) {
|
|
85
|
+
return { error: new Error(`Invalid balance to transfer`) };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { error: null };
|
|
89
|
+
}
|
|
90
|
+
async transfer(account, amount, symbol, fromPlatform, toPlatform) {
|
|
91
|
+
const chainFrom = await a_di_1.default.resolve(PlatformFactory_1.PlatformFactory).get(fromPlatform);
|
|
92
|
+
// const client = Web3ClientFactory.get(fromPlatform);
|
|
93
|
+
// const tokenService = di.resolve(TokenService, client);
|
|
94
|
+
// const tokensService = TokensServiceFactory.get(fromPlatform);
|
|
95
|
+
let token = await this.getToken(chainFrom.tokens, symbol, fromPlatform);
|
|
96
|
+
let amountWei = this.getAmount(amount, token);
|
|
97
|
+
let TokenBridges = this.getTokenBridges(symbol);
|
|
98
|
+
this.checkPlatforms(fromPlatform, toPlatform, symbol, TokenBridges);
|
|
99
|
+
const url = await chainFrom.client.getNodeURL({ ws: false });
|
|
100
|
+
const provider = new ethers_1.providers.JsonRpcProvider(url, Utils.getChainId(fromPlatform));
|
|
101
|
+
// WORKAROUND: make hop sdk to use our RPC.
|
|
102
|
+
mainnet_1.networks[fromPlatform].publicRpcUrl = url;
|
|
103
|
+
const signer = new ethers_1.Wallet(account.key, provider);
|
|
104
|
+
const hop = new sdk_1.Hop('mainnet', signer);
|
|
105
|
+
const bridge = hop.bridge(symbol);
|
|
106
|
+
let BridgeAddresses = this.getBridgeAddresses(fromPlatform, symbol, TokenBridges);
|
|
107
|
+
const l2AmmWrapperAddr = BridgeAddresses.l2AmmWrapper;
|
|
108
|
+
const l2BridgeAddr = BridgeAddresses.l2Bridge;
|
|
109
|
+
let withRemainder = amountWei < 0;
|
|
110
|
+
let balance = null;
|
|
111
|
+
let remainder = null;
|
|
112
|
+
if (withRemainder) {
|
|
113
|
+
remainder = amountWei * -1n;
|
|
114
|
+
balance = await chainFrom.token.balanceOf(account.address, token);
|
|
115
|
+
amountWei = balance + amountWei;
|
|
116
|
+
let gasPrice = await chainFrom.client.getGasPrice();
|
|
117
|
+
let gasLimit = 300000n;
|
|
118
|
+
amountWei -= gasPrice.price * gasLimit;
|
|
119
|
+
console.log(`Estimated GAS Price: ${_bigint_1.$bigint.toGweiFromWei(gasPrice.price)}GWEI; Total: ${_bigint_1.$bigint.toGweiFromWei(gasPrice.price * gasLimit)}GWEI`);
|
|
120
|
+
if (amountWei < 0) {
|
|
121
|
+
throw new Error(`Not enough amount to be left on chain. Balance ${balance}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const isNative = chainFrom.tokens.isNative(token);
|
|
125
|
+
if (isNative === false) {
|
|
126
|
+
// ERC20, check approval
|
|
127
|
+
let txApprove = await chainFrom.token.ensureApproved(account, token, l2AmmWrapperAddr, amountWei);
|
|
128
|
+
if (txApprove) {
|
|
129
|
+
await txApprove.onCompleted;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// console.log(
|
|
133
|
+
// 'Hop.transfer',
|
|
134
|
+
// symbol, l2AmmWrapperAddr,
|
|
135
|
+
// chainFrom.client.platform,
|
|
136
|
+
// fromPlatform,
|
|
137
|
+
// toPlatform,
|
|
138
|
+
// url
|
|
139
|
+
// );
|
|
140
|
+
let depositContract = new Dai_l2AmmWrapperContract_1.Dai_l2AmmWrapperContract(l2AmmWrapperAddr, chainFrom.client, BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(fromPlatform));
|
|
141
|
+
let bridgeContract = new Dai_l2BridgeContract_1.Dai_l2BridgeContract(l2BridgeAddr, chainFrom.client, BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(fromPlatform));
|
|
142
|
+
let deadline = bridge.defaultDeadlineSeconds; // BigInt($date.tool().add(`${bridge.defaultDeadlineSeconds}s`).toUnixTimestamp());
|
|
143
|
+
let sendData = await bridge.getSendData(amountWei.toString(), Utils.getChain(fromPlatform), Utils.getChain(toPlatform));
|
|
144
|
+
let params = {
|
|
145
|
+
bonderFee: BigInt(sendData.adjustedBonderFee.toString()),
|
|
146
|
+
txFee: BigInt(sendData.adjustedDestinationTxFee.toString()),
|
|
147
|
+
totalFee: BigInt(sendData.totalFee.toString()),
|
|
148
|
+
estimatedReceived: BigInt(sendData.estimatedReceived.toString()),
|
|
149
|
+
amountOut: BigInt(sendData.amountOut.toString())
|
|
150
|
+
};
|
|
151
|
+
let txWriter = await depositContract
|
|
152
|
+
.$config({
|
|
153
|
+
gasLimit: 300000,
|
|
154
|
+
gasLimitRatio: 1,
|
|
155
|
+
})
|
|
156
|
+
.swapAndSend({
|
|
157
|
+
...account,
|
|
158
|
+
value: isNative ? amountWei : 0n
|
|
159
|
+
}, BigInt(Utils.getChainId(toPlatform)), account.address, amountWei, params.totalFee, params.amountOut - _bigint_1.$bigint.toWei(.15, token.decimals), BigInt(deadline), params.estimatedReceived - _bigint_1.$bigint.toWei(.15, token.decimals), BigInt(deadline));
|
|
160
|
+
let result = {
|
|
161
|
+
txWriter: txWriter,
|
|
162
|
+
txReceipt: new atma_utils_1.class_Dfr(),
|
|
163
|
+
txTransferId: new atma_utils_1.class_Dfr()
|
|
164
|
+
};
|
|
165
|
+
(async function () {
|
|
166
|
+
try {
|
|
167
|
+
let receipt = await txWriter.onCompleted;
|
|
168
|
+
result.txReceipt.resolve(receipt);
|
|
169
|
+
let [event] = bridgeContract.extractLogsTransferSent(receipt);
|
|
170
|
+
if (event == null) {
|
|
171
|
+
throw new Error(`TransferSent Event was not parsed`);
|
|
172
|
+
}
|
|
173
|
+
result.txTransferId.resolve(event.transferId);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
result.txTransferId.reject(error);
|
|
177
|
+
}
|
|
178
|
+
}());
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
async waitForTransfer(transferId, symbol, toPlatform, toAccount) {
|
|
182
|
+
let r = await _fn_1.$fn.waitForObject(async () => {
|
|
183
|
+
let val = await this.status(transferId, symbol, toPlatform);
|
|
184
|
+
console.log(`${_date_1.$date.format(new Date(), 'HH:mm')} Checked for bridge transfer completion: ${val}`);
|
|
185
|
+
if (val) {
|
|
186
|
+
return [null, {}];
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}, {
|
|
190
|
+
intervalMs: 20000,
|
|
191
|
+
timeoutMs: 5 * 60 * 60 * 1000,
|
|
192
|
+
timeoutMessage: `Waiting the Transfer to be Completed timeouted`
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
async status(transferId, symbol, toPlatform) {
|
|
196
|
+
symbol = symbol.toUpperCase();
|
|
197
|
+
if (symbol === 'XDAI') {
|
|
198
|
+
symbol = 'DAI';
|
|
199
|
+
}
|
|
200
|
+
let TokenBridges = HopAddresses_1.HopAddresses.bridges[symbol];
|
|
201
|
+
if (TokenBridges == null) {
|
|
202
|
+
throw new Error(`Token ${symbol} is not supported by the HOP Protocol`);
|
|
203
|
+
}
|
|
204
|
+
let bridgeToPlatform = getBridgePlatform(toPlatform);
|
|
205
|
+
if (bridgeToPlatform in TokenBridges === false) {
|
|
206
|
+
throw new Error(`Unsupported chain ("${toPlatform}") to transfer ${symbol} token to`);
|
|
207
|
+
}
|
|
208
|
+
let BridgeAddresses = TokenBridges[bridgeToPlatform];
|
|
209
|
+
if (BridgeAddresses == null) {
|
|
210
|
+
throw new Error(`No BridgeAddresses for ${toPlatform} and token ${symbol}`);
|
|
211
|
+
}
|
|
212
|
+
const l2BridgeAddr = BridgeAddresses.l2Bridge;
|
|
213
|
+
const client = Web3ClientFactory_1.Web3ClientFactory.get(toPlatform);
|
|
214
|
+
let bridgeContract = new Dai_l2BridgeContract_1.Dai_l2BridgeContract(l2BridgeAddr, client, BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(toPlatform));
|
|
215
|
+
return bridgeContract.isTransferIdSpent(transferId);
|
|
216
|
+
}
|
|
217
|
+
async transferWithSDK(account, amount, token, fromPlatform, toPlatform) {
|
|
218
|
+
if (typeof amount === 'number') {
|
|
219
|
+
amount = _bigint_1.$bigint.toWei(amount, token.decimals);
|
|
220
|
+
}
|
|
221
|
+
const client = Web3ClientFactory_1.Web3ClientFactory.get(fromPlatform);
|
|
222
|
+
const url = await client.getNodeURL({ ws: false });
|
|
223
|
+
const provider = new ethers_1.providers.JsonRpcProvider(url);
|
|
224
|
+
const signer = new ethers_1.Wallet(account.key, provider);
|
|
225
|
+
const hop = new sdk_1.Hop('mainnet', signer);
|
|
226
|
+
const bridge = hop.bridge(token.symbol);
|
|
227
|
+
const tx = await bridge.approveAndSend(amount.toString(), Utils.getChain(fromPlatform), Utils.getChain(toPlatform));
|
|
228
|
+
console.log(tx);
|
|
229
|
+
return tx;
|
|
230
|
+
}
|
|
231
|
+
checkPlatforms(fromPlatform, toPlatform, symbol, TokenBridges) {
|
|
232
|
+
if (this.SUPPORTED_CHAINS.includes(fromPlatform) === false) {
|
|
233
|
+
throw new Error(`From ${fromPlatform} platform is not tested yet`);
|
|
234
|
+
}
|
|
235
|
+
if (this.SUPPORTED_CHAINS.includes(toPlatform) === false) {
|
|
236
|
+
throw new Error(`To ${toPlatform} platform is not tested yet`);
|
|
237
|
+
}
|
|
238
|
+
/** throws if invalid */
|
|
239
|
+
this.getBridgePlatform(fromPlatform, symbol, TokenBridges);
|
|
240
|
+
/** throws if invalid */
|
|
241
|
+
this.getBridgePlatform(toPlatform, symbol, TokenBridges);
|
|
242
|
+
/** throws if invalid */
|
|
243
|
+
this.getBridgeAddresses(fromPlatform, symbol, TokenBridges);
|
|
244
|
+
}
|
|
245
|
+
getAmount(amount, token) {
|
|
246
|
+
if (typeof amount === 'number') {
|
|
247
|
+
return _bigint_1.$bigint.toWei(amount, token.decimals);
|
|
248
|
+
}
|
|
249
|
+
return amount;
|
|
250
|
+
}
|
|
251
|
+
async getToken(tokensService, symbol, fromPlatform) {
|
|
252
|
+
if (fromPlatform === 'xdai') {
|
|
253
|
+
if (symbol === 'DAI') {
|
|
254
|
+
symbol = 'XDAI';
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let token = await tokensService.getKnownToken(symbol);
|
|
258
|
+
if (token.platform !== fromPlatform) {
|
|
259
|
+
throw new Error(`Token ${symbol} has wrong chain: ${token.platform}. Transfering from ${fromPlatform}`);
|
|
260
|
+
}
|
|
261
|
+
return token;
|
|
262
|
+
}
|
|
263
|
+
getTokenBridges(symbol) {
|
|
264
|
+
let TokenBridges = HopAddresses_1.HopAddresses.bridges[symbol];
|
|
265
|
+
if (TokenBridges == null) {
|
|
266
|
+
throw new Error(`Token ${symbol} is not supported by the HOP Protocol`);
|
|
267
|
+
}
|
|
268
|
+
return TokenBridges;
|
|
269
|
+
}
|
|
270
|
+
getBridgePlatform(platform, symbol, TokenBridges) {
|
|
271
|
+
let bridgePlatform = getBridgePlatform(platform);
|
|
272
|
+
if (bridgePlatform in TokenBridges === false) {
|
|
273
|
+
throw new Error(`Unsupported chain ("${platform}") to transfer ${symbol} token from`);
|
|
274
|
+
}
|
|
275
|
+
return bridgePlatform;
|
|
276
|
+
}
|
|
277
|
+
getBridgeAddresses(platform, symbol, TokenBridges) {
|
|
278
|
+
let bridgePlatform = this.getBridgePlatform(platform, symbol, TokenBridges);
|
|
279
|
+
let BridgeAddresses = TokenBridges[bridgePlatform];
|
|
280
|
+
if (BridgeAddresses == null) {
|
|
281
|
+
throw new Error(`No BridgeAddresses for ${platform} and token ${symbol}`);
|
|
282
|
+
}
|
|
283
|
+
return BridgeAddresses;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.HopBridge = HopBridge;
|
|
287
|
+
var Utils;
|
|
288
|
+
(function (Utils) {
|
|
289
|
+
function getChain(platform) {
|
|
290
|
+
switch (platform) {
|
|
291
|
+
case 'eth':
|
|
292
|
+
return sdk_1.Chain.Ethereum;
|
|
293
|
+
case 'bsc':
|
|
294
|
+
break;
|
|
295
|
+
case 'polygon':
|
|
296
|
+
return sdk_1.Chain.Polygon;
|
|
297
|
+
case 'xdai':
|
|
298
|
+
return sdk_1.Chain.xDai;
|
|
299
|
+
case 'arbitrum':
|
|
300
|
+
return sdk_1.Chain.Arbitrum;
|
|
301
|
+
}
|
|
302
|
+
throw new Error(`Not supported "${platform}" chain`);
|
|
303
|
+
}
|
|
304
|
+
Utils.getChain = getChain;
|
|
305
|
+
function getChainId(platform) {
|
|
306
|
+
switch (platform) {
|
|
307
|
+
case 'eth':
|
|
308
|
+
return 1;
|
|
309
|
+
case 'bsc':
|
|
310
|
+
return 56;
|
|
311
|
+
case 'polygon':
|
|
312
|
+
return 137;
|
|
313
|
+
case 'xdai':
|
|
314
|
+
return 100;
|
|
315
|
+
case 'arbitrum':
|
|
316
|
+
return 42161;
|
|
317
|
+
}
|
|
318
|
+
throw new Error(`Not supported "${platform}" chain`);
|
|
319
|
+
}
|
|
320
|
+
Utils.getChainId = getChainId;
|
|
321
|
+
})(Utils || (Utils = {}));
|
|
322
|
+
function getBridgePlatform(platform) {
|
|
323
|
+
switch (platform) {
|
|
324
|
+
case 'eth': return 'ethereum';
|
|
325
|
+
default: return platform;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
const BlockChainExplorerProvider_1 = require("@dequanto/BlockchainExplorer/BlockChainExplorerProvider");
|
|
7
|
+
const Generator_1 = require("@dequanto/gen/Generator");
|
|
8
|
+
const alot_1 = __importDefault(require("alot"));
|
|
9
|
+
const atma_utest_1 = require("atma-utest");
|
|
10
|
+
const HopAddresses_1 = require("../HopAddresses");
|
|
11
|
+
atma_utest_1.UAction.create({
|
|
12
|
+
async 'generate contracts'() {
|
|
13
|
+
const GENERATE_FOR = ['l2AmmWrapper', 'l2Bridge', 'l2SaddleSwap'];
|
|
14
|
+
await alot_1.default.fromObject(HopAddresses_1.HopAddresses.bridges).forEachAsync(async (tokenEntry) => {
|
|
15
|
+
let tokenSymbol = tokenEntry.key.replace(/(\w)(\w+)/g, (full, firstLetter, rest) => `${firstLetter}${rest.toLowerCase()}`);
|
|
16
|
+
await alot_1.default.fromObject(tokenEntry.value).forEachAsync(async (chainEntry) => {
|
|
17
|
+
let scan;
|
|
18
|
+
let platform;
|
|
19
|
+
if (chainEntry.key === 'polygon') {
|
|
20
|
+
platform = 'polygon';
|
|
21
|
+
scan = BlockChainExplorerProvider_1.BlockChainExplorerProvider.get('polygon');
|
|
22
|
+
}
|
|
23
|
+
if (scan != null) {
|
|
24
|
+
await alot_1.default.fromObject(chainEntry.value)
|
|
25
|
+
.filter(x => GENERATE_FOR.includes(x.key))
|
|
26
|
+
.forEachAsync(async (contractEntry) => {
|
|
27
|
+
let name = `${tokenSymbol}_${contractEntry.key}Contract`;
|
|
28
|
+
let opts = {
|
|
29
|
+
platform: platform,
|
|
30
|
+
name: name,
|
|
31
|
+
source: {
|
|
32
|
+
abi: contractEntry.value,
|
|
33
|
+
},
|
|
34
|
+
output: `./dequanto/src/bridges/hop/contracts/${platform}/`
|
|
35
|
+
};
|
|
36
|
+
let generator = new Generator_1.Generator(opts);
|
|
37
|
+
await generator.generate();
|
|
38
|
+
}).toArrayAsync();
|
|
39
|
+
}
|
|
40
|
+
}).toArrayAsync();
|
|
41
|
+
}).toArrayAsync();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
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.Dai_l2AmmWrapperContract = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* AUTO-Generated Class: 2022-01-08 23:50
|
|
9
|
+
* Implementation: https://polygonscan.com/address/0x28529fec439cfF6d7D1D5917e956dEE62Cd3BE5c#code
|
|
10
|
+
*/
|
|
11
|
+
const a_di_1 = __importDefault(require("a-di"));
|
|
12
|
+
const ContractBase_1 = require("@dequanto/contracts/ContractBase");
|
|
13
|
+
const Polyscan_1 = require("@dequanto/BlockchainExplorer/Polyscan");
|
|
14
|
+
const PolyWeb3Client_1 = require("@dequanto/clients/PolyWeb3Client");
|
|
15
|
+
class Dai_l2AmmWrapperContract extends ContractBase_1.ContractBase {
|
|
16
|
+
constructor(address = '0x28529fec439cfF6d7D1D5917e956dEE62Cd3BE5c', client = a_di_1.default.resolve(PolyWeb3Client_1.PolyWeb3Client), explorer = a_di_1.default.resolve(Polyscan_1.Polyscan)) {
|
|
17
|
+
super(address, client, explorer);
|
|
18
|
+
this.address = address;
|
|
19
|
+
this.client = client;
|
|
20
|
+
this.explorer = explorer;
|
|
21
|
+
this.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" }];
|
|
22
|
+
}
|
|
23
|
+
// 0x676c5ef6
|
|
24
|
+
async attemptSwap(eoa, recipient, amount, amountOutMin, deadline) {
|
|
25
|
+
return this.$write(this.$getAbiItem('function', 'attemptSwap'), eoa, recipient, amount, amountOutMin, deadline);
|
|
26
|
+
}
|
|
27
|
+
// 0xe78cea92
|
|
28
|
+
async bridge() {
|
|
29
|
+
return this.$read('function bridge() returns address');
|
|
30
|
+
}
|
|
31
|
+
// 0x9cd01605
|
|
32
|
+
async exchangeAddress() {
|
|
33
|
+
return this.$read('function exchangeAddress() returns address');
|
|
34
|
+
}
|
|
35
|
+
// 0xfc6e3b3b
|
|
36
|
+
async hToken() {
|
|
37
|
+
return this.$read('function hToken() returns address');
|
|
38
|
+
}
|
|
39
|
+
// 0x1ee1bf67
|
|
40
|
+
async l2CanonicalToken() {
|
|
41
|
+
return this.$read('function l2CanonicalToken() returns address');
|
|
42
|
+
}
|
|
43
|
+
// 0x28555125
|
|
44
|
+
async l2CanonicalTokenIsEth() {
|
|
45
|
+
return this.$read('function l2CanonicalTokenIsEth() returns bool');
|
|
46
|
+
}
|
|
47
|
+
// 0xeea0d7b2
|
|
48
|
+
async swapAndSend(eoa, chainId, recipient, amount, bonderFee, amountOutMin, deadline, destinationAmountOutMin, destinationDeadline) {
|
|
49
|
+
return this.$write(this.$getAbiItem('function', 'swapAndSend'), eoa, chainId, recipient, amount, bonderFee, amountOutMin, deadline, destinationAmountOutMin, destinationDeadline);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.Dai_l2AmmWrapperContract = Dai_l2AmmWrapperContract;
|