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.
- MicroGrantsStrategy
- Table of Contents
- Initialization
- Read-Only Functions
- Get Native Token Address
- Check Allocator
- Check Allocated Status
- Get Allocation End Time
- Get Allocation Start Time
- Get Approval Threshold
- Get Allo Instance
- Get Payouts
- Get Pool Amount
- Get Pool ID
- Get Recipient
- Get Recipient Status
- Get Strategy ID
- Check Pool Activity
- Check Allocator Validity
- Get Recipient Allocations
- Get Max Requested Amount
- Check Use Registry Anchor
- HATS MicroGrants
- Governance MicroGrants
- Get Strategy Contract ID
- Write Functions
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
});
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);
Retrieve the native token address used in the strategy:
const nativeToken = await strategy.getNative();
console.log(`Native Token Address: ${nativeToken}`);
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 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}`);
Retrieve the end time of the allocation period:
const endTime = await strategy.allocationEndTime();
console.log(`Allocation End Time: ${endTime}`);
Retrieve the start time of the allocation period:
const startTime = await strategy.allocationStartTime();
console.log(`Allocation Start Time: ${startTime}`);
Retrieve the approval threshold for the strategy:
const threshold = await strategy.approvalThreshold();
console.log(`Approval Threshold: ${threshold}`);
Retrieve the associated Allo instance for the strategy:
const alloInstance = await strategy.getAllo();
console.log(`Allo Instance: ${alloInstance}`);
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}`);
Retrieve the total amount available in the pool:
const poolAmount = await strategy.getPoolAmount
();
console.log(`Pool Amount: ${poolAmount}`);
Retrieve the current pool ID associated with the strategy:
const currentPoolId = await strategy.getPoolId();
console.log(`Current Pool ID: ${currentPoolId}`);
Retrieve details of a specific recipient:
const recipientId = "0xYourRecipientId";
const recipientDetails = await strategy.getRecipient(recipientId);
console.log(`Recipient Details: ${recipientDetails}`);
Retrieve the status of a specific recipient:
const recipientId = "0xYourRecipientId";
const recipientStatus = await strategy.getRecipientStatus(recipientId);
console.log(`Recipient Status: ${recipientStatus}`);
Retrieve the unique identifier for the strategy:
const strategyId = await strategy.getStrategyId();
console.log(`Strategy ID: ${strategyId}`);
Check if the pool associated with the strategy is active:
const isActive = await strategy.isPoolActive();
console.log(`Is Pool Active: ${isActive}`);
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}`);
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}`);
Retrieve the maximum requested amount allowed by the strategy:
const maxRequestedAmount = await strategy.maxRequestedAmount();
console.log(`Max Requested Amount: ${maxRequestedAmount}`);
Check if the strategy uses a registry anchor:
const useRegistryAnchor = await strategy.useRegistryAnchor();
console.log(`Use Registry Anchor: ${useRegistryAnchor}`);
This set of functions are available if the MicroGrants uses a hats micro grant strategy
Retrieve the address of the HATS contract associated with the strategy:
const hatsAddress = await strategy.getHatsAddress();
console.log(`HATS Contract Address: ${hatsAddress}`);
Retrieve the hatId used by the strategy:
const hatId = await strategy.getHatId();
console.log(`HAT ID: ${hatId}`);
This set of functions are available if the MicroGrants uses a governance token micro grant strategy
Retrieve the address of the governance contract associated with the strategy:
const govAddress = await strategy.getGovAddress();
console.log(`Governance Contract Address: ${govAddress}`);
Retrieve the snapshot reference used by the strategy:
const snapshotReference = await strategy.getSnapshotReference();
console.log(`Snapshot Reference: ${snapshotReference}`);
Retrieve the minimum vote power required by the strategy:
const minVotePower = await strategy.getMinimumVotePower();
console.log(`Minimum Vote Power: ${minVotePower}`);
Retrieve the unique identifier for the strategy contract:
const strategyContract = "0xYourStrategyContractAddress";
const strategyContractId = await strategy.getStrategyContractId(strategyContract);
console.log(`Strategy Contract ID: ${strategyContractId}`);
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: [],
});
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),
});
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),
});
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),
});
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),
});
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),
});
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),
});
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),
});
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),
});