Instaswap-core

NPM module which allows developers to easily build exchange platform where users can swap assets into LP tokens of several De-Fi AMM and vice versa.

You can find full example codes here => instaswap-core-example

1. Install Instaswap Core

yarn add @ratio-finance/instaswap-core

2. Load the InstaSwap instance

const conn = new Connection("https://api.metaplex.solana.com"); 
const instaSwap = new InstaSwap(conn); 
await instaSwap.load();

3. Types and Interfaces

export type LpTokenInfo = {
  address: string;
  decimals: number;
  name: string;
  platform: string;
  swapAccount: string;
  swapInfo?: any,
  icon?: any,
  underlyings: Array<{
    mint: string;
    decimals: number;
  }>;
}

We use TokenInfo type which is from '@solana/spl-token-registry'

4. Get Input token

5. Get available LP tokens which insta-swap supports

Output:

6. Get estimation of LP swap output amount

  • Swap Single Token into LP Token

  • Swap LP Token into Single Token

7. Execute insta-swap transactions

  • Swap Single Token into LP Token

  • Swap LP Token into Single Token

Last updated