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.
Files changed (95) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/CONTRIBUTING.md +2 -2
  3. package/__mocks__/ERC20.json +32561 -29055
  4. package/__mocks__/l1l2_compiled.json +10107 -0
  5. package/__tests__/account.test.ts +32 -24
  6. package/__tests__/contract.test.ts +25 -14
  7. package/__tests__/defaultProvider.test.ts +19 -49
  8. package/__tests__/fixtures.ts +11 -1
  9. package/__tests__/rpcProvider.test.ts +6 -15
  10. package/__tests__/sequencerProvider.test.ts +57 -11
  11. package/__tests__/utils/merkle.test.ts +113 -3
  12. package/__tests__/utils/typedData.test.ts +3 -3
  13. package/account/default.d.ts +10 -44
  14. package/account/default.js +255 -61
  15. package/account/interface.d.ts +78 -7
  16. package/constants.d.ts +1 -0
  17. package/constants.js +1 -0
  18. package/contract/default.js +6 -6
  19. package/dist/account/default.d.ts +10 -44
  20. package/dist/account/default.js +255 -61
  21. package/dist/account/interface.d.ts +78 -7
  22. package/dist/constants.d.ts +1 -0
  23. package/dist/constants.js +1 -0
  24. package/dist/contract/default.js +6 -6
  25. package/dist/provider/default.d.ts +8 -3
  26. package/dist/provider/default.js +31 -4
  27. package/dist/provider/interface.d.ts +67 -5
  28. package/dist/provider/rpc.d.ts +7 -2
  29. package/dist/provider/rpc.js +83 -8
  30. package/dist/provider/sequencer.d.ts +9 -3
  31. package/dist/provider/sequencer.js +93 -14
  32. package/dist/signer/default.d.ts +4 -1
  33. package/dist/signer/default.js +22 -0
  34. package/dist/signer/interface.d.ts +27 -2
  35. package/dist/types/api/openrpc.d.ts +24 -2
  36. package/dist/types/api/sequencer.d.ts +43 -23
  37. package/dist/types/lib.d.ts +23 -2
  38. package/dist/types/provider.d.ts +19 -10
  39. package/dist/types/signer.d.ts +14 -1
  40. package/dist/utils/hash.d.ts +8 -0
  41. package/dist/utils/hash.js +28 -2
  42. package/dist/utils/merkle.js +4 -5
  43. package/dist/utils/number.d.ts +5 -0
  44. package/dist/utils/number.js +29 -1
  45. package/dist/utils/responseParser/rpc.d.ts +2 -6
  46. package/dist/utils/responseParser/rpc.js +0 -11
  47. package/dist/utils/responseParser/sequencer.js +11 -33
  48. package/package.json +1 -1
  49. package/provider/default.d.ts +8 -3
  50. package/provider/default.js +31 -4
  51. package/provider/interface.d.ts +67 -5
  52. package/provider/rpc.d.ts +7 -2
  53. package/provider/rpc.js +83 -8
  54. package/provider/sequencer.d.ts +9 -3
  55. package/provider/sequencer.js +93 -14
  56. package/signer/default.d.ts +4 -1
  57. package/signer/default.js +22 -0
  58. package/signer/interface.d.ts +27 -2
  59. package/src/account/default.ts +201 -53
  60. package/src/account/interface.ts +104 -6
  61. package/src/constants.ts +1 -0
  62. package/src/contract/default.ts +6 -6
  63. package/src/provider/default.ts +43 -5
  64. package/src/provider/interface.ts +92 -7
  65. package/src/provider/rpc.ts +86 -12
  66. package/src/provider/sequencer.ts +105 -13
  67. package/src/signer/default.ts +54 -2
  68. package/src/signer/interface.ts +31 -2
  69. package/src/types/api/openrpc.ts +28 -2
  70. package/src/types/api/sequencer.ts +54 -25
  71. package/src/types/lib.ts +30 -2
  72. package/src/types/provider.ts +31 -11
  73. package/src/types/signer.ts +18 -1
  74. package/src/utils/hash.ts +70 -2
  75. package/src/utils/merkle.ts +4 -5
  76. package/src/utils/number.ts +27 -0
  77. package/src/utils/responseParser/rpc.ts +4 -20
  78. package/src/utils/responseParser/sequencer.ts +14 -7
  79. package/types/api/openrpc.d.ts +24 -2
  80. package/types/api/sequencer.d.ts +43 -23
  81. package/types/lib.d.ts +23 -2
  82. package/types/provider.d.ts +19 -10
  83. package/types/signer.d.ts +14 -1
  84. package/utils/hash.d.ts +8 -0
  85. package/utils/hash.js +28 -2
  86. package/utils/merkle.js +4 -5
  87. package/utils/number.d.ts +5 -0
  88. package/utils/number.js +29 -1
  89. package/utils/responseParser/rpc.d.ts +2 -6
  90. package/utils/responseParser/rpc.js +0 -11
  91. package/utils/responseParser/sequencer.js +11 -33
  92. package/www/docs/API/account.md +60 -1
  93. package/www/docs/API/provider.md +320 -23
  94. package/www/guides/account.md +1 -1
  95. package/www/guides/erc20.md +13 -7
