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

DRAFT - FM_PC_ExternalPriceSetter, Oracle, blacklist contracts and interfaces implemented #696

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
f58effe
Contract structure defined
vendrell46 Nov 15, 2024
1222ef5
removed IFundingManager extension
vendrell46 Nov 21, 2024
562574c
IFundingManager_v1 needed
vendrell46 Nov 21, 2024
68b0426
extended IRedeemingBondingCurveBase_v1 as well
vendrell46 Nov 22, 2024
c31b5bb
ExternalPriceSetter, blacklist, Oracle and interfaces added
vendrell46 Nov 27, 2024
6986527
formatting files and adapting to the code of conduct
vendrell46 Nov 29, 2024
77c774c
ManualExternalPriceSetter_v1 modified as LM
vendrell46 Nov 30, 2024
b2f0bd4
added fees checks, paymentOrder to the process and defined role for b…
vendrell46 Dec 2, 2024
546648d
managing roles, renaming, and removing unneeded things
vendrell46 Dec 3, 2024
e668661
whitelist logic removed, blacklist fixes
vendrell46 Dec 4, 2024
1c8494e
missing logic implemented
vendrell46 Dec 4, 2024
ebd23e6
blacklist fixes and custom error added
vendrell46 Dec 5, 2024
555d49b
switched from role to mapping for blacklist manager
vendrell46 Dec 5, 2024
769ad9f
moved blacklist files to external, modified sell, and more context added
vendrell46 Dec 6, 2024
06faf1d
PAYMENT_QUEUE_ROLE added, _sellOrder overriden
vendrell46 Dec 6, 2024
8ee039b
emit_timestamp(IssuancePriceSet,RedemptionPriceSet),NatSpec
scab24 Dec 6, 2024
215d74a
fix: remove collateral transfer & collateral check
Zitzak Dec 9, 2024
5351bd7
style: run make fmt for formating
Zitzak Dec 9, 2024
6f13452
small fixes and documentation added
vendrell46 Dec 9, 2024
f7dfd0f
docs added for issuance and redemption setters
vendrell46 Dec 9, 2024
1bc0182
Rename ERC20Issuance_blacklist_v1.sol to ERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 10, 2024
3f1f96c
Rename IERC20Issuance_blacklist_v1.sol to IERC20Issuance_Blacklist_v1…
vendrell46 Dec 10, 2024
fbe5901
fixed executeRedemptionQueue, docs and renaming
vendrell46 Dec 10, 2024
faefdab
formatting natspec
vendrell46 Dec 10, 2024
f95e153
feat: add treasury collateral withdraw
Zitzak Dec 10, 2024
1ed8a19
Fix fmt
Zitzak Dec 10, 2024
3949b43
fix: typo
Zitzak Dec 10, 2024
ca5d9cd
fix: fmt
Zitzak Dec 10, 2024
01a5497
Merge pull request #2 from ZealynxSecurity/add_collateral_transfer
Zitzak Dec 10, 2024
279225f
fix: remove oracle from init
Zitzak Dec 10, 2024
ca9a999
Merge pull request #3 from ZealynxSecurity/removeOracleAddress
Zitzak Dec 11, 2024
e0edb54
fixed natspec
vendrell46 Dec 11, 2024
4840512
modifier moved
vendrell46 Dec 12, 2024
3560000
feat: update openRedemptionAmount
Zitzak Dec 13, 2024
31ac2db
Merge pull request #4 from ZealynxSecurity/update_open_redemption_amount
Zitzak Dec 13, 2024
ac44fd0
Update src/external/token/ERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 13, 2024
c9865a4
Update src/external/token/ERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 13, 2024
c959a01
applied suggestions
vendrell46 Dec 13, 2024
53c6ddf
Update src/external/token/ERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 13, 2024
300811a
Update src/external/token/ERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 13, 2024
879a710
Update src/external/token/ERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 13, 2024
c62f86b
formatting
vendrell46 Dec 13, 2024
74df730
Update src/modules/fundingManager/oracle/interfaces/IFM_PC_ExternalPr…
vendrell46 Dec 13, 2024
b620817
formatting
vendrell46 Dec 13, 2024
5684733
Merge branch 'dev-1' of https://github.com/ZealynxSecurity/InverterCo…
vendrell46 Dec 13, 2024
2382a1e
Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeemin…
vendrell46 Dec 13, 2024
d159c91
formatting
vendrell46 Dec 13, 2024
99487e8
Modifier buyingIsEnabled and sellingIsEnabled added
scab24 Dec 16, 2024
7922834
formatting, updating code from parent and adding interface check
vendrell46 Dec 16, 2024
202811e
Update src/external/token/ERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 16, 2024
5d54427
Update src/external/token/ERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 16, 2024
3eaaca6
Update src/modules/fundingManager/oracle/interfaces/ILM_ManualExterna…
vendrell46 Dec 16, 2024
36aa5ff
Update src/modules/fundingManager/oracle/interfaces/ILM_ManualExterna…
vendrell46 Dec 16, 2024
05dd502
Update src/modules/fundingManager/oracle/interfaces/IOraclePrice_v1.sol
vendrell46 Dec 16, 2024
6edb139
Update src/modules/fundingManager/oracle/interfaces/IOraclePrice_v1.sol
vendrell46 Dec 16, 2024
958b149
Update src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 16, 2024
eeeecc5
Update src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 16, 2024
ef5ee28
Update src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 16, 2024
4249811
Update src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol
vendrell46 Dec 16, 2024
639b912
Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeemin…
vendrell46 Dec 16, 2024
4a78370
Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeemin…
vendrell46 Dec 16, 2024
9f1b155
Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeemin…
vendrell46 Dec 16, 2024
37beaba
Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeemin…
vendrell46 Dec 16, 2024
ea40ace
Update src/modules/fundingManager/oracle/LM_ManualExternalPriceSetter…
vendrell46 Dec 16, 2024
9165e42
Update src/modules/fundingManager/oracle/LM_ManualExternalPriceSetter…
vendrell46 Dec 16, 2024
196dff7
formatting
vendrell46 Dec 16, 2024
0d9e3a9
formatting
vendrell46 Dec 16, 2024
38ff8a3
moved constants
vendrell46 Dec 16, 2024
18ec689
changed notice to dev
vendrell46 Dec 16, 2024
0b04e3e
adding named returned variable
vendrell46 Dec 16, 2024
c4c0a8e
modifier renamed and buyingIsEnabled added to buy
vendrell46 Dec 16, 2024
c44d773
return named variables to interface
vendrell46 Dec 16, 2024
2cdbf19
formatting
vendrell46 Dec 16, 2024
e1e4e16
fix: revert during deployment
Zitzak Dec 17, 2024
8af215e
Merge pull request #6 from ZealynxSecurity/fix_setting_error
Zitzak Dec 17, 2024
17d0965
fix issue with authorization
Zitzak Dec 17, 2024
0b77581
Merge pull request #7 from ZealynxSecurity/add_internal_setter_function
Zitzak Dec 17, 2024
e5708bb
fix: interface check
Zitzak Dec 17, 2024
04fe2ff
Merge pull request #8 from ZealynxSecurity/fix_interface_check
Zitzak Dec 17, 2024
8f7eeea
interface natspec same as contract
vendrell46 Dec 18, 2024
a52ef2e
line too long fixed
vendrell46 Dec 18, 2024
ddfbe94
removed dot from title
vendrell46 Dec 18, 2024
7fe761c
_ensureTokenBalance overriden
vendrell46 Dec 18, 2024
2cafb1c
remove function
Zitzak Dec 18, 2024
6b813f5
Merge branch 'dev-1' into remove_function
Zitzak Dec 18, 2024
93a79fe
fix fmt
Zitzak Dec 18, 2024
0344209
Merge pull request #9 from ZealynxSecurity/remove_function
Zitzak Dec 18, 2024
cc95149
Update src/modules/fundingManager/oracle/interfaces/IOraclePrice_v1.sol
Zitzak Dec 19, 2024
f42bf47
fix: Move LM_ManualPriceSetter into LM folder
Zitzak Dec 19, 2024
214238e
Merge pull request #10 from ZealynxSecurity/move_lm_to_right_folder
Zitzak Dec 19, 2024
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
212 changes: 212 additions & 0 deletions src/external/token/ERC20Issuance_Blacklist_v1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.23;

