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:
_owner
: Owner of the vault_operator
: Operator that the vault is attached to implicitly delegating assets to it_depositToken
: Address of the depositToken for the Vault_name
: Name of the Vault_symbol
: Symbol for identifying the Vault_extraData
: This is where you canabi.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.