From 0050f7adae7e0040835c211b768c53fc4cb60798 Mon Sep 17 00:00:00 2001 From: kevincheng96 Date: Wed, 19 Jul 2023 15:07:25 -0700 Subject: [PATCH] Fix liquidition bot scenarios --- .../1689168483_add_maticx_collateral.ts | 2 +- scenario/LiquidationBotScenario.ts | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/deployments/polygon/usdc/migrations/1689168483_add_maticx_collateral.ts b/deployments/polygon/usdc/migrations/1689168483_add_maticx_collateral.ts index 4605bd976..dafdcb96b 100644 --- a/deployments/polygon/usdc/migrations/1689168483_add_maticx_collateral.ts +++ b/deployments/polygon/usdc/migrations/1689168483_add_maticx_collateral.ts @@ -101,7 +101,7 @@ export default migration("1689168483_add_maticx_collateral", { async verify(deploymentManager: DeploymentManager) { const { comet, configurator } = await deploymentManager.getContracts(); - const maticxAssetIndex = 3; // TODO + const maticxAssetIndex = Number(await comet.numAssets()) - 1; const maticxAssetConfig = { asset: MATICX_ADDRESS, diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index 679001409..66e27c603 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -1,4 +1,4 @@ -import { scenario } from './context/CometContext'; +import { CometContext, scenario } from './context/CometContext'; import { expect } from 'chai'; import { isValidAssetIndex, matchesDeployment, MAX_ASSETS, timeUntilUnderwater } from './utils'; import { ethers, event, exp, wait } from '../test/helpers'; @@ -68,6 +68,26 @@ async function borrowCapacityForAsset(comet: CometInterface, actor: CometActor, return collateralValue.mul(borrowCollateralFactor).mul(baseScale).div(factorScale).div(priceScale); } +// Filters out assets on networks that cannot be liquidated by the open-source liquidation bot +async function canBeLiquidatedByBot(ctx: CometContext, assetNum: number): Promise { + const unsupportedAssets = { + // Reason: Most liquidity lives in MATICX / MATIC pools, which the liquidation bot cannot use if the base asset is not MATIC + MaticX: { + network: 'polygon', + deployments: ['usdc'] + } + } + const comet = await ctx.getComet(); + const assetInfo = await comet.getAssetInfo(assetNum); + const asset = await ctx.getAssetByAddress(assetInfo.asset); + const symbol = await asset.token.symbol(); + if (symbol in unsupportedAssets) { + if (unsupportedAssets[symbol].network === ctx.world.base.network + && unsupportedAssets[symbol].deployments.includes(ctx.world.base.deployment)) return false; + } + return true; +} + for (let i = 0; i < MAX_ASSETS; i++) { const baseTokenBalances = { mainnet: { @@ -110,6 +130,8 @@ for (let i = 0; i < MAX_ASSETS; i++) { ' == 20', // WMATIC ' == 300000', + // MATICX + ' == 0', ], }, arbitrum: { @@ -131,7 +153,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { upgrade: { targetReserves: exp(20_000, 18) }, - filter: async (ctx) => await isValidAssetIndex(ctx, i) && matchesDeployment(ctx, [{network: 'mainnet'}, {network: 'polygon'}, {network: 'arbitrum'}]), + filter: async (ctx) => await isValidAssetIndex(ctx, i) && matchesDeployment(ctx, [{network: 'mainnet'}, {network: 'polygon'}, {network: 'arbitrum'}]) && canBeLiquidatedByBot(ctx, i), tokenBalances: async (ctx) => ( { $comet: { @@ -281,6 +303,8 @@ for (let i = 0; i < MAX_ASSETS; i++) { ' == 100', // WMATIC ' == 2500000', + // MATICX + ' == 0', ] }, arbitrum: { @@ -325,6 +349,8 @@ for (let i = 0; i < MAX_ASSETS; i++) { exp(20, 8), // WMATIC exp(5000, 18), + // MATICX + exp(5, 18) ] }, arbitrum: { @@ -346,7 +372,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { upgrade: { targetReserves: exp(20_000, 18) }, - filter: async (ctx) => await isValidAssetIndex(ctx, i) && matchesDeployment(ctx, [{network: 'mainnet'}, {network: 'polygon'}, {network: 'arbitrum'}]), + filter: async (ctx) => await isValidAssetIndex(ctx, i) && matchesDeployment(ctx, [{network: 'mainnet'}, {network: 'polygon'}, {network: 'arbitrum'}]) && canBeLiquidatedByBot(ctx, i), tokenBalances: async (ctx) => ( { $comet: {