Skip to content

Commit

Permalink
feat: tx builder & simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
borcherd committed Oct 15, 2024
1 parent be8e6f0 commit 6c90512
Show file tree
Hide file tree
Showing 11 changed files with 570 additions and 100 deletions.
74 changes: 47 additions & 27 deletions apps/marginfi-v2-ui/src/components/common/Mint/MintCardWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { ActionBoxDialog } from "~/components/common/ActionBox";
import { LST_MINT } from "~/store/lstStore";

/// XXX
import { useWallet } from "~/components/wallet-v2/hooks/use-wallet.hook";

/// YYY

interface MintCardWrapperProps {
mintCard: MintCardProps;
}
Expand All @@ -31,6 +36,13 @@ export const MintCardWrapper: React.FC<MintCardWrapperProps> = ({ mintCard, ...p
null,
[extendedBankInfos]
);

// XXX

const { connected } = useWallet();

/// YYY

return (
<Card variant="default" className="relative">
<CardHeader className="pt-8">
Expand Down Expand Up @@ -73,33 +85,41 @@ export const MintCardWrapper: React.FC<MintCardWrapperProps> = ({ mintCard, ...p
)}

{mintCard.title === "LST" ? (
<ActionBoxDialog
requestedAction={requestedAction}
requestedBank={requestedAction === ActionType.UnstakeLST ? requestedBank : null}
>
<div className="flex items-center gap-2">
<Button
variant="secondary"
size="lg"
className="mt-4"
onClick={() => {
setRequestedAction(ActionType.MintLST);
}}
>
Stake {mintCard.title}
</Button>
<Button
variant="outline-dark"
size="lg"
className="mt-4 hover:text-primary"
onClick={() => {
setRequestedAction(ActionType.UnstakeLST);
}}
>
Unstake {mintCard.title}
</Button>
</div>
</ActionBoxDialog>
<div className="flex items-center gap-2">
<ActionBox.Stake
isDialog={true}
useProvider={true}
stakeProps={{
connected: connected,
requestedActionType: ActionType.MintLST,
}}
dialogProps={{
trigger: (
<Button variant="secondary" size="lg" className="mt-4">
Stake {mintCard.title}
</Button>
),
title: "Mint LST",
}}
/>
<ActionBox.Stake
isDialog={true}
useProvider={true}
stakeProps={{
connected: connected,
requestedActionType: ActionType.UnstakeLST,
requestedBank: extendedBankInfos.find((bank) => bank?.info?.state?.mint.equals(LST_MINT)),
}}
dialogProps={{
trigger: (
<Button variant="outline-dark" size="lg" className="mt-4 hover:text-primary">
Unstake {mintCard.title}
</Button>
),
title: "Unstake LST",
}}
/>
</div>
) : transformedActionGate?.find((value) => value === ActionType.MintYBX) ? (
<div className="flex items-center gap-2">
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import { PortfolioUserStats, PortfolioAssetCard, PortfolioAssetCardSkeleton } fr
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/components/ui/tooltip";
import { ActionBox } from "@mrgnlabs/mrgn-ui";

/// XXX
import { useWallet } from "~/components/wallet-v2/hooks/use-wallet.hook";

/// YYY

export const LendingPortfolio = () => {
const router = useRouter();

Expand Down Expand Up @@ -99,12 +94,6 @@ export const LendingPortfolio = () => {
}
}, [accountSummary.healthFactor]);

// XXX

const { connected } = useWallet();

/// YYY

if (!lendingBanks.length && !borrowingBanks.length && isStoreInitialized) {
return (
<p className="text-center mt-4 text-muted-foreground">
Expand Down Expand Up @@ -170,18 +159,6 @@ export const LendingPortfolio = () => {
netValue={accountNetValue}
points={numeralFormatter(userPointsData.totalPoints)}
/>
<ActionBox.Stake
isDialog={true}
useProvider={true}
stakeProps={{
connected: connected,
requestedActionType: ActionType.MintLST,
}}
dialogProps={{
trigger: <div className="flex items-center gap-2 w-full">Dit is een trigger</div>,
title: "test",
}}
/>
</div>
<div className="flex flex-col md:flex-row justify-between flex-wrap gap-8 md:gap-20">
<div className="flex flex-col flex-1 gap-4 md:min-w-[340px]">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export const BankSelect = ({
nativeSolBalance,
actionMode,
connected,
// isSelectable = true,

setSelectedBank,
}: BankSelectProps) => {
const isSelectable = React.useMemo(() => true, []);
const [isOpen, setIsOpen] = React.useState(false);

const isSelectable = React.useMemo(() => selectedBank === null || selectedBank === undefined, [selectedBank]);

return (
<>
{!isSelectable && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { ActionStatItem } from "~/components/action-box-v2/components";
import {
getPriceImpactStat,
getSlippageStat,
getSupplyStat,
getProjectedAPYStat,
getCurrentPriceStat,
getCommissionStat,
getLstSupplyStat,
} from "~/components/action-box-v2/utils";

interface StakeActionSummary {
Expand Down Expand Up @@ -84,9 +84,9 @@ function generateStakeStats(
stats.push(getSlippageStat(summary.simulationPreview?.splippage));
}

stats.push(getSupplyStat(summary.actionPreview.supply, false, bank.info.state.totalBorrows));
stats.push(getProjectedAPYStat(summary.actionPreview.projectedApy, false));
stats.push(getCurrentPriceStat(summary.actionPreview.currentPrice, false));
stats.push(getLstSupplyStat(summary.actionPreview.supply));
stats.push(getProjectedAPYStat(summary.actionPreview.projectedApy));
stats.push(getCurrentPriceStat(summary.actionPreview.currentPrice));
stats.push(getCommissionStat(summary.actionPreview.commission));

return stats;
Expand Down
Loading

0 comments on commit 6c90512

Please sign in to comment.