Feature/add telemetry to fees (#346)
* add telemetry to fees * fix * fix * remove txid * fix
This commit is contained in:
parent
718848cfce
commit
34311a713b
|
@ -11,6 +11,8 @@ import useLocalStorageState from 'hooks/useLocalStorageState'
|
|||
import { DEFAULT_PRIORITY_FEE_LEVEL } from './settings/RpcSettings'
|
||||
import { useHiddenMangoAccounts } from 'hooks/useHiddenMangoAccounts'
|
||||
import { notify } from 'utils/notifications'
|
||||
import { usePlausible } from 'next-plausible'
|
||||
import { TelemetryEvents } from 'utils/telemetry'
|
||||
|
||||
const set = mangoStore.getState().set
|
||||
const actions = mangoStore.getState().actions
|
||||
|
@ -22,6 +24,7 @@ const HydrateStore = () => {
|
|||
const connection = mangoStore((s) => s.connection)
|
||||
const slowNetwork = useNetworkSpeed()
|
||||
const { wallet } = useWallet()
|
||||
const telemetry = usePlausible<TelemetryEvents>()
|
||||
|
||||
const [, setLastWalletName] = useLocalStorageState(LAST_WALLET_NAME, '')
|
||||
|
||||
|
@ -113,7 +116,7 @@ const HydrateStore = () => {
|
|||
localStorage.getItem(PRIORITY_FEE_KEY) ??
|
||||
DEFAULT_PRIORITY_FEE_LEVEL.value,
|
||||
)
|
||||
actions.estimatePriorityFee(priorityFeeMultiplier)
|
||||
actions.estimatePriorityFee(priorityFeeMultiplier, telemetry)
|
||||
}
|
||||
},
|
||||
(slowNetwork ? 60 : 10) * SECONDS,
|
||||
|
|
|
@ -88,6 +88,7 @@ import groupBy from 'lodash/groupBy'
|
|||
import sampleSize from 'lodash/sampleSize'
|
||||
import { fetchTokenStatsData, processTokenStatsData } from 'apis/mngo'
|
||||
import { OrderTypes } from 'utils/tradeForm'
|
||||
import { usePlausible } from 'next-plausible'
|
||||
|
||||
const GROUP = new PublicKey('78b8f4cGCwmZ9ysPFMWLaLTkkaYnUjwMJYStWe5RTSSX')
|
||||
|
||||
|
@ -126,6 +127,8 @@ const initMangoClient = (
|
|||
prependedGlobalAdditionalInstructions: [],
|
||||
multipleProviders: [],
|
||||
},
|
||||
//for analytics use
|
||||
telemetry: ReturnType<typeof usePlausible> | null,
|
||||
): MangoClient => {
|
||||
return MangoClient.connect(provider, CLUSTER, MANGO_V4_ID[CLUSTER], {
|
||||
prioritizationFee: opts.prioritizationFee,
|
||||
|
@ -133,6 +136,12 @@ const initMangoClient = (
|
|||
opts.prependedGlobalAdditionalInstructions,
|
||||
idsSource: 'api',
|
||||
postSendTxCallback: ({ txid }: { txid: string }) => {
|
||||
if (telemetry) {
|
||||
telemetry('postSendTx', {
|
||||
props: { fee: opts.prioritizationFee },
|
||||
})
|
||||
}
|
||||
|
||||
notify({
|
||||
title: 'Transaction sent',
|
||||
description: 'Waiting for confirmation',
|
||||
|
@ -294,6 +303,7 @@ export type MangoStore = {
|
|||
width: number
|
||||
height: number
|
||||
}
|
||||
telemetry: ReturnType<typeof usePlausible> | null
|
||||
actions: {
|
||||
fetchActivityFeed: (
|
||||
mangoAccountPk: string,
|
||||
|
@ -323,7 +333,10 @@ export type MangoStore = {
|
|||
setPrependedGlobalAdditionalInstructions: (
|
||||
instructions: TransactionInstruction[],
|
||||
) => void
|
||||
estimatePriorityFee: (feeMultiplier: number) => Promise<void>
|
||||
estimatePriorityFee: (
|
||||
feeMultiplier: number,
|
||||
telemetry: ReturnType<typeof usePlausible> | null,
|
||||
) => Promise<void>
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,11 +376,15 @@ const mangoStore = create<MangoStore>()(
|
|||
emptyWallet,
|
||||
options,
|
||||
)
|
||||
const client = initMangoClient(provider, {
|
||||
prioritizationFee: DEFAULT_PRIORITY_FEE,
|
||||
prependedGlobalAdditionalInstructions: [],
|
||||
multipleProviders: backupProviders,
|
||||
})
|
||||
const client = initMangoClient(
|
||||
provider,
|
||||
{
|
||||
prioritizationFee: DEFAULT_PRIORITY_FEE,
|
||||
prependedGlobalAdditionalInstructions: [],
|
||||
multipleProviders: backupProviders,
|
||||
},
|
||||
null,
|
||||
)
|
||||
|
||||
return {
|
||||
activityFeed: {
|
||||
|
@ -482,6 +499,7 @@ const mangoStore = create<MangoStore>()(
|
|||
width: 0,
|
||||
height: 0,
|
||||
},
|
||||
telemetry: null,
|
||||
actions: {
|
||||
fetchActivityFeed: async (
|
||||
mangoAccountPk: string,
|
||||
|
@ -1007,12 +1025,16 @@ const mangoStore = create<MangoStore>()(
|
|||
)
|
||||
const priorityFee = get().priorityFee ?? DEFAULT_PRIORITY_FEE
|
||||
|
||||
const client = initMangoClient(provider, {
|
||||
prioritizationFee: priorityFee,
|
||||
prependedGlobalAdditionalInstructions:
|
||||
get().prependedGlobalAdditionalInstructions,
|
||||
multipleProviders: backupProviders,
|
||||
})
|
||||
const client = initMangoClient(
|
||||
provider,
|
||||
{
|
||||
prioritizationFee: priorityFee,
|
||||
prependedGlobalAdditionalInstructions:
|
||||
get().prependedGlobalAdditionalInstructions,
|
||||
multipleProviders: backupProviders,
|
||||
},
|
||||
null,
|
||||
)
|
||||
|
||||
set((s) => {
|
||||
s.client = client
|
||||
|
@ -1036,11 +1058,15 @@ const mangoStore = create<MangoStore>()(
|
|||
const provider = client.program.provider as AnchorProvider
|
||||
provider.opts.skipPreflight = true
|
||||
|
||||
const newClient = initMangoClient(provider, {
|
||||
prioritizationFee: get().priorityFee,
|
||||
prependedGlobalAdditionalInstructions: instructions,
|
||||
multipleProviders: [],
|
||||
})
|
||||
const newClient = initMangoClient(
|
||||
provider,
|
||||
{
|
||||
prioritizationFee: get().priorityFee,
|
||||
prependedGlobalAdditionalInstructions: instructions,
|
||||
multipleProviders: [],
|
||||
},
|
||||
null,
|
||||
)
|
||||
|
||||
set((s) => {
|
||||
s.client = newClient
|
||||
|
@ -1121,23 +1147,29 @@ const mangoStore = create<MangoStore>()(
|
|||
options,
|
||||
)
|
||||
newProvider.opts.skipPreflight = true
|
||||
const newClient = initMangoClient(newProvider, {
|
||||
prependedGlobalAdditionalInstructions:
|
||||
get().prependedGlobalAdditionalInstructions,
|
||||
prioritizationFee: DEFAULT_PRIORITY_FEE,
|
||||
multipleProviders: [],
|
||||
})
|
||||
const newClient = initMangoClient(
|
||||
newProvider,
|
||||
{
|
||||
prependedGlobalAdditionalInstructions:
|
||||
get().prependedGlobalAdditionalInstructions,
|
||||
prioritizationFee: DEFAULT_PRIORITY_FEE,
|
||||
multipleProviders: [],
|
||||
},
|
||||
null,
|
||||
)
|
||||
set((state) => {
|
||||
state.connection = newConnection
|
||||
state.client = newClient
|
||||
})
|
||||
},
|
||||
estimatePriorityFee: async (feeMultiplier) => {
|
||||
estimatePriorityFee: async (feeMultiplier, telemetry) => {
|
||||
const set = get().set
|
||||
const group = mangoStore.getState().group
|
||||
const client = mangoStore.getState().client
|
||||
|
||||
const mangoAccount = get().mangoAccount.current
|
||||
const currentFee = get().priorityFee
|
||||
const currentTelemetry = get().telemetry
|
||||
if (!mangoAccount || !group || !client) return
|
||||
|
||||
const altResponse = await connection.getAddressLookupTable(
|
||||
|
@ -1176,16 +1208,25 @@ const mangoStore = create<MangoStore>()(
|
|||
|
||||
const provider = client.program.provider as AnchorProvider
|
||||
provider.opts.skipPreflight = true
|
||||
const newClient = initMangoClient(provider, {
|
||||
prioritizationFee: feeEstimate,
|
||||
prependedGlobalAdditionalInstructions:
|
||||
get().prependedGlobalAdditionalInstructions,
|
||||
multipleProviders: [],
|
||||
})
|
||||
set((state) => {
|
||||
state.priorityFee = feeEstimate
|
||||
state.client = newClient
|
||||
})
|
||||
|
||||
if (currentFee !== feeEstimate || !currentTelemetry) {
|
||||
const newClient = initMangoClient(
|
||||
provider,
|
||||
{
|
||||
prioritizationFee: feeEstimate,
|
||||
prependedGlobalAdditionalInstructions:
|
||||
get().prependedGlobalAdditionalInstructions,
|
||||
multipleProviders: [],
|
||||
},
|
||||
telemetry,
|
||||
)
|
||||
|
||||
set((state) => {
|
||||
state.priorityFee = feeEstimate
|
||||
state.client = newClient
|
||||
state.telemetry = telemetry
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -6,4 +6,5 @@ export type TelemetryEvents = {
|
|||
rewardsRenderUnsupported: { message: string }
|
||||
rewardsClaim: { rewards: number }
|
||||
rewardsClaimError: { message: string }
|
||||
postSendTx: { fee: number }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue