sdk-quantum-layer

1.1.9 • Public • Published

Quantum Layer SDK

The Quantum Layer SDK is a comprehensive toolkit designed for interacting with Central Layer Order Book Model Contracts and Indexer. It simplifies the process of making transactions, querying blockchain data, interacting with smart contracts and fetching data using APIs.

Getting Started

This guide will walk you through the process of setting up and using the Quantum Layer SDK in your projects.

Prerequisites

  • Node.js installed on your machine
  • Access to an RPC for squid indexer

Installation

To use the Quantum Layer SDK, first install it via npm:

npm i
npm install sdk-quantum-layer

Run Tests

npm run test

Usage

Initialization

To start using the SDK, you need to import it and create an instance with your Ethereum JSON RPC provider URL and the factory address of the contracts you'll be interacting with:

import { ethers } from "ethers";
import MyFinalSDK from "sdk-quantum-layer";


const sdk = new MyFinalSDK(signer);

Making Transactions

Create a Pair:

To create a pair, use the createPair method with the tokenA, tokenB, and feeRate addresses as arguments.

await sdk.exchangeSDK.createPair(tokenA, tokenB)
  .then(() => console.log("Pair Created Sucessfully"))
  .catch(error => console.error("Error Creating Pair:", error));

Place a Sell Order:

To place a sell order, use the placeSellOrder method with the price, amount, and token addresses as arguments.

Price must be in wei

await sdk.exchangeSDK.placeSellOrder(price, amount, "tokenAAddress", "tokenBAddress")
  .then(() => console.log("Sell Order placed successfully"))
  .catch(error => console.error("Error placing sell order:", error));

Place a Buy Order:

To place a buy order, use the placeBuyOrder method similarly.

Price must be in wei

await sdk.exchangeSDK.placeBuyOrder(price, amount, "tokenAAddress", "tokenBAddress")
  .then(() => console.log("Buy Order placed successfully"))
  .catch(error => console.error("Error placing buy order:", error));

Delete a Buy Order:

To delete a buy order, use the deleteBuyOrder method similarly.

await sdk.exchangeSDK.deleteBuyOrder(tokenAAddress, tokenBAddress, price, orderId)
  .then(() => console.log("Buy Order deleted successfully"))
  .catch(error => console.error("Error deleting buy order:", error));

Delete a Sell Order:

To delete a sell order, use the deleteSellOrder method similarly.

await sdk.exchangeSDK.deleteSellOrder(tokenAAddress, tokenBAddress, price, orderId)
  .then(() => console.log("Sell Order deleted successfully"))
  .catch(error => console.error("Error deleting Sell order:", error));

Querying Data

Fetch Orders

You can fetch prices in a particular contract address, helps us in price graphs

await sdk.myAPI.fetchTradeHistory('startTime', 'endTime', 'contractAddress')
  .then(data => console.log('Orders:', data))
  .catch(error => console.error("Error fetching orders:", error));

Additional API Methods

The SDK provides several methods to interact with the blockchain and fetch data. Below are some additional methods you might find useful:

  • Fetch Market Details: Fetches the price data of different currencies listed by their pair address
await sdk.myAPI.fetchMarketDetails('contractAddress')
  .then(data => console.log('fetchMarketDetails:', data.data))
  .catch(error => console.error("Error fetching fetchMarketDetails:", error));
  • Fetch Pairs:: Fetch trading pairs within a specific time range.
await sdk.myAPI.fetchPairs('startTime', 'endTime')
  .then(data => console.log('Pairs:', data))
  .catch(error => console.error("Error fetching pairs:", error));
  • Fetch Orders:: Fetch orders within a specific time range.
await sdk.myAPI.fetchOrders('startTime', 'endTime', 'seller')
  .then(data => console.log('Orders:', data.orders))
  .catch(error => console.error("Error fetching deleted sell orders:", error));
  • Fetch Deleted Buy Orders:: Fetch executed trades of a pair including buy sell deleted
await sdk.myAPI.fetchTrades('startTime', 'endTime', 'buyer')
  .then(data => console.log('Deleted Buy Orders:', data.orders))
  .catch(error => console.error("Error fetching deleted buy orders:", error));

Readme

Keywords

none

Package Sidebar

Install

npm i sdk-quantum-layer

Weekly Downloads

122

Version

1.1.9

License

ISC

Unpacked Size

54.4 kB

Total Files

13

Last publish

Collaborators

  • xazus