starknet 4.9.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 (65) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -3
  3. package/__tests__/account.test.ts +1 -1
  4. package/__tests__/defaultProvider.test.ts +85 -210
  5. package/__tests__/fixtures.ts +1 -1
  6. package/__tests__/rpcProvider.test.ts +4 -3
  7. package/__tests__/udc.test.ts +41 -0
  8. package/account/default.d.ts +3 -1
  9. package/account/default.js +50 -0
  10. package/account/interface.d.ts +24 -7
  11. package/constants.d.ts +7 -1
  12. package/constants.js +7 -1
  13. package/contract/default.d.ts +11 -27
  14. package/contract/default.js +104 -120
  15. package/contract/interface.d.ts +5 -2
  16. package/dist/account/default.d.ts +3 -1
  17. package/dist/account/default.js +50 -0
  18. package/dist/account/interface.d.ts +24 -7
  19. package/dist/constants.d.ts +7 -1
  20. package/dist/constants.js +7 -1
  21. package/dist/contract/default.d.ts +11 -27
  22. package/dist/contract/default.js +104 -120
  23. package/dist/contract/interface.d.ts +5 -2
  24. package/dist/provider/rpc.d.ts +3 -1
  25. package/dist/provider/rpc.js +15 -2
  26. package/dist/provider/sequencer.d.ts +4 -2
  27. package/dist/provider/sequencer.js +18 -5
  28. package/dist/signer/default.d.ts +2 -2
  29. package/dist/signer/default.js +15 -15
  30. package/dist/signer/interface.d.ts +2 -0
  31. package/dist/types/api/index.d.ts +0 -6
  32. package/dist/types/index.d.ts +1 -1
  33. package/dist/types/lib.d.ts +13 -0
  34. package/dist/utils/number.d.ts +1 -0
  35. package/dist/utils/number.js +3 -1
  36. package/package.json +1 -1
  37. package/provider/rpc.d.ts +3 -1
  38. package/provider/rpc.js +15 -2
  39. package/provider/sequencer.d.ts +4 -2
  40. package/provider/sequencer.js +18 -5
  41. package/signer/default.d.ts +2 -2
  42. package/signer/default.js +15 -15
  43. package/signer/interface.d.ts +2 -0
  44. package/src/account/default.ts +43 -3
  45. package/src/account/interface.ts +34 -7
  46. package/src/constants.ts +7 -0
  47. package/src/contract/default.ts +123 -140
  48. package/src/contract/interface.ts +5 -2
  49. package/src/provider/rpc.ts +7 -3
  50. package/src/provider/sequencer.ts +13 -4
  51. package/src/signer/default.ts +18 -18
  52. package/src/signer/interface.ts +2 -0
  53. package/src/types/api/index.ts +0 -4
  54. package/src/types/index.ts +1 -1
  55. package/src/types/lib.ts +13 -0
  56. package/src/utils/number.ts +2 -0
  57. package/types/api/index.d.ts +0 -6
  58. package/types/index.d.ts +1 -1
  59. package/types/lib.d.ts +13 -0
  60. package/utils/number.d.ts +1 -0
  61. package/utils/number.js +3 -1
  62. package/www/docs/API/account.md +122 -22
  63. package/www/docs/API/contract.md +39 -3
  64. package/www/docs/API/provider.md +4 -0
  65. package/www/docs/API/signer.md +56 -2
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,6 +13,7 @@ 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) {
@@ -22,6 +23,11 @@ var TransactionHashPrefix;
22
23
  TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
23
24
  TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
24
25
  })(TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {}));
26
+ exports.UDC = {
27
+ ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf',
28
+ ENTRYPOINT: 'deployContract',
29
+ ADDRESS_DEVNET: '0x25fcb74260022bd8ed7e8d542408941826b53345e478b8303d6f31744838a36',
30
+ };
25
31
  /**
26
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
27
33
  * Please do not edit until the JSON changes.
@@ -33,25 +33,22 @@ export declare class Contract implements ContractInterface {
33
33
  * @param providerOrAccount (optional) - Provider or Account to attach to
34
34
  */
35
35
  constructor(abi: Abi, address: string, providerOrAccount?: ProviderInterface | AccountInterface);
36
- /**
37
- * Saves the address of the contract deployed on network that will be used for interaction
38
- *
39
- * @param address - address of the contract
40
- */
41
36
  attach(address: string): void;
