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

Shade protocol #153

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
568 changes: 455 additions & 113 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"
members = [
"contracts/entry-point",
"contracts/secret-entry-point",
"contracts/adapters/hyperlane",
"contracts/adapters/ibc/*",
"contracts/adapters/swap/*",
Expand Down Expand Up @@ -52,6 +53,7 @@ serde = { version = "1.0.194", default-features = false, features
serde-cw-value = "0.7.0"
serde-json-wasm = "1.0.1"
skip = { version = "0.3.0", path = "./packages/skip" }
secret-skip = { version = "0.3.0", path = "./packages/secret-skip" }
test-case = "3.3.1"
thiserror = "1"
white-whale-std = "1.1.1"
Expand Down
43 changes: 43 additions & 0 deletions contracts/adapters/swap/shade-protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "skip-go-swap-adapter-shade-protocol"
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 }

secret-skip = { workspace = true }

cosmwasm-std = { package = "secret-cosmwasm-std", version = "1.1.11"}
cosmwasm-schema = "1.4.0"
secret-toolkit = { git = "https://github.com/scrtlabs/secret-toolkit", tag = "v0.10.0" }
secret-storage-plus = { git = "https://github.com/securesecrets/secret-plus-utils", tag = "v0.1.1", features = [] }
serde = "1.0.114"
schemars = "0.8.1"

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

The Neutron Astroport swap adapter contract is responsible for:
1. Taking the standardized entry point swap operations message format and converting it to Astroport pool swaps message format.
2. Swapping by dispatching swaps to Astroport pool contracts.
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) or an exact amount out (estimating how much is required to get the specified amount out).

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 Neutron Astroport swap adapter contract using the Entrypoint contract address provided in the instantiation message.

``` json
{
"entry_point_contract_address": "neutron..."
}
```

## ExecuteMsg

### `swap`

Swaps the coin sent using the operations provided.

``` json
{
"swap": {
"operations": [
{
"pool": "neutron...",
"denom_in": "uatom",
"denom_out": "untrn"
},
{
"pool": "neutron...",
"denom_in": "untrn",
"denom_out": "uosmo"
}
]
}
}
```

### `transfer_funds_back`

Transfers all contract funds to the address provided, called by the swap adapter contract to send back the entry point contract the assets received from swapping.

Note: This function can be called by anyone as the contract is assumed to have no balance before/after it's called by the entry point contract. Do not send funds directly to this contract without calling a function.

``` json
{
"transfer_funds_back": {
"caller": "neutron..."
}
}
```

## QueryMsg

### `simulate_swap_exact_coin_out`

Returns the coin in required to receive the `coin_out` specified in the call (swapped through the `swap_operatons` provided)

Query:
``` json
{
"simulate_swap_exact_coin_out": {
"coin_out": {
"denom": "untrn",
"amount": "200000"
},
"swap_operations": [
{
"pool": "neutron...",
"denom_in": "uatom",
"denom_out": "untrn"
}
]
}
}
```

Response:
``` json
{
"denom": "uatom",
"amount": "100"
}
```

### `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": {
"coin_in": {
"denom": "uatom",
"amount": "100"
},
"swap_operations": [
{
"pool": "neutron...",
"denom_in": "uatom",
"denom_out": "untrn"
}
]
}
}
```

Response:
``` json
{
"denom": "untrn",
"amount": "100000"
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_schema::write_api;
use secret_skip::swap::{ExecuteMsg, InstantiateMsg, QueryMsg};

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