@aztec/aztec.js 0.82.0 → 0.82.1

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.
Files changed (42) hide show
  1. package/dest/account_manager/account_manager.d.ts +11 -10
  2. package/dest/account_manager/account_manager.d.ts.map +1 -1
  3. package/dest/account_manager/account_manager.js +61 -10
  4. package/dest/account_manager/index.d.ts +0 -1
  5. package/dest/account_manager/index.d.ts.map +1 -1
  6. package/dest/account_manager/index.js +0 -1
  7. package/dest/api/fee.d.ts +1 -0
  8. package/dest/api/fee.d.ts.map +1 -1
  9. package/dest/api/fee.js +1 -0
  10. package/dest/api/fee_testing.d.ts +2 -0
  11. package/dest/api/fee_testing.d.ts.map +1 -0
  12. package/dest/api/fee_testing.js +1 -0
  13. package/dest/contract/deploy_proven_tx.js +1 -1
  14. package/dest/contract/proven_tx.d.ts +0 -1
  15. package/dest/contract/proven_tx.d.ts.map +1 -1
  16. package/dest/contract/proven_tx.js +2 -6
  17. package/dest/fee/account_entrypoint_meta_payment_method.d.ts +31 -0
  18. package/dest/fee/account_entrypoint_meta_payment_method.d.ts.map +1 -0
  19. package/dest/fee/account_entrypoint_meta_payment_method.js +64 -0
  20. package/dest/fee/sponsored_fee_payment.d.ts +15 -0
  21. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
  22. package/dest/fee/sponsored_fee_payment.js +30 -0
  23. package/dest/utils/authwit.d.ts.map +1 -1
  24. package/dest/utils/authwit.js +3 -3
  25. package/package.json +10 -9
  26. package/src/account_manager/account_manager.ts +73 -14
  27. package/src/account_manager/index.ts +0 -1
  28. package/src/api/fee.ts +1 -0
  29. package/src/api/fee_testing.ts +1 -0
  30. package/src/contract/deploy_proven_tx.ts +1 -1
  31. package/src/contract/proven_tx.ts +2 -19
  32. package/src/fee/account_entrypoint_meta_payment_method.ts +90 -0
  33. package/src/fee/sponsored_fee_payment.ts +38 -0
  34. package/src/utils/authwit.ts +3 -11
  35. package/dest/account_manager/deploy_account_method.d.ts +0 -15
  36. package/dest/account_manager/deploy_account_method.d.ts.map +0 -1
  37. package/dest/account_manager/deploy_account_method.js +0 -51
  38. package/dest/entrypoint/default_multi_call_entrypoint.d.ts +0 -16
  39. package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +0 -1
  40. package/dest/entrypoint/default_multi_call_entrypoint.js +0 -134
  41. package/src/account_manager/deploy_account_method.ts +0 -87
  42. package/src/entrypoint/default_multi_call_entrypoint.ts +0 -100
@@ -1,3 +1,2 @@
1
1
  export { AccountManager, type DeployAccountOptions } from './account_manager.js';
2
- export { DeployAccountMethod } from './deploy_account_method.js';
3
2
  export { type DeployAccountTxReceipt, DeployAccountSentTx } from './deploy_account_sent_tx.js';
