The Hard Vault contract is designed to hold LP (Liquidity Provider) tokens as collateral. The contract is ERC1155 compliant, which means that the underlying LP tokens are identified by casted tokenId from token address.
The Hard Vault contract has the following state variables:
config: The address of the protocol configuration contract.
The Hard Vault contract emits the following events:
Deposited: Emitted when a user deposits LP tokens into the vault.
Withdrawn: Emitted when a user withdraws LP tokens from the vault.
initialize(IProtocolConfig _config) external initializer
initializefunction is an initializer function that is called when the contract is deployed. It initializes the state variables of the contract.
_config(IProtocolConfig): The address of the protocol configuration contract.
_encodeTokenId(address uToken) internal pure returns (uint)
_encodeTokenIdfunction takes an underlying token address and encodes it into a token ID.
uToken(address): The address of the underlying token.
_decodeTokenId(uint tokenId) internal pure returns (address)
_decodeTokenIdfunction takes a token ID and decodes it into an underlying token address.
tokenId(uint): The token ID to decode.
balanceOfERC20(address token, address user) external view override returns (uint256)
balanceOfERC20function returns the balance of an underlying ERC20 token for a given user.
token: The address of the ERC20 token.
user: The address of the user.
getUnderlyingToken(uint256 tokenId) external pure override returns (address token)
getUnderlyingTokenfunction returns the underlying ERC20 token address for a given ERC1155 token ID.
tokenId: The ERC1155 token ID.
deposit(address token, uint256 amount) external override nonReentrant returns (uint256 shareAmount)
depositfunction allows a user to deposit underlying assets into the vault and issue share tokens.
token: The address of the underlying token to deposit.
amount: The amount of underlying tokens to deposit.
withdraw(address token, uint256 shareAmount) external override nonReentrant returns (uint256 withdrawAmount)
withdrawfunction allows a user to withdraw underlying assets from the vault.
token: The address of the underlying token to withdraw.
shareAmount: The amount of share tokens to redeem.