otomato-sdk 2.0.330 → 2.0.331
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/WorkflowTemplates.js +230 -24
- package/dist/src/constants/version.js +1 -1
- package/dist/src/utils/jsonToWf.js +257 -0
- package/dist/types/src/constants/WorkflowTemplates.d.ts +55 -0
- package/dist/types/src/constants/version.d.ts +1 -1
- package/dist/types/src/utils/jsonToWf.d.ts +19 -0
- package/dist/types/test/util.spec.d.ts +1 -0
- package/package.json +1 -1
|
@@ -42,6 +42,61 @@ const yieldUpdateMessage = `Daily Yield Report 🚀
|
|
|
42
42
|
The gas price on Ethereum is currently {{external.functions.mainnetGasPrice(,)}} gwei.
|
|
43
43
|
|
|
44
44
|
See you tomorrow!`;
|
|
45
|
+
/**
|
|
46
|
+
* Default workflow loop settings for various workflow types.
|
|
47
|
+
*/
|
|
48
|
+
export const DEFAULT_WORKFLOW_LOOP_SETTINGS = {
|
|
49
|
+
subscription: {
|
|
50
|
+
loopingType: 'subscription',
|
|
51
|
+
limit: 1000,
|
|
52
|
+
timeout: 365 * 24 * 60 * 60 * 1000,
|
|
53
|
+
},
|
|
54
|
+
polling1s: {
|
|
55
|
+
loopingType: 'polling',
|
|
56
|
+
period: 1000,
|
|
57
|
+
limit: 100,
|
|
58
|
+
},
|
|
59
|
+
polling1h: {
|
|
60
|
+
loopingType: 'polling',
|
|
61
|
+
period: 1 * 60 * 60 * 1000,
|
|
62
|
+
limit: 100,
|
|
63
|
+
},
|
|
64
|
+
polling4h: {
|
|
65
|
+
loopingType: 'polling',
|
|
66
|
+
period: 4 * 60 * 60 * 1000,
|
|
67
|
+
limit: 100,
|
|
68
|
+
},
|
|
69
|
+
polling1d: {
|
|
70
|
+
loopingType: 'polling',
|
|
71
|
+
period: 24 * 60 * 60 * 1000,
|
|
72
|
+
limit: 100,
|
|
73
|
+
},
|
|
74
|
+
polling12h: {
|
|
75
|
+
loopingType: 'polling',
|
|
76
|
+
period: 12 * 60 * 60 * 1000,
|
|
77
|
+
limit: 100,
|
|
78
|
+
},
|
|
79
|
+
polling3d: {
|
|
80
|
+
loopingType: 'polling',
|
|
81
|
+
period: 3 * 24 * 60 * 60 * 1000,
|
|
82
|
+
limit: 100,
|
|
83
|
+
},
|
|
84
|
+
polling7d: {
|
|
85
|
+
loopingType: 'polling',
|
|
86
|
+
period: 7 * 24 * 60 * 60 * 1000,
|
|
87
|
+
limit: 100,
|
|
88
|
+
},
|
|
89
|
+
subscription1m20rep: {
|
|
90
|
+
loopingType: 'subscription',
|
|
91
|
+
limit: 20,
|
|
92
|
+
timeout: 30 * 24 * 60 * 60 * 1000,
|
|
93
|
+
},
|
|
94
|
+
subscription1m30rep: {
|
|
95
|
+
loopingType: 'subscription',
|
|
96
|
+
limit: 30,
|
|
97
|
+
timeout: 30 * 24 * 60 * 60 * 1000,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
45
100
|
const createModeTransferNotificationWorkflow = () => {
|
|
46
101
|
const cbBTCTransferTrigger = new Trigger(TRIGGERS.TOKENS.TRANSFER.TRANSFER);
|
|
47
102
|
cbBTCTransferTrigger.setChainId(CHAINS.BASE);
|
|
@@ -53,7 +108,7 @@ const createModeTransferNotificationWorkflow = () => {
|
|
|
53
108
|
notificationAction.setParams("subject", "cbBTC transfer alert");
|
|
54
109
|
notificationAction.setPosition(400, 240);
|
|
55
110
|
const edge = new Edge({ source: cbBTCTransferTrigger, target: notificationAction });
|
|
56
|
-
return new Workflow('cbBTC transfer notification', [cbBTCTransferTrigger, notificationAction], [edge]);
|
|
111
|
+
return new Workflow('cbBTC transfer notification', [cbBTCTransferTrigger, notificationAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.subscription);
|
|
57
112
|
};
|
|
58
113
|
const createETHFearAndGreedBuy = async () => {
|
|
59
114
|
const trigger = new Trigger(TRIGGERS.SOCIALS.FEAR_AND_GREED.GET_FEAR_AND_GREED_INDEX);
|
|
@@ -68,7 +123,7 @@ const createETHFearAndGreedBuy = async () => {
|
|
|
68
123
|
odosAction.setParams("amount", await convertToTokenUnitsFromSymbol(100, chain, 'USDC'));
|
|
69
124
|
odosAction.setPosition(400, 240);
|
|
70
125
|
const edge = new Edge({ source: trigger, target: odosAction });
|
|
71
|
-
return new Workflow('Buy ETH
|
|
126
|
+
return new Workflow('Buy ETH daily as long as the market sentiment is extremely fearful', [trigger, odosAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1d);
|
|
72
127
|
};
|
|
73
128
|
const createDCAFearAndGreed = async () => {
|
|
74
129
|
// created with examples/UseCases/FearAndGreedDCA
|
|
@@ -101,7 +156,7 @@ const createETHFearAndGreedCapitalEfficientBuy = async () => {
|
|
|
101
156
|
const edge1 = new Edge({ source: trigger, target: ionicWithdraw });
|
|
102
157
|
const edge2 = new Edge({ source: ionicWithdraw, target: odosAction });
|
|
103
158
|
const edge3 = new Edge({ source: odosAction, target: ionicDeposit });
|
|
104
|
-
return new Workflow('Buy ETH
|
|
159
|
+
return new Workflow('Buy ETH daily as long as the market sentiment is extremely fearful - capital efficient', [trigger, odosAction, ionicWithdraw, ionicDeposit], [edge1, edge2, edge3], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1d);
|
|
105
160
|
};
|
|
106
161
|
const createSUsdeYieldBuy = async () => {
|
|
107
162
|
const trigger = new Trigger(TRIGGERS.YIELD.ETHENA.SUSDE_YIELD);
|
|
@@ -133,7 +188,7 @@ const createSusdeYieldNotification = async () => {
|
|
|
133
188
|
notificationAction.setParams("subject", "sUSDE negative switch");
|
|
134
189
|
notificationAction.setPosition(400, 240);
|
|
135
190
|
const edge = new Edge({ source: trigger, target: notificationAction });
|
|
136
|
-
return new Workflow('sUSDE yield notification', [trigger, notificationAction], [edge]);
|
|
191
|
+
return new Workflow('sUSDE yield notification', [trigger, notificationAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling7d);
|
|
137
192
|
};
|
|
138
193
|
const createAAVEBorrowingRateNotificationWorkflow = async () => {
|
|
139
194
|
const trigger = new Trigger(TRIGGERS.LENDING.AAVE.BORROWING_RATES);
|
|
@@ -145,7 +200,7 @@ const createAAVEBorrowingRateNotificationWorkflow = async () => {
|
|
|
145
200
|
notificationAction.setParams("body", "The USDC borrowing rate on AAVE is above 5%");
|
|
146
201
|
notificationAction.setParams("subject", "AAVE rates increased!");
|
|
147
202
|
const edge = new Edge({ source: trigger, target: notificationAction });
|
|
148
|
-
return new Workflow('AAVE borrowing rate notification', [trigger, notificationAction], [edge]);
|
|
203
|
+
return new Workflow('AAVE borrowing rate notification', [trigger, notificationAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling7d);
|
|
149
204
|
};
|
|
150
205
|
const copyTradeVitalikOdos = async () => {
|
|
151
206
|
const trigger = new Trigger(TRIGGERS.DEXES.ODOS.SWAP);
|
|
@@ -160,7 +215,7 @@ const copyTradeVitalikOdos = async () => {
|
|
|
160
215
|
swap.setParams('amount', await convertToTokenUnits(1, CHAINS.MODE, tokenIn));
|
|
161
216
|
swap.setPosition(400, 240);
|
|
162
217
|
const edge = new Edge({ source: trigger, target: swap });
|
|
163
|
-
return new Workflow('Copy-trade the trades done on Odos by vitalik.eth', [trigger, swap], [edge]);
|
|
218
|
+
return new Workflow('Copy-trade the trades done on Odos by vitalik.eth', [trigger, swap], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.subscription);
|
|
164
219
|
};
|
|
165
220
|
const gasMonitoring = async () => {
|
|
166
221
|
const trigger = new Trigger(TRIGGERS.TECHNICAL.GAS.GAS_API);
|
|
@@ -172,7 +227,7 @@ const gasMonitoring = async () => {
|
|
|
172
227
|
notificationAction.setParams("subject", "Ethereum Gas Price Alert: Below 6 Gwei");
|
|
173
228
|
notificationAction.setPosition(400, 240);
|
|
174
229
|
const edge = new Edge({ source: trigger, target: notificationAction });
|
|
175
|
-
return new Workflow('Get Notified When Ethereum Gas drops below 6 Gwei', [trigger, notificationAction], [edge]);
|
|
230
|
+
return new Workflow('Get Notified When Ethereum Gas drops below 6 Gwei', [trigger, notificationAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1d);
|
|
176
231
|
};
|
|
177
232
|
const dailyYieldEmail = async () => {
|
|
178
233
|
const trigger = new Trigger(TRIGGERS.CORE.EVERY_PERIOD.EVERY_PERIOD);
|
|
@@ -192,7 +247,7 @@ const abstractGetNotifiedOnNewFlashBadge = async () => {
|
|
|
192
247
|
const telegramAction = new Action(ACTIONS.NOTIFICATIONS.TELEGRAM.SEND_MESSAGE);
|
|
193
248
|
telegramAction.setParams('message', 'A new flash badge is available on Abstract');
|
|
194
249
|
const edge = new Edge({ source: trigger, target: telegramAction });
|
|
195
|
-
return new Workflow('Get notified when a new flash badge is available on Abstract', [trigger, telegramAction], [edge]);
|
|
250
|
+
return new Workflow('Get notified when a new flash badge is available on Abstract', [trigger, telegramAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1s);
|
|
196
251
|
};
|
|
197
252
|
const abstractGetNotifiedWhenStreamerIsLive = async () => {
|
|
198
253
|
const trigger = new Trigger(TRIGGERS.SOCIALS.ABSTRACT.ON_STREAMER_LIVE);
|
|
@@ -200,7 +255,7 @@ const abstractGetNotifiedWhenStreamerIsLive = async () => {
|
|
|
200
255
|
const telegramAction = new Action(ACTIONS.NOTIFICATIONS.TELEGRAM.SEND_MESSAGE);
|
|
201
256
|
telegramAction.setParams('message', `${trigger.getParameterVariableName('streamer')} is live!\n https://portal.abs.xyz/stream/${trigger.getParameterVariableName('streamer')}`);
|
|
202
257
|
const edge = new Edge({ source: trigger, target: telegramAction });
|
|
203
|
-
return new Workflow('Get notified when a given streamer goes live', [trigger, telegramAction], [edge]);
|
|
258
|
+
return new Workflow('Get notified when a given streamer goes live', [trigger, telegramAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1h);
|
|
204
259
|
};
|
|
205
260
|
const abstractGetNotifiedOnNewAppRelease = async () => {
|
|
206
261
|
const trigger1 = new Trigger(TRIGGERS.SOCIALS.ABSTRACT.ON_NEW_APP_RELEASE);
|
|
@@ -217,7 +272,7 @@ const abstractGetNotifiedOnNewAppRelease = async () => {
|
|
|
217
272
|
const edge = new Edge({ source: trigger1, target: telegramAction });
|
|
218
273
|
const edge2 = new Edge({ source: trigger2, target: telegramAction });
|
|
219
274
|
const edge3 = new Edge({ source: trigger3, target: telegramAction });
|
|
220
|
-
return new Workflow('Get notified when a new app is available on Abstract', [trigger1, trigger2, trigger3, telegramAction], [edge, edge2, edge3]);
|
|
275
|
+
return new Workflow('Get notified when a new app is available on Abstract', [trigger1, trigger2, trigger3, telegramAction], [edge, edge2, edge3], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1s);
|
|
221
276
|
};
|
|
222
277
|
const abstractGetNotifiedOnNewUserBadge = async () => {
|
|
223
278
|
const trigger = new Trigger(TRIGGERS.SOCIALS.ABSTRACT.ON_USERS_NEW_BADGE);
|
|
@@ -225,7 +280,7 @@ const abstractGetNotifiedOnNewUserBadge = async () => {
|
|
|
225
280
|
const telegramAction = new Action(ACTIONS.NOTIFICATIONS.TELEGRAM.SEND_MESSAGE);
|
|
226
281
|
telegramAction.setParams('message', `Insider got a new badge ${trigger.getOutputVariableName('newBadges')}`);
|
|
227
282
|
const edge = new Edge({ source: trigger, target: telegramAction });
|
|
228
|
-
return new Workflow('Get notified when a
|
|
283
|
+
return new Workflow('Get notified when a given abstract power user gets a new badge', [trigger, telegramAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1s);
|
|
229
284
|
};
|
|
230
285
|
// notify me when I can unstake my stakestone
|
|
231
286
|
const createStakestoneUnstakeNotificationWorkflow = async () => {
|
|
@@ -239,7 +294,7 @@ const createStakestoneUnstakeNotificationWorkflow = async () => {
|
|
|
239
294
|
notificationAction.setParams("message", "You can now unstake your Stakestone position!");
|
|
240
295
|
notificationAction.setPosition(400, 240);
|
|
241
296
|
const edge = new Edge({ source: trigger, target: notificationAction });
|
|
242
|
-
return new Workflow('Get notified when you can unstake your Stakestone position', [trigger, notificationAction], [edge]);
|
|
297
|
+
return new Workflow('Get notified when you can unstake your Stakestone position', [trigger, notificationAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1d);
|
|
243
298
|
};
|
|
244
299
|
// notify me when a given uniswap position is out of range [looping enabled - 5 times]
|
|
245
300
|
const createUniswapPositionOutOfRangeNotificationWorkflow = async () => {
|
|
@@ -348,7 +403,7 @@ const createEthereumFoundationTransferNotificationWorkflow = () => {
|
|
|
348
403
|
notificationAction.setParams("message", `The Ethereum foundation has sold ${ethTransferTrigger.getOutputVariableName('amount')} ETH`);
|
|
349
404
|
notificationAction.setPosition(400, 240);
|
|
350
405
|
const edge = new Edge({ source: ethTransferTrigger, target: notificationAction });
|
|
351
|
-
return new Workflow('Ethereum Foundation transfer notification', [ethTransferTrigger, notificationAction], [edge]);
|
|
406
|
+
return new Workflow('Ethereum Foundation transfer notification', [ethTransferTrigger, notificationAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1s);
|
|
352
407
|
};
|
|
353
408
|
const createHyperliquidBTCSpotNPerpsThresholdNotificationWorkflow = () => {
|
|
354
409
|
const trigger = new Trigger(TRIGGERS.CORE.EVERY_PERIOD.EVERY_PERIOD);
|
|
@@ -382,7 +437,7 @@ const createDefillamaRaiseNotificationWorkflow = () => {
|
|
|
382
437
|
telegramAction.setParams('message', `New raise detected on Defillama: ${trigger.getOutputVariableName('newRaises')}`);
|
|
383
438
|
telegramAction.setPosition(400, 360);
|
|
384
439
|
const edge1 = new Edge({ source: trigger, target: telegramAction });
|
|
385
|
-
const workflow = new Workflow('Get notified when a project announces a new raise', [trigger, telegramAction], [edge1]);
|
|
440
|
+
const workflow = new Workflow('Get notified when a project announces a new raise', [trigger, telegramAction], [edge1], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1s);
|
|
386
441
|
return workflow;
|
|
387
442
|
};
|
|
388
443
|
const createTokenMovementNotificationWorkflow = () => {
|
|
@@ -393,7 +448,7 @@ const createTokenMovementNotificationWorkflow = () => {
|
|
|
393
448
|
telegramAction.setParams('message', trigger.getOutputVariableName('balanceChanges'));
|
|
394
449
|
telegramAction.setPosition(400, 240);
|
|
395
450
|
const edge = new Edge({ source: trigger, target: telegramAction });
|
|
396
|
-
const workflow = new Workflow('Token Movement Notification', [trigger, telegramAction], [edge]);
|
|
451
|
+
const workflow = new Workflow('Token Movement Notification', [trigger, telegramAction], [edge], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1s);
|
|
397
452
|
return workflow;
|
|
398
453
|
};
|
|
399
454
|
const createTwitterAiNotificationWorkflow = (username, wfData) => {
|
|
@@ -417,7 +472,7 @@ const createTwitterAiNotificationWorkflow = (username, wfData) => {
|
|
|
417
472
|
const edge = new Edge({ source: trigger, target: aiAction });
|
|
418
473
|
const edge2 = new Edge({ source: aiAction, target: ifAction });
|
|
419
474
|
const edge3 = new Edge({ source: ifAction, target: telegramAction, label: 'true', value: true });
|
|
420
|
-
const workflow = new Workflow(wfData.wfTitle, [trigger, aiAction, ifAction, telegramAction], [edge, edge2, edge3]);
|
|
475
|
+
const workflow = new Workflow(wfData.wfTitle, [trigger, aiAction, ifAction, telegramAction], [edge, edge2, edge3], DEFAULT_WORKFLOW_LOOP_SETTINGS.subscription);
|
|
421
476
|
return workflow;
|
|
422
477
|
};
|
|
423
478
|
};
|
|
@@ -465,7 +520,7 @@ const createBuyBitcoinOnPeterSchiffBearishWorkflow = () => {
|
|
|
465
520
|
const edge = new Edge({ source: trigger, target: aiAction });
|
|
466
521
|
const edge2 = new Edge({ source: aiAction, target: ifAction });
|
|
467
522
|
const edge3 = new Edge({ source: ifAction, target: swapAction, label: 'true', value: true });
|
|
468
|
-
const workflow = new Workflow(`Buy cbBTC when PeterSchiff tweets a bearish tweet`, [trigger, aiAction, ifAction, swapAction], [edge, edge2, edge3]);
|
|
523
|
+
const workflow = new Workflow(`Buy cbBTC when PeterSchiff tweets a bearish tweet`, [trigger, aiAction, ifAction, swapAction], [edge, edge2, edge3], DEFAULT_WORKFLOW_LOOP_SETTINGS.subscription);
|
|
469
524
|
return workflow;
|
|
470
525
|
};
|
|
471
526
|
const createWithdrawOnAaveHackWorkflow = () => {
|
|
@@ -498,7 +553,7 @@ const createWithdrawOnAaveHackWorkflow = () => {
|
|
|
498
553
|
const edge2 = new Edge({ source: lookonchainTrigger, target: aiAction });
|
|
499
554
|
const edge3 = new Edge({ source: aiAction, target: ifAction });
|
|
500
555
|
const edge5 = new Edge({ source: ifAction, target: withdrawAction, label: 'true', value: true });
|
|
501
|
-
const workflow = new Workflow(`Withdraw liquidity from AAVE if hack is detected via AAVE or lookonchain tweets`, [aaveTrigger, lookonchainTrigger, aiAction, ifAction, withdrawAction], [edge1, edge2, edge3, edge5]);
|
|
556
|
+
const workflow = new Workflow(`Withdraw liquidity from AAVE if hack is detected via AAVE or lookonchain tweets`, [aaveTrigger, lookonchainTrigger, aiAction, ifAction, withdrawAction], [edge1, edge2, edge3, edge5], DEFAULT_WORKFLOW_LOOP_SETTINGS.subscription);
|
|
502
557
|
return workflow;
|
|
503
558
|
};
|
|
504
559
|
const createMonitorHyperliquidFundingRatesWorkflow = () => {
|
|
@@ -566,7 +621,7 @@ const createNFTSaleNotificationWorkflow = () => {
|
|
|
566
621
|
telegramAction.setParams('message', `New NFT sale detected on Blur: ${trigger.getOutputVariableName('message')}`);
|
|
567
622
|
telegramAction.setPosition(400, 360);
|
|
568
623
|
const edge1 = new Edge({ source: trigger, target: telegramAction });
|
|
569
|
-
const workflow = new Workflow('Get notified when a NFT is sold on Blur', [trigger, telegramAction], [edge1]);
|
|
624
|
+
const workflow = new Workflow('Get notified when a NFT is sold on Blur', [trigger, telegramAction], [edge1], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1s);
|
|
570
625
|
return workflow;
|
|
571
626
|
};
|
|
572
627
|
const createPudgyPenguinsSaleNotificationWorkflow = () => {
|
|
@@ -575,7 +630,7 @@ const createPudgyPenguinsSaleNotificationWorkflow = () => {
|
|
|
575
630
|
const telegramAction = new Action(ACTIONS.NOTIFICATIONS.TELEGRAM.SEND_MESSAGE);
|
|
576
631
|
telegramAction.setParams('message', `New Pudgy Penguins sale detected on Blur: ${trigger.getOutputVariableName('message')}`);
|
|
577
632
|
const edge1 = new Edge({ source: trigger, target: telegramAction });
|
|
578
|
-
const workflow = new Workflow('Get notified when a Pudgy Penguins is sold on Blur', [trigger, telegramAction], [edge1]);
|
|
633
|
+
const workflow = new Workflow('Get notified when a Pudgy Penguins is sold on Blur', [trigger, telegramAction], [edge1], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1s);
|
|
579
634
|
return workflow;
|
|
580
635
|
};
|
|
581
636
|
const createDailyHealthrateMonitoringWorkflow = () => {
|
|
@@ -619,6 +674,76 @@ const dailyCoinDeskNewsNotificationWorkflow = async () => {
|
|
|
619
674
|
const edge3 = new Edge({ source: aiAction, target: telegramAction });
|
|
620
675
|
return new Workflow('Daily CoinDesk news notification', [trigger, httpAction, aiAction, telegramAction], [edge, edge2, edge3]);
|
|
621
676
|
};
|
|
677
|
+
const createAaveHealthFactorAgentWorkflow = async () => {
|
|
678
|
+
const aaveHealthFactorTrigger = new Trigger(TRIGGERS.LENDING.AAVE.HEALTH_FACTOR);
|
|
679
|
+
aaveHealthFactorTrigger.setParams('chainId', 42161);
|
|
680
|
+
aaveHealthFactorTrigger.setParams('condition', 'lte');
|
|
681
|
+
aaveHealthFactorTrigger.setParams('comparisonValue', 1.5);
|
|
682
|
+
aaveHealthFactorTrigger.setPosition(400, 120);
|
|
683
|
+
const aaveWithdrawAction = new Action(ACTIONS.LENDING.AAVE.WITHDRAW);
|
|
684
|
+
aaveWithdrawAction.setParams('chainId', 42161);
|
|
685
|
+
aaveWithdrawAction.setParams('abiParams.asset', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1');
|
|
686
|
+
aaveWithdrawAction.setParams('abiParams.amount', '115792089237316195423570985008687907853269984665640564039457584007913129639935n');
|
|
687
|
+
aaveWithdrawAction.setParams('abiParams.to', null);
|
|
688
|
+
aaveWithdrawAction.setPosition(400, 240);
|
|
689
|
+
const iexecSendWeb3TelegramAction = new Action(ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM);
|
|
690
|
+
iexecSendWeb3TelegramAction.setParams('content', 'The health factor was above 1.5, so the funds were withdrawn to stay on the safe side.');
|
|
691
|
+
iexecSendWeb3TelegramAction.setPosition(400, 360);
|
|
692
|
+
const edge1 = new Edge({ source: aaveHealthFactorTrigger, target: aaveWithdrawAction });
|
|
693
|
+
const edge2 = new Edge({ source: aaveWithdrawAction, target: iexecSendWeb3TelegramAction });
|
|
694
|
+
const workflow = new Workflow('Withdraw from AAVE if the health factor is above 1.5', [aaveHealthFactorTrigger, aaveWithdrawAction, iexecSendWeb3TelegramAction], [edge1, edge2], DEFAULT_WORKFLOW_LOOP_SETTINGS.polling1d);
|
|
695
|
+
return workflow;
|
|
696
|
+
};
|
|
697
|
+
const createElonMuskTweeterAgentWorkflow = async () => {
|
|
698
|
+
const xXPostTriggerTrigger = new Trigger(TRIGGERS.TRENDING.X.X_POST_TRIGGER);
|
|
699
|
+
xXPostTriggerTrigger.setParams('username', 'elonmusk');
|
|
700
|
+
xXPostTriggerTrigger.setParams('includeRetweets', true);
|
|
701
|
+
xXPostTriggerTrigger.setPosition(400, 120);
|
|
702
|
+
const iexecSendWeb3TelegramAction = new Action(ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM);
|
|
703
|
+
iexecSendWeb3TelegramAction.setParams('content', `Elon Musk just tweeted. ${xXPostTriggerTrigger.getOutputVariableName('tweetContent')} ${xXPostTriggerTrigger.getOutputVariableName('tweetURL')}`);
|
|
704
|
+
iexecSendWeb3TelegramAction.setPosition(400, 240);
|
|
705
|
+
const edge1 = new Edge({ source: xXPostTriggerTrigger, target: iexecSendWeb3TelegramAction });
|
|
706
|
+
const workflow = new Workflow('Get notified when Elon Musk tweets', [xXPostTriggerTrigger, iexecSendWeb3TelegramAction], [edge1], DEFAULT_WORKFLOW_LOOP_SETTINGS.subscription1m30rep);
|
|
707
|
+
return workflow;
|
|
708
|
+
};
|
|
709
|
+
const createOrderLimitAgentWorkflow = async () => {
|
|
710
|
+
const pricePriceMovementAgainstCurrencyTrigger = new Trigger(TRIGGERS.TOKENS.PRICE.PRICE_MOVEMENT_AGAINST_CURRENCY);
|
|
711
|
+
pricePriceMovementAgainstCurrencyTrigger.setParams('chainId', 42161);
|
|
712
|
+
pricePriceMovementAgainstCurrencyTrigger.setParams('comparisonValue', 4500);
|
|
713
|
+
pricePriceMovementAgainstCurrencyTrigger.setParams('currency', 'USD');
|
|
714
|
+
pricePriceMovementAgainstCurrencyTrigger.setParams('condition', 'gt');
|
|
715
|
+
pricePriceMovementAgainstCurrencyTrigger.setParams('contractAddress', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1');
|
|
716
|
+
pricePriceMovementAgainstCurrencyTrigger.setPosition(400, 120);
|
|
717
|
+
const odosSwapAction = new Action(ACTIONS.SWAP.ODOS.SWAP);
|
|
718
|
+
odosSwapAction.setParams('chainId', 42161);
|
|
719
|
+
odosSwapAction.setParams('tokenIn', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1');
|
|
720
|
+
odosSwapAction.setParams('tokenOut', '0xaf88d065e77c8cc2239327c5edb3a432268e5831');
|
|
721
|
+
odosSwapAction.setParams('amount', 100);
|
|
722
|
+
odosSwapAction.setParams('slippage', '0.3');
|
|
723
|
+
odosSwapAction.setPosition(400, 240);
|
|
724
|
+
const iexecSendWeb3TelegramAction = new Action(ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM);
|
|
725
|
+
iexecSendWeb3TelegramAction.setParams('content', 'Swapped on Odos as ETH price is above 4500');
|
|
726
|
+
iexecSendWeb3TelegramAction.setPosition(400, 360);
|
|
727
|
+
const edge1 = new Edge({ source: pricePriceMovementAgainstCurrencyTrigger, target: odosSwapAction });
|
|
728
|
+
const edge2 = new Edge({ source: odosSwapAction, target: iexecSendWeb3TelegramAction });
|
|
729
|
+
const workflow = new Workflow('Swap on Odos if ETH price is above 4500', [pricePriceMovementAgainstCurrencyTrigger, odosSwapAction, iexecSendWeb3TelegramAction], [edge1, edge2], null);
|
|
730
|
+
return workflow;
|
|
731
|
+
};
|
|
732
|
+
const createPudgyPenguinHunterAgentWorkflow = async () => {
|
|
733
|
+
const blurListingTrigger = new Trigger(TRIGGERS.NFTS.BLUR.LISTING);
|
|
734
|
+
blurListingTrigger.setParams('contract', '0xbd3531da5cf5857e7cfaa92426877b022e612cf8');
|
|
735
|
+
blurListingTrigger.setParams('rarityCondition', 'lte');
|
|
736
|
+
blurListingTrigger.setParams('rarity', 5000);
|
|
737
|
+
blurListingTrigger.setParams('price', 30);
|
|
738
|
+
blurListingTrigger.setParams('traits', '{"Background":["Blue"],"Body":["Pineapple Suit"]}');
|
|
739
|
+
blurListingTrigger.setPosition(400, 120);
|
|
740
|
+
const iexecSendWeb3TelegramAction = new Action(ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM);
|
|
741
|
+
iexecSendWeb3TelegramAction.setParams('content', 'A Pudgy Penguin has just been listed.');
|
|
742
|
+
iexecSendWeb3TelegramAction.setPosition(400, 240);
|
|
743
|
+
const edge1 = new Edge({ source: blurListingTrigger, target: iexecSendWeb3TelegramAction });
|
|
744
|
+
const workflow = new Workflow('Get notified when a Pudgy Penguins is listed', [blurListingTrigger, iexecSendWeb3TelegramAction], [edge1], DEFAULT_WORKFLOW_LOOP_SETTINGS.subscription1m20rep);
|
|
745
|
+
return workflow;
|
|
746
|
+
};
|
|
622
747
|
export const WORKFLOW_TEMPLATES = [
|
|
623
748
|
{
|
|
624
749
|
'id': 1,
|
|
@@ -815,8 +940,8 @@ export const WORKFLOW_TEMPLATES = [
|
|
|
815
940
|
},
|
|
816
941
|
{
|
|
817
942
|
'id': 13,
|
|
818
|
-
'name': 'Get notified when
|
|
819
|
-
'description': 'Get notified when
|
|
943
|
+
'name': 'Get notified when a given abstract power user gets a new badge',
|
|
944
|
+
'description': 'Get notified when a given abstract power user gets a new badge',
|
|
820
945
|
'tags': [WORKFLOW_TEMPLATES_TAGS.ABSTRACT, WORKFLOW_TEMPLATES_TAGS.NOTIFICATIONS],
|
|
821
946
|
'thumbnail': 'https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/templates/abstract_badge.webp',
|
|
822
947
|
'image': [
|
|
@@ -1072,8 +1197,8 @@ export const WORKFLOW_TEMPLATES = [
|
|
|
1072
1197
|
},
|
|
1073
1198
|
{
|
|
1074
1199
|
'id': 32,
|
|
1075
|
-
'name': 'Buy ETH
|
|
1076
|
-
'description': 'Buy ETH
|
|
1200
|
+
'name': 'Buy ETH daily as long as the market sentiment is extremely fearful - capital efficient',
|
|
1201
|
+
'description': 'Buy ETH daily as long as the Bitcoin Fear and Greed Index is below 45. The idle funds are generating yield on AAVE.',
|
|
1077
1202
|
'tags': [WORKFLOW_TEMPLATES_TAGS.TRADING, WORKFLOW_TEMPLATES_TAGS.SOCIALS, WORKFLOW_TEMPLATES_TAGS.YIELD],
|
|
1078
1203
|
'thumbnail': 'https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/templates/dca_fear_and_greed_eth.webp',
|
|
1079
1204
|
'image': [
|
|
@@ -1222,4 +1347,85 @@ export const WORKFLOW_TEMPLATES = [
|
|
|
1222
1347
|
],
|
|
1223
1348
|
createWorkflow: dailyCoinDeskNewsNotificationWorkflow
|
|
1224
1349
|
},
|
|
1350
|
+
{
|
|
1351
|
+
'id': 41,
|
|
1352
|
+
'name': 'Withdraw from AAVE if the health factor is above 1.5',
|
|
1353
|
+
'description': 'Withdraw from AAVE if the health factor is above 1.5',
|
|
1354
|
+
'tags': [WORKFLOW_TEMPLATES_TAGS.SOCIALS, WORKFLOW_TEMPLATES_TAGS.NOTIFICATIONS, WORKFLOW_TEMPLATES_TAGS.LENDING, WORKFLOW_TEMPLATES_TAGS.IEXEC],
|
|
1355
|
+
'thumbnail': 'https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/templates/aave.webp',
|
|
1356
|
+
'image': [
|
|
1357
|
+
TRIGGERS.LENDING.AAVE.HEALTH_FACTOR.image,
|
|
1358
|
+
ACTIONS.LENDING.AAVE.WITHDRAW.image,
|
|
1359
|
+
ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM.image
|
|
1360
|
+
],
|
|
1361
|
+
'blockIDs': [
|
|
1362
|
+
TRIGGERS.LENDING.AAVE.HEALTH_FACTOR.blockId,
|
|
1363
|
+
ACTIONS.LENDING.AAVE.WITHDRAW.blockId,
|
|
1364
|
+
ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM.blockId
|
|
1365
|
+
],
|
|
1366
|
+
createWorkflow: createAaveHealthFactorAgentWorkflow
|
|
1367
|
+
},
|
|
1368
|
+
{
|
|
1369
|
+
'id': 42,
|
|
1370
|
+
'name': 'Get notified when Elon Musk tweets',
|
|
1371
|
+
'description': 'Receive a notification every time Elon Musk tweets.',
|
|
1372
|
+
'tags': [
|
|
1373
|
+
WORKFLOW_TEMPLATES_TAGS.SOCIALS,
|
|
1374
|
+
WORKFLOW_TEMPLATES_TAGS.NOTIFICATIONS,
|
|
1375
|
+
WORKFLOW_TEMPLATES_TAGS.IEXEC
|
|
1376
|
+
],
|
|
1377
|
+
'thumbnail': 'https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/templates/elon_tweet.webp',
|
|
1378
|
+
'image': [
|
|
1379
|
+
TRIGGERS.TRENDING.X.X_POST_TRIGGER.image,
|
|
1380
|
+
ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM.image
|
|
1381
|
+
],
|
|
1382
|
+
'blockIDs': [
|
|
1383
|
+
TRIGGERS.TRENDING.X.X_POST_TRIGGER.blockId,
|
|
1384
|
+
ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM.blockId
|
|
1385
|
+
],
|
|
1386
|
+
createWorkflow: createElonMuskTweeterAgentWorkflow
|
|
1387
|
+
},
|
|
1388
|
+
{
|
|
1389
|
+
'id': 43,
|
|
1390
|
+
'name': 'Swap on Odos if ETH price is above 4500',
|
|
1391
|
+
'description': 'Automatically swap tokens on Odos when ETH price exceeds 4500 USD.',
|
|
1392
|
+
'tags': [
|
|
1393
|
+
WORKFLOW_TEMPLATES_TAGS.SOCIALS,
|
|
1394
|
+
WORKFLOW_TEMPLATES_TAGS.NOTIFICATIONS,
|
|
1395
|
+
WORKFLOW_TEMPLATES_TAGS.DEXES,
|
|
1396
|
+
WORKFLOW_TEMPLATES_TAGS.IEXEC
|
|
1397
|
+
],
|
|
1398
|
+
'thumbnail': 'https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/templates/odos_sell_eth.webp',
|
|
1399
|
+
'image': [
|
|
1400
|
+
TRIGGERS.TOKENS.PRICE.PRICE_MOVEMENT_AGAINST_CURRENCY.image,
|
|
1401
|
+
ACTIONS.SWAP.ODOS.SWAP.image,
|
|
1402
|
+
ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM.image
|
|
1403
|
+
],
|
|
1404
|
+
'blockIDs': [
|
|
1405
|
+
TRIGGERS.TOKENS.PRICE.PRICE_MOVEMENT_AGAINST_CURRENCY.blockId,
|
|
1406
|
+
ACTIONS.SWAP.ODOS.SWAP.blockId,
|
|
1407
|
+
ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM.blockId
|
|
1408
|
+
],
|
|
1409
|
+
createWorkflow: createOrderLimitAgentWorkflow
|
|
1410
|
+
},
|
|
1411
|
+
{
|
|
1412
|
+
'id': 44,
|
|
1413
|
+
'name': 'Get notified when a Pudgy Penguins is listed',
|
|
1414
|
+
'description': 'Get notified when a Pudgy Penguin NFT with specific traits is listed on Blur.',
|
|
1415
|
+
'tags': [
|
|
1416
|
+
WORKFLOW_TEMPLATES_TAGS.NFTS,
|
|
1417
|
+
WORKFLOW_TEMPLATES_TAGS.NOTIFICATIONS,
|
|
1418
|
+
WORKFLOW_TEMPLATES_TAGS.IEXEC
|
|
1419
|
+
],
|
|
1420
|
+
'thumbnail': 'https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/templates/pudgy_penguins.webp',
|
|
1421
|
+
'image': [
|
|
1422
|
+
TRIGGERS.NFTS.BLUR.LISTING.image,
|
|
1423
|
+
ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM.image
|
|
1424
|
+
],
|
|
1425
|
+
'blockIDs': [
|
|
1426
|
+
TRIGGERS.NFTS.BLUR.LISTING.blockId,
|
|
1427
|
+
ACTIONS.NOTIFICATIONS.IEXEC.SEND_WEB3_TELEGRAM.blockId
|
|
1428
|
+
],
|
|
1429
|
+
createWorkflow: createPudgyPenguinHunterAgentWorkflow
|
|
1430
|
+
},
|
|
1225
1431
|
];
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the trigger constant string for a given blockId.
|
|
3
|
+
* @param blockId The block id to look up.
|
|
4
|
+
* @returns The trigger constant string, or undefined if not found.
|
|
5
|
+
*/
|
|
6
|
+
import { ACTIONS, TRIGGERS } from "../constants/Blocks.js";
|
|
7
|
+
/**
|
|
8
|
+
* Converts a string to camelCase
|
|
9
|
+
* @param str The string to convert
|
|
10
|
+
* @returns The camelCase string
|
|
11
|
+
*/
|
|
12
|
+
const toCamelCase = (str) => {
|
|
13
|
+
return str
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase());
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Formats a parameter value for code output
|
|
19
|
+
* @param value The parameter value to format
|
|
20
|
+
* @param nodeRefToName Mapping of node references to node names
|
|
21
|
+
* @returns The formatted value as a string
|
|
22
|
+
*/
|
|
23
|
+
const formatParameterValue = (value, nodeRefToName) => {
|
|
24
|
+
if (value === null) {
|
|
25
|
+
return 'null';
|
|
26
|
+
}
|
|
27
|
+
else if (value === undefined) {
|
|
28
|
+
return 'undefined';
|
|
29
|
+
}
|
|
30
|
+
else if (typeof value === 'string') {
|
|
31
|
+
// Check if it contains nodeMap references and convert them to getOutput calls
|
|
32
|
+
if (value.includes('{{nodeMap.')) {
|
|
33
|
+
return convertNodeMapToGetOutput(value, nodeRefToName);
|
|
34
|
+
}
|
|
35
|
+
// Escape single quotes in the string
|
|
36
|
+
const escapedValue = value.replace(/'/g, "\\'");
|
|
37
|
+
return `'${escapedValue}'`;
|
|
38
|
+
}
|
|
39
|
+
else if (typeof value === 'number') {
|
|
40
|
+
return String(value);
|
|
41
|
+
}
|
|
42
|
+
else if (typeof value === 'boolean') {
|
|
43
|
+
return String(value);
|
|
44
|
+
}
|
|
45
|
+
else if (typeof value === 'object') {
|
|
46
|
+
return JSON.stringify(value, null, 2);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return String(value);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Converts nodeMap references to getOutput calls
|
|
54
|
+
* @param value The string containing nodeMap references
|
|
55
|
+
* @param nodeRefToName Mapping of node references to node names
|
|
56
|
+
* @returns The converted string with getOutput calls
|
|
57
|
+
*/
|
|
58
|
+
const convertNodeMapToGetOutput = (value, nodeRefToName) => {
|
|
59
|
+
// Replace {{nodeMap.X.output.property}} with ${nodeName.getOutputVariableName('property')}
|
|
60
|
+
const converted = value.replace(/\{\{nodeMap\.(\d+)\.output\.(\w+)\}\}/g, (match, nodeRef, outputProperty) => {
|
|
61
|
+
const nodeName = nodeRefToName[nodeRef];
|
|
62
|
+
if (nodeName) {
|
|
63
|
+
return `\${${nodeName}.getOutputVariableName('${outputProperty}')}`;
|
|
64
|
+
}
|
|
65
|
+
// Fallback if node name not found
|
|
66
|
+
return `\${getNodeByRef('${nodeRef}').getOutputVariableName('${outputProperty}')}`;
|
|
67
|
+
});
|
|
68
|
+
// If the string contains getOutput calls, wrap it in template literal
|
|
69
|
+
if (converted.includes('.getOutputVariableName(')) {
|
|
70
|
+
return `\`${converted}\``;
|
|
71
|
+
}
|
|
72
|
+
return `'${converted}'`;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Returns the trigger or action constant string for a given blockId.
|
|
76
|
+
* Searches both TRIGGERS and ACTIONS.
|
|
77
|
+
* @param blockId The block id to look up.
|
|
78
|
+
* @returns The trigger or action constant string, or undefined if not found.
|
|
79
|
+
*/
|
|
80
|
+
export const getBlockConstantByBlockId = (blockId) => {
|
|
81
|
+
/**
|
|
82
|
+
* Recursively searches an object for a blockId and returns the path as a string.
|
|
83
|
+
* @param obj The object to search.
|
|
84
|
+
* @param path The current path in the object.
|
|
85
|
+
* @returns The path string if found, otherwise undefined.
|
|
86
|
+
*/
|
|
87
|
+
const searchBlocks = (obj, path = []) => {
|
|
88
|
+
for (const key in obj) {
|
|
89
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
90
|
+
continue;
|
|
91
|
+
const value = obj[key];
|
|
92
|
+
if (value && typeof value === 'object') {
|
|
93
|
+
if ('blockId' in value && value.blockId === blockId) {
|
|
94
|
+
return [...path, key].join('.');
|
|
95
|
+
}
|
|
96
|
+
const found = searchBlocks(value, [...path, key]);
|
|
97
|
+
if (found)
|
|
98
|
+
return found;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
};
|
|
103
|
+
// Search in TRIGGERS first
|
|
104
|
+
const foundTriggerPath = searchBlocks(TRIGGERS);
|
|
105
|
+
if (foundTriggerPath) {
|
|
106
|
+
return 'TRIGGERS.' + foundTriggerPath.toUpperCase();
|
|
107
|
+
}
|
|
108
|
+
// If not found in TRIGGERS, search in ACTIONS
|
|
109
|
+
const foundActionPath = searchBlocks(ACTIONS);
|
|
110
|
+
if (foundActionPath) {
|
|
111
|
+
return 'ACTIONS.' + foundActionPath.toUpperCase();
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Converts a workflow JSON object back to its representative code.
|
|
117
|
+
*
|
|
118
|
+
* @param wfJson The workflow JSON object
|
|
119
|
+
* @returns The workflow code as a string
|
|
120
|
+
*/
|
|
121
|
+
export const convertWFJSONToCode = (wfJson) => {
|
|
122
|
+
const nodes = wfJson.nodes;
|
|
123
|
+
const edges = wfJson.edges;
|
|
124
|
+
const settings = wfJson.settings;
|
|
125
|
+
let code = '';
|
|
126
|
+
const nodeRefToName = {};
|
|
127
|
+
// Generate imports
|
|
128
|
+
code += `import { Workflow, Edge, Trigger, Action } from './models';\n`;
|
|
129
|
+
code += `import { TRIGGERS, ACTIONS } from './constants/Blocks';\n`;
|
|
130
|
+
code += `import { WORKFLOW_LOOPING_TYPES } from './constants/WorkflowSettings';\n\n`;
|
|
131
|
+
// Generate node instantiations
|
|
132
|
+
for (const node of nodes) {
|
|
133
|
+
const blockConstant = getBlockConstantByBlockId(node.blockId);
|
|
134
|
+
if (!blockConstant) {
|
|
135
|
+
throw new Error(`Block constant not found for blockId: ${node.blockId}`);
|
|
136
|
+
}
|
|
137
|
+
// Extract the class name from the block constant and create a better name
|
|
138
|
+
const blockPath = blockConstant.split('.');
|
|
139
|
+
const blockName = blockPath[blockPath.length - 1];
|
|
140
|
+
// Create a more descriptive name based on the block path
|
|
141
|
+
let nodeName;
|
|
142
|
+
if (node.type === 'trigger') {
|
|
143
|
+
// For triggers: protocol + blockName + Trigger
|
|
144
|
+
const protocol = blockPath[1]?.toLowerCase() || '';
|
|
145
|
+
const subProtocol = blockPath[2]?.toLowerCase() || '';
|
|
146
|
+
const cleanBlockName = blockName.toLowerCase();
|
|
147
|
+
// Create proper camelCase name with better structure
|
|
148
|
+
const baseName = toCamelCase(`${subProtocol}_${cleanBlockName}`); //${protocol}_
|
|
149
|
+
nodeName = `${baseName}Trigger`;
|
|
150
|
+
}
|
|
151
|
+
else if (node.type === 'action') {
|
|
152
|
+
// For actions: protocol + blockName + Action
|
|
153
|
+
const protocol = blockPath[1]?.toLowerCase() || '';
|
|
154
|
+
const subProtocol = blockPath[2]?.toLowerCase() || '';
|
|
155
|
+
const cleanBlockName = blockName.toLowerCase();
|
|
156
|
+
// Create proper camelCase name with better structure
|
|
157
|
+
const baseName = toCamelCase(`${subProtocol}_${cleanBlockName}`); //${protocol}_
|
|
158
|
+
nodeName = `${baseName}Action`;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// Fallback to original naming
|
|
162
|
+
nodeName = `${blockName.toLowerCase()}${node.ref}`;
|
|
163
|
+
}
|
|
164
|
+
// Store the mapping for later use
|
|
165
|
+
nodeRefToName[node.ref] = nodeName;
|
|
166
|
+
// Generate the node instantiation
|
|
167
|
+
if (node.type === 'trigger') {
|
|
168
|
+
code += `const ${nodeName} = new Trigger(TRIGGERS.${blockPath.slice(1).join('.')});\n`;
|
|
169
|
+
}
|
|
170
|
+
else if (node.type === 'action') {
|
|
171
|
+
code += `const ${nodeName} = new Action(ACTIONS.${blockPath.slice(1).join('.')});\n`;
|
|
172
|
+
}
|
|
173
|
+
// Generate setParams code for each parameter
|
|
174
|
+
for (const [paramKey, paramValue] of Object.entries(node.parameters)) {
|
|
175
|
+
// Handle nested abi.parameters with abiParams prefix
|
|
176
|
+
if (paramKey === 'abi' && typeof paramValue === 'object' && paramValue !== null) {
|
|
177
|
+
const abiParams = paramValue.parameters;
|
|
178
|
+
if (abiParams && typeof abiParams === 'object') {
|
|
179
|
+
for (const [abiParamKey, abiParamValue] of Object.entries(abiParams)) {
|
|
180
|
+
const prefixedKey = `abiParams.${abiParamKey}`;
|
|
181
|
+
const valueCode = formatParameterValue(abiParamValue, nodeRefToName);
|
|
182
|
+
code += `${nodeName}.setParams('${prefixedKey}', ${valueCode});\n`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// Handle normal parameters
|
|
188
|
+
const valueCode = formatParameterValue(paramValue, nodeRefToName);
|
|
189
|
+
code += `${nodeName}.setParams('${paramKey}', ${valueCode});\n`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Generate setPosition code if position exists
|
|
193
|
+
if (node.position && typeof node.position.x === 'number' && typeof node.position.y === 'number') {
|
|
194
|
+
code += `${nodeName}.setPosition(${node.position.x}, ${node.position.y});\n`;
|
|
195
|
+
}
|
|
196
|
+
// Set ref and isOptional if present
|
|
197
|
+
// if (node.ref) {
|
|
198
|
+
// code += `${nodeName}.setRef('${node.ref}');\n`;
|
|
199
|
+
// }
|
|
200
|
+
if (typeof node.isOptional === 'boolean') {
|
|
201
|
+
code += `${nodeName}.setIsOptional(${node.isOptional});\n`;
|
|
202
|
+
}
|
|
203
|
+
code += '\n';
|
|
204
|
+
}
|
|
205
|
+
// Generate edge creations
|
|
206
|
+
const edgeNames = [];
|
|
207
|
+
for (let i = 0; i < edges.length; i++) {
|
|
208
|
+
const edge = edges[i];
|
|
209
|
+
const sourceName = nodeRefToName[edge.source];
|
|
210
|
+
const targetName = nodeRefToName[edge.target];
|
|
211
|
+
if (!sourceName || !targetName) {
|
|
212
|
+
throw new Error(`Node reference not found for edge: ${edge.source} -> ${edge.target}`);
|
|
213
|
+
}
|
|
214
|
+
const edgeName = `edge${i + 1}`;
|
|
215
|
+
edgeNames.push(edgeName);
|
|
216
|
+
code += `const ${edgeName} = new Edge({ source: ${sourceName}, target: ${targetName} });\n`;
|
|
217
|
+
}
|
|
218
|
+
code += '\n';
|
|
219
|
+
// Generate workflow creation
|
|
220
|
+
const nodeNames = Object.values(nodeRefToName);
|
|
221
|
+
const settingsCode = settings ? generateSettingsCode(settings) : 'null';
|
|
222
|
+
code += `const workflow = new Workflow('${wfJson.name}', [${nodeNames.join(', ')}], [${edgeNames.join(', ')}], ${settingsCode});\n`;
|
|
223
|
+
code += `\nreturn workflow;`;
|
|
224
|
+
return code;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Generates settings code for the workflow
|
|
228
|
+
* @param settings The workflow settings object
|
|
229
|
+
* @returns The settings code as a string
|
|
230
|
+
*/
|
|
231
|
+
const generateSettingsCode = (settings) => {
|
|
232
|
+
if (!settings)
|
|
233
|
+
return 'null';
|
|
234
|
+
let settingsCode = '{\n';
|
|
235
|
+
if (settings.loopingType) {
|
|
236
|
+
settingsCode += ` loopingType: WORKFLOW_LOOPING_TYPES.${settings.loopingType.toUpperCase()},\n`;
|
|
237
|
+
}
|
|
238
|
+
if (settings.period !== undefined) {
|
|
239
|
+
settingsCode += ` period: ${settings.period},\n`;
|
|
240
|
+
}
|
|
241
|
+
if (settings.limit !== undefined) {
|
|
242
|
+
settingsCode += ` limit: ${settings.limit},\n`;
|
|
243
|
+
}
|
|
244
|
+
if (settings.timeout !== undefined) {
|
|
245
|
+
settingsCode += ` timeout: ${settings.timeout},\n`;
|
|
246
|
+
}
|
|
247
|
+
// Remove trailing comma and newline
|
|
248
|
+
settingsCode = settingsCode.replace(/,\n$/, '\n');
|
|
249
|
+
settingsCode += '}';
|
|
250
|
+
return settingsCode;
|
|
251
|
+
};
|
|
252
|
+
// Uncomment to directly use the function
|
|
253
|
+
// Otherwise, import and use the convertWFJSONToCode function at your own convenience
|
|
254
|
+
// const jsonData = {
|
|
255
|
+
// YOUR JSON DATA HERE
|
|
256
|
+
// }
|
|
257
|
+
// console.log(convertWFJSONToCode(jsonData));
|
|
@@ -11,6 +11,61 @@ export declare const WORKFLOW_TEMPLATES_TAGS: {
|
|
|
11
11
|
DEXES: string;
|
|
12
12
|
LENDING: string;
|
|
13
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Default workflow loop settings for various workflow types.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_WORKFLOW_LOOP_SETTINGS: {
|
|
18
|
+
readonly subscription: {
|
|
19
|
+
readonly loopingType: "subscription";
|
|
20
|
+
readonly limit: 1000;
|
|
21
|
+
readonly timeout: number;
|
|
22
|
+
};
|
|
23
|
+
readonly polling1s: {
|
|
24
|
+
readonly loopingType: "polling";
|
|
25
|
+
readonly period: 1000;
|
|
26
|
+
readonly limit: 100;
|
|
27
|
+
};
|
|
28
|
+
readonly polling1h: {
|
|
29
|
+
readonly loopingType: "polling";
|
|
30
|
+
readonly period: number;
|
|
31
|
+
readonly limit: 100;
|
|
32
|
+
};
|
|
33
|
+
readonly polling4h: {
|
|
34
|
+
readonly loopingType: "polling";
|
|
35
|
+
readonly period: number;
|
|
36
|
+
readonly limit: 100;
|
|
37
|
+
};
|
|
38
|
+
readonly polling1d: {
|
|
39
|
+
readonly loopingType: "polling";
|
|
40
|
+
readonly period: number;
|
|
41
|
+
readonly limit: 100;
|
|
42
|
+
};
|
|
43
|
+
readonly polling12h: {
|
|
44
|
+
readonly loopingType: "polling";
|
|
45
|
+
readonly period: number;
|
|
46
|
+
readonly limit: 100;
|
|
47
|
+
};
|
|
48
|
+
readonly polling3d: {
|
|
49
|
+
readonly loopingType: "polling";
|
|
50
|
+
readonly period: number;
|
|
51
|
+
readonly limit: 100;
|
|
52
|
+
};
|
|
53
|
+
readonly polling7d: {
|
|
54
|
+
readonly loopingType: "polling";
|
|
55
|
+
readonly period: number;
|
|
56
|
+
readonly limit: 100;
|
|
57
|
+
};
|
|
58
|
+
readonly subscription1m20rep: {
|
|
59
|
+
readonly loopingType: "subscription";
|
|
60
|
+
readonly limit: 20;
|
|
61
|
+
readonly timeout: number;
|
|
62
|
+
};
|
|
63
|
+
readonly subscription1m30rep: {
|
|
64
|
+
readonly loopingType: "subscription";
|
|
65
|
+
readonly limit: 30;
|
|
66
|
+
readonly timeout: number;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
14
69
|
export declare const WORKFLOW_TEMPLATES: ({
|
|
15
70
|
id: number;
|
|
16
71
|
name: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.331";
|
|
2
2
|
export declare function compareVersions(v1: string, v2: string): number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the trigger constant string for a given blockId.
|
|
3
|
+
* @param blockId The block id to look up.
|
|
4
|
+
* @returns The trigger constant string, or undefined if not found.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Returns the trigger or action constant string for a given blockId.
|
|
8
|
+
* Searches both TRIGGERS and ACTIONS.
|
|
9
|
+
* @param blockId The block id to look up.
|
|
10
|
+
* @returns The trigger or action constant string, or undefined if not found.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getBlockConstantByBlockId: (blockId: number) => string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a workflow JSON object back to its representative code.
|
|
15
|
+
*
|
|
16
|
+
* @param wfJson The workflow JSON object
|
|
17
|
+
* @returns The workflow code as a string
|
|
18
|
+
*/
|
|
19
|
+
export declare const convertWFJSONToCode: (wfJson: any) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|