Skip to content

Commit

Permalink
feat: different workflow keys for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaskar-1F64F committed Aug 15, 2024
1 parent d823356 commit 67606d4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 58 deletions.
28 changes: 15 additions & 13 deletions src/actions/knock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,24 @@ export class KnockClient extends Client {
throw new Error("Knock client not initialized");
} else if (workflowData) {
console.log("Sending message to knock");
await this._knockClient.workflows.trigger(
let workflowKey =
network === Network.FUJI
? "new-oneclick-minipool-fuji"
: "new-oneclick-minipool",
{
recipients: [
{
collection: "webhook-users",
id: "tenderly",
},
],
data: {
...workflowData,
: "new-oneclick-minipool";
if (workflowData.workflowKey) {
workflowKey = workflowData.workflowKey;
}
await this._knockClient.workflows.trigger(workflowKey, {
recipients: [
{
collection: "webhook-users",
id: "tenderly",
},
}
);
],
data: {
...workflowData,
},
});
}
}
}
Expand Down
41 changes: 3 additions & 38 deletions src/actions/minipool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { emitter } from "./emitter";
import MinipoolManager from "./generated/contracts/MinipoolManager";
import { getMatchingEvents } from "./logParsing";
import { getHardwareProviderName } from "./minipoolLaunch";
import {
MINIPOOL_CANCELED_TEMPLATE,
MINIPOOL_ERROR_TEMPLATE,
Expand All @@ -20,15 +19,14 @@ import {
MINIPOOL_RESTAKE_TEMPLATE,
MINIPOOL_STAKING_TEMPLATE,
MINIPOOL_STREAMLINE_TEMPLATE,
MINIPOOL_WITHDRAWABLE_TEMPLATE,
SLACK_UNDERCOLLATERALIZED_TEMPLATE
MINIPOOL_WITHDRAWABLE_TEMPLATE
} from "./templates";
import {
MinipoolStatus,
MinipoolStatusChanged,
NewStreamlinedMinipoolMade,
} from "./types";
import { initServices, nodeHexToID } from "./utils";
import { initServices } from "./utils";

export const getMinipoolDataFromNodeId = async (
nodeID: string,
Expand Down Expand Up @@ -151,7 +149,7 @@ const getMessageFromStatusChangedEvent = async (
}
};

const getMinipoolFromEvent = async (
export const getMinipoolFromEvent = async (
event: TransactionEvent,
network?: Network
) => {
Expand Down Expand Up @@ -272,36 +270,3 @@ export const minipoolStatusChange = async (context: Context, event: Event) => {
await emitter.emit(message, workflowData, webhookData);
console.info("minipoolStatusChange function completed successfully");
};

export const minipoolUndercollateralized = async (
context: Context,
event: Event
) => {
console.info("Starting minipoolUndercollateralized function");
await initServices(context);
const transactionEvent = event as TransactionEvent;
const { minipool } = await getMinipoolFromEvent(
transactionEvent,
context.metadata.getNetwork()
);
const { owner, duration, nodeID, hardwareProvider } = minipool;
const hardwareProviderName = getHardwareProviderName(hardwareProvider);
if(hardwareProviderName === "Artifact"){
throw new Error("not tracked ; undercollateralized");
}
const slackMessage = await SLACK_UNDERCOLLATERALIZED_TEMPLATE({
transactionHash: transactionEvent.hash,
owner,
nodeID: nodeHexToID(nodeID),
});
console.info("Slack message prepared for hardware rented");
const workflowData = {
...slackMessage,
user: owner,
nodeID: nodeHexToID(nodeID),
nodeIDHex: nodeID.toString(),
hardwareProviderName,
duration: duration.toString(),
};
await emitter.emit(undefined, workflowData);
};
37 changes: 37 additions & 0 deletions src/actions/minipoolEjection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Context, Event, TransactionEvent } from "@tenderly/actions";
import { emitter } from "./emitter";
import { getHardwareProviderName } from "./minipoolLaunch";
import { SLACK_UNDERCOLLATERALIZED_TEMPLATE } from "./templates";
import { initServices, nodeHexToID } from "./utils";
import { getMinipoolFromEvent } from "./minipool";

export const undercollateralized = async (context: Context, event: Event) => {
console.info("Starting minipoolUndercollateralized function");
await initServices(context);
const transactionEvent = event as TransactionEvent;
const { minipool } = await getMinipoolFromEvent(
transactionEvent,
context.metadata.getNetwork()
);
const { owner, duration, nodeID, hardwareProvider } = minipool;
const hardwareProviderName = getHardwareProviderName(hardwareProvider);
if (hardwareProviderName === "Artifact") {
throw new Error("not tracked ; undercollateralized");
}
const slackMessage = await SLACK_UNDERCOLLATERALIZED_TEMPLATE({
transactionHash: transactionEvent.hash,
owner,
nodeID: nodeHexToID(nodeID),
});
console.info("Slack message prepared for hardware rented");
const workflowData = {
...slackMessage,
workflowKey: "minipool-ejection",
user: owner,
nodeID: nodeHexToID(nodeID),
nodeIDHex: nodeID.toString(),
hardwareProviderName,
duration: duration.toString(),
};
await emitter.emit(undefined, workflowData);
};
4 changes: 2 additions & 2 deletions src/actions/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ export const SLACK_UNDERCOLLATERALIZED_TEMPLATE = async ({
nodeID: string;
owner: string;
}) => {
const headerText = "⚠️ Minipool Undercollateralized";
const headerText = "⚠️ Minipool Kicked Out";
return {
blocks: [
{
Expand Down Expand Up @@ -1356,7 +1356,7 @@ export const SLACK_UNDERCOLLATERALIZED_TEMPLATE = async ({
type: "section",
text: {
type: "mrkdwn",
text: "This minipool has become undercollateralized and may be at risk of being kicked out of cycling.",
text: "This minipool was undercollateralized at the time of cycling and has been kicked out of the protocol.",
},
},
],
Expand Down
9 changes: 4 additions & 5 deletions tenderly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ actions:
sources: src/actions
specs:
undercollateralizedEjection:
description: Minipool was kicked out of cycling.
function: minipool:undercollateralized
description: When a minipool gets kicked out of cycling for undercollateralization
function: minipoolEjection:undercollateralized
trigger:
type: transaction
transaction:
status:
- mined
filters:
- network: 43114
function:
name: recordStakingEnd
contract:
address: 0xc300Bc9B4b690BA7A182126299a0618eCe268Ee7
status: success
status:
- mined
artifactHardwareProvider:
description: Artifact hardware provider changed.
function: artifact:hardwareRented
Expand Down

0 comments on commit 67606d4

Please sign in to comment.