# Swap Extension

AddrEncapsulate astroport for easy use by Kryptonite.

## Config

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Config {
    pub owner: Addr,
    pub new_owner: Option<Addr>,
}
```

<table><thead><tr><th width="185">Key</th><th width="204">Type</th><th>Description</th></tr></thead><tbody><tr><td>owner</td><td>Addr</td><td>The address of the contract's owner</td></tr><tr><td>new_owner*</td><td>Addr</td><td>The address of the contract's new owner</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

\* = optional

## InitMsg

```rust
#[cw_serde]
pub struct InstantiateMsg {
    pub owner: Addr,
}
```

```json
{
  "owner": "sei13xy3940qrar0k82k7fzhjpqaxj0h0tep7cpuxz"
}
```

<table><thead><tr><th width="185">Key</th><th width="204">Type</th><th>Description</th></tr></thead><tbody><tr><td>owner</td><td>Addr</td><td>The address of the contract's owner</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

## ExecuteMsg

### UpdatePairConfig&#x20;

Updates swap pair config , pair address find from astorport.

```rust
#[cw_serde]
pub enum ExecuteMsg {
    UpdatePairConfig {
        asset_infos: [AssetInfo; 2],
        pair_address: Addr,
        max_spread: Option<Decimal>,
        to: Option<Addr>,
    },
}
```

```
{
  "update_pair_config": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ],
    "pair_address": "sei1pqcgdn5vmf3g9ncs98vtxkydc6su0f9rk3uk73s5ku2xhthr6avswrwnrx"
  }
}
```

<table><thead><tr><th width="175">Key</th><th width="151">Type</th><th>Description</th></tr></thead><tbody><tr><td>asset_infos</td><td>Pair</td><td>The asset infos of the pair</td></tr><tr><td>pair_address</td><td>Addr</td><td>The address of the pair contract</td></tr><tr><td>max_spread*</td><td>Decimal</td><td>The maximum spread of the pair</td></tr><tr><td>to*</td><td>Addr</td><td>The address of the contract to receive the swap fees. If not set, use self</td></tr></tbody></table>

\* = optional

### ChangeOwner

Change the contract `owner`.only can issued by current owner.

```rust
#[cw_serde]
pub enum ExecuteMsg {
    ChangeOwner {
        new_owner: Addr,
    },
}
```

```
{
  "change_owner": {
    "new_owner": "sei...addr..."
  }
}
```

<table><thead><tr><th width="174">Key</th><th width="156">Type</th><th>Description</th></tr></thead><tbody><tr><td>new_owner</td><td>Addr</td><td>The new owner of the contract</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### UpdatePairStatus

Update whether the trading pair pool is available, the default is available, the type is bool.

```rust
#[cw_serde]
pub enum ExecuteMsg {
    UpdatePairStatus {
        asset_infos: [AssetInfo; 2],
        is_disabled: bool,
    },
}
```

```json
{
  "update_pair_status": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ],
    "is_disabled": false
  }
}
```

<table><thead><tr><th width="178">Key</th><th width="173">Type</th><th>Description</th></tr></thead><tbody><tr><td>asset_infos</td><td>Pair</td><td>Swap the asset pair</td></tr><tr><td>is_disabled</td><td>bool</td><td>The status of the pair</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### UpdatePairMaxSpread&#x20;

Set the maximum spread for a single pool, and use the default value of sparrow swap if it is not set by default

```
#[cw_serde]
pub enum ExecuteMsg {
    UpdatePairMaxSpread {
        asset_infos: [AssetInfo; 2],
        max_spread: Decimal,
    },
}
```

```
{
  "update_pair_max_spread": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ],
    "max_spread": 123456
  }
}

