Contracts for Sui 1.x
OpenZeppelin Contracts for Sui v1.x ships these core packages:
openzeppelin_mathfor deterministic integer arithmetic, configurable rounding, and decimal scaling.openzeppelin_fp_mathfor 9-decimal fixed-point arithmetic (UD30x9,SD29x9) backed byu128.openzeppelin_accessfor role-based authorization and ownership-transfer wrappers around privilegedkey + storeobjects.openzeppelin_utilsfor embeddable building blocks; its first module,rate_limiter, provides multi-strategy rate limiting.openzeppelin_salefor fixed-price token sales (presale / IDO): a prefunded inventory sold in a capped window, with refunds, optional compliance gating, and optional vesting.
Quickstart
Prerequisites
- Sui CLI installed.
- MVR CLI installed.
- A new or existing Move package.
1. Create a Move Package
sui move new my_sui_app
cd my_sui_app2. Add OpenZeppelin Dependencies from MVR
mvr add @openzeppelin-move/access
mvr add @openzeppelin-move/integer-math
mvr add @openzeppelin-move/fixed-point-math
mvr add @openzeppelin-move/utilsYou only need the dependencies your app actually uses. Add what you need and drop the others.
Packages not yet on the Move Registry - currently openzeppelin_sale - are added by git revision instead of mvr add (see the next step).
3. Verify Move.toml
mvr add updates Move.toml automatically. With all three installed it should include:
[dependencies]
openzeppelin_access = { r.mvr = "@openzeppelin-move/access" }
openzeppelin_math = { r.mvr = "@openzeppelin-move/integer-math" }
openzeppelin_fp_math = { r.mvr = "@openzeppelin-move/fixed-point-math" }
openzeppelin_utils = { r.mvr = "@openzeppelin-move/utils" }Since openzeppelin_sale isn't on MVR yet, add it manually, pinned to a git revision:
openzeppelin_sale = { git = "https://github.com/OpenZeppelin/contracts-sui.git", subdir = "contracts/finance", rev = "v1.5.0" }Alternatively, copy the module sources directly into your package's sources/ so you fully own the code - see each package guide for the per-package options.
4. Add a Minimal Module
Create sources/quickstart.move:
module my_sui_app::quickstart;
use openzeppelin_math::rounding;
use openzeppelin_math::u64::{mul_div, sqrt};
// === Functions ===
public fun quote_with_fee(amount: u64): u64 {
// 2.5% fee, rounded to nearest.
let quoted = mul_div(amount, 1025u64, 1000u64, rounding::nearest());
quoted.destroy_some()
}
public fun sqrt_floor(value: u64): u64 {
sqrt(value, rounding::down())
}5. Build and Test
sui move build
sui move testPicking a package
- Need role-based authorization for privileged functions or controlled transfer of admin/treasury/upgrade capabilities? Use Access.
- Need fractional values like prices, fees, rates, or signed deltas? Use Fixed-Point Math.
- Need integer arithmetic with safe overflow and explicit rounding? Use Integer Math.
- Need to throttle withdrawals, meter per-user budgets, gate action reuse, or delay an action? Use Rate Limiter.
- Need to run a fixed-price token sale or presale with caps, refunds, and optional KYC or vesting? Use Sale.
The packages compose. A typical protocol module imports openzeppelin_math for share math, openzeppelin_fp_math for rate and fee math, and openzeppelin_access for the admin capability that governs both.
Next steps
- Package guides: Integer Math, Fixed-Point Math, Access, Utilities, Sale.
- Access modules: RBAC, Two-Step Transfer, Delayed Transfer.
- Utilities modules: Rate Limiter.
- Sale modules: Prefunded Sale.
- Learn: Role Based Access Control.
- API reference: Integer Math, Fixed-Point Math, Access, Utilities, Sale.