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

Cosmos integration. #1432

Closed
artemii235 opened this issue Aug 4, 2022 · 5 comments
Closed

Cosmos integration. #1432

artemii235 opened this issue Aug 4, 2022 · 5 comments

Comments

@artemii235
Copy link
Member

artemii235 commented Aug 4, 2022

Full Cosmos/Tendermint support in AtomicDEX.
Useful resources:

@artemii235 artemii235 self-assigned this Aug 4, 2022
artemii235 added a commit that referenced this issue Aug 10, 2022
* Got balance of arbitrary address.

* Checked balance of address that has IBC asset in addition to ATOM.

* Activated testnet ATOM and got correct balance.

* Withdraw WIP.

* Made a first testnet withdraw.

* WIP. Preparing for tendermint rpc support under WASM.

* WIP. Added WASM. Got rid of unwrap. Started using account sequence in withdraw.

* Finalize PoC.

* Add my_balance RPC test for ATOM.

* Use constants for header names and values.
start_history_background_fetching unimplemented for tendermint.

* Review fixes + reorder lp_coins imports.

* Add TIMEOUT_HEIGHT_DELTA.

* Add multiple rpc_urls support TODO.

* Fixes after merge.

* Use opt-level = 2 for release profile.

Co-authored-by: Artem Vitae <[email protected]>
@artemii235
Copy link
Member Author

artemii235 commented Aug 11, 2022

I've made a brief research on atomic swaps support on Cosmos, discovered the following:

  1. Main Cosmos Hub (ATOM) chain doesn't seem to support HTLC and smart contracts at all (need to re-check it again).
  2. HTLC is supported on IRIS docs: https://www.irisnet.org/docs/features/htlc.html#htlc.
  3. JUNO has WASM smart contracts support https://docs.junonetwork.io/juno/home-of-cosmwasm.
  4. EVMOS supports EVM contracts.

According to this, to swap the native ATOM, we will need to perform IBC transfer of it to one of these chains, lock there, and IBC back to Cosmos Hub when the swap is completed. It will require users to also have a native asset of the specific blockchain (e.g. IRIS) to pay IBC transfers fees, which might be inconvenient from an UX perspective. Though, I've not figured out a better solution for this yet.

@ozkanonur I think the plan is as follows for you:

  1. Implement HTLC PoC on Iris testnet. https://www.irisnet.org/docs/get-started/testnet.html Do it for Iris itself and check if it works for IBC assets.

  2. Recheck whether HTLC is activated on Cosmos Hub. You can ask on their Discord https://discord.com/invite/cosmosnetwork, and maybe we will get direct Cosmos developers contacts from CA.

  • If HTLC works on native ATOM/Cosmos Hub, it would be perfect. We can proceed with swaps implementation on it.
  • If not, we will likely need to create a special chain for AtomicDEX swaps in Cosmos ecosystem using Iris HTLC module. Discuss tokenomics, fees, etc. directly with CA.

@onur-ozkan onur-ozkan linked a pull request Aug 31, 2022 that will close this issue
@artemii235
Copy link
Member Author

@ozkanonur

As you finished HTLC PoC for IRIS and tokens, we can proceed with further steps. For now, we can implement IRIS swaps and consider creating our own HTLC-enabled chain later (approved by @tonymorony and @ca333). It would be perfect to also demo IBC Atom swap in the coming two weeks, though I'm unsure if it's really feasible.

As per implementation, you can create a test similar to https://github.com/KomodoPlatform/atomicDEX-API/blob/c7dde3a0aeff113db4ba58cbfaa4da6926cd9612/mm2src/mm2_main/src/mm2_tests.rs#L963 to start the swap. You will get unimplemented panics on the various methods that you require to implement. For most of them, you can use dummy implementations (even for swap payments validation methods, since it's PoC) - we just need all swaps transactions to be sent and trading completed.

Please let me know if you need any assistance with it 🙂

