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,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: {
@@ -1,6 +1,6 @@
1
1
  export * from './lib';
2
2
  export * as api from './api';
3
- export { Calldata, Overrides, RawArgs } from './api';
3
+ export { Calldata, Overrides } from './api';
4
4
  export * from './signer';
5
5
  export * from './contract';
6
6
  export * from './account';
@@ -1,16 +1,50 @@
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 declare type RawArgs = {
9
+ [inputName: string]: string | string[] | {
10
+ type: 'struct';
11
+ [k: string]: BigNumberish;
12
+ };
13
+ } | string[];
14
+ export interface ContractClass {
15
+ program: CompressedProgram;
16
+ entry_points_by_type: RPC.ContractClass['entry_points_by_type'];
17
+ abi?: Abi;
18
+ }
19
+ export declare type UniversalDeployerContractPayload = {
20
+ classHash: BigNumberish;
21
+ salt: string;
22
+ unique: boolean;
23
+ constructorCalldata?: RawArgs;
24
+ isDevnet?: boolean;
25
+ };
6
26
  export declare type DeployContractPayload = {
7
27
  contract: CompiledContract | string;
8
28
  constructorCalldata?: RawCalldata;
9
29
  addressSalt?: string;
10
30
  };
31
+ export declare type DeployAccountContractPayload = {
32
+ classHash: BigNumberish;
33
+ constructorCalldata?: RawCalldata;
34
+ addressSalt?: BigNumberish;
35
+ contractAddress?: string;
36
+ };
37
+ export declare type DeployAccountContractTransaction = Omit<DeployAccountContractPayload, 'contractAddress'> & {
38
+ signature?: Signature;
39
+ };
11
40
  export declare type DeclareContractPayload = {
12
41
  contract: CompiledContract | string;
13
- version?: BigNumberish;
42
+ classHash: BigNumberish;
43
+ };
44
+ export declare type DeclareContractTransaction = {
45
+ contractDefinition: ContractClass;
46
+ senderAddress: string;
47
+ signature?: Signature;
14
48
  };
15
49
  export declare type CallDetails = {
16
50
  contractAddress: string;
@@ -32,7 +66,7 @@ export declare type InvocationsDetailsWithNonce = InvocationsDetails & {
32
66
  };
33
67
  export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
34
68
  export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
35
- export declare type Type = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION';
69
+ export declare type TransactionType = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT';
36
70
  export declare type EntryPointType = 'EXTERNAL';
37
71
  export declare type CompressedProgram = string;
38
72
  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
+ };
@@ -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
+ };
@@ -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;
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  return (mod && mod.__esModule) ? mod : { "default": mod };
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.calculateContractAddressFromHash = exports.calculateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelector = exports.getSelectorFromName = exports.starknetKeccak = exports.keccakBn = exports.feeTransactionVersion = exports.transactionVersion = void 0;
31
+ exports.calculateContractAddressFromHash = exports.calculateTransactionHash = exports.calculateDeployAccountTransactionHash = exports.calculateDeclareTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelector = exports.getSelectorFromName = exports.starknetKeccak = exports.keccakBn = exports.feeTransactionVersion = exports.transactionVersion = void 0;
32
32
  var keccak_1 = require("ethereum-cryptography/keccak");
33
33
  var utils_1 = require("ethereum-cryptography/utils");
34
34
  var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
@@ -66,7 +66,7 @@ exports.starknetKeccak = starknetKeccak;
66
66
  * @returns hex selector of given abi function name
67
67
  */
68
68
  function getSelectorFromName(funcName) {
69
- // sometimes BigInteger pads the hex string with zeros, which isnt allowed in the starknet api
69
+ // sometimes BigInteger pads the hex string with zeros, which is not allowed in the starknet api
70
70
  return (0, number_1.toHex)(starknetKeccak(funcName));
71
71
  }
72
72
  exports.getSelectorFromName = getSelectorFromName;
@@ -132,6 +132,17 @@ function calculateDeployTransactionHash(contractAddress, constructorCalldata, ve
132
132
  return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.DEPLOY, version, contractAddress, getSelectorFromName('constructor'), constructorCalldata, constants_1.ZERO, chainId);
133
133
  }
134
134
  exports.calculateDeployTransactionHash = calculateDeployTransactionHash;
