Вопрос, кому будет принадлежать данная разработка пройдя конкурс? По сути это обменник с комиссией, но все исходники идут на гитхаб и будут принадлежать всем. Все желающие будут поднимать обменники, любой кто поднимет такой обменник, сможет обмануть пользователей. Какая защита должна быть от владельца обменника, учитывая, что он полностью контролирует перевод? По идее СК дол жен быть настроен так, чтобы владелец обменника не имел возможности повлиять на сделку.
unfortunately I had not seen this proposal before approval to show my disagreement.
some points:
- atomic swaps is an exchange business model like other centralized or decentralized exchanges, so if Free TON community invest in writing the code then the Free TON community should follow to implement and marketing it !!! (it is not the community job)
if other third party company want to do marketing and implement the written code so that company also should pay the costs not the Free TON !!! - Free TON Community just should create different SDKs and libraries as facilitators, so other exchanges (any type of exchange) can easily adapt their systems with the Free TON blockchain .
- atomic swap model is some how a failed model. so called successful atomic swaps(for example Changelly) never became a real atomic swap exchanges (the reason is low liquidity) and finally became just an intermediary between centralized exchanges and the trader.
so finally:
1. if the Free TON community don’t want to implement it why we should have this contest?
2. isn’t it better to have this approach in the Free TON community facilitating for other devs to adapt TON in their systems instead of creating systems
Здесь суть задания как раз создать такие контракты, которые бы не позволяли владельцу обменника влиять на процесс совершения сделки, чтобы не возникало кастоди и не нарушалась приватность участников сделки. Но, поскольку он обеспечивает фронт и поддержку, он должен иметь возможность задать комиссию от сделки, которая автоматически будет уходить на его адрес по её завершении.
Исходники должны быть выложены в Open Source с открытой лицензией, т.е. стать общественным достоянием - это позволит любому желающему провести аудит их безопасности и улучшать их.
Что касается второй части, то тут скорее вопрос - как убедиться, что владелец обменника использует именно те исходники, которые провалидированы сообществом. Этот вопрос выходит за рамки данного конкурса, но мы можем вынести его в отдельное обсуждение.
Hello @nAMI, thanks for your opinion.
It is very good that you have addressed these points.
Let me try to oppose them.
On the goal of the contest
Ultimate goals of all FreeTON contests are decentralization, market penetration, and token distribution in the as short term as possible. However, we should not forget that FreeTON doesn’t exist in a vacuum and first needs to plug into the existing market architecture to succeed.
Creating technology that will help existing businesses (exchanges, wallets, OTC desks, and so on) to start accepting and exchanging crystals against popular coins and tokens will foster the liquidity flow and speed up FreeTON acceptance by people outside the FreeTON community.
On the reward
You stress that FreeTON pays contest winners for something, which is not true. The winners are rewarded for their impact on reaching FreeTON’s goals.
We are a decentralized organization that asks the community to help in the popularization of its values and benefits in exchange for some virtual assets, and not an institution running a tender and paying to the contractor.
On the tools created by the community
Free TON Community just should create different SDKs and libraries as facilitators
I disagree with such narrow positioning as it completely devalues the efforts of blockchain developers who invest their time in learning FreeTON smart contracts both in Fift and Solidity. Contests like this tease their professionalism and help them grow, at the same time creating a ground for discussion and rapid creation of industry standards.
Atomic Swaps is a challenging task that may be used as a basis for future technologies and growing popularity of FreeTON.
On failed model
atomic swap model is some how a failed model
This is a very strong argument, please ground it with facts.
The world of DeFi and DeX is booming, and atomic swaps and uniswaps are one of the core technologies. FreeTON IMHO is an ideal blockchain for DeFi projects, and having the solutions that are elaborated and validated by the community will help FreeTON to become very competitive.
On a community will
the Free TON community don’t want to implement it
I have published the contest proposal more than week and a half ago and invited the community to object. Vice a versa, I see really strong support from other members and their readiness to even participate in this contest.
The only fair criticism I have seen so far is the one from @Mitja who accented that it was worth to first have a design contest for this task. However, there are so many good examples from Ethereum and Bitcoin that we agreed to provide them here as a benchmark.
Кстати, @Mitja можешь выложить сюда референсные ссылки на реализацию, про которые ты говорил на звонке?
@cryonyx thanks a lot for your response (you easily could ignore my comment because any way the jurors have approved this contest and I am respectful also about their decision)
1.
about the failure of atomic swaps (because of liquidity problem):
1.1. I refer you to this article of Vitalik. he mentioned:
The main challenge that I see with the MKR market, etherdelta and other markets right now is the high spreads, often 10% or even higher.
he don’t use the word atomic swap but atomic swaps also include so later Vitalik wrote a new article to introduce what called x*y=k market makers that later inspired by Hayden Adams to create uniswap.org (we don’t have uniswaps it is just one exchange with x*y=k market maker idea)
1.2. this article explain that other alleged atomic swaps like Changelly and Shape Shift are not actually atomic swaps so the author called them instant exchanges. but the author don’t know that they wanted to be real atomic swaps and lack of liquidity forced them to became intermediaries between central exchanges and the customers. it is the reason that founders of Changelly had created a wallet an named it Atomic Wallet it wanted to be a real atomic exchange. I wish Konstantin Gladych again join to Free TON also as he was part of TON community in the past.
2.
no stress. i even think we should even reward to the proposal writers as well as contestants between 0-100k TON based on judge valuation their proposal (as I had explained in my proposal for idea management system contest at the end of page 5).
3.
you have answered @Aleksandr that have asked some how my first question
and you think that it is possible to fully implement an atomic swap on the blockchain as a smart contract with no dependancy to outer systems.
something by using a tool like SPV Verification that @Mitja mentioned. it is OK and so good so I think the contest should was a contest to create a tool like SPV Verification tool.
thanks @Mitja for sharing this link i really don’t know if their SPV tool work with no fault or not (even the possibility needs to be checked)
when I talk about different SDK and libraries the SPV Verification tool can be a good example it will facilitate any on chain exchange (atomic swap , uniswap or others) to work with the TON blockchain.
anyway thanks you and mitja for the contribution. I am learning also.
Colleagues, what is the reason to combine all this into one competition? These are large tasks, and the implementation of each of them requires a lot of resources. At the same time, these tasks do not depend on each other, they can simply be divided into different contests.
I have been writing a smart contract for trustless exchanging TON Crystal for Bitcoin using SPV for some time (very short announce). I started in early August. The implementation is still not ready, but at this point in time it took more than a month.
And of course I want to take part in this contest. But the conditions are such that you simply cut off the participant, requiring 3 unrelated exchangers to be implemented in 3 weeks. This can only be done by a large team or if you prepare for the contest in advance.
I propose changing the terms of participation in the contest so that you can provide separate implementations of BTC and ETH and even separate native ETH and ERC20. Or even better, launch separate contests for different blockchains. Otherwise it’s just too hard.
What is the point of a contest that only the organizers take part in?
I agree with you. The task is big and you need more time or more experts. The competition is organized for its creators. In the next topic, I raised this issue. To which I was told that any member of the community can create contests according to their skills, in addition, it is difficult to find specialists for such a task. I would also take part, but physically I will not have time, as I am engaged in another contest.
@creator, @Dekan I’m personally on your side and did what I could. However, the governance strongly objected to extend the deadline…
This is what the decentralization is
But still, I invite you to participate in the discussion and development of other DeFi elements and also participate in the Jury contest. We need such passionate members as you.
Atomic Swaps on Free TON [31 August 2020 - 20 September 2020] SUBMISSION
Our team is pleased to present you a fully decentralized infrastructure for two-way exchange between the following blockchains / tokens:
- Free TON <-> Ethereum
- Free TON <-> ERC20 Token (currently USDT supported)
- Free TON <-> Bitcoin in progress…
The exchange is based on HTLC Smart Contracts on each blockchain. This type of contracts allows exchanges between blockchains with guaranteed atomicity - that is, the exchange will either take place, or you will receive your funds back.
At the moment, HTLC smart contracts have been implemented for the following blockchains:
- Free TON smart contract (Solidity, https://github.com/ton-swaps/tonswapsmc)
- Ethereum smart contract for the exchange of ETH (Solidity, https://github.com/ton-swaps/ethswap)
- Ethereum smart contract for the exchange of ERC20 tokens (Solidity, https://github.com/ton-swaps/ethswap)
- Bitcoin Script for Hashlock & Timelock (built into js library)
Distributed backend
To place / search for orders, as well as synchronize the exchange between participants, an order book based on a smart contract in the TON network is used. It allows you to place orders for both buy and sell tokens with an indication of the volume range, exchange rate and maximum time for blocking funds.
Work with a smart contract is carried out by depositing TON CRYSTALS to the account of the order book contract, after which the funds are blocked for the duration of the exchange. This makes it possible to guarantee the receipt of funds by the buyer, and prevents the placement of a large number of fake orders.
No deposit is required to purchase TON CRYSTALS, however, a small amount of TON CRYSTALS is required to pay for transactions in the order book.
Unlocked funds can be withdrawn at any time without commission.
Since there is no intermediary when exchanging through the Free TON smart contract, you do not need to pay commissions for the exchange, only commissions for the transactions themselves. When you make a deposit, the amount required to cover the storage fees of the smart contract data is debited from you (after the automatic calculation of the storage cost function is implemented, this amount will not exceed 0.001 TON CRYSTAL).
User support can be provided on a paid basis as an additional service (which is often found in the open source world).
Frontend
A javascript library is implemented to interact with smart contracts in all supported blockchains.
Git repository link: https://github.com/ton-swaps/tonswaplib
To demonstrate the possibility of exchange and debugging of the solution, a JavaScript application for browsers was developed. It allows you to make a deposit / withdrawal of funds, place and confirm orders, and exchange or refund funds in a fully automatic mode.
Git repository link: https://github.com/ton-swaps/tonswapapp
Live demo: https://ton-swaps.github.io
Demonstration
Free TON Atomic Swaps (USDT - TON CRYSTAL) - YouTube - This video demonstrates the automatic exchange between USDT <-> TON CRYSTAL with comments (on test networks ropsten and net.ton.dev). Links to transactions are provided in the video description.
Free TON Atomic Swaps (ETH - TON CRYSTAL) - YouTube - This video demonstrates the automatic exchange between ETH <-> TON CRYSTAL with partial closing of the order volume.
Further tasks
To add a new coin, the target blockchain does not need to support a Turing-complete language, only 3 conditions must be met:
- It should be possible to block funds by sha256 hashsum
- It should be possible to block funds by time
- The participant exchange data must fit into 32 bytes (we will expand it later, since the bitcoin Public Key requires 33 bytes)
During the development, a number of ideas were put forward to improve the exchange protocol, which are planned to be implemented in the future. Among them:
- Purchase of TON CRYSTALS by participants who do not have this tokens (gas credit in TON allows you to do it).
- Completion of the exchange protocol by third parties for a small reward in case of deviations from the protocol by participants, which increases the stability of the exchange.
- Collecting verified statistics of participants will allow you to exchange with those participants who have proven themselves well.
Disclaimer:
Due to the extremely limited time for the contest, this software is for testing purposes only . The production-ready solution requires much more time. Thank you for understanding.
License:
Source code licensed under the MIT license.
Communication:
Telegram: @Sergeydobkin
E-mail: [email protected]
Free TON Address: 0:b25b1add7706d9fa2f4e67fff7a5790563b258bff996fe9d4d5ceda826e9f725
GitHub: https://github.com/ton-swaps/
Dear jurors, dear community,
My name is Sergey, I am the leading blockchain developer in Broxus. Let me present the solution that our team has implemented.
Link to Github
The sources are licensed under GPL3.
Demonstration video
Description
As required by the contest’s terms, we have implemented the following features:
- Smart contracts allowing exchange TON <> BTC, TON <> ETH, TON <> ERC20
- Protection from the unauthorized withdrawal of funds from published contracts
- The possibility of a safe return of funds to each of the parties if the other party does not comply with the terms of the trade
- Possibility to set a fee and target wallet for the fee collection of the organizer of the trade (broker)
Extra features implemented:
- Smart contracts also allow the exchange ETH <> BTC, ERC20 <> BTC
Contact information
Telegram: @sergey_pavlovdog
Jury disclaimer
Broxus team officially abstains from voting for this contest submissions.
ton-swap.live – easy Free TON swaps
Submission
- This set of slides is a submission from the RSquad team for
participation in the # 35 Contest: Atomic Swaps on Free TON - Smart contracts and documentation are available in the GitHub
repository here: https://github.com/RSquad/ton-swap/ - The video is available here: https://drive.google.com/file/d/1nnB-8YALeylgV3R5Pf_qsiHZzEUFMR_s/view?usp=sharing
- A prototype (alpha version) of the end-user interface is available
here: https://ton-swap.live - The developed end-user interface layouts are available in the
attached presentation (PDF)
Contacts
Our contacts:
Telegram: @inyellowbus
Telegram: @RRoman_Tver
Email: [email protected]
Free TON Address:
0:699029b342411e9df797ab657b3aca0e53feea7714cb4e7f0e04311e3db15b48
Scope & Comments
- Available types of cross-chain trades (via low-level or console):
- Ethereum (native ETH and ERC20 tokens) vs Free TON
- Bitcoin vs Free TON (needs additional testing)
- The prototype of end-user interface (as a part of a future Free TON Atomic Swap solution) is
available here: https://ton-swap.live - cross-chain trades between Ethereum (inc. ERC20) and Free TON are available
- cross-chain trades end-user interface between Bitcoin and Free TON is under
development - The prototype of end-user interface is working in net.ton.dev and Rinkeby (supported ERC
address: 0x27A6971737Cc8CF9C0806ED3B1c4aD8e4DBDb37a) - Disclaimer:
- the current version of software is for testing purpose only!
Find presentations there — https://drive.google.com/file/d/1QNtnyRB5wDOqQ7_r9pHFEAEpDMkGJ-Kz/view?usp=sharing
Or in submission attachment
Developers Contest: Atomic Swaps on Free TON
Repository
Requirements
- The possibility of a safe return of funds to each of the parties if the other party does not comply with the terms of the trade
- Open sources of smart contracts published at GitHub/GitLab or another open repository
- Documentation
- Name and contact information of the contestant for communication (Telegram username, e-mail)
Summary
Author - Nail Khafizov, independent software developer.
Implementation and demonstration smart contracts of Atomic Swaps:
Ton Crystal
, Native Ether
, Ethereum ERC20
, Bitcoin
Motivation
Develop an infrastructure that allows users to perform transactions between different blockchains without escrow in an untrusted environment. It will make the exchange market around TON Crystal more secure for OTC transactions.
Abstract
Atomic Swap — a smart contract technology enables the exchange of one cryptocurrency for another without using centralized intermediaries (such as exchanges).
I’ve learned two ways of swaps:
- By using Hashed TimeLock Contract
- By using Simplified Payment Verification.
HTLC — the most simple. It requires supporting common hash function (e.g. sha256
) from blockchain and TimeLock contract functionality.
+
Сan be fully decentralised
-
Requires side communication between participants and locking money on specific time
SPV requires from one of two blockchains supporting runnig complex smart contracts (e.g. Ethereum
or Ton
) to verify transaction’s Merke Proof of transfer.
+
Transfer can be fast and automatic
-
Requires solution to identify the source of the transaction:
mainnet / testnet / side blockchain by using oracles smart contracts / supporting SPV verification by validators.
I chose HTLC, because:
- Time of contest is limited to 3 weeks
- High transmission speed can be achieved through automation Atomic Swap Wallet, which supports SPV verification different blockchains off-chain.
Implementation
Tech Stack
FreeTon: TON-Solidity-Compiler
, Solidity
, JS
for testing
Ethereum: Truffle
, Solidity
, JS
for testing
Bitcoin (Work in progress): bitcoinjs-lib
, JS
Repository structure
./ton
- Atomic Swap Contracts for FreeTon blockchain
./eth
- Atomic Swap Contracts for Ethereum blockchain
./btc
- Atomic Swap Contracts for Bitcoin blockchain
./app
- App for demostrating working of Smart Contracts at testnets. Not used in production, only for learning purpose
WorkFlow
Commands:
initiate
(participant address, amount, secret hash, lock time)
participate
(initiator address, amount, secret hash, lock time)
redeem
(secret)
refund
Steps:
-
Part A have to generate the secret limited by 32 bytes and store it securely. Next, Part A
initiate
and create contract with hash of secret and participant’s address. In this contract the locktime should be doubled to avoid scam (e. g.24h * 2 = 48h
). After that, Part A have to send transaction or smart contract address to Part B. -
Part B have to verify Part A’s contract: participant’s address, lockTime, amount, hash of code. If everything is OK — Part B should
participate
and create contract with Part A’s secret hash, otherwise Part B can do nothing. Part B should be careful, lockTime should be less Part A’s lockTime at the moment of creating contract. After, Part B have to send transaction or smart contract address to Part A. -
Part A have to verify Part B’s contract. If everything is OK — Part A can
redeem
from Part B’s contract and reveal secret, otherwise Part A can wait timeLock and refund his transfer. -
Part B should extract secret and
redeem
from Part A’s contract.
The most part of steps can be automated by wallet, with the exception of exchange address and transactions
FreeTon Atomic Swap Smart Contract
Source code
./contracts/AtomicSwap.sol
- Atomic Swap Smart Contract
Commands
npm test
- run tests. Require running tondev docker instance.
npm run build
- compile solidity smart contracts and generate js wrappers.
Requirements:
Tests
-
./test/AtomicSwapMultisigWalletTest.js
- Testing Atomic Swap case withoutAtomicSwapWallet
, using onlySetcodeMultisigWallet
from Surf. Deploy Atomic Swap by external message. -
./test/AtomicSwapTest.js
- Testing standard Atomic Swap case, transfering ton crystals from oneAtomicSwapWallet
and redeem by anotherAtomicSwapWallet
. -
./test/AtomicSwapRefundTest.js
- Testingrefund
Atomic Swap case.
Specification AtomicSwap.sol
-
contract AtomicSwap
- This contract implements Hashed TimeLock Contract. Lock ton crystals until lock time or redeem by secret. -
constructor(address initiator, address participant, uint128 amount, uint32 timeLock) public
- Constructor for creating Atomic Swap. Initiator must ptovide all required params. Constructor can be called in two ways: by external or external message. At first case, initator should send a small amount ton crystals to UNINIT account before deploying withbounce=false
. After deploying initiator must send rest ton crystals. At second case, internal message, initiator must send required amount of ton crystals with internal deploy message. -
function redeem(bytes secret) external;
- Redeem Atomic Swap by participant before time lock. EmitRedeemed
event to reveal secret. Sender must be participant. Destruct contract after execution. -
function refund() external;
- Refund Atomic Swap by initiator after time lock. Sender must be initiator. Destruct contract after execution. -
function params() public view returns (address initiator, address participant, uint32 timeLock, uint32 now, uint256 secretHash, uint128 amount, uint256 balance)
- Fetch params of Atomic Swap to verify it.
Bitcoin Atomic Swap Smart Contract
Description
Here is implementation of Hashed TimeLock Contract for Bitcoin using Script. This library doesn’t interact with blockchain and don’t implement wallet logic. Using this lib you can create raw transactions or calculate p2sh address of Atomic Swap. For interacting with bitcoin blockchain you should use your wallet, but I reccomend bitcoin-core
.
Source code
./contracts/AtomicSwapContracts.js
- Atomic Swap Smart Contract
Tests
Command line interface for testing bitcoin Atomic Swap contracts on regtest. To run it you should run regtest bitcoin network and send bitcoins to Alice’s and Dave’s p2wpkh addresses. In this exmaple Dave want to transfer btc to Alice using Atomic Swap.
Required to install
bitcoin-core
.
There are 4 commands:
-
node ./test/AtomicSwapTest.js create
- creates p2sh address of Atomic Swap contract. Next you should send required bitcoins to this address using your bitcoin-core wallet from Dave p2wpkh address. At this step we store params, secretHash adn etc. in file./test/db.json
to avoid passing them through cli. -
node ./test/AtomicSwapTest.js verify <p2shAddress>
- Alice should verify that p2shAdress have right params. Participant and Initiator public keys, secretHash, timeLock. -
node ./test/AtomicSwapTest.js redeem <tx-id> <tx-vout> <tx-hex>
- to redeem Atomic Swap you need to provide params of transaction, that was send with bitcoins to p2shAddress. You can use bitcoin-core to get it. This command returns hex of transaction that you need to send usingsendrawtransaction
in bitcoin-core. After this step Atomic Swap transfer is redeemed by Alice. -
node ./test/AtomicSwapTest.js refund <tx-id> <tx-vout> <tx-hex>
- to refund Atomic Swap you need to provide params of transaction, that was send with bitcoins to p2shAddress. You can use bitcoin-core to get it. This command returns hex of transaction that you need to send usingsendrawtransaction
in bitcoin-core. After this step Atomic Swap transfer is refunded by Dave.
Specification AtomicSwapContrcats.js
This contract implements Hashed TimeLock Contract. Lock bitcoins until lock time or redeem by secret. I’ve used in contract OP_CHECKLOCKTIMEVERIFY and OP_SHA256.
-
function createAtomicSwapScript(secretHash, initiatorPubKey, participantPubKey, lockTime)
- creates an atomic swap contract using Bitcoin Script. -
function createAtomicSwapRedeemScript(signature, participantPubKey, secret)
- creates an atomic swap redeem script. Can be used together with #createAtomicSwapScript. -
function createAtomicSwapRefundScript(signature, initiatorPubKey)
- creates an atomic swap redeem script. Can be used together with #createAtomicSwapScript.
Ethereum Atomic Swap Smart Contract
Source code
./contracts/AtomicSwap.sol
- Atomic Swap Smart Contract
Commands
npm test
- run tests by truffle, require running ganache
npm run build
- compile solidity smart contracts by truffle, require running ganache
npm run deploy
- run migration smart contract to development network, require running ganache
npm run deploy-ropsten
- run migration smart contract to ropsten network
Tests
-
./test/AtomicSwapTest.js
- Testing Atomic Swap transfer native ethers from one account and redeem by another account. -
./test/AtomicSwapErc20Test.js
- Testing Atomic Swap transfer erc20 tokens from one account and redeem by another account. -
./test/AtomicSwapRefundTest.js
-
Testing Atomic Swap refund native ether. -
./test/AtomicSwapRefundErc20Test.js
-
Testing Atomic Swap refund erc20 token.
Specification AtomicSwap.sol
-
contract AtomicSwap
- implements Hashed TimeLock Contract. Lock native ethers or ERC20 tokens until lock time or redeem by secret. Everyone can deploy this contract or use already deployed contract by another person. -
function createSwap(uint256 secretHash, address participant, uint256 value, uint256 timeLock) external payable
- creates Atomic Swap transfer from sender toparticipant
. Lock native ethervalue
untiltimeLock
or redeem.secretHash
is unique identifier for Atomic Swap. Be careful while generating secret. -
function createSwapErc20(uint256 secretHash, address participant, uint256 alue, uint256 timeLock, address tokenAddr) external
- creates Atomic Swap transfer from sender toparticipant
. Lock erc20 tokensvalue
untiltimeLock
or redeem.secretHash
is unique identifier for Atomic Swap. Be careful while generating secret.tokenAddr
is address of ERC20 compatible smart contract. -
function redeem(bytes calldata secret) external
- redeem Atomic Swap by participant before time lock. EmitRedeemed
event to reveal secret. Sender must be participant. -
function refund(uint256 secretHash) external
- refund Atomic Swap by initiator after time lock. Sender must be initiator. -
function params(uint256 secretHash) public view returns (address initiator, address participant, uint256 timeLock, uint256 currTime, uint256 value, address tokenAddr, SwapType swapType)
- fetch params of Atomic Swap to verify it.
Demonstration of using Atomic Swap smart contracts
Prerequisites
Atomic-Swap cli interface ‘./app/app.js’:
- Not for production usage, only for demonstration
FreeTon:
- Testnet network
- Testnet blockchain explorer
- Wallet with ton rubins
Ethereum:
- Ropsten testnet network
- Ropsten Etherscan
- Infura
- Wallet with ethers
Bitcoin:
- Testnet
- Bitcoin testnet explorer
- Bitcoin-core
- Wallet with bitcoins
Description
2 users participate in this example: 0-Alice
and 1-Bob
.
Alice has ton rubins and want to buy Ether.
Bob has Ether, want to buy ton rubins.
I will use Atomic Swap cli interface.
Atomic Swap cli help message:
$ node ./app/app.js -h
Usage: app [options] [command]
Options:
-V, --version output the version number
-u, --user <number> user id, can be used to specify user (default: 0)
-h, --help display help for command
Commands:
ton command for freeton blockchain
eth command for ethereum blockchain
btc command for bitcoin blockchain
reset reset keys and wallets
help [command] display help for command
Preparation
Need to check users have working wallets and positive balances. Deploy wallet if need.
-u 0
- parameter for Alice
-u 1
- parameter for Bob
$ node ./app/app.js -u 0 ton wallet-address
Atomic Swap Wallet address:
0:290371955258087a35fdeae9fec0b5c69b310f39b90a4bf32dbfed26a5632296
Send ton rubins from Surf app and deploy wallet.
$ node ./app/app.js -u 0 ton deploy-wallet
Atomic Swap Wallet deployed
Alice’s balance:
$ node ./app/app.js -u 0 ton balance
Atomic Swap Wallet balance:
"4_971_068_999"
$ node ./app/app.js -u 1 ton wallet-address
Atomic Swap Wallet address:
0:c0bee8851ee87883a84fa3093eb0db5ccc46f25e7c92eb06d53a9ef18e840d24
Bob’s balance:
$ node ./app/app.js -u 1 ton balance
Atomic Swap Wallet balance:
"971_068_999"
$ node ./app/app.js -u 0 eth wallet-address
Wallet address:
0xBcb9eDA088910ACe1328185d286f1CD5f49aa649
https://ropsten.etherscan.io/address/0xbcb9eda088910ace1328185d286f1cd5f49aa649
$ node ./app/app.js -u 1 eth wallet-address
Wallet address:
0x3613452b0EA100724b071031B8Fe2DAb0097CEd5
https://ropsten.etherscan.io/address/0x3613452b0ea100724b071031b8fe2dab0097ced5
$ node ./app/app.js -u 0 eth balance
Wallet balance:
"1_999_801_590_088_213_200"
$ node ./app/app.js -u 1 eth balance
Wallet balance:
"1_999_293_474_225_822_500"
Summary of preparation
Alice:
- ton wallet address:
0:290371955258087a35fdeae9fec0b5c69b310f39b90a4bf32dbfed26a5632296
- eth wallet address:
0xBcb9eDA088910ACe1328185d286f1CD5f49aa649
Bob:
- ton wallet address:
0:c0bee8851ee87883a84fa3093eb0db5ccc46f25e7c92eb06d53a9ef18e840d24
- eth wallet address:
0x3613452b0EA100724b071031B8Fe2DAb0097CEd5
Creating Atomic Swap
Alice created Atomic Swap transfer on FreeTon:
$ node ./app/app.js -u 0 ton initiate 0:c0bee8851ee87883a84fa3093eb0db5ccc46f25e7c92eb06d53a9ef18e840d24 1
Atomic Swap deployed, params:
{
"atomicSwapAddress": "0:318481293577870246e85a66048f76775126de9b8015fd62ca777db7752e6c9a",
"secret": "3c571ae637a65054c0dc63ab3b422532c54f02f7bf556e64fb9475793392f268",
"secretHash": "e8fd86f1c857d7c82381db888c6e12221888883837aa79874442b1cbdbc61cfa"
}
Bob received address of Atomic Swap contract from Alice and verified it. Timelock in 2 days, balance of Atomic Swap is sufficient, code hash is correct.
$ node ./app/app.js -u 1 ton params 0:318481293577870246e85a66048f76775126de9b8015fd62ca777db7752e6c9a
Atomic Swap params:
{
"initiator": "0:290371955258087a35fdeae9fec0b5c69b310f39b90a4bf32dbfed26a5632296",
"participant": "0:c0bee8851ee87883a84fa3093eb0db5ccc46f25e7c92eb06d53a9ef18e840d24",
"secretHash": "0xe8fd86f1c857d7c82381db888c6e12221888883837aa79874442b1cbdbc61cfa",
"amount": "1_000_000_000",
"atomicSwapBalance": "1_002_989_000",
"now": "1_600_599_695",
"timeLock": "1_600_772_416",
"codeHash": "50b3b047a6ce66ca89f153f2d98432f7f99c950161d53627a269ae80c6d8748f"
}
All right, Bob decided to transfer Atomic Swap on ethereum using Alice’s secretHash
.
https://ropsten.etherscan.io/address/0x977Bc3a977Abd6D27b3e4cf3B9b6209DbCE71254
https://ropsten.etherscan.io/tx/0x2ddb1645cf9c19936aed6e5a9a6a0d701db489afec0b3ff2009b8106b3f546e9
$ node ./app/app.js -u 1 eth participate 0xBcb9eDA088910ACe1328185d286f1CD5f49aa649 1 e8fd86f1c857d7c82381db888c6e12221888883837aa79874442b1cbdbc61cfa
Atomic Swap created
Alice verified Atomic Swap at ethereum network. TimeLock in 1 day, addresses and amount are correct.
$ node ./app/app.js -u 0 eth params e8fd86f1c857d7c82381db888c6e12221888883837aa79874442b1cbdbc61cfa
Atomic Swap params:
{
"0": "0x3613452b0EA100724b071031B8Fe2DAb0097CEd5",
"1": "0xBcb9eDA088910ACe1328185d286f1CD5f49aa649",
"2": "1600686693",
"3": "1600600339",
"4": "1000000000000000000",
"5": "0x0000000000000000000000000000000000000000",
"6": "0",
"initiator": "0x3613452b0EA100724b071031B8Fe2DAb0097CEd5",
"participant": "0xBcb9eDA088910ACe1328185d286f1CD5f49aa649",
"timeLock": "1600686693",
"currTime": "1600600339",
"value": "1000000000000000000",
"tokenAddr": "0x0000000000000000000000000000000000000000",
"swapType": "0"
}
Redeem Atomic Swap
All right, Atomic Swaps were created, now Alice can redeem transfer and reveal secret.
https://ropsten.etherscan.io/tx/0x3b2cd2fc313a78a54db8b3b14b2cf1b4d963b2955fc078c726d848bd71a1d3b7
$ node ./app/app.js -u 0 eth redeem 3c571ae637a65054c0dc63ab3b422532c54f02f7bf556e64fb9475793392f268
Atomic Swap redeemed
$ node ./app/app.js -u 0 eth balance
Wallet balance:
"2_999_617_075_088_213_500"
Bob have to retrieve secret and redeem too.
$ node ./app/app.js -u 1 eth get-secret e8fd86f1c857d7c82381db888c6e12221888883837aa79874442b1cbdbc61cfa
Atomic Swap secret:
"0x3c571ae637a65054c0dc63ab3b422532c54f02f7bf556e64fb9475793392f268"
$ node ./app/app.js -u 1 ton redeem 0:318481293577870246e85a66048f76775126de9b8015fd62ca777db7752e6c9a 3c571ae637a65054c0dc63ab3b422532c54f02f7bf556e64fb9475793392f268
Redeem success, check balance
$ node ./app/app.js -u 1 ton balance
Atomic Swap Wallet balance:
"1_950_826_918"
References
Guys, @SergeyD, @pavlovdog, @roman.nguyen, @nailkhaf great works!
The only drawback, as it seems to me, is that there is little originality in this competition, everyone went the same way and uses HTLC. Perhaps the next competition will be for the implementation of Bitcoin SPV, as mentioned in the link above . I have just worked out in this direction, the code turns out to be really more complex.
Tell me, is any of the works production-ready?
Personally, I make my own just so that I can use it myself later. If there are ready-made ones, I would use them for exchanges. And if not, what are the plans to bring the contest works to working condition?
@creator Thank you!
Is it possible to verify Ethereum’s Merkle tree with keccak256 and check ethash PoW in TON VM?
Or verify TON Ed25519 signature in Ethereum VM?
HTLC require only the presence of a sha256, which is found in many blockchains. In this sense it is much more versatile.
I can only say for our project. It is not production-ready, it will take several months to complete.
Improvement is required not only in the part of the UI, but also a number of problems need to be solved, for example, the possibility of loss of funds, which I wrote about in an article on Medium (only in Russian)
https://medium.com/@sergey.dobkin8/атомарные-свопы-в-free-ton-9701dbdf1bdc
idk, to my shame. That’s why I didn’t plan to integrate with Ethereum at first. In any case, this would be too expensive for SPV due to more frequent transactions. So for a combined BTC-ETH contest, the HTLC seems the only right solution, agree.
@SergeyD @pavlovdog @roman.nguyen
Hello colleagues. One of the tough conditions for implementation was this:
Tell me, which of you added this functionality to your solution?
Please do not be angry if I was inconsiderate and did not see this in your submission. Just answer. Thank.
My second question is how long will it take for you to get a stable solution into production?
It is a pity that you did such a great job, but did not submit an official submission for the contest. Sorry, your forum post is not a submission. (
@bitjudge, Hello!
One of the tough conditions for implementation was this:
Tell me, which of you added this functionality to your solution?
Please do not be angry if I was inconsiderate and did not see this in your submission. Just answer. Thank.
Here I see some lack of specifics in the assignment. Who is a broker? The presence of the owner person, in the sense that he is the only one organizing the exchange, makes the solution partially centralized, and the owner - the main point of failure. This means that the service cannot be highly reliable. The arrest and shutdown of some centralized mixers and exchanges is a clear confirmation of this.
Therefore, we designed our solution with decentralization in mind. There is no “owner” here, only the “creator”. Which deploys a TON Orderbook smart contract and that’s it. He does not incur any operating costs and does not receive any fees. In our solution, the broker is a smart contract. It collects a constant fee when depositing (see the receive () function in tonorderbook.sol) to cover the smc storage fee (it is also constant).
This is the same approach as in uniswap and other contract-based exchanges. And it is very reliable.
Of course, we could make it possible to collect fees for the creator. However, it doesn’t make any sense. Since all sources are distributed under a free license, anyone can deploy the same smart contract except that it does not charge a fee. And users will prefer it.
If Satoshi charged his own fee in every Bitcoin transaction, how quickly would the fork appear without it?
My second question is how long will it take for you to get a stable solution into production?
approx. 3-5 months.
The most difficult tasks that need to be implemented for a production-ready solution are the ability to complete the last part of the transaction by a third party and the ability to buy crystals by a person who does not have them.