#ifndef AMM_CLIENT_FFI_H #define AMM_CLIENT_FFI_H #pragma once /* Generated by cbindgen. Do not edit. */ #include #include #include #include /** * Heap-allocated buffer of RISC0 instruction words, returned across the C * boundary. Free with `amm_client_free_words`. */ typedef struct AmmWords { uint32_t *ptr; uintptr_t len; bool ok; } AmmWords; /** * C-ABI representation of `nssa_core::program::ProgramId` (an Image ID), * which is itself defined as `[u32; 8]`. Declared as a concrete array here * (rather than an alias through `nssa_core::program::ProgramId`) so * cbindgen — which only inspects this crate's source, not its * dependencies' — can emit a real typedef instead of an opaque, * self-referential `ProgramId` in the generated header. Since both are * plain type aliases to `[u32; 8]`, they remain interchangeable to rustc. */ typedef uint32_t ProgramId[8]; /** * C-ABI mirror of `pool::PoolView`. u128 fields are little-endian bytes. */ typedef struct FfiPoolView { uint8_t def_a[32]; uint8_t def_b[32]; uint8_t vault_a[32]; uint8_t vault_b[32]; uint8_t reserve_a[16]; uint8_t reserve_b[16]; uint8_t liquidity_supply[16]; uint32_t fees; bool ok; } FfiPoolView; /** * C-ABI mirror of `pool::ConfigView`. */ typedef struct FfiConfigView { uint32_t token_program_id[8]; uint32_t twap_oracle_program_id[8]; uint8_t authority[32]; bool ok; } FfiConfigView; /** * Builds the RISC0 instruction words for a `SwapExactInput`. `amount_in` and * `min_out` are little-endian encoded `u128` values (`[u8; 16]`). The * returned buffer must be freed with `amm_client_free_words`. * * # Safety * `amount_in` and `min_out` must be valid, non-null pointers to readable * memory of the indicated sizes. */ struct AmmWords amm_client_swap_words(const uint8_t (*amount_in)[16], const uint8_t (*min_out)[16], uint64_t deadline); /** * Frees a buffer previously returned by `amm_client_swap_words`. * * # Safety * `w` must be a value previously returned by `amm_client_swap_words` that * has not already been freed. */ void amm_client_free_words(struct AmmWords w); /** * Computes the `ProgramId` (Image ID) of a compiled guest ELF. Returns * `false` on an invalid ELF, leaving `out` unwritten. * * # Safety * `elf` must be valid for reads of `elf_len` bytes, and `out` must be a * valid, non-null pointer to writable memory for a `ProgramId`. */ bool amm_client_program_id_from_elf(const uint8_t *elf, uintptr_t elf_len, ProgramId *out); /** * Fills `out` with the AMM config PDA. * * # Safety * `amm` must be a valid, non-null pointer to a readable `ProgramId`, and * `out` must be a valid, non-null pointer to writable memory. */ void amm_client_config_pda(const ProgramId *amm, uint8_t (*out)[32]); /** * Fills `out` with the pool PDA for the two definition ids. * * # Safety * All pointer arguments must be valid, non-null, and point to readable (or, * for `out`, writable) memory of the indicated sizes. */ void amm_client_pool_pda(const ProgramId *amm, const uint8_t (*def_a)[32], const uint8_t (*def_b)[32], uint8_t (*out)[32]); /** * Fills `out` with the vault PDA for a pool + token definition. * * # Safety * All pointer arguments must be valid, non-null, and point to readable (or, * for `out`, writable) memory of the indicated sizes. */ void amm_client_vault_pda(const ProgramId *amm, const uint8_t (*pool)[32], const uint8_t (*def)[32], uint8_t (*out)[32]); /** * Fills `out` with the TWAP oracle current-tick PDA for a pool. * * # Safety * All pointer arguments must be valid, non-null, and point to readable (or, * for `out`, writable) memory of the indicated sizes. */ void amm_client_current_tick_pda(const ProgramId *twap, const uint8_t (*pool)[32], uint8_t (*out)[32]); /** * Decodes a `PoolDefinition` account's raw bytes into `out`. Returns `false` * on decode failure, leaving `out` unwritten. * * # Safety * `bytes` must be valid for reads of `len` bytes, and `out` must be a * valid, non-null pointer to writable memory for a `FfiPoolView`. */ bool amm_client_decode_pool(const uint8_t *bytes, uintptr_t len, struct FfiPoolView *out); /** * Decodes an `AmmConfig` account's raw bytes into `out`. Returns `false` on * decode failure, leaving `out` unwritten. * * # Safety * `bytes` must be valid for reads of `len` bytes, and `out` must be a * valid, non-null pointer to writable memory for a `FfiConfigView`. */ bool amm_client_decode_config(const uint8_t *bytes, uintptr_t len, struct FfiConfigView *out); #endif /* AMM_CLIENT_FFI_H */