@aztec/aztec.js 0.78.1 → 0.80.0
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/account_manager/deploy_account_method.d.ts +2 -2
- package/dest/account_manager/deploy_account_method.d.ts.map +1 -1
- package/dest/account_manager/deploy_account_method.js +14 -21
- package/dest/account_manager/index.d.ts +2 -3
- package/dest/account_manager/index.d.ts.map +1 -1
- package/dest/account_manager/index.js +1 -1
- package/dest/api/abi.d.ts +1 -1
- package/dest/api/abi.d.ts.map +1 -1
- package/dest/api/abi.js +1 -1
- package/dest/api/account.d.ts +1 -1
- package/dest/api/account.d.ts.map +1 -1
- package/dest/{contract/index.d.ts → api/contract.d.ts} +9 -8
- package/dest/api/contract.d.ts.map +1 -0
- package/dest/{contract/index.js → api/contract.js} +8 -7
- package/dest/api/deployment.d.ts +1 -0
- package/dest/api/deployment.d.ts.map +1 -1
- package/dest/api/deployment.js +1 -0
- package/dest/api/ethereum.d.ts +3 -0
- package/dest/api/ethereum.d.ts.map +1 -0
- package/dest/api/ethereum.js +2 -0
- package/dest/api/{interfaces/pxe.d.ts → interfaces.d.ts} +1 -1
- package/dest/api/interfaces.d.ts.map +1 -0
- package/dest/api/rpc.d.ts +3 -0
- package/dest/api/rpc.d.ts.map +1 -0
- package/dest/api/rpc.js +2 -0
- package/dest/api/testing.d.ts +6 -0
- package/dest/api/testing.d.ts.map +1 -0
- package/dest/api/testing.js +5 -0
- package/dest/api/utils.d.ts +8 -0
- package/dest/api/utils.d.ts.map +1 -0
- package/dest/api/utils.js +6 -0
- package/dest/api/wallet.d.ts +1 -1
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +1 -1
- package/dest/contract/base_contract_interaction.d.ts +41 -3
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +39 -1
- package/dest/contract/batch_call.d.ts +25 -6
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +62 -25
- package/dest/contract/checker.d.ts +1 -1
- package/dest/contract/checker.d.ts.map +1 -1
- package/dest/contract/checker.js +2 -2
- package/dest/contract/contract.d.ts +1 -1
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract_base.d.ts +1 -1
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_base.js +2 -2
- package/dest/contract/contract_function_interaction.d.ts +8 -6
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +33 -25
- package/dest/contract/deploy_method.d.ts +6 -5
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +26 -50
- package/dest/contract/deploy_proven_tx.d.ts +1 -1
- package/dest/contract/deploy_proven_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.d.ts +1 -1
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/protocol_contracts.d.ts +1 -1
- package/dest/contract/protocol_contracts.d.ts.map +1 -1
- package/dest/contract/proven_tx.d.ts +1 -1
- package/dest/contract/proven_tx.d.ts.map +1 -1
- package/dest/contract/unsafe_contract.d.ts +1 -1
- package/dest/contract/unsafe_contract.d.ts.map +1 -1
- package/dest/entrypoint/entrypoint.d.ts +4 -0
- package/dest/entrypoint/entrypoint.d.ts.map +1 -1
- package/dest/entrypoint/entrypoint.js +16 -0
- package/dest/ethereum/l1_contracts.d.ts.map +1 -0
- package/dest/{api/ethereum → ethereum}/l1_contracts.js +1 -1
- package/dest/{api/ethereum → ethereum}/portal_manager.d.ts +1 -1
- package/dest/ethereum/portal_manager.d.ts.map +1 -0
- package/dest/{api/ethereum → ethereum}/portal_manager.js +4 -1
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +1 -1
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +1 -1
- package/dest/index.d.ts +7 -13
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -14
- package/dest/test/anvil_test_watcher.d.ts.map +1 -0
- package/dest/{api/ethereum → test}/anvil_test_watcher.js +2 -2
- package/dest/{utils/aztec_cheatcodes.d.ts → test/aztec_cheat_codes.d.ts} +1 -1
- package/dest/test/aztec_cheat_codes.d.ts.map +1 -0
- package/dest/{api → test}/cheat_codes.d.ts +2 -2
- package/dest/test/cheat_codes.d.ts.map +1 -0
- package/dest/{api → test}/cheat_codes.js +2 -2
- package/dest/{api/ethereum/cheat_codes.d.ts → test/rollup_cheat_codes.d.ts} +2 -3
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/{api/ethereum/cheat_codes.js → test/rollup_cheat_codes.js} +2 -4
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +1 -1
- package/dest/utils/fee_juice.d.ts +1 -1
- package/dest/utils/fee_juice.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +1 -1
- package/package.json +14 -13
- package/src/account_manager/deploy_account_method.ts +12 -31
- package/src/account_manager/index.ts +1 -1
- package/src/api/abi.ts +15 -0
- package/src/api/account.ts +1 -1
- package/src/{contract/index.ts → api/contract.ts} +21 -7
- package/src/api/deployment.ts +1 -0
- package/src/api/ethereum.ts +11 -0
- package/src/api/rpc.ts +2 -0
- package/src/api/testing.ts +5 -0
- package/src/{utils/index.ts → api/utils.ts} +7 -7
- package/src/api/wallet.ts +1 -7
- package/src/contract/base_contract_interaction.ts +60 -3
- package/src/contract/batch_call.ts +63 -21
- package/src/contract/checker.ts +8 -3
- package/src/contract/contract.ts +1 -1
- package/src/contract/contract_base.ts +4 -3
- package/src/contract/contract_function_interaction.ts +35 -25
- package/src/contract/deploy_method.ts +23 -37
- package/src/contract/deploy_proven_tx.ts +1 -1
- package/src/contract/deploy_sent_tx.ts +1 -1
- package/src/contract/protocol_contracts.ts +1 -1
- package/src/contract/proven_tx.ts +1 -1
- package/src/contract/unsafe_contract.ts +1 -1
- package/src/entrypoint/entrypoint.ts +21 -0
- package/src/{api/ethereum → ethereum}/l1_contracts.ts +1 -1
- package/src/{api/ethereum → ethereum}/portal_manager.ts +4 -1
- package/src/fee/fee_juice_payment_method_with_claim.ts +1 -1
- package/src/fee/public_fee_payment_method.ts +1 -1
- package/src/index.ts +7 -27
- package/src/{api/ethereum → test}/anvil_test_watcher.ts +2 -2
- package/src/{api → test}/cheat_codes.ts +2 -2
- package/src/{api/ethereum/cheat_codes.ts → test/rollup_cheat_codes.ts} +2 -4
- package/src/utils/authwit.ts +2 -1
- package/src/utils/fee_juice.ts +1 -2
- package/src/wallet/account_wallet.ts +1 -1
- package/dest/api/cheat_codes.d.ts.map +0 -1
- package/dest/api/ethereum/anvil_test_watcher.d.ts.map +0 -1
- package/dest/api/ethereum/chain_monitor.d.ts +0 -25
- package/dest/api/ethereum/chain_monitor.d.ts.map +0 -1
- package/dest/api/ethereum/chain_monitor.js +0 -74
- package/dest/api/ethereum/cheat_codes.d.ts.map +0 -1
- package/dest/api/ethereum/index.d.ts +0 -7
- package/dest/api/ethereum/index.d.ts.map +0 -1
- package/dest/api/ethereum/index.js +0 -6
- package/dest/api/ethereum/l1_contracts.d.ts.map +0 -1
- package/dest/api/ethereum/portal_manager.d.ts.map +0 -1
- package/dest/api/interfaces/pxe.d.ts.map +0 -1
- package/dest/contract/index.d.ts.map +0 -1
- package/dest/deployment/index.d.ts +0 -2
- package/dest/deployment/index.d.ts.map +0 -1
- package/dest/deployment/index.js +0 -1
- package/dest/rpc_clients/index.d.ts +0 -3
- package/dest/rpc_clients/index.d.ts.map +0 -1
- package/dest/rpc_clients/index.js +0 -2
- package/dest/utils/aztec_cheatcodes.d.ts.map +0 -1
- package/dest/utils/index.d.ts +0 -8
- package/dest/utils/index.d.ts.map +0 -1
- package/dest/utils/index.js +0 -6
- package/src/api/ethereum/chain_monitor.ts +0 -88
- package/src/api/ethereum/index.ts +0 -19
- package/src/deployment/index.ts +0 -1
- package/src/rpc_clients/index.ts +0 -2
- /package/dest/api/{interfaces/pxe.js → interfaces.js} +0 -0
- /package/dest/{api/ethereum → ethereum}/l1_contracts.d.ts +0 -0
- /package/dest/{api/ethereum → test}/anvil_test_watcher.d.ts +0 -0
- /package/dest/{utils/aztec_cheatcodes.js → test/aztec_cheat_codes.js} +0 -0
- /package/src/api/{interfaces/pxe.ts → interfaces.ts} +0 -0
- /package/src/{utils/aztec_cheatcodes.ts → test/aztec_cheat_codes.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { generatePublicKey } from '
|
|
1
|
+
export { generatePublicKey } from '../utils/pub_key.js';
|
|
2
2
|
export {
|
|
3
3
|
type AztecAddressLike,
|
|
4
4
|
type EthAddressLike,
|
|
@@ -7,15 +7,15 @@ export {
|
|
|
7
7
|
type FunctionSelectorLike,
|
|
8
8
|
type U128Like,
|
|
9
9
|
type WrappedFieldLike,
|
|
10
|
-
} from '
|
|
10
|
+
} from '../utils/abi_types.js';
|
|
11
11
|
export {
|
|
12
12
|
computeAuthWitMessageHash,
|
|
13
13
|
computeInnerAuthWitHash,
|
|
14
14
|
computeInnerAuthWitHashFromAction,
|
|
15
15
|
type IntentAction,
|
|
16
16
|
type IntentInnerHash,
|
|
17
|
-
} from '
|
|
18
|
-
export { waitForPXE } from '
|
|
19
|
-
export { waitForNode, createAztecNodeClient, type AztecNode } from '
|
|
20
|
-
export { getFeeJuiceBalance } from '
|
|
21
|
-
export { readFieldCompressedString } from '
|
|
17
|
+
} from '../utils/authwit.js';
|
|
18
|
+
export { waitForPXE } from '../utils/pxe.js';
|
|
19
|
+
export { waitForNode, createAztecNodeClient, type AztecNode } from '../utils/node.js';
|
|
20
|
+
export { getFeeJuiceBalance } from '../utils/fee_juice.js';
|
|
21
|
+
export { readFieldCompressedString } from '../utils/field_compressed_string.js';
|
package/src/api/wallet.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
AccountWallet,
|
|
3
|
-
AccountWalletWithSecretKey as AccountWalletWithSecretKey,
|
|
4
|
-
SignerlessWallet,
|
|
5
|
-
type Wallet,
|
|
6
|
-
getWallet,
|
|
7
|
-
} from '../wallet/index.js';
|
|
1
|
+
export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet, getWallet } from '../wallet/index.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
4
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
4
|
-
import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { Capsule, HashedValues, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
6
7
|
import type { Wallet } from '../account/wallet.js';
|
|
7
8
|
import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js';
|
|
@@ -33,7 +34,9 @@ export type SendMethodOptions = {
|
|
|
33
34
|
export abstract class BaseContractInteraction {
|
|
34
35
|
protected log = createLogger('aztecjs:contract_interaction');
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
protected authWitnesses: AuthWitness[] = [];
|
|
38
|
+
protected hashedArguments: HashedValues[] = [];
|
|
39
|
+
protected capsules: Capsule[] = [];
|
|
37
40
|
|
|
38
41
|
constructor(protected wallet: Wallet) {}
|
|
39
42
|
|
|
@@ -44,6 +47,14 @@ export abstract class BaseContractInteraction {
|
|
|
44
47
|
*/
|
|
45
48
|
public abstract create(options?: SendMethodOptions): Promise<TxExecutionRequest>;
|
|
46
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Returns an execution request that represents this operation.
|
|
52
|
+
* Can be used as a building block for constructing batch requests.
|
|
53
|
+
* @param options - An optional object containing additional configuration for the transaction.
|
|
54
|
+
* @returns An execution request wrapped in promise.
|
|
55
|
+
*/
|
|
56
|
+
public abstract request(options?: SendMethodOptions): Promise<Omit<ExecutionRequestInit, 'fee'>>;
|
|
57
|
+
|
|
47
58
|
/**
|
|
48
59
|
* Creates a transaction execution request, simulates and proves it. Differs from .prove in
|
|
49
60
|
* that its result does not include the wallet nor the composed tx object, but only the proving result.
|
|
@@ -167,6 +178,52 @@ export abstract class BaseContractInteraction {
|
|
|
167
178
|
return { gasSettings, paymentMethod };
|
|
168
179
|
}
|
|
169
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Add authWitness used in this contract interaction.
|
|
183
|
+
* @param authWitness - authWitness used in the contract interaction.
|
|
184
|
+
*/
|
|
185
|
+
public addAuthWitness(authWitness: AuthWitness) {
|
|
186
|
+
this.authWitnesses.push(authWitness);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Add authWitness used in this contract interaction.
|
|
191
|
+
* @param authWitnesses - authWitnesses used in the contract interaction.
|
|
192
|
+
*/
|
|
193
|
+
public addAuthWitnesses(authWitnesses: AuthWitness[]) {
|
|
194
|
+
this.authWitnesses.push(...authWitnesses);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Return all authWitnesses added for this interaction.
|
|
199
|
+
*/
|
|
200
|
+
public getAuthWitnesses() {
|
|
201
|
+
return this.authWitnesses;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Add hashedArgument used in this contract interaction.
|
|
206
|
+
* @param hashedArgument - hashedArgument used in the contract interaction.
|
|
207
|
+
*/
|
|
208
|
+
public addHashedArgument(hashedArgument: HashedValues) {
|
|
209
|
+
this.hashedArguments.push(hashedArgument);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Add hashedArguments used in this contract interaction.
|
|
214
|
+
* @param hashedArguments - hashedArguments used in the contract interaction.
|
|
215
|
+
*/
|
|
216
|
+
public addHashedArguments(hashedArguments: HashedValues[]) {
|
|
217
|
+
this.hashedArguments.push(...hashedArguments);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Return all hashedArguments added for this interaction.
|
|
222
|
+
*/
|
|
223
|
+
public getHashedArguments() {
|
|
224
|
+
return this.hashedArguments;
|
|
225
|
+
}
|
|
226
|
+
|
|
170
227
|
/**
|
|
171
228
|
* Add data passed to the oracle calls during this contract interaction.
|
|
172
229
|
* @param capsule - Data passed to oracle calls.
|
|
@@ -184,7 +241,7 @@ export abstract class BaseContractInteraction {
|
|
|
184
241
|
}
|
|
185
242
|
|
|
186
243
|
/**
|
|
187
|
-
* Return all capsules added for this
|
|
244
|
+
* Return all capsules added for this contract interaction.
|
|
188
245
|
*/
|
|
189
246
|
public getCapsules() {
|
|
190
247
|
return this.capsules;
|
|
@@ -1,27 +1,41 @@
|
|
|
1
1
|
import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
3
3
|
|
|
4
|
-
import type { Wallet } from '../account/
|
|
4
|
+
import type { Wallet } from '../account/wallet.js';
|
|
5
|
+
import { type ExecutionRequestInit, mergeExecutionRequestInits } from '../entrypoint/entrypoint.js';
|
|
5
6
|
import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
|
|
6
7
|
import type { SimulateMethodOptions } from './contract_function_interaction.js';
|
|
7
8
|
|
|
8
9
|
/** A batch of function calls to be sent as a single transaction through a wallet. */
|
|
9
10
|
export class BatchCall extends BaseContractInteraction {
|
|
10
|
-
constructor(wallet: Wallet, protected calls:
|
|
11
|
+
constructor(wallet: Wallet, protected calls: BaseContractInteraction[]) {
|
|
11
12
|
super(wallet);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Create a transaction execution request that represents this batch, encoded and authenticated by the
|
|
16
17
|
* user's wallet, ready to be simulated.
|
|
17
|
-
* @param
|
|
18
|
+
* @param options - An optional object containing additional configuration for the transaction.
|
|
18
19
|
* @returns A Promise that resolves to a transaction instance.
|
|
19
20
|
*/
|
|
20
|
-
public async create(
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const fee
|
|
24
|
-
|
|
21
|
+
public async create(options: SendMethodOptions = {}): Promise<TxExecutionRequest> {
|
|
22
|
+
const requestWithoutFee = await this.request(options);
|
|
23
|
+
|
|
24
|
+
const { fee: userFee } = options;
|
|
25
|
+
const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee });
|
|
26
|
+
|
|
27
|
+
return await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns an execution request that represents this operation.
|
|
32
|
+
* @param options - An optional object containing additional configuration for the transaction.
|
|
33
|
+
* @returns An execution request wrapped in promise.
|
|
34
|
+
*/
|
|
35
|
+
public async request(options: SendMethodOptions = {}): Promise<Omit<ExecutionRequestInit, 'fee'>> {
|
|
36
|
+
const requests = await this.getRequests();
|
|
37
|
+
const { nonce, cancellable } = options;
|
|
38
|
+
return mergeExecutionRequestInits(requests, { nonce, cancellable });
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
/**
|
|
@@ -34,35 +48,37 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
34
48
|
* @returns The result of the transaction as returned by the contract function.
|
|
35
49
|
*/
|
|
36
50
|
public async simulate(options: SimulateMethodOptions = {}): Promise<any> {
|
|
37
|
-
const {
|
|
51
|
+
const { indexedRequests, unconstrained } = (await this.getRequests()).reduce<{
|
|
38
52
|
/** Keep track of the number of private calls to retrieve the return values */
|
|
39
53
|
privateIndex: 0;
|
|
40
54
|
/** Keep track of the number of public calls to retrieve the return values */
|
|
41
55
|
publicIndex: 0;
|
|
42
|
-
/** The public and private function
|
|
43
|
-
|
|
56
|
+
/** The public and private function execution requests in the batch */
|
|
57
|
+
indexedRequests: [Omit<ExecutionRequestInit, 'fee'>, number, number][];
|
|
44
58
|
/** The unconstrained function calls in the batch. */
|
|
45
59
|
unconstrained: [FunctionCall, number][];
|
|
46
60
|
}>(
|
|
47
61
|
(acc, current, index) => {
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
const call = current.calls[0];
|
|
63
|
+
if (call.type === FunctionType.UNCONSTRAINED) {
|
|
64
|
+
acc.unconstrained.push([call, index]);
|
|
50
65
|
} else {
|
|
51
|
-
acc.
|
|
66
|
+
acc.indexedRequests.push([
|
|
52
67
|
current,
|
|
53
68
|
index,
|
|
54
|
-
|
|
69
|
+
call.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++,
|
|
55
70
|
]);
|
|
56
71
|
}
|
|
57
72
|
return acc;
|
|
58
73
|
},
|
|
59
|
-
{
|
|
74
|
+
{ indexedRequests: [], unconstrained: [], publicIndex: 0, privateIndex: 0 },
|
|
60
75
|
);
|
|
61
76
|
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const fee
|
|
65
|
-
const
|
|
77
|
+
const requests = indexedRequests.map(([request]) => request);
|
|
78
|
+
const requestWithoutFee = mergeExecutionRequestInits(requests);
|
|
79
|
+
const { fee: userFee } = options;
|
|
80
|
+
const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee });
|
|
81
|
+
const txRequest = await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee });
|
|
66
82
|
|
|
67
83
|
const unconstrainedCalls = unconstrained.map(
|
|
68
84
|
async ([call, index]) =>
|
|
@@ -79,7 +95,8 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
79
95
|
unconstrainedResults.forEach(([result, index]) => {
|
|
80
96
|
results[index] = result;
|
|
81
97
|
});
|
|
82
|
-
|
|
98
|
+
indexedRequests.forEach(([request, callIndex, resultIndex]) => {
|
|
99
|
+
const call = request.calls[0];
|
|
83
100
|
// As account entrypoints are private, for private functions we retrieve the return values from the first nested call
|
|
84
101
|
// since we're interested in the first set of values AFTER the account entrypoint
|
|
85
102
|
// For public functions we retrieve the first values directly from the public output.
|
|
@@ -92,4 +109,29 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
92
109
|
});
|
|
93
110
|
return results;
|
|
94
111
|
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Return all authWitnesses added for this interaction.
|
|
115
|
+
*/
|
|
116
|
+
public override getAuthWitnesses() {
|
|
117
|
+
return [this.authWitnesses, ...this.calls.map(c => c.getAuthWitnesses())].flat();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Return all hashedArguments added for this interaction.
|
|
122
|
+
*/
|
|
123
|
+
public override getHashedArguments() {
|
|
124
|
+
return [this.hashedArguments, ...this.calls.map(c => c.getHashedArguments())].flat();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Return all capsules added for this interaction.
|
|
129
|
+
*/
|
|
130
|
+
public override getCapsules() {
|
|
131
|
+
return [this.capsules, ...this.calls.map(c => c.getCapsules())].flat();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private async getRequests() {
|
|
135
|
+
return await Promise.all(this.calls.map(c => c.request()));
|
|
136
|
+
}
|
|
95
137
|
}
|
package/src/contract/checker.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type AbiType,
|
|
3
|
+
type BasicType,
|
|
4
|
+
type ContractArtifact,
|
|
5
|
+
type StructType,
|
|
6
|
+
getDefaultInitializer,
|
|
7
|
+
} from '@aztec/stdlib/abi';
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* Represents a type derived from input type T with the 'kind' property removed.
|
|
@@ -38,8 +44,7 @@ export function abiChecker(artifact: ContractArtifact) {
|
|
|
38
44
|
});
|
|
39
45
|
});
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
if (!artifact.functions.find(func => func.name === 'constructor')) {
|
|
47
|
+
if (!getDefaultInitializer(artifact)) {
|
|
43
48
|
throw new Error('ABI has no constructor');
|
|
44
49
|
}
|
|
45
50
|
|
package/src/contract/contract.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
3
3
|
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
4
4
|
import { PublicKeys } from '@aztec/stdlib/keys';
|
|
5
5
|
|
|
6
|
-
import type { Wallet } from '../account/
|
|
6
|
+
import type { Wallet } from '../account/wallet.js';
|
|
7
7
|
import { ContractBase } from './contract_base.js';
|
|
8
8
|
import { DeployMethod } from './deploy_method.js';
|
|
9
9
|
|
|
@@ -2,12 +2,13 @@ import {
|
|
|
2
2
|
type ContractArtifact,
|
|
3
3
|
type ContractNote,
|
|
4
4
|
type FieldLayout,
|
|
5
|
-
type
|
|
5
|
+
type FunctionAbi,
|
|
6
6
|
FunctionSelector,
|
|
7
|
+
getAllFunctionAbis,
|
|
7
8
|
} from '@aztec/stdlib/abi';
|
|
8
9
|
import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
|
|
9
10
|
|
|
10
|
-
import type { Wallet } from '../account/
|
|
11
|
+
import type { Wallet } from '../account/wallet.js';
|
|
11
12
|
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -52,7 +53,7 @@ export class ContractBase {
|
|
|
52
53
|
/** The wallet used for interacting with this contract. */
|
|
53
54
|
public wallet: Wallet,
|
|
54
55
|
) {
|
|
55
|
-
artifact.
|
|
56
|
+
getAllFunctionAbis(artifact).forEach((f: FunctionAbi) => {
|
|
56
57
|
const interactionFunction = (...args: any[]) => {
|
|
57
58
|
return new ContractFunctionInteraction(this.wallet, this.instance.address, f, args);
|
|
58
59
|
};
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type FunctionAbi,
|
|
3
|
-
FunctionCall,
|
|
4
|
-
FunctionSelector,
|
|
5
|
-
FunctionType,
|
|
6
|
-
decodeFromAbi,
|
|
7
|
-
encodeArguments,
|
|
8
|
-
} from '@aztec/stdlib/abi';
|
|
1
|
+
import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi';
|
|
9
2
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
3
|
import type { PrivateKernelProverProfileResult } from '@aztec/stdlib/kernel';
|
|
11
4
|
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
12
5
|
|
|
13
6
|
import type { Wallet } from '../account/wallet.js';
|
|
7
|
+
import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js';
|
|
14
8
|
import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
|
|
15
9
|
import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
|
|
16
10
|
|
|
@@ -59,38 +53,54 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
59
53
|
/**
|
|
60
54
|
* Create a transaction execution request that represents this call, encoded and authenticated by the
|
|
61
55
|
* user's wallet, ready to be simulated.
|
|
62
|
-
* @param
|
|
56
|
+
* @param options - An optional object containing additional configuration for the transaction.
|
|
63
57
|
* @returns A Promise that resolves to a transaction instance.
|
|
64
58
|
*/
|
|
65
|
-
public async create(
|
|
59
|
+
public async create(options: SendMethodOptions = {}): Promise<TxExecutionRequest> {
|
|
66
60
|
// docs:end:create
|
|
67
61
|
if (this.functionDao.functionType === FunctionType.UNCONSTRAINED) {
|
|
68
62
|
throw new Error("Can't call `create` on an unconstrained function.");
|
|
69
63
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const fee
|
|
73
|
-
const {
|
|
74
|
-
|
|
64
|
+
const requestWithoutFee = await this.request(options);
|
|
65
|
+
|
|
66
|
+
const { fee: userFee } = options;
|
|
67
|
+
const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee });
|
|
68
|
+
|
|
69
|
+
return await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee });
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
// docs:start:request
|
|
78
73
|
/**
|
|
79
|
-
* Returns an execution request that represents this operation.
|
|
80
|
-
* block for constructing batch requests.
|
|
74
|
+
* Returns an execution request that represents this operation.
|
|
75
|
+
* Can be used as a building block for constructing batch requests.
|
|
76
|
+
* @param options - An optional object containing additional configuration for the transaction.
|
|
81
77
|
* @returns An execution request wrapped in promise.
|
|
82
78
|
*/
|
|
83
|
-
public async request(): Promise<
|
|
79
|
+
public async request(options: SendMethodOptions = {}): Promise<Omit<ExecutionRequestInit, 'fee'>> {
|
|
84
80
|
// docs:end:request
|
|
85
81
|
const args = encodeArguments(this.functionDao, this.args);
|
|
82
|
+
const calls = [
|
|
83
|
+
{
|
|
84
|
+
name: this.functionDao.name,
|
|
85
|
+
args,
|
|
86
|
+
selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
|
|
87
|
+
type: this.functionDao.functionType,
|
|
88
|
+
to: this.contractAddress,
|
|
89
|
+
isStatic: this.functionDao.isStatic,
|
|
90
|
+
returnTypes: this.functionDao.returnTypes,
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
const authWitnesses = this.getAuthWitnesses();
|
|
94
|
+
const hashedArguments = this.getHashedArguments();
|
|
95
|
+
const capsules = this.getCapsules();
|
|
96
|
+
const { nonce, cancellable } = options;
|
|
86
97
|
return {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
returnTypes: this.functionDao.returnTypes,
|
|
98
|
+
calls,
|
|
99
|
+
authWitnesses,
|
|
100
|
+
hashedArguments,
|
|
101
|
+
capsules,
|
|
102
|
+
nonce,
|
|
103
|
+
cancellable,
|
|
94
104
|
};
|
|
95
105
|
}
|
|
96
106
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { type ContractArtifact, type
|
|
2
|
+
import { type ContractArtifact, type FunctionAbi, type FunctionArtifact, getInitializer } from '@aztec/stdlib/abi';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import {
|
|
5
5
|
type ContractInstanceWithAddress,
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
} from '@aztec/stdlib/contract';
|
|
10
10
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
11
11
|
import type { PublicKeys } from '@aztec/stdlib/keys';
|
|
12
|
-
import type {
|
|
12
|
+
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
13
13
|
|
|
14
|
-
import type { Wallet } from '../account/
|
|
14
|
+
import type { Wallet } from '../account/wallet.js';
|
|
15
15
|
import { deployInstance } from '../deployment/deploy_instance.js';
|
|
16
16
|
import { registerContractClass } from '../deployment/register_class.js';
|
|
17
|
-
import type
|
|
17
|
+
import { type ExecutionRequestInit, mergeExecutionRequestInits } from '../entrypoint/entrypoint.js';
|
|
18
18
|
import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
|
|
19
19
|
import type { Contract } from './contract.js';
|
|
20
20
|
import type { ContractBase } from './contract_base.js';
|
|
@@ -51,7 +51,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
51
51
|
private instance?: ContractInstanceWithAddress = undefined;
|
|
52
52
|
|
|
53
53
|
/** Constructor function to call. */
|
|
54
|
-
private constructorArtifact:
|
|
54
|
+
private constructorArtifact: FunctionAbi | undefined;
|
|
55
55
|
|
|
56
56
|
constructor(
|
|
57
57
|
private publicKeys: PublicKeys,
|
|
@@ -75,7 +75,9 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
75
75
|
* @returns A Promise resolving to an object containing the signed transaction data and other relevant information.
|
|
76
76
|
*/
|
|
77
77
|
public async create(options: DeployOptions = {}): Promise<TxExecutionRequest> {
|
|
78
|
-
|
|
78
|
+
const requestWithoutFee = await this.request(options);
|
|
79
|
+
const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: options.fee });
|
|
80
|
+
return this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee });
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
// REFACTOR: Having a `request` method with different semantics than the ones in the other
|
|
@@ -89,7 +91,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
89
91
|
* @remarks This method does not have the same return type as the `request` in the ContractInteraction object,
|
|
90
92
|
* it returns a promise for an array instead of a function call directly.
|
|
91
93
|
*/
|
|
92
|
-
public async request(options: DeployOptions = {}): Promise<ExecutionRequestInit
|
|
94
|
+
public async request(options: DeployOptions = {}): Promise<Omit<ExecutionRequestInit, 'fee'>> {
|
|
93
95
|
const deployment = await this.getDeploymentFunctionCalls(options);
|
|
94
96
|
|
|
95
97
|
// NOTE: MEGA HACK. Remove with #10007
|
|
@@ -105,20 +107,13 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
105
107
|
|
|
106
108
|
const bootstrap = await this.getInitializeFunctionCalls(options);
|
|
107
109
|
|
|
108
|
-
|
|
110
|
+
const requests = await Promise.all([...deployment, ...bootstrap].map(c => c.request()));
|
|
111
|
+
if (!requests.length) {
|
|
109
112
|
throw new Error(`No function calls needed to deploy contract ${this.artifact.name}`);
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
const hashedArguments = [...(deployment.hashedArguments ?? []), ...(bootstrap.hashedArguments ?? [])];
|
|
115
|
-
const capsules = [...(deployment.capsules ?? []), ...(bootstrap.capsules ?? [])];
|
|
116
|
-
const { cancellable, nonce, fee: userFee } = options;
|
|
117
|
-
|
|
118
|
-
const request = { calls, authWitnesses, hashedArguments, capsules, cancellable, fee: userFee, nonce };
|
|
119
|
-
|
|
120
|
-
const fee = await this.getFeeOptions(request);
|
|
121
|
-
return { ...request, fee };
|
|
115
|
+
const { nonce, cancellable } = options;
|
|
116
|
+
return mergeExecutionRequestInits(requests, { nonce, cancellable });
|
|
122
117
|
}
|
|
123
118
|
|
|
124
119
|
/**
|
|
@@ -136,11 +131,8 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
136
131
|
* @param options - Deployment options.
|
|
137
132
|
* @returns A function call array with potentially requests to the class registerer and instance deployer.
|
|
138
133
|
*/
|
|
139
|
-
protected async getDeploymentFunctionCalls(
|
|
140
|
-
|
|
141
|
-
): Promise<Pick<ExecutionRequestInit, 'calls' | 'authWitnesses' | 'hashedArguments' | 'capsules'>> {
|
|
142
|
-
const calls: FunctionCall[] = [];
|
|
143
|
-
const capsules: Capsule[] = [];
|
|
134
|
+
protected async getDeploymentFunctionCalls(options: DeployOptions = {}): Promise<ContractFunctionInteraction[]> {
|
|
135
|
+
const calls: ContractFunctionInteraction[] = [];
|
|
144
136
|
|
|
145
137
|
// Set contract instance object so it's available for populating the DeploySendTx object
|
|
146
138
|
const instance = await this.getInstance(options);
|
|
@@ -165,19 +157,17 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
165
157
|
`Creating request for registering contract class ${contractClass.id.toString()} as part of deployment for ${instance.address.toString()}`,
|
|
166
158
|
);
|
|
167
159
|
const registerContractClassInteraction = await registerContractClass(this.wallet, this.artifact);
|
|
168
|
-
calls.push(
|
|
169
|
-
capsules.push(...registerContractClassInteraction.getCapsules());
|
|
160
|
+
calls.push(registerContractClassInteraction);
|
|
170
161
|
}
|
|
171
162
|
}
|
|
172
163
|
|
|
173
164
|
// Deploy the contract via the instance deployer.
|
|
174
165
|
if (!options.skipPublicDeployment) {
|
|
175
166
|
const deploymentInteraction = await deployInstance(this.wallet, instance);
|
|
176
|
-
calls.push(
|
|
177
|
-
capsules.push(...deploymentInteraction.getCapsules());
|
|
167
|
+
calls.push(deploymentInteraction);
|
|
178
168
|
}
|
|
179
169
|
|
|
180
|
-
return
|
|
170
|
+
return calls;
|
|
181
171
|
}
|
|
182
172
|
|
|
183
173
|
/**
|
|
@@ -185,23 +175,19 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
185
175
|
* @param options - Deployment options.
|
|
186
176
|
* @returns - An array of function calls.
|
|
187
177
|
*/
|
|
188
|
-
protected async getInitializeFunctionCalls(
|
|
189
|
-
|
|
190
|
-
): Promise<Pick<ExecutionRequestInit, 'calls' | 'authWitnesses' | 'hashedArguments' | 'capsules'>> {
|
|
191
|
-
const { address } = await this.getInstance(options);
|
|
192
|
-
const calls: FunctionCall[] = [];
|
|
193
|
-
const capsules: Capsule[] = [];
|
|
178
|
+
protected async getInitializeFunctionCalls(options: DeployOptions): Promise<ContractFunctionInteraction[]> {
|
|
179
|
+
const calls: ContractFunctionInteraction[] = [];
|
|
194
180
|
if (this.constructorArtifact && !options.skipInitialization) {
|
|
181
|
+
const { address } = await this.getInstance(options);
|
|
195
182
|
const constructorCall = new ContractFunctionInteraction(
|
|
196
183
|
this.wallet,
|
|
197
184
|
address,
|
|
198
185
|
this.constructorArtifact,
|
|
199
186
|
this.args,
|
|
200
187
|
);
|
|
201
|
-
calls.push(
|
|
202
|
-
capsules.push(...constructorCall.getCapsules());
|
|
188
|
+
calls.push(constructorCall);
|
|
203
189
|
}
|
|
204
|
-
return
|
|
190
|
+
return calls;
|
|
205
191
|
}
|
|
206
192
|
|
|
207
193
|
/**
|
|
@@ -3,7 +3,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
|
3
3
|
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
4
4
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
|
-
import type { Wallet } from '../account/
|
|
6
|
+
import type { Wallet } from '../account/wallet.js';
|
|
7
7
|
import type { Contract } from './contract.js';
|
|
8
8
|
import { DeploySentTx } from './deploy_sent_tx.js';
|
|
9
9
|
import { ProvenTx } from './proven_tx.js';
|
|
@@ -5,7 +5,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
|
5
5
|
import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
|
|
6
6
|
import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
8
|
-
import type { Wallet } from '../account/
|
|
8
|
+
import type { Wallet } from '../account/wallet.js';
|
|
9
9
|
import type { Contract } from './contract.js';
|
|
10
10
|
import type { ContractBase } from './contract_base.js';
|
|
11
11
|
import { SentTx, type WaitOpts } from './sent_tx.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
2
2
|
|
|
3
|
-
import type { Wallet } from '../wallet
|
|
3
|
+
import type { Wallet } from '../account/wallet.js';
|
|
4
4
|
import { UnsafeContract } from './unsafe_contract.js';
|
|
5
5
|
|
|
6
6
|
/** Returns a Contract wrapper for the class registerer. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
3
3
|
|
|
4
|
-
import type { Wallet } from '../wallet
|
|
4
|
+
import type { Wallet } from '../account/wallet.js';
|
|
5
5
|
import { ContractBase } from './contract_base.js';
|
|
6
6
|
|
|
7
7
|
/** Unsafe constructor for ContractBase that bypasses the check that the instance is registered in the wallet. */
|
|
@@ -28,6 +28,27 @@ export type ExecutionRequestInit = {
|
|
|
28
28
|
cancellable?: boolean;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Merges an array of ExecutionRequestInits.
|
|
33
|
+
*/
|
|
34
|
+
export function mergeExecutionRequestInits(
|
|
35
|
+
requests: Pick<ExecutionRequestInit, 'calls' | 'authWitnesses' | 'hashedArguments' | 'capsules'>[],
|
|
36
|
+
{ nonce, cancellable }: Pick<ExecutionRequestInit, 'nonce' | 'cancellable'> = {},
|
|
37
|
+
): Omit<ExecutionRequestInit, 'fee'> {
|
|
38
|
+
const calls = requests.map(r => r.calls).flat();
|
|
39
|
+
const authWitnesses = requests.map(r => r.authWitnesses ?? []).flat();
|
|
40
|
+
const hashedArguments = requests.map(r => r.hashedArguments ?? []).flat();
|
|
41
|
+
const capsules = requests.map(r => r.capsules ?? []).flat();
|
|
42
|
+
return {
|
|
43
|
+
calls,
|
|
44
|
+
authWitnesses,
|
|
45
|
+
hashedArguments,
|
|
46
|
+
capsules,
|
|
47
|
+
nonce,
|
|
48
|
+
cancellable,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
31
52
|
/** Creates transaction execution requests out of a set of function calls. */
|
|
32
53
|
export interface EntrypointInterface {
|
|
33
54
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
2
2
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
3
|
|
|
4
|
-
import { createPXEClient } from '
|
|
4
|
+
import { createPXEClient } from '../rpc_clients/pxe_client.js';
|
|
5
5
|
|
|
6
6
|
export const getL1ContractAddresses = async (url: string): Promise<L1ContractAddresses> => {
|
|
7
7
|
const pxeClient = createPXEClient(url, {});
|