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
@@ -61,6 +61,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
61
61
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
62
  }
63
63
  };
64
+ var __read = (this && this.__read) || function (o, n) {
65
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
66
+ if (!m) return o;
67
+ var i = m.call(o), r, ar = [], e;
68
+ try {
69
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
70
+ }
71
+ catch (error) { e = { error: error }; }
72
+ finally {
73
+ try {
74
+ if (r && !r.done && (m = i["return"])) m.call(i);
75
+ }
76
+ finally { if (e) throw e.error; }
77
+ }
78
+ return ar;
79
+ };
80
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
81
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
82
+ if (ar || !(i in from)) {
83
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
84
+ ar[i] = from[i];
85
+ }
86
+ }
87
+ return to.concat(ar || Array.prototype.slice.call(from));
88
+ };
64
89
  Object.defineProperty(exports, "__esModule", { value: true });
65
90
  exports.Account = void 0;
66
91
  var constants_1 = require("../constants");
@@ -68,6 +93,7 @@ var default_1 = require("../provider/default");
68
93
  var signer_1 = require("../signer");
69
94
  var hash_1 = require("../utils/hash");
70
95
  var number_1 = require("../utils/number");
96
+ var provider_1 = require("../utils/provider");
71
97
  var stark_1 = require("../utils/stark");
72
98
  var transaction_1 = require("../utils/transaction");
73
99
  var typedData_1 = require("../utils/typedData");
@@ -87,7 +113,14 @@ var Account = /** @class */ (function (_super) {
87
113
  });
88
114
  });
89
115
  };
