Agents
Agents execute transactions based on certain conditions. Variables from scenarios can be accessed via the scenarioRet variable and used as shown below.
Example Agent Code:
let cUSDContract = scenarioRet.cUSDContract;
try {
let cUSDC = scenarioRet.cUSDC;
let WBTC = scenarioRet.WBTC;
let WETH = scenarioRet.WETH;
let SUPPLIERS = scenarioRet.SUPPLIERS;
let usdcContract = scenarioRet.usdcContract;
let liquidator = scenarioRet.liquidator;
let oracleContract = scenarioRet.oracleContract;
await usdcContract.connect(liquidator).approve(cUSDC, "1000000000000000000000000");
let liquidatableUsers = [];
for (let i = 0; i < SUPPLIERS.length; i++) {
let isUserLiquidable = await cUSDContract.isLiquidatable(SUPPLIERS[i]);
let isBorrowCollateralized = await cUSDContract.isBorrowCollateralized(SUPPLIERS[i]);
console.log("isUserLiquidable", isUserLiquidable);
if (isUserLiquidable && !isBorrowCollateralized) {
liquidatableUsers.push(SUPPLIERS[i]);
}
let collateralBalanceInBase = await oracleContract.getCollateralAvailableForPurchase();
let quoteWethCollateral = await cUSDContract.quoteCollateral(WETH, collateralBalanceInBase);
let collateralReserve = await cUSDContract.getCollateralReserves(WETH);
await cUSDContract.connect(liquidator).absorb(liquidator.address, liquidatableUsers);
console.log("collateralBalanceInBase", collateralBalanceInBase);
await cUSDContract.connect(liquidator).buyCollateral(WETH, 0, collateralBalanceInBase.toString(), liquidator.address);
}
console.log("AGENT EXECUTION COMPLETED");
} catch (err) {
console.log("error in agent", err);
}
In this code:
We check if users are liquidatable and push them into an array.
At the end, we liquidate them all at once.
Agents do not need to return anything.
Last updated