Inspiration

In the fast-paced world of crypto, market volatility can be overwhelming. It's impractical for investors to constantly monitor and adjust their portfolios as prices swing. TrailMix addresses this challenge by offering an automated solution to protect investments from sudden market downturns.

What it does

TrailMix introduces customizable trailing stop losses, a dynamic alternative to static onchain limit orders. This mechanism allows users to set a sell threshold that automatically adjusts when the price increases, ensuring sales occur near local price peaks. This tool is a game-changer for crypto users, providing a decentralized, onchain solution accessible to all, including those in regions where perp dexes are banned. TrailMix features inherent flexibility, giving users the control to choose assets, trail amounts, and update frequency.

How we built it

Leveraging Chainlink's reliable price feeds and decentralized automation network, TrailMix was built for real-time responsiveness and accuracy. The application's design simplifies complex trading strategies into user-friendly, automated processes, removing emotional decision-making from trading.

Challenges we ran into

Challenge 1:

Initially, TrailMix had one contract per token for all users to interact with. While gas-efficient, this strategy posed security risks and vastly increased complexity. The challenge was managing user balances and stop loss data scalably. Each loop had to be bounded to scale to increasing numbers of users and strategies.

  • Solution: Instead, I opted for a more modular approach where each strategy has its own contract. This reduces complexity, increases security and customization, and leaves the door open for modular combinations and even trading of strategies (maybe as NFTs…).

Challenge 2:

Since the sell threshold is updated onchain it is important to minimize the required updates in order to keep gas costs low. My first thought was to update at preset intervals, i.e. every hour. However I realize that it made more sense to update based on price changes. The system was restructured to update the stop loss threshold only when the price increased by a set percentage (e.g., 5%). This change, along with L2 scaling solutions, drastically reduces operational costs.

Challenge 3:

  • Swapping tokens within a contract, rather than from an EOA, presented unique challenges, especially given the limited testnet support for Uniswap. Currently the contract only swaps on Uniswap and only works for assets that have direct pools. This isn’t ideal as it doesn’t guarantee the best prices and limits potential assets. While there are swap API’s, I couldn’t find a way to embed them into the smart contract as they primarily function through javascript.

Accomplishments that we're proud of

  • Creating a flexible system that has immediate use cases.

  • Working with cutting edge products from Chainlink to bring a novel idea to life

  • Learning to build and test with foundry

  • Creating a functioning frontend to interact with multiple contracts

  • Deploying to a live testnet

What we learned

-Simplicity rules all. It’s better to build on a basic primitive than it is to try to start with something complex.

-Fullstack tooling is becoming better and better allowing for faster development and better products. There is no longer an excuse for web3 UIs to be slow and buggy

What's next for TrailMix

TrailMix is poised for further development:

  • Expanding to more ERC20 token pairs and Uniswap execution.

  • Expand to more price oracles to support tokens without a Chainlink price feed

  • Mitigate front-running risks.

  • Deploy to more chains

Conclusion:

TrailMix presents a significant advancement in automated crypto trading, offering users peace of mind and the potential to optimize their investment strategies in an ever-changing market.

Built With

Share this project:

Updates