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'; 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 volumeDiscountEpochs = programData?.currentVolumeDiscountProgram?.windowLength || 1; const referralDiscountEpochs = programData?.currentReferralProgram?.windowLength || 1; const { data: feesData, loading: feesLoading } = useFeesQuery({ variables: { partyId: pubKey || '', volumeDiscountEpochs, referralDiscountEpochs, }, skip: !pubKey || !programData, }); const { volumeDiscount, volumeTierIndex, volumeInWindow, volumeTiers } = useVolumeStats( feesData?.volumeDiscountStats, programData?.currentVolumeDiscountProgram ); const { referralDiscount, referralVolumeInWindow, referralTierIndex, referralTiers, epochsInSet, } = useReferralStats( feesData?.referralSetStats, feesData?.referralSetReferees, programData?.currentReferralProgram, feesData?.epoch ); const loading = paramsLoading || feesLoading || programLoading; const isConnected = Boolean(pubKey); return (
{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)}% |
---|---|
{t('Referral discount')} | {formatPercentage(referralDiscount)}% |
{t('No volume discount program active')}
); } return ({t('Tier')} | {t('Discount')} | {t('Min. trading volume')} | {t('My volume (last epoch)')} | |
---|---|---|---|---|
{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 ? |