mango-ui-v3/hooks/useFees.tsx

36 lines
1.0 KiB
TypeScript

import {
getMarketIndexBySymbol,
PerpMarket,
} from '@blockworks-foundation/mango-client'
import useSrmAccount from '../hooks/useSrmAccount'
import useMangoStore from '../stores/useMangoStore'
export default function useFees() {
const { rates } = useSrmAccount()
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
const mangoGroupConfig = useMangoStore((s) => s.selectedMangoGroup.config)
const marketConfig = useMangoStore((s) => s.selectedMarket.config)
const market = useMangoStore((s) => s.selectedMarket.current)
const marketIndex = getMarketIndexBySymbol(
mangoGroupConfig,
marketConfig.baseSymbol
)
if (!mangoGroup) return {}
let takerFee, makerFee
if (market instanceof PerpMarket) {
takerFee = parseFloat(
mangoGroup.perpMarkets[marketIndex].takerFee.toFixed()
)
makerFee = parseFloat(
mangoGroup.perpMarkets[marketIndex].makerFee.toFixed()
)
} else {
takerFee = rates.takerWithRebate
makerFee = rates.maker
}
return { makerFee, takerFee }
}