@argent/x-shared 1.56.0 → 1.56.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 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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("lodash-es"),a=require("starknet"),y=require("../../chains/starknet/address.cjs"),x=require("../../chains/starknet/constants.cjs"),U=require("./argentMaxFee.cjs"),E=require("./error.cjs"),h=require("../../utils/starknet/starknet.cjs"),P=require("../../features/simulation/transactionReview/schema.cjs"),S=require("../../utils/arrays.cjs");function F(t){return A.upperCase(t.unit)==="WEI"}function G(t){return A.upperCase(t.unit)==="FRI"}function u(t,n){return F(t)?{...t,maxFee:n(t.maxFee),overallFee:n(t.overallFee),gasPrice:n(t.gasPrice),gasUsage:n(t.gasUsage)}:{...t,overallFee:n(t.overallFee),gasPrice:n(t.gasPrice),gasUsage:n(t.gasUsage),maxAmount:n(t.maxAmount),maxPricePerUnit:n(t.maxPricePerUnit)}}function d(t){return F(t)?{maxFee:t.maxFee}:{amount:t.maxAmount,pricePerUnit:t.maxPricePerUnit}}function p(t){return G({unit:t})?x.STRK_TOKEN_ADDRESS:x.ETH_TOKEN_ADDRESS}function k(t,n,e=2){const r=BigInt(10**e),o=BigInt(Math.round(n*10**e));return t*o/r}const N=[x.STRK_TOKEN_ADDRESS],I=(t,n=C)=>{if(t.max&&"amount"in t.max)return{...t,...t.max};const e=10000n,{amount:r,pricePerUnit:o,dataGasConsumed:s=0n,dataGasPrice:m=0n}=t,c=r*o+s*m;if(c<0)throw Error("Cannot calculate max fee for negative fee");const i=a.num.toBigInt(U.argentMaxFee({estimatedFee:c})),f=Number(i)/Number(c),M=n(f),g=BigInt(Math.trunc(M*Number(e)));return{...t,amount:r*g/e,pricePerUnit:o*g/e,dataGasConsumed:s*g/e,dataGasPrice:m*g/e}},l=t=>{const{amount:n,pricePerUnit:e,dataGasConsumed:r=0n,dataGasPrice:o=0n}=t;return n*e+r*o},B=t=>{if(t.max)return"maxFee"in t.max?t.max.maxFee:l(t.max)},T=t=>{const n=B(t);return n||l(I(t))},R=t=>{if(t.deployment&&!y.isEqualAddress(t.deployment.feeTokenAddress,t.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=l(t.transactions),e=t.deployment?l(t.deployment):0n;return n+e},q=t=>{if(t.deployment&&!y.isEqualAddress(t.deployment.feeTokenAddress,t.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=t.deployment?T(t.deployment):0n,e=T(t.transactions);return n+e},D=(t,n)=>[{contractAddress:t,entrypoint:"transfer",calldata:a.CallData.compile(h.transferCalldataSchema.parse({recipient:n,amount:a.uint256.bnToUint256(BigInt(1))}))}],_=(t,n)=>{if(!t)return{transactions:{feeTokenAddress:n??x.ETH_TOKEN_ADDRESS,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!Array.isArray(t))throw Error(`Unexpected simulation response. Expected array. Got ${typeof t}`);if(t.length===1){const e=P.feeEstimationSchema.parse(t[0].feeEstimation);return{transactions:{feeTokenAddress:p(e.unit),amount:a.num.toBigInt(e.gasUsage),pricePerUnit:a.num.toBigInt(e.gasPrice),max:d(u(e,a.num.toBigInt)),dataGasConsumed:e.dataGasConsumed?a.num.toBigInt(e.dataGasConsumed):0n,dataGasPrice:e.dataGasPrice?a.num.toBigInt(e.dataGasPrice):0n}}}if(t.length===2){const e=P.feeEstimationSchema.parse(t[0].feeEstimation),r=P.feeEstimationSchema.parse(t[1].feeEstimation);return{deployment:{feeTokenAddress:p(e.unit),amount:a.num.toBigInt(e.gasUsage),pricePerUnit:a.num.toBigInt(e.gasPrice),max:d(u(e,a.num.toBigInt)),dataGasConsumed:e.dataGasConsumed?a.num.toBigInt(e.dataGasConsumed):0n,dataGasPrice:e.dataGasPrice?a.num.toBigInt(e.dataGasPrice):0n},transactions:{feeTokenAddress:p(r.unit),amount:a.num.toBigInt(r.gasUsage),pricePerUnit:a.num.toBigInt(r.gasPrice),max:d(u(r,a.num.toBigInt)),dataGasConsumed:r.dataGasConsumed?a.num.toBigInt(r.dataGasConsumed):0n,dataGasPrice:r.dataGasPrice?a.num.toBigInt(r.dataGasPrice):0n}}}throw Error("Unexpected simulation response length")},b=({transaction:t,nonce:n,chainId:e,version:r,isDeploymentTransaction:o,cairoVersion:s,address:m,appDomain:c})=>{let i=n;o&&t.type!=="DEPLOY_ACCOUNT"&&(i=a.num.toHex(1));const f=S.ensureArray(t.calls);return{type:t.type,chainId:e,cairoVersion:s,nonce:i,version:r,account:m,calls:f,calldata:t.calldata,salt:t.salt,signature:t.signature,classHash:t.classHash,appDomain:c}},W=(t,n)=>{const{transactions:e}=t;if(!e)throw new E.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});const r=e.map(i=>{if(!i.simulation)throw new E.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});return i}),o=r.map(i=>({...i.simulation,feeEstimation:u(i.simulation.feeEstimation,Number)})),s=_(o,n),[m,c]=r.length===1?[r[0],void 0]:[r[1],r[0]];return{...s,transactions:{...s.transactions,dataGasConsumed:s.transactions.dataGasConsumed??0n,dataGasPrice:s.transactions.dataGasPrice??0n,max:d(u(m.simulation.feeEstimation,a.num.toBigInt))},deployment:s.deployment&&c?{...s.deployment,dataGasConsumed:s.deployment.dataGasConsumed??0n,dataGasPrice:s.deployment.dataGasPrice??0n,max:d(u(c.simulation.feeEstimation,a.num.toBigInt))}:void 0}},j=t=>({max_amount:a.num.toHex(t.amount),max_price_per_unit:a.num.toHex(t.pricePerUnit)}),w=(t,n,e)=>({max_amount:a.num.toHex(t/n),max_price_per_unit:a.num.toHex(e)}),H=t=>{const n=I(t),e=T(t);return{maxFee:e,resourceBounds:{l1_gas:(o=>o!==void 0&&"amount"in o&&"pricePerUnit"in o)(t.max)?j(t.max):w(e,t.pricePerUnit,n.pricePerUnit),l2_gas:{max_amount:"0x0",max_price_per_unit:"0x0"}}}},L=t=>{const n=Math.sqrt(t);return isNaN(n)?Math.sqrt(2):n},C=t=>{const n=Math.cbrt(t);return isNaN(n)?Math.cbrt(2):n},v=t=>t<1||isNaN(t)?1.1:Math.log(t+1)+1;exports.buildDummyTx=D;exports.calculateCubeRootAdjustment=C;exports.calculateNonLinearAdjustment=v;exports.calculateSqrtAdjustment=L;exports.castFeeEstimation=u;exports.estimatedFeeToMaxFeeTotal=T;exports.estimatedFeeToMaxResourceBounds=H;exports.estimatedFeeToTotal=l;exports.estimatedFeesToMaxFeeTotal=q;exports.estimatedFeesToTotal=R;exports.getEstimatedFeeFromBulkSimulation=_;exports.getEstimatedFeeFromSimulationAndRespectWatermarkFee=W;exports.getPayloadFromTransaction=b;exports.getWatermarkedMaxFeeTotal=B;exports.isFRI=G;exports.isWEI=F;exports.multiplyBigIntByFloat=k;exports.toMax=d;exports.tokensRequireTxV3Support=N;exports.unitToFeeTokenAddress=p;
@@ -1,32 +1,32 @@
1
- import { upperCase as T } from "lodash-es";
2
- import { num as r, CallData as C, uint256 as U } 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";
1
+ import { upperCase as A } from "lodash-es";
2
+ import { num as r, CallData as B, uint256 as C } from "starknet";
3
+ import { isEqualAddress as T } from "../../chains/starknet/address.js";
4
+ import { STRK_TOKEN_ADDRESS as I, ETH_TOKEN_ADDRESS as y } from "../../chains/starknet/constants.js";
5
+ import { argentMaxFee as _ } from "./argentMaxFee.js";
6
6
  import { EstimateError as G } from "./error.js";
7
- import { transferCalldataSchema as _ } from "../../utils/starknet/starknet.js";
7
+ import { transferCalldataSchema as h } 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
10
  function E(t) {
11
- return T(t.unit) === "WEI";
11
+ return A(t.unit) === "WEI";
12
12
  }
13
13
  function k(t) {
14
- return T(t.unit) === "FRI";
14
+ return A(t.unit) === "FRI";
15
15
  }
16
- function u(t, n) {
16
+ function u(t, e) {
17
17
  return E(t) ? {
18
18
  ...t,
19
- maxFee: n(t.maxFee),
20
- overallFee: n(t.overallFee),
21
- gasPrice: n(t.gasPrice),
22
- gasUsage: n(t.gasUsage)
19
+ maxFee: e(t.maxFee),
20
+ overallFee: e(t.overallFee),
21
+ gasPrice: e(t.gasPrice),
22
+ gasUsage: e(t.gasUsage)
23
23
  } : {
24
24
  ...t,
25
- overallFee: n(t.overallFee),
26
- gasPrice: n(t.gasPrice),
27
- gasUsage: n(t.gasUsage),
28
- maxAmount: n(t.maxAmount),
29
- maxPricePerUnit: n(t.maxPricePerUnit)
25
+ overallFee: e(t.overallFee),
26
+ gasPrice: e(t.gasPrice),
27
+ gasUsage: e(t.gasUsage),
28
+ maxAmount: e(t.maxAmount),
29
+ maxPricePerUnit: e(t.maxPricePerUnit)
30
30
  };
31
31
  }
32
32
  function d(t) {
@@ -38,64 +38,64 @@ function d(t) {
38
38
  };
39
39
  }
40
40
  function x(t) {
41
- return k({ unit: t }) ? y : A;
41
+ return k({ unit: t }) ? I : y;
42
42
  }
43
- function O(t, n, e = 2) {
44
- const a = BigInt(10 ** e), s = BigInt(Math.round(n * 10 ** e));
45
- return t * s / a;
43
+ function V(t, e, n = 2) {
44
+ const a = BigInt(10 ** n), o = BigInt(Math.round(e * 10 ** n));
45
+ return t * o / a;
46
46
  }
47
- const K = [y], F = (t, n = D) => {
47
+ const Y = [I], U = (t, e = w) => {
48
48
  if (t.max && "amount" in t.max)
49
49
  return {
50
50
  ...t,
51
51
  ...t.max
52
52
  };
53
- const e = 10000n, { amount: a, pricePerUnit: s, dataGasConsumed: o = 0n, dataGasPrice: m = 0n } = t, c = a * s + o * m;
53
+ const n = 10000n, { amount: a, pricePerUnit: o, dataGasConsumed: s = 0n, dataGasPrice: m = 0n } = t, c = a * o + s * m;
54
54
  if (c < 0)
55
55
  throw Error("Cannot calculate max fee for negative fee");
56
- const i = r.toBigInt(h({ estimatedFee: c })), g = Number(i) / Number(c), B = n(g), l = BigInt(Math.trunc(B * Number(e)));
56
+ const i = r.toBigInt(_({ estimatedFee: c })), g = Number(i) / Number(c), F = e(g), l = BigInt(Math.trunc(F * Number(n)));
57
57
  return {
58
58
  ...t,
59
- amount: a * l / e,
60
- pricePerUnit: s * l / e,
61
- dataGasConsumed: o * l / e,
62
- dataGasPrice: m * l / e
59
+ amount: a * l / n,
60
+ pricePerUnit: o * l / n,
61
+ dataGasConsumed: s * l / n,
62
+ dataGasPrice: m * l / n
63
63
  };
64
64
  }, p = (t) => {
65
- const { amount: n, pricePerUnit: e, dataGasConsumed: a = 0n, dataGasPrice: s = 0n } = t;
66
- return n * e + a * s;
65
+ const { amount: e, pricePerUnit: n, dataGasConsumed: a = 0n, dataGasPrice: o = 0n } = t;
66
+ return e * n + a * o;
67
67
  }, N = (t) => {
68
68
  if (t.max)
69
69
  return "maxFee" in t.max ? t.max.maxFee : p(t.max);
70
70
  }, P = (t) => {
71
- const n = N(t);
72
- return n || p(F(t));
73
- }, V = (t) => {
74
- if (t.deployment && !I(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
71
+ const e = N(t);
72
+ return e || p(U(t));
73
+ }, $ = (t) => {
74
+ if (t.deployment && !T(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
75
75
  throw Error("Cannot calculate estimated fees for different tokens");
76
- const n = p(t.transactions), e = t.deployment ? p(t.deployment) : 0n;
77
- return n + e;
78
- }, Y = (t) => {
79
- if (t.deployment && !I(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
76
+ const e = p(t.transactions), n = t.deployment ? p(t.deployment) : 0n;
77
+ return e + n;
78
+ }, z = (t) => {
79
+ if (t.deployment && !T(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
80
80
  throw Error("Cannot calculate estimated fees for different tokens");
81
- const n = t.deployment ? P(t.deployment) : 0n, e = P(t.transactions);
82
- return n + e;
83
- }, $ = (t, n) => [
81
+ const e = t.deployment ? P(t.deployment) : 0n, n = P(t.transactions);
82
+ return e + n;
83
+ }, J = (t, e) => [
84
84
  {
85
85
  contractAddress: t,
86
86
  entrypoint: "transfer",
87
- calldata: C.compile(_.parse({
87
+ calldata: B.compile(h.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
- recipient: n,
89
+ recipient: e,
90
90
  // We are using the smallest possible amount to make sure this doesn't throw an error
91
- amount: U.bnToUint256(BigInt(1))
91
+ amount: C.bnToUint256(BigInt(1))
92
92
  }))
93
93
  }
94
- ], S = (t, n) => {
94
+ ], S = (t, e) => {
95
95
  if (!t)
96
96
  return {
97
97
  transactions: {
98
- feeTokenAddress: n ?? A,
98
+ feeTokenAddress: e ?? y,
99
99
  amount: 0n,
100
100
  pricePerUnit: 0n,
101
101
  dataGasConsumed: 0n,
@@ -105,28 +105,28 @@ const K = [y], F = (t, n = D) => {
105
105
  if (!Array.isArray(t))
106
106
  throw Error(`Unexpected simulation response. Expected array. Got ${typeof t}`);
107
107
  if (t.length === 1) {
108
- const e = f.parse(t[0].feeEstimation);
108
+ const n = f.parse(t[0].feeEstimation);
109
109
  return {
110
110
  transactions: {
111
- feeTokenAddress: x(e.unit),
112
- amount: r.toBigInt(e.gasUsage),
113
- pricePerUnit: r.toBigInt(e.gasPrice),
114
- max: d(u(e, r.toBigInt)),
115
- dataGasConsumed: e.dataGasConsumed ? r.toBigInt(e.dataGasConsumed) : 0n,
116
- dataGasPrice: e.dataGasPrice ? r.toBigInt(e.dataGasPrice) : 0n
111
+ feeTokenAddress: x(n.unit),
112
+ amount: r.toBigInt(n.gasUsage),
113
+ pricePerUnit: r.toBigInt(n.gasPrice),
114
+ max: d(u(n, r.toBigInt)),
115
+ dataGasConsumed: n.dataGasConsumed ? r.toBigInt(n.dataGasConsumed) : 0n,
116
+ dataGasPrice: n.dataGasPrice ? r.toBigInt(n.dataGasPrice) : 0n
117
117
  }
118
118
  };
119
119
  }
120
120
  if (t.length === 2) {
121
- const e = f.parse(t[0].feeEstimation), a = f.parse(t[1].feeEstimation);
121
+ const n = f.parse(t[0].feeEstimation), a = f.parse(t[1].feeEstimation);
122
122
  return {
123
123
  deployment: {
124
- feeTokenAddress: x(e.unit),
125
- amount: r.toBigInt(e.gasUsage),
126
- pricePerUnit: r.toBigInt(e.gasPrice),
127
- max: d(u(e, r.toBigInt)),
128
- dataGasConsumed: e.dataGasConsumed ? r.toBigInt(e.dataGasConsumed) : 0n,
129
- dataGasPrice: e.dataGasPrice ? r.toBigInt(e.dataGasPrice) : 0n
124
+ feeTokenAddress: x(n.unit),
125
+ amount: r.toBigInt(n.gasUsage),
126
+ pricePerUnit: r.toBigInt(n.gasPrice),
127
+ max: d(u(n, r.toBigInt)),
128
+ dataGasConsumed: n.dataGasConsumed ? r.toBigInt(n.dataGasConsumed) : 0n,
129
+ dataGasPrice: n.dataGasPrice ? r.toBigInt(n.dataGasPrice) : 0n
130
130
  },
131
131
  transactions: {
132
132
  feeTokenAddress: x(a.unit),
@@ -139,14 +139,14 @@ const K = [y], F = (t, n = D) => {
139
139
  };
140
140
  }
141
141
  throw Error("Unexpected simulation response length");
142
- }, z = ({ transaction: t, nonce: n, chainId: e, version: a, isDeploymentTransaction: s, cairoVersion: o, address: m, appDomain: c }) => {
143
- let i = n;
144
- s && t.type !== "DEPLOY_ACCOUNT" && (i = r.toHex(1));
142
+ }, Q = ({ transaction: t, nonce: e, chainId: n, version: a, isDeploymentTransaction: o, cairoVersion: s, address: m, appDomain: c }) => {
143
+ let i = e;
144
+ o && t.type !== "DEPLOY_ACCOUNT" && (i = r.toHex(1));
145
145
  const g = M(t.calls);
146
146
  return {
147
147
  type: t.type,
148
- chainId: e,
149
- cairoVersion: o,
148
+ chainId: n,
149
+ cairoVersion: s,
150
150
  nonce: i,
151
151
  version: a,
152
152
  account: m,
@@ -158,78 +158,78 @@ const K = [y], F = (t, n = D) => {
158
158
  appDomain: c
159
159
  // appDomain: "https://starknetkit-blacked-listed.vercel.app", // to simulate blacklisted domain
160
160
  };
161
- }, J = (t, n) => {
162
- const { transactions: e } = t;
163
- if (!e)
161
+ }, X = (t, e) => {
162
+ const { transactions: n } = t;
163
+ if (!n)
164
164
  throw new G({ code: "SIMULATE_AND_REVIEW_FAILED" });
165
- const a = e.map((i) => {
165
+ const a = n.map((i) => {
166
166
  if (!i.simulation)
167
167
  throw new G({ code: "SIMULATE_AND_REVIEW_FAILED" });
168
168
  return i;
169
- }), s = a.map((i) => ({
169
+ }), o = a.map((i) => ({
170
170
  ...i.simulation,
171
171
  feeEstimation: u(i.simulation.feeEstimation, Number)
172
- })), o = S(s, n), [m, c] = a.length === 1 ? [a[0], void 0] : [a[1], a[0]];
172
+ })), s = S(o, e), [m, c] = a.length === 1 ? [a[0], void 0] : [a[1], a[0]];
173
173
  return {
174
- ...o,
174
+ ...s,
175
175
  transactions: {
176
- ...o.transactions,
177
- dataGasConsumed: o.transactions.dataGasConsumed ?? 0n,
178
- dataGasPrice: o.transactions.dataGasPrice ?? 0n,
176
+ ...s.transactions,
177
+ dataGasConsumed: s.transactions.dataGasConsumed ?? 0n,
178
+ dataGasPrice: s.transactions.dataGasPrice ?? 0n,
179
179
  max: d(u(m.simulation.feeEstimation, r.toBigInt))
180
180
  },
181
- deployment: o.deployment && c ? {
182
- ...o.deployment,
183
- dataGasConsumed: o.deployment.dataGasConsumed ?? 0n,
184
- dataGasPrice: o.deployment.dataGasPrice ?? 0n,
181
+ deployment: s.deployment && c ? {
182
+ ...s.deployment,
183
+ dataGasConsumed: s.deployment.dataGasConsumed ?? 0n,
184
+ dataGasPrice: s.deployment.dataGasPrice ?? 0n,
185
185
  max: d(u(c.simulation.feeEstimation, r.toBigInt))
186
186
  } : void 0
187
187
  };
188
- }, Q = (t) => {
189
- const n = F(t), e = P(t);
188
+ }, D = (t) => ({
189
+ max_amount: r.toHex(t.amount),
190
+ max_price_per_unit: r.toHex(t.pricePerUnit)
191
+ }), R = (t, e, n) => ({
192
+ // (overall_fee / gas_price) × gas_safety_margin
193
+ max_amount: r.toHex(t / e),
194
+ // max_price_per_unit: gas_price × fee_safety_margin
195
+ max_price_per_unit: r.toHex(n)
196
+ }), Z = (t) => {
197
+ const e = U(t), n = P(t);
190
198
  return {
191
199
  // for v1 transactions
192
- maxFee: e,
200
+ maxFee: n,
193
201
  // for v3 transactions
194
202
  resourceBounds: {
195
- l1_gas: {
196
- // (overall_fee / gas_price) × gas_safety_margin
197
- max_amount: r.toHex(e / t.pricePerUnit),
198
- // max_price_per_unit: gas_price × fee_safety_margin
199
- max_price_per_unit: r.toHex(n.pricePerUnit)
200
- },
201
- l2_gas: {
202
- max_amount: "0x0",
203
- max_price_per_unit: "0x0"
204
- }
203
+ l1_gas: ((o) => o !== void 0 && "amount" in o && "pricePerUnit" in o)(t.max) ? D(t.max) : R(n, t.pricePerUnit, e.pricePerUnit),
204
+ l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
205
205
  }
206
206
  };
207
- }, X = (t) => {
208
- const n = Math.sqrt(t);
209
- return isNaN(n) ? Math.sqrt(2) : n;
210
- }, D = (t) => {
211
- const n = Math.cbrt(t);
212
- return isNaN(n) ? Math.cbrt(2) : n;
213
- }, Z = (t) => t < 1 || isNaN(t) ? 1.1 : Math.log(t + 1) + 1;
207
+ }, tt = (t) => {
208
+ const e = Math.sqrt(t);
209
+ return isNaN(e) ? Math.sqrt(2) : e;
210
+ }, w = (t) => {
211
+ const e = Math.cbrt(t);
212
+ return isNaN(e) ? Math.cbrt(2) : e;
213
+ }, nt = (t) => t < 1 || isNaN(t) ? 1.1 : Math.log(t + 1) + 1;
214
214
  export {
215
- $ as buildDummyTx,
216
- D as calculateCubeRootAdjustment,
217
- Z as calculateNonLinearAdjustment,
218
- X as calculateSqrtAdjustment,
215
+ J as buildDummyTx,
216
+ w as calculateCubeRootAdjustment,
217
+ nt as calculateNonLinearAdjustment,
218
+ tt as calculateSqrtAdjustment,
219
219
  u as castFeeEstimation,
220
220
  P as estimatedFeeToMaxFeeTotal,
221
- Q as estimatedFeeToMaxResourceBounds,
221
+ Z as estimatedFeeToMaxResourceBounds,
222
222
  p as estimatedFeeToTotal,
223
- Y as estimatedFeesToMaxFeeTotal,
224
- V as estimatedFeesToTotal,
223
+ z as estimatedFeesToMaxFeeTotal,
224
+ $ as estimatedFeesToTotal,
225
225
  S as getEstimatedFeeFromBulkSimulation,
226
- J as getEstimatedFeeFromSimulationAndRespectWatermarkFee,
227
- z as getPayloadFromTransaction,
226
+ X as getEstimatedFeeFromSimulationAndRespectWatermarkFee,
227
+ Q as getPayloadFromTransaction,
228
228
  N as getWatermarkedMaxFeeTotal,
229
229
  k as isFRI,
230
230
  E as isWEI,
231
- O as multiplyBigIntByFloat,
231
+ V as multiplyBigIntByFloat,
232
232
  d as toMax,
233
- K as tokensRequireTxV3Support,
233
+ Y as tokensRequireTxV3Support,
234
234
  x as unitToFeeTokenAddress
235
235
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.56.0",
3
+ "version": "1.56.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"