starknet 3.18.1 → 4.0.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 (159) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +1 -1
  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__/rpcProvider.test.ts +17 -0
  8. package/__tests__/sequencerProvider.test.ts +45 -0
  9. package/account/default.d.ts +54 -77
  10. package/account/default.js +271 -596
  11. package/account/index.js +18 -31
  12. package/account/interface.d.ts +66 -95
  13. package/account/interface.js +20 -30
  14. package/constants.d.ts +17 -19
  15. package/constants.js +2038 -2059
  16. package/contract/contractFactory.d.ts +25 -29
  17. package/contract/contractFactory.js +94 -210
  18. package/contract/default.d.ts +117 -146
  19. package/contract/default.js +582 -776
  20. package/contract/index.js +19 -32
  21. package/contract/interface.d.ts +72 -92
  22. package/contract/interface.js +6 -5
  23. package/dist/account/default.d.ts +5 -9
  24. package/dist/account/default.js +35 -169
  25. package/dist/account/interface.d.ts +3 -15
  26. package/dist/contract/contractFactory.js +4 -4
  27. package/dist/contract/default.d.ts +3 -3
  28. package/dist/contract/default.js +3 -2
  29. package/dist/contract/interface.d.ts +2 -2
  30. package/dist/provider/default.d.ts +18 -134
  31. package/dist/provider/default.js +47 -410
  32. package/dist/provider/index.d.ts +2 -0
  33. package/dist/provider/index.js +2 -0
  34. package/dist/provider/interface.d.ts +45 -50
  35. package/dist/provider/rpc.d.ts +57 -0
  36. package/dist/provider/rpc.js +364 -0
  37. package/dist/provider/sequencer.d.ts +66 -0
  38. package/dist/provider/sequencer.js +443 -0
  39. package/dist/types/account.d.ts +2 -3
  40. package/dist/types/api/index.d.ts +16 -0
  41. package/dist/types/api/index.js +18 -0
  42. package/dist/types/api/rpc.d.ts +221 -0
  43. package/dist/types/{api.js → api/rpc.js} +0 -0
  44. package/dist/types/api/sequencer.d.ts +289 -0
  45. package/dist/types/api/sequencer.js +2 -0
  46. package/dist/types/index.d.ts +3 -1
  47. package/dist/types/index.js +15 -1
  48. package/dist/types/lib.d.ts +3 -1
  49. package/dist/types/provider.d.ts +86 -0
  50. package/dist/types/provider.js +2 -0
  51. package/dist/utils/provider.d.ts +4 -0
  52. package/dist/utils/provider.js +38 -0
  53. package/dist/utils/responseParser/index.d.ts +11 -0
  54. package/dist/utils/responseParser/index.js +9 -0
  55. package/dist/utils/responseParser/rpc.d.ts +13 -0
  56. package/dist/utils/responseParser/rpc.js +96 -0
  57. package/dist/utils/responseParser/sequencer.d.ts +13 -0
  58. package/dist/utils/responseParser/sequencer.js +124 -0
  59. package/index.js +42 -75
  60. package/package.json +1 -1
  61. package/provider/default.d.ts +21 -175
  62. package/provider/default.js +139 -703
  63. package/provider/errors.d.ts +4 -4
  64. package/provider/errors.js +30 -40
  65. package/provider/index.d.ts +2 -0
  66. package/provider/index.js +22 -33
  67. package/provider/interface.d.ts +104 -131
  68. package/provider/interface.js +6 -5
  69. package/provider/rpc.d.ts +57 -0
  70. package/provider/rpc.js +364 -0
  71. package/provider/sequencer.d.ts +66 -0
  72. package/provider/sequencer.js +443 -0
  73. package/provider/utils.d.ts +7 -9
  74. package/provider/utils.js +39 -44
  75. package/signer/default.d.ts +5 -9
  76. package/signer/default.js +72 -177
  77. package/signer/index.js +18 -31
  78. package/signer/interface.d.ts +29 -33
  79. package/signer/interface.js +6 -5
  80. package/src/account/default.ts +26 -146
  81. package/src/account/interface.ts +5 -20
  82. package/src/contract/contractFactory.ts +3 -6
  83. package/src/contract/default.ts +6 -4
  84. package/src/contract/interface.ts +2 -2
  85. package/src/provider/default.ts +63 -394
  86. package/src/provider/index.ts +2 -0
  87. package/src/provider/interface.ts +68 -63
  88. package/src/provider/rpc.ts +300 -0
  89. package/src/provider/sequencer.ts +384 -0
  90. package/src/types/account.ts +2 -3
  91. package/src/types/api/index.ts +17 -0
  92. package/src/types/api/rpc.ts +247 -0
  93. package/src/types/api/sequencer.ts +331 -0
  94. package/src/types/index.ts +3 -1
  95. package/src/types/lib.ts +3 -1
  96. package/src/types/provider.ts +108 -0
  97. package/src/utils/provider.ts +28 -0
  98. package/src/utils/responseParser/index.ts +28 -0
  99. package/src/utils/responseParser/rpc.ts +93 -0
  100. package/src/utils/responseParser/sequencer.ts +127 -0
  101. package/types/account.d.ts +5 -7
  102. package/types/account.js +2 -2
  103. package/types/api/index.d.ts +16 -0
  104. package/types/api/index.js +18 -0
  105. package/types/api/rpc.d.ts +221 -0
  106. package/types/api/rpc.js +2 -0
  107. package/types/api/sequencer.d.ts +289 -0
  108. package/types/api/sequencer.js +2 -0
  109. package/types/contract.d.ts +1 -1
  110. package/types/contract.js +2 -2
  111. package/types/index.d.ts +3 -1
  112. package/types/index.js +35 -34
  113. package/types/lib.d.ts +36 -41
  114. package/types/lib.js +2 -2
  115. package/types/provider.d.ts +86 -0
  116. package/types/provider.js +2 -0
  117. package/types/signer.d.ts +2 -2
  118. package/types/signer.js +2 -2
  119. package/utils/address.js +26 -37
  120. package/utils/ellipticCurve.d.ts +1 -6
  121. package/utils/ellipticCurve.js +73 -137
  122. package/utils/encode.js +49 -85
  123. package/utils/hash.d.ts +4 -31
  124. package/utils/hash.js +76 -141
  125. package/utils/json.d.ts +13 -45
  126. package/utils/json.js +15 -22
  127. package/utils/number.d.ts +2 -9
  128. package/utils/number.js +47 -81
  129. package/utils/provider.d.ts +4 -0
  130. package/utils/provider.js +38 -0
  131. package/utils/responseParser/index.d.ts +11 -0
  132. package/utils/responseParser/index.js +9 -0
  133. package/utils/responseParser/rpc.d.ts +13 -0
  134. package/utils/responseParser/rpc.js +96 -0
  135. package/utils/responseParser/sequencer.d.ts +13 -0
  136. package/utils/responseParser/sequencer.js +124 -0
  137. package/utils/shortString.js +13 -21
  138. package/utils/stark.d.ts +0 -1
  139. package/utils/stark.js +59 -93
  140. package/utils/transaction.d.ts +3 -6
  141. package/utils/transaction.js +50 -81
  142. package/utils/typedData/index.d.ts +3 -15
  143. package/utils/typedData/index.js +109 -175
  144. package/utils/typedData/types.d.ts +9 -9
  145. package/utils/typedData/types.js +2 -2
  146. package/utils/typedData/utils.js +6 -6
  147. package/utils/uint256.d.ts +5 -5
  148. package/utils/uint256.js +16 -26
  149. package/www/docs/API/account.md +3 -4
  150. package/www/docs/API/contract.md +2 -2
  151. package/www/docs/API/contractFactory.md +2 -2
  152. package/www/docs/API/provider.md +185 -74
  153. package/www/guides/account.md +1 -8
  154. package/www/guides/erc20.md +3 -0
  155. package/__tests__/provider.test.ts +0 -168
  156. package/dist/types/api.d.ts +0 -261
  157. package/src/types/api.ts +0 -303
  158. package/types/api.d.ts +0 -287
  159. package/types/api.js +0 -2
