📋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

Creates 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 lend

  • amount: Amount of tokens to lend (in token's decimals)

  • interestRate: Annual interest rate in basis points (e.g., 1500 = 15%)

  • duration: Loan duration in seconds

  • collateralAddress: Address of required collateral token

  • collateralAmount: Required collateral amount

  • minCollateralRatioBPS: Minimum collateral ratio in basis points

  • liquidationThresholdBPS: Liquidation threshold in basis points

  • maxPriceStaleness: 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

Accepts an existing loan offer by providing collateral.

Parameters:

  • 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

Repays a loan in full, releasing all collateral.

Parameters:

  • 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

Makes a partial repayment on an active loan.

Parameters:

  • loanId: ID of the loan to partially repay

  • amount: 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

Liquidates an unhealthy or overdue loan.

Parameters:

  • 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

Adds additional collateral to an active loan.

Parameters:

  • loanId: ID of the loan to add collateral to

  • amount: 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

Removes excess collateral from an active loan.

Parameters:

  • loanId: ID of the loan to remove collateral from

  • amount: 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

Returns complete loan information.

calculateTotalRepayment

Calculates total repayment amount including interest.

calculateInterest

Calculates accrued interest for a loan.

getLoanHealthFactor

Returns loan health information.

isLoanLiquidatable

Checks if a loan can be liquidated.

Data Structures

LoanOffer

LoanStatus

Events

LoanOfferCreated

LoanOfferAccepted

LoanRepaid

LoanLiquidated

🎁 RewardsDistributor Contract API

Contract Address: 0x1ee1E4d84636FFDb8de6Dc684475C8f2Bdf5699c

Core Functions

startAccruingRewards

Starts reward accrual for a user.

stopAccruingRewards

Stops reward accrual for a user.

claimRewards

Claims accumulated rewards.

getAccumulatedRewards

Returns accumulated rewards for a user.

💎 DreamerToken Contract API

Contract Address: 0xf68F7B7FD9629f4990A5AB7181C2EE0E8b496B4B

Standard ERC20 functions plus:

mint

Mints new DREAM tokens (only by authorized contracts).

burn

Burns DREAM tokens.

🔮 Oracle Integration API

DIA Oracle V2

Contract Address: 0x9206296Ea3aEE3E6bdC07F7AaeF14DfCf33d865D

latestRoundData

Returns latest price data (Chainlink AggregatorV3Interface compatible).

🛠️ Integration Examples

Creating a Loan Offer

Accepting a Loan

Checking Loan Health

🔐 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 Resourcesarrow-up-right.

Last updated