Skip to content

Commit

Permalink
fix: add back getEstimateFee and estimateFee
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkelawala committed Oct 10, 2022
1 parent 421b9d7 commit bf7abca
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Abi,
Call,
DeclareContractResponse,
EstimateFeeResponse,
InvocationsDetails,
InvocationsSignerDetails,
InvokeFunctionResponse,
Expand Down Expand Up @@ -43,6 +44,13 @@ export class Account extends Provider implements AccountInterface {
return super.getNonce(this.address, blockIdentifier);
}

public async estimateFee(
calls: Call | Call[],
estimateFeeDetails?: EstimateFeeDetails | undefined
): Promise<EstimateFeeResponse> {
return this.estimateInvokeFee(calls, estimateFeeDetails);
}

public async estimateInvokeFee(
calls: Call | Call[],
{ nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
Expand Down Expand Up @@ -125,7 +133,7 @@ export class Account extends Provider implements AccountInterface {
): Promise<InvokeFunctionResponse> {
const transactions = Array.isArray(calls) ? calls : [calls];
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
let maxFee: BigNumberish = '0';
let maxFee: BigNumberish = ZERO;
if (transactionsDetail.maxFee || transactionsDetail.maxFee === 0) {
maxFee = transactionsDetail.maxFee;
} else {
Expand Down
19 changes: 17 additions & 2 deletions src/account/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,28 @@ export abstract class AccountInterface extends ProviderInterface {
public abstract signer: SignerInterface;

/**
* @deprecated Use estimateInvokeFee or estimateDeclareFee instead
* Estimate Fee for a method on starknet
*
* @param invocation the invocation object containing:
* @param calls the invocation object containing:
* - contractAddress - the address of the contract
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
*
* @returns response from addTransaction
*/
public abstract estimateFee(
calls: Call | Call[],
estimateFeeDetails?: EstimateFeeDetails
): Promise<EstimateFeeResponse>;

/**
* Estimate Fee for a method on starknet
*
* @param calls the invocation object containing:
* - contractAddress - the address of the contract
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
* - signature - (defaults to []) the signature
*
* @returns response from addTransaction
*/
Expand Down
8 changes: 8 additions & 0 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export class Provider implements ProviderInterface {
return this.provider.getClassAt(contractAddress, blockIdentifier);
}

public async getEstimateFee(
invocationWithTxType: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier = 'pending'
): Promise<EstimateFeeResponse> {
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
}

public async getInvokeEstimateFee(
invocationWithTxType: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
Expand Down
21 changes: 21 additions & 0 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ export abstract class ProviderInterface {
details: InvocationsDetailsWithNonce
): Promise<DeclareContractResponse>;

/**
* Estimates the fee for a given INVOKE transaction
* @deprecated Please use getInvokeEstimateFee or getDeclareEstimateFee instead
*
* @param invocation the invocation object containing:
* - contractAddress - the address of the contract
* - 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
* @returns the estimated fee
*/
public abstract getEstimateFee(
invocation: Invocation,
details: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier
): Promise<EstimateFeeResponse>;

/**
* Estimates the fee for a given INVOKE transaction
*
Expand Down
8 changes: 8 additions & 0 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ export class RpcProvider implements ProviderInterface {
throw new Error('RPC 0.1.0 does not implement getCode function');
}

public async getEstimateFee(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier = 'pending'
): Promise<EstimateFeeResponse> {
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
}

public async getInvokeEstimateFee(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
Expand Down
8 changes: 8 additions & 0 deletions src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ export class SequencerProvider implements ProviderInterface {
}).then(this.responseParser.parseDeclareContractResponse);
}

public async getEstimateFee(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier = 'pending'
): Promise<EstimateFeeResponse> {
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
}

public async getInvokeEstimateFee(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
Expand Down

0 comments on commit bf7abca

Please sign in to comment.