Compare commits
24
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
477f0a06ff | ||
|
|
beaed2e133 | ||
|
|
72e0cb76aa | ||
|
|
ca64516a52 | ||
|
|
55d692ea6f | ||
|
|
f235c03abe | ||
|
|
546deb0e1c | ||
|
|
042919eca9 | ||
|
|
c4a56e0de3 | ||
|
|
3c3bfb7dac | ||
|
|
196ba78806 | ||
|
|
53ac2dadee | ||
|
|
e532f88daa | ||
|
|
7b06c05853 | ||
|
|
a92fe92778 | ||
|
|
b8725a7fa8 | ||
|
|
f556247e1a | ||
|
|
48d6be0adf | ||
|
|
be6f395ce4 | ||
|
|
9a37572f51 | ||
|
|
19fb406d49 | ||
|
|
a2a04c57d2 | ||
|
|
1f08e8225a | ||
|
|
5fff6ba3f7 |
@@ -1,7 +1,7 @@
|
||||
import { getNewAssetTxBody } from '../support/governance.functions';
|
||||
|
||||
context('Proposal page', { tags: '@smoke' }, function () {
|
||||
describe('Verify elements on page', function () {
|
||||
describe.skip('Verify elements on page', function () {
|
||||
const proposalHeading = 'proposals-heading';
|
||||
const dateTimeRegex =
|
||||
/(\d{1,2})\/(\d{1,2})\/(\d{4}), (\d{1,2}):(\d{1,2}):(\d{1,2})/gm;
|
||||
|
||||
@@ -7,6 +7,7 @@ export type AssetBalanceProps = {
|
||||
price: string;
|
||||
showAssetLink?: boolean;
|
||||
showAssetSymbol?: boolean;
|
||||
rounded?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -18,12 +19,17 @@ const AssetBalance = ({
|
||||
price,
|
||||
showAssetLink = true,
|
||||
showAssetSymbol = false,
|
||||
rounded = false,
|
||||
}: AssetBalanceProps) => {
|
||||
const { data: asset, loading } = useAssetDataProvider(assetId);
|
||||
|
||||
const label =
|
||||
!loading && asset && asset.decimals
|
||||
? addDecimalsFixedFormatNumber(price, asset.decimals)
|
||||
? addDecimalsFixedFormatNumber(
|
||||
price,
|
||||
asset.decimals,
|
||||
rounded ? 0 : undefined
|
||||
)
|
||||
: price;
|
||||
|
||||
return (
|
||||
|
||||
@@ -41,6 +41,7 @@ export const Header = () => {
|
||||
Routes.ASSETS,
|
||||
Routes.MARKETS,
|
||||
Routes.GOVERNANCE,
|
||||
Routes.TREASURY,
|
||||
Routes.NETWORK_PARAMETERS,
|
||||
Routes.GENESIS,
|
||||
].map((n) => pages.find((r) => r.path === n))
|
||||
|
||||
@@ -32,9 +32,17 @@ export function getNameForParty(id: string, data?: ExplorerNodeNamesQuery) {
|
||||
export type PartyLinkProps = Partial<ComponentProps<typeof Link>> & {
|
||||
id: string;
|
||||
truncate?: boolean;
|
||||
networkLabel?: string;
|
||||
truncateLength?: number;
|
||||
};
|
||||
|
||||
const PartyLink = ({ id, truncate = false, ...props }: PartyLinkProps) => {
|
||||
const PartyLink = ({
|
||||
id,
|
||||
truncate = false,
|
||||
truncateLength = 4,
|
||||
networkLabel = t('Network'),
|
||||
...props
|
||||
}: PartyLinkProps) => {
|
||||
const { data } = useExplorerNodeNamesQuery();
|
||||
const name = useMemo(() => getNameForParty(id, data), [data, id]);
|
||||
const useName = name !== id;
|
||||
@@ -44,7 +52,7 @@ const PartyLink = ({ id, truncate = false, ...props }: PartyLinkProps) => {
|
||||
if (id === SPECIAL_CASE_NETWORK || id === SPECIAL_CASE_NETWORK_ID) {
|
||||
return (
|
||||
<span className="font-mono" data-testid="network">
|
||||
{t('Network')}
|
||||
{networkLabel}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -70,7 +78,11 @@ const PartyLink = ({ id, truncate = false, ...props }: PartyLinkProps) => {
|
||||
{useName ? (
|
||||
name
|
||||
) : (
|
||||
<Hash text={truncate ? truncateMiddle(id, 4, 4) : id} />
|
||||
<Hash
|
||||
text={
|
||||
truncate ? truncateMiddle(id, truncateLength, truncateLength) : id
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</Link>
|
||||
</span>
|
||||
|
||||
@@ -175,6 +175,7 @@ describe('Amend order details', () => {
|
||||
|
||||
const res = renderExistingAmend('123', 1, amend);
|
||||
expect(await res.findByText('New size')).toBeInTheDocument();
|
||||
expect(await res.findByText('Size ±')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('Renders Reference if provided', async () => {
|
||||
|
||||
@@ -82,7 +82,7 @@ const AmendOrderDetails = ({ id, version, amend }: AmendOrderDetailsProps) => {
|
||||
{amend.sizeDelta && amend.sizeDelta !== '0' ? (
|
||||
<div className="mb-12 md:mb-0">
|
||||
<h2 className="text-dark mb-4 text-2xl font-bold">
|
||||
{t('New size')}
|
||||
{t('Size ±')}
|
||||
</h2>
|
||||
<h5
|
||||
className={`mb-0 text-lg font-medium capitalize text-gray-500 ${getSideDeltaColour(
|
||||
@@ -93,6 +93,16 @@ const AmendOrderDetails = ({ id, version, amend }: AmendOrderDetailsProps) => {
|
||||
</h5>
|
||||
</div>
|
||||
) : null}
|
||||
{o && (
|
||||
<div className="">
|
||||
<h2 className="text-dark mb-4 text-2xl font-bold">
|
||||
{t('New size')}
|
||||
</h2>
|
||||
<h5 className="mb-0 text-lg font-medium text-gray-500">
|
||||
{o ? o.size : null}
|
||||
</h5>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{amend.price && amend.price !== '0' ? (
|
||||
<div className="">
|
||||
|
||||
@@ -34,10 +34,7 @@ export function TransferStatusView({ status, loading }: TransferStatusProps) {
|
||||
) : (
|
||||
<>
|
||||
<p className="leading-10 my-2">
|
||||
<Icon
|
||||
name={getIconForStatus(status)}
|
||||
className={getColourForStatus(status)}
|
||||
/>
|
||||
<TransferStatusIcon status={status} />
|
||||
</p>
|
||||
<p className="leading-10 my-2">{TransferStatusMapping[status]}</p>
|
||||
</>
|
||||
@@ -47,6 +44,21 @@ export function TransferStatusView({ status, loading }: TransferStatusProps) {
|
||||
);
|
||||
}
|
||||
|
||||
interface TransferStatusIconProps {
|
||||
status: TransferStatus;
|
||||
}
|
||||
|
||||
export function TransferStatusIcon({ status }: TransferStatusIconProps) {
|
||||
return (
|
||||
<span title={TransferStatusMapping[status]}>
|
||||
<Icon
|
||||
name={getIconForStatus(status)}
|
||||
className={getColourForStatus(status)}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple mapping from status to icon name
|
||||
* @param status TransferStatus
|
||||
@@ -60,6 +72,8 @@ export function getIconForStatus(status: TransferStatus): IconName {
|
||||
return IconNames.TICK;
|
||||
case TransferStatus.STATUS_REJECTED:
|
||||
return IconNames.CROSS;
|
||||
case TransferStatus.STATUS_CANCELLED:
|
||||
return IconNames.CROSS;
|
||||
default:
|
||||
return IconNames.TIME;
|
||||
}
|
||||
@@ -78,6 +92,8 @@ export function getColourForStatus(status: TransferStatus): string {
|
||||
return 'text-green-500';
|
||||
case TransferStatus.STATUS_REJECTED:
|
||||
return 'text-red-500';
|
||||
case TransferStatus.STATUS_CANCELLED:
|
||||
return 'text-red-600';
|
||||
default:
|
||||
return 'text-yellow-500';
|
||||
}
|
||||
|
||||
@@ -12,4 +12,5 @@ export const Routes = {
|
||||
ORACLES: 'oracles',
|
||||
NETWORK_PARAMETERS: 'network-parameters',
|
||||
DISCLAIMER: 'disclaimer',
|
||||
TREASURY: 'treasury',
|
||||
};
|
||||
|
||||
@@ -30,6 +30,7 @@ import { PartyAccountsByAsset } from './parties/id/accounts';
|
||||
import { Disclaimer } from './pages/disclaimer';
|
||||
import { useFeatureFlags } from '@vegaprotocol/environment';
|
||||
import RestrictedPage from './restricted';
|
||||
import { NetworkTreasury } from './treasury';
|
||||
|
||||
export type Navigable = {
|
||||
path: string;
|
||||
@@ -229,6 +230,17 @@ export const useRouterConfig = () => {
|
||||
]
|
||||
: [];
|
||||
|
||||
const treasuryRoutes: Route[] = [
|
||||
{
|
||||
path: Routes.TREASURY,
|
||||
handle: {
|
||||
name: t('Treasury'),
|
||||
text: t('Treasury'),
|
||||
breadcrumb: () => <Link to={Routes.TREASURY}>{t('Treasury')}</Link>,
|
||||
},
|
||||
element: <NetworkTreasury />,
|
||||
},
|
||||
];
|
||||
const validators: Route[] = featureFlags.EXPLORER_VALIDATORS
|
||||
? [
|
||||
{
|
||||
@@ -358,6 +370,7 @@ export const useRouterConfig = () => {
|
||||
...marketsRoutes,
|
||||
...networkParametersRoutes,
|
||||
...validators,
|
||||
...treasuryRoutes,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
query ExplorerTreasury {
|
||||
assetsConnection(pagination: { last: 1000 }) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
networkTreasuryAccount {
|
||||
balance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
query ExplorerTreasuryTransfers {
|
||||
transfersConnection(
|
||||
partyId: "network"
|
||||
direction: ToOrFrom
|
||||
pagination: { last: 200 }
|
||||
) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
transfer {
|
||||
timestamp
|
||||
from
|
||||
amount
|
||||
to
|
||||
status
|
||||
reason
|
||||
toAccountType
|
||||
fromAccountType
|
||||
asset {
|
||||
id
|
||||
}
|
||||
id
|
||||
status
|
||||
kind {
|
||||
... on OneOffTransfer {
|
||||
deliverOn
|
||||
}
|
||||
... on RecurringTransfer {
|
||||
startEpoch
|
||||
}
|
||||
... on OneOffGovernanceTransfer {
|
||||
deliverOn
|
||||
}
|
||||
... on RecurringGovernanceTransfer {
|
||||
endEpoch
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import * as Types from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type ExplorerTreasuryQueryVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type ExplorerTreasuryQuery = { __typename?: 'Query', assetsConnection?: { __typename?: 'AssetsConnection', edges?: Array<{ __typename?: 'AssetEdge', node: { __typename?: 'Asset', id: string, networkTreasuryAccount?: { __typename?: 'AccountBalance', balance: string } | null } } | null> | null } | null };
|
||||
|
||||
|
||||
export const ExplorerTreasuryDocument = gql`
|
||||
query ExplorerTreasury {
|
||||
assetsConnection(pagination: {last: 1000}) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
networkTreasuryAccount {
|
||||
balance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useExplorerTreasuryQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useExplorerTreasuryQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useExplorerTreasuryQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useExplorerTreasuryQuery({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useExplorerTreasuryQuery(baseOptions?: Apollo.QueryHookOptions<ExplorerTreasuryQuery, ExplorerTreasuryQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<ExplorerTreasuryQuery, ExplorerTreasuryQueryVariables>(ExplorerTreasuryDocument, options);
|
||||
}
|
||||
export function useExplorerTreasuryLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<ExplorerTreasuryQuery, ExplorerTreasuryQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<ExplorerTreasuryQuery, ExplorerTreasuryQueryVariables>(ExplorerTreasuryDocument, options);
|
||||
}
|
||||
export type ExplorerTreasuryQueryHookResult = ReturnType<typeof useExplorerTreasuryQuery>;
|
||||
export type ExplorerTreasuryLazyQueryHookResult = ReturnType<typeof useExplorerTreasuryLazyQuery>;
|
||||
export type ExplorerTreasuryQueryResult = Apollo.QueryResult<ExplorerTreasuryQuery, ExplorerTreasuryQueryVariables>;
|
||||
@@ -0,0 +1,84 @@
|
||||
import * as Types from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type ExplorerTreasuryTransfersQueryVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type ExplorerTreasuryTransfersQuery = { __typename?: 'Query', transfersConnection?: { __typename?: 'TransferConnection', pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean }, edges?: Array<{ __typename?: 'TransferEdge', node: { __typename?: 'TransferNode', transfer: { __typename?: 'Transfer', timestamp: any, from: string, amount: string, to: string, status: Types.TransferStatus, reason?: string | null, toAccountType: Types.AccountType, fromAccountType: Types.AccountType, id: string, asset?: { __typename?: 'Asset', id: string } | null, kind: { __typename?: 'OneOffGovernanceTransfer', deliverOn?: any | null } | { __typename?: 'OneOffTransfer', deliverOn?: any | null } | { __typename?: 'RecurringGovernanceTransfer', endEpoch?: number | null } | { __typename?: 'RecurringTransfer', startEpoch: number } } } } | null> | null } | null };
|
||||
|
||||
|
||||
export const ExplorerTreasuryTransfersDocument = gql`
|
||||
query ExplorerTreasuryTransfers {
|
||||
transfersConnection(
|
||||
partyId: "network"
|
||||
direction: ToOrFrom
|
||||
pagination: {last: 200}
|
||||
) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
transfer {
|
||||
timestamp
|
||||
from
|
||||
amount
|
||||
to
|
||||
status
|
||||
reason
|
||||
toAccountType
|
||||
fromAccountType
|
||||
asset {
|
||||
id
|
||||
}
|
||||
id
|
||||
status
|
||||
kind {
|
||||
... on OneOffTransfer {
|
||||
deliverOn
|
||||
}
|
||||
... on RecurringTransfer {
|
||||
startEpoch
|
||||
}
|
||||
... on OneOffGovernanceTransfer {
|
||||
deliverOn
|
||||
}
|
||||
... on RecurringGovernanceTransfer {
|
||||
endEpoch
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useExplorerTreasuryTransfersQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useExplorerTreasuryTransfersQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useExplorerTreasuryTransfersQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useExplorerTreasuryTransfersQuery({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useExplorerTreasuryTransfersQuery(baseOptions?: Apollo.QueryHookOptions<ExplorerTreasuryTransfersQuery, ExplorerTreasuryTransfersQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<ExplorerTreasuryTransfersQuery, ExplorerTreasuryTransfersQueryVariables>(ExplorerTreasuryTransfersDocument, options);
|
||||
}
|
||||
export function useExplorerTreasuryTransfersLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<ExplorerTreasuryTransfersQuery, ExplorerTreasuryTransfersQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<ExplorerTreasuryTransfersQuery, ExplorerTreasuryTransfersQueryVariables>(ExplorerTreasuryTransfersDocument, options);
|
||||
}
|
||||
export type ExplorerTreasuryTransfersQueryHookResult = ReturnType<typeof useExplorerTreasuryTransfersQuery>;
|
||||
export type ExplorerTreasuryTransfersLazyQueryHookResult = ReturnType<typeof useExplorerTreasuryTransfersLazyQuery>;
|
||||
export type ExplorerTreasuryTransfersQueryResult = Apollo.QueryResult<ExplorerTreasuryTransfersQuery, ExplorerTreasuryTransfersQueryVariables>;
|
||||
@@ -0,0 +1,37 @@
|
||||
// NOTE: These are a temporary measure, pulled from an old branch on console.
|
||||
|
||||
import { IconNames } from '@blueprintjs/icons';
|
||||
import { Icon } from '@vegaprotocol/ui-toolkit';
|
||||
import { USDc } from './usdc';
|
||||
import { Vega } from './vega';
|
||||
import { USDt } from './usdt';
|
||||
|
||||
export interface AssetIconProps {
|
||||
symbol: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A poorly implemented, limited support for asset icons.
|
||||
*
|
||||
* These are committed as 'deprecated' to discourage use outside the Treasury page. Rather
|
||||
* than use this, a better approach would be to use source contract addresses to match assets.
|
||||
* This will be done separately.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function AssetIcon({ symbol }: AssetIconProps) {
|
||||
const s = symbol.toLowerCase();
|
||||
switch (s) {
|
||||
case 'a4a16e250a09a86061ec83c2f9466fc9dc33d332f86876ee74b6f128a5cd6710': // mainnet
|
||||
case 'c9fe6fc24fce121b2cc72680543a886055abb560043fda394ba5376203b7527d': // mainnet
|
||||
return <USDc size={32} />;
|
||||
case 'd1984e3d365faa05bcafbe41f50f90e3663ee7c0da22bb1e24b164e9532691b2': // mainnet
|
||||
case 'fc7fd956078fb1fc9db5c19b88f0874c4299b2a7639ad05a47a28c0aef291b55': // testnet
|
||||
return <Vega size={32} />;
|
||||
case 'bf1e88d19db4b3ca0d1d5bdb73718a01686b18cf731ca26adedf3c8b83802bba': // mainnet
|
||||
case 'ede4076aef07fd79502d14326c54ab3911558371baaf697a19d077f4f89de399': // testnet
|
||||
return <USDt size={32} />;
|
||||
default:
|
||||
return <Icon name={IconNames.BANK_ACCOUNT} size={8} />;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* See note in index.tsx. This component is intended as a placeholder for a
|
||||
* better, more generic solution.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export const USDc = ({ size = 16 }: { size?: number }) => {
|
||||
return (
|
||||
<svg width={size} height={size} viewBox="0 0 2000 2000">
|
||||
<path
|
||||
d="M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z"
|
||||
fill="#2775ca"
|
||||
/>
|
||||
<path
|
||||
d="M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z"
|
||||
fill="#fff"
|
||||
/>
|
||||
<path
|
||||
d="M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z"
|
||||
fill="#fff"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* See note in index.tsx. This component is intended as a placeholder for a
|
||||
* better, more generic solution.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export const USDt = ({ size = 16 }: { size?: number }) => {
|
||||
return (
|
||||
<svg width={size} height={size} viewBox="0 0 339.43 295.27">
|
||||
<path
|
||||
fill="#50af95"
|
||||
d="M62.15,1.45l-61.89,130a2.52,2.52,0,0,0,.54,2.94L167.95,294.56a2.55,2.55,0,0,0,3.53,0L338.63,134.4a2.52,2.52,0,0,0,.54-2.94l-61.89-130A2.5,2.5,0,0,0,275,0H64.45a2.5,2.5,0,0,0-2.3,1.45h0Z"
|
||||
/>
|
||||
<path
|
||||
fill="#fff"
|
||||
d="M191.19,144.8v0c-1.2.09-7.4,0.46-21.23,0.46-11,0-18.81-.33-21.55-0.46v0c-42.51-1.87-74.24-9.27-74.24-18.13s31.73-16.25,74.24-18.15v28.91c2.78,0.2,10.74.67,21.74,0.67,13.2,0,19.81-.55,21-0.66v-28.9c42.42,1.89,74.08,9.29,74.08,18.13s-31.65,16.24-74.08,18.12h0Zm0-39.25V79.68h59.2V40.23H89.21V79.68H148.4v25.86c-48.11,2.21-84.29,11.74-84.29,23.16s36.18,20.94,84.29,23.16v82.9h42.78V151.83c48-2.21,84.12-11.73,84.12-23.14s-36.09-20.93-84.12-23.15h0Zm0,0h0Z"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* See note in index.tsx. This component is intended as a placeholder for a
|
||||
* better, more generic solution.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export const Vega = ({ size = 16 }: { size?: number }) => {
|
||||
return (
|
||||
<svg width={size} height={size} viewBox="0 0 42 42">
|
||||
<rect width="42" height="42" rx="21" fill="black" />
|
||||
<path d="M13 27.2726H16.4545V10H13V27.2726Z" fill="white" />
|
||||
<path d="M25.667 23.8181H29.1215V10H25.667V23.8181Z" fill="white" />
|
||||
<path d="M19.333 33.6059H22.7875V30.1514H19.333V33.6059Z" fill="white" />
|
||||
<path
|
||||
d="M22.7871 30.7271H26.2416V27.2726H22.7871V30.7271Z"
|
||||
fill="white"
|
||||
/>
|
||||
<path
|
||||
d="M29.1211 27.2726H31.9999V23.8181H29.1211V27.2726Z"
|
||||
fill="white"
|
||||
/>
|
||||
<path
|
||||
d="M16.4551 30.7271H19.3339V27.2726H16.4551V30.7271Z"
|
||||
fill="white"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,171 @@
|
||||
import type { DeepPartial } from '@apollo/client/utilities';
|
||||
import { parseResultsToAccounts } from './network-accounts-table';
|
||||
import {
|
||||
ExplorerTreasuryDocument,
|
||||
type ExplorerTreasuryQuery,
|
||||
} from '../__generated__/Treasury';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { NetworkAccountsTable } from './network-accounts-table';
|
||||
|
||||
describe('parseResultsToAccounts', () => {
|
||||
it('should return an array of non-zero treasury accounts', () => {
|
||||
const data: DeepPartial<ExplorerTreasuryQuery> = {
|
||||
assetsConnection: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
id: 'asset1',
|
||||
networkTreasuryAccount: {
|
||||
balance: '100',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
id: 'has0assets',
|
||||
networkTreasuryAccount: {
|
||||
balance: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
id: 'asset3',
|
||||
networkTreasuryAccount: {
|
||||
balance: '50',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
id: 'hasnonetworktreasuryaccount',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const result = parseResultsToAccounts(data as ExplorerTreasuryQuery);
|
||||
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result).toEqual([
|
||||
{
|
||||
assetId: 'asset1',
|
||||
balance: '100',
|
||||
type: 'ACCOUNT_TYPE_NETWORK_TREASURY',
|
||||
},
|
||||
{
|
||||
assetId: 'asset3',
|
||||
balance: '50',
|
||||
type: 'ACCOUNT_TYPE_NETWORK_TREASURY',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return an empty array if no non-zero accounts are found', () => {
|
||||
const data: DeepPartial<ExplorerTreasuryQuery> = {
|
||||
assetsConnection: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
id: 'asset1',
|
||||
networkTreasuryAccount: {
|
||||
balance: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
id: 'asset2',
|
||||
networkTreasuryAccount: {
|
||||
balance: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const result = parseResultsToAccounts(data as ExplorerTreasuryQuery);
|
||||
|
||||
expect(result).toHaveLength(0);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('should handle missing data', () => {
|
||||
const result = parseResultsToAccounts(
|
||||
undefined as unknown as ExplorerTreasuryQuery
|
||||
);
|
||||
|
||||
expect(result).toHaveLength(0);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('NetworkAccountsTable', () => {
|
||||
const mockData: ExplorerTreasuryQuery = {
|
||||
assetsConnection: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
id: 'asset1',
|
||||
networkTreasuryAccount: {
|
||||
balance: '100',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
id: 'asset2',
|
||||
networkTreasuryAccount: {
|
||||
balance: '50',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const mocks = [
|
||||
{
|
||||
request: {
|
||||
query: ExplorerTreasuryDocument,
|
||||
},
|
||||
result: {
|
||||
data: mockData,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
it('should render network accounts (as many as match - often just 1)', async () => {
|
||||
render(
|
||||
<MockedProvider mocks={mocks} addTypename={false}>
|
||||
<MemoryRouter>
|
||||
<NetworkAccountsTable />
|
||||
</MemoryRouter>
|
||||
</MockedProvider>
|
||||
);
|
||||
|
||||
// Wait for the data to load
|
||||
await screen.findByText('Loading...');
|
||||
|
||||
// Assert that the network accounts are rendered
|
||||
expect(screen.getByText('asset1')).toBeInTheDocument();
|
||||
expect(screen.getByText('asset2')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should handle loading state', async () => {
|
||||
render(
|
||||
<MockedProvider mocks={mocks} addTypename={false}>
|
||||
<MemoryRouter>
|
||||
<NetworkAccountsTable />
|
||||
</MemoryRouter>
|
||||
</MockedProvider>
|
||||
);
|
||||
|
||||
// Assert that the loading state is rendered
|
||||
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||
import {
|
||||
type ExplorerTreasuryQuery,
|
||||
useExplorerTreasuryQuery,
|
||||
} from '../__generated__/Treasury';
|
||||
import AssetBalance from '../../../components/asset-balance/asset-balance';
|
||||
import { AssetLink } from '../../../components/links';
|
||||
import { useMemo } from 'react';
|
||||
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
||||
import { AssetIcon } from './asset-icon';
|
||||
import { type NonZeroAccount } from '../network-treasury';
|
||||
import { AccountType } from '@vegaprotocol/types';
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
|
||||
export const NetworkAccountsTable = () => {
|
||||
const { data, loading, error } = useExplorerTreasuryQuery({
|
||||
// This needs to ignore error as old assets may no longer properly resolve
|
||||
errorPolicy: 'ignore',
|
||||
});
|
||||
const { screenSize } = useScreenDimensions();
|
||||
const shouldRound = useMemo(
|
||||
() => ['xs', 'sm', 'md', 'lg'].includes(screenSize),
|
||||
[screenSize]
|
||||
);
|
||||
|
||||
return (
|
||||
<AsyncRenderer
|
||||
data={data}
|
||||
loading={loading}
|
||||
error={error}
|
||||
render={(data) => {
|
||||
const c = parseResultsToAccounts(data);
|
||||
return (
|
||||
<section className="md:flex md:flex-row flex-wrap">
|
||||
{c.map((a) => (
|
||||
<div className="basis-1/2 md:basis-1/4">
|
||||
<div className="bg-white rounded overflow-hidden shadow-lg dark:bg-black dark:border-slate-500 dark:border">
|
||||
<div className="text-center p-6 bg-gray-100 dark:bg-slate-900 border-b dark:border-slate-500">
|
||||
<p className="flex justify-center">
|
||||
<AssetIcon symbol={a.assetId} />
|
||||
</p>
|
||||
<p className="mt-3" data-testid="name">
|
||||
<AssetLink assetId={a.assetId} />
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-center py-5" data-testid="balance">
|
||||
<AssetBalance
|
||||
assetId={a.assetId}
|
||||
price={a.balance}
|
||||
showAssetSymbol={true}
|
||||
rounded={shouldRound}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export function parseResultsToAccounts(
|
||||
data: ExplorerTreasuryQuery
|
||||
): NonZeroAccount[] {
|
||||
const nonZeroAccounts: NonZeroAccount[] = [];
|
||||
if (data?.assetsConnection?.edges) {
|
||||
const edges = removePaginationWrapper(data?.assetsConnection?.edges);
|
||||
if (edges) {
|
||||
edges.forEach((edge) => {
|
||||
if (
|
||||
edge.networkTreasuryAccount &&
|
||||
edge.networkTreasuryAccount?.balance !== '0'
|
||||
) {
|
||||
nonZeroAccounts.push({
|
||||
assetId: edge.id,
|
||||
balance: edge.networkTreasuryAccount?.balance,
|
||||
type: AccountType.ACCOUNT_TYPE_NETWORK_TREASURY,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return nonZeroAccounts;
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
import { AccountType } from '@vegaprotocol/types';
|
||||
import {
|
||||
typeLabel,
|
||||
getToAccountTypeLabel,
|
||||
filterAccountTransfers,
|
||||
} from './network-transfers-table';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { NetworkTransfersTable } from './network-transfers-table';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import {
|
||||
ExplorerTreasuryTransfersDocument,
|
||||
type ExplorerTreasuryTransfersQuery,
|
||||
} from '../__generated__/TreasuryTransfers';
|
||||
import type { DeepPartial } from '@apollo/client/utilities';
|
||||
|
||||
describe('typeLabel', () => {
|
||||
it('should return "Transfer" for "OneOffTransfer" kind', () => {
|
||||
expect(typeLabel('OneOffTransfer')).toBe('Transfer');
|
||||
});
|
||||
|
||||
it('should return "Transfer" for "RecurringTransfer" kind', () => {
|
||||
expect(typeLabel('RecurringTransfer')).toBe('Transfer');
|
||||
});
|
||||
|
||||
it('should return "Governance" for "OneOffGovernanceTransfer" kind', () => {
|
||||
expect(typeLabel('OneOffGovernanceTransfer')).toBe('Governance');
|
||||
});
|
||||
|
||||
it('should return "Governance" for "RecurringGovernanceTransfer" kind', () => {
|
||||
expect(typeLabel('RecurringGovernanceTransfer')).toBe('Governance');
|
||||
});
|
||||
|
||||
it('should return "Unknown" for unknown kind', () => {
|
||||
expect(typeLabel()).toBe('Unknown');
|
||||
expect(typeLabel('')).toBe('Unknown');
|
||||
expect(typeLabel('InvalidKind')).toBe('Unknown');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getToAccountTypeLabel', () => {
|
||||
it('should return "Treasury" when type is ACCOUNT_TYPE_NETWORK_TREASURY', () => {
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_NETWORK_TREASURY)
|
||||
).toBe('Treasury');
|
||||
});
|
||||
|
||||
it('should return "Fees" when type is any of the fee account types', () => {
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE)
|
||||
).toBe('Fees');
|
||||
expect(getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_FEES_MAKER)).toBe(
|
||||
'Fees'
|
||||
);
|
||||
expect(getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY)).toBe(
|
||||
'Fees'
|
||||
);
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_LP_LIQUIDITY_FEES)
|
||||
).toBe('Fees');
|
||||
expect(
|
||||
getToAccountTypeLabel(
|
||||
AccountType.ACCOUNT_TYPE_PENDING_FEE_REFERRAL_REWARD
|
||||
)
|
||||
).toBe('Fees');
|
||||
});
|
||||
|
||||
it('should return "Insurance" when type is ACCOUNT_TYPE_GLOBAL_INSURANCE', () => {
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_GLOBAL_INSURANCE)
|
||||
).toBe('Insurance');
|
||||
});
|
||||
|
||||
it('should return "Rewards" when type is any of the reward account types', () => {
|
||||
expect(getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_GLOBAL_REWARD)).toBe(
|
||||
'Rewards'
|
||||
);
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_REWARD_AVERAGE_POSITION)
|
||||
).toBe('Rewards');
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_REWARD_LP_RECEIVED_FEES)
|
||||
).toBe('Rewards');
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES)
|
||||
).toBe('Rewards');
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES)
|
||||
).toBe('Rewards');
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS)
|
||||
).toBe('Rewards');
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_REWARD_RELATIVE_RETURN)
|
||||
).toBe('Rewards');
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_REWARD_RETURN_VOLATILITY)
|
||||
).toBe('Rewards');
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_REWARD_VALIDATOR_RANKING)
|
||||
).toBe('Rewards');
|
||||
expect(getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_VESTED_REWARDS)).toBe(
|
||||
'Rewards'
|
||||
);
|
||||
expect(
|
||||
getToAccountTypeLabel(AccountType.ACCOUNT_TYPE_VESTING_REWARDS)
|
||||
).toBe('Rewards');
|
||||
});
|
||||
|
||||
it('should return "Other" for any other type', () => {
|
||||
expect(getToAccountTypeLabel(undefined)).toBe('Other');
|
||||
expect(getToAccountTypeLabel('unknown' as AccountType)).toBe('Other');
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterAccountTransfers', () => {
|
||||
it('filters out transactions that are not to or from a treasury account', () => {
|
||||
const data: DeepPartial<ExplorerTreasuryTransfersQuery> = {
|
||||
transfersConnection: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
transfer: {
|
||||
toAccountType: AccountType.ACCOUNT_TYPE_NETWORK_TREASURY,
|
||||
fromAccountType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
transfer: {
|
||||
toAccountType: AccountType.ACCOUNT_TYPE_NETWORK_TREASURY,
|
||||
fromAccountType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_AVERAGE_POSITION,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
transfer: {
|
||||
toAccountType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
fromAccountType: AccountType.ACCOUNT_TYPE_NETWORK_TREASURY,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
transfer: {
|
||||
toAccountType: AccountType.ACCOUNT_TYPE_REWARD_AVERAGE_POSITION,
|
||||
fromAccountType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_LP_RECEIVED_FEES,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const result = filterAccountTransfers(
|
||||
data as ExplorerTreasuryTransfersQuery
|
||||
);
|
||||
|
||||
expect(result).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('should return an empty array if no transfers match the filter', () => {
|
||||
const data: DeepPartial<ExplorerTreasuryTransfersQuery> = {
|
||||
transfersConnection: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
transfer: {
|
||||
toAccountType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
fromAccountType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
transfer: {
|
||||
toAccountType: AccountType.ACCOUNT_TYPE_REWARD_AVERAGE_POSITION,
|
||||
fromAccountType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_AVERAGE_POSITION,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const result = filterAccountTransfers(
|
||||
data as ExplorerTreasuryTransfersQuery
|
||||
);
|
||||
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('NetworkTransfersTable', () => {
|
||||
it('renders table headers correctly', async () => {
|
||||
const mocks = [
|
||||
{
|
||||
request: {
|
||||
query: ExplorerTreasuryTransfersDocument,
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
transfersConnection: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
transfer: {
|
||||
id: '123',
|
||||
toAccountType: AccountType.ACCOUNT_TYPE_NETWORK_TREASURY,
|
||||
fromAccountType:
|
||||
AccountType.ACCOUNT_TYPE_NETWORK_TREASURY,
|
||||
amount: '100',
|
||||
asset: {
|
||||
id: '1',
|
||||
},
|
||||
timestamp: '2022-01-01T00:00:00Z',
|
||||
from: 'network',
|
||||
to: '7100a8a82ef45adb9efa070cc821c6c5c48172d6dc5f842431549490fe5897a0',
|
||||
reason: '',
|
||||
status: 'COMPLETED',
|
||||
kind: {
|
||||
__typename: 'OneOffGovernanceTransfer',
|
||||
deliverOn: '123',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
render(
|
||||
<MockedProvider mocks={mocks} addTypename={true}>
|
||||
<MemoryRouter>
|
||||
<NetworkTransfersTable />
|
||||
</MemoryRouter>
|
||||
</MockedProvider>
|
||||
);
|
||||
|
||||
expect(await screen.findByText('Amount')).toBeInTheDocument();
|
||||
expect(screen.getByText('Asset')).toBeInTheDocument();
|
||||
expect(screen.getByText('Age')).toBeInTheDocument();
|
||||
expect(screen.getByText('From')).toBeInTheDocument();
|
||||
expect(screen.getByText('To')).toBeInTheDocument();
|
||||
expect(screen.getByText('Status')).toBeInTheDocument();
|
||||
expect(screen.getByText('Type')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByTestId('from-account').textContent).toEqual('Treasury');
|
||||
expect(screen.getByTestId('to-account').textContent).toEqual('7100…97a0');
|
||||
expect(screen.getByTestId('transfer-kind').textContent).toEqual(
|
||||
'Governance'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,253 @@
|
||||
import { AsyncRenderer, Icon } from '@vegaprotocol/ui-toolkit';
|
||||
import AssetBalance from '../../../components/asset-balance/asset-balance';
|
||||
import { AccountType, AccountTypeMapping } from '@vegaprotocol/types';
|
||||
import { AssetLink, PartyLink } from '../../../components/links';
|
||||
import {
|
||||
type ExplorerTreasuryTransfersQuery,
|
||||
useExplorerTreasuryTransfersQuery,
|
||||
} from '../__generated__/TreasuryTransfers';
|
||||
import { TimeAgo } from '../../../components/time-ago';
|
||||
import { TransferStatusIcon } from '../../../components/txs/details/transfer/blocks/transfer-status';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { IconNames } from '@blueprintjs/icons';
|
||||
import { useMemo } from 'react';
|
||||
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
||||
|
||||
export const colours = {
|
||||
INCOMING: '!fill-vega-green-600 text-vega-green-600 mr-2',
|
||||
OUTGOING: '!fill-vega-pink-600 text-vega-pink-600 mr-2',
|
||||
};
|
||||
|
||||
export const theadClasses =
|
||||
'py-2 border text-center bg-vega-light-150 dark:bg-vega-dark-150';
|
||||
|
||||
export function getToAccountTypeLabel(type?: AccountType): string {
|
||||
switch (type) {
|
||||
case AccountType.ACCOUNT_TYPE_NETWORK_TREASURY:
|
||||
return t('Treasury');
|
||||
case AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE:
|
||||
case AccountType.ACCOUNT_TYPE_FEES_MAKER:
|
||||
case AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY:
|
||||
case AccountType.ACCOUNT_TYPE_LP_LIQUIDITY_FEES:
|
||||
case AccountType.ACCOUNT_TYPE_PENDING_FEE_REFERRAL_REWARD:
|
||||
return t('Fees');
|
||||
case AccountType.ACCOUNT_TYPE_GLOBAL_INSURANCE:
|
||||
return t('Insurance');
|
||||
case AccountType.ACCOUNT_TYPE_GLOBAL_REWARD:
|
||||
case AccountType.ACCOUNT_TYPE_REWARD_AVERAGE_POSITION:
|
||||
case AccountType.ACCOUNT_TYPE_REWARD_LP_RECEIVED_FEES:
|
||||
case AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES:
|
||||
case AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES:
|
||||
case AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS:
|
||||
case AccountType.ACCOUNT_TYPE_REWARD_RELATIVE_RETURN:
|
||||
case AccountType.ACCOUNT_TYPE_REWARD_RETURN_VOLATILITY:
|
||||
case AccountType.ACCOUNT_TYPE_REWARD_VALIDATOR_RANKING:
|
||||
case AccountType.ACCOUNT_TYPE_VESTED_REWARDS:
|
||||
case AccountType.ACCOUNT_TYPE_VESTING_REWARDS:
|
||||
return t('Rewards');
|
||||
default:
|
||||
return t('Other');
|
||||
}
|
||||
}
|
||||
|
||||
export function typeLabel(kind?: string): string {
|
||||
switch (kind) {
|
||||
case 'OneOffTransfer':
|
||||
case 'RecurringTransfer':
|
||||
return t('Transfer');
|
||||
case 'OneOffGovernanceTransfer':
|
||||
case 'RecurringGovernanceTransfer':
|
||||
return t('Governance');
|
||||
default:
|
||||
return t('Unknown');
|
||||
}
|
||||
}
|
||||
|
||||
export function filterAccountTransfers(data: ExplorerTreasuryTransfersQuery) {
|
||||
return data.transfersConnection?.edges
|
||||
?.filter((edge) => {
|
||||
if (
|
||||
edge?.node.transfer.toAccountType ===
|
||||
AccountType.ACCOUNT_TYPE_NETWORK_TREASURY
|
||||
) {
|
||||
return true;
|
||||
} else if (
|
||||
edge?.node.transfer.fromAccountType ===
|
||||
AccountType.ACCOUNT_TYPE_NETWORK_TREASURY
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.map((edge) => {
|
||||
return edge?.node.transfer;
|
||||
});
|
||||
}
|
||||
|
||||
export const NetworkTransfersTable = () => {
|
||||
const { data, loading, error } = useExplorerTreasuryTransfersQuery({
|
||||
// This needs to ignore error as old assets may no longer properly resolve
|
||||
errorPolicy: 'ignore',
|
||||
});
|
||||
|
||||
const { screenSize } = useScreenDimensions();
|
||||
const shouldRound = useMemo(
|
||||
() => ['xs', 'sm', 'md', 'lg'].includes(screenSize),
|
||||
[screenSize]
|
||||
);
|
||||
const shouldTruncate = useMemo(
|
||||
() => ['xs', 'sm', 'md', 'lg', 'xl'].includes(screenSize),
|
||||
[screenSize]
|
||||
);
|
||||
const shouldHideColumns = useMemo(
|
||||
() => ['xs', 'sm'].includes(screenSize),
|
||||
[screenSize]
|
||||
);
|
||||
|
||||
return (
|
||||
<section>
|
||||
<AsyncRenderer
|
||||
data={data}
|
||||
loading={loading}
|
||||
error={error}
|
||||
render={(data) => {
|
||||
const c = filterAccountTransfers(data);
|
||||
if (!c) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<table className="table-fixed border-spacing-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className={theadClasses}>{t('Amount')}</th>
|
||||
<th className={theadClasses}>{t('Asset')}</th>
|
||||
<th className={theadClasses}>{t('Age')}</th>
|
||||
<th className={theadClasses}>{t('From')}</th>
|
||||
<th className={theadClasses}>{t('To')}</th>
|
||||
<th
|
||||
className={`${theadClasses} ${
|
||||
shouldHideColumns ? 'hidden' : ''
|
||||
}`}
|
||||
>
|
||||
{t('Status')}
|
||||
</th>
|
||||
<th
|
||||
className={`${theadClasses} ${
|
||||
shouldHideColumns ? 'hidden' : ''
|
||||
}`}
|
||||
>
|
||||
{t('Type')}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{c.map((a) => {
|
||||
const isIncoming =
|
||||
a?.toAccountType ===
|
||||
AccountType.ACCOUNT_TYPE_NETWORK_TREASURY;
|
||||
return (
|
||||
<tr>
|
||||
{a && a.amount && a.asset && (
|
||||
<td
|
||||
className={`px-2 py-1 border whitespace-nowrap text-right ${
|
||||
isIncoming ? colours.INCOMING : colours.OUTGOING
|
||||
}`}
|
||||
title={a.amount}
|
||||
>
|
||||
{a &&
|
||||
a.toAccountType ===
|
||||
AccountType.ACCOUNT_TYPE_NETWORK_TREASURY ? (
|
||||
<Icon
|
||||
name={IconNames.PLUS}
|
||||
className={colours.INCOMING}
|
||||
/>
|
||||
) : (
|
||||
<Icon
|
||||
name={IconNames.MINUS}
|
||||
className={colours.OUTGOING}
|
||||
/>
|
||||
)}
|
||||
<AssetBalance
|
||||
assetId={a.asset.id}
|
||||
price={a.amount}
|
||||
showAssetLink={false}
|
||||
rounded={shouldRound}
|
||||
/>
|
||||
</td>
|
||||
)}
|
||||
<td className="px-2 py-1 border whitespace-nowrap">
|
||||
{a && a.amount && a.asset && (
|
||||
<AssetLink
|
||||
assetId={a.asset.id}
|
||||
showAssetSymbol={true}
|
||||
/>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-2 py-1 border">
|
||||
{a && a.timestamp && <TimeAgo date={a.timestamp} />}
|
||||
</td>
|
||||
<td
|
||||
className="px-2 py-1 border"
|
||||
data-testid="from-account"
|
||||
>
|
||||
{a && a.from && (
|
||||
<PartyLink
|
||||
id={a.from}
|
||||
truncate={true}
|
||||
truncateLength={shouldTruncate ? 4 : 15}
|
||||
networkLabel={t('Treasury')}
|
||||
/>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-2 py-1 border" data-testid="to-account">
|
||||
{a && a.to && (
|
||||
<PartyLink
|
||||
id={a.to}
|
||||
networkLabel={t('Treasury')}
|
||||
truncate={true}
|
||||
truncateLength={shouldTruncate ? 4 : 15}
|
||||
/>
|
||||
)}
|
||||
{a && !a.to && (
|
||||
<span
|
||||
className="underline decoration-dotted"
|
||||
title={AccountTypeMapping[a.toAccountType]}
|
||||
>
|
||||
{getToAccountTypeLabel(a.toAccountType)}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
className={`px-2 py-1 border text-center ${
|
||||
shouldHideColumns ? 'hidden' : ''
|
||||
}`}
|
||||
>
|
||||
{a && a.status && (
|
||||
<TransferStatusIcon status={a.status} />
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
className={`px-2 py-1 border ${
|
||||
shouldHideColumns ? 'hidden' : ''
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className="underline decoration-dotted"
|
||||
title={a?.kind.__typename}
|
||||
data-testid="transfer-kind"
|
||||
>
|
||||
{a && typeLabel(a.kind.__typename)}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from './network-treasury';
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useDocumentTitle } from '../../hooks/use-document-title';
|
||||
import type { AccountType } from '@vegaprotocol/types';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { RouteTitle } from '../../components/route-title';
|
||||
import { NetworkAccountsTable } from './components/network-accounts-table';
|
||||
import { NetworkTransfersTable } from './components/network-transfers-table';
|
||||
|
||||
export type NonZeroAccount = {
|
||||
assetId: string;
|
||||
balance: string;
|
||||
type: AccountType;
|
||||
};
|
||||
|
||||
export const NetworkTreasury = () => {
|
||||
useDocumentTitle(['Network Treasury']);
|
||||
return (
|
||||
<section>
|
||||
<RouteTitle data-testid="block-header">{t(`Treasury`)}</RouteTitle>
|
||||
<div>
|
||||
<NetworkAccountsTable />
|
||||
</div>
|
||||
<div className="mt-5">
|
||||
<h2 className="text-3xl mb-2">{t('Transfers')}</h2>
|
||||
<NetworkTransfersTable />
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
@@ -7,7 +7,7 @@ context('Home Page - verify elements on page', { tags: '@smoke' }, function () {
|
||||
});
|
||||
|
||||
describe('Links and buttons', function () {
|
||||
it.skip('should have link for proposal page', function () {
|
||||
it('should have link for proposal page', function () {
|
||||
cy.getByTestId('home-proposals').within(() => {
|
||||
cy.get('[href="/proposals"]')
|
||||
.should('exist')
|
||||
@@ -51,7 +51,7 @@ context('Home Page - verify elements on page', { tags: '@smoke' }, function () {
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should have external link for governance', function () {
|
||||
it('should have external link for governance', function () {
|
||||
cy.getByTestId('home-proposals').within(() => {
|
||||
cy.getByTestId('external-link')
|
||||
.should('have.attr', 'href')
|
||||
@@ -59,7 +59,7 @@ context('Home Page - verify elements on page', { tags: '@smoke' }, function () {
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should have link for validator page', function () {
|
||||
it('should have link for validator page', function () {
|
||||
cy.getByTestId('home-validators').within(() => {
|
||||
cy.get('[href="/validators"]')
|
||||
.first()
|
||||
@@ -68,7 +68,7 @@ context('Home Page - verify elements on page', { tags: '@smoke' }, function () {
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should have external link for validators', function () {
|
||||
it('should have external link for validators', function () {
|
||||
cy.getByTestId('home-validators').within(() => {
|
||||
cy.getByTestId('external-link')
|
||||
.should('have.attr', 'href')
|
||||
@@ -79,29 +79,29 @@ context('Home Page - verify elements on page', { tags: '@smoke' }, function () {
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should have information on active nodes', function () {
|
||||
it('should have information on active nodes', function () {
|
||||
cy.getByTestId('node-information')
|
||||
.first()
|
||||
.should('contain.text', '2')
|
||||
.should('contain.text', '1')
|
||||
.and('contain.text', 'active nodes');
|
||||
});
|
||||
|
||||
it.skip('should have information on consensus nodes', function () {
|
||||
it('should have information on consensus nodes', function () {
|
||||
cy.getByTestId('node-information')
|
||||
.last()
|
||||
.should('contain.text', '2')
|
||||
.should('contain.text', '1')
|
||||
.and('contain.text', 'consensus nodes');
|
||||
});
|
||||
|
||||
it.skip('should contain link to specific validators', function () {
|
||||
it('should contain link to specific validators', function () {
|
||||
cy.getByTestId('validators')
|
||||
.should('have.length', '2')
|
||||
.should('have.length', '1')
|
||||
.each(($validator) => {
|
||||
cy.wrap($validator).find('a').should('have.attr', 'href');
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should have link for rewards page', function () {
|
||||
it('should have link for rewards page', function () {
|
||||
cy.getByTestId('home-rewards').within(() => {
|
||||
cy.get('[href="/rewards"]')
|
||||
.first()
|
||||
@@ -110,7 +110,7 @@ context('Home Page - verify elements on page', { tags: '@smoke' }, function () {
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should have link for withdrawal page', function () {
|
||||
it('should have link for withdrawal page', function () {
|
||||
cy.getByTestId('home-vega-token').within(() => {
|
||||
cy.get('[href="/token/withdraw"]')
|
||||
.first()
|
||||
@@ -132,7 +132,7 @@ context('Home Page - verify elements on page', { tags: '@smoke' }, function () {
|
||||
});
|
||||
|
||||
// 0006-NETW-003 0006-NETW-008 0006-NETW-009 0006-NETW-010 0006-NETW-012 0006-NETW-013 0006-NETW-017 0006-NETW-018 0006-NETW-019 0006-NETW-020
|
||||
it.skip('should have option to switch to different network node', function () {
|
||||
it('should have option to switch to different network node', function () {
|
||||
cy.getByTestId('git-network-data').within(() => {
|
||||
cy.getByTestId('link').click();
|
||||
});
|
||||
@@ -159,7 +159,7 @@ context('Home Page - verify elements on page', { tags: '@smoke' }, function () {
|
||||
cy.getByTestId('node-url-custom').click({ force: true });
|
||||
cy.get('input').should('exist');
|
||||
cy.getByTestId('connect').should('be.disabled');
|
||||
cy.getByTestId('icon-cross').click();
|
||||
cy.getByTestId('dialog-close').click();
|
||||
});
|
||||
|
||||
it('should display eth data', function () {
|
||||
|
||||
@@ -33,12 +33,12 @@ context(
|
||||
verifyTabHighlighted(navigation.proposals);
|
||||
});
|
||||
|
||||
it.skip('should have GOVERNANCE header visible', function () {
|
||||
it('should have GOVERNANCE header visible', function () {
|
||||
verifyPageHeader('Proposals');
|
||||
});
|
||||
|
||||
// 3002-PROP-023 3004-PMAC-002 3005-PASN-002 3006-PASC-002 3007-PNEC-002 3008-PFRO-003
|
||||
it.skip('new proposal page should have button for link to more information on proposals', function () {
|
||||
it('new proposal page should have button for link to more information on proposals', function () {
|
||||
cy.getByTestId('new-proposal-link').click();
|
||||
cy.url().should('include', '/proposals/propose/raw');
|
||||
cy.contains('To see Explorer data on proposals visit').within(() => {
|
||||
@@ -73,7 +73,7 @@ context(
|
||||
navigateTo(navigation.proposals);
|
||||
});
|
||||
|
||||
it.skip('should be able to see a working link for - find out more about Vega governance', function () {
|
||||
it('should be able to see a working link for - find out more about Vega governance', function () {
|
||||
// 3001-VOTE-001 // 3002-PROP-001
|
||||
cy.getByTestId(proposalDocumentationLink)
|
||||
.should('be.visible')
|
||||
|
||||
@@ -40,10 +40,10 @@ context('View functionality with public key', { tags: '@smoke' }, function () {
|
||||
verifyConnectedToPubKey();
|
||||
});
|
||||
|
||||
it('Able to connect public key via wallet and view assets in wallet', function () {
|
||||
it.skip('Able to connect public key via wallet and view assets in wallet', function () {
|
||||
verifyConnectedToPubKey();
|
||||
cy.getByTestId('currency-title', { timeout: 10000 })
|
||||
.should('have.length.at.least', 4)
|
||||
.should('have.length.at.least', 2)
|
||||
.and('contain.text', 'USDC (fake)');
|
||||
});
|
||||
|
||||
|
||||
@@ -46,11 +46,11 @@ context('Validators Page - verify elements on page', function () {
|
||||
|
||||
// @ts-ignore clash between jest and cypress
|
||||
describe('with wallets disconnected', { tags: '@smoke' }, function () {
|
||||
it.skip('Should have validators tab highlighted', function () {
|
||||
it('Should have validators tab highlighted', function () {
|
||||
verifyTabHighlighted(navigation.validators);
|
||||
});
|
||||
|
||||
it.skip('Should have validators ON VEGA header visible', function () {
|
||||
it('Should have validators ON VEGA header visible', function () {
|
||||
verifyPageHeader('Validators');
|
||||
});
|
||||
|
||||
@@ -192,7 +192,7 @@ context('Validators Page - verify elements on page', function () {
|
||||
});
|
||||
|
||||
// 1002-STKE-006
|
||||
it.skip('Should be able to see validator name', function () {
|
||||
it('Should be able to see validator name', function () {
|
||||
cy.getByTestId(validatorTitle).should('not.be.empty');
|
||||
});
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ LC_ALL="en_US.UTF-8"
|
||||
# Cosmic elevator flags
|
||||
NX_SUCCESSOR_MARKETS=true
|
||||
NX_METAMASK_SNAPS=true
|
||||
NX_PRODUCT_PERPETUALS=false
|
||||
NX_UPDATE_MARKET_STATE=false
|
||||
NX_PRODUCT_PERPETUALS=true
|
||||
NX_UPDATE_MARKET_STATE=true
|
||||
NX_REFERRALS=true
|
||||
NX_GOVERNANCE_TRANSFERS=false
|
||||
NX_GOVERNANCE_TRANSFERS=true
|
||||
|
||||
@@ -62,6 +62,9 @@ const cache: InMemoryCacheConfig = {
|
||||
Account: {
|
||||
keyFields: false,
|
||||
},
|
||||
Instrument: {
|
||||
keyFields: ['code'],
|
||||
},
|
||||
Delegation: {
|
||||
keyFields: false,
|
||||
// Only get full updates
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import classNames from 'classnames';
|
||||
import { type ReactNode } from 'react';
|
||||
|
||||
interface HeadingProps {
|
||||
title?: string;
|
||||
title?: ReactNode;
|
||||
centerContent?: boolean;
|
||||
marginTop?: boolean;
|
||||
marginBottom?: boolean;
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ describe('Proposal header', () => {
|
||||
screen.queryByTestId('proposal-description')
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('proposal-details')).toHaveTextContent(
|
||||
'Update to market ID: MarketId'
|
||||
'Update to market: MarketId'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
+57
-28
@@ -36,6 +36,8 @@ import { type Proposal, type BatchProposal } from '../../types';
|
||||
import { type ProposalTermsFieldsFragment } from '../../__generated__/Proposals';
|
||||
import { differenceInHours, format, formatDistanceToNowStrict } from 'date-fns';
|
||||
import { DATE_FORMAT_DETAILED } from '../../../../lib/date-formats';
|
||||
import { getIndicatorStyle } from '../proposal/colours';
|
||||
import { MarketName } from '../proposal/market-name';
|
||||
|
||||
const ProposalTypeTags = ({
|
||||
proposal,
|
||||
@@ -52,11 +54,8 @@ const ProposalTypeTags = ({
|
||||
|
||||
if (proposal.__typename === 'BatchProposal') {
|
||||
return (
|
||||
<div data-testid="proposal-type" className="flex gap-1">
|
||||
{proposal.subProposals?.map((subProposal, i) => {
|
||||
if (!subProposal?.terms) return null;
|
||||
return <ProposalTypeTag key={i} terms={subProposal.terms} />;
|
||||
})}
|
||||
<div data-testid="proposal-type">
|
||||
<ProposalInfoLabel variant="secondary">BatchProposal</ProposalInfoLabel>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -138,50 +137,77 @@ const ProposalDetails = ({
|
||||
);
|
||||
}
|
||||
case 'UpdateMarketState': {
|
||||
const marketPageLink = consoleLink(
|
||||
CONSOLE_MARKET_PAGE.replace(':marketId', terms.change.market.id)
|
||||
);
|
||||
return (
|
||||
<span>
|
||||
{featureFlags.UPDATE_MARKET_STATE &&
|
||||
terms.change?.market?.id &&
|
||||
terms.change.updateType ? (
|
||||
<>
|
||||
{t(terms.change.updateType)}:{' '}
|
||||
{truncateMiddle(terms.change.market.id)}
|
||||
<span>{t(terms.change.updateType)}: </span>
|
||||
<span className="inline-flex gap-2">
|
||||
<span className="break-all">
|
||||
<MarketName marketId={terms.change.market.id} />
|
||||
</span>
|
||||
<span className="inline-flex items-end gap-0">
|
||||
<CopyWithTooltip
|
||||
text={terms.change.market.id}
|
||||
description={t('copyId')}
|
||||
>
|
||||
<button className="inline-block px-1">
|
||||
<VegaIcon size={20} name={VegaIconNames.COPY} />
|
||||
</button>
|
||||
</CopyWithTooltip>
|
||||
<Tooltip description={t('OpenInConsole')} align="center">
|
||||
<Link
|
||||
className="inline-block px-1"
|
||||
to={marketPageLink}
|
||||
target="_blank"
|
||||
>
|
||||
<VegaIcon
|
||||
size={20}
|
||||
name={VegaIconNames.OPEN_EXTERNAL}
|
||||
/>
|
||||
</Link>
|
||||
</Tooltip>
|
||||
</span>
|
||||
</span>
|
||||
</>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
case 'UpdateMarket': {
|
||||
const marketPageLink = consoleLink(
|
||||
CONSOLE_MARKET_PAGE.replace(':marketId', terms.change.marketId)
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<span>{t('UpdateToMarket')}:</span>{' '}
|
||||
<span>{t('UpdateToMarket')}: </span>
|
||||
<span className="inline-flex items-start gap-2">
|
||||
<span className="break-all">{terms.change.marketId} </span>
|
||||
<span className="break-all">
|
||||
<MarketName marketId={terms.change.marketId} />
|
||||
</span>
|
||||
<span className="inline-flex items-end gap-0">
|
||||
<CopyWithTooltip
|
||||
text={terms.change.marketId}
|
||||
description={t('copyToClipboard')}
|
||||
description={t('copyId')}
|
||||
>
|
||||
<button className="inline-block px-1">
|
||||
<VegaIcon size={20} name={VegaIconNames.COPY} />
|
||||
</button>
|
||||
</CopyWithTooltip>
|
||||
<Tooltip description={t('OpenInConsole')} align="center">
|
||||
<button
|
||||
<Link
|
||||
className="inline-block px-1"
|
||||
onClick={() => {
|
||||
const marketPageLink = consoleLink(
|
||||
CONSOLE_MARKET_PAGE.replace(
|
||||
':marketId',
|
||||
// @ts-ignore ts doesn't like this field even though its already a string above???
|
||||
terms.change.marketId
|
||||
)
|
||||
);
|
||||
window.open(marketPageLink, '_blank');
|
||||
}}
|
||||
target="_blank"
|
||||
to={marketPageLink}
|
||||
>
|
||||
<VegaIcon size={20} name={VegaIconNames.OPEN_EXTERNAL} />
|
||||
</button>
|
||||
</Link>
|
||||
</Tooltip>
|
||||
</span>
|
||||
</span>
|
||||
@@ -286,12 +312,15 @@ const ProposalDetails = ({
|
||||
{proposal.subProposals.map((p, i) => {
|
||||
if (!p?.terms) return null;
|
||||
return (
|
||||
<li key={i}>
|
||||
<div>{renderDetails(p.terms)}</div>
|
||||
<SubProposalStateText
|
||||
state={proposal.state}
|
||||
enactmentDatetime={p.terms.enactmentDatetime}
|
||||
/>
|
||||
<li key={i} className="flex gap-3 items-center">
|
||||
<span className={getIndicatorStyle(i + 1)}>{i + 1}</span>
|
||||
<span>
|
||||
<div>{renderDetails(p.terms)}</div>
|
||||
<SubProposalStateText
|
||||
state={proposal.state}
|
||||
enactmentDatetime={p.terms.enactmentDatetime}
|
||||
/>
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -3,16 +3,8 @@ import { useTranslation } from 'react-i18next';
|
||||
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||
import { SubHeading } from '../../../../components/heading';
|
||||
import { CollapsibleToggle } from '../../../../components/collapsible-toggle';
|
||||
import {
|
||||
type BatchProposalFieldsFragment,
|
||||
type ProposalFieldsFragment,
|
||||
} from '../../__generated__/Proposals';
|
||||
|
||||
export const ProposalJson = ({
|
||||
proposal,
|
||||
}: {
|
||||
proposal: ProposalFieldsFragment | BatchProposalFieldsFragment;
|
||||
}) => {
|
||||
export const ProposalJson = ({ proposal }: { proposal?: unknown }) => {
|
||||
const { t } = useTranslation();
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
|
||||
|
||||
+8
-3
@@ -5,6 +5,11 @@ import {
|
||||
} from './proposal-market-changes';
|
||||
import type { JsonValue } from '../../../../components/json-diff';
|
||||
|
||||
jest.mock('../proposal/market-name.tsx', () => ({
|
||||
...jest.requireActual('../proposal/market-name.tsx'),
|
||||
MarketName: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('applyImmutableKeysFromEarlierVersion', () => {
|
||||
it('returns an empty object if any argument is not an object or null', () => {
|
||||
const earlierVersion: JsonValue = null;
|
||||
@@ -57,21 +62,21 @@ describe('applyImmutableKeysFromEarlierVersion', () => {
|
||||
describe('ProposalMarketChanges', () => {
|
||||
it('renders correctly', () => {
|
||||
const { getByTestId } = render(
|
||||
<ProposalMarketChanges marketId="market-id" updatedProposal={{}} />
|
||||
<ProposalMarketChanges marketId="market-id" updateProposalNode={null} />
|
||||
);
|
||||
expect(getByTestId('proposal-market-changes')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('JsonDiff is not visible when showChanges is false', () => {
|
||||
const { queryByTestId } = render(
|
||||
<ProposalMarketChanges marketId="market-id" updatedProposal={{}} />
|
||||
<ProposalMarketChanges marketId="market-id" updateProposalNode={null} />
|
||||
);
|
||||
expect(queryByTestId('json-diff')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('JsonDiff is visible when showChanges is true', async () => {
|
||||
const { getByTestId } = render(
|
||||
<ProposalMarketChanges marketId="market-id" updatedProposal={{}} />
|
||||
<ProposalMarketChanges marketId="market-id" updateProposalNode={null} />
|
||||
);
|
||||
fireEvent.click(getByTestId('proposal-market-changes-toggle'));
|
||||
expect(getByTestId('json-diff')).toBeInTheDocument();
|
||||
|
||||
+91
-52
@@ -1,14 +1,24 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import set from 'lodash/set';
|
||||
import get from 'lodash/get';
|
||||
import { JsonDiff } from '../../../../components/json-diff';
|
||||
import compact from 'lodash/compact';
|
||||
import orderBy from 'lodash/orderBy';
|
||||
import { JsonDiff, type JsonValue } from '../../../../components/json-diff';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useState } from 'react';
|
||||
import { CollapsibleToggle } from '../../../../components/collapsible-toggle';
|
||||
import { SubHeading } from '../../../../components/heading';
|
||||
import type { JsonValue } from '../../../../components/json-diff';
|
||||
import { useFetch } from '@vegaprotocol/react-helpers';
|
||||
import { ENV } from '../../../../config';
|
||||
import {
|
||||
useFetchProposal,
|
||||
useFetchProposals,
|
||||
flatten,
|
||||
isBatchProposalNode,
|
||||
isSingleProposalNode,
|
||||
type ProposalNode,
|
||||
type SingleProposalData,
|
||||
type SubProposalData,
|
||||
} from '../proposal/proposal-utils';
|
||||
import { MarketName } from '../proposal/market-name';
|
||||
|
||||
const immutableKeys = [
|
||||
'decimalPlaces',
|
||||
@@ -18,8 +28,8 @@ const immutableKeys = [
|
||||
];
|
||||
|
||||
export const applyImmutableKeysFromEarlierVersion = (
|
||||
earlierVersion: JsonValue,
|
||||
updatedVersion: JsonValue
|
||||
earlierVersion: unknown,
|
||||
updatedVersion: unknown
|
||||
) => {
|
||||
if (
|
||||
typeof earlierVersion !== 'object' ||
|
||||
@@ -35,7 +45,8 @@ export const applyImmutableKeysFromEarlierVersion = (
|
||||
|
||||
// Overwrite the immutable keys in the updatedVersionCopy with the earlier values
|
||||
immutableKeys.forEach((key) => {
|
||||
set(updatedVersionCopy, key, get(earlierVersion, key));
|
||||
const earlier = get(earlierVersion, key);
|
||||
if (earlier) set(updatedVersionCopy, key, earlier);
|
||||
});
|
||||
|
||||
return updatedVersionCopy;
|
||||
@@ -43,49 +54,84 @@ export const applyImmutableKeysFromEarlierVersion = (
|
||||
|
||||
interface ProposalMarketChangesProps {
|
||||
marketId: string;
|
||||
updatedProposal: JsonValue;
|
||||
/** This are the changes from proposal */
|
||||
updateProposalNode: ProposalNode | null;
|
||||
indicator?: number;
|
||||
}
|
||||
|
||||
export const ProposalMarketChanges = ({
|
||||
marketId,
|
||||
updatedProposal,
|
||||
updateProposalNode,
|
||||
indicator,
|
||||
}: ProposalMarketChangesProps) => {
|
||||
const { t } = useTranslation();
|
||||
const [showChanges, setShowChanges] = useState(false);
|
||||
|
||||
const {
|
||||
state: { data },
|
||||
} = useFetch(`${ENV.rest}governance?proposalId=${marketId}`, undefined, true);
|
||||
const { data: originalProposalData } = useFetchProposal({
|
||||
proposalId: marketId,
|
||||
});
|
||||
|
||||
const {
|
||||
state: { data: enactedProposalData },
|
||||
} = useFetch(
|
||||
`${ENV.rest}governances?proposalState=STATE_ENACTED&proposalType=TYPE_UPDATE_MARKET`,
|
||||
undefined,
|
||||
true
|
||||
const { data: enactedProposalsData } = useFetchProposals({
|
||||
proposalState: 'STATE_ENACTED',
|
||||
proposalType: 'TYPE_UPDATE_MARKET',
|
||||
});
|
||||
|
||||
let updateProposal: SingleProposalData | SubProposalData | undefined;
|
||||
if (isBatchProposalNode(updateProposalNode)) {
|
||||
updateProposal = updateProposalNode.proposals.find(
|
||||
(p, i) =>
|
||||
p.terms.updateMarket?.marketId === marketId &&
|
||||
(indicator != null ? i === indicator - 1 : true)
|
||||
);
|
||||
}
|
||||
if (isSingleProposalNode(updateProposalNode)) {
|
||||
updateProposal = updateProposalNode.proposal;
|
||||
}
|
||||
|
||||
// this should get the proposal before the current one
|
||||
const enactedUpdateMarketProposals = orderBy(
|
||||
compact(
|
||||
flatten(enactedProposalsData).filter((enacted) => {
|
||||
const related = enacted.terms.updateMarket?.marketId === marketId;
|
||||
const notCurrent =
|
||||
enacted.id !== updateProposal?.id ||
|
||||
('batchId' in enacted && enacted.batchId !== updateProposal.id);
|
||||
const beforeCurrent =
|
||||
Number(enacted.terms.enactmentTimestamp) <
|
||||
Number(updateProposal?.terms.enactmentTimestamp);
|
||||
return related && notCurrent && beforeCurrent;
|
||||
})
|
||||
),
|
||||
[(proposal) => Number(proposal.terms.enactmentTimestamp)],
|
||||
'desc'
|
||||
);
|
||||
|
||||
// @ts-ignore no types here :-/
|
||||
const enacted = enactedProposalData?.connection?.edges
|
||||
.filter(
|
||||
// @ts-ignore no type here
|
||||
({ node }) => node?.proposal?.terms?.updateMarket?.marketId === marketId
|
||||
)
|
||||
// @ts-ignore no type here
|
||||
.sort((a, b) => {
|
||||
return (
|
||||
new Date(a?.node?.terms?.enactmentTimestamp).getTime() -
|
||||
new Date(b?.node?.terms?.enactmentTimestamp).getTime()
|
||||
);
|
||||
});
|
||||
const latestEnactedProposal =
|
||||
enactedUpdateMarketProposals.length > 0
|
||||
? enactedUpdateMarketProposals[0]
|
||||
: undefined;
|
||||
|
||||
const latestEnactedProposal = enacted?.length
|
||||
? enacted[enacted.length - 1]
|
||||
: undefined;
|
||||
let originalProposal;
|
||||
if (isBatchProposalNode(originalProposalData)) {
|
||||
originalProposal = originalProposalData.proposals.find(
|
||||
(proposal) => proposal.id === marketId && proposal.terms.newMarket != null
|
||||
);
|
||||
}
|
||||
if (isSingleProposalNode(originalProposalData)) {
|
||||
originalProposal = originalProposalData.proposal;
|
||||
}
|
||||
|
||||
const originalProposal =
|
||||
// @ts-ignore no types with useFetch TODO: check this is good
|
||||
data?.data?.proposal?.terms?.newMarket?.changes;
|
||||
// LEFT SIDE: update market proposal enacted just before this one
|
||||
// or original new market proposal
|
||||
const left =
|
||||
latestEnactedProposal?.terms.updateMarket?.changes ||
|
||||
originalProposal?.terms.newMarket?.changes;
|
||||
|
||||
// RIGHT SIDE: this update market proposal
|
||||
const right = applyImmutableKeysFromEarlierVersion(
|
||||
left,
|
||||
updateProposal?.terms.updateMarket?.changes
|
||||
);
|
||||
|
||||
return (
|
||||
<section data-testid="proposal-market-changes">
|
||||
@@ -94,25 +140,18 @@ export const ProposalMarketChanges = ({
|
||||
setToggleState={setShowChanges}
|
||||
dataTestId={'proposal-market-changes-toggle'}
|
||||
>
|
||||
<SubHeading title={t('updatesToMarket')} />
|
||||
<SubHeading
|
||||
title={
|
||||
<>
|
||||
{t('UpdateToMarket')}: <MarketName marketId={marketId} />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</CollapsibleToggle>
|
||||
|
||||
{showChanges && (
|
||||
<div className="mb-6">
|
||||
<JsonDiff
|
||||
left={latestEnactedProposal || originalProposal}
|
||||
right={
|
||||
latestEnactedProposal
|
||||
? applyImmutableKeysFromEarlierVersion(
|
||||
latestEnactedProposal,
|
||||
updatedProposal
|
||||
)
|
||||
: applyImmutableKeysFromEarlierVersion(
|
||||
originalProposal,
|
||||
updatedProposal
|
||||
)
|
||||
}
|
||||
/>
|
||||
<JsonDiff left={left as JsonValue} right={right as JsonValue} />
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
+5
@@ -2,6 +2,11 @@ import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { ProposalUpdateMarketState } from './proposal-update-market-state';
|
||||
import { MarketUpdateType } from '@vegaprotocol/types';
|
||||
|
||||
jest.mock('../proposal/market-name.tsx', () => ({
|
||||
...jest.requireActual('../proposal/market-name.tsx'),
|
||||
MarketName: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('<ProposalUpdateMarketState />', () => {
|
||||
const suspendProposal = {
|
||||
__typename: 'UpdateMarketState' as const,
|
||||
|
||||
+23
-7
@@ -9,6 +9,8 @@ import { useState } from 'react';
|
||||
import { CollapsibleToggle } from '../../../../components/collapsible-toggle';
|
||||
import { SubHeading } from '../../../../components/heading';
|
||||
import { type UpdateMarketStatesFragment } from '../../__generated__/Proposals';
|
||||
import { MarketUpdateTypeMapping } from '@vegaprotocol/types';
|
||||
import { MarketName } from '../proposal/market-name';
|
||||
|
||||
interface ProposalUpdateMarketStateProps {
|
||||
change: UpdateMarketStatesFragment | null;
|
||||
@@ -19,16 +21,18 @@ export const ProposalUpdateMarketState = ({
|
||||
}: ProposalUpdateMarketStateProps) => {
|
||||
const { t } = useTranslation();
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
let market;
|
||||
let isTerminate = false;
|
||||
|
||||
if (!change) {
|
||||
if (!change || change.__typename !== 'UpdateMarketState') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (change.__typename === 'UpdateMarketState') {
|
||||
market = change?.market;
|
||||
isTerminate = change?.updateType === 'MARKET_STATE_UPDATE_TYPE_TERMINATE';
|
||||
const market = change?.market;
|
||||
const isTerminate =
|
||||
change?.updateType === 'MARKET_STATE_UPDATE_TYPE_TERMINATE';
|
||||
|
||||
let toggleTitle = t(change.updateType);
|
||||
if (toggleTitle.length === 0) {
|
||||
toggleTitle = t('MarketDetails');
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -38,7 +42,13 @@ export const ProposalUpdateMarketState = ({
|
||||
setToggleState={setShowDetails}
|
||||
dataTestId="proposal-market-data-toggle"
|
||||
>
|
||||
<SubHeading title={t('MarketDetails')} />
|
||||
<SubHeading
|
||||
title={
|
||||
<>
|
||||
{toggleTitle}: <MarketName marketId={market?.id} />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</CollapsibleToggle>
|
||||
|
||||
{showDetails && (
|
||||
@@ -49,6 +59,12 @@ export const ProposalUpdateMarketState = ({
|
||||
{t('marketId')}
|
||||
{market?.id}
|
||||
</KeyValueTableRow>
|
||||
<KeyValueTableRow>
|
||||
{t('State')}
|
||||
<span className="bg-vega-green-650 px-1">
|
||||
{MarketUpdateTypeMapping[change.updateType]}
|
||||
</span>
|
||||
</KeyValueTableRow>
|
||||
<KeyValueTableRow>
|
||||
{t('marketName')}
|
||||
{market?.tradableInstrument?.instrument?.name}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import classNames from 'classnames';
|
||||
|
||||
// rainbow-ish order
|
||||
const COLOURS = ['red', 'pink', 'orange', 'yellow', 'green', 'blue', 'purple'];
|
||||
|
||||
const getColour = (indicator: number, max = COLOURS.length) => {
|
||||
const available =
|
||||
max < COLOURS.length ? COLOURS.slice(COLOURS.length - max) : COLOURS;
|
||||
const tiers = Object.keys(available).length;
|
||||
let index = Math.abs(indicator - 1);
|
||||
if (indicator >= tiers) {
|
||||
index = index % tiers;
|
||||
}
|
||||
return available[index];
|
||||
};
|
||||
|
||||
export const getStyle = (indicator: number, max = COLOURS.length) =>
|
||||
classNames({
|
||||
'bg-vega-yellow-400 after:bg-vega-yellow-400':
|
||||
'yellow' === getColour(indicator, max),
|
||||
'bg-vega-green-400 after:bg-vega-green-400':
|
||||
'green' === getColour(indicator, max),
|
||||
'bg-vega-blue-400 after:bg-vega-blue-400':
|
||||
'blue' === getColour(indicator, max),
|
||||
'bg-vega-purple-400 after:bg-vega-purple-400':
|
||||
'purple' === getColour(indicator, max),
|
||||
'bg-vega-pink-400 after:bg-vega-pink-400':
|
||||
'pink' === getColour(indicator, max),
|
||||
'bg-vega-orange-400 after:bg-vega-orange-400':
|
||||
'orange' === getColour(indicator, max),
|
||||
'bg-vega-red-400 after:bg-vega-red-400':
|
||||
'red' === getColour(indicator, max),
|
||||
'bg-vega-clight-600 after:bg-vega-clight-600':
|
||||
'none' === getColour(indicator, max),
|
||||
});
|
||||
|
||||
export const getIndicatorStyle = (indicator: number) =>
|
||||
classNames(
|
||||
'rounded-sm text-black inline-block px-1 py-1 font-alpha calt h-8 w-7 text-center',
|
||||
'text-border-1',
|
||||
getStyle(indicator),
|
||||
// Comment below if you want to remove the "chevron"
|
||||
'relative mr-[11px]',
|
||||
'after:absolute after:z-[-1] after:top-1 after:right-[-11px] after:rounded-sm',
|
||||
"after:w-[22.62px] after:h-[22.62px] after:rotate-45 after:content-['']"
|
||||
);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useMarketInfoQuery } from '@vegaprotocol/markets';
|
||||
|
||||
export const MarketName = ({ marketId }: { marketId?: string }) => {
|
||||
const { data } = useMarketInfoQuery({
|
||||
variables: {
|
||||
marketId: marketId || '',
|
||||
},
|
||||
skip: !marketId,
|
||||
});
|
||||
|
||||
return (
|
||||
<span>{data?.market?.tradableInstrument.instrument.code || marketId}</span>
|
||||
);
|
||||
};
|
||||
+42
-26
@@ -12,21 +12,26 @@ import {
|
||||
import { ProposalUpdateBenefitTiers } from '../proposal-update-benefit-tiers';
|
||||
import { ProposalUpdateMarketState } from '../proposal-update-market-state';
|
||||
import { ProposalVolumeDiscountProgramDetails } from '../proposal-volume-discount-program-details';
|
||||
import { getIndicatorStyle } from './colours';
|
||||
import { type ProposalNode } from './proposal-utils';
|
||||
|
||||
export const ProposalChangeDetails = ({
|
||||
proposal,
|
||||
terms,
|
||||
restData,
|
||||
indicator,
|
||||
}: {
|
||||
proposal: Proposal | BatchProposal;
|
||||
terms: ProposalTermsFieldsFragment;
|
||||
// eslint-disable-next-line
|
||||
restData: any;
|
||||
restData: ProposalNode | null;
|
||||
indicator?: number;
|
||||
}) => {
|
||||
let details = null;
|
||||
|
||||
switch (terms.change.__typename) {
|
||||
case 'NewAsset': {
|
||||
if (proposal.id && terms.change.source.__typename === 'ERC20') {
|
||||
return (
|
||||
details = (
|
||||
<div>
|
||||
<ListAsset
|
||||
assetId={proposal.id}
|
||||
@@ -37,62 +42,64 @@ export const ProposalChangeDetails = ({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
case 'UpdateAsset': {
|
||||
if (proposal.id) {
|
||||
return (
|
||||
details = (
|
||||
<ProposalAssetDetails
|
||||
change={terms.change}
|
||||
assetId={terms.change.assetId}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
case 'NewMarket': {
|
||||
if (proposal.id) {
|
||||
return <ProposalMarketData proposalId={proposal.id} />;
|
||||
details = <ProposalMarketData proposalId={proposal.id} />;
|
||||
}
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
case 'UpdateMarket': {
|
||||
if (proposal.id) {
|
||||
return (
|
||||
details = (
|
||||
<div className="flex flex-col gap-4">
|
||||
<ProposalMarketData proposalId={proposal.id} />
|
||||
<ProposalMarketChanges
|
||||
indicator={indicator}
|
||||
marketId={terms.change.marketId}
|
||||
updatedProposal={
|
||||
restData?.data?.proposal?.terms?.updateMarket?.changes
|
||||
}
|
||||
updateProposalNode={restData}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
case 'NewTransfer': {
|
||||
if (proposal.id) {
|
||||
return <ProposalTransferDetails proposalId={proposal.id} />;
|
||||
details = <ProposalTransferDetails proposalId={proposal.id} />;
|
||||
}
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
case 'CancelTransfer': {
|
||||
if (proposal.id) {
|
||||
return <ProposalCancelTransferDetails proposalId={proposal.id} />;
|
||||
details = <ProposalCancelTransferDetails proposalId={proposal.id} />;
|
||||
}
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
case 'UpdateMarketState': {
|
||||
return <ProposalUpdateMarketState change={terms.change} />;
|
||||
details = <ProposalUpdateMarketState change={terms.change} />;
|
||||
break;
|
||||
}
|
||||
case 'UpdateReferralProgram': {
|
||||
return <ProposalReferralProgramDetails change={terms.change} />;
|
||||
details = <ProposalReferralProgramDetails change={terms.change} />;
|
||||
break;
|
||||
}
|
||||
case 'UpdateVolumeDiscountProgram': {
|
||||
return <ProposalVolumeDiscountProgramDetails change={terms.change} />;
|
||||
details = <ProposalVolumeDiscountProgramDetails change={terms.change} />;
|
||||
break;
|
||||
}
|
||||
case 'UpdateNetworkParameter': {
|
||||
if (
|
||||
@@ -100,18 +107,27 @@ export const ProposalChangeDetails = ({
|
||||
terms.change.networkParameter.key ===
|
||||
'rewards.activityStreak.benefitTiers'
|
||||
) {
|
||||
return <ProposalUpdateBenefitTiers change={terms.change} />;
|
||||
details = <ProposalUpdateBenefitTiers change={terms.change} />;
|
||||
}
|
||||
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
case 'NewFreeform':
|
||||
case 'NewSpotMarket':
|
||||
case 'UpdateSpotMarket': {
|
||||
return null;
|
||||
}
|
||||
case 'UpdateSpotMarket':
|
||||
default: {
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (indicator != null) {
|
||||
details = (
|
||||
<div className="flex gap-3 mb-3">
|
||||
<div className={getIndicatorStyle(indicator)}>{indicator}</div>
|
||||
<div>{details}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return details;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
import compact from 'lodash/compact';
|
||||
import { ENV } from '../../../../config';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
type Maybe<T> = T | null | undefined;
|
||||
|
||||
type ProposalState =
|
||||
| 'STATE_UNSPECIFIED'
|
||||
| 'STATE_FAILED'
|
||||
| 'STATE_OPEN'
|
||||
| 'STATE_PASSED'
|
||||
| 'STATE_REJECTED'
|
||||
| 'STATE_DECLINED'
|
||||
| 'STATE_ENACTED'
|
||||
| 'STATE_WAITING_FOR_NODE_VOTE';
|
||||
|
||||
type ProposalType =
|
||||
| 'TYPE_UNSPECIFIED'
|
||||
| 'TYPE_ALL'
|
||||
| 'TYPE_NEW_MARKET'
|
||||
| 'TYPE_UPDATE_MARKET'
|
||||
| 'TYPE_NETWORK_PARAMETERS'
|
||||
| 'TYPE_NEW_ASSET'
|
||||
| 'TYPE_NEW_FREE_FORM'
|
||||
| 'TYPE_UPDATE_ASSET'
|
||||
| 'TYPE_NEW_SPOT_MARKET'
|
||||
| 'TYPE_UPDATE_SPOT_MARKET'
|
||||
| 'TYPE_NEW_TRANSFER'
|
||||
| 'TYPE_CANCEL_TRANSFER'
|
||||
| 'TYPE_UPDATE_MARKET_STATE'
|
||||
| 'TYPE_UPDATE_REFERRAL_PROGRAM'
|
||||
| 'TYPE_UPDATE_VOLUME_DISCOUNT_PROGRAM';
|
||||
|
||||
type ProposalNodeType = 'TYPE_SINGLE_OR_UNSPECIFIED' | 'TYPE_BATCH';
|
||||
|
||||
type ProposalData = {
|
||||
id: string;
|
||||
rationale: {
|
||||
description: string;
|
||||
title: string;
|
||||
};
|
||||
state: ProposalState;
|
||||
timestamp: string;
|
||||
};
|
||||
|
||||
type Terms = {
|
||||
cancelTransfer?: { changes: unknown };
|
||||
enactmentTimestamp: string;
|
||||
newAsset?: { changes: unknown };
|
||||
newFreeform: object;
|
||||
newMarket?: { changes: unknown };
|
||||
newSpotMarket?: { changes: unknown };
|
||||
newTransfer?: { changes: unknown };
|
||||
updateAsset?: { assetId: string; changes: unknown };
|
||||
updateMarket?: { marketId: string; changes: unknown };
|
||||
updateMarketState?: {
|
||||
changes: {
|
||||
marketId: string;
|
||||
price: string;
|
||||
updateType:
|
||||
| 'MARKET_STATE_UPDATE_TYPE_UNSPECIFIED'
|
||||
| 'MARKET_STATE_UPDATE_TYPE_TERMINATE'
|
||||
| 'MARKET_STATE_UPDATE_TYPE_SUSPEND'
|
||||
| 'MARKET_STATE_UPDATE_TYPE_RESUME';
|
||||
};
|
||||
};
|
||||
updateNetworkParameter?: { changes: unknown };
|
||||
updateReferralProgram?: { changes: unknown };
|
||||
updateSpotMarket?: { marketId: string; changes: unknown };
|
||||
updateVolumeDiscountProgram?: { changes: unknown };
|
||||
};
|
||||
|
||||
export type SingleProposalData = ProposalData & {
|
||||
terms: Terms & {
|
||||
closingTimestamp: string;
|
||||
validationTimestamp: string;
|
||||
};
|
||||
};
|
||||
|
||||
type BatchProposalData = ProposalData & {
|
||||
batchTerms: {
|
||||
changes: Terms[];
|
||||
};
|
||||
};
|
||||
|
||||
export type SubProposalData = SingleProposalData & {
|
||||
batchId: string;
|
||||
};
|
||||
|
||||
export type ProposalNode = {
|
||||
proposal: ProposalData;
|
||||
proposalType: ProposalNodeType;
|
||||
proposals: SubProposalData[];
|
||||
};
|
||||
|
||||
type SingleProposalNode = ProposalNode & {
|
||||
proposal: SingleProposalData;
|
||||
proposalType: 'TYPE_SINGLE_OR_UNSPECIFIED';
|
||||
proposals: [];
|
||||
};
|
||||
|
||||
type BatchProposalNode = ProposalNode & {
|
||||
proposal: BatchProposalData;
|
||||
proposalType: 'TYPE_BATCH';
|
||||
};
|
||||
|
||||
export const isProposalNode = (node: unknown): node is ProposalNode =>
|
||||
Boolean(
|
||||
typeof node === 'object' &&
|
||||
node &&
|
||||
'proposal' in node &&
|
||||
typeof node.proposal === 'object' &&
|
||||
node?.proposal &&
|
||||
'id' in node.proposal &&
|
||||
node?.proposal?.id
|
||||
);
|
||||
|
||||
export const isSingleProposalNode = (
|
||||
node: Maybe<ProposalNode>
|
||||
): node is SingleProposalNode =>
|
||||
Boolean(
|
||||
node &&
|
||||
node?.proposalType === 'TYPE_SINGLE_OR_UNSPECIFIED' &&
|
||||
node?.proposal
|
||||
);
|
||||
|
||||
export const isBatchProposalNode = (
|
||||
node: Maybe<ProposalNode>
|
||||
): node is BatchProposalNode =>
|
||||
Boolean(
|
||||
node &&
|
||||
node?.proposalType === 'TYPE_BATCH' &&
|
||||
node?.proposal &&
|
||||
'batchTerms' in node.proposal &&
|
||||
node?.proposals?.length > 0
|
||||
);
|
||||
|
||||
// this includes also batch proposals with `updateMarket`s 👍
|
||||
const PROPOSALS_ENDPOINT = `${ENV.rest}governances?proposalState=:proposalState&proposalType=:proposalType`;
|
||||
|
||||
// this can be queried also by sub proposal id as `proposalId` and it will
|
||||
// return full batch proposal data with all of its sub proposals including
|
||||
// the requested one inside `proposals` array.
|
||||
const PROPOSAL_ENDPOINT = `${ENV.rest}governance?proposalId=:proposalId`;
|
||||
|
||||
export const getProposals = async ({
|
||||
proposalState,
|
||||
proposalType,
|
||||
}: {
|
||||
proposalState: ProposalState;
|
||||
proposalType: ProposalType;
|
||||
}) => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
PROPOSALS_ENDPOINT.replace(':proposalState', proposalState).replace(
|
||||
':proposalType',
|
||||
proposalType
|
||||
)
|
||||
);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (
|
||||
data &&
|
||||
'connection' in data &&
|
||||
data.connection &&
|
||||
'edges' in data.connection &&
|
||||
data.connection.edges?.length > 0
|
||||
) {
|
||||
const nodes = compact(
|
||||
data.connection.edges.map((e: { node?: object }) => e?.node)
|
||||
).filter(isProposalNode);
|
||||
|
||||
return nodes;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// NOOP - ignore errors
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
export const getProposal = async ({ proposalId }: { proposalId: string }) => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
PROPOSAL_ENDPOINT.replace(':proposalId', proposalId)
|
||||
);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data && 'data' in data && isProposalNode(data.data)) {
|
||||
return data.data as ProposalNode;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// NOOP - ignore errors
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const useFetchProposal = ({ proposalId }: { proposalId?: string }) => {
|
||||
const [data, setData] = useState<ProposalNode | null>(null);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
const cb = async () => {
|
||||
if (!proposalId) return;
|
||||
|
||||
setLoading(true);
|
||||
const data = await getProposal({ proposalId });
|
||||
setLoading(false);
|
||||
if (data) {
|
||||
setData(data);
|
||||
}
|
||||
};
|
||||
cb();
|
||||
}, [proposalId]);
|
||||
|
||||
return { data, loading };
|
||||
};
|
||||
|
||||
export const useFetchProposals = ({
|
||||
proposalState,
|
||||
proposalType,
|
||||
}: {
|
||||
proposalState: ProposalState;
|
||||
proposalType: ProposalType;
|
||||
}) => {
|
||||
const [data, setData] = useState<ProposalNode[]>([]);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
const cb = async () => {
|
||||
setLoading(true);
|
||||
const data = await getProposals({ proposalState, proposalType });
|
||||
setLoading(false);
|
||||
if (data) {
|
||||
setData(data);
|
||||
}
|
||||
};
|
||||
cb();
|
||||
}, [proposalState, proposalType]);
|
||||
|
||||
return { data, loading };
|
||||
};
|
||||
|
||||
export const flatten = (
|
||||
nodes: ProposalNode[]
|
||||
): (SingleProposalData | SubProposalData)[] => {
|
||||
const flattenNodes = [];
|
||||
for (const node of nodes) {
|
||||
if (isSingleProposalNode(node)) {
|
||||
flattenNodes.push(node.proposal);
|
||||
}
|
||||
if (isBatchProposalNode(node)) {
|
||||
for (const sub of node.proposals) {
|
||||
flattenNodes.push(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
return flattenNodes;
|
||||
};
|
||||
@@ -61,7 +61,7 @@ const renderComponent = (proposal: IProposal) => {
|
||||
<MemoryRouter>
|
||||
<MockedProvider>
|
||||
<VegaWalletProvider config={vegaWalletConfig}>
|
||||
<Proposal restData={{}} proposal={proposal} />
|
||||
<Proposal restData={null} proposal={proposal} />
|
||||
</VegaWalletProvider>
|
||||
</MockedProvider>
|
||||
</MemoryRouter>
|
||||
|
||||
@@ -8,15 +8,17 @@ import { ProposalJson } from '../proposal-json';
|
||||
import { UserVote } from '../vote-details';
|
||||
import Routes from '../../../routes';
|
||||
import { ProposalState } from '@vegaprotocol/types';
|
||||
import { type ProposalNode } from './proposal-utils';
|
||||
import { useVoteSubmit } from '@vegaprotocol/proposals';
|
||||
import { useUserVote } from '../vote-details/use-user-vote';
|
||||
import { type Proposal as IProposal, type BatchProposal } from '../../types';
|
||||
import { ProposalChangeDetails } from './proposal-change-details';
|
||||
import { type JsonValue } from 'type-fest';
|
||||
|
||||
export interface ProposalProps {
|
||||
proposal: IProposal | BatchProposal;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
restData: any;
|
||||
restData: ProposalNode | null;
|
||||
}
|
||||
|
||||
export const Proposal = ({ proposal, restData }: ProposalProps) => {
|
||||
@@ -70,6 +72,7 @@ export const Proposal = ({ proposal, restData }: ProposalProps) => {
|
||||
if (!p?.terms) return null;
|
||||
return (
|
||||
<ProposalChangeDetails
|
||||
indicator={i + 1}
|
||||
key={i}
|
||||
proposal={proposal}
|
||||
terms={p.terms}
|
||||
@@ -94,7 +97,7 @@ export const Proposal = ({ proposal, restData }: ProposalProps) => {
|
||||
</div>
|
||||
|
||||
<div className="mb-6">
|
||||
<ProposalJson proposal={restData?.data?.proposal} />
|
||||
<ProposalJson proposal={restData?.proposal as unknown as JsonValue} />
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
+165
-120
@@ -15,6 +15,8 @@ import {
|
||||
type VoteFieldsFragment,
|
||||
} from '../../__generated__/Proposals';
|
||||
import { useBatchVoteInformation } from '../../hooks/use-vote-information';
|
||||
import { getIndicatorStyle } from '../proposal/colours';
|
||||
import { MarketName } from '../proposal/market-name';
|
||||
|
||||
export const CompactVotes = ({ number }: { number: BigNumber }) => (
|
||||
<CompactNumber
|
||||
@@ -39,8 +41,9 @@ const VoteProgress = ({
|
||||
children,
|
||||
}: VoteProgressProps) => {
|
||||
const containerClasses = classNames(
|
||||
'relative h-10 rounded-md border border-vega-dark-300 overflow-hidden',
|
||||
colourfulBg ? 'bg-vega-pink' : 'bg-vega-dark-400'
|
||||
'relative h-2 rounded-md overflow-hidden',
|
||||
// 'border border-vega-dark-300',
|
||||
colourfulBg ? 'bg-vega-red' : 'bg-vega-dark-200'
|
||||
);
|
||||
|
||||
const progressClasses = classNames(
|
||||
@@ -49,17 +52,19 @@ const VoteProgress = ({
|
||||
);
|
||||
|
||||
const textClasses = classNames(
|
||||
'absolute top-0 left-0 w-full h-full flex items-center justify-start px-3 text-black'
|
||||
'w-full flex items-center justify-start text-white text-sm pb-1'
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={containerClasses}>
|
||||
<div
|
||||
className={progressClasses}
|
||||
style={{ width: `${percentageFor}%` }}
|
||||
data-testid={testId}
|
||||
/>
|
||||
<div>
|
||||
<div className={textClasses}>{children}</div>
|
||||
<div className={containerClasses}>
|
||||
<div
|
||||
className={progressClasses}
|
||||
style={{ width: `${percentageFor}%` }}
|
||||
data-testid={testId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -78,14 +83,22 @@ const Status = ({ reached, threshold, text, testId }: StatusProps) => {
|
||||
<div data-testid={testId}>
|
||||
{reached ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<VegaIcon name={VegaIconNames.TICK} size={20} />
|
||||
<VegaIcon
|
||||
name={VegaIconNames.TICK}
|
||||
className="text-vega-green"
|
||||
size={20}
|
||||
/>
|
||||
<span>
|
||||
{threshold.toString()}% {text} {t('met')}
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<VegaIcon name={VegaIconNames.CROSS} size={20} />
|
||||
<VegaIcon
|
||||
name={VegaIconNames.CROSS}
|
||||
className="text-vega-red"
|
||||
size={20}
|
||||
/>
|
||||
<span>
|
||||
{threshold.toString()}% {text} {t('not met')}
|
||||
</span>
|
||||
@@ -151,7 +164,7 @@ const VoteBreakdownBatch = ({ proposal }: { proposal: BatchProposal }) => {
|
||||
<p className="flex gap-2 m-0 items-center">
|
||||
<VegaIcon
|
||||
name={VegaIconNames.CROSS}
|
||||
className="text-vega-pink"
|
||||
className="text-vega-red"
|
||||
size={20}
|
||||
/>
|
||||
{t(
|
||||
@@ -176,6 +189,7 @@ const VoteBreakdownBatch = ({ proposal }: { proposal: BatchProposal }) => {
|
||||
if (!p?.terms) return null;
|
||||
return (
|
||||
<VoteBreakdownBatchSubProposal
|
||||
indicator={i + 1}
|
||||
key={i}
|
||||
proposal={proposal}
|
||||
votes={proposal.votes}
|
||||
@@ -213,7 +227,7 @@ const VoteBreakdownBatch = ({ proposal }: { proposal: BatchProposal }) => {
|
||||
<p className="flex gap-2 m-0 items-center">
|
||||
<VegaIcon
|
||||
name={VegaIconNames.CROSS}
|
||||
className="text-vega-pink"
|
||||
className="text-vega-red"
|
||||
size={20}
|
||||
/>
|
||||
{t('Proposal failed: {{count}} of {{total}} proposals passed', {
|
||||
@@ -235,6 +249,7 @@ const VoteBreakdownBatch = ({ proposal }: { proposal: BatchProposal }) => {
|
||||
if (!p?.terms) return null;
|
||||
return (
|
||||
<VoteBreakdownBatchSubProposal
|
||||
indicator={i + 1}
|
||||
key={i}
|
||||
proposal={proposal}
|
||||
votes={proposal.votes}
|
||||
@@ -255,10 +270,12 @@ const VoteBreakdownBatchSubProposal = ({
|
||||
proposal,
|
||||
votes,
|
||||
terms,
|
||||
indicator,
|
||||
}: {
|
||||
proposal: BatchProposal;
|
||||
votes: VoteFieldsFragment;
|
||||
terms: ProposalTermsFieldsFragment;
|
||||
indicator?: number;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const voteInfo = useVoteInformation({
|
||||
@@ -269,14 +286,39 @@ const VoteBreakdownBatchSubProposal = ({
|
||||
const isProposalOpen = proposal?.state === ProposalState.STATE_OPEN;
|
||||
const isUpdateMarket = terms?.change?.__typename === 'UpdateMarket';
|
||||
|
||||
let marketId = undefined;
|
||||
if (terms?.change?.__typename === 'UpdateMarket') {
|
||||
marketId = terms.change.marketId;
|
||||
}
|
||||
if (terms?.change?.__typename === 'UpdateMarketState') {
|
||||
marketId = terms.change.market.id;
|
||||
}
|
||||
|
||||
const marketName = marketId ? (
|
||||
<>
|
||||
: <MarketName marketId={marketId} />
|
||||
</>
|
||||
) : null;
|
||||
|
||||
const indicatorElement = indicator && (
|
||||
<span className={getIndicatorStyle(indicator)}>{indicator}</span>
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h4>{t(terms.change.__typename)}</h4>
|
||||
<VoteBreakDownUI
|
||||
voteInfo={voteInfo}
|
||||
isProposalOpen={isProposalOpen}
|
||||
isUpdateMarket={isUpdateMarket}
|
||||
/>
|
||||
<div className="mb-6">
|
||||
<div className="flex items-baseline gap-3 mb-3">
|
||||
{indicatorElement}
|
||||
<h4>
|
||||
{t(terms.change.__typename)} {marketName}
|
||||
</h4>
|
||||
</div>
|
||||
<div className="rounded-sm bg-vega-dark-100 p-3">
|
||||
<VoteBreakDownUI
|
||||
voteInfo={voteInfo}
|
||||
isProposalOpen={isProposalOpen}
|
||||
isUpdateMarket={isUpdateMarket}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -291,11 +333,13 @@ const VoteBreakdownNormal = ({ proposal }: { proposal: Proposal }) => {
|
||||
const isUpdateMarket = proposal?.terms?.change?.__typename === 'UpdateMarket';
|
||||
|
||||
return (
|
||||
<VoteBreakDownUI
|
||||
voteInfo={voteInfo}
|
||||
isProposalOpen={isProposalOpen}
|
||||
isUpdateMarket={isUpdateMarket}
|
||||
/>
|
||||
<div className="mb-6">
|
||||
<VoteBreakDownUI
|
||||
voteInfo={voteInfo}
|
||||
isProposalOpen={isProposalOpen}
|
||||
isUpdateMarket={isUpdateMarket}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -322,7 +366,6 @@ const VoteBreakDownUI = ({
|
||||
noPercentage,
|
||||
noLPPercentage,
|
||||
yesPercentage,
|
||||
yesLPPercentage,
|
||||
yesTokens,
|
||||
noTokens,
|
||||
totalEquityLikeShareWeight,
|
||||
@@ -335,6 +378,7 @@ const VoteBreakDownUI = ({
|
||||
majorityLPMet,
|
||||
willPassByTokenVote,
|
||||
willPassByLPVote,
|
||||
lpVoteWeight,
|
||||
} = voteInfo;
|
||||
|
||||
const participationThresholdProgress = BigNumber.min(
|
||||
@@ -359,13 +403,13 @@ const VoteBreakDownUI = ({
|
||||
'flex justify-between flex-wrap gap-6'
|
||||
);
|
||||
const sectionClasses = classNames('min-w-[300px] flex-1 flex-grow');
|
||||
const headingClasses = classNames('mb-2 text-vega-dark-400');
|
||||
const headingClasses = classNames('mb-2 text-sm text-white font-bold');
|
||||
const progressDetailsClasses = classNames(
|
||||
'flex justify-between flex-wrap mt-2 text-sm'
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<div>
|
||||
{isProposalOpen && (
|
||||
<div
|
||||
data-testid="vote-status"
|
||||
@@ -382,7 +426,7 @@ const VoteBreakDownUI = ({
|
||||
<VegaIcon
|
||||
name={VegaIconNames.CROSS}
|
||||
size={20}
|
||||
className="text-vega-pink"
|
||||
className="text-vega-red"
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
@@ -398,103 +442,13 @@ const VoteBreakDownUI = ({
|
||||
<p className="m-0">
|
||||
<Trans
|
||||
i18nKey={'Currently expected to <0>fail</0>'}
|
||||
components={[<span className="text-vega-pink" />]}
|
||||
components={[<span className="text-vega-red" />]}
|
||||
/>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isUpdateMarket && (
|
||||
<div className="mb-4">
|
||||
<h3 className={headingClasses}>{t('liquidityProviderVote')}</h3>
|
||||
<div className={sectionWrapperClasses}>
|
||||
<section
|
||||
className={sectionClasses}
|
||||
data-testid="lp-majority-breakdown"
|
||||
>
|
||||
<VoteProgress
|
||||
percentageFor={yesLPPercentage}
|
||||
colourfulBg={true}
|
||||
testId="lp-majority-progress"
|
||||
>
|
||||
<Status
|
||||
reached={majorityLPMet}
|
||||
threshold={requiredMajorityLPPercentage}
|
||||
text={t('majorityThreshold')}
|
||||
testId={
|
||||
majorityLPMet ? 'lp-majority-met' : 'lp-majority-not-met'
|
||||
}
|
||||
/>
|
||||
</VoteProgress>
|
||||
|
||||
<div className={progressDetailsClasses}>
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t('liquidityProviderVotesFor')}:</span>
|
||||
<Tooltip
|
||||
description={
|
||||
<span>{yesLPPercentage.toFixed(defaultDP)}%</span>
|
||||
}
|
||||
>
|
||||
<button>{yesLPPercentage.toFixed(1)}%</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t('liquidityProviderVotesAgainst')}:</span>
|
||||
<span>
|
||||
<Tooltip
|
||||
description={
|
||||
<span>{noLPPercentage.toFixed(defaultDP)}%</span>
|
||||
}
|
||||
>
|
||||
<button>{noLPPercentage.toFixed(1)}%</button>
|
||||
</Tooltip>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section
|
||||
className={sectionClasses}
|
||||
data-testid="lp-participation-breakdown"
|
||||
>
|
||||
<VoteProgress
|
||||
percentageFor={
|
||||
lpParticipationThresholdProgress || new BigNumber(0)
|
||||
}
|
||||
testId="lp-participation-progress"
|
||||
>
|
||||
<Status
|
||||
reached={participationLPMet}
|
||||
threshold={requiredParticipationLP || new BigNumber(1)}
|
||||
text={t('participationThreshold')}
|
||||
testId={
|
||||
participationLPMet
|
||||
? 'lp-participation-met'
|
||||
: 'lp-participation-not-met'
|
||||
}
|
||||
/>
|
||||
</VoteProgress>
|
||||
|
||||
<div className="flex mt-2 text-sm">
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t('totalLiquidityProviderTokensVoted')}:</span>
|
||||
<Tooltip
|
||||
description={formatNumber(
|
||||
totalEquityLikeShareWeight,
|
||||
defaultDP
|
||||
)}
|
||||
>
|
||||
<span>{totalEquityLikeShareWeight.toFixed(1)}%</span>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isUpdateMarket && <h3 className={headingClasses}>{t('tokenVote')}</h3>}
|
||||
<div className={sectionWrapperClasses}>
|
||||
<section
|
||||
@@ -594,6 +548,97 @@ const VoteBreakDownUI = ({
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{/** Liquidity provider vote */}
|
||||
{isUpdateMarket && (
|
||||
<div className="mt-3">
|
||||
<h3 className={headingClasses}>{t('liquidityProviderVote')}</h3>
|
||||
<div className={sectionWrapperClasses}>
|
||||
<section
|
||||
className={sectionClasses}
|
||||
data-testid="lp-majority-breakdown"
|
||||
>
|
||||
<VoteProgress
|
||||
percentageFor={lpVoteWeight}
|
||||
colourfulBg={true}
|
||||
testId="lp-majority-progress"
|
||||
>
|
||||
<Status
|
||||
reached={majorityLPMet}
|
||||
threshold={requiredMajorityLPPercentage}
|
||||
text={t('majorityThreshold')}
|
||||
testId={
|
||||
majorityLPMet ? 'lp-majority-met' : 'lp-majority-not-met'
|
||||
}
|
||||
/>
|
||||
</VoteProgress>
|
||||
|
||||
<div className={progressDetailsClasses}>
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t('liquidityProviderVotesFor')}:</span>
|
||||
<Tooltip
|
||||
description={
|
||||
<span>{lpVoteWeight.toFixed(defaultDP)}%</span>
|
||||
}
|
||||
>
|
||||
<button>{lpVoteWeight.toFixed(1)}%</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t('liquidityProviderVotesAgainst')}:</span>
|
||||
<span>
|
||||
<Tooltip
|
||||
description={
|
||||
<span>{noLPPercentage.toFixed(defaultDP)}%</span>
|
||||
}
|
||||
>
|
||||
<button>{noLPPercentage.toFixed(1)}%</button>
|
||||
</Tooltip>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section
|
||||
className={sectionClasses}
|
||||
data-testid="lp-participation-breakdown"
|
||||
>
|
||||
<VoteProgress
|
||||
percentageFor={
|
||||
lpParticipationThresholdProgress || new BigNumber(0)
|
||||
}
|
||||
testId="lp-participation-progress"
|
||||
>
|
||||
<Status
|
||||
reached={participationLPMet}
|
||||
threshold={requiredParticipationLP || new BigNumber(1)}
|
||||
text={t('participationThreshold')}
|
||||
testId={
|
||||
participationLPMet
|
||||
? 'lp-participation-met'
|
||||
: 'lp-participation-not-met'
|
||||
}
|
||||
/>
|
||||
</VoteProgress>
|
||||
|
||||
<div className="flex mt-2 text-sm">
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t('totalLiquidityProviderTokensVoted')}:</span>
|
||||
<Tooltip
|
||||
description={formatNumber(
|
||||
totalEquityLikeShareWeight,
|
||||
defaultDP
|
||||
)}
|
||||
>
|
||||
<span>{totalEquityLikeShareWeight.toFixed(1)}%</span>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -273,4 +273,74 @@ describe('use-vote-information', () => {
|
||||
expect(current?.willPassByTokenVote).toEqual(false);
|
||||
expect(current?.willPassByLPVote).toEqual(true);
|
||||
});
|
||||
|
||||
it('mainnet recreation: only yes LP votes equal passing', () => {
|
||||
const yesVotes = 0;
|
||||
const noVotes = 70;
|
||||
const yesEquityLikeShareWeight = '0.21';
|
||||
const noEquityLikeShareWeight = '0';
|
||||
const fixedTokenValue = 1000000000000000000;
|
||||
|
||||
const proposal = generateProposal({
|
||||
terms: {
|
||||
change: {
|
||||
__typename: 'UpdateMarket',
|
||||
marketId: '12345',
|
||||
},
|
||||
},
|
||||
votes: {
|
||||
__typename: 'ProposalVotes',
|
||||
yes: generateYesVotes(
|
||||
yesVotes,
|
||||
fixedTokenValue,
|
||||
yesEquityLikeShareWeight
|
||||
),
|
||||
no: generateNoVotes(noVotes, fixedTokenValue, noEquityLikeShareWeight),
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
result: { current },
|
||||
} = renderHook(() =>
|
||||
useVoteInformation({ terms: proposal.terms, votes: proposal.votes })
|
||||
);
|
||||
|
||||
expect(current?.willPassByTokenVote).toEqual(false);
|
||||
expect(current?.willPassByLPVote).toEqual(true);
|
||||
});
|
||||
|
||||
it('mainnet recreation: mixed yes and no LP votes equal failing', () => {
|
||||
const yesVotes = 0;
|
||||
const noVotes = 70;
|
||||
const yesEquityLikeShareWeight = '0.21';
|
||||
const noEquityLikeShareWeight = '0.22';
|
||||
const fixedTokenValue = 1000000000000000000;
|
||||
|
||||
const proposal = generateProposal({
|
||||
terms: {
|
||||
change: {
|
||||
__typename: 'UpdateMarket',
|
||||
marketId: '12345',
|
||||
},
|
||||
},
|
||||
votes: {
|
||||
__typename: 'ProposalVotes',
|
||||
yes: generateYesVotes(
|
||||
yesVotes,
|
||||
fixedTokenValue,
|
||||
yesEquityLikeShareWeight
|
||||
),
|
||||
no: generateNoVotes(noVotes, fixedTokenValue, noEquityLikeShareWeight),
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
result: { current },
|
||||
} = renderHook(() =>
|
||||
useVoteInformation({ terms: proposal.terms, votes: proposal.votes })
|
||||
);
|
||||
|
||||
expect(current?.willPassByTokenVote).toEqual(false);
|
||||
expect(current?.willPassByLPVote).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -123,15 +123,19 @@ const getVoteData = (
|
||||
totalSupply.multipliedBy(params.requiredParticipation)
|
||||
);
|
||||
|
||||
const lpVoteWeight = yesEquityLikeShareWeight
|
||||
.dividedBy(totalEquityLikeShareWeight)
|
||||
.multipliedBy(100);
|
||||
|
||||
const participationLPMet = params.requiredParticipationLP
|
||||
? totalEquityLikeShareWeight.isGreaterThan(params.requiredParticipationLP)
|
||||
? lpVoteWeight.isGreaterThan(params.requiredParticipationLP)
|
||||
: false;
|
||||
|
||||
const majorityMet = yesPercentage.isGreaterThanOrEqualTo(
|
||||
requiredMajorityPercentage
|
||||
);
|
||||
|
||||
const majorityLPMet = yesLPPercentage.isGreaterThanOrEqualTo(
|
||||
const majorityLPMet = lpVoteWeight.isGreaterThanOrEqualTo(
|
||||
requiredMajorityLPPercentage
|
||||
);
|
||||
|
||||
@@ -149,14 +153,12 @@ const getVoteData = (
|
||||
|
||||
const willPassByLPVote =
|
||||
participationLPMet &&
|
||||
new BigNumber(yesLPPercentage).isGreaterThanOrEqualTo(
|
||||
requiredMajorityLPPercentage
|
||||
);
|
||||
lpVoteWeight.isGreaterThanOrEqualTo(requiredMajorityLPPercentage);
|
||||
|
||||
let willPass = false;
|
||||
|
||||
if (changeType === 'UpdateMarket' || changeType === 'UpdateMarketState') {
|
||||
willPass = willPassByTokenVote && willPassByLPVote;
|
||||
willPass = willPassByTokenVote || willPassByLPVote;
|
||||
} else {
|
||||
willPass = willPassByTokenVote;
|
||||
}
|
||||
@@ -182,6 +184,7 @@ const getVoteData = (
|
||||
totalLPTokensPercentage,
|
||||
willPassByTokenVote,
|
||||
willPassByLPVote,
|
||||
lpVoteWeight: lpVoteWeight.isNaN() ? new BigNumber(0) : lpVoteWeight,
|
||||
yesVotes: new BigNumber(votes.yes.totalNumber ?? 0),
|
||||
noVotes: new BigNumber(votes.no.totalNumber ?? 0),
|
||||
totalVotes: new BigNumber(votes.yes.totalNumber ?? 0).plus(
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||
import { useFetch } from '@vegaprotocol/react-helpers';
|
||||
import { ENV } from '../../../config';
|
||||
import { Proposal } from '../components/proposal';
|
||||
import { ProposalNotFound } from '../components/proposal-not-found';
|
||||
import { useProposalQuery } from '../__generated__/Proposals';
|
||||
import { useFetchProposal } from '../components/proposal/proposal-utils';
|
||||
|
||||
export const ProposalContainer = () => {
|
||||
const params = useParams<{ proposalId: string }>();
|
||||
|
||||
const {
|
||||
state: { data: restData, loading: restLoading, error: restError },
|
||||
} = useFetch(`${ENV.rest}governance?proposalId=${params.proposalId}`);
|
||||
const { data: restData, loading: restLoading } = useFetchProposal({
|
||||
proposalId: params.proposalId,
|
||||
});
|
||||
|
||||
const { data, loading, error } = useProposalQuery({
|
||||
fetchPolicy: 'network-only',
|
||||
@@ -26,7 +25,7 @@ export const ProposalContainer = () => {
|
||||
return (
|
||||
<AsyncRenderer
|
||||
loading={Boolean(loading || restLoading)}
|
||||
error={error || restError}
|
||||
error={error}
|
||||
data={{
|
||||
...data,
|
||||
...(restData ? { restData } : {}),
|
||||
|
||||
@@ -22,7 +22,7 @@ NX_WALLETCONNECT_PROJECT_ID=fe8091dc35738863e509fc4947525c72
|
||||
# Cosmic elevator flags
|
||||
NX_SUCCESSOR_MARKETS=true
|
||||
NX_STOP_ORDERS=true
|
||||
NX_ISOLATED_MARGIN=true
|
||||
NX_ISOLATED_MARGIN=false
|
||||
NX_ICEBERG_ORDERS=true
|
||||
NX_METAMASK_SNAPS=true
|
||||
NX_REFERRALS=true
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { useT } from '../../lib/use-t';
|
||||
import { ErrorBoundary } from '@sentry/react';
|
||||
import { CompetitionsHeader } from '../../components/competitions/competitions-header';
|
||||
import { Intent, Loader, TradingButton } from '@vegaprotocol/ui-toolkit';
|
||||
|
||||
import { useGameCards } from '../../lib/hooks/use-game-cards';
|
||||
import {
|
||||
ExternalLink,
|
||||
Intent,
|
||||
Loader,
|
||||
TradingButton,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { useEpochInfoQuery } from '../../lib/hooks/__generated__/Epoch';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { Links } from '../../lib/links';
|
||||
@@ -18,6 +21,9 @@ import take from 'lodash/take';
|
||||
import { usePageTitle } from '../../lib/hooks/use-page-title';
|
||||
import { TeamCard } from '../../components/competitions/team-card';
|
||||
import { useMyTeam } from '../../lib/hooks/use-my-team';
|
||||
import { useRewards } from '../../lib/hooks/use-rewards';
|
||||
import { Trans } from 'react-i18next';
|
||||
import { DocsLinks } from '@vegaprotocol/environment';
|
||||
|
||||
export const CompetitionsHome = () => {
|
||||
const t = useT();
|
||||
@@ -28,9 +34,9 @@ export const CompetitionsHome = () => {
|
||||
const { data: epochData } = useEpochInfoQuery();
|
||||
const currentEpoch = Number(epochData?.epoch.id);
|
||||
|
||||
const { data: gamesData, loading: gamesLoading } = useGameCards({
|
||||
const { data: gamesData, loading: gamesLoading } = useRewards({
|
||||
onlyActive: true,
|
||||
currentEpoch,
|
||||
scopeToTeams: true,
|
||||
});
|
||||
|
||||
const { data: teamsData, loading: teamsLoading } = useTeams();
|
||||
@@ -45,10 +51,34 @@ export const CompetitionsHome = () => {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<CompetitionsHeader title={t('Competitions')}>
|
||||
<p className="text-lg mb-3">
|
||||
<Trans
|
||||
i18nKey={
|
||||
'Check the cards below to see what community-created, on-chain games are active and how to compete. Joining a team also lets you take part in the on-chain <0>referral program</0>.'
|
||||
}
|
||||
components={[
|
||||
<Link className="underline" key="ref-prog" to={Links.REFERRALS()}>
|
||||
referral program
|
||||
</Link>,
|
||||
]}
|
||||
/>
|
||||
</p>
|
||||
<p className="text-lg mb-1">
|
||||
{t(
|
||||
'Be a team player! Participate in games and work together to rake in as much profit to win.'
|
||||
)}
|
||||
<Trans
|
||||
i18nKey={
|
||||
'Got an idea for a competition? Anyone can define and fund one -- <0>propose an on-chain game</0> yourself.'
|
||||
}
|
||||
components={[
|
||||
<ExternalLink
|
||||
className="underline"
|
||||
key="propose"
|
||||
href={DocsLinks?.ASSET_TRANSFER_PROPOSAL}
|
||||
>
|
||||
propose an on-chain game
|
||||
</ExternalLink>,
|
||||
]}
|
||||
/>
|
||||
{/** Docs: https://docs.vega.xyz/mainnet/tutorials/proposals/asset-transfer-proposal */}
|
||||
</p>
|
||||
</CompetitionsHeader>
|
||||
|
||||
@@ -75,7 +105,7 @@ export const CompetitionsHome = () => {
|
||||
variant="A"
|
||||
title={t('Create a team')}
|
||||
description={t(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipisicing elit placeat ipsum minus nemo error dicta.'
|
||||
'Create a new team, share your code with potential members, or set a whitelist for an exclusive group.'
|
||||
)}
|
||||
actionElement={
|
||||
<TradingButton
|
||||
@@ -94,7 +124,7 @@ export const CompetitionsHome = () => {
|
||||
variant="B"
|
||||
title={t('Solo team / lone wolf')}
|
||||
description={t(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipisicing elit placeat ipsum minus nemo error dicta.'
|
||||
'Want to compete but think the best team size is one? This is the option for you.'
|
||||
)}
|
||||
actionElement={
|
||||
<TradingButton
|
||||
@@ -112,7 +142,7 @@ export const CompetitionsHome = () => {
|
||||
variant="C"
|
||||
title={t('Join a team')}
|
||||
description={t(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipisicing elit placeat ipsum minus nemo error dicta.'
|
||||
'Browse existing public teams to find your perfect match.'
|
||||
)}
|
||||
actionElement={
|
||||
<TradingButton
|
||||
@@ -131,27 +161,57 @@ export const CompetitionsHome = () => {
|
||||
)}
|
||||
|
||||
{/** List of available games */}
|
||||
<h2 className="text-2xl mb-6">{t('Games')}</h2>
|
||||
<h2 className="text-2xl mb-1">{t('Games')}</h2>
|
||||
<p className="mb-6 text-sm">
|
||||
<Trans
|
||||
i18nKey={
|
||||
'See all the live games on the cards below. Every on-chain game is community funded and designed. <0>Find out how to create one</0>.'
|
||||
}
|
||||
components={[
|
||||
<ExternalLink
|
||||
className="underline"
|
||||
key="find-out"
|
||||
href={DocsLinks?.ASSET_TRANSFER_PROPOSAL}
|
||||
>
|
||||
Find out how to create one
|
||||
</ExternalLink>,
|
||||
]}
|
||||
/>
|
||||
{/** Docs: https://docs.vega.xyz/mainnet/tutorials/proposals/asset-transfer-proposal */}
|
||||
</p>
|
||||
|
||||
{gamesLoading ? (
|
||||
<Loader size="small" />
|
||||
) : (
|
||||
<GamesContainer data={gamesData} currentEpoch={currentEpoch} />
|
||||
)}
|
||||
<div className="mb-12 flex">
|
||||
{gamesLoading ? (
|
||||
<Loader size="small" />
|
||||
) : (
|
||||
<GamesContainer data={gamesData} currentEpoch={currentEpoch} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/** The teams ranking */}
|
||||
<div className="mb-6 flex flex-row items-baseline justify-between">
|
||||
<h2 className="text-2xl">{t('Leaderboard')}</h2>
|
||||
<div className="mb-1 flex flex-row items-baseline gap-3 justify-between">
|
||||
<h2 className="text-2xl">
|
||||
<Link to={Links.COMPETITIONS_TEAMS()} className=" underline">
|
||||
{t('Leaderboard')}
|
||||
</Link>
|
||||
</h2>
|
||||
<Link to={Links.COMPETITIONS_TEAMS()} className="text-sm underline">
|
||||
{t('View all teams')}
|
||||
</Link>
|
||||
</div>
|
||||
<p className="mb-6 text-sm">
|
||||
{t(
|
||||
'Teams can earn rewards if they meet the goals set in the on-chain trading competitions. Track your earned rewards here, and see which teams are top of the leaderboard this month.'
|
||||
)}
|
||||
</p>
|
||||
|
||||
{teamsLoading ? (
|
||||
<Loader size="small" />
|
||||
) : (
|
||||
<CompetitionsLeaderboard data={take(teamsData, 10)} />
|
||||
)}
|
||||
<div className="flex">
|
||||
{teamsLoading ? (
|
||||
<Loader size="small" />
|
||||
) : (
|
||||
<CompetitionsLeaderboard data={take(teamsData, 10)} />
|
||||
)}
|
||||
</div>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -10,11 +10,7 @@ import {
|
||||
VegaIcon,
|
||||
VegaIconNames,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import {
|
||||
TransferStatus,
|
||||
type Asset,
|
||||
type RecurringTransfer,
|
||||
} from '@vegaprotocol/types';
|
||||
import { TransferStatus, type Asset } from '@vegaprotocol/types';
|
||||
import classNames from 'classnames';
|
||||
import { useT } from '../../lib/use-t';
|
||||
import { Table } from '../../components/table';
|
||||
@@ -44,11 +40,6 @@ import {
|
||||
areTeamGames,
|
||||
} from '../../lib/hooks/use-games';
|
||||
import { useEpochInfoQuery } from '../../lib/hooks/__generated__/Epoch';
|
||||
import {
|
||||
type EnrichedTransfer,
|
||||
isScopedToTeams,
|
||||
useGameCards,
|
||||
} from '../../lib/hooks/use-game-cards';
|
||||
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
||||
import {
|
||||
ActiveRewardCard,
|
||||
@@ -56,6 +47,11 @@ import {
|
||||
} from '../../components/rewards-container/active-rewards';
|
||||
import { type MarketMap, useMarketsMapProvider } from '@vegaprotocol/markets';
|
||||
import format from 'date-fns/format';
|
||||
import {
|
||||
type EnrichedRewardTransfer,
|
||||
isScopedToTeams,
|
||||
useRewards,
|
||||
} from '../../lib/hooks/use-rewards';
|
||||
|
||||
export const CompetitionsTeam = () => {
|
||||
const t = useT();
|
||||
@@ -78,10 +74,9 @@ const TeamPageContainer = ({ teamId }: { teamId: string | undefined }) => {
|
||||
|
||||
const { data: games, loading: gamesLoading } = useGames(teamId);
|
||||
|
||||
const { data: epochData, loading: epochLoading } = useEpochInfoQuery();
|
||||
const { data: transfersData, loading: transfersLoading } = useGameCards({
|
||||
currentEpoch: Number(epochData?.epoch.id),
|
||||
const { data: transfersData, loading: transfersLoading } = useRewards({
|
||||
onlyActive: false,
|
||||
scopeToTeams: true,
|
||||
});
|
||||
|
||||
const { data: markets } = useMarketsMapProvider();
|
||||
@@ -112,7 +107,7 @@ const TeamPageContainer = ({ teamId }: { teamId: string | undefined }) => {
|
||||
games={areTeamGames(games) ? games : undefined}
|
||||
gamesLoading={gamesLoading}
|
||||
transfers={transfersData}
|
||||
transfersLoading={epochLoading || transfersLoading}
|
||||
transfersLoading={transfersLoading}
|
||||
allMarkets={markets || undefined}
|
||||
refetch={refetch}
|
||||
/>
|
||||
@@ -137,7 +132,7 @@ const TeamPage = ({
|
||||
members?: Member[];
|
||||
games?: TeamGame[];
|
||||
gamesLoading?: boolean;
|
||||
transfers?: EnrichedTransfer[];
|
||||
transfers?: EnrichedRewardTransfer[];
|
||||
transfersLoading?: boolean;
|
||||
allMarkets?: MarketMap;
|
||||
refetch: () => void;
|
||||
@@ -211,7 +206,7 @@ const Games = ({
|
||||
}: {
|
||||
games?: TeamGame[];
|
||||
gamesLoading?: boolean;
|
||||
transfers?: EnrichedTransfer[];
|
||||
transfers?: EnrichedRewardTransfer[];
|
||||
transfersLoading?: boolean;
|
||||
allMarkets?: MarketMap;
|
||||
}) => {
|
||||
@@ -451,7 +446,7 @@ const GameTypeCell = ({
|
||||
transfer,
|
||||
allMarkets,
|
||||
}: {
|
||||
transfer?: EnrichedTransfer;
|
||||
transfer?: EnrichedRewardTransfer;
|
||||
allMarkets?: MarketMap;
|
||||
}) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -474,7 +469,7 @@ const GameTypeCell = ({
|
||||
ref={ref}
|
||||
className="border-b border-dashed border-vega-clight-200 dark:border-vega-cdark-200 text-left md:truncate md:max-w-[25vw]"
|
||||
>
|
||||
<DispatchMetricInfo transferNode={transfer} allMarkets={allMarkets} />
|
||||
<DispatchMetricInfo reward={transfer} />
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
@@ -490,7 +485,7 @@ const ActiveRewardCardDialog = ({
|
||||
open: boolean;
|
||||
onChange: (isOpen: boolean) => void;
|
||||
trigger?: HTMLElement | null;
|
||||
transfer: EnrichedTransfer;
|
||||
transfer: EnrichedRewardTransfer;
|
||||
allMarkets?: MarketMap;
|
||||
}) => {
|
||||
const t = useT();
|
||||
@@ -516,8 +511,6 @@ const ActiveRewardCardDialog = ({
|
||||
<ActiveRewardCard
|
||||
transferNode={transfer}
|
||||
currentEpoch={Number(data?.epoch.id)}
|
||||
kind={transfer.transfer.kind as RecurringTransfer}
|
||||
allMarkets={allMarkets}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-1/4">
|
||||
|
||||
@@ -75,6 +75,7 @@ export const TradePanels = ({ market, pinnedAsset }: TradePanelsProps) => {
|
||||
{[
|
||||
'chart',
|
||||
'orderbook',
|
||||
'depth',
|
||||
'trades',
|
||||
'liquidity',
|
||||
'fundingPayments',
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Splash } from '@vegaprotocol/ui-toolkit';
|
||||
import { formatNumber } from '@vegaprotocol/utils';
|
||||
import { type useTeams } from '../../lib/hooks/use-teams';
|
||||
import { useT } from '../../lib/use-t';
|
||||
@@ -18,7 +17,11 @@ export const CompetitionsLeaderboard = ({
|
||||
const num = (n?: number | string) => (!n ? '-' : formatNumber(n, 0));
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
return <Splash>{t('Could not find any teams')}</Splash>;
|
||||
return (
|
||||
<p className="text-sm">
|
||||
{t('Currently no active teams on the network.')}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import { ActiveRewardCard } from '../rewards-container/active-rewards';
|
||||
import { useT } from '../../lib/use-t';
|
||||
import { type EnrichedTransfer } from '../../lib/hooks/use-game-cards';
|
||||
import { useMarketsMapProvider } from '@vegaprotocol/markets';
|
||||
import { type EnrichedRewardTransfer } from '../../lib/hooks/use-rewards';
|
||||
|
||||
export const GamesContainer = ({
|
||||
data,
|
||||
currentEpoch,
|
||||
}: {
|
||||
data: EnrichedTransfer[];
|
||||
data: EnrichedRewardTransfer[];
|
||||
currentEpoch: number;
|
||||
}) => {
|
||||
const t = useT();
|
||||
const { data: markets } = useMarketsMapProvider();
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
return (
|
||||
<p className="mb-6 text-muted">
|
||||
{t('There are currently no games available.')}
|
||||
<p className="text-sm">
|
||||
{t('Currently no active games on the network.')}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mb-12 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{data.map((game, i) => {
|
||||
// TODO: Remove `kind` prop from ActiveRewardCard
|
||||
const { transfer } = game;
|
||||
@@ -37,8 +35,6 @@ export const GamesContainer = ({
|
||||
key={i}
|
||||
transferNode={game}
|
||||
currentEpoch={currentEpoch}
|
||||
kind={transfer.kind}
|
||||
allMarkets={markets || undefined}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
lpAggregatedDataProvider,
|
||||
type Filter,
|
||||
LiquidityTable,
|
||||
liquidityProvisionsDataProvider,
|
||||
} from '@vegaprotocol/liquidity';
|
||||
import { getAsset, useMarket } from '@vegaprotocol/markets';
|
||||
import {
|
||||
@@ -71,7 +70,7 @@ export const LiquidityContainer = ({
|
||||
|
||||
const useReloadLiquidityData = (marketId: string | undefined) => {
|
||||
const { reload } = useDataProvider({
|
||||
dataProvider: liquidityProvisionsDataProvider,
|
||||
dataProvider: lpAggregatedDataProvider,
|
||||
variables: { marketId: marketId || '' },
|
||||
update: () => true,
|
||||
skip: !marketId,
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import {
|
||||
ActiveRewardCard,
|
||||
applyFilter,
|
||||
isActiveReward,
|
||||
} from './active-rewards';
|
||||
import { ActiveRewardCard, applyFilter } from './active-rewards';
|
||||
import {
|
||||
AccountType,
|
||||
AssetStatus,
|
||||
@@ -11,54 +7,13 @@ import {
|
||||
DistributionStrategy,
|
||||
EntityScope,
|
||||
IndividualScope,
|
||||
type RecurringTransfer,
|
||||
type TransferNode,
|
||||
TransferStatus,
|
||||
type Transfer,
|
||||
} from '@vegaprotocol/types';
|
||||
|
||||
jest.mock('./__generated__/Rewards', () => ({
|
||||
useMarketForRewardsQuery: () => ({
|
||||
data: undefined,
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('@vegaprotocol/assets', () => ({
|
||||
useAssetDataProvider: () => {
|
||||
return {
|
||||
data: {
|
||||
assetId: 'asset-1',
|
||||
},
|
||||
};
|
||||
},
|
||||
}));
|
||||
import { type EnrichedRewardTransfer } from '../../lib/hooks/use-rewards';
|
||||
|
||||
describe('ActiveRewards', () => {
|
||||
const mockRecurringTransfer: RecurringTransfer = {
|
||||
__typename: 'RecurringTransfer',
|
||||
startEpoch: 115332,
|
||||
endEpoch: 115432,
|
||||
factor: '1',
|
||||
dispatchStrategy: {
|
||||
__typename: 'DispatchStrategy',
|
||||
dispatchMetric: DispatchMetric.DISPATCH_METRIC_LP_FEES_RECEIVED,
|
||||
dispatchMetricAssetId:
|
||||
'c9fe6fc24fce121b2cc72680543a886055abb560043fda394ba5376203b7527d',
|
||||
marketIdsInScope: null,
|
||||
entityScope: EntityScope.ENTITY_SCOPE_INDIVIDUALS,
|
||||
individualScope: IndividualScope.INDIVIDUAL_SCOPE_ALL,
|
||||
teamScope: null,
|
||||
nTopPerformers: '',
|
||||
stakingRequirement: '',
|
||||
notionalTimeWeightedAveragePositionRequirement: '',
|
||||
windowLength: 1,
|
||||
lockPeriod: 0,
|
||||
distributionStrategy: DistributionStrategy.DISTRIBUTION_STRATEGY_PRO_RATA,
|
||||
rankTable: null,
|
||||
},
|
||||
};
|
||||
|
||||
const mockTransferNode: TransferNode = {
|
||||
const reward: EnrichedRewardTransfer = {
|
||||
__typename: 'TransferNode',
|
||||
transfer: {
|
||||
__typename: 'Transfer',
|
||||
@@ -86,21 +41,37 @@ describe('ActiveRewards', () => {
|
||||
reference: 'reward',
|
||||
status: TransferStatus.STATUS_PENDING,
|
||||
timestamp: '2023-12-18T13:05:35.948706Z',
|
||||
kind: mockRecurringTransfer,
|
||||
kind: {
|
||||
__typename: 'RecurringTransfer',
|
||||
startEpoch: 115332,
|
||||
endEpoch: 115432,
|
||||
factor: '1',
|
||||
dispatchStrategy: {
|
||||
__typename: 'DispatchStrategy',
|
||||
dispatchMetric: DispatchMetric.DISPATCH_METRIC_LP_FEES_RECEIVED,
|
||||
dispatchMetricAssetId:
|
||||
'c9fe6fc24fce121b2cc72680543a886055abb560043fda394ba5376203b7527d',
|
||||
marketIdsInScope: null,
|
||||
entityScope: EntityScope.ENTITY_SCOPE_INDIVIDUALS,
|
||||
individualScope: IndividualScope.INDIVIDUAL_SCOPE_ALL,
|
||||
teamScope: null,
|
||||
nTopPerformers: '',
|
||||
stakingRequirement: '',
|
||||
notionalTimeWeightedAveragePositionRequirement: '',
|
||||
windowLength: 1,
|
||||
lockPeriod: 0,
|
||||
distributionStrategy:
|
||||
DistributionStrategy.DISTRIBUTION_STRATEGY_PRO_RATA,
|
||||
rankTable: null,
|
||||
},
|
||||
},
|
||||
reason: null,
|
||||
},
|
||||
fees: [],
|
||||
};
|
||||
|
||||
it('renders with valid props', () => {
|
||||
render(
|
||||
<ActiveRewardCard
|
||||
transferNode={mockTransferNode}
|
||||
currentEpoch={1}
|
||||
kind={mockRecurringTransfer}
|
||||
allMarkets={{}}
|
||||
/>
|
||||
);
|
||||
render(<ActiveRewardCard transferNode={reward} currentEpoch={115432} />);
|
||||
|
||||
expect(
|
||||
screen.getByText(/Liquidity provision fees received/i)
|
||||
@@ -108,41 +79,11 @@ describe('ActiveRewards', () => {
|
||||
expect(screen.getByText('Individual scope')).toBeInTheDocument();
|
||||
expect(screen.getByText('Average position')).toBeInTheDocument();
|
||||
expect(screen.getByText('Ends in')).toBeInTheDocument();
|
||||
expect(screen.getByText('115431 epochs')).toBeInTheDocument();
|
||||
expect(screen.getByText('1 epoch')).toBeInTheDocument();
|
||||
expect(screen.getByText('Assessed over')).toBeInTheDocument();
|
||||
expect(screen.getByText('1 epoch')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('isActiveReward', () => {
|
||||
it('returns true for valid active reward', () => {
|
||||
const node = {
|
||||
transfer: {
|
||||
kind: {
|
||||
__typename: 'RecurringTransfer',
|
||||
dispatchStrategy: {},
|
||||
endEpoch: 10,
|
||||
},
|
||||
status: TransferStatus.STATUS_PENDING,
|
||||
},
|
||||
} as TransferNode;
|
||||
expect(isActiveReward(node, 5)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('returns false for invalid active reward', () => {
|
||||
const node = {
|
||||
transfer: {
|
||||
kind: {
|
||||
__typename: 'RecurringTransfer',
|
||||
dispatchStrategy: {},
|
||||
endEpoch: 10,
|
||||
},
|
||||
status: TransferStatus.STATUS_PENDING,
|
||||
},
|
||||
} as TransferNode;
|
||||
expect(isActiveReward(node, 15)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('applyFilter', () => {
|
||||
it('returns true when filter matches dispatch metric label', () => {
|
||||
const transfer = {
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import { useActiveRewardsQuery } from './__generated__/Rewards';
|
||||
import { useT } from '../../lib/use-t';
|
||||
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
type IconName,
|
||||
type VegaIconSize,
|
||||
Icon,
|
||||
Intent,
|
||||
Tooltip,
|
||||
VegaIcon,
|
||||
VegaIconNames,
|
||||
@@ -14,18 +10,12 @@ import {
|
||||
TinyScroll,
|
||||
truncateMiddle,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { IconNames } from '@blueprintjs/icons';
|
||||
import {
|
||||
type Maybe,
|
||||
type Transfer,
|
||||
type TransferNode,
|
||||
type RecurringTransfer,
|
||||
DistributionStrategyDescriptionMapping,
|
||||
DistributionStrategyMapping,
|
||||
EntityScope,
|
||||
EntityScopeMapping,
|
||||
TransferStatus,
|
||||
TransferStatusMapping,
|
||||
DispatchMetric,
|
||||
DispatchMetricDescription,
|
||||
DispatchMetricLabels,
|
||||
@@ -36,43 +26,33 @@ import {
|
||||
IndividualScopeDescriptionMapping,
|
||||
} from '@vegaprotocol/types';
|
||||
import { Card } from '../card/card';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { type ReactNode, useState } from 'react';
|
||||
import {
|
||||
type AssetFieldsFragment,
|
||||
useAssetsMapProvider,
|
||||
type BasicAssetDetails,
|
||||
} from '@vegaprotocol/assets';
|
||||
import { type MarketFieldsFragment } from '@vegaprotocol/markets';
|
||||
import {
|
||||
type MarketFieldsFragment,
|
||||
useMarketsMapProvider,
|
||||
getAsset,
|
||||
} from '@vegaprotocol/markets';
|
||||
type EnrichedRewardTransfer,
|
||||
useRewards,
|
||||
} from '../../lib/hooks/use-rewards';
|
||||
import compact from 'lodash/compact';
|
||||
|
||||
enum CardColour {
|
||||
BLUE = 'BLUE',
|
||||
GREEN = 'GREEN',
|
||||
GREY = 'GREY',
|
||||
ORANGE = 'ORANGE',
|
||||
PINK = 'PINK',
|
||||
PURPLE = 'PURPLE',
|
||||
WHITE = 'WHITE',
|
||||
YELLOW = 'YELLOW',
|
||||
}
|
||||
|
||||
export type Filter = {
|
||||
searchTerm: string;
|
||||
};
|
||||
|
||||
export const isActiveReward = (node: TransferNode, currentEpoch: number) => {
|
||||
const { transfer } = node;
|
||||
if (transfer.kind.__typename !== 'RecurringTransfer') {
|
||||
return false;
|
||||
}
|
||||
const { dispatchStrategy } = transfer.kind;
|
||||
|
||||
if (!dispatchStrategy) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transfer.kind.endEpoch && transfer.kind.endEpoch < currentEpoch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transfer.status !== TransferStatus.STATUS_PENDING) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const applyFilter = (
|
||||
node: TransferNode & {
|
||||
asset?: AssetFieldsFragment | null;
|
||||
@@ -95,7 +75,10 @@ export const applyFilter = (
|
||||
transfer.asset?.symbol
|
||||
.toLowerCase()
|
||||
.includes(filter.searchTerm.toLowerCase()) ||
|
||||
EntityScopeLabelMapping[transfer.kind.dispatchStrategy.entityScope]
|
||||
(
|
||||
EntityScopeLabelMapping[transfer.kind.dispatchStrategy.entityScope] ||
|
||||
'Unspecified'
|
||||
)
|
||||
.toLowerCase()
|
||||
.includes(filter.searchTerm.toLowerCase()) ||
|
||||
node.asset?.name
|
||||
@@ -114,42 +97,15 @@ export const applyFilter = (
|
||||
|
||||
export const ActiveRewards = ({ currentEpoch }: { currentEpoch: number }) => {
|
||||
const t = useT();
|
||||
const { data: activeRewardsData } = useActiveRewardsQuery({
|
||||
variables: {
|
||||
isReward: true,
|
||||
},
|
||||
const { data } = useRewards({
|
||||
onlyActive: true,
|
||||
});
|
||||
|
||||
const [filter, setFilter] = useState<Filter>({
|
||||
searchTerm: '',
|
||||
});
|
||||
|
||||
const { data: assets } = useAssetsMapProvider();
|
||||
const { data: markets } = useMarketsMapProvider();
|
||||
|
||||
const enrichedTransfers = activeRewardsData?.transfersConnection?.edges
|
||||
?.map((e) => e?.node as TransferNode)
|
||||
.filter((node) => isActiveReward(node, currentEpoch))
|
||||
.map((node) => {
|
||||
if (node.transfer.kind.__typename !== 'RecurringTransfer') {
|
||||
return node;
|
||||
}
|
||||
|
||||
const asset =
|
||||
assets &&
|
||||
assets[
|
||||
node.transfer.kind.dispatchStrategy?.dispatchMetricAssetId || ''
|
||||
];
|
||||
|
||||
const marketsInScope =
|
||||
node.transfer.kind.dispatchStrategy?.marketIdsInScope?.map(
|
||||
(id) => markets && markets[id]
|
||||
);
|
||||
|
||||
return { ...node, asset, markets: marketsInScope };
|
||||
});
|
||||
|
||||
if (!enrichedTransfers || !enrichedTransfers.length) return null;
|
||||
if (!data || !data.length) return null;
|
||||
|
||||
return (
|
||||
<Card
|
||||
@@ -157,7 +113,8 @@ export const ActiveRewards = ({ currentEpoch }: { currentEpoch: number }) => {
|
||||
className="lg:col-span-full"
|
||||
data-testid="active-rewards-card"
|
||||
>
|
||||
{enrichedTransfers.length > 1 && (
|
||||
{/** CARDS FILTER */}
|
||||
{data.length > 1 && (
|
||||
<TradingInput
|
||||
onChange={(e) =>
|
||||
setFilter((curr) => ({ ...curr, searchTerm: e.target.value }))
|
||||
@@ -172,142 +129,32 @@ export const ActiveRewards = ({ currentEpoch }: { currentEpoch: number }) => {
|
||||
prependElement={<VegaIcon name={VegaIconNames.SEARCH} />}
|
||||
/>
|
||||
)}
|
||||
{/** CARDS */}
|
||||
<TinyScroll className="grid gap-x-8 gap-y-10 h-fit grid-cols-[repeat(auto-fill,_minmax(230px,_1fr))] md:grid-cols-[repeat(auto-fill,_minmax(230px,_1fr))] lg:grid-cols-[repeat(auto-fill,_minmax(320px,_1fr))] xl:grid-cols-[repeat(auto-fill,_minmax(335px,_1fr))] max-h-[40rem] overflow-auto pr-2">
|
||||
{enrichedTransfers
|
||||
{data
|
||||
.filter((n) => applyFilter(n, filter))
|
||||
.map((node, i) => {
|
||||
const { transfer } = node;
|
||||
if (
|
||||
transfer.kind.__typename !== 'RecurringTransfer' ||
|
||||
!transfer.kind.dispatchStrategy?.dispatchMetric
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
node && (
|
||||
<ActiveRewardCard
|
||||
key={i}
|
||||
transferNode={node}
|
||||
kind={transfer.kind}
|
||||
currentEpoch={currentEpoch}
|
||||
allMarkets={markets || {}}
|
||||
/>
|
||||
)
|
||||
);
|
||||
})}
|
||||
.map((node, i) => (
|
||||
<ActiveRewardCard
|
||||
key={i}
|
||||
transferNode={node}
|
||||
currentEpoch={currentEpoch}
|
||||
/>
|
||||
))}
|
||||
</TinyScroll>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
// This was built to be a status indicator for the rewards based on the transfer status
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const StatusIndicator = ({
|
||||
status,
|
||||
reason,
|
||||
}: {
|
||||
status: TransferStatus;
|
||||
reason?: Maybe<string> | undefined;
|
||||
}) => {
|
||||
const t = useT();
|
||||
const getIconIntent = (status: string) => {
|
||||
switch (status) {
|
||||
case TransferStatus.STATUS_DONE:
|
||||
return { icon: IconNames.TICK_CIRCLE, intent: Intent.Success };
|
||||
case TransferStatus.STATUS_REJECTED:
|
||||
return { icon: IconNames.ERROR, intent: Intent.Danger };
|
||||
default:
|
||||
return { icon: IconNames.HELP, intent: Intent.Primary };
|
||||
}
|
||||
};
|
||||
const { icon, intent } = getIconIntent(status);
|
||||
return (
|
||||
<Tooltip
|
||||
description={
|
||||
<span>
|
||||
{t('Transfer status: {{status}} {{reason}}', {
|
||||
status: TransferStatusMapping[status],
|
||||
reason: reason ? `(${reason})` : '',
|
||||
})}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<span
|
||||
className={classNames(
|
||||
{
|
||||
'text-gray-700 dark:text-gray-300': intent === Intent.None,
|
||||
'text-vega-blue': intent === Intent.Primary,
|
||||
'text-vega-green dark:text-vega-green': intent === Intent.Success,
|
||||
'dark:text-yellow text-yellow-600': intent === Intent.Warning,
|
||||
'text-vega-red': intent === Intent.Danger,
|
||||
},
|
||||
'flex items-start p-1 align-text-bottom'
|
||||
)}
|
||||
>
|
||||
<Icon size={3} name={icon as IconName} />
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
type ActiveRewardCardProps = {
|
||||
transferNode: TransferNode & {
|
||||
asset?: AssetFieldsFragment | null;
|
||||
markets?: (MarketFieldsFragment | null)[];
|
||||
};
|
||||
transferNode: EnrichedRewardTransfer;
|
||||
currentEpoch: number;
|
||||
kind: RecurringTransfer;
|
||||
allMarkets?: Record<string, MarketFieldsFragment | null>;
|
||||
};
|
||||
export const ActiveRewardCard = ({
|
||||
transferNode,
|
||||
currentEpoch,
|
||||
kind,
|
||||
allMarkets,
|
||||
}: ActiveRewardCardProps) => {
|
||||
const t = useT();
|
||||
|
||||
const { transfer } = transferNode;
|
||||
const { dispatchStrategy } = kind;
|
||||
|
||||
const marketIdsInScope = dispatchStrategy?.marketIdsInScope;
|
||||
const firstMarketData = transferNode.markets?.[0];
|
||||
|
||||
const specificMarkets = useMemo(() => {
|
||||
if (
|
||||
!firstMarketData ||
|
||||
!marketIdsInScope ||
|
||||
marketIdsInScope.length === 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
if (marketIdsInScope.length > 1) {
|
||||
const marketNames =
|
||||
allMarkets &&
|
||||
marketIdsInScope
|
||||
.map((id) => allMarkets[id]?.tradableInstrument?.instrument?.name)
|
||||
.join(', ');
|
||||
|
||||
return (
|
||||
<Tooltip description={marketNames}>
|
||||
<span>Specific markets</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span>{firstMarketData?.tradableInstrument?.instrument?.name || ''}</span>
|
||||
);
|
||||
}, [firstMarketData, marketIdsInScope, allMarkets]);
|
||||
|
||||
const dispatchAsset = transferNode.asset;
|
||||
|
||||
if (!dispatchStrategy) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Gray out/hide the cards that are related to not trading markets
|
||||
const marketSettled = transferNode.markets?.some(
|
||||
// don't display the cards that are scoped to not trading markets
|
||||
const marketSettled = transferNode.markets?.filter(
|
||||
(m) =>
|
||||
m?.state &&
|
||||
[
|
||||
@@ -318,97 +165,133 @@ export const ActiveRewardCard = ({
|
||||
].includes(m.state)
|
||||
);
|
||||
|
||||
if (marketSettled) {
|
||||
// hide the card if all of the markets are being marked as e.g. settled
|
||||
if (
|
||||
marketSettled?.length === transferNode.markets?.length &&
|
||||
Boolean(transferNode.markets && transferNode.markets.length > 0)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const assetInActiveMarket =
|
||||
allMarkets &&
|
||||
Object.values(allMarkets).some((m: MarketFieldsFragment | null) => {
|
||||
if (m && getAsset(m).id === dispatchStrategy.dispatchMetricAssetId) {
|
||||
return m?.state && MarketState.STATE_ACTIVE === m.state;
|
||||
let colour =
|
||||
DispatchMetricColourMap[
|
||||
transferNode.transfer.kind.dispatchStrategy.dispatchMetric
|
||||
];
|
||||
|
||||
// grey out of any of the markets is suspended or
|
||||
// if the asset is not currently traded on any of the active markets
|
||||
const marketSuspended =
|
||||
transferNode.markets?.filter(
|
||||
(m) =>
|
||||
m?.state === MarketState.STATE_SUSPENDED ||
|
||||
m?.state === MarketState.STATE_SUSPENDED_VIA_GOVERNANCE
|
||||
).length === transferNode.markets?.length &&
|
||||
Boolean(transferNode.markets && transferNode.markets.length > 0);
|
||||
|
||||
if (marketSuspended || !transferNode.isAssetTraded) {
|
||||
colour = CardColour.GREY;
|
||||
}
|
||||
|
||||
return (
|
||||
<RewardCard
|
||||
colour={colour}
|
||||
rewardAmount={addDecimalsFormatNumber(
|
||||
transferNode.transfer.amount,
|
||||
transferNode.transfer.asset?.decimals || 0,
|
||||
6
|
||||
)}
|
||||
rewardAsset={transferNode.asset}
|
||||
endsIn={
|
||||
transferNode.transfer.kind.endEpoch != null
|
||||
? transferNode.transfer.kind.endEpoch - currentEpoch
|
||||
: undefined
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
const marketSuspended = transferNode.markets?.some(
|
||||
(m) =>
|
||||
m?.state === MarketState.STATE_SUSPENDED ||
|
||||
m?.state === MarketState.STATE_SUSPENDED_VIA_GOVERNANCE
|
||||
dispatchStrategy={transferNode.transfer.kind.dispatchStrategy}
|
||||
dispatchMetricInfo={<DispatchMetricInfo reward={transferNode} />}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// Gray out the cards that are related to suspended markets
|
||||
// Or settlement assets in markets that are not active and eligible for rewards
|
||||
const { gradientClassName, mainClassName } =
|
||||
marketSuspended || !assetInActiveMarket
|
||||
? {
|
||||
gradientClassName: 'from-vega-cdark-500 to-vega-clight-400',
|
||||
mainClassName: 'from-vega-cdark-400 dark:from-vega-cdark-600 to-20%',
|
||||
}
|
||||
: getGradientClasses(dispatchStrategy.dispatchMetric);
|
||||
|
||||
const entityScope = dispatchStrategy.entityScope;
|
||||
|
||||
const RewardCard = ({
|
||||
colour,
|
||||
rewardAmount,
|
||||
rewardAsset,
|
||||
dispatchStrategy,
|
||||
endsIn,
|
||||
dispatchMetricInfo,
|
||||
}: {
|
||||
colour: CardColour;
|
||||
rewardAmount: string;
|
||||
/** The asset linked to the dispatch strategy via `dispatchMetricAssetId` property. */
|
||||
rewardAsset?: BasicAssetDetails;
|
||||
/** The transfer's dispatch strategy. */
|
||||
dispatchStrategy: DispatchStrategy;
|
||||
/** The number of epochs until the transfer stops. */
|
||||
endsIn?: number;
|
||||
/** The VEGA asset details, required to format the min staking amount. */
|
||||
vegaAsset?: BasicAssetDetails;
|
||||
dispatchMetricInfo?: ReactNode;
|
||||
}) => {
|
||||
const t = useT();
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
className={classNames(
|
||||
'bg-gradient-to-r col-span-full p-0.5 lg:col-auto h-full',
|
||||
'rounded-lg',
|
||||
gradientClassName
|
||||
CardColourStyles[colour].gradientClassName
|
||||
)}
|
||||
data-testid="active-rewards-card"
|
||||
>
|
||||
<div
|
||||
className={classNames(
|
||||
mainClassName,
|
||||
'bg-gradient-to-b bg-vega-clight-800 dark:bg-vega-cdark-800 h-full w-full rounded p-4 flex flex-col gap-4'
|
||||
CardColourStyles[colour].mainClassName,
|
||||
'bg-gradient-to-b bg-vega-clight-800 dark:bg-vega-cdark-800 h-full w-full rounded-md p-4 flex flex-col gap-4'
|
||||
)}
|
||||
>
|
||||
<div className="flex justify-between gap-4">
|
||||
{/** ENTITY SCOPE */}
|
||||
<div className="flex flex-col gap-2 items-center text-center">
|
||||
<EntityIcon transfer={transfer} />
|
||||
{entityScope && (
|
||||
<EntityIcon entityScope={dispatchStrategy.entityScope} />
|
||||
{dispatchStrategy.entityScope && (
|
||||
<span className="text-muted text-xs" data-testid="entity-scope">
|
||||
{EntityScopeLabelMapping[entityScope] || t('Unspecified')}
|
||||
{EntityScopeLabelMapping[dispatchStrategy.entityScope] ||
|
||||
t('Unspecified')}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/** AMOUNT AND DISTRIBUTION STRATEGY */}
|
||||
<div className="flex flex-col gap-2 items-center text-center">
|
||||
{/** AMOUNT */}
|
||||
<h3 className="flex flex-col gap-1 text-2xl shrink-1 text-center">
|
||||
<span className="font-glitch" data-testid="reward-value">
|
||||
{addDecimalsFormatNumber(
|
||||
transferNode.transfer.amount,
|
||||
transferNode.transfer.asset?.decimals || 0,
|
||||
6
|
||||
)}
|
||||
{rewardAmount}
|
||||
</span>
|
||||
|
||||
<span className="font-alpha">
|
||||
{transferNode.transfer.asset?.symbol}
|
||||
</span>
|
||||
<span className="font-alpha">{rewardAsset?.symbol || ''}</span>
|
||||
</h3>
|
||||
{
|
||||
<Tooltip
|
||||
description={t(
|
||||
DistributionStrategyDescriptionMapping[
|
||||
|
||||
{/** DISTRIBUTION STRATEGY */}
|
||||
<Tooltip
|
||||
description={t(
|
||||
DistributionStrategyDescriptionMapping[
|
||||
dispatchStrategy.distributionStrategy
|
||||
]
|
||||
)}
|
||||
underline={true}
|
||||
>
|
||||
<span className="text-xs" data-testid="distribution-strategy">
|
||||
{
|
||||
DistributionStrategyMapping[
|
||||
dispatchStrategy.distributionStrategy
|
||||
]
|
||||
)}
|
||||
underline={true}
|
||||
>
|
||||
<span className="text-xs" data-testid="distribution-strategy">
|
||||
{
|
||||
DistributionStrategyMapping[
|
||||
dispatchStrategy.distributionStrategy
|
||||
]
|
||||
}
|
||||
</span>
|
||||
</Tooltip>
|
||||
}
|
||||
}
|
||||
</span>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
{/** DISTRIBUTION DELAY */}
|
||||
<div className="flex flex-col gap-2 items-center text-center">
|
||||
<CardIcon
|
||||
iconName={VegaIconNames.LOCK}
|
||||
@@ -421,63 +304,59 @@ export const ActiveRewardCard = ({
|
||||
data-testid="locked-for"
|
||||
>
|
||||
{t('numberEpochs', '{{count}} epochs', {
|
||||
count: kind.dispatchStrategy?.lockPeriod,
|
||||
count: dispatchStrategy.lockPeriod,
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span className="border-[0.5px] border-gray-700" />
|
||||
<span data-testid="dispatch-metric-info">
|
||||
{DispatchMetricLabels[dispatchStrategy.dispatchMetric]} •{' '}
|
||||
<Tooltip
|
||||
underline={marketSuspended}
|
||||
description={
|
||||
(marketSuspended || !assetInActiveMarket) &&
|
||||
(specificMarkets
|
||||
? t('Eligible market(s) currently suspended')
|
||||
: !assetInActiveMarket
|
||||
? t('Currently no markets eligible for reward')
|
||||
: '')
|
||||
}
|
||||
>
|
||||
<span>{specificMarkets || dispatchAsset?.name}</span>
|
||||
</Tooltip>
|
||||
</span>
|
||||
{/** DISPATCH METRIC */}
|
||||
{dispatchMetricInfo ? (
|
||||
dispatchMetricInfo
|
||||
) : (
|
||||
<span data-testid="dispatch-metric-info">
|
||||
{DispatchMetricLabels[dispatchStrategy.dispatchMetric]}
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-8 flex-wrap">
|
||||
{kind.endEpoch && (
|
||||
{/** ENDS IN */}
|
||||
{endsIn != null && (
|
||||
<span className="flex flex-col">
|
||||
<span className="text-muted text-xs">{t('Ends in')} </span>
|
||||
<span data-testid="ends-in">
|
||||
{t('numberEpochs', '{{count}} epochs', {
|
||||
count: kind.endEpoch - currentEpoch,
|
||||
})}
|
||||
<span data-testid="ends-in" data-endsin={endsIn}>
|
||||
{endsIn >= 0
|
||||
? t('numberEpochs', '{{count}} epochs', {
|
||||
count: endsIn,
|
||||
})
|
||||
: t('Ended')}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
|
||||
{
|
||||
<span className="flex flex-col">
|
||||
<span className="text-muted text-xs">{t('Assessed over')}</span>
|
||||
<span data-testid="assessed-over">
|
||||
{t('numberEpochs', '{{count}} epochs', {
|
||||
count: dispatchStrategy.windowLength,
|
||||
})}
|
||||
</span>
|
||||
{/** WINDOW LENGTH */}
|
||||
<span className="flex flex-col">
|
||||
<span className="text-muted text-xs">{t('Assessed over')}</span>
|
||||
<span data-testid="assessed-over">
|
||||
{t('numberEpochs', '{{count}} epochs', {
|
||||
count: dispatchStrategy.windowLength,
|
||||
})}
|
||||
</span>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
{/** DISPATCH METRIC DESCRIPTION */}
|
||||
{dispatchStrategy?.dispatchMetric && (
|
||||
<span className="text-muted text-sm h-[3rem]">
|
||||
{t(DispatchMetricDescription[dispatchStrategy?.dispatchMetric])}
|
||||
</span>
|
||||
)}
|
||||
<span className="border-[0.5px] border-gray-700" />
|
||||
{kind.dispatchStrategy && (
|
||||
{/** REQUIREMENTS */}
|
||||
{dispatchStrategy && (
|
||||
<RewardRequirements
|
||||
dispatchStrategy={kind.dispatchStrategy}
|
||||
assetDecimalPlaces={transfer.asset?.decimals}
|
||||
dispatchStrategy={dispatchStrategy}
|
||||
rewardAsset={rewardAsset}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
@@ -487,77 +366,67 @@ export const ActiveRewardCard = ({
|
||||
};
|
||||
|
||||
export const DispatchMetricInfo = ({
|
||||
transferNode,
|
||||
allMarkets,
|
||||
reward,
|
||||
}: {
|
||||
transferNode: ActiveRewardCardProps['transferNode'];
|
||||
allMarkets?: ActiveRewardCardProps['allMarkets'];
|
||||
reward: EnrichedRewardTransfer;
|
||||
}) => {
|
||||
const dispatchStrategy =
|
||||
transferNode.transfer.kind.__typename === 'RecurringTransfer'
|
||||
? transferNode.transfer.kind.dispatchStrategy
|
||||
: null;
|
||||
const t = useT();
|
||||
const dispatchStrategy = reward.transfer.kind.dispatchStrategy;
|
||||
const marketNames = compact(
|
||||
reward.markets?.map((m) => m.tradableInstrument.instrument.name)
|
||||
);
|
||||
|
||||
const dispatchAsset = transferNode.transfer.asset;
|
||||
let additionalDispatchMetricInfo = null;
|
||||
|
||||
const marketIdsInScope = dispatchStrategy?.marketIdsInScope;
|
||||
const firstMarketData = transferNode.markets?.[0];
|
||||
const specificMarkets = useMemo(() => {
|
||||
if (
|
||||
!firstMarketData ||
|
||||
!marketIdsInScope ||
|
||||
marketIdsInScope.length === 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
if (marketIdsInScope.length > 1) {
|
||||
const marketNames =
|
||||
allMarkets &&
|
||||
marketIdsInScope
|
||||
.map((id) => allMarkets[id]?.tradableInstrument?.instrument?.name)
|
||||
.join(', ');
|
||||
|
||||
return (
|
||||
<Tooltip description={marketNames}>
|
||||
<span>Specific markets</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
const name = firstMarketData?.tradableInstrument?.instrument?.name;
|
||||
if (name) {
|
||||
return <span>{name}</span>;
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [firstMarketData, marketIdsInScope, allMarkets]);
|
||||
|
||||
if (!dispatchStrategy) return null;
|
||||
// if asset found then display asset symbol
|
||||
if (reward.asset) {
|
||||
additionalDispatchMetricInfo = <span>{reward.asset.symbol}</span>;
|
||||
}
|
||||
// but if scoped to only one market then display market name
|
||||
if (marketNames.length === 1) {
|
||||
additionalDispatchMetricInfo = <span>{marketNames[0]}</span>;
|
||||
}
|
||||
// or if scoped to many markets then indicate it's scoped to "specific markets"
|
||||
if (marketNames.length > 1) {
|
||||
additionalDispatchMetricInfo = (
|
||||
<Tooltip description={marketNames}>
|
||||
<span>{t('Specific markets')}</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span data-testid="dispatch-metric-info">
|
||||
{DispatchMetricLabels[dispatchStrategy.dispatchMetric]} •{' '}
|
||||
<span>{specificMarkets || dispatchAsset?.name}</span>
|
||||
{DispatchMetricLabels[dispatchStrategy.dispatchMetric]}
|
||||
{additionalDispatchMetricInfo != null && (
|
||||
<> • {additionalDispatchMetricInfo}</>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
const RewardRequirements = ({
|
||||
dispatchStrategy,
|
||||
assetDecimalPlaces = 0,
|
||||
rewardAsset,
|
||||
vegaAsset,
|
||||
}: {
|
||||
dispatchStrategy: DispatchStrategy;
|
||||
assetDecimalPlaces: number | undefined;
|
||||
rewardAsset?: BasicAssetDetails;
|
||||
vegaAsset?: BasicAssetDetails;
|
||||
}) => {
|
||||
const t = useT();
|
||||
|
||||
const entityLabel = EntityScopeLabelMapping[dispatchStrategy.entityScope];
|
||||
|
||||
return (
|
||||
<dl className="flex justify-between flex-wrap items-center gap-3 text-xs">
|
||||
<div className="flex flex-col gap-1">
|
||||
<dt className="flex items-center gap-1 text-muted">
|
||||
{t('{{entity}} scope', {
|
||||
entity: EntityScopeLabelMapping[dispatchStrategy.entityScope],
|
||||
})}
|
||||
{entityLabel
|
||||
? t('{{entity}} scope', {
|
||||
entity: entityLabel,
|
||||
})
|
||||
: t('Scope')}
|
||||
</dt>
|
||||
<dd className="flex items-center gap-1" data-testid="scope">
|
||||
<RewardEntityScope dispatchStrategy={dispatchStrategy} />
|
||||
@@ -574,7 +443,7 @@ const RewardRequirements = ({
|
||||
>
|
||||
{addDecimalsFormatNumber(
|
||||
dispatchStrategy?.stakingRequirement || 0,
|
||||
assetDecimalPlaces
|
||||
vegaAsset?.decimals || 18
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
@@ -587,7 +456,7 @@ const RewardRequirements = ({
|
||||
{addDecimalsFormatNumber(
|
||||
dispatchStrategy?.notionalTimeWeightedAveragePositionRequirement ||
|
||||
0,
|
||||
assetDecimalPlaces
|
||||
rewardAsset?.decimals || 0
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
@@ -645,44 +514,65 @@ const RewardEntityScope = ({
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
return t('Unspecified');
|
||||
};
|
||||
|
||||
const getGradientClasses = (d: DispatchMetric | undefined) => {
|
||||
switch (d) {
|
||||
case DispatchMetric.DISPATCH_METRIC_AVERAGE_POSITION:
|
||||
return {
|
||||
gradientClassName: 'from-vega-pink-500 to-vega-purple-400',
|
||||
mainClassName: 'from-vega-pink-400 dark:from-vega-pink-600 to-20%',
|
||||
};
|
||||
case DispatchMetric.DISPATCH_METRIC_LP_FEES_RECEIVED:
|
||||
return {
|
||||
gradientClassName: 'from-vega-green-500 to-vega-yellow-500',
|
||||
mainClassName: 'from-vega-green-400 dark:from-vega-green-600 to-20%',
|
||||
};
|
||||
case DispatchMetric.DISPATCH_METRIC_MAKER_FEES_PAID:
|
||||
return {
|
||||
gradientClassName: 'from-vega-orange-500 to-vega-pink-400',
|
||||
mainClassName: 'from-vega-orange-400 dark:from-vega-orange-600 to-20%',
|
||||
};
|
||||
case DispatchMetric.DISPATCH_METRIC_MARKET_VALUE:
|
||||
case DispatchMetric.DISPATCH_METRIC_RELATIVE_RETURN:
|
||||
return {
|
||||
gradientClassName: 'from-vega-purple-500 to-vega-blue-400',
|
||||
mainClassName: 'from-vega-purple-400 dark:from-vega-purple-600 to-20%',
|
||||
};
|
||||
case DispatchMetric.DISPATCH_METRIC_RETURN_VOLATILITY:
|
||||
return {
|
||||
gradientClassName: 'from-vega-blue-500 to-vega-green-400',
|
||||
mainClassName: 'from-vega-blue-400 dark:from-vega-blue-600 to-20%',
|
||||
};
|
||||
case DispatchMetric.DISPATCH_METRIC_VALIDATOR_RANKING:
|
||||
default:
|
||||
return {
|
||||
gradientClassName: 'from-vega-pink-500 to-vega-purple-400',
|
||||
mainClassName: 'from-vega-pink-400 dark:from-vega-pink-600 to-20%',
|
||||
};
|
||||
}
|
||||
const CardColourStyles: Record<
|
||||
CardColour,
|
||||
{ gradientClassName: string; mainClassName: string }
|
||||
> = {
|
||||
[CardColour.BLUE]: {
|
||||
gradientClassName: 'from-vega-blue-500 to-vega-green-400',
|
||||
mainClassName: 'from-vega-blue-400 dark:from-vega-blue-600 to-20%',
|
||||
},
|
||||
[CardColour.GREEN]: {
|
||||
gradientClassName: 'from-vega-green-500 to-vega-yellow-500',
|
||||
mainClassName: 'from-vega-green-400 dark:from-vega-green-600 to-20%',
|
||||
},
|
||||
[CardColour.GREY]: {
|
||||
gradientClassName: 'from-vega-cdark-500 to-vega-clight-200',
|
||||
mainClassName: 'from-vega-cdark-400 dark:from-vega-cdark-600 to-20%',
|
||||
},
|
||||
[CardColour.ORANGE]: {
|
||||
gradientClassName: 'from-vega-orange-500 to-vega-pink-400',
|
||||
mainClassName: 'from-vega-orange-400 dark:from-vega-orange-600 to-20%',
|
||||
},
|
||||
[CardColour.PINK]: {
|
||||
gradientClassName: 'from-vega-pink-500 to-vega-purple-400',
|
||||
mainClassName: 'from-vega-pink-400 dark:from-vega-pink-600 to-20%',
|
||||
},
|
||||
[CardColour.PURPLE]: {
|
||||
gradientClassName: 'from-vega-purple-500 to-vega-blue-400',
|
||||
mainClassName: 'from-vega-purple-400 dark:from-vega-purple-600 to-20%',
|
||||
},
|
||||
[CardColour.WHITE]: {
|
||||
gradientClassName:
|
||||
'from-vega-clight-600 dark:from-vega-clight-900 to-vega-yellow-500 dark:to-vega-yellow-400',
|
||||
mainClassName: 'from-white dark:from-vega-clight-100 to-20%',
|
||||
},
|
||||
[CardColour.YELLOW]: {
|
||||
gradientClassName: 'from-vega-yellow-500 to-vega-orange-400',
|
||||
mainClassName: 'from-vega-yellow-400 dark:from-vega-yellow-600 to-20%',
|
||||
},
|
||||
};
|
||||
|
||||
const DispatchMetricColourMap: Record<DispatchMetric, CardColour> = {
|
||||
// Liquidity provision fees received
|
||||
[DispatchMetric.DISPATCH_METRIC_LP_FEES_RECEIVED]: CardColour.BLUE,
|
||||
// Price maker fees paid
|
||||
[DispatchMetric.DISPATCH_METRIC_MAKER_FEES_PAID]: CardColour.PINK,
|
||||
// Price maker fees earned
|
||||
[DispatchMetric.DISPATCH_METRIC_MAKER_FEES_RECEIVED]: CardColour.GREEN,
|
||||
// Total market value
|
||||
[DispatchMetric.DISPATCH_METRIC_MARKET_VALUE]: CardColour.WHITE,
|
||||
// Average position
|
||||
[DispatchMetric.DISPATCH_METRIC_AVERAGE_POSITION]: CardColour.ORANGE,
|
||||
// Relative return
|
||||
[DispatchMetric.DISPATCH_METRIC_RELATIVE_RETURN]: CardColour.PURPLE,
|
||||
// Return volatility
|
||||
[DispatchMetric.DISPATCH_METRIC_RETURN_VOLATILITY]: CardColour.YELLOW,
|
||||
// Validator ranking
|
||||
[DispatchMetric.DISPATCH_METRIC_VALIDATOR_RANKING]: CardColour.WHITE,
|
||||
};
|
||||
|
||||
const CardIcon = ({
|
||||
@@ -703,36 +593,29 @@ const CardIcon = ({
|
||||
);
|
||||
};
|
||||
|
||||
const EntityScopeIconMap: Record<EntityScope, VegaIconNames> = {
|
||||
[EntityScope.ENTITY_SCOPE_TEAMS]: VegaIconNames.TEAM,
|
||||
[EntityScope.ENTITY_SCOPE_INDIVIDUALS]: VegaIconNames.MAN,
|
||||
};
|
||||
|
||||
const EntityIcon = ({
|
||||
transfer,
|
||||
entityScope,
|
||||
size = 18,
|
||||
}: {
|
||||
transfer: Transfer;
|
||||
entityScope: EntityScope;
|
||||
size?: VegaIconSize;
|
||||
}) => {
|
||||
if (transfer.kind.__typename !== 'RecurringTransfer') {
|
||||
return null;
|
||||
}
|
||||
const entityScope = transfer.kind.dispatchStrategy?.entityScope;
|
||||
const getIconName = () => {
|
||||
switch (entityScope) {
|
||||
case EntityScope.ENTITY_SCOPE_TEAMS:
|
||||
return VegaIconNames.TEAM;
|
||||
case EntityScope.ENTITY_SCOPE_INDIVIDUALS:
|
||||
return VegaIconNames.MAN;
|
||||
default:
|
||||
return VegaIconNames.QUESTION_MARK;
|
||||
}
|
||||
};
|
||||
const iconName = getIconName();
|
||||
return (
|
||||
<Tooltip
|
||||
description={
|
||||
<span>{entityScope ? EntityScopeMapping[entityScope] : ''}</span>
|
||||
entityScope ? <span>{EntityScopeMapping[entityScope]}</span> : undefined
|
||||
}
|
||||
>
|
||||
<span className="flex items-center p-2 rounded-full border border-gray-600">
|
||||
{iconName && <VegaIcon name={iconName} size={size} />}
|
||||
<VegaIcon
|
||||
name={EntityScopeIconMap[entityScope] || VegaIconNames.QUESTION_MARK}
|
||||
size={size}
|
||||
/>
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
type RewardsPageQuery,
|
||||
useRewardsPageQuery,
|
||||
useRewardsEpochQuery,
|
||||
} from './__generated__/Rewards';
|
||||
} from '../../lib/hooks/__generated__/Rewards';
|
||||
import {
|
||||
TradingButton,
|
||||
VegaIcon,
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
import {
|
||||
useRewardsHistoryQuery,
|
||||
type RewardsHistoryQuery,
|
||||
} from './__generated__/Rewards';
|
||||
} from '../../lib/hooks/__generated__/Rewards';
|
||||
import { useRewardsRowData } from './use-reward-row-data';
|
||||
import { useT } from '../../lib/use-t';
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import BigNumber from 'bignumber.js';
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
import { type Asset } from '@vegaprotocol/assets';
|
||||
import { type PartyRewardsConnection } from './rewards-history';
|
||||
import { type RewardsHistoryQuery } from './__generated__/Rewards';
|
||||
import { type RewardsHistoryQuery } from '../../lib/hooks/__generated__/Rewards';
|
||||
|
||||
const REWARD_ACCOUNT_TYPES = [
|
||||
AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
CONSOLE_IMAGE_NAME=vegaprotocol/trading:latest
|
||||
VEGA_VERSION=v0.74.1
|
||||
VEGA_VERSION=v0.74.3
|
||||
LOCAL_SERVER=false
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
CONSOLE_IMAGE_NAME=vegaprotocol/trading:develop
|
||||
VEGA_VERSION=v0.74.1
|
||||
VEGA_VERSION=v0.74.3
|
||||
LOCAL_SERVER=false
|
||||
|
||||
+63
-119
@@ -1,156 +1,100 @@
|
||||
# Trading Market-Sim End-To-End Tests
|
||||
|
||||
This direcotry contains end-to-end tests for the trading application using vega-market-sim. This README will guide you through setting up your environment and running the tests.
|
||||
This directory contains end-to-end tests for the Trading application using Vega-market-sim. This guide will help you set up your environment and run the tests efficiently.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- [Poetry](https://python-poetry.org/docs/#installing-with-the-official-installer)
|
||||
- [Docker](https://www.docker.com/)
|
||||
- [Python versions ">=3.9,<3.11"](https://www.python.org/)
|
||||
Ensure you have the following installed:
|
||||
|
||||
## Getting Started
|
||||
- [Poetry](https://python-poetry.org/docs/#installing-with-the-official-installer) for dependency management.
|
||||
- [Docker](https://www.docker.com/) for running isolated application containers.
|
||||
- Python, versions ">=3.9,<3.11". Install from the [official Python website](https://www.python.org/).
|
||||
|
||||
1. **Install Poetry**: Follow the instructions on the [official Poetry website](https://python-poetry.org/docs/#installing-with-the-official-installer).
|
||||
2. **Install Docker**: Follow the instructions on the [official Docker website](https://docs.docker.com/desktop/).
|
||||
3. **Install Python**: Follow the instructions on the [official Python website](https://www.python.org/)
|
||||
**ensure you install a version between 3.9 and 3.11.**
|
||||
4. **Start up a Poetry environment**: Execute the commands below to configure the Poetry environment.
|
||||
## Setup
|
||||
|
||||
### Ensure you are in the tests folder before running commands
|
||||
### 1. Install Dependencies
|
||||
|
||||
- **Poetry**: Follow the installation guide on the [official Poetry website](https://python-poetry.org/docs/#installing-with-the-official-installer).
|
||||
- **Docker**: Installation instructions are available on the [official Docker website](https://docs.docker.com/desktop/).
|
||||
- **Python**: Install a version between 3.9 and 3.11, as detailed on the [official Python website](https://www.python.org/).
|
||||
|
||||
### 2. Configure Your Environment
|
||||
|
||||
Ensure you're in the tests folder before executing commands.
|
||||
|
||||
```bash
|
||||
poetry shell
|
||||
```
|
||||
|
||||
5. **Install python dependencies**
|
||||
|
||||
To make sure you are on the latest version of our market-sim branch.
|
||||
|
||||
```bash
|
||||
poetry update vega-sim
|
||||
```
|
||||
|
||||
```bash
|
||||
poetry update vega-sim # Updates to the latest version of the market-sim branch
|
||||
poetry install
|
||||
playwright install chromium # Installs necessary browsers for Playwright
|
||||
```
|
||||
|
||||
6. **Install Playwright Browsers**: Execute the command below to browsers for Playwright.
|
||||
### 3. Prepare Binaries and Docker Images
|
||||
|
||||
```bash
|
||||
playwright install chromium
|
||||
```
|
||||
|
||||
7. **Download necessary binaries**:
|
||||
Use the following command within your Python environment. The `--force` flag ensures the binaries are overwritten, and the `--version` specifies the desired version. e.g. `v0.73.4`
|
||||
Download necessary binaries for the desired Vega version:
|
||||
|
||||
```bash
|
||||
python -m vega_sim.tools.load_binaries --force --version $VEGA_VERSION
|
||||
```
|
||||
|
||||
8. **Pull the desired Docker image**
|
||||
Pull Docker images for your environment:
|
||||
|
||||
```bash
|
||||
docker pull vegaprotocol/trading:develop
|
||||
```
|
||||
- **Development**: `docker pull vegaprotocol/trading:develop`
|
||||
- **Production**: `docker pull vegaprotocol/trading:main`
|
||||
|
||||
9. **Run tests**: Poetry/Python will serve the app from docker
|
||||
|
||||
### Update the .env file with the correct trading image.
|
||||
|
||||
```bash
|
||||
poetry run pytest
|
||||
```
|
||||
|
||||
### Docker images
|
||||
|
||||
Pull the desired image:
|
||||
|
||||
**Testnet**
|
||||
|
||||
```bash
|
||||
docker pull vegaprotocol/trading:develop
|
||||
```
|
||||
|
||||
**Mainnet**
|
||||
|
||||
```bash
|
||||
docker pull vegaprotocol/trading:main
|
||||
```
|
||||
|
||||
Find all available images on [Docker Hub](https://hub.docker.com/r/vegaprotocol/trading/tags).
|
||||
|
||||
#### Create a Docker Image of Your Locally Built Trading App
|
||||
|
||||
To build your Docker image, use the following commands:
|
||||
|
||||
```bash
|
||||
yarn nx build trading ./docker/prepare-dist.sh
|
||||
```
|
||||
### 4. Build a Docker Image of Your Locally Built Trading App
|
||||
|
||||
```bash
|
||||
./docker/prepare-dist.sh
|
||||
docker build -f docker/node-outside-docker.Dockerfile --build-arg APP=trading --build-arg ENV_NAME=stagnet1 -t vegaprotocol/trading:latest .
|
||||
```
|
||||
|
||||
## Running Tests 🧪
|
||||
## Running Tests
|
||||
|
||||
Before running make sure the docker daemon is running.
|
||||
Ensure the Docker daemon is running. Update the `.env` file with the correct trading image before proceeding.
|
||||
|
||||
To run a specific test, use the `-k` option followed by the name of the test.
|
||||
Run all tests:
|
||||
- **Run all tests**: `poetry run pytest`
|
||||
- **Run a specific test**: `poetry run pytest -k "test_name" -s --headed`
|
||||
- **Run tests using your locally served console**:
|
||||
|
||||
```bash
|
||||
poetry run pytest
|
||||
In one terminal window, build and serve the trading console:
|
||||
|
||||
```bash
|
||||
yarn nx build trading
|
||||
yarn nx serve trading
|
||||
```
|
||||
|
||||
Once the console is served, update the `.env` file to set `local_server=true`. You can then run your tests using the same commands as above.
|
||||
NOTE: Parallel running of tests will not work against locally served console.
|
||||
|
||||
## Test Strategy and Container Cleanup
|
||||
|
||||
### Strategy
|
||||
|
||||
We aim for each test file to use a single Vega instance to ensure test isolation and manage resources efficiently. This approach helps in maintaining test performance and reliability.
|
||||
|
||||
### Cleanup Procedure
|
||||
|
||||
To ensure proper cleanup of containers after each test, use the following fixture pattern:
|
||||
|
||||
```python
|
||||
@pytest.fixture
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
```
|
||||
|
||||
Run a targeted test:
|
||||
## Running Tests in Parallel
|
||||
|
||||
```bash
|
||||
poetry run pytest -k "test_name" -s --headed
|
||||
```
|
||||
For running tests in parallel:
|
||||
|
||||
Run from anywhere:
|
||||
- **Within the e2e folder**: `poetry run pytest -s --numprocesses auto --dist loadfile`
|
||||
- **From anywhere**: `yarn trading:test:all`
|
||||
|
||||
```bash
|
||||
yarn trading:test -- "test_name" -s --headed
|
||||
```
|
||||
## Troubleshooting
|
||||
|
||||
Run using your locally served console:
|
||||
If IntelliSense is not working in VSCode, follow these steps:
|
||||
|
||||
Within one terminal
|
||||
|
||||
```bash
|
||||
yarn nx build trading
|
||||
```
|
||||
|
||||
```bash
|
||||
yarn nx serve trading
|
||||
|
||||
```
|
||||
|
||||
Once console is served you can update the .env file to have local_server to true.
|
||||
|
||||
## Running Tests in Parallel 🔢
|
||||
|
||||
To run tests in parallel, use the `--numprocesses auto` option. The `--dist loadfile` setting ensures that multiple runners are not assigned to a single test file.
|
||||
|
||||
### From within the e2e folder:
|
||||
|
||||
```bash
|
||||
poetry run pytest -s --numprocesses auto --dist loadfile
|
||||
```
|
||||
|
||||
### From anywhere:
|
||||
|
||||
```bash
|
||||
yarn trading:test:all
|
||||
```
|
||||
|
||||
# Things to know
|
||||
|
||||
If you "intellisense" isn't working follow these steps:
|
||||
|
||||
1. ```bash
|
||||
poetry run which python
|
||||
```
|
||||
|
||||
2. Then open the command menu in vscode (cmd + shift + p) and type `select interpreter` , press enter, select enter interpreter path press enter then paste in the output from that above command you should get the right python again
|
||||
1. Find the Poetry environment's Python binary: `poetry run which python`
|
||||
2. In VSCode, open the command menu (`cmd + shift + p`), search for `Python: Select Interpreter`, select `Enter interpreter path`, and paste the path from step 1.
|
||||
|
||||
Generated
+394
-390
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@ def create_position(vega: VegaServiceNull, market_id):
|
||||
vega.wait_for_total_catchup
|
||||
|
||||
|
||||
@pytest.mark.skip("tempory disabling of isolated margin")
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted")
|
||||
def test_switch_cross_isolated_margin(
|
||||
continuous_market, vega: VegaServiceNull, page: Page):
|
||||
@@ -62,6 +63,7 @@ def test_switch_cross_isolated_margin(
|
||||
"22,109.99996Cross1.0x")
|
||||
|
||||
|
||||
@pytest.mark.skip("tempory disabling of isolated margin")
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted")
|
||||
def test_check_cross_isolated_margin_info(
|
||||
continuous_market, vega: VegaServiceNull, page: Page):
|
||||
|
||||
@@ -235,7 +235,7 @@ def test_submit_stop_oco_market_order_pending(
|
||||
"PendingOCO"
|
||||
)
|
||||
|
||||
@pytest.mark.usefixtures("page", "continuous_market", "auth", "risk_accepted")
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted")
|
||||
def test_submit_stop_oco_limit_order_pending(
|
||||
continuous_market, vega: VegaServiceNull, page: Page
|
||||
):
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
# test_ids.py
|
||||
|
||||
# Constants for test IDs
|
||||
ADJUSTED_FEES = "adjusted-fees"
|
||||
TOTAL_FEE_BEFORE_DISCOUNT = "total-fee-before-discount"
|
||||
INFRASTRUCTURE_FEES = "infrastructure-fees"
|
||||
MAKER_FEES = "maker-fees"
|
||||
LIQUIDITY_FEES = "liquidity-fees"
|
||||
TOTAL_DISCOUNT = "total-discount"
|
||||
VOLUME_DISCOUNT_ROW = "volume-discount-row"
|
||||
REFERRAL_DISCOUNT_ROW = "referral-discount-row"
|
||||
PAST_EPOCHS_VOLUME = "past-epochs-volume"
|
||||
REQUIRED_FOR_NEXT_TIER = "required-for-next-tier"
|
||||
TIER_VALUE_0 = "tier-value-0"
|
||||
TIER_VALUE_1 = "tier-value-1"
|
||||
DISCOUNT_VALUE_0 = "discount-value-0"
|
||||
DISCOUNT_VALUE_1 = "discount-value-1"
|
||||
MIN_VOLUME_VALUE_0 = "min-volume-value-0"
|
||||
MIN_VOLUME_VALUE_1 = "min-volume-value-1"
|
||||
MY_VOLUME_VALUE_0 = "my-volume-value-0"
|
||||
MY_VOLUME_VALUE_1 = "my-volume-value-1"
|
||||
ORDER_SIZE = "order-size"
|
||||
ORDER_PRICE = "order-price"
|
||||
DISCOUNT_PILL = "discount-pill"
|
||||
FEES_TEXT = "fees-text"
|
||||
TOOLTIP_CONTENT = "tooltip-content"
|
||||
INFRASTRUCTURE_FEE_FACTOR = "infrastructure-fee-factor"
|
||||
INFRASTRUCTURE_FEE_VALUE = "infrastructure-fee-value"
|
||||
LIQUIDITY_FEE_FACTOR = "liquidity-fee-factor"
|
||||
LIQUIDITY_FEE_VALUE = "liquidity-fee-value"
|
||||
MAKER_FEE_FACTOR = "maker-fee-factor"
|
||||
MAKER_FEE_VALUE = "maker-fee-value"
|
||||
SUBTOTAL_FEE_FACTOR = "subtotal-fee-factor"
|
||||
SUBTOTAL_FEE_VALUE = "subtotal-fee-value"
|
||||
DISCOUNT_FEE_FACTOR = "discount-fee-factor"
|
||||
DISCOUNT_FEE_VALUE = "discount-fee-value"
|
||||
TOTAL_FEE_VALUE = "total-fee-value"
|
||||
RUNNING_NOTIONAL_TAKER_VOLUME = "running-notional-taker-volume"
|
||||
EPOCHS_IN_REFERRAL_SET = "epochs-in-referral-set"
|
||||
REQUIRED_EPOCHS_VALUE_0 = "required-epochs-value-0"
|
||||
REQUIRED_EPOCHS_VALUE_1 = "required-epochs-value-1"
|
||||
FILLS = "Fills"
|
||||
TAB_FILLS = "tab-fills"
|
||||
FEE_BREAKDOWN_TOOLTIP = "fee-breakdown-tooltip"
|
||||
PINNED_ROW_LOCATOR = ".ag-pinned-left-cols-container .ag-row"
|
||||
ROW_LOCATOR = ".ag-center-cols-container .ag-row"
|
||||
# Col-Ids:
|
||||
COL_INSTRUMENT_CODE = '[data-testid="market-code"]'
|
||||
COL_CODE = '[col-id="code"]'
|
||||
COL_SIZE = '[col-id="size"]'
|
||||
COL_PRICE = '[col-id="price"]'
|
||||
COL_PRICE_1 = '[col-id="price_1"]'
|
||||
COL_AGGRESSOR = '[col-id="aggressor"]'
|
||||
COL_FEE = '[col-id="fee"]'
|
||||
COL_FEE_DISCOUNT = '[col-id="fee-discount"]'
|
||||
COL_FEE_AFTER_DISCOUNT = '[col-id="feeAfterDiscount"]'
|
||||
COL_INFRA_FEE = '[col-id="infraFee"]'
|
||||
COL_MAKER_FEE = '[col-id="makerFee"]'
|
||||
COL_LIQUIDITY_FEE = '[col-id="liquidityFee"]'
|
||||
COL_TOTAL_FEE = '[col-id="totalFee"]'
|
||||
@@ -1,689 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from playwright.sync_api import Page, expect
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
from actions.vega import submit_order
|
||||
from wallet_config import MM_WALLET
|
||||
from conftest import init_vega, init_page, auth_setup, cleanup_container
|
||||
from actions.utils import next_epoch, change_keys, forward_time
|
||||
from fixtures.market import market_exists, setup_continuous_market
|
||||
|
||||
# region Constants for test IDs
|
||||
ADJUSTED_FEES = "adjusted-fees"
|
||||
TOTAL_FEE_BEFORE_DISCOUNT = "total-fee-before-discount"
|
||||
INFRASTRUCTURE_FEES = "infrastructure-fees"
|
||||
MAKER_FEES = "maker-fees"
|
||||
LIQUIDITY_FEES = "liquidity-fees"
|
||||
TOTAL_DISCOUNT = "total-discount"
|
||||
VOLUME_DISCOUNT_ROW = "volume-discount-row"
|
||||
REFERRAL_DISCOUNT_ROW = "referral-discount-row"
|
||||
PAST_EPOCHS_VOLUME = "past-epochs-volume"
|
||||
REQUIRED_FOR_NEXT_TIER = "required-for-next-tier"
|
||||
TIER_VALUE_0 = "tier-value-0"
|
||||
TIER_VALUE_1 = "tier-value-1"
|
||||
DISCOUNT_VALUE_0 = "discount-value-0"
|
||||
DISCOUNT_VALUE_1 = "discount-value-1"
|
||||
MIN_VOLUME_VALUE_0 = "min-volume-value-0"
|
||||
MIN_VOLUME_VALUE_1 = "min-volume-value-1"
|
||||
MY_VOLUME_VALUE_0 = "my-volume-value-0"
|
||||
MY_VOLUME_VALUE_1 = "my-volume-value-1"
|
||||
ORDER_SIZE = "order-size"
|
||||
ORDER_PRICE = "order-price"
|
||||
DISCOUNT_PILL = "discount-pill"
|
||||
FEES_TEXT = "fees-text"
|
||||
TOOLTIP_CONTENT = "tooltip-content"
|
||||
INFRASTRUCTURE_FEE_FACTOR = "infrastructure-fee-factor"
|
||||
INFRASTRUCTURE_FEE_VALUE = "infrastructure-fee-value"
|
||||
LIQUIDITY_FEE_FACTOR = "liquidity-fee-factor"
|
||||
LIQUIDITY_FEE_VALUE = "liquidity-fee-value"
|
||||
MAKER_FEE_FACTOR = "maker-fee-factor"
|
||||
MAKER_FEE_VALUE = "maker-fee-value"
|
||||
SUBTOTAL_FEE_FACTOR = "subtotal-fee-factor"
|
||||
SUBTOTAL_FEE_VALUE = "subtotal-fee-value"
|
||||
DISCOUNT_FEE_FACTOR = "discount-fee-factor"
|
||||
DISCOUNT_FEE_VALUE = "discount-fee-value"
|
||||
TOTAL_FEE_VALUE = "total-fee-value"
|
||||
RUNNING_NOTIONAL_TAKER_VOLUME = "running-notional-taker-volume"
|
||||
EPOCHS_IN_REFERRAL_SET = "epochs-in-referral-set"
|
||||
REQUIRED_EPOCHS_VALUE_0 = "required-epochs-value-0"
|
||||
REQUIRED_EPOCHS_VALUE_1 = "required-epochs-value-1"
|
||||
FILLS = "Fills"
|
||||
TAB_FILLS = "tab-fills"
|
||||
FEE_BREAKDOWN_TOOLTIP = "fee-breakdown-tooltip"
|
||||
PINNED_ROW_LOCATOR = ".ag-pinned-left-cols-container .ag-row"
|
||||
ROW_LOCATOR = ".ag-center-cols-container .ag-row"
|
||||
# Col-Ids:
|
||||
COL_INSTRUMENT_CODE = '[data-testid="market-code"]'
|
||||
COL_CODE = '[col-id="code"]'
|
||||
COL_SIZE = '[col-id="size"]'
|
||||
COL_PRICE = '[col-id="price"]'
|
||||
COL_PRICE_1 = '[col-id="price_1"]'
|
||||
COL_AGGRESSOR = '[col-id="aggressor"]'
|
||||
COL_FEE = '[col-id="fee"]'
|
||||
COL_FEE_DISCOUNT = '[col-id="fee-discount"]'
|
||||
COL_FEE_AFTER_DISCOUNT = '[col-id="feeAfterDiscount"]'
|
||||
COL_INFRA_FEE = '[col-id="infraFee"]'
|
||||
COL_MAKER_FEE = '[col-id="makerFee"]'
|
||||
COL_LIQUIDITY_FEE = '[col-id="liquidityFee"]'
|
||||
COL_TOTAL_FEE = '[col-id="totalFee"]'
|
||||
# endregion
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def market_ids():
|
||||
return {
|
||||
"tier_1_volume": "default_id",
|
||||
"tier_2_volume": "default_id",
|
||||
"tier_1_referral": "default_id",
|
||||
"tier_2_referral": "default_id",
|
||||
"combo": "default_id",
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_volume_discount_tier_1(request):
|
||||
with init_vega(request) as vega_volume_discount_tier_1:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_volume_discount_tier_1)) # Register the cleanup function
|
||||
yield vega_volume_discount_tier_1
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_volume_discount_tier_2(request):
|
||||
with init_vega(request) as vega_volume_discount_tier_2:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_volume_discount_tier_2)) # Register the cleanup function
|
||||
yield vega_volume_discount_tier_2
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_referral_discount_tier_1(request):
|
||||
with init_vega(request) as vega_referral_discount_tier_1:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_referral_discount_tier_1)) # Register the cleanup function
|
||||
yield vega_referral_discount_tier_1
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_referral_discount_tier_2(request):
|
||||
with init_vega(request) as vega_referral_discount_tier_2:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_referral_discount_tier_2)) # Register the cleanup function
|
||||
yield vega_referral_discount_tier_2
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_referral_and_volume_discount(request):
|
||||
with init_vega(request) as vega_referral_and_volume_discount:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_referral_and_volume_discount)) # Register the cleanup function
|
||||
yield vega_referral_and_volume_discount
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def page(vega_instance, browser, request):
|
||||
with init_page(vega_instance, browser, request) as page_instance:
|
||||
yield page_instance
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vega_instance(
|
||||
tier,
|
||||
discount_program,
|
||||
vega_volume_discount_tier_1,
|
||||
vega_volume_discount_tier_2,
|
||||
vega_referral_discount_tier_1,
|
||||
vega_referral_discount_tier_2,
|
||||
vega_referral_and_volume_discount,
|
||||
):
|
||||
if discount_program == "volume":
|
||||
return vega_volume_discount_tier_1 if tier == 1 else vega_volume_discount_tier_2
|
||||
elif discount_program == "referral":
|
||||
return (
|
||||
vega_referral_discount_tier_1
|
||||
if tier == 1
|
||||
else vega_referral_discount_tier_2
|
||||
)
|
||||
elif discount_program == "combo":
|
||||
return vega_referral_and_volume_discount
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth(vega_instance, page):
|
||||
return auth_setup(vega_instance, page)
|
||||
|
||||
|
||||
def setup_market_with_volume_discount_program(vega: VegaServiceNull, tier: int):
|
||||
market = setup_continuous_market(vega, custom_quantum=100000)
|
||||
vega.update_volume_discount_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"volume_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"volume_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
window_length=7,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
order_count = 2 if tier == 1 else 3
|
||||
for _ in range(order_count):
|
||||
submit_order(vega, "Key 1", market, "SIDE_BUY", 1, 110)
|
||||
forward_time(vega, True if _ < order_count - 1 else False)
|
||||
|
||||
return market
|
||||
|
||||
|
||||
def setup_market_with_referral_discount_program(vega: VegaServiceNull, tier: int):
|
||||
market = setup_continuous_market(vega, custom_quantum=100000)
|
||||
vega.update_referral_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"minimum_epochs": 1,
|
||||
"referral_reward_factor": 0.1,
|
||||
"referral_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"minimum_epochs": 2,
|
||||
"referral_reward_factor": 0.2,
|
||||
"referral_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
staking_tiers=[
|
||||
{"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1},
|
||||
{"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2},
|
||||
],
|
||||
window_length=1,
|
||||
)
|
||||
vega.create_referral_set(key_name=MM_WALLET.name)
|
||||
next_epoch(vega=vega)
|
||||
referral_set_id = list(vega.list_referral_sets().keys())[0]
|
||||
vega.apply_referral_code(key_name="Key 1", id=referral_set_id)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
order_count = 2
|
||||
order_size = 1 if tier == 1 else 2
|
||||
for _ in range(order_count):
|
||||
submit_order(vega, "Key 1", market, "SIDE_BUY", order_size, 110)
|
||||
forward_time(vega, True if _ < order_count - 1 else False)
|
||||
|
||||
return market
|
||||
|
||||
|
||||
def setup_combined_market(vega: VegaServiceNull):
|
||||
market = setup_continuous_market(vega, custom_quantum=100000)
|
||||
vega.update_volume_discount_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"volume_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"volume_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
window_length=7,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
vega.update_referral_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"minimum_epochs": 1,
|
||||
"referral_reward_factor": 0.1,
|
||||
"referral_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"minimum_epochs": 2,
|
||||
"referral_reward_factor": 0.2,
|
||||
"referral_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
staking_tiers=[
|
||||
{"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1},
|
||||
{"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2},
|
||||
],
|
||||
window_length=1,
|
||||
)
|
||||
vega.create_referral_set(key_name=MM_WALLET.name)
|
||||
next_epoch(vega=vega)
|
||||
referral_set_id = list(vega.list_referral_sets().keys())[0]
|
||||
vega.apply_referral_code(key_name="Key 1", id=referral_set_id)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
order_count = 2
|
||||
order_size = 2
|
||||
for _ in range(order_count):
|
||||
submit_order(vega, "Key 1", market, "SIDE_BUY", order_size, 110)
|
||||
forward_time(vega, True if _ < order_count - 1 else False)
|
||||
return market
|
||||
|
||||
|
||||
def set_market_volume_discount(vega, tier, discount_program, market_ids):
|
||||
market_id_key = f"tier_{tier}_{discount_program}"
|
||||
if discount_program == "combo":
|
||||
market_id_key = "combo"
|
||||
|
||||
market_id = market_ids.get(market_id_key, "default_id")
|
||||
|
||||
print(f"Checking if market exists: {market_id}")
|
||||
if not market_exists(vega, market_id):
|
||||
print(
|
||||
f"Market doesn't exist for {discount_program} tier {tier}. Setting up new market."
|
||||
)
|
||||
|
||||
if discount_program == "volume":
|
||||
market_id = setup_market_with_volume_discount_program(vega, tier)
|
||||
elif discount_program == "referral":
|
||||
market_id = setup_market_with_referral_discount_program(vega, tier)
|
||||
elif discount_program == "combo":
|
||||
market_id = setup_combined_market(vega)
|
||||
|
||||
market_ids[market_id_key] = market_id
|
||||
|
||||
print(f"Using market ID: {market_id}")
|
||||
return market_ids
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, expected_text",
|
||||
[
|
||||
(1, "volume", "9.045%-9.045%"),
|
||||
(2, "volume", "8.04%-8.04%"),
|
||||
(1, "referral", "9.045%-9.045%"),
|
||||
(2, "referral", "8.04%-8.04%"),
|
||||
(2, "combo", "6.432%-6.432%"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fees_page_discount_program_my_trading_fees(
|
||||
tier, expected_text, discount_program, vega_instance, page: Page, market_ids
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text(expected_text)
|
||||
expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text(
|
||||
"Total fee before discount10.05%-10.05%"
|
||||
)
|
||||
expect(page.get_by_test_id(INFRASTRUCTURE_FEES)).to_have_text("Infrastructure0.05%")
|
||||
expect(page.get_by_test_id(MAKER_FEES)).to_have_text("Maker10%")
|
||||
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, volume_discount, total_discount, referral_discount",
|
||||
[
|
||||
(1, "volume", "Volume discount10%", "10%", "Referral discount0%"),
|
||||
(2, "volume", "Volume discount20%", "20%", "Referral discount0%"),
|
||||
(1, "referral", "Volume discount0%", "10%", "Referral discount10%"),
|
||||
(2, "referral", "Volume discount0%", "20%", "Referral discount20%"),
|
||||
(2, "combo", "Volume discount20%", "36%", "Referral discount20%"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fees_page_discount_program_total_discount(
|
||||
tier,
|
||||
discount_program,
|
||||
volume_discount,
|
||||
referral_discount,
|
||||
total_discount,
|
||||
vega_instance,
|
||||
page: Page,
|
||||
market_ids,
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text(total_discount)
|
||||
expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text(volume_discount)
|
||||
expect(page.get_by_test_id(REFERRAL_DISCOUNT_ROW)).to_have_text(referral_discount)
|
||||
page.get_by_test_id(TOTAL_DISCOUNT).hover()
|
||||
expect(page.get_by_test_id(TOOLTIP_CONTENT).nth(0)).to_have_text(
|
||||
"The total discount is calculated according to the following formula: 1 - (1 - dvolume) ⋇ (1 - dreferral)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, past_epochs_volume, required_for_next_tier",
|
||||
[(1, "volume", "103", "97"), (2, "volume", "206", "")],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fees_page_volume_discount_program_my_current_volume(
|
||||
tier,
|
||||
discount_program,
|
||||
past_epochs_volume,
|
||||
required_for_next_tier,
|
||||
vega_instance,
|
||||
page: Page,
|
||||
market_ids,
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(PAST_EPOCHS_VOLUME)).to_have_text(past_epochs_volume)
|
||||
|
||||
if tier == 1:
|
||||
expect(page.get_by_test_id(REQUIRED_FOR_NEXT_TIER)).to_have_text(
|
||||
required_for_next_tier
|
||||
)
|
||||
else:
|
||||
expect(page.get_by_test_id(REQUIRED_FOR_NEXT_TIER)).not_to_be_visible()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, notional_taker_volume, epochs_in_set",
|
||||
[(1, "referral", "103", "1"), (2, "referral", "207", "1")],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fees_page_referral_discount_program_referral_benefits(
|
||||
tier,
|
||||
vega_instance,
|
||||
discount_program,
|
||||
notional_taker_volume,
|
||||
epochs_in_set,
|
||||
page: Page,
|
||||
market_ids,
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(RUNNING_NOTIONAL_TAKER_VOLUME)).to_have_text(
|
||||
notional_taker_volume
|
||||
)
|
||||
expect(page.get_by_test_id(EPOCHS_IN_REFERRAL_SET)).to_have_text(epochs_in_set)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, my_volume_test_id, my_volume_value, your_tier",
|
||||
[
|
||||
(1, "volume", "my-volume-value-0", "103", "your-volume-tier-0"),
|
||||
(2, "volume", "my-volume-value-1", "206", "your-volume-tier-1"),
|
||||
(1, "referral", "my-volume-value-0", "103", "your-referral-tier-0"),
|
||||
(2, "referral", "my-volume-value-1", "206", "your-referral-tier-1"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fees_page_discount_program_discount(
|
||||
tier,
|
||||
discount_program,
|
||||
my_volume_test_id,
|
||||
my_volume_value,
|
||||
your_tier,
|
||||
vega_instance,
|
||||
page: Page,
|
||||
market_ids,
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1")
|
||||
expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_0)).to_have_text("10%")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_1)).to_have_text("20%")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_0)).to_have_text("100")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_1)).to_have_text("200")
|
||||
|
||||
if discount_program == "volume":
|
||||
expect(page.get_by_test_id(my_volume_test_id)).to_have_text(my_volume_value)
|
||||
else:
|
||||
expect(page.get_by_test_id(REQUIRED_EPOCHS_VALUE_0)).to_have_text("1")
|
||||
expect(page.get_by_test_id(REQUIRED_EPOCHS_VALUE_1)).to_have_text("2")
|
||||
|
||||
expect(page.get_by_test_id(your_tier).nth(1)).to_be_visible()
|
||||
expect(page.get_by_test_id(your_tier).nth(1)).to_have_text("Your tier")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, fees_after_discount",
|
||||
[
|
||||
(1, "volume", "9.045%"),
|
||||
(2, "volume", "8.04%"),
|
||||
(1, "referral", "9.045%"),
|
||||
(2, "referral", "8.04%"),
|
||||
(2, "combo", "6.432%"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fees_page_discount_program_fees_by_market(
|
||||
tier, discount_program, fees_after_discount, vega_instance, page: Page, market_ids
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
page.goto("/#/fees")
|
||||
pinned = page.locator(PINNED_ROW_LOCATOR)
|
||||
row = page.locator(ROW_LOCATOR)
|
||||
expect(pinned.locator(COL_CODE)).to_have_text("BTC:DAI_2023Futr")
|
||||
expect(row.locator(COL_FEE_AFTER_DISCOUNT)).to_have_text(fees_after_discount)
|
||||
expect(row.locator(COL_INFRA_FEE)).to_have_text("0.05%")
|
||||
expect(row.locator(COL_MAKER_FEE)).to_have_text("10%")
|
||||
expect(row.locator(COL_LIQUIDITY_FEE)).to_have_text("0%")
|
||||
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, discount, discount_value, total_fee",
|
||||
[
|
||||
(1, "volume", "-10%", "-0.01005 tDAI", "0.09045 tDAI"),
|
||||
(2, "volume", "-20%", "-0.0201 tDAI", "0.0804 tDAI"),
|
||||
(1, "referral", "-10%", "-0.01005 tDAI", "0.09045 tDAI"),
|
||||
(2, "referral", "-20%", "-0.0201 tDAI", "0.0804 tDAI"),
|
||||
(2, "combo", "-36%", "-0.03618 tDAI", "0.06432 tDAI"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_deal_ticket_discount_program(
|
||||
tier,
|
||||
discount_program,
|
||||
discount,
|
||||
discount_value,
|
||||
total_fee,
|
||||
vega_instance,
|
||||
page: Page,
|
||||
market_ids,
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
market_id_key = f"tier_{tier}_{discount_program}"
|
||||
if discount_program == "combo":
|
||||
market_id_key = "combo"
|
||||
market_id = market_ids.get(market_id_key)
|
||||
page.goto(f"/#/markets/{market_id}")
|
||||
page.get_by_test_id(ORDER_SIZE).fill("1")
|
||||
page.get_by_test_id(ORDER_PRICE).fill("1")
|
||||
expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text(discount)
|
||||
page.get_by_test_id(FEES_TEXT).hover()
|
||||
tooltip = page.get_by_test_id(TOOLTIP_CONTENT).first
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_FACTOR)).to_have_text("0.05%")
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_VALUE)).to_have_text("0.0005 tDAI")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_FACTOR)).to_have_text("0%")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_VALUE)).to_have_text("0.00 tDAI")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_FACTOR)).to_have_text("10%")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_VALUE)).to_have_text("0.10 tDAI")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_FACTOR)).to_have_text("10.05%")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_VALUE)).to_have_text("0.1005 tDAI")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_FACTOR)).to_have_text(discount)
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_VALUE)).to_have_text(discount_value)
|
||||
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text(total_fee)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, fee, fee_discount, price_1, size",
|
||||
[
|
||||
(1, "volume", "9.36158 tDAI", "1.04017 tDAI", "103.50 tDAI", "+1"),
|
||||
(2, "volume", "8.3214 tDAI", "2.08035 tDAI", "103.50 tDAI", "+1"),
|
||||
(
|
||||
1,
|
||||
"referral",
|
||||
"8.42543 tDAI ",
|
||||
"1.04017 tDAI",
|
||||
"103.50 tDAI",
|
||||
"+1",
|
||||
),
|
||||
(
|
||||
2,
|
||||
"referral",
|
||||
"13.31424 tDAI",
|
||||
"4.1607 tDAI",
|
||||
"207.00 tDAI",
|
||||
"+2",
|
||||
),
|
||||
(2, "combo", "10.6514 tDAI ", "7.48926 tDAI", "207.00 tDAI", "+2"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fills_taker_discount_program(
|
||||
tier,
|
||||
discount_program,
|
||||
fee,
|
||||
fee_discount,
|
||||
price_1,
|
||||
size,
|
||||
vega_instance,
|
||||
page: Page,
|
||||
market_ids,
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
market_id_key = f"tier_{tier}_{discount_program}"
|
||||
if discount_program == "combo":
|
||||
market_id_key = "combo"
|
||||
market_id = market_ids.get(market_id_key)
|
||||
page.goto(f"/#/markets/{market_id}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text(size)
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text(price_1)
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Taker")
|
||||
expect(row.locator(COL_FEE)).to_have_text(fee)
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text(fee_discount)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, fee, fee_discount, size, price_1",
|
||||
[
|
||||
(1, "volume", "-9.315 tDAI", "1.035 tDAI", "-1", "103.50 tDAI"),
|
||||
(2, "volume", "-8.28 tDAI", "2.07 tDAI", "-1", "103.50 tDAI"),
|
||||
(1, "referral", "-8.3835 tDAI", "1.035 tDAI", "-1", "103.50 tDAI"),
|
||||
(2, "referral", "-13.248 tDAI", "4.14 tDAI", "-2", "207.00 tDAI"),
|
||||
(2, "combo", "-10.5984 tDAI ", "7.452 tDAI", "-2", "207.00 tDAI"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fills_maker_discount_program(
|
||||
tier,
|
||||
discount_program,
|
||||
vega_instance,
|
||||
fee,
|
||||
fee_discount,
|
||||
size,
|
||||
price_1,
|
||||
page: Page,
|
||||
market_ids,
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
market_id_key = f"tier_{tier}_{discount_program}"
|
||||
if discount_program == "combo":
|
||||
market_id_key = "combo"
|
||||
market_id = market_ids.get(market_id_key)
|
||||
page.goto(f"/#/markets/{market_id}")
|
||||
change_keys(page, vega_instance, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text(size)
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text(price_1)
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Maker")
|
||||
expect(row.locator(COL_FEE)).to_have_text(fee)
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text(fee_discount)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, fee",
|
||||
[
|
||||
(1, "volume", "9.315"),
|
||||
(2, "volume", "8.28"),
|
||||
(1, "referral", "8.3835"),
|
||||
(2, "referral", "13.248"),
|
||||
(2, "combo", "10.5984"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fills_maker_fee_tooltip_discount_program(
|
||||
tier, discount_program, fee, vega_instance, page: Page, market_ids
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
market_id_key = f"tier_{tier}_{discount_program}"
|
||||
if discount_program == "combo":
|
||||
market_id_key = "combo"
|
||||
market_id = market_ids.get(market_id_key)
|
||||
page.goto(f"/#/markets/{market_id}")
|
||||
change_keys(page, vega_instance, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
f"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-{fee} tDAITotal fees-{fee} tDAI"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tier, discount_program, maker_fee, total_fee, infra_fee",
|
||||
[
|
||||
(1, "volume", "9.315", "9.36158", "0.04658"),
|
||||
(2, "volume", "8.28", "8.3214", "0.0414"),
|
||||
(1, "referral", "8.3835", "8.42543", "0.04193"),
|
||||
(2, "referral", "13.248", "13.31424", "0.06624"),
|
||||
(2, "combo", "10.5984", "10.6514", "0.053"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("risk_accepted", "auth", "market_ids")
|
||||
def test_fills_taker_fee_tooltip_discount_program(
|
||||
tier,
|
||||
discount_program,
|
||||
vega_instance,
|
||||
maker_fee,
|
||||
total_fee,
|
||||
infra_fee,
|
||||
page: Page,
|
||||
market_ids,
|
||||
):
|
||||
market_ids = set_market_volume_discount(
|
||||
vega_instance, tier, discount_program, market_ids
|
||||
)
|
||||
market_id_key = f"tier_{tier}_{discount_program}"
|
||||
if discount_program == "combo":
|
||||
market_id_key = "combo"
|
||||
market_id = market_ids.get(market_id_key)
|
||||
page.goto(f"/#/markets/{market_id}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
f"If the market was activeFees to be paid by the taker; discounts are already applied.Infrastructure fee{infra_fee} tDAILiquidity fee0.00 tDAIMaker fee{maker_fee} tDAITotal fees{total_fee} tDAI"
|
||||
)
|
||||
@@ -0,0 +1,216 @@
|
||||
import pytest
|
||||
from fees_test_ids import *
|
||||
from playwright.sync_api import Page, expect
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
from actions.vega import submit_order
|
||||
from wallet_config import MM_WALLET
|
||||
from conftest import (
|
||||
init_vega,
|
||||
init_page,
|
||||
auth_setup,
|
||||
risk_accepted_setup,
|
||||
cleanup_container,
|
||||
)
|
||||
from actions.utils import next_epoch, change_keys, forward_time
|
||||
from fixtures.market import setup_continuous_market
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(
|
||||
lambda: cleanup_container(vega_instance)
|
||||
)
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
yield page
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_combined_market(vega: VegaServiceNull):
|
||||
market = setup_continuous_market(vega, custom_quantum=100000)
|
||||
vega.update_volume_discount_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"volume_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"volume_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
window_length=7,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
vega.update_referral_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"minimum_epochs": 1,
|
||||
"referral_reward_factor": 0.1,
|
||||
"referral_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"minimum_epochs": 2,
|
||||
"referral_reward_factor": 0.2,
|
||||
"referral_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
staking_tiers=[
|
||||
{"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1},
|
||||
{"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2},
|
||||
],
|
||||
window_length=1,
|
||||
)
|
||||
vega.create_referral_set(key_name=MM_WALLET.name)
|
||||
next_epoch(vega=vega)
|
||||
referral_set_id = list(vega.list_referral_sets().keys())[0]
|
||||
vega.apply_referral_code(key_name="Key 1", id=referral_set_id)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
for _ in range(2):
|
||||
submit_order(vega, "Key 1", market, "SIDE_BUY", 2, 110)
|
||||
forward_time(vega, True if _ < 2 - 1 else False)
|
||||
return market
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
|
||||
def test_fees_page_discount_program_my_trading_fees(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("6.432%-6.432%")
|
||||
expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text(
|
||||
"Total fee before discount10.05%-10.05%"
|
||||
)
|
||||
expect(page.get_by_test_id(INFRASTRUCTURE_FEES)).to_have_text("Infrastructure0.05%")
|
||||
expect(page.get_by_test_id(MAKER_FEES)).to_have_text("Maker10%")
|
||||
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
|
||||
def test_fees_page_discount_program_total_discount(
|
||||
page: Page,
|
||||
):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("36%")
|
||||
expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount20%")
|
||||
expect(page.get_by_test_id(REFERRAL_DISCOUNT_ROW)).to_have_text(
|
||||
"Referral discount20%"
|
||||
)
|
||||
page.get_by_test_id(TOTAL_DISCOUNT).hover()
|
||||
expect(page.get_by_test_id(TOOLTIP_CONTENT).nth(0)).to_have_text(
|
||||
"The total discount is calculated according to the following formula: 1 - (1 - dvolume) ⋇ (1 - dreferral)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
|
||||
def test_fees_page_discount_program_fees_by_market(page: Page):
|
||||
page.goto("/#/fees")
|
||||
pinned = page.locator(PINNED_ROW_LOCATOR)
|
||||
row = page.locator(ROW_LOCATOR)
|
||||
expect(pinned.locator(COL_CODE)).to_have_text("BTC:DAI_2023Futr")
|
||||
expect(row.locator(COL_FEE_AFTER_DISCOUNT)).to_have_text("6.432%")
|
||||
expect(row.locator(COL_INFRA_FEE)).to_have_text("0.05%")
|
||||
expect(row.locator(COL_MAKER_FEE)).to_have_text("10%")
|
||||
expect(row.locator(COL_LIQUIDITY_FEE)).to_have_text("0%")
|
||||
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
|
||||
def test_deal_ticket_discount_program(
|
||||
page: Page,
|
||||
setup_combined_market,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_combined_market}")
|
||||
page.get_by_test_id(ORDER_SIZE).fill("1")
|
||||
page.get_by_test_id(ORDER_PRICE).fill("1")
|
||||
expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-36%")
|
||||
page.get_by_test_id(FEES_TEXT).hover()
|
||||
tooltip = page.get_by_test_id(TOOLTIP_CONTENT).first
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_FACTOR)).to_have_text("0.05%")
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_VALUE)).to_have_text("0.0005 tDAI")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_FACTOR)).to_have_text("0%")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_VALUE)).to_have_text("0.00 tDAI")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_FACTOR)).to_have_text("10%")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_VALUE)).to_have_text("0.10 tDAI")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_FACTOR)).to_have_text("10.05%")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_VALUE)).to_have_text("0.1005 tDAI")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_FACTOR)).to_have_text("-36%")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_VALUE)).to_have_text("-0.03618 tDAI")
|
||||
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.06432 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
|
||||
def test_fills_taker_discount_program(
|
||||
page: Page,
|
||||
setup_combined_market,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_combined_market}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("+2")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("207.00 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Taker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("10.6514 tDAI")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("7.48926 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
|
||||
def test_fills_maker_discount_program(
|
||||
vega: VegaServiceNull,
|
||||
page: Page,
|
||||
setup_combined_market,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_combined_market}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("-2")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("207.00 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Maker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("-10.5984 tDAI")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("7.452 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
|
||||
def test_fills_maker_fee_tooltip_discount_program(
|
||||
vega: VegaServiceNull, page: Page, setup_combined_market
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_combined_market}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-10.5984 tDAITotal fees-10.5984 tDAI"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
|
||||
def test_fills_taker_fee_tooltip_discount_program(
|
||||
page: Page,
|
||||
setup_combined_market,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_combined_market}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-10.5984 tDAITotal fees-10.5984 tDAI"
|
||||
)
|
||||
@@ -0,0 +1,221 @@
|
||||
import pytest
|
||||
from fees_test_ids import *
|
||||
from playwright.sync_api import Page, expect
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
from actions.vega import submit_order
|
||||
from wallet_config import MM_WALLET
|
||||
from conftest import (
|
||||
init_vega,
|
||||
init_page,
|
||||
auth_setup,
|
||||
risk_accepted_setup,
|
||||
cleanup_container,
|
||||
)
|
||||
from actions.utils import next_epoch, change_keys, forward_time
|
||||
from fixtures.market import setup_continuous_market
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(
|
||||
lambda: cleanup_container(vega_instance)
|
||||
)
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
yield page
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_market_with_referral_discount_program(vega: VegaServiceNull):
|
||||
market = setup_continuous_market(vega, custom_quantum=100000)
|
||||
vega.update_referral_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"minimum_epochs": 1,
|
||||
"referral_reward_factor": 0.1,
|
||||
"referral_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"minimum_epochs": 2,
|
||||
"referral_reward_factor": 0.2,
|
||||
"referral_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
staking_tiers=[
|
||||
{"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1},
|
||||
{"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2},
|
||||
],
|
||||
window_length=1,
|
||||
)
|
||||
vega.create_referral_set(key_name=MM_WALLET.name)
|
||||
next_epoch(vega=vega)
|
||||
referral_set_id = list(vega.list_referral_sets().keys())[0]
|
||||
vega.apply_referral_code(key_name="Key 1", id=referral_set_id)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
for _ in range(2):
|
||||
submit_order(vega, "Key 1", market, "SIDE_BUY", 1, 110)
|
||||
forward_time(vega, True if _ < 2 - 1 else False)
|
||||
|
||||
return market
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fees_page_discount_program_my_trading_fees(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("9.045%-9.045%")
|
||||
expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text(
|
||||
"Total fee before discount10.05%-10.05%"
|
||||
)
|
||||
expect(page.get_by_test_id(INFRASTRUCTURE_FEES)).to_have_text("Infrastructure0.05%")
|
||||
expect(page.get_by_test_id(MAKER_FEES)).to_have_text("Maker10%")
|
||||
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fees_page_discount_program_total_discount(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("10%")
|
||||
expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount0%")
|
||||
expect(page.get_by_test_id(REFERRAL_DISCOUNT_ROW)).to_have_text(
|
||||
"Referral discount10%"
|
||||
)
|
||||
page.get_by_test_id(TOTAL_DISCOUNT).hover()
|
||||
expect(page.get_by_test_id(TOOLTIP_CONTENT).nth(0)).to_have_text(
|
||||
"The total discount is calculated according to the following formula: 1 - (1 - dvolume) ⋇ (1 - dreferral)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fees_page_referral_discount_program_referral_benefits(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(RUNNING_NOTIONAL_TAKER_VOLUME)).to_have_text("103")
|
||||
expect(page.get_by_test_id(EPOCHS_IN_REFERRAL_SET)).to_have_text("1")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fees_page_discount_program_discount(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1")
|
||||
expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_0)).to_have_text("10%")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_1)).to_have_text("20%")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_0)).to_have_text("100")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_1)).to_have_text("200")
|
||||
|
||||
expect(page.get_by_test_id(REQUIRED_EPOCHS_VALUE_0)).to_have_text("1")
|
||||
expect(page.get_by_test_id(REQUIRED_EPOCHS_VALUE_1)).to_have_text("2")
|
||||
|
||||
expect(page.get_by_test_id("your-referral-tier-0").nth(1)).to_be_visible()
|
||||
expect(page.get_by_test_id("your-referral-tier-0").nth(1)).to_have_text("Your tier")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fees_page_discount_program_fees_by_market(page: Page):
|
||||
page.goto("/#/fees")
|
||||
pinned = page.locator(PINNED_ROW_LOCATOR)
|
||||
row = page.locator(ROW_LOCATOR)
|
||||
expect(pinned.locator(COL_CODE)).to_have_text("BTC:DAI_2023Futr")
|
||||
expect(row.locator(COL_FEE_AFTER_DISCOUNT)).to_have_text("9.045%")
|
||||
expect(row.locator(COL_INFRA_FEE)).to_have_text("0.05%")
|
||||
expect(row.locator(COL_MAKER_FEE)).to_have_text("10%")
|
||||
expect(row.locator(COL_LIQUIDITY_FEE)).to_have_text("0%")
|
||||
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_deal_ticket_discount_program(
|
||||
page: Page, setup_market_with_referral_discount_program
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
page.get_by_test_id(ORDER_SIZE).fill("1")
|
||||
page.get_by_test_id(ORDER_PRICE).fill("1")
|
||||
expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-10%")
|
||||
page.get_by_test_id(FEES_TEXT).hover()
|
||||
tooltip = page.get_by_test_id(TOOLTIP_CONTENT).first
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_FACTOR)).to_have_text("0.05%")
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_VALUE)).to_have_text("0.0005 tDAI")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_FACTOR)).to_have_text("0%")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_VALUE)).to_have_text("0.00 tDAI")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_FACTOR)).to_have_text("10%")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_VALUE)).to_have_text("0.10 tDAI")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_FACTOR)).to_have_text("10.05%")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_VALUE)).to_have_text("0.1005 tDAI")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_FACTOR)).to_have_text("-10%")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_VALUE)).to_have_text("-0.01005 tDAI")
|
||||
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.09045 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fills_taker_discount_program(
|
||||
page: Page,
|
||||
setup_market_with_referral_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("+1")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Taker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("8.42543 tDAI")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.04017 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fills_maker_discount_program(
|
||||
vega: VegaServiceNull,
|
||||
page: Page,
|
||||
setup_market_with_referral_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("-1")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Maker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("-8.3835 tDAI")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.035 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fills_maker_fee_tooltip_discount_program(
|
||||
vega: VegaServiceNull, page: Page, setup_market_with_referral_discount_program
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-8.3835 tDAITotal fees-8.3835 tDAI"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
|
||||
def test_fills_taker_fee_tooltip_discount_program(
|
||||
page: Page,
|
||||
setup_market_with_referral_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-8.3835 tDAITotal fees-8.3835 tDAI"
|
||||
)
|
||||
@@ -0,0 +1,222 @@
|
||||
import pytest
|
||||
from fees_test_ids import *
|
||||
from playwright.sync_api import Page, expect
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
from actions.vega import submit_order
|
||||
from wallet_config import MM_WALLET
|
||||
from conftest import (
|
||||
init_vega,
|
||||
init_page,
|
||||
auth_setup,
|
||||
risk_accepted_setup,
|
||||
cleanup_container,
|
||||
)
|
||||
from actions.utils import next_epoch, change_keys, forward_time
|
||||
from fixtures.market import setup_continuous_market
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(
|
||||
lambda: cleanup_container(vega_instance)
|
||||
)
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
yield page
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_market_with_referral_discount_program(vega: VegaServiceNull):
|
||||
market = setup_continuous_market(vega, custom_quantum=100000)
|
||||
vega.update_referral_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"minimum_epochs": 1,
|
||||
"referral_reward_factor": 0.1,
|
||||
"referral_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"minimum_epochs": 2,
|
||||
"referral_reward_factor": 0.2,
|
||||
"referral_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
staking_tiers=[
|
||||
{"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1},
|
||||
{"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2},
|
||||
],
|
||||
window_length=1,
|
||||
)
|
||||
vega.create_referral_set(key_name=MM_WALLET.name)
|
||||
next_epoch(vega=vega)
|
||||
referral_set_id = list(vega.list_referral_sets().keys())[0]
|
||||
vega.apply_referral_code(key_name="Key 1", id=referral_set_id)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
for _ in range(2):
|
||||
submit_order(vega, "Key 1", market, "SIDE_BUY", 2, 110)
|
||||
forward_time(vega, True if _ < 2 - 1 else False)
|
||||
|
||||
return market
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fees_page_discount_program_my_trading_fees(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("8.04%-8.04%")
|
||||
expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text(
|
||||
"Total fee before discount10.05%-10.05%"
|
||||
)
|
||||
expect(page.get_by_test_id(INFRASTRUCTURE_FEES)).to_have_text("Infrastructure0.05%")
|
||||
expect(page.get_by_test_id(MAKER_FEES)).to_have_text("Maker10%")
|
||||
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fees_page_discount_program_total_discount(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("20%")
|
||||
expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount0%")
|
||||
expect(page.get_by_test_id(REFERRAL_DISCOUNT_ROW)).to_have_text(
|
||||
"Referral discount20%"
|
||||
)
|
||||
page.get_by_test_id(TOTAL_DISCOUNT).hover()
|
||||
expect(page.get_by_test_id(TOOLTIP_CONTENT).nth(0)).to_have_text(
|
||||
"The total discount is calculated according to the following formula: 1 - (1 - dvolume) ⋇ (1 - dreferral)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fees_page_referral_discount_program_referral_benefits(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(RUNNING_NOTIONAL_TAKER_VOLUME)).to_have_text("207")
|
||||
expect(page.get_by_test_id(REQUIRED_FOR_NEXT_TIER)).not_to_be_visible()
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fees_page_discount_program_discount(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1")
|
||||
expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_0)).to_have_text("10%")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_1)).to_have_text("20%")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_0)).to_have_text("100")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_1)).to_have_text("200")
|
||||
|
||||
expect(page.get_by_test_id(REQUIRED_EPOCHS_VALUE_0)).to_have_text("1")
|
||||
expect(page.get_by_test_id(REQUIRED_EPOCHS_VALUE_1)).to_have_text("2")
|
||||
|
||||
expect(page.get_by_test_id("your-referral-tier-1").nth(1)).to_be_visible()
|
||||
expect(page.get_by_test_id("your-referral-tier-1").nth(1)).to_have_text("Your tier")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fees_page_discount_program_fees_by_market(page: Page):
|
||||
page.goto("/#/fees")
|
||||
pinned = page.locator(PINNED_ROW_LOCATOR)
|
||||
row = page.locator(ROW_LOCATOR)
|
||||
expect(pinned.locator(COL_CODE)).to_have_text("BTC:DAI_2023Futr")
|
||||
expect(row.locator(COL_FEE_AFTER_DISCOUNT)).to_have_text("8.04%")
|
||||
expect(row.locator(COL_INFRA_FEE)).to_have_text("0.05%")
|
||||
expect(row.locator(COL_MAKER_FEE)).to_have_text("10%")
|
||||
expect(row.locator(COL_LIQUIDITY_FEE)).to_have_text("0%")
|
||||
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_deal_ticket_discount_program(
|
||||
page: Page, setup_market_with_referral_discount_program
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
page.get_by_test_id(ORDER_SIZE).fill("1")
|
||||
page.get_by_test_id(ORDER_PRICE).fill("1")
|
||||
expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-20%")
|
||||
page.get_by_test_id(FEES_TEXT).hover()
|
||||
tooltip = page.get_by_test_id(TOOLTIP_CONTENT).first
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_FACTOR)).to_have_text("0.05%")
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_VALUE)).to_have_text("0.0005 tDAI")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_FACTOR)).to_have_text("0%")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_VALUE)).to_have_text("0.00 tDAI")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_FACTOR)).to_have_text("10%")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_VALUE)).to_have_text("0.10 tDAI")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_FACTOR)).to_have_text("10.05%")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_VALUE)).to_have_text("0.1005 tDAI")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_FACTOR)).to_have_text("-20%")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_VALUE)).to_have_text("-0.0201 tDAI")
|
||||
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.0804 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fills_taker_discount_program(
|
||||
page: Page,
|
||||
setup_market_with_referral_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("+2")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("207.00 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Taker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("13.31424 tDAI")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("4.1607 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fills_maker_discount_program(
|
||||
vega: VegaServiceNull,
|
||||
page: Page,
|
||||
setup_market_with_referral_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("-2")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("207.00 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Maker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("-13.248 tDAI")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("4.14 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fills_maker_fee_tooltip_discount_program(
|
||||
vega: VegaServiceNull, page: Page, setup_market_with_referral_discount_program
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
" If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-13.248 tDAITotal fees-13.248 tDAI "
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
|
||||
def test_fills_taker_fee_tooltip_discount_program(
|
||||
page: Page,
|
||||
setup_market_with_referral_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_referral_discount_program}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-13.248 tDAITotal fees-13.248 tDAI "
|
||||
)
|
||||
@@ -0,0 +1,210 @@
|
||||
import pytest
|
||||
from fees_test_ids import *
|
||||
from playwright.sync_api import Page, expect
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
from actions.vega import submit_order
|
||||
from wallet_config import MM_WALLET
|
||||
from conftest import (
|
||||
init_vega,
|
||||
init_page,
|
||||
auth_setup,
|
||||
risk_accepted_setup,
|
||||
cleanup_container,
|
||||
)
|
||||
from actions.utils import next_epoch, change_keys, forward_time
|
||||
from fixtures.market import setup_continuous_market
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(
|
||||
lambda: cleanup_container(vega_instance)
|
||||
)
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
yield page
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_market_with_volume_discount_program(vega: VegaServiceNull):
|
||||
market = setup_continuous_market(vega, custom_quantum=100000)
|
||||
vega.update_volume_discount_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"volume_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"volume_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
window_length=7,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
for _ in range(2):
|
||||
submit_order(vega, "Key 1", market, "SIDE_BUY", 1, 110)
|
||||
forward_time(vega, True if _ < 2 - 1 else False)
|
||||
return market
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fees_page_discount_program_my_trading_fees(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("9.045%-9.045%")
|
||||
expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text(
|
||||
"Total fee before discount10.05%-10.05%"
|
||||
)
|
||||
expect(page.get_by_test_id(INFRASTRUCTURE_FEES)).to_have_text("Infrastructure0.05%")
|
||||
expect(page.get_by_test_id(MAKER_FEES)).to_have_text("Maker10%")
|
||||
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fees_page_discount_program_total_discount(
|
||||
page: Page,
|
||||
):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("10%")
|
||||
expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount10%")
|
||||
expect(page.get_by_test_id(REFERRAL_DISCOUNT_ROW)).to_have_text(
|
||||
"Referral discount0%"
|
||||
)
|
||||
page.get_by_test_id(TOTAL_DISCOUNT).hover()
|
||||
expect(page.get_by_test_id(TOOLTIP_CONTENT).nth(0)).to_have_text(
|
||||
"The total discount is calculated according to the following formula: 1 - (1 - dvolume) ⋇ (1 - dreferral)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fees_page_volume_discount_program_my_current_volume(
|
||||
page: Page,
|
||||
):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(PAST_EPOCHS_VOLUME)).to_have_text("103")
|
||||
|
||||
expect(page.get_by_test_id(REQUIRED_FOR_NEXT_TIER)).to_have_text("97")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fees_page_discount_program_discount(
|
||||
page: Page,
|
||||
):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1")
|
||||
expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_0)).to_have_text("10%")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_1)).to_have_text("20%")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_0)).to_have_text("100")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_1)).to_have_text("200")
|
||||
expect(page.get_by_test_id("my-volume-value-0")).to_have_text("103")
|
||||
expect(page.get_by_test_id("your-volume-tier-0").nth(1)).to_be_visible()
|
||||
expect(page.get_by_test_id("your-volume-tier-0").nth(1)).to_have_text("Your tier")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fees_page_discount_program_fees_by_market(page: Page):
|
||||
page.goto("/#/fees")
|
||||
pinned = page.locator(PINNED_ROW_LOCATOR)
|
||||
row = page.locator(ROW_LOCATOR)
|
||||
expect(pinned.locator(COL_CODE)).to_have_text("BTC:DAI_2023Futr")
|
||||
expect(row.locator(COL_FEE_AFTER_DISCOUNT)).to_have_text("9.045%")
|
||||
expect(row.locator(COL_INFRA_FEE)).to_have_text("0.05%")
|
||||
expect(row.locator(COL_MAKER_FEE)).to_have_text("10%")
|
||||
expect(row.locator(COL_LIQUIDITY_FEE)).to_have_text("0%")
|
||||
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_deal_ticket_discount_program_testing(
|
||||
page: Page, setup_market_with_volume_discount_program
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
page.get_by_test_id(ORDER_SIZE).fill("1")
|
||||
page.get_by_test_id(ORDER_PRICE).fill("1")
|
||||
expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-10%")
|
||||
page.get_by_test_id(FEES_TEXT).hover()
|
||||
tooltip = page.get_by_test_id(TOOLTIP_CONTENT).first
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_FACTOR)).to_have_text("0.05%")
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_VALUE)).to_have_text("0.0005 tDAI")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_FACTOR)).to_have_text("0%")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_VALUE)).to_have_text("0.00 tDAI")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_FACTOR)).to_have_text("10%")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_VALUE)).to_have_text("0.10 tDAI")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_FACTOR)).to_have_text("10.05%")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_VALUE)).to_have_text("0.1005 tDAI")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_FACTOR)).to_have_text("-10%")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_VALUE)).to_have_text("-0.01005 tDAI")
|
||||
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.09045 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fills_taker_discount_program(
|
||||
page: Page, setup_market_with_volume_discount_program
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("+1")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Taker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("9.36158 tDAI")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.04017 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fills_maker_discount_program(
|
||||
page: Page, setup_market_with_volume_discount_program, vega: VegaServiceNull
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("-1")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Maker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("-9.315 tDAI")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.035 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fills_maker_fee_tooltip_discount_program(
|
||||
vega: VegaServiceNull, page: Page, setup_market_with_volume_discount_program
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-9.315 tDAITotal fees-9.315 tDAI"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_1")
|
||||
def test_fills_taker_fee_tooltip_discount_program(
|
||||
page: Page,
|
||||
setup_market_with_volume_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-9.315 tDAITotal fees-9.315 tDAI"
|
||||
)
|
||||
@@ -0,0 +1,209 @@
|
||||
import pytest
|
||||
from fees_test_ids import *
|
||||
from playwright.sync_api import Page, expect
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
from actions.vega import submit_order
|
||||
from wallet_config import MM_WALLET
|
||||
from conftest import (
|
||||
init_vega,
|
||||
init_page,
|
||||
auth_setup,
|
||||
risk_accepted_setup,
|
||||
cleanup_container,
|
||||
)
|
||||
from actions.utils import next_epoch, change_keys, forward_time
|
||||
from fixtures.market import setup_continuous_market
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(
|
||||
lambda: cleanup_container(vega_instance)
|
||||
)
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
yield page
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_market_with_volume_discount_program(vega: VegaServiceNull):
|
||||
market = setup_continuous_market(vega, custom_quantum=100000)
|
||||
vega.update_volume_discount_program(
|
||||
proposal_key=MM_WALLET.name,
|
||||
benefit_tiers=[
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 100,
|
||||
"volume_discount_factor": 0.1,
|
||||
},
|
||||
{
|
||||
"minimum_running_notional_taker_volume": 200,
|
||||
"volume_discount_factor": 0.2,
|
||||
},
|
||||
],
|
||||
window_length=7,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
for _ in range(3):
|
||||
submit_order(vega, "Key 1", market, "SIDE_BUY", 1, 110)
|
||||
forward_time(vega, True if _ < 3 - 1 else False)
|
||||
|
||||
return market
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fees_page_discount_program_my_trading_fees(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("8.04%-8.04%")
|
||||
expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text(
|
||||
"Total fee before discount10.05%-10.05%"
|
||||
)
|
||||
expect(page.get_by_test_id(INFRASTRUCTURE_FEES)).to_have_text("Infrastructure0.05%")
|
||||
expect(page.get_by_test_id(MAKER_FEES)).to_have_text("Maker10%")
|
||||
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fees_page_discount_program_total_discount(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("20%")
|
||||
expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount20%")
|
||||
expect(page.get_by_test_id(REFERRAL_DISCOUNT_ROW)).to_have_text(
|
||||
"Referral discount0%"
|
||||
)
|
||||
page.get_by_test_id(TOTAL_DISCOUNT).hover()
|
||||
expect(page.get_by_test_id(TOOLTIP_CONTENT).nth(0)).to_have_text(
|
||||
"The total discount is calculated according to the following formula: 1 - (1 - dvolume) ⋇ (1 - dreferral)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fees_page_volume_discount_program_my_current_volume(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(PAST_EPOCHS_VOLUME)).to_have_text("206")
|
||||
expect(page.get_by_test_id(REQUIRED_FOR_NEXT_TIER)).not_to_be_visible()
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fees_page_discount_program_discount(page: Page):
|
||||
page.goto("/#/fees")
|
||||
expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1")
|
||||
expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_0)).to_have_text("10%")
|
||||
expect(page.get_by_test_id(DISCOUNT_VALUE_1)).to_have_text("20%")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_0)).to_have_text("100")
|
||||
expect(page.get_by_test_id(MIN_VOLUME_VALUE_1)).to_have_text("200")
|
||||
expect(page.get_by_test_id("my-volume-value-1")).to_have_text("206")
|
||||
expect(page.get_by_test_id("your-volume-tier-1").nth(1)).to_be_visible()
|
||||
expect(page.get_by_test_id("your-volume-tier-1").nth(1)).to_have_text("Your tier")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fees_page_discount_program_fees_by_market(page: Page):
|
||||
page.goto("/#/fees")
|
||||
pinned = page.locator(PINNED_ROW_LOCATOR)
|
||||
row = page.locator(ROW_LOCATOR)
|
||||
expect(pinned.locator(COL_CODE)).to_have_text("BTC:DAI_2023Futr")
|
||||
expect(row.locator(COL_FEE_AFTER_DISCOUNT)).to_have_text("8.04%")
|
||||
expect(row.locator(COL_INFRA_FEE)).to_have_text("0.05%")
|
||||
expect(row.locator(COL_MAKER_FEE)).to_have_text("10%")
|
||||
expect(row.locator(COL_LIQUIDITY_FEE)).to_have_text("0%")
|
||||
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_deal_ticket_discount_program(
|
||||
page: Page,
|
||||
setup_market_with_volume_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
page.get_by_test_id(ORDER_SIZE).fill("1")
|
||||
page.get_by_test_id(ORDER_PRICE).fill("1")
|
||||
expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-20%")
|
||||
page.get_by_test_id(FEES_TEXT).hover()
|
||||
tooltip = page.get_by_test_id(TOOLTIP_CONTENT).first
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_FACTOR)).to_have_text("0.05%")
|
||||
expect(tooltip.get_by_test_id(INFRASTRUCTURE_FEE_VALUE)).to_have_text("0.0005 tDAI")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_FACTOR)).to_have_text("0%")
|
||||
expect(tooltip.get_by_test_id(LIQUIDITY_FEE_VALUE)).to_have_text("0.00 tDAI")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_FACTOR)).to_have_text("10%")
|
||||
expect(tooltip.get_by_test_id(MAKER_FEE_VALUE)).to_have_text("0.10 tDAI")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_FACTOR)).to_have_text("10.05%")
|
||||
expect(tooltip.get_by_test_id(SUBTOTAL_FEE_VALUE)).to_have_text("0.1005 tDAI")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_FACTOR)).to_have_text("-20%")
|
||||
expect(tooltip.get_by_test_id(DISCOUNT_FEE_VALUE)).to_have_text("-0.0201 tDAI")
|
||||
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.0804 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fills_taker_discount_program(
|
||||
page: Page,
|
||||
setup_market_with_volume_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("+1")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Taker")
|
||||
expect(row.locator(COL_FEE)).to_have_text(
|
||||
"8.3214 tDAI",
|
||||
)
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("2.08035 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fills_maker_discount_program(
|
||||
vega: VegaServiceNull,
|
||||
page: Page,
|
||||
setup_market_with_volume_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
expect(row.locator(COL_SIZE)).to_have_text("-1")
|
||||
expect(row.locator(COL_PRICE)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_PRICE_1)).to_have_text("103.50 tDAI")
|
||||
expect(row.locator(COL_AGGRESSOR)).to_have_text("Maker")
|
||||
expect(row.locator(COL_FEE)).to_have_text("-8.28 tDAI ")
|
||||
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("2.07 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fills_maker_fee_tooltip_discount_program(
|
||||
vega, page: Page, setup_market_with_volume_discount_program
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
change_keys(page, vega, MM_WALLET.name)
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-8.28 tDAITotal fees-8.28 tDAI"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
|
||||
def test_fills_taker_fee_tooltip_discount_program(
|
||||
page: Page,
|
||||
setup_market_with_volume_discount_program,
|
||||
):
|
||||
page.goto(f"/#/markets/{setup_market_with_volume_discount_program}")
|
||||
page.get_by_test_id(FILLS).click()
|
||||
row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first
|
||||
# tbd - tooltip is not visible without this wait
|
||||
page.wait_for_timeout(1000)
|
||||
row.locator(COL_FEE).hover()
|
||||
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
|
||||
"If the market was activeFee revenue to be received by the maker, takers' fee discounts already applied.During continuous trading the maker pays no infrastructure and liquidity fees.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee-8.28 tDAITotal fees-8.28 tDAI "
|
||||
)
|
||||
@@ -14,7 +14,7 @@ logger = logging.getLogger()
|
||||
@pytest.fixture(scope="class")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@@ -142,8 +142,7 @@ class TestGetStarted:
|
||||
def test_get_started_seen_already(self, simple_market, page: Page):
|
||||
page.goto(f"/#/markets/{simple_market}")
|
||||
get_started_locator = page.get_by_test_id("connect-vega-wallet")
|
||||
page.wait_for_selector(
|
||||
'[data-testid="connect-vega-wallet"]', state="attached")
|
||||
page.wait_for_selector('[data-testid="connect-vega-wallet"]', state="attached")
|
||||
expect(get_started_locator).to_be_enabled
|
||||
expect(get_started_locator).to_be_visible
|
||||
# 0007-FUGS-015
|
||||
@@ -153,7 +152,9 @@ class TestGetStarted:
|
||||
expect(page.get_by_test_id("dialog-content").nth(1)).to_be_visible()
|
||||
|
||||
@pytest.mark.skip("tbd-market-sim")
|
||||
def test_redirect_default_market(self, continuous_market, vega: VegaServiceNull, page: Page):
|
||||
def test_redirect_default_market(
|
||||
self, continuous_market, vega: VegaServiceNull, page: Page
|
||||
):
|
||||
page.goto("/")
|
||||
# 0007-FUGS-012
|
||||
expect(page).to_have_url(
|
||||
|
||||
@@ -8,7 +8,7 @@ from actions.utils import next_epoch, truncate_middle, change_keys
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from actions.utils import next_epoch
|
||||
@pytest.fixture(scope="class")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ market_title_test_id = "accordion-title"
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ col_market_id = '[col-id="market"] [data-testid="stack-cell-primary"]'
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ COL_ID_FEE = ".ag-center-cols-container [col-id='fee'] .ag-cell-value"
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@@ -7,11 +7,10 @@ from conftest import init_page, init_vega, cleanup_container
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
# we can reuse single page instance in all tests
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
|
||||
@@ -15,7 +15,7 @@ def vega(request):
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
yield vega_instance
|
||||
|
||||
|
||||
#
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def markets(vega: VegaServiceNull):
|
||||
market_1 = setup_continuous_market(
|
||||
@@ -49,7 +49,7 @@ def markets(vega: VegaServiceNull):
|
||||
price=130,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -63,7 +63,7 @@ def markets(vega: VegaServiceNull):
|
||||
price=88,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -77,7 +77,7 @@ def markets(vega: VegaServiceNull):
|
||||
price=88,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -92,7 +92,7 @@ def markets(vega: VegaServiceNull):
|
||||
wait=False,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -105,7 +105,7 @@ def markets(vega: VegaServiceNull):
|
||||
volume=100,
|
||||
price=104,
|
||||
)
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -120,7 +120,7 @@ def markets(vega: VegaServiceNull):
|
||||
expires_at=vega.get_blockchain_time() + 5 * 1e9,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -134,7 +134,7 @@ def markets(vega: VegaServiceNull):
|
||||
volume=20,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -148,7 +148,7 @@ def markets(vega: VegaServiceNull):
|
||||
volume=40,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -162,7 +162,7 @@ def markets(vega: VegaServiceNull):
|
||||
volume=60,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -177,7 +177,7 @@ def markets(vega: VegaServiceNull):
|
||||
volume=60,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.forward("2s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -190,8 +190,7 @@ def markets(vega: VegaServiceNull):
|
||||
volume=10,
|
||||
price=150,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -205,7 +204,6 @@ def markets(vega: VegaServiceNull):
|
||||
price=160,
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -217,9 +215,8 @@ def markets(vega: VegaServiceNull):
|
||||
side="SIDE_BUY",
|
||||
volume=10,
|
||||
price=60,
|
||||
)
|
||||
)
|
||||
|
||||
vega.forward("10s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
@@ -395,7 +392,6 @@ def test_order_amend_order(vega: VegaServiceNull, page: Page):
|
||||
page.get_by_role("button", name="Update").click()
|
||||
|
||||
wait_for_toast_confirmation(page, timeout=5000)
|
||||
vega.forward("10s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
expect(page.locator('[row-index="1"]').first).to_contain_text(
|
||||
@@ -414,7 +410,6 @@ def test_order_cancel_single_order(vega: VegaServiceNull, page: Page):
|
||||
page.get_by_test_id("cancel").first.click()
|
||||
|
||||
wait_for_toast_confirmation(page, timeout=5000)
|
||||
vega.forward("10s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
expect(page.locator('[row-index="0"]').first).to_contain_text(
|
||||
@@ -434,7 +429,6 @@ def test_order_cancel_all_orders(vega: VegaServiceNull, page: Page):
|
||||
page.get_by_test_id("cancelAll").click()
|
||||
|
||||
wait_for_toast_confirmation(page, timeout=5000)
|
||||
vega.forward("10s")
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from wallet_config import MM_WALLET, MM_WALLET2
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class TestPerpetuals:
|
||||
@pytest.fixture(scope="class")
|
||||
def vega(self, request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
|
||||
@@ -12,7 +12,7 @@ COL_ID_USED = ".ag-center-cols-container [col-id='used'] .ag-cell-value"
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ BUY_ORDERS = [[1, 106], [1, 107], [1, 108]]
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ def setup_market_and_referral_scheme(vega: VegaServiceNull, continuous_market: s
|
||||
forward_time(vega)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("page", "auth", "risk_accepted")
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted")
|
||||
def test_can_traverse_up_and_down_through_tiers(continuous_market, vega: VegaServiceNull, page: Page):
|
||||
setup_market_and_referral_scheme(vega, continuous_market, page)
|
||||
change_keys(page, vega, PARTY_B.name)
|
||||
@@ -163,7 +163,7 @@ def test_can_traverse_up_and_down_through_tiers(continuous_market, vega: VegaSer
|
||||
"1%", "1", "1%", "0", "1", "1"))
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("page", "auth", "risk_accepted")
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted")
|
||||
def test_does_not_move_up_tiers_when_not_enough_epochs(continuous_market, vega: VegaServiceNull, page: Page):
|
||||
setup_market_and_referral_scheme(vega, continuous_market, page)
|
||||
change_keys(page, vega, PARTY_B.name)
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
from actions.utils import create_and_faucet_wallet
|
||||
from wallet_config import WalletConfig
|
||||
# region Constants
|
||||
ACTIVITY = "activity"
|
||||
HOARDER = "hoarder"
|
||||
COMBO = "combo"
|
||||
|
||||
REWARDS_URL = "/#/rewards"
|
||||
|
||||
# test IDs
|
||||
COMBINED_MULTIPLIERS = "combined-multipliers"
|
||||
TOTAL_REWARDS = "total-rewards"
|
||||
PRICE_TAKING_COL_ID = '[col-id="priceTaking"]'
|
||||
TOTAL_COL_ID = '[col-id="total"]'
|
||||
ROW = "row"
|
||||
STREAK_REWARD_MULTIPLIER_VALUE = "streak-reward-multiplier-value"
|
||||
HOARDER_REWARD_MULTIPLIER_VALUE = "hoarder-reward-multiplier-value"
|
||||
HOARDER_BONUS_TOTAL_HOARDED = "hoarder-bonus-total-hoarded"
|
||||
EARNED_BY_ME_BUTTON = "earned-by-me-button"
|
||||
TRANSFER_AMOUNT = "transfer-amount"
|
||||
EPOCH_STREAK = "epoch-streak"
|
||||
|
||||
# endregion
|
||||
|
||||
# Keys
|
||||
PARTY_A = "PARTY_A"
|
||||
PARTY_B = "PARTY_B"
|
||||
PARTY_C = "PARTY_C"
|
||||
PARTY_D = "PARTY_D"
|
||||
|
||||
ACTIVITY_STREAKS = """
|
||||
{
|
||||
"tiers": [
|
||||
{
|
||||
"minimum_activity_streak": 2,
|
||||
"reward_multiplier": "2.0",
|
||||
"vesting_multiplier": "1.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
VESTING = """
|
||||
{
|
||||
"tiers": [
|
||||
{
|
||||
"minimum_quantum_balance": "10000000",
|
||||
"reward_multiplier": "2"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
def keys(vega):
|
||||
PARTY_A = WalletConfig("PARTY_A", "PARTY_A")
|
||||
create_and_faucet_wallet(vega=vega, wallet=PARTY_A)
|
||||
PARTY_B = WalletConfig("PARTY_B", "PARTY_B")
|
||||
create_and_faucet_wallet(vega=vega, wallet=PARTY_B)
|
||||
PARTY_C = WalletConfig("PARTY_C", "PARTY_C")
|
||||
create_and_faucet_wallet(vega=vega, wallet=PARTY_C)
|
||||
PARTY_D = WalletConfig("PARTY_D", "PARTY_D")
|
||||
create_and_faucet_wallet(vega=vega, wallet=PARTY_D)
|
||||
return PARTY_A, PARTY_B, PARTY_C, PARTY_D
|
||||
@@ -0,0 +1,121 @@
|
||||
import pytest
|
||||
import vega_sim.proto.vega as vega_protos
|
||||
from rewards_test_ids import *
|
||||
from playwright.sync_api import Page, expect
|
||||
from conftest import init_vega, init_page, auth_setup, risk_accepted_setup, cleanup_container
|
||||
from fixtures.market import setup_continuous_market
|
||||
from actions.utils import next_epoch, change_keys
|
||||
from wallet_config import MM_WALLET
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega, PARTY_B)
|
||||
yield page
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_market_with_reward_program(vega: VegaServiceNull):
|
||||
tDAI_market = setup_continuous_market(vega)
|
||||
PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega)
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.mint(key_name=PARTY_B.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_C.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_A.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_D.name, asset=tDAI_asset_id, amount=100000)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
vega.update_network_parameter(
|
||||
proposal_key=MM_WALLET.name,
|
||||
parameter="rewards.vesting.benefitTiers",
|
||||
new_value=VESTING,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.update_network_parameter(
|
||||
MM_WALLET.name, parameter="reward.asset", new_value=tDAI_asset_id
|
||||
)
|
||||
|
||||
next_epoch(vega=vega)
|
||||
vega.recurring_transfer(
|
||||
from_key_name=PARTY_A.name,
|
||||
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
|
||||
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
asset=tDAI_asset_id,
|
||||
reference="reward",
|
||||
asset_for_metric=tDAI_asset_id,
|
||||
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
|
||||
amount=100,
|
||||
factor=1.0,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_A.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
next_epoch(vega=vega)
|
||||
return tDAI_market, tDAI_asset_id
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_0")
|
||||
def test_network_reward_pot(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("50.00 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_0")
|
||||
def test_reward_multiplier(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("1x")
|
||||
expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text("1x")
|
||||
expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text("1x")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_0")
|
||||
def test_hoarder_bonus(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(HOARDER_BONUS_TOTAL_HOARDED)).to_contain_text(
|
||||
"5,000,000"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_0")
|
||||
def test_reward_history(
|
||||
page: Page,
|
||||
):
|
||||
page.locator('[name="fromEpoch"]').fill("1")
|
||||
expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text(
|
||||
"100.00100.00%"
|
||||
)
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text("100.00")
|
||||
page.get_by_test_id(EARNED_BY_ME_BUTTON).click()
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text("50.00")
|
||||
@@ -0,0 +1,173 @@
|
||||
import pytest
|
||||
from rewards_test_ids import *
|
||||
import vega_sim.proto.vega as vega_protos
|
||||
from playwright.sync_api import Page, expect
|
||||
from conftest import init_vega, init_page, auth_setup, risk_accepted_setup, cleanup_container
|
||||
from fixtures.market import setup_continuous_market
|
||||
from actions.utils import next_epoch, change_keys
|
||||
from wallet_config import MM_WALLET
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega, PARTY_B)
|
||||
yield page
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_market_with_reward_program(vega: VegaServiceNull):
|
||||
tDAI_market = setup_continuous_market(vega)
|
||||
PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega)
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.mint(key_name=PARTY_B.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_C.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_A.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_D.name, asset=tDAI_asset_id, amount=100000)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
vega.update_network_parameter(
|
||||
proposal_key=MM_WALLET.name,
|
||||
parameter="rewards.vesting.benefitTiers",
|
||||
new_value=VESTING,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.update_network_parameter(
|
||||
MM_WALLET.name, parameter="reward.asset", new_value=tDAI_asset_id
|
||||
)
|
||||
|
||||
next_epoch(vega=vega)
|
||||
vega.recurring_transfer(
|
||||
from_key_name=PARTY_A.name,
|
||||
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
|
||||
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
asset=tDAI_asset_id,
|
||||
reference="reward",
|
||||
asset_for_metric=tDAI_asset_id,
|
||||
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
|
||||
amount=100,
|
||||
factor=1.0,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_A.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_LIMIT",
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
side="SIDE_BUY",
|
||||
price=1,
|
||||
volume=1,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_D.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_D.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
return tDAI_market, tDAI_asset_id
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_1")
|
||||
def test_network_reward_pot(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("166.66666 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_1")
|
||||
def test_reward_multiplier(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("2x")
|
||||
expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text("1x")
|
||||
expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text("2x")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_1")
|
||||
def test_hoarder_bonus(page: Page):
|
||||
expect(page.get_by_test_id(HOARDER_BONUS_TOTAL_HOARDED)).to_contain_text(
|
||||
"16,666,666"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_1")
|
||||
def test_reward_history(page: Page):
|
||||
page.locator('[name="fromEpoch"]').fill("1")
|
||||
expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text(
|
||||
"299.99999100.00%"
|
||||
)
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text(
|
||||
"299.99999"
|
||||
)
|
||||
page.get_by_test_id(EARNED_BY_ME_BUTTON).click()
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text(
|
||||
"166.66666"
|
||||
)
|
||||
@@ -1,475 +0,0 @@
|
||||
import pytest
|
||||
|
||||
import vega_sim.proto.vega as vega_protos
|
||||
from playwright.sync_api import Page, expect
|
||||
from conftest import init_vega, init_page, auth_setup, cleanup_container
|
||||
from fixtures.market import setup_continuous_market, market_exists
|
||||
from actions.utils import next_epoch, change_keys
|
||||
from wallet_config import MM_WALLET, PARTY_A, PARTY_B, PARTY_C, PARTY_D
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
|
||||
# region Constants
|
||||
ACTIVITY = "activity"
|
||||
HOARDER = "hoarder"
|
||||
COMBO = "combo"
|
||||
|
||||
REWARDS_URL = "/#/rewards"
|
||||
|
||||
# test IDs
|
||||
COMBINED_MULTIPLIERS = "combined-multipliers"
|
||||
TOTAL_REWARDS = "total-rewards"
|
||||
PRICE_TAKING_COL_ID = '[col-id="priceTaking"]'
|
||||
TOTAL_COL_ID = '[col-id="total"]'
|
||||
ROW = "row"
|
||||
STREAK_REWARD_MULTIPLIER_VALUE = "streak-reward-multiplier-value"
|
||||
HOARDER_REWARD_MULTIPLIER_VALUE = "hoarder-reward-multiplier-value"
|
||||
HOARDER_BONUS_TOTAL_HOARDED = "hoarder-bonus-total-hoarded"
|
||||
EARNED_BY_ME_BUTTON = "earned-by-me-button"
|
||||
TRANSFER_AMOUNT = "transfer-amount"
|
||||
EPOCH_STREAK = "epoch-streak"
|
||||
|
||||
# endregion
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def market_ids():
|
||||
return {
|
||||
"vega_activity_tier_0": "default_id",
|
||||
"vega_hoarder_tier_0": "default_id",
|
||||
"vega_combo_tier_0": "default_id",
|
||||
"vega_activity_tier_1": "default_id",
|
||||
"vega_hoarder_tier_1": "default_id",
|
||||
"vega_combo_tier_1": "default_id",
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_activity_tier_0(request):
|
||||
with init_vega(request) as vega_activity_tier_0:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_activity_tier_0)) # Register the cleanup function
|
||||
yield vega_activity_tier_0
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_hoarder_tier_0(request):
|
||||
with init_vega(request) as vega_hoarder_tier_0:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_hoarder_tier_0)) # Register the cleanup function
|
||||
yield vega_hoarder_tier_0
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_combo_tier_0(request):
|
||||
with init_vega(request) as vega_combo_tier_0:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_combo_tier_0)) # Register the cleanup function
|
||||
yield vega_combo_tier_0
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_activity_tier_1(request):
|
||||
with init_vega(request) as vega_activity_tier_1:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_activity_tier_1)) # Register the cleanup function
|
||||
yield vega_activity_tier_1
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_hoarder_tier_1(request):
|
||||
with init_vega(request) as vega_hoarder_tier_1:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_hoarder_tier_1)) # Register the cleanup function
|
||||
yield vega_hoarder_tier_1
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega_combo_tier_1(request):
|
||||
with init_vega(request) as vega_combo_tier_1:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_combo_tier_1)) # Register the cleanup function
|
||||
yield vega_combo_tier_1
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth(vega_instance, page):
|
||||
return auth_setup(vega_instance, page)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def page(vega_instance, browser, request):
|
||||
with init_page(vega_instance, browser, request) as page_instance:
|
||||
yield page_instance
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vega_instance(
|
||||
reward_program,
|
||||
vega_activity_tier_0,
|
||||
vega_hoarder_tier_0,
|
||||
vega_combo_tier_0,
|
||||
vega_activity_tier_1,
|
||||
vega_hoarder_tier_1,
|
||||
vega_combo_tier_1,
|
||||
tier,
|
||||
):
|
||||
if reward_program == "activity":
|
||||
return vega_activity_tier_0 if tier == 1 else vega_activity_tier_1
|
||||
elif reward_program == "hoarder":
|
||||
return vega_hoarder_tier_0 if tier == 1 else vega_hoarder_tier_1
|
||||
elif reward_program == "combo":
|
||||
return vega_combo_tier_0 if tier == 1 else vega_combo_tier_1
|
||||
|
||||
|
||||
def setup_market_with_reward_program(vega: VegaServiceNull, reward_programs, tier):
|
||||
print(f"Started setup_market_with_{reward_programs}_{tier}")
|
||||
tDAI_market = setup_continuous_market(vega)
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.mint(key_name=PARTY_B.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_C.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_A.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_D.name, asset=tDAI_asset_id, amount=100000)
|
||||
next_epoch(vega=vega)
|
||||
if ACTIVITY in reward_programs:
|
||||
vega.update_network_parameter(
|
||||
proposal_key=MM_WALLET.name,
|
||||
parameter="rewards.activityStreak.benefitTiers",
|
||||
new_value=ACTIVITY_STREAKS,
|
||||
)
|
||||
print("update_network_parameter activity done")
|
||||
next_epoch(vega=vega)
|
||||
|
||||
if HOARDER in reward_programs:
|
||||
vega.update_network_parameter(
|
||||
proposal_key=MM_WALLET.name,
|
||||
parameter="rewards.vesting.benefitTiers",
|
||||
new_value=VESTING,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.update_network_parameter(
|
||||
MM_WALLET.name, parameter="reward.asset", new_value=tDAI_asset_id
|
||||
)
|
||||
|
||||
next_epoch(vega=vega)
|
||||
vega.recurring_transfer(
|
||||
from_key_name=PARTY_A.name,
|
||||
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
|
||||
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
asset=tDAI_asset_id,
|
||||
reference="reward",
|
||||
asset_for_metric=tDAI_asset_id,
|
||||
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
|
||||
# lock_period= 5,
|
||||
# TODO test lock period
|
||||
amount=100,
|
||||
factor=1.0,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_A.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
|
||||
vega.wait_for_total_catchup()
|
||||
if tier == 1:
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_LIMIT",
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
side="SIDE_BUY",
|
||||
price=1,
|
||||
volume=1,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_D.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
if HOARDER in reward_programs:
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_D.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
return tDAI_market, tDAI_asset_id
|
||||
|
||||
|
||||
def set_market_reward_program(vega, reward_program, market_ids, tier):
|
||||
market_id_key = f"vega_{reward_program}_tier_{tier}"
|
||||
if reward_program == COMBO:
|
||||
market_id_key = COMBO
|
||||
market_id = market_ids.get(market_id_key, "default_id")
|
||||
|
||||
print(f"Checking if market exists: {market_id}")
|
||||
if not market_exists(vega, market_id):
|
||||
print(
|
||||
f"Market doesn't exist for {reward_program} {tier}. Setting up new market."
|
||||
)
|
||||
|
||||
reward_programs = [reward_program]
|
||||
if reward_program == COMBO:
|
||||
reward_programs = [ACTIVITY, HOARDER]
|
||||
|
||||
market_id, _ = setup_market_with_reward_program(vega, reward_programs, tier)
|
||||
market_ids[market_id_key] = market_id
|
||||
|
||||
return market_id, market_ids
|
||||
|
||||
|
||||
ACTIVITY_STREAKS = """
|
||||
{
|
||||
"tiers": [
|
||||
{
|
||||
"minimum_activity_streak": 2,
|
||||
"reward_multiplier": "2.0",
|
||||
"vesting_multiplier": "1.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
VESTING = """
|
||||
{
|
||||
"tiers": [
|
||||
{
|
||||
"minimum_quantum_balance": "10000000",
|
||||
"reward_multiplier": "2"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"reward_program, tier, total_rewards",
|
||||
[
|
||||
(ACTIVITY, 0, "50.00 tDAI"),
|
||||
(HOARDER, 0, "50.00 tDAI"),
|
||||
(COMBO, 0, "50.00 tDAI"),
|
||||
(ACTIVITY, 1, "116.66666 tDAI"),
|
||||
(HOARDER, 1, "166.66666 tDAI "),
|
||||
(COMBO, 1, "183.33333 tDAI"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted", "market_ids")
|
||||
def test_network_reward_pot(
|
||||
reward_program,
|
||||
vega_instance: VegaServiceNull,
|
||||
page: Page,
|
||||
total_rewards,
|
||||
tier,
|
||||
market_ids,
|
||||
):
|
||||
print("reward program: " + reward_program, " tier:", tier)
|
||||
market_id, market_ids = set_market_reward_program(
|
||||
vega_instance, reward_program, market_ids, tier
|
||||
)
|
||||
page.goto(REWARDS_URL)
|
||||
|
||||
change_keys(page, vega_instance, PARTY_B.name)
|
||||
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text(total_rewards)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"reward_program, tier, reward_multiplier, streak_multiplier, hoarder_multiplier",
|
||||
[
|
||||
(ACTIVITY, 0, "1x", "1x", "1x"),
|
||||
(HOARDER, 0, "1x", "1x", "1x"),
|
||||
(COMBO, 0, "1x", "1x", "1x"),
|
||||
(ACTIVITY, 1, "2x", "2x", "1x"),
|
||||
(HOARDER, 1, "2x", "1x", "2x"),
|
||||
(COMBO, 1, "4x", "2x", "2x"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted", "market_ids")
|
||||
def test_reward_multiplier(
|
||||
reward_program,
|
||||
vega_instance: VegaServiceNull,
|
||||
page: Page,
|
||||
reward_multiplier,
|
||||
streak_multiplier,
|
||||
hoarder_multiplier,
|
||||
tier,
|
||||
market_ids,
|
||||
):
|
||||
print("reward program: " + reward_program, " tier:", tier)
|
||||
market_id, market_ids = set_market_reward_program(
|
||||
vega_instance, reward_program, market_ids, tier
|
||||
)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega_instance, PARTY_B.name)
|
||||
expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text(reward_multiplier)
|
||||
expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text(
|
||||
streak_multiplier
|
||||
)
|
||||
expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text(
|
||||
hoarder_multiplier
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"reward_program, tier, epoch_streak",
|
||||
[
|
||||
(ACTIVITY, 0, "1"),
|
||||
(ACTIVITY, 1, "7"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted", "market_ids")
|
||||
def test_activity_streak(
|
||||
reward_program,
|
||||
vega_instance: VegaServiceNull,
|
||||
page: Page,
|
||||
epoch_streak,
|
||||
tier,
|
||||
market_ids,
|
||||
):
|
||||
print("reward program: " + reward_program, " tier:", tier)
|
||||
market_id, market_ids = set_market_reward_program(
|
||||
vega_instance, reward_program, market_ids, tier
|
||||
)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega_instance, PARTY_B.name)
|
||||
if tier == 1:
|
||||
expect(page.get_by_test_id(EPOCH_STREAK)).to_have_text(
|
||||
"Active trader: " + epoch_streak + " epochs so far (Tier 1 as of last epoch)"
|
||||
)
|
||||
else:
|
||||
expect(page.get_by_test_id(EPOCH_STREAK)).to_have_text(
|
||||
"Active trader: " + epoch_streak + " epochs so far "
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"reward_program, tier, rewards_hoarded",
|
||||
[
|
||||
(HOARDER, 0, "5,000,000"),
|
||||
(HOARDER, 1, "16,666,666"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted", "market_ids")
|
||||
def test_hoarder_bonus(
|
||||
reward_program,
|
||||
vega_instance: VegaServiceNull,
|
||||
page: Page,
|
||||
rewards_hoarded,
|
||||
tier,
|
||||
market_ids,
|
||||
):
|
||||
print("reward program: " + reward_program, " tier:", tier)
|
||||
market_id, market_ids = set_market_reward_program(
|
||||
vega_instance, reward_program, market_ids, tier
|
||||
)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega_instance, PARTY_B.name)
|
||||
expect(page.get_by_test_id(HOARDER_BONUS_TOTAL_HOARDED)).to_contain_text(
|
||||
rewards_hoarded
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"reward_program, tier, price_taking, total, earned_by_me",
|
||||
[
|
||||
(ACTIVITY, 0, "100.00100.00%", "100.00", "50.00"),
|
||||
(HOARDER, 0, "100.00100.00%", "100.00", "50.00"),
|
||||
(COMBO, 0, "100.00100.00%", "100.00", "50.00"),
|
||||
(ACTIVITY, 1, "300.00100.00%", "300.00", "116.66666"),
|
||||
(HOARDER, 1, "299.99999100.00%", "299.99999", "166.66666"),
|
||||
(COMBO, 1, "299.99999100.00%", "299.99999", "183.33333"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted", "market_ids")
|
||||
def test_reward_history(
|
||||
reward_program,
|
||||
vega_instance: VegaServiceNull,
|
||||
page: Page,
|
||||
price_taking,
|
||||
total,
|
||||
earned_by_me,
|
||||
tier,
|
||||
market_ids,
|
||||
):
|
||||
print("reward program: " + reward_program, " tier:", tier)
|
||||
market_id, market_ids = set_market_reward_program(
|
||||
vega_instance, reward_program, market_ids, tier
|
||||
)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega_instance, PARTY_B.name)
|
||||
page.locator('[name="fromEpoch"]').fill("1")
|
||||
expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text(
|
||||
price_taking
|
||||
)
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text(total)
|
||||
page.get_by_test_id(EARNED_BY_ME_BUTTON).click()
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text(
|
||||
earned_by_me
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"reward_program, tier",
|
||||
[
|
||||
(ACTIVITY, 1),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("auth", "risk_accepted", "market_ids")
|
||||
def test_redeem(
|
||||
reward_program, vega_instance: VegaServiceNull, page: Page, tier, market_ids
|
||||
):
|
||||
print("reward program: " + reward_program, " tier:", tier)
|
||||
market_id, market_ids = set_market_reward_program(
|
||||
vega_instance, reward_program, market_ids, tier
|
||||
)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega_instance, PARTY_B.name)
|
||||
page.get_by_test_id("redeem-rewards-button").click()
|
||||
available_to_withdraw = page.get_by_test_id(
|
||||
"available-to-withdraw-value"
|
||||
).text_content()
|
||||
option_value = page.locator(
|
||||
'[data-testid="transfer-form"] [name="fromAccount"] option[value^="ACCOUNT_TYPE_VESTED_REWARDS"]'
|
||||
).first.get_attribute("value")
|
||||
|
||||
page.select_option(
|
||||
'[data-testid="transfer-form"] [name="fromAccount"]', option_value
|
||||
)
|
||||
|
||||
page.get_by_test_id("use-max-button").first.click()
|
||||
expect(page.get_by_test_id(TRANSFER_AMOUNT)).to_have_text(available_to_withdraw)
|
||||
@@ -1,49 +1,27 @@
|
||||
import pytest
|
||||
from rewards_test_ids import *
|
||||
import vega_sim.proto.vega as vega_protos
|
||||
from playwright.sync_api import Page, expect
|
||||
from conftest import init_vega, init_page, auth_setup, risk_accepted_setup, cleanup_container
|
||||
from conftest import (
|
||||
init_vega,
|
||||
init_page,
|
||||
auth_setup,
|
||||
risk_accepted_setup,
|
||||
cleanup_container,
|
||||
)
|
||||
from fixtures.market import setup_continuous_market
|
||||
from actions.utils import next_epoch, change_keys, create_and_faucet_wallet
|
||||
from wallet_config import MM_WALLET, WalletConfig
|
||||
from actions.utils import next_epoch, change_keys
|
||||
from wallet_config import MM_WALLET
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
|
||||
# region Constants
|
||||
ACTIVITY = "activity"
|
||||
HOARDER = "hoarder"
|
||||
COMBO = "combo"
|
||||
|
||||
REWARDS_URL = "/#/rewards"
|
||||
|
||||
# test IDs
|
||||
COMBINED_MULTIPLIERS = "combined-multipliers"
|
||||
TOTAL_REWARDS = "total-rewards"
|
||||
PRICE_TAKING_COL_ID = '[col-id="priceTaking"]'
|
||||
TOTAL_COL_ID = '[col-id="total"]'
|
||||
ROW = "row"
|
||||
STREAK_REWARD_MULTIPLIER_VALUE = "streak-reward-multiplier-value"
|
||||
HOARDER_REWARD_MULTIPLIER_VALUE = "hoarder-reward-multiplier-value"
|
||||
HOARDER_BONUS_TOTAL_HOARDED = "hoarder-bonus-total-hoarded"
|
||||
EARNED_BY_ME_BUTTON = "earned-by-me-button"
|
||||
TRANSFER_AMOUNT = "transfer-amount"
|
||||
EPOCH_STREAK = "epoch-streak"
|
||||
|
||||
# endregion
|
||||
|
||||
# Keys
|
||||
PARTY_A = "PARTY_A"
|
||||
PARTY_B = "PARTY_B"
|
||||
PARTY_C = "PARTY_C"
|
||||
PARTY_D = "PARTY_D"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
@@ -106,55 +84,31 @@ def setup_market_with_reward_program(vega: VegaServiceNull):
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
next_epoch(vega=vega)
|
||||
return tDAI_market, tDAI_asset_id
|
||||
|
||||
|
||||
ACTIVITY_STREAKS = """
|
||||
{
|
||||
"tiers": [
|
||||
{
|
||||
"minimum_activity_streak": 2,
|
||||
"reward_multiplier": "2.0",
|
||||
"vesting_multiplier": "1.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def keys(vega):
|
||||
PARTY_A = WalletConfig("PARTY_A", "PARTY_A")
|
||||
create_and_faucet_wallet(vega=vega, wallet=PARTY_A)
|
||||
PARTY_B = WalletConfig("PARTY_B", "PARTY_B")
|
||||
create_and_faucet_wallet(vega=vega, wallet=PARTY_B)
|
||||
PARTY_C = WalletConfig("PARTY_C", "PARTY_C")
|
||||
create_and_faucet_wallet(vega=vega, wallet=PARTY_C)
|
||||
PARTY_D = WalletConfig("PARTY_D", "PARTY_D")
|
||||
create_and_faucet_wallet(vega=vega, wallet=PARTY_D)
|
||||
return PARTY_A, PARTY_B, PARTY_C, PARTY_D
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_activity_tier_0")
|
||||
def test_network_reward_pot(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("50.00 tDAI")
|
||||
page.pause()
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_activity_tier_0")
|
||||
def test_reward_multiplier(
|
||||
page: Page,
|
||||
):
|
||||
page.pause()
|
||||
expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("1x")
|
||||
expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text("1x")
|
||||
expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text("1x")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_activity_tier_0")
|
||||
""" @pytest.mark.xdist_group(name="test_rewards_activity_tier_0")
|
||||
def test_activity_streak(
|
||||
page: Page,
|
||||
):
|
||||
@@ -174,3 +128,4 @@ def test_reward_history(
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text("100.00")
|
||||
page.get_by_test_id(EARNED_BY_ME_BUTTON).click()
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text("50.00")
|
||||
"""
|
||||
@@ -0,0 +1,187 @@
|
||||
import pytest
|
||||
from rewards_test_ids import *
|
||||
import vega_sim.proto.vega as vega_protos
|
||||
from playwright.sync_api import Page, expect
|
||||
from conftest import init_vega, init_page, auth_setup, risk_accepted_setup, cleanup_container
|
||||
from fixtures.market import setup_continuous_market
|
||||
from actions.utils import next_epoch, change_keys
|
||||
from wallet_config import MM_WALLET
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega, PARTY_B)
|
||||
yield page
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_market_with_reward_program(vega: VegaServiceNull):
|
||||
tDAI_market = setup_continuous_market(vega)
|
||||
PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega)
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.mint(key_name=PARTY_B.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_C.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_A.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_D.name, asset=tDAI_asset_id, amount=100000)
|
||||
next_epoch(vega=vega)
|
||||
vega.update_network_parameter(
|
||||
proposal_key=MM_WALLET.name,
|
||||
parameter="rewards.activityStreak.benefitTiers",
|
||||
new_value=ACTIVITY_STREAKS,
|
||||
)
|
||||
print("update_network_parameter activity done")
|
||||
next_epoch(vega=vega)
|
||||
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.update_network_parameter(
|
||||
MM_WALLET.name, parameter="reward.asset", new_value=tDAI_asset_id
|
||||
)
|
||||
|
||||
next_epoch(vega=vega)
|
||||
vega.recurring_transfer(
|
||||
from_key_name=PARTY_A.name,
|
||||
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
|
||||
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
asset=tDAI_asset_id,
|
||||
reference="reward",
|
||||
asset_for_metric=tDAI_asset_id,
|
||||
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
|
||||
# lock_period= 5,
|
||||
# TODO test lock period
|
||||
amount=100,
|
||||
factor=1.0,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_A.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_LIMIT",
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
side="SIDE_BUY",
|
||||
price=1,
|
||||
volume=1,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_D.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_D.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
return tDAI_market, tDAI_asset_id
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_activity_tier_1")
|
||||
def test_network_reward_pot(page: Page):
|
||||
|
||||
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("116.66666 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_activity_tier_1")
|
||||
def test_reward_multiplier(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("2x")
|
||||
expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text("2x")
|
||||
expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text("1x")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_activity_tier_1")
|
||||
def test_activity_streak(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(EPOCH_STREAK)).to_have_text(
|
||||
"Active trader: 7 epochs so far (Tier 1 as of last epoch)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_activity_tier_1")
|
||||
def test_reward_history(
|
||||
page: Page,
|
||||
):
|
||||
page.locator('[name="fromEpoch"]').fill("1")
|
||||
expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text(
|
||||
"300.00100.00%"
|
||||
)
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text("300.00")
|
||||
page.get_by_test_id(EARNED_BY_ME_BUTTON).click()
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text(
|
||||
"116.66666"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_activity_tier_1")
|
||||
def test_redeem(
|
||||
page: Page,
|
||||
):
|
||||
page.get_by_test_id("redeem-rewards-button").click()
|
||||
available_to_withdraw = page.get_by_test_id(
|
||||
"available-to-withdraw-value"
|
||||
).text_content()
|
||||
option_value = page.locator(
|
||||
'[data-testid="transfer-form"] [name="fromAccount"] option[value^="ACCOUNT_TYPE_VESTED_REWARDS"]'
|
||||
).first.get_attribute("value")
|
||||
|
||||
page.select_option(
|
||||
'[data-testid="transfer-form"] [name="fromAccount"]', option_value
|
||||
)
|
||||
|
||||
page.get_by_test_id("use-max-button").first.click()
|
||||
expect(page.get_by_test_id(TRANSFER_AMOUNT)).to_have_text(available_to_withdraw)
|
||||
@@ -0,0 +1,174 @@
|
||||
import pytest
|
||||
from rewards_test_ids import *
|
||||
import vega_sim.proto.vega as vega_protos
|
||||
from playwright.sync_api import Page, expect
|
||||
from conftest import init_vega, init_page, auth_setup, risk_accepted_setup, cleanup_container
|
||||
from fixtures.market import setup_continuous_market
|
||||
from actions.utils import next_epoch, change_keys
|
||||
from wallet_config import MM_WALLET
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(vega, browser, request):
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega, page)
|
||||
page.goto(REWARDS_URL)
|
||||
change_keys(page, vega, PARTY_B)
|
||||
yield page
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_market_with_reward_program(vega: VegaServiceNull):
|
||||
tDAI_market = setup_continuous_market(vega)
|
||||
PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega)
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.mint(key_name=PARTY_B.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_C.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_A.name, asset=tDAI_asset_id, amount=100000)
|
||||
vega.mint(key_name=PARTY_D.name, asset=tDAI_asset_id, amount=100000)
|
||||
next_epoch(vega=vega)
|
||||
vega.update_network_parameter(
|
||||
proposal_key=MM_WALLET.name,
|
||||
parameter="rewards.activityStreak.benefitTiers",
|
||||
new_value=ACTIVITY_STREAKS,
|
||||
)
|
||||
print("update_network_parameter activity done")
|
||||
next_epoch(vega=vega)
|
||||
|
||||
vega.update_network_parameter(
|
||||
proposal_key=MM_WALLET.name,
|
||||
parameter="rewards.vesting.benefitTiers",
|
||||
new_value=VESTING,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
|
||||
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
|
||||
vega.update_network_parameter(
|
||||
MM_WALLET.name, parameter="reward.asset", new_value=tDAI_asset_id
|
||||
)
|
||||
|
||||
next_epoch(vega=vega)
|
||||
vega.recurring_transfer(
|
||||
from_key_name=PARTY_A.name,
|
||||
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
|
||||
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
asset=tDAI_asset_id,
|
||||
reference="reward",
|
||||
asset_for_metric=tDAI_asset_id,
|
||||
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
|
||||
amount=100,
|
||||
factor=1.0,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_A.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_LIMIT",
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
side="SIDE_BUY",
|
||||
price=1,
|
||||
volume=1,
|
||||
)
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_D.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_B.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.submit_order(
|
||||
trading_key=PARTY_D.name,
|
||||
market_id=tDAI_market,
|
||||
order_type="TYPE_MARKET",
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_for_total_catchup()
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
next_epoch(vega=vega)
|
||||
return tDAI_market, tDAI_asset_id
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_combo_tier_1")
|
||||
def test_network_reward_pot( page: Page
|
||||
):
|
||||
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("183.33333 tDAI")
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_combo_tier_1")
|
||||
def test_reward_multiplier(
|
||||
page: Page,
|
||||
):
|
||||
expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("4x")
|
||||
expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text(
|
||||
"2x"
|
||||
)
|
||||
expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text(
|
||||
"2x"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="test_rewards_combo_tier_1")
|
||||
def test_reward_history(
|
||||
page: Page,
|
||||
):
|
||||
page.locator('[name="fromEpoch"]').fill("1")
|
||||
expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text(
|
||||
"299.99999100.00%"
|
||||
)
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text("299.99999")
|
||||
page.get_by_test_id(EARNED_BY_ME_BUTTON).click()
|
||||
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text(
|
||||
"183.33333"
|
||||
)
|
||||
@@ -43,6 +43,7 @@ def test_vesting(continuous_market, vega: VegaServiceNull, page: Page):
|
||||
side="SIDE_BUY",
|
||||
volume=1,
|
||||
)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
page.goto("/#/rewards")
|
||||
|
||||
@@ -6,7 +6,7 @@ from conftest import init_vega, cleanup_container
|
||||
@pytest.fixture(scope="module")
|
||||
def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
yield vega_instance
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ def vega(request):
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(
|
||||
lambda: cleanup_container(vega_instance)
|
||||
) # Register the cleanup function
|
||||
)
|
||||
yield vega_instance
|
||||
|
||||
|
||||
@@ -242,12 +242,12 @@ def test_team_page_headline(team_page: Page, setup_teams_and_games):
|
||||
expect(team_page.get_by_test_id("team-name")).to_have_text(team_name)
|
||||
expect(team_page.get_by_test_id("members-count-stat")).to_have_text("4")
|
||||
|
||||
expect(team_page.get_by_test_id("total-games-stat")).to_have_text("2")
|
||||
expect(team_page.get_by_test_id("total-games-stat")).to_have_text("1")
|
||||
|
||||
# TODO this still seems wrong as its always 0
|
||||
expect(team_page.get_by_test_id("total-volume-stat")).to_have_text("0")
|
||||
|
||||
expect(team_page.get_by_test_id("rewards-paid-stat")).to_have_text("1.2k")
|
||||
expect(team_page.get_by_test_id("rewards-paid-stat")).to_have_text("500")
|
||||
|
||||
|
||||
def test_switch_teams(team_page: Page, vega: VegaServiceNull):
|
||||
@@ -264,19 +264,18 @@ def test_switch_teams(team_page: Page, vega: VegaServiceNull):
|
||||
def test_leaderboard(competitions_page: Page, setup_teams_and_games):
|
||||
team_name = setup_teams_and_games["team_name"]
|
||||
competitions_page.reload()
|
||||
competitions_page.pause()
|
||||
expect(
|
||||
competitions_page.get_by_test_id("rank-0").locator(".text-yellow-300")
|
||||
).to_have_count(1)
|
||||
expect(
|
||||
competitions_page.get_by_test_id("rank-1").locator(".text-vega-clight-500")
|
||||
).to_have_count(1)
|
||||
expect(competitions_page.get_by_test_id("team-0")).to_have_text(team_name)
|
||||
expect(competitions_page.get_by_test_id("team-1")).to_have_text(team_name)
|
||||
expect(competitions_page.get_by_test_id("status-1")).to_have_text("Open")
|
||||
|
||||
# FIXME: the numbers are different we need to clarify this with the backend
|
||||
# expect(competitions_page.get_by_test_id("earned-1")).to_have_text("160")
|
||||
expect(competitions_page.get_by_test_id("games-1")).to_have_text("2")
|
||||
expect(competitions_page.get_by_test_id("games-1")).to_have_text("1")
|
||||
|
||||
# TODO still odd that this is 0
|
||||
expect(competitions_page.get_by_test_id("volume-0")).to_have_text("0")
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { ENV, Networks } from '@vegaprotocol/environment';
|
||||
|
||||
const TEAMS_STATS_EPOCHS_MAINNET = 30;
|
||||
const TEAMS_STATS_EPOCHS_TESTNET = 192;
|
||||
export const TEAMS_STATS_EPOCHS =
|
||||
ENV.VEGA_ENV === Networks.MAINNET
|
||||
? TEAMS_STATS_EPOCHS_MAINNET
|
||||
: TEAMS_STATS_EPOCHS_TESTNET;
|
||||
@@ -1,92 +0,0 @@
|
||||
import compact from 'lodash/compact';
|
||||
import { useActiveRewardsQuery } from '../../components/rewards-container/__generated__/Rewards';
|
||||
import { isActiveReward } from '../../components/rewards-container/active-rewards';
|
||||
import {
|
||||
type RecurringTransfer,
|
||||
type TransferNode,
|
||||
EntityScope,
|
||||
IndividualScope,
|
||||
} from '@vegaprotocol/types';
|
||||
import {
|
||||
type AssetFieldsFragment,
|
||||
useAssetsMapProvider,
|
||||
} from '@vegaprotocol/assets';
|
||||
import {
|
||||
type MarketFieldsFragment,
|
||||
useMarketsMapProvider,
|
||||
} from '@vegaprotocol/markets';
|
||||
import { type ApolloError } from '@apollo/client';
|
||||
|
||||
export type EnrichedTransfer = TransferNode & {
|
||||
asset?: AssetFieldsFragment | null;
|
||||
markets?: (MarketFieldsFragment | null)[];
|
||||
};
|
||||
|
||||
type RecurringTransferKind = EnrichedTransfer & {
|
||||
transfer: {
|
||||
kind: RecurringTransfer;
|
||||
};
|
||||
};
|
||||
|
||||
export const isScopedToTeams = (
|
||||
node: TransferNode
|
||||
): node is RecurringTransferKind =>
|
||||
node.transfer.kind.__typename === 'RecurringTransfer' &&
|
||||
// scoped to teams
|
||||
(node.transfer.kind.dispatchStrategy?.entityScope ===
|
||||
EntityScope.ENTITY_SCOPE_TEAMS ||
|
||||
// or to individuals
|
||||
(node.transfer.kind.dispatchStrategy?.entityScope ===
|
||||
EntityScope.ENTITY_SCOPE_INDIVIDUALS &&
|
||||
// but they have to be in a team
|
||||
node.transfer.kind.dispatchStrategy.individualScope ===
|
||||
IndividualScope.INDIVIDUAL_SCOPE_IN_TEAM));
|
||||
|
||||
export const useGameCards = ({
|
||||
currentEpoch,
|
||||
onlyActive,
|
||||
}: {
|
||||
currentEpoch: number;
|
||||
onlyActive: boolean;
|
||||
}): { data: EnrichedTransfer[]; loading: boolean; error?: ApolloError } => {
|
||||
const { data, loading, error } = useActiveRewardsQuery({
|
||||
variables: {
|
||||
isReward: true,
|
||||
},
|
||||
fetchPolicy: 'cache-and-network',
|
||||
});
|
||||
|
||||
const { data: assets, loading: assetsLoading } = useAssetsMapProvider();
|
||||
const { data: markets, loading: marketsLoading } = useMarketsMapProvider();
|
||||
|
||||
const games = compact(data?.transfersConnection?.edges?.map((n) => n?.node))
|
||||
.map((n) => n as TransferNode)
|
||||
.filter((node) => {
|
||||
const active = onlyActive ? isActiveReward(node, currentEpoch) : true;
|
||||
return active && isScopedToTeams(node);
|
||||
})
|
||||
.map((node) => {
|
||||
if (node.transfer.kind.__typename !== 'RecurringTransfer') {
|
||||
return node;
|
||||
}
|
||||
|
||||
const asset =
|
||||
assets &&
|
||||
assets[
|
||||
node.transfer.kind.dispatchStrategy?.dispatchMetricAssetId || ''
|
||||
];
|
||||
|
||||
const marketsInScope =
|
||||
node.transfer.kind.dispatchStrategy?.marketIdsInScope?.map(
|
||||
(id) => markets && markets[id]
|
||||
);
|
||||
|
||||
return { ...node, asset, markets: marketsInScope };
|
||||
});
|
||||
|
||||
return {
|
||||
data: games,
|
||||
loading: loading || assetsLoading || marketsLoading,
|
||||
error,
|
||||
};
|
||||
};
|
||||
@@ -7,8 +7,7 @@ import orderBy from 'lodash/orderBy';
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
import { useEpochInfoQuery } from './__generated__/Epoch';
|
||||
import { type ApolloError } from '@apollo/client';
|
||||
|
||||
const TAKE_EPOCHS = 30; // TODO: should this be DEFAULT_AGGREGATION_EPOCHS?
|
||||
import { TEAMS_STATS_EPOCHS } from './constants';
|
||||
|
||||
const findTeam = (entities: GameFieldsFragment['entities'], teamId: string) => {
|
||||
const team = entities.find(
|
||||
@@ -45,7 +44,7 @@ export const useGames = (teamId?: string, epochFrom?: number): GamesData => {
|
||||
|
||||
let from = epochFrom;
|
||||
if (!from && epochData) {
|
||||
from = Number(epochData.epoch.id) - TAKE_EPOCHS;
|
||||
from = Number(epochData.epoch.id) - TEAMS_STATS_EPOCHS;
|
||||
if (from < 1) from = 1; // make sure it's not negative
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
import {
|
||||
type DispatchStrategy,
|
||||
type TransferNode,
|
||||
EntityScope,
|
||||
type TransferKind,
|
||||
TransferStatus,
|
||||
IndividualScope,
|
||||
} from '@vegaprotocol/types';
|
||||
import {
|
||||
type RewardTransfer,
|
||||
isActiveReward,
|
||||
isReward,
|
||||
isScopedToTeams,
|
||||
} from './use-rewards';
|
||||
|
||||
const makeDispatchStrategy = (
|
||||
entityScope: EntityScope,
|
||||
individualScope?: IndividualScope
|
||||
): DispatchStrategy =>
|
||||
({
|
||||
entityScope,
|
||||
individualScope,
|
||||
} as DispatchStrategy);
|
||||
|
||||
const makeReward = (
|
||||
status: TransferStatus,
|
||||
startEpoch: number,
|
||||
endEpoch?: number,
|
||||
dispatchStrategy?: DispatchStrategy,
|
||||
kind: TransferKind['__typename'] = 'OneOffTransfer'
|
||||
): RewardTransfer =>
|
||||
({
|
||||
transfer: {
|
||||
status,
|
||||
kind: {
|
||||
__typename: kind,
|
||||
dispatchStrategy,
|
||||
startEpoch,
|
||||
endEpoch,
|
||||
},
|
||||
},
|
||||
} as RewardTransfer);
|
||||
|
||||
describe('isReward', () => {
|
||||
it.each([
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
true,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_INDIVIDUALS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
true,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
undefined,
|
||||
'RecurringTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'OneOffTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_INDIVIDUALS),
|
||||
'OneOffTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
])('checks if given transfer is a reward or not', (input, output) => {
|
||||
expect(isReward(input as TransferNode)).toEqual(output);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isActiveReward', () => {
|
||||
it.each([
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
true,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
2,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
true,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
3,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
true,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
4, // start in 1 epoch
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_DONE, // done, not active any more
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
2, // ended 1 epoch ago
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
3, // ends now, but active until end of epoch
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
true,
|
||||
],
|
||||
])('checks if given reward is active or not', (input, output) => {
|
||||
expect(isActiveReward(input, 3)).toEqual(output);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isScopedToTeams', () => {
|
||||
it.each([
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_TEAMS), // only teams
|
||||
'RecurringTransfer'
|
||||
),
|
||||
true,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(
|
||||
EntityScope.ENTITY_SCOPE_INDIVIDUALS,
|
||||
IndividualScope.INDIVIDUAL_SCOPE_IN_TEAM // individual in teams
|
||||
),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
true,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(EntityScope.ENTITY_SCOPE_INDIVIDUALS), // not in team
|
||||
'RecurringTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(
|
||||
EntityScope.ENTITY_SCOPE_INDIVIDUALS,
|
||||
IndividualScope.INDIVIDUAL_SCOPE_ALL // not only in team
|
||||
),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
[
|
||||
makeReward(
|
||||
TransferStatus.STATUS_PENDING,
|
||||
1,
|
||||
undefined,
|
||||
makeDispatchStrategy(
|
||||
EntityScope.ENTITY_SCOPE_INDIVIDUALS,
|
||||
IndividualScope.INDIVIDUAL_SCOPE_NOT_IN_TEAM // not in team
|
||||
),
|
||||
'RecurringTransfer'
|
||||
),
|
||||
false,
|
||||
],
|
||||
])('checks if given reward is scoped to teams or not', (input, output) => {
|
||||
expect(isScopedToTeams(input)).toEqual(output);
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user