From e1914e5849c60077bd519887e74b5f254eaadd9b Mon Sep 17 00:00:00 2001 From: Gabe Rodriguez Date: Thu, 29 Aug 2024 14:55:52 +0200 Subject: [PATCH] LP position action views (#187) --- packages/ui/components/ui/tx/action-view.tsx | 9 +- .../ui/tx/actions-views/position-close.tsx | 21 +++ .../ui/tx/actions-views/position-open.tsx | 126 ++++++++++++++++++ .../ui/tx/actions-views/position-withdraw.tsx | 32 +++++ 4 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 packages/ui/components/ui/tx/actions-views/position-close.tsx create mode 100644 packages/ui/components/ui/tx/actions-views/position-open.tsx create mode 100644 packages/ui/components/ui/tx/actions-views/position-withdraw.tsx diff --git a/packages/ui/components/ui/tx/action-view.tsx b/packages/ui/components/ui/tx/action-view.tsx index 6506dc09..79c0b0a9 100644 --- a/packages/ui/components/ui/tx/action-view.tsx +++ b/packages/ui/components/ui/tx/action-view.tsx @@ -14,6 +14,9 @@ import { ActionDutchAuctionWithdrawViewComponent } from './actions-views/action- import { ValueView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb'; import { DelegatorVoteComponent } from './actions-views/delegator-vote'; import { ValidatorVoteComponent } from './actions-views/validator-vote'; +import { PositionOpenComponent } from './actions-views/position-open'; +import { PositionCloseComponent } from './actions-views/position-close'; +import { PositionWithdrawComponent } from './actions-views/position-withdraw'; type Case = Exclude; @@ -121,13 +124,13 @@ export const ActionViewComponent = ({ return ; case 'positionOpen': - return ; + return ; case 'positionClose': - return ; + return ; case 'positionWithdraw': - return ; + return ; case 'positionRewardClaim': return ; diff --git a/packages/ui/components/ui/tx/actions-views/position-close.tsx b/packages/ui/components/ui/tx/actions-views/position-close.tsx new file mode 100644 index 00000000..c5a486a7 --- /dev/null +++ b/packages/ui/components/ui/tx/actions-views/position-close.tsx @@ -0,0 +1,21 @@ +import { ViewBox } from '../viewbox'; +import { ActionDetails } from './action-details'; +import { PositionClose } from '@penumbra-zone/protobuf/penumbra/core/component/dex/v1/dex_pb'; +import { bech32mPositionId } from '@penumbra-zone/bech32m/plpid'; + +export const PositionCloseComponent = ({ value }: { value: PositionClose }) => { + return ( + + {value.positionId && ( + + {bech32mPositionId(value.positionId)} + + )} + + } + /> + ); +}; diff --git a/packages/ui/components/ui/tx/actions-views/position-open.tsx b/packages/ui/components/ui/tx/actions-views/position-open.tsx new file mode 100644 index 00000000..60617ccc --- /dev/null +++ b/packages/ui/components/ui/tx/actions-views/position-open.tsx @@ -0,0 +1,126 @@ +import { ViewBox } from '../viewbox'; +import { ActionDetails } from './action-details'; +import { uint8ArrayToBase64 } from '@penumbra-zone/types/base64'; +import { + PositionOpen, + PositionState_PositionStateEnum, +} from '@penumbra-zone/protobuf/penumbra/core/component/dex/v1/dex_pb'; +import { joinLoHiAmount } from '@penumbra-zone/types/amount'; +import { bech32mAssetId } from '@penumbra-zone/bech32m/passet'; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../tooltip'; +import { InfoIcon } from 'lucide-react'; + +export const PositionOpenComponent = ({ value }: { value: PositionOpen }) => { + return ( + + + {stateToString(value.position?.state?.state)} + + + + {value.position?.state?.sequence ? value.position.state.sequence.toString() : '0'} + + + {!!value.position?.phi?.pair?.asset1 && ( + + + {bech32mAssetId(value.position.phi.pair.asset1)} + + + )} + + {!!value.position?.phi?.pair?.asset2 && ( + + + {bech32mAssetId(value.position.phi.pair.asset2)} + + + )} + + {!!value.position?.phi?.component?.fee && ( + {value.position.phi.component.fee} + )} + + {value.position?.nonce && ( + + + {uint8ArrayToBase64(value.position.nonce)} + + + )} + + + {value.position?.closeOnFill ? 'true' : 'false'} + + +
+

Trading Parameters

+ + + + + + +

+ p and q are the price coefficients of the trading function: phi(r1, r2) = p * r1 + + q * r2, where r1 and r2 represent the old and new reserves. +

+
+
+
+
+ + {value.position?.phi?.component?.p && ( + + {joinLoHiAmount(value.position.phi.component.p).toString()} + + )} + + {value.position?.phi?.component?.q && ( + + {joinLoHiAmount(value.position.phi.component.q).toString()} + + )} + + {value.position?.reserves?.r1 && ( + + {joinLoHiAmount(value.position.reserves.r1).toString()} + + )} + + {value.position?.reserves?.r2 && ( + + {joinLoHiAmount(value.position.reserves.r2).toString()} + + )} + + } + /> + ); +}; + +export const stateToString = (state?: PositionState_PositionStateEnum): string => { + switch (state) { + case PositionState_PositionStateEnum.UNSPECIFIED: { + return 'UNSPECIFIED'; + } + case PositionState_PositionStateEnum.OPENED: { + return 'OPENED'; + } + case PositionState_PositionStateEnum.CLOSED: { + return 'CLOSED'; + } + case PositionState_PositionStateEnum.WITHDRAWN: { + return 'WITHDRAWN'; + } + case PositionState_PositionStateEnum.CLAIMED: { + return 'CLAIMED'; + } + case undefined: { + return 'UNSPECIFIED'; + } + } +}; diff --git a/packages/ui/components/ui/tx/actions-views/position-withdraw.tsx b/packages/ui/components/ui/tx/actions-views/position-withdraw.tsx new file mode 100644 index 00000000..cb1ad874 --- /dev/null +++ b/packages/ui/components/ui/tx/actions-views/position-withdraw.tsx @@ -0,0 +1,32 @@ +import { ViewBox } from '../viewbox'; +import { ActionDetails } from './action-details'; +import { PositionWithdraw } from '@penumbra-zone/protobuf/penumbra/core/component/dex/v1/dex_pb'; +import { bech32mPositionId } from '@penumbra-zone/bech32m/plpid'; +import { uint8ArrayToBase64 } from '@penumbra-zone/types/base64'; + +export const PositionWithdrawComponent = ({ value }: { value: PositionWithdraw }) => { + return ( + + {value.positionId && ( + + {bech32mPositionId(value.positionId)} + + )} + + + {value.sequence ? value.sequence.toString() : '0'} + + + {value.reservesCommitment?.inner && ( + + {uint8ArrayToBase64(value.reservesCommitment.inner)} + + )} + + } + /> + ); +};