Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@cosmjs/tendermint-rpc": "^0.32.1",
"@datadog/browser-logs": "^5.23.3",
"@dydxprotocol/v4-client-js": "2.1.1",
"@dydxprotocol/v4-localization": "1.1.312",
"@dydxprotocol/v4-localization": "^1.1.313",
"@dydxprotocol/v4-proto": "^7.0.0-dev.0",
"@emotion/is-prop-valid": "^1.3.0",
"@hugocxl/react-to-image": "^0.0.9",
Expand Down Expand Up @@ -217,7 +217,9 @@
},
"pnpm": {
"overrides": {
"follow-redirects": "1.15.3"
"follow-redirects": "1.15.3",
"@injectivelabs/sdk-ts": "1.16.10",
"@injectivelabs/ts-types": "1.16.10"
Comment on lines +221 to +222
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this

}
},
"babelMacros": {
Expand Down
102 changes: 57 additions & 45 deletions pnpm-lock.yaml

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

6 changes: 6 additions & 0 deletions src/bonsai/calculators/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ function calculateSubaccountOrder(
reduceOnly: !!base.reduceOnly,
remainingSize: MustBigNumber(base.size).minus(MustBigNumber(base.totalFilled)),
removalReason: base.removalReason,
// TWAP order parameters
duration: base.duration || undefined,
interval: base.interval || undefined,
priceTolerance: base.priceTolerance || undefined,
};
order = maybeUpdateOrderIfExpired(order, protocolHeight);
return order;
Expand Down Expand Up @@ -232,6 +236,8 @@ function calculateBaseOrderStatus(
return OrderStatus.Canceling;
case IndexerOrderStatus.UNTRIGGERED:
return OrderStatus.Untriggered;
case IndexerOrderStatus.ERROR:
return OrderStatus.Canceled; // Treat ERROR status as canceled
Comment on lines +239 to +240
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this case is already handled in line 232

default:
assertNever(status);
return undefined;
Expand Down
13 changes: 12 additions & 1 deletion src/bonsai/selectors/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getCurrentMarketIdIfTradeable } from '@/state/currentMarketSelectors';
import { convertBech32Address } from '@/lib/addressUtils';
import { BIG_NUMBERS } from '@/lib/numbers';

import { IndexerOrderType } from '@/types/indexer/indexerApiGen';
import { calculateBlockRewards } from '../calculators/blockRewards';
import { calculateFills } from '../calculators/fills';
import { getMarketEffectiveInitialMarginForMarket } from '../calculators/markets';
Expand All @@ -29,7 +30,7 @@ import {
import { calculateTransfers } from '../calculators/transfers';
import { mergeLoadableStatus } from '../lib/mapLoadable';
import { selectParentSubaccountInfo } from '../socketSelectors';
import { SubaccountTransfer } from '../types/summaryTypes';
import { OrderFlags, SubaccountTransfer } from '../types/summaryTypes';
import { selectLatestIndexerHeight, selectLatestValidatorHeight } from './apiStatus';
import {
selectRawBlockTradingRewardsLiveData,
Expand Down Expand Up @@ -138,6 +139,16 @@ export const selectOrderHistory = createAppSelector([selectAccountOrders], (orde
return calculateOrderHistory(orders);
});

export const selectTWAPOrders = createAppSelector([selectAccountOrders], (orders) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there need for selecting TWAP orders that aren't open?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can simplify 148 to just filtering TWAP from selectOpenOrders instead

return orders.filter((order) =>
order.orderFlags === OrderFlags.TWAP && order.type === IndexerOrderType.TWAP
);
});

export const selectActiveTWAPOrders = createAppSelector([selectTWAPOrders], (twapOrders) => {
return calculateOpenOrders(twapOrders);
});

export const selectCurrentMarketOpenOrders = createAppSelector(
[getCurrentMarketIdIfTradeable, selectOpenOrders],
(currentMarketId, orders) =>
Expand Down
5 changes: 5 additions & 0 deletions src/bonsai/types/summaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ export enum OrderFlags {
SHORT_TERM = '0',
LONG_TERM = '64',
CONDITIONAL = '32',
TWAP = '128',
TWAP_SUBORDER = '256',
}

export type SubaccountOrder = {
Expand Down Expand Up @@ -176,6 +178,9 @@ export type SubaccountOrder = {
reduceOnly: boolean;
removalReason: string | undefined;
marginMode: MarginMode | undefined;
duration: string | undefined;
interval: string | undefined;
priceTolerance: string | undefined;
};

export enum SubaccountFillType {
Expand Down
Loading
Loading