// Internal
import {ERC20Issuance_v1} from "@ex/token/ERC20Issuance_v1.sol";
import {IERC20Issuance_Blacklist_v1} from
"@ex/token/interfaces/IERC20Issuance_Blacklist_v1.sol";

// External
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {ERC20} from "@oz/token/ERC20/ERC20.sol";
import {ERC20Capped} from "@oz/token/ERC20/extensions/ERC20Capped.sol";

/**
* @title ERC20 Issuance Token with Blacklist Functionality
*
* @notice An ERC20 token implementation that extends ERC20Issuance_v1 with
* blacklisting capabilities. This allows accounts with the blacklist
* manager role to restrict specific addresses from participating in
* token operations.
*
* @dev This contract inherits from:
* - IERC20Issuance_Blacklist_v1.
* - ERC20Issuance_v1.
* Key features:
* - Individual address blacklisting.
* - Batch blacklisting operations.
* - Owner-controlled manager role assignment.
* - Blacklist manager controlled blacklist management.
* Blacklist operations are performed by accounts with the
* blacklist manager role, while the contract owner controls who
* can be a blacklist manager.
* All blacklist operations can only be performed by accounts with the
* blacklist manager role.
*
* @custom:security-contact [email protected]
* In case of any concerns or findings, please refer to
* our Security Policy at security.inverter.network or
* email us directly!
*
* @custom:version v1.0.0
*
* @custom:standard-version v1.0.0
*
* @author Zealynx Security
*/
contract ERC20Issuance_Blacklist_v1 is
IERC20Issuance_Blacklist_v1,
ERC20Issuance_v1
{
// -------------------------------------------------------------------------
// Constants

/// @notice Maximum number of addresses that can be blacklisted in a batch.
uint public constant BATCH_LIMIT = 200;

// -------------------------------------------------------------------------
// Storage

/// @notice Mapping of blacklisted addresses.
mapping(address account => bool isBlacklisted) private _blacklist;

/// @notice Mapping of blacklist manager addresses.
mapping(address account => bool isManager) private _isBlacklistManager;

// -------------------------------------------------------------------------
// Modifiers

/// @notice Modifier to check if the caller is a blacklist manager.
modifier onlyBlacklistManager() {
if (!_isBlacklistManager[_msgSender()]) {
revert ERC20Issuance_Blacklist_NotBlacklistManager();
}
_;
}

// -------------------------------------------------------------------------
// Constructor

/// @notice Constructor for ERC20Issuance_Blacklist_v1.
/// @param name_ Token name.
/// @param symbol_ Token symbol.
/// @param decimals_ Token decimals.
/// @param maxSupply_ Max token supply.
/// @param initialAdmin_ Initial admin address.
/// @param initialBlacklistManager_ Initial blacklist manager (typically an
/// EOA).
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
uint maxSupply_,
address initialAdmin_,
address initialBlacklistManager_
) ERC20Issuance_v1(name_, symbol_, decimals_, maxSupply_, initialAdmin_) {
_setBlacklistManager(initialBlacklistManager_, true);
}

