@argent/x-shared 1.42.1 → 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.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/dist/.eslintrc.d.cts +2 -0
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.js +297 -295
  5. package/dist/src/backend/index.d.ts +1 -1
  6. package/dist/src/bigdecimal/index.d.ts +1 -1
  7. package/dist/src/cache/index.d.ts +1 -1
  8. package/dist/src/chains/starknet/services/address/index.d.ts +1 -1
  9. package/dist/src/errors/account.d.ts +1 -1
  10. package/dist/src/errors/address.d.ts +1 -1
  11. package/dist/src/errors/call.d.ts +1 -1
  12. package/dist/src/errors/network.d.ts +1 -1
  13. package/dist/src/errors/review.d.ts +1 -1
  14. package/dist/src/errors/swap.d.ts +1 -1
  15. package/dist/src/features/simulation/activity/schema.cjs +1 -1
  16. package/dist/src/features/simulation/activity/schema.d.ts +346 -334
  17. package/dist/src/features/simulation/activity/schema.js +17 -26
  18. package/dist/src/features/simulation/activity/utils/createNativeActivity.cjs +1 -1
  19. package/dist/src/features/simulation/activity/utils/createNativeActivity.js +23 -23
  20. package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.cjs +1 -1
  21. package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.js +10 -9
  22. package/dist/src/features/simulation/transactionReview/schema.cjs +1 -1
  23. package/dist/src/features/simulation/transactionReview/schema.d.ts +12 -12
  24. package/dist/src/features/simulation/transactionReview/schema.js +2 -2
  25. package/dist/src/features/swap/services/index.d.ts +1 -1
  26. package/dist/src/http/index.d.ts +2 -2
  27. package/dist/src/knownDapps/index.d.ts +1 -1
  28. package/dist/src/nameResolution/index.d.ts +1 -1
  29. package/dist/src/nfts/index.d.ts +1 -1
  30. package/dist/src/onchainRecovery/index.d.ts +1 -1
  31. package/dist/src/staking/schema.cjs +1 -1
  32. package/dist/src/staking/schema.d.ts +88 -505
  33. package/dist/src/staking/schema.js +27 -19
  34. package/dist/src/tokens/index.d.ts +1 -1
  35. package/dist/src/tokens/service/implementation.d.ts +16 -10
  36. package/dist/src/tokens/service/index.d.ts +1 -1
  37. package/dist/src/tokens/service/tokenError.d.ts +1 -1
  38. package/dist/src/tokens/service/types/backend.model.cjs +1 -1
  39. package/dist/src/tokens/service/types/backend.model.d.ts +640 -400
  40. package/dist/src/tokens/service/types/backend.model.js +116 -114
  41. package/dist/src/transactions/estimate/error.d.ts +1 -1
  42. package/dist/src/transactions/estimate/utils.cjs +1 -1
  43. package/dist/src/transactions/estimate/utils.js +30 -27
  44. package/dist/src/transactions/index.d.ts +5 -5
  45. package/dist/src/transactions/service/implementation.cjs +1 -1
  46. package/dist/src/transactions/service/implementation.js +66 -65
  47. package/dist/src/transactions/service/index.d.ts +1 -1
  48. package/package.json +1 -1
@@ -1,132 +1,134 @@
1
- import { z as a } from "zod";
2
- import { addressSchemaArgentBackend as n, addressSchema as t } from "../../../chains/starknet/address.js";
1
+ import { z as t } from "zod";
2
+ import { addressSchemaArgentBackend as o, addressSchema as a } from "../../../chains/starknet/address.js";
3
3
  import { defiPositionTypeSchema as d } from "./defiPositionType.model.js";
4
4
  import { createSchemaWithWarnings as g } from "../../../utils/schemas.js";
