Skip to content

Default ERC20 Vault

The Karak Vault is a ERC-4626 based vault which again implements the same IKarakBaseVault interface. The code for the vault can be found here

Deploy

Deploying a instance of the default ERC20 vault by calling the deployVaults function on the Core contract:

struct Config {
    address asset;
    uint8 decimals;
    address operator;
    string name;
    string symbol;
    bytes extraData;
}
 
/// @dev pass address(0) for vaultImpl to use the default ERC20 vault
function deployVaults(Config[] calldata vaultConfigs, address vaultImpl)
    external
    returns (IKarakBaseVault[] memory vaults);

Depositing

Approve

Give the vault contract approval to transfer your tokens from your wallet to it.

IERC20(depositAsset).approve(address vaultAddr, uint256 amount);

Deposit

It's recommended you use the overload function with minSharesOut to prevent any possible front-running attacks.

vault.deposit(uint256 assets, address to, uint256 minSharesOut) returns (uint256 shares);

Optionally, you can use the simpler function without minSharesOut but

vault.deposit(uint256 assets, address to) returns (uint256 shares);

Withdrawing

Start Redeem

First, you need to start the withdraw process

vault.startRedeem(uint256 shares, address beneficiary) returns (bytes32 withdrawalKey);

Wait

After starting the withdrawal process, you have to wait MIN_WITHDRAWAL_DELAY amount of time which currently is 9 days.

Finish Redeem

Finally, you finish the withdrawal process

vault.function finishRedeem(bytes32 withdrawalKey)

where withdrawalKey is both returned by the startRedeem function and emitted in the StartedRedeem event.