Skip to content

Commit

Permalink
Merge branch 'main' into feat-arbowner-client
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Dec 18, 2023
2 parents acc3596 + 4a09c4b commit b08a45b
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 43 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/check-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Check PR Title'
# PR title is checked according to https://www.conventionalcommits.org/en/v1.0.0/

on:
pull_request_target:
types:
- opened
- edited
- synchronize
merge_group:

jobs:
main:
name: Check
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
subjectPattern: '^.{0,50}$'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain, createPublicClient, http, Address } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { arbitrumGoerli } from 'viem/chains';
import { arbitrumSepolia } from 'viem/chains';
import {
createRollupPrepareConfig,
prepareChainConfig,
Expand Down Expand Up @@ -44,7 +44,7 @@ const validatorPrivateKey = withFallbackPrivateKey(process.env.VALIDATOR_PRIVATE
const validator = privateKeyToAccount(validatorPrivateKey).address;

// set the parent chain and create a public client for it
const parentChain = arbitrumGoerli;
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createPublicClient({
chain: parentChain,
transport: http(),
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-fee-token/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain, createPublicClient, http } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { arbitrumGoerli } from 'viem/chains';
import { arbitrumSepolia } from 'viem/chains';
import {
createRollupPrepareConfig,
prepareChainConfig,
Expand Down Expand Up @@ -42,7 +42,7 @@ const validatorPrivateKey = withFallbackPrivateKey(process.env.VALIDATOR_PRIVATE
const validator = privateKeyToAccount(validatorPrivateKey).address;

// set the parent chain and create a public client for it
const parentChain = arbitrumGoerli;
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createPublicClient({ chain: parentChain, transport: http() });

// load the deployer account
Expand Down
4 changes: 2 additions & 2 deletions examples/eth-with-deterministic-factories/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain, createPublicClient, http } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { arbitrumGoerli } from 'viem/chains';
import { arbitrumSepolia } from 'viem/chains';
import {
createRollupPrepareConfig,
prepareChainConfig,
Expand Down Expand Up @@ -42,7 +42,7 @@ const validatorPrivateKey = withFallbackPrivateKey(process.env.VALIDATOR_PRIVATE
const validator = privateKeyToAccount(validatorPrivateKey).address;

// set the parent chain and create a public client for it
const parentChain = arbitrumGoerli;
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createPublicClient({ chain: parentChain, transport: http() });

// load the deployer account
Expand Down
4 changes: 2 additions & 2 deletions examples/eth/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain, createPublicClient, http } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { arbitrumGoerli } from 'viem/chains';
import { arbitrumSepolia } from 'viem/chains';
import {
createRollupPrepareConfig,
prepareChainConfig,
Expand Down Expand Up @@ -42,7 +42,7 @@ const validatorPrivateKey = withFallbackPrivateKey(process.env.VALIDATOR_PRIVATE
const validator = privateKeyToAccount(validatorPrivateKey).address;

// set the parent chain and create a public client for it
const parentChain = arbitrumGoerli;
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createPublicClient({ chain: parentChain, transport: http() });

// load the deployer account
Expand Down
4 changes: 2 additions & 2 deletions examples/prepare-node-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chain, createPublicClient, http } from 'viem';
import { arbitrumGoerli } from 'viem/chains';
import { arbitrumSepolia } from 'viem/chains';
import {
ChainConfig,
createRollupPrepareTransaction,
Expand All @@ -14,7 +14,7 @@ function getRpcUrl(chain: Chain) {
}

// set the parent chain and create a public client for it
const parentChain = arbitrumGoerli;
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createPublicClient({
chain: parentChain,
transport: http(),
Expand Down
4 changes: 2 additions & 2 deletions examples/set-valid-keyset/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain, createPublicClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { arbitrumGoerli } from 'viem/chains';
import { arbitrumSepolia } from 'viem/chains';
import { setValidKeysetPrepareTransactionRequest } from '@arbitrum/orbit-sdk';

function sanitizePrivateKey(privateKey: string): `0x${string}` {
Expand All @@ -23,7 +23,7 @@ const keyset =
'0x00000000000000010000000000000001012160000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';

// set the parent chain and create a public client for it
const parentChain = arbitrumGoerli;
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createPublicClient({ chain: parentChain, transport: http() });

// load the deployer account
Expand Down
14 changes: 10 additions & 4 deletions src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
tokenBridgeCreatorConfig,
} from './generated';

export const erc20 = {
abi: erc20ABI,
};

export const arbOwner = {
...arbOwnerConfig,
address: Object.values(arbOwnerConfig.address)[0],
Expand All @@ -15,7 +19,9 @@ export const arbOwner = {
export const rollupCreator = rollupCreatorConfig;
export const tokenBridgeCreator = tokenBridgeCreatorConfig;

export { erc20ABI };
export const upgradeExecutorABI = parseAbi([
'function executeCall(address target, bytes targetCallData)',
]);
export const upgradeExecutor = {
abi: parseAbi([
'function execute(address upgrade, bytes upgradeCallData)',
'function executeCall(address target, bytes targetCallData)',
]),
};
13 changes: 0 additions & 13 deletions src/executeCallEncodeFunctionData.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import {
setValidKeysetPrepareTransactionRequest,
SetValidKeysetPrepareTransactionRequestParams,
} from './setValidKeysetPrepareTransactionRequest';
import {
UpgradeExecutorAbi,
UpgradeExecutorFunctionName,
upgradeExecutorEncodeFunctionData,
UpgradeExecutorEncodeFunctionDataParameters,
} from './upgradeExecutor';

import { ChainConfig, ChainConfigArbitrumParams } from './types/ChainConfig';
import { CoreContracts } from './types/CoreContracts';
import { ParentChain, ParentChainId } from './types/ParentChain';
Expand Down Expand Up @@ -57,6 +64,12 @@ export {
SetValidKeysetParams,
setValidKeysetPrepareTransactionRequest,
SetValidKeysetPrepareTransactionRequestParams,
//
UpgradeExecutorAbi,
UpgradeExecutorFunctionName,
upgradeExecutorEncodeFunctionData,
UpgradeExecutorEncodeFunctionDataParameters,
//
CoreContracts,
ChainConfig,
ChainConfigArbitrumParams,
Expand Down
10 changes: 5 additions & 5 deletions src/setValidKeyset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PublicClient, WalletClient } from 'viem';

import { upgradeExecutorABI } from './contracts';
import { upgradeExecutor } from './contracts';
import { validParentChainId } from './types/ParentChain';
import { CoreContracts } from './types/CoreContracts';
import { setValidKeysetEncodeFunctionData } from './setValidKeysetEncodeFunctionData';
Expand All @@ -13,7 +13,7 @@ export type SetValidKeysetParams = {
};

export async function setValidKeyset({
coreContracts: { upgradeExecutor, sequencerInbox },
coreContracts,
keyset,
publicClient,
walletClient,
Expand All @@ -30,11 +30,11 @@ export async function setValidKeyset({
}

const { request } = await publicClient.simulateContract({
address: upgradeExecutor,
abi: upgradeExecutorABI,
address: coreContracts.upgradeExecutor,
abi: upgradeExecutor.abi,
functionName: 'executeCall',
args: [
sequencerInbox, // target
coreContracts.sequencerInbox, // target
setValidKeysetEncodeFunctionData(keyset), // targetCallData
],
account,
Expand Down
13 changes: 8 additions & 5 deletions src/setValidKeysetPrepareTransactionRequest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Address } from 'viem';

import { validParentChainId } from './types/ParentChain';
import { executeCallEncodeFunctionData } from './executeCallEncodeFunctionData';
import { SetValidKeysetParams } from './setValidKeyset';
import { setValidKeysetEncodeFunctionData } from './setValidKeysetEncodeFunctionData';
import { upgradeExecutorEncodeFunctionData } from './upgradeExecutor';

export type SetValidKeysetPrepareTransactionRequestParams = Omit<
SetValidKeysetParams,
Expand All @@ -27,10 +27,13 @@ export async function setValidKeysetPrepareTransactionRequest({
const request = await publicClient.prepareTransactionRequest({
chain: publicClient.chain,
to: coreContracts.upgradeExecutor,
data: executeCallEncodeFunctionData([
coreContracts.sequencerInbox,
setValidKeysetEncodeFunctionData(keyset),
]),
data: upgradeExecutorEncodeFunctionData({
functionName: 'executeCall',
args: [
coreContracts.sequencerInbox, // target
setValidKeysetEncodeFunctionData(keyset), // targetCallData
],
}),
account,
});

Expand Down
7 changes: 7 additions & 0 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Abi } from 'viem';

// https://twitter.com/mattpocockuk/status/1622730173446557697
export type Prettify<T> = {
[K in keyof T]: T[K];
} & {};

export type GetFunctionName<TAbi extends Abi> = Extract<
TAbi[number],
{ type: 'function' }
>['name'];
18 changes: 18 additions & 0 deletions src/upgradeExecutor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { it, expect } from 'vitest';

import { upgradeExecutorEncodeFunctionData } from './upgradeExecutor';

// taken from https://arbiscan.io/tx/0xc7e6188415d5572b305219c9b01d773693bc5b07cd1a8ab3e1278107275016e5
it('upgradeExecutorEncodeFunctionData', () => {
const result = upgradeExecutorEncodeFunctionData({
functionName: 'execute',
args: [
'0x9BF7b8884Fa381a45f8CB2525905fb36C996297a',
'0x536d8944000000000000000000000000add68bcb0f66878ab9d37a447c7b9067c5dfa94100000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000003bd8e2ac65ad6f0f094ba6766cbd9484ab49ef23000000000000000000000000f8e1492255d9428c2fc20a98a1deb1215c8ffefd000000000000000000000000b07dc9103328a51128bc6cc1049d1137035f5e280000000000000000000000003e286452b1c66abb08eb5494c3894f40ab5a59af000000000000000000000000b71ca4ffbb7b58d75ba29891ab45e9dc12b444ed0000000000000000000000008f10e3413586c4a8dcfce19d009872b19e9cd8e3000000000000000000000000566a07c3c932ae6af74d77c29e5c30d8b18537100000000000000000000000005280406912eb8ec677df66c326be48f938dc2e440000000000000000000000000275b3d54a5ddbf8205a75984796efe8b7357bae0000000000000000000000005a1fd562271aac2dadb51baab7760b949d9d81df000000000000000000000000f6b6f07862a02c85628b3a9688beae07fea9c863000000000000000000000000475816ca2a31d601b4e336f5c2418a67978abf09',
],
});

expect(result).toEqual(
'0x1cff79cd0000000000000000000000009bf7b8884fa381a45f8cb2525905fb36c996297a00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000204536d8944000000000000000000000000add68bcb0f66878ab9d37a447c7b9067c5dfa94100000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000003bd8e2ac65ad6f0f094ba6766cbd9484ab49ef23000000000000000000000000f8e1492255d9428c2fc20a98a1deb1215c8ffefd000000000000000000000000b07dc9103328a51128bc6cc1049d1137035f5e280000000000000000000000003e286452b1c66abb08eb5494c3894f40ab5a59af000000000000000000000000b71ca4ffbb7b58d75ba29891ab45e9dc12b444ed0000000000000000000000008f10e3413586c4a8dcfce19d009872b19e9cd8e3000000000000000000000000566a07c3c932ae6af74d77c29e5c30d8b18537100000000000000000000000005280406912eb8ec677df66c326be48f938dc2e440000000000000000000000000275b3d54a5ddbf8205a75984796efe8b7357bae0000000000000000000000005a1fd562271aac2dadb51baab7760b949d9d81df000000000000000000000000f6b6f07862a02c85628b3a9688beae07fea9c863000000000000000000000000475816ca2a31d601b4e336f5c2418a67978abf0900000000000000000000000000000000000000000000000000000000'
);
});
30 changes: 30 additions & 0 deletions src/upgradeExecutor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { encodeFunctionData, EncodeFunctionDataParameters } from 'viem';

import { upgradeExecutor } from './contracts';
import { GetFunctionName, Prettify } from './types/utils';

export type UpgradeExecutorAbi = typeof upgradeExecutor.abi;

export type UpgradeExecutorFunctionName = GetFunctionName<UpgradeExecutorAbi>;

export type UpgradeExecutorEncodeFunctionDataParameters<
TFunctionName extends UpgradeExecutorFunctionName
> = Prettify<
Omit<EncodeFunctionDataParameters<UpgradeExecutorAbi, TFunctionName>, 'abi'>
>;

export function upgradeExecutorEncodeFunctionData<
TFunctionName extends UpgradeExecutorFunctionName
>({
functionName,
args,
}: UpgradeExecutorEncodeFunctionDataParameters<TFunctionName>) {
// todo: fix this weird type issue
//
// @ts-ignore
return encodeFunctionData({
abi: upgradeExecutor.abi,
functionName,
args,
});
}
8 changes: 4 additions & 4 deletions src/utils/erc20.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, PublicClient, WalletClient, encodeFunctionData } from 'viem';

import { erc20ABI } from '../generated';
import { erc20 } from '../contracts';

function approveEncodeFunctionData({
spender,
Expand All @@ -10,7 +10,7 @@ function approveEncodeFunctionData({
amount: bigint;
}) {
return encodeFunctionData({
abi: erc20ABI,
abi: erc20.abi,
functionName: 'approve',
args: [spender, amount],
});
Expand Down Expand Up @@ -63,7 +63,7 @@ export async function approve({

const { request } = await publicClient.simulateContract({
address: address,
abi: erc20ABI,
abi: erc20.abi,
functionName: 'approve',
args: [spender, amount],
account,
Expand All @@ -88,7 +88,7 @@ export async function fetchAllowance({
}: FetchAllowanceProps) {
return publicClient.readContract({
address,
abi: erc20ABI,
abi: erc20.abi,
functionName: 'allowance',
args: [owner, spender],
});
Expand Down

0 comments on commit b08a45b

Please sign in to comment.