Skip to content

IKarakBaseVault

This is the base vault interface which was defined to enable an adapter pattern wherein any custom vault can fit into Karak Core by just implementing this interface.

interface IKarakBaseVault {
    /* ========== MUTATIVE FUNCTIONS ========== */
    function initialize(
        address _owner,
        address _operator,
        address _depositToken,
        string memory _name,
        string memory _symbol,
        bytes memory _extraData
    ) external;
 
    function slashAssets(uint256 slashPercentageWad, address slashingHandler)
        external
        returns (uint256 transferAmount);
 
    function pause(uint256 map) external;
 
    function unpause(uint256 map) external;
    /* ======================================== */
 
    /* ============ VIEW FUNCTIONS ============ */
    function totalAssets() external view returns (uint256);
 
    function name() external view returns (string memory);
 
    function symbol() external view returns (string memory);
 
    function decimals() external view returns (uint8);
 
    function vaultConfig() external pure returns (VaultLib.Config memory);
 
    function asset() external view returns (address);
    /* ======================================== */
}

Lets go over what each mutative function does and why its needed.

initialize()

The initialize function enables any vault that implements it to be deployable by Karak Core. There are some necessary details that Core needs which includes:

  1. _owner: Owner of the vault
  2. _operator: Operator that the vault is attached to implicitly delegating assets to it
  3. _depositToken: Address of the depositToken for the Vault
  4. _name: Name of the Vault
  5. _symbol: Symbol for identifying the Vault
  6. _extraData: This is where you can abi.encode any data that you want to be available for the initialize function of your custom vault. Take a look at how NativeVault utilizes this extra data.

slashAssets()

When there is a Karak Core receives a slashing request from a DSS it needs to slash the Vaults attached to the Operator. The slashAssets function along with the totalAssets and asset functions allow the Core Slasher library to slash a particular Vault. slashPercentageWad is the amount of assets that are going to be slashed and the Vault should handle the assets being slashed based on this value. slashingHandler is sent by the Core which was already registered with the asset of the Vault when it was allow listed in Core. Its not necessary to use a slashing handler though. For reference have a look at how the Default ERC20 Vault and NativeVault handle slashing.

pause() and unpause()

These two functions utilize the Karak Pauser contract for granular pausing of contract functions. It allows you to pause and unpause a single functionality of the vault if required. For reference, take a look at how all Karak v2 contracts implement pausing.