Smart contracts for the INA Credit Markets protocol, implementing investment pools, account abstraction, and compliance infrastructure on Arbitrum.
- Overview
- Architecture
- Prerequisites
- Installation
- Environment Setup
- Building
- Testing
- Deployment
- Contract Addresses
- Development Workflow
- Security
- Contributing
INA Contracts is a comprehensive smart contract suite that powers the Credit Markets DeFi platform. The protocol enables:
- Credit Market Pools: ERC20-based investment pools for credit markets
- Account Abstraction: ERC-4337 smart wallet infrastructure
- KYC/Compliance: Integration with Ethereum Attestation Service (EAS)
- Registry System: Management of credit facilitators and attesters
- Gasless Transactions: Paymaster contracts for sponsored transactions
- CMPool: ERC20 investment pool implementation with deposit/withdrawal functionality
- CMRegistry: Registry for managing credit facilitators and EAS attesters
- CMAccountFactory: Factory for deploying smart wallets with account abstraction
- InaAccount: Modified Light Account implementation for user wallets
- InaPaymaster: Paymaster contract for gasless transactions
- Dual Framework Support: Both Hardhat and Foundry for maximum flexibility
- Account Abstraction: Full ERC-4337 implementation with Light Account
- Type Safety: TypeChain-generated TypeScript bindings
- Upgradeable Contracts: Proxy patterns for future upgrades
- Security: OpenZeppelin contracts and ReentrancyGuard patterns
- Node.js: Latest LTS version
- pnpm: v10.8.0 or higher (specified package manager)
- Foundry: Latest version (forge, anvil, cast)
- Git: For cloning the repository
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup- Clone the repository:
git clone <repository-url>
cd ina-contracts- Install dependencies:
pnpm install- Install Foundry dependencies:
forge install- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration# Deployer private key (KEEP SECRET!)
PRIVATE_KEY="0x..."
# Etherscan API key for contract verification
ETHERSCAN_API_KEY="your_etherscan_api_key"
# Alchemy API key for RPC services
ALCHEMY_API_KEY="your_alchemy_api_key"# ERC-4337 EntryPoint address (default: 0x0000000071727De22E5E9d8BAf0edAc6f37da032)
ENTRYPOINT="0x..."
# Factory owner address
OWNER="0x..."
# Account factory stake requirements
REQUIRED_STAKE_AMOUNT="0.1"
UNSTAKE_DELAY_SEC="86400"See .env.example for complete documentation of all environment variables.
# Hardhat compilation
npx hardhat compile
# Foundry compilation
forge build
# Generate TypeChain bindings
pnpm run typechainnpx hardhat clean
forge clean# Hardhat tests
npx hardhat test
# Foundry tests
forge test
# Run specific test file
npx hardhat test test/CMPool.test.ts
forge test --match-contract CMPoolTest# Hardhat coverage
npx hardhat coverage
# Foundry coverage
forge coverage# Enable gas reporting
REPORT_GAS=true npx hardhat test# Deploy Registry
pnpm run deploy-registry
# Deploy Account Factory
pnpm run deploy-factory
# Deploy Pool (example)
pnpm run deploy-pool
# Deploy Upgradeable Registry
pnpm run deploy-registry-upgradablenpx hardhat verify --network arbitrumSepolia DEPLOYED_CONTRACT_ADDRESS "Constructor Arg 1" "Constructor Arg 2"npx hardhat run scripts/deploy.ts --network arbitrumSepolia| Contract | Address | Description |
|---|---|---|
| CMRegistry | [To be deployed] |
Credit facilitator registry |
| CMAccountFactory | [To be deployed] |
Smart wallet factory |
| InaPaymaster | [To be deployed] |
Gasless transaction sponsor |
| EntryPoint | 0x0000000071727De22E5E9d8BAf0edAc6f37da032 |
ERC-4337 EntryPoint v0.7 |
Note: Update these addresses after deployment
# Start local Hardhat node
npx hardhat node
# Or start Anvil (Foundry)
anvil
# Deploy to local network
npx hardhat run scripts/deploy.ts --network localhost# Fork Arbitrum Sepolia for testing
npx hardhat node --fork https://sepolia-rollup.arbitrum.io/rpc
# Run tests against fork
npx hardhat test --network localhost# Generate TypeChain bindings after contract changes
pnpm run typechain
# Use generated types in scripts
import { CMPool__factory } from "../typechain-types";- Auditing: All contracts should be audited before mainnet deployment
- Testing: Comprehensive test coverage (aim for >90%)
- Access Control: Proper role-based permissions
- Upgradability: Use proxy patterns carefully
- External Calls: Validate all external contract interactions
- OpenZeppelin security contracts
- ReentrancyGuard for state-changing functions
- Role-based access control
- EAS integration for KYC compliance
- Signature verification for account abstraction
Please report security vulnerabilities privately to the team. Do not create public issues for security concerns.
| Script | Purpose | Command |
|---|---|---|
deploy-registry.ts |
Deploy CMRegistry contract | pnpm run deploy-registry |
deploy-factory.ts |
Deploy account factory | pnpm run deploy-factory |
deploy-pool.ts |
Deploy investment pool | pnpm run deploy-pool |
3_createPool.ts |
Create new pool instance | npx hardhat run scripts/3_createPool.ts |
10_sendDev.ts |
Send dev tokens | npx hardhat run scripts/10_sendDev.ts |
ina-contracts/
├── contracts/ # Solidity source files
│ ├── pools/ # Pool contracts
│ ├── registry/ # Registry contracts
│ ├── accounts/ # Account abstraction
│ └── interfaces/ # Contract interfaces
├── scripts/ # Deployment and operational scripts
├── test/ # Test files (TypeScript)
├── lib/ # Foundry dependencies
├── artifacts/ # Hardhat compilation artifacts
├── out/ # Foundry compilation artifacts
├── typechain-types/ # Generated TypeScript bindings
├── hardhat.config.ts # Hardhat configuration
├── foundry.toml # Foundry configuration
└── package.json # Node dependencies
- Compilation errors: Ensure both Hardhat and Foundry are properly installed
- Missing dependencies: Run
pnpm installandforge install - TypeChain errors: Regenerate bindings with
pnpm run typechain - Network issues: Check RPC URL and network configuration
- Gas estimation: Ensure account has sufficient funds
# Run Hardhat in verbose mode
npx hardhat compile --verbose
# Run Foundry with debug output
forge build -vvvv- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Write tests for your changes
- Ensure all tests pass
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Solidity style guide
- Write comprehensive tests
- Document all functions
- Use TypeScript for scripts
- Update TypeChain bindings
- Maintain high test coverage
- Hardhat Documentation
- Foundry Book
- OpenZeppelin Contracts
- ERC-4337 Specification
- Arbitrum Documentation
This project is licensed under the MIT License - see the LICENSE file for details.