Running Sentinel or similar event listener locally

Right now, we have implemented the handy main.js refactoring to run our Autotask logic locally, and this works very well.

I have a question about running Sentinel locally as well, triggering these Autotasks.

We have a Fullstack local setup running with Docker Compose. Some core operations of our platform involve triggering a Sentinel with a BountyCreated event. This Sentinel then adds some data to a MongoDB instance.

How might I run Sentinel locally? And if I cannot, do you have any other out-of-the-box configurable event listener JS packages? They are hard to find.

The most reliable event-triggered microservice we run is our Graph node, which works great locally. Was hoping there might be some similar service here.

Thanks :cowboy_hat_face:

Hi @flaco_jones ,

Glad to hear you find autotasks helpful!
Have you looked into our defender-sentinel-client package?
It allows you to manage your Sentinels locally.

Let me know if you have any questions, and thanks for the feedback!

Hey @flaco_jones, I understand that what you're looking for is running a Sentinel locally, rather than creating one from your local scripts. If that's the case, what would you expect the local Sentinel to be listening to? A local hardhat network? The actual chain? Or would you want to trigger specific alerts as part of your unit tests, for instance?

I'd like it to be able to respond to events from my local Hardhat Network.

So it's not that I need to manage my remote Sentinels locally - it's that I'd like to have a nifty batteries-included event listener and parser.

So when I mint a new bounty on our locally deployed contracts, my Sentinel/local event listener can run the main.js logic of my ALSO locally running Autotask code :slight_smile:

I think this would be a great offering and encourage OZ Defender use. The myriad event listeners available via npm are unmaintained and in my experience have poor DevEx, so many people are recreating the same polling + parsing work with ethers.js or web3.js.

What this would look like is I have an Express server holding my main.js Autotask logic like so:

// To run locally (this code will not be executed in Autotasks)
// Local Provider + Contract Setup
if (require.main === module) {
	const app = require('./app');
	const PORT = 8070;
	app.listen(PORT);
	console.log(`Open Zeppelin Autotask listening on http://localhost:${PORT}`);
}

Then I would have my local Sentinel listening for emitted Events, doing the heavy lifting of parsing the logs and formatting it into a Sentinel notification like so:

const BountyCreated = {
	request: {
		body: {
			sentinel: {
				id: STAGING_SENTINEL_ID
			},
			matchReasons: [
				{
					params: {
						bountyId: "I_kwDOGWnnz85L2NI_",
						organization: "MDEyOk9yZ2FuaXphdGlvbjc3NDAyNTM4",
						issuerAddress: "0x46e09468616365256F11F4544e65cE0C70ee624b",
						bountyAddress: "0x94e09468616365256F11F4544e65cE0C70ee624b",
						bountyMintTime: 143434343
					},
					signature: "BountyCreated(string,string,address,indexed address,uint256)"
				}
			]
		}
	},
	secrets: {
		GITHUB_BOT_SECRET: process.env.GITHUB_BOT_SECRET,
		OPENQ_API_SECRET: process.env.OPENQ_API_SECRET
	}
};

I would then write some simple logic to POST this to the "Autotask" :wink: running in Express, which will then do exactly what it would do in production with the Sentinel notification.

In our case, that something is making a comment on a GitHub issue AND creating a new off-chain entry for that newly minter bounty in our MongoDB instance.