-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-chain-public-actions-decorator' into add-chain-publ…
…ic-actions-setter
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Address } from 'viem'; | ||
import { Prettify } from './utils'; | ||
|
||
type RemoveUndefinedArgs<T> = T extends { args?: undefined } ? Omit<T, 'args'> : T; | ||
|
||
/** | ||
* If the function has no args, `GetFunctionArgs` returns `{ args?: undefined }` | ||
* we remove args from the returned type | ||
* | ||
* Contract address is required if no contract address was passed to the actions, otherwise it's optional | ||
*/ | ||
export type WithContractAddress< | ||
Args, | ||
ContractName extends string, | ||
Curried extends boolean = false, | ||
> = Prettify< | ||
RemoveUndefinedArgs< | ||
Args & | ||
(Curried extends true | ||
? { | ||
[key in ContractName]?: Address; | ||
} | ||
: { [key in ContractName]: Address }) | ||
> | ||
>; | ||
|
||
/** | ||
* Actions require contract address, but as part of decorators, the address might have been passed already to the decorator. | ||
* | ||
* If the address was passed to the decorator, it's now optional (we still allow overrides of the address per action). | ||
* If the action doesn't have any other parameters beside the contract address, then parameters can either be { contract: address } or void | ||
*/ | ||
export type ActionParameters<Args, ContractName extends string, Curried extends boolean> = Prettify< | ||
Curried extends false | ||
? RemoveUndefinedArgs<Args & { sequencerInbox: Address }> | ||
: Args extends { args?: undefined } | ||
? | ||
| { | ||
[key in ContractName]: Address; | ||
} | ||
| void | ||
: Args & { | ||
[key in ContractName]?: Address; | ||
} | ||
>; |