Skip to content

Commit

Permalink
Feat: Add v1 SequencerInbox setters
Browse files Browse the repository at this point in the history
Closes FS-535
  • Loading branch information
chrstph-dvx committed Jun 27, 2024
1 parent 6bbb0dd commit 3db265f
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/actions/invalidateKeysetHash.ts
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 { sequencerInbox } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import { Prettify } from '../types/utils';

export type InvalidateKeysetHashParameters<Curried extends boolean = false> = Prettify<
WithAccount<
ActionParameters<
{
keysetHash: Hex;
},
'sequencerInbox',
Curried
>
>
>;

export type InvalidateKeysetHashReturnType = PrepareTransactionRequestReturnType;

function sequencerInboxFunctionData({ keysetHash }: InvalidateKeysetHashParameters) {
return encodeFunctionData({
abi: sequencerInbox.abi,
functionName: 'invalidateKeysetHash',
args: [keysetHash],
});
}

export async function invalidateKeysetHash<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: InvalidateKeysetHashParameters,
): Promise<InvalidateKeysetHashReturnType> {
const data = sequencerInboxFunctionData(args);

return client.prepareTransactionRequest({
to: args.sequencerInbox,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
67 changes: 67 additions & 0 deletions src/actions/setIsbatchPoster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
Address,
Chain,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { sequencerInbox } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import { Prettify } from '../types/utils';

type Args = {
batchPoster: Address;
};

export type SetIsBatchPosterParameters<Curried extends boolean = false> = Prettify<
WithAccount<ActionParameters<Args, 'sequencerInbox', Curried>>
>;

export type SetIsBatchPosterReturnType = PrepareTransactionRequestReturnType;

function sequencerInboxFunctionData({
batchPoster,
enable,
}: SetIsBatchPosterParameters & { enable: boolean }) {
return encodeFunctionData({
abi: sequencerInbox.abi,
functionName: 'setIsBatchPoster',
args: [batchPoster, enable],
});
}

async function setIsBatchPoster<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetIsBatchPosterParameters & { enable: boolean },
): Promise<SetIsBatchPosterReturnType> {
const data = sequencerInboxFunctionData(args);
return client.prepareTransactionRequest({
to: args.sequencerInbox,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}

export async function enableBatchPoster<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetIsBatchPosterParameters,
): Promise<SetIsBatchPosterReturnType> {
return setIsBatchPoster(client, {
...args,
enable: true,
});
}

export async function disableBatchPoster<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetIsBatchPosterParameters,
): Promise<SetIsBatchPosterReturnType> {
return setIsBatchPoster(client, {
...args,
enable: false,
});
}
49 changes: 49 additions & 0 deletions src/actions/setKeyset.ts
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 { sequencerInbox } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import { Prettify } from '../types/utils';

export type SetKeysetParameters<Curried extends boolean = false> = Prettify<
WithAccount<
ActionParameters<
{
keyset: Hex;
},
'sequencerInbox',
Curried
>
>
>;

export type SetKeysetReturnType = PrepareTransactionRequestReturnType;

function sequencerInboxFunctionData({ keyset }: SetKeysetParameters) {
return encodeFunctionData({
abi: sequencerInbox.abi,
functionName: 'setValidKeyset',
args: [keyset],
});
}

export async function setKeyset<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetKeysetParameters,
): Promise<SetKeysetReturnType> {
const data = sequencerInboxFunctionData(args);

return client.prepareTransactionRequest({
to: args.sequencerInbox,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
46 changes: 46 additions & 0 deletions src/actions/setMaxTimeVariation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
Chain,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { sequencerInbox } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import { Prettify } from '../types/utils';

type Args = {
delayBlocks: bigint;
futureBlocks: bigint;
delaySeconds: bigint;
futureSeconds: bigint;
};
export type SetMaxTimeVariationParameters<Curried extends boolean = false> = Prettify<
WithAccount<ActionParameters<Args, 'sequencerInbox', Curried>>
>;

export type SetMaxTimeVariationReturnType = PrepareTransactionRequestReturnType;

function sequencerInboxFunctionData(args: SetMaxTimeVariationParameters) {
return encodeFunctionData({
abi: sequencerInbox.abi,
functionName: 'setMaxTimeVariation',
args: [args],
});
}

export async function setMaxTimeVariation<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetMaxTimeVariationParameters,
): Promise<SetMaxTimeVariationReturnType> {
const data = sequencerInboxFunctionData(args);

return client.prepareTransactionRequest({
to: args.sequencerInbox,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
4 changes: 4 additions & 0 deletions src/types/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ export type ActionParameters<Args, ContractName extends string, Curried extends
[key in ContractName]?: Address;
}
>;

export type WithAccount<Args> = Args & {
account: Address;
};

0 comments on commit 3db265f

Please sign in to comment.