-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathinterface.ts
372 lines (352 loc) · 14.4 KB
/
interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import { ProviderInterface } from '../provider';
import { SignerInterface } from '../signer';
import {
Abi,
AllowArray,
BlockIdentifier,
CairoVersion,
Call,
DeclareAndDeployContractPayload,
DeclareContractPayload,
DeclareContractResponse,
DeclareDeployUDCResponse,
DeployAccountContractPayload,
DeployContractResponse,
DeployContractUDCResponse,
EstimateFee,
EstimateFeeAction,
EstimateFeeDetails,
EstimateFeeResponse,
EstimateFeeResponseBulk,
Invocations,
InvocationsDetails,
InvokeFunctionResponse,
MultiDeployContractResponse,
Nonce,
Signature,
SimulateTransactionDetails,
SimulateTransactionResponse,
TypedData,
UniversalDeployerContractPayload,
} from '../types';
export abstract class AccountInterface extends ProviderInterface {
public abstract address: string;
public abstract signer: SignerInterface;
public abstract cairoVersion: CairoVersion;
/**
* Estimate Fee for executing an INVOKE transaction on starknet
*
* @param calls the invocation object containing:
* - contractAddress - the address of the contract
* - entrypoint - the entrypoint of the contract
* - calldata? - (defaults to []) the calldata
*
* @param estimateFeeDetails -
* - blockIdentifier?
* - nonce? = 0
* - skipValidate? - default true
* - tip? - prioritize order of transactions in the mempool.
* - accountDeploymentData? - deploy an account contract (substitution for deploy account transaction)
* - paymasterData? - entity other than the transaction sender to pay the transaction fees(EIP-4337)
* - nonceDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - feeDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - version? - specify ETransactionVersion - V3 Transactions fee is in fri, oldV transactions fee is in wei
*
* @returns response from estimate_fee
*/
public abstract estimateInvokeFee(
calls: AllowArray<Call>,
estimateFeeDetails?: EstimateFeeDetails
): Promise<EstimateFeeResponse>;
/**
* Estimate Fee for executing a DECLARE transaction on starknet
*
* @param contractPayload the payload object containing:
* - contract - the compiled contract to be declared
* - casm? - compiled cairo assembly. Cairo1(casm or compiledClassHash are required)
* - classHash? - the class hash of the compiled contract. Precalculate for faster execution.
* - compiledClassHash?: class hash of the cairo assembly. Cairo1(casm or compiledClassHash are required)
*
* @param estimateFeeDetails -
* - blockIdentifier?
* - nonce? = 0
* - skipValidate? - default true
* - tip? - prioritize order of transactions in the mempool.
* - accountDeploymentData? - deploy an account contract (substitution for deploy account transaction)
* - paymasterData? - entity other than the transaction sender to pay the transaction fees(EIP-4337)
* - nonceDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - feeDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - version? - specify ETransactionVersion - V3 Transactions fee is in fri, oldV transactions fee is in wei
*
* @returns response from estimate_fee
*/
public abstract estimateDeclareFee(
contractPayload: DeclareContractPayload,
estimateFeeDetails?: EstimateFeeDetails
): Promise<EstimateFeeResponse>;
/**
* Estimate Fee for executing a DEPLOY_ACCOUNT transaction on starknet
*
* @param contractPayload -
* - classHash - the class hash of the compiled contract.
* - constructorCalldata? - constructor data;
* - contractAddress? - future account contract address. Precalculate for faster execution.
* - addressSalt? - salt used for calculation of the contractAddress. Required if contractAddress is provided.
*
* @param estimateFeeDetails -
* - blockIdentifier?
* - nonce? = 0
* - skipValidate? - default true
* - tip? - prioritize order of transactions in the mempool.
* - paymasterData? - entity other than the transaction sender to pay the transaction fees(EIP-4337)
* - nonceDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - feeDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - version? - specify ETransactionVersion - V3 Transactions fee is in fri, oldV transactions fee is in wei
*
* @returns response from estimate_fee
*/
public abstract estimateAccountDeployFee(
contractPayload: DeployAccountContractPayload,
estimateFeeDetails?: EstimateFeeDetails
): Promise<EstimateFeeResponse>;
/**
* Estimate Fee for executing a UDC DEPLOY transaction on starknet
* This is different from the normal DEPLOY transaction as it goes through the Universal Deployer Contract (UDC)
* @param deployContractPayload array or singular
* - classHash: computed class hash of compiled contract
* - salt: address salt
* - unique: bool if true ensure unique salt
* - constructorCalldata: constructor calldata
*
* @param estimateFeeDetails -
* - blockIdentifier?
* - nonce?
* - skipValidate? - default true
* - tip? - prioritize order of transactions in the mempool.
* - accountDeploymentData? - deploy an account contract (substitution for deploy account transaction)
* - paymasterData? - entity other than the transaction sender to pay the transaction fees(EIP-4337)
* - nonceDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - feeDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - version? - specify ETransactionVersion - V3 Transactions fee is in fri, oldV transactions fee is in wei
*/
public abstract estimateDeployFee(
deployContractPayload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[],
estimateFeeDetails?: EstimateFeeDetails
): Promise<EstimateFeeResponse>;
/**
* Estimate Fee for executing a list of transactions on starknet
* Contract must be deployed for fee estimation to be possible
*
* @param invocations array of transaction object containing :
* - type - the type of transaction : 'DECLARE' | (multi)'DEPLOY' | (multi)'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT'
* - payload - the payload of the transaction
*
* @param details -
* - blockIdentifier?
* - nonce?
* - skipValidate? - default true
* - tip? - prioritize order of transactions in the mempool.
* - accountDeploymentData? - deploy an account contract (substitution for deploy account transaction)
* - paymasterData? - entity other than the transaction sender to pay the transaction fees(EIP-4337)
* - nonceDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - feeDataAvailabilityMode? - allows users to choose their preferred data availability mode (Volition)
* - version? - specify ETransactionVersion - V3 Transactions fee is in fri, oldV transactions fee is in wei
*
* @returns response from estimate_fee
*/
public abstract estimateFeeBulk(
invocations: Invocations,
details?: EstimateFeeDetails
): Promise<EstimateFeeResponseBulk>;
/**
* Gets Suggested Max Fee based on the transaction type
*
* @param {EstimateFeeAction} estimateFeeAction
* @param {EstimateFeeDetails} details
* @returns EstimateFee (...response, resourceBounds, suggestedMaxFee)
*/
public abstract getSuggestedFee(
estimateFeeAction: EstimateFeeAction,
details: EstimateFeeDetails
): Promise<EstimateFee>;
/**
* Simulates an array of transaction and returns an array of transaction trace and estimated fee.
*
* @param invocations Invocations containing:
* - type - transaction type: DECLARE, (multi)DEPLOY, DEPLOY_ACCOUNT, (multi)INVOKE_FUNCTION
* @param details SimulateTransactionDetails
*
* @returns response from simulate_transaction
*/
public abstract simulateTransaction(
invocations: Invocations,
details?: SimulateTransactionDetails
): Promise<SimulateTransactionResponse>;
/**
* Invoke execute function in account contract
*
* @param transactions the invocation object or an array of them, containing:
* - contractAddress - the address of the contract
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
* - signature - (defaults to []) the signature
* @param {InvocationsDetails} transactionsDetail Additional optional parameters for the transaction
*
* @returns response from addTransaction
*/
public abstract execute(
transactions: AllowArray<Call>,
transactionsDetail?: InvocationsDetails
): Promise<InvokeFunctionResponse>;
/**
* @deprecated
* @param transactions the invocation object or an array of them, containing:
* - contractAddress - the address of the contract
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
* - signature - (defaults to []) the signature
* @param abis (optional) the abi of the contract for better displaying
* @param {InvocationsDetails} transactionsDetail Additional optional parameters for the transaction
* * @returns response from addTransaction
*/
public abstract execute(
transactions: AllowArray<Call>,
abis?: Abi[],
transactionsDetail?: InvocationsDetails
): Promise<InvokeFunctionResponse>;
/**
* Declares a given compiled contract (json) to starknet
*
* @param contractPayload transaction payload to be deployed containing:
* - contract: compiled contract code
* - (optional) classHash: computed class hash of compiled contract. Pre-compute it for faster execution.
* - (required for Cairo1 without compiledClassHash) casm: CompiledContract | string;
* - (optional for Cairo1 with casm) compiledClassHash: compiled class hash from casm. Pre-compute it for faster execution.
* @param transactionsDetail - InvocationsDetails
*
* @returns a confirmation of sending a transaction on the starknet contract
*/
public abstract declare(
contractPayload: DeclareContractPayload,
transactionsDetail?: InvocationsDetails
): Promise<DeclareContractResponse>;
/**
* Deploys a declared contract to starknet - using Universal Deployer Contract (UDC)
* support multicall
*
* @param payload -
* - classHash: computed class hash of compiled contract
* - [constructorCalldata] contract constructor calldata
* - [salt=pseudorandom] deploy address salt
* - [unique=true] ensure unique salt
* @param details - InvocationsDetails
*
* @returns
* - contract_address[]
* - transaction_hash
*/
public abstract deploy(
payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[],
details?: InvocationsDetails
): Promise<MultiDeployContractResponse>;
/**
* Simplify deploy simulating old DeployContract with same response + UDC specific response
* Internal wait for L2 transaction, support multicall
*
* @param payload -
* - classHash: computed class hash of compiled contract
* - [constructorCalldata] contract constructor calldata
* - [salt=pseudorandom] deploy address salt
* - [unique=true] ensure unique salt
* @param details - InvocationsDetails
*
* @returns
* - contract_address
* - transaction_hash
* - address
* - deployer
* - unique
* - classHash
* - calldata_len
* - calldata
* - salt
*/
public abstract deployContract(
payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[],
details?: InvocationsDetails
): Promise<DeployContractUDCResponse>;
/**
* Declares and Deploy a given compiled contract (json) to starknet using UDC
* Internal wait for L2 transaction, do not support multicall
* Method will pass even if contract is already declared (internal using DeclareIfNot)
*
* @param payload
* - contract: compiled contract code
* - [casm=cairo1]: CairoAssembly | undefined;
* - [compiledClassHash]: string | undefined;
* - [classHash]: computed class hash of compiled contract
* - [constructorCalldata] contract constructor calldata
* - [salt=pseudorandom] deploy address salt
* - [unique=true] ensure unique salt
* @param details - InvocationsDetails
*
* @returns
* - declare
* - transaction_hash
* - deploy
* - contract_address
* - transaction_hash
* - address
* - deployer
* - unique
* - classHash
* - calldata_len
* - calldata
* - salt
*/
public abstract declareAndDeploy(
payload: DeclareAndDeployContractPayload,
details?: InvocationsDetails
): Promise<DeclareDeployUDCResponse>;
/**
* Deploy the account on Starknet
*
* @param contractPayload transaction payload to be deployed containing:
* - classHash: computed class hash of compiled contract
* - optional constructor calldata
* - optional address salt
* - optional contractAddress
* @param transactionsDetail - InvocationsDetails
*
* @returns a confirmation of sending a transaction on the starknet contract
*/
public abstract deployAccount(
contractPayload: DeployAccountContractPayload,
transactionsDetail?: InvocationsDetails
): Promise<DeployContractResponse>;
/**
* Signs a TypedData object for off-chain usage with the Starknet private key and returns the signature
* This adds a message prefix so it can't be interchanged with transactions
*
* @param typedData - TypedData object to be signed
* @returns the signature of the TypedData object
* @throws {Error} if typedData is not a valid TypedData
*/
public abstract signMessage(typedData: TypedData): Promise<Signature>;
/**
* Hash a TypedData object with Pedersen hash and return the hash
* This adds a message prefix so it can't be interchanged with transactions
*
* @param typedData - TypedData object to be hashed
* @returns the hash of the TypedData object
* @throws {Error} if typedData is not a valid TypedData
*/
public abstract hashMessage(typedData: TypedData): Promise<string>;
/**
* Gets the nonce of the account with respect to a specific block
*
* @param {BlockIdentifier} blockIdentifier - optional blockIdentifier. Defaults to 'pending'
* @returns nonce of the account
*/
public abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<Nonce>;
}