starknet 3.5.1 → 3.8.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 +39 -0
- package/__tests__/account.test.ts +38 -20
- package/__tests__/accountContract.test.ts +0 -31
- package/__tests__/constancts.ts +2 -0
- package/__tests__/contract.test.ts +14 -21
- package/__tests__/provider.test.ts +8 -0
- package/account/default.d.ts +14 -1
- package/account/default.js +78 -14
- package/account/interface.d.ts +14 -0
- package/contract/default.d.ts +13 -3
- package/contract/default.js +36 -25
- package/contract/interface.d.ts +21 -3
- package/dist/account/default.d.ts +8 -2
- package/dist/account/default.js +57 -11
- package/dist/account/interface.d.ts +13 -1
- package/dist/contract/default.d.ts +7 -4
- package/dist/contract/default.js +27 -24
- package/dist/contract/interface.d.ts +9 -4
- package/dist/provider/default.d.ts +11 -4
- package/dist/provider/default.js +34 -30
- package/dist/provider/utils.d.ts +1 -2
- package/dist/provider/utils.js +7 -8
- package/dist/signer/index.d.ts +1 -0
- package/dist/signer/index.js +1 -0
- package/dist/signer/ledger.d.ts +12 -0
- package/dist/signer/ledger.js +138 -0
- package/dist/types/api.d.ts +60 -3
- package/package.json +5 -2
- package/provider/default.d.ts +13 -3
- package/provider/default.js +49 -42
- package/provider/utils.d.ts +1 -2
- package/provider/utils.js +7 -8
- package/signer/index.d.ts +1 -0
- package/signer/index.js +1 -0
- package/signer/ledger.d.ts +15 -0
- package/signer/ledger.js +243 -0
- package/src/account/default.ts +40 -6
- package/src/account/interface.ts +15 -0
- package/src/contract/default.ts +37 -34
- package/src/contract/interface.ts +21 -3
- package/src/provider/default.ts +31 -23
- package/src/provider/utils.ts +7 -8
- package/src/signer/index.ts +1 -0
- package/src/signer/ledger.ts +81 -0
- package/src/types/api.ts +65 -4
- package/tsconfig.json +1 -10
- package/types/api.d.ts +60 -3
- package/www/README.md +41 -0
- package/www/babel.config.js +3 -0
- package/www/code-examples/account.js +62 -0
- package/www/code-examples/amm.js +49 -0
- package/www/code-examples/erc20.js +10 -0
- package/www/code-examples/package-lock.json +336 -0
- package/www/code-examples/package.json +15 -0
- package/www/docs/API/_category_.json +5 -0
- package/www/docs/API/account.md +11 -0
- package/www/docs/API/contract.md +14 -0
- package/www/docs/API/index.md +4 -0
- package/www/docs/API/provider.md +10 -0
- package/www/docs/API/signer.md +8 -0
- package/www/docusaurus.config.js +131 -0
- package/www/guides/account.md +60 -0
- package/www/guides/cra.md +3 -0
- package/www/guides/erc20.md +88 -0
- package/www/guides/intro.md +20 -0
- package/www/package-lock.json +22285 -0
- package/www/package.json +43 -0
- package/www/sidebars.js +31 -0
- package/www/src/components/HomepageFeatures/index.tsx +67 -0
- package/www/src/components/HomepageFeatures/styles.module.css +10 -0
- package/www/src/css/custom.css +39 -0
- package/www/src/pages/index.module.css +23 -0
- package/www/src/pages/index.tsx +40 -0
- package/www/src/pages/markdown-page.md +7 -0
- package/www/static/.nojekyll +0 -0
- package/www/static/img/docusaurus.png +0 -0
- package/www/static/img/favicon.ico +0 -0
- package/www/static/img/logo.svg +17 -0
- package/www/static/img/starknet-1.png +0 -0
- package/www/static/img/starknet-2.png +0 -0
- package/www/static/img/starknet-3.png +0 -0
- package/www/static/img/tutorial/docsVersionDropdown.png +0 -0
- package/www/static/img/tutorial/localeDropdown.png +0 -0
- package/www/tsconfig.json +8 -0
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,13 +1,19 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
-
import {
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
|
+
import { SignerInterface } from '../signer';
|
|
4
|
+
import { Abi, AddTransactionResponse, Call, EstimateFeeResponse, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
3
5
|
import { BigNumberish } from '../utils/number';
|
|
4
6
|
import { TypedData } from '../utils/typedData';
|
|
5
7
|
import { AccountInterface } from './interface';
|
|
6
8
|
export declare class Account extends Provider implements AccountInterface {
|
|
7
9
|
address: string;
|
|
8
10
|
private signer;
|
|
9
|
-
constructor(provider: Provider, address: string,
|
|
11
|
+
constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
10
12
|
getNonce(): Promise<string>;
|
|
13
|
+
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier, }?: {
|
|
14
|
+
nonce?: BigNumberish;
|
|
15
|
+
blockIdentifier?: BlockIdentifier;
|
|
16
|
+
}): Promise<EstimateFeeResponse>;
|
|
11
17
|
/**
|
|
12
18
|
* Invoke execute function in account contract
|
|
13
19
|
*
|
package/dist/account/default.js
CHANGED
|
@@ -91,9 +91,10 @@ var transaction_1 = require("../utils/transaction");
|
|
|
91
91
|
var typedData_1 = require("../utils/typedData");
|
|
92
92
|
var Account = /** @class */ (function (_super) {
|
|
93
93
|
__extends(Account, _super);
|
|
94
|
-
function Account(provider, address,
|
|
94
|
+
function Account(provider, address, keyPairOrSigner) {
|
|
95
95
|
var _this = _super.call(this, provider) || this;
|
|
96
|
-
_this.signer =
|
|
96
|
+
_this.signer =
|
|
97
|
+
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new signer_1.Signer(keyPairOrSigner);
|
|
97
98
|
_this.address = address;
|
|
98
99
|
return _this;
|
|
99
100
|
}
|
|
@@ -113,6 +114,42 @@ var Account = /** @class */ (function (_super) {
|
|
|
113
114
|
});
|
|
114
115
|
});
|
|
115
116
|
};
|
|
117
|
+
Account.prototype.estimateFee = function (calls, _a) {
|
|
118
|
+
var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
var transactions, nonce, _d, signerDetails, signature, calldata;
|
|
121
|
+
return __generator(this, function (_e) {
|
|
122
|
+
switch (_e.label) {
|
|
123
|
+
case 0:
|
|
124
|
+
transactions = Array.isArray(calls) ? calls : [calls];
|
|
125
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
126
|
+
_d = providedNonce;
|
|
127
|
+
return [3 /*break*/, 3];
|
|
128
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
129
|
+
case 2:
|
|
130
|
+
_d = (_e.sent());
|
|
131
|
+
_e.label = 3;
|
|
132
|
+
case 3:
|
|
133
|
+
nonce = _d;
|
|
134
|
+
signerDetails = {
|
|
135
|
+
walletAddress: this.address,
|
|
136
|
+
nonce: (0, number_1.toBN)(nonce),
|
|
137
|
+
maxFee: (0, number_1.toBN)('0'),
|
|
138
|
+
};
|
|
139
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
140
|
+
case 4:
|
|
141
|
+
signature = _e.sent();
|
|
142
|
+
calldata = __spreadArray(__spreadArray([], __read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)), false), [signerDetails.nonce.toString()], false);
|
|
143
|
+
return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
144
|
+
contract_address: this.address,
|
|
145
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
146
|
+
calldata: calldata,
|
|
147
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
148
|
+
})];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
116
153
|
/**
|
|
117
154
|
* Invoke execute function in account contract
|
|
118
155
|
*
|
|
@@ -126,15 +163,11 @@ var Account = /** @class */ (function (_super) {
|
|
|
126
163
|
if (abis === void 0) { abis = undefined; }
|
|
127
164
|
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
128
165
|
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
-
var transactions,
|
|
130
|
-
var _e;
|
|
166
|
+
var transactions, nonce, _c, _d, maxFee, _e, signerDetails, signature, calldata;
|
|
131
167
|
return __generator(this, function (_f) {
|
|
132
168
|
switch (_f.label) {
|
|
133
169
|
case 0:
|
|
134
170
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
135
|
-
_e = {
|
|
136
|
-
walletAddress: this.address
|
|
137
|
-
};
|
|
138
171
|
_c = number_1.toBN;
|
|
139
172
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
140
173
|
_d = _a;
|
|
@@ -144,11 +177,23 @@ var Account = /** @class */ (function (_super) {
|
|
|
144
177
|
_d = (_f.sent());
|
|
145
178
|
_f.label = 3;
|
|
146
179
|
case 3:
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
180
|
+
nonce = _c.apply(void 0, [_d]);
|
|
181
|
+
if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0)) return [3 /*break*/, 4];
|
|
182
|
+
_e = _b;
|
|
183
|
+
return [3 /*break*/, 6];
|
|
184
|
+
case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
185
|
+
case 5:
|
|
186
|
+
_e = (_f.sent()).amount;
|
|
187
|
+
_f.label = 6;
|
|
188
|
+
case 6:
|
|
189
|
+
maxFee = _e;
|
|
190
|
+
signerDetails = {
|
|
191
|
+
walletAddress: this.address,
|
|
192
|
+
nonce: nonce,
|
|
193
|
+
maxFee: maxFee,
|
|
194
|
+
};
|
|
150
195
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
151
|
-
case
|
|
196
|
+
case 7:
|
|
152
197
|
signature = _f.sent();
|
|
153
198
|
calldata = __spreadArray(__spreadArray([], __read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)), false), [signerDetails.nonce.toString()], false);
|
|
154
199
|
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
@@ -157,6 +202,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
157
202
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
158
203
|
calldata: calldata,
|
|
159
204
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
205
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(maxFee)),
|
|
160
206
|
})];
|
|
161
207
|
}
|
|
162
208
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
|
-
import { Abi, AddTransactionResponse, Call, DeployContractPayload, InvocationsDetails, Signature } from '../types';
|
|
2
|
+
import { Abi, AddTransactionResponse, Call, DeployContractPayload, EstimateFeeResponse, Invocation, InvocationsDetails, Signature } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { TypedData } from '../utils/typedData/types';
|
|
5
5
|
export declare abstract class AccountInterface extends ProviderInterface {
|
|
@@ -15,6 +15,18 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
15
15
|
* @returns a confirmation of sending a transaction on the starknet contract
|
|
16
16
|
*/
|
|
17
17
|
abstract deployContract(payload: DeployContractPayload, abi?: Abi): Promise<AddTransactionResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Estimate Fee for a method on starknet
|
|
20
|
+
*
|
|
21
|
+
* @param invocation the invocation object containing:
|
|
22
|
+
* - contractAddress - the address of the contract
|
|
23
|
+
* - entrypoint - the entrypoint of the contract
|
|
24
|
+
* - calldata - (defaults to []) the calldata
|
|
25
|
+
* - signature - (defaults to []) the signature
|
|
26
|
+
*
|
|
27
|
+
* @returns response from addTransaction
|
|
28
|
+
*/
|
|
29
|
+
abstract estimateFee(invocation: Invocation): Promise<EstimateFeeResponse>;
|
|
18
30
|
/**
|
|
19
31
|
* Invoke execute function in account contract
|
|
20
32
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
-
import {
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
4
|
+
import { Abi, AbiEntry, AddTransactionResponse, Args, AsyncContractFunction, Calldata, ContractFunction, Invocation, Overrides, ParsedStruct, Result, StructAbi } from '../types';
|
|
4
5
|
import { BigNumberish } from '../utils/number';
|
|
5
6
|
import { ContractInterface } from './interface';
|
|
6
7
|
export declare class Contract implements ContractInterface {
|
|
@@ -114,8 +115,10 @@ export declare class Contract implements ContractInterface {
|
|
|
114
115
|
* @return - parsed response corresponding to the abi
|
|
115
116
|
*/
|
|
116
117
|
protected parseResponse(method: string, response: string[]): Result;
|
|
117
|
-
invoke(method: string, args?: Array<any
|
|
118
|
-
call(method: string, args?: Array<any
|
|
119
|
-
|
|
118
|
+
invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
119
|
+
call(method: string, args?: Array<any>, { blockIdentifier, }?: {
|
|
120
|
+
blockIdentifier?: BlockIdentifier;
|
|
121
|
+
}): Promise<Result>;
|
|
122
|
+
estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
|
|
120
123
|
populate(method: string, args?: Array<any>): Invocation;
|
|
121
124
|
}
|
package/dist/contract/default.js
CHANGED
|
@@ -79,7 +79,6 @@ exports.Contract = void 0;
|
|
|
79
79
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
80
80
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
81
81
|
var provider_1 = require("../provider");
|
|
82
|
-
var hash_1 = require("../utils/hash");
|
|
83
82
|
var number_1 = require("../utils/number");
|
|
84
83
|
function parseFelt(candidate) {
|
|
85
84
|
try {
|
|
@@ -551,8 +550,9 @@ var Contract = /** @class */ (function () {
|
|
|
551
550
|
return acc;
|
|
552
551
|
}, []);
|
|
553
552
|
};
|
|
554
|
-
Contract.prototype.invoke = function (method, args) {
|
|
553
|
+
Contract.prototype.invoke = function (method, args, options) {
|
|
555
554
|
if (args === void 0) { args = []; }
|
|
555
|
+
if (options === void 0) { options = {}; }
|
|
556
556
|
// ensure contract is connected
|
|
557
557
|
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
558
558
|
// validate method and args
|
|
@@ -564,10 +564,6 @@ var Contract = /** @class */ (function () {
|
|
|
564
564
|
}
|
|
565
565
|
return acc;
|
|
566
566
|
}, 0);
|
|
567
|
-
var signature = [];
|
|
568
|
-
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
569
|
-
signature.push.apply(signature, __spreadArray([], __read(args.pop()), false));
|
|
570
|
-
}
|
|
571
567
|
if (args.length !== inputsLength) {
|
|
572
568
|
throw Error("Invalid number of arguments, expected " + inputsLength + " arguments, but got " + args.length);
|
|
573
569
|
}
|
|
@@ -579,45 +575,52 @@ var Contract = /** @class */ (function () {
|
|
|
579
575
|
entrypoint: method,
|
|
580
576
|
};
|
|
581
577
|
if ('execute' in this.providerOrAccount) {
|
|
582
|
-
return this.providerOrAccount.execute(invocation
|
|
578
|
+
return this.providerOrAccount.execute(invocation, undefined, {
|
|
579
|
+
maxFee: options.maxFee,
|
|
580
|
+
nonce: options.nonce,
|
|
581
|
+
});
|
|
583
582
|
}
|
|
584
|
-
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: signature }));
|
|
583
|
+
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }));
|
|
585
584
|
};
|
|
586
|
-
Contract.prototype.call = function (method, args) {
|
|
585
|
+
Contract.prototype.call = function (method, args, _a) {
|
|
587
586
|
if (args === void 0) { args = []; }
|
|
587
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
588
588
|
return __awaiter(this, void 0, void 0, function () {
|
|
589
|
-
var inputs,
|
|
589
|
+
var inputs, calldata;
|
|
590
590
|
var _this = this;
|
|
591
|
-
return __generator(this, function (
|
|
591
|
+
return __generator(this, function (_d) {
|
|
592
592
|
// ensure contract is connected
|
|
593
593
|
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
594
594
|
// validate method and args
|
|
595
595
|
this.validateMethodAndArgs('CALL', method, args);
|
|
596
596
|
inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
597
|
-
inputsLength = inputs.length;
|
|
598
|
-
options = {
|
|
599
|
-
blockIdentifier: null,
|
|
600
|
-
};
|
|
601
|
-
if (args.length === inputsLength + 1 && typeof args[args.length - 1] === 'object') {
|
|
602
|
-
Object.assign(options, args.pop());
|
|
603
|
-
}
|
|
604
597
|
calldata = this.compileCalldata(args, inputs);
|
|
605
598
|
return [2 /*return*/, this.providerOrAccount
|
|
606
599
|
.callContract({
|
|
607
600
|
contractAddress: this.address,
|
|
608
601
|
calldata: calldata,
|
|
609
602
|
entrypoint: method,
|
|
610
|
-
},
|
|
603
|
+
}, { blockIdentifier: blockIdentifier })
|
|
611
604
|
.then(function (x) { return _this.parseResponse(method, x.result); })];
|
|
612
605
|
});
|
|
613
606
|
});
|
|
614
607
|
};
|
|
615
|
-
Contract.prototype.estimate = function (
|
|
616
|
-
if (
|
|
608
|
+
Contract.prototype.estimate = function (method, args) {
|
|
609
|
+
if (args === void 0) { args = []; }
|
|
617
610
|
return __awaiter(this, void 0, void 0, function () {
|
|
618
|
-
|
|
611
|
+
var invocation;
|
|
612
|
+
var _a;
|
|
613
|
+
return __generator(this, function (_b) {
|
|
619
614
|
// TODO; remove error as soon as estimate fees are supported
|
|
620
|
-
|
|
615
|
+
// ensure contract is connected
|
|
616
|
+
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
617
|
+
// validate method and args
|
|
618
|
+
this.validateMethodAndArgs('INVOKE', method, args);
|
|
619
|
+
invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
|
|
620
|
+
if ('estimateFee' in this.providerOrAccount) {
|
|
621
|
+
return [2 /*return*/, this.providerOrAccount.estimateFee(invocation)];
|
|
622
|
+
}
|
|
623
|
+
throw Error('Contract must be connected to the account contract to estimate');
|
|
621
624
|
});
|
|
622
625
|
});
|
|
623
626
|
};
|
|
@@ -626,7 +629,7 @@ var Contract = /** @class */ (function () {
|
|
|
626
629
|
var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
627
630
|
return {
|
|
628
631
|
contractAddress: this.address,
|
|
629
|
-
entrypoint:
|
|
632
|
+
entrypoint: method,
|
|
630
633
|
calldata: this.compileCalldata(args, inputs),
|
|
631
634
|
signature: [],
|
|
632
635
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
-
import {
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
4
|
+
import { Abi, AddTransactionResponse, AsyncContractFunction, ContractFunction, Invocation, Overrides, Result } from '../types';
|
|
4
5
|
export declare abstract class ContractInterface {
|
|
5
6
|
abstract abi: Abi;
|
|
6
7
|
abstract address: string;
|
|
@@ -45,7 +46,9 @@ export declare abstract class ContractInterface {
|
|
|
45
46
|
* @param args Array of the arguments for the call
|
|
46
47
|
* @returns Result of the call as an array with key value pars
|
|
47
48
|
*/
|
|
48
|
-
abstract call(method: string, args?: Array<any
|
|
49
|
+
abstract call(method: string, args?: Array<any>, options?: {
|
|
50
|
+
blockIdentifier?: BlockIdentifier;
|
|
51
|
+
}): Promise<Result>;
|
|
49
52
|
/**
|
|
50
53
|
* Invokes a method on a contract
|
|
51
54
|
*
|
|
@@ -53,14 +56,16 @@ export declare abstract class ContractInterface {
|
|
|
53
56
|
* @param args Array of the arguments for the invoke
|
|
54
57
|
* @returns Add Transaction Response
|
|
55
58
|
*/
|
|
56
|
-
abstract invoke(method: string, args?: Array<any
|
|
59
|
+
abstract invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
57
60
|
/**
|
|
58
61
|
* Calls a method on a contract
|
|
59
62
|
*
|
|
60
63
|
* @param method name of the method
|
|
61
64
|
* @param args Array of the arguments for the call
|
|
62
65
|
*/
|
|
63
|
-
abstract estimate(method: string, args?: Array<any
|
|
66
|
+
abstract estimate(method: string, args?: Array<any>, options?: {
|
|
67
|
+
blockIdentifier?: BlockIdentifier;
|
|
68
|
+
}): Promise<any>;
|
|
64
69
|
/**
|
|
65
70
|
* Calls a method on a contract
|
|
66
71
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceipt } from '../types';
|
|
1
|
+
import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceipt } from '../types';
|
|
2
2
|
import { BigNumberish } from '../utils/number';
|
|
3
3
|
import { ProviderInterface } from './interface';
|
|
4
4
|
import { BlockIdentifier } from './utils';
|
|
@@ -36,8 +36,8 @@ 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,
|
|
40
|
-
blockIdentifier
|
|
39
|
+
callContract({ contractAddress, entrypoint, calldata }: Call, { blockIdentifier }?: {
|
|
40
|
+
blockIdentifier?: BlockIdentifier;
|
|
41
41
|
}): Promise<CallContractResponse>;
|
|
42
42
|
/**
|
|
43
43
|
* Gets the block information
|
|
@@ -103,6 +103,14 @@ export declare class Provider implements ProviderInterface {
|
|
|
103
103
|
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
104
104
|
*/
|
|
105
105
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Gets the transaction trace from a tx id.
|
|
108
|
+
*
|
|
109
|
+
*
|
|
110
|
+
* @param txHash
|
|
111
|
+
* @returns the transaction trace
|
|
112
|
+
*/
|
|
113
|
+
getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
|
|
106
114
|
/**
|
|
107
115
|
* Deploys a given compiled contract (json) to starknet
|
|
108
116
|
*
|
|
@@ -120,7 +128,6 @@ export declare class Provider implements ProviderInterface {
|
|
|
120
128
|
* @returns response from addTransaction
|
|
121
129
|
*/
|
|
122
130
|
invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
|
|
123
|
-
estimateFee(invocation: Invocation): Promise<any>;
|
|
124
131
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
125
132
|
/**
|
|
126
133
|
* @deprecated use `waitForTransaction` instead
|
package/dist/provider/default.js
CHANGED
|
@@ -219,12 +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,
|
|
223
|
-
var contractAddress = _a.contractAddress, entrypoint = _a.entrypoint,
|
|
224
|
-
|
|
222
|
+
Provider.prototype.callContract = function (_a, _b) {
|
|
223
|
+
var contractAddress = _a.contractAddress, entrypoint = _a.entrypoint, _c = _a.calldata, calldata = _c === void 0 ? [] : _c;
|
|
224
|
+
var _d = _b === void 0 ? {} : _b, _e = _d.blockIdentifier, blockIdentifier = _e === void 0 ? 'pending' : _e;
|
|
225
225
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
-
return __generator(this, function (
|
|
227
|
-
return [2 /*return*/, this.fetchEndpoint('call_contract',
|
|
226
|
+
return __generator(this, function (_f) {
|
|
227
|
+
return [2 /*return*/, this.fetchEndpoint('call_contract', { blockIdentifier: blockIdentifier }, {
|
|
228
228
|
signature: [],
|
|
229
229
|
contract_address: contractAddress,
|
|
230
230
|
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
@@ -261,7 +261,7 @@ var Provider = /** @class */ (function () {
|
|
|
261
261
|
* @returns Bytecode and ABI of compiled contract
|
|
262
262
|
*/
|
|
263
263
|
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
264
|
-
if (blockIdentifier === void 0) { blockIdentifier =
|
|
264
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
265
265
|
return __awaiter(this, void 0, void 0, function () {
|
|
266
266
|
return __generator(this, function (_a) {
|
|
267
267
|
return [2 /*return*/, this.fetchEndpoint('get_code', { blockIdentifier: blockIdentifier, contractAddress: contractAddress })];
|
|
@@ -281,7 +281,7 @@ var Provider = /** @class */ (function () {
|
|
|
281
281
|
* @returns the value of the storage variable
|
|
282
282
|
*/
|
|
283
283
|
Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
284
|
-
if (blockIdentifier === void 0) { blockIdentifier =
|
|
284
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
285
285
|
return __awaiter(this, void 0, void 0, function () {
|
|
286
286
|
return __generator(this, function (_a) {
|
|
287
287
|
return [2 /*return*/, this.fetchEndpoint('get_storage_at', { blockIdentifier: blockIdentifier, contractAddress: contractAddress, key: key })];
|
|
@@ -345,6 +345,22 @@ var Provider = /** @class */ (function () {
|
|
|
345
345
|
});
|
|
346
346
|
});
|
|
347
347
|
};
|
|
348
|
+
/**
|
|
349
|
+
* Gets the transaction trace from a tx id.
|
|
350
|
+
*
|
|
351
|
+
*
|
|
352
|
+
* @param txHash
|
|
353
|
+
* @returns the transaction trace
|
|
354
|
+
*/
|
|
355
|
+
Provider.prototype.getTransactionTrace = function (txHash) {
|
|
356
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
357
|
+
var txHashHex;
|
|
358
|
+
return __generator(this, function (_a) {
|
|
359
|
+
txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
|
|
360
|
+
return [2 /*return*/, this.fetchEndpoint('get_transaction_trace', { transactionHash: txHashHex })];
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
};
|
|
348
364
|
/**
|
|
349
365
|
* Deploys a given compiled contract (json) to starknet
|
|
350
366
|
*
|
|
@@ -383,43 +399,31 @@ var Provider = /** @class */ (function () {
|
|
|
383
399
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = invocation.signature) !== null && _b !== void 0 ? _b : []),
|
|
384
400
|
});
|
|
385
401
|
};
|
|
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
402
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
398
403
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
399
404
|
return __awaiter(this, void 0, void 0, function () {
|
|
400
|
-
var onchain, res, message, error;
|
|
405
|
+
var onchain, res, successStates, errorStates, message, error;
|
|
401
406
|
return __generator(this, function (_a) {
|
|
402
407
|
switch (_a.label) {
|
|
403
408
|
case 0:
|
|
404
409
|
onchain = false;
|
|
405
|
-
|
|
410
|
+
_a.label = 1;
|
|
406
411
|
case 1:
|
|
407
|
-
|
|
408
|
-
_a.label = 2;
|
|
409
|
-
case 2:
|
|
410
|
-
if (!!onchain) return [3 /*break*/, 5];
|
|
412
|
+
if (!!onchain) return [3 /*break*/, 4];
|
|
411
413
|
// eslint-disable-next-line no-await-in-loop
|
|
412
414
|
return [4 /*yield*/, wait(retryInterval)];
|
|
413
|
-
case
|
|
415
|
+
case 2:
|
|
414
416
|
// eslint-disable-next-line no-await-in-loop
|
|
415
417
|
_a.sent();
|
|
416
418
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
417
|
-
case
|
|
419
|
+
case 3:
|
|
418
420
|
res = _a.sent();
|
|
419
|
-
|
|
421
|
+
successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
|
|
422
|
+
errorStates = ['REJECTED', 'NOT_RECEIVED'];
|
|
423
|
+
if (successStates.includes(res.tx_status)) {
|
|
420
424
|
onchain = true;
|
|
421
425
|
}
|
|
422
|
-
else if (
|
|
426
|
+
else if (errorStates.includes(res.tx_status)) {
|
|
423
427
|
message = res.tx_failure_reason
|
|
424
428
|
? res.tx_status + ": " + res.tx_failure_reason.code + "\n" + res.tx_failure_reason.error_message
|
|
425
429
|
: res.tx_status;
|
|
@@ -427,8 +431,8 @@ var Provider = /** @class */ (function () {
|
|
|
427
431
|
error.response = res;
|
|
428
432
|
throw error;
|
|
429
433
|
}
|
|
430
|
-
return [3 /*break*/,
|
|
431
|
-
case
|
|
434
|
+
return [3 /*break*/, 1];
|
|
435
|
+
case 4: return [2 /*return*/];
|
|
432
436
|
}
|
|
433
437
|
});
|
|
434
438
|
});
|
package/dist/provider/utils.d.ts
CHANGED
|
@@ -35,8 +35,7 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
|
|
|
35
35
|
*
|
|
36
36
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @param blockHash
|
|
38
|
+
* @param blockIdentifier
|
|
40
39
|
* @returns block identifier for API request
|
|
41
40
|
*/
|
|
42
41
|
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
package/dist/provider/utils.js
CHANGED
|
@@ -36,6 +36,12 @@ exports.txIdentifier = txIdentifier;
|
|
|
36
36
|
* @returns block identifier object
|
|
37
37
|
*/
|
|
38
38
|
function getBlockIdentifier(blockIdentifier) {
|
|
39
|
+
if (blockIdentifier === null) {
|
|
40
|
+
return { type: 'BLOCK_NUMBER', data: null };
|
|
41
|
+
}
|
|
42
|
+
if (blockIdentifier === 'pending') {
|
|
43
|
+
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
44
|
+
}
|
|
39
45
|
if (typeof blockIdentifier === 'number') {
|
|
40
46
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
41
47
|
}
|
|
@@ -45,12 +51,6 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
45
51
|
if (typeof blockIdentifier === 'string' && !Number.isNaN(parseInt(blockIdentifier, 10))) {
|
|
46
52
|
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
47
53
|
}
|
|
48
|
-
if (blockIdentifier === null) {
|
|
49
|
-
return { type: 'BLOCK_NUMBER', data: null };
|
|
50
|
-
}
|
|
51
|
-
if (blockIdentifier === 'pending') {
|
|
52
|
-
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
53
|
-
}
|
|
54
54
|
if (typeof blockIdentifier === 'string') {
|
|
55
55
|
throw new Error("Invalid block identifier: " + blockIdentifier);
|
|
56
56
|
}
|
|
@@ -62,8 +62,7 @@ exports.getBlockIdentifier = getBlockIdentifier;
|
|
|
62
62
|
*
|
|
63
63
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
64
64
|
*
|
|
65
|
-
* @param
|
|
66
|
-
* @param blockHash
|
|
65
|
+
* @param blockIdentifier
|
|
67
66
|
* @returns block identifier for API request
|
|
68
67
|
*/
|
|
69
68
|
function getFormattedBlockIdentifier(blockIdentifier) {
|
package/dist/signer/index.d.ts
CHANGED
package/dist/signer/index.js
CHANGED
|
@@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./interface"), exports);
|
|
14
14
|
__exportStar(require("./default"), exports);
|
|
15
|
+
__exportStar(require("./ledger"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Invocation, InvocationsSignerDetails, Signature } from '../types';
|
|
2
|
+
import { TypedData } from '../utils/typedData';
|
|
3
|
+
import { SignerInterface } from './interface';
|
|
4
|
+
export declare class LedgerBlindSigner implements SignerInterface {
|
|
5
|
+
derivationPath: string;
|
|
6
|
+
private transport;
|
|
7
|
+
private getEthApp;
|
|
8
|
+
getPubKey(): Promise<string>;
|
|
9
|
+
signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails): Promise<Signature>;
|
|
10
|
+
signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
|
11
|
+
protected sign(msgHash: string): Promise<Signature>;
|
|
12
|
+
}
|