Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ members = [
"programs/amm/core",
"programs/amm",
"programs/amm/methods",
"programs/amm/client-ffi",
"programs/ata/core",
"programs/ata",
"programs/ata/methods",
Expand Down
3 changes: 2 additions & 1 deletion apps/amm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ logos_module(
src/AmmClient.cpp
src/NewPositionRuntime.h
src/NewPositionRuntime.cpp
src/SwapRuntime.h
src/SwapRuntime.cpp
FIND_PACKAGES
Qt6Gui
LINK_LIBRARIES
Expand All @@ -49,7 +51,6 @@ logos_module(
LINK_TARGETS
logos_wallet_access
EXTERNAL_LIBS
amm_client_ffi
amm_client
)

Expand Down
4 changes: 4 additions & 0 deletions apps/amm/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ borsh = { workspace = true }
clock_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0" }
hex = "0.4"
nssa_core = { workspace = true }
risc0-binfmt = { version = "=3.0.4", default-features = false }
risc0-zkvm = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = "0.10"
token_core = { workspace = true }
twap_oracle_core = { workspace = true }

[build-dependencies]
cbindgen = "0.28"

[dev-dependencies]
pretty_assertions = "1"
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ fn main() {
std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set by cargo");
cbindgen::generate(&crate_dir)
.expect("cbindgen")
.write_to_file(format!("{crate_dir}/amm_client_ffi.h"));
println!("cargo:rerun-if-changed=src/lib.rs");
.write_to_file(format!("{crate_dir}/include/amm_client.h"));
println!("cargo:rerun-if-changed=src");
println!("cargo:rerun-if-changed=cbindgen.toml");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language = "C"
include_guard = "AMM_CLIENT_FFI_H"
include_guard = "AMM_CLIENT_H"
pragma_once = true
cpp_compat = true
autogen_warning = "/* Generated by cbindgen. Do not edit. */"

[export]
Expand Down
37 changes: 33 additions & 4 deletions apps/amm/client/include/amm_client.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
#ifndef AMM_CLIENT_H
#define AMM_CLIENT_H

#pragma once

/* Generated by cbindgen. Do not edit. */

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif
#endif // __cplusplus

char *amm_config_id(const char *request_json);

char *amm_token_ids(const char *request_json);

char *amm_pair_ids(const char *request_json);

char *amm_context(const char *request_json);

char *amm_quote(const char *request_json);

char *amm_plan(const char *request_json);

char *amm_swap_pair(const char *request_json);

char *amm_resolve_pool(const char *request_json);

char *amm_swap_plan(const char *request_json);

char *amm_program_id(const char *request_json);

/**
* Releases a string returned by an `amm_*` operation.
*
* # Safety
* `value` must be null or a pointer returned by this library that has not been freed.
*/
void amm_free(char *value);

#ifdef __cplusplus
}
#endif
} // extern "C"
#endif // __cplusplus

#endif
#endif /* AMM_CLIENT_H */

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THe changes in this file are here because the headers are not autogenerated (this was also done in the amm_client ffi from the swap fuctionality PR)

24 changes: 23 additions & 1 deletion apps/amm/client/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod position;
mod quote;
mod quote_error;
mod request;
mod swap;

#[cfg(test)]
mod tests;
Expand All @@ -21,7 +22,8 @@ use std::{error::Error, fmt};

pub use request::{
ConfigIdRequest, ContextRequest, PairIdsRequest, PairSnapshot, PlanRequest, PositionRequest,
QuoteRequest, TokenIdsRequest,
ProgramIdRequest, QuoteRequest, ResolvePoolRequest, SwapPairRequest, SwapPlanRequest,
TokenIdsRequest,
};
use serde_json::Value;

Expand Down Expand Up @@ -95,3 +97,23 @@ pub fn quote(request: QuoteRequest) -> AmmResult {
pub fn plan(request: PlanRequest) -> AmmResult {
plan::plan(request).map_err(Into::into)
}

/// Derives the canonical account ids for a swap pair (tokens in either order).
pub fn swap_pair(request: SwapPairRequest) -> AmmResult {
swap::swap_pair(request).map_err(Into::into)
}

/// Decodes a pool account: existence, reserves (canonical order), fee tier.
pub fn resolve_pool(request: ResolvePoolRequest) -> AmmResult {
swap::resolve_pool(request).map_err(Into::into)
}

/// Builds the `SwapExactInput` wallet submission for a token pair.
pub fn swap_plan(request: SwapPlanRequest) -> AmmResult {
swap::swap_plan(request).map_err(Into::into)
}

/// Derives the AMM `ProgramId` (Image ID) from a deployed program binary.
pub fn program_id(request: ProgramIdRequest) -> AmmResult {
swap::program_id(request).map_err(Into::into)
}
35 changes: 35 additions & 0 deletions apps/amm/client/src/api/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,41 @@ pub struct PairIdsRequest {
pub token_b_id: String,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SwapPairRequest {
pub amm_program_id: String,
pub token_in_id: String,
pub token_out_id: String,
pub config: AccountRead,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ResolvePoolRequest {
pub pool: AccountRead,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SwapPlanRequest {
pub amm_program_id: String,
pub token_in_id: String,
pub token_out_id: String,
pub config: AccountRead,
pub user_input_holding_id: String,
pub user_output_holding_id: String,
pub amount_in: String,
pub min_out: String,
pub deadline_ms: String,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ProgramIdRequest {
pub elf: String,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct PositionRequest {
Expand Down
Loading
Loading