@@ -20,6 +20,8 @@ const SELECTOR_DEPLOYCONTRACT: Felt = Felt::from_raw([
20
20
18249998464715511309 ,
21
21
] ) ;
22
22
23
+ /// A contract factory that acts as a blueprint for deploying Starknet smart contracts using the
24
+ /// Universal Deployer Contract.
23
25
#[ derive( Debug ) ]
24
26
pub struct ContractFactory < A > {
25
27
class_hash : Felt ,
@@ -62,10 +64,15 @@ pub struct DeploymentV3<'f, A> {
62
64
}
63
65
64
66
impl < A > ContractFactory < A > {
67
+ /// Constructs a new [`ContractFactory`] from a class hash and an account.
68
+ ///
69
+ /// The [`ContractFactory`] created uses the default address for the Universal Deployer
70
+ /// Contract. To use a custom UDC deployment, use [`new_with_udc`](fn.new_with_udc) instead.
65
71
pub const fn new ( class_hash : Felt , account : A ) -> Self {
66
72
Self :: new_with_udc ( class_hash, account, UDC_ADDRESS )
67
73
}
68
74
75
+ /// Constructs a new [`ContractFactory`] with a custom Universal Deployer Contract address.
69
76
pub const fn new_with_udc ( class_hash : Felt , account : A , udc_address : Felt ) -> Self {
70
77
Self {
71
78
class_hash,
@@ -79,6 +86,8 @@ impl<A> ContractFactory<A>
79
86
where
80
87
A : Account ,
81
88
{
89
+ /// Generates an instance of [`DeploymentV1`] for sending `INVOKE` v1 transactions for the
90
+ /// contract deployment. Pays transaction fees in `ETH`.
82
91
pub const fn deploy_v1 (
83
92
& self ,
84
93
constructor_calldata : Vec < Felt > ,
96
105
}
97
106
}
98
107
108
+ /// Generates an instance of [`DeploymentV3`] for sending `INVOKE` v3 transactions for the
109
+ /// contract deployment. Pays transaction fees in `STRK`.
99
110
pub const fn deploy_v3 (
100
111
& self ,
101
112
constructor_calldata : Vec < Felt > ,
@@ -115,6 +126,8 @@ where
115
126
}
116
127
}
117
128
129
+ /// Generates an instance of [`DeploymentV1`] for sending `INVOKE` v1 transactions for the
130
+ /// contract deployment. Pays transaction fees in `ETH`.
118
131
#[ deprecated = "use version specific variants (`deploy_v1` & `deploy_v3`) instead" ]
119
132
pub const fn deploy (
120
133
& self ,
@@ -127,20 +140,25 @@ where
127
140
}
128
141
129
142
impl < ' f , A > DeploymentV1 < ' f , A > {
143
+ /// Returns a new [`DeploymentV1`] with the `nonce`.
130
144
pub fn nonce ( self , nonce : Felt ) -> Self {
131
145
Self {
132
146
nonce : Some ( nonce) ,
133
147
..self
134
148
}
135
149
}
136
150
151
+ /// Returns a new [`DeploymentV1`] with the `max_fee`.
137
152
pub fn max_fee ( self , max_fee : Felt ) -> Self {
138
153
Self {
139
154
max_fee : Some ( max_fee) ,
140
155
..self
141
156
}
142
157
}
143
158
159
+ /// Returns a new [`DeploymentV1`] with the fee estimate multiplier. The multiplier is used
160
+ /// when transaction fee is not manually specified and must be fetched from a
161
+ /// [`Provider`](starknet_providers::Provider) instead.
144
162
pub fn fee_estimate_multiplier ( self , fee_estimate_multiplier : f64 ) -> Self {
145
163
Self {
146
164
fee_estimate_multiplier,
@@ -150,34 +168,43 @@ impl<'f, A> DeploymentV1<'f, A> {
150
168
}
151
169
152
170
impl < ' f , A > DeploymentV3 < ' f , A > {
171
+ /// Returns a new [`DeploymentV3`] with the `nonce`.
153
172
pub fn nonce ( self , nonce : Felt ) -> Self {
154
173
Self {
155
174
nonce : Some ( nonce) ,
156
175
..self
157
176
}
158
177
}
159
178
179
+ /// Returns a new [`DeploymentV3`] with the `gas`.
160
180
pub fn gas ( self , gas : u64 ) -> Self {
161
181
Self {
162
182
gas : Some ( gas) ,
163
183
..self
164
184
}
165
185
}
166
186
187
+ /// Returns a new [`DeploymentV3`] with the `gas_price`.
167
188
pub fn gas_price ( self , gas_price : u128 ) -> Self {
168
189
Self {
169
190
gas_price : Some ( gas_price) ,
170
191
..self
171
192
}
172
193
}
173
194
195
+ /// Returns a new [`DeploymentV3`] with the gas amount estimate multiplier. The multiplier is
196
+ /// used when the gas amount is not manually specified and must be fetched from a
197
+ /// [`Provider`](starknet_providers::Provider) instead.
174
198
pub fn gas_estimate_multiplier ( self , gas_estimate_multiplier : f64 ) -> Self {
175
199
Self {
176
200
gas_estimate_multiplier,
177
201
..self
178
202
}
179
203
}
180
204
205
+ /// Returns a new [`DeploymentV3`] with the gas price estimate multiplier. The multiplier is
206
+ /// used when the gas price is not manually specified and must be fetched from a
207
+ /// [`Provider`](starknet_providers::Provider) instead.
181
208
pub fn gas_price_estimate_multiplier ( self , gas_price_estimate_multiplier : f64 ) -> Self {
182
209
Self {
183
210
gas_price_estimate_multiplier,
@@ -234,11 +261,14 @@ impl<'f, A> DeploymentV1<'f, A>
234
261
where
235
262
A : ConnectedAccount + Sync ,
236
263
{
264
+ /// Estimates transaction fees from a [`Provider`](starknet_providers::Provider).
237
265
pub async fn estimate_fee ( & self ) -> Result < FeeEstimate , AccountError < A :: SignError > > {
238
266
let execution: ExecutionV1 < ' _ , A > = self . into ( ) ;
239
267
execution. estimate_fee ( ) . await
240
268
}
241
269
270
+ /// Simulates the transaction from a [`Provider`](starknet_providers::Provider). Transaction
271
+ /// validation and fee transfer can be skipped.
242
272
pub async fn simulate (
243
273
& self ,
244
274
skip_validate : bool ,
@@ -248,6 +278,7 @@ where
248
278
execution. simulate ( skip_validate, skip_fee_charge) . await
249
279
}
250
280
281
+ /// Signs and broadcasts the transaction to the network.
251
282
pub async fn send ( & self ) -> Result < InvokeTransactionResult , AccountError < A :: SignError > > {
252
283
let execution: ExecutionV1 < ' _ , A > = self . into ( ) ;
253
284
execution. send ( ) . await
@@ -258,11 +289,14 @@ impl<'f, A> DeploymentV3<'f, A>
258
289
where
259
290
A : ConnectedAccount + Sync ,
260
291
{
292
+ /// Estimates transaction fees from a [`Provider`](starknet_providers::Provider).
261
293
pub async fn estimate_fee ( & self ) -> Result < FeeEstimate , AccountError < A :: SignError > > {
262
294
let execution: ExecutionV3 < ' _ , A > = self . into ( ) ;
263
295
execution. estimate_fee ( ) . await
264
296
}
265
297
298
+ /// Simulates the transaction from a [`Provider`](starknet_providers::Provider). Transaction
299
+ /// validation and fee transfer can be skipped.
266
300
pub async fn simulate (
267
301
& self ,
268
302
skip_validate : bool ,
@@ -272,6 +306,7 @@ where
272
306
execution. simulate ( skip_validate, skip_fee_charge) . await
273
307
}
274
308
309
+ /// Signs and broadcasts the transaction to the network.
275
310
pub async fn send ( & self ) -> Result < InvokeTransactionResult , AccountError < A :: SignError > > {
276
311
let execution: ExecutionV3 < ' _ , A > = self . into ( ) ;
277
312
execution. send ( ) . await
0 commit comments