Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions examples/set-new-validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { arbitrumSepolia } from 'viem/chains';
import {
createRollupFetchTransactionHash,
createRollupPrepareTransactionReceipt,
rollupAdminLogicPublicActions,
rollupABI,
rollupAdminLogicPrepareTransactionRequest,
// Uncomment it when you want to use getValidators() to get validator status
// getValidators,
} from '@arbitrum/chain-sdk';
Expand Down Expand Up @@ -39,11 +40,7 @@ const parentChain = arbitrumSepolia;
const parentChainPublicClient = createPublicClient({
chain: parentChain,
transport: http(process.env.PARENT_CHAIN_RPC),
}).extend(
rollupAdminLogicPublicActions({
rollup: process.env.ROLLUP_ADDRESS as Address,
}),
);
});

// load the deployer account
const deployer = privateKeyToAccount(sanitizePrivateKey(process.env.ROLLUP_OWNER_PRIVATE_KEY));
Expand All @@ -70,7 +67,9 @@ async function main() {
const newValidatorStatus = [true];

// check the status of this address in validator list before executing
const beforeStatus = await parentChainPublicClient.rollupAdminLogicReadContract({
const beforeStatus = await parentChainPublicClient.readContract({
address: coreContracts.rollup,
abi: rollupABI,
functionName: 'isValidator',
args: [newValidators[0]],
});
Expand All @@ -90,16 +89,19 @@ async function main() {
*/

// prepare set validator transaction request
const setValidatorTransactionRequest =
await parentChainPublicClient.rollupAdminLogicPrepareTransactionRequest({
const setValidatorTransactionRequest = await rollupAdminLogicPrepareTransactionRequest(
parentChainPublicClient,
{
functionName: 'setValidator',
args: [
newValidators, // validator address list
newValidatorStatus, // validator status list
],
upgradeExecutor: coreContracts.upgradeExecutor,
account: deployer.address,
});
rollup: coreContracts.rollup,
},
);

// sign and send the transaction
const setValidatorTransactionHash = await parentChainPublicClient.sendRawTransaction({
Expand All @@ -118,10 +120,11 @@ async function main() {
);

// Check the status of this address in validator list before executing
const afterStatus = await parentChainPublicClient.rollupAdminLogicReadContract({
const afterStatus = await parentChainPublicClient.readContract({
address: coreContracts.rollup,
abi: rollupABI,
functionName: 'isValidator',
args: [newValidators[0]],
rollup: coreContracts.rollup,
});

console.log(
Expand Down
48 changes: 28 additions & 20 deletions examples/setup-aep-fee-router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
feeRouterDeployRewardDistributor,
createRollupFetchCoreContracts,
createTokenBridgeFetchTokenBridgeContracts,
arbOwnerPublicActions,
arbGasInfoPublicActions,
arbOwnerPrepareTransactionRequest,
arbOwnerPublicConfig,
arbGasInfoConfig,
parentChainIsArbitrum,
ParentChainId,
} from '@arbitrum/chain-sdk';
Expand Down Expand Up @@ -77,9 +78,10 @@ const orbitChain = defineChain({
},
testnet: true,
});
const orbitChainPublicClient = createPublicClient({ chain: orbitChain, transport: http() })
.extend(arbOwnerPublicActions)
.extend(arbGasInfoPublicActions);
const orbitChainPublicClient = createPublicClient({
chain: orbitChain,
transport: http(),
});
const orbitChainWalletClient = createWalletClient({
chain: orbitChain,
transport: http(),
Expand Down Expand Up @@ -118,21 +120,22 @@ async function main() {
});

// getting Orbit base fee collector (infraFeeAccount)
const infraFeeAccount = await orbitChainPublicClient.arbOwnerReadContract({
const infraFeeAccount = await orbitChainPublicClient.readContract({
...arbOwnerPublicConfig,
functionName: 'getInfraFeeAccount',
});

// getting Orbit surplus fee collector (networkFeeAccount)
const networkFeeAccount = await orbitChainPublicClient.arbOwnerReadContract({
const networkFeeAccount = await orbitChainPublicClient.readContract({
...arbOwnerPublicConfig,
functionName: 'getNetworkFeeAccount',
});

// getting parent chain surplus fee collector (L1RewardRecipient)
// Note: Arbiscan (Sepolia) doesn't have the updated ABI for ArbGasInfo, so we need to
// fetch the reward recipient this way
const parentChainRewardRecipient = await orbitChainPublicClient.readContract({
address: '0x000000000000000000000000000000000000006C',
abi: parseAbi(['function getL1RewardRecipient() view returns (address)']),
...arbGasInfoConfig,
functionName: 'getL1RewardRecipient',
});

Expand Down Expand Up @@ -236,27 +239,31 @@ async function main() {
console.log('Setting the RewardDistributors as the fee new collectors...');

// setting Orbit base fee collector (infraFeeAccount)
const setOrbitBaseFeeCollectorTransactionRequest =
await orbitChainPublicClient.arbOwnerPrepareTransactionRequest({
const setOrbitBaseFeeCollectorTransactionRequest = await arbOwnerPrepareTransactionRequest(
orbitChainPublicClient,
{
functionName: 'setInfraFeeAccount',
args: [feeCollectorToRewardDistributor['infraFeeAccount']],
upgradeExecutor: tokenBridgeContracts.orbitChainContracts.upgradeExecutor,
account: chainOwner.address,
});
},
);
await orbitChainPublicClient.sendRawTransaction({
serializedTransaction: await chainOwner.signTransaction(
setOrbitBaseFeeCollectorTransactionRequest,
),
});

// setting Orbit surplus fee collector (networkFeeAccount)
const setOrbitSurplusFeeCollectorTransactionRequest =
await orbitChainPublicClient.arbOwnerPrepareTransactionRequest({
const setOrbitSurplusFeeCollectorTransactionRequest = await arbOwnerPrepareTransactionRequest(
orbitChainPublicClient,
{
functionName: 'setNetworkFeeAccount',
args: [feeCollectorToRewardDistributor['networkFeeAccount']],
upgradeExecutor: tokenBridgeContracts.orbitChainContracts.upgradeExecutor,
account: chainOwner.address,
});
},
);
await orbitChainPublicClient.sendRawTransaction({
serializedTransaction: await chainOwner.signTransaction(
setOrbitSurplusFeeCollectorTransactionRequest,
Expand All @@ -265,7 +272,7 @@ async function main() {

// setting parent chain surplus fee collector (L1RewardRecipient)
const setParentChainSurplusFeeCollectorTransactionRequest =
await orbitChainPublicClient.arbOwnerPrepareTransactionRequest({
await arbOwnerPrepareTransactionRequest(orbitChainPublicClient, {
functionName: 'setL1PricingRewardRecipient',
args: [feeCollectorToRewardDistributor['parentChainRewardRecipient']],
upgradeExecutor: tokenBridgeContracts.orbitChainContracts.upgradeExecutor,
Expand All @@ -278,7 +285,8 @@ async function main() {
});

// checking that the fee collectors were correctly set
const currentInfraFeeAccount = await orbitChainPublicClient.arbOwnerReadContract({
const currentInfraFeeAccount = await orbitChainPublicClient.readContract({
...arbOwnerPublicConfig,
functionName: 'getInfraFeeAccount',
});
if (currentInfraFeeAccount != feeCollectorToRewardDistributor['infraFeeAccount']) {
Expand All @@ -290,7 +298,8 @@ async function main() {
`Orbit base fee collector correctly set to the RewardDistributor contract ${currentInfraFeeAccount}`,
);

const currentNetworkFeeAccount = await orbitChainPublicClient.arbOwnerReadContract({
const currentNetworkFeeAccount = await orbitChainPublicClient.readContract({
...arbOwnerPublicConfig,
functionName: 'getNetworkFeeAccount',
});
if (currentNetworkFeeAccount != feeCollectorToRewardDistributor['networkFeeAccount']) {
Expand All @@ -303,8 +312,7 @@ async function main() {
);

const currentParentChainRewardRecipient = await orbitChainPublicClient.readContract({
address: '0x000000000000000000000000000000000000006C',
abi: parseAbi(['function getL1RewardRecipient() view returns (address)']),
...arbGasInfoConfig,
functionName: 'getL1RewardRecipient',
});
if (
Expand Down
25 changes: 14 additions & 11 deletions examples/setup-fast-withdrawal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
createRollupPrepareTransactionReceipt,
createSafePrepareTransactionReceipt,
createSafePrepareTransactionRequest,
rollupAdminLogicPublicActions,
rollupABI,
rollupAdminLogicPrepareTransactionRequest,
setAnyTrustFastConfirmerPrepareTransactionRequest,
} from '@arbitrum/chain-sdk';
import { sanitizePrivateKey, getParentChainFromId } from '@arbitrum/chain-sdk/utils';
Expand Down Expand Up @@ -59,11 +60,7 @@ const parentChain = getParentChainFromId(Number(process.env.PARENT_CHAIN_ID));
const parentChainPublicClient = createPublicClient({
chain: parentChain,
transport: http(),
}).extend(
rollupAdminLogicPublicActions({
rollup: rollupAddress,
}),
);
});

// load the deployer account
const safeOwner = privateKeyToAccount(sanitizePrivateKey(process.env.CHAIN_OWNER_PRIVATE_KEY));
Expand Down Expand Up @@ -158,16 +155,19 @@ async function main() {

// prepare set validator transaction request
const fcValidatorsStatus = Array(fcValidators.length).fill(true);
const setValidatorTransactionRequest =
await parentChainPublicClient.rollupAdminLogicPrepareTransactionRequest({
const setValidatorTransactionRequest = await rollupAdminLogicPrepareTransactionRequest(
parentChainPublicClient,
{
functionName: 'setValidator',
args: [
fcValidators, // validator address list
fcValidatorsStatus, // validator status list
],
upgradeExecutor: upgradeExecutorAddress,
account: safeOwner.address,
});
rollup: rollupAddress,
},
);

// sign and send the transaction
const setValidatorTransactionHash = await parentChainPublicClient.sendRawTransaction({
Expand Down Expand Up @@ -249,18 +249,21 @@ async function main() {
console.log('---');

// get current minimumAssertionPeriod
const currentMinimumAssertionPeriod = await parentChainPublicClient.rollupAdminLogicReadContract({
const currentMinimumAssertionPeriod = await parentChainPublicClient.readContract({
address: rollupAddress,
abi: rollupABI,
functionName: 'minimumAssertionPeriod',
});

if (currentMinimumAssertionPeriod !== minimumAssertionPeriod) {
// prepare setMinimumAssertionPeriod transaction request
const setMinimumAssertionPeriodTransactionRequest =
await parentChainPublicClient.rollupAdminLogicPrepareTransactionRequest({
await rollupAdminLogicPrepareTransactionRequest(parentChainPublicClient, {
functionName: 'setMinimumAssertionPeriod',
args: [minimumAssertionPeriod],
upgradeExecutor: upgradeExecutorAddress,
account: safeOwner.address,
rollup: rollupAddress,
});

// sign and send the transaction
Expand Down
18 changes: 10 additions & 8 deletions examples/setup-fee-distributor-contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
feeRouterDeployRewardDistributor,
createRollupFetchCoreContracts,
createTokenBridgeFetchTokenBridgeContracts,
arbOwnerPublicActions,
arbOwnerPrepareTransactionRequest,
arbOwnerPublicConfig,
} from '@arbitrum/chain-sdk';
import { getParentChainFromId, sanitizePrivateKey } from '@arbitrum/chain-sdk/utils';
import { config } from 'dotenv';
Expand Down Expand Up @@ -58,9 +59,7 @@ const orbitChain = defineChain({
},
testnet: true,
});
const orbitChainPublicClient = createPublicClient({ chain: orbitChain, transport: http() }).extend(
arbOwnerPublicActions,
);
const orbitChainPublicClient = createPublicClient({ chain: orbitChain, transport: http() });
const orbitChainWalletClient = createWalletClient({
chain: orbitChain,
transport: http(),
Expand Down Expand Up @@ -149,20 +148,23 @@ async function main() {
console.log(
'Setting the RewardDistributor as the collector of the Orbit chain execution fees...',
);
const setFeeCollectorTransactionRequest =
await orbitChainPublicClient.arbOwnerPrepareTransactionRequest({
const setFeeCollectorTransactionRequest = await arbOwnerPrepareTransactionRequest(
orbitChainPublicClient,
{
functionName: 'setInfraFeeAccount',
args: [rewardDistributorAddress],
upgradeExecutor: tokenBridgeContracts.orbitChainContracts.upgradeExecutor,
account: chainOwner.address,
});
},
);

await orbitChainPublicClient.sendRawTransaction({
serializedTransaction: await chainOwner.signTransaction(setFeeCollectorTransactionRequest),
});

// checking that the fee collector was correctly set
const currentFeeCollector = await orbitChainPublicClient.arbOwnerReadContract({
const currentFeeCollector = await orbitChainPublicClient.readContract({
...arbOwnerPublicConfig,
functionName: 'getInfraFeeAccount',
});
if (currentFeeCollector != rewardDistributorAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { it, expect, describe } from 'vitest';
import { createPublicClient, http } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';

import { nitroTestnodeL2 } from '../chains';
import { arbAggregatorActions } from './arbAggregatorActions';
import { getNitroTestnodePrivateKeyAccounts } from '../testHelpers';
import { nitroTestnodeL2 } from './chains';
import { arbAggregatorConfig } from './contracts/ArbAggregator';
import { arbAggregatorPrepareTransactionRequest } from './arbAggregatorPrepareTransactionRequest';
import { getNitroTestnodePrivateKeyAccounts } from './testHelpers';

const testnodeAccounts = getNitroTestnodePrivateKeyAccounts();
const l2RollupOwner = testnodeAccounts.l2RollupOwner;
Expand All @@ -13,18 +14,20 @@ const randomAccount = privateKeyToAccount(generatePrivateKey());
const nitroTestnodeL2Client = createPublicClient({
chain: nitroTestnodeL2,
transport: http(),
}).extend(arbAggregatorActions);
});

describe('ArgAggregator decorator tests', () => {
describe('ArbAggregator actions', () => {
it('successfully fetches the batch posters and the fee collectors', async () => {
const batchPosters = await nitroTestnodeL2Client.arbAggregatorReadContract({
const batchPosters = await nitroTestnodeL2Client.readContract({
...arbAggregatorConfig,
functionName: 'getBatchPosters',
});

expect(batchPosters).toHaveLength(2);
expect(batchPosters[0]).toEqual('0xA4b000000000000000000073657175656e636572');

const batchPosterFeeCollector = await nitroTestnodeL2Client.arbAggregatorReadContract({
const batchPosterFeeCollector = await nitroTestnodeL2Client.readContract({
...arbAggregatorConfig,
functionName: 'getFeeCollector',
args: [batchPosters[0]],
});
Expand All @@ -34,25 +37,29 @@ describe('ArgAggregator decorator tests', () => {

it('succesfully updates the fee collector of a batch poster', async () => {
// Get the batch posters
const batchPosters = await nitroTestnodeL2Client.arbAggregatorReadContract({
const batchPosters = await nitroTestnodeL2Client.readContract({
...arbAggregatorConfig,
functionName: 'getBatchPosters',
});

// Set the fee collector of the batch poster to the random address
const setFeeCollectorTransactionRequest =
await nitroTestnodeL2Client.arbAggregatorPrepareTransactionRequest({
const setFeeCollectorTransactionRequest = await arbAggregatorPrepareTransactionRequest(
nitroTestnodeL2Client,
{
functionName: 'setFeeCollector',
args: [batchPosters[1], randomAccount.address],
upgradeExecutor: false,
account: l2RollupOwner.address,
});
},
);
const txHash = await nitroTestnodeL2Client.sendRawTransaction({
serializedTransaction: await l2RollupOwner.signTransaction(setFeeCollectorTransactionRequest),
});
await nitroTestnodeL2Client.waitForTransactionReceipt({ hash: txHash });

// Check the fee collector has changed
const batchPosterFeeCollector = await nitroTestnodeL2Client.arbAggregatorReadContract({
const batchPosterFeeCollector = await nitroTestnodeL2Client.readContract({
...arbAggregatorConfig,
functionName: 'getFeeCollector',
args: [batchPosters[1]],
});
Expand Down
Loading
Loading