📋Smart Contract APIs
Complete API documentation for all DreamLend smart contracts. This guide covers all public functions, events, and data structures.
🏛️ DreamLend Contract API
Contract Address: 0xddDa4e2B1B8E6f06086F103dA6358E7aCbd020ec
Core Functions
createLoanOffer
createLoanOfferCreates a new loan offer with specified terms.
function createLoanOffer(
address tokenAddress,
uint256 amount,
uint256 interestRate,
uint256 duration,
address collateralAddress,
uint256 collateralAmount,
uint256 minCollateralRatioBPS,
uint256 liquidationThresholdBPS,
uint256 maxPriceStaleness
) external returns (uint256 loanId)Parameters:
tokenAddress: Address of the token to lendamount: Amount of tokens to lend (in token's decimals)interestRate: Annual interest rate in basis points (e.g., 1500 = 15%)duration: Loan duration in secondscollateralAddress: Address of required collateral tokencollateralAmount: Required collateral amountminCollateralRatioBPS: Minimum collateral ratio in basis pointsliquidationThresholdBPS: Liquidation threshold in basis pointsmaxPriceStaleness: Maximum allowed price staleness in seconds
Returns:
loanId: Unique identifier for the created loan offer
Events Emitted:
LoanOfferCreated(uint256 indexed loanId, address indexed lender, LoanOffer offer)
acceptLoanOffer
acceptLoanOfferAccepts an existing loan offer by providing collateral.
function acceptLoanOffer(uint256 loanId) externalParameters:
loanId: ID of the loan offer to accept
Requirements:
Loan must be in Pending status
Caller must have approved sufficient collateral tokens
Collateral amount must meet minimum requirements
Events Emitted:
LoanOfferAccepted(uint256 indexed loanId, address indexed borrower)
repayLoan
repayLoanRepays a loan in full, releasing all collateral.
function repayLoan(uint256 loanId) externalParameters:
loanId: ID of the loan to repay
Requirements:
Loan must be in Active status
Caller must be the borrower
Caller must have approved sufficient repayment tokens
Events Emitted:
LoanRepaid(uint256 indexed loanId, uint256 repaymentAmount)
makePartialRepayment
makePartialRepaymentMakes a partial repayment on an active loan.
function makePartialRepayment(uint256 loanId, uint256 amount) externalParameters:
loanId: ID of the loan to partially repayamount: Amount to repay (in loan token decimals)
Requirements:
Loan must be in Active status
Caller must be the borrower
Amount must be greater than 0 and less than total owed
Events Emitted:
PartialRepayment(uint256 indexed loanId, uint256 amount, uint256 remainingDebt)
liquidateLoan
liquidateLoanLiquidates an unhealthy or overdue loan.
function liquidateLoan(uint256 loanId) externalParameters:
loanId: ID of the loan to liquidate
Requirements:
Loan must be liquidatable (unhealthy or overdue)
Price feeds must not be stale
Caller receives liquidation bonus
Events Emitted:
LoanLiquidated(uint256 indexed loanId, address indexed liquidator, uint256 liquidationBonus)
addCollateral
addCollateralAdds additional collateral to an active loan.
function addCollateral(uint256 loanId, uint256 amount) externalParameters:
loanId: ID of the loan to add collateral toamount: Amount of collateral to add
Requirements:
Loan must be in Active status
Caller must be the borrower
Caller must have approved sufficient collateral tokens
Events Emitted:
CollateralAdded(uint256 indexed loanId, uint256 amount, uint256 newCollateralAmount)
removeCollateral
removeCollateralRemoves excess collateral from an active loan.
function removeCollateral(uint256 loanId, uint256 amount) externalParameters:
loanId: ID of the loan to remove collateral fromamount: Amount of collateral to remove
Requirements:
Loan must be in Active status
Caller must be the borrower
Remaining collateral must meet minimum ratio requirements
Events Emitted:
CollateralRemoved(uint256 indexed loanId, uint256 amount, uint256 newCollateralAmount)
View Functions
getLoan
getLoanReturns complete loan information.
function getLoan(uint256 loanId) external view returns (LoanOffer memory)calculateTotalRepayment
calculateTotalRepaymentCalculates total repayment amount including interest.
function calculateTotalRepayment(uint256 loanId) external view returns (uint256)calculateInterest
calculateInterestCalculates accrued interest for a loan.
function calculateInterest(uint256 loanId) external view returns (uint256)getLoanHealthFactor
getLoanHealthFactorReturns loan health information.
function getLoanHealthFactor(uint256 loanId) external view returns (
uint256 currentRatio,
bool priceStale
)isLoanLiquidatable
isLoanLiquidatableChecks if a loan can be liquidated.
function isLoanLiquidatable(uint256 loanId) external view returns (bool)Data Structures
LoanOffer
LoanOfferstruct LoanOffer {
uint256 id;
address lender;
address borrower;
address tokenAddress;
uint256 amount;
uint256 interestRate;
uint256 duration;
address collateralAddress;
uint256 collateralAmount;
uint256 minCollateralRatioBPS;
uint256 liquidationThresholdBPS;
uint256 maxPriceStaleness;
LoanStatus status;
uint256 startTime;
uint256 repaidAmount;
}LoanStatus
LoanStatusenum LoanStatus {
Pending, // 0 - Loan offer created, waiting for borrower
Active, // 1 - Loan accepted and active
Repaid, // 2 - Loan fully repaid
Defaulted, // 3 - Loan liquidated due to default
Cancelled // 4 - Loan offer cancelled by lender
}Events
LoanOfferCreated
LoanOfferCreatedevent LoanOfferCreated(
uint256 indexed loanId,
address indexed lender,
LoanOffer offer
);LoanOfferAccepted
LoanOfferAcceptedevent LoanOfferAccepted(
uint256 indexed loanId,
address indexed borrower
);LoanRepaid
LoanRepaidevent LoanRepaid(
uint256 indexed loanId,
uint256 repaymentAmount
);LoanLiquidated
LoanLiquidatedevent LoanLiquidated(
uint256 indexed loanId,
address indexed liquidator,
uint256 liquidationBonus
);🎁 RewardsDistributor Contract API
Contract Address: 0x1ee1E4d84636FFDb8de6Dc684475C8f2Bdf5699c
Core Functions
startAccruingRewards
startAccruingRewardsStarts reward accrual for a user.
function startAccruingRewards(address user, uint256 principal) externalstopAccruingRewards
stopAccruingRewardsStops reward accrual for a user.
function stopAccruingRewards(address user) externalclaimRewards
claimRewardsClaims accumulated rewards.
function claimRewards() external returns (uint256 rewardAmount)getAccumulatedRewards
getAccumulatedRewardsReturns accumulated rewards for a user.
function getAccumulatedRewards(address user) external view returns (uint256)💎 DreamerToken Contract API
Contract Address: 0xf68F7B7FD9629f4990A5AB7181C2EE0E8b496B4B
Standard ERC20 functions plus:
mint
mintMints new DREAM tokens (only by authorized contracts).
function mint(address to, uint256 amount) externalburn
burnBurns DREAM tokens.
function burn(uint256 amount) external🔮 Oracle Integration API
DIA Oracle V2
Contract Address: 0x9206296Ea3aEE3E6bdC07F7AaeF14DfCf33d865D
latestRoundData
latestRoundDataReturns latest price data (Chainlink AggregatorV3Interface compatible).
function latestRoundData() external view returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)🛠️ Integration Examples
Creating a Loan Offer
const tx = await dreamLendContract.createLoanOffer(
"0x...", // USDT address
ethers.parseUnits("1000", 6), // 1000 USDT
1500, // 15% APR
30 * 24 * 60 * 60, // 30 days
"0x...", // WBTC address
ethers.parseUnits("0.05", 8), // 0.05 WBTC
15000, // 150% min ratio
12000, // 120% liquidation threshold
3600 // 1 hour max staleness
);Accepting a Loan
// First approve collateral
await collateralToken.approve(dreamLendAddress, collateralAmount);
// Then accept the loan
const tx = await dreamLendContract.acceptLoanOffer(loanId);Checking Loan Health
const { currentRatio, priceStale } =
await dreamLendContract.getLoanHealthFactor(loanId);
const healthPercentage = Number(currentRatio) / 100;
console.log(`Loan health: ${healthPercentage}%`);🔐 Security Considerations
Access Control
Only loan participants can interact with their loans
Liquidations are permissionless when conditions are met
Reward distribution is controlled by the protocol
Price Feed Security
All price feeds have staleness checks
Liquidations are blocked with stale prices
Multiple oracle sources for redundancy
Reentrancy Protection
All state-changing functions use ReentrancyGuard
External calls are made after state updates
Token transfers use SafeERC20
For more detailed examples and integration guides, see our Developer Resources.
Last updated
