@aztec/aztec.js 0.0.1-commit.29c6b1a3 → 0.0.1-commit.2c85e299c
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/api/abi.d.ts +2 -2
- package/dest/api/abi.d.ts.map +1 -1
- package/dest/api/contract.d.ts +5 -5
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +3 -3
- package/dest/api/deployment.d.ts +1 -2
- package/dest/api/deployment.d.ts.map +1 -1
- package/dest/api/deployment.js +0 -1
- package/dest/api/events.d.ts +18 -6
- package/dest/api/events.d.ts.map +1 -1
- package/dest/api/events.js +37 -22
- package/dest/api/fields.d.ts +2 -1
- package/dest/api/fields.d.ts.map +1 -1
- package/dest/api/fields.js +1 -0
- package/dest/api/keys.d.ts +1 -1
- package/dest/api/keys.js +1 -1
- package/dest/api/wallet.d.ts +3 -2
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +2 -1
- package/dest/contract/base_contract_interaction.d.ts +3 -3
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/batch_call.d.ts +3 -3
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +17 -8
- package/dest/contract/contract_function_interaction.d.ts +7 -16
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +107 -18
- package/dest/contract/deploy_method.d.ts +37 -12
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +42 -21
- package/dest/contract/get_gas_limits.js +3 -3
- package/dest/contract/interaction_options.d.ts +62 -21
- package/dest/contract/interaction_options.d.ts.map +1 -1
- package/dest/contract/interaction_options.js +33 -0
- package/dest/contract/protocol_contracts/auth-registry.d.ts +1 -1
- package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/auth-registry.js +48 -6
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -22
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/contract-class-registry.js +13 -658
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/contract-instance-registry.js +76 -473
- package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
- package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/fee-juice.js +7 -400
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +1 -1
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/multi-call-entrypoint.js +39 -1
- package/dest/contract/protocol_contracts/public-checks.d.ts +1 -1
- package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/public-checks.js +39 -9
- package/dest/fee/fee_juice_payment_method_with_claim.js +6 -6
- package/dest/fee/private_fee_payment_method.d.ts +2 -1
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +11 -10
- package/dest/fee/public_fee_payment_method.d.ts +2 -1
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +11 -10
- package/dest/fee/sponsored_fee_payment.js +3 -3
- package/dest/utils/abi_types.d.ts +6 -1
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/abi_types.js +1 -1
- package/dest/utils/authwit.d.ts +5 -5
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +10 -6
- package/dest/utils/cross_chain.d.ts +3 -8
- package/dest/utils/cross_chain.d.ts.map +1 -1
- package/dest/utils/cross_chain.js +8 -15
- package/dest/wallet/capabilities.d.ts +452 -0
- package/dest/wallet/capabilities.d.ts.map +1 -0
- package/dest/wallet/capabilities.js +3 -0
- package/dest/wallet/deploy_account_method.d.ts +15 -4
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +26 -0
- package/dest/wallet/index.d.ts +2 -1
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +1 -0
- package/dest/wallet/wallet.d.ts +1663 -89
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +175 -27
- package/package.json +20 -11
- package/src/api/abi.ts +1 -0
- package/src/api/contract.ts +10 -3
- package/src/api/deployment.ts +0 -1
- package/src/api/events.ts +50 -32
- package/src/api/fields.ts +1 -0
- package/src/api/keys.ts +2 -2
- package/src/api/wallet.ts +43 -1
- package/src/contract/base_contract_interaction.ts +3 -2
- package/src/contract/batch_call.ts +17 -14
- package/src/contract/contract_function_interaction.ts +114 -26
- package/src/contract/deploy_method.ts +77 -32
- package/src/contract/get_gas_limits.ts +3 -3
- package/src/contract/interaction_options.ts +96 -23
- package/src/contract/protocol_contracts/auth-registry.ts +10 -2
- package/src/contract/protocol_contracts/contract-class-registry.ts +4 -338
- package/src/contract/protocol_contracts/contract-instance-registry.ts +33 -225
- package/src/contract/protocol_contracts/fee-juice.ts +2 -193
- package/src/contract/protocol_contracts/multi-call-entrypoint.ts +8 -1
- package/src/contract/protocol_contracts/public-checks.ts +8 -3
- package/src/fee/fee_juice_payment_method_with_claim.ts +5 -5
- package/src/fee/private_fee_payment_method.ts +8 -7
- package/src/fee/public_fee_payment_method.ts +9 -8
- package/src/fee/sponsored_fee_payment.ts +3 -3
- package/src/utils/abi_types.ts +7 -0
- package/src/utils/authwit.ts +20 -22
- package/src/utils/cross_chain.ts +9 -18
- package/src/wallet/capabilities.ts +500 -0
- package/src/wallet/deploy_account_method.ts +39 -2
- package/src/wallet/index.ts +1 -0
- package/src/wallet/wallet.ts +230 -39
- package/dest/deployment/broadcast_function.d.ts +0 -24
- package/dest/deployment/broadcast_function.d.ts.map +0 -1
- package/dest/deployment/broadcast_function.js +0 -74
- package/src/deployment/broadcast_function.ts +0 -148
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
2
|
-
import {
|
|
3
|
-
ExecutionPayload,
|
|
4
|
-
TxSimulationResult,
|
|
5
|
-
UtilitySimulationResult,
|
|
6
|
-
mergeExecutionPayloads,
|
|
7
|
-
} from '@aztec/stdlib/tx';
|
|
2
|
+
import { ExecutionPayload, TxSimulationResult, UtilityExecutionResult, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
8
3
|
|
|
9
4
|
import type { BatchedMethod, Wallet } from '../wallet/wallet.js';
|
|
10
5
|
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
11
6
|
import {
|
|
12
7
|
type RequestInteractionOptions,
|
|
13
8
|
type SimulateInteractionOptions,
|
|
9
|
+
emptyOffchainOutput,
|
|
10
|
+
extractOffchainOutput,
|
|
14
11
|
toSimulateOptions,
|
|
15
12
|
} from './interaction_options.js';
|
|
16
13
|
|
|
@@ -42,9 +39,9 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
/**
|
|
45
|
-
* Simulates the batch, supporting private, public and utility functions. Although this is a single
|
|
42
|
+
* Simulates/executes the batch, supporting private, public and utility functions. Although this is a single
|
|
46
43
|
* interaction with the wallet, private and public functions will be grouped into a single ExecutionPayload
|
|
47
|
-
* that the wallet will simulate as a single transaction. Utility function calls will
|
|
44
|
+
* that the wallet will simulate as a single transaction. Utility function calls will be executed
|
|
48
45
|
* one by one.
|
|
49
46
|
* @param options - An optional object containing additional configuration for the interaction.
|
|
50
47
|
* @returns The results of all the interactions that make up the batch
|
|
@@ -81,8 +78,8 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
81
78
|
// Add utility calls to batch
|
|
82
79
|
for (const [call] of utility) {
|
|
83
80
|
batchRequests.push({
|
|
84
|
-
name: '
|
|
85
|
-
args: [call, options
|
|
81
|
+
name: 'executeUtility' as const,
|
|
82
|
+
args: [call, { scope: options.from, authWitnesses: options.authWitnesses }],
|
|
86
83
|
});
|
|
87
84
|
}
|
|
88
85
|
|
|
@@ -111,9 +108,12 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
111
108
|
for (let i = 0; i < utility.length; i++) {
|
|
112
109
|
const [call, resultIndex] = utility[i];
|
|
113
110
|
const wrappedResult = batchResults[i];
|
|
114
|
-
if (wrappedResult.name === '
|
|
115
|
-
const rawReturnValues = (wrappedResult.result as
|
|
116
|
-
results[resultIndex] =
|
|
111
|
+
if (wrappedResult.name === 'executeUtility') {
|
|
112
|
+
const rawReturnValues = (wrappedResult.result as UtilityExecutionResult).result;
|
|
113
|
+
results[resultIndex] = {
|
|
114
|
+
result: rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [],
|
|
115
|
+
...emptyOffchainOutput(),
|
|
116
|
+
};
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -132,7 +132,10 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
132
132
|
? simulatedTx.getPrivateReturnValues()?.nested?.[resultIndex].values
|
|
133
133
|
: simulatedTx.getPublicReturnValues()?.[resultIndex].values;
|
|
134
134
|
|
|
135
|
-
results[callIndex] =
|
|
135
|
+
results[callIndex] = {
|
|
136
|
+
result: rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [],
|
|
137
|
+
...extractOffchainOutput(simulatedTx.offchainEffects),
|
|
138
|
+
};
|
|
136
139
|
});
|
|
137
140
|
}
|
|
138
141
|
}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type ABIParameter,
|
|
3
|
+
type AbiType,
|
|
4
|
+
type FunctionAbi,
|
|
5
|
+
FunctionCall,
|
|
6
|
+
FunctionSelector,
|
|
7
|
+
FunctionType,
|
|
8
|
+
canBeMappedFromNullOrUndefined,
|
|
9
|
+
decodeFromAbi,
|
|
10
|
+
encodeArguments,
|
|
11
|
+
isOptionStruct,
|
|
12
|
+
} from '@aztec/stdlib/abi';
|
|
2
13
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import {
|
|
15
|
+
import type { Capsule, HashedValues, TxProfileResult } from '@aztec/stdlib/tx';
|
|
5
16
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
6
17
|
|
|
7
18
|
import type { Wallet } from '../wallet/wallet.js';
|
|
@@ -11,7 +22,9 @@ import {
|
|
|
11
22
|
type ProfileInteractionOptions,
|
|
12
23
|
type RequestInteractionOptions,
|
|
13
24
|
type SimulateInteractionOptions,
|
|
14
|
-
type
|
|
25
|
+
type SimulationResult,
|
|
26
|
+
emptyOffchainOutput,
|
|
27
|
+
extractOffchainOutput,
|
|
15
28
|
toProfileOptions,
|
|
16
29
|
toSimulateOptions,
|
|
17
30
|
} from './interaction_options.js';
|
|
@@ -31,11 +44,32 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
31
44
|
private extraHashedArgs: HashedValues[] = [],
|
|
32
45
|
) {
|
|
33
46
|
super(wallet, authWitnesses, capsules);
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
// This may feel a bit ad-hoc here, so it warrants a comment. We accept Noir Option<T> parameters, and it's natural
|
|
48
|
+
// to map JS's null/undefined to Noir Option's None. One possible way to deal with null/undefined arguments at this
|
|
49
|
+
// point in the codebase is to conclude that they are accepted since at least one Noir type (ie: Option) can be
|
|
50
|
+
// encoded from them. Then we would let `encode` deal with potential mismatches. I chose not to do that because of
|
|
51
|
+
// the pervasiveness of null/undefined in JS, and how easy it is to inadvertently pass it around. Having this check
|
|
52
|
+
// here allows us to fail at a point where the boundaries and intent are clear.
|
|
53
|
+
if (this.hasInvalidNullOrUndefinedArguments(args)) {
|
|
54
|
+
const signature = formatFunctionSignature(this.functionDao.name, this.functionDao.parameters);
|
|
55
|
+
const received = args.map(formatArg).join(', ');
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Null or undefined arguments are only allowed for Option<T> parameters in ${signature}. Received: (${received}).`,
|
|
58
|
+
);
|
|
36
59
|
}
|
|
37
60
|
}
|
|
38
61
|
|
|
62
|
+
private hasInvalidNullOrUndefinedArguments(args: any[]) {
|
|
63
|
+
return args.some((arg, index) => {
|
|
64
|
+
if (arg !== undefined && arg !== null) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const parameterType = this.functionDao.parameters[index]?.type;
|
|
69
|
+
return !parameterType || !canBeMappedFromNullOrUndefined(parameterType);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
39
73
|
/**
|
|
40
74
|
* Returns the encoded function call wrapped by this interaction
|
|
41
75
|
* Useful when generating authwits
|
|
@@ -43,16 +77,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
43
77
|
*/
|
|
44
78
|
public async getFunctionCall() {
|
|
45
79
|
const args = encodeArguments(this.functionDao, this.args);
|
|
46
|
-
return {
|
|
80
|
+
return FunctionCall.from({
|
|
47
81
|
name: this.functionDao.name,
|
|
48
|
-
|
|
82
|
+
to: this.contractAddress,
|
|
49
83
|
selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
|
|
50
84
|
type: this.functionDao.functionType,
|
|
51
|
-
to: this.contractAddress,
|
|
52
|
-
isStatic: this.functionDao.isStatic,
|
|
53
85
|
hideMsgSender: false /** Only set to `true` for enqueued public function calls */,
|
|
86
|
+
isStatic: this.functionDao.isStatic,
|
|
87
|
+
args,
|
|
54
88
|
returnTypes: this.functionDao.returnTypes,
|
|
55
|
-
};
|
|
89
|
+
});
|
|
56
90
|
}
|
|
57
91
|
|
|
58
92
|
/**
|
|
@@ -90,21 +124,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
90
124
|
* function or a rich object containing extra metadata, such as estimated gas costs (if requested via options),
|
|
91
125
|
* execution statistics and emitted offchain effects
|
|
92
126
|
*/
|
|
93
|
-
public async simulate<T extends SimulateInteractionOptions>(
|
|
94
|
-
options: T,
|
|
95
|
-
): Promise<SimulationReturn<Exclude<T['fee'], undefined>['estimateGas']>>;
|
|
96
|
-
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
97
|
-
public async simulate<T extends SimulateInteractionOptions>(
|
|
98
|
-
options: T,
|
|
99
|
-
): Promise<SimulationReturn<T['includeMetadata']>>;
|
|
100
|
-
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
101
127
|
public async simulate(
|
|
102
|
-
options: SimulateInteractionOptions,
|
|
103
|
-
): Promise<
|
|
128
|
+
options: SimulateInteractionOptions = {} as SimulateInteractionOptions,
|
|
129
|
+
): Promise<SimulationResult> {
|
|
104
130
|
// docs:end:simulate
|
|
105
131
|
if (this.functionDao.functionType == FunctionType.UTILITY) {
|
|
106
132
|
const call = await this.getFunctionCall();
|
|
107
|
-
const utilityResult = await this.wallet.
|
|
133
|
+
const utilityResult = await this.wallet.executeUtility(call, {
|
|
134
|
+
scope: options.from,
|
|
135
|
+
authWitnesses: options.authWitnesses,
|
|
136
|
+
});
|
|
108
137
|
|
|
109
138
|
// Decode the raw field elements to the actual return type
|
|
110
139
|
const returnValue = utilityResult.result ? decodeFromAbi(this.functionDao.returnTypes, utilityResult.result) : [];
|
|
@@ -112,11 +141,11 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
112
141
|
if (options.includeMetadata) {
|
|
113
142
|
return {
|
|
114
143
|
stats: utilityResult.stats,
|
|
144
|
+
...emptyOffchainOutput(),
|
|
115
145
|
result: returnValue,
|
|
116
146
|
};
|
|
117
|
-
} else {
|
|
118
|
-
return returnValue;
|
|
119
147
|
}
|
|
148
|
+
return { result: returnValue, ...emptyOffchainOutput() };
|
|
120
149
|
}
|
|
121
150
|
|
|
122
151
|
const executionPayload = await this.request(options);
|
|
@@ -138,6 +167,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
138
167
|
}
|
|
139
168
|
|
|
140
169
|
const returnValue = rawReturnValues ? decodeFromAbi(this.functionDao.returnTypes, rawReturnValues) : [];
|
|
170
|
+
const offchainOutput = extractOffchainOutput(simulatedTx.offchainEffects);
|
|
141
171
|
|
|
142
172
|
if (options.includeMetadata || options.fee?.estimateGas) {
|
|
143
173
|
const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
|
|
@@ -146,13 +176,12 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
146
176
|
);
|
|
147
177
|
return {
|
|
148
178
|
stats: simulatedTx.stats,
|
|
149
|
-
|
|
179
|
+
...offchainOutput,
|
|
150
180
|
result: returnValue,
|
|
151
181
|
estimatedGas: { gasLimits, teardownGasLimits },
|
|
152
182
|
};
|
|
153
|
-
} else {
|
|
154
|
-
return returnValue;
|
|
155
183
|
}
|
|
184
|
+
return { result: returnValue, ...offchainOutput };
|
|
156
185
|
}
|
|
157
186
|
|
|
158
187
|
/**
|
|
@@ -200,3 +229,62 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
200
229
|
);
|
|
201
230
|
}
|
|
202
231
|
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Render an AbiType as a human readable string
|
|
235
|
+
* */
|
|
236
|
+
function formatAbiType(abiType: AbiType): string {
|
|
237
|
+
switch (abiType.kind) {
|
|
238
|
+
case 'field':
|
|
239
|
+
return 'Field';
|
|
240
|
+
case 'boolean':
|
|
241
|
+
return 'bool';
|
|
242
|
+
case 'integer':
|
|
243
|
+
return `${abiType.sign === 'signed' ? 'i' : 'u'}${abiType.width}`;
|
|
244
|
+
case 'string':
|
|
245
|
+
return `str<${abiType.length}>`;
|
|
246
|
+
case 'array':
|
|
247
|
+
return `[${formatAbiType(abiType.type)}; ${abiType.length}]`;
|
|
248
|
+
case 'struct': {
|
|
249
|
+
if (isOptionStruct(abiType)) {
|
|
250
|
+
const innerType = abiType.fields.find(f => f.name === '_value')!.type;
|
|
251
|
+
return `Option<${formatAbiType(innerType)}>`;
|
|
252
|
+
}
|
|
253
|
+
return `(${abiType.fields.map(f => `${f.name}: ${formatAbiType(f.type)}`).join(', ')})`;
|
|
254
|
+
}
|
|
255
|
+
case 'tuple':
|
|
256
|
+
return `(${abiType.fields.map(formatAbiType).join(', ')})`;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Pretty print a function signature
|
|
262
|
+
*/
|
|
263
|
+
function formatFunctionSignature(name: string, parameters: ABIParameter[]): string {
|
|
264
|
+
const params = parameters.map(p => `${p.name}: ${formatAbiType(p.type)}`).join(', ');
|
|
265
|
+
return `${name}(${params})`;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Non-exhaustive pretty print of JS args to display in error messages in this module
|
|
270
|
+
*/
|
|
271
|
+
function formatArg(arg: unknown): string {
|
|
272
|
+
if (arg === undefined) {
|
|
273
|
+
return 'undefined';
|
|
274
|
+
}
|
|
275
|
+
if (arg === null) {
|
|
276
|
+
return 'null';
|
|
277
|
+
}
|
|
278
|
+
if (typeof arg === 'bigint') {
|
|
279
|
+
return `${arg}n`;
|
|
280
|
+
}
|
|
281
|
+
if (Array.isArray(arg)) {
|
|
282
|
+
return `[${arg.map(formatArg).join(', ')}]`;
|
|
283
|
+
}
|
|
284
|
+
if (typeof arg === 'object') {
|
|
285
|
+
const entries = Object.entries(arg).map(([k, v]) => `${k}: ${formatArg(v)}`);
|
|
286
|
+
return `{ ${entries.join(', ')} }`;
|
|
287
|
+
}
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
289
|
+
return String(arg);
|
|
290
|
+
}
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
getContractInstanceFromInstantiationParams,
|
|
10
10
|
} from '@aztec/stdlib/contract';
|
|
11
11
|
import type { PublicKeys } from '@aztec/stdlib/keys';
|
|
12
|
-
import { type Capsule,
|
|
12
|
+
import { type Capsule, HashedValues, type TxProfileResult, type TxReceipt } from '@aztec/stdlib/tx';
|
|
13
13
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
14
14
|
|
|
15
15
|
import { publishContractClass } from '../deployment/publish_class.js';
|
|
16
16
|
import { publishInstance } from '../deployment/publish_instance.js';
|
|
17
|
-
import type { SendOptions, Wallet } from '../wallet/wallet.js';
|
|
17
|
+
import type { ProfileOptions, SendOptions, SimulateOptions, Wallet } from '../wallet/wallet.js';
|
|
18
18
|
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
19
19
|
import type { ContractBase } from './contract_base.js';
|
|
20
20
|
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
@@ -22,11 +22,15 @@ import { getGasLimits } from './get_gas_limits.js';
|
|
|
22
22
|
import {
|
|
23
23
|
NO_WAIT,
|
|
24
24
|
type NoWait,
|
|
25
|
+
type OffchainOutput,
|
|
25
26
|
type ProfileInteractionOptions,
|
|
26
27
|
type RequestInteractionOptions,
|
|
27
28
|
type SendInteractionOptionsWithoutWait,
|
|
28
29
|
type SimulationInteractionFeeOptions,
|
|
29
|
-
type
|
|
30
|
+
type SimulationResult,
|
|
31
|
+
type TxSendResultImmediate,
|
|
32
|
+
type TxSendResultMined,
|
|
33
|
+
extractOffchainOutput,
|
|
30
34
|
toProfileOptions,
|
|
31
35
|
toSendOptions,
|
|
32
36
|
toSimulateOptions,
|
|
@@ -82,7 +86,7 @@ export type DeployOptionsWithoutWait = Omit<RequestDeployOptions, 'deployer'> &
|
|
|
82
86
|
* is mutually exclusive with "deployer"
|
|
83
87
|
*/
|
|
84
88
|
universalDeploy?: boolean;
|
|
85
|
-
} & Pick<SendInteractionOptionsWithoutWait, 'from' | 'fee'>;
|
|
89
|
+
} & Pick<SendInteractionOptionsWithoutWait, 'from' | 'fee' | 'additionalScopes'>;
|
|
86
90
|
|
|
87
91
|
/**
|
|
88
92
|
* Extends the deployment options with the required parameters to send the transaction.
|
|
@@ -123,20 +127,32 @@ export type DeployTxReceipt<TContract extends ContractBase = ContractBase> = TxR
|
|
|
123
127
|
instance: ContractInstanceWithAddress;
|
|
124
128
|
};
|
|
125
129
|
|
|
130
|
+
/** Wait options that request a full receipt instead of just the contract instance. */
|
|
131
|
+
type WaitWithReturnReceipt = {
|
|
132
|
+
/** Request the full receipt instead of just the contract instance. */
|
|
133
|
+
returnReceipt: true;
|
|
134
|
+
};
|
|
135
|
+
|
|
126
136
|
/**
|
|
127
137
|
* Represents the result type of deploying a contract.
|
|
128
138
|
* - If wait is NO_WAIT, returns TxHash immediately.
|
|
129
139
|
* - If wait has returnReceipt: true, returns DeployTxReceipt after waiting.
|
|
130
140
|
* - Otherwise (undefined or DeployWaitOptions without returnReceipt), returns TContract after waiting.
|
|
131
141
|
*/
|
|
142
|
+
/** Result of deploying a contract when waiting for mining (default case). */
|
|
143
|
+
export type DeployResultMined<TContract extends ContractBase> = {
|
|
144
|
+
/** The deployed contract instance. */
|
|
145
|
+
contract: TContract;
|
|
146
|
+
/** The deploy transaction receipt. */
|
|
147
|
+
receipt: DeployTxReceipt<TContract>;
|
|
148
|
+
} & OffchainOutput;
|
|
149
|
+
|
|
150
|
+
/** Conditional return type for deploy based on wait options. */
|
|
132
151
|
export type DeployReturn<TContract extends ContractBase, W extends DeployInteractionWaitOptions> = W extends NoWait
|
|
133
|
-
?
|
|
134
|
-
: W extends
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
? DeployTxReceipt<TContract>
|
|
139
|
-
: TContract;
|
|
152
|
+
? TxSendResultImmediate
|
|
153
|
+
: W extends WaitWithReturnReceipt
|
|
154
|
+
? TxSendResultMined<DeployTxReceipt<TContract>>
|
|
155
|
+
: DeployResultMined<TContract>;
|
|
140
156
|
|
|
141
157
|
/**
|
|
142
158
|
* Contract interaction for deployment.
|
|
@@ -164,6 +180,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
164
180
|
constructorNameOrArtifact?: string | FunctionArtifact,
|
|
165
181
|
authWitnesses: AuthWitness[] = [],
|
|
166
182
|
capsules: Capsule[] = [],
|
|
183
|
+
private extraHashedArgs: HashedValues[] = [],
|
|
167
184
|
) {
|
|
168
185
|
super(wallet, authWitnesses, capsules);
|
|
169
186
|
this.constructorArtifact = getInitializer(artifact, constructorNameOrArtifact);
|
|
@@ -174,20 +191,29 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
174
191
|
* @param options - Configuration options.
|
|
175
192
|
* @returns The execution payload for this operation
|
|
176
193
|
*/
|
|
177
|
-
public async request(options
|
|
194
|
+
public async request(options: RequestDeployOptions = {}): Promise<ExecutionPayload> {
|
|
178
195
|
const publication = await this.getPublicationExecutionPayload(options);
|
|
179
196
|
|
|
180
197
|
if (!options?.skipRegistration) {
|
|
181
198
|
await this.wallet.registerContract(await this.getInstance(options), this.artifact);
|
|
182
199
|
}
|
|
183
|
-
|
|
200
|
+
const { authWitnesses, capsules } = options;
|
|
201
|
+
|
|
202
|
+
// Propagates the included authwitnesses, capsules, and extraHashedArgs
|
|
203
|
+
// potentially baked into the interaction
|
|
204
|
+
const initialExecutionPayload = new ExecutionPayload(
|
|
205
|
+
[],
|
|
206
|
+
this.authWitnesses.concat(authWitnesses ?? []),
|
|
207
|
+
this.capsules.concat(capsules ?? []),
|
|
208
|
+
this.extraHashedArgs,
|
|
209
|
+
);
|
|
184
210
|
const initialization = await this.getInitializationExecutionPayload(options);
|
|
185
211
|
const feeExecutionPayload = options?.fee?.paymentMethod
|
|
186
212
|
? await options.fee.paymentMethod.getExecutionPayload()
|
|
187
213
|
: undefined;
|
|
188
214
|
const finalExecutionPayload = feeExecutionPayload
|
|
189
|
-
? mergeExecutionPayloads([feeExecutionPayload, publication, initialization])
|
|
190
|
-
: mergeExecutionPayloads([publication, initialization]);
|
|
215
|
+
? mergeExecutionPayloads([initialExecutionPayload, feeExecutionPayload, publication, initialization])
|
|
216
|
+
: mergeExecutionPayloads([initialExecutionPayload, publication, initialization]);
|
|
191
217
|
if (!finalExecutionPayload.calls.length) {
|
|
192
218
|
throw new Error(`No transactions are needed to publish or initialize contract ${this.artifact.name}`);
|
|
193
219
|
}
|
|
@@ -207,7 +233,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
207
233
|
* @param options - Deploy options with wait parameter
|
|
208
234
|
* @returns Send options with wait parameter
|
|
209
235
|
*/
|
|
210
|
-
|
|
236
|
+
protected convertDeployOptionsToSendOptions<W extends DeployInteractionWaitOptions>(
|
|
211
237
|
options: DeployOptions<W>,
|
|
212
238
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
213
239
|
): SendOptions<W extends { returnReceipt: true } ? WaitOpts : W> {
|
|
@@ -219,6 +245,24 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
219
245
|
} as any;
|
|
220
246
|
}
|
|
221
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Converts deploy simulation options into wallet-level simulate options.
|
|
250
|
+
* @param options - The deploy simulation options to convert.
|
|
251
|
+
*/
|
|
252
|
+
protected convertDeployOptionsToSimulateOptions(options: SimulateDeployOptions): SimulateOptions {
|
|
253
|
+
return toSimulateOptions(options);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Converts deploy profile options into wallet-level profile options.
|
|
258
|
+
* @param options - The deploy profile options to convert.
|
|
259
|
+
*/
|
|
260
|
+
protected convertDeployOptionsToProfileOptions(
|
|
261
|
+
options: DeployOptionsWithoutWait & ProfileInteractionOptions,
|
|
262
|
+
): ProfileOptions {
|
|
263
|
+
return toProfileOptions(options);
|
|
264
|
+
}
|
|
265
|
+
|
|
222
266
|
/**
|
|
223
267
|
* Adds this contract to the wallet and returns the Contract object.
|
|
224
268
|
* @param options - Deployment options.
|
|
@@ -308,8 +352,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
308
352
|
* @returns TxHash (if wait is NO_WAIT), TContract (if wait is undefined or doesn't have returnReceipt), or DeployTxReceipt (if wait.returnReceipt is true)
|
|
309
353
|
*/
|
|
310
354
|
// Overload for when wait is not specified at all - returns the contract
|
|
311
|
-
public override send(options: DeployOptionsWithoutWait): Promise<TContract
|
|
312
|
-
// Generic overload for explicit wait values
|
|
355
|
+
public override send(options: DeployOptionsWithoutWait): Promise<DeployResultMined<TContract>>;
|
|
313
356
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
314
357
|
public override send<W extends DeployInteractionWaitOptions>(
|
|
315
358
|
options: DeployOptions<W>,
|
|
@@ -320,12 +363,15 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
320
363
|
const sendOptions = this.convertDeployOptionsToSendOptions(options);
|
|
321
364
|
|
|
322
365
|
if (options.wait === NO_WAIT) {
|
|
323
|
-
const
|
|
324
|
-
this.log.debug(`Sent deployment tx ${txHash.hash} of ${this.artifact.name} contract`);
|
|
325
|
-
return
|
|
366
|
+
const result = await this.wallet.sendTx(executionPayload, sendOptions as SendOptions<NoWait>);
|
|
367
|
+
this.log.debug(`Sent deployment tx ${result.txHash.hash} of ${this.artifact.name} contract`);
|
|
368
|
+
return result;
|
|
326
369
|
}
|
|
327
370
|
|
|
328
|
-
const receipt = await this.wallet.sendTx(
|
|
371
|
+
const { receipt, ...offchainOutput } = await this.wallet.sendTx(
|
|
372
|
+
executionPayload,
|
|
373
|
+
sendOptions as SendOptions<WaitOpts | undefined>,
|
|
374
|
+
);
|
|
329
375
|
this.log.debug(`Deployed ${this.artifact.name} contract in tx ${receipt.txHash}`);
|
|
330
376
|
|
|
331
377
|
// Attach contract instance
|
|
@@ -334,10 +380,10 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
334
380
|
|
|
335
381
|
// Return full receipt if requested, otherwise just the contract
|
|
336
382
|
if (options.wait && typeof options.wait === 'object' && options.wait.returnReceipt) {
|
|
337
|
-
return { ...receipt, contract, instance };
|
|
383
|
+
return { receipt: { ...receipt, contract, instance }, ...offchainOutput };
|
|
338
384
|
}
|
|
339
385
|
|
|
340
|
-
return contract;
|
|
386
|
+
return { contract, receipt, ...offchainOutput };
|
|
341
387
|
}
|
|
342
388
|
|
|
343
389
|
/**
|
|
@@ -366,9 +412,12 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
366
412
|
* @returns A simulation result object containing metadata of the execution, including gas
|
|
367
413
|
* estimations (if requested via options), execution statistics and emitted offchain effects
|
|
368
414
|
*/
|
|
369
|
-
public async simulate(options: SimulateDeployOptions): Promise<
|
|
415
|
+
public async simulate(options: SimulateDeployOptions): Promise<SimulationResult> {
|
|
370
416
|
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
|
|
371
|
-
const simulatedTx = await this.wallet.simulateTx(
|
|
417
|
+
const simulatedTx = await this.wallet.simulateTx(
|
|
418
|
+
executionPayload,
|
|
419
|
+
this.convertDeployOptionsToSimulateOptions(options),
|
|
420
|
+
);
|
|
372
421
|
|
|
373
422
|
const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
|
|
374
423
|
this.log.verbose(
|
|
@@ -376,7 +425,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
376
425
|
);
|
|
377
426
|
return {
|
|
378
427
|
stats: simulatedTx.stats!,
|
|
379
|
-
|
|
428
|
+
...extractOffchainOutput(simulatedTx.offchainEffects),
|
|
380
429
|
result: undefined,
|
|
381
430
|
estimatedGas: { gasLimits, teardownGasLimits },
|
|
382
431
|
};
|
|
@@ -390,11 +439,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
390
439
|
*/
|
|
391
440
|
public async profile(options: DeployOptionsWithoutWait & ProfileInteractionOptions): Promise<TxProfileResult> {
|
|
392
441
|
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
|
|
393
|
-
return await this.wallet.profileTx(executionPayload,
|
|
394
|
-
...toProfileOptions(options),
|
|
395
|
-
profileMode: options.profileMode,
|
|
396
|
-
skipProofGeneration: options.skipProofGeneration,
|
|
397
|
-
});
|
|
442
|
+
return await this.wallet.profileTx(executionPayload, this.convertDeployOptionsToProfileOptions(options));
|
|
398
443
|
}
|
|
399
444
|
|
|
400
445
|
/** Return this deployment address. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { Gas } from '@aztec/stdlib/gas';
|
|
3
3
|
import type { TxSimulationResult } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
@@ -23,8 +23,8 @@ export function getGasLimits(
|
|
|
23
23
|
const gasLimits = simulationResult.gasUsed.totalGas.mul(1 + pad);
|
|
24
24
|
const teardownGasLimits = simulationResult.gasUsed.teardownGas.mul(1 + pad);
|
|
25
25
|
|
|
26
|
-
if (gasLimits.l2Gas >
|
|
27
|
-
throw new Error('Transaction consumes more gas than the
|
|
26
|
+
if (gasLimits.l2Gas > MAX_PROCESSABLE_L2_GAS) {
|
|
27
|
+
throw new Error('Transaction consumes more l2 gas than the maximum processable gas');
|
|
28
28
|
}
|
|
29
29
|
return {
|
|
30
30
|
gasLimits,
|