Files
lez-programs/modules/amm/ffi/tests/public_api.rs
r4bbit 526d50bff1 feat(modules/amm): add createPool quote + plan ops and module methods
Bring pool creation onto the redesigned lean module surface
  mirroring the shipped swap vertical.

  FFI (amm_ffi):
  - amm_liquidity_quote: a pure create-pool preview from the two deposit
    amounts — expectedLpRaw / initialPriceRaw / lockedLpRaw via the shared
    amm_core opening-LP math (isqrt_product, MINIMUM_LIQUIDITY,
    spot_price_q64_64), so the preview equals what new_definition mints. No
    chain reads, no quoteHash, and no fee input (the fee is neither part of the
    pool PDA nor the pricing — one pool per pair).
  - amm_create_pool_plan: canonicalizes the pair, moving amounts and user
    holdings as one unit so each (vault, holding, amount) triple names the same
    token, then emits the fixed 11-account NewDefinition plan (only the user
    a/b and fresh LP holdings sign).

  Module (AmmModuleImpl):
  - liquidityQuote(request): thin preview wrapper, normalizes ids to hex.
  - createPool(request, fresh_lp_id): a new pool always needs a fresh LP
    holding, so an empty fresh_lp_id returns requiresFreshLp without
    submitting; otherwise builds the plan and submits, returning a hex
    transactionId.
2026-08-11 12:04:47 +02:00

33 lines
1.2 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),
amount_a_raw: Some("1000000".into()),
amount_b_raw: Some("4000000".into()),
})
.expect("a valid pure create-pool quote should succeed");
assert_eq!(quote["amountARaw"], "1000000");
let _plan: fn(CreatePoolPlanRequest) -> AmmResult = create_pool_plan;
}