Vesting

Vesting

Begin by importing VestingClient into your app. If you are using the SplitsClient, you can access the vesting client as well.

import { VestingClient } from '@0xsplits/splits-sdk'
 
const vestingClient = new VestingClient({
  chainId,
  publicClient, // viem public client (optional, required if using any of the contract functions)
  walletClient, // viem wallet client (optional, required if using any contract write functions. must have an account already attached)
  includeEnsNames, // boolean, defaults to false. If true, will return ens names for any vesting beneficiary (only for mainnet)
  // If you want to return ens names on chains other than mainnet, you can pass in a mainnet public client
  // here. Be aware though that the ens name may not necessarily resolve to the proper address on the
  // other chain for non EOAs (e.g. Gnosis Safe's)
  ensPublicClient, // viem public client (optional)
})

OR

import { SplitsClient } from '@0xsplits/splits-sdk'
 
const splitsClient = new SplitsClient({
  chainId,
  publicClient,
  walletClient,
  includeEnsNames,
  ensPublicClient,
})
 
const vestingClient = splitsClient.vesting

Now you're ready to use any of the functions. All Arguments and Responses for these functions are objects. This will make it easier for us to release updates to the SDK without breaking existing implementations.

The SDK comprises 3 different types of functions: Subgraph Reads, Vesting Writes, and Vesting Reads.

Subgraph Reads

These functions make it easier to query the subgraph.

getVestingMetadata

Returns all metadata for a given vestingModuleAddress.

Usage

const args = {
  vestingModuleAddress: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
}
 
const response = await vestingClient.getVestingMetadata(args)

Arguments

{
  vestingModuleAddress: string
}

Response

{
  type: 'VestingModule'
  address: string
  beneficiary: {
    address: string
    ensName?: string
  }
  vestingPeriod: number
  streams?: {
    streamId: number
    startTime: number
    totalAmount: number
    releasedAmount: number
    token: {
      address: string
      symbol?: string
      decimals?: number
    }
  }[]
}

Vesting Writes

These functions make it easier to call Vesting functions.

createVestingModule

Creates a new Vesting contract.

Usage

const args = {
  beneficiary: '0x8904D1fBfc9c88792aaaE8f452ac57E1Ba2130fC',
  vestingPeriodSeconds: 31536000,
}
 
const response = await vestingClient.createVestingModule(args)

Arguments

{
  beneficiary: string
  vestingPeriodSeconds: number
}

Response

{
  vestingModuleAddress: string
  event: Log # CreateVestingModule emitted on VestingModuleFactory
}

startVest

Starts vesting streams for the given tokens.

Usage

const args = {
  vestingModuleAddress: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
  tokens: [
    '0x0000000000000000000000000000000000000000',
    '0x64d91f12ece7362f91a6f8e7940cd55f05060b92',
  ],
}
 
const response = await vestingClient.startVest(args)

Arguments

{
  vestingModuleAddress: string
  tokens: string[]
}

Response

{
  events: Log[] # CreateVestingStream emitted on the Vesting contract (one event per token)
}

releaseVestedFunds

Releases vested funds to the beneficiary for the given stream id's.

Usage

const args = {
  vestingModuleAddress: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
  streamIds: ['0', '1'],
}
 
const response = await vestingClient.releaseVestedFunds(args)

Arguments

{
  vestingModuleAddress: string
  streamIds: string[]
}

Response

{
  events: Log[] # ReleaseFromVestingStream emitted on the Vesting contract (one event per stream)
}

Gas Estimation

The client has a gas estimation feature that can be used with any of the above write functions. Just call the function off of the estimateGas property. Estimating the gas for the create vesting module function would look like:

const args = {
  beneficiary: '0x8904D1fBfc9c88792aaaE8f452ac57E1Ba2130fC',
  vestingPeriodSeconds: 31536000,
}
 
const gasEstimate = await vestingClient.estimateGas.createVestingModule(args)

CallData

The client has a call data feature that can be used with any of the above write functions. Just call the function off of the callData property. Generating call data for the create vesting module function would look like:

const args = {
  beneficiary: '0x8904D1fBfc9c88792aaaE8f452ac57E1Ba2130fC',
  vestingPeriodSeconds: 31536000,
}
 
const callData = await vestingClient.callData.createVestingModule(args)

Vesting Reads

These functions make it easier to query the Vesting contracts.

predictVestingModuleAddress

Returns the vesting module address, and whether it exists yet, for the given beneficiary and vesting period.

Usage

const args = {
  beneficiary: '0x8904D1fBfc9c88792aaaE8f452ac57E1Ba2130fC',
  vestingPeriodSeconds: 31536000,
}
 
const response = await vestingClient.predictVestingModuleAddress(args)

Arguments

{
  beneficiary: string
  vestingPeriodSeconds: number
}

Response

{
  address: string
  exists: boolean
}

getBeneficiary

Returns the beneficiary for a given vestingModuleAddress.

Usage

const args = {
  vestingModuleAddress: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
}
 
const response = await vestingClient.getBeneficiary(args)

Arguments

{
  vestingModuleAddress: string
}

Response

{
  beneficiary: string
}

getVestingPeriod

Returns the vesting period for a given vestingModuleAddress.

Usage

const args = {
  vestingModuleAddress: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
}
 
const response = await vestingClient.getVestingPeriod(args)

Arguments

{
  vestingModuleAddress: string
}

Response

{
  vestingPeriod: bigint
}

getVestedAmount

Returns the vested amount for a given vestingModuleAddress and streamId.

Usage

const args = {
  vestingModuleAddress: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
  streamId: 0,
}
 
const response = await vestingClient.getVestedAmount(args)

Arguments

{
  vestingModuleAddress: string
  streamId: string
}

Response

{
  amount: bigint
}

getVestedAndUnreleasedAmount

Returns the vested and unreleased amount for a given vestingModuleAddress and streamId.

Usage

const args = {
  vestingModuleAddress: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
  streamId: 0,
}
 
const response = await vestingClient.getVestedAndUnreleasedAmount(args)

Arguments

{
  vestingModuleAddress: string
  streamId: string
}

Response

{
  amount: bigint
}