1.1.1 • Published 5 months ago

@perena/numeraire-sdk v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 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

5 months ago

1.1.0

5 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.19

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago