Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
feat: wormhole bridge implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
babchenko committed Oct 29, 2024
1 parent df3d147 commit 4625ad1
Show file tree
Hide file tree
Showing 19 changed files with 24,431 additions and 13,442 deletions.
4 changes: 4 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const nextConfig = {
source: "/api/prod-rpc-helius",
destination: `https://mainnet.helius-rpc.com/?api-key=${process.env.PROD_RPC_KEY_HELIUM}`,
},
{
source: "/api/prod-rpc-drpc",
destination: `https://lb.drpc.org/ogrpc?network=solana&dkey=${process.env.PROD_RRC_KET_DRPC}`,
},
];
},
};
Expand Down
37,570 changes: 24,180 additions & 13,390 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@solflare-wallet/wallet-adapter": "^1.0.3",
"@tiplink/wallet-adapter": "^2.1.20",
"@walletconnect/solana-adapter": "^0.0.6",
"@wormhole-foundation/wormhole-connect": "^1.1.2",
"lodash.debounce": "^4.0.8",
"next": "^14.2.15",
"react": "^18",
Expand Down
Binary file added public/logo/splyce-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 20 additions & 9 deletions src/components/Base/PageContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Container, styled, Typography } from "@mui/material";
import { BaseInfoBox } from "@/components/Base/Boxes/StyledBoxes";
import { BaseInfoIcon } from "@/components/Base/Icons/StyledIcons";
import { FC, ReactNode } from "react";