@@ -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,6 +1,7 @@
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';
@@ -36,8 +37,12 @@ export declare class RpcProvider implements ProviderInterface {
36
37
  getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<RPC.ContractClass>;
37
38
  getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
38
39
  getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
39
- declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
40
+ getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
41
+ getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
42
+ getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
43
+ declareContract({ contractDefinition, signature, senderAddress }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
40
44
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
45
+ deployAccountContract({ classHash, constructorCalldata, addressSalt, }: DeployAccountContractPayload): Promise<DeployContractResponse>;
41
46
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
42
47
  callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
43
48
  traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace>;
package/provider/rpc.js CHANGED
@@ -231,7 +231,7 @@ var RpcProvider = /** @class */ (function () {
231
231
  RpcProvider.prototype.getTransactionReceipt = function (txHash) {
232
232
  return __awaiter(this, void 0, void 0, function () {
233
233
  return __generator(this, function (_a) {
234
- return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash }).then(this.responseParser.parseGetTransactionReceiptResponse)];
234
+ return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash })];
235
235
  });
236
236
  });
237
237
  };
@@ -262,6 +262,14 @@ var RpcProvider = /** @class */ (function () {
262
262
  });
263
263
  };
264
264
  RpcProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
265
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ return __generator(this, function (_a) {
268
+ return [2 /*return*/, this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier)];
269
+ });
270
+ });
271
+ };
272
+ RpcProvider.prototype.getInvokeEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
265
273
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
266
274
  return __awaiter(this, void 0, void 0, function () {
267
275
  var block_id;
@@ -269,10 +277,12 @@ var RpcProvider = /** @class */ (function () {
269
277
  block_id = new utils_1.Block(blockIdentifier).identifier;
270
278
  return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
271
279
  request: {
280
+ type: 'INVOKE',
272
281
  contract_address: invocation.contractAddress,
273
282
  calldata: (0, provider_1.parseCalldata)(invocation.calldata),
274
283
  signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
275
284
  version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
285
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(invocationDetails.nonce)),
276
286
  max_fee: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.maxFee) || 0)),
277
287
  },
278
288
  block_id: block_id,
@@ -280,19 +290,72 @@ var RpcProvider = /** @class */ (function () {
280
290
  });
281
291
  });
282
292
  };