135
+ function calculateDeclareTransactionHash(
136
+ // contractClass: ContractClass, // Should be used once class hash is present in ContractClass
137
+ classHash, senderAddress, version, maxFee, chainId, nonce) {
138
+ return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.DECLARE, version, senderAddress, 0, [classHash], maxFee, chainId, [nonce]);
139
+ }
140
+ exports.calculateDeclareTransactionHash = calculateDeclareTransactionHash;
141
+ function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
142
+ var calldata = __spreadArray([classHash, salt], __read(constructorCalldata), false);
143
+ return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.DEPLOY_ACCOUNT, version, contractAddress, 0, calldata, maxFee, chainId, [nonce]);
144
+ }
145
+ exports.calculateDeployAccountTransactionHash = calculateDeployAccountTransactionHash;
135
146
  function calculateTransactionHash(contractAddress, version, calldata, maxFee, chainId, nonce) {
136
147
  return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.INVOKE, version, contractAddress, 0, calldata, maxFee, chainId, [nonce]);
137
148
  }
@@ -44,7 +44,7 @@ var MerkleTree = /** @class */ (function () {
44
44
  var newLeaves = [];
45
45
  for (var i = 0; i < leaves.length; i += 2) {
46
46
  if (i + 1 === leaves.length) {
47
- newLeaves.push(leaves[i]);
47
+ newLeaves.push(MerkleTree.hash(leaves[i], '0x0'));
48
48
  }
49
49
  else {
50
50
  newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
@@ -74,9 +74,7 @@ var MerkleTree = /** @class */ (function () {
74
74
  ? -1
75
75
  : this.branches.findIndex(function (b) { return b.length === branch.length; });
76
76
  var nextBranch = (_b = this.branches[currentBranchLevelIndex + 1]) !== null && _b !== void 0 ? _b : [this.root];
77
- return this.getProof(neededBranch === '0x0'
78
- ? leaf
79
- : MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf), nextBranch, newHashPath);
77
+ return this.getProof(MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf), nextBranch, newHashPath);
80
78
  };
81
79
  return MerkleTree;
82
80
  }());
@@ -13,3 +13,4 @@ export declare const toHexString: (value: string) => string;
13
13
  export declare function getDecimalString(value: string): string;
14
14
  export declare function getHexString(value: string): string;
15
15
  export declare function getHexStringArray(value: Array<string>): string[];
16
+ export declare const toCairoBool: (value: boolean) => string;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getHexStringArray = exports.getHexString = exports.getDecimalString = exports.toHexString = exports.isStringWholeNumber = exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
29
+ exports.toCairoBool = exports.getHexStringArray = exports.getHexString = exports.getDecimalString = exports.toHexString = exports.isStringWholeNumber = exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
30
30
  var bn_js_1 = __importStar(require("bn.js"));
31
31
  var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
32
32
  var encode_1 = require("./encode");
@@ -108,3 +108,5 @@ function getHexStringArray(value) {
108
108
  return value.map(function (el) { return getHexString(el); });
109
109
  }
110
110
  exports.getHexStringArray = getHexStringArray;
111
+ var toCairoBool = function (value) { return (+value).toString(); };
112
+ exports.toCairoBool = toCairoBool;
@@ -2,7 +2,7 @@
2
2
  * Map RPC Response to common interface response
3
3
  * Intersection (sequencer response ∩ (∪ rpc responses))
4
4
  */
5
- import { CallContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse } from '../../types';
5
+ import { CallContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionResponse } from '../../types';
6
6
  import { RPC } from '../../types/api';
7
7
  import { ResponseParser } from '.';
8
8
  declare type RpcGetBlockResponse = RPC.GetBlockWithTxHashesResponse & {
@@ -11,13 +11,9 @@ declare type RpcGetBlockResponse = RPC.GetBlockWithTxHashesResponse & {
11
11
  declare type GetTransactionByHashResponse = RPC.GetTransactionByHashResponse & {
12
12
  [key: string]: any;
13
13
  };
14
- declare type TransactionReceipt = RPC.TransactionReceipt & {
15
- [key: string]: any;
16
- };
17
- export declare class RPCResponseParser implements Omit<ResponseParser, 'parseDeclareContractResponse' | 'parseDeployContractResponse' | 'parseInvokeFunctionResponse'> {
14
+ export declare class RPCResponseParser implements Omit<ResponseParser, 'parseDeclareContractResponse' | 'parseDeployContractResponse' | 'parseInvokeFunctionResponse' | 'parseGetTransactionReceiptResponse'> {
18
15
  parseGetBlockResponse(res: RpcGetBlockResponse): GetBlockResponse;
19
16
  parseGetTransactionResponse(res: GetTransactionByHashResponse): GetTransactionResponse;
20
- parseGetTransactionReceiptResponse(res: TransactionReceipt): GetTransactionReceiptResponse;
21
17
  parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse;
22
18
  parseCallContractResponse(res: Array<string>): CallContractResponse;
23
19
  }
@@ -27,17 +27,6 @@ var RPCResponseParser = /** @class */ (function () {
27
27
  version: res.version,
28
28
  };
29
29
  };
30
- RPCResponseParser.prototype.parseGetTransactionReceiptResponse = function (res) {
31
- return {
32
- transaction_hash: res.transaction_hash,
33
- actual_fee: res.actual_fee,
34
- status: res.status,
35
- status_data: res.status_data,
36
- messages_sent: res.messages_sent,
37
- l1_origin_message: res.l1_origin_message,
38
- events: res.events,
39
- };
40
- };
41
30
  RPCResponseParser.prototype.parseFeeEstimateResponse = function (res) {
42
31
  return {
43
32
  overall_fee: (0, number_1.toBN)(res.overall_fee),
@@ -40,25 +40,15 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
40
40
  .filter(Boolean) });
41
41
  };
42
42
  SequencerAPIResponseParser.prototype.parseGetTransactionResponse = function (res) {
43
- return {
44
- calldata: 'calldata' in res.transaction ? res.transaction.calldata : [],
45
- contract_address: 'contract_address' in res.transaction ? res.transaction.contract_address : undefined,
46
- contract_class: 'contract_class' in res.transaction ? res.transaction.contract_class : undefined,
47
- entry_point_selector: 'entry_point_selector' in res.transaction
43
+ return __assign(__assign({}, res), { calldata: 'calldata' in res.transaction ? res.transaction.calldata : [], contract_address: 'contract_address' in res.transaction ? res.transaction.contract_address : undefined, contract_class: 'contract_class' in res.transaction ? res.transaction.contract_class : undefined, entry_point_selector: 'entry_point_selector' in res.transaction
48
44
  ? res.transaction.entry_point_selector
49
- : undefined,
50
- max_fee: 'max_fee' in res.transaction ? res.transaction.max_fee : undefined,
51
- nonce: res.transaction.nonce,
52
- sender_address: 'sender_address' in res.transaction
45
+ : undefined, max_fee: 'max_fee' in res.transaction ? res.transaction.max_fee : undefined, nonce: res.transaction.nonce, sender_address: 'sender_address' in res.transaction
53
46
  ? res.transaction.sender_address
54
- : undefined,
55
- signature: 'signature' in res.transaction ? res.transaction.signature : undefined,
56
- transaction_hash: 'transaction_hash' in res.transaction ? res.transaction.transaction_hash : undefined,
57
- version: 'version' in res.transaction ? res.transaction.version : undefined,
58
- };
47
+ : undefined, signature: 'signature' in res.transaction ? res.transaction.signature : undefined, transaction_hash: 'transaction_hash' in res.transaction ? res.transaction.transaction_hash : undefined, version: 'version' in res.transaction ? res.transaction.version : undefined });
59
48
  };
60
49
  SequencerAPIResponseParser.prototype.parseGetTransactionReceiptResponse = function (res) {
61
50
  return __assign(__assign(__assign(__assign(__assign(__assign(__assign({ transaction_hash: res.transaction_hash, status: res.status, messages_sent: res.l2_to_l1_messages, events: res.events }, ('block_hash' in res && { block_hash: res.block_hash })), ('block_number' in res && { block_number: res.block_number })), ('actual_fee' in res && { actual_fee: res.actual_fee })), ('transaction_index' in res && { transaction_index: res.transaction_index })), ('execution_resources' in res && { execution_resources: res.execution_resources })), ('l1_to_l2_consumed_message' in res && {
51
+ // eslint-disable-next-line @typescript-eslint/dot-notation
62
52
  l1_to_l2_consumed_message: res['l1_to_l2_consumed_message'],
63
53
  })), ('transaction_failure_reason' in res && {
64
54
  transaction_failure_reason: res.transaction_failure_reason,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "4.8.0",
3
+ "version": "4.10.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
+ import { DeclareContractTransaction, DeployAccountContractTransaction } from '../types/lib';
3
4
  import { BigNumberish } from '../utils/number';
4
5
  import { ProviderInterface } from './interface';
5
6
  import { RpcProviderOptions } from './rpc';
@@ -16,7 +17,8 @@ export declare class Provider implements ProviderInterface {
16
17
  getChainId(): Promise<StarknetChainId>;
17
18
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
18
19
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
19
- getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
20
+ getEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
21
+ getInvokeEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
20
22
  getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
21
23
  getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
22
24
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
@@ -24,7 +26,10 @@ export declare class Provider implements ProviderInterface {
24
26
  callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
25
27
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
26
28
  deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
27
- declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
29
+ deployAccountContract(payload: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
30
+ declareContract(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
31
+ getDeclareEstimateFee(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
32
+ getDeployAccountEstimateFee(transaction: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
28
33
  getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
29
34
  waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
30
35
  }
@@ -84,11 +84,19 @@ var Provider = /** @class */ (function () {
84
84
  });
85
85
  });
86
86
  };
87
- Provider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
87
+ Provider.prototype.getEstimateFee = function (invocationWithTxType, invocationDetails, blockIdentifier) {
88
88
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
89
89
  return __awaiter(this, void 0, void 0, function () {
90
90
  return __generator(this, function (_a) {
91
- return [2 /*return*/, this.provider.getEstimateFee(invocation, invocationDetails, blockIdentifier)];
91
+ return [2 /*return*/, this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier)];
92
+ });
93
+ });
94
+ };
95
+ Provider.prototype.getInvokeEstimateFee = function (invocationWithTxType, invocationDetails, blockIdentifier) {
96
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ return __generator(this, function (_a) {
99
+ return [2 /*return*/, this.provider.getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier)];
92
100
  });
93
101
  });
94
102
  };
@@ -143,13 +151,32 @@ var Provider = /** @class */ (function () {
143
151
  });
144
152
  });
145
153
  };
146
- Provider.prototype.declareContract = function (payload) {
154
+ Provider.prototype.deployAccountContract = function (payload, details) {
147
155
  return __awaiter(this, void 0, void 0, function () {
148
156
  return __generator(this, function (_a) {
149
- return [2 /*return*/, this.provider.declareContract(payload)];
157
+ return [2 /*return*/, this.provider.deployAccountContract(payload, details)];
150
158
  });
151
159
  });
152
160
  };
161
+ Provider.prototype.declareContract = function (transaction, details) {
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ return __generator(this, function (_a) {
164
+ return [2 /*return*/, this.provider.declareContract(transaction, details)];
165
+ });
166
+ });
167
+ };
168
+ Provider.prototype.getDeclareEstimateFee = function (transaction, details, blockIdentifier) {
169
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ return __generator(this, function (_a) {
172
+ return [2 /*return*/, this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier)];
173
+ });
174
+ });
175
+ };
176
+ Provider.prototype.getDeployAccountEstimateFee = function (transaction, details, blockIdentifier) {
177
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
178
+ return this.provider.getDeployAccountEstimateFee(transaction, details, blockIdentifier);
179
+ };
153
180
  Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