artemii235 pushed a commit that referenced this issue Sep 7, 2022
* create iris coin instance and execute `my_balance`

Signed-off-by: Onur Özkan <[email protected]>

* save development state

Signed-off-by: Onur Özkan <[email protected]>

* implement htlc for iris network

Signed-off-by: Onur Özkan <[email protected]>

* implement `hash_lock` generation in p.o.c test

Signed-off-by: Onur Özkan <[email protected]>

* save htlc claiming P.O.C state

Signed-off-by: Onur Özkan <[email protected]>

* update target address for htlc transactions

Signed-off-by: Onur Özkan <[email protected]>

* save htlc p.o.c(on IBC asset) work state

Signed-off-by: Onur Özkan <[email protected]>

* add doc-comments to iris/htlc.rs

Signed-off-by: Onur Özkan <[email protected]>

* save development state

Signed-off-by: Onur Özkan <[email protected]>

* save development state

Signed-off-by: Onur Özkan <[email protected]>

* save development state

Signed-off-by: Onur Özkan <[email protected]>

* update structs privacy of iris/htlc module

Signed-off-by: Onur Özkan <[email protected]>

* apply some beauty

Signed-off-by: ozkanonur <[email protected]>

* Exclude p.o.c derive attributes that are no longer required

Signed-off-by: ozkanonur <[email protected]>

* update annotation style

Signed-off-by: ozkanonur <[email protected]>

* fix code formatting

Signed-off-by: ozkanonur <[email protected]>

* fix review notes

Signed-off-by: ozkanonur <[email protected]>

* make `any_to_signed_raw_tx` sync

Signed-off-by: ozkanonur <[email protected]>

* drop mutability of `hash_lock_hash`

Signed-off-by: Onur Özkan <[email protected]>

* fix review note

Signed-off-by: Onur Özkan <[email protected]>

Signed-off-by: Onur Özkan <[email protected]>
Signed-off-by: ozkanonur <[email protected]>
borngraced pushed a commit that referenced this issue Sep 11, 2022
* create iris coin instance and execute `my_balance`

Signed-off-by: Onur Özkan <[email protected]>

* save development state

Signed-off-by: Onur Özkan <[email protected]>

* implement htlc for iris network

Signed-off-by: Onur Özkan <[email protected]>

* implement `hash_lock` generation in p.o.c test

Signed-off-by: Onur Özkan <[email protected]>

* save htlc claiming P.O.C state

Signed-off-by: Onur Özkan <[email protected]>

* update target address for htlc transactions

Signed-off-by: Onur Özkan <[email protected]>

* save htlc p.o.c(on IBC asset) work state

Signed-off-by: Onur Özkan <[email protected]>

* add doc-comments to iris/htlc.rs

Signed-off-by: Onur Özkan <[email protected]>

* save development state

Signed-off-by: Onur Özkan <[email protected]>

* save development state

Signed-off-by: Onur Özkan <[email protected]>

* save development state

Signed-off-by: Onur Özkan <[email protected]>

* update structs privacy of iris/htlc module

Signed-off-by: Onur Özkan <[email protected]>

* apply some beauty

Signed-off-by: ozkanonur <[email protected]>

* Exclude p.o.c derive attributes that are no longer required

Signed-off-by: ozkanonur <[email protected]>

* update annotation style

Signed-off-by: ozkanonur <[email protected]>

* fix code formatting

Signed-off-by: ozkanonur <[email protected]>

* fix review notes

Signed-off-by: ozkanonur <[email protected]>

* make `any_to_signed_raw_tx` sync

Signed-off-by: ozkanonur <[email protected]>

* drop mutability of `hash_lock_hash`

Signed-off-by: Onur Özkan <[email protected]>

* fix review note

Signed-off-by: Onur Özkan <[email protected]>

Signed-off-by: Onur Özkan <[email protected]>
Signed-off-by: ozkanonur <[email protected]>
@artemii235
Copy link
Member Author

artemii235 commented Sep 19, 2022

Checklist for the future:

