# blockfrost-adapter

> Query Minswap data from Blockfrost

Latest version **0.0.27** (published 2023-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install blockfrost-adapter
pnpm add blockfrost-adapter
yarn add blockfrost-adapter
bun add blockfrost-adapter
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.27 |
| Published | 2023-06-01 |
| First published | 2023-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 146 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 60 |
| Author | Minswap Labs |
| Maintainers | pedropiloto |
| Keywords | minswap, cardano, blockfrost, dex, blockchain, ape |

## Links

- npm: https://www.npmjs.com/package/blockfrost-adapter
- Repository: https://github.com/minswap/blockfrost-adapter
- Homepage: https://github.com/minswap/blockfrost-adapter#readme
- Issues: https://github.com/minswap/blockfrost-adapter/issues
- npm.io page: https://npm.io/package/blockfrost-adapter

## Dependencies (4)

- [big.js](https://npm.io/package/big.js.md) ^6.1.1
- [lucid-cardano](https://npm.io/package/lucid-cardano.md) ^0.10.1
- [@minswap/tiny-invariant](https://npm.io/package/@minswap/tiny-invariant.md) ^1.2.0
- [@blockfrost/blockfrost-js](https://npm.io/package/@blockfrost/blockfrost-js.md) ^5.3.1

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.0.27 (latest) — 2023-06-01
- 0.0.26 — 2023-06-01
- 0.0.25 — 2023-06-01
- 0.0.24 — 2023-06-01
- 0.0.23 — 2023-06-01
- 0.0.22 — 2023-06-01
- 0.0.21 — 2023-06-01
- 0.0.20 — 2023-06-01
- 0.0.19 — 2023-06-01
- 0.0.18 — 2023-06-01
- 0.0.17 — 2023-06-01
- 0.0.16 — 2023-06-01
- 0.0.15 — 2023-06-01
- 0.0.14 — 2023-06-01
- 0.0.13 — 2023-06-01
- … 7 more at https://npm.io/package/blockfrost-adapter/versions

## README

# Minswap Blockfrost Adapter

## Features

- [x] Get current pair price
- [x] Get historical pair price
- [x] Calculate trade price
- [x] Calculate price impact
- [ ] Create orders and submit to Blockfrost

## Install

- NPM: `npm install @minswap/blockfrost-adapter`
- Yarn: `yarn add @minswap/blockfrost-adapter`

## Examples

### Example 1: Get current price of MIN/ADA pool

```ts
import { BlockfrostAdapter, NetworkId } from "@minswap/blockfrost-adapter";

const api = new BlockfrostAdapter({
  projectId: "<your_project_id>",
  networkId: NetworkId.MAINNET,
});
for (let i = 1; ; i++) {
  const pools = await api.getPools({ page: i });
  if (pools.length === 0) {
    // last page
    break;
  }
  const minADAPool = pools.find(
    (p) =>
      p.assetA === "lovelace" &&
      p.assetB ===
        "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"
  );
  if (minADAPool) {
    const [a, b] = await api.getPoolPrice({ pool: minADAPool });
    console.log(
      `ADA/MIN price: ${a.toString()}; MIN/ADA price: ${b.toString()}`
    );
    // we can later use this ID to call getPoolById
    console.log(`ADA/MIN pool ID: ${minADAPool.id}`);
    break;
  }
}
```

### Example 2: Get historical prices of MIN/ADA pool

```ts
import { BlockfrostAdapter, NetworkId } from "@minswap/blockfrost-adapter";

const MIN_ADA_POOL_ID =
  "6aa2153e1ae896a95539c9d62f76cedcdabdcdf144e564b8955f609d660cf6a2";

const api = new BlockfrostAdapter({
  projectId: "<your_project_id>",
  networkId: NetworkId.MAINNET,
});
const history = await api.getPoolHistory({ id: MIN_ADA_POOL_ID });
for (const historyPoint of history) {
  const pool = await api.getPoolInTx({ txHash: historyPoint.txHash });
  if (!pool) {
    throw new Error("pool not found");
  }
  const [price0, price1] = await api.getPoolPrice({
    pool,
    decimalsA: 6,
    decimalsB: 6,
  });
  console.log(`${historyPoint.time}: ${price0} ADA/MIN, ${price1} MIN/ADA`);
}
```

---
_Source: https://npm.io/package/blockfrost-adapter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
