Contract Interactions
Overview
This provides a V1 overview of how protocols and applications can integrate and interact with Karak's restaking smart contracts.
Terms
Vault: A vault serves as the storage for tokens, with each token having its own dedicated vault deployed.
VaultSupervisor: The VaultSupervisor contract acts as the central hub connecting all vaults, managing all deposit and withdrawal calls for each vault.
DelegationSupervisor: The DelegationSupervisor contract handles withdrawals and soon
Deposit
Deposit function: The deposit function takes in ERC-20 tokens that have been whitelisted.
function deposit(IVault vault, uint256 amount) returns (uint256 shares)
vault
: Vault you’d like to deposit in
amount
: Amount you’d like to deposit
shares
: The amount of shares allotted to you in the vault
Interface IVault
can be found here
Usage: IVault(address of Vault)
Deposit with Signature (Gasless approval)
The deposit with signature function can be used for tokens that have an ERC-20 Permit implementation.
function depositWithSignature(
IVault vault, address user,
uint256 value, uint256 deadline, Signature calldata permit,
Signature calldata vaultAllowance
) returns (uint256 shares)
vault
: Vault you’d like to deposit in
user
: Address of the user who will approve the allowance for ERC-20 tokens
value
: Amount you’d like to deposit
deadline
: The UNIX timestamp till the signature is valid
permit
: The signature for ERC-20 Permit approval
vaultAllowance
: The signature that specifies which vault to deposit and the amount
shares
: The amount of shares allotted to you in the vault
struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
}
Interface IVault
can be found here
Usage: IVault(address of Vault)
Withdraw
To withdraw tokens in a vault the user needs to call two functions on the DelegationSupervisor
:
First the user needs to call startWithdraw
function
function startWithdraw(
Withdraw.WithdrawRequest[] calldata withdrawalRequests
) external returns (bytes32[] memory withdrawalRoots, Withdraw.QueuedWithdrawal[] memory withdrawConfigs)
withdrawalRequests
: Array of the WithdrawRequest
struct.
struct WithdrawRequest {
IVault[] vaults;
uint256[] shares;
address withdrawer;
}
After the withdrawDelay
amount of time, which can be found by calling
function withdrawalDelay() external view override returns (uint256)
You can finish the withdrawal by calling finishWithdraw
on the DelegationSupervisor
function finishWithdraw(Withdraw.QueuedWithdrawal[] calldata startedWithdrawals) external
startedWithdrawals: Array of the QueuedWithdrawal
struct
struct QueuedWithdrawal {
address staker;
address delegatedTo;
uint256 nonce;
uint256 start;
WithdrawRequest request;
}