Skip to content

Commit

Permalink
fix: disable overclaim dispute
Browse files Browse the repository at this point in the history
  • Loading branch information
Picodes committed Feb 13, 2024
1 parent b3cba6f commit 69f3ef4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 55 deletions.
30 changes: 15 additions & 15 deletions src/bot/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export const checkRoots: Step = async ({ logger }, report) => {
try {
const { startTree, endTree } = report;

const startRoot = buildMerklTree(startTree.rewards).tree.getHexRoot();
const endRoot = buildMerklTree(endTree.rewards).tree.getHexRoot();
const startRoot = buildMerklTree(startTree.rewards).getHexRoot();
const endRoot = buildMerklTree(endTree.rewards).getHexRoot();

logger?.computedRoots(startRoot, endRoot);

Expand Down Expand Up @@ -137,19 +137,19 @@ export const checkOverclaimedRewards: Step = async ({ onChainProvider }, report)
try {
const { holdersReport } = report;
expandedHoldersReport = await validateClaims(onChainProvider, holdersReport);
const overclaims = expandedHoldersReport.overclaimed;

if (
overclaims?.filter((a) => {
try {
const add = a?.split(':')[0];
return !(ALLOWED_OVER_CLAIM?.includes(add?.toLowerCase()) || ALLOWED_OVER_CLAIM?.includes(getAddress(add)));
} catch {
return true;
}
}).length > 0
)
throw overclaims.join('\n');
// const overclaims = expandedHoldersReport.overclaimed;

// if (
// overclaims?.filter((a) => {
// try {
// const add = a?.split(':')[0];
// return !(ALLOWED_OVER_CLAIM?.includes(add?.toLowerCase()) || ALLOWED_OVER_CLAIM?.includes(getAddress(add)));
// } catch {
// return true;
// }
// }).length > 0
// )
// throw overclaims.join('\n');

return Result.Success({ ...report, holdersReport: expandedHoldersReport });
} catch (reason) {
Expand Down
4 changes: 2 additions & 2 deletions src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default async function (context: DisputeContext, fromTimeStamp: number, t

logger.trees(startEpoch, startTree, endEpoch, endTree);

const endRoot = buildMerklTree(endTree.rewards).tree.getHexRoot();
const startRoot = buildMerklTree(startTree.rewards).tree.getHexRoot();
const endRoot = buildMerklTree(endTree.rewards).getHexRoot();
const startRoot = buildMerklTree(startTree.rewards).getHexRoot();

logger.computedRoots(startRoot, endRoot);

Expand Down
62 changes: 24 additions & 38 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,65 +71,51 @@ export const fetchPoolName = async (chainId: number, pool: string, amm: AMM) =>

export const round = (n: number, dec: number) => Math.round(n * 10 ** dec) / 10 ** dec;

export const buildMerklTree = (
underylingTreeData: UnderlyingTreeType
): {
tree: MerkleTree;
tokens: string[];
} => {
export const buildMerklTree = (underylingTreeData: UnderlyingTreeType): MerkleTree => {
/**
* 1 - Build the global list of users
*/
const users: string[] = [];
const auxUsers = {};
for (const id of Object.keys(underylingTreeData)) {
const rewardUsers = Object.keys(underylingTreeData[id].holders);
for (const r of rewardUsers) {
if (!users.includes(r)) {
users.push(r);
if (!auxUsers[r]) {
auxUsers[r] = true;
}
}
}

/**
* 2 - Build the global list of tokens
*/
const tokens: string[] = tokensFromTree(underylingTreeData);
const users = Object.keys(auxUsers);

/**
* 3 - Build the tree
*/
const sums = {};
const leaves = [];
for (const u of users) {
for (const t of tokens) {
let sum = BigNumber.from(0);
for (const id of Object.keys(underylingTreeData)) {
const distribution = underylingTreeData[id];
if (distribution.token === t) {
sum = sum?.add(distribution?.holders[u]?.amount.toString() ?? 0);
}
for (const id of Object.keys(underylingTreeData)) {
const rewardUsers = Object.keys(underylingTreeData[id].holders);
const t = underylingTreeData[id].token;
for (const u of rewardUsers) {
if (!sums[u]) {
sums[u] = {};
}
if (!!sum && sum.gt(0)) {
if (!sums[u][t]) {
sums[u][t] = BigNumber.from(0);
}
sums[u][t] = sums[u][t]?.add(underylingTreeData[id].holders[u]?.amount.toString() ?? 0);
}
}

for (const u of users) {
for (const t of Object.keys(sums[u])) {
if (!!sums[u][t] && sums[u][t].gt(0)) {
const hash = ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(['address', 'address', 'uint256'], [utils.getAddress(u), t, sum])
ethers.utils.defaultAbiCoder.encode(['address', 'address', 'uint256'], [utils.getAddress(u), t, sums[u][t]])
);
leaves.push(hash);
}
}
}
const tree = new MerkleTree(leaves, keccak256, MERKL_TREE_OPTIONS);

return {
tokens,
tree,
};
};

export const tokensFromTree = (json: AggregatedRewardsType['rewards']): string[] => {
const tokens: string[] = [];
for (const id of Object.keys(json)) {
if (!tokens.includes(json[id].token)) {
tokens.push(json[id].token);
}
}
return tokens;
return tree;
};

0 comments on commit 69f3ef4

Please sign in to comment.