42
- /**
43
- * Attaches to new Provider or Account
44
- *
45
- * @param providerOrAccount - new Provider or Account to attach to
46
- */
47
37
  connect(providerOrAccount: ProviderInterface | AccountInterface): void;
38
+ deployed(): Promise<Contract>;
39
+ call(method: string, args?: Array<any>, { blockIdentifier, }?: {
40
+ blockIdentifier?: BlockIdentifier;
41
+ }): Promise<Result>;
42
+ invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
43
+ estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
44
+ populate(method: string, args?: Array<any>): Call;
48
45
  /**
49
- * Resolves when contract is deployed on the network or when no deployment transaction is found
46
+ * Deep parse of the object that has been passed to the method
50
47
  *
51
- * @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
52
- * @throws When deployment fails
48
+ * @param struct - struct that needs to be calculated
49
+ * @return {number} - number of members for the given struct
53
50
  */
54
- deployed(): Promise<Contract>;
51
+ private calculateStructMembers;
55
52
  /**
56
53
  * Validates if all arguments that are passed to the method are corresponding to the ones in the abi
57
54
  *
@@ -60,13 +57,6 @@ export declare class Contract implements ContractInterface {
60
57
  * @param args - arguments that are passed to the method
61
58
  */
62
59
  protected validateMethodAndArgs(type: 'INVOKE' | 'CALL', method: string, args?: Array<any>): void;
63
- /**
64
- * Deep parse of the object that has been passed to the method
65
- *
66
- * @param struct - struct that needs to be calculated
67
- * @return {number} - number of members for the given struct
68
- */
69
- private calculateStructMembers;
70
60
  /**
71
61
  * Deep parse of the object that has been passed to the method
72
62
  *
@@ -115,10 +105,4 @@ export declare class Contract implements ContractInterface {
115
105
  * @return - parsed response corresponding to the abi
116
106
  */
117
107
  protected parseResponse(method: string, response: string[]): Result;
118
- invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
119
- call(method: string, args?: Array<any>, { blockIdentifier, }?: {
120
- blockIdentifier?: BlockIdentifier;
121
- }): Promise<Result>;
122
- estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
123
- populate(method: string, args?: Array<any>): Call;
124
108
  }
@@ -252,28 +252,12 @@ var Contract = /** @class */ (function () {
252
252
  }
253
253
  });
254
254
  }
255
- /**
256
- * Saves the address of the contract deployed on network that will be used for interaction
257
- *
258
- * @param address - address of the contract
259
- */
260
255
  Contract.prototype.attach = function (address) {
261
256
  this.address = address;
262
257
  };
263
- /**
264
- * Attaches to new Provider or Account
265
- *
266
- * @param providerOrAccount - new Provider or Account to attach to
267
- */
268
258
  Contract.prototype.connect = function (providerOrAccount) {
269
259
  this.providerOrAccount = providerOrAccount;
270
260
  };
