Skip to content

Latest commit

 

History

History
411 lines (302 loc) · 10.6 KB

README.md

File metadata and controls

411 lines (302 loc) · 10.6 KB

Registry Table of Contents


Registry

The Registry class provides a set of functions for interacting with the Registry contract's view and write functions. This README provides examples and explanations for using these functions.

Initialization

Before using the functions provided by the Registry module, you need to create an instance of the Registry class. Here's how you can create a Registry instance:

Creating a Registry Instance

To create a new Registry instance, you need to provide the chain information. In this example, we're using the 5 chain information.

import { Registry } from "@allo-team/allo-v2-sdk/";

const registry = new Registry({ chain: 5 });

This registry instance can then be used to call various read and transactional functions provided by the Registry module. Refer to the sections above for detailed examples on how to use these functions. Remember to replace placeholder values with actual values according to your requirements.


Read Functions

Get Allo Owner

To retrieve the Allo Owner:

const alloOwner: string = await registry.getAlloOwner();
console.log(alloOwner);

Get Default Admin Role

To get the Default Admin Role:

const defaultAdminRole: string = await registry.getDefaultAdminRole();
console.log(defaultAdminRole);

Get Native

To obtain the Native:

const native: string = await registry.getNative();
console.log(native);

Get Anchor To Profile Id

To retrieve the Profile ID associated with an Anchor:

const anchor = "your_anchor_value_here";
const profileId: string = await registry.getAnchorToProfileId(anchor);
console.log(profileId);

Get Profile By Anchor

To fetch a Profile using an Anchor:

import { Profile } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const anchor = "your_anchor_value_here";
const profile: Profile = await registry.getProfileByAnchor(anchor);
console.log(profile);

Get Profile By ID

To retrieve a Profile using its ID:

import { Profile } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const profileId = "your_profile_id_here";
const profile: Profile = await registry.getProfileById(profileId);
console.log(profile);

Get Role Admin

To get the admin of a specified role:

const role = "your_role_here";
const admin: string = await registry.getRoleAdmin(role);
console.log(admin);

Check Role Membership

To check if an account has a specific role:

import { HasRoleArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const hasRoleArgs: HasRoleArgs = {
  role: "your_role_here",
  account: "account_address_here",
};
const hasRole: boolean = await registry.hasRole(hasRoleArgs);
console.log(hasRole);

Check Membership in Profile

To check if an account is a member of a profile:

import { ProfileAndAddressArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const profileAndAddressArgs: ProfileAndAddressArgs = {
  profileId: "your_profile_id_here",
  account: "account_address_here",
};
const isMember: boolean = await registry.isMemberOfProfile(
  profileAndAddressArgs,
);
console.log(isMember);

Check Ownership of Profile

To check if an account is the owner of a profile:

import { ProfileAndAddressArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const profileAndAddressArgs: ProfileAndAddressArgs = {
  profileId: "your_profile_id_here",
  account: "account_address_here",
};
const isOwner: boolean = await registry.isOwnerOfProfile(profileAndAddressArgs);
console.log(isOwner);

Check Ownership or Membership in Profile

To check if an account is either the owner or a member of a profile:

import { ProfileAndAddressArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const profileAndAddressArgs: ProfileAndAddressArgs = {
  profileId: "your_profile_id_here",
  account: "account_address_here",
};
const isOwnerOrMember: boolean = await registry.isOwnerOrMemberOfProfile(
  profileAndAddressArgs,
);
console.log(isOwnerOrMember);

Get Profile ID to Pending Owner

To get the pending owner of a profile:

const profileId = "your_profile_id_here";
const pendingOwner: string = await registry.getProfileIdToPendingOwner(
  profileId,
);
console.log(pendingOwner);

Get Profile Details by ID

To get profile details by ID:

import { Profile } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const profileId = "your_profile_id_here";
const profile: Profile = await registry.getProfilesById(profileId);
console.log(profile);

Write Functions

Creating a Profile

To create a new profile using the createProfile function:

import { CreateProfileArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";
import { TransactionData } from "@allo-team/allo-v2-sdk/dist/Common/types";

const createProfileArgs: CreateProfileArgs = {
  nonce: 3,
  name: "Module Test 1",
  metadata: {
    protocol: BigInt(1),
    pointer: "bafybeia4khbew3r2mkflyn7nzlvfzcb3qpfeftz5ivpzfwn77ollj47gqi",
  },
  owner: "0xE7eB5D2b5b188777df902e89c54570E7Ef4F59CE",
  members: [
    "0x5cdb35fADB8262A3f88863254c870c2e6A848CcA",
    "0xE7eB5D2b5b188777df902e89c54570E7Ef4F59CE",
  ],
};

const txData: TransactionData = registry.createProfile(createProfileArgs);

// Client could be from ethers, viem, etc..
const hash = await client.sendTransaction({
  data: txData.data,
  to: txData.to,
  account,
  value: BigInt(txData.value),
});

console.log(`Transaction hash: ${hash}`);

Accepting Profile Ownership

To accept ownership of a profile using the acceptProfileOwnership function:

const profileId = "your_profile_id_here";

const txData: TransactionData = registry.acceptProfileOwnership(profileId);

// Client could be from ethers, viem, etc..
const hash = await client.sendTransaction({
  data: txData.data,
  account,
  to: txData.to,
  value: BigInt(txData.value),
});

console.log(`Transaction hash: ${hash}`);

Adding Members to a Profile

To add members to a profile using the addMembers function:

import { MemberArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const memberArgs: MemberArgs = {
  profileId: "your_profile_id_here",
  members: [
    "0xMemberAddress1",
    "0xMemberAddress2",
    // Add more member addresses if needed
  ],
};

const txData: TransactionData = registry.addMembers(memberArgs);

// Client could be from ethers, viem, etc..
const hash = await client.sendTransaction({
  data: txData.data,
  account,
  to: txData.to,
  value: BigInt(txData.value),
});

console.log(`Transaction hash: ${hash}`);

Removing Members from a Profile

To remove members from a profile using the removeMembers function:

import { MemberArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const memberArgs: MemberArgs = {
  profileId: "your_profile_id_here",
  members: [
    "0xMemberAddress1",
    "0xMemberAddress2",
    // Add more member addresses if needed
  ],
};

const txData: TransactionData = registry.removeMembers(memberArgs);

// Client could be from ethers, viem, etc..
const hash = await client.sendTransaction({
  data: txData.data,
  account,
  to: txData.to,
  value: BigInt(txData.value),
});

console.log(`Transaction hash: ${hash}`);

Updating Profile Metadata

To update profile metadata using the updateProfileMetadata function:

import { ProfileMetadataArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const profileMetadataArgs: ProfileMetadataArgs = {
  profileId: "your_profile_id_here",
  metadata: {
    protocol: 2,
    pointer: "bafybeia4khbew3r2mkflyn7nzlvfzcb3qpfeftz5ivpzfwn77ollj47gqi",
  },
};

const txData: TransactionData =
  registry.updateProfileMetadata(profileMetadataArgs);

// Client could be from ethers, viem, etc..
const hash = await client.sendTransaction({
  data: txData.data,
  account,
  to: txData.to,
  value: BigInt(txData.value),
});

console.log(`Transaction hash: ${hash}`);

Updating Profile Name

To update profile name using the updateProfileName function:

import { ProfileNameArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const profileNameArgs: ProfileNameArgs = {
  profileId: "your_profile_id_here",
  name: "New Profile Name",
};

const txData: TransactionData = registry.updateProfileName(profileNameArgs);

// Client could be from ethers, viem, etc..
const hash = await client.sendTransaction({
  data: txData.data,
  account,
  to: txData.to,
  value: BigInt(txData.value),
});

console.log(`Transaction hash: ${hash}`);

Updating Profile Pending Owner

To update the pending owner of a profile using the updateProfilePendingOwner function:

import { ProfileAndAddressArgs } from "@allo-team/allo-v2-sdk/dist/Registry/types";

const profilePendingOwnerArgs: ProfileAndAddressArgs = {
  profileId: "your_profile_id_here",
  account: "new_pending_owner_address_here",
};

const txData: TransactionData = registry.updateProfilePendingOwner(
  profilePendingOwnerArgs,
);

// Client could be from ethers, viem, etc..
const hash = await client.sendTransaction({
  data: txData.data,
  account,
  to: txData.to,
  value: BigInt(txData.value),
});

console.log(`Transaction hash: ${hash}`);