denotify-client 1.0.0

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.
Files changed (37) hide show
  1. package/README.md +1 -0
  2. package/dist/alertbuilder.js +44 -0
  3. package/dist/denotifyclient.js +108 -0
  4. package/dist/examples/aave-healthcheck.js +50 -0
  5. package/dist/examples/delete-alert.js +13 -0
  6. package/dist/functionbuilder.js +30 -0
  7. package/dist/index.js +4215 -0
  8. package/dist/index.min.js +1 -0
  9. package/dist/index.mjs +4201 -0
  10. package/dist/notifications/notification.js +8 -0
  11. package/dist/notifications/notify_discord_webhook.js +10 -0
  12. package/dist/triggers/handler_function_call.js +1 -0
  13. package/dist/triggers/handler_function_call_v2.js +12 -0
  14. package/dist/triggers/handler_onchain_event.js +1 -0
  15. package/dist/triggers/trigger.js +10 -0
  16. package/dist/types/types.js +1 -0
  17. package/dist/util/filter.js +131 -0
  18. package/license +9 -0
  19. package/package.json +64 -0
  20. package/types/alertbuilder.d.ts +17 -0
  21. package/types/client.d.ts +14 -0
  22. package/types/denotifyclient.d.ts +27 -0
  23. package/types/examples/aave-healthcheck.d.ts +1 -0
  24. package/types/examples/delete-alert.d.ts +1 -0
  25. package/types/functionbuilder.d.ts +16 -0
  26. package/types/index.d.ts +2 -0
  27. package/types/notifications/notification.d.ts +15 -0
  28. package/types/notifications/notify_discord_webhook.d.ts +32 -0
  29. package/types/temp.d.ts +1 -0
  30. package/types/triggers/handler_function_call.d.ts +39 -0
  31. package/types/triggers/handler_function_call_v2.d.ts +65 -0
  32. package/types/triggers/handler_onchain_event.d.ts +31 -0
  33. package/types/triggers/trigger.d.ts +20 -0
  34. package/types/types/notification.d.ts +7 -0
  35. package/types/types/trigger.d.ts +29 -0
  36. package/types/types/types.d.ts +20 -0
  37. package/types/util/filter.d.ts +35 -0
