fix(trading): settlement price of closed markets (#3831)

This commit is contained in:
Matthew Russell 2023-05-19 13:29:24 -07:00 committed by GitHub
parent afa627864c
commit b75d189054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 249 additions and 79 deletions

View File

@ -1,5 +1,10 @@
import { aliasGQLQuery } from '@vegaprotocol/cypress'; import { aliasGQLQuery } from '@vegaprotocol/cypress';
import { MarketState, MarketStateMapping } from '@vegaprotocol/types'; import type { DataSourceDefinition } from '@vegaprotocol/types';
import {
MarketState,
MarketStateMapping,
PropertyKeyType,
} from '@vegaprotocol/types';
import { addDays, subDays } from 'date-fns'; import { addDays, subDays } from 'date-fns';
import { import {
chainIdQuery, chainIdQuery,
@ -20,6 +25,25 @@ import {
} from '@vegaprotocol/utils'; } from '@vegaprotocol/utils';
describe('Closed markets', { tags: '@smoke' }, () => { describe('Closed markets', { tags: '@smoke' }, () => {
const settlementDataProperty = 'settlement-data-property';
const settlementDataPropertyKey = {
__typename: 'PropertyKey' as const,
name: settlementDataProperty,
type: PropertyKeyType.TYPE_INTEGER,
numberDecimalPlaces: 2,
};
const settlementDataSourceData: DataSourceDefinition = {
sourceType: {
sourceType: {
filters: [
{
__typename: 'Filter',
key: settlementDataPropertyKey,
},
],
},
},
};
const rowSelector = const rowSelector =
'[data-testid="tab-closed-markets"] .ag-center-cols-container .ag-row'; '[data-testid="tab-closed-markets"] .ag-center-cols-container .ag-row';
@ -37,11 +61,15 @@ describe('Closed markets', { tags: '@smoke' }, () => {
tradableInstrument: { tradableInstrument: {
instrument: { instrument: {
product: { product: {
dataSourceSpecBinding: {
settlementDataProperty,
},
dataSourceSpecForTradingTermination: { dataSourceSpecForTradingTermination: {
id: 'market-1-trading-termination-oracle-id', id: 'market-1-trading-termination-oracle-id',
}, },
dataSourceSpecForSettlementData: { dataSourceSpecForSettlementData: {
id: 'market-1-settlement-data-oracle-id', id: 'market-1-settlement-data-oracle-id',
data: settlementDataSourceData,
}, },
settlementAsset, settlementAsset,
}, },
@ -63,6 +91,15 @@ describe('Closed markets', { tags: '@smoke' }, () => {
`settlement-expiry-date:${addDays(new Date(), 4).toISOString()}`, `settlement-expiry-date:${addDays(new Date(), 4).toISOString()}`,
], ],
}, },
product: {
dataSourceSpecBinding: {
settlementDataProperty,
},
dataSourceSpecForSettlementData: {
id: 'market-1-settlement-data-oracle-id',
data: settlementDataSourceData,
},
},
}, },
}, },
}); });
@ -81,6 +118,15 @@ describe('Closed markets', { tags: '@smoke' }, () => {
`settlement-expiry-date:${subDays(new Date(), 2).toISOString()}`, `settlement-expiry-date:${subDays(new Date(), 2).toISOString()}`,
], ],
}, },
product: {
dataSourceSpecBinding: {
settlementDataProperty,
},
dataSourceSpecForSettlementData: {
id: 'market-1-settlement-data-oracle-id',
data: settlementDataSourceData,
},
},
}, },
}, },
}); });
@ -301,7 +347,7 @@ describe('Closed markets', { tags: '@smoke' }, () => {
addDecimalsFormatNumber( addDecimalsFormatNumber(
// @ts-ignore cannot deep un-partial // @ts-ignore cannot deep un-partial
specDataConnection.externalData.data.data[0].value, specDataConnection.externalData.data.data[0].value,
settledMarket.decimalPlaces settlementDataPropertyKey.numberDecimalPlaces
) )
); );

View File

