mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-07-26 00:05:39 -04:00
test security deposit based on trade amount
This commit is contained in:
parent
cfdec7115c
commit
35c0cf9301
11 changed files with 176 additions and 181 deletions
4
dist/HavenoClient.d.ts
vendored
4
dist/HavenoClient.d.ts
vendored
|
@ -418,7 +418,7 @@ export default class HavenoClient {
|
||||||
* @param {bigint} amount - amount of XMR to trade
|
* @param {bigint} amount - amount of XMR to trade
|
||||||
* @param {string} assetCode - asset code to trade for XMR
|
* @param {string} assetCode - asset code to trade for XMR
|
||||||
* @param {string} paymentAccountId - payment account id
|
* @param {string} paymentAccountId - payment account id
|
||||||
* @param {number} buyerSecurityDepositPct - buyer security deposit as % of trade amount
|
* @param {number} securityDepositPct - security deposit as % of trade amount for buyer and seller
|
||||||
* @param {number} price - trade price (optional, default to market price)
|
* @param {number} price - trade price (optional, default to market price)
|
||||||
* @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 {number} triggerPrice - price to remove offer (optional)
|
* @param {number} triggerPrice - price to remove offer (optional)
|
||||||
|
@ -426,7 +426,7 @@ export default class HavenoClient {
|
||||||
* @param {number} reserveExactAmount - reserve exact amount needed for offer, incurring 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
|
||||||
*/
|
*/
|
||||||
postOffer(direction: string, amount: bigint, assetCode: string, paymentAccountId: string, buyerSecurityDepositPct: number, price?: number, marketPriceMarginPct?: number, triggerPrice?: number, minAmount?: bigint, reserveExactAmount?: boolean): Promise<OfferInfo>;
|
postOffer(direction: string, amount: bigint, assetCode: string, paymentAccountId: string, securityDepositPct: number, price?: number, marketPriceMarginPct?: number, triggerPrice?: number, minAmount?: bigint, reserveExactAmount?: boolean): Promise<OfferInfo>;
|
||||||
/**
|
/**
|
||||||
* Remove a posted offer, releasing its reserved funds.
|
* Remove a posted offer, releasing its reserved funds.
|
||||||
*
|
*
|
||||||
|
|
7
dist/HavenoClient.js
vendored
7
dist/HavenoClient.js
vendored
|
@ -975,7 +975,7 @@ class HavenoClient {
|
||||||
* @param {bigint} amount - amount of XMR to trade
|
* @param {bigint} amount - amount of XMR to trade
|
||||||
* @param {string} assetCode - asset code to trade for XMR
|
* @param {string} assetCode - asset code to trade for XMR
|
||||||
* @param {string} paymentAccountId - payment account id
|
* @param {string} paymentAccountId - payment account id
|
||||||
* @param {number} buyerSecurityDepositPct - buyer security deposit as % of trade amount
|
* @param {number} securityDepositPct - security deposit as % of trade amount for buyer and seller
|
||||||
* @param {number} price - trade price (optional, default to market price)
|
* @param {number} price - trade price (optional, default to market price)
|
||||||
* @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 {number} triggerPrice - price to remove offer (optional)
|
* @param {number} triggerPrice - price to remove offer (optional)
|
||||||
|
@ -983,14 +983,15 @@ class HavenoClient {
|
||||||
* @param {number} reserveExactAmount - reserve exact amount needed for offer, incurring 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, amount, assetCode, paymentAccountId, buyerSecurityDepositPct, price, marketPriceMarginPct, triggerPrice, minAmount, reserveExactAmount) {
|
async postOffer(direction, amount, assetCode, paymentAccountId, securityDepositPct, price, marketPriceMarginPct, triggerPrice, minAmount, reserveExactAmount) {
|
||||||
|
console_1.default.log("Posting offer with security deposit %: " + securityDepositPct);
|
||||||
try {
|
try {
|
||||||
const request = new grpc_pb_1.PostOfferRequest()
|
const request = new grpc_pb_1.PostOfferRequest()
|
||||||
.setDirection(direction)
|
.setDirection(direction)
|
||||||
.setAmount(amount.toString())
|
.setAmount(amount.toString())
|
||||||
.setCurrencyCode(assetCode)
|
.setCurrencyCode(assetCode)
|
||||||
.setPaymentAccountId(paymentAccountId)
|
.setPaymentAccountId(paymentAccountId)
|
||||||
.setBuyerSecurityDepositPct(buyerSecurityDepositPct)
|
.setBuyerSecurityDepositPct(securityDepositPct)
|
||||||
.setUseMarketBasedPrice(price === undefined)
|
.setUseMarketBasedPrice(price === undefined)
|
||||||
.setMinAmount(minAmount ? minAmount.toString() : amount.toString());
|
.setMinAmount(minAmount ? minAmount.toString() : amount.toString());
|
||||||
if (price)
|
if (price)
|
||||||
|
|
2
dist/HavenoClient.js.map
vendored
2
dist/HavenoClient.js.map
vendored
File diff suppressed because one or more lines are too long
14
dist/protobuf/grpc_pb.d.ts
vendored
14
dist/protobuf/grpc_pb.d.ts
vendored
|
@ -1609,8 +1609,11 @@ export class OfferInfo extends jspb.Message {
|
||||||
getMinVolume(): string;
|
getMinVolume(): string;
|
||||||
setMinVolume(value: string): OfferInfo;
|
setMinVolume(value: string): OfferInfo;
|
||||||
|
|
||||||
getBuyerSecurityDeposit(): string;
|
getBuyerSecurityDepositPct(): number;
|
||||||
setBuyerSecurityDeposit(value: string): OfferInfo;
|
setBuyerSecurityDepositPct(value: number): OfferInfo;
|
||||||
|
|
||||||
|
getSellerSecurityDepositPct(): number;
|
||||||
|
setSellerSecurityDepositPct(value: number): OfferInfo;
|
||||||
|
|
||||||
getTriggerPrice(): string;
|
getTriggerPrice(): string;
|
||||||
setTriggerPrice(value: string): OfferInfo;
|
setTriggerPrice(value: string): OfferInfo;
|
||||||
|
@ -1636,9 +1639,6 @@ export class OfferInfo extends jspb.Message {
|
||||||
getState(): string;
|
getState(): string;
|
||||||
setState(value: string): OfferInfo;
|
setState(value: string): OfferInfo;
|
||||||
|
|
||||||
getSellerSecurityDeposit(): string;
|
|
||||||
setSellerSecurityDeposit(value: string): OfferInfo;
|
|
||||||
|
|
||||||
getMakerFee(): string;
|
getMakerFee(): string;
|
||||||
setMakerFee(value: string): OfferInfo;
|
setMakerFee(value: string): OfferInfo;
|
||||||
|
|
||||||
|
@ -1688,7 +1688,8 @@ export namespace OfferInfo {
|
||||||
minAmount: string,
|
minAmount: string,
|
||||||
volume: string,
|
volume: string,
|
||||||
minVolume: string,
|
minVolume: string,
|
||||||
buyerSecurityDeposit: string,
|
buyerSecurityDepositPct: number,
|
||||||
|
sellerSecurityDepositPct: number,
|
||||||
triggerPrice: string,
|
triggerPrice: string,
|
||||||
paymentAccountId: string,
|
paymentAccountId: string,
|
||||||
paymentMethodId: string,
|
paymentMethodId: string,
|
||||||
|
@ -1697,7 +1698,6 @@ export namespace OfferInfo {
|
||||||
counterCurrencyCode: string,
|
counterCurrencyCode: string,
|
||||||
date: number,
|
date: number,
|
||||||
state: string,
|
state: string,
|
||||||
sellerSecurityDeposit: string,
|
|
||||||
makerFee: string,
|
makerFee: string,
|
||||||
isActivated: boolean,
|
isActivated: boolean,
|
||||||
isMyOffer: boolean,
|
isMyOffer: boolean,
|
||||||
|
|
208
dist/protobuf/grpc_pb.js
vendored
208
dist/protobuf/grpc_pb.js
vendored
|
@ -15322,16 +15322,16 @@ proto.io.haveno.protobuffer.OfferInfo.toObject = function(includeInstance, msg)
|
||||||
minAmount: jspb.Message.getFieldWithDefault(msg, 7, "0"),
|
minAmount: jspb.Message.getFieldWithDefault(msg, 7, "0"),
|
||||||
volume: jspb.Message.getFieldWithDefault(msg, 8, ""),
|
volume: jspb.Message.getFieldWithDefault(msg, 8, ""),
|
||||||
minVolume: jspb.Message.getFieldWithDefault(msg, 9, ""),
|
minVolume: jspb.Message.getFieldWithDefault(msg, 9, ""),
|
||||||
buyerSecurityDeposit: jspb.Message.getFieldWithDefault(msg, 10, "0"),
|
buyerSecurityDepositPct: jspb.Message.getFloatingPointFieldWithDefault(msg, 10, 0.0),
|
||||||
triggerPrice: jspb.Message.getFieldWithDefault(msg, 11, ""),
|
sellerSecurityDepositPct: jspb.Message.getFloatingPointFieldWithDefault(msg, 11, 0.0),
|
||||||
paymentAccountId: jspb.Message.getFieldWithDefault(msg, 12, ""),
|
triggerPrice: jspb.Message.getFieldWithDefault(msg, 12, ""),
|
||||||
paymentMethodId: jspb.Message.getFieldWithDefault(msg, 13, ""),
|
paymentAccountId: jspb.Message.getFieldWithDefault(msg, 13, ""),
|
||||||
paymentMethodShortName: jspb.Message.getFieldWithDefault(msg, 14, ""),
|
paymentMethodId: jspb.Message.getFieldWithDefault(msg, 14, ""),
|
||||||
baseCurrencyCode: jspb.Message.getFieldWithDefault(msg, 15, ""),
|
paymentMethodShortName: jspb.Message.getFieldWithDefault(msg, 15, ""),
|
||||||
counterCurrencyCode: jspb.Message.getFieldWithDefault(msg, 16, ""),
|
baseCurrencyCode: jspb.Message.getFieldWithDefault(msg, 16, ""),
|
||||||
date: jspb.Message.getFieldWithDefault(msg, 17, 0),
|
counterCurrencyCode: jspb.Message.getFieldWithDefault(msg, 17, ""),
|
||||||
state: jspb.Message.getFieldWithDefault(msg, 18, ""),
|
date: jspb.Message.getFieldWithDefault(msg, 18, 0),
|
||||||
sellerSecurityDeposit: jspb.Message.getFieldWithDefault(msg, 19, "0"),
|
state: jspb.Message.getFieldWithDefault(msg, 19, ""),
|
||||||
makerFee: jspb.Message.getFieldWithDefault(msg, 20, "0"),
|
makerFee: jspb.Message.getFieldWithDefault(msg, 20, "0"),
|
||||||
isActivated: jspb.Message.getBooleanFieldWithDefault(msg, 21, false),
|
isActivated: jspb.Message.getBooleanFieldWithDefault(msg, 21, false),
|
||||||
isMyOffer: jspb.Message.getBooleanFieldWithDefault(msg, 22, false),
|
isMyOffer: jspb.Message.getBooleanFieldWithDefault(msg, 22, false),
|
||||||
|
@ -15415,45 +15415,45 @@ proto.io.haveno.protobuffer.OfferInfo.deserializeBinaryFromReader = function(msg
|
||||||
msg.setMinVolume(value);
|
msg.setMinVolume(value);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
var value = /** @type {string} */ (reader.readUint64String());
|
var value = /** @type {number} */ (reader.readDouble());
|
||||||
msg.setBuyerSecurityDeposit(value);
|
msg.setBuyerSecurityDepositPct(value);
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
var value = /** @type {string} */ (reader.readString());
|
var value = /** @type {number} */ (reader.readDouble());
|
||||||
msg.setTriggerPrice(value);
|
msg.setSellerSecurityDepositPct(value);
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
var value = /** @type {string} */ (reader.readString());
|
var value = /** @type {string} */ (reader.readString());
|
||||||
msg.setPaymentAccountId(value);
|
msg.setTriggerPrice(value);
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
var value = /** @type {string} */ (reader.readString());
|
var value = /** @type {string} */ (reader.readString());
|
||||||
msg.setPaymentMethodId(value);
|
msg.setPaymentAccountId(value);
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
var value = /** @type {string} */ (reader.readString());
|
var value = /** @type {string} */ (reader.readString());
|
||||||
msg.setPaymentMethodShortName(value);
|
msg.setPaymentMethodId(value);
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
var value = /** @type {string} */ (reader.readString());
|
var value = /** @type {string} */ (reader.readString());
|
||||||
msg.setBaseCurrencyCode(value);
|
msg.setPaymentMethodShortName(value);
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
var value = /** @type {string} */ (reader.readString());
|
var value = /** @type {string} */ (reader.readString());
|
||||||
msg.setCounterCurrencyCode(value);
|
msg.setBaseCurrencyCode(value);
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
|
var value = /** @type {string} */ (reader.readString());
|
||||||
|
msg.setCounterCurrencyCode(value);
|
||||||
|
break;
|
||||||
|
case 18:
|
||||||
var value = /** @type {number} */ (reader.readUint64());
|
var value = /** @type {number} */ (reader.readUint64());
|
||||||
msg.setDate(value);
|
msg.setDate(value);
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 19:
|
||||||
var value = /** @type {string} */ (reader.readString());
|
var value = /** @type {string} */ (reader.readString());
|
||||||
msg.setState(value);
|
msg.setState(value);
|
||||||
break;
|
break;
|
||||||
case 19:
|
|
||||||
var value = /** @type {string} */ (reader.readUint64String());
|
|
||||||
msg.setSellerSecurityDeposit(value);
|
|
||||||
break;
|
|
||||||
case 20:
|
case 20:
|
||||||
var value = /** @type {string} */ (reader.readUint64String());
|
var value = /** @type {string} */ (reader.readUint64String());
|
||||||
msg.setMakerFee(value);
|
msg.setMakerFee(value);
|
||||||
|
@ -15586,72 +15586,72 @@ proto.io.haveno.protobuffer.OfferInfo.serializeBinaryToWriter = function(message
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getBuyerSecurityDeposit();
|
f = message.getBuyerSecurityDepositPct();
|
||||||
if (parseInt(f, 10) !== 0) {
|
if (f !== 0.0) {
|
||||||
writer.writeUint64String(
|
writer.writeDouble(
|
||||||
10,
|
10,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
f = message.getSellerSecurityDepositPct();
|
||||||
|
if (f !== 0.0) {
|
||||||
|
writer.writeDouble(
|
||||||
|
11,
|
||||||
|
f
|
||||||
|
);
|
||||||
|
}
|
||||||
f = message.getTriggerPrice();
|
f = message.getTriggerPrice();
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
writer.writeString(
|
writer.writeString(
|
||||||
11,
|
12,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getPaymentAccountId();
|
f = message.getPaymentAccountId();
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
writer.writeString(
|
writer.writeString(
|
||||||
12,
|
13,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getPaymentMethodId();
|
f = message.getPaymentMethodId();
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
writer.writeString(
|
writer.writeString(
|
||||||
13,
|
14,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getPaymentMethodShortName();
|
f = message.getPaymentMethodShortName();
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
writer.writeString(
|
writer.writeString(
|
||||||
14,
|
15,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getBaseCurrencyCode();
|
f = message.getBaseCurrencyCode();
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
writer.writeString(
|
writer.writeString(
|
||||||
15,
|
16,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getCounterCurrencyCode();
|
f = message.getCounterCurrencyCode();
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
writer.writeString(
|
writer.writeString(
|
||||||
16,
|
17,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getDate();
|
f = message.getDate();
|
||||||
if (f !== 0) {
|
if (f !== 0) {
|
||||||
writer.writeUint64(
|
writer.writeUint64(
|
||||||
17,
|
18,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getState();
|
f = message.getState();
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
writer.writeString(
|
writer.writeString(
|
||||||
18,
|
|
||||||
f
|
|
||||||
);
|
|
||||||
}
|
|
||||||
f = message.getSellerSecurityDeposit();
|
|
||||||
if (parseInt(f, 10) !== 0) {
|
|
||||||
writer.writeUint64String(
|
|
||||||
19,
|
19,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
|
@ -15892,46 +15892,46 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.setMinVolume = function(value) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional uint64 buyer_security_deposit = 10;
|
* optional double buyer_security_deposit_pct = 10;
|
||||||
* @return {string}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getBuyerSecurityDeposit = function() {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getBuyerSecurityDepositPct = function() {
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 10, "0"));
|
return /** @type {number} */ (jspb.Message.getFloatingPointFieldWithDefault(this, 10, 0.0));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} value
|
* @param {number} value
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setBuyerSecurityDeposit = function(value) {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setBuyerSecurityDepositPct = function(value) {
|
||||||
return jspb.Message.setProto3StringIntField(this, 10, value);
|
return jspb.Message.setProto3FloatField(this, 10, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional string trigger_price = 11;
|
* optional double seller_security_deposit_pct = 11;
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getSellerSecurityDepositPct = function() {
|
||||||
|
return /** @type {number} */ (jspb.Message.getFloatingPointFieldWithDefault(this, 11, 0.0));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value
|
||||||
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
|
*/
|
||||||
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setSellerSecurityDepositPct = function(value) {
|
||||||
|
return jspb.Message.setProto3FloatField(this, 11, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* optional string trigger_price = 12;
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getTriggerPrice = function() {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getTriggerPrice = function() {
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 11, ""));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} value
|
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
|
||||||
*/
|
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setTriggerPrice = function(value) {
|
|
||||||
return jspb.Message.setProto3StringField(this, 11, value);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* optional string payment_account_id = 12;
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentAccountId = function() {
|
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 12, ""));
|
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 12, ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15940,16 +15940,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentAccountId = function()
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setPaymentAccountId = function(value) {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setTriggerPrice = function(value) {
|
||||||
return jspb.Message.setProto3StringField(this, 12, value);
|
return jspb.Message.setProto3StringField(this, 12, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional string payment_method_id = 13;
|
* optional string payment_account_id = 13;
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentMethodId = function() {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentAccountId = function() {
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 13, ""));
|
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 13, ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15958,16 +15958,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentMethodId = function()
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setPaymentMethodId = function(value) {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setPaymentAccountId = function(value) {
|
||||||
return jspb.Message.setProto3StringField(this, 13, value);
|
return jspb.Message.setProto3StringField(this, 13, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional string payment_method_short_name = 14;
|
* optional string payment_method_id = 14;
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentMethodShortName = function() {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentMethodId = function() {
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 14, ""));
|
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 14, ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15976,16 +15976,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentMethodShortName = func
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setPaymentMethodShortName = function(value) {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setPaymentMethodId = function(value) {
|
||||||
return jspb.Message.setProto3StringField(this, 14, value);
|
return jspb.Message.setProto3StringField(this, 14, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional string base_currency_code = 15;
|
* optional string payment_method_short_name = 15;
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getBaseCurrencyCode = function() {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentMethodShortName = function() {
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 15, ""));
|
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 15, ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15994,16 +15994,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getBaseCurrencyCode = function()
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setBaseCurrencyCode = function(value) {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setPaymentMethodShortName = function(value) {
|
||||||
return jspb.Message.setProto3StringField(this, 15, value);
|
return jspb.Message.setProto3StringField(this, 15, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional string counter_currency_code = 16;
|
* optional string base_currency_code = 16;
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getCounterCurrencyCode = function() {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getBaseCurrencyCode = function() {
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 16, ""));
|
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 16, ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16012,17 +16012,35 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getCounterCurrencyCode = functio
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setCounterCurrencyCode = function(value) {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setBaseCurrencyCode = function(value) {
|
||||||
return jspb.Message.setProto3StringField(this, 16, value);
|
return jspb.Message.setProto3StringField(this, 16, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional uint64 date = 17;
|
* optional string counter_currency_code = 17;
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getCounterCurrencyCode = function() {
|
||||||
|
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 17, ""));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} value
|
||||||
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
|
*/
|
||||||
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setCounterCurrencyCode = function(value) {
|
||||||
|
return jspb.Message.setProto3StringField(this, 17, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* optional uint64 date = 18;
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getDate = function() {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getDate = function() {
|
||||||
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 17, 0));
|
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 18, 0));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -16031,16 +16049,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getDate = function() {
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setDate = function(value) {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setDate = function(value) {
|
||||||
return jspb.Message.setProto3IntField(this, 17, value);
|
return jspb.Message.setProto3IntField(this, 18, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional string state = 18;
|
* optional string state = 19;
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getState = function() {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.getState = function() {
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 18, ""));
|
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 19, ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -16049,25 +16067,7 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getState = function() {
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setState = function(value) {
|
proto.io.haveno.protobuffer.OfferInfo.prototype.setState = function(value) {
|
||||||
return jspb.Message.setProto3StringField(this, 18, value);
|
return jspb.Message.setProto3StringField(this, 19, value);
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* optional uint64 seller_security_deposit = 19;
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.getSellerSecurityDeposit = function() {
|
|
||||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 19, "0"));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} value
|
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
|
|
||||||
*/
|
|
||||||
proto.io.haveno.protobuffer.OfferInfo.prototype.setSellerSecurityDeposit = function(value) {
|
|
||||||
return jspb.Message.setProto3StringIntField(this, 19, value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
2
dist/protobuf/grpc_pb.js.map
vendored
2
dist/protobuf/grpc_pb.js.map
vendored
File diff suppressed because one or more lines are too long
12
dist/protobuf/pb_pb.d.ts
vendored
12
dist/protobuf/pb_pb.d.ts
vendored
|
@ -2773,11 +2773,11 @@ export class OfferPayload extends jspb.Message {
|
||||||
getMakerFee(): number;
|
getMakerFee(): number;
|
||||||
setMakerFee(value: number): OfferPayload;
|
setMakerFee(value: number): OfferPayload;
|
||||||
|
|
||||||
getBuyerSecurityDeposit(): number;
|
getBuyerSecurityDepositPct(): number;
|
||||||
setBuyerSecurityDeposit(value: number): OfferPayload;
|
setBuyerSecurityDepositPct(value: number): OfferPayload;
|
||||||
|
|
||||||
getSellerSecurityDeposit(): number;
|
getSellerSecurityDepositPct(): number;
|
||||||
setSellerSecurityDeposit(value: number): OfferPayload;
|
setSellerSecurityDepositPct(value: number): OfferPayload;
|
||||||
|
|
||||||
getMaxTradeLimit(): number;
|
getMaxTradeLimit(): number;
|
||||||
setMaxTradeLimit(value: number): OfferPayload;
|
setMaxTradeLimit(value: number): OfferPayload;
|
||||||
|
@ -2855,8 +2855,8 @@ export namespace OfferPayload {
|
||||||
versionNr: string,
|
versionNr: string,
|
||||||
blockHeightAtOfferCreation: number,
|
blockHeightAtOfferCreation: number,
|
||||||
makerFee: number,
|
makerFee: number,
|
||||||
buyerSecurityDeposit: number,
|
buyerSecurityDepositPct: number,
|
||||||
sellerSecurityDeposit: number,
|
sellerSecurityDepositPct: number,
|
||||||
maxTradeLimit: number,
|
maxTradeLimit: number,
|
||||||
maxTradePeriod: number,
|
maxTradePeriod: number,
|
||||||
useAutoClose: boolean,
|
useAutoClose: boolean,
|
||||||
|
|
44
dist/protobuf/pb_pb.js
vendored
44
dist/protobuf/pb_pb.js
vendored
|
@ -25014,8 +25014,8 @@ proto.io.haveno.protobuffer.OfferPayload.toObject = function(includeInstance, ms
|
||||||
versionNr: jspb.Message.getFieldWithDefault(msg, 19, ""),
|
versionNr: jspb.Message.getFieldWithDefault(msg, 19, ""),
|
||||||
blockHeightAtOfferCreation: jspb.Message.getFieldWithDefault(msg, 20, 0),
|
blockHeightAtOfferCreation: jspb.Message.getFieldWithDefault(msg, 20, 0),
|
||||||
makerFee: jspb.Message.getFieldWithDefault(msg, 21, 0),
|
makerFee: jspb.Message.getFieldWithDefault(msg, 21, 0),
|
||||||
buyerSecurityDeposit: jspb.Message.getFieldWithDefault(msg, 22, 0),
|
buyerSecurityDepositPct: jspb.Message.getFloatingPointFieldWithDefault(msg, 22, 0.0),
|
||||||
sellerSecurityDeposit: jspb.Message.getFieldWithDefault(msg, 23, 0),
|
sellerSecurityDepositPct: jspb.Message.getFloatingPointFieldWithDefault(msg, 23, 0.0),
|
||||||
maxTradeLimit: jspb.Message.getFieldWithDefault(msg, 24, 0),
|
maxTradeLimit: jspb.Message.getFieldWithDefault(msg, 24, 0),
|
||||||
maxTradePeriod: jspb.Message.getFieldWithDefault(msg, 25, 0),
|
maxTradePeriod: jspb.Message.getFieldWithDefault(msg, 25, 0),
|
||||||
useAutoClose: jspb.Message.getBooleanFieldWithDefault(msg, 26, false),
|
useAutoClose: jspb.Message.getBooleanFieldWithDefault(msg, 26, false),
|
||||||
|
@ -25152,12 +25152,12 @@ proto.io.haveno.protobuffer.OfferPayload.deserializeBinaryFromReader = function(
|
||||||
msg.setMakerFee(value);
|
msg.setMakerFee(value);
|
||||||
break;
|
break;
|
||||||
case 22:
|
case 22:
|
||||||
var value = /** @type {number} */ (reader.readInt64());
|
var value = /** @type {number} */ (reader.readDouble());
|
||||||
msg.setBuyerSecurityDeposit(value);
|
msg.setBuyerSecurityDepositPct(value);
|
||||||
break;
|
break;
|
||||||
case 23:
|
case 23:
|
||||||
var value = /** @type {number} */ (reader.readInt64());
|
var value = /** @type {number} */ (reader.readDouble());
|
||||||
msg.setSellerSecurityDeposit(value);
|
msg.setSellerSecurityDepositPct(value);
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
var value = /** @type {number} */ (reader.readInt64());
|
var value = /** @type {number} */ (reader.readInt64());
|
||||||
|
@ -25392,16 +25392,16 @@ proto.io.haveno.protobuffer.OfferPayload.serializeBinaryToWriter = function(mess
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getBuyerSecurityDeposit();
|
f = message.getBuyerSecurityDepositPct();
|
||||||
if (f !== 0) {
|
if (f !== 0.0) {
|
||||||
writer.writeInt64(
|
writer.writeDouble(
|
||||||
22,
|
22,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
f = message.getSellerSecurityDeposit();
|
f = message.getSellerSecurityDepositPct();
|
||||||
if (f !== 0) {
|
if (f !== 0.0) {
|
||||||
writer.writeInt64(
|
writer.writeDouble(
|
||||||
23,
|
23,
|
||||||
f
|
f
|
||||||
);
|
);
|
||||||
|
@ -25953,11 +25953,11 @@ proto.io.haveno.protobuffer.OfferPayload.prototype.setMakerFee = function(value)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional int64 buyer_security_deposit = 22;
|
* optional double buyer_security_deposit_pct = 22;
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferPayload.prototype.getBuyerSecurityDeposit = function() {
|
proto.io.haveno.protobuffer.OfferPayload.prototype.getBuyerSecurityDepositPct = function() {
|
||||||
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 22, 0));
|
return /** @type {number} */ (jspb.Message.getFloatingPointFieldWithDefault(this, 22, 0.0));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -25965,17 +25965,17 @@ proto.io.haveno.protobuffer.OfferPayload.prototype.getBuyerSecurityDeposit = fun
|
||||||
* @param {number} value
|
* @param {number} value
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferPayload} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferPayload} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferPayload.prototype.setBuyerSecurityDeposit = function(value) {
|
proto.io.haveno.protobuffer.OfferPayload.prototype.setBuyerSecurityDepositPct = function(value) {
|
||||||
return jspb.Message.setProto3IntField(this, 22, value);
|
return jspb.Message.setProto3FloatField(this, 22, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional int64 seller_security_deposit = 23;
|
* optional double seller_security_deposit_pct = 23;
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferPayload.prototype.getSellerSecurityDeposit = function() {
|
proto.io.haveno.protobuffer.OfferPayload.prototype.getSellerSecurityDepositPct = function() {
|
||||||
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 23, 0));
|
return /** @type {number} */ (jspb.Message.getFloatingPointFieldWithDefault(this, 23, 0.0));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -25983,8 +25983,8 @@ proto.io.haveno.protobuffer.OfferPayload.prototype.getSellerSecurityDeposit = fu
|
||||||
* @param {number} value
|
* @param {number} value
|
||||||
* @return {!proto.io.haveno.protobuffer.OfferPayload} returns this
|
* @return {!proto.io.haveno.protobuffer.OfferPayload} returns this
|
||||||
*/
|
*/
|
||||||
proto.io.haveno.protobuffer.OfferPayload.prototype.setSellerSecurityDeposit = function(value) {
|
proto.io.haveno.protobuffer.OfferPayload.prototype.setSellerSecurityDepositPct = function(value) {
|
||||||
return jspb.Message.setProto3IntField(this, 23, value);
|
return jspb.Message.setProto3FloatField(this, 23, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
2
dist/protobuf/pb_pb.js.map
vendored
2
dist/protobuf/pb_pb.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -78,7 +78,7 @@ const defaultTradeConfig: Partial<TradeContext> = {
|
||||||
offerMinAmount: undefined,
|
offerMinAmount: undefined,
|
||||||
assetCode: "usd", // counter asset to trade
|
assetCode: "usd", // counter asset to trade
|
||||||
makerPaymentAccountId: undefined,
|
makerPaymentAccountId: undefined,
|
||||||
buyerSecurityDepositPct: 0.15,
|
securityDepositPct: 0.15,
|
||||||
price: undefined, // use market price if undefined
|
price: undefined, // use market price if undefined
|
||||||
triggerPrice: undefined,
|
triggerPrice: undefined,
|
||||||
awaitFundsToTakeOffer: true,
|
awaitFundsToTakeOffer: true,
|
||||||
|
@ -131,7 +131,7 @@ class TradeContext {
|
||||||
offerMinAmount?: bigint;
|
offerMinAmount?: bigint;
|
||||||
tradeAmount?: bigint; // trade amount within offer range
|
tradeAmount?: bigint; // trade amount within offer range
|
||||||
makerPaymentAccountId?: string;
|
makerPaymentAccountId?: string;
|
||||||
buyerSecurityDepositPct?: number;
|
securityDepositPct?: number;
|
||||||
price?: number;
|
price?: number;
|
||||||
priceMargin?: number;
|
priceMargin?: number;
|
||||||
triggerPrice?: number;
|
triggerPrice?: number;
|
||||||
|
@ -246,7 +246,7 @@ class TradeContext {
|
||||||
str += "\nTrade amount: " + this.tradeAmount;
|
str += "\nTrade amount: " + this.tradeAmount;
|
||||||
str += "\nMin amount: " + this.offerMinAmount;
|
str += "\nMin amount: " + this.offerMinAmount;
|
||||||
str += "\nMax amount: " + this.offerAmount;
|
str += "\nMax amount: " + this.offerAmount;
|
||||||
str += "\nSecurity deposit percent: " + this.buyerSecurityDepositPct;
|
str += "\nSecurity deposit percent: " + this.securityDepositPct;
|
||||||
str += "\nMaker balance before offer: " + this.maker.balancesBeforeOffer?.getBalance();
|
str += "\nMaker balance before offer: " + this.maker.balancesBeforeOffer?.getBalance();
|
||||||
str += "\nMaker split output tx fee: " + this.maker.splitOutputTxFee;
|
str += "\nMaker split output tx fee: " + this.maker.splitOutputTxFee;
|
||||||
if (this.offer) str += "\nMaker trade fee: " + this.offer!.getMakerFee();
|
if (this.offer) str += "\nMaker trade fee: " + this.offer!.getMakerFee();
|
||||||
|
@ -1512,9 +1512,9 @@ test("Can complete a trade within a range", async () => {
|
||||||
// execute trade
|
// execute trade
|
||||||
await executeTrade({
|
await executeTrade({
|
||||||
price: 142.23,
|
price: 142.23,
|
||||||
offerAmount: HavenoUtils.xmrToAtomicUnits(1),
|
offerAmount: HavenoUtils.xmrToAtomicUnits(2),
|
||||||
offerMinAmount: HavenoUtils.xmrToAtomicUnits(.15),
|
offerMinAmount: HavenoUtils.xmrToAtomicUnits(.15),
|
||||||
tradeAmount: HavenoUtils.xmrToAtomicUnits(.578),
|
tradeAmount: HavenoUtils.xmrToAtomicUnits(1),
|
||||||
testPayoutUnlocked: true, // override to test unlock
|
testPayoutUnlocked: true, // override to test unlock
|
||||||
makerPaymentAccountId: makerPaymentAccount.getId(),
|
makerPaymentAccountId: makerPaymentAccount.getId(),
|
||||||
takerPaymentAccountId: takerPaymentAccount.getId(),
|
takerPaymentAccountId: takerPaymentAccount.getId(),
|
||||||
|
@ -2479,7 +2479,7 @@ async function makeOffer(ctxP?: Partial<TradeContext>): Promise<OfferInfo> {
|
||||||
ctx.offerAmount!,
|
ctx.offerAmount!,
|
||||||
ctx.assetCode!,
|
ctx.assetCode!,
|
||||||
ctx.makerPaymentAccountId!,
|
ctx.makerPaymentAccountId!,
|
||||||
ctx.buyerSecurityDepositPct!,
|
ctx.securityDepositPct!,
|
||||||
ctx.price,
|
ctx.price,
|
||||||
ctx.priceMargin,
|
ctx.priceMargin,
|
||||||
ctx.triggerPrice,
|
ctx.triggerPrice,
|
||||||
|
@ -2565,9 +2565,6 @@ async function takeOffer(ctxP: Partial<TradeContext>): Promise<TradeInfo> {
|
||||||
const trade = await ctx.taker.havenod!.takeOffer(ctx.offerId, ctx.takerPaymentAccountId!, ctx.tradeAmount);
|
const trade = await ctx.taker.havenod!.takeOffer(ctx.offerId, ctx.takerPaymentAccountId!, ctx.tradeAmount);
|
||||||
HavenoUtils.log(1, "Done taking offer " + ctx.offerId + " in " + (Date.now() - startTime) + " ms");
|
HavenoUtils.log(1, "Done taking offer " + ctx.offerId + " in " + (Date.now() - startTime) + " ms");
|
||||||
|
|
||||||
// test trade model
|
|
||||||
await testTrade(trade);
|
|
||||||
|
|
||||||
// maker is notified that offer is taken
|
// maker is notified that offer is taken
|
||||||
await wait(ctx.maxTimePeerNoticeMs);
|
await wait(ctx.maxTimePeerNoticeMs);
|
||||||
const tradeNotifications = getNotifications(makerNotifications, NotificationMessage.NotificationType.TRADE_UPDATE, trade.getTradeId());
|
const tradeNotifications = getNotifications(makerNotifications, NotificationMessage.NotificationType.TRADE_UPDATE, trade.getTradeId());
|
||||||
|
@ -2594,6 +2591,9 @@ async function takeOffer(ctxP: Partial<TradeContext>): Promise<TradeInfo> {
|
||||||
ctx.getSeller().securityDepositActual = BigInt(trade.getSellerSecurityDeposit()!);
|
ctx.getSeller().securityDepositActual = BigInt(trade.getSellerSecurityDeposit()!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test trade model
|
||||||
|
await testTrade(trade, ctx);
|
||||||
|
|
||||||
// test buyer and seller balances after offer taken
|
// test buyer and seller balances after offer taken
|
||||||
if (!ctx.concurrentTrades) {
|
if (!ctx.concurrentTrades) {
|
||||||
ctx.arbitrator!.trade = await ctx.arbitrator.havenod!.getTrade(ctx.offerId!);
|
ctx.arbitrator!.trade = await ctx.arbitrator.havenod!.getTrade(ctx.offerId!);
|
||||||
|
@ -2624,7 +2624,7 @@ async function takeOffer(ctxP: Partial<TradeContext>): Promise<TradeInfo> {
|
||||||
|
|
||||||
// taker can get trade
|
// taker can get trade
|
||||||
let fetchedTrade: TradeInfo = await ctx.taker.havenod!.getTrade(trade.getTradeId());
|
let fetchedTrade: TradeInfo = await ctx.taker.havenod!.getTrade(trade.getTradeId());
|
||||||
await testTrade(fetchedTrade);
|
await testTrade(fetchedTrade, ctx);
|
||||||
assert(moneroTs.GenUtils.arrayContains(["DEPOSITS_PUBLISHED", "DEPOSITS_CONFIRMED", "DEPOSITS_UNLOCKED"], fetchedTrade.getPhase()), "Unexpected trade phase: " + fetchedTrade.getPhase());
|
assert(moneroTs.GenUtils.arrayContains(["DEPOSITS_PUBLISHED", "DEPOSITS_CONFIRMED", "DEPOSITS_UNLOCKED"], fetchedTrade.getPhase()), "Unexpected trade phase: " + fetchedTrade.getPhase());
|
||||||
// TODO: more fetched trade tests
|
// TODO: more fetched trade tests
|
||||||
|
|
||||||
|
@ -2640,14 +2640,19 @@ async function takeOffer(ctxP: Partial<TradeContext>): Promise<TradeInfo> {
|
||||||
|
|
||||||
// maker can get trade
|
// maker can get trade
|
||||||
fetchedTrade = await ctx.maker.havenod!.getTrade(trade.getTradeId());
|
fetchedTrade = await ctx.maker.havenod!.getTrade(trade.getTradeId());
|
||||||
await testTrade(fetchedTrade);
|
await testTrade(fetchedTrade, ctx);
|
||||||
assert(moneroTs.GenUtils.arrayContains(["DEPOSITS_PUBLISHED", "DEPOSITS_CONFIRMED", "DEPOSITS_UNLOCKED"], fetchedTrade.getPhase()), "Unexpected trade phase: " + fetchedTrade.getPhase());
|
assert(moneroTs.GenUtils.arrayContains(["DEPOSITS_PUBLISHED", "DEPOSITS_CONFIRMED", "DEPOSITS_UNLOCKED"], fetchedTrade.getPhase()), "Unexpected trade phase: " + fetchedTrade.getPhase());
|
||||||
return trade;
|
return trade;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testTrade(trade: TradeInfo) {
|
async function testTrade(trade: TradeInfo, ctx: TradeContext) {
|
||||||
assert(BigInt(trade.getBuyerSecurityDeposit()) > 0n);
|
expect(BigInt(trade.getAmount())).toEqual(ctx!.tradeAmount);
|
||||||
assert(BigInt(trade.getSellerSecurityDeposit()) > 0n);
|
|
||||||
|
// test security deposit = max(.1, trade amount * security deposit pct)
|
||||||
|
const expectedSecurityDeposit = HavenoUtils.xmrToAtomicUnits(Math.max(.1, HavenoUtils.atomicUnitsToXmr(ctx.tradeAmount!) * ctx.securityDepositPct!));
|
||||||
|
expect(BigInt(trade.getBuyerSecurityDeposit())).toEqual(expectedSecurityDeposit - ctx.getBuyer().depositTxFee);
|
||||||
|
expect(BigInt(trade.getSellerSecurityDeposit())).toEqual(expectedSecurityDeposit - ctx.getSeller().depositTxFee);
|
||||||
|
|
||||||
// TODO: test more fields
|
// TODO: test more fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3614,24 +3619,12 @@ function testCryptoPaymentAccountsEqual(acct1: PaymentAccount, acct2: PaymentAcc
|
||||||
|
|
||||||
function testOffer(offer: OfferInfo, ctx?: Partial<TradeContext>) {
|
function testOffer(offer: OfferInfo, ctx?: Partial<TradeContext>) {
|
||||||
expect(offer.getId().length).toBeGreaterThan(0);
|
expect(offer.getId().length).toBeGreaterThan(0);
|
||||||
// TODO: test that trade amount * pct = security deposit
|
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
if (BigInt(offer.getBuyerSecurityDeposit()) == TestConfig.minSecurityDeposit) {
|
expect(offer.getBuyerSecurityDepositPct()).toEqual(ctx?.securityDepositPct);
|
||||||
expect(BigInt(offer.getSellerSecurityDeposit())).toEqual(BigInt(offer.getBuyerSecurityDeposit()));
|
expect(offer.getSellerSecurityDepositPct()).toEqual(ctx?.securityDepositPct);
|
||||||
} else {
|
|
||||||
let buyerSecurityDepositPct = HavenoUtils.divideBI(BigInt(offer.getBuyerSecurityDeposit()), BigInt(offer.getAmount()));
|
|
||||||
let sellerSecurityDepositPct = HavenoUtils.divideBI(BigInt(offer.getSellerSecurityDeposit()), BigInt(offer.getAmount()));
|
|
||||||
if (ctx.reserveExactAmount) {
|
|
||||||
const tolerance = 0.000001;
|
|
||||||
assert(ctx.buyerSecurityDepositPct! - buyerSecurityDepositPct < tolerance);
|
|
||||||
assert(ctx.buyerSecurityDepositPct! - sellerSecurityDepositPct < tolerance);
|
|
||||||
} else {
|
|
||||||
expect(buyerSecurityDepositPct).toEqual(ctx.buyerSecurityDepositPct);
|
|
||||||
expect(sellerSecurityDepositPct).toEqual(ctx.buyerSecurityDepositPct); // TODO: using same security deposit config for buyer and seller
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(offer.getUseMarketBasedPrice()).toEqual(!ctx?.price);
|
expect(offer.getUseMarketBasedPrice()).toEqual(!ctx?.price);
|
||||||
expect(offer.getMarketPriceMarginPct()).toEqual(ctx?.priceMargin ? ctx?.priceMargin : 0);
|
expect(offer.getMarketPriceMarginPct()).toEqual(ctx?.priceMargin ? ctx?.priceMargin : 0);
|
||||||
|
|
||||||
// TODO: test rest of offer
|
// TODO: test rest of offer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -995,7 +995,7 @@ export default class HavenoClient {
|
||||||
* @param {bigint} amount - amount of XMR to trade
|
* @param {bigint} amount - amount of XMR to trade
|
||||||
* @param {string} assetCode - asset code to trade for XMR
|
* @param {string} assetCode - asset code to trade for XMR
|
||||||
* @param {string} paymentAccountId - payment account id
|
* @param {string} paymentAccountId - payment account id
|
||||||
* @param {number} buyerSecurityDepositPct - buyer security deposit as % of trade amount
|
* @param {number} securityDepositPct - security deposit as % of trade amount for buyer and seller
|
||||||
* @param {number} price - trade price (optional, default to market price)
|
* @param {number} price - trade price (optional, default to market price)
|
||||||
* @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 {number} triggerPrice - price to remove offer (optional)
|
* @param {number} triggerPrice - price to remove offer (optional)
|
||||||
|
@ -1007,19 +1007,20 @@ export default class HavenoClient {
|
||||||
amount: bigint,
|
amount: bigint,
|
||||||
assetCode: string,
|
assetCode: string,
|
||||||
paymentAccountId: string,
|
paymentAccountId: string,
|
||||||
buyerSecurityDepositPct: number,
|
securityDepositPct: number,
|
||||||
price?: number,
|
price?: number,
|
||||||
marketPriceMarginPct?: number,
|
marketPriceMarginPct?: number,
|
||||||
triggerPrice?: number,
|
triggerPrice?: number,
|
||||||
minAmount?: bigint,
|
minAmount?: bigint,
|
||||||
reserveExactAmount?: boolean): Promise<OfferInfo> {
|
reserveExactAmount?: boolean): Promise<OfferInfo> {
|
||||||
|
console.log("Posting offer with security deposit %: " + securityDepositPct)
|
||||||
try {
|
try {
|
||||||
const request = new PostOfferRequest()
|
const request = new PostOfferRequest()
|
||||||
.setDirection(direction)
|
.setDirection(direction)
|
||||||
.setAmount(amount.toString())
|
.setAmount(amount.toString())
|
||||||
.setCurrencyCode(assetCode)
|
.setCurrencyCode(assetCode)
|
||||||
.setPaymentAccountId(paymentAccountId)
|
.setPaymentAccountId(paymentAccountId)
|
||||||
.setBuyerSecurityDepositPct(buyerSecurityDepositPct)
|
.setBuyerSecurityDepositPct(securityDepositPct)
|
||||||
.setUseMarketBasedPrice(price === undefined)
|
.setUseMarketBasedPrice(price === undefined)
|
||||||
.setMinAmount(minAmount ? minAmount.toString() : amount.toString());
|
.setMinAmount(minAmount ? minAmount.toString() : amount.toString());
|
||||||
if (price) request.setPrice(price.toString());
|
if (price) request.setPrice(price.toString());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue