Zero-Slippage Mechanism
The zero-slippage mechanism is the core innovation of DobDex. It uses a Uniswap V4 Custom Accounting Hook to intercept swaps before the AMM bonding curve is applied, replacing the AMM-calculated output with an exact amount derived from the oracle price.
How Traditional AMMs Work
In a standard Uniswap V2/V3 pool, the price is determined by the constant-product formula:
x * y = k
Where:
x = reserve of token A
y = reserve of token B
k = constant product
When a user swaps token A for token B, the formula determines how much B they receive. Larger trades move the price further along the curve, causing slippage -- the difference between the expected price and the actual execution price.
For a $100,000 RWA token trade in a pool with $500,000 total liquidity, slippage could easily exceed 10%, meaning the seller receives $90,000 or less for an asset worth $100,000.
The DobPegHook Approach
DobPegHook is a Uniswap V4 hook contract that implements the beforeSwap callback. Uniswap V4 introduced a hook system where external contracts can intercept and modify swap behavior at specific points in the execution flow.
Swap Interception Flow
1. User calls swap on Uniswap V4 PoolManager
2. PoolManager calls DobPegHook.beforeSwap()
3. DobPegHook:
a. Reads oracle price from DobValidatorRegistry
b. Validates oracle freshness (< MAX_ORACLE_DELAY)
c. Calculates exact output amount at oracle price
d. Returns BeforeSwapReturnDelta with custom amounts
4. PoolManager uses the hook's delta INSTEAD of AMM math
5. User receives exactly the oracle-priced amount
BeforeSwapReturnDelta
The key mechanism is the BeforeSwapReturnDelta return value. When a V4 hook returns a custom delta from beforeSwap, it tells the PoolManager to use those amounts instead of computing them from the bonding curve:
function beforeSwap(
address sender,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
bytes calldata hookData
) external override returns (bytes4, BeforeSwapDelta, uint24) {
// Read oracle price
uint256 oraclePrice = validatorRegistry.getAssetPrice(rwaToken);
// Check oracle freshness
require(
block.timestamp - validatorRegistry.lastUpdated(rwaToken) < MAX_ORACLE_DELAY,
"Oracle stale"
);
// Calculate exact output at oracle price
int256 outputAmount = calculateOutputAtOraclePrice(params, oraclePrice);
// Return delta that skips AMM curve entirely
BeforeSwapDelta delta = toBeforeSwapDelta(specifiedDelta, unspecifiedDelta);
return (this.beforeSwap.selector, delta, 0);
}
The AMM pool still exists -- it is needed for Uniswap V4's routing and pool infrastructure -- but the actual price discovery is completely replaced by the oracle.
Oracle Integration
DobValidatorRegistry
The DobValidatorRegistry contract serves as the on-chain oracle for RWA asset prices:
interface IDobValidatorRegistry {
function getAssetPrice(address rwaToken) external view returns (uint256);
function lastUpdated(address rwaToken) external view returns (uint256);
function setAssetPrice(address rwaToken, uint256 price) external;
}
Prices originate from DobValidator's asset appraisal process. When a real-world asset is validated and scored, its appraised value is written to the registry by authorized validators.
Price Update Flow
1. Asset owner submits to DobValidator
2. Validator reviews and assigns TRUFA scores + appraised value
3. Authorized validator calls DobValidatorRegistry.setAssetPrice()
4. On-chain price is now available for DobPegHook
5. All subsequent swaps use the updated price
Staleness Circuit Breaker
To prevent trades at outdated prices, DobPegHook enforces a maximum oracle delay:
uint256 constant MAX_ORACLE_DELAY = 1 days;
If the oracle price has not been updated within the last 24 hours, all swaps are automatically blocked. This protects users from trading at prices that no longer reflect reality -- for example, if an asset was damaged or decommissioned but the price was not yet updated.
The circuit breaker is a safety mechanism, not a normal operating condition. In production, oracle prices are updated regularly as part of the DobValidator review cycle.
Swap Examples
Selling RWA Tokens
A user holds 100 tokens representing shares in a solar panel installation. The oracle price is $50 per token.
| Step | Action |
|---|---|
| 1 | User initiates swap: 100 RWA tokens to USDC |
| 2 | DobPegHook reads oracle: $50/token |
| 3 | Hook calculates: 100 * $50 = $5,000 USDC |
| 4 | Hook returns delta: -100 RWA, +5,000 USDC |
| 5 | User receives exactly 5,000 USDC |
In a traditional AMM, the user might receive $4,200--$4,800 depending on pool depth.
Buying RWA Tokens
A user wants to invest $10,000 USDC into the same solar panel tokens at $50/token.
| Step | Action |
|---|---|
| 1 | User initiates swap: 10,000 USDC to RWA tokens |
| 2 | DobPegHook reads oracle: $50/token |
| 3 | Hook calculates: $10,000 / $50 = 200 tokens |
| 4 | Hook returns delta: -10,000 USDC, +200 RWA |
| 5 | User receives exactly 200 RWA tokens |
DobDirectSwap: Chains Without V4
Not all chains support Uniswap V4. For these networks, DobDex provides DobDirectSwap -- a lightweight swap router that implements the same oracle-based pricing without the V4 hook infrastructure:
contract DobDirectSwap {
IDobValidatorRegistry public validatorRegistry;
IDobRwaVault public vault;
function swap(
address rwaToken,
address paymentToken,
uint256 amountIn,
bool isRwaToPayment
) external returns (uint256 amountOut) {
uint256 oraclePrice = validatorRegistry.getAssetPrice(rwaToken);
require(block.timestamp - validatorRegistry.lastUpdated(rwaToken) < MAX_ORACLE_DELAY);
if (isRwaToPayment) {
amountOut = (amountIn * oraclePrice) / PRICE_PRECISION;
// Transfer RWA in, payment out
} else {
amountOut = (amountIn * PRICE_PRECISION) / oraclePrice;
// Transfer payment in, RWA out
}
}
}
DobDirectSwap provides the same zero-slippage guarantee as DobPegHook, but as a standalone contract that does not depend on Uniswap V4 pool infrastructure. It is currently deployed on Robinhood Chain.
When to Use Each
| Scenario | Contract | Deployed On |
|---|---|---|
| Chain has Uniswap V4 | DobPegHook (via V4 pool) | Arbitrum Sepolia, Base Sepolia |
| Chain lacks Uniswap V4 | DobDirectSwap | Robinhood Chain |
Both implementations read from the same DobValidatorRegistry and enforce the same MAX_ORACLE_DELAY circuit breaker.
Security Considerations
| Risk | Mitigation |
|---|---|
| Oracle manipulation | Only authorized validators can update prices; multi-sig planned |
| Stale prices | MAX_ORACLE_DELAY circuit breaker blocks trades after 24h without update |
| Flash loan attacks | Oracle price is external (not derived from pool state), immune to flash loan manipulation |
| Front-running | Price is deterministic from oracle; no MEV opportunity from price curve |
| Hook reentrancy | Uniswap V4 PoolManager handles reentrancy protection |