Skip to content

Commit

Permalink
Merge pull request #245 from mrgnlabs/man0s/final-touch
Browse files Browse the repository at this point in the history
Man0s/final touch
  • Loading branch information
losman0s authored Sep 26, 2023
2 parents 528ed5e + 9d175b6 commit 9e5d763
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export const StakingCard: FC = () => {
</Typography>
</div>
<div className="flex flex-row justify-between w-full my-auto">
<Typography className="font-aeonik font-[400] text-base">Deposit fee</Typography>
<Typography className="font-aeonik font-[400] text-base">Commission</Typography>
<Typography className="font-aeonik font-[700] text-lg">{lstData?.solDepositFee ?? 0}%</Typography>
</div>
{priceImpactPct !== null && (
Expand Down
3 changes: 2 additions & 1 deletion apps/marginfi-v2-ui/src/pages/api/user/get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NextApiResponse } from "next";
import { NextApiRequest, getFirebaseUserByWallet, initFirebaseIfNeeded } from "./utils";
import { getFirebaseUserByWallet, initFirebaseIfNeeded } from "./utils";
import { NextApiRequest } from "../utils";
import { STATUS_INTERNAL_ERROR, STATUS_NOT_FOUND, STATUS_OK, firebaseApi } from "@mrgnlabs/marginfi-v2-ui-state";

initFirebaseIfNeeded();
Expand Down
3 changes: 2 additions & 1 deletion apps/marginfi-v2-ui/src/pages/api/user/login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as admin from "firebase-admin";
import * as Sentry from "@sentry/nextjs";
import { NextApiRequest, getFirebaseUserByWallet, initFirebaseIfNeeded, logLoginAttempt } from "./utils";
import { getFirebaseUserByWallet, initFirebaseIfNeeded, logLoginAttempt } from "./utils";
import { NextApiRequest } from "../utils";
import { MEMO_PROGRAM_ID } from "@mrgnlabs/mrgn-common";
import { PublicKey, Transaction } from "@solana/web3.js";
import base58 from "bs58";
Expand Down
4 changes: 3 additions & 1 deletion apps/marginfi-v2-ui/src/pages/api/user/signup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as admin from "firebase-admin";
import * as Sentry from "@sentry/nextjs";
import {
NextApiRequest,
createFirebaseUser,
getFirebaseUserByWallet,
initFirebaseIfNeeded,
logSignupAttempt,
} from "./utils";
import {
NextApiRequest,
} from "../utils";
import { is } from "superstruct";
import { MEMO_PROGRAM_ID } from "@mrgnlabs/mrgn-common";
import { PublicKey, Transaction } from "@solana/web3.js";
Expand Down
28 changes: 0 additions & 28 deletions apps/marginfi-v2-ui/src/pages/api/user/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,3 @@ export async function createFirebaseUser(walletAddress: string, referralCode?: s
referralCode: uuidv4(),
});
}

// ------- Next helpers

export declare type Env = {
[key: string]: string | undefined;
};

export interface NextApiRequest<T> extends IncomingMessage {
/**
* Object of `query` values from url
*/
query: Partial<{
[key: string]: string | string[];
}>;
/**
* Object of `cookies` from header
*/
cookies: Partial<{
[key: string]: string;
}>;
body: T;
env: Env;
preview?: boolean;
/**
* Preview data set on the request, if any
* */
previewData?: PreviewData;
}
31 changes: 31 additions & 0 deletions apps/marginfi-v2-ui/src/pages/api/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

// ------- Next helpers

import { IncomingMessage } from "http";
import { PreviewData } from "next";

export declare type Env = {
[key: string]: string | undefined;
};

export interface NextApiRequest<T> extends IncomingMessage {
/**
* Object of `query` values from url
*/
query: Partial<{
[key: string]: string | string[];
}>;
/**
* Object of `cookies` from header
*/
cookies: Partial<{
[key: string]: string;
}>;
body: T;
env: Env;
preview?: boolean;
/**
* Preview data set on the request, if any
* */
previewData?: PreviewData;
}
14 changes: 13 additions & 1 deletion apps/marginfi-v2-ui/src/store/lstStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { TokenAccount, TokenAccountMap, fetchBirdeyePrices } from "@mrgnlabs/mar
import { persist } from "zustand/middleware";
import { StakePoolProxyProgram, getStakePoolProxyProgram } from "~/utils/stakePoolProxy";

const STAKEVIEW_APP_URL = "https://stakeview.app/apy/prev3.json";
const BASELINE_VALIDATOR_ID = "FugJZepeGfh1Ruunhep19JC4F3Hr2FL3oKUMezoK8ajp";

export const SOL_MINT = new PublicKey("So11111111111111111111111111111111111111112");
const NETWORK_FEE_LAMPORTS = 15000; // network fee + some for potential account creation
const SOL_USD_PYTH_ORACLE = new PublicKey("H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG");
Expand Down Expand Up @@ -207,9 +210,10 @@ const stateCreator: StateCreator<LstState, [], []> = (set, get) => ({
});

async function fetchLstData(connection: Connection): Promise<LstData> {
const [stakePoolInfo, stakePoolAccount] = await Promise.all([
const [stakePoolInfo, stakePoolAccount, apyData] = await Promise.all([
solanaStakePool.stakePoolInfo(connection, STAKE_POOL_ID),
solanaStakePool.getStakePoolAccount(connection, STAKE_POOL_ID),
fetch(STAKEVIEW_APP_URL).then((res) => res.json()),
]);
const stakePool = stakePoolAccount.account.data;

Expand All @@ -234,6 +238,14 @@ async function fetchLstData(connection: Connection): Promise<LstData> {
projectedApy = aprToApy(apr, EPOCHS_PER_YEAR);
}

if (projectedApy < 7) {
// temporarily use baseline validator APY waiting for a few epochs to pass
const baselineValidatorData = apyData.validators.find(
(validator: any) => validator.id === BASELINE_VALIDATOR_ID
);
if (baselineValidatorData) projectedApy = baselineValidatorData.apy;
}

return {
poolAddress: new PublicKey(stakePoolInfo.address),
tvl: totalLamports / 1e9,
Expand Down

1 comment on commit 9e5d763

@vercel
Copy link

@vercel vercel bot commented on 9e5d763 Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.