const PageInfoBox = styled(BaseInfoBox)`
background: #071f2e;
Expand Down Expand Up @@ -28,17 +29,27 @@ const PageInfoBox = styled(BaseInfoBox)`
}
`;

const PageContainer = ({ children }) => {
type PageContainerProps = {
children: ReactNode;
displayNotice?: boolean;
};

const PageContainer: FC<PageContainerProps> = ({
children,
displayNotice = true,
}) => {
return (
<Container>
<PageInfoBox>
<BaseInfoIcon />
<Box flexDirection="column">
<Typography width="100%">
This is test launch, use at your own risk
</Typography>
</Box>
</PageInfoBox>
{displayNotice && (
<PageInfoBox>
<BaseInfoIcon />
<Box flexDirection="column">
<Typography width="100%">
This is test launch, use at your own risk
</Typography>
</Box>
</PageInfoBox>
)}
{children}
</Container>
);
Expand Down
15 changes: 8 additions & 7 deletions src/components/Vaults/Detail/Forms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const VaultFormWrapper = styled(FlexBox)`
`;

const VaultDetailForms = () => {
const [notLoading, setNotLoaded] = useState(false);
const [isLoaded, setIsLoaded] = useState<boolean>(false);

const {
vaultPosition,
Expand All @@ -39,15 +39,17 @@ const VaultDetailForms = () => {

useEffect(() => {
const timeout = setTimeout(() => {
setNotLoaded(vaultPosition && !vaultPositionLoading && !vaultLoading);
setIsLoaded(vaultPosition && !vaultPositionLoading && !vaultLoading);
}, 300);

return () => {
clearTimeout(timeout);
};
}, [vaultPosition, vaultPositionLoading, vaultLoading, setNotLoaded]);
}, [vaultPosition, vaultPositionLoading, vaultLoading, setIsLoaded]);

if (!notLoading) {
if (isTfVaultType && activeTfPeriod > 0) return null;

if (!isLoaded) {
return (
<VaultDepositPaper>
<Typography variant="h3" sx={{ fontSize: isMobile ? "14px" : "16px" }}>
Expand All @@ -70,14 +72,13 @@ const VaultDetailForms = () => {
</VaultDepositPaper>
);
}
if (isTfVaultType && activeTfPeriod > 0) return null;

return (
<VaultDepositPaper>
{notLoading && BigNumber(vaultPosition.balanceShares).isGreaterThan(0) ? (
{isLoaded && BigNumber(vaultPosition.balanceShares).isGreaterThan(0) ? (
<VaultDetailManageForm />
) : !shutdown ? (
<VaultDetailDepositForm notLoading={notLoading} />
<VaultDetailDepositForm />
) : null}
</VaultDepositPaper>
);
Expand Down
46 changes: 43 additions & 3 deletions src/components/Vaults/List/VaultListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, memo, useCallback, useMemo } from "react";
import { FC, memo, useCallback, useEffect, useMemo } from "react";
import Image from "next/image";
import { useRouter } from "next/router";
import {
Expand All @@ -22,6 +22,8 @@ import VaultListItemManageModal from "@/components/Vaults/List/ManageVaultModal"

import LockAquaSrc from "assets/svg/lock-aqua.svg";
import LockSrc from "assets/svg/lock.svg";
import useBridgeContext, { BridgeType } from "@/context/bridge";
import { USDC_MINT_ADDRESSES } from "@/utils/addresses";

export const VaultTitle = styled("div")`
display: flex;
Expand Down Expand Up @@ -126,6 +128,7 @@ const VaultListItem: FC<VaultListItemProps> = ({
const router = useRouter();
const formattedApr = useApr(vaultItemData);

const { bridgeInfo, setBridgeInfo } = useBridgeContext();
const {
balanceEarned,
manageVault,
Expand All @@ -149,6 +152,37 @@ const VaultListItem: FC<VaultListItemProps> = ({
router.push(`/vaults/${vaultItemData.id}`);
}, [vaultItemData.id]);

useEffect(() => {
if (
USDC_MINT_ADDRESSES.includes(vaultItemData.token.id.toLowerCase()) &&
bridgeInfo.type === BridgeType.CreateVaultDepositFromBridgedUSDC
) {
if (
(!vaultPosition ||
!BigNumber(vaultPosition.balanceShares).isGreaterThan(0)) &&
!shutdown &&
activeTfPeriod !== 2 &&
!tfVaultDepositEndTimeLoading
) {
setNewVaultDeposit(true);
} else if (
vaultPosition &&
BigNumber(vaultPosition.balanceShares).isGreaterThan(0) &&
!shutdown &&
activeTfPeriod !== 2
) {
setManageVault(true);
}
}
}, [
vaultItemData,
bridgeInfo,
vaultPosition,
shutdown,
activeTfPeriod,
tfVaultDepositEndTimeLoading,
]);

const fxdPrice = 1;

return (
Expand Down Expand Up @@ -340,7 +374,10 @@ const VaultListItem: FC<VaultListItemProps> = ({
tfVaultLockEndDate={tfVaultLockEndDate}
activeTfPeriod={activeTfPeriod}
minimumDeposit={minimumDeposit}
onClose={() => setNewVaultDeposit(false)}
onClose={() => {
setNewVaultDeposit(false);
setBridgeInfo({});
}}
/>
)
);
Expand All @@ -357,7 +394,10 @@ const VaultListItem: FC<VaultListItemProps> = ({
tfVaultLockEndDate={tfVaultLockEndDate}
activeTfPeriod={activeTfPeriod}
minimumDeposit={minimumDeposit}
onClose={() => setManageVault(false)}
onClose={() => {
setManageVault(false);
setBridgeInfo({});
}}
/>
)
);
Expand Down
11 changes: 11 additions & 0 deletions src/components/Vaults/NestedNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const VaultsNestedNav = () => {
[location.pathname]
);

const isFaucetBridge = useMemo(
() => ["/vaults/bridge"].includes(location.pathname),
[location.pathname]
);

// const isTutorialActive = useMemo(() => {
// return location.pathname.includes('/vaults/tutorial')
// }, [location.pathname])
Expand All @@ -35,6 +40,12 @@ const VaultsNestedNav = () => {
>
Faucet
</NestedRouteLink>
<NestedRouteLink
className={isFaucetBridge ? "active" : ""}
href="/vaults/bridge"
>
Bridge
</NestedRouteLink>
{/*<NestedRouteLink*/}
{/* className={isTutorialActive ? 'active' : ''}*/}
{/* href="/vaults/tutorial"*/}
Expand Down
45 changes: 45 additions & 0 deletions src/context/bridge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
createContext,
Dispatch,
FC,
ReactNode,
useContext,
useMemo,
useState,
} from "react";

type StakingProviderType = {
children: ReactNode;
};

type UseBridgeContextReturn = {
setBridgeInfo: Dispatch<any>;
bridgeInfo: any;
};

export const BridgeContext = createContext<UseBridgeContextReturn>(
{} as UseBridgeContextReturn
);

export enum BridgeType {
CreateVaultDepositFromBridgedUSDC = "CreateVaultDepositFromBridgedUSDC",
}

export const BridgeProvider: FC<StakingProviderType> = ({ children }) => {
const [bridgeInfo, setBridgeInfo] = useState<number>(0);

const values = useMemo(() => {
return {
bridgeInfo,
setBridgeInfo,
};
}, [bridgeInfo, setBridgeInfo]);

return (
<BridgeContext.Provider value={values}>{children}</BridgeContext.Provider>
);
};

const useBridgeContext = () => useContext(BridgeContext);

export default useBridgeContext;
5 changes: 1 addition & 4 deletions src/context/sync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
useMemo,
useState,
} from "react";
import { Connection } from "@solana/web3.js";
import { defaultEndpoint } from "@/utils/network";
import { connection } from "@/utils/network";

type StakingProviderType = {
children: ReactNode;
Expand All @@ -27,8 +26,6 @@ export const SyncContext = createContext<UseSyncContextReturn>(
export const SyncProvider: FC<StakingProviderType> = ({ children }) => {
const [lastTransactionBlock, setLastTransactionBlock] = useState<number>(0);

const connection = new Connection(defaultEndpoint, "confirmed");

useEffect(() => {
const getLatestSlot = async () => {
if (connection === null) return;
Expand Down
13 changes: 13 additions & 0 deletions src/hooks/Vaults/useVaultManageDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { formatNumber } from "@/utils/format";
import { MAX_PERSONAL_DEPOSIT } from "@/hooks/Vaults/useVaultOpenDeposit";
import useSyncContext from "@/context/sync";
import { getVaultIndex } from "@/utils/getVaultIndex";
import { USDC_MINT_ADDRESSES } from "@/utils/addresses";
import useBridgeContext, { BridgeType } from "@/context/bridge";

export const defaultValues = {
formToken: "",
Expand All @@ -43,6 +45,7 @@ const useVaultManageDeposit = (
const { publicKey } = useWallet();
const anchorWallet = useAnchorWallet() as AnchorWallet;
const { lastTransactionBlock, setLastTransactionBlock } = useSyncContext();
const { bridgeInfo } = useBridgeContext();

const methods = useForm({
defaultValues,
Expand All @@ -58,6 +61,16 @@ const useVaultManageDeposit = (
formState: { errors },
} = methods;

useEffect(() => {
if (
USDC_MINT_ADDRESSES.includes(token.id.toLowerCase()) &&
bridgeInfo.type === BridgeType.CreateVaultDepositFromBridgedUSDC
) {
console.log("set value", bridgeInfo.amount);
setValue("formToken", bridgeInfo.amount);
}
}, [bridgeInfo, token, setValue]);

const [formType, setFormType] = useState<FormType>(
shutdown ? FormType.WITHDRAW : FormType.DEPOSIT
);
Expand Down
13 changes: 13 additions & 0 deletions src/hooks/Vaults/useVaultOpenDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
import useSyncContext from "@/context/sync";
import { formatNumber } from "@/utils/format";
import { getVaultIndex } from "@/utils/getVaultIndex";
import useBridgeContext, { BridgeType } from "@/context/bridge";
import { USDC_MINT_ADDRESSES } from "@/utils/addresses";

export const MAX_PERSONAL_DEPOSIT = 50000;
export const defaultValues = {
Expand All @@ -31,6 +33,7 @@ const useVaultOpenDeposit = (vault: IVault, onClose: () => void) => {
const { publicKey, wallet } = useWallet();
const anchorWallet = useAnchorWallet();
const { lastTransactionBlock, setLastTransactionBlock } = useSyncContext();
const { bridgeInfo } = useBridgeContext();

const [walletBalance, setWalletBalance] = useState<string>("0");
const [isWalletFetching, setIsWalletFetching] = useState<boolean>(false);
Expand All @@ -53,6 +56,16 @@ const useVaultOpenDeposit = (vault: IVault, onClose: () => void) => {
const deposit = watch("deposit");
const sharedToken = watch("sharedToken");

useEffect(() => {
if (
USDC_MINT_ADDRESSES.includes(token.id.toLowerCase()) &&
bridgeInfo.type === BridgeType.CreateVaultDepositFromBridgedUSDC
) {
console.log("set value", bridgeInfo.amount);
setValue("deposit", bridgeInfo.amount);
}
}, [bridgeInfo, token, setValue]);

const getVaultTokenBalance = useCallback(async () => {
if (!publicKey || !token?.id) {
return;
Expand Down
Loading

0 comments on commit 4625ad1

Please sign in to comment.