Skip to content

Commit a1ddf6a

Browse files
committed
feat: ekubo manual swap
1 parent 796289e commit a1ddf6a

File tree

8 files changed

+430
-435
lines changed

8 files changed

+430
-435
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ edition = "2024"
2121
[dependencies]
2222
thiserror = "2.0.16"
2323
serde = {version="1.0.219", features=["derive"]}
24-
starknet = "0.15.0"
25-
starknet-contract = "0.15.0"
26-
starknet-accounts = "0.15.0"
27-
starknet-providers = "0.15.0"
28-
starknet-core = "0.15.0"
2924
tokio = { version = "1.0", features = ["full"] }
3025
reqwest = { version = "0.12", features = ["json"] }
3126
url = "2.5"
32-
hex = "0.4"
27+
hex = "0.4"
28+
starknet = "0.17.0"
29+
starknet-contract = "0.16.0"
30+
starknet-accounts = "0.16.0"
31+
starknet-providers = "0.16.0"
32+
starknet-core = "0.16.0"

src/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
contracts::{AutoSwapprContract, Erc20Contract},
3-
types::connector::{AutoSwapprConfig, AutoSwapprError, ContractInfo, SwapData, Uint256},
3+
types::connector::{AutoSwappr, AutoSwapprError, ContractInfo, SwapData, Uint256},
44
};
55
use starknet::{
66
accounts::{Account, ExecutionEncoding, SingleOwnerAccount},
@@ -18,12 +18,12 @@ pub struct AutoSwapprClient {
1818
provider: Arc<JsonRpcClient<HttpTransport>>,
1919
autoswappr_contract: AutoSwapprContract,
2020
account: SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet>,
21-
config: AutoSwapprConfig,
21+
config: AutoSwappr,
2222
}
2323

2424
impl AutoSwapprClient {
2525
/// Create a new AutoSwappr client with real Starknet integration
26-
pub async fn new(config: AutoSwapprConfig) -> Result<Self, AutoSwapprError> {
26+
pub async fn new(config: AutoSwappr) -> Result<Self, AutoSwapprError> {
2727
// Parse RPC URL
2828
let rpc_url = Url::parse(&config.rpc_url).map_err(|e| AutoSwapprError::InvalidInput {
2929
details: format!("Invalid RPC URL: {}", e),
@@ -430,7 +430,7 @@ impl AutoSwapprClient {
430430
mod tests {
431431
use super::*;
432432
use crate::types::connector::{
433-
Amount, AutoSwapprConfig, PoolKey, SwapData, SwapParameters, Uint256,
433+
Amount, AutoSwappr, PoolKey, SwapData, SwapParameters, Uint256,
434434
};
435435

436436
fn create_test_config() -> AutoSwapprConfig {

src/constant/mod.rs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
mod util;
2+
use std::sync::LazyLock;
3+
4+
use starknet::core::types::Felt;
5+
pub use util::u128_to_uint256;
16
//Token addresses for common tokens
2-
#[allow(dead_code)]
3-
const STRK: &str = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
4-
#[allow(dead_code)]
5-
const ETH: &str = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
6-
#[allow(dead_code)]
7-
const USDC: &str = "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8";
8-
#[allow(dead_code)]
9-
const USDT: &str = "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8";
10-
#[allow(dead_code)]
11-
const WBTC: &str = "0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac";
7+
8+
pub static STRK: LazyLock<Felt> = LazyLock::new(|| {
9+
Felt::from_hex("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d").unwrap()
10+
});
11+
pub static ETH: LazyLock<Felt> = LazyLock::new(|| {
12+
Felt::from_hex("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7").unwrap()
13+
});
14+
pub static USDC: LazyLock<Felt> = LazyLock::new(|| {
15+
Felt::from_hex("0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8").unwrap()
16+
});
17+
pub static USDT: LazyLock<Felt> = LazyLock::new(|| {
18+
Felt::from_hex("0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8").unwrap()
19+
});
20+
pub static WBTC: LazyLock<Felt> = LazyLock::new(|| {
21+
Felt::from_hex("0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac").unwrap()
22+
});
1223

1324
#[allow(dead_code)]
1425
#[derive(Clone)]
@@ -17,44 +28,44 @@ pub struct TokenAddress<'a> {
1728
}
1829

1930
#[allow(dead_code)]
20-
#[derive(Clone)]
31+
#[derive(Clone, Debug)]
2132
/// Token information for supported tokens
2233
pub struct TokenInfo<'a> {
23-
address: &'a str,
24-
symbol: &'a str,
25-
decimals: u8,
34+
pub address: Felt,
35+
pub symbol: &'a str,
36+
pub decimals: u8,
2637
name: &'a str,
2738
}
2839
#[allow(dead_code)]
2940
impl TokenAddress<'static> {
3041
pub fn new() -> Self {
3142
let tokens: Vec<TokenInfo> = vec![
3243
TokenInfo {
33-
address: ETH,
44+
address: *ETH,
3445
symbol: "ETH",
3546
decimals: 18,
3647
name: "Ether",
3748
},
3849
TokenInfo {
39-
address: USDC,
50+
address: *USDC,
4051
symbol: "USDC",
4152
decimals: 6,
4253
name: "USD Coin",
4354
},
4455
TokenInfo {
45-
address: USDT,
56+
address: *USDT,
4657
symbol: "USDT",
4758
decimals: 6,
4859
name: "Tether USD",
4960
},
5061
TokenInfo {
51-
address: WBTC,
62+
address: *WBTC,
5263
symbol: "WBTC",
5364
decimals: 8,
5465
name: "Wrapped BTC",
5566
},
5667
TokenInfo {
57-
address: STRK,
68+
address: *STRK,
5869
symbol: "STRK",
5970
decimals: 18,
6071
name: "Starknet Token",
@@ -73,14 +84,10 @@ impl TokenAddress<'static> {
7384
None => Err("TOKEN IS NOT AVAILABLE".to_string()),
7485
}
7586
}
76-
pub fn get_token_address(&self, address: &'static str) -> Result<&'static str, String> {
77-
let token = self
78-
.tokens
79-
.iter()
80-
.find(|x| x.symbol.to_lowercase() == address.to_lowercase())
81-
.cloned();
87+
pub fn get_token_info_by_address(&self, address: Felt) -> Result<TokenInfo<'static>, String> {
88+
let token = self.tokens.iter().find(|x| x.address == address).cloned();
8289
match token {
83-
Some(x) => Ok(x.address),
90+
Some(x) => Ok(x),
8491
None => Err("TOKEN IS NOT AVAILABLE".to_string()),
8592
}
8693
}
@@ -92,26 +99,27 @@ mod tests {
9299

93100
#[test]
94101
fn is_success() {
95-
let strk = TokenAddress::new().get_token_info("strk");
96-
assert_eq!(strk.unwrap().address, STRK);
97-
let usdc = TokenAddress::new().get_token_info("usdc");
98-
assert_eq!(usdc.unwrap().address, USDC);
99-
let usdt = TokenAddress::new().get_token_info("usdt");
100-
assert_eq!(usdt.unwrap().address, USDT);
101-
let eth = TokenAddress::new().get_token_info("eth");
102-
assert_eq!(eth.unwrap().address, ETH);
103-
let eth = TokenAddress::new().get_token_info("eth");
102+
let strk = TokenAddress::new().get_token_info_by_address(*STRK);
103+
assert_eq!(strk.clone().unwrap().address, *STRK);
104+
println!("strk {:?} ", strk);
105+
let usdc = TokenAddress::new().get_token_info_by_address(*USDC);
106+
assert_eq!(usdc.unwrap().address, *USDC);
107+
let usdt = TokenAddress::new().get_token_info_by_address(*USDT);
108+
assert_eq!(usdt.unwrap().address, *USDT);
109+
let eth = TokenAddress::new().get_token_info_by_address(*ETH);
110+
assert_eq!(eth.unwrap().address, *ETH);
111+
let eth = TokenAddress::new().get_token_info_by_address(*ETH);
104112
assert_eq!(eth.unwrap().name, "Ether");
105-
let wbtc = TokenAddress::new().get_token_info("wbtc");
106-
assert_eq!(wbtc.unwrap().address, WBTC);
107-
let wbtc = TokenAddress::new().get_token_info("wbtc");
113+
let wbtc = TokenAddress::new().get_token_info_by_address(*WBTC);
114+
assert_eq!(wbtc.unwrap().address, *WBTC);
115+
let wbtc = TokenAddress::new().get_token_info_by_address(*WBTC);
108116
assert_eq!(wbtc.unwrap().decimals, 8);
109117
}
110118

111119
#[test]
112120
#[should_panic(expected = "TOKEN IS NOT AVAILABLE")]
113121
fn should_panic() {
114122
let strk = TokenAddress::new().get_token_info("sol");
115-
assert_eq!(strk.unwrap().address, STRK);
123+
assert_eq!(strk.unwrap().address, *STRK);
116124
}
117125
}

src/constant/util.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use starknet::core::types::Felt;
2+
3+
// Helper function to convert u128 to (low, high) felts for uint256
4+
pub fn u128_to_uint256(amount: u128) -> (Felt, Felt) {
5+
let amount_low = Felt::from(amount & 0xFFFFFFFFFFFFFFFF); // Lower 64 bits (NOT 128!)
6+
let amount_high = Felt::from(amount >> 64); // Upper 64 bits
7+
(amount_low, amount_high)
8+
}

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
pub mod client;
1+
// pub mod client;
22
pub mod constant;
3-
pub mod contracts;
3+
// pub mod contracts;
44
pub mod provider;
55
pub mod simple_client;
6+
pub mod swappr;
67
pub mod types;
7-
8-
#[cfg(test)]
9-
mod contracts_test;
8+
// #[cfg(test)]
9+
// mod contracts_test;
1010

1111
// Re-export main types and clients for easy access
12-
pub use client::AutoSwapprClient;
13-
pub use contracts::{AutoSwapprContract, Erc20Contract, addresses};
12+
// pub use client::AutoSwapprClient;
13+
// pub use contracts::{AutoSwapprContract, Erc20Contract, addresses,conversions::u128_to_uint256};
1414
pub use provider::{Network, StarknetProvider};
1515
pub use simple_client::{
1616
SimpleAutoSwapprClient, SimpleConfig, SimpleError, SwapData as SimpleSwapData,
1717
};
1818
pub use types::connector::{
19-
Amount, AutoSwapprConfig, AutoSwapprError, ContractInfo, Delta, FeeType, I129, PoolKey, Route,
20-
RouteParams, SwapData, SwapOptions, SwapParameters, SwapParams, SwapResult, TokenInfo, Uint256,
19+
AutoSwappr, AutoSwapprError, ContractInfo, Delta, FeeType, I129, PoolKey, Route, RouteParams,
20+
SwapData, SwapOptions, SwapParameters, SwapParams, SwapResult, TokenInfo, Uint256,
2121
};

0 commit comments

Comments
 (0)