TokenSale
Inherits: AccessManaged, ReentrancyGuard
Allows users to purchase CMX tokens at a fixed $1 rate using stablecoins
Supports multiple stablecoins with different decimal configurations
State Variables
cmxToken
IERC20 public immutable cmxToken;
treasury
address public treasury;
acceptedStablecoins
mapping(address => StablecoinConfig) public acceptedStablecoins;
stablecoinList
address[] public stablecoinList;
saleActive
bool public saleActive;
maxPurchasePerTx
uint256 public maxPurchasePerTx;
totalSold
uint256 public totalSold;
maxSupplyForSale
uint256 public maxSupplyForSale;
Functions
constructor
Constructor
constructor(address _globalAccessManager, address _cmxToken, address _treasury, uint256 _maxSupplyForSale)
AccessManaged(_globalAccessManager);
Parameters
_globalAccessManager
address
Address of the GlobalAccessManager
_cmxToken
address
Address of the CMX token contract
_treasury
address
Address to receive stablecoin payments
_maxSupplyForSale
uint256
Maximum CMX tokens available for sale
purchaseCMX
Purchase CMX tokens with stablecoins at $1 per CMX
function purchaseCMX(address stablecoin, uint256 cmxAmount) external nonReentrant;
Parameters
stablecoin
address
Address of the stablecoin to pay with
cmxAmount
uint256
Amount of CMX tokens to purchase (18 decimals)
_calculateStablecoinAmount
Calculate the stablecoin amount needed for a given CMX amount
function _calculateStablecoinAmount(uint256 cmxAmount, uint8 stablecoinDecimals) internal pure returns (uint256);
Parameters
cmxAmount
uint256
Amount of CMX tokens (18 decimals)
stablecoinDecimals
uint8
Decimals of the stablecoin
Returns
<none>
uint256
stablecoinAmount Amount of stablecoin needed
getStablecoinAmount
Get the stablecoin amount needed for a given CMX amount (public view)
function getStablecoinAmount(address stablecoin, uint256 cmxAmount) external view returns (uint256);
Parameters
stablecoin
address
Address of the stablecoin
cmxAmount
uint256
Amount of CMX tokens (18 decimals)
Returns
<none>
uint256
stablecoinAmount Amount of stablecoin needed
getCMXAmount
Get the maximum CMX amount that can be purchased with a given stablecoin amount
function getCMXAmount(address stablecoin, uint256 stablecoinAmount) external view returns (uint256);
Parameters
stablecoin
address
Address of the stablecoin
stablecoinAmount
uint256
Amount of stablecoin available
Returns
<none>
uint256
cmxAmount Maximum CMX tokens that can be purchased
addStablecoin
Add a new accepted stablecoin
function addStablecoin(address stablecoin, uint8 decimals, uint256 minPurchase) external restricted;
Parameters
stablecoin
address
Address of the stablecoin
decimals
uint8
Decimals of the stablecoin
minPurchase
uint256
Minimum purchase amount in CMX tokens (18 decimals)
removeStablecoin
Remove an accepted stablecoin
function removeStablecoin(address stablecoin) external restricted;
Parameters
stablecoin
address
Address of the stablecoin to remove
updateStablecoinConfig
Update stablecoin configuration
function updateStablecoinConfig(address stablecoin, uint8 decimals, uint256 minPurchase) external restricted;
Parameters
stablecoin
address
Address of the stablecoin
decimals
uint8
New decimals value
minPurchase
uint256
New minimum purchase amount
setSaleStatus
Set sale status
function setSaleStatus(bool active) external restricted;
Parameters
active
bool
Whether the sale is active
setTreasury
Set treasury address
function setTreasury(address newTreasury) external restricted;
Parameters
newTreasury
address
New treasury address
setMaxPurchasePerTx
Set maximum purchase per transaction
function setMaxPurchasePerTx(uint256 newMax) external restricted;
Parameters
newMax
uint256
New maximum purchase amount in CMX tokens
setMaxSupplyForSale
Set maximum supply for sale
function setMaxSupplyForSale(uint256 newMax) external restricted;
Parameters
newMax
uint256
New maximum supply for sale
emergencyWithdrawCMX
Emergency withdraw CMX tokens
function emergencyWithdrawCMX(uint256 amount) external restricted;
Parameters
amount
uint256
Amount of CMX tokens to withdraw
emergencyWithdrawToken
Emergency withdraw any ERC20 token (except CMX)
function emergencyWithdrawToken(address token, uint256 amount) external restricted;
Parameters
token
address
Address of the token to withdraw
amount
uint256
Amount to withdraw
getAcceptedStablecoins
Get all accepted stablecoins
function getAcceptedStablecoins() external view returns (address[] memory);
Returns
<none>
address[]
Array of accepted stablecoin addresses
getSaleInfo
Get sale information
function getSaleInfo()
external
view
returns (bool active, uint256 sold, uint256 maxSupply, uint256 maxPerTx, uint256 remaining);
Returns
active
bool
Whether sale is active
sold
uint256
Total CMX tokens sold
maxSupply
uint256
Maximum CMX tokens for sale
maxPerTx
uint256
Maximum purchase per transaction
remaining
uint256
Remaining CMX tokens available
isStablecoinAccepted
Check if a stablecoin is accepted
function isStablecoinAccepted(address stablecoin) external view returns (bool);
Parameters
stablecoin
address
Address of the stablecoin
Returns
<none>
bool
accepted Whether the stablecoin is accepted
Events
CMXPurchased
event CMXPurchased(address indexed buyer, address indexed stablecoin, uint256 stablecoinAmount, uint256 cmxAmount);
StablecoinAdded
event StablecoinAdded(address indexed stablecoin, uint8 decimals, uint256 minPurchase);
StablecoinRemoved
event StablecoinRemoved(address indexed stablecoin);
StablecoinConfigUpdated
event StablecoinConfigUpdated(address indexed stablecoin, uint8 decimals, uint256 minPurchase);
SaleStatusUpdated
event SaleStatusUpdated(bool active);
TreasuryUpdated
event TreasuryUpdated(address indexed oldTreasury, address indexed newTreasury);
MaxPurchaseUpdated
event MaxPurchaseUpdated(uint256 oldMax, uint256 newMax);
MaxSupplyUpdated
event MaxSupplyUpdated(uint256 oldMax, uint256 newMax);
Structs
StablecoinConfig
struct StablecoinConfig {
bool accepted;
uint8 decimals;
uint256 minPurchase;
}
Last updated
Was this helpful?