otomato-sdk 1.3.3 → 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 +2 -11
- package/dist/src/utils/helpers.js +19 -0
- package/dist/src/utils/typeValidator.js +34 -8
- package/dist/test/action.spec.js +69 -6
- package/dist/test/automation.spec.js +8 -8
- package/dist/test/helpers.spec.js +23 -0
- package/dist/test/node.spec.js +11 -19
- package/dist/test/trigger.spec.js +79 -11
- 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 +1 -3
- 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 +2 -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 +2 -14
- package/src/utils/helpers.ts +9 -0
- package/src/utils/typeValidator.ts +28 -11
- package/test/action.spec.ts +64 -7
- package/test/automation.spec.ts +8 -8
- package/test/helpers.spec.ts +16 -0
- package/test/node.spec.ts +11 -19
- package/test/trigger.spec.ts +76 -11
package/README.md
CHANGED
|
@@ -22,13 +22,13 @@ npm install otomato-sdk
|
|
|
22
22
|
Here's how to create a trigger using the Otomato SDK:
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
|
-
import { Trigger, TRIGGERS, CHAINS,
|
|
25
|
+
import { Trigger, TRIGGERS, CHAINS, getTokenFromSymbol } from 'otomato-sdk';
|
|
26
26
|
|
|
27
27
|
const transferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
28
28
|
transferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
29
29
|
transferTrigger.setParams("value", 1000);
|
|
30
30
|
transferTrigger.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
31
|
-
transferTrigger.setContractAddress(
|
|
31
|
+
transferTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
32
32
|
|
|
33
33
|
console.log(transferTrigger.toJSON());
|
|
34
34
|
```
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { ACTIONS,
|
|
1
|
+
import { ACTIONS, getTokenFromSymbol, CHAINS, Action } from '../src/index.js';
|
|
2
2
|
const createAction = () => {
|
|
3
3
|
// Create an ERC20 transfer action
|
|
4
4
|
const transferAction = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
5
5
|
transferAction.setChainId(CHAINS.ETHEREUM);
|
|
6
6
|
transferAction.setParams("value", 1000);
|
|
7
7
|
transferAction.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
8
|
-
transferAction.setContractAddress(
|
|
9
|
-
console.log(transferAction.toJSON());
|
|
8
|
+
transferAction.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
9
|
+
console.log(JSON.stringify(transferAction.toJSON()));
|
|
10
10
|
// Create an SMS notification action
|
|
11
11
|
const smsAction = new Action(ACTIONS.NOTIFICATIONS.DISCORD.SEND_MESSAGE);
|
|
12
|
-
smsAction.setParams("
|
|
13
|
-
smsAction.setParams("
|
|
12
|
+
smsAction.setParams("webhook", "https://url");
|
|
13
|
+
smsAction.setParams("message", "This is a test message");
|
|
14
14
|
console.log(smsAction.toJSON());
|
|
15
15
|
// Create a Slack notification action
|
|
16
16
|
const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
17
17
|
slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
|
|
18
|
-
slackAction.setParams("
|
|
18
|
+
slackAction.setParams("message", "This is a test message");
|
|
19
19
|
console.log(slackAction.toJSON());
|
|
20
20
|
};
|
|
21
21
|
createAction();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TRIGGERS,
|
|
1
|
+
import { TRIGGERS, getTokenFromSymbol, TOKENS, CHAINS, Trigger } from '../src/index.js';
|
|
2
2
|
const generateDefaultTriggers = () => {
|
|
3
3
|
const triggersList = [];
|
|
4
4
|
const createDefaultTrigger = (trigger) => {
|
|
@@ -8,7 +8,7 @@ const generateDefaultTriggers = () => {
|
|
|
8
8
|
triggerInstance.setChainId(CHAINS.ETHEREUM);
|
|
9
9
|
}
|
|
10
10
|
if (trigger.parameters.some((p) => p.key === "contractAddress")) {
|
|
11
|
-
triggerInstance.setContractAddress(
|
|
11
|
+
triggerInstance.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
12
12
|
}
|
|
13
13
|
if (trigger.parameters.some((p) => p.key === "condition")) {
|
|
14
14
|
triggerInstance.setCondition('>');
|
|
@@ -16,9 +16,6 @@ const generateDefaultTriggers = () => {
|
|
|
16
16
|
if (trigger.parameters.some((p) => p.key === "comparisonValue")) {
|
|
17
17
|
triggerInstance.setComparisonValue(1000);
|
|
18
18
|
}
|
|
19
|
-
if (trigger.parameters.some((p) => p.key === "interval")) {
|
|
20
|
-
triggerInstance.setInterval(60000); // 1 minute interval
|
|
21
|
-
}
|
|
22
19
|
if (trigger.parameters.some((p) => p.key === "abiParams.account")) {
|
|
23
20
|
triggerInstance.setParams('account', '0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6');
|
|
24
21
|
}
|
|
@@ -56,7 +53,6 @@ function generateTriggersForAllTokens(chain) {
|
|
|
56
53
|
balanceTrigger.setContractAddress(token.contractAddress);
|
|
57
54
|
balanceTrigger.setCondition(">");
|
|
58
55
|
balanceTrigger.setComparisonValue(10);
|
|
59
|
-
balanceTrigger.setInterval(5000);
|
|
60
56
|
triggersList.push(balanceTrigger);
|
|
61
57
|
});
|
|
62
58
|
return triggersList.map(t => t.toJSON());
|
|
@@ -67,14 +63,13 @@ const generateSpecificTriggers = () => {
|
|
|
67
63
|
transferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
68
64
|
transferTrigger.setParams("value", 1000);
|
|
69
65
|
transferTrigger.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
70
|
-
transferTrigger.setContractAddress(
|
|
66
|
+
transferTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
71
67
|
const balanceTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.BALANCE);
|
|
72
68
|
balanceTrigger.setChainId(CHAINS.ETHEREUM);
|
|
73
69
|
balanceTrigger.setParams("account", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
74
|
-
balanceTrigger.setContractAddress(
|
|
70
|
+
balanceTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
75
71
|
balanceTrigger.setCondition(">");
|
|
76
72
|
balanceTrigger.setComparisonValue(45000);
|
|
77
|
-
balanceTrigger.setInterval(5000);
|
|
78
73
|
const spliceFiSwapTrigger = new Trigger(TRIGGERS.YIELD.SPLICE_FI.SWAP);
|
|
79
74
|
spliceFiSwapTrigger.setParams("caller", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
80
75
|
spliceFiSwapTrigger.setParams("market", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
@@ -133,4 +128,4 @@ const triggersList = [
|
|
|
133
128
|
...generateDefaultTriggers(),
|
|
134
129
|
...generateSpecificTriggers()
|
|
135
130
|
];
|
|
136
|
-
console.log(
|
|
131
|
+
console.log(triggersList);
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 { TRIGGERS, CHAINS, Trigger, getTokenFromSymbol, convertToTokenUnits } from '../src/index.js';
|
|
11
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const transferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
13
|
+
const contractAddr = getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress;
|
|
14
|
+
console.log(contractAddr);
|
|
15
|
+
transferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
16
|
+
transferTrigger.setParams("value", yield convertToTokenUnits(1, CHAINS.ETHEREUM, contractAddr));
|
|
17
|
+
transferTrigger.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
18
|
+
transferTrigger.setContractAddress(contractAddr);
|
|
19
|
+
console.log(JSON.stringify(transferTrigger.toJSON()));
|
|
20
|
+
});
|
|
21
|
+
main();
|
|
@@ -7,36 +7,46 @@ 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 { ACTIONS, Action, TRIGGERS, Trigger, Workflow, CHAINS,
|
|
10
|
+
import { ACTIONS, Action, TRIGGERS, Trigger, Workflow, CHAINS, getTokenFromSymbol, Edge, apiServices } from '../src/index.js';
|
|
11
11
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
12
|
apiServices.setAuth("eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIweDdjRUI4ZDgxNDdBYWE5ZEI4MUFjQkRGRTVjMzA1MERGQ2ZGMTg1MzciLCJzdWIiOiIweDg3RkU4YjRmMkZlODM3MGY2Y0M5YTk2MzQ0MmYwN0IwMmY0OTA5QTciLCJhdWQiOiJvdG9tYXRvLXRlc3QubmV0bGlmeS5hcHAiLCJleHAiOjE3MjMzODMxOTksIm5iZiI6MTcyMDc4OTM5OSwiaWF0IjoxNzIwNzkxMTk5LCJqdGkiOiIweDY4ZDkxOWEyMGZiYjIyNDUwZDZmOTFjMzM2ZTBmYjBjMmYyYTc3MmU3Zjg4NWU1ZjRmNzg1NTM2ZGIyYTY5YTAiLCJjdHgiOnt9fQ.MHgyOTM1NTM3MWYwOWM1YzllNWE3YjI4MjVkZTNjMDljZTkwMTQ3OTQwZmU1ZWRlMjM5YTk0MmFjYTQ5YTcwZWI0MGJlNmJiZDk2MDA4ZTIxMzJmNGM3ZTVlZGIzZDZiZjYyMDE4Mzc1MzUwMTRmNTc0ODM0ZDk4YWU3NDQwNDQzOTFi");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ref: 'n-1',
|
|
21
|
-
});
|
|
22
|
-
usdcTransferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
23
|
-
usdcTransferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
24
|
-
usdcTransferTrigger.setPosition(0, 0);
|
|
13
|
+
const trigger = new Trigger(TRIGGERS.PRICE_ACTION.ON_CHAIN_PRICE_MOVEMENT.PRICE_MOVEMENT_AGAINST_CURRENCY);
|
|
14
|
+
trigger.setChainId(CHAINS.MODE);
|
|
15
|
+
trigger.setComparisonValue(3000);
|
|
16
|
+
trigger.setCondition('gte');
|
|
17
|
+
trigger.setParams('currency', 'USD');
|
|
18
|
+
trigger.setContractAddress(getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress);
|
|
19
|
+
trigger.setPosition(0, 0);
|
|
25
20
|
const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
26
|
-
slackAction.setParams("webhook", "https://hooks.slack.com/services/
|
|
27
|
-
slackAction.setParams("message", "
|
|
21
|
+
slackAction.setParams("webhook", "https://hooks.slack.com/services/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");
|
|
22
|
+
slackAction.setParams("message", "Notification from the SDK");
|
|
28
23
|
slackAction.setPosition(0, -10);
|
|
29
|
-
const
|
|
24
|
+
const transferAction = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
25
|
+
transferAction.setChainId(CHAINS.ETHEREUM);
|
|
26
|
+
transferAction.setParams("value", 1000);
|
|
27
|
+
transferAction.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
28
|
+
transferAction.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
29
|
+
const workflow = new Workflow("test from SDK", [trigger, slackAction, transferAction]);
|
|
30
30
|
const edge = new Edge({
|
|
31
|
-
source:
|
|
31
|
+
source: trigger,
|
|
32
32
|
target: slackAction,
|
|
33
33
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
console.log(`Workflow ID: ${workflow.id}`); // This will print the ID of the created workflow
|
|
38
|
-
workflow.nodes.forEach(node => {
|
|
39
|
-
console.log(`Node ${node.getRef()} ID: ${node.id}`);
|
|
34
|
+
const edge2 = new Edge({
|
|
35
|
+
source: slackAction,
|
|
36
|
+
target: transferAction,
|
|
40
37
|
});
|
|
38
|
+
workflow.addEdge(edge);
|
|
39
|
+
workflow.addEdge(edge2);
|
|
40
|
+
console.log(JSON.stringify(workflow.toJSON()));
|
|
41
|
+
const creationResult = yield workflow.create();
|
|
42
|
+
if (!creationResult.success) {
|
|
43
|
+
throw new Error("An error occurred when publishing the workflow");
|
|
44
|
+
}
|
|
45
|
+
console.log(workflow.id);
|
|
46
|
+
const runResult = yield workflow.run();
|
|
47
|
+
if (!runResult.success) {
|
|
48
|
+
throw new Error("An error occurred when running the workflow");
|
|
49
|
+
}
|
|
50
|
+
console.log(`Workflow ${workflow.id} is running`);
|
|
41
51
|
});
|
|
42
52
|
main();
|
|
@@ -11,6 +11,6 @@ import { Workflow, apiServices } from '../src/index.js';
|
|
|
11
11
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
12
|
apiServices.setAuth("eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIweDdjRUI4ZDgxNDdBYWE5ZEI4MUFjQkRGRTVjMzA1MERGQ2ZGMTg1MzciLCJzdWIiOiIweDg3RkU4YjRmMkZlODM3MGY2Y0M5YTk2MzQ0MmYwN0IwMmY0OTA5QTciLCJhdWQiOiJvdG9tYXRvLXRlc3QubmV0bGlmeS5hcHAiLCJleHAiOjE3MjMzODMxOTksIm5iZiI6MTcyMDc4OTM5OSwiaWF0IjoxNzIwNzkxMTk5LCJqdGkiOiIweDY4ZDkxOWEyMGZiYjIyNDUwZDZmOTFjMzM2ZTBmYjBjMmYyYTc3MmU3Zjg4NWU1ZjRmNzg1NTM2ZGIyYTY5YTAiLCJjdHgiOnt9fQ.MHgyOTM1NTM3MWYwOWM1YzllNWE3YjI4MjVkZTNjMDljZTkwMTQ3OTQwZmU1ZWRlMjM5YTk0MmFjYTQ5YTcwZWI0MGJlNmJiZDk2MDA4ZTIxMzJmNGM3ZTVlZGIzZDZiZjYyMDE4Mzc1MzUwMTRmNTc0ODM0ZDk4YWU3NDQwNDQzOTFi");
|
|
13
13
|
const workflow = yield new Workflow().load("0b9bd533-339c-42b5-9ed3-a6a40fcfa8d3");
|
|
14
|
-
console.log(workflow);
|
|
14
|
+
console.log(JSON.stringify(workflow.nodes[1]));
|
|
15
15
|
});
|
|
16
16
|
main();
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { CHAINS, apiServices } from '../src/index.js';
|
|
11
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const address = "0x9b1E25bBbee162A26B67B1fb00cf4d67157656F6";
|
|
13
|
+
let payload = yield apiServices.generateLoginPayload(address, CHAINS.ETHEREUM);
|
|
14
|
+
// we replace the payload to fit the signature, don't do that in your implementation
|
|
15
|
+
const signature = '0x92a3b551ff2bc2eb9a3537a0b477af14c33e649c3479c204bb0a4da95bfee89e4ae966e5d555d34c5dfcf3899910c58e936375634f5b0f58978139d25b5b54761b';
|
|
16
|
+
payload = {
|
|
17
|
+
address: '0x9b1E25bBbee162A26B67B1fb00cf4d67157656F6',
|
|
18
|
+
chain_id: '1',
|
|
19
|
+
domain: 'otomato-test.netlify.app',
|
|
20
|
+
expiration_time: '2024-07-16T16:57:34.363Z',
|
|
21
|
+
invalid_before: '2024-07-16T15:57:34.363Z',
|
|
22
|
+
issued_at: '2024-07-16T16:27:34.363Z',
|
|
23
|
+
nonce: '0x4ed46b76a2ccb458bc84bfc3f8aeb43bbc6a2b2f1ae5ee9f10c13ba6bd05f832',
|
|
24
|
+
statement: 'Please ensure that the domain above matches the URL of the current website.',
|
|
25
|
+
version: '1'
|
|
26
|
+
};
|
|
27
|
+
const { token } = yield apiServices.getToken(payload, signature);
|
|
28
|
+
const verify = yield apiServices.verifyToken(token);
|
|
29
|
+
console.log(token);
|
|
30
|
+
console.log(verify);
|
|
31
|
+
});
|
|
32
|
+
main();
|
|
@@ -93,7 +93,7 @@ export const TRIGGERS = {
|
|
|
93
93
|
"SPLICE_FI": {
|
|
94
94
|
"description": "Split any yield-bearing asset into separate yield and principal components",
|
|
95
95
|
"chains": [
|
|
96
|
-
|
|
96
|
+
34443
|
|
97
97
|
],
|
|
98
98
|
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/splicefi.png",
|
|
99
99
|
"SWAP": {
|
|
@@ -244,7 +244,7 @@ export const TRIGGERS = {
|
|
|
244
244
|
"ASTARIA": {
|
|
245
245
|
"description": "Astaria is an oracle-less, intent-based, fixed-rate lending protocol supporting unlimited loan durations for any asset",
|
|
246
246
|
"chains": [
|
|
247
|
-
|
|
247
|
+
34443
|
|
248
248
|
],
|
|
249
249
|
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/astaria.png",
|
|
250
250
|
"LEND_RECALLED": {
|
|
@@ -278,7 +278,7 @@ export const TRIGGERS = {
|
|
|
278
278
|
"ODOS": {
|
|
279
279
|
"description": "Smart Order Routing across multiple blockchain protocols, 700+ Liquidity Sources and thousands of token pairs, delivering ultimate savings to users",
|
|
280
280
|
"chains": [
|
|
281
|
-
|
|
281
|
+
34443,
|
|
282
282
|
1
|
|
283
283
|
],
|
|
284
284
|
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/odos.jpg",
|
|
@@ -329,7 +329,7 @@ export const TRIGGERS = {
|
|
|
329
329
|
"MODE_NAME_SERVICE": {
|
|
330
330
|
"description": "Next generation of Mode Mainnet Domains",
|
|
331
331
|
"chains": [
|
|
332
|
-
|
|
332
|
+
34443
|
|
333
333
|
],
|
|
334
334
|
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/modens.png",
|
|
335
335
|
"NAME_REGISTERED": {
|
|
@@ -7,7 +7,7 @@ export const TOKENS = {
|
|
|
7
7
|
decimals: 6
|
|
8
8
|
},
|
|
9
9
|
],
|
|
10
|
-
|
|
10
|
+
34443: [
|
|
11
11
|
{
|
|
12
12
|
contractAddress: "0x0000000000000000000000000000000000000000",
|
|
13
13
|
name: "ETH",
|
|
@@ -93,14 +93,24 @@ export const NFTS = {
|
|
|
93
93
|
name: "Lil Pudgies"
|
|
94
94
|
},
|
|
95
95
|
],
|
|
96
|
-
|
|
96
|
+
34443: [
|
|
97
97
|
{
|
|
98
98
|
contractAddress: "0x2ad86eeec513ac16804bb05310214c3fd496835b",
|
|
99
99
|
name: "Space id"
|
|
100
100
|
}
|
|
101
101
|
]
|
|
102
102
|
};
|
|
103
|
-
export function getToken(chain,
|
|
103
|
+
export function getToken(chain, contractAddress) {
|
|
104
|
+
if (!(chain in TOKENS)) {
|
|
105
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
106
|
+
}
|
|
107
|
+
const token = TOKENS[chain].find(token => token.contractAddress.toLowerCase() === contractAddress.toLowerCase());
|
|
108
|
+
if (!token) {
|
|
109
|
+
throw new Error(`Token with contract address ${contractAddress} not found on chain ${chain}`);
|
|
110
|
+
}
|
|
111
|
+
return token;
|
|
112
|
+
}
|
|
113
|
+
export function getTokenFromSymbol(chain, symbol) {
|
|
104
114
|
if (!(chain in TOKENS)) {
|
|
105
115
|
throw new Error(`Unsupported chain: ${chain}`);
|
|
106
116
|
}
|
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
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 { Node } from './Node.js';
|
|
11
|
+
import { ACTIONS } from '../constants/Blocks.js';
|
|
12
|
+
import { typeIsNumber } from '../utils/typeValidator.js';
|
|
2
13
|
export class Action extends Node {
|
|
3
14
|
constructor(action) {
|
|
4
15
|
super(Object.assign(Object.assign({}, action), { class: 'action' }));
|
|
5
16
|
}
|
|
17
|
+
getStaticParameters() {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
static fromJSON(json) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const enriched = findActionByBlockId(json.blockId);
|
|
23
|
+
const action = new Action(Object.assign(Object.assign({}, enriched.block), { ref: json.ref, position: json.position, parentInfo: enriched.parentInfo }));
|
|
24
|
+
for (const [key, value] of Object.entries(json.parameters)) {
|
|
25
|
+
switch (key) {
|
|
26
|
+
case 'chainId':
|
|
27
|
+
action.setChainId(value);
|
|
28
|
+
break;
|
|
29
|
+
case 'contractAddress':
|
|
30
|
+
action.setContractAddress(value);
|
|
31
|
+
break;
|
|
32
|
+
case 'abi':
|
|
33
|
+
const abiParameters = value.parameters;
|
|
34
|
+
for (const abiKey in abiParameters) {
|
|
35
|
+
const enrichedParameter = enriched.block.parameters.find((param) => param.key === `abiParams.${abiKey}`);
|
|
36
|
+
const paramType = enrichedParameter ? enrichedParameter.type : null;
|
|
37
|
+
if (!abiParameters[abiKey] || !paramType)
|
|
38
|
+
continue;
|
|
39
|
+
if (typeIsNumber(paramType) && typeof abiParameters[abiKey] === 'string' && abiParameters[abiKey].endsWith('n')) {
|
|
40
|
+
action.setParams(abiKey, BigInt(abiParameters[abiKey].slice(0, -1)));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
action.setParams(abiKey, abiParameters[abiKey]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case 'interval':
|
|
48
|
+
// ignore
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
action.setParams(key, value);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
action.setId(json.id);
|
|
56
|
+
return action;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
6
59
|
}
|
|
60
|
+
const findActionByBlockId = (blockId) => {
|
|
61
|
+
for (const category in ACTIONS) {
|
|
62
|
+
for (const service in ACTIONS[category]) {
|
|
63
|
+
for (const actionKey in ACTIONS[category][service]) {
|
|
64
|
+
if (ACTIONS[category][service][actionKey].blockId === blockId) {
|
|
65
|
+
return {
|
|
66
|
+
parentInfo: {
|
|
67
|
+
name: service,
|
|
68
|
+
description: ACTIONS[category][service].description,
|
|
69
|
+
image: ACTIONS[category][service].image,
|
|
70
|
+
},
|
|
71
|
+
block: ACTIONS[category][service][actionKey],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Action with id ${blockId} not found`);
|
|
78
|
+
};
|
package/dist/src/models/Node.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
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
|
+
};
|
|
2
10
|
import { validateType } from '../utils/typeValidator.js';
|
|
3
|
-
import { ACTIONS, TRIGGERS } from '../constants/Blocks.js';
|
|
4
11
|
let nodeCounter = 0;
|
|
5
12
|
const generatedRefs = new Set();
|
|
6
13
|
export class Node {
|
|
@@ -14,6 +21,7 @@ export class Node {
|
|
|
14
21
|
this.parameters = {};
|
|
15
22
|
this.keyMap = {};
|
|
16
23
|
this.class = node.class;
|
|
24
|
+
this.parentInfo = node.parentInfo;
|
|
17
25
|
if (node.ref) {
|
|
18
26
|
this.ref = node.ref;
|
|
19
27
|
}
|
|
@@ -52,6 +60,9 @@ export class Node {
|
|
|
52
60
|
getRef() {
|
|
53
61
|
return this.ref;
|
|
54
62
|
}
|
|
63
|
+
getParentInfo() {
|
|
64
|
+
return this.parentInfo;
|
|
65
|
+
}
|
|
55
66
|
setParameter(key, value) {
|
|
56
67
|
if (key in this.parameters) {
|
|
57
68
|
const param = this.parameters[key];
|
|
@@ -89,77 +100,55 @@ export class Node {
|
|
|
89
100
|
return acc;
|
|
90
101
|
}, {});
|
|
91
102
|
}
|
|
103
|
+
getStaticParameters() {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
92
106
|
toJSON() {
|
|
107
|
+
const serializeBigInt = (key, value) => {
|
|
108
|
+
if (typeof value === 'bigint') {
|
|
109
|
+
return value.toString() + 'n';
|
|
110
|
+
}
|
|
111
|
+
else if (typeof value === 'object' && value !== null) {
|
|
112
|
+
// Recursively call serializeBigInt for nested objects
|
|
113
|
+
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
114
|
+
acc[k] = serializeBigInt(k, v);
|
|
115
|
+
return acc;
|
|
116
|
+
}, {});
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const staticParameters = this.getStaticParameters() || {};
|
|
93
123
|
const json = {
|
|
94
124
|
id: this.id,
|
|
95
125
|
ref: this.ref,
|
|
96
126
|
blockId: this.blockId,
|
|
97
127
|
type: this.class,
|
|
98
|
-
parameters: this.getParameters(),
|
|
128
|
+
parameters: Object.assign(Object.assign({}, this.getParameters()), staticParameters),
|
|
99
129
|
};
|
|
100
130
|
if (this.position) {
|
|
101
131
|
json.position = this.position;
|
|
102
132
|
}
|
|
103
|
-
return json;
|
|
133
|
+
return JSON.parse(JSON.stringify(json, serializeBigInt));
|
|
104
134
|
}
|
|
105
135
|
getSimplifiedKey(key) {
|
|
106
136
|
return key.replace(/[.\[\]]/g, '_');
|
|
107
137
|
}
|
|
108
138
|
static fromJSON(json) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const parameters = Object.keys(json.parameters).map(key => ({
|
|
115
|
-
key,
|
|
116
|
-
type: typeof json.parameters[key], // Assuming type can be derived from the value's type
|
|
117
|
-
description: '', // Add appropriate description if needed
|
|
118
|
-
value: json.parameters[key]
|
|
119
|
-
}));
|
|
120
|
-
const node = new Node({
|
|
121
|
-
blockId: json.blockId,
|
|
122
|
-
name: enriched.name,
|
|
123
|
-
description: enriched.description,
|
|
124
|
-
image: enriched.image,
|
|
125
|
-
parameters,
|
|
126
|
-
ref: json.ref,
|
|
127
|
-
position: json.position,
|
|
128
|
-
class: json.type
|
|
129
|
-
});
|
|
130
|
-
node.setId(json.id);
|
|
131
|
-
return node;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
const findActionByBlockId = (blockId) => {
|
|
135
|
-
for (const category in ACTIONS) {
|
|
136
|
-
for (const service in ACTIONS[category]) {
|
|
137
|
-
for (const actionKey in ACTIONS[category][service]) {
|
|
138
|
-
if (ACTIONS[category][service][actionKey].blockId === blockId) {
|
|
139
|
-
return {
|
|
140
|
-
name: ACTIONS[category][service][actionKey].name,
|
|
141
|
-
description: ACTIONS[category][service][actionKey].description,
|
|
142
|
-
image: ACTIONS[category][service][actionKey].image,
|
|
143
|
-
};
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
switch (json.type) {
|
|
141
|
+
case 'trigger': {
|
|
142
|
+
const { Trigger } = yield import('./Trigger.js');
|
|
143
|
+
return Trigger.fromJSON(json);
|
|
144
144
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return null;
|
|
149
|
-
};
|
|
150
|
-
const findTriggerByBlockId = (blockId) => {
|
|
151
|
-
for (const category in TRIGGERS) {
|
|
152
|
-
for (const service in TRIGGERS[category]) {
|
|
153
|
-
for (const triggerKey in TRIGGERS[category][service]) {
|
|
154
|
-
if (TRIGGERS[category][service][triggerKey].blockId === blockId) {
|
|
155
|
-
return {
|
|
156
|
-
name: TRIGGERS[category][service][triggerKey].name,
|
|
157
|
-
description: TRIGGERS[category][service][triggerKey].description,
|
|
158
|
-
image: TRIGGERS[category][service][triggerKey].image,
|
|
159
|
-
};
|
|
145
|
+
case 'action': {
|
|
146
|
+
const { Action } = yield import('./Action.js');
|
|
147
|
+
return Action.fromJSON(json);
|
|
160
148
|
}
|
|
149
|
+
default:
|
|
150
|
+
throw new Error(`Unsupported type: ${json.type}`);
|
|
161
151
|
}
|
|
162
|
-
}
|
|
152
|
+
});
|
|
163
153
|
}
|
|
164
|
-
|
|
165
|
-
};
|
|
154
|
+
}
|
|
@@ -1,4 +1,15 @@
|
|
|
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 { Node } from './Node.js';
|
|
11
|
+
import { TRIGGERS } from '../constants/Blocks.js';
|
|
12
|
+
import { typeIsNumber } from '../utils/typeValidator.js';
|
|
2
13
|
export class Trigger extends Node {
|
|
3
14
|
constructor(trigger) {
|
|
4
15
|
super(Object.assign(Object.assign({}, trigger), { class: 'trigger' }));
|
|
@@ -19,10 +30,75 @@ export class Trigger extends Node {
|
|
|
19
30
|
}
|
|
20
31
|
this.setParameter('comparisonValue', value);
|
|
21
32
|
}
|
|
22
|
-
|
|
23
|
-
if (this.notAPollingTrigger()) {
|
|
24
|
-
|
|
33
|
+
getStaticParameters() {
|
|
34
|
+
if (!this.notAPollingTrigger()) {
|
|
35
|
+
return { interval: 5000 };
|
|
25
36
|
}
|
|
26
|
-
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
static fromJSON(json) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const enriched = findTriggerByBlockId(json.blockId);
|
|
42
|
+
const trigger = new Trigger(Object.assign(Object.assign({}, enriched.block), { ref: json.ref, position: json.position, parentInfo: enriched.parentInfo }));
|
|
43
|
+
for (const [key, value] of Object.entries(json.parameters)) {
|
|
44
|
+
switch (key) {
|
|
45
|
+
case 'chainId':
|
|
46
|
+
trigger.setChainId(value);
|
|
47
|
+
break;
|
|
48
|
+
case 'contractAddress':
|
|
49
|
+
trigger.setContractAddress(value);
|
|
50
|
+
break;
|
|
51
|
+
case 'condition':
|
|
52
|
+
trigger.setCondition(value);
|
|
53
|
+
break;
|
|
54
|
+
case 'comparisonValue':
|
|
55
|
+
trigger.setComparisonValue(value);
|
|
56
|
+
break;
|
|
57
|
+
case 'abi':
|
|
58
|
+
const abiParameters = value.parameters;
|
|
59
|
+
for (const abiKey in abiParameters) {
|
|
60
|
+
const enrichedParameter = enriched.block.parameters.find((param) => param.key === `abiParams.${abiKey}`);
|
|
61
|
+
const paramType = enrichedParameter ? enrichedParameter.type : null;
|
|
62
|
+
if (!abiParameters[abiKey] || !paramType)
|
|
63
|
+
continue;
|
|
64
|
+
if (typeIsNumber(paramType) && typeof abiParameters[abiKey] === 'string' && abiParameters[abiKey].endsWith('n')) {
|
|
65
|
+
trigger.setParams(abiKey, BigInt(abiParameters[abiKey].slice(0, -1)));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
trigger.setParams(abiKey, abiParameters[abiKey]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
case 'interval':
|
|
73
|
+
// ignore
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
trigger.setParams(key, value);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
trigger.setId(json.id);
|
|
81
|
+
return trigger;
|
|
82
|
+
});
|
|
27
83
|
}
|
|
28
84
|
}
|
|
85
|
+
// Assuming findTriggerByBlockId function is defined as mentioned
|
|
86
|
+
const findTriggerByBlockId = (blockId) => {
|
|
87
|
+
for (const category in TRIGGERS) {
|
|
88
|
+
for (const service in TRIGGERS[category]) {
|
|
89
|
+
for (const triggerKey in TRIGGERS[category][service]) {
|
|
90
|
+
if (TRIGGERS[category][service][triggerKey].blockId === blockId) {
|
|
91
|
+
return {
|
|
92
|
+
parentInfo: {
|
|
93
|
+
name: service,
|
|
94
|
+
description: TRIGGERS[category][service].description,
|
|
95
|
+
image: TRIGGERS[category][service].image,
|
|
96
|
+
},
|
|
97
|
+
block: TRIGGERS[category][service][triggerKey],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
throw new Error(`Trigger with id ${blockId} not found`);
|
|
104
|
+
};
|