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

Update token premint logic by adding cancel/update posibility #67

Merged
merged 13 commits into from
Mar 13, 2024

Conversation

ihoroleksiienko
Copy link
Contributor

@ihoroleksiienko ihoroleksiienko commented Mar 8, 2024

Description

With the implementation of the new functionality, the contract now has the ability to update or cancel pending (not expired) premints. Premint operation restrictions were added to limit some actions during the premint() function call.

New premint() function declaration:

    /// @notice An enum describing restrictions for premint operation
    enum PremintRestriction {
        None,   // No restriction
        Create, // Creating a new premint is disallowed
        Update  // Updating an existing premint is disallowed
    }

    /**
     * @notice Premints tokens
     *
     * Emits a {Premint} event
     *
     * @param account The address of a tokens recipient
     * @param amount The amount of tokens to premint
     * @param release The timestamp when the tokens will be released
     * @param restriction The restriction for the premint operation
     */
    function premint(address account, uint256 amount, uint256 release, PremintRestriction restriction) external;

Key Highlights

The premint() function possible usage scenarios

  1. If a premint with the provided release timestamp does not exist and amount != 0 and restriction == (None || Update), a new premint will be created.
  2. If a premint with the provided release timestamp exists and amount != 0 and restriction == (None || Create), the existing premint will be updated with the new amount. Tokens will be minted or burned according to the difference between the new amount value and the old one.
  3. If a premint with the provided release timestamp exists and amount == 0 and restriction == (None || Create), the existing premint will be canceled.

The revert conditions for the premint() function

  1. If the passed release timestamp is not greater than the current block timestamp -- error PremintReleaseTimePassed.
  2. If a new premint should be created but amount == 0 -- error ZeroPremintAmount.
  3. If a new premint should be created but the number of non-released premints is already equals the allowed maximum -- error MaxPendingPremintsLimitReached.
  4. If the existing premint should be updated, but the old and new amount values are the same -- error PremintUnchanged.
  5. If the restriction argument is set as PremintRestriction.Create, and a new premint is going to be created.
  6. If the restriction argument is set as PremintRestriction.Update and an existing premint is going to be updated.

The premint() function common behaviour

  1. Each call of the premint() function checks and removes released premints from the internal array.
  2. If a premint was successfully created or updated, the following event will be emitted:
   /**
     * @notice Emitted when tokens are preminted
     *
     * @param minter The address of the minter
     * @param to The address of the tokens recipient
     * @param newAmount The new amount of tokens being preminted
     * @param oldAmount The old amount of tokens being preminted
     * @param release The timestamp when the tokens will be released
     */
    event Premint(
        address indexed minter,
        address indexed to,
        uint256 newAmount,
        uint256 oldAmount,
        uint256 release
    );

Test coverage

New functionality was fully covered with tests

igorsenych-cw
igorsenych-cw previously approved these changes Mar 13, 2024
@igorsenych-cw igorsenych-cw merged commit 1f21aad into main Mar 13, 2024
7 checks passed
@igorsenych-cw igorsenych-cw deleted the premint-update branch March 13, 2024 08:38
@igorsenych-cw igorsenych-cw changed the title Update premint logic Update token premint logic by adding cancel/update posibility Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants