Skip to content

Commit

Permalink
feat: make testnet/mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaskar-1F64F committed Aug 6, 2024
1 parent 833287a commit 34aea42
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
4 changes: 0 additions & 4 deletions src/actions/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ export const getEmojiAddress = (address: string) => {
return `${hashEmoji(address)} ${address.slice(0, 6)}...${address.slice(-4)}`
}

export const getAddressLink = (address: string) => {
return `https://snowscan.xyz/address/${address}`
}

export const getEmojiNodeId = (address: string) => {
const emoji = hashEmoji(address);
const nodeId = nodeHexToID(address);
Expand Down
5 changes: 4 additions & 1 deletion src/actions/minipoolLaunch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const HARDWARE_PROVIDERS: Record<string, string> = {
"0x0000000000000000000000000000000000000000000000000000000000000000": "Manual",
}
const handleMinipoolLaunchedEvent = async (
context: Context,
transactionEvent: TransactionEvent,
minipoolLaunchedEvent: MinipoolLaunched
) => {
Expand All @@ -18,7 +19,9 @@ const handleMinipoolLaunchedEvent = async (
if(!hardwareProviderName || hardwareProviderName == "Manual") {
return console.log("Minipool launch ignored with hardware provider: ", hardwareProviderName, hardwareProvider);
}
const network = context.metadata.getNetwork()
const slackMessage = await SLACK_MINIPOOL_LAUNCHED_TEMPLATE({
network,
transactionHash: transactionEvent.hash,
nodeID: nodeHexToID(nodeID),
hardwareProviderName,
Expand All @@ -41,7 +44,7 @@ export const minipoolLaunched = async (context: Context, event: Event) => {

const minipoolLaunchedEvent = await getMinipoolLaunchedEvent(transactionEvent);
if (minipoolLaunchedEvent) {
await handleMinipoolLaunchedEvent(transactionEvent, minipoolLaunchedEvent);
await handleMinipoolLaunchedEvent(context,transactionEvent, minipoolLaunchedEvent);
} else {
throw new Error("No Withdraw or Deposit event found");
}
Expand Down
64 changes: 35 additions & 29 deletions src/actions/templates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TransactionEvent } from "@tenderly/actions";
import { Network, TransactionEvent } from "@tenderly/actions";
// import { formatDistance } from "date-fns";
import {
APIEmbedField,
Expand All @@ -8,39 +8,39 @@ import {
EmbedBuilder,
} from "discord.js";
import { BigNumber, utils } from "ethers";
import { getOrdinalDisplay, nodeHexToID } from "./utils";
import { getAvascanUrl, getExplorerUrl, getOrdinalDisplay, nodeHexToID } from "./utils";
import { RewardsInformation, XGGPDeposit } from "./types";
import { getEmojiAddress, getEmojiNodeId } from "./addresses";

const pilotComponent = (owner: string) => {
return new ButtonBuilder()
.setEmoji("🧑‍✈️")
.setLabel("Pilot")
.setURL(`https://snowscan.xyz/address/${owner}`)
.setURL(getExplorerUrl({address: owner}))
.setStyle(ButtonStyle.Link);
};

const balloonComponent = (nodeId: string) => {
return new ButtonBuilder()
.setEmoji("🎈")
.setLabel("Balloon")
.setURL(`https://avascan.info/staking/validator/${nodeHexToID(nodeId)}`)
.setURL(getAvascanUrl({nodeID: nodeHexToID(nodeId)}))
.setStyle(ButtonStyle.Link);
};

const liquidStakerComponent = (owner: string) => {
return new ButtonBuilder()
.setEmoji("🌊")
.setLabel("Liquid Staker")
.setURL(`https://snowscan.xyz/address/${owner}`)
.setURL(getExplorerUrl({ address: owner}))
.setStyle(ButtonStyle.Link);
};

const transactionComponent = (hash: string) => {
return new ButtonBuilder()
.setEmoji("📝")
.setLabel("Transaction")
.setURL(`https://snowscan.xyz/tx/${hash}`)
.setURL(getExplorerUrl({hash}))
.setStyle(ButtonStyle.Link);
};

Expand Down Expand Up @@ -209,7 +209,7 @@ const liquidStakerField = (
const liquidStakerDisplay = (owner: string): string =>
`[${getEmojiAddress(
utils.getAddress(owner)
)}](https://snowscan.xyz/address/${owner})`;
)}](${getExplorerUrl({address: owner})})`;

const rewardsCycleStartTimeField = (
time: BigNumber,
Expand Down Expand Up @@ -719,9 +719,7 @@ export const GGAVAX_DEPOSIT_DISPLAY_TEMPLATE = (
embeds: [
new EmbedBuilder()
.setDescription(
`${title}\n\n[⛓️ transaction](https://snowscan.xyz/tx/${
transactionEvent.hash
}) [📄 liquid staking](https://docs.gogopool.com/liquid-staking/how-liquid-staking-works) ${liquidStakerDisplay(
`${title}\n\n[⛓️ transaction](${getExplorerUrl({hash: transactionEvent.hash})}) [📄 liquid staking](https://docs.gogopool.com/liquid-staking/how-liquid-staking-works) ${liquidStakerDisplay(
transactionEvent.from
)}`
)
Expand Down Expand Up @@ -781,9 +779,7 @@ export const GGAVAX_WITHDRAW_DISPLAY_TEMPLATE = (
embeds: [
new EmbedBuilder()
.setDescription(
`${title}\n\n[⛓️ transaction](https://snowscan.xyz/tx/${
transactionEvent.hash
}) [📄 liquid staking](https://docs.gogopool.com/liquid-staking/how-liquid-staking-works) ${liquidStakerDisplay(
`${title}\n\n[⛓️ transaction](${getExplorerUrl({hash: transactionEvent.hash})}) [📄 liquid staking](https://docs.gogopool.com/liquid-staking/how-liquid-staking-works) ${liquidStakerDisplay(
transactionEvent.from
)}`
)
Expand All @@ -804,9 +800,7 @@ export const XGGP_DEPOSIT_DISPLAY_TEMPLATE = (
embeds: [
new EmbedBuilder()
.setDescription(
`${title}\n\n[⛓️ transaction](https://snowscan.xyz/tx/${
transactionEvent.hash
}) [📄 vault deposit](https://docs.seafi.app/overview/depositors) ${liquidStakerDisplay(
`${title}\n\n[⛓️ transaction](${getExplorerUrl({hash: transactionEvent.hash})}) [📄 vault deposit](https://docs.seafi.app/overview/depositors) ${liquidStakerDisplay(
transactionEvent.from
)}`
)
Expand All @@ -827,9 +821,7 @@ export const XGGP_WITHDRAW_DISPLAY_TEMPLATE = (
embeds: [
new EmbedBuilder()
.setDescription(
`${title}\n\n[⛓️ transaction](https://snowscan.xyz/tx/${
transactionEvent.hash
}) [📄 vault withdraw](https://docs.seafi.app/overview/depositors) ${liquidStakerDisplay(
`${title}\n\n[⛓️ transaction](${getExplorerUrl({hash: transactionEvent.hash})}) [📄 vault withdraw](https://docs.seafi.app/overview/depositors) ${liquidStakerDisplay(
transactionEvent.from
)}`
)
Expand Down Expand Up @@ -1005,6 +997,7 @@ export const REWARDS_ENDING_REMINDER_TEMPLATE = ({
};

export const SLACK_STREAMLINED_MINIPOOL_LAUNCH_TEMPLATE = async ({
network,
transactionHash,
blsKey,
blsSig,
Expand All @@ -1015,6 +1008,7 @@ export const SLACK_STREAMLINED_MINIPOOL_LAUNCH_TEMPLATE = async ({
owner,
hardwareProviderContract,
}: {
network?: Network;
transactionHash: string;
blsKey?: string;
blsSig?: string;
Expand All @@ -1033,7 +1027,7 @@ export const SLACK_STREAMLINED_MINIPOOL_LAUNCH_TEMPLATE = async ({
emoji: true,
text: ":snowman: Transaction",
},
url: `https://snowscan.xyz/tx/${transactionHash}`,
url: getExplorerUrl({network, hash: transactionHash}),
action_id: "transaction-hash-link",
},
{
Expand All @@ -1043,7 +1037,7 @@ export const SLACK_STREAMLINED_MINIPOOL_LAUNCH_TEMPLATE = async ({
emoji: true,
text: ":snowman: Owner",
},
url: `https://snowscan.xyz/address/${owner}`,
url: getExplorerUrl({network, address: owner}),
action_id: "owner-link",
},
{
Expand All @@ -1053,7 +1047,7 @@ export const SLACK_STREAMLINED_MINIPOOL_LAUNCH_TEMPLATE = async ({
emoji: true,
text: ":closed_umbrella: Validator",
},
url: `https://avascan.info/staking/validator/${nodeID}`,
url: getAvascanUrl({network, nodeID}),
action_id: "node-id-link",
},
];
Expand Down Expand Up @@ -1125,27 +1119,33 @@ export const SLACK_STREAMLINED_MINIPOOL_LAUNCH_TEMPLATE = async ({
};

export const SLACK_HARDWARE_RENTED_TEMPLATE = async ({
network,
transactionHash,
user,
nodeID,
duration,
payment,
}: {
network?: Network;
transactionHash: string;
user: string;
nodeID: string;
hardwareProviderName: string;
duration: string;
payment: string;
}) => {
const headerText =
network === Network.MAINNET
? ":computer: Hardware Rented"
: ":female-construction-worker::computer: Hardware Rented (Testnet)";
const displayDuration = Math.floor(parseInt(duration) / 86400);
return {
blocks: [
{
type: "header",
text: {
type: "plain_text",
text: ":computer: Hardware Rented",
text: headerText,
emoji: true,
},
},
Expand Down Expand Up @@ -1176,7 +1176,7 @@ export const SLACK_HARDWARE_RENTED_TEMPLATE = async ({
emoji: true,
text: ":snowman: Transaction",
},
url: `https://testnet.snowtrace.io/tx/${transactionHash}`,
url: getExplorerUrl({network, hash: transactionHash}),
action_id: "transaction-hash-link",
},
{
Expand All @@ -1186,7 +1186,7 @@ export const SLACK_HARDWARE_RENTED_TEMPLATE = async ({
emoji: true,
text: ":bust_in_silhouette: User",
},
url: `https://testnet.snowtrace.io/address/${user}`,
url: getExplorerUrl({network, address: user}),
action_id: "user-link",
},
],
Expand All @@ -1210,22 +1210,28 @@ export const SLACK_HARDWARE_RENTED_TEMPLATE = async ({
};

export const SLACK_MINIPOOL_LAUNCHED_TEMPLATE = async ({
network,
transactionHash,
nodeID,
owner,
}: {
network?: Network;
owner: string;
transactionHash: string;
nodeID: string;
hardwareProviderName: string;
}) => {
const headerText =
network === Network.MAINNET
? ":rocket: Minipool Launched"
: ":female-construction-worker: :rocket: Minipool Launched (Testnet)";
return {
blocks: [
{
type: "header",
text: {
type: "plain_text",
text: ":rocket: Minipool Launched",
text: headerText,
emoji: true,
},
},
Expand All @@ -1239,7 +1245,7 @@ export const SLACK_MINIPOOL_LAUNCHED_TEMPLATE = async ({
emoji: true,
text: ":snowman: Transaction",
},
url: `https://testnet.snowscan.io/tx/${transactionHash}`,
url: getExplorerUrl({network, hash: transactionHash}),
action_id: "transaction-hash-link",
},
{
Expand All @@ -1249,7 +1255,7 @@ export const SLACK_MINIPOOL_LAUNCHED_TEMPLATE = async ({
emoji: true,
text: ":bust_in_silhouette: Owner",
},
url: `https://testnet.snowscan.io/address/${owner}`,
url: getExplorerUrl({network, address: owner}),
action_id: "owner-link",
},
{
Expand All @@ -1259,7 +1265,7 @@ export const SLACK_MINIPOOL_LAUNCHED_TEMPLATE = async ({
emoji: true,
text: ":closed_umbrella: Validator",
},
url: `https://testnet.avascan.info/staking/validator/${nodeID}`,
url: getAvascanUrl({network, nodeID}),
action_id: "node-id-link",
},
],
Expand Down
15 changes: 14 additions & 1 deletion src/actions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ import { webhookClient } from "./webhook";

const bintools = BinTools.getInstance();

// Take 0xF29Bce5F34a74301eB0dE716d5194E4a4aEA5d7A and return NodeID-P7oB2McjBGgW2NXXWVYjV8JEDFoW9xDE5
export const getExplorerUrl = ({network, hash, address}: {network?: Network, hash?: string, address?: string}) => {
const baseUrl = network === Network.FUJI ? "https://testnet.snowtrace.io" : "https://snowtrace.io";
if (address) {
return `${baseUrl}/address/${address}`;
}
return `${baseUrl}/tx/${hash}`;
};

export const getAvascanUrl = ({network, nodeID}: {network?: Network, nodeID: string}) => {
const baseUrl = network === Network.FUJI ? "https://testnet.avascan.info" : "https://avascan.info";
return `${baseUrl}/staking/validator/${nodeID}`;
};

// Take 0xF29Bce5F34a74301eB0dE716d5194E4a4EA5d7A and return NodeID-P7oB2McjBGgW2NXXWVYjV8JEDFoW9xDE5
const nodeIDToHex = (pk: string) => {
if (!pk.startsWith("NodeID-")) {
throw new Error("Error: nodeID must start with 'NodeID-'");
Expand Down

0 comments on commit 34aea42

Please sign in to comment.