artemii235 added a commit that referenced this issue Oct 26, 2022
* save development state

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: Onur Özkan <[email protected]>

* save dev state

Signed-off-by: Onur Özkan <[email protected]>

* IBC asset boilerplate. IRIS + USDC single RPC activation test WIP.

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* save dev  state

Signed-off-by: Onur Özkan <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* WIP. Activation in progress.

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: Onur Özkan <[email protected]>

* save todo notes

Signed-off-by: ozkanonur <[email protected]>

* IRIS + USDC activation done. Always set MsgCreateHtlc::timestamp to 0.
Pass secret hash directly.

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* Add sleep to wait_for_taker_payment_spend to test.

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* Display correct address for Tendermint related orders.

* save dev state

Signed-off-by: Onur Özkan <[email protected]>

* save dev state (integration test now passes)

Signed-off-by: ozkanonur <[email protected]>

* Add test that finds HTLC claim tx by HLTC id and extracts secret successfully.

* calculate amount

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* Implement wait_for_tx_spend with test.

* implement `fn extract_secret`

Signed-off-by: ozkanonur <[email protected]>

* fix clippy errors

Signed-off-by: ozkanonur <[email protected]>

* Fixed WASM compilation.

* Enable WASM tests on iris-swap-poc temporarily.

* handle errors/panics

Signed-off-by: ozkanonur <[email protected]>

* Added SecretHashAlgo and made SHA256 default temporarily.

* Lock sequence_lock in swap payments methods. NIMDA/RICK swap fails.
Temporarily remove is_tx_not_found_error check.

* Swap with UTXO works, but having issues with sequence on concurrent txs sending.

* WIP. Swaps fail.

* Refactor IBC -> TENDERMINTTOKEN. Make USDC and NIMDA TENDERMINTTOKEN in tests.

* Fix tests compilation.

* Pass secret hash as argument to HTLC spending methods.

* Temporarily return error from TendermintToken::withdraw (not implemented).

* Fix compilation.

* Additional logs in tests.

* implement `enable_tendermint_token` endpoint

Signed-off-by: ozkanonur <[email protected]>

* WIP. Adding ETH swaps support with sha256 secret hash.

* implement `tendermint_token::withdraw` and write unit test for
withdraw&token activation

Signed-off-by: ozkanonur <[email protected]>

* Add USDC-IBC-IRIS/tBNB to swaps test. Successful.

* support multiple rpc_urls

Signed-off-by: ozkanonur <[email protected]>

* fix wasm test

Signed-off-by: ozkanonur <[email protected]>

* fix `fmt` error

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* provide wasm compatibility

Signed-off-by: ozkanonur <[email protected]>

* Hotfix for orderbook and best orders v2 RPCs.

* [cosmos] increase tendermint fee

* increase fees

Signed-off-by: Onur Özkan <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* reduce time blocking

Signed-off-by: ozkanonur <[email protected]>

* Fixes after merge.

* Fix some tests.

* WIP. Iris dex fee validation. Swaps can fail!

* Fix clippy.

* WIP. Dex fee validation. Swaps work.

* save fee calculation dev state

Signed-off-by: ozkanonur <[email protected]>

* update `fn calculate_fee`

Signed-off-by: ozkanonur <[email protected]>

* implement dynamic fee calculation via tx simulation

Signed-off-by: ozkanonur <[email protected]>

* implement dynamic fee calculation on tendermint token and move `uuid` to
shared dependency section

Signed-off-by: ozkanonur <[email protected]>

* implement missing parts of fee calculation

Signed-off-by: ozkanonur <[email protected]>

* WIP. HTLC validation.

* WIP. Queried HTLC successfully.

* WIP. Payment validation done for now. Swaps work.

* Remove some #[allow(unused_variables)]. Impl get_public_key.

* Impl get_raw_transaction.

* make gas price as configurable

Signed-off-by: ozkanonur <[email protected]>

* save TODO notes for avg block time that will be used for time_lock calc

