UNPKG

allo-monad-ray

Version:

Monad version of Allo v2 SDK

174 lines (173 loc) 5.1 kB
import { encodeFunctionData, extractChain, getContract, } from "viem"; import { create } from "../Client/Client"; import { abi, getAddress } from "./registry.config"; import { supportedChains } from "../chains.config"; export class Registry { constructor({ chain, rpc }) { const usedChain = extractChain({ chains: supportedChains, id: chain, }); this.addr = getAddress(usedChain); this.client = create(usedChain, rpc); this.contract = getContract({ address: this.addr, abi: abi, client: { public: this.client, } }); } address() { return this.addr; } // Read only Functions async getAlloOwner() { const owner = await this.contract.read.ALLO_OWNER(); return owner; } async getDefaultAdminRole() { const admin = await this.contract.read.DEFAULT_ADMIN_ROLE(); return admin; } async getNative() { const native = await this.contract.read.NATIVE(); return native; } async getAnchorToProfileId(anchor) { const profileId = await this.contract.read.anchorToProfileId([anchor]); return profileId; } async getProfileByAnchor(anchor) { const profile = await this.contract.read.getProfileByAnchor([anchor]); return profile; } async getProfileById(profileId) { const profile = await this.contract.read.getProfileById([profileId]); return profile; } async getRoleAdmin(role) { const admin = await this.contract.read.getRoleAdmin([role]); return admin; } async hasRole({ role, account }) { const hasRole = await this.contract.read.hasRole([role, account]); return hasRole; } async isMemberOfProfile({ profileId, account, }) { const isMember = await this.contract.read.isMemberOfProfile([ profileId, account, ]); return isMember; } async isOwnerOfProfile({ profileId, account, }) { const isOwner = await this.contract.read.isOwnerOfProfile([ profileId, account, ]); return isOwner; } async isOwnerOrMemberOfProfile({ profileId, account, }) { const isOwnerOrMember = await this.contract.read.isOwnerOrMemberOfProfile([ profileId, account, ]); return isOwnerOrMember; } async profileIdToPendingOwner(profileId) { const pendingOwner = await this.contract.read.profileIdToPendingOwner([ profileId, ]); return pendingOwner; } async profilesById(profileId) { const profile = await this.contract.read.profilesById([profileId]); return profile; } // Write functions createProfile({ nonce, name, metadata, owner, members, }) { const data = encodeFunctionData({ abi: abi, functionName: "createProfile", args: [nonce, name, metadata, owner, members], }); return { to: this.addr, data: data, value: "0", }; } acceptProfileOwnership(profileId) { const data = encodeFunctionData({ abi: abi, functionName: "acceptProfileOwnership", args: [profileId], }); return { to: this.addr, data: data, value: "0", }; } addMembers({ profileId, members }) { const data = encodeFunctionData({ abi: abi, functionName: "addMembers", args: [profileId, members], }); return { to: this.addr, data: data, value: "0", }; } removeMembers({ profileId, members }) { const data = encodeFunctionData({ abi: abi, functionName: "removeMembers", args: [profileId, members], }); return { to: this.addr, data: data, value: "0", }; } updateProfileMetadata({ profileId, metadata, }) { const data = encodeFunctionData({ abi: abi, functionName: "updateProfileMetadata", args: [profileId, metadata], }); return { to: this.addr, data: data, value: "0", }; } updateProfileName({ profileId, name, }) { const data = encodeFunctionData({ abi: abi, functionName: "updateProfileName", args: [profileId, name], }); return { to: this.addr, data: data, value: "0", }; } updateProfilePendingOwner({ profileId, account, }) { const data = encodeFunctionData({ abi: abi, functionName: "updateProfilePendingOwner", args: [profileId, account], }); return { to: this.addr, data: data, value: "0", }; } }