starknet 4.7.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/CONTRIBUTING.md +2 -2
- package/__mocks__/ERC20.json +32561 -29055
- package/__mocks__/l1l2_compiled.json +10107 -0
- package/__tests__/account.test.ts +32 -24
- package/__tests__/contract.test.ts +25 -14
- package/__tests__/defaultProvider.test.ts +19 -49
- package/__tests__/fixtures.ts +11 -1
- package/__tests__/rpcProvider.test.ts +6 -15
- package/__tests__/sequencerProvider.test.ts +57 -11
- package/__tests__/utils/merkle.test.ts +113 -3
- package/__tests__/utils/typedData.test.ts +3 -3
- package/account/default.d.ts +10 -44
- package/account/default.js +255 -61
- package/account/interface.d.ts +78 -7
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/contract/default.js +6 -6
- package/dist/account/default.d.ts +10 -44
- package/dist/account/default.js +255 -61
- package/dist/account/interface.d.ts +78 -7
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/contract/default.js +6 -6
- package/dist/provider/default.d.ts +8 -3
- package/dist/provider/default.js +31 -4
- package/dist/provider/interface.d.ts +67 -5
- package/dist/provider/rpc.d.ts +7 -2
- package/dist/provider/rpc.js +83 -8
- package/dist/provider/sequencer.d.ts +9 -3
- package/dist/provider/sequencer.js +93 -14
- package/dist/signer/default.d.ts +4 -1
- package/dist/signer/default.js +22 -0
- package/dist/signer/interface.d.ts +27 -2
- package/dist/types/api/openrpc.d.ts +24 -2
- package/dist/types/api/sequencer.d.ts +43 -23
- package/dist/types/lib.d.ts +23 -2
- package/dist/types/provider.d.ts +19 -10
- package/dist/types/signer.d.ts +14 -1
- package/dist/utils/hash.d.ts +8 -0
- package/dist/utils/hash.js +28 -2
- package/dist/utils/merkle.js +4 -5
- package/dist/utils/number.d.ts +5 -0
- package/dist/utils/number.js +29 -1
- package/dist/utils/responseParser/rpc.d.ts +2 -6
- package/dist/utils/responseParser/rpc.js +0 -11
- package/dist/utils/responseParser/sequencer.js +11 -33
- package/package.json +1 -1
- package/provider/default.d.ts +8 -3
- package/provider/default.js +31 -4
- package/provider/interface.d.ts +67 -5
- package/provider/rpc.d.ts +7 -2
- package/provider/rpc.js +83 -8
- package/provider/sequencer.d.ts +9 -3
- package/provider/sequencer.js +93 -14
- package/signer/default.d.ts +4 -1
- package/signer/default.js +22 -0
- package/signer/interface.d.ts +27 -2
- package/src/account/default.ts +201 -53
- package/src/account/interface.ts +104 -6
- package/src/constants.ts +1 -0
- package/src/contract/default.ts +6 -6
- package/src/provider/default.ts +43 -5
- package/src/provider/interface.ts +92 -7
- package/src/provider/rpc.ts +86 -12
- package/src/provider/sequencer.ts +105 -13
- package/src/signer/default.ts +54 -2
- package/src/signer/interface.ts +31 -2
- package/src/types/api/openrpc.ts +28 -2
- package/src/types/api/sequencer.ts +54 -25
- package/src/types/lib.ts +30 -2
- package/src/types/provider.ts +31 -11
- package/src/types/signer.ts +18 -1
- package/src/utils/hash.ts +70 -2
- package/src/utils/merkle.ts +4 -5
- package/src/utils/number.ts +27 -0
- package/src/utils/responseParser/rpc.ts +4 -20
- package/src/utils/responseParser/sequencer.ts +14 -7
- package/types/api/openrpc.d.ts +24 -2
- package/types/api/sequencer.d.ts +43 -23
- package/types/lib.d.ts +23 -2
- package/types/provider.d.ts +19 -10
- package/types/signer.d.ts +14 -1
- package/utils/hash.d.ts +8 -0
- package/utils/hash.js +28 -2
- package/utils/merkle.js +4 -5
- package/utils/number.d.ts +5 -0
- package/utils/number.js +29 -1
- package/utils/responseParser/rpc.d.ts +2 -6
- package/utils/responseParser/rpc.js +0 -11
- package/utils/responseParser/sequencer.js +11 -33
- package/www/docs/API/account.md +60 -1
- package/www/docs/API/provider.md +320 -23
- package/www/guides/account.md +1 -1
- package/www/guides/erc20.md +13 -7
package/src/account/default.ts
CHANGED
|
@@ -6,6 +6,9 @@ import { Signer, SignerInterface } from '../signer';
|
|
|
6
6
|
import {
|
|
7
7
|
Abi,
|
|
8
8
|
Call,
|
|
9
|
+
DeclareContractResponse,
|
|
10
|
+
DeployContractResponse,
|
|
11
|
+
EstimateFeeAction,
|
|
9
12
|
InvocationsDetails,
|
|
10
13
|
InvocationsSignerDetails,
|
|
11
14
|
InvokeFunctionResponse,
|
|
@@ -13,8 +16,10 @@ import {
|
|
|
13
16
|
Signature,
|
|
14
17
|
} from '../types';
|
|
15
18
|
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
16
|
-
import {
|
|
19
|
+
import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
|
|
20
|
+
import { calculateContractAddressFromHash, transactionVersion } from '../utils/hash';
|
|
17
21
|
import { BigNumberish, toBN } from '../utils/number';
|
|
22
|
+
import { parseContract } from '../utils/provider';
|
|
18
23
|
import { compileCalldata, estimatedFeeToMaxFee } from '../utils/stark';
|
|
19
24
|
import { fromCallsToExecuteCalldata } from '../utils/transaction';
|
|
20
25
|
import { TypedData, getMessageHash } from '../utils/typedData';
|
|
@@ -41,7 +46,14 @@ export class Account extends Provider implements AccountInterface {
|
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
public async estimateFee(
|
|
44
|
-
calls: Call
|
|
49
|
+
calls: AllowArray<Call>,
|
|
50
|
+
estimateFeeDetails?: EstimateFeeDetails | undefined
|
|
51
|
+
): Promise<EstimateFee> {
|
|
52
|
+
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public async estimateInvokeFee(
|
|
56
|
+
calls: AllowArray<Call>,
|
|
45
57
|
{ nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
|
|
46
58
|
): Promise<EstimateFee> {
|
|
47
59
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
@@ -60,7 +72,7 @@ export class Account extends Provider implements AccountInterface {
|
|
|
60
72
|
const signature = await this.signer.signTransaction(transactions, signerDetails);
|
|
61
73
|
|
|
62
74
|
const calldata = fromCallsToExecuteCalldata(transactions);
|
|
63
|
-
const response = await super.
|
|
75
|
+
const response = await super.getInvokeEstimateFee(
|
|
64
76
|
{ contractAddress: this.address, calldata, signature },
|
|
65
77
|
{ version, nonce },
|
|
66
78
|
blockIdentifier
|
|
@@ -74,31 +86,87 @@ export class Account extends Provider implements AccountInterface {
|
|
|
74
86
|
};
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
public async estimateDeclareFee(
|
|
90
|
+
{ classHash, contract }: DeclareContractPayload,
|
|
91
|
+
{ blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
|
|
92
|
+
): Promise<EstimateFee> {
|
|
93
|
+
const nonce = toBN(providedNonce ?? (await this.getNonce()));
|
|
94
|
+
const version = toBN(transactionVersion);
|
|
95
|
+
const chainId = await this.getChainId();
|
|
96
|
+
const contractDefinition = parseContract(contract);
|
|
97
|
+
|
|
98
|
+
const signature = await this.signer.signDeclareTransaction({
|
|
99
|
+
classHash,
|
|
100
|
+
senderAddress: this.address,
|
|
101
|
+
chainId,
|
|
102
|
+
maxFee: ZERO,
|
|
103
|
+
version,
|
|
104
|
+
nonce,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const response = await super.getDeclareEstimateFee(
|
|
108
|
+
{ senderAddress: this.address, signature, contractDefinition },
|
|
109
|
+
{ version, nonce },
|
|
110
|
+
blockIdentifier
|
|
111
|
+
);
|
|
112
|
+
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
...response,
|
|
116
|
+
suggestedMaxFee,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public async estimateAccountDeployFee(
|
|
121
|
+
{
|
|
122
|
+
classHash,
|
|
123
|
+
addressSalt = 0,
|
|
124
|
+
constructorCalldata = [],
|
|
125
|
+
contractAddress: providedContractAddress,
|
|
126
|
+
}: DeployAccountContractPayload,
|
|
127
|
+
{ blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
|
|
128
|
+
): Promise<EstimateFee> {
|
|
129
|
+
const nonce = toBN(providedNonce ?? (await this.getNonce()));
|
|
130
|
+
const version = toBN(transactionVersion);
|
|
131
|
+
const chainId = await this.getChainId();
|
|
132
|
+
const contractAddress =
|
|
133
|
+
providedContractAddress ??
|
|
134
|
+
calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
|
|
135
|
+
|
|
136
|
+
const signature = await this.signer.signDeployAccountTransaction({
|
|
137
|
+
classHash,
|
|
138
|
+
contractAddress,
|
|
139
|
+
chainId,
|
|
140
|
+
maxFee: ZERO,
|
|
141
|
+
version,
|
|
142
|
+
nonce,
|
|
143
|
+
addressSalt,
|
|
144
|
+
constructorCalldata,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const response = await super.getDeployAccountEstimateFee(
|
|
148
|
+
{ classHash, addressSalt, constructorCalldata, signature },
|
|
149
|
+
{ version, nonce },
|
|
150
|
+
blockIdentifier
|
|
151
|
+
);
|
|
152
|
+
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
...response,
|
|
156
|
+
suggestedMaxFee,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
87
160
|
public async execute(
|
|
88
|
-
calls: Call
|
|
161
|
+
calls: AllowArray<Call>,
|
|
89
162
|
abis: Abi[] | undefined = undefined,
|
|
90
163
|
transactionsDetail: InvocationsDetails = {}
|
|
91
164
|
): Promise<InvokeFunctionResponse> {
|
|
92
165
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
93
166
|
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} else {
|
|
98
|
-
const { suggestedMaxFee } = await this.estimateFee(transactions, { nonce });
|
|
99
|
-
maxFee = suggestedMaxFee.toString();
|
|
100
|
-
}
|
|
101
|
-
|
|
167
|
+
const maxFee =
|
|
168
|
+
transactionsDetail.maxFee ??
|
|
169
|
+
(await this.getSuggestedMaxFee({ type: 'INVOKE', payload: calls }, transactionsDetail));
|
|
102
170
|
const version = toBN(transactionVersion);
|
|
103
171
|
const chainId = await this.getChainId();
|
|
104
172
|
|
|
@@ -124,37 +192,98 @@ export class Account extends Provider implements AccountInterface {
|
|
|
124
192
|
);
|
|
125
193
|
}
|
|
126
194
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
195
|
+
public async declare(
|
|
196
|
+
{ classHash, contract }: DeclareContractPayload,
|
|
197
|
+
transactionsDetail: InvocationsDetails = {}
|
|
198
|
+
): Promise<DeclareContractResponse> {
|
|
199
|
+
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
|
|
200
|
+
const maxFee =
|
|
201
|
+
transactionsDetail.maxFee ??
|
|
202
|
+
(await this.getSuggestedMaxFee(
|
|
203
|
+
{ type: 'DECLARE', payload: { classHash, contract } },
|
|
204
|
+
transactionsDetail
|
|
205
|
+
));
|
|
206
|
+
|
|
207
|
+
const version = toBN(transactionVersion);
|
|
208
|
+
const chainId = await this.getChainId();
|
|
209
|
+
|
|
210
|
+
const signature = await this.signer.signDeclareTransaction({
|
|
211
|
+
classHash,
|
|
212
|
+
senderAddress: this.address,
|
|
213
|
+
chainId,
|
|
214
|
+
maxFee,
|
|
215
|
+
version,
|
|
216
|
+
nonce,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const contractDefinition = parseContract(contract);
|
|
220
|
+
|
|
221
|
+
return this.declareContract(
|
|
222
|
+
{ contractDefinition, senderAddress: this.address, signature },
|
|
223
|
+
{
|
|
224
|
+
nonce,
|
|
225
|
+
maxFee,
|
|
226
|
+
version,
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public async deployAccount(
|
|
232
|
+
{
|
|
233
|
+
classHash,
|
|
234
|
+
constructorCalldata = [],
|
|
235
|
+
addressSalt = 0,
|
|
236
|
+
contractAddress: providedContractAddress,
|
|
237
|
+
}: DeployAccountContractPayload,
|
|
238
|
+
transactionsDetail: InvocationsDetails = {}
|
|
239
|
+
): Promise<DeployContractResponse> {
|
|
240
|
+
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
|
|
241
|
+
const version = toBN(transactionVersion);
|
|
242
|
+
const chainId = await this.getChainId();
|
|
243
|
+
|
|
244
|
+
const contractAddress =
|
|
245
|
+
providedContractAddress ??
|
|
246
|
+
calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
|
|
247
|
+
|
|
248
|
+
const maxFee =
|
|
249
|
+
transactionsDetail.maxFee ??
|
|
250
|
+
(await this.getSuggestedMaxFee(
|
|
251
|
+
{
|
|
252
|
+
type: 'DEPLOY_ACCOUNT',
|
|
253
|
+
payload: { classHash, constructorCalldata, addressSalt, contractAddress },
|
|
254
|
+
},
|
|
255
|
+
transactionsDetail
|
|
256
|
+
));
|
|
257
|
+
|
|
258
|
+
const signature = await this.signer.signDeployAccountTransaction({
|
|
259
|
+
classHash,
|
|
260
|
+
constructorCalldata,
|
|
261
|
+
contractAddress,
|
|
262
|
+
addressSalt,
|
|
263
|
+
chainId,
|
|
264
|
+
maxFee,
|
|
265
|
+
version,
|
|
266
|
+
nonce,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
return this.deployAccountContract(
|
|
270
|
+
{ classHash, addressSalt, constructorCalldata, signature },
|
|
271
|
+
{
|
|
272
|
+
nonce,
|
|
273
|
+
maxFee,
|
|
274
|
+
version,
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
134
279
|
public async signMessage(typedData: TypedData): Promise<Signature> {
|
|
135
280
|
return this.signer.signMessage(typedData, this.address);
|
|
136
281
|
}
|
|
137
282
|
|
|
138
|
-
/**
|
|
139
|
-
* Hash a JSON object with pederson hash and return the hash
|
|
140
|
-
*
|
|
141
|
-
* @param json - JSON object to be hashed
|
|
142
|
-
* @returns the hash of the JSON object
|
|
143
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
144
|
-
*/
|
|
145
283
|
public async hashMessage(typedData: TypedData): Promise<string> {
|
|
146
284
|
return getMessageHash(typedData, this.address);
|
|
147
285
|
}
|
|
148
286
|
|
|
149
|
-
/**
|
|
150
|
-
* Verify a signature of a given hash
|
|
151
|
-
* @warning This method is not recommended, use verifyMessage instead
|
|
152
|
-
*
|
|
153
|
-
* @param hash - JSON object to be verified
|
|
154
|
-
* @param signature - signature of the JSON object
|
|
155
|
-
* @returns true if the signature is valid, false otherwise
|
|
156
|
-
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
157
|
-
*/
|
|
158
287
|
public async verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean> {
|
|
159
288
|
try {
|
|
160
289
|
await this.callContract({
|
|
@@ -171,16 +300,35 @@ export class Account extends Provider implements AccountInterface {
|
|
|
171
300
|
}
|
|
172
301
|
}
|
|
173
302
|
|
|
174
|
-
/**
|
|
175
|
-
* Verify a signature of a JSON object
|
|
176
|
-
*
|
|
177
|
-
* @param hash - hash to be verified
|
|
178
|
-
* @param signature - signature of the hash
|
|
179
|
-
* @returns true if the signature is valid, false otherwise
|
|
180
|
-
* @throws {Error} if the signature is not a valid signature
|
|
181
|
-
*/
|
|
182
303
|
public async verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean> {
|
|
183
304
|
const hash = await this.hashMessage(typedData);
|
|
184
305
|
return this.verifyMessageHash(hash, signature);
|
|
185
306
|
}
|
|
307
|
+
|
|
308
|
+
public async getSuggestedMaxFee(
|
|
309
|
+
estimateFeeAction: EstimateFeeAction,
|
|
310
|
+
details: EstimateFeeDetails
|
|
311
|
+
) {
|
|
312
|
+
let feeEstimate: EstimateFee;
|
|
313
|
+
|
|
314
|
+
switch (estimateFeeAction.type) {
|
|
315
|
+
case 'INVOKE':
|
|
316
|
+
feeEstimate = await this.estimateInvokeFee(estimateFeeAction.payload, details);
|
|
317
|
+
break;
|
|
318
|
+
|
|
319
|
+
case 'DECLARE':
|
|
320
|
+
feeEstimate = await this.estimateDeclareFee(estimateFeeAction.payload, details);
|
|
321
|
+
break;
|
|
322
|
+
|
|
323
|
+
case 'DEPLOY_ACCOUNT':
|
|
324
|
+
feeEstimate = await this.estimateAccountDeployFee(estimateFeeAction.payload, details);
|
|
325
|
+
break;
|
|
326
|
+
|
|
327
|
+
default:
|
|
328
|
+
feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return feeEstimate.suggestedMaxFee.toString();
|
|
333
|
+
}
|
|
186
334
|
}
|
package/src/account/interface.ts
CHANGED
|
@@ -4,12 +4,16 @@ import { SignerInterface } from '../signer';
|
|
|
4
4
|
import {
|
|
5
5
|
Abi,
|
|
6
6
|
Call,
|
|
7
|
+
DeclareContractResponse,
|
|
8
|
+
DeployContractResponse,
|
|
9
|
+
EstimateFeeAction,
|
|
7
10
|
EstimateFeeDetails,
|
|
8
11
|
EstimateFeeResponse,
|
|
9
12
|
InvocationsDetails,
|
|
10
13
|
InvokeFunctionResponse,
|
|
11
14
|
Signature,
|
|
12
15
|
} from '../types';
|
|
16
|
+
import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
|
|
13
17
|
import { BigNumberish } from '../utils/number';
|
|
14
18
|
import { TypedData } from '../utils/typedData/types';
|
|
15
19
|
|
|
@@ -19,18 +23,61 @@ export abstract class AccountInterface extends ProviderInterface {
|
|
|
19
23
|
public abstract signer: SignerInterface;
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
|
-
*
|
|
26
|
+
* @deprecated Use estimateInvokeFee or estimateDeclareFee instead
|
|
27
|
+
* Estimate Fee for executing an INVOKE transaction on starknet
|
|
23
28
|
*
|
|
24
|
-
* @param
|
|
29
|
+
* @param calls the invocation object containing:
|
|
25
30
|
* - contractAddress - the address of the contract
|
|
26
31
|
* - entrypoint - the entrypoint of the contract
|
|
27
32
|
* - calldata - (defaults to []) the calldata
|
|
28
|
-
* - signature - (defaults to []) the signature
|
|
29
33
|
*
|
|
30
|
-
* @returns response from
|
|
34
|
+
* @returns response from estimate_fee
|
|
31
35
|
*/
|
|
32
36
|
public abstract estimateFee(
|
|
33
|
-
calls: Call
|
|
37
|
+
calls: AllowArray<Call>,
|
|
38
|
+
estimateFeeDetails?: EstimateFeeDetails
|
|
39
|
+
): Promise<EstimateFeeResponse>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Estimate Fee for executing an INVOKE transaction on starknet
|
|
43
|
+
*
|
|
44
|
+
* @param calls the invocation object containing:
|
|
45
|
+
* - contractAddress - the address of the contract
|
|
46
|
+
* - entrypoint - the entrypoint of the contract
|
|
47
|
+
* - calldata - (defaults to []) the calldata
|
|
48
|
+
*
|
|
49
|
+
* @returns response from estimate_fee
|
|
50
|
+
*/
|
|
51
|
+
public abstract estimateInvokeFee(
|
|
52
|
+
calls: AllowArray<Call>,
|
|
53
|
+
estimateFeeDetails?: EstimateFeeDetails
|
|
54
|
+
): Promise<EstimateFeeResponse>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Estimate Fee for executing a DECLARE transaction on starknet
|
|
58
|
+
*
|
|
59
|
+
* @param contractPayload the payload object containing:
|
|
60
|
+
* - contract - the compiled contract to be declared
|
|
61
|
+
* - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
|
|
62
|
+
*
|
|
63
|
+
* @returns response from estimate_fee
|
|
64
|
+
*/
|
|
65
|
+
public abstract estimateDeclareFee(
|
|
66
|
+
contractPayload: DeclareContractPayload,
|
|
67
|
+
estimateFeeDetails?: EstimateFeeDetails
|
|
68
|
+
): Promise<EstimateFeeResponse>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Estimate Fee for executing a DEPLOY_ACCOUNT transaction on starknet
|
|
72
|
+
*
|
|
73
|
+
* @param contractPayload the payload object containing:
|
|
74
|
+
* - contract - the compiled contract to be declared
|
|
75
|
+
* - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
|
|
76
|
+
*
|
|
77
|
+
* @returns response from estimate_fee
|
|
78
|
+
*/
|
|
79
|
+
public abstract estimateAccountDeployFee(
|
|
80
|
+
contractPayload: DeployAccountContractPayload,
|
|
34
81
|
estimateFeeDetails?: EstimateFeeDetails
|
|
35
82
|
): Promise<EstimateFeeResponse>;
|
|
36
83
|
|
|
@@ -47,11 +94,46 @@ export abstract class AccountInterface extends ProviderInterface {
|
|
|
47
94
|
* @returns response from addTransaction
|
|
48
95
|
*/
|
|
49
96
|
public abstract execute(
|
|
50
|
-
transactions: Call
|
|
97
|
+
transactions: AllowArray<Call>,
|
|
51
98
|
abis?: Abi[],
|
|
52
99
|
transactionsDetail?: InvocationsDetails
|
|
53
100
|
): Promise<InvokeFunctionResponse>;
|
|
54
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Declares a given compiled contract (json) to starknet
|
|
104
|
+
* @param contractPayload transaction payload to be deployed containing:
|
|
105
|
+
- contract: compiled contract code
|
|
106
|
+
- classHash: computed class hash of compiled contract
|
|
107
|
+
- signature
|
|
108
|
+
* @param transactionsDetail Invocation Details containing:
|
|
109
|
+
- optional nonce
|
|
110
|
+
- optional version
|
|
111
|
+
- optional maxFee
|
|
112
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
113
|
+
*/
|
|
114
|
+
public abstract declare(
|
|
115
|
+
contractPayload: DeclareContractPayload,
|
|
116
|
+
transactionsDetail?: InvocationsDetails
|
|
117
|
+
): Promise<DeclareContractResponse>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Deploy the account on Starknet
|
|
121
|
+
* @param contractPayload transaction payload to be deployed containing:
|
|
122
|
+
* - classHash: computed class hash of compiled contract
|
|
123
|
+
* - constructor calldata
|
|
124
|
+
* - address salt
|
|
125
|
+
- signature
|
|
126
|
+
* @param transactionsDetail Invocation Details containing:
|
|
127
|
+
- optional nonce
|
|
128
|
+
- optional version
|
|
129
|
+
- optional maxFee
|
|
130
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
131
|
+
*/
|
|
132
|
+
public abstract deployAccount(
|
|
133
|
+
contractPayload: DeployAccountContractPayload,
|
|
134
|
+
transactionsDetail?: InvocationsDetails
|
|
135
|
+
): Promise<DeployContractResponse>;
|
|
136
|
+
|
|
55
137
|
/**
|
|
56
138
|
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
57
139
|
* This adds a message prefix so it cant be interchanged with transactions
|
|
@@ -93,5 +175,21 @@ export abstract class AccountInterface extends ProviderInterface {
|
|
|
93
175
|
*/
|
|
94
176
|
public abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
95
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Gets the nonce of the account with respect to a specific block
|
|
180
|
+
* @param {BlockIdentifier} blockIdentifier - optional blockIdentifier. Defaults to 'pending'
|
|
181
|
+
* @returns nonce of the account
|
|
182
|
+
*/
|
|
96
183
|
public abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Gets Suggested Max Fee based on the transaction type
|
|
187
|
+
* @param {EstimateFeeAction} estimateFeeAction
|
|
188
|
+
* @param {EstimateFeeDetails} details
|
|
189
|
+
* @returns suggestedMaxFee
|
|
190
|
+
*/
|
|
191
|
+
public abstract getSuggestedMaxFee(
|
|
192
|
+
estimateFeeAction: EstimateFeeAction,
|
|
193
|
+
details: EstimateFeeDetails
|
|
194
|
+
): Promise<BigNumberish>;
|
|
97
195
|
}
|
package/src/constants.ts
CHANGED
|
@@ -15,6 +15,7 @@ export enum StarknetChainId {
|
|
|
15
15
|
export enum TransactionHashPrefix {
|
|
16
16
|
DECLARE = '0x6465636c617265', // encodeShortString('declare'),
|
|
17
17
|
DEPLOY = '0x6465706c6f79', // encodeShortString('deploy'),
|
|
18
|
+
DEPLOY_ACCOUNT = '0x6465706c6f795f6163636f756e74', // encodeShortString('deploy_account'),
|
|
18
19
|
INVOKE = '0x696e766f6b65', // encodeShortString('invoke'),
|
|
19
20
|
L1_HANDLER = '0x6c315f68616e646c6572', // encodeShortString('l1_handler'),
|
|
20
21
|
}
|
package/src/contract/default.ts
CHANGED
|
@@ -125,7 +125,7 @@ export class Contract implements ContractInterface {
|
|
|
125
125
|
address: string,
|
|
126
126
|
providerOrAccount: ProviderInterface | AccountInterface = defaultProvider
|
|
127
127
|
) {
|
|
128
|
-
this.address = address.toLowerCase();
|
|
128
|
+
this.address = address && address.toLowerCase();
|
|
129
129
|
this.providerOrAccount = providerOrAccount;
|
|
130
130
|
this.abi = abi;
|
|
131
131
|
this.structs = abi
|
|
@@ -546,7 +546,7 @@ export class Contract implements ContractInterface {
|
|
|
546
546
|
options: Overrides = {}
|
|
547
547
|
): Promise<InvokeFunctionResponse> {
|
|
548
548
|
// ensure contract is connected
|
|
549
|
-
assert(this.address !== null, 'contract
|
|
549
|
+
assert(this.address !== null, 'contract is not connected to an address');
|
|
550
550
|
// validate method and args
|
|
551
551
|
this.validateMethodAndArgs('INVOKE', method, args);
|
|
552
552
|
|
|
@@ -606,7 +606,7 @@ export class Contract implements ContractInterface {
|
|
|
606
606
|
} = {}
|
|
607
607
|
): Promise<Result> {
|
|
608
608
|
// ensure contract is connected
|
|
609
|
-
assert(this.address !== null, 'contract
|
|
609
|
+
assert(this.address !== null, 'contract is not connected to an address');
|
|
610
610
|
|
|
611
611
|
// validate method and args
|
|
612
612
|
this.validateMethodAndArgs('CALL', method, args);
|
|
@@ -628,13 +628,13 @@ export class Contract implements ContractInterface {
|
|
|
628
628
|
|
|
629
629
|
public async estimate(method: string, args: Array<any> = []) {
|
|
630
630
|
// ensure contract is connected
|
|
631
|
-
assert(this.address !== null, 'contract
|
|
631
|
+
assert(this.address !== null, 'contract is not connected to an address');
|
|
632
632
|
|
|
633
633
|
// validate method and args
|
|
634
634
|
this.validateMethodAndArgs('INVOKE', method, args);
|
|
635
635
|
const invocation = this.populateTransaction[method](...args);
|
|
636
|
-
if ('
|
|
637
|
-
return this.providerOrAccount.
|
|
636
|
+
if ('estimateInvokeFee' in this.providerOrAccount) {
|
|
637
|
+
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
638
638
|
}
|
|
639
639
|
throw Error('Contract must be connected to the account contract to estimate');
|
|
640
640
|
}
|
package/src/provider/default.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
Call,
|
|
4
4
|
CallContractResponse,
|
|
5
5
|
ContractClass,
|
|
6
|
-
DeclareContractPayload,
|
|
7
6
|
DeclareContractResponse,
|
|
8
7
|
DeployContractPayload,
|
|
9
8
|
DeployContractResponse,
|
|
@@ -16,6 +15,7 @@ import {
|
|
|
16
15
|
InvocationsDetailsWithNonce,
|
|
17
16
|
InvokeFunctionResponse,
|
|
18
17
|
} from '../types';
|
|
18
|
+
import { DeclareContractTransaction, DeployAccountContractTransaction } from '../types/lib';
|
|
19
19
|
import { BigNumberish } from '../utils/number';
|
|
20
20
|
import { ProviderInterface } from './interface';
|
|
21
21
|
import { RpcProvider, RpcProviderOptions } from './rpc';
|
|
@@ -62,11 +62,23 @@ export class Provider implements ProviderInterface {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
public async getEstimateFee(
|
|
65
|
-
|
|
65
|
+
invocationWithTxType: Invocation,
|
|
66
66
|
invocationDetails: InvocationsDetailsWithNonce,
|
|
67
67
|
blockIdentifier: BlockIdentifier = 'pending'
|
|
68
68
|
): Promise<EstimateFeeResponse> {
|
|
69
|
-
return this.provider.getEstimateFee(
|
|
69
|
+
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public async getInvokeEstimateFee(
|
|
73
|
+
invocationWithTxType: Invocation,
|
|
74
|
+
invocationDetails: InvocationsDetailsWithNonce,
|
|
75
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
76
|
+
): Promise<EstimateFeeResponse> {
|
|
77
|
+
return this.provider.getInvokeEstimateFee(
|
|
78
|
+
invocationWithTxType,
|
|
79
|
+
invocationDetails,
|
|
80
|
+
blockIdentifier
|
|
81
|
+
);
|
|
70
82
|
}
|
|
71
83
|
|
|
72
84
|
public async getNonce(
|
|
@@ -110,8 +122,34 @@ export class Provider implements ProviderInterface {
|
|
|
110
122
|
return this.provider.deployContract(payload);
|
|
111
123
|
}
|
|
112
124
|
|
|
113
|
-
public async
|
|
114
|
-
|
|
125
|
+
public async deployAccountContract(
|
|
126
|
+
payload: DeployAccountContractTransaction,
|
|
127
|
+
details: InvocationsDetailsWithNonce
|
|
128
|
+
): Promise<DeployContractResponse> {
|
|
129
|
+
return this.provider.deployAccountContract(payload, details);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public async declareContract(
|
|
133
|
+
transaction: DeclareContractTransaction,
|
|
134
|
+
details: InvocationsDetailsWithNonce
|
|
135
|
+
): Promise<DeclareContractResponse> {
|
|
136
|
+
return this.provider.declareContract(transaction, details);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public async getDeclareEstimateFee(
|
|
140
|
+
transaction: DeclareContractTransaction,
|
|
141
|
+
details: InvocationsDetailsWithNonce,
|
|
142
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
143
|
+
): Promise<EstimateFeeResponse> {
|
|
144
|
+
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public getDeployAccountEstimateFee(
|
|
148
|
+
transaction: DeployAccountContractTransaction,
|
|
149
|
+
details: InvocationsDetailsWithNonce,
|
|
150
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
151
|
+
): Promise<EstimateFeeResponse> {
|
|
152
|
+
return this.provider.getDeployAccountEstimateFee(transaction, details, blockIdentifier);
|
|
115
153
|
}
|
|
116
154
|
|
|
117
155
|
public async getCode(
|