diff --git a/src/actions/ggavax.ts b/src/actions/ggavax.ts index 62aa092..ceb40d5 100644 --- a/src/actions/ggavax.ts +++ b/src/actions/ggavax.ts @@ -1,6 +1,9 @@ import { Context, Event, TransactionEvent } from "@tenderly/actions"; import { getGgAvaxDepositEvent, getGgAvaxWithdrawEvent } from "./logParsing"; -import { GGAVAX_DEPOSIT_TEMPLATE, GGAVAX_WITHDRAW_TEMPLATE } from "./templates"; +import { + GGAVAX_DEPOSIT_DISPLAY_TEMPLATE, + GGAVAX_WITHDRAW_DISPLAY_TEMPLATE, +} from "./templates"; import { GGAVAXDeposit, GGAVAXWithdraw, GgAvaxInformation } from "./types"; import { jsonRpcProvider } from "./ethers"; import { TOKENGG_AVAX_ADDRESS, TOKEN_GGAVAX_INTERFACE } from "./constants"; @@ -11,13 +14,12 @@ const handleGgAvaxDepositEvent = async ( transactionEvent: TransactionEvent, ggpStakedEvent: GGAVAXDeposit ) => { - const { assets, shares } = ggpStakedEvent; + const { assets } = ggpStakedEvent; const { amountAvailableForStaking } = await getGgAvaxInformation(); await emitter.emit( - GGAVAX_DEPOSIT_TEMPLATE( + GGAVAX_DEPOSIT_DISPLAY_TEMPLATE( transactionEvent, assets, - shares, amountAvailableForStaking ) ); @@ -27,25 +29,25 @@ const handleGgAvaxEvent = async ( transactionEvent: TransactionEvent, ggpWithdrawnEvent: GGAVAXWithdraw ) => { - const { assets, shares } = ggpWithdrawnEvent; + const { assets } = ggpWithdrawnEvent; const { amountAvailableForStaking } = await getGgAvaxInformation(); await emitter.emit( - GGAVAX_WITHDRAW_TEMPLATE( + GGAVAX_WITHDRAW_DISPLAY_TEMPLATE( transactionEvent, assets, - shares, amountAvailableForStaking ) ); }; - const getGgAvaxInformation = async (): Promise => { const amountAvailableForStakingCallResult = jsonRpcProvider .getProvider() .call({ to: TOKENGG_AVAX_ADDRESS, - data: TOKEN_GGAVAX_INTERFACE.encodeFunctionData("amountAvailableForStaking"), + data: TOKEN_GGAVAX_INTERFACE.encodeFunctionData( + "amountAvailableForStaking" + ), }); const stakingTotalAssetsCallResult = jsonRpcProvider.getProvider().call({ to: TOKENGG_AVAX_ADDRESS, diff --git a/src/actions/templates.ts b/src/actions/templates.ts index 4c06793..30a1f96 100644 --- a/src/actions/templates.ts +++ b/src/actions/templates.ts @@ -172,6 +172,15 @@ const avaxAmountField = ( }; }; +const avaxAmountDisplay = ( + amount: BigNumber, + options?: Intl.NumberFormatOptions +): string => + `**${Number(utils.formatUnits(amount, 18)).toLocaleString("en-us", { + minimumFractionDigits: 4, + ...options, + })} AVAX**`; + const ggAvaxAmountField = ( amount: BigNumber, options?: Partial @@ -198,6 +207,11 @@ const liquidStakerField = ( }; }; +const liquidStakerDisplay = (owner: string): string => + `[${getEmojiAddress( + utils.getAddress(owner) + )}](https://snowtrace.io/address/${owner})`; + const rewardsCycleStartTimeField = ( time: BigNumber, options?: Partial @@ -685,6 +699,41 @@ export const GGAVAX_DEPOSIT_TEMPLATE = ( }; }; +export const GGAVAX_DEPOSIT_DISPLAY_TEMPLATE = ( + transactionEvent: TransactionEvent, + assets: BigNumber, + amountAvailableForStaking: BigNumber +) => { + const title = `⬆️ ${avaxAmountDisplay( + assets + )} Added to the Liquid Staking Pool (${avaxAmountDisplay( + amountAvailableForStaking, + { + minimumFractionDigits: 0, + } + )})`; + const spacer = " ".repeat(99 - title.length); + return { + components: [ + new ActionRowBuilder().addComponents( + liquidStakerComponent(transactionEvent.from), + transactionComponent(transactionEvent.hash) + ), + ], + embeds: [ + new EmbedBuilder() + .setDescription( + `${title} ${spacer}\n\n[⛓️ transaction](https://snowtrace.io/tx/${ + transactionEvent.transactionHash + }) [📄 liquid staking](https://docs.gogopool.com/design/how-liquid-staking-works) ${liquidStakerDisplay( + transactionEvent.from + )}` + ) + .setColor(0x8aa0d1), + ], + }; +}; + export const GGAVAX_WITHDRAW_TEMPLATE = ( transactionEvent: TransactionEvent, assets: BigNumber, @@ -718,6 +767,41 @@ export const GGAVAX_WITHDRAW_TEMPLATE = ( }; }; +export const GGAVAX_WITHDRAW_DISPLAY_TEMPLATE = ( + transactionEvent: TransactionEvent, + assets: BigNumber, + amountAvailableForStaking: BigNumber +) => { + const title = `⬇️ ${avaxAmountDisplay( + assets + )} Drained from Liquid Staking Pool (${avaxAmountDisplay( + amountAvailableForStaking, + { + minimumFractionDigits: 0, + } + )})`; + const spacer = " ".repeat(97 - title.length); + return { + components: [ + new ActionRowBuilder().addComponents( + liquidStakerComponent(transactionEvent.from), + transactionComponent(transactionEvent.hash) + ), + ], + embeds: [ + new EmbedBuilder() + .setDescription( + `${title} ${spacer}\n\n[⛓️ transaction](https://snowtrace.io/tx/${ + transactionEvent.transactionHash + }) [📄 liquid staking](https://docs.gogopool.com/design/how-liquid-staking-works) ${liquidStakerDisplay( + transactionEvent.from + )}` + ) + .setColor(0x4363aa), + ], + }; +}; + export const REWARDS_NEW_CYCLE_TEMPLATE = ({ rewardsCycleStartTime, rewardsEligibilityTime,