In my last article, I talk about Atomic Swaps and why we need them. I explained that Atomic Swaps is one of the solutions we have for the no trust issue that we need to overcome if we want to trade cryptocurrencies between two parties without a trusted side in between (peer to peer exchange or P2P).
To make a long story short if User A, let’s call him Kirk, wants to trade some cryptocurrency with User B, let’s call him Picard (Yes I am a Trekkie), and they don’t know and trust each other, they will need to use a third trusted party to do the exchange for them, which is called a “centralized” exchange.
The advantages and disadvantages of centralized exchanges are beyond the scope of this article, and there are tons of great articles on that subject online so I won’t get into that.
Today I want to talk about Smart Swap which is a new solution for the no trust issue we have on a P2P exchange.
What Is Smart Swap?
Smart Swap is a P2P trading technology built on the Ethereum network. The key aspects of Smart Swap are:
- It’s 100% decentralized.
- It eliminates the need for trust between the parties.
- It overcomes some of the Atomic Swap disadvantages.
- It’s a face value exchange.
Before I explain how Smart Swap works, let’s explain what we mean by “face value exchange” and why we need it. So, let’s return to our captains, and this time, Kirk is issuing an order to buy 10,000 A tokens for 10,000 B tokens, which are valued at $1 each.
While Kirk is waiting for the exchange to find a match for his order, it could be a few days or more depending on the token’s liquidity. During this wait time, Token A’s value has increased by 5% so now he needs 9,523 A tokens only to get 10,000 B tokens. But if Kirk was not on his guard and the order came through would lose 477 A tokens.
A face value exchange will guarantee this kind of loss will not happen by measuring the rate of the Token against the USD and change the order accordingly. When using Smart Swap, the order will be $10,000 worth of TokenA for TokenB, meaning Kirk will get 10,000 B tokens plus 477 A tokens refund.
How It Works
As I mentioned before, the Smart Swap is built on the Ethereum net, but it will allow trading with other blockchains, and that process will be slightly different. So I’ll explain it once for trading two Ethereum-based tokens and once for trading BTC with an Ethereum-based token.
Use case 1: User A wants to trade $100 worth of TokenA for $100 worth of TokenB
* Tokens A and B are based on Ethereum.
- User A deposits $100 worth of Token A to the Smart Swap contract.When tokens are deposit into a smart contract, they can only be withdrawn using a smart contract function, even if you have the contracts account private key you can’t just transfer tokens from the account like you would with your private wallet.
The Smart Swap contract will only remove funds from the account to user A wallet if the same face value funds are deposit by User A.
So, like Atomic Swap, a user cannot access the other side funds unless he deposits his own funds.
- The deposit triggers an event that will search for a user that wants to trade some Token B for Token A.
- If a match found the smart contract will:
- Check tokens current value to evaluate the amount of the tokens needed for both tokens to cover $100.
- Transfer $100 worth of Token B from the Smart Swap contract to User’s A account.
- Transfer $100 worth of Token A to the User account that is selling Token B.
- Refund tokens if needed.
- If the entire $100 was not covered the search for other matches.
User A’s order can be covered with many users that want to trade Token B for Token A. As long as User A didn’t cancel his order and his order wasn’t completed, the Smart Swap will keep searching for matches, and the order will keep pending.
Remember, user A doesn’t have to worry about losing money due to changes in the cryptocurrencies he/she is trading, the Smart Swap has it covered.
Use Case 2: User A wants to trade $100 worth of BTC for $100 worth of TokenA
In this case, we can’t lock User’s A’s BTCs on the Smart Swap contract because Bitcoin and Ethereum are two different blockchain nets, so we use a signed Bitcoin transaction and a third-party secure wallet service instead.
A signed transaction is like a check: it has a recipient which is the secure wallet in our case and an amount so it will serve the Smart Swap for the locking mechanism it needs.
Let see the process:
- User A submits to the Smart Swap a signed BTC transaction addressed to a third-party secure wallet service.
- The deposit triggers an event that will search for a user that wants to trade tokens A for BTC.
- If a match found the smart contract will:
- Check BTC’s current value to evaluate the number of tokens needed for both BTC and Token A to cover $100.
- Execute the signed BTC transaction, meaning 100 BTC is being moved from User A to the secure wallet.
If the transaction fails to cancel the process.
- Transfer $100 worth of Token A from the Smart Swap contract to User’s A account (this token was deposited to the contract by a user that wants to sell his A tokens for BTC – the matching order).
- Transfer $100 worth of BTC from the secure wallet to the User account that is selling Token A.
- Handle returning funds to the user or pending orders.
Smart Swap is a great way to execute P2P trading. It’s secure, easy to implement, protects the user against losses in case of currency rate changes and it doesn’t require the blockchains involved to have code abilities and the same Hash algorithm (like Atomic Swap does).
I believe we’re going to hear a lot about Smart Swap in the next few months.
Smart Swap: Face Value P2P With Element Zero CTO was originally found on Cryptocurrency News | Tech, Privacy, Bitcoin & Blockchain | Blokt.