starknet 3.16.3 → 3.17.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [3.17.0](https://github.com/0xs34n/starknet.js/compare/v3.16.3...v3.17.0) (2022-07-15)
2
+
3
+ ### Features
4
+
5
+ - support SN 0.9.1 estimate_fee response ([9302aab](https://github.com/0xs34n/starknet.js/commit/9302aab9cbbe5eaa3a9933b19f8f46b2dd6d6a1d))
6
+
1
7
  ## [3.16.3](https://github.com/0xs34n/starknet.js/compare/v3.16.2...v3.16.3) (2022-07-15)
2
8
 
3
9
  ### Bug Fixes
@@ -24,20 +24,6 @@ var __extends =
24
24
  d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
25
25
  };
26
26
  })();
27
- var __assign =
28
- (this && this.__assign) ||
29
- function () {
30
- __assign =
31
- Object.assign ||
32
- function (t) {
33
- for (var s, i = 1, n = arguments.length; i < n; i++) {
34
- s = arguments[i];
35
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
36
- }
37
- return t;
38
- };
39
- return __assign.apply(this, arguments);
40
- };
41
27
  var __awaiter =
42
28
  (this && this.__awaiter) ||
43
29
  function (thisArg, _arguments, P, generator) {
@@ -251,34 +237,36 @@ var Account = /** @class */ (function (_super) {
251
237
  });
252
238
  };
