Skip to content
raphpapPublic

About

First step towards a truly trustless Ethereum to Bitcoin swapper

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Inspiration

The era of centralized exchanges is about to end. Last year, during the QuadrigaCX fiasco, 110 000 of my canadian peers were affected, some being close friends, totaling more than $100 millions in losses. Crazy thing is, this is only a drop in the bucket when talking about crypto exchanges being hacked and/or ill-intentionned and user's fund being ripped away.

LinkSwap is the first step towards a truly trustless way to trade Ethereum with Bitcoin, for which I believe there is a great demand.

Demo

Make sure to have Metamask installed!

Website: https://raphpap.github.io/link-swap/#/

The contract is currently deployed here on Ropsten, and uses data from the BTC Tesnet.

Homescreen

How this works:

In this scenario, Alice is the Ethereum trader and Bob is the Bitcoin trader.

Alice creates a contract by entering:

  • A never used before BTC address
  • The number of offered ETH
  • The requested amount of BTC
  • A possible ETH collateral (to avoid Bob from freezing her funds without consequences)

Create contract

Anyone can read the contract information if they know the BTC address

Bob can accept a contract by sending the right amount of ETH as a collateral

  • Coincidently, his ETH adress is the only one who can receive Alice's ETH if Alice receives her requested BTC
  • Bob should then read the contract to validate that he "got the spot"
  • Bob now has 4 hours to proceed to the BTC payment to Alice

Accept contract

On the BTC chain, Bob proceeds to send AS A SINGLE TRANSACTION the EXACT AMOUNT of requested BTC to Alice

  • Bob must take note of the transaction hash (id) and wait for at least 6 confirmations

BTC transaction

On the platform, Bob then fullfills the contract by inputing the transaction hash

Fullfill contract

Honeycomb's Oracle then uses Tatum's API to fetch the following information:

  • Nb. confirmations (must be > 6)
  • voutAddress (must be equal to Alice's BTC address)
  • voutValue (must be equal to Alice's requested BTC amount)
  • If all is good, Bob receives his collateral back along with Alice's ETH

Alice can cancel her contract if either of the following is true:

  • The contract hasn't been accepted yet
    • Alice receives her balance back
  • The contract has been accepted but more than 4 hours has passed withouth fullfillment
    • Alice receives her balance back along with the ETH collateral
  • Once cancelled, the Contract's information cannot be read anymore

Technical limitations

The contract's functions are currently quite costly to call, especially the fullfillment call due to value type conversions.

The BTC adress is currently trimmed down to 32 characters (during the expected vs result obained via oracle only) due to a current technical limitation with Chainlink oracles. This is quite bad for the BTC Testnet since addresses are very long (40 chars). On BTC mainnet, addresses are often 26-34 char so this limitation could be worked-around.

Currently, 3 different calls are made to the Honeycomb Oracle to fetch all three needed informations for validation. A single call would be better.

Local development

Before installation

npm install -g truffle

  • Install the Metamask add-on to your browser and create a wallet. Note down the mnemonics. Fund it with Ropsten ETH and Ropsten LINK.

  • Create an Infura account, get an endpoint URL for the Ropsten testnet and note it down.

  • Install nv to load the environment variables

  • (Optional) Install Visual Studio Code

Installation

  • Clone this repo

  • Install the dependencies:

npm install

  • Create the file that you are going to enter your environment variables:

cp .env.example .env

  • Open the newly created .env file and enter RPC_URL and PRIVATE_KEYS you noted earlier.

  • Deploy the contract (Ropsten LINK will be transferred from your wallet to the contract automatically during deployment)

nv .env npm run migrate:live

Helper Scripts

Fund the Deployed Contract

nv .env npm run script-1
(User 1) - Create a Swap Contract

nv .env npm run script-2
(Anyone) - Read a Swap Contract

nv .env npm run script-3
(User 2) - Accept a Swap Contract

nv .env npm run script-4
(User 2) - Fulfill a Swap Contract

nv .env npm run script-5
(User 2) - Request nbConfirmations

nv .env npm run script-5.1
(User 2) - Request voutAddress

nv .env npm run script-5.2
(User 2) - Request voutValue

nv .env npm run script-5.3
(User 1) - Cancel a Swap Contract

nv .env npm run script-6

Running the Client

Simply go into the client folder and follow the instructions

About

First step towards a truly trustless Ethereum to Bitcoin swapper

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages