Skip to content

Latest commit

 

History

History
525 lines (385 loc) · 13.7 KB

File metadata and controls

525 lines (385 loc) · 13.7 KB

MicroGrantsStrategy

The MicroGrantsStrategy class is a powerful tool for interacting with the MicroGrants contract. It provides methods for reading information from the contract and executing various transactions.

Table of Contents


Initialization

Creating a MicroGrantsStrategy Instance

To start interacting with the MicroGrants contract, create a new instance of MicroGrantsStrategy:

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

const strategy = new MicroGrantsStrategy({
  chain: 1,
});

If you are aware of the poolId, you can load that while creating the instance

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

const strategy = new MicroGrantsStrategy({
  chain: 1,
  poolId: 1, // valid pool Id
});

Setting Pool ID and Strategy Contract

To perform operations that require a specific pool and strategy contract, set the pool ID and strategy contract address:

const poolId = 1;
const strategyAddress = "0xYourStrategyContractAddress";

await strategy.setPoolId(poolId);
strategy.setContract(strategyAddress);

Read-Only Functions

Get Native Token Address

Retrieve the native token address used in the strategy:

const nativeToken = await strategy.getNative();
console.log(`Native Token Address: ${nativeToken}`);

Check Allocator

Check if a specific allocator has already cast their allocation

const allocatorAddress = "0xYourAllocatorAddress";
const isAllocator = await strategy.allocator(allocatorAddress);
console.log(`Is Allocator: ${isAllocator}`);

Check Allocated Status

Check if a specific allocator has already cast their allocation to a specific recipient

const allocatorAddress = "0xYourAllocatorAddress";
const recipientAddress = "0xYourRecipientAddress";
const isAllocated = await strategy.allocated(allocatorAddress, recipientAddress);
console.log(`Is Allocated: ${isAllocated}`);

Get Allocation End Time

Retrieve the end time of the allocation period:

const endTime = await strategy.allocationEndTime();
console.log(`Allocation End Time: ${endTime}`);

Get Allocation Start Time

Retrieve the start time of the allocation period:

const startTime = await strategy.allocationStartTime();
console.log(`Allocation Start Time: ${startTime}`);

Get Approval Threshold

Retrieve the approval threshold for the strategy:

const threshold = await strategy.approvalThreshold();
console.log(`Approval Threshold: ${threshold}`);

Get Allo Instance

Retrieve the associated Allo instance for the strategy:

const alloInstance = await strategy.getAllo();
console.log(`Allo Instance: ${alloInstance}`);

Get Payouts

Retrieve a summary of payouts for a list of recipient addresses:

const recipientIds = ["0xRecipient1", "0xRecipient2"];
const payouts = await strategy.getPayouts(recipientIds);
console.log(`Payouts: ${payouts}`);

Get Pool Amount

Retrieve the total amount available in the pool:

const poolAmount = await strategy.getPoolAmount

();
console.log(`Pool Amount: ${poolAmount}`);

Get Pool ID

Retrieve the current pool ID associated with the strategy:

const currentPoolId = await strategy.getPoolId();
console.log(`Current Pool ID: ${currentPoolId}`);

Get Recipient

Retrieve details of a specific recipient:

const recipientId = "0xYourRecipientId";
const recipientDetails = await strategy.getRecipient(recipientId);
console.log(`Recipient Details: ${recipientDetails}`);

Get Recipient Status

Retrieve the status of a specific recipient:

const recipientId = "0xYourRecipientId";
const recipientStatus = await strategy.getRecipientStatus(recipientId);
console.log(`Recipient Status: ${recipientStatus}`);

Get Strategy ID

Retrieve the unique identifier for the strategy:

const strategyId = await strategy.getStrategyId();
console.log(`Strategy ID: ${strategyId}`);

Check Pool Activity

Check if the pool associated with the strategy is active:

const isActive = await strategy.isPoolActive();
console.log(`Is Pool Active: ${isActive}`);

Check Allocator Validity

Check if a specific allocator address is valid for the strategy:

const allocatorAddress = "0xYourAllocatorAddress";
const isValid = await strategy.isValidAllocator(allocatorAddress);
console.log(`Is Allocator Valid: ${isValid}`);

Get Recipient Allocations

Retrieve the allocations of a recipient based on their status:

const recipientId = "0xYourRecipientId";
const status = 1; // Example status, replace with the actual status value
const allocations = await strategy.recipientAllocations(recipientId, status);
console.log(`Recipient Allocations: ${allocations}`);

Get Max Requested Amount

Retrieve the maximum requested amount allowed by the strategy:

const maxRequestedAmount = await strategy.maxRequestedAmount();
console.log(`Max Requested Amount: ${maxRequestedAmount}`);

Check Use Registry Anchor

Check if the strategy uses a registry anchor:

const useRegistryAnchor = await strategy.useRegistryAnchor();
console.log(`Use Registry Anchor: ${useRegistryAnchor}`);

