Atomic Swaps with Litecoin (Faucet and Initial Market)

by BlakeKeiller, Monday, December 07, 2020, 15:30 (363 days ago) @ BlakeKeiller

There are new commands allowing nodes to coordinate atomic swaps exchanging Proofgold bars for litecoins at specified price. Proofgold generally has the disclaimer of "use at your own risk", but this should be emphasized with this new feature. Under normal operation of the network, there should not be a risk of losing funds, but I cannot guarantee normal operation of the network. If your node dies for 48 blocks (about two days), funds can be lost. And, of course, if there are bugs in the code, funds could be lost in other unforeseen ways.

Due to the experimental nature, I would recommend that people only use this (for now) with relatively low values. To be specific, I will not use this with values over 1 litecoin or 1000 bars, and recommend others have these limits (or stricter).

Atomic swaps should help newcomers obtain a relatively small amount of Proofgold bars for experimentation. Atomic swaps can also be the seed for an initial market.

By default client nodes will not engage in swapping (or notice that others are swapping). To enable swapping, put

swapping=1

in proofgold.conf or start proofgold with the -swapping command line option.

The proofgold.conf also needs to have at least one bech32 litecoin address marked as a trade address, like this:

ltctradeaddress=ltc1...

The trade addresses should be different from other ltcaddress addresses in the proofgold.conf file. (Those others are used to create burn transactions for staking).

Here are the most important new commands for atomic swaps and how to use them.

Suppose Alice has 0.0015 litecoin (LTC) and wishes to buy 100 bars (PFG) at a price of 0.000015 LTC:PFG (about 1 eurocent per PFG bar at current prices). She can use the createswapbuyoffer command like this:

createswapbuyoffer <address> 0.000015 100 0.0015

The address should be one Alice has in her wallet. The command newaddress can give her a new address if she needs one.

When Alice does this, assuming an ltctradeaddress has enough litecoins, a litecoin transaction will be sent to herself. The first output of the transaction is an OP_RETURN giving the relevant buy offer information. The second output is the 0.0015 litecoins to be spent for the bars. (An optional third output will be change.)

This buy offer will be visible to all other nodes with swapping enabled. All current buy offers can be listed with the "buyoffers" command.

Alice can cancel the buy offer by spending the first txout of the litecoin transaction back to herself. The command "cancelswapbuyoffers <ltctxid>" can do this for her.

Buy offers like the one above are public. Sell offers are private and are only known to the local node.

If Bob is willing to sell between 100 and 300 Proofgold at a price of at least 0.00001 LTC:PFG, he can issue the following command:

createswapselloffer 0.00001 100 300

If Alice and Bob have both done this, then Bob's node will recognize that there is a match. Without going into full technicalities (explanation available upon request), Bob's node will create an unsigned litecoin transaction that could send Alice's 0.0015 ltc to his address. He then creates a smart contract that will allow Alice to spend from the contract if the unsigned litecoin transaction is signed, published and has 3 confirmations. Bob can spend from the smart contract after 48 blocks (two days) in case Alice does not accept the match offer. Bob's node then sends 100 bars to the smart contract with a Proofgold transaction of a special form. When Alice sees this Proofgold transaction (and it has 3 confirmations), her node can sign the litecoin transaction and publish it. After it has 3 confirmations, Alice can spend the 100 bars at the smart contract to an address she controls. She must do this before the smart contract is 48 blocks old, or Bob can retake the bars.

Assuming Alice;s node accepts the match offer, signs and publishes the litecoin tx and then collects from the smart contract, she will have 100 PFG bars (minus transaction fees, so really ~99.999) and Bob will have 0.0015 litecoins (minus transaction fees, so really ~0.00149).

On average a successful exchange like this should take 3 to 4 hours after there is a match.

Bob can cancel all his current sell offers with the command "cancelswapselloffers." Bob can see his current (local) sell offers with the command "selloffers".

In case an atomic swap does not seem to have worked, check the debug.log file (in .proofgold) for information about what may have gone wrong.

Again, this feature is "USE AT YOUR OWN RISK" and I highly suggest not placing buy or sell offers of high value.


Complete thread:

 RSS Feed of thread

powered by my little forum