otomato-sdk 1.0.1 → 1.2.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 (54) hide show
  1. package/dist/examples/create-action.js +21 -0
  2. package/dist/examples/create-automation.js +42 -0
  3. package/dist/src/constants/Blocks.js +391 -0
  4. package/dist/src/constants/tokens.js +40 -0
  5. package/dist/src/index.js +3 -2
  6. package/dist/src/models/Action.js +6 -1
  7. package/dist/src/models/Automation.js +44 -1
  8. package/dist/src/models/Edge.js +25 -0
  9. package/dist/src/models/Node.js +92 -0
  10. package/dist/src/models/Trigger.js +3 -88
  11. package/dist/src/services/ApiService.js +39 -1
  12. package/dist/src/utils/typeValidator.js +70 -0
  13. package/dist/test/action.spec.js +74 -0
  14. package/dist/test/automation.spec.js +71 -0
  15. package/dist/test/node.spec.js +126 -0
  16. package/dist/test/trigger.spec.js +3 -3
  17. package/dist/test/typeValidator.spec.js +59 -0
  18. package/dist/types/examples/create-action.d.ts +1 -0
  19. package/dist/types/examples/create-automation.d.ts +1 -0
  20. package/dist/types/src/constants/Blocks.d.ts +118 -0
  21. package/dist/types/src/constants/tokens.d.ts +9 -0
  22. package/dist/types/src/index.d.ts +3 -2
  23. package/dist/types/src/models/Action.d.ts +11 -5
  24. package/dist/types/src/models/Automation.d.ts +22 -5
  25. package/dist/types/src/models/Edge.d.ts +14 -0
  26. package/dist/types/src/models/Node.d.ts +42 -0
  27. package/dist/types/src/models/Trigger.d.ts +4 -24
  28. package/dist/types/src/services/ApiService.d.ts +3 -6
  29. package/dist/types/src/utils/typeValidator.d.ts +4 -0
  30. package/dist/types/test/action.spec.d.ts +1 -0
  31. package/dist/types/test/automation.spec.d.ts +1 -0
  32. package/dist/types/test/node.spec.d.ts +1 -0
  33. package/dist/types/test/typeValidator.spec.d.ts +1 -0
  34. package/examples/create-action.ts +28 -0
  35. package/examples/create-automation.ts +41 -0
  36. package/package.json +4 -3
  37. package/src/constants/{ActionBlocks.ts → Blocks.ts} +73 -2
  38. package/src/constants/chains.ts +1 -1
  39. package/src/constants/json.json +16 -0
  40. package/src/constants/tokens.ts +56 -0
  41. package/src/index.ts +3 -2
  42. package/src/models/Action.ts +8 -6
  43. package/src/models/Automation.ts +47 -6
  44. package/src/models/Edge.ts +33 -0
  45. package/src/models/Node.ts +118 -0
  46. package/src/models/Trigger.ts +5 -101
  47. package/src/services/ApiService.ts +31 -6
  48. package/src/utils/typeValidator.ts +65 -0
  49. package/test/action.spec.ts +90 -0
  50. package/test/automation.spec.ts +88 -0
  51. package/test/node.spec.ts +143 -0
  52. package/test/trigger.spec.ts +3 -3
  53. package/test/typeValidator.spec.ts +71 -0
  54. package/src/services/AutomationService.ts +0 -6
