Skip to content

Commit

Permalink
Add WithContractAddress type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Jul 15, 2024
1 parent b517a5f commit 1466726
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/actions/getConfirmPeriodBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { rollupAdminLogic } from '../contracts';
import { ActionParameters } from '../types/Actions';
import { WithContractAddress } from '../types/Actions';
import { getRollupAddress } from '../getRollupAddress';

export type GetConfirmPeriodBlocksParameters<Curried extends boolean = false> = ActionParameters<
export type GetConfirmPeriodBlocksParameters<Curried extends boolean = false> = WithContractAddress<
{},
'rollupAdminLogic',
Curried
Expand Down
4 changes: 2 additions & 2 deletions src/actions/getExtraChallengeTimeBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { rollupAdminLogic } from '../contracts';
import { ActionParameters } from '../types/Actions';
import { WithContractAddress } from '../types/Actions';
import { getRollupAddress } from '../getRollupAddress';

export type GetExtraChallengeTimeBlocksParameters<Curried extends boolean = false> =
ActionParameters<{}, 'rollupAdminLogic', Curried>;
WithContractAddress<{}, 'rollupAdminLogic', Curried>;

export type GetExtraChallengeTimeBlocksReturnType = ReadContractReturnType<
typeof rollupAdminLogic.abi,
Expand Down
9 changes: 3 additions & 6 deletions src/actions/getMinimumAssertionPeriod.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { rollupAdminLogic } from '../contracts';
import { ActionParameters } from '../types/Actions';
import { WithContractAddress } from '../types/Actions';
import { getRollupAddress } from '../getRollupAddress';

export type GetMinimumAssertionPeriodParameters<Curried extends boolean = false> = ActionParameters<
{},
'rollupAdminLogic',
Curried
>;
export type GetMinimumAssertionPeriodParameters<Curried extends boolean = false> =
WithContractAddress<{}, 'rollupAdminLogic', Curried>;

export type GetMinimumAssertionPeriodReturnType = ReadContractReturnType<
typeof rollupAdminLogic.abi,
Expand Down
4 changes: 2 additions & 2 deletions src/actions/getWasmModuleRoot.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { rollupAdminLogic } from '../contracts';
import { ActionParameters } from '../types/Actions';
import { WithContractAddress } from '../types/Actions';
import { getRollupAddress } from '../getRollupAddress';

export type GetWasmModuleRootParameters<Curried extends boolean = false> = ActionParameters<
export type GetWasmModuleRootParameters<Curried extends boolean = false> = WithContractAddress<
{},
'rollupAdminLogic',
Curried
Expand Down
32 changes: 32 additions & 0 deletions src/types/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,35 @@ export type ActionParameters<Args, ContractName extends string, Curried extends
[key in ContractName]?: Address;
}
>;

/**
* Some actions require a different contract than sequencerInbox.
* We either accept sequencerInbox to fetch the contract address
* or an override
*/
export type WithContractAddress<
Args,
ContractName extends string,
Curried extends boolean,
> = Curried extends true
? /**
* If sequencerInbox was passed to the decorator. We accept the contract address,
* an sequencerInbox override, or no parameters
*/
| (Args & {
sequencerInbox?: Address;
})
| (Args & {
[key in ContractName]?: Address;
})
| void
: /**
* If sequencerInbox wasn't passed to the decorator. We need one of the address to be passed
* We either accept the contract address or an sequencerInbox override
*/
| (Args & {
sequencerInbox: Address;
})
| (Args & {
[key in ContractName]: Address;
});

0 comments on commit 1466726

Please sign in to comment.