Credit Vault
v1.1
Last updated
v1.1
Last updated
The Credit Vault implements the vault standard ERC4626, so the standard documentation can be referenced for most interfaces. Users deposit stablecoins into a vault and receive an interest-accruing deposit token. Approved borrowers can borrow from the vault and interest rates are set by admins.
ERC20 standard - Security Token
rate (uint256) the fixed interest rate which is set by the borrower. Range value (0 - 100000)
stablecoin (address) stable coin token contract address which allowed to deposit to the pool and earn interest
maxPoolValue (uint256) max value can supply to the pool
poolValue (uint256) total underlying token
accrualTimestamp (uint256) timestamp that interest was last accrued at
totalBorrowed (uint256) total borrowed token
If a vault does not have enough liquidity to support a withdrawal request by a lender, the transaction will not revert. Instead, withdrawal requests will be added to a list of withdrawal requests that are filled as liquidity becomes available.
When liquidity becomes available, either through a loan repayment or a new deposit, the withdrawal queue is checked for open withdrawal requests. Withdrawal requests are processed using the First-In-First-Out (“FIFO”) method, meaning that the oldest withdrawal request is always processed first. The amount of new liquidity dictates how many withdrawals are processed. Available liquidity should be used to fulfill withdrawal requests until there are no withdrawal requests remaining, and partial fulfillments should be supported.
When a withdrawal request is filled, the USDC is held in the vault on behalf of the user. The user can then claim the USDC from the vault at any time. The USDC used to fill withdrawal requests should not be eligible for withdrawal by other users nor borrowers.
Build contracts:
Test contracts:
The contract implemented ERC4626 and follows Stellar contract convention, example
totalAssets changed to total_assets, and with additional interfaces:
ERC4626 interface
total_claimable_assets
The total amount of processed withdraw users can claim
queue_process
Process the withdrawal queue when there is available underlying token
get_withdraw_queue_detail_list
Get the detail of a withdraw queue batch
@param offset_ the index of the previous node, put 0 to start from first node
@param size_ the size of the queue batch to return
get_withdraw_queue_size
Get the current size of queue list (total number of withdraw requests)
cancel_withdraw
Cancel withdraw request of sender by queue index
claimable_assets
The amount of processed withdraw an user can claim
total_borrowed_assets
Returns the total amount of assets borrowed by pool
pending_withdraw_assets
Returns the total amount assets of pending withdraw requests
claim_withdraw
This function claims the processed amount of assets from previous withdraw/redeem request of sender
token_address
Returns the vault token address which presents the shares of each user in the vault
rate
Returns the interest rate value of the pool (0 - 10000).
QUEUE DETAIL |
---|
QUEUE PROCESS LIMIT |
---|
CLAIMABLE WITHDRAW AMOUNT |
---|
TOTAL UNCLAIMED WITHDRAW AMOUNT |
---|
TOTAL PENDING WITHDRAW AMOUNT |
---|
CANCEL WITHDRAW REQUEST |
---|
CANCEL WITHDRAW REQUESTS |
---|
GET WITHDRAW QUEUE SIZE |
---|
GET WITHDRAW QUEUE DETAIL LIST |
---|
SET QUEUE PROCESS LIMIT |
---|
PROCESS THE FIRST BATCH OF QUEUE |
---|
BORROW FUND |
---|
REPAY DEBT |
---|
SET NEW INTEREST RATE |
---|
EVENTS |
---|
/**
* @dev Get the withdraw request detail in queue by node index
*
* @return RedeemRequest{ address redeemer; uint256 amount; }
*/
function queueDetail(uint nodeIndex) external view returns(RedeemRequest);
/**
* @dev Batch size of queue list being process at each transaction
*
* @return batch size
*/
function queueProcessLimit() external view returns(uint256);
/**
* @dev The amount of processed withdraw an user can claim
*
* @return amount to claim
*/
function claimableAssets(address owner) external view returns(uint256);
/**
* @dev The total amount of processed withdraw users can claim
*
* @return total amount can claim
*/
function totalClaimableAssets() external view returns(uint256);
/**
* @dev The total withdraw request amount in queue
*
*/
function pendingWithdrawAssets() external view returns(uint256);
/**
* @dev Cancel withdraw request of sender
*
*/
function cancelWithdraw(uint nodeIndex) external;
/**
* @dev Cancel multi withdraw requests of sender
*
*/
function cancelWithdraws(uint256[] memory nodes) external;
/**
* @dev Get the current size of queue list (total number of withdraw requests)
*
* @return the current size of queue list
*/
function getWithdrawQueueSize() external view returns(uint256);
/**
* @dev Get the detail of a withdraw queue batch
*
* @param offset_ the index of the previous node, put 0 to start from first node
* @param size_ the size of the queue batch to return
*
* @returns (array of node index, array of corresponding withdraw request detail)
*/
function getWithdrawQueueDetailList(uint256 offset_, uint256 size_) external view returns(uint256[] memory, WithdrawRequest[] memory);
/**
* @notice Sets a new queue process limit
* @dev Admin function to set a new queue process limit
*/
function setQueueProcessLimit(uint256 limit_) virtual external;
/**
* @notice process the withdrawal queue when there is available underlying token.
* Should be run by contract itself, anyone trigger this function.
*/
function queueProcess() virtual public;
/**
* @dev Method to let borrower borrow token from the pool
*
* @param receiver_ Address to receive token
* @param amount_ Amount to transfer from the pool. Token in base decimal (1e18).
*/
function borrowFund(address receiver_, uint256 amount_) external;
/**
* @dev Borrower execute this function to repay token back to the pool
*
* @param amount_ Amount of token to repay. Token in token decimal.
*/
function repayDebt(uint256 amount_) external;
/**
* @dev Set new rate
*
* @param newRate_ New rate value. Rate value in range (0 - 100000)
*/
function setRate(uint256 newRate_) external;
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
event BorrowFund(address, uint256);
event Repay(address, uint256);
event MaxPoolValue(uint256, uint256);
event SetQueueProcessLimit(uint256);
event AddQueue(address, uint256);
event ClaimWithdraw(address, uint256);
event CancelQueue(address, uint256);
event ProcessedQueue(uint256 indexed node, address indexed receiver, uint256 assets);