Skip to content

Instantly share code, notes, and snippets.

@chuckbergeron
Last active September 14, 2023 19:55
Show Gist options
  • Save chuckbergeron/2841607f338b9f42c2a41a2e2447df45 to your computer and use it in GitHub Desktop.
Save chuckbergeron/2841607f338b9f42c2a41a2e2447df45 to your computer and use it in GitHub Desktop.
PoolTogether v5 Hyperstructure - Draw Auction Bot, Gather Contract State pt. 1
import { BigNumber, ethers } from 'ethers';
import { formatUnits } from '@ethersproject/units';
import { Provider } from '@ethersproject/providers';
import {
AuctionContracts,
DrawAuctionContext,
DrawAuctionRelayerContext,
RelayDrawAuctionContext,
RngDrawAuctionContext,
TokenWithRate,
} from '@generationsoftware/pt-v5-autotasks-library';
export enum DrawAuctionState {
RngStartVrfHelper = 'RngVrfHelper',
RngRelayBridge = 'RngRelayBridge',
}
import { ERC20Abi } from '../abis/ERC20Abi';
import { VrfRngAbi } from '../abis/VrfRngAbi';
const RELAYER_ADDRESS = ''; // account address of your signer / relayer
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
const RNG_FEE_TOKEN_MARKET_RATE_USD = 6.14
const REWARD_TOKEN_MARKET_RATE_USD = 0.62
const ETH_MARKET_RATE_USD = 1636.27
const getDrawAuctionContext = async (
rngReadProvider: Provider,
relayReadProvider: Provider,
auctionContracts: AuctionContracts,
): Promise<DrawAuctionContext> => {
const prizePoolReserve = await auctionContracts.prizePoolContract.reserve();
const prizePoolReserveForOpenDraw = await auctionContracts.prizePoolContract.reserveForOpenDraw();
const reserve = prizePoolReserve.add(prizePoolReserveForOpenDraw);
const rngContext = await getRng(rngReadProvider, auctionContracts, reserve);
const relayContext = await getRelay(relayReadProvider, auctionContracts, rngContext);
const rngNativeTokenMarketRateUsd = await getNativeTokenMarketRateUsd(RNG_CHAIN_ID);
const relayNativeTokenMarketRateUsd = await getNativeTokenMarketRateUsd(RELAY_CHAIN_ID);
const rngExpectedRewardUsd = rngContext.rngExpectedReward * relayContext.rewardToken.assetRateUsd;
const context = {
...rngContext,
...relayContext,
rngNativeTokenMarketRateUsd,
relayNativeTokenMarketRateUsd,
rngExpectedRewardUsd,
};
return {
...context,
state: getState(context),
};
};
const getState = (context: DrawAuctionContext): DrawAuctionState => {
if (context.rngIsAuctionOpen && context.rngFeeTokenIsSet && context.rngFeeUsd > 0) {
return DrawAuctionState.RngStartVrfHelper;
} else if (context.rngRelayIsAuctionOpen) {
return DrawAuctionState.RngRelayBridge;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment