Files
lez-programs/modules/amm/ffi/src/api/holding.rs
T
r4bbit 64e7614e74 refactor(amm): remove the dead newPosition quote path
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).
2026-08-11 17:51:51 +02:00

60 lines
1.5 KiB
Rust

use nssa_core::{account::AccountId, program::ProgramId};
use token_core::TokenHolding;
use crate::account::{decode_account, AccountRead};
#[derive(Clone)]
pub(super) struct SelectedHolding {
pub(super) id: AccountId,
pub(super) definition_id: AccountId,
pub(super) balance: u128,
}
pub(super) fn wallet_holdings(
reads: &[AccountRead],
token_program: ProgramId,
) -> Vec<SelectedHolding> {
reads
.iter()
.filter_map(|read| decode_fungible_holding(read, token_program).ok())
.collect()
}
pub(super) fn decode_fungible_holding(
read: &AccountRead,
token_program: ProgramId,
) -> Result<SelectedHolding, String> {
let (id, account) = decode_account(read)?;
if account.program_owner != token_program {
return Err(String::from("holding owner mismatch"));
}
let TokenHolding::Fungible {
definition_id,
balance,
} = TokenHolding::try_from(&account.data)
.map_err(|_| String::from("invalid fungible holding"))?
else {
return Err(String::from("invalid fungible holding"));
};
Ok(SelectedHolding {
id,
definition_id,
balance,
})
}
pub(super) fn select_holding(
holdings: &[SelectedHolding],
definition_id: AccountId,
) -> Option<SelectedHolding> {
holdings
.iter()
.filter(|holding| holding.definition_id == definition_id)
.max_by(|left, right| {
left.balance
.cmp(&right.balance)
.then_with(|| right.id.cmp(&left.id))
})
.cloned()
}