283
- RpcProvider.prototype.declareContract = function (_a) {
284
- var contract = _a.contract, version = _a.version;
293
+ // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
294
+ RpcProvider.prototype.getDeclareEstimateFee = function (_a, details, blockIdentifier) {
295
+ var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
296
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
297
+ return __awaiter(this, void 0, void 0, function () {
298
+ var block_id;
299
+ return __generator(this, function (_b) {
300
+ block_id = new utils_1.Block(blockIdentifier).identifier;
301
+ return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
302
+ request: {
303
+ type: 'DECLARE',
304
+ contract_class: {
305
+ program: contractDefinition.program,
306
+ entry_points_by_type: contractDefinition.entry_points_by_type,
307
+ abi: contractDefinition.abi, // rpc 2.0
308
+ },
309
+ sender_address: senderAddress,
310
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
311
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
312
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
313
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.maxFee) || 0)),
314
+ },
315
+ block_id: block_id,
316
+ }).then(this.responseParser.parseFeeEstimateResponse)];
317
+ });
318
+ });
319
+ };
320
+ RpcProvider.prototype.getDeployAccountEstimateFee = function (_a, details, blockIdentifier) {
321
+ var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
322
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
323
+ return __awaiter(this, void 0, void 0, function () {
324
+ var block_id;
325
+ return __generator(this, function (_b) {
326
+ block_id = new utils_1.Block(blockIdentifier).identifier;
327
+ return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
328
+ request: {
329
+ type: 'DEPLOY_ACCOUNT',
330
+ constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
331
+ class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
332
+ contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
333
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
334
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
335
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
336
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.maxFee) || 0)),
337
+ },
338
+ block_id: block_id,
339
+ }).then(this.responseParser.parseFeeEstimateResponse)];
340
+ });
341
+ });
342
+ };
343
+ // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
344
+ RpcProvider.prototype.declareContract = function (_a, details) {
345
+ var contractDefinition = _a.contractDefinition, signature = _a.signature, senderAddress = _a.senderAddress;
285
346
  return __awaiter(this, void 0, void 0, function () {
286
- var contractDefinition;
287
347
  return __generator(this, function (_b) {
288
- contractDefinition = (0, provider_1.parseContract)(contract);
289
348
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
290
349
  contract_class: {
291
350
  program: contractDefinition.program,
292
351
  entry_points_by_type: contractDefinition.entry_points_by_type,
293
352
  abi: contractDefinition.abi, // rpc 2.0
294
353
  },
295
- version: (0, number_1.toHex)((0, number_1.toBN)(version || 0)),
354
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
355
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
356
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
357
+ sender_address: senderAddress,
358
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
296
359
  })];
297
360
  });
298
361
  });
@@ -315,6 +378,18 @@ var RpcProvider = /** @class */ (function () {
315
378
  });
316
379
  });
317
380
  };
