denotify-client 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alertbuilder.js +24 -1
- package/dist/examples/balance-monitor.js +47 -0
- package/dist/functionbuilder.js +9 -0
- package/dist/index.js +4617 -7
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +284 -164
- package/dist/notifications/notify_discord_webhook.js +11 -0
- package/dist/triggers/handler_function_call.js +14 -0
- package/dist/triggers/handler_function_call_v2.js +29 -0
- package/dist/triggers/handler_onchain_event.js +16 -0
- package/dist/triggers/trigger.js +1 -1
- package/dist/util/filter.js +29 -0
- package/package.json +6 -4
- package/types/alertbuilder.d.ts +57 -3
- package/types/examples/aave-healthcheck.d.ts +1 -1
- package/types/examples/balance-monitor.d.ts +1 -0
- package/types/functionbuilder.d.ts +7 -0
- package/types/notifications/notify_discord_webhook.d.ts +6 -0
- package/types/triggers/handler_function_call.d.ts +9 -0
- package/types/triggers/handler_function_call_v2.d.ts +26 -0
- package/types/triggers/handler_onchain_event.d.ts +11 -1
- package/types/triggers/trigger.d.ts +1 -1
- package/types/util/filter.d.ts +11 -0
package/dist/alertbuilder.js
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
import { NotifyDiscordWebhook } from "./notifications/notify_discord_webhook.js";
|
2
|
+
import { HandlerFunctionCall } from "./triggers/handler_function_call.js";
|
3
|
+
import { HandlerFunctionCallV2 } from "./triggers/handler_function_call_v2.js";
|
4
|
+
import { HandlerOnchainEvent } from "./triggers/handler_onchain_event.js";
|
1
5
|
export class AlertBuilder {
|
2
6
|
name;
|
3
7
|
network;
|
@@ -15,6 +19,13 @@ export class AlertBuilder {
|
|
15
19
|
this.network = network;
|
16
20
|
return this;
|
17
21
|
}
|
22
|
+
/**
|
23
|
+
* Call withTrigger with one of the TriggerConfig types:
|
24
|
+
* PollFunctionV2 | PollFunctionV1 | OnchainEventV1
|
25
|
+
* @param id Simple ID
|
26
|
+
* @param options Desired trigger configuration
|
27
|
+
* @returns self for piping
|
28
|
+
*/
|
18
29
|
withTrigger(id, options) {
|
19
30
|
this.triggerId = id;
|
20
31
|
this.trigger = options;
|
@@ -25,13 +36,25 @@ export class AlertBuilder {
|
|
25
36
|
this.notification = options;
|
26
37
|
return this;
|
27
38
|
}
|
28
|
-
|
39
|
+
async validate() {
|
40
|
+
// Validate trigger
|
41
|
+
switch (this.triggerId) {
|
42
|
+
case 'OnchainEventV1': return HandlerOnchainEvent.validateCreate(this.trigger);
|
43
|
+
case 'PollFunctionV1': return HandlerFunctionCall.validateCreate(this.trigger);
|
44
|
+
case 'PollFunctionV2': return HandlerFunctionCallV2.validateCreate(this.trigger);
|
45
|
+
}
|
46
|
+
switch (this.notificationId) {
|
47
|
+
case 'Discord': return NotifyDiscordWebhook.validateCreate(this.notification);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
async config() {
|
29
51
|
if (this.trigger === undefined || this.triggerId === undefined)
|
30
52
|
throw new Error('Trigger not configured');
|
31
53
|
if (this.notification === undefined || this.notificationId === undefined)
|
32
54
|
throw new Error('Notification not configured');
|
33
55
|
if (this.network === undefined)
|
34
56
|
throw new Error('Network not configured');
|
57
|
+
await this.validate();
|
35
58
|
return {
|
36
59
|
name: this.name,
|
37
60
|
network: this.network,
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { AlertBuilder } from "../alertbuilder.js";
|
2
|
+
import { DeNotifyClient } from "../denotifyclient.js";
|
3
|
+
import { FunctionBuilder } from "../functionbuilder.js";
|
4
|
+
import { FilterBuilder } from "../util/filter.js";
|
5
|
+
// Simple App to demonstrate usage. Created a balance monitoring alert, updates it and deletes it
|
6
|
+
async function main() {
|
7
|
+
const api = await DeNotifyClient.create({
|
8
|
+
email: process.env.EMAIL,
|
9
|
+
password: process.env.PASSWORD,
|
10
|
+
});
|
11
|
+
const network = 'avalanche';
|
12
|
+
const address = '0x26985888d5b7019ff2A7444fB567D8F386c3b538';
|
13
|
+
const myAddress = '0x7601630eC802952ba1ED2B6e4db16F699A0a5A87';
|
14
|
+
const { abi } = await api.getAbi(network, address);
|
15
|
+
const webhook = process.env.DISCORD_WEBHOOK;
|
16
|
+
const builder = FunctionBuilder.create(api);
|
17
|
+
await builder.addFunction(address, 'getBalance', [myAddress], abi);
|
18
|
+
// Create the Balance Monitor alert
|
19
|
+
const alert = await AlertBuilder.create('Test Alert')
|
20
|
+
.onNetwork('avalanche')
|
21
|
+
.withTrigger('PollFunctionV2', {
|
22
|
+
timeBase: 'time',
|
23
|
+
timePeriod: '100s',
|
24
|
+
functions: builder.get(),
|
25
|
+
triggerOn: 'always',
|
26
|
+
})
|
27
|
+
.withNotification('Discord', {
|
28
|
+
url: webhook,
|
29
|
+
message: `Your avax balance is [{func_0_ret_0 / 1e18}](https://snowtrace.io/address/${myAddress})`,
|
30
|
+
})
|
31
|
+
.config();
|
32
|
+
// Create the alert with the API
|
33
|
+
const triggerId = await api.createAlert(alert);
|
34
|
+
console.log(triggerId);
|
35
|
+
// Update the period to every 10s
|
36
|
+
await api.updateTrigger(triggerId, { timePeriod: '10s' });
|
37
|
+
// Update the Filter using the filter builder
|
38
|
+
const filter = FilterBuilder.new()
|
39
|
+
.addCondition('WHERE', 'func_0_ret_0', 'Number', 'gt', 3)
|
40
|
+
.finalise();
|
41
|
+
await api.updateTrigger(13, { triggerOn: 'filter', filter, filterVersion: FilterBuilder.version() });
|
42
|
+
// Delete the filter in 10s
|
43
|
+
setTimeout(async () => {
|
44
|
+
await api.deleteAlert(triggerId);
|
45
|
+
}, 10 * 1000);
|
46
|
+
}
|
47
|
+
main();
|
package/dist/functionbuilder.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
+
import * as yup from 'yup';
|
2
3
|
export class FunctionBuilder {
|
3
4
|
api;
|
4
5
|
data = [];
|
@@ -27,4 +28,12 @@ export class FunctionBuilder {
|
|
27
28
|
get() {
|
28
29
|
return this.data;
|
29
30
|
}
|
31
|
+
static schema() {
|
32
|
+
return yup.array().of(yup.object({
|
33
|
+
address: yup.string().required(),
|
34
|
+
bytecode: yup.string().matches(/^(0x)?([0-9a-fA-F]{2})*$/).required(),
|
35
|
+
abiHash: yup.string().matches(/^[A-Fa-f0-9]{64}/).required(),
|
36
|
+
function: yup.string().required()
|
37
|
+
}));
|
38
|
+
}
|
30
39
|
}
|