mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-04-01 18:45:44 -04:00
always adjust offer amount
This commit is contained in:
parent
72aad448d8
commit
7f8ba50faf
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user