Overview
The crvUSD Factory enables the creation of new markets and adjustments, including setting a new fee receiver, modifying the debt ceiling of an existing market, or updating blueprint implementations.
Other than the pool factory, this factory does not allow permissionless deployment of new markets. Only its admin
, the CurveOwnershipAgent, can call to add a market. Therefore, adding a new market requires a successfully passed DAO vote.
Contract Source & Deployment
crvUSD Market Factory contract is deployed to the Ethereum mainnet at: 0xC9332fdCB1C491Dcc683bAe86Fe3cb70360738BC.
Source code available on Github.
Debt Ceilings¶
debt_ceiling
¶
ControllerFactory.debt_ceiling(agr0: address) -> uint256: view
Getter for the current debt ceiling of a market.
Returns: debt ceiling (uint256
).
Input | Type | Description |
---|---|---|
arg0 | address | Address of the controller |
debt_ceiling_residual
¶
ControllerFactory.debt_ceiling_residual(arg0: address) -> uint256: view
Getter for the residual debt ceiling for a market.
Returns: debt ceiling residual (uint256
).
Input | Type | Description |
---|---|---|
arg0 | address | Address of the controller |
rug_debt_ceiling
¶
ControllerFactory.rug_debt_ceiling(_to: address):
Function to remove stablecoins above the debt seiling from a controller and burn them. This function is used to burn residual crvUSD when the debt ceiling was lowered.
Input | Type | Description |
---|---|---|
_to | address | Address of the controller to remove stablecoins from |
Source code
@external
@nonreentrant('lock')
def rug_debt_ceiling(_to: address):
"""
@notice Remove stablecoins above the debt ceiling from the address and burn them
@param _to Address to remove stablecoins from
"""
self._set_debt_ceiling(_to, self.debt_ceiling[_to], False)
@internal
def _set_debt_ceiling(addr: address, debt_ceiling: uint256, update: bool):
"""
@notice Set debt ceiling for a market
@param addr Controller address
@param debt_ceiling Value for stablecoin debt ceiling
@param update Whether to actually update the debt ceiling (False is used for burning the residuals)
"""
old_debt_residual: uint256 = self.debt_ceiling_residual[addr]
if debt_ceiling > old_debt_residual:
to_mint: uint256 = debt_ceiling - old_debt_residual
STABLECOIN.mint(addr, to_mint)
self.debt_ceiling_residual[addr] = debt_ceiling
log MintForMarket(addr, to_mint)
if debt_ceiling < old_debt_residual:
diff: uint256 = min(old_debt_residual - debt_ceiling, STABLECOIN.balanceOf(addr))
STABLECOIN.burnFrom(addr, diff)
self.debt_ceiling_residual[addr] = old_debt_residual - diff
log RemoveFromMarket(addr, diff)
if update:
self.debt_ceiling[addr] = debt_ceiling
log SetDebtCeiling(addr, debt_ceiling)
Fee Receiver¶
The fee receiver is the address that receives the claimed fees when calling collect_fees()
on the Controller. A new receiver can be set by the admin
of the contract, which is the CurveOwnershipAgent.
fee_receiver
¶
ControllerFactory.fee_receiver() -> address: view
Getter for the fee receiver address.
Returns: address
of fee receiver.
Source code
fee_receiver: public(address)
@external
def __init__(stablecoin: ERC20,
admin: address,
fee_receiver: address,
weth: address):
"""
@notice Factory which creates both controllers and AMMs from blueprints
@param stablecoin Stablecoin address
@param admin Admin of the factory (ideally DAO)
@param fee_receiver Receiver of interest and admin fees
@param weth Address of WETH contract address
"""
STABLECOIN = stablecoin
self.admin = admin
self.fee_receiver = fee_receiver
WETH = weth
Implementations¶
Implementations are blueprint contracts used to deploy new markets. When calling add_market
, Controller and AMM are created from the current implementations.
controller_implementation
¶
ControllerFactory.controller_implementation() -> address: view
Getter for controller implementation address.
Returns: implementation (address
).
amm_implementation
¶
ControllerFactory.amm_implementation() -> address: view
Getter for amm implementation address.
Returns: implementation (address
).
Contract Info Methods¶
stablecoin
¶
ControllerFactory.stablecoin() -> address: view
Getter for the stablecoin address.
Returns: stablecoin (address
).
Source code
STABLECOIN: immutable(ERC20)
@external
def __init__(stablecoin: ERC20,
admin: address,
fee_receiver: address,
weth: address):
"""
@notice Factory which creates both controllers and AMMs from blueprints
@param stablecoin Stablecoin address
@param admin Admin of the factory (ideally DAO)
@param fee_receiver Receiver of interest and admin fees
@param weth Address of WETH contract address
"""
STABLECOIN = stablecoin
self.admin = admin
self.fee_receiver = fee_receiver
WETH = weth
total_debt
¶
ControllerFactory.total_debt() -> uint256: view
Getter for the sum of all debts across the controllers.
Returns: total amount of debt (uint256
).
Source code
get_controller
¶
ControllerFactory.get_controller(collateral: address, i: uint256 = 0) -> address:
Getter for the controller address for collateral
.
Returns: controller address
.
Input | Type | Description |
---|---|---|
collateral | address | Address of collateral token |
i | uint256 | Index to iterate over several controller for the same collateral if needed |
Source code
@external
@view
def get_controller(collateral: address, i: uint256 = 0) -> address:
"""
@notice Get controller address for collateral
@param collateral Address of collateral token
@param i Iterate over several controllers for collateral if needed
"""
return self.controllers[self.collaterals_index[collateral][i] - 2**128]
get_amm
¶
ControllerFactory.get_amm(collateral: address, i: uint256 = 0) -> address:
Getter for the amm address for collateral
.
Returns: amm address
.
Input | Type | Description |
---|---|---|
collateral | address | Address of collateral token |
i | uint256 | Index to iterate over several amms for the same collateral if needed |
Source code
controllers
¶
ControllerFactory.controllers(arg0: uint256) -> address:
Getter for the controller address at index arg0
.
Returns: controller address
at specific index.
Input | Type | Description |
---|---|---|
arg0 | uint256 | Index |
Source code
amms
¶
ControllerFactory.amms(arg0: uint256) -> address:
Getter for the amm address at index arg0
.
Returns: AMM address
at specific index.
Input | Type | Description |
---|---|---|
arg0 | uint256 | Index |
n_collaterals
¶
ControllerFactory.n_collaterals() -> uint256: view
Getter for the number of collaterals.
Returns: number of collaterals (uint256
).
collaterals
¶
ControllerFactory.collaterals(arg0: uint256) -> address: view
Getter for the collateral addresses at index arg0
.
Returns: address
of collateral.
Input | Type | Description |
---|---|---|
arg0 | uint256 | Index |
collaterals_index
¶
ControllerFactory.collaterals(arg0: address, arg1: uint256) -> uint256: view
Getter for the index of a controller for arg0
.
Returns: index (uint256
).
Note
The returned value is \(2^{128}\) + index.
Input | Type | Description |
---|---|---|
arg0 | address | Address of collateral |
arg0 | uint256 | Index |
WETH
¶
ControllerFactory.WETH() -> address: view
Getter for WETH address.
Returns: address
of WETH.
Source code
WETH: public(immutable(address))
@external
def __init__(stablecoin: ERC20,
admin: address,
fee_receiver: address,
weth: address):
"""
@notice Factory which creates both controllers and AMMs from blueprints
@param stablecoin Stablecoin address
@param admin Admin of the factory (ideally DAO)
@param fee_receiver Receiver of interest and admin fees
@param weth Address of WETH contract address
"""
STABLECOIN = stablecoin
self.admin = admin
self.fee_receiver = fee_receiver
WETH = weth