diff --git a/src/core/engine/engine.ts b/src/core/engine/engine.ts index ea2fee1..619129b 100644 --- a/src/core/engine/engine.ts +++ b/src/core/engine/engine.ts @@ -73,7 +73,7 @@ export class Engine< if (execution === undefined) return // * Pass the need for Execution to the Executors. - this.stream.emit('Execution', execution) + this.stream.emit(execution.key, execution.execution) } ) } diff --git a/src/core/executors/discord.ts b/src/core/executors/discord.ts new file mode 100644 index 0000000..816c5f7 --- /dev/null +++ b/src/core/executors/discord.ts @@ -0,0 +1,36 @@ +import axios from 'axios' + +import { Executor } from '@/core/executor' +import { logger } from '@/lib/logger' + +const key = 'Discord' + +export type DiscordExecution = { + webhookUrl: string + data: { + embeds: Array> + } +} + +export class DiscordExecutor< + TExecution extends DiscordExecution = DiscordExecution +> extends Executor { + constructor() { + super(key) + } + + execute = async ({ webhookUrl, data }: TExecution) => { + axios + .post(webhookUrl, data, { + headers: { 'Content-Type': 'application/json' } + }) + .then(() => { + logger.info(`Discord message sent to ${webhookUrl}`) + }) + .catch(error => { + logger.error( + `Discord message failed to send to ${webhookUrl}: ${error}` + ) + }) + } +} diff --git a/src/index.ts b/src/index.ts index 39d578e..061c543 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,7 @@ export { // ! Executors export { Executor } from '@/core/executor' +export { DiscordExecution, DiscordExecutor } from '@/core/executors/discord' export { FlashbotsExecution, FlashbotsExecutor diff --git a/src/lib/functions/references.ts b/src/lib/functions/references.ts index 233354f..c3eace9 100644 --- a/src/lib/functions/references.ts +++ b/src/lib/functions/references.ts @@ -32,9 +32,13 @@ const generateStaticReferences = async ({ import { ${imports} } from 'ethers' export const ${bigName}_NAME = '${name}' as const - export const ${bigName}_ABI = ${abi} as const ` + if (abi) + protocolGeneration += `\n + export const ${bigName}_ABI = ${abi} as const + ` + if (bytecode) protocolGeneration += `\n export const ${bigName}_BYTECODE = '${bytecode}' as const @@ -47,12 +51,17 @@ const generateStaticReferences = async ({ if (address !== undefined) protocolGeneration += `\n - export const ${bigName}_ADDRESS = '${address}' as const - export const ${bigName}_CONTRACT = new Contract( - '${address}', - ${bigName}_ABI - ) - export const ${bigName}_INTERFACE = ${bigName}_CONTRACT.interface` + export const ${bigName}_ADDRESS = '${address}' as const + ` + + if (address !== undefined && abi !== undefined) + protocolGeneration += `\n + export const ${bigName}_CONTRACT = new Contract( + '${address}', + ${bigName}_ABI + ) + export const ${bigName}_INTERFACE = ${bigName}_CONTRACT.interface + ` if (address === undefined && abi !== undefined) protocolGeneration += `