Hello, we are glad to introduce Tulip Protocol's Platform SDK to fellow Solana Developers!
You can use this SDK to easily integrate Tulip Protocol's Vaults into your product. Cheers 🍻
npm install --save @tulip-protocol/platform-sdk
Open a margin position
openMarginPosition({ connection: Connection, wallet: SolanaWalletAdapter | Object, symbol: String, coinBorrowAmount: Number, pcBorrowAmount: Number, baseTokenAmount: Number, quoteTokenAmount: Number, obligationIdx?: Number, onSendTransactions?: Function })
connection: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectsymbol: String
- Asset symbol of leverage farmcoinBorrowAmount: Number
- Coin borrow amountpcBorrowAmount: Number
- PC borrow amountbaseTokenAmount: Number
- Base token amountquoteTokenAmount: Number
- Quote token amountobligationIdx?: Number
- [Optional] Obligation index for the position stateonSendTransactions: Function
- [Optional] Web3 function to execute multiple transactions
Promise<transaction: Transaction>
import { openMarginPosition } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
// Inputs taken by Tulip SDK's `depositToVault`
const connection = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
const openMarginPositionTulipProtocol = ({
symbol,
coinBorrowAmount,
pcBorrowAmount,
baseTokenAmount,
quoteTokenAmount
}) => {
return openMarginPosition({
connection,
wallet,
symbol,
coinBorrowAmount,
pcBorrowAmount,
baseTokenAmount,
quoteTokenAmount
});
};
Add collateral to a margin position
addCollateralPosition({ connection: Connection, wallet: SolanaWalletAdapter | Object, symbol: String, reserveName: String, coinBorrowAmount: Number, pcBorrowAmount: Number, baseTokenAmount: Number, quoteTokenAmount: Number, obligationIdx: Number, onSendTransactions?: Function })
connection: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectsymbol: String
- Asset symbol of leverage farmreserveName: String
- Reserve name of the farm. For single borrow send symbol of borrow asset else sendDEFAULT
for dual borrow.coinBorrowAmount: Number
- Coin borrow amountpcBorrowAmount: Number
- PC borrow amountbaseTokenAmount: Number
- Base token amountquoteTokenAmount: Number
- Quote token amountobligationIdx: Number
- Obligation index for the position stateonSendTransactions: Function
- [Optional] Web3 function to execute multiple transactions
Promise<transaction: Transaction>
import { addCollateralPosition } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
// Inputs taken by Tulip SDK's `depositToVault`
const connection = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
const addCollateralPositionTulipProtocol = ({
symbol,
obligationIdx,
reserveName,
baseTokenAmount,
quoteTokenAmount,
coinBorrowAmount,
pcBorrowAmount
}) => {
return addCollateralPosition({
connection,
wallet,
symbol,
obligationIdx,
reserveName,
baseTokenAmount,
quoteTokenAmount,
coinBorrowAmount,
pcBorrowAmount
});
};
Close off the margin position
closeMarginPosition({ connection: Connection, wallet: SolanaWalletAdapter | Object, symbol: String, obligationIdx: Number, selectedOption: Number, partialClose: Number, onSendTransactions?: Function })
connection: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectsymbol: String
- Asset symbol of leverage farmobligationIdx: Number
- Obligation index for the position stateselectedOption: Number
- Use one of the value fromCLOSE_POSITION_OPTIONS
optionspartialClose: Number
- Percentage value to partial close a position from 0 - 100%. Defaults to 100.onSendTransactions: Function
- [Optional] Web3 function to execute multiple transactions
CLOSE_POSITION_OPTIONS = { MINIMIZE_TRADING: 10, CONVERT_TO_COIN: 11, CONVERT_TO_PC: 12 };
Promise<transaction: Transaction>
import { closeMarginPosition, CLOSE_POSITION_OPTIONS } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
// Inputs taken by Tulip SDK's `depositToVault`
const connection = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
const closeMarginPositionTulipProtocol = ({
symbol,
obligationIdx,
selectedOption: CLOSE_POSITION_OPTIONS.MINIMIZE_TRADING,
partialClose: 100
}) => {
return closeMarginPosition({
wallet,
connection,
symbol,
obligationIdx,
selectedOption,
partialClose
});
};
Deposit to Raydium Vault
depositToVault(conn: Connection, wallet: SolanaWalletAdapter | Object, mintAddress: String, authorityTokenAccount: PublicKey, amount: String | Number)
conn: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectmintAddress: String
- Mint Address of the VaultauthorityTokenAccount: PublicKey
- Token account address of the user corresponding to the vaultamount: String | Number
- Amount to deposit
Promise<transaction: Transaction>
import { depositToVault } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
import { PublicKey } from '@solana/web3.js';
// Create a util to send transactions
import { sendTransaction } from 'utils/web3';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
const TOKEN_PROGRAM_ID = new PublicKey(
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
// Token Accounts in the user's wallet
const tokenAccounts = {};
// Set token accounts
(() => {
conn
.getParsedTokenAccountsByOwner(
wallet.publicKey,
{
programId: TOKEN_PROGRAM_ID,
},
commitment
)
.then((parsedTokenAccounts) => {
parsedTokenAccounts.value.forEach((tokenAccountInfo) => {
// `tokenAccountAddress` is same as `authorityTokenAccount`
// (used in input to `depositToVault`)
const tokenAccountAddress = tokenAccountInfo.pubkey.toBase58(),
parsedInfo = tokenAccountInfo.account.data.parsed.info,
mintAddress = parsedInfo.mint,
balance = parsedInfo.tokenAmount.amount;
tokenAccounts[mintAddress] = {
tokenAccountAddress,
balance,
};
});
});
})();
// Inputs taken by Tulip SDK's `depositToVault`
const conn = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
// For example, this is the `mintAddress` of TULIP-USDC
const farmMintAddress = '2doeZGLJyACtaG9DCUyqMLtswesfje1hjNA11hMdj6YU';
const depositToTulipProtocol = async () => {
// For example, let's hardcode the `amount` to '0.01'
const amountToDeposit = '0.01';
const authorityTokenAccount = tokenAccounts[farmMintAddress].tokenAccountAddress;
const transaction = await depositToVault(
conn,
wallet,
farmMintAddress,
authorityTokenAccount,
amountToDeposit
);
// Let's assume this is how the function signature of
// your custom `sendTransaction` looks like
return sendTransaction(conn, wallet, transaction);
};
Withdraw from Raydium Vault
withdrawFromVault(conn: Connection, wallet: SolanaWalletAdapter | Object, mintAddress: String, authorityTokenAccount: PublicKey, amount: String | Number)
conn: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectmintAddress: String
- Mint Address of the VaultauthorityTokenAccount: PublicKey
- Token account address of the user corresponding to the vaultamount?: String | Number
- [Optional] Amount to withdraw (Use this if you don't have userShares)userShares?: Number
- [Optional] User shares to withdraw (Use this if you don't have amount)
Promise<transaction: Transaction>
import { withdrawFromVault } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
import { PublicKey } from '@solana/web3.js';
// Create a util to send transactions
import { sendTransaction } from 'utils/web3';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
const TOKEN_PROGRAM_ID = new PublicKey(
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
// Token Accounts in the user's wallet
const tokenAccounts = {};
// Set token accounts
(() => {
conn
.getParsedTokenAccountsByOwner(
wallet.publicKey,
{
programId: TOKEN_PROGRAM_ID,
},
commitment
)
.then((parsedTokenAccounts) => {
parsedTokenAccounts.value.forEach((tokenAccountInfo) => {
// `tokenAccountAddress` is same as `authorityTokenAccount`
// (used in input to `withdrawFromVault`)
const tokenAccountAddress = tokenAccountInfo.pubkey.toBase58(),
parsedInfo = tokenAccountInfo.account.data.parsed.info,
mintAddress = parsedInfo.mint,
balance = parsedInfo.tokenAmount.amount;
tokenAccounts[mintAddress] = {
tokenAccountAddress,
balance,
};
});
});
})();
// Inputs taken by Tulip SDK's `withdrawFromVault`
const conn = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
// For example, this is the `mintAddress` of TULIP-USDC
const farmMintAddress = '2doeZGLJyACtaG9DCUyqMLtswesfje1hjNA11hMdj6YU';
const withdrawFromTulipProtocol = async () => {
// For example, let's hardcode the `amount` to '0.01'
const amountToWithdraw = '0.01';
// You can also use userShares directly instead of providing an amount,
// and we suggest using it when you want to withdraw all the shares from a vault
const userShares = 0;
const authorityTokenAccount = tokenAccounts[farmMintAddress].tokenAccountAddress;
const transaction = await withdrawFromVault(
conn,
wallet,
farmMintAddress,
authorityTokenAccount,
amountToWithdraw,
userShares
);
// Let's assume this is how the function signature of
// your custom `sendTransaction` looks like
return sendTransaction(conn, wallet, transaction);
};
Get Balance for a user in a Vault
getBalanceForVault(conn: Connection, wallet: SolanaWalletAdapter | Object, mintAddress: String)
conn: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectmintAddress: String
- Mint Address of the Vault
Promise<{ lastDepositTime: BigNumber, depositedAmount: BigNumber, rewardsSinceLastDeposit: BigNumber }>
import { getBalanceForVault } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
// Inputs taken by Tulip SDK's `getBalanceForVault`
const conn = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
// For example, this is the `mintAddress` of TULIP-USDC
const farmMintAddress = '2doeZGLJyACtaG9DCUyqMLtswesfje1hjNA11hMdj6YU';
const getUserBalanceForTulipProtocol = async () => {
const {
lastDepositTime,
depositedAmount,
rewardsSinceLastDeposit
} = await getBalanceForVault(conn, wallet, farmMintAddress);
return {
lastDepositTime,
depositedAmount,
rewardsSinceLastDeposit
};
};
Get APYs for lending reserves.
The function accepts a single object as an argument with the following properties.
getAPYForLendingReserves({
connection: Connection,
reserves: Array<String>
})
connection: Connection
- web3 Connection objectreserves: Array<String>
- Symbol or mint address of the reserves for example [USDC
,TULIP
] or [EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
]
Promise<reserveData: Array<Object>>
import { getAPYForLendingReserves } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
// Inputs taken by Tulip SDK's `getAPYForLendingReserves`
const connection = new Connection(endpoint, { commitment });
const getTulipProtocolLendingReserveAPYs = async (reserves) => {
const reserveData = await getAPYForLendingReserves({
connection,
reserves
});
// Map over it if needed to take out just the `name` and `lendAPY` property
return reserveData.map((reserve) => {
return {
name: reserve.name,
lendAPY: reserve.lendAPY
};
});
};
Get user's balance for lending reserves.
The function accepts a single object as an argument with the following properties.
getBalanceForLendingReserves({
connection: Connection,
wallet: SolanaWalletAdapter | Object,
reserves: Array<String>
})
connection: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectreserves: Array<String>
- Symbol or mint address of the reserves for example [USDC
,TULIP
] or [EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
]
Promise<reserveData: Array<Object>>
import { getBalanceForLendingReserves } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
// You can have any wallet adapter you may want, we're taking Phantom as an example here.
// More info can be found here: https://github.com/solana-labs/wallet-adapter#wallets
import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
// Inputs taken by Tulip SDK's `getBalanceForLendingReserves`
const connection = new Connection(endpoint, { commitment });
const wallet = new PhantomWalletAdapter();
const getTulipProtocolLendingReserveBalances = async (reserves) => {
const reserveData = await getBalanceForLendingReserves({
connection,
wallet,
reserves
});
// Map over it if needed to take out just the `name` and `deposited` property
return reserveData.map((reserve) => {
return {
name: reserve.name,
deposited: reserve.deposited
};
});
};
Deposit to a Lending Reserve.
The function accepts a single object as an argument with the following properties.
depositToLendingReserve({
connection: Connection,
wallet: SolanaWalletAdapter | Object,
reserve: String,
amount: String | Number,
authorityTokenAccount?: PublicKey
})
connection: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectreserve: String
- Symbol or mint address of the reserve for exampleUSDC
orEPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
amount: String | Number
- Amount to depositauthorityTokenAccount?: PublicKey
- [Optional] Token account address of the user corresponding to the reserve, if not provided then will automatically be fetched by the SDK
Promise<transaction: Transaction>
import { depositLendingReserve } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
// You can have any wallet adapter you may want, we're taking Phantom as an example here.
// More info can be found here: https://github.com/solana-labs/wallet-adapter#wallets
import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom';
// Create a util to send transactions
import { sendTransaction } from 'utils/web3';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
// Inputs taken by Tulip SDK's `depositLendingReserve`
const connection = new Connection(endpoint, { commitment });
const wallet = new PhantomWalletAdapter();
/**
* Now you need the lending reserve for which you'd want to deposit funds.
* Refer: https://tulip.garden/lend to find the lending reserve symbol you want.
* The reserve's symbol or mint address can be provided as the value.
* For example, this is the symbol of `TULIP`
*/
const reserve = 'TULIP';
const depositToTulipProtocol = async () => {
// Let's take the hardcoded amount for the example
const amount = '145';
const transaction = await depositLendingReserve({
connection,
wallet,
reserve,
amount
});
// Let's assume this is how the function signature of
// your custom `sendTransaction` looks like
return sendTransaction(connection, wallet, transaction);
};
Withdraw from a Lending Reserve.
The function accepts a single object as an argument with the following properties.
withdrawLendingReserve({
connection: Connection,
wallet: SolanaWalletAdapter | Object,
reserve: String,
amount: String | Number,
authorityTokenAccount?: PublicKey
})
connection: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectreserve: String
- Symbol or mint address of the reserve for exampleUSDC
orEPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
amount: String | Number
- Amount to withdrawauthorityTokenAccount?: PublicKey
- [Optional] Token account address of the user corresponding to the reserve, if not provided then will automatically be fetched by the SDK
Promise<transaction: Transaction>
import { withdrawLendingReserve } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
// You can have any wallet adapter you may want, we're taking Phantom as an example here.
// More info can be found here: https://github.com/solana-labs/wallet-adapter#wallets
import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom';
// Create a util to send transactions
import { sendTransaction } from 'utils/web3';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
// Inputs taken by Tulip SDK's `depositLendingReserve`
const connection = new Connection(endpoint, { commitment });
const wallet = new PhantomWalletAdapter();
/**
* Now you need the lending reserve for which you'd want to withdraw funds from.
* Refer: https://tulip.garden/lend to find the lending reserve symbol you want.
* The reserve's symbol or mint address can be provided as the value.
* For example, this is the symbol of `TULIP`
*/
const reserve = 'TULIP';
const withdrawFromTulipProtocol = async () => {
// Let's take the hardcoded amount for the example
const amount = '145';
const transaction = await withdrawLendingReserve({
connection,
wallet,
reserve,
amount
});
// Let's assume this is how the function signature of
// your custom `sendTransaction` looks like
return sendTransaction(connection, wallet, transaction);
};
Deposit to a Lending Reserve.
We recommend using the depositLendingReserve
function instead, since it has been updated
with automatic authorityToken finding and can accept a reserve symbol etc.
depositToLendingReserve(conn: Connection, wallet: SolanaWalletAdapter | Object, mintAddress: String, authorityTokenAccount: PublicKey, amount: String | Number)
conn: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectmintAddress: String
- Mint Address of the VaultauthorityTokenAccount: PublicKey
- Token account address of the user corresponding to the reserveamount: String | Number
- Amount to deposit
Promise<transaction: Transaction>
import { depositToLendingReserve } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
import { PublicKey } from '@solana/web3.js';
// Create a util to send transactions
import { sendTransaction } from 'utils/web3';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
const TOKEN_PROGRAM_ID = new PublicKey(
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
// Token Accounts in the user's wallet
const tokenAccounts = {};
// Set token accounts
(() => {
conn
.getParsedTokenAccountsByOwner(
wallet.publicKey,
{
programId: TOKEN_PROGRAM_ID,
},
commitment
)
.then((parsedTokenAccounts) => {
parsedTokenAccounts.value.forEach((tokenAccountInfo) => {
// `tokenAccountAddress` is same as `authorityTokenAccount`
// (used in input to `depositToLendingReserve`)
const tokenAccountAddress = tokenAccountInfo.pubkey.toBase58(),
parsedInfo = tokenAccountInfo.account.data.parsed.info,
mintAddress = parsedInfo.mint,
balance = parsedInfo.tokenAmount.amount;
tokenAccounts[mintAddress] = {
tokenAccountAddress,
balance,
};
});
});
})();
// Inputs taken by Tulip SDK's `depositToLendingReserve`
const conn = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
// For example, this is the `mintAddress` of TULIP
const farmMintAddress = 'TuLipcqtGVXP9XR62wM8WWCm6a9vhLs7T1uoWBk6FDs';
const depositToTulipProtocol = async () => {
// For example, let's hardcode the `amount` to '0.01'
const amountToDeposit = '0.01';
const authorityTokenAccount = tokenAccounts[farmMintAddress].tokenAccountAddress;
const transaction = await depositToLendingReserve(
conn,
wallet,
farmMintAddress,
authorityTokenAccount,
amountToDeposit
);
// Let's assume this is how the function signature of
// your custom `sendTransaction` looks like
return sendTransaction(conn, wallet, transaction);
};
Withdraw from a Lending Reserve
We recommend using the withdrawLendingReserve
function instead, since it has been updated
with automatic authorityToken finding and can accept a reserve symbol etc.
withdrawFromLendingReserve(conn: Connection, wallet: SolanaWalletAdapter | Object, mintAddress: String, authorityTokenAccount: PublicKey, amount: String | Number)
conn: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectmintAddress: String
- Mint Address of the VaultauthorityTokenAccount: PublicKey
- Token account address of the user corresponding to the vaultamount: String | Number
- Amount to deposit
Promise<transaction: Transaction>
import { withdrawFromLendingReserve } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
import { PublicKey } from '@solana/web3.js';
// Create a util to send transactions
import { sendTransaction } from 'utils/web3';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
const TOKEN_PROGRAM_ID = new PublicKey(
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
// Token Accounts in the user's wallet
const tokenAccounts = {};
// Set token accounts
(() => {
conn
.getParsedTokenAccountsByOwner(
wallet.publicKey,
{
programId: TOKEN_PROGRAM_ID,
},
commitment
)
.then((parsedTokenAccounts) => {
parsedTokenAccounts.value.forEach((tokenAccountInfo) => {
// `tokenAccountAddress` is same as `authorityTokenAccount`
// (used in input to `withdrawFromLendingReserve`)
const tokenAccountAddress = tokenAccountInfo.pubkey.toBase58(),
parsedInfo = tokenAccountInfo.account.data.parsed.info,
mintAddress = parsedInfo.mint,
balance = parsedInfo.tokenAmount.amount;
tokenAccounts[mintAddress] = {
tokenAccountAddress,
balance,
};
});
});
})();
// Inputs taken by Tulip SDK's `withdrawFromLendingReserve`
const conn = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
// For example, this is the `mintAddress` of TULIP
const farmMintAddress = 'TuLipcqtGVXP9XR62wM8WWCm6a9vhLs7T1uoWBk6FDs';
const withdrawFromTulipProtocol = async () => {
// For example, let's hardcode the `amount` to '0.01'
const amountToWithdraw = '0.01';
const authorityTokenAccount = tokenAccounts[farmMintAddress].tokenAccountAddress;
const transaction = await withdrawFromLendingReserve(
conn,
wallet,
farmMintAddress,
authorityTokenAccount,
amountToWithdraw
);
// Let's assume this is how the function signature of
// your custom `sendTransaction` looks like
return sendTransaction(conn, wallet, transaction);
};
Fetch the total deposited balance of V2 autovaults
getBalancesForAutoVaults(conn: Connection, wallet: SolanaWalletAdapter | Object, query: Object)
conn: Connection
- web3 Connection objectwallet: SolanaWalletAdapter | Object
- Wallet objectquery
- Query object [OPTIONAL]query.platforms
- Could be any of ['raydium', 'saber', 'orca', 'atrix']query.vaults
- Any supported vault symbol
Promise<object: Object>
import { FARM_PLATFORMS, VAULTS, getBalancesForAutoVaults } from '@tulip-protocol/platform-sdk';
import { Connection } from '@solana/web3.js';
import SolanaWalletAdapter from '@project-serum/sol-wallet-adapter';
import { PublicKey } from '@solana/web3.js';
// Create a util to send transactions
import { sendTransaction } from 'utils/web3';
// Boilerplate setup for web3 connection
const endpoint = 'https://solana-api.projectserum.com';
const commitment = 'confirmed';
const TOKEN_PROGRAM_ID = new PublicKey(
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
// Inputs taken by Tulip SDK's `withdrawFromLendingReserve`
const conn = new Connection(endpoint, { commitment });
const wallet = new SolanaWalletAdapter('', endpoint);
const getBalanceForV2Vaults = async () => {
// Let's say we want to fetch all the balances for all raydium and saber vaults
// and we only need the balance for ORCA-USDC separately, then we can create the following query:
const query = {
platforms: [FARM_PLATFORMS.RAYDIUM, FARM_PLATFORMS.SABER],
vaults: [VAULTS.ORCA.ATLAS_USDC]
};
const vaults = await getBalancesForAutoVaults(connection, getStore('WalletStore').wallet, query);
return vaults;
};
``