npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

floorswap

v0.1.21

Published

floorswap sdk

Downloads

97

Readme

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;
}