Mercurial Vault SDK
Getting started
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.
Docs: https://docs.mercurial.finance/mercurial-dynamic-yield-infra/
Discord: https://discord.com/channels/841152225564950528/864859354335412224
Install
npm i @mercurial-finance/vault-sdk @project-serum/anchor @solana/web3.js @solana/spl-token @solana/spl-token-registry
- Initialize VaultImpl instance
import VaultImpl from '@mercurial-finance/vault-sdk';
import { PublicKey } from '@solana/web3.js';
import { StaticTokenListResolutionStrategy, TokenInfo } from "@solana/spl-token-registry";
import { Wallet, AnchorProvider } from '@project-serum/anchor';
const mainnetConnection = new Connection('https://api.mainnet-beta.solana.com');
const mockWallet = new Wallet(new Keypair());
const provider = new AnchorProvider(mainnetConnection, mockWallet, {
commitment: 'confirmed',
});
const tokenMap = new StaticTokenListResolutionStrategy().resolve();
const SOL_TOKEN_INFO = tokenMap.find(token => token.symbol === 'SOL') as TokenInfo;
const vaultImpl = await VaultImpl.create(connection, SOL_TOKEN_INFO);
- To interact with the VaultImpl
const lpSupply = await vaultImpl.getVaultSupply();
const unlockedAmount = await vaultImpl.getWithdrawableAmount()
const amountInLamports = 1 * 10 ** SOL_TOKEN_INFO.decimals;
const depositTx = await vaultImpl.deposit(mockWallet.publicKey, new BN(amountInLamports));
const depositResult = await provider.sendAndConfirm(depositTx);
const userLpBalance = await vaultImpl.getUserBalance(mockWallet.publicKey);
const withdrawTx = await vaultImpl.withdraw(mockWallet.publicKey, new BN(userLpBalance));
const withdrawResult = await provider.sendAndConfirm(withdrawTx);
import { helper } from '@mercurial-finance/vault-sdk';
const userShare = await vaultImpl.getUserBalance(mockWallet.publicKey);
const unlockedAmount = await vaultImpl.getWithdrawableAmount()
const lpSupply = await vaultImpl.getVaultSupply();
const underlyingShare = helper.getAmountByShare(userShare, unlockedAmount, lpSupply)
const amountInLamports = 1 * 10 ** SOL_TOKEN_INFO.decimals;
const lpToUnmint = helper.getUnmintAmount(new BN(amountInLamports), unlockedAmount, lpSupply)
Vault Affiliate
To be a part of the Mercurial Finance's Vault Affiliate Program, visit our Discord above!
To initialize vault with affiliate
Affiliates only need to initialize the vault instance with the third paratemer opt.affiliate, subsequently, all interaction with the vault are the same as the usage guide above, no further configuration required.
const vaultImpl = await VaultImpl.create(
connection,
SOL_TOKEN_INFO,
{
affiliateId: new PublicKey('YOUR_PARTNER_PUBLIC_KEY');
}
);
To check Partner info
const partnerInfo = await vaultImpl.getAffiliateInfo();
@mercurial-finance/vault-sdk [2.2.1] - PR #131
Added
- new utils
deserializeMint