Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate fills table to abacus-ts #1378

Open
wants to merge 81 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
d2f3489
abacus-ts-types
tyleroooo Nov 27, 2024
f887e6c
add codegen and helpers and manual types
tyleroooo Nov 27, 2024
94ef1e3
Merge remote-tracking branch 'origin/main' into tu/abacus-ts-types
tyleroooo Nov 27, 2024
71f8dd8
fixes
tyleroooo Nov 27, 2024
e0e05ff
fix
tyleroooo Nov 27, 2024
6ddeb68
add websocket layer
tyleroooo Dec 2, 2024
7c25ca7
fix
tyleroooo Dec 2, 2024
8305f2e
fix
tyleroooo Dec 2, 2024
202f169
add market tracker and helpers
tyleroooo Dec 3, 2024
27acae5
fix
tyleroooo Dec 3, 2024
7cd5506
fix
tyleroooo Dec 3, 2024
595e1a0
bunch of fixes and refactors
tyleroooo Dec 4, 2024
306b31b
fix
tyleroooo Dec 5, 2024
7a85a86
Merge remote-tracking branch 'origin/main' into tu/abacus-ts-types
tyleroooo Dec 5, 2024
91f1196
fix
tyleroooo Dec 6, 2024
15621c1
add all new
tyleroooo Dec 6, 2024
d0855de
Merge remote-tracking branch 'origin/main' into tu/abacus-ts-types
tyleroooo Dec 6, 2024
fd1a39d
fixes
tyleroooo Dec 6, 2024
0da5633
add more data
tyleroooo Dec 6, 2024
3cadec2
went wild
tyleroooo Dec 9, 2024
1c516a3
fixes
tyleroooo Dec 9, 2024
f0cfc7a
fix
tyleroooo Dec 9, 2024
0198c59
move files around, fix logging
tyleroooo Dec 10, 2024
6189fa1
fix
tyleroooo Dec 10, 2024
dcc53a8
fix
tyleroooo Dec 10, 2024
75ff184
fix
tyleroooo Dec 10, 2024
6856775
fix
tyleroooo Dec 10, 2024
88cb956
fix
tyleroooo Dec 10, 2024
4f4e061
fix
tyleroooo Dec 10, 2024
e965fb5
fix
tyleroooo Dec 10, 2024
74f78ef
start
tyleroooo Dec 10, 2024
5172c36
fix
tyleroooo Dec 10, 2024
134567d
Merge branch 'tu/abacus-ts-types' into tu/abacus-ts-2
tyleroooo Dec 10, 2024
5486c65
fix
tyleroooo Dec 10, 2024
a6fe44f
fix
tyleroooo Dec 10, 2024
07ce170
Merge branch 'tu/abacus-ts-types' into tu/abacus-ts-2
tyleroooo Dec 10, 2024
13e0acb
more types
tyleroooo Dec 11, 2024
59a27a0
updates
tyleroooo Dec 12, 2024
bfc405e
fix
tyleroooo Dec 12, 2024
917832c
fixes
tyleroooo Dec 12, 2024
9772e4d
merge
tyleroooo Dec 12, 2024
41bb0af
fix
tyleroooo Dec 12, 2024
e27402c
Merge branch 'tu/abacus-ts-types' into tu/abacus-ts-2
tyleroooo Dec 12, 2024
73d52e8
fix
tyleroooo Dec 12, 2024
2487d1d
fix horrible stupid mistake
tyleroooo Dec 12, 2024
a58d832
Merge branch 'tu/abacus-ts-types' into tu/abacus-ts-2
tyleroooo Dec 12, 2024
c419034
more calc
tyleroooo Dec 12, 2024
eadb0b4
fixes
tyleroooo Dec 13, 2024
e7d5a2a
order calculations
tyleroooo Dec 13, 2024
2c7563a
fix
tyleroooo Dec 13, 2024
dc2500a
move stuff around
tyleroooo Dec 13, 2024
d1e187c
fix
tyleroooo Dec 16, 2024
2bbe7af
add validator calls
tyleroooo Dec 16, 2024
32beb8b
Merge branch 'tu/abacus-ts-types' into tu/abacus-ts-2
tyleroooo Dec 16, 2024
4882993
fix order calcs
tyleroooo Dec 17, 2024
75c9297
Merge remote-tracking branch 'origin/main' into tu/abacus-ts-types
tyleroooo Dec 17, 2024
4399e36
dedupe
tyleroooo Dec 17, 2024
3c7a33c
Merge remote-tracking branch 'origin/tu/abacus-ts-types' into tu/abac…
tyleroooo Dec 17, 2024
a226648
fix
tyleroooo Dec 17, 2024
684de6b
fix
tyleroooo Dec 17, 2024
5fbe076
add
tyleroooo Dec 17, 2024
f3ec57f
Merge remote-tracking branch 'origin/tu/abacus-ts-types' into tu/abac…
tyleroooo Dec 17, 2024
517bd47
fix
tyleroooo Dec 17, 2024
c868496
fix
tyleroooo Dec 17, 2024
d628fd0
fix
tyleroooo Dec 17, 2024
1a9928c
fix
tyleroooo Dec 17, 2024
6e2dff3
fix
tyleroooo Dec 17, 2024
3f02331
fix
tyleroooo Dec 17, 2024
2c3419d
small fix
tyleroooo Dec 17, 2024
bd867e9
assets, immerjs, more changes
tyleroooo Dec 17, 2024
2ee4069
fix
tyleroooo Dec 17, 2024
0c567b7
Merge remote-tracking branch 'origin/tu/abacus-ts-types' into tu/abac…
tyleroooo Dec 17, 2024
78ab949
fills table
tyleroooo Dec 17, 2024
fcc5306
fix
tyleroooo Dec 17, 2024
c9b8375
fix
tyleroooo Dec 17, 2024
7d7d7cb
Merge remote-tracking branch 'origin/tu/abacus-ts-types' into tu/abac…
tyleroooo Dec 17, 2024
4f5c9bb
Merge remote-tracking branch 'origin/tu/abacus-ts-2' into tu/migrate-…
tyleroooo Dec 17, 2024
2b2fc58
Merge remote-tracking branch 'origin/main' into tu/migrate-fills
tyleroooo Dec 19, 2024
59cf4c0
fix
tyleroooo Dec 19, 2024
7f67a33
fix
tyleroooo Dec 19, 2024
5d73d72
fix
tyleroooo Dec 19, 2024
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
11 changes: 4 additions & 7 deletions src/abacus-ts/lib/mapLoadable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@ export function mergeLoadableData<T, R>(
} as any;
}

// converts idle to pending and if a status has valid data is counts as success
export function mergeLoadableStatus(
...status: Array<Loadable<any>>
): Exclude<Loadable<any>['status'], 'idle'> {
export function mergeLoadableStatus(...status: Array<Loadable<any>>): Loadable<any>['status'] {
if (status.some((s) => s.status === 'error' && s.data == null)) {
return 'error';
}
if (status.some((s) => s.status === 'idle')) {
return 'pending';
}
if (status.some((s) => s.status === 'pending' && s.data == null)) {
return 'pending';
}
if (status.some((s) => s.status === 'idle')) {
return 'idle';
}
return 'success';
}
3 changes: 2 additions & 1 deletion src/components/OrderSideTag.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IndexerOrderSide } from '@/types/indexer/indexerApiGen';
import { OrderSide } from '@dydxprotocol/v4-client-js';

import { STRING_KEYS } from '@/constants/localization';
Expand All @@ -7,7 +8,7 @@ import { useStringGetter } from '@/hooks/useStringGetter';
import { Tag, TagSign, TagSize, TagType } from './Tag';

type ElementProps = {
orderSide: OrderSide;
orderSide: OrderSide | IndexerOrderSide;
};

type StyleProps = {
Expand Down
34 changes: 33 additions & 1 deletion src/lib/orders.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AssetInfo, AssetInfos, MarketsData } from '@/abacus-ts/rawTypes';
import { IndexerCompositeFillObject } from '@/types/indexer/indexerManual';
import { OrderSide } from '@dydxprotocol/v4-client-js';
import BigNumber from 'bignumber.js';

Expand All @@ -8,12 +10,12 @@ import {
AbacusOrderTypes,
KotlinIrEnumValues,
Nullable,
SubaccountFill,
SubaccountFills,
TRADE_TYPES,
type Asset,
type OrderStatus,
type PerpetualMarket,
type SubaccountFill,
type SubaccountFundingPayment,
type SubaccountOrder,
} from '@/constants/abacus';
Expand All @@ -22,6 +24,9 @@ import { IconName } from '@/components/Icon';

import { convertAbacusOrderSide } from '@/lib/abacus/conversions';

import { getAssetFromMarketId } from './assetUtils';
import { MaybeBigNumber } from './numbers';

export const getOrderStatusInfo = ({ status }: { status: string }) => {
switch (status) {
case AbacusOrderStatus.Open.rawValue: {
Expand Down Expand Up @@ -145,6 +150,33 @@ export const getHydratedTradingData = <
...('side' in data && { orderSide: convertAbacusOrderSide(data.side) }),
});

type NewAddedProps = {
asset: AssetInfo | undefined;
stepSizeDecimals: Nullable<number>;
tickSizeDecimals: Nullable<number>;
};

export const getHydratedFill = ({
data,
assets,
perpetualMarkets,
}: {
data: IndexerCompositeFillObject;
assets: AssetInfos;
perpetualMarkets: MarketsData;
}): IndexerCompositeFillObject & NewAddedProps => {
return {
...data,
asset: assets[getAssetFromMarketId(data.market ?? '')],
stepSizeDecimals: MaybeBigNumber(
perpetualMarkets[data.market ?? '']?.stepSize
)?.decimalPlaces(),
tickSizeDecimals: MaybeBigNumber(
perpetualMarkets[data.market ?? '']?.tickSize
)?.decimalPlaces(),
};
};

export const getTradeType = (orderType: string) =>
TRADE_TYPES[orderType as KotlinIrEnumValues<typeof AbacusOrderType>];

Expand Down
21 changes: 14 additions & 7 deletions src/pages/trade/HorizontalPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useMemo, useState } from 'react';

