Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research Staker Loan Threshold #202

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ pragma solidity >=0.8.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";

contract LenderCommitmentGroupShares is ERC20, Ownable {

using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;


uint8 private immutable DECIMALS;


mapping(address => uint256) public poolSharesPreparedToWithdrawForLender;
mapping(address => uint256) public poolSharesPreparedTimestamp;


// Using EnumerableSet to track unique holders
EnumerableSetUpgradeable.AddressSet private holders;

event SharesPrepared(
address recipient,
uint256 sharesAmount,
Expand All @@ -32,6 +39,7 @@ contract LenderCommitmentGroupShares is ERC20, Ownable {

function mint(address _recipient, uint256 _amount) external onlyOwner {
_mint(_recipient, _amount);
holders.add(_recipient);
}

function burn(address _burner, uint256 _amount, uint256 withdrawDelayTimeSeconds) external onlyOwner {
Expand All @@ -48,6 +56,7 @@ contract LenderCommitmentGroupShares is ERC20, Ownable {


_burn(_burner, _amount);
_removeHolderIfEmpty(_burner);
}

function decimals() public view virtual override returns (uint8) {
Expand All @@ -57,20 +66,29 @@ contract LenderCommitmentGroupShares is ERC20, Ownable {

// ----

function _afterTokenTransfer(
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
super._afterTokenTransfer(from, to, amount);

if (amount > 0) {
//reset prepared
poolSharesPreparedToWithdrawForLender[from] = 0;
poolSharesPreparedTimestamp[from] = block.timestamp;
poolSharesPreparedTimestamp[from] = block.timestamp;


if (from != address(0)) {
_removeHolderIfEmpty(from);
}

if (to != address(0)) {
holders.add(to);
}

}


}


Expand Down Expand Up @@ -120,7 +138,22 @@ contract LenderCommitmentGroupShares is ERC20, Ownable {
return true;
}

/**
* @notice Returns the list of all token holders.
*/
function getAllHolders() external view returns (address[] memory) {
return holders.values();
}

/**
* @notice Removes a holder if their balance reaches zero.
* @param account The address to check and remove.
*/
function _removeHolderIfEmpty(address account) internal {
if (balanceOf(account) == 0) {
holders.remove(account);
}
}



Expand Down
Loading