A Rust SDK for interacting with the AutoSwappr contract on Starknet.
- 🔄 Execute manual token swaps on Ekubo
- 🦀 Full Rust type safety
- ⚡ Async/await support with Tokio
Add this to your Cargo.toml:
[dependencies]
autoswappr-sdk = "0.1.0"
tokio = { version = "1", features = ["full"] }All other dependencies (like starknet, axum, etc.) are automatically included.
0x05582ad635c43b4c14dbfa53cbde0df32266164a0d1b36e5b510e5b34aeb364b
use autoswappr_sdk::{AutoSwappr, constant::{STRK, USDC}};
#[tokio::main]
async fn main() {
// Initialize the SDK
let mut swapper = AutoSwappr::config(
"https://starknet-mainnet.public.blastapi.io".to_string(),
"YOUR_ACCOUNT_ADDRESS".to_string(),
"YOUR_PRIVATE_KEY".to_string(),
"0x05582ad635c43b4c14dbfa53cbde0df32266164a0d1b36e5b510e5b34aeb364b".to_string(),
).unwrap();
// Execute swap (1 STRK to USDC)
let result = swapper.ekubo_manual_swap(*STRK, *USDC, 1).await;
match result {
Ok(response) => println!("Swap successful! Tx: {:?}", response.tx_hash),
Err(error) => println!("Swap failed: {}", error.message),
}
}Configure a new AutoSwappr instance.
pub fn config(
rpc_url: String,
account_address: String,
private_key: String,
contract_address: String,
) -> Result<AutoSwappr, Json<ErrorResponse>>Execute a manual token swap.
pub async fn ekubo_manual_swap(
&mut self,
token0: Felt,
token1: Felt,
swap_amount: u128,
) -> Result<Json<SuccessResponse>, Json<ErrorResponse>>Parameters:
token0: Source token addresstoken1: Destination token addressswap_amount: Amount to swap (in token units, not smallest denomination)
Returns:
Ok(SuccessResponse): Contains transaction hash on successErr(ErrorResponse): Contains error message on failure
use autoswappr_sdk::constant::{STRK, USDC, ETH};
// STRK token
*STRK
// USDC token
*USDC
// ETH token
*ETH- Use environment variables for sensitive data
- Keep private keys secure and encrypted
- Test with small amounts first
use std::env;
let rpc_url = env::var("STARKNET_RPC_URL").expect("STARKNET_RPC_URL not set");
let account_address = env::var("ACCOUNT_ADDRESS").expect("ACCOUNT_ADDRESS not set");
let private_key = env::var("PRIVATE_KEY").expect("PRIVATE_KEY not set");
let mut swapper = AutoSwappr::config(
rpc_url,
account_address,
private_key,
"0x05582ad635c43b4c14dbfa53cbde0df32266164a0d1b36e5b510e5b34aeb364b".to_string(),
).unwrap();- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
For support and questions, please open an issue on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.
- AutoSwappr TypeScript SDK - Original TypeScript implementation