HATS MicroGrants

This set of functions are available if the MicroGrants uses a hats micro grant strategy

Get HATS Contract Address

Retrieve the address of the HATS contract associated with the strategy:

const hatsAddress = await strategy.getHatsAddress();
console.log(`HATS Contract Address: ${hatsAddress}`);

Get HAT ID

Retrieve the hatId used by the strategy:

const hatId = await strategy.getHatId();
console.log(`HAT ID: ${hatId}`);

Governance MicroGrants

This set of functions are available if the MicroGrants uses a governance token micro grant strategy

Get Governance Contract Address

Retrieve the address of the governance contract associated with the strategy:

const govAddress = await strategy.getGovAddress();
console.log(`Governance Contract Address: ${govAddress}`);

Get Snapshot Reference

Retrieve the snapshot reference used by the strategy:

const snapshotReference = await strategy.getSnapshotReference();
console.log(`Snapshot Reference: ${snapshotReference}`);

Get Minimum Vote Power

Retrieve the minimum vote power required by the strategy:

const minVotePower = await strategy.getMinimumVotePower();
console.log(`Minimum Vote Power: ${minVotePower}`);

Get Strategy Contract ID

Retrieve the unique identifier for the strategy contract:

const strategyContract = "0xYourStrategyContractAddress";
const strategyContractId = await strategy.getStrategyContractId(strategyContract);
console.log(`Strategy Contract ID: ${strategyContractId}`);

Write Functions

Deploy Parameters

Generate deployment parameters for deploying a new strategy:

import { StrategyType } from "@allo-team/allo-v2-sdk/dist/strategies/MicroGrantsStrategy/types";

const strategyType = StrategyType.Gov; // Specify the strategy type
const deployParams = strategy.getDeployParams(strategyType);

// Client could be from ethers, viem, etc.
const hash = await walletClient!.deployContract({
  abi: deployParams.abi,
  bytecode: deployParams.bytecode as `0x${string}`,
  args: [],
});

Batch Allocation Data

Generate transaction data for batch allocation to multiple pools:

const allocations = [
  { recipientId: "0xRecipient1", status: 1 },
  { recipientId: "0xRecipient2", status: 1 },
];

const txData = strategy.getBatchAllocationData(allocations);

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

Allocation Data

Generate transaction data for allocating funds to a specific recipient:

const recipientId = "0xYourRecipientId";
const status = 1; // Example status, replace with the actual status value

const txData = strategy.getAllocationData(recipientId, status);

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

Register Recipient Data

Generate transaction data for registering a new recipient:

const registerData = {
  registryAnchor: "0xYourRegistryAnchor", // Optional
  recipientAddress: "0xRecipientAddress",
  requestedAmount: BigInt(1),
  metadata: {
    protocol: BigInt(0),
    pointer: "0xYourPointer",
  },
};

const txData = strategy.getRegisterRecipientData(registerData);

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

Batch Register Recipient Data

Generate transaction data for batch registering multiple recipients:

const batchRegisterData = [
  {
    registryAnchor: "0xYourRegistryAnchor1", // Optional
    recipientAddress: "0xRecipientAddress1",
    requestedAmount: BigInt(1),
    metadata: {
      protocol:  BigInt(1),
      pointer: "0xYourPointer1",
    },
  },
  {
    registryAnchor: "0xYourRegistryAnchor2", // Optional
    recipientAddress: "0xRecipientAddress2",
    requestedAmount:  BigInt(2),
    metadata: {
      protocol: BigInt(1),
      pointer: "0xYourPointer2",
    },
  },
];

const txData = strategy.getBatchRegisterRecipientData(batchRegisterData);

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

Increase Max Requested Amount Data

Generate transaction data for increasing the maximum requested amount:

const amount = 200;

const txData = strategy.getIncreasemaxRequestedAmountData(amount);

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

Set Allocator Data

Generate transaction data for setting allocator data:

const allocatorData = {
  allocatorAddress: "0xYourAllocatorAddress",
  flag: true,
};

const txData = strategy.getSetAllocatorData(allocatorData);

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

Batch Set Allocator Data

Generate transaction data for batch setting allocator data:

const batchSetAllocatorData = [
  {
    allocatorAddress: "0xYourAllocatorAddress1",
    flag: true,
  },
  {
    allocatorAddress: "0xYourAllocatorAddress2",
    flag: false,
  },
];

const txData = strategy.getBatchSetAllocatorData(batchSetAllocatorData);

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

Update Pool Timestamps Data

Generate transaction data for updating pool timestamps:

const allocationStartTime = 1642320000; // Example timestamp, replace with the actual value
const allocationEndTime = 1642410000; // Example timestamp, replace with the actual value

const txData = strategy.getUpdatePoolTimestampsData(allocationStartTime, allocationEndTime);

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