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

@musedao/sudoswap.js

v0.3.4

Published

An unofficial library to make it easier to work with sudoswap in JS

Downloads

33

Readme

sudoswap.js

An unofficial library to make it easier to work with sudoswap in JS.

License: MIT

This is a work in progress, issues and PR are welcome.

Features

  • Wrap contract calls to make it easier to interact with pools/router from JS.
  • Parse historical trade events of pools.
  • Helpers to format sudo related data such as delta and fee.

Documentation

Installation

npm install @musedao/sudoswap.js


const sudoswap = require("@musedao/sudoswap.js");

const sudo = new sudoswap(`https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY}`, process.env.PRIVATE_KEY); //RPC and optional private key if used for sending transactions

// Or you can pass a web3 provider exposed by metamask/walletconnect 
// window.ethereum.enable();
//const sudo = new sudoswap(window.ethereum)

const pool = sudo.getPool("0x6210e6229aec95d17f57dab93e042013d7d3603c"); //any sudo pool
const router = sudo.router(); //use the router

Pool

Getters

pool.getSellNFTQuote(nbNFT) //get x NFTs sell quote
pool.getBuyNFTQuote(nbNFT) //get x NFTs buy quote
pool.getType() // Type of pool: TRADE/SELL/BUY
pool.getNFT() // Address of the NFT
pool.getDelta()
pool.getSpotPrice()
pool.getFee()
pool.getOwner() // return owner of pool
pool.getCurve() // EXPONENTIAL or LINEAR
pool.getAssetRecipient()
pool.getAllHeldIds() // return all nft ids in the pool
pool.getNFTContract() // return an ethers.js instance of the ERC721 contract
pool.getPoolContract() // return an ethers.js instance of the pool contract

History

pool.getTrades()

Returns an array containing all past trades from the pool:

[
 {
  type: 'NFT_OUT_POOL',
  transactionHash: '0x843a0612826b6820383fd8b5b08e97c8645221ee8f9622bcf3ea9ed7c1bfebc1',
  blockNumber: 15391750,
  nfts: [ '4024' ],
  nbNfts: 1,
  buyer: '0x095aca033F31708Bf2542F15f7C5AEAFFA9B8e0b',
  fee: '30000000000000000',
  delta: '1100000000000000000',
  lpFee: '103321068658202847',
  protocolFee: '17220178109700474',
  inputValue: '3564576868707998237',
  pricePerNft: '3564576868707998237',
  priceBefore: '3130941474490995379',
  priceAfter: '3571014492753623300',
  timestamp: 1661191376,
  pool: '0x451018623f2ea29a625ac5e051720eeac2b0e765',
  logIndex: 130
 },
 {
  type: 'NFT_IN_POOL',
  transactionHash: '0xabd28282f9f3b3b074e57c0a7fbb0adbf67def90b3dddba43cd088aef957fe65',
  blockNumber: 15391959,
  nfts: [ '7309' ],
  nbNfts: 1,
  buyer: '0x451018623F2EA29A625Ac5e051720eEAc2b0E765',
  fee: '30000000000000000',
  delta: '1030000000000000000',
  lpFee: '117843478260869568',
  protocolFee: '19640579710144928',
  outputValue: '3790631884057971129',
  pricePerNft: '3790631884057971129',
  priceBefore: '3928115942028985625',
  priceAfter: '3571014492753623291',
  timestamp: 1661194031,
  pool: '0x451018623f2ea29a625ac5e051720eeac2b0e765'
 }
]

Router

To execute trades via the router you need to pass a private key when intializing sudoswap js.


const router = await sudo.router();


await router.isApprovedForRouter(nftCollection); //check if signer gave approval to the router for spend

const tx = await router.approveCollection(nftCollection); //set approval from nft collection to the router if wasn't set.

//buy any nfts from pools
const tx = await router.swapETHForAnyNFTs(
  swapList,
  ethRecipient,
  nftRecipient,
  deadline,
  ethAmount
) 

//buy specific nft ids from pool
const tx = await router.swapETHForSpecificNFTs(
  swapList,
  ethRecipient,
  nftRecipient,
  deadline,
  ethAmount
)

// Sell nfts
const tx = await router.swapNFTsForToken(
  swapList,
  minOutput,
  tokenRecipient,
  deadline
)

// Approve the router to spend your nft if not already approved
const tx = await router.approveCollection(nftAddress)

// Check if the router was approved to spend your nft
const isApprovedForRouter = await router.isApprovedForRouter(nftAddress)

Factory

To create pools with the Factory you need to pass a private key when intializing sudoswap js.

const factory = sudo.factory()

factory.createPairETH( nft, bondingCurve, assetRecipient, poolType, delta, fee, spotPrice, initialNFTIds) // Create new pair
factory.getNewPairsAddress()
factory.getNewPairsInstance()
factory.approveCollection()
factory.isApprovedForFactory()

Utils

Utilitiy functions to make it easier simulating behaviour.

const utils = sudo.utils;

utils.getBuyInfo(curve, fee, delta, spotPrice, nbNfts) // simulates curve. returns: inputValue, newDelta, lpFee, protocolFee, newSpotPrice
utils.getSellInfo(curve, fee, delta, spotPrice, nbNfts) //simulates curve returns: outputValue, newDelta, lpFee, protocolFee, newSpotPrice
utils.formatDelta("0.05", "exponential") // returns correct format for a 5% exponential curve.
utils.formatFee("0.05") // returns correct format for a 5% fee.