From 58b17a57faa33f873c0a2a4f7a9bdd99bcbc8505 Mon Sep 17 00:00:00 2001 From: GreatSoshiant <61604245+GreatSoshiant@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:38:35 -0800 Subject: [PATCH 1/5] changing arb goerli to arb sepolia --- examples/eth/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/eth/index.ts b/examples/eth/index.ts index 08fb397e..8f7e23f0 100644 --- a/examples/eth/index.ts +++ b/examples/eth/index.ts @@ -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, @@ -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 From f6f65f08b671a02cf54ea5c25e432da78496e1d6 Mon Sep 17 00:00:00 2001 From: GreatSoshiant <61604245+GreatSoshiant@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:45:44 -0800 Subject: [PATCH 2/5] changing arb goerli to arb sepolia on examples --- .../custom-fee-token-with-deterministic-factories/index.ts | 4 ++-- examples/custom-fee-token/index.ts | 4 ++-- examples/eth-with-deterministic-factories/index.ts | 4 ++-- examples/prepare-node-config/index.ts | 4 ++-- examples/set-valid-keyset/index.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/custom-fee-token-with-deterministic-factories/index.ts b/examples/custom-fee-token-with-deterministic-factories/index.ts index 33e3ee98..835066ec 100644 --- a/examples/custom-fee-token-with-deterministic-factories/index.ts +++ b/examples/custom-fee-token-with-deterministic-factories/index.ts @@ -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, @@ -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(), diff --git a/examples/custom-fee-token/index.ts b/examples/custom-fee-token/index.ts index 26f60e72..69d6a6a2 100644 --- a/examples/custom-fee-token/index.ts +++ b/examples/custom-fee-token/index.ts @@ -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, @@ -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 diff --git a/examples/eth-with-deterministic-factories/index.ts b/examples/eth-with-deterministic-factories/index.ts index 8d4cc7f4..39e3a35b 100644 --- a/examples/eth-with-deterministic-factories/index.ts +++ b/examples/eth-with-deterministic-factories/index.ts @@ -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, @@ -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 diff --git a/examples/prepare-node-config/index.ts b/examples/prepare-node-config/index.ts index 580848f4..2b995599 100644 --- a/examples/prepare-node-config/index.ts +++ b/examples/prepare-node-config/index.ts @@ -1,5 +1,5 @@ import { Chain, createPublicClient, http } from 'viem'; -import { arbitrumGoerli } from 'viem/chains'; +import { arbitrumSepolia } from 'viem/chains'; import { ChainConfig, createRollupPrepareTransaction, @@ -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(), diff --git a/examples/set-valid-keyset/index.ts b/examples/set-valid-keyset/index.ts index 6e267d7d..2dede0e5 100644 --- a/examples/set-valid-keyset/index.ts +++ b/examples/set-valid-keyset/index.ts @@ -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}` { @@ -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 From 5c30f251a6de5f21f413a0fd6c34fab9cbd6c8a7 Mon Sep 17 00:00:00 2001 From: spsjvc Date: Thu, 14 Dec 2023 10:37:04 +0100 Subject: [PATCH 3/5] ci: check pr title (#9) --- .github/workflows/check-pr-title.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/check-pr-title.yml diff --git a/.github/workflows/check-pr-title.yml b/.github/workflows/check-pr-title.yml new file mode 100644 index 00000000..28b0f84c --- /dev/null +++ b/.github/workflows/check-pr-title.yml @@ -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}$' From 563c26344ce122d0b58d33692eed3cdb2e85ec80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dragi=C5=A1a=20Spasojevi=C4=87?= Date: Thu, 14 Dec 2023 10:43:15 +0100 Subject: [PATCH 4/5] refactor: make contract configs consistent --- src/contracts.ts | 14 ++++++++++---- src/executeCallEncodeFunctionData.ts | 4 ++-- src/setValidKeyset.ts | 10 +++++----- src/utils/erc20.ts | 8 ++++---- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/contracts.ts b/src/contracts.ts index baf30419..c949406a 100644 --- a/src/contracts.ts +++ b/src/contracts.ts @@ -7,6 +7,10 @@ import { tokenBridgeCreatorConfig, } from './generated'; +export const erc20 = { + abi: erc20ABI, +}; + export const arbOwner = { ...arbOwnerConfig, address: Object.values(arbOwnerConfig.address)[0], @@ -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)', + ]), +}; diff --git a/src/executeCallEncodeFunctionData.ts b/src/executeCallEncodeFunctionData.ts index 00719520..65fa0d18 100644 --- a/src/executeCallEncodeFunctionData.ts +++ b/src/executeCallEncodeFunctionData.ts @@ -1,12 +1,12 @@ import { Address, encodeFunctionData } from 'viem'; -import { upgradeExecutorABI } from './contracts'; +import { upgradeExecutor } from './contracts'; export function executeCallEncodeFunctionData( args: [target: Address, targetCallData: `0x${string}`] ) { return encodeFunctionData({ - abi: upgradeExecutorABI, + abi: upgradeExecutor.abi, functionName: 'executeCall', args, }); diff --git a/src/setValidKeyset.ts b/src/setValidKeyset.ts index 7df1c343..1cf6d55b 100644 --- a/src/setValidKeyset.ts +++ b/src/setValidKeyset.ts @@ -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'; @@ -13,7 +13,7 @@ export type SetValidKeysetParams = { }; export async function setValidKeyset({ - coreContracts: { upgradeExecutor, sequencerInbox }, + coreContracts, keyset, publicClient, walletClient, @@ -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, diff --git a/src/utils/erc20.ts b/src/utils/erc20.ts index 0a218e25..610a75e6 100644 --- a/src/utils/erc20.ts +++ b/src/utils/erc20.ts @@ -1,6 +1,6 @@ import { Address, PublicClient, WalletClient, encodeFunctionData } from 'viem'; -import { erc20ABI } from '../generated'; +import { erc20 } from '../contracts'; function approveEncodeFunctionData({ spender, @@ -10,7 +10,7 @@ function approveEncodeFunctionData({ amount: bigint; }) { return encodeFunctionData({ - abi: erc20ABI, + abi: erc20.abi, functionName: 'approve', args: [spender, amount], }); @@ -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, @@ -88,7 +88,7 @@ export async function fetchAllowance({ }: FetchAllowanceProps) { return publicClient.readContract({ address, - abi: erc20ABI, + abi: erc20.abi, functionName: 'allowance', args: [owner, spender], }); From 4a09c4b9ab3a352f5afd0930fee9563fefbc38d2 Mon Sep 17 00:00:00 2001 From: spsjvc Date: Fri, 15 Dec 2023 12:41:08 +0100 Subject: [PATCH 5/5] feat: add upgrade executor encode function data util (#11) --- src/executeCallEncodeFunctionData.ts | 13 -------- src/index.ts | 13 ++++++++ ...setValidKeysetPrepareTransactionRequest.ts | 13 ++++---- src/types/utils.ts | 7 +++++ src/upgradeExecutor.test.ts | 18 +++++++++++ src/upgradeExecutor.ts | 30 +++++++++++++++++++ 6 files changed, 76 insertions(+), 18 deletions(-) delete mode 100644 src/executeCallEncodeFunctionData.ts create mode 100644 src/upgradeExecutor.test.ts create mode 100644 src/upgradeExecutor.ts diff --git a/src/executeCallEncodeFunctionData.ts b/src/executeCallEncodeFunctionData.ts deleted file mode 100644 index 65fa0d18..00000000 --- a/src/executeCallEncodeFunctionData.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Address, encodeFunctionData } from 'viem'; - -import { upgradeExecutor } from './contracts'; - -export function executeCallEncodeFunctionData( - args: [target: Address, targetCallData: `0x${string}`] -) { - return encodeFunctionData({ - abi: upgradeExecutor.abi, - functionName: 'executeCall', - args, - }); -} diff --git a/src/index.ts b/src/index.ts index b3d78971..b62d67ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -57,6 +64,12 @@ export { SetValidKeysetParams, setValidKeysetPrepareTransactionRequest, SetValidKeysetPrepareTransactionRequestParams, + // + UpgradeExecutorAbi, + UpgradeExecutorFunctionName, + upgradeExecutorEncodeFunctionData, + UpgradeExecutorEncodeFunctionDataParameters, + // CoreContracts, ChainConfig, ChainConfigArbitrumParams, diff --git a/src/setValidKeysetPrepareTransactionRequest.ts b/src/setValidKeysetPrepareTransactionRequest.ts index 9192900a..1ed2fe2a 100644 --- a/src/setValidKeysetPrepareTransactionRequest.ts +++ b/src/setValidKeysetPrepareTransactionRequest.ts @@ -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, @@ -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, }); diff --git a/src/types/utils.ts b/src/types/utils.ts index 43df0df4..f093fc78 100644 --- a/src/types/utils.ts +++ b/src/types/utils.ts @@ -1,4 +1,11 @@ +import { Abi } from 'viem'; + // https://twitter.com/mattpocockuk/status/1622730173446557697 export type Prettify = { [K in keyof T]: T[K]; } & {}; + +export type GetFunctionName = Extract< + TAbi[number], + { type: 'function' } +>['name']; diff --git a/src/upgradeExecutor.test.ts b/src/upgradeExecutor.test.ts new file mode 100644 index 00000000..8821158c --- /dev/null +++ b/src/upgradeExecutor.test.ts @@ -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' + ); +}); diff --git a/src/upgradeExecutor.ts b/src/upgradeExecutor.ts new file mode 100644 index 00000000..634afb35 --- /dev/null +++ b/src/upgradeExecutor.ts @@ -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; + +export type UpgradeExecutorEncodeFunctionDataParameters< + TFunctionName extends UpgradeExecutorFunctionName +> = Prettify< + Omit, 'abi'> +>; + +export function upgradeExecutorEncodeFunctionData< + TFunctionName extends UpgradeExecutorFunctionName +>({ + functionName, + args, +}: UpgradeExecutorEncodeFunctionDataParameters) { + // todo: fix this weird type issue + // + // @ts-ignore + return encodeFunctionData({ + abi: upgradeExecutor.abi, + functionName, + args, + }); +}