package/src/api/fee.ts CHANGED
@@ -3,3 +3,4 @@ export { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
3
3
  export { PrivateFeePaymentMethod } from '../fee/private_fee_payment_method.js';
4
4
  export { PublicFeePaymentMethod } from '../fee/public_fee_payment_method.js';
5
5
  export { FeeJuicePaymentMethodWithClaim } from '../fee/fee_juice_payment_method_with_claim.js';
6
+ export { SponsoredFeePaymentMethod } from '../fee/sponsored_fee_payment.js';
@@ -0,0 +1 @@
1
+ export { SponsoredFeePaymentMethod } from '../fee/sponsored_fee_payment.js';
@@ -25,7 +25,7 @@ export class DeployProvenTx<TContract extends Contract = Contract> extends Prove
25
25
  */
26
26
  public override send(): DeploySentTx<TContract> {
27
27
  const promise = (() => {
28
- return this.wallet.sendTx(this.getPlainDataTx());
28
+ return this.wallet.sendTx(this);
29
29
  })();
30
30
 
31
31
  return new DeploySentTx(this.wallet, promise, this.postDeployCtor, this.instanceGetter);
@@ -8,24 +8,7 @@ import { SentTx } from './sent_tx.js';
8
8
  */
9
9
  export class ProvenTx extends Tx {
10
10
  constructor(protected wallet: Wallet, tx: Tx) {
11
- super(
12
- tx.data,
13
- tx.clientIvcProof,
14
- tx.contractClassLogs,
15
- tx.enqueuedPublicFunctionCalls,
16
- tx.publicTeardownFunctionCall,
17
- );
18
- }
19
-
20
- // Clone the TX data to get a serializable object.
21
- protected getPlainDataTx(): Tx {
22
- return new Tx(
23
- this.data,
24
- this.clientIvcProof,
25
- this.contractClassLogs,
26
- this.enqueuedPublicFunctionCalls,
27
- this.publicTeardownFunctionCall,
28
- );
11
+ super(tx.data, tx.clientIvcProof, tx.contractClassLogs, tx.publicFunctionCalldata);
29
12
  }
30
13
 
31
14
  /**
@@ -33,7 +16,7 @@ export class ProvenTx extends Tx {
33
16
  */
34
17
  public send(): SentTx {
35
18
  const promise = (() => {
36
- return this.wallet.sendTx(this.getPlainDataTx());
19
+ return this.wallet.sendTx(this);
37
20
  })();
38
21
 
39
22
  return new SentTx(this.wallet, promise);
@@ -0,0 +1,90 @@
1
+ import {
2
+ EncodedAppEntrypointCalls,
3
+ EncodedCallsForEntrypoint,
4
+ computeCombinedPayloadHash,
5
+ } from '@aztec/entrypoints/encoding';
6
+ import type { AuthWitnessProvider, FeePaymentMethod } from '@aztec/entrypoints/interfaces';
7
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
8
+ import {
9
+ type ContractArtifact,
10
+ type FunctionArtifact,
11
+ FunctionCall,
12
+ FunctionSelector,
13
+ encodeArguments,
14
+ getFunctionArtifactByName,
15
+ } from '@aztec/stdlib/abi';
16
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
17
+ import type { GasSettings } from '@aztec/stdlib/gas';
18
+
19
+ /**
20
+ * Fee payment method that allows a contract to pay for its own deployment
21
+ * It works by rerouting the provided fee payment method through the account's entrypoint,
22
+ * which sets itself as fee payer.
23
+ *
24
+ * Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
25
+ * that is sent to the user's account entrypoint, that has plumbing to handle a fee payload.
26
+ * If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
27
+ * how to handle this payload.
28
+ * HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
29
+ * being deployed with the original fee payload.
30
+ *
31
+ * This class can be seen in action in AccountManager.ts#getSelfPaymentMethod
32
+ */
33
+ export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
34
+ constructor(
35
+ private artifact: ContractArtifact,
36
+ private authWitnessProvider: AuthWitnessProvider,
37
+ private feePaymentNameOrArtifact: string | FunctionArtifact,
38
+ private accountAddress: AztecAddress,
39
+ private paymentMethod: FeePaymentMethod,
40
+ ) {}
41
+
42
+ getAsset(): Promise<AztecAddress> {
43
+ return this.paymentMethod.getAsset();
44
+ }
45
+
46
+ async getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload> {
47
+ const emptyAppCalls = await EncodedAppEntrypointCalls.fromAppExecution([]);
48
+ // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
49
+ const { calls: feeCalls, authWitnesses: feeAuthwitnesses } = await this.paymentMethod.getExecutionPayload(
50
+ gasSettings,
51
+ );
52
+ // Encode the calls for the fee
53
+ const feePayer = await this.paymentMethod.getFeePayer(gasSettings);
54
+ const isFeePayer = feePayer.equals(this.accountAddress);
55
+ const feeEncodedCalls = await EncodedCallsForEntrypoint.fromFeeCalls(feeCalls, isFeePayer);
56
+
57
+ // Get the entrypoint args
58
+ const args = [emptyAppCalls, feeEncodedCalls, false];
59
+ const feePaymentArtifact =
60
+ typeof this.feePaymentNameOrArtifact === 'string'
61
+ ? getFunctionArtifactByName(this.artifact, this.feePaymentNameOrArtifact)
62
+ : this.feePaymentNameOrArtifact;
63
+
64
+ const entrypointCall = new FunctionCall(
65
+ feePaymentArtifact.name,
66
+ this.accountAddress,
67
+ await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters),
68
+ feePaymentArtifact.functionType,
69
+ feePaymentArtifact.isStatic,
70
+ encodeArguments(feePaymentArtifact, args),
71
+ feePaymentArtifact.returnTypes,
72
+ );
73
+
74
+ // Compute the authwitness required to verify the combined payload
75
+ const combinedPayloadAuthWitness = await this.authWitnessProvider.createAuthWit(
76
+ await computeCombinedPayloadHash(emptyAppCalls, feeEncodedCalls),
77
+ );
78
+
79
+ return new ExecutionPayload(
80
+ [entrypointCall],
81
+ [combinedPayloadAuthWitness, ...feeAuthwitnesses],
82
+ [],
83
+ [...emptyAppCalls.hashedArguments, ...feeEncodedCalls.hashedArguments],
84
+ );
85
+ }
86
+
87
+ getFeePayer(gasSettings: GasSettings): Promise<AztecAddress> {
88
+ return this.paymentMethod.getFeePayer(gasSettings);
89
+ }
90
+ }
@@ -0,0 +1,38 @@
1
+ import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
2
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
3
+ import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+
6
+ /**
7
+ * A fee payment method that uses a contract that blindly sponsors transactions.
8
+ * This contract is expected to be prefunded in testing environments.
9
+ */
10
+ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
11
+ constructor(private paymentContract: AztecAddress) {}
12
+
13
+ getAsset(): Promise<AztecAddress> {
14
+ throw new Error('Asset is not required for sponsored fpc.');
15
+ }
16
+
17
+ getFeePayer() {
18
+ return Promise.resolve(this.paymentContract);
19
+ }
20
+
21
+ async getExecutionPayload(): Promise<ExecutionPayload> {
22
+ return new ExecutionPayload(
23
+ [
24
+ {
25
+ name: 'sponsor_unconditionally',
26
+ to: this.paymentContract,
27
+ selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
28
+ type: FunctionType.PRIVATE,
29
+ isStatic: false,
30
+ args: [],
31
+ returnTypes: [],
32
+ },
33
+ ],
34
+ [],
35
+ [],
36
+ );
37
+ }
38
+ }
@@ -2,7 +2,7 @@ import { Fr } from '@aztec/foundation/fields';
2
2
  import type { FunctionCall } from '@aztec/stdlib/abi';
3
3
  import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import { HashedValues } from '@aztec/stdlib/tx';
5
+ import { computeVarArgsHash } from '@aztec/stdlib/hash';
6
6
 
7
7
  import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
8
8
 
@@ -80,11 +80,7 @@ export const computeAuthWitMessageHash = async (intent: IntentInnerHash | Intent
80
80
  * @returns The inner hash for the function call
81
81
  **/
82
82
  export const computeInnerAuthWitHashFromFunctionCall = async (caller: AztecAddress, fnCall: FunctionCall) => {
83
- return computeInnerAuthWitHash([
84
- caller.toField(),
85
- fnCall.selector.toField(),
86
- (await HashedValues.fromValues(fnCall.args)).hash,
87
- ]);
83
+ return computeInnerAuthWitHash([caller.toField(), fnCall.selector.toField(), await computeVarArgsHash(fnCall.args)]);
88
84
  };
89
85
 
90
86
  /**
@@ -100,9 +96,5 @@ export const computeInnerAuthWitHashFromAction = async (
100
96
  action: FunctionCall | ContractFunctionInteraction,
101
97
  ) => {
102
98
  action = action instanceof ContractFunctionInteraction ? (await action.request()).calls[0] : action;
103
- return computeInnerAuthWitHash([
104
- caller.toField(),
105
- action.selector.toField(),
106
- (await HashedValues.fromValues(action.args)).hash,
107
- ]);
99
+ return computeInnerAuthWitHash([caller.toField(), action.selector.toField(), await computeVarArgsHash(action.args)]);
108
100
  };
@@ -1,15 +0,0 @@
1
- import type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces';
2
- import { ExecutionPayload } from '@aztec/entrypoints/payload';
3
- import { type ContractArtifact, type FunctionArtifact } from '@aztec/stdlib/abi';
4
- import type { PublicKeys } from '@aztec/stdlib/keys';
5
- import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js';
6
- import type { Wallet } from '../wallet/wallet.js';
7
- /**
8
- * Contract interaction for deploying an account contract. Handles fee preparation and contract initialization.
9
- */
10
- export declare class DeployAccountMethod extends DeployMethod {
11
- #private;
12
- constructor(authWitnessProvider: AuthWitnessProvider, publicKeys: PublicKeys, wallet: Wallet, artifact: ContractArtifact, args?: any[], constructorNameOrArtifact?: string | FunctionArtifact, feePaymentNameOrArtifact?: string | FunctionArtifact);
13
- protected getInitializeExecutionPayload(options: DeployOptions): Promise<ExecutionPayload>;
14
- }
15
- //# sourceMappingURL=deploy_account_method.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deploy_account_method.d.ts","sourceRoot":"","sources":["../../src/account_manager/deploy_account_method.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAA0B,MAAM,4BAA4B,CAAC;AACtF,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAA6B,MAAM,mBAAmB,CAAC;AAC5G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;;gBAKjD,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,GAAE,GAAG,EAAO,EAChB,yBAAyB,CAAC,EAAE,MAAM,GAAG,gBAAgB,EACrD,wBAAwB,CAAC,EAAE,MAAM,GAAG,gBAAgB;cAkB7B,6BAA6B,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAuC1G"}
@@ -1,51 +0,0 @@
1
- import { EncodedAppEntrypointCalls, EncodedCallsForEntrypoint, computeCombinedPayloadHash } from '@aztec/entrypoints/encoding';
2
- import { mergeExecutionPayloads } from '@aztec/entrypoints/payload';
3
- import { getFunctionArtifactByName } from '@aztec/stdlib/abi';
4
- import { Contract } from '../contract/contract.js';
5
- import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
6
- import { DeployMethod } from '../contract/deploy_method.js';
7
- /**
8
- * Contract interaction for deploying an account contract. Handles fee preparation and contract initialization.
9
- */ export class DeployAccountMethod extends DeployMethod {
10
- #authWitnessProvider;
11
- #feePaymentArtifact;
12
- constructor(authWitnessProvider, publicKeys, wallet, artifact, args = [], constructorNameOrArtifact, feePaymentNameOrArtifact){
13
- super(publicKeys, wallet, artifact, (address, wallet)=>Contract.at(address, artifact, wallet), args, constructorNameOrArtifact);
14
- this.#authWitnessProvider = authWitnessProvider;
15
- this.#feePaymentArtifact = typeof feePaymentNameOrArtifact === 'string' ? getFunctionArtifactByName(artifact, feePaymentNameOrArtifact) : feePaymentNameOrArtifact;
16
- }
17
- async getInitializeExecutionPayload(options) {
18
- let exec = await super.getInitializeExecutionPayload(options);
19
- if (options.fee && this.#feePaymentArtifact) {
20
- const { address } = await this.getInstance();
21
- const emptyAppCalls = await EncodedAppEntrypointCalls.fromAppExecution([]);
22
- const fee = await this.getDefaultFeeOptions(options.fee);
23
- // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
24
- const { calls: feeCalls, authWitnesses: feeAuthwitnesses } = await fee.paymentMethod.getExecutionPayload(fee.gasSettings);
25
- // Encode the calls for the fee
26
- const feePayer = await fee.paymentMethod.getFeePayer(fee.gasSettings);
27
- const isFeePayer = feePayer.equals(address);
28
- const feeEncodedCalls = await EncodedCallsForEntrypoint.fromFeeCalls(feeCalls, isFeePayer);
29
- // Get the entrypoint args
30
- const args = [
31
- emptyAppCalls,
32
- feeEncodedCalls,
33
- false
34
- ];
35
- // Compute the authwitness required to verify the combined payload
36
- const combinedPayloadAuthWitness = await this.#authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(emptyAppCalls, feeEncodedCalls));
37
- const call = new ContractFunctionInteraction(this.wallet, address, this.#feePaymentArtifact, args, [
38
- combinedPayloadAuthWitness,
39
- ...feeAuthwitnesses
40
- ], [], [
41
- ...emptyAppCalls.hashedArguments,
42
- ...feeEncodedCalls.hashedArguments
43
- ]);
44
- exec = mergeExecutionPayloads([
45
- exec,
46
- await call.request()
47
- ]);
48
- }
49
- return exec;
50
- }
51
- }
@@ -1,16 +0,0 @@
1
- import type { EntrypointInterface, FeeOptions } from '@aztec/entrypoints/interfaces';
2
- import { ExecutionPayload } from '@aztec/entrypoints/payload';
3
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import { TxExecutionRequest } from '@aztec/stdlib/tx';
5
- /**
6
- * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
7
- */
8
- export declare class DefaultMultiCallEntrypoint implements EntrypointInterface {
9
- private chainId;
10
- private version;
11
- private address;
12
- constructor(chainId: number, version: number, address?: AztecAddress);
13
- createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise<TxExecutionRequest>;
14
- private getEntrypointAbi;
15
- }
16
- //# sourceMappingURL=default_multi_call_entrypoint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default_multi_call_entrypoint.d.ts","sourceRoot":"","sources":["../../src/entrypoint/default_multi_call_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE/E;;GAEG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IAElE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAFP,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,YAA0D;IAGvE,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAyBpG,OAAO,CAAC,gBAAgB;CAwDzB"}
@@ -1,134 +0,0 @@
1
- import { EncodedCallsForEntrypoint } from '@aztec/entrypoints/encoding';
2
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
- import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
- /**
6
- * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
7
- */ export class DefaultMultiCallEntrypoint {
8
- chainId;
9
- version;
10
- address;
11
- constructor(chainId, version, address = ProtocolContractAddress.MultiCallEntrypoint){
12
- this.chainId = chainId;
13
- this.version = version;
14
- this.address = address;
15
- }
16
- async createTxExecutionRequest(exec, fee) {
17
- // Initial request with calls, authWitnesses and capsules
18
- const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
19
- // Encode the calls
20
- const encodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls);
21
- // Obtain the entrypoint hashed args, built from the encoded calls
22
- const abi = this.getEntrypointAbi();
23
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
24
- encodedCalls
25
- ]));
26
- // Assemble the tx request
27
- const txRequest = TxExecutionRequest.from({
28
- firstCallArgsHash: entrypointHashedArgs.hash,
29
- origin: this.address,
30
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
31
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
32
- argsOfCalls: [
33
- ...encodedCalls.hashedArguments,
34
- entrypointHashedArgs,
35
- ...extraHashedArgs
36
- ],
37
- authWitnesses,
38
- capsules
39
- });
40
- return Promise.resolve(txRequest);
41
- }
42
- getEntrypointAbi() {
43
- return {
44
- name: 'entrypoint',
45
- isInitializer: false,
46
- functionType: 'private',
47
- isInternal: false,
48
- isStatic: false,
49
- parameters: [
50
- {
51
- name: 'app_payload',
52
- type: {
53
- kind: 'struct',
54
- path: 'authwit::entrypoint::app::AppPayload',
55
- fields: [
56
- {
57
- name: 'function_calls',
58
- type: {
59
- kind: 'array',
60
- length: 4,
61
- type: {
62
- kind: 'struct',
63
- path: 'authwit::entrypoint::function_call::FunctionCall',
64
- fields: [
65
- {
66
- name: 'args_hash',
67
- type: {
68
- kind: 'field'
69
- }
70
- },
71
- {
72
- name: 'function_selector',
73
- type: {
74
- kind: 'struct',
75
- path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
76
- fields: [
77
- {
78
- name: 'inner',
79
- type: {
80
- kind: 'integer',
81
- sign: 'unsigned',
82
- width: 32
83
- }
84
- }
85
- ]
86
- }
87
- },
88
- {
89
- name: 'target_address',
90
- type: {
91
- kind: 'struct',
92
- path: 'authwit::aztec::protocol_types::address::AztecAddress',
93
- fields: [
94
- {
95
- name: 'inner',
96
- type: {
97
- kind: 'field'
98
- }
99
- }
100
- ]
101
- }
102
- },
103
- {
104
- name: 'is_public',
105
- type: {
106
- kind: 'boolean'
107
- }
108
- },
109
- {
110
- name: 'is_static',
111
- type: {
112
- kind: 'boolean'
113
- }
114
- }
115
- ]
116
- }
117
- }
118
- },
119
- {
120
- name: 'nonce',
121
- type: {
122
- kind: 'field'
123
- }
124
- }
125
- ]
126
- },
127
- visibility: 'public'
128
- }
129
- ],
130
- returnTypes: [],
131
- errorTypes: {}
132
- };
133
- }
134
- }
@@ -1,87 +0,0 @@
1
- import {
2
- EncodedAppEntrypointCalls,
3
- EncodedCallsForEntrypoint,
4
- computeCombinedPayloadHash,
5
- } from '@aztec/entrypoints/encoding';
6
- import type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces';
7
- import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
8
- import { type ContractArtifact, type FunctionArtifact, getFunctionArtifactByName } from '@aztec/stdlib/abi';
9
- import type { PublicKeys } from '@aztec/stdlib/keys';
10
-
11
- import { Contract } from '../contract/contract.js';
12
- import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
13
- import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js';
14
- import type { Wallet } from '../wallet/wallet.js';
15
-
16
- /**
17
- * Contract interaction for deploying an account contract. Handles fee preparation and contract initialization.
18
- */
19
- export class DeployAccountMethod extends DeployMethod {
20
- #authWitnessProvider: AuthWitnessProvider;
21
- #feePaymentArtifact: FunctionArtifact | undefined;
22
-
23
- constructor(
24
- authWitnessProvider: AuthWitnessProvider,
25
- publicKeys: PublicKeys,
26
- wallet: Wallet,
27
- artifact: ContractArtifact,
28
- args: any[] = [],
29
- constructorNameOrArtifact?: string | FunctionArtifact,
30
- feePaymentNameOrArtifact?: string | FunctionArtifact,
31
- ) {
32
- super(
33
- publicKeys,
34
- wallet,
35
- artifact,
36
- (address, wallet) => Contract.at(address, artifact, wallet),
37
- args,
38
- constructorNameOrArtifact,
39
- );
40
-
41
- this.#authWitnessProvider = authWitnessProvider;
42
- this.#feePaymentArtifact =
43
- typeof feePaymentNameOrArtifact === 'string'
44
- ? getFunctionArtifactByName(artifact, feePaymentNameOrArtifact)
45
- : feePaymentNameOrArtifact;
46
- }
47
-
48
- protected override async getInitializeExecutionPayload(options: DeployOptions): Promise<ExecutionPayload> {
49
- let exec = await super.getInitializeExecutionPayload(options);
50
-
51
- if (options.fee && this.#feePaymentArtifact) {
52
- const { address } = await this.getInstance();
53
- const emptyAppCalls = await EncodedAppEntrypointCalls.fromAppExecution([]);
54
- const fee = await this.getDefaultFeeOptions(options.fee);
55
- // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
56
- const { calls: feeCalls, authWitnesses: feeAuthwitnesses } = await fee.paymentMethod.getExecutionPayload(
57
- fee.gasSettings,
58
- );
59
- // Encode the calls for the fee
60
- const feePayer = await fee.paymentMethod.getFeePayer(fee.gasSettings);
61
- const isFeePayer = feePayer.equals(address);
62
- const feeEncodedCalls = await EncodedCallsForEntrypoint.fromFeeCalls(feeCalls, isFeePayer);
63
-
64
- // Get the entrypoint args
65
- const args = [emptyAppCalls, feeEncodedCalls, false];
66
-
67
- // Compute the authwitness required to verify the combined payload
68
- const combinedPayloadAuthWitness = await this.#authWitnessProvider.createAuthWit(
69
- await computeCombinedPayloadHash(emptyAppCalls, feeEncodedCalls),
70
- );
71
-
72
- const call = new ContractFunctionInteraction(
73
- this.wallet,
74
- address,
75
- this.#feePaymentArtifact,
76
- args,
77
- [combinedPayloadAuthWitness, ...feeAuthwitnesses],
78
- [],
79
- [...emptyAppCalls.hashedArguments, ...feeEncodedCalls.hashedArguments],
80
- );
81
-
82
- exec = mergeExecutionPayloads([exec, await call.request()]);
83
- }
84
-
85
- return exec;
86
- }
87
- }
@@ -1,100 +0,0 @@
1
- import { EncodedCallsForEntrypoint } from '@aztec/entrypoints/encoding';
2
- import type { EntrypointInterface, FeeOptions } from '@aztec/entrypoints/interfaces';
3
- import { ExecutionPayload } from '@aztec/entrypoints/payload';
4
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
- import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
6
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
8
-
9
- /**
10
- * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
11
- */
12
- export class DefaultMultiCallEntrypoint implements EntrypointInterface {
13
- constructor(
14
- private chainId: number,
15
- private version: number,
16
- private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint,
17
- ) {}
18
-
19
- async createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise<TxExecutionRequest> {
20
- // Initial request with calls, authWitnesses and capsules
21
- const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
22
-
23
- // Encode the calls
24
- const encodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls);
25
-
26
- // Obtain the entrypoint hashed args, built from the encoded calls
27
- const abi = this.getEntrypointAbi();
28
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [encodedCalls]));
29
-
30
- // Assemble the tx request
31
- const txRequest = TxExecutionRequest.from({
32
- firstCallArgsHash: entrypointHashedArgs.hash,
33
- origin: this.address,
34
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
35
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
36
- argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
37
- authWitnesses,
38
- capsules,
39
- });
40
-
41
- return Promise.resolve(txRequest);
42
- }
43
-
44
- private getEntrypointAbi() {
45
- return {
46
- name: 'entrypoint',
47
- isInitializer: false,
48
- functionType: 'private',
49
- isInternal: false,
50
- isStatic: false,
51
- parameters: [
52
- {
53
- name: 'app_payload',
54
- type: {
55
- kind: 'struct',
56
- path: 'authwit::entrypoint::app::AppPayload',
57
- fields: [
58
- {
59
- name: 'function_calls',
60
- type: {
61
- kind: 'array',
62
- length: 4,
63
- type: {
64
- kind: 'struct',
65
- path: 'authwit::entrypoint::function_call::FunctionCall',
66
- fields: [
67
- { name: 'args_hash', type: { kind: 'field' } },
68
- {
69
- name: 'function_selector',
70
- type: {
71
- kind: 'struct',
72
- path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
73
- fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }],
74
- },
75
- },
76
- {
77
- name: 'target_address',
78
- type: {
79
- kind: 'struct',
80
- path: 'authwit::aztec::protocol_types::address::AztecAddress',
81
- fields: [{ name: 'inner', type: { kind: 'field' } }],
82
- },
83
- },
84
- { name: 'is_public', type: { kind: 'boolean' } },
85
- { name: 'is_static', type: { kind: 'boolean' } },
86
- ],
87
- },
88
- },
89
- },
90
- { name: 'nonce', type: { kind: 'field' } },
91
- ],
92
- },
93
- visibility: 'public',
94
- },
95
- ],
96
- returnTypes: [],
97
- errorTypes: {},
98
- } as FunctionAbi;
99
- }
100
- }