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

Sell order function #1

Merged
merged 2 commits into from
Dec 9, 2024
Merged
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
31 changes: 13 additions & 18 deletions src/external/token/ERC20Issuance_blacklist_v1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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";
import {IERC20Issuance_Blacklist_v1} from
"@ex/token/interfaces/IERC20Issuance_Blacklist_v1.sol";

// External
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
Expand Down Expand Up @@ -48,7 +48,7 @@ contract ERC20Issuance_Blacklist_v1 is
mapping(address => bool) private _blacklist;

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

//--------------------------------------------------------------------------
// Constants
Expand All @@ -69,17 +69,11 @@ contract ERC20Issuance_Blacklist_v1 is
string memory name_,
string memory symbol_,
uint8 decimals_,
uint256 initialSupply_,
uint initialSupply_,
address initialAdmin_,
address initialBlacklistManager_
)
ERC20Issuance_v1(
name_,
symbol_,
decimals_,
initialSupply_,
initialAdmin_
)
ERC20Issuance_v1(name_, symbol_, decimals_, initialSupply_, initialAdmin_)
{
if (initialBlacklistManager_ == address(0)) {
revert ERC20Issuance_Blacklist_ZeroAddress();
Expand Down Expand Up @@ -113,10 +107,7 @@ contract ERC20Issuance_Blacklist_v1 is
}

/// @inheritdoc IERC20Issuance_Blacklist_v1
function addToBlacklist(address account_)
public
onlyBlacklistManager
{
function addToBlacklist(address account_) public onlyBlacklistManager {
if (account_ == address(0)) {
revert ERC20Issuance_Blacklist_ZeroAddress();
}
Expand Down Expand Up @@ -146,7 +137,9 @@ contract ERC20Issuance_Blacklist_v1 is
{
uint totalAccount_ = accounts_.length;
if (totalAccount_ > BATCH_LIMIT) {
revert ERC20Issuance_Blacklist_BatchLimitExceeded(totalAccount_, BATCH_LIMIT);
revert ERC20Issuance_Blacklist_BatchLimitExceeded(
totalAccount_, BATCH_LIMIT
);
}
for (uint i_; i_ < totalAccount_; ++i_) {
addToBlacklist(accounts_[i_]);
Expand All @@ -160,7 +153,9 @@ contract ERC20Issuance_Blacklist_v1 is
{
uint totalAccount_ = accounts_.length;
if (totalAccount_ > BATCH_LIMIT) {
revert ERC20Issuance_Blacklist_BatchLimitExceeded(totalAccount_, BATCH_LIMIT);
revert ERC20Issuance_Blacklist_BatchLimitExceeded(
totalAccount_, BATCH_LIMIT
);
}
for (uint i_; i_ < totalAccount_; ++i_) {
removeFromBlacklist(accounts_[i_]);
Expand All @@ -176,7 +171,7 @@ contract ERC20Issuance_Blacklist_v1 is
/// @param to Address tokens are transferred to
/// @param amount Number of tokens to transfer
/// @inheritdoc ERC20Capped
function _update(address from, address to, uint256 amount)
function _update(address from, address to, uint amount)
internal
override(ERC20Capped)
{
Expand Down
34 changes: 17 additions & 17 deletions src/external/token/interfaces/IERC20Issuance_blacklist_v1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
// Imports

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

/**
* @title ERC20 Issuance Token with Blacklist Interface
Expand Down Expand Up @@ -54,28 +54,30 @@ interface IERC20Issuance_Blacklist_v1 is IERC20Issuance_v1 {
error ERC20Issuance_Blacklist_BlacklistedAddress(address account);

/// @notice Thrown when batch operation exceeds the maximum allowed size
error ERC20Issuance_Blacklist_BatchLimitExceeded(uint256 provided, uint256 limit);
error ERC20Issuance_Blacklist_BatchLimitExceeded(uint provided, uint limit);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for using uint instead of uint256?


//--------------------------------------------------------------------------
// 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_);
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_);
function isBlacklistManager(address account_)
external
view
returns (bool isBlacklistManager_);

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

/// @notice Removes an address from blacklist
Expand All @@ -88,16 +90,14 @@ interface IERC20Issuance_Blacklist_v1 is IERC20Issuance_v1 {
/// @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 addToBlacklistBatchAddresses(
address[] memory accounts_
) external;
function addToBlacklistBatchAddresses(address[] memory accounts_)
external;

/// @notice Removes multiple addresses from 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 removeFromBlacklistBatchAddresses(
address[] calldata accounts_
) external;
}
function removeFromBlacklistBatchAddresses(address[] calldata accounts_)
external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ contract FM_PC_ExternalPrice_Redeeming_v1 is
type(IOraclePrice_v1).interfaceId
)
) {
revert Module__FM_PC_ExternalPrice_Redeeming_InvalidOracleInterface();
revert Module__FM_PC_ExternalPrice_Redeeming_InvalidOracleInterface(
);
}
// Set oracle
_oracle = IOraclePrice_v1(oracleAddress_);
Expand Down Expand Up @@ -389,10 +390,7 @@ contract FM_PC_ExternalPrice_Redeeming_v1 is

// Emit event
emit TokensSold(
receiver,
depositAmount,
collateralRedeemAmount,
_msgSender()
receiver, depositAmount, collateralRedeemAmount, _msgSender()
);
}

Expand Down Expand Up @@ -444,7 +442,7 @@ contract FM_PC_ExternalPrice_Redeeming_v1 is

// Require that enough collateral token is held to be redeemable
if (
(collateralRedeemAmount + projectCollateralFeeCollected)
(projectCollateralFeeCollected)
> collateralToken.balanceOf(address(this))
) {
revert
Expand Down Expand Up @@ -476,7 +474,9 @@ contract FM_PC_ExternalPrice_Redeeming_v1 is
_handleCollateralTokensAfterSell(_receiver, collateralRedeemAmount);

// Create and emit the order
_createAndEmitOrder(_receiver, _depositAmount, collateralRedeemAmount, issuanceFeeAmount);
_createAndEmitOrder(
_receiver, _depositAmount, collateralRedeemAmount, issuanceFeeAmount
);

return (totalCollateralTokenMovedOut, issuanceFeeAmount);
}
Expand Down Expand Up @@ -587,6 +587,16 @@ contract FM_PC_ExternalPrice_Redeeming_v1 is
//--------------------------------------------------------------------------
// Internal Functions

/// @dev Internal function which only emits the event for amount of project fee collected. The contract
/// does not hold collateral as the payout is managed through a redemption queue
/// @param _projectFeeAmount The amount of fee collected
function _projectFeeCollected(uint _projectFeeAmount)
internal
override(BondingCurveBase_v1)
{
emit ProjectCollateralFeeAdded(_projectFeeAmount);
}

/// @notice Sets the maximum fee that can be charged for buy operations
/// @param fee_ The maximum fee percentage to set
function _setMaxBuyFee(uint fee_) internal {
Expand Down Expand Up @@ -661,12 +671,13 @@ contract FM_PC_ExternalPrice_Redeeming_v1 is
}

/// @inheritdoc RedeemingBondingCurveBase_v1
/// @dev Implementation does not transfer collateral tokens to recipient as the
/// payout is managed through a redemption queue
function _handleCollateralTokensAfterSell(address recipient_, uint amount_)
internal
virtual
override
{
// Transfer collateral tokens to recipient
IERC20(token()).safeTransfer(recipient_, amount_);
// This function is not used in this implementation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {IOrchestrator_v1} from
"src/orchestrator/interfaces/IOrchestrator_v1.sol";

// External
import {IERC20Metadata} from
"@oz/token/ERC20/extensions/IERC20Metadata.sol";
import {ERC165Upgradeable} from "@oz-up/utils/introspection/ERC165Upgradeable.sol";
import {IERC20Metadata} from "@oz/token/ERC20/extensions/IERC20Metadata.sol";
import {ERC165Upgradeable} from
"@oz-up/utils/introspection/ERC165Upgradeable.sol";

/**
* @title Manual External Price Oracle Implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ interface IFM_PC_ExternalPrice_Redeeming_v1 is
/// @notice Fee exceeds maximum allowed value
/// @param fee The fee that was attempted to be set
/// @param maxFee The maximum allowed fee
error Module__FM_PC_ExternalPrice_Redeeming_FeeExceedsMaximum(uint256 fee, uint256 maxFee);
error Module__FM_PC_ExternalPrice_Redeeming_FeeExceedsMaximum(
uint fee, uint maxFee
);

/// @notice Thrown when the oracle contract does not implement the required interface
error Module__FM_PC_ExternalPrice_Redeeming_InvalidOracleInterface();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ interface IOraclePrice_v1 {
/// @notice Gets current price for token issuance (buying tokens)
/// @return price_ Current price in 18 decimals (collateral tokens per 1 issuance token)
/// @dev Example: If price is 2 USDC/ISS, returns 2e18 (2 USDC needed for 1 ISS)
function getPriceForIssuance() external view returns (uint256 price_);
function getPriceForIssuance() external view returns (uint price_);

/// @notice Gets current price for token redemption (selling tokens)
/// @return price_ Current price in 18 decimals (collateral tokens per 1 issuance token)
/// @dev Example: If price is 1.9 USDC/ISS, returns 1.9e18 (1.9 USDC received for 1 ISS)
function getPriceForRedemption() external view returns (uint256 price_);
}
function getPriceForRedemption() external view returns (uint price_);
}
Loading