otomato-sdk 1.3.2 → 1.3.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.
- package/README.md +2 -2
- package/dist/examples/create-action.js +6 -6
- package/dist/examples/create-trigger-list.js +5 -10
- package/dist/examples/create-trigger.js +21 -7
- package/dist/examples/create-workflow.js +33 -23
- package/dist/examples/load-workflow.js +1 -1
- package/dist/examples/login.js +32 -0
- package/dist/src/constants/Blocks.js +4 -4
- package/dist/src/constants/chains.js +1 -1
- package/dist/src/constants/tokens.js +13 -3
- package/dist/src/index.js +1 -0
- package/dist/src/models/Action.js +72 -0
- package/dist/src/models/Node.js +46 -57
- package/dist/src/models/Trigger.js +80 -4
- package/dist/src/models/Workflow.js +40 -9
- package/dist/src/services/ApiService.js +27 -5
- package/dist/src/utils/helpers.js +19 -0
- package/dist/src/utils/typeValidator.js +34 -8
- package/dist/test/action.spec.js +80 -11
- package/dist/test/automation.spec.js +9 -8
- package/dist/test/helpers.spec.js +23 -0
- package/dist/test/node.spec.js +13 -19
- package/dist/test/trigger.spec.js +92 -19
- package/dist/types/examples/login.d.ts +1 -0
- package/dist/types/src/constants/tokens.d.ts +2 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/models/Action.d.ts +6 -1
- package/dist/types/src/models/Node.d.ts +13 -2
- package/dist/types/src/models/Trigger.d.ts +8 -2
- package/dist/types/src/models/Workflow.d.ts +14 -1
- package/dist/types/src/services/ApiService.d.ts +6 -1
- package/dist/types/src/utils/helpers.d.ts +2 -0
- package/dist/types/src/utils/typeValidator.d.ts +1 -0
- package/dist/types/test/helpers.spec.d.ts +1 -0
- package/examples/create-action.ts +6 -6
- package/examples/create-trigger-list.ts +5 -10
- package/examples/create-trigger.ts +14 -7
- package/examples/create-workflow.ts +43 -25
- package/examples/load-workflow.ts +1 -1
- package/examples/login.ts +27 -0
- package/package.json +4 -2
- package/src/constants/Blocks.ts +4 -4
- package/src/constants/chains.ts +1 -1
- package/src/constants/tokens.ts +18 -4
- package/src/index.ts +1 -0
- package/src/models/Action.ts +77 -3
- package/src/models/Node.ts +54 -65
- package/src/models/Trigger.ts +84 -6
- package/src/models/Workflow.ts +37 -10
- package/src/services/ApiService.ts +24 -5
- package/src/utils/helpers.ts +9 -0
- package/src/utils/typeValidator.ts +28 -11
- package/test/action.spec.ts +75 -11
- package/test/automation.spec.ts +9 -8
- package/test/helpers.spec.ts +16 -0
- package/test/node.spec.ts +17 -23
- package/test/trigger.spec.ts +89 -19
|
@@ -42,16 +42,27 @@ export class Workflow {
|
|
|
42
42
|
}
|
|
43
43
|
create() {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
try {
|
|
47
|
+
const response = yield apiServices.post('/workflows', this.toJSON());
|
|
48
|
+
if (response.status === 201) {
|
|
49
|
+
this.id = response.data.id; // Assign the returned ID to the workflow instance
|
|
50
|
+
// Assign IDs to the nodes based on the response
|
|
51
|
+
response.data.nodes.forEach((nodeResponse) => {
|
|
52
|
+
const node = this.nodes.find(n => n.getRef() === nodeResponse.ref);
|
|
53
|
+
if (node) {
|
|
54
|
+
node.setId(nodeResponse.id);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return { success: true };
|
|
52
58
|
}
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
else {
|
|
60
|
+
return { success: false, error: ((_a = response.data) === null || _a === void 0 ? void 0 : _a.error) || 'Unknown error' };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return { success: false, error: error.message || 'Unknown error' };
|
|
65
|
+
}
|
|
55
66
|
});
|
|
56
67
|
}
|
|
57
68
|
load(workflowId) {
|
|
@@ -64,4 +75,24 @@ export class Workflow {
|
|
|
64
75
|
return this;
|
|
65
76
|
});
|
|
66
77
|
}
|
|
78
|
+
run() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
var _a;
|
|
81
|
+
if (!this.id) {
|
|
82
|
+
throw new Error('The workflow needs to be published first');
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const response = yield apiServices.post(`/workflows/${this.id}/run`, this.toJSON());
|
|
86
|
+
if (response.status === 204) {
|
|
87
|
+
return { success: true };
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return { success: false, error: ((_a = response.data) === null || _a === void 0 ? void 0 : _a.error) || 'Unknown error' };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return { success: false, error: error.message || 'Unknown error' };
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
67
98
|
}
|
|
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
// networkService.ts
|
|
11
10
|
import axios from 'axios';
|
|
12
11
|
const API_CONFIG = {
|
|
13
12
|
BASE_URL: 'https://staging-api.otomato.xyz/api',
|
|
@@ -22,17 +21,14 @@ const axiosInstance = axios.create({
|
|
|
22
21
|
class ApiServices {
|
|
23
22
|
constructor() {
|
|
24
23
|
this.auth = null;
|
|
25
|
-
// You can add other methods (get, put, delete) similarly
|
|
26
24
|
}
|
|
27
25
|
setAuth(auth) {
|
|
28
26
|
this.auth = auth;
|
|
29
27
|
}
|
|
30
28
|
post(url, data) {
|
|
31
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
console.log(JSON.stringify(data));
|
|
33
30
|
const headers = this.auth ? { 'Authorization': this.auth } : {};
|
|
34
|
-
|
|
35
|
-
return response.data;
|
|
31
|
+
return yield axiosInstance.post(url, data, { headers });
|
|
36
32
|
});
|
|
37
33
|
}
|
|
38
34
|
get(url) {
|
|
@@ -42,5 +38,31 @@ class ApiServices {
|
|
|
42
38
|
return response.data;
|
|
43
39
|
});
|
|
44
40
|
}
|
|
41
|
+
generateLoginPayload(address, chainId) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
44
|
+
const response = yield axiosInstance.post('/auth/generate-payload', { address, chainId }, { headers });
|
|
45
|
+
return response.data;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
getToken(loginPayload, signature) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
51
|
+
const body = {
|
|
52
|
+
payload: loginPayload,
|
|
53
|
+
signature,
|
|
54
|
+
};
|
|
55
|
+
const response = yield axiosInstance.post('/auth/token', body, { headers });
|
|
56
|
+
const token = response.data.token;
|
|
57
|
+
return { token };
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
verifyToken(token) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
63
|
+
const response = yield axiosInstance.post('/auth/verify-token', { token }, { headers });
|
|
64
|
+
return response.data;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
45
67
|
}
|
|
46
68
|
export const apiServices = new ApiServices();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ethers } from 'ethers';
|
|
11
|
+
import { getToken } from '../constants/tokens.js';
|
|
12
|
+
export function convertToTokenUnits(amount, chainId, contractAddress) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const token = yield getToken(chainId, contractAddress);
|
|
15
|
+
const decimals = token.decimals;
|
|
16
|
+
const adjustedAmount = ethers.parseUnits(amount.toString(), decimals);
|
|
17
|
+
return adjustedAmount;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -6,21 +6,21 @@ export function validateType(expectedType, value) {
|
|
|
6
6
|
return typeof value === 'boolean';
|
|
7
7
|
case 'chainId':
|
|
8
8
|
case 'integer':
|
|
9
|
-
return Number.isInteger(value);
|
|
9
|
+
return Number.isInteger(value) || typeof value === 'bigint';
|
|
10
10
|
case 'int8':
|
|
11
11
|
case 'int16':
|
|
12
12
|
case 'int32':
|
|
13
13
|
case 'int64':
|
|
14
14
|
case 'int128':
|
|
15
15
|
case 'int256':
|
|
16
|
-
return Number.isInteger(value) && isIntInRange(value, parseInt(expectedType.replace('int', '')));
|
|
16
|
+
return (Number.isInteger(value) || typeof value === 'bigint') && isIntInRange(value, parseInt(expectedType.replace('int', '')));
|
|
17
17
|
case 'uint8':
|
|
18
18
|
case 'uint16':
|
|
19
19
|
case 'uint32':
|
|
20
20
|
case 'uint64':
|
|
21
21
|
case 'uint128':
|
|
22
22
|
case 'uint256':
|
|
23
|
-
return Number.isInteger(value) && isUintInRange(value, parseInt(expectedType.replace('uint', '')));
|
|
23
|
+
return (Number.isInteger(value) || typeof value === 'bigint') && isUintInRange(value, parseInt(expectedType.replace('uint', '')));
|
|
24
24
|
case 'erc20':
|
|
25
25
|
case 'nftCollection':
|
|
26
26
|
case 'address':
|
|
@@ -45,14 +45,40 @@ export function validateType(expectedType, value) {
|
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
export function typeIsNumber(type) {
|
|
49
|
+
switch (type) {
|
|
50
|
+
case 'integer':
|
|
51
|
+
case 'float':
|
|
52
|
+
case 'fixed':
|
|
53
|
+
case 'ufixed':
|
|
54
|
+
case 'chainId':
|
|
55
|
+
case 'int8':
|
|
56
|
+
case 'int16':
|
|
57
|
+
case 'int32':
|
|
58
|
+
case 'int64':
|
|
59
|
+
case 'int128':
|
|
60
|
+
case 'int256':
|
|
61
|
+
case 'uint8':
|
|
62
|
+
case 'uint16':
|
|
63
|
+
case 'uint32':
|
|
64
|
+
case 'uint64':
|
|
65
|
+
case 'uint128':
|
|
66
|
+
case 'uint256':
|
|
67
|
+
return true;
|
|
68
|
+
default:
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
48
72
|
function isIntInRange(value, bits) {
|
|
49
|
-
const min = -(Math.pow(2, (bits - 1)));
|
|
50
|
-
const max = (Math.pow(2, (bits - 1))) - 1;
|
|
51
|
-
|
|
73
|
+
const min = BigInt(-(Math.pow(2, (bits - 1))));
|
|
74
|
+
const max = BigInt((Math.pow(2, (bits - 1))) - 1);
|
|
75
|
+
const bigIntValue = BigInt(value);
|
|
76
|
+
return bigIntValue >= min && bigIntValue <= max;
|
|
52
77
|
}
|
|
53
78
|
function isUintInRange(value, bits) {
|
|
54
|
-
const max = (Math.pow(2, bits)) - 1;
|
|
55
|
-
|
|
79
|
+
const max = BigInt((Math.pow(2, bits)) - 1);
|
|
80
|
+
const bigIntValue = BigInt(value);
|
|
81
|
+
return bigIntValue >= 0 && bigIntValue <= max;
|
|
56
82
|
}
|
|
57
83
|
export function isAddress(value) {
|
|
58
84
|
return ethers.isAddress(value);
|
package/dist/test/action.spec.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { expect } from 'chai';
|
|
2
|
-
import { Action, ACTIONS,
|
|
11
|
+
import { Action, ACTIONS, getTokenFromSymbol, CHAINS } from '../src/index';
|
|
3
12
|
const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
4
13
|
describe('Action Class', () => {
|
|
5
14
|
it('should create a transfer action without parameters', () => {
|
|
6
15
|
const transferAction = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
7
16
|
const params = transferAction.getParameters();
|
|
8
17
|
expect(params.chainId).to.be.null;
|
|
9
|
-
expect(params
|
|
10
|
-
expect(params
|
|
18
|
+
expect(params.abi.parameters.value).to.be.null;
|
|
19
|
+
expect(params.abi.parameters.to).to.be.null;
|
|
11
20
|
expect(params.contractAddress).to.be.null;
|
|
12
21
|
});
|
|
13
22
|
it('should create a transfer action and set parameters correctly', () => {
|
|
@@ -15,29 +24,34 @@ describe('Action Class', () => {
|
|
|
15
24
|
transferAction.setChainId(CHAINS.ETHEREUM);
|
|
16
25
|
transferAction.setParams("value", 1000);
|
|
17
26
|
transferAction.setParams("to", DEFAULT_ADDRESS);
|
|
18
|
-
transferAction.setContractAddress(
|
|
27
|
+
transferAction.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
19
28
|
const params = transferAction.getParameters();
|
|
20
29
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
21
|
-
expect(params
|
|
22
|
-
expect(params
|
|
23
|
-
expect(params.contractAddress).to.equal(
|
|
30
|
+
expect(params.abi.parameters.value).to.equal(1000);
|
|
31
|
+
expect(params.abi.parameters.to).to.equal(DEFAULT_ADDRESS);
|
|
32
|
+
expect(params.contractAddress).to.equal(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
24
33
|
});
|
|
25
34
|
it('should be able to export an action as json', () => {
|
|
26
35
|
const transferAction = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
27
36
|
transferAction.setChainId(CHAINS.ETHEREUM);
|
|
28
37
|
transferAction.setParams("value", 1000);
|
|
29
38
|
transferAction.setParams("to", DEFAULT_ADDRESS);
|
|
30
|
-
transferAction.setContractAddress(
|
|
39
|
+
transferAction.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
31
40
|
const json = transferAction.toJSON();
|
|
32
41
|
expect(json).to.deep.equal({
|
|
33
42
|
blockId: ACTIONS.TOKENS.ERC20.TRANSFER.blockId,
|
|
34
43
|
ref: transferAction.getRef(),
|
|
35
44
|
type: 'action',
|
|
45
|
+
id: null,
|
|
36
46
|
parameters: {
|
|
37
47
|
chainId: CHAINS.ETHEREUM,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
abi: {
|
|
49
|
+
parameters: {
|
|
50
|
+
to: DEFAULT_ADDRESS,
|
|
51
|
+
value: 1000
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
contractAddress: getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress
|
|
41
55
|
}
|
|
42
56
|
});
|
|
43
57
|
});
|
|
@@ -74,4 +88,59 @@ describe('Action Class', () => {
|
|
|
74
88
|
const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
|
|
75
89
|
expect(() => smsAction.setParams("phoneNumber", "invalid_phone_number")).to.throw('Invalid type for parameter phoneNumber. Expected phone_number.');
|
|
76
90
|
});*/
|
|
91
|
+
it('should create an action from JSON correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
var _a;
|
|
93
|
+
const json = {
|
|
94
|
+
"id": "755671a7-adac-4aeb-a759-73c00dd397bc",
|
|
95
|
+
"ref": "n-2",
|
|
96
|
+
"blockId": 100002,
|
|
97
|
+
"type": "action",
|
|
98
|
+
"position": {
|
|
99
|
+
"x": 0,
|
|
100
|
+
"y": -10
|
|
101
|
+
},
|
|
102
|
+
"parameters": {
|
|
103
|
+
"message": "ETH is at 3550 :pepe_joy:",
|
|
104
|
+
"webhook": "https://hooks.slack.com/services/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"
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const action = yield Action.fromJSON(json);
|
|
108
|
+
expect(action.id).to.equal("755671a7-adac-4aeb-a759-73c00dd397bc");
|
|
109
|
+
expect(action.getRef()).to.equal("n-2");
|
|
110
|
+
expect(action.blockId).to.equal(100002);
|
|
111
|
+
expect(action.getParameters().message).to.equal("ETH is at 3550 :pepe_joy:");
|
|
112
|
+
expect(action.getParameters().webhook).to.equal("https://hooks.slack.com/services/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");
|
|
113
|
+
expect((_a = action.getParentInfo()) === null || _a === void 0 ? void 0 : _a.name).to.equal("SLACK");
|
|
114
|
+
expect(action.toJSON()).to.deep.equal(json);
|
|
115
|
+
}));
|
|
116
|
+
it('should create an action with abi parameters from JSON correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
var _b;
|
|
118
|
+
const json = {
|
|
119
|
+
"id": "d6e6884f-cd8f-4c96-b36c-e5539b3599fc",
|
|
120
|
+
"ref": "n-3",
|
|
121
|
+
"blockId": 100004,
|
|
122
|
+
"type": "action",
|
|
123
|
+
"parameters": {
|
|
124
|
+
"abi": {
|
|
125
|
+
"parameters": {
|
|
126
|
+
"to": "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6",
|
|
127
|
+
"value": 1000
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"chainId": 1,
|
|
131
|
+
"contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const action = yield Action.fromJSON(json);
|
|
135
|
+
console.log(action);
|
|
136
|
+
expect(action.id).to.equal("d6e6884f-cd8f-4c96-b36c-e5539b3599fc");
|
|
137
|
+
expect(action.getRef()).to.equal("n-3");
|
|
138
|
+
expect(action.blockId).to.equal(100004);
|
|
139
|
+
expect(action.getParameters().chainId).to.equal(1);
|
|
140
|
+
expect(action.getParameters().contractAddress).to.equal("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48");
|
|
141
|
+
expect(action.getParameters().abi.parameters.to).to.equal("0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
142
|
+
expect(action.getParameters().abi.parameters.value).to.equal(1000);
|
|
143
|
+
expect((_b = action.getParentInfo()) === null || _b === void 0 ? void 0 : _b.name).to.equal("ERC20");
|
|
144
|
+
expect(action.toJSON()).to.deep.equal(json);
|
|
145
|
+
}));
|
|
77
146
|
});
|
|
@@ -2,18 +2,18 @@ import { expect } from 'chai';
|
|
|
2
2
|
import { Workflow } from '../src/models/Workflow.js';
|
|
3
3
|
import { Trigger } from '../src/models/Trigger.js';
|
|
4
4
|
import { Action } from '../src/models/Action.js';
|
|
5
|
-
import { TRIGGERS, ACTIONS,
|
|
5
|
+
import { TRIGGERS, ACTIONS, getTokenFromSymbol, CHAINS } from '../src/index.js';
|
|
6
6
|
describe('Workflow Class', () => {
|
|
7
7
|
it('should create a workflow with a trigger and actions', () => {
|
|
8
8
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
9
9
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
10
|
-
trigger.setContractAddress(
|
|
10
|
+
trigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
11
11
|
trigger.setPosition(0, 0);
|
|
12
12
|
const action1 = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
13
13
|
action1.setChainId(CHAINS.ETHEREUM);
|
|
14
14
|
action1.setParams("value", 1000);
|
|
15
15
|
action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
16
|
-
action1.setContractAddress(
|
|
16
|
+
action1.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
17
17
|
action1.setPosition(1, 0);
|
|
18
18
|
const action2 = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
19
19
|
action2.setParams("webhook", "https://webhook.url");
|
|
@@ -23,6 +23,7 @@ describe('Workflow Class', () => {
|
|
|
23
23
|
const json = workflow.toJSON();
|
|
24
24
|
expect(json).to.deep.equal({
|
|
25
25
|
name: "Test Workflow",
|
|
26
|
+
id: null,
|
|
26
27
|
nodes: [trigger.toJSON(), action1.toJSON(), action2.toJSON()],
|
|
27
28
|
edges: []
|
|
28
29
|
});
|
|
@@ -30,7 +31,7 @@ describe('Workflow Class', () => {
|
|
|
30
31
|
it('should set the name of the workflow', () => {
|
|
31
32
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
32
33
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
33
|
-
trigger.setContractAddress(
|
|
34
|
+
trigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
34
35
|
trigger.setPosition(0, 0);
|
|
35
36
|
const workflow = new Workflow("Initial Name", [trigger]);
|
|
36
37
|
workflow.setName("Updated Name");
|
|
@@ -39,11 +40,11 @@ describe('Workflow Class', () => {
|
|
|
39
40
|
it('should add a trigger to the workflow', () => {
|
|
40
41
|
const initialTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
41
42
|
initialTrigger.setChainId(CHAINS.ETHEREUM);
|
|
42
|
-
initialTrigger.setContractAddress(
|
|
43
|
+
initialTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
43
44
|
initialTrigger.setPosition(0, 0);
|
|
44
45
|
const newTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
45
46
|
newTrigger.setChainId(CHAINS.ETHEREUM);
|
|
46
|
-
newTrigger.setContractAddress(
|
|
47
|
+
newTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
47
48
|
newTrigger.setPosition(1, 0);
|
|
48
49
|
const workflow = new Workflow("Test Workflow", [initialTrigger]);
|
|
49
50
|
workflow.addNode(newTrigger);
|
|
@@ -52,13 +53,13 @@ describe('Workflow Class', () => {
|
|
|
52
53
|
it('should add actions to the workflow', () => {
|
|
53
54
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
54
55
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
55
|
-
trigger.setContractAddress(
|
|
56
|
+
trigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
56
57
|
trigger.setPosition(0, 0);
|
|
57
58
|
const action1 = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
58
59
|
action1.setChainId(CHAINS.ETHEREUM);
|
|
59
60
|
action1.setParams("value", 1000);
|
|
60
61
|
action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
61
|
-
action1.setContractAddress(
|
|
62
|
+
action1.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
62
63
|
action1.setPosition(1, 0);
|
|
63
64
|
const action2 = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
64
65
|
action2.setParams("webhook", "https://webhook.url");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { expect } from 'chai';
|
|
11
|
+
import { convertToTokenUnits, getTokenFromSymbol, CHAINS } from '../src/index.js';
|
|
12
|
+
describe('convertToTokenUnits', () => {
|
|
13
|
+
it('should return 10^6 for 1 USDC', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const usdcContractAddr = getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress;
|
|
15
|
+
const result = yield convertToTokenUnits(1, CHAINS.ETHEREUM, usdcContractAddr);
|
|
16
|
+
expect(result).to.equal(BigInt(Math.pow(10, 6)));
|
|
17
|
+
}));
|
|
18
|
+
it('should return 10^18 for 1 MODE', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const modeContractAddr = getTokenFromSymbol(CHAINS.MODE, 'MODE').contractAddress;
|
|
20
|
+
const result = yield convertToTokenUnits(1, CHAINS.MODE, modeContractAddr);
|
|
21
|
+
expect(result).to.equal(BigInt(Math.pow(10, 18)));
|
|
22
|
+
}));
|
|
23
|
+
});
|
package/dist/test/node.spec.js
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import {
|
|
2
|
+
import { Action } from '../src/index'; // Adjust the import path according to your project structure
|
|
3
3
|
const DEFAULT_PARAMETERS = [
|
|
4
4
|
{ key: 'chainId', type: 'integer', description: 'Chain ID', value: null },
|
|
5
5
|
{ key: 'contractAddress', type: 'address', description: 'Contract Address', value: null }
|
|
6
6
|
];
|
|
7
7
|
describe('Node Class', () => {
|
|
8
8
|
it('should create a node without coordinates', () => {
|
|
9
|
-
const node = new
|
|
9
|
+
const node = new Action({
|
|
10
10
|
blockId: 1,
|
|
11
11
|
name: 'Test Node',
|
|
12
12
|
description: 'A node for testing',
|
|
13
13
|
parameters: DEFAULT_PARAMETERS,
|
|
14
|
-
class: 'testClass',
|
|
15
14
|
image: 'a',
|
|
16
15
|
});
|
|
17
16
|
expect(node.position).to.be.undefined;
|
|
18
17
|
});
|
|
19
18
|
it('should create a node with coordinates', () => {
|
|
20
19
|
var _a, _b;
|
|
21
|
-
const node = new
|
|
20
|
+
const node = new Action({
|
|
22
21
|
blockId: 2,
|
|
23
22
|
name: 'Test Node with Coordinates',
|
|
24
23
|
description: 'A node for testing with coordinates',
|
|
25
24
|
parameters: DEFAULT_PARAMETERS,
|
|
26
|
-
class: 'testClass',
|
|
27
25
|
position: { x: 100, y: 200 },
|
|
28
26
|
image: 'a',
|
|
29
27
|
});
|
|
@@ -32,12 +30,11 @@ describe('Node Class', () => {
|
|
|
32
30
|
});
|
|
33
31
|
it('should set and get coordinates correctly', () => {
|
|
34
32
|
var _a, _b;
|
|
35
|
-
const node = new
|
|
33
|
+
const node = new Action({
|
|
36
34
|
blockId: 3,
|
|
37
35
|
name: 'Test Node for Coordinates',
|
|
38
36
|
description: 'A node for testing coordinate setting',
|
|
39
37
|
parameters: DEFAULT_PARAMETERS,
|
|
40
|
-
class: 'testClass',
|
|
41
38
|
image: 'a',
|
|
42
39
|
});
|
|
43
40
|
node.setPosition(300, 400);
|
|
@@ -45,12 +42,11 @@ describe('Node Class', () => {
|
|
|
45
42
|
expect((_b = node.position) === null || _b === void 0 ? void 0 : _b.y).to.equal(400);
|
|
46
43
|
});
|
|
47
44
|
it('should create a node and set parameters correctly', () => {
|
|
48
|
-
const node = new
|
|
45
|
+
const node = new Action({
|
|
49
46
|
blockId: 4,
|
|
50
47
|
name: 'Test Node for Parameters',
|
|
51
48
|
description: 'A node for testing parameter setting',
|
|
52
49
|
parameters: DEFAULT_PARAMETERS,
|
|
53
|
-
class: 'testClass',
|
|
54
50
|
image: 'a',
|
|
55
51
|
});
|
|
56
52
|
node.setChainId(1);
|
|
@@ -60,12 +56,11 @@ describe('Node Class', () => {
|
|
|
60
56
|
expect(params.contractAddress).to.equal("0x0000000000000000000000000000000000000000");
|
|
61
57
|
});
|
|
62
58
|
it('should be able to export a node as json without coordinates', () => {
|
|
63
|
-
const node = new
|
|
59
|
+
const node = new Action({
|
|
64
60
|
blockId: 5,
|
|
65
61
|
name: 'Test Node for JSON',
|
|
66
62
|
description: 'A node for testing JSON export',
|
|
67
63
|
parameters: DEFAULT_PARAMETERS,
|
|
68
|
-
class: 'testClass',
|
|
69
64
|
image: 'a',
|
|
70
65
|
});
|
|
71
66
|
node.setChainId(1);
|
|
@@ -73,8 +68,9 @@ describe('Node Class', () => {
|
|
|
73
68
|
const json = node.toJSON();
|
|
74
69
|
expect(json).to.deep.equal({
|
|
75
70
|
blockId: 5,
|
|
71
|
+
id: null,
|
|
76
72
|
ref: node.getRef(),
|
|
77
|
-
type: '
|
|
73
|
+
type: 'action',
|
|
78
74
|
parameters: {
|
|
79
75
|
chainId: 1,
|
|
80
76
|
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
@@ -82,12 +78,11 @@ describe('Node Class', () => {
|
|
|
82
78
|
});
|
|
83
79
|
});
|
|
84
80
|
it('should be able to export a node as json with coordinates', () => {
|
|
85
|
-
const node = new
|
|
81
|
+
const node = new Action({
|
|
86
82
|
blockId: 6,
|
|
87
83
|
name: 'Test Node for JSON with Coordinates',
|
|
88
84
|
description: 'A node for testing JSON export with coordinates',
|
|
89
85
|
parameters: DEFAULT_PARAMETERS,
|
|
90
|
-
class: 'testClass',
|
|
91
86
|
position: { x: 1, y: 2 },
|
|
92
87
|
image: 'a',
|
|
93
88
|
});
|
|
@@ -95,8 +90,9 @@ describe('Node Class', () => {
|
|
|
95
90
|
node.setContractAddress("0x0000000000000000000000000000000000000000");
|
|
96
91
|
const json = node.toJSON();
|
|
97
92
|
expect(json).to.deep.equal({
|
|
98
|
-
type: '
|
|
93
|
+
type: 'action',
|
|
99
94
|
blockId: 6,
|
|
95
|
+
id: null,
|
|
100
96
|
ref: node.getRef(),
|
|
101
97
|
parameters: {
|
|
102
98
|
chainId: 1,
|
|
@@ -106,23 +102,21 @@ describe('Node Class', () => {
|
|
|
106
102
|
});
|
|
107
103
|
});
|
|
108
104
|
it('should throw an error for invalid parameter type', () => {
|
|
109
|
-
const node = new
|
|
105
|
+
const node = new Action({
|
|
110
106
|
blockId: 7,
|
|
111
107
|
name: 'Test Node for Invalid Parameter Type',
|
|
112
108
|
description: 'A node for testing invalid parameter type',
|
|
113
109
|
parameters: DEFAULT_PARAMETERS,
|
|
114
|
-
class: 'testClass',
|
|
115
110
|
image: 'a',
|
|
116
111
|
});
|
|
117
112
|
expect(() => node.setParams("chainId", "invalid")).to.throw('Invalid type for parameter chainId. Expected integer.');
|
|
118
113
|
});
|
|
119
114
|
it('should throw an error for invalid address', () => {
|
|
120
|
-
const node = new
|
|
115
|
+
const node = new Action({
|
|
121
116
|
blockId: 8,
|
|
122
117
|
name: 'Test Node for Invalid Address',
|
|
123
118
|
description: 'A node for testing invalid address',
|
|
124
119
|
parameters: DEFAULT_PARAMETERS,
|
|
125
|
-
class: 'testClass',
|
|
126
120
|
image: 'a',
|
|
127
121
|
});
|
|
128
122
|
expect(() => node.setParams("contractAddress", "invalid_address")).to.throw('Invalid type for parameter contractAddress. Expected address.');
|