@argent/x-shared 1.70.3 → 1.71.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/dist/index.cjs +1 -1
- package/dist/index.js +286 -307
- package/dist/simulation.cjs +1 -1
- package/dist/simulation.js +66 -68
- package/dist/src/features/paymaster/types.d.ts +2 -2
- package/dist/src/features/simulation/fees/schema.cjs +1 -1
- package/dist/src/features/simulation/fees/schema.d.ts +665 -705
- package/dist/src/features/simulation/fees/schema.js +32 -39
- package/dist/src/features/simulation/transactionReview/schema.cjs +1 -1
- package/dist/src/features/simulation/transactionReview/schema.d.ts +2117 -7917
- package/dist/src/features/simulation/transactionReview/schema.js +103 -112
- package/dist/src/features/swap/models/execute.model.d.ts +4 -0
- package/dist/src/features/swap/services/SwapTransactionService.cjs +1 -1
- package/dist/src/features/swap/services/SwapTransactionService.js +22 -18
- package/dist/src/tokens/isUnlimitedAmount.cjs +1 -1
- package/dist/src/tokens/isUnlimitedAmount.js +3 -3
- package/dist/src/transactions/amount.cjs +1 -1
- package/dist/src/transactions/amount.d.ts +2 -2
- package/dist/src/transactions/amount.js +9 -9
- package/dist/src/transactions/estimate/adjustment.cjs +1 -0
- package/dist/src/transactions/estimate/adjustment.d.ts +4 -0
- package/dist/src/transactions/estimate/adjustment.js +7 -0
- package/dist/src/transactions/estimate/argentMaxFee.d.ts +3 -3
- package/dist/src/transactions/estimate/index.d.ts +0 -1
- package/dist/src/transactions/estimate/model.d.ts +1 -10
- package/dist/src/transactions/estimate/utils.cjs +1 -1
- package/dist/src/transactions/estimate/utils.d.ts +31 -61
- package/dist/src/transactions/estimate/utils.js +156 -223
- package/dist/src/transactions/index.d.ts +0 -1
- package/dist/src/transactions/service/implementation.cjs +1 -1
- package/dist/src/transactions/service/implementation.d.ts +39 -22
- package/dist/src/transactions/service/implementation.js +130 -97
- package/dist/src/transactions/service/index.d.ts +1 -0
- package/dist/src/transactions/service/utils.cjs +1 -0
- package/dist/src/transactions/service/utils.d.ts +25 -0
- package/dist/src/transactions/service/utils.js +25 -0
- package/dist/src/transactions/transactionSimulationTypes.d.ts +1 -7
- package/dist/src/transactions/transactionVersion.cjs +1 -1
- package/dist/src/transactions/transactionVersion.d.ts +5 -6
- package/dist/src/transactions/transactionVersion.js +10 -12
- package/package.json +2 -2
- package/dist/src/transactions/estimate/utilsV2.cjs +0 -1
- package/dist/src/transactions/estimate/utilsV2.d.ts +0 -26
- package/dist/src/transactions/estimate/utilsV2.js +0 -107
- package/dist/src/transactions/getTransactionVersion.cjs +0 -1
- package/dist/src/transactions/getTransactionVersion.d.ts +0 -12
- package/dist/src/transactions/getTransactionVersion.js +0 -21
|
@@ -1,61 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
export declare
|
|
16
|
-
export declare
|
|
17
|
-
export declare const
|
|
18
|
-
export
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 {
|
|
2
|
-
import { num as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
...
|
|
51
|
-
...
|
|
22
|
+
...m.simulation,
|
|
23
|
+
..._(m.simulation.feeEstimations)
|
|
52
24
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
return {
|
|
58
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
...
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
},
|
|
189
|
-
|
|
190
|
-
|
|
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: (
|
|
204
|
-
l2_gas: {
|
|
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
|
-
},
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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;
|