Secured Finance Docs
HomeBlogGitHubCommunityStablecoin ↗Fixed Income ↗
  • Introduction
    • ⚜️About Secured Finance
    • 🎏Vision & Mission
    • 🌍Ecosystem Overview
    • 🏁Roadmap
      • Roadmap 2024
      • Roadmap 2023
    • 📚DeFi Starter Guide
      • 🔄DeFi vs CeFi
      • 👛Wallet Setup
      • ⛽Gas Fees
      • 🤝DApps
      • 🏦DEX
      • 📝Smart Contracts
      • 🪙Governance Tokens
      • 🏛️DAOs
  • USDFC Stablecoin
    • 📢Overview
    • 🧙Getting Started
      • ⛽Creating Your First Trove
      • 👛Minting USDFC Step-by-Step
      • 🤝Managing Collateral Effectively
      • 🏦Monitoring Your Position
      • 🏊Using the Stability Pool
      • 💸Redeeming USDFC
    • 🔦Core Mechanics
      • 🏗️System Overview
      • ✏️The Trove System
      • 💰Mint & Borrow
      • 🚰Liquidation
      • 💸Redemption
      • 🧀Protocol Fees
    • 🎓Advanced Topics
      • 🚨Recovery Mode
    • 📔Contracts and Security
    • ❓FAQs
  • Fixed-Rate Lending
    • 📢Overview
      • 📖White Paper
      • 🎓Concept Paper
    • 🧙‍♂️Getting Started
      • 💵Lending Assets
      • 🏦Borrowing Assets
      • 📈Managing Positions
      • 🎮Platform Guide
        • 💰Trading
          • 💲Supported Currencies
        • 📈Markets
        • 🐋Portfolio
        • Bridge
        • 🚀Points
        • 📣Campaign
    • 🔦Core Mechanics
      • 🧩Order Book System
        • 🆎Order Type
        • 🪃Order Life Cycle
          • 💫Case Study: Order Status & Transition
      • 📐Standardization
        • 💠Zero-Coupon Bonds
        • ⏳Fixed Maturity
      • 🏋️Collateralization
      • 🪙Tokenization
      • 🚰Liquidation
        • ⚖️Mark to Market
        • 👮‍♂️Liquidators
          • ✏️How Liquidation Works
        • 📋Liquidation Case Study
      • 🧀Protocol Fees
    • 🎓Advanced Topics
      • 📈APR vs APY
      • ➗ZC Bond Price to APR
      • 📉Discount Factor
      • 🏋️‍♀️ZC Bond Collateral
        • 🏍️ZC Collateral Case Study
      • 🧬Market Dynamics
        • ♻️Auto-Rolling
          • 💰Price Discovery for Auto-Rolling
        • 🗓️New Market Listing and Delisting
          • 🤝Itayose - Fair Price Discovery
      • 🛡️Safety Measures
        • 🚦Circuit Breaker
          • 🛑Price Range Limits
        • 🪄Base Price Adjustment
        • 🌎Emergency Global Settlement
      • ⛓️Orderbook Deep Dive
        • 🎡Orderbook Rotation
        • 🎋Red Black Tree
        • ⏯️Lazy Evaluation
        • ⏮️Genesis Value
        • 🔄Compound Factor
    • 📔Contracts and Security
    • ❓FAQs
  • Developer Portal
    • 🧑‍💻Introduction
    • 🔌API Reference
      • 📈Fixed-Rate Lending Subgraph
        • 🔍Query Examples
    • 📦SDK Reference
      • ⛽Fixed-Rate Lending SDK
      • 👛USDFC SDK
    • 🐛Bug Bounty
  • Community
    • 🤝Overview
    • 🏛️Governance
    • 🪙Tokenomics
      • 🔵Secured Finance Coin (SFC)
      • 🔶Secured Finance Points (SFP) v2
        • 🔶Secured Finance Points (SFP) v1
    • 🎗️Support & Contacts
  • Resources
    • 🖼️Media Kit
      • 🖼️Secured Finance Logo
      • 💲USDFC Logo
    • ⚖️Legal
      • 📜Terms of Use
      • 🔒Privacy Policy
      • ⚠️Risk Disclaimer
Powered by GitBook
On this page
  • Overview
  • How It Works
  • Common Smart Contract Languages
  • Key Parameters
  • Examples
  • Token Contracts
  • DeFi Protocol Contracts
  • Common Questions
  • Related Resources

Was this helpful?

Edit on GitHub
Export as PDF
  1. Introduction
  2. DeFi Starter Guide

