Coder Social home page Coder Social logo

freeton-atomic-swap's Introduction

Developers Contest: Atomic Swaps on Free TON

Requirements

  • The possibility of a safe return of funds to each of the parties if the other party does not comply with the terms of the trade
  • Open sources of smart contracts published at GitHub/GitLab or another open repository
  • Documentation
  • Name and contact information of the contestant for communication (Telegram username, e-mail)

Summary

Author - Nail Khafizov, independent software developer.

Implementation and demonstration smart contracts of Atomic Swaps:

Ton Crystal, Native Ether, Ethereum ERC20, Bitcoin

Motivation

Develop an infrastructure that allows users to perform transactions between different blockchains without escrow in an untrusted environment. It will make the exchange market around TON Crystal more secure for OTC transactions.

Abstract

Atomic Swap — a smart contract technology enables the exchange of one cryptocurrency for another without using centralized intermediaries (such as exchanges). I've learned two ways of swaps:

  1. By using Hashed TimeLock Contract
  2. By using Simplified Payment Verification.

HTLC — the most simple. It requires supporting common hash function (e.g. sha256) from blockchain and TimeLock contract functionality.
+ Сan be fully decentralised
- Requires side communication between participants and locking money on specific time

SPV requires from one of two blockchains supporting runnig complex smart contracts (e.g. Ethereum or Ton) to verify transaction's Merke Proof of transfer.
+ Transfer can be fast and automatic
- Requires solution to identify the source of the transaction: mainnet / testnet / side blockchain by using oracles smart contracts / supporting SPV verification by validators.


I chose HTLC, because:

  • Time of contest is limited to 3 weeks
  • High transmission speed can be achieved through automation Atomic Swap Wallet, which supports SPV verification different blockchains off-chain.

Implementation

Tech Stack

FreeTon: TON-Solidity-Compiler, Solidity, JS for testing
Ethereum: Truffle, Solidity, JS for testing
Bitcoin (Work in progress): bitcoinjs-lib, JS

Repository structure

./ton - Atomic Swap Contracts for FreeTon blockchain
./eth - Atomic Swap Contracts for Ethereum blockchain
./btc - Atomic Swap Contracts for Bitcoin blockchain
./app - App for demostrating working of Smart Contracts at testnets. Not used in production, only for learning purpose

WorkFlow

workflow image

Commands:

initiate (participant address, amount, secret hash, lock time)
participate (initiator address, amount, secret hash, lock time)
redeem (secret)
refund

Steps:

  1. Part A have to generate the secret limited by 32 bytes and store it securely. Next, Part A initiate and create contract with hash of secret and participant's address. In this contract the locktime should be doubled to avoid scam (e. g. 24h * 2 = 48h). After that, Part A have to send transaction or smart contract address to Part B.
  2. Part B have to verify Part A's contract: participant's address, lockTime, amount, hash of code. If everything is OK — Part B should participate and create contract with Part A's secret hash, otherwise Part B can do nothing. Part B should be careful, lockTime should be less Part A's lockTime at the moment of creating contract. After, Part B have to send transaction or smart contract address to Part A.
  3. Part A have to verify Part B's contract. If everything is OK — Part A can redeem from Part B's contract and reveal secret, otherwise Part A can wait timeLock and refund his transfer.
  4. Part B should extract secret and redeem from Part A's contract.

The most part of steps can be automated by wallet, with the exception of exchange address and transactions

References

https://www.investopedia.com/terms/a/atomic-swaps.asp
https://github.com/decred/atomicswap
https://medium.com/summa-technology/cross-chain-auction-technical-f16710bfe69f

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.