From 1dc0a31555bc22f2951ca00f132e7975bf1967d8 Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 23 Jul 2023 12:23:10 -0400 Subject: [PATCH] rename splitOutput to reserveExactAmount --- src/HavenoClient.test.ts | 16 ++++++++-------- src/HavenoClient.ts | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/HavenoClient.test.ts b/src/HavenoClient.test.ts index 4cd5980c..62a3d760 100644 --- a/src/HavenoClient.test.ts +++ b/src/HavenoClient.test.ts @@ -227,7 +227,7 @@ interface TradeContext { price?: number, priceMargin?: number, triggerPrice?: number, - splitOutput?: boolean, + reserveExactAmount?: boolean, // take offer taker?: HavenoClient, @@ -1341,14 +1341,14 @@ test("Can schedule offers with locked funds (CI)", async () => { if (err) throw err; }); -test("Can split offer outputs (CI)", async () => { +test("Can reserve exact amount needed for offer (CI)", async () => { let randomOfferAmount = 1.0 + (Math.random() * 1.0); // random amount between 1 and 2 xmr await executeTrade({ price: 150, offerAmount: HavenoUtils.xmrToAtomicUnits(randomOfferAmount), offerMinAmount: HavenoUtils.xmrToAtomicUnits(.15), tradeAmount: HavenoUtils.xmrToAtomicUnits(.92), - splitOutput: true + reserveExactAmount: true }); }); @@ -2003,7 +2003,7 @@ async function executeTrade(ctx?: TradeContext): Promise { // make offer if configured if (makingOffer) { ctx.offer = await makeOffer(ctx); - expect(ctx.offer.getState()).toEqual(ctx.splitOutput ? "SCHEDULED" : "AVAILABLE"); + expect(ctx.offer.getState()).toEqual(ctx.reserveExactAmount ? "SCHEDULED" : "AVAILABLE"); ctx.offerId = ctx.offer.getId(); await wait(ctx.maxTimePeerNoticeMs!); } else { @@ -2019,7 +2019,7 @@ async function executeTrade(ctx?: TradeContext): Promise { // TODO (woodser): test error message taking offer before posted // wait for split output tx to unlock - if (ctx.splitOutput) { + if (ctx.reserveExactAmount) { await mineToHeight(await monerod.getHeight() + 10); // TODO: wait for offer to be available (dandilion) await wait(TestConfig.daemonPollPeriodMs * 2); } @@ -2322,7 +2322,7 @@ async function makeOffer(ctx?: TradeContext): Promise { ctx.price, ctx.priceMargin, ctx.triggerPrice, - ctx.splitOutput, + ctx.reserveExactAmount, ctx.offerMinAmount); testOffer(offer, ctx); @@ -2337,7 +2337,7 @@ async function makeOffer(ctx?: TradeContext): Promise { // unlocked balance has decreased let unlockedBalanceAfter = BigInt((await ctx.maker!.getBalances()).getAvailableBalance()); if (offer.getState() === "SCHEDULED") { - if (!ctx.splitOutput && unlockedBalanceAfter !== unlockedBalanceBefore) throw new Error("Unlocked balance should not change for scheduled offer " + offer.getId()); + if (!ctx.reserveExactAmount && unlockedBalanceAfter !== unlockedBalanceBefore) throw new Error("Unlocked balance should not change for scheduled offer " + offer.getId()); } else if (offer.getState() === "AVAILABLE") { if (unlockedBalanceAfter === unlockedBalanceBefore) { console.warn("Unlocked balance did not change after posting offer, waiting a sync period"); @@ -3337,7 +3337,7 @@ function testOffer(offer: OfferInfo, ctx?: TradeContext) { } else { let buyerSecurityDepositPct = HavenoUtils.divideBI(BigInt(offer.getBuyerSecurityDeposit()), BigInt(offer.getAmount())); let sellerSecurityDepositPct = HavenoUtils.divideBI(BigInt(offer.getSellerSecurityDeposit()), BigInt(offer.getAmount())); - if (ctx.splitOutput) { + if (ctx.reserveExactAmount) { const tolerance = 0.000001; assert(ctx.buyerSecurityDepositPct! - buyerSecurityDepositPct < tolerance); assert(ctx.buyerSecurityDepositPct! - sellerSecurityDepositPct < tolerance); diff --git a/src/HavenoClient.ts b/src/HavenoClient.ts index 0f97a1ee..9c8dc149 100644 --- a/src/HavenoClient.ts +++ b/src/HavenoClient.ts @@ -999,7 +999,7 @@ export default class HavenoClient { * @param {number} marketPriceMarginPct - if using market price, % from market price to accept (optional, default 0%) * @param {bigint} minAmount - minimum amount to trade (optional, default to fixed amount) * @param {number} triggerPrice - price to remove offer (optional) - * @param {number} splitOutput - create a new output reserved for the offer, incurring an on-chain transaction and 10 confirmations before the offer goes live (default = false) + * @param {number} reserveExactAmount - reserve exact amount needed for offer, incurring on-chain transaction and 10 confirmations before the offer goes live (default = false) * @return {OfferInfo} the posted offer */ async postOffer(direction: string, @@ -1010,7 +1010,7 @@ export default class HavenoClient { price?: number, marketPriceMarginPct?: number, triggerPrice?: number, - splitOutput?: boolean, + reserveExactAmount?: boolean, minAmount?: bigint): Promise { try { const request = new PostOfferRequest() @@ -1024,7 +1024,7 @@ export default class HavenoClient { if (price) request.setPrice(price.toString()); if (marketPriceMarginPct) request.setMarketPriceMarginPct(marketPriceMarginPct); if (triggerPrice) request.setTriggerPrice(triggerPrice.toString()); - if (splitOutput) request.setSplitOutput(splitOutput); + if (reserveExactAmount) request.setReserveExactAmount(reserveExactAmount); return (await this._offersClient.postOffer(request, {password: this._password})).getOffer()!; } catch (e: any) { throw new HavenoError(e.message, e.code);