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

mcswap-js

v0.2.6

Published

mcswap-js javascript sdk for the mcswap protocol

Downloads

90

Readme

mcswap-js

Javascript SDK for the McSwap OTC Protocol

OTC Trade Contract Functionality

Create, Fetch, Cancel, Execute, Fetch Sent, Fetch Received

Supported Standards

• SPL (+Token Extensions)

• NFT (+Token Extensions)

• pNFT (Default Rules)

• cNFT

• Core

Install SDK

npm i mcswap-js

Import SDK

import mcswap from 'mcswap-js';

Params

// create new params object
const params = {"rpc":"your helius rpc endpoint"} 
// false = you're expecting a normal signable transaction
// true = you're expecting base64 for a Blink
params.blink = false; // (omit||default = false)
// false = you're passing fractionalized units when creating
// true = you're passing decimal values when creating
params.convert = false; // (omit||default = false)
// Fee Priority Options = VeryHigh, High, Medium, Low, Min
params.priority = "Low"; // (omit||default = "Low")

Simple NFT Sale

Selling a Core NFT for 1.0 SOL

Every OTC Contract has a "seller" and a "buyer"

import mcswap from 'mcswap-js'; // import module
const params = {"rpc":"your helius rpc endpoint"} // create new params object
params.blink = false; // return signable tx
params.convert = true; // use decimals instead of fractional units
params.priority = "Medium"; // fee priority
params.seller = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"; // seller wallet
params.sellerMint = "56nFoG781ZksKWEyJF5vs5H8Fq3S491EJM3BAogCqRBi"; // seller nft
params.buyer = "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"; // buyer wallet
params.lamports = 1.0; // SOL - using decimals via convert
const tx = await mcswap.coreCreate(params); // build the tx
const signed = await provider.signTransaction(tx); // sign the tx
const signature = await mcswap.send(signed); // send the tx
const status = await mcswap.status(signature,10,2); // wait for finalization
if(status!="finalized"){console.log({"status":"error","message":status});return;}
console.log({"status":"ok","message":"contract created!"});

Non-Fungible Assets

Sell a Non-Fungible Asset for one or more of the following:

• A NFT of the same Standard

• A SPL or Token2022 Token

• SOL

Create Contract

params.blink = true;
params.convert = true;
params.priority = "Medium";
params.seller = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"; // required
params.sellerMint = "56nFoG781ZksKWEyJF5vs5H8Fq3S491EJM3BAogCqRBi"; // required
params.buyer = "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"; // required
params.buyerMint = "J8kHWEjGo4rH1rsVbLvL7idFiKdx3sJCrwd6yU8W3JyP"; // optional
params.lamports = 0.0001; // optional
params.tokenMint = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"; // optional
params.units = 1.0; // optional
const tx = await mcswap.coreCreate(params);

Fetch Contract

params.display = true;
params.sellerMint = "56nFoG781ZksKWEyJF5vs5H8Fq3S491EJM3BAogCqRBi";
params.buyerMint = "J8kHWEjGo4rH1rsVbLvL7idFiKdx3sJCrwd6yU8W3JyP"; // omit if no buyer nft
params.standard = "nft";
// params.standard = "cnft";
// params.standard = "pnft";
// params.standard = "core";
console.log(await mcswap.fetch(params));

Cancel Contract (only the seller can cancel)

params.blink = true;
params.priority = "Medium";
params.seller = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"; // required
params.sellerMint = "56nFoG781ZksKWEyJF5vs5H8Fq3S491EJM3BAogCqRBi"; // required
params.buyerMint = "J8kHWEjGo4rH1rsVbLvL7idFiKdx3sJCrwd6yU8W3JyP"; // omit if no nft was requested
const tx = await mcswap.coreCancel(params);

Execute Contract (only the buyer can execute)

params.blink = true;
params.priority = "Medium";
params.buyer = "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"; // required
params.sellerMint = "56nFoG781ZksKWEyJF5vs5H8Fq3S491EJM3BAogCqRBi"; // required
params.buyerMint = "J8kHWEjGo4rH1rsVbLvL7idFiKdx3sJCrwd6yU8W3JyP"; // omit if no nft was requested
const tx = await mcswap.coreExecute(params);

Fetch Sent Contracts

params.wallet = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"; // required seller wallet
params.display = true; // optional convert units to decimals in response
const coreSent = await mcswap.coreSent(params);

Fetch Received Contracts

params.wallet = "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"; // required buyer wallet
params.display = true; // optional convert units to decimals in response
const coreReceived = await mcswap.coreReceived(params);

Fungible Assets

Sell one or two Fungible Assets for one or two other Fungible Assets

A "seller" can not sell SOL, but can request it from the "buyer"

Create Contract

params.blink = true;
params.convert = false;
params.priority = "Medium";
params.seller = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"; // required
params.buyer = "ACgZcmgmAnMDxXxZUo9Zwg2PS6WQLXy63JnnLmJFYxZZ"; // required
params.token1Mint = "CKfatsPMUf8SkiURsDXs7eK6GWb4Jsd6UDbs7twMCWxo"; // required
params.token1Amount = 1000; // required
params.token2Mint = "AVm6WLmMuzdedAMjpXLYmSGjLLPPjjVWNuR6JJhJLWn3"; // optional/omit
params.token2Amount = 10000000000; // optional/omit
params.token3Mint = "11111111111111111111111111111111"; // required - if requesting SOL it must be in pos 3
params.token3Amount = 1000000; // required
params.token4Mint = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"; // optional/omit
params.token4Amount = 100000; // optional/omit
const tx = await mcswap.splCreate(params);

Fetch Contract

fetch spl is temporarily unavailable
params.display = true;
params.seller = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere";
params.buyer = "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"; // omit if no buyer nft
params.standard = "spl";
console.log(await mcswap.fetch(params));

Cancel Contract (only the seller can cancel)

params.blink = true;
params.priority = "Medium";
params.seller = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"; // required
params.buyer = "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"; // required
const tx = await mcswap.splCancel(params);

Execute Contract (only the buyer can execute)

params.blink = true;
params.priority = "Medium";
params.seller = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"; // required
params.buyer = "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"; // required
const tx = await mcswap.splExecute(params);

Fetch Sent Contracts

params.wallet = "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"; // required seller wallet
params.display = true; // optional convert units to decimals in response
const splSent = await mcswap.splSent(params);

Fetch Received Contracts

params.wallet = "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"; // required buyer wallet
params.display = true; // optional convert units to decimals in response
const splReceived = await mcswap.splReceived(params);

Fees

The following fetches the current protocol fees

// Get PIKL fee for the McSwap SPL txs (Fungible)
params.standard = "spl";
console.log(await mcswap.fee(params));
// Get SOL fee for McSwap NFT txs (Non-Fungible)
params.standard = "nft";
console.log(await mcswap.fee(params));
params.standard = "cnft";
console.log(await mcswap.fee(params));
params.standard = "pnft";
console.log(await mcswap.fee(params));
params.standard = "core";
console.log(await mcswap.fee(params));