Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement atomic swap contract with native tokens #26

Closed
ethanfrey opened this issue Jul 28, 2020 · 3 comments
Closed

Implement atomic swap contract with native tokens #26

ethanfrey opened this issue Jul 28, 2020 · 3 comments
Assignees

Comments

@ethanfrey
Copy link
Member

ethanfrey commented Jul 28, 2020

This should be a basic contract that implements one half of the IOV atomic swap spec. There is also a Solidity implementation of atomic swap as well as one that supports ERC20 tokens, so creating such a contract allows any CosmWasm-based chain to swap tokens with an Ethereum-based chain, possibly on some off-chain DEX or just "over the counter".

Create one contract that can handle and track many atomic swaps. Each swap has a unique ID and can store some tokens when it is created. Its balance cannot be adjusted after that fact, until it is either claimed or aborted (when the swap is closed and the funds go to a recipient).

For the first step, this should just handle native tokens that are sent along with the "create swap" message (see env.msg.sent_funds), and these can be distributed with BankMsg::Send.

You can start with with cosmwasm-template, but as the various contracts in this package are rather customized, it might make sense to copy eg. cw20-escrow as a start and then modify it heavily.

Please cover it with reasonable unit tests. You can look at this integration test to get an idea of a successful end-to-end flow. For this contract, it would be nice to break it up into smaller pieces. Note it should be able to create both sides of the swap on the same contract and resolve them.

@ethanfrey
Copy link
Member Author

@maurolacy I was doing cleanup and stubled upon https://github.com/CosmWasm/cosmwasm-examples/pull/2 which is when I started an atomic swap contract in Jan/Feb. The code uses a much older version of CosmWasm, but the key logic is the same. Maybe you can copy some stuff from that (I'm closing that PR)

@maurolacy
Copy link
Contributor

maurolacy commented Aug 19, 2020

OK, I've done an initial implementation. Basically copying cw20-escrow as you suggested, and adapting from your cosmwasm-examples atomic-swap branch.

I guess you'll want / prefer to have HandleMsg::Create functionality, a la cw20-escrow, to support multiple swaps in the contract. I'll do that next.

In case you want to take a look, code is pushed under https://github.com/CosmWasm/cosmwasm-plus/tree/atomic-swap.

Didn't make a pull request as code is still pretty basic, no unit tests, etc.

@maurolacy
Copy link
Contributor

PR: #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants