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,
  provider, // ethers provider (optional, required if using any of the SplitMain functions)
  signer, // ethers signer (optional, required if using the SplitMain write functions)
  includeEnsNames, // boolean, defaults to false. If true, will return ens names for vesting beneficiaries (only for mainnet)
  // If you want to return ens names on chains other than mainnet, you can pass in a mainnet provider
  // 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)
  ensProvider, // ethers provider (optional)
})OR
import { SplitsClient } from '@0xsplits/splits-sdk'
 
const splitsClient = new SplitsClient({
  chainId,
  provider,
  signer,
  includeEnsNames,
  ensProvider,
})
 
const vestingClient = splitsClient.vestingNow 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 vestingModuleId.
Usage
const args = {
  vestingModuleId: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
}
 
const response = await vestingClient.getVestingMetadata(args)Arguments
{
  vestingModuleId: string
}Response
{
  type: 'VestingModule'
  id: 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
{
  vestingModuleId: string
  event: Event # CreateVestingModule emitted on VestingModuleFactory
}startVest
Starts vesting streams for the given tokens.
Usage
const args = {
  vestingModuleId: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
  tokens: [
    '0x0000000000000000000000000000000000000000',
    '0x64d91f12ece7362f91a6f8e7940cd55f05060b92',
  ],
}
 
const response = await vestingClient.startVest(args)Arguments
{
  vestingModuleId: string
  tokens: string[]
}Response
{
  events: Event[] # 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 = {
  vestingModuleId: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
  streamIds: ['0', '1'],
}
 
const response = await vestingClient.releaseVestedFunds(args)Arguments
{
  vestingModuleId: string
  streamIds: string[]
}Response
{
  events: Event[] # 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)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 vestingModuleId.
Usage
const args = {
  vestingModuleId: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
}
 
const response = await vestingClient.getBeneficiary(args)Arguments
{
  vestingModuleId: string
}Response
{
  beneficiary: string
}getVestingPeriod
Returns the vesting period for a given vestingModuleId.
Usage
const args = {
  vestingModuleId: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
}
 
const response = await vestingClient.getVestingPeriod(args)Arguments
{
  vestingModuleId: string
}Response
{
  vestingPeriod: BigNumber
}getVestedAmount
Returns the vested amount for a given vestingModuleId and streamId.
Usage
const args = {
  vestingModuleId: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
  streamId: 0,
}
 
const response = await vestingClient.getVestedAmount(args)Arguments
{
  vestingModuleId: string
  streamId: string
}Response
{
  amount: BigNumber
}getVestedAndUnreleasedAmount
Returns the vested and unreleased amount for a given vestingModuleId and
streamId.
Usage
const args = {
  vestingModuleId: '0x0aab2E1E7D7bb0CAb1c0A49A59DCEfe241aA2ba1',
  streamId: 0,
}
 
const response = await vestingClient.getVestedAndUnreleasedAmount(args)Arguments
{
  vestingModuleId: string
  streamId: string
}Response
{
  amount: BigNumber
}