cotyledon 0.1.0

Framework for writing sprouts — sandboxed, event-driven on-chain trading bots.
Documentation
//! Jupiter swap plugin (official, behind the `jupiter` feature).

use crate::{Ctx, Receipt, Result, Usd, Wallet};

/// Buy `amount` (USD) of `token` via a Jupiter swap.
pub async fn buy(ctx: &Ctx, wallet: &Wallet, token: &str, amount: Usd) -> Result<Receipt> {
    swap(ctx, wallet, token, amount, Side::Buy).await
}

/// Sell `amount` (USD) of `token` via a Jupiter swap.
pub async fn sell(ctx: &Ctx, wallet: &Wallet, token: &str, amount: Usd) -> Result<Receipt> {
    swap(ctx, wallet, token, amount, Side::Sell).await
}

enum Side {
    Buy,
    Sell,
}

async fn swap(
    _ctx: &Ctx,
    _wallet: &Wallet,
    _token: &str,
    _amount: Usd,
    _side: Side,
) -> Result<Receipt> {
    // TODO: fetch a route, build the swap tx, `wallet.sign(..)`, then
    // `ctx.rpc().submit_tx(..)` and return the resulting `Receipt`.
    todo!("jupiter swap")
}