0.0.16 • Published 6 months ago

cashlab v0.0.16

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

Features

  • construct cauldron exchange trades, generate cauldron trade transactions.

Install

npm install cashlab

Cauldron example

import { cauldron, TokenId, NATIVE_BCH_TOKEN_ID, Fraction } from 'cashlab';
import type { PoolV0Parameters, PoolV0, TradeResult, TradeTxResult } from 'cashlab/build/cauldron/types.js';

const exlab = new cauldron.ExchangeLab();

const supply_token_id: TokenId = 'BCH';
const demand_token_id: TokenId = <the_token_id_hex as string>;
const pool0_params: PoolV0Parameters = {
  withdraw_pubkey_hash: <the_withdraw_pubkey_hash_of_the_pool>,
};
const pool0_locking_bytecode = exlab.generatePoolV0LockingBytecode(pool0_params)
const input_pools: PoolV0[] = [
  {
    version: '0',
    parameters: pool0_params,
    outpoint: {
      index: <utxo_index as number>,
      txhash: <utxo_txhash as Uint8Array>,
    },
    output: {
      locking_bytecode: pool0_locking_bytecode,
      token: {
        amount: <token_amount as bigint>,
        token_id: <the_token_id_hex as string>,
      },
      amount: <satoshis_amount as bigint>,
    },
  },
  ....
];
const demand: bigint = <an amount greater than zero>;

const result: TradeResult = exlab.constructTradeBestRateForTargetDemand(supply_token_id, demand_token_id, demand, input_pools);

const txfee_per_byte: bigint = 1n;

const result: TradeTxResult = exlab.writeTradeTx(input_pool_trade_list, input_coins, payout_rules, null, txfee_per_byte);
 
exlab.verifyTradeTx(result);

console.log(Object.fromEntries([ 'txfee', 'payout_outputs' ].map((a) => [ a, result[a] ])))

broadcastTransaction(result.txbin)
0.1.3-beta.1

6 months ago

0.1.2-beta.1

6 months ago

0.1.1-beta.1

6 months ago

0.0.13

9 months ago

0.0.14

9 months ago

0.0.15

9 months ago

0.0.16

9 months ago

0.0.12

11 months ago

0.0.10

12 months ago

0.0.11

12 months ago

0.0.9

12 months ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago