Assessment reports>SAX>Threat Model>Function: sellTokens(address token, uint256 amount)

Function: sellTokens(address token, uint256 amount)

The function allows the caller to sell tokens they own associated with a specific hashtag. The current sell price is calculated differently than the buy price, and it is the minimum of two prices: the first one depends on the current liquidity and full price of all tokens, and the second depends on viralityScore and supply. The function is available only whenNotPaused.

Inputs

  • token

    • Validation: onlyRegistered(token).

    • Impact: The hashtag token address that the caller wants to sell.

  • amount

    • Validation: If the balance of the caller IERC20(token).balanceOf(msg.sender) is less than amount, the function will revert.

    • Impact: The amount of token to buy.

Branches and code coverage (including function calls)

Intended branches

  • The caller received the expected amount of paymentToken.

Negative behavior

  • The caller does not own enough hashtag tokens to sell.

  • The token is not registered.

  • The contract is paused.

Function call analysis

  • getSellPrice(token, amount)

    • External/Internal? Internal.

    • Argument control? token and amount.

    • Impact: Calculates the current price for selling the specified amount of tokens.

  • IERC20(token).balanceOf(msg.sender)

    • External/Internal? External.

    • Argument control? token and amount.

    • Impact: Returns the current hashtag token balance for the caller account to be sure that the caller owns enough tokens.

  • TrendingERC20(token).burn(msg.sender, amount)

    • External/Internal? External.

    • Argument control? token and amount.

    • Impact: Burn the hashtag tokens from the caller account.

  • IERC20(paymentToken).safeTransfer(msg.sender, totalPrice);

    • External/Internal? External.

    • Argument control? N/A.

    • Impact: Transfers the amount of paymentToken for the token sale to the caller of the function.

Zellic © 2024Back to top ↑