@argent/x-shared 1.72.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.
@@ -1,168 +1,169 @@
1
- import { isEmpty as P, partition as A } from "lodash-es";
1
+ import { isEmpty as y, partition as P } from "lodash-es";
2
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";
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 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))
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 (e.length > 2)
17
- throw Error(`Unexpected simulation response length. Got ${e.length}`);
18
- const a = e.map((m) => {
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 F({ code: "SIMULATE_AND_REVIEW_FAILED" });
20
+ throw new p({ code: "SIMULATE_AND_REVIEW_FAILED" });
21
21
  return {
22
22
  ...m.simulation,
23
- ..._(m.simulation.feeEstimations)
23
+ ...G(m.simulation.feeEstimations)
24
24
  };
25
- }), [n, s] = a.length === 1 ? [a[0], void 0] : [a[1], a[0]], r = h(n, s), i = v(n, s);
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
- }, _ = (t) => {
28
- const [e, a] = A(t, (n) => "unit" in n && n.unit === "FRI");
29
- return { nativeFeeEstimations: e, paymasterFeeEstimations: a };
30
- }, v = (t, e) => {
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 t.paymasterFeeEstimations.map((s) => ({
32
+ return [];
33
+ if (!t)
34
+ return e.paymasterFeeEstimations.map((n) => ({
35
35
  type: "paymaster",
36
- transactions: u(s),
36
+ transactions: d(n),
37
37
  deployment: void 0
38
38
  }));
39
- const a = e.paymasterFeeEstimations, n = t.paymasterFeeEstimations;
40
- if (a.length !== n.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 n.map((s, r) => ({
42
+ return s.map((n, r) => ({
43
43
  type: "paymaster",
44
- transactions: u(s),
45
- deployment: u(a[r])
44
+ transactions: d(n),
45
+ deployment: d(a[r])
46
46
  }));
47
- }, h = (t, e) => {
48
- if (!t)
49
- return [];
47
+ }, h = (e, t) => {
50
48
  if (!e)
51
- return t.nativeFeeEstimations.map((s) => ({
49
+ return [];
50
+ if (!t)
51
+ return e.nativeFeeEstimations.map((n) => ({
52
52
  type: "native",
53
- transactions: l(s),
53
+ transactions: g(n),
54
54
  deployment: void 0
55
55
  }));
56
- const a = e.nativeFeeEstimations, n = t.nativeFeeEstimations;
57
- if (a.length !== n.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 n.map((s, r) => ({
59
+ return s.map((n, r) => ({
60
60
  type: "native",
61
- transactions: l(s),
62
- deployment: l(a[r])
61
+ transactions: g(n),
62
+ deployment: g(a[r])
63
63
  }));
64
- }, u = (t) => ({
65
- feeTokenAddress: t.token.address,
66
- maxFee: BigInt(t.maxFee),
67
- overallFee: BigInt(t.overallFee)
68
- }), l = (t) => ({
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(t.resourceBounds.l1Gas.maxAmount),
72
- gasPrice: o.toBigInt(t.resourceBounds.l1Gas.maxPricePerUnit)
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(t.resourceBounds.l1DataGas.maxAmount),
76
- gasPrice: o.toBigInt(t.resourceBounds.l1DataGas.maxPricePerUnit)
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(t.resourceBounds.l2Gas.maxAmount),
80
- gasPrice: o.toBigInt(t.resourceBounds.l2Gas.maxPricePerUnit)
80
+ gasConsumed: o.toBigInt(e.resourceBounds.l2Gas.maxAmount),
81
+ gasPrice: o.toBigInt(e.resourceBounds.l2Gas.maxPricePerUnit)
81
82
  }
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))
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 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));
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 ${e}`);
100
+ throw Error(`No native estimated fee found for ${t}`);
100
101
  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))
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 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;
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(T({ estimatedFee: i })), f = Number(m) / Number(i), x = e(f), c = BigInt(Math.trunc(x * Number(a)));
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
- ...t,
119
+ ...e,
119
120
  l1Gas: {
120
- gasConsumed: n.gasConsumed * c / a,
121
- gasPrice: n.gasPrice
121
+ gasConsumed: s.gasConsumed * c / a,
122
+ gasPrice: s.gasPrice * c / a
122
123
  },
123
124
  l2Gas: {
124
- gasConsumed: s.gasConsumed * c / a,
125
- gasPrice: s.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
- }, q = (t) => {
133
- const e = y(t);
134
- return g(t), {
133
+ }, O = (e) => {
134
+ const t = e.overallFee ? e : f(e);
135
+ return {
135
136
  resourceBounds: {
136
- l1_gas: w(e.l1Gas),
137
+ l1_gas: w(t.l1Gas),
137
138
  l2_gas: {
138
- max_amount: o.toHex(e.l2Gas.gasConsumed),
139
- max_price_per_unit: o.toHex(e.l2Gas.gasPrice)
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(e.l1DataGas.gasConsumed),
143
- max_price_per_unit: o.toHex(e.l1DataGas.gasPrice)
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 = (t) => ({
148
- max_amount: o.toHex(t.gasConsumed),
149
- max_price_per_unit: o.toHex(t.gasPrice)
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
- g as estimatedFeeToMaxFeeTotal,
153
- q as estimatedFeeToMaxResourceBounds,
154
- d as estimatedFeeToTotal,
153
+ N as estimatedFeeToMaxFeeTotal,
154
+ O as estimatedFeeToMaxResourceBounds,
155
+ l as estimatedFeeToTotal,
155
156
  j as estimatedFeesToMaxFeeTotalV2,
156
- N as estimatedFeesToTotal,
157
- W as estimatedFeesToTotalV2,
157
+ D as estimatedFeesToTotal,
158
+ W as estimatedFeesToTotalWithOverallFee,
158
159
  $ as filterPaymasterEstimatedFees,
159
160
  L as getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2,
160
- I as getNativeEstimatedFeeByFeeToken,
161
- D as getNativeEstimatedFeeByTxVersion,
161
+ C as getNativeEstimatedFeeByFeeToken,
162
+ I as getNativeEstimatedFeeByTxVersion,
162
163
  K as getNativeEstimatedFeeForAccount,
163
- B as getNativeEstimatedFees,
164
+ _ as getNativeEstimatedFees,
164
165
  h as getNativeFeeFromSimulation,
165
- C as getNativeFeeTokenAddress,
166
- v as getPaymasterFeeFromSimulation,
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.72.0",
3
+ "version": "1.72.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"