High level methods

A list of high level methods of the Orion SDK

The following high level methods are currently available in Orion's SDK:


Installs the SDK.

npm i @orionprotocol/sdk


Initializes the SDK after installation.

⚠️ Ethers ^5.6.0 required

// Node.js
import { OrionUnit } from "@orionprotocol/sdk";
import { Wallet } from "ethers";

const orionUnit = new OrionUnit("bsc", "production"); // eth, bsc, ftm available
const wallet = new Wallet("0x...", orionUnit.provider);
// OrionUnit is chain-in-environment abstraction
// Metamask
import { OrionUnit } from "@orionprotocol/sdk";
import detectEthereumProvider from "@metamask/detect-provider";
import { BaseProvider } from "@metamask/providers";
import { providers } from "ethers";

const startApp = async (provider: BaseProvider) => {
  const web3Provider = new providers.Web3Provider(provider);
  await web3Provider.ready;
  const signer = web3Provider.getSigner(); // ready to go
  const orionUnit = new OrionUnit("eth", "production"); // ready to go

detectEthereumProvider().then((provider) => {
  if (provider) {
    startApp(provider as BaseProvider);
  } else {
    console.log("Please install MetaMask!");


Deposits a given amount of tokens into Orion’s contract which allows to provide faster execution. Currently, deposit is required for chain native tokens, i.e. ETH/BNB/FTM. Initial deposit is not required for tokens deployed on supported chain.

  amount: 2.5,
  asset: "ORN",
  signer: wallet, // or signer when UI

Source code


Withdraws currencies directly into the specified wallet.

  amount: 435.275,
  asset: "USDT",
  signer: wallet, // or signer when UI

Source code

Get Swap Market fee info

Returns information on a market swap fee for given parameters.

const { swapInfo, fee } = await orionUnit.exchange.getSwapInfo({
  type: "exactSpend",
  assetIn: "ORN",
  assetOut: "USDT",
  feeAsset: "ORN",
  amount: 23.89045345,
  options: {
    // Optional
    instantSettlement: true,
    poolOnly: false,


// {
//   route: 'pool',
//   swapInfo: {
//     id: 'e5d50b8e-ca82-4826-b454-3fa12b693c11',
//     amountIn: 20,
//     amountOut: 25.68,
//     assetIn: 'ORN',
//     assetOut: 'USDT',
//     path: [ 'ORN', 'USDT' ],
//     executionInfo: '...',
//     orderInfo: {
//       assetPair: 'ORN-USDT',
//       side: 'SELL',
//       amount: 20,
//       safePrice: 1.284
//     },
//     exchanges: [ 'BINANCE' ],
//     price: 1.284,
//     minAmountOut: 12,
//     minAmountIn: 9.4,
//     marketPrice: 1.284,
//     availableAmountOut: null,
//     availableAmountIn: 20,
//     marketAmountOut: 25.68,
//     marketAmountIn: null,
//     type: 'exactSpend'
//   },
//   fee: {
//     assetName: 'FTM',
//     assetAddress: '0x0000000000000000000000000000000000000000',
//     networkFeeInFeeAsset: '0.00073929546',
//     protocolFeeInFeeAsset: undefined
//   }
// }

Source code

Make Swap Market

Main exchange method and the easiest way of swapping one token for another. In case of a failed swap, returns information on action required for the swap to go through (detailed message from the log). Includes possibility to allow auto-approval of tokens spending.

// Each trading pair has its own quantity precision
// You need to prepare (round) the quantity according to quantity precision

const pairConfig = await simpleFetch(orionAggregator.getPairConfig)("ORN-USDT");
if (!pairConfig) throw new Error(`Pair config ORN-USDT not found`);

const { qtyPrecision } = pairConfig;

const amount = 23.5346563;
const roundedAmount = new BigNumber(amount).decimalPlaces(
); // You can use you own Math lib

    type: "exactSpend",
    assetIn: "ORN",
    assetOut: "USDT",
    feeAsset: "ORN",
    amount: roundedAmount.toNumber(),
    slippagePercent: 1,
    signer: wallet, // or signer when UI
    options: {
      // All options are optional 🙂
      poolOnly: true, // You can specify whether you want to perform the exchange only through the pool
      instantSettlement: true, // Set true to ensure that funds can be instantly transferred to wallet (otherwise, there is a possibility of receiving funds to the balance of the exchange contract)
      logger: console.log,
      // Set it to true if you want the issues associated with
      // the lack of allowance to be automatically corrected
      autoApprove: true,

Source code

Add liquidity

Adds liquidity to an Orion protocol pool. When the amount of the first token in a pair is put in, the method automatically calculates the required equivalent amount of the second token in a pair.

  poolName: "ORN-USDT",
  amountAsset: "ORN", // ORN or USDT for this pool
  amount: 23.352345,
  signer: wallet, // or signer when UI

Source code

Remove all liquidity

Removes all liquidity deposited in a specified pool. Partial liquidity removal will be added with later versions.

  poolName: "ORN-USDT",
  signer: wallet, // or signer when UI

Source code

Last updated