Skip to content

Commit

Permalink
feat: Add v1 arbOwnerPublic setters
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Sep 24, 2024
1 parent 2f33e44 commit 2d2793b
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 4 deletions.
42 changes: 42 additions & 0 deletions src/actions/buildAddChainOwner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
import {
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';

export type BuildAddChainOwnerParameters = Prettify<
WithUpgradeExecutor<
WithAccount<{
params: {
newOwner: Address;
};
}>
>
>;
export type BuildAddChainOwnerReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildAddChainOwner<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params }: BuildAddChainOwnerParameters,
): Promise<BuildAddChainOwnerReturnType> {
const validatedPublicClient = validateChildChainPublicClient(client);

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: arbOwnerAddress,
upgradeExecutor,
args: [params.newOwner],
abi: arbOwnerABI,
functionName: 'addChainOwner',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
41 changes: 41 additions & 0 deletions src/actions/buildRemoveChainOwner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
import {
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildRemoveChainOwnerParameters = Prettify<
WithUpgradeExecutor<
WithAccount<{
params: { owner: Address };
}>
>
>;

export type BuildRemoveChainOwnerReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildRemoveChainOwner<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params }: BuildRemoveChainOwnerParameters,
): Promise<BuildRemoveChainOwnerReturnType> {
const validatedPublicClient = validateChildChainPublicClient(client);

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: arbOwnerAddress,
upgradeExecutor,
args: [params.owner],
abi: arbOwnerABI,
functionName: 'removeChainOwner',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
41 changes: 41 additions & 0 deletions src/actions/buildSetMaxTxGasLimit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
import {
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetMaxTxGasLimitParameters = Prettify<
WithUpgradeExecutor<
WithAccount<{
params: { limit: bigint };
}>
>
>;

export type BuildSetMaxTxGasLimitReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetMaxTxGasLimit<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params }: BuildSetMaxTxGasLimitParameters,
): Promise<BuildSetMaxTxGasLimitReturnType> {
const validatedPublicClient = validateChildChainPublicClient(client);

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: arbOwnerAddress,
upgradeExecutor,
args: [params.limit],
abi: arbOwnerABI,
functionName: 'setMaxTxGasLimit',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
41 changes: 41 additions & 0 deletions src/actions/buildSetParentPricePerUnit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
import {
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';

export type BuildSetParentPricePerUnitParameters = Prettify<
WithUpgradeExecutor<
WithAccount<{
params: { pricePerUnit: bigint };
}>
>
>;

export type BuildSetParentPricePerUnitReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetParentPricePerUnit<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params }: BuildSetParentPricePerUnitParameters,
): Promise<BuildSetParentPricePerUnitReturnType> {
const validatedPublicClient = validateChildChainPublicClient(client);

const request = await client.prepareTransactionRequest({
chain: validatedPublicClient.chain,
account,
...prepareUpgradeExecutorCallParameters({
to: arbOwnerAddress,
upgradeExecutor,
args: [params.pricePerUnit],
abi: arbOwnerABI,
functionName: 'setL1PricePerUnit',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
42 changes: 42 additions & 0 deletions src/actions/buildSetParentPricingRewardRate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
import {
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetParentPricingRewardRateParameters = Prettify<
WithUpgradeExecutor<
WithAccount<{
params: { weiPerUnit: bigint };
}>
>
>;

export type BuildSetParentPricingRewardRateReturnType =
PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetParentPricingRewardRate<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params }: BuildSetParentPricingRewardRateParameters,
): Promise<BuildSetParentPricingRewardRateReturnType> {
const validatedPublicClient = validateChildChainPublicClient(client);

const request = await client.prepareTransactionRequest({
chain: client.chain,
account,
...prepareUpgradeExecutorCallParameters({
to: arbOwnerAddress,
upgradeExecutor,
args: [params.weiPerUnit],
abi: arbOwnerABI,
functionName: 'setL1PricingRewardRate',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
42 changes: 42 additions & 0 deletions src/actions/buildSetParentPricingRewardRecipient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
import {
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetParentPricingRewardRecipientParameters = Prettify<
WithUpgradeExecutor<
WithAccount<{
params: { recipient: Address };
}>
>
>;

export type BuildSetParentPricingRewardRecipientReturnType =
PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetParentPricingRewardRecipient<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params }: BuildSetParentPricingRewardRecipientParameters,
): Promise<BuildSetParentPricingRewardRecipientReturnType> {
const validatedPublicClient = validateChildChainPublicClient(client);

const request = await client.prepareTransactionRequest({
chain: client.chain,
account,
...prepareUpgradeExecutorCallParameters({
to: arbOwnerAddress,
upgradeExecutor,
args: [params.recipient],
abi: arbOwnerABI,
functionName: 'setL1PricingRewardRecipient',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
41 changes: 41 additions & 0 deletions src/actions/buildSetSpeedLimit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
import {
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';

export type BuildSetSpeedLimitParameters = Prettify<
WithUpgradeExecutor<
WithAccount<{
params: { limit: bigint };
}>
>
>;

export type BuildSetSpeedLimitReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetSpeedLimit<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params }: BuildSetSpeedLimitParameters,
): Promise<BuildSetSpeedLimitReturnType> {
const validatedPublicClient = validateChildChainPublicClient(client);

const request = await client.prepareTransactionRequest({
chain: client.chain,
account,
...prepareUpgradeExecutorCallParameters({
to: arbOwnerAddress,
upgradeExecutor,
args: [params.limit],
abi: arbOwnerABI,
functionName: 'setSpeedLimit',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
8 changes: 4 additions & 4 deletions src/types/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type isEmptyObject<Args> = Args extends Record<string, never> ? true : false;
export type ActionParameters<Args, ContractName extends string, Curried extends boolean> = Prettify<
Curried extends false
? isEmptyObject<Args> extends true
? { [key in ContractName]: Address } // Contract wasn't curried. Args is an empty object. Only requires the contract name
: { params: Args } & { [key in ContractName]: Address } // Contract wasn't curried. Args is not empty. Requires both params and contract name
? { [key in ContractName]: Address } | { sequencerInbox: Address } // Contract wasn't curried. Args is an empty object. Only requires the contract name
: { params: Args } & ({ [key in ContractName]: Address } | { sequencerInbox: Address }) // Contract wasn't curried. Args is not empty. Requires both params and contract name
: isEmptyObject<Args> extends true
? { [key in ContractName]: Address } | void // Contract was curried. Args is empty. Only requires the contract name. Allows no parameters
: { params: Args } & { [key in ContractName]?: Address } // Contract was curried. Args is not empty. Requires params, contract name is optional
? { [key in ContractName]: Address } | { sequencerInbox: Address } | void // Contract was curried. Args is empty. Only requires the contract name. Allows no parameters
: { params: Args } & ({ [key in ContractName]?: Address } | { sequencerInbox?: Address }) // Contract was curried. Args is not empty. Requires params, contract name is optional
>;

export type WithAccount<Args> = Args & {
Expand Down
16 changes: 16 additions & 0 deletions src/types/validateChildChainPublicClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Chain, PublicClient, Transport } from 'viem';
import { Prettify } from './utils';

export type ChildChainPublicClient<TChain extends Chain | undefined> = Prettify<
PublicClient<Transport, TChain> & { chain: NonNullable<TChain> }
>;

export function validateChildChainPublicClient<TChain extends Chain | undefined>(
publicClient: PublicClient<Transport, TChain>,
): ChildChainPublicClient<TChain> {
if (!publicClient.chain) {
throw new Error('client.chain is undefined');
}

return publicClient as ChildChainPublicClient<TChain>;
}

0 comments on commit 2d2793b

Please sign in to comment.