90
- Account.prototype.estimateFee = function (calls, _a) {
116
+ Account.prototype.estimateFee = function (calls, estimateFeeDetails) {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ return __generator(this, function (_a) {
119
+ return [2 /*return*/, this.estimateInvokeFee(calls, estimateFeeDetails)];
120
+ });
121
+ });
122
+ };
123
+ Account.prototype.estimateInvokeFee = function (calls, _a) {
91
124
  var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
92
125
  return __awaiter(this, void 0, void 0, function () {
93
126
  var transactions, nonce, _c, _d, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
@@ -120,7 +153,7 @@ var Account = /** @class */ (function (_super) {
120
153
  case 5:
121
154
  signature = _e.sent();
122
155
  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)];
156
+ return [4 /*yield*/, _super.prototype.getInvokeEstimateFee.call(this, { contractAddress: this.address, calldata: calldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
124
157
  case 6:
125
158
  response = _e.sent();
126
159
  suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
@@ -129,50 +162,125 @@ var Account = /** @class */ (function (_super) {
129
162
  });
130
163
  });
131
164
  };
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
- */
165
+ Account.prototype.estimateDeclareFee = function (_a, _b) {
166
+ var classHash = _a.classHash, contract = _a.contract;
167
+ var _c = _b === void 0 ? {} : _b, blockIdentifier = _c.blockIdentifier, providedNonce = _c.nonce;
168
+ return __awaiter(this, void 0, void 0, function () {
169
+ var nonce, _d, _e, version, chainId, contractDefinition, signature, response, suggestedMaxFee;
170
+ return __generator(this, function (_f) {
171
+ switch (_f.label) {
172
+ case 0:
173
+ _d = number_1.toBN;
174
+ if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
175
+ _e = providedNonce;
176
+ return [3 /*break*/, 3];
177
+ case 1: return [4 /*yield*/, this.getNonce()];
178
+ case 2:
179
+ _e = (_f.sent());
180
+ _f.label = 3;
181
+ case 3:
182
+ nonce = _d.apply(void 0, [_e]);
183
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
184
+ return [4 /*yield*/, this.getChainId()];
185
+ case 4:
186
+ chainId = _f.sent();
187
+ contractDefinition = (0, provider_1.parseContract)(contract);
188
+ return [4 /*yield*/, this.signer.signDeclareTransaction({
189
+ classHash: classHash,
190
+ senderAddress: this.address,
191
+ chainId: chainId,
192
+ maxFee: constants_1.ZERO,
193
+ version: version,
194
+ nonce: nonce,
195
+ })];
196
+ case 5:
197
+ signature = _f.sent();
198
+ return [4 /*yield*/, _super.prototype.getDeclareEstimateFee.call(this, { senderAddress: this.address, signature: signature, contractDefinition: contractDefinition }, { version: version, nonce: nonce }, blockIdentifier)];
199
+ case 6:
200
+ response = _f.sent();
201
+ suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
202
+ return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ Account.prototype.estimateAccountDeployFee = function (_a, _b) {
208
+ var classHash = _a.classHash, _c = _a.addressSalt, addressSalt = _c === void 0 ? 0 : _c, _d = _a.constructorCalldata, constructorCalldata = _d === void 0 ? [] : _d, providedContractAddress = _a.contractAddress;
209
+ var _e = _b === void 0 ? {} : _b, blockIdentifier = _e.blockIdentifier, providedNonce = _e.nonce;
210
+ return __awaiter(this, void 0, void 0, function () {
211
+ var nonce, _f, _g, version, chainId, contractAddress, signature, response, suggestedMaxFee;
212
+ return __generator(this, function (_h) {
213
+ switch (_h.label) {
214
+ case 0:
215
+ _f = number_1.toBN;
216
+ if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
217
+ _g = providedNonce;
218
+ return [3 /*break*/, 3];
219
+ case 1: return [4 /*yield*/, this.getNonce()];
220
+ case 2:
221
+ _g = (_h.sent());
222
+ _h.label = 3;
223
+ case 3:
224
+ nonce = _f.apply(void 0, [_g]);
225
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
226
+ return [4 /*yield*/, this.getChainId()];
227
+ case 4:
228
+ chainId = _h.sent();
229
+ contractAddress = providedContractAddress !== null && providedContractAddress !== void 0 ? providedContractAddress : (0, hash_1.calculateContractAddressFromHash)(addressSalt, classHash, constructorCalldata, 0);
230
+ return [4 /*yield*/, this.signer.signDeployAccountTransaction({
231
+ classHash: classHash,
232
+ contractAddress: contractAddress,
233
+ chainId: chainId,
234
+ maxFee: constants_1.ZERO,
235
+ version: version,
236
+ nonce: nonce,
237
+ addressSalt: addressSalt,
238
+ constructorCalldata: constructorCalldata,
239
+ })];
240
+ case 5:
241
+ signature = _h.sent();
242
+ return [4 /*yield*/, _super.prototype.getDeployAccountEstimateFee.call(this, { classHash: classHash, addressSalt: addressSalt, constructorCalldata: constructorCalldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
243
+ case 6:
244
+ response = _h.sent();
245
+ suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
246
+ return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
247
+ }
248
+ });
249
+ });
250
+ };
142
251
  Account.prototype.execute = function (calls, abis, transactionsDetail) {
143
- var _a;
252
+ var _a, _b;
144
253
  if (abis === void 0) { abis = undefined; }
145
254
  if (transactionsDetail === void 0) { transactionsDetail = {}; }
146
255
  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) {
256
+ var transactions, nonce, _c, _d, maxFee, _e, version, chainId, signerDetails, signature, calldata;
257
+ return __generator(this, function (_f) {
258
+ switch (_f.label) {
150
259
  case 0:
151
260
  transactions = Array.isArray(calls) ? calls : [calls];
152
- _b = number_1.toBN;
261
+ _c = number_1.toBN;
153
262
  if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
154
- _c = _a;
263
+ _d = _a;
155
264
  return [3 /*break*/, 3];
156
265
  case 1: return [4 /*yield*/, this.getNonce()];
157
266
  case 2:
158
- _c = (_d.sent());
159
- _d.label = 3;
267
+ _d = (_f.sent());
268
+ _f.label = 3;
160
269
  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;
270
+ nonce = _c.apply(void 0, [_d]);
271
+ if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0)) return [3 /*break*/, 4];
272
+ _e = _b;
165
273
  return [3 /*break*/, 6];
166
- case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
274
+ case 4: return [4 /*yield*/, this.getSuggestedMaxFee({ type: 'INVOKE', payload: calls }, transactionsDetail)];
167
275
  case 5:
168
- suggestedMaxFee = (_d.sent()).suggestedMaxFee;
169
- maxFee = suggestedMaxFee.toString();
170
- _d.label = 6;
276
+ _e = (_f.sent());
277
+ _f.label = 6;
171
278
  case 6:
279
+ maxFee = _e;
172
280
  version = (0, number_1.toBN)(hash_1.transactionVersion);
173
281
  return [4 /*yield*/, this.getChainId()];
174
282
  case 7:
175
- chainId = _d.sent();
283
+ chainId = _f.sent();
176
284
  signerDetails = {
177
285
  walletAddress: this.address,
178
286
  nonce: nonce,
@@ -182,7 +290,7 @@ var Account = /** @class */ (function (_super) {
182
290
  };
183
291
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
184
292
  case 8:
185
- signature = _d.sent();
293
+ signature = _f.sent();
186
294
  calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
187
295
  return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, calldata: calldata, signature: signature }, {
188
296
  nonce: nonce,
@@ -193,13 +301,140 @@ var Account = /** @class */ (function (_super) {
193
301
  });
194
302
  });
195
303
  };
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
- */
304
+ Account.prototype.declare = function (_a, transactionsDetail) {
305
+ var _b, _c;
306
+ var classHash = _a.classHash, contract = _a.contract;
307
+ if (transactionsDetail === void 0) { transactionsDetail = {}; }
308
+ return __awaiter(this, void 0, void 0, function () {
309
+ var nonce, _d, _e, maxFee, _f, version, chainId, signature, contractDefinition;
310
+ return __generator(this, function (_g) {
311
+ switch (_g.label) {
312
+ case 0:
313
+ _d = number_1.toBN;
314
+ if (!((_b = transactionsDetail.nonce) !== null && _b !== void 0)) return [3 /*break*/, 1];
315
+ _e = _b;
316
+ return [3 /*break*/, 3];
317
+ case 1: return [4 /*yield*/, this.getNonce()];
318
+ case 2:
319
+ _e = (_g.sent());
320
+ _g.label = 3;
321
+ case 3:
322
+ nonce = _d.apply(void 0, [_e]);
323
+ if (!((_c = transactionsDetail.maxFee) !== null && _c !== void 0)) return [3 /*break*/, 4];
324
+ _f = _c;
325
+ return [3 /*break*/, 6];
326
+ case 4: return [4 /*yield*/, this.getSuggestedMaxFee({ type: 'DECLARE', payload: { classHash: classHash, contract: contract } }, transactionsDetail)];
327
+ case 5:
328
+ _f = (_g.sent());
329
+ _g.label = 6;
330
+ case 6:
331
+ maxFee = _f;
332
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
333
+ return [4 /*yield*/, this.getChainId()];
334
+ case 7:
335
+ chainId = _g.sent();
336
+ return [4 /*yield*/, this.signer.signDeclareTransaction({
337
+ classHash: classHash,
338
+ senderAddress: this.address,
339
+ chainId: chainId,
340
+ maxFee: maxFee,
341
+ version: version,
342
+ nonce: nonce,
343
+ })];
344
+ case 8:
345
+ signature = _g.sent();
346
+ contractDefinition = (0, provider_1.parseContract)(contract);
347
+ return [2 /*return*/, this.declareContract({ contractDefinition: contractDefinition, senderAddress: this.address, signature: signature }, {
348
+ nonce: nonce,
349
+ maxFee: maxFee,
350
+ version: version,
351
+ })];
352
+ }
353
+ });
354
+ });
355
+ };
356
+ Account.prototype.deploy = function (_a, additionalCalls, // support multicall
357
+ transactionsDetail) {
358
+ var classHash = _a.classHash, salt = _a.salt, _b = _a.unique, unique = _b === void 0 ? true : _b, _c = _a.constructorCalldata, constructorCalldata = _c === void 0 ? [] : _c, _d = _a.isDevnet, isDevnet = _d === void 0 ? false : _d;
359
+ if (additionalCalls === void 0) { additionalCalls = []; }
360
+ if (transactionsDetail === void 0) { transactionsDetail = {}; }
361
+ return __awaiter(this, void 0, void 0, function () {
362
+ var compiledConstructorCallData, callsArray;
363
+ return __generator(this, function (_e) {
364
+ compiledConstructorCallData = (0, stark_1.compileCalldata)(constructorCalldata);
365
+ callsArray = Array.isArray(additionalCalls) ? additionalCalls : [additionalCalls];
366
+ return [2 /*return*/, this.execute(__spreadArray([
367
+ {
368
+ contractAddress: isDevnet ? constants_1.UDC.ADDRESS_DEVNET : constants_1.UDC.ADDRESS,
369
+ entrypoint: constants_1.UDC.ENTRYPOINT,
370
+ calldata: __spreadArray([
371
+ classHash,
372
+ salt,
373
+ (0, number_1.toCairoBool)(unique),
374
+ compiledConstructorCallData.length
375
+ ], __read(compiledConstructorCallData), false),
376
+ }
377
+ ], __read(callsArray), false), undefined, transactionsDetail)];
378
+ });
379
+ });
380
+ };
381
+ Account.prototype.deployAccount = function (_a, transactionsDetail) {
382
+ var _b, _c;
383
+ var classHash = _a.classHash, _d = _a.constructorCalldata, constructorCalldata = _d === void 0 ? [] : _d, _e = _a.addressSalt, addressSalt = _e === void 0 ? 0 : _e, providedContractAddress = _a.contractAddress;
384
+ if (transactionsDetail === void 0) { transactionsDetail = {}; }
385
+ return __awaiter(this, void 0, void 0, function () {
386
+ var nonce, _f, _g, version, chainId, contractAddress, maxFee, _h, signature;
387
+ return __generator(this, function (_j) {
388
+ switch (_j.label) {
389
+ case 0:
390
+ _f = number_1.toBN;
391
+ if (!((_b = transactionsDetail.nonce) !== null && _b !== void 0)) return [3 /*break*/, 1];
392
+ _g = _b;
393
+ return [3 /*break*/, 3];
394
+ case 1: return [4 /*yield*/, this.getNonce()];
395
+ case 2:
396
+ _g = (_j.sent());
397
+ _j.label = 3;
398
+ case 3:
399
+ nonce = _f.apply(void 0, [_g]);
400
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
401
+ return [4 /*yield*/, this.getChainId()];
402
+ case 4:
403
+ chainId = _j.sent();
404
+ contractAddress = providedContractAddress !== null && providedContractAddress !== void 0 ? providedContractAddress : (0, hash_1.calculateContractAddressFromHash)(addressSalt, classHash, constructorCalldata, 0);
405
+ if (!((_c = transactionsDetail.maxFee) !== null && _c !== void 0)) return [3 /*break*/, 5];
406
+ _h = _c;
407
+ return [3 /*break*/, 7];
408
+ case 5: return [4 /*yield*/, this.getSuggestedMaxFee({
409
+ type: 'DEPLOY_ACCOUNT',
410
+ payload: { classHash: classHash, constructorCalldata: constructorCalldata, addressSalt: addressSalt, contractAddress: contractAddress },
411
+ }, transactionsDetail)];
412
+ case 6:
413
+ _h = (_j.sent());
414
+ _j.label = 7;
415
+ case 7:
416
+ maxFee = _h;
417
+ return [4 /*yield*/, this.signer.signDeployAccountTransaction({
418
+ classHash: classHash,
419
+ constructorCalldata: constructorCalldata,
420
+ contractAddress: contractAddress,
421
+ addressSalt: addressSalt,
422
+ chainId: chainId,
423
+ maxFee: maxFee,
424
+ version: version,
425
+ nonce: nonce,
426
+ })];
427
+ case 8:
428
+ signature = _j.sent();
429
+ return [2 /*return*/, this.deployAccountContract({ classHash: classHash, addressSalt: addressSalt, constructorCalldata: constructorCalldata, signature: signature }, {
430
+ nonce: nonce,
431
+ maxFee: maxFee,
432
+ version: version,
433
+ })];
434
+ }
435
+ });
436
+ });
437
+ };
203
438
  Account.prototype.signMessage = function (typedData) {
204
439
  return __awaiter(this, void 0, void 0, function () {
205
440
  return __generator(this, function (_a) {
@@ -207,13 +442,6 @@ var Account = /** @class */ (function (_super) {
207
442
  });
208
443
  });
209
444
  };
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
445
  Account.prototype.hashMessage = function (typedData) {
218
446
  return __awaiter(this, void 0, void 0, function () {
219
447
  return __generator(this, function (_a) {
@@ -221,15 +449,6 @@ var Account = /** @class */ (function (_super) {
221
449
  });
222
450
  });
223
451
  };
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
452
  Account.prototype.verifyMessageHash = function (hash, signature) {
234
453
  return __awaiter(this, void 0, void 0, function () {
235
454
  var _a;
@@ -256,14 +475,6 @@ var Account = /** @class */ (function (_super) {
256
475
  });
257
476
  });
258
477
  };
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
478
  Account.prototype.verifyMessage = function (typedData, signature) {
268
479
  return __awaiter(this, void 0, void 0, function () {
269
480
  var hash;
@@ -277,6 +488,39 @@ var Account = /** @class */ (function (_super) {
277
488
  });
278
489
  });
279
490
  };
491
+ Account.prototype.getSuggestedMaxFee = function (estimateFeeAction, details) {
492
+ return __awaiter(this, void 0, void 0, function () {
493
+ var feeEstimate, _a;
494
+ return __generator(this, function (_b) {
495
+ switch (_b.label) {
496
+ case 0:
497
+ _a = estimateFeeAction.type;
498
+ switch (_a) {
499
+ case 'INVOKE': return [3 /*break*/, 1];
500
+ case 'DECLARE': return [3 /*break*/, 3];
501
+ case 'DEPLOY_ACCOUNT': return [3 /*break*/, 5];
502
+ }
503
+ return [3 /*break*/, 7];
504
+ case 1: return [4 /*yield*/, this.estimateInvokeFee(estimateFeeAction.payload, details)];
505
+ case 2:
506
+ feeEstimate = _b.sent();
507
+ return [3 /*break*/, 8];
508
+ case 3: return [4 /*yield*/, this.estimateDeclareFee(estimateFeeAction.payload, details)];
509
+ case 4:
510
+ feeEstimate = _b.sent();
511
+ return [3 /*break*/, 8];
512
+ case 5: return [4 /*yield*/, this.estimateAccountDeployFee(estimateFeeAction.payload, details)];
513
+ case 6:
514
+ feeEstimate = _b.sent();
515
+ return [3 /*break*/, 8];
516
+ case 7:
517
+ feeEstimate = { suggestedMaxFee: constants_1.ZERO, overall_fee: constants_1.ZERO };
518
+ return [3 /*break*/, 8];
519
+ case 8: return [2 /*return*/, feeEstimate.suggestedMaxFee.toString()];
520
+ }
521
+ });
522
+ });
523
+ };
280
524
  return Account;
281
525
  }(default_1.Provider));
282
526
  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, UniversalDeployerContractPayload } 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 deployed
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,49 @@ 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
+ *
70
+ * @param contractPayload transaction payload to be deployed containing:
71
+ - contract: compiled contract code
72
+ - classHash: computed class hash of compiled contract
73
+ - signature
74
+ * @param transactionsDetail Invocation Details containing:
75
+ - optional nonce
76
+ - optional version
77
+ - optional maxFee
78
+ * @returns a confirmation of sending a transaction on the starknet contract
79
+ */
80
+ abstract declare(contractPayload: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
81
+ /**
82
+ * @param deployContractPayload containing
83
+ * - classHash: computed class hash of compiled contract
84
+ * - salt: address salt
85
+ * - unique: bool if true ensure unique salt
86
+ * - calldata: constructor calldata
87
+ * @param additionalCalls - optional additional calls array to support multicall
88
+ * @param transactionsDetail Invocation Details containing:
89
+ * - optional nonce
90
+ * - optional version
91
+ * - optional maxFee
92
+ */
93
+ abstract deploy(deployContractPayload: UniversalDeployerContractPayload, additionalCalls?: AllowArray<Call>, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
94
+ /**
95
+ * Deploy the account on Starknet
96
+ *
97
+ * @param contractPayload transaction payload to be deployed containing:
98
+ - classHash: computed class hash of compiled contract
99
+ - optional constructor calldata
100
+ - optional address salt
101
+ - optional contractAddress
102
+ * @param transactionsDetail Invocation Details containing:
103
+ - optional nonce
104
+ - optional version
105
+ - optional maxFee
106
+ * @returns a confirmation of sending a transaction on the starknet contract
107
+ */
108
+ abstract deployAccount(contractPayload: DeployAccountContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeployContractResponse>;
35
109
  /**
36
110
  * Sign an JSON object for off-chain usage with the starknet private key and return the signature
37
111
  * This adds a message prefix so it cant be interchanged with transactions
@@ -53,7 +127,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
53
127
  /**
54
128
  * Verify a signature of a JSON object
55
129
  *
56
- * @param json - JSON object to be verified
130
+ * @param typedData - JSON object to be verified
57
131
  * @param signature - signature of the JSON object
58
132
  * @returns true if the signature is valid, false otherwise
59
133
  * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
@@ -69,5 +143,19 @@ export declare abstract class AccountInterface extends ProviderInterface {
69
143
  * @throws {Error} if the signature is not a valid signature
70
144
  */
71
145
  abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
146
+ /**
147
+ * Gets the nonce of the account with respect to a specific block
148
+ *
149
+ * @param {BlockIdentifier} blockIdentifier - optional blockIdentifier. Defaults to 'pending'
150
+ * @returns nonce of the account
151
+ */
72
152
  abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
153
+ /**
154
+ * Gets Suggested Max Fee based on the transaction type
155
+ *
156
+ * @param {EstimateFeeAction} estimateFeeAction
157
+ * @param {EstimateFeeDetails} details
158
+ * @returns suggestedMaxFee
159
+ */
160
+ abstract getSuggestedMaxFee(estimateFeeAction: EstimateFeeAction, details: EstimateFeeDetails): Promise<BigNumberish>;
73
161
  }
package/constants.d.ts CHANGED
@@ -7,14 +7,21 @@ export declare const MASK_250: import("bn.js");
7
7
  export declare const MASK_251: import("bn.js");
8
8
  export declare enum StarknetChainId {
9
9
  MAINNET = "0x534e5f4d41494e",
10
- TESTNET = "0x534e5f474f45524c49"
10
+ TESTNET = "0x534e5f474f45524c49",
11
+ TESTNET2 = "0x534e5f474f45524c4932"
11
12
  }
12
13
  export declare enum TransactionHashPrefix {
13
14
  DECLARE = "0x6465636c617265",
14
15
  DEPLOY = "0x6465706c6f79",
16
+ DEPLOY_ACCOUNT = "0x6465706c6f795f6163636f756e74",
15
17
  INVOKE = "0x696e766f6b65",
16
18
  L1_HANDLER = "0x6c315f68616e646c6572"
17
19
  }
20
+ export declare const UDC: {
21
+ ADDRESS: string;
22
+ ENTRYPOINT: string;
23
+ ADDRESS_DEVNET: string;
24
+ };
18
25
  /**
19
26
  * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
20
27
  * Please do not edit until the JSON changes.
package/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONSTANT_POINTS = exports.MAX_ECDSA_VAL = exports.BETA = exports.ALPHA = exports.EC_ORDER = exports.FIELD_SIZE = exports.FIELD_GEN = exports.FIELD_PRIME = exports.TransactionHashPrefix = exports.StarknetChainId = exports.MASK_251 = exports.MASK_250 = exports.TWO = exports.ONE = exports.ZERO = exports.IS_BROWSER = void 0;
3
+ exports.CONSTANT_POINTS = exports.MAX_ECDSA_VAL = exports.BETA = exports.ALPHA = exports.EC_ORDER = exports.FIELD_SIZE = exports.FIELD_GEN = exports.FIELD_PRIME = exports.UDC = exports.TransactionHashPrefix = exports.StarknetChainId = exports.MASK_251 = exports.MASK_250 = exports.TWO = exports.ONE = exports.ZERO = exports.IS_BROWSER = void 0;
4
4
  var number_1 = require("./utils/number");
5
5
  var encode_1 = require("./utils/encode");
6
6
  Object.defineProperty(exports, "IS_BROWSER", { enumerable: true, get: function () { return encode_1.IS_BROWSER; } });
@@ -13,14 +13,21 @@ var StarknetChainId;
13
13
  (function (StarknetChainId) {
14
14
  StarknetChainId["MAINNET"] = "0x534e5f4d41494e";
15
15
  StarknetChainId["TESTNET"] = "0x534e5f474f45524c49";
16
+ StarknetChainId["TESTNET2"] = "0x534e5f474f45524c4932";
16
17
  })(StarknetChainId = exports.StarknetChainId || (exports.StarknetChainId = {}));
17
18
  var TransactionHashPrefix;
18
19
  (function (TransactionHashPrefix) {
19
20
  TransactionHashPrefix["DECLARE"] = "0x6465636c617265";
20
21
  TransactionHashPrefix["DEPLOY"] = "0x6465706c6f79";
22
+ TransactionHashPrefix["DEPLOY_ACCOUNT"] = "0x6465706c6f795f6163636f756e74";
21
23
  TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
22
24
  TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
23
25
  })(TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {}));
26
+ exports.UDC = {
27
+ ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf',
28
+ ENTRYPOINT: 'deployContract',
29
+ ADDRESS_DEVNET: '0x25fcb74260022bd8ed7e8d542408941826b53345e478b8303d6f31744838a36',
30
+ };
24
31
  /**
25
32
  * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
26
33
  * Please do not edit until the JSON changes.