starknet 3.2.0 → 3.5.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/.eslintrc +2 -1
- package/CHANGELOG.md +32 -0
- package/__tests__/account.test.ts +11 -21
- package/__tests__/accountContract.test.ts +15 -27
- package/__tests__/contract.test.ts +156 -59
- package/__tests__/utils/utils.browser.test.ts +1 -3
- package/account/default.d.ts +6 -0
- package/account/default.js +129 -0
- package/contract/contractFactory.d.ts +36 -0
- package/contract/contractFactory.js +218 -0
- package/contract/default.d.ts +143 -0
- package/{contract.js → contract/default.js} +357 -86
- package/contract/index.d.ts +3 -0
- package/contract/index.js +28 -0
- package/contract/interface.d.ts +79 -0
- package/contract/interface.js +8 -0
- package/dist/account/default.d.ts +6 -1
- package/dist/account/default.js +99 -0
- package/dist/contract/contractFactory.d.ts +32 -0
- package/dist/contract/contractFactory.js +102 -0
- package/dist/contract/default.d.ts +121 -0
- package/dist/{contract.js → contract/default.js} +321 -73
- package/dist/contract/index.d.ts +3 -0
- package/dist/contract/index.js +15 -0
- package/dist/contract/interface.d.ts +72 -0
- package/dist/contract/interface.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/provider/default.d.ts +10 -5
- package/dist/provider/default.js +29 -11
- package/dist/provider/interface.d.ts +8 -2
- package/dist/types/api.d.ts +6 -0
- package/dist/types/contract.d.ts +5 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/lib.d.ts +11 -1
- package/dist/utils/transaction.d.ts +1 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/provider/default.d.ts +10 -5
- package/provider/default.js +41 -21
- package/provider/interface.d.ts +8 -2
- package/src/account/default.ts +109 -1
- package/src/contract/contractFactory.ts +78 -0
- package/src/contract/default.ts +622 -0
- package/src/contract/index.ts +3 -0
- package/src/contract/interface.ts +87 -0
- package/src/index.ts +1 -1
- package/src/provider/default.ts +29 -19
- package/src/provider/interface.ts +9 -2
- package/src/types/api.ts +7 -0
- package/src/types/contract.ts +5 -0
- package/src/types/index.ts +1 -0
- package/src/types/lib.ts +12 -1
- package/src/utils/transaction.ts +1 -2
- package/types/api.d.ts +6 -0
- package/types/contract.d.ts +5 -0
- package/types/contract.js +2 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/lib.d.ts +11 -1
- package/utils/transaction.d.ts +1 -2
- package/contract.d.ts +0 -98
- package/dist/contract.d.ts +0 -94
- package/src/contract.ts +0 -357
package/dist/index.js
CHANGED
|
@@ -26,8 +26,8 @@ exports.typedData = exports.shortString = exports.uint256 = exports.ec = exports
|
|
|
26
26
|
/**
|
|
27
27
|
* Main
|
|
28
28
|
*/
|
|
29
|
-
__exportStar(require("./types"), exports);
|
|
30
29
|
__exportStar(require("./contract"), exports);
|
|
30
|
+
__exportStar(require("./types"), exports);
|
|
31
31
|
__exportStar(require("./provider"), exports);
|
|
32
32
|
__exportStar(require("./account"), exports);
|
|
33
33
|
__exportStar(require("./signer"), exports);
|
|
@@ -36,7 +36,9 @@ export declare class Provider implements ProviderInterface {
|
|
|
36
36
|
* @param blockNumber
|
|
37
37
|
* @returns the result of the function on the smart contract.
|
|
38
38
|
*/
|
|
39
|
-
callContract({ contractAddress, entrypoint, calldata }: Call,
|
|
39
|
+
callContract({ contractAddress, entrypoint, calldata }: Call, options?: {
|
|
40
|
+
blockIdentifier: BlockIdentifier;
|
|
41
|
+
}): Promise<CallContractResponse>;
|
|
40
42
|
/**
|
|
41
43
|
* Gets the block information
|
|
42
44
|
*
|
|
@@ -113,13 +115,16 @@ export declare class Provider implements ProviderInterface {
|
|
|
113
115
|
* Invokes a function on starknet
|
|
114
116
|
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
115
117
|
*
|
|
116
|
-
* @param
|
|
117
|
-
* @param
|
|
118
|
-
* @param calldata - (optional, default []) calldata
|
|
119
|
-
* @param signature - (optional) signature to send along
|
|
118
|
+
* @param invocation
|
|
119
|
+
* @param _abi - (optional) signature to send along
|
|
120
120
|
* @returns response from addTransaction
|
|
121
121
|
*/
|
|
122
122
|
invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
|
|
123
|
+
estimateFee(invocation: Invocation): Promise<any>;
|
|
124
|
+
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated use `waitForTransaction` instead
|
|
127
|
+
*/
|
|
123
128
|
waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
124
129
|
}
|
|
125
130
|
export {};
|
package/dist/provider/default.js
CHANGED
|
@@ -117,7 +117,7 @@ var Provider = /** @class */ (function () {
|
|
|
117
117
|
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
|
|
118
118
|
};
|
|
119
119
|
Provider.prototype.getFetchMethod = function (endpoint) {
|
|
120
|
-
var postMethodEndpoints = ['add_transaction', 'call_contract'];
|
|
120
|
+
var postMethodEndpoints = ['add_transaction', 'call_contract', 'estimate_fee'];
|
|
121
121
|
return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
|
|
122
122
|
};
|
|
123
123
|
Provider.prototype.getQueryString = function (query) {
|
|
@@ -219,14 +219,12 @@ var Provider = /** @class */ (function () {
|
|
|
219
219
|
* @param blockNumber
|
|
220
220
|
* @returns the result of the function on the smart contract.
|
|
221
221
|
*/
|
|
222
|
-
Provider.prototype.callContract = function (_a,
|
|
222
|
+
Provider.prototype.callContract = function (_a, options) {
|
|
223
223
|
var contractAddress = _a.contractAddress, entrypoint = _a.entrypoint, _b = _a.calldata, calldata = _b === void 0 ? [] : _b;
|
|
224
|
-
if (
|
|
224
|
+
if (options === void 0) { options = { blockIdentifier: null }; }
|
|
225
225
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
226
|
return __generator(this, function (_c) {
|
|
227
|
-
return [2 /*return*/, this.fetchEndpoint('call_contract', {
|
|
228
|
-
blockIdentifier: blockIdentifier,
|
|
229
|
-
}, {
|
|
227
|
+
return [2 /*return*/, this.fetchEndpoint('call_contract', options, {
|
|
230
228
|
signature: [],
|
|
231
229
|
contract_address: contractAddress,
|
|
232
230
|
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
@@ -371,10 +369,8 @@ var Provider = /** @class */ (function () {
|
|
|
371
369
|
* Invokes a function on starknet
|
|
372
370
|
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
373
371
|
*
|
|
374
|
-
* @param
|
|
375
|
-
* @param
|
|
376
|
-
* @param calldata - (optional, default []) calldata
|
|
377
|
-
* @param signature - (optional) signature to send along
|
|
372
|
+
* @param invocation
|
|
373
|
+
* @param _abi - (optional) signature to send along
|
|
378
374
|
* @returns response from addTransaction
|
|
379
375
|
*/
|
|
380
376
|
Provider.prototype.invokeFunction = function (invocation, _abi) {
|
|
@@ -387,7 +383,18 @@ var Provider = /** @class */ (function () {
|
|
|
387
383
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = invocation.signature) !== null && _b !== void 0 ? _b : []),
|
|
388
384
|
});
|
|
389
385
|
};
|
|
390
|
-
Provider.prototype.
|
|
386
|
+
Provider.prototype.estimateFee = function (invocation) {
|
|
387
|
+
var _a, _b;
|
|
388
|
+
return this.fetchEndpoint('estimate_fee', undefined, {
|
|
389
|
+
// TODO: change the TYPE of the call
|
|
390
|
+
type: 'INVOKE_FUNCTION',
|
|
391
|
+
contract_address: invocation.contractAddress,
|
|
392
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
|
|
393
|
+
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)((_a = invocation.calldata) !== null && _a !== void 0 ? _a : []),
|
|
394
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = invocation.signature) !== null && _b !== void 0 ? _b : []),
|
|
395
|
+
});
|
|
396
|
+
};
|
|
397
|
+
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
391
398
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
392
399
|
return __awaiter(this, void 0, void 0, function () {
|
|
393
400
|
var onchain, res, message, error;
|
|
@@ -426,6 +433,17 @@ var Provider = /** @class */ (function () {
|
|
|
426
433
|
});
|
|
427
434
|
});
|
|
428
435
|
};
|
|
436
|
+
/**
|
|
437
|
+
* @deprecated use `waitForTransaction` instead
|
|
438
|
+
*/
|
|
439
|
+
Provider.prototype.waitForTx = function (txHash, retryInterval) {
|
|
440
|
+
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
441
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
442
|
+
return __generator(this, function (_a) {
|
|
443
|
+
return [2 /*return*/, this.waitForTransaction(txHash, retryInterval)];
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
};
|
|
429
447
|
return Provider;
|
|
430
448
|
}());
|
|
431
449
|
exports.Provider = Provider;
|
|
@@ -21,7 +21,9 @@ export declare abstract class ProviderInterface {
|
|
|
21
21
|
* @param blockIdentifier block identifier
|
|
22
22
|
* @returns the result of the function on the smart contract.
|
|
23
23
|
*/
|
|
24
|
-
abstract callContract(invokeTransaction: Call,
|
|
24
|
+
abstract callContract(invokeTransaction: Call, options: {
|
|
25
|
+
blockIdentifier: BlockIdentifier;
|
|
26
|
+
}): Promise<CallContractResponse>;
|
|
25
27
|
/**
|
|
26
28
|
* Gets the block information
|
|
27
29
|
*
|
|
@@ -97,5 +99,9 @@ export declare abstract class ProviderInterface {
|
|
|
97
99
|
* @returns response from addTransaction
|
|
98
100
|
*/
|
|
99
101
|
abstract invokeFunction(invocation: Invocation): Promise<AddTransactionResponse>;
|
|
100
|
-
abstract
|
|
102
|
+
abstract waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated use `waitForTransaction` instead
|
|
105
|
+
*/
|
|
106
|
+
abstract waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
101
107
|
}
|
package/dist/types/api.d.ts
CHANGED
|
@@ -57,6 +57,11 @@ export declare type Endpoints = {
|
|
|
57
57
|
REQUEST: CallContractTransaction;
|
|
58
58
|
RESPONSE: CallContractResponse;
|
|
59
59
|
};
|
|
60
|
+
estimate_fee: {
|
|
61
|
+
QUERY: never;
|
|
62
|
+
REQUEST: Transaction;
|
|
63
|
+
RESPONSE: EstimateFeeResponse;
|
|
64
|
+
};
|
|
60
65
|
};
|
|
61
66
|
export declare type GetContractAddressesResponse = {
|
|
62
67
|
Starknet: string;
|
|
@@ -143,6 +148,7 @@ export declare type TransactionReceipt = {
|
|
|
143
148
|
l2_to_l1_messages: string[];
|
|
144
149
|
events: string[];
|
|
145
150
|
};
|
|
151
|
+
export declare type EstimateFeeResponse = {};
|
|
146
152
|
export declare type RawArgs = {
|
|
147
153
|
[inputName: string]: string | string[] | {
|
|
148
154
|
type: 'struct';
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
package/dist/types/lib.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export declare type FunctionAbi = {
|
|
|
33
33
|
name: string;
|
|
34
34
|
outputs: AbiEntry[];
|
|
35
35
|
stateMutability?: 'view';
|
|
36
|
-
type: 'function';
|
|
36
|
+
type: 'function' | 'constructor';
|
|
37
37
|
};
|
|
38
38
|
export declare type StructAbi = {
|
|
39
39
|
members: (AbiEntry & {
|
|
@@ -55,3 +55,13 @@ export declare type CompiledContract = {
|
|
|
55
55
|
export declare type CompressedCompiledContract = Omit<CompiledContract, 'program'> & {
|
|
56
56
|
program: CompressedProgram;
|
|
57
57
|
};
|
|
58
|
+
export declare type Struct = {
|
|
59
|
+
type: 'struct';
|
|
60
|
+
[k: string]: BigNumberish;
|
|
61
|
+
};
|
|
62
|
+
export declare type Args = {
|
|
63
|
+
[inputName: string]: BigNumberish | BigNumberish[] | ParsedStruct | ParsedStruct[];
|
|
64
|
+
};
|
|
65
|
+
export declare type ParsedStruct = {
|
|
66
|
+
[key: string]: BigNumberish | ParsedStruct;
|
|
67
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ParsedStruct } from '../
|
|
2
|
-
import { Call } from '../types';
|
|
1
|
+
import { Call, ParsedStruct } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* Transforms a list of Calls, each with their own calldata, into
|
|
5
4
|
* two arrays: one with the entrypoints, and one with the concatenated calldata.
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -58,8 +58,8 @@ exports.typedData =
|
|
|
58
58
|
/**
|
|
59
59
|
* Main
|
|
60
60
|
*/
|
|
61
|
-
__exportStar(require('./types'), exports);
|
|
62
61
|
__exportStar(require('./contract'), exports);
|
|
62
|
+
__exportStar(require('./types'), exports);
|
|
63
63
|
__exportStar(require('./provider'), exports);
|
|
64
64
|
__exportStar(require('./account'), exports);
|
|
65
65
|
__exportStar(require('./signer'), exports);
|
package/package.json
CHANGED
package/provider/default.d.ts
CHANGED
|
@@ -65,7 +65,9 @@ export declare class Provider implements ProviderInterface {
|
|
|
65
65
|
*/
|
|
66
66
|
callContract(
|
|
67
67
|
{ contractAddress, entrypoint, calldata }: Call,
|
|
68
|
-
|
|
68
|
+
options?: {
|
|
69
|
+
blockIdentifier: BlockIdentifier;
|
|
70
|
+
}
|
|
69
71
|
): Promise<CallContractResponse>;
|
|
70
72
|
/**
|
|
71
73
|
* Gets the block information
|
|
@@ -150,13 +152,16 @@ export declare class Provider implements ProviderInterface {
|
|
|
150
152
|
* Invokes a function on starknet
|
|
151
153
|
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
152
154
|
*
|
|
153
|
-
* @param
|
|
154
|
-
* @param
|
|
155
|
-
* @param calldata - (optional, default []) calldata
|
|
156
|
-
* @param signature - (optional) signature to send along
|
|
155
|
+
* @param invocation
|
|
156
|
+
* @param _abi - (optional) signature to send along
|
|
157
157
|
* @returns response from addTransaction
|
|
158
158
|
*/
|
|
159
159
|
invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
|
|
160
|
+
estimateFee(invocation: Invocation): Promise<any>;
|
|
161
|
+
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* @deprecated use `waitForTransaction` instead
|
|
164
|
+
*/
|
|
160
165
|
waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
161
166
|
}
|
|
162
167
|
export {};
|
package/provider/default.js
CHANGED
|
@@ -231,7 +231,7 @@ var Provider = /** @class */ (function () {
|
|
|
231
231
|
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
|
|
232
232
|
};
|
|
233
233
|
Provider.prototype.getFetchMethod = function (endpoint) {
|
|
234
|
-
var postMethodEndpoints = ['add_transaction', 'call_contract'];
|
|
234
|
+
var postMethodEndpoints = ['add_transaction', 'call_contract', 'estimate_fee'];
|
|
235
235
|
return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
|
|
236
236
|
};
|
|
237
237
|
Provider.prototype.getQueryString = function (query) {
|
|
@@ -343,30 +343,24 @@ var Provider = /** @class */ (function () {
|
|
|
343
343
|
* @param blockNumber
|
|
344
344
|
* @returns the result of the function on the smart contract.
|
|
345
345
|
*/
|
|
346
|
-
Provider.prototype.callContract = function (_a,
|
|
346
|
+
Provider.prototype.callContract = function (_a, options) {
|
|
347
347
|
var contractAddress = _a.contractAddress,
|
|
348
348
|
entrypoint = _a.entrypoint,
|
|
349
349
|
_b = _a.calldata,
|
|
350
350
|
calldata = _b === void 0 ? [] : _b;
|
|
351
|
-
if (
|
|
352
|
-
|
|
351
|
+
if (options === void 0) {
|
|
352
|
+
options = { blockIdentifier: null };
|
|
353
353
|
}
|
|
354
354
|
return __awaiter(this, void 0, void 0, function () {
|
|
355
355
|
return __generator(this, function (_c) {
|
|
356
356
|
return [
|
|
357
357
|
2 /*return*/,
|
|
358
|
-
this.fetchEndpoint(
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
signature: [],
|
|
365
|
-
contract_address: contractAddress,
|
|
366
|
-
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
367
|
-
calldata: calldata,
|
|
368
|
-
}
|
|
369
|
-
),
|
|
358
|
+
this.fetchEndpoint('call_contract', options, {
|
|
359
|
+
signature: [],
|
|
360
|
+
contract_address: contractAddress,
|
|
361
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
362
|
+
calldata: calldata,
|
|
363
|
+
}),
|
|
370
364
|
];
|
|
371
365
|
});
|
|
372
366
|
});
|
|
@@ -550,10 +544,8 @@ var Provider = /** @class */ (function () {
|
|
|
550
544
|
* Invokes a function on starknet
|
|
551
545
|
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
552
546
|
*
|
|
553
|
-
* @param
|
|
554
|
-
* @param
|
|
555
|
-
* @param calldata - (optional, default []) calldata
|
|
556
|
-
* @param signature - (optional) signature to send along
|
|
547
|
+
* @param invocation
|
|
548
|
+
* @param _abi - (optional) signature to send along
|
|
557
549
|
* @returns response from addTransaction
|
|
558
550
|
*/
|
|
559
551
|
Provider.prototype.invokeFunction = function (invocation, _abi) {
|
|
@@ -570,7 +562,22 @@ var Provider = /** @class */ (function () {
|
|
|
570
562
|
),
|
|
571
563
|
});
|
|
572
564
|
};
|
|
573
|
-
Provider.prototype.
|
|
565
|
+
Provider.prototype.estimateFee = function (invocation) {
|
|
566
|
+
var _a, _b;
|
|
567
|
+
return this.fetchEndpoint('estimate_fee', undefined, {
|
|
568
|
+
// TODO: change the TYPE of the call
|
|
569
|
+
type: 'INVOKE_FUNCTION',
|
|
570
|
+
contract_address: invocation.contractAddress,
|
|
571
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
|
|
572
|
+
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(
|
|
573
|
+
(_a = invocation.calldata) !== null && _a !== void 0 ? _a : []
|
|
574
|
+
),
|
|
575
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(
|
|
576
|
+
(_b = invocation.signature) !== null && _b !== void 0 ? _b : []
|
|
577
|
+
),
|
|
578
|
+
});
|
|
579
|
+
};
|
|
580
|
+
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
574
581
|
if (retryInterval === void 0) {
|
|
575
582
|
retryInterval = 8000;
|
|
576
583
|
}
|
|
@@ -615,6 +622,19 @@ var Provider = /** @class */ (function () {
|
|
|
615
622
|
});
|
|
616
623
|
});
|
|
617
624
|
};
|
|
625
|
+
/**
|
|
626
|
+
* @deprecated use `waitForTransaction` instead
|
|
627
|
+
*/
|
|
628
|
+
Provider.prototype.waitForTx = function (txHash, retryInterval) {
|
|
629
|
+
if (retryInterval === void 0) {
|
|
630
|
+
retryInterval = 8000;
|
|
631
|
+
}
|
|
632
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
633
|
+
return __generator(this, function (_a) {
|
|
634
|
+
return [2 /*return*/, this.waitForTransaction(txHash, retryInterval)];
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
};
|
|
618
638
|
return Provider;
|
|
619
639
|
})();
|
|
620
640
|
exports.Provider = Provider;
|
package/provider/interface.d.ts
CHANGED
|
@@ -35,7 +35,9 @@ export declare abstract class ProviderInterface {
|
|
|
35
35
|
*/
|
|
36
36
|
abstract callContract(
|
|
37
37
|
invokeTransaction: Call,
|
|
38
|
-
|
|
38
|
+
options: {
|
|
39
|
+
blockIdentifier: BlockIdentifier;
|
|
40
|
+
}
|
|
39
41
|
): Promise<CallContractResponse>;
|
|
40
42
|
/**
|
|
41
43
|
* Gets the block information
|
|
@@ -122,5 +124,9 @@ export declare abstract class ProviderInterface {
|
|
|
122
124
|
* @returns response from addTransaction
|
|
123
125
|
*/
|
|
124
126
|
abstract invokeFunction(invocation: Invocation): Promise<AddTransactionResponse>;
|
|
125
|
-
abstract
|
|
127
|
+
abstract waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated use `waitForTransaction` instead
|
|
130
|
+
*/
|
|
131
|
+
abstract waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
126
132
|
}
|
package/src/account/default.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert';
|
|
2
|
+
|
|
1
3
|
import { Provider } from '../provider';
|
|
2
4
|
import { Signer, SignerInterface } from '../signer';
|
|
3
5
|
import {
|
|
@@ -5,10 +7,18 @@ import {
|
|
|
5
7
|
AddTransactionResponse,
|
|
6
8
|
Call,
|
|
7
9
|
InvocationsDetails,
|
|
10
|
+
InvokeFunctionTransaction,
|
|
8
11
|
KeyPair,
|
|
9
12
|
Signature,
|
|
13
|
+
Transaction,
|
|
10
14
|
} from '../types';
|
|
11
|
-
import {
|
|
15
|
+
import { sign } from '../utils/ellipticCurve';
|
|
16
|
+
import {
|
|
17
|
+
computeHashOnElements,
|
|
18
|
+
getSelectorFromName,
|
|
19
|
+
transactionPrefix,
|
|
20
|
+
transactionVersion,
|
|
21
|
+
} from '../utils/hash';
|
|
12
22
|
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
|
|
13
23
|
import { compileCalldata } from '../utils/stark';
|
|
14
24
|
import { fromCallsToExecuteCalldata } from '../utils/transaction';
|
|
@@ -68,6 +78,104 @@ export class Account extends Provider implements AccountInterface {
|
|
|
68
78
|
});
|
|
69
79
|
}
|
|
70
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
|
|
83
|
+
* @deprecated to remove ASAP
|
|
84
|
+
*/
|
|
85
|
+
public async LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse> {
|
|
86
|
+
if (transaction.type === 'DEPLOY') throw new Error('No DEPLOYS');
|
|
87
|
+
|
|
88
|
+
assert(
|
|
89
|
+
!transaction.signature,
|
|
90
|
+
"Adding signatures to a signer transaction currently isn't supported"
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
let nonceBn;
|
|
94
|
+
if (transaction.nonce) {
|
|
95
|
+
nonceBn = toBN(transaction.nonce);
|
|
96
|
+
} else {
|
|
97
|
+
const { result } = await this.callContract({
|
|
98
|
+
contractAddress: this.address,
|
|
99
|
+
entrypoint: 'get_nonce',
|
|
100
|
+
});
|
|
101
|
+
nonceBn = toBN(result[0]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function hashMulticall(
|
|
105
|
+
account: string,
|
|
106
|
+
transactions: InvokeFunctionTransaction[],
|
|
107
|
+
nonce: string,
|
|
108
|
+
maxFee: string
|
|
109
|
+
) {
|
|
110
|
+
const hashArray = transactions
|
|
111
|
+
.map(({ contract_address, entry_point_selector, calldata }) => [
|
|
112
|
+
contract_address,
|
|
113
|
+
entry_point_selector,
|
|
114
|
+
computeHashOnElements(calldata || []),
|
|
115
|
+
])
|
|
116
|
+
.map(bigNumberishArrayToDecimalStringArray)
|
|
117
|
+
.map(computeHashOnElements);
|
|
118
|
+
|
|
119
|
+
return computeHashOnElements([
|
|
120
|
+
transactionPrefix,
|
|
121
|
+
account,
|
|
122
|
+
computeHashOnElements(hashArray),
|
|
123
|
+
nonce,
|
|
124
|
+
maxFee,
|
|
125
|
+
transactionVersion,
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
const msgHash = hashMulticall(this.address, [transaction], nonceBn.toString(), '0');
|
|
129
|
+
if (!('keyPair' in this.signer)) {
|
|
130
|
+
throw new Error('No keyPair');
|
|
131
|
+
}
|
|
132
|
+
const signature = sign((this.signer as any).keyPair, msgHash);
|
|
133
|
+
|
|
134
|
+
const transformCallsToMulticallArrays = (calls: InvokeFunctionTransaction[]) => {
|
|
135
|
+
const callArray: any[] = [];
|
|
136
|
+
const calldata: BigNumberish[] = [];
|
|
137
|
+
calls.forEach((call) => {
|
|
138
|
+
const data = call.calldata || [];
|
|
139
|
+
callArray.push({
|
|
140
|
+
to: toBN(call.contract_address).toString(10),
|
|
141
|
+
selector: toBN(call.entry_point_selector).toString(10),
|
|
142
|
+
data_offset: calldata.length.toString(),
|
|
143
|
+
data_len: data.length.toString(),
|
|
144
|
+
});
|
|
145
|
+
calldata.push(...data);
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
callArray,
|
|
149
|
+
calldata: bigNumberishArrayToDecimalStringArray(calldata),
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const fromCallsToExecuteCalldata2 = (calls: InvokeFunctionTransaction[]): string[] => {
|
|
154
|
+
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
155
|
+
return [
|
|
156
|
+
callArray.length.toString(),
|
|
157
|
+
...callArray
|
|
158
|
+
.map(
|
|
159
|
+
({ to, selector, data_offset, data_len }) =>
|
|
160
|
+
[to, selector, data_offset, data_len] as string[]
|
|
161
|
+
)
|
|
162
|
+
.flat(),
|
|
163
|
+
calldata.length.toString(),
|
|
164
|
+
...calldata,
|
|
165
|
+
];
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const calldata = [...fromCallsToExecuteCalldata2([transaction]), nonceBn.toString()];
|
|
169
|
+
|
|
170
|
+
return this.fetchEndpoint('add_transaction', undefined, {
|
|
171
|
+
type: 'INVOKE_FUNCTION',
|
|
172
|
+
contract_address: this.address,
|
|
173
|
+
entry_point_selector: getSelectorFromName('__execute__'),
|
|
174
|
+
calldata,
|
|
175
|
+
signature: bigNumberishArrayToDecimalStringArray(signature),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
71
179
|
/**
|
|
72
180
|
* Sign an JSON object with the starknet private key and return the signature
|
|
73
181
|
*
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert';
|
|
2
|
+
|
|
3
|
+
import { Account } from '../account';
|
|
4
|
+
import { Provider, defaultProvider } from '../provider';
|
|
5
|
+
import { Abi, CompiledContract, RawCalldata } from '../types';
|
|
6
|
+
import { BigNumberish } from '../utils/number';
|
|
7
|
+
import { Contract } from './default';
|
|
8
|
+
|
|
9
|
+
export class ContractFactory {
|
|
10
|
+
abi: Abi;
|
|
11
|
+
|
|
12
|
+
compiledContract: CompiledContract;
|
|
13
|
+
|
|
14
|
+
providerOrAccount: Provider | Account;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
compiledContract: CompiledContract,
|
|
18
|
+
providerOrAccount: Provider | Account = defaultProvider,
|
|
19
|
+
abi: Abi = compiledContract.abi // abi can be different from the deployed contract ie for proxy contracts
|
|
20
|
+
) {
|
|
21
|
+
this.abi = abi;
|
|
22
|
+
this.compiledContract = compiledContract;
|
|
23
|
+
this.providerOrAccount = providerOrAccount;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Deploys contract and returns new instance of the Contract
|
|
28
|
+
*
|
|
29
|
+
* @param constructorCalldata - Constructor Calldata
|
|
30
|
+
* @param addressSalt (optional) - Address Salt for deployment
|
|
31
|
+
* @returns deployed Contract
|
|
32
|
+
*/
|
|
33
|
+
public async deploy(
|
|
34
|
+
constructorCalldata?: RawCalldata,
|
|
35
|
+
addressSalt?: BigNumberish
|
|
36
|
+
): Promise<Contract> {
|
|
37
|
+
const { address, code, transaction_hash } = await this.providerOrAccount.deployContract({
|
|
38
|
+
contract: this.compiledContract,
|
|
39
|
+
constructorCalldata,
|
|
40
|
+
addressSalt,
|
|
41
|
+
});
|
|
42
|
+
assert(
|
|
43
|
+
code === 'TRANSACTION_RECEIVED' && Boolean(address),
|
|
44
|
+
'Deployment of the contract failed'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const contractInstance = new Contract(
|
|
48
|
+
this.compiledContract.abi,
|
|
49
|
+
address!,
|
|
50
|
+
this.providerOrAccount
|
|
51
|
+
);
|
|
52
|
+
contractInstance.deployTransactionHash = transaction_hash;
|
|
53
|
+
|
|
54
|
+
return contractInstance;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Attaches to new Provider or Account
|
|
59
|
+
*
|
|
60
|
+
* @param providerOrAccount - new Provider or Account to attach to
|
|
61
|
+
*/
|
|
62
|
+
connect(providerOrAccount: Provider | Account): ContractFactory {
|
|
63
|
+
this.providerOrAccount = providerOrAccount;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Attaches current abi and provider or account to the new address
|
|
69
|
+
*
|
|
70
|
+
* @param address - Contract address
|
|
71
|
+
* @returns Contract
|
|
72
|
+
*/
|
|
73
|
+
attach(address: string): Contract {
|
|
74
|
+
return new Contract(this.abi, address, this.providerOrAccount);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
78
|
+
}
|