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