starknet 3.7.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +18 -53
- package/__mocks__/ArgentAccount.json +32022 -38726
- package/__tests__/accountContract.test.ts +42 -32
- package/__tests__/contract.test.ts +20 -6
- package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +2 -2
- package/__tests__/utils/__snapshots__/utils.test.ts.snap +2 -2
- package/__tests__/utils/ellipticalCurve.test.ts +26 -8
- package/__tests__/utils/transactionHash.test.ts +17 -0
- package/__tests__/utils/utils.test.ts +10 -0
- package/account/default.d.ts +11 -1
- package/account/default.js +58 -50
- package/constants.d.ts +9 -0
- package/constants.js +13 -0
- package/contract/default.d.ts +12 -2
- package/contract/default.js +27 -20
- package/contract/interface.d.ts +21 -3
- package/dist/account/default.d.ts +5 -1
- package/dist/account/default.js +46 -30
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +12 -1
- package/dist/contract/default.d.ts +6 -3
- package/dist/contract/default.js +23 -20
- package/dist/contract/interface.d.ts +9 -4
- package/dist/provider/default.d.ts +5 -2
- package/dist/provider/default.js +36 -19
- package/dist/provider/interface.d.ts +2 -0
- package/dist/provider/utils.d.ts +1 -2
- package/dist/provider/utils.js +7 -8
- package/dist/signer/default.js +4 -2
- package/dist/signer/ledger.js +4 -2
- package/dist/types/api.d.ts +4 -1
- package/dist/types/lib.d.ts +1 -0
- package/dist/types/signer.d.ts +2 -0
- package/dist/utils/hash.d.ts +5 -3
- package/dist/utils/hash.js +25 -23
- package/dist/utils/stark.d.ts +3 -0
- package/dist/utils/stark.js +8 -1
- package/dist/utils/transaction.d.ts +2 -0
- package/dist/utils/transaction.js +5 -1
- package/dist/utils/typedData/index.d.ts +2 -2
- package/dist/utils/typedData/types.d.ts +3 -3
- package/dist/utils/typedData/utils.d.ts +1 -1
- package/package.json +1 -1
- package/provider/default.d.ts +7 -2
- package/provider/default.js +49 -27
- package/provider/interface.d.ts +2 -0
- package/provider/utils.d.ts +1 -2
- package/provider/utils.js +7 -8
- package/signer/default.js +12 -5
- package/signer/ledger.js +12 -5
- package/src/account/default.ts +47 -18
- package/src/constants.ts +10 -0
- package/src/contract/default.ts +32 -19
- package/src/contract/interface.ts +21 -3
- package/src/provider/default.ts +37 -12
- package/src/provider/interface.ts +3 -0
- package/src/provider/utils.ts +7 -8
- package/src/signer/default.ts +10 -5
- package/src/signer/ledger.ts +10 -5
- package/src/types/api.ts +4 -1
- package/src/types/lib.ts +1 -0
- package/src/types/signer.ts +2 -0
- package/src/utils/hash.ts +70 -26
- package/src/utils/stark.ts +8 -1
- package/src/utils/transaction.ts +7 -0
- package/types/api.d.ts +4 -1
- package/types/lib.d.ts +1 -0
- package/types/signer.d.ts +2 -0
- package/utils/hash.d.ts +25 -7
- package/utils/hash.js +60 -26
- package/utils/stark.d.ts +4 -0
- package/utils/stark.js +13 -1
- package/utils/transaction.d.ts +5 -0
- package/utils/transaction.js +12 -1
- package/utils/typedData/index.d.ts +2 -2
- package/utils/typedData/types.d.ts +3 -3
- package/utils/typedData/utils.d.ts +1 -1
- package/__tests__/constancts.ts +0 -2
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import { StarknetChainId } from '../../src/constants';
|
|
1
2
|
import { ec, getKeyPair, getStarkKey, sign, verify } from '../../src/utils/ellipticCurve';
|
|
2
3
|
import { removeHexPrefix } from '../../src/utils/encode';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
calculcateTransactionHash,
|
|
6
|
+
computeHashOnElements,
|
|
7
|
+
getSelectorFromName,
|
|
8
|
+
pedersen,
|
|
9
|
+
transactionVersion,
|
|
10
|
+
} from '../../src/utils/hash';
|
|
4
11
|
import { toBN, toHex } from '../../src/utils/number';
|
|
12
|
+
import { fromCallsToExecuteCalldataWithNonce } from '../../src/utils/transaction';
|
|
5
13
|
|
|
6
14
|
test('getKeyPair()', () => {
|
|
7
15
|
const privateKey = '0x019800ea6a9a73f94aee6a3d2edf018fc770443e90c7ba121e8303ec6b349279';
|
|
@@ -42,17 +50,27 @@ test('hashMessage()', () => {
|
|
|
42
50
|
];
|
|
43
51
|
const nonce = '3';
|
|
44
52
|
const maxFee = '0';
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
const calldata = fromCallsToExecuteCalldataWithNonce(transactions, nonce);
|
|
54
|
+
|
|
55
|
+
const hashMsg = calculcateTransactionHash(
|
|
56
|
+
account,
|
|
57
|
+
transactionVersion,
|
|
58
|
+
getSelectorFromName('__execute__'),
|
|
59
|
+
calldata,
|
|
60
|
+
maxFee,
|
|
61
|
+
StarknetChainId.TESTNET
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(hashMsg).toMatchInlineSnapshot(
|
|
65
|
+
`"0x4c337c6bf32b2cf2b8ae54064e4b982c214660e8d0423b431a3fde10b9b9c02"`
|
|
48
66
|
);
|
|
49
67
|
const keyPair = getKeyPair(privateKey);
|
|
50
68
|
const [r, s] = sign(keyPair, removeHexPrefix(hashMsg));
|
|
51
|
-
expect(r.toString()).
|
|
52
|
-
|
|
69
|
+
expect(r.toString()).toMatchInlineSnapshot(
|
|
70
|
+
`"1944132633844378384908742523072599391732300777648030785844673145513474741467"`
|
|
53
71
|
);
|
|
54
|
-
expect(s.toString()).
|
|
55
|
-
|
|
72
|
+
expect(s.toString()).toMatchInlineSnapshot(
|
|
73
|
+
`"1067771353159635307522498807851959257107695451405842425488451092336556917559"`
|
|
56
74
|
);
|
|
57
75
|
});
|
|
58
76
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StarknetChainId, TransactionHashPrefix } from '../../src/constants';
|
|
2
|
+
import { calculateTransactionHashCommon } from '../../src/utils/hash';
|
|
3
|
+
|
|
4
|
+
describe('calculateTransactionHashCommon()', () => {
|
|
5
|
+
test('should match most simple python output', () => {
|
|
6
|
+
const result = calculateTransactionHashCommon(
|
|
7
|
+
TransactionHashPrefix.INVOKE,
|
|
8
|
+
'0x0',
|
|
9
|
+
'0x2a',
|
|
10
|
+
'0x64',
|
|
11
|
+
[],
|
|
12
|
+
'0x0',
|
|
13
|
+
StarknetChainId.TESTNET
|
|
14
|
+
);
|
|
15
|
+
expect(result).toBe('0x7d260744de9d8c55e7675a34512d1951a7b262c79e685d26599edd2948de959');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -77,3 +77,13 @@ describe('computeHashOnElements()', () => {
|
|
|
77
77
|
);
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
|
+
describe('estimatedFeeToMaxFee()', () => {
|
|
81
|
+
test('should return maxFee for 0', () => {
|
|
82
|
+
const res = stark.estimatedFeeToMaxFee(0, 0.15).toNumber();
|
|
83
|
+
expect(res).toBe(0);
|
|
84
|
+
});
|
|
85
|
+
test('should return maxFee for 10_000', () => {
|
|
86
|
+
const res = stark.estimatedFeeToMaxFee(10_000, 0.15).toNumber();
|
|
87
|
+
expect(res).toBe(11_500);
|
|
88
|
+
});
|
|
89
|
+
});
|
package/account/default.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
2
3
|
import { SignerInterface } from '../signer';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
@@ -18,7 +19,16 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
18
19
|
private signer;
|
|
19
20
|
constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
20
21
|
getNonce(): Promise<string>;
|
|
21
|
-
estimateFee(
|
|
22
|
+
estimateFee(
|
|
23
|
+
calls: Call | Call[],
|
|
24
|
+
{
|
|
25
|
+
nonce: providedNonce,
|
|
26
|
+
blockIdentifier,
|
|
27
|
+
}?: {
|
|
28
|
+
nonce?: BigNumberish;
|
|
29
|
+
blockIdentifier?: BlockIdentifier;
|
|
30
|
+
}
|
|
31
|
+
): Promise<EstimateFeeResponse>;
|
|
22
32
|
/**
|
|
23
33
|
* Invoke execute function in account contract
|
|
24
34
|
*
|
package/account/default.js
CHANGED
|
@@ -197,11 +197,13 @@ var __importDefault =
|
|
|
197
197
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
198
198
|
exports.Account = void 0;
|
|
199
199
|
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
200
|
+
var constants_1 = require('../constants');
|
|
200
201
|
var provider_1 = require('../provider');
|
|
201
202
|
var signer_1 = require('../signer');
|
|
202
203
|
var ellipticCurve_1 = require('../utils/ellipticCurve');
|
|
203
204
|
var hash_1 = require('../utils/hash');
|
|
204
205
|
var number_1 = require('../utils/number');
|
|
206
|
+
var shortString_1 = require('../utils/shortString');
|
|
205
207
|
var stark_1 = require('../utils/stark');
|
|
206
208
|
var transaction_1 = require('../utils/transaction');
|
|
207
209
|
var typedData_1 = require('../utils/typedData');
|
|
@@ -234,41 +236,52 @@ var Account = /** @class */ (function (_super) {
|
|
|
234
236
|
});
|
|
235
237
|
});
|
|
236
238
|
};
|
|
237
|
-
Account.prototype.estimateFee = function (calls) {
|
|
239
|
+
Account.prototype.estimateFee = function (calls, _a) {
|
|
240
|
+
var _b = _a === void 0 ? {} : _a,
|
|
241
|
+
providedNonce = _b.nonce,
|
|
242
|
+
_c = _b.blockIdentifier,
|
|
243
|
+
blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
238
244
|
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
-
var transactions, nonce, signerDetails, signature, calldata;
|
|
240
|
-
return __generator(this, function (
|
|
241
|
-
switch (
|
|
245
|
+
var transactions, nonce, _d, version, signerDetails, signature, calldata;
|
|
246
|
+
return __generator(this, function (_e) {
|
|
247
|
+
switch (_e.label) {
|
|
242
248
|
case 0:
|
|
243
249
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
244
|
-
return [
|
|
250
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
251
|
+
_d = providedNonce;
|
|
252
|
+
return [3 /*break*/, 3];
|
|
245
253
|
case 1:
|
|
246
|
-
|
|
254
|
+
return [4 /*yield*/, this.getNonce()];
|
|
255
|
+
case 2:
|
|
256
|
+
_d = _e.sent();
|
|
257
|
+
_e.label = 3;
|
|
258
|
+
case 3:
|
|
259
|
+
nonce = _d;
|
|
260
|
+
version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
|
|
247
261
|
signerDetails = {
|
|
248
262
|
walletAddress: this.address,
|
|
249
263
|
nonce: (0, number_1.toBN)(nonce),
|
|
250
|
-
maxFee:
|
|
264
|
+
maxFee: constants_1.ZERO,
|
|
265
|
+
version: version,
|
|
266
|
+
chainId: this.chainId,
|
|
251
267
|
};
|
|
252
268
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
253
|
-
case
|
|
254
|
-
signature =
|
|
255
|
-
calldata =
|
|
256
|
-
__spreadArray(
|
|
257
|
-
[],
|
|
258
|
-
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
259
|
-
false
|
|
260
|
-
),
|
|
261
|
-
[signerDetails.nonce.toString()],
|
|
262
|
-
false
|
|
263
|
-
);
|
|
269
|
+
case 4:
|
|
270
|
+
signature = _e.sent();
|
|
271
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
264
272
|
return [
|
|
265
273
|
2 /*return*/,
|
|
266
|
-
this.fetchEndpoint(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
274
|
+
this.fetchEndpoint(
|
|
275
|
+
'estimate_fee',
|
|
276
|
+
{ blockIdentifier: blockIdentifier },
|
|
277
|
+
{
|
|
278
|
+
contract_address: this.address,
|
|
279
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
280
|
+
calldata: calldata,
|
|
281
|
+
version: (0, number_1.toHex)(version),
|
|
282
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
283
|
+
}
|
|
284
|
+
),
|
|
272
285
|
];
|
|
273
286
|
}
|
|
274
287
|
});
|
|
@@ -283,7 +296,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
283
296
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
284
297
|
*/
|
|
285
298
|
Account.prototype.execute = function (calls, abis, transactionsDetail) {
|
|
286
|
-
var _a
|
|
299
|
+
var _a;
|
|
287
300
|
if (abis === void 0) {
|
|
288
301
|
abis = undefined;
|
|
289
302
|
}
|
|
@@ -291,51 +304,46 @@ var Account = /** @class */ (function (_super) {
|
|
|
291
304
|
transactionsDetail = {};
|
|
292
305
|
}
|
|
293
306
|
return __awaiter(this, void 0, void 0, function () {
|
|
294
|
-
var transactions, nonce,
|
|
295
|
-
return __generator(this, function (
|
|
296
|
-
switch (
|
|
307
|
+
var transactions, nonce, _b, _c, maxFee, estimatedFee, signerDetails, signature, calldata;
|
|
308
|
+
return __generator(this, function (_d) {
|
|
309
|
+
switch (_d.label) {
|
|
297
310
|
case 0:
|
|
298
311
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
299
|
-
|
|
312
|
+
_b = number_1.toBN;
|
|
300
313
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0))
|
|
301
314
|
return [3 /*break*/, 1];
|
|
302
|
-
|
|
315
|
+
_c = _a;
|
|
303
316
|
return [3 /*break*/, 3];
|
|
304
317
|
case 1:
|
|
305
318
|
return [4 /*yield*/, this.getNonce()];
|
|
306
319
|
case 2:
|
|
307
|
-
|
|
308
|
-
|
|
320
|
+
_c = _d.sent();
|
|
321
|
+
_d.label = 3;
|
|
309
322
|
case 3:
|
|
310
|
-
nonce =
|
|
311
|
-
|
|
323
|
+
nonce = _b.apply(void 0, [_c]);
|
|
324
|
+
maxFee = '0';
|
|
325
|
+
if (!(transactionsDetail.maxFee || transactionsDetail.maxFee === 0))
|
|
312
326
|
return [3 /*break*/, 4];
|
|
313
|
-
|
|
327
|
+
maxFee = transactionsDetail.maxFee;
|
|
314
328
|
return [3 /*break*/, 6];
|
|
315
329
|
case 4:
|
|
316
|
-
return [4 /*yield*/, this.estimateFee(transactions)];
|
|
330
|
+
return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
317
331
|
case 5:
|
|
318
|
-
|
|
319
|
-
|
|
332
|
+
estimatedFee = _d.sent().amount;
|
|
333
|
+
maxFee = (0, stark_1.estimatedFeeToMaxFee)(estimatedFee).toString();
|
|
334
|
+
_d.label = 6;
|
|
320
335
|
case 6:
|
|
321
|
-
maxFee = _e;
|
|
322
336
|
signerDetails = {
|
|
323
337
|
walletAddress: this.address,
|
|
324
338
|
nonce: nonce,
|
|
325
339
|
maxFee: maxFee,
|
|
340
|
+
version: (0, number_1.toBN)(hash_1.transactionVersion),
|
|
341
|
+
chainId: this.chainId,
|
|
326
342
|
};
|
|
327
343
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
328
344
|
case 7:
|
|
329
|
-
signature =
|
|
330
|
-
calldata =
|
|
331
|
-
__spreadArray(
|
|
332
|
-
[],
|
|
333
|
-
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
334
|
-
false
|
|
335
|
-
),
|
|
336
|
-
[signerDetails.nonce.toString()],
|
|
337
|
-
false
|
|
338
|
-
);
|
|
345
|
+
signature = _d.sent();
|
|
346
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
339
347
|
return [
|
|
340
348
|
2 /*return*/,
|
|
341
349
|
this.fetchEndpoint('add_transaction', undefined, {
|
|
@@ -372,7 +380,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
372
380
|
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
373
381
|
.map(hash_1.computeHashOnElements);
|
|
374
382
|
return (0,
|
|
375
|
-
hash_1.computeHashOnElements)([
|
|
383
|
+
hash_1.computeHashOnElements)([(0, shortString_1.encodeShortString)('StarkNet Transaction'), account, (0, hash_1.computeHashOnElements)(hashArray), nonce, maxFee, hash_1.transactionVersion]);
|
|
376
384
|
}
|
|
377
385
|
var nonceBn,
|
|
378
386
|
result,
|
package/constants.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export declare const ONE: import('bn.js');
|
|
|
5
5
|
export declare const TWO: import('bn.js');
|
|
6
6
|
export declare const MASK_250: import('bn.js');
|
|
7
7
|
export declare const MASK_251: import('bn.js');
|
|
8
|
+
export declare enum StarknetChainId {
|
|
9
|
+
MAINNET = '0x534e5f4d41494e',
|
|
10
|
+
TESTNET = '0x534e5f474f45524c49',
|
|
11
|
+
}
|
|
12
|
+
export declare enum TransactionHashPrefix {
|
|
13
|
+
DEPLOY = '0x6465706c6f79',
|
|
14
|
+
INVOKE = '0x696e766f6b65',
|
|
15
|
+
L1_HANDLER = '0x6c315f68616e646c6572',
|
|
16
|
+
}
|
|
8
17
|
/**
|
|
9
18
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
10
19
|
* Please do not edit until the JSON changes.
|
package/constants.js
CHANGED
|
@@ -8,6 +8,8 @@ exports.CONSTANT_POINTS =
|
|
|
8
8
|
exports.FIELD_SIZE =
|
|
9
9
|
exports.FIELD_GEN =
|
|
10
10
|
exports.FIELD_PRIME =
|
|
11
|
+
exports.TransactionHashPrefix =
|
|
12
|
+
exports.StarknetChainId =
|
|
11
13
|
exports.MASK_251 =
|
|
12
14
|
exports.MASK_250 =
|
|
13
15
|
exports.TWO =
|
|
@@ -28,6 +30,17 @@ exports.ONE = (0, number_1.toBN)(1);
|
|
|
28
30
|
exports.TWO = (0, number_1.toBN)(2);
|
|
29
31
|
exports.MASK_250 = exports.TWO.pow((0, number_1.toBN)(250)).sub(exports.ONE); // 2 ** 250 - 1
|
|
30
32
|
exports.MASK_251 = exports.TWO.pow((0, number_1.toBN)(251));
|
|
33
|
+
var StarknetChainId;
|
|
34
|
+
(function (StarknetChainId) {
|
|
35
|
+
StarknetChainId['MAINNET'] = '0x534e5f4d41494e';
|
|
36
|
+
StarknetChainId['TESTNET'] = '0x534e5f474f45524c49';
|
|
37
|
+
})((StarknetChainId = exports.StarknetChainId || (exports.StarknetChainId = {})));
|
|
38
|
+
var TransactionHashPrefix;
|
|
39
|
+
(function (TransactionHashPrefix) {
|
|
40
|
+
TransactionHashPrefix['DEPLOY'] = '0x6465706c6f79';
|
|
41
|
+
TransactionHashPrefix['INVOKE'] = '0x696e766f6b65';
|
|
42
|
+
TransactionHashPrefix['L1_HANDLER'] = '0x6c315f68616e646c6572';
|
|
43
|
+
})((TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {})));
|
|
31
44
|
/**
|
|
32
45
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
33
46
|
* Please do not edit until the JSON changes.
|
package/contract/default.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
5
6
|
AbiEntry,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
Calldata,
|
|
10
11
|
ContractFunction,
|
|
11
12
|
Invocation,
|
|
13
|
+
Overrides,
|
|
12
14
|
ParsedStruct,
|
|
13
15
|
Result,
|
|
14
16
|
StructAbi,
|
|
@@ -136,8 +138,16 @@ export declare class Contract implements ContractInterface {
|
|
|
136
138
|
* @return - parsed response corresponding to the abi
|
|
137
139
|
*/
|
|
138
140
|
protected parseResponse(method: string, response: string[]): Result;
|
|
139
|
-
invoke(method: string, args?: Array<any
|
|
140
|
-
call(
|
|
141
|
+
invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
142
|
+
call(
|
|
143
|
+
method: string,
|
|
144
|
+
args?: Array<any>,
|
|
145
|
+
{
|
|
146
|
+
blockIdentifier,
|
|
147
|
+
}?: {
|
|
148
|
+
blockIdentifier?: BlockIdentifier;
|
|
149
|
+
}
|
|
150
|
+
): Promise<Result>;
|
|
141
151
|
estimate(method: string, args?: Array<any>): Promise<import('../types').EstimateFeeResponse>;
|
|
142
152
|
populate(method: string, args?: Array<any>): Invocation;
|
|
143
153
|
}
|
package/contract/default.js
CHANGED
|
@@ -224,8 +224,20 @@ function buildInvoke(contract, functionAbi) {
|
|
|
224
224
|
args[_i] = arguments[_i];
|
|
225
225
|
}
|
|
226
226
|
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
var inputs, inputsLength, options;
|
|
227
228
|
return __generator(this, function (_a) {
|
|
228
|
-
|
|
229
|
+
inputs = functionAbi.inputs;
|
|
230
|
+
inputsLength = inputs.reduce(function (acc, input) {
|
|
231
|
+
if (!/_len$/.test(input.name)) {
|
|
232
|
+
return acc + 1;
|
|
233
|
+
}
|
|
234
|
+
return acc;
|
|
235
|
+
}, 0);
|
|
236
|
+
options = {};
|
|
237
|
+
if (inputsLength + 1 === args.length && typeof args[args.length - 1] === 'object') {
|
|
238
|
+
Object.assign(options, args.pop());
|
|
239
|
+
}
|
|
240
|
+
return [2 /*return*/, contract.invoke(functionAbi.name, args, options)];
|
|
229
241
|
});
|
|
230
242
|
});
|
|
231
243
|
};
|
|
@@ -705,10 +717,13 @@ var Contract = /** @class */ (function () {
|
|
|
705
717
|
return acc;
|
|
706
718
|
}, []);
|
|
707
719
|
};
|
|
708
|
-
Contract.prototype.invoke = function (method, args) {
|
|
720
|
+
Contract.prototype.invoke = function (method, args, options) {
|
|
709
721
|
if (args === void 0) {
|
|
710
722
|
args = [];
|
|
711
723
|
}
|
|
724
|
+
if (options === void 0) {
|
|
725
|
+
options = {};
|
|
726
|
+
}
|
|
712
727
|
// ensure contract is connected
|
|
713
728
|
(0, minimalistic_assert_1.default)(
|
|
714
729
|
this.address !== null,
|
|
@@ -725,10 +740,6 @@ var Contract = /** @class */ (function () {
|
|
|
725
740
|
}
|
|
726
741
|
return acc;
|
|
727
742
|
}, 0);
|
|
728
|
-
var overrides = {};
|
|
729
|
-
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
730
|
-
Object.assign(overrides, args.pop());
|
|
731
|
-
}
|
|
732
743
|
if (args.length !== inputsLength) {
|
|
733
744
|
throw Error(
|
|
734
745
|
'Invalid number of arguments, expected ' +
|
|
@@ -746,22 +757,25 @@ var Contract = /** @class */ (function () {
|
|
|
746
757
|
};
|
|
747
758
|
if ('execute' in this.providerOrAccount) {
|
|
748
759
|
return this.providerOrAccount.execute(invocation, undefined, {
|
|
749
|
-
maxFee:
|
|
750
|
-
nonce:
|
|
760
|
+
maxFee: options.maxFee,
|
|
761
|
+
nonce: options.nonce,
|
|
751
762
|
});
|
|
752
763
|
}
|
|
753
764
|
return this.providerOrAccount.invokeFunction(
|
|
754
|
-
__assign(__assign({}, invocation), { signature:
|
|
765
|
+
__assign(__assign({}, invocation), { signature: options.signature || [] })
|
|
755
766
|
);
|
|
756
767
|
};
|
|
757
|
-
Contract.prototype.call = function (method, args) {
|
|
768
|
+
Contract.prototype.call = function (method, args, _a) {
|
|
758
769
|
if (args === void 0) {
|
|
759
770
|
args = [];
|
|
760
771
|
}
|
|
772
|
+
var _b = _a === void 0 ? {} : _a,
|
|
773
|
+
_c = _b.blockIdentifier,
|
|
774
|
+
blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
761
775
|
return __awaiter(this, void 0, void 0, function () {
|
|
762
|
-
var inputs,
|
|
776
|
+
var inputs, calldata;
|
|
763
777
|
var _this = this;
|
|
764
|
-
return __generator(this, function (
|
|
778
|
+
return __generator(this, function (_d) {
|
|
765
779
|
// ensure contract is connected
|
|
766
780
|
(0,
|
|
767
781
|
minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
@@ -770,13 +784,6 @@ var Contract = /** @class */ (function () {
|
|
|
770
784
|
inputs = this.abi.find(function (abi) {
|
|
771
785
|
return abi.name === method;
|
|
772
786
|
}).inputs;
|
|
773
|
-
inputsLength = inputs.length;
|
|
774
|
-
options = {
|
|
775
|
-
blockIdentifier: null,
|
|
776
|
-
};
|
|
777
|
-
if (args.length === inputsLength + 1 && typeof args[args.length - 1] === 'object') {
|
|
778
|
-
Object.assign(options, args.pop());
|
|
779
|
-
}
|
|
780
787
|
calldata = this.compileCalldata(args, inputs);
|
|
781
788
|
return [
|
|
782
789
|
2 /*return*/,
|
|
@@ -787,7 +794,7 @@ var Contract = /** @class */ (function () {
|
|
|
787
794
|
calldata: calldata,
|
|
788
795
|
entrypoint: method,
|
|
789
796
|
},
|
|
790
|
-
|
|
797
|
+
{ blockIdentifier: blockIdentifier }
|
|
791
798
|
)
|
|
792
799
|
.then(function (x) {
|
|
793
800
|
return _this.parseResponse(method, x.result);
|
package/contract/interface.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
5
6
|
AddTransactionResponse,
|
|
6
7
|
AsyncContractFunction,
|
|
7
8
|
ContractFunction,
|
|
8
9
|
Invocation,
|
|
10
|
+
Overrides,
|
|
9
11
|
Result,
|
|
10
12
|
} from '../types';
|
|
11
13
|
export declare abstract class ContractInterface {
|
|
@@ -52,7 +54,13 @@ export declare abstract class ContractInterface {
|
|
|
52
54
|
* @param args Array of the arguments for the call
|
|
53
55
|
* @returns Result of the call as an array with key value pars
|
|
54
56
|
*/
|
|
55
|
-
abstract call(
|
|
57
|
+
abstract call(
|
|
58
|
+
method: string,
|
|
59
|
+
args?: Array<any>,
|
|
60
|
+
options?: {
|
|
61
|
+
blockIdentifier?: BlockIdentifier;
|
|
62
|
+
}
|
|
63
|
+
): Promise<Result>;
|
|
56
64
|
/**
|
|
57
65
|
* Invokes a method on a contract
|
|
58
66
|
*
|
|
@@ -60,14 +68,24 @@ export declare abstract class ContractInterface {
|
|
|
60
68
|
* @param args Array of the arguments for the invoke
|
|
61
69
|
* @returns Add Transaction Response
|
|
62
70
|
*/
|
|
63
|
-
abstract invoke(
|
|
71
|
+
abstract invoke(
|
|
72
|
+
method: string,
|
|
73
|
+
args?: Array<any>,
|
|
74
|
+
options?: Overrides
|
|
75
|
+
): Promise<AddTransactionResponse>;
|
|
64
76
|
/**
|
|
65
77
|
* Calls a method on a contract
|
|
66
78
|
*
|
|
67
79
|
* @param method name of the method
|
|
68
80
|
* @param args Array of the arguments for the call
|
|
69
81
|
*/
|
|
70
|
-
abstract estimate(
|
|
82
|
+
abstract estimate(
|
|
83
|
+
method: string,
|
|
84
|
+
args?: Array<any>,
|
|
85
|
+
options?: {
|
|
86
|
+
blockIdentifier?: BlockIdentifier;
|
|
87
|
+
}
|
|
88
|
+
): Promise<any>;
|
|
71
89
|
/**
|
|
72
90
|
* Calls a method on a contract
|
|
73
91
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
2
3
|
import { SignerInterface } from '../signer';
|
|
3
4
|
import { Abi, AddTransactionResponse, Call, EstimateFeeResponse, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
4
5
|
import { BigNumberish } from '../utils/number';
|
|
@@ -9,7 +10,10 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
9
10
|
private signer;
|
|
10
11
|
constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
11
12
|
getNonce(): Promise<string>;
|
|
12
|
-
estimateFee(calls: Call | Call[]
|
|
13
|
+
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier, }?: {
|
|
14
|
+
nonce?: BigNumberish;
|
|
15
|
+
blockIdentifier?: BlockIdentifier;
|
|
16
|
+
}): Promise<EstimateFeeResponse>;
|
|
13
17
|
/**
|
|
14
18
|
* Invoke execute function in account contract
|
|
15
19
|
*
|