UNPKG

@holographxyz/cli

Version:
91 lines (90 loc) 3.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const contracts_1 = require("@ethersproject/contracts"); const bignumber_1 = require("@ethersproject/bignumber"); const environment_1 = require("@holographxyz/environment"); const contracts_2 = require("../utils/contracts"); const ENVIRONMENT = (0, environment_1.getEnvironment)(); const HOLOGRAPH_ADDRESS = contracts_2.HOLOGRAPH_ADDRESSES[ENVIRONMENT]; const HLG_FAUCET_ADDRESS = contracts_2.FAUCET_ADDRESSES[ENVIRONMENT]; class CoreChainService { network; networkMonitor; holograph; abis = {}; get provider() { return this.networkMonitor.providers[this.network]; } get wallet() { return this.networkMonitor.wallets[this.network]; } constructor(network, networkMonitor) { this.network = network; this.networkMonitor = networkMonitor; } // NOTE: This must be called on instantiation! async initialize() { this.abis = await (0, contracts_2.getABIs)(ENVIRONMENT); this.holograph = new contracts_1.Contract(HOLOGRAPH_ADDRESS, this.abis.HolographABI, this.wallet); } getChainGasPrice = () => { let gasPrice = this.networkMonitor.gasPrices[this.network].gasPrice; gasPrice = gasPrice.add(gasPrice.div(bignumber_1.BigNumber.from('4'))); return gasPrice; }; getCxipNFT = (collection) => { return new contracts_1.Contract(collection, this.abis.CxipERC721ABI, this.wallet); }; getBridge = async () => { const address = await this.holograph?.getBridge(); return new contracts_1.Contract(address, this.abis.HolographBridgeABI, this.wallet); }; getFactory = async () => { const address = await this.holograph?.getFactory(); return new contracts_1.Contract(address, this.abis.HolographFactoryABI, this.wallet); }; getFaucet = () => { return new contracts_1.Contract(HLG_FAUCET_ADDRESS, this.abis.FaucetABI, this.wallet); }; getInterfaces = async () => { const address = await this.holograph?.getInterfaces(); return new contracts_1.Contract(address, this.abis.HolographInterfacesABI, this.wallet); }; getOperator = async () => { const address = await this.holograph?.getOperator(); return new contracts_1.Contract(address, this.abis.HolographOperatorABI, this.wallet); }; getRegistry = async () => { const address = await this.holograph?.getRegistry(); return new contracts_1.Contract(address, this.abis.HolographRegistryABI, this.wallet); }; getRegistryAddress = async () => { return this.holograph?.getRegistry(); }; getUtilityToken = async () => { const address = await this.holograph?.getUtilityToken(); return new contracts_1.Contract(address, this.abis.HolographERC20ABI, this.wallet); }; getLZ = () => { return new contracts_1.Contract(contracts_2.LZ_RELAYER_ADDRESSES[this.network], this.abis.LayerZeroABI, this.wallet); }; getWalletAddress = async () => { return this.wallet.getAddress(); }; getBalance = async (account) => { if (account === undefined) { account = this.wallet.address; } return this.networkMonitor.getBalance({ walletAddress: account, network: this.network, }); }; getTransaction = async (txHash) => { return this.networkMonitor.getTransaction({ transactionHash: txHash, network: this.network, }); }; } exports.default = CoreChainService;