Smart Contracts

Understanding the building blocks of DeFi applications

Overview

Smart contracts are self-executing programs that run on blockchain networks and automatically enforce agreements between parties without requiring intermediaries. They serve as the foundation for decentralized applications (DApps) and are essential building blocks of the DeFi ecosystem. Smart contracts enable complex financial operations to be executed transparently, securely, and without relying on traditional financial institutions.

How It Works

Smart contracts function based on predefined conditions coded into their logic. When these conditions are met, the contract automatically executes the specified actions. The process typically works as follows:

  1. Creation: Developers write code that defines the rules and conditions of the contract

  2. Deployment: The code is deployed to a blockchain network where it receives a unique address

  3. Interaction: Users interact with the contract by sending transactions to its address

  4. Execution: When triggered by a transaction, the contract executes its code across all nodes in the network

  5. State Change: The blockchain's state is updated to reflect the outcome of the execution

Smart contracts are:

  • Immutable: Once deployed, their code cannot be changed (though upgradeable patterns exist)

  • Deterministic: Given the same input, they always produce the same output

  • Transparent: Their code and all interactions are visible on the blockchain

  • Trustless: They execute exactly as programmed without relying on trusted third parties

Common Smart Contract Languages

Different blockchain platforms support different programming languages for smart contract development:

  • Solidity: The primary language for Ethereum and EVM-compatible chains

  • Rust: Used for Solana and Near Protocol

  • Move: Developed for the Diem blockchain and adopted by Aptos and Sui

  • Vyper: An alternative language for Ethereum focused on security

  • Ink: Used for Polkadot's parachain smart contracts

Key Parameters

Parameter
Description
Importance

Gas Limit

Maximum computational resources allowed

Prevents infinite loops and DoS attacks

State Variables

Data stored in the contract

Determines contract's memory footprint and gas costs

Access Controls

Permissions for different functions

Critical for security and privilege management

External Dependencies

Calls to other contracts

Potential security vulnerabilities if not handled properly

Upgradeability

Ability to modify contract logic

Trade-off between flexibility and security

Examples

Token Contracts

The most common smart contracts in DeFi are token contracts that implement standards like ERC-20 (fungible tokens) or ERC-721 (non-fungible tokens). These contracts define:

  • Token supply and distribution

  • Transfer mechanisms

  • Approval systems for third-party spending

  • Optional features like minting, burning, or pausing

// Simplified ERC-20 token example
contract SimpleToken {
    mapping(address => uint256) balances;
    
    function transfer(address to, uint256 amount) external {
        require(balances[msg.sender] >= amount, "Insufficient balance");
        balances[msg.sender] -= amount;
        balances[to] += amount;
    }
}

DeFi Protocol Contracts

More complex smart contracts power DeFi protocols:

  • Lending Protocols: Manage deposits, loans, interest rates, and liquidations

  • Automated Market Makers: Facilitate token swaps using mathematical formulas

  • Staking Contracts: Handle token delegation and reward distribution

  • Governance Systems: Enable decentralized decision-making through voting

Common Questions

What happens if there's a bug in a smart contract? Unlike traditional software, smart contracts cannot be directly patched once deployed. If a bug is discovered, developers typically must deploy a new contract and migrate users to it. Serious vulnerabilities can lead to loss of funds, as seen in several high-profile DeFi hacks.

Are smart contracts legally binding? The legal status of smart contracts varies by jurisdiction. Some regions have begun recognizing them as legally binding agreements, while others consider them technological tools rather than legal contracts.

How are smart contracts verified? Smart contract verification involves publishing the source code alongside the deployed bytecode so users can confirm they match. Projects often undergo security audits by specialized firms and may use formal verification techniques to mathematically prove correctness.

Can smart contracts access real-world data? Smart contracts cannot directly access external data. They rely on oracles—trusted data feeds that bring off-chain information onto the blockchain—for real-world data like price information or weather conditions.

What are the limitations of smart contracts? Smart contracts face several limitations including:

  • High execution costs for complex operations

  • Limited storage capacity

  • Inability to maintain secrets (all data is public)

  • Challenges with upgradeability and bug fixes

  • Dependency on external oracles for off-chain data

Related Resources

PreviousDEXNextGovernance Tokens

Last updated 22 days ago

Was this helpful?

📚
📝
Understanding DeFi vs CeFi
Decentralized Exchanges (DEX)
Interacting with DApps
Understanding Gas Fees
Understanding DAOs