otomato-sdk 1.2.0 → 1.2.1

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.
@@ -68,7 +68,16 @@ export class Node {
68
68
  }
69
69
  getParameters() {
70
70
  return Object.keys(this.parameters).reduce((acc, key) => {
71
- acc[key] = this.parameters[key].value;
71
+ if (key.startsWith('abiParams.')) {
72
+ const abiKey = key.replace('abiParams.', '');
73
+ if (!acc.abi) {
74
+ acc.abi = { parameters: {} };
75
+ }
76
+ acc.abi.parameters[abiKey] = this.parameters[key].value;
77
+ }
78
+ else {
79
+ acc[key] = this.parameters[key].value;
80
+ }
72
81
  return acc;
73
82
  }, {});
74
83
  }
@@ -77,9 +86,7 @@ export class Node {
77
86
  id: this.id,
78
87
  ref: this.ref,
79
88
  type: this.class,
80
- data: {
81
- parameters: this.getParameters(),
82
- }
89
+ parameters: this.getParameters(),
83
90
  };
84
91
  if (this.position) {
85
92
  json.position = this.position;
@@ -4,20 +4,23 @@ export class Trigger extends Node {
4
4
  super(Object.assign(Object.assign({}, trigger), { class: 'trigger' }));
5
5
  this.type = trigger.type;
6
6
  }
7
+ notAPollingTrigger() {
8
+ return this.type === 0;
9
+ }
7
10
  setCondition(value) {
8
- if (this.type !== 1) {
11
+ if (this.notAPollingTrigger()) {
9
12
  throw new Error('Condition setting is not applicable for subscription based triggers.');
10
13
  }
11
14
  this.setParameter('condition', value);
12
15
  }
13
16
  setComparisonValue(value) {
14
- if (this.type !== 1) {
17
+ if (this.notAPollingTrigger()) {
15
18
  throw new Error('Comparison value setting is not applicable for subscription based triggers.');
16
19
  }
17
20
  this.setParameter('comparisonValue', value);
18
21
  }
19
22
  setInterval(value) {
20
- if (this.type !== 1) {
23
+ if (this.notAPollingTrigger()) {
21
24
  throw new Error('Interval setting is not applicable for subscription based triggers.');
22
25
  }
23
26
  this.setParameter('interval', value);
@@ -33,10 +33,11 @@ export function validateType(expectedType, value) {
33
33
  return typeof value === 'string' && isValidUrl(value);
34
34
  case 'phone_number':
35
35
  return typeof value === 'string' && isValidPhoneNumber(value);
36
+ case 'string':
36
37
  case 'paragraph':
37
38
  return typeof value === 'string';
38
39
  case 'logic_operator':
39
- const validOperators = new Set(['<', '>', '<=', '>=', '==', '!=']);
40
+ const validOperators = new Set(['gte', 'gt', 'lte', 'lt', 'eq', 'neq']);
40
41
  return typeof value === 'string' && validOperators.has(value);
41
42
  case 'any':
42
43
  return true;
@@ -31,6 +31,8 @@ describe('Action Class', () => {
31
31
  const json = transferAction.toJSON();
32
32
  expect(json).to.deep.equal({
33
33
  id: ACTIONS.TOKENS.ERC20.TRANSFER.id,
34
+ ref: transferAction.getRef(),
35
+ type: 'action',
34
36
  parameters: {
35
37
  chainId: CHAINS.ETHEREUM,
36
38
  'abiParams.value': 1000,
@@ -39,21 +41,22 @@ describe('Action Class', () => {
39
41
  }
40
42
  });
41
43
  });
42
- it('should create an SMS action and set parameters correctly', () => {
43
- const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
44
- smsAction.setParams("phoneNumber", "+1234567890");
45
- smsAction.setParams("text", "Hello, this is a test message!");
46
- const params = smsAction.getParameters();
47
- expect(params.phoneNumber).to.equal("+1234567890");
48
- expect(params.text).to.equal("Hello, this is a test message!");
49
- });
44
+ /*it('should create an SMS action and set parameters correctly', () => {
45
+ const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
46
+ smsAction.setParams("phoneNumber", "+1234567890");
47
+ smsAction.setParams("text", "Hello, this is a test message!");
48
+
49
+ const params = smsAction.getParameters();
50
+ expect(params.phoneNumber).to.equal("+1234567890");
51
+ expect(params.text).to.equal("Hello, this is a test message!");
52
+ });*/
50
53
  it('should create a Slack action and set parameters correctly', () => {
51
- const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK);
54
+ const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
52
55
  slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
53
- slackAction.setParams("text", "This is a test message!");
56
+ slackAction.setParams("message", "This is a test message!");
54
57
  const params = slackAction.getParameters();
55
58
  expect(params.webhook).to.equal("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
56
- expect(params.text).to.equal("This is a test message!");
59
+ expect(params.message).to.equal("This is a test message!");
57
60
  });
58
61
  it('should throw an error for invalid parameter type', () => {
59
62
  const transferAction = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
@@ -64,11 +67,11 @@ describe('Action Class', () => {
64
67
  expect(() => transferAction.setParams("to", "invalid_address")).to.throw('Invalid type for parameter abiParams.to. Expected address.');
65
68
  });
66
69
  it('should throw an error for invalid URL', () => {
67
- const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK);
70
+ const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
68
71
  expect(() => slackAction.setParams("webhook", "invalid_url")).to.throw('Invalid type for parameter webhook. Expected url.');
69
72
  });
70
- it('should throw an error for invalid phone number', () => {
71
- const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
72
- expect(() => smsAction.setParams("phoneNumber", "invalid_phone_number")).to.throw('Invalid type for parameter phoneNumber. Expected phone_number.');
73
- });
73
+ /*it('should throw an error for invalid phone number', () => {
74
+ const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
75
+ expect(() => smsAction.setParams("phoneNumber", "invalid_phone_number")).to.throw('Invalid type for parameter phoneNumber. Expected phone_number.');
76
+ });*/
74
77
  });
@@ -15,15 +15,16 @@ describe('Automation Class', () => {
15
15
  action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
16
16
  action1.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
17
17
  action1.setPosition(1, 0);
18
- const action2 = new Action(ACTIONS.NOTIFICATIONS.SMS);
19
- action2.setParams("phoneNumber", "+1234567890");
20
- action2.setParams("text", "This is a test message");
18
+ const action2 = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
19
+ action2.setParams("webhook", "https://webhook.url");
20
+ action2.setParams("message", "This is a test message");
21
21
  action2.setPosition(2, 0);
22
22
  const automation = new Automation("Test Automation", [trigger, action1, action2]);
23
23
  const json = automation.toJSON();
24
24
  expect(json).to.deep.equal({
25
25
  name: "Test Automation",
26
26
  nodes: [trigger.toJSON(), action1.toJSON(), action2.toJSON()],
27
+ edges: []
27
28
  });
28
29
  });
29
30
  it('should set the name of the automation', () => {
@@ -59,9 +60,9 @@ describe('Automation Class', () => {
59
60
  action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
60
61
  action1.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
61
62
  action1.setPosition(1, 0);
62
- const action2 = new Action(ACTIONS.NOTIFICATIONS.SMS);
63
- action2.setParams("phoneNumber", "+1234567890");
64
- action2.setParams("text", "This is a test message");
63
+ const action2 = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
64
+ action2.setParams("webhook", "https://webhook.url");
65
+ action2.setParams("message", "This is a test message");
65
66
  action2.setPosition(2, 0);
66
67
  const automation = new Automation("Test Automation", [trigger]);
67
68
  automation.addNode(action1);
@@ -69,12 +69,10 @@ describe('Node Class', () => {
69
69
  expect(json).to.deep.equal({
70
70
  id: 5,
71
71
  ref: node.getRef(),
72
- class: 'testClass',
73
- data: {
74
- parameters: {
75
- chainId: 1,
76
- contractAddress: "0x0000000000000000000000000000000000000000"
77
- }
72
+ type: 'testClass',
73
+ parameters: {
74
+ chainId: 1,
75
+ contractAddress: "0x0000000000000000000000000000000000000000"
78
76
  }
79
77
  });
80
78
  });
@@ -91,14 +89,12 @@ describe('Node Class', () => {
91
89
  node.setContractAddress("0x0000000000000000000000000000000000000000");
92
90
  const json = node.toJSON();
93
91
  expect(json).to.deep.equal({
92
+ type: 'testClass',
94
93
  id: 6,
95
94
  ref: node.getRef(),
96
- class: 'testClass',
97
- data: {
98
- parameters: {
99
- chainId: 1,
100
- contractAddress: "0x0000000000000000000000000000000000000000"
101
- }
95
+ parameters: {
96
+ chainId: 1,
97
+ contractAddress: "0x0000000000000000000000000000000000000000"
102
98
  },
103
99
  position: { x: 1, y: 2 }
104
100
  });
@@ -29,12 +29,16 @@ describe('Trigger Class', () => {
29
29
  transferTrigger.setParams("to", DEFAULT_ADDRESS);
30
30
  transferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
31
31
  const json = transferTrigger.toJSON();
32
+ console.log(json);
32
33
  expect(json).to.deep.equal({
33
34
  id: TRIGGERS.TOKENS.ERC20.TRANSFER.id,
35
+ ref: transferTrigger.getRef(),
36
+ type: 'trigger',
34
37
  parameters: {
35
38
  chainId: CHAINS.ETHEREUM,
36
39
  'abiParams.value': 1000,
37
40
  'abiParams.to': DEFAULT_ADDRESS,
41
+ 'abiParams.from': null,
38
42
  contractAddress: getToken(CHAINS.ETHEREUM, 'USDC').contractAddress
39
43
  }
40
44
  });
@@ -44,14 +48,15 @@ describe('Trigger Class', () => {
44
48
  balanceTrigger.setChainId(CHAINS.ETHEREUM);
45
49
  balanceTrigger.setParams("account", DEFAULT_ADDRESS);
46
50
  balanceTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
47
- balanceTrigger.setCondition(">");
51
+ balanceTrigger.setCondition("gte");
48
52
  balanceTrigger.setComparisonValue(45000);
49
53
  balanceTrigger.setInterval(5000);
50
54
  const params = balanceTrigger.getParameters();
51
55
  expect(params.chainId).to.equal(CHAINS.ETHEREUM);
52
56
  expect(params['abiParams.account']).to.equal(DEFAULT_ADDRESS);
53
57
  expect(params.contractAddress).to.equal(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
54
- expect(balanceTrigger.toJSON().parameters.condition).to.equal(">");
58
+ console.log(balanceTrigger.toJSON());
59
+ expect(balanceTrigger.toJSON().parameters.condition).to.equal("gte");
55
60
  expect(balanceTrigger.toJSON().parameters.comparisonValue).to.equal(45000);
56
61
  expect(balanceTrigger.toJSON().parameters.interval).to.equal(5000);
57
62
  });
@@ -47,7 +47,8 @@ describe('Type Validator Utility Functions', () => {
47
47
  expect(validateType('paragraph', 12345)).to.be.false;
48
48
  });
49
49
  it('should validate logic operators', () => {
50
- expect(validateType('logic_operator', '>')).to.be.true;
50
+ expect(validateType('logic_operator', 'gte')).to.be.true;
51
+ expect(validateType('logic_operator', '>')).to.be.false;
51
52
  expect(validateType('logic_operator', 'invalid_operator')).to.be.false;
52
53
  });
53
54
  it('should validate any type', () => {
@@ -0,0 +1 @@
1
+ export {};
@@ -15,6 +15,8 @@ export declare const TRIGGERS: {
15
15
  name: string;
16
16
  description: string;
17
17
  type: number;
18
+ method: string;
19
+ handler: string;
18
20
  parameters: Parameter[];
19
21
  };
20
22
  };
@@ -27,6 +29,7 @@ export declare const TRIGGERS: {
27
29
  name: string;
28
30
  description: string;
29
31
  type: number;
32
+ contractAddress: string;
30
33
  parameters: Parameter[];
31
34
  };
32
35
  LIQUIDITY_REMOVED: {
@@ -34,6 +37,7 @@ export declare const TRIGGERS: {
34
37
  name: string;
35
38
  description: string;
36
39
  type: number;
40
+ contractAddress: string;
37
41
  parameters: Parameter[];
38
42
  };
39
43
  MARKET_CREATION: {
@@ -41,6 +45,7 @@ export declare const TRIGGERS: {
41
45
  name: string;
42
46
  description: string;
43
47
  type: number;
48
+ contractAddress: string;
44
49
  parameters: Parameter[];
45
50
  };
46
51
  INTEREST_RATE_UPDATE: {
@@ -48,6 +53,7 @@ export declare const TRIGGERS: {
48
53
  name: string;
49
54
  description: string;
50
55
  type: number;
56
+ contractAddress: string;
51
57
  parameters: Parameter[];
52
58
  };
53
59
  };
@@ -60,6 +66,7 @@ export declare const TRIGGERS: {
60
66
  name: string;
61
67
  description: string;
62
68
  type: number;
69
+ contractAddress: string;
63
70
  parameters: Parameter[];
64
71
  };
65
72
  };
@@ -72,6 +79,7 @@ export declare const TRIGGERS: {
72
79
  name: string;
73
80
  description: string;
74
81
  type: number;
82
+ contractAddress: string;
75
83
  parameters: Parameter[];
76
84
  };
77
85
  };
@@ -80,6 +88,19 @@ export declare const TRIGGERS: {
80
88
  MODE_NAME_SERVICE: {
81
89
  CHAINS: number[];
82
90
  NAME_REGISTERED: {
91
+ id: number;
92
+ name: string;
93
+ description: string;
94
+ type: number;
95
+ contractAddress: string;
96
+ parameters: Parameter[];
97
+ };
98
+ };
99
+ };
100
+ PRICE_ACTION: {
101
+ ON_CHAIN_PRICE_MOVEMENT: {
102
+ CHAINS: number[];
103
+ PRICE_MOVEMENT_AGAINST_CURRENCY: {
83
104
  id: number;
84
105
  name: string;
85
106
  description: string;
@@ -90,6 +111,35 @@ export declare const TRIGGERS: {
90
111
  };
91
112
  };
92
113
  export declare const ACTIONS: {
114
+ NOTIFICATIONS: {
115
+ SLACK: {
116
+ SEND_MESSAGE: {
117
+ id: number;
118
+ name: string;
119
+ type: number;
120
+ description: string;
121
+ parameters: Parameter[];
122
+ };
123
+ };
124
+ DISCORD: {
125
+ SEND_MESSAGE: {
126
+ id: number;
127
+ name: string;
128
+ type: number;
129
+ description: string;
130
+ parameters: Parameter[];
131
+ };
132
+ };
133
+ TELEGRAM: {
134
+ SEND_MESSAGE: {
135
+ id: number;
136
+ name: string;
137
+ type: number;
138
+ description: string;
139
+ parameters: Parameter[];
140
+ };
141
+ };
142
+ };
93
143
  TOKENS: {
94
144
  ERC20: {
95
145
  CHAINS: number[];
@@ -97,22 +147,10 @@ export declare const ACTIONS: {
97
147
  id: number;
98
148
  name: string;
99
149
  description: string;
150
+ type: number;
151
+ method: string;
100
152
  parameters: Parameter[];
101
153
  };
102
154
  };
103
155
  };
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
156
  };
@@ -2,5 +2,5 @@ export interface Parameter {
2
2
  key: string;
3
3
  type: string;
4
4
  description: string;
5
- value: any;
5
+ value?: any;
6
6
  }
@@ -11,6 +11,7 @@ export declare class Trigger extends Node {
11
11
  ref?: string;
12
12
  position?: Position;
13
13
  });
14
+ private notAPollingTrigger;
14
15
  setCondition(value: string): void;
15
16
  setComparisonValue(value: number): void;
16
17
  setInterval(value: number): void;
@@ -11,14 +11,14 @@ const createAction = () => {
11
11
  console.log(transferAction.toJSON());
12
12
 
13
13
  // Create an SMS notification action
14
- const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
14
+ const smsAction = new Action(ACTIONS.NOTIFICATIONS.DISCORD.SEND_MESSAGE);
15
15
  smsAction.setParams("phoneNumber", "+1234567890");
16
16
  smsAction.setParams("text", "This is a test message");
17
17
 
18
18
  console.log(smsAction.toJSON());
19
19
 
20
20
  // Create a Slack notification action
21
- const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK);
21
+ const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
22
22
  slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
23
23
  slackAction.setParams("text", "This is a test message");
24
24
 
@@ -13,15 +13,9 @@ const main = async () => {
13
13
  usdcTransferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
14
14
  usdcTransferTrigger.setPosition(0, 0);
15
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
- });
16
+ const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
23
17
  slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
24
- slackAction.setParams("text", "USDC has been transferred!");
18
+ slackAction.setParams("message", "USDC has been transferred!");
25
19
  slackAction.setPosition(0, -10);
26
20
 
27
21
  const automation = new Automation("USDC Transfer Notification", [usdcTransferTrigger, slackAction]);
@@ -6,7 +6,7 @@ const transferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
6
6
 
7
7
  transferTrigger.setChainId(CHAINS.ETHEREUM);
8
8
  // transferTrigger.setParams("value", 1000);
9
- // transferTrigger.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
9
+ transferTrigger.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
10
10
  transferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
11
11
 
12
- console.log(transferTrigger.toJSON());
12
+ console.log(JSON.stringify(transferTrigger.toJSON(), null, 2));
@@ -0,0 +1,12 @@
1
+ import { TRIGGERS, getToken, CHAINS, Trigger } from '../src/index.js';
2
+
3
+ const trigger = new Trigger(TRIGGERS.PRICE_ACTION.ON_CHAIN_PRICE_MOVEMENT.PRICE_MOVEMENT_AGAINST_CURRENCY);
4
+
5
+ trigger.setChainId(CHAINS.MODE);
6
+ trigger.setComparisonValue(3200);
7
+ trigger.setCondition("gte");
8
+ trigger.setParams('currency', 'USD');
9
+ trigger.setParams('contractAddress', getToken(CHAINS.MODE, 'MODE').contractAddress);
10
+ trigger.setPosition(1, 0);
11
+
12
+ console.log(JSON.stringify(trigger.toJSON(), null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
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",