Skip to content

TroveFi/playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

1 WINNER -> ALLOW PEOPLE TO CHOOSE THEIR OWN ODDS SO THEY CAN CHOOSE TO WIN AS BIG AS THEY WANT, OR JUST STAKE THEIR WITH SECURED GAINS SO EVERYONE HAS THEIR OWN VRF CASHOUT

my main concern is that with current architecture: not much reason for repeat users? not enough winners if only 1 per week or month...

Additions:

ADD WAY TO CLAIM DEPOSIT BACK AND YIELD BACK AND ALSO WAY TO GET EMAIL NOTIFICATIONS!!

ADD REFERRAL SYSTEM

Working on Contracts Notes: X Y MEV addition?

Current Dummy Values to Replace to Shift to Prod:

Currently away, ready to continue building soon & sorting out socials / growth avenues etc.

  1. protocols to consider for yield farming implentation: Mainnet: IncrementFi BloctoSwap Flowty Trado.one KittyPunch / PunchSwap More.Markets Sturdy.Finance Ankr Sudocat Hitdex NBA Top Shot Lending (via Flowty) Versus Zealy/TaskOn campaigns

Testnet: IncrementFi Trado Finance (Trado.one) More.Markets KittyPunch / PunchSwap Celer Network (cBridge) Ankr USDC (via Celer) Blocto Wallet EVM Uniswap forks (community)

  1. MEV strategies

Build out core product for live production. Additional condisderation brainstorm: More likely to risk what has already been staked? Potential for building features for user to use their staked funds here?

TO:

๐Ÿค– Autonomous Rebalancing Engine Every 5 Minutes:

๐Ÿง  ML Risk Assessment: Uses your trained risk models to evaluate strategy safety ๐Ÿ“Š Market Analysis: Monitors volatility, liquidity, and market stress ๐Ÿ” Opportunity Scanning: Identifies optimal yield opportunities across chains

Every 4 Hours:

โšก Optimal Allocation: ML calculates best fund distribution ๐Ÿ’ฐ Smart Execution: Automatically deploys funds to optimal strategies ๐ŸŽฏ Performance Tracking: Learns from results to improve decisions

Immediate Response:

๐Ÿšจ Emergency Exits: Automatically exits if strategy risk > 80% ๐Ÿ”„ Market Adaptation: Reduces risk in stress conditions ๐Ÿ“ˆ Yield Maximization: Moves funds to better opportunities

TroveFi: The AI-Powered Yield Raffle Game

Where financial growth meets the thrill of the win. We are turning passive savings into an active, rewarding experience you can't lose.


๐Ÿ’ญ The Problem: The Saver's Dilemma

Trillions of dollars sit in traditional savings accounts, eroded by inflation and earning negligible interest. It's safe, but it's a losing game. On the other end of the spectrum, billions are spent on lotteries, chasing life-changing wins but almost always resulting in a total loss of capital.

This creates a massive dilemma for everyday people:

  • The Safe Path: Earn virtually nothing on your savings.
  • The Risky Path: Gamble your savings for a shot at high rewards.

This is the market gap. People want the security of savings combined with the excitement and upside of a lottery, without the risk of loss.


๐Ÿš€ Our Solution: The AI-Powered, No-Loss Savings Game

Flow Prize Savings is the first AI-managed, prize-linked savings protocol on the Flow blockchain. We've created a positive-sum game where users can't lose. By depositing funds, you are not only saving your money securely but also automatically entering a weekly draw to win the entire prize pool generated from the collective yield.

Think of us as an intelligent, gamified bank account. Your money is always safe, always yours, but now it also gives you a weekly shot at a better financial future.

How It Works in 4 Simple Steps

