@argent/x-shared 1.70.3 → 1.72.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.
Files changed (64) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +286 -307
  3. package/dist/simulation.cjs +1 -1
  4. package/dist/simulation.js +73 -69
  5. package/dist/src/features/paymaster/types.d.ts +2 -2
  6. package/dist/src/features/simulation/activity/utils/index.d.ts +3 -0
  7. package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.cjs +1 -0
  8. package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.d.ts +3 -0
  9. package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.js +24 -0
  10. package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.cjs +1 -0
  11. package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.d.ts +3 -0
  12. package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.js +24 -0
  13. package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.cjs +1 -0
  14. package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.d.ts +3 -0
  15. package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.js +24 -0
  16. package/dist/src/features/simulation/activity/utils/isReplaceMultisigSignersActivity.d.ts +3 -0
  17. package/dist/src/features/simulation/activity/utils/isSwapActivity.cjs +1 -1
  18. package/dist/src/features/simulation/activity/utils/isSwapActivity.d.ts +2 -1
  19. package/dist/src/features/simulation/activity/utils/isSwapActivity.js +15 -17
  20. package/dist/src/features/simulation/activity/utils/isUpgradeActivity.cjs +1 -1
  21. package/dist/src/features/simulation/activity/utils/isUpgradeActivity.d.ts +2 -1
  22. package/dist/src/features/simulation/activity/utils/isUpgradeActivity.js +16 -14
  23. package/dist/src/features/simulation/fees/schema.cjs +1 -1
  24. package/dist/src/features/simulation/fees/schema.d.ts +665 -705
  25. package/dist/src/features/simulation/fees/schema.js +32 -39
  26. package/dist/src/features/simulation/transactionReview/schema.cjs +1 -1
  27. package/dist/src/features/simulation/transactionReview/schema.d.ts +2117 -7917
  28. package/dist/src/features/simulation/transactionReview/schema.js +103 -112
  29. package/dist/src/features/swap/models/execute.model.d.ts +4 -0
  30. package/dist/src/features/swap/services/SwapTransactionService.cjs +1 -1
  31. package/dist/src/features/swap/services/SwapTransactionService.js +22 -18
  32. package/dist/src/tokens/isUnlimitedAmount.cjs +1 -1
  33. package/dist/src/tokens/isUnlimitedAmount.js +3 -3
  34. package/dist/src/transactions/amount.cjs +1 -1
  35. package/dist/src/transactions/amount.d.ts +2 -2
  36. package/dist/src/transactions/amount.js +9 -9
  37. package/dist/src/transactions/estimate/adjustment.cjs +1 -0
  38. package/dist/src/transactions/estimate/adjustment.d.ts +4 -0
  39. package/dist/src/transactions/estimate/adjustment.js +7 -0
  40. package/dist/src/transactions/estimate/argentMaxFee.d.ts +3 -3
  41. package/dist/src/transactions/estimate/index.d.ts +0 -1
  42. package/dist/src/transactions/estimate/model.d.ts +1 -10
  43. package/dist/src/transactions/estimate/utils.cjs +1 -1
  44. package/dist/src/transactions/estimate/utils.d.ts +31 -61
  45. package/dist/src/transactions/estimate/utils.js +156 -223
  46. package/dist/src/transactions/index.d.ts +0 -1
  47. package/dist/src/transactions/service/implementation.cjs +1 -1
  48. package/dist/src/transactions/service/implementation.d.ts +39 -22
  49. package/dist/src/transactions/service/implementation.js +130 -97
  50. package/dist/src/transactions/service/index.d.ts +1 -0
  51. package/dist/src/transactions/service/utils.cjs +1 -0
  52. package/dist/src/transactions/service/utils.d.ts +25 -0
  53. package/dist/src/transactions/service/utils.js +25 -0
  54. package/dist/src/transactions/transactionSimulationTypes.d.ts +1 -7
  55. package/dist/src/transactions/transactionVersion.cjs +1 -1
  56. package/dist/src/transactions/transactionVersion.d.ts +5 -6
  57. package/dist/src/transactions/transactionVersion.js +10 -12
  58. package/package.json +2 -2
  59. package/dist/src/transactions/estimate/utilsV2.cjs +0 -1
  60. package/dist/src/transactions/estimate/utilsV2.d.ts +0 -26
  61. package/dist/src/transactions/estimate/utilsV2.js +0 -107
  62. package/dist/src/transactions/getTransactionVersion.cjs +0 -1
  63. package/dist/src/transactions/getTransactionVersion.d.ts +0 -12
  64. package/dist/src/transactions/getTransactionVersion.js +0 -21
