always adjust offer amount

This commit is contained in:
woodser 2025-01-17 10:28:11 -05:00
parent 72aad448d8
commit 7f8ba50faf
No known key found for this signature in database
GPG Key ID: 55A10DD48ADEE5EF
2 changed files with 10 additions and 14 deletions

View File

@ -138,6 +138,8 @@ const defaultTradeConfig: Partial<TradeContext> = {
takerPaymentAccountId: undefined,
buyerSendsPayment: true,
sellerReceivesPayment: true,
buyerDisputeContext: DisputeContext.NONE,
sellerDisputeContext: DisputeContext.NONE,
resolveDispute: true, // resolve dispute after opening
disputeWinner: DisputeResult.Winner.SELLER,
disputeReason: DisputeResult.Reason.PEER_WAS_LATE,
@ -2394,7 +2396,7 @@ test("Can bootstrap a network", async () => {
if (ctxP.sellerDisputeContext === undefined) ctxP.sellerDisputeContext = getRandomOutcome(1/14) ? DisputeContext.OPEN_AFTER_DEPOSITS_UNLOCK : undefined;
if (ctxP.sellerDisputeContext === undefined) ctxP.sellerDisputeContext = getRandomOutcome(1/14) ? DisputeContext.OPEN_AFTER_PAYMENT_SENT : undefined;
if (ctxP.resolveDispute === undefined) ctxP.resolveDispute = getRandomOutcome(5/7);
return TradeContext.init(ctxP);
}
@ -2923,19 +2925,13 @@ async function makeOffer(ctxP?: Partial<TradeContext>): Promise<OfferInfo> {
ctx.taker.splitOutputTxFee = 0n;
ctx.challenge = offer.getChallenge();
// market-priced offer amounts are unadjusted, fixed-priced offer amounts are adjusted (e.g. cash at atm is $10 increments)
// TODO: adjustments should be based on currency and payment method, not fixed-price
// offer amounts are adjusted to 4 decimals
if (!ctx.offerMinAmount) ctx.offerMinAmount = ctx.offerAmount;
if (offer.getUseMarketBasedPrice()) {
expect(BigInt(offer.getAmount())).toEqual(ctx.offerAmount!);
expect(BigInt(offer.getMinAmount())).toEqual(ctx.offerMinAmount!);
} else {
expect(Math.abs(HavenoUtils.percentageDiff(ctx.offerAmount!, BigInt(offer.getAmount())))).toBeLessThan(TestConfig.maxAdjustmentPct);
expect(Math.abs(HavenoUtils.percentageDiff(ctx.offerMinAmount!, BigInt(offer.getMinAmount())))).toBeLessThan(TestConfig.maxAdjustmentPct);
if (ctx.tradeAmount === ctx.offerAmount) ctx.tradeAmount = BigInt(offer.getAmount()); // adjust trade amount
ctx.offerAmount = BigInt(offer.getAmount());
ctx.offerMinAmount = BigInt(offer.getMinAmount());
}
expect(Math.abs(HavenoUtils.percentageDiff(ctx.offerAmount!, BigInt(offer.getAmount())))).toBeLessThan(TestConfig.maxAdjustmentPct);
expect(Math.abs(HavenoUtils.percentageDiff(ctx.offerMinAmount!, BigInt(offer.getMinAmount())))).toBeLessThan(TestConfig.maxAdjustmentPct);
if (ctx.tradeAmount === ctx.offerAmount) ctx.tradeAmount = BigInt(offer.getAmount()); // adjust trade amount
ctx.offerAmount = BigInt(offer.getAmount());
ctx.offerMinAmount = BigInt(offer.getMinAmount());
// unlocked balance has decreased
let unlockedBalanceAfter = BigInt((await ctx.maker.havenod!.getBalances()).getAvailableBalance());

View File

@ -808,7 +808,7 @@ export default class HavenoClient {
try {
return (await this._priceClient.getMarketPrice(new MarketPriceRequest().setCurrencyCode(assetCode), {password: this._password})).getPrice();
} catch (e: any) {
if (e.message.indexOf("not found") >= 0) return undefined;
if (e.message.indexOf("not found") >= 0) return undefined; // TODO: return unknown price server side (0?)
throw new HavenoError(e.message, e.code);
}
}