5
- const f = a.object({
6
- status: a.literal("initialising")
7
- }).or(a.object({
8
- status: a.literal("initialised"),
9
- balances: a.array(a.object({
10
- tokenAddress: n,
11
- tokenBalance: a.string()
5
+ const f = t.object({
6
+ status: t.literal("initialising")
7
+ }).or(t.object({
8
+ status: t.literal("initialised"),
9
+ balances: t.array(t.object({
10
+ tokenAddress: o,
11
+ tokenBalance: t.string()
12
12
  }))
13
- })), i = a.object({
14
- id: a.number(),
15
- address: t,
16
- brandColor: a.string().optional(),
17
- name: a.string(),
18
- symbol: a.string(),
19
- decimals: a.number(),
20
- iconUrl: a.string().optional(),
21
- sendable: a.boolean(),
22
- popular: a.boolean(),
23
- refundable: a.boolean(),
24
- listed: a.boolean(),
25
- tradable: a.boolean(),
26
- category: a.union([
27
- a.literal("tokens"),
28
- a.literal("currencies"),
29
- a.literal("savings")
13
+ })), i = t.object({
14
+ id: t.number(),
15
+ address: a,
16
+ brandColor: t.string().optional(),
17
+ name: t.string(),
18
+ symbol: t.string(),
19
+ decimals: t.number(),
20
+ iconUrl: t.string().optional(),
21
+ sendable: t.boolean(),
22
+ popular: t.boolean(),
23
+ refundable: t.boolean(),
24
+ listed: t.boolean(),
25
+ tradable: t.boolean(),
26
+ category: t.union([
27
+ t.literal("tokens"),
28
+ t.literal("currencies"),
29
+ t.literal("savings")
30
30
  ]),
31
- pricingId: a.number().optional(),
32
- dappId: a.string().optional(),
33
- marketData: a.object({
34
- marketCap: a.number(),
35
- marketCap24hChange: a.number(),
36
- dailyVolume: a.number(),
37
- rank: a.number()
31
+ pricingId: t.number().optional(),
32
+ dappId: t.string().optional(),
33
+ marketData: t.object({
34
+ marketCap: t.number(),
35
+ marketCap24hChange: t.number(),
36
+ dailyVolume: t.number(),
37
+ rank: t.number()
38
38
  }).optional(),
39
- tags: a.array(a.string()).optional()
40
- }), I = a.object({
41
- tokens: a.array(i)
42
- }), A = i, m = a.object({
43
- pricingId: a.number(),
44
- ethValue: a.string(),
45
- ccyValue: a.string(),
46
- ethDayChange: a.string(),
47
- ccyDayChange: a.string()
48
- }), C = a.object({
49
- prices: a.array(m)
50
- }), o = a.object({
51
- tokenAddress: n,
52
- principal: a.string(),
53
- accruedFees: a.string(),
54
- minPrice: a.string(),
55
- maxPrice: a.string(),
56
- currentPrice: a.string()
57
- }), e = a.object({
58
- id: a.string(),
59
- investmentId: a.string().optional(),
60
- tokenAddress: t.optional(),
61
- totalBalances: a.record(a.string())
39
+ tags: t.array(t.string()).optional()
40
+ }), I = t.object({
41
+ tokens: t.array(i)
42
+ }), A = i, m = t.object({
43
+ pricingId: t.number(),
44
+ ethValue: t.string(),
45
+ ccyValue: t.string(),
46
+ ethDayChange: t.string(),
47
+ ccyDayChange: t.string()
48
+ }), C = t.object({
49
+ prices: t.array(m)
50
+ }), n = t.object({
51
+ tokenAddress: o,
52
+ principal: t.string(),
53
+ accruedFees: t.string(),
54
+ minPrice: t.string(),
55
+ maxPrice: t.string(),
56
+ currentPrice: t.string()
57
+ }), e = t.object({
58
+ id: t.string(),
59
+ investmentId: t.string().optional(),
60
+ tokenAddress: a.optional(),
61
+ totalBalances: t.record(t.string())
62
62
  }), r = e.extend({
63
- tokenId: a.string(),
64
- data: a.object({
65
- poolFeePercentage: a.string(),
66
- tickSpacingPercentage: a.string().optional(),
67
- token0: o,
68
- token1: o
63
+ tokenId: t.string(),
64
+ data: t.object({
65
+ poolFeePercentage: t.string(),
66
+ tickSpacingPercentage: t.string().optional(),
67
+ token0: n,
68
+ token1: n
69
69
  })
70
- }), T = a.array(r), s = e.extend({
71
- data: a.object({
72
- apy: a.string()
70
+ }), T = t.array(r), s = e.extend({
71
+ data: t.object({
72
+ apy: t.string()
73
73
  }),
74
- investmentId: a.string().optional(),
75
- totalBalances: a.record(a.string())
76
- }), x = a.array(s), c = e.extend({
77
- data: a.object({
78
- apy: a.string().optional(),
79
- group: a.number().optional(),
80
- collateral: a.boolean(),
81
- debt: a.boolean(),
82
- lending: a.boolean()
74
+ investmentId: t.string().optional(),
75
+ totalBalances: t.record(t.string())
76
+ }), x = t.array(s), c = e.extend({
77
+ data: t.object({
78
+ apy: t.string().optional(),
79
+ group: t.number().optional(),
80
+ collateral: t.boolean(),
81
+ debt: t.boolean(),
82
+ lending: t.boolean()
83
83
  })
84
- }), B = a.array(c), l = e.extend({
85
- id: a.string(),
86
- data: a.object({
87
- delegatingTo: t
84
+ }), B = t.array(c), l = e.extend({
85
+ id: t.string(),
86
+ data: t.object({
87
+ delegatingTo: a
88
88
  }),
89
- totalBalances: a.record(a.string())
90
- }), R = a.array(l), p = e.extend({
91
- data: a.object({
92
- stakerInfo: a.object({
93
- name: a.string().optional(),
94
- iconUrl: a.string().optional(),
95
- address: t
89
+ totalBalances: t.record(t.string())
90
+ }), R = t.array(l), p = e.extend({
91
+ investmentId: t.string(),
92
+ data: t.object({
93
+ stakerInfo: t.object({
94
+ name: t.string().optional(),
95
+ iconUrl: t.string().optional(),
96
+ address: a
96
97
  }),
97
- accruedRewards: a.string(),
98
- pendingWithdrawal: a.object({
99
- amount: a.string(),
100
- withdrawableAfter: a.number()
98
+ accruedRewards: t.string(),
99
+ stakedAmount: t.string(),
100
+ pendingWithdrawal: t.object({
101
+ amount: t.string(),
102
+ withdrawableAfter: t.number()
101
103
  }).optional(),
102
- apy: a.string().optional()
104
+ apy: t.string().optional()
103
105
  })
104
- }), w = a.array(p), b = r.or(c).or(l).or(s).or(p), h = a.array(b), u = g({
105
- productId: a.string().optional(),
106
- name: a.string(),
107
- manageUrl: a.string(),
106
+ }), w = t.array(p), b = r.or(c).or(l).or(s).or(p), h = t.array(b), u = g({
107
+ productId: t.string().optional(),
108
+ name: t.string(),
109
+ manageUrl: t.string(),
108
110
  type: d,
109
- groups: a.record(a.object({
110
- name: a.string().optional(),
111
- healthRatio: a.string().optional()
111
+ groups: t.record(t.object({
112
+ name: t.string().optional(),
113
+ healthRatio: t.string().optional()
112
114
  })).optional(),
113
115
  positions: h
114
- }), S = a.object({
115
- dappId: a.string(),
116
- products: a.array(u)
117
- }), U = a.object({
118
- dapps: a.array(S)
119
- }), k = a.object({
120
- name: a.string().optional(),
121
- tokenAddress: t,
122
- amount: a.string().optional(),
123
- claimUrl: a.string().optional(),
124
- claimStart: a.number(),
125
- claimEnd: a.number().optional()
126
- }), v = a.object({
127
- accountAddress: t,
128
- chain: a.string(),
129
- airdrops: a.array(k)
116
+ }), S = t.object({
117
+ dappId: t.string(),
118
+ products: t.array(u)
119
+ }), U = t.object({
120
+ dapps: t.array(S)
121
+ }), k = t.object({
122
+ name: t.string().optional(),
123
+ tokenAddress: a,
124
+ amount: t.string().optional(),
125
+ claimUrl: t.string().optional(),
126
+ claimStart: t.number(),
127
+ claimEnd: t.number().optional()
128
+ }), v = t.object({
129
+ accountAddress: a,
130
+ chain: t.string(),
131
+ airdrops: t.array(k)
130
132
  });
131
133
  export {
132
134
  f as apiAccountTokenBalancesSchema,
@@ -138,7 +140,7 @@ export {
138
140
  u as apiDefiDecompositionProduct,
139
141
  h as apiDefiDecompositionProducts,
140
142
  S as apiDefiDecompositionSchema,
141
- o as apiDefiDecompositionToken,
143
+ n as apiDefiDecompositionToken,
142
144
  b as apiDefiPositionSchema,
143
145
  U as apiDefiPositionsSchema,
144
146
  R as apiDelegatedTokensArraySchema,
@@ -1,4 +1,4 @@
1
- import { BaseError, BaseErrorPayload } from '../../errors/baseErrors';
1
+ import { BaseErrorPayload, BaseError } from '../../errors/baseErrors';
2
2
  export declare enum ESTIMATE_ERROR_MESSAGES {
3
3
  SIMULATE_AND_REVIEW_FAILED = "Missing simulation"
4
4
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("lodash-es"),r=require("starknet"),E=require("../../chains/starknet/address.cjs"),x=require("../../chains/starknet/constants.cjs"),h=require("./argentMaxFee.cjs"),M=require("./error.cjs"),S=require("../../utils/starknet/starknet.cjs"),F=require("../../features/simulation/transactionReview/schema.cjs"),k=require("../../utils/arrays.cjs");function P(e){return y.upperCase(e.unit)==="WEI"}function A(e){return y.upperCase(e.unit)==="FRI"}function c(e,n){return P(e)?{...e,maxFee:n(e.maxFee),overallFee:n(e.overallFee),gasPrice:n(e.gasPrice),gasUsage:n(e.gasUsage)}:{...e,overallFee:n(e.overallFee),gasPrice:n(e.gasPrice),gasUsage:n(e.gasUsage),maxAmount:n(e.maxAmount),maxPricePerUnit:n(e.maxPricePerUnit)}}function d(e){return P(e)?{maxFee:e.maxFee}:{amount:e.maxAmount,pricePerUnit:e.maxPricePerUnit}}function p(e){return A({unit:e})?x.STRK_TOKEN_ADDRESS:x.ETH_TOKEN_ADDRESS}function _(e,n,t=2){const a=BigInt(10**t),s=BigInt(Math.round(n*10**t));return e*s/a}const N=[x.STRK_TOKEN_ADDRESS],G=(e,n=C)=>{if(e.max&&"amount"in e.max)return{...e,...e.max};const t=10000n,{amount:a,pricePerUnit:s,dataGasConsumed:o=0n,dataGasPrice:m=0n}=e,u=a*s+o*m;if(u<0)throw Error("Cannot calculate max fee for negative fee");const i=r.num.toBigInt(h.argentMaxFee({estimatedFee:u})),f=Number(i)/Number(u),U=n(f),g=BigInt(Math.trunc(U*Number(t)));return{...e,amount:a*g/t,pricePerUnit:s*g/t,dataGasConsumed:o*g/t,dataGasPrice:m*g/t}},l=e=>{const{amount:n,pricePerUnit:t,dataGasConsumed:a=0n,dataGasPrice:s=0n}=e;return n*t+a*s},I=e=>{if(e.max)return"maxFee"in e.max?e.max.maxFee:l(e.max)},T=e=>{const n=I(e);return n||l(G(e))},R=e=>{if(e.deployment&&!E.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=l(e.transactions),t=e.deployment?l(e.deployment):0n;return n+t},q=e=>{if(e.deployment&&!E.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=e.deployment?T(e.deployment):0n,t=T(e.transactions);return n+t},D=(e,n)=>[{contractAddress:e,entrypoint:"transfer",calldata:r.CallData.compile(S.transferCalldataSchema.parse({recipient:n,amount:r.uint256.bnToUint256(BigInt(1))}))}],B=(e,n)=>{if(!e)return{transactions:{feeTokenAddress:n??x.ETH_TOKEN_ADDRESS,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!Array.isArray(e))throw Error(`Unexpected simulation response. Expected array. Got ${typeof e}`);if(e.length===1){const t=F.feeEstimationSchema.parse(e[0].feeEstimation);return{transactions:{feeTokenAddress:p(t.unit),amount:r.num.toBigInt(t.gasUsage),pricePerUnit:r.num.toBigInt(t.gasPrice),max:d(c(t,r.num.toBigInt)),dataGasConsumed:t.dataGasConsumed?r.num.toBigInt(t.dataGasConsumed):0n,dataGasPrice:t.dataGasPrice?r.num.toBigInt(t.dataGasPrice):0n}}}if(e.length===2){const t=F.feeEstimationSchema.parse(e[0].feeEstimation),a=F.feeEstimationSchema.parse(e[1].feeEstimation);return{deployment:{feeTokenAddress:p(t.unit),amount:r.num.toBigInt(t.gasUsage),pricePerUnit:r.num.toBigInt(t.gasPrice),max:d(c(t,r.num.toBigInt)),dataGasConsumed:t.dataGasConsumed?r.num.toBigInt(t.dataGasConsumed):0n,dataGasPrice:t.dataGasPrice?r.num.toBigInt(t.dataGasPrice):0n},transactions:{feeTokenAddress:p(a.unit),amount:r.num.toBigInt(a.gasUsage),pricePerUnit:r.num.toBigInt(a.gasPrice),max:d(c(a,r.num.toBigInt)),dataGasConsumed:a.dataGasConsumed?r.num.toBigInt(a.dataGasConsumed):0n,dataGasPrice:a.dataGasPrice?r.num.toBigInt(a.dataGasPrice):0n}}}throw Error("Unexpected simulation response length")},b=({transaction:e,nonce:n,chainId:t,version:a,isDeploymentTransaction:s,cairoVersion:o,address:m,appDomain:u})=>{let i=n;s&&e.type!=="DEPLOY_ACCOUNT"&&(i=r.num.toHex(1));const f=k.ensureArray(e.calls);return{type:e.type,chainId:t,cairoVersion:o,nonce:i,version:a,account:m,calls:f,calldata:e.calldata,salt:e.salt,signature:e.signature,classHash:e.classHash,appDomain:u}},j=(e,n)=>{const{transactions:t}=e,a=t.map(i=>{if(!i.simulation)throw new M.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});return i}),s=a.map(i=>({...i.simulation,feeEstimation:c(i.simulation.feeEstimation,Number)})),o=B(s,n),[m,u]=a.length===1?[a[0],void 0]:[a[1],a[0]];return{...o,transactions:{...o.transactions,dataGasConsumed:o.transactions.dataGasConsumed??0n,dataGasPrice:o.transactions.dataGasPrice??0n,max:d(c(m.simulation.feeEstimation,r.num.toBigInt))},deployment:o.deployment&&u?{...o.deployment,dataGasConsumed:o.deployment.dataGasConsumed??0n,dataGasPrice:o.deployment.dataGasPrice??0n,max:d(c(u.simulation.feeEstimation,r.num.toBigInt))}:void 0}},w=e=>{const n=G(e),t=T(e);return{maxFee:t,resourceBounds:{l1_gas:{max_amount:r.num.toHex(t/e.pricePerUnit),max_price_per_unit:r.num.toHex(n.pricePerUnit)},l2_gas:{max_amount:"0x0",max_price_per_unit:"0x0"}}}},O=e=>{const n=Math.sqrt(e);return isNaN(n)?Math.sqrt(2):n},C=e=>{const n=Math.cbrt(e);return isNaN(n)?Math.cbrt(2):n},W=e=>e<1||isNaN(e)?1.1:Math.log(e+1)+1;exports.buildDummyTx=D;exports.calculateCubeRootAdjustment=C;exports.calculateNonLinearAdjustment=W;exports.calculateSqrtAdjustment=O;exports.castFeeEstimation=c;exports.estimatedFeeToMaxFeeTotal=T;exports.estimatedFeeToMaxResourceBounds=w;exports.estimatedFeeToTotal=l;exports.estimatedFeesToMaxFeeTotal=q;exports.estimatedFeesToTotal=R;exports.getEstimatedFeeFromBulkSimulation=B;exports.getEstimatedFeeFromSimulationAndRespectWatermarkFee=j;exports.getPayloadFromTransaction=b;exports.getWatermarkedMaxFeeTotal=I;exports.isFRI=A;exports.isWEI=P;exports.multiplyBigIntByFloat=_;exports.toMax=d;exports.tokensRequireTxV3Support=N;exports.unitToFeeTokenAddress=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("lodash-es"),r=require("starknet"),y=require("../../chains/starknet/address.cjs"),x=require("../../chains/starknet/constants.cjs"),M=require("./argentMaxFee.cjs"),E=require("./error.cjs"),S=require("../../utils/starknet/starknet.cjs"),F=require("../../features/simulation/transactionReview/schema.cjs"),_=require("../../utils/arrays.cjs");function P(e){return A.upperCase(e.unit)==="WEI"}function I(e){return A.upperCase(e.unit)==="FRI"}function u(e,n){return P(e)?{...e,maxFee:n(e.maxFee),overallFee:n(e.overallFee),gasPrice:n(e.gasPrice),gasUsage:n(e.gasUsage)}:{...e,overallFee:n(e.overallFee),gasPrice:n(e.gasPrice),gasUsage:n(e.gasUsage),maxAmount:n(e.maxAmount),maxPricePerUnit:n(e.maxPricePerUnit)}}function d(e){return P(e)?{maxFee:e.maxFee}:{amount:e.maxAmount,pricePerUnit:e.maxPricePerUnit}}function p(e){return I({unit:e})?x.STRK_TOKEN_ADDRESS:x.ETH_TOKEN_ADDRESS}function k(e,n,t=2){const a=BigInt(10**t),s=BigInt(Math.round(n*10**t));return e*s/a}const N=[x.STRK_TOKEN_ADDRESS],G=(e,n=U)=>{if(e.max&&"amount"in e.max)return{...e,...e.max};const t=10000n,{amount:a,pricePerUnit:s,dataGasConsumed:o=0n,dataGasPrice:m=0n}=e,c=a*s+o*m;if(c<0)throw Error("Cannot calculate max fee for negative fee");const i=r.num.toBigInt(M.argentMaxFee({estimatedFee:c})),f=Number(i)/Number(c),h=n(f),g=BigInt(Math.trunc(h*Number(t)));return{...e,amount:a*g/t,pricePerUnit:s*g/t,dataGasConsumed:o*g/t,dataGasPrice:m*g/t}},l=e=>{const{amount:n,pricePerUnit:t,dataGasConsumed:a=0n,dataGasPrice:s=0n}=e;return n*t+a*s},B=e=>{if(e.max)return"maxFee"in e.max?e.max.maxFee:l(e.max)},T=e=>{const n=B(e);return n||l(G(e))},R=e=>{if(e.deployment&&!y.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=l(e.transactions),t=e.deployment?l(e.deployment):0n;return n+t},q=e=>{if(e.deployment&&!y.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const n=e.deployment?T(e.deployment):0n,t=T(e.transactions);return n+t},D=(e,n)=>[{contractAddress:e,entrypoint:"transfer",calldata:r.CallData.compile(S.transferCalldataSchema.parse({recipient:n,amount:r.uint256.bnToUint256(BigInt(1))}))}],C=(e,n)=>{if(!e)return{transactions:{feeTokenAddress:n??x.ETH_TOKEN_ADDRESS,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!Array.isArray(e))throw Error(`Unexpected simulation response. Expected array. Got ${typeof e}`);if(e.length===1){const t=F.feeEstimationSchema.parse(e[0].feeEstimation);return{transactions:{feeTokenAddress:p(t.unit),amount:r.num.toBigInt(t.gasUsage),pricePerUnit:r.num.toBigInt(t.gasPrice),max:d(u(t,r.num.toBigInt)),dataGasConsumed:t.dataGasConsumed?r.num.toBigInt(t.dataGasConsumed):0n,dataGasPrice:t.dataGasPrice?r.num.toBigInt(t.dataGasPrice):0n}}}if(e.length===2){const t=F.feeEstimationSchema.parse(e[0].feeEstimation),a=F.feeEstimationSchema.parse(e[1].feeEstimation);return{deployment:{feeTokenAddress:p(t.unit),amount:r.num.toBigInt(t.gasUsage),pricePerUnit:r.num.toBigInt(t.gasPrice),max:d(u(t,r.num.toBigInt)),dataGasConsumed:t.dataGasConsumed?r.num.toBigInt(t.dataGasConsumed):0n,dataGasPrice:t.dataGasPrice?r.num.toBigInt(t.dataGasPrice):0n},transactions:{feeTokenAddress:p(a.unit),amount:r.num.toBigInt(a.gasUsage),pricePerUnit:r.num.toBigInt(a.gasPrice),max:d(u(a,r.num.toBigInt)),dataGasConsumed:a.dataGasConsumed?r.num.toBigInt(a.dataGasConsumed):0n,dataGasPrice:a.dataGasPrice?r.num.toBigInt(a.dataGasPrice):0n}}}throw Error("Unexpected simulation response length")},b=({transaction:e,nonce:n,chainId:t,version:a,isDeploymentTransaction:s,cairoVersion:o,address:m,appDomain:c})=>{let i=n;s&&e.type!=="DEPLOY_ACCOUNT"&&(i=r.num.toHex(1));const f=_.ensureArray(e.calls);return{type:e.type,chainId:t,cairoVersion:o,nonce:i,version:a,account:m,calls:f,calldata:e.calldata,salt:e.salt,signature:e.signature,classHash:e.classHash,appDomain:c}},j=(e,n)=>{const{transactions:t}=e;if(!t)throw new E.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});const a=t.map(i=>{if(!i.simulation)throw new E.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});return i}),s=a.map(i=>({...i.simulation,feeEstimation:u(i.simulation.feeEstimation,Number)})),o=C(s,n),[m,c]=a.length===1?[a[0],void 0]:[a[1],a[0]];return{...o,transactions:{...o.transactions,dataGasConsumed:o.transactions.dataGasConsumed??0n,dataGasPrice:o.transactions.dataGasPrice??0n,max:d(u(m.simulation.feeEstimation,r.num.toBigInt))},deployment:o.deployment&&c?{...o.deployment,dataGasConsumed:o.deployment.dataGasConsumed??0n,dataGasPrice:o.deployment.dataGasPrice??0n,max:d(u(c.simulation.feeEstimation,r.num.toBigInt))}:void 0}},w=e=>{const n=G(e),t=T(e);return{maxFee:t,resourceBounds:{l1_gas:{max_amount:r.num.toHex(t/e.pricePerUnit),max_price_per_unit:r.num.toHex(n.pricePerUnit)},l2_gas:{max_amount:"0x0",max_price_per_unit:"0x0"}}}},W=e=>{const n=Math.sqrt(e);return isNaN(n)?Math.sqrt(2):n},U=e=>{const n=Math.cbrt(e);return isNaN(n)?Math.cbrt(2):n},O=e=>e<1||isNaN(e)?1.1:Math.log(e+1)+1;exports.buildDummyTx=D;exports.calculateCubeRootAdjustment=U;exports.calculateNonLinearAdjustment=O;exports.calculateSqrtAdjustment=W;exports.castFeeEstimation=u;exports.estimatedFeeToMaxFeeTotal=T;exports.estimatedFeeToMaxResourceBounds=w;exports.estimatedFeeToTotal=l;exports.estimatedFeesToMaxFeeTotal=q;exports.estimatedFeesToTotal=R;exports.getEstimatedFeeFromBulkSimulation=C;exports.getEstimatedFeeFromSimulationAndRespectWatermarkFee=j;exports.getPayloadFromTransaction=b;exports.getWatermarkedMaxFeeTotal=B;exports.isFRI=I;exports.isWEI=P;exports.multiplyBigIntByFloat=k;exports.toMax=d;exports.tokensRequireTxV3Support=N;exports.unitToFeeTokenAddress=p;
@@ -1,20 +1,20 @@
1
- import { upperCase as G } from "lodash-es";
2
- import { CallData as F, uint256 as U, num as r } from "starknet";
3
- import { isEqualAddress as T } from "../../chains/starknet/address.js";
4
- import { STRK_TOKEN_ADDRESS as y, ETH_TOKEN_ADDRESS as I } from "../../chains/starknet/constants.js";
5
- import { argentMaxFee as E } from "./argentMaxFee.js";
6
- import { EstimateError as h } from "./error.js";
1
+ import { upperCase as T } from "lodash-es";
2
+ import { CallData as C, uint256 as U, num as r } from "starknet";
3
+ import { isEqualAddress as I } from "../../chains/starknet/address.js";
4
+ import { STRK_TOKEN_ADDRESS as y, ETH_TOKEN_ADDRESS as A } from "../../chains/starknet/constants.js";
5
+ import { argentMaxFee as h } from "./argentMaxFee.js";
6
+ import { EstimateError as G } from "./error.js";
7
7
  import { transferCalldataSchema as _ } from "../../utils/starknet/starknet.js";
8
8
  import { feeEstimationSchema as f } from "../../features/simulation/transactionReview/schema.js";
9
9
  import { ensureArray as M } from "../../utils/arrays.js";
10
- function A(t) {
11
- return G(t.unit) === "WEI";
10
+ function E(t) {
11
+ return T(t.unit) === "WEI";
12
12
  }
13
13
  function k(t) {
14
- return G(t.unit) === "FRI";
14
+ return T(t.unit) === "FRI";
15
15
  }
16
16
  function u(t, n) {
17
- return A(t) ? {
17
+ return E(t) ? {
18
18
  ...t,
19
19
  maxFee: n(t.maxFee),
20
20
  overallFee: n(t.overallFee),
@@ -30,7 +30,7 @@ function u(t, n) {
30
30
  };
31
31
  }
32
32
  function d(t) {
33
- return A(t) ? {
33
+ return E(t) ? {
34
34
  maxFee: t.maxFee
35
35
  } : {
36
36
  amount: t.maxAmount,
@@ -38,13 +38,13 @@ function d(t) {
38
38
  };
39
39
  }
40
40
  function x(t) {
41
- return k({ unit: t }) ? y : I;
41
+ return k({ unit: t }) ? y : A;
42
42
  }
43
- function L(t, n, e = 2) {
43
+ function O(t, n, e = 2) {
44
44
  const a = BigInt(10 ** e), s = BigInt(Math.round(n * 10 ** e));
45
45
  return t * s / a;
46
46
  }
47
- const K = [y], B = (t, n = R) => {
47
+ const K = [y], F = (t, n = D) => {
48
48
  if (t.max && "amount" in t.max)
49
49
  return {
50
50
  ...t,
@@ -53,7 +53,7 @@ const K = [y], B = (t, n = R) => {
53
53
  const e = 10000n, { amount: a, pricePerUnit: s, dataGasConsumed: o = 0n, dataGasPrice: m = 0n } = t, c = a * s + o * m;
54
54
  if (c < 0)
55
55
  throw Error("Cannot calculate max fee for negative fee");
56
- const i = r.toBigInt(E({ estimatedFee: c })), g = Number(i) / Number(c), C = n(g), l = BigInt(Math.trunc(C * Number(e)));
56
+ const i = r.toBigInt(h({ estimatedFee: c })), g = Number(i) / Number(c), B = n(g), l = BigInt(Math.trunc(B * Number(e)));
57
57
  return {
58
58
  ...t,
59
59
  amount: a * l / e,
@@ -69,14 +69,14 @@ const K = [y], B = (t, n = R) => {
69
69
  return "maxFee" in t.max ? t.max.maxFee : p(t.max);
70
70
  }, P = (t) => {
71
71
  const n = N(t);
72
- return n || p(B(t));
72
+ return n || p(F(t));
73
73
  }, V = (t) => {
74
- if (t.deployment && !T(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
74
+ if (t.deployment && !I(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
75
75
  throw Error("Cannot calculate estimated fees for different tokens");
76
76
  const n = p(t.transactions), e = t.deployment ? p(t.deployment) : 0n;
77
77
  return n + e;
78
78
  }, Y = (t) => {
79
- if (t.deployment && !T(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
79
+ if (t.deployment && !I(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
80
80
  throw Error("Cannot calculate estimated fees for different tokens");
81
81
  const n = t.deployment ? P(t.deployment) : 0n, e = P(t.transactions);
82
82
  return n + e;
@@ -84,7 +84,7 @@ const K = [y], B = (t, n = R) => {
84
84
  {
85
85
  contractAddress: t,
86
86
  entrypoint: "transfer",
87
- calldata: F.compile(_.parse({
87
+ calldata: C.compile(_.parse({
88
88
  // We are using a dummy address (ETH here) as recipient to estimate the fee given we don't have a receipient yet
89
89
  recipient: n,
90
90
  // We are using the smallest possible amount to make sure this doesn't throw an error
@@ -95,7 +95,7 @@ const K = [y], B = (t, n = R) => {
95
95
  if (!t)
96
96
  return {
97
97
  transactions: {
98
- feeTokenAddress: n ?? I,
98
+ feeTokenAddress: n ?? A,
99
99
  amount: 0n,
100
100
  pricePerUnit: 0n,
101
101
  dataGasConsumed: 0n,
@@ -159,9 +159,12 @@ const K = [y], B = (t, n = R) => {
159
159
  // appDomain: "https://starknetkit-blacked-listed.vercel.app", // to simulate blacklisted domain
160
160
  };
161
161
  }, J = (t, n) => {
162
- const { transactions: e } = t, a = e.map((i) => {
162
+ const { transactions: e } = t;
163
+ if (!e)
164
+ throw new G({ code: "SIMULATE_AND_REVIEW_FAILED" });
165
+ const a = e.map((i) => {
163
166
  if (!i.simulation)
164
- throw new h({ code: "SIMULATE_AND_REVIEW_FAILED" });
167
+ throw new G({ code: "SIMULATE_AND_REVIEW_FAILED" });
165
168
  return i;
166
169
  }), s = a.map((i) => ({
167
170
  ...i.simulation,
@@ -183,7 +186,7 @@ const K = [y], B = (t, n = R) => {
183
186
  } : void 0
184
187
  };
185
188
  }, Q = (t) => {
186
- const n = B(t), e = P(t);
189
+ const n = F(t), e = P(t);
187
190
  return {
188
191
  // for v1 transactions
189
192
  maxFee: e,
@@ -204,13 +207,13 @@ const K = [y], B = (t, n = R) => {
204
207
  }, X = (t) => {
205
208
  const n = Math.sqrt(t);
206
209
  return isNaN(n) ? Math.sqrt(2) : n;
207
- }, R = (t) => {
210
+ }, D = (t) => {
208
211
  const n = Math.cbrt(t);
209
212
  return isNaN(n) ? Math.cbrt(2) : n;
210
213
  }, Z = (t) => t < 1 || isNaN(t) ? 1.1 : Math.log(t + 1) + 1;
211
214
  export {
212
215
  $ as buildDummyTx,
213
- R as calculateCubeRootAdjustment,
216
+ D as calculateCubeRootAdjustment,
214
217
  Z as calculateNonLinearAdjustment,
215
218
  X as calculateSqrtAdjustment,
216
219
  u as castFeeEstimation,
@@ -224,8 +227,8 @@ export {
224
227
  z as getPayloadFromTransaction,
225
228
  N as getWatermarkedMaxFeeTotal,
226
229
  k as isFRI,
227
- A as isWEI,
228
- L as multiplyBigIntByFloat,
230
+ E as isWEI,
231
+ O as multiplyBigIntByFloat,
229
232
  d as toMax,
230
233
  K as tokensRequireTxV3Support,
231
234
  x as unitToFeeTokenAddress
@@ -1,16 +1,16 @@
1
- export * from './aggregatedSimDataTypes';
1
+ export type * from './aggregatedSimDataTypes';
2
2
  export * from './amount';
3
3
  export * from './buildTransactions';
4
- export * from './deployAccountTypes';
4
+ export type * from './deployAccountTypes';
5
5
  export * from './errors';
6
6
  export * from './estimate';
7
7
  export * from './findTransfersAndApprovals';
8
8
  export * from './getPrettyRcpError';
9
9
  export * from './getTransactionVersion';
10
10
  export * from './service';
11
- export * from './transactionAction';
11
+ export type * from './transactionAction';
12
12
  export * from './transactionReviewTypes';
13
- export * from './transactionSimulationTypes';
13
+ export type * from './transactionSimulationTypes';
14
14
  export * from './transactionVersion';
15
15
  export * from './txv3';
16
- export * from './types';
16
+ export type * from './types';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("starknet"),h=require("url-join"),m=require("../../errors/review.cjs"),w=require("../getTransactionVersion.cjs"),E=require("../estimate/utils.cjs"),T=require("../../utils/url/urlWithQuery.cjs"),y=require("../../features/simulation/transactionReview/schema.cjs"),S=require("../../utils/arrays.cjs");class I{constructor(e,a){this.apiBase=e,this.httpService=a}async getLabels(){const e=h(this.apiBase,"reviewer","labels");return await this.httpService.get(e)}async getWarnings(){const e=h(this.apiBase,"reviewer","warnings/reasons");return await this.httpService.get(e)}async simulateAndReview(e,a,c,o,l,s){const r=a.some(i=>i.type==="DEPLOY_ACCOUNT");try{if(!("getChainId"in e))throw new Error("MISSING_METHOD");const i=w.getTxVersionFromFeeToken(c),t=r?"0x0":await e.getNonce(),n=await e.getChainId(),d={transactions:a.map(g=>({...E.getPayloadFromTransaction({transaction:g,nonce:t,version:i,chainId:n,isDeploymentTransaction:r,appDomain:o,cairoVersion:e.cairoVersion,address:e.address}),type:g.type}))},p=h(this.apiBase,"reviewer","transactions","v2","review","starknet"),F=s?T.urlWithQuery(p,{delayedTransactions:"true"}):p,u=await this.httpService.post(F,{headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(d)},y.simulateAndReviewSchema);if(u.transactions.some(g=>y.isTransactionSimulationError(g)))return u;const v=E.getEstimatedFeeFromSimulationAndRespectWatermarkFee(u,c);return{...u,enrichedFeeEstimation:v}}catch(i){return console.error(i),this.fallbackToOnchainFeeEstimation({transactions:a,account:e,isDeploymentTransaction:r,feeTokenAddress:c,accountDeployTransaction:l})}}getCallsFromTx(e){let a;return e.calls&&(a=S.ensureArray(e.calls)),a}async fallbackToOnchainFeeEstimation({transactions:e,account:a,isDeploymentTransaction:c,feeTokenAddress:o,accountDeployTransaction:l}){try{const s=c?this.getCallsFromTx(e[1]):this.getCallsFromTx(e[0]);if(!s)throw new m.ReviewError({code:"NO_CALLS_FOUND"});const r=await this.fetchFeesOnchain({starknetAccount:a,calls:s,isDeployed:!c,feeTokenAddress:o,accountDeployTransaction:l});return{transactions:[],enrichedFeeEstimation:r,isBackendDown:!0}}catch(s){throw console.error(s),new m.ReviewError({message:`${s}`,code:"SIMULATE_AND_REVIEW_FAILED"})}}async fetchFeesOnchain({starknetAccount:e,calls:a,isDeployed:c,feeTokenAddress:o,accountDeployTransaction:l}){try{const s=w.getTxVersionFromFeeToken(o),r={transactions:{feeTokenAddress:o,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!c&&l){if("estimateFeeBulk"in e){const i=[{type:_.TransactionType.DEPLOY_ACCOUNT,payload:{classHash:l.classHash,addressSalt:l.salt,constructorCalldata:l.calldata,contractAddress:e.address}},{type:_.TransactionType.INVOKE,payload:a}],[t,n]=await e.estimateFeeBulk(i,{version:s}).catch(d=>{throw console.error(d),d});if(!t.gas_consumed||!t.gas_price||!n.gas_consumed||!n.gas_price)throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});r.deployment={feeTokenAddress:o,amount:t.gas_consumed,pricePerUnit:t.gas_price,dataGasConsumed:t.data_gas_consumed,dataGasPrice:t.data_gas_price},r.transactions={feeTokenAddress:o,amount:n.gas_consumed,pricePerUnit:n.gas_price,dataGasConsumed:n.data_gas_consumed,dataGasPrice:n.data_gas_price}}}else{const{gas_consumed:i,gas_price:t,data_gas_consumed:n,data_gas_price:d}=await e.estimateFee(a,{skipValidate:!0,version:s});if(!i||!t)throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});r.transactions={feeTokenAddress:o,amount:i,pricePerUnit:t,dataGasConsumed:n,dataGasPrice:d}}return r}catch(s){throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:`${s}`})}}}exports.TransactionReviewServiceWeb=I;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("starknet"),h=require("url-join"),m=require("../../errors/review.cjs"),w=require("../getTransactionVersion.cjs"),E=require("../estimate/utils.cjs"),S=require("../../utils/url/urlWithQuery.cjs"),y=require("../../features/simulation/transactionReview/schema.cjs"),I=require("../../utils/arrays.cjs");class C{constructor(e,a){this.apiBase=e,this.httpService=a}async getLabels(){const e=h(this.apiBase,"reviewer","labels");return await this.httpService.get(e)}async getWarnings(){const e=h(this.apiBase,"reviewer","warnings/reasons");return await this.httpService.get(e)}async simulateAndReview(e,a,o,n,c,t){var l;const r=a.some(s=>s.type==="DEPLOY_ACCOUNT");try{if(!("getChainId"in e))throw new Error("MISSING_METHOD");const s=w.getTxVersionFromFeeToken(o),i=r?"0x0":await e.getNonce(),d=await e.getChainId(),F={transactions:a.map(g=>({...E.getPayloadFromTransaction({transaction:g,nonce:i,version:s,chainId:d,isDeploymentTransaction:r,appDomain:n,cairoVersion:e.cairoVersion,address:e.address}),type:g.type}))},p=h(this.apiBase,"reviewer","transactions","v2","review","starknet"),v=t?S.urlWithQuery(p,{delayedTransactions:"true"}):p,u=await this.httpService.post(v,{headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(F)},y.simulateAndReviewSchema);if((l=u.transactions)==null?void 0:l.some(g=>y.isTransactionSimulationError(g)))return u;const T=E.getEstimatedFeeFromSimulationAndRespectWatermarkFee(u,o);return{...u,enrichedFeeEstimation:T}}catch(s){return console.error(s),this.fallbackToOnchainFeeEstimation({transactions:a,account:e,isDeploymentTransaction:r,feeTokenAddress:o,accountDeployTransaction:c})}}getCallsFromTx(e){let a;return e.calls&&(a=I.ensureArray(e.calls)),a}async fallbackToOnchainFeeEstimation({transactions:e,account:a,isDeploymentTransaction:o,feeTokenAddress:n,accountDeployTransaction:c}){try{const t=o?this.getCallsFromTx(e[1]):this.getCallsFromTx(e[0]);if(!t)throw new m.ReviewError({code:"NO_CALLS_FOUND"});const r=await this.fetchFeesOnchain({starknetAccount:a,calls:t,isDeployed:!o,feeTokenAddress:n,accountDeployTransaction:c});return{transactions:[],enrichedFeeEstimation:r,isBackendDown:!0}}catch(t){throw console.error(t),new m.ReviewError({message:`${t}`,code:"SIMULATE_AND_REVIEW_FAILED"})}}async fetchFeesOnchain({starknetAccount:e,calls:a,isDeployed:o,feeTokenAddress:n,accountDeployTransaction:c}){try{const t=w.getTxVersionFromFeeToken(n),r={transactions:{feeTokenAddress:n,amount:0n,pricePerUnit:0n,dataGasConsumed:0n,dataGasPrice:0n}};if(!o&&c){if("estimateFeeBulk"in e){const l=[{type:_.TransactionType.DEPLOY_ACCOUNT,payload:{classHash:c.classHash,addressSalt:c.salt,constructorCalldata:c.calldata,contractAddress:e.address}},{type:_.TransactionType.INVOKE,payload:a}],[s,i]=await e.estimateFeeBulk(l,{version:t}).catch(d=>{throw console.error(d),d});if(!s.gas_consumed||!s.gas_price||!i.gas_consumed||!i.gas_price)throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});r.deployment={feeTokenAddress:n,amount:s.gas_consumed,pricePerUnit:s.gas_price,dataGasConsumed:s.data_gas_consumed,dataGasPrice:s.data_gas_price},r.transactions={feeTokenAddress:n,amount:i.gas_consumed,pricePerUnit:i.gas_price,dataGasConsumed:i.data_gas_consumed,dataGasPrice:i.data_gas_price}}}else{const{gas_consumed:l,gas_price:s,data_gas_consumed:i,data_gas_price:d}=await e.estimateFee(a,{skipValidate:!0,version:t});if(!l||!s)throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:"Missing gas_consumed or gas_price"});r.transactions={feeTokenAddress:n,amount:l,pricePerUnit:s,dataGasConsumed:i,dataGasPrice:d}}return r}catch(t){throw new m.ReviewError({code:"ONCHAIN_FEE_ESTIMATION_FAILED",message:`${t}`})}}}exports.TransactionReviewServiceWeb=C;