@rhinestone/sdk 1.0.0-alpha.2 → 1.0.0-alpha.21

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 (136) hide show
  1. package/dist/src/accounts/custom.d.ts +18 -0
  2. package/dist/src/accounts/custom.d.ts.map +1 -0
  3. package/dist/src/accounts/custom.js +121 -0
  4. package/dist/src/accounts/custom.test.d.ts +2 -0
  5. package/dist/src/accounts/custom.test.d.ts.map +1 -0
  6. package/dist/src/accounts/custom.test.js +64 -0
  7. package/dist/src/accounts/error.d.ts.map +1 -1
  8. package/dist/src/accounts/error.js +2 -0
  9. package/dist/src/accounts/index.d.ts +22 -13
  10. package/dist/src/accounts/index.d.ts.map +1 -1
  11. package/dist/src/accounts/index.js +192 -186
  12. package/dist/src/accounts/index.test.js +3 -3
  13. package/dist/src/accounts/json-rpc/index.d.ts +5 -0
  14. package/dist/src/accounts/json-rpc/index.d.ts.map +1 -0
  15. package/dist/src/accounts/json-rpc/index.js +16 -0
  16. package/dist/src/accounts/json-rpc/index.test.d.ts +2 -0
  17. package/dist/src/accounts/json-rpc/index.test.d.ts.map +1 -0
  18. package/dist/src/accounts/json-rpc/index.test.js +16 -0
  19. package/dist/src/accounts/json-rpc/providers.d.ts +4 -0
  20. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -0
  21. package/dist/src/accounts/json-rpc/providers.js +14 -0
  22. package/dist/src/accounts/json-rpc/providers.test.d.ts +2 -0
  23. package/dist/src/accounts/json-rpc/providers.test.d.ts.map +1 -0
  24. package/dist/src/accounts/json-rpc/providers.test.js +15 -0
  25. package/dist/src/accounts/kernel.d.ts +9 -10
  26. package/dist/src/accounts/kernel.d.ts.map +1 -1
  27. package/dist/src/accounts/kernel.js +3 -14
  28. package/dist/src/accounts/kernel.test.js +10 -15
  29. package/dist/src/accounts/nexus.d.ts +14 -13
  30. package/dist/src/accounts/nexus.d.ts.map +1 -1
  31. package/dist/src/accounts/nexus.js +121 -93
  32. package/dist/src/accounts/nexus.test.js +13 -14
  33. package/dist/src/accounts/safe.d.ts +5 -7
  34. package/dist/src/accounts/safe.d.ts.map +1 -1
  35. package/dist/src/accounts/safe.js +25 -35
  36. package/dist/src/accounts/safe.test.js +9 -10
  37. package/dist/src/accounts/signing/common.d.ts +27 -0
  38. package/dist/src/accounts/signing/common.d.ts.map +1 -0
  39. package/dist/src/accounts/signing/common.js +142 -0
  40. package/dist/src/accounts/signing/message.d.ts +5 -0
  41. package/dist/src/accounts/signing/message.d.ts.map +1 -0
  42. package/dist/src/accounts/signing/message.js +47 -0
  43. package/dist/src/accounts/signing/passkeys.d.ts +29 -0
  44. package/dist/src/accounts/signing/passkeys.d.ts.map +1 -0
  45. package/dist/src/accounts/signing/passkeys.js +90 -0
  46. package/dist/src/accounts/signing/passkeys.test.d.ts +2 -0
  47. package/dist/src/accounts/signing/passkeys.test.d.ts.map +1 -0
  48. package/dist/src/accounts/signing/passkeys.test.js +73 -0
  49. package/dist/src/accounts/signing/typedData.d.ts +5 -0
  50. package/dist/src/accounts/signing/typedData.d.ts.map +1 -0
  51. package/dist/src/accounts/signing/typedData.js +35 -0
  52. package/dist/src/accounts/startale.d.ts +20 -0
  53. package/dist/src/accounts/startale.d.ts.map +1 -0
  54. package/dist/src/accounts/startale.js +100 -0
  55. package/dist/src/accounts/startale.test.d.ts +2 -0
  56. package/dist/src/accounts/startale.test.d.ts.map +1 -0
  57. package/dist/src/accounts/startale.test.js +96 -0
  58. package/dist/src/accounts/utils.d.ts +2 -1
  59. package/dist/src/accounts/utils.d.ts.map +1 -1
  60. package/dist/src/accounts/utils.js +7 -0
  61. package/dist/src/actions/index.d.ts +145 -7
  62. package/dist/src/actions/index.d.ts.map +1 -1
  63. package/dist/src/actions/index.js +373 -23
  64. package/dist/src/actions/index.test.js +35 -17
  65. package/dist/src/actions/smart-session.d.ts +8 -2
  66. package/dist/src/actions/smart-session.d.ts.map +1 -1
  67. package/dist/src/actions/smart-session.js +6 -0
  68. package/dist/src/execution/compact.d.ts +130 -3
  69. package/dist/src/execution/compact.d.ts.map +1 -1
  70. package/dist/src/execution/compact.js +94 -1
  71. package/dist/src/execution/error.d.ts +2 -9
  72. package/dist/src/execution/error.d.ts.map +1 -1
  73. package/dist/src/execution/error.js +4 -13
  74. package/dist/src/execution/index.d.ts +3 -4
  75. package/dist/src/execution/index.d.ts.map +1 -1
  76. package/dist/src/execution/index.js +35 -80
  77. package/dist/src/execution/smart-session.d.ts +1 -1
  78. package/dist/src/execution/smart-session.d.ts.map +1 -1
  79. package/dist/src/execution/smart-session.js +12 -17
  80. package/dist/src/execution/utils.d.ts +19 -14
  81. package/dist/src/execution/utils.d.ts.map +1 -1
  82. package/dist/src/execution/utils.js +222 -97
  83. package/dist/src/index.d.ts +17 -15
  84. package/dist/src/index.d.ts.map +1 -1
  85. package/dist/src/index.js +108 -21
  86. package/dist/src/modules/index.d.ts +3 -22
  87. package/dist/src/modules/index.d.ts.map +1 -1
  88. package/dist/src/modules/index.js +5 -65
  89. package/dist/src/modules/index.test.js +3 -17
  90. package/dist/src/modules/omni-account.d.ts +2 -4
  91. package/dist/src/modules/omni-account.d.ts.map +1 -1
  92. package/dist/src/modules/omni-account.js +4 -8
  93. package/dist/src/modules/read.d.ts +5 -6
  94. package/dist/src/modules/read.d.ts.map +1 -1
  95. package/dist/src/modules/read.js +7 -37
  96. package/dist/src/modules/validators/core.d.ts +8 -8
  97. package/dist/src/modules/validators/core.d.ts.map +1 -1
  98. package/dist/src/modules/validators/core.js +126 -42
  99. package/dist/src/modules/validators/core.test.js +7 -7
  100. package/dist/src/modules/validators/smart-sessions.d.ts +3 -3
  101. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
  102. package/dist/src/modules/validators/smart-sessions.js +10 -9
  103. package/dist/src/modules/validators/smart-sessions.test.js +4 -4
  104. package/dist/src/orchestrator/client.d.ts +5 -3
  105. package/dist/src/orchestrator/client.d.ts.map +1 -1
  106. package/dist/src/orchestrator/client.js +159 -95
  107. package/dist/src/orchestrator/consts.d.ts +3 -2
  108. package/dist/src/orchestrator/consts.d.ts.map +1 -1
  109. package/dist/src/orchestrator/consts.js +4 -2
  110. package/dist/src/orchestrator/index.d.ts +3 -4
  111. package/dist/src/orchestrator/index.d.ts.map +1 -1
  112. package/dist/src/orchestrator/index.js +1 -9
  113. package/dist/src/orchestrator/registry.d.ts +10 -13
  114. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  115. package/dist/src/orchestrator/registry.js +75 -395
  116. package/dist/src/orchestrator/registry.test.d.ts.map +1 -0
  117. package/dist/src/orchestrator/registry.test.js +137 -0
  118. package/dist/src/orchestrator/types.d.ts +78 -16
  119. package/dist/src/orchestrator/types.d.ts.map +1 -1
  120. package/dist/src/orchestrator/utils.d.ts +1 -3
  121. package/dist/src/orchestrator/utils.d.ts.map +1 -1
  122. package/dist/src/orchestrator/utils.js +0 -102
  123. package/dist/src/types.d.ts +69 -26
  124. package/dist/src/types.d.ts.map +1 -1
  125. package/dist/test/consts.d.ts +2 -2
  126. package/dist/test/consts.d.ts.map +1 -1
  127. package/package.json +2 -1
  128. package/dist/src/actions/registry.d.ts +0 -7
  129. package/dist/src/actions/registry.d.ts.map +0 -1
  130. package/dist/src/actions/registry.js +0 -7
  131. package/dist/src/actions/registry.test.d.ts.map +0 -1
  132. package/dist/src/actions/registry.test.js +0 -25
  133. package/dist/src/modules/registry.d.ts +0 -13
  134. package/dist/src/modules/registry.d.ts.map +0 -1
  135. package/dist/src/modules/registry.js +0 -67
  136. /package/dist/src/{actions → orchestrator}/registry.test.d.ts +0 -0
