-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
35 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
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
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
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
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
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 |
---|---|---|
@@ -1,19 +1,29 @@ | ||
import type { Chain } from 'viem' | ||
import { getChainContractAddress as _getChainContractAddress } from 'viem/utils' | ||
import type { ChainWithEns } from './consts.js' | ||
|
||
type ChainClient<TChain extends ChainWithEns> = { | ||
chain: TChain | ||
type ExtractContract<TClient> = TClient extends { | ||
chain: { contracts: infer C } | ||
} | ||
? C extends Record<string, { address: string }> | ||
? C | ||
: never | ||
: never | ||
|
||
export const getChainContractAddress = < | ||
TChain extends ChainWithEns, | ||
TClient extends ChainClient<TChain>, | ||
const TClient extends { chain: Chain }, | ||
TContracts extends ExtractContract<TClient> = ExtractContract<TClient>, | ||
TContract extends keyof TContracts = keyof TContracts, | ||
>({ | ||
blockNumber, | ||
client, | ||
contract, | ||
}: { | ||
blockNumber?: bigint | ||
client: TClient | ||
contract: Extract<keyof TChain['contracts'], string> | ||
}) => _getChainContractAddress({ blockNumber, chain: client.chain, contract }) | ||
contract: TContract | ||
}) => | ||
_getChainContractAddress({ | ||
blockNumber, | ||
chain: client.chain, | ||
contract: contract as string, | ||
}) as TContracts[TContract]['address'] |
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