Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-dydx committed Sep 28, 2023
1 parent a8e785c commit 377a08d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions v4-client-js/examples/cancel_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ async function test(): Promise<void> {
console.log(client);
const subaccount = new Subaccount(wallet, 0);

/*
Note this example places a stateful order.
Programmatic traders should generally not use stateful orders for following reasons:
- Stateful orders received out of order by validators will fail sequence number validation and be dropped.

Check failure on line 27 in v4-client-js/examples/cancel_example.ts

View workflow job for this annotation

GitHub Actions / CI

This line has a length of 108. Maximum allowed is 100
- Stateful orders have worse time priority since they are only matched after they are included on the block.

Check failure on line 28 in v4-client-js/examples/cancel_example.ts

View workflow job for this annotation

GitHub Actions / CI

This line has a length of 110. Maximum allowed is 100

Check failure on line 28 in v4-client-js/examples/cancel_example.ts

View workflow job for this annotation

GitHub Actions / CI

Irregular whitespace not allowed

Check failure on line 28 in v4-client-js/examples/cancel_example.ts

View workflow job for this annotation

GitHub Actions / CI

Irregular whitespace not allowed
- Stateful order rate limits are more restrictive than Short-Term orders, specifically max 2 per block / 20 per 100 blocks.

Check failure on line 29 in v4-client-js/examples/cancel_example.ts

View workflow job for this annotation

GitHub Actions / CI

This line has a length of 125. Maximum allowed is 100
- Stateful orders can only be canceled after they’ve been included in a block.
*/
const longTermOrderClientId = randomInt(MAX_CLIENT_ID);
try {
// place a long term order
Expand Down
4 changes: 2 additions & 2 deletions v4-client-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v4-client-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dydxprotocol/v4-client-js",
"version": "0.38.1",
"version": "0.38.2",
"description": "General client library for the new dYdX system (v4 decentralized)",
"main": "build/src/index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion v4-client-js/src/clients/composite-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Order_ConditionType, Order_TimeInForce } from '@dydxprotocol/v4-proto/s
import Long from 'long';
import protobuf from 'protobufjs';

import { isStatefulOrder } from '../lib/validation';
import { isStatefulOrder, verifyOrderFlags } from '../lib/validation';
import { OrderFlags } from '../types';
import {
DYDX_DENOM,
Expand Down Expand Up @@ -519,6 +519,10 @@ export class CompositeClient {
const market = marketsResponse.markets[marketId];
const clobPairId = market.clobPairId;

if (!verifyOrderFlags(orderFlags)) {
throw new Error('Invalid order flags: ' + orderFlags);

Check failure on line 523 in v4-client-js/src/clients/composite-client.ts

View workflow job for this annotation

GitHub Actions / CI

Unexpected string concatenation
}

let goodTilBlockTime;
if (isStatefulOrder(orderFlags)) {
if (goodTilTimeInSeconds === 0) {
Expand Down
5 changes: 5 additions & 0 deletions v4-client-js/src/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ function verifyNumberIsUint32(num: number): boolean {
return num >= 0 && num <= MAX_UINT_32;
}

export function verifyOrderFlags(orderFlags: OrderFlags): boolean {
return orderFlags === OrderFlags.SHORT_TERM ||
orderFlags === OrderFlags.LONG_TERM || orderFlags === OrderFlags.CONDITIONAL;
}

export function isStatefulOrder(orderFlags: OrderFlags): boolean {
return orderFlags === OrderFlags.LONG_TERM || orderFlags === OrderFlags.CONDITIONAL;
}
Expand Down

0 comments on commit 377a08d

Please sign in to comment.