@generationsoftware/pt-v5-autotasks-library
Advanced tools
Comparing version 1.2.7 to 1.3.0
@@ -15,2 +15,3 @@ import chalk from 'chalk'; | ||
console.log(chalk.dim('Config - MIN_PROFIT_THRESHOLD_USD:'), chalk.yellow(config.minProfitThresholdUsd)); | ||
console.log(chalk.dim('Config - ERROR_STATE_MAX_GAS_COST_THRESHOLD_USD:'), chalk.yellow(config.errorStateMaxGasCostThresholdUsd)); | ||
const drawAuctionContracts = instantiateDrawAuctionContracts(config, contracts); | ||
@@ -27,3 +28,4 @@ const context = await getDrawAuctionContextMulticall(config, drawAuctionContracts); | ||
} | ||
if (context.drawAuctionState === DrawAuctionState.Start) { | ||
if (context.drawAuctionState === DrawAuctionState.Start || | ||
context.drawAuctionState === DrawAuctionState.Error) { | ||
console.log(chalk.green(`Processing 'Start Draw' for ${chainName(chainId)}:`)); | ||
@@ -83,8 +85,22 @@ await checkStartDraw(config, context, drawAuctionContracts, rewardRecipient); | ||
const profitable = await calculateStartDrawProfit(config, context, gasCostUsd); | ||
if (profitable) { | ||
await sendPopulatedStartDrawTransaction(config, context, drawAuctionContracts, rewardRecipient); | ||
let sendTransaction; | ||
if (context.drawAuctionState === DrawAuctionState.Error) { | ||
printErrorNote(); | ||
if (gasCostUsd < config.errorStateMaxGasCostThresholdUsd) { | ||
console.log(chalk.yellow('Cost within threshold, sending tx for new random number!')); | ||
sendTransaction = true; | ||
} | ||
else { | ||
console.log(chalk.yellow('Cost above error state re-submit threshold, ignoring for now ...')); | ||
} | ||
} | ||
else if (profitable) { | ||
sendTransaction = true; | ||
} | ||
else { | ||
console.log(chalk.yellow(`Completing current auction currently not profitable. Try again soon ...`)); | ||
} | ||
if (sendTransaction) { | ||
await sendPopulatedStartDrawTransaction(config, context, drawAuctionContracts, rewardRecipient); | ||
} | ||
}; | ||
@@ -118,3 +134,5 @@ const sendPopulatedStartDrawTransaction = async (config, context, drawAuctionContracts, rewardRecipient) => { | ||
printSpacer(); | ||
printNote(); | ||
if (context.drawAuctionState !== DrawAuctionState.Error) { | ||
printNote(); | ||
} | ||
}; | ||
@@ -343,2 +361,9 @@ const checkFinishDraw = async (config, context, drawAuctionContracts, rewardRecipient) => { | ||
}; | ||
const printErrorNote = () => { | ||
console.log(chalk.yellow('|*******************************************************|')); | ||
console.log(chalk.yellow('| |')); | ||
console.log(chalk.yellow('| Witnet random number request returned an error! |')); | ||
console.log(chalk.yellow('| |')); | ||
console.log(chalk.yellow('|*******************************************************|')); | ||
}; | ||
//# sourceMappingURL=drawAuction.js.map |
@@ -57,2 +57,3 @@ import { Contract, BigNumber, Wallet, Signer } from 'ethers'; | ||
export interface DrawAuctionConfig extends AutotaskConfig { | ||
errorStateMaxGasCostThresholdUsd: number; | ||
rewardRecipient?: string; | ||
@@ -80,2 +81,3 @@ } | ||
REWARD_RECIPIENT: string; | ||
ERROR_STATE_MAX_GAS_COST_THRESHOLD_USD: number; | ||
} | ||
@@ -104,2 +106,3 @@ export interface SharedLiquidatorEnvVars extends AutotaskEnvVars { | ||
rewardToken: TokenWithRate; | ||
startDrawError: boolean; | ||
nativeTokenMarketRateUsd?: number; | ||
@@ -106,0 +109,0 @@ drawAuctionState?: DrawAuctionState; |
import { DrawAuctionContracts, DrawAuctionContext, DrawAuctionConfig } from '../types.js'; | ||
export declare enum DrawAuctionState { | ||
Error = "Error", | ||
Start = "Start", | ||
@@ -7,2 +8,8 @@ Finish = "Finish", | ||
} | ||
export interface StartDrawAuction { | ||
recipient: string; | ||
closedAt: number; | ||
drawId: number; | ||
rngRequestId: number; | ||
} | ||
export declare const getDrawAuctionContextMulticall: (config: DrawAuctionConfig, drawAuctionContracts: DrawAuctionContracts) => Promise<DrawAuctionContext>; |
@@ -11,2 +11,3 @@ import { ethers } from 'ethers'; | ||
(function (DrawAuctionState) { | ||
DrawAuctionState["Error"] = "Error"; | ||
DrawAuctionState["Start"] = "Start"; | ||
@@ -23,2 +24,3 @@ DrawAuctionState["Finish"] = "Finish"; | ||
RNG_WITNET_ESTIMATE_RANDOMIZE_FEE_KEY: 'rngWitnet-estimateRandomizeFee', | ||
DRAW_MANAGER_LAST_START_DRAW_AUCTION: 'drawManager-lastStartDrawAuction', | ||
DRAW_MANAGER_CAN_START_DRAW_KEY: 'drawManager-canStartDraw', | ||
@@ -33,3 +35,2 @@ DRAW_MANAGER_START_DRAW_REWARD_KEY: 'drawManager-startDrawReward', | ||
}; | ||
const RELAY_AUCTION_CLOSES_SOON_PERCENT_THRESHOLD = 10; | ||
export const getDrawAuctionContextMulticall = async (config, drawAuctionContracts) => { | ||
@@ -54,2 +55,4 @@ printSpacer(); | ||
queriesOne[QUERY_KEYS.DRAW_MANAGER_START_DRAW_REWARD_KEY] = drawManagerContract.startDrawReward(); | ||
queriesOne[QUERY_KEYS.DRAW_MANAGER_LAST_START_DRAW_AUCTION] = | ||
drawManagerContract.getLastStartDrawAuction(); | ||
queriesOne[QUERY_KEYS.DRAW_MANAGER_CAN_FINISH_DRAW_KEY] = drawManagerContract.canFinishDraw(); | ||
@@ -69,2 +72,3 @@ queriesOne[QUERY_KEYS.DRAW_MANAGER_FINISH_DRAW_REWARD_KEY] = | ||
const resultsOne = await getEthersMulticallProviderResults(multicallProvider, queriesOne); | ||
const lastStartDrawAuction = resultsOne[QUERY_KEYS.DRAW_MANAGER_LAST_START_DRAW_AUCTION]; | ||
const canStartDraw = resultsOne[QUERY_KEYS.DRAW_MANAGER_CAN_START_DRAW_KEY]; | ||
@@ -80,2 +84,4 @@ const startDrawReward = resultsOne[QUERY_KEYS.DRAW_MANAGER_START_DRAW_REWARD_KEY]; | ||
const rewardTokenAddress = resultsOne[QUERY_KEYS.PRIZE_POOL_PRIZE_TOKEN_ADDRESS_KEY]; | ||
const closedDrawId = drawId - 1; | ||
const startDrawError = canStartDraw && closedDrawId === lastStartDrawAuction.rngRequestId; | ||
let queriesTwo = {}; | ||
@@ -118,2 +124,3 @@ queriesTwo[QUERY_KEYS.PRIZE_POOL_DRAW_CLOSES_AT_KEY] = prizePoolContract.drawClosesAt(drawId); | ||
prizePoolDrawClosesAt, | ||
startDrawError, | ||
nativeTokenMarketRateUsd, | ||
@@ -123,3 +130,6 @@ }; | ||
const getDrawAuctionState = (context) => { | ||
if (context.canStartDraw) { | ||
if (context.startDrawError) { | ||
return DrawAuctionState.Error; | ||
} | ||
else if (context.canStartDraw) { | ||
return DrawAuctionState.Start; | ||
@@ -126,0 +136,0 @@ } |
@@ -5,7 +5,9 @@ import { loadEnvVars } from './index.js'; | ||
const rewardRecipient = process.env.REWARD_RECIPIENT; | ||
const errorStateMaxGasCostThresholdUsd = Number(process.env.ERROR_STATE_MAX_GAS_COST_THRESHOLD_USD); | ||
return { | ||
...envVars, | ||
REWARD_RECIPIENT: rewardRecipient, | ||
ERROR_STATE_MAX_GAS_COST_THRESHOLD_USD: errorStateMaxGasCostThresholdUsd, | ||
}; | ||
}; | ||
//# sourceMappingURL=loadDrawAuctionEnvVars.js.map |
{ | ||
"name": "@generationsoftware/pt-v5-autotasks-library", | ||
"version": "1.2.7", | ||
"version": "1.3.0", | ||
"description": "Library of shared utils to run PoolTogether v5 hyperstructure autotasks.", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
447308
7368
15