Asset Freeze Mechanism

Token Freezes

The Token Freeze Mechanism acts as a measure, against fraudulent behavior. When the compliance contract detects activities it promptly freezes the tokens involved making them untransferable and unusable. The freeze remains in place for a duration and only legal intervention can lift it in certain situations.

We want to implement multi signature based algorithms to ensure no single party has the ability to decide about freezes.

Data Flow:

  1. Fraud Detection:

    • The compliance contract detects a potential fraudulent activity associated with a specific token.

  2. Token Freezing:

    • The token associated with the suspicious activity is frozen for a predefined duration.

    • During this freeze period, the token cannot be transferred or used in any operations.

  3. Token Defrosting:

    • After the predefined duration, the token is automatically defrosted, making it usable again.

    • Alternatively, an external trigger (like legal intervention) can defrost the token.

Contract Structure:

pragma solidity ^0.8.0;

contract FreezeMechanism {
    // Mapping of token ID to its freeze status and end time
    mapping(uint256 => FreezeData) public tokenFreezeStatus;

    struct FreezeData {
        bool isFrozen;
        uint256 freezeEndTime;
    }

    event TokenFrozen(uint256 tokenId, uint256 freezeDuration);
    event TokenDefrosted(uint256 tokenId);

    function freezeToken(uint256 tokenId, uint256 freezeDuration) public {
        require(!tokenFreezeStatus[tokenId].isFrozen, "Token is already frozen");
        
        tokenFreezeStatus[tokenId].isFrozen = true;
        tokenFreezeStatus[tokenId].freezeEndTime = block.timestamp + freezeDuration;

        emit TokenFrozen(tokenId, freezeDuration);
    }

    function defrostToken(uint256 tokenId) public {
        require(tokenFreezeStatus[tokenId].isFrozen, "Token is not frozen");
        require(block.timestamp >= tokenFreezeStatus[tokenId].freezeEndTime, "Freeze duration not yet over");

        tokenFreezeStatus[tokenId].isFrozen = false;

        emit TokenDefrosted(tokenId);
    }

    function isTokenFrozen(uint256 tokenId) public view returns (bool) {
        if (tokenFreezeStatus[tokenId].isFrozen && block.timestamp >= tokenFreezeStatus[tokenId].freezeEndTime) {
            return false; // Token is considered defrosted after the freeze duration
        }
        return tokenFreezeStatus[tokenId].isFrozen;
    }
}

Function Descriptions:

freezeToken:

  • Purpose: Freezes a token for a specified duration.

  • Inputs:

    • tokenId: The ID of the token to be frozen.

    • freezeDuration: Duration (in seconds) for which the token should remain frozen.

  • Outputs: Emits a TokenFrozen event with the token ID and freeze duration.

  • Internal Operations: The function sets the isFrozen status of the token to true and calculates the freezeEndTime by adding the freezeDuration to the current block timestamp.

defrostToken:

  • Purpose: Defrosts a frozen token after the freeze duration has passed.

  • Inputs:

    • tokenId: The ID of the token to be defrosted.

  • Outputs: Emits a TokenDefrosted event with the token ID.

  • Internal Operations: The function checks if the token is frozen and if the current time has surpassed the freezeEndTime. If both conditions are met, the token's isFrozen status is set to false.

isTokenFrozen:

  • Purpose: Checks if a token is currently frozen.

  • Inputs:

    • tokenId: The ID of the token to check.

  • Outputs: Returns a boolean indicating if the token is frozen.

Mathematical and Logical Considerations:

  1. Freeze Duration: The freeze duration is added to the current block timestamp to determine the freezeEndTime. This ensures a clear and immutable end time for the freeze.

  2. Automatic Defrosting: The system doesn't automatically defrost tokens once the freeze duration is over. Instead, the isTokenFrozen function considers tokens as defrosted if the current time surpasses the freezeEndTime, even if their isFrozen status remains true. This design choice reduces unnecessary writes to the blockchain, saving gas.

  3. Safety Checks: The contract includes checks to prevent already frozen tokens from being frozen again and to ensure only tokens that have completed their freeze duration can be defrosted.

Last updated

Logo