mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-07-23 06:50:55 -04:00
always adjust offer amount
This commit is contained in:
parent
a33c7fd830
commit
f6268c4d9f
2 changed files with 10 additions and 14 deletions
|
@ -138,6 +138,8 @@ const defaultTradeConfig: Partial<TradeContext> = {
|
||||||
takerPaymentAccountId: undefined,
|
takerPaymentAccountId: undefined,
|
||||||
buyerSendsPayment: true,
|
buyerSendsPayment: true,
|
||||||
sellerReceivesPayment: true,
|
sellerReceivesPayment: true,
|
||||||
|
buyerDisputeContext: DisputeContext.NONE,
|
||||||
|
sellerDisputeContext: DisputeContext.NONE,
|
||||||
resolveDispute: true, // resolve dispute after opening
|
resolveDispute: true, // resolve dispute after opening
|
||||||
disputeWinner: DisputeResult.Winner.SELLER,
|
disputeWinner: DisputeResult.Winner.SELLER,
|
||||||
disputeReason: DisputeResult.Reason.PEER_WAS_LATE,
|
disputeReason: DisputeResult.Reason.PEER_WAS_LATE,
|
||||||
|
@ -2923,19 +2925,13 @@ async function makeOffer(ctxP?: Partial<TradeContext>): Promise<OfferInfo> {
|
||||||
ctx.taker.splitOutputTxFee = 0n;
|
ctx.taker.splitOutputTxFee = 0n;
|
||||||
ctx.challenge = offer.getChallenge();
|
ctx.challenge = offer.getChallenge();
|
||||||
|
|
||||||
// market-priced offer amounts are unadjusted, fixed-priced offer amounts are adjusted (e.g. cash at atm is $10 increments)
|
// offer amounts are adjusted to 4 decimals
|
||||||
// TODO: adjustments should be based on currency and payment method, not fixed-price
|
|
||||||
if (!ctx.offerMinAmount) ctx.offerMinAmount = ctx.offerAmount;
|
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.offerAmount!, BigInt(offer.getAmount())))).toBeLessThan(TestConfig.maxAdjustmentPct);
|
||||||
expect(Math.abs(HavenoUtils.percentageDiff(ctx.offerMinAmount!, BigInt(offer.getMinAmount())))).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
|
if (ctx.tradeAmount === ctx.offerAmount) ctx.tradeAmount = BigInt(offer.getAmount()); // adjust trade amount
|
||||||
ctx.offerAmount = BigInt(offer.getAmount());
|
ctx.offerAmount = BigInt(offer.getAmount());
|
||||||
ctx.offerMinAmount = BigInt(offer.getMinAmount());
|
ctx.offerMinAmount = BigInt(offer.getMinAmount());
|
||||||
}
|
|
||||||
|
|
||||||
// unlocked balance has decreased
|
// unlocked balance has decreased
|
||||||
let unlockedBalanceAfter = BigInt((await ctx.maker.havenod!.getBalances()).getAvailableBalance());
|
let unlockedBalanceAfter = BigInt((await ctx.maker.havenod!.getBalances()).getAvailableBalance());
|
||||||
|
|
|
@ -808,7 +808,7 @@ export default class HavenoClient {
|
||||||
try {
|
try {
|
||||||
return (await this._priceClient.getMarketPrice(new MarketPriceRequest().setCurrencyCode(assetCode), {password: this._password})).getPrice();
|
return (await this._priceClient.getMarketPrice(new MarketPriceRequest().setCurrencyCode(assetCode), {password: this._password})).getPrice();
|
||||||
} catch (e: any) {
|
} 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);
|
throw new HavenoError(e.message, e.code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue