Skip to content

Commit

Permalink
⬆️⬇️ Smallify
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaskar-1F64F committed Dec 24, 2023
1 parent aa975f9 commit bb3a61d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/actions/ggavax.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
)
);
Expand All @@ -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<GgAvaxInformation> => {
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,
Expand Down
84 changes: 84 additions & 0 deletions src/actions/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<APIEmbedField>
Expand All @@ -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<APIEmbedField>
Expand Down Expand Up @@ -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<ButtonBuilder>().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,
Expand Down Expand Up @@ -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<ButtonBuilder>().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,
Expand Down

0 comments on commit bb3a61d

Please sign in to comment.