Using Typescript-Client
Mercurial Vault SDK is a typescript library that allows you to interact with Mercurial's dynamic vaults.
The typescript client provides an easy way to integrate and interact with our Mercurial Dynamic Vaults. With the integration, your users can deposit and withdraw tokens from the vaults and receive the yield generated by the lending pools. You can also display key information regarding the vaults like total LP supply, total liquidity and APY etc. You can follow the simple guide below to get started.
Alternatively, you can also refer to and git clone the demo repos (react or node) to get started. The example demo includes all functionality and information we display on our own site.
Resources
NPM: https://www.npmjs.com/package/@mercurial-finance/vault-sdk
SDK: https://github.com/mercurial-finance/vault-sdk
Demo: https://vault-sdk-demo.vercel.app/
Demo repo: https://github.com/mercurial-finance/vault-sdk-demo
Easiest way to get started with our Typescript SDK, the example demo includes all functionality and information we display on our own site.
Node Demo repo: https://github.com/mercurial-finance/vault-sdk-node-demo
This is a simple demo written in node to help you have a quick understanding of how to integrate with the mercurial vault and call the various key functions.
You can git clone the repo and follow the steps in the readme to run the demo.
Docs: https://docs.mercurial.finance/mercurial-dynamic-yield-infra/
Discord: https://discord.com/channels/841152225564950528/864859354335412224
Note: If you are an affiliate partner, you are required to pass in your partner address in step 5 (in guide) when you initialize the vault instance. This is to allow our system to track the referral fees generated due to the liquidity provided by your users. To become an affiliate partner, you can contact us via our discord.
Quick Start Guide
1. Install Mercurial Vaults Dependencies
2. Import the needed libraries
3. Set up the connection, wallet and provider necessary to interact with the network
Set up the devnet connection
Set up your mock wallet. We will be using the devnet wallet address for this demo
Finally, set up the Provider using the devnetConnection and mock wallet object
4. Airdrop SOL into the devnet wallet
As this demo will be done using a devnet wallet, we can use the Solana airdrop function to deposit some initial SOL into the wallet.
Define the SOL airdrop function as shown below. We have already included this function in the util.ts file for easy access and use.
To trigger the airdrop to your devnet wallet, simply call the function with devnetConnection and your mockWallet public key as input parameters.
5. Initialize the Vault
Retrieve the token info required to initialize the vault instance. We use the SOL token as an example here.
Set up the vault instance using the connection and the token info
If you are an affiliate partner, you have to pass in an additional parameter - affiliateId
when setting up the vault instance. The affiliateId
is the partner wallet address that was used to set up the affiliate relationship with the Mercurial Dynamic Yield layer.
6. Get key data from the vault instance
Retrieve on-chain data from the vault and off-chain APY data from API. Key info includes total amount currently unlocked for user withdrawals, virtual price and the various strategies connected to the vault. The code for this can be found in getVaultDetails.ts
You can trigger the function and get the vault details via the following:
7. To deposit tokens into the vault
The steps below will allow you to deposit tokens into the vault by specifying the source wallet and the amount you want to deposit.
8. To withdraw tokens from the vault
The steps below will allow you to withdraw tokens from the vault by specifying the destination wallet and the amount you want to withdraw from the vault.
9. Retrieve affiliate partner info (only if you are set up as an affiliate partner)
If you are an affiliate partner, you can retrieve information about the partner account.
Last updated