From d847d46838bbc12ed057a4ad8a09f2bcfbb92612 Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Wed, 6 Sep 2023 16:22:56 +0100 Subject: [PATCH 1/4] fixed issue in saving vault editor --- .../VaultEditorFormPage.tsx | 132 ++++++++++-------- 1 file changed, 73 insertions(+), 59 deletions(-) diff --git a/packages/web/src/pages/VaultEditor/VaultEditorFormPage/VaultEditorFormPage.tsx b/packages/web/src/pages/VaultEditor/VaultEditorFormPage/VaultEditorFormPage.tsx index 17421f01f..89ee1e00a 100644 --- a/packages/web/src/pages/VaultEditor/VaultEditorFormPage/VaultEditorFormPage.tsx +++ b/packages/web/src/pages/VaultEditor/VaultEditorFormPage/VaultEditorFormPage.tsx @@ -143,47 +143,6 @@ const VaultEditorFormPage = () => { checkGovMember(); }, [address, chain]); - const createOrSaveEditSession = async (isCreation = false, withIpfsHash = false) => { - try { - // If vault is already created or is isNonEditableStatus, edition is blocked - if (isNonEditableStatus) return; - if (allFormDisabled) return; - if (isSomeoneCreatingTheVault) return; - if (!isCreation && !formState.isDirty) return; - if (isCreation) setLoadingEditSession(true); - if (!isCreation) setSavingEditSession(true); - - let sessionIdOrSessionResponse: string | IEditedSessionResponse; - - if (isCreation) { - sessionIdOrSessionResponse = await VaultEditorService.upsertEditSession( - undefined, - undefined, - withIpfsHash ? editSessionId : undefined - ); - } else { - const data: IEditedVaultDescription = getValues(); - sessionIdOrSessionResponse = await VaultEditorService.upsertEditSession(data, editSessionId, undefined); - } - - if (typeof sessionIdOrSessionResponse === "string") { - navigate(`${RoutePaths.vault_editor}/${sessionIdOrSessionResponse}`, { replace: true }); - } else { - refreshEditSessionData(sessionIdOrSessionResponse); - } - - setSavingEditSession(false); - setLoadingEditSession(false); - } catch (error) { - setSavingEditSession(false); - setLoadingEditSession(false); - - if (!editSessionId) return; - const editSessionResponse = await VaultEditorService.getEditSessionData(editSessionId); - refreshEditSessionData(editSessionResponse); - } - }; - async function loadEditSessionData(editSessionId: string) { if (isVaultCreated) return; // If vault is already created, creation is blocked @@ -217,24 +176,80 @@ const VaultEditorFormPage = () => { } } - const refreshEditSessionData = async (newEditSession: IEditedSessionResponse, withReset = true) => { - const wasSubmittedToCreation = (newEditSession.submittedToCreation ?? false) && !newEditSession.vaultAddress; - - setEditSessionSubmittedCreation(wasSubmittedToCreation); - setDescriptionHash(newEditSession.descriptionHash); - setLastModifedOn(newEditSession.updatedAt); - setEditingExistingVaultStatus(newEditSession.vaultEditionStatus); - setIsSomeoneCreatingTheVault( - (!wasSubmittedToCreation && - newEditSession.lastCreationOnChainRequest && - moment().diff(moment(newEditSession.lastCreationOnChainRequest), "minute") < 5) ?? - false - ); + const refreshEditSessionData = useCallback( + async (newEditSession: IEditedSessionResponse, withReset = true) => { + const wasSubmittedToCreation = (newEditSession.submittedToCreation ?? false) && !newEditSession.vaultAddress; + + setEditSessionSubmittedCreation(wasSubmittedToCreation); + setDescriptionHash(newEditSession.descriptionHash); + setLastModifedOn(newEditSession.updatedAt); + setEditingExistingVaultStatus(newEditSession.vaultEditionStatus); + setIsSomeoneCreatingTheVault( + (!wasSubmittedToCreation && + newEditSession.lastCreationOnChainRequest && + moment().diff(moment(newEditSession.lastCreationOnChainRequest), "minute") < 5) ?? + false + ); - if (withReset) handleReset(newEditSession.editedDescription, { keepErrors: true }); - }; + if (withReset) handleReset(newEditSession.editedDescription, { keepErrors: true }); + }, + [handleReset] + ); + + const createOrSaveEditSession = useCallback( + async (isCreation = false, withIpfsHash = false) => { + try { + // If vault is already created or is isNonEditableStatus, edition is blocked + if (isNonEditableStatus) return; + if (allFormDisabled) return; + if (isSomeoneCreatingTheVault) return; + if (!isCreation && !formState.isDirty) return; + if (isCreation) setLoadingEditSession(true); + if (!isCreation) setSavingEditSession(true); + + let sessionIdOrSessionResponse: string | IEditedSessionResponse; + + if (isCreation) { + sessionIdOrSessionResponse = await VaultEditorService.upsertEditSession( + undefined, + undefined, + withIpfsHash ? editSessionId : undefined + ); + } else { + const data: IEditedVaultDescription = getValues(); + sessionIdOrSessionResponse = await VaultEditorService.upsertEditSession(data, editSessionId, undefined); + } + + if (typeof sessionIdOrSessionResponse === "string") { + navigate(`${RoutePaths.vault_editor}/${sessionIdOrSessionResponse}`, { replace: true }); + } else { + refreshEditSessionData(sessionIdOrSessionResponse); + } + + setSavingEditSession(false); + setLoadingEditSession(false); + } catch (error) { + setSavingEditSession(false); + setLoadingEditSession(false); + + if (!editSessionId) return; + const editSessionResponse = await VaultEditorService.getEditSessionData(editSessionId); + refreshEditSessionData(editSessionResponse); + } + }, + [ + allFormDisabled, + editSessionId, + formState.isDirty, + getValues, + isNonEditableStatus, + isSomeoneCreatingTheVault, + navigate, + refreshEditSessionData, + ] + ); - const createVaultOnChain = async () => { + const createVaultOnChain = useCallback(async () => { if (allFormDisabled) return; try { @@ -294,8 +309,7 @@ const VaultEditorFormPage = () => { console.error(error); setCreatingVault(false); } - }; - + }, [address, allFormDisabled, confirm, descriptionHash, editSessionId, getValues, navigate, refreshEditSessionData, t]); const sendEditionToGovApproval = async () => { if (allFormDisabled) return; if (!wasEditedSinceCreated) return; From c339e3c48dde430c0a4913675e923c0417344a6c Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Thu, 7 Sep 2023 15:29:36 +0100 Subject: [PATCH 2/4] fixed maxRewards information --- .../src/components/VaultCard/VaultCard.tsx | 2 +- .../web/src/hooks/subgraph/vaults/parser.ts | 40 ++++++++++++--- packages/web/src/languages/en.json | 3 ++ .../VaultRewardsSection.tsx | 49 +++++++++---------- 4 files changed, 59 insertions(+), 35 deletions(-) diff --git a/packages/web/src/components/VaultCard/VaultCard.tsx b/packages/web/src/components/VaultCard/VaultCard.tsx index c35c4f158..83d0386ad 100644 --- a/packages/web/src/components/VaultCard/VaultCard.tsx +++ b/packages/web/src/components/VaultCard/VaultCard.tsx @@ -267,7 +267,7 @@ export const VaultCard = ({ ? millify(totalPaidOutOnAudit?.usd ?? 0) : showIntended ? millify(vault.amountsInfo?.competitionIntendedAmount?.deposited.usd ?? 0) - : millify(vault.amountsInfo?.depositedAmount.usd ?? 0)} + : millify(vault.amountsInfo?.maxRewardAmount.usd ?? 0)}
diff --git a/packages/web/src/hooks/subgraph/vaults/parser.ts b/packages/web/src/hooks/subgraph/vaults/parser.ts index 1b0e1dbcf..0feb8e589 100644 --- a/packages/web/src/hooks/subgraph/vaults/parser.ts +++ b/packages/web/src/hooks/subgraph/vaults/parser.ts @@ -1,6 +1,6 @@ import { formatUnits } from "@ethersproject/units"; import { IMaster, IPayoutGraph, IUserNft, IVault } from "@hats-finance/shared"; -import { BigNumber } from "ethers"; +import { BigNumber, ethers } from "ethers"; import { appChains } from "settings"; export const parseMasters = (masters: IMaster[], chainId: number) => { @@ -49,14 +49,39 @@ export const populateVaultsWithPricing = (vaults: IVault[], tokenPrices: number[ const isTestnet = appChains[vault.chainId].chain.testnet; const tokenPrice: number = isTestnet ? 1387.65 : (tokenPrices && tokenPrices[vault.stakingToken]) ?? 0; const depositedAmountTokens = Number(formatUnits(vault.honeyPotBalance, vault.stakingTokenDecimals)); + const isAudit = vault.description?.["project-metadata"].type === "audit"; - const maxRewardFactor = vault.version === "v1" ? +vault.rewardsLevels[vault.rewardsLevels.length - 1] : +vault.maxBounty; + console.log(vault); + + const governanceSplit = BigNumber.from(vault.governanceHatRewardSplit).eq(ethers.constants.MaxUint256) + ? vault.master.defaultGovernanceHatRewardSplit + : vault.governanceHatRewardSplit; + const hackerHatsSplit = BigNumber.from(vault.hackerHatRewardSplit).eq(ethers.constants.MaxUint256) + ? vault.master.defaultHackerHatRewardSplit + : vault.hackerHatRewardSplit; + + // In v2 vaults the split sum (immediate, vested, committee) is 100%. So we need to calculate the split factor to get the correct values. + // In v1 this is not a probem. So the factor is 1. + const splitFactor = vault.version === "v1" ? 1 : (10000 - Number(governanceSplit) - Number(hackerHatsSplit)) / 100 / 100; + + const governanceFee = Number(governanceSplit) / 100 / 100; + const committeeFee = (Number(vault.committeeRewardSplit) / 100 / 100) * splitFactor; + + let maxRewardFactor = 1; + if (isAudit) { + // For audits the max bounty is 100% - governanceFee - committeeFee + maxRewardFactor = maxRewardFactor - governanceFee - committeeFee; + } else { + // maxRewardFactor = vault.version === "v1" ? 10000 : +vault.maxBounty; + maxRewardFactor = maxRewardFactor - governanceFee - committeeFee; + } return { ...vault, amountsInfo: { showCompetitionIntendedAmount: - vault.description?.["project-metadata"].type === "audit" && + isAudit && + vault.description && vault.description["project-metadata"].starttime && vault.description["project-metadata"].starttime > new Date().getTime() / 1000 + 48 * 3600 && // 48 hours !!vault.description?.["project-metadata"].intendedCompetitionAmount && @@ -69,9 +94,8 @@ export const populateVaultsWithPricing = (vaults: IVault[], tokenPrices: number[ usd: +vault.description?.["project-metadata"].intendedCompetitionAmount * tokenPrice, }, maxReward: { - tokens: +vault.description?.["project-metadata"].intendedCompetitionAmount * (maxRewardFactor / 100 / 100), - usd: - +vault.description?.["project-metadata"].intendedCompetitionAmount * tokenPrice * (maxRewardFactor / 100 / 100), + tokens: +vault.description?.["project-metadata"].intendedCompetitionAmount * maxRewardFactor, + usd: +vault.description?.["project-metadata"].intendedCompetitionAmount * tokenPrice * maxRewardFactor, }, } : undefined, @@ -80,8 +104,8 @@ export const populateVaultsWithPricing = (vaults: IVault[], tokenPrices: number[ usd: depositedAmountTokens * tokenPrice, }, maxRewardAmount: { - tokens: depositedAmountTokens * (maxRewardFactor / 100 / 100), - usd: depositedAmountTokens * tokenPrice * (maxRewardFactor / 100 / 100), + tokens: depositedAmountTokens * maxRewardFactor, + usd: depositedAmountTokens * tokenPrice * maxRewardFactor, }, }, } as IVault; diff --git a/packages/web/src/languages/en.json b/packages/web/src/languages/en.json index d65854669..f8c846cea 100644 --- a/packages/web/src/languages/en.json +++ b/packages/web/src/languages/en.json @@ -582,6 +582,9 @@ "goToProjectWebsite": "Go to project website", "doYouWantToGoToProjectWebsite": "Do you want to go to project website? \n ({{website}})", "yesGo": "Yes, go", + "ofRewards": "of rewards", + "maxRewardCap": "Max reward cap", + "maxRewardCapExplanation": "This is the maximum amount that will be paid for a single submission.", "PGPTool": { "title": "PGP tool", "unlockPgpTool": "Unlock the PGP tool", diff --git a/packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultRewardsSection/VaultRewardsSection.tsx b/packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultRewardsSection/VaultRewardsSection.tsx index 804ba1d97..0fafbc1b0 100644 --- a/packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultRewardsSection/VaultRewardsSection.tsx +++ b/packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultRewardsSection/VaultRewardsSection.tsx @@ -14,25 +14,27 @@ type VaultRewardsSectionProps = { export const VaultRewardsSection = ({ vault }: VaultRewardsSectionProps) => { const { t } = useTranslation(); - const isAudit = vault.description && vault.description["project-metadata"].type === "audit"; + const isAudit = vault.description && vault.description["project-metadata"].type === "audit"; const showIntended = vault.amountsInfo?.showCompetitionIntendedAmount ?? false; return ( - +

{t("rewards")}

-
-

{showIntended ? t("intendedDeposits") : t("totalDeposits")}

- {showIntended ? ( - -

~${millify(vault.amountsInfo?.competitionIntendedAmount?.deposited.usd ?? 0)}

-
- ) : ( -

~${millify(vault.amountsInfo?.depositedAmount.usd ?? 0)}

- )} -
+ {!isAudit && ( +
+

{showIntended ? t("intendedDeposits") : t("totalDeposits")}

+ {showIntended ? ( + +

~${millify(vault.amountsInfo?.competitionIntendedAmount?.deposited.usd ?? 0)}

+
+ ) : ( +

~${millify(vault.amountsInfo?.depositedAmount.usd ?? 0)}

+ )} +
+ )}

{t("assetsInVault")}

@@ -44,25 +46,20 @@ export const VaultRewardsSection = ({ vault }: VaultRewardsSectionProps) => {

~${millify(vault.amountsInfo?.competitionIntendedAmount?.maxReward.usd ?? 0)}

) : ( - // TODO: In here should be only the max reward amount, not the deposited amount - // Change this once we have the new contract version -

- ~$ - {isAudit - ? millify(vault.amountsInfo?.depositedAmount.usd ?? 0) - : millify(vault.amountsInfo?.maxRewardAmount.usd ?? 0)} -

+

~${millify(vault.amountsInfo?.maxRewardAmount.usd ?? 0)}

)}
-
-
-

{t("rewardsDivision")}

-
- + {!isAudit && ( +
+
+

{t("rewardsDivision")}

+
+ +
-
+ )}

{t("severityRewards")}

From b658db30a4ed3f8301517301a0d2b7b0bbbf7416 Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Thu, 7 Sep 2023 15:29:52 +0100 Subject: [PATCH 3/4] improved rewards section for audit competitions --- .../VaultSeverityRewardCard.tsx | 33 +++++++++++++++---- .../VaultSeverityRewardCard/styles.ts | 31 ++++++++++++----- .../hooks/severities/useSeverityRewardInfo.ts | 25 +++++++------- .../Sections/VaultRewardsSection/styles.ts | 26 ++++++++++++--- 4 files changed, 82 insertions(+), 33 deletions(-) diff --git a/packages/web/src/components/VaultSeverityRewardCard/VaultSeverityRewardCard.tsx b/packages/web/src/components/VaultSeverityRewardCard/VaultSeverityRewardCard.tsx index a285eac5b..f48cd5363 100644 --- a/packages/web/src/components/VaultSeverityRewardCard/VaultSeverityRewardCard.tsx +++ b/packages/web/src/components/VaultSeverityRewardCard/VaultSeverityRewardCard.tsx @@ -1,5 +1,6 @@ -import { IVault, IVulnerabilitySeverity } from "@hats-finance/shared"; -import { Pill, VaultNftRewardCard } from "components"; +import { IVault, IVulnerabilitySeverity, IVulnerabilitySeverityV2 } from "@hats-finance/shared"; +import InfoIcon from "@mui/icons-material/InfoOutlined"; +import { Pill, VaultNftRewardCard, WithTooltip } from "components"; import { useSeverityRewardInfo } from "hooks/severities/useSeverityRewardInfo"; import { useTranslation } from "react-i18next"; import { formatNumber } from "utils"; @@ -14,20 +15,40 @@ interface VaultSeverityRewardCardProps { export function VaultSeverityRewardCard({ vault, severity, severityIndex, noNft = false }: VaultSeverityRewardCardProps) { const { t } = useTranslation(); - const { rewardPercentage, rewardPrice, rewardColor } = useSeverityRewardInfo(vault, severityIndex); + const { rewardPercentage, rewardPrice, rewardCap, rewardColor } = useSeverityRewardInfo(vault, severityIndex); const severityName = severity?.name.toLowerCase().replace("severity", "") ?? ""; + const showCap = vault.version === "v2" && vault.description?.severities.some((sev) => !!sev.capAmount); return ( - - + +
+ +
{`${rewardPercentage.toFixed(2)}%`} -  {t("ofVault")}  +  {t("ofRewards")} 
~{`$${formatNumber(rewardPrice)}`}
+ {showCap && ( + <> + {(severity as IVulnerabilitySeverityV2).capAmount ? ( + +
+
+ {t("maxRewardCap")} + +
+ ~{`$${formatNumber(rewardCap)}`} +
+
+ ) : ( +
+ )} + + )} {!noNft && (
diff --git a/packages/web/src/components/VaultSeverityRewardCard/styles.ts b/packages/web/src/components/VaultSeverityRewardCard/styles.ts index 72c3f998b..961a7ebe1 100644 --- a/packages/web/src/components/VaultSeverityRewardCard/styles.ts +++ b/packages/web/src/components/VaultSeverityRewardCard/styles.ts @@ -2,13 +2,13 @@ import styled, { css } from "styled-components"; import { getSpacing } from "styles"; import { breakpointsDefinition } from "styles/breakpoints.styles"; -export const StyledVaultSeverityRewardCard = styled.div<{ color: string; noNft: boolean }>( - ({ color, noNft }) => css` +export const StyledVaultSeverityRewardCard = styled.div<{ color: string; columns: number }>( + ({ color, columns }) => css` display: grid; - grid-template-columns: ${noNft ? "3fr 4fr" : "1fr 1fr 1fr"}; + grid-template-columns: ${columns === 2 ? "3fr 4fr" : columns === 3 ? "1fr 1fr 1fr" : "1fr 1fr 1fr 1fr"}; align-items: center; justify-content: space-between; - gap: ${getSpacing(1)}; + gap: ${getSpacing(2)}; .severity-name, .severity-prize, @@ -24,11 +24,16 @@ export const StyledVaultSeverityRewardCard = styled.div<{ color: string; noNft: } @media (max-width: ${breakpointsDefinition.mediumMobile}) { - grid-template-columns: ${noNft ? "1fr 1fr" : "2fr 1fr 1fr"}; + grid-template-columns: ${columns === 2 ? "1fr 1fr" : columns === 3 ? "1fr 1fr 1fr" : "1fr 1fr 1fr 1fr"}; } @media (max-width: ${breakpointsDefinition.smallMobile}) { - grid-template-columns: ${noNft ? "1fr 1fr" : "4fr 4fr 3fr"}; + grid-template-columns: ${columns === 2 ? "1fr" : columns === 3 ? "1fr 1fr" : "1fr 1fr"}; + + .severity-name { + grid-column-start: 1; + grid-column-end: ${columns}; + } } .severity-name { @@ -39,10 +44,17 @@ export const StyledVaultSeverityRewardCard = styled.div<{ color: string; noNft: .severity-prize { font-weight: 700; + flex-direction: column; + align-items: flex-end; + + @media (max-width: ${breakpointsDefinition.smallMobile}) { + align-items: center; + } - @media (max-width: ${breakpointsDefinition.mediumMobile}) { - flex-direction: column; - align-items: flex-end; + .title-container { + display: flex; + align-items: center; + gap: ${getSpacing(0.2)}; } .tiny { @@ -51,6 +63,7 @@ export const StyledVaultSeverityRewardCard = styled.div<{ color: string; noNft: } .price { + font-size: var(--small); color: ${color}; font-weight: 700; } diff --git a/packages/web/src/hooks/severities/useSeverityRewardInfo.ts b/packages/web/src/hooks/severities/useSeverityRewardInfo.ts index 3088de7f6..82326de47 100644 --- a/packages/web/src/hooks/severities/useSeverityRewardInfo.ts +++ b/packages/web/src/hooks/severities/useSeverityRewardInfo.ts @@ -1,4 +1,3 @@ -import { formatUnits } from "ethers/lib/utils"; import { useVaultsTotalPrices } from "hooks/vaults/useVaultsTotalPrices"; import { IVault } from "types"; import { generateColorsArrayInBetween } from "utils/colors.utils"; @@ -15,53 +14,53 @@ export const getSeveritiesColorsArray = (vault: IVault | undefined): string[] => export function useSeverityRewardInfo(vault: IVault | undefined, severityIndex: number) { const { totalPrices } = useVaultsTotalPrices(vault ? vault.multipleVaults ?? [vault] : []); - if (!vault || !vault.description) return { rewardPrice: 0, rewardPercentage: 0, rewardColor: INITIAL_SEVERITY_COLOR }; + if (!vault || !vault.description) + return { rewardPrice: 0, rewardPercentage: 0, rewardCap: 0, rewardColor: INITIAL_SEVERITY_COLOR }; - const isAudit = vault.description && vault.description["project-metadata"].type === "audit"; const showIntendedAmounts = vault.amountsInfo?.showCompetitionIntendedAmount ?? false; const SEVERITIES_COLORS = getSeveritiesColorsArray(vault); if (vault.version === "v2") { const severity = vault.description.severities[severityIndex]; - if (!severity) return { rewardPrice: 0, rewardPercentage: 0, rewardColor: INITIAL_SEVERITY_COLOR }; + if (!severity) return { rewardPrice: 0, rewardPercentage: 0, rewardCap: 0, rewardColor: INITIAL_SEVERITY_COLOR }; const sumTotalPrices = Object.values(totalPrices).reduce((a, b = 0) => a + b, 0); - // const maxBountyPercentage = Number(vault.maxBounty) / 10000; // Number between 0 and 1; - // TODO: remove this when we have the new vault contract version - const maxBountyPercentage = Number(isAudit ? 10000 : vault.maxBounty) / 10000; - const rewardPercentage = +severity.percentage * maxBountyPercentage; + const rewardPercentage = +severity.percentage; let rewardPrice: number = 0; + let rewardCap: number = 0; if (vault.multipleVaults && sumTotalPrices) { rewardPrice = sumTotalPrices * (rewardPercentage / 100); } else if (vault.amountsInfo?.tokenPriceUsd) { rewardPrice = (showIntendedAmounts ? vault.amountsInfo.competitionIntendedAmount?.deposited.tokens ?? 0 - : Number(formatUnits(vault.honeyPotBalance, vault.stakingTokenDecimals))) * + : vault.amountsInfo.maxRewardAmount.tokens) * (rewardPercentage / 100) * vault.amountsInfo?.tokenPriceUsd; + rewardCap = (severity.capAmount ?? 0) * vault.amountsInfo?.tokenPriceUsd; } const orderedSeverities = vault.description.severities.map((severity) => severity.percentage).sort((a, b) => a - b); const rewardColor: string = SEVERITIES_COLORS[orderedSeverities.indexOf(severity.percentage) ?? 0]; - return { rewardPrice, rewardPercentage, rewardColor }; + return { rewardPrice, rewardPercentage, rewardCap, rewardColor }; } else { const severity = vault.description.severities[severityIndex]; - if (!severity) return { rewardPrice: 0, rewardPercentage: 0, rewardColor: INITIAL_SEVERITY_COLOR }; + if (!severity) return { rewardPrice: 0, rewardPercentage: 0, rewardCap: 0, rewardColor: INITIAL_SEVERITY_COLOR }; const sumTotalPrices = Object.values(totalPrices).reduce((a, b = 0) => a + b, 0); const rewardPercentage = (Number(vault.rewardsLevels[severity.index]) / 10000) * 100; let rewardPrice: number = 0; + let rewardCap: number = 0; if (vault.multipleVaults && sumTotalPrices) { rewardPrice = sumTotalPrices * (rewardPercentage / 100); } else if (vault.amountsInfo?.tokenPriceUsd) { rewardPrice = (showIntendedAmounts ? vault.amountsInfo.competitionIntendedAmount?.deposited.tokens ?? 0 - : Number(formatUnits(vault.honeyPotBalance, vault.stakingTokenDecimals))) * + : vault.amountsInfo.maxRewardAmount.tokens) * (rewardPercentage / 100) * vault.amountsInfo?.tokenPriceUsd; } @@ -69,6 +68,6 @@ export function useSeverityRewardInfo(vault: IVault | undefined, severityIndex: const orderedSeverities = vault.description.severities.map((severity) => severity.index).sort((a, b) => a - b); const rewardColor: string = SEVERITIES_COLORS[orderedSeverities.indexOf(severity.index) ?? 0]; - return { rewardPrice, rewardPercentage, rewardColor }; + return { rewardPrice, rewardPercentage, rewardCap, rewardColor }; } } diff --git a/packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultRewardsSection/styles.ts b/packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultRewardsSection/styles.ts index 0bd940981..abcad1217 100644 --- a/packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultRewardsSection/styles.ts +++ b/packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultRewardsSection/styles.ts @@ -2,22 +2,37 @@ import styled, { css } from "styled-components"; import { getSpacing } from "styles"; import { breakpointsDefinition } from "styles/breakpoints.styles"; -export const StyledRewardsSection = styled.div<{ showIntended: boolean }>( - ({ showIntended }) => css` +export const StyledRewardsSection = styled.div<{ showIntended: boolean; isAudit: boolean }>( + ({ showIntended, isAudit }) => css` padding-bottom: ${getSpacing(10)}; .rewards-containers { display: grid; grid-template-columns: auto 1fr 1fr; - gap: ${getSpacing(1.5)}; + gap: ${getSpacing(3)}; flex-grow: 1; + ${isAudit && + css` + grid-template-columns: 1fr 3fr; + `} + @media (max-width: ${breakpointsDefinition.mediumScreen}) { grid-template-columns: auto 4fr 5fr; + + ${isAudit && + css` + grid-template-columns: 1fr 2fr; + `} } @media (max-width: ${breakpointsDefinition.mediumMobile}) { grid-template-columns: 1fr 1fr; + + ${isAudit && + css` + grid-template-columns: 1fr; + `} } @media (max-width: ${breakpointsDefinition.smallMobile}) { @@ -27,7 +42,7 @@ export const StyledRewardsSection = styled.div<{ showIntended: boolean }>( .amounts { display: grid; grid-template-columns: 1fr; - gap: ${getSpacing(1.5)}; + gap: ${getSpacing(3)}; @media (max-width: ${breakpointsDefinition.mediumMobile}) { grid-template-columns: 1fr; @@ -44,10 +59,11 @@ export const StyledRewardsSection = styled.div<{ showIntended: boolean }>( } .severities-rewards { - max-height: 500px; + max-height: 550px; overflow: hidden; @media (max-width: ${breakpointsDefinition.smallMobile}) { + max-height: unset; grid-column-start: 1; grid-column-end: 3; } From 91237297d0b9a19d285a3183a40fc937ccc51e19 Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Tue, 26 Sep 2023 16:52:55 +0100 Subject: [PATCH 4/4] minor improvement --- packages/web/src/hooks/subgraph/vaults/parser.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/web/src/hooks/subgraph/vaults/parser.ts b/packages/web/src/hooks/subgraph/vaults/parser.ts index 0feb8e589..46d47457e 100644 --- a/packages/web/src/hooks/subgraph/vaults/parser.ts +++ b/packages/web/src/hooks/subgraph/vaults/parser.ts @@ -67,14 +67,7 @@ export const populateVaultsWithPricing = (vaults: IVault[], tokenPrices: number[ const governanceFee = Number(governanceSplit) / 100 / 100; const committeeFee = (Number(vault.committeeRewardSplit) / 100 / 100) * splitFactor; - let maxRewardFactor = 1; - if (isAudit) { - // For audits the max bounty is 100% - governanceFee - committeeFee - maxRewardFactor = maxRewardFactor - governanceFee - committeeFee; - } else { - // maxRewardFactor = vault.version === "v1" ? 10000 : +vault.maxBounty; - maxRewardFactor = maxRewardFactor - governanceFee - committeeFee; - } + const maxRewardFactor = 1 - governanceFee - committeeFee; return { ...vault,