@aldrin_exchange/sdk

Aldrin SDK

Usage no npm install needed!

<script type="module">
  import aldrinExchangeSdk from 'https://cdn.skypack.dev/@aldrin_exchange/sdk';
</script>

README

Aldrin DEX SDK

GitHub license

Aldrin logo

[Website | API Reference | Examples ]

Getting Started

  1. Install one of available Solana wallets
  2. Install library with npm install @aldrin_exchange/sdk or yarn add @aldrin_exchange/sdk
  3. Check Usage section or take a look at examples and API reference

Usage


Trade (swap tokens)

import { Wallet } from '@project-serum/anchor';
import { PublicKey } from '@solana/web3.js';
import BN from 'bn.js';
import { TokenSwap } from '../../src';


const wallet = Wallet.local() // Or any other solana wallet

async function trade() {
  const tokenSwap = await TokenSwap.initialize()

  const rin = new PublicKey('E5ndSkaB17Dm7CsD22dvcjfrYSDLCxFcMd6z8ddCk5wp')
  const usdc = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v')

  const rinPrice = await tokenSwap.getPrice({ mintFrom: rin, mintTo: usdc })
  const usdRinPrice = await tokenSwap.getPrice({ mintFrom: usdc, mintTo: rin })

  console.log(`RIN/USDC price: ${rinPrice}`, `USDC/RIN price: ${usdRinPrice}` )

  const transactionId = await tokenSwap.swap({
    wallet: wallet,
    // A least 1 of parameters minIncomeAmount/outcomeAmount is required
    minIncomeAmount: new BN(1_000_000_000), // 1 RIN
    // outcomeAmount: new BN(5_000_000) // 5 USDC
    mintFrom: usdc,
    mintTo: rin,
  })
} 
trade()

Add pool liquidity

import BN from 'bn.js'
import { Wallet } from '@project-serum/anchor';
import { AUTHORIZED_POOLS } from '../../src'

const wallet = Wallet.local() // Or any other solana wallet


async function depositLiquidity() {
   const tokenSwap = await TokenSwap.initialize()

  const transactionId = await tokenSwap.depositLiquidity({
    wallet: wallet,
    poolMint: AUTHORIZED_POOLS.RIN_USDC.poolMint,
    // A least 1 of parameters maxBase/maxQuote is required
    // maxBase: new BN(1_000_000_000), // 1 RIN
    maxQuote: new BN(5_000_000), // 5 USDC
  })

  console.log('Liquidity added: ', transactionId)
}

Withdraw liquidity from pool

import BN from 'bn.js'
import { Wallet } from '@project-serum/anchor';
import { AUTHORIZED_POOLS } from '../../src'

const wallet = Wallet.local() // Or any other solana wallet

export async function withdrawLiquidity() {
  const tokenSwap = await TokenSwap.initialize()

  const transactionId = await tokenSwap.withdrawLiquidity({
    wallet: wallet,
    poolMint: AUTHORIZED_POOLS.RIN_USDC.poolMint,
    poolTokenAmount: new BN(100_000), // LP tokens
    // A least 1 of parameters minBase/minQuote is required
    // minBase: new BN(1_000_000), // 1 RIN
    // minQuote: new BN(5_000_000), // 1 RIN
  })

  console.log('Liquidity withdrawed: ', transactionId)
}

Check farming rewards

import { AUTHORIZED_POOLS, TokenSwap } from '../../src';
import { wallet } from '../common';


export async function checkFarmed() {
  const tokenSwap = await TokenSwap.initialize()

  const farmed = await tokenSwap.getFarmed({
    wallet,
    poolMint: AUTHORIZED_POOLS.SOL_USDC.poolMint,
  })


  farmed.forEach((f) => {
    console.log(`Reward for farming: mint ${f.tokenInfo.mint.toBase58()}, amount: ${f.calcAccount.tokenAmount.toString()}`)
  })
}

checkFarmed()

You can find more complex examples by link.

Development

  1. Clone repository
  2. Run yarn or npm install

Warning

The library is under active development. Use it at your own risk.