Integration & Direct Contract Interactions

This section describes how best to integrate with the contracts directly, for governance & smart contract direct interactions.

There are three typical ways you may want to integrate or interact with the smart contracts;

  1. dApp integrations using Web3.js | Ethers.js | Viem (Wagmi) or other SDK & Library

  2. Governance Contract interactions

  3. Smart Contract interactions & Modules

Creating Vesting Plans

For creating vesting plans, there are two ways to interact with the smart contract directly - either using the createPlan function itself, or by using the BatchPlanner contract, which will mint many plans in a single transaction.

dApp Integrations

Governance Contract (Governor Bravo) Interaction

We assume that you will be leveraging a Governor Bravo style contract, with the following function:

function propose(
  address[] memory targets, 
  uint[] memory values, 
  string[] memory signatures, 
  bytes[] memory calldatas, 
  string memory description) returns (uint)
  • targets: The ordered list of target addresses for calls to be made during proposal execution. This array must be the same length as all other array parameters in this function.

  • calldatas: The ordered list of data to be passed to each individual function call during proposal execution. This array must be the same length as all other array parameters in this function.

You can find more information here about the Governor Bravo Smart Contract. There is no need to send a value in the propose function, but we will address the targets and the calldatas elements.

target will be the BatchPlanner address: 0x3466EB008EDD8d5052446293D1a7D212cb65C646

calldatas To generate this, you can use web3 library (ethersjs or web3js), and create the array of plans and parameters, and ABI encode the plans, converting to bytes. Here's an example script you can run to convert multiple plans into encoded data.

const { ethers,  BigNumber } = require("ethers")

let planA = {
    recipient: '0x0CCFAb8d9DBE788808EeCCC3bf0295278E307777',
    amount: BigNumber.from(10).pow(18), // 10 tokens
    start: '1696161600', // Oct 1st
    cliff: '1698840000', // Nov 1st
    rate: '1000',
}

let planB = {
    recipient: '0xDD06fEee44433A0B9eEEEE0Ed777721F88885555',
    amount: BigNumber.from(10).pow(18).mul(2), // 10 tokens
    start: '1696161600', // Oct 1st
    cliff: '1698840000', // Nov 1st
    rate: '2000',
}


let locker = '0x1bb64AF7FE05fc69c740609267d2AbE3e119Ef82' // voting vesting address
let token = '0xE13FB676E9bdd7AFda91495eC4e027FC63212FC3' //input token address here
let period = '1' // use 1 for streaming version
let dao = '0xDA0B6bDA01eEd76667D7b4FDA0615657C6b9aDA0' // doa contract address, or address that will be responsible for revoking plans

async function encodeData(vestingAddress, tokenAddress, plans, period, daoAddress) {
    let totalAmount = BigNumber.from(0);
    for (let i = 0; i < plans.length; i++) {
        totalAmount.add(plans[i].amount);
    }
    const abiCoder = new ethers.utils.AbiCoder();
    const encodedData = abiCoder.encode(
        ['address', 'address', 'uint256', "tuple(address recipient, uint256 amount, uint256 start, uint256 cliff, uint256 rate)[]", 'uint256', 'address', 'bool', 'uint8'],
        [vestingAddress, tokenAddress, totalAmount, plans, period, daoAddress, true, '4']
    )
    
    const hexString = encodedData.slice(2);
    const bytes = Buffer.from(hexString, 'hex')
    console.log(bytes);
    return bytes;
}

encodeData(locker, token, [planA, planB], period, dao);

With this information, you can now create a proposal and input the other information required by the DAO in its governance system into the propose function.

Smart Contract Interaction via Contract Interface

This section will help you understand how to create a middleware solidity file that incorporates the BatchPlanner interface so that you can effectively create vesting plans from a smart contract directly. You will need to import the below file, and then your contract should call the function with its inputs directly.

pragma solidity 0.8.19;

interface IBatchPlanner {
  struct Plan {
    address recipient;
    uint256 amount;
    uint256 start;
    uint256 cliff;
    uint256 rate;
  }
  

  function batchVestingPlans(
    address locker,
    address token,
    uint256 totalAmount,
    Plan[] calldata plans,
    uint256 period,
    address vestingAdmin,
    bool adminTransferOBO,
    uint8 mintType
  ) external;
}

Last updated