import { BigNumber, ethers } from 'ethers'; import { OmniteLayerZeroBridgeSender__factory } from '../config/abi/factories/OmniteLayerZeroBridgeSender__factory'; import { IOmniteLayerZeroBridge, IOmniteLayerZeroBridgeSender, OmniteLayerZeroBridgeSender as BaseContract, } from '../config/abi/OmniteLayerZeroBridgeSender'; import config from '../config/config'; import { ChainId } from '../config/constants'; import { DeployBlueprintName } from '../types'; import { normalizeChainId } from '../utils/chainUtils'; import { ContractInitializer } from './ContractInitializer'; const iface = OmniteLayerZeroBridgeSender__factory.createInterface(); export class OmniteLayerZeroBridgeSender extends ContractInitializer { className = OmniteLayerZeroBridgeSender.name; static async create(signer: ethers.providers.JsonRpcSigner) { const chainId = normalizeChainId(await signer.getChainId()); if (!chainId) { throw new Error('chainId is not defined'); } const instance = new OmniteLayerZeroBridgeSender( chainId, iface, signer ); instance.address = instance.contractAddress.omniteLayerZeroBridgeSender; instance.initialize(); return instance; } static _newInstance = (chainId: string) => { const selfInstance = new OmniteLayerZeroBridgeSender(chainId, iface); selfInstance.address = selfInstance.contractAddress.omniteLayerZeroBridgeSender; selfInstance.initialize(); return selfInstance; }; deployExternalCollectionOnNewChains = async ( collectionId: string, deploymentParams: Array, params: IOmniteLayerZeroBridgeSender.DeployExternalParamsStruct, value: BigNumber ) => { this.logCall('deployExternalCollectionOnNewChains', { collectionId, deploymentParams, params, value, }); return this.contractInstance.deployExternalCollectionOnNewChains( collectionId, deploymentParams, params, { value } ); }; deployNativeCollection = async ( deploymentParams: Array, params: IOmniteLayerZeroBridgeSender.DeployNativeParamsStruct, value: BigNumber ) => { this.logCall('deployNativeCollection', { deploymentParams, params, value, }); return this.contractInstance.deployNativeCollection( deploymentParams, params, { value, } ); }; populateDeployNativeCollection = async ( deploymentParams: Array, params: IOmniteLayerZeroBridgeSender.DeployNativeParamsStruct, value: BigNumber ) => { this.logCall('deployNativeCollection', { deploymentParams, params, value, }); return this.contractInstance.populateTransaction.deployNativeCollection( deploymentParams, params, { value, } ); }; // deployExternalCollection = async ( // deploymentParams: Array, // params: IOmniteLayerZeroBridgeSender.DeployExternalParamsStruct, // value: BigNumber // ) => { // this.logCall('deployExternalCollection', { // deploymentParams, // params, // value, // }); // return this.contractInstance.deployExternalCollection( // deploymentParams, // params, // { // value, // } // ); // }; // /** // * Mint token on another chain than source one using broker // * // * @param {ChainId} targetChainId // * @param {BigNumber} mintId // * @param {string} tokenURI // * @param {BigNumber} gasAmount // * @param {BigNumber} value // */ // mintOnTargetChain = async ( // targetChainId: ChainId, // mintId: BigNumber, // tokenURI: string, // gasAmount: BigNumber, // value: BigNumber // ) => { // const ownerAddress = await this.signer.getAddress(); // const targetChainConfig = config.getChainConfig(targetChainId); // const targetChainSystemData = config.getSystemData(targetChainId); // this.logCall('mintOnTargetChain', [ // targetChainConfig.layerZeroChainId, // targetChainSystemData.omniteLayerZeroBridgeReceiver, // ownerAddress, // ownerAddress, // mintId, // tokenURI, // gasAmount, // { value }, // ]); // return this.contractInstance.mintOnTargetChain( // targetChainConfig.layerZeroChainId, // targetChainSystemData.omniteLayerZeroBridgeReceiver, // ownerAddress, // ownerAddress, // mintId, // tokenURI, // gasAmount, // { value } // ); // }; // deployCrowdsale = async ( // deploymentParams: IOmniteLayerZeroBridge.DeploymentParamsStruct, // grantRoleParams: IBridge.GrantRoleParamsStruct, // refundAddress: string, // gasAmount: ethers.BigNumberish, // owner: string, // crowdsaleSalt: ethers.utils.BytesLike, // value: BigNumber // ) => { // this.logCall('deployCrowdsale', { // address: this.address, // deploymentParams, // grantRoleParams, // refundAddress, // gasAmount, // owner, // crowdsaleSalt, // }); // return this.contractInstance.deployCrowdsale( // deploymentParams, // grantRoleParams, // refundAddress, // gasAmount, // owner, // crowdsaleSalt, // { value } // ); // }; static deployTokenContractEncode = async ( chainId: string, blueprintName: DeployBlueprintName, collectionId: ethers.utils.BytesLike, ctorParams: ethers.utils.BytesLike, collectionName: string, ownerAddress: string ) => { const instance = OmniteLayerZeroBridgeSender._newInstance(chainId); instance.logCall('deployTokenContractEncode', { chainId, blueprintName, collectionId, ctorParams, collectionName, ownerAddress, }); if (blueprintName === DeployBlueprintName.SimpleNftCrowdsale) { throw new Error('Invalid blueprint'); } else { return instance.contractInstance.deployTokenContractEncode( blueprintName, collectionId, ctorParams, collectionName, ownerAddress ); } }; // static deployCrowdsaleContractEncode = async ( // chainId: string, // blueprintName: DeployBlueprintName, // collectionId: ethers.utils.BytesLike, // ctorParams: ethers.utils.BytesLike, // collectionName: string, // grantRoleParams: IBridge.GrantRoleParamsStruct // ) => { // const instance = OmniteLayerZeroBridgeSender._newInstance(chainId); // instance.logCall('deployCrowdsaleContractEncode', { // chainId, // blueprintName, // collectionId, // ctorParams, // collectionName, // grantRoleParams, // }); // if (blueprintName !== DeployBlueprintName.SimpleNftCrowdsale) { // throw new Error('Invalid blueprint'); // } // return instance.contractInstance.deployCrowdsaleContractEncode( // blueprintName, // collectionId, // ctorParams, // collectionName, // grantRoleParams // ); // }; /** * Returns encoded data of target chain deployment for cost estimation. * * @param {string} chainId * @param {ethers.utils.BytesLike} collectionId * @param {string} ownerAddress * @param {ethers.BigNumberish} mintId * @param {string} tokenUri */ static mintOnTargetChainEncode = async ( chainId: string, collectionId: ethers.utils.BytesLike, ownerAddress: string, mintId: ethers.BigNumberish, tokenUri: string ) => { const instance = OmniteLayerZeroBridgeSender._newInstance(chainId); instance.logCall('mintOnTargetChainEncode', { chainId, collectionId, ownerAddress, mintId, tokenUri, }); return instance.contractInstance.mintOnTargetChainEncode( collectionId, ownerAddress, mintId, tokenUri ); }; }