Signed-off-by: ozkanonur <[email protected]>

* save dev state of time_lock calculation

Signed-off-by: Onur Özkan <[email protected]>

* refactor time_lock calculation

Signed-off-by: ozkanonur <[email protected]>

* fix wasm compilation

Signed-off-by: ozkanonur <[email protected]>

* Add TODO title on p.o.c implementations

Signed-off-by: ozkanonur <[email protected]>

* implement `fn check_if_my_payment_sent`

Signed-off-by: ozkanonur <[email protected]>

* provide wasm compatibility for `fn check_if_my_payment_sent`

Signed-off-by: ozkanonur <[email protected]>

* provide Abci paths as constants

Signed-off-by: Onur Özkan <[email protected]>

* rollback wasm pipeline diff

Signed-off-by: ozkanonur <[email protected]>

* support `memo` field for withdraws

Signed-off-by: ozkanonur <[email protected]>

* downgrade visibility of `TX_DEFAULT_MEMO`

Signed-off-by: ozkanonur <[email protected]>

* use `TX_DEFAULT_MEMO` if memo is None for withdraws

Signed-off-by: ozkanonur <[email protected]>

* Fix few minor notes.

* use constants for ABCI request defaults

Signed-off-by: Onur Özkan <[email protected]>

* fix some review notes

Signed-off-by: Onur Özkan <[email protected]>

* fix some reivew notes

Signed-off-by: Onur Özkan <[email protected]>

* update `tendermint_token::check_if_my_payment_sent`

Signed-off-by: Onur Özkan <[email protected]>

* fix some PR notes

Signed-off-by: Onur Özkan <[email protected]>

* Stop ignoring some tests.

* create `MIN_TX_SATOSHIS` for tendermint

Signed-off-by: Onur Özkan <[email protected]>

* Fix some error mappings to avoid using empty ticker.

* Implement new trait methods after other PRs merge.

* refactor `fn check_if_my_payment_sent`

Signed-off-by: Onur Özkan <[email protected]>

* fix lint error

Signed-off-by: Onur Özkan <[email protected]>

* return `None` if can't find htlc in `fn check_if_my_payment_sent`

Signed-off-by: Onur Özkan <[email protected]>

* add fixes and optimizations

Signed-off-by: ozkanonur <[email protected]>

* fix some  notes

Signed-off-by: Onur Özkan <[email protected]>

* return error instead of `None` on error code

Signed-off-by: ozkanonur <[email protected]>

* fix fmt

Signed-off-by: Onur Özkan <[email protected]>

* Fixes after merge.

* fix compilation error for tests

Signed-off-by: ozkanonur <[email protected]>

* update condition comment

Signed-off-by: ozkanonur <[email protected]>

* Fix extremely long-running eth_tests.

* Fix tendermint_coin_tests::validate_payment_test.

* Fix more tests.

Signed-off-by: ozkanonur <[email protected]>
Signed-off-by: Onur Özkan <[email protected]>
Co-authored-by: Artem Vitae <[email protected]>
Co-authored-by: Artem Vitae <[email protected]>
Co-authored-by: Anton TonyL Lysakov <[email protected]>
Co-authored-by: Artem Vitae <[email protected]>
artemii235 added a commit that referenced this issue Nov 3, 2022
…1527)

* Implement methods used in recover_funds_of_swap for Tendermint.
Also implemented validate_address.
Add dummy error return for others to avoid occasional panics.

* Review fix.

* Ignore test_spl_transactions.

Co-authored-by: Artem Vitae <[email protected]>
artemii235 pushed a commit that referenced this issue Dec 4, 2022
* increase simulated gas to predict better values for real tx operations

Signed-off-by: Onur Özkan <[email protected]>

* remove couple TODO notes and impelement `lp_coins::wait_for_confirmations` for tendermint

Signed-off-by: Onur Özkan <[email protected]>

* create new fn `tendermint_coin::get_tx_status_code_or_none`

