otomato-sdk 2.0.123 → 2.0.124
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 +217 -89
- package/dist/src/constants/Blocks.js +77 -11
- package/dist/src/constants/version.js +1 -1
- package/dist/types/examples/Chains/oasis-accumulated-finance-apy-trigger.d.ts +1 -0
- package/dist/types/examples/Chains/oasis-accumulated-finance-tvl-trigger.d.ts +1 -0
- package/dist/types/examples/Chains/oasis-weth-balance-trigger.d.ts +1 -0
- package/dist/types/examples/Chains/oasis-wrose-transfer-trigger.d.ts +1 -0
- package/dist/types/examples/DeFi/AAVE/aave-trigger-ltv.d.ts +1 -0
- package/dist/types/examples/GettingStarted/simpleEthPriceMonitor.d.ts +1 -0
- package/dist/types/examples/UseCases/LendingAggregator/lending-aggregator-2-protocols.d.ts +4 -0
- package/dist/types/examples/UseCases/LendingAggregator/stop-lending-aggregator-2-protocols.d.ts +7 -0
- package/dist/types/examples/test.d.ts +7 -0
- package/dist/types/src/constants/Blocks.d.ts +31 -0
- package/dist/types/src/constants/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,64 +1,224 @@
|
|
|
1
1
|
# Otomato SDK
|
|
2
2
|
|
|
3
|
-
The Otomato SDK empowers users to automate
|
|
3
|
+
The Otomato SDK empowers users to automate crypto-related behaviors. It provides intuitive tools to respond to market dynamics by abstracting complexities.
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
|
-
- [Features](#features)
|
|
8
|
-
- [Installation](#installation)
|
|
9
7
|
- [Getting Started](#getting-started)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Setting Up Environment Variables](#setting-up-environment-variables)
|
|
10
|
+
- [Simple ETH Price Monitor Example](#simple-eth-price-monitor-example)
|
|
11
|
+
- [Running the First Example](#running-the-first-example)
|
|
10
12
|
- [Authentication](#authentication)
|
|
11
|
-
|
|
12
|
-
- [
|
|
13
|
-
- [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
13
|
+
- [Going Further](#going-further)
|
|
14
|
+
- [Core Concepts](#core-concepts)
|
|
15
|
+
- [Workflow](#workflow)
|
|
16
|
+
- [Node](#node)
|
|
17
|
+
- [Trigger](#trigger)
|
|
18
|
+
- [Action](#action)
|
|
19
|
+
- [Edge](#edge)
|
|
20
|
+
- [Examples](#examples)
|
|
21
|
+
- [Swap and Deposit Workflow](#swap-and-deposit-workflow)
|
|
22
|
+
- [ETH Price Monitoring with Split Conditions](#eth-price-monitoring-with-split-conditions)
|
|
23
|
+
- [API Reference](#api-reference)
|
|
24
|
+
- [Features](#features)
|
|
23
25
|
- [Contributing](#contributing)
|
|
24
26
|
- [License](#license)
|
|
25
27
|
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
- **Automate Web3 Actions**: Create automated workflows to interact with smart contracts, perform token swaps, send notifications, and more.
|
|
29
|
-
- **Smart Account Integration**: Utilize Smart Accounts (ERC-4337) for secure and efficient automation.
|
|
30
|
-
- **Building Block System**: Combine triggers and actions to build complex strategies without writing low-level code.
|
|
31
|
-
- **Session Key Permissions**: Maintain control over your assets with explicit action authorizations.
|
|
32
|
-
- **Extensible Architecture**: Easily add new triggers, actions, and services.
|
|
28
|
+
## Getting Started
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
### Installation
|
|
35
31
|
|
|
36
32
|
```bash
|
|
37
33
|
npm install otomato-sdk
|
|
34
|
+
```
|
|
38
35
|
|
|
39
|
-
|
|
36
|
+
### Setting Up Environment Variables
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
For the first example, set the following environment variables:
|
|
39
|
+
* `API_URL`: Should be set to `https://api.otomato.xyz/api`.
|
|
40
|
+
* `AUTH_TOKEN`: Obtain this by following the [Authentication](#authentication) instructions.
|
|
41
|
+
|
|
42
|
+
Alternatively, you can replace these placeholder values directly in the example code.
|
|
43
|
+
|
|
44
|
+
### Simple ETH Price Monitor Example
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
This minimal example monitors the ETH price and sends an email notification if it drops below $2500.
|
|
44
47
|
|
|
45
48
|
```js
|
|
46
|
-
import {
|
|
49
|
+
import { ACTIONS, Action, TRIGGERS, Trigger, Workflow, CHAINS, getTokenFromSymbol, Edge, apiServices } from 'otomato-sdk';
|
|
50
|
+
import dotenv from 'dotenv';
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
const address = 'YOUR_WALLET_ADDRESS';
|
|
50
|
-
const chainId = CHAINS.ETHEREUM;
|
|
51
|
-
const accessCode = 'YOUR_ACCESS_CODE';
|
|
52
|
+
dotenv.config();
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const
|
|
54
|
+
async function simpleEthPriceMonitor() {
|
|
55
|
+
const API_URL = process.env.API_URL || "https://api.otomato.xyz/api";
|
|
56
|
+
const EMAIL_ADDRESS = process.env.EMAIL_ADDRESS || "your-email@example.com"; // Replace with your email or set as ENV var
|
|
57
|
+
const AUTH_TOKEN = process.env.AUTH_TOKEN;
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
if (!AUTH_TOKEN) {
|
|
60
|
+
console.error("Error: AUTH_TOKEN is not set. Please set it as an environment variable or directly in the code.");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (EMAIL_ADDRESS === "your-email@example.com") {
|
|
64
|
+
console.warn("Warning: EMAIL_ADDRESS is set to the default. Replace with your email to receive notifications.");
|
|
65
|
+
}
|
|
66
|
+
apiServices.setUrl(API_URL);
|
|
67
|
+
apiServices.setAuth(AUTH_TOKEN);
|
|
68
|
+
|
|
69
|
+
const priceTrigger = new Trigger(TRIGGERS.TOKENS.PRICE.PRICE_MOVEMENT_AGAINST_CURRENCY);
|
|
70
|
+
priceTrigger.setChainId(CHAINS.BASE); // Using Base network
|
|
71
|
+
priceTrigger.setComparisonValue(2500);
|
|
72
|
+
priceTrigger.setCondition("lte");
|
|
73
|
+
priceTrigger.setParams("currency", "USD");
|
|
74
|
+
priceTrigger.setContractAddress(getTokenFromSymbol(CHAINS.BASE, "WETH").contractAddress); // Using WETH on Base as an example
|
|
75
|
+
|
|
76
|
+
const emailAction = new Action(ACTIONS.NOTIFICATIONS.EMAIL.SEND_EMAIL);
|
|
77
|
+
emailAction.setParams("to", EMAIL_ADDRESS);
|
|
78
|
+
emailAction.setParams("subject", "ETH Price Alert");
|
|
79
|
+
emailAction.setParams("body", `ETH price is now below $2500. Current value: ${priceTrigger.getOutputVariableName('price')}`);
|
|
80
|
+
|
|
81
|
+
const workflow = new Workflow("Simple ETH Price Monitor", [priceTrigger, emailAction], [new Edge({ source: priceTrigger, target: emailAction })]);
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const { success: createSuccess, error: createError } = await workflow.create();
|
|
85
|
+
if (!createSuccess) {
|
|
86
|
+
console.error(`Error creating workflow: ${createError}`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
console.log(`Workflow "${workflow.name}" created with ID: ${workflow.id}. Current state: ${workflow.getState()}`);
|
|
90
|
+
|
|
91
|
+
const { success: runSuccess, error: runError } = await workflow.run();
|
|
92
|
+
if (!runSuccess) {
|
|
93
|
+
console.error(`Error running workflow: ${runError}`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
console.log(`Workflow "${workflow.name}" is now running. Current state: ${workflow.getState()}`);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error(`An unexpected error occurred: ${error}`);
|
|
99
|
+
}
|
|
58
100
|
}
|
|
101
|
+
|
|
102
|
+
simpleEthPriceMonitor();
|
|
59
103
|
```
|
|
60
104
|
|
|
61
|
-
###
|
|
105
|
+
### Running the First Example
|
|
106
|
+
|
|
107
|
+
1. **Install the SDK**:
|
|
108
|
+
If you haven't already, install the SDK using npm:
|
|
109
|
+
```bash
|
|
110
|
+
npm install otomato-sdk
|
|
111
|
+
```
|
|
112
|
+
2. **Set Environment Variables (Recommended)**:
|
|
113
|
+
Create a `.env` file in your project's root directory:
|
|
114
|
+
```
|
|
115
|
+
API_URL=https://api.otomato.xyz/api
|
|
116
|
+
AUTH_TOKEN=your-auth-token
|
|
117
|
+
EMAIL_ADDRESS=your-email@example.com
|
|
118
|
+
```
|
|
119
|
+
Replace `your-auth-token` and `your-email@example.com` with your actual credentials.
|
|
120
|
+
Alternatively, modify these values directly in the `simple_eth_price_monitor.js` file.
|
|
121
|
+
3. **Save the code**:
|
|
122
|
+
Save the example code as `simple_eth_price_monitor.js` in your project.
|
|
123
|
+
4. **Install dependencies**:
|
|
124
|
+
If using a `.env` file, install `dotenv`. The SDK itself is already handled by step 1.
|
|
125
|
+
```bash
|
|
126
|
+
npm install dotenv
|
|
127
|
+
```
|
|
128
|
+
5. **Run the script**:
|
|
129
|
+
Execute the script using Node.js:
|
|
130
|
+
```bash
|
|
131
|
+
node simple_eth_price_monitor.js
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Authentication
|
|
135
|
+
|
|
136
|
+
Before interacting with the Otomato SDK, you need to authenticate your account. This is done by obtaining an `AUTH_TOKEN`.
|
|
137
|
+
|
|
138
|
+
**How to get an `AUTH_TOKEN`:**
|
|
139
|
+
|
|
140
|
+
1. **Through the Web App (recommended and fastest way)**:
|
|
141
|
+
This is the primary and recommended method. You can obtain a token by visiting `[Your Web App URL Here - e.g., https://app.otomato.xyz/settings/api-keys]`.
|
|
142
|
+
Sign in with your wallet, and you'll typically find the token in your account settings or a dedicated API keys section.
|
|
143
|
+
|
|
144
|
+
2. **Programmatically (non-recommended)**:
|
|
145
|
+
This method involves generating a login payload, signing it with your wallet, and then exchanging the signature for an `AUTH_TOKEN`. This is a secondary method and generally not recommended for most users.
|
|
146
|
+
```js
|
|
147
|
+
import { apiServices, CHAINS } from 'otomato-sdk'; // Ensure CHAINS is imported if used
|
|
148
|
+
|
|
149
|
+
// Example: (Replace with your actual wallet address, access code, owner address, and signing function)
|
|
150
|
+
async function getAuthToken(walletAddress, accessCode, ownerAddress, signFunction) {
|
|
151
|
+
try {
|
|
152
|
+
// Ensure chainId is defined, e.g., CHAINS.ETHEREUM or your specific chain
|
|
153
|
+
const chainId = CHAINS.ETHEREUM;
|
|
154
|
+
const loginPayload = await apiServices.generateLoginPayload(walletAddress, chainId, accessCode, ownerAddress);
|
|
155
|
+
|
|
156
|
+
// The signFunction needs to be implemented by you, using your preferred wallet library (ethers.js, web3.js, etc.)
|
|
157
|
+
// It takes the JSON string of loginPayload and returns a signature.
|
|
158
|
+
// Example: const signature = await ethersSigner.signMessage(JSON.stringify(loginPayload));
|
|
159
|
+
const signature = await signFunction(JSON.stringify(loginPayload));
|
|
160
|
+
|
|
161
|
+
const { token } = await apiServices.getToken(loginPayload, signature);
|
|
162
|
+
apiServices.setAuth(token); // Sets token for subsequent SDK use
|
|
163
|
+
console.log("Authentication successful. AUTH_TOKEN:", token);
|
|
164
|
+
return token;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.error("Programmatic authentication failed:", error);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// --- How to use getAuthToken (Example Placeholder) ---
|
|
172
|
+
// This is a conceptual guide. You'll need to integrate with your specific wallet setup.
|
|
173
|
+
//
|
|
174
|
+
// import { Wallet } from 'ethers'; // Example using ethers.js
|
|
175
|
+
//
|
|
176
|
+
// async function mySignFunction(payloadString) {
|
|
177
|
+
// const privateKey = "YOUR_PRIVATE_KEY"; // Keep private keys secure!
|
|
178
|
+
// const wallet = new Wallet(privateKey);
|
|
179
|
+
// return await wallet.signMessage(payloadString);
|
|
180
|
+
// }
|
|
181
|
+
//
|
|
182
|
+
// const MY_WALLET_ADDRESS = "0xYourWalletAddress";
|
|
183
|
+
// const MY_ACCESS_CODE = "YourAccessCode"; // If applicable
|
|
184
|
+
// const MY_OWNER_WALLET_ADDRESS = "0xOwnerWalletAddress"; // If applicable
|
|
185
|
+
//
|
|
186
|
+
// getAuthToken(MY_WALLET_ADDRESS, MY_ACCESS_CODE, MY_OWNER_WALLET_ADDRESS, mySignFunction)
|
|
187
|
+
// .then(token => {
|
|
188
|
+
// // Use the token for your Otomato SDK operations
|
|
189
|
+
// })
|
|
190
|
+
// .catch(error => console.error("Failed to get AUTH_TOKEN:", error));
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Remember to keep your `AUTH_TOKEN` secure. Do not commit it directly into version control, especially if hardcoded. Using environment variables (as shown in the first example) is a good practice.
|
|
194
|
+
|
|
195
|
+
## Going Further
|
|
196
|
+
|
|
197
|
+
### Core Concepts
|
|
198
|
+
|
|
199
|
+
A brief overview of the main components in the Otomato SDK:
|
|
200
|
+
|
|
201
|
+
### Workflow
|
|
202
|
+
|
|
203
|
+
A Workflow is the top-level container for your automation logic. It consists of Nodes (Triggers and Actions) connected by Edges, defining the sequence of operations. Key properties include `id`, `name`, `nodes`, `edges`, and `state`.
|
|
204
|
+
|
|
205
|
+
### Node
|
|
206
|
+
A Node is a fundamental building block in a Workflow, representing either a Trigger or an Action. It has an `id`, a `blockId` (type of node), `parameters` for configuration, and `position` (for UI).
|
|
207
|
+
|
|
208
|
+
### Trigger
|
|
209
|
+
A Trigger is a special type of Node that starts a Workflow when specific conditions are met (e.g., price movement, new transaction). Methods like `setCondition()` and `setComparisonValue()` configure its behavior for polling-based triggers.
|
|
210
|
+
|
|
211
|
+
### Action
|
|
212
|
+
An Action is a Node that performs a task within a Workflow (e.g., swap tokens, send a notification, interact with a smart contract). Use `setParams()` to configure action-specific parameters.
|
|
213
|
+
|
|
214
|
+
### Edge
|
|
215
|
+
An Edge connects two Nodes (a source and a target), defining the direction of flow and dependencies within a Workflow. It can optionally have a `label` and a `value` for conditional branching.
|
|
216
|
+
|
|
217
|
+
For more details on properties and methods, refer to the [API Reference](#api-reference) or specific examples.
|
|
218
|
+
|
|
219
|
+
### Examples
|
|
220
|
+
|
|
221
|
+
#### Creating a workflow
|
|
62
222
|
|
|
63
223
|
A Workflow is a collection of Nodes (Triggers and Actions) connected by Edges.
|
|
64
224
|
|
|
@@ -88,7 +248,7 @@ const edge = new Edge({ source: priceTrigger, target: swapAction });
|
|
|
88
248
|
const workflow = new Workflow('Swap on Price Trigger', [priceTrigger, swapAction], [edge]);
|
|
89
249
|
```
|
|
90
250
|
|
|
91
|
-
|
|
251
|
+
#### Running a Workflow
|
|
92
252
|
|
|
93
253
|
```js
|
|
94
254
|
// Publish the Workflow
|
|
@@ -107,57 +267,6 @@ if (creationResult.success) {
|
|
|
107
267
|
}
|
|
108
268
|
```
|
|
109
269
|
|
|
110
|
-
## Core concepts
|
|
111
|
-
|
|
112
|
-
### Workflow
|
|
113
|
-
|
|
114
|
-
A Workflow is a container for nodes (triggers and actions) and the edges that connect them.
|
|
115
|
-
|
|
116
|
-
**Properties**:
|
|
117
|
-
• `id`: Unique identifier.
|
|
118
|
-
• `name`: Name of the workflow.
|
|
119
|
-
• `nodes`: Array of Node instances.
|
|
120
|
-
• `edges`: Array of Edge instances.
|
|
121
|
-
• `state`: Current state (inactive, active, failed, completed, waiting).
|
|
122
|
-
|
|
123
|
-
### node
|
|
124
|
-
|
|
125
|
-
Node is an abstract class representing either a Trigger or an Action.
|
|
126
|
-
|
|
127
|
-
**Properties**:
|
|
128
|
-
• `id`: Unique identifier.
|
|
129
|
-
• `blockId`: Identifier for the block type.
|
|
130
|
-
• `parameters`: Key-value pairs for node configuration.
|
|
131
|
-
• `position`: Coordinates for UI placement.
|
|
132
|
-
|
|
133
|
-
### Trigger
|
|
134
|
-
|
|
135
|
-
A Trigger initiates the workflow based on certain conditions.
|
|
136
|
-
|
|
137
|
-
**Methods**:
|
|
138
|
-
• `setCondition(value)`: Sets the logical condition (lt, gt, etc.). This works only for polling based triggers.
|
|
139
|
-
• `setComparisonValue(value)`: Sets the value to compare against. This works only for polling based triggers.
|
|
140
|
-
|
|
141
|
-
### Action
|
|
142
|
-
|
|
143
|
-
An Action performs operations like swapping tokens, sending notifications, etc.
|
|
144
|
-
|
|
145
|
-
**Methods**:
|
|
146
|
-
• `setParams(key, value)`: Sets parameters specific to the action.
|
|
147
|
-
|
|
148
|
-
### Edges
|
|
149
|
-
|
|
150
|
-
An Edge connects two nodes, defining the workflow’s execution path.
|
|
151
|
-
|
|
152
|
-
**Properties**:
|
|
153
|
-
• `source`: Source Node.
|
|
154
|
-
• `target`: Target Node.
|
|
155
|
-
• `label`: Optional label for the edge.
|
|
156
|
-
• `value`: Optional value for conditional edges.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
## Examples
|
|
160
|
-
|
|
161
270
|
### Swap and Deposit Workflow
|
|
162
271
|
|
|
163
272
|
This example demonstrates how to create a workflow that swaps tokens and then deposits them into a lending platform.
|
|
@@ -235,7 +344,9 @@ const edge3 = new Edge({ source: conditionTrue, target: slackAction, label: 'tru
|
|
|
235
344
|
const workflow = new Workflow('ETH Price Monitoring', [ethPriceTrigger, splitAction, conditionTrue, slackAction], [edge1, edge2, edge3]);
|
|
236
345
|
```
|
|
237
346
|
|
|
238
|
-
|
|
347
|
+
### API Reference
|
|
348
|
+
|
|
349
|
+
This section provides a high-level overview of key classes and their primary methods. For exhaustive details, consult the full API documentation (if available separately) or examine the SDK's source code.
|
|
239
350
|
|
|
240
351
|
### Workflow Class
|
|
241
352
|
|
|
@@ -267,6 +378,23 @@ const workflow = new Workflow('ETH Price Monitoring', [ethPriceTrigger, splitAct
|
|
|
267
378
|
- `toJSON()`: Serializes the edge.
|
|
268
379
|
- `delete()`: Deletes the edge.
|
|
269
380
|
|
|
381
|
+
### Features
|
|
382
|
+
|
|
383
|
+
- **Automate Web3 Operations**: Build workflows for smart contract interactions, token swaps, notifications, etc.
|
|
384
|
+
- **Smart Account Ready**: Designed for secure automation with Smart Accounts (ERC-4337).
|
|
385
|
+
- **Modular Design**: Use triggers and actions as building blocks for complex strategies.
|
|
386
|
+
- **Controlled Permissions**: Leverage session keys for fine-grained control over asset interactions.
|
|
387
|
+
- **Extensible**: Add custom triggers, actions, and services.
|
|
388
|
+
|
|
389
|
+
## Contributing
|
|
390
|
+
|
|
391
|
+
We welcome contributions to enhance the Otomato SDK! Please follow these steps:
|
|
392
|
+
|
|
393
|
+
1. Fork the repository.
|
|
394
|
+
2. Create a new branch.
|
|
395
|
+
3. Make your changes, including clear comments and tests (if applicable).
|
|
396
|
+
4. Submit a pull request for review.
|
|
397
|
+
|
|
270
398
|
## License
|
|
271
399
|
|
|
272
400
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|