Skip to content

Commit

Permalink
fix: payout issue in v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavaparoksham committed May 15, 2024
1 parent da95485 commit 406cfd0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
51 changes: 45 additions & 6 deletions packages/common/src/allo/backends/allo-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { PermitSignature, getPermitType } from "../voting";
import Erc20ABI from "../abis/erc20";
import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
import { buildUpdatedRowsOfApplicationStatuses } from "../application";
import { generateMerkleTree } from "./allo-v1";
import { BigNumber, utils } from "ethers";

function getStrategyAddress(strategy: RoundCategory, chainId: ChainId): string {
Expand Down Expand Up @@ -1181,7 +1180,7 @@ export class AlloV2 implements Allo {
);

// Generate merkle tree
const { tree, matchingResults } = generateMerkleTree(args.allProjects);
const { tree, matchingResults } = generateMerkleTreeV2(args.allProjects);

// Filter projects to be paid from matching results
const projectsToBePaid = matchingResults.filter((project) =>
Expand All @@ -1194,11 +1193,14 @@ export class AlloV2 implements Allo {
if (!project.index) {
throw new AlloError("Project index is required");
}
const distribution: [number, string, BigNumber, string] = [
if (!project.anchorAddress) {
throw new AlloError("Anchor address is required");
}
const distribution: [number, string, string, BigNumber] = [
project.index,
project.applicationId,
project.anchorAddress,
project.projectPayoutAddress,
project.matchAmountInToken,
project.projectId,
];

// Generate merkle proof
Expand All @@ -1207,7 +1209,7 @@ export class AlloV2 implements Allo {
projectsWithMerkleProof.push({
index: distribution[0],
recipientId: distribution[1],
amount: distribution[2],
amount: distribution[3],
merkleProof: validMerkleProof,
});
});
Expand Down Expand Up @@ -1340,3 +1342,40 @@ export type ProjectWithMerkleProof = {
amount: BigNumber;
merkleProof: string[];
};

/**
* Generate merkle tree
*
* To get merkle Proof: tree.getProof(distributions[0]);
* @param matchingResults MatchingStatsData[]
* @returns
*/
export const generateMerkleTreeV2 = (
matchingResults: MatchingStatsData[]
): {
distribution: [number, string, string, BigNumber][];
tree: StandardMerkleTree<[number, string, string, BigNumber]>;
matchingResults: MatchingStatsData[];
} => {
const distribution: [number, string, string, BigNumber][] = [];

matchingResults.forEach((matchingResult, index) => {
matchingResults[index].index = index;

distribution.push([
index,
matchingResult.anchorAddress ?? "",
matchingResult.projectPayoutAddress,
matchingResult.matchAmountInToken, // TODO: FIX
]);
});

const tree = StandardMerkleTree.of(distribution, [
"uint256",
"address",
"address",
"uint256",
]);

return { distribution, tree, matchingResults };
};
3 changes: 2 additions & 1 deletion packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type MatchingStatsData = {
matchPoolPercentage: number;
projectId: string;
applicationId: string;
anchorAddress?: string;
matchAmountInToken: BigNumber;
originalMatchAmountInToken: BigNumber;
projectPayoutAddress: string;
Expand Down Expand Up @@ -110,4 +111,4 @@ export type VotingToken = {
//TODO: split PayoutTokens and VotingTokens in
// 2 different types/lists and remove the following attribute
canVote: boolean;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export const useGroupProjectsByPaymentStatus = (
matchPoolPercentage: matchingStatsData.matchPoolPercentage,
projectId: matchingStatsData.projectId,
applicationId: matchingStatsData.applicationId,
anchorAddress: applications?.find(
(application) =>
application.projectId === matchingStatsData.projectId
)?.anchorAddress,
matchAmountInToken: BigNumber.from(
matchingStatsData.matchAmountInToken
),
Expand All @@ -81,7 +85,7 @@ export const useGroupProjectsByPaymentStatus = (
};
}
) ?? [],
[round.matchingDistribution?.matchingDistribution]
[round.matchingDistribution?.matchingDistribution, applications]
);

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/round-manager/src/features/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export type MatchingStatsData = {
matchPoolPercentage: number;
projectId: string;
applicationId: string;
anchorAddress?: string;
matchAmountInToken: BigNumber;
originalMatchAmountInToken: BigNumber;
projectPayoutAddress: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ export function PayProjectsTable(props: {
? getAddress(props.round.payoutStrategy.id)
: props.round.id,
allProjects: props.allProjects,
projectIdsToBePaid: selectedProjects.map((p) => p.projectId),
projectIdsToBePaid:
alloVersion === "allo-v1"
? selectedProjects.map((p) => p.projectId)
: selectedProjects.map((p) => p.anchorAddress ?? ""),
})
.on("transaction", (result) => {
if (result.type === "error") {
Expand Down

0 comments on commit 406cfd0

Please sign in to comment.