Skip to content

Commit 2d2793b

Browse files
committed
feat: Add v1 arbOwnerPublic setters
1 parent 2f33e44 commit 2d2793b

9 files changed

+310
-4
lines changed

src/actions/buildAddChainOwner.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
2+
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
3+
import {
4+
PrepareTransactionRequestReturnTypeWithChainId,
5+
WithAccount,
6+
WithUpgradeExecutor,
7+
} from '../types/Actions';
8+
import { Prettify } from '../types/utils';
9+
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
10+
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
11+
12+
export type BuildAddChainOwnerParameters = Prettify<
13+
WithUpgradeExecutor<
14+
WithAccount<{
15+
params: {
16+
newOwner: Address;
17+
};
18+
}>
19+
>
20+
>;
21+
export type BuildAddChainOwnerReturnType = PrepareTransactionRequestReturnTypeWithChainId;
22+
23+
export async function buildAddChainOwner<TChain extends Chain>(
24+
client: PublicClient<Transport, TChain>,
25+
{ account, upgradeExecutor, params }: BuildAddChainOwnerParameters,
26+
): Promise<BuildAddChainOwnerReturnType> {
27+
const validatedPublicClient = validateChildChainPublicClient(client);
28+
29+
const request = await client.prepareTransactionRequest({
30+
chain: client.chain as Chain | undefined,
31+
account,
32+
...prepareUpgradeExecutorCallParameters({
33+
to: arbOwnerAddress,
34+
upgradeExecutor,
35+
args: [params.newOwner],
36+
abi: arbOwnerABI,
37+
functionName: 'addChainOwner',
38+
}),
39+
} satisfies PrepareTransactionRequestParameters);
40+
41+
return { ...request, chainId: validatedPublicClient.chain.id };
42+
}

src/actions/buildRemoveChainOwner.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
2+
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
3+
import {
4+
PrepareTransactionRequestReturnTypeWithChainId,
5+
WithAccount,
6+
WithUpgradeExecutor,
7+
} from '../types/Actions';
8+
import { Prettify } from '../types/utils';
9+
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
10+
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
11+
12+
export type BuildRemoveChainOwnerParameters = Prettify<
13+
WithUpgradeExecutor<
14+
WithAccount<{
15+
params: { owner: Address };
16+
}>
17+
>
18+
>;
19+
20+
export type BuildRemoveChainOwnerReturnType = PrepareTransactionRequestReturnTypeWithChainId;
21+
22+
export async function buildRemoveChainOwner<TChain extends Chain>(
23+
client: PublicClient<Transport, TChain>,
24+
{ account, upgradeExecutor, params }: BuildRemoveChainOwnerParameters,
25+
): Promise<BuildRemoveChainOwnerReturnType> {
26+
const validatedPublicClient = validateChildChainPublicClient(client);
27+
28+
const request = await client.prepareTransactionRequest({
29+
chain: client.chain as Chain | undefined,
30+
account,
31+
...prepareUpgradeExecutorCallParameters({
32+
to: arbOwnerAddress,
33+
upgradeExecutor,
34+
args: [params.owner],
35+
abi: arbOwnerABI,
36+
functionName: 'removeChainOwner',
37+
}),
38+
} satisfies PrepareTransactionRequestParameters);
39+
40+
return { ...request, chainId: validatedPublicClient.chain.id };
41+
}

