@aztec/builder 0.0.1-commit.7b86788 → 0.0.1-commit.7cbc774

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.
@@ -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=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXNjcmlwdC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0LWludGVyZmFjZS1nZW4vdHlwZXNjcmlwdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBR0wsS0FBSyxnQkFBZ0IsRUFZdEIsTUFBTSxtQkFBbUIsQ0FBQztBQTRRM0I7Ozs7O0dBS0c7QUFDSCx3QkFBc0IsbUNBQW1DLENBQUMsS0FBSyxFQUFFLGdCQUFnQixFQUFFLGtCQUFrQixDQUFDLEVBQUUsTUFBTSxtQkFrRDdHIn0=
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXNjcmlwdC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0LWludGVyZmFjZS1nZW4vdHlwZXNjcmlwdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBR0wsS0FBSyxnQkFBZ0IsRUFhdEIsTUFBTSxtQkFBbUIsQ0FBQztBQXVSM0I7Ozs7O0dBS0c7QUFDSCx3QkFBc0IsbUNBQW1DLENBQUMsS0FBSyxFQUFFLGdCQUFnQixFQUFFLGtCQUFrQixDQUFDLEVBQUUsTUFBTSxtQkFrRDdHIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/contract-interface-gen/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EAYtB,MAAM,mBAAmB,CAAC;AA4Q3B;;;;;GAKG;AACH,wBAAsB,mCAAmC,CAAC,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,EAAE,MAAM,mBAkD7G"}
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;AAuR3B;;;;;GAKG;AACH,wBAAsB,mCAAmC,CAAC,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,EAAE,MAAM,mBAkD7G"}
@@ -1,4 +1,4 @@
1
- import { EventSelector, decodeFunctionSignature, getAllFunctionAbis, getDefaultInitializer, isAztecAddressStruct, isBoundedVecStruct, isEthAddressStruct, isFunctionSelectorStruct, isPublicKeysStruct, 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.
@@ -38,6 +38,9 @@ import { EventSelector, decodeFunctionSignature, getAllFunctionAbis, getDefaultI
38
38
  // as a BoundedVec in the ArgumentsEncoder.
39
39
  return `${abiTypeToTypescript(type.fields[0].type)}`;
40
40
  }
41
+ if (isOptionStruct(type)) {
42
+ return `OptionLike<${abiTypeToTypescript(type.fields[1].type)}>`;
43
+ }
41
44
  return `{ ${type.fields.map((f)=>`${f.name}: ${abiTypeToTypescript(f.type)}`).join(', ')} }`;
42
45
  default:
43
46
  throw new Error(`Unknown type ${type.kind}`);
@@ -66,38 +69,46 @@ import { EventSelector, decodeFunctionSignature, getAllFunctionAbis, getDefaultI
66
69
  * @returns A type-safe deploy method in ts.
67
70
  */ function generateDeploy(input) {
68
71
  const ctor = getDefaultInitializer(input);
69
- const args = (ctor?.parameters ?? []).map(generateParameter).join(', ');
72
+ const ctorParams = ctor?.parameters ?? [];
73
+ const args = ctorParams.map(generateParameter).join(', ');
74
+ const argNames = ctorParams.map((p)=>p.name).join(', ');
75
+ const argsForwarding = argNames ? `[${argNames}]` : '[]';
70
76
  const contractName = `${input.name}Contract`;
71
77
  const artifactName = `${contractName}Artifact`;
72
78
  return `
73
79
  /**
74
80
  * Creates a tx to deploy a new instance of this contract.
81
+ * @param instantiation - Optional address-affecting parameters (salt, deployer / universalDeploy, publicKeys).
82
+ * Salt defaults to a random value; the deployer is locked lazily from the first send-time \`from\`.
75
83
  */
76
- public static deploy(wallet: Wallet, ${args}) {
77
- return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(1));
78
- }
79
-
80
- /**
81
- * Creates a tx to deploy a new instance of this contract using the specified public keys hash to derive the address.
82
- */
83
- public static deployWithPublicKeys(publicKeys: PublicKeys, wallet: Wallet, ${args}) {
84
- return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(2));
84
+ public static deploy(wallet: Wallet, ${args ? `${args}, ` : ''}instantiation?: DeployInstantiationOptions) {
85
+ return DeployMethod.create<${contractName}>(
86
+ wallet,
87
+ {
88
+ artifact: ${artifactName},
89
+ postDeployCtor: (instance, wallet) => ${contractName}.at(instance.address, wallet),
90
+ args: ${argsForwarding},
91
+ },
92
+ instantiation,
93
+ );
85
94
  }
86
95
 
87
96
  /**
88
97
  * Creates a tx to deploy a new instance of this contract using the specified constructor method.
89
98
  */
90
99
  public static deployWithOpts<M extends keyof ${contractName}['methods']>(
91
- opts: { publicKeys?: PublicKeys; method?: M; wallet: Wallet },
100
+ opts: { method?: M; wallet: Wallet; instantiation?: DeployInstantiationOptions },
92
101
  ...args: Parameters<${contractName}['methods'][M]>
93
102
  ) {
94
- return new DeployMethod<${contractName}>(
95
- opts.publicKeys ?? PublicKeys.default(),
103
+ return DeployMethod.create<${contractName}>(
96
104
  opts.wallet,
97
- ${artifactName},
98
- (instance, wallet) => ${contractName}.at(instance.address, wallet),
99
- Array.from(arguments).slice(1),
100
- opts.method ?? 'constructor',
105
+ {
106
+ artifact: ${artifactName},
107
+ postDeployCtor: (instance, wallet) => ${contractName}.at(instance.address, wallet),
108
+ args,
109
+ constructorNameOrArtifact: opts.method ?? 'constructor',
110
+ },
111
+ opts.instantiation,
101
112
  );
102
113
  }
103
114
  `;
@@ -250,8 +261,8 @@ async function generateEvents(events) {
250
261
 
251
262
  /* eslint-disable */
252
263
  import { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
253
- 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';
254
- import { Contract, ContractBase, ContractFunctionInteraction, type ContractMethod, type ContractStorageLayout, DeployMethod } from '@aztec/aztec.js/contracts';
264
+ 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';
265
+ import { Contract, ContractBase, ContractFunctionInteraction, type ContractMethod, type ContractStorageLayout, type DeployInstantiationOptions, DeployMethod } from '@aztec/aztec.js/contracts';
255
266
  import { EthAddress } from '@aztec/aztec.js/addresses';
256
267
  import { Fr, Point } from '@aztec/aztec.js/fields';
257
268
  import { type PublicKey, PublicKeys } from '@aztec/aztec.js/keys';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/builder",
3
- "version": "0.0.1-commit.7b86788",
3
+ "version": "0.0.1-commit.7cbc774",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -67,8 +67,8 @@
67
67
  ]
68
68
  },
69
69
  "dependencies": {
70
- "@aztec/foundation": "0.0.1-commit.7b86788",
71
- "@aztec/stdlib": "0.0.1-commit.7b86788",
70
+ "@aztec/foundation": "0.0.1-commit.7cbc774",
71
+ "@aztec/stdlib": "0.0.1-commit.7cbc774",
72
72
  "commander": "^12.1.0"
73
73
  },
74
74
  "devDependencies": {
@@ -11,6 +11,7 @@ import {
11
11
  isBoundedVecStruct,
12
12
  isEthAddressStruct,
13
13
  isFunctionSelectorStruct,
14
+ isOptionStruct,
14
15
  isPublicKeysStruct,
15
16
  isWrappedFieldStruct,
16
17
  } from '@aztec/stdlib/abi';
@@ -55,6 +56,9 @@ function abiTypeToTypescript(type: ABIParameter['type']): string {
55
56
  // as a BoundedVec in the ArgumentsEncoder.
56
57
  return `${abiTypeToTypescript(type.fields[0].type)}`;
57
58
  }
59
+ if (isOptionStruct(type)) {
60
+ return `OptionLike<${abiTypeToTypescript(type.fields[1].type)}>`;
61
+ }
58
62
  return `{ ${type.fields.map(f => `${f.name}: ${abiTypeToTypescript(f.type)}`).join(', ')} }`;
59
63
  default:
60
64
  throw new Error(`Unknown type ${type.kind}`);
@@ -89,39 +93,47 @@ function generateMethod(entry: FunctionAbi) {
89
93
  */
90
94
  function generateDeploy(input: ContractArtifact) {
91
95
  const ctor = getDefaultInitializer(input);
92
- const args = (ctor?.parameters ?? []).map(generateParameter).join(', ');
96
+ const ctorParams = ctor?.parameters ?? [];
97
+ const args = ctorParams.map(generateParameter).join(', ');
98
+ const argNames = ctorParams.map(p => p.name).join(', ');
99
+ const argsForwarding = argNames ? `[${argNames}]` : '[]';
93
100
  const contractName = `${input.name}Contract`;
94
101
  const artifactName = `${contractName}Artifact`;
95
102
 
96
103
  return `
97
104
  /**
98
105
  * Creates a tx to deploy a new instance of this contract.
106
+ * @param instantiation - Optional address-affecting parameters (salt, deployer / universalDeploy, publicKeys).
107
+ * Salt defaults to a random value; the deployer is locked lazily from the first send-time \`from\`.
99
108
  */
100
- public static deploy(wallet: Wallet, ${args}) {
101
- return new DeployMethod<${contractName}>(PublicKeys.default(), wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(1));
102
- }
103
-
104
- /**
105
- * Creates a tx to deploy a new instance of this contract using the specified public keys hash to derive the address.
106
- */
107
- public static deployWithPublicKeys(publicKeys: PublicKeys, wallet: Wallet, ${args}) {
108
- return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, (instance, wallet) => ${contractName}.at(instance.address, wallet), Array.from(arguments).slice(2));
109
+ public static deploy(wallet: Wallet, ${args ? `${args}, ` : ''}instantiation?: DeployInstantiationOptions) {
110
+ return DeployMethod.create<${contractName}>(
111
+ wallet,
112
+ {
113
+ artifact: ${artifactName},
114
+ postDeployCtor: (instance, wallet) => ${contractName}.at(instance.address, wallet),
115
+ args: ${argsForwarding},
116
+ },
117
+ instantiation,
118
+ );
109
119
  }
110
120
 
111
121
  /**
112
122
  * Creates a tx to deploy a new instance of this contract using the specified constructor method.
113
123
  */
114
124
  public static deployWithOpts<M extends keyof ${contractName}['methods']>(
115
- opts: { publicKeys?: PublicKeys; method?: M; wallet: Wallet },
125
+ opts: { method?: M; wallet: Wallet; instantiation?: DeployInstantiationOptions },
116
126
  ...args: Parameters<${contractName}['methods'][M]>
117
127
  ) {
118
- return new DeployMethod<${contractName}>(
119
- opts.publicKeys ?? PublicKeys.default(),
128
+ return DeployMethod.create<${contractName}>(
120
129
  opts.wallet,
121
- ${artifactName},
122
- (instance, wallet) => ${contractName}.at(instance.address, wallet),
123
- Array.from(arguments).slice(1),
124
- opts.method ?? 'constructor',
130
+ {
131
+ artifact: ${artifactName},
132
+ postDeployCtor: (instance, wallet) => ${contractName}.at(instance.address, wallet),
133
+ args,
134
+ constructorNameOrArtifact: opts.method ?? 'constructor',
135
+ },
136
+ opts.instantiation,
125
137
  );
126
138
  }
127
139
  `;
@@ -305,8 +317,8 @@ export async function generateTypescriptContractInterface(input: ContractArtifac
305
317
 
306
318
  /* eslint-disable */
307
319
  import { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
308
- 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';
309
- import { Contract, ContractBase, ContractFunctionInteraction, type ContractMethod, type ContractStorageLayout, DeployMethod } from '@aztec/aztec.js/contracts';
320
+ 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';
321
+ import { Contract, ContractBase, ContractFunctionInteraction, type ContractMethod, type ContractStorageLayout, type DeployInstantiationOptions, DeployMethod } from '@aztec/aztec.js/contracts';
310
322
  import { EthAddress } from '@aztec/aztec.js/addresses';
311
323
  import { Fr, Point } from '@aztec/aztec.js/fields';
312
324
  import { type PublicKey, PublicKeys } from '@aztec/aztec.js/keys';