Skip to content

Commit e794c08

Browse files
authored
Merge pull request #42 from nautls/start-documentation
Start documentation
2 parents d5d1b74 + 508750f commit e794c08

File tree

3 files changed

+189
-0
lines changed

3 files changed

+189
-0
lines changed

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -1 +1,49 @@
11
# Ergomatic
2+
3+
[![ci](https://github.com/nautls/ergomatic/actions/workflows/ci.yaml/badge.svg)](https://github.com/nautls/ergomatic/actions/workflows/ci.yaml)
4+
[![Discord badge][]][Discord link]
5+
6+
`ergomatic` is a generic off-chain execution framework for bots. Bot
7+
functionality is provided via plugins which are audited by the nautilus team.
8+
9+
## Install
10+
11+
Shell (Mac, Linux):
12+
13+
```sh
14+
curl -fsSL https://raw.githubusercontent.com/nautls/ergomatic/main/scripts/install/install.sh | sh
15+
```
16+
17+
PowerShell (Windows):
18+
19+
```powershell
20+
irm https://raw.githubusercontent.com/nautls/ergomatic/main/scripts/install/install.ps1 | iex
21+
```
22+
23+
### Running
24+
25+
Ergomatic can be ran using the `run` CLI command. The `-c` flag can optionally
26+
be passed to specify the config file path, if not provided it will default to
27+
`$CWD/ergomatic.yaml`.
28+
29+
```sh
30+
ergomatic run
31+
```
32+
33+
Logs can be viewed in your terminal and are also persisted to disk depending on
34+
OS:
35+
36+
- Linux: `$XDG_DATA_HOME/ergomatic`
37+
- macOS: `$HOME/Library/Application Support/ergomatic`
38+
- Windows: `$LOCALAPPDATA/ergomatic`
39+
40+
Log files will automatically be rotated with a maximum of 300mb of logs kept.
41+
42+
## Contributing
43+
44+
We appreciate your help!
45+
46+
To contribute, please read our [contributing instructions](CONTRIBUTING.md).
47+
48+
[Discord badge]: https://img.shields.io/discord/668903786361651200?logo=discord&style=social
49+
[Discord link]: https://discord.gg/ergo-platform-668903786361651200

docs/plugins.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Plugins
2+
3+
## Creating a Plugin
4+
5+
For this exercise lets assume I am creating a plugin for my dapp that requires
6+
off-chain bot functionality, my dapp is called "Degenz".
7+
8+
Firstly decide on a `id` for your plugin, this should be in `snake_case` format,
9+
in my case I will use `degenz`.
10+
11+
The easiest way to get started is to use the provided plugin template:
12+
13+
```
14+
cp -r plugins/_template plugins/degenz
15+
```
16+
17+
Next update the naming of various variables and classes to match your dapp, for
18+
example:
19+
20+
```
21+
export const _TEMPLATE_PLUGIN_ID = "_template_plugin"; -> export const DEGENZ_PLUGIN_ID = "degenz";
22+
interface _TemplatePluginConfig -> interface DegenzPluginConfig
23+
class TemplatePlugin -> class DegenzPlugin
24+
```
25+
26+
The template contains placeholder implementations for each plugin method, update
27+
these to implement your plugins logic as required. `onStart` is where you should
28+
do any initialization logic such as starting of tasks, etc. `onStop` is where
29+
any clean-up logic should be placed, destroying of tasks, persisting of any
30+
data, etc.
31+
32+
Finally register your plugin for usage by added it to `pluginConstructorMap` in
33+
`plugins/mod.ts` like so:
34+
35+
```ts
36+
import { PluginConstructor } from "../src/plugins/plugin.ts";
37+
import { EXAMPLE_PLUGIN_ID, ExamplePlugin } from "./example_plugin/mod.ts";
38+
import { DEGENZ_PLUGIN_ID, DegenzPlugin } from "./degenz/mod.ts";
39+
40+
export const pluginConstructorMap: Record<string, PluginConstructor> = {
41+
[EXAMPLE_PLUGIN_ID]: ExamplePlugin,
42+
[DEGENZ_PLUGIN_ID]: DegenzPlugin,
43+
};
44+
```
45+
46+
Now you should be all set to add your plugin to your `ergomatic` configuration
47+
file. For example:
48+
49+
```toml
50+
logLevel: INFO
51+
plugins:
52+
- id: degenz
53+
enabled: true
54+
logLevel: DEBUG
55+
config:
56+
configValue: "testing"
57+
otherConfigValue: 5
58+
```

plugins/_template/mod.ts

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Block, SignedTransaction } from "@fleet-sdk/common";
2+
import { BlockchainSnapshot } from "../../src/blockchain/blockchain_monitor.ts";
3+
import { Plugin, PluginDescriptor } from "../../src/plugins/mod.ts";
4+
import { z } from "zod/mod.ts";
5+
6+
export const _TEMPLATE_PLUGIN_ID = "_template_plugin";
7+
8+
interface _TemplatePluginConfig {
9+
configValue: string;
10+
otherConfigValue: number;
11+
}
12+
13+
export class _TemplatePlugin extends Plugin<_TemplatePluginConfig> {
14+
get descriptor(): PluginDescriptor {
15+
return {
16+
// Human readable name of your plugin
17+
name: "Template Plugin",
18+
// Description of your plugins functionality and anything else users should be aware of
19+
description:
20+
"Template for developers to get started creating their own plugins",
21+
// Version of your plugin
22+
version: "0.1.0",
23+
};
24+
}
25+
26+
onStart(): Promise<void> {
27+
this.logger.info(`started with configuration: ${this.config}`);
28+
29+
return Promise.resolve();
30+
}
31+
32+
onStop(): Promise<void> {
33+
this.logger.info("Plugin shutting down, performing cleanup!");
34+
35+
return Promise.resolve();
36+
}
37+
38+
onNewBlock(
39+
block: Block,
40+
snapshot: Readonly<BlockchainSnapshot>,
41+
): Promise<void> {
42+
this.logger.info(`block: ${block}, snapshot: ${snapshot}`);
43+
44+
return Promise.resolve();
45+
}
46+
47+
onMempoolTx(
48+
tx: SignedTransaction,
49+
snapshot: Readonly<BlockchainSnapshot>,
50+
): Promise<void> {
51+
this.logger.info(`mempool tx: ${tx}, snapshot: ${snapshot}`);
52+
53+
return Promise.resolve();
54+
}
55+
56+
onIncludedTx(
57+
tx: SignedTransaction,
58+
snapshot: Readonly<BlockchainSnapshot>,
59+
): Promise<void> {
60+
this.logger.info(`tx included in block: ${tx}, snapshot: ${snapshot}`);
61+
62+
return Promise.resolve();
63+
}
64+
65+
onMempoolTxDrop(
66+
tx: SignedTransaction,
67+
snapshot: Readonly<BlockchainSnapshot>,
68+
): Promise<void> {
69+
this.logger.warning(
70+
`tx dropped from mempool without being included in block: ${tx}, snapshot: ${snapshot}`,
71+
);
72+
73+
return Promise.resolve();
74+
}
75+
76+
// deno-lint-ignore no-explicit-any
77+
configSchema(): z.ZodObject<any> | undefined {
78+
return z.object({
79+
configValue: z.string(),
80+
otherConfigValue: z.number(),
81+
});
82+
}
83+
}

0 commit comments

Comments
 (0)