allo-monad-ray
Version:
Monad version of Allo v2 SDK
178 lines (177 loc) • 5.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Registry = void 0;
const viem_1 = require("viem");
const Client_1 = require("../Client/Client");
const registry_config_1 = require("./registry.config");
const chains_config_1 = require("../chains.config");
class Registry {
constructor({ chain, rpc }) {
const usedChain = (0, viem_1.extractChain)({
chains: chains_config_1.supportedChains,
id: chain,
});
this.addr = (0, registry_config_1.getAddress)(usedChain);
this.client = (0, Client_1.create)(usedChain, rpc);
this.contract = (0, viem_1.getContract)({
address: this.addr,
abi: registry_config_1.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 = (0, viem_1.encodeFunctionData)({
abi: registry_config_1.abi,
functionName: "createProfile",
args: [nonce, name, metadata, owner, members],
});
return {
to: this.addr,
data: data,
value: "0",
};
}
acceptProfileOwnership(profileId) {
const data = (0, viem_1.encodeFunctionData)({
abi: registry_config_1.abi,
functionName: "acceptProfileOwnership",
args: [profileId],
});
return {
to: this.addr,
data: data,
value: "0",
};
}
addMembers({ profileId, members }) {
const data = (0, viem_1.encodeFunctionData)({
abi: registry_config_1.abi,
functionName: "addMembers",
args: [profileId, members],
});
return {
to: this.addr,
data: data,
value: "0",
};
}
removeMembers({ profileId, members }) {
const data = (0, viem_1.encodeFunctionData)({
abi: registry_config_1.abi,
functionName: "removeMembers",
args: [profileId, members],
});
return {
to: this.addr,
data: data,
value: "0",
};
}
updateProfileMetadata({ profileId, metadata, }) {
const data = (0, viem_1.encodeFunctionData)({
abi: registry_config_1.abi,
functionName: "updateProfileMetadata",
args: [profileId, metadata],
});
return {
to: this.addr,
data: data,
value: "0",
};
}
updateProfileName({ profileId, name, }) {
const data = (0, viem_1.encodeFunctionData)({
abi: registry_config_1.abi,
functionName: "updateProfileName",
args: [profileId, name],
});
return {
to: this.addr,
data: data,
value: "0",
};
}
updateProfilePendingOwner({ profileId, account, }) {
const data = (0, viem_1.encodeFunctionData)({
abi: registry_config_1.abi,
functionName: "updateProfilePendingOwner",
args: [profileId, account],
});
return {
to: this.addr,
data: data,
value: "0",
};
}
}
exports.Registry = Registry;