fix: total fees calculation (#1394)
* fix: total fees calculation * fix: total fees calculation * fix: add two more tests * fix: market-info.cy.ts Co-authored-by: Madalina Raicu <madalina@vegaprotocol.io>
This commit is contained in:
parent
597a1fa878
commit
4ddacb5269
@ -22,7 +22,7 @@ describe('market info is displayed', () => {
|
||||
validateMarketDataRow(0, 'Maker Fee', '0.02%');
|
||||
validateMarketDataRow(1, 'Infrastructure Fee', '0.05%');
|
||||
validateMarketDataRow(2, 'Liquidity Fee', '1.00%');
|
||||
validateMarketDataRow(3, 'Total Fees', '1.04%');
|
||||
validateMarketDataRow(3, 'Total Fees', '1.07%');
|
||||
});
|
||||
|
||||
it('market price', () => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { MarketState, MarketTradingMode } from '@vegaprotocol/types';
|
||||
import type { Market } from '../markets-provider';
|
||||
import { mapDataToMarketList } from './market-utils';
|
||||
import { mapDataToMarketList, totalFees } from './market-utils';
|
||||
|
||||
const MARKET_A: Partial<Market> = {
|
||||
id: '1',
|
||||
@ -57,3 +57,22 @@ describe('mapDataToMarketList', () => {
|
||||
expect(result).toEqual([MARKET_B, MARKET_A]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('totalFees', () => {
|
||||
const createFee = (...f: number[]): Market['fees']['factors'] => ({
|
||||
__typename: 'FeeFactors',
|
||||
infrastructureFee: f[0].toString(),
|
||||
liquidityFee: f[1].toString(),
|
||||
makerFee: f[2].toString(),
|
||||
});
|
||||
it.each([
|
||||
{ i: createFee(0, 0, 1), o: '100.00%' },
|
||||
{ i: createFee(0, 1, 0), o: '100.00%' },
|
||||
{ i: createFee(1, 0, 0), o: '100.00%' },
|
||||
{ i: createFee(0.01, 0.02, 0.003), o: '3.30%' },
|
||||
{ i: createFee(0.01, 0.056782, 0.003), o: '6.9782%' },
|
||||
{ i: createFee(0.01, 0.056782, 0), o: '6.6782%' },
|
||||
])('adds fees correctly', ({ i, o }) => {
|
||||
expect(totalFees(i)).toEqual(o);
|
||||
});
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ export const totalFees = (fees: Market['fees']['factors']) => {
|
||||
return formatNumberPercentage(
|
||||
new BigNumber(fees.makerFee)
|
||||
.plus(fees.liquidityFee)
|
||||
.plus(fees.makerFee)
|
||||
.plus(fees.infrastructureFee)
|
||||
.times(100)
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user