From 3d2715589d5b3078118cd415fd33abd16183ccea Mon Sep 17 00:00:00 2001 From: mrq Date: Mon, 25 Nov 2024 08:00:16 +0100 Subject: [PATCH] liquidations --- src/currencies.js | 1 + src/handlers/borrowing.js | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/currencies.js b/src/currencies.js index 194882e..066033b 100644 --- a/src/currencies.js +++ b/src/currencies.js @@ -106,3 +106,4 @@ export const formatUsdValue = value => { const symbol = currencies[usdCurrencyId].symbol || currencies[usdCurrencyId].name || 'USD'; return ` *~ ${new Intl.NumberFormat('en-US', {maximumSignificantDigits: amount < 1 ? 1 : 4, maximumFractionDigits: 2}).format(amount).replace(/,/g, " ")} ${symbol}*`; }; +export const formatAsset = asset => `**${formatAmount(asset)}**${formatUsdValue(usdValue(asset))}`; diff --git a/src/handlers/borrowing.js b/src/handlers/borrowing.js index c46f162..308e108 100644 --- a/src/handlers/borrowing.js +++ b/src/handlers/borrowing.js @@ -1,4 +1,4 @@ -import {formatAccount, formatAmount, formatUsdValue, usdValue} from "../currencies.js"; +import {formatAccount, formatAmount, formatAsset, formatUsdValue, usdValue} from "../currencies.js"; import {broadcast} from "../discord.js"; import poolAbi from "../resources/aave-pool.abi.js"; import ERC20Mapping from "../utils/erc20mapping.js"; @@ -10,32 +10,40 @@ export default function borrowingHandler(events) { .onLog('Withdraw', poolAbi, withdraw) .onLog('Borrow', poolAbi, borrow) .onLog('Repay', poolAbi, repay) + .onLog('LiquidationCall', poolAbi, liquidationCall) } async function supply({log: {args: {reserve, amount, onBehalfOf}}}) { const supplied = {currencyId: ERC20Mapping.decodeEvmAddress(reserve), amount} const account = await toAccount(onBehalfOf); - const message = `${formatAccount(account)} supplied **${formatAmount(supplied)}**${formatUsdValue(usdValue(amount))} to 🏦`; + const message = `${formatAccount(account)} supplied ${formatAsset(supplied)} to 🏦`; broadcast(message); } async function withdraw({log: {args: {reserve, amount, to}}}) { const withdrew = {currencyId: ERC20Mapping.decodeEvmAddress(reserve), amount} const account = await toAccount(to); - const message = `${formatAccount(account)} withdrew **${formatAmount(withdrew)}**${formatUsdValue(usdValue(amount))} from 🏦`; + const message = `${formatAccount(account)} withdrew ${formatAsset(withdrew)} from 🏦`; broadcast(message); } async function borrow({log: {args: {reserve, amount, onBehalfOf}}}) { const borrowed = {currencyId: ERC20Mapping.decodeEvmAddress(reserve), amount} const account = await toAccount(onBehalfOf); - const message = `${formatAccount(account)} borrowed **${formatAmount(borrowed)}**${formatUsdValue(usdValue(amount))} from 🏦`; + const message = `${formatAccount(account)} borrowed ${formatAsset(borrowed)} from 🏦`; broadcast(message); } async function repay({log: {args: {reserve, amount, user}}}) { const repaid = {currencyId: ERC20Mapping.decodeEvmAddress(reserve), amount} const account = await toAccount(user); - const message = `${formatAccount(account)} repaid **${formatAmount(repaid)}**${formatUsdValue(usdValue(amount))} to 🏦`; + const message = `${formatAccount(account)} repaid ${formatAsset(repaid)} to 🏦`; + broadcast(message); +} + +async function liquidationCall({log: {args: {collateralAsset, liquidatedCollateralAmount, user}}}) { + const collateral = {currencyId: ERC20Mapping.decodeEvmAddress(collateralAsset), amount: liquidatedCollateralAmount} + const account = await toAccount(user); + const message = `🏦 liquidated ${formatAsset(collateral)} of ${formatAccount(account)}`; broadcast(message); }