starknet 3.18.2 → 4.0.1

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 (165) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +1 -2
  3. package/__tests__/account.test.ts +11 -56
  4. package/__tests__/contract.test.ts +11 -49
  5. package/__tests__/defaultProvider.test.ts +321 -0
  6. package/__tests__/fixtures.ts +32 -11
  7. package/__tests__/jest.setup.ts +2 -3
  8. package/__tests__/rpcProvider.test.ts +17 -0
  9. package/__tests__/sequencerProvider.test.ts +45 -0
  10. package/account/default.d.ts +54 -77
  11. package/account/default.js +271 -596
  12. package/account/index.js +18 -31
  13. package/account/interface.d.ts +66 -95
  14. package/account/interface.js +20 -30
  15. package/constants.d.ts +17 -19
  16. package/constants.js +2038 -2059
  17. package/contract/contractFactory.d.ts +25 -29
  18. package/contract/contractFactory.js +94 -210
  19. package/contract/default.d.ts +117 -146
  20. package/contract/default.js +582 -776
  21. package/contract/index.js +19 -32
  22. package/contract/interface.d.ts +72 -92
  23. package/contract/interface.js +6 -5
  24. package/dist/account/default.d.ts +5 -9
  25. package/dist/account/default.js +35 -169
  26. package/dist/account/interface.d.ts +3 -15
  27. package/dist/contract/contractFactory.js +4 -4
  28. package/dist/contract/default.d.ts +3 -3
  29. package/dist/contract/default.js +3 -2
  30. package/dist/contract/interface.d.ts +2 -2
  31. package/dist/provider/default.d.ts +18 -134
  32. package/dist/provider/default.js +47 -411
  33. package/dist/provider/index.d.ts +2 -0
  34. package/dist/provider/index.js +2 -0
  35. package/dist/provider/interface.d.ts +45 -50
  36. package/dist/provider/rpc.d.ts +57 -0
  37. package/dist/provider/rpc.js +364 -0
  38. package/dist/provider/sequencer.d.ts +66 -0
  39. package/dist/provider/sequencer.js +444 -0
  40. package/dist/types/account.d.ts +2 -3
  41. package/dist/types/api/index.d.ts +16 -0
  42. package/dist/types/api/index.js +18 -0
  43. package/dist/types/api/rpc.d.ts +221 -0
  44. package/dist/types/{api.js → api/rpc.js} +0 -0
  45. package/dist/types/api/sequencer.d.ts +289 -0
  46. package/dist/types/api/sequencer.js +2 -0
  47. package/dist/types/index.d.ts +3 -1
  48. package/dist/types/index.js +15 -1
  49. package/dist/types/lib.d.ts +3 -1
  50. package/dist/types/provider.d.ts +86 -0
  51. package/dist/types/provider.js +2 -0
  52. package/dist/utils/fetchPonyfill.d.ts +2 -0
  53. package/dist/utils/fetchPonyfill.js +6 -0
  54. package/dist/utils/provider.d.ts +4 -0
  55. package/dist/utils/provider.js +38 -0
  56. package/dist/utils/responseParser/index.d.ts +11 -0
  57. package/dist/utils/responseParser/index.js +9 -0
  58. package/dist/utils/responseParser/rpc.d.ts +13 -0
  59. package/dist/utils/responseParser/rpc.js +96 -0
  60. package/dist/utils/responseParser/sequencer.d.ts +13 -0
  61. package/dist/utils/responseParser/sequencer.js +124 -0
  62. package/index.js +42 -75
  63. package/package.json +2 -3
  64. package/provider/default.d.ts +21 -175
  65. package/provider/default.js +139 -704
  66. package/provider/errors.d.ts +4 -4
  67. package/provider/errors.js +30 -40
  68. package/provider/index.d.ts +2 -0
  69. package/provider/index.js +22 -33
  70. package/provider/interface.d.ts +104 -131
  71. package/provider/interface.js +6 -5
  72. package/provider/rpc.d.ts +57 -0
  73. package/provider/rpc.js +364 -0
  74. package/provider/sequencer.d.ts +66 -0
  75. package/provider/sequencer.js +444 -0
  76. package/provider/utils.d.ts +7 -9
  77. package/provider/utils.js +39 -44
  78. package/signer/default.d.ts +5 -9
  79. package/signer/default.js +72 -177
  80. package/signer/index.js +18 -31
  81. package/signer/interface.d.ts +29 -33
  82. package/signer/interface.js +6 -5
  83. package/src/account/default.ts +26 -146
  84. package/src/account/interface.ts +5 -20
  85. package/src/contract/contractFactory.ts +3 -6
  86. package/src/contract/default.ts +6 -4
  87. package/src/contract/interface.ts +2 -2
  88. package/src/provider/default.ts +63 -395
  89. package/src/provider/index.ts +2 -0
  90. package/src/provider/interface.ts +68 -63
  91. package/src/provider/rpc.ts +299 -0
  92. package/src/provider/sequencer.ts +385 -0
  93. package/src/types/account.ts +2 -3
  94. package/src/types/api/index.ts +17 -0
  95. package/src/types/api/rpc.ts +247 -0
  96. package/src/types/api/sequencer.ts +331 -0
  97. package/src/types/index.ts +3 -1
  98. package/src/types/lib.ts +3 -1
  99. package/src/types/provider.ts +108 -0
  100. package/src/utils/fetchPonyfill.ts +4 -0
  101. package/src/utils/provider.ts +28 -0
  102. package/src/utils/responseParser/index.ts +28 -0
  103. package/src/utils/responseParser/rpc.ts +93 -0
  104. package/src/utils/responseParser/sequencer.ts +127 -0
  105. package/types/account.d.ts +5 -7
  106. package/types/account.js +2 -2
  107. package/types/api/index.d.ts +16 -0
  108. package/types/api/index.js +18 -0
  109. package/types/api/rpc.d.ts +221 -0
  110. package/types/api/rpc.js +2 -0
  111. package/types/api/sequencer.d.ts +289 -0
  112. package/types/api/sequencer.js +2 -0
  113. package/types/contract.d.ts +1 -1
  114. package/types/contract.js +2 -2
  115. package/types/index.d.ts +3 -1
  116. package/types/index.js +35 -34
  117. package/types/lib.d.ts +36 -41
  118. package/types/lib.js +2 -2
  119. package/types/provider.d.ts +86 -0
  120. package/types/provider.js +2 -0
  121. package/types/signer.d.ts +2 -2
  122. package/types/signer.js +2 -2
  123. package/utils/address.js +26 -37
  124. package/utils/ellipticCurve.d.ts +1 -6
  125. package/utils/ellipticCurve.js +73 -137
  126. package/utils/encode.js +49 -85
  127. package/utils/fetchPonyfill.d.ts +2 -0
  128. package/utils/fetchPonyfill.js +6 -0
  129. package/utils/hash.d.ts +4 -31
  130. package/utils/hash.js +76 -141
  131. package/utils/json.d.ts +13 -45
  132. package/utils/json.js +15 -22
  133. package/utils/number.d.ts +2 -9
  134. package/utils/number.js +47 -81
  135. package/utils/provider.d.ts +4 -0
  136. package/utils/provider.js +38 -0
  137. package/utils/responseParser/index.d.ts +11 -0
  138. package/utils/responseParser/index.js +9 -0
  139. package/utils/responseParser/rpc.d.ts +13 -0
  140. package/utils/responseParser/rpc.js +96 -0
  141. package/utils/responseParser/sequencer.d.ts +13 -0
  142. package/utils/responseParser/sequencer.js +124 -0
  143. package/utils/shortString.js +13 -21
  144. package/utils/stark.d.ts +0 -1
  145. package/utils/stark.js +59 -93
  146. package/utils/transaction.d.ts +3 -6
  147. package/utils/transaction.js +50 -81
  148. package/utils/typedData/index.d.ts +3 -15
  149. package/utils/typedData/index.js +109 -175
  150. package/utils/typedData/types.d.ts +9 -9
  151. package/utils/typedData/types.js +2 -2
  152. package/utils/typedData/utils.js +6 -6
  153. package/utils/uint256.d.ts +5 -5
  154. package/utils/uint256.js +16 -26
  155. package/www/docs/API/account.md +3 -4
  156. package/www/docs/API/contract.md +2 -2
  157. package/www/docs/API/contractFactory.md +2 -2
  158. package/www/docs/API/provider.md +185 -74
  159. package/www/guides/account.md +1 -8
  160. package/www/guides/erc20.md +3 -0
  161. package/__tests__/provider.test.ts +0 -168
  162. package/dist/types/api.d.ts +0 -261
  163. package/src/types/api.ts +0 -303
  164. package/types/api.d.ts +0 -287
  165. package/types/api.js +0 -2
