LogoLogo
  • 🌊💸 Welcome to Fluidity Money
  • Docs
    • 📚Learning and getting started
      • 🔮Why Fluidity?
      • ❓What are Fluid Assets?
      • 🌟How do you get a Fluid Asset?
      • 💰How are the rewards earned?
      • 🗃️The Economics of a Fluid Asset
        • ✏️Transfer Reward Function (TRF) Example
      • 📋Tutorials
        • How to use Fluidity
    • 🏡Addresses
      • 🅰️Arbitrum
      • ☀️Solana
      • 💧Sui
      • 😳Superposition devnet
    • 🔠Fundamentals
      • 📄FAQ
      • 🔫Fluidity Wars
      • ⛏️Utility Mining
      • 🤝For arbitrage
      • 🏛️Understanding the $FLY Governance Token
        • 💸Fluidity $FLY Vaults
        • 🪙Understanding $FLY Tokenomics
      • ⛓️Launch restrictions (mint limits)
      • 🔓Governance structure
      • 🚂Advisory team
      • 👩‍🏫👩🏫 Laws of Fluidity
      • 🛣️Roadmap
        • 🚀Product roadmap
        • 🌤️Decentralisation roadmap
      • 👩‍🚀Why instant rewards?
    • 💸Use-cases
      • ⌨️Developers
      • 🦄DEXs
      • ✨Fluid Assets and Utility
      • 🎮Metaverse and Gaming
      • 🖼️NFTs
      • 💳Transactions and Payments
      • 🌊Other Use-Cases
    • 🎪Developers
      • 🏢Architecture
        • 👷Worker architecture
        • 💠Ethereum contract architecture
        • ☀️Solana program architecture
      • 🎍EVM ABIs
      • ☀️Solana account structure
      • 🙋How can I Fluid Wrap my custom token?
      • 📊GraphQL
      • 🧾Dev Tutorials
        • ⛏️Creating a New Utility Mining Client
        • 👩‍💻Supporting a New Application
        • 💸Sending and receiving a Fluid Asset
        • 🚄Supporting a Fluid Asset on your DEX/AMM/exchange
        • 🎁Wrapping and unwrapping a Fluid Asset in your app
        • 🌊Providing liquidity for a Fluid Asset
      • 📔Whitepapers
    • 💪Security
      • 🤳Website/infrastructure security
      • 📥Dropboxes
      • 💰Bounty program
      • 📜Audits completed
      • 🫂Contactable team
    • 🤝Partnerships/collaboration
      • 🤝Partnering with us
      • 👐Join us!
      • 💬Fluidifying your asset
        • 😎Brand assets
    • Useful links
      • Fluidity website and whitepapers
      • Fluidity Whitepaper v1.0
      • Discord server
      • Medium
      • Telegram
Powered by GitBook
On this page

Was this helpful?

  1. Docs
  2. Developers
  3. Architecture

Ethereum contract architecture

PreviousWorker architectureNextSolana program architecture

Last updated 2 years ago

Was this helpful?

Ethereum support is built as a trio of contracts:

  1. Token - the token for the wrapped asset being traded/transferred, supporting swapping in, swapping out, ERC20 features

  2. WorkerConfig - configuration for each token

  3. LiquidityProvider - abstract wrapper that holds custody of ctokens/atokens

Ethereum high level

Features in pseudocode form

Wrapping in/swapping in (erc20In)

  1. Token takes the user's unwrapped tokens and moves it into the contract

  2. Token sends the unwrapped tokens to the LiquidityProvider

  3. LiquidityProvider provides it to the underlying liquidity provider (Compound or AAVE)

  4. Underlying liquidity provider (Compound/AAVE) mints cToken/aToken with the amount given

  5. LiquidityProvider receives cToken/aToken adjusted to the "exchange rate" of the cToken/aToken (unwrapped token/exchange rate)

  6. Token sends the user an amount equal to the initial unwrapped token of the Fluid Asset form using the mint function

Wrapping out/swapping out (erc20Out)

  1. Token burns the minted amount owed to the user wrapping out of the contract

  2. Underlying LiquidityProvider "redeems" the amount of token that the user wishes to unwrap - the underlying redemption process (Compound/AAVE) calculates the amount owed using the amount of the cToken/aToken - on Compound this is cToken * exchange rate

  3. The LiquidityProvider sends the Token the amount redeemed

  4. The Token sends the user their unwrapped asset after redemption

Batch reward process (batchReward)

  1. Worker sends to the Token a batch of winners and the span of blocks that was won

  2. Token aggregates the amounts that should be paid out to each winner

  3. Token aggregates the remaining pool amount

  4. Token rewards each user with the internal reward function rewardPool

Reward pool amount calculation (rewardPool)

  1. LiquidityProvider calculates the balance of the underlying assets based on the exchange rate of the cTokens/aTokens held in the Compound/AAVE pool

  2. Token calculates the difference between the amount deposited by users with the amount reported by the LiquidityProvider for the prize pool amount

  3. Token calls the reward from pool function (rewardFromPool) - which simply calls the mint function and emits a log

🎪
🏢
💠
https://github.com/fluidity-money/fluidity-app/tree/production/contracts/ethereum