mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-08-25 14:11:09 +00:00
refactor(modules/amm): rename swap_plan to swap_exact_in_plan
Rename the swap-submission planning op for symmetry with the exact-in/exact-out split already applied to the quote ops (swap_exact_in_quote / swap_exact_out_quote): swap_plan -> swap_exact_in_plan, SwapPlanRequest -> SwapExactInPlanRequest, and the C export amm_swap_plan -> amm_swap_exact_in_plan (cbindgen header regenerated). The module's swapExactInput call site and trace are updated to match.
This commit is contained in:
@@ -36,7 +36,7 @@ char *amm_swap_exact_in_quote(const char *request_json);
|
||||
|
||||
char *amm_swap_exact_out_quote(const char *request_json);
|
||||
|
||||
char *amm_swap_plan(const char *request_json);
|
||||
char *amm_swap_exact_in_plan(const char *request_json);
|
||||
|
||||
char *amm_program_id(const char *request_json);
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ use std::{error::Error, fmt};
|
||||
|
||||
pub use request::{
|
||||
ConfigIdRequest, ContextRequest, PairIdsRequest, PairSnapshot, PlanRequest, PoolIdRequest,
|
||||
PositionRequest, ProgramIdRequest, QuoteRequest, ResolvePoolRequest, SwapExactInQuoteRequest,
|
||||
SwapExactOutQuoteRequest, SwapPairRequest, SwapPlanRequest, TokenIdsRequest,
|
||||
PositionRequest, ProgramIdRequest, QuoteRequest, ResolvePoolRequest, SwapExactInPlanRequest,
|
||||
SwapExactInQuoteRequest, SwapExactOutQuoteRequest, SwapPairRequest, TokenIdsRequest,
|
||||
};
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -119,8 +119,8 @@ pub fn swap_exact_out_quote(request: SwapExactOutQuoteRequest) -> AmmResult {
|
||||
}
|
||||
|
||||
/// Builds the `SwapExactInput` wallet submission for a token pair.
|
||||
pub fn swap_plan(request: SwapPlanRequest) -> AmmResult {
|
||||
swap::swap_plan(request).map_err(Into::into)
|
||||
pub fn swap_exact_in_plan(request: SwapExactInPlanRequest) -> AmmResult {
|
||||
swap::swap_exact_in_plan(request).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Derives the AMM `ProgramId` (Image ID) from a deployed program binary.
|
||||
|
||||
@@ -101,7 +101,7 @@ pub struct PoolIdRequest {
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SwapPlanRequest {
|
||||
pub struct SwapExactInPlanRequest {
|
||||
pub amm_program_id: String,
|
||||
pub token_in_id: String,
|
||||
pub token_out_id: String,
|
||||
|
||||
@@ -13,8 +13,8 @@ use serde_json::{json, Value};
|
||||
|
||||
use super::{
|
||||
pair::{derive_pair, is_canonical_pair},
|
||||
PoolIdRequest, ProgramIdRequest, ResolvePoolRequest, SwapExactInQuoteRequest,
|
||||
SwapExactOutQuoteRequest, SwapPairRequest, SwapPlanRequest,
|
||||
PoolIdRequest, ProgramIdRequest, ResolvePoolRequest, SwapExactInPlanRequest,
|
||||
SwapExactInQuoteRequest, SwapExactOutQuoteRequest, SwapPairRequest,
|
||||
};
|
||||
use crate::account::{
|
||||
account_id_from_hex, account_id_hex, decode_account, parse_program_id, program_id_bytes,
|
||||
@@ -271,7 +271,7 @@ pub(super) fn swap_exact_out_quote(request: SwapExactOutQuoteRequest) -> Result<
|
||||
/// order (vaults canonical, only the user's input holding signs) and the
|
||||
/// instruction words (`risc0_zkvm::serde` — the same encoding the guest
|
||||
/// decodes). Mirrors `plan.rs`'s `ready` output shape.
|
||||
pub(super) fn swap_plan(request: SwapPlanRequest) -> Result<Value, String> {
|
||||
pub(super) fn swap_exact_in_plan(request: SwapExactInPlanRequest) -> Result<Value, String> {
|
||||
let amm_program = parse_program_id(&request.amm_program_id)?;
|
||||
let token_in = account_id_from_hex(&request.token_in_id, "token in id")?;
|
||||
let token_out = account_id_from_hex(&request.token_out_id, "token out id")?;
|
||||
@@ -424,7 +424,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(pair, expected);
|
||||
|
||||
let plan = swap_plan(SwapPlanRequest {
|
||||
let plan = swap_exact_in_plan(SwapExactInPlanRequest {
|
||||
amm_program_id: program,
|
||||
token_in_id: same.clone(),
|
||||
token_out_id: same,
|
||||
|
||||
@@ -7,8 +7,8 @@ use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use crate::api::{
|
||||
self, AmmApiError, AmmResult, ConfigIdRequest, ContextRequest, PairIdsRequest, PlanRequest,
|
||||
PoolIdRequest, ProgramIdRequest, QuoteRequest, ResolvePoolRequest, SwapExactInQuoteRequest,
|
||||
SwapExactOutQuoteRequest, SwapPairRequest, SwapPlanRequest, TokenIdsRequest,
|
||||
PoolIdRequest, ProgramIdRequest, QuoteRequest, ResolvePoolRequest, SwapExactInPlanRequest,
|
||||
SwapExactInQuoteRequest, SwapExactOutQuoteRequest, SwapPairRequest, TokenIdsRequest,
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -133,8 +133,8 @@ pub extern "C" fn amm_swap_exact_out_quote(request_json: *const c_char) -> *mut
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn amm_swap_plan(request_json: *const c_char) -> *mut c_char {
|
||||
call::<SwapPlanRequest>(request_json, api::swap_plan)
|
||||
pub extern "C" fn amm_swap_exact_in_plan(request_json: *const c_char) -> *mut c_char {
|
||||
call::<SwapExactInPlanRequest>(request_json, api::swap_exact_in_plan)
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
|
||||
@@ -7,9 +7,9 @@ pub mod api;
|
||||
|
||||
pub use api::{
|
||||
config_id, context, pair_ids, plan, pool_id, program_id, quote, resolve_pool,
|
||||
swap_exact_in_quote, swap_exact_out_quote, swap_pair, swap_plan, token_ids, AccountRead,
|
||||
AmmApiError, AmmResponse, AmmResult, ConfigIdRequest, ContextRequest, PairIdsRequest,
|
||||
PairSnapshot, PlanRequest, PoolIdRequest, PositionRequest, ProgramIdRequest, QuoteRequest,
|
||||
ResolvePoolRequest, SwapExactInQuoteRequest, SwapExactOutQuoteRequest, SwapPairRequest,
|
||||
SwapPlanRequest, TokenIdsRequest, WalletAccount,
|
||||
swap_exact_in_plan, swap_exact_in_quote, swap_exact_out_quote, swap_pair, token_ids,
|
||||
AccountRead, AmmApiError, AmmResponse, AmmResult, ConfigIdRequest, ContextRequest,
|
||||
PairIdsRequest, PairSnapshot, PlanRequest, PoolIdRequest, PositionRequest, ProgramIdRequest,
|
||||
QuoteRequest, ResolvePoolRequest, SwapExactInPlanRequest, SwapExactInQuoteRequest,
|
||||
SwapExactOutQuoteRequest, SwapPairRequest, TokenIdsRequest, WalletAccount,
|
||||
};
|
||||
|
||||
@@ -609,9 +609,9 @@ std::string AmmModuleImpl::swapExactInput(const std::string& def_a_hex,
|
||||
return {};
|
||||
}
|
||||
|
||||
// amm_swap_plan resolves the pool, reorders holdings to the pool's canonical
|
||||
// def order, encodes SwapExactInput, and returns a ready-to-submit plan.
|
||||
const FfiResult planResult = call(amm_swap_plan, json{
|
||||
// amm_swap_exact_in_plan resolves the pool, reorders holdings to the pool's
|
||||
// canonical def order, encodes SwapExactInput, and returns a ready-to-submit plan.
|
||||
const FfiResult planResult = call(amm_swap_exact_in_plan, json{
|
||||
{"ammProgramId", net.amm_program_id},
|
||||
{"tokenInId", def_a_hex},
|
||||
{"tokenOutId", def_b_hex},
|
||||
@@ -623,7 +623,7 @@ std::string AmmModuleImpl::swapExactInput(const std::string& def_a_hex,
|
||||
{"deadlineMs", deadline_decimal},
|
||||
});
|
||||
if (!planResult.ok || jStr(planResult.value, "status") != "ready") {
|
||||
AMM_TRACE("swapExactInput: FAIL amm_swap_plan not ready");
|
||||
AMM_TRACE("swapExactInput: FAIL amm_swap_exact_in_plan not ready");
|
||||
return {};
|
||||
}
|
||||
const json plan = planResult.value;
|
||||
|
||||
Reference in New Issue
Block a user