Step Action Technical Implementation
1. Deposit & Pool Users deposit USDC into a single, secure, non-custodial smart contract vault on Flow. Users interact with the React frontend, which calls the deposit() function on the Vault.sol contract.
2. AI Generates Prize Our AI agent simulates yield generation, creating and funding the weekly prize pool. The agent's backend calls simulate_yield_harvest_and_deposit(), which mints MockUSDC and deposits it into the FlowVrfYieldStrategy.sol contract.
3. Provably Fair Draw The agent triggers the weekly lottery, using Flow's Native VRF for a cryptographically secure and random winner selection. The agent calls trigger_lottery_draw(), which executes the harvestStrategy() function on the Vault.sol contract, initiating the VRF draw in the strategy.
4. Win or Save One lucky winner receives the entire prize pool. Everyone else keeps 100% of their initial deposit. The FlowVrfYieldStrategy contract automatically transfers the prize to the winner's address. All other users' shares in the Vault remain untouched.

๐Ÿ›๏ธ The Philosophy: Why A "Positive-Sum Game"?

Finance is too often a zero-sum game. Lotteries are a negative-sum game by design. Flow Prize Savings is built on the principle of a positive-sum game:

  • The Winner: Receives a prize far greater than they could have earned alone.
  • The Participants: Lose nothing. Their savings remain intact and they benefit from a fun, engaging experience.
  • The Ecosystem: Grows as more users are onboarded to a safe, compelling Web3 product, increasing overall liquidity and activity on Flow.

This philosophy is embodied by our AI agent: it works for the collective good, optimizing the prize potential while guaranteeing the safety of the individual's capital.


๐Ÿ”‘ Key Features & Technical Innovation

We've built a sophisticated system that blends cutting-edge AI with robust blockchain security.

๐Ÿฆ No-Loss Savings Vault & ERC4626 Architecture

  • What it is: Your principal deposit is always safe. Only the generated yield is contributed to the prize pool.
  • Technical Detail: Our Vault.sol contract is designed based on the principles of the ERC4626 Tokenized Vault Standard. This ensures a clear separation between user deposits (represented as shares) and the yield-generating strategies, making it impossible for the prize mechanism to touch user principal.

๐Ÿค– AI-Powered Autonomous Agent

  • What it is: The protocol is managed by a sophisticated backend agent that handles all operations, from funding the prize pool to triggering draws and assessing risk.
  • Technical Detail: The agent is built in Python using FastAPI for the server, LangChain for structuring LLM interactions, and OpenAI's GPT-4o-mini as the reasoning engine. It can interpret high-level commands (e.g., "run the weekly lottery cycle") and execute a multi-step, on-chain plan. This grounds intelligent automation in a transparent, verifiable system.

๐ŸŽฒ Provably Fair Lottery with Flow Native VRF

  • What it is: We use Flow's built-in Verifiable Random Function for cryptographically secure and auditable randomness, ensuring every lottery draw is transparent and fair.
  • Technical Detail: Our FlowVrfYieldStrategy.sol contract directly integrates with Flow's native VRF contract at 0x0000000000000000000000010000000000000001. This avoids reliance on external oracles, providing a higher level of security and decentralization.

๐Ÿ“Š ML-Driven Risk Management

  • What it is: The agent uses a machine learning model to assess the risk of potential DeFi strategies before deploying capital.
  • Technical Detail: The agent loads a pre-trained .joblib anomaly detection model. The assess_strategy_risk() tool can analyze a strategy's on-chain metrics (if on Ethereum) to generate a risk score, preventing the agent from allocating funds to high-risk protocols.

๐Ÿ”— FCL & EVM Dual-Compatibility

  • What it is: A seamless user experience for everyone, whether they use a native Flow wallet or a standard EVM wallet like MetaMask.
  • Technical Detail: Our React frontend uses wagmi for EVM wallet connections and @onflow/fcl for native Flow integration. We've built custom hooks (useFCLStatus) to detect the user's connection type and provide a tailored UI, showcasing the power of Flow's EVM compatibility.

๐Ÿ—๏ธ Technical Architecture

Our system is composed of three core, interconnected components designed for security, scalability, and intelligence.


โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               ๐ŸŒ Frontend (React & Next.js)   โ”‚
โ”‚-----------------------------------------------โ”‚
โ”‚  ๐Ÿ–ฅ๏ธ  User Interface                           โ”‚
โ”‚  ๐Ÿ”—  Wallet Integration (Wagmi / FCL Hooks)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        ๐Ÿ”ท Flow EVM Testnet (Smart Contracts)  โ”‚
โ”‚-----------------------------------------------โ”‚
โ”‚  ๐Ÿฆ Vault.sol (Manage deposits/withdrawals)   โ”‚
โ”‚  ๐ŸŽฏ FlowVrfYieldStrategy.sol (Prize pool + VRF)โ”‚
โ”‚  ๐Ÿ’ต MockUSDC.sol (ERC20 token)                 โ”‚
โ”‚  ๐ŸŽฒ Flow Native VRF (Randomness)              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     ๐Ÿค– AI Agent Backend (Python + FastAPI)    โ”‚
โ”‚-----------------------------------------------โ”‚
โ”‚  ๐Ÿšช API Endpoints                             โ”‚
โ”‚  ๐Ÿง  LangChain Agent Executor                 โ”‚
โ”‚  ๐Ÿ” OpenAI GPT-4o-mini                        โ”‚
โ”‚  ๐Ÿ“Š ML Risk Model                             โ”‚
โ”‚  โ›“๏ธ  Web3.py                                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”„ How It Works (At a Glance)

๐Ÿ“ฅ Step 1: User deposits funds on the frontend โ†’ triggers Wagmi/FCL Hook โ†’ calls Vault.sol.

๐Ÿ“ค Step 2: Vault.sol deposits into FlowVrfYieldStrategy.sol.

๐ŸŽฒ Step 3: Strategy requests randomness from Flow Native VRF for lottery outcomes.

๐Ÿค– Step 4: AI Agent Backend:

  • Receives triggers (e.g., run lottery, harvest yield).
  • Decides optimal actions via GPT-4o-mini + ML Risk Model.
  • Executes blockchain transactions through Web3.py.

Core Contracts (Deployed on Flow Testnet)

Contract Address Description
MockUSDC 0x4edbDC8Ed8Ca935513A2F06e231EE42FB6ed1d15 An ERC20 token used for deposits and prize pools.
Lottery Vault 0xBaE8f26eDa40Ab353A34ce38F8917318d226318F The main vault where users deposit and withdraw funds.
Flow VRF Strategy 0xf5DC9ca0518B45C3E372c3bC7959a4f3d1B18901 The strategy that holds the prize pool and interacts with Flow's VRF.

๐Ÿ”ฌ Under the Hood: A Modular & Scalable Contract Framework

While the current testnet deployment uses a focused set of contracts to power the core prize-savings game, we have built a comprehensive and modular smart contract system designed for rapid, secure expansion. This architecture is the foundation for our long-term vision and is ready for future deployment.

This forward-thinking framework includes several key components:

1. The VaultFactory.sol

  • Purpose: This factory contract is designed to deploy new, isolated Vault instances permissionlessly.
  • Vision: This enables the creation of a multi-vault ecosystem where different communities, or even individuals, can launch their own prize-savings games with unique assets or configurations, all managed by our AI agent framework.

2. Pluggable Yield Strategies (Strategies.sol)

  • Purpose: We've designed a generic strategy interface that can interact with any external DeFi protocol simply by defining its function selectors.
  • Vision: This makes our system incredibly adaptable. Integrating a new yield source becomes a simple matter of deploying a new strategy adapter, not re-writing the core vault logic. To prove this model, we have already built production-ready implementations for major protocols:
    • AaveV3Strategy.sol: A complete strategy for earning yield on Aave.
    • CompoundV3Strategy.sol: A complete strategy for earning yield on Compound.

3. User Experience & Automation Contracts

  • AutoDepositProxy.sol: This helper contract is designed to enhance user experience by allowing for one-click deposits. For example, funds bridged from another chain can be sent directly to this proxy, which then automatically deposits them into the vault on behalf of the user, saving gas and steps.

This modular design is what allows our Future Roadmap to be so ambitious. The foundation is already built to support real multi-protocol and multi-chain yield generation in a secure and scalable way.


