How ref-finance/ref-contracts works
Project type and purpose
• This is a monorepo for a set of NEAR‐based smart contracts written in Rust and compiled to WebAssembly (WASM).
• Primary contracts:
• ref-exchange: the main exchange logic for depositing, withdrawing, and swapping tokens.
• ref-farming: staking and reward distribution functionality.
• test-token and various mock-* crates: support testing and simulate external services (price oracles, wrapped NEAR).
• The repo also includes documentation, build/deploy scripts, CI workflows, and multiple versions of compiled WASM releases.
File structure
• Top-level directories:
• .github/workflows: CI for building/testing contracts.
• doc/ and docs.md: feature and fee documentation.
• mock-*: standalone crates simulating external dependencies (boost farming logic, price oracles, tokens).
• ref-exchange/ and ref-farming/: each contains a Rust crate with src/, tests/, build scripts, and release notes.
• test-token/: a simple NEP-21 token for integration tests.
• scripts/ and Makefile/Dockerfile: automation for building, testing, and deploying.
• Patterns inside each contract crate:
• src/actions_of_*.rs and src/* files separate business logic modules (e.g., seed, pool, farm).
• src/storage_impl.rs isolates persistent state.
• src/view.rs exposes read-only methods.
• tests/common and tests/fuzzy/integration tests using NEAR Simulation framework.
Key insights from README
• Confirms Rust/WASM toolchain (rustup, target wasm32-unknown-unknown).
• Testing via cargo test and NEAR Simulation.
• Deployment to TestNet via near dev-deploy.
• ref-exchange is the “main” contract—other crates support testing or specialized logic.