bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 24쪽 중 21쪽
n
(
)
)
.
lt_allocate_stablecoins
(
lt
,
limit
)
Related
Core: HybridVault
— the vault instance deployed by this factory.
Core: Factory
— YB core Factory (parent admin chain).
User: Hybrid Vaults
— user-level explainer.
Overview
Function Documentation
Public Variables
Events
create_vault()
set_vault_impl()
set_stablecoin_fraction()
set_pool_limit()
set_allowed_crvusd_vault()
set_crvusd_vault_limit()
update_vault_required()
lt_allocate_stablecoins()
Related
## /dev/core/lt-migrator
On this page
LTMigrator.vy
— upgrade path without forcing users to withdraw.
Constants / Immutables
Name
Notes
STABLECOIN
crvUSD
FACTORY_OWNER
MFOwner — validates LTs are factory-issued
External functions
Signature
Purpose
preview_migrate_plain(lt_from, lt_to, shares_in, debt_coefficient) → shares_out
View — unstaked path
preview_migrate_staked(lt_from, lt_to, shares_in, debt_coefficient) → shares_out
View — staked path
migrate_plain(lt_from, lt_to, shares_in, min_out, debt_coefficient)
Execute unstaked migration
migrate_staked(lt_from, lt_to, shares_in, min_out, debt_coefficient)
Execute staked migration
debt_coefficient
default 1e18. Scale down (e.g. 0.9e18) to migrate with reduced leverage.
Reverts
String
Cause
lt_to deprecated
Target LT has been disabled in the factory owner (
disabled_lts[lt_to] == True
). The DAO sets this when winding a market down via
lt_allocate_stablecoins(lt, 0)
. Migrate to a different LT.
not enough out
shares_out < min_out
in staked migration
Flow
Validate both LTs belong to a factory (via
FACTORY_OWNER.lt_in_factory()
) and that the target is not disabled (
disabled_lts[lt_to] == False
).
collect_fees()
on source AMM (so fee accruals do not contaminate measurements).
lt_from.withdraw(shares_in, 0)
→ receive asset + debt unwound through Cryptoswap.
Temporarily inflate target's
stablecoin_allocation
to
max((pool_value + additional_crvusd) × 2.2, previous_allocation)
on target LT — gives the deposit headroom against the
AMM.max_debt() / 2
cap.
lt_to.deposit(assets, debt × debt_coefficient / 1e18, min_out, receiver)
into target.
Restore allocation to its previous value.
For staked: unstake from source gauge before, re-stake into target gauge after.
Related
Core: LT
Core: Factory
Constants / Immutables
External functions
Reverts
Flow
Related
## /dev/core/hybrid-factory-owner
On this page
The source code of the
HybridFactoryOwner.vy
contract can be found on
GitHub
. The contract is written with
Vyper
version 0.4.3.
Overview
HybridFactoryOwner
is the address held as
Factory.admin
. The DAO does not call
Factory.set_admin
/
LT.set_rate
directly; it calls the equivalent wrapper on
HybridFactoryOwner
, and the wrapper forwards. Three reasons:
One ACL surface.
Every privileged call checks
msg.sender == ADMIN
. The Factory and its LT instances never need their own DAO logic.
Allowlist for stablecoin allocators.
limit_setters
grants non-admin contracts (notably each
HybridVault
) permission to call
lt_allocate_stablecoins
with non-zero limits, without giving them broader admin rights.
Permissionless deallocation of disabled LTs.
When the admin disables a market via
lt_allocate_stablecoins(lt, 0)
, the
disabled_lts[lt]
flag flips. After that, anyone can pull stablecoins out of that market (down to a 75% safety floor on remaining reserves) — useful for winding down without DAO-vote latency.
For market discovery, integrators read the
Factory
directly. They only need this contract when they are operating inside a HybridVault or running governance tooling.
Immutable variables
Name
Type
Notes
ADMIN
address
DAO / multisig that owns this proxy. Never changes after deploy.
FACTORY
Factory
The YB Factory this proxy controls. Held as
Factory.admin
.
STABLECOIN
IERC20
crvUSD, cached from
factory.STABLECOIN()
at deploy.
Storage
Name
Type
Description
disabled_lts
HashMap[LT, bool]
Flag set by
ADMIN
when an LT is wound down (
lt_allocate_stablecoins(lt, 0)
). Once true, anyone can drain the market's allocation down to safe reserves. LTMigrator refuses to migrate INTO a disabled LT.
limit_setters
HashMap[address, bool]
Allowlist of non-admin contracts that may call
lt_allocate_stablecoins(lt, limit)
with
limit > 0
. HybridVault instances are added here so they can size their own stablecoin allocation per deposit.
Events
SetLimitSetter
— emitted by
set_limit_setter
setter
(
address
) — address whose privilege changed
enabled
(
bool
) — true to grant, false to revoke
Privileged LT controls
All require
msg.sender == ADMIN
.
Function
Effect
lt_set_rate(lt, rate)
Forwards to
LT.set_rate(rate)
. Changes the borrow / refuel rate on the AMM.
lt_set_amm_fee(lt, fee)
Forwards to
LT.set_amm_fee(fee)
. Bounded by
AMM.MAX_FEE
(10%).
lt_set_killed(lt, is_killed)
Kill or unkill the market via
LT.set_killed
. Killed markets force the
emergency_withdraw
exit path.
lt_distribute_borrower_fees(lt, discount)
Forwards to
LT.distribute_borrower_fees(discount)
. Anyone can call the default-discount variant directly on LT; this wrapper exists so admin can pass a non-default discount.
Stablecoin allocation
@external
def
lt_allocate_stablecoins
(
lt
:
LT
,
limit
:
uint256
=
max_value
(
uint256
)
)
Three call patterns:
Caller
limit
Behaviour
ADMIN
> 0
Sets
LT.stablecoin_allocation
to
limit
, clears
disabled_lts[lt]
.
limit_setters[caller] == True
> 0
Same as above. This is the path HybridVaults use to size allocation during deposits.
ADMIN
0
Flips
disabled_lts[lt] = True
. Does not change the LT's allocation directly — that is the next step.
Anyone
0
,
disabled_lts[lt] == True
Reads
LT.amm.value_oracle().value
, computes
safe_limit = value × 3 / 4
, and shrinks
LT.stablecoin_allocation
down to that floor (or
available_limit
if smaller). Reverts
"Not enough reserves"
if
available_limit
is below
safe_limit
.
Anyone,
disabled_lts[lt] == False
,
limit == 0
—
Reverts
"Not disabled"
.
Anyone else,
limit > 0
—
Reverts
"Access"
.
The 75% floor is the same conservative bound used internally by
LT.allocate_stablecoins
when deflating. It guarantees that even after permissionless deallocation, the AMM still holds three-quarters of its oracle-priced collateral value as stablecoin reserves.
Factory passthroughs
All require
msg.sender == ADMIN
. Each is a thin one-line forward.
Function
Forwards to
transfer_ownership_back()
FACTORY.set_admin(ADMIN, FACTORY.emergency_admin())
— gives admin role back to the DAO directly, bypassing this proxy.
add_market(pool, fee, rate, debt_ceiling)
FACTORY.add_market(...)
set_fee_receiver(addr)
FACTORY.set_fee_receiver(addr)
set_implementations(amm, lt, virtual_pool, price_oracle, staker)
FACTORY.set_implementations(...)
set_min_admin_fee(value)
FACTORY.set_min_admin_fee(value)
fill_staker_vpool(i)
FACTORY.fill_staker_vpool(i)
set_allocator(allocator, amount)
FACTORY.set_allocator(...)
set_agg(agg)
FACTORY.set_agg(agg)
set_flash(flash)
FACTORY.set_flash(flash)
Limit-setter management
@external
def
set_limit_setter
(
setter
:
address
,
enabled
:
bool
)
Only
ADMIN
. Toggles
limit_setters[setter]
. Emits
SetLimitSetter
.
When the HybridVaultFactory deploys a new
HybridVault
, the DAO is expected to add the vault to
limit_setters
so it can call
lt_allocate_stablecoins
during deposit. Revoking the flag freezes the vault's ability to grow stablecoin allocation on a market.
Public views
Function
Returns
lt_in_factory(lt)
True
if
STABLECOIN.allowance(FACTORY, lt) > 0
— a stand-in check for "factory has approved this LT to spend its crvUSD," used by
LTMigrator
and by HybridVaults before they route deposits.
lt_needs_withdraw(lt)
Quote: number of yb-LP shares the holder would need to withdraw to bring
available_limit = lp_price × collateral_amount
back down to the LT's
stablecoin_allocated
. Returns 0 if no withdrawal is needed.
Common revert strings
String
Cause
Access
Caller is not
ADMIN
, or (for
lt_allocate_stablecoins
with
limit > 0
) not in
limit_setters
.
Not disabled
Permissionless
lt_allocate_stablecoins(lt, 0)
called but the LT was never flagged for wind-down.
Not enough reserves
Permissionless deallocation attempt would leave the AMM below the 75% safe floor of oracle-priced collateral value.
Related
Core: Factory
— the contract owned by this proxy.
Core: LT
— receives all the
lt_*
forwards.
Core: HybridVault
— typical
limit_setter
and the consumer of
lt_allocate_stablecoins
from non-admin callers.
Core: LTMigrator
— reads
lt_in_factory
and
disabled_lts
before routing migrations.
Core: MigrationFactoryOwner
— earlier admin-proxy variant without the
limit_setters
and
lt_distribute_borrower_fees
surface.
Overview
Immutable variables
Storage
Events
Privileged LT controls
Stablecoin allocation
Factory passthroughs
Limit-setter management
Public views
Common revert strings
Related
## /dev/core/migration-factory-owner
On this page
The source code of the
MigrationFactoryOwner.vy
contract can be found on
GitHub
. The contract is written with
Vyper
version 0.4.3.
Overview
MigrationFactoryOwner
is a slimmer predecessor of
HybridFactoryOwner
— same admin-proxy pattern, fewer features. It owns its
FACTORY
and forwards governance calls, but it lacks the
limit_setters
allowlist and the
lt_distribute_borrower_fees
surface. It still exists on-chain because
LTMigrator
reads two of its views to gate migrations.
The bulk of this contract is governance plumbing for the DAO that operates the migration-era Factory. Integrators only care about two public views.
What integrators read
@external
@view
def
lt_in_factory
(
lt
:
address
)
-
>
bool
Returns
True
if
STABLECOIN.allowance(FACTORY, lt) > 0
— a stand-in check for "this LT has been deployed by FACTORY and was given crvUSD spend permission."
LTMigrator
calls this against both
lt_from
and
lt_to
before routing a migration; integrators should do the same before treating an LT address as a valid YB market under this Factory.
disabled_lts
:
public
(
HashMap
[
LT
,
bool
]
)
Map keyed by LT address.
True
means admin disabled that market (via
lt_allocate_stablecoins(lt, 0)
).
LTMigrator
refuses to migrate INTO any LT where this flag is set (
"lt_to deprecated"
).
@view
accessor signature:
disabled_lts(lt: address) -> bool
.
Governance surface (admin-only)
For completeness — none of these are intended for non-admin callers. Each requires
msg.sender == ADMIN
.
Function
Forwards to / effect
transfer_ownership_back()
FACTORY.set_admin(ADMIN, emergency_admin)
lt_set_rate(lt, rate)
LT.set_rate
lt_set_amm_rate(lt, fee)
LT.set_amm_fee
(note the function name differs from the LT method)
lt_set_killed(lt, is_killed)
LT.set_killed
lt_allocate_stablecoins(lt, limit)
Admin-only when
limit > 0
(no
limit_setters
allowlist here); permissionless when
limit == 0
and
disabled_lts[lt] == True
, same 75% safe floor as
HybridFactoryOwner
.
lt_needs_withdraw(lt)
View: shares that need to be withdrawn for
available_limit
to match
stablecoin_allocated
.
add_market(...)
FACTORY.add_market
set_fee_receiver(addr)
FACTORY.set_fee_receiver
set_implementations(...)
FACTORY.set_implementations
set_min_admin_fee(value)
FACTORY.set_min_admin_fee
This contract does
not
expose
lt_distribute_borrower_fees
,
set_allocator
,
set_agg
,
set_flash
,
fill_staker_vpool
, or
set_limit_setter
. For those, use
HybridFactoryOwner
.
Related
Core: HybridFactoryOwner
— current admin proxy with the fuller surface.
Core: LTMigrator
— primary consumer of
lt_in_factory
and
disabled_lts
.
Overview
What integrators read
Governance surface (admin-only)
Related
## /dev/core/net-pressure
On this page
A feedback-controlled incentive system: measure aggregate crvUSD net pressure across YB markets, stream crvUSD to a FastGauge over the Curve crvUSD/pyUSD sink pool at a PID-set rate, funded by a DAO-set slice of LT admin fees.
Source code lives in
contracts/net_pressure/
in yb-core. All contracts are written with
Vyper
0.4.3.
PID stands for proportional–integral–derivative: the controller's output combines a term proportional to the current error, a term integrating past error, and a term tracking how fast the error is rising.
The system was activated by
DAO vote
: the proposal recovered the deprecated BTC markets' fee balances from the FeeDistributor (
recover_token
), converted them into the PID reserve via
LTSwapZap.convert
, transferred a crvUSD headstart to the MerklPIDDriver, and installed the FeeSplitter as
Factory.fee_receiver()
.
Components
Contract
Role
YBNetPressure.vy
Pressure oracle. Per market: AMM debt minus the crvUSD inside the Curve LP the AMM holds. Positive = crvUSD must be bought to repay (buy pressure). Aggregates over a DAO-selected set of LTs.
PID.vy
The controller. Converts incoming LT fees to a crvUSD reserve, runs the control loop on aggregate pressure, and sets the FastGauge's
reward_rate
.
FastGauge.vy
ERC-4626 staking gauge over the sink pool's LP token. Streams a single reward (crvUSD), pulled from the PID's reserve at every checkpoint. Includes
add_liquidity
/
remove_liquidity
/
remove_liquidity_one_coin
zaps for one-call entry and exit.
FeeSplitter.vy
Installed as
Factory.fee_receiver()
. Routes
split_fraction
(1e18-scaled, DAO-set) of each incoming LT fee balance to the PID and forwards the rest to the FeeDistributor, then pokes both. Reads the LT token set from the FeeDistributor.
MerklPIDDriver.vy
Read-only mirror of the PID's parameters and inputs so Merkl can run the same control loop off-chain and post campaigns at the resulting target APR.
MarketRateGetter.vy
The comparator rate the PID prices its bonus against. Current implementation reads the Sky Savings Rate (sUSDS); swappable by the DAO — only
rate()
is part of the interface.
The control loop
Per step (
dt
in years, all values 1e18 fixed point), from the
PID.vy
specification:
pressure = max(0, sum of net pressure) / sum of half-TVL (oracle-priced)
sink = sink-pool TVL / sum of half-TVL
error = pressure - sink (coverage gap)
integral += error * dt clamped to [0, max_integral]
d_pressure = max(0, d(pressure)/dt) (rising edge only)
target = min(feedforward_gain*pressure + kp*error
+ ki*integral + kd*d_pressure, sink_cap)
offer = max(1, dead_band + target / sink_per_offer) (APR multiple, floored at 1x)
bonus_apr = (offer - 1) * market_rate (0 when no sink is wanted)
rate = bonus_apr * staked_value / seconds_per_year (crvUSD/sec)
Gains and parameters are DAO-settable storage, not constants (
set_gains
,
set_execution_params
,
set_sources
,
set_pressure_lts
,
set_gauge
). The reserve is the PID contract's crvUSD balance.
Behaviour worth knowing
trigger()
is permissionless.
Anyone can advance the loop; there is no keeper dependency for liveness.
preview_signals()
exposes the full signal set (pressure, sink, error, integral, derivative, offer, rate) as a view for monitoring and integration.
Graceful depletion.
The FastGauge pulls owed crvUSD from the PID at each checkpoint, capped by the PID's balance. An empty reserve slows and stops the stream; nothing reverts.
Manipulation resistance.
The PID reads the sink size via the FastGauge's
tvl_ema()
, an EMA over staked value, so flash deposits cannot spike the measured sink inside one block. Fee conversion into crvUSD happens via bounded, oracle-checked swaps (
swap_fee_multiplier
,
dust_floor
).
FastGauge is not a LiquidityGauge.
No CRV emissions, no boost, single reward token, ERC-4626 accounting mirroring Curve's reward logic.
Fee flow.
With the FeeSplitter installed as
fee_receiver
, veYB distributions receive
1 − split_fraction
of admin fees. The PID share is DAO-set; it is 15% at activation.
Related
User: Net Pressure & the PID Controller
— plain-language explanation and how to participate
DAO: FeeDistributor
— the downstream recipient the FeeSplitter fronts
Core: LT
— source of the fee balances that fund the reserve
Core: AMM (LEVAMM)
— debt side of the pressure calculation
Components
The control loop
Behaviour worth knowing
Related
## /dev/dao/yb-token
On this page
The source code of the
YB.vy
contract can be found on
GitHub
. The contract is written with
Vyper
version 0.4.3.
Overview
The
YB
contract is the governance token for the Yield Basis protocol. It extends standard ERC20 functionality with
inflationary emissions
that follow an exponential decay curve. The token implements a
minting mechanism
where authorized minters (
GaugeController
) can emit tokens based on time elapsed and a configurable rate factor.
Hard cap
: 1,000,000,000 YB, fixed forever at deployment. Pre-allocations plus the emission reserve set in the constructor sum to exactly 1B; the reserve can only shrink as tokens are emitted, and no function exists to raise it or mint outside it. Total supply can never exceed 1B.
Exponential Decay Emissions
: Token emissions follow an exponential decay curve
Reserve-Based Minting
: Total emissions are limited by a reserve amount set at deploy
Rate Factor Control
: Minters can control emission rate via
rate_factor
parameter
Ownable + Minter System
: Combines ownership control with minter permissions
Controlled Emissions Start
: Emissions clock starts when ownership is renounced or
start_emissions()
is called
Minter-Based Minting
: Actual tokens are minted only when authorized minters call
emit()
Related
: See
GaugeController
for emission distribution and
VotingEscrow
for governance voting.
Public Variables
Emission State
reserve
(
uint256
) - Remaining tokens available to be minted
last_minted
(
uint256
) - Timestamp of the last minting event
max_mint_rate
(
uint256
) - Maximum emission rate (immutable)
Function Documentation
_emissions()
(internal)
Description:
Internal function that calculates the amount of tokens to emit based on time elapsed and rate factor. Uses exponential decay formula.
Returns:
uint256
- Amount of tokens to emit.
Input
Type
Description
t
uint256
Target timestamp for emission calculation
rate_factor
uint256
Rate factor (100% = 10^18)
📄 View Source Code
@internal
@view
def
_emissions
(
t
:
uint256
,
rate_factor
:
uint256
)
-
>
uint256
:
assert
rate_factor
<=
10
**
18
last_minted
:
uint256
=
self
.
last_minted
if
last_minted
==
0
or
t
<=
last_minted
:
return
0
else
:
dt
:
int256
=
convert
(
t
-
last_minted
,
int256
)
rate_36
:
int256
=
convert
(
max_mint_rate
*
rate_factor
,
int256
)
reserve
:
int256
=
convert
(
self
.
reserve
,
int256
)
return
convert
(
reserve
*
(
10
**
18
-
math
.
_wad_exp
(
-
dt
*
rate_36
//
10
**
18
)
)
//
10
**
18
,
uint256
)
Formula:
amount = reserve * (1 - exp(-dt * max_mint_rate * rate_factor / 10^18))
Where
rate_factor ∈ [0, 10^18]
and
dt
is the time elapsed since last mint.
preview_emissions()
Description:
View function to preview the amount of tokens that would be emitted for a given timestamp and rate factor.
Note:
This is the token-level
preview_emissions()
. The
GaugeController
also has a
preview_emissions(gauge, at_time)
function for per-gauge emission previews.
Returns:
uint256
- Preview of tokens to be emitted.
Input
Type
Description
t
uint256
Target timestamp for emission calculation
rate_factor
uint256
Rate factor (100% = 10^18)
📄 View Source Code
@external
@view
def
preview_emissions
(
t
:
uint256
,
rate_factor
:
uint256
)
-
>
uint256
:
return
self
.
_emissions
(
t
,
rate_factor
)
start_emissions()
Description:
Starts the emission process by setting the initial timestamp. Only callable by the owner.
📄 View Source Code
@external
def
start_emissions
(
)
:
ownable
.
_check_owner
(
)
if
self
.
last_minted
==
0
:
self
.
last_minted
=
block
.
timestamp
renounce_ownership()
Description:
Renounces ownership and forces emissions 프로젝트로 돌아가기