Files
lez-programs/modules/amm/ffi/tests/public_api.rs
r4bbit 1513091b98 feat(amm): drive the create-pool liquidity preview from liquidityQuote
Both liquidity branches now quote through the lean composable ops. The create
path joins the add path (already on addLiquidityQuote) by reworking
liquidity_quote into a dual-mode create quote and wiring the form to it via
the resolvePool pool read. quoteNewPosition/amm_quote are no longer reached
from the UI.

FFI (modules/amm/ffi):
- liquidity_quote is dual-mode: price-only (initialPriceRealRaw, no amounts)
  returns the minimum opening deposit via minimum_opening_pair; supplied
  amounts return the actual deposit with the price derived from them. Emits
  actual/minimum amounts, expectedLp, lockedLp and the Q64.64 price.
- LiquidityQuoteRequest gains initial_price_real_raw (Option<String>, needed
  only in price-only mode).

Module (modules/amm/src):
- liquidityQuote forwards initialPriceRealRaw to the op.

UI (apps/amm/qml):
- Route create-vs-add on the pool read (resolvePool -> poolExists); create
  quotes via liquidityQuote, assembled into the missing-pool shape the form
  already consumes.
- poolStatus moves off the quote onto the flow's poolExists; the form derives
  activePool/missingPool from it. Trim the vestigial quote fields (canSubmit,
  requiresFreshLp, warnings, errors[], accountPreview, the "Pool" row) and drop
  the account-plan panel for parity with the swap view.
- Fix a real bug: a pair change now resets poolExists (resetPoolExistence) so
  resetPairDraft re-resolves the pool like a fresh selection. Otherwise an
  active pool kept stale (cleared) reserves with no re-quote, and the deposit
  ratio-fill silently no-op'd.

Tests (apps/amm/tests):
- Read activePool instead of the removed poolStatus. The add test waits for the
  reset's active-pool quote to settle (reserves reloaded) before the ratio-fill;
  the create test resets the draft to clear leftover cross-run amounts and the
  stale submitted transactionId.
2026-08-11 15:18:20 +02:00

34 lines
1.3 KiB
Rust

use amm_ffi::{
config_id, create_pool_plan, liquidity_quote, AmmResult, ConfigIdRequest,
CreatePoolPlanRequest, LiquidityQuoteRequest,
};
#[test]
fn direct_rust_api_does_not_require_ffi() {
let response = config_id(ConfigIdRequest {
amm_program_id: "0000000000000000000000000000000000000000000000000000000000000000".into(),
})
.expect("valid program ID should produce a response");
assert_eq!(response["status"], "ok");
assert!(response["configId"].is_string());
}
// The create-pool surface must be reachable from the crate root too — Rust callers import from
// `amm_ffi::`, not `amm_ffi::api`. liquidity_quote is a pure preview, so exercise it directly;
// create_pool_plan needs chain reads, so a typed reference is enough to pin the re-export.
#[test]
fn create_pool_surface_is_reexported_from_crate_root() {
let quote = liquidity_quote(LiquidityQuoteRequest {
token_a_id: "11".repeat(32),
token_b_id: "22".repeat(32),
initial_price_real_raw: None, // amounts supplied ⇒ the op derives the price
amount_a_raw: Some("1000000".into()),
amount_b_raw: Some("4000000".into()),
})
.expect("a valid pure create-pool quote should succeed");
assert_eq!(quote["actualAmountARaw"], "1000000");
let _plan: fn(CreatePoolPlanRequest) -> AmmResult = create_pool_plan;
}