Skip to content

Instantly share code, notes, and snippets.

@chuckbergeron
Last active September 12, 2023 22:46
Show Gist options
  • Save chuckbergeron/1b0a2cbf12d2328b48ef055ae8941478 to your computer and use it in GitHub Desktop.
Save chuckbergeron/1b0a2cbf12d2328b48ef055ae8941478 to your computer and use it in GitHub Desktop.
PoolTogether v5 Hyperstructure - Prize Claiming Bot, Getting Claim Info
const MIN_PROFIT_USD = 0.1; // $0.10 per prize claimed
const FEE_TOKEN_ASSET_RATE_USD = 0.6; // $0.60 for prize token (likely POOL)
const FEE_TOKEN_DECIMALS = 18;
const GAS_ONE_CLAIM_USD = 0.08; // $0.08 gas cost for one claim
const GAS_EACH_FOLLOWING_CLAIM_USD = 0.02; // $0.02 extra gas cost for each following claim
interface ClaimInfo {
claimCount: number;
minVrgdaFeePerClaim: string;
}
const getClaimInfo = async (
claimerContract: Contract,
tierIndex: number,
claims: Claim[],
): Promise<ClaimInfo> => {
let claimCount = 0;
let claimFeesUsd = 0;
let totalCostUsd = 0;
let prevNetFeesUsd = 0;
let claimFees = BigNumber.from(0);
let minVrgdaFees: BigNumber[] = [];
for (let numClaims = 1; numClaims <= claims.length; numClaims++) {
const nextClaimFees = await claimerContract.functions['computeTotalFees(uint8,uint256)'](
tierIndex,
numClaims,
);
const totalCostUsd =
numClaims === 1
? GAS_ONE_CLAIM_USD
: GAS_ONE_CLAIM_USD + GAS_EACH_FOLLOWING_CLAIM_USD * numClaims;
const claimFeesFormatted = formatUnits(claimFees.toString(), FEE_TOKEN_DECIMALS);
claimFeesUsd = parseFloat(claimFeesFormatted) * FEE_TOKEN_ASSET_RATE_USD;
const nextClaimFeesFormatted = formatUnits(claimFees.toString(), FEE_TOKEN_DECIMALS);
const nextClaimFeesUsd = parseFloat(nextClaimFeesFormatted) * FEE_TOKEN_ASSET_RATE_USD;
const netFeesUsd = nextClaimFeesUsd - totalCostUsd;
if (netFeesUsd > prevNetFeesUsd && netFeesUsd > MIN_PROFIT_USD) {
prevNetFeesUsd = netFeesUsd;
claimCount = numClaims;
claimFees = nextClaimFees;
claimFeesUsd = nextClaimFeesUsd;
minVrgdaFees.push(nextClaimFees);
} else {
break;
}
}
// Sort array of BigNumbers by comparing them using basic JS built-in sort()
minVrgdaFees.sort((a: BigNumber, b: BigNumber) => (a.gt(b) ? 1 : -1));
// Take the lowest BigNumber as the lowest fee we will accept
const minVrgdaFeePerClaim = Boolean(minVrgdaFees[0]) ? minVrgdaFees[0].toString() : '0';
console.log(`$${netProfitUsd} = ($${claimFeesUsd} - $${totalCostUsd})`);
return { claimCount, minVrgdaFeePerClaim };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment