Net pressure
The net-pressure system measures aggregate crvUSD net buy/sell pressure across YieldBasis markets, splits a governance-configured fraction of LT admin fees into a crvUSD reserve, and computes target incentive APRs for a sink Curve Stableswap pool. Read FeeSplitter.pid() and FeeSplitter.split_fraction() on-chain to inspect active routing, or check Contract addresses.
Architecture and distribution cycle
Six contracts in contracts/net_pressure/ compose the stack:
| Contract | Role |
|---|---|
FeeSplitter.vy | Installed as Factory.fee_receiver(). Splits split_fraction() of incoming LT admin fees to pid() and the remainder to FeeDistributor, then triggers both. |
MerklPIDDriver.vy | Stateless PID driver for off-chain Merkl campaigns. Converts incoming LT fees to crvUSD on trigger(), exposes preview_target_apr(), and lets owner or manager create and override Merkl campaigns backed by its crvUSD reserve. |
PID.vy | Stateful on-chain PID controller. Converts LT fees to crvUSD, advances the PID loop on trigger(), and sets FastGauge.set_reward_rate(). |
FastGauge.vy | ERC-4626 staking gauge over the sink pool LP token streaming crvUSD pulled from PID at each checkpoint. |
YBNetPressure.vy | Manipulation-resistant net-pressure and half_tvl oracle built on AMM invariants and lp_oracle_2. |
MarketRateGetter.vy | Benchmark rate source (rate() -> uint256) reading the Sky Savings Rate (sUSDS.ssr()). |
A full distribution cycle executes in one permissionless call to FeeSplitter.trigger() (or its alias FeeSplitter.fill_epochs()):
FeeSplitterenumeratesFeeDistributor's current token set viacurrent_token_set()andtoken_sets(set_id, i).- For each
LTtoken,FeeSplittermakes a best-effort call tolt.withdraw_admin_fees()to mint newly accrued admin fee shares to itself. - For each nonzero balance
bal, it transfersto_pid = bal * split_fraction // 10**18topid()andbal - to_pidtofee_distributor(). - If
pid() != address(0), it callsPID(pid).trigger(), which converts heldLTshares intocrvUSD(and updatesFastGaugeifpid()isPID.vy). - It calls
fee_distributor().fill_epochs()to distribute the remaining share toveYBholders.
PID controller math
Both MerklPIDDriver.vy and PID.vy execute the same 1e18 fixed-point control law with dt expressed in years (SECONDS_PER_YEAR = 365 * 86400):
- Filtered derivative (): Enforcing
d_filter_time > 0keeps the denominator strictly positive even on same-block calls (). Only rising pressure () contributes totarget. - Signed target:
targetis clamped only at the top (sink_cap), so negative values letofferdrop to1x(target_apr = 0) when no sink is needed. - Connection gate:
MerklPIDDriver.connected()(andPID._connected()) returnsTrueiffFACTORY.fee_receiver()is a contract whosepid()returnsself. Off-chain Merkl runners checkconnected()before starting integration so the integral does not wind up before activation.
FeeSplitter (FeeSplitter.vy)
FeeSplitter sits in front of FeeDistributor as Factory.fee_receiver(). It reads the active LT token set directly from fee_distributor so token lists are never duplicated.
Constants, storage, and events
- Constants:
PRECISION = 10**18,MAX_TOKENS = 100. - Public storage:
split_fraction() -> uint256(1e18= 100%),pid() -> address,fee_distributor() -> address,owner() -> address. - Events:
SetSplitFraction(fraction),SetDestinations(pid, fee_distributor),Recover(indexed token, amount).
External functions
Owner-only functions use snekmate ownable ("ownable: caller is not the owner").
| Signature | Mutability | Access | Notes |
|---|---|---|---|
trigger() | nonpayable, @nonreentrant | Anyone | Realizes LT admin fees (best-effort), splits balances by split_fraction, calls pid.trigger() (if pid != 0x0), and calls fee_distributor.fill_epochs(). |
fill_epochs() | nonpayable, @nonreentrant | Anyone | Alias of trigger() for FeeDistributor keeper compatibility. |
set_split_fraction(fraction: uint256) | nonpayable | Owner | Reverts "fraction > 1" if fraction > 10**18. Emits SetSplitFraction. |
set_destinations(pid: address, fee_distributor: address) | nonpayable | Owner | Validates fee_distributor by calling fill_epochs(). Emits SetDestinations. |
recover(token: address, amount: uint256, to: address) | nonpayable | Owner | Transfers amount of token to to. Emits Recover. |
transfer_ownership(new_owner: address) | nonpayable | Owner | Transfers contract ownership. |
MerklPIDDriver (MerklPIDDriver.vy)
MerklPIDDriver holds the crvUSD incentive reserve, converts incoming LT admin fees into crvUSD, exposes the stateless PID step (preview_target_apr) and primitive signals (raw_signals) for Merkl, and manages Merkl campaigns funded via a Pull-on-Claim wrapper token.
Constants, immutables, and storage
- Constants:
PRECISION = 10**18,FEE_DENOM = 10**10,SECONDS_PER_YEAR = 365 * 86400,MAX_POOLS = 20,MAX_TOKENS = 100,MAX_CAMPAIGN_DATA = 4096,MAX_PARAM = 10**24,MAX_FILTER_TIME = 10**9. - Immutables:
CRVUSD() -> IERC20,FACTORY() -> Factory. - Wiring storage:
net_pressure(),market_rate_getter(),fee_distributor(),pressure_lts(i),sink_pool()(informational only; Merkl suppliessink_tvl),manager(),merkl_creator(),reward_wrapper(),pool_approved(pool). - Controller parameter getters (all
1e18exceptd_filter_timein seconds):feedforward_gain(),kp(),ki(),kd(),max_integral(),sink_cap(),dead_band(),sink_per_offer(),d_filter_time(),swap_fee_multiplier(),dust_floor(). Read these getters on-chain for active governance values.
Structs
struct RawSignals:
pressure: uint256 # max(0, sum net_pressure) / half_tvl, 1e18
half_tvl: uint256 # sum of AMM half-TVL (crvUSD, 1e18)
market_rate: uint256 # market_rate_getter.rate(), 1e18
struct AprState:
target_apr: uint256 # bonus APR (1e18)
integral: int256 # next integral accumulator
prev_pressure: uint256 # next prev_pressure
d_pressure: int256 # next filtered derivative
pressure: uint256 # current pressure (monitoring)
sink: uint256 # current sink (monitoring)
Fee conversion mechanics
trigger() checkpoints FACTORY.agg().price_w() once, iterates FeeDistributor's current token set, skips balances below dust_floor, and for each LT:
- Computes
discount = min(swap_fee_multiplier * pool.fee() // 10**10, 10**18). On a pool running an unkilledYBOraclizedPolicy,pool.fee()returnsconfig().fee.fallback_fee; on a pool runningYBTwocryptoPolicy, it returns the pool's native fee. - Withdraws
sharesvialt.withdraw(shares, min_assets, self)wheremin_assetsis bounded byfair_assets * (1 - discount)usingnet_pressure_and_tvl(lt, agg_price).half_tvlandpool.price_oracle(). A slippage failure on withdrawal revertstrigger(). - Swaps
asset_outtocrvUSDvia a best-effortraw_calltopool.exchange(1, 0, asset_out, min_dy, self). If the swap cannot meetmin_dy, it is skipped so one pool cannot block conversion of others; the withdrawn asset remains recoverable by the owner.
min_dy scaling on 8-decimal marketsThe repository source scales min_dy by precision1 (asset_out * precision1 * p_o // PRECISION * (PRECISION - discount) // PRECISION) for 8-decimal collateral tokens. The currently deployed MerklPIDDriver and idle LTSwapZap still run the pre-fix formula without * precision1 on 8-decimal markets; the scaling fix ships with the next driver redeploy.
External functions
| Signature | Mutability | Access | Notes |
|---|---|---|---|
trigger() | nonpayable, @nonreentrant | Anyone | Converts held LT fees to crvUSD and emits Converted(crvusd_gained, reserve). Does not store PID state. |
preview_target_apr(sink_tvl, integral_in, prev_pressure_in, d_pressure_in, dt) -> AprState | view | Anyone | Runs one stateless PID step using live oracle, market rate, and gains. Reverts "No pools" if summed half_tvl == 0. |
raw_signals() -> RawSignals | view | Anyone | Returns (pressure, half_tvl, market_rate). Returns pressure = 0 when half_tvl == 0. |
reserve() -> uint256 | view | Anyone | Returns CRVUSD.balanceOf(self). |
connected() -> bool | view | Anyone | True iff FACTORY.fee_receiver().pid() == self. |
set_gains(feedforward_gain, kp, ki, kd, max_integral, sink_cap, dead_band, sink_per_offer, d_filter_time) | nonpayable | Owner or manager ("Not manager") | Enforces abs(signed) <= 1e24, max_integral >= 0, sink_cap >= 0, dead_band <= 1e24, 0 < sink_per_offer <= 1e24, 0 < d_filter_time <= 1e9. Emits SetGains. |
set_execution_params(swap_fee_multiplier: uint256, dust_floor: uint256) | nonpayable | Owner or manager | Requires swap_fee_multiplier <= 1e24. Emits SetExecutionParams. |
create_campaign(amount, campaign_type, start_timestamp, duration, campaign_data) -> bytes32 | nonpayable | Owner or manager | Mints amount of reward_wrapper and calls merkl_creator.createCampaign(...) (start_timestamp = 0 defaults to block.timestamp). Emits CampaignCreated. |
override_campaign(campaign_id, campaign_type, start_timestamp, duration, campaign_data) | nonpayable | Owner or manager | Updates campaign_data, duration, or start_timestamp via merkl_creator.overrideCampaign. Emits CampaignOverridden. |
approve_merkl(amount: uint256) | nonpayable | Owner or manager | Sets CRVUSD allowance for reward_wrapper (reverts "No wrapper" if unset). |
accept_conditions() | nonpayable | Owner or manager | Calls merkl_creator.acceptConditions(). |
set_manager(manager: address) | nonpayable | Owner | Sets or clears (0x0) the manager role. Emits SetManager. |
set_merkl(creator: address, wrapper: address) | nonpayable | Owner | Revokes prior wrapper/creator allowances to 0, installs new pair, and grants infinite allowances (skipping 0x0). Emits SetMerkl. |
set_pressure_lts(lts: DynArray[address, 20]) | nonpayable | Owner | Sets LT markets summed for net pressure. Emits SetPressureLts. |
set_sink_pool(sink_pool: address) | nonpayable | Owner | Sets informational sink_pool. Emits SetSinkPool. |
set_sources(net_pressure, market_rate_getter, fee_distributor) | nonpayable | Owner | Updates oracle, rate source, and token-set source. Emits SetSources. |
recover(token: address, amount: uint256, to: address) | nonpayable | Owner | Sweeps crvUSD reserve or any token to to. Emits Recover. |
Companion contracts
PID.vy: On-chain stateful counterpart toMerklPIDDriver.vy. Storesintegral,prev_pressure,d_pressure,last_ts, andactive. Readssink_tvl = gauge.tvl_ema() * sink_pool.get_virtual_price() // 10**18, cachesnet_pressure_and_tvlin transient storage (_npt) across fee conversion and signal evaluation, and writesgauge.set_reward_rate(bonus_apr * staked_value // 10**18 // SECONDS_PER_YEAR). When disconnected, resetsactive = Falseand sets gauge rate to0.FastGauge.vy: ERC-4626 staking gauge over the sink pool LP token (MIN_TOTAL_SUPPLY = 10 * 10**18). PullscrvUSDfromPIDcapped bymin(balance, allowance)so reserve depletion stops the stream without reverting. Exposestvl_ema(),claim(),claimable_reward(), and optional 2-coin zaps (add_liquidity,remove_liquidity,remove_liquidity_one_coin).YBNetPressure.vy: Exposesnet_pressure_and_tvl(lt, agg_price = 0) -> (int256, uint256),net_pressure_oracle(lt, agg_price = 0),half_tvl_oracle(lt, agg_price = 0),net_pressure_naive(lt), andcrvusd_value_fraction(lt). Every view probesAMM.check_nonreentrant()("AMM reentrancy").MarketRateGetter.vy: Exposesrate() -> uint256(1e18= 100%) derived fromSUSDS_TOKEN.ssr(). Returns0whenssr <= 1e27.
Related
- DAO contracts:
FeeDistributor,GaugeController, andVotingEscrowinterfaces. - Pool policy and report bank: How
YBOraclizedPolicyandYBTwocryptoPolicyaffectpool.fee(). - Events and Errors: Event signatures and revert strings across the net-pressure stack.
- Contract addresses: Deployed addresses for
FeeSplitter,MerklPIDDriver, and companion contracts.