otomato-sdk 1.5.80 → 1.5.82
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/dist/src/constants/tokens.js +4 -2
- package/dist/src/constants/version.js +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/models/Edge.js +23 -5
- package/dist/src/models/Node.js +5 -1
- package/dist/src/services/RpcServices.js +1 -1
- package/dist/src/utils/helpers.js +19 -0
- package/dist/src/utils/typeValidator.js +60 -0
- package/dist/types/examples/create-workflow-with-condition-and-split.d.ts +1 -0
- package/dist/types/examples/create-workflow-with-split.d.ts +1 -0
- package/dist/types/src/constants/tokens.d.ts +2 -0
- package/dist/types/src/constants/version.d.ts +1 -1
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/models/Edge.d.ts +4 -0
- package/dist/types/src/utils/helpers.d.ts +11 -0
- package/dist/types/src/utils/typeValidator.d.ts +6 -0
- package/package.json +1 -1
|
@@ -29,7 +29,8 @@ export const TOKENS = {
|
|
|
29
29
|
name: "ETH",
|
|
30
30
|
symbol: "ETH",
|
|
31
31
|
decimals: 18,
|
|
32
|
-
|
|
32
|
+
nativeCurrency: true,
|
|
33
|
+
equivalentERC20: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
33
34
|
image: "https://static.debank.com/image/chain/logo_url/eth/42ba589cd077e7bdd97db6480b0ff61d.png"
|
|
34
35
|
},
|
|
35
36
|
{
|
|
@@ -46,7 +47,8 @@ export const TOKENS = {
|
|
|
46
47
|
name: "ETH",
|
|
47
48
|
symbol: "ETH",
|
|
48
49
|
decimals: 18,
|
|
49
|
-
|
|
50
|
+
nativeCurrency: true,
|
|
51
|
+
equivalentERC20: "0x4200000000000000000000000000000000000006",
|
|
50
52
|
image: "https://static.debank.com/image/chain/logo_url/eth/42ba589cd077e7bdd97db6480b0ff61d.png"
|
|
51
53
|
},
|
|
52
54
|
{
|
package/dist/src/index.js
CHANGED
|
@@ -4,10 +4,12 @@ export * from './constants/chains.js';
|
|
|
4
4
|
export * from './constants/version.js';
|
|
5
5
|
export * from './constants/tokens.js';
|
|
6
6
|
export * from './constants/WorkflowTemplates.js';
|
|
7
|
+
export * from './constants/logicOperators.js';
|
|
7
8
|
// Exporting models
|
|
8
9
|
export * from './models/Action.js';
|
|
9
10
|
export * from './models/Workflow.js';
|
|
10
|
-
export * from './models/
|
|
11
|
+
export * from './models/conditions/ConditionCheck.js';
|
|
12
|
+
export * from './models/conditions/ConditionGroup.js';
|
|
11
13
|
export * from './models/Parameter.js';
|
|
12
14
|
export * from './models/Trigger.js';
|
|
13
15
|
export * from './models/Node.js';
|
package/dist/src/models/Edge.js
CHANGED
|
@@ -7,31 +7,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { Node } from './Node.js';
|
|
10
11
|
import { apiServices } from '../services/ApiService.js';
|
|
11
12
|
export class Edge {
|
|
12
13
|
constructor(edge) {
|
|
13
14
|
var _a;
|
|
15
|
+
if (!edge.source || !(edge.source instanceof Node)) {
|
|
16
|
+
throw new Error('Edge must have a valid source node.');
|
|
17
|
+
}
|
|
18
|
+
if (!edge.target || !(edge.target instanceof Node)) {
|
|
19
|
+
throw new Error('Edge must have a valid target node.');
|
|
20
|
+
}
|
|
14
21
|
this.id = (_a = edge.id) !== null && _a !== void 0 ? _a : null;
|
|
15
22
|
this.source = edge.source;
|
|
16
23
|
this.target = edge.target;
|
|
24
|
+
this.label = edge.label;
|
|
25
|
+
this.value = edge.value;
|
|
17
26
|
}
|
|
18
27
|
toJSON() {
|
|
19
|
-
|
|
28
|
+
const result = {
|
|
20
29
|
id: this.id,
|
|
21
30
|
source: this.source.getRef(),
|
|
22
31
|
target: this.target.getRef(),
|
|
23
32
|
};
|
|
33
|
+
if (this.label != null) {
|
|
34
|
+
result.label = this.label;
|
|
35
|
+
}
|
|
36
|
+
if (this.value != null) {
|
|
37
|
+
result.value = this.value;
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
24
40
|
}
|
|
25
41
|
static fromJSON(json, nodes) {
|
|
26
|
-
const source = nodes.find(n => n.getRef() === json.source);
|
|
27
|
-
const target = nodes.find(n => n.getRef() === json.target);
|
|
42
|
+
const source = nodes.find((n) => n.getRef() === json.source);
|
|
43
|
+
const target = nodes.find((n) => n.getRef() === json.target);
|
|
28
44
|
if (!source || !target) {
|
|
29
|
-
throw new Error(
|
|
45
|
+
throw new Error('Edge refers to a non-existing node');
|
|
30
46
|
}
|
|
31
47
|
return new Edge({
|
|
32
48
|
id: json.id,
|
|
33
49
|
source,
|
|
34
|
-
target
|
|
50
|
+
target,
|
|
51
|
+
label: json.label,
|
|
52
|
+
value: json.value,
|
|
35
53
|
});
|
|
36
54
|
}
|
|
37
55
|
delete() {
|
package/dist/src/models/Node.js
CHANGED
|
@@ -149,8 +149,12 @@ export class Node {
|
|
|
149
149
|
if (typeof value === 'bigint') {
|
|
150
150
|
return value.toString() + 'n';
|
|
151
151
|
}
|
|
152
|
+
else if (Array.isArray(value)) {
|
|
153
|
+
// Handle arrays by mapping over each element
|
|
154
|
+
return value.map((item) => serializeBigInt('', item));
|
|
155
|
+
}
|
|
152
156
|
else if (typeof value === 'object' && value !== null) {
|
|
153
|
-
// Recursively
|
|
157
|
+
// Recursively handle objects
|
|
154
158
|
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
155
159
|
acc[k] = serializeBigInt(k, v);
|
|
156
160
|
return acc;
|
|
@@ -59,7 +59,7 @@ class RPCServices {
|
|
|
59
59
|
throw new Error(`Error fetching token details ${contractAddress} on chain ${chainId}`);
|
|
60
60
|
}
|
|
61
61
|
attempt++;
|
|
62
|
-
console.warn(`Attempt ${attempt} to fetch token details failed. Retrying in ${retryDelay(attempt)}ms...`);
|
|
62
|
+
// console.warn(`Attempt ${attempt} to fetch token details failed. Retrying in ${retryDelay(attempt)}ms...`);
|
|
63
63
|
yield new Promise(resolve => setTimeout(resolve, retryDelay(attempt)));
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { ethers } from 'ethers';
|
|
11
11
|
import { getToken, getTokenFromSymbol } from '../constants/tokens.js';
|
|
12
|
+
import { isAddress, isNumericString } from './typeValidator.js';
|
|
12
13
|
export function convertToTokenUnits(amount, chainId, contractAddress) {
|
|
13
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
15
|
const token = yield getToken(chainId, contractAddress);
|
|
@@ -72,3 +73,21 @@ export function compareAddresses(address1, address2) {
|
|
|
72
73
|
// Compare the normalized addresses
|
|
73
74
|
return normalizedAddress1 === normalizedAddress2;
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Generates a formula string for dynamically computing the ERC20 amount in the workflow,
|
|
78
|
+
* based on the amount, chain ID, and contract address.
|
|
79
|
+
* If the contract address is valid, it will be wrapped in double quotes.
|
|
80
|
+
* If the amount is a numeric string, it will also be wrapped in double quotes.
|
|
81
|
+
* @param amount - The amount of the ERC20 token to compute.
|
|
82
|
+
* @param chainId - The ID of the blockchain network.
|
|
83
|
+
* @param contractAddress - The contract address of the ERC20 token.
|
|
84
|
+
* @returns string - A formatted string to be used as a variable in the workflow.
|
|
85
|
+
*/
|
|
86
|
+
export function getComputeERC20Variable(amount, chainId, contractAddress) {
|
|
87
|
+
// Check if the contract address is a valid Ethereum address and wrap in quotes if it is
|
|
88
|
+
const formattedContractAddress = isAddress(contractAddress) ? `"${contractAddress}"` : contractAddress;
|
|
89
|
+
// Check if the amount is a numeric string and wrap it in quotes if it is
|
|
90
|
+
const formattedAmount = isNumericString(amount) ? `${amount}` : amount;
|
|
91
|
+
// Construct the computeERC20Amount formula
|
|
92
|
+
return `{{computeERC20Amount(${formattedAmount}, ${chainId}, ${formattedContractAddress})}}`;
|
|
93
|
+
}
|
|
@@ -49,12 +49,64 @@ export function validateType(expectedType, value) {
|
|
|
49
49
|
case 'addresses_array':
|
|
50
50
|
// Ensure value is an array, and each element is a valid address
|
|
51
51
|
return Array.isArray(value) && value.every(isAddress);
|
|
52
|
+
case 'condition_groups':
|
|
53
|
+
return Array.isArray(value) && value.every(isValidConditionGroup);
|
|
54
|
+
case 'and_or':
|
|
55
|
+
const validLogicOperators = new Set(['and', 'or']);
|
|
56
|
+
return typeof value === 'string' && validLogicOperators.has(value.toLowerCase());
|
|
52
57
|
case 'any':
|
|
53
58
|
return true;
|
|
54
59
|
default:
|
|
55
60
|
return false;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
63
|
+
function isValidConditionGroup(value) {
|
|
64
|
+
if (typeof value !== 'object' || value === null) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const { logic, checks } = value;
|
|
68
|
+
validateType('and_or', logic);
|
|
69
|
+
// Validate checks array
|
|
70
|
+
if (!Array.isArray(checks) || checks.length === 0) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
// Validate each condition check
|
|
74
|
+
for (const check of checks) {
|
|
75
|
+
if (!isValidConditionCheck(check)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
function isValidConditionCheck(value) {
|
|
82
|
+
if (typeof value !== 'object' || value === null) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const { value1, condition, value2 } = value;
|
|
86
|
+
// Validate condition operator
|
|
87
|
+
const validConditionOperators = new Set(['gte', 'gt', 'lte', 'lt', 'eq', 'neq']);
|
|
88
|
+
if (typeof condition !== 'string' || !validConditionOperators.has(condition.toLowerCase())) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
// Validate value1 and value2 (they can be numbers, strings, or variables)
|
|
92
|
+
if (!isValidValue(value1) || !isValidValue(value2)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
function isValidValue(value) {
|
|
98
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (typeof value === 'string') {
|
|
102
|
+
if (isVariable(value)) {
|
|
103
|
+
return true; // It's a variable placeholder
|
|
104
|
+
}
|
|
105
|
+
// Optionally, add further validation for strings if needed
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
58
110
|
function isVariable(value) {
|
|
59
111
|
return /\{\{nodeMap\.[^.}]+\.(?:output|parameters(?:\.abi\.parameters)?)\.[^.}]+\}\}/.test(value);
|
|
60
112
|
}
|
|
@@ -111,3 +163,11 @@ export function isValidPhoneNumber(value) {
|
|
|
111
163
|
export function isValidEmail(value) {
|
|
112
164
|
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
113
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Checks if a string is numeric (represents a valid number).
|
|
168
|
+
* @param value - The string to check.
|
|
169
|
+
* @returns boolean - True if the string represents a number, false otherwise.
|
|
170
|
+
*/
|
|
171
|
+
export function isNumericString(value) {
|
|
172
|
+
return !isNaN(Number(value)) && value.trim() !== '';
|
|
173
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.5.
|
|
1
|
+
export declare const SDK_VERSION = "1.5.82";
|
|
2
2
|
export declare function compareVersions(v1: string, v2: string): number;
|
|
@@ -3,9 +3,11 @@ export * from './constants/chains.js';
|
|
|
3
3
|
export * from './constants/version.js';
|
|
4
4
|
export * from './constants/tokens.js';
|
|
5
5
|
export * from './constants/WorkflowTemplates.js';
|
|
6
|
+
export * from './constants/logicOperators.js';
|
|
6
7
|
export * from './models/Action.js';
|
|
7
8
|
export * from './models/Workflow.js';
|
|
8
|
-
export * from './models/
|
|
9
|
+
export * from './models/conditions/ConditionCheck.js';
|
|
10
|
+
export * from './models/conditions/ConditionGroup.js';
|
|
9
11
|
export * from './models/Parameter.js';
|
|
10
12
|
export * from './models/Trigger.js';
|
|
11
13
|
export * from './models/Node.js';
|
|
@@ -3,10 +3,14 @@ export declare class Edge {
|
|
|
3
3
|
id: string | null;
|
|
4
4
|
source: Node;
|
|
5
5
|
target: Node;
|
|
6
|
+
label?: string;
|
|
7
|
+
value?: any;
|
|
6
8
|
constructor(edge: {
|
|
7
9
|
id?: string | null;
|
|
8
10
|
source: Node;
|
|
9
11
|
target: Node;
|
|
12
|
+
label?: string;
|
|
13
|
+
value?: any;
|
|
10
14
|
});
|
|
11
15
|
toJSON(): {
|
|
12
16
|
[key: string]: any;
|
|
@@ -12,3 +12,14 @@ export declare function convertTokenUnitsFromDecimals(amount: bigint, decimals:
|
|
|
12
12
|
* @returns boolean - True if the addresses are equal, false otherwise.
|
|
13
13
|
*/
|
|
14
14
|
export declare function compareAddresses(address1: string, address2: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Generates a formula string for dynamically computing the ERC20 amount in the workflow,
|
|
17
|
+
* based on the amount, chain ID, and contract address.
|
|
18
|
+
* If the contract address is valid, it will be wrapped in double quotes.
|
|
19
|
+
* If the amount is a numeric string, it will also be wrapped in double quotes.
|
|
20
|
+
* @param amount - The amount of the ERC20 token to compute.
|
|
21
|
+
* @param chainId - The ID of the blockchain network.
|
|
22
|
+
* @param contractAddress - The contract address of the ERC20 token.
|
|
23
|
+
* @returns string - A formatted string to be used as a variable in the workflow.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getComputeERC20Variable(amount: string, chainId: any, contractAddress: string): string;
|
|
@@ -4,3 +4,9 @@ export declare function isAddress(value: string): boolean;
|
|
|
4
4
|
export declare function isValidUrl(value: string): boolean;
|
|
5
5
|
export declare function isValidPhoneNumber(value: string): boolean;
|
|
6
6
|
export declare function isValidEmail(value: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a string is numeric (represents a valid number).
|
|
9
|
+
* @param value - The string to check.
|
|
10
|
+
* @returns boolean - True if the string represents a number, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isNumericString(value: string): boolean;
|