@aztec/wallets 5.0.0-patched.20260318 → 5.0.0-private.20260319
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.
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { type Account } from '@aztec/aztec.js/account';
|
|
2
|
-
import type
|
|
2
|
+
import { type InteractionWaitOptions, type SendReturn } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import type { Aliased, SendOptions } from '@aztec/aztec.js/wallet';
|
|
3
4
|
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
4
5
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
5
6
|
import type { Logger } from '@aztec/foundation/log';
|
|
6
|
-
import type {
|
|
7
|
+
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
7
8
|
import type { PXE } from '@aztec/pxe/server';
|
|
8
9
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
10
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
10
11
|
import { ExecutionPayload, type TxSimulationResult } from '@aztec/stdlib/tx';
|
|
11
|
-
import { BaseWallet, type
|
|
12
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
12
13
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
13
14
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
14
15
|
export type EmbeddedWalletOptions = {
|
|
@@ -24,17 +25,24 @@ export type EmbeddedWalletOptions = {
|
|
|
24
25
|
export declare class EmbeddedWallet extends BaseWallet {
|
|
25
26
|
protected walletDB: WalletDB;
|
|
26
27
|
protected accountContracts: AccountContractsProvider;
|
|
28
|
+
protected estimatedGasPadding: number;
|
|
27
29
|
constructor(pxe: PXE, aztecNode: AztecNode, walletDB: WalletDB, accountContracts: AccountContractsProvider, log?: Logger);
|
|
28
30
|
protected getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
29
31
|
getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
30
32
|
registerSender(address: AztecAddress, alias: string): Promise<AztecAddress>;
|
|
31
33
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
36
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
37
|
+
* the necessary authwitnesses.
|
|
38
|
+
*/
|
|
39
|
+
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
32
40
|
/**
|
|
33
41
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
34
42
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
35
43
|
* private kernel circuit execution.
|
|
36
44
|
*/
|
|
37
|
-
protected simulateViaEntrypoint(executionPayload: ExecutionPayload,
|
|
45
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions): Promise<TxSimulationResult>;
|
|
38
46
|
private getFakeAccountDataFor;
|
|
39
47
|
protected createAccountInternal(type: AccountType, secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
|
|
40
48
|
createAndStoreAccount(alias: string, type: AccountType, secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
|
|
@@ -42,6 +50,7 @@ export declare class EmbeddedWallet extends BaseWallet {
|
|
|
42
50
|
createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager>;
|
|
43
51
|
createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager>;
|
|
44
52
|
setMinFeePadding(value?: number): void;
|
|
53
|
+
setEstimatedGasPadding(value?: number): void;
|
|
45
54
|
stop(): Promise<void>;
|
|
46
55
|
}
|
|
47
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
56
|
+
//# sourceMappingURL=data:application/json;base64,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BQUUsSUFBSSxFQUFFLEVBQUUsRUFBRSxVQUFVLEVBQUUsTUFBTSxFQUFFLEtBQUssQ0FBQyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsY0FBYyxDQUFDLENBRXJHO0lBRUQsbUJBQW1CLENBQUMsTUFBTSxFQUFFLEVBQUUsRUFBRSxJQUFJLEVBQUUsRUFBRSxFQUFFLFVBQVUsRUFBRSxNQUFNLEVBQUUsS0FBSyxDQUFDLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FFckc7SUFFRCxnQkFBZ0IsQ0FBQyxLQUFLLENBQUMsRUFBRSxNQUFNLFFBRTlCO0lBRUQsc0JBQXNCLENBQUMsS0FBSyxDQUFDLEVBQUUsTUFBTSxRQUVwQztJQUVELElBQUksa0JBRUg7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedded_wallet.d.ts","sourceRoot":"","sources":["../../src/embedded/embedded_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAqB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"embedded_wallet.d.ts","sourceRoot":"","sources":["../../src/embedded/embedded_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAqB,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAAE,KAAK,sBAAsB,EAAE,KAAK,UAAU,EAAgB,MAAM,2BAA2B,CAAC;AACvG,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,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,EAAE,MAAM,QAE9B;IAED,sBAAsB,CAAC,KAAK,CAAC,EAAE,MAAM,QAEpC;IAED,IAAI,kBAEH;CACF"}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { SignerlessAccount } from '@aztec/aztec.js/account';
|
|
2
|
+
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { getGasLimits } from '@aztec/aztec.js/contracts';
|
|
2
4
|
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
3
5
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
4
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
7
|
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
8
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
6
9
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
7
|
-
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
10
|
+
import { collectOffchainEffects, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
8
11
|
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
12
|
+
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
9
13
|
export class EmbeddedWallet extends BaseWallet {
|
|
10
14
|
walletDB;
|
|
11
15
|
accountContracts;
|
|
16
|
+
estimatedGasPadding;
|
|
12
17
|
constructor(pxe, aztecNode, walletDB, accountContracts, log){
|
|
13
|
-
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts;
|
|
18
|
+
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
14
19
|
}
|
|
15
20
|
async getAccountFromAddress(address) {
|
|
16
21
|
if (address.equals(AztecAddress.ZERO)) {
|
|
@@ -42,10 +47,59 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
42
47
|
return storedSenders;
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
50
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
51
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
52
|
+
* the necessary authwitnesses.
|
|
53
|
+
*/ async sendTx(executionPayload, opts) {
|
|
54
|
+
const feeOptions = await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
55
|
+
// Simulate the transaction first to estimate gas and capture required
|
|
56
|
+
// private authwitnesses based on offchain effects.
|
|
57
|
+
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
58
|
+
from: opts.from,
|
|
59
|
+
feeOptions,
|
|
60
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
61
|
+
skipTxValidation: true
|
|
62
|
+
});
|
|
63
|
+
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
64
|
+
const authWitnesses = await Promise.all(offchainEffects.map(async (effect)=>{
|
|
65
|
+
try {
|
|
66
|
+
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
67
|
+
return this.createAuthWit(opts.from, {
|
|
68
|
+
consumer: effect.contractAddress,
|
|
69
|
+
innerHash: authRequest.innerHash
|
|
70
|
+
});
|
|
71
|
+
} catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
for (const authwit of authWitnesses){
|
|
76
|
+
if (authwit) {
|
|
77
|
+
executionPayload.authWitnesses.push(authwit);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const estimated = getGasLimits(simulationResult, this.estimatedGasPadding);
|
|
81
|
+
this.log.verbose(`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`);
|
|
82
|
+
const gasSettings = GasSettings.from({
|
|
83
|
+
...opts.fee?.gasSettings,
|
|
84
|
+
maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
|
|
85
|
+
maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
|
|
86
|
+
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
87
|
+
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits
|
|
88
|
+
});
|
|
89
|
+
return super.sendTx(executionPayload, {
|
|
90
|
+
...opts,
|
|
91
|
+
fee: {
|
|
92
|
+
...opts.fee,
|
|
93
|
+
gasSettings
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
45
98
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
46
99
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
47
100
|
* private kernel circuit execution.
|
|
48
|
-
*/ async simulateViaEntrypoint(executionPayload,
|
|
101
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
102
|
+
const { from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement } = opts;
|
|
49
103
|
let overrides;
|
|
50
104
|
let fromAccount;
|
|
51
105
|
if (!from.equals(AztecAddress.ZERO)) {
|
|
@@ -159,6 +213,9 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
159
213
|
setMinFeePadding(value) {
|
|
160
214
|
this.minFeePadding = value ?? 0.5;
|
|
161
215
|
}
|
|
216
|
+
setEstimatedGasPadding(value) {
|
|
217
|
+
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
218
|
+
}
|
|
162
219
|
stop() {
|
|
163
220
|
return this.pxe.stop();
|
|
164
221
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wallets",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallets",
|
|
4
|
-
"version": "5.0.0-
|
|
4
|
+
"version": "5.0.0-private.20260319",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./embedded": {
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"../package.common.json"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@aztec/accounts": "5.0.0-
|
|
31
|
-
"@aztec/aztec.js": "5.0.0-
|
|
32
|
-
"@aztec/entrypoints": "5.0.0-
|
|
33
|
-
"@aztec/foundation": "5.0.0-
|
|
34
|
-
"@aztec/kv-store": "5.0.0-
|
|
35
|
-
"@aztec/protocol-contracts": "5.0.0-
|
|
36
|
-
"@aztec/pxe": "5.0.0-
|
|
37
|
-
"@aztec/stdlib": "5.0.0-
|
|
38
|
-
"@aztec/wallet-sdk": "5.0.0-
|
|
30
|
+
"@aztec/accounts": "5.0.0-private.20260319",
|
|
31
|
+
"@aztec/aztec.js": "5.0.0-private.20260319",
|
|
32
|
+
"@aztec/entrypoints": "5.0.0-private.20260319",
|
|
33
|
+
"@aztec/foundation": "5.0.0-private.20260319",
|
|
34
|
+
"@aztec/kv-store": "5.0.0-private.20260319",
|
|
35
|
+
"@aztec/protocol-contracts": "5.0.0-private.20260319",
|
|
36
|
+
"@aztec/pxe": "5.0.0-private.20260319",
|
|
37
|
+
"@aztec/stdlib": "5.0.0-private.20260319",
|
|
38
|
+
"@aztec/wallet-sdk": "5.0.0-private.20260319"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@jest/globals": "^30.0.0",
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import { type Account, SignerlessAccount } from '@aztec/aztec.js/account';
|
|
2
|
-
import
|
|
2
|
+
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { type InteractionWaitOptions, type SendReturn, getGasLimits } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import type { Aliased, SendOptions } from '@aztec/aztec.js/wallet';
|
|
3
5
|
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
4
6
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
5
7
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
6
8
|
import type { Logger } from '@aztec/foundation/log';
|
|
7
|
-
import type {
|
|
9
|
+
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
8
10
|
import type { PXE } from '@aztec/pxe/server';
|
|
9
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
12
|
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
13
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
11
14
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
12
15
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
13
16
|
import {
|
|
14
17
|
ExecutionPayload,
|
|
15
18
|
SimulationOverrides,
|
|
16
19
|
type TxSimulationResult,
|
|
20
|
+
collectOffchainEffects,
|
|
17
21
|
mergeExecutionPayloads,
|
|
18
22
|
} from '@aztec/stdlib/tx';
|
|
19
|
-
import { BaseWallet, type
|
|
23
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
20
24
|
|
|
21
25
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
22
26
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
@@ -32,7 +36,11 @@ export type EmbeddedWalletOptions = {
|
|
|
32
36
|
pxeOptions?: PXECreationOptions;
|
|
33
37
|
};
|
|
34
38
|
|
|
39
|
+
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
40
|
+
|
|
35
41
|
export class EmbeddedWallet extends BaseWallet {
|
|
42
|
+
protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
43
|
+
|
|
36
44
|
constructor(
|
|
37
45
|
pxe: PXE,
|
|
38
46
|
aztecNode: AztecNode,
|
|
@@ -79,6 +87,66 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
79
87
|
return storedSenders;
|
|
80
88
|
}
|
|
81
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
92
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
93
|
+
* the necessary authwitnesses.
|
|
94
|
+
*/
|
|
95
|
+
public override async sendTx<W extends InteractionWaitOptions = undefined>(
|
|
96
|
+
executionPayload: ExecutionPayload,
|
|
97
|
+
opts: SendOptions<W>,
|
|
98
|
+
): Promise<SendReturn<W>> {
|
|
99
|
+
const feeOptions = await this.completeFeeOptionsForEstimation(
|
|
100
|
+
opts.from,
|
|
101
|
+
executionPayload.feePayer,
|
|
102
|
+
opts.fee?.gasSettings,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Simulate the transaction first to estimate gas and capture required
|
|
106
|
+
// private authwitnesses based on offchain effects.
|
|
107
|
+
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
108
|
+
from: opts.from,
|
|
109
|
+
feeOptions,
|
|
110
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
111
|
+
skipTxValidation: true,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
115
|
+
const authWitnesses = await Promise.all(
|
|
116
|
+
offchainEffects.map(async effect => {
|
|
117
|
+
try {
|
|
118
|
+
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
119
|
+
return this.createAuthWit(opts.from, {
|
|
120
|
+
consumer: effect.contractAddress,
|
|
121
|
+
innerHash: authRequest.innerHash,
|
|
122
|
+
});
|
|
123
|
+
} catch {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
for (const authwit of authWitnesses) {
|
|
129
|
+
if (authwit) {
|
|
130
|
+
executionPayload.authWitnesses.push(authwit);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const estimated = getGasLimits(simulationResult, this.estimatedGasPadding);
|
|
134
|
+
this.log.verbose(
|
|
135
|
+
`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
|
|
136
|
+
);
|
|
137
|
+
const gasSettings = GasSettings.from({
|
|
138
|
+
...opts.fee?.gasSettings,
|
|
139
|
+
maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
|
|
140
|
+
maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
|
|
141
|
+
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
142
|
+
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
143
|
+
});
|
|
144
|
+
return super.sendTx(executionPayload, {
|
|
145
|
+
...opts,
|
|
146
|
+
fee: { ...opts.fee, gasSettings },
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
82
150
|
/**
|
|
83
151
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
84
152
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
@@ -86,12 +154,10 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
86
154
|
*/
|
|
87
155
|
protected override async simulateViaEntrypoint(
|
|
88
156
|
executionPayload: ExecutionPayload,
|
|
89
|
-
|
|
90
|
-
feeOptions: FeeOptions,
|
|
91
|
-
scopes: AccessScopes,
|
|
92
|
-
skipTxValidation?: boolean,
|
|
93
|
-
skipFeeEnforcement?: boolean,
|
|
157
|
+
opts: SimulateViaEntrypointOptions,
|
|
94
158
|
): Promise<TxSimulationResult> {
|
|
159
|
+
const { from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement } = opts;
|
|
160
|
+
|
|
95
161
|
let overrides: SimulationOverrides | undefined;
|
|
96
162
|
let fromAccount: Account;
|
|
97
163
|
if (!from.equals(AztecAddress.ZERO)) {
|
|
@@ -220,6 +286,10 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
220
286
|
this.minFeePadding = value ?? 0.5;
|
|
221
287
|
}
|
|
222
288
|
|
|
289
|
+
setEstimatedGasPadding(value?: number) {
|
|
290
|
+
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
291
|
+
}
|
|
292
|
+
|
|
223
293
|
stop() {
|
|
224
294
|
return this.pxe.stop();
|
|
225
295
|
}
|