Liquid Splits
Begin by importing LiquidSplitClient
into your app. If you are using the
SplitsClient
, you can access the liquid split client as well.
import { LiquidSplitClient } from '@0xsplits/splits-sdk'
const liquidSplitClient = new LiquidSplitClient({
chainId,
provider, // ethers provider (optional, required if using any of the contract functions)
signer, // ethers signer (optional, required if using the contract write functions)
includeEnsNames, // boolean, defaults to false. If true, will return ens names for liquid split holders (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 liquidSplitClient = splitsClient.liquidSplits
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, Liquid Split Writes, and Liquid Split Reads.
Subgraph Reads
These functions make it easier to query the subgraph.
getLiquidSplitMetadata
Returns all metadata for a given liquidSplitId
.
Usage
const args = {
liquidSplitId: '0xb5Ce41320F3d486671918733BB3226E3981Db62b',
}
const response = await liquidSplitClient.getLiquidSplitMetadata(args)
Arguments
{
liquidSplitId: string
}
Response
{
type: 'LiquidSplit'
id: string
distributorFeePercent: number
payoutSplitId: string
isFactoryGenerated: boolean
holders: {
address: string
percentAllocation: number
ensName?: string
}[]
}
Liquid Split Writes
These functions make it easier to call Liquid Split functions.
createLiquidSplit
Creates a new Liquid Split contract.
Usage
const args = {
holders: [
{
address: "0x442C01498ED8205bFD9aaB6B8cc5C810Ed070C8f";
percentAllocation: 50.0
},
{
address: "0xc3313847E2c4A506893999f9d53d07cDa961a675";
percentAllocation: 50.0
}
]
distributorFeePercent: 1.0000
owner: "0x442C01498ED8205bFD9aaB6B8cc5C810Ed070C8f",
}
const response = await liquidSplitClient.createLiquidSplit(args)
Arguments
{
holders: {
address: string;
percentAllocation: number # >0 and <100 and up to 1 decimal
}[]
distributorFeePercent: number # <10 and up to 4 decimals
owner?: string # defaults to signer
}
Response
{
liquidSplitId: string
event: Event # CreateLS1155Clone emitted on LiquidSplitFactory
}
distributeToken
Distributes the current token balance for the given liquid split to the current NFT holders
Usage
const args = {
liquidSplitId: "0xb5Ce41320F3d486671918733BB3226E3981Db62b"
token: "0x64d91f12ece7362f91a6f8e7940cd55f05060b92"
distributorAddress: "0x2fa128274cfcf47afd4dc03cd3f2a59af09b6a72"
}
const response = await liquidSplitClient.distributeToken(args)
Arguments
{
liquidSplitId: string
token: string
distributorAddress?: string # defaults to signer
}
Response
{
event: Event # DistributeETH or DistributeERC20 emitted on the Liquid Split contract
}
transferOwnership
Transfer ownership of the given liquid split to the newOwner
. Only callable by
the owner of the liquid split contract.
Usage
const args = {
liquidSplitId: "0xb5Ce41320F3d486671918733BB3226E3981Db62b"
newOwner: "0x2fa128274cfcf47afd4dc03cd3f2a59af09b6a72",
}
const response = await liquidSplitClient.transferOwnership(args)
Arguments
{
liquidSplitId: string
newOwner: string
}
Response
{
event: Event # OwnershipTransferred emitted on the Liquid Split contract
}
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 liquid split function would look like:
const args = {
holders: [
{
address: "0x442C01498ED8205bFD9aaB6B8cc5C810Ed070C8f";
percentAllocation: 50.0
},
{
address: "0xc3313847E2c4A506893999f9d53d07cDa961a675";
percentAllocation: 50.0
}
]
distributorFeePercent: 1.0000
owner: "0x442C01498ED8205bFD9aaB6B8cc5C810Ed070C8f",
}
const gasEstimate = await liquidSplitClient.estimateGas.createLiquidSplit(args)
Liquid Split Reads
These functions make it easier to query the Liquid Split contracts.
getDistributorFee
Returns the distributor fee of a given liquidSplitId
.
Usage
const args = {
liquidSplitId: '0xb5Ce41320F3d486671918733BB3226E3981Db62b',
}
const response = await liquidSplitClient.getDistributorFee(args)
Arguments
{
liquidSplitId: string
}
Response
{
distributorFee: number
}
getPayoutSplit
Returns the payout split of a given liquidSplitId
.
Usage
const args = {
liquidSplitId: '0xb5Ce41320F3d486671918733BB3226E3981Db62b',
}
const response = await liquidSplitClient.getPayoutSplit(args)
Arguments
{
liquidSplitId: string
}
Response
{
payoutSplitId: string
}
getOwner
Returns the owner of a given liquidSplitId
.
Usage
const args = {
liquidSplitId: '0xb5Ce41320F3d486671918733BB3226E3981Db62b',
}
const response = await liquidSplitClient.getOwner(args)
Arguments
{
liquidSplitId: string
}
Response
{
owner: string
}
getUri
Returns the uri of a given liquidSplitId
.
Usage
const args = {
liquidSplitId: '0xb5Ce41320F3d486671918733BB3226E3981Db62b',
}
const response = await liquidSplitClient.getUri(args)
Arguments
{
liquidSplitId: string
}
Response
{
uri: string
}
getScaledPercentBalanceOf
Returns the current percent ownership of a given liquidSplitId
for an
address
.
Usage
const args = {
liquidSplitId: '0xb5Ce41320F3d486671918733BB3226E3981Db62b',
address: '0x2fa128274cfcf47afd4dc03cd3f2a59af09b6a72',
}
const response = await liquidSplitClient.getScaledPercentBalanceOf(args)
Arguments
{
liquidSplitId: string
address: string
}
Response
{
scaledPercentBalance: number
}