0.0.10 • Published 4 months ago

nomadex-client v0.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
4 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

4 months ago

0.0.9

7 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago