Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nodejs 20.12.2
yarn 1.22.19
solidity 0.8.24
solidity 0.8.25
47 changes: 23 additions & 24 deletions contracts/talent/TalentVaultV3.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
Expand Down Expand Up @@ -89,14 +89,12 @@ contract TalentVaultV3 is ERC4626, Ownable, ReentrancyGuard {
/// @notice Create a new Talent Vault V3 contract
/// @param _token The token that will be deposited into the contract
/// @param _yieldSource The wallet paying for the yield
constructor(
IERC20 _token,
address _yieldSource
) ERC4626(_token) ERC20("TalentVaultV3", "sTALENT3") Ownable(msg.sender) {
if (
address(_token) == address(0) ||
address(_yieldSource) == address(0)
) {
constructor(IERC20 _token, address _yieldSource)
ERC4626(_token)
ERC20("TalentVaultV3", "sTALENT3")
Ownable(msg.sender)
{
if (address(_token) == address(0) || address(_yieldSource) == address(0)) {
revert InvalidAddress();
}

Expand Down Expand Up @@ -195,6 +193,7 @@ contract TalentVaultV3 is ERC4626, Ownable, ReentrancyGuard {

/// @notice Get the maximum deposit amount for an address
/// @param receiver The address to get the maximum deposit amount for
/// @return The maximum deposit amount for the address
function maxDeposit(address receiver) public view virtual override returns (uint256) {
if (maxDepositLimitFlags[receiver]) {
return maxDeposits[receiver];
Expand All @@ -205,15 +204,17 @@ contract TalentVaultV3 is ERC4626, Ownable, ReentrancyGuard {

/// @notice Get the maximum deposit amount for an address
/// @param receiver The address to get the maximum deposit amount for
/// @return The maximum deposit amount for the address
function maxMint(address receiver) public view virtual override returns (uint256) {
return maxDeposit(receiver);
}

/// @notice Deposit tokens into the contract
/// @param assets The amount of tokens to deposit
/// @param receiver The address to deposit the tokens for
/// @return The number of tokens deposited
function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
if (assets <= 0) {
if (assets == 0) {
revert InvalidDepositAmount();
}

Expand All @@ -237,6 +238,7 @@ contract TalentVaultV3 is ERC4626, Ownable, ReentrancyGuard {
/// @notice Deposit tokens into the contract
/// @param shares The amount of shares to deposit
/// @param receiver The address to deposit the shares for
/// @return The number of tokens deposited
function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
return deposit(shares, receiver);
}
Expand All @@ -245,7 +247,7 @@ contract TalentVaultV3 is ERC4626, Ownable, ReentrancyGuard {
/// the deposit meta data including minting any rewards
/// @param account The address of the user to refresh
function refreshForAddress(address account) public {
if (balanceOf(account) <= 0) {
if (balanceOf(account) == 0) {
UserBalanceMeta storage balanceMeta = userBalanceMeta[account];
balanceMeta.lastRewardCalculation = block.timestamp;
return;
Expand All @@ -267,20 +269,21 @@ contract TalentVaultV3 is ERC4626, Ownable, ReentrancyGuard {
}

/// @notice This reverts because TalentVault is non-transferable
/// @dev reverts with TalentVaultNonTansferable
/// @dev reverts with TalentVaultNonTransferable
function transferFrom(address, address, uint256) public virtual override(ERC20, IERC20) returns (bool) {
revert TalentVaultNonTransferable();
}

/// @notice Calculate the accrued rewards for an address
/// @param user The address to calculate the accrued rewards for
/// @return The amount of accrued rewards for the user
function calculateRewards(address user) public view returns (uint256) {
UserBalanceMeta storage balanceMeta = userBalanceMeta[user];

if (!yieldRewardsFlag) {
return 0;
}

UserBalanceMeta storage balanceMeta = userBalanceMeta[user];

uint256 userBalance = balanceOf(user);

uint256 endTime;
Expand All @@ -294,9 +297,7 @@ contract TalentVaultV3 is ERC4626, Ownable, ReentrancyGuard {
uint256 timeElapsed;

if (block.timestamp > endTime) {
timeElapsed = endTime > balanceMeta.lastRewardCalculation
? endTime - balanceMeta.lastRewardCalculation
: 0;
timeElapsed = endTime > balanceMeta.lastRewardCalculation ? endTime - balanceMeta.lastRewardCalculation : 0;
} else {
timeElapsed = block.timestamp - balanceMeta.lastRewardCalculation;
}
Expand Down Expand Up @@ -339,13 +340,11 @@ contract TalentVaultV3 is ERC4626, Ownable, ReentrancyGuard {
/// @param owner The address of the owner
/// @param assets The amount of tokens to withdraw
/// @param shares The amount of shares to withdraw
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256 shares
) internal virtual override {
function _withdraw(address caller, address receiver, address owner, uint256 assets, uint256 shares)
internal
virtual
override
{
UserBalanceMeta storage ownerUserBalanceMeta = userBalanceMeta[owner];

if (ownerUserBalanceMeta.lastDepositAt + lockPeriod > block.timestamp) {
Expand Down
Loading