// -------------------------------------------------------------------------
// View Functions

/// @inheritdoc IERC20Issuance_Blacklist_v1
function isBlacklisted(address account_) public view returns (bool) {
return _blacklist[account_];
}

/// @inheritdoc IERC20Issuance_Blacklist_v1
function isBlacklistManager(address account_) public view returns (bool) {
return _isBlacklistManager[account_];
}

// -------------------------------------------------------------------------
// External Functions

/// @inheritdoc IERC20Issuance_Blacklist_v1
function addToBlacklist(address account_) public onlyBlacklistManager {
if (account_ == address(0)) {
revert ERC20Issuance_Blacklist_ZeroAddress();
}
if (!isBlacklisted(account_)) {
_blacklist[account_] = true;
emit AddedToBlacklist(account_);
}
}

/// @inheritdoc IERC20Issuance_Blacklist_v1
function removeFromBlacklist(address account_)
public
onlyBlacklistManager
{
if (account_ == address(0)) {
revert ERC20Issuance_Blacklist_ZeroAddress();
}
if (isBlacklisted(account_)) {
_blacklist[account_] = false;
emit RemovedFromBlacklist(account_);
}
}

/// @inheritdoc IERC20Issuance_Blacklist_v1
function addToBlacklistBatched(address[] memory accounts_)
external
onlyBlacklistManager
{
uint totalAccounts = accounts_.length;
if (totalAccounts > BATCH_LIMIT) {
revert ERC20Issuance_Blacklist_BatchLimitExceeded(
totalAccounts, BATCH_LIMIT
);
}
for (uint i; i < totalAccounts; ++i) {
addToBlacklist(accounts_[i]);
}
}