@@ -0,0 +1,8 @@
1
+ import { NotifyDiscordWebhook } from "./notify_discord_webhook.js";
2
+ export class Notification {
3
+ static SimpleToRaw(id, config) {
4
+ switch (id) {
5
+ case 'Discord': return NotifyDiscordWebhook.SimpleToRaw(config);
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,10 @@
1
+ export const NOTIFY_DISCORD_WEBHOOK_RAW_ID = 'notify_discord_webhook';
2
+ export class NotifyDiscordWebhook {
3
+ static SimpleToRaw(config) {
4
+ return {
5
+ name: '',
6
+ notify_type: NOTIFY_DISCORD_WEBHOOK_RAW_ID,
7
+ notify: config
8
+ };
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ const HANDLER_FUNCTION_CALL_V2_RAW_ID = 'handler_function_call_v2';
2
+ export class HandlerFunctionCallV2 {
3
+ static SimpleToRaw(name, network, config) {
4
+ return {
5
+ alertType: 'event',
6
+ network,
7
+ nickname: name,
8
+ type: HANDLER_FUNCTION_CALL_V2_RAW_ID,
9
+ handler: config
10
+ };
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { HandlerFunctionCallV2 } from "./handler_function_call_v2.js";
2
+ export class Trigger {
3
+ static SimpleToRaw(name, id, network, config) {
4
+ switch (id) {
5
+ case 'PollFunctionV2': return HandlerFunctionCallV2.SimpleToRaw(name, network, config);
6
+ default:
7
+ throw new Error('Invalid Trigger ID');
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,131 @@
1
+ export class Filter {
2
+ static version() {
3
+ return 'v1';
4
+ }
5
+ static execute(record, groupsIn, version = 'v1') {
6
+ // Deep copy to so we can edit the object during recursion
7
+ const groups = JSON.parse(JSON.stringify(groupsIn));
8
+ let lhs = true;
9
+ for (const group of groups) {
10
+ const rhs = Filter.process(record, group.conditions);
11
+ lhs = Filter.execLogic(lhs, group.logic, rhs);
12
+ }
13
+ return lhs;
14
+ }
15
+ static process(record, conditions, lhs) {
16
+ const condition = conditions.shift();
17
+ if (!condition) {
18
+ if (lhs === undefined)
19
+ return true;
20
+ return lhs;
21
+ }
22
+ // lhs <logic> rhs
23
+ const rhs = Filter.execCondition(record, condition);
24
+ if (lhs === undefined || condition.logic === 'WHERE')
25
+ return Filter.process(record, conditions, rhs);
26
+ if (condition.logic === undefined)
27
+ throw new Error('Invalid filter. Condition must have logic value');
28
+ const next = Filter.execLogic(lhs, condition.logic, rhs);
29
+ return Filter.process(record, conditions, next);
30
+ }
31
+ static execLogic(lhs, logic, rhs) {
32
+ switch (logic) {
33
+ case 'AND': return lhs && rhs;
34
+ case 'OR': return lhs || rhs;
35
+ case 'XOR': return (lhs || rhs) && !(lhs && rhs);
36
+ case 'NAND': return !(lhs && rhs);
37
+ case 'NOR': return !(lhs && rhs);
38
+ case 'WHERE': return rhs;
39
+ default: throw new Error(`Invalid Filter. Bad logic value: ${logic}`);
40
+ }
41
+ }
42
+ static execCondition(record, condition) {
43
+ const data = record[condition.key];
44
+ if (condition.type === 'Number') {
45
+ if (typeof condition.constant !== 'number' || typeof data !== 'number')
46
+ throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
47
+ const n = data;
48
+ const constant = condition.constant;
49
+ switch (condition.operation) {
50
+ case 'eq': return n === constant;
51
+ case '!eq': return n !== constant;
52
+ case 'gt': return n > constant;
53
+ case 'gte': return n >= constant;
54
+ case 'lt': return n < constant;
55
+ case 'lte': return n <= constant;
56
+ default: throw new Error('Invalid Filter. Operation does not match type');
57
+ }
58
+ }
59
+ if (condition.type === 'String') {
60
+ if (typeof condition.constant !== 'string' || typeof data !== 'string')
61
+ throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
62
+ const str = data;
63
+ const constant = condition.constant;
64
+ switch (condition.operation) {
65
+ case 'contains': return str.includes(constant);
66
+ case '!contains': return !str.includes(constant);
67
+ case 'is': return str === constant;
68
+ case '!is': return str !== constant;
69
+ case 'isEmpty': return str === '';
70
+ case '!isEmpty': return str !== '';
71
+ default: throw new Error('Invalid Filter. Operation does not match type');
72
+ }
73
+ }
74
+ if (condition.type === 'Address') {
75
+ if (typeof condition.constant !== 'string' || typeof data !== 'string')
76
+ throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
77
+ const str = data;
78
+ const constant = condition.constant;
79
+ switch (condition.operation) {
80
+ case 'contains': return str.toLowerCase().includes(constant.toLowerCase());
81
+ case '!contains': return !str.toLowerCase().includes(constant.toLowerCase());
82
+ case 'is': return str.toLowerCase() === constant.toLowerCase();
83
+ case '!is': return str.toLowerCase() !== constant.toLowerCase();
84
+ case 'isEmpty': return str === '';
85
+ case '!isEmpty': return str !== '';
86
+ default: throw new Error('Invalid Filter. Operation does not match type');
87
+ }
88
+ }
89
+ throw new Error('Invalid Filter. Unknown Type');
90
+ }
91
+ }
92
+ export class FilterBuilder {
93
+ groups = [];
94
+ constructor() {
95
+ this.newGroup('WHERE');
96
+ }
97
+ static version() {
98
+ return Filter.version();
99
+ }
100
+ static new() {
101
+ return new FilterBuilder();
102
+ }
103
+ newGroup(logic) {
104
+ if (this.groups.length !== 0 && logic === 'WHERE')
105
+ throw new Error('Only the first groups can start with "WHERE"');
106
+ this.groups.push({ logic: 'WHERE', conditions: [] });
107
+ return this;
108
+ }
109
+ addCondition(logic, key, type, operation, constant) {
110
+ const group = this.groups[this.groups.length - 1];
111
+ if (group.conditions.length === 0 && logic !== 'WHERE')
112
+ throw new Error('Logic for the first condition of a group must be "WHERE"');
113
+ if (group.conditions.length > 0 && logic === 'WHERE')
114
+ throw new Error('Only the first condition of a group can be "WHERE"');
115
+ group.conditions.push({
116
+ logic,
117
+ key,
118
+ type,
119
+ operation,
120
+ constant
121
+ });
122
+ return this;
123
+ }
124
+ finalise() {
125
+ for (const group of this.groups) {
126
+ if (group.conditions.length === 0)
127
+ throw new Error('Bad Filter. All Groups must have atleast one condition');
128
+ }
129
+ return this.groups;
130
+ }
131
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) ROBO LABS <info@robolabs.biz> (https://robolabs.biz)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "name": "denotify-client",
4
+ "umd:name": "denotify-client",
5
+ "repository": "robo-labs/denotify-client",
6
+ "description": "Client module for the Robo Labs DeNotify Crypto Alerts API",
7
+ "unpkg": "dist/index.min.js",
8
+ "module": "dist/index.mjs",
9
+ "main": "dist/index.js",
10
+ "types": "types/index.d.ts",
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "author": {
14
+ "name": "Robo Labs",
15
+ "email": "info@robolabs.biz",
16
+ "url": "https://robolabs.biz"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "types"
21
+ ],
22
+ "exports": {
23
+ ".": {
24
+ "import": "./dist/index.mjs",
25
+ "require": "./dist/index.js"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "engines": {
30
+ "node": ">=12"
31
+ },
32
+ "scripts": {
33
+ "build": "rollup -c",
34
+ "prepublishOnly": "npm run build",
35
+ "types": "tsc --noEmit",
36
+ "test": "uvu -r tsm test"
37
+ },
38
+ "keywords": [
39
+ "crypto",
40
+ "web3",
41
+ "alerts",
42
+ "ethereum",
43
+ "module",
44
+ "keywords"
45
+ ],
46
+ "devDependencies": {
47
+ "@rollup/plugin-node-resolve": "13.1.3",
48
+ "@supabase/supabase-js": "^2.10.0",
49
+ "axois": "^0.0.1-security",
50
+ "ethers": "^6.0.8",
51
+ "rollup": "2.66.1",
52
+ "rollup-plugin-terser": "7.0.2",
53
+ "rollup-plugin-typescript2": "0.27.1",
54
+ "tsm": "2.2.1",
55
+ "typescript": "4.5.5",
56
+ "uvu": "0.5.3"
57
+ },
58
+ "dependencies": {
59
+ "@supabase/supabase-js": "^2.10.0",
60
+ "@types/axios": "^0.14.0",
61
+ "axois": "^0.0.1-security",
62
+ "ethers": "^6.0.8"
63
+ }
64
+ }
@@ -0,0 +1,17 @@
1
+ import { NotificationConfig, NotificationTypeId } from "./notifications/notification.js";
2
+ import { Network, TriggerConfig, TriggerTypeId } from "./triggers/trigger.js";
3
+ import { AlertConfig } from "./types/types.js";
4
+ export declare class AlertBuilder {
5
+ private name;
6
+ private network?;
7
+ private triggerId?;
8
+ private trigger?;
9
+ private notificationId?;
10
+ private notification?;
11
+ private constructor();
12
+ static create(name: string): AlertBuilder;
13
+ onNetwork(network: Network): AlertBuilder;
14
+ withTrigger<T = TriggerConfig>(id: TriggerTypeId, options: T): AlertBuilder;
15
+ withNotification<T = NotificationConfig>(id: NotificationTypeId, options: T): AlertBuilder;
16
+ config(): AlertConfig;
17
+ }
@@ -0,0 +1,14 @@
1
+ import { DeNotifyOptions } from "./types/types";
2
+ export declare class DeNotifyClient {
3
+ private url;
4
+ private token;
5
+ private headers;
6
+ private constructor();
7
+ static create(options: DeNotifyOptions): Promise<DeNotifyClient>;
8
+ getAlert(id: number): Promise<any>;
9
+ getAlerts(): Promise<any>;
10
+ createAlert(): Promise<void>;
11
+ deleteAlert(id: number): Promise<any>;
12
+ private request;
13
+ getAbiHash(abi: any): Promise<any>;
14
+ }
@@ -0,0 +1,27 @@
1
+ import { AlertConfig, DeNotifyOptions } from "./types/types.js";
2
+ import { TriggerUpdate } from "./triggers/trigger.js";
3
+ export declare class DeNotifyClient {
4
+ private url;
5
+ private token;
6
+ private headers;
7
+ private constructor();
8
+ static create(options: DeNotifyOptions): Promise<DeNotifyClient>;
9
+ alertHistory(id: number | null, pagination?: {
10
+ page?: number;
11
+ size?: number;
12
+ }): Promise<any>;
13
+ getAlert(id: number): Promise<any>;
14
+ getAlerts(): Promise<any>;
15
+ createAlert(config: AlertConfig): Promise<any>;
16
+ deleteAlert(id: number): Promise<any>;
17
+ private request;
18
+ getAbi(network: string, address: string): Promise<{
19
+ abi: any[];
20
+ proxy?: string;
21
+ }>;
22
+ getAbiHash(abi: any): Promise<any>;
23
+ setAlertName(triggerId: number, name: string): Promise<void>;
24
+ enableAlert(triggerId: number): Promise<void>;
25
+ disableAlert(triggerId: number): Promise<void>;
26
+ updateTrigger(triggerId: number, update: TriggerUpdate): Promise<any>;
27
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { DeNotifyClient } from "./denotifyclient.js";
2
+ export declare type FunctionCallerConfig = {
3
+ address: string;
4
+ bytecode: string;
5
+ abiHash: string;
6
+ function: string;
7
+ }[];
8
+ export declare class FunctionBuilder {
9
+ private api?;
10
+ private data;
11
+ private constructor();
12
+ static create(api?: DeNotifyClient): FunctionBuilder;
13
+ getAbiHash(abi: any): Promise<string>;
14
+ addFunction<T = any>(address: string, func: string, args: T[], abi: any): Promise<this>;
15
+ get(): FunctionCallerConfig;
16
+ }
@@ -0,0 +1,2 @@
1
+ import { DeNotifyClient } from "./denotifyclient.js";
2
+ export { DeNotifyClient };
@@ -0,0 +1,15 @@
1
+ import { DiscordWebhook, NotifyDiscordWebhookRawConfig, NotifyDiscordWebhookRawId, NotifyDiscordWebhookRawResponse, NotifyDiscordWebhookRawUpdate } from "./notify_discord_webhook.js";
2
+ export declare type NotificationTypeId = 'Discord';
3
+ export declare type NotificationConfig = DiscordWebhook;
4
+ export declare type NotifyRawId = NotifyDiscordWebhookRawId;
5
+ export declare type NotifyRawConfig = NotifyDiscordWebhookRawConfig;
6
+ export declare type NotifyRawResponse = NotifyDiscordWebhookRawResponse;
7
+ export declare type NotifyRawUpdate = NotifyDiscordWebhookRawUpdate;
8
+ export declare type NotificationRawConfig = {
9
+ name: string;
10
+ notify_type: NotifyRawId;
11
+ notify: NotifyRawConfig;
12
+ };
13
+ export declare class Notification {
14
+ static SimpleToRaw(id: NotificationTypeId, config: NotificationConfig): NotificationRawConfig;
15
+ }
@@ -0,0 +1,32 @@
1
+ import { NotificationRawConfig } from "./notification.js";
2
+ export declare type DiscordWebhook = {
3
+ url: string;
4
+ username?: string;
5
+ avatar_url?: string;
6
+ message: string;
7
+ };
8
+ export declare type NotifyDiscordWebhookRawId = 'notify_discord_webhook';
9
+ export declare const NOTIFY_DISCORD_WEBHOOK_RAW_ID = "notify_discord_webhook";
10
+ export declare type NotifyDiscordWebhookRawConfig = {
11
+ url: string;
12
+ username?: string;
13
+ avatar_url?: string;
14
+ message: string;
15
+ };
16
+ export declare type NotifyDiscordWebhookRawResponse = {
17
+ id: number;
18
+ created_at: string;
19
+ url: string;
20
+ username: string;
21
+ avatar_url: string;
22
+ message: string;
23
+ };
24
+ export declare type NotifyDiscordWebhookRawUpdate = {
25
+ url?: string;
26
+ username?: string;
27
+ avatar_url?: string;
28
+ message?: string;
29
+ };
30
+ export declare class NotifyDiscordWebhook {
31
+ static SimpleToRaw(config: DiscordWebhook): NotificationRawConfig;
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ import { Condition } from "../types/types.js";
2
+ export declare type PollFunctionV1 = {};
3
+ export declare type HandlerFunctionCallRawConfig = {
4
+ nBlocks: number;
5
+ address: string;
6
+ abi: any;
7
+ fixedArgs?: (string | number)[];
8
+ function: string;
9
+ condition: Condition;
10
+ responseArgIndex?: number;
11
+ responseArgDecimals?: number;
12
+ constant?: number;
13
+ };
14
+ export declare type HandlerFunctionCallUpdate = Partial<HandlerFunctionCallRawConfig>;
15
+ export declare type HandlerFunctionCallRawResponse = {
16
+ id: number;
17
+ created_at: string;
18
+ nBlocks: number;
19
+ address: string;
20
+ fixedArgs: string[];
21
+ responseArgIndex: number;
22
+ responseArgDecimals: number;
23
+ function: string;
24
+ condition: Condition;
25
+ constant: number;
26
+ abi: string[];
27
+ version: number;
28
+ };
29
+ export declare type HandlerFunctionCallRawUpdate = {
30
+ address?: string;
31
+ function?: string;
32
+ abi?: any;
33
+ constant?: number;
34
+ nBlocks?: number;
35
+ confition?: Condition;
36
+ fixedArgs?: (string | number)[];
37
+ responseArgIndex?: number;
38
+ responseArgDecimals?: number;
39
+ };
@@ -0,0 +1,65 @@
1
+ import { FunctionCallerConfig } from "../functionbuilder.js";
2
+ import { Condition } from "../types/types.js";
3
+ import { FilterConfig } from "../util/filter.js";
4
+ import { Network, TriggerRawConfig } from "./trigger.js";
5
+ declare type TimeBase = 'blocks' | 'time';
6
+ /**
7
+ * @typedef PollFunction
8
+ * @param {TimeBase} timeBase - Supports two poll period types. 'block' will test the trigger ever nBlocks blocks, 'time' will test the trigger as specified by timePeriod
9
+ * @param {number} nBlocks -
10
+ *
11
+ */
12
+ export declare type PollFunctionV2 = {
13
+ timeBase: TimeBase;
14
+ nBlocks?: number;
15
+ timePeriod?: string | null;
16
+ startTime?: number;
17
+ debounceCount?: number;
18
+ functions: FunctionCallerConfig;
19
+ triggerOn: 'always' | 'filter';
20
+ latch?: boolean;
21
+ filterVersion?: string;
22
+ filter?: FilterConfig;
23
+ };
24
+ export declare type HandlerFunctionCallV2RawConfig = {
25
+ timeBase: TimeBase;
26
+ nBlocks?: number;
27
+ timePeriod?: string | null;
28
+ startTime?: number;
29
+ debounceCount?: number;
30
+ functions: FunctionCallerConfig;
31
+ triggerOn: 'always' | 'filter';
32
+ latch?: boolean;
33
+ filterVersion?: string;
34
+ filter?: FilterConfig;
35
+ };
36
+ export declare type HandlerFunctionCallV2Update = Partial<HandlerFunctionCallV2RawConfig>;
37
+ export declare type HandlerFunctionCallV2RawResponse = {
38
+ id: number;
39
+ created_at: string;
40
+ nBlocks: number;
41
+ address: string;
42
+ fixedArgs: string[];
43
+ responseArgIndex: number;
44
+ responseArgDecimals: number;
45
+ function: string;
46
+ condition: Condition;
47
+ constant: number;
48
+ abi: string[];
49
+ version: number;
50
+ };
51
+ export declare type HandlerFunctionCallV2RawUpdate = {
52
+ address?: string;
53
+ function?: string;
54
+ abi?: any;
55
+ constant?: number;
56
+ nBlocks?: number;
57
+ confition?: Condition;
58
+ fixedArgs?: (string | number)[];
59
+ responseArgIndex?: number;
60
+ responseArgDecimals?: number;
61
+ };
62
+ export declare class HandlerFunctionCallV2 {
63
+ static SimpleToRaw(name: string, network: Network, config: PollFunctionV2): TriggerRawConfig;
64
+ }
65
+ export {};
@@ -0,0 +1,31 @@
1
+ import { Condition } from "../util/filter.js";
2
+ export declare type OnchainEventV1 = {};
3
+ export declare type HandlerOnchainEventRawConfig = {
4
+ address: string;
5
+ event: string;
6
+ abi: any;
7
+ condition: Condition;
8
+ paramsIndex?: number;
9
+ paramsDecimals?: number;
10
+ constant?: number;
11
+ };
12
+ export declare type HandlerOnchainEventUpdate = Partial<HandlerOnchainEventRawConfig>;
13
+ export declare type HandlerOnchainEventRawResponse = {
14
+ id: number;
15
+ created_at: string;
16
+ address: string;
17
+ event: string;
18
+ abi: any;
19
+ paramsIndex: number;
20
+ paramsDecimals: number;
21
+ condition: Condition;
22
+ constant: number;
23
+ };
24
+ export declare type HandlerOnchainEventRawUpdate = {
25
+ address?: string;
26
+ event?: string;
27
+ abi?: any;
28
+ paramsIndex?: number;
29
+ paramsDecimals?: number;
30
+ constant?: number;
31
+ };
@@ -0,0 +1,20 @@
1
+ import { HandlerFunctionCallRawConfig, HandlerFunctionCallUpdate, PollFunctionV1 } from "./handler_function_call.js";
2
+ import { HandlerOnchainEventRawConfig, HandlerOnchainEventUpdate, OnchainEventV1 } from "./handler_onchain_event.js";
3
+ import { HandlerFunctionCallV2RawConfig, HandlerFunctionCallV2Update, PollFunctionV2 } from "./handler_function_call_v2.js";
4
+ export declare type Network = 'avalanche' | 'ethereum';
5
+ export declare type TriggerConfig = PollFunctionV2 | PollFunctionV1 | OnchainEventV1;
6
+ export declare type TriggerTypeId = 'PollFunctionV2' | 'OnchainEventV2' | 'FunctionEventV2';
7
+ export declare type TriggerUpdate = HandlerFunctionCallV2Update | HandlerFunctionCallUpdate | HandlerOnchainEventUpdate;
8
+ export declare type TriggerTypeRawId = 'handler_function_call' | 'onchain_event_call_v2' | 'handler_function_call_v2';
9
+ export declare type TriggerOn = 'event' | 'latch';
10
+ export declare type HandlerRawConfig = HandlerFunctionCallRawConfig | HandlerOnchainEventRawConfig | HandlerFunctionCallV2RawConfig;
11
+ export declare type TriggerRawConfig = {
12
+ nickname: string;
13
+ type: TriggerTypeRawId;
14
+ alertType: TriggerOn;
15
+ network: Network;
16
+ handler: HandlerRawConfig;
17
+ };
18
+ export declare class Trigger {
19
+ static SimpleToRaw(name: string, id: TriggerTypeId, network: Network, config: TriggerConfig): TriggerRawConfig;
20
+ }
@@ -0,0 +1,7 @@
1
+ declare type DiscordWebhook = {
2
+ url: string;
3
+ message: string;
4
+ username?: string;
5
+ avatar_url?: string;
6
+ };
7
+ declare type NotificationType = DiscordWebhook;
@@ -0,0 +1,29 @@
1
+ import { FilterConfig } from "../util/filter";
2
+ export declare type FunctionCallerConfig = {
3
+ address: string;
4
+ bytecode: string;
5
+ abiHash: string;
6
+ function: string;
7
+ }[];
8
+ export declare type TriggerTypeId = 'PollFunctionV2' | 'OnchainEventV2' | 'FunctionEventV2';
9
+ declare type TimeBase = 'blocks' | 'time';
10
+ /**
11
+ * @typedef PollFunction
12
+ * @param {TimeBase} timeBase - Supports two poll period types. 'block' will test the trigger ever nBlocks blocks, 'time' will test the trigger as specified by timePeriod
13
+ * @param {number} nBlocks -
14
+ *
15
+ */
16
+ export declare type PollFunction = {
17
+ timeBase: TimeBase;
18
+ nBlocks?: number;
19
+ timePeriod?: string | null;
20
+ startTime?: number;
21
+ debounceCount?: number;
22
+ functions: FunctionCallerConfig;
23
+ triggerOn: 'always' | 'filter';
24
+ latch?: boolean;
25
+ filterVersion?: string;
26
+ filter?: FilterConfig;
27
+ };
28
+ export declare type TriggerType = PollFunction;
29
+ export {};
@@ -0,0 +1,20 @@
1
+ import { NotificationConfig, NotificationTypeId } from "../notifications/notification.js";
2
+ import { Network, TriggerConfig, TriggerTypeId } from "../triggers/trigger.js";
3
+ export declare type Condition = '>' | '>=' | '<' | '<=' | '=' | 'true';
4
+ export declare type TriggerOn = 'event' | 'latch';
5
+ export declare type DeNotifyOptions = {
6
+ email?: string;
7
+ password?: string;
8
+ projectId?: string;
9
+ key?: string;
10
+ url?: string;
11
+ anonKey?: string;
12
+ };
13
+ export declare type AlertConfig = {
14
+ name: string;
15
+ network: Network;
16
+ triggerId: TriggerTypeId;
17
+ trigger: TriggerConfig;
18
+ notificationId: NotificationTypeId;
19
+ notification: NotificationConfig;
20
+ };
@@ -0,0 +1,35 @@
1
+ declare type Logic = 'AND' | 'OR' | 'XOR' | 'NAND' | 'NOR' | 'WHERE';
2
+ declare type NumericOperation = 'eq' | '!eq' | 'gt' | 'gte' | 'lt' | 'lte';
3
+ declare type StringOperation = 'contains' | '!contains' | 'is' | '!is' | 'isEmpty' | '!isEmpty';
4
+ declare type AddressOperation = 'is' | '!is' | 'isEmpty' | '!isEmpty';
5
+ declare type FilterDataTypes = 'String' | 'Address' | 'Number';
6
+ declare type FilterOpertationType = NumericOperation | StringOperation | AddressOperation;
7
+ export declare type Condition = {
8
+ logic?: Logic;
9
+ key: string;
10
+ type: FilterDataTypes;
11
+ operation: FilterOpertationType;
12
+ constant: string | number;
13
+ };
14
+ export declare type ConditionGroup = {
15
+ logic: Logic;
16
+ conditions: Condition[];
17
+ };
18
+ export declare type FilterConfig = ConditionGroup[];
19
+ export declare class Filter {
20
+ static version(): string;
21
+ static execute(record: any, groupsIn: FilterConfig, version?: string): boolean;
22
+ private static process;
23
+ private static execLogic;
24
+ private static execCondition;
25
+ }
26
+ export declare class FilterBuilder {
27
+ private groups;
28
+ constructor();
29
+ static version(): string;
30
+ static new(): FilterBuilder;
31
+ newGroup(logic: Logic): FilterBuilder;
32
+ addCondition(logic: Logic, key: string, type: FilterDataTypes, operation: FilterOpertationType, constant: string | number): FilterBuilder;
33
+ finalise(): ConditionGroup[];
34
+ }
35
+ export {};