mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-07-23 15:00:43 -04:00
rename splitOutput to reserveExactAmount
This commit is contained in:
parent
ad8ac4091b
commit
1dc0a31555
2 changed files with 11 additions and 11 deletions
|
@ -227,7 +227,7 @@ interface TradeContext {
|
||||||
price?: number,
|
price?: number,
|
||||||
priceMargin?: number,
|
priceMargin?: number,
|
||||||
triggerPrice?: number,
|
triggerPrice?: number,
|
||||||
splitOutput?: boolean,
|
reserveExactAmount?: boolean,
|
||||||
|
|
||||||
// take offer
|
// take offer
|
||||||
taker?: HavenoClient,
|
taker?: HavenoClient,
|
||||||
|
@ -1341,14 +1341,14 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
||||||
if (err) throw err;
|
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
|
let randomOfferAmount = 1.0 + (Math.random() * 1.0); // random amount between 1 and 2 xmr
|
||||||
await executeTrade({
|
await executeTrade({
|
||||||
price: 150,
|
price: 150,
|
||||||
offerAmount: HavenoUtils.xmrToAtomicUnits(randomOfferAmount),
|
offerAmount: HavenoUtils.xmrToAtomicUnits(randomOfferAmount),
|
||||||
offerMinAmount: HavenoUtils.xmrToAtomicUnits(.15),
|
offerMinAmount: HavenoUtils.xmrToAtomicUnits(.15),
|
||||||
tradeAmount: HavenoUtils.xmrToAtomicUnits(.92),
|
tradeAmount: HavenoUtils.xmrToAtomicUnits(.92),
|
||||||
splitOutput: true
|
reserveExactAmount: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2003,7 +2003,7 @@ async function executeTrade(ctx?: TradeContext): Promise<string> {
|
||||||
// make offer if configured
|
// make offer if configured
|
||||||
if (makingOffer) {
|
if (makingOffer) {
|
||||||
ctx.offer = await makeOffer(ctx);
|
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();
|
ctx.offerId = ctx.offer.getId();
|
||||||
await wait(ctx.maxTimePeerNoticeMs!);
|
await wait(ctx.maxTimePeerNoticeMs!);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2019,7 +2019,7 @@ async function executeTrade(ctx?: TradeContext): Promise<string> {
|
||||||
// TODO (woodser): test error message taking offer before posted
|
// TODO (woodser): test error message taking offer before posted
|
||||||
|
|
||||||
// wait for split output tx to unlock
|
// 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 mineToHeight(await monerod.getHeight() + 10); // TODO: wait for offer to be available (dandilion)
|
||||||
await wait(TestConfig.daemonPollPeriodMs * 2);
|
await wait(TestConfig.daemonPollPeriodMs * 2);
|
||||||
}
|
}
|
||||||
|
@ -2322,7 +2322,7 @@ async function makeOffer(ctx?: TradeContext): Promise<OfferInfo> {
|
||||||
ctx.price,
|
ctx.price,
|
||||||
ctx.priceMargin,
|
ctx.priceMargin,
|
||||||
ctx.triggerPrice,
|
ctx.triggerPrice,
|
||||||
ctx.splitOutput,
|
ctx.reserveExactAmount,
|
||||||
ctx.offerMinAmount);
|
ctx.offerMinAmount);
|
||||||
testOffer(offer, ctx);
|
testOffer(offer, ctx);
|
||||||
|
|
||||||
|
@ -2337,7 +2337,7 @@ async function makeOffer(ctx?: TradeContext): Promise<OfferInfo> {
|
||||||
// unlocked balance has decreased
|
// unlocked balance has decreased
|
||||||
let unlockedBalanceAfter = BigInt((await ctx.maker!.getBalances()).getAvailableBalance());
|
let unlockedBalanceAfter = BigInt((await ctx.maker!.getBalances()).getAvailableBalance());
|
||||||
if (offer.getState() === "SCHEDULED") {
|
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") {
|
} else if (offer.getState() === "AVAILABLE") {
|
||||||
if (unlockedBalanceAfter === unlockedBalanceBefore) {
|
if (unlockedBalanceAfter === unlockedBalanceBefore) {
|
||||||
console.warn("Unlocked balance did not change after posting offer, waiting a sync period");
|
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 {
|
} else {
|
||||||
let buyerSecurityDepositPct = HavenoUtils.divideBI(BigInt(offer.getBuyerSecurityDeposit()), BigInt(offer.getAmount()));
|
let buyerSecurityDepositPct = HavenoUtils.divideBI(BigInt(offer.getBuyerSecurityDeposit()), BigInt(offer.getAmount()));
|
||||||
let sellerSecurityDepositPct = HavenoUtils.divideBI(BigInt(offer.getSellerSecurityDeposit()), BigInt(offer.getAmount()));
|
let sellerSecurityDepositPct = HavenoUtils.divideBI(BigInt(offer.getSellerSecurityDeposit()), BigInt(offer.getAmount()));
|
||||||
if (ctx.splitOutput) {
|
if (ctx.reserveExactAmount) {
|
||||||
const tolerance = 0.000001;
|
const tolerance = 0.000001;
|
||||||
assert(ctx.buyerSecurityDepositPct! - buyerSecurityDepositPct < tolerance);
|
assert(ctx.buyerSecurityDepositPct! - buyerSecurityDepositPct < tolerance);
|
||||||
assert(ctx.buyerSecurityDepositPct! - sellerSecurityDepositPct < tolerance);
|
assert(ctx.buyerSecurityDepositPct! - sellerSecurityDepositPct < tolerance);
|
||||||
|
|
|
@ -999,7 +999,7 @@ export default class HavenoClient {
|
||||||
* @param {number} marketPriceMarginPct - if using market price, % from market price to accept (optional, default 0%)
|
* @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 {bigint} minAmount - minimum amount to trade (optional, default to fixed amount)
|
||||||
* @param {number} triggerPrice - price to remove offer (optional)
|
* @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
|
* @return {OfferInfo} the posted offer
|
||||||
*/
|
*/
|
||||||
async postOffer(direction: string,
|
async postOffer(direction: string,
|
||||||
|
@ -1010,7 +1010,7 @@ export default class HavenoClient {
|
||||||
price?: number,
|
price?: number,
|
||||||
marketPriceMarginPct?: number,
|
marketPriceMarginPct?: number,
|
||||||
triggerPrice?: number,
|
triggerPrice?: number,
|
||||||
splitOutput?: boolean,
|
reserveExactAmount?: boolean,
|
||||||
minAmount?: bigint): Promise<OfferInfo> {
|
minAmount?: bigint): Promise<OfferInfo> {
|
||||||
try {
|
try {
|
||||||
const request = new PostOfferRequest()
|
const request = new PostOfferRequest()
|
||||||
|
@ -1024,7 +1024,7 @@ export default class HavenoClient {
|
||||||
if (price) request.setPrice(price.toString());
|
if (price) request.setPrice(price.toString());
|
||||||
if (marketPriceMarginPct) request.setMarketPriceMarginPct(marketPriceMarginPct);
|
if (marketPriceMarginPct) request.setMarketPriceMarginPct(marketPriceMarginPct);
|
||||||
if (triggerPrice) request.setTriggerPrice(triggerPrice.toString());
|
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()!;
|
return (await this._offersClient.postOffer(request, {password: this._password})).getOffer()!;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
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