Skip to content

Instantly share code, notes, and snippets.

@chuckbergeron
Last active September 19, 2023 21:49
Show Gist options
  • Save chuckbergeron/770b7a7935bfbffaf81574b06cd234fc to your computer and use it in GitHub Desktop.
Save chuckbergeron/770b7a7935bfbffaf81574b06cd234fc to your computer and use it in GitHub Desktop.
PoolTogether v5 Hyperstructure - Draw Auction Bot, Gather Contract State pt. 3
export const getRelay = async (
readProvider: Provider,
auctionContracts: AuctionContracts,
rngContext: RngDrawAuctionContext,
): Promise<RelayDrawAuctionContext> => {
// Prize Pool Info
const prizePoolOpenDrawEndsAt = await auctionContracts.prizePoolContract.openDrawEndsAt();
const rewardTokenAddress = await auctionContracts.prizePoolContract.prizeToken();
const rewardTokenContract = new ethers.Contract(rewardTokenAddress, ERC20Abi, readProvider);
// Reward Token
const rewardTokenSymbol = await rewardTokenContract.symbol();
const rewardToken: TokenWithRate = {
address: rewardTokenAddress,
decimals: await rewardTokenContract.decimals(),
name: await rewardTokenContract.name(),
symbol: rewardTokenSymbol,
assetRateUsd: REWARD_TOKEN_MARKET_RATE_USD,
};
// Relay Auction Info
const rngRelayLastSequenceId = auctionContracts.rngAuctionContract.lastSequenceId();
const lastSequenceCompleted = await auctionContracts.rngRelayAuctionContract.isSequenceCompleted(
rngRelayLastSequenceId,
);
const rngRelayIsAuctionOpen =
rngRelayLastSequenceId > 0 && rngContext.rngIsRngComplete && !lastSequenceCompleted;
// Relayer Reward
let rngRelayExpectedReward, rngRelayExpectedRewardUsd;
if (rngRelayIsAuctionOpen) {
const [randomNumber, completedAt] =
await auctionContracts.rngAuctionContract.callStatic.getRngResults();
const rngLastAuctionResult = await auctionContracts.rngAuctionContract.getLastAuctionResult();
const elapsedTime = Math.floor(Date.now() / 1000) - Number(completedAt.toString());
const rngRelayRewardFraction =
await auctionContracts.rngRelayAuctionContract.computeRewardFraction(elapsedTime);
const auctionResult = {
rewardFraction: rngRelayRewardFraction,
recipient: RELAYER_ADDRESS,
};
const auctionResults = [];
auctionResults[0] = rngLastAuctionResult;
auctionResults[1] = auctionResult;
const rngRelayExpectedRewardResult =
await auctionContracts.rngRelayAuctionContract.callStatic.computeRewards(auctionResults);
rngRelayExpectedReward = rngRelayExpectedRewardResult[1];
rngRelayExpectedRewardUsd =
parseFloat(formatUnits(rngRelayExpectedReward.toString(), rewardToken.decimals)) *
rewardToken.assetRateUsd;
}
return {
prizePoolOpenDrawEndsAt,
rewardToken,
rngRelayIsAuctionOpen,
rngRelayExpectedReward,
rngRelayExpectedRewardUsd,
rngRelayLastSequenceId,
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment