@argent/x-shared 1.60.0 → 1.62.0
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 +185 -180
- package/dist/paymaster.cjs +1 -0
- package/dist/paymaster.d.ts +2 -0
- package/dist/paymaster.js +8 -0
- package/dist/src/features/paymaster/IPaymasterService.d.ts +6 -0
- package/dist/src/features/paymaster/PaymasterService.cjs +1 -0
- package/dist/src/features/paymaster/PaymasterService.d.ts +12 -0
- package/dist/src/features/paymaster/PaymasterService.js +60 -0
- package/dist/src/features/paymaster/index.d.ts +3 -0
- package/dist/src/features/paymaster/types.cjs +1 -0
- package/dist/src/features/paymaster/types.d.ts +151 -0
- package/dist/src/features/paymaster/types.js +25 -0
- package/dist/src/transactions/estimate/utilsV2.cjs +1 -1
- package/dist/src/transactions/estimate/utilsV2.d.ts +16 -4
- package/dist/src/transactions/estimate/utilsV2.js +86 -75
- package/dist/src/transactions/getTransactionVersion.js +1 -1
- package/dist/src/utils/starknet/starknet.cjs +1 -1
- package/dist/src/utils/starknet/starknet.d.ts +71 -0
- package/dist/src/utils/starknet/starknet.js +45 -24
- package/package.json +6 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PaymasterService as r } from "./src/features/paymaster/PaymasterService.js";
|
|
2
|
+
import { paymasterExecuteParams as m, paymasterExecuteResponse as s, paymasterExecutionDataParams as o } from "./src/features/paymaster/types.js";
|
|
3
|
+
export {
|
|
4
|
+
r as PaymasterService,
|
|
5
|
+
m as paymasterExecuteParams,
|
|
6
|
+
s as paymasterExecuteResponse,
|
|
7
|
+
o as paymasterExecutionDataParams
|
|
8
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TypedData } from 'starknet';
|
|
2
|
+
import { PaymasterExecutionDataParams, PaymasterExecuteParams } from './types';
|
|
3
|
+
export interface IPaymasterService {
|
|
4
|
+
getExecutionData(params: PaymasterExecutionDataParams, useAvnu?: boolean): Promise<TypedData>;
|
|
5
|
+
execute(params: PaymasterExecuteParams, useAvnu?: boolean): Promise<string>;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("starknet"),l=require("url-join"),u=require("./types.cjs"),p=require("../../utils/starknet/starknet.cjs");class y{constructor(e="",t){this.argentRelayerUrl=e,this.httpService=t}async getExecutionData(e,t=!1){const r=l(t?this.getAvnuUrl(e.networkId):this.argentRelayerUrl,"/build-typed-data"),n={calls:t?e.calls.map(o=>({contractAddress:s.num.toHex(o.contractAddress),calldata:s.CallData.toCalldata(o.calldata).map(d=>s.num.toHex(d)),entrypoint:o.entrypoint})):e.calls,userAddress:e.accountAddress,gasTokenAddress:s.num.toHex(e.feeTokenAddress),maxGasTokenAmount:s.num.toHex(e.maxFee),accountClassHash:e.accountClassHash},a=await this.httpService.post(r,{body:s.json.stringify(n),headers:{"Content-Type":"application/json"}}),c=p.typedDataSchema.safeParse(a);if(!c.success)throw new Error("Invalid response from paymaster");return c.data}getAvnuUrl(e){if(!e)throw new Error("Network id is required for Avnu paymaster");let t="";if(e==="mainnet"||e==="mainnet-alpha")t="starknet";else if(e==="sepolia"||e==="sepolia-alpha")t="sepolia";else throw new Error("Invalid network id");return`https://${t}.api.avnu.fi/paymaster/v1`}async execute(e,t=!1){const r=l(t?this.getAvnuUrl(e.networkId):this.argentRelayerUrl,"/execute"),i={signature:e.signature,userAddress:e.accountAddress,typedData:t?s.json.stringify(e.typedData):e.typedData},n=await this.httpService.post(r,{body:s.json.stringify(i),headers:{"Content-Type":"application/json"}}),a=u.paymasterExecuteResponse.safeParse(n);if(!a.success)throw new Error("Invalid response from paymaster");return a.data.transactionHash}}exports.PaymasterService=y;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TypedData } from '@starknet-io/types-js';
|
|
2
|
+
import { IHttpService } from '../../http';
|
|
3
|
+
import { IPaymasterService } from './IPaymasterService';
|
|
4
|
+
import { PaymasterExecuteParams, PaymasterExecutionDataParams } from './types';
|
|
5
|
+
export declare class PaymasterService implements IPaymasterService {
|
|
6
|
+
private readonly argentRelayerUrl;
|
|
7
|
+
private readonly httpService;
|
|
8
|
+
constructor(argentRelayerUrl: string | undefined, httpService: IHttpService);
|
|
9
|
+
getExecutionData(params: PaymasterExecutionDataParams, useAvnu?: boolean): Promise<TypedData>;
|
|
10
|
+
getAvnuUrl(networkId?: string): string;
|
|
11
|
+
execute(params: PaymasterExecuteParams, useAvnu?: boolean): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { CallData as y, num as a, json as i } from "starknet";
|
|
2
|
+
import d from "url-join";
|
|
3
|
+
import { paymasterExecuteResponse as u } from "./types.js";
|
|
4
|
+
import { typedDataSchema as h } from "../../utils/starknet/starknet.js";
|
|
5
|
+
class A {
|
|
6
|
+
constructor(e = "", t) {
|
|
7
|
+
this.argentRelayerUrl = e, this.httpService = t;
|
|
8
|
+
}
|
|
9
|
+
async getExecutionData(e, t = !1) {
|
|
10
|
+
const r = d(t ? this.getAvnuUrl(e.networkId) : this.argentRelayerUrl, "/build-typed-data"), o = {
|
|
11
|
+
calls: t ? e.calls.map((n) => ({
|
|
12
|
+
contractAddress: a.toHex(n.contractAddress),
|
|
13
|
+
calldata: y.toCalldata(n.calldata).map((p) => a.toHex(p)),
|
|
14
|
+
entrypoint: n.entrypoint
|
|
15
|
+
})) : e.calls,
|
|
16
|
+
userAddress: e.accountAddress,
|
|
17
|
+
gasTokenAddress: a.toHex(e.feeTokenAddress),
|
|
18
|
+
maxGasTokenAmount: a.toHex(e.maxFee),
|
|
19
|
+
accountClassHash: e.accountClassHash
|
|
20
|
+
}, s = await this.httpService.post(r, {
|
|
21
|
+
body: i.stringify(o),
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json"
|
|
24
|
+
}
|
|
25
|
+
}), l = h.safeParse(s);
|
|
26
|
+
if (!l.success)
|
|
27
|
+
throw new Error("Invalid response from paymaster");
|
|
28
|
+
return l.data;
|
|
29
|
+
}
|
|
30
|
+
getAvnuUrl(e) {
|
|
31
|
+
if (!e)
|
|
32
|
+
throw new Error("Network id is required for Avnu paymaster");
|
|
33
|
+
let t = "";
|
|
34
|
+
if (e === "mainnet" || e === "mainnet-alpha")
|
|
35
|
+
t = "starknet";
|
|
36
|
+
else if (e === "sepolia" || e === "sepolia-alpha")
|
|
37
|
+
t = "sepolia";
|
|
38
|
+
else
|
|
39
|
+
throw new Error("Invalid network id");
|
|
40
|
+
return `https://${t}.api.avnu.fi/paymaster/v1`;
|
|
41
|
+
}
|
|
42
|
+
async execute(e, t = !1) {
|
|
43
|
+
const r = d(t ? this.getAvnuUrl(e.networkId) : this.argentRelayerUrl, "/execute"), c = {
|
|
44
|
+
signature: e.signature,
|
|
45
|
+
userAddress: e.accountAddress,
|
|
46
|
+
typedData: t ? i.stringify(e.typedData) : e.typedData
|
|
47
|
+
}, o = await this.httpService.post(r, {
|
|
48
|
+
body: i.stringify(c),
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "application/json"
|
|
51
|
+
}
|
|
52
|
+
}), s = u.safeParse(o);
|
|
53
|
+
if (!s.success)
|
|
54
|
+
throw new Error("Invalid response from paymaster");
|
|
55
|
+
return s.data.transactionHash;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
A as PaymasterService
|
|
60
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("zod"),a=require("../../utils/starknet/starknet.cjs"),t=require("../../backend/schema.cjs"),s=require("../../chains/starknet/address.cjs"),r=e.z.object({calls:e.z.array(a.callSchema),accountAddress:s.addressSchema,networkId:t.argentNetworkIdSchema.or(t.argentBackendNetworkIdSchema).optional(),feeTokenAddress:s.addressSchema,maxFee:a.bigNumberishSchema,accountClassHash:e.z.string().optional()}),c=e.z.object({signature:e.z.string().array(),accountAddress:s.addressSchema,typedData:a.typedDataSchema,networkId:t.argentNetworkIdSchema.optional()}),o=e.z.object({transactionHash:e.z.string()});exports.paymasterExecuteParams=c;exports.paymasterExecuteResponse=o;exports.paymasterExecutionDataParams=r;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const paymasterExecutionDataParams: z.ZodObject<{
|
|
3
|
+
calls: z.ZodArray<z.ZodType<import('starknet').Call, z.ZodTypeDef, import('starknet').Call>, "many">;
|
|
4
|
+
accountAddress: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
5
|
+
networkId: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["mainnet-alpha", "sepolia-alpha"]>, z.ZodEnum<["mainnet", "sepolia"]>]>>;
|
|
6
|
+
feeTokenAddress: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
7
|
+
maxFee: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBigInt]>;
|
|
8
|
+
accountClassHash: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
accountAddress: `0x${string}`;
|
|
11
|
+
calls: import('starknet').Call[];
|
|
12
|
+
maxFee: string | number | bigint;
|
|
13
|
+
feeTokenAddress: `0x${string}`;
|
|
14
|
+
accountClassHash?: string | undefined;
|
|
15
|
+
networkId?: "mainnet-alpha" | "sepolia-alpha" | "mainnet" | "sepolia" | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
accountAddress: string;
|
|
18
|
+
calls: import('starknet').Call[];
|
|
19
|
+
maxFee: string | number | bigint;
|
|
20
|
+
feeTokenAddress: string;
|
|
21
|
+
accountClassHash?: string | undefined;
|
|
22
|
+
networkId?: "mainnet-alpha" | "sepolia-alpha" | "mainnet" | "sepolia" | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
export type PaymasterExecutionDataParams = z.infer<typeof paymasterExecutionDataParams>;
|
|
25
|
+
export declare const paymasterExecuteParams: z.ZodObject<{
|
|
26
|
+
signature: z.ZodArray<z.ZodString, "many">;
|
|
27
|
+
accountAddress: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
28
|
+
typedData: z.ZodObject<{
|
|
29
|
+
types: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
30
|
+
name: z.ZodString;
|
|
31
|
+
type: z.ZodLiteral<"merkletree">;
|
|
32
|
+
contains: z.ZodString;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
name: string;
|
|
35
|
+
type: "merkletree";
|
|
36
|
+
contains: string;
|
|
37
|
+
}, {
|
|
38
|
+
name: string;
|
|
39
|
+
type: "merkletree";
|
|
40
|
+
contains: string;
|
|
41
|
+
}>, z.ZodObject<{
|
|
42
|
+
name: z.ZodString;
|
|
43
|
+
type: z.ZodLiteral<"enum">;
|
|
44
|
+
contains: z.ZodString;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
name: string;
|
|
47
|
+
type: "enum";
|
|
48
|
+
contains: string;
|
|
49
|
+
}, {
|
|
50
|
+
name: string;
|
|
51
|
+
type: "enum";
|
|
52
|
+
contains: string;
|
|
53
|
+
}>, z.ZodObject<{
|
|
54
|
+
name: z.ZodString;
|
|
55
|
+
type: z.ZodString;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
name: string;
|
|
58
|
+
type: string;
|
|
59
|
+
}, {
|
|
60
|
+
name: string;
|
|
61
|
+
type: string;
|
|
62
|
+
}>]>, "many">>;
|
|
63
|
+
primaryType: z.ZodString;
|
|
64
|
+
domain: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
65
|
+
message: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
message: {};
|
|
68
|
+
types: Record<string, ({
|
|
69
|
+
name: string;
|
|
70
|
+
type: "merkletree";
|
|
71
|
+
contains: string;
|
|
72
|
+
} | {
|
|
73
|
+
name: string;
|
|
74
|
+
type: "enum";
|
|
75
|
+
contains: string;
|
|
76
|
+
} | {
|
|
77
|
+
name: string;
|
|
78
|
+
type: string;
|
|
79
|
+
})[]>;
|
|
80
|
+
primaryType: string;
|
|
81
|
+
domain: Record<string, unknown>;
|
|
82
|
+
}, {
|
|
83
|
+
message: {};
|
|
84
|
+
types: Record<string, ({
|
|
85
|
+
name: string;
|
|
86
|
+
type: "merkletree";
|
|
87
|
+
contains: string;
|
|
88
|
+
} | {
|
|
89
|
+
name: string;
|
|
90
|
+
type: "enum";
|
|
91
|
+
contains: string;
|
|
92
|
+
} | {
|
|
93
|
+
name: string;
|
|
94
|
+
type: string;
|
|
95
|
+
})[]>;
|
|
96
|
+
primaryType: string;
|
|
97
|
+
domain: Record<string, unknown>;
|
|
98
|
+
}>;
|
|
99
|
+
networkId: z.ZodOptional<z.ZodEnum<["mainnet-alpha", "sepolia-alpha"]>>;
|
|
100
|
+
}, "strip", z.ZodTypeAny, {
|
|
101
|
+
signature: string[];
|
|
102
|
+
accountAddress: `0x${string}`;
|
|
103
|
+
typedData: {
|
|
104
|
+
message: {};
|
|
105
|
+
types: Record<string, ({
|
|
106
|
+
name: string;
|
|
107
|
+
type: "merkletree";
|
|
108
|
+
contains: string;
|
|
109
|
+
} | {
|
|
110
|
+
name: string;
|
|
111
|
+
type: "enum";
|
|
112
|
+
contains: string;
|
|
113
|
+
} | {
|
|
114
|
+
name: string;
|
|
115
|
+
type: string;
|
|
116
|
+
})[]>;
|
|
117
|
+
primaryType: string;
|
|
118
|
+
domain: Record<string, unknown>;
|
|
119
|
+
};
|
|
120
|
+
networkId?: "mainnet-alpha" | "sepolia-alpha" | undefined;
|
|
121
|
+
}, {
|
|
122
|
+
signature: string[];
|
|
123
|
+
accountAddress: string;
|
|
124
|
+
typedData: {
|
|
125
|
+
message: {};
|
|
126
|
+
types: Record<string, ({
|
|
127
|
+
name: string;
|
|
128
|
+
type: "merkletree";
|
|
129
|
+
contains: string;
|
|
130
|
+
} | {
|
|
131
|
+
name: string;
|
|
132
|
+
type: "enum";
|
|
133
|
+
contains: string;
|
|
134
|
+
} | {
|
|
135
|
+
name: string;
|
|
136
|
+
type: string;
|
|
137
|
+
})[]>;
|
|
138
|
+
primaryType: string;
|
|
139
|
+
domain: Record<string, unknown>;
|
|
140
|
+
};
|
|
141
|
+
networkId?: "mainnet-alpha" | "sepolia-alpha" | undefined;
|
|
142
|
+
}>;
|
|
143
|
+
export type PaymasterExecuteParams = z.infer<typeof paymasterExecuteParams>;
|
|
144
|
+
export declare const paymasterExecuteResponse: z.ZodObject<{
|
|
145
|
+
transactionHash: z.ZodString;
|
|
146
|
+
}, "strip", z.ZodTypeAny, {
|
|
147
|
+
transactionHash: string;
|
|
148
|
+
}, {
|
|
149
|
+
transactionHash: string;
|
|
150
|
+
}>;
|
|
151
|
+
export type PaymasterExecuteResponse = z.infer<typeof paymasterExecuteResponse>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z as a } from "zod";
|
|
2
|
+
import { bigNumberishSchema as r, callSchema as o, typedDataSchema as s } from "../../utils/starknet/starknet.js";
|
|
3
|
+
import { argentNetworkIdSchema as t, argentBackendNetworkIdSchema as c } from "../../backend/schema.js";
|
|
4
|
+
import { addressSchema as e } from "../../chains/starknet/address.js";
|
|
5
|
+
const p = a.object({
|
|
6
|
+
calls: a.array(o),
|
|
7
|
+
accountAddress: e,
|
|
8
|
+
networkId: t.or(c).optional(),
|
|
9
|
+
feeTokenAddress: e,
|
|
10
|
+
maxFee: r,
|
|
11
|
+
accountClassHash: a.string().optional()
|
|
12
|
+
}), h = a.object({
|
|
13
|
+
signature: a.string().array(),
|
|
14
|
+
accountAddress: e,
|
|
15
|
+
typedData: s,
|
|
16
|
+
networkId: t.optional()
|
|
17
|
+
// deploymentData: z.object() // TODO: Implement account deployment
|
|
18
|
+
}), l = a.object({
|
|
19
|
+
transactionHash: a.string()
|
|
20
|
+
});
|
|
21
|
+
export {
|
|
22
|
+
h as paymasterExecuteParams,
|
|
23
|
+
l as paymasterExecuteResponse,
|
|
24
|
+
p as paymasterExecutionDataParams
|
|
25
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("lodash-es"),o=require("starknet"),N=require("../getTransactionVersion.cjs"),F=require("./error.cjs"),r=require("./utils.cjs"),u=require("../../chains/starknet/constants.cjs"),E=require("../../chains/starknet/address.cjs"),h=e=>{const{transactions:t}=e;if(!t)throw new F.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});if(!Array.isArray(t))throw Error(`Unexpected simulation response. Expected array. Got ${typeof t}`);if(l.isEmpty(t))return[];if(t.length>2)throw Error(`Unexpected simulation response length. Got ${t.length}`);const n=t.map(m=>{if(!m.simulation)throw new F.EstimateError({code:"SIMULATE_AND_REVIEW_FAILED"});return{...m.simulation,...I(m.simulation.feeEstimations)}}),[a,s]=n.length===1?[n[0],void 0]:[n[1],n[0]],i=y(a,s),f=p(a,s);return[...i,...f]},I=e=>{const[t,n]=l.partition(e,a=>"unit"in a&&(a.unit==="FRI"||a.unit==="WEI"));return{nativeFeeEstimations:t,paymasterFeeEstimations:n}},p=(e,t)=>{if(!e)return[];if(!t)return e.paymasterFeeEstimations.map(s=>({type:"paymaster",transactions:c(s),deployment:void 0}));const n=t.paymasterFeeEstimations,a=e.paymasterFeeEstimations;if(n.length!==a.length)throw Error("Deployment and transaction fee estimations length mismatch");return a.map((s,i)=>({type:"paymaster",transactions:c(s),deployment:c(n[i])}))},y=(e,t)=>{if(!e)return[];if(!t)return e.nativeFeeEstimations.map(s=>({type:"native",transactions:d(s),deployment:void 0}));const n=t.nativeFeeEstimations,a=e.nativeFeeEstimations;if(n.length!==a.length)throw Error("Deployment and transaction fee estimations length mismatch");return a.map((s,i)=>({type:"native",transactions:d(s),deployment:d(n[i])}))},c=e=>({feeTokenAddress:e.token.address,maxFee:BigInt(e.maxFee),overallFee:BigInt(e.overallFee)}),d=e=>({amount:o.num.toBigInt(e.gasUsage),feeTokenAddress:r.unitToFeeTokenAddress(e.unit),pricePerUnit:o.num.toBigInt(e.gasPrice),dataGasConsumed:o.num.toBigInt(e.dataGasConsumed??0),dataGasPrice:o.num.toBigInt(e.dataGasPrice??0),max:r.toMax(r.castFeeEstimation(e,o.num.toBigInt))}),S=e=>{var a;if(e.type==="paymaster")return e.transactions.maxFee+(((a=e.deployment)==null?void 0:a.maxFee)??0n);if(e.deployment&&!E.isEqualAddress(e.deployment.feeTokenAddress,e.transactions.feeTokenAddress))throw Error("Cannot calculate estimated fees for different tokens");const t=e.deployment?r.estimatedFeeToMaxFeeTotal(e.deployment):0n,n=r.estimatedFeeToMaxFeeTotal(e.transactions);return t+n},V=e=>{var t;return e.type==="paymaster"?e.transactions.overallFee+(((t=e.deployment)==null?void 0:t.overallFee)??0n):r.estimatedFeesToTotal(e)},g=(e=[])=>e.filter(n=>n.type==="native"),x=e=>e.filter(t=>t.type==="paymaster"),T=e=>e===o.constants.TRANSACTION_VERSION.V1||e===o.constants.TRANSACTION_VERSION.F1?u.ETH_TOKEN_ADDRESS:u.STRK_TOKEN_ADDRESS,v=(e=[],t)=>{const n=g(e).find(a=>E.isEqualAddress(a.transactions.feeTokenAddress,t));if(!n)throw Error(`No native estimated fee found for ${t}`);return n},A=(e=[],t)=>{const n=T(t);return v(e,n)},_=(e=[],t)=>A(e,N.getAccountTxVersion(t));exports.estimatedFeesToMaxFeeTotalV2=S;exports.estimatedFeesToTotalV2=V;exports.filterPaymasterEstimatedFees=x;exports.getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2=h;exports.getNativeEstimatedFeeByFeeToken=v;exports.getNativeEstimatedFeeByTxVersion=A;exports.getNativeEstimatedFeeForAccount=_;exports.getNativeEstimatedFees=g;exports.getNativeFeeFromSimulation=y;exports.getNativeFeeTokenAddress=T;exports.getPaymasterFeeFromSimulation=p;
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { Address } from '../../chains';
|
|
2
|
-
import { PaymasterFeeEstimation, SimulateAndReview } from '../../features/simulation';
|
|
2
|
+
import { PaymasterFeeEstimation, FeeEstimation, SimulateAndReview } from '../../features/simulation';
|
|
3
3
|
import { EstimatedFeesV2, NativeEstimatedFees, PaymasterEstimatedFees } from '../../features/simulation/fees/schema';
|
|
4
4
|
import { StrictOmit } from '../../utils/type.utils';
|
|
5
5
|
import { TransactionVersion } from '../transactionVersion';
|
|
6
6
|
export declare const getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2: (simulateAndReviewResult: Pick<SimulateAndReview, "transactions">) => EstimatedFeesV2[];
|
|
7
|
-
export declare const getPaymasterFeeFromSimulation: (
|
|
7
|
+
export declare const getPaymasterFeeFromSimulation: (invokeTransaction: {
|
|
8
8
|
paymasterFeeEstimations: PaymasterFeeEstimation[];
|
|
9
|
-
}
|
|
9
|
+
}, deployTransactionOrUndefined?: {
|
|
10
|
+
paymasterFeeEstimations: PaymasterFeeEstimation[];
|
|
11
|
+
} | undefined) => EstimatedFeesV2[];
|
|
12
|
+
export declare const getNativeFeeFromSimulation: (invokeTransaction: {
|
|
13
|
+
nativeFeeEstimations: FeeEstimation[];
|
|
14
|
+
}, deployTransactionOrUndefined?: {
|
|
15
|
+
nativeFeeEstimations: FeeEstimation[];
|
|
16
|
+
} | undefined) => EstimatedFeesV2[];
|
|
10
17
|
export declare const estimatedFeesToMaxFeeTotalV2: (estimatedFees: EstimatedFeesV2) => bigint;
|
|
11
18
|
export declare const estimatedFeesToTotalV2: (estimatedFees: EstimatedFeesV2) => bigint;
|
|
12
|
-
export declare const getNativeEstimatedFees: (estimatedFees?: EstimatedFeesV2[]) => NativeEstimatedFees;
|
|
19
|
+
export declare const getNativeEstimatedFees: (estimatedFees?: EstimatedFeesV2[]) => NativeEstimatedFees[];
|
|
13
20
|
export declare const filterPaymasterEstimatedFees: (estimatedFees: EstimatedFeesV2[]) => StrictOmit<PaymasterEstimatedFees, "type">[];
|
|
14
21
|
export declare const getNativeFeeTokenAddress: (transactionVersion: TransactionVersion) => Address;
|
|
22
|
+
export declare const getNativeEstimatedFeeByFeeToken: (estimatedFees: EstimatedFeesV2[] | undefined, feeTokenAddress: string) => NativeEstimatedFees;
|
|
23
|
+
export declare const getNativeEstimatedFeeByTxVersion: (estimatedFees: EstimatedFeesV2[] | undefined, transactionVersion: TransactionVersion) => NativeEstimatedFees;
|
|
24
|
+
export declare const getNativeEstimatedFeeForAccount: (estimatedFees: EstimatedFeesV2[] | undefined, account: {
|
|
25
|
+
classHash: string;
|
|
26
|
+
}) => NativeEstimatedFees;
|
|
@@ -1,96 +1,107 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { num as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { isEmpty as u, partition as y } from "lodash-es";
|
|
2
|
+
import { num as s, constants as p } from "starknet";
|
|
3
|
+
import { getAccountTxVersion as f } from "../getTransactionVersion.js";
|
|
4
|
+
import { EstimateError as d } from "./error.js";
|
|
5
|
+
import { toMax as g, castFeeEstimation as T, unitToFeeTokenAddress as A, estimatedFeeToMaxFeeTotal as E, estimatedFeesToTotal as v } from "./utils.js";
|
|
6
|
+
import { ETH_TOKEN_ADDRESS as h, STRK_TOKEN_ADDRESS as I } from "../../chains/starknet/constants.js";
|
|
7
|
+
import { isEqualAddress as l } from "../../chains/starknet/address.js";
|
|
7
8
|
const O = (t) => {
|
|
8
9
|
const { transactions: e } = t;
|
|
9
10
|
if (!e)
|
|
10
|
-
throw new
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
throw new d({ code: "SIMULATE_AND_REVIEW_FAILED" });
|
|
12
|
+
if (!Array.isArray(e))
|
|
13
|
+
throw Error(`Unexpected simulation response. Expected array. Got ${typeof e}`);
|
|
14
|
+
if (u(e))
|
|
15
|
+
return [];
|
|
16
|
+
if (e.length > 2)
|
|
17
|
+
throw Error(`Unexpected simulation response length. Got ${e.length}`);
|
|
18
|
+
const n = e.map((i) => {
|
|
19
|
+
if (!i.simulation)
|
|
20
|
+
throw new d({ code: "SIMULATE_AND_REVIEW_FAILED" });
|
|
15
21
|
return {
|
|
16
|
-
...
|
|
17
|
-
|
|
18
|
-
paymasterFeeEstimations: f
|
|
22
|
+
...i.simulation,
|
|
23
|
+
...N(i.simulation.feeEstimations)
|
|
19
24
|
};
|
|
20
|
-
}),
|
|
21
|
-
return [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
..._(n)
|
|
28
|
-
];
|
|
29
|
-
}, d = (t, e) => ({
|
|
30
|
-
...t,
|
|
31
|
-
dataGasConsumed: t.dataGasConsumed ?? 0n,
|
|
32
|
-
dataGasPrice: t.dataGasPrice ?? 0n,
|
|
33
|
-
max: v(g(e.feeEstimation, T.toBigInt))
|
|
34
|
-
}), S = (t) => {
|
|
35
|
-
const [e, n] = u(t, (a) => "unit" in a && (a.unit === "FRI" || a.unit === "WEI"));
|
|
36
|
-
return {
|
|
37
|
-
nativeFeeEstimation: e[0],
|
|
38
|
-
paymasterFeeEstimations: n
|
|
39
|
-
};
|
|
40
|
-
}, _ = (t) => {
|
|
25
|
+
}), [o, a] = n.length === 1 ? [n[0], void 0] : [n[1], n[0]], r = _(o, a), F = S(o, a);
|
|
26
|
+
return [...r, ...F];
|
|
27
|
+
}, N = (t) => {
|
|
28
|
+
const [e, n] = y(t, (o) => "unit" in o && (o.unit === "FRI" || o.unit === "WEI"));
|
|
29
|
+
return { nativeFeeEstimations: e, paymasterFeeEstimations: n };
|
|
30
|
+
}, S = (t, e) => {
|
|
41
31
|
if (!t)
|
|
42
32
|
return [];
|
|
43
|
-
if (!
|
|
44
|
-
|
|
45
|
-
if (t.length === 1)
|
|
46
|
-
return t[0].paymasterFeeEstimations.map((e) => ({
|
|
33
|
+
if (!e)
|
|
34
|
+
return t.paymasterFeeEstimations.map((a) => ({
|
|
47
35
|
type: "paymaster",
|
|
48
|
-
transactions:
|
|
36
|
+
transactions: m(a),
|
|
49
37
|
deployment: void 0
|
|
50
38
|
}));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
39
|
+
const n = e.paymasterFeeEstimations, o = t.paymasterFeeEstimations;
|
|
40
|
+
if (n.length !== o.length)
|
|
41
|
+
throw Error("Deployment and transaction fee estimations length mismatch");
|
|
42
|
+
return o.map((a, r) => ({
|
|
43
|
+
type: "paymaster",
|
|
44
|
+
transactions: m(a),
|
|
45
|
+
deployment: m(n[r])
|
|
46
|
+
}));
|
|
47
|
+
}, _ = (t, e) => {
|
|
48
|
+
if (!t)
|
|
49
|
+
return [];
|
|
50
|
+
if (!e)
|
|
51
|
+
return t.nativeFeeEstimations.map((a) => ({
|
|
52
|
+
type: "native",
|
|
53
|
+
transactions: c(a),
|
|
54
|
+
deployment: void 0
|
|
59
55
|
}));
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
const n = e.nativeFeeEstimations, o = t.nativeFeeEstimations;
|
|
57
|
+
if (n.length !== o.length)
|
|
58
|
+
throw Error("Deployment and transaction fee estimations length mismatch");
|
|
59
|
+
return o.map((a, r) => ({
|
|
60
|
+
type: "native",
|
|
61
|
+
transactions: c(a),
|
|
62
|
+
deployment: c(n[r])
|
|
63
|
+
}));
|
|
64
|
+
}, m = (t) => ({
|
|
63
65
|
feeTokenAddress: t.token.address,
|
|
64
66
|
maxFee: BigInt(t.maxFee),
|
|
65
67
|
overallFee: BigInt(t.overallFee)
|
|
66
|
-
}),
|
|
67
|
-
|
|
68
|
+
}), c = (t) => ({
|
|
69
|
+
amount: s.toBigInt(t.gasUsage),
|
|
70
|
+
feeTokenAddress: A(t.unit),
|
|
71
|
+
pricePerUnit: s.toBigInt(t.gasPrice),
|
|
72
|
+
dataGasConsumed: s.toBigInt(t.dataGasConsumed ?? 0),
|
|
73
|
+
dataGasPrice: s.toBigInt(t.dataGasPrice ?? 0),
|
|
74
|
+
max: g(T(t, s.toBigInt))
|
|
75
|
+
}), U = (t) => {
|
|
76
|
+
var o;
|
|
68
77
|
if (t.type === "paymaster")
|
|
69
|
-
return t.transactions.maxFee + (((
|
|
70
|
-
if (t.deployment && !
|
|
78
|
+
return t.transactions.maxFee + (((o = t.deployment) == null ? void 0 : o.maxFee) ?? 0n);
|
|
79
|
+
if (t.deployment && !l(t.deployment.feeTokenAddress, t.transactions.feeTokenAddress))
|
|
71
80
|
throw Error("Cannot calculate estimated fees for different tokens");
|
|
72
|
-
const e = t.deployment ?
|
|
81
|
+
const e = t.deployment ? E(t.deployment) : 0n, n = E(t.transactions);
|
|
73
82
|
return e + n;
|
|
74
|
-
},
|
|
83
|
+
}, L = (t) => {
|
|
75
84
|
var e;
|
|
76
|
-
return t.type === "paymaster" ? t.transactions.overallFee + (((e = t.deployment) == null ? void 0 : e.overallFee) ?? 0n) :
|
|
77
|
-
},
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
}, G = (t) => t.filter((e) => e.type === "paymaster"), M = (t) => t === m.TRANSACTION_VERSION.V1 || t === m.TRANSACTION_VERSION.F1 ? h : E;
|
|
85
|
+
return t.type === "paymaster" ? t.transactions.overallFee + (((e = t.deployment) == null ? void 0 : e.overallFee) ?? 0n) : v(t);
|
|
86
|
+
}, x = (t = []) => t.filter((n) => n.type === "native"), W = (t) => t.filter((e) => e.type === "paymaster"), R = (t) => t === p.TRANSACTION_VERSION.V1 || t === p.TRANSACTION_VERSION.F1 ? h : I, V = (t = [], e) => {
|
|
87
|
+
const n = x(t).find((o) => l(o.transactions.feeTokenAddress, e));
|
|
88
|
+
if (!n)
|
|
89
|
+
throw Error(`No native estimated fee found for ${e}`);
|
|
90
|
+
return n;
|
|
91
|
+
}, w = (t = [], e) => {
|
|
92
|
+
const n = R(e);
|
|
93
|
+
return V(t, n);
|
|
94
|
+
}, K = (t = [], e) => w(t, f(e));
|
|
88
95
|
export {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
U as estimatedFeesToMaxFeeTotalV2,
|
|
97
|
+
L as estimatedFeesToTotalV2,
|
|
98
|
+
W as filterPaymasterEstimatedFees,
|
|
92
99
|
O as getEstimatedFeeFromSimulationAndRespectWatermarkFeeV2,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
V as getNativeEstimatedFeeByFeeToken,
|
|
101
|
+
w as getNativeEstimatedFeeByTxVersion,
|
|
102
|
+
K as getNativeEstimatedFeeForAccount,
|
|
103
|
+
x as getNativeEstimatedFees,
|
|
104
|
+
_ as getNativeFeeFromSimulation,
|
|
105
|
+
R as getNativeFeeTokenAddress,
|
|
106
|
+
S as getPaymasterFeeFromSimulation
|
|
96
107
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { constants as r, isSierra as T } from "starknet";
|
|
2
|
-
import {
|
|
2
|
+
import { classHashSupportsTxV3 as n, feeTokenNeedsTxV3Support as t } from "./txv3.js";
|
|
3
3
|
function S(e) {
|
|
4
4
|
return t({
|
|
5
5
|
address: e
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("zod"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("zod"),h=require("../../chains/starknet/address.cjs"),t=a.z.union([a.z.string(),a.z.number(),a.z.bigint()]),l=a.z.object({low:t,high:t}),o=a.z.array(a.z.string()).and(a.z.object({__compiled__:a.z.boolean().optional()}).optional()),s=a.z.lazy(()=>a.z.array(a.z.union([r,a.z.array(r),c]))),r=a.z.union([t,l,a.z.any(),a.z.boolean()]),i=a.z.lazy(()=>a.z.record(a.z.union([r,a.z.array(r),c]))),c=a.z.lazy(()=>a.z.union([i,s])),z=a.z.union([c,o]).optional(),m=a.z.lazy(()=>a.z.object({contractAddress:a.z.string(),calldata:z,entrypoint:a.z.string().optional()})),d=a.z.lazy(()=>m.and(a.z.object({entrypoint:a.z.string()}))),e=a.z.string().refine(n=>typeof parseInt(n)=="number"),S=a.z.tuple([e]),g=a.z.tuple([e]),u=a.z.object({new_threshold:a.z.string().refine(n=>typeof parseInt(n)=="number"),signers_to_add:a.z.array(e)}),p=a.z.object({new_threshold:a.z.string().refine(n=>typeof parseInt(n)=="number"),signers_to_remove:a.z.array(e)}),y=a.z.object({signer_to_remove:e,signer_to_add:e}),b=a.z.tuple([e]),C=a.z.tuple([e]),j=a.z.tuple([e]),w=a.z.tuple([e]).rest(e),_=a.z.object({recipient:h.addressSchema,amount:a.z.object({low:t,high:t})}),f=a.z.object({types:a.z.record(a.z.array(a.z.union([a.z.object({name:a.z.string(),type:a.z.literal("merkletree"),contains:a.z.string()}),a.z.object({name:a.z.string(),type:a.z.literal("enum"),contains:a.z.string()}),a.z.object({name:a.z.string(),type:a.z.string()})]))),primaryType:a.z.string(),domain:a.z.record(a.z.unknown()),message:a.z.object({})});exports.addOwnersCalldataSchema=u;exports.addPluginCalldataSchema=C;exports.bigNumberishSchema=t;exports.callDetailsSchema=m;exports.callSchema=d;exports.calldataSchema=o;exports.changeGuardianCalldataSchema=S;exports.changeThresholdCalldataSchema=b;exports.escapeGuardianCalldataSchema=g;exports.executeOnPluginCalldataSchema=w;exports.feltSchema=e;exports.looseCalldataSchema=z;exports.multiTypeSchema=r;exports.rawArgsArraySchema=s;exports.rawArgsObjectSchema=i;exports.rawArgsSchema=c;exports.removeOwnersCalldataSchema=p;exports.removePluginCalldataSchema=j;exports.replaceSignerCalldataSchema=y;exports.transferCalldataSchema=_;exports.typedDataSchema=f;exports.uint256Schema=l;
|
|
@@ -102,3 +102,74 @@ export declare const transferCalldataSchema: z.ZodObject<{
|
|
|
102
102
|
low: string | number | bigint;
|
|
103
103
|
};
|
|
104
104
|
}>;
|
|
105
|
+
export declare const typedDataSchema: z.ZodObject<{
|
|
106
|
+
types: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
107
|
+
name: z.ZodString;
|
|
108
|
+
type: z.ZodLiteral<"merkletree">;
|
|
109
|
+
contains: z.ZodString;
|
|
110
|
+
}, "strip", z.ZodTypeAny, {
|
|
111
|
+
name: string;
|
|
112
|
+
type: "merkletree";
|
|
113
|
+
contains: string;
|
|
114
|
+
}, {
|
|
115
|
+
name: string;
|
|
116
|
+
type: "merkletree";
|
|
117
|
+
contains: string;
|
|
118
|
+
}>, z.ZodObject<{
|
|
119
|
+
name: z.ZodString;
|
|
120
|
+
type: z.ZodLiteral<"enum">;
|
|
121
|
+
contains: z.ZodString;
|
|
122
|
+
}, "strip", z.ZodTypeAny, {
|
|
123
|
+
name: string;
|
|
124
|
+
type: "enum";
|
|
125
|
+
contains: string;
|
|
126
|
+
}, {
|
|
127
|
+
name: string;
|
|
128
|
+
type: "enum";
|
|
129
|
+
contains: string;
|
|
130
|
+
}>, z.ZodObject<{
|
|
131
|
+
name: z.ZodString;
|
|
132
|
+
type: z.ZodString;
|
|
133
|
+
}, "strip", z.ZodTypeAny, {
|
|
134
|
+
name: string;
|
|
135
|
+
type: string;
|
|
136
|
+
}, {
|
|
137
|
+
name: string;
|
|
138
|
+
type: string;
|
|
139
|
+
}>]>, "many">>;
|
|
140
|
+
primaryType: z.ZodString;
|
|
141
|
+
domain: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
142
|
+
message: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
|
144
|
+
message: {};
|
|
145
|
+
types: Record<string, ({
|
|
146
|
+
name: string;
|
|
147
|
+
type: "merkletree";
|
|
148
|
+
contains: string;
|
|
149
|
+
} | {
|
|
150
|
+
name: string;
|
|
151
|
+
type: "enum";
|
|
152
|
+
contains: string;
|
|
153
|
+
} | {
|
|
154
|
+
name: string;
|
|
155
|
+
type: string;
|
|
156
|
+
})[]>;
|
|
157
|
+
primaryType: string;
|
|
158
|
+
domain: Record<string, unknown>;
|
|
159
|
+
}, {
|
|
160
|
+
message: {};
|
|
161
|
+
types: Record<string, ({
|
|
162
|
+
name: string;
|
|
163
|
+
type: "merkletree";
|
|
164
|
+
contains: string;
|
|
165
|
+
} | {
|
|
166
|
+
name: string;
|
|
167
|
+
type: "enum";
|
|
168
|
+
contains: string;
|
|
169
|
+
} | {
|
|
170
|
+
name: string;
|
|
171
|
+
type: string;
|
|
172
|
+
})[]>;
|
|
173
|
+
primaryType: string;
|
|
174
|
+
domain: Record<string, unknown>;
|
|
175
|
+
}>;
|