-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch rollupAddress from sequencerInbox in getters
- Loading branch information
1 parent
f04abba
commit 221ecbf
Showing
7 changed files
with
86 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Address, Chain, PublicClient, Transport } from 'viem'; | ||
import { sequencerInboxABI } from './abi'; | ||
|
||
const cache: Record<Address, Address> = {}; | ||
export async function getRollupAddress<TChain extends Chain | undefined>( | ||
publicClient: PublicClient<Transport, TChain>, | ||
params: { sequencerInbox: Address } | { rollupAdminLogic: Address }, | ||
): Promise<Address> { | ||
// rollupAdminLogic was passed as an override, return directly | ||
if ('rollupAdminLogic' in params) { | ||
return params.rollupAdminLogic; | ||
} | ||
|
||
const addressFromCache = cache[params.sequencerInbox]; | ||
if (addressFromCache) { | ||
return addressFromCache; | ||
} | ||
|
||
// Otherwise, fetch the rollup address from sequencerInbox contract | ||
const rollupAddress = await publicClient.readContract({ | ||
functionName: 'rollup', | ||
address: params.sequencerInbox, | ||
abi: sequencerInboxABI, | ||
}); | ||
cache[params.sequencerInbox] = rollupAddress; | ||
return rollupAddress; | ||
} |
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