starknet 4.7.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.
- package/CHANGELOG.md +43 -0
- package/CONTRIBUTING.md +2 -2
- package/__mocks__/ERC20.json +32561 -29055
- package/__mocks__/l1l2_compiled.json +10107 -0
- package/__tests__/account.test.ts +32 -24
- package/__tests__/contract.test.ts +25 -14
- package/__tests__/defaultProvider.test.ts +19 -49
- package/__tests__/fixtures.ts +11 -1
- package/__tests__/rpcProvider.test.ts +6 -15
- package/__tests__/sequencerProvider.test.ts +57 -11
- package/__tests__/utils/merkle.test.ts +113 -3
- package/__tests__/utils/typedData.test.ts +3 -3
- package/account/default.d.ts +10 -44
- package/account/default.js +255 -61
- package/account/interface.d.ts +78 -7
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/contract/default.js +6 -6
- package/dist/account/default.d.ts +10 -44
- package/dist/account/default.js +255 -61
- package/dist/account/interface.d.ts +78 -7
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/contract/default.js +6 -6
- package/dist/provider/default.d.ts +8 -3
- package/dist/provider/default.js +31 -4
- package/dist/provider/interface.d.ts +67 -5
- package/dist/provider/rpc.d.ts +7 -2
- package/dist/provider/rpc.js +83 -8
- package/dist/provider/sequencer.d.ts +9 -3
- package/dist/provider/sequencer.js +93 -14
- package/dist/signer/default.d.ts +4 -1
- package/dist/signer/default.js +22 -0
- package/dist/signer/interface.d.ts +27 -2
- package/dist/types/api/openrpc.d.ts +24 -2
- package/dist/types/api/sequencer.d.ts +43 -23
- package/dist/types/lib.d.ts +23 -2
- package/dist/types/provider.d.ts +19 -10
- package/dist/types/signer.d.ts +14 -1
- package/dist/utils/hash.d.ts +8 -0
- package/dist/utils/hash.js +28 -2
- package/dist/utils/merkle.js +4 -5
- package/dist/utils/number.d.ts +5 -0
- package/dist/utils/number.js +29 -1
- package/dist/utils/responseParser/rpc.d.ts +2 -6
- package/dist/utils/responseParser/rpc.js +0 -11
- package/dist/utils/responseParser/sequencer.js +11 -33
- package/package.json +1 -1
- package/provider/default.d.ts +8 -3
- package/provider/default.js +31 -4
- package/provider/interface.d.ts +67 -5
- package/provider/rpc.d.ts +7 -2
- package/provider/rpc.js +83 -8
- package/provider/sequencer.d.ts +9 -3
- package/provider/sequencer.js +93 -14
- package/signer/default.d.ts +4 -1
- package/signer/default.js +22 -0
- package/signer/interface.d.ts +27 -2
- package/src/account/default.ts +201 -53
- package/src/account/interface.ts +104 -6
- package/src/constants.ts +1 -0
- package/src/contract/default.ts +6 -6
- package/src/provider/default.ts +43 -5
- package/src/provider/interface.ts +92 -7
- package/src/provider/rpc.ts +86 -12
- package/src/provider/sequencer.ts +105 -13
- package/src/signer/default.ts +54 -2
- package/src/signer/interface.ts +31 -2
- package/src/types/api/openrpc.ts +28 -2
- package/src/types/api/sequencer.ts +54 -25
- package/src/types/lib.ts +30 -2
- package/src/types/provider.ts +31 -11
- package/src/types/signer.ts +18 -1
- package/src/utils/hash.ts +70 -2
- package/src/utils/merkle.ts +4 -5
- package/src/utils/number.ts +27 -0
- package/src/utils/responseParser/rpc.ts +4 -20
- package/src/utils/responseParser/sequencer.ts +14 -7
- package/types/api/openrpc.d.ts +24 -2
- package/types/api/sequencer.d.ts +43 -23
- package/types/lib.d.ts +23 -2
- package/types/provider.d.ts +19 -10
- package/types/signer.d.ts +14 -1
- package/utils/hash.d.ts +8 -0
- package/utils/hash.js +28 -2
- package/utils/merkle.js +4 -5
- package/utils/number.d.ts +5 -0
- package/utils/number.js +29 -1
- package/utils/responseParser/rpc.d.ts +2 -6
- package/utils/responseParser/rpc.js +0 -11
- package/utils/responseParser/sequencer.js +11 -33
- package/www/docs/API/account.md +60 -1
- package/www/docs/API/provider.md +320 -23
- package/www/guides/account.md +1 -1
- 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;
|
|
@@ -27,15 +27,17 @@ export type GetContractAddressesResponse = {
|
|
|
27
27
|
GpsStatementVerifier: string;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
export type
|
|
30
|
+
export type FunctionInvocation = {
|
|
31
31
|
caller_address: string;
|
|
32
32
|
contract_address: string;
|
|
33
|
-
code_address: string;
|
|
34
|
-
selector: string;
|
|
35
33
|
calldata: RawCalldata;
|
|
34
|
+
call_type?: string;
|
|
35
|
+
class_hash?: string;
|
|
36
|
+
selector?: string;
|
|
37
|
+
entry_point_type?: EntryPointType;
|
|
36
38
|
result: Array<any>;
|
|
37
39
|
execution_resources: ExecutionResources;
|
|
38
|
-
|
|
40
|
+
internal_calls: Array<FunctionInvocation>;
|
|
39
41
|
events: Array<any>;
|
|
40
42
|
messages: Array<any>;
|
|
41
43
|
};
|
|
@@ -54,18 +56,9 @@ export type ExecutionResources = {
|
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
export type GetTransactionTraceResponse = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
code_address: string;
|
|
61
|
-
selector: string;
|
|
62
|
-
calldata: RawArgs;
|
|
63
|
-
result: Array<any>;
|
|
64
|
-
execution_resources: ExecutionResources;
|
|
65
|
-
internal_call: Array<any>;
|
|
66
|
-
events: Array<any>;
|
|
67
|
-
messages: Array<any>;
|
|
68
|
-
};
|
|
59
|
+
validate_invocation?: FunctionInvocation;
|
|
60
|
+
function_invocation?: FunctionInvocation;
|
|
61
|
+
fee_transfer_invocation?: FunctionInvocation;
|
|
69
62
|
signature: Signature;
|
|
70
63
|
};
|
|
71
64
|
|
|
@@ -73,13 +66,22 @@ export type RawArgs = {
|
|
|
73
66
|
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
|
|
74
67
|
};
|
|
75
68
|
|
|
69
|
+
export type CallL1Handler = {
|
|
70
|
+
from_address: string;
|
|
71
|
+
to_address: string;
|
|
72
|
+
entry_point_selector: string;
|
|
73
|
+
payload: Array<string>;
|
|
74
|
+
};
|
|
75
|
+
|
|
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
|
-
|
|
82
|
-
|
|
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 =
|
|
117
|
+
export type Transaction =
|
|
118
|
+
| DeclareTransaction
|
|
119
|
+
| DeployTransaction
|
|
120
|
+
| InvokeFunctionTransaction
|
|
121
|
+
| DeployAccountTransaction;
|
|
105
122
|
|
|
106
123
|
export type AddTransactionResponse = {
|
|
107
124
|
transaction_hash: string;
|
|
@@ -197,6 +214,7 @@ export namespace Sequencer {
|
|
|
197
214
|
status: Status;
|
|
198
215
|
gas_price: string;
|
|
199
216
|
sequencer_address: string;
|
|
217
|
+
starknet_version: string;
|
|
200
218
|
};
|
|
201
219
|
|
|
202
220
|
export type CallContractTransaction = Omit<
|
|
@@ -208,10 +226,16 @@ export namespace Sequencer {
|
|
|
208
226
|
result: string[];
|
|
209
227
|
};
|
|
210
228
|
|
|
211
|
-
export type
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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;
|
|
215
239
|
|
|
216
240
|
// Support 0.9.1 changes in a backward-compatible way
|
|
217
241
|
export type EstimateFeeResponse =
|
|
@@ -307,7 +331,7 @@ export namespace Sequencer {
|
|
|
307
331
|
QUERY: {
|
|
308
332
|
blockIdentifier: BlockIdentifier;
|
|
309
333
|
};
|
|
310
|
-
REQUEST:
|
|
334
|
+
REQUEST: EstimateFeeRequest;
|
|
311
335
|
RESPONSE: EstimateFeeResponse;
|
|
312
336
|
};
|
|
313
337
|
get_class_by_hash: {
|
|
@@ -340,5 +364,10 @@ export namespace Sequencer {
|
|
|
340
364
|
REQUEST: never;
|
|
341
365
|
RESPONSE: any;
|
|
342
366
|
};
|
|
367
|
+
estimate_message_fee: {
|
|
368
|
+
QUERY: any;
|
|
369
|
+
REQUEST: any;
|
|
370
|
+
RESPONSE: EstimateFeeResponse;
|
|
371
|
+
};
|
|
343
372
|
};
|
|
344
373
|
}
|
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
|
-
|
|
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
|
|
73
|
+
export type TransactionType = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT';
|
|
46
74
|
export type EntryPointType = 'EXTERNAL';
|
|
47
75
|
export type CompressedProgram = string;
|
|
48
76
|
|
package/src/types/provider.ts
CHANGED
|
@@ -4,8 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import BN from 'bn.js';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
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;
|
|
@@ -15,6 +22,10 @@ export interface GetBlockResponse {
|
|
|
15
22
|
parent_hash: string;
|
|
16
23
|
status: Status;
|
|
17
24
|
transactions: Array<string>;
|
|
25
|
+
gas_price?: string;
|
|
26
|
+
sequencer_address?: string;
|
|
27
|
+
starknet_version?: string;
|
|
28
|
+
transaction_receipts?: any;
|
|
18
29
|
}
|
|
19
30
|
|
|
20
31
|
export interface GetCodeResponse {
|
|
@@ -43,12 +54,6 @@ export interface ContractEntryPoint {
|
|
|
43
54
|
selector: string;
|
|
44
55
|
}
|
|
45
56
|
|
|
46
|
-
export interface ContractClass {
|
|
47
|
-
program: CompressedProgram;
|
|
48
|
-
entry_points_by_type: RPC.ContractClass['entry_points_by_type'];
|
|
49
|
-
abi?: Abi;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
57
|
export interface DeclareTransactionResponse extends CommonTransactionResponse {
|
|
53
58
|
contract_class?: any;
|
|
54
59
|
sender_address?: string;
|
|
@@ -60,7 +65,7 @@ export type GetTransactionReceiptResponse =
|
|
|
60
65
|
|
|
61
66
|
export interface CommonTransactionReceiptResponse {
|
|
62
67
|
transaction_hash: string;
|
|
63
|
-
status
|
|
68
|
+
status?: Status;
|
|
64
69
|
actual_fee?: string;
|
|
65
70
|
status_data?: string;
|
|
66
71
|
}
|
|
@@ -82,8 +87,9 @@ export interface MessageToL2 {
|
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
export interface InvokeTransactionReceiptResponse extends CommonTransactionReceiptResponse {
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
/** @deprecated Use l2_to_l1_messages */
|
|
91
|
+
messages_sent?: Array<MessageToL1>;
|
|
92
|
+
events?: Array<Event>;
|
|
87
93
|
l1_origin_message?: MessageToL2;
|
|
88
94
|
}
|
|
89
95
|
|
|
@@ -112,3 +118,17 @@ export interface DeclareContractResponse {
|
|
|
112
118
|
export type CallContractResponse = {
|
|
113
119
|
result: Array<string>;
|
|
114
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
|
+
};
|
package/src/types/signer.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import {
|
|
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
|
@@ -15,7 +15,15 @@ import {
|
|
|
15
15
|
import { RawCalldata } from '../types/lib';
|
|
16
16
|
import { ec } from './ellipticCurve';
|
|
17
17
|
import { addHexPrefix, buf2hex, removeHexPrefix, utf8ToArray } from './encode';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
BigNumberish,
|
|
20
|
+
isHex,
|
|
21
|
+
isStringWholeNumber,
|
|
22
|
+
toBN,
|
|
23
|
+
toFelt,
|
|
24
|
+
toHex,
|
|
25
|
+
toHexString,
|
|
26
|
+
} from './number';
|
|
19
27
|
|
|
20
28
|
export const transactionVersion = 1;
|
|
21
29
|
export const feeTransactionVersion = toBN(2).pow(toBN(128)).add(toBN(transactionVersion));
|
|
@@ -49,10 +57,25 @@ export function starknetKeccak(value: string): BN {
|
|
|
49
57
|
* @returns hex selector of given abi function name
|
|
50
58
|
*/
|
|
51
59
|
export function getSelectorFromName(funcName: string) {
|
|
52
|
-
// sometimes BigInteger pads the hex string with zeros, which
|
|
60
|
+
// sometimes BigInteger pads the hex string with zeros, which is not allowed in the starknet api
|
|
53
61
|
return toHex(starknetKeccak(funcName));
|
|
54
62
|
}
|
|
55
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Function to get hex selector from function name, decimal string or hex string
|
|
66
|
+
* @param value hex string | decimal string | string
|
|
67
|
+
* @returns Hex selector
|
|
68
|
+
*/
|
|
69
|
+
export function getSelector(value: string) {
|
|
70
|
+
if (isHex(value)) {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
if (isStringWholeNumber(value)) {
|
|
74
|
+
return toHexString(value);
|
|
75
|
+
}
|
|
76
|
+
return getSelectorFromName(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
56
79
|
const constantPoints = CONSTANT_POINTS.map((coords: string[]) =>
|
|
57
80
|
ec.curve.point(coords[0], coords[1])
|
|
58
81
|
);
|
|
@@ -124,6 +147,51 @@ export function calculateDeployTransactionHash(
|
|
|
124
147
|
);
|
|
125
148
|
}
|
|
126
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
|
+
|
|
127
195
|
export function calculateTransactionHash(
|
|
128
196
|
contractAddress: BigNumberish,
|
|
129
197
|
version: BigNumberish,
|
package/src/utils/merkle.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { pedersen } from './hash';
|
|
2
|
+
import { toBN } from './number';
|
|
2
3
|
|
|
3
4
|
export class MerkleTree {
|
|
4
5
|
public leaves: string[];
|
|
@@ -22,7 +23,7 @@ export class MerkleTree {
|
|
|
22
23
|
const newLeaves = [];
|
|
23
24
|
for (let i = 0; i < leaves.length; i += 2) {
|
|
24
25
|
if (i + 1 === leaves.length) {
|
|
25
|
-
newLeaves.push(leaves[i]);
|
|
26
|
+
newLeaves.push(MerkleTree.hash(leaves[i], '0x0'));
|
|
26
27
|
} else {
|
|
27
28
|
newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
|
|
28
29
|
}
|
|
@@ -31,7 +32,7 @@ export class MerkleTree {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
static hash(a: string, b: string) {
|
|
34
|
-
const [aSorted, bSorted] = [a, b].sort();
|
|
35
|
+
const [aSorted, bSorted] = [toBN(a), toBN(b)].sort((x: any, y: any) => (x.gte(y) ? 1 : -1));
|
|
35
36
|
return pedersen([aSorted, bSorted]);
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -52,9 +53,7 @@ export class MerkleTree {
|
|
|
52
53
|
: this.branches.findIndex((b) => b.length === branch.length);
|
|
53
54
|
const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
|
|
54
55
|
return this.getProof(
|
|
55
|
-
neededBranch
|
|
56
|
-
? leaf
|
|
57
|
-
: MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
|
|
56
|
+
MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
|
|
58
57
|
nextBranch,
|
|
59
58
|
newHashPath
|
|
60
59
|
);
|
package/src/utils/number.ts
CHANGED
|
@@ -61,3 +61,30 @@ export function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[
|
|
|
61
61
|
export function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[] {
|
|
62
62
|
return rawCalldata.map((x) => toHex(toBN(x)));
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
export const isStringWholeNumber = (value: string) => /^\d+$/.test(value);
|
|
66
|
+
export const toHexString = (value: string) => toHex(toBN(value));
|
|
67
|
+
|
|
68
|
+
export function getDecimalString(value: string) {
|
|
69
|
+
if (isHex(value)) {
|
|
70
|
+
return hexToDecimalString(value);
|
|
71
|
+
}
|
|
72
|
+
if (isStringWholeNumber(value)) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getHexString(value: string) {
|
|
79
|
+
if (isHex(value)) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
if (isStringWholeNumber(value)) {
|
|
83
|
+
return toHexString(value);
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function getHexStringArray(value: Array<string>) {
|
|
89
|
+
return value.map((el) => getHexString(el));
|
|
90
|
+
}
|
|
@@ -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
|
-
|
|
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),
|
|
@@ -19,12 +19,9 @@ import { ResponseParser } from '.';
|
|
|
19
19
|
export class SequencerAPIResponseParser extends ResponseParser {
|
|
20
20
|
public parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse {
|
|
21
21
|
return {
|
|
22
|
-
|
|
23
|
-
block_hash: res.block_hash,
|
|
24
|
-
block_number: res.block_number,
|
|
22
|
+
...res,
|
|
25
23
|
new_root: res.state_root,
|
|
26
24
|
parent_hash: res.parent_block_hash,
|
|
27
|
-
status: res.status,
|
|
28
25
|
transactions: Object.values(res.transactions)
|
|
29
26
|
.map((value) => 'transaction_hash' in value && value.transaction_hash)
|
|
30
27
|
.filter(Boolean) as Array<string>,
|
|
@@ -35,6 +32,7 @@ export class SequencerAPIResponseParser extends ResponseParser {
|
|
|
35
32
|
res: Sequencer.GetTransactionResponse
|
|
36
33
|
): GetTransactionResponse {
|
|
37
34
|
return {
|
|
35
|
+
...res,
|
|
38
36
|
calldata: 'calldata' in res.transaction ? (res.transaction.calldata as Array<string>) : [],
|
|
39
37
|
contract_address:
|
|
40
38
|
'contract_address' in res.transaction ? res.transaction.contract_address : undefined,
|
|
@@ -62,12 +60,21 @@ export class SequencerAPIResponseParser extends ResponseParser {
|
|
|
62
60
|
): GetTransactionReceiptResponse {
|
|
63
61
|
return {
|
|
64
62
|
transaction_hash: res.transaction_hash,
|
|
65
|
-
actual_fee: 'actual_fee' in res ? res.actual_fee : undefined,
|
|
66
63
|
status: res.status,
|
|
67
|
-
status_data: undefined,
|
|
68
64
|
messages_sent: res.l2_to_l1_messages as any, // TODO: parse
|
|
69
65
|
events: res.events as any,
|
|
70
|
-
|
|
66
|
+
...('block_hash' in res && { block_hash: res.block_hash }),
|
|
67
|
+
...('block_number' in res && { block_number: res.block_number }),
|
|
68
|
+
...('actual_fee' in res && { actual_fee: res.actual_fee }),
|
|
69
|
+
...('transaction_index' in res && { transaction_index: res.transaction_index }),
|
|
70
|
+
...('execution_resources' in res && { execution_resources: res.execution_resources }),
|
|
71
|
+
...('l1_to_l2_consumed_message' in res && {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
73
|
+
l1_to_l2_consumed_message: res['l1_to_l2_consumed_message'],
|
|
74
|
+
}),
|
|
75
|
+
...('transaction_failure_reason' in res && {
|
|
76
|
+
transaction_failure_reason: res.transaction_failure_reason,
|
|
77
|
+
}),
|
|
71
78
|
};
|
|
72
79
|
}
|
|
73
80
|
|
package/types/api/openrpc.d.ts
CHANGED
|
@@ -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;
|