otomato-sdk 2.0.13 → 2.0.15

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.
Files changed (71) hide show
  1. package/dist/src/constants/Blocks.js +1102 -36
  2. package/dist/src/constants/tokens.js +1 -1
  3. package/dist/src/constants/version.js +1 -1
  4. package/dist/src/models/Node.js +0 -2
  5. package/dist/types/examples/UseCases/lending-aggregator-v2.d.ts +4 -0
  6. package/dist/types/examples/UseCases/stop-lending-aggregator.d.ts +7 -0
  7. package/dist/types/src/constants/Blocks.d.ts +480 -8
  8. package/dist/types/src/constants/version.d.ts +1 -1
  9. package/package.json +1 -1
  10. package/dist/src/constants/ActionBlocks.js +0 -321
  11. package/dist/src/models/Automation.js +0 -44
  12. package/dist/src/utils/balances/addressBalance.js +0 -177
  13. package/dist/src/utils/balances/getBalanceInUnderlying.js +0 -95
  14. package/dist/types/examples/ex.d.ts +0 -1
  15. package/dist/types/examples/lending-aggregator.d.ts +0 -1
  16. package/dist/types/examples/load-workflows.d.ts +0 -1
  17. package/dist/types/examples/protocols/aave_trigger_borrow_action_borrow.d.ts +0 -1
  18. package/dist/types/examples/protocols/aave_trigger_borrow_action_withdraw.d.ts +0 -1
  19. package/dist/types/examples/protocols/aave_trigger_supply_action_supply.d.ts +0 -1
  20. package/dist/types/examples/protocols/ionic_base_supply.d.ts +0 -1
  21. package/dist/types/examples/protocols/ionic_base_withdraw.d.ts +0 -1
  22. package/dist/types/examples/sandbox.d.ts +0 -1
  23. package/dist/types/examples/update-edge.d.ts +0 -1
  24. package/dist/types/examples/yield-comparator.d.ts +0 -1
  25. package/dist/types/src/constants/ActionBlocks.d.ts +0 -91
  26. package/dist/types/src/models/Automation.d.ts +0 -23
  27. package/dist/types/src/models/Condition.d.ts +0 -6
  28. package/dist/types/src/services/AutomationService.d.ts +0 -6
  29. package/dist/types/src/utils/balances/addressBalance.d.ts +0 -20
  30. package/dist/types/src/utils/balances/getBalanceInUnderlying.d.ts +0 -44
  31. package/dist/types/test/automation.spec.d.ts +0 -1
  32. package/dist/types/test/sessionKeyPermission.spec.d.ts +0 -1
  33. /package/dist/types/examples/{authorizations.d.ts → Core/authorizations.d.ts} +0 -0
  34. /package/dist/types/examples/{create-action.d.ts → Core/create-action.d.ts} +0 -0
  35. /package/dist/types/examples/{create-condition.d.ts → Core/create-condition.d.ts} +0 -0
  36. /package/dist/types/examples/{create-trigger-list.d.ts → Core/create-trigger-list.d.ts} +0 -0
  37. /package/dist/types/examples/{create-trigger.d.ts → Core/create-trigger.d.ts} +0 -0
  38. /package/dist/types/examples/{delete-edge.d.ts → Core/delete-edge.d.ts} +0 -0
  39. /package/dist/types/examples/{login.d.ts → Core/login.d.ts} +0 -0
  40. /package/dist/types/examples/{rpcServices.d.ts → Core/rpcServices.d.ts} +0 -0
  41. /package/dist/types/examples/{sessionKeyPermissions.d.ts → Core/sessionKeyPermissions.d.ts} +0 -0
  42. /package/dist/types/examples/{update-action.d.ts → Core/update-action.d.ts} +0 -0
  43. /package/dist/types/examples/{version.d.ts → Core/version.d.ts} +0 -0
  44. /package/dist/types/examples/{aave-trigger-borrow-action-borrow.d.ts → DeFi/AAVE/aave-trigger-borrow-action-borrow.d.ts} +0 -0
  45. /package/dist/types/examples/{aave-trigger-supply-action-supply.d.ts → DeFi/AAVE/aave-trigger-supply-action-supply.d.ts} +0 -0
  46. /package/dist/types/examples/{compound-supply-trigger-and-supply-action.d.ts → DeFi/Compound/compound-supply-trigger-and-supply-action.d.ts} +0 -0
  47. /package/dist/types/examples/{compound-withdraw-trigger-and-withdraw-action.d.ts → DeFi/Compound/compound-withdraw-trigger-and-withdraw-action.d.ts} +0 -0
  48. /package/dist/types/examples/{ionic-base-supply.d.ts → DeFi/Ionic/ionic-base-supply.d.ts} +0 -0
  49. /package/dist/types/examples/{ionic-base-withdraw.d.ts → DeFi/Ionic/ionic-base-withdraw.d.ts} +0 -0
  50. /package/dist/types/examples/{ionic-trigger-lending.d.ts → DeFi/Ionic/ionic-trigger-lending.d.ts} +0 -0
  51. /package/dist/types/examples/{ionic-trigger-withdraw.d.ts → DeFi/Ionic/ionic-trigger-withdraw.d.ts} +0 -0
  52. /package/dist/{src/models/Condition.js → types/examples/DeFi/Ironclad/ironclad-trigger-borrow-action-withdraw.d.ts} +0 -0
  53. /package/dist/{src/services/AutomationService.js → types/examples/DeFi/Ironclad/ironclad-trigger-supply-action-supply.d.ts} +0 -0
  54. /package/dist/types/examples/{moonwell-borrow-trigger-deposit-action.d.ts → DeFi/Moonwell/moonwell-borrow-trigger-deposit-action.d.ts} +0 -0
  55. /package/dist/types/examples/{moonwell-borrow.d.ts → DeFi/Moonwell/moonwell-borrow.d.ts} +0 -0
  56. /package/dist/types/examples/{moonwell-repay.d.ts → DeFi/Moonwell/moonwell-repay.d.ts} +0 -0
  57. /package/dist/types/examples/{moonwell-supply-trigger-withdraw-action.d.ts → DeFi/Moonwell/moonwell-supply-trigger-withdraw-action.d.ts} +0 -0
  58. /package/dist/types/examples/{create-odos-swap.d.ts → DeFi/Odos/create-odos-swap.d.ts} +0 -0
  59. /package/dist/types/examples/{create-automation.d.ts → UseCases/lending-aggregator-base.d.ts} +0 -0
  60. /package/dist/types/examples/{create-workflow-with-condition-and-split.d.ts → UseCases/lending-aggregator-mode.d.ts} +0 -0
  61. /package/dist/types/examples/{create-workflow-with-condition.d.ts → Workflow/create-workflow-with-condition-and-split.d.ts} +0 -0
  62. /package/dist/types/examples/{create-workflow-with-external-variable-condition.d.ts → Workflow/create-workflow-with-condition.d.ts} +0 -0
  63. /package/dist/types/examples/{create-workflow-with-notes.d.ts → Workflow/create-workflow-with-external-variable-condition.d.ts} +0 -0
  64. /package/dist/types/examples/{create-workflow-with-split.d.ts → Workflow/create-workflow-with-notes.d.ts} +0 -0
  65. /package/dist/types/examples/{create-workflow-with-variables.d.ts → Workflow/create-workflow-with-split.d.ts} +0 -0
  66. /package/dist/types/examples/{create-workflow.d.ts → Workflow/create-workflow-with-variables.d.ts} +0 -0
  67. /package/dist/types/examples/{delete-workflow.d.ts → Workflow/create-workflow.d.ts} +0 -0
  68. /package/dist/types/examples/{everyhour-ifusdc-ionic.d.ts → Workflow/delete-workflow.d.ts} +0 -0
  69. /package/dist/types/examples/{get-all-workflows-from-user.d.ts → Workflow/get-all-workflows-from-user.d.ts} +0 -0
  70. /package/dist/types/examples/{load-workflow.d.ts → Workflow/load-workflow.d.ts} +0 -0
  71. /package/dist/types/examples/{workflow-templates.d.ts → Workflow/workflow-templates.d.ts} +0 -0
