Credit Line Factory
The Credit Line Factory is the main entry point for creating new credit lines. It deploys and manages individual credit line contracts.
Contract Address: 0x... (Base Mainnet)
Overview
The Credit Line Factory is responsible for deploying new credit line contracts. Each credit line is represented by an ERC20 token that lenders can purchase to fund the borrower's credit line.
Key Functions
createCreditLine
function createCreditLine(
string memory name,
uint256 creditLimit,
uint256 apy,
address underlyingAsset
) external returns (address creditLineAddress)Parameters
- name: The name of the credit line (e.g., "CL.1234.001")
- creditLimit: Maximum amount that can be borrowed
- apy: Annual percentage yield (in basis points, e.g., 500 = 5%)
- underlyingAsset: Address of the underlying token (USDC, crvUSD, etc.)
Returns
The address of the newly deployed credit line contract.
getCreditLinesByBorrower
function getCreditLinesByBorrower(address borrower)
external view returns (address[] memory creditLines)Events
CreditLineCreated
event CreditLineCreated(
address indexed borrower,
address indexed creditLine,
string name,
uint256 creditLimit,
uint256 apy,
address underlyingAsset
)Usage Examples
Creating a Credit Line
// Example: Create a $10,000 USDC credit line with 5% APY
const factory = await ethers.getContractAt("CreditLineFactory", factoryAddress);
const tx = await factory.createCreditLine(
"CL.1234.001",
ethers.utils.parseUnits("10000", 6), // 10,000 USDC (6 decimals)
500, // 5% APY (500 basis points)
usdcAddress
);
const receipt = await tx.wait();
const event = receipt.events.find(e => e.event === 'CreditLineCreated');
const creditLineAddress = event.args.creditLine;Querying Credit Lines
// Get all credit lines created by a borrower
const creditLines = await factory.getCreditLinesByBorrower(borrowerAddress);
// Iterate through credit lines
for (const creditLineAddress of creditLines) {
const creditLine = await ethers.getContractAt("CreditLineToken", creditLineAddress);
const name = await creditLine.name();
const creditLimit = await creditLine.creditLimit();
console.log(`Credit Line: ${name}, Limit: ${creditLimit}`);
}Security Considerations
- Access Control: Only the factory owner can upgrade the implementation
- Input Validation: All parameters are validated before deployment
- Gas Optimization: Uses minimal proxy pattern for efficient deployment
- Reentrancy Protection: Protected against reentrancy attacks
Integration with Other Contracts
The factory works closely with several other contracts in the system:
Credit Line Token
Each credit line deploys an ERC20 token that represents the investment opportunity.
Principal Pool
Manages the actual deposits and redemptions for each credit line.
Interest Pool
Handles interest payments and vesting schedules.
Liquidity Manager
Manages Aerodrome pool integration for secondary market trading.