/// @inheritdoc IERC20Issuance_Blacklist_v1
function removeFromBlacklistBatched(address[] memory accounts_)
external
onlyBlacklistManager
{
uint totalAccounts = accounts_.length;
if (totalAccounts > BATCH_LIMIT) {
revert ERC20Issuance_Blacklist_BatchLimitExceeded(
totalAccounts, BATCH_LIMIT
);
}
for (uint i; i < totalAccounts; ++i) {
removeFromBlacklist(accounts_[i]);
}
}

/// @inheritdoc IERC20Issuance_Blacklist_v1
function setBlacklistManager(address manager_, bool allowed_)
external
onlyOwner
{
_setBlacklistManager(manager_, allowed_);
}

// -------------------------------------------------------------------------
// Internal Functions

/// @notice Internal hook to enforce blacklist restrictions on token transfers.
/// @dev Overrides ERC20Capped._update to add blacklist checks.
/// @param from_ Address tokens are transferred from.
/// @param to_ Address tokens are transferred to.
/// @param amount_ Number of tokens to transfer.
/// @inheritdoc ERC20Capped
function _update(address from_, address to_, uint amount_)
internal
override(ERC20Capped)
{
if (isBlacklisted(from_)) {
revert ERC20Issuance_Blacklist_BlacklistedAddress(from_);
}
if (isBlacklisted(to_)) {
revert ERC20Issuance_Blacklist_BlacklistedAddress(to_);
}
super._update(from_, to_, amount_);
}

/// @notice Internal function to set a blacklist manager.
/// @param manager_ Address to set as blacklist manager.
/// @param allowed_ Whether to grant or revoke the blacklist manager role.
function _setBlacklistManager(address manager_, bool allowed_) internal {
if (manager_ == address(0)) {
revert ERC20Issuance_Blacklist_ZeroAddress();
}
_isBlacklistManager[manager_] = allowed_;
emit BlacklistManagerUpdated(manager_, allowed_);
}
}
125 changes: 125 additions & 0 deletions src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.0;

// Internal
import {IERC20Issuance_v1} from "@ex/token/IERC20Issuance_v1.sol";