package/contract/index.js CHANGED
@@ -1,32 +1,19 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __exportStar =
23
- (this && this.__exportStar) ||
24
- function (m, exports) {
25
- for (var p in m)
26
- if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
27
- __createBinding(exports, m, p);
28
- };
29
- Object.defineProperty(exports, '__esModule', { value: true });
30
- __exportStar(require('./default'), exports);
31
- __exportStar(require('./interface'), exports);
32
- __exportStar(require('./contractFactory'), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./default"), exports);
18
+ __exportStar(require("./interface"), exports);
19
+ __exportStar(require("./contractFactory"), exports);
@@ -1,97 +1,77 @@
1
1
  import { AccountInterface } from '../account';
2
2
  import { ProviderInterface } from '../provider';
3
3
  import { BlockIdentifier } from '../provider/utils';
4
- import {
5
- Abi,
6
- AddTransactionResponse,
7
- AsyncContractFunction,
8
- ContractFunction,
9
- Invocation,
10
- Overrides,
11
- Result,
12
- } from '../types';
4
+ import { Abi, AsyncContractFunction, ContractFunction, Invocation, InvokeFunctionResponse, Overrides, Result } from '../types';
13
5
  export declare abstract class ContractInterface {
14
- abstract abi: Abi;
15
- abstract address: string;
16
- abstract providerOrAccount: ProviderInterface | AccountInterface;
17
- abstract deployTransactionHash?: string;
18
- readonly functions: {
19
- [name: string]: AsyncContractFunction;
20
- };
21
- readonly callStatic: {
22
- [name: string]: AsyncContractFunction;
23
- };
24
- readonly populateTransaction: {
25
- [name: string]: ContractFunction;
26
- };
27
- readonly estimateFee: {
28
- [name: string]: ContractFunction;
29
- };
30
- readonly [key: string]: AsyncContractFunction | any;
31
- /**
32
- * Saves the address of the contract deployed on network that will be used for interaction
33
- *
34
- * @param address - address of the contract
35
- */
36
- abstract attach(address: string): void;
37
- /**
38
- * Attaches to new Provider or Account
39
- *
40
- * @param providerOrAccount - new Provider or Account to attach to
41
- */
42
- abstract connect(providerOrAccount: ProviderInterface | AccountInterface): void;
43
- /**
44
- * Resolves when contract is deployed on the network or when no deployment transaction is found
45
- *
46
- * @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
47
- * @throws When deployment fails
48
- */
49
- abstract deployed(): Promise<ContractInterface>;
50
- /**
51
- * Calls a method on a contract
52
- *
53
- * @param method name of the method
54
- * @param args Array of the arguments for the call
55
- * @returns Result of the call as an array with key value pars
56
- */
57
- abstract call(
58
- method: string,
59
- args?: Array<any>,
60
- options?: {
61
- blockIdentifier?: BlockIdentifier;
62
- }
63
- ): Promise<Result>;
64
- /**
65
- * Invokes a method on a contract
66
- *
67
- * @param method name of the method
68
- * @param args Array of the arguments for the invoke
69
- * @returns Add Transaction Response
70
- */
71
- abstract invoke(
72
- method: string,
73
- args?: Array<any>,
74
- options?: Overrides
75
- ): Promise<AddTransactionResponse>;
76
- /**
77
- * Calls a method on a contract
78
- *
79
- * @param method name of the method
80
- * @param args Array of the arguments for the call
81
- */
82
- abstract estimate(
83
- method: string,
84
- args?: Array<any>,
85
- options?: {
86
- blockIdentifier?: BlockIdentifier;
87
- }
88
- ): Promise<any>;
89
- /**
90
- * Calls a method on a contract
91
- *
92
- * @param method name of the method
93
- * @param args Array of the arguments for the call
94
- * @returns Invocation objet
95
- */
96
- abstract populate(method: string, args?: Array<any>): Invocation;
6
+ abstract abi: Abi;
7
+ abstract address: string;
8
+ abstract providerOrAccount: ProviderInterface | AccountInterface;
9
+ abstract deployTransactionHash?: string;
10
+ readonly functions: {
11
+ [name: string]: AsyncContractFunction;
12
+ };
13
+ readonly callStatic: {
14
+ [name: string]: AsyncContractFunction;
15
+ };
16
+ readonly populateTransaction: {
17
+ [name: string]: ContractFunction;
18
+ };
19
+ readonly estimateFee: {
20
+ [name: string]: ContractFunction;
21
+ };
22
+ readonly [key: string]: AsyncContractFunction | any;
23
+ /**
24
+ * Saves the address of the contract deployed on network that will be used for interaction
25
+ *
26
+ * @param address - address of the contract
27
+ */
28
+ abstract attach(address: string): void;
29
+ /**
30
+ * Attaches to new Provider or Account
31
+ *
32
+ * @param providerOrAccount - new Provider or Account to attach to
33
+ */
34
+ abstract connect(providerOrAccount: ProviderInterface | AccountInterface): void;
35
+ /**
36
+ * Resolves when contract is deployed on the network or when no deployment transaction is found
37
+ *
38
+ * @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
39
+ * @throws When deployment fails
40
+ */
41
+ abstract deployed(): Promise<ContractInterface>;
42
+ /**
43
+ * Calls a method on a contract
44
+ *
45
+ * @param method name of the method
46
+ * @param args Array of the arguments for the call
47
+ * @returns Result of the call as an array with key value pars
48
+ */
49
+ abstract call(method: string, args?: Array<any>, options?: {
50
+ blockIdentifier?: BlockIdentifier;
51
+ }): Promise<Result>;
52
+ /**
53
+ * Invokes a method on a contract
54
+ *
55
+ * @param method name of the method
56
+ * @param args Array of the arguments for the invoke
57
+ * @returns Add Transaction Response
58
+ */
59
+ abstract invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
60
+ /**
61
+ * Calls a method on a contract
62
+ *
63
+ * @param method name of the method
64
+ * @param args Array of the arguments for the call
65
+ */
66
+ abstract estimate(method: string, args?: Array<any>, options?: {
67
+ blockIdentifier?: BlockIdentifier;
68
+ }): Promise<any>;
69
+ /**
70
+ * Calls a method on a contract
71
+ *
72
+ * @param method name of the method
73
+ * @param args Array of the arguments for the call
74
+ * @returns Invocation objet
75
+ */
76
+ abstract populate(method: string, args?: Array<any>): Invocation;
97
77
  }
@@ -1,8 +1,9 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContractInterface = void 0;
4
4
  var ContractInterface = /** @class */ (function () {
5
- function ContractInterface() {}
6
- return ContractInterface;
7
- })();
5
+ function ContractInterface() {
6
+ }
7
+ return ContractInterface;
8
+ }());
8
9
  exports.ContractInterface = ContractInterface;
