@aztec/builder 0.0.0-test.1 → 0.0.1-commit.b655e406

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,mBAkD7G"}
@@ -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,51 +233,25 @@ 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! */
254
246
 
255
247
  /* eslint-disable */
256
- import {
257
- type AbiType,
258
- AztecAddress,
259
- type AztecAddressLike,
260
- CompleteAddress,
261
- Contract,
262
- type ContractArtifact,
263
- ContractBase,
264
- ContractFunctionInteraction,
265
- type ContractInstanceWithAddress,
266
- type ContractMethod,
267
- type ContractStorageLayout,
268
- type ContractNotes,
269
- decodeFromAbi,
270
- DeployMethod,
271
- EthAddress,
272
- type EthAddressLike,
273
- EventSelector,
274
- type FieldLike,
275
- Fr,
276
- type FunctionSelectorLike,
277
- L1EventPayload,
278
- loadContractArtifact,
279
- type NoirCompiledContract,
280
- NoteSelector,
281
- Point,
282
- type PublicKey,
283
- PublicKeys,
284
- type Wallet,
285
- type U128Like,
286
- type WrappedFieldLike,
287
- } from '@aztec/aztec.js';
248
+ import { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
249
+ import { type AbiType, type AztecAddressLike, type ContractArtifact, EventSelector, decodeFromAbi, type EthAddressLike, type FieldLike, type FunctionSelectorLike, loadContractArtifact, loadContractArtifactForPublic, type NoirCompiledContract, type U128Like, type WrappedFieldLike } from '@aztec/aztec.js/abi';
250
+ import { Contract, ContractBase, ContractFunctionInteraction, type ContractInstanceWithAddress, type ContractMethod, type ContractStorageLayout, DeployMethod } from '@aztec/aztec.js/contracts';
251
+ import { EthAddress } from '@aztec/aztec.js/addresses';
252
+ import { Fr, Point } from '@aztec/aztec.js/fields';
253
+ import { type PublicKey, PublicKeys } from '@aztec/aztec.js/keys';
254
+ import type { Wallet } from '@aztec/aztec.js/wallet';
288
255
  ${artifactStatement}
289
256
 
290
257
  ${eventDefs}
@@ -303,8 +270,6 @@ export class ${input.name}Contract extends ContractBase {
303
270
 
304
271
  ${storageLayoutGetter}
305
272
 
306
- ${notesGetter}
307
-
308
273
  /** Type-safe wrappers for the public methods exposed by the contract. */
309
274
  public declare methods: {
310
275
  ${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-commit.b655e406",
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-commit.b655e406",
73
+ "@aztec/stdlib": "0.0.1-commit.b655e406",
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,47 +291,21 @@ 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 `
315
299
  /* Autogenerated file, do not edit! */
316
300
 
317
301
  /* eslint-disable */
318
- import {
319
- type AbiType,
320
- AztecAddress,
321
- type AztecAddressLike,
322
- CompleteAddress,
323
- Contract,
324
- type ContractArtifact,
325
- ContractBase,
326
- ContractFunctionInteraction,
327
- type ContractInstanceWithAddress,
328
- type ContractMethod,
329
- type ContractStorageLayout,
330
- type ContractNotes,
331
- decodeFromAbi,
332
- DeployMethod,
333
- EthAddress,
334
- type EthAddressLike,
335
- EventSelector,
336
- type FieldLike,
337
- Fr,
338
- type FunctionSelectorLike,
339
- L1EventPayload,
340
- loadContractArtifact,
341
- type NoirCompiledContract,
342
- NoteSelector,
343
- Point,
344
- type PublicKey,
345
- PublicKeys,
346
- type Wallet,
347
- type U128Like,
348
- type WrappedFieldLike,
349
- } from '@aztec/aztec.js';
302
+ import { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
303
+ import { type AbiType, type AztecAddressLike, type ContractArtifact, EventSelector, decodeFromAbi, type EthAddressLike, type FieldLike, type FunctionSelectorLike, loadContractArtifact, loadContractArtifactForPublic, type NoirCompiledContract, type U128Like, type WrappedFieldLike } from '@aztec/aztec.js/abi';
304
+ import { Contract, ContractBase, ContractFunctionInteraction, type ContractInstanceWithAddress, type ContractMethod, type ContractStorageLayout, DeployMethod } from '@aztec/aztec.js/contracts';
305
+ import { EthAddress } from '@aztec/aztec.js/addresses';
306
+ import { Fr, Point } from '@aztec/aztec.js/fields';
307
+ import { type PublicKey, PublicKeys } from '@aztec/aztec.js/keys';
308
+ import type { Wallet } from '@aztec/aztec.js/wallet';
350
309
  ${artifactStatement}
351
310
 
352
311
  ${eventDefs}
@@ -365,8 +324,6 @@ export class ${input.name}Contract extends ContractBase {
365
324
 
366
325
  ${storageLayoutGetter}
367
326
 
368
- ${notesGetter}
369
-
370
327
  /** Type-safe wrappers for the public methods exposed by the contract. */
371
328
  public declare methods: {
372
329
  ${methods.join('\n')}