381
+ RpcProvider.prototype.deployAccountContract = function (_a) {
382
+ var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
383
+ return __awaiter(this, void 0, void 0, function () {
384
+ return __generator(this, function (_b) {
385
+ return [2 /*return*/, this.fetchEndpoint('starknet_addDeployAccountTransaction', {
386
+ constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
387
+ class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
388
+ contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
389
+ })];
390
+ });
391
+ });
392
+ };
318
393
  RpcProvider.prototype.invokeFunction = function (functionInvocation, details) {
319
394
  return __awaiter(this, void 0, void 0, function () {
320
395
  return __generator(this, function (_a) {
@@ -393,10 +468,10 @@ var RpcProvider = /** @class */ (function () {
393
468
  return [4 /*yield*/, this.getTransactionReceipt(txHash)];
394
469
  case 4:
395
470
  res = _a.sent();
396
- if (successStates.includes(res.status)) {
471
+ if (res.status && successStates.includes(res.status)) {
397
472
  onchain = true;
398
473
  }
399
- else if (errorStates.includes(res.status)) {
474
+ else if (res.status && errorStates.includes(res.status)) {
400
475
  message = res.status;
401
476
  error = new Error(message);
402
477
  error.response = res;
@@ -1,6 +1,7 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
- import { GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
2
+ import { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
+ import { CallL1Handler, GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
4
+ import { DeclareContractTransaction, DeployAccountContractTransaction } from '../types/lib';
4
5
  import { BigNumberish } from '../utils/number';
5
6
  import { ProviderInterface } from './interface';
6
7
  import { BlockIdentifier } from './utils';
@@ -37,8 +38,12 @@ export declare class SequencerProvider implements ProviderInterface {
37
38
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
38
39
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
39
40
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
40
- declareContract({ contract, }: DeclareContractPayload): Promise<DeclareContractResponse>;
41
+ deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
42
+ declareContract({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
41
43
  getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
44
+ getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
45
+ getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
46
+ getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
42
47
  getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
43
48
  waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
44
49
  /**
@@ -65,5 +70,6 @@ export declare class SequencerProvider implements ProviderInterface {
65
70
  * @returns the transaction trace
66
71
  */
67
72
  getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
73
+ estimateMessageFee({ from_address, to_address, entry_point_selector, payload }: CallL1Handler, blockIdentifier?: BlockIdentifier): Promise<Sequencer.EstimateFeeResponse>;
68
74
  }
69
75
  export {};
@@ -123,7 +123,12 @@ var SequencerProvider = /** @class */ (function () {
123
123
  return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
124
124
  };
125
125
  SequencerProvider.prototype.getFetchMethod = function (endpoint) {
126
- var postMethodEndpoints = ['add_transaction', 'call_contract', 'estimate_fee'];
126
+ var postMethodEndpoints = [
127
+ 'add_transaction',
128
+ 'call_contract',
129
+ 'estimate_fee',
130
+ 'estimate_message_fee',
131
+ ];
127
132
  return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
128
133
  };
129
134
  SequencerProvider.prototype.getQueryString = function (query) {
@@ -152,22 +157,22 @@ var SequencerProvider = /** @class */ (function () {
152
157
  };
153
158
  // typesafe fetch
154
159
  SequencerProvider.prototype.fetchEndpoint = function (endpoint) {
155
- // typescript type magiuc to create a nice fitting function interface
160
+ // typescript type magic to create a nice fitting function interface
156
161
  var _a = []; // when both query and request are needed, we cant omit anything
157
162
  for (
158
- // typescript type magiuc to create a nice fitting function interface
163
+ // typescript type magic to create a nice fitting function interface
159
164
  var _i = 1 // when both query and request are needed, we cant omit anything
160
165
  ;
161
- // typescript type magiuc to create a nice fitting function interface
166
+ // typescript type magic to create a nice fitting function interface
162
167
  _i < arguments.length // when both query and request are needed, we cant omit anything
163
168
  ;
164
- // typescript type magiuc to create a nice fitting function interface
169
+ // typescript type magic to create a nice fitting function interface
165
170
  _i++ // when both query and request are needed, we cant omit anything
166
171
  ) {
167
- // typescript type magiuc to create a nice fitting function interface
172
+ // typescript type magic to create a nice fitting function interface
168
173
  _a[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
169
174
  }
170
- // typescript type magiuc to create a nice fitting function interface
175
+ // typescript type magic to create a nice fitting function interface
171
176
  var _b = __read(_a, 2), query = _b[0], request = _b[1]; // when both query and request are needed, we cant omit anything
172
177
  return __awaiter(this, void 0, void 0, function () {
173
178
  var baseUrl, method, queryString, headers, url, res, textResponse, responseBody, errorCode, err_1;
@@ -339,23 +344,48 @@ var SequencerProvider = /** @class */ (function () {
339
344
  });
340
345
  });
341
346
  };
342
- SequencerProvider.prototype.declareContract = function (_a) {
343
- var contract = _a.contract;
347
+ SequencerProvider.prototype.deployAccountContract = function (_a, details) {
348
+ var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
349
+ return __awaiter(this, void 0, void 0, function () {
350
+ return __generator(this, function (_b) {
351
+ return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
352
+ type: 'DEPLOY_ACCOUNT',
353
+ contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
354
+ constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
355
+ class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
356
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
357
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
358
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
359
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
360
+ }).then(this.responseParser.parseDeployContractResponse)];
361
+ });
362
+ });
363
+ };
364
+ SequencerProvider.prototype.declareContract = function (_a, details) {
365
+ var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
344
366
  return __awaiter(this, void 0, void 0, function () {
345
- var contractDefinition;
346
367
  return __generator(this, function (_b) {
347
- contractDefinition = (0, provider_1.parseContract)(contract);
348
368
  return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
349
369
  type: 'DECLARE',
350
370
  contract_class: contractDefinition,
351
- nonce: (0, number_1.toHex)(constants_1.ZERO),
352
- signature: [],
353
- sender_address: (0, number_1.toHex)(constants_1.ONE),
371
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
372
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
373
+ sender_address: senderAddress,
374
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
375
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 1)),
354
376
  }).then(this.responseParser.parseDeclareContractResponse)];
355
377
  });
356
378
  });
357
379
  };
358
380
  SequencerProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
381
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
382
+ return __awaiter(this, void 0, void 0, function () {
383
+ return __generator(this, function (_a) {
384
+ return [2 /*return*/, this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier)];
385
+ });
386
+ });
387
+ };
388
+ SequencerProvider.prototype.getInvokeEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
359
389
  var _a;
360
390
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
361
391
  return __awaiter(this, void 0, void 0, function () {
@@ -371,6 +401,39 @@ var SequencerProvider = /** @class */ (function () {
371
401
  });
372
402
  });
373
403
  };
404
+ SequencerProvider.prototype.getDeclareEstimateFee = function (_a, details, blockIdentifier) {
405
+ var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
406
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
407
+ return __awaiter(this, void 0, void 0, function () {
408
+ return __generator(this, function (_b) {
409
+ return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
410
+ type: 'DECLARE',
411
+ sender_address: senderAddress,
412
+ contract_class: contractDefinition,
413
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
414
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 1)),
415
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
416
+ }).then(this.responseParser.parseFeeEstimateResponse)];
417
+ });
418
+ });
419
+ };
420
+ SequencerProvider.prototype.getDeployAccountEstimateFee = function (_a, details, blockIdentifier) {
421
+ var classHash = _a.classHash, addressSalt = _a.addressSalt, constructorCalldata = _a.constructorCalldata, signature = _a.signature;
422
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
423
+ return __awaiter(this, void 0, void 0, function () {
424
+ return __generator(this, function (_b) {
425
+ return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
426
+ type: 'DEPLOY_ACCOUNT',
427
+ class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
428
+ constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata || []),
429
+ contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
430
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
431
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
432
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
433
+ }).then(this.responseParser.parseFeeEstimateResponse)];
434
+ });
435
+ });
436
+ };
374
437
  SequencerProvider.prototype.getCode = function (contractAddress, blockIdentifier) {
375
438
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
376
439
  return __awaiter(this, void 0, void 0, function () {
@@ -463,6 +526,22 @@ var SequencerProvider = /** @class */ (function () {
463
526
  });
464
527
  });
465
528
  };
529
+ SequencerProvider.prototype.estimateMessageFee = function (_a, blockIdentifier) {
530
+ var from_address = _a.from_address, to_address = _a.to_address, entry_point_selector = _a.entry_point_selector, payload = _a.payload;
531
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
532
+ return __awaiter(this, void 0, void 0, function () {
533
+ var validCallL1Handler;
534
+ return __generator(this, function (_b) {
535
+ validCallL1Handler = {
536
+ from_address: (0, number_1.getDecimalString)(from_address),
537
+ to_address: (0, number_1.getHexString)(to_address),
538
+ entry_point_selector: (0, hash_1.getSelector)(entry_point_selector),
539
+ payload: (0, number_1.getHexStringArray)(payload),
540
+ };
541
+ return [2 /*return*/, this.fetchEndpoint('estimate_message_fee', { blockIdentifier: blockIdentifier }, validCallL1Handler)];
542
+ });
543
+ });
544
+ };
466
545
  return SequencerProvider;
467
546
  }());
468
547
  exports.SequencerProvider = SequencerProvider;
@@ -1,4 +1,5 @@
1
- import { Abi, Call, InvocationsSignerDetails, KeyPair, Signature } from '../types';
1
+ import { Abi, Call, DeclareSignerDetails, InvocationsSignerDetails, KeyPair, Signature } from '../types';
2
+ import { DeployAccountSignerDetails } from '../types/signer';
2
3
  import { TypedData } from '../utils/typedData';
3
4
  import { SignerInterface } from './interface';
