@argent/x-shared 1.43.0 → 1.43.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 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("lodash-es"),f=require("../normalize.cjs"),m=require("../schema.cjs");function y(t){var n,a;const r=(a=(n=t.transactions)==null?void 0:n[0].reviewOfTransaction)==null?void 0:a.reviews;return r?r.map(c=>c.action):void 0}function p({simulateAndReview:t,...r}){var n,a;const i={type:m.NativeActivityTypeNative,...r};if(t&&!v.isEmpty(t.transactions)){const c=t.transactions[t.transactions.length-1],o=(n=c.simulation)==null?void 0:n.summary;if(o){const u=f.normalizeActivitySummaryCollection(o);i.transferSummary=u}const s=(a=c.reviewOfTransaction)==null?void 0:a.targetedDapp;s&&(i.dapp=s);const e=y(t);e&&(i.actions=e)}return m.nativeActivitySchema.parse(i)}exports.createNativeActivity=p;exports.normalizeActions=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("lodash-es"),p=require("../normalize.cjs"),y=require("../schema.cjs");function u(t){var n,e;const c=(e=(n=t.transactions)==null?void 0:n[0].reviewOfTransaction)==null?void 0:e.reviews;return c?c.map(a=>a.action):void 0}function S({simulateAndReview:t,...c}){var n,e,a;const r={type:y.NativeActivityTypeNative,...c};if(t&&!f.isEmpty(t.transactions)){const i=(n=t.transactions)==null?void 0:n[t.transactions.length-1],o=(e=i==null?void 0:i.simulation)==null?void 0:e.summary;if(o){const v=p.normalizeActivitySummaryCollection(o);r.transferSummary=v}const s=(a=i==null?void 0:i.reviewOfTransaction)==null?void 0:a.targetedDapp;s&&(r.dapp=s);const m=u(t);m&&(r.actions=m)}return y.nativeActivitySchema.parse(r)}exports.createNativeActivity=S;exports.normalizeActions=u;
@@ -1,31 +1,31 @@
1
- import { isEmpty as p } from "lodash-es";
2
- import { normalizeActivitySummaryCollection as f } from "../normalize.js";
3
- import { NativeActivityTypeNative as y, nativeActivitySchema as v } from "../schema.js";
4
- function u(t) {
5
- var i, r;
6
- const a = (r = (i = t.transactions) == null ? void 0 : i[0].reviewOfTransaction) == null ? void 0 : r.reviews;
7
- return a ? a.map((o) => o.action) : void 0;
1
+ import { isEmpty as f } from "lodash-es";
2
+ import { normalizeActivitySummaryCollection as y } from "../normalize.js";
3
+ import { NativeActivityTypeNative as v, nativeActivitySchema as u } from "../schema.js";
4
+ function S(t) {
5
+ var n, o;
6
+ const a = (o = (n = t.transactions) == null ? void 0 : n[0].reviewOfTransaction) == null ? void 0 : o.reviews;
7
+ return a ? a.map((c) => c.action) : void 0;
8
8
  }
9
- function N({ simulateAndReview: t, ...a }) {
10
- var i, r;
11
- const n = {
12
- type: y,
9
+ function z({ simulateAndReview: t, ...a }) {
10
+ var n, o, c;
11
+ const r = {
12
+ type: v,
13
13
  ...a
14
14
  };
15
- if (t && !p(t.transactions)) {
16
- const o = t.transactions[t.transactions.length - 1], c = (i = o.simulation) == null ? void 0 : i.summary;
17
- if (c) {
18
- const m = f(c);
19
- n.transferSummary = m;
15
+ if (t && !f(t.transactions)) {
16
+ const i = (n = t.transactions) == null ? void 0 : n[t.transactions.length - 1], s = (o = i == null ? void 0 : i.simulation) == null ? void 0 : o.summary;
17
+ if (s) {
18
+ const p = y(s);
19
+ r.transferSummary = p;
20
20
  }
21
- const s = (r = o.reviewOfTransaction) == null ? void 0 : r.targetedDapp;
22
- s && (n.dapp = s);
23
- const e = u(t);
24
- e && (n.actions = e);
21
+ const e = (c = i == null ? void 0 : i.reviewOfTransaction) == null ? void 0 : c.targetedDapp;
22
+ e && (r.dapp = e);
23
+ const m = S(t);
24
+ m && (r.actions = m);
25
25
  }
26
- return v.parse(n);
26
+ return u.parse(r);
27
27
  }
28
28
  export {
29
- N as createNativeActivity,
30
- u as normalizeActions
29
+ z as createNativeActivity,
30
+ S as normalizeActions
31
31
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./getMessageFromSimulationError.cjs"),c=require("./schema.cjs"),g=require("../../../transactions/getPrettyRcpError.cjs");function u(o){if(!o)return;const e=o.transactions.flatMap(a=>c.isTransactionSimulationError(a)?a.simulationError:!1),r=e==null?void 0:e[e.length-1];if(!r)return;const n=l.getMessageFromSimulationError(r),s=r.message||r.error,t=g.getPrettyRpcError(s),i=t||r.label;return{message:t?s:n,label:i}}exports.getErrorMessageAndLabelFromSimulation=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./getMessageFromSimulationError.cjs"),g=require("./schema.cjs"),u=require("../../../transactions/getPrettyRcpError.cjs");function m(o){var a;if(!o)return;const e=(a=o.transactions)==null?void 0:a.flatMap(n=>g.isTransactionSimulationError(n)?n.simulationError:!1),r=e==null?void 0:e[e.length-1];if(!r)return;const i=c.getMessageFromSimulationError(r),s=r.message||r.error,t=u.getPrettyRpcError(s),l=t||r.label;return{message:t?s:i,label:l}}exports.getErrorMessageAndLabelFromSimulation=m;
@@ -1,18 +1,19 @@
1
- import { getMessageFromSimulationError as m } from "./getMessageFromSimulationError.js";
2
- import { isTransactionSimulationError as l } from "./schema.js";
3
- import { getPrettyRpcError as c } from "../../../transactions/getPrettyRcpError.js";
4
- function E(e) {
1
+ import { getMessageFromSimulationError as l } from "./getMessageFromSimulationError.js";
2
+ import { isTransactionSimulationError as c } from "./schema.js";
3
+ import { getPrettyRpcError as g } from "../../../transactions/getPrettyRcpError.js";
4
+ function M(e) {
5
+ var a;
5
6
  if (!e)
6
7
  return;
7
- const o = e.transactions.flatMap((a) => l(a) ? a.simulationError : !1), r = o == null ? void 0 : o[o.length - 1];
8
+ const o = (a = e.transactions) == null ? void 0 : a.flatMap((n) => c(n) ? n.simulationError : !1), r = o == null ? void 0 : o[o.length - 1];
8
9
  if (!r)
9
10
  return;
10
- const n = m(r), s = r.message || r.error, t = c(s), i = t || r.label;
11
+ const i = l(r), s = r.message || r.error, t = g(s), m = t || r.label;
11
12
  return {
12
- message: t ? s : n,
13
- label: i
13
+ message: t ? s : i,
14
+ label: m
14
15
  };
15
16
  }
16
17
  export {
17
- E as getErrorMessageAndLabelFromSimulation
18
+ M as getErrorMessageAndLabelFromSimulation
18
19
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("zod"),f=require("../fees/schema.cjs"),l=require("../warning/schema.cjs"),n=require("../../../chains/starknet/address.cjs"),k=e.z.object({name:e.z.string(),url:e.z.string(),position:e.z.number()}),o=e.z.object({address:e.z.string(),name:e.z.string(),symbol:e.z.string().optional(),decimals:e.z.number().optional(),unknown:e.z.boolean(),iconUrl:e.z.string().optional(),type:e.z.string()}),i=e.z.discriminatedUnion("type",[e.z.object({type:e.z.literal("amount"),label:e.z.string(),token:o,amount:e.z.string(),usd:e.z.string(),editable:e.z.boolean()}),e.z.object({type:e.z.literal("address"),label:e.z.string(),address:e.z.string(),addressName:e.z.string().optional(),verified:e.z.boolean().optional()}),e.z.object({type:e.z.literal("timestamp"),label:e.z.string(),value:e.z.string()}),e.z.object({type:e.z.literal("token_address"),label:e.z.string(),token:o}),e.z.object({type:e.z.literal("calldata"),label:e.z.string(),entrypoint:e.z.string(),calldata:e.z.array(e.z.string())}),e.z.object({type:e.z.literal("text"),label:e.z.string(),text:e.z.string()}),e.z.object({type:e.z.literal("nft"),label:e.z.string(),token:o})]),z=e.z.object({name:e.z.string(),properties:e.z.array(i),defaultProperties:e.z.array(i).optional()}),m=e.z.union([e.z.literal("verified"),e.z.literal("neutral"),e.z.literal("partial"),e.z.literal("warn")]),p=e.z.object({unknown_token:e.z.unknown().optional(),date_of_addition:e.z.string().optional(),contract_address:n.addressSchema.optional(),reason:e.z.string().optional(),value:e.z.string().or(e.z.number()).optional()}),r=e.z.object({reason:l.reasonsSchema,details:p.optional(),severity:l.severitySchema}),d=e.z.object({assessment:m,warnings:e.z.array(r).optional(),assessmentReasons:e.z.array(e.z.string()).optional(),assessmentDetails:e.z.object({contract_address:e.z.string()}).optional(),action:z}),g=e.z.object({name:e.z.string(),description:e.z.string(),logoUrl:e.z.string(),iconUrl:e.z.string(),argentVerified:e.z.boolean(),links:e.z.array(k)}),u=e.z.object({assessment:e.z.union([e.z.literal("verified"),e.z.literal("neutral"),e.z.literal("partial"),e.z.literal("warn")]),warnings:e.z.array(r).optional(),assessmentDetails:e.z.object({contract_address:e.z.string()}).optional(),targetedDapp:g.optional(),reviews:e.z.array(d)}).optional(),b=e.z.object({banner:e.z.string().nullable().optional(),preview:e.z.string().nullable().optional(),full:e.z.string().nullable().optional(),original:e.z.string().nullable().optional()}),v=e.z.object({twitter:e.z.string().optional(),external:e.z.string().optional(),discord:e.z.string().optional()}),s=e.z.object({address:n.addressSchemaArgentBackend,decimals:e.z.number().optional(),symbol:e.z.string().optional(),name:e.z.string(),description:e.z.string().optional(),type:e.z.string().optional(),usdValue:e.z.string().optional(),iconUrl:e.z.string().optional(),unknown:e.z.boolean().optional(),imageUrls:b.optional(),links:v.optional()}),w=e.z.object({tokenAddress:n.addressSchemaArgentBackend,owner:n.addressSchemaArgentBackend,spender:n.addressSchemaArgentBackend,value:e.z.string().optional(),approvalForAll:e.z.boolean(),details:s.optional()}),A=e.z.object({tokenAddress:n.addressSchemaArgentBackend,from:n.addressSchemaArgentBackend,to:n.addressSchemaArgentBackend,tokenId:e.z.string().optional(),value:e.z.string().optional(),details:s.optional()}),a=e.z.union([e.z.string(),e.z.number(),e.z.bigint()]).transform(t=>parseInt(t.toString(),10)),c={overallFee:a,gasPrice:a,gasUsage:a,dataGasPrice:a.optional(),dataGasConsumed:a.optional()},S=e.z.object({...c,unit:e.z.string().transform(t=>t.toUpperCase()).pipe(e.z.literal("WEI")),maxFee:a}).or(e.z.object({...c,unit:e.z.string().transform(t=>t.toUpperCase()).pipe(e.z.literal("FRI")),maxAmount:a,maxPricePerUnit:a})),E=e.z.object({type:e.z.string(),label:e.z.string(),tokenId:e.z.string().optional(),value:e.z.string().optional(),usdValue:e.z.string().optional(),token:s,sent:e.z.boolean().optional(),tokenIdDetails:e.z.object({name:e.z.string().optional(),description:e.z.string().optional(),imageUrls:b.optional()}).optional()}),U=e.z.object({approvals:e.z.array(w).optional(),transfers:e.z.array(A).optional(),calculatedNonce:e.z.string().optional(),feeEstimation:S,summary:e.z.array(E).optional()}),D=e.z.object({label:e.z.string().optional(),code:e.z.number().optional(),message:e.z.string().optional(),error:e.z.string().optional()}),h=e.z.object({reviewOfTransaction:u,simulation:U,simulationError:e.z.undefined()}),y=e.z.object({reviewOfTransaction:u,simulation:e.z.undefined(),simulationError:D}),j=h.or(y),B=e.z.object({transactions:e.z.array(j)}),P=e.z.object({transactions:e.z.array(j),enrichedFeeEstimation:f.estimatedFeesSchema.optional(),isBackendDown:e.z.boolean().default(!1).optional()});function T(t){return h.safeParse(t).success}function F(t){return y.safeParse(t).success}exports.actionSchema=z;exports.assessmentSchema=m;exports.enrichedSimulateAndReviewSchema=P;exports.feeEstimationSchema=S;exports.isNotTransactionSimulationError=T;exports.isTransactionSimulationError=F;exports.propertySchema=i;exports.reviewSchema=d;exports.simulateAndReviewSchema=B;exports.targetedDappSchema=g;exports.warningDetailsSchema=p;exports.warningSchema=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("zod"),f=require("../fees/schema.cjs"),l=require("../warning/schema.cjs"),n=require("../../../chains/starknet/address.cjs"),k=t.z.object({name:t.z.string(),url:t.z.string(),position:t.z.number()}),o=t.z.object({address:t.z.string(),name:t.z.string(),symbol:t.z.string().optional(),decimals:t.z.number().optional(),unknown:t.z.boolean(),iconUrl:t.z.string().optional(),type:t.z.string()}),i=t.z.discriminatedUnion("type",[t.z.object({type:t.z.literal("amount"),label:t.z.string(),token:o,amount:t.z.string(),usd:t.z.string(),editable:t.z.boolean()}),t.z.object({type:t.z.literal("address"),label:t.z.string(),address:t.z.string(),addressName:t.z.string().optional(),verified:t.z.boolean().optional()}),t.z.object({type:t.z.literal("timestamp"),label:t.z.string(),value:t.z.string()}),t.z.object({type:t.z.literal("token_address"),label:t.z.string(),token:o}),t.z.object({type:t.z.literal("calldata"),label:t.z.string(),entrypoint:t.z.string(),calldata:t.z.array(t.z.string())}),t.z.object({type:t.z.literal("text"),label:t.z.string(),text:t.z.string()}),t.z.object({type:t.z.literal("nft"),label:t.z.string(),token:o})]),z=t.z.object({name:t.z.string(),properties:t.z.array(i),defaultProperties:t.z.array(i).optional()}),m=t.z.union([t.z.literal("verified"),t.z.literal("neutral"),t.z.literal("partial"),t.z.literal("warn")]),p=t.z.object({unknown_token:t.z.unknown().optional(),date_of_addition:t.z.string().optional(),contract_address:n.addressSchema.optional(),reason:t.z.string().optional(),value:t.z.string().or(t.z.number()).optional()}),r=t.z.object({reason:l.reasonsSchema,details:p.optional(),severity:l.severitySchema}),d=t.z.object({assessment:m,warnings:t.z.array(r).optional(),assessmentReasons:t.z.array(t.z.string()).optional(),assessmentDetails:t.z.object({contract_address:t.z.string()}).optional(),action:z}),g=t.z.object({name:t.z.string(),description:t.z.string(),logoUrl:t.z.string(),iconUrl:t.z.string(),argentVerified:t.z.boolean(),links:t.z.array(k)}),u=t.z.object({assessment:t.z.union([t.z.literal("verified"),t.z.literal("neutral"),t.z.literal("partial"),t.z.literal("warn")]),warnings:t.z.array(r).optional(),assessmentDetails:t.z.object({contract_address:t.z.string()}).optional(),targetedDapp:g.optional(),reviews:t.z.array(d)}).optional(),b=t.z.object({banner:t.z.string().nullable().optional(),preview:t.z.string().nullable().optional(),full:t.z.string().nullable().optional(),original:t.z.string().nullable().optional()}),v=t.z.object({twitter:t.z.string().optional(),external:t.z.string().optional(),discord:t.z.string().optional()}),s=t.z.object({address:n.addressSchemaArgentBackend,decimals:t.z.number().optional(),symbol:t.z.string().optional(),name:t.z.string(),description:t.z.string().optional(),type:t.z.string().optional(),usdValue:t.z.string().optional(),iconUrl:t.z.string().optional(),unknown:t.z.boolean().optional(),imageUrls:b.optional(),links:v.optional()}),w=t.z.object({tokenAddress:n.addressSchemaArgentBackend,owner:n.addressSchemaArgentBackend,spender:n.addressSchemaArgentBackend,value:t.z.string().optional(),approvalForAll:t.z.boolean(),details:s.optional()}),A=t.z.object({tokenAddress:n.addressSchemaArgentBackend,from:n.addressSchemaArgentBackend,to:n.addressSchemaArgentBackend,tokenId:t.z.string().optional(),value:t.z.string().optional(),details:s.optional()}),a=t.z.union([t.z.string(),t.z.number(),t.z.bigint()]).transform(e=>parseInt(e.toString(),10)),c={overallFee:a,gasPrice:a,gasUsage:a,dataGasPrice:a.optional(),dataGasConsumed:a.optional()},S=t.z.object({...c,unit:t.z.string().transform(e=>e.toUpperCase()).pipe(t.z.literal("WEI")),maxFee:a}).or(t.z.object({...c,unit:t.z.string().transform(e=>e.toUpperCase()).pipe(t.z.literal("FRI")),maxAmount:a,maxPricePerUnit:a})),E=t.z.object({type:t.z.string(),label:t.z.string(),tokenId:t.z.string().optional(),value:t.z.string().optional(),usdValue:t.z.string().optional(),token:s,sent:t.z.boolean().optional(),tokenIdDetails:t.z.object({name:t.z.string().optional(),description:t.z.string().optional(),imageUrls:b.optional()}).optional()}),U=t.z.object({approvals:t.z.array(w).optional(),transfers:t.z.array(A).optional(),calculatedNonce:t.z.string().optional(),feeEstimation:S,summary:t.z.array(E).optional()}),D=t.z.object({label:t.z.string().optional(),code:t.z.number().optional(),message:t.z.string().optional(),error:t.z.string().optional()}),h=t.z.object({reviewOfTransaction:u,simulation:U,simulationError:t.z.undefined()}),y=t.z.object({reviewOfTransaction:u,simulation:t.z.undefined(),simulationError:D}),j=h.or(y),B=t.z.object({transactions:t.z.array(j).optional()}),P=t.z.object({transactions:t.z.array(j).optional(),enrichedFeeEstimation:f.estimatedFeesSchema.optional(),isBackendDown:t.z.boolean().default(!1).optional()});function T(e){return h.safeParse(e).success}function F(e){return y.safeParse(e).success}exports.actionSchema=z;exports.assessmentSchema=m;exports.enrichedSimulateAndReviewSchema=P;exports.feeEstimationSchema=S;exports.isNotTransactionSimulationError=T;exports.isTransactionSimulationError=F;exports.propertySchema=i;exports.reviewSchema=d;exports.simulateAndReviewSchema=B;exports.targetedDappSchema=g;exports.warningDetailsSchema=p;exports.warningSchema=r;
@@ -13814,7 +13814,7 @@ declare const transactionSchema: z.ZodUnion<[z.ZodObject<{
13814
13814
  simulation?: undefined;
13815
13815
  }>]>;
13816
13816
  export declare const simulateAndReviewSchema: z.ZodObject<{
13817
- transactions: z.ZodArray<z.ZodUnion<[z.ZodObject<{
13817
+ transactions: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
13818
13818
  reviewOfTransaction: z.ZodOptional<z.ZodObject<{
13819
13819
  assessment: z.ZodUnion<[z.ZodLiteral<"verified">, z.ZodLiteral<"neutral">, z.ZodLiteral<"partial">, z.ZodLiteral<"warn">]>;
13820
13820
  warnings: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -18447,9 +18447,9 @@ export declare const simulateAndReviewSchema: z.ZodObject<{
18447
18447
  } | undefined;
18448
18448
  } | undefined;
18449
18449
  simulation?: undefined;
18450
- }>]>, "many">;
18450
+ }>]>, "many">>;
18451
18451
  }, "strip", z.ZodTypeAny, {
18452
- transactions: ({
18452
+ transactions?: ({
18453
18453
  simulation: {
18454
18454
  feeEstimation: {
18455
18455
  maxFee: number;
@@ -18914,9 +18914,9 @@ export declare const simulateAndReviewSchema: z.ZodObject<{
18914
18914
  } | undefined;
18915
18915
  } | undefined;
18916
18916
  simulation?: undefined;
18917
- })[];
18917
+ })[] | undefined;
18918
18918
  }, {
18919
- transactions: ({
18919
+ transactions?: ({
18920
18920
  simulation: {
18921
18921
  feeEstimation: {
18922
18922
  maxFee: string | number | bigint;
@@ -19381,10 +19381,10 @@ export declare const simulateAndReviewSchema: z.ZodObject<{
19381
19381
  } | undefined;
19382
19382
  } | undefined;
19383
19383
  simulation?: undefined;
19384
- })[];
19384
+ })[] | undefined;
19385
19385
  }>;
19386
19386
  export declare const enrichedSimulateAndReviewSchema: z.ZodObject<{
19387
- transactions: z.ZodArray<z.ZodUnion<[z.ZodObject<{
19387
+ transactions: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
19388
19388
  reviewOfTransaction: z.ZodOptional<z.ZodObject<{
19389
19389
  assessment: z.ZodUnion<[z.ZodLiteral<"verified">, z.ZodLiteral<"neutral">, z.ZodLiteral<"partial">, z.ZodLiteral<"warn">]>;
19390
19390
  warnings: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -24017,7 +24017,7 @@ export declare const enrichedSimulateAndReviewSchema: z.ZodObject<{
24017
24017
  } | undefined;
24018
24018
  } | undefined;
24019
24019
  simulation?: undefined;
24020
- }>]>, "many">;
24020
+ }>]>, "many">>;
24021
24021
  enrichedFeeEstimation: z.ZodOptional<z.ZodObject<{
24022
24022
  deployment: z.ZodOptional<z.ZodObject<{
24023
24023
  feeTokenAddress: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
@@ -24170,7 +24170,7 @@ export declare const enrichedSimulateAndReviewSchema: z.ZodObject<{
24170
24170
  }>>;
24171
24171
  isBackendDown: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
24172
24172
  }, "strip", z.ZodTypeAny, {
24173
- transactions: ({
24173
+ transactions?: ({
24174
24174
  simulation: {
24175
24175
  feeEstimation: {
24176
24176
  maxFee: number;
@@ -24635,7 +24635,7 @@ export declare const enrichedSimulateAndReviewSchema: z.ZodObject<{
24635
24635
  } | undefined;
24636
24636
  } | undefined;
24637
24637
  simulation?: undefined;
24638
- })[];
24638
+ })[] | undefined;
24639
24639
  enrichedFeeEstimation?: {
24640
24640
  transactions: {
24641
24641
  amount: bigint;
@@ -24666,7 +24666,7 @@ export declare const enrichedSimulateAndReviewSchema: z.ZodObject<{
24666
24666
  } | undefined;
24667
24667
  isBackendDown?: boolean | undefined;
24668
24668
  }, {
24669
- transactions: ({
24669
+ transactions?: ({
24670
24670
  simulation: {
24671
24671
  feeEstimation: {
24672
24672
  maxFee: string | number | bigint;
@@ -25131,7 +25131,7 @@ export declare const enrichedSimulateAndReviewSchema: z.ZodObject<{
25131
25131
  } | undefined;
25132
25132
  } | undefined;
25133
25133
  simulation?: undefined;
25134
- })[];
25134
+ })[] | undefined;
25135
25135
  enrichedFeeEstimation?: {
25136
25136
  transactions: {
25137
25137
  amount: bigint;
@@ -187,9 +187,9 @@ const h = t.object({
187
187
  simulation: t.undefined(),
188
188
  simulationError: P
189
189
  }), d = m.or(g), C = t.object({
190
- transactions: t.array(d)
190
+ transactions: t.array(d).optional()
191
191
  }), O = t.object({
192
- transactions: t.array(d),
192
+ transactions: t.array(d).optional(),
193
193
  enrichedFeeEstimation: b.optional(),
194
194
  isBackendDown: t.boolean().default(!1).optional()
195
195
  });
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("lodash-es"),r=require("starknet"),E=require("../../chains/starknet/address.cjs"),x=require("../../chains/starknet/constants.cjs"),h=require("./argentMaxFee.cjs"),M=require("./error.cjs"),S=require("../../utils/starknet/starknet.cjs"),F=require("../../features/simulation/transactionReview/schema.cjs"),k=require("../../utils/arrays.cjs");function P(e){return y.upperCase(e.unit)==="WEI"}function A(e){return y.upperCase(e.unit)==="FRI"}function c(e,n){return P(e)?{...e,maxFee:n(e.maxFee),overallFee:n(e.overallFee),gasPrice:n(e.gasPrice),gasUsage:n(e.gasUsage)}:{...e,overallFee:n(e.overallFee),gasPrice:n(e.gasPrice),gasUsage:n(e.gasUsage),maxAmount:n(e.maxAmount),maxPricePerUnit:n(e.maxPricePerUnit)}}function d(e){return P(e)?{maxFee:e.maxFee}:{amount:e.maxAmount,pricePerUnit:e.maxPricePerUnit}}function p(e){return A({unit:e})?x.STRK_TOKEN_ADDRESS:x.ETH_TOKEN_ADDRESS}function _(e,n,t=2){const a=BigInt(10**t),s=BigInt(Math.round(n*10**t));return e*s/a}const N=[x.STRK_TOKEN_ADDRESS],G=(e,n=C)=>{if(e.max&&"amount"in e.max)return{...e,...e.max};const t=10000n,{amount:a,pricePerUnit:s,dataGasConsumed:o=0n,dataGasPrice:m=0n}=e,u=a*s+o*m;if(u<0)throw Error("Cannot calculate max fee for negative fee");const i=r.num.toBigInt(h.argentMaxFee({estimatedFee:u})),f=Number(i)/Number(u),U=n(f),g=BigInt(Math.trunc(U*Number(t)));return{...e,amount:a*g/t,pricePerUnit:s*g/t,dataGasConsumed:o*g/t,dataGasPrice:m*g/t}},l=e=>{const{amount:n,pricePerUnit:t,dataGasConsumed:a=0n,dataGasPrice:s=0n}=e;return n*t+a*s},I=e=>{if(e.max)return"maxFee"in e.max?e.max.maxFee:l(e.max)},T=e=>{const n=I(e);return n||l(G(e))},R=e=>{if(e.deployment&&!E.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=l(e.transactions),t=e.deployment?l(e.deployment):0n;return n+t},q=e=>{if(e.deployment&&!E.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=e.deployment?T(e.deployment):0n,t=T(e.transactions);return n+t},D=(e,n)=>[{contractAddress:e,entrypoint:"transfer",calldata:r.CallData.compile(S.transferCalldataSchema.parse({recipient:n,amount:r.uint256.bnToUint256(BigInt(1))}))}],B=(e,n)=>{if(!e)return{transactions:{feeTokenAddress:n??x.ETH_TOKEN_ADDRESS,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!Array.isArray(e))throw Error(`Unexpected simulation response. Expected array. Got ${typeof e}`);if(e.length===1){const t=F.feeEstimationSchema.parse(e[0].feeEstimation);return{transactions:{feeTokenAddress:p(t.unit),amount:r.num.toBigInt(t.gasUsage),pricePerUnit:r.num.toBigInt(t.gasPrice),max:d(c(t,r.num.toBigInt)),dataGasConsumed:t.dataGasConsumed?r.num.toBigInt(t.dataGasConsumed):0n,dataGasPrice:t.dataGasPrice?r.num.toBigInt(t.dataGasPrice):0n}}}if(e.length===2){const t=F.feeEstimationSchema.parse(e[0].feeEstimation),a=F.feeEstimationSchema.parse(e[1].feeEstimation);return{deployment:{feeTokenAddress:p(t.unit),amount:r.num.toBigInt(t.gasUsage),pricePerUnit:r.num.toBigInt(t.gasPrice),max:d(c(t,r.num.toBigInt)),dataGasConsumed:t.dataGasConsumed?r.num.toBigInt(t.dataGasConsumed):0n,dataGasPrice:t.dataGasPrice?r.num.toBigInt(t.dataGasPrice):0n},transactions:{feeTokenAddress:p(a.unit),amount:r.num.toBigInt(a.gasUsage),pricePerUnit:r.num.toBigInt(a.gasPrice),max:d(c(a,r.num.toBigInt)),dataGasConsumed:a.dataGasConsumed?r.num.toBigInt(a.dataGasConsumed):0n,dataGasPrice:a.dataGasPrice?r.num.toBigInt(a.dataGasPrice):0n}}}throw Error("Unexpected simulation response length")},b=({transaction:e,nonce:n,chainId:t,version:a,isDeploymentTransaction:s,cairoVersion:o,address:m,appDomain:u})=>{let i=n;s&&e.type!=="DEPLOY_ACCOUNT"&&(i=r.num.toHex(1));const f=k.ensureArray(e.calls);return{type:e.type,chainId:t,cairoVersion:o,nonce:i,version:a,account:m,calls:f,calldata:e.calldata,salt:e.salt,signature:e.signature,classHash:e.classHash,appDomain:u}},j=(e,n)=>{const{transactions:t}=e,a=t.map(i=>{if(!i.simulation)throw new M.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});return i}),s=a.map(i=>({...i.simulation,feeEstimation:c(i.simulation.feeEstimation,Number)})),o=B(s,n),[m,u]=a.length===1?[a[0],void 0]:[a[1],a[0]];return{...o,transactions:{...o.transactions,dataGasConsumed:o.transactions.dataGasConsumed??0n,dataGasPrice:o.transactions.dataGasPrice??0n,max:d(c(m.simulation.feeEstimation,r.num.toBigInt))},deployment:o.deployment&&u?{...o.deployment,dataGasConsumed:o.deployment.dataGasConsumed??0n,dataGasPrice:o.deployment.dataGasPrice??0n,max:d(c(u.simulation.feeEstimation,r.num.toBigInt))}:void 0}},w=e=>{const n=G(e),t=T(e);return{maxFee:t,resourceBounds:{l1_gas:{max_amount:r.num.toHex(t/e.pricePerUnit),max_price_per_unit:r.num.toHex(n.pricePerUnit)},l2_gas:{max_amount:"0x0",max_price_per_unit:"0x0"}}}},O=e=>{const n=Math.sqrt(e);return isNaN(n)?Math.sqrt(2):n},C=e=>{const n=Math.cbrt(e);return isNaN(n)?Math.cbrt(2):n},W=e=>e<1||isNaN(e)?1.1:Math.log(e+1)+1;exports.buildDummyTx=D;exports.calculateCubeRootAdjustment=C;exports.calculateNonLinearAdjustment=W;exports.calculateSqrtAdjustment=O;exports.castFeeEstimation=c;exports.estimatedFeeToMaxFeeTotal=T;exports.estimatedFeeToMaxResourceBounds=w;exports.estimatedFeeToTotal=l;exports.estimatedFeesToMaxFeeTotal=q;exports.estimatedFeesToTotal=R;exports.getEstimatedFeeFromBulkSimulation=B;exports.getEstimatedFeeFromSimulationAndRespectWatermarkFee=j;exports.getPayloadFromTransaction=b;exports.getWatermarkedMaxFeeTotal=I;exports.isFRI=A;exports.isWEI=P;exports.multiplyBigIntByFloat=_;exports.toMax=d;exports.tokensRequireTxV3Support=N;exports.unitToFeeTokenAddress=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("lodash-es"),r=require("starknet"),y=require("../../chains/starknet/address.cjs"),x=require("../../chains/starknet/constants.cjs"),M=require("./argentMaxFee.cjs"),E=require("./error.cjs"),S=require("../../utils/starknet/starknet.cjs"),F=require("../../features/simulation/transactionReview/schema.cjs"),_=require("../../utils/arrays.cjs");function P(e){return A.upperCase(e.unit)==="WEI"}function I(e){return A.upperCase(e.unit)==="FRI"}function u(e,n){return P(e)?{...e,maxFee:n(e.maxFee),overallFee:n(e.overallFee),gasPrice:n(e.gasPrice),gasUsage:n(e.gasUsage)}:{...e,overallFee:n(e.overallFee),gasPrice:n(e.gasPrice),gasUsage:n(e.gasUsage),maxAmount:n(e.maxAmount),maxPricePerUnit:n(e.maxPricePerUnit)}}function d(e){return P(e)?{maxFee:e.maxFee}:{amount:e.maxAmount,pricePerUnit:e.maxPricePerUnit}}function p(e){return I({unit:e})?x.STRK_TOKEN_ADDRESS:x.ETH_TOKEN_ADDRESS}function k(e,n,t=2){const a=BigInt(10**t),s=BigInt(Math.round(n*10**t));return e*s/a}const N=[x.STRK_TOKEN_ADDRESS],G=(e,n=U)=>{if(e.max&&"amount"in e.max)return{...e,...e.max};const t=10000n,{amount:a,pricePerUnit:s,dataGasConsumed:o=0n,dataGasPrice:m=0n}=e,c=a*s+o*m;if(c<0)throw Error("Cannot calculate max fee for negative fee");const i=r.num.toBigInt(M.argentMaxFee({estimatedFee:c})),f=Number(i)/Number(c),h=n(f),g=BigInt(Math.trunc(h*Number(t)));return{...e,amount:a*g/t,pricePerUnit:s*g/t,dataGasConsumed:o*g/t,dataGasPrice:m*g/t}},l=e=>{const{amount:n,pricePerUnit:t,dataGasConsumed:a=0n,dataGasPrice:s=0n}=e;return n*t+a*s},B=e=>{if(e.max)return"maxFee"in e.max?e.max.maxFee:l(e.max)},T=e=>{const n=B(e);return n||l(G(e))},R=e=>{if(e.deployment&&!y.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=l(e.transactions),t=e.deployment?l(e.deployment):0n;return n+t},q=e=>{if(e.deployment&&!y.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=e.deployment?T(e.deployment):0n,t=T(e.transactions);return n+t},D=(e,n)=>[{contractAddress:e,entrypoint:"transfer",calldata:r.CallData.compile(S.transferCalldataSchema.parse({recipient:n,amount:r.uint256.bnToUint256(BigInt(1))}))}],C=(e,n)=>{if(!e)return{transactions:{feeTokenAddress:n??x.ETH_TOKEN_ADDRESS,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!Array.isArray(e))throw Error(`Unexpected simulation response. Expected array. Got ${typeof e}`);if(e.length===1){const t=F.feeEstimationSchema.parse(e[0].feeEstimation);return{transactions:{feeTokenAddress:p(t.unit),amount:r.num.toBigInt(t.gasUsage),pricePerUnit:r.num.toBigInt(t.gasPrice),max:d(u(t,r.num.toBigInt)),dataGasConsumed:t.dataGasConsumed?r.num.toBigInt(t.dataGasConsumed):0n,dataGasPrice:t.dataGasPrice?r.num.toBigInt(t.dataGasPrice):0n}}}if(e.length===2){const t=F.feeEstimationSchema.parse(e[0].feeEstimation),a=F.feeEstimationSchema.parse(e[1].feeEstimation);return{deployment:{feeTokenAddress:p(t.unit),amount:r.num.toBigInt(t.gasUsage),pricePerUnit:r.num.toBigInt(t.gasPrice),max:d(u(t,r.num.toBigInt)),dataGasConsumed:t.dataGasConsumed?r.num.toBigInt(t.dataGasConsumed):0n,dataGasPrice:t.dataGasPrice?r.num.toBigInt(t.dataGasPrice):0n},transactions:{feeTokenAddress:p(a.unit),amount:r.num.toBigInt(a.gasUsage),pricePerUnit:r.num.toBigInt(a.gasPrice),max:d(u(a,r.num.toBigInt)),dataGasConsumed:a.dataGasConsumed?r.num.toBigInt(a.dataGasConsumed):0n,dataGasPrice:a.dataGasPrice?r.num.toBigInt(a.dataGasPrice):0n}}}throw Error("Unexpected simulation response length")},b=({transaction:e,nonce:n,chainId:t,version:a,isDeploymentTransaction:s,cairoVersion:o,address:m,appDomain:c})=>{let i=n;s&&e.type!=="DEPLOY_ACCOUNT"&&(i=r.num.toHex(1));const f=_.ensureArray(e.calls);return{type:e.type,chainId:t,cairoVersion:o,nonce:i,version:a,account:m,calls:f,calldata:e.calldata,salt:e.salt,signature:e.signature,classHash:e.classHash,appDomain:c}},j=(e,n)=>{const{transactions:t}=e;if(!t)throw new E.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});const a=t.map(i=>{if(!i.simulation)throw new E.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});return i}),s=a.map(i=>({...i.simulation,feeEstimation:u(i.simulation.feeEstimation,Number)})),o=C(s,n),[m,c]=a.length===1?[a[0],void 0]:[a[1],a[0]];return{...o,transactions:{...o.transactions,dataGasConsumed:o.transactions.dataGasConsumed??0n,dataGasPrice:o.transactions.dataGasPrice??0n,max:d(u(m.simulation.feeEstimation,r.num.toBigInt))},deployment:o.deployment&&c?{...o.deployment,dataGasConsumed:o.deployment.dataGasConsumed??0n,dataGasPrice:o.deployment.dataGasPrice??0n,max:d(u(c.simulation.feeEstimation,r.num.toBigInt))}:void 0}},w=e=>{const n=G(e),t=T(e);return{maxFee:t,resourceBounds:{l1_gas:{max_amount:r.num.toHex(t/e.pricePerUnit),max_price_per_unit:r.num.toHex(n.pricePerUnit)},l2_gas:{max_amount:"0x0",max_price_per_unit:"0x0"}}}},W=e=>{const n=Math.sqrt(e);return isNaN(n)?Math.sqrt(2):n},U=e=>{const n=Math.cbrt(e);return isNaN(n)?Math.cbrt(2):n},O=e=>e<1||isNaN(e)?1.1:Math.log(e+1)+1;exports.buildDummyTx=D;exports.calculateCubeRootAdjustment=U;exports.calculateNonLinearAdjustment=O;exports.calculateSqrtAdjustment=W;exports.castFeeEstimation=u;exports.estimatedFeeToMaxFeeTotal=T;exports.estimatedFeeToMaxResourceBounds=w;exports.estimatedFeeToTotal=l;exports.estimatedFeesToMaxFeeTotal=q;exports.estimatedFeesToTotal=R;exports.getEstimatedFeeFromBulkSimulation=C;exports.getEstimatedFeeFromSimulationAndRespectWatermarkFee=j;exports.getPayloadFromTransaction=b;exports.getWatermarkedMaxFeeTotal=B;exports.isFRI=I;exports.isWEI=P;exports.multiplyBigIntByFloat=k;exports.toMax=d;exports.tokensRequireTxV3Support=N;exports.unitToFeeTokenAddress=p;
@@ -1,20 +1,20 @@
1
- import { upperCase as G } from "lodash-es";
2
- import { CallData as F, uint256 as U, num as r } from "starknet";
3
- import { isEqualAddress as T } from "../../chains/starknet/address.js";
4
- import { STRK_TOKEN_ADDRESS as y, ETH_TOKEN_ADDRESS as I } from "../../chains/starknet/constants.js";
5
- import { argentMaxFee as E } from "./argentMaxFee.js";
6
- import { EstimateError as h } from "./error.js";
1
+ import { upperCase as T } from "lodash-es";
2
+ import { CallData as C, uint256 as U, num as r } from "starknet";
3
+ import { isEqualAddress as I } from "../../chains/starknet/address.js";
4
+ import { STRK_TOKEN_ADDRESS as y, ETH_TOKEN_ADDRESS as A } from "../../chains/starknet/constants.js";
5
+ import { argentMaxFee as h } from "./argentMaxFee.js";
6
+ import { EstimateError as G } from "./error.js";
7
7
  import { transferCalldataSchema as _ } from "../../utils/starknet/starknet.js";
8
8
  import { feeEstimationSchema as f } from "../../features/simulation/transactionReview/schema.js";
9
9
  import { ensureArray as M } from "../../utils/arrays.js";
10
- function A(t) {
11
- return G(t.unit) === "WEI";
10
+ function E(t) {
11
+ return T(t.unit) === "WEI";
12
12
  }
13
13
  function k(t) {
14
- return G(t.unit) === "FRI";
14
+ return T(t.unit) === "FRI";
15
15
  }
16
16
  function u(t, n) {
17
- return A(t) ? {
17
+ return E(t) ? {
18
18
  ...t,
19
19
  maxFee: n(t.maxFee),
20
20
  overallFee: n(t.overallFee),
@@ -30,7 +30,7 @@ function u(t, n) {
30
30
  };
31
31
  }
32
32
  function d(t) {
33
- return A(t) ? {
33
+ return E(t) ? {
34
34
  maxFee: t.maxFee
35
35
  } : {
36
36
  amount: t.maxAmount,
@@ -38,13 +38,13 @@ function d(t) {
38
38
  };
39
39
  }
40
40
  function x(t) {
41
- return k({ unit: t }) ? y : I;
41
+ return k({ unit: t }) ? y : A;
42
42
  }
43
- function L(t, n, e = 2) {
43
+ function O(t, n, e = 2) {
44
44
  const a = BigInt(10 ** e), s = BigInt(Math.round(n * 10 ** e));
45
45
  return t * s / a;
46
46
  }
47
- const K = [y], B = (t, n = R) => {
47
+ const K = [y], F = (t, n = D) => {
48
48
  if (t.max && "amount" in t.max)
49
49
  return {
50
50
  ...t,
@@ -53,7 +53,7 @@ const K = [y], B = (t, n = R) => {
53
53
  const e = 10000n, { amount: a, pricePerUnit: s, dataGasConsumed: o = 0n, dataGasPrice: m = 0n } = t, c = a * s + o * m;
54
54
  if (c < 0)
55
55
  throw Error("Cannot calculate max fee for negative fee");
56
- const i = r.toBigInt(E({ estimatedFee: c })), g = Number(i) / Number(c), C = n(g), l = BigInt(Math.trunc(C * Number(e)));
56
+ const i = r.toBigInt(h({ estimatedFee: c })), g = Number(i) / Number(c), B = n(g), l = BigInt(Math.trunc(B * Number(e)));
57
57
  return {
58
58
  ...t,
59
59
  amount: a * l / e,
@@ -69,14 +69,14 @@ const K = [y], B = (t, n = R) => {
69
69
  return "maxFee" in t.max ? t.max.maxFee : p(t.max);
70
70
  }, P = (t) => {
71
71
  const n = N(t);
72
- return n || p(B(t));
72
+ return n || p(F(t));
73
73
  }, V = (t) => {
74
- if (t.deployment && !T(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
74
+ if (t.deployment && !I(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
75
75
  throw Error("Cannot calculate estimated fees for different tokens");
76
76
  const n = p(t.transactions), e = t.deployment ? p(t.deployment) : 0n;
77
77
  return n + e;
78
78
  }, Y = (t) => {
79
- if (t.deployment && !T(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
79
+ if (t.deployment && !I(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
80
80
  throw Error("Cannot calculate estimated fees for different tokens");
81
81
  const n = t.deployment ? P(t.deployment) : 0n, e = P(t.transactions);
82
82
  return n + e;
@@ -84,7 +84,7 @@ const K = [y], B = (t, n = R) => {
84
84
  {
85
85
  contractAddress: t,
86
86
  entrypoint: "transfer",
87
- calldata: F.compile(_.parse({
87
+ calldata: C.compile(_.parse({
88
88
  // We are using a dummy address (ETH here) as recipient to estimate the fee given we don't have a receipient yet
89
89
  recipient: n,
90
90
  // We are using the smallest possible amount to make sure this doesn't throw an error
@@ -95,7 +95,7 @@ const K = [y], B = (t, n = R) => {
95
95
  if (!t)
96
96
  return {
97
97
  transactions: {
98
- feeTokenAddress: n ?? I,
98
+ feeTokenAddress: n ?? A,
99
99
  amount: 0n,
100
100
  pricePerUnit: 0n,
101
101
  dataGasConsumed: 0n,
@@ -159,9 +159,12 @@ const K = [y], B = (t, n = R) => {
159
159
  // appDomain: "https://starknetkit-blacked-listed.vercel.app", // to simulate blacklisted domain
160
160
  };
161
161
  }, J = (t, n) => {
162
- const { transactions: e } = t, a = e.map((i) => {
162
+ const { transactions: e } = t;
163
+ if (!e)
164
+ throw new G({ code: "SIMULATE_AND_REVIEW_FAILED" });
165
+ const a = e.map((i) => {
163
166
  if (!i.simulation)
164
- throw new h({ code: "SIMULATE_AND_REVIEW_FAILED" });
167
+ throw new G({ code: "SIMULATE_AND_REVIEW_FAILED" });
165
168
  return i;
166
169
  }), s = a.map((i) => ({
167
170
  ...i.simulation,
@@ -183,7 +186,7 @@ const K = [y], B = (t, n = R) => {
183
186
  } : void 0
184
187
  };
185
188
  }, Q = (t) => {
186
- const n = B(t), e = P(t);
189
+ const n = F(t), e = P(t);
187
190
  return {
188
191
  // for v1 transactions
189
192
  maxFee: e,
@@ -204,13 +207,13 @@ const K = [y], B = (t, n = R) => {
204
207
  }, X = (t) => {
205
208
  const n = Math.sqrt(t);
206
209
  return isNaN(n) ? Math.sqrt(2) : n;
207
- }, R = (t) => {
210
+ }, D = (t) => {
208
211
  const n = Math.cbrt(t);
209
212
  return isNaN(n) ? Math.cbrt(2) : n;
210
213
  }, Z = (t) => t < 1 || isNaN(t) ? 1.1 : Math.log(t + 1) + 1;
211
214
  export {
212
215
  $ as buildDummyTx,
213
- R as calculateCubeRootAdjustment,
216
+ D as calculateCubeRootAdjustment,
214
217
  Z as calculateNonLinearAdjustment,
215
218
  X as calculateSqrtAdjustment,
216
219
  u as castFeeEstimation,
@@ -224,8 +227,8 @@ export {
224
227
  z as getPayloadFromTransaction,
225
228
  N as getWatermarkedMaxFeeTotal,
226
229
  k as isFRI,
227
- A as isWEI,
228
- L as multiplyBigIntByFloat,
230
+ E as isWEI,
231
+ O as multiplyBigIntByFloat,
229
232
  d as toMax,
230
233
  K as tokensRequireTxV3Support,
231
234
  x as unitToFeeTokenAddress
@@ -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"),T=require("../../utils/url/urlWithQuery.cjs"),y=require("../../features/simulation/transactionReview/schema.cjs"),S=require("../../utils/arrays.cjs");class I{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,c,o,l,s){const r=a.some(i=>i.type==="DEPLOY_ACCOUNT");try{if(!("getChainId"in e))throw new Error("MISSING_METHOD");const i=w.getTxVersionFromFeeToken(c),t=r?"0x0":await e.getNonce(),n=await e.getChainId(),d={transactions:a.map(g=>({...E.getPayloadFromTransaction({transaction:g,nonce:t,version:i,chainId:n,isDeploymentTransaction:r,appDomain:o,cairoVersion:e.cairoVersion,address:e.address}),type:g.type}))},p=h(this.apiBase,"reviewer","transactions","v2","review","starknet"),F=s?T.urlWithQuery(p,{delayedTransactions:"true"}):p,u=await this.httpService.post(F,{headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(d)},y.simulateAndReviewSchema);if(u.transactions.some(g=>y.isTransactionSimulationError(g)))return u;const v=E.getEstimatedFeeFromSimulationAndRespectWatermarkFee(u,c);return{...u,enrichedFeeEstimation:v}}catch(i){return console.error(i),this.fallbackToOnchainFeeEstimation({transactions:a,account:e,isDeploymentTransaction:r,feeTokenAddress:c,accountDeployTransaction:l})}}getCallsFromTx(e){let a;return e.calls&&(a=S.ensureArray(e.calls)),a}async fallbackToOnchainFeeEstimation({transactions:e,account:a,isDeploymentTransaction:c,feeTokenAddress:o,accountDeployTransaction:l}){try{const s=c?this.getCallsFromTx(e[1]):this.getCallsFromTx(e[0]);if(!s)throw new m.ReviewError({code:"NO_CALLS_FOUND"});const r=await this.fetchFeesOnchain({starknetAccount:a,calls:s,isDeployed:!c,feeTokenAddress:o,accountDeployTransaction:l});return{transactions:[],enrichedFeeEstimation:r,isBackendDown:!0}}catch(s){throw console.error(s),new m.ReviewError({message:`${s}`,code:"SIMULATE_AND_REVIEW_FAILED"})}}async fetchFeesOnchain({starknetAccount:e,calls:a,isDeployed:c,feeTokenAddress:o,accountDeployTransaction:l}){try{const s=w.getTxVersionFromFeeToken(o),r={transactions:{feeTokenAddress:o,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!c&&l){if("estimateFeeBulk"in e){const i=[{type:_.TransactionType.DEPLOY_ACCOUNT,payload:{classHash:l.classHash,addressSalt:l.salt,constructorCalldata:l.calldata,contractAddress:e.address}},{type:_.TransactionType.INVOKE,payload:a}],[t,n]=await e.estimateFeeBulk(i,{version:s}).catch(d=>{throw console.error(d),d});if(!t.gas_consumed||!t.gas_price||!n.gas_consumed||!n.gas_price)throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});r.deployment={feeTokenAddress:o,amount:t.gas_consumed,pricePerUnit:t.gas_price,dataGasConsumed:t.data_gas_consumed,dataGasPrice:t.data_gas_price},r.transactions={feeTokenAddress:o,amount:n.gas_consumed,pricePerUnit:n.gas_price,dataGasConsumed:n.data_gas_consumed,dataGasPrice:n.data_gas_price}}}else{const{gas_consumed:i,gas_price:t,data_gas_consumed:n,data_gas_price:d}=await e.estimateFee(a,{skipValidate:!0,version:s});if(!i||!t)throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});r.transactions={feeTokenAddress:o,amount:i,pricePerUnit:t,dataGasConsumed:n,dataGasPrice:d}}return r}catch(s){throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:`${s}`})}}}exports.TransactionReviewServiceWeb=I;
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;
@@ -2,11 +2,11 @@ import { TransactionType as u } from "starknet";
2
2
  import g from "url-join";
3
3
  import { ReviewError as d } from "../../errors/review.js";
4
4
  import { getTxVersionFromFeeToken as E } from "../getTransactionVersion.js";
5
- import { getPayloadFromTransaction as F, getEstimatedFeeFromSimulationAndRespectWatermarkFee as I } from "../estimate/utils.js";
6
- import { urlWithQuery as C } from "../../utils/url/urlWithQuery.js";
7
- import { simulateAndReviewSchema as O, isTransactionSimulationError as S } from "../../features/simulation/transactionReview/schema.js";
8
- import { ensureArray as N } from "../../utils/arrays.js";
9
- class B {
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
10
  constructor(a, e) {
11
11
  this.apiBase = a, this.httpService = e;
12
12
  }
@@ -26,99 +26,100 @@ class B {
26
26
  const a = g(this.apiBase, "reviewer", "warnings/reasons");
27
27
  return await this.httpService.get(a);
28
28
  }
29
- async simulateAndReview(a, e, c, o, m, t) {
30
- const r = e.some((i) => i.type === "DEPLOY_ACCOUNT");
29
+ async simulateAndReview(a, e, o, n, c, s) {
30
+ var m;
31
+ const r = e.some((t) => t.type === "DEPLOY_ACCOUNT");
31
32
  try {
32
33
  if (!("getChainId" in a))
33
34
  throw new Error("MISSING_METHOD");
34
- const i = E(c), s = r ? "0x0" : await a.getNonce(), n = await a.getChainId(), l = {
35
+ const t = E(o), i = r ? "0x0" : await a.getNonce(), l = await a.getChainId(), w = {
35
36
  transactions: e.map((h) => ({
36
- ...F({
37
+ ...I({
37
38
  transaction: h,
38
- nonce: s,
39
- version: i,
40
- chainId: n,
39
+ nonce: i,
40
+ version: t,
41
+ chainId: l,
41
42
  isDeploymentTransaction: r,
42
- appDomain: o,
43
+ appDomain: n,
43
44
  cairoVersion: a.cairoVersion,
44
45
  address: a.address
45
46
  }),
46
47
  type: h.type
47
48
  }))
48
- }, _ = g(this.apiBase, "reviewer", "transactions", "v2", "review", "starknet"), w = t ? C(_, { delayedTransactions: "true" }) : _, p = await this.httpService.post(w, {
49
+ }, _ = g(this.apiBase, "reviewer", "transactions", "v2", "review", "starknet"), y = s ? O(_, { delayedTransactions: "true" }) : _, p = await this.httpService.post(y, {
49
50
  headers: {
50
51
  Accept: "application/json",
51
52
  "Content-Type": "application/json"
52
53
  },
53
- body: JSON.stringify(l)
54
- }, O);
55
- if (p.transactions.some((h) => S(h)))
54
+ body: JSON.stringify(w)
55
+ }, S);
56
+ if ((m = p.transactions) == null ? void 0 : m.some((h) => N(h)))
56
57
  return p;
57
- const y = I(p, c);
58
+ const F = C(p, o);
58
59
  return {
59
60
  ...p,
60
- enrichedFeeEstimation: y
61
+ enrichedFeeEstimation: F
61
62
  };
62
- } catch (i) {
63
- return console.error(i), this.fallbackToOnchainFeeEstimation({
63
+ } catch (t) {
64
+ return console.error(t), this.fallbackToOnchainFeeEstimation({
64
65
  transactions: e,
65
66
  account: a,
66
67
  isDeploymentTransaction: r,
67
- feeTokenAddress: c,
68
- accountDeployTransaction: m
68
+ feeTokenAddress: o,
69
+ accountDeployTransaction: c
69
70
  });
70
71
  }
71
72
  }
72
73
  getCallsFromTx(a) {
73
74
  let e;
74
- return a.calls && (e = N(a.calls)), e;
75
+ return a.calls && (e = v(a.calls)), e;
75
76
  }
76
- async fallbackToOnchainFeeEstimation({ transactions: a, account: e, isDeploymentTransaction: c, feeTokenAddress: o, accountDeployTransaction: m }) {
77
+ async fallbackToOnchainFeeEstimation({ transactions: a, account: e, isDeploymentTransaction: o, feeTokenAddress: n, accountDeployTransaction: c }) {
77
78
  try {
78
- const t = c ? this.getCallsFromTx(a[1]) : this.getCallsFromTx(a[0]);
79
- if (!t)
79
+ const s = o ? this.getCallsFromTx(a[1]) : this.getCallsFromTx(a[0]);
80
+ if (!s)
80
81
  throw new d({
81
82
  code: "NO_CALLS_FOUND"
82
83
  });
83
84
  const r = await this.fetchFeesOnchain({
84
85
  starknetAccount: e,
85
- calls: t,
86
- isDeployed: !c,
87
- feeTokenAddress: o,
88
- accountDeployTransaction: m
86
+ calls: s,
87
+ isDeployed: !o,
88
+ feeTokenAddress: n,
89
+ accountDeployTransaction: c
89
90
  });
90
91
  return {
91
92
  transactions: [],
92
93
  enrichedFeeEstimation: r,
93
94
  isBackendDown: !0
94
95
  };
95
- } catch (t) {
96
- throw console.error(t), new d({
97
- message: `${t}`,
96
+ } catch (s) {
97
+ throw console.error(s), new d({
98
+ message: `${s}`,
98
99
  code: "SIMULATE_AND_REVIEW_FAILED"
99
100
  });
100
101
  }
101
102
  }
102
- async fetchFeesOnchain({ starknetAccount: a, calls: e, isDeployed: c, feeTokenAddress: o, accountDeployTransaction: m }) {
103
+ async fetchFeesOnchain({ starknetAccount: a, calls: e, isDeployed: o, feeTokenAddress: n, accountDeployTransaction: c }) {
103
104
  try {
104
- const t = E(o), r = {
105
+ const s = E(n), r = {
105
106
  transactions: {
106
- feeTokenAddress: o,
107
+ feeTokenAddress: n,
107
108
  amount: 0n,
108
109
  pricePerUnit: 0n,
109
110
  dataGasConsumed: 0n,
110
111
  dataGasPrice: 0n
111
112
  }
112
113
  };
113
- if (!c && m) {
114
+ if (!o && c) {
114
115
  if ("estimateFeeBulk" in a) {
115
- const i = [
116
+ const m = [
116
117
  {
117
118
  type: u.DEPLOY_ACCOUNT,
118
119
  payload: {
119
- classHash: m.classHash,
120
- addressSalt: m.salt,
121
- constructorCalldata: m.calldata,
120
+ classHash: c.classHash,
121
+ addressSalt: c.salt,
122
+ constructorCalldata: c.calldata,
122
123
  contractAddress: a.address
123
124
  }
124
125
  },
@@ -126,57 +127,57 @@ class B {
126
127
  type: u.INVOKE,
127
128
  payload: e
128
129
  }
129
- ], [s, n] = await a.estimateFeeBulk(i, {
130
- version: t
130
+ ], [t, i] = await a.estimateFeeBulk(m, {
131
+ version: s
131
132
  }).catch((l) => {
132
133
  throw console.error(l), l;
133
134
  });
134
- if (!s.gas_consumed || !s.gas_price || !n.gas_consumed || !n.gas_price)
135
+ if (!t.gas_consumed || !t.gas_price || !i.gas_consumed || !i.gas_price)
135
136
  throw new d({
136
137
  code: "ONCHAIN_FEE_ESTIMATION_FAILED",
137
138
  message: "Missing gas_consumed or gas_price"
138
139
  });
139
140
  r.deployment = {
140
- feeTokenAddress: o,
141
- amount: s.gas_consumed,
142
- pricePerUnit: s.gas_price,
143
- dataGasConsumed: s.data_gas_consumed,
144
- dataGasPrice: s.data_gas_price
141
+ feeTokenAddress: n,
142
+ amount: t.gas_consumed,
143
+ pricePerUnit: t.gas_price,
144
+ dataGasConsumed: t.data_gas_consumed,
145
+ dataGasPrice: t.data_gas_price
145
146
  }, r.transactions = {
146
- feeTokenAddress: o,
147
- amount: n.gas_consumed,
148
- pricePerUnit: n.gas_price,
149
- dataGasConsumed: n.data_gas_consumed,
150
- dataGasPrice: n.data_gas_price
147
+ feeTokenAddress: n,
148
+ amount: i.gas_consumed,
149
+ pricePerUnit: i.gas_price,
150
+ dataGasConsumed: i.data_gas_consumed,
151
+ dataGasPrice: i.data_gas_price
151
152
  };
152
153
  }
153
154
  } else {
154
- const { gas_consumed: i, gas_price: s, data_gas_consumed: n, data_gas_price: l } = await a.estimateFee(e, {
155
+ const { gas_consumed: m, gas_price: t, data_gas_consumed: i, data_gas_price: l } = await a.estimateFee(e, {
155
156
  skipValidate: !0,
156
- version: t
157
+ version: s
157
158
  });
158
- if (!i || !s)
159
+ if (!m || !t)
159
160
  throw new d({
160
161
  code: "ONCHAIN_FEE_ESTIMATION_FAILED",
161
162
  message: "Missing gas_consumed or gas_price"
162
163
  });
163
164
  r.transactions = {
164
- feeTokenAddress: o,
165
- amount: i,
166
- pricePerUnit: s,
167
- dataGasConsumed: n,
165
+ feeTokenAddress: n,
166
+ amount: m,
167
+ pricePerUnit: t,
168
+ dataGasConsumed: i,
168
169
  dataGasPrice: l
169
170
  };
170
171
  }
171
172
  return r;
172
- } catch (t) {
173
+ } catch (s) {
173
174
  throw new d({
174
175
  code: "ONCHAIN_FEE_ESTIMATION_FAILED",
175
- message: `${t}`
176
+ message: `${s}`
176
177
  });
177
178
  }
178
179
  }
179
180
  }
180
181
  export {
181
- B as TransactionReviewServiceWeb
182
+ x as TransactionReviewServiceWeb
182
183
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.43.0",
3
+ "version": "1.43.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"