-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from WHELP-project/multihop/implement-contract
Multihop: Implement new contract
- Loading branch information
Showing
18 changed files
with
2,643 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[alias] | ||
wasm = "build --release --lib --target wasm32-unknown-unknown" | ||
wasm-debug = "build --lib --target wasm32-unknown-unknown" | ||
unit-test = "test --lib" | ||
integration-test = "test --test integration" | ||
schema = "run --bin multi_hop_schema" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.rs] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Build results | ||
/target | ||
|
||
# Text file backups | ||
**/*.rs.bk | ||
|
||
# macOS | ||
.DS_Store | ||
|
||
# IDEs | ||
*.iml | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "dex-multi-hop" | ||
version = { workspace = true } | ||
authors = ["Jakub <[email protected]>"] | ||
edition = { workspace = true } | ||
description = "Dex Multi-hop - provides multi-hop swap functionality" | ||
license = { workspace = true } | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
library = [] | ||
|
||
[dependencies] | ||
coreum-wasm-sdk = { workspace = true } | ||
cosmwasm-schema = { workspace = true } | ||
cosmwasm-std = { workspace = true } | ||
cw-storage-plus = { workspace = true } | ||
cw2 = { workspace = true } | ||
cw20 = { workspace = true } | ||
cw-utils = { workspace = true } | ||
thiserror = { workspace = true } | ||
dex = { workspace = true } | ||
|
||
[dev-dependencies] | ||
anyhow = { workspace = true } | ||
cw-multi-test = { workspace = true } | ||
cw20-base = { workspace = true } | ||
# dex-factory = { workspace = true } | ||
dex-pool = { workspace = true } | ||
dex-stake = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
# Dex Router | ||
|
||
The Router contract contains logic to facilitate multi-hop swaps for smart tokens and cw20. | ||
|
||
--- | ||
|
||
### Operations Assertion | ||
|
||
For every swap, the contract checks if the resulting token is the one that was asked for and whether the receiving amount exceeds the minimum to receive. | ||
|
||
## InstantiateMsg | ||
|
||
Initializes the contract with the dex factory contract address. | ||
|
||
```json | ||
{ | ||
"dex_factory": "core..." | ||
} | ||
``` | ||
|
||
## ExecuteMsg | ||
|
||
### `receive` | ||
|
||
CW20 receive msg. | ||
|
||
```json | ||
{ | ||
"receive": { | ||
"sender": "core...", | ||
"amount": "123", | ||
"msg": "<base64_encoded_json_string>" | ||
} | ||
} | ||
``` | ||
|
||
### `execute_swap_operation` | ||
|
||
Swaps one token to another. _single_ defines whether this swap is single or part of a multi hop route. | ||
This message is for internal use. | ||
|
||
### Example | ||
|
||
Swap UST => mABNB | ||
|
||
```json | ||
{ | ||
"execute_swap_operation": { | ||
"operation": { | ||
"dex_swap": { | ||
"offer_asset_info": { | ||
"smart_token": { | ||
"denom": "uusd" | ||
} | ||
}, | ||
"ask_asset_info": { | ||
"cw20_token": { | ||
"contract_addr": "core..." | ||
} | ||
} | ||
} | ||
}, | ||
"to": "terra...", | ||
"max_spread": "0.05", | ||
"single": false | ||
} | ||
} | ||
``` | ||
|
||
### `execute_swap_operations` | ||
|
||
Performs multi-hop swap operations for native & cw20 tokens. Swaps execute one-by-one and the last swap will return the ask token. This function is public (can be called by anyone). | ||
|
||
### Example | ||
|
||
Swap KRT => UST => mABNB | ||
|
||
```json | ||
{ | ||
"execute_swap_operations": { | ||
"operations": [ | ||
{ | ||
"native_swap":{ | ||
"offer_denom":"ukrw", | ||
"ask_denom":"uusd" | ||
} | ||
}, | ||
{ | ||
"dex_swap": { | ||
"offer_asset_info": { | ||
"native_token": { | ||
"denom": "uusd" | ||
} | ||
}, | ||
"ask_asset_info": { | ||
"token": { | ||
"contract_addr": "core..." | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"minimum_receive": "123", | ||
"to": "core...", | ||
"max_spread": "0.05" | ||
} | ||
} | ||
``` | ||
|
||
### `assert_minimum_receive` | ||
|
||
Checks that an amount of ask tokens exceeds `minimum_receive`. This message is for internal use. | ||
|
||
```json | ||
{ | ||
"assert_minimum_receive": { | ||
"asset_info": { | ||
"smart_token": { | ||
"contract_addr": "core..." | ||
} | ||
}, | ||
"prev_balance": "123", | ||
"minimum_receive": "123", | ||
"receiver": "core..." | ||
} | ||
} | ||
``` | ||
|
||
## QueryMsg | ||
|
||
All query messages are described below. A custom struct is defined for each query response. | ||
|
||
### `config` | ||
|
||
Returns the general configuration for the router contract. | ||
|
||
```json | ||
{ | ||
"config": {} | ||
} | ||
``` | ||
|
||
### `simulate_swap_operations` | ||
|
||
Simulates multi-hop swap operations. Examples: | ||
|
||
- KRT => UST => mABNB | ||
|
||
```json | ||
{ | ||
"simulate_swap_operations" : { | ||
"offer_amount": "123", | ||
"operations": [ | ||
{ | ||
"smart_swap": { | ||
"offer_denom": "ukrw", | ||
"ask_denom": "uusd" | ||
} | ||
}, | ||
{ | ||
"dex_swap": { | ||
"offer_asset_info": { | ||
"smart_token": { | ||
"denom": "uusd" | ||
} | ||
}, | ||
"ask_asset_info": { | ||
"cw20_token": { | ||
"contract_addr": "core..." | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
- mABNB => UST => KRT | ||
|
||
```json | ||
{ | ||
"simulate_swap_operations" : { | ||
"offer_amount": "123", | ||
"operations": [ | ||
{ | ||
"dex_swap": { | ||
"offer_denom": "uusd", | ||
"ask_denom": "ukrw" | ||
} | ||
}, | ||
{ | ||
"dex_swap": { | ||
"offer_asset_info": { | ||
"cw20_token": { | ||
"contract_addr": "core..." | ||
} | ||
}, | ||
"ask_asset_info": { | ||
"smart_token": { | ||
"denom": "uusd" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# stable | ||
newline_style = "unix" | ||
hard_tabs = false | ||
tab_spaces = 4 | ||
|
||
# unstable... should we require `rustup run nightly cargo fmt` ? | ||
# or just update the style guide when they are stable? | ||
#fn_single_line = true | ||
#format_code_in_doc_comments = true | ||
#overflow_delimited_expr = true | ||
#reorder_impl_items = true | ||
#struct_field_align_threshold = 20 | ||
#struct_lit_single_line = true | ||
#report_todo = "Always" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use cosmwasm_schema::write_api; | ||
use dex_multi_hop::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; | ||
|
||
fn main() { | ||
write_api! { | ||
instantiate: InstantiateMsg, | ||
query: QueryMsg, | ||
execute: ExecuteMsg | ||
} | ||
} |
Oops, something went wrong.