Skip to content

Commit

Permalink
feat: add isAnyTrust (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx authored Jun 24, 2024
1 parent e90ed84 commit 62e1ace
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
GetBatchPostersParams,
GetBatchPostersReturnType,
} from './getBatchPosters';
import { isAnyTrust } from './isAnyTrust';

export {
arbOwnerPublicActions,
Expand Down Expand Up @@ -195,4 +196,6 @@ export {
getBatchPosters,
GetBatchPostersParams,
GetBatchPostersReturnType,
//
isAnyTrust,
};
29 changes: 29 additions & 0 deletions src/isAnyTrust.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Address, Chain, PublicClient, Transport, decodeFunctionData, getAbiItem } from 'viem';
import { createRollupFetchTransactionHash } from './createRollupFetchTransactionHash';
import { rollupCreator } from './contracts';

const createRollupABI = getAbiItem({ abi: rollupCreator.abi, name: 'createRollup' });
export async function isAnyTrust<TChain extends Chain | undefined>({
rollup,
publicClient,
}: {
rollup: Address;
publicClient: PublicClient<Transport, TChain>;
}) {
const createRollupTransactionHash = await createRollupFetchTransactionHash({
rollup,
publicClient,
});

const transaction = await publicClient.getTransaction({
hash: createRollupTransactionHash,
});
const {
args: [{ config }],
} = decodeFunctionData({
abi: [createRollupABI],
data: transaction.input,
});
const chainConfig = JSON.parse(config.chainConfig);
return chainConfig.arbitrum.DataAvailabilityCommittee;
}
30 changes: 30 additions & 0 deletions src/isAnyTrust.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect, it } from 'vitest';
import { isAnyTrust } from './isAnyTrust';
import { createPublicClient, http } from 'viem';
import { arbitrumNova, arbitrumSepolia, sepolia } from 'viem/chains';

it('should return true for AnyTrust chain', async () => {
const client = createPublicClient({
chain: arbitrumNova,
transport: http(),
});
// https://nova.arbiscan.io/tx/0x37be7a29db10d18501dcf4d0243fa6aefeeba21cbc17832ef16ccf288ce58ef2
const isPlaynanceAnyTrust = await isAnyTrust({
publicClient: client,
rollup: '0x04ea347cC6A258A7F65D67aFb60B1d487062A1d0',
});
expect(isPlaynanceAnyTrust).toBeTruthy();
});

it('should return false for non AnyTrust chain', async () => {
const client = createPublicClient({
chain: arbitrumSepolia,
transport: http(),
});
// https://sepolia.arbiscan.io/tx/0x0bbb740d8b0286654b3d0f63175ec882dcbb7714cbf5207357a4a72a4d2dc640
const isAnyTrustChain = await isAnyTrust({
publicClient: client,
rollup: '0xd0c7b5c4e8f72e0750ed9dc70a10cf6f5afd4787',
});
expect(isAnyTrustChain).toBeFalsy();
});

0 comments on commit 62e1ace

Please sign in to comment.