Skip to content

Commit

Permalink
Jw/smart swap exact in (#109)
Browse files Browse the repository at this point in the history
* add SmartSwapExactAssetIn swap type

* Revert "Add split route support in all adapters (#103)"

This reverts commit 1fa4f21.

* Revert "Support multiple routes in astroport adapter (#99)"

This reverts commit a95f17d.

* Revert "Support split routes in entry point contract (#101)"

This reverts commit 94c3bbf.

* Revert "Update contract types to support route splitting (#98)"

This reverts commit ec1fd57.

* Revert "add interface field to SwapOperation (#96)"

This reverts commit eb37618.

* remove deployed test contracts

* fix fmt issue

* update schema

* since user_swap is mutatable, we can mutate in place

* swap excess funds

* update schema

* lint change

* fix test

* add optional interface field to SwapOperation (#108)

* return error for largest_route_index

* [API-2792] Add hallswap adapter (#102)

* feat: add hallswap adapter

* chore: add readme

* pr fixes

* add optional interface field to SwapOperation

* update hallswap adapter to implement updated interface

* remove get_hallswap_routes_from_skip_routes

---------

Co-authored-by: thal0x <[email protected]>

---------

Co-authored-by: Jeremy Liu <[email protected]>
Co-authored-by: Yonggiee <[email protected]>
  • Loading branch information
3 people authored May 8, 2024
1 parent bf540d0 commit 2aba09a
Show file tree
Hide file tree
Showing 10 changed files with 536 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions contracts/adapters/swap/hallswap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "skip-api-swap-adapter-hallswap"
version = { workspace = true }
rust-version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
documentation = { workspace = true }
keywords = { workspace = true }

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
astroport = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw20 = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
skip = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
test-case = { workspace = true }
97 changes: 97 additions & 0 deletions contracts/adapters/swap/hallswap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Hallswap Adapter Contract

The Hallswap adapter contract is responsible for:

1. Taking the standardized entry point swap operations message format and converting it to Hallswap entry point swap execute message.
2. Swapping by dispatching the multi-hop swap operations to the Hallswap contract.
3. Providing query methods that can be called by the entry point contract (generally, to any external actor) to simulate multi-hop swaps that either specify an exact amount in (estimating how much would be received from the swap).

Note: Swap adapter contracts expect to be called by an entry point contract that provides basic validation and minimum amount out safety guarantees for the caller. There are no slippage guarantees provided by swap adapter contracts.

WARNING: Do not send funds directly to the contract without calling one of its functions. Funds sent directly to the contract do not trigger any contract logic that performs validation / safety checks (as the Cosmos SDK handles direct fund transfers in the `Bank` module and not the `Wasm` module). There are no explicit recovery mechanisms for accidentally sent funds.

## InstantiateMsg

Instantiates a new Dexter swap adapter contract using the Entrypoint contract address provided in the instantiation message.

``` json
{
"entry_point_contract_address": "terra1....",
"hallswap_contract_address": "terra1...."
}
```

## ExecuteMsg

### `swap`

Swaps the coin sent using the operations provided.

``` json
{
"swap": {
"offer_asset": {
"native": {
"denom": "uluna",
"amount": "10000"
}
},
"operations": [
{
"pool": "terra...",
"denom_in": "uluna",
"denom_out": "ibc/..."
},
{
"pool": "terra...",
"denom_in": "ibc/...",
"denom_out": "factory/..."
}
]
}
}
```

## QueryMsg

### `simulate_swap_exact_coin_in`

Returns the coin out that would be received from swapping the `coin_in` specified in the call (swapped through the `swap_operatons` provided)

Query:

``` json
{
"simulate_swap_exact_coin_in": {
"asset_in": {
"native": {
"denom": "uluna",
"amount": "2000000"
}
},
"swap_operations": [
{
"pool": "terra...",
"denom_in": "uluna",
"denom_out": "ibc/..."
},
{
"pool": "terra...",
"denom_in": "ibc/...",
"denom_out": "factory/..."
}
]
}
}
```

Response:

``` json
{
"native": {
"denom": "factory/...",
"amount": "1900000"
}
}
```
10 changes: 10 additions & 0 deletions contracts/adapters/swap/hallswap/src/bin/hallswap-schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_schema::write_api;
use skip::swap::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg
}
}
Loading

0 comments on commit 2aba09a

Please sign in to comment.