denotify-client 1.1.6 → 1.1.7
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.
@@ -1,57 +1,47 @@
|
|
1
|
+
import { AlertBuilder } from "../alertbuilder.js";
|
1
2
|
import { DeNotifyClient } from "../denotifyclient.js";
|
3
|
+
import { FunctionBuilder } from "../functionbuilder.js";
|
4
|
+
import { FilterBuilder } from "../util/filter.js";
|
2
5
|
// Simple App to demonstrate usage. Created a balance monitoring alert, updates it and deletes it
|
3
6
|
async function main() {
|
4
7
|
const api = await DeNotifyClient.create({
|
5
|
-
email:
|
6
|
-
password:
|
8
|
+
email: process.env.EMAIL,
|
9
|
+
password: process.env.PASSWORD,
|
7
10
|
});
|
8
|
-
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
//
|
30
|
-
|
31
|
-
|
32
|
-
//
|
33
|
-
|
34
|
-
//
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
//
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
// const triggerId = await api.createAlert(alert)
|
44
|
-
// console.log(triggerId)
|
45
|
-
// // Update the period to every 10s
|
46
|
-
// await api.updateTrigger(triggerId, { timePeriod: '10s' })
|
47
|
-
// // Update the Filter using the filter builder
|
48
|
-
// const filter = FilterBuilder.new()
|
49
|
-
// .addCondition('WHERE', 'func_0_ret_0', 'Number', 'gt', 3)
|
50
|
-
// .finalise()
|
51
|
-
// await api.updateTrigger(13, { triggerOn: 'filter', filter, filterVersion: FilterBuilder.version() })
|
52
|
-
// // Delete the filter in 10s
|
53
|
-
// setTimeout(async () => {
|
54
|
-
// await api.deleteAlert(triggerId)
|
55
|
-
// }, 10 * 1000)
|
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);
|
56
46
|
}
|
57
47
|
main();
|
package/package.json
CHANGED
@@ -1,47 +0,0 @@
|
|
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 = 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();
|