-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from superfluid-finance/fallback
This PR is the base of Graphinator Refactoring
- Loading branch information
Showing
10 changed files
with
674 additions
and
526 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,88 @@ | ||
#!/usr/bin/env bun | ||
|
||
import dotenv from "dotenv"; | ||
|
||
import yargs from "yargs" | ||
import { hideBin } from "yargs/helpers" | ||
import Graphinator from './src/graphinator'; | ||
|
||
|
||
const log = (msg: string, lineDecorator="") => console.log(`${new Date().toISOString()} - ${lineDecorator} (Graphinator) ${msg}`); | ||
|
||
|
||
dotenv.config(); | ||
|
||
const argv = await yargs(hideBin(process.argv)) | ||
.option('network', { | ||
alias: 'n', | ||
type: 'string', | ||
description: 'Set the network', | ||
default: 'base-mainnet' | ||
demandOption: true, | ||
default: process.env.NETWORK | ||
}) | ||
.option('batchSize', { | ||
alias: 'b', | ||
/* | ||
Note: there's currently no scientific way to determine a safe batch size. | ||
That's because the gas consumed by an individual flow's liquidation can vary widely, | ||
especially if SuperApp callbacks are involved. | ||
The safe and default choice is thus 1. | ||
Most of the time considerably higher values (e.g. 10) will work and may be used. | ||
But since the logic is currently such that a failing batch could stall any progress, | ||
setting this differently should be a conscious choice. | ||
*/ | ||
.option('token', { | ||
alias: 't', | ||
type: 'string', | ||
description: 'Address of the Super Token to process. If not set, all "listed" (curated) Super Tokens will be processed', | ||
default: process.env.TOKEN | ||
}) | ||
.option('maxGasPriceMwei', { | ||
alias: 'm', | ||
type: 'number', | ||
description: 'Set the batch size', | ||
default: 15 | ||
description: 'Set the max gas price in mwei (milli wei). Default: 10000 (10 gwei)', | ||
default: process.env.MAX_GAS_PRICE_MWEI ? parseInt(process.env.MAX_GAS_PRICE_MWEI) : 10000 | ||
}) | ||
.option('gasMultiplier', { | ||
alias: 'g', | ||
type: 'number', | ||
description: 'Set the gas multiplier', | ||
default: 1.2 | ||
description: 'Set the gas multiplier - allows to define the gas limit margin set on top of the estimation', | ||
default: process.env.GAS_MULTIPLIER ? parseFloat(process.env.GAS_MULTIPLIER) : 1.2 | ||
}) | ||
.option('token', { | ||
alias: 't', | ||
type: 'string', | ||
description: 'Set the token to liquidate', | ||
demandOption: true | ||
.option('batchSize', { | ||
alias: 'b', | ||
type: 'number', | ||
description: 'Set the batch size', | ||
default: process.env.BATCH_SIZE ? parseInt(process.env.BATCH_SIZE) : 1 | ||
}) | ||
.option('loop', { | ||
alias: 'l', | ||
type: 'boolean', | ||
description: 'Set to true to loop forever, false to run once', | ||
default: false | ||
}) | ||
.option('maxGasPrice', { | ||
alias: 'm', | ||
type: 'number', | ||
description: 'Set the max gas price', | ||
default: 500000000 | ||
description: 'Set to true to loop forever, false to run once.', | ||
default: process.env.LOOP === 'true' | ||
}) | ||
.parse(); | ||
|
||
const runAgainIn = 15 * 60 * 1000; | ||
const runAgainIn = 30000 //15 * 60 * 1000; | ||
const network = argv.network; | ||
const batchSize = argv.batchSize; | ||
const gasMultiplier = argv.gasMultiplier; | ||
const token = argv.token.toLowerCase(); | ||
const token = argv.token; | ||
const loop = argv.loop; | ||
const maxGasPrice = BigInt(argv.maxGasPrice); | ||
|
||
|
||
const config = { | ||
batchContractAddress: '0x6b008BAc0e5846cB5d9Ca02ca0e801fCbF88B6f9', | ||
gdaForwarderAddress: '0x6DA13Bde224A05a288748d857b9e7DDEffd1dE08', | ||
superTokenAddress: token | ||
} | ||
const maxGasPrice = argv.maxGasPriceMwei * 1000000; | ||
|
||
const ghr = new Graphinator(network, config); | ||
const ghr = new Graphinator(network, batchSize, gasMultiplier, maxGasPrice); | ||
if(loop) { | ||
log("run liquidations forever...", "🤖"); | ||
await ghr.run(batchSize, gasMultiplier, maxGasPrice, BigInt(0)); | ||
setInterval(async () => { | ||
const executeLiquidations = async () => { | ||
try { | ||
await ghr.run(batchSize, gasMultiplier, maxGasPrice, BigInt(0)); | ||
await ghr.processAll(token); | ||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
log(`run again in ${runAgainIn}`); | ||
setTimeout(executeLiquidations, runAgainIn); // Schedule the next run | ||
} | ||
}, runAgainIn); | ||
}; | ||
await executeLiquidations(); | ||
} else { | ||
log("run liquidations once...", "🤖"); | ||
await ghr.run(batchSize, gasMultiplier, maxGasPrice, BigInt(0)); | ||
log(new Date().toISOString() + " - run liquidations..."); | ||
await ghr.processAll(token); | ||
} |
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
Oops, something went wrong.