diff --git a/Cargo.lock b/Cargo.lock index 93c11be13b5..2c6cfcd6ef0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8128,16 +8128,24 @@ dependencies = [ name = "spl-math" version = "0.3.0" dependencies = [ - "borsh 1.5.1", "libm", - "num-derive", "num-traits", "proptest", + "uint", +] + +[[package]] +name = "spl-math-example" +version = "0.1.0" +dependencies = [ + "borsh 1.5.1", + "num-derive", + "num-traits", "solana-program", "solana-program-test", "solana-sdk", + "spl-math", "thiserror", - "uint", ] [[package]] @@ -8369,7 +8377,6 @@ dependencies = [ "solana-sdk", "solana-security-txt", "solana-vote-program", - "spl-math", "spl-pod 0.4.0", "spl-token 6.0.0", "spl-token-2022 5.0.2", diff --git a/Cargo.toml b/Cargo.toml index e5db1081db4..a2ca9427310 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/libraries/math-example/Cargo.toml b/libraries/math-example/Cargo.toml new file mode 100644 index 00000000000..2bf3618c64d --- /dev/null +++ b/libraries/math-example/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "spl-math-example" +version = "0.1.0" +description = "Solana Program Library Math Example" +authors = ["Solana Labs Maintainers "] +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"] diff --git a/libraries/math-example/README.md b/libraries/math-example/README.md new file mode 100644 index 00000000000..2035ce0c8f0 --- /dev/null +++ b/libraries/math-example/README.md @@ -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. diff --git a/libraries/math/Xargo.toml b/libraries/math-example/Xargo.toml similarity index 100% rename from libraries/math/Xargo.toml rename to libraries/math-example/Xargo.toml diff --git a/libraries/math/src/entrypoint.rs b/libraries/math-example/src/entrypoint.rs similarity index 100% rename from libraries/math/src/entrypoint.rs rename to libraries/math-example/src/entrypoint.rs diff --git a/libraries/math/src/error.rs b/libraries/math-example/src/error.rs similarity index 100% rename from libraries/math/src/error.rs rename to libraries/math-example/src/error.rs diff --git a/libraries/math/src/instruction.rs b/libraries/math-example/src/instruction.rs similarity index 100% rename from libraries/math/src/instruction.rs rename to libraries/math-example/src/instruction.rs diff --git a/libraries/math-example/src/lib.rs b/libraries/math-example/src/lib.rs new file mode 100644 index 00000000000..e0162970628 --- /dev/null +++ b/libraries/math-example/src/lib.rs @@ -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"); diff --git a/libraries/math/src/processor.rs b/libraries/math-example/src/processor.rs similarity index 100% rename from libraries/math/src/processor.rs rename to libraries/math-example/src/processor.rs diff --git a/libraries/math/tests/instruction_count.rs b/libraries/math-example/tests/instruction_count.rs similarity index 99% rename from libraries/math/tests/instruction_count.rs rename to libraries/math-example/tests/instruction_count.rs index 921c0319f63..93025ad86cd 100644 --- a/libraries/math/tests/instruction_count.rs +++ b/libraries/math-example/tests/instruction_count.rs @@ -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] diff --git a/libraries/math/Cargo.toml b/libraries/math/Cargo.toml index eefe4bb8a22..72bf60c978e 100644 --- a/libraries/math/Cargo.toml +++ b/libraries/math/Cargo.toml @@ -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"] diff --git a/libraries/math/src/lib.rs b/libraries/math/src/lib.rs index 3e9c5ba83b4..54c5a430917 100644 --- a/libraries/math/src/lib.rs +++ b/libraries/math/src/lib.rs @@ -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"); diff --git a/stake-pool/program/Cargo.toml b/stake-pool/program/Cargo.toml index ad4c5c35550..622f6f4ad36 100644 --- a/stake-pool/program/Cargo.toml +++ b/stake-pool/program/Cargo.toml @@ -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", ] } diff --git a/token-swap/program/Cargo.toml b/token-swap/program/Cargo.toml index fc880f3a9f5..e86e75c8f38 100644 --- a/token-swap/program/Cargo.toml +++ b/token-swap/program/Cargo.toml @@ -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" diff --git a/token-swap/program/fuzz/Cargo.toml b/token-swap/program/fuzz/Cargo.toml index 4d010363edf..e565e75d0f0 100644 --- a/token-swap/program/fuzz/Cargo.toml +++ b/token-swap/program/fuzz/Cargo.toml @@ -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"] }