UNPKG

allo-monad-ray

Version:

Monad version of Allo v2 SDK

75 lines (74 loc) 2.31 kB
import { encodeFunctionData, extractChain, getContract, } from "viem"; import { supportedChains } from "../../chains.config"; import { create } from "../../Client/Client"; import { abi as DGLabi, getAddress as getAddressDGL, } from "./strategyFactory.DGL.config"; import { abi as DVMDTabi, getAddress as getAddressDVMDT, } from "./strategyFactory.DVMDT.config"; export class StrategyFactory { constructor({ chain, factoryType, address, rpc, }) { const usedChain = extractChain({ chains: supportedChains, id: chain, }); this.factoryType = factoryType; this.client = create(usedChain, rpc); this.chainId = chain; if (address) this.setFactoryAddress(address); } getAbi() { switch (this.factoryType) { case "DGL": return DGLabi; case "DVMDT": return DVMDTabi; default: throw new Error("Invalid factory type"); } } getAddress(chainId) { switch (this.factoryType) { case "DGL": return getAddressDGL(chainId); case "DVMDT": return getAddressDVMDT(chainId); default: throw new Error("Invalid factory type"); } } setFactoryAddress(address) { if (address) { this.contract = getContract({ address: address, abi: this.getAbi(), client: { public: this.client, }, }); this.factory = address; } } getCreateStrategyData() { const encodedData = encodeFunctionData({ abi: this.getAbi(), functionName: "createStrategy", args: [], }); return { to: this.factory || this.getAddress(this.chainId), data: encodedData, value: "0", }; } getCreateStrategyDataByChainId(chainId) { const encodedData = encodeFunctionData({ abi: this.getAbi(), functionName: "createStrategy", args: [], }); return { to: this.getAddress(chainId), data: encodedData, value: "0", }; } }