271
- /**
272
- * Resolves when contract is deployed on the network or when no deployment transaction is found
273
- *
274
- * @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
275
- * @throws When deployment fails
276
- */
277
261
  Contract.prototype.deployed = function () {
278
262
  return __awaiter(this, void 0, void 0, function () {
279
263
  return __generator(this, function (_a) {
@@ -290,6 +274,110 @@ var Contract = /** @class */ (function () {
290
274
  });
291
275
  });
292
276
  };
277
+ Contract.prototype.call = function (method, args, _a) {
278
+ if (args === void 0) { args = []; }
279
+ var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
280
+ return __awaiter(this, void 0, void 0, function () {
281
+ var inputs, calldata;
282
+ var _this = this;
283
+ return __generator(this, function (_d) {
284
+ // ensure contract is connected
285
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
286
+ // validate method and args
287
+ this.validateMethodAndArgs('CALL', method, args);
288
+ inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
289
+ calldata = this.compileCalldata(args, inputs);
290
+ return [2 /*return*/, this.providerOrAccount
291
+ .callContract({
292
+ contractAddress: this.address,
293
+ calldata: calldata,
294
+ entrypoint: method,
295
+ }, blockIdentifier)
296
+ .then(function (x) { return _this.parseResponse(method, x.result); })];
297
+ });
298
+ });
299
+ };
300
+ Contract.prototype.invoke = function (method, args, options) {
301
+ if (args === void 0) { args = []; }
302
+ if (options === void 0) { options = {}; }
303
+ // ensure contract is connected
304
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
305
+ // validate method and args
306
+ this.validateMethodAndArgs('INVOKE', method, args);
307
+ var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
308
+ var inputsLength = inputs.reduce(function (acc, input) {
309
+ if (!/_len$/.test(input.name)) {
310
+ return acc + 1;
311
+ }
312
+ return acc;
313
+ }, 0);
314
+ if (args.length !== inputsLength) {
315
+ throw Error("Invalid number of arguments, expected ".concat(inputsLength, " arguments, but got ").concat(args.length));
316
+ }
317
+ // compile calldata
318
+ var calldata = this.compileCalldata(args, inputs);
319
+ var invocation = {
320
+ contractAddress: this.address,
321
+ calldata: calldata,
322
+ entrypoint: method,
323
+ };
324
+ if ('execute' in this.providerOrAccount) {
325
+ return this.providerOrAccount.execute(invocation, undefined, {
326
+ maxFee: options.maxFee,
327
+ nonce: options.nonce,
328
+ });
329
+ }
330
+ if (!options.nonce) {
331
+ throw new Error("Nonce is required when invoking a function without an account");
332
+ }
333
+ // eslint-disable-next-line no-console
334
+ console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
335
+ return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
336
+ nonce: options.nonce,
337
+ });
338
+ };
339
+ Contract.prototype.estimate = function (method, args) {
340
+ if (args === void 0) { args = []; }
341
+ return __awaiter(this, void 0, void 0, function () {
342
+ var invocation;
343
+ var _a;
344
+ return __generator(this, function (_b) {
345
+ // ensure contract is connected
346
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
347
+ // validate method and args
348
+ this.validateMethodAndArgs('INVOKE', method, args);
349
+ invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
350
+ if ('estimateInvokeFee' in this.providerOrAccount) {
351
+ return [2 /*return*/, this.providerOrAccount.estimateInvokeFee(invocation)];
352
+ }
353
+ throw Error('Contract must be connected to the account contract to estimate');
354
+ });
355
+ });
356
+ };
357
+ Contract.prototype.populate = function (method, args) {
358
+ if (args === void 0) { args = []; }
359
+ var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
360
+ return {
361
+ contractAddress: this.address,
362
+ entrypoint: method,
363
+ calldata: this.compileCalldata(args, inputs),
364
+ };
365
+ };
366
+ /**
367
+ * Deep parse of the object that has been passed to the method
368
+ *
369
+ * @param struct - struct that needs to be calculated
370
+ * @return {number} - number of members for the given struct
371
+ */
372
+ Contract.prototype.calculateStructMembers = function (struct) {
373
+ var _this = this;
374
+ return this.structs[struct].members.reduce(function (acc, member) {
375
+ if (member.type === 'felt') {
376
+ return acc + 1;
377
+ }
378
+ return acc + _this.calculateStructMembers(member.type);
379
+ }, 0);
380
+ };
293
381
  /**
294
382
  * Validates if all arguments that are passed to the method are corresponding to the ones in the abi
295
383
  *
@@ -371,21 +459,6 @@ var Contract = /** @class */ (function () {
371
459
  }
372
460
  });
373
461
  };
374
- /**
375
- * Deep parse of the object that has been passed to the method
376
- *
377
- * @param struct - struct that needs to be calculated
378
- * @return {number} - number of members for the given struct
379
- */
380
- Contract.prototype.calculateStructMembers = function (struct) {
381
- var _this = this;
382
- return this.structs[struct].members.reduce(function (acc, member) {
383
- if (member.type === 'felt') {
384
- return acc + 1;
385
- }
386
- return acc + _this.calculateStructMembers(member.type);
387
- }, 0);
388
- };
389
462
  /**
390
463
  * Deep parse of the object that has been passed to the method
391
464
  *
@@ -562,95 +635,6 @@ var Contract = /** @class */ (function () {
562
635
  return acc;
563
636
  }, []);
564
637
  };