```

<table><thead><tr><th width="190">Key</th><th width="205">Type</th><th>Description</th></tr></thead><tbody><tr><td>asset_infos</td><td>Pair</td><td>Swap the asset pair</td></tr><tr><td>max_spread</td><td>Decimal</td><td>The max spread of the pair</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### SetWhitelist&#x20;

To set those addresses you can call the SwapDenom method.

```
#[cw_serde]
pub enum ExecuteMsg {
    SetWhitelist {
        caller: Addr,
        is_whitelist: bool,
    },
}
```

```
{
  "set_whitelist": {
    "caller": "sei...addr...",
    "is_whitelist": true
  }
}
```

<table><thead><tr><th width="167">Key</th><th width="191">Type</th><th>Description</th></tr></thead><tbody><tr><td>caller</td><td>Addr</td><td>The address of the caller</td></tr><tr><td>is_whitelist</td><td>bool</td><td>The status of the pair</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### SwapDenom

Swap for assets of the specified denom type.

```rust
#[cw_serde]
pub enum ExecuteMsg {
    SwapDenom {
        from_coin: Coin,
        target_denom: String,
        to_address: Option<String>,
    },
}
```

```
{
  "swap_denom": {
    "from_coin": {
      "denom": "usei",
      "amount": "12300"
    },
    "target_denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
  }
}
```

<table><thead><tr><th width="173">Key</th><th width="178">Type</th><th>Description</th></tr></thead><tbody><tr><td>from_coin</td><td>Coin</td><td>The input asset type of the source</td></tr><tr><td>target_denom</td><td>String</td><td>The target asset type to swap to</td></tr><tr><td>to_address*</td><td>String</td><td>The destination address where the target asset is sent, defaulting to the address initiating the swap.</td></tr></tbody></table>



## QueryMsg

All query messages are described below. A custom struct is defined for each query response.

### QueryConfig

Returns information about global config.

```
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(ConfigResponse)]
    QueryConfig {},
}
```

```
{
  "query_config": {}
}
```

### ConfigResponse&#x20;

```rust
#[cw_serde]
pub struct ConfigResponse {
    pub owner: Addr,
}
```

```
{
  "owner": "sei...addr..."
}
```

<table><thead><tr><th width="165">Key</th><th width="178">Type</th><th>Description</th></tr></thead><tbody><tr><td>owner</td><td>Addr</td><td>The address of the contract's owner</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### QueryIsSwapWhitelist&#x20;

Returns whether the address is in the whitelist.

```rust
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(bool)]
    QueryIsSwapWhitelist {
        caller: Addr
    },
}
```

```
{
  "query_is_swap_whitelist": {
    "caller": "sei...addr..."
  }
}
```

<table><thead><tr><th width="178">Key</th><th width="182">Type</th><th>Description</th></tr></thead><tbody><tr><td>caller</td><td>Addr</td><td>The address of the caller</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

Return ture or false.

### QueryPairConfig&#x20;

Returns information about a specific swap pair config.

```rust
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(PairConfigResponse)]
    QueryPairConfig {
        asset_infos: [AssetInfo; 2]
    },
}
```

```json
{
  "query_pair_config": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ]
  }
}
```

<table><thead><tr><th width="185">Key</th><th width="201">Type</th><th>Description</th></tr></thead><tbody><tr><td>asset_infos</td><td>Pair</td><td>Swap the asset pair</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### PairConfigResponse&#x20;

```rust
#[cw_serde]
pub struct PairConfigResponse {
    pub pair_address: Addr,
    pub is_disabled: bool,
    pub max_spread: Option<Decimal>,
    pub to: Option<Addr>,
}
```

```json
{
  "query_swap_info": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ]
  }
}
```

<table><thead><tr><th width="172">Key</th><th width="205">Type</th><th>Description</th></tr></thead><tbody><tr><td>asset_infos</td><td>Pair</td><td>Swap the asset pair</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### QuerySwapInfo&#x20;

Returns information about a specific swap pair info.

```rust
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(SwapInfoResponse)]
    QuerySwapInfo {
        asset_infos: [AssetInfo; 2]
    },
}

```

```json
{
  "query_swap_info": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ]
  }
}
```

### SwapInfoResponse&#x20;

```rust
#[cw_serde]
pub struct SwapInfoResponse {
    pub total_amount_in: Uint128,
    pub total_amount_out: Uint128,
}
```

```
{
  "total_amount_in": "123456",
  "total_amount_out": "123456"
}
```

<table><thead><tr><th width="204">Key</th><th width="196">Type</th><th>Description</th></tr></thead><tbody><tr><td>total_amount_in</td><td>Uint128</td><td>The total amount in of the pair</td></tr><tr><td>total_amount_out</td><td>Uint128</td><td>The total amount out of the pair</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### QuerySimulation

Returns information about a specific swap simulation.

```rust
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(SimulationResponse)]
    QuerySimulation {
        asset_infos: [AssetInfo; 2],
        offer_asset: Asset,
    },
}
```

```json
{
  "query_simulation": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ],
    "offer_asset": {
      "info": {
        "native_token": {
          "denom": "usei"
        }
      },
      "amount": "123456"
    }
  }
}
```

<table><thead><tr><th width="174">Key</th><th width="201">Type</th><th>Description</th></tr></thead><tbody><tr><td>asset_infos</td><td>Pair</td><td>Swap the asset pair</td></tr><tr><td>offer_asset</td><td>Asset</td><td>the offer asset</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### SimulationResponse

```rust
/// This structure holds the parameters that are returned from a swap simulation response
#[cw_serde]
pub struct SimulationResponse {
    /// The amount of ask assets returned by the swap
    pub return_amount: Uint128,
    /// The spread used in the swap operation
    pub spread_amount: Uint128,
    /// The amount of fees charged by the transaction
    pub commission_amount: Uint128,
}
```

```
{
  "return_amount": "123456",
  "spread_amount": "123456",
  "commission_amount": "123456"
}
```

<table><thead><tr><th width="206">Key</th><th width="139">Type</th><th>Description</th></tr></thead><tbody><tr><td>return_amount</td><td>Uint128</td><td>The return amount of the swap</td></tr><tr><td>spread_amount</td><td>Uint128</td><td>The spread amount of the swap</td></tr><tr><td>commission_amount</td><td>Uint128</td><td>The commission amount of the swap</td></tr></tbody></table>

### QueryReverseSimulation&#x20;

Returns information about a specific reverse swap simulation

```rust
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(ReverseSimulationResponse)]
    QueryReverseSimulation {
        asset_infos: [AssetInfo; 2],
        ask_asset: Asset,
    },
}
```

```json
{
  "query_reverse_simulation": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ],
    "ask_asset": {
      "info": {
        "native_token": {
          "denom": "usei"
        }
      },
      "amount": "123456"
    }
  }
}
```

<table><thead><tr><th width="169">Key</th><th width="173">Type</th><th>Description</th></tr></thead><tbody><tr><td>asset_infos</td><td>Pair</td><td>Swap the asset pair</td></tr><tr><td>ask_asset</td><td>Asset</td><td>The ask asset</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### ReverseSimulationResponse

```rust
/// This structure holds the parameters that are returned from a reverse swap simulation response.
#[cw_serde]
pub struct ReverseSimulationResponse {
    /// The amount of offer assets returned by the reverse swap
    pub offer_amount: Uint128,
    /// The spread used in the swap operation
    pub spread_amount: Uint128,
    /// The amount of fees charged by the transaction
    pub commission_amount: Uint128,
}
```

```
{
  "offer_amount": "123456",
  "spread_amount": "123456",
  "commission_amount": "123456"
}
```

<table><thead><tr><th width="204">Key</th><th width="158">Type</th><th>Description</th></tr></thead><tbody><tr><td>offer_amount</td><td>Uint128</td><td>The offer amount of the swap</td></tr><tr><td>spread_amount</td><td>Uint128</td><td>The spread amount of the swap</td></tr><tr><td>commission_amount</td><td>Uint128</td><td>The commission amount of the swap</td></tr></tbody></table>

### QueryCumulativePrices&#x20;

Returns information about a specific cumulative prices.

```rust
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(CumulativePricesResponse)]
    QueryCumulativePrices {
        asset_infos: [AssetInfo; 2],
    },
}
```

```
{
  "query_cumulative_prices": {
    "asset_infos": [
      {
        "native_token": {
          "denom": "usei"
        }
      },
      {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      }
    ]
  }
}
```

<table><thead><tr><th width="190">Key</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td>asset_infos</td><td>Pair</td><td>Swap the asset pair</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### CumulativePricesResponse&#x20;

```rust
/// This structure is used to return a cumulative prices query response.
#[cw_serde]
pub struct CumulativePricesResponse {
    /// The two assets in the pool to query
    pub assets: [Asset; 2],
    /// The total amount of LP tokens currently issued
    pub total_share: Uint128,
    /// The last value for the token0 cumulative price
    pub price0_cumulative_last: Uint128,
    /// The last value for the token1 cumulative price
    pub price1_cumulative_last: Uint128,
}
```

```json
{
  "assets": [
    {
      "info": {
        "native_token": {
          "denom": "usei"
        }
      },
      "amount": "123456"
    },
    {
      "info": {
        "native_token": {
          "denom": "factory/sei1h3ukufh4lhacftdf6kyxzum4p86rcnel35v4jk/usdt"
        }
      },
      "amount": "123456"
    }
  ],
  "total_share": "123456",
  "price0_cumulative_last": "123456",
  "price1_cumulative_last": "123456"
}
```

<table><thead><tr><th width="238">Key</th><th width="188">Type</th><th>Description</th></tr></thead><tbody><tr><td>assets</td><td>Pair</td><td>Swap the asset pair</td></tr><tr><td>total_share</td><td>Uint128</td><td>The total share of the pair</td></tr><tr><td>price0_cumulative_last</td><td>Uint128</td><td>The price0 cumulative last of the pair</td></tr><tr><td>price1_cumulative_last</td><td>Uint128</td><td>The price1 cumulative last of the pair</td></tr></tbody></table>
