add srm dex fee discount table
This commit is contained in:
parent
8da8d0d973
commit
afb09d828b
|
@ -4,14 +4,13 @@ import OpenOrdersTable from './OpenOrdersTable'
|
|||
import BalancesTable from './BalancesTable'
|
||||
import PositionsTable from './PerpPositionsTable'
|
||||
import TradeHistoryTable from './TradeHistoryTable'
|
||||
// import { Position } from '../public/charting_library/charting_library'
|
||||
// import FeeDiscountsTable from './FeeDiscountsTable'
|
||||
import FeeDiscountsTable from './FeeDiscountsTable'
|
||||
|
||||
const TABS = [
|
||||
'Balances',
|
||||
'Open Orders',
|
||||
'Perp Positions',
|
||||
/*'Fee Discounts'*/
|
||||
'Fee Discounts',
|
||||
'Trade History',
|
||||
]
|
||||
|
||||
|
@ -74,8 +73,8 @@ const TabContent = ({ activeTab }) => {
|
|||
return <TradeHistoryTable />
|
||||
case 'Perp Positions':
|
||||
return <PositionsTable />
|
||||
// case 'Fee Discounts':
|
||||
// return <FeeDiscountsTable />
|
||||
case 'Fee Discounts':
|
||||
return <FeeDiscountsTable />
|
||||
default:
|
||||
return <BalancesTable />
|
||||
}
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
import useMangoStore from '../stores/useMangoStore'
|
||||
import { useState } from 'react'
|
||||
import useMangoStore, { DEFAULT_CONNECTION } from '../stores/useMangoStore'
|
||||
import { nativeToUi } from '@blockworks-foundation/mango-client'
|
||||
import { SRM_DECIMALS } from '@project-serum/serum/lib/token-instructions'
|
||||
import { getFeeTier, getFeeRates } from '@project-serum/serum'
|
||||
import { parseTokenAccountData } from '../utils/tokens'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const useSrmAccount = () => {
|
||||
const srmAccount = useMangoStore((s) => s.selectedMangoGroup.srmAccount)
|
||||
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
|
||||
const [srmAccount, setSrmAccount] = useState(null)
|
||||
// const [msrmAccount, setMsrmAccount] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
const srmPk = mangoGroup.srmVault
|
||||
const fetchAccounts = async () => {
|
||||
const srmAccountInfo = await DEFAULT_CONNECTION.getAccountInfo(srmPk)
|
||||
|
||||
setSrmAccount(srmAccountInfo)
|
||||
}
|
||||
|
||||
fetchAccounts()
|
||||
}, [mangoGroup])
|
||||
|
||||
const accountData = srmAccount
|
||||
? parseTokenAccountData(srmAccount?.data)
|
||||
|
|
|
@ -80,8 +80,6 @@ export const INITIAL_STATE = {
|
|||
connected: false,
|
||||
current: null,
|
||||
tokens: [],
|
||||
srmAccountsForOwner: [],
|
||||
contributedSrm: 0,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -154,8 +152,6 @@ interface MangoStore extends State {
|
|||
connected: boolean
|
||||
current: WalletAdapter | undefined
|
||||
tokens: WalletToken[]
|
||||
srmAccountsForOwner: any[]
|
||||
contributedSrm: number
|
||||
}
|
||||
settings: {
|
||||
uiLocked: boolean
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import { ACCOUNT_LAYOUT } from '@blockworks-foundation/mango-client'
|
||||
import { Connection, PublicKey } from '@solana/web3.js'
|
||||
import * as bs58 from 'bs58'
|
||||
import { TokenInstructions } from '@project-serum/serum'
|
||||
import { WRAPPED_SOL_MINT } from '@project-serum/serum/lib/token-instructions'
|
||||
import { TokenAccountLayout } from '@blockworks-foundation/mango-client'
|
||||
import { PublicKey } from '@solana/web3.js'
|
||||
|
||||
export const TOKEN_PROGRAM_ID = new PublicKey(
|
||||
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
|
||||
|
@ -18,73 +15,10 @@ export function parseTokenAccountData(data: Buffer): {
|
|||
owner: PublicKey
|
||||
amount: number
|
||||
} {
|
||||
const { mint, owner, amount } = ACCOUNT_LAYOUT.decode(data)
|
||||
const { mint, owner, amount } = TokenAccountLayout.decode(data)
|
||||
return {
|
||||
mint: new PublicKey(mint),
|
||||
owner: new PublicKey(owner),
|
||||
amount,
|
||||
}
|
||||
}
|
||||
|
||||
// export async function getWalletTokenInfo(
|
||||
// connection: Connection,
|
||||
// ownerPublicKey: PublicKey
|
||||
// ) {
|
||||
// const splAccounts = await getOwnedTokenAccounts(connection, ownerPublicKey)
|
||||
// const account = await connection.getAccountInfo(ownerPublicKey)
|
||||
// if (!account) return splAccounts
|
||||
// return [
|
||||
// {
|
||||
// publicKey: ownerPublicKey,
|
||||
// account: {
|
||||
// mint: WRAPPED_SOL_MINT,
|
||||
// owner: ownerPublicKey,
|
||||
// amount: account.lamports,
|
||||
// },
|
||||
// },
|
||||
// ].concat(splAccounts)
|
||||
// }
|
||||
|
||||
// export async function getOwnedTokenAccounts(
|
||||
// connection: Connection,
|
||||
// publicKey: PublicKey
|
||||
// ): Promise<any[]> {
|
||||
// const filters = getOwnedAccountsFilters(publicKey)
|
||||
// // @ts-ignore
|
||||
// const resp = await connection._rpcRequest('getProgramAccounts', [
|
||||
// TokenInstructions.TOKEN_PROGRAM_ID.toBase58(),
|
||||
// {
|
||||
// commitment: connection.commitment,
|
||||
// filters,
|
||||
// },
|
||||
// ])
|
||||
// if (resp.error) {
|
||||
// throw new Error(
|
||||
// 'failed to get token accounts owned by ' +
|
||||
// publicKey.toBase58() +
|
||||
// ': ' +
|
||||
// resp.error.message
|
||||
// )
|
||||
// }
|
||||
// return resp.result.map(({ pubkey, account: { data } }) => {
|
||||
// data = bs58.decode(data)
|
||||
// return {
|
||||
// publicKey: new PublicKey(pubkey),
|
||||
// account: parseTokenAccountData(data),
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// export function getOwnedAccountsFilters(publicKey: PublicKey) {
|
||||
// return [
|
||||
// {
|
||||
// memcmp: {
|
||||
// offset: ACCOUNT_LAYOUT.offsetOf('owner'),
|
||||
// bytes: publicKey.toBase58(),
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// dataSize: ACCOUNT_LAYOUT.span,
|
||||
// },
|
||||
// ]
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue