defactor.ai

Smart Contracts

Complete reference for all Defactor smart contracts deployed on-chain. Includes function signatures, event definitions, and deployment information for each supported network. AI agents can interact with these contracts directly via ethers.js or through the SDK.

ERC20CollateralPool

Custom (Solidity ^0.8.20)

Core lending pool contract. Manages collateralized lending with ERC-20 tokens. Supports multiple collateral types per pool, configurable interest rates, and automated liquidation.

Features

Multi-collateral supportConfigurable interest rates (basis points)Soft/hard cap mechanicsAutomated liquidation triggersLender collection after deadline

Key Functions

FunctionReturnsDescription
getTotalPools()uint256Total number of pools
getPools(uint256 offset, uint256 limit)Pool[]Paginated pool list
lend(uint256 poolId, uint256 amount)voidSupply capital to pool
borrow(uint256 poolId, uint256 amount)voidBorrow from pool
repay(uint256 poolId, uint256 amount)voidRepay borrowed amount
collectPool(uint256 poolId)voidCollect returns after deadline
liquidatePool(uint256 poolId)voidLiquidate under-collateralized pool

Events

PoolCreated(uint256 indexed poolId, address creator)Lent(uint256 indexed poolId, address lender, uint256 amount)Borrowed(uint256 indexed poolId, address borrower, uint256 amount)Repaid(uint256 indexed poolId, address borrower, uint256 amount)PoolCollected(uint256 indexed poolId, address lender, uint256 amount)PoolLiquidated(uint256 indexed poolId)

ERC-20 Token Factory

ERC-20 (OpenZeppelin)

Factory contract for deploying standard ERC-20 tokens representing tokenized real-world assets. Supports customizable supply, decimals, and metadata.

Features

Standard fungible tokenConfigurable supply and decimalsMintable / Burnable optionsPausable transfersSnapshot capability

Key Functions

FunctionReturnsDescription
deploy(string name, string symbol, uint256 supply)addressDeploy new ERC-20 token
mint(address to, uint256 amount)voidMint new tokens (owner only)
burn(uint256 amount)voidBurn tokens from caller
transfer(address to, uint256 amount)boolTransfer tokens
approve(address spender, uint256 amount)boolApprove spending

Events

Transfer(address indexed from, address indexed to, uint256 value)Approval(address indexed owner, address indexed spender, uint256 value)

ERC-3643 (T-REX)

ERC-3643 / T-REX

Compliant security token standard with built-in identity registry and transfer restrictions. Used for regulated real-world asset tokens that require KYC/AML compliance.

Features

On-chain identity registryTransfer compliance checksCountry-based restrictionsClaim-based identity verificationForced transfers (regulatory)Token recovery mechanism

Key Functions

FunctionReturnsDescription
isVerified(address)boolCheck if address has valid identity
identityRegistry()addressGet identity registry contract
compliance()addressGet compliance contract
transfer(address to, uint256 amount)boolCompliant transfer (checks identity)
forcedTransfer(address from, address to, uint256 amount)voidRegulatory forced transfer
freeze(address account)voidFreeze account (regulatory)
unfreeze(address account)voidUnfreeze account

Events

Transfer(address indexed from, address indexed to, uint256 value)IdentityVerified(address indexed account)AccountFrozen(address indexed account)AccountUnfrozen(address indexed account)

Engage (Staking & Governance)

Custom (Solidity ^0.8.20)

Combined staking and governance contract for the FACTR token. Manages staking plans with configurable lock periods, reward distribution, and on-chain governance voting.

Features

Multiple staking plansTime-locked stakingReward accumulationGovernance proposal creationWeighted voting (by stake)Buyback mechanism

Key Functions

FunctionReturnsDescription
getStakingPlans()Plan[]List all staking plans
stake(uint256 planId, uint256 amount)voidStake FACTR tokens
unstake(uint256 planId)voidUnstake after lock period
claimRewards(uint256 planId)voidClaim staking rewards
vote(uint256 proposalId, bool support)voidVote on proposal
createProposal(string title, string desc, bytes[] actions)uint256Create governance proposal

Events

Staked(address indexed user, uint256 planId, uint256 amount)Unstaked(address indexed user, uint256 planId, uint256 amount)RewardsClaimed(address indexed user, uint256 amount)ProposalCreated(uint256 indexed proposalId, address proposer)Voted(uint256 indexed proposalId, address voter, bool support)

CounterpartyPool

Custom (Solidity ^0.8.20)

Bilateral lending pool contract for private agreements between two specific parties. Supports custom terms, collateral requirements, and dispute resolution.

Features

Bilateral agreementsCustom terms per poolPrivate pool accessDispute resolutionEscrow mechanism

Key Functions

FunctionReturnsDescription
createPool(address counterparty, ...params)uint256Create bilateral pool
acceptPool(uint256 poolId)voidCounterparty accepts terms
depositCollateral(uint256 poolId, uint256 amount)voidDeposit collateral
withdraw(uint256 poolId)voidWithdraw after settlement

Events

PoolCreated(uint256 indexed poolId, address creator, address counterparty)PoolAccepted(uint256 indexed poolId)CollateralDeposited(uint256 indexed poolId, uint256 amount)PoolSettled(uint256 indexed poolId)

Direct ABI Interaction

For agents that prefer direct contract interaction without the SDK:

Direct Contract Interactiontypescript
1// Loading Contract ABI for Direct Interaction
2import { ethers } from 'ethers'
3
4// The SDK includes ABIs, but for direct interaction:
5const ERC20_COLLATERAL_POOL_ABI = [
6 "function getTotalPools() view returns (uint256)",
7 "function getPools(uint256 offset, uint256 limit) view returns (tuple[])",
8 "function lend(uint256 poolId, uint256 amount)",
9 "function borrow(uint256 poolId, uint256 amount)",
10 "function repay(uint256 poolId, uint256 amount)",
11 "function collectPool(uint256 poolId)",
12 "function liquidatePool(uint256 poolId)",
13 "event Lent(uint256 indexed poolId, address lender, uint256 amount)",
14 "event Borrowed(uint256 indexed poolId, address borrower, uint256 amount)"
15]
16
17// Create contract instance
18const provider = new ethers.JsonRpcProvider('https://polygon-rpc.com')
19const wallet = new ethers.Wallet(PRIVATE_KEY, provider)
20const pool = new ethers.Contract(POOL_ADDRESS, ERC20_COLLATERAL_POOL_ABI, wallet)
21
22// Direct interaction
23const totalPools = await pool.getTotalPools()
24console.log('Total pools:', totalPools.toString())
25
26// Listen for events
27pool.on('Lent', (poolId, lender, amount) => {
28 console.log(`Pool ${poolId}: ${lender} lent ${ethers.formatEther(amount)}`)
29})

Event Monitoring for Agents

AI agents can subscribe to on-chain events to trigger automated responses. Use WebSocket providers for real-time event streaming.

Event Monitoringtypescript
1// Event Monitoring for AI Agents
2// Listen for on-chain events to trigger automated responses
3
4import { ethers } from 'ethers'
5
6const provider = new ethers.WebSocketProvider('wss://polygon-rpc.com')
7const pool = new ethers.Contract(POOL_ADDRESS, ABI, provider)
8
9// Monitor new lending activity
10pool.on('Lent', async (poolId, lender, amount) => {
11 console.log(`[Event] New lend: Pool ${poolId}, Amount: ${ethers.formatEther(amount)}`)
12
13 // Agent can react to events
14 const poolDetails = await pool.getPoolDetails(poolId)
15 if (poolDetails.totalLent >= poolDetails.softCap) {
16 console.log('[Agent] Pool reached soft cap, considering borrowing')
17 }
18})
19
20// Monitor liquidation opportunities
21pool.on('Borrowed', async (poolId, borrower, amount) => {
22 const details = await pool.getPoolDetails(poolId)
23 const healthFactor = Number(details.healthFactor)
24
25 if (healthFactor < 12000) { // Below 120%
26 console.log(`[Agent] Pool ${poolId} health factor low: ${healthFactor/100}%`)
27 console.log('[Agent] Monitoring for liquidation opportunity')
28 }
29})