Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: testing submodule #133

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ target
**/*.rs.bk
node_modules

ts-client/dist/
ts-client/dist/
ts-client/.turbo/
40 changes: 23 additions & 17 deletions ts-client/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Mercurial Vault SDK

<p align="center">
<img align="center" src="https://vaults.mercurial.finance/icons/logo.svg" width="180" height="180" />
<img align="center" src="https://app.meteora.ag/icons/logo.svg" width="180" height="180" />
</p>
<br>

## Getting started
NPM: https://www.npmjs.com/package/@mercurial-finance/vault-sdk

NPM: https://www.npmjs.com/package/@meteora-ag/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/
Expand All @@ -26,40 +28,40 @@ 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 @meteora-ag/vault-sdk @project-serum/anchor @solana/web3.js @solana/spl-token
```

2. Initialize VaultImpl instance

- Affiliate or partner? refer to the [Vault Affiliate Program]()

```ts
import VaultImpl from '@mercurial-finance/vault-sdk';
import VaultImpl from '@meteora-ag/vault-sdk';
import { PublicKey } from '@solana/web3.js';
import { StaticTokenListResolutionStrategy, TokenInfo } from "@solana/spl-token-registry";
import { NATIVE_MINT } from '@solana/spl-token';
import { Wallet, AnchorProvider } from '@project-serum/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 vaultImpl = await VaultImpl.create(connection, SOL_TOKEN_INFO);
const vaultImpl = await VaultImpl.create(connection, NATIVE_MINT);
```

3. To interact with the VaultImpl

```ts
// To refetch the vault's latest supply
// Alternatively, use `vaultImpl.lpSupply`
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
Expand All @@ -75,34 +77,37 @@ const withdrawResult = await provider.sendAndConfirm(withdrawTx); // Transaction
```

4. Helper function

```ts
import { helper } from '@mercurial-finance/vault-sdk';
import { helper } from '@meteora-ag/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
```

<hr>

## Vault Affiliate

To be a part of the Mercurial Finance's Vault Affiliate Program, visit our Discord above!

<br>

#### 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');
Expand All @@ -111,7 +116,8 @@ const vaultImpl = await VaultImpl.create(
```

#### To check Partner info

```ts
// Affiliate / Partner info
const partnerInfo = await vaultImpl.getAffiliateInfo();
```
```
4 changes: 4 additions & 0 deletions ts-client/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { config } from '@meteora-ag/config/eslint/base';

/** @type {import("eslint").Linter.Config} */
export default config;
32 changes: 15 additions & 17 deletions ts-client/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "@mercurial-finance/vault-sdk",
"version": "2.2.1",
"description": "Mercurial Vault SDK is a typescript library that allows you to interact with Mercurial v2's vault.",
"name": "@meteora-ag/vault-sdk",
"version": "0.1.0",
"description": "Meteora Vault SDK is a typescript library that allows you to interact with Meteora's dynamic vault.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"scripts": {
"postclone": "pnpm rm @meteora-ag/config && pnpm i @meteora-ag/config",
"dev": "rm -rf dist && tsc -p tsconfig.dev.json --watch",
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.esm.json",
"test": "jest ./src/vault/tests/*.test.ts --runInBand",
"test-affiliate": "jest ./src/vault/tests/affiliate.test.ts --runInBand"
Expand All @@ -13,32 +15,28 @@
"dist"
],
"keywords": [],
"author": "mercurial-finance",
"author": "meteora-ag",
"license": "MIT",
"dependencies": {
"@coral-xyz/anchor": "^0.28.0",
"@solana/buffer-layout": "^4.0.1",
"@solana/spl-token": "^0.4.6",
"@solana/spl-token-registry": "^0.2.4574",
"@solana/web3.js": "^1.91.6",
"bn.js": "5.2.1",
"cross-fetch": "^3.1.5",
"decimal.js": "10.3.1",
"jsbi": "4.3.0"
},
"devDependencies": {
"@tsconfig/recommended": "^1.0.1",
"@types/bn.js": "^5.1.0",
"@meteora-ag/config": "workspace:*",
"@types/bn.js": "^5.1.6",
"@types/chai": "^4.3.1",
"@types/jest": "^27.5.1",
"@types/mocha": "^9.1.1",
"@types/node": "^22.10.1",
"chai": "^4.3.6",
"jest": "^28.1.0",
"mocha": "^10.0.0",
"ts-jest": "^28.0.2",
"ts-mocha": "^10.0.0",
"typescript": "^5.5.4"
},
"peerDependencies": {
"@coral-xyz/anchor": "^0.28.0",
"@solana/spl-token": "^0.4.9",
"@solana/web3.js": "^1.95.5",
"bn.js": "^5.2.1"
},
"directories": {
"test": "tests"
},
Expand Down
Loading
Loading