From 954b4b27558da3dbd36f7e0a7d6396c5abb30f25 Mon Sep 17 00:00:00 2001 From: "m.ray" <16125548+MadalinaRaicu@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:50:07 +0000 Subject: [PATCH] fix(trading): recurring governance transfers after 0.75.1 (#6122) --- .../competitions/games-container.tsx | 5 +- .../rewards-container/active-rewards.tsx | 5 +- apps/trading/lib/hooks/Rewards.graphql | 73 ++++++++++----- .../lib/hooks/__generated__/Rewards.ts | 89 +++++++++++++------ apps/trading/lib/hooks/use-rewards.ts | 3 +- 5 files changed, 123 insertions(+), 52 deletions(-) diff --git a/apps/trading/components/competitions/games-container.tsx b/apps/trading/components/competitions/games-container.tsx index 8b2bdc496..787205861 100644 --- a/apps/trading/components/competitions/games-container.tsx +++ b/apps/trading/components/competitions/games-container.tsx @@ -40,7 +40,10 @@ export const applyFilter = ( return true; } - if (transfer.kind.__typename !== 'RecurringTransfer') { + if ( + transfer.kind.__typename !== 'RecurringTransfer' && + transfer.kind.__typename !== 'RecurringGovernanceTransfer' + ) { return false; } diff --git a/apps/trading/components/rewards-container/active-rewards.tsx b/apps/trading/components/rewards-container/active-rewards.tsx index 2e16388b2..5fa819e87 100644 --- a/apps/trading/components/rewards-container/active-rewards.tsx +++ b/apps/trading/components/rewards-container/active-rewards.tsx @@ -38,7 +38,10 @@ export const applyFilter = ( return true; } - if (transfer.kind.__typename !== 'RecurringTransfer') { + if ( + transfer.kind.__typename !== 'RecurringTransfer' && + transfer.kind.__typename !== 'RecurringGovernanceTransfer' + ) { return false; } diff --git a/apps/trading/lib/hooks/Rewards.graphql b/apps/trading/lib/hooks/Rewards.graphql index 78f201f0f..26ee3faef 100644 --- a/apps/trading/lib/hooks/Rewards.graphql +++ b/apps/trading/lib/hooks/Rewards.graphql @@ -41,6 +41,55 @@ query RewardsPage($partyId: ID!) { } } +fragment RecurringTransferFields on TransferKind { + ... on RecurringGovernanceTransfer { + startEpoch + endEpoch + dispatchStrategy { + capRewardFeeMultiple + dispatchMetric + dispatchMetricAssetId + marketIdsInScope + entityScope + individualScope + teamScope + nTopPerformers + stakingRequirement + notionalTimeWeightedAveragePositionRequirement + windowLength + lockPeriod + distributionStrategy + rankTable { + startRank + shareRatio + } + } + } + ... on RecurringTransfer { + startEpoch + endEpoch + dispatchStrategy { + capRewardFeeMultiple + dispatchMetric + dispatchMetricAssetId + marketIdsInScope + entityScope + individualScope + teamScope + nTopPerformers + stakingRequirement + notionalTimeWeightedAveragePositionRequirement + windowLength + lockPeriod + distributionStrategy + rankTable { + startRank + shareRatio + } + } + } +} + query ActiveRewards( $isReward: Boolean $partyId: ID @@ -75,29 +124,7 @@ query ActiveRewards( timestamp gameId kind { - ... on RecurringTransfer { - startEpoch - endEpoch - dispatchStrategy { - capRewardFeeMultiple - dispatchMetric - dispatchMetricAssetId - marketIdsInScope - entityScope - individualScope - teamScope - nTopPerformers - stakingRequirement - notionalTimeWeightedAveragePositionRequirement - windowLength - lockPeriod - distributionStrategy - rankTable { - startRank - shareRatio - } - } - } + ...RecurringTransferFields } reason } diff --git a/apps/trading/lib/hooks/__generated__/Rewards.ts b/apps/trading/lib/hooks/__generated__/Rewards.ts index 3b80e9f0e..0ac4f7b6d 100644 --- a/apps/trading/lib/hooks/__generated__/Rewards.ts +++ b/apps/trading/lib/hooks/__generated__/Rewards.ts @@ -10,6 +10,16 @@ export type RewardsPageQueryVariables = Types.Exact<{ export type RewardsPageQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, vestingStats?: { __typename?: 'PartyVestingStats', rewardBonusMultiplier: string, quantumBalance: string, epochSeq: number } | null, activityStreak?: { __typename?: 'PartyActivityStreak', activeFor: number, isActive: boolean, inactiveFor: number, rewardDistributionMultiplier: string, rewardVestingMultiplier: string, epoch: number, tradedVolume: string, openVolume: string } | null, vestingBalancesSummary: { __typename?: 'PartyVestingBalancesSummary', epoch?: number | null, vestingBalances?: Array<{ __typename?: 'PartyVestingBalance', balance: string, asset: { __typename?: 'Asset', id: string, symbol: string, decimals: number, quantum: string } }> | null, lockedBalances?: Array<{ __typename?: 'PartyLockedBalance', balance: string, untilEpoch: number, asset: { __typename?: 'Asset', id: string, symbol: string, decimals: number, quantum: string } }> | null } } | null }; +export type RecurringTransferFields_OneOffGovernanceTransfer_Fragment = { __typename?: 'OneOffGovernanceTransfer' }; + +export type RecurringTransferFields_OneOffTransfer_Fragment = { __typename?: 'OneOffTransfer' }; + +export type RecurringTransferFields_RecurringGovernanceTransfer_Fragment = { __typename?: 'RecurringGovernanceTransfer', startEpoch: number, endEpoch?: number | null, dispatchStrategy?: { __typename?: 'DispatchStrategy', capRewardFeeMultiple?: string | null, dispatchMetric: Types.DispatchMetric, dispatchMetricAssetId: string, marketIdsInScope?: Array | null, entityScope: Types.EntityScope, individualScope?: Types.IndividualScope | null, teamScope?: Array | null, nTopPerformers?: string | null, stakingRequirement: string, notionalTimeWeightedAveragePositionRequirement: string, windowLength: number, lockPeriod: number, distributionStrategy: Types.DistributionStrategy, rankTable?: Array<{ __typename?: 'RankTable', startRank: number, shareRatio: number } | null> | null } | null }; + +export type RecurringTransferFields_RecurringTransfer_Fragment = { __typename?: 'RecurringTransfer', startEpoch: number, endEpoch?: number | null, dispatchStrategy?: { __typename?: 'DispatchStrategy', capRewardFeeMultiple?: string | null, dispatchMetric: Types.DispatchMetric, dispatchMetricAssetId: string, marketIdsInScope?: Array | null, entityScope: Types.EntityScope, individualScope?: Types.IndividualScope | null, teamScope?: Array | null, nTopPerformers?: string | null, stakingRequirement: string, notionalTimeWeightedAveragePositionRequirement: string, windowLength: number, lockPeriod: number, distributionStrategy: Types.DistributionStrategy, rankTable?: Array<{ __typename?: 'RankTable', startRank: number, shareRatio: number } | null> | null } | null }; + +export type RecurringTransferFieldsFragment = RecurringTransferFields_OneOffGovernanceTransfer_Fragment | RecurringTransferFields_OneOffTransfer_Fragment | RecurringTransferFields_RecurringGovernanceTransfer_Fragment | RecurringTransferFields_RecurringTransfer_Fragment; + export type ActiveRewardsQueryVariables = Types.Exact<{ isReward?: Types.InputMaybe; partyId?: Types.InputMaybe; @@ -18,7 +28,7 @@ export type ActiveRewardsQueryVariables = Types.Exact<{ }>; -export type ActiveRewardsQuery = { __typename?: 'Query', transfersConnection?: { __typename?: 'TransferConnection', edges?: Array<{ __typename?: 'TransferEdge', node: { __typename?: 'TransferNode', transfer: { __typename?: 'Transfer', amount: string, id: string, from: string, fromAccountType: Types.AccountType, to: string, toAccountType: Types.AccountType, reference?: string | null, status: Types.TransferStatus, timestamp: any, gameId?: string | null, reason?: string | null, asset?: { __typename?: 'Asset', id: string, symbol: string, decimals: number, name: string, quantum: string, status: Types.AssetStatus } | null, kind: { __typename?: 'OneOffGovernanceTransfer' } | { __typename?: 'OneOffTransfer' } | { __typename?: 'RecurringGovernanceTransfer' } | { __typename?: 'RecurringTransfer', startEpoch: number, endEpoch?: number | null, dispatchStrategy?: { __typename?: 'DispatchStrategy', capRewardFeeMultiple?: string | null, dispatchMetric: Types.DispatchMetric, dispatchMetricAssetId: string, marketIdsInScope?: Array | null, entityScope: Types.EntityScope, individualScope?: Types.IndividualScope | null, teamScope?: Array | null, nTopPerformers?: string | null, stakingRequirement: string, notionalTimeWeightedAveragePositionRequirement: string, windowLength: number, lockPeriod: number, distributionStrategy: Types.DistributionStrategy, rankTable?: Array<{ __typename?: 'RankTable', startRank: number, shareRatio: number } | null> | null } | null } }, fees?: Array<{ __typename?: 'TransferFee', transferId: string, amount: string, epoch: number } | null> | null } } | null> | null } | null }; +export type ActiveRewardsQuery = { __typename?: 'Query', transfersConnection?: { __typename?: 'TransferConnection', edges?: Array<{ __typename?: 'TransferEdge', node: { __typename?: 'TransferNode', transfer: { __typename?: 'Transfer', amount: string, id: string, from: string, fromAccountType: Types.AccountType, to: string, toAccountType: Types.AccountType, reference?: string | null, status: Types.TransferStatus, timestamp: any, gameId?: string | null, reason?: string | null, asset?: { __typename?: 'Asset', id: string, symbol: string, decimals: number, name: string, quantum: string, status: Types.AssetStatus } | null, kind: { __typename?: 'OneOffGovernanceTransfer' } | { __typename?: 'OneOffTransfer' } | { __typename?: 'RecurringGovernanceTransfer', startEpoch: number, endEpoch?: number | null, dispatchStrategy?: { __typename?: 'DispatchStrategy', capRewardFeeMultiple?: string | null, dispatchMetric: Types.DispatchMetric, dispatchMetricAssetId: string, marketIdsInScope?: Array | null, entityScope: Types.EntityScope, individualScope?: Types.IndividualScope | null, teamScope?: Array | null, nTopPerformers?: string | null, stakingRequirement: string, notionalTimeWeightedAveragePositionRequirement: string, windowLength: number, lockPeriod: number, distributionStrategy: Types.DistributionStrategy, rankTable?: Array<{ __typename?: 'RankTable', startRank: number, shareRatio: number } | null> | null } | null } | { __typename?: 'RecurringTransfer', startEpoch: number, endEpoch?: number | null, dispatchStrategy?: { __typename?: 'DispatchStrategy', capRewardFeeMultiple?: string | null, dispatchMetric: Types.DispatchMetric, dispatchMetricAssetId: string, marketIdsInScope?: Array | null, entityScope: Types.EntityScope, individualScope?: Types.IndividualScope | null, teamScope?: Array | null, nTopPerformers?: string | null, stakingRequirement: string, notionalTimeWeightedAveragePositionRequirement: string, windowLength: number, lockPeriod: number, distributionStrategy: Types.DistributionStrategy, rankTable?: Array<{ __typename?: 'RankTable', startRank: number, shareRatio: number } | null> | null } | null } }, fees?: Array<{ __typename?: 'TransferFee', transferId: string, amount: string, epoch: number } | null> | null } } | null> | null } | null }; export type TWAPQueryVariables = Types.Exact<{ partyId: Types.Scalars['ID']; @@ -53,7 +63,56 @@ export type MarketForRewardsQueryVariables = Types.Exact<{ export type MarketForRewardsQuery = { __typename?: 'Query', market?: { __typename?: 'Market', tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string, metadata: { __typename?: 'InstrumentMetadata', tags?: Array | null } } } } | null }; - +export const RecurringTransferFieldsFragmentDoc = gql` + fragment RecurringTransferFields on TransferKind { + ... on RecurringGovernanceTransfer { + startEpoch + endEpoch + dispatchStrategy { + capRewardFeeMultiple + dispatchMetric + dispatchMetricAssetId + marketIdsInScope + entityScope + individualScope + teamScope + nTopPerformers + stakingRequirement + notionalTimeWeightedAveragePositionRequirement + windowLength + lockPeriod + distributionStrategy + rankTable { + startRank + shareRatio + } + } + } + ... on RecurringTransfer { + startEpoch + endEpoch + dispatchStrategy { + capRewardFeeMultiple + dispatchMetric + dispatchMetricAssetId + marketIdsInScope + entityScope + individualScope + teamScope + nTopPerformers + stakingRequirement + notionalTimeWeightedAveragePositionRequirement + windowLength + lockPeriod + distributionStrategy + rankTable { + startRank + shareRatio + } + } + } +} + `; export const RewardsPageDocument = gql` query RewardsPage($partyId: ID!) { party(id: $partyId) { @@ -156,29 +215,7 @@ export const ActiveRewardsDocument = gql` timestamp gameId kind { - ... on RecurringTransfer { - startEpoch - endEpoch - dispatchStrategy { - capRewardFeeMultiple - dispatchMetric - dispatchMetricAssetId - marketIdsInScope - entityScope - individualScope - teamScope - nTopPerformers - stakingRequirement - notionalTimeWeightedAveragePositionRequirement - windowLength - lockPeriod - distributionStrategy - rankTable { - startRank - shareRatio - } - } - } + ...RecurringTransferFields } reason } @@ -191,7 +228,7 @@ export const ActiveRewardsDocument = gql` } } } - `; + ${RecurringTransferFieldsFragmentDoc}`; /** * __useActiveRewardsQuery__ diff --git a/apps/trading/lib/hooks/use-rewards.ts b/apps/trading/lib/hooks/use-rewards.ts index 922284240..b016d4ead 100644 --- a/apps/trading/lib/hooks/use-rewards.ts +++ b/apps/trading/lib/hooks/use-rewards.ts @@ -47,7 +47,8 @@ export type EnrichedRewardTransfer = RewardTransfer & { */ export const isReward = (node: TransferNode): node is RewardTransfer => { if ( - (node.transfer.kind.__typename === 'RecurringTransfer' && + ((node.transfer.kind.__typename === 'RecurringTransfer' || + node.transfer.kind.__typename === 'RecurringGovernanceTransfer') && node.transfer.kind.dispatchStrategy != null) || node.transfer.toAccountType === AccountType.ACCOUNT_TYPE_GLOBAL_REWARD ) {