Skip to content

Commit

Permalink
Fix liquidition bot scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincheng96 committed Jul 19, 2023
1 parent 5bf3eb9 commit 0050f7a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 29 additions & 3 deletions scenario/LiquidationBotScenario.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<boolean> {
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: {
Expand Down Expand Up @@ -110,6 +130,8 @@ for (let i = 0; i < MAX_ASSETS; i++) {
' == 20',
// WMATIC
' == 300000',
// MATICX
' == 0',
],
},
arbitrum: {
Expand All @@ -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: {
Expand Down Expand Up @@ -281,6 +303,8 @@ for (let i = 0; i < MAX_ASSETS; i++) {
' == 100',
// WMATIC
' == 2500000',
// MATICX
' == 0',
]
},
arbitrum: {
Expand Down Expand Up @@ -325,6 +349,8 @@ for (let i = 0; i < MAX_ASSETS; i++) {
exp(20, 8),
// WMATIC
exp(5000, 18),
// MATICX
exp(5, 18)
]
},
arbitrum: {
Expand All @@ -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: {
Expand Down

0 comments on commit 0050f7a

Please sign in to comment.