@aztec/builder 0.0.0-test.1 → 0.0.1-commit.5476d83
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 +1 -1
- 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 +36 -72
- package/dest/index.d.ts +1 -1
- package/package.json +17 -14
- package/src/contract-interface-gen/typescript.ts +40 -84
package/dest/bin/cli.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export type GenerateCodeOptions = {
|
|
|
6
6
|
* Generates Noir interface or Typescript interface for a folder or single file from a Noir compilation artifact.
|
|
7
7
|
*/
|
|
8
8
|
export declare function generateCode(outputPath: string, fileOrDirPath: string, opts?: GenerateCodeOptions): Promise<string[]>;
|
|
9
|
-
//# sourceMappingURL=
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29kZWdlbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0LWludGVyZmFjZS1nZW4vY29kZWdlbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFZQSw0QkFBNEI7QUFDNUIsTUFBTSxNQUFNLG1CQUFtQixHQUFHO0lBQUUsS0FBSyxDQUFDLEVBQUUsT0FBTyxDQUFBO0NBQUUsQ0FBQztBQUV0RDs7R0FFRztBQUNILHdCQUFzQixZQUFZLENBQUMsVUFBVSxFQUFFLE1BQU0sRUFBRSxhQUFhLEVBQUUsTUFBTSxFQUFFLElBQUksR0FBRSxtQkFBd0IscUJBa0IzRyJ9
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXNjcmlwdC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0LWludGVyZmFjZS1nZW4vdHlwZXNjcmlwdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBR0wsS0FBSyxnQkFBZ0IsRUFXdEIsTUFBTSxtQkFBbUIsQ0FBQztBQXVRM0I7Ozs7O0dBS0c7QUFDSCx3QkFBc0IsbUNBQW1DLENBQUMsS0FBSyxFQUFFLGdCQUFnQixFQUFFLGtCQUFrQixDQUFDLEVBQUUsTUFBTSxtQkFrRDdHIn0=
|
|
@@ -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,EAWtB,MAAM,mBAAmB,CAAC;AAuQ3B;;;;;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
|
/**
|
|
@@ -64,14 +69,14 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
64
69
|
* Creates a tx to deploy a new instance of this contract.
|
|
65
70
|
*/
|
|
66
71
|
public static deploy(wallet: Wallet, ${args}) {
|
|
67
|
-
return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1));
|
|
72
|
+
return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(1));
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
/**
|
|
71
76
|
* Creates a tx to deploy a new instance of this contract using the specified public keys hash to derive the address.
|
|
72
77
|
*/
|
|
73
78
|
public static deployWithPublicKeys(publicKeys: PublicKeys, wallet: Wallet, ${args}) {
|
|
74
|
-
return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(2));
|
|
79
|
+
return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(2));
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
/**
|
|
@@ -85,7 +90,7 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
85
90
|
opts.publicKeys ?? PublicKeys.default(),
|
|
86
91
|
opts.wallet,
|
|
87
92
|
${artifactName},
|
|
88
|
-
${contractName}.at,
|
|
93
|
+
(instance, wallet) => ${contractName}.at(instance.address, wallet),
|
|
89
94
|
Array.from(arguments).slice(1),
|
|
90
95
|
opts.method ?? 'constructor',
|
|
91
96
|
);
|
|
@@ -96,14 +101,14 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
96
101
|
* Generates the constructor by supplying the ABI to the parent class so the user doesn't have to.
|
|
97
102
|
* @param name - Name of the contract to derive the ABI name from.
|
|
98
103
|
* @returns A constructor method.
|
|
99
|
-
* @remarks The constructor is private because we want to force the user to use the
|
|
104
|
+
* @remarks The constructor is private because we want to force the user to use the at method.
|
|
100
105
|
*/ function generateConstructor(name) {
|
|
101
106
|
return `
|
|
102
107
|
private constructor(
|
|
103
|
-
|
|
108
|
+
address: AztecAddress,
|
|
104
109
|
wallet: Wallet,
|
|
105
110
|
) {
|
|
106
|
-
super(
|
|
111
|
+
super(address, ${name}ContractArtifact, wallet);
|
|
107
112
|
}
|
|
108
113
|
`;
|
|
109
114
|
}
|
|
@@ -111,26 +116,25 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
111
116
|
* Generates the at method for this contract.
|
|
112
117
|
* @param name - Name of the contract to derive the ABI name from.
|
|
113
118
|
* @returns An at method.
|
|
114
|
-
* @remarks We don't use constructor directly because of the async `wallet.getContractData` call.
|
|
115
119
|
*/ function generateAt(name) {
|
|
116
120
|
return `
|
|
117
121
|
/**
|
|
118
122
|
* Creates a contract instance.
|
|
119
123
|
* @param address - The deployed contract's address.
|
|
120
124
|
* @param wallet - The wallet to use when interacting with the contract.
|
|
121
|
-
* @returns A
|
|
125
|
+
* @returns A new Contract instance.
|
|
122
126
|
*/
|
|
123
|
-
public static
|
|
127
|
+
public static at(
|
|
124
128
|
address: AztecAddress,
|
|
125
129
|
wallet: Wallet,
|
|
126
|
-
) {
|
|
127
|
-
return Contract.at(address, ${name}Contract.artifact, wallet) as
|
|
130
|
+
): ${name}Contract {
|
|
131
|
+
return Contract.at(address, ${name}Contract.artifact, wallet) as ${name}Contract;
|
|
128
132
|
}`;
|
|
129
133
|
}
|
|
130
134
|
/**
|
|
131
|
-
* Generates
|
|
135
|
+
* Generates static getters for the contract's artifact.
|
|
132
136
|
* @param name - Name of the contract used to derive name of the artifact import.
|
|
133
|
-
*/ function
|
|
137
|
+
*/ function generateArtifactGetters(name) {
|
|
134
138
|
const artifactName = `${name}ContractArtifact`;
|
|
135
139
|
return `
|
|
136
140
|
/**
|
|
@@ -139,6 +143,13 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
139
143
|
public static get artifact(): ContractArtifact {
|
|
140
144
|
return ${artifactName};
|
|
141
145
|
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Returns this contract's artifact with public bytecode.
|
|
149
|
+
*/
|
|
150
|
+
public static get artifactForPublic(): ContractArtifact {
|
|
151
|
+
return loadContractArtifactForPublic(${artifactName}Json as NoirCompiledContract);
|
|
152
|
+
}
|
|
142
153
|
`;
|
|
143
154
|
}
|
|
144
155
|
/**
|
|
@@ -148,7 +159,7 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
148
159
|
* @returns Code.
|
|
149
160
|
*/ function generateAbiStatement(name, artifactImportPath) {
|
|
150
161
|
const stmts = [
|
|
151
|
-
`import ${name}ContractArtifactJson from '${artifactImportPath}'
|
|
162
|
+
`import ${name}ContractArtifactJson from '${artifactImportPath}' with { type: 'json' };`,
|
|
152
163
|
`export const ${name}ContractArtifact = loadContractArtifact(${name}ContractArtifactJson as NoirCompiledContract);`
|
|
153
164
|
];
|
|
154
165
|
return stmts.join('\n');
|
|
@@ -172,25 +183,6 @@ import { EventSelector, decodeFunctionSignature, getDefaultInitializer, isAztecA
|
|
|
172
183
|
}
|
|
173
184
|
`;
|
|
174
185
|
}
|
|
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
186
|
// events is of type AbiType
|
|
195
187
|
async function generateEvents(events) {
|
|
196
188
|
if (events === undefined) {
|
|
@@ -240,51 +232,25 @@ async function generateEvents(events) {
|
|
|
240
232
|
* @param artifactImportPath - Optional path to import the artifact (if not set, will be required in the constructor).
|
|
241
233
|
* @returns The corresponding ts code.
|
|
242
234
|
*/ export async function generateTypescriptContractInterface(input, artifactImportPath) {
|
|
243
|
-
const methods = input.
|
|
235
|
+
const methods = getAllFunctionAbis(input).filter((f)=>!f.isOnlySelf).sort((a, b)=>a.name.localeCompare(b.name)).map(generateMethod);
|
|
244
236
|
const deploy = artifactImportPath && generateDeploy(input);
|
|
245
237
|
const ctor = artifactImportPath && generateConstructor(input.name);
|
|
246
238
|
const at = artifactImportPath && generateAt(input.name);
|
|
247
239
|
const artifactStatement = artifactImportPath && generateAbiStatement(input.name, artifactImportPath);
|
|
248
|
-
const artifactGetter = artifactImportPath &&
|
|
240
|
+
const artifactGetter = artifactImportPath && generateArtifactGetters(input.name);
|
|
249
241
|
const storageLayoutGetter = artifactImportPath && generateStorageLayoutGetter(input);
|
|
250
|
-
const notesGetter = artifactImportPath && generateNotesGetter(input);
|
|
251
242
|
const { eventDefs, events } = await generateEvents(input.outputs.structs?.events);
|
|
252
243
|
return `
|
|
253
244
|
/* Autogenerated file, do not edit! */
|
|
254
245
|
|
|
255
246
|
/* 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';
|
|
247
|
+
import { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
|
|
248
|
+
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';
|
|
249
|
+
import { Contract, ContractBase, ContractFunctionInteraction, type ContractMethod, type ContractStorageLayout, DeployMethod } from '@aztec/aztec.js/contracts';
|
|
250
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
251
|
+
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
252
|
+
import { type PublicKey, PublicKeys } from '@aztec/aztec.js/keys';
|
|
253
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
288
254
|
${artifactStatement}
|
|
289
255
|
|
|
290
256
|
${eventDefs}
|
|
@@ -303,8 +269,6 @@ export class ${input.name}Contract extends ContractBase {
|
|
|
303
269
|
|
|
304
270
|
${storageLayoutGetter}
|
|
305
271
|
|
|
306
|
-
${notesGetter}
|
|
307
|
-
|
|
308
272
|
/** Type-safe wrappers for the public methods exposed by the contract. */
|
|
309
273
|
public declare methods: {
|
|
310
274
|
${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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-commit.5476d83",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -17,12 +17,10 @@
|
|
|
17
17
|
"aztec-builder": "dest/bin/cli.js"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "yarn clean &&
|
|
21
|
-
"build:dev": "
|
|
22
|
-
"generate": "
|
|
20
|
+
"build": "yarn clean && tsgo -b",
|
|
21
|
+
"build:dev": "tsgo -b --watch",
|
|
22
|
+
"generate": "tsgo -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,25 @@
|
|
|
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.
|
|
71
|
-
"@aztec/stdlib": "0.0.
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.5476d83",
|
|
73
|
+
"@aztec/stdlib": "0.0.1-commit.5476d83",
|
|
72
74
|
"commander": "^12.1.0"
|
|
73
75
|
},
|
|
74
76
|
"devDependencies": {
|
|
75
|
-
"@jest/globals": "^
|
|
76
|
-
"@types/jest": "^
|
|
77
|
-
"@types/node": "^
|
|
78
|
-
"
|
|
77
|
+
"@jest/globals": "^30.0.0",
|
|
78
|
+
"@types/jest": "^30.0.0",
|
|
79
|
+
"@types/node": "^22.15.17",
|
|
80
|
+
"@typescript/native-preview": "7.0.0-dev.20251126.1",
|
|
81
|
+
"jest": "^30.0.0",
|
|
79
82
|
"ts-node": "^10.9.1",
|
|
80
|
-
"typescript": "^5.
|
|
83
|
+
"typescript": "^5.3.3"
|
|
81
84
|
},
|
|
82
85
|
"files": [
|
|
83
86
|
"dest",
|
|
@@ -86,6 +89,6 @@
|
|
|
86
89
|
],
|
|
87
90
|
"types": "./dest/index.d.ts",
|
|
88
91
|
"engines": {
|
|
89
|
-
"node": ">=
|
|
92
|
+
"node": ">=20.10"
|
|
90
93
|
}
|
|
91
94
|
}
|
|
@@ -3,10 +3,12 @@ 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,
|
|
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:
|
|
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(', ')}) */
|
|
@@ -85,14 +92,14 @@ function generateDeploy(input: ContractArtifact) {
|
|
|
85
92
|
* Creates a tx to deploy a new instance of this contract.
|
|
86
93
|
*/
|
|
87
94
|
public static deploy(wallet: Wallet, ${args}) {
|
|
88
|
-
return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1));
|
|
95
|
+
return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(1));
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
/**
|
|
92
99
|
* Creates a tx to deploy a new instance of this contract using the specified public keys hash to derive the address.
|
|
93
100
|
*/
|
|
94
101
|
public static deployWithPublicKeys(publicKeys: PublicKeys, wallet: Wallet, ${args}) {
|
|
95
|
-
return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(2));
|
|
102
|
+
return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(2));
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
/**
|
|
@@ -106,7 +113,7 @@ function generateDeploy(input: ContractArtifact) {
|
|
|
106
113
|
opts.publicKeys ?? PublicKeys.default(),
|
|
107
114
|
opts.wallet,
|
|
108
115
|
${artifactName},
|
|
109
|
-
${contractName}.at,
|
|
116
|
+
(instance, wallet) => ${contractName}.at(instance.address, wallet),
|
|
110
117
|
Array.from(arguments).slice(1),
|
|
111
118
|
opts.method ?? 'constructor',
|
|
112
119
|
);
|
|
@@ -118,15 +125,15 @@ function generateDeploy(input: ContractArtifact) {
|
|
|
118
125
|
* Generates the constructor by supplying the ABI to the parent class so the user doesn't have to.
|
|
119
126
|
* @param name - Name of the contract to derive the ABI name from.
|
|
120
127
|
* @returns A constructor method.
|
|
121
|
-
* @remarks The constructor is private because we want to force the user to use the
|
|
128
|
+
* @remarks The constructor is private because we want to force the user to use the at method.
|
|
122
129
|
*/
|
|
123
130
|
function generateConstructor(name: string) {
|
|
124
131
|
return `
|
|
125
132
|
private constructor(
|
|
126
|
-
|
|
133
|
+
address: AztecAddress,
|
|
127
134
|
wallet: Wallet,
|
|
128
135
|
) {
|
|
129
|
-
super(
|
|
136
|
+
super(address, ${name}ContractArtifact, wallet);
|
|
130
137
|
}
|
|
131
138
|
`;
|
|
132
139
|
}
|
|
@@ -135,7 +142,6 @@ function generateConstructor(name: string) {
|
|
|
135
142
|
* Generates the at method for this contract.
|
|
136
143
|
* @param name - Name of the contract to derive the ABI name from.
|
|
137
144
|
* @returns An at method.
|
|
138
|
-
* @remarks We don't use constructor directly because of the async `wallet.getContractData` call.
|
|
139
145
|
*/
|
|
140
146
|
function generateAt(name: string) {
|
|
141
147
|
return `
|
|
@@ -143,21 +149,21 @@ function generateAt(name: string) {
|
|
|
143
149
|
* Creates a contract instance.
|
|
144
150
|
* @param address - The deployed contract's address.
|
|
145
151
|
* @param wallet - The wallet to use when interacting with the contract.
|
|
146
|
-
* @returns A
|
|
152
|
+
* @returns A new Contract instance.
|
|
147
153
|
*/
|
|
148
|
-
public static
|
|
154
|
+
public static at(
|
|
149
155
|
address: AztecAddress,
|
|
150
156
|
wallet: Wallet,
|
|
151
|
-
) {
|
|
152
|
-
return Contract.at(address, ${name}Contract.artifact, wallet) as
|
|
157
|
+
): ${name}Contract {
|
|
158
|
+
return Contract.at(address, ${name}Contract.artifact, wallet) as ${name}Contract;
|
|
153
159
|
}`;
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
/**
|
|
157
|
-
* Generates
|
|
163
|
+
* Generates static getters for the contract's artifact.
|
|
158
164
|
* @param name - Name of the contract used to derive name of the artifact import.
|
|
159
165
|
*/
|
|
160
|
-
function
|
|
166
|
+
function generateArtifactGetters(name: string) {
|
|
161
167
|
const artifactName = `${name}ContractArtifact`;
|
|
162
168
|
return `
|
|
163
169
|
/**
|
|
@@ -166,6 +172,13 @@ function generateArtifactGetter(name: string) {
|
|
|
166
172
|
public static get artifact(): ContractArtifact {
|
|
167
173
|
return ${artifactName};
|
|
168
174
|
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Returns this contract's artifact with public bytecode.
|
|
178
|
+
*/
|
|
179
|
+
public static get artifactForPublic(): ContractArtifact {
|
|
180
|
+
return loadContractArtifactForPublic(${artifactName}Json as NoirCompiledContract);
|
|
181
|
+
}
|
|
169
182
|
`;
|
|
170
183
|
}
|
|
171
184
|
|
|
@@ -177,7 +190,7 @@ function generateArtifactGetter(name: string) {
|
|
|
177
190
|
*/
|
|
178
191
|
function generateAbiStatement(name: string, artifactImportPath: string) {
|
|
179
192
|
const stmts = [
|
|
180
|
-
`import ${name}ContractArtifactJson from '${artifactImportPath}'
|
|
193
|
+
`import ${name}ContractArtifactJson from '${artifactImportPath}' with { type: 'json' };`,
|
|
181
194
|
`export const ${name}ContractArtifact = loadContractArtifact(${name}ContractArtifactJson as NoirCompiledContract);`,
|
|
182
195
|
];
|
|
183
196
|
return stmts.join('\n');
|
|
@@ -212,35 +225,6 @@ function generateStorageLayoutGetter(input: ContractArtifact) {
|
|
|
212
225
|
`;
|
|
213
226
|
}
|
|
214
227
|
|
|
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
228
|
// events is of type AbiType
|
|
245
229
|
async function generateEvents(events: any[] | undefined) {
|
|
246
230
|
if (events === undefined) {
|
|
@@ -298,55 +282,29 @@ async function generateEvents(events: any[] | undefined) {
|
|
|
298
282
|
* @returns The corresponding ts code.
|
|
299
283
|
*/
|
|
300
284
|
export async function generateTypescriptContractInterface(input: ContractArtifact, artifactImportPath?: string) {
|
|
301
|
-
const methods = input
|
|
302
|
-
.filter(f => !f.
|
|
285
|
+
const methods = getAllFunctionAbis(input)
|
|
286
|
+
.filter(f => !f.isOnlySelf)
|
|
303
287
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
304
288
|
.map(generateMethod);
|
|
305
289
|
const deploy = artifactImportPath && generateDeploy(input);
|
|
306
290
|
const ctor = artifactImportPath && generateConstructor(input.name);
|
|
307
291
|
const at = artifactImportPath && generateAt(input.name);
|
|
308
292
|
const artifactStatement = artifactImportPath && generateAbiStatement(input.name, artifactImportPath);
|
|
309
|
-
const artifactGetter = artifactImportPath &&
|
|
293
|
+
const artifactGetter = artifactImportPath && generateArtifactGetters(input.name);
|
|
310
294
|
const storageLayoutGetter = artifactImportPath && generateStorageLayoutGetter(input);
|
|
311
|
-
const notesGetter = artifactImportPath && generateNotesGetter(input);
|
|
312
295
|
const { eventDefs, events } = await generateEvents(input.outputs.structs?.events);
|
|
313
296
|
|
|
314
297
|
return `
|
|
315
298
|
/* Autogenerated file, do not edit! */
|
|
316
299
|
|
|
317
300
|
/* 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';
|
|
301
|
+
import { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
|
|
302
|
+
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';
|
|
303
|
+
import { Contract, ContractBase, ContractFunctionInteraction, type ContractMethod, type ContractStorageLayout, DeployMethod } from '@aztec/aztec.js/contracts';
|
|
304
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
305
|
+
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
306
|
+
import { type PublicKey, PublicKeys } from '@aztec/aztec.js/keys';
|
|
307
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
350
308
|
${artifactStatement}
|
|
351
309
|
|
|
352
310
|
${eventDefs}
|
|
@@ -365,8 +323,6 @@ export class ${input.name}Contract extends ContractBase {
|
|
|
365
323
|
|
|
366
324
|
${storageLayoutGetter}
|
|
367
325
|
|
|
368
|
-
${notesGetter}
|
|
369
|
-
|
|
370
326
|
/** Type-safe wrappers for the public methods exposed by the contract. */
|
|
371
327
|
public declare methods: {
|
|
372
328
|
${methods.join('\n')}
|