๐Ÿ“Š Key Differentiators

We're not just another DeFi protocol. We're creating a new category of financial product.

Solution Your Return Management Risk of Loss Gamified
Flow Prize Savings Principal + Chance to Win Yield Fully Passive (AI-Managed) ๐Ÿ”ฅ None โœ… Yes
Traditional Savings Principal + ~1% APY Passive None โŒ No
Lotteries / Gambling -100% (Usually) Active Very High โœ… Yes
Yield Aggregators (Yearn) Principal + Yield Passive Smart Contract Risk โŒ No

๐Ÿ’ฐ Business Model & Go-To-Market

Our revenue model is simple, transparent, and fully aligned with our users' success.

  • Primary Revenue Stream: Performance Fee
    • We will take a small percentage (e.g., 10%) of the generated yield only.
    • Example: If the prize pool for a week is $1,000, the winner receives $900 and the protocol receives $100 to fund operations and growth.
    • The Guarantee: If there is no yield, there are no fees. We only earn when our users win.

Go-To-Market Strategy

  • Phase 1: Launch on Flow Testnet & Build Community (Current)
    • Engage with the Flow community through social media, developer forums, and hackathons.
    • Gather user feedback to refine the product and user experience.
  • Phase 2: Mainnet Launch with Real Yield Strategies
    • Integrate with audited, blue-chip protocols on Flow (e.g., Increment Finance) to generate real yield.
    • Launch a marketing campaign focused on the "no-loss" value proposition to attract initial liquidity.
  • Phase 3: Scale & Expand
    • Introduce new features like premium prize tiers, team-based savings games, and NFT-based rewards.
    • Explore multi-chain yield optimization, using the AI agent to find the best risk-adjusted returns across the entire Web3 ecosystem.

๐Ÿ—บ๏ธ Future Development & Roadmap

This project provides a robust foundation. The next phase will focus on transitioning from a simulated environment to a live, fully autonomous, yield-bearing protocol.

  • Implement Real Yield Strategies on Flow:
    • Integrate with established Flow protocols like Increment Finance or Flowswap to generate real yield from user deposits.
    • Develop and deploy new Cadence-based yield strategies to leverage Flow's unique capabilities for gas efficiency and composability.
  • Enhance the ML Risk Model:
    • Train the risk assessment model on historical data from actual Flow DeFi protocols.
    • Build a data pipeline to continuously fetch on-chain data to keep the model updated and relevant.
    • Allow the agent to dynamically retrain the model based on new information and market conditions.
  • Expand Agent's Autonomous Capabilities:
    • Enable the agent to autonomously decide when and how much capital to allocate to different strategies based on risk/reward calculations.
    • Implement logic for the agent to automatically rebalance the portfolio if a strategy's risk profile changes.
    • Use Account Linking on Flow to allow the agent to securely manage vault operations with clear permissions and user-controlled recovery mechanisms, creating a truly secure autonomous system.
  • UX Enhancements with Cadence:
    • Leverage Cadence to introduce features impossible on traditional EVM chains, such as sponsored/batched transactions for a gasless user experience and walletless onboarding for mainstream adoption.

โ“ Addressing Key Questions (FAQ)

"Is this just another lottery?"

No. It's a savings protocol first. Traditional lotteries require you to spend and lose your money for a chance to win. With us, your deposit is never spent. You are essentially getting a free lottery ticket every week, just for saving your money. The prize is created from the yield, not the principal.

"If I don't win, do I lose anything?"

Absolutely not. This is the core of our "no-loss" guarantee. If you don't win, your initial deposit remains untouched and is available for you to withdraw at any time.

"Is my money safe?"

Security is our highest priority.

  1. Non-Custodial: You always maintain full ownership of your funds. We can never access your deposited principal.
  2. No-Loss Guarantee: The smart contracts are architected to ensure only generated yield is moved to the prize pool. Your deposit is isolated and safe.
  3. Future-Proofing: When real yield strategies are implemented, they will be restricted to a whitelist of heavily audited, battle-tested protocols, and our AI will continuously monitor for risks.

