Skip to content

Commit

Permalink
remove CLI (saved a branch cli-abandoned-here) logic - moving to api/…
Browse files Browse the repository at this point in the history
…protocol only

import new ethereum-htlc module which includes the ABI and address of the Ethereum HTLCs
update tests to use ganache / truffle v4
can now directly compare bytecode on chain to bytecode in ABI files (since truffle v4)
  • Loading branch information
Chris Hatch committed Jan 22, 2018
1 parent cad1b53 commit 355a214
Show file tree
Hide file tree
Showing 17 changed files with 1,253 additions and 1,198 deletions.
79 changes: 28 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
# xcat
A tool for doing cross chain atomic trades via a [cli](src/cli) or [api](src/protocol.js).

Only trades between Stellar and Ethereum are supported at this stage.
Protocol and api for doing cross chain atomic trades between Stellar and Ethereum.

## Protocol

Stellar XLM <-> Ethereum ETH
* [protocol_stellar_xlm_to_ethereum_eth.md](docs/protocol_stellar_xlm_to_ethereum_eth.md)
* [protocol-scenario1.js](integration-test/protocol-scenario1.js) - script that walks through scenario 1 of the protocol


* [protocol_stellar_xlm_to_ethereum_eth.md](docs/protocol_stellar_xlm_to_ethereum_eth.md)
* [protocol-scenario1.js](integration-test/protocol-scenario1.js) - script that walks through scenario 1 of the protocol

Stellar Asset <-> Ethereum ERC20 Token
* [protocol_stellar_asset_to_ethereum_erc20.md](docs/protocol_stellar_asset_to_ethereum_erc20.md) TODO

* [protocol_stellar_asset_to_ethereum_erc20.md](docs/protocol_stellar_asset_to_ethereum_erc20.md)

## Progress

### Native Token Swap (XLM <-> ETH)
- [x] Protocol API Scenario 1 (Stellar side initiated)
- [ ] Protocol API Scenario 2 (Ethereum side initiated)
- [x] CLI Scenario 1 (Stellar side initiated)
- [ ] CLI Scenario 2 (Ethereum side initiated)
- [ ] Built in communication channel (Telehash Links?)

The protocol for trades initiated from the Stellar side is working as demonstrated by this [script](integration-test/protocol-scenario1.js) which exercises both parties along the path of least resistance. More testing is required around refunds and edge cases. The command line interface (see below) also works for the simple case where each party follows the protocol.
* [x] Protocol API Scenario 1 (Stellar side initiated)
* [ ] Protocol API Scenario 2 (Ethereum side initiated)
* [ ] Built in communication channel (Telehash Links?)

The protocol for trades initiated from the Stellar side is working as demonstrated by this [script](integration-test/protocol-scenario1.js) which exercises both parties along the path of least resistance. More testing is required around refunds and edge cases.

Communication would ideally be done by the tool over some channel rather then having users manually send each other data (see last todo item above). These 2 pieces require manual sharing:
* initial trade.json and trade.json.sig signature (intiater sends after running 'new', counterparty run 'verifysig' and 'import' commands)
* refund tx envelope (party 2 sends to the initiater, initiater puts it in the trade.json file and runs 'status' to continue with the trade)

* initial trade.json and trade.json.sig signature (intiater sends after running 'new', counterparty run 'verifysig' and 'import' commands)
* refund tx envelope (party 2 sends to the initiater, initiater puts it in the trade.json file and runs 'status' to continue with the trade)

These pieces can be found by scanning the ledgers and so don't require communication:
* Ethereum HTLC contract id
* hash(x) preimage (after submission)
* deposit and withdraw transactions on both sides

* Ethereum HTLC contract id
* hash(x) preimage (after submission)
* deposit and withdraw transactions on both sides

### Asset to Token Swap (Asset <-> ERC20)
- [ ] TODO!

* [ ] TODO!

## Trade.json

Trades are defined by a trade.json file conforming to the JSON schema [here](src/schema/trade.json).

Example:

```
{
"timelock": 1505729032,
Expand All @@ -60,66 +64,39 @@ Example:
}
```

## CLI

```
Usage: cli [options] [command]
Stellar tool for doing cross chain atomic trades
Options:
-h, --help output usage information
Commands:
new|n <trade.json> Initiate a new trade given a trade.json file
import|i <trade.json> Import a trade from a trade.json file
status|s <tradeId> Check status of a trade
verifysig|v <trade.json> <trade.json.sig> Verify signature for a trade.json
help [cmd] display help for [cmd]
```

### Summary

```
party1> npm run cli new ./trade_localnet.json
party2> npm run cli verify trade-little-eagle-37.json trade-little-eagle-37.json.sig
party2> npm run cli import trade-little-eagle-37.json
party1+2> npm run cli status little-eagle-37
```
After 'import' only the 'status' command is needed. It will scan the ledgers, determine what the next step is for the party running it and carry it out as required.

## Develop

### Start Stellar private network

```
docker run -it --rm --name horizon-integrationnet -p 8000:8000 zulucrypto/stellar-integration-test-network
```

### Start Ethereum local network

```
PHRASE="end staff push admit delay abandon ability nurse renew alert stomach jazz"
docker run --rm -it -p 8545:8545 chatch/ethereumjs-testrpc:4.1.3 -m "$PHRASE" $@
```

NOTE: PHRASE is important as the integration tests expect specific accounts to exist.

### Deploy HashedTimelock smart contract

```
git clone https://github.com/chatch/hashed-timelock-contract-ethereum
npm i -g truffle
truffle migrate
```

### Run tests

```
npm run test
```

### Run integration test

```
npm run test-protocol
```

4 changes: 1 addition & 3 deletions integration-test/protocol-scenario1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import chalk from 'chalk'
import sdk from 'stellar-sdk'
import Web3 from 'web3'
import expect from 'expect'
Expand Down Expand Up @@ -77,8 +76,7 @@ const configParty2 = {
}

const log = msg => console.info(`INFO: ${msg}`)
const logError = msg =>
console.error(chalk.red(`ERROR: ${JSON.stringify(msg, null, 2)}`))
// const logError = msg => console.error(`ERROR: ${JSON.stringify(msg, null, 2)}`)

const main = async () => {
/*
Expand Down
Loading

0 comments on commit 355a214

Please sign in to comment.