VarlaCore
ℹ Source
contracts/VarlaCore.sol — inherits ERC1155Holder, AccessManaged, ReentrancyGuard Immutables
| Name | Type | Description |
|---|---|---|
positionsToken | IERC1155 | The ERC1155 contract holding prediction market positions (e.g. CTF) |
collateralToken | IERC20 | The ERC20 token used for borrowing (e.g. USDC) |
collateralDecimals | uint8 | Decimal precision of the collateral token |
pool | IVarlaPool | The lending pool that provides liquidity |
MIN_BORROW | uint256 | Minimum borrow amount to prevent dust positions |
Key Structs
LtvConfig
Per-position LTV configuration with three risk tiers (all values in WAD — 18 decimals).
solidity
struct LtvConfig {
uint256 conservative; // e.g. 0.50e18 → 50% LTV
uint256 moderate; // e.g. 0.65e18 → 65% LTV
uint256 risk; // e.g. 0.80e18 → 80% LTV
} LiquidationConfig
solidity
struct LiquidationConfig {
uint256 targetHealthFactor; // HF target after liquidation
uint256 healthFactorForMaxBonus; // HF threshold for max bonus
uint256 liquidationBonusFactorBps; // Bonus factor in basis points
uint256 dustThreshold; // Min debt to avoid dust
uint256 collateralDustThreshold; // Min collateral to avoid dust
} TierLiquidationConfig
solidity
struct TierLiquidationConfig {
uint16 maxLiquidationBonusBps; // Max bonus for this risk tier
uint16 liquidationFeeBps; // Protocol fee on liquidations
} RiskTier enum
solidity
enum RiskTier { CONSERVATIVE, MODERATE, RISK } Each user selects a risk tier when opening a position. Higher tiers allow higher LTV but face steeper liquidation penalties.
UserAccount
solidity
struct UserAccount {
uint256[] positionIds; // Deposited ERC1155 token IDs
uint256 scaledDebt; // Scaled debt (before interest)
uint256 borrowTimestamp; // When the user last borrowed
} User-Facing Functions
| Function | Description |
|---|---|
deposit(uint256[] positionIds, uint256[] amounts) | Deposit ERC1155 prediction market positions as collateral. Transfers tokens into VarlaCore. |
withdraw(uint256[] positionIds, uint256[] amounts) | Withdraw collateral. Reverts if withdrawal would make position unhealthy. |
borrow(uint256 amount) | Borrow collateral token (e.g. USDC) against deposited positions. Must maintain health factor ≥ 1.0. Minimum borrow enforced. |
repay(uint256 amount) | Repay outstanding debt. Partial repayment allowed. |
repayAll() | Repay full outstanding debt including accrued interest. |
View Functions
| Function | Returns |
|---|---|
getHealthFactor(address user) | Current health factor (WAD). < 1.0 → liquidatable. |
getAccountValues(address user) | AccountValues — portfolio value, collateral value, liquidation eligibility, oracle guard state. |
getUserPositionIds(address user) | Array of deposited ERC1155 token IDs. |
getUserDebt(address user) | Current debt including accrued interest. |
getPositionLtv(uint256 positionId) | LtvConfig for the given position. |
Admin Functions
⚠ Access restricted
These functions are gated by
AccessManaged — only addresses with the appropriate role in VarlaAccessManager can call them.
| Function | Role | Description |
|---|---|---|
setLtvConfig(uint256 pid, LtvConfig) | RISK_MANAGER | Set LTV tiers for a position ID |
setLiquidationConfig(...) | RISK_MANAGER | Update liquidation parameters |
setTierLiquidationConfig(RiskTier, ...) | RISK_MANAGER | Configure per-tier liquidation bonus/fee |
setLiquidator(address) | Admin | Set the liquidator contract address |
Events
solidity
event Deposited(address indexed user, uint256[] positionIds, uint256[] amounts);
event Withdrawn(address indexed user, uint256[] positionIds, uint256[] amounts);
event Borrowed(address indexed user, uint256 amount);
event Repaid(address indexed user, uint256 amount);
event Liquidated(address indexed user, address indexed liquidator, uint256 debtRepaid, uint256 collateralSeized); ✦ Key Takeaways
- VarlaCore is the central contract — it holds all ERC1155 collateral and manages all user debt
- All collateral is ERC1155 (prediction market positions), all debt is ERC20 (e.g. USDC)
- Health factor < 1.0 triggers liquidation eligibility — see VarlaLiquidator
- Three risk tiers (Conservative, Moderate, Risk) with different LTV and liquidation parameters
- Protected by ReentrancyGuard and AccessManaged (RBAC via VarlaAccessManager)