@rainbow-ic/sunbeam
v0.0.9
Published
multiple ICP dexes lib
Downloads
1,383
Readme
Sunbeam SDK
Sunbeam SDK is a TypeScript library for interacting with decentralized exchanges (DEXs) on the Internet Computer (IC) blockchain. It provides a unified interface for interacting with different DEXs like KongSwap and ICPSwap.
Features
- List tokens and pools
- Get pool information
- Prepare and execute swaps
- Retrieve transaction history
Installation
To install the Sunbeam SDK, use npm or yarn:
npm install sunbeam-sdk
Table of Contents
Usage
Importing the SDK
import { KongSwap, ICPSwap } from "sunbeam-sdk";
Initializing a DEX
KongSwap
import { HttpAgent } from "@dfinity/agent";
import { KongSwap } from "sunbeam-sdk";
const agent = new HttpAgent({ host: "https://ic0.app" });
const kongSwap = new KongSwap({ agent, address: "your-kongswap-canister-id" });
ICPSwap
import { HttpAgent } from "@dfinity/agent";
import { ICPSwap } from "sunbeam-sdk";
const agent = new HttpAgent({ host: "https://ic0.app" });
const icpSwap = new ICPSwap({ agent });
Listing Tokens
KongSwap
const tokens = await kongSwap.listTokens();
console.log(tokens);
ICPSwap
const tokens = await icpSwap.listTokens();
console.log(tokens);
Listing Pools
KongSwap
const pools = await kongSwap.listPools();
console.log(pools);
ICPSwap
const pools = await icpSwap.listPools();
console.log(pools);
Getting Pool Information
KongSwap
const pool = await kongSwap.getPoolByAddress("pool-address");
if (pool) {
const poolInfo = pool.getPoolInfo();
console.log(poolInfo);
}
ICPSwap
const pool = await icpSwap.getPoolByAddress("pool-address");
if (pool) {
const poolInfo = pool.getPoolInfo();
console.log(poolInfo);
}
Preparing and Executing a Swap
KongSwap
const pool = await kongSwap.getPoolByAddress("pool-address");
if (pool) {
const swapInput = {
tokenIn: { address: "token-in-address", amountIn: 1000 },
tokenOut: { address: "token-out-address", amountOut: 900 },
slippage: 0.5,
};
const preparedSwap = await pool.prepareSwap(swapInput);
console.log(preparedSwap);
const swapResult = await pool.swap(swapInput);
console.log(swapResult);
}
ICPSwap
const pool = await icpSwap.getPoolByAddress("pool-address");
if (pool) {
const swapInput = {
tokenIn: { address: "token-in-address", amountIn: 1000 },
tokenOut: { address: "token-out-address", amountOut: 900 },
slippage: 0.5,
};
const preparedSwap = await pool.prepareSwap(swapInput);
console.log(preparedSwap);
const swapResult = await pool.swap(swapInput);
console.log(swapResult);
}
Getting Transaction History
KongSwap
const transactions = await kongSwap.getTransactions();
console.log(transactions);
ICPSwap
const transactions = await icpSwap.getTransactions();
console.log(transactions);
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License.
This README provides an overview of the Sunbeam SDK, including installation instructions, usage examples, and information on contributing and licensing.