-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lp inspect: move registry info to frontend (#197)
- Loading branch information
Showing
14 changed files
with
407 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,117 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { PositionTimelineResponse } from '@/shared/api/server/position/timeline/types'; | ||
import { | ||
PositionExecutions, | ||
PositionStateResponse, | ||
PositionTimelineResponse, | ||
PositionWithdrawal, | ||
VolumeAndFeesResponse, | ||
} from '@/shared/api/server/position/timeline/types'; | ||
import { apiFetch } from '@/shared/utils/api-fetch.ts'; | ||
import { | ||
PositionExecutionsVV, | ||
PositionStateVV, | ||
PositionTimelineResponseVV, | ||
PositionWithdrawalVV, | ||
VolumeAndFeesAll, | ||
} from '@/pages/inspect/lp/api/types.ts'; | ||
import { Registry } from '@penumbra-labs/registry'; | ||
import { registryQueryFn } from '@/shared/api/registry.ts'; | ||
import { getValueView } from '@/shared/api/server/book/helpers.ts'; | ||
|
||
const positionsStateAddVV = (res: PositionStateResponse, registry: Registry): PositionStateVV => { | ||
return { | ||
reserves1: getValueView(registry, res.reserves1), | ||
reserves2: getValueView(registry, res.reserves2), | ||
unit1: getValueView(registry, res.unit1), | ||
unit2: getValueView(registry, res.unit2), | ||
offer1: getValueView(registry, res.offer1), | ||
offer2: getValueView(registry, res.offer2), | ||
priceRef1: getValueView(registry, res.priceRef1), | ||
priceRef2: getValueView(registry, res.priceRef2), | ||
priceRef1Inv: getValueView(registry, res.priceRef1Inv), | ||
priceRef2Inv: getValueView(registry, res.priceRef2Inv), | ||
feeBps: res.feeBps, | ||
openingHeight: res.openingHeight, | ||
openingTime: res.openingTime, | ||
openingTx: res.openingTx, | ||
closingHeight: res.closingHeight, | ||
closingTime: res.closingTime, | ||
closingTx: res.closingTx, | ||
}; | ||
}; | ||
|
||
const executionsAddVV = (res: PositionExecutions, registry: Registry): PositionExecutionsVV => { | ||
return { | ||
items: res.items.map(p => ({ | ||
input: getValueView(registry, p.input), | ||
output: getValueView(registry, p.output), | ||
fee: getValueView(registry, p.fee), | ||
reserves1: getValueView(registry, p.reserves1), | ||
reserves2: getValueView(registry, p.reserves2), | ||
contextStart: registry.getMetadata(p.contextStart), | ||
contextEnd: registry.getMetadata(p.contextEnd), | ||
time: p.time, | ||
height: p.height, | ||
})), | ||
skipped: res.skipped, | ||
}; | ||
}; | ||
|
||
const withdrawalsAddVV = ( | ||
res: PositionWithdrawal[], | ||
registry: Registry, | ||
): PositionWithdrawalVV[] => { | ||
return res.map(w => ({ | ||
reserves1: getValueView(registry, w.reserves1), | ||
reserves2: getValueView(registry, w.reserves2), | ||
time: w.time, | ||
height: w.height, | ||
txHash: w.txHash, | ||
})); | ||
}; | ||
|
||
const volumeAddVV = (res: VolumeAndFeesResponse, registry: Registry): VolumeAndFeesAll => { | ||
return { | ||
asset1: registry.getMetadata(res.asset1), | ||
asset2: registry.getMetadata(res.asset2), | ||
totals: { | ||
volume1: getValueView(registry, res.totals.volume1), | ||
volume2: getValueView(registry, res.totals.volume2), | ||
fees1: getValueView(registry, res.totals.fees1), | ||
fees2: getValueView(registry, res.totals.fees2), | ||
executionCount: res.totals.executionCount, | ||
}, | ||
all: res.all.map(v => ({ | ||
volume1: getValueView(registry, v.volume1), | ||
volume2: getValueView(registry, v.volume2), | ||
fees1: getValueView(registry, v.fees1), | ||
fees2: getValueView(registry, v.fees2), | ||
contextAssetStart: registry.getMetadata(v.contextAssetStart), | ||
contextAssetEnd: registry.getMetadata(v.contextAssetEnd), | ||
executionCount: v.executionCount, | ||
})), | ||
}; | ||
}; | ||
|
||
const timelineFetch = async (id: string): Promise<PositionTimelineResponseVV> => { | ||
const result = await apiFetch<PositionTimelineResponse>( | ||
`/api/position/timeline?positionId=${id}`, | ||
); | ||
|
||
const registry = await registryQueryFn(); | ||
|
||
return { | ||
state: positionsStateAddVV(result.state, registry), | ||
executions: executionsAddVV(result.executions, registry), | ||
withdrawals: withdrawalsAddVV(result.withdrawals, registry), | ||
volumeAndFees: volumeAddVV(result.volumeAndFees, registry), | ||
}; | ||
}; | ||
|
||
export const useLpPosition = (id: string) => { | ||
return useQuery({ | ||
queryKey: ['lpPosition', id], | ||
retry: 1, | ||
queryFn: async () => | ||
apiFetch<PositionTimelineResponse>(`/api/position/timeline?positionId=${id}`), | ||
queryFn: () => timelineFetch(id), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Metadata, ValueView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb'; | ||
|
||
export interface PositionStateVV { | ||
reserves1: ValueView; | ||
reserves2: ValueView; | ||
unit1: ValueView; | ||
unit2: ValueView; | ||
offer1: ValueView; | ||
offer2: ValueView; | ||
priceRef1: ValueView; | ||
priceRef2: ValueView; | ||
priceRef1Inv: ValueView; | ||
priceRef2Inv: ValueView; | ||
feeBps: number; | ||
openingHeight: number; | ||
openingTime: string; | ||
openingTx?: string; | ||
closingHeight?: number; | ||
closingTime?: string; | ||
closingTx?: string; | ||
} | ||
|
||
export interface VolumeAndFeesVV { | ||
volume1: ValueView; | ||
volume2: ValueView; | ||
fees1: ValueView; | ||
fees2: ValueView; | ||
contextAssetStart: Metadata; | ||
contextAssetEnd: Metadata; | ||
executionCount: number; | ||
} | ||
|
||
export interface VolumeAndFeesAll { | ||
asset1: Metadata; | ||
asset2: Metadata; | ||
totals: Omit<VolumeAndFeesVV, 'contextAssetStart' | 'contextAssetEnd'>; | ||
all: VolumeAndFeesVV[]; | ||
} | ||
|
||
export interface PositionWithdrawalVV { | ||
reserves1: ValueView; | ||
reserves2: ValueView; | ||
time: string; | ||
height: number; | ||
txHash: string; | ||
} | ||
|
||
export interface PositionExecutionVV { | ||
input: ValueView; | ||
output: ValueView; | ||
fee: ValueView; | ||
reserves1: ValueView; | ||
reserves2: ValueView; | ||
contextStart: Metadata; | ||
contextEnd: Metadata; | ||
time: string; | ||
height: number; | ||
} | ||
|
||
export interface PositionExecutionsVV { | ||
items: PositionExecutionVV[]; | ||
skipped: number; | ||
} | ||
|
||
export interface PositionTimelineResponseVV { | ||
executions: PositionExecutionsVV; | ||
state: PositionStateVV; | ||
withdrawals: PositionWithdrawalVV[]; | ||
volumeAndFees: VolumeAndFeesAll; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.