From 61ee07fe8efdce5d3dfa4cc666b5e3ec2ff4b48f Mon Sep 17 00:00:00 2001 From: McSam Date: Wed, 16 Aug 2023 12:09:48 +0800 Subject: [PATCH 1/2] update readme for anchor --- ts-client/README.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/ts-client/README.md b/ts-client/README.md index 68b1b03..d6acbd2 100644 --- a/ts-client/README.md +++ b/ts-client/README.md @@ -6,6 +6,7 @@
## Getting started + NPM: https://www.npmjs.com/package/@mercurial-finance/vault-sdk SDK: https://github.com/mercurial-finance/vault-sdk @@ -13,6 +14,7 @@ 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/ @@ -26,32 +28,35 @@ Discord: https://discord.com/channels/841152225564950528/864859354335412224 1. Install deps ``` -npm i @mercurial-finance/vault-sdk @project-serum/anchor @solana/web3.js @solana/spl-token @solana/spl-token-registry +npm i @mercurial-finance/vault-sdk @coral-xyz/anchor @solana/web3.js @solana/spl-token @solana/spl-token-registry ``` 2. Initialize VaultImpl instance + - Affiliate or partner? refer to the [Vault Affiliate Program]() + ```ts 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'; +import { StaticTokenListResolutionStrategy, TokenInfo } from '@solana/spl-token-registry'; +import { Wallet, AnchorProvider } from '@coral-xyz/anchor'; // Connection, Wallet, and AnchorProvider to interact with the network const mainnetConnection = new Connection('https://api.mainnet-beta.solana.com'); const mockWallet = new Wallet(new Keypair()); const provider = new AnchorProvider(mainnetConnection, mockWallet, { - commitment: 'confirmed', + commitment: 'confirmed', }); // Alternatively, to use Solana Wallet Adapter, refer to `Demo Repo` const tokenMap = new StaticTokenListResolutionStrategy().resolve(); // Find the token info you want to use. -const SOL_TOKEN_INFO = tokenMap.find(token => token.symbol === 'SOL') as TokenInfo; +const SOL_TOKEN_INFO = tokenMap.find((token) => token.symbol === 'SOL') as TokenInfo; const vaultImpl = await VaultImpl.create(connection, SOL_TOKEN_INFO); ``` 3. To interact with the VaultImpl + ```ts // To refetch the vault's latest supply // Alternatively, use `vaultImpl.lpSupply` @@ -59,7 +64,7 @@ const lpSupply = await vaultImpl.getVaultSupply(); // Rewards are not instantly redeemable, and are subject to a lock. // This function returns the amount of LP that are redeemable. -const unlockedAmount = await vaultImpl.getWithdrawableAmount() +const unlockedAmount = await vaultImpl.getWithdrawableAmount(); // To deposit into the vault const amountInLamports = 1 * 10 ** SOL_TOKEN_INFO.decimals; // 1.0 SOL @@ -75,34 +80,37 @@ const withdrawResult = await provider.sendAndConfirm(withdrawTx); // Transaction ``` 4. Helper function + ```ts import { helper } from '@mercurial-finance/vault-sdk'; const userShare = await vaultImpl.getUserBalance(mockWallet.publicKey); -const unlockedAmount = await vaultImpl.getWithdrawableAmount() +const unlockedAmount = await vaultImpl.getWithdrawableAmount(); const lpSupply = await vaultImpl.getVaultSupply(); // To convert user's LP balance into underlying token amount -const underlyingShare = helper.getAmountByShare(userShare, unlockedAmount, lpSupply) +const underlyingShare = helper.getAmountByShare(userShare, unlockedAmount, lpSupply); // To convert underlying token amount into user's LP balance const amountInLamports = 1 * 10 ** SOL_TOKEN_INFO.decimals; // 1.0 SOL -const lpToUnmint = helper.getUnmintAmount(new BN(amountInLamports), unlockedAmount, lpSupply) // To withdraw 1.0 SOL +const lpToUnmint = helper.getUnmintAmount(new BN(amountInLamports), unlockedAmount, lpSupply); // To withdraw 1.0 SOL ```
## 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. ```ts const vaultImpl = await VaultImpl.create( - connection, + connection, SOL_TOKEN_INFO, { affiliateId: new PublicKey('YOUR_PARTNER_PUBLIC_KEY'); @@ -111,7 +119,8 @@ const vaultImpl = await VaultImpl.create( ``` #### To check Partner info + ```ts // Affiliate / Partner info const partnerInfo = await vaultImpl.getAffiliateInfo(); -``` \ No newline at end of file +``` From 4f7902fbd024d740e2b29d569f297b1c8ee7ebda Mon Sep 17 00:00:00 2001 From: McSam Date: Wed, 16 Aug 2023 12:13:40 +0800 Subject: [PATCH 2/2] bump: version --- ts-client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts-client/package.json b/ts-client/package.json index 924fb48..2b656b9 100644 --- a/ts-client/package.json +++ b/ts-client/package.json @@ -1,6 +1,6 @@ { "name": "@mercurial-finance/vault-sdk", - "version": "0.5.1", + "version": "0.5.2", "description": "Mercurial Vault SDK is a typescript library that allows you to interact with Mercurial v2's vault.", "main": "dist/cjs/index.js", "module": "dist/esm/index.js",