Function: buyTokens(address token, uint256 amount)
The function allows the caller to buy tokens associated with a specific hashtag. The current buy price depends on the current viralityScore
and supply
of the token, which may change over time, and the unchangeable initialPrice
, exponent
, and initialSupply
values. The function is available only whenNotPaused
.
Inputs
token
Validation:
onlyRegistered(token)
.Impact: The hashtag-token address that the caller wants to buy.
amount
Validation: The
amount
of tokens is not directly validated, but the user must have enough funds to buy this amount of tokens.Impact: The amount of token to buy.
Branches and code coverage (including function calls)
Intended branches
The caller received the expected amount of tokens in exchange for the expected amount of
paymentToken
tokens.
Negative behavior
The caller does not own enough
paymentToken
tokens to buy theamount
of hashtag tokens.The
token
is not registered.The contract is paused.
Function call analysis
getBuyPrice(token, amount)
External/Internal? Internal.
Argument control?
token
andamount
.Impact: Calculates the current price of the the requested
amount
of tokens.
IERC20(paymentToken).safeTransferFrom(msg.sender, address(this), totalPrice)
External/Internal? External.
Argument control? N/A.
Impact: Transfers of payment for the requested
amount
of tokens.
TrendingERC20(token).mint(msg.sender, amount)
External/Internal? External.
Argument control?
amount
.Impact: Mints the requested amount of hashtag tokens for the caller of the function.