Cross Chain Swaps
Cross-chain swaps enable rhino.fi users to swap stablecoins into any of our supported tokens on other chains, and then back into stables (currently, one of the tokens in the transaction always has to be a stablecoin). We support over 600 tokens, across four different chains: Ethereum (our native chain), BSC, Polygon and Arbitrum. To execute a cross-chain swap, users must go to or from rhino.fi: they can’t swap between two of our supported chains without going through our platform.
rhino.fi deploys this self-custodial smart-wallet on several chains, and it holds tokens on behalf of users. rhino.fi can broadcast meta-transactions signed by users in order to swap via aggregators such as Paraswap or invest into yield opportunities such as via Beefy Finance.
- Atomic swaps. These are smart contracts that allow you to swap tokens between different tokens in a single trade.
- Hops. These refer to the blockchains you visit when making a cross-chain swap. Think of it like your journey.
- Liquidity outposts. These power our cross-chain swap system. We have established liquidity positions on different chains and use these to deliver cross-chain swaps.
- Payload. This is the arbitrary execution call data, or, more simply, the set of instructions needed for the contract to execute. These instructions could be as simple as a token transfer or as complex as performing multiple swaps or other actions.
- Collateralised Bridges. This means we can keep funds on multiple chains to provide very fast bridging capabilities.
Executing cross-chain swaps Our system is based on two key points: Our liquidity outposts enable us to make transactions on various chains, using collateralised bridges to send funds back and forth. Our cross-chain smart contracts manage the flow of funds across these bridges, without the need for a human oversight committee. So to take an example, let’s say a user wants to swap USDT for AVAX on Polygon. In this case, the user would deposit to rhino.fi and rhino.fi would give them USDT from our outpost on Polygon, and use this USDT to acquire AVAX. Now, the AVAX would be deposited into our cross-chain smart contract under the user’s address. These contracts ensure that only the users themselves can spend the assets they receive - rhino.fi does not have authority to do anything with them. The user must then sign a message with a deadline and a set of parameters, one of which is the amount they want in return for their newly acquired tokens. Upon receipt of this message, rhino.fi sends another transaction to the contract to execute the further swap, and the contract verifies that it has received the amount of tokens the user has signed for. Finally, we bridge back these assets using our collateralised bridges.
Points of difference There are two noteworthy aspects to the process: versatility and safe, arbitrary logic. The versatility is particularly noteworthy. With one contract, we can support practically any combination of ‘from’ and ‘to’ tokens. Our cross-chain contracts allow us to program all the necessary steps into our own backend, and execute transactions simply. Our system allows us to execute arbitrary logic on our transactions via a VM contract. This contract is independent from our main fund-holding contract to ensure client assets are always safe and secure. Our contract transfers funds into the VM contract, and gives it the payload. Now the VM contract executes the payload, and does so securely because the VM is not permissioned anywhere. Then, when it receives funds in return, the VM contract transfers these funds back into the cross-chain contract which validates the execution, essentially saying ‘you were supposed to give me this amount, have you done so?’ If the VM contract hasn’t provided these funds, the whole transfer reverts, and the user retains all their funds. One of the key strengths of smart contracts is that they can revert an entire transaction atomically, and it’s as if nothing happened. So the whole process is extremely safe. Speed Our swaps are nearly instantaneous. As soon as the user confirms the transaction, it is submitted practically straight away. The only delay is how long the transaction takes to get mined. On some side-chains, this may take a few seconds. On others, slightly longer. Aggregators We outsource to a number of aggregators, notably ParaSwap, to get the best route (and cheapest price) for each transaction. So, if a user wanted to swap USDT to Bitcoin, our aggregators might tell us to go from USDT to ETH and then ETH to BTC, for example. In very simple terms, the aggregator tells us ‘Okay, on this chain, you want to go from this token to this token. Here are the hops you have to make and here are the percentages of your liquidity you should use on each of them.’ This is atomic as well, because all the steps are combined in a single transaction. When we submit the query, we use all the aggregator’s querying and routing logic to let them tell us the best route for the user’s trade.
The role of StarkEx
As previously discussed, StarkEx provides our layer 2 contracts, running on Ethereum. In other words, users deposit from Ethereum into our StarkEx pools, and then it’s very cheap for us to combine transactions within our StarkEx platform. Users can swap with one another, or swap on our markets, and these are very cheap transactions for us to process. If the user were to make these transactions on Ethereum, it would cost somewhere in the region of $5-10 per transaction. On rhino.fi, it costs a fraction of that amount, and StarkEx is running on Ethereum, which means the user receives the security benefits of the Ethereum blockchain directly. Self-custody Self-custody is baked into the cross-chain smart contracts. These contracts are activated by user signatures, and rhino.fi cannot execute any transaction on a user’s behalf without these signatures. Trusted elements The bridges do create a trusted element. If a user swaps a certain amount of tokens through rhino.fi, our platform transmits those to another chain and then executes the swap, this is a trusted process; the user deposits and swaps some tokens on rhino.fi and they trust that rhino.fi will give them those tokens on another chain. This is the only trusted element in the entire process. Once the tokens are swapped, the process is totally self-custodial. This trusted element is necessary to guarantee speed. If rhino.fi were to make the bridging process trustless, the transaction time could reach several minutes, depending on the chain. Gas fees Rhino.fi’s core infrastructure minimises executions - in other words, the process does not execute unnecessary transactions. Furthermore, the cross-chain swaps are built on Layer 2s, which are relatively inexpensive. In general, rhino.fi favours flexibility over gas fee reductions, because greater flexibility leads to greater opportunities. Gas-fee optimisation must be carried out on chain, which in turn costs flexibility, which in turn leads to the deployment of more contracts and more logic. Overall, however, the process is gas-efficient. For example, cross-chain swaps to Polygon currently cost around $0.10 on average.