Skip to content

Commit

Permalink
feat(provider): preparation for the fee integration
Browse files Browse the repository at this point in the history
  • Loading branch information
MilGard91 committed Mar 8, 2022
1 parent 570d1c2 commit c1c231b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class Provider implements ProviderInterface {
}

private getFetchMethod(endpoint: keyof Endpoints) {
const postMethodEndpoints = ['add_transaction', 'call_contract'];
const postMethodEndpoints = ['add_transaction', 'call_contract', 'estimate_fee'];

return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
}
Expand Down Expand Up @@ -333,6 +333,17 @@ export class Provider implements ProviderInterface {
});
}

public estimateFee(invocation: Invocation): Promise<any> {
return this.fetchEndpoint('estimate_fee', undefined, {
// TODO: change the TYPE of the call
type: 'INVOKE_FUNCTION',
contract_address: invocation.contractAddress,
entry_point_selector: getSelectorFromName(invocation.entrypoint),
calldata: bigNumberishArrayToDecimalStringArray(invocation.calldata ?? []),
signature: bigNumberishArrayToDecimalStringArray(invocation.signature ?? []),
});
}

public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
let onchain = false;
await wait(retryInterval);
Expand Down
7 changes: 7 additions & 0 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export type Endpoints = {
REQUEST: CallContractTransaction;
RESPONSE: CallContractResponse;
};
estimate_fee: {
QUERY: never;
REQUEST: Transaction;
RESPONSE: EstimateFeeResponse;
};
};

export type GetContractAddressesResponse = {
Expand Down Expand Up @@ -168,6 +173,8 @@ export type TransactionReceipt = {
l2_to_l1_messages: string[];
events: string[];
};
// TODO: Add response data
export type EstimateFeeResponse = {};

export type RawArgs = {
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
Expand Down
4 changes: 4 additions & 0 deletions src/types/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ export type CompiledContract = {
export type CompressedCompiledContract = Omit<CompiledContract, 'program'> & {
program: CompressedProgram;
};

export type ParsedStruct = {
[key: string]: BigNumberish | ParsedStruct;
};
3 changes: 1 addition & 2 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ParsedStruct } from '../contract';
import { Call } from '../types';
import { Call, ParsedStruct } from '../types';
import { getSelectorFromName } from './hash';
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN } from './number';

Expand Down

0 comments on commit c1c231b

Please sign in to comment.