Vault Depository
[NEW Experimental] Bank Depository addon for time-locked vaults with prepaid gStable interest and ability to transfer to other vaults.
Last updated
[NEW Experimental] Bank Depository addon for time-locked vaults with prepaid gStable interest and ability to transfer to other vaults.
Last updated
Mainnet Soon
Nile
Github
The VaultDepository
contract is designed to facilitate the deposit, redemption, and transfer of gStable tokens. It includes additional features such as pausing functionality, credit limits, and lock periods on deposits. Let's break down its key functionalities in a simplified manner:
The contract inherits from the AdminAuth
, Pausable
, and ReentrancyGuard
contracts. These provide administrative authorization, pausing and resuming functionality, and protection against reentrancy attacks, respectively.
There are several state variables declared at the beginning of the contract:
basisPointCredit
: Represents the basis point credit used to calculate the credit limit for each deposited amount.
maxTransferPercent
: Specifies the maximum percentage of deposited gStable tokens that can be transferred by an account.
gStableIntervalMap
: Maps gStable token IDs to their respective lock periods (in minutes).
vaultBalances
: Tracks the balances of gStable tokens deposited by users in the vault.
gStableLockPeriodMap
: Maps gStable token IDs to individual lock periods for each user.
transferableBalances
: Stores the transferable balances of gStable tokens for each user.
Events are emitted to provide information about important contract operations:
Deposit
: Triggered when a user deposits gStable tokens into the vault.
Mint
: Fired when credit limit tokens are minted to a user after a deposit.
Redeem
: Indicates that a user has redeemed gStable tokens from the vault.
Transfer
: Signals a transfer of gStable tokens between users.
The contract constructor takes three parameters:
bankDepositoryAddress
: Address of the BankDepository contract that handles the movement of gStable tokens.
basisPointCredit_
: The basis point credit value to determine the credit limit for each deposit.
gStableLookupAddress_
: Address of the gStableManager contract used to interact with gStable tokens.
The contract defines several modifiers:
onlyPositive
: Ensures that a value passed to a function is greater than zero.
isGStable
: Verifies that the specified token ID is not a stable coin.
hasGStableAddress
: Checks if a gStable token exists for the given ID.
The contract includes functions to pause and unpause the contract, set the BankDepository address, set the basis point credit value, and set the gStableLookup address. These functions can only be called by the contract admin.
The setLockInterval
function allows the admin to set the lock period for a specific gStable token ID.
The setMaxTransferPercent
function allows the admin to set the maximum transfer percentage of gStable tokens for users.
The transferDeposit
function enables users to transfer gStable tokens to the vault:
The transferable amount is calculated based on the deposited balance and the specified maximum transfer percentage.
The gStable tokens are moved from the user's account to the vault using the BankDepository contract.
The vault balances are updated, and the deposit is locked for a specific period.
The transferable balance and credit limit for the user are adjusted accordingly.
Events are emitted to reflect the deposit and minting of credit limit tokens.
The redeem
function allows users to redeem their deposited gStable tokens from the vault:
The function checks if the user has a sufficient balance in the vault and if the lock period has expired.
The gStable tokens are moved from the vault back to the user's account using the BankDepository contract.
The vault balances are updated.
An event is emitted to indicate the redemption.
The transferBalance
function allows users to transfer gStable tokens from their vault to another user:
The function checks if the user has a sufficient transferable balance for the specified token.
The transferable balance of the sender and the balances of the recipient's vault and transferable balances are updated accordingly.
An event is emitted to indicate the transfer.
Explanation Generated by Sorrel's AIA Team - Powered by ChatGPT