Skip to content

Commit b95c462

Browse files
committed
feat: v3 wip with est
1 parent 5dfe445 commit b95c462

File tree

4 files changed

+128
-54
lines changed

4 files changed

+128
-54
lines changed

src/account/default.ts

Lines changed: 119 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
TypedData,
4141
UniversalDeployerContractPayload,
4242
} from '../types';
43-
import { ETransactionVersion, ETransactionVersion3 } from '../types/api';
43+
import { ETransactionVersion, ETransactionVersion3, ResourceBounds } from '../types/api';
4444
import { CallData } from '../utils/calldata';
4545
import { extractContractHashes, isSierra } from '../utils/contract';
4646
import { starkCurve } from '../utils/ec';
@@ -161,7 +161,8 @@ export class Account extends Provider implements AccountInterface {
161161
const estimateFeeResponse = await super.getInvokeEstimateFee(
162162
{ ...invocation },
163163
{ ...v3Details(details), version, nonce },
164-
blockIdentifier
164+
blockIdentifier,
165+
details.skipValidate
165166
);
166167

167168
return {
@@ -201,7 +202,8 @@ export class Account extends Provider implements AccountInterface {
201202
const estimateFeeResponse = await super.getDeclareEstimateFee(
202203
declareContractTransaction,
203204
{ ...v3Details(details), version, nonce },
204-
blockIdentifier
205+
blockIdentifier,
206+
details.skipValidate
205207
);
206208

207209
return {
@@ -244,7 +246,8 @@ export class Account extends Provider implements AccountInterface {
244246
const estimateFeeResponse = await super.getDeployAccountEstimateFee(
245247
{ ...payload },
246248
{ ...v3Details(details), version, nonce },
247-
blockIdentifier
249+
blockIdentifier,
250+
details.skipValidate
248251
);
249252

250253
return {
@@ -279,6 +282,7 @@ export class Account extends Provider implements AccountInterface {
279282

280283
const EstimateFeeResponseBulk = await super.getEstimateFeeBulk(accountInvocations, {
281284
blockIdentifier,
285+
skipValidate: details.skipValidate,
282286
});
283287

284288
return [].concat(EstimateFeeResponseBulk as []).map((elem: EstimateFeeResponse) => {
@@ -316,23 +320,43 @@ export class Account extends Provider implements AccountInterface {
316320
this.getPreferredVersion(ETransactionVersion.V1, ETransactionVersion.V3), // TODO: does this depend on cairo version ?
317321
details.version
318322
);
319-
const maxFee =
320-
details.maxFee ??
321-
(await this.getSuggestedMaxFee(
322-
{ type: TransactionType.INVOKE, payload: calls },
323-
{
324-
...details,
325-
version,
326-
}
327-
));
323+
324+
let suggestedMaxFee: BigNumberish = 0;
325+
let resourceBounds: ResourceBounds = estimateFeeToBounds(ZERO);
326+
if (version === ETransactionVersion.V3) {
327+
resourceBounds =
328+
details.resourceBounds ??
329+
(
330+
await this.getSuggestedFee(
331+
{ type: TransactionType.INVOKE, payload: calls },
332+
{
333+
...details,
334+
version,
335+
}
336+
)
337+
).resourceBounds;
338+
} else {
339+
suggestedMaxFee =
340+
details.maxFee ??
341+
(
342+
await this.getSuggestedFee(
343+
{ type: TransactionType.INVOKE, payload: calls },
344+
{
345+
...details,
346+
version,
347+
}
348+
)
349+
).suggestedMaxFee;
350+
}
328351

329352
const chainId = await this.getChainId();
330353

331354
const signerDetails: InvocationsSignerDetails = {
332355
...v3Details(details),
356+
resourceBounds,
333357
walletAddress: this.address,
334358
nonce,
335-
maxFee,
359+
maxFee: suggestedMaxFee,
336360
version,
337361
chainId,
338362
cairoVersion: await this.getCairoVersion(),
@@ -346,8 +370,9 @@ export class Account extends Provider implements AccountInterface {
346370
{ contractAddress: this.address, calldata, signature },
347371
{
348372
...v3Details(details),
373+
resourceBounds,
349374
nonce,
350-
maxFee,
375+
maxFee: suggestedMaxFee,
351376
version,
352377
}
353378
);
@@ -388,21 +413,45 @@ export class Account extends Provider implements AccountInterface {
388413
providedVersion
389414
);
390415

416+
let suggestedMaxFee: BigNumberish = 0;
417+
let resourceBounds: ResourceBounds = estimateFeeToBounds(ZERO);
418+
if (version === ETransactionVersion.V3) {
419+
resourceBounds =
420+
details.resourceBounds ??
421+
(
422+
await this.getSuggestedFee(
423+
{
424+
type: TransactionType.DECLARE,
425+
payload: declareContractPayload,
426+
},
427+
{
428+
...details,
429+
version,
430+
}
431+
)
432+
).resourceBounds;
433+
} else {
434+
suggestedMaxFee =
435+
maxFee ??
436+
(
437+
await this.getSuggestedFee(
438+
{
439+
type: TransactionType.DECLARE,
440+
payload: declareContractPayload,
441+
},
442+
{
443+
...details,
444+
version,
445+
}
446+
)
447+
).suggestedMaxFee;
448+
}
449+
391450
const declareDetails: InvocationsSignerDetails = {
392451
...v3Details(details),
452+
resourceBounds,
453+
maxFee: suggestedMaxFee,
393454
nonce: toBigInt(nonce ?? (await this.getNonce())),
394-
maxFee:
395-
maxFee ??
396-
(await this.getSuggestedMaxFee(
397-
{
398-
type: TransactionType.DECLARE,
399-
payload: declareContractPayload,
400-
},
401-
{
402-
...details,
403-
version,
404-
}
405-
)),
406455
version,
407456
chainId: await this.getChainId(),
408457
walletAddress: this.address,
@@ -512,20 +561,43 @@ export class Account extends Provider implements AccountInterface {
512561
providedContractAddress ??
513562
calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
514563

515-
const maxFee =
516-
details.maxFee ??
517-
(await this.getSuggestedMaxFee(
518-
{
519-
type: TransactionType.DEPLOY_ACCOUNT,
520-
payload: {
521-
classHash,
522-
constructorCalldata: compiledCalldata,
523-
addressSalt,
524-
contractAddress,
525-
},
526-
},
527-
details
528-
));
564+
let suggestedMaxFee: BigNumberish = 0;
565+
let resourceBounds: ResourceBounds = estimateFeeToBounds(ZERO);
566+
if (version === ETransactionVersion.V3) {
567+
resourceBounds =
568+
details.resourceBounds ??
569+
(
570+
await this.getSuggestedFee(
571+
{
572+
type: TransactionType.DEPLOY_ACCOUNT,
573+
payload: {
574+
classHash,
575+
constructorCalldata: compiledCalldata,
576+
addressSalt,
577+
contractAddress,
578+
},
579+
},
580+
details
581+
)
582+
).resourceBounds;
583+
} else {
584+
suggestedMaxFee =
585+
details.maxFee ??
586+
(
587+
await this.getSuggestedFee(
588+
{
589+
type: TransactionType.DEPLOY_ACCOUNT,
590+
payload: {
591+
classHash,
592+
constructorCalldata: compiledCalldata,
593+
addressSalt,
594+
contractAddress,
595+
},
596+
},
597+
details
598+
)
599+
).suggestedMaxFee;
600+
}
529601

530602
const signature = await this.signer.signDeployAccountTransaction({
531603
...v3Details(details),
@@ -534,7 +606,8 @@ export class Account extends Provider implements AccountInterface {
534606
contractAddress,
535607
addressSalt,
536608
chainId,
537-
maxFee,
609+
resourceBounds,
610+
maxFee: suggestedMaxFee,
538611
version,
539612
nonce,
540613
});
@@ -544,7 +617,8 @@ export class Account extends Provider implements AccountInterface {
544617
{
545618
...v3Details(details),
546619
nonce,
547-
maxFee,
620+
resourceBounds,
621+
maxFee: suggestedMaxFee,
548622
version,
549623
}
550624
);
@@ -579,10 +653,7 @@ export class Account extends Provider implements AccountInterface {
579653
return this.verifyMessageHash(hash, signature);
580654
}
581655

582-
public async getSuggestedMaxFee(
583-
{ type, payload }: EstimateFeeAction,
584-
details: EstimateFeeDetails
585-
) {
656+
public async getSuggestedFee({ type, payload }: EstimateFeeAction, details: EstimateFeeDetails) {
586657
let feeEstimate: EstimateFee;
587658

588659
switch (type) {
@@ -611,7 +682,7 @@ export class Account extends Provider implements AccountInterface {
611682
break;
612683
}
613684

614-
return feeEstimate.suggestedMaxFee;
685+
return feeEstimate;
615686
}
616687

617688
/**

src/account/interface.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
DeployAccountContractPayload,
1515
DeployContractResponse,
1616
DeployContractUDCResponse,
17+
EstimateFee,
1718
EstimateFeeAction,
1819
EstimateFeeDetails,
1920
EstimateFeeResponse,
@@ -166,7 +167,7 @@ export abstract class AccountInterface extends ProviderInterface {
166167
* @param details -
167168
* - [nonce=getNonce]
168169
* - [version=transactionVersion]
169-
* - [maxFee=getSuggestedMaxFee]
170+
* - [maxFee=getSuggestedFee]
170171
* @returns
171172
* - contract_address[]
172173
* - transaction_hash
@@ -188,7 +189,7 @@ export abstract class AccountInterface extends ProviderInterface {
188189
* @param details -
189190
* - [nonce=getNonce]
190191
* - [version=transactionVersion]
191-
* - [maxFee=getSuggestedMaxFee]
192+
* - [maxFee=getSuggestedFee]
192193
* @returns
193194
* - contract_address
194195
* - transaction_hash
@@ -221,7 +222,7 @@ export abstract class AccountInterface extends ProviderInterface {
221222
* @param details
222223
* - [nonce=getNonce]
223224
* - [version=transactionVersion]
224-
* - [maxFee=getSuggestedMaxFee]
225+
* - [maxFee=getSuggestedFee]
225226
* @returns
226227
* - declare
227228
* - transaction_hash
@@ -316,10 +317,10 @@ export abstract class AccountInterface extends ProviderInterface {
316317
* @param {EstimateFeeDetails} details
317318
* @returns suggestedMaxFee
318319
*/
319-
public abstract getSuggestedMaxFee(
320+
public abstract getSuggestedFee(
320321
estimateFeeAction: EstimateFeeAction,
321322
details: EstimateFeeDetails
322-
): Promise<bigint>;
323+
): Promise<EstimateFee>;
323324

324325
/**
325326
* Simulates an array of transaction and returns an array of transaction trace and estimated fee.

src/channel/rpc_0_6.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export class RpcChannel {
362362

363363
public async getEstimateFee(
364364
invocations: AccountInvocations,
365-
{ blockIdentifier = this.blockIdentifier, skipValidate = false }: getEstimateFeeBulkOptions
365+
{ blockIdentifier = this.blockIdentifier, skipValidate = true }: getEstimateFeeBulkOptions
366366
) {
367367
const block_id = new Block(blockIdentifier).identifier;
368368
let flags = {};

src/types/account.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface EstimateFeeDetails {
2626
nonceDataAvailabilityMode?: EDataAvailabilityMode;
2727
feeDataAvailabilityMode?: EDataAvailabilityMode;
2828
version?: BigNumberish; // TODO: this is BigNumberish for interoperability with InvocationsDetails
29+
resourceBounds?: ResourceBounds; // TODO: required for non estimate and for estimate is 00
30+
skipValidate?: boolean; // TODO: Specific only to estimatFee methods
2931
}
3032

3133
export interface DeployContractResponse {

0 commit comments

Comments
 (0)