nftperp sdk ✨
SDK to interact with the nftperp protocol (docs).
tldr; nftperp is a derivates platform for nfts. for the first time ever, short nfts with leverage
The protocol is currently in BETA on arbitrum mainnet (dapp). it uses fake eth for paper trading, which can be obtained from faucet on website
For any queries, hop in the community discord and ask away invite link
Installation
npm i @nftperp/sdk
Also requires ethers
library
NOTE: If npm i ethers
is used, it will default to installing ethers v6
, which will create errors when initialising the SDK
npm i ethers@5
Usage
Setup
import { ethers } from "ethers";
import { SDK } from "@nftperp/sdk";
import { Instance } from "@nftperp/sdk/types";
const provider = new ethers.providers.JsonRpcProvider("<your-rpc-url>");
const wallet = new ethers.Wallet("<your-private-key>", provider);
const nftperp = new SDK({ wallet, instance: Instance.TRADING_COMP });
If an error of the following occurs: SyntaxError: Cannot use import statement outside a module
, add in the following to your package.json
file
"type": "module"
If an error of the following occurs: Directory import '..\@nftperp\sdk\types' is not supported resolving ES modules
, do the following:
import { Instance } from "@nftperp/sdk/types";
import { Instance } from "@nftperp/sdk/types/index.js";
Open a position
import { Amm, Side } from "@nftperp/sdk/types";
const hash = await nftperp.openPosition({
amm: Amm.BAYC,
side: Side.BUY,
amount: 0.1,
leverage: 3,
});
note: to get a list of supported amms do:
console.log(nftperp.getSupportedAmms(Instance.BETA));
Get postion
const position = await nftperp.getPosition(Amm.BAYC);
Close position
const hash = await nftperp.closePosition({
amm: Amm.BAYC,
});
Estimate fee on position
const feeInfo = await nftperp.calcFee({
amm: Amm.BAYC,
amount: 1,
leverage: 1,
side: Side.BUY,
open: true,
});
Calculate open position transaction summary
const txSummary = await nftperp.getOpenPosTxSummary({
amm: Amm.BAYC,
amount: 1,
leverage: 1,
side: Side.BUY,
});
Calculate close position transaction summary
const txSummary = await nftperp.getClosePosTxSummary({
amm: Amm.BAYC,
closePercent: 100,
});
Get mark price
const markPrice = await nftperp.getMarkPrice(Amm.BAYC);
Get index price
const indexPrice = await nftperp.getIndexPrice(Amm.BAYC);
Get funding info
const fundingInfo = await nftperp.getFundingInfo(Amm.BAYC);