LP Deposit Page

This page will display a form to add & edit liquidity to the jackpot. It also lets users adjust their risk percentage (Position in Range) for the current jackpot as well as withdraw their liquidity.

This references our Jackpot Demo Integration Github Repo. You can find the code for the demo integration here.

LP Pool Status

This component will display the status of the LP Pool.

// /app/components/lp-pool-status.tsx

import { LiquidityComponent } from '@/components/lp-component';

export default function LiquidityPage() {
    return <LiquidityComponent />;
}

Liquidity Component

This component will display the liquidity component.

'use client';

import { getLpPoolStatus, getLpsInfo } from '@/lib/contract';
import { useEffect, useState, useCallback } from 'react';
import { useAccount } from 'wagmi';
import { LpDepositForm } from './lp-components/lp-deposit-form';
import { LpPoolStatus } from './lp-components/lp-pool-status';
import { UserLpBalances } from './lp-components/user-lp-balances';

interface LpState {
    lpsInfo?: [bigint, bigint, bigint, boolean];
    lpPoolStatus?: boolean;
    isLoading: boolean;
    error?: string;
}

export function LiquidityComponent() {
    const { address, isConnected } = useAccount();
    const [state, setState] = useState<LpState>({
        isLoading: true,
    });

    const fetchLpPoolStatus = useCallback(async () => {
        try {
            const status = await getLpPoolStatus();
            setState((prev) => ({ ...prev, lpPoolStatus: status }));
        } catch (error) {
            setState((prev) => ({
                ...prev,
                error: 'Failed to fetch pool status',
            }));
        } finally {
            setState((prev) => ({ ...prev, isLoading: false }));
        }
    }, []);

    const fetchLpsInfo = useCallback(async () => {
        if (!address) return;

        setState((prev) => ({ ...prev, isLoading: true }));
        try {
            const info = await getLpsInfo(address as `0x${string}`);
            setState((prev) => ({ ...prev, lpsInfo: info }));
        } catch (error) {
            setState((prev) => ({
                ...prev,
                error: 'Failed to fetch LP info',
                lpsInfo: undefined,
            }));
        } finally {
            setState((prev) => ({ ...prev, isLoading: false }));
        }
    }, [address]);

    useEffect(() => {
        fetchLpPoolStatus();
        return () => {
            setState({ isLoading: true });
        };
    }, [fetchLpPoolStatus]);

    useEffect(() => {
        if (isConnected && address) {
            fetchLpsInfo();
        }
    }, [isConnected, address, fetchLpsInfo]);

    if (state.error) {
        return <div className="text-red-500">{state.error}</div>;
    }

    return (
        <div className="space-y-6">
            {state.isLoading ? (
                <div className="animate-pulse">Loading...</div>
            ) : (
                <>
                    <LpPoolStatus poolStatus={state.lpPoolStatus ?? false} />
                    {state.lpPoolStatus && address && (
                        <LpDepositForm address={address} />
                    )}
                    {state.lpsInfo && state.lpsInfo[0] > BigInt(0) && (
                        <UserLpBalances lpInfo={state.lpsInfo} />
                    )}
                </>
            )}
        </div>
    );
}

Lp Pool Status

This component will display the status of the LP Pool. Whether it is open or closed.

Lp Deposit Form

This component will display the form to add & edit liquidity to the jackpot as well as set the initial risk percentage (Position in Range).

Deposit Input

This component will display the input for the deposit amount & risk percentage (Position in Range).

Min Lp Deposit

This component will display the minimum deposit amount for the current jackpot.

Risk Percentage

This component will allow the user to adjust their risk percentage (Position in Range) for future jackpots.

Form Button

This component will display the button to add & edit liquidity to the jackpot as well as set the initial risk percentage (Position in Range).

Lp Balances

This component will display the user's LP balances.

  • Principal - This is how much liquidity is deposited but not in range. Position in Range is 100%

  • Position in Range - This is how much liquidity is in range. Position in Range is how much liquidity is at risk in the current jackpot.

  • Risk Percentage - This is the risk percentage (Position in Range) for the current jackpot.

Adjust Risk Percentage

This component will allow the user to adjust their risk percentage (Position in Range) for future jackpots.

Last updated