0.0.10 • Published 6 months ago

nomadex-client v0.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

nomadex-client

Client library to programmatically interact with https://voi.nomadex.app

Install

npm i -d nomadex-client
yarn add -d nomadex-client
bun add -D nomadex-client

Swap

import { MyPool, TokenType } from 'nomadex-client';
import type { TransactionSigner, Algodv2 } from 'algosdk';

async function swap(
    poolId: number,
    network: 'voimain' | 'voitest',
    algod: Algodv2,
    signer: { addr: string; signer: TransactionSigner; },
    tokenA: { id: number, type: TokenType },
    tokenB: { id: number, type: TokenType },
    amountA: bigint,
    minAmountB: bigint,
    isDirectionAlphaToBeta: boolean,
) {
    try {
        const poolClient = new MyPool(
            poolId,
            network,
            algod,
            signer
        );
        const receivedAmount = await poolClient.swap(
            tokenA,
            tokenB,
            amountA,
            minAmountB,
            isDirectionAlphaToBeta
        );
        return receivedAmount;
    } catch (e) {
        console.error(e);
    }
}

Add Liquidity

import { MyPool, TokenType } from 'nomadex-client';
import type { TransactionSigner, Algodv2 } from 'algosdk';

async function addLiquidity(
    poolId: number,
    network: 'voimain' | 'voitest',
    algod: Algodv2,
    signer: { addr: string; signer: TransactionSigner; },
    tokenA: { id: number, type: TokenType },
    tokenB: { id: number, type: TokenType },
    amountA: bigint,
    amountB: bigint,
) {
    try {
        const poolClient = new MyPool(
            poolId,
            network,
            algod,
            signer
        );
        const success = await poolClient.addLiquidity(
            tokenA,
            tokenB,
            amountA,
            amountB,
        );
        return success;
    } catch (e) {
        console.error(e);
    }
}

Remove Liquidity

import { MyPool, TokenType } from 'nomadex-client';
import type { TransactionSigner, Algodv2 } from 'algosdk';

async function removeLiquidity(
    poolId: number,
    network: 'voimain' | 'voitest',
    algod: Algodv2,
    signer: { addr: string; signer: TransactionSigner; },
    amountLpt: bigint,
) {
    try {
        const poolClient = new MyPool(
            poolId,
            network,
            algod,
            signer
        );
        const success = await poolClient.removeLiquidity(amountLpt);
        return success;
    } catch (e) {
        console.error(e);
    }
}
0.0.10

6 months ago

0.0.9

9 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago