otomato-sdk 1.5.37 → 1.5.40

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 CHANGED
@@ -24,7 +24,7 @@ Here's how to create a trigger using the Otomato SDK:
24
24
  ```typescript
25
25
  import { Trigger, TRIGGERS, CHAINS, getTokenFromSymbol } from 'otomato-sdk';
26
26
 
27
- const transferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
27
+ const transferTrigger = new Trigger(TRIGGERS.TOKENS.TRANSFER.TRANSFER);
28
28
  transferTrigger.setChainId(CHAINS.ETHEREUM);
29
29
  transferTrigger.setParams("value", 1000);
30
30
  transferTrigger.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
@@ -1,11 +1,11 @@
1
1
  export const TRIGGERS = {
2
2
  "TOKENS": {
3
- "ERC20": {
4
- "description": "The most used standard for tokens on ethereum compatible blockchains",
3
+ "TRANSFER": {
4
+ "description": "Monitors token transfers",
5
5
  "chains": [
6
6
  0
7
7
  ],
8
- "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp",
8
+ "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/tokenTransfer.png",
9
9
  "TRANSFER": {
10
10
  "name": "Transfer token",
11
11
  "description": "This block gets triggered when someone transfers the ERC20 configured in the params",
@@ -71,8 +71,15 @@ export const TRIGGERS = {
71
71
  }
72
72
  ],
73
73
  "blockId": 1,
74
- "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp"
75
- },
74
+ "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/tokenTransfer.png"
75
+ }
76
+ },
77
+ "BALANCE": {
78
+ "description": "Monitors token balance of selected addresses",
79
+ "chains": [
80
+ 0
81
+ ],
82
+ "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/tokenBalance.png",
76
83
  "BALANCE": {
77
84
  "name": "ERC20 balance check",
78
85
  "description": "Fetches the balance of an ERC20 and checks it against the specified condition.",
@@ -98,7 +105,7 @@ export const TRIGGERS = {
98
105
  },
99
106
  {
100
107
  "key": "contractAddress",
101
- "type": "address",
108
+ "type": "erc20",
102
109
  "description": "The contract address of the ERC20",
103
110
  "mandatory": true,
104
111
  "category": 0
@@ -151,7 +158,7 @@ export const TRIGGERS = {
151
158
  }
152
159
  ],
153
160
  "blockId": 5,
154
- "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp"
161
+ "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/tokenBalance.png"
155
162
  }
156
163
  }
157
164
  },
@@ -463,7 +470,9 @@ export const TRIGGERS = {
463
470
  "blockId": 9,
464
471
  "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/splicefi.png"
465
472
  }
466
- },
473
+ }
474
+ },
475
+ "LENDING": {
467
476
  "IONIC": {
468
477
  "description": "#1 money market for Yield Bearing Assets on the OP Superchain",
469
478
  "chains": [
@@ -530,15 +539,14 @@ export const TRIGGERS = {
530
539
  ]
531
540
  }
532
541
  ],
542
+ "before": "\n async (env) => {\n const otomatoSdk = await import('otomato-sdk');\n \n if (!env.parameters.chainId)\n throw new Error('You need to provide the chainId first');\n \n const getIonicTokenFromToken = (chain, tokenAddress) => {\n const CHAINS = otomatoSdk.CHAINS;\n if (chain == CHAINS.MODE) {\n switch (tokenAddress.toLowerCase()) {\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDT').contractAddress.toLowerCase():\n return '0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDC').contractAddress.toLowerCase():\n return '0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'ezETH').contractAddress.toLowerCase():\n return '0x59e710215d45F584f44c0FEe83DA6d43D762D857';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress.toLowerCase():\n return '0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WBTC').contractAddress.toLowerCase():\n return '0xd70254C3baD29504789714A7c69d60Ec1127375C';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'STONE').contractAddress.toLowerCase():\n return '0x959FA710CCBb22c7Ce1e59Da82A247e686629310';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'wrsETH').contractAddress.toLowerCase():\n return '0x49950319aBE7CE5c3A6C90698381b45989C99b46';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'weETH.mode').contractAddress.toLowerCase():\n return '0xA0D844742B4abbbc43d8931a6Edb00C56325aA18';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'M-BTC').contractAddress.toLowerCase():\n return '0x19F245782b1258cf3e11Eda25784A378cC18c108';\n\n default: throw new Error('This asset is not available on Ionic');\n }\n }\n}\n \n let ionicTokenContractAddress = getIonicTokenFromToken(\n env.parameters.chainId,\n env.parameters.token.toLowerCase()\n );\n return {\n contractAddress: ionicTokenContractAddress\n };\n }",
533
543
  "output": {
534
544
  "lendingRate": "float"
535
545
  },
536
546
  "blockId": 15,
537
547
  "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ionic.jpg"
538
548
  }
539
- }
540
- },
541
- "LENDING": {
549
+ },
542
550
  "ASTARIA": {
543
551
  "description": "Astaria is an oracle-less, intent-based, fixed-rate lending protocol supporting unlimited loan durations for any asset",
544
552
  "chains": [
@@ -1121,8 +1129,8 @@ export const ACTIONS = {
1121
1129
  "chains": [
1122
1130
  34443
1123
1131
  ],
1124
- "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/delay.png",
1125
1132
  "SWAP": {
1133
+ "id": 100005,
1126
1134
  "name": "Swap",
1127
1135
  "description": "Swap two assets using the best market rates accross multiple pools",
1128
1136
  "type": 1,
@@ -1189,7 +1197,7 @@ export const ACTIONS = {
1189
1197
  "value": 0.3,
1190
1198
  "mandatory": true,
1191
1199
  "category": 1
1192
- },
1200
+ }
1193
1201
  ],
1194
1202
  "examples": [
1195
1203
  {
@@ -1231,10 +1239,9 @@ export const ACTIONS = {
1231
1239
  "Transfer ETH"
1232
1240
  ]
1233
1241
  },
1234
- "duplicate": true,
1235
- "blockId": 100005,
1236
- "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/delay.png"
1237
- }
1242
+ "duplicate": true
1243
+ },
1244
+ "blockId": 100013
1238
1245
  }
1239
1246
  },
1240
1247
  "NOTIFICATIONS": {
@@ -1355,12 +1362,12 @@ export const ACTIONS = {
1355
1362
  }
1356
1363
  },
1357
1364
  "TOKENS": {
1358
- "ERC20": {
1359
- "description": "The most used standard for tokens on ethereum compatible blockchains",
1365
+ "TRANSFER": {
1366
+ "description": "Transfer token",
1360
1367
  "chains": [
1361
1368
  34443
1362
1369
  ],
1363
- "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp",
1370
+ "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/tokenTransfer.png",
1364
1371
  "TRANSFER": {
1365
1372
  "name": "Transfer token",
1366
1373
  "description": "Transfers an ERC20 token",
@@ -1408,7 +1415,7 @@ export const ACTIONS = {
1408
1415
  "type": 0,
1409
1416
  "chainId": "{{parameters.chainId}}",
1410
1417
  "contractAddress": "{{parameters.contractAddress}}",
1411
- "amount": "{{parameters.abi.parameters.amount}}"
1418
+ "amount": "{{parameters.abi.parameters.value}}"
1412
1419
  }
1413
1420
  ],
1414
1421
  "examples": [
@@ -1447,7 +1454,7 @@ export const ACTIONS = {
1447
1454
  ]
1448
1455
  },
1449
1456
  "blockId": 100004,
1450
- "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp"
1457
+ "image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/tokenTransfer.png"
1451
1458
  }
1452
1459
  }
1453
1460
  },
@@ -1526,6 +1533,7 @@ export const ACTIONS = {
1526
1533
  "to": "{{before.contractAddress}}"
1527
1534
  }
1528
1535
  ],
1536
+ "before": "\n async (env) => {\n const otomatoSdk = await import('otomato-sdk');\n \n if (!env.parameters.chainId)\n throw new Error('You need to provide the chainId first');\n \n const getIonicTokenFromToken = (chain, tokenAddress) => {\n const CHAINS = otomatoSdk.CHAINS;\n if (chain == CHAINS.MODE) {\n switch (tokenAddress.toLowerCase()) {\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDT').contractAddress.toLowerCase():\n return '0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDC').contractAddress.toLowerCase():\n return '0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'ezETH').contractAddress.toLowerCase():\n return '0x59e710215d45F584f44c0FEe83DA6d43D762D857';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress.toLowerCase():\n return '0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WBTC').contractAddress.toLowerCase():\n return '0xd70254C3baD29504789714A7c69d60Ec1127375C';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'STONE').contractAddress.toLowerCase():\n return '0x959FA710CCBb22c7Ce1e59Da82A247e686629310';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'wrsETH').contractAddress.toLowerCase():\n return '0x49950319aBE7CE5c3A6C90698381b45989C99b46';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'weETH.mode').contractAddress.toLowerCase():\n return '0xA0D844742B4abbbc43d8931a6Edb00C56325aA18';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'M-BTC').contractAddress.toLowerCase():\n return '0x19F245782b1258cf3e11Eda25784A378cC18c108';\n\n default: throw new Error('This asset is not available on Ionic');\n }\n }\n}\n \n let ionicTokenContractAddress = getIonicTokenFromToken(\n env.parameters.chainId,\n env.parameters.tokenToDeposit.toLowerCase()\n );\n return {\n contractAddress: ionicTokenContractAddress\n };\n }",
1529
1537
  "output": {
1530
1538
  "transactionHash": "string"
1531
1539
  },
@@ -1615,6 +1623,7 @@ export const ACTIONS = {
1615
1623
  }
1616
1624
  ],
1617
1625
  "requiredApprovals": [],
1626
+ "before": "\n async (env) => {\n const otomatoSdk = await import('otomato-sdk');\n \n if (!env.parameters.chainId)\n throw new Error('You need to provide the chainId first');\n \n const getIonicTokenFromToken = (chain, tokenAddress) => {\n const CHAINS = otomatoSdk.CHAINS;\n if (chain == CHAINS.MODE) {\n switch (tokenAddress.toLowerCase()) {\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDT').contractAddress.toLowerCase():\n return '0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDC').contractAddress.toLowerCase():\n return '0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'ezETH').contractAddress.toLowerCase():\n return '0x59e710215d45F584f44c0FEe83DA6d43D762D857';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress.toLowerCase():\n return '0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WBTC').contractAddress.toLowerCase():\n return '0xd70254C3baD29504789714A7c69d60Ec1127375C';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'STONE').contractAddress.toLowerCase():\n return '0x959FA710CCBb22c7Ce1e59Da82A247e686629310';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'wrsETH').contractAddress.toLowerCase():\n return '0x49950319aBE7CE5c3A6C90698381b45989C99b46';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'weETH.mode').contractAddress.toLowerCase():\n return '0xA0D844742B4abbbc43d8931a6Edb00C56325aA18';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'M-BTC').contractAddress.toLowerCase():\n return '0x19F245782b1258cf3e11Eda25784A378cC18c108';\n\n default: throw new Error('This asset is not available on Ionic');\n }\n }\n}\n \n let ionicTokenContractAddress = getIonicTokenFromToken(\n env.parameters.chainId,\n env.parameters.tokenToWithdraw.toLowerCase()\n );\n return {\n contractAddress: ionicTokenContractAddress\n };\n }",
1618
1627
  "output": {
1619
1628
  "transactionHash": "string"
1620
1629
  },
@@ -1686,6 +1695,7 @@ export const ACTIONS = {
1686
1695
  }
1687
1696
  ],
1688
1697
  "requiredApprovals": [],
1698
+ "before": "\n async (env) => {\n const otomatoSdk = await import('otomato-sdk');\n \n if (!env.parameters.chainId)\n throw new Error('You need to provide the chainId first');\n \n const getIonicTokenFromToken = (chain, tokenAddress) => {\n const CHAINS = otomatoSdk.CHAINS;\n if (chain == CHAINS.MODE) {\n switch (tokenAddress.toLowerCase()) {\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDT').contractAddress.toLowerCase():\n return '0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDC').contractAddress.toLowerCase():\n return '0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'ezETH').contractAddress.toLowerCase():\n return '0x59e710215d45F584f44c0FEe83DA6d43D762D857';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress.toLowerCase():\n return '0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WBTC').contractAddress.toLowerCase():\n return '0xd70254C3baD29504789714A7c69d60Ec1127375C';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'STONE').contractAddress.toLowerCase():\n return '0x959FA710CCBb22c7Ce1e59Da82A247e686629310';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'wrsETH').contractAddress.toLowerCase():\n return '0x49950319aBE7CE5c3A6C90698381b45989C99b46';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'weETH.mode').contractAddress.toLowerCase():\n return '0xA0D844742B4abbbc43d8931a6Edb00C56325aA18';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'M-BTC').contractAddress.toLowerCase():\n return '0x19F245782b1258cf3e11Eda25784A378cC18c108';\n\n default: throw new Error('This asset is not available on Ionic');\n }\n }\n}\n \n let ionicTokenContractAddress = getIonicTokenFromToken(\n env.parameters.chainId,\n env.parameters.tokenToBorrow.toLowerCase()\n );\n return {\n contractAddress: ionicTokenContractAddress\n };\n }",
1689
1699
  "output": {
1690
1700
  "transactionHash": "string"
1691
1701
  },
@@ -1771,6 +1781,7 @@ export const ACTIONS = {
1771
1781
  "to": "{{before.contractAddress}}"
1772
1782
  }
1773
1783
  ],
1784
+ "before": "\n async (env) => {\n const otomatoSdk = await import('otomato-sdk');\n \n if (!env.parameters.chainId)\n throw new Error('You need to provide the chainId first');\n \n const getIonicTokenFromToken = (chain, tokenAddress) => {\n const CHAINS = otomatoSdk.CHAINS;\n if (chain == CHAINS.MODE) {\n switch (tokenAddress.toLowerCase()) {\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDT').contractAddress.toLowerCase():\n return '0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'USDC').contractAddress.toLowerCase():\n return '0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'ezETH').contractAddress.toLowerCase():\n return '0x59e710215d45F584f44c0FEe83DA6d43D762D857';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress.toLowerCase():\n return '0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'WBTC').contractAddress.toLowerCase():\n return '0xd70254C3baD29504789714A7c69d60Ec1127375C';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'STONE').contractAddress.toLowerCase():\n return '0x959FA710CCBb22c7Ce1e59Da82A247e686629310';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'wrsETH').contractAddress.toLowerCase():\n return '0x49950319aBE7CE5c3A6C90698381b45989C99b46';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'weETH.mode').contractAddress.toLowerCase():\n return '0xA0D844742B4abbbc43d8931a6Edb00C56325aA18';\n case otomatoSdk.getTokenFromSymbol(CHAINS.MODE, 'M-BTC').contractAddress.toLowerCase():\n return '0x19F245782b1258cf3e11Eda25784A378cC18c108';\n\n default: throw new Error('This asset is not available on Ionic');\n }\n }\n}\n \n let ionicTokenContractAddress = getIonicTokenFromToken(\n env.parameters.chainId,\n env.parameters.tokenToRepay.toLowerCase()\n );\n return {\n contractAddress: ionicTokenContractAddress\n };\n }",
1774
1785
  "output": {
1775
1786
  "transactionHash": "string"
1776
1787
  },
@@ -1805,7 +1816,7 @@ export const ACTIONS = {
1805
1816
  },
1806
1817
  {
1807
1818
  "key": "abiParams.tokens",
1808
- "type": "uint256",
1819
+ "type": "addresses_array",
1809
1820
  "description": "List of collaterals",
1810
1821
  "mandatory": true,
1811
1822
  "category": 0
@@ -1817,10 +1828,10 @@ export const ACTIONS = {
1817
1828
  "0xFB3323E24743Caf4ADD0fDCCFB268565c0685556"
1818
1829
  ],
1819
1830
  "label": [
1820
- "Borrow against {{tokenSymbol({{parameters.chainId}}, {{parameters.abiParams.tokens[0]}})}} on IONIC"
1831
+ "Enable {{tokenSymbol({{parameters.chainId}}, {{parameters.abi.parameters.tokens[0]}})}} as collateral on IONIC"
1821
1832
  ],
1822
1833
  "labelNotAuthorized": [
1823
- "Transfer {{tokenSymbol({{parameters.chainId}}, {{parameters.abiParams.tokens[0]}})}}"
1834
+ "Transfer {{tokenSymbol({{parameters.chainId}}, {{parameters.abi.parameters.tokens[0]}})}}"
1824
1835
  ]
1825
1836
  },
1826
1837
  "blockId": 100012,
@@ -15,7 +15,7 @@ export const WORKFLOW_TEMPLATES_TAGS = {
15
15
  ON_CHAIN_MONITORING: 'On-chain monitoring'
16
16
  };
17
17
  const createModeTransferNotificationWorkflow = () => {
18
- const modeTransferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
18
+ const modeTransferTrigger = new Trigger(TRIGGERS.TOKENS.TRANSFER.TRANSFER);
19
19
  modeTransferTrigger.setChainId(CHAINS.MODE);
20
20
  modeTransferTrigger.setContractAddress(getTokenFromSymbol(CHAINS.MODE, 'MODE').contractAddress);
21
21
  modeTransferTrigger.setParams('from', '0x74B847b308BD89Ef15639E6e4a2544E4b8b8C6B4');
@@ -16,13 +16,73 @@ export class Action extends Node {
16
16
  super(Object.assign(Object.assign({}, action), { class: 'action', parentInfo: findActionByBlockId(action.blockId).parentInfo }));
17
17
  }
18
18
  getSessionKeyPermissions() {
19
- const parentBlock = findActionByBlockId(this.blockId).block;
20
- if (!parentBlock.permissions)
21
- return null;
22
- const permissions = SessionKeyPermission.fromJSON(parentBlock.permissions);
23
- permissions.fillParameters(this.getParameters());
24
- permissions.fillMethod();
25
- return permissions;
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const parentBlock = findActionByBlockId(this.blockId).block;
21
+ if (!parentBlock.permissions)
22
+ return null;
23
+ const permissions = SessionKeyPermission.fromJSON(parentBlock.permissions);
24
+ permissions.fillParameters(this.getParameters());
25
+ permissions.fillMethod();
26
+ // Handle 'before' code for the main action
27
+ if (parentBlock.before) {
28
+ yield permissions.fillBeforeVariables(parentBlock.before, this.getParameters());
29
+ }
30
+ // Handle batchWith: for any batched actions, merge their permissions
31
+ if (parentBlock.batchWith && parentBlock.batchWith.length > 0) {
32
+ for (const batch of parentBlock.batchWith) {
33
+ const batchedAction = findActionByBlockId(batch.id).block;
34
+ if (batchedAction.permissions) {
35
+ const batchedActionInstance = new Action(batchedAction);
36
+ // Replace placeholders in parameters
37
+ const resolvedBatchParams = batch.parameters;
38
+ Object.keys(resolvedBatchParams).forEach(key => {
39
+ var _a;
40
+ // If it's an ABI parameter, handle it separately
41
+ if (key === 'abi' && ((_a = resolvedBatchParams.abi) === null || _a === void 0 ? void 0 : _a.parameters)) {
42
+ Object.keys(resolvedBatchParams.abi.parameters).forEach(abiKey => {
43
+ const abiValue = this.replaceVariables(resolvedBatchParams.abi.parameters[abiKey]);
44
+ batchedActionInstance.setParams(`${abiKey}`, abiValue);
45
+ });
46
+ }
47
+ else {
48
+ let value = this.replaceVariables(resolvedBatchParams[key]);
49
+ batchedActionInstance.setParams(key, value);
50
+ }
51
+ });
52
+ // Get batched permissions
53
+ const batchedPermissions = yield batchedActionInstance.getSessionKeyPermissions();
54
+ if (!batchedPermissions)
55
+ continue;
56
+ batchedPermissions.fillParameters(batch.parameters); // Pass batched action parameters
57
+ batchedPermissions.fillMethod();
58
+ // Handle 'before' code for the batched action
59
+ if (batchedAction.before) {
60
+ yield batchedPermissions.fillBeforeVariables(batchedAction.before, batch.parameters);
61
+ }
62
+ // Merge the batched action's permissions with the main action's permissions
63
+ permissions.merge(batchedPermissions);
64
+ }
65
+ }
66
+ }
67
+ return permissions;
68
+ });
69
+ }
70
+ /**
71
+ * Replace any placeholders like {{parameters.tokenToDeposit}} with actual values
72
+ * from the parameters of the current action. Supports both strings and arrays.
73
+ */
74
+ replaceVariables(value) {
75
+ if (typeof value === 'string') {
76
+ return value.replace(/\{\{parameters\.(.*?)\}\}/g, (_, key) => {
77
+ console.log(`Looking for ${key} parameter`);
78
+ return this.getParameter(key) || '';
79
+ });
80
+ }
81
+ if (Array.isArray(value)) {
82
+ return value.map(item => this.replaceVariables(item)); // Recursively handle each array element
83
+ }
84
+ // Return the value unchanged if it's neither a string nor an array
85
+ return value;
26
86
  }
27
87
  static fromJSON(json) {
28
88
  return __awaiter(this, void 0, void 0, function* () {
@@ -7,7 +7,7 @@ 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 { validateType, isANumber } from '../utils/typeValidator.js';
10
+ import { validateType, typeIsNumber } from '../utils/typeValidator.js';
11
11
  import { apiServices } from '../services/ApiService.js';
12
12
  let nodeCounter = 0;
13
13
  const generatedRefs = new Set();
@@ -73,11 +73,22 @@ export class Node {
73
73
  if (key in this.parameters) {
74
74
  const param = this.parameters[key];
75
75
  try {
76
- // if the user pass '100000n' for a number, we transform it to Bigints
77
- if (isANumber(param.type) && (value === null || value === void 0 ? void 0 : value.endsWith('n')))
76
+ // BigInt conversion
77
+ if (typeIsNumber(param.type) && typeof value === 'string' && value.endsWith('n')) {
78
78
  value = BigInt(value.substring(0, value.length - 1));
79
+ }
80
+ // String to integer conversion
81
+ if (typeIsNumber(param.type) && typeof value === 'string') {
82
+ const parsedValue = parseInt(value, 10);
83
+ if (!isNaN(parsedValue)) {
84
+ value = parsedValue;
85
+ }
86
+ }
87
+ }
88
+ catch (e) {
89
+ console.error(`Error processing parameter ${key}:`, e);
79
90
  }
80
- catch (e) { }
91
+ // Validate the value type
81
92
  if (validateType(param.type, value)) {
82
93
  this.parameters[key].value = value;
83
94
  }
@@ -1,3 +1,12 @@
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 { getToken } from "../constants/tokens.js";
2
11
  export class SessionKeyPermission {
3
12
  constructor({ approvedTargets = [], label = [], labelNotAuthorized = [], } = {}) {
@@ -6,26 +15,81 @@ export class SessionKeyPermission {
6
15
  this.labelNotAuthorized = labelNotAuthorized;
7
16
  }
8
17
  fill(key, value) {
9
- const replacePlaceholder = (target) => {
10
- const placeholder = new RegExp(`{{${key}}}`, 'g');
11
- return target.replace(placeholder, value);
12
- };
18
+ // Escape special regex characters in the key
19
+ const escapedKey = key.replace(/[.*+?^${}()|[\]\\[\]]/g, '\\$&');
20
+ const placeholder = new RegExp(`{{${escapedKey}}}`, 'g');
21
+ // Function to replace placeholders in a target string
22
+ const replacePlaceholder = (target) => target.replace(placeholder, value);
23
+ // Apply the placeholder replacement logic
13
24
  this.approvedTargets = this.approvedTargets.map(replacePlaceholder);
14
25
  this.label = this.label.map(replacePlaceholder);
15
26
  this.labelNotAuthorized = this.labelNotAuthorized.map(replacePlaceholder);
16
27
  }
28
+ /**
29
+ * Fill placeholders using variables returned by the 'before' string execution.
30
+ * @param beforeCode - A string representing the 'before' logic to execute.
31
+ */
32
+ fillBeforeVariables(beforeCode, parameters) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ try {
35
+ // Prepare the environment with parameters
36
+ const env = { parameters };
37
+ // Replace the import statement in the beforeCode string if needed
38
+ const beforeCodeUpdated = beforeCode.replace("import('otomato-sdk')", "import('../index.js')");
39
+ // Wrap the beforeCode in an async function and immediately invoke it
40
+ const asyncBeforeFn = new Function('env', `
41
+ return (async function() {
42
+ return await (${beforeCodeUpdated})(env);
43
+ })();
44
+ `);
45
+ // Execute the async function and await the result
46
+ const beforeResult = yield asyncBeforeFn(env);
47
+ // Replace placeholders like {{before.variableName}} with the corresponding values
48
+ if (beforeResult && typeof beforeResult === 'object') {
49
+ Object.keys(beforeResult).forEach(key => {
50
+ this.fill(`before.${key}`, beforeResult[key]);
51
+ });
52
+ }
53
+ else {
54
+ console.error("Before function did not return an object:", beforeResult);
55
+ }
56
+ }
57
+ catch (error) {
58
+ console.error('Error executing before code:', error);
59
+ }
60
+ });
61
+ }
62
+ // The rest of your existing code
17
63
  fillParameters(params) {
18
64
  var _a;
19
- // 1. replace non abi params
65
+ // Helper to handle the replacement in case of arrays
66
+ const fillArray = (key, array) => {
67
+ array.forEach((item, index) => {
68
+ if (typeof item === 'string') {
69
+ this.fill(`${key}[${index}]`, item);
70
+ }
71
+ });
72
+ };
73
+ // 1. Replace non-ABI params
20
74
  for (let key in params) {
21
75
  if (key !== 'abi') {
22
- this.fill(`parameters.${key}`, params[key]);
76
+ if (Array.isArray(params[key])) {
77
+ fillArray(`parameters.${key}`, params[key]);
78
+ }
79
+ else {
80
+ this.fill(`parameters.${key}`, params[key]);
81
+ }
23
82
  }
24
83
  }
25
- // 2. replace abi params
84
+ // 2. Replace ABI params
26
85
  const abiParams = (_a = params.abi) === null || _a === void 0 ? void 0 : _a.parameters;
27
86
  for (let key in abiParams) {
28
- this.fill(`parameters.abiParams.${key}`, abiParams[key]);
87
+ if (Array.isArray(abiParams[key])) {
88
+ fillArray(`parameters.abi.parameters.${key}`, abiParams[key]);
89
+ }
90
+ else {
91
+ this.fill(`parameters.abi.parameters.${key}`, abiParams[key]);
92
+ }
29
93
  }
30
94
  }
31
95
  fillMethod() {
@@ -89,6 +153,7 @@ export class SessionKeyPermission {
89
153
  this.labelNotAuthorized = this.labelNotAuthorized.filter(lbl => !this.label.includes(lbl));
90
154
  }
91
155
  }
156
+ // Helper function to get a different token
92
157
  const getDifferentToken = (chain, contractAddress) => {
93
158
  var _a;
94
159
  const tokenSymbol = (_a = getToken(chain, contractAddress)) === null || _a === void 0 ? void 0 : _a.symbol;
@@ -202,20 +202,22 @@ export class Workflow {
202
202
  });
203
203
  }
204
204
  getSessionKeyPermissions() {
205
- const permissions = new SessionKeyPermission();
206
- for (const node of this.nodes) {
207
- try {
208
- if (node.class === 'action' && 'getSessionKeyPermissions' in node) {
209
- const nodePermissions = node.getSessionKeyPermissions();
210
- if (nodePermissions) {
211
- permissions.merge(nodePermissions);
205
+ return __awaiter(this, void 0, void 0, function* () {
206
+ const permissions = new SessionKeyPermission();
207
+ for (const node of this.nodes) {
208
+ try {
209
+ if (node.class === 'action' && 'getSessionKeyPermissions' in node) {
210
+ const nodePermissions = yield node.getSessionKeyPermissions();
211
+ if (nodePermissions) {
212
+ permissions.merge(nodePermissions);
213
+ }
212
214
  }
213
215
  }
216
+ catch (error) {
217
+ console.error(`Error getting session key permissions for node ${node.getRef()}:`, error);
218
+ }
214
219
  }
215
- catch (error) {
216
- console.error(`Error getting session key permissions for node ${node.getRef()}:`, error);
217
- }
218
- }
219
- return permissions;
220
+ return permissions;
221
+ });
220
222
  }
221
223
  }
@@ -1,25 +1,4 @@
1
1
  import { ethers } from 'ethers';
2
- export function isANumber(type) {
3
- switch (type) {
4
- case 'integer':
5
- return true;
6
- case 'int8':
7
- case 'int16':
8
- case 'int32':
9
- case 'int64':
10
- case 'int128':
11
- case 'int256':
12
- return true;
13
- case 'uint8':
14
- case 'uint16':
15
- case 'uint32':
16
- case 'uint64':
17
- case 'uint128':
18
- case 'uint256':
19
- return true;
20
- default: return false;
21
- }
22
- }
23
2
  export function validateType(expectedType, value) {
24
3
  switch (expectedType) {
25
4
  case 'bool':
@@ -62,6 +41,9 @@ export function validateType(expectedType, value) {
62
41
  case 'logic_operator':
63
42
  const validOperators = new Set(['gte', 'gt', 'lte', 'lt', 'eq', 'neq']);
64
43
  return typeof value === 'string' && validOperators.has(value);
44
+ case 'addresses_array':
45
+ // Ensure value is an array, and each element is a valid address
46
+ return Array.isArray(value) && value.every(isAddress);
65
47
  case 'any':
66
48
  return true;
67
49
  default:
@@ -1,7 +1,7 @@
1
1
  import { Parameter } from '../models/Parameter.js';
2
2
  export declare const TRIGGERS: {
3
3
  TOKENS: {
4
- ERC20: {
4
+ TRANSFER: {
5
5
  description: string;
6
6
  chains: number[];
7
7
  image: string;
@@ -30,6 +30,11 @@ export declare const TRIGGERS: {
30
30
  blockId: number;
31
31
  image: string;
32
32
  };
33
+ };
34
+ BALANCE: {
35
+ description: string;
36
+ chains: number[];
37
+ image: string;
33
38
  BALANCE: {
34
39
  name: string;
35
40
  description: string;
@@ -183,6 +188,8 @@ export declare const TRIGGERS: {
183
188
  image: string;
184
189
  };
185
190
  };
191
+ };
192
+ LENDING: {
186
193
  IONIC: {
187
194
  description: string;
188
195
  chains: number[];
@@ -204,6 +211,7 @@ export declare const TRIGGERS: {
204
211
  value: string;
205
212
  })[];
206
213
  }[];
214
+ before: string;
207
215
  output: {
208
216
  lendingRate: string;
209
217
  };
@@ -211,8 +219,6 @@ export declare const TRIGGERS: {
211
219
  image: string;
212
220
  };
213
221
  };
214
- };
215
- LENDING: {
216
222
  ASTARIA: {
217
223
  description: string;
218
224
  chains: number[];
@@ -452,8 +458,8 @@ export declare const ACTIONS: {
452
458
  SWAP: {
453
459
  description: string;
454
460
  chains: number[];
455
- image: string;
456
461
  SWAP: {
462
+ id: number;
457
463
  name: string;
458
464
  description: string;
459
465
  type: number;
@@ -476,7 +482,34 @@ export declare const ACTIONS: {
476
482
  tokenOut: string;
477
483
  transactionHash: string;
478
484
  };
479
- parameters: Parameter[];
485
+ parameters: ({
486
+ key: string;
487
+ type: string;
488
+ description: string;
489
+ mandatory: boolean;
490
+ category: number;
491
+ erc20FormattedAmount?: undefined;
492
+ value?: undefined;
493
+ } | {
494
+ key: string;
495
+ type: string;
496
+ description: string;
497
+ mandatory: boolean;
498
+ category: number;
499
+ erc20FormattedAmount: {
500
+ contractAddress: string;
501
+ chain: string;
502
+ };
503
+ value?: undefined;
504
+ } | {
505
+ key: string;
506
+ type: string;
507
+ description: string;
508
+ value: number;
509
+ mandatory: boolean;
510
+ category: number;
511
+ erc20FormattedAmount?: undefined;
512
+ })[];
480
513
  examples: {
481
514
  name: string;
482
515
  description: string;
@@ -494,9 +527,8 @@ export declare const ACTIONS: {
494
527
  labelNotAuthorized: string[];
495
528
  };
496
529
  duplicate: boolean;
497
- blockId: number;
498
- image: string;
499
530
  };
531
+ blockId: number;
500
532
  };
501
533
  };
502
534
  NOTIFICATIONS: {
@@ -569,7 +601,7 @@ export declare const ACTIONS: {
569
601
  };
570
602
  };
571
603
  TOKENS: {
572
- ERC20: {
604
+ TRANSFER: {
573
605
  description: string;
574
606
  chains: number[];
575
607
  image: string;
@@ -642,6 +674,7 @@ export declare const ACTIONS: {
642
674
  amount: string;
643
675
  to: string;
644
676
  }[];
677
+ before: string;
645
678
  output: {
646
679
  transactionHash: string;
647
680
  };
@@ -684,6 +717,7 @@ export declare const ACTIONS: {
684
717
  })[];
685
718
  }[];
686
719
  requiredApprovals: never[];
720
+ before: string;
687
721
  output: {
688
722
  transactionHash: string;
689
723
  };
@@ -713,6 +747,7 @@ export declare const ACTIONS: {
713
747
  })[];
714
748
  }[];
715
749
  requiredApprovals: never[];
750
+ before: string;
716
751
  output: {
717
752
  transactionHash: string;
718
753
  };
@@ -752,6 +787,7 @@ export declare const ACTIONS: {
752
787
  amount: string;
753
788
  to: string;
754
789
  }[];
790
+ before: string;
755
791
  output: {
756
792
  transactionHash: string;
757
793
  };
@@ -16,7 +16,12 @@ export declare class Action extends Node {
16
16
  parentInfo?: ParentInfo;
17
17
  state?: NodeState;
18
18
  });
19
- getSessionKeyPermissions(): SessionKeyPermission | null;
19
+ getSessionKeyPermissions(): Promise<SessionKeyPermission | null>;
20
+ /**
21
+ * Replace any placeholders like {{parameters.tokenToDeposit}} with actual values
22
+ * from the parameters of the current action. Supports both strings and arrays.
23
+ */
24
+ replaceVariables(value: any): any;
20
25
  static fromJSON(json: {
21
26
  [key: string]: any;
22
27
  }): Promise<Action>;
@@ -8,6 +8,13 @@ export declare class SessionKeyPermission {
8
8
  labelNotAuthorized?: string[];
9
9
  });
10
10
  fill(key: string, value: any): void;
11
+ /**
12
+ * Fill placeholders using variables returned by the 'before' string execution.
13
+ * @param beforeCode - A string representing the 'before' logic to execute.
14
+ */
15
+ fillBeforeVariables(beforeCode: string, parameters: {
16
+ [key: string]: any;
17
+ }): Promise<void>;
11
18
  fillParameters(params: {
12
19
  [key: string]: any;
13
20
  }): void;
@@ -49,5 +49,5 @@ export declare class Workflow {
49
49
  success: boolean;
50
50
  error?: string;
51
51
  }>;
52
- getSessionKeyPermissions(): SessionKeyPermission;
52
+ getSessionKeyPermissions(): Promise<SessionKeyPermission>;
53
53
  }
@@ -1,4 +1,3 @@
1
- export declare function isANumber(type: string): boolean;
2
1
  export declare function validateType(expectedType: string, value: any): boolean;
3
2
  export declare function typeIsNumber(type: string): boolean;
4
3
  export declare function isAddress(value: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "1.5.37",
3
+ "version": "1.5.40",
4
4
  "description": "An SDK for building and managing automations on Otomato",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/types/src/index.d.ts",