UNPKG

@muirglacier/jellyfish-transaction-builder

Version:

A collection of TypeScript + JavaScript tools and libraries for DeFi Blockchain developers to build decentralized finance for Bitcoin

54 lines 3.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TxnBuilderLiqPool = void 0; const jellyfish_transaction_1 = require("@muirglacier/jellyfish-transaction"); const txn_builder_1 = require("./txn_builder"); const txn_builder_error_1 = require("./txn_builder_error"); class TxnBuilderLiqPool extends txn_builder_1.P2WPKHTxnBuilder { /** * Add to liquidity pool using token balances pair supplied in `addLiquidity`.from[0].balances. * * @param {PoolAddLiquidity} addLiquidity txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @throws {TxnBuilderError} if 'addLiquidity.from' length is not `1` * @throws {TxnBuilderError} if 'addLiquidity.from[0].balances' length is not `2` * @returns {Promise<TransactionSegWit>} */ addLiquidity(addLiquidity, changeScript) { return __awaiter(this, void 0, void 0, function* () { if (addLiquidity.from.length !== 1) { throw new txn_builder_error_1.TxnBuilderError(txn_builder_error_1.TxnBuilderErrorType.INVALID_ADD_LIQUIDITY_INPUT, '`addLiquidity.from` array length must be ONE'); } if (addLiquidity.from[0].balances.length !== 2) { throw new txn_builder_error_1.TxnBuilderError(txn_builder_error_1.TxnBuilderErrorType.INVALID_ADD_LIQUIDITY_INPUT, '`addLiquidity.from[0].balances` array length must be TWO'); } if (addLiquidity.from[0].balances[0].token === addLiquidity.from[0].balances[1].token) { throw new txn_builder_error_1.TxnBuilderError(txn_builder_error_1.TxnBuilderErrorType.INVALID_ADD_LIQUIDITY_INPUT, '`addLiquidity.from[0].balances` must consists of TWO different token'); } return yield this.createDeFiTx(jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_POOL_ADD_LIQUIDITY(addLiquidity), changeScript); }); } /** * Remove from liquidity pool. * * @param {PoolRemoveLiquidity} removeLiquidity pool token p2pwkh scipt, token id and amount to remove * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ removeLiquidity(removeLiquidity, changeScript) { return __awaiter(this, void 0, void 0, function* () { return yield this.createDeFiTx(jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_POOL_REMOVE_LIQUIDITY(removeLiquidity), changeScript); }); } } exports.TxnBuilderLiqPool = TxnBuilderLiqPool; //# sourceMappingURL=txn_builder_liq_pool.js.map