@@ -1,321 +0,0 @@
1
- import { CHAINS } from './chains.js';
2
- const TRIGGER_TYPE = {
3
- SUBSCRIPTION: 0,
4
- POLLING: 1,
5
- };
6
- export const TRIGGERS = {
7
- TOKENS: {
8
- ERC20: {
9
- CHAINS: [CHAINS.ALL],
10
- TRANSFER: {
11
- id: 1,
12
- name: "Transfer token",
13
- description: "Transfer an ERC-20 token",
14
- type: TRIGGER_TYPE.SUBSCRIPTION,
15
- parameters: [
16
- {
17
- key: "chainId",
18
- type: "int",
19
- description: "Chain ID of the ETH blockchain"
20
- },
21
- {
22
- key: "abiParams.value",
23
- type: "uint256",
24
- description: "Amount of crypto to transfer"
25
- },
26
- {
27
- key: "abiParams.to",
28
- type: "address",
29
- description: "Address to transfer crypto to"
30
- },
31
- {
32
- key: "contractAddress",
33
- type: "address",
34
- description: "The contract address of the ERC20"
35
- }
36
- ]
37
- },
38
- BALANCE: {
39
- id: 1000,
40
- name: "ERC20 balance check",
41
- description: "Fetches the balance of an ERC20 and checks it against the specified condition.",
42
- type: TRIGGER_TYPE.POLLING,
43
- parameters: [
44
- {
45
- key: "chainId",
46
- type: "int",
47
- description: "Chain ID of the ETH blockchain"
48
- },
49
- {
50
- key: "abiParams.account",
51
- type: "address",
52
- description: "Amount of crypto to transfer"
53
- },
54
- {
55
- key: "contractAddress",
56
- type: "address",
57
- description: "The contract address of the ERC20"
58
- },
59
- {
60
- key: "condition",
61
- type: "logic_operator",
62
- description: "Logic operator used for the comparison: <, >, <=, >=, ==, ..."
63
- },
64
- // todo: it should be in the same type as the output of the function
65
- {
66
- key: "comparisonValue",
67
- type: "any",
68
- description: "The value to compare to"
69
- },
70
- {
71
- key: "interval",
72
- type: "integer",
73
- description: "The waiting time between each polling"
74
- },
75
- ],
76
- }
77
- },
78
- },
79
- YIELD: {
80
- SPLICE_FI: {
81
- CHAINS: [CHAINS.MODE],
82
- SWAP: {
83
- id: 2,
84
- name: "Splice Finance Swap",
85
- description: "Swap in Splice Finance",
86
- type: TRIGGER_TYPE.SUBSCRIPTION,
87
- parameters: [
88
- {
89
- key: "abiParams.caller",
90
- type: "address",
91
- description: "Caller address"
92
- },
93
- {
94
- key: "abiParams.market",
95
- type: "address",
96
- description: "Market address"
97
- },
98
- {
99
- key: "abiParams.receiver",
100
- type: "address",
101
- description: "Receiver address"
102
- },
103
- {
104
- key: "abiParams.netPtToAccount",
105
- type: "int256",
106
- description: "Net PT to account"
107
- },
108
- {
109
- key: "abiParams.netSyToAccount",
110
- type: "int256",
111
- description: "Net SY to account"
112
- }
113
- ]
114
- },
115
- LIQUIDITY_REMOVED: {
116
- id: 6,
117
- name: "Liquidity Removed",
118
- description: "Liquidity removed in Splice Finance",
119
- type: TRIGGER_TYPE.SUBSCRIPTION,
120
- parameters: [
121
- {
122
- key: "abiParams.caller",
123
- type: "address",
124
- description: "Caller address"
125
- },
126
- {
127
- key: "abiParams.market",
128
- type: "address",
129
- description: "Market address"
130
- },
131
- {
132
- key: "abiParams.receiver",
133
- type: "address",
134
- description: "Receiver address"
135
- },
136
- {
137
- key: "abiParams.netLpToRemove",
138
- type: "uint256",
139
- description: "Net LP to remove"
140
- },
141
- {
142
- key: "abiParams.netPtOut",
143
- type: "uint256",
144
- description: "Net PT out"
145
- },
146
- {
147
- key: "abiParams.netSyOut",
148
- type: "uint256",
149
- description: "Net SY out"
150
- }
151
- ]
152
- },
153
- MARKET_CREATION: {
154
- id: 7,
155
- name: "Market Creation",
156
- description: "Market creation in Splice Finance",
157
- type: TRIGGER_TYPE.SUBSCRIPTION,
158
- parameters: [
159
- {
160
- key: "abiParams.market",
161
- type: "address",
162
- description: "Market address"
163
- },
164
- {
165
- key: "abiParams.PT",
166
- type: "address",
167
- description: "PT address"
168
- },
169
- {
170
- key: "abiParams.scalarRoot",
171
- type: "int256",
172
- description: "Scalar root"
173
- },
174
- {
175
- key: "abiParams.initialAnchor",
176
- type: "int256",
177
- description: "Initial anchor"
178
- },
179
- {
180
- key: "abiParams.lnFeeRateRoot",
181
- type: "uint256",
182
- description: "LN fee rate root"
183
- }
184
- ]
185
- },
186
- INTEREST_RATE_UPDATE: {
187
- id: 9,
188
- name: "Interest Rate Update",
189
- description: "Interest rate update in Splice Finance",
190
- type: TRIGGER_TYPE.SUBSCRIPTION,
191
- parameters: [
192
- {
193
- key: "abiParams.timestamp",
194
- type: "uint256",
195
- description: "Timestamp"
196
- },
197
- {
198
- key: "abiParams.lastLnImpliedRate",
199
- type: "int256",
200
- description: "Last LN implied rate"
201
- },
202
- {
203
- key: "contractAddress",
204
- type: "address",
205
- description: "Contract address to monitor",
206
- enum: [
207
- "0xDE95511418EBD8Bd36294B11C86314DdFA50e212", // wrsETH
208
- "0x34cf9BF641bd5f34197060A3f3478a1f97f78f0a", // ezETH
209
- "0xb950A73Ea0842B0Cd06D0e369aE974799BB346f1", // MODE
210
- "0xbF14932e1A7962C77D0b31be80075936bE1A43D4" // weETH
211
- ]
212
- }
213
- ]
214
- }
215
- }
216
- },
217
- LENDING: {
218
- ASTARIA: {
219
- CHAINS: [CHAINS.MODE],
220
- LEND_RECALLED: {
221
- id: 8,
222
- name: "Lend Recalled",
223
- description: "Lend recalled in Astaria",
224
- type: TRIGGER_TYPE.SUBSCRIPTION,
225
- parameters: [
226
- {
227
- key: "abiParams.loanId",
228
- type: "uint256",
229
- description: "Loan ID"
230
- },
231
- {
232
- key: "abiParams.recaller",
233
- type: "address",
234
- description: "Recaller address"
235
- },
236
- {
237
- key: "abiParams.end",
238
- type: "uint256",
239
- description: "End time"
240
- }
241
- ]
242
- }
243
- }
244
- },
245
- DEXES: {
246
- ODOS: {
247
- CHAINS: [CHAINS.MODE, CHAINS.ETHEREUM],
248
- SWAP: {
249
- id: 4,
250
- name: "Odos Swap",
251
- description: "Swap on Odos",
252
- type: TRIGGER_TYPE.SUBSCRIPTION,
253
- parameters: [
254
- {
255
- key: "chainId",
256
- type: "int",
257
- description: "Chain ID of the ETH blockchain"
258
- },
259
- {
260
- key: "abiParams.sender",
261
- type: "address",
262
- description: "Sender address"
263
- },
264
- {
265
- key: "abiParams.inputAmount",
266
- type: "uint256",
267
- description: "Input amount"
268
- },
269
- {
270
- key: "abiParams.inputToken",
271
- type: "address",
272
- description: "Input token address"
273
- },
274
- {
275
- key: "abiParams.amountOut",
276
- type: "uint256",
277
- description: "Output amount"
278
- },
279
- {
280
- key: "abiParams.outputToken",
281
- type: "address",
282
- description: "Output token address"
283
- },
284
- {
285
- key: "abiParams.exchangeRate",
286
- type: "float",
287
- description: "Exchange rate"
288
- }
289
- ]
290
- }
291
- }
292
- },
293
- SOCIALS: {
294
- MODE_NAME_SERVICE: {
295
- CHAINS: [CHAINS.MODE],
296
- NAME_REGISTERED: {
297
- id: 3,
298
- name: "Name Registered",
299
- description: "Name registered in Mode Name Service",
300
- type: TRIGGER_TYPE.SUBSCRIPTION,
301
- parameters: [
302
- {
303
- key: "abiParams.id",
304
- type: "uint256",
305
- description: "ID of the name registered"
306
- },
307
- {
308
- key: "abiParams.owner",
309
- type: "address",
310
- description: "Owner address"
311
- },
312
- {
313
- key: "abiParams.expires",
314
- type: "uint256",
315
- description: "Expiration time"
316
- }
317
- ]
318
- }
319
- }
320
- }
321
- };
@@ -1,44 +0,0 @@
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 { apiServices } from '../services/ApiService.js';
11
- export class Automation {
12
- constructor(name, nodes = [], edges = []) {
13
- this.name = name;
14
- this.nodes = nodes;
15
- this.edges = edges;
16
- }
17
- setName(name) {
18
- this.name = name;
19
- }
20
- addNode(node) {
21
- this.nodes.push(node);
22
- }
23
- addNodes(nodes) {
24
- this.nodes.push(...nodes);
25
- }
26
- addEdge(edge) {
27
- this.edges.push(edge);
28
- }
29
- addEdges(edges) {
30
- this.edges.push(...edges);
31
- }
32
- toJSON() {
33
- return {
34
- name: this.name,
35
- nodes: this.nodes.map(node => node.toJSON()),
36
- edges: this.edges.map(edge => edge.toJSON()),
37
- };
38
- }
39
- save() {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return apiServices.post('/workflows', this.toJSON());
42
- });
43
- }
44
- }
@@ -1,177 +0,0 @@
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
- // getUserProtocolBalances.ts
11
- import { ethers } from 'ethers';
12
- import { rpcServices } from '../../services/RpcServices';
13
- // -------------- PROTOCOLS ENUM --------------
14
- export const PROTOCOLS = {
15
- AAVE: 'AAVE',
16
- COMPOUND: 'COMPOUND',
17
- IONIC: 'IONIC',
18
- MOONWELL: 'MOONWELL',
19
- WALLET: 'WALLET',
20
- };
21
- // Minimal ABIs
22
- const ERC20_ABI = [
23
- 'function balanceOf(address) view returns (uint256)',
24
- 'function decimals() view returns (uint8)',
25
- 'function symbol() view returns (string)',
26
- ];
27
- const COMPOUNDV2_EXCHANGERATE_ABI = [
28
- 'function exchangeRateCurrent() view returns (uint)',
29
- ];
30
- // -------------- ACTUAL MAP --------------
31
- const chainTokenProtocolMap = {
32
- 8453: {
33
- // USDC on Base
34
- '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': [
35
- { protocol: PROTOCOLS.AAVE, token: '0x4e65fE4DbA92790696d040ac24Aa414708F5c0AB' },
36
- { protocol: PROTOCOLS.COMPOUND, token: '0xb125E6687d4313864e53df431d5425969c15Eb2F' },
37
- { protocol: PROTOCOLS.IONIC, token: '0xa900A17a49Bc4D442bA7F72c39FA2108865671f0' },
38
- { protocol: PROTOCOLS.MOONWELL, token: '0xEdc817A28E8B93B03976FBd4a3dDBc9f7D176c22' },
39
- { protocol: PROTOCOLS.WALLET, token: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913' },
40
- ],
41
- // WETH on Base
42
- '0x4200000000000000000000000000000000000006': [
43
- { protocol: PROTOCOLS.AAVE, token: '0xd4a0e0b9149BCee3C920d2E00b5dE09138fd8bb7' },
44
- { protocol: PROTOCOLS.COMPOUND, token: '0x46e6b214b524310239732D51387075E0e70970bf' },
45
- { protocol: PROTOCOLS.IONIC, token: '0x49420311B518f3d0c94e897592014de53831cfA3' },
46
- { protocol: PROTOCOLS.MOONWELL, token: '0x628ff693426583D9a7FB391E54366292F509D457' },
47
- { protocol: PROTOCOLS.WALLET, token: '0x4200000000000000000000000000000000000006' },
48
- ],
49
- },
50
- 34443: {
51
- // USDC on Mode
52
- '0xd988097fb8612cc24eeC14542bC03424c656005f': [
53
- { protocol: PROTOCOLS.IONIC, token: '0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038' },
54
- { protocol: PROTOCOLS.WALLET, token: '0xd988097fb8612cc24eeC14542bC03424c656005f' },
55
- ],
56
- // WETH on Mode
57
- '0x4200000000000000000000000000000000000006': [
58
- { protocol: PROTOCOLS.IONIC, token: '0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2' },
59
- { protocol: PROTOCOLS.WALLET, token: '0x4200000000000000000000000000000000000006' },
60
- ],
61
- },
62
- };
63
- // -------------- EXACT getBalanceInUnderlying LOGIC --------------
64
- function executeReadContract(address, abi, method, params, provider) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const contract = new ethers.Contract(address, abi, provider);
67
- return contract[method](...params);
68
- });
69
- }
70
- /**
71
- * The function that does your protocol-specific "wrapper => underlying" logic
72
- * using BigInt(10) instead of 10n for older TS targets.
73
- */
74
- function getBalanceInUnderlying(protocol, chainId, smartAccountAddress, contractAddress, balanceObj, decimals, provider) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- switch (protocol) {
77
- case PROTOCOLS.WALLET:
78
- return balanceObj.displayValue;
79
- case PROTOCOLS.AAVE:
80
- return balanceObj.displayValue;
81
- case PROTOCOLS.COMPOUND: {
82
- return balanceObj.displayValue;
83
- }
84
- case PROTOCOLS.IONIC:
85
- case PROTOCOLS.MOONWELL: {
86
- // read exchangeRateCurrent
87
- const rawExRate = yield executeReadContract(contractAddress, COMPOUNDV2_EXCHANGERATE_ABI, 'exchangeRateCurrent', [], provider);
88
- const exRateBN = BigInt(rawExRate.toString());
89
- // For IONIC => scale = 18 - decimals + 6
90
- // For MOONWELL => you used scale=18. Let's handle them with logic or keep it simple
91
- let scale = 18 - decimals + 6;
92
- // If MOONWELL, you said "scale=18" in your snippet
93
- if (protocol === PROTOCOLS.MOONWELL) {
94
- scale = 18;
95
- }
96
- // Fix: BigInt(10) instead of 10n
97
- const TEN = BigInt(10);
98
- const divisor = TEN ** BigInt(scale);
99
- const rawBalanceInAssetBN = (balanceObj.value * exRateBN) / divisor;
100
- const balanceInAssetString = ethers.formatUnits(rawBalanceInAssetBN, decimals);
101
- return balanceInAssetString;
102
- }
103
- default:
104
- return balanceObj.displayValue;
105
- }
106
- });
107
- }
108
- // -------------- MAIN FUNCTION --------------
109
- export function getUserProtocolBalances(params) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const { chainId, address, contractAddress } = params;
112
- const chainMap = chainTokenProtocolMap[chainId];
113
- if (!chainMap || chainId === undefined) {
114
- throw new Error(`No token map for chainId=${chainId}`);
115
- }
116
- // If recognized => read all wrappers
117
- const protocolWrappers = chainMap[contractAddress.toLowerCase()];
118
- let addressesToCheck;
119
- if (protocolWrappers) {
120
- addressesToCheck = protocolWrappers;
121
- }
122
- else {
123
- // fallback => just WALLET
124
- addressesToCheck = [
125
- {
126
- protocol: PROTOCOLS.WALLET,
127
- token: contractAddress,
128
- },
129
- ];
130
- }
131
- // Setup provider from rpcServices
132
- const rpcUrl = rpcServices.getRPC(chainId);
133
- const provider = new ethers.JsonRpcProvider(rpcUrl);
134
- // Minimal read ABI
135
- const readABI = [
136
- 'function balanceOf(address) view returns (uint256)',
137
- 'function decimals() view returns (uint8)',
138
- 'function symbol() view returns (string)',
139
- ];
140
- const results = [];
141
- for (const { protocol, token } of addressesToCheck) {
142
- const contract = new ethers.Contract(token, readABI, provider);
143
- const [rawBalanceBN, decimals, symbol] = yield Promise.all([
144
- contract.balanceOf(address),
145
- contract.decimals(),
146
- contract.symbol(),
147
- ]);
148
- const rawBalance = BigInt(rawBalanceBN.toString());
149
- const displayValue = ethers.formatUnits(rawBalance, decimals);
150
- // We'll guess the underlying decimals from the symbol or fallback
151
- // In your snippet, you explicitly used the WALLET decimals for USDC => 6
152
- let underlyingDecimals = decimals;
153
- if (symbol.toLowerCase().includes('usdc')) {
154
- underlyingDecimals = 6;
155
- }
156
- else if (symbol.toLowerCase().includes('weth') || symbol.toLowerCase().includes('eth')) {
157
- underlyingDecimals = 18;
158
- }
159
- // Build the "balanceObj"
160
- const balanceObj = {
161
- value: rawBalance,
162
- decimals,
163
- symbol,
164
- displayValue,
165
- };
166
- // Now do your conversion
167
- const underlyingBalance = yield getBalanceInUnderlying(protocol, chainId, address, token, balanceObj, underlyingDecimals, provider);
168
- results.push({
169
- protocol,
170
- wrapperTokenAddress: token,
171
- wrapperBalance: displayValue, // raw wrapper token balance
172
- underlyingBalance, // computed by getBalanceInUnderlying
173
- });
174
- }
175
- return results;
176
- });
177
- }
@@ -1,95 +0,0 @@
1
- // getBalanceInUnderlying.ts
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- import { ethers } from 'ethers';
12
- // The protocol enumeration you already use
13
- export const PROTOCOLS = {
14
- AAVE: 'AAVE',
15
- COMPOUND: 'COMPOUND',
16
- IONIC: 'IONIC',
17
- MOONWELL: 'MOONWELL',
18
- WALLET: 'WALLET',
19
- };
20
- // Reuse your COMPOUNDV2_EXCHANGERATE_ABI if needed
21
- // (exchangeRateCurrent is read-only in your snippet)
22
- export const COMPOUNDV2_EXCHANGERATE_ABI = [
23
- 'function exchangeRateCurrent() view returns (uint)',
24
- ];
25
- /**
26
- * A minimal "executeReadContract" helper, exactly like in your code snippet.
27
- * You can import this from wherever you defined it.
28
- */
29
- export function executeReadContract(address_1, abi_1, method_1) {
30
- return __awaiter(this, arguments, void 0, function* (address, abi, method, params = [], provider) {
31
- const contract = new ethers.Contract(address, abi, provider);
32
- return contract[method](...params);
33
- });
34
- }
35
- /**
36
- * getBalanceInUnderlying:
37
- * Keeps the exact logic you provided for each protocol.
38
- *
39
- * @param protocol - which protocol (WALLET, AAVE, COMPOUND, IONIC, MOONWELL)
40
- * @param chainId - the chain you’re on (not actively used in this snippet, but kept for consistency)
41
- * @param smartAccountAddress - the user’s address (passed, but your snippet only uses it for logs or COMPOUND custom calls if you expand logic)
42
- * @param contractAddress - the “wrapper token” contract to read from
43
- * @param balanceObj - the result from getBalanceObject (raw BigInt, decimals, displayValue, etc.)
44
- * @param decimals - typically the “underlying decimals” you want to interpret. (In your code, you used the WALLET entry’s decimals for USDC.)
45
- * @param provider - a JsonRpcProvider for read calls (required if you do exchangeRateCurrent).
46
- *
47
- * @returns a string representing the final “underlying” balance
48
- */
49
- export function getBalanceInUnderlying(protocol, chainId, smartAccountAddress, contractAddress, balanceObj, decimals, provider) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- switch (protocol) {
52
- // WALLET => actual USDC, 1:1 => if rawBalance = 1, then underlying = 1
53
- case PROTOCOLS.WALLET: {
54
- return balanceObj.displayValue;
55
- }
56
- // AAVE => often pegged 1:1 for typical aTokens => 1 => 1
57
- case PROTOCOLS.AAVE: {
58
- return balanceObj.displayValue;
59
- }
60
- // COMPOUND => your snippet simply logs the balanceObj and returns displayValue
61
- // (If you wanted a real conversion, you could do “collateralBalanceOf” logic here)
62
- case PROTOCOLS.COMPOUND: {
63
- return balanceObj.displayValue;
64
- }
65
- // IONIC => calls “exchangeRateCurrent”, then does BigInt math
66
- case PROTOCOLS.IONIC: {
67
- const rawExRate = yield executeReadContract(contractAddress, COMPOUNDV2_EXCHANGERATE_ABI, 'exchangeRateCurrent', [], provider);
68
- const exRateBN = BigInt(rawExRate.toString());
69
- // “Suppose we do scale = 18 - decimals + 6 (typical for cTokens w/ USDC underlying).”
70
- // In your snippet, “decimals” is from the WALLET token (if that’s USDC => 6).
71
- const scale = 18 - decimals + 6;
72
- const divisor = BigInt(10) ** BigInt(scale);
73
- // cTokenBalance * exchangeRate / divisor => underlying
74
- const rawBalanceInAssetBN = (balanceObj.value * exRateBN) / divisor;
75
- const balanceInAssetString = ethers.formatUnits(rawBalanceInAssetBN, decimals);
76
- return balanceInAssetString;
77
- }
78
- // MOONWELL => same logic, but you used a fixed scale=18
79
- case PROTOCOLS.MOONWELL: {
80
- const rawExRate = yield executeReadContract(contractAddress, COMPOUNDV2_EXCHANGERATE_ABI, 'exchangeRateCurrent', [], provider);
81
- const exRateBN = BigInt(rawExRate.toString());
82
- // “ALL the moonwell tokens have 8 decimals,” so you did scale=18
83
- const scale = 18;
84
- const divisor = BigInt(10) ** BigInt(scale);
85
- const rawBalanceInAssetBN = (balanceObj.value * exRateBN) / divisor;
86
- const balanceInAssetString = ethers.formatUnits(rawBalanceInAssetBN, decimals);
87
- return balanceInAssetString;
88
- }
89
- default: {
90
- // If not recognized, just return the wrapper’s displayValue
91
- return balanceObj.displayValue;
92
- }
93
- }
94
- });
95
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};