@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.
- package/dist/src/features/simulation/activity/utils/createNativeActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/createNativeActivity.js +23 -23
- package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.cjs +1 -1
- package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.js +10 -9
- package/dist/src/features/simulation/transactionReview/schema.cjs +1 -1
- package/dist/src/features/simulation/transactionReview/schema.d.ts +12 -12
- package/dist/src/features/simulation/transactionReview/schema.js +2 -2
- package/dist/src/transactions/estimate/utils.cjs +1 -1
- package/dist/src/transactions/estimate/utils.js +30 -27
- package/dist/src/transactions/service/implementation.cjs +1 -1
- package/dist/src/transactions/service/implementation.js +66 -65
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
2
|
-
import { normalizeActivitySummaryCollection as
|
|
3
|
-
import { NativeActivityTypeNative as
|
|
4
|
-
function
|
|
5
|
-
var
|
|
6
|
-
const a = (
|
|
7
|
-
return a ? a.map((
|
|
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
|
|
10
|
-
var
|
|
11
|
-
const
|
|
12
|
-
type:
|
|
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 && !
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
const
|
|
19
|
-
|
|
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
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
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
|
|
26
|
+
return u.parse(r);
|
|
27
27
|
}
|
|
28
28
|
export {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
z as createNativeActivity,
|
|
30
|
+
S as normalizeActions
|
|
31
31
|
};
|
package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|
package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { getMessageFromSimulationError as
|
|
2
|
-
import { isTransactionSimulationError as
|
|
3
|
-
import { getPrettyRpcError as
|
|
4
|
-
function
|
|
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((
|
|
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
|
|
11
|
+
const i = l(r), s = r.message || r.error, t = g(s), m = t || r.label;
|
|
11
12
|
return {
|
|
12
|
-
message: t ? s :
|
|
13
|
-
label:
|
|
13
|
+
message: t ? s : i,
|
|
14
|
+
label: m
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
export {
|
|
17
|
-
|
|
18
|
+
M as getErrorMessageAndLabelFromSimulation
|
|
18
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
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
|
|
2
|
-
import { CallData as
|
|
3
|
-
import { isEqualAddress as
|
|
4
|
-
import { STRK_TOKEN_ADDRESS as y, ETH_TOKEN_ADDRESS as
|
|
5
|
-
import { argentMaxFee as
|
|
6
|
-
import { EstimateError as
|
|
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
|
|
11
|
-
return
|
|
10
|
+
function E(t) {
|
|
11
|
+
return T(t.unit) === "WEI";
|
|
12
12
|
}
|
|
13
13
|
function k(t) {
|
|
14
|
-
return
|
|
14
|
+
return T(t.unit) === "FRI";
|
|
15
15
|
}
|
|
16
16
|
function u(t, n) {
|
|
17
|
-
return
|
|
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
|
|
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 :
|
|
41
|
+
return k({ unit: t }) ? y : A;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
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],
|
|
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(
|
|
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(
|
|
72
|
+
return n || p(F(t));
|
|
73
73
|
}, V = (t) => {
|
|
74
|
-
if (t.deployment && !
|
|
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 && !
|
|
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:
|
|
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 ??
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
},
|
|
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
|
-
|
|
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
|
-
|
|
228
|
-
|
|
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"),
|
|
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
|
|
6
|
-
import { urlWithQuery as
|
|
7
|
-
import { simulateAndReviewSchema as
|
|
8
|
-
import { ensureArray as
|
|
9
|
-
class
|
|
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,
|
|
30
|
-
|
|
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
|
|
35
|
+
const t = E(o), i = r ? "0x0" : await a.getNonce(), l = await a.getChainId(), w = {
|
|
35
36
|
transactions: e.map((h) => ({
|
|
36
|
-
...
|
|
37
|
+
...I({
|
|
37
38
|
transaction: h,
|
|
38
|
-
nonce:
|
|
39
|
-
version:
|
|
40
|
-
chainId:
|
|
39
|
+
nonce: i,
|
|
40
|
+
version: t,
|
|
41
|
+
chainId: l,
|
|
41
42
|
isDeploymentTransaction: r,
|
|
42
|
-
appDomain:
|
|
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"),
|
|
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(
|
|
54
|
-
},
|
|
55
|
-
if (p.transactions.some((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
|
|
58
|
+
const F = C(p, o);
|
|
58
59
|
return {
|
|
59
60
|
...p,
|
|
60
|
-
enrichedFeeEstimation:
|
|
61
|
+
enrichedFeeEstimation: F
|
|
61
62
|
};
|
|
62
|
-
} catch (
|
|
63
|
-
return console.error(
|
|
63
|
+
} catch (t) {
|
|
64
|
+
return console.error(t), this.fallbackToOnchainFeeEstimation({
|
|
64
65
|
transactions: e,
|
|
65
66
|
account: a,
|
|
66
67
|
isDeploymentTransaction: r,
|
|
67
|
-
feeTokenAddress:
|
|
68
|
-
accountDeployTransaction:
|
|
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 =
|
|
75
|
+
return a.calls && (e = v(a.calls)), e;
|
|
75
76
|
}
|
|
76
|
-
async fallbackToOnchainFeeEstimation({ transactions: a, account: e, isDeploymentTransaction:
|
|
77
|
+
async fallbackToOnchainFeeEstimation({ transactions: a, account: e, isDeploymentTransaction: o, feeTokenAddress: n, accountDeployTransaction: c }) {
|
|
77
78
|
try {
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
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:
|
|
86
|
-
isDeployed: !
|
|
87
|
-
feeTokenAddress:
|
|
88
|
-
accountDeployTransaction:
|
|
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 (
|
|
96
|
-
throw console.error(
|
|
97
|
-
message: `${
|
|
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:
|
|
103
|
+
async fetchFeesOnchain({ starknetAccount: a, calls: e, isDeployed: o, feeTokenAddress: n, accountDeployTransaction: c }) {
|
|
103
104
|
try {
|
|
104
|
-
const
|
|
105
|
+
const s = E(n), r = {
|
|
105
106
|
transactions: {
|
|
106
|
-
feeTokenAddress:
|
|
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 (!
|
|
114
|
+
if (!o && c) {
|
|
114
115
|
if ("estimateFeeBulk" in a) {
|
|
115
|
-
const
|
|
116
|
+
const m = [
|
|
116
117
|
{
|
|
117
118
|
type: u.DEPLOY_ACCOUNT,
|
|
118
119
|
payload: {
|
|
119
|
-
classHash:
|
|
120
|
-
addressSalt:
|
|
121
|
-
constructorCalldata:
|
|
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
|
-
], [
|
|
130
|
-
version:
|
|
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 (!
|
|
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:
|
|
141
|
-
amount:
|
|
142
|
-
pricePerUnit:
|
|
143
|
-
dataGasConsumed:
|
|
144
|
-
dataGasPrice:
|
|
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:
|
|
147
|
-
amount:
|
|
148
|
-
pricePerUnit:
|
|
149
|
-
dataGasConsumed:
|
|
150
|
-
dataGasPrice:
|
|
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:
|
|
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:
|
|
157
|
+
version: s
|
|
157
158
|
});
|
|
158
|
-
if (!
|
|
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:
|
|
165
|
-
amount:
|
|
166
|
-
pricePerUnit:
|
|
167
|
-
dataGasConsumed:
|
|
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 (
|
|
173
|
+
} catch (s) {
|
|
173
174
|
throw new d({
|
|
174
175
|
code: "ONCHAIN_FEE_ESTIMATION_FAILED",
|
|
175
|
-
message: `${
|
|
176
|
+
message: `${s}`
|
|
176
177
|
});
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
export {
|
|
181
|
-
|
|
182
|
+
x as TransactionReviewServiceWeb
|
|
182
183
|
};
|