@argent/x-shared 1.74.2 → 1.75.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +212 -209
- package/dist/node_modules/.pnpm/@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/weierstrass.cjs +1 -1
- package/dist/node_modules/.pnpm/@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/weierstrass.js +12 -13
- package/dist/node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.cjs +1 -1
- package/dist/node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.js +60 -60
- package/dist/node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getValue.cjs +1 -1
- package/dist/node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getValue.js +1 -1
- package/dist/src/chains/starknet/address.cjs +1 -1
- package/dist/src/chains/starknet/address.js +16 -16
- package/dist/src/features/simulation/activity/normalize.cjs +1 -1
- package/dist/src/features/simulation/activity/normalize.js +12 -13
- package/dist/src/features/simulation/activity/utils/createNativeActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/createNativeActivity.js +22 -24
- package/dist/src/features/simulation/activity/utils/getAnyActivityTitle.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/getAnyActivityTitle.js +11 -12
- package/dist/src/features/simulation/activity/utils/hasDelegationActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/hasDelegationActivity.js +2 -8
- package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.js +4 -8
- package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.js +4 -8
- package/dist/src/features/simulation/activity/utils/isMulticallWithDeploymentActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isMulticallWithDeploymentActivity.js +3 -9
- package/dist/src/features/simulation/activity/utils/isRejectOnChainActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isRejectOnChainActivity.js +15 -19
- package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.js +4 -8
- package/dist/src/features/simulation/activity/utils/isSwapActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isSwapActivity.js +9 -16
- package/dist/src/features/simulation/activity/utils/isUpgradeActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isUpgradeActivity.js +4 -8
- package/dist/src/features/simulation/fees/schema.cjs +1 -1
- package/dist/src/features/simulation/fees/schema.d.ts +16 -0
- package/dist/src/features/simulation/fees/schema.js +8 -6
- package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.cjs +1 -1
- package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.js +10 -11
- package/dist/src/features/simulation/transactionReview/schema.cjs +1 -1
- package/dist/src/features/simulation/transactionReview/schema.d.ts +23 -0
- package/dist/src/features/simulation/transactionReview/schema.js +20 -18
- package/dist/src/features/swap/services/SwapTransactionService.cjs +1 -1
- package/dist/src/features/swap/services/SwapTransactionService.js +46 -49
- package/dist/src/http/HttpService.cjs +1 -1
- package/dist/src/http/HttpService.js +55 -55
- package/dist/src/knownDapps/utils/getDapplandUrl.cjs +1 -1
- package/dist/src/knownDapps/utils/getDapplandUrl.js +6 -8
- package/dist/src/nfts/BackendNftService.cjs +1 -1
- package/dist/src/nfts/BackendNftService.js +15 -16
- package/dist/src/tokens/service/implementation.cjs +1 -1
- package/dist/src/tokens/service/implementation.d.ts +2 -0
- package/dist/src/tokens/service/implementation.js +12 -12
- package/dist/src/tokens/service/types/backend.model.cjs +1 -1
- package/dist/src/tokens/service/types/backend.model.d.ts +26 -0
- package/dist/src/tokens/service/types/backend.model.js +25 -23
- package/dist/src/transactions/estimate/utils.cjs +1 -1
- package/dist/src/transactions/estimate/utils.d.ts +33 -0
- package/dist/src/transactions/estimate/utils.js +80 -76
- package/dist/src/transactions/service/implementation.cjs +1 -1
- package/dist/src/transactions/service/implementation.d.ts +4 -0
- package/dist/src/transactions/service/implementation.js +89 -96
- package/dist/src/transactions/service/utils.cjs +1 -1
- package/dist/src/transactions/service/utils.d.ts +2 -3
- package/dist/src/transactions/service/utils.js +12 -11
- package/dist/src/transactions/transactionVersion.cjs +1 -1
- package/dist/src/transactions/transactionVersion.d.ts +2 -0
- package/dist/src/transactions/transactionVersion.js +12 -10
- package/dist/src/utils/readFileAsString.cjs +1 -1
- package/dist/src/utils/readFileAsString.js +3 -6
- package/package.json +5 -5
- package/dist/defiDecomposition.cjs +0 -1
- package/dist/defiDecomposition.d.ts +0 -2
- package/dist/defiDecomposition.js +0 -65
- package/dist/node_modules/.pnpm/@starknet-io_types-js@0.7.7/node_modules/@starknet-io/types-js/dist/esm/api/nonspec.cjs +0 -1
- package/dist/node_modules/.pnpm/@starknet-io_types-js@0.7.7/node_modules/@starknet-io/types-js/dist/esm/api/nonspec.js +0 -6
- package/dist/src/features/defiDecomposition/helpers/computeCollateralizedDebtPositionsUsdValue.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/computeCollateralizedDebtPositionsUsdValue.d.ts +0 -6
- package/dist/src/features/defiDecomposition/helpers/computeCollateralizedDebtPositionsUsdValue.js +0 -62
- package/dist/src/features/defiDecomposition/helpers/computeConcentratedLiquidityPositionsUsdValue.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/computeConcentratedLiquidityPositionsUsdValue.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/computeConcentratedLiquidityPositionsUsdValue.js +0 -31
- package/dist/src/features/defiDecomposition/helpers/computeDefiDecompositionUsdValue.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/computeDefiDecompositionUsdValue.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/computeDefiDecompositionUsdValue.js +0 -55
- package/dist/src/features/defiDecomposition/helpers/computeDelegatedTokensPositionsUsdValue.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/computeDelegatedTokensPositionsUsdValue.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/computeDelegatedTokensPositionsUsdValue.js +0 -30
- package/dist/src/features/defiDecomposition/helpers/computeStakingPositionsUsdValue.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/computeStakingPositionsUsdValue.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/computeStakingPositionsUsdValue.js +0 -30
- package/dist/src/features/defiDecomposition/helpers/computeStrkDelegatedStakingPositionsUsdValue.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/computeStrkDelegatedStakingPositionsUsdValue.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/computeStrkDelegatedStakingPositionsUsdValue.js +0 -30
- package/dist/src/features/defiDecomposition/helpers/computeUsdValueForPosition.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/computeUsdValueForPosition.d.ts +0 -3
- package/dist/src/features/defiDecomposition/helpers/computeUsdValueForPosition.js +0 -17
- package/dist/src/features/defiDecomposition/helpers/getDefiProductName.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/getDefiProductName.d.ts +0 -1
- package/dist/src/features/defiDecomposition/helpers/getDefiProductName.js +0 -11
- package/dist/src/features/defiDecomposition/helpers/index.d.ts +0 -13
- package/dist/src/features/defiDecomposition/helpers/parseCollateralizedDebtPositions.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/parseCollateralizedDebtPositions.d.ts +0 -7
- package/dist/src/features/defiDecomposition/helpers/parseCollateralizedDebtPositions.js +0 -57
- package/dist/src/features/defiDecomposition/helpers/parseConcentratedLiquidityPositions.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/parseConcentratedLiquidityPositions.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/parseConcentratedLiquidityPositions.js +0 -42
- package/dist/src/features/defiDecomposition/helpers/parseDefiDecomposition.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/parseDefiDecomposition.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/parseDefiDecomposition.js +0 -63
- package/dist/src/features/defiDecomposition/helpers/parseDelegatedTokensPositions.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/parseDelegatedTokensPositions.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/parseDelegatedTokensPositions.js +0 -27
- package/dist/src/features/defiDecomposition/helpers/parseStakingPositions.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/parseStakingPositions.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/parseStakingPositions.js +0 -29
- package/dist/src/features/defiDecomposition/helpers/parseStrkDelegatedStakingPositions.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/parseStrkDelegatedStakingPositions.d.ts +0 -4
- package/dist/src/features/defiDecomposition/helpers/parseStrkDelegatedStakingPositions.js +0 -27
- package/dist/src/features/defiDecomposition/helpers/sortDescendingByUsdValue.cjs +0 -1
- package/dist/src/features/defiDecomposition/helpers/sortDescendingByUsdValue.d.ts +0 -9
- package/dist/src/features/defiDecomposition/helpers/sortDescendingByUsdValue.js +0 -9
- package/dist/src/features/defiDecomposition/index.d.ts +0 -2
- package/dist/src/features/defiDecomposition/schema.cjs +0 -1
- package/dist/src/features/defiDecomposition/schema.d.ts +0 -1842
- package/dist/src/features/defiDecomposition/schema.js +0 -153
- package/dist/src/transactions/equalTokens.cjs +0 -1
- package/dist/src/transactions/equalTokens.js +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("lodash-es"),o=require("starknet"),C=require("./adjustment.cjs"),I=require("./argentMaxFee.cjs"),p=require("./error.cjs"),T=require("../../chains/starknet/constants.cjs"),g=require("../../chains/starknet/address.cjs"),D=e=>{const{transactions:t}=e;if(!t)throw new p.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});if(!Array.isArray(t))throw Error(`Unexpected simulation response. Expected array. Got ${typeof t}`);if(E.isEmpty(t))return[];if(t.length>2)throw Error(`Unexpected simulation response length. Got ${t.length}`);const a=t.map(m=>{if(!m.simulation)throw new p.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});return{...m.simulation,...M(m.simulation.feeEstimations)}}),[s,n]=a.length===1?[a[0],void 0]:[a[1],a[0]],r=y(s,n),i=x(s,n);return[...r,...i]},M=e=>{const[t,a]=E.partition(e,s=>"unit"in s&&s.unit==="FRI");return{nativeFeeEstimations:t,paymasterFeeEstimations:a}},x=(e,t)=>{if(!e)return[];if(!t)return e.paymasterFeeEstimations.map(n=>({type:"paymaster",transactions:l(n),deployment:void 0}));const a=t.paymasterFeeEstimations,s=e.paymasterFeeEstimations;if(a.length!==s.length)throw Error("Deployment and transaction fee estimations length mismatch");return s.map((n,r)=>({type:"paymaster",transactions:l(n),deployment:l(a[r])}))},y=(e,t)=>{if(!e)return[];if(!t)return e.nativeFeeEstimations.map(n=>({type:"native",transactions:F(n),deployment:void 0}));const a=t.nativeFeeEstimations,s=e.nativeFeeEstimations;if(a.length!==s.length)throw Error("Deployment and transaction fee estimations length mismatch");return s.map((n,r)=>({type:"native",transactions:F(n),deployment:F(a[r])}))},l=e=>({feeTokenAddress:e.token.address,maxFee:BigInt(e.maxFee),overallFee:BigInt(e.overallFee),tip:e.defaultTip?o.num.toBigInt(e.defaultTip):void 0}),F=e=>({feeTokenAddress:T.STRK_TOKEN_ADDRESS,overallFee:o.num.toBigInt(e.overallFee),l1Gas:{gasConsumed:o.num.toBigInt(e.resourceBounds.l1Gas.maxAmount),gasPrice:o.num.toBigInt(e.resourceBounds.l1Gas.maxPricePerUnit)},l1DataGas:{gasConsumed:o.num.toBigInt(e.resourceBounds.l1DataGas.maxAmount),gasPrice:o.num.toBigInt(e.resourceBounds.l1DataGas.maxPricePerUnit)},l2Gas:{gasConsumed:o.num.toBigInt(e.resourceBounds.l2Gas.maxAmount),gasPrice:o.num.toBigInt(e.resourceBounds.l2Gas.maxPricePerUnit)},tip:e.defaultTip?o.num.toBigInt(e.defaultTip):void 0}),S=e=>{const{l1Gas:t,l2Gas:a,l1DataGas:s}=e.resourceBounds,n=t.maxAmount*t.maxPricePerUnit+a.maxAmount*a.maxPricePerUnit+s.maxAmount*s.maxPricePerUnit;return o.num.toBigInt(n)},k=e=>{const{type:t,deployment:a,transactions:s}=e;if(t==="paymaster")return s.maxFee+(a?.maxFee??0n);if(a&&!g.isEqualAddress(a.feeTokenAddress,s.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=!s.overallFee&&!a?.overallFee,r=d=>n?G(d):c(d),i=a?r(a):0n,m=r(s);return i+m},R=e=>e.transactions.overallFee?e.transactions.overallFee+(e.deployment?.overallFee??0n):A(e),v=(e=[])=>e.filter(a=>a.type==="native"),w=e=>e.filter(t=>t.type==="paymaster"),f=()=>T.STRK_TOKEN_ADDRESS,B=(e=[],t)=>{const a=v(e).find(s=>g.isEqualAddress(s.transactions.feeTokenAddress,t));if(!a)throw Error(`No native estimated fee found for ${t}`);return a},P=(e=[])=>{const t=f();return B(e,t)},q=(e=[])=>P(e),A=e=>{if(e.deployment&&!g.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const t=c(e.transactions),a=e.deployment?c(e.deployment):0n;return t+a},c=e=>{const{l1Gas:t,l2Gas:a,l1DataGas:s}=e;return t.gasConsumed*t.gasPrice+a.gasConsumed*a.gasPrice+s.gasConsumed*s.gasPrice},G=e=>c(h(e)),h=(e,t=C.calculateCubeRootAdjustment)=>{const a=10000n,{l1Gas:s,l2Gas:n,l1DataGas:r}=e,i=s.gasConsumed*s.gasPrice+n.gasConsumed*n.gasPrice+r.gasConsumed*r.gasPrice;if(i<0)throw Error("Cannot calculate max fee for negative fee");const m=o.num.toBigInt(I.argentMaxFee({estimatedFee:i})),d=Number(m)/Number(i),N=t(d),u=BigInt(Math.trunc(N*Number(a)));return{...e,l1Gas:{gasConsumed:s.gasConsumed*u/a,gasPrice:s.gasPrice*u/a},l2Gas:{gasConsumed:n.gasConsumed*u/a,gasPrice:n.gasPrice*u/a},l1DataGas:{gasConsumed:r.gasConsumed*u/a,gasPrice:r.gasPrice*u/a}}},_=e=>{const t=e.overallFee?e:h(e);return{...e,resourceBounds:{l1_gas:U(t.l1Gas),l2_gas:{max_amount:o.num.toHex(t.l2Gas.gasConsumed),max_price_per_unit:o.num.toHex(t.l2Gas.gasPrice)},l1_data_gas:{max_amount:o.num.toHex(t.l1DataGas.gasConsumed),max_price_per_unit:o.num.toHex(t.l1DataGas.gasPrice)}}}},V=e=>({...e,resourceBounds:o.stark.resourceBoundsToBigInt(_(e).resourceBounds)}),U=e=>({max_amount:o.num.toHex(e.gasConsumed),max_price_per_unit:o.num.toHex(e.gasPrice)});exports.estimatedFeeToMaxFeeTotal=G;exports.estimatedFeeToMaxResourceBounds=_;exports.estimatedFeeToMaxResourceBoundsBN=V;exports.estimatedFeeToTotal=c;exports.estimatedFeesToMaxFeeTotalV2=k;exports.estimatedFeesToTotal=A;exports.estimatedFeesToTotalWithOverallFee=R;exports.filterPaymasterEstimatedFees=w;exports.getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2=D;exports.getNativeEstimatedFeeByFeeToken=B;exports.getNativeEstimatedFeeByTxVersion=P;exports.getNativeEstimatedFeeForAccount=q;exports.getNativeEstimatedFees=v;exports.getNativeFeeFromSimulation=y;exports.getNativeFeeTokenAddress=f;exports.getPaymasterFeeFromSimulation=x;exports.toMaxFeeEstimation=S;
|
|
@@ -39,4 +39,37 @@ export declare const estimatedFeeToMaxResourceBounds: (estimatedFee: NativeEstim
|
|
|
39
39
|
max_price_per_unit: string;
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
+
feeTokenAddress: `0x${string}`;
|
|
43
|
+
l1Gas: {
|
|
44
|
+
gasConsumed: bigint;
|
|
45
|
+
gasPrice: bigint;
|
|
46
|
+
};
|
|
47
|
+
l2Gas: {
|
|
48
|
+
gasConsumed: bigint;
|
|
49
|
+
gasPrice: bigint;
|
|
50
|
+
};
|
|
51
|
+
l1DataGas: {
|
|
52
|
+
gasConsumed: bigint;
|
|
53
|
+
gasPrice: bigint;
|
|
54
|
+
};
|
|
55
|
+
overallFee?: bigint | undefined;
|
|
56
|
+
tip?: bigint | undefined;
|
|
57
|
+
};
|
|
58
|
+
export declare const estimatedFeeToMaxResourceBoundsBN: (estimatedFee: NativeEstimatedFeeData) => {
|
|
59
|
+
resourceBounds: import('starknet').ResourceBoundsBN;
|
|
60
|
+
feeTokenAddress: `0x${string}`;
|
|
61
|
+
l1Gas: {
|
|
62
|
+
gasConsumed: bigint;
|
|
63
|
+
gasPrice: bigint;
|
|
64
|
+
};
|
|
65
|
+
l2Gas: {
|
|
66
|
+
gasConsumed: bigint;
|
|
67
|
+
gasPrice: bigint;
|
|
68
|
+
};
|
|
69
|
+
l1DataGas: {
|
|
70
|
+
gasConsumed: bigint;
|
|
71
|
+
gasPrice: bigint;
|
|
72
|
+
};
|
|
73
|
+
overallFee?: bigint | undefined;
|
|
74
|
+
tip?: bigint | undefined;
|
|
42
75
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { isEmpty as y, partition as
|
|
2
|
-
import { num as
|
|
3
|
-
import { calculateCubeRootAdjustment as
|
|
4
|
-
import { argentMaxFee as
|
|
5
|
-
import { EstimateError as
|
|
1
|
+
import { isEmpty as y, partition as v } from "lodash-es";
|
|
2
|
+
import { stark as P, num as n } from "starknet";
|
|
3
|
+
import { calculateCubeRootAdjustment as T } from "./adjustment.js";
|
|
4
|
+
import { argentMaxFee as B } from "./argentMaxFee.js";
|
|
5
|
+
import { EstimateError as F } from "./error.js";
|
|
6
6
|
import { STRK_TOKEN_ADDRESS as E } from "../../chains/starknet/constants.js";
|
|
7
|
-
import { isEqualAddress as
|
|
8
|
-
const
|
|
7
|
+
import { isEqualAddress as p } from "../../chains/starknet/address.js";
|
|
8
|
+
const j = (e) => {
|
|
9
9
|
const { transactions: t } = e;
|
|
10
10
|
if (!t)
|
|
11
|
-
throw new
|
|
11
|
+
throw new F({ code: "SIMULATE_AND_REVIEW_FAILED" });
|
|
12
12
|
if (!Array.isArray(t))
|
|
13
13
|
throw Error(`Unexpected simulation response. Expected array. Got ${typeof t}`);
|
|
14
14
|
if (y(t))
|
|
@@ -17,104 +17,103 @@ const L = (e) => {
|
|
|
17
17
|
throw Error(`Unexpected simulation response length. Got ${t.length}`);
|
|
18
18
|
const a = t.map((m) => {
|
|
19
19
|
if (!m.simulation)
|
|
20
|
-
throw new
|
|
20
|
+
throw new F({ code: "SIMULATE_AND_REVIEW_FAILED" });
|
|
21
21
|
return {
|
|
22
22
|
...m.simulation,
|
|
23
|
-
...
|
|
23
|
+
...A(m.simulation.feeEstimations)
|
|
24
24
|
};
|
|
25
|
-
}), [s,
|
|
25
|
+
}), [s, o] = a.length === 1 ? [a[0], void 0] : [a[1], a[0]], r = h(s, o), i = G(s, o);
|
|
26
26
|
return [...r, ...i];
|
|
27
|
-
},
|
|
28
|
-
const [t, a] =
|
|
27
|
+
}, A = (e) => {
|
|
28
|
+
const [t, a] = v(e, (s) => "unit" in s && s.unit === "FRI");
|
|
29
29
|
return { nativeFeeEstimations: t, paymasterFeeEstimations: a };
|
|
30
|
-
},
|
|
30
|
+
}, G = (e, t) => {
|
|
31
31
|
if (!e)
|
|
32
32
|
return [];
|
|
33
33
|
if (!t)
|
|
34
|
-
return e.paymasterFeeEstimations.map((
|
|
34
|
+
return e.paymasterFeeEstimations.map((o) => ({
|
|
35
35
|
type: "paymaster",
|
|
36
|
-
transactions: d(
|
|
36
|
+
transactions: d(o),
|
|
37
37
|
deployment: void 0
|
|
38
38
|
}));
|
|
39
39
|
const a = t.paymasterFeeEstimations, s = e.paymasterFeeEstimations;
|
|
40
40
|
if (a.length !== s.length)
|
|
41
41
|
throw Error("Deployment and transaction fee estimations length mismatch");
|
|
42
|
-
return s.map((
|
|
42
|
+
return s.map((o, r) => ({
|
|
43
43
|
type: "paymaster",
|
|
44
|
-
transactions: d(
|
|
44
|
+
transactions: d(o),
|
|
45
45
|
deployment: d(a[r])
|
|
46
46
|
}));
|
|
47
47
|
}, h = (e, t) => {
|
|
48
48
|
if (!e)
|
|
49
49
|
return [];
|
|
50
50
|
if (!t)
|
|
51
|
-
return e.nativeFeeEstimations.map((
|
|
51
|
+
return e.nativeFeeEstimations.map((o) => ({
|
|
52
52
|
type: "native",
|
|
53
|
-
transactions: g(
|
|
53
|
+
transactions: g(o),
|
|
54
54
|
deployment: void 0
|
|
55
55
|
}));
|
|
56
56
|
const a = t.nativeFeeEstimations, s = e.nativeFeeEstimations;
|
|
57
57
|
if (a.length !== s.length)
|
|
58
58
|
throw Error("Deployment and transaction fee estimations length mismatch");
|
|
59
|
-
return s.map((
|
|
59
|
+
return s.map((o, r) => ({
|
|
60
60
|
type: "native",
|
|
61
|
-
transactions: g(
|
|
61
|
+
transactions: g(o),
|
|
62
62
|
deployment: g(a[r])
|
|
63
63
|
}));
|
|
64
64
|
}, d = (e) => ({
|
|
65
65
|
feeTokenAddress: e.token.address,
|
|
66
66
|
maxFee: BigInt(e.maxFee),
|
|
67
|
-
overallFee: BigInt(e.overallFee)
|
|
67
|
+
overallFee: BigInt(e.overallFee),
|
|
68
|
+
tip: e.defaultTip ? n.toBigInt(e.defaultTip) : void 0
|
|
68
69
|
}), g = (e) => ({
|
|
69
70
|
feeTokenAddress: E,
|
|
70
|
-
overallFee:
|
|
71
|
+
overallFee: n.toBigInt(e.overallFee),
|
|
71
72
|
l1Gas: {
|
|
72
|
-
gasConsumed:
|
|
73
|
-
gasPrice:
|
|
73
|
+
gasConsumed: n.toBigInt(e.resourceBounds.l1Gas.maxAmount),
|
|
74
|
+
gasPrice: n.toBigInt(e.resourceBounds.l1Gas.maxPricePerUnit)
|
|
74
75
|
},
|
|
75
76
|
l1DataGas: {
|
|
76
|
-
gasConsumed:
|
|
77
|
-
gasPrice:
|
|
77
|
+
gasConsumed: n.toBigInt(e.resourceBounds.l1DataGas.maxAmount),
|
|
78
|
+
gasPrice: n.toBigInt(e.resourceBounds.l1DataGas.maxPricePerUnit)
|
|
78
79
|
},
|
|
79
80
|
l2Gas: {
|
|
80
|
-
gasConsumed:
|
|
81
|
-
gasPrice:
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
gasConsumed: n.toBigInt(e.resourceBounds.l2Gas.maxAmount),
|
|
82
|
+
gasPrice: n.toBigInt(e.resourceBounds.l2Gas.maxPricePerUnit)
|
|
83
|
+
},
|
|
84
|
+
tip: e.defaultTip ? n.toBigInt(e.defaultTip) : void 0
|
|
85
|
+
}), W = (e) => {
|
|
86
|
+
const { l1Gas: t, l2Gas: a, l1DataGas: s } = e.resourceBounds, o = t.maxAmount * t.maxPricePerUnit + a.maxAmount * a.maxPricePerUnit + s.maxAmount * s.maxPricePerUnit;
|
|
87
|
+
return n.toBigInt(o);
|
|
88
|
+
}, $ = (e) => {
|
|
87
89
|
const { type: t, deployment: a, transactions: s } = e;
|
|
88
90
|
if (t === "paymaster")
|
|
89
|
-
return s.maxFee + (
|
|
90
|
-
if (a && !
|
|
91
|
+
return s.maxFee + (a?.maxFee ?? 0n);
|
|
92
|
+
if (a && !p(a.feeTokenAddress, s.feeTokenAddress))
|
|
91
93
|
throw Error("Cannot calculate estimated fees for different tokens");
|
|
92
|
-
const
|
|
94
|
+
const o = !s.overallFee && !a?.overallFee, r = (u) => o ? w(u) : l(u), i = a ? r(a) : 0n, m = r(s);
|
|
93
95
|
return i + m;
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
return e.transactions.overallFee ? e.transactions.overallFee + (((t = e.deployment) == null ? void 0 : t.overallFee) ?? 0n) : D(e);
|
|
97
|
-
}, _ = (e = []) => e.filter((a) => a.type === "native"), $ = (e) => e.filter((t) => t.type === "paymaster"), B = () => E, C = (e = [], t) => {
|
|
98
|
-
const a = _(e).find((s) => F(s.transactions.feeTokenAddress, t));
|
|
96
|
+
}, K = (e) => e.transactions.overallFee ? e.transactions.overallFee + (e.deployment?.overallFee ?? 0n) : N(e), _ = (e = []) => e.filter((a) => a.type === "native"), O = (e) => e.filter((t) => t.type === "paymaster"), C = () => E, I = (e = [], t) => {
|
|
97
|
+
const a = _(e).find((s) => p(s.transactions.feeTokenAddress, t));
|
|
99
98
|
if (!a)
|
|
100
99
|
throw Error(`No native estimated fee found for ${t}`);
|
|
101
100
|
return a;
|
|
102
|
-
},
|
|
103
|
-
const t =
|
|
104
|
-
return
|
|
105
|
-
},
|
|
106
|
-
if (e.deployment && !
|
|
101
|
+
}, D = (e = []) => {
|
|
102
|
+
const t = C();
|
|
103
|
+
return I(e, t);
|
|
104
|
+
}, q = (e = []) => D(e), N = (e) => {
|
|
105
|
+
if (e.deployment && !p(e.deployment.feeTokenAddress, e.transactions.feeTokenAddress))
|
|
107
106
|
throw Error("Cannot calculate estimated fees for different tokens");
|
|
108
107
|
const t = l(e.transactions), a = e.deployment ? l(e.deployment) : 0n;
|
|
109
108
|
return t + a;
|
|
110
109
|
}, l = (e) => {
|
|
111
110
|
const { l1Gas: t, l2Gas: a, l1DataGas: s } = e;
|
|
112
111
|
return t.gasConsumed * t.gasPrice + a.gasConsumed * a.gasPrice + s.gasConsumed * s.gasPrice;
|
|
113
|
-
},
|
|
114
|
-
const a = 10000n, { l1Gas: s, l2Gas:
|
|
112
|
+
}, w = (e) => l(x(e)), x = (e, t = T) => {
|
|
113
|
+
const a = 10000n, { l1Gas: s, l2Gas: o, l1DataGas: r } = e, i = s.gasConsumed * s.gasPrice + o.gasConsumed * o.gasPrice + r.gasConsumed * r.gasPrice;
|
|
115
114
|
if (i < 0)
|
|
116
115
|
throw Error("Cannot calculate max fee for negative fee");
|
|
117
|
-
const m =
|
|
116
|
+
const m = n.toBigInt(B({ estimatedFee: i })), u = Number(m) / Number(i), f = t(u), c = BigInt(Math.trunc(f * Number(a)));
|
|
118
117
|
return {
|
|
119
118
|
...e,
|
|
120
119
|
l1Gas: {
|
|
@@ -122,48 +121,53 @@ const L = (e) => {
|
|
|
122
121
|
gasPrice: s.gasPrice * c / a
|
|
123
122
|
},
|
|
124
123
|
l2Gas: {
|
|
125
|
-
gasConsumed:
|
|
126
|
-
gasPrice:
|
|
124
|
+
gasConsumed: o.gasConsumed * c / a,
|
|
125
|
+
gasPrice: o.gasPrice * c / a
|
|
127
126
|
},
|
|
128
127
|
l1DataGas: {
|
|
129
128
|
gasConsumed: r.gasConsumed * c / a,
|
|
130
129
|
gasPrice: r.gasPrice * c / a
|
|
131
130
|
}
|
|
132
131
|
};
|
|
133
|
-
},
|
|
134
|
-
const t = e.overallFee ? e :
|
|
132
|
+
}, k = (e) => {
|
|
133
|
+
const t = e.overallFee ? e : x(e);
|
|
135
134
|
return {
|
|
135
|
+
...e,
|
|
136
136
|
resourceBounds: {
|
|
137
|
-
l1_gas:
|
|
137
|
+
l1_gas: M(t.l1Gas),
|
|
138
138
|
l2_gas: {
|
|
139
|
-
max_amount:
|
|
140
|
-
max_price_per_unit:
|
|
139
|
+
max_amount: n.toHex(t.l2Gas.gasConsumed),
|
|
140
|
+
max_price_per_unit: n.toHex(t.l2Gas.gasPrice)
|
|
141
141
|
},
|
|
142
142
|
l1_data_gas: {
|
|
143
|
-
max_amount:
|
|
144
|
-
max_price_per_unit:
|
|
143
|
+
max_amount: n.toHex(t.l1DataGas.gasConsumed),
|
|
144
|
+
max_price_per_unit: n.toHex(t.l1DataGas.gasPrice)
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
}, z = (e) => ({
|
|
149
|
+
...e,
|
|
150
|
+
resourceBounds: P.resourceBoundsToBigInt(k(e).resourceBounds)
|
|
151
|
+
}), M = (e) => ({
|
|
152
|
+
max_amount: n.toHex(e.gasConsumed),
|
|
153
|
+
max_price_per_unit: n.toHex(e.gasPrice)
|
|
151
154
|
});
|
|
152
155
|
export {
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
w as estimatedFeeToMaxFeeTotal,
|
|
157
|
+
k as estimatedFeeToMaxResourceBounds,
|
|
158
|
+
z as estimatedFeeToMaxResourceBoundsBN,
|
|
155
159
|
l as estimatedFeeToTotal,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
$ as estimatedFeesToMaxFeeTotalV2,
|
|
161
|
+
N as estimatedFeesToTotal,
|
|
162
|
+
K as estimatedFeesToTotalWithOverallFee,
|
|
163
|
+
O as filterPaymasterEstimatedFees,
|
|
164
|
+
j as getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2,
|
|
165
|
+
I as getNativeEstimatedFeeByFeeToken,
|
|
166
|
+
D as getNativeEstimatedFeeByTxVersion,
|
|
167
|
+
q as getNativeEstimatedFeeForAccount,
|
|
164
168
|
_ as getNativeEstimatedFees,
|
|
165
169
|
h as getNativeFeeFromSimulation,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
C as getNativeFeeTokenAddress,
|
|
171
|
+
G as getPaymasterFeeFromSimulation,
|
|
172
|
+
W as toMaxFeeEstimation
|
|
169
173
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("starknet"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("starknet"),g=require("url-join"),l=require("../../errors/review.cjs"),y=require("./utils.cjs"),C=require("../../utils/url/urlWithQuery.cjs"),h=require("../../features/simulation/transactionReview/schema.cjs"),B=require("../estimate/utils.cjs"),v=require("../../utils/arrays.cjs");class F{constructor(e,a){this.apiBase=e,this.httpService=a}async getLabels(){const e=g(this.apiBase,"reviewer","labels");return await this.httpService.get(e)}async getWarnings(){const e=g(this.apiBase,"reviewer","warnings/reasons");return await this.httpService.get(e)}async simulateAndReview(e,a,c,i,o,t){const s=a.some(r=>r.type==="DEPLOY_ACCOUNT");try{if(!("getChainId"in e))throw new Error("MISSING_METHOD");const r=s?"0x0":await e.getNonce(),n=await e.getChainId(),u={transactions:a.map(d=>({...y.getPayloadFromTransaction({transaction:d,nonce:r,chainId:n,isDeploymentTransaction:s,appDomain:i,cairoVersion:e.cairoVersion,address:e.address}),type:d.type}))},m=g(this.apiBase,"reviewer","transactions","v2","review","starknet"),w=t?C.urlWithQuery(m,{delayedTransactions:"true"}):m,_=await this.httpService.post(w,{headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(u)},h.simulateAndReviewSchema);if(_.transactions?.some(d=>h.isTransactionSimulationError(d)))return _;const E=B.getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2(_);return{..._,enrichedFeeEstimation:E}}catch(r){return console.error(r),this.fallbackToOnchainFeeEstimation({transactions:a,account:e,isDeploymentTransaction:s,feeTokenAddress:c,accountDeployTransaction:o})}}getCallsFromTx(e){let a;return e.calls&&(a=v.ensureArray(e.calls)),a}async fallbackToOnchainFeeEstimation({transactions:e,account:a,isDeploymentTransaction:c,feeTokenAddress:i,accountDeployTransaction:o}){try{const t=c?this.getCallsFromTx(e[1]):this.getCallsFromTx(e[0]);if(!t)throw new l.ReviewError({code:"NO_CALLS_FOUND"});const s=await this.fetchFeesOnchain({starknetAccount:a,calls:t,isDeployed:!c,feeTokenAddress:i,accountDeployTransaction:o});return{transactions:[],enrichedFeeEstimation:s,isBackendDown:!0}}catch(t){throw console.error(t),new l.ReviewError({message:`${t}`,code:"SIMULATE_AND_REVIEW_FAILED"})}}async fetchFeesOnchain({starknetAccount:e,calls:a,isDeployed:c,feeTokenAddress:i,accountDeployTransaction:o}){try{const t={type:"native",transactions:{feeTokenAddress:i,l1Gas:{gasConsumed:0n,gasPrice:0n},l2Gas:{gasConsumed:0n,gasPrice:0n},l1DataGas:{gasConsumed:0n,gasPrice:0n}}};if(!c&&o){if("estimateFeeBulk"in e){const s=[{type:p.TransactionType.DEPLOY_ACCOUNT,payload:{classHash:o.classHash,addressSalt:o.salt,constructorCalldata:o.calldata,contractAddress:e.address}},{type:p.TransactionType.INVOKE,payload:a}],[r,n]=await e.estimateFeeBulk(s).catch(u=>{throw console.error(u),u});if(!r.resourceBounds.l1_data_gas||!r.resourceBounds.l1_gas||!r.resourceBounds.l2_gas||!n.resourceBounds.l1_data_gas||!n.resourceBounds.l1_gas||!n.resourceBounds.l2_gas)throw new l.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});t.deployment={feeTokenAddress:i,l1Gas:{gasConsumed:r.resourceBounds.l1_gas.max_amount,gasPrice:r.resourceBounds.l1_gas.max_price_per_unit},l2Gas:{gasConsumed:r.resourceBounds.l2_gas.max_amount,gasPrice:r.resourceBounds.l2_gas.max_price_per_unit},l1DataGas:{gasConsumed:r.resourceBounds.l1_data_gas.max_amount,gasPrice:r.resourceBounds.l1_data_gas.max_price_per_unit}},t.transactions={feeTokenAddress:i,l1Gas:{gasConsumed:n.resourceBounds.l1_gas.max_amount,gasPrice:n.resourceBounds.l1_gas.max_price_per_unit},l2Gas:{gasConsumed:n.resourceBounds.l2_gas.max_amount,gasPrice:n.resourceBounds.l2_gas.max_price_per_unit},l1DataGas:{gasConsumed:n.resourceBounds.l1_data_gas.max_amount,gasPrice:n.resourceBounds.l1_data_gas.max_price_per_unit}}}}else{const{resourceBounds:s}=await e.estimateInvokeFee(a);if(!s.l1_gas||!s.l2_gas||!s.l1_data_gas)throw new l.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});t.transactions={feeTokenAddress:i,l1Gas:{gasConsumed:s.l1_gas.max_amount,gasPrice:s.l1_gas.max_price_per_unit},l2Gas:{gasConsumed:s.l2_gas.max_amount,gasPrice:s.l2_gas.max_price_per_unit},l1DataGas:{gasConsumed:s.l1_data_gas.max_amount,gasPrice:s.l1_data_gas.max_price_per_unit}}}return[t]}catch(t){throw new l.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:`${t}`})}}}exports.TransactionReviewServiceWeb=F;
|
|
@@ -50,6 +50,7 @@ export declare class TransactionReviewServiceWeb implements ITransactionReviewSe
|
|
|
50
50
|
gasPrice: bigint;
|
|
51
51
|
};
|
|
52
52
|
overallFee?: bigint | undefined;
|
|
53
|
+
tip?: bigint | undefined;
|
|
53
54
|
};
|
|
54
55
|
deployment?: {
|
|
55
56
|
feeTokenAddress: `0x${string}`;
|
|
@@ -66,6 +67,7 @@ export declare class TransactionReviewServiceWeb implements ITransactionReviewSe
|
|
|
66
67
|
gasPrice: bigint;
|
|
67
68
|
};
|
|
68
69
|
overallFee?: bigint | undefined;
|
|
70
|
+
tip?: bigint | undefined;
|
|
69
71
|
} | undefined;
|
|
70
72
|
} | {
|
|
71
73
|
type: "paymaster";
|
|
@@ -73,11 +75,13 @@ export declare class TransactionReviewServiceWeb implements ITransactionReviewSe
|
|
|
73
75
|
feeTokenAddress: `0x${string}`;
|
|
74
76
|
overallFee: bigint;
|
|
75
77
|
maxFee: bigint;
|
|
78
|
+
tip?: bigint | undefined;
|
|
76
79
|
};
|
|
77
80
|
deployment?: {
|
|
78
81
|
feeTokenAddress: `0x${string}`;
|
|
79
82
|
overallFee: bigint;
|
|
80
83
|
maxFee: bigint;
|
|
84
|
+
tip?: bigint | undefined;
|
|
81
85
|
} | undefined;
|
|
82
86
|
})[];
|
|
83
87
|
isBackendDown: boolean;
|