@aztec/builder 0.0.0-test.0 → 0.0.1-commit.001888fc
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.
- package/dest/bin/cli.d.ts +1 -1
- package/dest/contract-interface-gen/codegen.d.ts +2 -2
- package/dest/contract-interface-gen/codegen.d.ts.map +1 -1
- package/dest/contract-interface-gen/codegen.js +4 -0
- package/dest/contract-interface-gen/index.d.ts +2 -0
- package/dest/contract-interface-gen/index.d.ts.map +1 -0
- package/dest/contract-interface-gen/index.js +1 -0
- package/dest/contract-interface-gen/typescript.d.ts +1 -1
- package/dest/contract-interface-gen/typescript.d.ts.map +1 -1
- package/dest/contract-interface-gen/typescript.js +44 -72
- package/dest/index.d.ts +1 -1
- package/package.json +19 -18
- package/src/contract-interface-gen/codegen.ts +6 -0
- package/src/contract-interface-gen/index.ts +1 -0
- package/src/contract-interface-gen/typescript.ts +50 -84
package/dest/bin/cli.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export type GenerateCodeOptions = {
|
|
|
5
5
|
/**
|
|
6
6
|
* Generates Noir interface or Typescript interface for a folder or single file from a Noir compilation artifact.
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateCode(outputPath: string, fileOrDirPath: string, opts?: GenerateCodeOptions): Promise<string[]>;
|
|
9
|
-
//# sourceMappingURL=
|
|
8
|
+
export declare function generateCode(outputPath: string, fileOrDirPath: string, opts?: GenerateCodeOptions): Promise<(string | undefined)[]>;
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29kZWdlbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0LWludGVyZmFjZS1nZW4vY29kZWdlbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFZQSw0QkFBNEI7QUFDNUIsTUFBTSxNQUFNLG1CQUFtQixHQUFHO0lBQUUsS0FBSyxDQUFDLEVBQUUsT0FBTyxDQUFBO0NBQUUsQ0FBQztBQUV0RDs7R0FFRztBQUNILHdCQUFzQixZQUFZLENBQUMsVUFBVSxFQUFFLE1BQU0sRUFBRSxhQUFhLEVBQUUsTUFBTSxFQUFFLElBQUksR0FBRSxtQkFBd0IsbUNBa0IzRyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/contract-interface-gen/codegen.ts"],"names":[],"mappings":"AAYA,4BAA4B;AAC5B,MAAM,MAAM,mBAAmB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtD;;GAEG;AACH,wBAAsB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,GAAE,mBAAwB,
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/contract-interface-gen/codegen.ts"],"names":[],"mappings":"AAYA,4BAA4B;AAC5B,MAAM,MAAM,mBAAmB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtD;;GAEG;AACH,wBAAsB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,GAAE,mBAAwB,mCAkB3G"}
|
|
@@ -38,6 +38,10 @@ let cache = {};
|
|
|
38
38
|
}
|
|
39
39
|
const file = await readFile(noirAbiPath, 'utf8');
|
|
40
40
|
const contract = JSON.parse(file);
|
|
41
|
+
if (!Array.isArray(contract.functions)) {
|
|
42
|
+
console.log(`${fileName} is not a contract artifact. Skipping.`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
41
45
|
const aztecAbi = loadContractArtifact(contract);
|
|
42
46
|
await mkdir(outputPath, {
|
|
43
47
|
recursive: true
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { generateTypescriptContractInterface } from './typescript.js';
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb250cmFjdC1pbnRlcmZhY2UtZ2VuL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLGlCQUFpQixDQUFDIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract-interface-gen/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateTypescriptContractInterface } from './typescript.js';
|
|
@@ -6,4 +6,4 @@ import { type ContractArtifact } from '@aztec/stdlib/abi';
|
|
|
6
6
|
* @returns The corresponding ts code.
|
|
7
7
|
*/
|
|
8
8
|
export declare function generateTypescriptContractInterface(input: ContractArtifact, artifactImportPath?: string): Promise<string>;
|
|
9
|
-
//# sourceMappingURL=
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXNjcmlwdC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0LWludGVyZmFjZS1nZW4vdHlwZXNjcmlwdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBR0wsS0FBSyxnQkFBZ0IsRUFhdEIsTUFBTSxtQkFBbUIsQ0FBQztBQStRM0I7Ozs7O0dBS0c7QUFDSCx3QkFBc0IsbUNBQW1DLENBQUMsS0FBSyxFQUFFLGdCQUFnQixFQUFFLGtCQUFrQixDQUFDLEVBQUUsTUFBTSxtQkFrRDdHIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/contract-interface-gen/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/contract-interface-gen/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EAatB,MAAM,mBAAmB,CAAC;AA+Q3B;;;;;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, isOptionStruct, isPublicKeysStruct, 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,22 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
28
28
|
if (isWrappedFieldStruct(type)) {
|
|
29
29
|
return 'WrappedFieldLike';
|
|
30
30
|
}
|
|
31
|
+
if (isPublicKeysStruct(type)) {
|
|
32
|
+
// PublicKeys are special cased due to them being part of the preimage of contract addresses.
|
|
33
|
+
// The proper type is expected by the TS code that deals with the ContractInstanceRegistry protocol contract.
|
|
34
|
+
return 'PublicKeys';
|
|
35
|
+
}
|
|
36
|
+
if (isBoundedVecStruct(type)) {
|
|
37
|
+
// To make BoundedVec easier to work with, we expect a simple array on the input and then we encode it
|
|
38
|
+
// as a BoundedVec in the ArgumentsEncoder.
|
|
39
|
+
return `${abiTypeToTypescript(type.fields[0].type)}`;
|
|
40
|
+
}
|
|
41
|
+
if (isOptionStruct(type)) {
|
|
42
|
+
return `OptionLike<${abiTypeToTypescript(type.fields[1].type)}>`;
|
|
43
|
+
}
|
|
31
44
|
return `{ ${type.fields.map((f)=>`${f.name}: ${abiTypeToTypescript(f.type)}`).join(', ')} }`;
|
|
32
45
|
default:
|
|
33
|
-
throw new Error(`Unknown type ${type}`);
|
|
46
|
+
throw new Error(`Unknown type ${type.kind}`);
|
|
34
47
|
}
|
|
35
48
|
}
|
|
36
49
|
/**
|
|
@@ -64,14 +77,14 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
64
77
|
* Creates a tx to deploy a new instance of this contract.
|
|
65
78
|
*/
|
|
66
79
|
public static deploy(wallet: Wallet, ${args}) {
|
|
67
|
-
return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1));
|
|
80
|
+
return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(1));
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
/**
|
|
71
84
|
* Creates a tx to deploy a new instance of this contract using the specified public keys hash to derive the address.
|
|
72
85
|
*/
|
|
73
86
|
public static deployWithPublicKeys(publicKeys: PublicKeys, wallet: Wallet, ${args}) {
|
|
74
|
-
return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(2));
|
|
87
|
+
return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(2));
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
/**
|
|
@@ -85,7 +98,7 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
85
98
|
opts.publicKeys ?? PublicKeys.default(),
|
|
86
99
|
opts.wallet,
|
|
87
100
|
${artifactName},
|
|
88
|
-
${contractName}.at,
|
|
101
|
+
(instance, wallet) => ${contractName}.at(instance.address, wallet),
|
|
89
102
|
Array.from(arguments).slice(1),
|
|
90
103
|
opts.method ?? 'constructor',
|
|
91
104
|
);
|
|
@@ -96,14 +109,14 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
96
109
|
* Generates the constructor by supplying the ABI to the parent class so the user doesn't have to.
|
|
97
110
|
* @param name - Name of the contract to derive the ABI name from.
|
|
98
111
|
* @returns A constructor method.
|
|
99
|
-
* @remarks The constructor is private because we want to force the user to use the
|
|
112
|
+
* @remarks The constructor is private because we want to force the user to use the at method.
|
|
100
113
|
*/ function generateConstructor(name) {
|
|
101
114
|
return `
|
|
102
115
|
private constructor(
|
|
103
|
-
|
|
116
|
+
address: AztecAddress,
|
|
104
117
|
wallet: Wallet,
|
|
105
118
|
) {
|
|
106
|
-
super(
|
|
119
|
+
super(address, ${name}ContractArtifact, wallet);
|
|
107
120
|
}
|
|
108
121
|
`;
|
|
109
122
|
}
|
|
@@ -111,26 +124,25 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
111
124
|
* Generates the at method for this contract.
|
|
112
125
|
* @param name - Name of the contract to derive the ABI name from.
|
|
113
126
|
* @returns An at method.
|
|
114
|
-
* @remarks We don't use constructor directly because of the async `wallet.getContractData` call.
|
|
115
127
|
*/ function generateAt(name) {
|
|
116
128
|
return `
|
|
117
129
|
/**
|
|
118
130
|
* Creates a contract instance.
|
|
119
131
|
* @param address - The deployed contract's address.
|
|
120
132
|
* @param wallet - The wallet to use when interacting with the contract.
|
|
121
|
-
* @returns A
|
|
133
|
+
* @returns A new Contract instance.
|
|
122
134
|
*/
|
|
123
|
-
public static
|
|
135
|
+
public static at(
|
|
124
136
|
address: AztecAddress,
|
|
125
137
|
wallet: Wallet,
|
|
126
|
-
) {
|
|
127
|
-
return Contract.at(address, ${name}Contract.artifact, wallet) as
|
|
138
|
+
): ${name}Contract {
|
|
139
|
+
return Contract.at(address, ${name}Contract.artifact, wallet) as ${name}Contract;
|
|
128
140
|
}`;
|
|
129
141
|
}
|
|
130
142
|
/**
|
|
131
|
-
* Generates
|
|
143
|
+
* Generates static getters for the contract's artifact.
|
|
132
144
|
* @param name - Name of the contract used to derive name of the artifact import.
|
|
133
|
-
*/ function
|
|
145
|
+
*/ function generateArtifactGetters(name) {
|
|
134
146
|
const artifactName = `${name}ContractArtifact`;
|
|
135
147
|
return `
|
|
136
148
|
/**
|
|
@@ -139,6 +151,13 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
139
151
|
public static get artifact(): ContractArtifact {
|
|
140
152
|
return ${artifactName};
|
|
141
153
|
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Returns this contract's artifact with public bytecode.
|
|
157
|
+
*/
|
|
158
|
+
public static get artifactForPublic(): ContractArtifact {
|
|
159
|
+
return loadContractArtifactForPublic(${artifactName}Json as NoirCompiledContract);
|
|
160
|
+
}
|
|
142
161
|
`;
|
|
143
162
|
}
|
|
144
163
|
/**
|
|
@@ -148,7 +167,7 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
148
167
|
* @returns Code.
|
|
149
168
|
*/ function generateAbiStatement(name, artifactImportPath) {
|
|
150
169
|
const stmts = [
|
|
151
|
-
`import ${name}ContractArtifactJson from '${artifactImportPath}'
|
|
170
|
+
`import ${name}ContractArtifactJson from '${artifactImportPath}' with { type: 'json' };`,
|
|
152
171
|
`export const ${name}ContractArtifact = loadContractArtifact(${name}ContractArtifactJson as NoirCompiledContract);`
|
|
153
172
|
];
|
|
154
173
|
return stmts.join('\n');
|
|
@@ -172,25 +191,6 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
172
191
|
}
|
|
173
192
|
`;
|
|
174
193
|
}
|
|
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
194
|
// events is of type AbiType
|
|
195
195
|
async function generateEvents(events) {
|
|
196
196
|
if (events === undefined) {
|
|
@@ -240,51 +240,25 @@ async function generateEvents(events) {
|
|
|
240
240
|
* @param artifactImportPath - Optional path to import the artifact (if not set, will be required in the constructor).
|
|
241
241
|
* @returns The corresponding ts code.
|
|
242
242
|
*/ export async function generateTypescriptContractInterface(input, artifactImportPath) {
|
|
243
|
-
const methods = input.
|
|
243
|
+
const methods = getAllFunctionAbis(input).filter((f)=>!f.isOnlySelf).sort((a, b)=>a.name.localeCompare(b.name)).map(generateMethod);
|
|
244
244
|
const deploy = artifactImportPath && generateDeploy(input);
|
|
245
245
|
const ctor = artifactImportPath && generateConstructor(input.name);
|
|
246
246
|
const at = artifactImportPath && generateAt(input.name);
|
|
247
247
|
const artifactStatement = artifactImportPath && generateAbiStatement(input.name, artifactImportPath);
|
|
248
|
-
const artifactGetter = artifactImportPath &&
|
|
248
|
+
const artifactGetter = artifactImportPath && generateArtifactGetters(input.name);
|
|
249
249
|
const storageLayoutGetter = artifactImportPath && generateStorageLayoutGetter(input);
|
|
250
|
-
const notesGetter = artifactImportPath && generateNotesGetter(input);
|
|
251
250
|
const { eventDefs, events } = await generateEvents(input.outputs.structs?.events);
|
|
252
251
|
return `
|
|
253
252
|
/* Autogenerated file, do not edit! */
|
|
254
253
|
|
|
255
254
|
/* eslint-disable */
|
|
256
|
-
import {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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';
|
|
255
|
+
import { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
|
|
256
|
+
import { type AbiType, type AztecAddressLike, type ContractArtifact, EventSelector, decodeFromAbi, type EthAddressLike, type FieldLike, type FunctionSelectorLike, loadContractArtifact, loadContractArtifactForPublic, type NoirCompiledContract, type OptionLike, type U128Like, type WrappedFieldLike } from '@aztec/aztec.js/abi';
|
|
257
|
+
import { Contract, ContractBase, ContractFunctionInteraction, type ContractMethod, type ContractStorageLayout, DeployMethod } from '@aztec/aztec.js/contracts';
|
|
258
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
259
|
+
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
260
|
+
import { type PublicKey, PublicKeys } from '@aztec/aztec.js/keys';
|
|
261
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
288
262
|
${artifactStatement}
|
|
289
263
|
|
|
290
264
|
${eventDefs}
|
|
@@ -303,8 +277,6 @@ export class ${input.name}Contract extends ContractBase {
|
|
|
303
277
|
|
|
304
278
|
${storageLayoutGetter}
|
|
305
279
|
|
|
306
|
-
${notesGetter}
|
|
307
|
-
|
|
308
280
|
/** Type-safe wrappers for the public methods exposed by the contract. */
|
|
309
281
|
public declare methods: {
|
|
310
282
|
${methods.join('\n')}
|
package/dest/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
2
|
export declare function injectCommands(program: Command): Command;
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSxXQUFXLENBQUM7QUFHekMsd0JBQWdCLGNBQWMsQ0FBQyxPQUFPLEVBQUUsT0FBTyxXQVk5QyJ9
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-commit.001888fc",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
7
|
-
"./cli": "./dest/bin/cli.js"
|
|
7
|
+
"./cli": "./dest/bin/cli.js",
|
|
8
|
+
"./codegen": "./dest/contract-interface-gen/index.js"
|
|
8
9
|
},
|
|
9
10
|
"typedocOptions": {
|
|
10
11
|
"entryPoints": [
|
|
@@ -13,16 +14,11 @@
|
|
|
13
14
|
"name": "Aztec builder",
|
|
14
15
|
"tsconfig": "./tsconfig.json"
|
|
15
16
|
},
|
|
16
|
-
"bin": {
|
|
17
|
-
"aztec-builder": "dest/bin/cli.js"
|
|
18
|
-
},
|
|
19
17
|
"scripts": {
|
|
20
|
-
"build": "yarn clean && tsc
|
|
21
|
-
"build:dev": "tsc
|
|
22
|
-
"generate": "tsc
|
|
18
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
19
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
20
|
+
"generate": "../scripts/tsc.sh",
|
|
23
21
|
"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
22
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
27
23
|
},
|
|
28
24
|
"inherits": [
|
|
@@ -64,20 +60,25 @@
|
|
|
64
60
|
"testTimeout": 120000,
|
|
65
61
|
"setupFiles": [
|
|
66
62
|
"../../foundation/src/jest/setup.mjs"
|
|
63
|
+
],
|
|
64
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
65
|
+
"setupFilesAfterEnv": [
|
|
66
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/foundation": "0.0.
|
|
71
|
-
"@aztec/stdlib": "0.0.
|
|
70
|
+
"@aztec/foundation": "0.0.1-commit.001888fc",
|
|
71
|
+
"@aztec/stdlib": "0.0.1-commit.001888fc",
|
|
72
72
|
"commander": "^12.1.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@jest/globals": "^
|
|
76
|
-
"@types/jest": "^
|
|
77
|
-
"@types/node": "^
|
|
78
|
-
"
|
|
75
|
+
"@jest/globals": "^30.0.0",
|
|
76
|
+
"@types/jest": "^30.0.0",
|
|
77
|
+
"@types/node": "^22.15.17",
|
|
78
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
79
|
+
"jest": "^30.0.0",
|
|
79
80
|
"ts-node": "^10.9.1",
|
|
80
|
-
"typescript": "^5.
|
|
81
|
+
"typescript": "^5.3.3"
|
|
81
82
|
},
|
|
82
83
|
"files": [
|
|
83
84
|
"dest",
|
|
@@ -86,6 +87,6 @@
|
|
|
86
87
|
],
|
|
87
88
|
"types": "./dest/index.d.ts",
|
|
88
89
|
"engines": {
|
|
89
|
-
"node": ">=
|
|
90
|
+
"node": ">=20.10"
|
|
90
91
|
}
|
|
91
92
|
}
|
|
@@ -50,6 +50,12 @@ async function generateFromNoirAbi(outputPath: string, noirAbiPath: string, opts
|
|
|
50
50
|
|
|
51
51
|
const file = await readFile(noirAbiPath, 'utf8');
|
|
52
52
|
const contract = JSON.parse(file);
|
|
53
|
+
|
|
54
|
+
if (!Array.isArray(contract.functions)) {
|
|
55
|
+
console.log(`${fileName} is not a contract artifact. Skipping.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
const aztecAbi = loadContractArtifact(contract);
|
|
54
60
|
|
|
55
61
|
await mkdir(outputPath, { recursive: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateTypescriptContractInterface } from './typescript.js';
|
|
@@ -3,12 +3,16 @@ import {
|
|
|
3
3
|
type ABIVariable,
|
|
4
4
|
type ContractArtifact,
|
|
5
5
|
EventSelector,
|
|
6
|
-
type
|
|
6
|
+
type FunctionAbi,
|
|
7
7
|
decodeFunctionSignature,
|
|
8
|
+
getAllFunctionAbis,
|
|
8
9
|
getDefaultInitializer,
|
|
9
10
|
isAztecAddressStruct,
|
|
11
|
+
isBoundedVecStruct,
|
|
10
12
|
isEthAddressStruct,
|
|
11
13
|
isFunctionSelectorStruct,
|
|
14
|
+
isOptionStruct,
|
|
15
|
+
isPublicKeysStruct,
|
|
12
16
|
isWrappedFieldStruct,
|
|
13
17
|
} from '@aztec/stdlib/abi';
|
|
14
18
|
|
|
@@ -42,9 +46,22 @@ function abiTypeToTypescript(type: ABIParameter['type']): string {
|
|
|
42
46
|
if (isWrappedFieldStruct(type)) {
|
|
43
47
|
return 'WrappedFieldLike';
|
|
44
48
|
}
|
|
49
|
+
if (isPublicKeysStruct(type)) {
|
|
50
|
+
// PublicKeys are special cased due to them being part of the preimage of contract addresses.
|
|
51
|
+
// The proper type is expected by the TS code that deals with the ContractInstanceRegistry protocol contract.
|
|
52
|
+
return 'PublicKeys';
|
|
53
|
+
}
|
|
54
|
+
if (isBoundedVecStruct(type)) {
|
|
55
|
+
// To make BoundedVec easier to work with, we expect a simple array on the input and then we encode it
|
|
56
|
+
// as a BoundedVec in the ArgumentsEncoder.
|
|
57
|
+
return `${abiTypeToTypescript(type.fields[0].type)}`;
|
|
58
|
+
}
|
|
59
|
+
if (isOptionStruct(type)) {
|
|
60
|
+
return `OptionLike<${abiTypeToTypescript(type.fields[1].type)}>`;
|
|
61
|
+
}
|
|
45
62
|
return `{ ${type.fields.map(f => `${f.name}: ${abiTypeToTypescript(f.type)}`).join(', ')} }`;
|
|
46
63
|
default:
|
|
47
|
-
throw new Error(`Unknown type ${type}`);
|
|
64
|
+
throw new Error(`Unknown type ${type.kind}`);
|
|
48
65
|
}
|
|
49
66
|
}
|
|
50
67
|
|
|
@@ -62,7 +79,7 @@ function generateParameter(param: ABIParameter) {
|
|
|
62
79
|
* @param param - A Noir function.
|
|
63
80
|
* @returns The corresponding ts code.
|
|
64
81
|
*/
|
|
65
|
-
function generateMethod(entry:
|
|
82
|
+
function generateMethod(entry: FunctionAbi) {
|
|
66
83
|
const args = entry.parameters.map(generateParameter).join(', ');
|
|
67
84
|
return `
|
|
68
85
|
/** ${entry.name}(${entry.parameters.map(p => `${p.name}: ${p.type.kind}`).join(', ')}) */
|
|
@@ -85,14 +102,14 @@ function generateDeploy(input: ContractArtifact) {
|
|
|
85
102
|
* Creates a tx to deploy a new instance of this contract.
|
|
86
103
|
*/
|
|
87
104
|
public static deploy(wallet: Wallet, ${args}) {
|
|
88
|
-
return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1));
|
|
105
|
+
return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(1));
|
|
89
106
|
}
|
|
90
107
|
|
|
91
108
|
/**
|
|
92
109
|
* Creates a tx to deploy a new instance of this contract using the specified public keys hash to derive the address.
|
|
93
110
|
*/
|
|
94
111
|
public static deployWithPublicKeys(publicKeys: PublicKeys, wallet: Wallet, ${args}) {
|
|
95
|
-
return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(2));
|
|
112
|
+
return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(2));
|
|
96
113
|
}
|
|
97
114
|
|
|
98
115
|
/**
|
|
@@ -106,7 +123,7 @@ function generateDeploy(input: ContractArtifact) {
|
|
|
106
123
|
opts.publicKeys ?? PublicKeys.default(),
|
|
107
124
|
opts.wallet,
|
|
108
125
|
${artifactName},
|
|
109
|
-
${contractName}.at,
|
|
126
|
+
(instance, wallet) => ${contractName}.at(instance.address, wallet),
|
|
110
127
|
Array.from(arguments).slice(1),
|
|
111
128
|
opts.method ?? 'constructor',
|
|
112
129
|
);
|
|
@@ -118,15 +135,15 @@ function generateDeploy(input: ContractArtifact) {
|
|
|
118
135
|
* Generates the constructor by supplying the ABI to the parent class so the user doesn't have to.
|
|
119
136
|
* @param name - Name of the contract to derive the ABI name from.
|
|
120
137
|
* @returns A constructor method.
|
|
121
|
-
* @remarks The constructor is private because we want to force the user to use the
|
|
138
|
+
* @remarks The constructor is private because we want to force the user to use the at method.
|
|
122
139
|
*/
|
|
123
140
|
function generateConstructor(name: string) {
|
|
124
141
|
return `
|
|
125
142
|
private constructor(
|
|
126
|
-
|
|
143
|
+
address: AztecAddress,
|
|
127
144
|
wallet: Wallet,
|
|
128
145
|
) {
|
|
129
|
-
super(
|
|
146
|
+
super(address, ${name}ContractArtifact, wallet);
|
|
130
147
|
}
|
|
131
148
|
`;
|
|
132
149
|
}
|
|
@@ -135,7 +152,6 @@ function generateConstructor(name: string) {
|
|
|
135
152
|
* Generates the at method for this contract.
|
|
136
153
|
* @param name - Name of the contract to derive the ABI name from.
|
|
137
154
|
* @returns An at method.
|
|
138
|
-
* @remarks We don't use constructor directly because of the async `wallet.getContractData` call.
|
|
139
155
|
*/
|
|
140
156
|
function generateAt(name: string) {
|
|
141
157
|
return `
|
|
@@ -143,21 +159,21 @@ function generateAt(name: string) {
|
|
|
143
159
|
* Creates a contract instance.
|
|
144
160
|
* @param address - The deployed contract's address.
|
|
145
161
|
* @param wallet - The wallet to use when interacting with the contract.
|
|
146
|
-
* @returns A
|
|
162
|
+
* @returns A new Contract instance.
|
|
147
163
|
*/
|
|
148
|
-
public static
|
|
164
|
+
public static at(
|
|
149
165
|
address: AztecAddress,
|
|
150
166
|
wallet: Wallet,
|
|
151
|
-
) {
|
|
152
|
-
return Contract.at(address, ${name}Contract.artifact, wallet) as
|
|
167
|
+
): ${name}Contract {
|
|
168
|
+
return Contract.at(address, ${name}Contract.artifact, wallet) as ${name}Contract;
|
|
153
169
|
}`;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
/**
|
|
157
|
-
* Generates
|
|
173
|
+
* Generates static getters for the contract's artifact.
|
|
158
174
|
* @param name - Name of the contract used to derive name of the artifact import.
|
|
159
175
|
*/
|
|
160
|
-
function
|
|
176
|
+
function generateArtifactGetters(name: string) {
|
|
161
177
|
const artifactName = `${name}ContractArtifact`;
|
|
162
178
|
return `
|
|
163
179
|
/**
|
|
@@ -166,6 +182,13 @@ function generateArtifactGetter(name: string) {
|
|
|
166
182
|
public static get artifact(): ContractArtifact {
|
|
167
183
|
return ${artifactName};
|
|
168
184
|
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Returns this contract's artifact with public bytecode.
|
|
188
|
+
*/
|
|
189
|
+
public static get artifactForPublic(): ContractArtifact {
|
|
190
|
+
return loadContractArtifactForPublic(${artifactName}Json as NoirCompiledContract);
|
|
191
|
+
}
|
|
169
192
|
`;
|
|
170
193
|
}
|
|
171
194
|
|
|
@@ -177,7 +200,7 @@ function generateArtifactGetter(name: string) {
|
|
|
177
200
|
*/
|
|
178
201
|
function generateAbiStatement(name: string, artifactImportPath: string) {
|
|
179
202
|
const stmts = [
|
|
180
|
-
`import ${name}ContractArtifactJson from '${artifactImportPath}'
|
|
203
|
+
`import ${name}ContractArtifactJson from '${artifactImportPath}' with { type: 'json' };`,
|
|
181
204
|
`export const ${name}ContractArtifact = loadContractArtifact(${name}ContractArtifactJson as NoirCompiledContract);`,
|
|
182
205
|
];
|
|
183
206
|
return stmts.join('\n');
|
|
@@ -212,35 +235,6 @@ function generateStorageLayoutGetter(input: ContractArtifact) {
|
|
|
212
235
|
`;
|
|
213
236
|
}
|
|
214
237
|
|
|
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
238
|
// events is of type AbiType
|
|
245
239
|
async function generateEvents(events: any[] | undefined) {
|
|
246
240
|
if (events === undefined) {
|
|
@@ -298,55 +292,29 @@ async function generateEvents(events: any[] | undefined) {
|
|
|
298
292
|
* @returns The corresponding ts code.
|
|
299
293
|
*/
|
|
300
294
|
export async function generateTypescriptContractInterface(input: ContractArtifact, artifactImportPath?: string) {
|
|
301
|
-
const methods = input
|
|
302
|
-
.filter(f => !f.
|
|
295
|
+
const methods = getAllFunctionAbis(input)
|
|
296
|
+
.filter(f => !f.isOnlySelf)
|
|
303
297
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
304
298
|
.map(generateMethod);
|
|
305
299
|
const deploy = artifactImportPath && generateDeploy(input);
|
|
306
300
|
const ctor = artifactImportPath && generateConstructor(input.name);
|
|
307
301
|
const at = artifactImportPath && generateAt(input.name);
|
|
308
302
|
const artifactStatement = artifactImportPath && generateAbiStatement(input.name, artifactImportPath);
|
|
309
|
-
const artifactGetter = artifactImportPath &&
|
|
303
|
+
const artifactGetter = artifactImportPath && generateArtifactGetters(input.name);
|
|
310
304
|
const storageLayoutGetter = artifactImportPath && generateStorageLayoutGetter(input);
|
|
311
|
-
const notesGetter = artifactImportPath && generateNotesGetter(input);
|
|
312
305
|
const { eventDefs, events } = await generateEvents(input.outputs.structs?.events);
|
|
313
306
|
|
|
314
307
|
return `
|
|
315
308
|
/* Autogenerated file, do not edit! */
|
|
316
309
|
|
|
317
310
|
/* eslint-disable */
|
|
318
|
-
import {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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';
|
|
311
|
+
import { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
|
|
312
|
+
import { type AbiType, type AztecAddressLike, type ContractArtifact, EventSelector, decodeFromAbi, type EthAddressLike, type FieldLike, type FunctionSelectorLike, loadContractArtifact, loadContractArtifactForPublic, type NoirCompiledContract, type OptionLike, type U128Like, type WrappedFieldLike } from '@aztec/aztec.js/abi';
|
|
313
|
+
import { Contract, ContractBase, ContractFunctionInteraction, type ContractMethod, type ContractStorageLayout, DeployMethod } from '@aztec/aztec.js/contracts';
|
|
314
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
315
|
+
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
316
|
+
import { type PublicKey, PublicKeys } from '@aztec/aztec.js/keys';
|
|
317
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
350
318
|
${artifactStatement}
|
|
351
319
|
|
|
352
320
|
${eventDefs}
|
|
@@ -365,8 +333,6 @@ export class ${input.name}Contract extends ContractBase {
|
|
|
365
333
|
|
|
366
334
|
${storageLayoutGetter}
|
|
367
335
|
|
|
368
|
-
${notesGetter}
|
|
369
|
-
|
|
370
336
|
/** Type-safe wrappers for the public methods exposed by the contract. */
|
|
371
337
|
public declare methods: {
|
|
372
338
|
${methods.join('\n')}
|