Inspiration
Investing and trading crypto are time consuming activities with the constant need to track crypto developments and metrics such as price and sentiment. As busy people, we want to automate these activities using algorithms and AI.
What it does
SwapAI daily swaps between BTC and TUSD by swapping BTC for TUSD to lock in BTC gains or swapping TUSD for BTC to buy BTC at a low price before a significant price increase. The swapping decision is determined by the BTC 24-hour price forecast, BTC 24-hour positive/negative sentiment forecast, and TUSD asset to reserve ratio. For example, if the current BTC price was 50000 and the price forecast was 52500 (5% increase), the sentiment forecast was 0.8 (in range of [-1,1] with 1 being most positive), and TUSD ratio was 0.999, SwapAI would swap an opted-in user’s TUSD balance for BTC.
How we built it
- Frontend: React with Ether.js and Material UI. Deployed to GitHub Pages.
- Backend: Solidity dapp with Hardhat tooling and Alchemy deployment to Kovan. Used Chainlink, Sushiswap, and OpenZeppelin libraries. Chainlink was used to get BTC price feed data, call QDT AI Bitcoin Price Prediction Oracle and Connexun AI News Sentiment Oracle, make GET requests to the TrustToken TUSD API. Used Chainlink Keeper for automating the daily swapping functionality. Sushiswap was used to create liquidity pools for fake TUSD and WBTC tokens and make swap calls for the tokens from within SwapAI
Challenges we ran into
- We had to deploy mocked BTC and TUSD ERC-20 tokens since real tokens don’t exist on Kovan for TUSD and WBTC (which is how BTC is used on Ethereum networks).
- The oracles that we wanted to use (Connexun AI News Sentiment and QDT AI Bitcoin Price Prediction) weren’t on the Kovan testnet, even despite the first one advertising that they had an oracle on there. Since we didn’t want to deploy on the mainnet and spend real money for hackathon-quality code, we had to mock their responses by generating random values (not from the VRF service).
- Managing deployment of multiple contracts (required creating multiple deployment scripts)
Accomplishments that we're proud of
- We had to create a bunch of hardhat scripts to allow us to quickly deploy contracts to Kovan and to debug (via Etherscan’s verify contract ability). Hopefully these scripts will serve us for future projects.
- We also developed some useful utility contract scripts for managing oracle calling, which should make it easier to facilitate multiple oracle calls at the same time.
- Learned how to develop with Sushiswap and Chainlink
- Learned how to debug contracts with Tenderly and Etherscan
What we learned
- How to overcome challenges and achieve achievements
What's next for SwapAI
- Writing tests and deploying to mainnet so we can actually call the QDT and Connexun oracles.
- Adding the ability to swap in longer intervals than 24 hour (i.e. 72 hours, 1 week).
- Supporting swap to more stablecoins (i.e. USDC, USDT) and from more cryptocurrencies (i.e. ETH, MATIC)
Built With
- bitcoin
- blockchain
- chainlink
- ethereum
- ethers.js
- javascript
- solidity
- sushiswap
- tusd




Log in or sign up for Devpost to join the conversation.