1.1.1 • Published 10 months ago

@perena/numeraire-sdk v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Numeraire SDK

An SDK to build on top of Numeraire.

Program ID

NUMERUNsFCP3kuNmWZuXtm1AaQCPj9uw6Guv2Ekoi5P

NPM

Just run, this will take care of committing and tagging:

npm version patch
#or 
npm version minor
#or
npm version major

Then

git push --tags

Finally

npm publish

User Guide

Installation

# NPM
npm i @perena/numeraire-sdk
# YARN
yarn add @perena/numeraire-sdk
# Or, use any package manager of your choice.

Numéraire is Perena's stableswap AMM. It facilitates the launch, trading and liquidity provisioning of stablecoins by implementing composable, extensible pools and reducing idle-liquidity that exists in traditional AMM designs

This composable structure isolates risks and optimizes swaps by connecting established stablecoins with emerging ones. It consists in the combination of:

  • Seed Pool
  • Growth Pools.

USD* Price Calculation

The current price of USD* can be calculated with the help of SDK by following steps:

  • Simulate an add_liquidity call from the SDK with USDC, USDT, PYUSD on seed pool from an account
  • Get the amount of USD* minted during add_liquidity to that account
  • Now, we have Total amount of tokens deposited and amount of USD* minted during add_liquidity
USD_Star_Price = Total_Token_Deposited / USD_Star_Minted

The SDK provides you with off-chain helpers to call the Numéraire program.

User Guide

While integrating with Numéraire program and in general to build a optimal transaction its important to simulate the transactions and to set a proper Compute Unit Price and Limit. Guide to build Optimal transaction on Solana using @solana-developers/helpers, or simply use the helper buildOptimalTransaction available in the SDK.

Examples

Swap

import { PublicKey } from "@solana/web3.js";
import { init, swapExactIn, PRODUCTION_POOLS } from "@perena/numeraire-sdk";

(async () => {
  let state = init({ applyD: false });
  console.log(state);

  const { call } = await swapExactIn({
    pool: new PublicKey(PRODUCTION_POOLS.susd),
    in: 1, // pair index of 'in' token, can also use the mint address as string
    out: 0, // pair index of 'out' token, can also use the mint address as string
    exactAmountIn: 100_000,
    minAmountOut: 99_000,
    cuLimit: 1500000,
  });
  console.log(await call.rpc());
})();

Add liquidity

import { PublicKey } from "@solana/web3.js";
import {
  init,
  addLiquidity,
  loadKeypairFromFile,
  PRODUCTION_POOLS,
} from "@perena/numeraire-sdk";

(async () => {
  init({ payer: loadKeypairFromFile("./keypair.json") });

  const { call } = await addLiquidity({
    pool: new PublicKey(PRODUCTION_POOLS.tripool),
    maxAmountsIn: [15, 10, 10],
    minLpTokenMintAmount: 1,
    takeSwaps: true,
  });
  console.log(await call.rpc());
})();

Remove liquidity

import { PublicKey } from "@solana/web3.js";
import { init, removeLiquidity, PRODUCTION_POOLS } from "@perena/numeraire-sdk";

(async () => {
  init({ applyD: false });

  const decimals = 6;
  const d = 10 ** decimals;
  const { call } = await removeLiquidity({
    pool: new PublicKey(PRODUCTION_POOLS.usds),
    lpTokenRedeemAmount: 15 * d,
  });
  console.log(await call.rpc());
})();
1.1.1

10 months ago

1.1.0

10 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago