Skip to content

Commit

Permalink
Add named inputs/outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Jun 24, 2024
1 parent 865dc20 commit ef58ede
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
35 changes: 19 additions & 16 deletions src/actions/getMaxTimeVariation.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
import { Chain, GetFunctionArgs, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { Address, Chain, PublicClient, Transport } from 'viem';
import { sequencerInbox } from '../contracts';
import { ActionParameters, WithContractAddress } from '../types/Actions';
import { ActionParameters } from '../types/Actions';

type Args = GetFunctionArgs<SequencerInboxABI, 'maxTimeVariation'>;
type SequencerInboxABI = typeof sequencerInbox.abi;
type GetMaxTimeVariationParameters<Curried extends boolean = false> = WithContractAddress<
Args,
'sequencerInbox',
Curried
>;
export type GetMaxTimeVariationActionParameters<Curried extends boolean> = ActionParameters<
Args,
{},
'sequencerInbox',
Curried
>;

export type GetMaxTimeVariationReturnType = ReadContractReturnType<
SequencerInboxABI,
'maxTimeVariation'
>;
export type GetMaxTimeVariationReturnType = {
delayBlocks: bigint;
futureBlocks: bigint;
delaySeconds: bigint;
futureSeconds: bigint;
};

export async function getMaxTimeVariation<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: GetMaxTimeVariationParameters,
args: {
sequencerInbox: Address;
},
): Promise<GetMaxTimeVariationReturnType> {
return client.readContract({
const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({
abi: sequencerInbox.abi,
functionName: 'maxTimeVariation',
address: args.sequencerInbox,
});
return {
delayBlocks,
futureBlocks,
delaySeconds,
futureSeconds,
};
}
8 changes: 5 additions & 3 deletions src/actions/isBatchPoster.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Chain, GetFunctionArgs, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { Address, Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { sequencerInbox } from '../contracts';
import { ActionParameters, WithContractAddress } from '../types/Actions';

type Args = GetFunctionArgs<SequencerInboxABI, 'isBatchPoster'>;
type Args = {
batchPoster: Address;
};
type SequencerInboxABI = typeof sequencerInbox.abi;
type IsBatchPosterParameters<Curried extends boolean = false> = WithContractAddress<
Args,
Expand All @@ -25,6 +27,6 @@ export async function isBatchPoster<TChain extends Chain | undefined>(
abi: sequencerInbox.abi,
functionName: 'isBatchPoster',
address: args.sequencerInbox,
args: args.args,
args: [args.batchPoster],
});
}
8 changes: 5 additions & 3 deletions src/actions/isValidKeysetHash.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Chain, GetFunctionArgs, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { Chain, Hex, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { sequencerInbox } from '../contracts';
import { ActionParameters, WithContractAddress } from '../types/Actions';

type Args = GetFunctionArgs<SequencerInboxABI, 'isValidKeysetHash'>;
type Args = {
keysetHash: Hex;
};
type SequencerInboxABI = typeof sequencerInbox.abi;
type IsValidKeysetHashParameters<Curried extends boolean = false> = WithContractAddress<
Args,
Expand All @@ -28,6 +30,6 @@ export async function isValidKeysetHash<TChain extends Chain | undefined>(
abi: sequencerInbox.abi,
functionName: 'isValidKeysetHash',
address: args.sequencerInbox,
args: args.args,
args: [args.keysetHash],
});
}

0 comments on commit ef58ede

Please sign in to comment.