/**
* @title ERC20 Issuance Token with Blacklist Functionality
*
* @notice An ERC20 token implementation that extends ERC20Issuance_v1 with
* blacklisting capabilities. This allows accounts with the blacklist
* manager role to restrict specific addresses from participating in
* token operations.
*
* @dev This contract inherits from:
* - IERC20Issuance_Blacklist_v1.
* - ERC20Issuance_v1.
* Key features:
* - Individual address blacklisting.
* - Batch blacklisting operations.
* - Owner-controlled manager role assignment.
* - Blacklist manager controlled blacklist management.
* Blacklist operations are performed by accounts with the
* blacklist manager role, while the contract owner controls who
* can be a blacklist manager.
* All blacklist operations can only be performed by accounts with the
* blacklist manager role.
*
* @custom:security-contact [email protected]
* In case of any concerns or findings, please refer to
* our Security Policy at security.inverter.network or
* email us directly!
*
* @custom:version v1.0.0
*
* @custom:standard-version v1.0.0
*
* @author Zealynx Security
*/
interface IERC20Issuance_Blacklist_v1 is IERC20Issuance_v1 {
// -------------------------------------------------------------------------
// Events

/// @notice Emitted when an address is added to the blacklist.
/// @param account_ The address that was blacklisted.
event AddedToBlacklist(address indexed account_);

/// @notice Emitted when an address is removed from the blacklist.
/// @param account_ The address that was removed from blacklist.
event RemovedFromBlacklist(address indexed account_);

/// @notice Emitted when a blacklist manager role is granted or revoked.
/// @param account_ The address that was granted or revoked the role.
/// @param allowed_ Whether the role was granted (true) or revoked (false).
event BlacklistManagerUpdated(address indexed account_, bool allowed_);

// -------------------------------------------------------------------------
// Errors

/// @notice Thrown when attempting to blacklist the zero address.
error ERC20Issuance_Blacklist_ZeroAddress();

/// @notice Thrown when caller does not have blacklist manager role.
error ERC20Issuance_Blacklist_NotBlacklistManager();

/// @notice Thrown when attempting to mint tokens to a blacklisted address.
error ERC20Issuance_Blacklist_BlacklistedAddress(address account_);

/// @notice Thrown when batch operation exceeds the maximum allowed size.
error ERC20Issuance_Blacklist_BatchLimitExceeded(
uint provided_, uint limit_
);

// -------------------------------------------------------------------------
// External Functions

/// @notice Checks if an address is blacklisted.
/// @param account_ The address to check.
/// @return isBlacklisted_ True if address is blacklisted.
function isBlacklisted(address account_)
external
view
returns (bool isBlacklisted_);

/// @notice Checks if an address is a blacklist manager.
/// @param account_ The address to check.
/// @return isBlacklistManager_ True if address is a blacklist manager.
function isBlacklistManager(address account_)
external
view
returns (bool isBlacklistManager_);

/// @notice Adds an address to blacklist.
/// @param account_ The address to the blacklist.
/// @dev May revert with ERC20Issuance_Blacklist_ZeroAddress.
function addToBlacklist(address account_) external;

/// @notice Removes an address from the blacklist.
/// @param account_ The address to remove.
/// @dev May revert with ERC20Issuance_Blacklist_ZeroAddress.
function removeFromBlacklist(address account_) external;

/// @notice Adds multiple addresses to the blacklist.
/// @param accounts_ Array of addresses to the blacklist.
/// @dev May revert with ERC20Issuance_Blacklist_ZeroAddress
/// The array size should not exceed the block gas limit. Consider
/// using smaller batches (e.g., 100-200 addresses) to ensure
/// transaction success.
function addToBlacklistBatched(address[] calldata accounts_) external;

/// @notice Removes multiple addresses from the blacklist.
/// @param accounts_ Array of addresses to remove.
/// @dev May revert with ERC20Issuance_Blacklist_ZeroAddress
/// The array size should not exceed the block gas limit. Consider
/// using smaller batches (e.g., 100-200 addresses) to ensure
/// transaction success.
function removeFromBlacklistBatched(address[] calldata accounts_)
external;

/// @notice Sets or revokes blacklist manager role for an address.
/// @param manager_ The address to grant or revoke the role from.
/// @param allowed_ Whether to grant (true) or revoke (false) the role.
/// @dev May revert with ERC20Issuance_Blacklist_ZeroAddress.
function setBlacklistManager(address manager_, bool allowed_) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ abstract contract RedeemingBondingCurveBase_v1 is
uint _minAmountOut
)
internal
virtual
returns (uint totalCollateralTokenMovedOut, uint issuanceFeeAmount)
{
_ensureNonZeroTradeParameters(_depositAmount, _minAmountOut);
Expand Down
Loading
Loading