System Architecture

Overview

Each strategy has its own fungible token that users receive when they invest in the strategy. These tokens can be traded freely on the Tradegen marketplace in exchange for TGEN, and generate yield when the associated strategy makes a trade. When users want to withdraw their investment from the strategy, they can burn their tokens and receive the TGEN equivalent of their cUSD (Celo dollars) investment. Users wanting to invest in a strategy after the max pool size has been reached can buy the strategy’s tokens from other users on the marketplace.

Strategies also have their own trading bot that trades on Ubeswap based on the entry/exit rules of the strategy. A strategy accumulates debt or yield, depending on whether the bot makes a losing or profitable trade. When users withdraw their investment from the strategy and they have debt, the debt gets settled on their behalf (using their original investment). If users, instead, have yield when they want to withdraw, the TGEN equivalent of the yield is minted and sent to the users.

Withdrawals are handled by sending the user their stake in the strategy's underlying asset, instead of sending the user cUSD. If the bot is not in a trade when the user withdraws, the user receives cUSD.

Trading Bots

Each strategy has an on-chain trading bot that responds to price feed updates from a Chainlink price feed for the strategy’s underlying asset. When the bot receives an update, it decides whether to enter/exit/avoid a trade based on the strategy’s entry/exit criteria. If entry/exit conditions are met, the trading bot contract trades the strategy's underlying asset on Ubeswap using Ubeswap's IUniswapV2Router02 interface. The bot is implemented as a state machine, storing the state of each entry/exit rule and updating the state when the price feed updates.

Indicators and Comparators

Strategies' entry/exit rules have two indicators and a comparator, each with their own state that gets updated whenever the underlying asset's price feed updates. Indicators calculate a value based on the latest price feed update. Comparators compares the value of one indicator to the value of another, and return true if the comparator's condition is met.

Last updated