UNPKG

@muirglacier/jellyfish-transaction-builder

Version:

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

230 lines 10.7 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.TxnBuilderLoans = void 0; const jellyfish_transaction_1 = require("@muirglacier/jellyfish-transaction"); const txn_builder_1 = require("./txn_builder"); const jellyfish_json_1 = require("@muirglacier/jellyfish-json"); class TxnBuilderLoans extends txn_builder_1.P2WPKHTxnBuilder { /** * Create or update a loan scheme. Currently requires Foundation Authorization. * * @param {SetLoanScheme} setLoanScheme txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ setLoanScheme(setLoanScheme, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_SET_LOAN_SCHEME(setLoanScheme), changeScript); }); } /** * Destroy a loan scheme. Currently requires Foundation Authorization. * * @param {DestroyLoanScheme} destroyLoanScheme txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ destroyLoanScheme(destroyLoanScheme, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_DESTROY_LOAN_SCHEME(destroyLoanScheme), changeScript); }); } /** * Set default loan scheme. Currently requires Foundation Authorization. * * @param {SetDefaultLoanScheme} setDefaultLoanScheme txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ setDefaultLoanScheme(setDefaultLoanScheme, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_SET_DEFAULT_LOAN_SCHEME(setDefaultLoanScheme), changeScript); }); } /** * Set a collateral token. Currently requires Foundation Authorization. * * @param {SetCollateralToken} setCollateralToken txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ setCollateralToken(setCollateralToken, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_SET_COLLATERAL_TOKEN(setCollateralToken), changeScript); }); } /** * Set loan token. Currently requires Foundation Authorization. * * @param {SetLoanToken} setLoanToken txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ setLoanToken(setLoanToken, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_SET_LOAN_TOKEN(setLoanToken), changeScript); }); } /** * Update loan token. Currently requires Foundation Authorization. * * @param {UpdateLoanToken} updateLoanToken txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ updateLoanToken(updateLoanToken, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_UPDATE_LOAN_TOKEN(updateLoanToken), changeScript); }); } /** * Creates vault transaction. * * @param {CreateVault} createVault txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ createVault(createVault, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { const creationFee = this.network.name === 'regtest' ? new jellyfish_json_1.BigNumber('1') : new jellyfish_json_1.BigNumber('2'); return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_CREATE_VAULT(createVault), changeScript, creationFee); }); } /** * Create update vault transaction. * * @param {UpdateVault} updateVault txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ updateVault(updateVault, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_UPDATE_VAULT(updateVault), changeScript); }); } /** * Deposit to vault transaction. * * @param {DepositToVault} depositToVault txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ depositToVault(depositToVault, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_DEPOSIT_TO_VAULT(depositToVault), changeScript); }); } /** * Withdraw from vault transaction. * * @param {withdrawFromVault} withdrawFromVault txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ withdrawFromVault(withdrawFromVault, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_WITHDRAW_FROM_VAULT(withdrawFromVault), changeScript); }); } /** * Close a vault. * * @param {CloseVault} closeVault txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ closeVault(closeVault, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_CLOSE_VAULT(closeVault), changeScript); }); } /** * Take loan transaction. * * @param {TakeLoan} takeLoan txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ takeLoan(takeLoan, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_TAKE_LOAN(takeLoan), changeScript); }); } /** * PaybackLoan to vault transaction. * * @param {PaybackLoan} paybackLoan txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ paybackLoan(paybackLoan, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_PAYBACK_LOAN(paybackLoan), changeScript); }); } /** * placeAuctionBid transaction. * * @param {PlaceAuctionBid} placeAuctionBid txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ placeAuctionBid(placeAuctionBid, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_AUCTION_BID(placeAuctionBid), changeScript); }); } } exports.TxnBuilderLoans = TxnBuilderLoans; //# sourceMappingURL=txn_builder_loans.js.map