defactor.ai

Pools API

LIVE

The 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

Contract: ERC20CollateralPool
Standard: Solidity ^0.8.20
Networks: Ethereum, Polygon, Base, BSC
SDK Class: ERC20CollateralPool

Agent Workflow: Pool Interaction

Complete workflow for an AI agent to discover, analyze, and interact with lending pools.

pool-agent-workflow.tstypescript
1// Complete Pool Interaction Workflow for AI Agents
2import { ERC20CollateralPool, SelfProvider } from '@defactor/defactor-sdk'
3import { ethers } from 'ethers'
4
5// Initialize
6const provider = new SelfProvider.SelfProvider<ERC20CollateralPool>(
7 ERC20CollateralPool,
8 POOL_CONTRACT_ADDRESS,
9 RPC_URL,
10 AGENT_PRIVATE_KEY
11)
12
13// 1. Discover available pools
14const totalPools = await provider.contract.getTotalPools()
15const pools = await provider.contract.getPools(0n, totalPools)
16
17// 2. Analyze pool opportunities
18const 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 opportunity
22 const score = rate * (1 - utilization)
23 return score > best.score ? { idx, score, pool } : best
24}, { idx: 0, score: 0, pool: pools[0] })
25
26// 3. Approve lending token
27const lendingToken = new ethers.Contract(
28 bestPool.pool.lendingToken,
29 ['function approve(address,uint256)'],
30 wallet
31)
32await lendingToken.approve(POOL_CONTRACT_ADDRESS, LEND_AMOUNT)
33
34// 4. Lend to the best pool
35await provider.contract.lend(BigInt(bestPool.idx), LEND_AMOUNT)
36
37// 5. Monitor and collect after deadline
38// Set up a cron job or interval to check pool status
39const 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.