HardVault

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.

State Variables

The Hard Vault contract has the following state variables:

  • config: The address of the protocol configuration contract.

Events

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.

Functions

initialize

initialize(IProtocolConfig _config) external initializer

The initialize function is an initializer function that is called when the contract is deployed. It initializes the state variables of the contract.

Parameters:

  • _config(IProtocolConfig): The address of the protocol configuration contract.

_encodeTokenId

_encodeTokenId(address uToken) internal pure returns (uint)

The _encodeTokenId function takes an underlying token address and encodes it into a token ID.

Parameters:

  • uToken(address): The address of the underlying token.

_decodeTokenId

_decodeTokenId(uint tokenId) internal pure returns (address)

The _decodeTokenId function takes a token ID and decodes it into an underlying token address.

Parameters:

  • tokenId(uint): The token ID to decode.

balanceOfERC20

balanceOfERC20(address token, address user) external view override returns (uint256)

The balanceOfERC20 function returns the balance of an underlying ERC20 token for a given user.

Parameters:

  • token: The address of the ERC20 token.

  • user: The address of the user.

getUnderlyingToken

getUnderlyingToken(uint256 tokenId) external pure override returns (address token)

The getUnderlyingToken function returns the underlying ERC20 token address for a given ERC1155 token ID.

Parameters:

  • tokenId: The ERC1155 token ID.

deposit

deposit(address token, uint256 amount) external override nonReentrant returns (uint256 shareAmount)

The deposit function allows a user to deposit underlying assets into the vault and issue share tokens.

Parameters:

  • token: The address of the underlying token to deposit.

  • amount: The amount of underlying tokens to deposit.

withdraw

withdraw(address token, uint256 shareAmount) external override nonReentrant returns (uint256 withdrawAmount)

The withdraw function allows a user to withdraw underlying assets from the vault.

Parameters:

  • token: The address of the underlying token to withdraw.

  • shareAmount: The amount of share tokens to redeem.

Last updated