We are crypto enthusiasts, developers, contributors, and first of all, a strong team that have been working in DeFi sector since 2018 to achieve common goal. This goal is modest, but at the same time very important contribution to the DeFi industry: improvement of a user experience for any type of user - trader, beginner, market maker or investor. Although the unique solution to UX improvement is simple at first glance and solves the key problem associated with cross-chain swaps, it did not come immediately, but as a result of development, testing and use of the dex over a long period of time. While we were developing, testing and adjusting the 1st iteration of the dex, there were 5 key issues which did not allow us to present it as the most convenient cross-chain dex for our community:
- Time. It could take up to 3 hours to complete cross-chain swap.
- Fees. Each bridge charges a transaction fee on both source and destination chains.
- Relevance of the swap. With both issues above (time and fees), there was a real question if the trade is really relevant, as price is volatile and may no longer be relevant to the user.
- Liquidity aggregation. Although that was not a direct problem for the end user, but it directly limited the user's choice while trading certain assets between different chains: not all assets available; not enough liquidity available; not fast enough liquidity aggregation.
- Complexity. New things can be adopted widely only when there is intuitive user experience. With crosschain-swaps it was really hard to trade because of intermediary - bridge. It took time to learn and test how to use a bridge and even then user needed to perform a lot of clicks in order to complete only one cross-chain transaction.
It took us time to understand how to solve this problem, but the solution was simple - to exclude this intermediary (bridge) for users!
What it does
So how it works for the end user and how then assets get bridged? Pretty simple!
- Swap initiated by the user on source chain with target asset and chain information to calculate the order route
- User assets are converted to stablecoin
- The stablecoins are deposited to chain specific Magpie stable pools
- User swap and deposit information is sent and recorded by Wormhole State Guardian Network (our key partner)
- Upon verification, Magpie relayer executes swap-out function on target chain converting stablecoins to users target asset.
And if you want close example in real life, it is very similar to how TransferWise is working: Alice from Germany sends euros through TransferWise. TransferWise receives euros and sends dollars to Bob account in USA. And that's how Magpie works: assets are converted to stablecoin on source chain and stablecoin on destination chain is used to buy destination asset.
How we built it
Now lets explore how did we build it from a technical view. We built our backend infrastructure of Magpie aggregator based on microservices using Nodejs which calculates paths for swapping from one token to another. It uses an advanced proprietary routing algorithm which finds the most efficient paths for a token swap by splitting the order between different protocols (DEXs) to get the maximum amount of tokens for the user. It also provides an API endpoint that returns a quotation for a token swap. It calculates the best route to exchange tokens using graph search, based on the data collected by the pool explorer service, which is prioritized based on available liquidity in USD. It performs price impact calculations off-chain based on the collected data in order to find the best deal for the user. It includes the Pool Explorer Service that makes sure that our system has all the necessary information from the integrated AMMs on each chain, Token Provider Service that keeps the token list up to date, User Service that keeps track of user balances and transactions, Relayer Service that listens to swappedIn event on all supported chains, it queries wormhole guardian network to get VAA for any swapIn transaction and then it calls swapOut on the target chain and Message Broker handles the communication between the services. We built our frontend interface using Quasar, which let user to perform cross-chain swap using Webapp.
Challenges we ran into
We heavily focused on refactoring our source code, enhancing our aggregator quotes by refining our routing algorithm and distribution logic, we tried to work with several node provider services and other public node RPCs but we were faced with rate limit errors hence we decided to run our own nodes for the supported networks.
Accomplishments that we're proud of
And now the good news are the results we are happy to share! Magpie aggregator can provide the best on-chain and cross-chain swap quotes among all leading aggregators. The response speed on the frontend interface for quotations is exceptional and extremely fast which updates the quotes on a user interface in almost realtime through websocket connection.
What's next for Magpie Protocol
We are close to our alpha testing release and there still many things under the development. Currently we are planning to expand to more EVM and non-EVM networks and integrate more AMMs
Log in or sign up for Devpost to join the conversation.