154
181
  return __awaiter(this, void 0, void 0, function () {
155
182
  return __generator(this, function (_a) {
@@ -1,5 +1,6 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import type { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
2
+ import type { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
+ import { DeclareContractTransaction, DeployAccountContractPayload, DeployAccountContractTransaction } from '../types/lib';
3
4
  import type { BigNumberish } from '../utils/number';
4
5
  import { BlockIdentifier } from './utils';
5
6
  export declare abstract class ProviderInterface {
@@ -78,14 +79,15 @@ export declare abstract class ProviderInterface {
78
79
  */
79
80
  abstract deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
80
81
  /**
81
- * Declares a given compiled contract (json) to starknet
82
+ * Deploys a given compiled Account contract (json) to starknet
82
83
  *
83
84
  * @param payload payload to be deployed containing:
84
85
  * - compiled contract code
85
- * - optional version
86
+ * - constructor calldata
87
+ * - address salt
86
88
  * @returns a confirmation of sending a transaction on the starknet contract
87
89
  */
88
- abstract declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
90
+ abstract deployAccountContract(payload: DeployAccountContractPayload, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
89
91
  /**
90
92
  * Invokes a function on starknet
91
93
  * @deprecated This method wont be supported as soon as fees are mandatory
@@ -103,7 +105,21 @@ export declare abstract class ProviderInterface {
103
105
  */
104
106
  abstract invokeFunction(invocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
105
107
  /**
106
- * Estimates the fee for a given transaction
108
+ * Declares a given compiled contract (json) to starknet
109
+ * @param transaction transaction payload to be deployed containing:
110
+ * - compiled contract code
111
+ * - sender address
112
+ * - signature
113
+ * @param details Invocation Details containing:
114
+ * - nonce
115
+ * - optional version
116
+ * - optional maxFee
117
+ * @returns a confirmation of sending a transaction on the starknet contract
118
+ */
119
+ abstract declareContract(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
120
+ /**
121
+ * Estimates the fee for a given INVOKE transaction
122
+ * @deprecated Please use getInvokeEstimateFee or getDeclareEstimateFee instead
107
123
  *
108
124
  * @param invocation the invocation object containing:
109
125
  * - contractAddress - the address of the contract
@@ -117,6 +133,52 @@ export declare abstract class ProviderInterface {
117
133
  * @returns the estimated fee
118
134
  */
119
135
  abstract getEstimateFee(invocation: Invocation, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
136
+ /**
137
+ * Estimates the fee for a given INVOKE transaction
138
+ *
139
+ * @param invocation the invocation object containing:
140
+ * - contractAddress - the address of the contract
141
+ * - entrypoint - the entrypoint of the contract
142
+ * - calldata - (defaults to []) the calldata
143
+ * - signature - (defaults to []) the signature
144
+ * @param blockIdentifier - block identifier
145
+ * @param details - optional details containing:
146
+ * - nonce - optional nonce
147
+ * - version - optional version
148
+ * @returns the estimated fee
149
+ */
150
+ abstract getInvokeEstimateFee(invocation: Invocation, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
151
+ /**
152
+ * Estimates the fee for a given DECLARE transaction
153
+ *
154
+ * @param transaction transaction payload to be declared containing:
155
+ * - compiled contract code
156
+ * - sender address
157
+ * - signature - (defaults to []) the signature
158
+ * @param details - optional details containing:
159
+ * - nonce
160
+ * - version - optional version
161
+ * - optional maxFee
162
+ * @param blockIdentifier - block identifier
163
+ * @returns the estimated fee
164
+ */
165
+ abstract getDeclareEstimateFee(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
166
+ /**
167
+ * Estimates the fee for a given DEPLOY_ACCOUNT transaction
168
+ *
169
+ * @param transaction transaction payload to be deployed containing:
170
+ * - classHash
171
+ * - constructorCalldata
172
+ * - addressSalt
173
+ * - signature - (defaults to []) the signature
174
+ * @param details - optional details containing:
175
+ * - nonce
176
+ * - version - optional version
177
+ * - optional maxFee
178
+ * @param blockIdentifier - block identifier
179
+ * @returns the estimated fee
180
+ */
181
+ abstract getDeployAccountEstimateFee(transaction: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
120
182
  /**
121
183
  * Wait for the transaction to be accepted
122
184
  * @param txHash - transaction hash
package/provider/rpc.d.ts CHANGED
@@ -1,16 +1,19 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
3
  import { RPC } from '../types/api';
4
+ import { DeclareContractTransaction, DeployAccountContractPayload, DeployAccountContractTransaction } from '../types/lib';
4
5
  import { BigNumberish } from '../utils/number';
5
6
  import { ProviderInterface } from './interface';
6
7
  import { BlockIdentifier } from './utils';
7
8
  export declare type RpcProviderOptions = {
8
9
  nodeUrl: string;
9
10
  retries?: number;
11
+ headers?: object;
10
12
  };
11
13
  export declare class RpcProvider implements ProviderInterface {
12
14
  nodeUrl: string;
13
15
  chainId: StarknetChainId;
16
+ headers: object;
14
17
  private responseParser;
15
18
  private retries;
16
19
  constructor(optionsOrProvider: RpcProviderOptions);
@@ -33,11 +36,15 @@ export declare class RpcProvider implements ProviderInterface {
33
36
  getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
34
37
  getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse>;
35
38
  getClass(classHash: RPC.Felt): Promise<RPC.ContractClass>;
36
- getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<RPC.ContractClass>;
39
+ getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
37
40
  getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
38
41
  getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
39
- declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
42
+ getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
43
+ getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
44
+ getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
45
+ declareContract({ contractDefinition, signature, senderAddress }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
40
46
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
47
+ deployAccountContract({ classHash, constructorCalldata, addressSalt, }: DeployAccountContractPayload): Promise<DeployContractResponse>;
41
48
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
42
49
  callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
43
50
  traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace>;