Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(mfi-v2-ui): perf improvements #388

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 = {
Expand Down
7 changes: 6 additions & 1 deletion apps/marginfi-v2-ui/src/store/lstStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -259,6 +260,10 @@ async function fetchJupiterTokenInfo(): Promise<TokenInfoMap> {
? 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
Expand Down
2 changes: 1 addition & 1 deletion apps/marginfi-v2-ui/src/store/uiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const stateCreator: StateCreator<UiState, [], []> = (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 }),
Expand Down
10 changes: 7 additions & 3 deletions packages/marginfi-v2-ui-state/src/store/jupiterStore.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,6 +42,10 @@ const stateCreator: StateCreator<JupiterState, [], []> = (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) => {
Expand Down
20 changes: 9 additions & 11 deletions packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -116,6 +111,9 @@ const stateCreator: StateCreator<MrgnlendState, [], []> = (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;
Expand Down