@rhinestone/shared-configs 1.4.71 → 1.4.74

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.
@@ -14,7 +14,8 @@
14
14
  ],
15
15
  "swapQuoters": [
16
16
  "1inch",
17
- "0x"
17
+ "0x",
18
+ "velora"
18
19
  ],
19
20
  "tokens": [
20
21
  {
@@ -69,7 +70,8 @@
69
70
  ],
70
71
  "swapQuoters": [
71
72
  "1inch",
72
- "0x"
73
+ "0x",
74
+ "velora"
73
75
  ],
74
76
  "tokens": [
75
77
  {
@@ -121,7 +123,8 @@
121
123
  "RELAY"
122
124
  ],
123
125
  "swapQuoters": [
124
- "1inch"
126
+ "1inch",
127
+ "velora"
125
128
  ],
126
129
  "tokens": [
127
130
  {
@@ -161,7 +164,8 @@
161
164
  ],
162
165
  "swapQuoters": [
163
166
  "1inch",
164
- "0x"
167
+ "0x",
168
+ "velora"
165
169
  ],
166
170
  "tokens": [
167
171
  {
@@ -207,7 +211,8 @@
207
211
  ],
208
212
  "swapQuoters": [
209
213
  "1inch",
210
- "0x"
214
+ "0x",
215
+ "velora"
211
216
  ],
212
217
  "tokens": [
213
218
  {
@@ -282,7 +287,8 @@
282
287
  ],
283
288
  "swapQuoters": [
284
289
  "1inch",
285
- "0x"
290
+ "0x",
291
+ "velora"
286
292
  ],
287
293
  "tokens": [
288
294
  {
@@ -395,7 +401,8 @@
395
401
  ],
396
402
  "swapQuoters": [
397
403
  "1inch",
398
- "0x"
404
+ "0x",
405
+ "velora"
399
406
  ],
400
407
  "tokens": [
401
408
  {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sync-abis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-abis.d.ts","sourceRoot":"","sources":["../../scripts/sync-abis.ts"],"names":[],"mappings":""}
@@ -0,0 +1,435 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_child_process_1 = require("node:child_process");
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ function parseArgs(argv) {
10
+ const opts = {
11
+ env: "staging",
12
+ strict: false,
13
+ generate: false,
14
+ };
15
+ for (let i = 0; i < argv.length; i += 1) {
16
+ const arg = argv[i];
17
+ if (arg === "--env" && argv[i + 1]) {
18
+ opts.env = argv[i + 1];
19
+ i += 1;
20
+ continue;
21
+ }
22
+ if (arg.startsWith("--env=")) {
23
+ opts.env = arg.split("=")[1] ?? opts.env;
24
+ continue;
25
+ }
26
+ if (arg === "--strict") {
27
+ opts.strict = true;
28
+ continue;
29
+ }
30
+ if (arg === "--generate") {
31
+ opts.generate = true;
32
+ }
33
+ }
34
+ return opts;
35
+ }
36
+ function readJsonFile(filePath) {
37
+ return JSON.parse((0, node_fs_1.readFileSync)(filePath, "utf8"));
38
+ }
39
+ function normalizeRepo(repo) {
40
+ let normalized = repo.trim();
41
+ if (normalized.startsWith("git@github.com:")) {
42
+ normalized = normalized.replace("git@github.com:", "");
43
+ }
44
+ if (normalized.startsWith("https://github.com/")) {
45
+ normalized = normalized.replace("https://github.com/", "");
46
+ }
47
+ if (normalized.endsWith(".git")) {
48
+ normalized = normalized.slice(0, -4);
49
+ }
50
+ return normalized;
51
+ }
52
+ function resolveRef(versionControl, env, repoKey, artifactPath, entry) {
53
+ if (entry.ref) {
54
+ return entry.ref;
55
+ }
56
+ const envConfig = versionControl[env];
57
+ if (!envConfig) {
58
+ throw new Error(`Missing env '${env}' in config/versioncontrol.jsonnet`);
59
+ }
60
+ const artifactKey = `${repoKey}/${artifactPath}`;
61
+ const entryConfig = envConfig[artifactKey] ?? envConfig[repoKey];
62
+ if (!entryConfig) {
63
+ throw new Error(`Missing versioncontrol entry for ${artifactKey} (env=${env})`);
64
+ }
65
+ if (typeof entryConfig === "string") {
66
+ return entryConfig;
67
+ }
68
+ if (entryConfig.ref) {
69
+ return entryConfig.ref;
70
+ }
71
+ throw new Error(`No ref found for ${artifactKey} (env=${env})`);
72
+ }
73
+ function loadVersionControl(yeetRoot) {
74
+ const jsonnetFile = node_path_1.default.join(yeetRoot, "config", "versioncontrol.jsonnet");
75
+ const jsonnetEth = node_path_1.default.join(yeetRoot, "bin", "jsonnet-eth");
76
+ let output = "";
77
+ if ((0, node_fs_1.existsSync)(jsonnetEth)) {
78
+ output = (0, node_child_process_1.execFileSync)(jsonnetEth, [jsonnetFile], {
79
+ cwd: yeetRoot,
80
+ encoding: "utf8",
81
+ });
82
+ }
83
+ else {
84
+ output = (0, node_child_process_1.execFileSync)("go", ["run", "./cmd/jsonnet-eth", jsonnetFile], {
85
+ cwd: yeetRoot,
86
+ encoding: "utf8",
87
+ });
88
+ }
89
+ return JSON.parse(output);
90
+ }
91
+ function fetchArtifactJson(repoKey, ref, artifactPath, fileName) {
92
+ const fullPath = node_path_1.default.posix.join(artifactPath, fileName);
93
+ const ghArgs = [
94
+ "api",
95
+ `repos/${repoKey}/contents/${fullPath}?ref=${ref}`,
96
+ "--jq",
97
+ ".content",
98
+ ];
99
+ const content = (0, node_child_process_1.execFileSync)("gh", ghArgs, { encoding: "utf8" }).trim();
100
+ if (!content) {
101
+ throw new Error(`Empty response for ${repoKey}:${fullPath}@${ref}`);
102
+ }
103
+ const decoded = Buffer.from(content.replace(/\n/g, ""), "base64").toString("utf8");
104
+ return JSON.parse(decoded);
105
+ }
106
+ function fetchRepoFile(repoKey, ref, filePath) {
107
+ const fullPath = node_path_1.default.posix.normalize(filePath);
108
+ const ghArgs = [
109
+ "api",
110
+ `repos/${repoKey}/contents/${fullPath}?ref=${ref}`,
111
+ "--jq",
112
+ ".content",
113
+ ];
114
+ const content = (0, node_child_process_1.execFileSync)("gh", ghArgs, { encoding: "utf8" }).trim();
115
+ if (!content) {
116
+ throw new Error(`Empty response for ${repoKey}:${fullPath}@${ref}`);
117
+ }
118
+ return Buffer.from(content.replace(/\n/g, ""), "base64").toString("utf8");
119
+ }
120
+ function extractAbi(payload) {
121
+ if (Array.isArray(payload)) {
122
+ return payload;
123
+ }
124
+ if (payload && typeof payload === "object" && "abi" in payload) {
125
+ const abi = payload.abi;
126
+ if (Array.isArray(abi)) {
127
+ return abi;
128
+ }
129
+ }
130
+ throw new Error("Unsupported artifact format: expected ABI array or { abi }");
131
+ }
132
+ function filterAbiByFunctions(abi, functions) {
133
+ const allowed = new Set(functions);
134
+ const found = new Set();
135
+ const filtered = abi.filter((item) => {
136
+ if (!item || typeof item !== "object") {
137
+ return false;
138
+ }
139
+ const typed = item;
140
+ if (typed.type !== "function" || !typed.name) {
141
+ return false;
142
+ }
143
+ if (!allowed.has(typed.name)) {
144
+ return false;
145
+ }
146
+ found.add(typed.name);
147
+ return true;
148
+ });
149
+ const missing = functions.filter((name) => !found.has(name));
150
+ if (missing.length > 0) {
151
+ throw new Error(`Missing functions in ABI: ${missing.join(", ")}`);
152
+ }
153
+ return filtered;
154
+ }
155
+ function stripComments(source) {
156
+ const withoutBlock = source.replace(/\/\*[\s\S]*?\*\//g, "");
157
+ return withoutBlock.replace(/\/\/.*$/gm, "");
158
+ }
159
+ function parseStruct(source, structName) {
160
+ const cleaned = stripComments(source);
161
+ const structRegex = new RegExp(`struct\\s+${structName}\\s*\\{([\\s\\S]*?)\\}`);
162
+ const match = cleaned.match(structRegex);
163
+ if (!match) {
164
+ throw new Error(`Struct ${structName} not found`);
165
+ }
166
+ const body = match[1];
167
+ const fields = body
168
+ .split(";")
169
+ .map((line) => line.trim())
170
+ .filter(Boolean);
171
+ const components = [];
172
+ for (const field of fields) {
173
+ const tokens = field.split(/\s+/).filter(Boolean);
174
+ if (tokens.length < 2) {
175
+ continue;
176
+ }
177
+ const name = tokens[tokens.length - 1];
178
+ const type = tokens.slice(0, -1).join(" ");
179
+ components.push({
180
+ name,
181
+ type,
182
+ internalType: type,
183
+ });
184
+ }
185
+ return components;
186
+ }
187
+ function resolveParamType(typeStr, structs) {
188
+ const arrayMatch = typeStr.match(/^(.+?)(\[[^\]]*\])+$/);
189
+ const baseType = arrayMatch ? arrayMatch[1] : typeStr;
190
+ const arraySuffix = arrayMatch ? typeStr.slice(baseType.length) : "";
191
+ if (structs[baseType]) {
192
+ return {
193
+ type: `tuple${arraySuffix}`,
194
+ internalType: `struct ${baseType}${arraySuffix}`,
195
+ components: structs[baseType],
196
+ };
197
+ }
198
+ return {
199
+ type: typeStr,
200
+ internalType: typeStr,
201
+ };
202
+ }
203
+ function parseParams(paramsText, structs) {
204
+ const trimmed = paramsText.trim();
205
+ if (!trimmed) {
206
+ return [];
207
+ }
208
+ return trimmed
209
+ .split(",")
210
+ .map((part) => part.trim())
211
+ .filter(Boolean)
212
+ .map((part) => {
213
+ const tokens = part
214
+ .split(/\s+/)
215
+ .filter((token) => token &&
216
+ token !== "calldata" &&
217
+ token !== "memory" &&
218
+ token !== "storage");
219
+ const name = tokens.length > 1 ? tokens[tokens.length - 1] : "";
220
+ const type = tokens.length > 1 ? tokens.slice(0, -1).join(" ") : tokens[0];
221
+ const resolved = resolveParamType(type, structs);
222
+ return {
223
+ name,
224
+ ...resolved,
225
+ };
226
+ });
227
+ }
228
+ function parseInterfaceAbi(source, interfaceName, structs) {
229
+ const cleaned = stripComments(source);
230
+ const interfaceIndex = cleaned.indexOf(`interface ${interfaceName}`);
231
+ if (interfaceIndex === -1) {
232
+ throw new Error(`Interface ${interfaceName} not found`);
233
+ }
234
+ const braceStart = cleaned.indexOf("{", interfaceIndex);
235
+ if (braceStart === -1) {
236
+ throw new Error(`Interface ${interfaceName} has no body`);
237
+ }
238
+ let depth = 0;
239
+ let end = -1;
240
+ for (let i = braceStart; i < cleaned.length; i += 1) {
241
+ const char = cleaned[i];
242
+ if (char === "{") {
243
+ depth += 1;
244
+ }
245
+ else if (char === "}") {
246
+ depth -= 1;
247
+ if (depth === 0) {
248
+ end = i;
249
+ break;
250
+ }
251
+ }
252
+ }
253
+ if (end === -1) {
254
+ throw new Error(`Interface ${interfaceName} body not closed`);
255
+ }
256
+ const body = cleaned.slice(braceStart + 1, end).replace(/\s+/g, " ");
257
+ const functions = [];
258
+ const regex = /function\s+([A-Za-z0-9_]+)\s*\(([^)]*)\)\s*external\s*(?:returns\s*\(([^)]*)\))?\s*;/g;
259
+ let match;
260
+ while ((match = regex.exec(body)) !== null) {
261
+ const name = match[1];
262
+ const inputsText = match[2] ?? "";
263
+ const outputsText = match[3] ?? "";
264
+ functions.push({
265
+ type: "function",
266
+ name,
267
+ inputs: parseParams(inputsText, structs),
268
+ outputs: parseParams(outputsText, structs),
269
+ stateMutability: "nonpayable",
270
+ });
271
+ }
272
+ if (functions.length === 0) {
273
+ throw new Error(`No functions parsed for ${interfaceName}`);
274
+ }
275
+ return functions;
276
+ }
277
+ function abiParamKey(param) {
278
+ if (!param || typeof param !== "object") {
279
+ return "";
280
+ }
281
+ const typed = param;
282
+ if (!typed.type) {
283
+ return "";
284
+ }
285
+ if (typed.type.startsWith("tuple") && Array.isArray(typed.components)) {
286
+ const inner = typed.components.map(abiParamKey).join(",");
287
+ return `${typed.type}(${inner})`;
288
+ }
289
+ return typed.type;
290
+ }
291
+ function abiItemKey(item) {
292
+ if (!item || typeof item !== "object") {
293
+ return "";
294
+ }
295
+ const typed = item;
296
+ const type = typed.type ?? "";
297
+ const name = typed.name ?? "";
298
+ const inputs = Array.isArray(typed.inputs)
299
+ ? typed.inputs.map(abiParamKey).join(",")
300
+ : "";
301
+ const outputs = Array.isArray(typed.outputs)
302
+ ? typed.outputs.map(abiParamKey).join(",")
303
+ : "";
304
+ const mutability = typed.stateMutability ?? "";
305
+ const anonymous = typed.anonymous ? "1" : "0";
306
+ return `${type}|${name}|${inputs}|${outputs}|${mutability}|${anonymous}`;
307
+ }
308
+ function mergeAbis(abis) {
309
+ const merged = [];
310
+ const seen = new Set();
311
+ let hasConstructor = false;
312
+ let hasFallback = false;
313
+ let hasReceive = false;
314
+ for (const abi of abis) {
315
+ for (const item of abi) {
316
+ if (!item || typeof item !== "object") {
317
+ merged.push(item);
318
+ continue;
319
+ }
320
+ const typed = item;
321
+ const type = typed.type ?? "";
322
+ if (type === "constructor") {
323
+ if (hasConstructor) {
324
+ continue;
325
+ }
326
+ hasConstructor = true;
327
+ }
328
+ else if (type === "fallback") {
329
+ if (hasFallback) {
330
+ continue;
331
+ }
332
+ hasFallback = true;
333
+ }
334
+ else if (type === "receive") {
335
+ if (hasReceive) {
336
+ continue;
337
+ }
338
+ hasReceive = true;
339
+ }
340
+ const key = abiItemKey(item);
341
+ if (key) {
342
+ if (seen.has(key)) {
343
+ continue;
344
+ }
345
+ seen.add(key);
346
+ }
347
+ merged.push(item);
348
+ }
349
+ }
350
+ return merged;
351
+ }
352
+ function resolveEntryAbi(entry, versionControl, opts) {
353
+ if (entry.solFile && entry.interface) {
354
+ if (!entry.repo) {
355
+ throw new Error("missing repo for interface source");
356
+ }
357
+ const repoKey = normalizeRepo(entry.repo);
358
+ const ref = resolveRef(versionControl, opts.env, repoKey, entry.solFile, entry);
359
+ const interfaceSource = fetchRepoFile(repoKey, ref, entry.solFile);
360
+ const structs = {};
361
+ if (entry.structs) {
362
+ for (const [alias, spec] of Object.entries(entry.structs)) {
363
+ const structSource = fetchRepoFile(repoKey, ref, spec.solFile);
364
+ structs[alias] = parseStruct(structSource, spec.struct);
365
+ }
366
+ }
367
+ return parseInterfaceAbi(interfaceSource, entry.interface, structs);
368
+ }
369
+ if (!entry.repo || !entry.path) {
370
+ throw new Error("missing repo/path");
371
+ }
372
+ let payload;
373
+ if (entry.localFile && (0, node_fs_1.existsSync)(entry.localFile)) {
374
+ payload = readJsonFile(entry.localFile);
375
+ }
376
+ else {
377
+ const repoKey = normalizeRepo(entry.repo);
378
+ const ref = resolveRef(versionControl, opts.env, repoKey, entry.path, entry);
379
+ const artifactName = node_path_1.default.posix.basename(entry.path);
380
+ const fileName = entry.file ?? `${artifactName}.json`;
381
+ payload = fetchArtifactJson(repoKey, ref, entry.path, fileName);
382
+ }
383
+ let abi = extractAbi(payload);
384
+ if (entry.functions && entry.functions.length > 0) {
385
+ abi = filterAbiByFunctions(abi, entry.functions);
386
+ }
387
+ return abi;
388
+ }
389
+ function syncAbis() {
390
+ const opts = parseArgs(process.argv.slice(2));
391
+ const sharedConfigsRoot = process.cwd();
392
+ const yeetRoot = node_path_1.default.resolve(sharedConfigsRoot, "..");
393
+ const sourcesPath = node_path_1.default.join(sharedConfigsRoot, "abis-source", "sources.json");
394
+ const sources = readJsonFile(sourcesPath);
395
+ const versionControl = loadVersionControl(yeetRoot);
396
+ const outputDir = node_path_1.default.join(sharedConfigsRoot, "abis-source");
397
+ if (!(0, node_fs_1.existsSync)(outputDir)) {
398
+ (0, node_fs_1.mkdirSync)(outputDir, { recursive: true });
399
+ }
400
+ const failures = [];
401
+ for (const [targetFile, entry] of Object.entries(sources)) {
402
+ if (entry.skip) {
403
+ continue;
404
+ }
405
+ try {
406
+ const abi = entry.merge && entry.merge.length > 0
407
+ ? mergeAbis(entry.merge.map((child) => resolveEntryAbi(child, versionControl, opts)))
408
+ : resolveEntryAbi(entry, versionControl, opts);
409
+ const outputPath = node_path_1.default.join(outputDir, targetFile);
410
+ (0, node_fs_1.writeFileSync)(outputPath, `${JSON.stringify(abi, null, 2)}\n`);
411
+ console.log(`Updated ${targetFile}`);
412
+ }
413
+ catch (error) {
414
+ const message = error instanceof Error ? error.message : "Unknown error";
415
+ const line = `${targetFile}: ${message}`;
416
+ if (opts.strict) {
417
+ throw new Error(line);
418
+ }
419
+ failures.push(line);
420
+ }
421
+ }
422
+ if (failures.length > 0) {
423
+ console.warn("ABI sync warnings:");
424
+ for (const line of failures) {
425
+ console.warn(`- ${line}`);
426
+ }
427
+ }
428
+ if (opts.generate) {
429
+ (0, node_child_process_1.execFileSync)("bun", ["run", "generate:abis"], {
430
+ cwd: sharedConfigsRoot,
431
+ stdio: "inherit",
432
+ });
433
+ }
434
+ }
435
+ syncAbis();