Git Product home page Git Product logo

etomic-swap's Introduction

Etomic Swap Smart Contracts for BarterDex platform.

Build Status
Etomic swap Smart Contract is implemented to support ETH and ERC20 atomic swaps on BarterDex platform. Please note that this project is not production ready yet!

Swap workflow

Smart Contracts follow standard symmetric Atomic swap protocol.
Despite example shows swap of ETH/ERC20 this approach will work also for ETH/ERC20 swaps to any currency supporting HTLC (https://en.bitcoin.it/wiki/Hashed_Timelock_Contracts).

  1. Bob wants to change his 1 ETH to Alice 1 ERC20 token.
  2. Alice sends dexfee (handled externally by client side).
  3. Bob sends payment locked with hash of the Secret. He can refund the payment in 4 hours.
  4. Alice sends payment locked with Bob Secret hash. She can refund her payment in 2 hours.
  5. Bob spends Alice payment by revealing the secret.
  6. Alice spends Bob payment using revealed secret.

Project structure

  1. contracts - Smart Contracts source code.
  2. test - Smart contracts unit tests.

How to setup dev environment?

  1. Install docker.
  2. Run docker-compose build.
  3. cp .env.empty .env.
  4. Start containers docker-compose up -d.
  5. Install project dependencies: docker-compose exec workspace yarn.
  6. To run tests: docker-compose exec workspace truffle test.

Related links

  1. Komodo platform - https://www.komodoplatform.com

Useful links for smart contracts development

  1. Truffle suite - https://github.com/trufflesuite/truffle
  2. Ganache-cli (EthereumJS Testrpc) - https://github.com/trufflesuite/ganache-cli
  3. Zeppelin Solidity - https://github.com/OpenZeppelin/zeppelin-solidity

etomic-swap's People

Contributors

artemii235 avatar caglaryucekaya avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

etomic-swap's Issues

ERC20 test token tx send fails

The swap between ETH and other coins are working both ways using testnet and mainnet. When we tried swapping ERC20 test tokens, we see swap completed message in console, then the tx from bob in etherscan says pending and it fails after that.

I used {\"coin\":\"\EBR\",\"name\":\"Beereum\",\"etomic\":\"0x354ad7bd20ec1c8919a80d7ff40c854202301e78\",\"rpcport\":80}, in my coins file.

Please check the last transactions got failed from this address. They are related to those swaps.
https://ropsten.etherscan.io/address/0x012f7e74120d3d002e8f215ccc6f6f65618f00cb

Market maker got crashed while swap

Crash details, While undergoing BEER/EBR swap, found When order get connected I see, Order get struck at Bobdeposit and Found The debug Output as below

found mini.6 1.99343773 for targetval 1.00004999 -> targetval2 0.00131706, ratio 1.99
set inuse until 1519324633 lag.120 for cb4f80ba5432c5f679dccb6316cf188812e0a7ed5f286602fa45b5bfb68026a0/v1
set inuse until 1519324633 lag.120 for 4aff90960e9b247f8b36167d8e7ffe09f866f9ae5778caefff0a315da77d1aec/v1
LP_trade BEER/EBR 0.05002051 vol 1.00001000 dest.(0000000000000000000000000000000000000000000000000000000000000000) maxprice 20.02000000 etomicdest.(0x03d76a0329c441c8064825d1db8c172034f05cde)

. 1st refht BEER 79e1c975583838863abcd71933f4134ec231338ca4df6898c625aa0f5d18139d <- 14006, scan 0 0
. 1st refht ETOMIC 4aff90960e9b247f8b36167d8e7ffe09f866f9ae5778caefff0a315da77d1aec <- 6349, scan 0 0
2113 (1507254906 2888540503) request id.5749854903066034177 BEER/EBR 0.05002051 -> 1.00001000 (19.99199928) | RT.0 0 n169
2114 (543275228 2470591370) reserved id.5749854903066034177 BEER/EBR 0.20828532 -> 1.00001000 ( 4.80115449) | RT.0 0 n169
updated eae11b910c2392570b1616903ad3dcc88d2dad133588cd67ad3e6601523cff95/v0 BEER/EBR 20828532 price 4.80138501

received quote BEER/EBR 4.80138501
aliceid.5749854903066034177 got new bestprice 4.80138501 dynamictrust -0.20828532 (unconf 0.00000000) slowresponse.0
New priority.1 max_Reserved_msgs.2
2116 (543275228 2470591370) connect id.5749854903066034177 BEER/EBR 0.20828532 -> 1.00001000 ( 4.80115449) | RT.0 0 n169
2116 (543275228 1680505311) connected id.5749854903066034177 BEER/EBR 0.20828532 -> 1.00001000 ( 4.80115449) | RT.0 0 n169
alice ff1362b81c859ced6aebb2877b31007d3b62b3a37a339d3dbad39e25536af624 received CONNECTED.(5749854903066034177)
CONNECTED ALICE
CONNECTED numpending.0 tradeid.989474840 requestid.543275228 quoteid.1680505311 pairstr.tcp://51.255.38.28:24890
BEER/EBR bid 20.02000000 ask 0.00000000 values 0.00000000 0.00000000
LP_swapinit request.543275228 iambob.0 (BEER/EBR) quoteid.1680505311
jumblrflag.-2 <<<<<<<<< r.543275228 q.1680505311, 0.20827532 bobconfs.1, 1.00000000 aliceconfs.0 taddr.0 0
etomic src ( 0x012f7e74120d3d002e8f215ccc6f6f65618f00cb) dest (0x354ad7bd20ec1c8919a80d7ff40c854202301e78 0x03d76a0329c441c8064825d1db8c172034f05cde)
alice pairstr.(tcp://51.255.38.28:24890) pairsock.2 pthread_t 8
[New Thread 0x7fffb7fff700 (LWP 27899)]
start swap iamalice pair.2
send >>>>>>>>> r.543275228 q.1680505311 datalen.16046
MISMATCHED required confirms me.(0 1) vs (1 1) max.(6 6) othermax.(6 6)
NUMCONFIRMS for SWAP alice.1 bob.1, otheristrusted.0 othertrusts.0
SEND pubA0/1 cbfb56e70ea3beed4f176a095ae920cad2ecd1334a4854b608d2a2eb78d991f3
CUT VERIFIED
reset ETOMIC ap->utxos
added 15 from ETOMIC listunspents
dustcombine.0 numpre.1 min0.(nil) min1.(nil) numutxos.13 amount 1.00002999
preselected[0]: cb4f80ba5432c5f679dccb6316cf188812e0a7ed5f286602fa45b5bfb68026a0/v1 1.99343773
numunspents.13 vini.0 value 1.99343773, total 1.99343773 remains -0.99340774 interest 0.00000000 sum 0.00000000 cb4f80ba5432c5f679dccb6316cf188812e0a7ed5f286602fa45b5bfb68026a0/v1
set inuse until 1519325117 lag.600 for cb4f80ba5432c5f679dccb6316cf188812e0a7ed5f286602fa45b5bfb68026a0/v1
reset ETOMIC ap->utxos
added 15 from ETOMIC listunspents
dustcombine.0 numpre.1 min0.(nil) min1.(nil) numutxos.13 amount 0.00129700
preselected[0]: 4aff90960e9b247f8b36167d8e7ffe09f866f9ae5778caefff0a315da77d1aec/v1 0.09819297
numunspents.13 vini.0 value 0.09819297, total 0.09819297 remains -0.09689597 interest 0.00000000 sum 0.00000000 4aff90960e9b247f8b36167d8e7ffe09f866f9ae5778caefff0a315da77d1aec/v1
set inuse until 1519325117 lag.600 for 4aff90960e9b247f8b36167d8e7ffe09f866f9ae5778caefff0a315da77d1aec/v1
ETH txid received: 0x0000000000000000000000000000000000000000000000000000000000000000
0 wait for bobdeposit bDAeZVuvW8e3ZdnZj2XKC3SfGQsyMS7w5L numconfs.1 BEER 0cb3db7eec7e892a78b602e858b12e1f1d88df8f591eb697219353f7f5a30769
0 wait for bobdeposit bDAeZVuvW8e3ZdnZj2XKC3SfGQsyMS7w5L numconfs.1 BEER 0cb3db7eec7e892a78b602e858b12e1f1d88df8f591eb697219353f7f5a30769
[New Thread 0x7fffb77fe700 (LWP 27901)]
[Thread 0x7fffb77fe700 (LWP 27901) exited]
[New Thread 0x7fffb77fe700 (LWP 27902)]
[Thread 0x7fffb77fe700 (LWP 27902) exited]

Thread 19 "marketmaker" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb7fff700 (LWP 27899)]
0x0000000000621fcb in sendRawTx (
rawTx=rawTx@entry=0x7fffac5c2170 "0xf9012a3485174876e800830493e094e1d4236c5774d35dc47dcc2e5e0ccfc463a3289c80b8c4184db3bfcb4f80ba5432c5f679dccb6316cf188812e0a7ed5f286602fa45b5bfb68026a", '0' <repeats 50 times>, "d"...) at /root/SuperNET/iguana/exchanges/etomicswap/etomiccurl.c:86
86 char* tmp = cJSON_GetObjectItem(json, "result")->valuestring;
(gdb)
(gdb)
(gdb)
(gdb)
(gdb) backtrace
#0 0x0000000000621fcb in sendRawTx ( rawTx=rawTx@entry=0x7fffac5c2170 "0xf9012a3485174876e800830493e094e1d4236c5774d35dc47dcc2e5e0ccfc463a3289c80b8c4184db3bfcb4f80ba5432c5f679dccb6316cf188812e0a7ed5f286602fa45b5bfb68026a", '0' <repeats 50 times>, "d"...) at /root/SuperNET/iguana/exchanges/etomicswap/etomiccurl.c:86 #1 0x00000000004dd584 in aliceSendsErc20Payment (input=..., txData=...) at /root/SuperNET/iguana/exchanges/etomicswap/etomiclib.cpp:103 #2 0x000000000042bae5 in LP_etomicalice_send_payment (swap=swap@entry=0x7fffb0003ad0) at /root/SuperNET/iguana/exchanges/LP_etomic.c:63 #3 0x000000000042d34e in sendEthTx (swap=swap@entry=0x7fffb0003ad0, rawtx=rawtx@entry=0x7fffb00139a0) at /root/SuperNET/iguana/exchanges/LP_etomic.c:353 #4 0x00000000004425c3 in LP_swapdata_rawtxsend (pairsock=2, swap=0x7fffb0003ad0, msgbits=4096, rawtx=0x7fffb00139a0, nextbits=2048, suppress_swapsend=0, maxlen=<optimized out>, data=<optimized out>) at /root/SuperNET/iguana/exchanges/LP_swap.c:701 #5 0x0000000000465e9f in LP_aliceloop (_swap=0x7fffb0003ad0) at /root/SuperNET/iguana/exchanges/LP_swap.c:919 #6 0x00007ffff796c6ba in start_thread (arg=0x7fffb7fff700) at pthread_create.c:333 #7 0x00007ffff6b8a41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109 (gdb)

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.