@argent/x-shared 1.71.0 → 1.72.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +36 -36
- package/dist/simulation.cjs +1 -1
- package/dist/simulation.js +54 -48
- package/dist/src/features/simulation/activity/utils/index.d.ts +3 -0
- package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.cjs +1 -0
- package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.d.ts +3 -0
- package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.js +24 -0
- package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.cjs +1 -0
- package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.d.ts +3 -0
- package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.js +24 -0
- package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.cjs +1 -0
- package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.d.ts +3 -0
- package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.js +24 -0
- package/dist/src/features/simulation/activity/utils/isReplaceMultisigSignersActivity.d.ts +3 -0
- package/dist/src/features/simulation/activity/utils/isSwapActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isSwapActivity.d.ts +2 -1
- package/dist/src/features/simulation/activity/utils/isSwapActivity.js +15 -17
- package/dist/src/features/simulation/activity/utils/isUpgradeActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isUpgradeActivity.d.ts +2 -1
- package/dist/src/features/simulation/activity/utils/isUpgradeActivity.js +16 -14
- package/dist/src/features/simulation/fees/schema.cjs +1 -1
- package/dist/src/features/simulation/fees/schema.d.ts +72 -32
- package/dist/src/features/simulation/fees/schema.js +9 -8
- package/dist/src/features/simulation/transactionReview/schema.d.ts +62 -48
- package/dist/src/transactions/estimate/utils.cjs +1 -1
- package/dist/src/transactions/estimate/utils.d.ts +1 -1
- package/dist/src/transactions/estimate/utils.js +109 -108
- package/dist/src/transactions/service/implementation.d.ts +4 -2
- package/package.json +1 -1
|
@@ -1,168 +1,169 @@
|
|
|
1
|
-
import { isEmpty as
|
|
1
|
+
import { isEmpty as y, partition as P } from "lodash-es";
|
|
2
2
|
import { num as o } from "starknet";
|
|
3
|
-
import { calculateCubeRootAdjustment as
|
|
4
|
-
import { argentMaxFee as
|
|
5
|
-
import { EstimateError as
|
|
3
|
+
import { calculateCubeRootAdjustment as v } from "./adjustment.js";
|
|
4
|
+
import { argentMaxFee as A } from "./argentMaxFee.js";
|
|
5
|
+
import { EstimateError as p } from "./error.js";
|
|
6
6
|
import { STRK_TOKEN_ADDRESS as E } from "../../chains/starknet/constants.js";
|
|
7
|
-
import { isEqualAddress as
|
|
8
|
-
const L = (
|
|
9
|
-
const { transactions:
|
|
10
|
-
if (!
|
|
11
|
-
throw new
|
|
12
|
-
if (!Array.isArray(
|
|
13
|
-
throw Error(`Unexpected simulation response. Expected array. Got ${typeof
|
|
14
|
-
if (
|
|
7
|
+
import { isEqualAddress as F } from "../../chains/starknet/address.js";
|
|
8
|
+
const L = (e) => {
|
|
9
|
+
const { transactions: t } = e;
|
|
10
|
+
if (!t)
|
|
11
|
+
throw new p({ code: "SIMULATE_AND_REVIEW_FAILED" });
|
|
12
|
+
if (!Array.isArray(t))
|
|
13
|
+
throw Error(`Unexpected simulation response. Expected array. Got ${typeof t}`);
|
|
14
|
+
if (y(t))
|
|
15
15
|
return [];
|
|
16
|
-
if (
|
|
17
|
-
throw Error(`Unexpected simulation response length. Got ${
|
|
18
|
-
const a =
|
|
16
|
+
if (t.length > 2)
|
|
17
|
+
throw Error(`Unexpected simulation response length. Got ${t.length}`);
|
|
18
|
+
const a = t.map((m) => {
|
|
19
19
|
if (!m.simulation)
|
|
20
|
-
throw new
|
|
20
|
+
throw new p({ code: "SIMULATE_AND_REVIEW_FAILED" });
|
|
21
21
|
return {
|
|
22
22
|
...m.simulation,
|
|
23
|
-
...
|
|
23
|
+
...G(m.simulation.feeEstimations)
|
|
24
24
|
};
|
|
25
|
-
}), [
|
|
25
|
+
}), [s, n] = a.length === 1 ? [a[0], void 0] : [a[1], a[0]], r = h(s, n), i = T(s, n);
|
|
26
26
|
return [...r, ...i];
|
|
27
|
-
},
|
|
28
|
-
const [
|
|
29
|
-
return { nativeFeeEstimations:
|
|
30
|
-
},
|
|
31
|
-
if (!t)
|
|
32
|
-
return [];
|
|
27
|
+
}, G = (e) => {
|
|
28
|
+
const [t, a] = P(e, (s) => "unit" in s && s.unit === "FRI");
|
|
29
|
+
return { nativeFeeEstimations: t, paymasterFeeEstimations: a };
|
|
30
|
+
}, T = (e, t) => {
|
|
33
31
|
if (!e)
|
|
34
|
-
return
|
|
32
|
+
return [];
|
|
33
|
+
if (!t)
|
|
34
|
+
return e.paymasterFeeEstimations.map((n) => ({
|
|
35
35
|
type: "paymaster",
|
|
36
|
-
transactions:
|
|
36
|
+
transactions: d(n),
|
|
37
37
|
deployment: void 0
|
|
38
38
|
}));
|
|
39
|
-
const a =
|
|
40
|
-
if (a.length !==
|
|
39
|
+
const a = t.paymasterFeeEstimations, s = e.paymasterFeeEstimations;
|
|
40
|
+
if (a.length !== s.length)
|
|
41
41
|
throw Error("Deployment and transaction fee estimations length mismatch");
|
|
42
|
-
return
|
|
42
|
+
return s.map((n, r) => ({
|
|
43
43
|
type: "paymaster",
|
|
44
|
-
transactions:
|
|
45
|
-
deployment:
|
|
44
|
+
transactions: d(n),
|
|
45
|
+
deployment: d(a[r])
|
|
46
46
|
}));
|
|
47
|
-
}, h = (
|
|
48
|
-
if (!t)
|
|
49
|
-
return [];
|
|
47
|
+
}, h = (e, t) => {
|
|
50
48
|
if (!e)
|
|
51
|
-
return
|
|
49
|
+
return [];
|
|
50
|
+
if (!t)
|
|
51
|
+
return e.nativeFeeEstimations.map((n) => ({
|
|
52
52
|
type: "native",
|
|
53
|
-
transactions:
|
|
53
|
+
transactions: g(n),
|
|
54
54
|
deployment: void 0
|
|
55
55
|
}));
|
|
56
|
-
const a =
|
|
57
|
-
if (a.length !==
|
|
56
|
+
const a = t.nativeFeeEstimations, s = e.nativeFeeEstimations;
|
|
57
|
+
if (a.length !== s.length)
|
|
58
58
|
throw Error("Deployment and transaction fee estimations length mismatch");
|
|
59
|
-
return
|
|
59
|
+
return s.map((n, r) => ({
|
|
60
60
|
type: "native",
|
|
61
|
-
transactions:
|
|
62
|
-
deployment:
|
|
61
|
+
transactions: g(n),
|
|
62
|
+
deployment: g(a[r])
|
|
63
63
|
}));
|
|
64
|
-
},
|
|
65
|
-
feeTokenAddress:
|
|
66
|
-
maxFee: BigInt(
|
|
67
|
-
overallFee: BigInt(
|
|
68
|
-
}),
|
|
64
|
+
}, d = (e) => ({
|
|
65
|
+
feeTokenAddress: e.token.address,
|
|
66
|
+
maxFee: BigInt(e.maxFee),
|
|
67
|
+
overallFee: BigInt(e.overallFee)
|
|
68
|
+
}), g = (e) => ({
|
|
69
69
|
feeTokenAddress: E,
|
|
70
|
+
overallFee: o.toBigInt(e.overallFee),
|
|
70
71
|
l1Gas: {
|
|
71
|
-
gasConsumed: o.toBigInt(
|
|
72
|
-
gasPrice: o.toBigInt(
|
|
72
|
+
gasConsumed: o.toBigInt(e.resourceBounds.l1Gas.maxAmount),
|
|
73
|
+
gasPrice: o.toBigInt(e.resourceBounds.l1Gas.maxPricePerUnit)
|
|
73
74
|
},
|
|
74
75
|
l1DataGas: {
|
|
75
|
-
gasConsumed: o.toBigInt(
|
|
76
|
-
gasPrice: o.toBigInt(
|
|
76
|
+
gasConsumed: o.toBigInt(e.resourceBounds.l1DataGas.maxAmount),
|
|
77
|
+
gasPrice: o.toBigInt(e.resourceBounds.l1DataGas.maxPricePerUnit)
|
|
77
78
|
},
|
|
78
79
|
l2Gas: {
|
|
79
|
-
gasConsumed: o.toBigInt(
|
|
80
|
-
gasPrice: o.toBigInt(
|
|
80
|
+
gasConsumed: o.toBigInt(e.resourceBounds.l2Gas.maxAmount),
|
|
81
|
+
gasPrice: o.toBigInt(e.resourceBounds.l2Gas.maxPricePerUnit)
|
|
81
82
|
}
|
|
82
|
-
}), b = (
|
|
83
|
-
const { l1Gas:
|
|
84
|
-
return o.toBigInt(
|
|
85
|
-
}, j = (
|
|
86
|
-
|
|
87
|
-
if (t
|
|
88
|
-
return
|
|
89
|
-
if (
|
|
83
|
+
}), b = (e) => {
|
|
84
|
+
const { l1Gas: t, l2Gas: a, l1DataGas: s } = e.resourceBounds, n = t.maxAmount * t.maxPricePerUnit + a.maxAmount * a.maxPricePerUnit + s.maxAmount * s.maxPricePerUnit;
|
|
85
|
+
return o.toBigInt(n);
|
|
86
|
+
}, j = (e) => {
|
|
87
|
+
const { type: t, deployment: a, transactions: s } = e;
|
|
88
|
+
if (t === "paymaster")
|
|
89
|
+
return s.maxFee + ((a == null ? void 0 : a.maxFee) ?? 0n);
|
|
90
|
+
if (a && !F(a.feeTokenAddress, s.feeTokenAddress))
|
|
90
91
|
throw Error("Cannot calculate estimated fees for different tokens");
|
|
91
|
-
const
|
|
92
|
-
return
|
|
93
|
-
}, W = (
|
|
94
|
-
var
|
|
95
|
-
return
|
|
96
|
-
},
|
|
97
|
-
const a =
|
|
92
|
+
const n = !s.overallFee && !(a != null && a.overallFee), r = (u) => n ? N(u) : l(u), i = a ? r(a) : 0n, m = r(s);
|
|
93
|
+
return i + m;
|
|
94
|
+
}, W = (e) => {
|
|
95
|
+
var t;
|
|
96
|
+
return e.transactions.overallFee ? e.transactions.overallFee + (((t = e.deployment) == null ? void 0 : t.overallFee) ?? 0n) : D(e);
|
|
97
|
+
}, _ = (e = []) => e.filter((a) => a.type === "native"), $ = (e) => e.filter((t) => t.type === "paymaster"), B = () => E, C = (e = [], t) => {
|
|
98
|
+
const a = _(e).find((s) => F(s.transactions.feeTokenAddress, t));
|
|
98
99
|
if (!a)
|
|
99
|
-
throw Error(`No native estimated fee found for ${
|
|
100
|
+
throw Error(`No native estimated fee found for ${t}`);
|
|
100
101
|
return a;
|
|
101
|
-
},
|
|
102
|
-
const
|
|
103
|
-
return
|
|
104
|
-
}, K = (
|
|
105
|
-
if (
|
|
102
|
+
}, I = (e = []) => {
|
|
103
|
+
const t = B();
|
|
104
|
+
return C(e, t);
|
|
105
|
+
}, K = (e = []) => I(e), D = (e) => {
|
|
106
|
+
if (e.deployment && !F(e.deployment.feeTokenAddress, e.transactions.feeTokenAddress))
|
|
106
107
|
throw Error("Cannot calculate estimated fees for different tokens");
|
|
107
|
-
const
|
|
108
|
-
return
|
|
109
|
-
},
|
|
110
|
-
const { l1Gas:
|
|
111
|
-
return
|
|
112
|
-
},
|
|
113
|
-
const a = 10000n, { l1Gas:
|
|
108
|
+
const t = l(e.transactions), a = e.deployment ? l(e.deployment) : 0n;
|
|
109
|
+
return t + a;
|
|
110
|
+
}, l = (e) => {
|
|
111
|
+
const { l1Gas: t, l2Gas: a, l1DataGas: s } = e;
|
|
112
|
+
return t.gasConsumed * t.gasPrice + a.gasConsumed * a.gasPrice + s.gasConsumed * s.gasPrice;
|
|
113
|
+
}, N = (e) => l(f(e)), f = (e, t = v) => {
|
|
114
|
+
const a = 10000n, { l1Gas: s, l2Gas: n, l1DataGas: r } = e, i = s.gasConsumed * s.gasPrice + n.gasConsumed * n.gasPrice + r.gasConsumed * r.gasPrice;
|
|
114
115
|
if (i < 0)
|
|
115
116
|
throw Error("Cannot calculate max fee for negative fee");
|
|
116
|
-
const m = o.toBigInt(
|
|
117
|
+
const m = o.toBigInt(A({ estimatedFee: i })), u = Number(m) / Number(i), x = t(u), c = BigInt(Math.trunc(x * Number(a)));
|
|
117
118
|
return {
|
|
118
|
-
...
|
|
119
|
+
...e,
|
|
119
120
|
l1Gas: {
|
|
120
|
-
gasConsumed:
|
|
121
|
-
gasPrice:
|
|
121
|
+
gasConsumed: s.gasConsumed * c / a,
|
|
122
|
+
gasPrice: s.gasPrice * c / a
|
|
122
123
|
},
|
|
123
124
|
l2Gas: {
|
|
124
|
-
gasConsumed:
|
|
125
|
-
gasPrice:
|
|
125
|
+
gasConsumed: n.gasConsumed * c / a,
|
|
126
|
+
gasPrice: n.gasPrice * c / a
|
|
126
127
|
},
|
|
127
128
|
l1DataGas: {
|
|
128
129
|
gasConsumed: r.gasConsumed * c / a,
|
|
129
|
-
gasPrice: r.gasPrice
|
|
130
|
+
gasPrice: r.gasPrice * c / a
|
|
130
131
|
}
|
|
131
132
|
};
|
|
132
|
-
},
|
|
133
|
-
const
|
|
134
|
-
return
|
|
133
|
+
}, O = (e) => {
|
|
134
|
+
const t = e.overallFee ? e : f(e);
|
|
135
|
+
return {
|
|
135
136
|
resourceBounds: {
|
|
136
|
-
l1_gas: w(
|
|
137
|
+
l1_gas: w(t.l1Gas),
|
|
137
138
|
l2_gas: {
|
|
138
|
-
max_amount: o.toHex(
|
|
139
|
-
max_price_per_unit: o.toHex(
|
|
139
|
+
max_amount: o.toHex(t.l2Gas.gasConsumed),
|
|
140
|
+
max_price_per_unit: o.toHex(t.l2Gas.gasPrice)
|
|
140
141
|
},
|
|
141
142
|
l1_data_gas: {
|
|
142
|
-
max_amount: o.toHex(
|
|
143
|
-
max_price_per_unit: o.toHex(
|
|
143
|
+
max_amount: o.toHex(t.l1DataGas.gasConsumed),
|
|
144
|
+
max_price_per_unit: o.toHex(t.l1DataGas.gasPrice)
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
};
|
|
147
|
-
}, w = (
|
|
148
|
-
max_amount: o.toHex(
|
|
149
|
-
max_price_per_unit: o.toHex(
|
|
148
|
+
}, w = (e) => ({
|
|
149
|
+
max_amount: o.toHex(e.gasConsumed),
|
|
150
|
+
max_price_per_unit: o.toHex(e.gasPrice)
|
|
150
151
|
});
|
|
151
152
|
export {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
N as estimatedFeeToMaxFeeTotal,
|
|
154
|
+
O as estimatedFeeToMaxResourceBounds,
|
|
155
|
+
l as estimatedFeeToTotal,
|
|
155
156
|
j as estimatedFeesToMaxFeeTotalV2,
|
|
156
|
-
|
|
157
|
-
W as
|
|
157
|
+
D as estimatedFeesToTotal,
|
|
158
|
+
W as estimatedFeesToTotalWithOverallFee,
|
|
158
159
|
$ as filterPaymasterEstimatedFees,
|
|
159
160
|
L as getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2,
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
C as getNativeEstimatedFeeByFeeToken,
|
|
162
|
+
I as getNativeEstimatedFeeByTxVersion,
|
|
162
163
|
K as getNativeEstimatedFeeForAccount,
|
|
163
|
-
|
|
164
|
+
_ as getNativeEstimatedFees,
|
|
164
165
|
h as getNativeFeeFromSimulation,
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
B as getNativeFeeTokenAddress,
|
|
167
|
+
T as getPaymasterFeeFromSimulation,
|
|
167
168
|
b as toMaxFeeEstimation
|
|
168
169
|
};
|
|
@@ -49,6 +49,7 @@ export declare class TransactionReviewServiceWeb implements ITransactionReviewSe
|
|
|
49
49
|
gasConsumed: bigint;
|
|
50
50
|
gasPrice: bigint;
|
|
51
51
|
};
|
|
52
|
+
overallFee?: bigint | undefined;
|
|
52
53
|
};
|
|
53
54
|
deployment?: {
|
|
54
55
|
feeTokenAddress: `0x${string}`;
|
|
@@ -64,18 +65,19 @@ export declare class TransactionReviewServiceWeb implements ITransactionReviewSe
|
|
|
64
65
|
gasConsumed: bigint;
|
|
65
66
|
gasPrice: bigint;
|
|
66
67
|
};
|
|
68
|
+
overallFee?: bigint | undefined;
|
|
67
69
|
} | undefined;
|
|
68
70
|
} | {
|
|
69
71
|
type: "paymaster";
|
|
70
72
|
transactions: {
|
|
71
73
|
feeTokenAddress: `0x${string}`;
|
|
72
|
-
maxFee: bigint;
|
|
73
74
|
overallFee: bigint;
|
|
75
|
+
maxFee: bigint;
|
|
74
76
|
};
|
|
75
77
|
deployment?: {
|
|
76
78
|
feeTokenAddress: `0x${string}`;
|
|
77
|
-
maxFee: bigint;
|
|
78
79
|
overallFee: bigint;
|
|
80
|
+
maxFee: bigint;
|
|
79
81
|
} | undefined;
|
|
80
82
|
})[];
|
|
81
83
|
isBackendDown: boolean;
|