starknet 4.7.0 → 4.9.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 +43 -0
- package/CONTRIBUTING.md +2 -2
- package/__mocks__/ERC20.json +32561 -29055
- package/__mocks__/l1l2_compiled.json +10107 -0
- package/__tests__/account.test.ts +32 -24
- package/__tests__/contract.test.ts +25 -14
- package/__tests__/defaultProvider.test.ts +19 -49
- package/__tests__/fixtures.ts +11 -1
- package/__tests__/rpcProvider.test.ts +6 -15
- package/__tests__/sequencerProvider.test.ts +57 -11
- package/__tests__/utils/merkle.test.ts +113 -3
- package/__tests__/utils/typedData.test.ts +3 -3
- package/account/default.d.ts +10 -44
- package/account/default.js +255 -61
- package/account/interface.d.ts +78 -7
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/contract/default.js +6 -6
- package/dist/account/default.d.ts +10 -44
- package/dist/account/default.js +255 -61
- package/dist/account/interface.d.ts +78 -7
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/contract/default.js +6 -6
- package/dist/provider/default.d.ts +8 -3
- package/dist/provider/default.js +31 -4
- package/dist/provider/interface.d.ts +67 -5
- package/dist/provider/rpc.d.ts +7 -2
- package/dist/provider/rpc.js +83 -8
- package/dist/provider/sequencer.d.ts +9 -3
- package/dist/provider/sequencer.js +93 -14
- package/dist/signer/default.d.ts +4 -1
- package/dist/signer/default.js +22 -0
- package/dist/signer/interface.d.ts +27 -2
- package/dist/types/api/openrpc.d.ts +24 -2
- package/dist/types/api/sequencer.d.ts +43 -23
- package/dist/types/lib.d.ts +23 -2
- package/dist/types/provider.d.ts +19 -10
- package/dist/types/signer.d.ts +14 -1
- package/dist/utils/hash.d.ts +8 -0
- package/dist/utils/hash.js +28 -2
- package/dist/utils/merkle.js +4 -5
- package/dist/utils/number.d.ts +5 -0
- package/dist/utils/number.js +29 -1
- package/dist/utils/responseParser/rpc.d.ts +2 -6
- package/dist/utils/responseParser/rpc.js +0 -11
- package/dist/utils/responseParser/sequencer.js +11 -33
- package/package.json +1 -1
- package/provider/default.d.ts +8 -3
- package/provider/default.js +31 -4
- package/provider/interface.d.ts +67 -5
- package/provider/rpc.d.ts +7 -2
- package/provider/rpc.js +83 -8
- package/provider/sequencer.d.ts +9 -3
- package/provider/sequencer.js +93 -14
- package/signer/default.d.ts +4 -1
- package/signer/default.js +22 -0
- package/signer/interface.d.ts +27 -2
- package/src/account/default.ts +201 -53
- package/src/account/interface.ts +104 -6
- package/src/constants.ts +1 -0
- package/src/contract/default.ts +6 -6
- package/src/provider/default.ts +43 -5
- package/src/provider/interface.ts +92 -7
- package/src/provider/rpc.ts +86 -12
- package/src/provider/sequencer.ts +105 -13
- package/src/signer/default.ts +54 -2
- package/src/signer/interface.ts +31 -2
- package/src/types/api/openrpc.ts +28 -2
- package/src/types/api/sequencer.ts +54 -25
- package/src/types/lib.ts +30 -2
- package/src/types/provider.ts +31 -11
- package/src/types/signer.ts +18 -1
- package/src/utils/hash.ts +70 -2
- package/src/utils/merkle.ts +4 -5
- package/src/utils/number.ts +27 -0
- package/src/utils/responseParser/rpc.ts +4 -20
- package/src/utils/responseParser/sequencer.ts +14 -7
- package/types/api/openrpc.d.ts +24 -2
- package/types/api/sequencer.d.ts +43 -23
- package/types/lib.d.ts +23 -2
- package/types/provider.d.ts +19 -10
- package/types/signer.d.ts +14 -1
- package/utils/hash.d.ts +8 -0
- package/utils/hash.js +28 -2
- package/utils/merkle.js +4 -5
- package/utils/number.d.ts +5 -0
- package/utils/number.js +29 -1
- package/utils/responseParser/rpc.d.ts +2 -6
- package/utils/responseParser/rpc.js +0 -11
- package/utils/responseParser/sequencer.js +11 -33
- package/www/docs/API/account.md +60 -1
- package/www/docs/API/provider.md +320 -23
- package/www/guides/account.md +1 -1
- package/www/guides/erc20.md +13 -7
package/account/default.js
CHANGED
|
@@ -68,6 +68,7 @@ var default_1 = require("../provider/default");
|
|
|
68
68
|
var signer_1 = require("../signer");
|
|
69
69
|
var hash_1 = require("../utils/hash");
|
|
70
70
|
var number_1 = require("../utils/number");
|
|
71
|
+
var provider_1 = require("../utils/provider");
|
|
71
72
|
var stark_1 = require("../utils/stark");
|
|
72
73
|
var transaction_1 = require("../utils/transaction");
|
|
73
74
|
var typedData_1 = require("../utils/typedData");
|
|
@@ -87,7 +88,14 @@ var Account = /** @class */ (function (_super) {
|
|
|
87
88
|
});
|
|
88
89
|
});
|
|
89
90
|
};
|
|
90
|
-
Account.prototype.estimateFee = function (calls,
|
|
91
|
+
Account.prototype.estimateFee = function (calls, estimateFeeDetails) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
return [2 /*return*/, this.estimateInvokeFee(calls, estimateFeeDetails)];
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
Account.prototype.estimateInvokeFee = function (calls, _a) {
|
|
91
99
|
var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
|
|
92
100
|
return __awaiter(this, void 0, void 0, function () {
|
|
93
101
|
var transactions, nonce, _c, _d, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
|
|
@@ -120,7 +128,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
120
128
|
case 5:
|
|
121
129
|
signature = _e.sent();
|
|
122
130
|
calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
|
|
123
|
-
return [4 /*yield*/, _super.prototype.
|
|
131
|
+
return [4 /*yield*/, _super.prototype.getInvokeEstimateFee.call(this, { contractAddress: this.address, calldata: calldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
|
|
124
132
|
case 6:
|
|
125
133
|
response = _e.sent();
|
|
126
134
|
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
|
|
@@ -129,50 +137,125 @@ var Account = /** @class */ (function (_super) {
|
|
|
129
137
|
});
|
|
130
138
|
});
|
|
131
139
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
Account.prototype.estimateDeclareFee = function (_a, _b) {
|
|
141
|
+
var classHash = _a.classHash, contract = _a.contract;
|
|
142
|
+
var _c = _b === void 0 ? {} : _b, blockIdentifier = _c.blockIdentifier, providedNonce = _c.nonce;
|
|
143
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
+
var nonce, _d, _e, version, chainId, contractDefinition, signature, response, suggestedMaxFee;
|
|
145
|
+
return __generator(this, function (_f) {
|
|
146
|
+
switch (_f.label) {
|
|
147
|
+
case 0:
|
|
148
|
+
_d = number_1.toBN;
|
|
149
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
150
|
+
_e = providedNonce;
|
|
151
|
+
return [3 /*break*/, 3];
|
|
152
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
153
|
+
case 2:
|
|
154
|
+
_e = (_f.sent());
|
|
155
|
+
_f.label = 3;
|
|
156
|
+
case 3:
|
|
157
|
+
nonce = _d.apply(void 0, [_e]);
|
|
158
|
+
version = (0, number_1.toBN)(hash_1.transactionVersion);
|
|
159
|
+
return [4 /*yield*/, this.getChainId()];
|
|
160
|
+
case 4:
|
|
161
|
+
chainId = _f.sent();
|
|
162
|
+
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
163
|
+
return [4 /*yield*/, this.signer.signDeclareTransaction({
|
|
164
|
+
classHash: classHash,
|
|
165
|
+
senderAddress: this.address,
|
|
166
|
+
chainId: chainId,
|
|
167
|
+
maxFee: constants_1.ZERO,
|
|
168
|
+
version: version,
|
|
169
|
+
nonce: nonce,
|
|
170
|
+
})];
|
|
171
|
+
case 5:
|
|
172
|
+
signature = _f.sent();
|
|
173
|
+
return [4 /*yield*/, _super.prototype.getDeclareEstimateFee.call(this, { senderAddress: this.address, signature: signature, contractDefinition: contractDefinition }, { version: version, nonce: nonce }, blockIdentifier)];
|
|
174
|
+
case 6:
|
|
175
|
+
response = _f.sent();
|
|
176
|
+
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
|
|
177
|
+
return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
Account.prototype.estimateAccountDeployFee = function (_a, _b) {
|
|
183
|
+
var classHash = _a.classHash, _c = _a.addressSalt, addressSalt = _c === void 0 ? 0 : _c, _d = _a.constructorCalldata, constructorCalldata = _d === void 0 ? [] : _d, providedContractAddress = _a.contractAddress;
|
|
184
|
+
var _e = _b === void 0 ? {} : _b, blockIdentifier = _e.blockIdentifier, providedNonce = _e.nonce;
|
|
185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
var nonce, _f, _g, version, chainId, contractAddress, signature, response, suggestedMaxFee;
|
|
187
|
+
return __generator(this, function (_h) {
|
|
188
|
+
switch (_h.label) {
|
|
189
|
+
case 0:
|
|
190
|
+
_f = number_1.toBN;
|
|
191
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
192
|
+
_g = providedNonce;
|
|
193
|
+
return [3 /*break*/, 3];
|
|
194
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
195
|
+
case 2:
|
|
196
|
+
_g = (_h.sent());
|
|
197
|
+
_h.label = 3;
|
|
198
|
+
case 3:
|
|
199
|
+
nonce = _f.apply(void 0, [_g]);
|
|
200
|
+
version = (0, number_1.toBN)(hash_1.transactionVersion);
|
|
201
|
+
return [4 /*yield*/, this.getChainId()];
|
|
202
|
+
case 4:
|
|
203
|
+
chainId = _h.sent();
|
|
204
|
+
contractAddress = providedContractAddress !== null && providedContractAddress !== void 0 ? providedContractAddress : (0, hash_1.calculateContractAddressFromHash)(addressSalt, classHash, constructorCalldata, 0);
|
|
205
|
+
return [4 /*yield*/, this.signer.signDeployAccountTransaction({
|
|
206
|
+
classHash: classHash,
|
|
207
|
+
contractAddress: contractAddress,
|
|
208
|
+
chainId: chainId,
|
|
209
|
+
maxFee: constants_1.ZERO,
|
|
210
|
+
version: version,
|
|
211
|
+
nonce: nonce,
|
|
212
|
+
addressSalt: addressSalt,
|
|
213
|
+
constructorCalldata: constructorCalldata,
|
|
214
|
+
})];
|
|
215
|
+
case 5:
|
|
216
|
+
signature = _h.sent();
|
|
217
|
+
return [4 /*yield*/, _super.prototype.getDeployAccountEstimateFee.call(this, { classHash: classHash, addressSalt: addressSalt, constructorCalldata: constructorCalldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
|
|
218
|
+
case 6:
|
|
219
|
+
response = _h.sent();
|
|
220
|
+
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
|
|
221
|
+
return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
};
|
|
142
226
|
Account.prototype.execute = function (calls, abis, transactionsDetail) {
|
|
143
|
-
var _a;
|
|
227
|
+
var _a, _b;
|
|
144
228
|
if (abis === void 0) { abis = undefined; }
|
|
145
229
|
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
146
230
|
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
-
var transactions, nonce,
|
|
148
|
-
return __generator(this, function (
|
|
149
|
-
switch (
|
|
231
|
+
var transactions, nonce, _c, _d, maxFee, _e, version, chainId, signerDetails, signature, calldata;
|
|
232
|
+
return __generator(this, function (_f) {
|
|
233
|
+
switch (_f.label) {
|
|
150
234
|
case 0:
|
|
151
235
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
152
|
-
|
|
236
|
+
_c = number_1.toBN;
|
|
153
237
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
154
|
-
|
|
238
|
+
_d = _a;
|
|
155
239
|
return [3 /*break*/, 3];
|
|
156
240
|
case 1: return [4 /*yield*/, this.getNonce()];
|
|
157
241
|
case 2:
|
|
158
|
-
|
|
159
|
-
|
|
242
|
+
_d = (_f.sent());
|
|
243
|
+
_f.label = 3;
|
|
160
244
|
case 3:
|
|
161
|
-
nonce =
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
maxFee = transactionsDetail.maxFee;
|
|
245
|
+
nonce = _c.apply(void 0, [_d]);
|
|
246
|
+
if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0)) return [3 /*break*/, 4];
|
|
247
|
+
_e = _b;
|
|
165
248
|
return [3 /*break*/, 6];
|
|
166
|
-
case 4: return [4 /*yield*/, this.
|
|
249
|
+
case 4: return [4 /*yield*/, this.getSuggestedMaxFee({ type: 'INVOKE', payload: calls }, transactionsDetail)];
|
|
167
250
|
case 5:
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
_d.label = 6;
|
|
251
|
+
_e = (_f.sent());
|
|
252
|
+
_f.label = 6;
|
|
171
253
|
case 6:
|
|
254
|
+
maxFee = _e;
|
|
172
255
|
version = (0, number_1.toBN)(hash_1.transactionVersion);
|
|
173
256
|
return [4 /*yield*/, this.getChainId()];
|
|
174
257
|
case 7:
|
|
175
|
-
chainId =
|
|
258
|
+
chainId = _f.sent();
|
|
176
259
|
signerDetails = {
|
|
177
260
|
walletAddress: this.address,
|
|
178
261
|
nonce: nonce,
|
|
@@ -182,7 +265,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
182
265
|
};
|
|
183
266
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
184
267
|
case 8:
|
|
185
|
-
signature =
|
|
268
|
+
signature = _f.sent();
|
|
186
269
|
calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
|
|
187
270
|
return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, calldata: calldata, signature: signature }, {
|
|
188
271
|
nonce: nonce,
|
|
@@ -193,13 +276,115 @@ var Account = /** @class */ (function (_super) {
|
|
|
193
276
|
});
|
|
194
277
|
});
|
|
195
278
|
};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
279
|
+
Account.prototype.declare = function (_a, transactionsDetail) {
|
|
280
|
+
var _b, _c;
|
|
281
|
+
var classHash = _a.classHash, contract = _a.contract;
|
|
282
|
+
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
283
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
284
|
+
var nonce, _d, _e, maxFee, _f, version, chainId, signature, contractDefinition;
|
|
285
|
+
return __generator(this, function (_g) {
|
|
286
|
+
switch (_g.label) {
|
|
287
|
+
case 0:
|
|
288
|
+
_d = number_1.toBN;
|
|
289
|
+
if (!((_b = transactionsDetail.nonce) !== null && _b !== void 0)) return [3 /*break*/, 1];
|
|
290
|
+
_e = _b;
|
|
291
|
+
return [3 /*break*/, 3];
|
|
292
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
293
|
+
case 2:
|
|
294
|
+
_e = (_g.sent());
|
|
295
|
+
_g.label = 3;
|
|
296
|
+
case 3:
|
|
297
|
+
nonce = _d.apply(void 0, [_e]);
|
|
298
|
+
if (!((_c = transactionsDetail.maxFee) !== null && _c !== void 0)) return [3 /*break*/, 4];
|
|
299
|
+
_f = _c;
|
|
300
|
+
return [3 /*break*/, 6];
|
|
301
|
+
case 4: return [4 /*yield*/, this.getSuggestedMaxFee({ type: 'DECLARE', payload: { classHash: classHash, contract: contract } }, transactionsDetail)];
|
|
302
|
+
case 5:
|
|
303
|
+
_f = (_g.sent());
|
|
304
|
+
_g.label = 6;
|
|
305
|
+
case 6:
|
|
306
|
+
maxFee = _f;
|
|
307
|
+
version = (0, number_1.toBN)(hash_1.transactionVersion);
|
|
308
|
+
return [4 /*yield*/, this.getChainId()];
|
|
309
|
+
case 7:
|
|
310
|
+
chainId = _g.sent();
|
|
311
|
+
return [4 /*yield*/, this.signer.signDeclareTransaction({
|
|
312
|
+
classHash: classHash,
|
|
313
|
+
senderAddress: this.address,
|
|
314
|
+
chainId: chainId,
|
|
315
|
+
maxFee: maxFee,
|
|
316
|
+
version: version,
|
|
317
|
+
nonce: nonce,
|
|
318
|
+
})];
|
|
319
|
+
case 8:
|
|
320
|
+
signature = _g.sent();
|
|
321
|
+
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
322
|
+
return [2 /*return*/, this.declareContract({ contractDefinition: contractDefinition, senderAddress: this.address, signature: signature }, {
|
|
323
|
+
nonce: nonce,
|
|
324
|
+
maxFee: maxFee,
|
|
325
|
+
version: version,
|
|
326
|
+
})];
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
Account.prototype.deployAccount = function (_a, transactionsDetail) {
|
|
332
|
+
var _b, _c;
|
|
333
|
+
var classHash = _a.classHash, _d = _a.constructorCalldata, constructorCalldata = _d === void 0 ? [] : _d, _e = _a.addressSalt, addressSalt = _e === void 0 ? 0 : _e, providedContractAddress = _a.contractAddress;
|
|
334
|
+
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
335
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
336
|
+
var nonce, _f, _g, version, chainId, contractAddress, maxFee, _h, signature;
|
|
337
|
+
return __generator(this, function (_j) {
|
|
338
|
+
switch (_j.label) {
|
|
339
|
+
case 0:
|
|
340
|
+
_f = number_1.toBN;
|
|
341
|
+
if (!((_b = transactionsDetail.nonce) !== null && _b !== void 0)) return [3 /*break*/, 1];
|
|
342
|
+
_g = _b;
|
|
343
|
+
return [3 /*break*/, 3];
|
|
344
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
345
|
+
case 2:
|
|
346
|
+
_g = (_j.sent());
|
|
347
|
+
_j.label = 3;
|
|
348
|
+
case 3:
|
|
349
|
+
nonce = _f.apply(void 0, [_g]);
|
|
350
|
+
version = (0, number_1.toBN)(hash_1.transactionVersion);
|
|
351
|
+
return [4 /*yield*/, this.getChainId()];
|
|
352
|
+
case 4:
|
|
353
|
+
chainId = _j.sent();
|
|
354
|
+
contractAddress = providedContractAddress !== null && providedContractAddress !== void 0 ? providedContractAddress : (0, hash_1.calculateContractAddressFromHash)(addressSalt, classHash, constructorCalldata, 0);
|
|
355
|
+
if (!((_c = transactionsDetail.maxFee) !== null && _c !== void 0)) return [3 /*break*/, 5];
|
|
356
|
+
_h = _c;
|
|
357
|
+
return [3 /*break*/, 7];
|
|
358
|
+
case 5: return [4 /*yield*/, this.getSuggestedMaxFee({
|
|
359
|
+
type: 'DEPLOY_ACCOUNT',
|
|
360
|
+
payload: { classHash: classHash, constructorCalldata: constructorCalldata, addressSalt: addressSalt, contractAddress: contractAddress },
|
|
361
|
+
}, transactionsDetail)];
|
|
362
|
+
case 6:
|
|
363
|
+
_h = (_j.sent());
|
|
364
|
+
_j.label = 7;
|
|
365
|
+
case 7:
|
|
366
|
+
maxFee = _h;
|
|
367
|
+
return [4 /*yield*/, this.signer.signDeployAccountTransaction({
|
|
368
|
+
classHash: classHash,
|
|
369
|
+
constructorCalldata: constructorCalldata,
|
|
370
|
+
contractAddress: contractAddress,
|
|
371
|
+
addressSalt: addressSalt,
|
|
372
|
+
chainId: chainId,
|
|
373
|
+
maxFee: maxFee,
|
|
374
|
+
version: version,
|
|
375
|
+
nonce: nonce,
|
|
376
|
+
})];
|
|
377
|
+
case 8:
|
|
378
|
+
signature = _j.sent();
|
|
379
|
+
return [2 /*return*/, this.deployAccountContract({ classHash: classHash, addressSalt: addressSalt, constructorCalldata: constructorCalldata, signature: signature }, {
|
|
380
|
+
nonce: nonce,
|
|
381
|
+
maxFee: maxFee,
|
|
382
|
+
version: version,
|
|
383
|
+
})];
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
};
|
|
203
388
|
Account.prototype.signMessage = function (typedData) {
|
|
204
389
|
return __awaiter(this, void 0, void 0, function () {
|
|
205
390
|
return __generator(this, function (_a) {
|
|
@@ -207,13 +392,6 @@ var Account = /** @class */ (function (_super) {
|
|
|
207
392
|
});
|
|
208
393
|
});
|
|
209
394
|
};
|
|
210
|
-
/**
|
|
211
|
-
* Hash a JSON object with pederson hash and return the hash
|
|
212
|
-
*
|
|
213
|
-
* @param json - JSON object to be hashed
|
|
214
|
-
* @returns the hash of the JSON object
|
|
215
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
216
|
-
*/
|
|
217
395
|
Account.prototype.hashMessage = function (typedData) {
|
|
218
396
|
return __awaiter(this, void 0, void 0, function () {
|
|
219
397
|
return __generator(this, function (_a) {
|
|
@@ -221,15 +399,6 @@ var Account = /** @class */ (function (_super) {
|
|
|
221
399
|
});
|
|
222
400
|
});
|
|
223
401
|
};
|
|
224
|
-
/**
|
|
225
|
-
* Verify a signature of a given hash
|
|
226
|
-
* @warning This method is not recommended, use verifyMessage instead
|
|
227
|
-
*
|
|
228
|
-
* @param hash - JSON object to be verified
|
|
229
|
-
* @param signature - signature of the JSON object
|
|
230
|
-
* @returns true if the signature is valid, false otherwise
|
|
231
|
-
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
232
|
-
*/
|
|
233
402
|
Account.prototype.verifyMessageHash = function (hash, signature) {
|
|
234
403
|
return __awaiter(this, void 0, void 0, function () {
|
|
235
404
|
var _a;
|
|
@@ -256,14 +425,6 @@ var Account = /** @class */ (function (_super) {
|
|
|
256
425
|
});
|
|
257
426
|
});
|
|
258
427
|
};
|
|
259
|
-
/**
|
|
260
|
-
* Verify a signature of a JSON object
|
|
261
|
-
*
|
|
262
|
-
* @param hash - hash to be verified
|
|
263
|
-
* @param signature - signature of the hash
|
|
264
|
-
* @returns true if the signature is valid, false otherwise
|
|
265
|
-
* @throws {Error} if the signature is not a valid signature
|
|
266
|
-
*/
|
|
267
428
|
Account.prototype.verifyMessage = function (typedData, signature) {
|
|
268
429
|
return __awaiter(this, void 0, void 0, function () {
|
|
269
430
|
var hash;
|
|
@@ -277,6 +438,39 @@ var Account = /** @class */ (function (_super) {
|
|
|
277
438
|
});
|
|
278
439
|
});
|
|
279
440
|
};
|
|
441
|
+
Account.prototype.getSuggestedMaxFee = function (estimateFeeAction, details) {
|
|
442
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
443
|
+
var feeEstimate, _a;
|
|
444
|
+
return __generator(this, function (_b) {
|
|
445
|
+
switch (_b.label) {
|
|
446
|
+
case 0:
|
|
447
|
+
_a = estimateFeeAction.type;
|
|
448
|
+
switch (_a) {
|
|
449
|
+
case 'INVOKE': return [3 /*break*/, 1];
|
|
450
|
+
case 'DECLARE': return [3 /*break*/, 3];
|
|
451
|
+
case 'DEPLOY_ACCOUNT': return [3 /*break*/, 5];
|
|
452
|
+
}
|
|
453
|
+
return [3 /*break*/, 7];
|
|
454
|
+
case 1: return [4 /*yield*/, this.estimateInvokeFee(estimateFeeAction.payload, details)];
|
|
455
|
+
case 2:
|
|
456
|
+
feeEstimate = _b.sent();
|
|
457
|
+
return [3 /*break*/, 8];
|
|
458
|
+
case 3: return [4 /*yield*/, this.estimateDeclareFee(estimateFeeAction.payload, details)];
|
|
459
|
+
case 4:
|
|
460
|
+
feeEstimate = _b.sent();
|
|
461
|
+
return [3 /*break*/, 8];
|
|
462
|
+
case 5: return [4 /*yield*/, this.estimateAccountDeployFee(estimateFeeAction.payload, details)];
|
|
463
|
+
case 6:
|
|
464
|
+
feeEstimate = _b.sent();
|
|
465
|
+
return [3 /*break*/, 8];
|
|
466
|
+
case 7:
|
|
467
|
+
feeEstimate = { suggestedMaxFee: constants_1.ZERO, overall_fee: constants_1.ZERO };
|
|
468
|
+
return [3 /*break*/, 8];
|
|
469
|
+
case 8: return [2 /*return*/, feeEstimate.suggestedMaxFee.toString()];
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
};
|
|
280
474
|
return Account;
|
|
281
475
|
}(default_1.Provider));
|
|
282
476
|
exports.Account = Account;
|
package/account/interface.d.ts
CHANGED
|
@@ -1,24 +1,56 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
2
|
import { BlockIdentifier } from '../provider/utils';
|
|
3
3
|
import { SignerInterface } from '../signer';
|
|
4
|
-
import { Abi, Call, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
|
|
4
|
+
import { Abi, Call, DeclareContractResponse, DeployContractResponse, EstimateFeeAction, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
|
|
5
|
+
import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
|
|
5
6
|
import { BigNumberish } from '../utils/number';
|
|
6
7
|
import { TypedData } from '../utils/typedData/types';
|
|
7
8
|
export declare abstract class AccountInterface extends ProviderInterface {
|
|
8
9
|
abstract address: string;
|
|
9
10
|
abstract signer: SignerInterface;
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* @deprecated Use estimateInvokeFee or estimateDeclareFee instead
|
|
13
|
+
* Estimate Fee for executing an INVOKE transaction on starknet
|
|
12
14
|
*
|
|
13
|
-
* @param
|
|
15
|
+
* @param calls the invocation object containing:
|
|
14
16
|
* - contractAddress - the address of the contract
|
|
15
17
|
* - entrypoint - the entrypoint of the contract
|
|
16
18
|
* - calldata - (defaults to []) the calldata
|
|
17
|
-
* - signature - (defaults to []) the signature
|
|
18
19
|
*
|
|
19
|
-
* @returns response from
|
|
20
|
+
* @returns response from estimate_fee
|
|
21
|
+
*/
|
|
22
|
+
abstract estimateFee(calls: AllowArray<Call>, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Estimate Fee for executing an INVOKE transaction on starknet
|
|
25
|
+
*
|
|
26
|
+
* @param calls the invocation object containing:
|
|
27
|
+
* - contractAddress - the address of the contract
|
|
28
|
+
* - entrypoint - the entrypoint of the contract
|
|
29
|
+
* - calldata - (defaults to []) the calldata
|
|
30
|
+
*
|
|
31
|
+
* @returns response from estimate_fee
|
|
32
|
+
*/
|
|
33
|
+
abstract estimateInvokeFee(calls: AllowArray<Call>, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
|
|
34
|
+
/**
|
|
35
|
+
* Estimate Fee for executing a DECLARE transaction on starknet
|
|
36
|
+
*
|
|
37
|
+
* @param contractPayload the payload object containing:
|
|
38
|
+
* - contract - the compiled contract to be declared
|
|
39
|
+
* - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
|
|
40
|
+
*
|
|
41
|
+
* @returns response from estimate_fee
|
|
20
42
|
*/
|
|
21
|
-
abstract
|
|
43
|
+
abstract estimateDeclareFee(contractPayload: DeclareContractPayload, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Estimate Fee for executing a DEPLOY_ACCOUNT transaction on starknet
|
|
46
|
+
*
|
|
47
|
+
* @param contractPayload the payload object containing:
|
|
48
|
+
* - contract - the compiled contract to be declared
|
|
49
|
+
* - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
|
|
50
|
+
*
|
|
51
|
+
* @returns response from estimate_fee
|
|
52
|
+
*/
|
|
53
|
+
abstract estimateAccountDeployFee(contractPayload: DeployAccountContractPayload, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
|
|
22
54
|
/**
|
|
23
55
|
* Invoke execute function in account contract
|
|
24
56
|
*
|
|
@@ -31,7 +63,34 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
31
63
|
*
|
|
32
64
|
* @returns response from addTransaction
|
|
33
65
|
*/
|
|
34
|
-
abstract execute(transactions: Call
|
|
66
|
+
abstract execute(transactions: AllowArray<Call>, abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Declares a given compiled contract (json) to starknet
|
|
69
|
+
* @param contractPayload transaction payload to be deployed containing:
|
|
70
|
+
- contract: compiled contract code
|
|
71
|
+
- classHash: computed class hash of compiled contract
|
|
72
|
+
- signature
|
|
73
|
+
* @param transactionsDetail Invocation Details containing:
|
|
74
|
+
- optional nonce
|
|
75
|
+
- optional version
|
|
76
|
+
- optional maxFee
|
|
77
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
78
|
+
*/
|
|
79
|
+
abstract declare(contractPayload: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Deploy the account on Starknet
|
|
82
|
+
* @param contractPayload transaction payload to be deployed containing:
|
|
83
|
+
* - classHash: computed class hash of compiled contract
|
|
84
|
+
* - constructor calldata
|
|
85
|
+
* - address salt
|
|
86
|
+
- signature
|
|
87
|
+
* @param transactionsDetail Invocation Details containing:
|
|
88
|
+
- optional nonce
|
|
89
|
+
- optional version
|
|
90
|
+
- optional maxFee
|
|
91
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
92
|
+
*/
|
|
93
|
+
abstract deployAccount(contractPayload: DeployAccountContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeployContractResponse>;
|
|
35
94
|
/**
|
|
36
95
|
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
37
96
|
* This adds a message prefix so it cant be interchanged with transactions
|
|
@@ -69,5 +128,17 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
69
128
|
* @throws {Error} if the signature is not a valid signature
|
|
70
129
|
*/
|
|
71
130
|
abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the nonce of the account with respect to a specific block
|
|
133
|
+
* @param {BlockIdentifier} blockIdentifier - optional blockIdentifier. Defaults to 'pending'
|
|
134
|
+
* @returns nonce of the account
|
|
135
|
+
*/
|
|
72
136
|
abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
137
|
+
/**
|
|
138
|
+
* Gets Suggested Max Fee based on the transaction type
|
|
139
|
+
* @param {EstimateFeeAction} estimateFeeAction
|
|
140
|
+
* @param {EstimateFeeDetails} details
|
|
141
|
+
* @returns suggestedMaxFee
|
|
142
|
+
*/
|
|
143
|
+
abstract getSuggestedMaxFee(estimateFeeAction: EstimateFeeAction, details: EstimateFeeDetails): Promise<BigNumberish>;
|
|
73
144
|
}
|
package/constants.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare enum StarknetChainId {
|
|
|
12
12
|
export declare enum TransactionHashPrefix {
|
|
13
13
|
DECLARE = "0x6465636c617265",
|
|
14
14
|
DEPLOY = "0x6465706c6f79",
|
|
15
|
+
DEPLOY_ACCOUNT = "0x6465706c6f795f6163636f756e74",
|
|
15
16
|
INVOKE = "0x696e766f6b65",
|
|
16
17
|
L1_HANDLER = "0x6c315f68616e646c6572"
|
|
17
18
|
}
|
package/constants.js
CHANGED
|
@@ -18,6 +18,7 @@ var TransactionHashPrefix;
|
|
|
18
18
|
(function (TransactionHashPrefix) {
|
|
19
19
|
TransactionHashPrefix["DECLARE"] = "0x6465636c617265";
|
|
20
20
|
TransactionHashPrefix["DEPLOY"] = "0x6465706c6f79";
|
|
21
|
+
TransactionHashPrefix["DEPLOY_ACCOUNT"] = "0x6465706c6f795f6163636f756e74";
|
|
21
22
|
TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
|
|
22
23
|
TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
|
|
23
24
|
})(TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {}));
|
package/contract/default.js
CHANGED
|
@@ -181,7 +181,7 @@ var Contract = /** @class */ (function () {
|
|
|
181
181
|
function Contract(abi, address, providerOrAccount) {
|
|
182
182
|
if (providerOrAccount === void 0) { providerOrAccount = provider_1.defaultProvider; }
|
|
183
183
|
var _this = this;
|
|
184
|
-
this.address = address.toLowerCase();
|
|
184
|
+
this.address = address && address.toLowerCase();
|
|
185
185
|
this.providerOrAccount = providerOrAccount;
|
|
186
186
|
this.abi = abi;
|
|
187
187
|
this.structs = abi
|
|
@@ -566,7 +566,7 @@ var Contract = /** @class */ (function () {
|
|
|
566
566
|
if (args === void 0) { args = []; }
|
|
567
567
|
if (options === void 0) { options = {}; }
|
|
568
568
|
// ensure contract is connected
|
|
569
|
-
(0, minimalistic_assert_1.default)(this.address !== null, 'contract
|
|
569
|
+
(0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
|
|
570
570
|
// validate method and args
|
|
571
571
|
this.validateMethodAndArgs('INVOKE', method, args);
|
|
572
572
|
var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
@@ -609,7 +609,7 @@ var Contract = /** @class */ (function () {
|
|
|
609
609
|
var _this = this;
|
|
610
610
|
return __generator(this, function (_d) {
|
|
611
611
|
// ensure contract is connected
|
|
612
|
-
(0, minimalistic_assert_1.default)(this.address !== null, 'contract
|
|
612
|
+
(0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
|
|
613
613
|
// validate method and args
|
|
614
614
|
this.validateMethodAndArgs('CALL', method, args);
|
|
615
615
|
inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
@@ -631,12 +631,12 @@ var Contract = /** @class */ (function () {
|
|
|
631
631
|
var _a;
|
|
632
632
|
return __generator(this, function (_b) {
|
|
633
633
|
// ensure contract is connected
|
|
634
|
-
(0, minimalistic_assert_1.default)(this.address !== null, 'contract
|
|
634
|
+
(0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
|
|
635
635
|
// validate method and args
|
|
636
636
|
this.validateMethodAndArgs('INVOKE', method, args);
|
|
637
637
|
invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
|
|
638
|
-
if ('
|
|
639
|
-
return [2 /*return*/, this.providerOrAccount.
|
|
638
|
+
if ('estimateInvokeFee' in this.providerOrAccount) {
|
|
639
|
+
return [2 /*return*/, this.providerOrAccount.estimateInvokeFee(invocation)];
|
|
640
640
|
}
|
|
641
641
|
throw Error('Contract must be connected to the account contract to estimate');
|
|
642
642
|
});
|
|
@@ -2,8 +2,9 @@ import { ProviderInterface, ProviderOptions } from '../provider';
|
|
|
2
2
|
import { Provider } from '../provider/default';
|
|
3
3
|
import { BlockIdentifier } from '../provider/utils';
|
|
4
4
|
import { SignerInterface } from '../signer';
|
|
5
|
-
import { Abi, Call, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
|
|
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
8
|
import { BigNumberish } from '../utils/number';
|
|
8
9
|
import { TypedData } from '../utils/typedData';
|
|
9
10
|
import { AccountInterface } from './interface';
|
|
@@ -12,51 +13,16 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
12
13
|
address: string;
|
|
13
14
|
constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
14
15
|
getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
15
|
-
estimateFee(calls: Call
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @param abis - one or more abis which can be used to display the calls
|
|
23
|
-
* @param transactionsDetail - optional transaction details
|
|
24
|
-
* @returns a confirmation of invoking a function on the starknet contract
|
|
25
|
-
*/
|
|
26
|
-
execute(calls: Call | Call[], abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
27
|
-
/**
|
|
28
|
-
* Sign an JSON object with the starknet private key and return the signature
|
|
29
|
-
*
|
|
30
|
-
* @param json - JSON object to be signed
|
|
31
|
-
* @returns the signature of the JSON object
|
|
32
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
33
|
-
*/
|
|
16
|
+
estimateFee(calls: AllowArray<Call>, estimateFeeDetails?: EstimateFeeDetails | undefined): Promise<EstimateFee>;
|
|
17
|
+
estimateInvokeFee(calls: AllowArray<Call>, { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
18
|
+
estimateDeclareFee({ classHash, contract }: DeclareContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
19
|
+
estimateAccountDeployFee({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
20
|
+
execute(calls: AllowArray<Call>, abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
21
|
+
declare({ classHash, contract }: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
|
|
22
|
+
deployAccount({ classHash, constructorCalldata, addressSalt, contractAddress: providedContractAddress, }: DeployAccountContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeployContractResponse>;
|
|
34
23
|
signMessage(typedData: TypedData): Promise<Signature>;
|
|
35
|
-
/**
|
|
36
|
-
* Hash a JSON object with pederson hash and return the hash
|
|
37
|
-
*
|
|
38
|
-
* @param json - JSON object to be hashed
|
|
39
|
-
* @returns the hash of the JSON object
|
|
40
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
41
|
-
*/
|
|
42
24
|
hashMessage(typedData: TypedData): Promise<string>;
|
|
43
|
-
/**
|
|
44
|
-
* Verify a signature of a given hash
|
|
45
|
-
* @warning This method is not recommended, use verifyMessage instead
|
|
46
|
-
*
|
|
47
|
-
* @param hash - JSON object to be verified
|
|
48
|
-
* @param signature - signature of the JSON object
|
|
49
|
-
* @returns true if the signature is valid, false otherwise
|
|
50
|
-
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
51
|
-
*/
|
|
52
25
|
verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
53
|
-
/**
|
|
54
|
-
* Verify a signature of a JSON object
|
|
55
|
-
*
|
|
56
|
-
* @param hash - hash to be verified
|
|
57
|
-
* @param signature - signature of the hash
|
|
58
|
-
* @returns true if the signature is valid, false otherwise
|
|
59
|
-
* @throws {Error} if the signature is not a valid signature
|
|
60
|
-
*/
|
|
61
26
|
verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
|
|
27
|
+
getSuggestedMaxFee(estimateFeeAction: EstimateFeeAction, details: EstimateFeeDetails): Promise<string>;
|
|
62
28
|
}
|