@@ -2,443 +2,123 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTokenSymbol = getTokenSymbol;
4
4
  exports.getTokenAddress = getTokenAddress;
5
- exports.getTokenRootBalanceSlot = getTokenRootBalanceSlot;
6
- exports.getTokenBalanceSlot = getTokenBalanceSlot;
7
5
  exports.getWethAddress = getWethAddress;
8
- exports.getHookAddress = getHookAddress;
9
- exports.getSameChainModuleAddress = getSameChainModuleAddress;
10
- exports.getTargetModuleAddress = getTargetModuleAddress;
11
- exports.getRhinestoneSpokePoolAddress = getRhinestoneSpokePoolAddress;
12
6
  exports.getChainById = getChainById;
13
7
  exports.getSupportedTokens = getSupportedTokens;
8
+ exports.getSupportedChainIds = getSupportedChainIds;
14
9
  exports.isTestnet = isTestnet;
15
10
  exports.isTokenAddressSupported = isTokenAddressSupported;
16
11
  exports.getDefaultAccountAccessList = getDefaultAccountAccessList;
12
+ exports.resolveTokenAddress = resolveTokenAddress;
13
+ const shared_configs_1 = require("@rhinestone/shared-configs");
17
14
  const viem_1 = require("viem");
18
15
  const chains_1 = require("viem/chains");