@ -1,6 +1,6 @@
import { act, render, screen, within } from '@testing-library/react'; import { act, render, screen, within } from '@testing-library/react';
import { Closed } from './closed'; import { Closed } from './closed';
import { MarketStateMapping } from '@vegaprotocol/types'; import { MarketStateMapping, PropertyKeyType } from '@vegaprotocol/types';
import { PositionStatus } from '@vegaprotocol/types'; import { PositionStatus } from '@vegaprotocol/types';
import { MarketState } from '@vegaprotocol/types'; import { MarketState } from '@vegaprotocol/types';
import { subDays } from 'date-fns'; import { subDays } from 'date-fns';
@ -55,6 +55,23 @@ describe('Closed', () => {
product: { product: {
dataSourceSpecForSettlementData: { dataSourceSpecForSettlementData: {
id: settlementDataId, id: settlementDataId,
data: {
sourceType: {
sourceType: {
filters: [
{
__typename: 'Filter',
key: {
__typename: 'PropertyKey',
name: settlementDataProperty,
type: PropertyKeyType.TYPE_INTEGER,
numberDecimalPlaces: 5,
},
},
],
},
},
},
}, },
dataSourceSpecBinding: { dataSourceSpecBinding: {
settlementDataProperty, settlementDataProperty,

View File

@ -13,7 +13,10 @@ import {
getMarketExpiryDate, getMarketExpiryDate,
} from '@vegaprotocol/utils'; } from '@vegaprotocol/utils';
import { usePositionsQuery } from '@vegaprotocol/positions'; import { usePositionsQuery } from '@vegaprotocol/positions';
import type { MarketMaybeWithData } from '@vegaprotocol/markets'; import type {
DataSourceFilterFragment,
MarketMaybeWithData,
} from '@vegaprotocol/markets';
import { import {
MarketTableActions, MarketTableActions,
closedMarketsWithDataProvider, closedMarketsWithDataProvider,
@ -42,6 +45,7 @@ interface Row {
markPrice: string | undefined; markPrice: string | undefined;
settlementDataOracleId: string; settlementDataOracleId: string;
settlementDataSpecBinding: string; settlementDataSpecBinding: string;
setlementDataSourceFilter: DataSourceFilterFragment | undefined;
tradingTerminationOracleId: string; tradingTerminationOracleId: string;
settlementAsset: SettlementAsset; settlementAsset: SettlementAsset;
realisedPNL: string | undefined; realisedPNL: string | undefined;
@ -74,28 +78,40 @@ export const Closed = () => {
} }
); );
const instrument = market.tradableInstrument.instrument;
const spec =
instrument.product.dataSourceSpecForSettlementData.data.sourceType
.__typename === 'DataSourceDefinitionExternal'
? instrument.product.dataSourceSpecForSettlementData.data.sourceType
.sourceType
: undefined;
const filters = spec?.filters || [];
const settlementDataSpecBinding =
instrument.product.dataSourceSpecBinding.settlementDataProperty;
const filter = filters?.find((filter) => {
return filter.key.name === settlementDataSpecBinding;
});
const row: Row = { const row: Row = {
id: market.id, id: market.id,
code: market.tradableInstrument.instrument.code, code: instrument.code,
name: market.tradableInstrument.instrument.name, name: instrument.name,
decimalPlaces: market.decimalPlaces, decimalPlaces: market.decimalPlaces,
state: market.state, state: market.state,
metadata: market.tradableInstrument.instrument.metadata.tags ?? [], metadata: instrument.metadata.tags ?? [],
closeTimestamp: market.marketTimestamps.close, closeTimestamp: market.marketTimestamps.close,
bestBidPrice: market.data?.bestBidPrice, bestBidPrice: market.data?.bestBidPrice,
bestOfferPrice: market.data?.bestOfferPrice, bestOfferPrice: market.data?.bestOfferPrice,
markPrice: market.data?.markPrice, markPrice: market.data?.markPrice,
settlementDataOracleId: settlementDataOracleId:
market.tradableInstrument.instrument.product instrument.product.dataSourceSpecForSettlementData.id,
.dataSourceSpecForSettlementData.id, settlementDataSpecBinding,
settlementDataSpecBinding: setlementDataSourceFilter: filter,
market.tradableInstrument.instrument.product.dataSourceSpecBinding
.settlementDataProperty,
tradingTerminationOracleId: tradingTerminationOracleId:
market.tradableInstrument.instrument.product instrument.product.dataSourceSpecForTradingTermination.id,
.dataSourceSpecForTradingTermination.id, settlementAsset: instrument.product.settlementAsset,
settlementAsset:
market.tradableInstrument.instrument.product.settlementAsset,
realisedPNL: position?.node.realisedPNL, realisedPNL: position?.node.realisedPNL,
}; };
@ -238,8 +254,8 @@ const ClosedMarketsDataGrid = ({ rowData }: { rowData: Row[] }) => {
}: VegaICellRendererParams<Row, 'settlementDataOracleId'>) => ( }: VegaICellRendererParams<Row, 'settlementDataOracleId'>) => (
<SettlementPriceCell <SettlementPriceCell
oracleSpecId={value} oracleSpecId={value}
decimalPlaces={data?.decimalPlaces ?? 0}
settlementDataSpecBinding={data?.settlementDataSpecBinding} settlementDataSpecBinding={data?.settlementDataSpecBinding}
filter={data?.setlementDataSourceFilter}
/> />
), ),
}, },

