The following high level methods are currently available in Orion's SDK:
Installation
Installs the SDK.
npm i @orionprotocol/sdk
Initialization
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!");
}
});
Deposit
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.
orionUnit.exchange.deposit({
amount: 2.5,
asset: "ORN",
signer: wallet, // or signer when UI
});
Withdraw
Withdraws currencies directly into the specified wallet.
orionUnit.exchange.withdraw({
amount: 435.275,
asset: "USDT",
signer: wallet, // or signer when UI
});
Get Swap Market fee info
Returns information on a market swap fee for given parameters.
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(
qtyPrecision,
BigNumber.ROUND_FLOOR
); // You can use you own Math lib
orionUnit.exchange
.swapMarket({
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,
},
})
.then(console.log);
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.
orionUnit.farmingManager.addLiquidity({
poolName: "ORN-USDT",
amountAsset: "ORN", // ORN or USDT for this pool
amount: 23.352345,
signer: wallet, // or signer when UI
});
Remove all liquidity
Removes all liquidity deposited in a specified pool. Partial liquidity removal will be added with later versions.
orionUnit.farmingManager.removeAllLiquidity({
poolName: "ORN-USDT",
signer: wallet, // or signer when UI
});