Skip to content

Commit

Permalink
Astrovault swap adapter (#141)
Browse files Browse the repository at this point in the history
* add astrovault swap venue adapter

* add way to include the spot price on smart swap with metadata query (weighted spot price calc)

* remove unused import

* remove duplicate validation

both of these checks are already validated in the entrypoint contract, removing to reduce gas

* remove tests that test removed validation

---------

Co-authored-by: Jeremy Liu <[email protected]>
  • Loading branch information
FSoaresDev and NotJeremyLiu authored Oct 29, 2024
1 parent dfb2a0c commit 36d39e1
Show file tree
Hide file tree
Showing 13 changed files with 1,569 additions and 1 deletion.
51 changes: 50 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ keywords = ["cosmwasm"]

[workspace.dependencies]
astroport = "2.9"
astrovault = "0.1.8"
dexter = "1.4.0"
dexter-vault = "1.1.0"
dexter-stable-pool = "1.1.1"
Expand Down
34 changes: 34 additions & 0 deletions contracts/adapters/swap/astrovault/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "skip-go-swap-adapter-astrovault"
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]
astrovault = { 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 }
96 changes: 96 additions & 0 deletions contracts/adapters/swap/astrovault/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Neutron Astrovault Swap Adapter Contract

The Neutron Astrovault swap adapter contract is responsible for:

1. Taking the standardized entry point swap operations message format and converting it to Astrovault pool swaps message format.
2. Swapping by dispatching swaps to Astrovault router 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 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 Neutron Astrovault swap adapter contract using the Entrypoint contract address provided in the instantiation message.

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

## ExecuteMsg

### `swap`

Swaps the coin sent using the operations provided.

```json
{
"swap": {
"operations": [
{
"pool": "neutron...",
"denom_in": "ibc/B559A80D62249C8AA07A380E2A2BEA6E5CA9A6F079C912C3A9E9B494105E4F81",
"denom_out": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9"
},
{
"pool": "neutron...",
"denom_in": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9",
"denom_out": "untrn"
}
]
}
}
```

### `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_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": "untrn",
"amount": "1000000"
},
"swap_operations": [
{
"pool": "neutron...",
"denom_in": "untrn",
"denom_out": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9"
}
]
}
}
```

Response:

```json
{
"denom": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9",
"amount": "1000"
}
```
10 changes: 10 additions & 0 deletions contracts/adapters/swap/astrovault/src/bin/astrovault-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 36d39e1

Please sign in to comment.