From 100c6b795c315cb6f8175d573e8e524e8b75a301 Mon Sep 17 00:00:00 2001 From: Nishant Ghodke <64554492+iamcrazycoder@users.noreply.github.com> Date: Fri, 29 Sep 2023 16:21:03 +0530 Subject: [PATCH] fix(sdk): allow PSBTBuilder to fetch more UTXOs as needed (#77) * fix: let PSBTBuilder fetch more UTXOs as needed * feat: change scope of isEligible method to private --- .../instant-trade/InstantTradeBuyerTxBuilder.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts b/packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts index 2ed6c141..d15fe95d 100644 --- a/packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts +++ b/packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts @@ -123,10 +123,10 @@ export default class InstantTradeBuyerTxBuilder extends InstantTradeBuilder { } // bind minimum utxos. PSBTBuilder will add more if needed - return utxos.slice(0, 3) + return utxos.slice(0, 2) } - async isEligible() { + private async isEligible() { if (!this.inscriptionOutpoint) { throw new Error("decode seller PSBT to check eligiblity") } @@ -142,24 +142,19 @@ export default class InstantTradeBuyerTxBuilder extends InstantTradeBuilder { this.postage = inscriptionUTXO.sats const sortedUTXOs = utxos.sort((a, b) => a.sats - b.sats) - const [refundableUTXOOne, refundableUTXOTwo, ...restUTXOs] = sortedUTXOs + const [refundableUTXOOne, refundableUTXOTwo] = sortedUTXOs const refundables = [refundableUTXOOne, refundableUTXOTwo].reduce((acc, curr) => (acc += curr.sats), 0) - const spendables = restUTXOs.reduce((acc, curr) => (acc += curr.sats), 0) - const eligible = refundables >= MINIMUM_AMOUNT_IN_SATS * 2 && spendables >= MINIMUM_AMOUNT_IN_SATS + const eligible = refundables >= MINIMUM_AMOUNT_IN_SATS * 2 if (eligible) { this.utxos = utxos } - return { - eligible, - refundables, - spendables - } + return true } async build() { - const { eligible } = await this.isEligible() + const eligible = await this.isEligible() if (!eligible) { throw new Error("Not eligible") }