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