feat(trading): liquidity provision current and pending on update (#5152)
This commit is contained in:
parent
0ebfab64ff
commit
6421cf87c6
@ -21,7 +21,10 @@ import type {
|
|||||||
} from './__generated__/MarketLiquidity';
|
} from './__generated__/MarketLiquidity';
|
||||||
|
|
||||||
export type LiquidityProvisionFields = LiquidityProvisionFieldsFragment &
|
export type LiquidityProvisionFields = LiquidityProvisionFieldsFragment &
|
||||||
Schema.LiquiditySLAParameters;
|
Schema.LiquiditySLAParameters & {
|
||||||
|
currentCommitmentAmount?: string;
|
||||||
|
currentFee?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const liquidityProvisionsDataProvider = makeDataProvider<
|
export const liquidityProvisionsDataProvider = makeDataProvider<
|
||||||
LiquidityProvisionsQuery,
|
LiquidityProvisionsQuery,
|
||||||
@ -34,10 +37,28 @@ export const liquidityProvisionsDataProvider = makeDataProvider<
|
|||||||
getData: (responseData: LiquidityProvisionsQuery | null) => {
|
getData: (responseData: LiquidityProvisionsQuery | null) => {
|
||||||
return (responseData?.market?.liquidityProvisions?.edges
|
return (responseData?.market?.liquidityProvisions?.edges
|
||||||
?.filter((n) => !!n)
|
?.filter((n) => !!n)
|
||||||
.map((e) => ({
|
.map((e) => {
|
||||||
...e?.node.current,
|
let node;
|
||||||
...responseData.market?.liquiditySLAParameters,
|
if (!e?.node.pending && e?.node.current) {
|
||||||
})) ?? []) as LiquidityProvisionFields[];
|
node = {
|
||||||
|
...e?.node.current,
|
||||||
|
...responseData.market?.liquiditySLAParameters,
|
||||||
|
};
|
||||||
|
} else if (!e?.node.current && e?.node.pending) {
|
||||||
|
node = {
|
||||||
|
...e?.node.pending,
|
||||||
|
...responseData.market?.liquiditySLAParameters,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
node = {
|
||||||
|
...e?.node.pending,
|
||||||
|
currentCommitmentAmount: e?.node.current.commitmentAmount,
|
||||||
|
currentFee: e?.node.current.fee,
|
||||||
|
...responseData.market?.liquiditySLAParameters,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}) ?? []) as LiquidityProvisionFields[];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -91,7 +112,8 @@ export const matchFilter = (filter: Filter, lp: LiquidityProvisionData) => {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
filter.active === true &&
|
filter.active === true &&
|
||||||
lp.status !== Schema.LiquidityProvisionStatus.STATUS_ACTIVE
|
lp.status !== Schema.LiquidityProvisionStatus.STATUS_ACTIVE &&
|
||||||
|
lp.status !== Schema.LiquidityProvisionStatus.STATUS_PENDING
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -105,7 +127,7 @@ export const matchFilter = (filter: Filter, lp: LiquidityProvisionData) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface LiquidityProvisionData
|
export interface LiquidityProvisionData
|
||||||
extends Omit<LiquidityProvisionFieldsFragment, '__typename'>,
|
extends Omit<LiquidityProvisionFields, '__typename'>,
|
||||||
Partial<LiquidityProviderFieldsFragment>,
|
Partial<LiquidityProviderFieldsFragment>,
|
||||||
Omit<Schema.LiquiditySLAParameters, '__typename'> {
|
Omit<Schema.LiquiditySLAParameters, '__typename'> {
|
||||||
assetDecimalPlaces?: number;
|
assetDecimalPlaces?: number;
|
||||||
@ -113,11 +135,12 @@ export interface LiquidityProvisionData
|
|||||||
averageEntryValuation?: string;
|
averageEntryValuation?: string;
|
||||||
equityLikeShare?: string;
|
equityLikeShare?: string;
|
||||||
earmarkedFees?: number;
|
earmarkedFees?: number;
|
||||||
|
status: Schema.LiquidityProvisionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getLiquidityProvision = (
|
export const getLiquidityProvision = (
|
||||||
liquidityProvisions: LiquidityProvisionFields[],
|
liquidityProvisions: LiquidityProvisionFields[],
|
||||||
liquidityProvider: LiquidityProviderFieldsFragment[],
|
liquidityProviders: LiquidityProviderFieldsFragment[],
|
||||||
filter?: Filter
|
filter?: Filter
|
||||||
): LiquidityProvisionData[] => {
|
): LiquidityProvisionData[] => {
|
||||||
return liquidityProvisions
|
return liquidityProvisions
|
||||||
@ -136,12 +159,14 @@ export const getLiquidityProvision = (
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.map((lp) => {
|
.map((liquidityProvision) => {
|
||||||
const lpObj = liquidityProvider.find((f) => lp.party.id === f.partyId);
|
const liquidityProvider = liquidityProviders.find(
|
||||||
if (!lpObj) return lp;
|
(f) => liquidityProvision.party.id === f.partyId
|
||||||
const accounts = compact(lp.party.accountsConnection?.edges).map(
|
|
||||||
(e) => e.node
|
|
||||||
);
|
);
|
||||||
|
if (!liquidityProvider) return liquidityProvision;
|
||||||
|
const accounts = compact(
|
||||||
|
liquidityProvision.party.accountsConnection?.edges
|
||||||
|
).map((e) => e.node);
|
||||||
const bondAccounts = accounts?.filter(
|
const bondAccounts = accounts?.filter(
|
||||||
(a) => a?.type === Schema.AccountType.ACCOUNT_TYPE_BOND
|
(a) => a?.type === Schema.AccountType.ACCOUNT_TYPE_BOND
|
||||||
);
|
);
|
||||||
@ -164,8 +189,8 @@ export const getLiquidityProvision = (
|
|||||||
)
|
)
|
||||||
.toNumber() ?? 0;
|
.toNumber() ?? 0;
|
||||||
return {
|
return {
|
||||||
...lp,
|
...liquidityProvision,
|
||||||
...lpObj,
|
...liquidityProvider,
|
||||||
balance,
|
balance,
|
||||||
earmarkedFees,
|
earmarkedFees,
|
||||||
__typename: undefined,
|
__typename: undefined,
|
||||||
|
@ -6,7 +6,10 @@ import {
|
|||||||
getDateTimeFormat,
|
getDateTimeFormat,
|
||||||
} from '@vegaprotocol/utils';
|
} from '@vegaprotocol/utils';
|
||||||
import { t } from '@vegaprotocol/i18n';
|
import { t } from '@vegaprotocol/i18n';
|
||||||
import type { TypedDataAgGrid } from '@vegaprotocol/datagrid';
|
import type {
|
||||||
|
TypedDataAgGrid,
|
||||||
|
VegaValueFormatterParams,
|
||||||
|
} from '@vegaprotocol/datagrid';
|
||||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||||
import {
|
import {
|
||||||
CopyWithTooltip,
|
CopyWithTooltip,
|
||||||
@ -22,7 +25,7 @@ import type {
|
|||||||
ValueFormatterParams,
|
ValueFormatterParams,
|
||||||
} from 'ag-grid-community';
|
} from 'ag-grid-community';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import type { LiquidityProvisionStatus } from '@vegaprotocol/types';
|
import { LiquidityProvisionStatus } from '@vegaprotocol/types';
|
||||||
import { LiquidityProvisionStatusMapping } from '@vegaprotocol/types';
|
import { LiquidityProvisionStatusMapping } from '@vegaprotocol/types';
|
||||||
import type { LiquidityProvisionData } from './liquidity-data-provider';
|
import type { LiquidityProvisionData } from './liquidity-data-provider';
|
||||||
|
|
||||||
@ -187,7 +190,32 @@ export const LiquidityTable = ({
|
|||||||
headerTooltip: t(
|
headerTooltip: t(
|
||||||
'The amount committed to the market by this liquidity provider.'
|
'The amount committed to the market by this liquidity provider.'
|
||||||
),
|
),
|
||||||
valueFormatter: assetDecimalsQuantumFormatter,
|
valueFormatter: ({
|
||||||
|
data,
|
||||||
|
value,
|
||||||
|
}: VegaValueFormatterParams<
|
||||||
|
LiquidityProvisionData,
|
||||||
|
'commitmentAmount'
|
||||||
|
>) => {
|
||||||
|
if (!value) return '-';
|
||||||
|
const formattedCommitmentAmount = addDecimalsFormatNumberQuantum(
|
||||||
|
value,
|
||||||
|
assetDecimalPlaces ?? 0,
|
||||||
|
quantum ?? 0
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
data?.currentCommitmentAmount &&
|
||||||
|
data?.currentCommitmentAmount !== value
|
||||||
|
) {
|
||||||
|
return `${addDecimalsFormatNumberQuantum(
|
||||||
|
data.currentCommitmentAmount,
|
||||||
|
assetDecimalPlaces ?? 0,
|
||||||
|
quantum ?? 0
|
||||||
|
)}/${formattedCommitmentAmount}`;
|
||||||
|
} else {
|
||||||
|
return formattedCommitmentAmount;
|
||||||
|
}
|
||||||
|
},
|
||||||
tooltipValueGetter: assetDecimalsFormatter,
|
tooltipValueGetter: assetDecimalsFormatter,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -207,7 +235,22 @@ export const LiquidityTable = ({
|
|||||||
),
|
),
|
||||||
field: 'fee',
|
field: 'fee',
|
||||||
type: 'rightAligned',
|
type: 'rightAligned',
|
||||||
valueFormatter: percentageFormatter,
|
valueFormatter: ({
|
||||||
|
data,
|
||||||
|
value,
|
||||||
|
}: ValueFormatterParams<LiquidityProvisionData, 'fee'>) => {
|
||||||
|
if (!value) return '-';
|
||||||
|
const formattedValue =
|
||||||
|
formatNumberPercentage(new BigNumber(value).times(100), 2) ||
|
||||||
|
'-';
|
||||||
|
if (data?.currentFee && data?.currentFee !== value) {
|
||||||
|
return `${formatNumberPercentage(
|
||||||
|
new BigNumber(data.currentFee).times(100),
|
||||||
|
2
|
||||||
|
)}/${formattedValue}`;
|
||||||
|
}
|
||||||
|
return formattedValue;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headerName: t('Adjusted stake share'),
|
headerName: t('Adjusted stake share'),
|
||||||
@ -328,8 +371,17 @@ export const LiquidityTable = ({
|
|||||||
headerName: t('Status'),
|
headerName: t('Status'),
|
||||||
headerTooltip: t('The current status of this liquidity provision.'),
|
headerTooltip: t('The current status of this liquidity provision.'),
|
||||||
field: 'status',
|
field: 'status',
|
||||||
valueFormatter: ({ value }) => {
|
valueFormatter: ({
|
||||||
|
data,
|
||||||
|
value,
|
||||||
|
}: ValueFormatterParams<LiquidityProvisionData, 'status'>) => {
|
||||||
if (!value) return value;
|
if (!value) return value;
|
||||||
|
if (
|
||||||
|
data?.status === LiquidityProvisionStatus.STATUS_PENDING &&
|
||||||
|
(data?.currentCommitmentAmount || data?.currentFee)
|
||||||
|
) {
|
||||||
|
return t('Updating next epoch');
|
||||||
|
}
|
||||||
return LiquidityProvisionStatusMapping[
|
return LiquidityProvisionStatusMapping[
|
||||||
value as LiquidityProvisionStatus
|
value as LiquidityProvisionStatus
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user