must provide fixed price unless using market price

This commit is contained in:
woodser 2022-11-24 17:06:45 +00:00
parent ae8d9a1839
commit 428e22f7b1
2 changed files with 8 additions and 8 deletions

View File

@ -1088,7 +1088,7 @@ test("Can prepare for trading", async () => {
await prepareForTrading(4, user1, user2); await prepareForTrading(4, user1, user2);
}); });
test("Can make and remove an offer", async () => { test("Can post and remove an offer", async () => {
// wait for user1 to have unlocked balance to post offer // wait for user1 to have unlocked balance to post offer
await waitForAvailableBalance(BigInt("250000000000") * BigInt("2"), user1); await waitForAvailableBalance(BigInt("250000000000") * BigInt("2"), user1);
@ -1495,7 +1495,7 @@ test("Invalidates offers when reserved funds are spent", async () => {
// TODO (woodser): test arbitrator state too // TODO (woodser): test arbitrator state too
// TODO (woodser): test breaking protocol after depositing to multisig (e.g. don't send payment account payload by deleting it) // TODO (woodser): test breaking protocol after depositing to multisig (e.g. don't send payment account payload by deleting it)
test("Handles unexpected errors during trade initialization", async () => { test("Can handle unexpected errors during trade initialization", async () => {
let traders: HavenoClient[] = []; let traders: HavenoClient[] = [];
let err: any; let err: any;
try { try {
@ -2056,7 +2056,7 @@ async function testTradePayoutUnlock(ctx: TradeContext) {
// test after payout unlocked // test after payout unlocked
if (payoutTx?.getIsLocked()) { if (payoutTx?.getIsLocked()) {
await mineToHeight(height + 10); await mineToHeight(height + 10);
await wait(TestConfig.maxWalletStartupMs + TestConfig.walletSyncPeriodMs); await wait(TestConfig.maxWalletStartupMs + TestConfig.walletSyncPeriodMs * 2);
} }
await testTradeState(await ctx.buyer!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_UNLOCKED"]}); await testTradeState(await ctx.buyer!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_UNLOCKED"]});
await testTradeState(await ctx.seller!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_UNLOCKED"]}); await testTradeState(await ctx.seller!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_UNLOCKED"]});

View File

@ -4,7 +4,7 @@ import HavenoUtils from "./utils/HavenoUtils";
import TaskLooper from "./utils/TaskLooper"; import TaskLooper from "./utils/TaskLooper";
import type * as grpcWeb from "grpc-web"; import type * as grpcWeb from "grpc-web";
import { GetVersionClient, AccountClient, MoneroConnectionsClient, DisputesClient, DisputeAgentsClient, NotificationsClient, WalletsClient, PriceClient, OffersClient, PaymentAccountsClient, TradesClient, ShutdownServerClient, MoneroNodeClient } from './protobuf/GrpcServiceClientPb'; import { GetVersionClient, AccountClient, MoneroConnectionsClient, DisputesClient, DisputeAgentsClient, NotificationsClient, WalletsClient, PriceClient, OffersClient, PaymentAccountsClient, TradesClient, ShutdownServerClient, MoneroNodeClient } from './protobuf/GrpcServiceClientPb';
import { GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, UnregisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, ValidateFormFieldRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, CreateOfferRequest, CreateOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetXmrPrimaryAddressRequest, GetXmrPrimaryAddressReply, GetXmrNewSubaddressRequest, GetXmrNewSubaddressReply, ConfirmPaymentStartedRequest, ConfirmPaymentReceivedRequest, CompleteTradeRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, RelayXmrTxRequest, RelayXmrTxReply, CreateAccountRequest, AccountExistsRequest, AccountExistsReply, DeleteAccountRequest, OpenAccountRequest, IsAccountOpenRequest, IsAccountOpenReply, CloseAccountRequest, ChangePasswordRequest, BackupAccountRequest, BackupAccountReply, RestoreAccountRequest, StopRequest, NotificationMessage, RegisterNotificationListenerRequest, SendNotificationRequest, UrlConnection, AddConnectionRequest, RemoveConnectionRequest, GetConnectionRequest, GetConnectionsRequest, SetConnectionRequest, CheckConnectionRequest, CheckConnectionsReply, CheckConnectionsRequest, StartCheckingConnectionsRequest, StopCheckingConnectionsRequest, GetBestAvailableConnectionRequest, SetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestAvailableConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartMoneroNodeRequest, StopMoneroNodeRequest, IsMoneroNodeOnlineRequest, IsMoneroNodeOnlineReply, GetMoneroNodeSettingsRequest, GetMoneroNodeSettingsReply } from "./protobuf/grpc_pb"; import { GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, UnregisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, ValidateFormFieldRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, PostOfferRequest, PostOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetXmrPrimaryAddressRequest, GetXmrPrimaryAddressReply, GetXmrNewSubaddressRequest, GetXmrNewSubaddressReply, ConfirmPaymentStartedRequest, ConfirmPaymentReceivedRequest, CompleteTradeRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, RelayXmrTxRequest, RelayXmrTxReply, CreateAccountRequest, AccountExistsRequest, AccountExistsReply, DeleteAccountRequest, OpenAccountRequest, IsAccountOpenRequest, IsAccountOpenReply, CloseAccountRequest, ChangePasswordRequest, BackupAccountRequest, BackupAccountReply, RestoreAccountRequest, StopRequest, NotificationMessage, RegisterNotificationListenerRequest, SendNotificationRequest, UrlConnection, AddConnectionRequest, RemoveConnectionRequest, GetConnectionRequest, GetConnectionsRequest, SetConnectionRequest, CheckConnectionRequest, CheckConnectionsReply, CheckConnectionsRequest, StartCheckingConnectionsRequest, StopCheckingConnectionsRequest, GetBestAvailableConnectionRequest, SetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestAvailableConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartMoneroNodeRequest, StopMoneroNodeRequest, IsMoneroNodeOnlineRequest, IsMoneroNodeOnlineReply, GetMoneroNodeSettingsRequest, GetMoneroNodeSettingsReply } from "./protobuf/grpc_pb";
import { PaymentMethod, PaymentAccountForm, PaymentAccountFormField, PaymentAccount, PaymentAccountPayload, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, MoneroNodeSettings } from "./protobuf/pb_pb"; import { PaymentMethod, PaymentAccountForm, PaymentAccountFormField, PaymentAccount, PaymentAccountPayload, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, MoneroNodeSettings } from "./protobuf/pb_pb";
/** /**
@ -1231,19 +1231,19 @@ export default class HavenoClient {
triggerPrice?: number, triggerPrice?: number,
minAmount?: bigint): Promise<OfferInfo> { minAmount?: bigint): Promise<OfferInfo> {
try { try {
const request = new CreateOfferRequest() 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(buyerSecurityDepositPct)
.setPrice(price ? price.toString() : "1.0") // TOOD (woodser): positive price required even if using market price? .setUseMarketBasedPrice(price === undefined)
.setUseMarketBasedPrice(price === undefined) // TODO (woodser): this field is redundant; remove from api
.setMinAmount(minAmount ? minAmount.toString() : amount.toString()); .setMinAmount(minAmount ? minAmount.toString() : amount.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());
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
this._offersClient.createOffer(request, {password: this._password}, function(err: grpcWeb.RpcError, response: CreateOfferReply) { this._offersClient.postOffer(request, {password: this._password}, function(err: grpcWeb.RpcError, response: PostOfferReply) {
if (err) reject(err); if (err) reject(err);
else resolve(response.getOffer()!); else resolve(response.getOffer()!);
}); });