From 7740950829fbc9e88321fbb472ce736bc79edfec Mon Sep 17 00:00:00 2001 From: mandalorian-101 Date: Fri, 7 Jan 2022 16:24:14 +0800 Subject: [PATCH 1/3] add Mushrooms Finace job sample for CLI --- src/abi/MushroomsFinanceKp3rJobV2.json | 1047 +++++++++++++++++++ src/mainnet/mushrooms-finance/README.md | 17 + src/mainnet/mushrooms-finance/job.ts | 94 ++ src/mainnet/mushrooms-finance/metadata.json | 3 + 4 files changed, 1161 insertions(+) create mode 100644 src/abi/MushroomsFinanceKp3rJobV2.json create mode 100644 src/mainnet/mushrooms-finance/README.md create mode 100644 src/mainnet/mushrooms-finance/job.ts create mode 100644 src/mainnet/mushrooms-finance/metadata.json diff --git a/src/abi/MushroomsFinanceKp3rJobV2.json b/src/abi/MushroomsFinanceKp3rJobV2.json new file mode 100644 index 0000000..b11003f --- /dev/null +++ b/src/abi/MushroomsFinanceKp3rJobV2.json @@ -0,0 +1,1047 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_keep3r", + "type": "address" + }, + { + "internalType": "address", + "name": "_keep3rHelper", + "type": "address" + }, + { + "internalType": "address", + "name": "_slidingOracle", + "type": "address" + }, + { + "internalType": "address", + "name": "_sushiSlidingOracle", + "type": "address" + }, + { + "internalType": "address", + "name": "_mmController", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_vault", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_requiredEarnBalance", + "type": "uint256" + } + ], + "name": "EarnVaultAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_vault", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_requiredEarnBalance", + "type": "uint256" + } + ], + "name": "EarnVaultModified", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_vault", + "type": "address" + } + ], + "name": "EarnVaultRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_vault", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "_strategy", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_requiredHarvest", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bool", + "name": "_requiredKeepMinRatio", + "type": "bool" + }, + { + "indexed": false, + "internalType": "bool", + "name": "_requiredLeverageToMax", + "type": "bool" + }, + { + "indexed": false, + "internalType": "address", + "name": "yieldToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "yieldTokenOracle", + "type": "uint256" + } + ], + "name": "HarvestStrategyAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_strategy", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_requiredHarvest", + "type": "uint256" + } + ], + "name": "HarvestStrategyModified", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "HarvestStrategyRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_strategy", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "profitTokenAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "profitFactor", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "profitInEther", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "ethCallCost", + "type": "uint256" + } + ], + "name": "HarvestableCheck", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "HarvestedByKeeper", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "keep3rHelper", + "type": "address" + } + ], + "name": "Keep3rHelperSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "keep3r", + "type": "address" + } + ], + "name": "Keep3rSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "slidingOracle", + "type": "address" + } + ], + "name": "SlidingOracleSet", + "type": "event" + }, + { + "inputs": [], + "name": "COMP", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CRV", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CRVRENWBTC", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DAI", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "KP3R", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LINK", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIRUSTLP", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SUSHISWAP_ORACLE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "THREECRV", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "UNISWAP_ORACLE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "USDC", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "WBTC", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "WETH", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ZRX", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_governor", + "type": "address" + } + ], + "name": "_setGovernor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_vault", + "type": "address" + }, + { + "internalType": "address", + "name": "_strategy", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_requiredHarvest", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "_requiredKeepMinRatio", + "type": "bool" + }, + { + "internalType": "bool", + "name": "_requiredLeverageToMax", + "type": "bool" + }, + { + "internalType": "address", + "name": "yieldToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "yieldTokenOracle", + "type": "uint256" + } + ], + "name": "addStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_vault", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_requiredEarnBalance", + "type": "uint256" + } + ], + "name": "addVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_vault", + "type": "address" + } + ], + "name": "earn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_vault", + "type": "address" + } + ], + "name": "earnable", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCollateralizedStrategies", + "outputs": [ + { + "internalType": "address[]", + "name": "_strategies", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getStrategies", + "outputs": [ + { + "internalType": "address[]", + "name": "_strategies", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVaults", + "outputs": [ + { + "internalType": "address[]", + "name": "_vaults", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "governor", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "harvest", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "harvestable", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "keep3r", + "outputs": [ + { + "internalType": "contract IKeep3rV1", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "keep3rHelper", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "keepMinRatio", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "keepMinRatioMayday", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "minHarvestInterval", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "mmController", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "profitFactor", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_vault", + "type": "address" + } + ], + "name": "removeEarnVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "removeHarvestStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "requiredEarnBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "requiredHarvest", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_keep3r", + "type": "address" + } + ], + "name": "setKeep3r", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_keep3rHelper", + "type": "address" + } + ], + "name": "setKeep3rHelper", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_interval", + "type": "uint256" + } + ], + "name": "setMinHarvestInterval", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_profitFactor", + "type": "uint256" + } + ], + "name": "setProfitFactor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_slidingOracle", + "type": "address" + } + ], + "name": "setSlidingOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sushiSlidingOracle", + "type": "address" + } + ], + "name": "setSushiSlidingOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "slidingOracle", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "stratagyYieldTokenOracles", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "stratagyYieldTokens", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "strategyLastHarvest", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "sushiSlidingOracle", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_vault", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_requiredEarnBalance", + "type": "uint256" + } + ], + "name": "updateRequiredEarn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategy", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_requiredHarvest", + "type": "uint256" + } + ], + "name": "updateRequiredHarvestAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategy", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_yieldTokenOracle", + "type": "uint256" + } + ], + "name": "updateYieldTokenOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "vaultStrategies", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] \ No newline at end of file diff --git a/src/mainnet/mushrooms-finance/README.md b/src/mainnet/mushrooms-finance/README.md new file mode 100644 index 0000000..049225d --- /dev/null +++ b/src/mainnet/mushrooms-finance/README.md @@ -0,0 +1,17 @@ +# Mushrooms Finance + +This sample job enable kp3r keepers on Ethereum to execute tasks for Mushrooms yield-farming vaults (`earn`) and underlying strategies (`harvest`) + +## Config path + +`node_modules/@keep3r-network/cli-sample-jobs/dist/mainnet/mushrooms-finance-v2` + +## Keeper Requirements + +* Must be a valid Keeper on Keep3r V1 + +## Useful Links + +* [Job](https://etherscan.io/address/0x0bd1d668d8e83d14252f2e01d5873df77a6511f0) +* [Documentation](https://github.com/keep3r-network/keep3r.network/pull/52) +* [Keep3r V1](https://etherscan.io/address/0x1ceb5cb57c4d4e2b2433641b95dd330a33185a44) \ No newline at end of file diff --git a/src/mainnet/mushrooms-finance/job.ts b/src/mainnet/mushrooms-finance/job.ts new file mode 100644 index 0000000..5090ab4 --- /dev/null +++ b/src/mainnet/mushrooms-finance/job.ts @@ -0,0 +1,94 @@ +import { Job, JobWorkableGroup, makeid, prelog, toKebabCase } from '@keep3r-network/cli-utils'; +import { Contract } from 'ethers'; +import kp3rJobABI from '../../abi/MushroomsFinanceKp3rJobV2.json'; +import metadata from './metadata.json'; + +const jobAddress = '0x0bD1d668d8E83d14252F2e01D5873df77A6511f0'; + +const getWorkableTxs: Job['getWorkableTxs'] = async (args) => { + const correlationId = toKebabCase(metadata.name); + const logMetadata = {job: metadata.name, block: args.advancedBlock, logId: makeid(5),}; + const logConsole = prelog(logMetadata); + + if(args.skipIds.includes(correlationId)) { + logConsole.log(`Job in progress, avoid running`); + return args.subject.complete(); + } + + logConsole.log(`Trying to work`); + + const job = new Contract(jobAddress, kp3rJobABI, args.fork.ethersProvider); + + try { + + const workableGroups: JobWorkableGroup[] = []; + const harvestableStrategies = []; + const earnableVaults = []; + + ///////////////////////////////////////////////////////////////////////// + // find workable harvest() + ///////////////////////////////////////////////////////////////////////// + job.getStrategies().then((result) => { + for (i = 0; i < result.length; i++) { + let workable = await job.callStatic.harvestable(result[i], {blockTag: args.advancedBlock,}); + logConsole.lo('harvestable() check for ' + result[i] + '=' + workable); + if(workable == 'true'){ + harvestableStrategies.push(result[i]); + } + } + }).catch(err: any){ + logConsole.warn('checking harvestable() but failed', {message: err.message,}); + return args.subject.complete(); + } + + ///////////////////////////////////////////////////////////////////////// + // find workable earn() + ///////////////////////////////////////////////////////////////////////// + job.getVaults().then((result) => { + for (i = 0; i < result.length; i++) { + let workable = await job.earnable(result[i], {blockTag: args.advancedBlock,}); + logConsole.lo('earnable() check for ' + result[i] + '=' + workable); + if(workable == 'true'){ + earnableVaults.push(result[i]); + } + } + }).catch(err: any){ + logConsole.warn('checking earnable() but failed', {message: err.message,}); + return args.subject.complete(); + } + + ///////////////////////////////////////////////////////////////////////// + // populate workable transactions + ///////////////////////////////////////////////////////////////////////// + if(harvestableStrategies.length > 0 || earnableVaults.length > 0){ + let workableTxs = []; + let gas_limit = 2_500_000; + let tx_type = 2; + + for(let i = 0; i < harvestableStrategies.length; i++){ + const tx = await job.connect(args.keeperAddress).populateTransaction.harvest(harvestableStrategies[i], {nonce: (args.keeperNonce + i), gasLimit: gas_limit, type: tx_type,}); + workableTxs.push(tx); + } + for(let i = 0; i < earnableVaults.length; i++){ + const tx = await job.connect(args.keeperAddress).populateTransaction.earn(earnableVaults[i], {nonce: (args.keeperNonce + workableTxs.length + i), gasLimit: gas_limit, type: tx_type,}); + workableTxs.push(tx); + } + + for (let index = 0; index < args.bundleBurst; index++) { + workableGroups.push({targetBlock: args.targetBlock + index, txs: workableTxs, logId: `${logMetadata.logId}-${makeid(5)}`,}); + } + } + + if (!workableGroups.length) return args.subject.complete(); + args.subject.next({workableGroups, correlationId,}); + + } catch (err: any) { + logConsole.warn('Unexpected error', { message: err.message }); + } + + args.subject.complete(); +}; + +module.exports = { + getWorkableTxs, +} as Job; diff --git a/src/mainnet/mushrooms-finance/metadata.json b/src/mainnet/mushrooms-finance/metadata.json new file mode 100644 index 0000000..868d63d --- /dev/null +++ b/src/mainnet/mushrooms-finance/metadata.json @@ -0,0 +1,3 @@ +{ + "name": "MushroomsFinance" +} From 038cbe31a9c314d986490aca078829f199735a03 Mon Sep 17 00:00:00 2001 From: mushroomsforest <72915034+mushroomsforest@users.noreply.github.com> Date: Sun, 9 Jan 2022 13:05:27 +0800 Subject: [PATCH 2/3] fix typos and format --- src/mainnet/mushrooms-finance/job.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mainnet/mushrooms-finance/job.ts b/src/mainnet/mushrooms-finance/job.ts index 5090ab4..f1bdb37 100644 --- a/src/mainnet/mushrooms-finance/job.ts +++ b/src/mainnet/mushrooms-finance/job.ts @@ -31,7 +31,7 @@ const getWorkableTxs: Job['getWorkableTxs'] = async (args) => { job.getStrategies().then((result) => { for (i = 0; i < result.length; i++) { let workable = await job.callStatic.harvestable(result[i], {blockTag: args.advancedBlock,}); - logConsole.lo('harvestable() check for ' + result[i] + '=' + workable); + logConsole.log('harvestable() check for ' + result[i] + '=' + workable); if(workable == 'true'){ harvestableStrategies.push(result[i]); } @@ -47,7 +47,7 @@ const getWorkableTxs: Job['getWorkableTxs'] = async (args) => { job.getVaults().then((result) => { for (i = 0; i < result.length; i++) { let workable = await job.earnable(result[i], {blockTag: args.advancedBlock,}); - logConsole.lo('earnable() check for ' + result[i] + '=' + workable); + logConsole.log('earnable() check for ' + result[i] + '=' + workable); if(workable == 'true'){ earnableVaults.push(result[i]); } @@ -68,7 +68,7 @@ const getWorkableTxs: Job['getWorkableTxs'] = async (args) => { for(let i = 0; i < harvestableStrategies.length; i++){ const tx = await job.connect(args.keeperAddress).populateTransaction.harvest(harvestableStrategies[i], {nonce: (args.keeperNonce + i), gasLimit: gas_limit, type: tx_type,}); workableTxs.push(tx); - } + } for(let i = 0; i < earnableVaults.length; i++){ const tx = await job.connect(args.keeperAddress).populateTransaction.earn(earnableVaults[i], {nonce: (args.keeperNonce + workableTxs.length + i), gasLimit: gas_limit, type: tx_type,}); workableTxs.push(tx); From c2f1f07e1d95f979d07e8540ffa1e484f8319509 Mon Sep 17 00:00:00 2001 From: mandalorian-101 Date: Tue, 11 Jan 2022 11:20:22 +0800 Subject: [PATCH 3/3] fix async read --- src/mainnet/mushrooms-finance/job.ts | 37 +++++++++++----------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/mainnet/mushrooms-finance/job.ts b/src/mainnet/mushrooms-finance/job.ts index 5090ab4..13946d6 100644 --- a/src/mainnet/mushrooms-finance/job.ts +++ b/src/mainnet/mushrooms-finance/job.ts @@ -28,33 +28,25 @@ const getWorkableTxs: Job['getWorkableTxs'] = async (args) => { ///////////////////////////////////////////////////////////////////////// // find workable harvest() ///////////////////////////////////////////////////////////////////////// - job.getStrategies().then((result) => { - for (i = 0; i < result.length; i++) { - let workable = await job.callStatic.harvestable(result[i], {blockTag: args.advancedBlock,}); - logConsole.lo('harvestable() check for ' + result[i] + '=' + workable); - if(workable == 'true'){ - harvestableStrategies.push(result[i]); - } + let getStrategiesResult = await job.getStrategies(); + for (i = 0; i < getStrategiesResult.length; i++) { + let workable = await job.callStatic.harvestable(getStrategiesResult[i], {blockTag: args.advancedBlock,}); + logConsole.log('harvestable() check for ' + getStrategiesResult[i] + '=' + workable); + if (workable == 'true'){ + harvestableStrategies.push(result[i]); } - }).catch(err: any){ - logConsole.warn('checking harvestable() but failed', {message: err.message,}); - return args.subject.complete(); } ///////////////////////////////////////////////////////////////////////// // find workable earn() ///////////////////////////////////////////////////////////////////////// - job.getVaults().then((result) => { - for (i = 0; i < result.length; i++) { - let workable = await job.earnable(result[i], {blockTag: args.advancedBlock,}); - logConsole.lo('earnable() check for ' + result[i] + '=' + workable); - if(workable == 'true'){ - earnableVaults.push(result[i]); - } + let getVaultsResult = await job.getVaults(); + for (i = 0; i < getVaultsResult.length; i++) { + let workable = await job.earnable(getVaultsResult[i], {blockTag: args.advancedBlock,}); + logConsole.log('earnable() check for ' + result[i] + '=' + workable); + if (workable == 'true'){ + earnableVaults.push(result[i]); } - }).catch(err: any){ - logConsole.warn('checking earnable() but failed', {message: err.message,}); - return args.subject.complete(); } ///////////////////////////////////////////////////////////////////////// @@ -63,14 +55,15 @@ const getWorkableTxs: Job['getWorkableTxs'] = async (args) => { if(harvestableStrategies.length > 0 || earnableVaults.length > 0){ let workableTxs = []; let gas_limit = 2_500_000; + let earn_gas_limit = 1_500_000; let tx_type = 2; for(let i = 0; i < harvestableStrategies.length; i++){ const tx = await job.connect(args.keeperAddress).populateTransaction.harvest(harvestableStrategies[i], {nonce: (args.keeperNonce + i), gasLimit: gas_limit, type: tx_type,}); workableTxs.push(tx); - } + } for(let i = 0; i < earnableVaults.length; i++){ - const tx = await job.connect(args.keeperAddress).populateTransaction.earn(earnableVaults[i], {nonce: (args.keeperNonce + workableTxs.length + i), gasLimit: gas_limit, type: tx_type,}); + const tx = await job.connect(args.keeperAddress).populateTransaction.earn(earnableVaults[i], {nonce: (args.keeperNonce + workableTxs.length + i), gasLimit: earn_gas_limit, type: tx_type,}); workableTxs.push(tx); }