This sdk contains collection of functions to interact with IchiVault's smart contract.
- Installation
- Usage
- Vault Functions
approveDepositToken()
deposit()
depositNativeToken()
approveVaultToken()
isVaultTokenApproved()
withdraw()
withdrawWithSlippage()
withdrawNativeToken()
isDepositTokenApproved()
isTokenAllowed()
getMaxDepositAmount()
getUserBalance()
getUserAmounts()
getTotalSupply()
getTotalAmounts()
getFeesCollected()
getFeesCollectedInfo()
getAverageDepositTokenRatios()
getLpApr()
getLpPriceChange()
getIchiVaultInfo()
getVaultsByTokens()
- Vault Functions
Install with
yarn add @ichidao/ichi-vaults-sdk
or
npm install @ichidao/ichi-vaults-sdk
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
tokenIdx | 0 | 1 | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
amount | string | number | undefined | false |
overrides | Overrides | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { approveDepositToken, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const accountAddress = "0xaaaa...aaaaaa"
const amount = 100
const dex = SupportedDex.UniswapV3
const txnDetails = await approveDepositToken(
accountAddress,
0, // token idx can be 0 or 1
vaultAddress,
web3Provider,
dex,
amount // (optional)
);
await txnDetails.wait();
// can now deposit token0
// ...
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
amount0 | string | number | - | true |
amount1 | string | number | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
percentSlippage | number | 1 | false |
overrides | Overrides | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { deposit, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const accountAddress = "0xaaaa...aaaaaa"
const amount0 = 100
const amount1 = 0
const txnDetails = await deposit(
accountAddress,
amount0, // can be 0 when only depositing amount1
amount1, // can be 0 when only depositing amount0
vaultAddress,
web3Provider,
dex,
1 // acceptable slippage (percents)
)
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
amount0 | string | number | - | true |
amount1 | string | number | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
percentSlippage | number | 1 | false |
overrides | Overrides | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { deposit, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const accountAddress = "0xaaaa...aaaaaa"
const amount0 = 100
const amount1 = 0
const txnDetails = await depositNativeToken(
accountAddress,
amount0, // can be 0 when only depositing amount1
amount1, // can be 0 when only depositing amount0
vaultAddress,
web3Provider,
dex,
1 // acceptable slippage (percents)
)
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
shares | string | number | undefined | false |
overrides | Overrides | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { approveDepositToken, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const accountAddress = "0xaaaa...aaaaaa"
const amount = 100
const dex = SupportedDex.UniswapV3
const txnDetails = await approveVaultToken(
accountAddress,
vaultAddress,
web3Provider,
dex,
amount // (optional)
);
await txnDetails.wait();
// can now deposit token0
// ...
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
shares | string | number, | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
import { Web3Provider } from '@ethersproject/providers';
import { isDepositTokenApproved, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const accountAddress = "0xaaaa...aaaaaa"
const amount = 100
const dex = SupportedDex.UniswapV3
const isToken0Approved: boolean = await isDepositTokenApproved(
accountAddress,
amount,
vaultAddress,
web3Provider,
dex
)
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
shares | string | number | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
overrides | Overrides | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { getUserBalance, withdraw, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const accountAddress = "0xaaaa...aaaaaa"
const totalUserShares: string = await getUserBalance(
accountAddress,
vaultAddress,
web3Provider
dex,
)
let shares = Number(totalUserShare) * 0.5 // 50% of user deshare balance
const txnDetails = await withdraw(
accountAddress,
shares,
vaultAddress,
web3Provider,
dex
)
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
shares | string | number | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
percentSlippage | number | 1 | false |
overrides | Overrides | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { getUserBalance, withdraw, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const accountAddress = "0xaaaa...aaaaaa"
const totalUserShares: string = await getUserBalance(
accountAddress,
vaultAddress,
web3Provider
dex,
)
let shares = Number(totalUserShare) * 0.5 // 50% of user deshare balance
const txnDetails = await withdraw(
accountAddress,
shares,
vaultAddress,
web3Provider,
dex
)
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
shares | string | number | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
percentSlippage | number | 1 | false |
overrides | Overrides | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { getUserBalance, withdraw, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const accountAddress = "0xaaaa...aaaaaa"
const totalUserShares: string = await getUserBalance(
accountAddress,
vaultAddress,
web3Provider
dex,
)
let shares = Number(totalUserShare) * 0.5 // 50% of user deshare balance
const txnDetails = await withdraw(
accountAddress,
shares,
vaultAddress,
web3Provider,
dex
)
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
tokenIdx | 0 | 1 | - | true |
amount | string | number, | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
import { Web3Provider } from '@ethersproject/providers';
import { isDepositTokenApproved, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const accountAddress = "0xaaaa...aaaaaa"
const amount = 100
const dex = SupportedDex.UniswapV3
const isToken0Approved: boolean = await isDepositTokenApproved(
accountAddress,
0, // token idx can be 0 or 1
amount,
vaultAddress,
web3Provider,
dex
)
param | type | default | required |
---|---|---|---|
tokenIdx | 0 | 1 | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
import { Web3Provider } from '@ethersproject/providers';
import { isTokenAllowed, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const isAllowed = await isTokenAllowed(
0, // token idx can be 0 or 1
vaultAddress,
web3Provider,
dex
)
param | type | default | required |
---|---|---|---|
tokenIdx | 0 | 1 | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
import { Web3Provider } from '@ethersproject/providers';
import { getMaxDepositAmount, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const maxAmount = await getMaxDepositAmount(
0, // token idx can be 0 or 1
vaultAddress,
web3Provider,
dex
)
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
raw | true | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { getUserBalance, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const accountAddress = "0xaaaa...aaaaaa"
const shares: string = await getUserBalance(
accountAddress,
vaultAddress,
web3Provider
dex
)
// - or -
const sharesBN: BigNumber = await getUserBalance(
accountAddress,
vaultAddress,
web3Provider
dex,
true
)
param | type | default | required |
---|---|---|---|
accountAddress | string | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
raw | true | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { getUserAmounts, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const accountAddress = "0xaaaa...aaaaaa"
const amounts: [string, string] & {amount0: string, amount1: string} = await getUserAmounts(
accountAddress,
vaultAddress,
web3Provider
dex,
)
// - or -
const amountsBN: [BigNumber, BigNumber] & {amount0: BigNumber, amount1: BigNumber} = await getUserAmounts(
accountAddress,
vaultAddress,
web3Provider
dex,
true
)
param | type | default | required |
---|---|---|---|
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
raw | true | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { getTotalSupply, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const shares: string = await getTotalSupply(
accountAddress,
vaultAddress,
web3Provider
dex,
)
// - or -
const sharesBN: BigNumber = await getTotalSupply(
accountAddress,
vaultAddress,
web3Provider
dex,
true
)
param | type | default | required |
---|---|---|---|
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
raw | true | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { getTotalAmounts, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3
const accountAddress = "0xaaaa...aaaaaa"
const amounts: [string, string] & {total0: string, total1: string} = await getTotalAmounts(
accountAddress,
vaultAddress,
web3Provider
dex,
)
// - or -
const amountsBN: [BigNumber, BigNumber] & {total0: BigNumber, total1: BigNumber} = await getTotalAmounts(
accountAddress,
vaultAddress,
web3Provider
dex,
true
)
param | type | default | required |
---|---|---|---|
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
rawOrDays | true or number | undefined | false |
days | number | undefined | false |
import { Web3Provider } from '@ethersproject/providers';
import { getFeesCollected, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132";
const dex = SupportedDex.UniswapV3;
const days = 7;
const amounts: [string, string] & {total0: string, total1: string} = await getFeesCollected(
vaultAddress,
web3Provider
dex,
)
// - or -
const amountsBN: [BigNumber, BigNumber] & {total0: BigNumber, total1: BigNumber} = await getFeesCollected(
vaultAddress,
web3Provider
dex,
true
)
// - or -
const amounts: [string, string] & {total0: string, total1: string} = await getFeesCollected(
vaultAddress,
web3Provider
dex,
days
)
// - or -
const amountsBN: [BigNumber, BigNumber] & {total0: BigNumber, total1: BigNumber} = await getFeesCollected(
vaultAddress,
web3Provider
dex,
true,
days
)
param | type | default | required |
---|---|---|---|
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
forDays | number[] | undefined | false |
If forDays is not specified, returns FeesInfo for time periods of 1, 7, and 30 days.
import { Web3Provider } from '@ethersproject/providers';
import { getFeesCollectedInfo, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132";
const dex = SupportedDex.UniswapV3;
const days = [2, 5, 14, 60];
const feesInfo: FeesInfo[] = await getFeesCollectedInfo(
vaultAddress,
web3Provider
dex,
)
// - or -
const feesInfo: FeesInfo[] = await getFeesCollectedInfo(
vaultAddress,
web3Provider
dex,
days,
)
param | type | default | required |
---|---|---|---|
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
timeIntervals | number[] | [1, 7, 30] | false |
import { Web3Provider } from '@ethersproject/providers';
import { getFeesCollectedInfo, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132";
const dex = SupportedDex.UniswapV3;
const days = [2, 5, 14, 60];
const averageDtr: AverageDepositTokenRatio[] = await getAverageDepositTokenRatios(
vaultAddress,
web3Provider
dex,
)
// - or -
const averageDtr: AverageDepositTokenRatio[] = await getAverageDepositTokenRatios(
vaultAddress,
web3Provider
dex,
days,
)
param | type | default | required |
---|---|---|---|
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
timeIntervals | number[] | [1, 7, 30] | false |
import { Web3Provider } from '@ethersproject/providers';
import { getLpApr, SupportedDex, VaultApr } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132";
const dex = SupportedDex.UniswapV3;
const days = [2, 5, 14, 60];
const averageDtr: VaultApr[] = await getLpApr(
vaultAddress,
web3Provider
dex,
)
// - or -
const averageDtr: VaultApr[] = await getLpApr(
vaultAddress,
web3Provider
dex,
days,
)
param | type | default | required |
---|---|---|---|
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | true |
dex | SupportedDex | - | true |
timeIntervals | number[] | [1, 7, 30] | false |
import { Web3Provider } from '@ethersproject/providers';
import { getFeesCollectedInfo, SupportedDex } from '@ichidao/ichi-vaults-sdk';
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const vaultAddress = "0x3ac9...a5f132";
const dex = SupportedDex.UniswapV3;
const days = [2, 5, 14, 60];
const averageDtr: AverageDepositTokenRatio[] = await getAverageDepositTokenRatios(
vaultAddress,
web3Provider
dex,
)
// - or -
const averageDtr: AverageDepositTokenRatio[] = await getAverageDepositTokenRatios(
vaultAddress,
web3Provider
dex,
days,
)
param | type | default | required |
---|---|---|---|
chain | SupportedChain | - | true |
dex | SupportedDex | - | true |
vaultAddress | string | - | true |
jsonProvider | JsonRpcProvider | - | false |
import { Web3Provider } from '@ethersproject/providers';
import { getIchiVaultInfo, SupportedDex, SupportedChain, IchiVault } from '@ichidao/ichi-vaults-sdk';
const vaultAddress = "0x3ac9...a5f132"
const dex = SupportedDex.UniswapV3;
const chain = SupportedChain.Polygon;
const vaultInfo = await getIchiVaultInfo(chain, dex, vaultAddress);
if (vaultInfo) {
const addressTokenA = vaultInfo.tokenA;
}
param | type | default | required |
---|---|---|---|
chain | SupportedChain | - | true |
dex | SupportedDex | - | true |
depositTokenAddress | string | - | true |
pairedTokenAddress | string | - | true |
import { Web3Provider } from '@ethersproject/providers';
import { getVaultsByTokens, SupportedDex, SupportedChain, IchiVault } from '@ichidao/ichi-vaults-sdk';
const depositToken = "0x1b...bfd6"
const pairedToken = "0x11...c4d6"
const dex = SupportedDex.UniswapV3;
const chain = SupportedChain.Polygon;
const vault = await getVaultsByTokens(chain, dex, depositToken, pairedToken)
if (!vault) {
console.log("Couldn't find vaults with these parameters")
} else {
const vaultAddress = vault.id;
}
enum SupportedChainId {
arbitrum = 42161,
base = 8453,
blast = 81457,
blast_sepolia_testnet = 168587773,
bsc = 56,
celo = 42220,
eon = 7332,
evmos = 9001,
fantom = 250,
hedera_testnet = 296,
linea = 59144,
mainnet = 1,
mantle = 5000,
polygon = 137,
polygon_zkevm = 1101,
zksync_era = 324,
zksync_era_testnet = 280,
}
enum SupportedDex {
Ascent = 'Ascent',
Blueprint = 'Blueprint',
Cleo = 'Cleo',
Equalizer = 'Equalizer',
Fenix = 'Fenix',
Forge = 'Forge',
Horiza = 'Horiza',
Lynex = 'Lynex',
Pancakeswap = 'PancakeSwap',
Quickswap = 'QuickSwap',
Ramses = 'Ramses',
Retro = 'Retro',
SaucerSwap = 'SaucerSwap',
Sushiswap = 'SushiSwap',
Thena = 'Thena',
UniswapV3 = 'Uniswap V3',
Velocore = 'Velocore',
}
interface IchiVault {
id: string; // vault address
tokenA: string; // token0 address
tokenB: string; // token1 address
allowTokenA: boolean;
allowTokenB: boolean;
}
type FeesInfo = {
timePeriod: number; // in days
feeAmount0: string; // in token0
feeAmount1: string; // in token1
pctAPR: number; // yearly APR based on the timePeriod
}
type AverageDepositTokenRatio = {
timePeriod: number; // in days
percent: number;
}
type VaultApr = {
timeInterval: number; // in days
apr: number; // percent
}
type PriceChange = {
timeInterval: number; // in days
priceChange: number;
}