Trust scores are calculated off-chain using the algorithm in the previous section. The smart contracts handle money movement, not social graph analysis. This keeps gas costs low (Base L2 fees are ~$0.01 per transaction).
Each loan gets its own smart contract with parameters: principal P, maturity date T_maturity, borrower address, and verified Farcaster ID.
2. Lenders Contribute
Lenders send funds to the contract. Each contribution updates:
Where:
C_lender = cumulative contribution from this lender
R_total = total raised across all lenders
Trust scores are calculated off-chain and displayed in the UI. The contract only tracks capital flow.
3. Funds Disbursed to Borrower
Once fully funded, borrower can claim funds within the disbursement window:
Conditions:
R_total β₯ P (fully funded)
T_current β€ T_deadline + 14 days
Funds not yet disbursed
Action: Transfer R_total to borrower
4. Repayment & Claims
Borrower repays flexibly. Lenders claim their pro-rata share using an accumulator pattern for gas efficiency.
On Each Repayment:
Where:
A = accumulator (tracks total repaid per $1 of principal)
r = repayment amount
k = precision constant (10^18)
P = original principal
Claimable Amount per Lender:
Where:
C_lender = lender's contribution
D_lender = amount already claimed by lender
Result is proportional to contribution share
This approach calculates pro-rata shares in O(1) time per lender, rather than iterating over all lenders. Overpayments automatically distribute as bonuses.
Tipping on Repayment
Borrowers can express gratitude by repaying more than the principal amount. The smart contract automatically distributes tips proportionally among all lenders.
How it works:
The accumulator pattern handles this automaticallyβany repayment amount distributes proportionally, whether it's 50%, 100%, or 110% of principal.
Pro Tip: Tips strengthen your reputation and show gratitude to supporters. Even small tips (5-10%) signal reliability and appreciation.
Gas Optimization
The accumulator pattern is crucial for scalability:
Approach
Gas Cost per Lender
Gas for 100 Lenders
Accumulator (Our Method)
~40,000 gas
~40,000 gas
Iterate All Lenders
~40,000 gas
~4,000,000 gas
With Base L2 gas at ~$0.01 per 40,000 gas, our method keeps costs constant regardless of lender count.
Security Considerations
Reentrancy Protection: All external calls use nonReentrant modifier
Access Control: Only borrower can disburse funds
Overflow Protection: Solidity 0.8.20 has built-in overflow checks