1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::Uint128;
5
6#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
7pub struct Swap {
8 pub pool_id: u64,
9 pub denom_in: String,
10 pub denom_out: String,
11}
12
13impl Swap {
14 pub fn new(pool_id: u64, denom_in: impl Into<String>, denom_out: impl Into<String>) -> Self {
15 Swap {
16 pool_id,
17 denom_in: denom_in.into(),
18 denom_out: denom_out.into(),
19 }
20 }
21}
22
23#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
24pub struct Step {
25 pub pool_id: u64,
26 pub denom_out: String,
27}
28
29impl Step {
30 pub fn new(pool_id: u64, denom_out: impl Into<String>) -> Self {
31 Step {
32 pool_id,
33 denom_out: denom_out.into(),
34 }
35 }
36}
37
38#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
39#[serde(rename_all = "snake_case")]
40pub enum SwapAmount {
41 In(Uint128),
42 Out(Uint128),
43}
44
45impl SwapAmount {
46 pub fn as_in(&self) -> Uint128 {
47 match self {
48 SwapAmount::In(x) => *x,
49 _ => panic!("was output"),
50 }
51 }
52
53 pub fn as_out(&self) -> Uint128 {
54 match self {
55 SwapAmount::Out(x) => *x,
56 _ => panic!("was input"),
57 }
58 }
59}
60
61#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
62#[serde(rename_all = "snake_case")]
63pub enum SwapAmountWithLimit {
64 ExactIn { input: Uint128, min_output: Uint128 },
65 ExactOut { output: Uint128, max_input: Uint128 },
66}
67
68impl SwapAmountWithLimit {
69 pub fn discard_limit(self) -> SwapAmount {
70 match self {
71 SwapAmountWithLimit::ExactIn { input, .. } => SwapAmount::In(input),
72 SwapAmountWithLimit::ExactOut { output, .. } => SwapAmount::Out(output),
73 }
74 }
75}