253
239
  Account.prototype.estimateFee = function (calls, _a) {
254
- var _b = _a === void 0 ? {} : _a,
255
- providedNonce = _b.nonce,
256
- _c = _b.blockIdentifier,
257
- blockIdentifier = _c === void 0 ? 'pending' : _c;
240
+ var _b;
241
+ var _c = _a === void 0 ? {} : _a,
242
+ providedNonce = _c.nonce,
243
+ _d = _c.blockIdentifier,
244
+ blockIdentifier = _d === void 0 ? 'pending' : _d;
258
245
  return __awaiter(this, void 0, void 0, function () {
259
246
  var transactions,
260
247
  nonce,
261
- _d,
248
+ _e,
262
249
  version,
263
250
  signerDetails,
264
251
  signature,
265
252
  calldata,
266
253
  fetchedEstimate,
254
+ fee,
267
255
  suggestedMaxFee;
268
- return __generator(this, function (_e) {
269
- switch (_e.label) {
256
+ return __generator(this, function (_f) {
257
+ switch (_f.label) {
270
258
  case 0:
271
259
  transactions = Array.isArray(calls) ? calls : [calls];
272
260
  if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
273
- _d = providedNonce;
261
+ _e = providedNonce;
274
262
  return [3 /*break*/, 3];
275
263
  case 1:
276
264
  return [4 /*yield*/, this.getNonce()];
277
265
  case 2:
278
- _d = _e.sent();
279
- _e.label = 3;
266
+ _e = _f.sent();
267
+ _f.label = 3;
280
268
  case 3:
281
- nonce = _d;
269
+ nonce = _e;
282
270
  version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
283
271
  signerDetails = {
284
272
  walletAddress: this.address,
@@ -289,7 +277,7 @@ var Account = /** @class */ (function (_super) {
289
277
  };
290
278
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
291
279
  case 4:
292
- signature = _e.sent();
280
+ signature = _f.sent();
293
281
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
294
282
  return [
295
283
  4 /*yield*/,
@@ -306,11 +294,22 @@ var Account = /** @class */ (function (_super) {
306
294
  ),
307
295
  ];
308
296
  case 5:
309
- fetchedEstimate = _e.sent();
310
- suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fetchedEstimate.amount);
297
+ fetchedEstimate = _f.sent();
298
+ fee =
299
+ (_b = fetchedEstimate.overall_fee) !== null && _b !== void 0
300
+ ? _b
301
+ : fetchedEstimate.amount;
302
+ if (fee === undefined) {
303
+ throw new Error('Expected either amount or overall_fee in estimate_fee response');
304
+ }
305
+ suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fee);
311
306
  return [
312
307
  2 /*return*/,
313
- __assign(__assign({}, fetchedEstimate), { suggestedMaxFee: suggestedMaxFee }),
308
+ {
309
+ amount: fee,
310
+ unit: fetchedEstimate.unit,
311
+ suggestedMaxFee: suggestedMaxFee,
312
+ },
314
313
  ];
315
314
  }
316
315
  });
@@ -14,17 +14,6 @@ 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
- };
28
17
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
18
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
19
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -128,22 +117,23 @@ var Account = /** @class */ (function (_super) {
128
117
  });
129
118
  };
130
119
  Account.prototype.estimateFee = function (calls, _a) {
131
- var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
120
+ var _b;
121
+ var _c = _a === void 0 ? {} : _a, providedNonce = _c.nonce, _d = _c.blockIdentifier, blockIdentifier = _d === void 0 ? 'pending' : _d;
132
122
  return __awaiter(this, void 0, void 0, function () {
133
- var transactions, nonce, _d, version, signerDetails, signature, calldata, fetchedEstimate, suggestedMaxFee;
134
- return __generator(this, function (_e) {
135
- switch (_e.label) {
123
+ var transactions, nonce, _e, version, signerDetails, signature, calldata, fetchedEstimate, fee, suggestedMaxFee;
124
+ return __generator(this, function (_f) {
125
+ switch (_f.label) {
136
126
  case 0:
137
127
  transactions = Array.isArray(calls) ? calls : [calls];
138
128
  if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
139
- _d = providedNonce;
129
+ _e = providedNonce;
140
130
  return [3 /*break*/, 3];
141
131
  case 1: return [4 /*yield*/, this.getNonce()];
142
132
  case 2:
143
- _d = (_e.sent());
144
- _e.label = 3;
133
+ _e = (_f.sent());
134
+ _f.label = 3;
145
135
  case 3:
146
- nonce = _d;
136
+ nonce = _e;
147
137
  version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
148
138
  signerDetails = {
149
139
  walletAddress: this.address,
@@ -154,7 +144,7 @@ var Account = /** @class */ (function (_super) {
154
144
  };
155
145
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
156
146
  case 4:
157
- signature = _e.sent();
147
+ signature = _f.sent();
158
148
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
159
149
  return [4 /*yield*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
160
150
  contract_address: this.address,
@@ -164,9 +154,17 @@ var Account = /** @class */ (function (_super) {
164
154
  signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
165
155
  })];
166
156
  case 5:
167
- fetchedEstimate = _e.sent();
168
- suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fetchedEstimate.amount);
169
- return [2 /*return*/, __assign(__assign({}, fetchedEstimate), { suggestedMaxFee: suggestedMaxFee })];
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
+ }];
170
168
  }
171
169
  });
172
170
  });
@@ -1,8 +1,9 @@
1
1
  import BN from 'bn.js';
2
2
  import { BlockIdentifier } from '../provider/utils';
3
3
  import { BigNumberish } from '../utils/number';
4
- import { EstimateFeeResponse } from './api';
5
- export interface EstimateFee extends EstimateFeeResponse {
4
+ export interface EstimateFee {
5
+ amount: BN;
6
+ unit: string;
6
7
  suggestedMaxFee: BN;
7
8
  }
8
9
  export interface EstimateFeeDetails {
@@ -240,8 +240,11 @@ export declare type FailedTransactionReceiptResponse = {
240
240
  };
241
241
  export declare type TransactionReceiptResponse = SuccessfulTransactionReceiptResponse | FailedTransactionReceiptResponse;
242
242
  export declare type EstimateFeeResponse = {
243
- amount: BN;
243
+ overall_fee?: BN;
244
+ amount?: BN;
244
245
  unit: string;
246
+ gas_price?: BN;
247
+ gas_usage?: BigNumberish;
245
248
  };
246
249
  export declare type RawArgs = {
247
250
  [inputName: string]: string | string[] | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.16.3",
3
+ "version": "3.17.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -83,10 +83,15 @@ export class Account extends Provider implements AccountInterface {
83
83
  signature: bigNumberishArrayToDecimalStringArray(signature),
84
84
  }
85
85
  );
86
- const suggestedMaxFee = estimatedFeeToMaxFee(fetchedEstimate.amount);
86
+ const fee = fetchedEstimate.overall_fee ?? fetchedEstimate.amount;
87
+ if (fee === undefined) {
88
+ throw new Error('Expected either amount or overall_fee in estimate_fee response');
89
+ }
90
+ const suggestedMaxFee = estimatedFeeToMaxFee(fee);
87
91
 
88
92
  return {
89
- ...fetchedEstimate,
93
+ amount: fee,
94
+ unit: fetchedEstimate.unit,
90
95
  suggestedMaxFee,
91
96
  };
92
97
  }
@@ -2,9 +2,10 @@ import BN from 'bn.js';
2
2
 
3
3
  import { BlockIdentifier } from '../provider/utils';
4
4
  import { BigNumberish } from '../utils/number';
5
- import { EstimateFeeResponse } from './api';
6
5
 
7
- export interface EstimateFee extends EstimateFeeResponse {
6
+ export interface EstimateFee {
7
+ amount: BN;
8
+ unit: string;
8
9
  suggestedMaxFee: BN;
9
10
  }
10
11
 
package/src/types/api.ts CHANGED
@@ -280,9 +280,13 @@ export type TransactionReceiptResponse =
280
280
  | SuccessfulTransactionReceiptResponse
281
281
  | FailedTransactionReceiptResponse;
282
282
 
283
+ // Support 0.9.1 changes in a backward-compatible way
283
284
  export type EstimateFeeResponse = {
284
- amount: BN;
285
+ overall_fee?: BN;
286
+ amount?: BN;
285
287
  unit: string;
288
+ gas_price?: BN;
289
+ gas_usage?: BigNumberish;
286
290
  };
287
291
 
288
292
  export type RawArgs = {
@@ -2,8 +2,9 @@ import BN from 'bn.js';
2
2
 
3
3
  import { BlockIdentifier } from '../provider/utils';
4
4
  import { BigNumberish } from '../utils/number';
5
- import { EstimateFeeResponse } from './api';
6
- export interface EstimateFee extends EstimateFeeResponse {
5
+ export interface EstimateFee {
6
+ amount: BN;
7
+ unit: string;
7
8
  suggestedMaxFee: BN;
8
9
  }
9
10
  export interface EstimateFeeDetails {
package/types/api.d.ts CHANGED
@@ -263,8 +263,11 @@ export declare type TransactionReceiptResponse =
263
263
  | SuccessfulTransactionReceiptResponse
264
264
  | FailedTransactionReceiptResponse;
265
265
  export declare type EstimateFeeResponse = {
266
- amount: BN;
266
+ overall_fee?: BN;
267
+ amount?: BN;
267
268
  unit: string;
269
+ gas_price?: BN;
270
+ gas_usage?: BigNumberish;
268
271
  };
269
272
  export declare type RawArgs = {
270
273
  [inputName: string]: