# Skypools deep dive Kicking off Swingby's Article Series, we started with our multi-chain and trustless vision of the world. Following that, we shared how our latest product - SkyPools helps Bitcoin traverse across chains & interact with smart contracts, opening up a new world of possibilities. Today, we'd like to go deeper into what our team does best - the technical workings behind our producst. That's right, we will be going under the hood and sharing more about the technical upgrades that make SkyPools possible. For the technical folks and diagram geeks, you'll be in for a ride! ## Technical Overview: What goes into the SkyPools update? ![](https://i.imgur.com/pBvMegu.png) For the SkyPools update, the team had 2 main objectives: 1. Improve user experience & cryptography 2. Enable smart contract interactions to empower Swaps over SkyPools ### Objective 1: Improve user experience & cryptography The first objective of the SkyPools update is to **improve the user experience and security for bridges made on SkyBridge**. For users behind the $81M swaps over the last 9 months, you will see faster transactions and a more seamless user experience from these updates. More specifically, the technical upgrades are **CMP & FROST cryptography**, as well as the **integration of BIP32**. #### CMP & FROST Integration [CMP (ECDSA)](https://eprint.iacr.org/2021/060) and FROST (EdDSA & Taproot) vastly improve the performance of the underlying cryptography that powers Skybridge. By implementing both CMP and Frost, we have: * Massively reduced the number of signing rounds required to form a consensus. * Reduced the amount of processing overhead * Added support for parallel processing, significantly speeding up signing rounds. This upgrade creates a better user experience through faster transactions and reduces complexity of Metanode processing for Metanode operators. #### Implementation of BIP32 [Bitcoin Improvement Proposal 32](https://en.bitcoin.it/wiki/BIP_0032) enables Skybridge to create unique Bitcoin deposit addresses for each swap. This gives us the ability to identify & handle your swaps uniquely without needing you to send in Bitcoin with long running decimals currently. ![](https://i.imgur.com/uMP4Qap.png) As a user, sending exactly how much you want without running decimals will greatly improve your user experience. For Metanodes, the new identification method under BIP32 also reduces the complexity of Metanode operations. ### Objective 2: Enable smart contract interactions for SkyPools Next and more importantly, the SkyPools update aims to empower SkyBridge to interact with smart contracts and launch Swaps. This means that Metanodes will be able to sign transactions that invoke smart-contract functions once a consensus is formed. Initially, the first application of this upgrade is to enable any-to-any coin swaps over the Ethereum network, but you can imagine a world where Bitcoin can be directly used with all DeFi applications in the future. The Development team's effort is heavily focused here, which we'll share more in the second part of this article. ## Under The Hood: How Skypools Swap Works Skypools allows users to directly interact with the existing Skybridge in ways that more directly allow native Bitcoin to participate in existing decentralized finance protocols in ways that were not possible before. Two major flows make up the primary features of Skypools. ### Flow 1: Swapping native BTC to ERC-20 tokens This flow first converts native BTC to wrapped BTC tokens (BTCt) on the applicable EVM network (wBTC on Ethereum), before executing the swap to ERC-20 tokens. **Step 1: Convert native BTC to BTCt (WBTC)** First, to execute the conversion between native BTC to BTCt, the user must request the nodes to do the cross-chain conversion in a similar fashion to the original Skybridge flow. This request includes the user’s Ethereum wallet address to allow the receipt of tokens. Once the nodes have executed the cross-chain conversion to BTCt, the BTCt will be placed into a balance on the smart contract allocated to the user’s wallet address. The user can either withdraw the BTCt directly to their wallet (i.e. a BTC to BTCt bridge) or execute a swap. **Step 2: Swap BTCt to ERC-20 token via Paraswap** By executing the swap, the user does not pay gas fees and the swapped token will be sent to the user’s wallet directly. To enable this swap, our smart contract utilizes the Paraswap V5 interface, as follows: 1. Make GET request to Paraswap API V5 to get pricing data for token pair 2. Make PUT request to Paraswap API V5 (using pricing data from GET request) to get the full transaction data. This gives us every parameter we need to execute the swap using the Paraswap smart contract interface. - Here, we will collect the data required for the swap, and will only execute the wap call when the user submits the transaction & executes the function call on the SkyPools UI. 3. User clicks on Swap & submits transaction. This calls the external function on our smart contract to execute the swap using the data from the API PUT response. 4. The swap is executed using liquidity from Paraswap, and the resulting tokens are sent directly to the user’s wallet ### Flow 2: Swapping ERC-20 tokens into native BTC The second flow works in the opposite direction from the first, allowing a user to deposit any ERC-20 token to the swap contract and swap it to native BTC in 1 transaction. These deposited tokens are held and assigned to the depositing wallet address. At this time, the sequence of events as replicated in our tests is as follows: **Step 1: Swap ERC-20 tokens to BTCt via Paraswap** Mirroring Flow 1, there will be 2 Paraswap V5 API calls: 1. Get pricing data for the swap from deposited token to BTCt (wBTC on ethereum) 2. The user calling the external function to execute the swap using the Paraswap interface. **Step 2: Convert BTCt to native BTC** After the swap, The BTCt tokens are sent to the swap contract rather than the user’s wallet. 1. The contract calculates the exact amount received, and stores it as a pending swap along with any other associated information (e.g. receiving native BTC wallet address). This allows the Skybridge nodes to pick up pending transactions so the user can be sent their native BTC. 2. At the time this is recorded, the contract also cleans up any old pending transactions (to native BTC) that have already been executed by the Skybridge nodes 3. A SwapTokensToBTC event is emitted, allowing the Skybridge nodes to know a new swap has occurred. 4. SkyBridge nodes send native BTC to the receiving wallet address, once consensus is achieved In the event of a failed Skypools transaction, such as with an invalid receiving native BTC address, the user will be refunded with BTCt (wBTC on ethereum) --- With that, this sums up the technical upgrades going into the SkyPools update, as well as the smart contract flows that enable SkyPools to do swaps. While enabling smart contract interactions sounds simple in theory, the development team is hard at work ensuring that all edge cases are accounted for. This way, you can use SkyPools with minimized trust on all levels, knowing that your funds are always safu! We are excited to bring you the testnet launch in Q4 and will keep you posted on any technical updates. Meanwhile, for the more technical folks, what do you think? We'd love to know if you have any thoughts and feedback. Join us in our Discord to discuss more! --- CTA