@@ -0,0 +1,443 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __read = (this && this.__read) || function (o, n) {
39
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
40
+ if (!m) return o;
41
+ var i = m.call(o), r, ar = [], e;
42
+ try {
43
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
+ }
45
+ catch (error) { e = { error: error }; }
46
+ finally {
47
+ try {
48
+ if (r && !r.done && (m = i["return"])) m.call(i);
49
+ }
50
+ finally { if (e) throw e.error; }
51
+ }
52
+ return ar;
53
+ };
54
+ var __importDefault = (this && this.__importDefault) || function (mod) {
55
+ return (mod && mod.__esModule) ? mod : { "default": mod };
56
+ };
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.SequencerProvider = void 0;
59
+ var url_join_1 = __importDefault(require("url-join"));
60
+ var constants_1 = require("../constants");
61
+ var hash_1 = require("../utils/hash");
62
+ var json_1 = require("../utils/json");
63
+ var number_1 = require("../utils/number");
64
+ var provider_1 = require("../utils/provider");
65
+ var sequencer_1 = require("../utils/responseParser/sequencer");
66
+ var stark_1 = require("../utils/stark");
67
+ var errors_1 = require("./errors");
68
+ var utils_1 = require("./utils");
69
+ function isEmptyQueryObject(obj) {
70
+ return (obj === undefined ||
71
+ Object.keys(obj).length === 0 ||
72
+ (Object.keys(obj).length === 1 &&
73
+ Object.entries(obj).every(function (_a) {
74
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
75
+ return k === 'blockIdentifier' && v === null;
76
+ })));
77
+ }
78
+ var SequencerProvider = /** @class */ (function () {
79
+ function SequencerProvider(optionsOrProvider) {
80
+ if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
81
+ var _a, _b, _c;
82
+ this.responseParser = new sequencer_1.SequencerAPIResponseParser();
83
+ if ('network' in optionsOrProvider) {
84
+ this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
85
+ this.chainId = SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
86
+ this.feederGatewayUrl = (0, url_join_1.default)(this.baseUrl, 'feeder_gateway');
87
+ this.gatewayUrl = (0, url_join_1.default)(this.baseUrl, 'gateway');
88
+ }
89
+ else {
90
+ this.baseUrl = optionsOrProvider.baseUrl;
91
+ this.feederGatewayUrl =
92
+ (_a = optionsOrProvider.feederGatewayUrl) !== null && _a !== void 0 ? _a : (0, url_join_1.default)(this.baseUrl, 'feeder_gateway');
93
+ this.gatewayUrl = (_b = optionsOrProvider.gatewayUrl) !== null && _b !== void 0 ? _b : (0, url_join_1.default)(this.baseUrl, 'gateway');
94
+ this.chainId =
95
+ (_c = optionsOrProvider.chainId) !== null && _c !== void 0 ? _c : SequencerProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
96
+ }
97
+ }
98
+ SequencerProvider.getNetworkFromName = function (name) {
99
+ switch (name) {
100
+ case 'mainnet-alpha':
101
+ return 'https://alpha-mainnet.starknet.io';
102
+ case 'goerli-alpha':
103
+ default:
104
+ return 'https://alpha4.starknet.io';
105
+ }
106
+ };
107
+ SequencerProvider.getChainIdFromBaseUrl = function (baseUrl) {
108
+ try {
109
+ var url = new URL(baseUrl);
110
+ if (url.host.includes('mainnet.starknet.io')) {
111
+ return constants_1.StarknetChainId.MAINNET;
112
+ }
113
+ }
114
+ catch (_a) {
115
+ // eslint-disable-next-line no-console
116
+ console.error("Could not parse baseUrl: ".concat(baseUrl));
117
+ }
118
+ return constants_1.StarknetChainId.TESTNET;
119
+ };
120
+ SequencerProvider.prototype.getFetchUrl = function (endpoint) {
121
+ var gatewayUrlEndpoints = ['add_transaction'];
122
+ return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
123
+ };
124
+ SequencerProvider.prototype.getFetchMethod = function (endpoint) {
125
+ var postMethodEndpoints = ['add_transaction', 'call_contract', 'estimate_fee'];
126
+ return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
127
+ };
128
+ SequencerProvider.prototype.getQueryString = function (query) {
129
+ if (isEmptyQueryObject(query)) {
130
+ return '';
131
+ }
132
+ var queryString = Object.entries(query)
133
+ .map(function (_a) {
134
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
135
+ if (key === 'blockIdentifier') {
136
+ return "".concat((0, utils_1.getFormattedBlockIdentifier)(value));
137
+ }
138
+ return "".concat(key, "=").concat(value);
139
+ })
140
+ .join('&');
141
+ return "?".concat(queryString);
142
+ };
143
+ SequencerProvider.prototype.getHeaders = function (method) {
144
+ if (method === 'POST') {
145
+ return {
146
+ 'Content-Type': 'application/json',
147
+ };
148
+ }
149
+ return undefined;
150
+ };
151
+ // typesafe fetch
152
+ SequencerProvider.prototype.fetchEndpoint = function (endpoint) {
153
+ // typescript type magiuc to create a nice fitting function interface
154
+ var _a = []; // when both query and request are needed, we cant omit anything
155
+ for (
156
+ // typescript type magiuc to create a nice fitting function interface
157
+ var _i = 1 // when both query and request are needed, we cant omit anything
158
+ ;
159
+ // typescript type magiuc to create a nice fitting function interface
160
+ _i < arguments.length // when both query and request are needed, we cant omit anything
161
+ ;
162
+ // typescript type magiuc to create a nice fitting function interface
163
+ _i++ // when both query and request are needed, we cant omit anything
164
+ ) {
165
+ // typescript type magiuc to create a nice fitting function interface
166
+ _a[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
167
+ }
168
+ // typescript type magiuc to create a nice fitting function interface
169
+ var _b = __read(_a, 2), query = _b[0], request = _b[1]; // when both query and request are needed, we cant omit anything
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ var baseUrl, method, queryString, headers, url, res, textResponse, responseBody, errorCode, err_1;
172
+ return __generator(this, function (_c) {
173
+ switch (_c.label) {
174
+ case 0:
175
+ baseUrl = this.getFetchUrl(endpoint);
176
+ method = this.getFetchMethod(endpoint);
177
+ queryString = this.getQueryString(query);
178
+ headers = this.getHeaders(method);
179
+ url = (0, url_join_1.default)(baseUrl, endpoint, queryString);
180
+ _c.label = 1;
181
+ case 1:
182
+ _c.trys.push([1, 4, , 5]);
183
+ return [4 /*yield*/, fetch(url, {
184
+ method: method,
185
+ body: (0, json_1.stringify)(request),
186
+ headers: headers,
187
+ })];
188
+ case 2:
189
+ res = _c.sent();
190
+ return [4 /*yield*/, res.text()];
191
+ case 3:
192
+ textResponse = _c.sent();
193
+ if (!res.ok) {
194
+ responseBody = void 0;
195
+ try {
196
+ responseBody = (0, json_1.parse)(textResponse);
197
+ }
198
+ catch (_d) {
199
+ // if error parsing fails, return an http error
200
+ throw new errors_1.HttpError(res.statusText, res.status);
201
+ }
202
+ errorCode = responseBody.code || (responseBody === null || responseBody === void 0 ? void 0 : responseBody.status_code);
203
+ throw new errors_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
204
+ }
205
+ if (endpoint === 'estimate_fee') {
206
+ return [2 /*return*/, (0, json_1.parseAlwaysAsBig)(textResponse, function (_, v) {
207
+ if (v && typeof v === 'bigint') {
208
+ return (0, number_1.toBN)(v.toString());
209
+ }
210
+ return v;
211
+ })];
212
+ }
213
+ return [2 /*return*/, (0, json_1.parse)(textResponse)];
214
+ case 4:
215
+ err_1 = _c.sent();
216
+ // rethrow custom errors
217
+ if (err_1 instanceof errors_1.GatewayError || err_1 instanceof errors_1.HttpError) {
218
+ throw err_1;
219
+ }
220
+ if (err_1 instanceof Error) {
221
+ throw Error("Could not ".concat(method, " from endpoint `").concat(url, "`: ").concat(err_1.message));
222
+ }
223
+ throw err_1;
224
+ case 5: return [2 /*return*/];
225
+ }
226
+ });
227
+ });
228
+ };
229
+ SequencerProvider.prototype.callContract = function (_a, blockIdentifier) {
230
+ var contractAddress = _a.contractAddress, entryPointSelector = _a.entrypoint, _b = _a.calldata, calldata = _b === void 0 ? [] : _b;
231
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
232
+ return __awaiter(this, void 0, void 0, function () {
233
+ return __generator(this, function (_c) {
234
+ return [2 /*return*/, this.fetchEndpoint('call_contract', { blockIdentifier: blockIdentifier }, {
235
+ signature: [],
236
+ contract_address: contractAddress,
237
+ entry_point_selector: (0, hash_1.getSelectorFromName)(entryPointSelector),
238
+ calldata: calldata,
239
+ }).then(this.responseParser.parseCallContractResponse)];
240
+ });
241
+ });
242
+ };
243
+ SequencerProvider.prototype.getBlock = function (blockIdentifier) {
244
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
245
+ return __awaiter(this, void 0, void 0, function () {
246
+ return __generator(this, function (_a) {
247
+ return [2 /*return*/, this.fetchEndpoint('get_block', { blockIdentifier: blockIdentifier }).then(this.responseParser.parseGetBlockResponse)];
248
+ });
249
+ });
250
+ };
251
+ SequencerProvider.prototype.getStorageAt = function (contractAddress, key, blockHashOrTag) {
252
+ if (blockHashOrTag === void 0) { blockHashOrTag = 'pending'; }
253
+ return __awaiter(this, void 0, void 0, function () {
254
+ var parsedKey;
255
+ return __generator(this, function (_a) {
256
+ parsedKey = (0, number_1.toBN)(key).toString(10);
257
+ return [2 /*return*/, this.fetchEndpoint('get_storage_at', {
258
+ blockIdentifier: blockHashOrTag,
259
+ contractAddress: contractAddress,
260
+ key: parsedKey,
261
+ })];
262
+ });
263
+ });
264
+ };
265
+ SequencerProvider.prototype.getTransaction = function (txHash) {
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ var txHashHex;
268
+ var _this = this;
269
+ return __generator(this, function (_a) {
270
+ txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
271
+ return [2 /*return*/, this.fetchEndpoint('get_transaction', { transactionHash: txHashHex }).then(function (value) {
272
+ return _this.responseParser.parseGetTransactionResponse(value);
273
+ })];
274
+ });
275
+ });
276
+ };
277
+ SequencerProvider.prototype.getTransactionReceipt = function (txHash) {
278
+ return __awaiter(this, void 0, void 0, function () {
279
+ var txHashHex;
280
+ return __generator(this, function (_a) {
281
+ txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
282
+ return [2 /*return*/, this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex }).then(this.responseParser.parseGetTransactionReceiptResponse)];
283
+ });
284
+ });
285
+ };
286
+ SequencerProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
287
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
288
+ return __awaiter(this, void 0, void 0, function () {
289
+ return __generator(this, function (_a) {
290
+ return [2 /*return*/, this.fetchEndpoint('get_full_contract', { blockIdentifier: blockIdentifier, contractAddress: contractAddress }).then(provider_1.parseContract)];
291
+ });
292
+ });
293
+ };
294
+ SequencerProvider.prototype.invokeFunction = function (functionInvocation, details) {
295
+ var _a, _b;
296
+ return __awaiter(this, void 0, void 0, function () {
297
+ return __generator(this, function (_c) {
298
+ return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
299
+ type: 'INVOKE_FUNCTION',
300
+ contract_address: functionInvocation.contractAddress,
301
+ entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
302
+ calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)((_a = functionInvocation.calldata) !== null && _a !== void 0 ? _a : []),
303
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = functionInvocation.signature) !== null && _b !== void 0 ? _b : []),
304
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
305
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
306
+ }).then(this.responseParser.parseInvokeFunctionResponse)];
307
+ });
308
+ });
309
+ };
310
+ SequencerProvider.prototype.deployContract = function (_a) {
311
+ var contract = _a.contract, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
312
+ return __awaiter(this, void 0, void 0, function () {
313
+ var contractDefinition;
314
+ return __generator(this, function (_b) {
315
+ contractDefinition = (0, provider_1.parseContract)(contract);
316
+ return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
317
+ type: 'DEPLOY',
318
+ contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
319
+ constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
320
+ contract_definition: contractDefinition,
321
+ }).then(this.responseParser.parseDeployContractResponse)];
322
+ });
323
+ });
324
+ };
325
+ SequencerProvider.prototype.declareContract = function (_a) {
326
+ var contract = _a.contract;
327
+ return __awaiter(this, void 0, void 0, function () {
328
+ var contractDefinition;
329
+ return __generator(this, function (_b) {
330
+ contractDefinition = (0, provider_1.parseContract)(contract);
331
+ return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
332
+ type: 'DECLARE',
333
+ contract_class: contractDefinition,
334
+ nonce: (0, number_1.toHex)(constants_1.ZERO),
335
+ signature: [],
336
+ sender_address: (0, number_1.toHex)(constants_1.ONE),
337
+ }).then(this.responseParser.parseDeclareContractResponse)];
338
+ });
339
+ });
340
+ };
341
+ SequencerProvider.prototype.getEstimateFee = function (invocation, blockIdentifier, invocationDetails) {
342
+ var _a;
343
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
344
+ if (invocationDetails === void 0) { invocationDetails = {}; }
345
+ return __awaiter(this, void 0, void 0, function () {
346
+ return __generator(this, function (_b) {
347
+ return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
348
+ contract_address: invocation.contractAddress,
349
+ entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
350
+ calldata: (_a = invocation.calldata) !== null && _a !== void 0 ? _a : [],
351
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(invocation.signature || []),
352
+ version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
353
+ }).then(this.responseParser.parseFeeEstimateResponse)];
354
+ });
355
+ });
356
+ };
357
+ SequencerProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
358
+ if (retryInterval === void 0) { retryInterval = 8000; }
359
+ return __awaiter(this, void 0, void 0, function () {
360
+ var onchain, res, successStates, errorStates, message, error;
361
+ return __generator(this, function (_a) {
362
+ switch (_a.label) {
363
+ case 0:
364
+ onchain = false;
365
+ _a.label = 1;
366
+ case 1:
367
+ if (!!onchain) return [3 /*break*/, 4];
368
+ // eslint-disable-next-line no-await-in-loop
369
+ return [4 /*yield*/, (0, provider_1.wait)(retryInterval)];
370
+ case 2:
371
+ // eslint-disable-next-line no-await-in-loop
372
+ _a.sent();
373
+ return [4 /*yield*/, this.getTransactionStatus(txHash)];
374
+ case 3:
375
+ res = _a.sent();
376
+ successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
377
+ errorStates = ['REJECTED', 'NOT_RECEIVED'];
378
+ if (successStates.includes(res.tx_status)) {
379
+ onchain = true;
380
+ }
381
+ else if (errorStates.includes(res.tx_status)) {
382
+ message = res.tx_failure_reason
383
+ ? "".concat(res.tx_status, ": ").concat(res.tx_failure_reason.code, "\n").concat(res.tx_failure_reason.error_message)
384
+ : res.tx_status;
385
+ error = new Error(message);
386
+ error.response = res;
387
+ throw error;
388
+ }
389
+ return [3 /*break*/, 1];
390
+ case 4: return [2 /*return*/];
391
+ }
392
+ });
393
+ });
394
+ };
395
+ /**
396
+ * Gets the status of a transaction.
397
+ *
398
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
399
+ *
400
+ * @param txHash
401
+ * @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
402
+ */
403
+ SequencerProvider.prototype.getTransactionStatus = function (txHash) {
404
+ return __awaiter(this, void 0, void 0, function () {
405
+ var txHashHex;
406
+ return __generator(this, function (_a) {
407
+ txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
408
+ return [2 /*return*/, this.fetchEndpoint('get_transaction_status', { transactionHash: txHashHex })];
409
+ });
410
+ });
411
+ };
412
+ /**
413
+ * Gets the smart contract address on the goerli testnet.
414
+ *
415
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
416
+ * @returns starknet smart contract addresses
417
+ */
418
+ SequencerProvider.prototype.getContractAddresses = function () {
419
+ return __awaiter(this, void 0, void 0, function () {
420
+ return __generator(this, function (_a) {
421
+ return [2 /*return*/, this.fetchEndpoint('get_contract_addresses')];
422
+ });
423
+ });
424
+ };
425
+ /**
426
+ * Gets the transaction trace from a tx id.
427
+ *
428
+ *
429
+ * @param txHash
430
+ * @returns the transaction trace
431
+ */
432
+ SequencerProvider.prototype.getTransactionTrace = function (txHash) {
433
+ return __awaiter(this, void 0, void 0, function () {
434
+ var txHashHex;
435
+ return __generator(this, function (_a) {
436
+ txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
437
+ return [2 /*return*/, this.fetchEndpoint('get_transaction_trace', { transactionHash: txHashHex })];
438
+ });
439
+ });
440
+ };
441
+ return SequencerProvider;
442
+ }());
443
+ exports.SequencerProvider = SequencerProvider;
@@ -1,9 +1,8 @@
1
1
  import BN from 'bn.js';
2
2
  import { BlockIdentifier } from '../provider/utils';
3
3
  import { BigNumberish } from '../utils/number';
4
- export interface EstimateFee {
5
- amount: BN;
6
- unit: string;
4
+ import { EstimateFeeResponse } from './provider';
5
+ export interface EstimateFee extends EstimateFeeResponse {
7
6
  suggestedMaxFee: BN;
8
7
  }
9
8
  export interface EstimateFeeDetails {
@@ -0,0 +1,16 @@
1
+ import { BigNumberish } from '../../utils/number';
2
+ import { Signature } from '../lib';
3
+ export declare type RawArgs = {
4
+ [inputName: string]: string | string[] | {
5
+ type: 'struct';
6
+ [k: string]: BigNumberish;
7
+ };
8
+ };
9
+ export declare type Calldata = string[];
10
+ export declare type Overrides = {
11
+ maxFee?: BigNumberish;
12
+ nonce?: BigNumberish;
13
+ signature?: Signature;
14
+ };
15
+ export * from './sequencer';
16
+ export * from './rpc';
@@ -0,0 +1,18 @@
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("./sequencer"), exports);
18
+ __exportStar(require("./rpc"), exports);