Skip to content

Commit

Permalink
Merge pull request #790 from hats-finance/develop
Browse files Browse the repository at this point in the history
prod
  • Loading branch information
shayzluf authored Dec 17, 2024
2 parents 3ad721c + eac1e7f commit a8181b4
Show file tree
Hide file tree
Showing 23 changed files with 326 additions and 101 deletions.
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hats.finance/shared",
"version": "1.1.124",
"version": "1.1.125",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/types/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface IBaseEditedVaultDescription {
emails: IEditedCommunicationEmail[];
oneLiner?: string;
intendedCompetitionAmount?: number;
loc?: number;
curator?: {
username: string;
role: CuratorRole;
Expand Down
19 changes: 17 additions & 2 deletions packages/shared/src/types/payout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,28 @@ export type GithubIssue = {
createdBy: number;
labels: string[];
validLabels: string[];
createdAt: string;
body: string;
txHash?: string;
severity?: string;
bonusPointsLabels: {
needsFix: boolean;
needsTest: boolean;
};
};

export type GithubPR = {
id: number;
number: number;
title: string;
createdBy: number;
labels: string[];
createdAt: string;
body: string;
txHash?: string;
bonusSubmissionStatus: "COMPLETE" | "INCOMPLETE" | "PENDING";
linkedIssueNumber?: number;
linkedIssue?: GithubIssue;
};

export type IPayoutData = ISinglePayoutData | ISplitPayoutData;
Expand All @@ -80,7 +95,7 @@ export interface ISinglePayoutData extends IPayoutDataBase {
nftUrl: string;
submissionData?: { id: string; subId: string; idx: number };
decryptedSubmission?: Omit<ISubmittedSubmission, "linkedVault">; // Omit: workaround to avoid circular dependency;
ghIssue?: GithubIssue;
ghIssue?: GithubIssue | GithubPR;
}

// Only for v2 vaults
Expand All @@ -106,7 +121,7 @@ export interface ISplitPayoutBeneficiary {
nftUrl: string;
submissionData?: { id: string; subId: string; idx: number };
decryptedSubmission?: Omit<ISubmittedSubmission, "linkedVault">; // Omit: workaround to avoid circular dependency;
ghIssue?: GithubIssue;
ghIssue?: GithubIssue | GithubPR;
}

export interface IPayoutSignature {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ interface IBaseVaultDescription {
starttime?: number;
oneLiner?: string;
intendedCompetitionAmount?: number;
loc?: number;
curator?: {
username: string;
role: CuratorRole;
Expand Down
11 changes: 10 additions & 1 deletion packages/shared/src/utils/vaults.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,23 @@ export const getVaultInfoWithCommittee = async (

export const getAllVaultsAddressesByChain = async (
chainId: number
): Promise<{ id: string; registered: boolean; version: IVault["version"]; claimsManager: IVault["claimsManager"] }[]> => {
): Promise<
{
id: string;
descriptionHash: string;
registered: boolean;
version: IVault["version"];
claimsManager: IVault["claimsManager"];
}[]
> => {
if (!chainId) return [];

try {
const GET_VAULTS = `
query getVaults {
vaults(where: {version_not: "v1"}) {
id
descriptionHash
registered
claimsManager
version
Expand Down
14 changes: 0 additions & 14 deletions packages/web/src/components/Seo/Seo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ export const Seo = ({ isMainPage, title, description, image }: SeoProps) => {
image: image ?? require("../../assets/images/hats_og.png"),
};

// const allowedEndpoints = [
// "'self'",
// "https://*.hats.finance",
// "https://*.infura.io",
// "https://api.coingecko.com/",
// "https://cloudflare-eth.com/",
// new URL(stagingServiceUrl).protocol + "//" + new URL(stagingServiceUrl).host,
// new URL(prodServiceUrl).protocol + "//" + new URL(prodServiceUrl).host,
// ...Object.values(appChains).map((chain) => chain.subgraph),
// ...Object.values(appChains).map((chain) => chain.uniswapSubgraph),
// ...Object.values(externalPricingProvidersUrls),
// ];
// const connectSrc = allowedEndpoints.join(" ");

return (
<Helmet prioritizeSeoTags htmlAttributes={{ lang: "en" }} titleTemplate="%s | HatsFinance" title={seo.title}>
{isMainPage && (
Expand Down
22 changes: 0 additions & 22 deletions packages/web/src/hooks/nft/getStakerData.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { useAccount } from "wagmi";
import { parseMasters, parsePayouts, parseUserNfts, parseVaults } from "./parser";
import { IGraphVaultsData, getSubgraphData } from "./vaultsService";

const DATA_REFRESH_TIME = 30000;

const INITIAL_NETWORK_DATA = {
vaults: [] as IVault[],
masters: [] as IMaster[],
Expand All @@ -29,8 +27,7 @@ export const useMultiChainVaultsV2 = () => {
queries: Object.keys(appChains).map((chainId) => ({
queryKey: ["subgraph", chainId],
queryFn: () => getSubgraphData(+chainId, account),
// refetchInterval: DATA_REFRESH_TIME, // We dont want to refetch data automatically anymore
refetchIntervalInBackground: false,
refetchOnWindowFocus: false,
retry: false,
})),
});
Expand Down
7 changes: 6 additions & 1 deletion packages/web/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,9 @@
"bonusPointsReminder": "Remember, you have 12 hours to submit after claiming. Happy fixing and testing!",
"bonusPointsEnabled": "Enable bonus points?",
"claimFixAndTest": "Claim fix and test",
"linesOfCode": "Lines of code (LoC)",
"issueAlreadyHaveValidSubmission": "This issue already have a valid submission. You can submit complementary submission in other issue.",
"oneSubmissionIsBeingReviewed": "One submission is being reviewed. Please wait, if the submission is not complete, you can submit another one.",
"MyWallet": {
"overview": "Overview",
"pointValue": "Point value",
Expand Down Expand Up @@ -1650,7 +1653,9 @@
"curator-placeholder": "Select curator of the vault",
"curatorRole": "Curator role",
"curatorRole-placeholder": "Select the role of the curator",
"clearCurator": "Clear curator"
"clearCurator": "Clear curator",
"loc-placeholder": "Enter number of lines of code",
"loc": "Lines of code"
},
"signatureMessage": "I hereby confirm the details in ipfs hash {{ipfsHash}}.",
"committee-details": "Committee Details",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export const PayoutFormPage = () => {
});
}
} else {
if (vault.description["project-metadata"].bonusPointsEnabled) {
severities.push({
label: "Complementary",
value: "complementary",
});
}

for (const splitPayoutBeneficiary of payout.payoutData.beneficiaries) {
if (
splitPayoutBeneficiary.severity &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GithubIssue, IPayoutResponse, ISplitPayoutData, IVault } from "@hats.finance/shared";
import { GithubIssue, GithubPR, IPayoutResponse, ISplitPayoutData, IVault } from "@hats.finance/shared";
import DeleteIcon from "@mui/icons-material/DeleteOutlineOutlined";
import InfoIcon from "@mui/icons-material/InfoOutlined";
import MoreIcon from "@mui/icons-material/MoreVertOutlined";
Expand All @@ -8,7 +8,12 @@ import useModal from "hooks/useModal";
import { useOnChange } from "hooks/usePrevious";
import { hasSubmissionData } from "pages/CommitteeTools/PayoutsTool/utils/hasSubmissionData";
import { SubmissionCard } from "pages/CommitteeTools/SubmissionsTool/SubmissionsListPage/SubmissionCard";
import { getGhIssueFromSubmission, getGithubIssuesFromVault } from "pages/CommitteeTools/SubmissionsTool/submissionsService.api";
import {
getGhIssueFromSubmission,
getGhPRFromSubmission,
getGithubIssuesFromVault,
getGithubPRsFromVault,
} from "pages/CommitteeTools/SubmissionsTool/submissionsService.api";
import { useVaultSubmissionsByKeystore } from "pages/CommitteeTools/SubmissionsTool/submissionsService.hooks";
import { useEffect, useState } from "react";
import { Controller, UseFieldArrayRemove, useWatch } from "react-hook-form";
Expand Down Expand Up @@ -99,6 +104,7 @@ export const SplitPayoutBeneficiaryForm = ({
});

const [vaultGithubIssues, setVaultGithubIssues] = useState<GithubIssue[] | undefined>(undefined);
const [vaultGithubPRs, setVaultGithubPRs] = useState<GithubPR[] | undefined>(undefined);
const [isLoadingGH, setIsLoadingGH] = useState<boolean>(false);

// Get information from github
Expand All @@ -113,6 +119,12 @@ export const SplitPayoutBeneficiaryForm = ({
setIsLoadingGH(false);
};
loadGhIssues();

const loadGhPRs = async () => {
const ghPRs = await getGithubPRsFromVault(vault);
setVaultGithubPRs(ghPRs);
};
loadGhPRs();
}, [vault, vaultGithubIssues, beneficiarySubmission, isLoadingGH]);

const getMoreOptions = () => {
Expand Down Expand Up @@ -153,6 +165,10 @@ export const SplitPayoutBeneficiaryForm = ({
];
};

const selectedSubmission = isPayoutCreated
? beneficiaries[index]?.decryptedSubmission ?? beneficiarySubmission!
: beneficiarySubmission!;

return (
<div>
<div className="mb-1">{index + 1}.</div>
Expand All @@ -166,10 +182,10 @@ export const SplitPayoutBeneficiaryForm = ({
submission={
isPayoutCreated ? beneficiaries[index]?.decryptedSubmission ?? beneficiarySubmission! : beneficiarySubmission!
}
ghIssue={getGhIssueFromSubmission(
isPayoutCreated ? beneficiaries[index]?.decryptedSubmission ?? beneficiarySubmission! : beneficiarySubmission!,
vaultGithubIssues
)}
ghIssue={
getGhIssueFromSubmission(selectedSubmission, vaultGithubIssues) ||
getGhPRFromSubmission(selectedSubmission, vaultGithubPRs, vaultGithubIssues)
}
/>
</div>
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ISplitPayoutBeneficiary, ISplitPayoutData } from "@hats.finance/shared";
import { GithubPR, ISplitPayoutBeneficiary, ISplitPayoutData } from "@hats.finance/shared";
import millify from "millify";

const BONUS_POINTS_CONSTRAINTS = {
fix: 0.1, // 10%
test: 0.05, // 5%
};

const DECIMALS_TO_USE = 4;

// type IMultipayoutCalculation = ISplitPayoutBeneficiary[];
Expand Down Expand Up @@ -98,16 +103,39 @@ export const autocalculateMultiPayoutPointingSystem = (

const needPoints = beneficiaries.every((ben) => ben.percentageOfPayout === "" || ben.percentageOfPayout === undefined);
for (let beneficiary of beneficiaries) {
const sevInfo = constraints.find((constraint) => constraint.severity.toLowerCase() === beneficiary.severity.toLowerCase());
const defaultPoints = sevInfo?.points ? `${sevInfo.points.value.first}` : "1";

const beneficiaryCalculated: IBeneficiaryWithCalcs = {
...beneficiary,
percentageOfPayout: needPoints ? defaultPoints : beneficiary.percentageOfPayout,
amount: 0,
calculatedReward: 0,
};
beneficiariesCalculated.push(beneficiaryCalculated);
if (beneficiary.severity.toLowerCase() === "complementary") {
const mainIssueSev = (beneficiary.ghIssue as GithubPR).linkedIssue?.severity;
const mainIssueSevInfo = constraints.find(
(constraint) => constraint.severity.toLowerCase() === mainIssueSev?.toLowerCase()
);
const mainIssuePoints = mainIssueSevInfo?.points ? `${mainIssueSevInfo.points.value.first}` : "1";

let totalMultiplier = 0;

if (beneficiary.ghIssue?.labels?.includes("complete-fix")) totalMultiplier += BONUS_POINTS_CONSTRAINTS.fix;
if (beneficiary.ghIssue?.labels?.includes("complete-test")) totalMultiplier += BONUS_POINTS_CONSTRAINTS.test;

const complementaryPoints = totalMultiplier * +mainIssuePoints;

const beneficiaryCalculated: IBeneficiaryWithCalcs = {
...beneficiary,
percentageOfPayout: needPoints ? `${complementaryPoints.toFixed(4)}` : beneficiary.percentageOfPayout,
amount: 0,
calculatedReward: 0,
};
beneficiariesCalculated.push(beneficiaryCalculated);
} else {
const sevInfo = constraints.find((constraint) => constraint.severity.toLowerCase() === beneficiary.severity.toLowerCase());
const defaultPoints = sevInfo?.points ? `${sevInfo.points.value.first}` : "1";

const beneficiaryCalculated: IBeneficiaryWithCalcs = {
...beneficiary,
percentageOfPayout: needPoints ? defaultPoints : beneficiary.percentageOfPayout,
amount: 0,
calculatedReward: 0,
};
beneficiariesCalculated.push(beneficiaryCalculated);
}
}

const totalPointsToPay = beneficiariesCalculated.reduce((prev, curr) => prev + +curr.percentageOfPayout, 0);
Expand Down
Loading

0 comments on commit a8181b4

Please sign in to comment.