2021-04-07 14:49:37 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-04-09 17:01:00 -07:00
|
|
|
import { nativeToUi } from '@blockworks-foundation/mango-client'
|
2021-04-07 14:49:37 -07:00
|
|
|
import { SRM_DECIMALS } from '@project-serum/serum/lib/token-instructions'
|
|
|
|
import { getFeeTier, getFeeRates } from '@project-serum/serum'
|
2021-04-09 17:01:00 -07:00
|
|
|
import { parseTokenAccountData } from '../utils/tokens'
|
2021-04-07 14:49:37 -07:00
|
|
|
|
|
|
|
const useSrmAccount = () => {
|
|
|
|
const srmAccount = useMangoStore((s) => s.selectedMangoGroup.srmAccount)
|
|
|
|
|
|
|
|
const accountData = parseTokenAccountData(srmAccount.data)
|
|
|
|
const totalSrm = nativeToUi(accountData.amount, SRM_DECIMALS)
|
|
|
|
const feeTier = getFeeTier(0, totalSrm)
|
|
|
|
const rates = getFeeRates(feeTier)
|
|
|
|
|
|
|
|
return { totalSrm, feeTier, rates }
|
|
|
|
}
|
|
|
|
|
|
|
|
export default useSrmAccount
|