import { BigNumber, ethers } from 'ethers'; import { Interface } from 'ethers/lib/utils'; import { ContractInitializer } from './ContractInitializer'; const iface = new Interface([ 'function estimateFees(uint16 _chainId, address _ua, bytes calldata _payload, bool _payInZRO, bytes calldata _adapterParams) external view override returns (uint nativeFee, uint zroFee)', ]); export class LayerZeroUltraLightNode extends ContractInitializer { className = LayerZeroUltraLightNode.name; static create( signer: ethers.providers.JsonRpcSigner, address: string, chainId: string ) { const instance = new LayerZeroUltraLightNode(chainId, iface, signer); instance.address = address; instance.initialize(); return instance; } static _newInstance = (chainId: string) => { const selfInstance = new LayerZeroUltraLightNode(chainId, iface); selfInstance.address = selfInstance.chainConfig.contractAddress.layerZero; selfInstance.initialize(); return selfInstance; }; static estimateFees = async ( chainId: string, dstLayerZeroChainId: ethers.BigNumberish, userContractAdddress: string, payload: ethers.utils.BytesLike, gas: ethers.BigNumberish ): Promise<{ nativeFee: BigNumber; zroFee: BigNumber }> => { const selfInstance = LayerZeroUltraLightNode._newInstance(chainId); selfInstance.logCall('estimateFees', { chainId, dstLayerZeroChainId, userContractAdddress, payload, gas, }); const payInZRO = false; const adapterParam = ethers.utils.solidityPack( ['uint16', 'uint256'], [1, gas] ); return selfInstance.contractInstance.estimateFees( dstLayerZeroChainId, userContractAdddress, payload, payInZRO, adapterParam ); }; }