4
5
  export declare class Signer implements SignerInterface {
@@ -6,5 +7,7 @@ export declare class Signer implements SignerInterface {
6
7
  constructor(keyPair?: KeyPair);
7
8
  getPubKey(): Promise<string>;
8
9
  signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
10
+ signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails): Promise<Signature>;
11
+ signDeployAccountTransaction({ classHash, contractAddress, constructorCalldata, addressSalt, maxFee, version, chainId, nonce, }: DeployAccountSignerDetails): Promise<Signature>;
9
12
  signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
10
13
  }
package/signer/default.js CHANGED
@@ -66,6 +66,28 @@ var Signer = /** @class */ (function () {
66
66
  });
67
67
  });
68
68
  };
69
+ Signer.prototype.signDeclareTransaction = function (
70
+ // contractClass: ContractClass, // Should be used once class hash is present in ContractClass
71
+ _a) {
72
+ var classHash = _a.classHash, senderAddress = _a.senderAddress, chainId = _a.chainId, maxFee = _a.maxFee, version = _a.version, nonce = _a.nonce;
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var msgHash;
75
+ return __generator(this, function (_b) {
76
+ msgHash = (0, hash_1.calculateDeclareTransactionHash)(classHash, senderAddress, version, maxFee, chainId, nonce);
77
+ return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
78
+ });
79
+ });
80
+ };
81
+ Signer.prototype.signDeployAccountTransaction = function (_a) {
82
+ var classHash = _a.classHash, contractAddress = _a.contractAddress, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, maxFee = _a.maxFee, version = _a.version, chainId = _a.chainId, nonce = _a.nonce;
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var msgHash;
85
+ return __generator(this, function (_b) {
86
+ msgHash = (0, hash_1.calculateDeployAccountTransactionHash)(contractAddress, classHash, constructorCalldata, addressSalt, version, maxFee, chainId, nonce);
87
+ return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
88
+ });
89
+ });
90
+ };
69
91
  Signer.prototype.signMessage = function (typedData, accountAddress) {
70
92
  return __awaiter(this, void 0, void 0, function () {
71
93
  var msgHash;
@@ -1,4 +1,5 @@
1
- import { Abi, Call, InvocationsSignerDetails, Signature } from '../types';
1
+ import { Abi, Call, DeclareSignerDetails, InvocationsSignerDetails, Signature } from '../types';
2
+ import { DeployAccountSignerDetails } from '../types/signer';
2
3
  import { TypedData } from '../utils/typedData';
3
4
  export declare abstract class SignerInterface {
4
5
  /**
@@ -24,10 +25,34 @@ export declare abstract class SignerInterface {
24
25
  * - contractAddress - the address of the contract
25
26
  * - entrypoint - the entrypoint of the contract
26
27
  * - calldata - (defaults to []) the calldata
27
- * - signature - (defaults to []) the signature
28
28
  * @param abi (optional) the abi of the contract for better displaying
29
29
  *
30
30
  * @returns signature
31
31
  */
32
32
  abstract signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
33
+ /**
34
+ * Signs a DEPLOY_ACCOUNT transaction with the starknet private key and returns the signature
35
+ * @param transaction
36
+ * - contractAddress - the computed address of the contract
37
+ * - constructorCalldata - calldata to be passed in deploy constructor
38
+ * - addressSalt - contract address salt
39
+ * - chainId - the chainId to declare contract on
40
+ * - maxFee - maxFee for the declare transaction
41
+ * - version - transaction version
42
+ * - nonce - Nonce of the declare transaction
43
+ * @returns signature
44
+ */
45
+ abstract signDeployAccountTransaction(transaction: DeployAccountSignerDetails): Promise<Signature>;
46
+ /**
47
+ * Signs a DECLARE transaction with the starknet private key and returns the signature
48
+ * @param transaction
49
+ * - classHash - computed class hash. Will be replaced by ContractClass in future once class hash is present in CompiledContract
50
+ * - senderAddress - the address of the sender
51
+ * - chainId - the chainId to declare contract on
52
+ * - maxFee - maxFee for the declare transaction
53
+ * - version - transaction version
54
+ * - nonce - Nonce of the declare transaction
55
+ * @returns signature
56
+ */
57
+ abstract signDeclareTransaction(transaction: DeclareSignerDetails): Promise<Signature>;
33
58
  }