Skip to content

Commit c8fdd84

Browse files
authored
Dexes MinSwap and SundaeSwap (#25)
* Dexes MinSwap and SundaeSwap * Fix structure and some code loopes for DEXes * Fix variable name colision
1 parent adf7f4a commit c8fdd84

File tree

12 files changed

+972
-415
lines changed

12 files changed

+972
-415
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ serde_json = "1.0.86"
2727
tokio-tungstenite = "0.17.2"
2828
futures = "0.3.24"
2929
headers = "0.3.8"
30+
async-trait = "0.1.58"

example.toml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,30 @@
33
script_hash = "e6c90a5923713af5786963dee0fdffd830ca7e0c86a041d9e5833e91"
44
request_hash = "86ae9eebd8b97944a45201e4aec1330a72291af2d071644bba015959"
55
vesting_hash = "0a27b0fb1daeb27ff58a79adcefc784fe5cfb5399750d3552e8c54f9"
6-
address = "addr1wxr2a8htmzuhj39y2gq7ftkpxv98y2g67tg8zezthgq4jkg0a4ul4"
6+
address = "addr1wxr2a8htmzuhj39y2gq7ftkpxv98y2g67tg8zezthgq4jkg0a4ul4"
7+
type = "WingRidersV1"
8+
enable = true
9+
10+
[[pools]]
11+
script_hash = "57c8e718c201fba10a9da1748d675b54281d3b1b983c5d1687fc7317"
12+
request_hash = "0ca50950adbb06c5c5f6833924a66ac873e43202588b6d338602d78d"
13+
vesting_hash = "73c3f85a23b2b81d7df84a9616b666b1e1c8c5fcfff6783d9c4a1a45"
14+
address = "addr1wyx22z2s4kasd3w976pnjf9xdty88epjqfvgkmfnscpd0rg3z8y6v"
15+
type = "MinSwapV1"
16+
enable = true
17+
18+
[[pools]]
19+
script_hash = "e1317b152faac13426e6a83e06ff88a4d62cce3c1634ab0a5ec13309"
20+
request_hash = "a65ca58a4e9c755fa830173d2a5caed458ac0c73f97db7faae2e7e3b"
21+
vesting_hash = "73c3f85a23b2b81d7df84a9616b666b1e1c8c5fcfff6783d9c4a1a45"
22+
address = "addr1wxn9efv2f6w82hagxqtn62ju4m293tqvw0uhmdl64ch8uwc0h43gt"
23+
type = "MinSwapV1"
24+
enable = true
25+
26+
[[pools]]
27+
script_hash = "4020e7fc2de75a0729c3cc3af715b34d98381e0cdbcfa99c950bc3ac"
28+
request_hash = "ba158766c1bae60e2117ee8987621441fac66a5e0fb9c7aca58cf20a"
29+
vesting_hash = "ba158766c1bae60e2117ee8987621441fac66a5e0fb9c7aca58cf20a"
30+
address = "addr1w9qzpelu9hn45pefc0xr4ac4kdxeswq7pndul2vuj59u8tqaxdznu"
31+
type = "SundaeSwapV1"
32+
enable = true

src/config.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,78 @@
1+
use crate::sink::common::Dex;
12
use serde::Deserialize;
23

4+
use crate::types::{AssetAmount, Swap};
5+
use async_trait::async_trait;
6+
use oura::model::TransactionRecord;
7+
use sea_orm::DatabaseConnection;
8+
9+
fn default_as_true() -> bool {
10+
true
11+
}
12+
313
#[derive(Deserialize, Debug)]
414
pub struct Config {
515
pub pools: Vec<PoolConfig>,
616
}
717

18+
#[derive(Deserialize, Debug, PartialEq, Eq)]
19+
pub struct WingRidersV1;
20+
#[derive(Deserialize, Debug, PartialEq, Eq)]
21+
pub struct MinSwapV1;
22+
#[derive(Deserialize, Debug, PartialEq, Eq)]
23+
pub struct MinSwapV2;
24+
#[derive(Deserialize, Debug, PartialEq, Eq)]
25+
pub struct SundaeSwapV1;
26+
#[derive(Deserialize, Debug, PartialEq, Eq)]
27+
pub struct Empty;
28+
29+
#[derive(Debug, Deserialize, PartialEq, Eq)]
30+
pub enum PoolType {
31+
WingRidersV1,
32+
SundaeSwapV1,
33+
MinSwapV1,
34+
MinSwapV2,
35+
}
36+
37+
#[async_trait]
38+
impl Dex for Empty {
39+
async fn mean_value(
40+
&self,
41+
_pool: &PoolConfig,
42+
_db: &DatabaseConnection,
43+
_transaction: &TransactionRecord,
44+
) -> Option<(AssetAmount, AssetAmount)> {
45+
unimplemented!();
46+
}
47+
async fn swaps(
48+
&self,
49+
_pool: &PoolConfig,
50+
_db: &DatabaseConnection,
51+
_transaction: &TransactionRecord,
52+
) -> anyhow::Result<Vec<Swap>> {
53+
unimplemented!();
54+
}
55+
}
56+
857
#[derive(Deserialize, Debug)]
958
pub struct PoolConfig {
59+
#[serde(default = "default_as_true")]
60+
pub enable: bool,
1061
pub script_hash: String,
1162
pub request_hash: String,
1263
pub vesting_hash: String,
1364
pub address: String,
65+
#[serde(rename = "type")]
66+
pub pool_type: PoolType,
67+
}
68+
69+
impl PoolConfig {
70+
pub fn as_trait(&self) -> &dyn Dex {
71+
match &self.pool_type {
72+
PoolType::WingRidersV1 => &WingRidersV1 {},
73+
PoolType::MinSwapV1 => &MinSwapV1 {},
74+
PoolType::SundaeSwapV1 => &SundaeSwapV1 {},
75+
_ => &Empty {},
76+
}
77+
}
1478
}

src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ pub async fn get_utxo_input(
483483
}
484484
let mut assets = Vec::new();
485485
let mut out = TxOutputRecord {
486-
address: String::from("address"),
486+
address: o.payload.clone(),
487487
amount: 0,
488488
assets: None,
489489
datum_hash: o.datum_hash.clone(),

0 commit comments

Comments
 (0)