View File

@ -1,13 +1,17 @@
import { render, screen } from '@testing-library/react'; import { render, screen } from '@testing-library/react';
import type { Property } from '@vegaprotocol/types'; import type { Property } from '@vegaprotocol/types';
import { PropertyKeyType } from '@vegaprotocol/types';
import type { MockedResponse } from '@apollo/client/testing'; import type { MockedResponse } from '@apollo/client/testing';
import { MockedProvider } from '@apollo/client/testing'; import { MockedProvider } from '@apollo/client/testing';
import type { OracleSpecDataConnectionQuery } from '@vegaprotocol/markets'; import type { OracleSpecDataConnectionQuery } from '@vegaprotocol/markets';
import { OracleSpecDataConnectionDocument } from '@vegaprotocol/markets'; import { OracleSpecDataConnectionDocument } from '@vegaprotocol/markets';
import type { SettlementPriceCellProps } from './settlement-price-cell'; import type { SettlementPriceCellProps } from './settlement-price-cell';
import { SettlementPriceCell } from './settlement-price-cell'; import { SettlementPriceCell } from './settlement-price-cell';
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
describe('SettlementPriceCell', () => { describe('SettlementPriceCell', () => {
const settlementDataSpecBinding = 'settlement-data-spec-binding';
const createMock = ( const createMock = (
id: string, id: string,
property: Property property: Property
@ -40,11 +44,19 @@ describe('SettlementPriceCell', () => {
}, },
}; };
}; };
const createProps = (): SettlementPriceCellProps => { const createProps = (
filterKey = {
name: settlementDataSpecBinding,
type: PropertyKeyType.TYPE_INTEGER,
numberDecimalPlaces: 2,
}
): SettlementPriceCellProps => {
return { return {
oracleSpecId: 'oracle-spec-id', oracleSpecId: 'oracle-spec-id',
decimalPlaces: 2, filter: {
settlementDataSpecBinding: 'settlement-data-spec-binding', key: filterKey,
},
settlementDataSpecBinding,
}; };
}; };
it('renders fetches and renders the settlment data value', async () => { it('renders fetches and renders the settlment data value', async () => {
@ -65,14 +77,19 @@ describe('SettlementPriceCell', () => {
expect(screen.getByText('-')).toBeInTheDocument(); expect(screen.getByText('-')).toBeInTheDocument();
const link = await screen.findByRole('link'); const link = await screen.findByRole('link');
expect(link).toHaveTextContent('12.34'); expect(link).toHaveTextContent(
addDecimalsFormatNumber(
property.value,
props.filter?.key.numberDecimalPlaces || 0
)
);
expect(link).toHaveAttribute( expect(link).toHaveAttribute(
'href', 'href',
expect.stringContaining(`/oracles/${props.oracleSpecId}`) expect.stringContaining(`/oracles/${props.oracleSpecId}`)
); );
}); });
it('renders "-" if no spec value is found', async () => { it('renders "Unknown" if no spec value is found', async () => {
const props = createProps(); const props = createProps();
const property = { const property = {
__typename: 'Property' as const, __typename: 'Property' as const,
@ -90,7 +107,7 @@ describe('SettlementPriceCell', () => {
expect(screen.getByText('-')).toBeInTheDocument(); expect(screen.getByText('-')).toBeInTheDocument();
const link = await screen.findByRole('link'); const link = await screen.findByRole('link');
expect(link).toHaveTextContent('-'); expect(link).toHaveTextContent('Unknown');
expect(link).toHaveAttribute( expect(link).toHaveAttribute(
'href', 'href',
expect.stringContaining(`/oracles/${props.oracleSpecId}`) expect.stringContaining(`/oracles/${props.oracleSpecId}`)
@ -110,4 +127,33 @@ describe('SettlementPriceCell', () => {
expect(screen.getByText('-')).toBeInTheDocument(); expect(screen.getByText('-')).toBeInTheDocument();
expect(screen.queryByRole('link')).not.toBeInTheDocument(); expect(screen.queryByRole('link')).not.toBeInTheDocument();
}); });
it('does not format value if property key type is not integer', async () => {
const props = createProps({
name: settlementDataSpecBinding,
type: PropertyKeyType.TYPE_TIMESTAMP,
numberDecimalPlaces: 2,
});
const property = {
__typename: 'Property' as const,
name: props.settlementDataSpecBinding as string,
value: '1234',
};
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const mock = createMock(props.oracleSpecId!, property);
render(
<MockedProvider mocks={[mock]}>
<SettlementPriceCell {...props} />
</MockedProvider>
);
expect(screen.getByText('-')).toBeInTheDocument();
const link = await screen.findByRole('link');
expect(link).toHaveTextContent(property.value);
expect(link).toHaveAttribute(
'href',
expect.stringContaining(`/oracles/${props.oracleSpecId}`)
);
});
}); });

View File

@ -1,19 +1,21 @@
import { DApp, EXPLORER_ORACLE, useLinks } from '@vegaprotocol/environment'; import { DApp, EXPLORER_ORACLE, useLinks } from '@vegaprotocol/environment';
import { t } from '@vegaprotocol/i18n'; import { t } from '@vegaprotocol/i18n';
import type { DataSourceFilterFragment } from '@vegaprotocol/markets';
import { useOracleSpecBindingData } from '@vegaprotocol/markets'; import { useOracleSpecBindingData } from '@vegaprotocol/markets';
import { PropertyKeyType } from '@vegaprotocol/types';
import { Link } from '@vegaprotocol/ui-toolkit'; import { Link } from '@vegaprotocol/ui-toolkit';
import { addDecimalsFormatNumber } from '@vegaprotocol/utils'; import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
export interface SettlementPriceCellProps { export interface SettlementPriceCellProps {
oracleSpecId: string | undefined; oracleSpecId: string | undefined;
decimalPlaces: number;
settlementDataSpecBinding: string | undefined; settlementDataSpecBinding: string | undefined;
filter: DataSourceFilterFragment | undefined;
} }
export const SettlementPriceCell = ({ export const SettlementPriceCell = ({
oracleSpecId, oracleSpecId,
decimalPlaces,
settlementDataSpecBinding, settlementDataSpecBinding,
filter,
}: SettlementPriceCellProps) => { }: SettlementPriceCellProps) => {
const linkCreator = useLinks(DApp.Explorer); const linkCreator = useLinks(DApp.Explorer);
const { property, loading } = useOracleSpecBindingData( const { property, loading } = useOracleSpecBindingData(
@ -25,15 +27,32 @@ export const SettlementPriceCell = ({
return <span>-</span>; return <span>-</span>;
} }
const renderText = () => {
if (!property || !filter) {
return t('Unknown');
}
if (
filter.key.type === PropertyKeyType.TYPE_INTEGER &&
filter.key.numberDecimalPlaces !== null &&
filter.key.numberDecimalPlaces !== undefined
) {
return addDecimalsFormatNumber(
property.value,
filter.key.numberDecimalPlaces
);
}
return property.value;
};
return ( return (
<Link <Link
href={linkCreator(EXPLORER_ORACLE.replace(':id', oracleSpecId))} href={linkCreator(EXPLORER_ORACLE.replace(':id', oracleSpecId))}
className="underline font-mono" className="underline font-mono"
target="_blank" target="_blank"
> >
{property {renderText()}
? addDecimalsFormatNumber(property.value, decimalPlaces)
: t('-')}
</Link> </Link>
); );
}; };

View File

@ -31,27 +31,6 @@ fragment OracleMarketSpecFields on Market {
} }
} }
fragment DataSourceSpec on DataSourceDefinition {
sourceType {
... on DataSourceDefinitionExternal {
sourceType {
... on DataSourceSpecConfiguration {
signers {
signer {
... on PubKey {
key
}
... on ETHAddress {
address
}
}
}
}
}
}
}
}
query OracleMarketsSpec { query OracleMarketsSpec {
marketsConnection { marketsConnection {
edges { edges {

View File

@ -1,39 +1,16 @@
import * as Types from '@vegaprotocol/types'; import * as Types from '@vegaprotocol/types';
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
import { DataSourceSpecFragmentDoc } from './markets';
import * as Apollo from '@apollo/client'; import * as Apollo from '@apollo/client';
const defaultOptions = {} as const; const defaultOptions = {} as const;
export type OracleMarketSpecFieldsFragment = { __typename?: 'Market', id: string, state: Types.MarketState, tradingMode: Types.MarketTradingMode, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, product: { __typename?: 'Future', dataSourceSpecForSettlementData: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } } } }; export type OracleMarketSpecFieldsFragment = { __typename?: 'Market', id: string, state: Types.MarketState, tradingMode: Types.MarketTradingMode, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, product: { __typename?: 'Future', dataSourceSpecForSettlementData: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } } } };
export type DataSourceSpecFragment = { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } };
export type OracleMarketsSpecQueryVariables = Types.Exact<{ [key: string]: never; }>; export type OracleMarketsSpecQueryVariables = Types.Exact<{ [key: string]: never; }>;
export type OracleMarketsSpecQuery = { __typename?: 'Query', marketsConnection?: { __typename?: 'MarketConnection', edges: Array<{ __typename?: 'MarketEdge', node: { __typename?: 'Market', id: string, state: Types.MarketState, tradingMode: Types.MarketTradingMode, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, product: { __typename?: 'Future', dataSourceSpecForSettlementData: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } } } } }> } | null }; export type OracleMarketsSpecQuery = { __typename?: 'Query', marketsConnection?: { __typename?: 'MarketConnection', edges: Array<{ __typename?: 'MarketEdge', node: { __typename?: 'Market', id: string, state: Types.MarketState, tradingMode: Types.MarketTradingMode, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, product: { __typename?: 'Future', dataSourceSpecForSettlementData: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } } } } }> } | null };
export const DataSourceSpecFragmentDoc = gql`
fragment DataSourceSpec on DataSourceDefinition {
sourceType {
... on DataSourceDefinitionExternal {
sourceType {
... on DataSourceSpecConfiguration {
signers {
signer {
... on PubKey {
key
}
... on ETHAddress {
address
}
}
}
}
}
}
}
}
`;
export const OracleMarketSpecFieldsFragmentDoc = gql` export const OracleMarketSpecFieldsFragmentDoc = gql`
fragment OracleMarketSpecFields on Market { fragment OracleMarketSpecFields on Market {
id id

View File

@ -1,16 +1,53 @@
import * as Types from '@vegaprotocol/types'; import * as Types from '@vegaprotocol/types';
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
import { DataSourceSpecFragmentDoc } from './OracleMarketsSpec';
import * as Apollo from '@apollo/client'; import * as Apollo from '@apollo/client';
const defaultOptions = {} as const; const defaultOptions = {} as const;
export type MarketFieldsFragment = { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, state: Types.MarketState, tradingMode: Types.MarketTradingMode, fees: { __typename?: 'Fees', factors: { __typename?: 'FeeFactors', makerFee: string, infrastructureFee: string, liquidityFee: string } }, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, metadata: { __typename?: 'InstrumentMetadata', tags?: Array<string> | null }, product: { __typename?: 'Future', quoteName: string, settlementAsset: { __typename?: 'Asset', id: string, symbol: string, name: string, decimals: number }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecForSettlementData: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } } }, marketTimestamps: { __typename?: 'MarketTimestamps', open: any, close: any } }; export type DataSourceFilterFragment = { __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } };
export type DataSourceSpecFragment = { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } };
export type MarketFieldsFragment = { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, state: Types.MarketState, tradingMode: Types.MarketTradingMode, fees: { __typename?: 'Fees', factors: { __typename?: 'FeeFactors', makerFee: string, infrastructureFee: string, liquidityFee: string } }, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, metadata: { __typename?: 'InstrumentMetadata', tags?: Array<string> | null }, product: { __typename?: 'Future', quoteName: string, settlementAsset: { __typename?: 'Asset', id: string, symbol: string, name: string, decimals: number }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecForSettlementData: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } } }, marketTimestamps: { __typename?: 'MarketTimestamps', open: any, close: any } };
export type MarketsQueryVariables = Types.Exact<{ [key: string]: never; }>; export type MarketsQueryVariables = Types.Exact<{ [key: string]: never; }>;
export type MarketsQuery = { __typename?: 'Query', marketsConnection?: { __typename?: 'MarketConnection', edges: Array<{ __typename?: 'MarketEdge', node: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, state: Types.MarketState, tradingMode: Types.MarketTradingMode, fees: { __typename?: 'Fees', factors: { __typename?: 'FeeFactors', makerFee: string, infrastructureFee: string, liquidityFee: string } }, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, metadata: { __typename?: 'InstrumentMetadata', tags?: Array<string> | null }, product: { __typename?: 'Future', quoteName: string, settlementAsset: { __typename?: 'Asset', id: string, symbol: string, name: string, decimals: number }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecForSettlementData: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } } }, marketTimestamps: { __typename?: 'MarketTimestamps', open: any, close: any } } }> } | null }; export type MarketsQuery = { __typename?: 'Query', marketsConnection?: { __typename?: 'MarketConnection', edges: Array<{ __typename?: 'MarketEdge', node: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, state: Types.MarketState, tradingMode: Types.MarketTradingMode, fees: { __typename?: 'Fees', factors: { __typename?: 'FeeFactors', makerFee: string, infrastructureFee: string, liquidityFee: string } }, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, metadata: { __typename?: 'InstrumentMetadata', tags?: Array<string> | null }, product: { __typename?: 'Future', quoteName: string, settlementAsset: { __typename?: 'Asset', id: string, symbol: string, name: string, decimals: number }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecForSettlementData: { __typename?: 'DataSourceSpec', id: string, data: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType, numberDecimalPlaces?: number | null } }> | null } } | { __typename?: 'DataSourceDefinitionInternal' } } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } } }, marketTimestamps: { __typename?: 'MarketTimestamps', open: any, close: any } } }> } | null };
export const DataSourceFilterFragmentDoc = gql`
fragment DataSourceFilter on Filter {
key {
name
type
numberDecimalPlaces
}
}
`;
export const DataSourceSpecFragmentDoc = gql`
fragment DataSourceSpec on DataSourceDefinition {
sourceType {
... on DataSourceDefinitionExternal {
sourceType {
... on DataSourceSpecConfiguration {
signers {
signer {
... on PubKey {
key
}
... on ETHAddress {
address
}
}
}
filters {
...DataSourceFilter
}
}
}
}
}
}
${DataSourceFilterFragmentDoc}`;
export const MarketFieldsFragmentDoc = gql` export const MarketFieldsFragmentDoc = gql`
fragment MarketFields on Market { fragment MarketFields on Market {
id id

View File

@ -4,7 +4,7 @@ import { useMarket } from '../markets-provider';
import { useMemo } from 'react'; import { useMemo } from 'react';
import type { Provider } from '../oracle-schema'; import type { Provider } from '../oracle-schema';
import type { DataSourceSpecFragment } from '../__generated__/OracleMarketsSpec'; import type { DataSourceSpecFragment } from '../__generated__';
export const getMatchingOracleProvider = ( export const getMatchingOracleProvider = (
dataSourceSpec: DataSourceSpecFragment, dataSourceSpec: DataSourceSpecFragment,

View File

@ -1,3 +1,11 @@
fragment DataSourceFilter on Filter {
key {
name
type
numberDecimalPlaces
}
}
fragment DataSourceSpec on DataSourceDefinition { fragment DataSourceSpec on DataSourceDefinition {
sourceType { sourceType {
... on DataSourceDefinitionExternal { ... on DataSourceDefinitionExternal {
@ -13,6 +21,9 @@ fragment DataSourceSpec on DataSourceDefinition {
} }
} }
} }
filters {
...DataSourceFilter
}
} }
} }
} }

View File

@ -80,6 +80,17 @@ export const createMarketFragment = (
}, },
}, },
], ],
filters: [
{
__typename: 'Filter',
key: {
__typename: 'PropertyKey',
name: 'settlement-data-property',
type: Schema.PropertyKeyType.TYPE_TIMESTAMP,
numberDecimalPlaces: null,
},
},
],
}, },
}, },
}, },
@ -102,6 +113,17 @@ export const createMarketFragment = (
}, },
}, },
], ],
filters: [
{
__typename: 'Filter',
key: {
__typename: 'PropertyKey',
name: 'settlement-data-property',
type: Schema.PropertyKeyType.TYPE_INTEGER,
numberDecimalPlaces: 2,
},
},
],
}, },
}, },
}, },