From be3e25706e85030551d9112926b2226d594c82a6 Mon Sep 17 00:00:00 2001 From: Adam Chambers Date: Wed, 29 Nov 2023 20:39:13 -0500 Subject: [PATCH 1/5] chore: dynamically load token data in lst store --- apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx | 4 ++-- apps/marginfi-v2-ui/src/store/lstStore.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx b/apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx index ed760f5b43..bad314363c 100644 --- a/apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx +++ b/apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx @@ -1,7 +1,6 @@ import React from "react"; import { useRouter } from "next/router"; -import { toast } from "react-toastify"; import { useCookies } from "react-cookie"; import { minidenticon } from "minidenticons"; import { useAnchorWallet, useWallet, WalletContextState } from "@solana/wallet-adapter-react"; @@ -11,10 +10,11 @@ import { Web3AuthNoModal } from "@web3auth/no-modal"; import { OpenloginAdapter } from "@web3auth/openlogin-adapter"; import { SolanaWallet, SolanaPrivateKeyProvider } from "@web3auth/solana-provider"; import base58 from "bs58"; -import { Wallet } from "@mrgnlabs/mrgn-common"; import { showErrorToast } from "~/utils/toastUtils"; +import type { Wallet } from "@mrgnlabs/mrgn-common"; + // wallet adapter context type to override with web3auth data // this allows us to pass web3auth wallet to 3rd party services that expect wallet adapter type WalletContextOverride = { diff --git a/apps/marginfi-v2-ui/src/store/lstStore.ts b/apps/marginfi-v2-ui/src/store/lstStore.ts index 2a48fc8c32..dc4641c184 100644 --- a/apps/marginfi-v2-ui/src/store/lstStore.ts +++ b/apps/marginfi-v2-ui/src/store/lstStore.ts @@ -4,11 +4,12 @@ import { Connection, PublicKey } from "@solana/web3.js"; import { create, StateCreator } from "zustand"; import * as solanaStakePool from "@solana/spl-stake-pool"; import { EPOCHS_PER_YEAR, StakeData, fetchStakeAccounts } from "~/utils"; -import { TokenInfo, TokenInfoMap, TokenListContainer } from "@solana/spl-token-registry"; import { TokenAccount, TokenAccountMap, fetchBirdeyePrices } from "@mrgnlabs/marginfi-v2-ui-state"; import { persist } from "zustand/middleware"; import BN from "bn.js"; +import type { TokenInfo, TokenInfoMap } from "@solana/spl-token-registry"; + const STAKEVIEW_APP_URL = "https://stakeview.app/apy/prev3.json"; const BASELINE_VALIDATOR_ID = "mrgn28BhocwdAUEenen3Sw2MR9cPKDpLkDvzDdR7DBD"; @@ -259,6 +260,10 @@ async function fetchJupiterTokenInfo(): Promise { ? await fetch("https://token.jup.ag/strict") : await fetch("https://token.jup.ag/all") ).json(); + + // Dynamically import TokenListContainer when needed + const { TokenListContainer } = await import("@solana/spl-token-registry"); + const res = new TokenListContainer(tokens); const list = res.filterByChainId(101).getList(); const tokenMap = list From 6c5f8e461b2b761a334d3c63c3c38405b2bad7f2 Mon Sep 17 00:00:00 2001 From: Adam Chambers Date: Wed, 29 Nov 2023 21:54:47 -0500 Subject: [PATCH 2/5] chore: refactor imports --- .../src/store/jupiterStore.ts | 10 +++++++--- .../src/store/mrgnlendStore.ts | 20 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/marginfi-v2-ui-state/src/store/jupiterStore.ts b/packages/marginfi-v2-ui-state/src/store/jupiterStore.ts index 083fccc200..c9284c08b5 100644 --- a/packages/marginfi-v2-ui-state/src/store/jupiterStore.ts +++ b/packages/marginfi-v2-ui-state/src/store/jupiterStore.ts @@ -1,9 +1,9 @@ -import { Wallet, nativeToUi, TOKEN_PROGRAM_ID } from "@mrgnlabs/mrgn-common"; -import { TokenInfo, TokenListContainer } from "@solana/spl-token-registry"; +import { Wallet, TOKEN_PROGRAM_ID } from "@mrgnlabs/mrgn-common"; import { Connection, PublicKey } from "@solana/web3.js"; import { TokenAccountMap, TokenAccount } from "../lib"; import { create, StateCreator } from "zustand"; -import { BN } from "@coral-xyz/anchor"; + +import type { TokenInfo } from "@solana/spl-token-registry"; interface JupiterState { // State @@ -42,6 +42,10 @@ const stateCreator: StateCreator = (set, get) => ({ ? await fetch("https://token.jup.ag/strict") : await fetch("https://token.jup.ag/all") ).json(); + + // Dynamically import TokenListContainer when needed + const { TokenListContainer } = await import("@solana/spl-token-registry"); + const res = new TokenListContainer(tokens); const list = res.filterByChainId(101).getList(); tokenMap = list.reduce((acc, item) => { diff --git a/packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts b/packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts index 868e48e5ab..c78efb32dd 100644 --- a/packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts +++ b/packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts @@ -1,14 +1,4 @@ -import { MarginfiAccountWrapper, MarginfiClient, MarginfiConfig } from "@mrgnlabs/marginfi-client-v2"; -import { - Wallet, - getValueInsensitive, - loadBankMetadatas, - loadTokenMetadatas, - BankMetadataMap, - TokenMetadataMap, - TokenMetadata, -} from "@mrgnlabs/mrgn-common"; -import { Bank, OraclePrice } from "@mrgnlabs/marginfi-client-v2"; +import { getValueInsensitive } from "@mrgnlabs/mrgn-common"; import { Connection, PublicKey } from "@solana/web3.js"; import { DEFAULT_ACCOUNT_SUMMARY, @@ -28,6 +18,11 @@ import { getPointsSummary } from "../lib/points"; import { create, StateCreator } from "zustand"; import { persist } from "zustand/middleware"; +import type { Bank, OraclePrice } from "@mrgnlabs/marginfi-client-v2"; +import type { Wallet, BankMetadataMap, TokenMetadataMap, TokenMetadata } from "@mrgnlabs/mrgn-common"; +import type { MarginfiAccountWrapper } from "@mrgnlabs/marginfi-client-v2"; +import type { MarginfiClient, MarginfiConfig } from "@mrgnlabs/marginfi-client-v2"; + interface ProtocolStats { deposits: number; borrows: number; @@ -116,6 +111,9 @@ const stateCreator: StateCreator = (set, get) => ({ birdEyeApiKey?: string; }) => { try { + const { MarginfiClient } = await import("@mrgnlabs/marginfi-client-v2"); + const { loadBankMetadatas, loadTokenMetadatas } = await import("@mrgnlabs/mrgn-common"); + let userDataFetched = false; const connection = args?.connection ?? get().marginfiClient?.provider.connection; From e389f21e93d83c205b090034dcad3be17988ebbe Mon Sep 17 00:00:00 2001 From: Adam Chambers Date: Wed, 29 Nov 2023 22:05:36 -0500 Subject: [PATCH 3/5] chore: change default sort option to match sdk --- apps/marginfi-v2-ui/src/store/uiStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/marginfi-v2-ui/src/store/uiStore.ts b/apps/marginfi-v2-ui/src/store/uiStore.ts index 7ead4b1942..f57275c55e 100644 --- a/apps/marginfi-v2-ui/src/store/uiStore.ts +++ b/apps/marginfi-v2-ui/src/store/uiStore.ts @@ -69,7 +69,7 @@ const stateCreator: StateCreator = (set, get) => ({ isFilteredUserPositions: false, lendingMode: LendingModes.LEND, poolFilter: PoolTypes.ALL, - sortOption: SORT_OPTIONS_MAP[SortType.APY_DESC], + sortOption: SORT_OPTIONS_MAP[SortType.TVL_DESC], // Actions setIsMenuDrawerOpen: (isOpen: boolean) => set({ isMenuDrawerOpen: isOpen }), From b67fef9b35e783f746de3a96c2550f6ee2b9766c Mon Sep 17 00:00:00 2001 From: Adam Chambers Date: Thu, 30 Nov 2023 08:48:50 -0500 Subject: [PATCH 4/5] chore: use Next Script component --- apps/marginfi-v2-ui/src/pages/_document.tsx | 14 +++++------ apps/marginfi-v2-ui/src/pages/swap.tsx | 26 +++++++++++++-------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/apps/marginfi-v2-ui/src/pages/_document.tsx b/apps/marginfi-v2-ui/src/pages/_document.tsx index 446dc4b774..26967e2cc1 100644 --- a/apps/marginfi-v2-ui/src/pages/_document.tsx +++ b/apps/marginfi-v2-ui/src/pages/_document.tsx @@ -1,21 +1,19 @@ import { Html, Head, Main, NextScript } from "next/document"; +import Script from "next/script"; export default function Document() { return ( - { - // eslint-disable-next-line @next/next/no-sync-scripts -