Version: 0.1.3
This protocol supports atomic cross-chain trades between the native tokens of Stellar and Ethereum.
It is based on the TierNolan protocol but instead of using Bitcoin Script it uses Stellar hash(x) signers and time bounded transactions and for Ethereum a Solidity hashed timelock smart contract.
Two scenarios are described below:
- Scenario 1 is initiated from Stellar.
- Scenario 2 is initiated from Ethereum.
- all hashes are SHA-2 SHA-256 hashes
- Ethereum HashedTimelock refers to this Ethereum smart contract
- 'Preimage' and 'x' are used interchangeably to refer to the generated secret preimage, the hash of which is used in the hashlocks
- 'HTLC' refers to Hashed Timelock Contracts
- Alice is selling XLM to Bob
- Bob is selling ETH to Alice
- Alice initiates the setup process creating the secret preimage x
- Alice creates a holding account on Stellar to hold the XLM
- Bob creates a new HTLC on the Ethereum HTLC contract to hold the ETH
- Alice claims ETH revealing x to the HTLC contract on Ethereum
- Bob takes the revealed x and claims XLM from the Stellar holding account
-
Agreement
- Agree to terms over some channel (telegram, phone call, whatever ..) and define the amounts to trade
- Exchange Stellar and Ethereum public addresses. Each trader must have 1 account on each network
- Define trade details in a trade.json file that conforms to the JSON schema
-
Setup
- Alice generates a secret preimage x
- [Stellar] Alice generates a new address for the holding account
- [Stellar] Alice creates holding account submitting this transaction:
source: Alice sequence: Alice current sequence operations: - type: createAccount destination: holdingAccount # address created in 2.2 above balance: 4 * base_reserve # 4 = 2 + signer hashx + signer bob - type: setOptions source: holdingAccount signer: - ed25519PublicKey: Bob - weight: 1 - type: setOptions source: holdingAccount masterWeight: 0 lowThreshold: 2 medThreshold: 2 highThreshold: 2 signer: - sha256Hash: hash(x) - weight: 1 sign: Alice sign: holdingAccount
- [Stellar] Bob creates a refund tx envelope and signs and sends it to Alice:
source: holdingAccount sequence: holdingAccount current sequence timebounds: - minTime: now + N minutes - maxTime: 0 operations: - type: accountMerge destination: Alice sign: Bob
- [Stellar] Alice submits Tx moving agreed XLM into the holding account:
source: Alice sequence: Alice current sequence operations: - type: payment destination: holdingAccount asset: XLM amount: agreed amount sign: Alice
- [Ethereum] Bob calls newContract() on the HashedTimelock. This creates a new 32 byte HTLC id. Alice can scan the blockchain to retrieve this.
newContract: - _receiver: Alice's address (Ethereum) _hashlock: hash(x) _timelock: now + N / 2 minutes # N from step 2.4 above options: - from: Bob - value: agreed amount
-
Trade
-
[Ethereum] Alice claims ETH - calls withdraw() on the contract revealing x:
withdraw: - _contractId: <HTLC id> _preimage: x
-
[Stellar] Bob claims XLM - now knows x and submits a transaction to Stellar to get funds:
source: holdingAccount sequence: holdingAccount current sequence operations: - type: accountMerge destination: Bob sign: Bob signHashX: x
-
NOTES:
- If nothing happens after 2.5 Alice can get a refund after N minutes time has passed by adding a signature x to the transaction Bob gave here in 2.4.
- If nothing happens after 2.6 Bob can get a refund after N / 2 minutes time has passed by calling refund() on the Ethereum smart contract.
- Alice is selling XLM to Bob
- Bob is selling ETH to Alice
- Bob initiates the setup process creating the secret preimage x
- Bob creates a new HTLC on the Ethereum HTLC contract to hold the ETH
- Alice creates a holding account on Stellar to hold the XLM
- Bob claims XLM in the holding account revealing x on Stellar
- Alice takes the revealed x and claims ETH from the HTLC on Ethereum
- Agreement
- same as in S1 1
- Setup
- Bob generates secret x
- [Ethereum] Bob creates new HTLC on Ethereum getting a contract id:
- same as 2.6 in S1 expect:
- timelock is N minutes
- it's Bob who knows x
- [Stellar] Alice sets up Stellar holding account:
- same as in 2.2 and 2.3 in S1 except that signers are Bob and Alice (instead Bob and hash(x))
- [Stellar] Bob creates and signs a refund tx envelope for Alice:
- same as in 2.4 in S1 except timelock is N / 2 minutes
- [Stellar] Alice submits a transaction moving agreed XLM into the holding account:
- same as in 2.5 in S1
- Exchange
- [Stellar] Bob claims XLM revealing x:
source: holdingAccount sequence: holdingAccount sequence operations: - type: accountMerge destination: Bob sign: Bob signHashX: x
- [Ethereum] Alice claims ETH - calls withdraw() (uses x from the last step)
withdraw: - _contractId: <HTLC id> _preimage: x
NOTES:
- If nothing happens after S2 2.2 Bob can get a refund after timelock time has passed by calling refund() on the Ethereum smart contract.
- If nothing happens after S2 2.5 Alice can get a refund after the timelock expires by signing the transaction Bob gave her in S2 2.4.