mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-08-26 14:41:12 +00:00
Both liquidity branches now quote through the lean ops (liquidityQuote /
addLiquidityQuote), so quoteNewPosition and the heavy amm_quote machinery it
drove are unreachable. Remove them end to end.
FFI (modules/amm/ffi):
- Drop the amm_quote entry point and the whole quote-evaluation graph:
api/{accounts,commitment,funding,position}.rs, the QuoteRequest /
PositionRequest / PairSnapshot request types, quote_error::fatal_quote, and
api/clock.rs (its decode_clock was quote-only). quote.rs keeps only the shared
opening-deposit math (minimum_opening_pair + helpers) that liquidity_quote
reuses.
- Trim the fields the quote path was the sole reader of: SelectedHolding.account
and PairIds.{token_program,twap_program}.
- Drop the quote-path unit tests; keep the math / pair / context / holding /
swap ones (37 pass, clippy clean).
Module (modules/amm/src):
- Remove AmmModuleImpl::quoteNewPosition and its buildQuoteInput snapshot helper.
App (apps/amm):
- Remove the AmmUiBackend quoteNewPosition slot (.rep/.h/.cpp) and the dead QML
backend mock + obsolete fresh-quote test.
- finishSubmitFailure no longer keeps a submit-returned re-quote (the lean submit
ops never return one); it always re-quotes on failure.
- submissionSnapshot drops the always-empty quoteHash and derives the confirm
dialog's action from the resolved pool state instead of the dead
quotePayload.instruction (restores the "Create pool" / "Add liquidity" label).
145 lines
4.6 KiB
Rust
145 lines
4.6 KiB
Rust
//! Transport-independent AMM client operations.
|
|
|
|
mod config;
|
|
mod context;
|
|
mod holding;
|
|
mod liquidity;
|
|
mod pair;
|
|
mod quote;
|
|
mod quote_error;
|
|
mod request;
|
|
mod swap;
|
|
mod token_holdings;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
use std::{error::Error, fmt};
|
|
|
|
pub use request::{
|
|
AddLiquidityPlanRequest, AddLiquidityQuoteRequest, ConfigIdRequest, ContextRequest,
|
|
CreatePoolPlanRequest, LiquidityQuoteRequest, PairIdsRequest, PoolIdRequest, ProgramIdRequest,
|
|
ResolvePoolRequest, SwapExactInPlanRequest, SwapExactInQuoteRequest, SwapExactOutPlanRequest,
|
|
SwapExactOutQuoteRequest, SwapPairRequest, TokenHoldingsRequest, TokenIdsRequest,
|
|
};
|
|
use serde_json::Value;
|
|
|
|
pub use crate::account::{AccountRead, WalletAccount};
|
|
|
|
/// JSON response shared by direct Rust callers and transport adapters.
|
|
pub type AmmResponse = Value;
|
|
|
|
/// Result returned by AMM client operations.
|
|
pub type AmmResult = Result<AmmResponse, AmmApiError>;
|
|
|
|
/// Failure produced before an AMM response can be constructed.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct AmmApiError {
|
|
message: String,
|
|
}
|
|
|
|
impl AmmApiError {
|
|
/// Returns the stable human-readable failure detail.
|
|
#[must_use]
|
|
pub fn message(&self) -> &str {
|
|
&self.message
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for AmmApiError {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
formatter.write_str(&self.message)
|
|
}
|
|
}
|
|
|
|
impl Error for AmmApiError {}
|
|
|
|
impl From<String> for AmmApiError {
|
|
fn from(message: String) -> Self {
|
|
Self { message }
|
|
}
|
|
}
|
|
|
|
/// Derives the AMM configuration account ID.
|
|
pub fn config_id(request: ConfigIdRequest) -> AmmResult {
|
|
config::config_id(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Discovers token definition IDs available to the active wallet and app.
|
|
pub fn token_ids(request: TokenIdsRequest) -> AmmResult {
|
|
context::token_ids(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Derives canonical accounts for one token pair.
|
|
pub fn pair_ids(request: PairIdsRequest) -> AmmResult {
|
|
pair::pair_ids(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Builds network, token, holding, and fee-tier context.
|
|
pub fn context(request: ContextRequest) -> AmmResult {
|
|
context::context(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Derives the canonical account ids for a swap pair (tokens in either order).
|
|
pub fn swap_pair(request: SwapPairRequest) -> AmmResult {
|
|
swap::swap_pair(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Decodes a pool account: existence, reserves (canonical order), fee tier.
|
|
pub fn resolve_pool(request: ResolvePoolRequest) -> AmmResult {
|
|
swap::resolve_pool(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Derives the pool PDA for a pair — config-free, so a reader needn't load config.
|
|
pub fn pool_id(request: PoolIdRequest) -> AmmResult {
|
|
swap::pool_id(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Prices a `SwapExactInput`: expected output, slippage floor, and price impact.
|
|
pub fn swap_exact_in_quote(request: SwapExactInQuoteRequest) -> AmmResult {
|
|
swap::swap_exact_in_quote(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Prices a `SwapExactOutput`: required input, slippage ceiling, and price impact.
|
|
pub fn swap_exact_out_quote(request: SwapExactOutQuoteRequest) -> AmmResult {
|
|
swap::swap_exact_out_quote(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Builds the `SwapExactInput` wallet submission for a token pair.
|
|
pub fn swap_exact_in_plan(request: SwapExactInPlanRequest) -> AmmResult {
|
|
swap::swap_exact_in_plan(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Builds the `SwapExactOutput` wallet submission for a token pair.
|
|
pub fn swap_exact_out_plan(request: SwapExactOutPlanRequest) -> AmmResult {
|
|
swap::swap_exact_out_plan(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Prices a create-pool deposit: the LP the creator receives and the opening price.
|
|
pub fn liquidity_quote(request: LiquidityQuoteRequest) -> AmmResult {
|
|
liquidity::liquidity_quote(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Builds the `NewDefinition` submission for creating a pool.
|
|
pub fn create_pool_plan(request: CreatePoolPlanRequest) -> AmmResult {
|
|
liquidity::create_pool_plan(request).map_err(Into::into)
|
|
}
|
|
|
|
pub fn add_liquidity_quote(request: AddLiquidityQuoteRequest) -> AmmResult {
|
|
liquidity::add_liquidity_quote(request).map_err(Into::into)
|
|
}
|
|
|
|
pub fn add_liquidity_plan(request: AddLiquidityPlanRequest) -> AmmResult {
|
|
liquidity::add_liquidity_plan(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Lists the wallet's fungible token holdings for the account selector.
|
|
pub fn token_holdings(request: TokenHoldingsRequest) -> AmmResult {
|
|
token_holdings::token_holdings(request).map_err(Into::into)
|
|
}
|
|
|
|
/// Derives the AMM `ProgramId` (Image ID) from a deployed program binary.
|
|
pub fn program_id(request: ProgramIdRequest) -> AmmResult {
|
|
swap::program_id(request).map_err(Into::into)
|
|
}
|