starknet 4.8.0 → 4.10.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +1 -3
  3. package/__mocks__/ERC20.json +32561 -29055
  4. package/__tests__/account.test.ts +32 -24
  5. package/__tests__/contract.test.ts +25 -14
  6. package/__tests__/defaultProvider.test.ts +91 -240
  7. package/__tests__/fixtures.ts +10 -2
  8. package/__tests__/rpcProvider.test.ts +8 -16
  9. package/__tests__/sequencerProvider.test.ts +17 -10
  10. package/__tests__/udc.test.ts +41 -0
  11. package/__tests__/utils/merkle.test.ts +98 -3
  12. package/__tests__/utils/typedData.test.ts +3 -3
  13. package/account/default.d.ts +12 -44
  14. package/account/default.js +305 -61
  15. package/account/interface.d.ts +96 -8
  16. package/constants.d.ts +8 -1
  17. package/constants.js +8 -1
  18. package/contract/default.d.ts +11 -27
  19. package/contract/default.js +105 -121
  20. package/contract/interface.d.ts +5 -2
  21. package/dist/account/default.d.ts +12 -44
  22. package/dist/account/default.js +305 -61
  23. package/dist/account/interface.d.ts +96 -8
  24. package/dist/constants.d.ts +8 -1
  25. package/dist/constants.js +8 -1
  26. package/dist/contract/default.d.ts +11 -27
  27. package/dist/contract/default.js +105 -121
  28. package/dist/contract/interface.d.ts +5 -2
  29. package/dist/provider/default.d.ts +8 -3
  30. package/dist/provider/default.js +31 -4
  31. package/dist/provider/interface.d.ts +67 -5
  32. package/dist/provider/rpc.d.ts +10 -3
  33. package/dist/provider/rpc.js +98 -10
  34. package/dist/provider/sequencer.d.ts +11 -4
  35. package/dist/provider/sequencer.js +89 -18
  36. package/dist/signer/default.d.ts +5 -2
  37. package/dist/signer/default.js +25 -3
  38. package/dist/signer/interface.d.ts +29 -2
  39. package/dist/types/api/index.d.ts +0 -6
  40. package/dist/types/api/openrpc.d.ts +24 -2
  41. package/dist/types/api/sequencer.d.ts +22 -7
  42. package/dist/types/index.d.ts +1 -1
  43. package/dist/types/lib.d.ts +36 -2
  44. package/dist/types/provider.d.ts +15 -10
  45. package/dist/types/signer.d.ts +14 -1
  46. package/dist/utils/hash.d.ts +2 -0
  47. package/dist/utils/hash.js +13 -2
  48. package/dist/utils/merkle.js +2 -4
  49. package/dist/utils/number.d.ts +1 -0
  50. package/dist/utils/number.js +3 -1
  51. package/dist/utils/responseParser/rpc.d.ts +2 -6
  52. package/dist/utils/responseParser/rpc.js +0 -11
  53. package/dist/utils/responseParser/sequencer.js +4 -14
  54. package/package.json +1 -1
  55. package/provider/default.d.ts +8 -3
  56. package/provider/default.js +31 -4
  57. package/provider/interface.d.ts +67 -5
  58. package/provider/rpc.d.ts +10 -3
  59. package/provider/rpc.js +98 -10
  60. package/provider/sequencer.d.ts +11 -4
  61. package/provider/sequencer.js +89 -18
  62. package/signer/default.d.ts +5 -2
  63. package/signer/default.js +25 -3
  64. package/signer/interface.d.ts +29 -2
  65. package/src/account/default.ts +243 -55
  66. package/src/account/interface.ts +132 -7
  67. package/src/constants.ts +8 -0
  68. package/src/contract/default.ts +124 -141
  69. package/src/contract/interface.ts +5 -2
  70. package/src/provider/default.ts +43 -5
  71. package/src/provider/interface.ts +92 -7
  72. package/src/provider/rpc.ts +93 -15
  73. package/src/provider/sequencer.ts +87 -14
  74. package/src/signer/default.ts +56 -4
  75. package/src/signer/interface.ts +33 -2
  76. package/src/types/api/index.ts +0 -4
  77. package/src/types/api/openrpc.ts +28 -2
  78. package/src/types/api/sequencer.ts +32 -9
  79. package/src/types/index.ts +1 -1
  80. package/src/types/lib.ts +43 -2
  81. package/src/types/provider.ts +27 -11
  82. package/src/types/signer.ts +18 -1
  83. package/src/utils/hash.ts +46 -1
  84. package/src/utils/merkle.ts +2 -4
  85. package/src/utils/number.ts +2 -0
  86. package/src/utils/responseParser/rpc.ts +4 -20
  87. package/src/utils/responseParser/sequencer.ts +2 -0
  88. package/types/api/index.d.ts +0 -6
  89. package/types/api/openrpc.d.ts +24 -2
  90. package/types/api/sequencer.d.ts +22 -7
  91. package/types/index.d.ts +1 -1
  92. package/types/lib.d.ts +36 -2
  93. package/types/provider.d.ts +15 -10
  94. package/types/signer.d.ts +14 -1
  95. package/utils/hash.d.ts +2 -0
  96. package/utils/hash.js +13 -2
  97. package/utils/merkle.js +2 -4
  98. package/utils/number.d.ts +1 -0
  99. package/utils/number.js +3 -1
  100. package/utils/responseParser/rpc.d.ts +2 -6
  101. package/utils/responseParser/rpc.js +0 -11
  102. package/utils/responseParser/sequencer.js +4 -14
  103. package/www/docs/API/account.md +170 -11
  104. package/www/docs/API/contract.md +39 -3
  105. package/www/docs/API/provider.md +310 -17
  106. package/www/docs/API/signer.md +56 -2
  107. package/www/guides/erc20.md +13 -7
