Skip to content

Commit

Permalink
Merge branch 'main' into feat-custom-parent-chain
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Sep 10, 2024
2 parents 8d4069c + 5fb2533 commit c2ae2f3
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 48 deletions.
10 changes: 7 additions & 3 deletions src/actions/buildInvalidateKeysetHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ export type BuildInvalidateKeysetHashReturnType = PrepareTransactionRequestRetur

export async function buildInvalidateKeysetHash<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
params: BuildInvalidateKeysetHashParameters,
{
account,
upgradeExecutor,
sequencerInbox: sequencerInboxAddress,
params,
}: BuildInvalidateKeysetHashParameters,
): Promise<BuildInvalidateKeysetHashReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params;

const request = await client.prepareTransactionRequest({
chain: client.chain,
account,
...prepareUpgradeExecutorCallParameters({
to: sequencerInboxAddress,
upgradeExecutor,
args: [args.keysetHash],
args: [params.keysetHash],
abi: sequencerInboxABI,
functionName: 'invalidateKeysetHash',
}),
Expand Down
20 changes: 15 additions & 5 deletions src/actions/buildSetIsBatchPoster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ export type BuildSetIsBatchPosterReturnType = PrepareTransactionRequestReturnTyp

export async function buildSetIsBatchPoster<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
params: BuildSetIsBatchPosterParameters & { enable: boolean },
{
account,
upgradeExecutor,
sequencerInbox: sequencerInboxAddress,
params,
}: BuildSetIsBatchPosterParameters & { params: { enable: boolean } },
): Promise<BuildSetIsBatchPosterReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params;

const request = await client.prepareTransactionRequest({
chain: client.chain,
account,
...prepareUpgradeExecutorCallParameters({
to: sequencerInboxAddress,
upgradeExecutor,
args: [args.batchPoster, args.enable],
args: [params.batchPoster, params.enable],
abi: sequencerInboxABI,
functionName: 'setIsBatchPoster',
}),
Expand All @@ -48,7 +52,10 @@ export async function buildEnableBatchPoster<TChain extends Chain | undefined>(
): Promise<BuildSetIsBatchPosterReturnType> {
return buildSetIsBatchPoster(client, {
...args,
enable: true,
params: {
...args.params,
enable: true,
},
});
}

Expand All @@ -58,6 +65,9 @@ export async function buildDisableBatchPoster<TChain extends Chain | undefined>(
): Promise<BuildSetIsBatchPosterReturnType> {
return buildSetIsBatchPoster(client, {
...args,
enable: false,
params: {
...args.params,
enable: false,
},
});
}
10 changes: 7 additions & 3 deletions src/actions/buildSetMaxTimeVariation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ export type BuildSetMaxTimeVariationReturnType = PrepareTransactionRequestReturn

export async function buildSetMaxTimeVariation<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
params: BuildSetMaxTimeVariationParameters,
{
account,
upgradeExecutor,
sequencerInbox: sequencerInboxAddress,
params,
}: BuildSetMaxTimeVariationParameters,
): Promise<BuildSetMaxTimeVariationReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params;

const request = await client.prepareTransactionRequest({
chain: client.chain,
account,
...prepareUpgradeExecutorCallParameters({
to: sequencerInboxAddress,
upgradeExecutor,
args: [args],
args: [params],
abi: sequencerInboxABI,
functionName: 'setMaxTimeVariation',
}),
Expand Down
10 changes: 7 additions & 3 deletions src/actions/buildSetValidKeyset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ export type BuildSetValidKeysetReturnType = PrepareTransactionRequestReturnTypeW

export async function buildSetValidKeyset<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
params: BuildSetValidKeysetParameters,
{
account,
upgradeExecutor,
sequencerInbox: sequencerInboxAddress,
params,
}: BuildSetValidKeysetParameters,
): Promise<BuildSetValidKeysetReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params;

const request = await client.prepareTransactionRequest({
chain: client.chain,
account,
...prepareUpgradeExecutorCallParameters({
to: sequencerInboxAddress,
upgradeExecutor,
args: [args.keyset],
args: [params.keyset],
abi: sequencerInboxABI,
functionName: 'setValidKeyset',
}),
Expand Down
4 changes: 2 additions & 2 deletions src/actions/getMaxTimeVariation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export type GetMaxTimeVariationReturnType = {

export async function getMaxTimeVariation<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: GetMaxTimeVariationParameters,
{ sequencerInbox }: GetMaxTimeVariationParameters,
): Promise<GetMaxTimeVariationReturnType> {
const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({
abi: sequencerInboxABI,
functionName: 'maxTimeVariation',
address: args.sequencerInbox,
address: sequencerInbox,
});
return {
delayBlocks,
Expand Down
6 changes: 3 additions & 3 deletions src/actions/isBatchPoster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export type IsBatchPosterReturnType = ReadContractReturnType<

export async function isBatchPoster<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: IsBatchPosterParameters,
{ sequencerInbox, params }: IsBatchPosterParameters,
): Promise<IsBatchPosterReturnType> {
return client.readContract({
abi: sequencerInboxABI,
functionName: 'isBatchPoster',
address: args.sequencerInbox,
args: [args.batchPoster],
address: sequencerInbox,
args: [params.batchPoster],
});
}
6 changes: 3 additions & 3 deletions src/actions/isValidKeysetHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export type IsValidKeysetHashReturnType = ReadContractReturnType<

export async function isValidKeysetHash<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: IsValidKeysetHashParameters,
{ sequencerInbox, params }: IsValidKeysetHashParameters,
): Promise<IsValidKeysetHashReturnType> {
return client.readContract({
abi: sequencerInboxABI,
functionName: 'isValidKeysetHash',
address: args.sequencerInbox,
args: [args.keysetHash],
address: sequencerInbox,
args: [params.keysetHash],
});
}
55 changes: 40 additions & 15 deletions src/actions/sequencerInbox.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ describe('max time variation management', () => {
const transactionRequest = await buildSetMaxTimeVariation(client, {
sequencerInbox: l3SequencerInbox,
upgradeExecutor: l3UpgradeExecutor,
...changes,

account: l3RollupOwner.address,
params: changes,
});
const txHash = await client.sendRawTransaction({
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
Expand Down Expand Up @@ -83,12 +82,16 @@ describe('batch poster management', () => {
it('isBatchPoster successfully fetches whether or an address is a batch poster', async () => {
const isNotBatchPosterAddress = await isBatchPoster(client, {
sequencerInbox: l3SequencerInbox,
batchPoster: zeroAddress,
params: {
batchPoster: zeroAddress,
},
});
expect(isNotBatchPosterAddress).toBeFalsy();
const isBatchPosterAddress = await isBatchPoster(client, {
sequencerInbox: l3SequencerInbox,
batchPoster: l3BatchPoster,
params: {
batchPoster: l3BatchPoster,
},
});
expect(isBatchPosterAddress).toBeTruthy();
});
Expand All @@ -97,39 +100,49 @@ describe('batch poster management', () => {
const randomAddress = privateKeyToAccount(generatePrivateKey()).address;
const isRandomAddressBatchPoster = await isBatchPoster(client, {
sequencerInbox: l3SequencerInbox,
batchPoster: randomAddress,
params: {
batchPoster: randomAddress,
},
});
expect(isRandomAddressBatchPoster).toBeFalsy();

const enableTransactionRequest = await buildEnableBatchPoster(client, {
sequencerInbox: l3SequencerInbox,
upgradeExecutor: l3UpgradeExecutor,
batchPoster: randomAddress,
account: l3RollupOwner.address,
params: {
batchPoster: randomAddress,
},
});
const enableTxHash = await client.sendRawTransaction({
serializedTransaction: await l3RollupOwner.signTransaction(enableTransactionRequest),
});
await client.waitForTransactionReceipt({ hash: enableTxHash });
const isRandomAddressBatchPosterAfterEnabling = await isBatchPoster(client, {
sequencerInbox: l3SequencerInbox,
batchPoster: randomAddress,
params: {
batchPoster: randomAddress,
},
});
expect(isRandomAddressBatchPosterAfterEnabling).toBeTruthy();

const disableTransactionRequest = await buildDisableBatchPoster(client, {
sequencerInbox: l3SequencerInbox,
upgradeExecutor: l3UpgradeExecutor,
batchPoster: randomAddress,
account: l3RollupOwner.address,
params: {
batchPoster: randomAddress,
},
});
const disableTxHash = await client.sendRawTransaction({
serializedTransaction: await l3RollupOwner.signTransaction(disableTransactionRequest),
});
await client.waitForTransactionReceipt({ hash: disableTxHash });
const isRandomAddressBatchPosterAfterDisabling = await isBatchPoster(client, {
sequencerInbox: l3SequencerInbox,
batchPoster: randomAddress,
params: {
batchPoster: randomAddress,
},
});
expect(isRandomAddressBatchPosterAfterDisabling).toBeFalsy();
});
Expand All @@ -153,9 +166,11 @@ describe('keyset management', () => {
const { sequencerInbox, upgradeExecutor } = createRollupInformation.coreContracts;
const transactionRequest = await buildSetValidKeyset(client, {
sequencerInbox: sequencerInbox,
keyset,
account: l3TokenBridgeDeployer.address,
upgradeExecutor,
params: {
keyset,
},
});
const transactionHash = await client.sendRawTransaction({
serializedTransaction: await l3TokenBridgeDeployer.signTransaction(transactionRequest),
Expand All @@ -179,15 +194,19 @@ describe('keyset management', () => {
it('isValidKeysetHash successfully fetches whether a hash is a valid keyset hash', async () => {
const invalidKeysetHash = await isValidKeysetHash(client, {
sequencerInbox: l3SequencerInbox,
keysetHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
params: {
keysetHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
},
});
expect(invalidKeysetHash).toBeFalsy();

const { sequencerInbox, keysetHash } = await deployAnyTrustChainWithKeyset(keysetBytes);

const result = await isValidKeysetHash(client, {
sequencerInbox,
keysetHash: keysetHash!,
params: {
keysetHash: keysetHash!,
},
});
expect(result).toBeTruthy();
});
Expand All @@ -199,15 +218,19 @@ describe('keyset management', () => {

const result = await isValidKeysetHash(client, {
sequencerInbox,
keysetHash: keysetHash!,
params: {
keysetHash: keysetHash!,
},
});
expect(result).toBeTruthy();

const transactionRequest = await buildInvalidateKeysetHash(client, {
keysetHash: keysetHash!,
sequencerInbox,
account: l3TokenBridgeDeployer.address,
upgradeExecutor,
params: {
keysetHash: keysetHash!,
},
});
const txHash = await client.sendRawTransaction({
serializedTransaction: await l3TokenBridgeDeployer.signTransaction(transactionRequest),
Expand All @@ -216,7 +239,9 @@ describe('keyset management', () => {

const resultAfterChange = await isValidKeysetHash(client, {
sequencerInbox,
keysetHash: keysetHash!,
params: {
keysetHash: keysetHash!,
},
});
expect(resultAfterChange).toBeFalsy();
});
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@arbitrum/orbit-sdk",
"description": "TypeScript SDK for building Arbitrum Orbit chains",
"version": "0.19.0-beta.0",
"version": "0.19.0",
"main": "./dist/index.js",
"files": [
"./dist"
Expand Down
18 changes: 8 additions & 10 deletions src/types/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Address, PrepareTransactionRequestReturnType } from 'viem';
import { Prettify } from './utils';

type isEmptyObject<Args> = Args extends Record<string, never> ? true : false;

/**
* Actions require contract address, but as part of decorators, the address might have been passed already to the decorator.
*
Expand All @@ -9,16 +11,12 @@ import { Prettify } from './utils';
*/
export type ActionParameters<Args, ContractName extends string, Curried extends boolean> = Prettify<
Curried extends false
? Args & { [key in ContractName]: Address }
: Args extends Record<string, never>
?
| {
[key in ContractName]: Address;
}
| void
: Args & {
[key in ContractName]?: Address;
}
? 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
: 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
>;

export type WithAccount<Args> = Args & {
Expand Down

0 comments on commit c2ae2f3

Please sign in to comment.