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

@wingriders/dex-blockfrost-adapter

v0.4.2

Published

Adapter to get the WingRiders state using blockfrost. For deserialization of the data it uses [@wingriders/dex-serializer](https://github.com/WingRiders/dex-serializer) library.

Downloads

287

Readme

EXPERIMENTAL WingRiders Blockfrost adapter

Adapter to get the WingRiders state using blockfrost. For deserialization of the data it uses @wingriders/dex-serializer library.

Installation

Install the package with:

npm install @wingriders/dex-blockfrost-adapter @dcspark/cardano-multiplatform-lib-nodejs

Usage

A very simple use-case when using node js:

/**
 * On WingRiders all ADA<>Token pools have different addresses.
 * Blockfrost does not support quierying just based on the script address,
 * so a mapping is necessary. There is a snapshot of the liquidity pools
 * in the test folder. Alternatively you can fetch your own running
 * $ npm run scripts:lpmap
 */
const addressMap = require("./test/lpmap.mainnet.20221013.json");

/**
 * Require or import the package. The common js package is built against
 * @dcspark/cardano-multiplatform-lib-nodejs, while the browser one againt *-browser
 */
const wr = require("@wingriders/dex-blockfrost-adapter");

/**
 * Initialize the WingRiders blockfrost adapter with your project ID
 * and the address map.
 */
const adapter = new wr.WingRidersAdapter({
  projectId: "mainnetYOUR_PROJECT_ID",
  lpAddressMap: addressMap,
  poolType: wr.PoolType.CONSTANT_PRODUCT,
});

/**
 * The address map keys are based on the LP token assetname.
 * The ADA<>WRT lP token on mainnet is as below
 */
const adaWrtLP = addressMap["dec347c549f618e80d97682b5b4c6985256503bbb3f3955831f5679cdb8de72f"];

/**
 * Get the latest state of the liquidity pool based on the included tokens.
 * Unit - is a term from blockfrost, the concatenated `policyId <> assetName` encoded as hex
 */
console.log(await adapter.getLiquidityPoolState(adaWrtLP.unitA, adaWrtLP.unitB));

/**
 * If you are only interested in the mid ADA price based on the ADA <> MELD pool
 * the parameter is the unit similar to above. E.g. MELD asset:
 * https://cardanoscan.io/token/6ac8ef33b510ec004fe11585f7c5a9f0c07f0c23428ab4f29c1d7d104d454c44
 *
 * !Warning! The actual swap price will differ because it depends on the swapped amount
 *           and the depth of the liquidity pool.
 */
console.log(await adapter.getAdaPrice("6ac8ef33b510ec004fe11585f7c5a9f0c07f0c23428ab4f29c1d7d104d454c44"));

Should give you something similar to:

{
  address: 'addr1z8nvjzjeydcn4atcd93aac8allvrpjn7pjr2qsweukpnaytvcg6zm2vds6mz9x3h3yalqmnf24w86m09n40q3tgqxjms9yu6v8',
  unitA: 'lovelace',
  unitB: 'c0ee29a85b13209423b10447d3c2e6a50641a15c57770e27cb9d507357696e67526964657273',
  unitLp: '026a18d04a0c642759bb3d83b12e3344894e5c1c7b2aeb1a2113a570dec347c549f618e80d97682b5b4c6985256503bbb3f3955831f5679cdb8de72f',
  issuedLpTokens: '3287316988194',
  quantityA: '1955086131373',
  quantityB: '5666239873301'
}

0.052060335367318265

WRT pool state MELD ada price

Examples

The examples folder contains additional examples how to set up bundling to interact also with frontend applications

  • Current Price - Example bundling vite and vanilla JS to show a token price on a webpage. The example intentionally does not use any frontend framework.
  • Swap - Example combining multiple aspects of interacting with WingRiders smart contracts: getting liquidity pool states, computing expected swap quantities, building a tx on the frontend using lucid and submitting a swap request to WingRiders.

Known issues

  • only mainnet is supported fully, proprod support is planned
  • serialization lib conflicting types between nodejs and browser versions

Development

npm install
npm run build