565
- Contract.prototype.invoke = function (method, args, options) {
566
- if (args === void 0) { args = []; }
567
- if (options === void 0) { options = {}; }
568
- // ensure contract is connected
569
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
570
- // validate method and args
571
- this.validateMethodAndArgs('INVOKE', method, args);
572
- var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
573
- var inputsLength = inputs.reduce(function (acc, input) {
574
- if (!/_len$/.test(input.name)) {
575
- return acc + 1;
576
- }
577
- return acc;
578
- }, 0);
579
- if (args.length !== inputsLength) {
580
- throw Error("Invalid number of arguments, expected ".concat(inputsLength, " arguments, but got ").concat(args.length));
581
- }
582
- // compile calldata
583
- var calldata = this.compileCalldata(args, inputs);
584
- var invocation = {
585
- contractAddress: this.address,
586
- calldata: calldata,
587
- entrypoint: method,
588
- };
589
- if ('execute' in this.providerOrAccount) {
590
- return this.providerOrAccount.execute(invocation, undefined, {
591
- maxFee: options.maxFee,
592
- nonce: options.nonce,
593
- });
594
- }
595
- if (!options.nonce) {
596
- throw new Error("Nonce is required when invoking a function without an account");
597
- }
598
- // eslint-disable-next-line no-console
599
- console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
600
- return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
601
- nonce: options.nonce,
602
- });
603
- };
604
- Contract.prototype.call = function (method, args, _a) {
605
- if (args === void 0) { args = []; }
606
- var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
607
- return __awaiter(this, void 0, void 0, function () {
608
- var inputs, calldata;
609
- var _this = this;
610
- return __generator(this, function (_d) {
611
- // ensure contract is connected
612
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
613
- // validate method and args
614
- this.validateMethodAndArgs('CALL', method, args);
615
- inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
616
- calldata = this.compileCalldata(args, inputs);
617
- return [2 /*return*/, this.providerOrAccount
618
- .callContract({
619
- contractAddress: this.address,
620
- calldata: calldata,
621
- entrypoint: method,
622
- }, blockIdentifier)
623
- .then(function (x) { return _this.parseResponse(method, x.result); })];
624
- });
625
- });
626
- };
627
- Contract.prototype.estimate = function (method, args) {
628
- if (args === void 0) { args = []; }
629
- return __awaiter(this, void 0, void 0, function () {
630
- var invocation;
631
- var _a;
632
- return __generator(this, function (_b) {
633
- // ensure contract is connected
634
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
635
- // validate method and args
636
- this.validateMethodAndArgs('INVOKE', method, args);
637
- invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
638
- if ('estimateInvokeFee' in this.providerOrAccount) {
639
- return [2 /*return*/, this.providerOrAccount.estimateInvokeFee(invocation)];
640
- }
641
- throw Error('Contract must be connected to the account contract to estimate');
642
- });
643
- });
644
- };
645
- Contract.prototype.populate = function (method, args) {
646
- if (args === void 0) { args = []; }
647
- var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
648
- return {
649
- contractAddress: this.address,
650
- entrypoint: method,
651
- calldata: this.compileCalldata(args, inputs),
652
- };
653
- };
654
638
  return Contract;
655
639
  }());
656
640
  exports.Contract = Contract;
