Skip to content

Commit

Permalink
liquidations
Browse files Browse the repository at this point in the history
  • Loading branch information
mrq1911 committed Nov 26, 2024
1 parent 500f0a4 commit 3d27155
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))}`;
18 changes: 13 additions & 5 deletions src/handlers/borrowing.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
}

0 comments on commit 3d27155

Please sign in to comment.