Skip to content

Commit

Permalink
feat: skipValidate full impl
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Mar 29, 2023
1 parent 3e832a7 commit 8b20e2e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
20 changes: 12 additions & 8 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Account extends Provider implements AccountInterface {

public async estimateInvokeFee(
calls: AllowArray<Call>,
{ nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
{ nonce: providedNonce, blockIdentifier, skipValidate }: EstimateFeeDetails = {}
): Promise<EstimateFee> {
const transactions = Array.isArray(calls) ? calls : [calls];
const nonce = toBigInt(providedNonce ?? (await this.getNonce()));
Expand All @@ -98,7 +98,8 @@ export class Account extends Provider implements AccountInterface {
const response = await super.getInvokeEstimateFee(
{ ...invocation },
{ version, nonce },
blockIdentifier
blockIdentifier,
skipValidate
);

const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
Expand All @@ -111,7 +112,7 @@ export class Account extends Provider implements AccountInterface {

public async estimateDeclareFee(
{ contract, classHash: providedClassHash, casm, compiledClassHash }: DeclareContractPayload,
{ blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
{ blockIdentifier, nonce: providedNonce, skipValidate }: EstimateFeeDetails = {}
): Promise<EstimateFee> {
const nonce = toBigInt(providedNonce ?? (await this.getNonce()));
const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2;
Expand All @@ -125,7 +126,8 @@ export class Account extends Provider implements AccountInterface {
const response = await super.getDeclareEstimateFee(
declareContractTransaction,
{ version, nonce },
blockIdentifier
blockIdentifier,
skipValidate
);
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);

Expand All @@ -142,7 +144,7 @@ export class Account extends Provider implements AccountInterface {
constructorCalldata = [],
contractAddress: providedContractAddress,
}: DeployAccountContractPayload,
{ blockIdentifier }: EstimateFeeDetails = {}
{ blockIdentifier, skipValidate }: EstimateFeeDetails = {}
): Promise<EstimateFee> {
const version = toBigInt(feeTransactionVersion);
const nonce = ZERO; // DEPLOY_ACCOUNT transaction will have a nonce zero as it is the first transaction in the account
Expand All @@ -156,7 +158,8 @@ export class Account extends Provider implements AccountInterface {
const response = await super.getDeployAccountEstimateFee(
{ ...payload },
{ version, nonce },
blockIdentifier
blockIdentifier,
skipValidate
);
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);

Expand Down Expand Up @@ -600,7 +603,7 @@ export class Account extends Provider implements AccountInterface {

public async simulateTransaction(
calls: AllowArray<Call>,
{ nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
{ nonce: providedNonce, blockIdentifier, skipValidate }: EstimateFeeDetails = {}
): Promise<TransactionSimulation> {
const transactions = Array.isArray(calls) ? calls : [calls];
const nonce = toBigInt(providedNonce ?? (await this.getNonce()));
Expand All @@ -619,7 +622,8 @@ export class Account extends Provider implements AccountInterface {
const response = await super.getSimulateTransaction(
invocation,
{ version, nonce },
blockIdentifier
blockIdentifier,
skipValidate
);

const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
Expand Down
31 changes: 23 additions & 8 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ export class Provider implements ProviderInterface {
public async getInvokeEstimateFee(
invocationWithTxType: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse> {
return this.provider.getInvokeEstimateFee(
invocationWithTxType,
invocationDetails,
blockIdentifier
blockIdentifier,
skipValidate
);
}

Expand Down Expand Up @@ -168,17 +170,24 @@ export class Provider implements ProviderInterface {
public async getDeclareEstimateFee(
transaction: DeclareContractTransaction,
details: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse> {
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier);
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
}

public getDeployAccountEstimateFee(
transaction: DeployAccountContractTransaction,
details: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse> {
return this.provider.getDeployAccountEstimateFee(transaction, details, blockIdentifier);
return this.provider.getDeployAccountEstimateFee(
transaction,
details,
blockIdentifier,
skipValidate
);
}

public async getCode(
Expand All @@ -198,9 +207,15 @@ export class Provider implements ProviderInterface {
public async getSimulateTransaction(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<TransactionSimulationResponse> {
return this.provider.getSimulateTransaction(invocation, invocationDetails, blockIdentifier);
return this.provider.getSimulateTransaction(
invocation,
invocationDetails,
blockIdentifier,
skipValidate
);
}

public async getStateUpdate(blockIdentifier?: BlockIdentifier): Promise<StateUpdateResponse> {
Expand Down
18 changes: 12 additions & 6 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ export abstract class ProviderInterface {
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
* - signature - (defaults to []) the signature
* @param blockIdentifier - block identifier
* @param details - optional details containing:
* - nonce - optional nonce
* - version - optional version
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the estimated fee
*/
public abstract getEstimateFee(
Expand All @@ -220,10 +221,11 @@ export abstract class ProviderInterface {
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
* - signature - (defaults to []) the signature
* @param blockIdentifier - block identifier
* @param details - optional details containing:
* - nonce - optional nonce
* - version - optional version
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the estimated fee
*/
public abstract getInvokeEstimateFee(
Expand All @@ -244,7 +246,8 @@ export abstract class ProviderInterface {
* - nonce
* - version - optional version
* - optional maxFee
* @param blockIdentifier - block identifier
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the estimated fee
*/
public abstract getDeclareEstimateFee(
Expand All @@ -266,7 +269,8 @@ export abstract class ProviderInterface {
* - nonce
* - version - optional version
* - optional maxFee
* @param blockIdentifier - block identifier
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the estimated fee
*/
public abstract getDeployAccountEstimateFee(
Expand Down Expand Up @@ -315,13 +319,15 @@ export abstract class ProviderInterface {
* @param details - optional details containing:
* - nonce - optional nonce
* - version - optional version
* @param blockIdentifier - block identifier
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the transaction trace and estimated fee
*/
public abstract getSimulateTransaction(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<TransactionSimulationResponse>;

/**
Expand Down
5 changes: 3 additions & 2 deletions src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,12 @@ export class SequencerProvider implements ProviderInterface {
public async getSimulateTransaction(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier = this.blockIdentifier
blockIdentifier: BlockIdentifier = this.blockIdentifier,
skipValidate: boolean = false
): Promise<TransactionSimulationResponse> {
return this.fetchEndpoint(
'simulate_transaction',
{ blockIdentifier },
{ blockIdentifier, skipValidate },
{
type: 'INVOKE_FUNCTION',
sender_address: invocation.contractAddress,
Expand Down
1 change: 1 addition & 0 deletions src/types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type EstimateFeeBulk = Array<EstimateFee>;
export interface EstimateFeeDetails {
nonce?: BigNumberish;
blockIdentifier?: BlockIdentifier;
skipValidate?: boolean;
}

export interface DeployContractResponse {
Expand Down
1 change: 1 addition & 0 deletions src/types/api/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ export namespace Sequencer {
simulate_transaction: {
QUERY: {
blockIdentifier: BlockIdentifier;
skipValidate: boolean;
};
REQUEST: SimulateTransaction;
RESPONSE: TransactionSimulationResponse;
Expand Down

0 comments on commit 8b20e2e

Please sign in to comment.