Skip to content

Commit

Permalink
feat: handle badDebtAssets differently
Browse files Browse the repository at this point in the history
  • Loading branch information
yum0e committed Jul 3, 2024
1 parent 004643d commit cfccee0
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/handlers/morpho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,32 @@ export function handleLiquidate(event: LiquidateEvent): void {

handleMorphoTx(withdrawCollatTx);

// we also need to remove some assets in the supply of the market
// we also need to remove bad debt assets in the supply of the market
// if the bad debt shares are not zero
if (!event.params.badDebtShares.isZero()) {
market.totalSupplyAssets = market.totalSupplyAssets.minus(
event.params.badDebtAssets
const removeBadDebtAssetsId = generateLogId(event).concat(
Bytes.fromUTF8(EventType.SUPPLY)
);

const removeBadDebtAssetsTx = new MorphoTx(removeBadDebtAssetsId);
removeBadDebtAssetsTx.type = EventType.SUPPLY;
removeBadDebtAssetsTx.user = setupUser(event.params.borrower).id;
removeBadDebtAssetsTx.market = market.id;
// we dont need to remove shares, only assets
removeBadDebtAssetsTx.shares = BigInt.zero();
removeBadDebtAssetsTx.assets = event.params.badDebtAssets.neg();

removeBadDebtAssetsTx.timestamp = event.block.timestamp;

removeBadDebtAssetsTx.txHash = event.transaction.hash;
removeBadDebtAssetsTx.txIndex = event.transaction.index;
removeBadDebtAssetsTx.logIndex = event.logIndex;

removeBadDebtAssetsTx.blockNumber = event.block.number;
removeBadDebtAssetsTx.save();

handleMorphoTx(removeBadDebtAssetsTx);
}
market.save();

if (MetaMorpho.load(market.collateralToken) != null) {
handleTransferEntity(
Expand Down

0 comments on commit cfccee0

Please sign in to comment.