-
Notifications
You must be signed in to change notification settings - Fork 122
ICX Atomic Swap
U-Zyn Chua edited this page Aug 18, 2021
·
1 revision
For Tech Talk on 2021-08-12
- Maker: make order
- Taker: make offer
- Maker: accept offer, generates seed (password) and sends to HTLC
- Taker: sends to HTLC with the same hash
- Maker: claims, reveals seed
- Taker: claims with the revealed seed
- Taker
- 0.3% of the BTC transaction amount
- 0.003 * BTC * DFI/BTC (rate on DEX)
- Maker
- If it's a parity trade (1 BTC for 1 dBTC), receives 75% of taker fee (DFI)
- Else, receives 25% of taker fee (DFI)
- Remaining taker fee is burned (25% or 75%)
- Fee needs to be paid in token,
We are running a parity maker bot.
https://github.com/DeFiCh/icx-makerbot
Parity maker bot address: 8cDSPjDe7HqvzmSL33xCrcrvBbUcmkTSpg
-
Get DFI address and Bitcoin pubkey
- HTLC (BIP 199) uses pubkey, not address:
defi-cli spv_getaddresspubkey BTC_ADDRESS
- DFI address
- from UI
- HTLC (BIP 199) uses pubkey, not address:
-
icx_listorders
-
type
-
INTERNAL
: Maker is going OUT of DeFiChain (Maker has dBTC) -
EXTERNAL
: Maker is going INTO of DeFiChain (Maker has BTC)
-
- Take note of
orderPrice
-
Reference: https://github.com/DeFiCh/app/discussions/996
Taker has BTC
-
Make offer
- Pick an
INTERNAL
one. Take node ofownerAddress
. -
orderTx
: fromicx_listorders
amount
-
ownerAddress
: for DFI and dBTC (receive and refund) -
receivePubkey
: for BTC -
expiry
: number of DeFiChain blocks icx_makeoffer '{"orderTx":"670f177dd1e1ca81412790688197b529863fd0ee148f05911e9661228593f7d7","amount":0.00102,"ownerAddress":"dSdXC5bEXxLbeoLCHUgh6jVQiLbgp83Aiq","receivePubkey":"0332a00d8328b2bcec0d73f75900498a4b24c4c11aaa8c88a5534f4781bfcf39a1","expiry":240}'
- Pick an
-
Check for status
- Check if the maker has locked up the BTC at an HTLC
icx_listhtlcs '{"offerTx":"f07275d4bf45191b035e5d7bb61cbead451ad37fa53471791cae438e76ac1221"}'
- Or
icx_listhtlcs '{"offerTx":"f07275d4bf45191b035e5d7bb61cbead451ad37fa53471791cae438e76ac1221", "closed":true}'
- Ensure that the response is correct
-
Lock in BTC to SPV
spc_createhtlc
-
timeout
in Bitcoin should be spv_createhtlc 03923fb45dab6b1c2aa87d59341337016d4e37c025b22ff6f78061d18c568b78d5 022432051c0559558807977ae4fce2617383b23e08c3990ac9d36cbe67c8e6d4a1 9 9a77b7e5db814ae87d050efd00a313e41a2270d381a10ed59111305dbae03613
-
Fund HTLC
spv_sendtoaddress
spv_sendtoaddress 3HLRXfaZQSMSQ8B61bTgJq9iYrUJqcsSYR 0.00012
-
Inform DeFiChain of HTLC
- icx_submitexthtlc '{"offerTx":"5906ea3e568d375bc8f9f66edab804b030dd77498d268953c375b86ea63ec2e2","hash":"9a77b7e5db814ae87d050efd00a313e41a2270d381a10ed59111305dbae03613","amount":"0.00012","htlcScriptAddress":"3HLRXfaZQSMSQ8B61bTgJq9iYrUJqcsSYR","ownerPubkey":"022432051c0559558807977ae4fce2617383b23e08c3990ac9d36cbe67c8e6d4a1","timeout":9}'
-
Check for fund claim
spv_gethtlcseed "3HLRXfaZQSMSQ8B61bTgJq9iYrUJqcsSYR"
-
Claim dBTC
- offerTx, seed
icx_claimdfchtlc '{"dfchtlcTx":"2afa1a7c935548ffd6be9d550bb9c7f59da31b9a461bd6c3ad8ee11a50f8ac41","seed":"26f5d9f68086e0bb3458d6f102a6b3bb66a1f70a4a439a3276362017bc1d5540"}'
Reference: https://github.com/DeFiCh/app/discussions/998
Taker has dBTC
-
Make offer
- Pick an
EXTERNAL
one. Take node ofownerAddress
. -
orderTx
: fromicx_listorders
amount
-
ownerAddress
: for DFI and dBTC (receive and refund) -
receivePubkey
: for BTC -
expiry
: number of DeFiChain blocks icx_makeoffer '{"orderTx":"670f177dd1e1ca81412790688197b529863fd0ee148f05911e9661228593f7d7","amount":0.00102,"ownerAddress":"dSdXC5bEXxLbeoLCHUgh6jVQiLbgp83Aiq","receivePubkey":"0332a00d8328b2bcec0d73f75900498a4b24c4c11aaa8c88a5534f4781bfcf39a1","expiry":240}'
- Pick an
-
Check for status
- Check if the maker has locked up the BTC at an HTLC
icx_listhtlcs '{"offerTx":"f07275d4bf45191b035e5d7bb61cbead451ad37fa53471791cae438e76ac1221"}'
- Or
icx_listhtlcs '{"offerTx":"f07275d4bf45191b035e5d7bb61cbead451ad37fa53471791cae438e76ac1221", "closed":true}'
- Ensure that the response is correct, esp. that token is locked up.
-
Create BTC HTLC to check for funding
spc_createhtlc
-
timeout
in Bitcoin should be spv_createhtlc 03923fb45dab6b1c2aa87d59341337016d4e37c025b22ff6f78061d18c568b78d5 022432051c0559558807977ae4fce2617383b23e08c3990ac9d36cbe67c8e6d4a1 9 9a77b7e5db814ae87d050efd00a313e41a2270d381a10ed59111305dbae03613
-
Check that SPV is funded correctly
spv_listreceivedbyaddress 1 htlcAddress
-
Lock in DST via
icx_submitdfchtlc
defi-cli icx_submitdfchtlc '{"offerTx":"95873cdf935157b9c0395d307c9b40a9bab30a3057a548b3df2678373479437a","amount":0.0001,"hash":"ded4a16fde0a2dbab8db98c55d29733f40506068aaad84387a201ce53657465d"}'
-
Check for DST claim by Maker
- This would reveal seed (password)
- `defi-cli icx_listhtlcs '{"offerTx":"95873cdf935157b9c0395d307c9b40a9bab30a3057a548b3df2678373479437a"}'
-
Claim BTC
- offerTx, seed
spv_claimhtlc SCRIPT_ADDRESS TAKER_SPV_ADDRESS SEED
- Refund is automatically carried out for DST side when offer or HTLC expires
- For BTC side, claim is needed, use
spv_refundhtlc
- Make order:
icx_createorder
- Wait for offer:
icx_listorders
- When there's offer, accept the offer. Maker can accept less offer.
- Maker generates the seed & hash
- Submit hash to HTLC