-
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
Closes FS-621
- Loading branch information
1 parent
1808db7
commit a5dc412
Showing
6 changed files
with
303 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,48 @@ | ||
import { | ||
Chain, | ||
PrepareTransactionRequestParameters, | ||
PrepareTransactionRequestReturnType, | ||
PublicClient, | ||
Transport, | ||
encodeFunctionData, | ||
} from 'viem'; | ||
import { rollupAdminLogic } from '../contracts'; | ||
import { ActionParameters, WithAccount } from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
|
||
export type SetConfirmPeriodBlocksParameters<Curried extends boolean = false> = Prettify< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
newPeriod: bigint; | ||
}, | ||
'rollupAdminLogic', | ||
Curried | ||
> | ||
> | ||
>; | ||
|
||
export type SetConfirmPeriodBlocksReturnType = PrepareTransactionRequestReturnType; | ||
|
||
function rollupAdminLogicFunctionData({ newPeriod }: SetConfirmPeriodBlocksParameters) { | ||
return encodeFunctionData({ | ||
abi: rollupAdminLogic.abi, | ||
functionName: 'setConfirmPeriodBlocks', | ||
args: [newPeriod], | ||
}); | ||
} | ||
|
||
export async function setConfirmPeriodBlocks<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: SetConfirmPeriodBlocksParameters, | ||
): Promise<SetConfirmPeriodBlocksReturnType> { | ||
const data = rollupAdminLogicFunctionData(args); | ||
|
||
return client.prepareTransactionRequest({ | ||
to: args.rollupAdminLogic, | ||
value: BigInt(0), | ||
chain: client.chain, | ||
data, | ||
account: args.account, | ||
} satisfies PrepareTransactionRequestParameters); | ||
} |
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,50 @@ | ||
import { | ||
Chain, | ||
PrepareTransactionRequestParameters, | ||
PrepareTransactionRequestReturnType, | ||
PublicClient, | ||
Transport, | ||
encodeFunctionData, | ||
} from 'viem'; | ||
import { rollupAdminLogic } from '../contracts'; | ||
import { ActionParameters, WithAccount } from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
|
||
export type SetExtraChallengeTimeBlocksParameters<Curried extends boolean = false> = Prettify< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
newExtraTimeBlocks: bigint; | ||
}, | ||
'rollupAdminLogic', | ||
Curried | ||
> | ||
> | ||
>; | ||
|
||
export type SetExtraChallengeTimeBlocksReturnType = PrepareTransactionRequestReturnType; | ||
|
||
function rollupAdminLogicFunctionData({ | ||
newExtraTimeBlocks, | ||
}: SetExtraChallengeTimeBlocksParameters) { | ||
return encodeFunctionData({ | ||
abi: rollupAdminLogic.abi, | ||
functionName: 'setExtraChallengeTimeBlocks', | ||
args: [newExtraTimeBlocks], | ||
}); | ||
} | ||
|
||
export async function setExtraChallengeTimeBlocks<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: SetExtraChallengeTimeBlocksParameters, | ||
): Promise<SetExtraChallengeTimeBlocksReturnType> { | ||
const data = rollupAdminLogicFunctionData(args); | ||
|
||
return client.prepareTransactionRequest({ | ||
to: args.rollupAdminLogic, | ||
value: BigInt(0), | ||
chain: client.chain, | ||
data, | ||
account: args.account, | ||
} satisfies PrepareTransactionRequestParameters); | ||
} |
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,48 @@ | ||
import { | ||
Chain, | ||
PrepareTransactionRequestParameters, | ||
PrepareTransactionRequestReturnType, | ||
PublicClient, | ||
Transport, | ||
encodeFunctionData, | ||
} from 'viem'; | ||
import { rollupAdminLogic } from '../contracts'; | ||
import { ActionParameters, WithAccount } from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
|
||
export type SetMinimumAssertionPeriodParameters<Curried extends boolean = false> = Prettify< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
newPeriod: bigint; | ||
}, | ||
'rollupAdminLogic', | ||
Curried | ||
> | ||
> | ||
>; | ||
|
||
export type SetMinimumAssertionPeriodReturnType = PrepareTransactionRequestReturnType; | ||
|
||
function rollupAdminLogicFunctionData({ newPeriod }: SetMinimumAssertionPeriodParameters) { | ||
return encodeFunctionData({ | ||
abi: rollupAdminLogic.abi, | ||
functionName: 'setMinimumAssertionPeriod', | ||
args: [newPeriod], | ||
}); | ||
} | ||
|
||
export async function setMinimumAssertionPeriod<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: SetMinimumAssertionPeriodParameters, | ||
): Promise<SetMinimumAssertionPeriodReturnType> { | ||
const data = rollupAdminLogicFunctionData(args); | ||
|
||
return client.prepareTransactionRequest({ | ||
to: args.rollupAdminLogic, | ||
value: BigInt(0), | ||
chain: client.chain, | ||
data, | ||
account: args.account, | ||
} satisfies PrepareTransactionRequestParameters); | ||
} |
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,47 @@ | ||
import { | ||
Address, | ||
Chain, | ||
PrepareTransactionRequestParameters, | ||
PrepareTransactionRequestReturnType, | ||
PublicClient, | ||
Transport, | ||
encodeFunctionData, | ||
} from 'viem'; | ||
import { rollupAdminLogic } from '../contracts'; | ||
import { ActionParameters, WithAccount } from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
|
||
type Args = { | ||
add: Address[]; | ||
remove: Address[]; | ||
}; | ||
|
||
export type SetIsValidatorParameters<Curried extends boolean = false> = Prettify< | ||
WithAccount<ActionParameters<Args, 'rollupAdminLogic', Curried>> | ||
>; | ||
|
||
export type SetIsValidatorReturnType = PrepareTransactionRequestReturnType; | ||
|
||
function rollupAdminLogicFunctionData({ add, remove }: SetIsValidatorParameters) { | ||
const addState: boolean[] = new Array(add.length).fill(true); | ||
const removeState: boolean[] = new Array(remove.length).fill(false); | ||
return encodeFunctionData({ | ||
abi: rollupAdminLogic.abi, | ||
functionName: 'setValidator', | ||
args: [add.concat(remove), addState.concat(removeState)], | ||
}); | ||
} | ||
|
||
export async function setValidators<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: SetIsValidatorParameters, | ||
): Promise<SetIsValidatorReturnType> { | ||
const data = rollupAdminLogicFunctionData(args); | ||
return client.prepareTransactionRequest({ | ||
to: args.rollupAdminLogic, | ||
value: BigInt(0), | ||
chain: client.chain, | ||
data, | ||
account: args.account, | ||
} satisfies PrepareTransactionRequestParameters); | ||
} |
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,61 @@ | ||
import { | ||
Chain, | ||
PrepareTransactionRequestParameters, | ||
PrepareTransactionRequestReturnType, | ||
PublicClient, | ||
Transport, | ||
encodeFunctionData, | ||
} from 'viem'; | ||
import { rollupAdminLogic } from '../contracts'; | ||
import { ActionParameters, WithAccount } from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
|
||
export type SetValidatorWhitelistDisabledParameters<Curried extends boolean = false> = Prettify< | ||
WithAccount<ActionParameters<{}, 'rollupAdminLogic', Curried>> | ||
>; | ||
|
||
export type SetValidatorWhitelistDisabledReturnType = PrepareTransactionRequestReturnType; | ||
|
||
function rollupAdminLogicFunctionData({ | ||
enable, | ||
}: SetValidatorWhitelistDisabledParameters & { enable: boolean }) { | ||
return encodeFunctionData({ | ||
abi: rollupAdminLogic.abi, | ||
functionName: 'setValidatorWhitelistDisabled', | ||
args: [enable], | ||
}); | ||
} | ||
|
||
async function setValidatorWhitelistDisabled<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: SetValidatorWhitelistDisabledParameters & { enable: boolean }, | ||
): Promise<SetValidatorWhitelistDisabledReturnType> { | ||
const data = rollupAdminLogicFunctionData(args); | ||
return client.prepareTransactionRequest({ | ||
to: args.rollupAdminLogic, | ||
value: BigInt(0), | ||
chain: client.chain, | ||
data, | ||
account: args.account, | ||
} satisfies PrepareTransactionRequestParameters); | ||
} | ||
|
||
export async function enableValidatorWhitelist<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: SetValidatorWhitelistDisabledParameters, | ||
): Promise<SetValidatorWhitelistDisabledReturnType> { | ||
return setValidatorWhitelistDisabled(client, { | ||
...args, | ||
enable: true, | ||
}); | ||
} | ||
|
||
export async function disableValidatorWhitelist<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: SetValidatorWhitelistDisabledParameters, | ||
): Promise<SetValidatorWhitelistDisabledReturnType> { | ||
return setValidatorWhitelistDisabled(client, { | ||
...args, | ||
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,49 @@ | ||
import { | ||
Chain, | ||
Hex, | ||
PrepareTransactionRequestParameters, | ||
PrepareTransactionRequestReturnType, | ||
PublicClient, | ||
Transport, | ||
encodeFunctionData, | ||
} from 'viem'; | ||
import { rollupAdminLogic } from '../contracts'; | ||
import { ActionParameters, WithAccount } from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
|
||
export type SetWasmModuleRootParameters<Curried extends boolean = false> = Prettify< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
newWasmModuleRoot: Hex; | ||
}, | ||
'rollupAdminLogic', | ||
Curried | ||
> | ||
> | ||
>; | ||
|
||
export type SetWasmModuleRootReturnType = PrepareTransactionRequestReturnType; | ||
|
||
function rollupAdminLogicFunctionData({ newWasmModuleRoot }: SetWasmModuleRootParameters) { | ||
return encodeFunctionData({ | ||
abi: rollupAdminLogic.abi, | ||
functionName: 'setWasmModuleRoot', | ||
args: [newWasmModuleRoot], | ||
}); | ||
} | ||
|
||
export async function setWasmModuleRoot<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: SetWasmModuleRootParameters, | ||
): Promise<SetWasmModuleRootReturnType> { | ||
const data = rollupAdminLogicFunctionData(args); | ||
|
||
return client.prepareTransactionRequest({ | ||
to: args.rollupAdminLogic, | ||
value: BigInt(0), | ||
chain: client.chain, | ||
data, | ||
account: args.account, | ||
} satisfies PrepareTransactionRequestParameters); | ||
} |