Pools API
LIVEThe Pools API provides programmatic access to Defactor's lending infrastructure. Create and manage lending pools with RWA collateral, supply capital, borrow assets, and automate liquidation workflows. Includes both standard pools (ERC20CollateralPool) and counterparty pools for bilateral agreements.
Smart Contract
ERC20CollateralPoolSolidity ^0.8.20ERC20CollateralPoolAgent Workflow: Pool Interaction
Complete workflow for an AI agent to discover, analyze, and interact with lending pools.
1// Complete Pool Interaction Workflow for AI Agents2import { ERC20CollateralPool, SelfProvider } from '@defactor/defactor-sdk'3import { ethers } from 'ethers'45// Initialize6const provider = new SelfProvider.SelfProvider<ERC20CollateralPool>(7 ERC20CollateralPool,8 POOL_CONTRACT_ADDRESS,9 RPC_URL,10 AGENT_PRIVATE_KEY11)1213// 1. Discover available pools14const totalPools = await provider.contract.getTotalPools()15const pools = await provider.contract.getPools(0n, totalPools)1617// 2. Analyze pool opportunities18const bestPool = pools.reduce((best, pool, idx) => {19 const utilization = Number(pool.totalBorrowed) / Number(pool.hardCap)20 const rate = Number(pool.interestRate) / 100 // basis points to %21 // Higher rate + lower utilization = better opportunity22 const score = rate * (1 - utilization)23 return score > best.score ? { idx, score, pool } : best24}, { idx: 0, score: 0, pool: pools[0] })2526// 3. Approve lending token27const lendingToken = new ethers.Contract(28 bestPool.pool.lendingToken,29 ['function approve(address,uint256)'],30 wallet31)32await lendingToken.approve(POOL_CONTRACT_ADDRESS, LEND_AMOUNT)3334// 4. Lend to the best pool35await provider.contract.lend(BigInt(bestPool.idx), LEND_AMOUNT)3637// 5. Monitor and collect after deadline38// Set up a cron job or interval to check pool status39const poolDetails = await provider.contract.getPoolDetails(BigInt(bestPool.idx))40if (poolDetails.deadline < BigInt(Date.now() / 1000)) {41 await provider.contract.collectPool(BigInt(bestPool.idx))42}ERC20CollateralPool Methods
Core lending pool smart contract methods. Accessible via SDK or direct contract interaction.
Counterparty Pool Methods
Bilateral lending agreements between specific counterparties with custom terms.
Key Concepts
Soft Cap / Hard Cap
Soft cap is the minimum pool size to activate. Hard cap is the maximum. Pool activates between these bounds.
Interest Rate (Basis Points)
Rates expressed in basis points. 500 = 5%, 1000 = 10%. Divide by 10000 for decimal rate.
Collateral Ratio
Required collateral as percentage of borrowed amount. 15000 = 150% collateralization required.
Health Factor
Ratio of collateral value to debt. Below 10000 (100%) triggers liquidation eligibility.