starknet 4.8.0 → 4.9.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 (87) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/__mocks__/ERC20.json +32561 -29055
  3. package/__tests__/account.test.ts +32 -24
  4. package/__tests__/contract.test.ts +25 -14
  5. package/__tests__/defaultProvider.test.ts +19 -43
  6. package/__tests__/fixtures.ts +9 -1
  7. package/__tests__/rpcProvider.test.ts +6 -15
  8. package/__tests__/sequencerProvider.test.ts +17 -10
  9. package/__tests__/utils/merkle.test.ts +98 -3
  10. package/__tests__/utils/typedData.test.ts +3 -3
  11. package/account/default.d.ts +10 -44
  12. package/account/default.js +255 -61
  13. package/account/interface.d.ts +78 -7
  14. package/constants.d.ts +1 -0
  15. package/constants.js +1 -0
  16. package/contract/default.js +6 -6
  17. package/dist/account/default.d.ts +10 -44
  18. package/dist/account/default.js +255 -61
  19. package/dist/account/interface.d.ts +78 -7
  20. package/dist/constants.d.ts +1 -0
  21. package/dist/constants.js +1 -0
  22. package/dist/contract/default.js +6 -6
  23. package/dist/provider/default.d.ts +8 -3
  24. package/dist/provider/default.js +31 -4
  25. package/dist/provider/interface.d.ts +67 -5
  26. package/dist/provider/rpc.d.ts +7 -2
  27. package/dist/provider/rpc.js +83 -8
  28. package/dist/provider/sequencer.d.ts +7 -2
  29. package/dist/provider/sequencer.js +71 -13
  30. package/dist/signer/default.d.ts +4 -1
  31. package/dist/signer/default.js +22 -0
  32. package/dist/signer/interface.d.ts +27 -2
  33. package/dist/types/api/openrpc.d.ts +24 -2
  34. package/dist/types/api/sequencer.d.ts +22 -7
  35. package/dist/types/lib.d.ts +23 -2
  36. package/dist/types/provider.d.ts +15 -10
  37. package/dist/types/signer.d.ts +14 -1
  38. package/dist/utils/hash.d.ts +2 -0
  39. package/dist/utils/hash.js +13 -2
  40. package/dist/utils/merkle.js +2 -4
  41. package/dist/utils/responseParser/rpc.d.ts +2 -6
  42. package/dist/utils/responseParser/rpc.js +0 -11
  43. package/dist/utils/responseParser/sequencer.js +4 -14
  44. package/package.json +1 -1
  45. package/provider/default.d.ts +8 -3
  46. package/provider/default.js +31 -4
  47. package/provider/interface.d.ts +67 -5
  48. package/provider/rpc.d.ts +7 -2
  49. package/provider/rpc.js +83 -8
  50. package/provider/sequencer.d.ts +7 -2
  51. package/provider/sequencer.js +71 -13
  52. package/signer/default.d.ts +4 -1
  53. package/signer/default.js +22 -0
  54. package/signer/interface.d.ts +27 -2
  55. package/src/account/default.ts +201 -53
  56. package/src/account/interface.ts +104 -6
  57. package/src/constants.ts +1 -0
  58. package/src/contract/default.ts +6 -6
  59. package/src/provider/default.ts +43 -5
  60. package/src/provider/interface.ts +92 -7
  61. package/src/provider/rpc.ts +86 -12
  62. package/src/provider/sequencer.ts +74 -10
  63. package/src/signer/default.ts +54 -2
  64. package/src/signer/interface.ts +31 -2
  65. package/src/types/api/openrpc.ts +28 -2
  66. package/src/types/api/sequencer.ts +32 -9
  67. package/src/types/lib.ts +30 -2
  68. package/src/types/provider.ts +27 -11
  69. package/src/types/signer.ts +18 -1
  70. package/src/utils/hash.ts +46 -1
  71. package/src/utils/merkle.ts +2 -4
  72. package/src/utils/responseParser/rpc.ts +4 -20
  73. package/src/utils/responseParser/sequencer.ts +2 -0
  74. package/types/api/openrpc.d.ts +24 -2
  75. package/types/api/sequencer.d.ts +22 -7
  76. package/types/lib.d.ts +23 -2
  77. package/types/provider.d.ts +15 -10
  78. package/types/signer.d.ts +14 -1
  79. package/utils/hash.d.ts +2 -0
  80. package/utils/hash.js +13 -2
  81. package/utils/merkle.js +2 -4
  82. package/utils/responseParser/rpc.d.ts +2 -6
  83. package/utils/responseParser/rpc.js +0 -11
  84. package/utils/responseParser/sequencer.js +4 -14
  85. package/www/docs/API/account.md +60 -1
  86. package/www/docs/API/provider.md +306 -17
  87. package/www/guides/erc20.md +13 -7
