# Metio EMA Treasury Bot
## What Inspired Us
We were inspired by a simple observation:
**most “AI trading bots” are hard to trust, hard to explain, and impossible to audit.**
In contrast, the MNEE hackathon theme emphasized *programmable money*, *automation*, and *reliable on-chain workflows*. That pushed us to ask a different question:
> *What if money itself followed transparent rules, instead of opaque predictions?*
This led us to design a **rule-based, on-chain treasury vault** that uses MNEE (a USD-backed stablecoin) as its base asset and reallocates into ETH using a well-known financial indicator: the **Exponential Moving Average (EMA)**.
Instead of building “another trading bot,” we focused on building **financial automation infrastructure** that judges, developers, and users could immediately understand and verify.
---
## What We Built
We built a **Telegram-based MNEE Treasury Bot** backed by an **Ethereum mainnet smart contract**.
At its core, the system is an **autonomous treasury vault** that holds:
- **MNEE (USD stablecoin)**
- **ETH (via WETH)**
The vault follows a simple, transparent strategy:
- If ETH price is **above EMA**, the treasury allocates more into ETH
- If ETH price is **below EMA**, the treasury reallocates back into MNEE
No leverage. No prediction. No black box.
All logic is enforced **on-chain**, while a lightweight agent (keeper) merely triggers execution.
---
## The Math (EMA Strategy)
We use Exponential Moving Averages to smooth price data and identify market regimes.
The EMA is calculated as:
\[
\text{EMA}_t = \text{EMA}_{t-1} \cdot (1 - k) + \text{Price}_t \cdot k
\]
Where:
\[
k = \frac{2}{N+1}
\]
For example:
- **EMA5** → \( k = \frac{2}{6} \approx 0.3333 \)
- **EMA200** → \( k = \frac{2}{201} \approx 0.00995 \)
Prices are sourced from **Chainlink ETH/USD oracles**, and EMA values are stored and updated directly in the smart contract for full auditability.
---
## How We Built It
### 1. Smart Contracts (Ethereum Mainnet)
- Vault contract that holds MNEE and WETH
- On-chain EMA computation (EMA5 / EMA200)
- Risk controls:
- max trade size
- slippage limits
- cooldowns
- oracle staleness checks
- Circuit breaker + pause functionality
- Profit-lock mechanism that automatically settles gains back into MNEE
### 2. Automation Agent (Keeper)
- Periodically calls `rebalance()`
- No strategy logic off-chain
- Cannot override vault rules
- Cheap calls when no trade is needed, more expensive only when swaps occur
### 3. Telegram Bot Interface
- Human-readable access to a complex on-chain system
- Buttons instead of commands
- Clear separation between:
- education (“How it works”)
- control (deposit / withdraw / pause)
- execution (manual rebalance for demos)
This made the project accessible even to non-DeFi-native users.
---
## What We Learned
- **Simplicity wins**: A single, well-explained rule beats complex AI narratives.
- **Programmable money is about constraints, not intelligence**.
- EMA strategies are easy to explain but require careful handling of cadence, gas costs, and oracle freshness.
- Gas optimization matters: most calls cost \<50k gas when no trade happens.
- UX matters as much as contracts—Telegram made the system feel usable, not academic.
Most importantly, we learned that **financial automation doesn’t need hype** to be compelling—clarity and trust are enough.
---
## Challenges We Faced
### 1. EMA Warm-Up Problem
EMA values need multiple updates before they become meaningful.
We solved this by:
- seeding EMA on first call
- running the keeper on a fixed cadence
- clearly documenting this behavior for users and judges
### 2. Gas vs Accuracy Tradeoff
Updating EMA too frequently increases gas costs; updating too infrequently reduces signal quality.
We balanced this by:
- separating EMA updates from swap execution
- only trading when thresholds are crossed
### 3. UX Without Over-Promising
Avoiding phrases like *“guaranteed profit”* was intentional.
Instead, we focused on:
- risk-managed rebalancing
- transparency
- user control at all times
### 4. Trust Boundaries
We had to ensure the bot could **never** act outside the contract’s rules.
All sensitive logic lives on-chain; the bot is just an interface.
---
## Why This Matters
This project demonstrates how **stablecoins like MNEE can act as programmable treasuries**, not just passive payment assets.
By combining:
- transparent on-chain rules
- autonomous execution
- human-friendly interfaces
we show a practical, credible path toward **automated finance that users can actually trust**.
Log in or sign up for Devpost to join the conversation.