-
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.
Feat: Add v1 RollupAdminLogic setters
- Loading branch information
1 parent
2f33e44
commit 6548a84
Showing
9 changed files
with
336 additions
and
5 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,43 @@ | ||
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { rollupABI } from '../contracts/Rollup'; | ||
import { | ||
WithAccount, | ||
ActionParameters, | ||
WithUpgradeExecutor, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { getRollupAddress } from '../getRollupAddress'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildSetConfirmPeriodBlocksParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor< | ||
WithAccount<ActionParameters<{ newPeriod: bigint }, 'rollupAdminLogic', Curried>> | ||
> | ||
>; | ||
|
||
export type BuildSetConfirmPeriodBlocksReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildSetConfirmPeriodBlocks<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
{ params, account, upgradeExecutor, ...args }: BuildSetConfirmPeriodBlocksParameters, | ||
): Promise<BuildSetConfirmPeriodBlocksReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const rollupAdminLogicAddress = | ||
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain as Chain | undefined, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: rollupAdminLogicAddress, | ||
upgradeExecutor, | ||
args: [params.newPeriod], | ||
abi: rollupABI, | ||
functionName: 'setConfirmPeriodBlocks', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} |
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,44 @@ | ||
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { rollupABI } from '../contracts/Rollup'; | ||
import { | ||
WithAccount, | ||
ActionParameters, | ||
WithUpgradeExecutor, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { getRollupAddress } from '../getRollupAddress'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildSetExtraChallengeTimeBlocksParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor< | ||
WithAccount<ActionParameters<{ newExtraTimeBlocks: bigint }, 'rollupAdminLogic', Curried>> | ||
> | ||
>; | ||
|
||
export type BuildSetExtraChallengeTimeBlocksReturnType = | ||
PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildSetExtraChallengeTimeBlocks<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
{ params, account, upgradeExecutor, ...args }: BuildSetExtraChallengeTimeBlocksParameters, | ||
): Promise<BuildSetExtraChallengeTimeBlocksReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const rollupAdminLogicAddress = | ||
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain as Chain | undefined, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: rollupAdminLogicAddress, | ||
upgradeExecutor, | ||
args: [params.newExtraTimeBlocks], | ||
abi: rollupABI, | ||
functionName: 'setExtraChallengeTimeBlocks', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} |
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,44 @@ | ||
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { rollupABI } from '../contracts/Rollup'; | ||
import { | ||
WithAccount, | ||
ActionParameters, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
WithUpgradeExecutor, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { getRollupAddress } from '../getRollupAddress'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildSetMinimumAssertionPeriodParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor< | ||
WithAccount<ActionParameters<{ newPeriod: bigint }, 'rollupAdminLogic', Curried>> | ||
> | ||
>; | ||
|
||
export type BuildSetMinimumAssertionPeriodReturnType = | ||
PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function setMinimumAssertionPeriod<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
{ params, account, upgradeExecutor, ...args }: BuildSetMinimumAssertionPeriodParameters, | ||
): Promise<BuildSetMinimumAssertionPeriodReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const rollupAdminLogicAddress = | ||
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain as Chain | undefined, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: rollupAdminLogicAddress, | ||
upgradeExecutor, | ||
args: [params.newPeriod], | ||
abi: rollupABI, | ||
functionName: 'setMinimumAssertionPeriod', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} |
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,56 @@ | ||
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { rollupABI } from '../contracts/Rollup'; | ||
import { | ||
WithAccount, | ||
ActionParameters, | ||
WithUpgradeExecutor, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { getRollupAddress } from '../getRollupAddress'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildSetIsValidatorParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
add: Address[]; | ||
remove: Address[]; | ||
}, | ||
'rollupAdminLogic', | ||
Curried | ||
> | ||
> | ||
> | ||
>; | ||
|
||
export type BuildSetIsValidatorReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildSetValidators<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
{ account, upgradeExecutor, params, ...args }: BuildSetIsValidatorParameters, | ||
): Promise<BuildSetIsValidatorReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const rollupAdminLogicAddress = | ||
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic; | ||
const { add: addressesToAdd, remove: addressesToRemove } = params; | ||
|
||
const addState: boolean[] = new Array(addressesToAdd.length).fill(true); | ||
const removeState: boolean[] = new Array(addressesToRemove.length).fill(false); | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain as Chain | undefined, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: rollupAdminLogicAddress, | ||
upgradeExecutor, | ||
args: [addressesToAdd.concat(addressesToRemove), addState.concat(removeState)], | ||
abi: rollupABI, | ||
functionName: 'setValidator', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} |
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,70 @@ | ||
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { rollupABI } from '../contracts/Rollup'; | ||
import { | ||
WithAccount, | ||
ActionParameters, | ||
WithUpgradeExecutor, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { getRollupAddress } from '../getRollupAddress'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildSetValidatorWhitelistDisabledParameters<Curried extends boolean = false> = | ||
Prettify<WithUpgradeExecutor<WithAccount<ActionParameters<{}, 'rollupAdminLogic', Curried>>>>; | ||
|
||
export type BuildSetValidatorWhitelistDisabledReturnType = | ||
PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildSetValidatorWhitelistDisabled<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
{ | ||
account, | ||
upgradeExecutor, | ||
params, | ||
...args | ||
}: BuildSetValidatorWhitelistDisabledParameters & { params: { enable: boolean } }, | ||
): Promise<BuildSetValidatorWhitelistDisabledReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const rollupAdminLogicAddress = | ||
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain as Chain | undefined, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: rollupAdminLogicAddress, | ||
upgradeExecutor, | ||
args: [params.enable], | ||
abi: rollupABI, | ||
functionName: 'setValidatorWhitelistDisabled', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} | ||
|
||
export async function buildEnableValidatorWhitelist<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
args: BuildSetValidatorWhitelistDisabledParameters, | ||
): Promise<BuildSetValidatorWhitelistDisabledReturnType> { | ||
return buildSetValidatorWhitelistDisabled(client, { | ||
...args, | ||
params: { | ||
enable: true, | ||
}, | ||
}); | ||
} | ||
|
||
export async function buildDisableValidatorWhitelist<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
args: BuildSetValidatorWhitelistDisabledParameters, | ||
): Promise<BuildSetValidatorWhitelistDisabledReturnType> { | ||
return buildSetValidatorWhitelistDisabled(client, { | ||
...args, | ||
params: { | ||
enable: false, | ||
}, | ||
}); | ||
} |
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,51 @@ | ||
import { Chain, Hex, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { rollupABI } from '../contracts/Rollup'; | ||
import { | ||
WithAccount, | ||
ActionParameters, | ||
WithUpgradeExecutor, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { getRollupAddress } from '../getRollupAddress'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildSetWasmModuleRootParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
newWasmModuleRoot: Hex; | ||
}, | ||
'rollupAdminLogic', | ||
Curried | ||
> | ||
> | ||
> | ||
>; | ||
|
||
export type BuildSetWasmModuleRootReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildSetWasmModuleRoot<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
{ account, upgradeExecutor, params, ...args }: BuildSetWasmModuleRootParameters, | ||
): Promise<BuildSetWasmModuleRootReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const rollupAdminLogicAddress = | ||
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain as Chain | undefined, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: rollupAdminLogicAddress, | ||
upgradeExecutor, | ||
args: [params.newWasmModuleRoot], | ||
abi: rollupABI, | ||
functionName: 'setWasmModuleRoot', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} |
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,22 @@ | ||
import { Address, Chain, PublicClient, Transport } from 'viem'; | ||
import { sequencerInboxABI } from './contracts/SequencerInbox'; | ||
|
||
const cache: Record<string, Address> = {}; | ||
export async function getRollupAddress<TChain extends Chain>( | ||
publicClient: PublicClient<Transport, TChain>, | ||
params: { sequencerInbox: Address }, | ||
): Promise<Address> { | ||
const addressFromCache = cache[`${publicClient.chain.id}_${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[`${publicClient.chain.id}_${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
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