src/actions/buildSetMaxTxGasLimit.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
2+
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
3+
import {
4+
PrepareTransactionRequestReturnTypeWithChainId,
5+
WithAccount,
6+
WithUpgradeExecutor,
7+
} from '../types/Actions';
8+
import { Prettify } from '../types/utils';
9+
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
10+
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
11+
12+
export type BuildSetMaxTxGasLimitParameters = Prettify<
13+
WithUpgradeExecutor<
14+
WithAccount<{
15+
params: { limit: bigint };
16+
}>
17+
>
18+
>;
19+
20+
export type BuildSetMaxTxGasLimitReturnType = PrepareTransactionRequestReturnTypeWithChainId;
21+
22+
export async function buildSetMaxTxGasLimit<TChain extends Chain>(
23+
client: PublicClient<Transport, TChain>,
24+
{ account, upgradeExecutor, params }: BuildSetMaxTxGasLimitParameters,
25+
): Promise<BuildSetMaxTxGasLimitReturnType> {
26+
const validatedPublicClient = validateChildChainPublicClient(client);
27+
28+
const request = await client.prepareTransactionRequest({
29+
chain: client.chain as Chain | undefined,
30+
account,
31+
...prepareUpgradeExecutorCallParameters({
32+
to: arbOwnerAddress,
33+
upgradeExecutor,
34+
args: [params.limit],
35+
abi: arbOwnerABI,
36+
functionName: 'setMaxTxGasLimit',
37+
}),
38+
} satisfies PrepareTransactionRequestParameters);
39+
40+
return { ...request, chainId: validatedPublicClient.chain.id };
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
2+
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
3+
import {
4+
PrepareTransactionRequestReturnTypeWithChainId,
5+
WithAccount,
6+
WithUpgradeExecutor,
7+
} from '../types/Actions';
8+
import { Prettify } from '../types/utils';
9+
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
10+
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
11+
12+
export type BuildSetParentPricePerUnitParameters = Prettify<
13+
WithUpgradeExecutor<
14+
WithAccount<{
15+
params: { pricePerUnit: bigint };
16+
}>
17+
>
18+
>;
19+
20+
export type BuildSetParentPricePerUnitReturnType = PrepareTransactionRequestReturnTypeWithChainId;
21+
22+
export async function buildSetParentPricePerUnit<TChain extends Chain | undefined>(
23+
client: PublicClient<Transport, TChain>,
24+
{ account, upgradeExecutor, params }: BuildSetParentPricePerUnitParameters,
25+
): Promise<BuildSetParentPricePerUnitReturnType> {
26+
const validatedPublicClient = validateChildChainPublicClient(client);
27+
28+
const request = await client.prepareTransactionRequest({
29+
chain: validatedPublicClient.chain,
30+
account,
31+
...prepareUpgradeExecutorCallParameters({
32+
to: arbOwnerAddress,
33+
upgradeExecutor,
34+
args: [params.pricePerUnit],
35+
abi: arbOwnerABI,
36+
functionName: 'setL1PricePerUnit',
37+
}),
38+
} satisfies PrepareTransactionRequestParameters);
39+
40+
return { ...request, chainId: validatedPublicClient.chain.id };
41+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
2+
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
3+
import {
4+
PrepareTransactionRequestReturnTypeWithChainId,
5+
WithAccount,
6+
WithUpgradeExecutor,
7+
} from '../types/Actions';
8+
import { Prettify } from '../types/utils';
9+
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
10+
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
11+
12+
export type BuildSetParentPricingRewardRateParameters = Prettify<
13+
WithUpgradeExecutor<
14+
WithAccount<{
15+
params: { weiPerUnit: bigint };
16+
}>
17+
>
18+
>;
19+
20+
export type BuildSetParentPricingRewardRateReturnType =
21+
PrepareTransactionRequestReturnTypeWithChainId;
22+
23+
export async function buildSetParentPricingRewardRate<TChain extends Chain | undefined>(
24+
client: PublicClient<Transport, TChain>,
25+
{ account, upgradeExecutor, params }: BuildSetParentPricingRewardRateParameters,
26+
): Promise<BuildSetParentPricingRewardRateReturnType> {
27+
const validatedPublicClient = validateChildChainPublicClient(client);
28+
29+
const request = await client.prepareTransactionRequest({
30+
chain: client.chain,
31+
account,
32+
...prepareUpgradeExecutorCallParameters({
33+
to: arbOwnerAddress,
34+
upgradeExecutor,
35+
args: [params.weiPerUnit],
36+
abi: arbOwnerABI,
37+
functionName: 'setL1PricingRewardRate',
38+
}),
39+
} satisfies PrepareTransactionRequestParameters);
40+
41+
return { ...request, chainId: validatedPublicClient.chain.id };
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
2+
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
3+
import {
4+
PrepareTransactionRequestReturnTypeWithChainId,
5+
WithAccount,
6+
WithUpgradeExecutor,
7+
} from '../types/Actions';
8+
import { Prettify } from '../types/utils';
9+
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
10+
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
11+
12+
export type BuildSetParentPricingRewardRecipientParameters = Prettify<
13+
WithUpgradeExecutor<
14+
WithAccount<{
15+
params: { recipient: Address };
16+
}>
17+
>
18+
>;
19+
20+
export type BuildSetParentPricingRewardRecipientReturnType =
21+
PrepareTransactionRequestReturnTypeWithChainId;
22+
23+
export async function buildSetParentPricingRewardRecipient<TChain extends Chain | undefined>(
24+
client: PublicClient<Transport, TChain>,
25+
{ account, upgradeExecutor, params }: BuildSetParentPricingRewardRecipientParameters,
26+
): Promise<BuildSetParentPricingRewardRecipientReturnType> {
27+
const validatedPublicClient = validateChildChainPublicClient(client);
28+
29+
const request = await client.prepareTransactionRequest({
30+
chain: client.chain,
31+
account,
32+
...prepareUpgradeExecutorCallParameters({
33+
to: arbOwnerAddress,
34+
upgradeExecutor,
35+
args: [params.recipient],
36+
abi: arbOwnerABI,
37+
functionName: 'setL1PricingRewardRecipient',
38+
}),
39+
} satisfies PrepareTransactionRequestParameters);
40+
41+
return { ...request, chainId: validatedPublicClient.chain.id };
42+
}

src/actions/buildSetSpeedLimit.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
2+
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
3+
import {
4+
PrepareTransactionRequestReturnTypeWithChainId,
5+
WithAccount,
6+
WithUpgradeExecutor,
7+
} from '../types/Actions';
8+
import { Prettify } from '../types/utils';
9+
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';
10+
import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient';
11+
12+
export type BuildSetSpeedLimitParameters = Prettify<
13+
WithUpgradeExecutor<
14+
WithAccount<{
15+
params: { limit: bigint };
16+
}>
17+
>
18+
>;
19+
20+
export type BuildSetSpeedLimitReturnType = PrepareTransactionRequestReturnTypeWithChainId;
21+
22+
export async function buildSetSpeedLimit<TChain extends Chain | undefined>(
23+
client: PublicClient<Transport, TChain>,
24+
{ account, upgradeExecutor, params }: BuildSetSpeedLimitParameters,
25+
): Promise<BuildSetSpeedLimitReturnType> {
26+
const validatedPublicClient = validateChildChainPublicClient(client);
27+
28+
const request = await client.prepareTransactionRequest({
29+
chain: client.chain,
30+
account,
31+
...prepareUpgradeExecutorCallParameters({
32+
to: arbOwnerAddress,
33+
upgradeExecutor,
34+
args: [params.limit],
35+
abi: arbOwnerABI,
36+
functionName: 'setSpeedLimit',
37+
}),
38+
} satisfies PrepareTransactionRequestParameters);
39+
40+
return { ...request, chainId: validatedPublicClient.chain.id };
41+
}

src/types/Actions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ type isEmptyObject<Args> = Args extends Record<string, never> ? true : false;
1212
export type ActionParameters<Args, ContractName extends string, Curried extends boolean> = Prettify<
1313
Curried extends false
1414
? isEmptyObject<Args> extends true
15-
? { [key in ContractName]: Address } // Contract wasn't curried. Args is an empty object. Only requires the contract name
16-
: { params: Args } & { [key in ContractName]: Address } // Contract wasn't curried. Args is not empty. Requires both params and contract name
15+
? { [key in ContractName]: Address } | { sequencerInbox: Address } // Contract wasn't curried. Args is an empty object. Only requires the contract name
16+
: { params: Args } & ({ [key in ContractName]: Address } | { sequencerInbox: Address }) // Contract wasn't curried. Args is not empty. Requires both params and contract name
1717
: isEmptyObject<Args> extends true
18-
? { [key in ContractName]: Address } | void // Contract was curried. Args is empty. Only requires the contract name. Allows no parameters
19-
: { params: Args } & { [key in ContractName]?: Address } // Contract was curried. Args is not empty. Requires params, contract name is optional
18+
? { [key in ContractName]: Address } | { sequencerInbox: Address } | void // Contract was curried. Args is empty. Only requires the contract name. Allows no parameters
19+
: { params: Args } & ({ [key in ContractName]?: Address } | { sequencerInbox?: Address }) // Contract was curried. Args is not empty. Requires params, contract name is optional
2020
>;
2121

2222
export type WithAccount<Args> = Args & {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Chain, PublicClient, Transport } from 'viem';
2+
import { Prettify } from './utils';
3+
4+
export type ChildChainPublicClient<TChain extends Chain | undefined> = Prettify<
5+
PublicClient<Transport, TChain> & { chain: NonNullable<TChain> }
6+
>;
7+
8+
export function validateChildChainPublicClient<TChain extends Chain | undefined>(
9+
publicClient: PublicClient<Transport, TChain>,
10+
): ChildChainPublicClient<TChain> {
11+
if (!publicClient.chain) {
12+
throw new Error('client.chain is undefined');
13+
}
14+
15+
return publicClient as ChildChainPublicClient<TChain>;
16+
}

0 commit comments

Comments
 (0)