Limit Orders
Separate, fully funded fixed-price token orders. Humans or bots can fill any portion; makers can cancel anytime and withdraw only the unfilled balance. No oracle, admin or protocol fees in this initial version. Not deployed or independently audited.
BaraFiLimitOrders.sol
contracts/src/BaraFiLimitOrders.sol
Immutable escrow, partial fills, price/deadline protection, cancellation and individual or batch withdrawals. Payments round up per fill; maker sale proceeds are claimable.
DeployLimitOrders.s.sol
contracts/script/DeployLimitOrders.s.sol
Standalone Foundry deployment script; independent review required before broadcasting.
BaraFiLimitOrders.t.sol
contracts/test/BaraFiLimitOrders.t.sol
Tests covering partial fills, cancellation before and after expiry, ownership, rounding, failed transfers, withdrawal fallback and escrow conservation.
Prediction Markets
Separate YES/NO prediction markets backed by any standard ERC-20 chosen by the market creator. Every YES + NO pair is backed by exactly 1 token; shares are created when opposite buyers are matched on a fully onchain, fixed-cent order book. 0.5% taker fee with 25% affiliate share. Outcomes are settled by a separate bonded resolver with a creator-chosen dispute arbiter. Not deployed or independently audited; obtain legal advice before launch.
BaraFiPredictions.sol
contracts/src/BaraFiPredictions.sol
Markets, split/merge, order book with partial fills and pair-minting matches, cancellation anytime, redemption and claimable proceeds.
BaraFiOutcomeResolver.sol
contracts/src/BaraFiOutcomeResolver.sol
Optimistic bonded proposals, 2-day dispute window, arbiter ruling within 30 days, otherwise Invalid with bonds refunded. Holds bonds only.
DeployPredictions.s.sol
contracts/script/DeployPredictions.s.sol
Standalone Foundry deployment script; the resolver deploys automatically.
BaraFiPredictions.t.sol
contracts/test/BaraFiPredictions.t.sol
Tests covering pair backing, matching, fees, referrals, cancellation, close times, disputes, silent arbiters and taxed tokens.
AI Oracle
Separate registry where anyone can run an AI oracle service. Operators choose Free, per-request (escrowed, refundable if unanswered by the deadline) or subscription pricing in any standard ERC-20. No trust mechanism yet: answers are only as reliable as the operator. No owner, upgrades or protocol fee. Not deployed or independently audited.
BaraFiAIOracle.sol
contracts/src/BaraFiAIOracle.sol
Oracle registration, immutable pricing, pause, subscriptions, requests, deadline-bound answers, refunds and pull claims.
DeployAIOracle.s.sol
contracts/script/DeployAIOracle.s.sol
Standalone Foundry deployment script; no constructor arguments.
BaraFiAIOracle.t.sol
contracts/test/BaraFiAIOracle.t.sol
Tests covering free, per-request and subscription flows, refunds, operator-only answers, pausing, invalid configs and taxed tokens.
BaraFiRandomness.sol
contracts/src/BaraFiRandomness.sol
Separate multi-operator random numbers: commit, reveal, mixed result, no operator deposits, fees only to revealers, pull claims.
DeployRandomness.s.sol
contracts/script/DeployRandomness.s.sol
Standalone Foundry deployment script; no constructor arguments.
BaraFiRandomness.t.sol
contracts/test/BaraFiRandomness.t.sol
Tests covering full reveals, unpaid withholders, no-deposit operators, too-few commits, bad reveals and invalid configs.
Loans
Peer-to-peer lending offers. Lenders escrow the coins they want to lend and name the collateral they require; borrowers fill all or part of an offer. Fixed terms, static interest, no liquidations and no oracles.
BaraFiLending.sol
contracts/src/BaraFiLending.sol
The lending contract: offers, partial fills, fixed terms, static interest, and collateral released only after full repayment. A 1% protocol fee is charged on the required collateral, in the collateral token, when a loan is taken out. Immutable — no owner, no admin keys, no pause, no upgrades.
Deploy.s.sol
contracts/script/Deploy.s.sol
Foundry deploy script. Set TREASURY and FEE_BPS, then broadcast to Ethereum.
BaraFiLending.t.sol
contracts/test/BaraFiLending.t.sol
Unit tests covering offer creation, partial fills, repayment, default, collateral claims and the transfer checks that reject unsupported tokens.
BaraFiIntegration.t.sol
contracts/test/BaraFiIntegration.t.sol
End-to-end tests for the helper flows: deadline-protected borrows, atomic repay-and-withdraw, permit paths and bounded batch claims.
Options
Puts and calls, written by their own contract and kept apart from lending so each contract carries its own attack surface. Sellers fully back the obligation up front, buyers pay a premium, and exercise is open any time before expiry.
BaraFiOptions.sol
contracts/src/BaraFiOptions.sol
The options contract: writers escrow the full call underlying or put strike up front, buyers pay a premium for all or part of an offer, and only the unsold portion can be cancelled. American-style exercise before expiry, seller reclaim after. Immutable, wallet-bound, no oracles.
DeployOptions.s.sol
contracts/script/DeployOptions.s.sol
Foundry deploy script. Set TREASURY, PREMIUM_FEE_BPS and EXERCISE_FEE_BPS.
BaraFiOptions.t.sol
contracts/test/BaraFiOptions.t.sol
Tests for offer creation, partial fills, premium collection, exercise before expiry, expiry reclaim and the fee split.
DEX
The swap fee add-on for an unmodified Uniswap v4 core: an extra 0.2% on the token being sold, half burned and half to BaraFi, with 25% of BaraFi’s half to the swap’s referrer. Uniswap’s own math and LP fees are untouched.
BaraFiSwapFeeHook.sol
contracts/src/BaraFiSwapFeeHook.sol
Uniswap v4 hook that charges the extra 0.2% and splits it between the burn address and BaraFi. Only swap callbacks are enabled — liquidity and donations are never touched. No owner, no upgrades, all rates are constants.
burn-exempt-stablecoins.json
contracts/config/burn-exempt-stablecoins.json
The stablecoin addresses handed to the hook at deploy so their fees are never burned. One entry per chain, each verified on-chain; the list cannot change once deployed.
BaraFiSwapFeeHook.t.sol
contracts/test/BaraFiSwapFeeHook.t.sol
Tests for the fee math on exact-in and exact-out swaps, partial fills, the burn split, stablecoin exemptions and referrer credits.
Uniswap v4 core
The Uniswap v4 core the DEX builds on, vendored unmodified under contracts/lib/v4-core so the deployed pool math matches the audited upstream exactly. BaraFi changes nothing here — the fee add-on lives entirely in the hook above. Licensed BUSL-1.1 by Uniswap Labs; production use is restricted until the license converts.
ERC6909.sol
contracts/vendor/v4-core/src/ERC6909.sol
Uniswap v4 core contract: ERC6909.
ERC6909Claims.sol
contracts/vendor/v4-core/src/ERC6909Claims.sol
Uniswap v4 core contract: ERC6909Claims.
Extsload.sol
contracts/vendor/v4-core/src/Extsload.sol
Uniswap v4 core contract: Extsload.
Exttload.sol
contracts/vendor/v4-core/src/Exttload.sol
Uniswap v4 core contract: Exttload.
NoDelegateCall.sol
contracts/vendor/v4-core/src/NoDelegateCall.sol
Uniswap v4 core contract: NoDelegateCall.
PoolManager.sol
contracts/vendor/v4-core/src/PoolManager.sol
Uniswap v4 core contract: PoolManager.
ProtocolFees.sol
contracts/vendor/v4-core/src/ProtocolFees.sol
Uniswap v4 core contract: ProtocolFees.
IExtsload.sol
contracts/vendor/v4-core/src/interfaces/IExtsload.sol
Uniswap v4 interface: IExtsload.
IExttload.sol
contracts/vendor/v4-core/src/interfaces/IExttload.sol
Uniswap v4 interface: IExttload.
IHooks.sol
contracts/vendor/v4-core/src/interfaces/IHooks.sol
Uniswap v4 interface: IHooks.
IPoolManager.sol
contracts/vendor/v4-core/src/interfaces/IPoolManager.sol
Uniswap v4 interface: IPoolManager.
IProtocolFees.sol
contracts/vendor/v4-core/src/interfaces/IProtocolFees.sol
Uniswap v4 interface: IProtocolFees.
IUnlockCallback.sol
contracts/vendor/v4-core/src/interfaces/callback/IUnlockCallback.sol
Uniswap v4 interface: IUnlockCallback.
IERC20Minimal.sol
contracts/vendor/v4-core/src/interfaces/external/IERC20Minimal.sol
Uniswap v4 interface: IERC20Minimal.
IERC6909Claims.sol
contracts/vendor/v4-core/src/interfaces/external/IERC6909Claims.sol
Uniswap v4 interface: IERC6909Claims.
BitMath.sol
contracts/vendor/v4-core/src/libraries/BitMath.sol
Uniswap v4 library: BitMath.
CurrencyDelta.sol
contracts/vendor/v4-core/src/libraries/CurrencyDelta.sol
Uniswap v4 library: CurrencyDelta.
CurrencyReserves.sol
contracts/vendor/v4-core/src/libraries/CurrencyReserves.sol
Uniswap v4 library: CurrencyReserves.
CustomRevert.sol
contracts/vendor/v4-core/src/libraries/CustomRevert.sol
Uniswap v4 library: CustomRevert.
FixedPoint128.sol
contracts/vendor/v4-core/src/libraries/FixedPoint128.sol
Uniswap v4 library: FixedPoint128.
FixedPoint96.sol
contracts/vendor/v4-core/src/libraries/FixedPoint96.sol
Uniswap v4 library: FixedPoint96.
FullMath.sol
contracts/vendor/v4-core/src/libraries/FullMath.sol
Uniswap v4 library: FullMath.
Hooks.sol
contracts/vendor/v4-core/src/libraries/Hooks.sol
Uniswap v4 library: Hooks.
LPFeeLibrary.sol
contracts/vendor/v4-core/src/libraries/LPFeeLibrary.sol
Uniswap v4 library: LPFeeLibrary.
LiquidityMath.sol
contracts/vendor/v4-core/src/libraries/LiquidityMath.sol
Uniswap v4 library: LiquidityMath.
Lock.sol
contracts/vendor/v4-core/src/libraries/Lock.sol
Uniswap v4 library: Lock.
NonzeroDeltaCount.sol
contracts/vendor/v4-core/src/libraries/NonzeroDeltaCount.sol
Uniswap v4 library: NonzeroDeltaCount.
ParseBytes.sol
contracts/vendor/v4-core/src/libraries/ParseBytes.sol
Uniswap v4 library: ParseBytes.
Pool.sol
contracts/vendor/v4-core/src/libraries/Pool.sol
Uniswap v4 library: Pool.
Position.sol
contracts/vendor/v4-core/src/libraries/Position.sol
Uniswap v4 library: Position.
ProtocolFeeLibrary.sol
contracts/vendor/v4-core/src/libraries/ProtocolFeeLibrary.sol
Uniswap v4 library: ProtocolFeeLibrary.
SafeCast.sol
contracts/vendor/v4-core/src/libraries/SafeCast.sol
Uniswap v4 library: SafeCast.
SqrtPriceMath.sol
contracts/vendor/v4-core/src/libraries/SqrtPriceMath.sol
Uniswap v4 library: SqrtPriceMath.
StateLibrary.sol
contracts/vendor/v4-core/src/libraries/StateLibrary.sol
Uniswap v4 library: StateLibrary.
SwapMath.sol
contracts/vendor/v4-core/src/libraries/SwapMath.sol
Uniswap v4 library: SwapMath.
TickBitmap.sol
contracts/vendor/v4-core/src/libraries/TickBitmap.sol
Uniswap v4 library: TickBitmap.
TickMath.sol
contracts/vendor/v4-core/src/libraries/TickMath.sol
Uniswap v4 library: TickMath.
TransientStateLibrary.sol
contracts/vendor/v4-core/src/libraries/TransientStateLibrary.sol
Uniswap v4 library: TransientStateLibrary.
UnsafeMath.sol
contracts/vendor/v4-core/src/libraries/UnsafeMath.sol
Uniswap v4 library: UnsafeMath.
BalanceDelta.sol
contracts/vendor/v4-core/src/types/BalanceDelta.sol
Uniswap v4 type definitions: BalanceDelta.
BeforeSwapDelta.sol
contracts/vendor/v4-core/src/types/BeforeSwapDelta.sol
Uniswap v4 type definitions: BeforeSwapDelta.
Currency.sol
contracts/vendor/v4-core/src/types/Currency.sol
Uniswap v4 type definitions: Currency.
PoolId.sol
contracts/vendor/v4-core/src/types/PoolId.sol
Uniswap v4 type definitions: PoolId.
PoolKey.sol
contracts/vendor/v4-core/src/types/PoolKey.sol
Uniswap v4 type definitions: PoolKey.
PoolOperation.sol
contracts/vendor/v4-core/src/types/PoolOperation.sol
Uniswap v4 type definitions: PoolOperation.
Slot0.sol
contracts/vendor/v4-core/src/types/Slot0.sol
Uniswap v4 type definitions: Slot0.