test security deposit based on trade amount

This commit is contained in:
woodser 2023-10-30 17:11:33 -04:00
parent cfdec7115c
commit 35c0cf9301
11 changed files with 176 additions and 181 deletions

View File

@ -418,7 +418,7 @@ export default class HavenoClient {
* @param {bigint} amount - amount of XMR to trade
* @param {string} assetCode - asset code to trade for XMR
* @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} marketPriceMarginPct - if using market price, % from market price to accept (optional, default 0%)
* @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)
* @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.
*

View File

@ -975,7 +975,7 @@ class HavenoClient {
* @param {bigint} amount - amount of XMR to trade
* @param {string} assetCode - asset code to trade for XMR
* @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} marketPriceMarginPct - if using market price, % from market price to accept (optional, default 0%)
* @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)
* @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 {
const request = new grpc_pb_1.PostOfferRequest()
.setDirection(direction)
.setAmount(amount.toString())
.setCurrencyCode(assetCode)
.setPaymentAccountId(paymentAccountId)
.setBuyerSecurityDepositPct(buyerSecurityDepositPct)
.setBuyerSecurityDepositPct(securityDepositPct)
.setUseMarketBasedPrice(price === undefined)
.setMinAmount(minAmount ? minAmount.toString() : amount.toString());
if (price)

File diff suppressed because one or more lines are too long

View File

@ -1609,8 +1609,11 @@ export class OfferInfo extends jspb.Message {
getMinVolume(): string;
setMinVolume(value: string): OfferInfo;
getBuyerSecurityDeposit(): string;
setBuyerSecurityDeposit(value: string): OfferInfo;
getBuyerSecurityDepositPct(): number;
setBuyerSecurityDepositPct(value: number): OfferInfo;
getSellerSecurityDepositPct(): number;
setSellerSecurityDepositPct(value: number): OfferInfo;
getTriggerPrice(): string;
setTriggerPrice(value: string): OfferInfo;
@ -1636,9 +1639,6 @@ export class OfferInfo extends jspb.Message {
getState(): string;
setState(value: string): OfferInfo;
getSellerSecurityDeposit(): string;
setSellerSecurityDeposit(value: string): OfferInfo;
getMakerFee(): string;
setMakerFee(value: string): OfferInfo;
@ -1688,7 +1688,8 @@ export namespace OfferInfo {
minAmount: string,
volume: string,
minVolume: string,
buyerSecurityDeposit: string,
buyerSecurityDepositPct: number,
sellerSecurityDepositPct: number,
triggerPrice: string,
paymentAccountId: string,
paymentMethodId: string,
@ -1697,7 +1698,6 @@ export namespace OfferInfo {
counterCurrencyCode: string,
date: number,
state: string,
sellerSecurityDeposit: string,
makerFee: string,
isActivated: boolean,
isMyOffer: boolean,

View File

@ -15322,16 +15322,16 @@ proto.io.haveno.protobuffer.OfferInfo.toObject = function(includeInstance, msg)
minAmount: jspb.Message.getFieldWithDefault(msg, 7, "0"),
volume: jspb.Message.getFieldWithDefault(msg, 8, ""),
minVolume: jspb.Message.getFieldWithDefault(msg, 9, ""),
buyerSecurityDeposit: jspb.Message.getFieldWithDefault(msg, 10, "0"),
triggerPrice: jspb.Message.getFieldWithDefault(msg, 11, ""),
paymentAccountId: jspb.Message.getFieldWithDefault(msg, 12, ""),
paymentMethodId: jspb.Message.getFieldWithDefault(msg, 13, ""),
paymentMethodShortName: jspb.Message.getFieldWithDefault(msg, 14, ""),
baseCurrencyCode: jspb.Message.getFieldWithDefault(msg, 15, ""),
counterCurrencyCode: jspb.Message.getFieldWithDefault(msg, 16, ""),
date: jspb.Message.getFieldWithDefault(msg, 17, 0),
state: jspb.Message.getFieldWithDefault(msg, 18, ""),
sellerSecurityDeposit: jspb.Message.getFieldWithDefault(msg, 19, "0"),
buyerSecurityDepositPct: jspb.Message.getFloatingPointFieldWithDefault(msg, 10, 0.0),
sellerSecurityDepositPct: jspb.Message.getFloatingPointFieldWithDefault(msg, 11, 0.0),
triggerPrice: jspb.Message.getFieldWithDefault(msg, 12, ""),
paymentAccountId: jspb.Message.getFieldWithDefault(msg, 13, ""),
paymentMethodId: jspb.Message.getFieldWithDefault(msg, 14, ""),
paymentMethodShortName: jspb.Message.getFieldWithDefault(msg, 15, ""),
baseCurrencyCode: jspb.Message.getFieldWithDefault(msg, 16, ""),
counterCurrencyCode: jspb.Message.getFieldWithDefault(msg, 17, ""),
date: jspb.Message.getFieldWithDefault(msg, 18, 0),
state: jspb.Message.getFieldWithDefault(msg, 19, ""),
makerFee: jspb.Message.getFieldWithDefault(msg, 20, "0"),
isActivated: jspb.Message.getBooleanFieldWithDefault(msg, 21, false),
isMyOffer: jspb.Message.getBooleanFieldWithDefault(msg, 22, false),
@ -15415,45 +15415,45 @@ proto.io.haveno.protobuffer.OfferInfo.deserializeBinaryFromReader = function(msg
msg.setMinVolume(value);
break;
case 10:
var value = /** @type {string} */ (reader.readUint64String());
msg.setBuyerSecurityDeposit(value);
var value = /** @type {number} */ (reader.readDouble());
msg.setBuyerSecurityDepositPct(value);
break;
case 11:
var value = /** @type {string} */ (reader.readString());
msg.setTriggerPrice(value);
var value = /** @type {number} */ (reader.readDouble());
msg.setSellerSecurityDepositPct(value);
break;
case 12:
var value = /** @type {string} */ (reader.readString());
msg.setPaymentAccountId(value);
msg.setTriggerPrice(value);
break;
case 13:
var value = /** @type {string} */ (reader.readString());
msg.setPaymentMethodId(value);
msg.setPaymentAccountId(value);
break;
case 14:
var value = /** @type {string} */ (reader.readString());
msg.setPaymentMethodShortName(value);
msg.setPaymentMethodId(value);
break;
case 15:
var value = /** @type {string} */ (reader.readString());
msg.setBaseCurrencyCode(value);
msg.setPaymentMethodShortName(value);
break;
case 16:
var value = /** @type {string} */ (reader.readString());
msg.setCounterCurrencyCode(value);
msg.setBaseCurrencyCode(value);
break;
case 17:
var value = /** @type {string} */ (reader.readString());
msg.setCounterCurrencyCode(value);
break;
case 18:
var value = /** @type {number} */ (reader.readUint64());
msg.setDate(value);
break;
case 18:
case 19:
var value = /** @type {string} */ (reader.readString());
msg.setState(value);
break;
case 19:
var value = /** @type {string} */ (reader.readUint64String());
msg.setSellerSecurityDeposit(value);
break;
case 20:
var value = /** @type {string} */ (reader.readUint64String());
msg.setMakerFee(value);
@ -15586,72 +15586,72 @@ proto.io.haveno.protobuffer.OfferInfo.serializeBinaryToWriter = function(message
f
);
}
f = message.getBuyerSecurityDeposit();
if (parseInt(f, 10) !== 0) {
writer.writeUint64String(
f = message.getBuyerSecurityDepositPct();
if (f !== 0.0) {
writer.writeDouble(
10,
f
);
}
f = message.getSellerSecurityDepositPct();
if (f !== 0.0) {
writer.writeDouble(
11,
f
);
}
f = message.getTriggerPrice();
if (f.length > 0) {
writer.writeString(
11,
12,
f
);
}
f = message.getPaymentAccountId();
if (f.length > 0) {
writer.writeString(
12,
13,
f
);
}
f = message.getPaymentMethodId();
if (f.length > 0) {
writer.writeString(
13,
14,
f
);
}
f = message.getPaymentMethodShortName();
if (f.length > 0) {
writer.writeString(
14,
15,
f
);
}
f = message.getBaseCurrencyCode();
if (f.length > 0) {
writer.writeString(
15,
16,
f
);
}
f = message.getCounterCurrencyCode();
if (f.length > 0) {
writer.writeString(
16,
17,
f
);
}
f = message.getDate();
if (f !== 0) {
writer.writeUint64(
17,
18,
f
);
}
f = message.getState();
if (f.length > 0) {
writer.writeString(
18,
f
);
}
f = message.getSellerSecurityDeposit();
if (parseInt(f, 10) !== 0) {
writer.writeUint64String(
19,
f
);
@ -15892,46 +15892,46 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.setMinVolume = function(value) {
/**
* optional uint64 buyer_security_deposit = 10;
* @return {string}
* optional double buyer_security_deposit_pct = 10;
* @return {number}
*/
proto.io.haveno.protobuffer.OfferInfo.prototype.getBuyerSecurityDeposit = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 10, "0"));
proto.io.haveno.protobuffer.OfferInfo.prototype.getBuyerSecurityDepositPct = function() {
return /** @type {number} */ (jspb.Message.getFloatingPointFieldWithDefault(this, 10, 0.0));
};
/**
* @param {string} value
* @param {number} value
* @return {!proto.io.haveno.protobuffer.OfferInfo} returns this
*/
proto.io.haveno.protobuffer.OfferInfo.prototype.setBuyerSecurityDeposit = function(value) {
return jspb.Message.setProto3StringIntField(this, 10, value);
proto.io.haveno.protobuffer.OfferInfo.prototype.setBuyerSecurityDepositPct = function(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}
*/
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, ""));
};
@ -15940,16 +15940,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentAccountId = function()
* @param {string} value
* @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);
};
/**
* optional string payment_method_id = 13;
* optional string payment_account_id = 13;
* @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, ""));
};
@ -15958,16 +15958,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentMethodId = function()
* @param {string} value
* @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);
};
/**
* optional string payment_method_short_name = 14;
* optional string payment_method_id = 14;
* @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, ""));
};
@ -15976,16 +15976,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getPaymentMethodShortName = func
* @param {string} value
* @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);
};
/**
* optional string base_currency_code = 15;
* optional string payment_method_short_name = 15;
* @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, ""));
};
@ -15994,16 +15994,16 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getBaseCurrencyCode = function()
* @param {string} value
* @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);
};
/**
* optional string counter_currency_code = 16;
* optional string base_currency_code = 16;
* @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, ""));
};
@ -16012,17 +16012,35 @@ proto.io.haveno.protobuffer.OfferInfo.prototype.getCounterCurrencyCode = functio
* @param {string} value
* @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);
};
/**
* 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}
*/
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
*/
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}
*/
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
*/
proto.io.haveno.protobuffer.OfferInfo.prototype.setState = function(value) {
return jspb.Message.setProto3StringField(this, 18, 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);
return jspb.Message.setProto3StringField(this, 19, value);
};

File diff suppressed because one or more lines are too long

View File

@ -2773,11 +2773,11 @@ export class OfferPayload extends jspb.Message {
getMakerFee(): number;
setMakerFee(value: number): OfferPayload;
getBuyerSecurityDeposit(): number;
setBuyerSecurityDeposit(value: number): OfferPayload;
getBuyerSecurityDepositPct(): number;
setBuyerSecurityDepositPct(value: number): OfferPayload;
getSellerSecurityDeposit(): number;
setSellerSecurityDeposit(value: number): OfferPayload;
getSellerSecurityDepositPct(): number;
setSellerSecurityDepositPct(value: number): OfferPayload;
getMaxTradeLimit(): number;
setMaxTradeLimit(value: number): OfferPayload;
@ -2855,8 +2855,8 @@ export namespace OfferPayload {
versionNr: string,
blockHeightAtOfferCreation: number,
makerFee: number,
buyerSecurityDeposit: number,
sellerSecurityDeposit: number,
buyerSecurityDepositPct: number,
sellerSecurityDepositPct: number,
maxTradeLimit: number,
maxTradePeriod: number,
useAutoClose: boolean,

View File

@ -25014,8 +25014,8 @@ proto.io.haveno.protobuffer.OfferPayload.toObject = function(includeInstance, ms
versionNr: jspb.Message.getFieldWithDefault(msg, 19, ""),
blockHeightAtOfferCreation: jspb.Message.getFieldWithDefault(msg, 20, 0),
makerFee: jspb.Message.getFieldWithDefault(msg, 21, 0),
buyerSecurityDeposit: jspb.Message.getFieldWithDefault(msg, 22, 0),
sellerSecurityDeposit: jspb.Message.getFieldWithDefault(msg, 23, 0),
buyerSecurityDepositPct: jspb.Message.getFloatingPointFieldWithDefault(msg, 22, 0.0),
sellerSecurityDepositPct: jspb.Message.getFloatingPointFieldWithDefault(msg, 23, 0.0),
maxTradeLimit: jspb.Message.getFieldWithDefault(msg, 24, 0),
maxTradePeriod: jspb.Message.getFieldWithDefault(msg, 25, 0),
useAutoClose: jspb.Message.getBooleanFieldWithDefault(msg, 26, false),
@ -25152,12 +25152,12 @@ proto.io.haveno.protobuffer.OfferPayload.deserializeBinaryFromReader = function(
msg.setMakerFee(value);
break;
case 22:
var value = /** @type {number} */ (reader.readInt64());
msg.setBuyerSecurityDeposit(value);
var value = /** @type {number} */ (reader.readDouble());
msg.setBuyerSecurityDepositPct(value);
break;
case 23:
var value = /** @type {number} */ (reader.readInt64());
msg.setSellerSecurityDeposit(value);
var value = /** @type {number} */ (reader.readDouble());
msg.setSellerSecurityDepositPct(value);
break;
case 24:
var value = /** @type {number} */ (reader.readInt64());
@ -25392,16 +25392,16 @@ proto.io.haveno.protobuffer.OfferPayload.serializeBinaryToWriter = function(mess
f
);
}
f = message.getBuyerSecurityDeposit();
if (f !== 0) {
writer.writeInt64(
f = message.getBuyerSecurityDepositPct();
if (f !== 0.0) {
writer.writeDouble(
22,
f
);
}
f = message.getSellerSecurityDeposit();
if (f !== 0) {
writer.writeInt64(
f = message.getSellerSecurityDepositPct();
if (f !== 0.0) {
writer.writeDouble(
23,
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}
*/
proto.io.haveno.protobuffer.OfferPayload.prototype.getBuyerSecurityDeposit = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 22, 0));
proto.io.haveno.protobuffer.OfferPayload.prototype.getBuyerSecurityDepositPct = function() {
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
* @return {!proto.io.haveno.protobuffer.OfferPayload} returns this
*/
proto.io.haveno.protobuffer.OfferPayload.prototype.setBuyerSecurityDeposit = function(value) {
return jspb.Message.setProto3IntField(this, 22, value);
proto.io.haveno.protobuffer.OfferPayload.prototype.setBuyerSecurityDepositPct = function(value) {
return jspb.Message.setProto3FloatField(this, 22, value);
};
/**
* optional int64 seller_security_deposit = 23;
* optional double seller_security_deposit_pct = 23;
* @return {number}
*/
proto.io.haveno.protobuffer.OfferPayload.prototype.getSellerSecurityDeposit = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 23, 0));
proto.io.haveno.protobuffer.OfferPayload.prototype.getSellerSecurityDepositPct = function() {
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
* @return {!proto.io.haveno.protobuffer.OfferPayload} returns this
*/
proto.io.haveno.protobuffer.OfferPayload.prototype.setSellerSecurityDeposit = function(value) {
return jspb.Message.setProto3IntField(this, 23, value);
proto.io.haveno.protobuffer.OfferPayload.prototype.setSellerSecurityDepositPct = function(value) {
return jspb.Message.setProto3FloatField(this, 23, value);
};

File diff suppressed because one or more lines are too long

View File

@ -78,7 +78,7 @@ const defaultTradeConfig: Partial<TradeContext> = {
offerMinAmount: undefined,
assetCode: "usd", // counter asset to trade
makerPaymentAccountId: undefined,
buyerSecurityDepositPct: 0.15,
securityDepositPct: 0.15,
price: undefined, // use market price if undefined
triggerPrice: undefined,
awaitFundsToTakeOffer: true,
@ -131,7 +131,7 @@ class TradeContext {
offerMinAmount?: bigint;
tradeAmount?: bigint; // trade amount within offer range
makerPaymentAccountId?: string;
buyerSecurityDepositPct?: number;
securityDepositPct?: number;
price?: number;
priceMargin?: number;
triggerPrice?: number;
@ -246,7 +246,7 @@ class TradeContext {
str += "\nTrade amount: " + this.tradeAmount;
str += "\nMin amount: " + this.offerMinAmount;
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 split output tx fee: " + this.maker.splitOutputTxFee;
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
await executeTrade({
price: 142.23,
offerAmount: HavenoUtils.xmrToAtomicUnits(1),
offerAmount: HavenoUtils.xmrToAtomicUnits(2),
offerMinAmount: HavenoUtils.xmrToAtomicUnits(.15),
tradeAmount: HavenoUtils.xmrToAtomicUnits(.578),
tradeAmount: HavenoUtils.xmrToAtomicUnits(1),
testPayoutUnlocked: true, // override to test unlock
makerPaymentAccountId: makerPaymentAccount.getId(),
takerPaymentAccountId: takerPaymentAccount.getId(),
@ -2479,7 +2479,7 @@ async function makeOffer(ctxP?: Partial<TradeContext>): Promise<OfferInfo> {
ctx.offerAmount!,
ctx.assetCode!,
ctx.makerPaymentAccountId!,
ctx.buyerSecurityDepositPct!,
ctx.securityDepositPct!,
ctx.price,
ctx.priceMargin,
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);
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
await wait(ctx.maxTimePeerNoticeMs);
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()!);
}
// test trade model
await testTrade(trade, ctx);
// test buyer and seller balances after offer taken
if (!ctx.concurrentTrades) {
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
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());
// TODO: more fetched trade tests
@ -2640,15 +2640,20 @@ async function takeOffer(ctxP: Partial<TradeContext>): Promise<TradeInfo> {
// maker can get trade
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());
return trade;
}
async function testTrade(trade: TradeInfo) {
assert(BigInt(trade.getBuyerSecurityDeposit()) > 0n);
assert(BigInt(trade.getSellerSecurityDeposit()) > 0n);
// TODO: test more fields
async function testTrade(trade: TradeInfo, ctx: TradeContext) {
expect(BigInt(trade.getAmount())).toEqual(ctx!.tradeAmount);
// 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
}
async function testOpenDispute(ctxP: Partial<TradeContext>) {
@ -3613,25 +3618,13 @@ function testCryptoPaymentAccountsEqual(acct1: PaymentAccount, acct2: PaymentAcc
}
function testOffer(offer: OfferInfo, ctx?: Partial<TradeContext>) {
expect(offer.getId().length).toBeGreaterThan(0);
// TODO: test that trade amount * pct = security deposit
expect(offer.getId().length).toBeGreaterThan(0);
if (ctx) {
if (BigInt(offer.getBuyerSecurityDeposit()) == TestConfig.minSecurityDeposit) {
expect(BigInt(offer.getSellerSecurityDeposit())).toEqual(BigInt(offer.getBuyerSecurityDeposit()));
} 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.getBuyerSecurityDepositPct()).toEqual(ctx?.securityDepositPct);
expect(offer.getSellerSecurityDepositPct()).toEqual(ctx?.securityDepositPct);
expect(offer.getUseMarketBasedPrice()).toEqual(!ctx?.price);
expect(offer.getMarketPriceMarginPct()).toEqual(ctx?.priceMargin ? ctx?.priceMargin : 0);
// TODO: test rest of offer
}
}

View File

@ -995,7 +995,7 @@ export default class HavenoClient {
* @param {bigint} amount - amount of XMR to trade
* @param {string} assetCode - asset code to trade for XMR
* @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} marketPriceMarginPct - if using market price, % from market price to accept (optional, default 0%)
* @param {number} triggerPrice - price to remove offer (optional)
@ -1007,19 +1007,20 @@ export default class HavenoClient {
amount: bigint,
assetCode: string,
paymentAccountId: string,
buyerSecurityDepositPct: number,
securityDepositPct: number,
price?: number,
marketPriceMarginPct?: number,
triggerPrice?: number,
minAmount?: bigint,
reserveExactAmount?: boolean): Promise<OfferInfo> {
console.log("Posting offer with security deposit %: " + securityDepositPct)
try {
const request = new PostOfferRequest()
.setDirection(direction)
.setAmount(amount.toString())
.setCurrencyCode(assetCode)
.setPaymentAccountId(paymentAccountId)
.setBuyerSecurityDepositPct(buyerSecurityDepositPct)
.setBuyerSecurityDepositPct(securityDepositPct)
.setUseMarketBasedPrice(price === undefined)
.setMinAmount(minAmount ? minAmount.toString() : amount.toString());
if (price) request.setPrice(price.toString());