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
@@ -68,6 +68,7 @@ var default_1 = require("../provider/default");
68
68
  var signer_1 = require("../signer");
69
69
  var hash_1 = require("../utils/hash");
70
70
  var number_1 = require("../utils/number");
71
+ var provider_1 = require("../utils/provider");
71
72
  var stark_1 = require("../utils/stark");
72
73
  var transaction_1 = require("../utils/transaction");
73
74
  var typedData_1 = require("../utils/typedData");
@@ -87,7 +88,14 @@ var Account = /** @class */ (function (_super) {
87
88
  });
88
89
  });
89
90
  };
90
- Account.prototype.estimateFee = function (calls, _a) {
91
+ Account.prototype.estimateFee = function (calls, estimateFeeDetails) {
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ return __generator(this, function (_a) {
94
+ return [2 /*return*/, this.estimateInvokeFee(calls, estimateFeeDetails)];
95
+ });
96
+ });
97
+ };
98
+ Account.prototype.estimateInvokeFee = function (calls, _a) {
91
99
  var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
92
100
  return __awaiter(this, void 0, void 0, function () {
93
101
  var transactions, nonce, _c, _d, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
@@ -120,7 +128,7 @@ var Account = /** @class */ (function (_super) {
120
128
  case 5:
121
129
  signature = _e.sent();
122
130
  calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
123
- return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, calldata: calldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
131
+ return [4 /*yield*/, _super.prototype.getInvokeEstimateFee.call(this, { contractAddress: this.address, calldata: calldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
124
132
  case 6:
125
133
  response = _e.sent();
126
134
  suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
@@ -129,50 +137,125 @@ var Account = /** @class */ (function (_super) {
129
137
  });
130
138
  });
131
139
  };
132
- /**
133
- * Invoke execute function in account contract
134
- *
135
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
136
- *
137
- * @param calls - one or more calls to be executed
138
- * @param abis - one or more abis which can be used to display the calls
139
- * @param transactionsDetail - optional transaction details
140
- * @returns a confirmation of invoking a function on the starknet contract
141
- */
140
+ Account.prototype.estimateDeclareFee = function (_a, _b) {
141
+ var classHash = _a.classHash, contract = _a.contract;
142
+ var _c = _b === void 0 ? {} : _b, blockIdentifier = _c.blockIdentifier, providedNonce = _c.nonce;
143
+ return __awaiter(this, void 0, void 0, function () {
144
+ var nonce, _d, _e, version, chainId, contractDefinition, signature, response, suggestedMaxFee;
145
+ return __generator(this, function (_f) {
146
+ switch (_f.label) {
147
+ case 0:
148
+ _d = number_1.toBN;
149
+ if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
150
+ _e = providedNonce;
151
+ return [3 /*break*/, 3];
152
+ case 1: return [4 /*yield*/, this.getNonce()];
153
+ case 2:
154
+ _e = (_f.sent());
155
+ _f.label = 3;
156
+ case 3:
157
+ nonce = _d.apply(void 0, [_e]);
158
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
159
+ return [4 /*yield*/, this.getChainId()];
160
+ case 4:
161
+ chainId = _f.sent();
162
+ contractDefinition = (0, provider_1.parseContract)(contract);
163
+ return [4 /*yield*/, this.signer.signDeclareTransaction({
164
+ classHash: classHash,
165
+ senderAddress: this.address,
166
+ chainId: chainId,
167
+ maxFee: constants_1.ZERO,
168
+ version: version,
169
+ nonce: nonce,
170
+ })];
171
+ case 5:
172
+ signature = _f.sent();
173
+ return [4 /*yield*/, _super.prototype.getDeclareEstimateFee.call(this, { senderAddress: this.address, signature: signature, contractDefinition: contractDefinition }, { version: version, nonce: nonce }, blockIdentifier)];
174
+ case 6:
175
+ response = _f.sent();
176
+ suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
177
+ return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
178
+ }
179
+ });
180
+ });
181
+ };
182
+ Account.prototype.estimateAccountDeployFee = function (_a, _b) {
183
+ var classHash = _a.classHash, _c = _a.addressSalt, addressSalt = _c === void 0 ? 0 : _c, _d = _a.constructorCalldata, constructorCalldata = _d === void 0 ? [] : _d, providedContractAddress = _a.contractAddress;
184
+ var _e = _b === void 0 ? {} : _b, blockIdentifier = _e.blockIdentifier, providedNonce = _e.nonce;
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ var nonce, _f, _g, version, chainId, contractAddress, signature, response, suggestedMaxFee;
187
+ return __generator(this, function (_h) {
188
+ switch (_h.label) {
189
+ case 0:
190
+ _f = number_1.toBN;
191
+ if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
192
+ _g = providedNonce;
193
+ return [3 /*break*/, 3];
194
+ case 1: return [4 /*yield*/, this.getNonce()];
195
+ case 2:
196
+ _g = (_h.sent());
197
+ _h.label = 3;
198
+ case 3:
199
+ nonce = _f.apply(void 0, [_g]);
200
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
201
+ return [4 /*yield*/, this.getChainId()];
202
+ case 4:
203
+ chainId = _h.sent();
204
+ contractAddress = providedContractAddress !== null && providedContractAddress !== void 0 ? providedContractAddress : (0, hash_1.calculateContractAddressFromHash)(addressSalt, classHash, constructorCalldata, 0);
205
+ return [4 /*yield*/, this.signer.signDeployAccountTransaction({
206
+ classHash: classHash,
207
+ contractAddress: contractAddress,
208
+ chainId: chainId,
209
+ maxFee: constants_1.ZERO,
210
+ version: version,
211
+ nonce: nonce,
212
+ addressSalt: addressSalt,
213
+ constructorCalldata: constructorCalldata,
214
+ })];
215
+ case 5:
216
+ signature = _h.sent();
217
+ return [4 /*yield*/, _super.prototype.getDeployAccountEstimateFee.call(this, { classHash: classHash, addressSalt: addressSalt, constructorCalldata: constructorCalldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
218
+ case 6:
219
+ response = _h.sent();
220
+ suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
221
+ return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
222
+ }
223
+ });
224
+ });
225
+ };
142
226
  Account.prototype.execute = function (calls, abis, transactionsDetail) {
143
- var _a;
227
+ var _a, _b;
144
228
  if (abis === void 0) { abis = undefined; }
145
229
  if (transactionsDetail === void 0) { transactionsDetail = {}; }
146
230
  return __awaiter(this, void 0, void 0, function () {
147
- var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, version, chainId, signerDetails, signature, calldata;
148
- return __generator(this, function (_d) {
149
- switch (_d.label) {
231
+ var transactions, nonce, _c, _d, maxFee, _e, version, chainId, signerDetails, signature, calldata;
232
+ return __generator(this, function (_f) {
233
+ switch (_f.label) {
150
234
  case 0:
151
235
  transactions = Array.isArray(calls) ? calls : [calls];
152
- _b = number_1.toBN;
236
+ _c = number_1.toBN;
153
237
  if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
154
- _c = _a;
238
+ _d = _a;
155
239
  return [3 /*break*/, 3];
156
240
  case 1: return [4 /*yield*/, this.getNonce()];
157
241
  case 2:
158
- _c = (_d.sent());
159
- _d.label = 3;
242
+ _d = (_f.sent());
243
+ _f.label = 3;
160
244
  case 3:
161
- nonce = _b.apply(void 0, [_c]);
162
- maxFee = '0';
163
- if (!(transactionsDetail.maxFee || transactionsDetail.maxFee === 0)) return [3 /*break*/, 4];
164
- maxFee = transactionsDetail.maxFee;
245
+ nonce = _c.apply(void 0, [_d]);
246
+ if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0)) return [3 /*break*/, 4];
247
+ _e = _b;
165
248
  return [3 /*break*/, 6];
166
- case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
249
+ case 4: return [4 /*yield*/, this.getSuggestedMaxFee({ type: 'INVOKE', payload: calls }, transactionsDetail)];
167
250
  case 5:
168
- suggestedMaxFee = (_d.sent()).suggestedMaxFee;
169
- maxFee = suggestedMaxFee.toString();
170
- _d.label = 6;
251
+ _e = (_f.sent());
252
+ _f.label = 6;
171
253
  case 6:
254
+ maxFee = _e;
172
255
  version = (0, number_1.toBN)(hash_1.transactionVersion);
173
256
  return [4 /*yield*/, this.getChainId()];
174
257
  case 7:
175
- chainId = _d.sent();
258
+ chainId = _f.sent();
176
259
  signerDetails = {
177
260
  walletAddress: this.address,
178
261
  nonce: nonce,
@@ -182,7 +265,7 @@ var Account = /** @class */ (function (_super) {
182
265
  };
183
266
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
184
267
  case 8:
185
- signature = _d.sent();
268
+ signature = _f.sent();
186
269
  calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
187
270
  return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, calldata: calldata, signature: signature }, {
188
271
  nonce: nonce,
@@ -193,13 +276,115 @@ var Account = /** @class */ (function (_super) {
193
276
  });
194
277
  });
195
278
  };
196
- /**
197
- * Sign an JSON object with the starknet private key and return the signature
198
- *
199
- * @param json - JSON object to be signed
200
- * @returns the signature of the JSON object
201
- * @throws {Error} if the JSON object is not a valid JSON
202
- */
279
+ Account.prototype.declare = function (_a, transactionsDetail) {
280
+ var _b, _c;
281
+ var classHash = _a.classHash, contract = _a.contract;
282
+ if (transactionsDetail === void 0) { transactionsDetail = {}; }
283
+ return __awaiter(this, void 0, void 0, function () {
284
+ var nonce, _d, _e, maxFee, _f, version, chainId, signature, contractDefinition;
285
+ return __generator(this, function (_g) {
286
+ switch (_g.label) {
287
+ case 0:
288
+ _d = number_1.toBN;
289
+ if (!((_b = transactionsDetail.nonce) !== null && _b !== void 0)) return [3 /*break*/, 1];
290
+ _e = _b;
291
+ return [3 /*break*/, 3];
292
+ case 1: return [4 /*yield*/, this.getNonce()];
293
+ case 2:
294
+ _e = (_g.sent());
295
+ _g.label = 3;
296
+ case 3:
297
+ nonce = _d.apply(void 0, [_e]);
298
+ if (!((_c = transactionsDetail.maxFee) !== null && _c !== void 0)) return [3 /*break*/, 4];
299
+ _f = _c;
300
+ return [3 /*break*/, 6];
301
+ case 4: return [4 /*yield*/, this.getSuggestedMaxFee({ type: 'DECLARE', payload: { classHash: classHash, contract: contract } }, transactionsDetail)];
302
+ case 5:
303
+ _f = (_g.sent());
304
+ _g.label = 6;
305
+ case 6:
306
+ maxFee = _f;
307
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
308
+ return [4 /*yield*/, this.getChainId()];
309
+ case 7:
310
+ chainId = _g.sent();
311
+ return [4 /*yield*/, this.signer.signDeclareTransaction({
312
+ classHash: classHash,
313
+ senderAddress: this.address,
314
+ chainId: chainId,
315
+ maxFee: maxFee,
316
+ version: version,
317
+ nonce: nonce,
318
+ })];
319
+ case 8:
320
+ signature = _g.sent();
321
+ contractDefinition = (0, provider_1.parseContract)(contract);
322
+ return [2 /*return*/, this.declareContract({ contractDefinition: contractDefinition, senderAddress: this.address, signature: signature }, {
323
+ nonce: nonce,
324
+ maxFee: maxFee,
325
+ version: version,
326
+ })];
327
+ }
328
+ });
329
+ });
330
+ };
331
+ Account.prototype.deployAccount = function (_a, transactionsDetail) {
332
+ var _b, _c;
333
+ var classHash = _a.classHash, _d = _a.constructorCalldata, constructorCalldata = _d === void 0 ? [] : _d, _e = _a.addressSalt, addressSalt = _e === void 0 ? 0 : _e, providedContractAddress = _a.contractAddress;
334
+ if (transactionsDetail === void 0) { transactionsDetail = {}; }
335
+ return __awaiter(this, void 0, void 0, function () {
336
+ var nonce, _f, _g, version, chainId, contractAddress, maxFee, _h, signature;
337
+ return __generator(this, function (_j) {
338
+ switch (_j.label) {
339
+ case 0:
340
+ _f = number_1.toBN;
341
+ if (!((_b = transactionsDetail.nonce) !== null && _b !== void 0)) return [3 /*break*/, 1];
342
+ _g = _b;
343
+ return [3 /*break*/, 3];
344
+ case 1: return [4 /*yield*/, this.getNonce()];
345
+ case 2:
346
+ _g = (_j.sent());
347
+ _j.label = 3;
348
+ case 3:
349
+ nonce = _f.apply(void 0, [_g]);
350
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
351
+ return [4 /*yield*/, this.getChainId()];
352
+ case 4:
353
+ chainId = _j.sent();
354
+ contractAddress = providedContractAddress !== null && providedContractAddress !== void 0 ? providedContractAddress : (0, hash_1.calculateContractAddressFromHash)(addressSalt, classHash, constructorCalldata, 0);
355
+ if (!((_c = transactionsDetail.maxFee) !== null && _c !== void 0)) return [3 /*break*/, 5];
356
+ _h = _c;
357
+ return [3 /*break*/, 7];
358
+ case 5: return [4 /*yield*/, this.getSuggestedMaxFee({
359
+ type: 'DEPLOY_ACCOUNT',
360
+ payload: { classHash: classHash, constructorCalldata: constructorCalldata, addressSalt: addressSalt, contractAddress: contractAddress },
361
+ }, transactionsDetail)];
362
+ case 6:
363
+ _h = (_j.sent());
364
+ _j.label = 7;
365
+ case 7:
366
+ maxFee = _h;
367
+ return [4 /*yield*/, this.signer.signDeployAccountTransaction({
368
+ classHash: classHash,
369
+ constructorCalldata: constructorCalldata,
370
+ contractAddress: contractAddress,
371
+ addressSalt: addressSalt,
372
+ chainId: chainId,
373
+ maxFee: maxFee,
374
+ version: version,
375
+ nonce: nonce,
376
+ })];
377
+ case 8:
378
+ signature = _j.sent();
379
+ return [2 /*return*/, this.deployAccountContract({ classHash: classHash, addressSalt: addressSalt, constructorCalldata: constructorCalldata, signature: signature }, {
380
+ nonce: nonce,
381
+ maxFee: maxFee,
382
+ version: version,
383
+ })];
384
+ }
385
+ });
386
+ });
387
+ };
203
388
  Account.prototype.signMessage = function (typedData) {
204
389
  return __awaiter(this, void 0, void 0, function () {
205
390
  return __generator(this, function (_a) {
@@ -207,13 +392,6 @@ var Account = /** @class */ (function (_super) {
207
392
  });
208
393
  });
209
394
  };
210
- /**
211
- * Hash a JSON object with pederson hash and return the hash
212
- *
213
- * @param json - JSON object to be hashed
214
- * @returns the hash of the JSON object
215
- * @throws {Error} if the JSON object is not a valid JSON
216
- */
217
395
  Account.prototype.hashMessage = function (typedData) {
218
396
  return __awaiter(this, void 0, void 0, function () {
219
397
  return __generator(this, function (_a) {
@@ -221,15 +399,6 @@ var Account = /** @class */ (function (_super) {
221
399
  });
222
400
  });
223
401
  };
224
- /**
225
- * Verify a signature of a given hash
226
- * @warning This method is not recommended, use verifyMessage instead
227
- *
228
- * @param hash - JSON object to be verified
229
- * @param signature - signature of the JSON object
230
- * @returns true if the signature is valid, false otherwise
231
- * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
232
- */
233
402
  Account.prototype.verifyMessageHash = function (hash, signature) {
234
403
  return __awaiter(this, void 0, void 0, function () {
235
404
  var _a;
@@ -256,14 +425,6 @@ var Account = /** @class */ (function (_super) {
256
425
  });
257
426
  });
258
427
  };
259
- /**
260
- * Verify a signature of a JSON object
261
- *
262
- * @param hash - hash to be verified
263
- * @param signature - signature of the hash
264
- * @returns true if the signature is valid, false otherwise
265
- * @throws {Error} if the signature is not a valid signature
266
- */
267
428
  Account.prototype.verifyMessage = function (typedData, signature) {
268
429
  return __awaiter(this, void 0, void 0, function () {
269
430
  var hash;
@@ -277,6 +438,39 @@ var Account = /** @class */ (function (_super) {
277
438
  });
278
439
  });
279
440
  };
441
+ Account.prototype.getSuggestedMaxFee = function (estimateFeeAction, details) {
442
+ return __awaiter(this, void 0, void 0, function () {
443
+ var feeEstimate, _a;
444
+ return __generator(this, function (_b) {
445
+ switch (_b.label) {
446
+ case 0:
447
+ _a = estimateFeeAction.type;
448
+ switch (_a) {
449
+ case 'INVOKE': return [3 /*break*/, 1];
450
+ case 'DECLARE': return [3 /*break*/, 3];
451
+ case 'DEPLOY_ACCOUNT': return [3 /*break*/, 5];
452
+ }
453
+ return [3 /*break*/, 7];
454
+ case 1: return [4 /*yield*/, this.estimateInvokeFee(estimateFeeAction.payload, details)];
455
+ case 2:
456
+ feeEstimate = _b.sent();
457
+ return [3 /*break*/, 8];
458
+ case 3: return [4 /*yield*/, this.estimateDeclareFee(estimateFeeAction.payload, details)];
459
+ case 4:
460
+ feeEstimate = _b.sent();
461
+ return [3 /*break*/, 8];
462
+ case 5: return [4 /*yield*/, this.estimateAccountDeployFee(estimateFeeAction.payload, details)];
463
+ case 6:
464
+ feeEstimate = _b.sent();
465
+ return [3 /*break*/, 8];
466
+ case 7:
467
+ feeEstimate = { suggestedMaxFee: constants_1.ZERO, overall_fee: constants_1.ZERO };
468
+ return [3 /*break*/, 8];
469
+ case 8: return [2 /*return*/, feeEstimate.suggestedMaxFee.toString()];
470
+ }
471
+ });
472
+ });
473
+ };
280
474
  return Account;
281
475
  }(default_1.Provider));
282
476
  exports.Account = Account;
@@ -1,24 +1,56 @@
1
1
  import { ProviderInterface } from '../provider';
2
2
  import { BlockIdentifier } from '../provider/utils';
3
3
  import { SignerInterface } from '../signer';
4
- import { Abi, Call, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
4
+ import { Abi, Call, DeclareContractResponse, DeployContractResponse, EstimateFeeAction, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
5
+ import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
5
6
  import { BigNumberish } from '../utils/number';
6
7
  import { TypedData } from '../utils/typedData/types';
7
8
  export declare abstract class AccountInterface extends ProviderInterface {
8
9
  abstract address: string;
9
10
  abstract signer: SignerInterface;
10
11
  /**
11
- * Estimate Fee for a method on starknet
12
+ * @deprecated Use estimateInvokeFee or estimateDeclareFee instead
13
+ * Estimate Fee for executing an INVOKE transaction on starknet
12
14
  *
13
- * @param invocation the invocation object containing:
15
+ * @param calls the invocation object containing:
14
16
  * - contractAddress - the address of the contract
15
17
  * - entrypoint - the entrypoint of the contract
16
18
  * - calldata - (defaults to []) the calldata
17
- * - signature - (defaults to []) the signature
18
19
  *
19
- * @returns response from addTransaction
20
+ * @returns response from estimate_fee
21
+ */
22
+ abstract estimateFee(calls: AllowArray<Call>, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
23
+ /**
24
+ * Estimate Fee for executing an INVOKE transaction on starknet
25
+ *
26
+ * @param calls the invocation object containing:
27
+ * - contractAddress - the address of the contract
28
+ * - entrypoint - the entrypoint of the contract
29
+ * - calldata - (defaults to []) the calldata
30
+ *
31
+ * @returns response from estimate_fee
32
+ */
33
+ abstract estimateInvokeFee(calls: AllowArray<Call>, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
34
+ /**
35
+ * Estimate Fee for executing a DECLARE transaction on starknet
36
+ *
37
+ * @param contractPayload the payload object containing:
38
+ * - contract - the compiled contract to be declared
39
+ * - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
40
+ *
41
+ * @returns response from estimate_fee
20
42
  */
21
- abstract estimateFee(calls: Call | Call[], estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
43
+ abstract estimateDeclareFee(contractPayload: DeclareContractPayload, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
44
+ /**
45
+ * Estimate Fee for executing a DEPLOY_ACCOUNT transaction on starknet
46
+ *
47
+ * @param contractPayload the payload object containing:
48
+ * - contract - the compiled contract to be declared
49
+ * - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
50
+ *
51
+ * @returns response from estimate_fee
52
+ */
53
+ abstract estimateAccountDeployFee(contractPayload: DeployAccountContractPayload, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
22
54
  /**
23
55
  * Invoke execute function in account contract
24
56
  *
@@ -31,7 +63,34 @@ export declare abstract class AccountInterface extends ProviderInterface {
31
63
  *
32
64
  * @returns response from addTransaction
33
65
  */
34
- abstract execute(transactions: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
66
+ abstract execute(transactions: AllowArray<Call>, abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
67
+ /**
68
+ * Declares a given compiled contract (json) to starknet
69
+ * @param contractPayload transaction payload to be deployed containing:
70
+ - contract: compiled contract code
71
+ - classHash: computed class hash of compiled contract
72
+ - signature
73
+ * @param transactionsDetail Invocation Details containing:
74
+ - optional nonce
75
+ - optional version
76
+ - optional maxFee
77
+ * @returns a confirmation of sending a transaction on the starknet contract
78
+ */
79
+ abstract declare(contractPayload: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
80
+ /**
81
+ * Deploy the account on Starknet
82
+ * @param contractPayload transaction payload to be deployed containing:
83
+ * - classHash: computed class hash of compiled contract
84
+ * - constructor calldata
85
+ * - address salt
86
+ - signature
87
+ * @param transactionsDetail Invocation Details containing:
88
+ - optional nonce
89
+ - optional version
90
+ - optional maxFee
91
+ * @returns a confirmation of sending a transaction on the starknet contract
92
+ */
93
+ abstract deployAccount(contractPayload: DeployAccountContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeployContractResponse>;
35
94
  /**
36
95
  * Sign an JSON object for off-chain usage with the starknet private key and return the signature
37
96
  * This adds a message prefix so it cant be interchanged with transactions
@@ -69,5 +128,17 @@ export declare abstract class AccountInterface extends ProviderInterface {
69
128
  * @throws {Error} if the signature is not a valid signature
70
129
  */
71
130
  abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
131
+ /**
132
+ * Gets the nonce of the account with respect to a specific block
133
+ * @param {BlockIdentifier} blockIdentifier - optional blockIdentifier. Defaults to 'pending'
134
+ * @returns nonce of the account
135
+ */
72
136
  abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
137
+ /**
138
+ * Gets Suggested Max Fee based on the transaction type
139
+ * @param {EstimateFeeAction} estimateFeeAction
140
+ * @param {EstimateFeeDetails} details
141
+ * @returns suggestedMaxFee
142
+ */
143
+ abstract getSuggestedMaxFee(estimateFeeAction: EstimateFeeAction, details: EstimateFeeDetails): Promise<BigNumberish>;
73
144
  }
package/constants.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare enum StarknetChainId {
12
12
  export declare enum TransactionHashPrefix {
13
13
  DECLARE = "0x6465636c617265",
14
14
  DEPLOY = "0x6465706c6f79",
15
+ DEPLOY_ACCOUNT = "0x6465706c6f795f6163636f756e74",
15
16
  INVOKE = "0x696e766f6b65",
16
17
  L1_HANDLER = "0x6c315f68616e646c6572"
17
18
  }
package/constants.js CHANGED
@@ -18,6 +18,7 @@ var TransactionHashPrefix;
18
18
  (function (TransactionHashPrefix) {
19
19
  TransactionHashPrefix["DECLARE"] = "0x6465636c617265";
20
20
  TransactionHashPrefix["DEPLOY"] = "0x6465706c6f79";
21
+ TransactionHashPrefix["DEPLOY_ACCOUNT"] = "0x6465706c6f795f6163636f756e74";
21
22
  TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
22
23
  TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
23
24
  })(TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {}));
@@ -181,7 +181,7 @@ var Contract = /** @class */ (function () {
181
181
  function Contract(abi, address, providerOrAccount) {
182
182
  if (providerOrAccount === void 0) { providerOrAccount = provider_1.defaultProvider; }
183
183
  var _this = this;
184
- this.address = address.toLowerCase();
184
+ this.address = address && address.toLowerCase();
185
185
  this.providerOrAccount = providerOrAccount;
186
186
  this.abi = abi;
187
187
  this.structs = abi
@@ -566,7 +566,7 @@ var Contract = /** @class */ (function () {
566
566
  if (args === void 0) { args = []; }
567
567
  if (options === void 0) { options = {}; }
568
568
  // ensure contract is connected
569
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
569
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
570
570
  // validate method and args
571
571
  this.validateMethodAndArgs('INVOKE', method, args);
572
572
  var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
@@ -609,7 +609,7 @@ var Contract = /** @class */ (function () {
609
609
  var _this = this;
610
610
  return __generator(this, function (_d) {
611
611
  // ensure contract is connected
612
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
612
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
613
613
  // validate method and args
614
614
  this.validateMethodAndArgs('CALL', method, args);
615
615
  inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
@@ -631,12 +631,12 @@ var Contract = /** @class */ (function () {
631
631
  var _a;
632
632
  return __generator(this, function (_b) {
633
633
  // ensure contract is connected
634
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
634
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
635
635
  // validate method and args
636
636
  this.validateMethodAndArgs('INVOKE', method, args);
637
637
  invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
638
- if ('estimateFee' in this.providerOrAccount) {
639
- return [2 /*return*/, this.providerOrAccount.estimateFee(invocation)];
638
+ if ('estimateInvokeFee' in this.providerOrAccount) {
639
+ return [2 /*return*/, this.providerOrAccount.estimateInvokeFee(invocation)];
640
640
  }
641
641
  throw Error('Contract must be connected to the account contract to estimate');
642
642
  });
@@ -2,8 +2,9 @@ import { ProviderInterface, ProviderOptions } from '../provider';
2
2
  import { Provider } from '../provider/default';
3
3
  import { BlockIdentifier } from '../provider/utils';
4
4
  import { SignerInterface } from '../signer';
5
- import { Abi, Call, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
5
+ import { Abi, Call, DeclareContractResponse, DeployContractResponse, EstimateFeeAction, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
6
6
  import { EstimateFee, EstimateFeeDetails } from '../types/account';
7
+ import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
7
8
  import { BigNumberish } from '../utils/number';
8
9
  import { TypedData } from '../utils/typedData';
9
10
  import { AccountInterface } from './interface';
@@ -12,51 +13,16 @@ export declare class Account extends Provider implements AccountInterface {
12
13
  address: string;
13
14
  constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
14
15
  getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
15
- estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
16
- /**
17
- * Invoke execute function in account contract
18
- *
19
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
20
- *
21
- * @param calls - one or more calls to be executed
22
- * @param abis - one or more abis which can be used to display the calls
23
- * @param transactionsDetail - optional transaction details
24
- * @returns a confirmation of invoking a function on the starknet contract
25
- */
26
- execute(calls: Call | Call[], abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
27
- /**
28
- * Sign an JSON object with the starknet private key and return the signature
29
- *
30
- * @param json - JSON object to be signed
31
- * @returns the signature of the JSON object
32
- * @throws {Error} if the JSON object is not a valid JSON
33
- */
16
+ estimateFee(calls: AllowArray<Call>, estimateFeeDetails?: EstimateFeeDetails | undefined): Promise<EstimateFee>;
17
+ estimateInvokeFee(calls: AllowArray<Call>, { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
18
+ estimateDeclareFee({ classHash, contract }: DeclareContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
19
+ estimateAccountDeployFee({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
20
+ execute(calls: AllowArray<Call>, abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
21
+ declare({ classHash, contract }: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
22
+ deployAccount({ classHash, constructorCalldata, addressSalt, contractAddress: providedContractAddress, }: DeployAccountContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeployContractResponse>;
34
23
  signMessage(typedData: TypedData): Promise<Signature>;
35
- /**
36
- * Hash a JSON object with pederson hash and return the hash
37
- *
38
- * @param json - JSON object to be hashed
39
- * @returns the hash of the JSON object
40
- * @throws {Error} if the JSON object is not a valid JSON
41
- */
42
24
  hashMessage(typedData: TypedData): Promise<string>;
43
- /**
44
- * Verify a signature of a given hash
45
- * @warning This method is not recommended, use verifyMessage instead
46
- *
47
- * @param hash - JSON object to be verified
48
- * @param signature - signature of the JSON object
49
- * @returns true if the signature is valid, false otherwise
50
- * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
51
- */
52
25
  verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
53
- /**
54
- * Verify a signature of a JSON object
55
- *
56
- * @param hash - hash to be verified
57
- * @param signature - signature of the hash
58
- * @returns true if the signature is valid, false otherwise
59
- * @throws {Error} if the signature is not a valid signature
60
- */
61
26
  verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
27
+ getSuggestedMaxFee(estimateFeeAction: EstimateFeeAction, details: EstimateFeeDetails): Promise<string>;
62
28
  }