@wonderland/aztec-fee-payment 4.1.0-rc.4 → 4.2.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/README.md +40 -16
- package/dist/src/artifacts/Counter.d.ts +9 -9
- package/dist/src/artifacts/Counter.d.ts.map +1 -1
- package/dist/src/artifacts/{BridgedFPC.d.ts → PrivateFPC.d.ts} +19 -19
- package/dist/src/artifacts/PrivateFPC.d.ts.map +1 -0
- package/dist/src/artifacts/{BridgedFPC.js → PrivateFPC.js} +12 -12
- package/dist/src/ts/fee-payment-methods/index.d.ts +2 -2
- package/dist/src/ts/fee-payment-methods/index.d.ts.map +1 -1
- package/dist/src/ts/fee-payment-methods/index.js +3 -3
- package/dist/src/ts/fee-payment-methods/{bridged.d.ts → private.d.ts} +7 -7
- package/dist/src/ts/fee-payment-methods/{bridged.d.ts.map → private.d.ts.map} +1 -1
- package/dist/src/ts/fee-payment-methods/{bridged.js → private.js} +8 -8
- package/dist/src/ts/fee-payment-methods/shared.d.ts +0 -16
- package/dist/src/ts/fee-payment-methods/shared.d.ts.map +1 -1
- package/dist/src/ts/fee-payment-methods/shared.js +1 -37
- package/dist/src/ts/index.d.ts +8 -7
- package/dist/src/ts/index.d.ts.map +1 -1
- package/dist/src/ts/index.js +9 -9
- package/dist/src/ts/utils/deploy.d.ts +7 -7
- package/dist/src/ts/utils/deploy.d.ts.map +1 -1
- package/dist/src/ts/utils/deploy.js +9 -10
- package/dist/src/ts/utils/gas.d.ts +61 -25
- package/dist/src/ts/utils/gas.d.ts.map +1 -1
- package/dist/src/ts/utils/gas.js +85 -28
- package/dist/src/ts/utils/index.d.ts +3 -2
- package/dist/src/ts/utils/index.d.ts.map +1 -1
- package/dist/src/ts/utils/index.js +3 -3
- package/dist/target/counter_contract-Counter.json +4451 -455
- package/dist/target/private_contract-PrivateFPC.json +14170 -0
- package/package.json +5 -5
- package/target/counter_contract-Counter.json +4451 -455
- package/target/counter_contract-Counter.json.bak +1 -1
- package/target/private_contract-PrivateFPC.json +14170 -0
- package/target/private_contract-PrivateFPC.json.bak +1 -0
- package/dist/src/artifacts/BridgedFPC.d.ts.map +0 -1
- package/dist/target/bridged_contract-BridgedFPC.json +0 -8821
- package/target/bridged_contract-BridgedFPC.json +0 -8821
- package/target/bridged_contract-BridgedFPC.json.bak +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Fr } from "@aztec/
|
|
1
|
+
import { Fr } from "@aztec/aztec.js/fields";
|
|
2
2
|
import { Wallet } from "@aztec/aztec.js/wallet";
|
|
3
|
-
import {
|
|
3
|
+
import { PrivateFPCContract } from "../../artifacts/PrivateFPC.js";
|
|
4
4
|
/**
|
|
5
|
-
* Registers the
|
|
5
|
+
* Registers the PrivateFPC contract with the PXE without sending any deployment transaction.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* PrivateFPC is a fully private contract (no public functions, no constructor, no initializer).
|
|
8
8
|
* The Aztec protocol allows interacting with such contracts immediately once registered —
|
|
9
9
|
* no on-chain deployment transaction is required.
|
|
10
10
|
*
|
|
@@ -15,8 +15,8 @@ import { BridgedFPCContract } from "../../artifacts/BridgedFPC.js";
|
|
|
15
15
|
* is setting `deployer` to `AztecAddress.ZERO`.)
|
|
16
16
|
*
|
|
17
17
|
* @param wallet The wallet used to register the contract with the PXE
|
|
18
|
-
* @param salt
|
|
19
|
-
* @returns The registered
|
|
18
|
+
* @param salt Salt used to derive the contract address
|
|
19
|
+
* @returns The registered PrivateFPC contract instance
|
|
20
20
|
*/
|
|
21
|
-
export declare function
|
|
21
|
+
export declare function registerPrivateContract(wallet: Wallet, salt: Fr): Promise<PrivateFPCContract>;
|
|
22
22
|
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,EAAE,GACP,OAAO,CAAC,kBAAkB,CAAC,CAM7B"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { BridgedFPCContract } from "../../artifacts/BridgedFPC.js";
|
|
1
|
+
import { AztecAddress } from "@aztec/stdlib/aztec-address";
|
|
2
|
+
import { PrivateFPCContract } from "../../artifacts/PrivateFPC.js";
|
|
4
3
|
/**
|
|
5
|
-
* Registers the
|
|
4
|
+
* Registers the PrivateFPC contract with the PXE without sending any deployment transaction.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* PrivateFPC is a fully private contract (no public functions, no constructor, no initializer).
|
|
8
7
|
* The Aztec protocol allows interacting with such contracts immediately once registered —
|
|
9
8
|
* no on-chain deployment transaction is required.
|
|
10
9
|
*
|
|
@@ -15,14 +14,14 @@ import { BridgedFPCContract } from "../../artifacts/BridgedFPC.js";
|
|
|
15
14
|
* is setting `deployer` to `AztecAddress.ZERO`.)
|
|
16
15
|
*
|
|
17
16
|
* @param wallet The wallet used to register the contract with the PXE
|
|
18
|
-
* @param salt
|
|
19
|
-
* @returns The registered
|
|
17
|
+
* @param salt Salt used to derive the contract address
|
|
18
|
+
* @returns The registered PrivateFPC contract instance
|
|
20
19
|
*/
|
|
21
|
-
export async function
|
|
22
|
-
return
|
|
20
|
+
export async function registerPrivateContract(wallet, salt) {
|
|
21
|
+
return PrivateFPCContract.deploy(wallet).register({
|
|
23
22
|
contractAddressSalt: salt,
|
|
24
23
|
skipInitialization: true,
|
|
25
24
|
deployer: AztecAddress.ZERO,
|
|
26
25
|
});
|
|
27
26
|
}
|
|
28
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVwbG95LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RzL3V0aWxzL2RlcGxveS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFFM0QsT0FBTyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFFbkU7Ozs7Ozs7Ozs7Ozs7Ozs7R0FnQkc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLHVCQUF1QixDQUMzQyxNQUFjLEVBQ2QsSUFBUTtJQUVSLE9BQU8sa0JBQWtCLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLFFBQVEsQ0FBQztRQUNoRCxtQkFBbUIsRUFBRSxJQUFJO1FBQ3pCLGtCQUFrQixFQUFFLElBQUk7UUFDeEIsUUFBUSxFQUFFLFlBQVksQ0FBQyxJQUFJO0tBQzVCLENBQUMsQ0FBQztBQUNMLENBQUMifQ==
|
|
@@ -1,32 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FeePaymentMethod } from "@aztec/aztec.js/fee";
|
|
2
|
+
import { AztecAddress } from "@aztec/stdlib/aztec-address";
|
|
3
|
+
import { Gas, GasFees, GasSettings } from "@aztec/stdlib/gas";
|
|
4
|
+
type BaseFeesProvider = {
|
|
5
|
+
getCurrentMinFees(): Promise<GasFees>;
|
|
6
|
+
};
|
|
7
|
+
type SimulatedGasEstimate = Pick<GasSettings, "gasLimits" | "teardownGasLimits">;
|
|
8
|
+
type SimulatableInteraction = {
|
|
9
|
+
simulate(options: {
|
|
10
|
+
from: AztecAddress;
|
|
11
|
+
additionalScopes?: AztecAddress[];
|
|
12
|
+
includeMetadata?: boolean;
|
|
13
|
+
fee?: {
|
|
14
|
+
paymentMethod?: FeePaymentMethod;
|
|
15
|
+
estimatedGasPadding?: number;
|
|
16
|
+
gasSettings?: {
|
|
17
|
+
gasLimits?: Gas;
|
|
18
|
+
teardownGasLimits?: Gas;
|
|
19
|
+
maxFeesPerGas?: GasFees;
|
|
20
|
+
maxPriorityFeesPerGas?: GasFees;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}): Promise<{
|
|
24
|
+
estimatedGas?: SimulatedGasEstimate;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
export type FeeMultiplier = number | {
|
|
28
|
+
numerator: bigint;
|
|
29
|
+
denominator: bigint;
|
|
30
|
+
};
|
|
2
31
|
/**
|
|
3
|
-
* Default
|
|
4
|
-
*
|
|
32
|
+
* Default max fee multiplier applied to the node's current minimum fees.
|
|
33
|
+
* Represented as an exact 6/5 fraction so bigint fee values never depend on
|
|
34
|
+
* floating-point multiplication.
|
|
5
35
|
*/
|
|
6
|
-
export declare const DEFAULT_FEE_MULTIPLIER
|
|
36
|
+
export declare const DEFAULT_FEE_MULTIPLIER: {
|
|
37
|
+
readonly numerator: 6n;
|
|
38
|
+
readonly denominator: 5n;
|
|
39
|
+
};
|
|
7
40
|
/**
|
|
8
|
-
*
|
|
41
|
+
* Default padding applied to simulated gas usage when turning it into limits.
|
|
9
42
|
*/
|
|
10
|
-
export declare const
|
|
43
|
+
export declare const DEFAULT_GAS_ESTIMATE_PADDING = 0.1;
|
|
11
44
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* These are Aztec's protocol-wide defaults (DEFAULT_TEARDOWN_DA_GAS_LIMIT = 393,216;
|
|
15
|
-
* DEFAULT_TEARDOWN_L2_GAS_LIMIT = 1,000,000). They are NOT calibrated to the _refund
|
|
16
|
-
* teardown function, which only emits one note hash and costs roughly 40-50k L2 gas
|
|
17
|
-
* in practice (~20x cheaper than this limit).
|
|
18
|
-
*
|
|
19
|
-
* The protocol bills teardown gas at the limit (rather than actual usage), this
|
|
20
|
-
* overestimate inflates the cost of every pay_fee_exact transaction. Consider
|
|
21
|
-
* benchmarking _refund's actual gas consumption and replacing this with a tighter
|
|
22
|
-
* constant.
|
|
23
|
-
*
|
|
24
|
-
* NOTE: teardown gas is already included in the gas_limits fee calculation by the protocol,
|
|
25
|
-
* so this must NOT be passed to maxGasCostFor (that would double-count teardown cost).
|
|
26
|
-
*/
|
|
27
|
-
export declare const REASONABLE_TEARDOWN_GAS_LIMITS: Gas;
|
|
28
|
-
/**
|
|
29
|
-
* Calculate max fees per gas from base fees with a multiplier.
|
|
45
|
+
* Calculate max fees per gas from the node's minimum fees with a multiplier.
|
|
30
46
|
* @param baseFees - The current base fees from the node
|
|
31
47
|
* @param multiplier - Multiplier to apply (default: DEFAULT_FEE_MULTIPLIER)
|
|
32
48
|
* @returns GasFees object with calculated max fees
|
|
@@ -34,7 +50,12 @@ export declare const REASONABLE_TEARDOWN_GAS_LIMITS: Gas;
|
|
|
34
50
|
export declare function maxFeesPerGasFromBaseFees(baseFees: {
|
|
35
51
|
feePerDaGas: string | number | bigint;
|
|
36
52
|
feePerL2Gas: string | number | bigint;
|
|
37
|
-
}, multiplier?:
|
|
53
|
+
}, multiplier?: FeeMultiplier): GasFees;
|
|
54
|
+
/**
|
|
55
|
+
* Mirror max fees into priority fees.
|
|
56
|
+
* Aztec models both fee caps independently, but this SDK currently keeps them equal.
|
|
57
|
+
*/
|
|
58
|
+
export declare function maxPriorityFeesPerGasFromMaxFees(maxFeesPerGas: GasFees): GasFees;
|
|
38
59
|
/**
|
|
39
60
|
* Calculate the maximum gas cost for a transaction.
|
|
40
61
|
*
|
|
@@ -48,4 +69,19 @@ export declare function maxFeesPerGasFromBaseFees(baseFees: {
|
|
|
48
69
|
* @returns Maximum possible gas cost in wei
|
|
49
70
|
*/
|
|
50
71
|
export declare function maxGasCostFor(maxFeesPerGas: GasFees, gasLimits: Gas): bigint;
|
|
72
|
+
/**
|
|
73
|
+
* Simulate an interaction to derive tighter gas limits, then combine them with
|
|
74
|
+
* fee caps based on the node's current minimum fees.
|
|
75
|
+
*/
|
|
76
|
+
export declare function estimateGasSettings(interaction: SimulatableInteraction, { aztecNode, from, paymentMethod, additionalScopes, maxFeeMultiplier, estimatedGasPadding, gasLimits, teardownGasLimits, }: {
|
|
77
|
+
aztecNode: BaseFeesProvider;
|
|
78
|
+
from: AztecAddress;
|
|
79
|
+
paymentMethod?: FeePaymentMethod;
|
|
80
|
+
additionalScopes?: AztecAddress[];
|
|
81
|
+
maxFeeMultiplier?: FeeMultiplier;
|
|
82
|
+
estimatedGasPadding?: number;
|
|
83
|
+
gasLimits?: Gas;
|
|
84
|
+
teardownGasLimits?: Gas;
|
|
85
|
+
}): Promise<GasSettings>;
|
|
86
|
+
export {};
|
|
51
87
|
//# sourceMappingURL=gas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EACL,GAAG,EACH,OAAO,EACP,WAAW,EAIZ,MAAM,mBAAmB,CAAC;AAG3B,KAAK,gBAAgB,GAAG;IACtB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF,KAAK,oBAAoB,GAAG,IAAI,CAC9B,WAAW,EACX,WAAW,GAAG,mBAAmB,CACl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ACvC,WAAW,EAAE,sBAAsB,EACnC,EACE,SAAS,EACT,IAAI,EACJ,aAAa,EACb,gBAAgB,EAChB,gBAAyC,EACzC,mBAAkD,EAClD,SAA0B,EAC1B,iBAAgD,GACjD,EAAE;IACD,SAAS,EAAE,gBAAgB,CAAC;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,aAAa,CAAC,EAAE,gBAAgB,CAAC;IACjC,gBAAgB,CAAC,EAAE,YAAY,EAAE,CAAC;IAClC,gBAAgB,CAAC,EAAE,aAAa,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,iBAAiB,CAAC,EAAE,GAAG,CAAC;CACzB,GACA,OAAO,CAAC,WAAW,CAAC,CAiCtB"}
|
package/dist/src/ts/utils/gas.js
CHANGED
|
@@ -1,45 +1,75 @@
|
|
|
1
|
-
import { Gas, GasFees } from "@aztec/stdlib/gas";
|
|
2
|
-
import {
|
|
1
|
+
import { Gas, GasFees, GasSettings, APPROXIMATE_MAX_DA_GAS_PER_BLOCK, FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT, } from "@aztec/stdlib/gas";
|
|
2
|
+
import { MAX_PROCESSABLE_L2_GAS } from "@aztec/constants";
|
|
3
|
+
const FEE_MULTIPLIER_SCALE = 10000n;
|
|
4
|
+
const DEFAULT_FEE_MULTIPLIER_NUMERATOR = 6n;
|
|
5
|
+
const DEFAULT_FEE_MULTIPLIER_DENOMINATOR = 5n;
|
|
6
|
+
function ceilDiv(numerator, denominator) {
|
|
7
|
+
return (numerator + denominator - 1n) / denominator;
|
|
8
|
+
}
|
|
9
|
+
function normalizeMultiplier(multiplier) {
|
|
10
|
+
if (typeof multiplier === "number") {
|
|
11
|
+
if (!Number.isFinite(multiplier) || multiplier <= 0) {
|
|
12
|
+
throw new Error(`Fee multiplier must be a positive finite number, got ${multiplier}`);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
numerator: BigInt(Math.ceil(multiplier * Number(FEE_MULTIPLIER_SCALE))),
|
|
16
|
+
denominator: FEE_MULTIPLIER_SCALE,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (multiplier.denominator <= 0n || multiplier.numerator <= 0n) {
|
|
20
|
+
throw new Error(`Fee multiplier must be a positive fraction, got ${multiplier.numerator}/${multiplier.denominator}`);
|
|
21
|
+
}
|
|
22
|
+
return multiplier;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Default max fee multiplier applied to the node's current minimum fees.
|
|
26
|
+
* Represented as an exact 6/5 fraction so bigint fee values never depend on
|
|
27
|
+
* floating-point multiplication.
|
|
28
|
+
*/
|
|
29
|
+
export const DEFAULT_FEE_MULTIPLIER = {
|
|
30
|
+
numerator: DEFAULT_FEE_MULTIPLIER_NUMERATOR,
|
|
31
|
+
denominator: DEFAULT_FEE_MULTIPLIER_DENOMINATOR,
|
|
32
|
+
};
|
|
3
33
|
/**
|
|
4
|
-
* Default
|
|
5
|
-
* Provides headroom above the current minimum to avoid rejection under fee spikes.
|
|
34
|
+
* Default padding applied to simulated gas usage when turning it into limits.
|
|
6
35
|
*/
|
|
7
|
-
export const
|
|
36
|
+
export const DEFAULT_GAS_ESTIMATE_PADDING = 0.1;
|
|
8
37
|
/**
|
|
9
|
-
*
|
|
38
|
+
* Protocol-maximum gas limits, used as the initial ceiling for
|
|
39
|
+
* estimateGasSettings — the simulation replaces them with tighter values.
|
|
10
40
|
*/
|
|
11
|
-
|
|
12
|
-
daGas:
|
|
13
|
-
l2Gas:
|
|
41
|
+
const MAX_GAS_LIMITS = Gas.from({
|
|
42
|
+
daGas: APPROXIMATE_MAX_DA_GAS_PER_BLOCK,
|
|
43
|
+
l2Gas: MAX_PROCESSABLE_L2_GAS,
|
|
14
44
|
});
|
|
15
45
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* DEFAULT_TEARDOWN_L2_GAS_LIMIT = 1,000,000). They are NOT calibrated to the _refund
|
|
20
|
-
* teardown function, which only emits one note hash and costs roughly 40-50k L2 gas
|
|
21
|
-
* in practice (~20x cheaper than this limit).
|
|
22
|
-
*
|
|
23
|
-
* The protocol bills teardown gas at the limit (rather than actual usage), this
|
|
24
|
-
* overestimate inflates the cost of every pay_fee_exact transaction. Consider
|
|
25
|
-
* benchmarking _refund's actual gas consumption and replacing this with a tighter
|
|
26
|
-
* constant.
|
|
46
|
+
* Protocol-default teardown gas limits. The protocol bills teardown gas at the
|
|
47
|
+
* limit (not actual usage), so these overestimate. estimateGasSettings replaces
|
|
48
|
+
* them with simulation output.
|
|
27
49
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
50
|
+
* Teardown gas is already included in gasLimits by the protocol, so these must
|
|
51
|
+
* NOT be passed to maxGasCostFor (that would double-count teardown cost).
|
|
30
52
|
*/
|
|
31
|
-
|
|
32
|
-
daGas:
|
|
33
|
-
l2Gas:
|
|
53
|
+
const FALLBACK_TEARDOWN_GAS_LIMITS = Gas.from({
|
|
54
|
+
daGas: FALLBACK_TEARDOWN_DA_GAS_LIMIT,
|
|
55
|
+
l2Gas: FALLBACK_TEARDOWN_L2_GAS_LIMIT,
|
|
34
56
|
});
|
|
35
57
|
/**
|
|
36
|
-
* Calculate max fees per gas from
|
|
58
|
+
* Calculate max fees per gas from the node's minimum fees with a multiplier.
|
|
37
59
|
* @param baseFees - The current base fees from the node
|
|
38
60
|
* @param multiplier - Multiplier to apply (default: DEFAULT_FEE_MULTIPLIER)
|
|
39
61
|
* @returns GasFees object with calculated max fees
|
|
40
62
|
*/
|
|
41
63
|
export function maxFeesPerGasFromBaseFees(baseFees, multiplier = DEFAULT_FEE_MULTIPLIER) {
|
|
42
|
-
|
|
64
|
+
const normalizedMultiplier = normalizeMultiplier(multiplier);
|
|
65
|
+
return new GasFees(ceilDiv(BigInt(baseFees.feePerDaGas) * normalizedMultiplier.numerator, normalizedMultiplier.denominator), ceilDiv(BigInt(baseFees.feePerL2Gas) * normalizedMultiplier.numerator, normalizedMultiplier.denominator));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Mirror max fees into priority fees.
|
|
69
|
+
* Aztec models both fee caps independently, but this SDK currently keeps them equal.
|
|
70
|
+
*/
|
|
71
|
+
export function maxPriorityFeesPerGasFromMaxFees(maxFeesPerGas) {
|
|
72
|
+
return maxFeesPerGas.clone();
|
|
43
73
|
}
|
|
44
74
|
/**
|
|
45
75
|
* Calculate the maximum gas cost for a transaction.
|
|
@@ -57,4 +87,31 @@ export function maxGasCostFor(maxFeesPerGas, gasLimits) {
|
|
|
57
87
|
return (BigInt(maxFeesPerGas.feePerDaGas) * BigInt(gasLimits.daGas) +
|
|
58
88
|
BigInt(maxFeesPerGas.feePerL2Gas) * BigInt(gasLimits.l2Gas));
|
|
59
89
|
}
|
|
60
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Simulate an interaction to derive tighter gas limits, then combine them with
|
|
92
|
+
* fee caps based on the node's current minimum fees.
|
|
93
|
+
*/
|
|
94
|
+
export async function estimateGasSettings(interaction, { aztecNode, from, paymentMethod, additionalScopes, maxFeeMultiplier = DEFAULT_FEE_MULTIPLIER, estimatedGasPadding = DEFAULT_GAS_ESTIMATE_PADDING, gasLimits = MAX_GAS_LIMITS, teardownGasLimits = FALLBACK_TEARDOWN_GAS_LIMITS, }) {
|
|
95
|
+
const maxFeesPerGas = maxFeesPerGasFromBaseFees(await aztecNode.getCurrentMinFees(), maxFeeMultiplier);
|
|
96
|
+
const maxPriorityFeesPerGas = maxPriorityFeesPerGasFromMaxFees(maxFeesPerGas);
|
|
97
|
+
const simulation = await interaction.simulate({
|
|
98
|
+
from,
|
|
99
|
+
additionalScopes,
|
|
100
|
+
includeMetadata: true,
|
|
101
|
+
fee: {
|
|
102
|
+
paymentMethod,
|
|
103
|
+
estimatedGasPadding,
|
|
104
|
+
gasSettings: {
|
|
105
|
+
gasLimits,
|
|
106
|
+
teardownGasLimits,
|
|
107
|
+
maxFeesPerGas,
|
|
108
|
+
maxPriorityFeesPerGas,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
if (!simulation.estimatedGas) {
|
|
113
|
+
throw new Error("Gas estimation metadata was not returned by simulation.");
|
|
114
|
+
}
|
|
115
|
+
return new GasSettings(simulation.estimatedGas.gasLimits, simulation.estimatedGas.teardownGasLimits, maxFeesPerGas, maxPriorityFeesPerGas);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2FzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RzL3V0aWxzL2dhcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQ0wsR0FBRyxFQUNILE9BQU8sRUFDUCxXQUFXLEVBQ1gsZ0NBQWdDLEVBQ2hDLDhCQUE4QixFQUM5Qiw4QkFBOEIsR0FDL0IsTUFBTSxtQkFBbUIsQ0FBQztBQUMzQixPQUFPLEVBQUUsc0JBQXNCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQTZCMUQsTUFBTSxvQkFBb0IsR0FBRyxNQUFPLENBQUM7QUFDckMsTUFBTSxnQ0FBZ0MsR0FBRyxFQUFFLENBQUM7QUFDNUMsTUFBTSxrQ0FBa0MsR0FBRyxFQUFFLENBQUM7QUFTOUMsU0FBUyxPQUFPLENBQUMsU0FBaUIsRUFBRSxXQUFtQjtJQUNyRCxPQUFPLENBQUMsU0FBUyxHQUFHLFdBQVcsR0FBRyxFQUFFLENBQUMsR0FBRyxXQUFXLENBQUM7QUFDdEQsQ0FBQztBQUVELFNBQVMsbUJBQW1CLENBQUMsVUFBeUI7SUFJcEQsSUFBSSxPQUFPLFVBQVUsS0FBSyxRQUFRLEVBQUUsQ0FBQztRQUNuQyxJQUFJLENBQUMsTUFB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
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export type { FeeMultiplier } from "./gas.js";
|
|
2
|
+
export { DEFAULT_FEE_MULTIPLIER, DEFAULT_GAS_ESTIMATE_PADDING, estimateGasSettings, maxFeesPerGasFromBaseFees, maxPriorityFeesPerGasFromMaxFees, maxGasCostFor, } from "./gas.js";
|
|
3
|
+
export { registerPrivateContract } from "./deploy.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,mBAAmB,EACnB,yBAAyB,EACzB,gCAAgC,EAChC,aAAa,GACd,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Gas calculation utilities
|
|
2
|
-
export { DEFAULT_FEE_MULTIPLIER,
|
|
2
|
+
export { DEFAULT_FEE_MULTIPLIER, DEFAULT_GAS_ESTIMATE_PADDING, estimateGasSettings, maxFeesPerGasFromBaseFees, maxPriorityFeesPerGasFromMaxFees, maxGasCostFor, } from "./gas.js";
|
|
3
3
|
// Deployment utilities
|
|
4
|
-
export {
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
4
|
+
export { registerPrivateContract } from "./deploy.js";
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvdHMvdXRpbHMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsNEJBQTRCO0FBQzVCLE9BQU8sRUFDTCxzQkFBc0IsRUFDdEIsNEJBQTRCLEVBQzVCLG1CQUFtQixFQUNuQix5QkFBeUIsRUFDekIsZ0NBQWdDLEVBQ2hDLGFBQWEsR0FDZCxNQUFNLFVBQVUsQ0FBQztBQUVsQix1QkFBdUI7QUFDdkIsT0FBTyxFQUFFLHVCQUF1QixFQUFFLE1BQU0sYUFBYSxDQUFDIn0=
|