This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (profitable) { | |
const transactionPopulated = await | |
liquidationRouterContract.populateTransaction.swapExactAmountOut( | |
liquidationPair.address, | |
swapRecipient, | |
wantedAmountsOut[selectedIndex], | |
amountInMin, | |
Math.floor(Date.now() / 1000) + 100 // deadline | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get allowance approval | |
const allowance = await tokenInContract.allowance( | |
relayerAddress, | |
liquidationRouterContract.address | |
); | |
// Note that we're setting it to the max allowance as we trust the security | |
// audits of the LiquidationRouter contract | |
if (allowance.lt(exactAmountIn)) { | |
const tx = await tokenInContract.approve( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getRng = async ( | |
rngReadProvider: Provider, | |
auctionContracts: AuctionContracts, | |
reserve: BigNumber, | |
): Promise<RngDrawAuctionContext> => { | |
// RNG Auction Service Info | |
const rngService = await auctionContracts.rngAuctionContract.getNextRngService(); | |
const rngServiceContract = new ethers.Contract(rngService, VrfRngAbi, rngReadProvider); | |
const rngServiceRequestFee = await rngServiceContract.getRequestFee(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Contract, BigNumber } from 'ethers'; | |
import { JsonRpcProvider } from '@ethersproject/providers' | |
import { formatUnits } from '@ethersproject/units'; | |
import { | |
computeDrawWinners, | |
downloadContractsBlob, | |
flagClaimedRpc, | |
Claim, | |
ContractsBlob, | |
} from '@generationsoftware/pt-v5-utils-js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const calculateProfit = async ( | |
gasCostUsd: number, | |
context: DrawAuctionContext, | |
): Promise<boolean> => { | |
const grossProfitUsd = | |
context.state === DrawAuctionState.RngStartVrfHelper | |
? context.rngExpectedRewardUsd | |
: context.rngRelayExpectedRewardUsd; | |
let netProfitUsd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sendTransaction = async ( | |
relayer: Relayer, | |
auctionContracts: AuctionContracts, | |
context: DrawAuctionContext, | |
) => { | |
let populatedTx: PopulatedTransaction; | |
if (context.drawAuctionState === DrawAuctionState.RngStartVrfHelper) { | |
const chainlinkRngAuctionHelper = auctionContracts.chainlinkVRFV2DirectRngAuctionHelperContract; | |
populatedTx = await chainlinkRngAuctionHelper.populateTransaction.transferFeeAndStartRngRequest( | |
REWARD_RECIPIENT, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ethers, Contract } from 'ethers'; | |
import { Provider } from '@ethersproject/providers'; | |
import { | |
ContractsBlob, | |
downloadContractsBlob, | |
getContract, | |
} from '@generationsoftware/pt-v5-utils-js'; | |
export interface AuctionContracts { | |
prizePoolContract: Contract; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const checkBalance = (context: DrawAuctionContext) => { | |
const cannotAffordRngFee = context.relayer.rngFeeTokenBalance.lt(context.rngFeeAmount); | |
if (cannotAffordRngFee) { | |
console.warn( | |
`Need to increase relayer/bot's balance of '${context.rngFeeToken.symbol}' to pay RNG fee.`, | |
); | |
} else { | |
console.log('Sufficient balance ✔'); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BigNumber, ethers } from 'ethers'; | |
import { formatUnits } from '@ethersproject/units'; | |
import { Provider } from '@ethersproject/providers'; | |
import { | |
AuctionContracts, | |
DrawAuctionContext, | |
DrawAuctionRelayerContext, | |
RelayDrawAuctionContext, | |
RngDrawAuctionContext, | |
TokenWithRate, |
NewerOlder