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
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
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
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
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
import { BigNumber, ethers } from 'ethers'; | |
import { formatUnits } from '@ethersproject/units'; | |
import { Provider } from '@ethersproject/providers'; | |
import { | |
AuctionContracts, | |
DrawAuctionContext, | |
DrawAuctionRelayerContext, | |
RelayDrawAuctionContext, | |
RngDrawAuctionContext, | |
TokenWithRate, |
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
import { ethers, BigNumber } from 'ethers'; | |
const { profitable, selectedIndex } = await calculateProfit(wantedAmountsIn, wantedAmountsOut); | |
// Calculates the amount of profit the bot will make on this swap | |
// and if it's profitable or not | |
const calculateProfit = async ( | |
wantedAmountsIn: BigNumber[], | |
wantedAmountsOut: BigNumber[], | |
): Promise<{ profitable: boolean; selectedIndex: number }> => { |
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 { Contract } from 'ethers'; | |
import { Provider } from '@ethersproject/providers'; | |
import { getLiquidationPairComputeExactAmountInMulticall } | |
from '@generationsoftware/pt-v5-autotasks-library'; | |
const { amountIn, amountInMin, wantedAmountsIn } = await calculateAmountIn( | |
readProvider, | |
liquidationPairContract, | |
originalMaxAmountOut, |
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 { originalMaxAmountOut, wantedAmountsOut } = await calculateAmountOut( | |
liquidationPairContract, | |
context, | |
); | |
// Calculates necessary input parameters for the swap call based on current state | |
// of the contracts | |
const calculateAmountOut = async ( | |
liquidationPair: Contract, | |
context: ArbLiquidatorContext, |
NewerOlder