Links

Contracts Overview

This documentation is a work in progress!

Introduction

Contracts that Kresko has developed mainly fall into four categories:
  • Diamond: Contracts related to EIP-2535 diamond proxy pattern.
  • Core: Borrow/Mint/Liquidation state, logic and configuration.
  • Tokenization: Kresko Asset, Kresko Asset Anchor (Non-rebasing wrapper token) and KISS.
  • Utility: Non-protocol contracts like staking and helper contracts.

Diamond

Diamond proxy pattern (https://eips.ethereum.org/EIPS/eip-2535).
AuthorizationFacet
Enumerable access control based on the OpenZeppelin AccessControlEnumerable but is customized to work as a diamond proxy facet that uses shared diamond storage through a library.
Diamond
Proxy contract that holds the address and storage of he protocol. Main logic included is the fallback function which maps the incoming function signature to an implementation facet.
DiamondCutFacet
Functions for modifying the mapping of function selectors into their implementation facet and performing state upgrades when doing so.
DiamondLoupeFacet
Functions that allow inspection of the function selector to facet mappings inside the diamond proxy.
DiamondOwnershipFacet
Two-step ownership facet that handles ownership for the diamond.
DiamondState
ERC-2535 related storage in a single struct that is stored in the diamond storage.
DiamondStorage
Includes the diamond storage setter as a free function and the storage location hash.
DiamondTypes
Structs used within DiamondState.
ERC165Facet
Standard interface detection facet.
LibDiamondCut
Main upgradeability logic for the diamond proxy.
LibOwnership
Ownership handling logic for the diamond proxy.

Core

AccountStateFacet
View functions that can be used to obain information about account states within the protocol.
BurnFacet
Exposes the function to burn (repay) kresko assets.
BurnHelperFacet
Quality-of-life helper functions that deal with burning (repaying) kresko assets.
ConfigurationFacet
Authorized functions that allow the configuration of protocol state.
DepositWithdrawFacet
Functions to deal with collateral assets. Namely the deposit and withdraw of collateral assets.
LiquidationFacet
Exposes the core liquidation function and a view to calculate the maximum liquidatable value for a market pair in a user position.
MintFacet
Exposes the function to mint (borrow) kresko assets.
Modifiers
Contains all modifiers related to the diamond proxy and the protocol in separate abstract contracts.
SafetyCouncilFacet
Allows the safety council (multisig of 5) to toggle a pause status on each core functionality (Deposit/Withdraw/Repay/Borrow/Liquidation).
StateFacet
View functions that can be used to obtain information about the global state.
UIDataProviderFacet
View functions that are used by the Minter application.
LibAccount
Shared account state related functions.
LibAssetUtility
Utility functions that are connected to the Kresko Asset struct and Collateral Asset struct.
LibCalculation
Functions that perform calculations for open and close fee and liquidations.
LibCollateral
Logic and helpers for handling collateral actions and amounts.
LibDecimals
Decimal conversion utilities mainly involving oracle values and collateral assets.
LibKrAsset
Logic and helpers for handling kresko asset actions and amounts.
LibMint
Main state modifying logic for handling mints (borrows).
LibRepay
Main state modifying logic for handling repayment of debt.
LibUI
Frontend related structs and view functions.
MinterState
Main storage layout for the protocol defined as a struct.
MinterStorage
Includes the protocol storage setter as a free function and the storage location hash.
DiamondTypes
Structs used within the protocol.
UniswapV2Oracle
Oracle contract to get on-chain prices from any UniswapV2Pair. Non-upgradeable.

Tokenization

ERC4626Upgradeable
ERC4626 Tokenized Vault Standard, used by the non-rebasing wrapper token (Kresko Asset Anchor).
KreskoAsset
Mintable and burnable rebasing ERC-20. Minting and burning is controlled by AccessControlUpgradeable.
KreskoAssetAnchor
ERC-4626 that handles the pro-rata representation of Kresko Assets. Main purpose is to allow easier integration for the rebasing KreskoAsset with other protocols and chains.
KISS
Mintable, burnable and pausable ERC-20 token that only the protocol can mint and burn.
RebaseMath
Library that contains the positive and negative rebasing functions.

Utility

KrStaking
Staking contract that handles multiple pools and multiple reward tokens.
KrStakingHelper
Contract that contains helper functionality related to the KrStaking.