@@ -5,13 +5,13 @@ import { BigNumberish } from '../../utils/number';
5
5
  import {
6
6
  Abi,
7
7
  BlockNumber,
8
+ ContractClass,
8
9
  EntryPointType,
9
10
  RawCalldata,
10
11
  Signature,
11
12
  Status,
12
13
  TransactionStatus,
13
14
  } from '../lib';
14
- import { ContractClass } from '../provider';
15
15
 
16
16
  export type GetTransactionStatusResponse = {
17
17
  tx_status: Status;
@@ -76,10 +76,12 @@ export type CallL1Handler = {
76
76
  export namespace Sequencer {
77
77
  export type DeclareTransaction = {
78
78
  type: 'DECLARE';
79
+ sender_address: string;
79
80
  contract_class: ContractClass;
81
+ signature?: Signature;
80
82
  nonce: BigNumberish;
81
- sender_address: BigNumberish;
82
- signature: Signature;
83
+ max_fee?: BigNumberish;
84
+ version?: BigNumberish;
83
85
  };
84
86
 
85
87
  export type DeployTransaction = {
@@ -90,6 +92,17 @@ export namespace Sequencer {
90
92
  nonce?: BigNumberish;
91
93
  };
92
94
 
95
+ export type DeployAccountTransaction = {
96
+ type: 'DEPLOY_ACCOUNT';
97
+ class_hash: string;
98
+ contract_address_salt: BigNumberish;
99
+ constructor_calldata: string[];
100
+ signature?: Signature;
101
+ max_fee?: BigNumberish;
102
+ version?: BigNumberish;
103
+ nonce?: BigNumberish;
104
+ };
105
+
93
106
  export type InvokeFunctionTransaction = {
94
107
  type: 'INVOKE_FUNCTION';
95
108
  contract_address: string;
@@ -101,7 +114,11 @@ export namespace Sequencer {
101
114
  version?: BigNumberish;
102
115
  };
103
116
 
104
- export type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
117
+ export type Transaction =
118
+ | DeclareTransaction
119
+ | DeployTransaction
120
+ | InvokeFunctionTransaction
121
+ | DeployAccountTransaction;
105
122
 
106
123
  export type AddTransactionResponse = {
107
124
  transaction_hash: string;
@@ -209,10 +226,16 @@ export namespace Sequencer {
209
226
  result: string[];
210
227
  };
211
228
 
212
- export type EstimateFeeTransaction = Omit<
213
- InvokeFunctionTransaction,
214
- 'max_fee' | 'entry_point_type'
215
- >;
229
+ export type InvokeEstimateFee = Omit<InvokeFunctionTransaction, 'max_fee' | 'entry_point_type'>;
230
+ export type DeclareEstimateFee = Omit<DeclareTransaction, 'max_fee'>;
231
+ export type DeployAccountEstimateFee = Omit<DeployAccountTransaction, 'max_fee'>;
232
+ export type DeployEstimateFee = DeployTransaction;
233
+
234
+ export type EstimateFeeRequest =
235
+ | InvokeEstimateFee
236
+ | DeclareEstimateFee
237
+ | DeployEstimateFee
238
+ | DeployAccountEstimateFee;
216
239
 
217
240
  // Support 0.9.1 changes in a backward-compatible way
218
241
  export type EstimateFeeResponse =
@@ -308,7 +331,7 @@ export namespace Sequencer {
308
331
  QUERY: {
309
332
  blockIdentifier: BlockIdentifier;
310
333
  };
311
- REQUEST: EstimateFeeTransaction;
334
+ REQUEST: EstimateFeeRequest;
312
335
  RESPONSE: EstimateFeeResponse;
313
336
  };
314
337
  get_class_by_hash: {
package/src/types/lib.ts CHANGED
@@ -1,10 +1,18 @@
1
1
  import type { ec as EC } from 'elliptic';
2
2
 
3
3
  import type { BigNumberish } from '../utils/number';
4
+ import { RPC } from './api/rpc';
4
5
 
5
6
  export type KeyPair = EC.KeyPair;
6
7
  export type Signature = string[];
7
8
  export type RawCalldata = BigNumberish[];
9
+ export type AllowArray<T> = T | T[];
10
+
11
+ export interface ContractClass {
12
+ program: CompressedProgram;
13
+ entry_points_by_type: RPC.ContractClass['entry_points_by_type'];
14
+ abi?: Abi;
15
+ }
8
16
 
9
17
  export type DeployContractPayload = {
10
18
  contract: CompiledContract | string;
@@ -12,9 +20,29 @@ export type DeployContractPayload = {
12
20
  addressSalt?: string;
13
21
  };
14
22
 
23
+ export type DeployAccountContractPayload = {
24
+ classHash: BigNumberish;
25
+ constructorCalldata?: RawCalldata;
26
+ addressSalt?: BigNumberish;
27
+ contractAddress?: string;
28
+ };
29
+
30
+ export type DeployAccountContractTransaction = Omit<
31
+ DeployAccountContractPayload,
32
+ 'contractAddress'
33
+ > & {
34
+ signature?: Signature;
35
+ };
36
+
15
37
  export type DeclareContractPayload = {
16
38
  contract: CompiledContract | string;
17
- version?: BigNumberish;
39
+ classHash: BigNumberish; // Once the classHash is included in CompiledContract, this can be removed
40
+ };
41
+
42
+ export type DeclareContractTransaction = {
43
+ contractDefinition: ContractClass;
44
+ senderAddress: string;
45
+ signature?: Signature;
18
46
  };
19
47
 
20
48
  export type CallDetails = {
@@ -42,7 +70,7 @@ export type Status =
42
70
  | 'ACCEPTED_ON_L1'
43
71
  | 'REJECTED';
44
72
  export type TransactionStatus = 'TRANSACTION_RECEIVED';
45
- export type Type = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION';
73
+ export type TransactionType = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT';
46
74
  export type EntryPointType = 'EXTERNAL';
47
75
  export type CompressedProgram = string;
48
76
 
@@ -4,8 +4,15 @@
4
4
  */
5
5
  import BN from 'bn.js';
6
6
 
7
- import { RPC } from './api/rpc';
8
- import { Abi, CompressedProgram, RawCalldata, Signature, Status } from './lib';
7
+ import {
8
+ AllowArray,
9
+ Call,
10
+ DeclareContractPayload,
11
+ DeployAccountContractPayload,
12
+ RawCalldata,
13
+ Signature,
14
+ Status,
15
+ } from './lib';
9
16
 
10
17
  export interface GetBlockResponse {
11
18
  timestamp: number;
@@ -47,12 +54,6 @@ export interface ContractEntryPoint {
47
54
  selector: string;
48
55
  }
49
56
 
50
- export interface ContractClass {
51
- program: CompressedProgram;
52
- entry_points_by_type: RPC.ContractClass['entry_points_by_type'];
53
- abi?: Abi;
54
- }
55
-
56
57
  export interface DeclareTransactionResponse extends CommonTransactionResponse {
57
58
  contract_class?: any;
58
59
  sender_address?: string;
@@ -64,7 +65,7 @@ export type GetTransactionReceiptResponse =
64
65
 
65
66
  export interface CommonTransactionReceiptResponse {
66
67
  transaction_hash: string;
67
- status: Status;
68
+ status?: Status;
68
69
  actual_fee?: string;
69
70
  status_data?: string;
70
71
  }
@@ -86,8 +87,9 @@ export interface MessageToL2 {
86
87
  }
87
88
 
88
89
  export interface InvokeTransactionReceiptResponse extends CommonTransactionReceiptResponse {
89
- messages_sent: Array<MessageToL1>;
90
- events: Array<Event>;
90
+ /** @deprecated Use l2_to_l1_messages */
91
+ messages_sent?: Array<MessageToL1>;
92
+ events?: Array<Event>;
91
93
  l1_origin_message?: MessageToL2;
92
94
  }
93
95
 
@@ -116,3 +118,17 @@ export interface DeclareContractResponse {
116
118
  export type CallContractResponse = {
117
119
  result: Array<string>;
118
120
  };
121
+
122
+ export type EstimateFeeAction =
123
+ | {
124
+ type: 'INVOKE';
125
+ payload: AllowArray<Call>;
126
+ }
127
+ | {
128
+ type: 'DECLARE';
129
+ payload: DeclareContractPayload;
130
+ }
131
+ | {
132
+ type: 'DEPLOY_ACCOUNT';
133
+ payload: DeployAccountContractPayload;
134
+ };
@@ -1,7 +1,24 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { InvocationsDetails } from './lib';
2
+ import { BigNumberish } from '../utils/number';
3
+ import { DeployAccountContractPayload, InvocationsDetails } from './lib';
3
4
 
4
5
  export interface InvocationsSignerDetails extends Required<InvocationsDetails> {
5
6
  walletAddress: string;
6
7
  chainId: StarknetChainId;
7
8
  }
9
+
10
+ export interface DeclareSignerDetails {
11
+ // contractClass: ContractClass, // Should be used once class hash is present in ContractClass
12
+ classHash: BigNumberish;
13
+ senderAddress: BigNumberish;
14
+ chainId: StarknetChainId;
15
+ maxFee: BigNumberish;
16
+ version: BigNumberish;
17
+ nonce: BigNumberish;
18
+ }
19
+
20
+ export type DeployAccountSignerDetails = Required<DeployAccountContractPayload> &
21
+ Required<InvocationsDetails> & {
22
+ contractAddress: BigNumberish;
23
+ chainId: StarknetChainId;
24
+ };
package/src/utils/hash.ts CHANGED
@@ -57,7 +57,7 @@ export function starknetKeccak(value: string): BN {
57
57
  * @returns hex selector of given abi function name
58
58
  */
59
59
  export function getSelectorFromName(funcName: string) {
60
- // sometimes BigInteger pads the hex string with zeros, which isnt allowed in the starknet api
60
+ // sometimes BigInteger pads the hex string with zeros, which is not allowed in the starknet api
61
61
  return toHex(starknetKeccak(funcName));
62
62
  }
63
63
 
@@ -147,6 +147,51 @@ export function calculateDeployTransactionHash(
147
147
  );
148
148
  }
149
149
 
150
+ export function calculateDeclareTransactionHash(
151
+ // contractClass: ContractClass, // Should be used once class hash is present in ContractClass
152
+ classHash: BigNumberish,
153
+ senderAddress: BigNumberish,
154
+ version: BigNumberish,
155
+ maxFee: BigNumberish,
156
+ chainId: StarknetChainId,
157
+ nonce: BigNumberish
158
+ ): string {
159
+ return calculateTransactionHashCommon(
160
+ TransactionHashPrefix.DECLARE,
161
+ version,
162
+ senderAddress,
163
+ 0,
164
+ [classHash],
165
+ maxFee,
166
+ chainId,
167
+ [nonce]
168
+ );
169
+ }
170
+
171
+ export function calculateDeployAccountTransactionHash(
172
+ contractAddress: BigNumberish,
173
+ classHash: BigNumberish,
174
+ constructorCalldata: BigNumberish[],
175
+ salt: BigNumberish,
176
+ version: BigNumberish,
177
+ maxFee: BigNumberish,
178
+ chainId: StarknetChainId,
179
+ nonce: BigNumberish
180
+ ) {
181
+ const calldata = [classHash, salt, ...constructorCalldata];
182
+
183
+ return calculateTransactionHashCommon(
184
+ TransactionHashPrefix.DEPLOY_ACCOUNT,
185
+ version,
186
+ contractAddress,
187
+ 0,
188
+ calldata,
189
+ maxFee,
190
+ chainId,
191
+ [nonce]
192
+ );
193
+ }
194
+
150
195
  export function calculateTransactionHash(
151
196
  contractAddress: BigNumberish,
152
197
  version: BigNumberish,
@@ -23,7 +23,7 @@ export class MerkleTree {
23
23
  const newLeaves = [];
24
24
  for (let i = 0; i < leaves.length; i += 2) {
25
25
  if (i + 1 === leaves.length) {
26
- newLeaves.push(leaves[i]);
26
+ newLeaves.push(MerkleTree.hash(leaves[i], '0x0'));
27
27
  } else {
28
28
  newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
29
29
  }
@@ -53,9 +53,7 @@ export class MerkleTree {
53
53
  : this.branches.findIndex((b) => b.length === branch.length);
54
54
  const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
55
55
  return this.getProof(
56
- neededBranch === '0x0'
57
- ? leaf
58
- : MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
56
+ MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
59
57
  nextBranch,
60
58
  newHashPath
61
59
  );
@@ -6,7 +6,6 @@ import {
6
6
  CallContractResponse,
7
7
  EstimateFeeResponse,
8
8
  GetBlockResponse,
9
- GetTransactionReceiptResponse,
10
9
  GetTransactionResponse,
11
10
  } from '../../types';
12
11
  import { RPC } from '../../types/api';
@@ -21,15 +20,14 @@ type GetTransactionByHashResponse = RPC.GetTransactionByHashResponse & {
21
20
  [key: string]: any;
22
21
  };
23
22
 
24
- type TransactionReceipt = RPC.TransactionReceipt & {
25
- [key: string]: any;
26
- };
27
-
28
23
  export class RPCResponseParser
29
24
  implements
30
25
  Omit<
31
26
  ResponseParser,
32
- 'parseDeclareContractResponse' | 'parseDeployContractResponse' | 'parseInvokeFunctionResponse'
27
+ | 'parseDeclareContractResponse'
28
+ | 'parseDeployContractResponse'
29
+ | 'parseInvokeFunctionResponse'
30
+ | 'parseGetTransactionReceiptResponse'
33
31
  >
34
32
  {
35
33
  public parseGetBlockResponse(res: RpcGetBlockResponse): GetBlockResponse {
@@ -56,20 +54,6 @@ export class RPCResponseParser
56
54
  };
57
55
  }
58
56
 
59
- public parseGetTransactionReceiptResponse(
60
- res: TransactionReceipt
61
- ): GetTransactionReceiptResponse {
62
- return {
63
- transaction_hash: res.transaction_hash,
64
- actual_fee: res.actual_fee,
65
- status: res.status,
66
- status_data: res.status_data,
67
- messages_sent: res.messages_sent,
68
- l1_origin_message: res.l1_origin_message,
69
- events: res.events,
70
- };
71
- }
72
-
73
57
  public parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse {
74
58
  return {
75
59
  overall_fee: toBN(res.overall_fee),
@@ -32,6 +32,7 @@ export class SequencerAPIResponseParser extends ResponseParser {
32
32
  res: Sequencer.GetTransactionResponse
33
33
  ): GetTransactionResponse {
34
34
  return {
35
+ ...res,
35
36
  calldata: 'calldata' in res.transaction ? (res.transaction.calldata as Array<string>) : [],
36
37
  contract_address:
37
38
  'contract_address' in res.transaction ? res.transaction.contract_address : undefined,
@@ -68,6 +69,7 @@ export class SequencerAPIResponseParser extends ResponseParser {
68
69
  ...('transaction_index' in res && { transaction_index: res.transaction_index }),
69
70
  ...('execution_resources' in res && { execution_resources: res.execution_resources }),
70
71
  ...('l1_to_l2_consumed_message' in res && {
72
+ // eslint-disable-next-line @typescript-eslint/dot-notation
71
73
  l1_to_l2_consumed_message: res['l1_to_l2_consumed_message'],
72
74
  }),
73
75
  ...('transaction_failure_reason' in res && {
@@ -17,7 +17,7 @@ declare type BLOCK_HASH = FELT;
17
17
  declare type TXN_HASH = FELT;
18
18
  declare type PROTOCOL_VERSION = string;
19
19
  declare type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
20
- declare type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'INVOKE' | 'L1_HANDLER';
20
+ declare type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'DEPLOY_ACCOUNT' | 'INVOKE' | 'L1_HANDLER';
21
21
  declare type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
22
22
  declare enum BLOCK_TAG {
23
23
  'latest' = 0,
@@ -101,6 +101,15 @@ declare type DECLARE_TXN = COMMON_TXN_PROPERTIES & {
101
101
  class_hash: FELT;
102
102
  sender_address: ADDRESS;
103
103
  };
104
+ declare type DEPLOY_ACCOUNT_TXN_REQUEST = COMMON_TXN_PROPERTIES & {
105
+ class_hash: FELT;
106
+ contract_address_salt: FELT;
107
+ constructor_calldata: Array<FELT>;
108
+ };
109
+ declare type DECLARE_TXN_REQUEST = COMMON_TXN_PROPERTIES & {
110
+ contract_class: CONTRACT_CLASS;
111
+ sender_address: ADDRESS;
112
+ };
104
113
  declare type DEPLOY_TXN = {
105
114
  transaction_hash: TXN_HASH;
106
115
  class_hash: FELT;
@@ -352,7 +361,7 @@ export declare namespace OPENRPC {
352
361
  };
353
362
  starknet_estimateFee: {
354
363
  params: {
355
- request: INVOKE_TXN;
364
+ request: INVOKE_TXN | DECLARE_TXN_REQUEST | DEPLOY_ACCOUNT_TXN_REQUEST;
356
365
  block_id: BLOCK_ID;
357
366
  };
358
367
  result: FEE_ESTIMATE;
@@ -407,7 +416,11 @@ export declare namespace OPENRPC {
407
416
  starknet_addDeclareTransaction: {
408
417
  params: {
409
418
  contract_class: CONTRACT_CLASS;
419
+ sender_address: ADDRESS;
420
+ signature: SIGNATURE;
421
+ max_fee: NUM_AS_HEX;
410
422
  version: NUM_AS_HEX;
423
+ nonce: FELT;
411
424
  };
412
425
  result: DeclaredTransaction;
413
426
  errors: Errors.INVALID_CONTRACT_CLASS;
@@ -421,6 +434,15 @@ export declare namespace OPENRPC {
421
434
  result: DeployedTransaction;
422
435
  errors: Errors.INVALID_CONTRACT_CLASS;
423
436
  };
437
+ starknet_addDeployAccountTransaction: {
438
+ params: {
439
+ contract_address_salt: FELT;
440
+ constructor_calldata: Array<FELT>;
441
+ class_hash: FELT;
442
+ };
443
+ result: DeployedTransaction;
444
+ errors: Errors.INVALID_CONTRACT_CLASS;
445
+ };
424
446
  starknet_traceTransaction: {
425
447
  params: {
426
448
  transaction_hash: TXN_HASH;
@@ -1,8 +1,7 @@
1
1
  import BN from 'bn.js';
2
2
  import { BlockIdentifier } from '../../provider/utils';
3
3
  import { BigNumberish } from '../../utils/number';
4
- import { Abi, BlockNumber, EntryPointType, RawCalldata, Signature, Status, TransactionStatus } from '../lib';
5
- import { ContractClass } from '../provider';
4
+ import { Abi, BlockNumber, ContractClass, EntryPointType, RawCalldata, Signature, Status, TransactionStatus } from '../lib';
6
5
  export declare type GetTransactionStatusResponse = {
7
6
  tx_status: Status;
8
7
  block_hash?: string;
@@ -62,10 +61,12 @@ export declare type CallL1Handler = {
62
61
  export declare namespace Sequencer {
63
62
  type DeclareTransaction = {
64
63
  type: 'DECLARE';
64
+ sender_address: string;
65
65
  contract_class: ContractClass;
66
+ signature?: Signature;
66
67
  nonce: BigNumberish;
67
- sender_address: BigNumberish;
68
- signature: Signature;
68
+ max_fee?: BigNumberish;
69
+ version?: BigNumberish;
69
70
  };
70
71
  type DeployTransaction = {
71
72
  type: 'DEPLOY';
@@ -74,6 +75,16 @@ export declare namespace Sequencer {
74
75
  constructor_calldata: string[];
75
76
  nonce?: BigNumberish;
76
77
  };
78
+ type DeployAccountTransaction = {
79
+ type: 'DEPLOY_ACCOUNT';
80
+ class_hash: string;
81
+ contract_address_salt: BigNumberish;
82
+ constructor_calldata: string[];
83
+ signature?: Signature;
84
+ max_fee?: BigNumberish;
85
+ version?: BigNumberish;
86
+ nonce?: BigNumberish;
87
+ };
77
88
  type InvokeFunctionTransaction = {
78
89
  type: 'INVOKE_FUNCTION';
79
90
  contract_address: string;
@@ -84,7 +95,7 @@ export declare namespace Sequencer {
84
95
  max_fee?: BigNumberish;
85
96
  version?: BigNumberish;
86
97
  };
87
- type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
98
+ type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction | DeployAccountTransaction;
88
99
  type AddTransactionResponse = {
89
100
  transaction_hash: string;
90
101
  code?: TransactionStatus;
@@ -172,7 +183,11 @@ export declare namespace Sequencer {
172
183
  type CallContractResponse = {
173
184
  result: string[];
174
185
  };
175
- type EstimateFeeTransaction = Omit<InvokeFunctionTransaction, 'max_fee' | 'entry_point_type'>;
186
+ type InvokeEstimateFee = Omit<InvokeFunctionTransaction, 'max_fee' | 'entry_point_type'>;
187
+ type DeclareEstimateFee = Omit<DeclareTransaction, 'max_fee'>;
188
+ type DeployAccountEstimateFee = Omit<DeployAccountTransaction, 'max_fee'>;
189
+ type DeployEstimateFee = DeployTransaction;
190
+ type EstimateFeeRequest = InvokeEstimateFee | DeclareEstimateFee | DeployEstimateFee | DeployAccountEstimateFee;
176
191
  type EstimateFeeResponse = {
177
192
  overall_fee: number;
178
193
  gas_price: number;
@@ -263,7 +278,7 @@ export declare namespace Sequencer {
263
278
  QUERY: {
264
279
  blockIdentifier: BlockIdentifier;
265
280
  };
266
- REQUEST: EstimateFeeTransaction;
281
+ REQUEST: EstimateFeeRequest;
267
282
  RESPONSE: EstimateFeeResponse;
268
283
  };
269
284
  get_class_by_hash: {
package/types/lib.d.ts CHANGED
@@ -1,16 +1,37 @@
1
1
  import type { ec as EC } from 'elliptic';
2
2
  import type { BigNumberish } from '../utils/number';
3
+ import { RPC } from './api/rpc';
3
4
  export declare type KeyPair = EC.KeyPair;
4
5
  export declare type Signature = string[];
5
6
  export declare type RawCalldata = BigNumberish[];
7
+ export declare type AllowArray<T> = T | T[];
8
+ export interface ContractClass {
9
+ program: CompressedProgram;
10
+ entry_points_by_type: RPC.ContractClass['entry_points_by_type'];
11
+ abi?: Abi;
12
+ }
6
13
  export declare type DeployContractPayload = {
7
14
  contract: CompiledContract | string;
8
15
  constructorCalldata?: RawCalldata;
9
16
  addressSalt?: string;
10
17
  };
18
+ export declare type DeployAccountContractPayload = {
19
+ classHash: BigNumberish;
20
+ constructorCalldata?: RawCalldata;
21
+ addressSalt?: BigNumberish;
22
+ contractAddress?: string;
23
+ };
24
+ export declare type DeployAccountContractTransaction = Omit<DeployAccountContractPayload, 'contractAddress'> & {
25
+ signature?: Signature;
26
+ };
11
27
  export declare type DeclareContractPayload = {
12
28
  contract: CompiledContract | string;
13
- version?: BigNumberish;
29
+ classHash: BigNumberish;
30
+ };
31
+ export declare type DeclareContractTransaction = {
32
+ contractDefinition: ContractClass;
33
+ senderAddress: string;
34
+ signature?: Signature;
14
35
  };
15
36
  export declare type CallDetails = {
16
37
  contractAddress: string;
@@ -32,7 +53,7 @@ export declare type InvocationsDetailsWithNonce = InvocationsDetails & {
32
53
  };
33
54
  export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
34
55
  export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
35
- export declare type Type = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION';
56
+ export declare type TransactionType = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT';
36
57
  export declare type EntryPointType = 'EXTERNAL';
37
58
  export declare type CompressedProgram = string;
38
59
  export declare type AbiEntry = {
@@ -3,8 +3,7 @@
3
3
  * Intersection (sequencer response ∩ (∪ rpc responses))
4
4
  */
5
5
  import BN from 'bn.js';
6
- import { RPC } from './api/rpc';
7
- import { Abi, CompressedProgram, RawCalldata, Signature, Status } from './lib';
6
+ import { AllowArray, Call, DeclareContractPayload, DeployAccountContractPayload, RawCalldata, Signature, Status } from './lib';
8
7
  export interface GetBlockResponse {
9
8
  timestamp: number;
10
9
  block_hash: string;
@@ -38,11 +37,6 @@ export interface ContractEntryPoint {
38
37
  offset: string;
39
38
  selector: string;
40
39
  }
41
- export interface ContractClass {
42
- program: CompressedProgram;
43
- entry_points_by_type: RPC.ContractClass['entry_points_by_type'];
44
- abi?: Abi;
45
- }
46
40
  export interface DeclareTransactionResponse extends CommonTransactionResponse {
47
41
  contract_class?: any;
48
42
  sender_address?: string;
@@ -50,7 +44,7 @@ export interface DeclareTransactionResponse extends CommonTransactionResponse {
50
44
  export declare type GetTransactionReceiptResponse = InvokeTransactionReceiptResponse | DeclareTransactionReceiptResponse;
51
45
  export interface CommonTransactionReceiptResponse {
52
46
  transaction_hash: string;
53
- status: Status;
47
+ status?: Status;
54
48
  actual_fee?: string;
55
49
  status_data?: string;
56
50
  }
@@ -68,8 +62,9 @@ export interface MessageToL2 {
68
62
  payload: Array<string>;
69
63
  }
70
64
  export interface InvokeTransactionReceiptResponse extends CommonTransactionReceiptResponse {
71
- messages_sent: Array<MessageToL1>;
72
- events: Array<Event>;
65
+ /** @deprecated Use l2_to_l1_messages */
66
+ messages_sent?: Array<MessageToL1>;
67
+ events?: Array<Event>;
73
68
  l1_origin_message?: MessageToL2;
74
69
  }
75
70
  export declare type DeclareTransactionReceiptResponse = CommonTransactionReceiptResponse;
@@ -92,3 +87,13 @@ export interface DeclareContractResponse {
92
87
  export declare type CallContractResponse = {
93
88
  result: Array<string>;
94
89
  };
90
+ export declare type EstimateFeeAction = {
91
+ type: 'INVOKE';
92
+ payload: AllowArray<Call>;
93
+ } | {
94
+ type: 'DECLARE';
95
+ payload: DeclareContractPayload;
96
+ } | {
97
+ type: 'DEPLOY_ACCOUNT';
98
+ payload: DeployAccountContractPayload;
99
+ };
package/types/signer.d.ts CHANGED
@@ -1,6 +1,19 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { InvocationsDetails } from './lib';
2
+ import { BigNumberish } from '../utils/number';
3
+ import { DeployAccountContractPayload, InvocationsDetails } from './lib';
3
4
  export interface InvocationsSignerDetails extends Required<InvocationsDetails> {
4
5
  walletAddress: string;
5
6
  chainId: StarknetChainId;
6
7
  }
8
+ export interface DeclareSignerDetails {
9
+ classHash: BigNumberish;
10
+ senderAddress: BigNumberish;
11
+ chainId: StarknetChainId;
12
+ maxFee: BigNumberish;
13
+ version: BigNumberish;
14
+ nonce: BigNumberish;
15
+ }
16
+ export declare type DeployAccountSignerDetails = Required<DeployAccountContractPayload> & Required<InvocationsDetails> & {
17
+ contractAddress: BigNumberish;
18
+ chainId: StarknetChainId;
19
+ };
package/utils/hash.d.ts CHANGED
@@ -31,5 +31,7 @@ export declare function pedersen(input: [BigNumberish, BigNumberish]): string;
31
31
  export declare function computeHashOnElements(data: BigNumberish[]): string;
32
32
  export declare function calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish, contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, additionalData?: BigNumberish[]): string;
33
33
  export declare function calculateDeployTransactionHash(contractAddress: BigNumberish, constructorCalldata: BigNumberish[], version: BigNumberish, chainId: StarknetChainId): string;
34
+ export declare function calculateDeclareTransactionHash(classHash: BigNumberish, senderAddress: BigNumberish, version: BigNumberish, maxFee: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish): string;
35
+ export declare function calculateDeployAccountTransactionHash(contractAddress: BigNumberish, classHash: BigNumberish, constructorCalldata: BigNumberish[], salt: BigNumberish, version: BigNumberish, maxFee: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish): string;
34
36
  export declare function calculateTransactionHash(contractAddress: BigNumberish, version: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish): string;
35
37
  export declare function calculateContractAddressFromHash(salt: BigNumberish, classHash: BigNumberish, constructorCalldata: RawCalldata, deployerAddress: BigNumberish): string;