@@ -44,6 +44,7 @@ export declare abstract class ContractInterface {
44
44
  *
45
45
  * @param method name of the method
46
46
  * @param args Array of the arguments for the call
47
+ * @param options optional blockIdentifier
47
48
  * @returns Result of the call as an array with key value pars
48
49
  */
49
50
  abstract call(method: string, args?: Array<any>, options?: {
@@ -54,14 +55,16 @@ export declare abstract class ContractInterface {
54
55
  *
55
56
  * @param method name of the method
56
57
  * @param args Array of the arguments for the invoke
58
+ * @param options
57
59
  * @returns Add Transaction Response
58
60
  */
59
61
  abstract invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
60
62
  /**
61
- * Calls a method on a contract
63
+ * Estimates a method on a contract
62
64
  *
63
65
  * @param method name of the method
64
66
  * @param args Array of the arguments for the call
67
+ * @param options optional blockIdentifier
65
68
  */
66
69
  abstract estimate(method: string, args?: Array<any>, options?: {
67
70
  blockIdentifier?: BlockIdentifier;
@@ -71,7 +74,7 @@ export declare abstract class ContractInterface {
71
74
  *
72
75
  * @param method name of the method
73
76
  * @param args Array of the arguments for the call
74
- * @returns Invocation objet
77
+ * @returns Invocation object
75
78
  */
76
79
  abstract populate(method: string, args?: Array<any>): Invocation;
77
80
  }
@@ -4,7 +4,7 @@ import { BlockIdentifier } from '../provider/utils';
4
4
  import { SignerInterface } from '../signer';
5
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
+ import { AllowArray, DeclareContractPayload, DeployAccountContractPayload, UniversalDeployerContractPayload } from '../types/lib';
8
8
  import { BigNumberish } from '../utils/number';
9
9
  import { TypedData } from '../utils/typedData';
10
10
  import { AccountInterface } from './interface';
@@ -19,6 +19,8 @@ export declare class Account extends Provider implements AccountInterface {
19
19
  estimateAccountDeployFee({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
20
20
  execute(calls: AllowArray<Call>, abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
21
21
  declare({ classHash, contract }: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
22
+ deploy({ classHash, salt, unique, constructorCalldata, isDevnet, }: UniversalDeployerContractPayload, additionalCalls?: AllowArray<Call>, // support multicall
23
+ transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
22
24
  deployAccount({ classHash, constructorCalldata, addressSalt, contractAddress: providedContractAddress, }: DeployAccountContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeployContractResponse>;
23
25
  signMessage(typedData: TypedData): Promise<Signature>;
24
26
  hashMessage(typedData: TypedData): Promise<string>;
@@ -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");
@@ -328,6 +353,31 @@ var Account = /** @class */ (function (_super) {
328
353
  });
329
354
  });
330
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
+ };
331
381
  Account.prototype.deployAccount = function (_a, transactionsDetail) {
332
382
  var _b, _c;
333
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;
@@ -2,7 +2,7 @@ import { ProviderInterface } from '../provider';
2
2
  import { BlockIdentifier } from '../provider/utils';
3
3
  import { SignerInterface } from '../signer';
4
4
  import { Abi, Call, DeclareContractResponse, DeployContractResponse, EstimateFeeAction, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
5
- import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
5
+ import { AllowArray, DeclareContractPayload, DeployAccountContractPayload, UniversalDeployerContractPayload } from '../types/lib';
6
6
  import { BigNumberish } from '../utils/number';
7
7
  import { TypedData } from '../utils/typedData/types';
8
8
  export declare abstract class AccountInterface extends ProviderInterface {
@@ -45,7 +45,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
45
45
  * Estimate Fee for executing a DEPLOY_ACCOUNT transaction on starknet
46
46
  *
47
47
  * @param contractPayload the payload object containing:
48
- * - contract - the compiled contract to be declared
48
+ * - contract - the compiled contract to be deployed
49
49
  * - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
50
50
  *
51
51
  * @returns response from estimate_fee
@@ -66,6 +66,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
66
66
  abstract execute(transactions: AllowArray<Call>, abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
67
67
  /**
68
68
  * Declares a given compiled contract (json) to starknet
69
+ *
69
70
  * @param contractPayload transaction payload to be deployed containing:
70
71
  - contract: compiled contract code
71
72
  - classHash: computed class hash of compiled contract
@@ -77,13 +78,27 @@ export declare abstract class AccountInterface extends ProviderInterface {
77
78
  * @returns a confirmation of sending a transaction on the starknet contract
78
79
  */
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>;
80
94
  /**
81
95
  * Deploy the account on Starknet
96
+ *
82
97
  * @param contractPayload transaction payload to be deployed containing:
83
- * - classHash: computed class hash of compiled contract
84
- * - constructor calldata
85
- * - address salt
86
- - signature
98
+ - classHash: computed class hash of compiled contract
99
+ - optional constructor calldata
100
+ - optional address salt
101
+ - optional contractAddress
87
102
  * @param transactionsDetail Invocation Details containing:
88
103
  - optional nonce
89
104
  - optional version
@@ -112,7 +127,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
112
127
  /**
113
128
  * Verify a signature of a JSON object
114
129
  *
115
- * @param json - JSON object to be verified
130
+ * @param typedData - JSON object to be verified
116
131
  * @param signature - signature of the JSON object
117
132
  * @returns true if the signature is valid, false otherwise
118
133
  * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
@@ -130,12 +145,14 @@ export declare abstract class AccountInterface extends ProviderInterface {
130
145
  abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
131
146
  /**
132
147
  * Gets the nonce of the account with respect to a specific block
148
+ *
133
149
  * @param {BlockIdentifier} blockIdentifier - optional blockIdentifier. Defaults to 'pending'
134
150
  * @returns nonce of the account
135
151
  */
136
152
  abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
137
153
  /**
138
154
  * Gets Suggested Max Fee based on the transaction type
155
+ *
139
156
  * @param {EstimateFeeAction} estimateFeeAction
140
157
  * @param {EstimateFeeDetails} details
141
158
  * @returns suggestedMaxFee
@@ -7,7 +7,8 @@ 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",
@@ -16,6 +17,11 @@ export declare enum TransactionHashPrefix {
16
17
  INVOKE = "0x696e766f6b65",
17
18
  L1_HANDLER = "0x6c315f68616e646c6572"
18
19
  }
20
+ export declare const UDC: {
21
+ ADDRESS: string;
22
+ ENTRYPOINT: string;
23
+ ADDRESS_DEVNET: string;
24
+ };
19
25
  /**
20
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
21
27
  * Please do not edit until the JSON changes.
package/dist/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,6 +13,7 @@ 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) {
@@ -22,6 +23,11 @@ var TransactionHashPrefix;
22
23
  TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
23
24
  TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
24
25
  })(TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {}));
26
+ exports.UDC = {
27
+ ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf',
28
+ ENTRYPOINT: 'deployContract',
29
+ ADDRESS_DEVNET: '0x25fcb74260022bd8ed7e8d542408941826b53345e478b8303d6f31744838a36',
30
+ };
25
31
  /**
26
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
27
33
  * Please do not edit until the JSON changes.
@@ -33,25 +33,22 @@ export declare class Contract implements ContractInterface {
33
33
  * @param providerOrAccount (optional) - Provider or Account to attach to
34
34
  */
35
35
  constructor(abi: Abi, address: string, providerOrAccount?: ProviderInterface | AccountInterface);
36
- /**
37
- * Saves the address of the contract deployed on network that will be used for interaction
38
- *
39
- * @param address - address of the contract
40
- */
41
36
  attach(address: string): void;
42
- /**
43
- * Attaches to new Provider or Account
44
- *
45
- * @param providerOrAccount - new Provider or Account to attach to
46
- */
47
37
  connect(providerOrAccount: ProviderInterface | AccountInterface): void;
38
+ deployed(): Promise<Contract>;
39
+ call(method: string, args?: Array<any>, { blockIdentifier, }?: {
40
+ blockIdentifier?: BlockIdentifier;
41
+ }): Promise<Result>;
42
+ invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
43
+ estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
44
+ populate(method: string, args?: Array<any>): Call;
48
45
  /**
49
- * Resolves when contract is deployed on the network or when no deployment transaction is found
46
+ * Deep parse of the object that has been passed to the method
50
47
  *
51
- * @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
52
- * @throws When deployment fails
48
+ * @param struct - struct that needs to be calculated
49
+ * @return {number} - number of members for the given struct
53
50
  */
54
- deployed(): Promise<Contract>;
51
+ private calculateStructMembers;
55
52
  /**
56
53
  * Validates if all arguments that are passed to the method are corresponding to the ones in the abi
57
54
  *
@@ -60,13 +57,6 @@ export declare class Contract implements ContractInterface {
60
57
  * @param args - arguments that are passed to the method
61
58
  */
62
59
  protected validateMethodAndArgs(type: 'INVOKE' | 'CALL', method: string, args?: Array<any>): void;
63
- /**
64
- * Deep parse of the object that has been passed to the method
65
- *
66
- * @param struct - struct that needs to be calculated
67
- * @return {number} - number of members for the given struct
68
- */
69
- private calculateStructMembers;
70
60
  /**
71
61
  * Deep parse of the object that has been passed to the method
72
62
  *
@@ -115,10 +105,4 @@ export declare class Contract implements ContractInterface {
115
105
  * @return - parsed response corresponding to the abi
116
106
  */
117
107
  protected parseResponse(method: string, response: string[]): Result;
118
- invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
119
- call(method: string, args?: Array<any>, { blockIdentifier, }?: {
120
- blockIdentifier?: BlockIdentifier;
121
- }): Promise<Result>;
122
- estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
123
- populate(method: string, args?: Array<any>): Call;
124
108
  }