19
- function getWethAddress(chain) {
20
- switch (chain.id) {
21
- case chains_1.mainnet.id: {
22
- return '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
23
- }
24
- case chains_1.sepolia.id: {
25
- return '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14';
26
- }
27
- case chains_1.base.id: {
28
- return '0x4200000000000000000000000000000000000006';
29
- }
30
- case chains_1.baseSepolia.id: {
31
- return '0x4200000000000000000000000000000000000006';
32
- }
33
- case chains_1.arbitrum.id: {
34
- return '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1';
35
- }
36
- case chains_1.arbitrumSepolia.id: {
37
- return '0x980B62Da83eFf3D4576C647993b0c1D7faf17c73';
38
- }
39
- case chains_1.optimism.id: {
40
- return '0x4200000000000000000000000000000000000006';
41
- }
42
- case chains_1.optimismSepolia.id: {
43
- return '0x4200000000000000000000000000000000000006';
44
- }
45
- case chains_1.polygon.id: {
46
- return '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619';
47
- }
48
- case chains_1.polygonAmoy.id: {
49
- return '0x52eF3d68BaB452a294342DC3e5f464d7f610f72E';
50
- }
51
- case chains_1.zksync.id: {
52
- return '0x5aea5775959fbc2557cc8789bc1bf90a239d9a91';
53
- }
54
- default: {
55
- throw new Error(`Unsupported chain ${chain.id}`);
56
- }
57
- }
16
+ function getSupportedChainIds() {
17
+ return shared_configs_1.chains.map((chain) => chain.id);
58
18
  }
59
- function getUsdcAddress(chain) {
60
- switch (chain.id) {
61
- case chains_1.mainnet.id: {
62
- return '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
63
- }
64
- case chains_1.sepolia.id: {
65
- return '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238';
66
- }
67
- case chains_1.base.id: {
68
- return '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
69
- }
70
- case chains_1.baseSepolia.id: {
71
- return '0x036CbD53842c5426634e7929541eC2318f3dCF7e';
72
- }
73
- case chains_1.arbitrum.id: {
74
- return '0xaf88d065e77c8cC2239327C5EDb3A432268e5831';
75
- }
76
- case chains_1.arbitrumSepolia.id: {
77
- return '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d';
78
- }
79
- case chains_1.optimism.id: {
80
- return '0x0b2c639c533813f4aa9d7837caf62653d097ff85';
81
- }
82
- case chains_1.optimismSepolia.id: {
83
- return '0x5fd84259d66Cd46123540766Be93DFE6D43130D7';
84
- }
85
- case chains_1.polygon.id: {
86
- return '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359';
87
- }
88
- case chains_1.polygonAmoy.id: {
89
- return '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582';
90
- }
91
- case chains_1.zksync.id: {
92
- return '0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4';
93
- }
94
- default: {
95
- throw new Error(`Unsupported chain ${chain.id}`);
96
- }
97
- }
98
- }
99
- function getUsdtAddress(chain) {
100
- switch (chain.id) {
101
- case chains_1.mainnet.id: {
102
- return '0xdAC17F958D2ee523a2206206994597C13D831ec7';
103
- }
104
- case chains_1.base.id: {
105
- return '0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2';
106
- }
107
- case chains_1.arbitrum.id: {
108
- return '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9';
109
- }
110
- case chains_1.optimism.id: {
111
- return '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58';
112
- }
113
- case chains_1.polygon.id: {
114
- return '0xc2132D05D31c914a87C6611C10748AEb04B58e8F';
115
- }
116
- case chains_1.zksync.id: {
117
- return '0x493257fD37EDB34451f62EDf8D2a0C418852bA4C';
118
- }
119
- default: {
120
- throw new Error(`Unsupported chain ${chain.id}`);
121
- }
122
- }
19
+ function getChainEntry(chainId) {
20
+ return shared_configs_1.chainRegistry[chainId.toString()];
123
21
  }
124
- function getTokenRootBalanceSlot(chain, tokenAddress) {
125
- switch (chain.id) {
126
- case chains_1.mainnet.id: {
127
- // ETH
128
- if (tokenAddress === viem_1.zeroAddress) {
129
- return null;
130
- }
131
- // USDC
132
- if (tokenAddress === '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48') {
133
- return 9n;
134
- }
135
- // WETH
136
- if (tokenAddress === '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2') {
137
- return 3n;
138
- }
139
- // USDT
140
- if (tokenAddress === '0xdAC17F958D2ee523a2206206994597C13D831ec7') {
141
- return 2n;
142
- }
143
- break;
144
- }
145
- case chains_1.sepolia.id: {
146
- // ETH
147
- if (tokenAddress === viem_1.zeroAddress) {
148
- return null;
149
- }
150
- // USDC
151
- if (tokenAddress === '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238') {
152
- return 9n;
153
- }
154
- // WETH
155
- if (tokenAddress === '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14') {
156
- return 3n;
157
- }
158
- break;
159
- }
160
- case chains_1.base.id: {
161
- // ETH
162
- if (tokenAddress === viem_1.zeroAddress) {
163
- return null;
164
- }
165
- // USDC
166
- if (tokenAddress === '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913') {
167
- return 9n;
168
- }
169
- // WETH
170
- if (tokenAddress === '0x4200000000000000000000000000000000000006') {
171
- return 3n;
172
- }
173
- // USDT
174
- if (tokenAddress === '0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2') {
175
- return 51n;
176
- }
177
- break;
178
- }
179
- case chains_1.baseSepolia.id: {
180
- // ETH
181
- if (tokenAddress === viem_1.zeroAddress) {
182
- return null;
183
- }
184
- // USDC
185
- if (tokenAddress === '0x036CbD53842c5426634e7929541eC2318f3dCF7e') {
186
- return 9n;
187
- }
188
- // WETH
189
- if (tokenAddress === '0x4200000000000000000000000000000000000006') {
190
- return 3n;
191
- }
192
- break;
193
- }
194
- case chains_1.arbitrum.id: {
195
- // ETH
196
- if (tokenAddress === viem_1.zeroAddress) {
197
- return null;
198
- }
199
- // USDC
200
- if (tokenAddress === '0xaf88d065e77c8cC2239327C5EDb3A432268e5831') {
201
- return 9n;
202
- }
203
- // WETH
204
- if (tokenAddress === '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1') {
205
- return 51n;
206
- }
207
- // USDT
208
- if (tokenAddress === '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9') {
209
- return 51n;
210
- }
211
- break;
212
- }
213
- case chains_1.arbitrumSepolia.id: {
214
- // ETH
215
- if (tokenAddress === viem_1.zeroAddress) {
216
- return null;
217
- }
218
- // USDC
219
- if (tokenAddress === '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d') {
220
- return 9n;
221
- }
222
- // WETH
223
- if (tokenAddress === '0x980B62Da83eFf3D4576C647993b0c1D7faf17c73') {
224
- return 51n;
225
- }
226
- break;
227
- }
228
- case chains_1.optimism.id: {
229
- // ETH
230
- if (tokenAddress === viem_1.zeroAddress) {
231
- return null;
232
- }
233
- // USDC
234
- if (tokenAddress === '0x0b2c639c533813f4aa9d7837caf62653d097ff85') {
235
- return 9n;
236
- }
237
- // WETH
238
- if (tokenAddress === '0x4200000000000000000000000000000000000006') {
239
- return 3n;
240
- }
241
- // USDT
242
- if (tokenAddress === '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58') {
243
- return 0n;
244
- }
245
- break;
246
- }
247
- case chains_1.optimismSepolia.id: {
248
- // ETH
249
- if (tokenAddress === viem_1.zeroAddress) {
250
- return null;
251
- }
252
- // USDC
253
- if (tokenAddress === '0x5fd84259d66Cd46123540766Be93DFE6D43130D7') {
254
- return 9n;
255
- }
256
- // WETH
257
- if (tokenAddress === '0x4200000000000000000000000000000000000006') {
258
- return 3n;
259
- }
260
- break;
261
- }
262
- case chains_1.polygon.id: {
263
- // USDC
264
- if (tokenAddress === '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359') {
265
- return 9n;
266
- }
267
- // WETH
268
- if (tokenAddress === '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619') {
269
- return 3n;
270
- }
271
- // USDT
272
- if (tokenAddress === '0xc2132D05D31c914a87C6611C10748AEb04B58e8F') {
273
- return 0n;
274
- }
275
- break;
276
- }
277
- case chains_1.polygonAmoy.id: {
278
- // USDC
279
- if (tokenAddress === '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582') {
280
- return 9n;
281
- }
282
- // WETH
283
- if (tokenAddress === '0x52eF3d68BaB452a294342DC3e5f464d7f610f72E') {
284
- return 3n;
285
- }
286
- break;
287
- }
288
- case chains_1.zksync.id: {
289
- // ETH
290
- if (tokenAddress === viem_1.zeroAddress) {
291
- return null;
292
- }
293
- // USDC
294
- if (tokenAddress === '0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4') {
295
- return 9n;
296
- }
297
- // WETH
298
- if (tokenAddress === '0x5aea5775959fbc2557cc8789bc1bf90a239d9a91') {
299
- return 3n;
300
- }
301
- // USDT
302
- if (tokenAddress === '0x493257fD37EDB34451f62EDf8D2a0C418852bA4C') {
303
- return 2n;
304
- }
305
- break;
306
- }
22
+ function getWethAddress(chain) {
23
+ const chainEntry = getChainEntry(chain.id);
24
+ if (!chainEntry) {
25
+ throw new Error(`Unsupported chain ${chain.id}`);
307
26
  }
308
- throw new Error(`Unsupported token address ${tokenAddress} for chain ${chain.id}`);
309
- }
310
- function getTokenBalanceSlot(tokenSymbol, chainId, accountAddress) {
311
- const tokenAddress = getTokenAddress(tokenSymbol, chainId);
312
- const chain = getChainById(chainId);
313
- if (!chain) {
314
- throw new Error(`Unsupported chain: ${chainId}`);
27
+ const wethToken = chainEntry.tokens.find((token) => token.symbol === 'WETH');
28
+ if (!wethToken) {
29
+ throw new Error(`WETH not found for chain ${chain.id}`);
315
30
  }
316
- const rootBalanceSlot = getTokenRootBalanceSlot(chain, tokenAddress);
317
- const balanceSlot = rootBalanceSlot
318
- ? (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'address' }, { type: 'uint256' }], [accountAddress, rootBalanceSlot]))
319
- : '0x';
320
- return balanceSlot;
321
- }
322
- function getHookAddress(_chainId) {
323
- return '0x0000000000f6Ed8Be424d673c63eeFF8b9267420';
324
- }
325
- function getSameChainModuleAddress(_chainId) {
326
- return '0x000000000043ff16d5776c7F0f65Ec485C17Ca04';
327
- }
328
- function getTargetModuleAddress(_chainId) {
329
- return '0x0000000000E5a37279A001301A837a91b5de1D5E';
330
- }
331
- function getRhinestoneSpokePoolAddress(_chainId) {
332
- return '0x000000000060f6e853447881951574CDd0663530';
31
+ return wethToken.address;
333
32
  }
334
33
  function getTokenSymbol(tokenAddress, chainId) {
335
- const knownSymbols = getKnownSymbols();
336
- for (const symbol of knownSymbols) {
337
- const address = getTokenAddress(symbol, chainId);
338
- if (address.toLowerCase() === tokenAddress.toLowerCase()) {
339
- return symbol;
340
- }
34
+ const chainEntry = getChainEntry(chainId);
35
+ if (!chainEntry) {
36
+ throw new Error(`Unsupported chain ${chainId}`);
341
37
  }
342
- throw new Error(`Unsupported token address ${tokenAddress} for chain ${chainId}`);
38
+ const token = chainEntry.tokens.find((t) => t.address.toLowerCase() === tokenAddress.toLowerCase());
39
+ if (!token) {
40
+ throw new Error(`Unsupported token address ${tokenAddress} for chain ${chainId}`);
41
+ }
42
+ return token.symbol;
343
43
  }
344
44
  function getTokenAddress(tokenSymbol, chainId) {
345
- if (chainId === 137 && tokenSymbol === 'ETH') {
45
+ if (chainId === chains_1.polygon.id && tokenSymbol === 'ETH') {
346
46
  throw new Error(`Chain ${chainId} does not allow for ETH to be used`);
347
47
  }
48
+ if (chainId === chains_1.sonic.id && tokenSymbol !== 'USDC') {
49
+ throw new Error(`Chain ${chainId} only has USDC available`);
50
+ }
348
51
  if (tokenSymbol === 'ETH') {
349
52
  return viem_1.zeroAddress;
350
53
  }
351
- const chain = getChainById(chainId);
352
- if (!chain) {
54
+ const chainEntry = getChainEntry(chainId);
55
+ if (!chainEntry) {
353
56
  throw new Error(`Unsupported chain ${chainId}`);
354
57
  }
355
- if (tokenSymbol === 'WETH') {
356
- return getWethAddress(chain);
357
- }
358
- if (tokenSymbol === 'USDC') {
359
- return getUsdcAddress(chain);
360
- }
361
- if (tokenSymbol === 'USDT') {
362
- return getUsdtAddress(chain);
58
+ const token = chainEntry.tokens.find((t) => t.symbol === tokenSymbol);
59
+ if (!token) {
60
+ throw new Error(`Unsupported token symbol ${tokenSymbol}`);
363
61
  }
364
- throw new Error(`Unsupported token symbol ${tokenSymbol}`);
62
+ return token.address;
63
+ }
64
+ function isChainIdSupported(chainId) {
65
+ const chainIds = shared_configs_1.chains.map((chain) => chain.id);
66
+ return chainIds.includes(chainId);
365
67
  }
366
68
  function getChainById(chainId) {
367
- const supportedChains = [
368
- chains_1.mainnet,
369
- chains_1.sepolia,
370
- chains_1.base,
371
- chains_1.baseSepolia,
372
- chains_1.arbitrum,
373
- chains_1.arbitrumSepolia,
374
- chains_1.optimism,
375
- chains_1.optimismSepolia,
376
- chains_1.polygon,
377
- chains_1.polygonAmoy,
378
- chains_1.zksync,
379
- ];
380
- for (const chain of supportedChains) {
381
- if (chain.id === chainId) {
382
- return chain;
383
- }
69
+ const chains = {
70
+ [chains_1.mainnet.id]: chains_1.mainnet,
71
+ [chains_1.sepolia.id]: chains_1.sepolia,
72
+ [chains_1.base.id]: chains_1.base,
73
+ [chains_1.baseSepolia.id]: chains_1.baseSepolia,
74
+ [chains_1.arbitrum.id]: chains_1.arbitrum,
75
+ [chains_1.arbitrumSepolia.id]: chains_1.arbitrumSepolia,
76
+ [chains_1.optimism.id]: chains_1.optimism,
77
+ [chains_1.optimismSepolia.id]: chains_1.optimismSepolia,
78
+ [chains_1.polygon.id]: chains_1.polygon,
79
+ [chains_1.soneium.id]: chains_1.soneium,
80
+ [chains_1.sonic.id]: chains_1.sonic,
81
+ };
82
+ if (!isChainIdSupported(chainId)) {
83
+ throw new Error(`Chain not supported: ${chainId}`);
384
84
  }
85
+ return chains[chainId];
385
86
  }
386
87
  function isTestnet(chainId) {
387
88
  const chain = getChainById(chainId);
388
- if (!chain) {
389
- throw new Error(`Chain not supported: ${chainId}`);
390
- }
391
89
  return chain.testnet ?? false;
392
90
  }
393
91
  function isTokenAddressSupported(address, chainId) {
394
- const chain = getChainById(chainId);
395
- if (!chain) {
396
- throw new Error(`Chain not supported: ${chainId}`);
397
- }
398
- try {
399
- getTokenSymbol(address, chainId);
400
- return true;
401
- }
402
- catch {
92
+ const chainEntry = getChainEntry(chainId);
93
+ if (!chainEntry) {
403
94
  return false;
404
95
  }
96
+ return chainEntry.tokens.some((token) => token.address.toLowerCase() === address.toLowerCase());
405
97
  }
406
98
  function getSupportedTokens(chainId) {
407
- const chain = getChainById(chainId);
408
- if (!chain) {
99
+ const chainEntry = getChainEntry(chainId);
100
+ if (!chainEntry) {
409
101
  throw new Error(`Chain not supported: ${chainId}`);
410
102
  }
411
- const knownSymbols = getKnownSymbols();
412
- return knownSymbols.map((symbol) => {
413
- const decimals = getTokenDecimals(symbol);
414
- const address = getTokenAddress(symbol, chainId);
415
- return {
416
- symbol,
417
- address,
418
- decimals,
419
- balanceSlot: (accountAddress) => getTokenBalanceSlot(symbol, chainId, accountAddress),
420
- };
421
- });
422
- }
423
- function getKnownSymbols() {
424
- return ['ETH', 'WETH', 'USDC', 'USDT'];
425
- }
426
- function getTokenDecimals(symbol) {
427
- switch (symbol) {
428
- case 'ETH':
429
- case 'WETH':
430
- return 18;
431
- case 'USDC':
432
- case 'USDT':
433
- return 6;
434
- default:
435
- throw new Error(`Symbol not supported: ${symbol}`);
436
- }
103
+ return chainEntry.tokens;
437
104
  }
438
105
  function getDefaultAccountAccessList(onTestnets) {
106
+ const supportedChainIds = getSupportedChainIds();
107
+ const filteredChainIds = supportedChainIds.filter((chainId) => {
108
+ try {
109
+ return isTestnet(chainId) === !!onTestnets;
110
+ }
111
+ catch {
112
+ return false;
113
+ }
114
+ });
439
115
  return {
440
- chainIds: onTestnets
441
- ? [chains_1.sepolia.id, chains_1.baseSepolia.id, chains_1.arbitrumSepolia.id, chains_1.optimismSepolia.id]
442
- : [chains_1.mainnet.id, chains_1.base.id, chains_1.arbitrum.id, chains_1.optimism.id],
116
+ chainIds: filteredChainIds,
443
117
  };
444
118
  }
119
+ function resolveTokenAddress(token, chainId) {
120
+ if ((0, viem_1.isAddress)(token)) {
121
+ return token;
122
+ }
123
+ return getTokenAddress(token, chainId);
124
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.test.d.ts","sourceRoot":"","sources":["../../../orchestrator/registry.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const viem_1 = require("viem");
4
+ const chains_1 = require("viem/chains");
5
+ const vitest_1 = require("vitest");
6
+ const registry_1 = require("./registry");
7
+ const DEPRECATED_CHAIN_ID = 5; // Goerli
8
+ const UNSUPPORTED_CHAIN_ID = 56; // BNB Chain
9
+ const TOKEN_SYMBOLS = {
10
+ ETH: 'ETH',
11
+ USDC: 'USDC',
12
+ USDT: 'USDT',
13
+ WETH: 'WETH',
14
+ };
15
+ const TOKEN_ADDRESSES = {
16
+ ETHEREUM_USDC: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
17
+ BASE_WETH: '0x4200000000000000000000000000000000000006',
18
+ };
19
+ const UNSUPPORTED_TOKEN_ADDRESS = '0x1234567890123456789012345678901234567890';
20
+ (0, vitest_1.describe)('Registry', () => {
21
+ (0, vitest_1.describe)('getSupportedChainIds', () => {
22
+ (0, vitest_1.test)('returns supported chain IDs', () => {
23
+ const chainIds = (0, registry_1.getSupportedChainIds)();
24
+ (0, vitest_1.expect)(chainIds).toContain(chains_1.mainnet.id);
25
+ (0, vitest_1.expect)(chainIds).toContain(chains_1.base.id);
26
+ (0, vitest_1.expect)(chainIds).toContain(chains_1.sepolia.id);
27
+ });
28
+ (0, vitest_1.test)('does not include unsupported chains', () => {
29
+ const chainIds = (0, registry_1.getSupportedChainIds)();
30
+ (0, vitest_1.expect)(chainIds).not.toContain(DEPRECATED_CHAIN_ID);
31
+ (0, vitest_1.expect)(chainIds).not.toContain(UNSUPPORTED_CHAIN_ID);
32
+ });
33
+ });
34
+ (0, vitest_1.describe)('getTokenSymbol', () => {
35
+ (0, vitest_1.test)('returns correct symbol for supported token', () => {
36
+ const symbol = (0, registry_1.getTokenSymbol)(TOKEN_ADDRESSES.ETHEREUM_USDC, chains_1.mainnet.id);
37
+ (0, vitest_1.expect)(symbol).toBe(TOKEN_SYMBOLS.USDC);
38
+ });
39
+ (0, vitest_1.test)('throws error for unsupported chain', () => {
40
+ (0, vitest_1.expect)(() => (0, registry_1.getTokenSymbol)(TOKEN_ADDRESSES.ETHEREUM_USDC, UNSUPPORTED_CHAIN_ID)).toThrow(`Unsupported chain ${UNSUPPORTED_CHAIN_ID}`);
41
+ });
42
+ });
43
+ (0, vitest_1.describe)('getTokenAddress', () => {
44
+ (0, vitest_1.test)('returns zero address for ETH', () => {
45
+ const address = (0, registry_1.getTokenAddress)(TOKEN_SYMBOLS.ETH, chains_1.mainnet.id);
46
+ (0, vitest_1.expect)(address).toBe(viem_1.zeroAddress);
47
+ });
48
+ (0, vitest_1.test)('returns correct address for token symbol', () => {
49
+ const address = (0, registry_1.getTokenAddress)(TOKEN_SYMBOLS.USDC, chains_1.mainnet.id);
50
+ (0, vitest_1.expect)(address).toBe(TOKEN_ADDRESSES.ETHEREUM_USDC);
51
+ });
52
+ (0, vitest_1.test)('throws error for unsupported chain', () => {
53
+ (0, vitest_1.expect)(() => (0, registry_1.getTokenAddress)(TOKEN_SYMBOLS.USDC, UNSUPPORTED_CHAIN_ID)).toThrow(`Unsupported chain ${UNSUPPORTED_CHAIN_ID}`);
54
+ });
55
+ });
56
+ (0, vitest_1.describe)('getWethAddress', () => {
57
+ (0, vitest_1.test)('returns correct WETH address', () => {
58
+ const address = (0, registry_1.getWethAddress)(chains_1.base);
59
+ (0, vitest_1.expect)(address).toBe(TOKEN_ADDRESSES.BASE_WETH);
60
+ });
61
+ (0, vitest_1.test)('throws error for unsupported chain', () => {
62
+ const unsupportedChain = {
63
+ id: UNSUPPORTED_CHAIN_ID,
64
+ name: 'Unsupported',
65
+ };
66
+ (0, vitest_1.expect)(() => (0, registry_1.getWethAddress)(unsupportedChain)).toThrow(`Unsupported chain ${UNSUPPORTED_CHAIN_ID}`);
67
+ });
68
+ });
69
+ (0, vitest_1.describe)('getChainById', () => {
70
+ (0, vitest_1.test)('returns correct chain for supported ID', () => {
71
+ const chain = (0, registry_1.getChainById)(chains_1.mainnet.id);
72
+ (0, vitest_1.expect)(chain.id).toBe(chains_1.mainnet.id);
73
+ (0, vitest_1.expect)(chain.name).toBe(chains_1.mainnet.name);
74
+ });
75
+ (0, vitest_1.test)('throws error for unsupported chain', () => {
76
+ (0, vitest_1.expect)(() => (0, registry_1.getChainById)(UNSUPPORTED_CHAIN_ID)).toThrow(`Chain not supported: ${UNSUPPORTED_CHAIN_ID}`);
77
+ });
78
+ });
79
+ (0, vitest_1.describe)('isTestnet', () => {
80
+ (0, vitest_1.test)('returns false for mainnet', () => {
81
+ (0, vitest_1.expect)((0, registry_1.isTestnet)(chains_1.mainnet.id)).toBe(false);
82
+ });
83
+ (0, vitest_1.test)('returns true for testnet', () => {
84
+ (0, vitest_1.expect)((0, registry_1.isTestnet)(chains_1.sepolia.id)).toBe(true);
85
+ });
86
+ (0, vitest_1.test)('throws error for unsupported chain', () => {
87
+ (0, vitest_1.expect)(() => (0, registry_1.isTestnet)(UNSUPPORTED_CHAIN_ID)).toThrow(`Chain not supported: ${UNSUPPORTED_CHAIN_ID}`);
88
+ });
89
+ });
90
+ (0, vitest_1.describe)('isTokenAddressSupported', () => {
91
+ (0, vitest_1.test)('returns true for supported token', () => {
92
+ const isSupported = (0, registry_1.isTokenAddressSupported)(TOKEN_ADDRESSES.ETHEREUM_USDC, chains_1.mainnet.id);
93
+ (0, vitest_1.expect)(isSupported).toBe(true);
94
+ });
95
+ (0, vitest_1.test)('returns false for unsupported token or chain', () => {
96
+ (0, vitest_1.expect)((0, registry_1.isTokenAddressSupported)(UNSUPPORTED_TOKEN_ADDRESS, chains_1.mainnet.id)).toBe(false);
97
+ (0, vitest_1.expect)((0, registry_1.isTokenAddressSupported)(TOKEN_ADDRESSES.ETHEREUM_USDC, UNSUPPORTED_CHAIN_ID)).toBe(false);
98
+ });
99
+ });
100
+ (0, vitest_1.describe)('getSupportedTokens', () => {
101
+ (0, vitest_1.test)('returns tokens for supported chain', () => {
102
+ const tokens = (0, registry_1.getSupportedTokens)(chains_1.mainnet.id);
103
+ (0, vitest_1.expect)(tokens.length).toBeGreaterThan(0);
104
+ (0, vitest_1.expect)(tokens.find((t) => t.symbol === TOKEN_SYMBOLS.USDC)).toBeDefined();
105
+ });
106
+ (0, vitest_1.test)('throws error for unsupported chain', () => {
107
+ (0, vitest_1.expect)(() => (0, registry_1.getSupportedTokens)(UNSUPPORTED_CHAIN_ID)).toThrow(`Chain not supported: ${UNSUPPORTED_CHAIN_ID}`);
108
+ });
109
+ });
110
+ (0, vitest_1.describe)('getDefaultAccountAccessList', () => {
111
+ (0, vitest_1.test)('filters chains by testnet status', () => {
112
+ const mainnetList = (0, registry_1.getDefaultAccountAccessList)(false);
113
+ const testnetList = (0, registry_1.getDefaultAccountAccessList)(true);
114
+ (0, vitest_1.expect)(mainnetList.chainIds).toContain(chains_1.mainnet.id);
115
+ (0, vitest_1.expect)(mainnetList.chainIds).not.toContain(chains_1.sepolia.id);
116
+ (0, vitest_1.expect)(testnetList.chainIds).toContain(chains_1.sepolia.id);
117
+ (0, vitest_1.expect)(testnetList.chainIds).not.toContain(chains_1.mainnet.id);
118
+ });
119
+ });
120
+ (0, vitest_1.describe)('resolveTokenAddress', () => {
121
+ (0, vitest_1.test)('returns address as-is when given valid address', () => {
122
+ const address = TOKEN_ADDRESSES.ETHEREUM_USDC;
123
+ const result = (0, registry_1.resolveTokenAddress)(address, chains_1.mainnet.id);
124
+ (0, vitest_1.expect)(result).toBe(address);
125
+ });
126
+ (0, vitest_1.test)('resolves token symbol to address', () => {
127
+ const result = (0, registry_1.resolveTokenAddress)(TOKEN_SYMBOLS.USDC, chains_1.mainnet.id);
128
+ (0, vitest_1.expect)(result).toBe(TOKEN_ADDRESSES.ETHEREUM_USDC);
129
+ });
130
+ (0, vitest_1.test)('throw error for unsupported token', () => {
131
+ (0, vitest_1.expect)(() => (0, registry_1.resolveTokenAddress)(TOKEN_SYMBOLS.USDT, chains_1.baseSepolia.id)).toThrow(`Unsupported token symbol ${TOKEN_SYMBOLS.USDT}`);
132
+ });
133
+ (0, vitest_1.test)('throws error for unsupported chain', () => {
134
+ (0, vitest_1.expect)(() => (0, registry_1.resolveTokenAddress)(TOKEN_SYMBOLS.USDC, UNSUPPORTED_CHAIN_ID)).toThrow(`Unsupported chain ${UNSUPPORTED_CHAIN_ID}`);
135
+ });
136
+ });
137
+ });