๐Ÿ”ง Quick Start & Installation

This project contains a full-stack application with smart contracts, an AI backend, and a React frontend.

Prerequisites

  • Node.js v18+
  • Python 3.9+
  • An EVM-compatible wallet (e.g., MetaMask) funded on the Flow Testnet.

Installation & Setup

  1. Clone the Repository:

    git clone https://github.com/TroveFi/submission-repo
    cd backend
  2. Set Up AI Backend:

    cd backend
    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
    cp .env.example .env
    • Fill in your AGENT_PRIVATE_KEY and OPENAI_API_KEY in the .env file.
  3. Set Up Frontend:

    cd <frontend-folder>
    npm install

Running the Application

  1. Start the AI Agent Backend:

    cd <backend-folder>
    uvicorn main:app --reload

    The agent is now running on http://localhost:8000.

  2. Start the Frontend:

    cd <frontend-folder>
    npm run dev

    Access the user interface at http://localhost:3000.


๐Ÿค– Agent Demo Guide: A Full Operational Cycle

You can interact with the live agent using these curl commands to simulate a full operational week.

  1. Check System Health

    • What it does: Confirms the agent is online, connected to the Flow blockchain, and can communicate with our smart contracts.
    • Command:
      curl http://localhost:8000/health
  2. Generate the Prize Pool

    • What it does: Simulates yield generation. The agent mints 150 USDC and deposits it into the strategy contract to create this week's prize.
    • Command:
      curl -X POST http://localhost:8000/generate-yield \
           -H "Content-Type: application/json" \
           -d '{"amount_usdc": 150.0}'
  3. Check the Status

    • What it does: Shows the prize pool is now funded and ready for the draw.
    • Command:
      curl http://localhost:8000/enhanced-status
  4. Trigger the Lottery Draw

    • What it does: Instructs the agent to trigger the lottery, calling the smart contract that uses Flow's native VRF to select a winner.
    • Command:
      curl -X POST http://localhost:8000/trigger-lottery
  5. Confirm the Winner

    • What it does: Confirms the draw is complete and shows the winner's address.
    • Command:
      curl http://localhost:8000/enhanced-status
  6. Ask the AI for a Strategy

    • What it does: Demonstrates the agent's intelligence. It analyzes the current state and uses GPT-4 to recommend a strategic course of action.
    • Command:
      curl -X POST http://localhost:8000/ai-strategy \
           -H "Content-Type: application/json" \
           -d '{"command": "What should I do next after successfully running the lottery?"}'
  7. Run an Emergency Risk Check

    • What it does: Showcases the agent's security focus by running an emergency risk assessment across all strategies.
    • Command:
      curl http://localhost:8000/emergency-status

๐ŸŒ The Vision: Onboarding the Next Billion Users to Web3

Our vision is to make saving and wealth creation accessible, fun, and rewarding for everyone. We believe Flow Prize Savings can become the default savings account for the next generation of internet usersโ€”a place where your money is not only safe but is also constantly working to give you a shot at a better financial future.

By abstracting away the complexities of DeFi with a powerful AI and a simple, engaging interface, we are building a "killer app" that solves a real-world problem for a global audience, right here on Flow.

--- CONTRACT DEPLOYMENT SUMMARY ---

Mock USDC Token: 0x4edbDC8Ed8Ca935513A2F06e231EE42FB6ed1d15 Vault Factory: 0xa87fe90A07DE4E10398F2203A9F3Bd8b98Cf902D Lottery Vault: 0xBaE8f26eDa40Ab353A34ce38F8917318d226318F Flow VRF Strategy: 0xf5DC9ca0518B45C3E372c3bC7959a4f3d1B18901

VRF strategy added and configured to Vault

๐Ÿ”ฎ VRF Integration Details: The Flow VRF Strategy uses the Cadence Arch contract at: 0x0000000000000000000000010000000000000001 This provides secure, on-chain randomness.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published