mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-10 06:38:04 -05:00
add joining stagenet and recovery module documentation (#117)
This commit is contained in:
3
Makefile
3
Makefile
@@ -17,5 +17,8 @@ install:
|
||||
build:
|
||||
./scripts/build.sh
|
||||
|
||||
build-all:
|
||||
ALL=true ./scripts/build.sh
|
||||
|
||||
build-dleq:
|
||||
./scripts/install-rust.sh && cd farcaster-dleq && cargo build --release && cd ..
|
||||
146
README.md
146
README.md
@@ -4,152 +4,36 @@ This is a WIP implementation of ETH-XMR atomic swaps, currently in the pre-produ
|
||||
|
||||
## Disclaimer
|
||||
|
||||
**This code is unaudited and under active development and should not be used on mainnet!** Running this on mainnet may result in loss of funds.
|
||||
**This code is unaudited and under active development and should not be used on mainnet or any networks that hold monetary value!!!**
|
||||
|
||||
## Protocol
|
||||
|
||||
Please see the [protocol documentation](docs/protocol.md) for how it works.
|
||||
|
||||
## Instructions
|
||||
## Swap instructions
|
||||
|
||||
### Requirements
|
||||
### Trying it locally
|
||||
|
||||
- go 1.17
|
||||
- ganache-cli (can be installed with `npm i -g ganache-cli`) I suggest using nvm to install npm: https://github.com/nvm-sh/nvm#installing-and-updating
|
||||
To try the swap locally with two nodes (maker and taker) on a development environment, follow the instructions [here](./docs/local.md).
|
||||
|
||||
Note: this program has only been tested on Ubuntu 20.04.
|
||||
### Trying it on Monero's stagenet and Ethereum's Goerli testnet
|
||||
|
||||
#### Set up development environment
|
||||
To try the swap on Stagenet/Goerli, follow the instructions [here](./docs/stagenet.md).
|
||||
|
||||
Note: the `scripts/install-monero-linux.sh` script will download the monero binaries needed for you. You can also check out the `scripts/run-unit-tests.sh` script for the commands needed to setup the environment.
|
||||
|
||||
Start ganache-cli with determinstic keys:
|
||||
```
|
||||
ganache-cli -d
|
||||
```
|
||||
|
||||
Start monerod for regtest, this binary is in the monero bin directory:
|
||||
```bash
|
||||
cd ./monero-x86_64-linux-gnu
|
||||
./monerod --regtest --fixed-difficulty=1 --rpc-bind-port 18081 --offline
|
||||
```
|
||||
|
||||
Create a wallet for "Bob", who will own XMR later on:
|
||||
```
|
||||
./monero-wallet-cli // you will be prompted to create a wallet. In the next steps, we will go with "Bob", without password. Remember the name and optionally the password for the upcoming steps
|
||||
```
|
||||
You do not need to mine blocks, and you can exit the the wallet-cli once Bob's account has been created by typing "exit".
|
||||
|
||||
Start monero-wallet-rpc for Bob on port 18083. Make sure `--wallet-dir` corresponds to the directory the wallet from the previous step is in:
|
||||
```
|
||||
./monero-wallet-rpc --rpc-bind-port 18083 --password "" --disable-rpc-login --wallet-dir .
|
||||
```
|
||||
|
||||
Open the wallet:
|
||||
```bash
|
||||
curl http://localhost:18083/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"open_wallet","params":{"filename":"Bob","password":""}}' -H 'Content-Type: application/json'
|
||||
|
||||
# {
|
||||
# "id": "0",
|
||||
# "jsonrpc": "2.0",
|
||||
# "result": {
|
||||
# }
|
||||
# }
|
||||
```
|
||||
|
||||
Determine the address of `Bob` by looking at `monero-wallet-rpc` logs, in our case 45GcPCB ... uLkV5bTrZRe
|
||||
```
|
||||
# 2022-01-20 21:40:06.460 W Loaded wallet keys file, with public address: 45GcPCBQgCG3tYcYqLdj4iQixpDZYw1MGew4PH1rthp9X2YrB2c2dty1r7SwhbCXw1RJMvfy8cW1UXyeESTAuLkV5bTrZRe
|
||||
```
|
||||
|
||||
Then, mine some blocks on the monero test chain by running the following RPC command, replacing the address with the one from Bob's wallet:
|
||||
```
|
||||
curl -X POST http://127.0.0.1:18081/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"generateblocks","params":{"wallet_address":"45GcPCBQgCG3tYcYqLdj4iQixpDZYw1MGew4PH1rthp9X2YrB2c2dty1r7SwhbCXw1RJMvfy8cW1UXyeESTAuLkV5bTrZRe","amount_of_blocks":100}' -H 'Content-Type: application/json'
|
||||
```
|
||||
|
||||
This will deposit some XMR in Bob's account.
|
||||
|
||||
|
||||
Start monero-wallet-rpc for Alice on port 18084 (note that the directory provided to `--wallet-dir` is where Alice's XMR wallet will end up):
|
||||
```
|
||||
./monero-wallet-rpc --rpc-bind-port 18084 --password "" --disable-rpc-login --wallet-dir .
|
||||
```
|
||||
#### Build and run
|
||||
|
||||
Build binary:
|
||||
```
|
||||
make build
|
||||
```
|
||||
|
||||
This creates `swapd` and `swapcli` binaries in the root directory.
|
||||
|
||||
To run as Alice, execute in terminal 1:
|
||||
```
|
||||
./swapd --dev-alice
|
||||
```
|
||||
|
||||
Alice will print out a libp2p node address, for example `/ip4/127.0.0.1/tcp/9933/p2p/12D3KooWFUEQpGHQ3PtypLvgnWc5XjrqM2zyvdrZXin4vTpQ6QE5`. This will be used for Bob to connect.
|
||||
|
||||
To run as Bob and connect to Alice, replace the bootnode in the following line with what Alice logged, and execute in terminal 2:
|
||||
|
||||
```
|
||||
./swapd --dev-bob --wallet-file Bob --bootnodes /ip4/127.0.0.1/tcp/9933/p2p/12D3KooWFUEQpGHQ3PtypLvgnWc5XjrqM2zyvdrZXin4vTpQ6QE5
|
||||
```
|
||||
|
||||
Note: when using the `--dev-alice` and `--dev-bob` flags, Alice's RPC server runs on http://localhost:5001, Bob's runs on http://localhost:5002 by default.
|
||||
|
||||
In terminal 3, we will interact with the swap daemon using `swapcli`.
|
||||
|
||||
Firstly, we need Bob to make an offer and advertise it, so that Alice can take it:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --daemon-addr=http://localhost:5002
|
||||
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
|
||||
```
|
||||
|
||||
Alternatively, you can make the offer via websockets and get notified when the swap is taken:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --daemon-addr=ws://localhost:8082 --subscribe
|
||||
```
|
||||
|
||||
Now, we can have Alice begin discovering peers who have offers advertised.
|
||||
```bash
|
||||
./swapcli discover --provides XMR --search-time 3
|
||||
# [[/ip4/127.0.0.1/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv]]
|
||||
```
|
||||
|
||||
Query the returned peer as to how much XMR they can provide and their preferred exchange rate (replace `"--multiaddr"` field with one of the addresses returned in the above step):
|
||||
```bash
|
||||
./swapcli query --multiaddr /ip4/192.168.0.101/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv
|
||||
# Offer ID=cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 Provides=XMR MinimumAmount=0.1 MaximumAmount=1 ExchangeRate=0.05
|
||||
```
|
||||
|
||||
Now, we can tell Alice to initiate the protocol w/ the peer (Bob), the offer (copy the Offer id from above), and a desired amount to swap:
|
||||
```bash
|
||||
./swapcli take --multiaddr /ip4/192.168.0.101/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05
|
||||
# Initiated swap with ID=0
|
||||
```
|
||||
|
||||
Alternatively, you can take the offer via websockets and get notified when the swap status updates:
|
||||
```bash
|
||||
./swapcli take --multiaddr /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7 --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05 --subscribe --daemon-addr=ws://localhost:8081
|
||||
```
|
||||
|
||||
If all goes well, you should see Alice and Bob successfully exchange messages and execute the swap protocol. The result is that Alice now owns the private key to a Monero account (and is the only owner of that key) and Bob has the ETH transferred to him. On Alice's side, a Monero wallet will be generated in the `--wallet-dir` provided in the `monero-wallet-rpc` step for Alice.
|
||||
|
||||
To query the information for an ongoing swap, you can run:
|
||||
```bash
|
||||
./swapcli get-ongoing-swap
|
||||
```
|
||||
|
||||
To query information for a past swap using its ID, you can run:
|
||||
```bash
|
||||
./swapcli get-past-swap --id <id>
|
||||
```
|
||||
## Additional documentation
|
||||
|
||||
### Developer instructions
|
||||
|
||||
Please see the [developer docs](docs/developing.md).
|
||||
|
||||
### Recovery module
|
||||
|
||||
In case the swap process crashes during a swap, you can recover your funds with the recovery module. Please see the instructions [here](./docs/recovery.md).
|
||||
|
||||
### RPC API
|
||||
|
||||
The swap process comes with a HTTP JSON-RPC API as well as a Websockets API. You can find the documentation [here](./docs/rpc.md).
|
||||
|
||||
## Contributions
|
||||
|
||||
If you'd like to contribute, feel free to fork the repo and make a pull request. Please make sure the CI is passing - you can run `make build`, `make lint`, and `make test` to make sure the checks pass locally.
|
||||
|
||||
@@ -40,7 +40,7 @@ const (
|
||||
defaultAliceRPCPort = 5001
|
||||
defaultBobRPCPort = 5002
|
||||
|
||||
defaultWSPort = 8080
|
||||
defaultWSPort = 6005
|
||||
defaultAliceWSPort = 8081
|
||||
defaultBobWSPort = 8082
|
||||
)
|
||||
|
||||
24
docs/build.md
Normal file
24
docs/build.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Building the project
|
||||
|
||||
1. Install go [here](https://go.dev/doc/install).
|
||||
|
||||
For Linux 64-bit:
|
||||
```bash
|
||||
wget https://go.dev/dl/go1.18.linux-amd64.tar.gz
|
||||
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.linux-amd64.tar.gz
|
||||
echo "export PATH=$PATH:/usr/local/go/bin" >> .profile
|
||||
source .profile
|
||||
```
|
||||
|
||||
2. Clone the repo:
|
||||
```bash
|
||||
git clone https://github.com/noot/atomic-swap.git
|
||||
cd atomic-swap
|
||||
```
|
||||
|
||||
3. Finally, build the repo:
|
||||
```bash
|
||||
make build
|
||||
```
|
||||
|
||||
This creates the binaries `swapd` and `swapcli`.
|
||||
@@ -1,5 +1,15 @@
|
||||
# Developing
|
||||
|
||||
## Building the project
|
||||
|
||||
Follow the [build instructions](./build.md) to ensure you have Go installed and can build the project.
|
||||
|
||||
## Setting up your local environment
|
||||
|
||||
Follow the instructions [here](local.md) to set up your local Alice (ETH-holder, XMR-wanter) and Bob (XMR-holder, ETH-wanter) nodes.
|
||||
|
||||
You can also run `bash scripts/setup-env.sh` to quickly set up the local Monero and ganache-cli environment.
|
||||
|
||||
## Deploying or using deployed SwapFactory.sol
|
||||
|
||||
The swap program uses a "factory" contract for the Ethereum side to reduce gas costs from deploying a new contract for each swap. The contract can be found in [here](../ethereum/contracts/SwapFactory.sol). For each new swap, the eth-holding party will call `NewSwap` on the factory contract, initiating a swap instance inside the contract.
|
||||
@@ -73,4 +83,11 @@ make test
|
||||
This include tests for main protocol functionality, such as:
|
||||
1. Success case, where both parties obey the protocol
|
||||
2. Case where Bob never locks monero on his side. Alice can Refund
|
||||
3. Case where Bob locks monero, but never claims his ether from the contract
|
||||
3. Case where Bob locks monero, but never claims his ether from the contract
|
||||
|
||||
You can also run
|
||||
```
|
||||
make test-integration
|
||||
```
|
||||
|
||||
to run integration tests which spin up 3 local nodes and execute calls between them.
|
||||
BIN
docs/images/ui-swapping.png
Normal file
BIN
docs/images/ui-swapping.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 164 KiB |
BIN
docs/images/ui-take.png
Normal file
BIN
docs/images/ui-take.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 164 KiB |
BIN
docs/images/ui.png
Normal file
BIN
docs/images/ui.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 137 KiB |
135
docs/local.md
Normal file
135
docs/local.md
Normal file
@@ -0,0 +1,135 @@
|
||||
# Trying the swap locally
|
||||
|
||||
### Requirements
|
||||
|
||||
- go 1.17+ (see [build instructions](./build.md) to download Go.)
|
||||
- ganache-cli (can be installed with `npm i -g ganache-cli`) I suggest using nvm to install npm: https://github.com/nvm-sh/nvm#installing-and-updating
|
||||
|
||||
Note: this program has only been tested on Ubuntu 20.04.
|
||||
|
||||
#### Set up development environment
|
||||
|
||||
Note: the `scripts/install-monero-linux.sh` script will download the monero binaries needed for you. You can also check out the `scripts/run-unit-tests.sh` script for the commands needed to setup the environment.
|
||||
|
||||
Start ganache-cli with determinstic keys:
|
||||
```
|
||||
ganache-cli -d
|
||||
```
|
||||
|
||||
Start monerod for regtest, this binary is in the monero bin directory:
|
||||
```bash
|
||||
cd ./monero-x86_64-linux-gnu
|
||||
./monerod --regtest --fixed-difficulty=1 --rpc-bind-port 18081 --offline
|
||||
```
|
||||
|
||||
Create a wallet for "Bob", who will own XMR later on:
|
||||
```
|
||||
./monero-wallet-cli // you will be prompted to create a wallet. In the next steps, we will go with "Bob", without password. Remember the name and optionally the password for the upcoming steps
|
||||
```
|
||||
You do not need to mine blocks, and you can exit the the wallet-cli once Bob's account has been created by typing "exit".
|
||||
|
||||
Start monero-wallet-rpc for Bob on port 18083. Make sure `--wallet-dir` corresponds to the directory the wallet from the previous step is in:
|
||||
```
|
||||
./monero-wallet-rpc --rpc-bind-port 18083 --password "" --disable-rpc-login --wallet-dir .
|
||||
```
|
||||
|
||||
Open the wallet:
|
||||
```bash
|
||||
curl http://localhost:18083/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"open_wallet","params":{"filename":"Bob","password":""}}' -H 'Content-Type: application/json'
|
||||
|
||||
# {
|
||||
# "id": "0",
|
||||
# "jsonrpc": "2.0",
|
||||
# "result": {
|
||||
# }
|
||||
# }
|
||||
```
|
||||
|
||||
Determine the address of `Bob` by looking at `monero-wallet-rpc` logs, in our case 45GcPCB ... uLkV5bTrZRe
|
||||
```
|
||||
# 2022-01-20 21:40:06.460 W Loaded wallet keys file, with public address: 45GcPCBQgCG3tYcYqLdj4iQixpDZYw1MGew4PH1rthp9X2YrB2c2dty1r7SwhbCXw1RJMvfy8cW1UXyeESTAuLkV5bTrZRe
|
||||
```
|
||||
|
||||
Then, mine some blocks on the monero test chain by running the following RPC command, replacing the address with the one from Bob's wallet:
|
||||
```
|
||||
curl -X POST http://127.0.0.1:18081/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"generateblocks","params":{"wallet_address":"45GcPCBQgCG3tYcYqLdj4iQixpDZYw1MGew4PH1rthp9X2YrB2c2dty1r7SwhbCXw1RJMvfy8cW1UXyeESTAuLkV5bTrZRe","amount_of_blocks":100}' -H 'Content-Type: application/json'
|
||||
```
|
||||
|
||||
This will deposit some XMR in Bob's account.
|
||||
|
||||
|
||||
Start monero-wallet-rpc for Alice on port 18084 (note that the directory provided to `--wallet-dir` is where Alice's XMR wallet will end up):
|
||||
```
|
||||
./monero-wallet-rpc --rpc-bind-port 18084 --password "" --disable-rpc-login --wallet-dir .
|
||||
```
|
||||
#### Build and run
|
||||
|
||||
Build binary:
|
||||
```
|
||||
make build
|
||||
```
|
||||
|
||||
This creates `swapd` and `swapcli` binaries in the root directory.
|
||||
|
||||
To run as Alice, execute in terminal 1:
|
||||
```
|
||||
./swapd --dev-alice
|
||||
```
|
||||
|
||||
Alice will print out a libp2p node address, for example `/ip4/127.0.0.1/tcp/9933/p2p/12D3KooWFUEQpGHQ3PtypLvgnWc5XjrqM2zyvdrZXin4vTpQ6QE5`. This will be used for Bob to connect.
|
||||
|
||||
To run as Bob and connect to Alice, replace the bootnode in the following line with what Alice logged, and execute in terminal 2:
|
||||
|
||||
```
|
||||
./swapd --dev-bob --wallet-file Bob --bootnodes /ip4/127.0.0.1/tcp/9933/p2p/12D3KooWFUEQpGHQ3PtypLvgnWc5XjrqM2zyvdrZXin4vTpQ6QE5
|
||||
```
|
||||
|
||||
Note: when using the `--dev-alice` and `--dev-bob` flags, Alice's RPC server runs on http://localhost:5001, Bob's runs on http://localhost:5002 by default.
|
||||
|
||||
In terminal 3, we will interact with the swap daemon using `swapcli`.
|
||||
|
||||
Firstly, we need Bob to make an offer and advertise it, so that Alice can take it:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --daemon-addr=http://localhost:5002
|
||||
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
|
||||
```
|
||||
|
||||
Alternatively, you can make the offer via websockets and get notified when the swap is taken:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --daemon-addr=ws://localhost:8082 --subscribe
|
||||
```
|
||||
|
||||
Now, we can have Alice begin discovering peers who have offers advertised.
|
||||
```bash
|
||||
./swapcli discover --provides XMR --search-time 3
|
||||
# [[/ip4/127.0.0.1/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv]]
|
||||
```
|
||||
|
||||
Query the returned peer as to how much XMR they can provide and their preferred exchange rate (replace `"--multiaddr"` field with one of the addresses returned in the above step):
|
||||
```bash
|
||||
./swapcli query --multiaddr /ip4/192.168.0.101/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv
|
||||
# Offer ID=cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 Provides=XMR MinimumAmount=0.1 MaximumAmount=1 ExchangeRate=0.05
|
||||
```
|
||||
|
||||
Now, we can tell Alice to initiate the protocol w/ the peer (Bob), the offer (copy the Offer id from above), and a desired amount to swap:
|
||||
```bash
|
||||
./swapcli take --multiaddr /ip4/192.168.0.101/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05
|
||||
# Initiated swap with ID=0
|
||||
```
|
||||
|
||||
Alternatively, you can take the offer via websockets and get notified when the swap status updates:
|
||||
```bash
|
||||
./swapcli take --multiaddr /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7 --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05 --subscribe --daemon-addr=ws://localhost:8081
|
||||
```
|
||||
|
||||
If all goes well, you should see Alice and Bob successfully exchange messages and execute the swap protocol. The result is that Alice now owns the private key to a Monero account (and is the only owner of that key) and Bob has the ETH transferred to him. On Alice's side, a Monero wallet will be generated in the `--wallet-dir` provided in the `monero-wallet-rpc` step for Alice.
|
||||
|
||||
To query the information for an ongoing swap, you can run:
|
||||
```bash
|
||||
./swapcli get-ongoing-swap
|
||||
```
|
||||
|
||||
To query information for a past swap using its ID, you can run:
|
||||
```bash
|
||||
./swapcli get-past-swap --id <id>
|
||||
```
|
||||
66
docs/recovery.md
Normal file
66
docs/recovery.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# Recovery
|
||||
|
||||
In the case that the swap process crashes in the middle of the swap while funds are still locked, you can use the built-in recovery module to recover your funds manually.
|
||||
|
||||
## Building
|
||||
|
||||
To build the `swaprecover` binary, follow the instructions in [here](./build.md) but run `make build-all` instead of `make build`.
|
||||
|
||||
## Locating recovery file
|
||||
|
||||
Depending on whether you were on `dev`, `stagenet`, or `mainnet`, there will be a directory in your home directory `.atomicswap` that contains a directory of the network you were on.
|
||||
|
||||
Enter that directory and you should see a file named `info-<date-and-time>.txt`:
|
||||
|
||||
```bash
|
||||
ls ~/.atomicswap/dev/
|
||||
# info-2022-Apr-19-22:55:22.txt
|
||||
```
|
||||
|
||||
This file contains all the information you need to recover your funds.
|
||||
|
||||
## Recovering as a maker
|
||||
|
||||
If you were in the role of maker during the swap, ie. you had XMR and were swapping for ETH, the following will allow you to either recover your XMR or claim the ETH.
|
||||
|
||||
### Check if XMR account key was obtained
|
||||
|
||||
If the `SharedSwapPrivateKey` field in the info file is non-empty, you can simply claim the XMR by importing the `PrivateSpendKey`, `PrivateViewKey`, and `Address` in that file into your Monero wallet.
|
||||
|
||||
With monero-wallet-cli, you can follow the instructions [here](https://www.getmonero.org/resources/user-guides/restore_from_keys.html).
|
||||
|
||||
### Otherwise, recover from contract address and swap secret
|
||||
|
||||
Using the `PrivateSpendKey`, `ContractAddress`, and `SwapID` fields within the info file, you can recover your funds using the `swaprecover` binary.
|
||||
|
||||
For example, on the stagenet-Goerli networks:
|
||||
```bash
|
||||
./swaprecover --env stagenet --ethereum-endpoint=<your-goerli-endpoint> --ethereum-privkey=goerli.key --ethereum-chain-id=5 --contract-swap-id=<SwapID> --bob-secret=<PrivateSpendKey> --contract-addr=<ContractAddress>
|
||||
```
|
||||
|
||||
The Ethereum private key must be the same one used when you ran `swapd`.
|
||||
|
||||
The recovery program will firstly try to claim ETH from the contract if possible. If the time to claim has already passed, and/or the counterparty has refunded the ETH to themselves, the program will refund the XMR to you by creating a Monero wallet containing the funds. If the program logs indicate a refund has occurred, please check your `monero-wallet-rpc` for the wallet containing your XMR.
|
||||
|
||||
## Recovering as a taker
|
||||
|
||||
If you were in the role of taker during the swap, ie. you had ETH and were swapping for XMR, the following will allow you to either recover your ETH or claim the XMR.
|
||||
|
||||
### Check if XMR account key was obtained
|
||||
|
||||
If the `SharedSwapPrivateKey` field in the info file is non-empty, you can simply claim the XMR by importing the `PrivateSpendKey`, `PrivateViewKey`, and `Address` in that file into your Monero wallet.
|
||||
|
||||
With monero-wallet-cli, you can follow the instructions [here](https://www.getmonero.org/resources/user-guides/restore_from_keys.html).
|
||||
|
||||
### Otherwise, recover from contract address and swap secret
|
||||
|
||||
Using the `PrivateSpendKey`, `ContractAddress`, and `SwapID` fields within the info file, you can recover your funds using the `swaprecover` binary.
|
||||
|
||||
For example, on the stagenet-Goerli networks:
|
||||
```bash
|
||||
./swaprecover --env stagenet --ethereum-endpoint=<your-goerli-endpoint> --ethereum-privkey=goerli.key --ethereum-chain-id=5 --contract-swap-id=<SwapID> --alice-secret=<PrivateSpendKey> --contract-addr=<ContractAddress>
|
||||
```
|
||||
|
||||
The Ethereum private key must be the same one used when you ran `swapd`.
|
||||
|
||||
The recovery program will firstly try to claim XMR by checking if the counterparty has claimed the ETH or not. If they haven't, the program will wait until the claim period finishes before trying to refund the ETH. If the program ends up refunding the ETH to you, it will end up back in your account specified by `--ethereum-privkey`. Otherwise, if the counterparty ends up claiming the ETH, you will receive the XMR in a new wallet inside `monero-wallet-rpc`.
|
||||
186
docs/stagenet.md
Normal file
186
docs/stagenet.md
Normal file
@@ -0,0 +1,186 @@
|
||||
# Joining the Stagenet/Goerli network
|
||||
|
||||
Currently, an initial version of the swap is deployed onto the Goerli (Ethereum testnet) and Monero Stagenet networks. To join the network and try out the swap, either as a maker or a taker, please see the following.
|
||||
|
||||
> Note: a swap on stagenet currenty takes around 10-20 minutes due to block times.
|
||||
|
||||
> Note: the `swapd` process directly interacts with an unlocked Monero wallet and Ethereum private key. This is to allow for a smoother swap process that doesn't require any interaction from you once initiated. However, this effectively gives `swapd` access to all your (testnet) funds. In the future, there will be a mode that does not access your keys/wallet, but will require user interaction during a swap.
|
||||
|
||||
## Setup
|
||||
|
||||
The atomic swap daemon requires a connection to a monero-wallet-rpc process connected to a stagenet daemon, a Goerli network endpoint, and a Goerli network private key funded with some GoETH.
|
||||
|
||||
1. Install the Monero CLI if you haven't already. You can get it [here](https://www.getmonero.org/downloads/#cli):
|
||||
|
||||
For Linux 64-bit, you can do:
|
||||
```bash
|
||||
curl -L https://downloads.getmonero.org/cli/linux64 > monero.tar.bz2
|
||||
tar xjvf monero.tar.bz2
|
||||
```
|
||||
|
||||
2. Begin the stagenet daemon and wait for it to sync. This may take a day or so. Alternatively, you can use an existing stagenet endpoint if you know of one.
|
||||
```bash
|
||||
./monero-x86_64-linux-gnu-v0.17.3.2/monerod --detach --stagenet
|
||||
```
|
||||
|
||||
3. Create a wallet directory and start the monero-wallet-rpc process. The directory `node-keys` will store your monero wallet keys.
|
||||
```bash
|
||||
mkdir node-keys
|
||||
./monero-x86_64-linux-gnu-v0.17.3.2/monero-wallet-rpc --stagenet --rpc-bind-port 18083 --disable-rpc-login --wallet-dir ./node-keys &> monero-wallet-cli.log &
|
||||
```
|
||||
|
||||
4. Create a Goerli wallet. You can do this using Metamask by selecting "Goerli Test Network" from the networks, then creating a new account with "Create account". I'd recommend naming this new account something explicit like `goerli-swap-account`.
|
||||
|
||||
5. Export the private key for this account by navigating to: three dots in upper right of Metamask -> account details -> export private key. Paste this private key into a file named `goerli.key`.
|
||||
|
||||
6. Fund your Goerli account using a faucet:
|
||||
- https://goerli-faucet.pk910.de/
|
||||
- https://goerlifaucet.com/
|
||||
- https://goerli-faucet.mudit.blog/
|
||||
|
||||
If you don't have any luck with these, please message me on twitter/reddit (@elizabethereum) with your Goerli address, and I can send you some GoETH.
|
||||
|
||||
7. Obtain a Goerli JSON-RPC endpoint. You can get one from infura.io, or you can sync your own node, or ask a friend for their endpoint.
|
||||
|
||||
8. Install go 1.18 from [here](https://go.dev/doc/install).
|
||||
|
||||
For Linux 64-bit, you can do:
|
||||
```bash
|
||||
wget https://go.dev/dl/go1.18.linux-amd64.tar.gz
|
||||
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.linux-amd64.tar.gz
|
||||
echo "export PATH=$PATH:/usr/local/go/bin" >> .profile
|
||||
source .profile
|
||||
```
|
||||
|
||||
9. Clone and build the atomic-swap binaries:
|
||||
```bash
|
||||
git clone https://github.com/noot/atomic-swap.git
|
||||
cd atomic-swap
|
||||
make build
|
||||
```
|
||||
|
||||
10. Copy `goerli.key` into this directory. If you are using an Infura Goerli endpoint, copy-paste your API key into the field below following the `--ethereum-endpoint` flag. Otherwise, change `--ethereum-endpoint` to point to your endpoint. Finally, start the `swapd` atomic swap daemon process:
|
||||
```bash
|
||||
./swapd --env stagenet --ethereum-privkey=goerli.key --monero-endpoint=http://localhost:18083/json_rpc --wallet-file=stagenet-wallet --ethereum-endpoint=https://goerli.infura.io/v3/<your-api-key> --ethereum-chain-id=5 --contract-address=0xe532f0C720dCD102854281aeF1a8Be01f464C8fE --bootnodes /ip4/134.122.115.208/tcp/9900/p2p/12D3KooWDqCzbjexHEa8Rut7bzxHFpRMZyDRW1L6TGkL1KY24JH5,/ip4/143.198.123.27/tcp/9900/p2p/12D3KooWSc4yFkPWBFmPToTMbhChH3FAgGH96DNzSg5fio1pQYoN,/ip4/67.207.89.83/tcp/9900/p2p/12D3KooWLbfkLZZvvn8Lxs1KDU3u7gyvBk88ZNtJBbugytBr5RCG,/ip4/134.122.115.208/tcp/9900/p2p/12D3KooWDqCzbjexHEa8Rut7bzxHFpRMZyDRW1L6TGkL1KY24JH5,/ip4/164.92.103.160/tcp/9900/p2p/12D3KooWAZtRECEv7zN69zU1e7sPrHbMgfqFUn7QTLh1pKGiMuaM,/ip4/164.92.103.159/tcp/9900/p2p/12D3KooWSNQF1eNyapxC2zA3jJExgLX7jWhEyw8B3k7zMW5ZRvQz,/ip4/164.92.123.10/tcp/9900/p2p/12D3KooWG8z9fXVTB72XL8hQbahpfEjutREL9vbBQ4FzqtDKzTBu,/ip4/161.35.110.210/tcp/9900/p2p/12D3KooWS8iKxqsGTiL3Yc1VaAfg99U5km1AE7bWYQiuavXj3Yz6,/ip4/206.189.47.220/tcp/9900/p2p/12D3KooWGVzz2d2LSceVFFdqTYqmQXTqc5eWziw7PLRahCWGJhKB --rpc-port=5001
|
||||
```
|
||||
|
||||
> Note: please also see the [RPC documentation](./rpc.md) for complete documentation on available RPC calls and their parameters.
|
||||
|
||||
## Taker
|
||||
|
||||
As a taker, you can use either the UI or `swapcli` to discover and take offers.
|
||||
|
||||
### UI
|
||||
|
||||
1. From the `atomic-swap` directory, build and start the UI. Note: you need to have node.js installed.
|
||||
```bash
|
||||
cd ui/
|
||||
yarn install
|
||||
yarn build
|
||||
yarn start
|
||||
```
|
||||
|
||||
2. Navigate to http://localhost:8080 to see the UI running. It will automatically connect to your `swapd` process and try to find offers. You can also refresh the offers by clicking `refresh`.
|
||||
|
||||

|
||||
|
||||
3. When you find an offer you'd like to take, press the `take` button to input the amount of ETH you'd like to provide. Then, confirm the offer. If all goes well, you should see the swap complete in the logs of `swapd`.
|
||||
|
||||

|
||||

|
||||
|
||||
### CLI
|
||||
|
||||
1. Search for existing XMR offers using `swapcli`:
|
||||
```bash
|
||||
./swapcli discover --provides XMR --search-time 3 --daemon-addr=http://localhost:5005
|
||||
# [[/ip4/127.0.0.1/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv]]
|
||||
```
|
||||
|
||||
2. Query a returned peer as to how much XMR they can provide and their preferred exchange rate (replace `"--multiaddr"` field with one of the addresses returned in the above step):
|
||||
```bash
|
||||
./swapcli query --multiaddr /ip4/192.168.0.101/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv
|
||||
# Offer ID=cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 Provides=XMR MinimumAmount=0.1 MaximumAmount=1 ExchangeRate=0.05
|
||||
```
|
||||
|
||||
> Note: the exchange rate is the ratio of XMR:ETH price. So for example, a ratio of 0.05 would mean 20 XMR to 1 ETH. Since we're on testnet, it's not critical what you set it to.
|
||||
|
||||
3. a. Then, finding an offer you like, take the offer by copying the peer's multiaddress and offer ID into the command below. As well, specify how much GoETH you would like to provide, taking into account the offer's exchange rate and min/max XMR amounts.
|
||||
```bash
|
||||
./swapcli take --multiaddr /ip4/192.168.0.101/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05
|
||||
# Initiated swap with ID=0
|
||||
```
|
||||
|
||||
3. b. Alternatively, you can take the offer via websockets and get notified when the swap status updates:
|
||||
```bash
|
||||
./swapcli take --multiaddr /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7 --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05 --subscribe --daemon-addr=ws://localhost:8081
|
||||
```
|
||||
|
||||
If all goes well, you should see the node execute the swap protocol. If the swap ends successfully, a Monero wallet will be generated in the `--wallet-dir` provided in the `monero-wallet-rpc` step (so `./node-keys`) named `swap-deposit-wallet`. This wallet will contained the received XMR.
|
||||
|
||||
> Note: optionally, you can add the `--transfer-back` flag when starting `swapd` to automatically transfer received XMR back into your original wallet, if you have one opened on the endpoint when starting `swapd`.
|
||||
|
||||
## Maker
|
||||
|
||||
1. Create a stagenet wallet:
|
||||
```bash
|
||||
curl http://localhost:18083/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"create_wallet","params":{"filename":"stagenet-wallet","password":"","language":"English"}}' -H 'Content-Type: application/json'
|
||||
```
|
||||
|
||||
2. Find your stagenet address:
|
||||
```bash
|
||||
curl http://localhost:18083/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"get_accounts","params":{}}' -H 'Content-Type: application/json'
|
||||
```
|
||||
|
||||
3. Fund this address with some stagenet XMR. You can try the faucets here:
|
||||
- https://stagenet-faucet.xmr-tw.org/
|
||||
- https://community.rino.io/faucet/stagenet/
|
||||
|
||||
If you don't have any luck with these, please message me on twitter/reddit (@elizabethereum) with your stagenet address, and I can send you some stagenet XMR.
|
||||
|
||||
4. a. Make an offer with `swapcli`:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.5 --daemon-addr http://localhost:5005
|
||||
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
|
||||
```
|
||||
|
||||
4. b. Alternatively, make an offer and subscribe to updates on it with `swapcli`:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.5 --daemon-addr ws://localhost:6005 --subscribe
|
||||
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
|
||||
```
|
||||
|
||||
> Note: the exchange rate is the ratio of XMR:ETH price. So for example, a ratio of 0.05 would mean 20 XMR to 1 ETH. Since we're on testnet, it's not critical what you set it to.
|
||||
|
||||
When a peer takes your offer, you will see logs in `swapd` notifying you that a swap has been initiated. If all goes well, you should receive the GoETH in the Goerli account created earlier.
|
||||
|
||||
> Note: if you exit the `swapd` process, your offers are currently not saved, so when you restart you will not have any offers.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Ideally, the exit case of the swap should be `Success`. If this is not the case, it will either be one of `Refunded` or `Aborted`.
|
||||
- `Refunded` means that the swap refunded after your funds were already locked. In this case, you would lose transaction fees.
|
||||
- `Aborted` means that the swap exited before any funds were locked, so nothing was lost except time.
|
||||
|
||||
Neither of these should happen, so if they happen, it indicates an issue either on your side or the remote peer's side.
|
||||
|
||||
A few common errors are:
|
||||
- `Failed to get height`: double check that your `monerod --stagenet` process is running.
|
||||
- `unlocked balance is less than maximum offer amount`: you will see this if you're a maker and try to make an offer but don't have enough balance. Either get more stagenet XMR or wait for your balance to unlock.
|
||||
- `already have ongoing swap`: either you or the remote peer already have a swap happening, so you need to wait for it to finish before starting another swap. Currently, `swapd` only supports one swap at a time, but support for concurrent swaps is planned.
|
||||
|
||||
## Trying the swap on a different network
|
||||
|
||||
You can also try the swap on another Ethereum or EVM-compatible testnet. However, you'll need to run your own maker nodes.
|
||||
|
||||
To connect to a different Ethereum network, follow [Setup](#setup) steps 4-7 but with your desired network. Then, start `swapd` with your specified private key file, endpoint, and chain ID. Common chain IDs can be found [here](https://besu.hyperledger.org/en/stable/Concepts/NetworkID-And-ChainID/).
|
||||
|
||||
> Note: this command will deploy a new instance of `Swap.sol` to the network, as it has not been deployed onto any other networks currently. If you want to use an already-deployed swap contract, remove the `--deploy` flag and pass in the address using `--contract-addr=<addr>`. You need to have funds in your account to deploy the contract.
|
||||
|
||||
```bash
|
||||
./swapd --env stagenet --ethereum-privkey=<network>.key --monero-endpoint=http://localhost:18083/json_rpc --wallet-file=stagenet-wallet --ethereum-endpoint=https://<network>.infura.io/v3/<your-api-key> --ethereum-chain-id=<network-chain-id> --deploy
|
||||
```
|
||||
|
||||
## Bug reports
|
||||
|
||||
If you find any bugs or unexpected swap occurrences, please [open an issue](https://github.com/noot/atomic-swap/issues/new) on the repo, detailing exact steps you took to setup `swapd` and what caused the bug to occur. Your OS and environment would be helpful as well. Any bug reports or general improvement suggestions are much appreciated.
|
||||
@@ -26,7 +26,7 @@ func WriteContractAddressToFile(infofile, addr string) error {
|
||||
|
||||
contents.ContractAddress = addr
|
||||
|
||||
bz, err := json.Marshal(contents)
|
||||
bz, err := json.MarshalIndent(contents, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func WriteSwapIDToFile(infofile string, id uint64) error {
|
||||
|
||||
contents.SwapID = id
|
||||
|
||||
bz, err := json.Marshal(contents)
|
||||
bz, err := json.MarshalIndent(contents, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func WriteKeysToFile(infofile string, keys *mcrypto.PrivateKeyPair, env common.E
|
||||
|
||||
contents.PrivateKeyInfo = keys.Info(env)
|
||||
|
||||
bz, err := json.Marshal(contents)
|
||||
bz, err := json.MarshalIndent(contents, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func WriteSharedSwapKeyPairToFile(infofile string, keys *mcrypto.PrivateKeyPair,
|
||||
|
||||
contents.SharedSwapPrivateKey = keys.Info(env)
|
||||
|
||||
bz, err := json.Marshal(contents)
|
||||
bz, err := json.MarshalIndent(contents, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,26 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "building swapd..."
|
||||
cd cmd/daemon
|
||||
if ! go build -o swapd ; then
|
||||
exit 1
|
||||
fi
|
||||
mv swapd ../..
|
||||
echo "done building swapd."
|
||||
|
||||
echo "building swapcli..."
|
||||
cd ../client
|
||||
if ! go build -o swapcli ; then
|
||||
exit 1
|
||||
fi
|
||||
mv swapcli ../..
|
||||
echo "done building swapcli."
|
||||
|
||||
if [[ -z "${ALL}" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "build swaprecover..."
|
||||
cd ../recover
|
||||
if ! go build -o swaprecover ; then
|
||||
exit 1
|
||||
fi
|
||||
mv swaprecover ../..
|
||||
echo "done building swaprecover."
|
||||
|
||||
echo "building swaptester..."
|
||||
cd ../tester
|
||||
if ! go build -o swaptester ; then
|
||||
exit 1
|
||||
fi
|
||||
mv swaptester ../..
|
||||
cd ../..
|
||||
cd ../..
|
||||
echo "done building swaptester."
|
||||
|
||||
Reference in New Issue
Block a user