@generationsoftware/pt-v5-autotasks-library
Advanced tools
Comparing version 1.6.1 to 1.7.0
@@ -16,4 +16,4 @@ import chalk from 'chalk'; | ||
const rewardRecipient = findRecipient(config); | ||
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)); | ||
console.log(chalk.dim('Config - MIN_PROFIT_THRESHOLD_USD:'), chalk.yellowBright(config.minProfitThresholdUsd)); | ||
console.log(chalk.dim('Config - ERROR_STATE_MAX_GAS_COST_THRESHOLD_USD:'), chalk.yellowBright(config.errorStateMaxGasCostThresholdUsd)); | ||
const drawAuctionContracts = instantiateDrawAuctionContracts(config, contracts); | ||
@@ -26,3 +26,3 @@ const context = await getDrawAuctionContextMulticall(config, drawAuctionContracts); | ||
printAsterisks(); | ||
console.log(chalk.yellow(`Currently no draw auctions to start or finish. Exiting ...`)); | ||
console.log(chalk.yellowBright(`Currently no draw auctions to start or finish. Exiting ...`)); | ||
printSpacer(); | ||
@@ -33,7 +33,7 @@ return; | ||
context.drawAuctionState === DrawAuctionState.Error) { | ||
console.log(chalk.green(`Processing 'Start Draw' for ${chainName(chainId)}:`)); | ||
console.log(chalk.greenBright(`Processing 'Start Draw' for ${chainName(chainId)}:`)); | ||
await checkStartDraw(config, context, drawAuctionContracts, rewardRecipient); | ||
} | ||
else if (context.drawAuctionState === DrawAuctionState.Finish) { | ||
console.log(chalk.green(`Processing 'Finish Draw' for ${chainName(chainId)}:`)); | ||
console.log(chalk.greenBright(`Processing 'Finish Draw' for ${chainName(chainId)}:`)); | ||
await checkFinishDraw(config, context, drawAuctionContracts, rewardRecipient); | ||
@@ -62,3 +62,3 @@ } | ||
catch (e) { | ||
console.warn(chalk.yellow('Unable to find RngWitnet contract. Likely uses RngBlockhash')); | ||
console.warn(chalk.yellowBright('Unable to find RngWitnet contract. Likely uses RngBlockhash')); | ||
} | ||
@@ -69,3 +69,3 @@ try { | ||
catch (e) { | ||
console.warn(chalk.yellow('Unable to find RngBlockhash contract. Likely uses RngWitnet')); | ||
console.warn(chalk.yellowBright('Unable to find RngBlockhash contract. Likely uses RngWitnet')); | ||
} | ||
@@ -97,7 +97,7 @@ logTable({ | ||
if (gasCostUsd < config.errorStateMaxGasCostThresholdUsd) { | ||
console.log(chalk.yellow('Cost within threshold, sending tx for new random number!')); | ||
console.log(chalk.yellowBright('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 ...')); | ||
console.log(chalk.yellowBright('Cost above error state re-submit threshold, ignoring for now ...')); | ||
} | ||
@@ -109,3 +109,3 @@ } | ||
else { | ||
console.log(chalk.yellow(`Completing current auction currently not profitable. Try again soon ...`)); | ||
console.log(chalk.yellowBright(`Completing current auction currently not profitable. Try again soon ...`)); | ||
} | ||
@@ -118,4 +118,4 @@ if (sendTransaction) { | ||
const { wallet, provider } = config; | ||
console.log(chalk.yellow(`Start Draw Transaction:`)); | ||
console.log(chalk.green(`Execute rngWitnet#startDraw`)); | ||
console.log(chalk.yellowBright(`Start Draw Transaction:`)); | ||
console.log(chalk.greenBright(`Execute rngWitnet#startDraw`)); | ||
printSpacer(); | ||
@@ -162,3 +162,3 @@ let txParams; | ||
else { | ||
console.log(chalk.yellow(`Completing current auction currently not profitable. Try again soon ...`)); | ||
console.log(chalk.yellowBright(`Completing current auction currently not profitable. Try again soon ...`)); | ||
} | ||
@@ -203,3 +203,3 @@ }; | ||
printSpacer(); | ||
console.log(chalk.blue(`Calculating profit ...`)); | ||
console.log(chalk.blueBright(`Calculating profit ...`)); | ||
console.log(chalk.magenta('Profit/Loss (USD):')); | ||
@@ -225,3 +225,3 @@ printSpacer(); | ||
printSpacer(); | ||
console.log(chalk.blue(`Calculating profit ...`)); | ||
console.log(chalk.blueBright(`Calculating profit ...`)); | ||
printSpacer(); | ||
@@ -264,3 +264,3 @@ console.log(chalk.magenta('Profit/Loss (USD):')); | ||
logStringValue(`2b. Start Draw Expected Reward:`, `${ethers.utils.formatUnits(context.startDrawReward, context.rewardToken.decimals)} ${context.rewardToken.symbol}`); | ||
console.log(chalk.grey(`2c. Start Draw Expected Reward (USD):`), chalk.yellow(`$${roundTwoDecimalPlaces(context.startDrawRewardUsd)}`), chalk.dim(`$${context.startDrawRewardUsd}`)); | ||
console.log(chalk.grey(`2c. Start Draw Expected Reward (USD):`), chalk.yellowBright(`$${roundTwoDecimalPlaces(context.startDrawRewardUsd)}`), chalk.dim(`$${context.startDrawRewardUsd}`)); | ||
logStringValue(`2d. PrizePool (${chainName(chainId)}) can start draw in:`, `${(context.prizePoolDrawClosesAt - Math.ceil(Date.now() / 1000)) / 60} minutes`); | ||
@@ -273,3 +273,3 @@ printSpacer(); | ||
logStringValue(`3b. Finish Draw Expected Reward:`, `${ethers.utils.formatUnits(context.finishDrawReward, context.rewardToken.decimals)} ${context.rewardToken.symbol}`); | ||
console.log(chalk.grey(`3c. Finish Draw Expected Reward (USD):`), chalk.yellow(`$${roundTwoDecimalPlaces(context.finishDrawRewardUsd)}`), chalk.dim(`$${context.finishDrawRewardUsd}`)); | ||
console.log(chalk.grey(`3c. Finish Draw Expected Reward (USD):`), chalk.yellowBright(`$${roundTwoDecimalPlaces(context.finishDrawRewardUsd)}`), chalk.dim(`$${context.finishDrawRewardUsd}`)); | ||
printSpacer(); | ||
@@ -279,3 +279,3 @@ }; | ||
const { nativeTokenMarketRateUsd } = context; | ||
console.log(chalk.blue(`Estimating RngWitnet#startDraw() gas costs ...`)); | ||
console.log(chalk.blueBright(`Estimating RngWitnet#startDraw() gas costs ...`)); | ||
printSpacer(); | ||
@@ -322,3 +322,3 @@ let txParams; | ||
const getFinishDrawGasCostUsd = async (txParams, contract, config, context) => { | ||
console.log(chalk.blue(`Estimating DrawManager#finishDraw() gas costs ...`)); | ||
console.log(chalk.blueBright(`Estimating DrawManager#finishDraw() gas costs ...`)); | ||
printSpacer(); | ||
@@ -335,3 +335,3 @@ const { nativeTokenMarketRateUsd } = context; | ||
if (!estimatedGasLimit || estimatedGasLimit.eq(0)) { | ||
console.error(chalk.yellow('Estimated gas limit is 0 ...')); | ||
console.error(chalk.yellowBright('Estimated gas limit is 0 ...')); | ||
return 0; | ||
@@ -347,3 +347,3 @@ } | ||
const { avgFeeUsd } = await getFeesUsd(chainId, estimatedGasLimit, nativeTokenMarketRateUsd, provider, populatedTx.data); | ||
console.log(chalk.grey(`Gas Cost (USD):`), chalk.yellow(`$${roundTwoDecimalPlaces(avgFeeUsd)}`), chalk.dim(`$${avgFeeUsd}`)); | ||
console.log(chalk.grey(`Gas Cost (USD):`), chalk.yellowBright(`$${roundTwoDecimalPlaces(avgFeeUsd)}`), chalk.dim(`$${avgFeeUsd}`)); | ||
return avgFeeUsd; | ||
@@ -355,3 +355,3 @@ }; | ||
const estimatedGasLimitWithBufferAsNumber = Number(estimatedGasLimit) + DRAW_GAS_LIMIT_BUFFER; | ||
console.log(chalk.green(`Execute DrawManager#finishDraw`)); | ||
console.log(chalk.greenBright(`Execute DrawManager#finishDraw`)); | ||
console.log(chalk.greenBright.bold(`Sending ...`)); | ||
@@ -373,16 +373,16 @@ printSpacer(); | ||
const printNote = () => { | ||
console.log(chalk.yellow('|*******************************************************|')); | ||
console.log(chalk.yellow('| |')); | ||
console.log(chalk.yellow('| Rewards accumulate post-draw on the PrizePool! |')); | ||
console.log(chalk.yellow('| Withdraw your rewards manually from that contract. |')); | ||
console.log(chalk.yellow('| |')); | ||
console.log(chalk.yellow('|*******************************************************|')); | ||
console.log(chalk.yellowBright('|*******************************************************|')); | ||
console.log(chalk.yellowBright('| |')); | ||
console.log(chalk.yellowBright('| Rewards accumulate post-draw on the PrizePool! |')); | ||
console.log(chalk.yellowBright('| Withdraw your rewards manually from that contract. |')); | ||
console.log(chalk.yellowBright('| |')); | ||
console.log(chalk.yellowBright('|*******************************************************|')); | ||
}; | ||
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('|*******************************************************|')); | ||
console.log(chalk.yellowBright('|*******************************************************|')); | ||
console.log(chalk.yellowBright('| |')); | ||
console.log(chalk.yellowBright('| Witnet random number request returned an error! |')); | ||
console.log(chalk.yellowBright('| |')); | ||
console.log(chalk.yellowBright('|*******************************************************|')); | ||
}; | ||
//# sourceMappingURL=drawAuction.js.map |
@@ -33,3 +33,3 @@ import { ethers } from 'ethers'; | ||
if (!context.underlyingAssetToken.assetRateUsd) { | ||
console.log(chalk.yellow(`Could not get underlying asset USD value to calculate profit with`)); | ||
console.log(chalk.yellowBright(`Could not get underlying asset USD value to calculate profit with`)); | ||
stats.push({ | ||
@@ -57,3 +57,3 @@ pair, | ||
if (!!bestQuote && !bestQuote.success) { | ||
console.log(chalk.yellow('A flash liquidation on this pair would fail right now, try again soon.')); | ||
console.log(chalk.yellowBright('A flash liquidation on this pair would fail right now, try again soon.')); | ||
stats.push({ | ||
@@ -82,3 +82,3 @@ pair, | ||
console.error(chalk.red(e)); | ||
console.log(chalk.yellow('Could not estimate gas costs!')); | ||
console.log(chalk.yellowBright('Could not estimate gas costs!')); | ||
stats.push({ | ||
@@ -104,3 +104,3 @@ pair, | ||
let populatedTx; | ||
console.log(chalk.blue('6. Populating swap transaction ...')); | ||
console.log(chalk.blueBright('6. Populating swap transaction ...')); | ||
printSpacer(); | ||
@@ -143,3 +143,3 @@ populatedTx = await flashLiquidationContract.populateTransaction.flashLiquidate(...Object.values(flashLiquidateParams)); | ||
printAsterisks(); | ||
console.log(chalk.blue(`Liquidation Pair: ${context.tokenIn.symbol}/${context.tokenOut.symbol}`)); | ||
console.log(chalk.blueBright(`Liquidation Pair: ${context.tokenIn.symbol}/${context.tokenOut.symbol}`)); | ||
printSpacer(); | ||
@@ -154,3 +154,3 @@ logTable({ | ||
printAsterisks(); | ||
console.log(chalk.blue('5. Profit/Loss (USD):')); | ||
console.log(chalk.blueBright('5. Profit/Loss (USD):')); | ||
printSpacer(); | ||
@@ -179,3 +179,3 @@ console.log(chalk.blueBright('Gross profit = tokenOut - tokenIn')); | ||
printAsterisks(); | ||
console.log(chalk.blue('4. Current gas costs for transaction:')); | ||
console.log(chalk.blueBright('4. Current gas costs for transaction:')); | ||
const estimatedGasLimit = await flashLiquidationContract.estimateGas.flashLiquidate(...Object.values(flashLiquidateParams)); | ||
@@ -182,0 +182,0 @@ printSpacer(); |
@@ -17,3 +17,3 @@ import { ethers, BigNumber } from 'ethers'; | ||
const error = `tokenOut '${context.tokenOut.symbol}' (CA: ${context.tokenOut.address.toLowerCase()}) not in token allow list`; | ||
console.log(chalk.yellow(error)); | ||
console.log(chalk.yellowBright(error)); | ||
stats.push({ | ||
@@ -29,3 +29,3 @@ pair, | ||
const error = `amountIn is 0`; | ||
console.log(chalk.yellow(error)); | ||
console.log(chalk.yellowBright(error)); | ||
stats.push({ | ||
@@ -41,3 +41,3 @@ pair, | ||
const error = `amountOut is 0`; | ||
console.log(chalk.yellow(error)); | ||
console.log(chalk.yellowBright(error)); | ||
stats.push({ | ||
@@ -53,3 +53,3 @@ pair, | ||
const error = `Could not get tokenOut asset value (in $USD) to calculate profit with.`; | ||
console.log(chalk.yellow(error)); | ||
console.log(chalk.yellowBright(error)); | ||
stats.push({ | ||
@@ -76,3 +76,3 @@ pair, | ||
const error = `Flash swap unavailable at this time.`; | ||
console.log(chalk.yellow(error)); | ||
console.log(chalk.yellowBright(error)); | ||
stats.push({ | ||
@@ -88,3 +88,3 @@ pair, | ||
const error = `Could not estimate gas cost`; | ||
console.log(chalk.yellow(error)); | ||
console.log(chalk.yellowBright(error)); | ||
stats.push({ | ||
@@ -100,3 +100,3 @@ pair, | ||
const error = `Liquidation Pair ${context.tokenIn.symbol}/${context.tokenOut.symbol}: currently not a profitable trade.`; | ||
console.log(chalk.yellow(error)); | ||
console.log(chalk.yellowBright(error)); | ||
stats.push({ | ||
@@ -114,8 +114,8 @@ pair, | ||
const swapRecipient = findRecipient(config); | ||
console.log(chalk.dim('Config - MIN_PROFIT_THRESHOLD_USD:'), chalk.yellow(config.minProfitThresholdUsd)); | ||
console.log(chalk.dim('Config - MIN_PROFIT_THRESHOLD_USD:'), chalk.yellowBright(config.minProfitThresholdUsd)); | ||
if (config.envTokenAllowList?.length > 0) { | ||
console.log(chalk.dim('Config - ENV_TOKEN_ALLOW_LIST:'), chalk.yellow(config.envTokenAllowList)); | ||
console.log(chalk.dim('Config - ENV_TOKEN_ALLOW_LIST:'), chalk.yellowBright(config.envTokenAllowList)); | ||
} | ||
if (config.pairsToLiquidate?.length > 0) { | ||
console.log(chalk.dim('Config - PAIRS_TO_LIQUIDATE:'), chalk.yellow(config.pairsToLiquidate)); | ||
console.log(chalk.dim('Config - PAIRS_TO_LIQUIDATE:'), chalk.yellowBright(config.pairsToLiquidate)); | ||
} | ||
@@ -141,3 +141,3 @@ printSpacer(); | ||
printSpacer(); | ||
console.log(chalk.blue(`Pair Address: ${liquidationPairContract.address}`)); | ||
console.log(chalk.blueBright(`Pair Address: ${liquidationPairContract.address}`)); | ||
printContext(config, context); | ||
@@ -152,7 +152,7 @@ printSpacer(); | ||
} | ||
console.log(chalk.green(`tokenOut is in the allow list! 👍`)); | ||
console.log(chalk.greenBright(`tokenOut is in the allow list! 👍`)); | ||
} | ||
printSpacer(); | ||
printSpacer(); | ||
console.log(chalk.blue(`1. Amounts:`)); | ||
console.log(chalk.blueBright(`1. Amounts:`)); | ||
const { amountOut } = await getAmountOut(liquidationPairContract, context); | ||
@@ -244,3 +244,3 @@ if (amountOut.eq(0)) { | ||
console.error(chalk.red(e)); | ||
console.log(chalk.yellow('Failed getting amount in!')); | ||
console.log(chalk.yellowBright('Failed getting amount in!')); | ||
} | ||
@@ -254,3 +254,3 @@ }; | ||
if (sufficientBalance) { | ||
console.log(chalk.green('Sufficient balance ✔')); | ||
console.log(chalk.greenBright('Sufficient balance ✔')); | ||
} | ||
@@ -329,3 +329,3 @@ else { | ||
let populatedTx; | ||
console.log(chalk.blue('5. Populating swap transaction ...')); | ||
console.log(chalk.blueBright('5. Populating swap transaction ...')); | ||
populatedTx = await liquidationRouterContract.populateTransaction.swapExactAmountOut(...Object.values(swapExactAmountOutParams)); | ||
@@ -341,3 +341,3 @@ const gasLimit = LIQUIDATOR_GAS_LIMIT; | ||
let populatedTx; | ||
console.log(chalk.blue('6. Populating swap transaction ...')); | ||
console.log(chalk.blueBright('6. Populating swap transaction ...')); | ||
const estimatedGasLimit = await uniswapV2WethPairFlashLiquidatorContract.estimateGas.flashSwapExactAmountOut(...Object.values(flashSwapExactAmountOutParams)); | ||
@@ -366,3 +366,3 @@ populatedTx = | ||
else { | ||
console.log(chalk.green('Sufficient allowance ✔')); | ||
console.log(chalk.greenBright('Sufficient allowance ✔')); | ||
} | ||
@@ -404,3 +404,3 @@ } | ||
const printContext = (config, context) => { | ||
console.log(chalk.blue(`Pair Symbol: ${context.tokenIn.symbol}/${context.tokenOut.symbol}`)); | ||
console.log(chalk.blueBright(`Pair Symbol: ${context.tokenIn.symbol}/${context.tokenOut.symbol}`)); | ||
printSpacer(); | ||
@@ -424,3 +424,3 @@ logTable({ | ||
printSpacer(); | ||
console.log(chalk.blue('2. Balance & Allowance')); | ||
console.log(chalk.blueBright('2. Balance & Allowance')); | ||
printSpacer(); | ||
@@ -434,3 +434,3 @@ console.log("Checking relayer 'tokenIn' balance ..."); | ||
printSpacer(); | ||
console.log(chalk.blue('4. Profit/Loss (USD):')); | ||
console.log(chalk.blueBright('4. Profit/Loss (USD):')); | ||
printSpacer(); | ||
@@ -462,3 +462,3 @@ console.log(chalk.blueBright('Gross profit = tokenOut - tokenIn')); | ||
printSpacer(); | ||
console.log(chalk.blue('3. Profit/Loss (USD):')); | ||
console.log(chalk.blueBright('3. Profit/Loss (USD):')); | ||
printSpacer(); | ||
@@ -485,3 +485,3 @@ const nativeTokenMarketRateUsd = await getNativeTokenMarketRateUsd(chainId, covalentApiKey); | ||
printSpacer(); | ||
console.log(chalk.blue('3. Current gas costs for transaction:')); | ||
console.log(chalk.blueBright('3. Current gas costs for transaction:')); | ||
printSpacer(); | ||
@@ -503,3 +503,3 @@ const estimatedGasLimit = await liquidationRouter.estimateGas.swapExactAmountOut(...Object.values(swapExactAmountOutParams)); | ||
printSpacer(); | ||
console.log(chalk.blue('2. Current gas costs for transaction:')); | ||
console.log(chalk.blueBright('2. Current gas costs for transaction:')); | ||
printSpacer(); | ||
@@ -541,3 +541,3 @@ const estimatedGasLimit = await uniswapV2WethPairFlashLiquidatorContract.estimateGas.flashSwapExactAmountOut(...Object.values(flashSwapExactAmountOutParams)); | ||
if (liquidationPair !== liquidationPairContracts[liquidationPairContracts.length - 1]) { | ||
console.warn(chalk.yellow(`Moving to next pair ...`)); | ||
console.warn(chalk.yellowBright(`Moving to next pair ...`)); | ||
} | ||
@@ -544,0 +544,0 @@ }; |
@@ -41,3 +41,3 @@ import nodeFetch from 'node-fetch'; | ||
const rewardRecipient = findRecipient(config); | ||
console.log(chalk.dim('Config - MIN_PROFIT_THRESHOLD_USD:'), chalk.yellow(minProfitThresholdUsd)); | ||
console.log(chalk.dim('Config - MIN_PROFIT_THRESHOLD_USD:'), chalk.yellowBright(minProfitThresholdUsd)); | ||
const contractsVersion = { | ||
@@ -55,3 +55,3 @@ major: 1, | ||
printAsterisks(); | ||
console.log(chalk.yellow(`Draw is finalized. Cannot claim prizes anymore for finalized draw. Exiting ...`)); | ||
console.log(chalk.yellowBright(`Draw is finalized. Cannot claim prizes anymore for finalized draw. Exiting ...`)); | ||
printSpacer(); | ||
@@ -70,3 +70,4 @@ printDateTimeStr('END'); | ||
printSpacer(); | ||
let claims = await fetchClaims(chainId, prizePoolContract.address, context.drawId, prizeVaults); | ||
const prizeVaultAddresses = prizeVaults.map((prizeVault) => prizeVault.id); | ||
let claims = await fetchClaims(chainId, prizePoolContract.address, context.drawId, prizeVaultAddresses); | ||
claims = await flagClaimedRpc(provider, contracts, claims); | ||
@@ -85,7 +86,3 @@ let unclaimedClaims = claims.filter((claim) => !claim.claimed); | ||
printAsterisks(); | ||
console.log(chalk.yellow(`No prizes left to claim. Exiting ...`)); | ||
printSpacer(); | ||
printDateTimeStr('END'); | ||
printSpacer(); | ||
return; | ||
console.log(chalk.yellowBright(`No prizes left to claim for current draw.`)); | ||
} | ||
@@ -118,3 +115,3 @@ const unclaimedClaimsGrouped = groupBy(unclaimedClaims, (item) => [item.vault, item.tier]); | ||
printSpacer(); | ||
console.log(chalk.blue(`5a. Processing PT Classic vault ...`)); | ||
console.log(chalk.blueBright(`5a. Processing PT Classic vault ...`)); | ||
await processClassicVault(vault, claimerContract, Number(tier), groupedClaims, rewardRecipient, context, config); | ||
@@ -124,3 +121,3 @@ } | ||
printSpacer(); | ||
console.log(chalk.blue(`5a. Calculating # of profitable claims ...`)); | ||
console.log(chalk.blueBright(`5a. Calculating # of profitable claims ...`)); | ||
const claimPrizesParams = await calculateProfit(provider, vault, Number(tier), claimerContract, groupedClaims, tierRemainingPrizeCounts, context, config, rewardRecipient); | ||
@@ -131,3 +128,3 @@ if (claimPrizesParams.winners.length > 0) { | ||
else { | ||
console.log(chalk.yellow(`Not profitable to claim for Draw #${context.drawId}, Tier: #${tierWords(context, Number(tier))}`)); | ||
console.log(chalk.yellowBright(`Not profitable to claim for Draw #${context.drawId}, Tier: #${tierWords(context, Number(tier))}`)); | ||
if (isCanary(context, Number(tier))) { | ||
@@ -139,2 +136,3 @@ canaryTierNotProfitable = true; | ||
} | ||
await sweepPreviousAutoCompoundingPrizes(prizePoolContract.address, rewardRecipient, context, config); | ||
printSpacer(); | ||
@@ -144,2 +142,55 @@ printDateTimeStr('END'); | ||
} | ||
const getLastPrizeWinners = async (prizePoolAddress, context) => { | ||
const claims = await fetchClaims(CHAIN_IDS.base, prizePoolAddress, context.drawId - 1, [ | ||
PT_CLASSIC_PRIZE_VAULT_ADDRESS, | ||
]); | ||
const winners = claims.map((claim) => claim.winner); | ||
return winners.filter(function (v, i) { | ||
return winners.indexOf(v) == i; | ||
}); | ||
}; | ||
const sweepPreviousAutoCompoundingPrizes = async (prizePoolAddress, rewardRecipient, context, config) => { | ||
const { chainId, provider, wallet } = config; | ||
if (chainId !== CHAIN_IDS.base) { | ||
return; | ||
} | ||
printSpacer(); | ||
printSpacer(); | ||
printAsterisks(); | ||
console.log(chalk.blueBright(`Processing compoundAccounts() for previous draw winners:`)); | ||
printSpacer(); | ||
const claimerContract = await getClaimerContract(PT_CLASSIC_PRIZE_VAULT_ADDRESS, provider); | ||
const lastPrizeWinners = await getLastPrizeWinners(prizePoolAddress, context); | ||
debugClaimer('lastPrizeWinners'); | ||
debugClaimer(lastPrizeWinners); | ||
const gasLimit = GAS_LIMIT; | ||
for (let n = 0; n <= lastPrizeWinners.length; n += TOTAL_CLAIM_COUNT_PER_TRANSACTION) { | ||
const start = n; | ||
const end = n + TOTAL_CLAIM_COUNT_PER_TRANSACTION; | ||
let params = { | ||
winners: lastPrizeWinners.slice(start, end), | ||
rewardRecipient, | ||
minReward: BigNumber.from(0), | ||
}; | ||
params.minReward = await getCompoundingRewards(claimerContract, params); | ||
debugClaimer('minReward'); | ||
debugClaimer(params.minReward); | ||
if (params.minReward.gt(0)) { | ||
params.minReward = params.minReward.mul(90).div(100); | ||
printSpacer(); | ||
printSpacer(); | ||
console.log(chalk.greenBright(`Execute 'Compound Accounts' Transaction for PT Classic Prize Vault, winners: ${start + 1} to ${Math.min(end, params.winners.length)} `)); | ||
const populatedTx = await claimerContract.populateTransaction.compoundAccounts(...Object.values(params)); | ||
const tx = await sendPopulatedTx(provider, wallet, populatedTx, gasLimit); | ||
console.log(chalk.greenBright.bold('Transaction sent! ✔')); | ||
console.log(chalk.blueBright.bold('Transaction hash:', tx.hash)); | ||
console.log(chalk.dim('Waiting on transaction to be confirmed ...')); | ||
await provider.waitForTransaction(tx.hash); | ||
console.log(chalk.dim('Transaction confirmed !')); | ||
} | ||
else { | ||
console.log(chalk.yellowBright.bold('Skipping transaction as rewards from simulation are 0')); | ||
} | ||
} | ||
}; | ||
const sendClaimTransaction = async (claimerContract, params, gasLimit, config) => { | ||
@@ -170,3 +221,3 @@ const { provider, wallet } = config; | ||
printSpacer(); | ||
console.log(chalk.green(`Execute Claim Transaction for Tier #${tierWords(context, tier)}, claims ${start + 1} to ${Math.min(end, claimPrizesParams.winners.length)} `)); | ||
console.log(chalk.greenBright(`Execute 'Claim Prizes' Transaction for Tier #${tierWords(context, tier)}, claims ${start + 1} to ${Math.min(end, claimPrizesParams.winners.length)} `)); | ||
const rewards = await getRewards(claimerContract, paramsClone); | ||
@@ -228,7 +279,7 @@ if (rewards.gt(0)) { | ||
printSpacer(); | ||
console.log(chalk.green(`Execute Claim Transaction for Tier #${tierWords(context, tier)}, claims ${start + 1} to ${Math.min(end, paramsClone.winners.length)} `)); | ||
console.log(chalk.greenBright(`Execute 'Claim Prizes' Transaction for Tier #${tierWords(context, tier)}, claims ${start + 1} to ${Math.min(end, paramsClone.winners.length)} `)); | ||
await sendClaimTransaction(claimerContract, paramsClone, gasLimit, config); | ||
} | ||
else { | ||
console.log(chalk.yellow(`Claiming tier #${tierWords(context, tier)} currently not profitable.`)); | ||
console.log(chalk.yellowBright(`Claiming tier #${tierWords(context, tier)} currently not profitable.`)); | ||
} | ||
@@ -252,2 +303,13 @@ } | ||
}; | ||
const getCompoundingRewards = async (claimerContract, params) => { | ||
let rewards = BigNumber.from(0); | ||
try { | ||
rewards = await claimerContract.callStatic.compoundAccounts(...Object.values(params)); | ||
} | ||
catch (e) { | ||
console.log('Error while checking rewards for compounding previous account prizes returned via callStatic simulation'); | ||
console.log(e.message); | ||
} | ||
return rewards; | ||
}; | ||
const isCanary = (context, tier) => { | ||
@@ -287,6 +349,6 @@ const tiersLength = context.tiers.tiersRangeArray.length; | ||
printSpacer(); | ||
console.log(chalk.yellow(`Submitting transaction(s) to claim ${claimCount} prize(s):`)); | ||
console.log(chalk.yellowBright(`Submitting transaction(s) to claim ${claimCount} prize(s):`)); | ||
} | ||
else { | ||
console.log(chalk.yellow(`Claiming tier #${tierWords(context, tier)} currently not profitable.`)); | ||
console.log(chalk.yellowBright(`Claiming tier #${tierWords(context, tier)} currently not profitable.`)); | ||
} | ||
@@ -372,3 +434,3 @@ return claimPrizesParams; | ||
if (!estimatedGasLimitForOne || estimatedGasLimitForOne.eq(0)) { | ||
console.error(chalk.yellow('Estimated gas limit is 0 ...')); | ||
console.error(chalk.yellowBright('Estimated gas limit is 0 ...')); | ||
} | ||
@@ -386,3 +448,3 @@ else { | ||
if (!estimatedGasLimitForTwo || estimatedGasLimitForTwo.eq(0)) { | ||
console.error(chalk.yellow('Estimated gas limit is 0 ...')); | ||
console.error(chalk.yellowBright('Estimated gas limit is 0 ...')); | ||
} | ||
@@ -404,5 +466,5 @@ else { | ||
const { avgFeeUsd: gasCostEachFollowingClaimUsd } = await getFeesUsd(chainId, gasCostEachFollowingClaim, nativeTokenMarketRateUsd, provider, populatedTx.data); | ||
console.log(chalk.grey(`Gas Cost: First Claim (USD):`), chalk.yellow(`$${roundTwoDecimalPlaces(gasCostOneClaimUsd)}`), chalk.dim(`$${gasCostOneClaimUsd}`)); | ||
console.log(chalk.grey(`Gas Cost: First Claim (USD):`), chalk.yellowBright(`$${roundTwoDecimalPlaces(gasCostOneClaimUsd)}`), chalk.dim(`$${gasCostOneClaimUsd}`)); | ||
if (claims.length > 1) { | ||
console.log(chalk.grey(`Gas Cost: Each Following Claim (USD):`), chalk.yellow(`$${roundTwoDecimalPlaces(gasCostEachFollowingClaimUsd)}`), chalk.dim(`$${gasCostEachFollowingClaimUsd}`)); | ||
console.log(chalk.grey(`Gas Cost: Each Following Claim (USD):`), chalk.yellowBright(`$${roundTwoDecimalPlaces(gasCostEachFollowingClaimUsd)}`), chalk.dim(`$${gasCostEachFollowingClaimUsd}`)); | ||
} | ||
@@ -424,3 +486,3 @@ return { | ||
printSpacer(); | ||
console.log(chalk.grey(`Gas Cost (USD):`), chalk.yellow(`$${roundTwoDecimalPlaces(gasCostUsd)}`), chalk.dim(`$${gasCostUsd}`)); | ||
console.log(chalk.grey(`Gas Cost (USD):`), chalk.yellowBright(`$${roundTwoDecimalPlaces(gasCostUsd)}`), chalk.dim(`$${gasCostUsd}`)); | ||
return gasCostUsd; | ||
@@ -453,3 +515,3 @@ }; | ||
printSpacer(); | ||
console.log(chalk.green(`Total gas cost: ${numClaims} Claim(s) (USD):`, `$${roundTwoDecimalPlaces(totalCostUsd)}`), chalk.dim(`($${totalCostUsd})`)); | ||
console.log(chalk.greenBright(`Total gas cost: ${numClaims} Claim(s) (USD):`, `$${roundTwoDecimalPlaces(totalCostUsd)}`), chalk.dim(`($${totalCostUsd})`)); | ||
printSpacer(); | ||
@@ -461,3 +523,3 @@ if (claimCount !== 0) { | ||
logBigNumber(`Claim Reward: ${claimCount} Claim(s) (WEI):`, claimReward, context.prizeToken.decimals, context.prizeToken.symbol); | ||
console.log(chalk.green(`Claim Reward: ${claimCount} Claim(s) (USD):`, `$${roundTwoDecimalPlaces(claimRewardUsd)}`), chalk.dim(`($${claimRewardUsd})`)); | ||
console.log(chalk.greenBright(`Claim Reward: ${claimCount} Claim(s) (USD):`, `$${roundTwoDecimalPlaces(claimRewardUsd)}`), chalk.dim(`($${claimRewardUsd})`)); | ||
printSpacer(); | ||
@@ -467,3 +529,3 @@ } | ||
logBigNumber(`Next Claim Reward: ${numClaims} Claim(s) (WEI):`, nextClaimReward, context.prizeToken.decimals, context.prizeToken.symbol); | ||
console.log(chalk.green(`Next Claim Reward: ${numClaims} Claim(s) (USD):`, `$${roundTwoDecimalPlaces(nextClaimRewardUsd)}`), chalk.dim(`($${nextClaimRewardUsd})`)); | ||
console.log(chalk.greenBright(`Next Claim Reward: ${numClaims} Claim(s) (USD):`, `$${roundTwoDecimalPlaces(nextClaimRewardUsd)}`), chalk.dim(`($${nextClaimRewardUsd})`)); | ||
printSpacer(); | ||
@@ -494,6 +556,6 @@ const netProfitUsd = nextClaimRewardUsd - totalCostUsd; | ||
}; | ||
const fetchClaims = async (chainId, prizePoolAddress, drawId, prizeVaults) => { | ||
const fetchClaims = async (chainId, prizePoolAddress, drawId, prizeVaultAddresses) => { | ||
let claims = []; | ||
for (let prizeVault of prizeVaults) { | ||
const winnersUri = getWinnersUri(chainId, prizePoolAddress, drawId, prizeVault.id); | ||
for (let prizeVaultAddress of prizeVaultAddresses) { | ||
const winnersUri = getWinnersUri(chainId, prizePoolAddress, drawId, prizeVaultAddress); | ||
let winners = []; | ||
@@ -504,3 +566,3 @@ try { | ||
printSpacer(); | ||
console.log(chalk.yellow(`Could not find winners for prize vault: ${prizeVault.id} (results not yet computed for new draw with id #${drawId}?)`)); | ||
console.log(chalk.yellowBright(`Could not find winners for prize vault: ${prizeVaultAddress} (results not yet computed for new draw with id #${drawId}?)`)); | ||
console.log(chalk.dim(winnersUri)); | ||
@@ -516,3 +578,3 @@ printSpacer(); | ||
claims.push({ | ||
vault: prizeVault.id, | ||
vault: prizeVaultAddress, | ||
winner: winner.user, | ||
@@ -519,0 +581,0 @@ tier: Number(tier), |
@@ -5,11 +5,11 @@ import chalk from 'chalk'; | ||
const message = `Config - SWAP_RECIPIENT (Liquidator) or REWARD_RECIPIENT (DrawAuction, PrizeClaimer) not provided, setting recipient to relayer address:`; | ||
console.log(chalk.dim(message), chalk.yellow(config.relayerAddress)); | ||
console.log(chalk.dim(message), chalk.yellowBright(config.relayerAddress)); | ||
return config.relayerAddress; | ||
} | ||
else if (config.swapRecipient) { | ||
console.log(chalk.dim(`Config - SWAP_RECIPIENT:`), chalk.yellow(config.swapRecipient)); | ||
console.log(chalk.dim(`Config - SWAP_RECIPIENT:`), chalk.yellowBright(config.swapRecipient)); | ||
return config.swapRecipient; | ||
} | ||
else { | ||
console.log(chalk.dim(`Config - REWARD_RECIPIENT:`), chalk.yellow(config.rewardRecipient)); | ||
console.log(chalk.dim(`Config - REWARD_RECIPIENT:`), chalk.yellowBright(config.rewardRecipient)); | ||
return config.rewardRecipient; | ||
@@ -16,0 +16,0 @@ } |
@@ -109,3 +109,3 @@ import { ethers, BigNumber } from 'ethers'; | ||
if (!inAllowList) { | ||
console.log(chalk.yellow(`token (CA: ${tokenAddress.toLowerCase()}) not in token allow list`)); | ||
console.log(chalk.yellowBright(`token (CA: ${tokenAddress.toLowerCase()}) not in token allow list`)); | ||
} | ||
@@ -112,0 +112,0 @@ return inAllowList; |
@@ -82,3 +82,3 @@ import chalk from 'chalk'; | ||
else { | ||
console.log(chalk.yellow(`Token with symbol ${symbol} address not found for Covalent API price lookup.`)); | ||
console.log(chalk.yellowBright(`Token with symbol ${symbol} address not found for Covalent API price lookup.`)); | ||
} | ||
@@ -109,3 +109,3 @@ } | ||
if (!response.ok) { | ||
console.log(chalk.yellow(`Unable to fetch current USD value from Dexscreener of '${tokenAddress}' token.`)); | ||
console.log(chalk.yellowBright(`Unable to fetch current USD value from Dexscreener of '${tokenAddress}' token.`)); | ||
throw new Error(response.statusText); | ||
@@ -135,3 +135,3 @@ } | ||
printSpacer(); | ||
console.log(chalk.yellow(`Note: No Coingecko token API ID found for symbol: '${symbol}'`)); | ||
console.log(chalk.yellowBright(`Note: No Coingecko token API ID found for symbol: '${symbol}'`)); | ||
printSpacer(); | ||
@@ -144,3 +144,3 @@ return; | ||
if (!response.ok) { | ||
console.log(chalk.yellow(`Unable to fetch current USD value from Coingecko of '${symbol}' token.`)); | ||
console.log(chalk.yellowBright(`Unable to fetch current USD value from Coingecko of '${symbol}' token.`)); | ||
throw new Error(response.statusText); | ||
@@ -175,3 +175,3 @@ } | ||
if (!response.ok) { | ||
console.log(chalk.yellow(`Error while fetching USD value from Covalent of token with CA: '${address}'.`)); | ||
console.log(chalk.yellowBright(`Error while fetching USD value from Covalent of token with CA: '${address}'.`)); | ||
throw new Error(response.statusText); | ||
@@ -199,3 +199,3 @@ } | ||
else { | ||
console.log(chalk.yellow(`Unable to fetch current USD value from Covalent of token: '${tokenAddress}', missing lookup contract address on ETH mainnet.`)); | ||
console.log(chalk.yellowBright(`Unable to fetch current USD value from Covalent of token: '${tokenAddress}', missing lookup contract address on ETH mainnet.`)); | ||
} | ||
@@ -202,0 +202,0 @@ return rateUsd; |
@@ -7,3 +7,3 @@ import chalk from 'chalk'; | ||
console.log(''); | ||
console.log(chalk.blue(`Operating on: ${chainName(chainId)}`)); | ||
console.log(chalk.blueBright(`Operating on: ${chainName(chainId)}`)); | ||
console.log(''); | ||
@@ -10,0 +10,0 @@ const covalentApiKey = process.env.COVALENT_API_KEY; |
@@ -12,3 +12,3 @@ import { ethers } from 'ethers'; | ||
export const logStringValue = (str, val) => { | ||
console.log(chalk.grey(str), chalk.yellow(val)); | ||
console.log(chalk.grey(str), chalk.yellowBright(val)); | ||
}; | ||
@@ -26,3 +26,3 @@ export const logBigNumber = (title, bigNumber, decimals, symbol = null) => { | ||
printSpacer(); | ||
console.log(chalk.blue('******************')); | ||
console.log(chalk.blueBright('******************')); | ||
}; | ||
@@ -29,0 +29,0 @@ export const printSpacer = () => console.log(''); |
{ | ||
"name": "@generationsoftware/pt-v5-autotasks-library", | ||
"version": "1.6.1", | ||
"version": "1.7.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
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
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
737458
11655