Signed-off-by: Onur Özkan <[email protected]>

* if no `gui_auth` was given, consider it as `false`

Signed-off-by: ozkanonur <[email protected]>

* implement `get_sender_trade_fee`

Signed-off-by: ozkanonur <[email protected]>

* implement `trade_fee` functionalities for cosmos

Signed-off-by: ozkanonur <[email protected]>

* group wasm and native rpcs under the rpc mod

Signed-off-by: ozkanonur <[email protected]>

* Create TendermintResultOrder and impl it's required traits

Signed-off-by: ozkanonur <[email protected]>

* fix wasm compilation

Signed-off-by: ozkanonur <[email protected]>

* fix avg_blocktime confusion

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* add iris mod

Signed-off-by: ozkanonur <[email protected]>

* fix wasm compilation

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* add TODO notes

Signed-off-by: ozkanonur <[email protected]>

* add TODO note

Signed-off-by: ozkanonur <[email protected]>

* avoid memory pressure, skip existed txs in tx_history, add fee_details

Signed-off-by: ozkanonur <[email protected]>

* remove no-longer required notes

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* implement `WaitForHistoryUpdateTrigger` for tendermint tx_history v2

Signed-off-by: ozkanonur <[email protected]>

* remove not required todo notes

Signed-off-by: ozkanonur <[email protected]>

* update `fn process_history_loop`

Signed-off-by: ozkanonur <[email protected]>

* update TODO notes of tendermint_token

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* complete tx_history_v2 functionality for tendermint

Signed-off-by: ozkanonur <[email protected]>

* move token insert to right before of result returning

Signed-off-by: ozkanonur <[email protected]>

* implement better error handling for tx_history v2 on tendermint

Signed-off-by: ozkanonur <[email protected]>

* shorten `fn is_tx_exists`

Signed-off-by: ozkanonur <[email protected]>

* rename `iris_swap_poc` into `iris_swap` remove ingored flag from the test

Signed-off-by: ozkanonur <[email protected]>

* update name of the iris swap test function

Signed-off-by: ozkanonur <[email protected]>

* re-ignore iris swap integration tests because of iris bug

Signed-off-by: ozkanonur <[email protected]>

* fix review notes

Signed-off-by: ozkanonur <[email protected]>

* show extra tx for platform fees on token txs

Signed-off-by: ozkanonur <[email protected]>

* partial fixes for review notes

Signed-off-by: ozkanonur <[email protected]>

* update expected log for tendermint tx history test

Signed-off-by: ozkanonur <[email protected]>

* read highest height for tendermint history

Signed-off-by: ozkanonur <[email protected]>

* remap tx amounts and insert all possible assets for tendermint

Signed-off-by: ozkanonur <[email protected]>

* fix balance problem

Signed-off-by: ozkanonur <[email protected]>

* skip `uamount` field for `TendermintFeeDetails`

Signed-off-by: ozkanonur <[email protected]>

* parse multiple tx events

Signed-off-by: ozkanonur <[email protected]>

* save dev state

Signed-off-by: ozkanonur <[email protected]>

* remove debug lines

Signed-off-by: ozkanonur <[email protected]>

* refactor tendermit tx history test

Signed-off-by: ozkanonur <[email protected]>

* fix review notes

Signed-off-by: ozkanonur <[email protected]>

Signed-off-by: Onur Özkan <[email protected]>
Signed-off-by: ozkanonur <[email protected]>
@onur-ozkan
Copy link
Member

Try to create a chain using Cosmos SDK with Iris HTLC support, connect it to testnet Cosmos HUB and setup IBC channel.

Is this part of the cosmos integration? It seemed like nucleus project is out of scope for this task.

@shamardy
Copy link
Collaborator

@onur-ozkan I think we can close this issue as completed. Only item left in the checklist is SPV validation of swap transactions and there is an issue opened for SPV for all protocols, and I added tendermint to the checklist there #1612 (comment).

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

No branches or pull requests

3 participants