@@ -1,4 +1,4 @@
1
- import { ZERO } from '../constants';
1
+ import { UDC, ZERO } from '../constants';
2
2
  import { ProviderInterface, ProviderOptions } from '../provider';
3
3
  import { Provider } from '../provider/default';
4
4
  import { BlockIdentifier } from '../provider/utils';
@@ -6,6 +6,9 @@ import { Signer, SignerInterface } from '../signer';
6
6
  import {
7
7
  Abi,
8
8
  Call,
9
+ DeclareContractResponse,
10
+ DeployContractResponse,
11
+ EstimateFeeAction,
9
12
  InvocationsDetails,
10
13
  InvocationsSignerDetails,
11
14
  InvokeFunctionResponse,
@@ -13,8 +16,15 @@ import {
13
16
  Signature,
14
17
  } from '../types';
15
18
  import { EstimateFee, EstimateFeeDetails } from '../types/account';
16
- import { transactionVersion } from '../utils/hash';
17
- import { BigNumberish, toBN } from '../utils/number';
19
+ import {
20
+ AllowArray,
21
+ DeclareContractPayload,
22
+ DeployAccountContractPayload,
23
+ UniversalDeployerContractPayload,
24
+ } from '../types/lib';
25
+ import { calculateContractAddressFromHash, transactionVersion } from '../utils/hash';
26
+ import { BigNumberish, toBN, toCairoBool } from '../utils/number';
27
+ import { parseContract } from '../utils/provider';
18
28
  import { compileCalldata, estimatedFeeToMaxFee } from '../utils/stark';
19
29
  import { fromCallsToExecuteCalldata } from '../utils/transaction';
20
30
  import { TypedData, getMessageHash } from '../utils/typedData';
@@ -41,7 +51,14 @@ export class Account extends Provider implements AccountInterface {
41
51
  }
42
52
 
43
53
  public async estimateFee(
44
- calls: Call | Call[],
54
+ calls: AllowArray<Call>,
55
+ estimateFeeDetails?: EstimateFeeDetails | undefined
56
+ ): Promise<EstimateFee> {
57
+ return this.estimateInvokeFee(calls, estimateFeeDetails);
58
+ }
59
+
60
+ public async estimateInvokeFee(
61
+ calls: AllowArray<Call>,
45
62
  { nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
46
63
  ): Promise<EstimateFee> {
47
64
  const transactions = Array.isArray(calls) ? calls : [calls];
@@ -60,7 +77,7 @@ export class Account extends Provider implements AccountInterface {
60
77
  const signature = await this.signer.signTransaction(transactions, signerDetails);
61
78
 
62
79
  const calldata = fromCallsToExecuteCalldata(transactions);
63
- const response = await super.getEstimateFee(
80
+ const response = await super.getInvokeEstimateFee(
64
81
  { contractAddress: this.address, calldata, signature },
65
82
  { version, nonce },
66
83
  blockIdentifier
@@ -74,31 +91,87 @@ export class Account extends Provider implements AccountInterface {
74
91
  };
75
92
  }
76
93
 
77
- /**
78
- * Invoke execute function in account contract
79
- *
80
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
81
- *
82
- * @param calls - one or more calls to be executed
83
- * @param abis - one or more abis which can be used to display the calls
84
- * @param transactionsDetail - optional transaction details
85
- * @returns a confirmation of invoking a function on the starknet contract
86
- */
94
+ public async estimateDeclareFee(
95
+ { classHash, contract }: DeclareContractPayload,
96
+ { blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
97
+ ): Promise<EstimateFee> {
98
+ const nonce = toBN(providedNonce ?? (await this.getNonce()));
99
+ const version = toBN(transactionVersion);
100
+ const chainId = await this.getChainId();
101
+ const contractDefinition = parseContract(contract);
102
+
103
+ const signature = await this.signer.signDeclareTransaction({
104
+ classHash,
105
+ senderAddress: this.address,
106
+ chainId,
107
+ maxFee: ZERO,
108
+ version,
109
+ nonce,
110
+ });
111
+
112
+ const response = await super.getDeclareEstimateFee(
113
+ { senderAddress: this.address, signature, contractDefinition },
114
+ { version, nonce },
115
+ blockIdentifier
116
+ );
117
+ const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
118
+
119
+ return {
120
+ ...response,
121
+ suggestedMaxFee,
122
+ };
123
+ }
124
+
125
+ public async estimateAccountDeployFee(
126
+ {
127
+ classHash,
128
+ addressSalt = 0,
129
+ constructorCalldata = [],
130
+ contractAddress: providedContractAddress,
131
+ }: DeployAccountContractPayload,
132
+ { blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
133
+ ): Promise<EstimateFee> {
134
+ const nonce = toBN(providedNonce ?? (await this.getNonce()));
135
+ const version = toBN(transactionVersion);
136
+ const chainId = await this.getChainId();
137
+ const contractAddress =
138
+ providedContractAddress ??
139
+ calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
140
+
141
+ const signature = await this.signer.signDeployAccountTransaction({
142
+ classHash,
143
+ contractAddress,
144
+ chainId,
145
+ maxFee: ZERO,
146
+ version,
147
+ nonce,
148
+ addressSalt,
149
+ constructorCalldata,
150
+ });
151
+
152
+ const response = await super.getDeployAccountEstimateFee(
153
+ { classHash, addressSalt, constructorCalldata, signature },
154
+ { version, nonce },
155
+ blockIdentifier
156
+ );
157
+ const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
158
+
159
+ return {
160
+ ...response,
161
+ suggestedMaxFee,
162
+ };
163
+ }
164
+
87
165
  public async execute(
88
- calls: Call | Call[],
166
+ calls: AllowArray<Call>,
89
167
  abis: Abi[] | undefined = undefined,
90
168
  transactionsDetail: InvocationsDetails = {}
91
169
  ): Promise<InvokeFunctionResponse> {
92
170
  const transactions = Array.isArray(calls) ? calls : [calls];
93
171
  const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
94
- let maxFee: BigNumberish = '0';
95
- if (transactionsDetail.maxFee || transactionsDetail.maxFee === 0) {
96
- maxFee = transactionsDetail.maxFee;
97
- } else {
98
- const { suggestedMaxFee } = await this.estimateFee(transactions, { nonce });
99
- maxFee = suggestedMaxFee.toString();
100
- }
101
-
172
+ const maxFee =
173
+ transactionsDetail.maxFee ??
174
+ (await this.getSuggestedMaxFee({ type: 'INVOKE', payload: calls }, transactionsDetail));
102
175
  const version = toBN(transactionVersion);
103
176
  const chainId = await this.getChainId();
104
177
 
@@ -124,37 +197,133 @@ export class Account extends Provider implements AccountInterface {
124
197
  );
125
198
  }
126
199
 
127
- /**
128
- * Sign an JSON object with the starknet private key and return the signature
129
- *
130
- * @param json - JSON object to be signed
131
- * @returns the signature of the JSON object
132
- * @throws {Error} if the JSON object is not a valid JSON
133
- */
200
+ public async declare(
201
+ { classHash, contract }: DeclareContractPayload,
202
+ transactionsDetail: InvocationsDetails = {}
203
+ ): Promise<DeclareContractResponse> {
204
+ const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
205
+ const maxFee =
206
+ transactionsDetail.maxFee ??
207
+ (await this.getSuggestedMaxFee(
208
+ { type: 'DECLARE', payload: { classHash, contract } },
209
+ transactionsDetail
210
+ ));
211
+
212
+ const version = toBN(transactionVersion);
213
+ const chainId = await this.getChainId();
214
+
215
+ const signature = await this.signer.signDeclareTransaction({
216
+ classHash,
217
+ senderAddress: this.address,
218
+ chainId,
219
+ maxFee,
220
+ version,
221
+ nonce,
222
+ });
223
+
224
+ const contractDefinition = parseContract(contract);
225
+
226
+ return this.declareContract(
227
+ { contractDefinition, senderAddress: this.address, signature },
228
+ {
229
+ nonce,
230
+ maxFee,
231
+ version,
232
+ }
233
+ );
234
+ }
235
+
236
+ public async deploy(
237
+ {
238
+ classHash,
239
+ salt,
240
+ unique = true,
241
+ constructorCalldata = [],
242
+ isDevnet = false,
243
+ }: UniversalDeployerContractPayload,
244
+ additionalCalls: AllowArray<Call> = [], // support multicall
245
+ transactionsDetail: InvocationsDetails = {}
246
+ ): Promise<InvokeFunctionResponse> {
247
+ const compiledConstructorCallData = compileCalldata(constructorCalldata);
248
+
249
+ const callsArray = Array.isArray(additionalCalls) ? additionalCalls : [additionalCalls];
250
+
251
+ return this.execute(
252
+ [
253
+ {
254
+ contractAddress: isDevnet ? UDC.ADDRESS_DEVNET : UDC.ADDRESS,
255
+ entrypoint: UDC.ENTRYPOINT,
256
+ calldata: [
257
+ classHash,
258
+ salt,
259
+ toCairoBool(unique),
260
+ compiledConstructorCallData.length,
261
+ ...compiledConstructorCallData,
262
+ ],
263
+ },
264
+ ...callsArray,
265
+ ],
266
+ undefined,
267
+ transactionsDetail
268
+ );
269
+ }
270
+
271
+ public async deployAccount(
272
+ {
273
+ classHash,
274
+ constructorCalldata = [],
275
+ addressSalt = 0,
276
+ contractAddress: providedContractAddress,
277
+ }: DeployAccountContractPayload,
278
+ transactionsDetail: InvocationsDetails = {}
279
+ ): Promise<DeployContractResponse> {
280
+ const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
281
+ const version = toBN(transactionVersion);
282
+ const chainId = await this.getChainId();
283
+
284
+ const contractAddress =
285
+ providedContractAddress ??
286
+ calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
287
+
288
+ const maxFee =
289
+ transactionsDetail.maxFee ??
290
+ (await this.getSuggestedMaxFee(
291
+ {
292
+ type: 'DEPLOY_ACCOUNT',
293
+ payload: { classHash, constructorCalldata, addressSalt, contractAddress },
294
+ },
295
+ transactionsDetail
296
+ ));
297
+
298
+ const signature = await this.signer.signDeployAccountTransaction({
299
+ classHash,
300
+ constructorCalldata,
301
+ contractAddress,
302
+ addressSalt,
303
+ chainId,
304
+ maxFee,
305
+ version,
306
+ nonce,
307
+ });
308
+
309
+ return this.deployAccountContract(
310
+ { classHash, addressSalt, constructorCalldata, signature },
311
+ {
312
+ nonce,
313
+ maxFee,
314
+ version,
315
+ }
316
+ );
317
+ }
318
+
134
319
  public async signMessage(typedData: TypedData): Promise<Signature> {
135
320
  return this.signer.signMessage(typedData, this.address);
136
321
  }
137
322
 
138
- /**
139
- * Hash a JSON object with pederson hash and return the hash
140
- *
141
- * @param json - JSON object to be hashed
142
- * @returns the hash of the JSON object
143
- * @throws {Error} if the JSON object is not a valid JSON
144
- */
145
323
  public async hashMessage(typedData: TypedData): Promise<string> {
146
324
  return getMessageHash(typedData, this.address);
147
325
  }
148
326
 
149
- /**
150
- * Verify a signature of a given hash
151
- * @warning This method is not recommended, use verifyMessage instead
152
- *
153
- * @param hash - JSON object to be verified
154
- * @param signature - signature of the JSON object
155
- * @returns true if the signature is valid, false otherwise
156
- * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
157
- */
158
327
  public async verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean> {
159
328
  try {
160
329
  await this.callContract({
@@ -171,16 +340,35 @@ export class Account extends Provider implements AccountInterface {
171
340
  }
172
341
  }
173
342
 
174
- /**
175
- * Verify a signature of a JSON object
176
- *
177
- * @param hash - hash to be verified
178
- * @param signature - signature of the hash
179
- * @returns true if the signature is valid, false otherwise
180
- * @throws {Error} if the signature is not a valid signature
181
- */
182
343
  public async verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean> {
183
344
  const hash = await this.hashMessage(typedData);
184
345
  return this.verifyMessageHash(hash, signature);
185
346
  }
347
+
348
+ public async getSuggestedMaxFee(
349
+ estimateFeeAction: EstimateFeeAction,
350
+ details: EstimateFeeDetails
351
+ ) {
352
+ let feeEstimate: EstimateFee;
353
+
354
+ switch (estimateFeeAction.type) {
355
+ case 'INVOKE':
356
+ feeEstimate = await this.estimateInvokeFee(estimateFeeAction.payload, details);
357
+ break;
358
+
359
+ case 'DECLARE':
360
+ feeEstimate = await this.estimateDeclareFee(estimateFeeAction.payload, details);
361
+ break;
362
+
363
+ case 'DEPLOY_ACCOUNT':
364
+ feeEstimate = await this.estimateAccountDeployFee(estimateFeeAction.payload, details);
365
+ break;
366
+
367
+ default:
368
+ feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
369
+ break;
370
+ }
371
+
372
+ return feeEstimate.suggestedMaxFee.toString();
373
+ }
186
374
  }
@@ -4,12 +4,21 @@ import { SignerInterface } from '../signer';
4
4
  import {
5
5
  Abi,
6
6
  Call,
7
+ DeclareContractResponse,
8
+ DeployContractResponse,
9
+ EstimateFeeAction,
7
10
  EstimateFeeDetails,
8
11
  EstimateFeeResponse,
9
12
  InvocationsDetails,
10
13
  InvokeFunctionResponse,
11
14
  Signature,
12
15
  } from '../types';
16
+ import {
17
+ AllowArray,
18
+ DeclareContractPayload,
19
+ DeployAccountContractPayload,
20
+ UniversalDeployerContractPayload,
21
+ } from '../types/lib';
13
22
  import { BigNumberish } from '../utils/number';
14
23
  import { TypedData } from '../utils/typedData/types';
15
24
 
@@ -19,18 +28,61 @@ export abstract class AccountInterface extends ProviderInterface {
19
28
  public abstract signer: SignerInterface;
20
29
 
21
30
  /**
22
- * Estimate Fee for a method on starknet
31
+ * @deprecated Use estimateInvokeFee or estimateDeclareFee instead
32
+ * Estimate Fee for executing an INVOKE transaction on starknet
23
33
  *
24
- * @param invocation the invocation object containing:
34
+ * @param calls the invocation object containing:
25
35
  * - contractAddress - the address of the contract
26
36
  * - entrypoint - the entrypoint of the contract
27
37
  * - calldata - (defaults to []) the calldata
28
- * - signature - (defaults to []) the signature
29
38
  *
30
- * @returns response from addTransaction
39
+ * @returns response from estimate_fee
31
40
  */
32
41
  public abstract estimateFee(
33
- calls: Call | Call[],
42
+ calls: AllowArray<Call>,
43
+ estimateFeeDetails?: EstimateFeeDetails
44
+ ): Promise<EstimateFeeResponse>;
45
+
46
+ /**
47
+ * Estimate Fee for executing an INVOKE transaction on starknet
48
+ *
49
+ * @param calls the invocation object containing:
50
+ * - contractAddress - the address of the contract
51
+ * - entrypoint - the entrypoint of the contract
52
+ * - calldata - (defaults to []) the calldata
53
+ *
54
+ * @returns response from estimate_fee
55
+ */
56
+ public abstract estimateInvokeFee(
57
+ calls: AllowArray<Call>,
58
+ estimateFeeDetails?: EstimateFeeDetails
59
+ ): Promise<EstimateFeeResponse>;
60
+
61
+ /**
62
+ * Estimate Fee for executing a DECLARE transaction on starknet
63
+ *
64
+ * @param contractPayload the payload object containing:
65
+ * - contract - the compiled contract to be declared
66
+ * - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
67
+ *
68
+ * @returns response from estimate_fee
69
+ */
70
+ public abstract estimateDeclareFee(
71
+ contractPayload: DeclareContractPayload,
72
+ estimateFeeDetails?: EstimateFeeDetails
73
+ ): Promise<EstimateFeeResponse>;
74
+
75
+ /**
76
+ * Estimate Fee for executing a DEPLOY_ACCOUNT transaction on starknet
77
+ *
78
+ * @param contractPayload the payload object containing:
79
+ * - contract - the compiled contract to be deployed
80
+ * - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
81
+ *
82
+ * @returns response from estimate_fee
83
+ */
84
+ public abstract estimateAccountDeployFee(
85
+ contractPayload: DeployAccountContractPayload,
34
86
  estimateFeeDetails?: EstimateFeeDetails
35
87
  ): Promise<EstimateFeeResponse>;
36
88
 
@@ -47,11 +99,66 @@ export abstract class AccountInterface extends ProviderInterface {
47
99
  * @returns response from addTransaction
48
100
  */
49
101
  public abstract execute(
50
- transactions: Call | Call[],
102
+ transactions: AllowArray<Call>,
51
103
  abis?: Abi[],
52
104
  transactionsDetail?: InvocationsDetails
53
105
  ): Promise<InvokeFunctionResponse>;
54
106
 
107
+ /**
108
+ * Declares a given compiled contract (json) to starknet
109
+ *
110
+ * @param contractPayload transaction payload to be deployed containing:
111
+ - contract: compiled contract code
112
+ - classHash: computed class hash of compiled contract
113
+ - signature
114
+ * @param transactionsDetail Invocation Details containing:
115
+ - optional nonce
116
+ - optional version
117
+ - optional maxFee
118
+ * @returns a confirmation of sending a transaction on the starknet contract
119
+ */
120
+ public abstract declare(
121
+ contractPayload: DeclareContractPayload,
122
+ transactionsDetail?: InvocationsDetails
123
+ ): Promise<DeclareContractResponse>;
124
+
125
+ /**
126
+ * @param deployContractPayload containing
127
+ * - classHash: computed class hash of compiled contract
128
+ * - salt: address salt
129
+ * - unique: bool if true ensure unique salt
130
+ * - calldata: constructor calldata
131
+ * @param additionalCalls - optional additional calls array to support multicall
132
+ * @param transactionsDetail Invocation Details containing:
133
+ * - optional nonce
134
+ * - optional version
135
+ * - optional maxFee
136
+ */
137
+ public abstract deploy(
138
+ deployContractPayload: UniversalDeployerContractPayload,
139
+ additionalCalls?: AllowArray<Call>,
140
+ transactionsDetail?: InvocationsDetails
141
+ ): Promise<InvokeFunctionResponse>;
142
+
143
+ /**
144
+ * Deploy the account on Starknet
145
+ *
146
+ * @param contractPayload transaction payload to be deployed containing:
147
+ - classHash: computed class hash of compiled contract
148
+ - optional constructor calldata
149
+ - optional address salt
150
+ - optional contractAddress
151
+ * @param transactionsDetail Invocation Details containing:
152
+ - optional nonce
153
+ - optional version
154
+ - optional maxFee
155
+ * @returns a confirmation of sending a transaction on the starknet contract
156
+ */
157
+ public abstract deployAccount(
158
+ contractPayload: DeployAccountContractPayload,
159
+ transactionsDetail?: InvocationsDetails
160
+ ): Promise<DeployContractResponse>;
161
+
55
162
  /**
56
163
  * Sign an JSON object for off-chain usage with the starknet private key and return the signature
57
164
  * This adds a message prefix so it cant be interchanged with transactions
@@ -75,7 +182,7 @@ export abstract class AccountInterface extends ProviderInterface {
75
182
  /**
76
183
  * Verify a signature of a JSON object
77
184
  *
78
- * @param json - JSON object to be verified
185
+ * @param typedData - JSON object to be verified
79
186
  * @param signature - signature of the JSON object
80
187
  * @returns true if the signature is valid, false otherwise
81
188
  * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
@@ -93,5 +200,23 @@ export abstract class AccountInterface extends ProviderInterface {
93
200
  */
94
201
  public abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
95
202
 
203
+ /**
204
+ * Gets the nonce of the account with respect to a specific block
205
+ *
206
+ * @param {BlockIdentifier} blockIdentifier - optional blockIdentifier. Defaults to 'pending'
207
+ * @returns nonce of the account
208
+ */
96
209
  public abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
210
+
211
+ /**
212
+ * Gets Suggested Max Fee based on the transaction type
213
+ *
214
+ * @param {EstimateFeeAction} estimateFeeAction
215
+ * @param {EstimateFeeDetails} details
216
+ * @returns suggestedMaxFee
217
+ */
218
+ public abstract getSuggestedMaxFee(
219
+ estimateFeeAction: EstimateFeeAction,
220
+ details: EstimateFeeDetails
221
+ ): Promise<BigNumberish>;
97
222
  }
package/src/constants.ts CHANGED
@@ -11,14 +11,22 @@ export const MASK_251 = TWO.pow(toBN(251));
11
11
  export enum StarknetChainId {
12
12
  MAINNET = '0x534e5f4d41494e', // encodeShortString('SN_MAIN'),
13
13
  TESTNET = '0x534e5f474f45524c49', // encodeShortString('SN_GOERLI'),
14
+ TESTNET2 = '0x534e5f474f45524c4932',
14
15
  }
15
16
  export enum TransactionHashPrefix {
16
17
  DECLARE = '0x6465636c617265', // encodeShortString('declare'),
17
18
  DEPLOY = '0x6465706c6f79', // encodeShortString('deploy'),
19
+ DEPLOY_ACCOUNT = '0x6465706c6f795f6163636f756e74', // encodeShortString('deploy_account'),
18
20
  INVOKE = '0x696e766f6b65', // encodeShortString('invoke'),
19
21
  L1_HANDLER = '0x6c315f68616e646c6572', // encodeShortString('l1_handler'),
20
22
  }
21
23
 
24
+ export const UDC = {
25
+ ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf',
26
+ ENTRYPOINT: 'deployContract',
27
+ ADDRESS_DEVNET: '0x25fcb74260022bd8ed7e8d542408941826b53345e478b8303d6f31744838a36',
28
+ };
29
+
22
30
  /**
23
31
  * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
24
32
  * Please do not edit until the JSON changes.