floorswap
TypeScript icon, indicating that this package has built-in type declarations

0.1.21 • Public • Published

Floorswap

The Floorswap SDK provides abstractions to assist you with interacting with the Floorswap smart contracts in a Typescript/Javascript environment (e.g. websites, node scripts). With the SDK, you can manipulate data that has been queried from the EVM using libraries that assist with needs such as data modeling, protection from rounding errors, and compile time enforced typing.

Synopsis

Floorswap JavaScript SDK allows developers easily interact with Floorswap smart contract, such as:

  1. Access liquidity pool to obtain collection list.
  2. Manipulate data that has been queried from the EVM such as data modeling, filtering.
  3. Create buy/sell orders
  4. Add/remove liquidity
  5. Swap NFT and tokens.

Before you logically compose actions, please remember initialize first.

Installation

Explain some prerequisites that users need to prepare before installation and use, such as:You Need install or upgrade Node.js (>= 8.*, Npm version >= 5.2.0, Yarn preferred).

Installation

npm install --save floorswap
# or
yarn add floorswap

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance.

Getting Started

Please note and confirm you are consent to the "Terms of Use" for API data. Then you can new a Floorswap client from 'ethers provider' to start your journey.

import Floorswap from 'floorswap'
import { Chain, Environment } from 'floorswap'

const provider = new ethers.JsonRpcProvider("https://mainnet.infura.io")
const signer = new ethers.Wallet(<privateKey>, provider)
const floorswapSDK = new Floorswap({ chain: Chain.sepolia, environment: Environment.testnet })

NOTE: If you wanna tour floorswap in testnet, please switch your network to Seqpolia. Goerli will be abandoned in end of 2023 NOTE: You need to sign transaction using your private key when running official instances.

Get pool list

IPool returns a pool list. Only offcially supported pools will be included.

interface IPool {
  collectionName: string;
  collectionAddress: string;
  nftsOffer: number;
  tokensOffer: number;
  volume24h: number;
  floorPrice: number;
  offerPrice: number;
}
const pools = await floorswapSDK.pool.poolList({ page: 1 });

Get pool details

View pool details, such as collection name, contract address.

interface IPoolDetail {
  collectionName: string;
  collectionAddress: string;
  nftsOffer: number;
  tokensOffer: number;
  volume24h: number;
  floorPrice: number;
  offerPrice: number;
  position: {
    pairAddress: string;
    status: number;
  }[];
}
const poolDetail = await floorswapSDK.pool.poolDetail({
  collectionAddress: "0x1234...",
});

Get token IDs held by the owner

interface IGetNFTIdsResponse {
  balance: number;
  tokenIds: string[];
}
const { balance, tokenIds } = await floorswapSDK.account.getNFTIds(
  provider,
  collection,
  owner,
  limit,
);

Initialize liquidity

Initilize a liquduity pool, after that you can add more and remove liquidity

const collectionAddress = "0x1234..."; // nft address
const fee = ethers.parseEther("0.01").toString(); // 0.01 means 1%
const concentration = 8; // The larger the value, the smaller the slippage/spread
const depositETH = "800000000000000000"; // uint is wei
const nftIds = ["2", "6", "8"];
await floorswapSDK.pool.initLiquidity({
  signer: signer,
  nft: collectionAddress,
  bondingCurve: 0,
  fee: fee,
  concentration: concentration,
  initialNFTIDs: nftIds,
  value: depositETH,
});

Remove liquidity

Remove liquidity from the pool and collect the LP fee.

# Obtain pair ID from "floorswapSDK.position.positionList"
# const pariList = floorswapSDK.position.positionList({address=<you wallet address>})
const pairId = "1"
await floorswapSDK.position.removeLiquidity({ signer: signer, pairId: pairId })

Swap for NFTs

Swap ETH for NFTs.

const count = 2; // Amount of NFTs you wanna swap for
const collection = "0x1234..."; // Collection contract address
const slippage = 0.02; // 0.02 = 2%
await floorswapSDK.swap.swapTokenForNft({
  signer: signer,
  collection: collection,
  count: count,
  slippage: slippage,
}: ISwapTokenForNftParams & { signer: ethers.Signer });

interface ISwapTokenForNftParams {
  collection: string;
  slippage: number;
  count: number;
}

Swap for ETH

Swap NFTs for ETH.

const collection = "0x1234..."; // Collection contract address
const nftIds = ["57", "68"];
const slippage = 0.02; //0.02 = 2%
await floorswapSDK.swap.swapNftForToken({
  signer: signer,
  collection: nftAddress,
  nftIds: nftIds,
  slippage: slippage,
}: ISwapNftForTokenParams & { signer: ethers.Signer });

interface ISwapNftForTokenParams {
  collection: string;
  slippage: number;
  nftIds: string[];
}

Swap Any NFTs for ETH.

const collection = "0x1234..."; // Collection contract address
const amount = 2;
const slippage = 0.02; //0.02 = 2%
await floorswapSDK.swap.swapAnyNftForToken({
  signer: signer,
  collection: nftAddress,
  amount: nftIds,
  slippage: slippage,
}: ISwapAnyNftForTokenParams & { signer: ethers.Signer });

interface ISwapAnyNftForTokenParams {
  collection: string;
  slippage: number;
  amount: number;
}

Package Sidebar

Install

npm i floorswap

Weekly Downloads

25

Version

0.1.21

License

ISC

Unpacked Size

167 kB

Total Files

28

Last publish

Collaborators

  • chac-dev