@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.
Files changed (47) 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 +66 -68
  5. package/dist/src/features/paymaster/types.d.ts +2 -2
  6. package/dist/src/features/simulation/fees/schema.cjs +1 -1
  7. package/dist/src/features/simulation/fees/schema.d.ts +665 -705
  8. package/dist/src/features/simulation/fees/schema.js +32 -39
  9. package/dist/src/features/simulation/transactionReview/schema.cjs +1 -1
  10. package/dist/src/features/simulation/transactionReview/schema.d.ts +2117 -7917
  11. package/dist/src/features/simulation/transactionReview/schema.js +103 -112
  12. package/dist/src/features/swap/models/execute.model.d.ts +4 -0
  13. package/dist/src/features/swap/services/SwapTransactionService.cjs +1 -1
  14. package/dist/src/features/swap/services/SwapTransactionService.js +22 -18
  15. package/dist/src/tokens/isUnlimitedAmount.cjs +1 -1
  16. package/dist/src/tokens/isUnlimitedAmount.js +3 -3
  17. package/dist/src/transactions/amount.cjs +1 -1
  18. package/dist/src/transactions/amount.d.ts +2 -2
  19. package/dist/src/transactions/amount.js +9 -9
  20. package/dist/src/transactions/estimate/adjustment.cjs +1 -0
  21. package/dist/src/transactions/estimate/adjustment.d.ts +4 -0
  22. package/dist/src/transactions/estimate/adjustment.js +7 -0
  23. package/dist/src/transactions/estimate/argentMaxFee.d.ts +3 -3
  24. package/dist/src/transactions/estimate/index.d.ts +0 -1
  25. package/dist/src/transactions/estimate/model.d.ts +1 -10
  26. package/dist/src/transactions/estimate/utils.cjs +1 -1
  27. package/dist/src/transactions/estimate/utils.d.ts +31 -61
  28. package/dist/src/transactions/estimate/utils.js +156 -223
  29. package/dist/src/transactions/index.d.ts +0 -1
  30. package/dist/src/transactions/service/implementation.cjs +1 -1
  31. package/dist/src/transactions/service/implementation.d.ts +39 -22
  32. package/dist/src/transactions/service/implementation.js +130 -97
  33. package/dist/src/transactions/service/index.d.ts +1 -0
  34. package/dist/src/transactions/service/utils.cjs +1 -0
  35. package/dist/src/transactions/service/utils.d.ts +25 -0
  36. package/dist/src/transactions/service/utils.js +25 -0
  37. package/dist/src/transactions/transactionSimulationTypes.d.ts +1 -7
  38. package/dist/src/transactions/transactionVersion.cjs +1 -1
  39. package/dist/src/transactions/transactionVersion.d.ts +5 -6
  40. package/dist/src/transactions/transactionVersion.js +10 -12
  41. package/package.json +2 -2
  42. package/dist/src/transactions/estimate/utilsV2.cjs +0 -1
  43. package/dist/src/transactions/estimate/utilsV2.d.ts +0 -26
  44. package/dist/src/transactions/estimate/utilsV2.js +0 -107
  45. package/dist/src/transactions/getTransactionVersion.cjs +0 -1
  46. package/dist/src/transactions/getTransactionVersion.d.ts +0 -12
  47. package/dist/src/transactions/getTransactionVersion.js +0 -21
@@ -1,183 +1,216 @@
1
- import { TransactionType as u } from "starknet";
2
- import g from "url-join";
3
- import { ReviewError as d } from "../../errors/review.js";
4
- import { getTxVersionFromFeeToken as E } from "../getTransactionVersion.js";
5
- import { getPayloadFromTransaction as I, getEstimatedFeeFromSimulationAndRespectWatermarkFee as C } from "../estimate/utils.js";
6
- import { urlWithQuery as O } from "../../utils/url/urlWithQuery.js";
7
- import { simulateAndReviewSchema as S, isTransactionSimulationError as N } from "../../features/simulation/transactionReview/schema.js";
8
- import { ensureArray as v } from "../../utils/arrays.js";
9
- class x {
10
- constructor(a, e) {
11
- this.apiBase = a, this.httpService = e;
1
+ import { constants as E, TransactionType as w } from "starknet";
2
+ import u from "url-join";
3
+ import { ReviewError as m } from "../../errors/review.js";
4
+ import { getPayloadFromTransaction as I } from "./utils.js";
5
+ import { urlWithQuery as F } from "../../utils/url/urlWithQuery.js";
6
+ import { simulateAndReviewSchema as N, isTransactionSimulationError as O } from "../../features/simulation/transactionReview/schema.js";
7
+ import { getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2 as S } from "../estimate/utils.js";
8
+ import { ensureArray as T } from "../../utils/arrays.js";
9
+ class B {
10
+ constructor(s, e) {
11
+ this.apiBase = s, this.httpService = e;
12
12
  }
13
13
  /**
14
14
  * Fetch transaction review labels
15
15
  * @returns {Promise<TransactionReviewLabel[] | undefined>} The account activities.
16
16
  */
17
17
  async getLabels() {
18
- const a = g(this.apiBase, "reviewer", "labels");
19
- return await this.httpService.get(a);
18
+ const s = u(this.apiBase, "reviewer", "labels");
19
+ return await this.httpService.get(s);
20
20
  }
21
21
  /**
22
22
  * Fetch transaction review warnings.
23
23
  * @returns {Promise<TransactionReviewWarning[] | undefined>} The account activities.
24
24
  */
25
25
  async getWarnings() {
26
- const a = g(this.apiBase, "reviewer", "warnings/reasons");
27
- return await this.httpService.get(a);
26
+ const s = u(this.apiBase, "reviewer", "warnings/reasons");
27
+ return await this.httpService.get(s);
28
28
  }
29
- async simulateAndReview(a, e, o, n, c, s) {
30
- var m;
31
- const r = e.some((t) => t.type === "DEPLOY_ACCOUNT");
29
+ async simulateAndReview(s, e, l, n, o, r) {
30
+ var _;
31
+ const i = e.some((a) => a.type === "DEPLOY_ACCOUNT");
32
32
  try {
33
- if (!("getChainId" in a))
33
+ if (!("getChainId" in s))
34
34
  throw new Error("MISSING_METHOD");
35
- const t = E(o), i = r ? "0x0" : await a.getNonce(), l = await a.getChainId(), w = {
35
+ const a = E.TRANSACTION_VERSION.V3, t = i ? "0x0" : await s.getNonce(), c = await s.getChainId(), d = {
36
36
  transactions: e.map((h) => ({
37
37
  ...I({
38
38
  transaction: h,
39
- nonce: i,
40
- version: t,
41
- chainId: l,
42
- isDeploymentTransaction: r,
39
+ nonce: t,
40
+ version: a,
41
+ chainId: c,
42
+ isDeploymentTransaction: i,
43
43
  appDomain: n,
44
- cairoVersion: a.cairoVersion,
45
- address: a.address
44
+ cairoVersion: s.cairoVersion,
45
+ address: s.address
46
46
  }),
47
47
  type: h.type
48
48
  }))
49
- }, _ = g(this.apiBase, "reviewer", "transactions", "v2", "review", "starknet"), y = s ? O(_, { delayedTransactions: "true" }) : _, p = await this.httpService.post(y, {
49
+ }, g = u(this.apiBase, "reviewer", "transactions", "v2", "review", "starknet"), C = r ? F(g, { delayedTransactions: "true" }) : g, p = await this.httpService.post(C, {
50
50
  headers: {
51
51
  Accept: "application/json",
52
52
  "Content-Type": "application/json"
53
53
  },
54
- body: JSON.stringify(w)
55
- }, S);
56
- if ((m = p.transactions) == null ? void 0 : m.some((h) => N(h)))
54
+ body: JSON.stringify(d)
55
+ }, N);
56
+ if ((_ = p.transactions) == null ? void 0 : _.some((h) => O(h)))
57
57
  return p;
58
- const F = C(p, o);
58
+ const y = S(p);
59
59
  return {
60
60
  ...p,
61
- enrichedFeeEstimation: F
61
+ enrichedFeeEstimation: y
62
62
  };
63
- } catch (t) {
64
- return console.error(t), this.fallbackToOnchainFeeEstimation({
63
+ } catch (a) {
64
+ return console.error(a), this.fallbackToOnchainFeeEstimation({
65
65
  transactions: e,
66
- account: a,
67
- isDeploymentTransaction: r,
68
- feeTokenAddress: o,
69
- accountDeployTransaction: c
66
+ account: s,
67
+ isDeploymentTransaction: i,
68
+ feeTokenAddress: l,
69
+ accountDeployTransaction: o
70
70
  });
71
71
  }
72
72
  }
73
- getCallsFromTx(a) {
73
+ getCallsFromTx(s) {
74
74
  let e;
75
- return a.calls && (e = v(a.calls)), e;
75
+ return s.calls && (e = T(s.calls)), e;
76
76
  }
77
- async fallbackToOnchainFeeEstimation({ transactions: a, account: e, isDeploymentTransaction: o, feeTokenAddress: n, accountDeployTransaction: c }) {
77
+ async fallbackToOnchainFeeEstimation({ transactions: s, account: e, isDeploymentTransaction: l, feeTokenAddress: n, accountDeployTransaction: o }) {
78
78
  try {
79
- const s = o ? this.getCallsFromTx(a[1]) : this.getCallsFromTx(a[0]);
80
- if (!s)
81
- throw new d({
79
+ const r = l ? this.getCallsFromTx(s[1]) : this.getCallsFromTx(s[0]);
80
+ if (!r)
81
+ throw new m({
82
82
  code: "NO_CALLS_FOUND"
83
83
  });
84
- const r = await this.fetchFeesOnchain({
84
+ const i = await this.fetchFeesOnchain({
85
85
  starknetAccount: e,
86
- calls: s,
87
- isDeployed: !o,
86
+ calls: r,
87
+ isDeployed: !l,
88
88
  feeTokenAddress: n,
89
- accountDeployTransaction: c
89
+ accountDeployTransaction: o
90
90
  });
91
91
  return {
92
92
  transactions: [],
93
- enrichedFeeEstimation: r,
93
+ enrichedFeeEstimation: i,
94
94
  isBackendDown: !0
95
95
  };
96
- } catch (s) {
97
- throw console.error(s), new d({
98
- message: `${s}`,
96
+ } catch (r) {
97
+ throw console.error(r), new m({
98
+ message: `${r}`,
99
99
  code: "SIMULATE_AND_REVIEW_FAILED"
100
100
  });
101
101
  }
102
102
  }
103
- async fetchFeesOnchain({ starknetAccount: a, calls: e, isDeployed: o, feeTokenAddress: n, accountDeployTransaction: c }) {
103
+ async fetchFeesOnchain({ starknetAccount: s, calls: e, isDeployed: l, feeTokenAddress: n, accountDeployTransaction: o }) {
104
104
  try {
105
- const s = E(n), r = {
105
+ const r = E.TRANSACTION_VERSION.V3, i = {
106
+ type: "native",
106
107
  transactions: {
107
108
  feeTokenAddress: n,
108
- amount: 0n,
109
- pricePerUnit: 0n,
110
- dataGasConsumed: 0n,
111
- dataGasPrice: 0n
109
+ l1Gas: {
110
+ gasConsumed: 0n,
111
+ gasPrice: 0n
112
+ },
113
+ l2Gas: {
114
+ gasConsumed: 0n,
115
+ gasPrice: 0n
116
+ },
117
+ l1DataGas: {
118
+ gasConsumed: 0n,
119
+ gasPrice: 0n
120
+ }
112
121
  }
113
122
  };
114
- if (!o && c) {
115
- if ("estimateFeeBulk" in a) {
116
- const m = [
123
+ if (!l && o) {
124
+ if ("estimateFeeBulk" in s) {
125
+ const _ = [
117
126
  {
118
- type: u.DEPLOY_ACCOUNT,
127
+ type: w.DEPLOY_ACCOUNT,
119
128
  payload: {
120
- classHash: c.classHash,
121
- addressSalt: c.salt,
122
- constructorCalldata: c.calldata,
123
- contractAddress: a.address
129
+ classHash: o.classHash,
130
+ addressSalt: o.salt,
131
+ constructorCalldata: o.calldata,
132
+ contractAddress: s.address
124
133
  }
125
134
  },
126
135
  {
127
- type: u.INVOKE,
136
+ type: w.INVOKE,
128
137
  payload: e
129
138
  }
130
- ], [t, i] = await a.estimateFeeBulk(m, {
131
- version: s
132
- }).catch((l) => {
133
- throw console.error(l), l;
139
+ ], [a, t] = await s.estimateFeeBulk(_, {
140
+ version: r
141
+ }).catch((c) => {
142
+ throw console.error(c), c;
134
143
  });
135
- if (!t.gas_consumed || !t.gas_price || !i.gas_consumed || !i.gas_price)
136
- throw new d({
144
+ if (!a.l1_gas_consumed || !a.l1_gas_price || !a.l2_gas_consumed || !a.l2_gas_price || !t.l2_gas_consumed || !t.l2_gas_price)
145
+ throw new m({
137
146
  code: "ONCHAIN_FEE_ESTIMATION_FAILED",
138
147
  message: "Missing gas_consumed or gas_price"
139
148
  });
140
- r.deployment = {
149
+ i.deployment = {
141
150
  feeTokenAddress: n,
142
- amount: t.gas_consumed,
143
- pricePerUnit: t.gas_price,
144
- dataGasConsumed: t.data_gas_consumed,
145
- dataGasPrice: t.data_gas_price
146
- }, r.transactions = {
151
+ l1Gas: {
152
+ gasConsumed: a.l1_gas_consumed,
153
+ gasPrice: a.l1_gas_price
154
+ },
155
+ l2Gas: {
156
+ gasConsumed: a.l2_gas_consumed,
157
+ gasPrice: a.l2_gas_price
158
+ },
159
+ l1DataGas: {
160
+ gasConsumed: a.l1_data_gas_consumed,
161
+ gasPrice: a.l1_data_gas_price
162
+ }
163
+ }, i.transactions = {
147
164
  feeTokenAddress: n,
148
- amount: i.gas_consumed,
149
- pricePerUnit: i.gas_price,
150
- dataGasConsumed: i.data_gas_consumed,
151
- dataGasPrice: i.data_gas_price
165
+ l1Gas: {
166
+ gasConsumed: t.l1_gas_consumed,
167
+ gasPrice: t.l1_gas_price
168
+ },
169
+ l2Gas: {
170
+ gasConsumed: t.l2_gas_consumed,
171
+ gasPrice: t.l2_gas_price
172
+ },
173
+ l1DataGas: {
174
+ gasConsumed: t.l1_data_gas_consumed,
175
+ gasPrice: t.l1_data_gas_price
176
+ }
152
177
  };
153
178
  }
154
179
  } else {
155
- const { gas_consumed: m, gas_price: t, data_gas_consumed: i, data_gas_price: l } = await a.estimateFee(e, {
180
+ const { l1_data_gas_price: _, l1_data_gas_consumed: a, l1_gas_consumed: t, l2_gas_price: c, l2_gas_consumed: d, l1_gas_price: g } = await s.estimateFee(e, {
156
181
  skipValidate: !0,
157
- version: s
182
+ version: r
158
183
  });
159
- if (!m || !t)
160
- throw new d({
184
+ if (!t || !g || !d || !c)
185
+ throw new m({
161
186
  code: "ONCHAIN_FEE_ESTIMATION_FAILED",
162
187
  message: "Missing gas_consumed or gas_price"
163
188
  });
164
- r.transactions = {
189
+ i.transactions = {
165
190
  feeTokenAddress: n,
166
- amount: m,
167
- pricePerUnit: t,
168
- dataGasConsumed: i,
169
- dataGasPrice: l
191
+ l1Gas: {
192
+ gasConsumed: t,
193
+ gasPrice: g
194
+ },
195
+ l2Gas: {
196
+ gasConsumed: d,
197
+ gasPrice: c
198
+ },
199
+ l1DataGas: {
200
+ gasConsumed: a,
201
+ gasPrice: _
202
+ }
170
203
  };
171
204
  }
172
- return r;
173
- } catch (s) {
174
- throw new d({
205
+ return [i];
206
+ } catch (r) {
207
+ throw new m({
175
208
  code: "ONCHAIN_FEE_ESTIMATION_FAILED",
176
- message: `${s}`
209
+ message: `${r}`
177
210
  });
178
211
  }
179
212
  }
180
213
  }
181
214
  export {
182
- x as TransactionReviewServiceWeb
215
+ B as TransactionReviewServiceWeb
183
216
  };
@@ -1,3 +1,4 @@
1
1
  export * from './implementation';
2
2
  export type * from './interface';
3
3
  export * from './types';
4
+ export * from './utils';
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("starknet"),d=require("../../utils/arrays.cjs"),g=({transaction:e,nonce:t,chainId:l,version:s,isDeploymentTransaction:r,cairoVersion:c,address:o,appDomain:u})=>{let a=t;r&&e.type!=="DEPLOY_ACCOUNT"&&(a=y.num.toHex(1));const n=d.ensureArray(e.calls);return{type:e.type,chainId:l,cairoVersion:c,nonce:a,version:s,account:o,calls:n,calldata:e.calldata,salt:e.salt,signature:e.signature,classHash:e.classHash,appDomain:u}};exports.getPayloadFromTransaction=g;
@@ -0,0 +1,25 @@
1
+ import { CairoVersion } from 'starknet';
2
+ import { TransactionReviewTransactions } from '../estimate';
3
+ export declare const getPayloadFromTransaction: ({ transaction, nonce, chainId, version, isDeploymentTransaction, cairoVersion, address, appDomain, }: {
4
+ transaction: TransactionReviewTransactions;
5
+ nonce: string;
6
+ chainId: string;
7
+ version: string;
8
+ isDeploymentTransaction: boolean;
9
+ cairoVersion: CairoVersion;
10
+ address: string;
11
+ appDomain?: string;
12
+ }) => {
13
+ type: "DECLARE" | "DEPLOY" | "DEPLOY_ACCOUNT" | "INVOKE";
14
+ chainId: string;
15
+ cairoVersion: CairoVersion;
16
+ nonce: string;
17
+ version: string;
18
+ account: string;
19
+ calls: import('starknet').Call[];
20
+ calldata: string[] | undefined;
21
+ salt: `0x${string}` | undefined;
22
+ signature: string[] | undefined;
23
+ classHash: `0x${string}` | undefined;
24
+ appDomain: string | undefined;
25
+ };
@@ -0,0 +1,25 @@
1
+ import { num as u } from "starknet";
2
+ import { ensureArray as y } from "../../utils/arrays.js";
3
+ const g = ({ transaction: e, nonce: a, chainId: s, version: t, isDeploymentTransaction: o, cairoVersion: r, address: c, appDomain: m }) => {
4
+ let l = a;
5
+ o && e.type !== "DEPLOY_ACCOUNT" && (l = u.toHex(1));
6
+ const p = y(e.calls);
7
+ return {
8
+ type: e.type,
9
+ chainId: s,
10
+ cairoVersion: r,
11
+ nonce: l,
12
+ version: t,
13
+ account: c,
14
+ calls: p,
15
+ calldata: e.calldata,
16
+ salt: e.salt,
17
+ signature: e.signature,
18
+ classHash: e.classHash,
19
+ appDomain: m
20
+ // appDomain: "https://starknetkit-blacked-listed.vercel.app", // to simulate blacklisted domain
21
+ };
22
+ };
23
+ export {
24
+ g as getPayloadFromTransaction
25
+ };
@@ -2,7 +2,7 @@ import { Account, ArraySignatureType, Call, Calldata, DeployAccountContractPaylo
2
2
  import { Sequencer } from 'starknet5';
3
3
  import { Address } from '../chains';
4
4
  import { ApiData } from '../http/apiData';
5
- import { FRI, WEI } from './estimate';
5
+ import { FRI } from './estimate';
6
6
  export interface SimulationError extends Error {
7
7
  name: string;
8
8
  responseJson: {
@@ -33,12 +33,6 @@ export interface IUseTransactionSimulation {
33
33
  transactionSimulationEnabled?: boolean;
34
34
  }
35
35
  export type TransactionSimulationFeesEstimation = {
36
- gasPrice: number;
37
- gasUsage: number;
38
- overallFee: number;
39
- unit: WEI;
40
- maxFee: number;
41
- } | {
42
36
  gasPrice: number;
43
37
  gasUsage: number;
44
38
  overallFee: number;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("starknet"),s=require("zod"),o=Object.values(n.constants.TRANSACTION_VERSION),i=s.z.string().default("0x3").refine(t=>{const e=n.num.toBigInt(t);return o.map(r=>n.num.toBigInt(r)).includes(e)}).transform(t=>n.num.toHex(t));function c(t){if(t===n.constants.TRANSACTION_VERSION.V3||t===n.constants.TRANSACTION_VERSION.F3)throw Error("Only txv1 is supported")}exports.denyTxV3=c;exports.txVersionSchema=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("starknet"),o=require("zod"),s=[n.ETransactionVersion3.V3,n.ETransactionVersion3.F3],i=o.z.string().default("0x3").refine(t=>{const e=n.num.toBigInt(t);return s.map(r=>n.num.toBigInt(r)).includes(e)}).transform(t=>n.num.toHex(t));exports.txVersionSchema=i;
@@ -1,8 +1,7 @@
1
- import { ETransactionVersion } from '@starknet-io/types-js';
1
+ import { ETransactionVersion3 } from 'starknet';
2
2
  import { z } from 'zod';
3
- export type TRANSACTION_VERSION = ETransactionVersion;
4
- export type TransactionInvokeVersion = typeof ETransactionVersion.V0 | typeof ETransactionVersion.V1 | typeof ETransactionVersion.V2 | typeof ETransactionVersion.V3;
5
- export type TransactionSimulationVersion = typeof ETransactionVersion.F0 | typeof ETransactionVersion.F1 | typeof ETransactionVersion.F2 | typeof ETransactionVersion.F3;
3
+ export type TRANSACTION_VERSION = ETransactionVersion3;
4
+ export type TransactionInvokeVersion = typeof ETransactionVersion3.V3;
5
+ export type TransactionSimulationVersion = typeof ETransactionVersion3.F3;
6
6
  export type TransactionVersion = TransactionInvokeVersion | TransactionSimulationVersion;
7
- export declare const txVersionSchema: z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>, "0x0" | "0x1" | "0x2" | "0x3" | "0x100000000000000000000000000000000" | "0x100000000000000000000000000000001" | "0x100000000000000000000000000000002" | "0x100000000000000000000000000000003", string | undefined>;
8
- export declare function denyTxV3(version: TransactionVersion): asserts version is Exclude<TransactionVersion, typeof ETransactionVersion.V3 | typeof ETransactionVersion.F3>;
7
+ export declare const txVersionSchema: z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>, "0x3" | "0x100000000000000000000000000000003", string | undefined>;
@@ -1,14 +1,12 @@
1
- import { num as n, constants as r } from "starknet";
2
- import { z as s } from "zod";
3
- const i = Object.values(r.TRANSACTION_VERSION), m = s.string().default("0x3").refine((t) => {
4
- const o = n.toBigInt(t);
5
- return i.map((e) => n.toBigInt(e)).includes(o);
6
- }).transform((t) => n.toHex(t));
7
- function u(t) {
8
- if (t === r.TRANSACTION_VERSION.V3 || t === r.TRANSACTION_VERSION.F3)
9
- throw Error("Only txv1 is supported");
10
- }
1
+ import { num as t, ETransactionVersion3 as r } from "starknet";
2
+ import { z as i } from "zod";
3
+ const s = [
4
+ r.V3,
5
+ r.F3
6
+ ], c = i.string().default("0x3").refine((n) => {
7
+ const o = t.toBigInt(n);
8
+ return s.map((e) => t.toBigInt(e)).includes(o);
9
+ }).transform((n) => t.toHex(n));
11
10
  export {
12
- u as denyTxV3,
13
- m as txVersionSchema
11
+ c as txVersionSchema
14
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.70.3",
3
+ "version": "1.71.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"
@@ -99,7 +99,7 @@
99
99
  "micro-starknet": "^0.2.3",
100
100
  "numeral": "2.0.6",
101
101
  "react-i18next": "^15.4.1",
102
- "starknet": "6.21.1",
102
+ "starknet": "7.5.1",
103
103
  "starknet4-deprecated": "npm:starknet@4.4.0",
104
104
  "starknet5": "npm:starknet@5.25.0",
105
105
  "zod-to-json-schema": "^3.24.5"
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("lodash-es"),o=require("starknet"),N=require("../getTransactionVersion.cjs"),F=require("./error.cjs"),r=require("./utils.cjs"),E=require("../../chains/starknet/address.cjs"),u=require("../../chains/starknet/constants.cjs"),h=e=>{const{transactions:t}=e;if(!t)throw new F.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});if(!Array.isArray(t))throw Error(`Unexpected simulation response. Expected array. Got ${typeof t}`);if(l.isEmpty(t))return[];if(t.length>2)throw Error(`Unexpected simulation response length. Got ${t.length}`);const n=t.map(m=>{if(!m.simulation)throw new F.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});return{...m.simulation,...I(m.simulation.feeEstimations)}}),[a,s]=n.length===1?[n[0],void 0]:[n[1],n[0]],i=y(a,s),f=p(a,s);return[...i,...f]},I=e=>{const[t,n]=l.partition(e,a=>"unit"in a&&(a.unit==="FRI"||a.unit==="WEI"));return{nativeFeeEstimations:t,paymasterFeeEstimations:n}},p=(e,t)=>{if(!e)return[];if(!t)return e.paymasterFeeEstimations.map(s=>({type:"paymaster",transactions:c(s),deployment:void 0}));const n=t.paymasterFeeEstimations,a=e.paymasterFeeEstimations;if(n.length!==a.length)throw Error("Deployment and transaction fee estimations length mismatch");return a.map((s,i)=>({type:"paymaster",transactions:c(s),deployment:c(n[i])}))},y=(e,t)=>{if(!e)return[];if(!t)return e.nativeFeeEstimations.map(s=>({type:"native",transactions:d(s),deployment:void 0}));const n=t.nativeFeeEstimations,a=e.nativeFeeEstimations;if(n.length!==a.length)throw Error("Deployment and transaction fee estimations length mismatch");return a.map((s,i)=>({type:"native",transactions:d(s),deployment:d(n[i])}))},c=e=>({feeTokenAddress:e.token.address,maxFee:BigInt(e.maxFee),overallFee:BigInt(e.overallFee)}),d=e=>({amount:o.num.toBigInt(e.gasUsage),feeTokenAddress:r.unitToFeeTokenAddress(e.unit),pricePerUnit:o.num.toBigInt(e.gasPrice),dataGasConsumed:o.num.toBigInt(e.dataGasConsumed??0),dataGasPrice:o.num.toBigInt(e.dataGasPrice??0),max:r.toMax(r.castFeeEstimation(e,o.num.toBigInt))}),S=e=>{var a;if(e.type==="paymaster")return e.transactions.maxFee+(((a=e.deployment)==null?void 0:a.maxFee)??0n);if(e.deployment&&!E.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const t=e.deployment?r.estimatedFeeToMaxFeeTotal(e.deployment):0n,n=r.estimatedFeeToMaxFeeTotal(e.transactions);return t+n},V=e=>{var t;return e.type==="paymaster"?e.transactions.overallFee+(((t=e.deployment)==null?void 0:t.overallFee)??0n):r.estimatedFeesToTotal(e)},g=(e=[])=>e.filter(n=>n.type==="native"),x=e=>e.filter(t=>t.type==="paymaster"),T=e=>e===o.constants.TRANSACTION_VERSION.V1||e===o.constants.TRANSACTION_VERSION.F1?u.ETH_TOKEN_ADDRESS:u.STRK_TOKEN_ADDRESS,v=(e=[],t)=>{const n=g(e).find(a=>E.isEqualAddress(a.transactions.feeTokenAddress,t));if(!n)throw Error(`No native estimated fee found for ${t}`);return n},A=(e=[],t)=>{const n=T(t);return v(e,n)},_=(e=[],t)=>A(e,N.getAccountTxVersion(t));exports.estimatedFeesToMaxFeeTotalV2=S;exports.estimatedFeesToTotalV2=V;exports.filterPaymasterEstimatedFees=x;exports.getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2=h;exports.getNativeEstimatedFeeByFeeToken=v;exports.getNativeEstimatedFeeByTxVersion=A;exports.getNativeEstimatedFeeForAccount=_;exports.getNativeEstimatedFees=g;exports.getNativeFeeFromSimulation=y;exports.getNativeFeeTokenAddress=T;exports.getPaymasterFeeFromSimulation=p;
@@ -1,26 +0,0 @@
1
- import { Address } from '../../chains';
2
- import { PaymasterFeeEstimation, FeeEstimation, SimulateAndReview } from '../../features/simulation';
3
- import { EstimatedFeesV2, NativeEstimatedFees, PaymasterEstimatedFees } from '../../features/simulation/fees/schema';
4
- import { StrictOmit } from '../../utils/type.utils';
5
- import { TransactionVersion } from '../transactionVersion';
6
- export declare const getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2: (simulateAndReviewResult: Pick<SimulateAndReview, "transactions">) => EstimatedFeesV2[];
7
- export declare const getPaymasterFeeFromSimulation: (invokeTransaction: {
8
- paymasterFeeEstimations: PaymasterFeeEstimation[];
9
- }, deployTransactionOrUndefined?: {
10
- paymasterFeeEstimations: PaymasterFeeEstimation[];
11
- } | undefined) => EstimatedFeesV2[];
12
- export declare const getNativeFeeFromSimulation: (invokeTransaction: {
13
- nativeFeeEstimations: FeeEstimation[];
14
- }, deployTransactionOrUndefined?: {
15
- nativeFeeEstimations: FeeEstimation[];
16
- } | undefined) => EstimatedFeesV2[];
17
- export declare const estimatedFeesToMaxFeeTotalV2: (estimatedFees: EstimatedFeesV2) => bigint;
18
- export declare const estimatedFeesToTotalV2: (estimatedFees: EstimatedFeesV2) => bigint;
19
- export declare const getNativeEstimatedFees: (estimatedFees?: EstimatedFeesV2[]) => NativeEstimatedFees[];
20
- export declare const filterPaymasterEstimatedFees: (estimatedFees: EstimatedFeesV2[]) => StrictOmit<PaymasterEstimatedFees, "type">[];
21
- export declare const getNativeFeeTokenAddress: (transactionVersion: TransactionVersion) => Address;
22
- export declare const getNativeEstimatedFeeByFeeToken: (estimatedFees: EstimatedFeesV2[] | undefined, feeTokenAddress: string) => NativeEstimatedFees;
23
- export declare const getNativeEstimatedFeeByTxVersion: (estimatedFees: EstimatedFeesV2[] | undefined, transactionVersion: TransactionVersion) => NativeEstimatedFees;
24
- export declare const getNativeEstimatedFeeForAccount: (estimatedFees: EstimatedFeesV2[] | undefined, account: {
25
- classHash: string;
26
- }) => NativeEstimatedFees;
@@ -1,107 +0,0 @@
1
- import { isEmpty as u, partition as y } from "lodash-es";
2
- import { num as s, constants as p } from "starknet";
3
- import { getAccountTxVersion as f } from "../getTransactionVersion.js";
4
- import { EstimateError as d } from "./error.js";
5
- import { toMax as g, castFeeEstimation as T, unitToFeeTokenAddress as A, estimatedFeeToMaxFeeTotal as E, estimatedFeesToTotal as v } from "./utils.js";
6
- import { isEqualAddress as l } from "../../chains/starknet/address.js";
7
- import { ETH_TOKEN_ADDRESS as h, STRK_TOKEN_ADDRESS as I } from "../../chains/starknet/constants.js";
8
- const O = (t) => {
9
- const { transactions: e } = t;
10
- if (!e)
11
- throw new d({ code: "SIMULATE_AND_REVIEW_FAILED" });
12
- if (!Array.isArray(e))
13
- throw Error(`Unexpected simulation response. Expected array. Got ${typeof e}`);
14
- if (u(e))
15
- return [];
16
- if (e.length > 2)
17
- throw Error(`Unexpected simulation response length. Got ${e.length}`);
18
- const n = e.map((i) => {
19
- if (!i.simulation)
20
- throw new d({ code: "SIMULATE_AND_REVIEW_FAILED" });
21
- return {
22
- ...i.simulation,
23
- ...N(i.simulation.feeEstimations)
24
- };
25
- }), [o, a] = n.length === 1 ? [n[0], void 0] : [n[1], n[0]], r = _(o, a), F = S(o, a);
26
- return [...r, ...F];
27
- }, N = (t) => {
28
- const [e, n] = y(t, (o) => "unit" in o && (o.unit === "FRI" || o.unit === "WEI"));
29
- return { nativeFeeEstimations: e, paymasterFeeEstimations: n };
30
- }, S = (t, e) => {
31
- if (!t)
32
- return [];
33
- if (!e)
34
- return t.paymasterFeeEstimations.map((a) => ({
35
- type: "paymaster",
36
- transactions: m(a),
37
- deployment: void 0
38
- }));
39
- const n = e.paymasterFeeEstimations, o = t.paymasterFeeEstimations;
40
- if (n.length !== o.length)
41
- throw Error("Deployment and transaction fee estimations length mismatch");
42
- return o.map((a, r) => ({
43
- type: "paymaster",
44
- transactions: m(a),
45
- deployment: m(n[r])
46
- }));
47
- }, _ = (t, e) => {
48
- if (!t)
49
- return [];
50
- if (!e)
51
- return t.nativeFeeEstimations.map((a) => ({
52
- type: "native",
53
- transactions: c(a),
54
- deployment: void 0
55
- }));
56
- const n = e.nativeFeeEstimations, o = t.nativeFeeEstimations;
57
- if (n.length !== o.length)
58
- throw Error("Deployment and transaction fee estimations length mismatch");
59
- return o.map((a, r) => ({
60
- type: "native",
61
- transactions: c(a),
62
- deployment: c(n[r])
63
- }));
64
- }, m = (t) => ({
65
- feeTokenAddress: t.token.address,
66
- maxFee: BigInt(t.maxFee),
67
- overallFee: BigInt(t.overallFee)
68
- }), c = (t) => ({
69
- amount: s.toBigInt(t.gasUsage),
70
- feeTokenAddress: A(t.unit),
71
- pricePerUnit: s.toBigInt(t.gasPrice),
72
- dataGasConsumed: s.toBigInt(t.dataGasConsumed ?? 0),
73
- dataGasPrice: s.toBigInt(t.dataGasPrice ?? 0),
74
- max: g(T(t, s.toBigInt))
75
- }), U = (t) => {
76
- var o;
77
- if (t.type === "paymaster")
78
- return t.transactions.maxFee + (((o = t.deployment) == null ? void 0 : o.maxFee) ?? 0n);
79
- if (t.deployment && !l(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
80
- throw Error("Cannot calculate estimated fees for different tokens");
81
- const e = t.deployment ? E(t.deployment) : 0n, n = E(t.transactions);
82
- return e + n;
83
- }, L = (t) => {
84
- var e;
85
- return t.type === "paymaster" ? t.transactions.overallFee + (((e = t.deployment) == null ? void 0 : e.overallFee) ?? 0n) : v(t);
86
- }, x = (t = []) => t.filter((n) => n.type === "native"), W = (t) => t.filter((e) => e.type === "paymaster"), R = (t) => t === p.TRANSACTION_VERSION.V1 || t === p.TRANSACTION_VERSION.F1 ? h : I, V = (t = [], e) => {
87
- const n = x(t).find((o) => l(o.transactions.feeTokenAddress, e));
88
- if (!n)
89
- throw Error(`No native estimated fee found for ${e}`);
90
- return n;
91
- }, w = (t = [], e) => {
92
- const n = R(e);
93
- return V(t, n);
94
- }, K = (t = [], e) => w(t, f(e));
95
- export {
96
- U as estimatedFeesToMaxFeeTotalV2,
97
- L as estimatedFeesToTotalV2,
98
- W as filterPaymasterEstimatedFees,
99
- O as getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2,
100
- V as getNativeEstimatedFeeByFeeToken,
101
- w as getNativeEstimatedFeeByTxVersion,
102
- K as getNativeEstimatedFeeForAccount,
103
- x as getNativeEstimatedFees,
104
- _ as getNativeFeeFromSimulation,
105
- R as getNativeFeeTokenAddress,
106
- S as getPaymasterFeeFromSimulation
107
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("starknet"),r=require("../chains/starknet/address.cjs"),o=require("../chains/starknet/constants.cjs"),s=require("./txv3.cjs");function T(e){return r.isEqualAddress(e,o.ETH_TOKEN_ADDRESS)?t.constants.TRANSACTION_VERSION.V1:t.constants.TRANSACTION_VERSION.V3}function c(e){return r.isEqualAddress(e,o.ETH_TOKEN_ADDRESS)?t.constants.TRANSACTION_VERSION.F1:t.constants.TRANSACTION_VERSION.F3}function N(e,n){return t.isSierra(n.contract)?r.isEqualAddress(e,o.ETH_TOKEN_ADDRESS)?t.constants.TRANSACTION_VERSION.V2:t.constants.TRANSACTION_VERSION.V3:t.constants.TRANSACTION_VERSION.V1}const S=({classHash:e})=>e&&!s.classHashSupportsTxV3(e)?t.constants.TRANSACTION_VERSION.V1:t.constants.TRANSACTION_VERSION.V3,a=({classHash:e},n)=>t.isSierra(n.contract)?e&&!s.classHashSupportsTxV3(e)?t.constants.TRANSACTION_VERSION.V2:t.constants.TRANSACTION_VERSION.V3:t.constants.TRANSACTION_VERSION.V1;exports.getAccountTxVersion=S;exports.getSimulationTxVersionFromFeeToken=c;exports.getTxVersionForDeclareContract=a;exports.getTxVersionFromFeeToken=T;exports.getTxVersionFromFeeTokenForDeclareContract=N;
@@ -1,12 +0,0 @@
1
- import { DeclareContractPayload } from 'starknet';
2
- import { Address } from '../chains/starknet';
3
- import { TransactionInvokeVersion, TransactionSimulationVersion } from './transactionVersion';
4
- export declare function getTxVersionFromFeeToken(feeTokenAddress: Address): TransactionInvokeVersion;
5
- export declare function getSimulationTxVersionFromFeeToken(feeTokenAddress: Address): TransactionSimulationVersion;
6
- export declare function getTxVersionFromFeeTokenForDeclareContract(feeTokenAddress: Address, payload: DeclareContractPayload): TransactionInvokeVersion;
7
- type AccountClassHash = {
8
- classHash?: string;
9
- };
10
- export declare const getAccountTxVersion: ({ classHash }: AccountClassHash) => "0x1" | "0x3";
11
- export declare const getTxVersionForDeclareContract: ({ classHash }: AccountClassHash, payload: DeclareContractPayload) => TransactionInvokeVersion;
12
- export {};