otomato-sdk 1.5.3 → 1.5.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.
@@ -1,7 +1,3 @@
1
- const TRIGGER_TYPE = {
2
- SUBSCRIPTION: 0,
3
- POLLING: 1,
4
- };
5
1
  export const TRIGGERS = {
6
2
  "TOKENS": {
7
3
  "ERC20": {
@@ -538,6 +534,11 @@ export const ACTIONS = {
538
534
  "description": "The contract address of the ERC20"
539
535
  },
540
536
  ],
537
+ "permissions": {
538
+ "approvedTargets": [
539
+ "$contractAddress"
540
+ ]
541
+ },
541
542
  "blockId": 100004,
542
543
  "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp"
543
544
  }
@@ -1,4 +1,10 @@
1
1
  import { Workflow, Trigger, Action, Edge, TRIGGERS, ACTIONS, CHAINS, getTokenFromSymbol } from '../index.js';
2
+ export const WORKFLOW_TEMPLATES_TAGS = {
3
+ NFTS: 'NFTs',
4
+ SOCIALS: 'Socials',
5
+ TRADING: 'Trading',
6
+ ON_CHAIN_MONITORING: 'On-chain monitoring'
7
+ };
2
8
  const createModeTransferNotificationWorkflow = () => {
3
9
  const modeTransferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
4
10
  modeTransferTrigger.setChainId(CHAINS.MODE);
@@ -7,27 +13,28 @@ const createModeTransferNotificationWorkflow = () => {
7
13
  const telegramAction = new Action(ACTIONS.NOTIFICATIONS.TELEGRAM.SEND_MESSAGE);
8
14
  telegramAction.setParams("message", "0x74B8....C6B4 transferred $MODE");
9
15
  const edge = new Edge({ source: modeTransferTrigger, target: telegramAction });
10
- return new Workflow('Buy ETH when the market sentiment is fearful', [modeTransferTrigger, telegramAction], [edge]);
16
+ return new Workflow('MODE transfer notification', [modeTransferTrigger, telegramAction], [edge]);
11
17
  };
12
18
  const createETHFearAndGreedBuy = () => {
13
19
  const trigger = new Trigger(TRIGGERS.SOCIALS.FEAR_AND_GREED.GET_FEAR_AND_GREED_INDEX);
14
20
  trigger.setCondition('lt');
15
21
  trigger.setComparisonValue(30);
16
- // todo: change to swap
17
22
  const telegramAction = new Action(ACTIONS.NOTIFICATIONS.TELEGRAM.SEND_MESSAGE);
18
- telegramAction.setParams("message", "0x74B8....C6B4 transferred $MODE");
23
+ telegramAction.setParams("message", "The market sentiment is extremely fearful. Consider buying ETH.");
19
24
  const edge = new Edge({ source: trigger, target: telegramAction });
20
- return new Workflow('MODE transfer notification', [trigger, telegramAction], [edge]);
25
+ return new Workflow('Buy ETH when the market sentiment is extremely fearful', [trigger, telegramAction], [edge]);
21
26
  };
22
27
  export const WORKFLOW_TEMPLATES = [
23
28
  {
24
29
  'name': 'MODE transfer notification',
25
30
  'description': 'Receive notifications when a top $MODE holder (0x74B8....C6B4) transfers $MODE',
31
+ 'tags': [WORKFLOW_TEMPLATES_TAGS.ON_CHAIN_MONITORING],
26
32
  createWorkflow: createModeTransferNotificationWorkflow
27
33
  },
28
34
  {
29
- 'name': 'Buy ETH when the market sentiment is fearful',
30
- 'description': 'Buy eth when the bitcoin fear and greed is below 30',
35
+ 'name': 'Buy ETH when the market sentiment is extremely fearful',
36
+ 'description': 'Buy ETH when the Bitcoin Fear and Greed Index is below 30',
37
+ 'tags': [WORKFLOW_TEMPLATES_TAGS.TRADING, WORKFLOW_TEMPLATES_TAGS.SOCIALS],
31
38
  createWorkflow: createETHFearAndGreedBuy
32
39
  },
33
40
  ];
package/dist/src/index.js CHANGED
@@ -11,6 +11,7 @@ export * from './models/Parameter.js';
11
11
  export * from './models/Trigger.js';
12
12
  export * from './models/Node.js';
13
13
  export * from './models/Edge.js';
14
+ export * from './models/SessionKeyPermission.js';
14
15
  // Exporting services
15
16
  export * from './services/ApiService.js';
16
17
  export * from './utils/helpers.js';
@@ -10,12 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { Node } from './Node.js';
11
11
  import { ACTIONS } from '../constants/Blocks.js';
12
12
  import { typeIsNumber } from '../utils/typeValidator.js';
13
+ import { SessionKeyPermission } from './SessionKeyPermission.js';
13
14
  export class Action extends Node {
14
15
  constructor(action) {
15
16
  super(Object.assign(Object.assign({}, action), { class: 'action', parentInfo: findActionByBlockId(action.blockId).parentInfo }));
16
17
  }
17
- getStaticParameters() {
18
- return null;
18
+ getSessionKeyPermissions() {
19
+ const parentBlock = findActionByBlockId(this.blockId).block;
20
+ if (!parentBlock.permissions)
21
+ return null;
22
+ const permissions = SessionKeyPermission.fromJSON(parentBlock.permissions);
23
+ permissions.fill('contractAddress', this.getParameter('contractAddress'));
24
+ return permissions;
19
25
  }
20
26
  static fromJSON(json) {
21
27
  return __awaiter(this, void 0, void 0, function* () {
@@ -44,9 +50,6 @@ export class Action extends Node {
44
50
  }
45
51
  }
46
52
  break;
47
- case 'interval':
48
- // ignore
49
- break;
50
53
  default:
51
54
  action.setParams(key, value);
52
55
  break;
@@ -105,9 +105,6 @@ export class Node {
105
105
  return acc;
106
106
  }, {});
107
107
  }
108
- getStaticParameters() {
109
- return null;
110
- }
111
108
  toJSON() {
112
109
  const serializeBigInt = (key, value) => {
113
110
  if (typeof value === 'bigint') {
@@ -124,14 +121,13 @@ export class Node {
124
121
  return value;
125
122
  }
126
123
  };
127
- const staticParameters = this.getStaticParameters() || {};
128
124
  const json = {
129
125
  id: this.id,
130
126
  ref: this.ref,
131
127
  blockId: this.blockId,
132
128
  type: this.class,
133
129
  state: this.state,
134
- parameters: Object.assign(Object.assign({}, this.getParameters()), staticParameters),
130
+ parameters: Object.assign({}, this.getParameters()),
135
131
  };
136
132
  if (this.position) {
137
133
  json.position = this.position;
@@ -0,0 +1,47 @@
1
+ export class SessionKeyPermission {
2
+ constructor(approvedTargets = []) {
3
+ if (!Array.isArray(approvedTargets)) {
4
+ console.error('approvedTargets should be an array. Received:', approvedTargets);
5
+ approvedTargets = [];
6
+ }
7
+ this.approvedTargets = approvedTargets;
8
+ }
9
+ fill(key, value) {
10
+ if (!Array.isArray(this.approvedTargets)) {
11
+ console.error('approvedTargets is not an array. Cannot call map on:', this.approvedTargets);
12
+ return;
13
+ }
14
+ this.approvedTargets = this.approvedTargets.map(target => {
15
+ const placeholder = `$${key}`;
16
+ if (typeof target === 'string' && target.includes(placeholder)) {
17
+ target = target.replace(placeholder, value);
18
+ }
19
+ return target;
20
+ });
21
+ }
22
+ toJSON() {
23
+ const containsPlaceholder = this.approvedTargets.some(target => typeof target === 'string' && target.includes('$'));
24
+ if (containsPlaceholder) {
25
+ throw new Error('Approved targets contain unresolved placeholders.');
26
+ }
27
+ return {
28
+ approvedTargets: this.approvedTargets,
29
+ };
30
+ }
31
+ static fromJSON(json) {
32
+ if (!json || !Array.isArray(json.approvedTargets)) {
33
+ console.error('Invalid JSON object for SessionKeyPermission:', json);
34
+ throw new Error('Invalid JSON object for SessionKeyPermission');
35
+ }
36
+ return new SessionKeyPermission(json.approvedTargets);
37
+ }
38
+ merge(other) {
39
+ if (!other || !Array.isArray(other.approvedTargets)) {
40
+ console.error('Invalid SessionKeyPermission object to merge:', other);
41
+ return;
42
+ }
43
+ const uniqueTargets = new Set(this.approvedTargets);
44
+ other.approvedTargets.forEach(target => uniqueTargets.add(target));
45
+ this.approvedTargets = Array.from(uniqueTargets);
46
+ }
47
+ }
@@ -30,12 +30,6 @@ export class Trigger extends Node {
30
30
  }
31
31
  this.setParameter('comparisonValue', value);
32
32
  }
33
- getStaticParameters() {
34
- if (!this.notAPollingTrigger()) {
35
- return { interval: 5000 };
36
- }
37
- return null;
38
- }
39
33
  static fromJSON(json) {
40
34
  return __awaiter(this, void 0, void 0, function* () {
41
35
  const enriched = findTriggerByBlockId(json.blockId);
@@ -69,9 +63,6 @@ export class Trigger extends Node {
69
63
  }
70
64
  }
71
65
  break;
72
- case 'interval':
73
- // ignore
74
- break;
75
66
  default:
76
67
  trigger.setParams(key, value);
77
68
  break;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { Node } from './Node.js';
11
11
  import { Edge } from './Edge.js';
12
12
  import { apiServices } from '../services/ApiService.js';
13
+ import { SessionKeyPermission } from './SessionKeyPermission.js';
13
14
  export class Workflow {
14
15
  constructor(name = '', nodes = [], edges = []) {
15
16
  this.id = null;
@@ -191,4 +192,21 @@ export class Workflow {
191
192
  }
192
193
  });
193
194
  }
195
+ getSessionKeyPermissions() {
196
+ const permissions = new SessionKeyPermission();
197
+ for (const node of this.nodes) {
198
+ try {
199
+ if (node.class === 'action' && 'getSessionKeyPermissions' in node) {
200
+ const nodePermissions = node.getSessionKeyPermissions();
201
+ if (nodePermissions) {
202
+ permissions.merge(nodePermissions);
203
+ }
204
+ }
205
+ }
206
+ catch (error) {
207
+ console.error(`Error getting session key permissions for node ${node.getRef()}:`, error);
208
+ }
209
+ }
210
+ return permissions;
211
+ }
194
212
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -197,6 +197,9 @@ export declare const ACTIONS: {
197
197
  type: number;
198
198
  method: string;
199
199
  parameters: Parameter[];
200
+ permissions: {
201
+ approvedTargets: string[];
202
+ };
200
203
  blockId: number;
201
204
  image: string;
202
205
  };
@@ -1,6 +1,13 @@
1
1
  import { Workflow } from '../index.js';
2
+ export declare const WORKFLOW_TEMPLATES_TAGS: {
3
+ NFTS: string;
4
+ SOCIALS: string;
5
+ TRADING: string;
6
+ ON_CHAIN_MONITORING: string;
7
+ };
2
8
  export declare const WORKFLOW_TEMPLATES: {
3
9
  name: string;
4
10
  description: string;
11
+ tags: string[];
5
12
  createWorkflow: () => Workflow;
6
13
  }[];
@@ -9,6 +9,7 @@ export * from './models/Parameter.js';
9
9
  export * from './models/Trigger.js';
10
10
  export * from './models/Node.js';
11
11
  export * from './models/Edge.js';
12
+ export * from './models/SessionKeyPermission.js';
12
13
  export * from './services/ApiService.js';
13
14
  export * from './utils/helpers.js';
14
15
  export * from './utils/typeValidator.js';
@@ -1,5 +1,6 @@
1
1
  import { Parameter } from './Parameter.js';
2
2
  import { Node, ParentInfo, Position, NodeState } from './Node.js';
3
+ import { SessionKeyPermission } from './SessionKeyPermission.js';
3
4
  export declare class Action extends Node {
4
5
  constructor(action: {
5
6
  blockId: number;
@@ -12,7 +13,7 @@ export declare class Action extends Node {
12
13
  parentInfo?: ParentInfo;
13
14
  state?: NodeState;
14
15
  });
15
- getStaticParameters(): null;
16
+ getSessionKeyPermissions(): SessionKeyPermission | null;
16
17
  static fromJSON(json: {
17
18
  [key: string]: any;
18
19
  }): Promise<Action>;
@@ -51,9 +51,6 @@ export declare abstract class Node {
51
51
  getParameters(): {
52
52
  [key: string]: any;
53
53
  };
54
- getStaticParameters(): {
55
- [key: string]: any;
56
- } | null;
57
54
  toJSON(): {
58
55
  [key: string]: any;
59
56
  };
@@ -0,0 +1,12 @@
1
+ export declare class SessionKeyPermission {
2
+ approvedTargets: string[];
3
+ constructor(approvedTargets?: string[]);
4
+ fill(key: string, value: any): void;
5
+ toJSON(): {
6
+ [key: string]: any;
7
+ };
8
+ static fromJSON(json: {
9
+ [key: string]: any;
10
+ }): SessionKeyPermission;
11
+ merge(other: SessionKeyPermission): void;
12
+ }
@@ -17,9 +17,6 @@ export declare class Trigger extends Node {
17
17
  private notAPollingTrigger;
18
18
  setCondition(value: string): void;
19
19
  setComparisonValue(value: number): void;
20
- getStaticParameters(): {
21
- interval: number;
22
- } | null;
23
20
  static fromJSON(json: {
24
21
  [key: string]: any;
25
22
  }): Promise<Trigger>;
@@ -1,5 +1,6 @@
1
1
  import { Node } from './Node.js';
2
2
  import { Edge } from './Edge.js';
3
+ import { SessionKeyPermission } from './SessionKeyPermission.js';
3
4
  export type WorkflowState = 'inactive' | 'active' | 'failed' | 'completed';
4
5
  export declare class Workflow {
5
6
  id: string | null;
@@ -44,4 +45,5 @@ export declare class Workflow {
44
45
  success: boolean;
45
46
  error?: string;
46
47
  }>;
48
+ getSessionKeyPermissions(): SessionKeyPermission;
47
49
  }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
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",