Skip to content

Commit

Permalink
Extract spl-math-utils from spl-math (#7421)
Browse files Browse the repository at this point in the history
* extract math-utils from spl-math

* newline

* replace spl-math with spl-math-utils in spl-token-swap

* remove now-unused deps from spl-math

* remove spl-math from stake-pool deps (it was already unused)

* fix math-utils dep in spl-token-swap-fuzz

* moce crate dirs

* make spl-math the library crate and spl-math-example the program crate
  • Loading branch information
kevinheavey authored Oct 31, 2024
1 parent 356ef02 commit d0f238f
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 34 deletions.
15 changes: 11 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ members = [
"libraries/discriminator",
"libraries/concurrent-merkle-tree",
"libraries/math",
"libraries/math-example",
"libraries/merkle-tree-reference",
"libraries/pod",
"libraries/program-error",
Expand Down
31 changes: 31 additions & 0 deletions libraries/math-example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "spl-math-example"
version = "0.1.0"
description = "Solana Program Library Math Example"
authors = ["Solana Labs Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana-program-library"
license = "Apache-2.0"
edition = "2021"

[features]
no-entrypoint = []
test-sbf = []

[dependencies]
borsh = "1.5.1"
num-derive = "0.4"
num-traits = "0.2"
solana-program = "2.1.0"
spl-math = { path = "../math", version = "0.3.0" }
thiserror = "1.0"

[dev-dependencies]
solana-program-test = "2.1.0"
solana-sdk = "2.1.0"

[lib]
crate-type = ["cdylib", "lib"]


[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
8 changes: 8 additions & 0 deletions libraries/math-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Math

Program wrapper around the spl-math-utils crate. The program exists for testing purposes.

## Audit

The repository [README](https://github.com/solana-labs/solana-program-library#audits)
contains information about program audits.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions libraries/math-example/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Math operations using unsigned integers
#![deny(missing_docs)]
#![forbid(unsafe_code)]

mod entrypoint;
pub mod error;
pub mod instruction;
pub mod processor;

pub use spl_math::{approximations, checked_ceil_div, precise_number, uint};

solana_program::declare_id!("Math111111111111111111111111111111111111111");
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use {
solana_program_test::*,
solana_sdk::{signature::Signer, transaction::Transaction},
spl_math::{id, instruction, processor::process_instruction},
spl_math_example::{id, instruction, processor::process_instruction},
};

#[tokio::test]
Expand Down
14 changes: 0 additions & 14 deletions libraries/math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,13 @@ repository = "https://github.com/solana-labs/solana-program-library"
license = "Apache-2.0"
edition = "2021"

[features]
no-entrypoint = []
test-sbf = []

[dependencies]
borsh = "1.5.1"
num-derive = "0.4"
num-traits = "0.2"
solana-program = "2.1.0"
thiserror = "1.0"
uint = "0.10"

[dev-dependencies]
proptest = "1.5.0"
solana-program-test = "2.1.0"
solana-sdk = "2.1.0"
libm = "0.2.11"

[lib]
crate-type = ["cdylib", "lib"]


[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
11 changes: 1 addition & 10 deletions libraries/math/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
//! Math operations using unsigned integers
#![deny(missing_docs)]
#![forbid(unsafe_code)]
//! Math utilities.
pub mod approximations;
pub mod checked_ceil_div;
mod entrypoint;
pub mod error;
pub mod instruction;
pub mod precise_number;
pub mod processor;
pub mod uint;

solana_program::declare_id!("Math111111111111111111111111111111111111111");
3 changes: 0 additions & 3 deletions stake-pool/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ serde = "1.0.214"
serde_derive = "1.0.103"
solana-program = "2.1.0"
solana-security-txt = "1.1.1"
spl-math = { version = "0.3", path = "../../libraries/math", features = [
"no-entrypoint",
] }
spl-pod = { version = "0.4.0", path = "../../libraries/pod", features = [
"borsh",
] }
Expand Down
2 changes: 1 addition & 1 deletion token-swap/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum_dispatch = "0.3.13"
num-derive = "0.4"
num-traits = "0.2"
solana-program = "2.1.0"
spl-math = { version = "0.3", path = "../../libraries/math", features = [ "no-entrypoint" ] }
spl-math = { version = "0.3", path = "../../libraries/math" }
spl-token = { version = "6.0", path = "../../token/program", features = [ "no-entrypoint" ] }
spl-token-2022 = { version = "5.0.2", path = "../../token/program-2022", features = [ "no-entrypoint" ] }
thiserror = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion token-swap/program/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ publish = false
honggfuzz = { version = "0.5.56" }
arbitrary = { version = "1.3", features = ["derive"] }
solana-program = "2.1.0"
spl-math = { version = "0.3", path = "../../../libraries/math", features = [ "no-entrypoint" ] }
spl-math = { version = "0.3", path = "../../../libraries/math" }
spl-token = { version = "6.0", path = "../../../token/program", features = [ "no-entrypoint" ] }
spl-token-swap = { path = "..", features = ["fuzz", "no-entrypoint"] }

Expand Down

0 comments on commit d0f238f

Please sign in to comment.