import { selectAccountFillsLoading } from '@/abacus-ts/selectors/account';
import { shallowEqual } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import styled from 'styled-components';
Expand Down Expand Up @@ -90,6 +91,7 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
);
const hasUnseenOrderUpdates = unseenOrders > 0;

const areFillsLoading = useAppSelector(selectAccountFillsLoading) === 'pending';
const numUnseenFills = useParameterizedSelector(
createGetUnseenFillsCount,
showCurrentMarket ? currentMarketId : undefined
Expand Down Expand Up @@ -227,10 +229,14 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
value: InfoSection.Fills,
label: stringGetter({ key: STRING_KEYS.FILLS }),

slotRight: fillsTagNumber && (
<Tag type={TagType.Number} isHighlighted={hasUnseenFillUpdates}>
{fillsTagNumber}
</Tag>
slotRight: areFillsLoading ? (
<LoadingSpinner tw="[--spinner-width:1rem]" />
) : (
fillsTagNumber && (
<Tag type={TagType.Number} isHighlighted={hasUnseenFillUpdates}>
{fillsTagNumber}
</Tag>
)
),

content: (
Expand Down Expand Up @@ -264,11 +270,12 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
}),
[
stringGetter,
currentMarketId,
showCurrentMarket,
isTablet,
areFillsLoading,
fillsTagNumber,
hasUnseenFillUpdates,
showCurrentMarket,
currentMarketId,
isTablet,
]
);

Expand Down
13 changes: 5 additions & 8 deletions src/state/_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import storage from 'redux-persist/lib/storage';

import abacusStateManager from '@/lib/abacus';
import { runFn } from '@/lib/do';
import { testFlags } from '@/lib/testFlags';

import { accountSlice } from './account';
import { accountUiMemorySlice } from './accountUiMemory';
Expand Down Expand Up @@ -98,13 +97,11 @@ export const persistor = persistStore(store);
// Set store so (Abacus & v4-Client) classes can getState and dispatch
abacusStateManager.setStore(store);

if (testFlags.useAbacusTs) {
runFn(async () => {
const { storeLifecycles } = await import('@/abacus-ts/storeLifecycles');
// we ignore the cleanups for now since we want these running forever
storeLifecycles.forEach((fn) => fn(store));
});
}
runFn(async () => {
const { storeLifecycles } = await import('@/abacus-ts/storeLifecycles');
// we ignore the cleanups for now since we want these running forever
storeLifecycles.forEach((fn) => fn(store));
});

export type RootStore = typeof store;
export type RootState = ReturnType<typeof store.getState>;
Expand Down
10 changes: 5 additions & 5 deletions src/state/accountSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { selectAccountFills } from '@/abacus-ts/selectors/account';
import { selectRawIndexerHeightData } from '@/abacus-ts/selectors/base';
import { OrderSide } from '@dydxprotocol/v4-client-js';
import BigNumber from 'bignumber.js';
Expand Down Expand Up @@ -735,15 +736,14 @@ export const createGetUnseenFillsCount = () =>
[
getCurrentAccountMemory,
selectRawIndexerHeightData,
getSubaccountFills,
selectAccountFills,
(state, market: string | undefined) => market,
],
(memory, height, fills, market) => {
if (height == null) {
return 0;
}
const ourFills =
(market == null ? fills : fills?.filter((o) => o.marketId === market)) ?? EMPTY_ARR;
const ourFills = market == null ? fills : fills.filter((o) => o.market === market);
if (ourFills.length === 0) {
return 0;
}
Expand All @@ -752,9 +752,9 @@ export const createGetUnseenFillsCount = () =>
}
const unseen = ourFills.filter(
(o) =>
o.createdAtMilliseconds >
(mapIfPresent(o.createdAt, (c) => new Date(c).valueOf()) ?? 0) >
(mapIfPresent(
(memory.seenFills[o.marketId] ?? memory.seenFills[ALL_MARKETS_STRING])?.time,
(memory.seenFills[o.market ?? ''] ?? memory.seenFills[ALL_MARKETS_STRING])?.time,
(t) => new Date(t).valueOf()
) ?? 0)
);
Expand Down
Loading
Loading