# Clone the repository
git clone https://github.com/InternetMaximalism/intmax2-contract.git
cd intmax2-contract
# Install dependencies
npm install
# Install from npm
npm install intmax2-contract
In your foundry.toml
file, add:
[profile.default]
libs = ['node_modules']
Then install the package:
# Install the package
npm install intmax2-contract
# Or with Forge
forge install --no-git intmax2-contract
contracts/
: Smart contract source codeblock-builder-registry/
: Block builder registration and managementclaim/
: Claim processing and verificationcommon/
: Shared libraries and utilitiescontribution/
: Contribution managementliquidity/
: Liquidity pool managementpermitter/
: Permission managementrollup/
: Rollup functionalitywithdrawal/
: Withdrawal processingverifiers/
: Proof verification contractstest/
: Test contracts
scripts/
: Deployment and operational scriptstest/
: Test filestest_data/
: Test data filestest_data_generator/
: Tools for generating test data
A smart contract responsible for handling operations related to Intmax blocks.
- Deployment: Scroll
- Functions:
- Block Posting: Allows posting blocks.
- Deposit Processing: Integrates deposits from the liquidity contract into the Rollup state.
- Penalty Fee Management: Enables withdrawal and adjustment of penalty fees associated with rate limiting.
This contract manages asset transfers between the Ethereum and Intmax networks. It handles user deposit and withdrawal operations and maintains asset states.
- Deployment: Ethereum
- Functions:
- Asset Deposits: Users can deposit tokens (native tokens, ERC20, ERC721, ERC1155) from Ethereum into Intmax.
- AML Check: Performs AML checks upon deposits and rejects deposits from non-compliant addresses.
- Asset Withdrawals: Sends tokens withdrawn from Intmax to users on Ethereum.
- Deposit Management: Stores deposited tokens in a queue, and a Deposit Relayer communicates this information to the Intmax network.
- Contribution Recording: Records addresses executing essential transactions (such as withdrawals).
Manages withdrawal processes from the Intmax network to Ethereum, verifies withdrawal proofs, and manages eligible token indices for direct withdrawals.
- Deployment: Scroll
- Functions:
- Withdrawal Request Submission: Allows submission and verification of withdrawal proofs from Intmax.
- Token Management for Direct Withdrawals: Manages token indices eligible for direct withdrawals.
Used to claim rewards from privacy mining, distributing ITX tokens on Ethereum.
- Deployment: Scroll
- Functions:
- Claim Proof Submission: Submit claim proof from Intmax network.
- Token Management for Direct Withdrawals: Manages tokens eligible for direct withdrawals.
Maintains a registry of active block builders via heartbeat signals.
- Deployment: Scroll
- Functions:
- Heartbeat Emission: Enables periodic signals indicating active status.
Manages user contributions, tracking allocations, weights, and reward distributions.
- Deployment: Ethereum and Scroll
- Functions:
- Contribution Recording: Records user contributions with tags for specific periods.
- Period Management: Manages periodic increments and resets for contributions.
- Weight Management: Assigns and manages tag weights for each period.
This contract uses a service called Predicate to verify AML checks and to determine whether the transaction originates from valid mining activities. It is invoked by the Liquidity contract whenever a user deposits funds. Deposits from addresses that do not comply with predetermined policies will be rejected.
- Deployment: Ethereum
- Functions:
- Policy Verification: Rejects transaction executions from addresses not compliant with AML and mining validation policies.
Create a .env
file in the root directory with the following variables:
DEPLOYER_PRIVATE_KEY
: Deployer's private key for contract deploymentADMIN_ADDRESS
: Admin's address for contract initialization and managementRELAYER_ADDRESS
: Relayer's address for the Liquidity contractINTMAX_TOKEN_ADDRESS
: INTMAX token address. If set to empty string, use the address ofTestERC20
token instead.WBTC_ADDRESS
: Wrapped Bitcoin token address.USDC_ADDRESS
: USDC token address.CONTRIBUTION_PERIOD_INTERVAL
: Contribution period interval in secondsCLAIM_PERIOD_INTERVAL
: Claim period interval in seconds
ALCHEMY_KEY
: Key for Alchemy API accessETHERSCAN_API_KEY
: Key for Etherscan contract verificationSCROLLSCAN_API_KEY
: Key for Scrollscan contract verification
ADMIN_PRIVATE_KEY
: Admin's private key (required ifGRANT_ROLE=true
)RELAYER_PRIVATE_KEY
: Relayer's private key (required for running relay scripts likerelayDeposits.ts
)GRANT_ROLE
: Set totrue
to grant roles during deployment (default:false
)DEPLOY_MOCK_MESSENGER
: Set totrue
to deploy mock messenger contracts for testing (default:false
)PLONK_VERIFIER_TYPE
: Type of Plonk verifier to deploy. Options aremock
,faster-mining
,normal
(default:normal
)SLEEP_TIME
: Sleep time in seconds between deployments (default:30
)
RATELIMIT_THRESHOLD_INTERVAL
: Target interval for rate limiting (default:10^18 * 30
- 30 seconds in fixed point)RATELIMIT_ALPHA
: Alpha parameter for rate limiting (default:10^18 / 3
- 1/3 in fixed point)RATELIMIT_K
: K parameter for rate limiting (default:10^18 / 1000
- 0.001 in fixed point)
You can use the provided .env.example
file as a template.
The deployment process consists of 3 sequential stages. Each stage must be completed before proceeding to the next.
Set the appropriate network variables before running the deployment scripts:
For localhost environment:
L1_NETWORK=localhost
L2_NETWORK=localhost
For testnet environment:
L1_NETWORK=sepolia
L2_NETWORK=scrollSepolia
For mainnet environment:
L1_NETWORK=mainnet
L2_NETWORK=scroll
Execute the following scripts in sequence:
# Step 1: Deploy contracts to L2
npx hardhat run ./scripts/deploy/1_deployToL2.ts --network $L2_NETWORK
# Step 2: Deploy contracts to L1
npx hardhat run ./scripts/deploy/2_deployToL1.ts --network $L1_NETWORK
# Step 3: Initialize L2 contracts
npx hardhat run ./scripts/deploy/3_initializeOnL2.ts --network $L2_NETWORK
The following scripts can be used to test and operate the INTMAX2 protocol:
Users can deposit ETH to the contract and cancel the deposit if needed:
npx hardhat run scripts/test/depositEth.ts --network $L1_NETWORK
npx hardhat run scripts/test/depositAndCancelEth.ts --network $L1_NETWORK
Users can deposit ERC20 tokens to the contract and cancel the deposit if needed:
npx hardhat run scripts/test/depositAndCancelErc20.ts --network $L1_NETWORK
The relayer transfers analyzed deposits from L1 to L2:
npx hardhat run scripts/test/relayDeposits.ts --network $L1_NETWORK
Block builders post blocks to the contract:
npx hardhat run scripts/test/postBlock.ts --network $L2_NETWORK
When a user wants to withdraw assets from INTMAX2, the withdrawal aggregator submits the withdrawal proof:
npx hardhat run scripts/test/submitWithdrawalProof.ts --network $L2_NETWORK
The withdrawal aggregator relays user withdrawals from L2 to L1:
npx hardhat run scripts/test/relayClaims.ts --network $L2_NETWORK
npx hardhat run scripts/test/submitClaimProof.ts --network $L2_NETWORK
npx hardhat run scripts/test/getTokenInfo.ts --network $L2_NETWORK
npm run lint
npm test
Generate documentation from NatSpec comments in the contracts:
npx hardhat docgen