Skip to main content

LendFactory

The LendFactory is the entry point for creating new one-way lending markets. It deploys a triplet of contracts — Vault, LendController, and AMM — from blueprint implementations stored in an internal registry. Each market is fully isolated.

The factory uses Snekmate's ownable module for access control and pausable for emergency pause functionality.

LendFactory.vy

The source code for the LendFactory.vy contract can be found on GitHub. The contract is written in Vyper version 0.4.3.

Deployment addresses will be added once contracts are finalized.


Market Creation

create

LendFactory.create(_borrowed_token: address, _collateral_token: address, _A: uint256, _fee: uint256, _loan_discount: uint256, _liquidation_discount: uint256, _price_oracle: address, _monetary_policy: address, _name: String[64], _supply_limit: uint256) -> address[3]

Deploys a new lending market by creating a Vault, LendController, and AMM from their respective blueprints. Validates all parameters, initializes the triplet, and registers the market.

InputTypeDescription
_borrowed_tokenaddressToken that lenders deposit and borrowers receive
_collateral_tokenaddressToken used as collateral by borrowers
_Auint256Amplification coefficient — determines band width (~1/A)
_feeuint256Swap fee for the AMM
_loan_discountuint256Maximum discount for LTV calculation
_liquidation_discountuint256Discount at which liquidation can occur
_price_oracleaddressInitialized price oracle contract
_monetary_policyaddressInitialized monetary policy contract
_nameString[64]Name for the vault token
_supply_limituint256Maximum supply cap for the vault

Returns: array of three addresses — [vault, controller, amm] (address[3]).

Emits: NewVault event.

<>Source code
Example

Market Registry

market_count

LendFactory.market_count() -> uint256: view

Returns the total number of lending markets created by the factory.

Returns: number of markets (uint256).

<>Source code
Example

markets

LendFactory.markets(_n: uint256) -> Market: view

Returns the market info struct for a given market index.

InputTypeDescription
_nuint256Market index (0-based)

Returns: market struct containing vault, controller, amm, collateral token, borrowed token, and market index (Market).

<>Source code
Example

coins

LendFactory.coins(_vault_id: uint256) -> IERC20[2]: view

Returns the borrowed and collateral token addresses for a given vault.

InputTypeDescription
_vault_iduint256Vault index

Returns: array of [borrowed_token, collateral_token] (IERC20[2]).

<>Source code
Example

vaults_index

LendFactory.vaults_index(_vault: IVault) -> uint256: view

Returns the index of a vault in the factory registry. Uses a 2^128 offset internally — a return value of 0 means the vault is not registered.

InputTypeDescription
_vaultIVaultVault address to look up

Returns: vault index (uint256).

<>Source code
Example

Blueprints

amm_blueprint

LendFactory.amm_blueprint() -> address: view

Returns the current AMM blueprint address used for deploying new markets.

Returns: blueprint address (address).

<>Source code
Example

controller_blueprint

LendFactory.controller_blueprint() -> address: view

Returns the current controller blueprint address.

Returns: blueprint address (address).

<>Source code
Example

vault_blueprint

LendFactory.vault_blueprint() -> address: view

Returns the current vault blueprint address.

Returns: blueprint address (address).

<>Source code
Example

controller_view_blueprint

LendFactory.controller_view_blueprint() -> address: view

Returns the current controller view blueprint address.

Returns: blueprint address (address).

<>Source code
Example

Fee Receivers

fee_receiver

LendFactory.fee_receiver(_controller: address) -> address: view

Returns the fee receiver for a given controller. If a custom fee receiver is set, it returns that; otherwise, it returns the default fee receiver.

InputTypeDescription
_controlleraddressController address

Returns: fee receiver address (address).

<>Source code
Example

set_default_fee_receiver

LendFactory.set_default_fee_receiver(_fee_receiver: address)
Guarded Method by Snekmate 🐍

This function is only callable by the owner of the contract.

Sets the default fee receiver for all markets that don't have a custom one.

InputTypeDescription
_fee_receiveraddressNew default fee receiver address

Emits: SetFeeReceiver event.

<>Source code
Example

set_custom_fee_receiver

LendFactory.set_custom_fee_receiver(_controller: address, _fee_receiver: address)
Guarded Method by Snekmate 🐍

This function is only callable by the owner of the contract.

Sets a custom fee receiver for a specific market's controller.

InputTypeDescription
_controlleraddressController address
_fee_receiveraddressCustom fee receiver address

Emits: CustomSetFeeReceiver event.

<>Source code
Example

Contract Ownership

admin

LendFactory.admin() -> address: view

Returns the current owner of the factory contract.

Returns: owner address (address).

<>Source code
Example

pause

LendFactory.pause()
Guarded Method by Snekmate 🐍

This function is only callable by the owner of the contract.

Pauses the factory, preventing new market creation.

<>Source code
Example

unpause

LendFactory.unpause()
Guarded Method by Snekmate 🐍

This function is only callable by the owner of the contract.

Unpauses the factory, re-enabling market creation.

<>Source code
Example

Other Methods

version

LendFactory.version() -> String[5]: view

Returns the contract version string.

Returns: version (String[5]).

<>Source code
Example