Skip to content

Files

Latest commit

ada45e6 · Jun 2, 2022

History

History
367 lines (237 loc) · 7.6 KB

Cauldron.md

File metadata and controls

367 lines (237 loc) · 7.6 KB

Cauldron

CauldronMath

add

function add(uint128 x, int128 y) internal pure returns (uint128 z)

Add a number (which might be negative) to a positive, and revert if the result is negative.

Cauldron

AssetAdded

event AssetAdded(bytes6 assetId, address asset)

SeriesAdded

event SeriesAdded(bytes6 seriesId, bytes6 baseId, address fyToken)

IlkAdded

event IlkAdded(bytes6 seriesId, bytes6 ilkId)

SpotOracleAdded

event SpotOracleAdded(bytes6 baseId, bytes6 ilkId, address oracle, uint32 ratio)

RateOracleAdded

event RateOracleAdded(bytes6 baseId, address oracle)

DebtLimitsSet

event DebtLimitsSet(bytes6 baseId, bytes6 ilkId, uint96 max, uint24 min, uint8 dec)

VaultBuilt

event VaultBuilt(bytes12 vaultId, address owner, bytes6 seriesId, bytes6 ilkId)

VaultTweaked

event VaultTweaked(bytes12 vaultId, bytes6 seriesId, bytes6 ilkId)

VaultDestroyed

event VaultDestroyed(bytes12 vaultId)

VaultGiven

event VaultGiven(bytes12 vaultId, address receiver)

VaultPoured

event VaultPoured(bytes12 vaultId, bytes6 seriesId, bytes6 ilkId, int128 ink, int128 art)

VaultStirred

event VaultStirred(bytes12 from, bytes12 to, uint128 ink, uint128 art)

VaultRolled

event VaultRolled(bytes12 vaultId, bytes6 seriesId, uint128 art)

SeriesMatured

event SeriesMatured(bytes6 seriesId, uint256 rateAtMaturity)

assets

mapping(bytes6 => address) assets

series

mapping(bytes6 => struct DataTypes.Series) series

ilks

mapping(bytes6 => mapping(bytes6 => bool)) ilks

lendingOracles

mapping(bytes6 => contract IOracle) lendingOracles

spotOracles

mapping(bytes6 => mapping(bytes6 => struct DataTypes.SpotOracle)) spotOracles

debt

mapping(bytes6 => mapping(bytes6 => struct DataTypes.Debt)) debt

ratesAtMaturity

mapping(bytes6 => uint256) ratesAtMaturity

vaults

mapping(bytes12 => struct DataTypes.Vault) vaults

balances

mapping(bytes12 => struct DataTypes.Balances) balances

addAsset

function addAsset(bytes6 assetId, address asset) external

Add a new Asset.

setDebtLimits

function setDebtLimits(bytes6 baseId, bytes6 ilkId, uint96 max, uint24 min, uint8 dec) external

Set the maximum and minimum debt for an underlying and ilk pair. Can be reset.

setLendingOracle

function setLendingOracle(bytes6 baseId, contract IOracle oracle) external

Set a rate oracle. Can be reset.

setSpotOracle

function setSpotOracle(bytes6 baseId, bytes6 ilkId, contract IOracle oracle, uint32 ratio) external

Set a spot oracle and its collateralization ratio. Can be reset.

addSeries

function addSeries(bytes6 seriesId, bytes6 baseId, contract IFYToken fyToken) external

Add a new series

addIlks

function addIlks(bytes6 seriesId, bytes6[] ilkIds) external

Add a new Ilk (approve an asset as collateral for a series).

build

function build(address owner, bytes12 vaultId, bytes6 seriesId, bytes6 ilkId) external returns (struct DataTypes.Vault vault)

Create a new vault, linked to a series (and therefore underlying) and a collateral

destroy

function destroy(bytes12 vaultId) external

Destroy an empty vault. Used to recover gas costs.

_tweak

function _tweak(bytes12 vaultId, bytes6 seriesId, bytes6 ilkId) internal returns (struct DataTypes.Vault vault)

Change a vault series and/or collateral types. We can change the series if there is no debt, or assets if there are no assets

tweak

function tweak(bytes12 vaultId, bytes6 seriesId, bytes6 ilkId) external returns (struct DataTypes.Vault vault)

Change a vault series and/or collateral types. We can change the series if there is no debt, or assets if there are no assets

_give

function _give(bytes12 vaultId, address receiver) internal returns (struct DataTypes.Vault vault)

Transfer a vault to another user.

give

function give(bytes12 vaultId, address receiver) external returns (struct DataTypes.Vault vault)

Transfer a vault to another user.

vaultData

function vaultData(bytes12 vaultId, bool getSeries) internal view returns (struct DataTypes.Vault vault_, struct DataTypes.Series series_, struct DataTypes.Balances balances_)

debtFromBase

function debtFromBase(bytes6 seriesId, uint128 base) external returns (uint128 art)

Think about rounding up if using, since we are dividing.

Convert a debt amount for a series from base to fyToken terms.

debtToBase

function debtToBase(bytes6 seriesId, uint128 art) external returns (uint128 base)

Convert a debt amount for a series from fyToken to base terms

stir

function stir(bytes12 from, bytes12 to, uint128 ink, uint128 art) external returns (struct DataTypes.Balances, struct DataTypes.Balances)

Move collateral and debt between vaults.

_pour

function _pour(bytes12 vaultId, struct DataTypes.Vault vault_, struct DataTypes.Balances balances_, struct DataTypes.Series series_, int128 ink, int128 art) internal returns (struct DataTypes.Balances)

Add collateral and borrow from vault, pull assets from and push borrowed asset to user Or, repay to vault and remove collateral, pull borrowed asset from and push assets to user

pour

function pour(bytes12 vaultId, int128 ink, int128 art) external virtual returns (struct DataTypes.Balances)

Manipulate a vault, ensuring it is collateralized afterwards. To be used by debt management contracts.

slurp

function slurp(bytes12 vaultId, uint128 ink, uint128 art) external returns (struct DataTypes.Balances)

Reduce debt and collateral from a vault, ignoring collateralization checks. To be used by liquidation engines.

roll

function roll(bytes12 vaultId, bytes6 newSeriesId, int128 art) external returns (struct DataTypes.Vault, struct DataTypes.Balances)

Change series and debt of a vault. The module calling this function also needs to buy underlying in the pool for the new series, and sell it in pool for the old series.

level

function level(bytes12 vaultId) external returns (int256)

Return the collateralization level of a vault. It will be negative if undercollateralized.

mature

function mature(bytes6 seriesId) external

Record the borrowing rate at maturity for a series

_mature

function _mature(bytes6 seriesId, struct DataTypes.Series series_) internal

Record the borrowing rate at maturity for a series

accrual

function accrual(bytes6 seriesId) external returns (uint256)

Retrieve the rate accrual since maturity, maturing if necessary.

_accrual

function _accrual(bytes6 seriesId, struct DataTypes.Series series_) private returns (uint256 accrual_)

Retrieve the rate accrual since maturity, maturing if necessary. Note: Call only after checking we are past maturity

_level

function _level(struct DataTypes.Vault vault_, struct DataTypes.Balances balances_, struct DataTypes.Series series_) internal returns (int256)

Return the collateralization level of a vault. It will be negative if undercollateralized.