Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
feat: add check for max permit price
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Aug 17, 2023
1 parent 9013519 commit 0a2d848
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/handlers/payout/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export const incentivizeComments = async () => {
logger.debug(`Comment parsed for the user: ${user}. comments: ${JSON.stringify(commentsByNode)}, sum: ${rewardValue}`);
const account = await getWalletAddress(user);
const amountInETH = rewardValue.mul(baseMultiplier).div(1000);
if (amountInETH.gt(paymentPermitMaxPrice)) {
logger.info(`Skipping comment reward for user ${user} because reward is higher than payment permit max price`);
continue;
}
if (account) {
const { payoutUrl } = await generatePermit2Signature(account, amountInETH, issue.node_id);
comment = `${comment}### [ **${user}: [ CLAIM ${amountInETH} ${tokenSymbol.toUpperCase()} ]** ](${payoutUrl})\n`;
Expand Down Expand Up @@ -181,7 +185,15 @@ export const incentivizeCreatorComment = async () => {
}

const tokenSymbol = await getTokenSymbol(paymentToken, rpc);
const result = await generatePermitForComments(creator.login, [description], issueCreatorMultiplier, incentives, tokenSymbol, issue.node_id);
const result = await generatePermitForComments(
creator.login,
[description],
issueCreatorMultiplier,
incentives,
tokenSymbol,
issue.node_id,
paymentPermitMaxPrice
);

if (result.payoutUrl) {
logger.info(`Permit url generated for creator. reward: ${result.payoutUrl}`);
Expand All @@ -198,7 +210,8 @@ const generatePermitForComments = async (
multiplier: number,
incentives: Incentives,
tokenSymbol: string,
node_id: string
node_id: string,
paymentPermitMaxPrice: number
): Promise<{ comment: string; payoutUrl?: string; amountInETH?: Decimal }> => {
const logger = getLogger();
const commentsByNode = await parseComments(comments, ItemsToExclude);
Expand All @@ -210,6 +223,10 @@ const generatePermitForComments = async (
logger.debug(`Comment parsed for the user: ${user}. comments: ${JSON.stringify(commentsByNode)}, sum: ${rewardValue}`);
const account = await getWalletAddress(user);
const amountInETH = rewardValue.mul(multiplier).div(1000);
if (amountInETH.gt(paymentPermitMaxPrice)) {
logger.info(`Skipping issue creator reward for user ${user} because reward is higher than payment permit max price`);
return { comment: "" };
}
let comment = `#### Task Creator Reward\n`;
if (account) {
const { payoutUrl } = await generatePermit2Signature(account, amountInETH, node_id);
Expand Down

0 comments on commit 0a2d848

Please sign in to comment.