@@ -0,0 +1,118 @@
1
+ import { Parameter } from '../models/Parameter.js';
2
+ export declare const TRIGGERS: {
3
+ TOKENS: {
4
+ ERC20: {
5
+ CHAINS: number[];
6
+ TRANSFER: {
7
+ id: number;
8
+ name: string;
9
+ description: string;
10
+ type: number;
11
+ parameters: Parameter[];
12
+ };
13
+ BALANCE: {
14
+ id: number;
15
+ name: string;
16
+ description: string;
17
+ type: number;
18
+ parameters: Parameter[];
19
+ };
20
+ };
21
+ };
22
+ YIELD: {
23
+ SPLICE_FI: {
24
+ CHAINS: number[];
25
+ SWAP: {
26
+ id: number;
27
+ name: string;
28
+ description: string;
29
+ type: number;
30
+ parameters: Parameter[];
31
+ };
32
+ LIQUIDITY_REMOVED: {
33
+ id: number;
34
+ name: string;
35
+ description: string;
36
+ type: number;
37
+ parameters: Parameter[];
38
+ };
39
+ MARKET_CREATION: {
40
+ id: number;
41
+ name: string;
42
+ description: string;
43
+ type: number;
44
+ parameters: Parameter[];
45
+ };
46
+ INTEREST_RATE_UPDATE: {
47
+ id: number;
48
+ name: string;
49
+ description: string;
50
+ type: number;
51
+ parameters: Parameter[];
52
+ };
53
+ };
54
+ };
55
+ LENDING: {
56
+ ASTARIA: {
57
+ CHAINS: number[];
58
+ LEND_RECALLED: {
59
+ id: number;
60
+ name: string;
61
+ description: string;
62
+ type: number;
63
+ parameters: Parameter[];
64
+ };
65
+ };
66
+ };
67
+ DEXES: {
68
+ ODOS: {
69
+ CHAINS: number[];
70
+ SWAP: {
71
+ id: number;
72
+ name: string;
73
+ description: string;
74
+ type: number;
75
+ parameters: Parameter[];
76
+ };
77
+ };
78
+ };
79
+ SOCIALS: {
80
+ MODE_NAME_SERVICE: {
81
+ CHAINS: number[];
82
+ NAME_REGISTERED: {
83
+ id: number;
84
+ name: string;
85
+ description: string;
86
+ type: number;
87
+ parameters: Parameter[];
88
+ };
89
+ };
90
+ };
91
+ };
92
+ export declare const ACTIONS: {
93
+ TOKENS: {
94
+ ERC20: {
95
+ CHAINS: number[];
96
+ TRANSFER: {
97
+ id: number;
98
+ name: string;
99
+ description: string;
100
+ parameters: Parameter[];
101
+ };
102
+ };
103
+ };
104
+ NOTIFICATIONS: {
105
+ SMS: {
106
+ id: number;
107
+ name: string;
108
+ description: string;
109
+ parameters: Parameter[];
110
+ };
111
+ SLACK: {
112
+ id: number;
113
+ name: string;
114
+ description: string;
115
+ parameters: Parameter[];
116
+ };
117
+ };
118
+ };
@@ -8,4 +8,13 @@ export interface Tokens {
8
8
  [key: number]: Token[];
9
9
  }
10
10
  export declare const TOKENS: Tokens;
11
+ export interface NFT {
12
+ contractAddress: string;
13
+ name: string;
14
+ }
15
+ export interface NFTs {
16
+ [key: number]: NFT[];
17
+ }
18
+ export declare const NFTS: NFTs;
11
19
  export declare function getToken(chain: number, symbol: string): Token;
20
+ export declare function getNFT(chain: number, name: string): NFT;
@@ -1,4 +1,4 @@
1
- export * from './constants/ActionBlocks.js';
1
+ export * from './constants/Blocks.js';
2
2
  export * from './constants/chains.js';
3
3
  export * from './constants/tokens.js';
4
4
  export * from './models/Action.js';
@@ -6,5 +6,6 @@ export * from './models/Automation.js';
6
6
  export * from './models/Condition.js';
7
7
  export * from './models/Parameter.js';
8
8
  export * from './models/Trigger.js';
9
+ export * from './models/Node.js';
10
+ export * from './models/Edge.js';
9
11
  export * from './services/ApiService.js';