@@ -1,61 +1,30 @@
1
- import { CairoVersion } from 'starknet';
2
- import { Address } from '../../chains/starknet/address';
3
- import { EstimatedFee, EstimatedFees, SimulateAndReview } from '../../features/simulation';
4
- import { ApiTransactionSimulationResponse } from '../transactionSimulationTypes';
5
- import { CastFeeEstimation, FRI, FeeEstimationV1, FeeEstimationV3, TransactionReviewTransactions, WEI } from './model';
6
- export declare function isWEI<T>(value: Pick<CastFeeEstimation<T>, "unit">): value is FeeEstimationV1<T>;
7
- export declare function isFRI<T>(value: Pick<CastFeeEstimation<T>, "unit">): value is FeeEstimationV3<T>;
8
- export declare function castFeeEstimation<S, T extends CastFeeEstimation<S>, C>(feeEstimation: T, cast: (value: S) => C): CastFeeEstimation<C>;
9
- export declare function toMax<S, T extends CastFeeEstimation<S>>(value: T): T["unit"] extends WEI ? {
10
- maxFee: S;
11
- } : {
12
- amount: S;
13
- pricePerUnit: S;
14
- };
15
- export declare function unitToFeeTokenAddress(unit: WEI | FRI): Address;
16
- export declare function multiplyBigIntByFloat(bigintValue: bigint, floatValue: number, precision?: number): bigint;
17
- export declare const tokensRequireTxV3Support: string[];
18
- export type FeeAdjustmentFn = (ratio: number) => number;
19
- export declare const estimatedFeeToTotal: (estimatedFee: Pick<EstimatedFee, "amount" | "pricePerUnit" | "dataGasConsumed" | "dataGasPrice">) => bigint;
20
- export declare const getWatermarkedMaxFeeTotal: (estimatedFee: EstimatedFee) => bigint | undefined;
21
- export declare const estimatedFeeToMaxFeeTotal: (estimatedFee: EstimatedFee) => bigint;
22
- export declare const estimatedFeesToTotal: (estimatedFees: EstimatedFees) => bigint;
23
- export declare const estimatedFeesToMaxFeeTotal: (estimatedFees: EstimatedFees) => bigint;
24
- export declare const buildDummyTx: (tokenAddress: Address, feeTokenAddress: Address) => {
25
- contractAddress: `0x${string}`;
26
- entrypoint: string;
27
- calldata: import('starknet').Calldata;
28
- }[];
29
- export declare const getEstimatedFeeFromBulkSimulation: (simulation: Pick<ApiTransactionSimulationResponse, "feeEstimation">[] | undefined, feeTokenAddress?: Address) => EstimatedFees;
30
- export declare const getPayloadFromTransaction: ({ transaction, nonce, chainId, version, isDeploymentTransaction, cairoVersion, address, appDomain, }: {
31
- transaction: TransactionReviewTransactions;
32
- nonce: string;
33
- chainId: string;
34
- version: string;
35
- isDeploymentTransaction: boolean;
36
- cairoVersion: CairoVersion;
37
- address: string;
38
- appDomain?: string;
39
- }) => {
40
- type: "DECLARE" | "DEPLOY" | "DEPLOY_ACCOUNT" | "INVOKE";
41
- chainId: string;
42
- cairoVersion: CairoVersion;
43
- nonce: string;
44
- version: string;
45
- account: string;
46
- calls: import('starknet').Call[];
47
- calldata: string[] | undefined;
48
- salt: `0x${string}` | undefined;
49
- signature: string[] | undefined;
50
- classHash: `0x${string}` | undefined;
51
- appDomain: string | undefined;
52
- };
53
- export declare const getEstimatedFeeFromSimulationAndRespectWatermarkFee: (simulateAndReviewResult: Pick<SimulateAndReview, "transactions">, feeTokenAddress?: Address) => EstimatedFees & {
54
- transactions: Required<EstimatedFee>;
55
- deployment?: Required<EstimatedFee>;
56
- };
57
- export declare const estimatedFeeToMaxResourceBounds: (estimatedFee: EstimatedFee) => {
58
- maxFee: bigint;
1
+ import { Address } from '../../chains';
2
+ import { PaymasterFeeEstimation, FeeEstimation, SimulateAndReview } from '../../features/simulation';
3
+ import { EstimatedFees, NativeEstimatedFees, NativeEstimatedFeeData, NativeEstimatedFeesData, PaymasterEstimatedFeesData } from '../../features/simulation/fees/schema';
4
+ export declare const getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2: (simulateAndReviewResult: Pick<SimulateAndReview, "transactions">) => EstimatedFees[];
5
+ export declare const getPaymasterFeeFromSimulation: (invokeTransaction: {
6
+ paymasterFeeEstimations: PaymasterFeeEstimation[];
7
+ }, deployTransactionOrUndefined?: {
8
+ paymasterFeeEstimations: PaymasterFeeEstimation[];
9
+ } | undefined) => EstimatedFees[];
10
+ export declare const getNativeFeeFromSimulation: (invokeTransaction: {
11
+ nativeFeeEstimations: FeeEstimation[];
12
+ }, deployTransactionOrUndefined?: {
13
+ nativeFeeEstimations: FeeEstimation[];
14
+ } | undefined) => EstimatedFees[];
15
+ export declare const toMaxFeeEstimation: (fee: FeeEstimation) => bigint;
16
+ export declare const estimatedFeesToMaxFeeTotalV2: (estimatedFees: EstimatedFees) => bigint;
17
+ export declare const estimatedFeesToTotalV2: (estimatedFees: EstimatedFees) => bigint;
18
+ export declare const getNativeEstimatedFees: (estimatedFees?: EstimatedFees[]) => NativeEstimatedFees[];
19
+ export declare const filterPaymasterEstimatedFees: (estimatedFees: EstimatedFees[]) => PaymasterEstimatedFeesData[];
20
+ export declare const getNativeFeeTokenAddress: () => Address;
21
+ export declare const getNativeEstimatedFeeByFeeToken: (estimatedFees: EstimatedFees[] | undefined, feeTokenAddress: string) => NativeEstimatedFees;
22
+ export declare const getNativeEstimatedFeeByTxVersion: (estimatedFees?: EstimatedFees[]) => NativeEstimatedFees;
23
+ export declare const getNativeEstimatedFeeForAccount: (estimatedFees?: EstimatedFees[]) => NativeEstimatedFees;
24
+ export declare const estimatedFeesToTotal: (estimatedFees: NativeEstimatedFeesData) => bigint;
25
+ export declare const estimatedFeeToTotal: (estimatedFee: NativeEstimatedFeeData) => bigint;
26
+ export declare const estimatedFeeToMaxFeeTotal: (estimatedFee: NativeEstimatedFeeData) => bigint;
27
+ export declare const estimatedFeeToMaxResourceBounds: (estimatedFee: NativeEstimatedFeeData) => {
59
28
  resourceBounds: {
60
29
  l1_gas: {
61
30
  max_amount: string;
@@ -65,8 +34,9 @@ export declare const estimatedFeeToMaxResourceBounds: (estimatedFee: EstimatedFe
65
34
  max_amount: string;
66
35
  max_price_per_unit: string;
67
36
  };
37
+ l1_data_gas: {
38
+ max_amount: string;
39
+ max_price_per_unit: string;
40
+ };
68
41
  };
69
42
  };
70
- export declare const calculateSqrtAdjustment: (ratio: number) => number;
71
- export declare const calculateCubeRootAdjustment: (ratio: number) => number;
72
- export declare const calculateNonLinearAdjustment: (ratio: number) => number;
@@ -1,235 +1,168 @@
1
- import { upperCase as A } from "lodash-es";
2
- import { num as r, CallData as B, uint256 as C } from "starknet";
3
- import { isEqualAddress as T } from "../../chains/starknet/address.js";
4
- import { STRK_TOKEN_ADDRESS as I, ETH_TOKEN_ADDRESS as y } from "../../chains/starknet/constants.js";
5
- import { argentMaxFee as _ } from "./argentMaxFee.js";
6
- import { EstimateError as G } from "./error.js";
7
- import { transferCalldataSchema as h } from "../../utils/starknet/starknet.js";
8
- import { feeEstimationSchema as f } from "../../features/simulation/transactionReview/schema.js";
9
- import { ensureArray as M } from "../../utils/arrays.js";
10
- function E(t) {
11
- return A(t.unit) === "WEI";
12
- }
13
- function k(t) {
14
- return A(t.unit) === "FRI";
15
- }
16
- function u(t, e) {
17
- return E(t) ? {
18
- ...t,
19
- maxFee: e(t.maxFee),
20
- overallFee: e(t.overallFee),
21
- gasPrice: e(t.gasPrice),
22
- gasUsage: e(t.gasUsage)
23
- } : {
24
- ...t,
25
- overallFee: e(t.overallFee),
26
- gasPrice: e(t.gasPrice),
27
- gasUsage: e(t.gasUsage),
28
- maxAmount: e(t.maxAmount),
29
- maxPricePerUnit: e(t.maxPricePerUnit)
30
- };
31
- }
32
- function d(t) {
33
- return E(t) ? {
34
- maxFee: t.maxFee
35
- } : {
36
- amount: t.maxAmount,
37
- pricePerUnit: t.maxPricePerUnit
38
- };
39
- }
40
- function x(t) {
41
- return k({ unit: t }) ? I : y;
42
- }
43
- function V(t, e, n = 2) {
44
- const a = BigInt(10 ** n), o = BigInt(Math.round(e * 10 ** n));
45
- return t * o / a;
46
- }
47
- const Y = [I], U = (t, e = w) => {
48
- if (t.max && "amount" in t.max)
1
+ import { isEmpty as P, partition as A } from "lodash-es";
2
+ import { num as o } from "starknet";
3
+ import { calculateCubeRootAdjustment as G } from "./adjustment.js";
4
+ import { argentMaxFee as T } from "./argentMaxFee.js";
5
+ import { EstimateError as F } from "./error.js";
6
+ import { STRK_TOKEN_ADDRESS as E } from "../../chains/starknet/constants.js";
7
+ import { isEqualAddress as p } from "../../chains/starknet/address.js";
8
+ const L = (t) => {
9
+ const { transactions: e } = t;
10
+ if (!e)
11
+ throw new F({ code: "SIMULATE_AND_REVIEW_FAILED" });
12
+ if (!Array.isArray(e))
13
+ throw Error(`Unexpected simulation response. Expected array. Got ${typeof e}`);
14
+ if (P(e))
15
+ return [];
16
+ if (e.length > 2)
17
+ throw Error(`Unexpected simulation response length. Got ${e.length}`);
18
+ const a = e.map((m) => {
19
+ if (!m.simulation)
20
+ throw new F({ code: "SIMULATE_AND_REVIEW_FAILED" });
49
21
  return {
50
- ...t,
51
- ...t.max
22
+ ...m.simulation,
23
+ ..._(m.simulation.feeEstimations)
52
24
  };
53
- const n = 10000n, { amount: a, pricePerUnit: o, dataGasConsumed: s = 0n, dataGasPrice: m = 0n } = t, c = a * o + s * m;
54
- if (c < 0)
55
- throw Error("Cannot calculate max fee for negative fee");
56
- const i = r.toBigInt(_({ estimatedFee: c })), g = Number(i) / Number(c), F = e(g), l = BigInt(Math.trunc(F * Number(n)));
57
- return {
58
- ...t,
59
- amount: a * l / n,
60
- pricePerUnit: o * l / n,
61
- dataGasConsumed: s * l / n,
62
- dataGasPrice: m * l / n
63
- };
64
- }, p = (t) => {
65
- const { amount: e, pricePerUnit: n, dataGasConsumed: a = 0n, dataGasPrice: o = 0n } = t;
66
- return e * n + a * o;
67
- }, N = (t) => {
68
- if (t.max)
69
- return "maxFee" in t.max ? t.max.maxFee : p(t.max);
70
- }, P = (t) => {
71
- const e = N(t);
72
- return e || p(U(t));
73
- }, $ = (t) => {
74
- if (t.deployment && !T(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
75
- throw Error("Cannot calculate estimated fees for different tokens");
76
- const e = p(t.transactions), n = t.deployment ? p(t.deployment) : 0n;
77
- return e + n;
78
- }, z = (t) => {
79
- if (t.deployment && !T(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
80
- throw Error("Cannot calculate estimated fees for different tokens");
81
- const e = t.deployment ? P(t.deployment) : 0n, n = P(t.transactions);
82
- return e + n;
83
- }, J = (t, e) => [
84
- {
85
- contractAddress: t,
86
- entrypoint: "transfer",
87
- calldata: B.compile(h.parse({
88
- // We are using a dummy address (ETH here) as recipient to estimate the fee given we don't have a receipient yet
89
- recipient: e,
90
- // We are using the smallest possible amount to make sure this doesn't throw an error
91
- amount: C.bnToUint256(BigInt(1))
92
- }))
93
- }
94
- ], S = (t, e) => {
25
+ }), [n, s] = a.length === 1 ? [a[0], void 0] : [a[1], a[0]], r = h(n, s), i = v(n, s);
26
+ return [...r, ...i];
27
+ }, _ = (t) => {
28
+ const [e, a] = A(t, (n) => "unit" in n && n.unit === "FRI");
29
+ return { nativeFeeEstimations: e, paymasterFeeEstimations: a };
30
+ }, v = (t, e) => {
95
31
  if (!t)
96
- return {
97
- transactions: {
98
- feeTokenAddress: e ?? y,
99
- amount: 0n,
100
- pricePerUnit: 0n,
101
- dataGasConsumed: 0n,
102
- dataGasPrice: 0n
103
- }
104
- };
105
- if (!Array.isArray(t))
106
- throw Error(`Unexpected simulation response. Expected array. Got ${typeof t}`);
107
- if (t.length === 1) {
108
- const n = f.parse(t[0].feeEstimation);
109
- return {
110
- transactions: {
111
- feeTokenAddress: x(n.unit),
112
- amount: r.toBigInt(n.gasUsage),
113
- pricePerUnit: r.toBigInt(n.gasPrice),
114
- max: d(u(n, r.toBigInt)),
115
- dataGasConsumed: n.dataGasConsumed ? r.toBigInt(n.dataGasConsumed) : 0n,
116
- dataGasPrice: n.dataGasPrice ? r.toBigInt(n.dataGasPrice) : 0n
117
- }
118
- };
119
- }
120
- if (t.length === 2) {
121
- const n = f.parse(t[0].feeEstimation), a = f.parse(t[1].feeEstimation);
122
- return {
123
- deployment: {
124
- feeTokenAddress: x(n.unit),
125
- amount: r.toBigInt(n.gasUsage),
126
- pricePerUnit: r.toBigInt(n.gasPrice),
127
- max: d(u(n, r.toBigInt)),
128
- dataGasConsumed: n.dataGasConsumed ? r.toBigInt(n.dataGasConsumed) : 0n,
129
- dataGasPrice: n.dataGasPrice ? r.toBigInt(n.dataGasPrice) : 0n
130
- },
131
- transactions: {
132
- feeTokenAddress: x(a.unit),
133
- amount: r.toBigInt(a.gasUsage),
134
- pricePerUnit: r.toBigInt(a.gasPrice),
135
- max: d(u(a, r.toBigInt)),
136
- dataGasConsumed: a.dataGasConsumed ? r.toBigInt(a.dataGasConsumed) : 0n,
137
- dataGasPrice: a.dataGasPrice ? r.toBigInt(a.dataGasPrice) : 0n
138
- }
139
- };
32
+ return [];
33
+ if (!e)
34
+ return t.paymasterFeeEstimations.map((s) => ({
35
+ type: "paymaster",
36
+ transactions: u(s),
37
+ deployment: void 0
38
+ }));
39
+ const a = e.paymasterFeeEstimations, n = t.paymasterFeeEstimations;
40
+ if (a.length !== n.length)
41
+ throw Error("Deployment and transaction fee estimations length mismatch");
42
+ return n.map((s, r) => ({
43
+ type: "paymaster",
44
+ transactions: u(s),
45
+ deployment: u(a[r])
46
+ }));
47
+ }, h = (t, e) => {
48
+ if (!t)
49
+ return [];
50
+ if (!e)
51
+ return t.nativeFeeEstimations.map((s) => ({
52
+ type: "native",
53
+ transactions: l(s),
54
+ deployment: void 0
55
+ }));
56
+ const a = e.nativeFeeEstimations, n = t.nativeFeeEstimations;
57
+ if (a.length !== n.length)
58
+ throw Error("Deployment and transaction fee estimations length mismatch");
59
+ return n.map((s, r) => ({
60
+ type: "native",
61
+ transactions: l(s),
62
+ deployment: l(a[r])
63
+ }));
64
+ }, u = (t) => ({
65
+ feeTokenAddress: t.token.address,
66
+ maxFee: BigInt(t.maxFee),
67
+ overallFee: BigInt(t.overallFee)
68
+ }), l = (t) => ({
69
+ feeTokenAddress: E,
70
+ l1Gas: {
71
+ gasConsumed: o.toBigInt(t.resourceBounds.l1Gas.maxAmount),
72
+ gasPrice: o.toBigInt(t.resourceBounds.l1Gas.maxPricePerUnit)
73
+ },
74
+ l1DataGas: {
75
+ gasConsumed: o.toBigInt(t.resourceBounds.l1DataGas.maxAmount),
76
+ gasPrice: o.toBigInt(t.resourceBounds.l1DataGas.maxPricePerUnit)
77
+ },
78
+ l2Gas: {
79
+ gasConsumed: o.toBigInt(t.resourceBounds.l2Gas.maxAmount),
80
+ gasPrice: o.toBigInt(t.resourceBounds.l2Gas.maxPricePerUnit)
140
81
  }
141
- throw Error("Unexpected simulation response length");
142
- }, Q = ({ transaction: t, nonce: e, chainId: n, version: a, isDeploymentTransaction: o, cairoVersion: s, address: m, appDomain: c }) => {
143
- let i = e;
144
- o && t.type !== "DEPLOY_ACCOUNT" && (i = r.toHex(1));
145
- const g = M(t.calls);
146
- return {
147
- type: t.type,
148
- chainId: n,
149
- cairoVersion: s,
150
- nonce: i,
151
- version: a,
152
- account: m,
153
- calls: g,
154
- calldata: t.calldata,
155
- salt: t.salt,
156
- signature: t.signature,
157
- classHash: t.classHash,
158
- appDomain: c
159
- // appDomain: "https://starknetkit-blacked-listed.vercel.app", // to simulate blacklisted domain
160
- };
161
- }, X = (t, e) => {
162
- const { transactions: n } = t;
163
- if (!n)
164
- throw new G({ code: "SIMULATE_AND_REVIEW_FAILED" });
165
- const a = n.map((i) => {
166
- if (!i.simulation)
167
- throw new G({ code: "SIMULATE_AND_REVIEW_FAILED" });
168
- return i;
169
- }), o = a.map((i) => ({
170
- ...i.simulation,
171
- feeEstimation: u(i.simulation.feeEstimation, Number)
172
- })), s = S(o, e), [m, c] = a.length === 1 ? [a[0], void 0] : [a[1], a[0]];
82
+ }), b = (t) => {
83
+ const { l1Gas: e, l2Gas: a, l1DataGas: n } = t.resourceBounds, s = e.maxAmount * e.maxPricePerUnit + a.maxAmount * a.maxPricePerUnit + n.maxAmount * n.maxPricePerUnit;
84
+ return o.toBigInt(s);
85
+ }, j = (t) => {
86
+ var n;
87
+ if (t.type === "paymaster")
88
+ return t.transactions.maxFee + (((n = t.deployment) == null ? void 0 : n.maxFee) ?? 0n);
89
+ if (t.deployment && !p(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
90
+ throw Error("Cannot calculate estimated fees for different tokens");
91
+ const e = t.deployment ? g(t.deployment) : 0n, a = g(t.transactions);
92
+ return e + a;
93
+ }, W = (t) => {
94
+ var e;
95
+ return t.type === "paymaster" ? t.transactions.overallFee + (((e = t.deployment) == null ? void 0 : e.overallFee) ?? 0n) : N(t);
96
+ }, B = (t = []) => t.filter((a) => a.type === "native"), $ = (t) => t.filter((e) => e.type === "paymaster"), C = () => E, I = (t = [], e) => {
97
+ const a = B(t).find((n) => p(n.transactions.feeTokenAddress, e));
98
+ if (!a)
99
+ throw Error(`No native estimated fee found for ${e}`);
100
+ return a;
101
+ }, D = (t = []) => {
102
+ const e = C();
103
+ return I(t, e);
104
+ }, K = (t = []) => D(t), N = (t) => {
105
+ if (t.deployment && !p(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
106
+ throw Error("Cannot calculate estimated fees for different tokens");
107
+ const e = d(t.transactions), a = t.deployment ? d(t.deployment) : 0n;
108
+ return e + a;
109
+ }, d = (t) => {
110
+ const { l1Gas: e, l2Gas: a, l1DataGas: n } = t;
111
+ return e.gasConsumed * e.gasPrice + a.gasConsumed * a.gasPrice + n.gasConsumed * n.gasPrice;
112
+ }, g = (t) => d(y(t)), y = (t, e = G) => {
113
+ const a = 10000n, { l1Gas: n, l2Gas: s, l1DataGas: r } = t, i = n.gasConsumed * n.gasPrice + s.gasConsumed * s.gasPrice + r.gasConsumed * r.gasPrice;
114
+ if (i < 0)
115
+ throw Error("Cannot calculate max fee for negative fee");
116
+ const m = o.toBigInt(T({ estimatedFee: i })), f = Number(m) / Number(i), x = e(f), c = BigInt(Math.trunc(x * Number(a)));
173
117
  return {
174
- ...s,
175
- transactions: {
176
- ...s.transactions,
177
- dataGasConsumed: s.transactions.dataGasConsumed ?? 0n,
178
- dataGasPrice: s.transactions.dataGasPrice ?? 0n,
179
- max: d(u(m.simulation.feeEstimation, r.toBigInt))
118
+ ...t,
119
+ l1Gas: {
120
+ gasConsumed: n.gasConsumed * c / a,
121
+ gasPrice: n.gasPrice
122
+ },
123
+ l2Gas: {
124
+ gasConsumed: s.gasConsumed * c / a,
125
+ gasPrice: s.gasPrice
180
126
  },
181
- deployment: s.deployment && c ? {
182
- ...s.deployment,
183
- dataGasConsumed: s.deployment.dataGasConsumed ?? 0n,
184
- dataGasPrice: s.deployment.dataGasPrice ?? 0n,
185
- max: d(u(c.simulation.feeEstimation, r.toBigInt))
186
- } : void 0
127
+ l1DataGas: {
128
+ gasConsumed: r.gasConsumed * c / a,
129
+ gasPrice: r.gasPrice
130
+ }
187
131
  };
188
- }, D = (t) => ({
189
- max_amount: r.toHex(t.amount),
190
- max_price_per_unit: r.toHex(t.pricePerUnit)
191
- }), R = (t, e, n) => ({
192
- // (overall_fee / gas_price) × gas_safety_margin
193
- max_amount: r.toHex(t / e),
194
- // max_price_per_unit: gas_price × fee_safety_margin
195
- max_price_per_unit: r.toHex(n)
196
- }), Z = (t) => {
197
- const e = U(t), n = P(t);
198
- return {
199
- // for v1 transactions
200
- maxFee: n,
201
- // for v3 transactions
132
+ }, q = (t) => {
133
+ const e = y(t);
134
+ return g(t), {
202
135
  resourceBounds: {
203
- l1_gas: ((o) => o !== void 0 && "amount" in o && "pricePerUnit" in o)(t.max) ? D(t.max) : R(n, t.pricePerUnit, e.pricePerUnit),
204
- l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
136
+ l1_gas: w(e.l1Gas),
137
+ l2_gas: {
138
+ max_amount: o.toHex(e.l2Gas.gasConsumed),
139
+ max_price_per_unit: o.toHex(e.l2Gas.gasPrice)
140
+ },
141
+ l1_data_gas: {
142
+ max_amount: o.toHex(e.l1DataGas.gasConsumed),
143
+ max_price_per_unit: o.toHex(e.l1DataGas.gasPrice)
144
+ }
205
145
  }
206
146
  };
207
- }, tt = (t) => {
208
- const e = Math.sqrt(t);
209
- return isNaN(e) ? Math.sqrt(2) : e;
210
- }, w = (t) => {
211
- const e = Math.cbrt(t);
212
- return isNaN(e) ? Math.cbrt(2) : e;
213
- }, nt = (t) => t < 1 || isNaN(t) ? 1.1 : Math.log(t + 1) + 1;
147
+ }, w = (t) => ({
148
+ max_amount: o.toHex(t.gasConsumed),
149
+ max_price_per_unit: o.toHex(t.gasPrice)
150
+ });
214
151
  export {
215
- J as buildDummyTx,
216
- w as calculateCubeRootAdjustment,
217
- nt as calculateNonLinearAdjustment,
218
- tt as calculateSqrtAdjustment,
219
- u as castFeeEstimation,
220
- P as estimatedFeeToMaxFeeTotal,
221
- Z as estimatedFeeToMaxResourceBounds,
222
- p as estimatedFeeToTotal,
223
- z as estimatedFeesToMaxFeeTotal,
224
- $ as estimatedFeesToTotal,
225
- S as getEstimatedFeeFromBulkSimulation,
226
- X as getEstimatedFeeFromSimulationAndRespectWatermarkFee,
227
- Q as getPayloadFromTransaction,
228
- N as getWatermarkedMaxFeeTotal,
229
- k as isFRI,
230
- E as isWEI,
231
- V as multiplyBigIntByFloat,
232
- d as toMax,
233
- Y as tokensRequireTxV3Support,
234
- x as unitToFeeTokenAddress
152
+ g as estimatedFeeToMaxFeeTotal,
153
+ q as estimatedFeeToMaxResourceBounds,
154
+ d as estimatedFeeToTotal,
155
+ j as estimatedFeesToMaxFeeTotalV2,
156
+ N as estimatedFeesToTotal,
157
+ W as estimatedFeesToTotalV2,
158
+ $ as filterPaymasterEstimatedFees,
159
+ L as getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2,
160
+ I as getNativeEstimatedFeeByFeeToken,
161
+ D as getNativeEstimatedFeeByTxVersion,
162
+ K as getNativeEstimatedFeeForAccount,
163
+ B as getNativeEstimatedFees,
164
+ h as getNativeFeeFromSimulation,
165
+ C as getNativeFeeTokenAddress,
166
+ v as getPaymasterFeeFromSimulation,
167
+ b as toMaxFeeEstimation
235
168
  };
@@ -6,7 +6,6 @@ export * from './errors';
6
6
  export * from './estimate';
7
7
  export * from './findTransfersAndApprovals';
8
8
  export * from './getPrettyRcpError';
9
- export * from './getTransactionVersion';
10
9
  export * from './service';
11
10
  export type * from './transactionAction';
12
11
  export * from './transactionReviewTypes';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("starknet"),h=require("url-join"),m=require("../../errors/review.cjs"),w=require("../getTransactionVersion.cjs"),E=require("../estimate/utils.cjs"),S=require("../../utils/url/urlWithQuery.cjs"),y=require("../../features/simulation/transactionReview/schema.cjs"),I=require("../../utils/arrays.cjs");class C{constructor(e,a){this.apiBase=e,this.httpService=a}async getLabels(){const e=h(this.apiBase,"reviewer","labels");return await this.httpService.get(e)}async getWarnings(){const e=h(this.apiBase,"reviewer","warnings/reasons");return await this.httpService.get(e)}async simulateAndReview(e,a,o,n,c,t){var l;const r=a.some(s=>s.type==="DEPLOY_ACCOUNT");try{if(!("getChainId"in e))throw new Error("MISSING_METHOD");const s=w.getTxVersionFromFeeToken(o),i=r?"0x0":await e.getNonce(),d=await e.getChainId(),F={transactions:a.map(g=>({...E.getPayloadFromTransaction({transaction:g,nonce:i,version:s,chainId:d,isDeploymentTransaction:r,appDomain:n,cairoVersion:e.cairoVersion,address:e.address}),type:g.type}))},p=h(this.apiBase,"reviewer","transactions","v2","review","starknet"),v=t?S.urlWithQuery(p,{delayedTransactions:"true"}):p,u=await this.httpService.post(v,{headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(F)},y.simulateAndReviewSchema);if((l=u.transactions)==null?void 0:l.some(g=>y.isTransactionSimulationError(g)))return u;const T=E.getEstimatedFeeFromSimulationAndRespectWatermarkFee(u,o);return{...u,enrichedFeeEstimation:T}}catch(s){return console.error(s),this.fallbackToOnchainFeeEstimation({transactions:a,account:e,isDeploymentTransaction:r,feeTokenAddress:o,accountDeployTransaction:c})}}getCallsFromTx(e){let a;return e.calls&&(a=I.ensureArray(e.calls)),a}async fallbackToOnchainFeeEstimation({transactions:e,account:a,isDeploymentTransaction:o,feeTokenAddress:n,accountDeployTransaction:c}){try{const t=o?this.getCallsFromTx(e[1]):this.getCallsFromTx(e[0]);if(!t)throw new m.ReviewError({code:"NO_CALLS_FOUND"});const r=await this.fetchFeesOnchain({starknetAccount:a,calls:t,isDeployed:!o,feeTokenAddress:n,accountDeployTransaction:c});return{transactions:[],enrichedFeeEstimation:r,isBackendDown:!0}}catch(t){throw console.error(t),new m.ReviewError({message:`${t}`,code:"SIMULATE_AND_REVIEW_FAILED"})}}async fetchFeesOnchain({starknetAccount:e,calls:a,isDeployed:o,feeTokenAddress:n,accountDeployTransaction:c}){try{const t=w.getTxVersionFromFeeToken(n),r={transactions:{feeTokenAddress:n,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!o&&c){if("estimateFeeBulk"in e){const l=[{type:_.TransactionType.DEPLOY_ACCOUNT,payload:{classHash:c.classHash,addressSalt:c.salt,constructorCalldata:c.calldata,contractAddress:e.address}},{type:_.TransactionType.INVOKE,payload:a}],[s,i]=await e.estimateFeeBulk(l,{version:t}).catch(d=>{throw console.error(d),d});if(!s.gas_consumed||!s.gas_price||!i.gas_consumed||!i.gas_price)throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});r.deployment={feeTokenAddress:n,amount:s.gas_consumed,pricePerUnit:s.gas_price,dataGasConsumed:s.data_gas_consumed,dataGasPrice:s.data_gas_price},r.transactions={feeTokenAddress:n,amount:i.gas_consumed,pricePerUnit:i.gas_price,dataGasConsumed:i.data_gas_consumed,dataGasPrice:i.data_gas_price}}}else{const{gas_consumed:l,gas_price:s,data_gas_consumed:i,data_gas_price:d}=await e.estimateFee(a,{skipValidate:!0,version:t});if(!l||!s)throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});r.transactions={feeTokenAddress:n,amount:l,pricePerUnit:s,dataGasConsumed:i,dataGasPrice:d}}return r}catch(t){throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:`${t}`})}}}exports.TransactionReviewServiceWeb=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("starknet"),E=require("url-join"),d=require("../../errors/review.cjs"),v=require("./utils.cjs"),S=require("../../utils/url/urlWithQuery.cjs"),w=require("../../features/simulation/transactionReview/schema.cjs"),I=require("../estimate/utils.cjs"),T=require("../../utils/arrays.cjs");class F{constructor(e,a){this.apiBase=e,this.httpService=a}async getLabels(){const e=E(this.apiBase,"reviewer","labels");return await this.httpService.get(e)}async getWarnings(){const e=E(this.apiBase,"reviewer","warnings/reasons");return await this.httpService.get(e)}async simulateAndReview(e,a,l,n,o,r){var g;const i=a.some(s=>s.type==="DEPLOY_ACCOUNT");try{if(!("getChainId"in e))throw new Error("MISSING_METHOD");const s=p.constants.TRANSACTION_VERSION.V3,t=i?"0x0":await e.getNonce(),c=await e.getChainId(),m={transactions:a.map(h=>({...v.getPayloadFromTransaction({transaction:h,nonce:t,version:s,chainId:c,isDeploymentTransaction:i,appDomain:n,cairoVersion:e.cairoVersion,address:e.address}),type:h.type}))},_=E(this.apiBase,"reviewer","transactions","v2","review","starknet"),y=r?S.urlWithQuery(_,{delayedTransactions:"true"}):_,u=await this.httpService.post(y,{headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(m)},w.simulateAndReviewSchema);if((g=u.transactions)==null?void 0:g.some(h=>w.isTransactionSimulationError(h)))return u;const C=I.getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2(u);return{...u,enrichedFeeEstimation:C}}catch(s){return console.error(s),this.fallbackToOnchainFeeEstimation({transactions:a,account:e,isDeploymentTransaction:i,feeTokenAddress:l,accountDeployTransaction:o})}}getCallsFromTx(e){let a;return e.calls&&(a=T.ensureArray(e.calls)),a}async fallbackToOnchainFeeEstimation({transactions:e,account:a,isDeploymentTransaction:l,feeTokenAddress:n,accountDeployTransaction:o}){try{const r=l?this.getCallsFromTx(e[1]):this.getCallsFromTx(e[0]);if(!r)throw new d.ReviewError({code:"NO_CALLS_FOUND"});const i=await this.fetchFeesOnchain({starknetAccount:a,calls:r,isDeployed:!l,feeTokenAddress:n,accountDeployTransaction:o});return{transactions:[],enrichedFeeEstimation:i,isBackendDown:!0}}catch(r){throw console.error(r),new d.ReviewError({message:`${r}`,code:"SIMULATE_AND_REVIEW_FAILED"})}}async fetchFeesOnchain({starknetAccount:e,calls:a,isDeployed:l,feeTokenAddress:n,accountDeployTransaction:o}){try{const r=p.constants.TRANSACTION_VERSION.V3,i={type:"native",transactions:{feeTokenAddress:n,l1Gas:{gasConsumed:0n,gasPrice:0n},l2Gas:{gasConsumed:0n,gasPrice:0n},l1DataGas:{gasConsumed:0n,gasPrice:0n}}};if(!l&&o){if("estimateFeeBulk"in e){const g=[{type:p.TransactionType.DEPLOY_ACCOUNT,payload:{classHash:o.classHash,addressSalt:o.salt,constructorCalldata:o.calldata,contractAddress:e.address}},{type:p.TransactionType.INVOKE,payload:a}],[s,t]=await e.estimateFeeBulk(g,{version:r}).catch(c=>{throw console.error(c),c});if(!s.l1_gas_consumed||!s.l1_gas_price||!s.l2_gas_consumed||!s.l2_gas_price||!t.l2_gas_consumed||!t.l2_gas_price)throw new d.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});i.deployment={feeTokenAddress:n,l1Gas:{gasConsumed:s.l1_gas_consumed,gasPrice:s.l1_gas_price},l2Gas:{gasConsumed:s.l2_gas_consumed,gasPrice:s.l2_gas_price},l1DataGas:{gasConsumed:s.l1_data_gas_consumed,gasPrice:s.l1_data_gas_price}},i.transactions={feeTokenAddress:n,l1Gas:{gasConsumed:t.l1_gas_consumed,gasPrice:t.l1_gas_price},l2Gas:{gasConsumed:t.l2_gas_consumed,gasPrice:t.l2_gas_price},l1DataGas:{gasConsumed:t.l1_data_gas_consumed,gasPrice:t.l1_data_gas_price}}}}else{const{l1_data_gas_price:g,l1_data_gas_consumed:s,l1_gas_consumed:t,l2_gas_price:c,l2_gas_consumed:m,l1_gas_price:_}=await e.estimateFee(a,{skipValidate:!0,version:r});if(!t||!_||!m||!c)throw new d.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});i.transactions={feeTokenAddress:n,l1Gas:{gasConsumed:t,gasPrice:_},l2Gas:{gasConsumed:m,gasPrice:c},l1DataGas:{gasConsumed:s,gasPrice:g}}}return[i]}catch(r){throw new d.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:`${r}`})}}}exports.TransactionReviewServiceWeb=F;
@@ -33,34 +33,51 @@ export declare class TransactionReviewServiceWeb implements ITransactionReviewSe
33
33
  accountDeployTransaction?: AccountDeployTransaction;
34
34
  }): Promise<{
35
35
  transactions: never[];
36
- enrichedFeeEstimation: {
36
+ enrichedFeeEstimation: ({
37
+ type: "native";
37
38
  transactions: {
38
- amount: bigint;
39
- pricePerUnit: bigint;
40
39
  feeTokenAddress: `0x${string}`;
41
- max?: {
42
- amount: bigint;
43
- pricePerUnit: bigint;
44
- } | {
45
- maxFee: bigint;
46
- } | undefined;
47
- dataGasConsumed?: bigint | undefined;
48
- dataGasPrice?: bigint | undefined;
40
+ l1Gas: {
41
+ gasConsumed: bigint;
42
+ gasPrice: bigint;
43
+ };
44
+ l2Gas: {
45
+ gasConsumed: bigint;
46
+ gasPrice: bigint;
47
+ };
48
+ l1DataGas: {
49
+ gasConsumed: bigint;
50
+ gasPrice: bigint;
51
+ };
49
52
  };
50
53
  deployment?: {
51
- amount: bigint;
52
- pricePerUnit: bigint;
53
54
  feeTokenAddress: `0x${string}`;
54
- max?: {
55
- amount: bigint;
56
- pricePerUnit: bigint;
57
- } | {
58
- maxFee: bigint;
59
- } | undefined;
60
- dataGasConsumed?: bigint | undefined;
61
- dataGasPrice?: bigint | undefined;
55
+ l1Gas: {
56
+ gasConsumed: bigint;
57
+ gasPrice: bigint;
58
+ };
59
+ l2Gas: {
60
+ gasConsumed: bigint;
61
+ gasPrice: bigint;
62
+ };
63
+ l1DataGas: {
64
+ gasConsumed: bigint;
65
+ gasPrice: bigint;
66
+ };
62
67
  } | undefined;
63
- };
68
+ } | {
69
+ type: "paymaster";
70
+ transactions: {
71
+ feeTokenAddress: `0x${string}`;
72
+ maxFee: bigint;
73
+ overallFee: bigint;
74
+ };
75
+ deployment?: {
76
+ feeTokenAddress: `0x${string}`;
77
+ maxFee: bigint;
78
+ overallFee: bigint;
79
+ } | undefined;
80
+ })[];
64
81
  isBackendDown: boolean;
65
82
  }>;
66
83
  private fetchFeesOnchain;