A Rust implementation using ethers-rs to interact with SpookySwap Brew contracts (currently migrated to Sonic). This tool allows you to automate the brewing process of BOO tokens from LP pairs.
This program serves as a basic template/reference implementation. Users should modify and optimize the code according to their specific brewing strategies. The default implementation is not necessarily optimal for all use cases.
- Rust toolchain (1.56.0 or later)
- Valid wallet private key
- Access to a Sonic network RPC endpoint
jq
command tools
# For Ubuntu/Debian
sudo apt-get install jq
# For MacOS
brew install jq
- Clone the repository:
git clone https://github.com/heronimus/spookybrew-ethers-rs.git
cd spookybrew-ethers-rs
-
Configure your environment:
- Update
config.json
with appropriate contract addresses (current default is valid SpookyBrewV2 contract on Sonic) - Choose or implement your brewing strategy (see Strategies section below)
- Update
-
Build the project:
make build
- Run the program:
./target/release/spookybrew_simple -k YOUR_PRIVATE_KEY_FILE_PATH -p YOUR_RPC_ENDPOINT -v v2
Update config.json
to match your target contract addresses:
{
"contracts": {
"brewboo_v2": {
"address": "0xc3815bF058fB94243Ebc6c559dfc59ceaEeF00eA",
"abi_path": "src/abi/brewboo_v2.json"
},
"brewboo_v3": {
"address": "0x79710d58c3600401fe21e799ff97f37100c8b179",
"abi_path": "src/abi/brewboo_v3.json"
}
}
}
The project comes with a SimpleStrategy
that handles the wS/USDC.e pair by default.
To create a new strategy:
- Create a new file in
src/strategies/
(e.g.,custom_strategy.rs
) - Implement the
Strategy
trait:
use super::types::{Strategy, LiquidityPoolStrategy};
use ethers::prelude::*;
pub struct CustomStrategy {
pairs: Vec<LiquidityPoolStrategy>,
}
impl CustomStrategy {
pub fn new() -> Self {
// Define your LP pairs here
let pairs = vec![
LiquidityPoolStrategy {
token_a: "TOKEN_A_ADDRESS".parse().expect("Invalid token A address"),
token_b: "TOKEN_B_ADDRESS".parse().expect("Invalid token B address"),
amount: None, // Or Some(amount) for specific amounts
},
// Extend pairs with additional entries or populate from external data sources like price APIs
];
Self { pairs }
}
}
impl Strategy for CustomStrategy {
fn get_pairs(&self) -> Vec<StrategyPair> {
self.pairs.clone()
}
fn name(&self) -> &str {
"Custom Strategy Name"
}
fn description(&self) -> &str {
"Description of your strategy"
}
}
- Register your strategy in
src/strategies/mod.rs
:
mod custom_strategy;
pub use custom_strategy::CustomStrategy;
- Use your strategy in the brew handler:
async fn brew_v2(
contract: BrewBooV2<SignerMiddleware<Provider<Http>, LocalWallet>>,
client: SignerClient,
) -> Result<()> {
let strategy = CustomStrategy::new();
// ... rest of the implementation
}
This template can be enhanced in several ways:
- Gas Optimization: Implement dynamic gas price calculation
- Strategy Enhancements:
- Add strategy configuration via config files
- Implement timing-based strategies
- Create sophisticated routing strategies
- Monitoring: Add logging and monitoring capabilities
- Testing: Add comprehensive tests for strategies
Contributions are welcome! Please feel free to submit pull requests or create issues for bugs and feature requests.
When contributing new strategies:
- Ensure your strategy is well-documented
- Include any specific configuration requirements
- Add tests for your strategy
- Update the README with strategy details if needed
- This is experimental software and comes with no warranties or guarantees
- Always test with small amounts first
- Verify all transactions before signing
- Keep your private keys secure