10
- export * from './services/AutomationService.js';
@@ -1,6 +1,12 @@
1
- export interface Action {
2
- key: string;
3
- type: string;
4
- description: string;
5
- value: any;
1
+ import { Parameter } from './Parameter.js';
2
+ import { Node, Position } from './Node.js';
3
+ export declare class Action extends Node {
4
+ constructor(action: {
5
+ id: number;
6
+ name: string;
7
+ description: string;
8
+ parameters: Parameter[];
9
+ ref?: string;
10
+ position?: Position;
11
+ });
6
12
  }
@@ -1,6 +1,23 @@
1
- export interface Automation {
2
- key: string;
3
- type: string;
4
- description: string;
5
- value: any;
1
+ import { Node } from './Node.js';
2
+ import { Edge } from './Edge.js';
3
+ export declare class Automation {
4
+ name: string;
5
+ nodes: Node[];
6
+ edges: Edge[];
7
+ constructor(name: string, nodes?: Node[], edges?: Edge[]);
8
+ setName(name: string): void;
9
+ addNode(node: Node): void;
10
+ addNodes(nodes: Node[]): void;
11
+ addEdge(edge: Edge): void;
12
+ addEdges(edges: Edge[]): void;
13
+ toJSON(): {
14
+ name: string;
15
+ nodes: {
16
+ [key: string]: any;
17
+ }[];
18
+ edges: {
19
+ [key: string]: any;
20
+ }[];
21
+ };
22
+ save(): Promise<any>;
6
23
  }
@@ -0,0 +1,14 @@
1
+ import { Node } from './Node.js';
2
+ export declare class Edge {
3
+ id: string;
4
+ source: Node;
5
+ target: Node;
6
+ constructor(edge: {
7
+ id?: string;
8
+ source: Node;
9
+ target: Node;
10
+ });
11
+ toJSON(): {
12
+ [key: string]: any;
13
+ };
14
+ }
@@ -0,0 +1,42 @@
1
+ import { Parameter } from './Parameter.js';
2
+ export interface Position {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export declare class Node {
7
+ id: number;
8
+ name: string;
9
+ description: string;
10
+ parameters: {
11
+ [key: string]: Parameter;
12
+ };
13
+ keyMap: {
14
+ [key: string]: string;
15
+ };
16
+ position?: Position;
17
+ ref: string;
18
+ class: string;
19
+ constructor(node: {
20
+ id: number;
21
+ name: string;
22
+ description: string;
23
+ parameters: Parameter[];
24
+ ref?: string;
25
+ position?: Position;
26
+ class: string;
27
+ });
28
+ setChainId(value: number): void;
29
+ setContractAddress(value: string): void;
30
+ setParams(key: string, value: any): void;
31
+ setPosition(x: number, y: number): void;
32
+ getRef(): string;
33
+ protected setParameter(key: string, value: any): void;
34
+ getParameter(key: string): any;
35
+ getParameters(): {
36
+ [key: string]: any;
37
+ };
38
+ toJSON(): {
39
+ [key: string]: any;
40
+ };
41
+ private getSimplifiedKey;
42
+ }
@@ -1,37 +1,17 @@
1
1
  import { Parameter } from './Parameter.js';
2
- export declare class Trigger {
3
- id: number;
4
- name: string;
5
- description: string;
2
+ import { Node, Position } from './Node.js';
3
+ export declare class Trigger extends Node {
6
4
  type: number;
7
- parameters: {
8
- [key: string]: Parameter;
9
- };
10
- keyMap: {
11
- [key: string]: string;
12
- };
13
5
  constructor(trigger: {
14
6
  id: number;
15
7
  name: string;
16
8
  description: string;
17
9
  type: number;
18
10
  parameters: Parameter[];
11
+ ref?: string;
12
+ position?: Position;
19
13
  });
20
- setChainId(value: number): void;
21
- setContractAddress(value: string): void;
22
14
  setCondition(value: string): void;
23
15
  setComparisonValue(value: number): void;
24
16
  setInterval(value: number): void;
25
- setParams(key: string, value: any): void;
26
- private setParameter;
27
- private validateType;
28
- private isAddress;
29
- getParameter(key: string): any;
30
- getParameters(): {
31
- [key: string]: any;
32
- };
33
- toJSON(): {
34
- [key: string]: any;
35
- };
36
- private getSimplifiedKey;
37
17
  }
@@ -1,6 +1,3 @@
1
- export interface APISERVICES {
2
- key: string;
3
- type: string;
4
- description: string;
5
- value: any;
6
- }
1
+ export declare const apiServices: {
2
+ post(endpoint: string, data: any): Promise<any>;
3
+ };
@@ -0,0 +1,4 @@
1
+ export declare function validateType(expectedType: string, value: any): boolean;
2
+ export declare function isAddress(value: string): boolean;
3
+ export declare function isValidUrl(value: string): boolean;
4
+ export declare function isValidPhoneNumber(value: string): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { ACTIONS, getToken, CHAINS, Action } from '../src/index.js';
2
+
3
+ const createAction = () => {
4
+ // Create an ERC20 transfer action
5
+ const transferAction = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
6
+ transferAction.setChainId(CHAINS.ETHEREUM);
7
+ transferAction.setParams("value", 1000);
8
+ transferAction.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
9
+ transferAction.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
10
+
11
+ console.log(transferAction.toJSON());
12
+
13
+ // Create an SMS notification action
14
+ const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
15
+ smsAction.setParams("phoneNumber", "+1234567890");
16
+ smsAction.setParams("text", "This is a test message");
17
+
18
+ console.log(smsAction.toJSON());
19
+
20
+ // Create a Slack notification action
21
+ const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK);
22
+ slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
23
+ slackAction.setParams("text", "This is a test message");
24
+
25
+ console.log(slackAction.toJSON());
26
+ };
27
+
28
+ createAction();
@@ -0,0 +1,41 @@
1
+ import { ACTIONS, Action, TRIGGERS, Trigger, Automation, CHAINS, getToken, Edge } from '../src/index.js';
2
+
3
+ const main = async () => {
4
+ const usdcTransferTrigger = new Trigger({
5
+ id: TRIGGERS.TOKENS.ERC20.TRANSFER.id,
6
+ name: TRIGGERS.TOKENS.ERC20.TRANSFER.name,
7
+ description: TRIGGERS.TOKENS.ERC20.TRANSFER.description,
8
+ type: TRIGGERS.TOKENS.ERC20.TRANSFER.type,
9
+ parameters: TRIGGERS.TOKENS.ERC20.TRANSFER.parameters,
10
+ ref: 'n-1',
11
+ });
12
+ usdcTransferTrigger.setChainId(CHAINS.ETHEREUM);
13
+ usdcTransferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
14
+ usdcTransferTrigger.setPosition(0, 0);
15
+
16
+ const slackAction = new Action({
17
+ id: ACTIONS.NOTIFICATIONS.SLACK.id,
18
+ name: ACTIONS.NOTIFICATIONS.SLACK.name,
19
+ description: ACTIONS.NOTIFICATIONS.SLACK.description,
20
+ parameters: ACTIONS.NOTIFICATIONS.SLACK.parameters,
21
+ // not forced to provide a ref id, it will generate it
22
+ });
23
+ slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
24
+ slackAction.setParams("text", "USDC has been transferred!");
25
+ slackAction.setPosition(0, -10);
26
+
27
+ const automation = new Automation("USDC Transfer Notification", [usdcTransferTrigger, slackAction]);
28
+
29
+ const edge = new Edge({
30
+ source: usdcTransferTrigger,
31
+ target: slackAction,
32
+ });
33
+
34
+ automation.addEdge(edge);
35
+
36
+ console.log(JSON.stringify(automation.toJSON(), null, 2));
37
+
38
+ //await automation.save();
39
+ }
40
+
41
+ main();
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "An SDK for building and managing automations on Otomato",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/types/src/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "build": "npx tsc",
10
- "test": "mocha --config .mocharc.json"
10
+ "test": "mocha --config .mocharc.json",
11
+ "publish": "npm publish"
11
12
  },
12
13
  "keywords": [
13
14
  "sdk",
@@ -34,4 +35,4 @@
34
35
  "axios": "^1.7.2",
35
36
  "ethers": "^6.13.0"
36
37
  }
37
- }
38
+ }
@@ -18,7 +18,7 @@ export const TRIGGERS = {
18
18
  parameters: [
19
19
  {
20
20
  key: "chainId",
21
- type: "int",
21
+ type: "chainId",
22
22
  description: "Chain ID of the ETH blockchain"
23
23
  },
24
24
  {
@@ -46,7 +46,7 @@ export const TRIGGERS = {
46
46
  parameters: [
47
47
  {
48
48
  key: "chainId",
49
- type: "int",
49
+ type: "chainId",
50
50
  description: "Chain ID of the ETH blockchain"
51
51
  },
52
52
  {
@@ -322,3 +322,74 @@ export const TRIGGERS = {
322
322
  }
323
323
  }
324
324
  };
325
+
326
+ export const ACTIONS = {
327
+ TOKENS: {
328
+ ERC20: {
329
+ CHAINS: [CHAINS.ALL],
330
+ TRANSFER: {
331
+ id: 1,
332
+ name: "Transfer ERC-20 Token",
333
+ description: "Transfer an ERC-20 token",
334
+ parameters: [
335
+ {
336
+ key: "chainId",
337
+ type: "chainId",
338
+ description: "Chain ID of the blockchain"
339
+ },
340
+ {
341
+ key: "abiParams.value",
342
+ type: "uint256",
343
+ description: "Amount of crypto to transfer"
344
+ },
345
+ {
346
+ key: "abiParams.to",
347
+ type: "address",
348
+ description: "Address to transfer crypto to"
349
+ },
350
+ {
351
+ key: "contractAddress",
352
+ type: "address",
353
+ description: "The contract address of the ERC-20 token"
354
+ }
355
+ ] as Parameter[]
356
+ },
357
+ },
358
+ },
359
+ NOTIFICATIONS: {
360
+ SMS: {
361
+ id: 3,
362
+ name: "Send SMS",
363
+ description: "Send an SMS notification to a specified phone number",
364
+ parameters: [
365
+ {
366
+ key: "phoneNumber",
367
+ type: "phone_number",
368
+ description: "Phone number to send the message to"
369
+ },
370
+ {
371
+ key: "text",
372
+ type: "paragraph",
373
+ description: "Content of the SMS message"
374
+ },
375
+ ] as Parameter[]
376
+ },
377
+ SLACK: {
378
+ id: 4,
379
+ name: "Send Slack Message",
380
+ description: "Send a message to a specified Slack channel via webhook",
381
+ parameters: [
382
+ {
383
+ key: "webhook",
384
+ type: "url",
385
+ description: "Slack channel webhook URL"
386
+ },
387
+ {
388
+ key: "text",
389
+ type: "paragraph",
390
+ description: "Content of the Slack message"
391
+ },
392
+ ] as Parameter[]
393
+ },
394
+ }
395
+ };
@@ -2,4 +2,4 @@ export const CHAINS = {
2
2
  ALL: 0,
3
3
  ETHEREUM: 1,
4
4
  MODE: 43334,
5
- };
5
+ };
@@ -0,0 +1,16 @@
1
+ {
2
+ "id": 1,
3
+ "refId": "n-1",
4
+ "data": {
5
+ "parameters": {
6
+ "chainId": 1,
7
+ "abiParams.value": null,
8
+ "abiParams.to": null,
9
+ "contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
10
+ },
11
+ },
12
+ "position": {
13
+ "x": 0,
14
+ "y": 0
15
+ }
16
+ }
@@ -82,6 +82,48 @@ export const TOKENS: Tokens = {
82
82
  ]
83
83
  };
84
84
 
85
+ export interface NFT {
86
+ contractAddress: string;
87
+ name: string;
88
+ }
89
+
90
+ export interface NFTs {
91
+ [key: number]: NFT[];
92
+ }
93
+
94
+ export const NFTS: NFTs = {
95
+ 1: [
96
+ {
97
+ contractAddress: "0x60e4d786628fea6478f785a6d7e704777c86a7c6",
98
+ name: "MutantApeYachtClub"
99
+ },
100
+ {
101
+ contractAddress: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
102
+ name: "BoredApeYachtClub"
103
+ },
104
+
105
+ {
106
+ contractAddress: "0xbd3531da5cf5857e7cfaa92426877b022e612cf8",
107
+ name: "Pudgy Penguins"
108
+ },
109
+ {
110
+ contractAddress: "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
111
+ name: "Doodles"
112
+ },
113
+ {
114
+ contractAddress: "0x524cab2ec69124574082676e6f654a18df49a048",
115
+ name: "Lil Pudgies"
116
+ },
117
+
118
+ ],
119
+ 43334: [
120
+ {
121
+ contractAddress: "0x2ad86eeec513ac16804bb05310214c3fd496835b",
122
+ name: "Space id"
123
+ }
124
+ ]
125
+ };
126
+
85
127
  export function getToken(chain: number, symbol: string): Token {
86
128
  if (!(chain in TOKENS)) {
87
129
  throw new Error(`Unsupported chain: ${chain}`);
@@ -95,3 +137,17 @@ export function getToken(chain: number, symbol: string): Token {
95
137
 
96
138
  return token;
97
139
  }
140
+
141
+ export function getNFT(chain: number, name: string): NFT {
142
+ if (!(chain in NFTS)) {
143
+ throw new Error(`Unsupported chain: ${chain}`);
144
+ }
145
+
146
+ const nft = NFTS[chain].find(nft => nft.name === name);
147
+
148
+ if (!nft) {
149
+ throw new Error(`NFT ${name} not found on chain ${chain}`);
150
+ }
151
+
152
+ return nft;
153
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Exporting constants
2
- export * from './constants/ActionBlocks.js';
2
+ export * from './constants/Blocks.js';
3
3
  export * from './constants/chains.js';
4
4
  export * from './constants/tokens.js';
5
5
 
@@ -9,7 +9,8 @@ export * from './models/Automation.js';
9
9
  export * from './models/Condition.js';
10
10
  export * from './models/Parameter.js';
11
11
  export * from './models/Trigger.js';
12
+ export * from './models/Node.js';
13
+ export * from './models/Edge.js';
12
14
 
13
15
  // Exporting services
14
16
  export * from './services/ApiService.js';
15
- export * from './services/AutomationService.js';
@@ -1,6 +1,8 @@
1
- export interface Action {
2
- key: string;
3
- type: string;
4
- description: string;
5
- value: any;
6
- }
1
+ import { Parameter } from './Parameter.js';
2
+ import { Node, Position } from './Node.js';
3
+
4
+ export class Action extends Node {
5
+ constructor(action: { id: number; name: string; description: string; parameters: Parameter[], ref?: string, position?: Position }) {
6
+ super({ ...action, class: 'action' });
7
+ }
8
+ }