@aztec/builder 0.0.0-test.1 → 0.0.1-fake-ceab37513c

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.
@@ -1 +1 @@
1
- {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/contract-interface-gen/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EAStB,MAAM,mBAAmB,CAAC;AAyR3B;;;;;GAKG;AACH,wBAAsB,mCAAmC,CAAC,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,EAAE,MAAM,mBA8E7G"}
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/contract-interface-gen/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EAWtB,MAAM,mBAAmB,CAAC;AAwQ3B;;;;;GAKG;AACH,wBAAsB,mCAAmC,CAAC,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,EAAE,MAAM,mBAyE7G"}
@@ -1,4 +1,4 @@
1
- import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecAddressStruct, isEthAddressStruct, isFunctionSelectorStruct, isWrappedFieldStruct } from '@aztec/stdlib/abi';
1
+ import { EventSelector, decodeFunctionSignature, getAllFunctionAbis, getDefaultInitializer, isAztecAddressStruct, isBoundedVecStruct, isEthAddressStruct, isFunctionSelectorStruct, isWrappedFieldStruct } from '@aztec/stdlib/abi';
2
2
  /**
3
3
  * Returns the corresponding typescript type for a given Noir type.
4
4
  * @param type - The input Noir type.
@@ -28,9 +28,14 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
28
28
  if (isWrappedFieldStruct(type)) {
29
29
  return 'WrappedFieldLike';
30
30
  }
31
+ if (isBoundedVecStruct(type)) {
32
+ // To make BoundedVec easier to work with, we expect a simple array on the input and then we encode it
33
+ // as a BoundedVec in the ArgumentsEncoder.
34
+ return `${abiTypeToTypescript(type.fields[0].type)}`;
35
+ }
31
36
  return `{ ${type.fields.map((f)=>`${f.name}: ${abiTypeToTypescript(f.type)}`).join(', ')} }`;
32
37
  default:
33
- throw new Error(`Unknown type ${type}`);
38
+ throw new Error(`Unknown type ${type.kind}`);
34
39
  }
35
40
  }
36
41
  /**
@@ -128,9 +133,9 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
128
133
  }`;
129
134
  }
130
135
  /**
131
- * Generates a static getter for the contract's artifact.
136
+ * Generates static getters for the contract's artifact.
132
137
  * @param name - Name of the contract used to derive name of the artifact import.
133
- */ function generateArtifactGetter(name) {
138
+ */ function generateArtifactGetters(name) {
134
139
  const artifactName = `${name}ContractArtifact`;
135
140
  return `
136
141
  /**
@@ -139,6 +144,13 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
139
144
  public static get artifact(): ContractArtifact {
140
145
  return ${artifactName};
141
146
  }
147
+
148
+ /**
149
+ * Returns this contract's artifact with public bytecode.
150
+ */
151
+ public static get artifactForPublic(): ContractArtifact {
152
+ return loadContractArtifactForPublic(${artifactName}Json as NoirCompiledContract);
153
+ }
142
154
  `;
143
155
  }
144
156
  /**
@@ -148,7 +160,7 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
148
160
  * @returns Code.
149
161
  */ function generateAbiStatement(name, artifactImportPath) {
150
162
  const stmts = [
151
- `import ${name}ContractArtifactJson from '${artifactImportPath}' assert { type: 'json' };`,
163
+ `import ${name}ContractArtifactJson from '${artifactImportPath}' with { type: 'json' };`,
152
164
  `export const ${name}ContractArtifact = loadContractArtifact(${name}ContractArtifactJson as NoirCompiledContract);`
153
165
  ];
154
166
  return stmts.join('\n');
@@ -172,25 +184,6 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
172
184
  }
173
185
  `;
174
186
  }
175
- /**
176
- * Generates a getter for the contract notes
177
- * @param input - The contract artifact.
178
- */ function generateNotesGetter(input) {
179
- const entries = Object.entries(input.notes);
180
- if (entries.length === 0) {
181
- return '';
182
- }
183
- const notesUnionType = entries.map(([name])=>`'${name}'`).join(' | ');
184
- const noteMetadata = entries.map(([name, { id }])=>`${name}: {
185
- id: new NoteSelector(${id.value}),
186
- }`).join(',\n');
187
- return `public static get notes(): ContractNotes<${notesUnionType}> {
188
- return {
189
- ${noteMetadata}
190
- } as ContractNotes<${notesUnionType}>;
191
- }
192
- `;
193
- }
194
187
  // events is of type AbiType
195
188
  async function generateEvents(events) {
196
189
  if (events === undefined) {
@@ -240,14 +233,13 @@ async function generateEvents(events) {
240
233
  * @param artifactImportPath - Optional path to import the artifact (if not set, will be required in the constructor).
241
234
  * @returns The corresponding ts code.
242
235
  */ export async function generateTypescriptContractInterface(input, artifactImportPath) {
243
- const methods = input.functions.filter((f)=>!f.isInternal).sort((a, b)=>a.name.localeCompare(b.name)).map(generateMethod);
236
+ const methods = getAllFunctionAbis(input).filter((f)=>!f.isInternal).sort((a, b)=>a.name.localeCompare(b.name)).map(generateMethod);
244
237
  const deploy = artifactImportPath && generateDeploy(input);
245
238
  const ctor = artifactImportPath && generateConstructor(input.name);
246
239
  const at = artifactImportPath && generateAt(input.name);
247
240
  const artifactStatement = artifactImportPath && generateAbiStatement(input.name, artifactImportPath);
248
- const artifactGetter = artifactImportPath && generateArtifactGetter(input.name);
241
+ const artifactGetter = artifactImportPath && generateArtifactGetters(input.name);
249
242
  const storageLayoutGetter = artifactImportPath && generateStorageLayoutGetter(input);
250
- const notesGetter = artifactImportPath && generateNotesGetter(input);
251
243
  const { eventDefs, events } = await generateEvents(input.outputs.structs?.events);
252
244
  return `
253
245
  /* Autogenerated file, do not edit! */
@@ -265,7 +257,6 @@ import {
265
257
  type ContractInstanceWithAddress,
266
258
  type ContractMethod,
267
259
  type ContractStorageLayout,
268
- type ContractNotes,
269
260
  decodeFromAbi,
270
261
  DeployMethod,
271
262
  EthAddress,
@@ -274,10 +265,9 @@ import {
274
265
  type FieldLike,
275
266
  Fr,
276
267
  type FunctionSelectorLike,
277
- L1EventPayload,
278
268
  loadContractArtifact,
269
+ loadContractArtifactForPublic,
279
270
  type NoirCompiledContract,
280
- NoteSelector,
281
271
  Point,
282
272
  type PublicKey,
283
273
  PublicKeys,
@@ -303,8 +293,6 @@ export class ${input.name}Contract extends ContractBase {
303
293
 
304
294
  ${storageLayoutGetter}
305
295
 
306
- ${notesGetter}
307
-
308
296
  /** Type-safe wrappers for the public methods exposed by the contract. */
309
297
  public declare methods: {
310
298
  ${methods.join('\n')}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/builder",
3
- "version": "0.0.0-test.1",
3
+ "version": "0.0.1-fake-ceab37513c",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -21,8 +21,6 @@
21
21
  "build:dev": "tsc -b --watch",
22
22
  "generate": "tsc -b",
23
23
  "clean": "rm -rf ./dest .tsbuildinfo",
24
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
25
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
26
24
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
27
25
  },
28
26
  "inherits": [
@@ -64,20 +62,24 @@
64
62
  "testTimeout": 120000,
65
63
  "setupFiles": [
66
64
  "../../foundation/src/jest/setup.mjs"
65
+ ],
66
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
67
+ "setupFilesAfterEnv": [
68
+ "../../foundation/src/jest/setupAfterEnv.mjs"
67
69
  ]
68
70
  },
69
71
  "dependencies": {
70
- "@aztec/foundation": "0.0.0-test.1",
71
- "@aztec/stdlib": "0.0.0-test.1",
72
+ "@aztec/foundation": "0.0.1-fake-ceab37513c",
73
+ "@aztec/stdlib": "0.0.1-fake-ceab37513c",
72
74
  "commander": "^12.1.0"
73
75
  },
74
76
  "devDependencies": {
75
- "@jest/globals": "^29.5.0",
76
- "@types/jest": "^29.5.0",
77
- "@types/node": "^18.7.23",
78
- "jest": "^29.5.0",
77
+ "@jest/globals": "^30.0.0",
78
+ "@types/jest": "^30.0.0",
79
+ "@types/node": "^22.15.17",
80
+ "jest": "^30.0.0",
79
81
  "ts-node": "^10.9.1",
80
- "typescript": "^5.0.4"
82
+ "typescript": "^5.3.3"
81
83
  },
82
84
  "files": [
83
85
  "dest",
@@ -86,6 +88,6 @@
86
88
  ],
87
89
  "types": "./dest/index.d.ts",
88
90
  "engines": {
89
- "node": ">=18"
91
+ "node": ">=20.10"
90
92
  }
91
93
  }
@@ -3,10 +3,12 @@ import {
3
3
  type ABIVariable,
4
4
  type ContractArtifact,
5
5
  EventSelector,
6
- type FunctionArtifact,
6
+ type FunctionAbi,
7
7
  decodeFunctionSignature,
8
+ getAllFunctionAbis,
8
9
  getDefaultInitializer,
9
10
  isAztecAddressStruct,
11
+ isBoundedVecStruct,
10
12
  isEthAddressStruct,
11
13
  isFunctionSelectorStruct,
12
14
  isWrappedFieldStruct,
@@ -42,9 +44,14 @@ function abiTypeToTypescript(type: ABIParameter['type']): string {
42
44
  if (isWrappedFieldStruct(type)) {
43
45
  return 'WrappedFieldLike';
44
46
  }
47
+ if (isBoundedVecStruct(type)) {
48
+ // To make BoundedVec easier to work with, we expect a simple array on the input and then we encode it
49
+ // as a BoundedVec in the ArgumentsEncoder.
50
+ return `${abiTypeToTypescript(type.fields[0].type)}`;
51
+ }
45
52
  return `{ ${type.fields.map(f => `${f.name}: ${abiTypeToTypescript(f.type)}`).join(', ')} }`;
46
53
  default:
47
- throw new Error(`Unknown type ${type}`);
54
+ throw new Error(`Unknown type ${type.kind}`);
48
55
  }
49
56
  }
50
57
 
@@ -62,7 +69,7 @@ function generateParameter(param: ABIParameter) {
62
69
  * @param param - A Noir function.
63
70
  * @returns The corresponding ts code.
64
71
  */
65
- function generateMethod(entry: FunctionArtifact) {
72
+ function generateMethod(entry: FunctionAbi) {
66
73
  const args = entry.parameters.map(generateParameter).join(', ');
67
74
  return `
68
75
  /** ${entry.name}(${entry.parameters.map(p => `${p.name}: ${p.type.kind}`).join(', ')}) */
@@ -154,10 +161,10 @@ function generateAt(name: string) {
154
161
  }
155
162
 
156
163
  /**
157
- * Generates a static getter for the contract's artifact.
164
+ * Generates static getters for the contract's artifact.
158
165
  * @param name - Name of the contract used to derive name of the artifact import.
159
166
  */
160
- function generateArtifactGetter(name: string) {
167
+ function generateArtifactGetters(name: string) {
161
168
  const artifactName = `${name}ContractArtifact`;
162
169
  return `
163
170
  /**
@@ -166,6 +173,13 @@ function generateArtifactGetter(name: string) {
166
173
  public static get artifact(): ContractArtifact {
167
174
  return ${artifactName};
168
175
  }
176
+
177
+ /**
178
+ * Returns this contract's artifact with public bytecode.
179
+ */
180
+ public static get artifactForPublic(): ContractArtifact {
181
+ return loadContractArtifactForPublic(${artifactName}Json as NoirCompiledContract);
182
+ }
169
183
  `;
170
184
  }
171
185
 
@@ -177,7 +191,7 @@ function generateArtifactGetter(name: string) {
177
191
  */
178
192
  function generateAbiStatement(name: string, artifactImportPath: string) {
179
193
  const stmts = [
180
- `import ${name}ContractArtifactJson from '${artifactImportPath}' assert { type: 'json' };`,
194
+ `import ${name}ContractArtifactJson from '${artifactImportPath}' with { type: 'json' };`,
181
195
  `export const ${name}ContractArtifact = loadContractArtifact(${name}ContractArtifactJson as NoirCompiledContract);`,
182
196
  ];
183
197
  return stmts.join('\n');
@@ -212,35 +226,6 @@ function generateStorageLayoutGetter(input: ContractArtifact) {
212
226
  `;
213
227
  }
214
228
 
215
- /**
216
- * Generates a getter for the contract notes
217
- * @param input - The contract artifact.
218
- */
219
- function generateNotesGetter(input: ContractArtifact) {
220
- const entries = Object.entries(input.notes);
221
-
222
- if (entries.length === 0) {
223
- return '';
224
- }
225
-
226
- const notesUnionType = entries.map(([name]) => `'${name}'`).join(' | ');
227
- const noteMetadata = entries
228
- .map(
229
- ([name, { id }]) =>
230
- `${name}: {
231
- id: new NoteSelector(${id.value}),
232
- }`,
233
- )
234
- .join(',\n');
235
-
236
- return `public static get notes(): ContractNotes<${notesUnionType}> {
237
- return {
238
- ${noteMetadata}
239
- } as ContractNotes<${notesUnionType}>;
240
- }
241
- `;
242
- }
243
-
244
229
  // events is of type AbiType
245
230
  async function generateEvents(events: any[] | undefined) {
246
231
  if (events === undefined) {
@@ -298,7 +283,7 @@ async function generateEvents(events: any[] | undefined) {
298
283
  * @returns The corresponding ts code.
299
284
  */
300
285
  export async function generateTypescriptContractInterface(input: ContractArtifact, artifactImportPath?: string) {
301
- const methods = input.functions
286
+ const methods = getAllFunctionAbis(input)
302
287
  .filter(f => !f.isInternal)
303
288
  .sort((a, b) => a.name.localeCompare(b.name))
304
289
  .map(generateMethod);
@@ -306,9 +291,8 @@ export async function generateTypescriptContractInterface(input: ContractArtifac
306
291
  const ctor = artifactImportPath && generateConstructor(input.name);
307
292
  const at = artifactImportPath && generateAt(input.name);
308
293
  const artifactStatement = artifactImportPath && generateAbiStatement(input.name, artifactImportPath);
309
- const artifactGetter = artifactImportPath && generateArtifactGetter(input.name);
294
+ const artifactGetter = artifactImportPath && generateArtifactGetters(input.name);
310
295
  const storageLayoutGetter = artifactImportPath && generateStorageLayoutGetter(input);
311
- const notesGetter = artifactImportPath && generateNotesGetter(input);
312
296
  const { eventDefs, events } = await generateEvents(input.outputs.structs?.events);
313
297
 
314
298
  return `
@@ -327,7 +311,6 @@ import {
327
311
  type ContractInstanceWithAddress,
328
312
  type ContractMethod,
329
313
  type ContractStorageLayout,
330
- type ContractNotes,
331
314
  decodeFromAbi,
332
315
  DeployMethod,
333
316
  EthAddress,
@@ -336,10 +319,9 @@ import {
336
319
  type FieldLike,
337
320
  Fr,
338
321
  type FunctionSelectorLike,
339
- L1EventPayload,
340
322
  loadContractArtifact,
323
+ loadContractArtifactForPublic,
341
324
  type NoirCompiledContract,
342
- NoteSelector,
343
325
  Point,
344
326
  type PublicKey,
345
327
  PublicKeys,
@@ -365,8 +347,6 @@ export class ${input.name}Contract extends ContractBase {
365
347
 
366
348
  ${storageLayoutGetter}
367
349
 
368
- ${notesGetter}
369
-
370
350
  /** Type-safe wrappers for the public methods exposed by the contract. */
371
351
  public declare methods: {
372
352
  ${methods.join('\n')}