import maxBy from 'lodash/maxBy'; import minBy from 'lodash/minBy'; import { t } from '@vegaprotocol/i18n'; import { useVegaWallet } from '@vegaprotocol/wallet'; import { useNetworkParams, NetworkParams, } from '@vegaprotocol/network-parameters'; import { useMarketList } from '@vegaprotocol/markets'; import { formatNumber, formatNumberRounded } from '@vegaprotocol/utils'; import { useDiscountProgramsQuery, useFeesQuery } from './__generated__/Fees'; import { FeeCard } from './fees-card'; import { MarketFees } from './market-fees'; import { Stat } from './stat'; import { useVolumeStats } from './use-volume-stats'; import { useReferralStats } from './use-referral-stats'; import { formatPercentage, getAdjustedFee } from './utils'; import { Table, Td, Th, THead, Tr } from './table'; import BigNumber from 'bignumber.js'; import { Links } from '../../lib/links'; import { Link } from 'react-router-dom'; import { Tooltip, VegaIcon, VegaIconNames, truncateMiddle, } from '@vegaprotocol/ui-toolkit'; export const FeesContainer = () => { const { pubKey } = useVegaWallet(); const { params, loading: paramsLoading } = useNetworkParams([ NetworkParams.market_fee_factors_makerFee, NetworkParams.market_fee_factors_infrastructureFee, ]); const { data: markets, loading: marketsLoading } = useMarketList(); const { data: programData, loading: programLoading } = useDiscountProgramsQuery(); const volumeDiscountWindowLength = programData?.currentVolumeDiscountProgram?.windowLength || 1; const referralDiscountWindowLength = programData?.currentReferralProgram?.windowLength || 1; const { data: feesData, loading: feesLoading } = useFeesQuery({ variables: { partyId: pubKey || '', volumeDiscountEpochs: volumeDiscountWindowLength, referralDiscountEpochs: referralDiscountWindowLength, }, skip: !pubKey || !programData, }); const { volumeDiscount, volumeTierIndex, volumeInWindow, volumeTiers } = useVolumeStats( feesData?.volumeDiscountStats, programData?.currentVolumeDiscountProgram ); const { referralDiscount, referralVolumeInWindow, referralTierIndex, referralTiers, epochsInSet, code, isReferrer, } = useReferralStats( feesData?.referralSetStats, feesData?.referralSetReferees, programData?.currentReferralProgram, feesData?.epoch, feesData?.referrer, feesData?.referee ); const loading = paramsLoading || feesLoading || programLoading; const isConnected = Boolean(pubKey); const isReferralProgramRunning = Boolean(programData?.currentReferralProgram); const isVolumeDiscountProgramRunning = Boolean( programData?.currentVolumeDiscountProgram ); return (
{t('No volume discount program active')}
)}{t('No referral program active')}
)}{minAdjustedTotal !== undefined && maxAdjustedTotal !== undefined ? `${formatPercentage(minAdjustedTotal)}%-${formatPercentage( maxAdjustedTotal )}%` : `${formatPercentage(adjustedTotal)}%`}
{t('Total fee before discount')} | {minTotal !== undefined && maxTotal !== undefined ? `${formatPercentage( minTotal.toNumber() )}%-${formatPercentage(maxTotal.toNumber())}%` : `${formatPercentage(total.toNumber())}%`} |
---|---|
{t('Infrastructure')} | {formatPercentage( Number(params.market_fee_factors_infrastructureFee) )} % |
{t('Maker')} | {formatPercentage(Number(params.market_fee_factors_makerFee))}% |
{t('Liquidity')} | {formatPercentage(Number(minLiq.fees.factors.liquidityFee))}% {'-'} {formatPercentage(Number(maxLiq.fees.factors.liquidityFee))}% |
{t('Volume discount')} |
{formatPercentage(volumeDiscount)}%
{!isVolumeDiscountProgramRunning && (
|
---|---|
{t('Referral discount')} |
{formatPercentage(referralDiscount)}%
{!isReferralProgramRunning && (
|
{t('No volume discount program active')}
); } return ({t('Tier')} | {t('Discount')} | {t('Min. trading volume')} | {t('My volume (last %s epochs)', windowLength.toString())} | |
---|---|---|---|---|
{i + 1} | {formatPercentage(Number(tier.volumeDiscountFactor))}% | {formatNumber(tier.minimumRunningNotionalTakerVolume)} | {isUserTier ? formatNumber(lastEpochVolume) : ''} | {isUserTier ? |
{t('No referral program active')}
); } return ({t('Tier')} | {t('Discount')} | {t('Min. trading volume')} | {t('Required epochs')} | |
---|---|---|---|---|
{i + 1} | {formatPercentage(Number(t.referralDiscountFactor))}% | {formatNumber(t.minimumRunningNotionalTakerVolume)} | {t.minimumEpochs} | {isUserTier ? |
{t('Connected key is owner of the referral set')} {code && ( <> {' '} {truncateMiddle(code)} > )} {'. '} {t('As owner, it is eligible for commission not fee discounts.')}
{t('See')}{' '} {t('Referrals')} {' '} {t('for more information.')}