@@ -1,6 +1,7 @@
1
- import { Provider, ProviderInterface } from '../provider';
1
+ import { ProviderInterface, ProviderOptions } from '../provider';
2
+ import { Provider } from '../provider/default';
2
3
  import { SignerInterface } from '../signer';
3
- import { Abi, AddTransactionResponse, Call, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
4
+ import { Abi, Call, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
4
5
  import { EstimateFee, EstimateFeeDetails } from '../types/account';
5
6
  import { BigNumberish } from '../utils/number';
6
7
  import { TypedData } from '../utils/typedData';
@@ -8,7 +9,7 @@ import { AccountInterface } from './interface';
8
9
  export declare class Account extends Provider implements AccountInterface {
9
10
  address: string;
10
11
  signer: SignerInterface;
11
- constructor(provider: ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
12
+ constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
12
13
  getNonce(): Promise<string>;
13
14
  estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
14
15
  /**
@@ -21,12 +22,7 @@ export declare class Account extends Provider implements AccountInterface {
21
22
  * @param transactionsDetail - optional transaction details
22
23
  * @returns a confirmation of invoking a function on the starknet contract
23
24
  */
24
- execute(calls: Call | Call[], abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<AddTransactionResponse>;
25
- /**
26
- * Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
27
- * @deprecated to remove ASAP
28
- */
29
- LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
25
+ execute(calls: Call | Call[], abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
30
26
  /**
31
27
  * Sign an JSON object with the starknet private key and return the signature
32
28
  *
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -50,54 +61,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
50
61
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
62
  }
52
63
  };
53
- var __read = (this && this.__read) || function (o, n) {
54
- var m = typeof Symbol === "function" && o[Symbol.iterator];
55
- if (!m) return o;
56
- var i = m.call(o), r, ar = [], e;
57
- try {
58
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
- }
60
- catch (error) { e = { error: error }; }
61
- finally {
62
- try {
63
- if (r && !r.done && (m = i["return"])) m.call(i);
64
- }
65
- finally { if (e) throw e.error; }
66
- }
67
- return ar;
68
- };
69
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
70
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
71
- if (ar || !(i in from)) {
72
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
73
- ar[i] = from[i];
74
- }
75
- }
76
- return to.concat(ar || Array.prototype.slice.call(from));
77
- };
78
- var __importDefault = (this && this.__importDefault) || function (mod) {
79
- return (mod && mod.__esModule) ? mod : { "default": mod };
80
- };
81
64
  Object.defineProperty(exports, "__esModule", { value: true });
82
65
  exports.Account = void 0;
83
- var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
84
66
  var constants_1 = require("../constants");
85
- var provider_1 = require("../provider");
67
+ var default_1 = require("../provider/default");
86
68
  var signer_1 = require("../signer");
87
- var ellipticCurve_1 = require("../utils/ellipticCurve");
88
69
  var hash_1 = require("../utils/hash");
89
70
  var number_1 = require("../utils/number");
90
- var shortString_1 = require("../utils/shortString");
91
71
  var stark_1 = require("../utils/stark");
92
72
  var transaction_1 = require("../utils/transaction");
93
73
  var typedData_1 = require("../utils/typedData");
94
74
  var Account = /** @class */ (function (_super) {
95
75
  __extends(Account, _super);
96
- function Account(provider, address, keyPairOrSigner) {
97
- var _this = _super.call(this, provider) || this;
76
+ function Account(providerOrOptions, address, keyPairOrSigner) {
77
+ var _this = _super.call(this, providerOrOptions) || this;
78
+ _this.address = address;
98
79
  _this.signer =
99
80
  'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new signer_1.Signer(keyPairOrSigner);
100
- _this.address = address;
101
81
  return _this;
102
82
  }
103
83
  Account.prototype.getNonce = function () {
@@ -117,23 +97,22 @@ var Account = /** @class */ (function (_super) {
117
97
  });
118
98
  };
119
99
  Account.prototype.estimateFee = function (calls, _a) {
120
- var _b;
121
- var _c = _a === void 0 ? {} : _a, providedNonce = _c.nonce, _d = _c.blockIdentifier, blockIdentifier = _d === void 0 ? 'pending' : _d;
100
+ var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
122
101
  return __awaiter(this, void 0, void 0, function () {
123
- var transactions, nonce, _e, version, signerDetails, signature, calldata, fetchedEstimate, fee, suggestedMaxFee;
124
- return __generator(this, function (_f) {
125
- switch (_f.label) {
102
+ var transactions, nonce, _c, version, signerDetails, signature, calldata, response, suggestedMaxFee;
103
+ return __generator(this, function (_d) {
104
+ switch (_d.label) {
126
105
  case 0:
127
106
  transactions = Array.isArray(calls) ? calls : [calls];
128
107
  if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
129
- _e = providedNonce;
108
+ _c = providedNonce;
130
109
  return [3 /*break*/, 3];
131
110
  case 1: return [4 /*yield*/, this.getNonce()];
132
111
  case 2:
133
- _e = (_f.sent());
134
- _f.label = 3;
112
+ _c = (_d.sent());
113
+ _d.label = 3;
135
114
  case 3:
136
- nonce = _e;
115
+ nonce = _c;
137
116
  version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
138
117
  signerDetails = {
139
118
  walletAddress: this.address,
@@ -144,27 +123,13 @@ var Account = /** @class */ (function (_super) {
144
123
  };
145
124
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
146
125
  case 4:
147
- signature = _f.sent();
126
+ signature = _d.sent();
148
127
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
149
- return [4 /*yield*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
150
- contract_address: this.address,
151
- entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
152
- calldata: calldata,
153
- version: (0, number_1.toHex)(version),
154
- signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
155
- })];
128
+ return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, blockIdentifier, { version: version })];
156
129
  case 5:
157
- fetchedEstimate = _f.sent();
158
- fee = (_b = fetchedEstimate.overall_fee) !== null && _b !== void 0 ? _b : fetchedEstimate.amount;
159
- if (fee === undefined) {
160
- throw new Error('Expected either amount or overall_fee in estimate_fee response');
161
- }
162
- suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fee);
163
- return [2 /*return*/, {
164
- amount: fee,
165
- unit: fetchedEstimate.unit,
166
- suggestedMaxFee: suggestedMaxFee,
167
- }];
130
+ response = _d.sent();
131
+ suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
132
+ return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
168
133
  }
169
134
  });
170
135
  });
@@ -184,7 +149,7 @@ var Account = /** @class */ (function (_super) {
184
149
  if (abis === void 0) { abis = undefined; }
185
150
  if (transactionsDetail === void 0) { transactionsDetail = {}; }
186
151
  return __awaiter(this, void 0, void 0, function () {
187
- var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, signerDetails, signature, calldata;
152
+ var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, version, signerDetails, signature, calldata;
188
153
  return __generator(this, function (_d) {
189
154
  switch (_d.label) {
190
155
  case 0:
@@ -209,120 +174,21 @@ var Account = /** @class */ (function (_super) {
209
174
  maxFee = suggestedMaxFee.toString();
210
175
  _d.label = 6;
211
176
  case 6:
177
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
212
178
  signerDetails = {
213
179
  walletAddress: this.address,
214
180
  nonce: nonce,
215
181
  maxFee: maxFee,
216
- version: (0, number_1.toBN)(hash_1.transactionVersion),
182
+ version: version,
217
183
  chainId: this.chainId,
218
184
  };
219
185
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
220
186
  case 7:
221
187
  signature = _d.sent();
222
188
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
223
- return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
224
- type: 'INVOKE_FUNCTION',
225
- contract_address: this.address,
226
- entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
227
- calldata: calldata,
228
- signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
229
- max_fee: (0, number_1.toHex)((0, number_1.toBN)(maxFee)),
230
- })];
231
- }
232
- });
233
- });
234
- };
235
- /**
236
- * Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
237
- * @deprecated to remove ASAP
238
- */
239
- Account.prototype.LEGACY_addTransaction = function (transaction) {
240
- return __awaiter(this, void 0, void 0, function () {
241
- function hashMulticall(account, transactions, nonce, maxFee) {
242
- var hashArray = transactions
243
- .map(function (_a) {
244
- var contract_address = _a.contract_address, entry_point_selector = _a.entry_point_selector, calldata = _a.calldata;
245
- return [
246
- contract_address,
247
- entry_point_selector,
248
- (0, hash_1.computeHashOnElements)(calldata || []),
249
- ];
250
- })
251
- .map(number_1.bigNumberishArrayToDecimalStringArray)
252
- .map(hash_1.computeHashOnElements);
253
- return (0, hash_1.computeHashOnElements)([
254
- (0, shortString_1.encodeShortString)('StarkNet Transaction'),
255
- account,
256
- (0, hash_1.computeHashOnElements)(hashArray),
257
- nonce,
258
- maxFee,
259
- hash_1.transactionVersion,
260
- ]);
261
- }
262
- var nonceBn, result, msgHash, signature, transformCallsToMulticallArrays, fromCallsToExecuteCalldata2, calldata;
263
- return __generator(this, function (_a) {
264
- switch (_a.label) {
265
- case 0:
266
- if (transaction.type === 'DEPLOY')
267
- throw new Error('No DEPLOYS');
268
- if (transaction.type === 'DECLARE')
269
- throw new Error('No DECLARES');
270
- (0, minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
271
- if (!transaction.nonce) return [3 /*break*/, 1];
272
- nonceBn = (0, number_1.toBN)(transaction.nonce);
273
- return [3 /*break*/, 3];
274
- case 1: return [4 /*yield*/, this.callContract({
275
- contractAddress: this.address,
276
- entrypoint: 'get_nonce',
277
- })];
278
- case 2:
279
- result = (_a.sent()).result;
280
- nonceBn = (0, number_1.toBN)(result[0]);
281
- _a.label = 3;
282
- case 3:
283
- msgHash = hashMulticall(this.address, [transaction], nonceBn.toString(), '0');
284
- if (!('keyPair' in this.signer)) {
285
- throw new Error('No keyPair');
286
- }
287
- signature = (0, ellipticCurve_1.sign)(this.signer.keyPair, msgHash);
288
- transformCallsToMulticallArrays = function (calls) {
289
- var callArray = [];
290
- var calldata = [];
291
- calls.forEach(function (call) {
292
- var data = call.calldata || [];
293
- callArray.push({
294
- to: (0, number_1.toBN)(call.contract_address).toString(10),
295
- selector: (0, number_1.toBN)(call.entry_point_selector).toString(10),
296
- data_offset: calldata.length.toString(),
297
- data_len: data.length.toString(),
298
- });
299
- calldata.push.apply(calldata, __spreadArray([], __read(data), false));
300
- });
301
- return {
302
- callArray: callArray,
303
- calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata),
304
- };
305
- };
306
- fromCallsToExecuteCalldata2 = function (calls) {
307
- var _a = transformCallsToMulticallArrays(calls), callArray = _a.callArray, calldata = _a.calldata;
308
- return __spreadArray(__spreadArray(__spreadArray([
309
- callArray.length.toString()
310
- ], __read(callArray
311
- .map(function (_a) {
312
- var to = _a.to, selector = _a.selector, data_offset = _a.data_offset, data_len = _a.data_len;
313
- return [to, selector, data_offset, data_len];
314
- })
315
- .flat()), false), [
316
- calldata.length.toString()
317
- ], false), __read(calldata), false);
318
- };
319
- calldata = __spreadArray(__spreadArray([], __read(fromCallsToExecuteCalldata2([transaction])), false), [nonceBn.toString()], false);
320
- return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
321
- type: 'INVOKE_FUNCTION',
322
- contract_address: this.address,
323
- entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
324
- calldata: calldata,
325
- signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
189
+ return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, {
190
+ maxFee: maxFee,
191
+ version: version,
326
192
  })];
327
193
  }
328
194
  });
@@ -413,5 +279,5 @@ var Account = /** @class */ (function (_super) {
413
279
  });
414
280
  };
415
281
  return Account;
416
- }(provider_1.Provider));
282
+ }(default_1.Provider));
417
283
  exports.Account = Account;
@@ -1,23 +1,11 @@
1
1
  import { ProviderInterface } from '../provider';
2
2
  import { SignerInterface } from '../signer';
3
- import { Abi, AddTransactionResponse, Call, DeployContractPayload, InvocationsDetails, Signature } from '../types';
4
- import { EstimateFee, EstimateFeeDetails } from '../types/account';
3
+ import { Abi, Call, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
5
4
  import { BigNumberish } from '../utils/number';
6
5
  import { TypedData } from '../utils/typedData/types';
7
6
  export declare abstract class AccountInterface extends ProviderInterface {
8
7
  abstract address: string;
9
8
  abstract signer: SignerInterface;
10
- /**
11
- * Deploys a given compiled contract (json) to starknet
12
- *
13
- * @param payload payload to be deployed containing:
14
- * - compiled contract code
15
- * - constructor calldata
16
- * - address salt
17
- * @param abi the abi of the contract
18
- * @returns a confirmation of sending a transaction on the starknet contract
19
- */
20
- abstract deployContract(payload: DeployContractPayload, abi?: Abi): Promise<AddTransactionResponse>;
21
9
  /**
22
10
  * Estimate Fee for a method on starknet
23
11
  *
@@ -29,7 +17,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
29
17
  *
30
18
  * @returns response from addTransaction
31
19
  */
32
- abstract estimateFee(calls: Call | Call[], estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFee>;
20
+ abstract estimateFee(calls: Call | Call[], estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
33
21
  /**
34
22
  * Invoke execute function in account contract
35
23
  *
@@ -42,7 +30,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
42
30
  *
43
31
  * @returns response from addTransaction
44
32
  */
45
- abstract execute(transactions: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<AddTransactionResponse>;
33
+ abstract execute(transactions: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
46
34
  /**
47
35
  * Sign an JSON object for off-chain usage with the starknet private key and return the signature
48
36
  * This adds a message prefix so it cant be interchanged with transactions
@@ -61,7 +61,7 @@ var ContractFactory = /** @class */ (function () {
61
61
  */
62
62
  ContractFactory.prototype.deploy = function (constructorCalldata, addressSalt) {
63
63
  return __awaiter(this, void 0, void 0, function () {
64
- var _a, address, code, transaction_hash, contractInstance;
64
+ var _a, contract_address, transaction_hash, contractInstance;
65
65
  return __generator(this, function (_b) {
66
66
  switch (_b.label) {
67
67
  case 0: return [4 /*yield*/, this.providerOrAccount.deployContract({
@@ -70,9 +70,9 @@ var ContractFactory = /** @class */ (function () {
70
70
  addressSalt: addressSalt,
71
71
  })];
72
72
  case 1:
73
- _a = _b.sent(), address = _a.address, code = _a.code, transaction_hash = _a.transaction_hash;
74
- (0, minimalistic_assert_1.default)(code === 'TRANSACTION_RECEIVED' && Boolean(address), 'Deployment of the contract failed');
75
- contractInstance = new default_1.Contract(this.compiledContract.abi, address, this.providerOrAccount);
73
+ _a = _b.sent(), contract_address = _a.contract_address, transaction_hash = _a.transaction_hash;
74
+ (0, minimalistic_assert_1.default)(Boolean(contract_address), 'Deployment of the contract failed');
75
+ contractInstance = new default_1.Contract(this.compiledContract.abi, contract_address, this.providerOrAccount);
76
76
  contractInstance.deployTransactionHash = transaction_hash;
77
77
  return [2 /*return*/, contractInstance];
78
78
  }
@@ -1,7 +1,7 @@
1
1
  import { AccountInterface } from '../account';
2
2
  import { ProviderInterface } from '../provider';
3
3
  import { BlockIdentifier } from '../provider/utils';
4
- import { Abi, AbiEntry, AddTransactionResponse, Args, AsyncContractFunction, Calldata, ContractFunction, Invocation, Overrides, ParsedStruct, Result, StructAbi } from '../types';
4
+ import { Abi, AbiEntry, Args, AsyncContractFunction, Calldata, ContractFunction, Invocation, InvokeFunctionResponse, Overrides, ParsedStruct, Result, StructAbi } from '../types';
5
5
  import { BigNumberish } from '../utils/number';
6
6
  import { ContractInterface } from './interface';
7
7
  export declare class Contract implements ContractInterface {
@@ -115,10 +115,10 @@ export declare class Contract implements ContractInterface {
115
115
  * @return - parsed response corresponding to the abi
116
116
  */
117
117
  protected parseResponse(method: string, response: string[]): Result;
118
- invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
118
+ invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
119
119
  call(method: string, args?: Array<any>, { blockIdentifier, }?: {
120
120
  blockIdentifier?: BlockIdentifier;
121
121
  }): Promise<Result>;
122
- estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFee>;
122
+ estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
123
123
  populate(method: string, args?: Array<any>): Invocation;
124
124
  }