@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.
- package/dest/account_manager/account_manager.d.ts +11 -10
- package/dest/account_manager/account_manager.d.ts.map +1 -1
- package/dest/account_manager/account_manager.js +61 -10
- package/dest/account_manager/index.d.ts +0 -1
- package/dest/account_manager/index.d.ts.map +1 -1
- package/dest/account_manager/index.js +0 -1
- package/dest/api/fee.d.ts +1 -0
- package/dest/api/fee.d.ts.map +1 -1
- package/dest/api/fee.js +1 -0
- package/dest/api/fee_testing.d.ts +2 -0
- package/dest/api/fee_testing.d.ts.map +1 -0
- package/dest/api/fee_testing.js +1 -0
- package/dest/contract/deploy_proven_tx.js +1 -1
- package/dest/contract/proven_tx.d.ts +0 -1
- package/dest/contract/proven_tx.d.ts.map +1 -1
- package/dest/contract/proven_tx.js +2 -6
- package/dest/fee/account_entrypoint_meta_payment_method.d.ts +31 -0
- package/dest/fee/account_entrypoint_meta_payment_method.d.ts.map +1 -0
- package/dest/fee/account_entrypoint_meta_payment_method.js +64 -0
- package/dest/fee/sponsored_fee_payment.d.ts +15 -0
- package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
- package/dest/fee/sponsored_fee_payment.js +30 -0
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +3 -3
- package/package.json +10 -9
- package/src/account_manager/account_manager.ts +73 -14
- package/src/account_manager/index.ts +0 -1
- package/src/api/fee.ts +1 -0
- package/src/api/fee_testing.ts +1 -0
- package/src/contract/deploy_proven_tx.ts +1 -1
- package/src/contract/proven_tx.ts +2 -19
- package/src/fee/account_entrypoint_meta_payment_method.ts +90 -0
- package/src/fee/sponsored_fee_payment.ts +38 -0
- package/src/utils/authwit.ts +3 -11
- package/dest/account_manager/deploy_account_method.d.ts +0 -15
- package/dest/account_manager/deploy_account_method.d.ts.map +0 -1
- package/dest/account_manager/deploy_account_method.js +0 -51
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts +0 -16
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/default_multi_call_entrypoint.js +0 -134
- package/src/account_manager/deploy_account_method.ts +0 -87
- package/src/entrypoint/default_multi_call_entrypoint.ts +0 -100
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { CompleteAddress, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
3
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
3
4
|
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
4
5
|
import type { AccountContract } from '../account/account_contract.js';
|
|
5
6
|
import type { Salt } from '../account/index.js';
|
|
6
7
|
import type { AccountInterface } from '../account/interface.js';
|
|
7
|
-
import {
|
|
8
|
-
import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js';
|
|
8
|
+
import { type DeployOptions } from '../contract/deploy_method.js';
|
|
9
9
|
import { type WaitOpts } from '../contract/sent_tx.js';
|
|
10
10
|
import { AccountWalletWithSecretKey, type Wallet } from '../wallet/index.js';
|
|
11
11
|
import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
|
|
@@ -23,6 +23,7 @@ export type DeployAccountOptions = Pick<DeployOptions, 'fee' | 'skipClassRegistr
|
|
|
23
23
|
* and creating and registering the user wallet in the PXE Service.
|
|
24
24
|
*/
|
|
25
25
|
export declare class AccountManager {
|
|
26
|
+
#private;
|
|
26
27
|
private pxe;
|
|
27
28
|
private secretKey;
|
|
28
29
|
private accountContract;
|
|
@@ -72,14 +73,6 @@ export declare class AccountManager {
|
|
|
72
73
|
* @returns A Wallet instance.
|
|
73
74
|
*/
|
|
74
75
|
register(): Promise<AccountWalletWithSecretKey>;
|
|
75
|
-
/**
|
|
76
|
-
* Returns the pre-populated deployment method to deploy the account contract that backs this account.
|
|
77
|
-
* Typically you will not need this method and can call `deploy` directly. Use this for having finer
|
|
78
|
-
* grained control on when to create, simulate, and send the deployment tx.
|
|
79
|
-
* @param deployWallet - Wallet used for deploying the account contract.
|
|
80
|
-
* @returns A DeployMethod instance that deploys this account contract.
|
|
81
|
-
*/
|
|
82
|
-
getDeployMethod(deployWallet?: Wallet): Promise<DeployMethod<Contract>>;
|
|
83
76
|
/**
|
|
84
77
|
* Deploys the account contract that backs this account.
|
|
85
78
|
* Does not register the associated class nor publicly deploy the instance by default.
|
|
@@ -89,6 +82,14 @@ export declare class AccountManager {
|
|
|
89
82
|
* @returns A SentTx object that can be waited to get the associated Wallet.
|
|
90
83
|
*/
|
|
91
84
|
deploy(opts?: DeployAccountOptions): DeployAccountSentTx;
|
|
85
|
+
/**
|
|
86
|
+
* Estimates the gas needed to deploy the account contract that backs this account.
|
|
87
|
+
* This method is here to ensure that the fee payment method is correctly set up in case
|
|
88
|
+
* the account contract needs to pay for its own deployment.
|
|
89
|
+
* @param opts - Fee options to be used for the deployment.
|
|
90
|
+
* @returns The gas estimations for the account contract deployment and initialization.
|
|
91
|
+
*/
|
|
92
|
+
estimateDeploymentGas(opts?: DeployAccountOptions): Promise<Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>>;
|
|
92
93
|
/**
|
|
93
94
|
* Deploys the account contract that backs this account if needed and awaits the tx to be mined.
|
|
94
95
|
* Uses the salt provided in the constructor or a randomly generated one. If no initialization
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account_manager.d.ts","sourceRoot":"","sources":["../../src/account_manager/account_manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account_manager.d.ts","sourceRoot":"","sources":["../../src/account_manager/account_manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,KAAK,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGxE,OAAO,EAAE,0BAA0B,EAAoB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,aAAa,EACb,KAAK,GAAG,uBAAuB,GAAG,sBAAsB,GAAG,oBAAoB,CAChF,GAAG;IACF;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,qBAAa,cAAc;;IAEvB,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,QAAQ;IAChB;;OAEG;aACa,IAAI,EAAE,IAAI;IAR5B,OAAO;WAWM,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,IAAI;IAoB1F,SAAS,CAAC,aAAa;IAIvB,SAAS,CAAC,iBAAiB;IAI3B;;;OAGG;IACU,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAMpD;;;;OAIG;IACI,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;IAIrD;;;;OAIG;IACI,UAAU;IAIjB;;;;OAIG;IACI,WAAW,IAAI,2BAA2B;IAIjD;;;;OAIG;IACU,SAAS,IAAI,OAAO,CAAC,0BAA0B,CAAC;IAK7D;;;;;;OAMG;IACU,QAAQ,IAAI,OAAO,CAAC,0BAA0B,CAAC;IAqF5D;;;;;;;OAOG;IACI,MAAM,CAAC,IAAI,CAAC,EAAE,oBAAoB,GAAG,mBAAmB;IA2B/D;;;;;;OAMG;IACU,qBAAqB,CAChC,IAAI,CAAC,EAAE,oBAAoB,GAC1B,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,mBAAmB,CAAC,CAAC;IAgBhE;;;;;;OAMG;IACU,SAAS,CAAC,IAAI,GAAE,oBAAoB,GAAG,QAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAKpH;;OAEG;IACU,YAAY;CAG1B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DefaultMultiCallEntrypoint } from '@aztec/entrypoints/multicall';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
3
4
|
import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract';
|
|
@@ -5,9 +6,9 @@ import { deriveKeys } from '@aztec/stdlib/keys';
|
|
|
5
6
|
import { Contract } from '../contract/contract.js';
|
|
6
7
|
import { DeployMethod } from '../contract/deploy_method.js';
|
|
7
8
|
import { DefaultWaitOpts } from '../contract/sent_tx.js';
|
|
8
|
-
import {
|
|
9
|
+
import { AccountEntrypointMetaPaymentMethod } from '../fee/account_entrypoint_meta_payment_method.js';
|
|
10
|
+
import { FeeJuicePaymentMethod } from '../index.js';
|
|
9
11
|
import { AccountWalletWithSecretKey, SignerlessWallet } from '../wallet/index.js';
|
|
10
|
-
import { DeployAccountMethod } from './deploy_account_method.js';
|
|
11
12
|
import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
|
|
12
13
|
/**
|
|
13
14
|
* Manages a user account. Provides methods for calculating the account's address, deploying the account contract,
|
|
@@ -102,11 +103,10 @@ import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
|
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* Returns the pre-populated deployment method to deploy the account contract that backs this account.
|
|
105
|
-
*
|
|
106
|
-
* grained control on when to create, simulate, and send the deployment tx.
|
|
106
|
+
* If no wallet is provided, it uses a signerless wallet with the multi call entrypoint
|
|
107
107
|
* @param deployWallet - Wallet used for deploying the account contract.
|
|
108
|
-
* @returns A DeployMethod instance that deploys this account contract
|
|
109
|
-
*/ async getDeployMethod(deployWallet) {
|
|
108
|
+
* @returns A DeployMethod instance that deploys this account contract
|
|
109
|
+
*/ async #getDeployMethod(deployWallet) {
|
|
110
110
|
const artifact = await this.accountContract.getContractArtifact();
|
|
111
111
|
if (!await this.isDeployable()) {
|
|
112
112
|
throw new Error(`Account contract ${artifact.name} does not require deployment.`);
|
|
@@ -127,7 +127,22 @@ import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
|
|
|
127
127
|
// If we used getWallet, the deployment would get routed via the account contract entrypoint
|
|
128
128
|
// and it can't be used unless the contract is initialized.
|
|
129
129
|
const wallet = new SignerlessWallet(this.pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion));
|
|
130
|
-
return new
|
|
130
|
+
return new DeployMethod(this.getPublicKeys(), wallet, artifact, (address)=>Contract.at(address, artifact, wallet), constructorArgs, constructorName);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns a FeePaymentMethod that routes the original one provided as an argument
|
|
134
|
+
* through the account's entrypoint. This allows an account contract to pay
|
|
135
|
+
* for its own deployment and initialization.
|
|
136
|
+
*
|
|
137
|
+
* For more details on how the fee payment routing works see documentation of AccountEntrypointMetaPaymentMethod class.
|
|
138
|
+
*
|
|
139
|
+
* @param originalPaymentMethod - originalPaymentMethod The original payment method to be wrapped.
|
|
140
|
+
* @returns A FeePaymentMethod that routes the original one through the account's entrypoint (AccountEntrypointMetaPaymentMethod)
|
|
141
|
+
*/ async #getSelfPaymentMethod(originalPaymentMethod) {
|
|
142
|
+
const artifact = await this.accountContract.getContractArtifact();
|
|
143
|
+
const wallet = await this.getWallet();
|
|
144
|
+
const address = wallet.getAddress();
|
|
145
|
+
return new AccountEntrypointMetaPaymentMethod(artifact, wallet, 'entrypoint', address, originalPaymentMethod ?? new FeeJuicePaymentMethod(address));
|
|
131
146
|
}
|
|
132
147
|
/**
|
|
133
148
|
* Deploys the account contract that backs this account.
|
|
@@ -137,17 +152,53 @@ import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
|
|
|
137
152
|
* @param opts - Fee options to be used for the deployment.
|
|
138
153
|
* @returns A SentTx object that can be waited to get the associated Wallet.
|
|
139
154
|
*/ deploy(opts) {
|
|
140
|
-
|
|
155
|
+
let deployMethod;
|
|
156
|
+
const sentTx = this.#getDeployMethod(opts?.deployWallet).then((method)=>{
|
|
157
|
+
deployMethod = method;
|
|
158
|
+
if (!opts?.deployWallet && opts?.fee) {
|
|
159
|
+
return this.#getSelfPaymentMethod(opts?.fee?.paymentMethod);
|
|
160
|
+
}
|
|
161
|
+
}).then((maybeWrappedPaymentMethod)=>{
|
|
162
|
+
let fee = opts?.fee;
|
|
163
|
+
if (maybeWrappedPaymentMethod) {
|
|
164
|
+
fee = {
|
|
165
|
+
...opts?.fee,
|
|
166
|
+
paymentMethod: maybeWrappedPaymentMethod
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return deployMethod.send({
|
|
141
170
|
contractAddressSalt: new Fr(this.salt),
|
|
142
171
|
skipClassRegistration: opts?.skipClassRegistration ?? true,
|
|
143
172
|
skipPublicDeployment: opts?.skipPublicDeployment ?? true,
|
|
144
173
|
skipInitialization: opts?.skipInitialization ?? false,
|
|
145
174
|
universalDeploy: true,
|
|
146
|
-
fee
|
|
147
|
-
})
|
|
175
|
+
fee
|
|
176
|
+
});
|
|
177
|
+
}).then((tx)=>tx.getTxHash());
|
|
148
178
|
return new DeployAccountSentTx(this.pxe, sentTx, this.getWallet());
|
|
149
179
|
}
|
|
150
180
|
/**
|
|
181
|
+
* Estimates the gas needed to deploy the account contract that backs this account.
|
|
182
|
+
* This method is here to ensure that the fee payment method is correctly set up in case
|
|
183
|
+
* the account contract needs to pay for its own deployment.
|
|
184
|
+
* @param opts - Fee options to be used for the deployment.
|
|
185
|
+
* @returns The gas estimations for the account contract deployment and initialization.
|
|
186
|
+
*/ async estimateDeploymentGas(opts) {
|
|
187
|
+
const deployMethod = await this.#getDeployMethod(opts?.deployWallet);
|
|
188
|
+
const fee = !opts?.deployWallet && opts?.fee ? {
|
|
189
|
+
...opts.fee,
|
|
190
|
+
paymentMethod: await this.#getSelfPaymentMethod(opts.fee.paymentMethod)
|
|
191
|
+
} : opts?.fee;
|
|
192
|
+
return deployMethod.estimateGas({
|
|
193
|
+
contractAddressSalt: new Fr(this.salt),
|
|
194
|
+
skipClassRegistration: opts?.skipClassRegistration ?? true,
|
|
195
|
+
skipPublicDeployment: opts?.skipPublicDeployment ?? true,
|
|
196
|
+
skipInitialization: opts?.skipInitialization ?? false,
|
|
197
|
+
universalDeploy: true,
|
|
198
|
+
fee
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
151
202
|
* Deploys the account contract that backs this account if needed and awaits the tx to be mined.
|
|
152
203
|
* Uses the salt provided in the constructor or a randomly generated one. If no initialization
|
|
153
204
|
* is required it skips the transaction, and only registers the account in the PXE Service.
|
|
@@ -1,4 +1,3 @@
|
|
|
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';
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/account_manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/account_manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,KAAK,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dest/api/fee.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ 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';
|
|
6
7
|
//# sourceMappingURL=fee.d.ts.map
|
package/dest/api/fee.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fee.d.ts","sourceRoot":"","sources":["../../src/api/fee.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAC"}
|
|
1
|
+
{"version":3,"file":"fee.d.ts","sourceRoot":"","sources":["../../src/api/fee.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC"}
|
package/dest/api/fee.js
CHANGED
|
@@ -2,3 +2,4 @@ export { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
|
|
|
2
2
|
export { PrivateFeePaymentMethod } from '../fee/private_fee_payment_method.js';
|
|
3
3
|
export { PublicFeePaymentMethod } from '../fee/public_fee_payment_method.js';
|
|
4
4
|
export { FeeJuicePaymentMethodWithClaim } from '../fee/fee_juice_payment_method_with_claim.js';
|
|
5
|
+
export { SponsoredFeePaymentMethod } from '../fee/sponsored_fee_payment.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee_testing.d.ts","sourceRoot":"","sources":["../../src/api/fee_testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SponsoredFeePaymentMethod } from '../fee/sponsored_fee_payment.js';
|
|
@@ -12,7 +12,7 @@ import { ProvenTx } from './proven_tx.js';
|
|
|
12
12
|
* Sends the transaction to the network via the provided wallet.
|
|
13
13
|
*/ send() {
|
|
14
14
|
const promise = (()=>{
|
|
15
|
-
return this.wallet.sendTx(this
|
|
15
|
+
return this.wallet.sendTx(this);
|
|
16
16
|
})();
|
|
17
17
|
return new DeploySentTx(this.wallet, promise, this.postDeployCtor, this.instanceGetter);
|
|
18
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proven_tx.d.ts","sourceRoot":"","sources":["../../src/contract/proven_tx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;GAEG;AACH,qBAAa,QAAS,SAAQ,EAAE;IAClB,SAAS,CAAC,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"proven_tx.d.ts","sourceRoot":"","sources":["../../src/contract/proven_tx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;GAEG;AACH,qBAAa,QAAS,SAAQ,EAAE;IAClB,SAAS,CAAC,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE;IAI5C;;OAEG;IACI,IAAI,IAAI,MAAM;CAOtB"}
|
|
@@ -5,17 +5,13 @@ import { SentTx } from './sent_tx.js';
|
|
|
5
5
|
*/ export class ProvenTx extends Tx {
|
|
6
6
|
wallet;
|
|
7
7
|
constructor(wallet, tx){
|
|
8
|
-
super(tx.data, tx.clientIvcProof, tx.contractClassLogs, tx.
|
|
9
|
-
}
|
|
10
|
-
// Clone the TX data to get a serializable object.
|
|
11
|
-
getPlainDataTx() {
|
|
12
|
-
return new Tx(this.data, this.clientIvcProof, this.contractClassLogs, this.enqueuedPublicFunctionCalls, this.publicTeardownFunctionCall);
|
|
8
|
+
super(tx.data, tx.clientIvcProof, tx.contractClassLogs, tx.publicFunctionCalldata), this.wallet = wallet;
|
|
13
9
|
}
|
|
14
10
|
/**
|
|
15
11
|
* Sends the transaction to the network via the provided wallet.
|
|
16
12
|
*/ send() {
|
|
17
13
|
const promise = (()=>{
|
|
18
|
-
return this.wallet.sendTx(this
|
|
14
|
+
return this.wallet.sendTx(this);
|
|
19
15
|
})();
|
|
20
16
|
return new SentTx(this.wallet, promise);
|
|
21
17
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AuthWitnessProvider, FeePaymentMethod } from '@aztec/entrypoints/interfaces';
|
|
2
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
3
|
+
import { type ContractArtifact, type FunctionArtifact } from '@aztec/stdlib/abi';
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
6
|
+
/**
|
|
7
|
+
* Fee payment method that allows a contract to pay for its own deployment
|
|
8
|
+
* It works by rerouting the provided fee payment method through the account's entrypoint,
|
|
9
|
+
* which sets itself as fee payer.
|
|
10
|
+
*
|
|
11
|
+
* Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
|
|
12
|
+
* that is sent to the user's account entrypoint, that has plumbing to handle a fee payload.
|
|
13
|
+
* If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
|
|
14
|
+
* how to handle this payload.
|
|
15
|
+
* HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
|
|
16
|
+
* being deployed with the original fee payload.
|
|
17
|
+
*
|
|
18
|
+
* This class can be seen in action in AccountManager.ts#getSelfPaymentMethod
|
|
19
|
+
*/
|
|
20
|
+
export declare class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
|
|
21
|
+
private artifact;
|
|
22
|
+
private authWitnessProvider;
|
|
23
|
+
private feePaymentNameOrArtifact;
|
|
24
|
+
private accountAddress;
|
|
25
|
+
private paymentMethod;
|
|
26
|
+
constructor(artifact: ContractArtifact, authWitnessProvider: AuthWitnessProvider, feePaymentNameOrArtifact: string | FunctionArtifact, accountAddress: AztecAddress, paymentMethod: FeePaymentMethod);
|
|
27
|
+
getAsset(): Promise<AztecAddress>;
|
|
28
|
+
getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload>;
|
|
29
|
+
getFeePayer(gasSettings: GasSettings): Promise<AztecAddress>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=account_entrypoint_meta_payment_method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account_entrypoint_meta_payment_method.d.ts","sourceRoot":"","sources":["../../src/fee/account_entrypoint_meta_payment_method.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAKtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,qBAAa,kCAAmC,YAAW,gBAAgB;IAEvE,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,wBAAwB;IAChC,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,aAAa;gBAJb,QAAQ,EAAE,gBAAgB,EAC1B,mBAAmB,EAAE,mBAAmB,EACxC,wBAAwB,EAAE,MAAM,GAAG,gBAAgB,EACnD,cAAc,EAAE,YAAY,EAC5B,aAAa,EAAE,gBAAgB;IAGzC,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC;IAI3B,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyC9E,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAG7D"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EncodedAppEntrypointCalls, EncodedCallsForEntrypoint, computeCombinedPayloadHash } from '@aztec/entrypoints/encoding';
|
|
2
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
3
|
+
import { FunctionCall, FunctionSelector, encodeArguments, getFunctionArtifactByName } from '@aztec/stdlib/abi';
|
|
4
|
+
/**
|
|
5
|
+
* Fee payment method that allows a contract to pay for its own deployment
|
|
6
|
+
* It works by rerouting the provided fee payment method through the account's entrypoint,
|
|
7
|
+
* which sets itself as fee payer.
|
|
8
|
+
*
|
|
9
|
+
* Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
|
|
10
|
+
* that is sent to the user's account entrypoint, that has plumbing to handle a fee payload.
|
|
11
|
+
* If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
|
|
12
|
+
* how to handle this payload.
|
|
13
|
+
* HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
|
|
14
|
+
* being deployed with the original fee payload.
|
|
15
|
+
*
|
|
16
|
+
* This class can be seen in action in AccountManager.ts#getSelfPaymentMethod
|
|
17
|
+
*/ export class AccountEntrypointMetaPaymentMethod {
|
|
18
|
+
artifact;
|
|
19
|
+
authWitnessProvider;
|
|
20
|
+
feePaymentNameOrArtifact;
|
|
21
|
+
accountAddress;
|
|
22
|
+
paymentMethod;
|
|
23
|
+
constructor(artifact, authWitnessProvider, feePaymentNameOrArtifact, accountAddress, paymentMethod){
|
|
24
|
+
this.artifact = artifact;
|
|
25
|
+
this.authWitnessProvider = authWitnessProvider;
|
|
26
|
+
this.feePaymentNameOrArtifact = feePaymentNameOrArtifact;
|
|
27
|
+
this.accountAddress = accountAddress;
|
|
28
|
+
this.paymentMethod = paymentMethod;
|
|
29
|
+
}
|
|
30
|
+
getAsset() {
|
|
31
|
+
return this.paymentMethod.getAsset();
|
|
32
|
+
}
|
|
33
|
+
async getExecutionPayload(gasSettings) {
|
|
34
|
+
const emptyAppCalls = await EncodedAppEntrypointCalls.fromAppExecution([]);
|
|
35
|
+
// Get the execution payload for the fee, it includes the calls and potentially authWitnesses
|
|
36
|
+
const { calls: feeCalls, authWitnesses: feeAuthwitnesses } = await this.paymentMethod.getExecutionPayload(gasSettings);
|
|
37
|
+
// Encode the calls for the fee
|
|
38
|
+
const feePayer = await this.paymentMethod.getFeePayer(gasSettings);
|
|
39
|
+
const isFeePayer = feePayer.equals(this.accountAddress);
|
|
40
|
+
const feeEncodedCalls = await EncodedCallsForEntrypoint.fromFeeCalls(feeCalls, isFeePayer);
|
|
41
|
+
// Get the entrypoint args
|
|
42
|
+
const args = [
|
|
43
|
+
emptyAppCalls,
|
|
44
|
+
feeEncodedCalls,
|
|
45
|
+
false
|
|
46
|
+
];
|
|
47
|
+
const feePaymentArtifact = typeof this.feePaymentNameOrArtifact === 'string' ? getFunctionArtifactByName(this.artifact, this.feePaymentNameOrArtifact) : this.feePaymentNameOrArtifact;
|
|
48
|
+
const entrypointCall = new FunctionCall(feePaymentArtifact.name, this.accountAddress, await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters), feePaymentArtifact.functionType, feePaymentArtifact.isStatic, encodeArguments(feePaymentArtifact, args), feePaymentArtifact.returnTypes);
|
|
49
|
+
// Compute the authwitness required to verify the combined payload
|
|
50
|
+
const combinedPayloadAuthWitness = await this.authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(emptyAppCalls, feeEncodedCalls));
|
|
51
|
+
return new ExecutionPayload([
|
|
52
|
+
entrypointCall
|
|
53
|
+
], [
|
|
54
|
+
combinedPayloadAuthWitness,
|
|
55
|
+
...feeAuthwitnesses
|
|
56
|
+
], [], [
|
|
57
|
+
...emptyAppCalls.hashedArguments,
|
|
58
|
+
...feeEncodedCalls.hashedArguments
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
getFeePayer(gasSettings) {
|
|
62
|
+
return this.paymentMethod.getFeePayer(gasSettings);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
2
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
/**
|
|
5
|
+
* A fee payment method that uses a contract that blindly sponsors transactions.
|
|
6
|
+
* This contract is expected to be prefunded in testing environments.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SponsoredFeePaymentMethod implements FeePaymentMethod {
|
|
9
|
+
private paymentContract;
|
|
10
|
+
constructor(paymentContract: AztecAddress);
|
|
11
|
+
getAsset(): Promise<AztecAddress>;
|
|
12
|
+
getFeePayer(): Promise<AztecAddress>;
|
|
13
|
+
getExecutionPayload(): Promise<ExecutionPayload>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=sponsored_fee_payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sponsored_fee_payment.d.ts","sourceRoot":"","sources":["../../src/fee/sponsored_fee_payment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;;GAGG;AACH,qBAAa,yBAA0B,YAAW,gBAAgB;IACpD,OAAO,CAAC,eAAe;gBAAf,eAAe,EAAE,YAAY;IAEjD,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC;IAIjC,WAAW;IAIL,mBAAmB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAiBvD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
2
|
+
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
3
|
+
/**
|
|
4
|
+
* A fee payment method that uses a contract that blindly sponsors transactions.
|
|
5
|
+
* This contract is expected to be prefunded in testing environments.
|
|
6
|
+
*/ export class SponsoredFeePaymentMethod {
|
|
7
|
+
paymentContract;
|
|
8
|
+
constructor(paymentContract){
|
|
9
|
+
this.paymentContract = paymentContract;
|
|
10
|
+
}
|
|
11
|
+
getAsset() {
|
|
12
|
+
throw new Error('Asset is not required for sponsored fpc.');
|
|
13
|
+
}
|
|
14
|
+
getFeePayer() {
|
|
15
|
+
return Promise.resolve(this.paymentContract);
|
|
16
|
+
}
|
|
17
|
+
async getExecutionPayload() {
|
|
18
|
+
return new ExecutionPayload([
|
|
19
|
+
{
|
|
20
|
+
name: 'sponsor_unconditionally',
|
|
21
|
+
to: this.paymentContract,
|
|
22
|
+
selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
|
|
23
|
+
type: FunctionType.PRIVATE,
|
|
24
|
+
isStatic: false,
|
|
25
|
+
args: [],
|
|
26
|
+
returnTypes: []
|
|
27
|
+
}
|
|
28
|
+
], [], []);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authwit.d.ts","sourceRoot":"","sources":["../../src/utils/authwit.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAE3F,8BAA8B;AAC9B,MAAM,MAAM,cAAc,GAAG;IAC3B,8BAA8B;IAC9B,OAAO,EAAE,EAAE,CAAC;IACZ,8BAA8B;IAC9B,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,gCAAgC;AAChC,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB;IACrB,QAAQ,EAAE,YAAY,CAAC;IACvB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC;CACxB,CAAC;AAEF,4BAA4B;AAC5B,MAAM,MAAM,YAAY,GAAG;IACzB,6BAA6B;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,4BAA4B;IAC5B,MAAM,EAAE,2BAA2B,GAAG,YAAY,CAAC;CACpD,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,yBAAyB,WAAkB,eAAe,GAAG,YAAY,YAAY,cAAc,gBAiB/G,CAAC;AAGF;;;;;;IAMI;AACJ,eAAO,MAAM,uCAAuC,WAAkB,YAAY,UAAU,YAAY,
|
|
1
|
+
{"version":3,"file":"authwit.d.ts","sourceRoot":"","sources":["../../src/utils/authwit.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAE3F,8BAA8B;AAC9B,MAAM,MAAM,cAAc,GAAG;IAC3B,8BAA8B;IAC9B,OAAO,EAAE,EAAE,CAAC;IACZ,8BAA8B;IAC9B,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,gCAAgC;AAChC,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB;IACrB,QAAQ,EAAE,YAAY,CAAC;IACvB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC;CACxB,CAAC;AAEF,4BAA4B;AAC5B,MAAM,MAAM,YAAY,GAAG;IACzB,6BAA6B;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,4BAA4B;IAC5B,MAAM,EAAE,2BAA2B,GAAG,YAAY,CAAC;CACpD,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,yBAAyB,WAAkB,eAAe,GAAG,YAAY,YAAY,cAAc,gBAiB/G,CAAC;AAGF;;;;;;IAMI;AACJ,eAAO,MAAM,uCAAuC,WAAkB,YAAY,UAAU,YAAY,gBAEvG,CAAC;AAEF;;;;;;;IAOI;AACJ,eAAO,MAAM,iCAAiC,WACpC,YAAY,UACZ,YAAY,GAAG,2BAA2B,gBAInD,CAAC"}
|
package/dest/utils/authwit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
|
|
3
|
-
import {
|
|
3
|
+
import { computeVarArgsHash } from '@aztec/stdlib/hash';
|
|
4
4
|
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
5
5
|
// docs:start:authwit_computeAuthWitMessageHash
|
|
6
6
|
/**
|
|
@@ -45,7 +45,7 @@ import { ContractFunctionInteraction } from '../contract/contract_function_inter
|
|
|
45
45
|
return computeInnerAuthWitHash([
|
|
46
46
|
caller.toField(),
|
|
47
47
|
fnCall.selector.toField(),
|
|
48
|
-
|
|
48
|
+
await computeVarArgsHash(fnCall.args)
|
|
49
49
|
]);
|
|
50
50
|
};
|
|
51
51
|
/**
|
|
@@ -60,6 +60,6 @@ import { ContractFunctionInteraction } from '../contract/contract_function_inter
|
|
|
60
60
|
return computeInnerAuthWitHash([
|
|
61
61
|
caller.toField(),
|
|
62
62
|
action.selector.toField(),
|
|
63
|
-
|
|
63
|
+
await computeVarArgsHash(action.args)
|
|
64
64
|
]);
|
|
65
65
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/aztec.js",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec.js",
|
|
4
|
-
"version": "0.82.
|
|
4
|
+
"version": "0.82.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dest/index.js",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"./tx_hash": "./dest/api/tx_hash.js",
|
|
24
24
|
"./wallet": "./dest/api/wallet.js",
|
|
25
25
|
"./utils": "./dest/api/utils.js",
|
|
26
|
-
"./testing": "./dest/api/testing.js"
|
|
26
|
+
"./testing": "./dest/api/testing.js",
|
|
27
|
+
"./fee/testing": "./dest/api/fee_testing.js"
|
|
27
28
|
},
|
|
28
29
|
"typedocOptions": {
|
|
29
30
|
"entryPoints": [
|
|
@@ -79,13 +80,13 @@
|
|
|
79
80
|
]
|
|
80
81
|
},
|
|
81
82
|
"dependencies": {
|
|
82
|
-
"@aztec/constants": "0.82.
|
|
83
|
-
"@aztec/entrypoints": "0.82.
|
|
84
|
-
"@aztec/ethereum": "0.82.
|
|
85
|
-
"@aztec/foundation": "0.82.
|
|
86
|
-
"@aztec/l1-artifacts": "0.82.
|
|
87
|
-
"@aztec/protocol-contracts": "0.82.
|
|
88
|
-
"@aztec/stdlib": "0.82.
|
|
83
|
+
"@aztec/constants": "0.82.1",
|
|
84
|
+
"@aztec/entrypoints": "0.82.1",
|
|
85
|
+
"@aztec/ethereum": "0.82.1",
|
|
86
|
+
"@aztec/foundation": "0.82.1",
|
|
87
|
+
"@aztec/l1-artifacts": "0.82.1",
|
|
88
|
+
"@aztec/protocol-contracts": "0.82.1",
|
|
89
|
+
"@aztec/stdlib": "0.82.1",
|
|
89
90
|
"axios": "^1.7.2",
|
|
90
91
|
"tslib": "^2.4.0",
|
|
91
92
|
"viem": "2.23.7"
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { DefaultMultiCallEntrypoint } from '@aztec/entrypoints/multicall';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import { CompleteAddress, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
3
4
|
import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
4
6
|
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
5
7
|
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
6
8
|
|
|
@@ -10,9 +12,9 @@ import type { AccountInterface } from '../account/interface.js';
|
|
|
10
12
|
import { Contract } from '../contract/contract.js';
|
|
11
13
|
import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js';
|
|
12
14
|
import { DefaultWaitOpts, type WaitOpts } from '../contract/sent_tx.js';
|
|
13
|
-
import {
|
|
15
|
+
import { AccountEntrypointMetaPaymentMethod } from '../fee/account_entrypoint_meta_payment_method.js';
|
|
16
|
+
import { FeeJuicePaymentMethod, type FeePaymentMethod } from '../index.js';
|
|
14
17
|
import { AccountWalletWithSecretKey, SignerlessWallet, type Wallet } from '../wallet/index.js';
|
|
15
|
-
import { DeployAccountMethod } from './deploy_account_method.js';
|
|
16
18
|
import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -139,12 +141,11 @@ export class AccountManager {
|
|
|
139
141
|
|
|
140
142
|
/**
|
|
141
143
|
* Returns the pre-populated deployment method to deploy the account contract that backs this account.
|
|
142
|
-
*
|
|
143
|
-
* grained control on when to create, simulate, and send the deployment tx.
|
|
144
|
+
* If no wallet is provided, it uses a signerless wallet with the multi call entrypoint
|
|
144
145
|
* @param deployWallet - Wallet used for deploying the account contract.
|
|
145
|
-
* @returns A DeployMethod instance that deploys this account contract
|
|
146
|
+
* @returns A DeployMethod instance that deploys this account contract
|
|
146
147
|
*/
|
|
147
|
-
|
|
148
|
+
async #getDeployMethod(deployWallet?: Wallet): Promise<DeployMethod> {
|
|
148
149
|
const artifact = await this.accountContract.getContractArtifact();
|
|
149
150
|
|
|
150
151
|
if (!(await this.isDeployable())) {
|
|
@@ -179,14 +180,36 @@ export class AccountManager {
|
|
|
179
180
|
// and it can't be used unless the contract is initialized.
|
|
180
181
|
const wallet = new SignerlessWallet(this.pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion));
|
|
181
182
|
|
|
182
|
-
return new
|
|
183
|
-
this.accountContract.getAuthWitnessProvider(completeAddress),
|
|
183
|
+
return new DeployMethod(
|
|
184
184
|
this.getPublicKeys(),
|
|
185
185
|
wallet,
|
|
186
186
|
artifact,
|
|
187
|
+
address => Contract.at(address, artifact, wallet),
|
|
187
188
|
constructorArgs,
|
|
188
189
|
constructorName,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Returns a FeePaymentMethod that routes the original one provided as an argument
|
|
195
|
+
* through the account's entrypoint. This allows an account contract to pay
|
|
196
|
+
* for its own deployment and initialization.
|
|
197
|
+
*
|
|
198
|
+
* For more details on how the fee payment routing works see documentation of AccountEntrypointMetaPaymentMethod class.
|
|
199
|
+
*
|
|
200
|
+
* @param originalPaymentMethod - originalPaymentMethod The original payment method to be wrapped.
|
|
201
|
+
* @returns A FeePaymentMethod that routes the original one through the account's entrypoint (AccountEntrypointMetaPaymentMethod)
|
|
202
|
+
*/
|
|
203
|
+
async #getSelfPaymentMethod(originalPaymentMethod?: FeePaymentMethod) {
|
|
204
|
+
const artifact = await this.accountContract.getContractArtifact();
|
|
205
|
+
const wallet = await this.getWallet();
|
|
206
|
+
const address = wallet.getAddress();
|
|
207
|
+
return new AccountEntrypointMetaPaymentMethod(
|
|
208
|
+
artifact,
|
|
209
|
+
wallet,
|
|
189
210
|
'entrypoint',
|
|
211
|
+
address,
|
|
212
|
+
originalPaymentMethod ?? new FeeJuicePaymentMethod(address),
|
|
190
213
|
);
|
|
191
214
|
}
|
|
192
215
|
|
|
@@ -199,21 +222,57 @@ export class AccountManager {
|
|
|
199
222
|
* @returns A SentTx object that can be waited to get the associated Wallet.
|
|
200
223
|
*/
|
|
201
224
|
public deploy(opts?: DeployAccountOptions): DeployAccountSentTx {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
225
|
+
let deployMethod: DeployMethod;
|
|
226
|
+
const sentTx = this.#getDeployMethod(opts?.deployWallet)
|
|
227
|
+
.then(method => {
|
|
228
|
+
deployMethod = method;
|
|
229
|
+
if (!opts?.deployWallet && opts?.fee) {
|
|
230
|
+
return this.#getSelfPaymentMethod(opts?.fee?.paymentMethod);
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
.then(maybeWrappedPaymentMethod => {
|
|
234
|
+
let fee = opts?.fee;
|
|
235
|
+
if (maybeWrappedPaymentMethod) {
|
|
236
|
+
fee = { ...opts?.fee, paymentMethod: maybeWrappedPaymentMethod };
|
|
237
|
+
}
|
|
238
|
+
return deployMethod.send({
|
|
205
239
|
contractAddressSalt: new Fr(this.salt),
|
|
206
240
|
skipClassRegistration: opts?.skipClassRegistration ?? true,
|
|
207
241
|
skipPublicDeployment: opts?.skipPublicDeployment ?? true,
|
|
208
242
|
skipInitialization: opts?.skipInitialization ?? false,
|
|
209
243
|
universalDeploy: true,
|
|
210
|
-
fee
|
|
211
|
-
})
|
|
212
|
-
)
|
|
244
|
+
fee,
|
|
245
|
+
});
|
|
246
|
+
})
|
|
213
247
|
.then(tx => tx.getTxHash());
|
|
214
248
|
return new DeployAccountSentTx(this.pxe, sentTx, this.getWallet());
|
|
215
249
|
}
|
|
216
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Estimates the gas needed to deploy the account contract that backs this account.
|
|
253
|
+
* This method is here to ensure that the fee payment method is correctly set up in case
|
|
254
|
+
* the account contract needs to pay for its own deployment.
|
|
255
|
+
* @param opts - Fee options to be used for the deployment.
|
|
256
|
+
* @returns The gas estimations for the account contract deployment and initialization.
|
|
257
|
+
*/
|
|
258
|
+
public async estimateDeploymentGas(
|
|
259
|
+
opts?: DeployAccountOptions,
|
|
260
|
+
): Promise<Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>> {
|
|
261
|
+
const deployMethod = await this.#getDeployMethod(opts?.deployWallet);
|
|
262
|
+
const fee =
|
|
263
|
+
!opts?.deployWallet && opts?.fee
|
|
264
|
+
? { ...opts.fee, paymentMethod: await this.#getSelfPaymentMethod(opts.fee.paymentMethod) }
|
|
265
|
+
: opts?.fee;
|
|
266
|
+
return deployMethod.estimateGas({
|
|
267
|
+
contractAddressSalt: new Fr(this.salt),
|
|
268
|
+
skipClassRegistration: opts?.skipClassRegistration ?? true,
|
|
269
|
+
skipPublicDeployment: opts?.skipPublicDeployment ?? true,
|
|
270
|
+
skipInitialization: opts?.skipInitialization ?? false,
|
|
271
|
+
universalDeploy: true,
|
|
272
|
+
fee,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
217
276
|
/**
|
|
218
277
|
* Deploys the account contract that backs this account if needed and awaits the tx to be mined.
|
|
219
278
|
* Uses the salt provided in the constructor or a randomly generated one. If no initialization
|