starknet 3.12.3 → 3.14.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/.github/workflows/pr.yml +3 -0
- package/.github/workflows/release.yml +4 -0
- package/CHANGELOG.md +42 -0
- package/__mocks__/Account.json +25468 -0
- package/__tests__/account.test.ts +102 -65
- package/__tests__/contract.test.ts +23 -65
- package/__tests__/fixtures.ts +21 -1
- package/__tests__/provider.test.ts +31 -2
- package/account/default.d.ts +2 -9
- package/account/default.js +1 -0
- package/account/index.js +10 -6
- package/account/interface.d.ts +5 -3
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/contract/default.d.ts +1 -1
- package/contract/default.js +20 -21
- package/contract/index.js +10 -6
- package/dist/account/default.d.ts +2 -6
- package/dist/account/default.js +2 -0
- package/dist/account/index.js +5 -1
- package/dist/account/interface.d.ts +3 -3
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/contract/default.d.ts +1 -1
- package/dist/contract/default.js +18 -18
- package/dist/contract/index.js +5 -1
- package/dist/index.js +5 -1
- package/dist/provider/default.d.ts +11 -4
- package/dist/provider/default.js +29 -8
- package/dist/provider/index.js +5 -1
- package/dist/provider/interface.d.ts +9 -1
- package/dist/provider/utils.js +5 -5
- package/dist/signer/index.js +5 -1
- package/dist/types/account.d.ts +6 -0
- package/dist/types/api.d.ts +10 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +6 -1
- package/dist/types/lib.d.ts +4 -1
- package/dist/utils/ellipticCurve.js +1 -1
- package/dist/utils/encode.js +1 -1
- package/dist/utils/hash.js +1 -1
- package/dist/utils/number.js +8 -4
- package/dist/utils/shortString.js +2 -2
- package/dist/utils/typedData/index.js +8 -4
- package/index.js +10 -6
- package/package.json +30 -28
- package/provider/default.d.ts +11 -3
- package/provider/default.js +31 -12
- package/provider/index.js +10 -6
- package/provider/interface.d.ts +9 -1
- package/provider/utils.js +5 -5
- package/signer/index.js +10 -6
- package/src/account/default.ts +3 -6
- package/src/account/interface.ts +5 -3
- package/src/constants.ts +1 -0
- package/src/provider/default.ts +33 -6
- package/src/provider/interface.ts +9 -1
- package/src/types/account.ts +7 -0
- package/src/types/api.ts +11 -2
- package/src/types/index.ts +1 -0
- package/src/types/lib.ts +5 -1
- package/types/account.d.ts +6 -0
- package/types/api.d.ts +13 -2
- package/types/index.d.ts +1 -0
- package/types/index.js +11 -6
- package/types/lib.d.ts +4 -1
- package/utils/ellipticCurve.js +1 -1
- package/utils/encode.js +1 -1
- package/utils/hash.js +1 -1
- package/utils/number.js +13 -9
- package/utils/shortString.js +2 -2
- package/utils/typedData/index.js +15 -13
- package/www/docs/API/provider.md +20 -3
- package/www/guides/account.md +21 -7
- package/www/guides/erc20.md +15 -27
- package/__tests__/accountContract.test.ts +0 -110
package/contract/default.js
CHANGED
|
@@ -287,10 +287,10 @@ var Contract = /** @class */ (function () {
|
|
|
287
287
|
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
288
288
|
*/
|
|
289
289
|
function Contract(abi, address, providerOrAccount) {
|
|
290
|
-
var _this = this;
|
|
291
290
|
if (providerOrAccount === void 0) {
|
|
292
291
|
providerOrAccount = provider_1.defaultProvider;
|
|
293
292
|
}
|
|
293
|
+
var _this = this;
|
|
294
294
|
this.address = address;
|
|
295
295
|
this.providerOrAccount = providerOrAccount;
|
|
296
296
|
this.abi = abi;
|
|
@@ -430,7 +430,7 @@ var Contract = /** @class */ (function () {
|
|
|
430
430
|
});
|
|
431
431
|
(0, minimalistic_assert_1.default)(
|
|
432
432
|
invokeableFunctionNames.includes(method),
|
|
433
|
-
(type === 'INVOKE' ? 'invokeable' : 'viewable'
|
|
433
|
+
''.concat(type === 'INVOKE' ? 'invokeable' : 'viewable', ' method not found in abi')
|
|
434
434
|
);
|
|
435
435
|
// ensure args match abi type
|
|
436
436
|
var methodAbi = this.abi.find(function (abi) {
|
|
@@ -446,7 +446,7 @@ var Contract = /** @class */ (function () {
|
|
|
446
446
|
typeof args[argPosition] === 'string' ||
|
|
447
447
|
typeof args[argPosition] === 'number' ||
|
|
448
448
|
args[argPosition] instanceof bn_js_1.default,
|
|
449
|
-
'arg '
|
|
449
|
+
'arg '.concat(input.name, ' should be a felt (string, number, BigNumber)')
|
|
450
450
|
);
|
|
451
451
|
argPosition += 1;
|
|
452
452
|
} else if (input.type in _this.structs && typeof args[argPosition] === 'object') {
|
|
@@ -454,36 +454,36 @@ var Contract = /** @class */ (function () {
|
|
|
454
454
|
var structMembersLength = _this.calculateStructMembers(input.type);
|
|
455
455
|
(0, minimalistic_assert_1.default)(
|
|
456
456
|
args[argPosition].length === structMembersLength,
|
|
457
|
-
'arg should be of length '
|
|
457
|
+
'arg should be of length '.concat(structMembersLength)
|
|
458
458
|
);
|
|
459
459
|
} else {
|
|
460
460
|
_this.structs[input.type].members.forEach(function (_a) {
|
|
461
461
|
var name = _a.name;
|
|
462
462
|
(0,
|
|
463
|
-
minimalistic_assert_1.default)(Object.keys(args[argPosition]).includes(name), 'arg should have a property '
|
|
463
|
+
minimalistic_assert_1.default)(Object.keys(args[argPosition]).includes(name), 'arg should have a property '.concat(name));
|
|
464
464
|
});
|
|
465
465
|
}
|
|
466
466
|
argPosition += 1;
|
|
467
467
|
} else {
|
|
468
468
|
(0, minimalistic_assert_1.default)(
|
|
469
469
|
Array.isArray(args[argPosition]),
|
|
470
|
-
'arg '
|
|
470
|
+
'arg '.concat(input.name, ' should be an Array')
|
|
471
471
|
);
|
|
472
472
|
if (input.type === 'felt*') {
|
|
473
473
|
args[argPosition].forEach(function (felt) {
|
|
474
474
|
(0,
|
|
475
|
-
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '
|
|
475
|
+
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '.concat(input.name, ' should be an array of string, number or BigNumber'));
|
|
476
476
|
});
|
|
477
477
|
argPosition += 1;
|
|
478
478
|
} else if (/\(felt/.test(input.type)) {
|
|
479
479
|
var tupleLength = input.type.split(',').length;
|
|
480
480
|
(0, minimalistic_assert_1.default)(
|
|
481
481
|
args[argPosition].length === tupleLength,
|
|
482
|
-
'arg '
|
|
482
|
+
'arg '.concat(input.name, ' should have ').concat(tupleLength, ' elements in tuple')
|
|
483
483
|
);
|
|
484
484
|
args[argPosition].forEach(function (felt) {
|
|
485
485
|
(0,
|
|
486
|
-
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '
|
|
486
|
+
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '.concat(input.name, ' should be an array of string, number or BigNumber'));
|
|
487
487
|
});
|
|
488
488
|
argPosition += 1;
|
|
489
489
|
} else {
|
|
@@ -495,12 +495,12 @@ var Contract = /** @class */ (function () {
|
|
|
495
495
|
var structMembersLength = _this.calculateStructMembers(arrayType_1);
|
|
496
496
|
(0, minimalistic_assert_1.default)(
|
|
497
497
|
struct.length === structMembersLength,
|
|
498
|
-
'arg should be of length '
|
|
498
|
+
'arg should be of length '.concat(structMembersLength)
|
|
499
499
|
);
|
|
500
500
|
} else {
|
|
501
501
|
(0, minimalistic_assert_1.default)(
|
|
502
502
|
Object.keys(struct).includes(name),
|
|
503
|
-
'arg '
|
|
503
|
+
'arg '.concat(input.name, ' should be an array of ').concat(arrayType_1)
|
|
504
504
|
);
|
|
505
505
|
}
|
|
506
506
|
});
|
|
@@ -616,7 +616,7 @@ var Contract = /** @class */ (function () {
|
|
|
616
616
|
return acc;
|
|
617
617
|
}, parsedCalldata);
|
|
618
618
|
}
|
|
619
|
-
throw Error('Expected '
|
|
619
|
+
throw Error('Expected '.concat(name, ' to be array'));
|
|
620
620
|
case type in this.structs:
|
|
621
621
|
return this.parseCalldataValue(value, type);
|
|
622
622
|
case /\(felt/.test(type):
|
|
@@ -625,7 +625,7 @@ var Contract = /** @class */ (function () {
|
|
|
625
625
|
return (0, number_1.toFelt)(el);
|
|
626
626
|
});
|
|
627
627
|
}
|
|
628
|
-
throw Error('Expected '
|
|
628
|
+
throw Error('Expected '.concat(name, ' to be array'));
|
|
629
629
|
default:
|
|
630
630
|
return (0, number_1.toFelt)(value);
|
|
631
631
|
}
|
|
@@ -673,8 +673,8 @@ var Contract = /** @class */ (function () {
|
|
|
673
673
|
return acc;
|
|
674
674
|
}, []);
|
|
675
675
|
case /\*/.test(type):
|
|
676
|
-
if (parsedResult && parsedResult[name
|
|
677
|
-
var arrLen = parsedResult[name
|
|
676
|
+
if (parsedResult && parsedResult[''.concat(name, '_len')]) {
|
|
677
|
+
var arrLen = parsedResult[''.concat(name, '_len')];
|
|
678
678
|
while (parsedDataArr.length < arrLen) {
|
|
679
679
|
parsedDataArr.push(
|
|
680
680
|
this.parseResponseStruct(responseIterator, output.type.replace('*', ''))
|
|
@@ -703,8 +703,8 @@ var Contract = /** @class */ (function () {
|
|
|
703
703
|
var responseIterator = response.flat()[Symbol.iterator]();
|
|
704
704
|
var resultObject = outputs.flat().reduce(function (acc, output) {
|
|
705
705
|
acc[output.name] = _this.parseResponseField(responseIterator, output, acc);
|
|
706
|
-
if (acc[output.name] && acc[output.name
|
|
707
|
-
delete acc[output.name
|
|
706
|
+
if (acc[output.name] && acc[''.concat(output.name, '_len')]) {
|
|
707
|
+
delete acc[''.concat(output.name, '_len')];
|
|
708
708
|
}
|
|
709
709
|
return acc;
|
|
710
710
|
}, {});
|
|
@@ -742,10 +742,9 @@ var Contract = /** @class */ (function () {
|
|
|
742
742
|
}, 0);
|
|
743
743
|
if (args.length !== inputsLength) {
|
|
744
744
|
throw Error(
|
|
745
|
-
'Invalid number of arguments, expected '
|
|
746
|
-
inputsLength
|
|
747
|
-
|
|
748
|
-
args.length
|
|
745
|
+
'Invalid number of arguments, expected '
|
|
746
|
+
.concat(inputsLength, ' arguments, but got ')
|
|
747
|
+
.concat(args.length)
|
|
749
748
|
);
|
|
750
749
|
}
|
|
751
750
|
// compile calldata
|
package/contract/index.js
CHANGED
|
@@ -4,12 +4,16 @@ var __createBinding =
|
|
|
4
4
|
(Object.create
|
|
5
5
|
? function (o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
13
17
|
}
|
|
14
18
|
: function (o, m, k, k2) {
|
|
15
19
|
if (k2 === undefined) k2 = k;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Provider, ProviderInterface } from '../provider';
|
|
2
|
-
import { BlockIdentifier } from '../provider/utils';
|
|
3
2
|
import { SignerInterface } from '../signer';
|
|
4
3
|
import { Abi, AddTransactionResponse, Call, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
5
|
-
import { EstimateFee } from '../types/account';
|
|
4
|
+
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
6
5
|
import { BigNumberish } from '../utils/number';
|
|
7
6
|
import { TypedData } from '../utils/typedData';
|
|
8
7
|
import { AccountInterface } from './interface';
|
|
@@ -11,10 +10,7 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
11
10
|
signer: SignerInterface;
|
|
12
11
|
constructor(provider: ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
13
12
|
getNonce(): Promise<string>;
|
|
14
|
-
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier
|
|
15
|
-
nonce?: BigNumberish;
|
|
16
|
-
blockIdentifier?: BlockIdentifier;
|
|
17
|
-
}): Promise<EstimateFee>;
|
|
13
|
+
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
18
14
|
/**
|
|
19
15
|
* Invoke execute function in account contract
|
|
20
16
|
*
|
package/dist/account/default.js
CHANGED
|
@@ -267,6 +267,8 @@ var Account = /** @class */ (function (_super) {
|
|
|
267
267
|
case 0:
|
|
268
268
|
if (transaction.type === 'DEPLOY')
|
|
269
269
|
throw new Error('No DEPLOYS');
|
|
270
|
+
if (transaction.type === 'DECLARE')
|
|
271
|
+
throw new Error('No DECLARES');
|
|
270
272
|
(0, minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
|
|
271
273
|
if (!transaction.nonce) return [3 /*break*/, 1];
|
|
272
274
|
nonceBn = (0, number_1.toBN)(transaction.nonce);
|
package/dist/account/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
2
|
import { SignerInterface } from '../signer';
|
|
3
|
-
import { Abi, AddTransactionResponse, Call, DeployContractPayload,
|
|
4
|
-
import { EstimateFee } from '../types/account';
|
|
3
|
+
import { Abi, AddTransactionResponse, Call, DeployContractPayload, InvocationsDetails, Signature } from '../types';
|
|
4
|
+
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
5
5
|
import { BigNumberish } from '../utils/number';
|
|
6
6
|
import { TypedData } from '../utils/typedData/types';
|
|
7
7
|
export declare abstract class AccountInterface extends ProviderInterface {
|
|
@@ -29,7 +29,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
29
29
|
*
|
|
30
30
|
* @returns response from addTransaction
|
|
31
31
|
*/
|
|
32
|
-
abstract estimateFee(
|
|
32
|
+
abstract estimateFee(calls: Call | Call[], estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
33
33
|
/**
|
|
34
34
|
* Invoke execute function in account contract
|
|
35
35
|
*
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -16,6 +16,7 @@ var StarknetChainId;
|
|
|
16
16
|
})(StarknetChainId = exports.StarknetChainId || (exports.StarknetChainId = {}));
|
|
17
17
|
var TransactionHashPrefix;
|
|
18
18
|
(function (TransactionHashPrefix) {
|
|
19
|
+
TransactionHashPrefix["DECLARE"] = "0x6465636c617265";
|
|
19
20
|
TransactionHashPrefix["DEPLOY"] = "0x6465706c6f79";
|
|
20
21
|
TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
|
|
21
22
|
TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
|
|
@@ -119,6 +119,6 @@ export declare class Contract implements ContractInterface {
|
|
|
119
119
|
call(method: string, args?: Array<any>, { blockIdentifier, }?: {
|
|
120
120
|
blockIdentifier?: BlockIdentifier;
|
|
121
121
|
}): Promise<Result>;
|
|
122
|
-
estimate(method: string, args?: Array<any>): Promise<import("../types
|
|
122
|
+
estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFee>;
|
|
123
123
|
populate(method: string, args?: Array<any>): Invocation;
|
|
124
124
|
}
|
package/dist/contract/default.js
CHANGED
|
@@ -179,8 +179,8 @@ var Contract = /** @class */ (function () {
|
|
|
179
179
|
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
180
180
|
*/
|
|
181
181
|
function Contract(abi, address, providerOrAccount) {
|
|
182
|
-
var _this = this;
|
|
183
182
|
if (providerOrAccount === void 0) { providerOrAccount = provider_1.defaultProvider; }
|
|
183
|
+
var _this = this;
|
|
184
184
|
this.address = address;
|
|
185
185
|
this.providerOrAccount = providerOrAccount;
|
|
186
186
|
this.abi = abi;
|
|
@@ -309,7 +309,7 @@ var Contract = /** @class */ (function () {
|
|
|
309
309
|
return type === 'INVOKE' ? !isView : isView;
|
|
310
310
|
})
|
|
311
311
|
.map(function (abi) { return abi.name; });
|
|
312
|
-
(0, minimalistic_assert_1.default)(invokeableFunctionNames.includes(method), (type === 'INVOKE' ? 'invokeable' : 'viewable'
|
|
312
|
+
(0, minimalistic_assert_1.default)(invokeableFunctionNames.includes(method), "".concat(type === 'INVOKE' ? 'invokeable' : 'viewable', " method not found in abi"));
|
|
313
313
|
// ensure args match abi type
|
|
314
314
|
var methodAbi = this.abi.find(function (abi) { return abi.name === method && abi.type === 'function'; });
|
|
315
315
|
var argPosition = 0;
|
|
@@ -320,35 +320,35 @@ var Contract = /** @class */ (function () {
|
|
|
320
320
|
if (input.type === 'felt') {
|
|
321
321
|
(0, minimalistic_assert_1.default)(typeof args[argPosition] === 'string' ||
|
|
322
322
|
typeof args[argPosition] === 'number' ||
|
|
323
|
-
args[argPosition] instanceof bn_js_1.default, "arg "
|
|
323
|
+
args[argPosition] instanceof bn_js_1.default, "arg ".concat(input.name, " should be a felt (string, number, BigNumber)"));
|
|
324
324
|
argPosition += 1;
|
|
325
325
|
}
|
|
326
326
|
else if (input.type in _this.structs && typeof args[argPosition] === 'object') {
|
|
327
327
|
if (Array.isArray(args[argPosition])) {
|
|
328
328
|
var structMembersLength = _this.calculateStructMembers(input.type);
|
|
329
|
-
(0, minimalistic_assert_1.default)(args[argPosition].length === structMembersLength, "arg should be of length "
|
|
329
|
+
(0, minimalistic_assert_1.default)(args[argPosition].length === structMembersLength, "arg should be of length ".concat(structMembersLength));
|
|
330
330
|
}
|
|
331
331
|
else {
|
|
332
332
|
_this.structs[input.type].members.forEach(function (_a) {
|
|
333
333
|
var name = _a.name;
|
|
334
|
-
(0, minimalistic_assert_1.default)(Object.keys(args[argPosition]).includes(name), "arg should have a property "
|
|
334
|
+
(0, minimalistic_assert_1.default)(Object.keys(args[argPosition]).includes(name), "arg should have a property ".concat(name));
|
|
335
335
|
});
|
|
336
336
|
}
|
|
337
337
|
argPosition += 1;
|
|
338
338
|
}
|
|
339
339
|
else {
|
|
340
|
-
(0, minimalistic_assert_1.default)(Array.isArray(args[argPosition]), "arg "
|
|
340
|
+
(0, minimalistic_assert_1.default)(Array.isArray(args[argPosition]), "arg ".concat(input.name, " should be an Array"));
|
|
341
341
|
if (input.type === 'felt*') {
|
|
342
342
|
args[argPosition].forEach(function (felt) {
|
|
343
|
-
(0, minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, "arg "
|
|
343
|
+
(0, minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, "arg ".concat(input.name, " should be an array of string, number or BigNumber"));
|
|
344
344
|
});
|
|
345
345
|
argPosition += 1;
|
|
346
346
|
}
|
|
347
347
|
else if (/\(felt/.test(input.type)) {
|
|
348
348
|
var tupleLength = input.type.split(',').length;
|
|
349
|
-
(0, minimalistic_assert_1.default)(args[argPosition].length === tupleLength, "arg "
|
|
349
|
+
(0, minimalistic_assert_1.default)(args[argPosition].length === tupleLength, "arg ".concat(input.name, " should have ").concat(tupleLength, " elements in tuple"));
|
|
350
350
|
args[argPosition].forEach(function (felt) {
|
|
351
|
-
(0, minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, "arg "
|
|
351
|
+
(0, minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, "arg ".concat(input.name, " should be an array of string, number or BigNumber"));
|
|
352
352
|
});
|
|
353
353
|
argPosition += 1;
|
|
354
354
|
}
|
|
@@ -359,10 +359,10 @@ var Contract = /** @class */ (function () {
|
|
|
359
359
|
var name = _a.name;
|
|
360
360
|
if (Array.isArray(struct)) {
|
|
361
361
|
var structMembersLength = _this.calculateStructMembers(arrayType_1);
|
|
362
|
-
(0, minimalistic_assert_1.default)(struct.length === structMembersLength, "arg should be of length "
|
|
362
|
+
(0, minimalistic_assert_1.default)(struct.length === structMembersLength, "arg should be of length ".concat(structMembersLength));
|
|
363
363
|
}
|
|
364
364
|
else {
|
|
365
|
-
(0, minimalistic_assert_1.default)(Object.keys(struct).includes(name), "arg "
|
|
365
|
+
(0, minimalistic_assert_1.default)(Object.keys(struct).includes(name), "arg ".concat(input.name, " should be an array of ").concat(arrayType_1));
|
|
366
366
|
}
|
|
367
367
|
});
|
|
368
368
|
});
|
|
@@ -469,14 +469,14 @@ var Contract = /** @class */ (function () {
|
|
|
469
469
|
return acc;
|
|
470
470
|
}, parsedCalldata);
|
|
471
471
|
}
|
|
472
|
-
throw Error("Expected "
|
|
472
|
+
throw Error("Expected ".concat(name, " to be array"));
|
|
473
473
|
case type in this.structs:
|
|
474
474
|
return this.parseCalldataValue(value, type);
|
|
475
475
|
case /\(felt/.test(type):
|
|
476
476
|
if (Array.isArray(value)) {
|
|
477
477
|
return value.map(function (el) { return (0, number_1.toFelt)(el); });
|
|
478
478
|
}
|
|
479
|
-
throw Error("Expected "
|
|
479
|
+
throw Error("Expected ".concat(name, " to be array"));
|
|
480
480
|
default:
|
|
481
481
|
return (0, number_1.toFelt)(value);
|
|
482
482
|
}
|
|
@@ -524,8 +524,8 @@ var Contract = /** @class */ (function () {
|
|
|
524
524
|
return acc;
|
|
525
525
|
}, []);
|
|
526
526
|
case /\*/.test(type):
|
|
527
|
-
if (parsedResult && parsedResult[name
|
|
528
|
-
var arrLen = parsedResult[name
|
|
527
|
+
if (parsedResult && parsedResult["".concat(name, "_len")]) {
|
|
528
|
+
var arrLen = parsedResult["".concat(name, "_len")];
|
|
529
529
|
while (parsedDataArr.length < arrLen) {
|
|
530
530
|
parsedDataArr.push(this.parseResponseStruct(responseIterator, output.type.replace('*', '')));
|
|
531
531
|
}
|
|
@@ -550,8 +550,8 @@ var Contract = /** @class */ (function () {
|
|
|
550
550
|
var responseIterator = response.flat()[Symbol.iterator]();
|
|
551
551
|
var resultObject = outputs.flat().reduce(function (acc, output) {
|
|
552
552
|
acc[output.name] = _this.parseResponseField(responseIterator, output, acc);
|
|
553
|
-
if (acc[output.name] && acc[output.name
|
|
554
|
-
delete acc[output.name
|
|
553
|
+
if (acc[output.name] && acc["".concat(output.name, "_len")]) {
|
|
554
|
+
delete acc["".concat(output.name, "_len")];
|
|
555
555
|
}
|
|
556
556
|
return acc;
|
|
557
557
|
}, {});
|
|
@@ -577,7 +577,7 @@ var Contract = /** @class */ (function () {
|
|
|
577
577
|
return acc;
|
|
578
578
|
}, 0);
|
|
579
579
|
if (args.length !== inputsLength) {
|
|
580
|
-
throw Error("Invalid number of arguments, expected "
|
|
580
|
+
throw Error("Invalid number of arguments, expected ".concat(inputsLength, " arguments, but got ").concat(args.length));
|
|
581
581
|
}
|
|
582
582
|
// compile calldata
|
|
583
583
|
var calldata = this.compileCalldata(args, inputs);
|
package/dist/contract/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceiptResponse } from '../types';
|
|
2
|
+
import { Abi, AddTransactionResponse, Call, CallContractResponse, DeclareContractPayload, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceiptResponse } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { ProviderInterface } from './interface';
|
|
5
5
|
import { BlockIdentifier } from './utils';
|
|
@@ -74,7 +74,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
74
74
|
* @param blockNumber
|
|
75
75
|
* @returns the value of the storage variable
|
|
76
76
|
*/
|
|
77
|
-
getStorageAt(contractAddress: string, key:
|
|
77
|
+
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<object>;
|
|
78
78
|
/**
|
|
79
79
|
* Gets the status of a transaction.
|
|
80
80
|
*
|
|
@@ -85,9 +85,9 @@ export declare class Provider implements ProviderInterface {
|
|
|
85
85
|
*/
|
|
86
86
|
getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
|
|
87
87
|
/**
|
|
88
|
-
* Gets the transaction receipt from a tx hash
|
|
88
|
+
* Gets the transaction receipt from a tx hash.
|
|
89
89
|
*
|
|
90
|
-
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/
|
|
90
|
+
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
|
|
91
91
|
*
|
|
92
92
|
* @param txHash
|
|
93
93
|
* @returns the transaction receipt object
|
|
@@ -110,6 +110,13 @@ export declare class Provider implements ProviderInterface {
|
|
|
110
110
|
* @returns the transaction trace
|
|
111
111
|
*/
|
|
112
112
|
getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
|
|
113
|
+
/**
|
|
114
|
+
* Declare a given compiled contract (json) on starknet
|
|
115
|
+
*
|
|
116
|
+
* @param contract - a json object containing the compiled contract
|
|
117
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
118
|
+
*/
|
|
119
|
+
declareContract(payload: DeclareContractPayload): Promise<AddTransactionResponse>;
|
|
113
120
|
/**
|
|
114
121
|
* Deploys a given compiled contract (json) to starknet
|
|
115
122
|
*
|
package/dist/provider/default.js
CHANGED
|
@@ -77,7 +77,9 @@ var stark_1 = require("../utils/stark");
|
|
|
77
77
|
var interface_1 = require("./interface");
|
|
78
78
|
var utils_1 = require("./utils");
|
|
79
79
|
function wait(delay) {
|
|
80
|
-
return new Promise(function (res) {
|
|
80
|
+
return new Promise(function (res) {
|
|
81
|
+
setTimeout(res, delay);
|
|
82
|
+
});
|
|
81
83
|
}
|
|
82
84
|
function isEmptyQueryObject(obj) {
|
|
83
85
|
return (obj === undefined ||
|
|
@@ -127,7 +129,7 @@ var Provider = /** @class */ (function () {
|
|
|
127
129
|
}
|
|
128
130
|
catch (_a) {
|
|
129
131
|
// eslint-disable-next-line no-console
|
|
130
|
-
console.error("Could not parse baseUrl: "
|
|
132
|
+
console.error("Could not parse baseUrl: ".concat(baseUrl));
|
|
131
133
|
}
|
|
132
134
|
return constants_1.StarknetChainId.TESTNET;
|
|
133
135
|
};
|
|
@@ -147,12 +149,12 @@ var Provider = /** @class */ (function () {
|
|
|
147
149
|
.map(function (_a) {
|
|
148
150
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
149
151
|
if (key === 'blockIdentifier') {
|
|
150
|
-
return ""
|
|
152
|
+
return "".concat((0, utils_1.getFormattedBlockIdentifier)(value));
|
|
151
153
|
}
|
|
152
|
-
return key
|
|
154
|
+
return "".concat(key, "=").concat(value);
|
|
153
155
|
})
|
|
154
156
|
.join('&');
|
|
155
|
-
return "?"
|
|
157
|
+
return "?".concat(queryString);
|
|
156
158
|
};
|
|
157
159
|
Provider.prototype.getHeaders = function (method) {
|
|
158
160
|
if (method === 'POST') {
|
|
@@ -319,9 +321,9 @@ var Provider = /** @class */ (function () {
|
|
|
319
321
|
});
|
|
320
322
|
};
|
|
321
323
|
/**
|
|
322
|
-
* Gets the transaction receipt from a tx hash
|
|
324
|
+
* Gets the transaction receipt from a tx hash.
|
|
323
325
|
*
|
|
324
|
-
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/
|
|
326
|
+
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
|
|
325
327
|
*
|
|
326
328
|
* @param txHash
|
|
327
329
|
* @returns the transaction receipt object
|
|
@@ -368,6 +370,25 @@ var Provider = /** @class */ (function () {
|
|
|
368
370
|
});
|
|
369
371
|
});
|
|
370
372
|
};
|
|
373
|
+
/**
|
|
374
|
+
* Declare a given compiled contract (json) on starknet
|
|
375
|
+
*
|
|
376
|
+
* @param contract - a json object containing the compiled contract
|
|
377
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
378
|
+
*/
|
|
379
|
+
Provider.prototype.declareContract = function (payload) {
|
|
380
|
+
var parsedContract = typeof payload.contract === 'string'
|
|
381
|
+
? (0, json_1.parse)(payload.contract)
|
|
382
|
+
: payload.contract;
|
|
383
|
+
var contractDefinition = __assign(__assign({}, parsedContract), { program: (0, stark_1.compressProgram)(parsedContract.program) });
|
|
384
|
+
return this.fetchEndpoint('add_transaction', undefined, {
|
|
385
|
+
type: 'DECLARE',
|
|
386
|
+
contract_class: contractDefinition,
|
|
387
|
+
nonce: (0, number_1.toHex)(constants_1.ZERO),
|
|
388
|
+
signature: [],
|
|
389
|
+
sender_address: (0, number_1.toHex)(constants_1.ONE),
|
|
390
|
+
});
|
|
391
|
+
};
|
|
371
392
|
/**
|
|
372
393
|
* Deploys a given compiled contract (json) to starknet
|
|
373
394
|
*
|
|
@@ -432,7 +453,7 @@ var Provider = /** @class */ (function () {
|
|
|
432
453
|
}
|
|
433
454
|
else if (errorStates.includes(res.tx_status)) {
|
|
434
455
|
message = res.tx_failure_reason
|
|
435
|
-
? res.tx_status
|
|
456
|
+
? "".concat(res.tx_status, ": ").concat(res.tx_failure_reason.code, "\n").concat(res.tx_failure_reason.error_message)
|
|
436
457
|
: res.tx_status;
|
|
437
458
|
error = new Error(message);
|
|
438
459
|
error.response = res;
|
package/dist/provider/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -55,7 +55,7 @@ export declare abstract class ProviderInterface {
|
|
|
55
55
|
* @param blockIdentifier - block identifier
|
|
56
56
|
* @returns the value of the storage variable
|
|
57
57
|
*/
|
|
58
|
-
abstract getStorageAt(contractAddress: string, key:
|
|
58
|
+
abstract getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<object>;
|
|
59
59
|
/**
|
|
60
60
|
* Gets the status of a transaction.
|
|
61
61
|
*
|
|
@@ -74,6 +74,14 @@ export declare abstract class ProviderInterface {
|
|
|
74
74
|
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
75
75
|
*/
|
|
76
76
|
abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the transaction receipt from a tx hash.
|
|
79
|
+
*
|
|
80
|
+
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
|
|
81
|
+
*
|
|
82
|
+
* @param txHash
|
|
83
|
+
* @returns the transaction receipt object
|
|
84
|
+
*/
|
|
77
85
|
abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
|
|
78
86
|
/**
|
|
79
87
|
* Deploys a given compiled contract (json) to starknet
|
package/dist/provider/utils.js
CHANGED
|
@@ -23,10 +23,10 @@ exports.formatHash = formatHash;
|
|
|
23
23
|
*/
|
|
24
24
|
function txIdentifier(txHash, txId) {
|
|
25
25
|
if (!txHash) {
|
|
26
|
-
return "transactionId="
|
|
26
|
+
return "transactionId=".concat(JSON.stringify(txId));
|
|
27
27
|
}
|
|
28
28
|
var hashString = formatHash(txHash);
|
|
29
|
-
return "transactionHash="
|
|
29
|
+
return "transactionHash=".concat(hashString);
|
|
30
30
|
}
|
|
31
31
|
exports.txIdentifier = txIdentifier;
|
|
32
32
|
/**
|
|
@@ -52,7 +52,7 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
52
52
|
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
53
53
|
}
|
|
54
54
|
if (typeof blockIdentifier === 'string') {
|
|
55
|
-
throw new Error("Invalid block identifier: "
|
|
55
|
+
throw new Error("Invalid block identifier: ".concat(blockIdentifier));
|
|
56
56
|
}
|
|
57
57
|
return { type: 'BLOCK_HASH', data: blockIdentifier };
|
|
58
58
|
}
|
|
@@ -72,8 +72,8 @@ function getFormattedBlockIdentifier(blockIdentifier) {
|
|
|
72
72
|
return '';
|
|
73
73
|
}
|
|
74
74
|
if (blockIdentifierObject.type === 'BLOCK_NUMBER') {
|
|
75
|
-
return "blockNumber="
|
|
75
|
+
return "blockNumber=".concat(blockIdentifierObject.data);
|
|
76
76
|
}
|
|
77
|
-
return "blockHash="
|
|
77
|
+
return "blockHash=".concat((0, number_1.toHex)((0, number_1.toBN)(blockIdentifierObject.data)));
|
|
78
78
|
}
|
|
79
79
|
exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
|
package/dist/signer/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/types/account.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
|
+
import { BigNumberish } from '../utils/number';
|
|
2
4
|
import { EstimateFeeResponse } from './api';
|
|
3
5
|
export interface EstimateFee extends EstimateFeeResponse {
|
|
4
6
|
suggestedMaxFee: BN;
|
|
5
7
|
}
|
|
8
|
+
export interface EstimateFeeDetails {
|
|
9
|
+
nonce?: BigNumberish;
|
|
10
|
+
blockIdentifier?: BlockIdentifier;
|
|
11
|
+
}
|