AuditTrail

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "@openzeppelin/contracts/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
"
    },
    "@openzeppelin/contracts/utils/Context.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
"
    },
    "@openzeppelin/contracts/utils/Pausable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    bool private _paused;

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
"
    },
    "contracts/core/AuditTrail.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
import "../interfaces/IAuditTrail.sol";

/**
 * @title AuditTrail
 * @dev Immutable record of all market making activities for transparency
 * @notice This contract provides a permanent, transparent log of all trading activities
 *
 * @dev OWNERSHIP:
 * - Owner: Set via constructor parameter during deployment
 *   - Should be a hardware wallet or multisig for production (same as Treasury owner)
 *   - Can authorize/revoke loggers
 *   - Has administrative control over the audit system
 */
contract AuditTrail is IAuditTrail, Ownable, Pausable {
    /**
     * @dev Constructor
     * @param _owner Address that will be the owner of the audit trail
     */
    constructor(address _owner) Ownable(_owner) {
        require(_owner != address(0), "Owner cannot be zero address");
    }

    // Trade record structure
    struct TradeRecord {
        address trader;
        bool isPurchase;
        uint256 tokenAmount;
        uint256 ethAmount;
        uint256 price;
        uint256 timestamp;
        uint256 blockNumber;
    }
    
    // Revenue record structure
    struct RevenueRecord {
        address source;
        uint256 amount;
        uint256 timestamp;
        uint256 blockNumber;
        string description;
    }

    // Purchase record structure for integration tracking
    struct PurchaseRecord {
        address vault;
        uint256 ethAmount;
        uint256 tokenAmount;
        string exchange;
        uint256 timestamp;
        uint256 blockNumber;
    }
    
    // State variables
    TradeRecord[] public trades;
    RevenueRecord[] public revenueDeposits;
    PurchaseRecord[] public purchases;
    
    mapping(address => bool) public authorizedLoggers;
    mapping(address => uint256[]) public traderToTrades;
    
    uint256 public totalTradesLogged;
    uint256 public totalVolumeETH;
    uint256 public totalVolumeBWS;
    uint256 public totalRevenueLogged;
    
    // Events
    event TradeLogged(
        uint256 indexed tradeId,
        address indexed trader,
        bool isPurchase,
        uint256 tokenAmount,
        uint256 ethAmount,
        uint256 price
    );
    
    event RevenueLogged(
        uint256 indexed revenueId,
        address indexed source,
        uint256 amount,
        string description
    );
    
    event LoggerAuthorized(address indexed logger);
    event LoggerRevoked(address indexed logger);
    event TokenPurchaseRecorded(address indexed vault, uint256 ethAmount, uint256 tokenAmount, string exchange);
    
    // Modifiers
    modifier onlyAuthorizedLogger() {
        require(authorizedLoggers[msg.sender], "Not authorized logger");
        _;
    }
    
    
    /**
     * @dev Log a trade transaction
     * @param trader Address of the trader
     * @param isPurchase True for purchase, false for sale
     * @param tokenAmount Amount of BWS tokens
     * @param ethAmount Amount of ETH
     * @param price Token price at time of trade
     */
    function logTrade(
        address trader,
        bool isPurchase,
        uint256 tokenAmount,
        uint256 ethAmount,
        uint256 price
    ) public onlyAuthorizedLogger {
        require(trader != address(0), "Invalid trader address");
        require(tokenAmount > 0, "Invalid token amount");
        require(ethAmount > 0, "Invalid ETH amount");
        require(price > 0, "Invalid price");
        
        TradeRecord memory newTrade = TradeRecord({
            trader: trader,
            isPurchase: isPurchase,
            tokenAmount: tokenAmount,
            ethAmount: ethAmount,
            price: price,
            timestamp: block.timestamp,
            blockNumber: block.number
        });
        
        uint256 tradeId = trades.length;
        trades.push(newTrade);
        traderToTrades[trader].push(tradeId);
        
        // Update statistics
        totalTradesLogged++;
        totalVolumeETH += ethAmount;
        totalVolumeBWS += tokenAmount;
        
        emit TradeLogged(
            tradeId,
            trader,
            isPurchase,
            tokenAmount,
            ethAmount,
            price
        );
    }
    
    /**
     * @dev Log revenue deposit
     * @param source Address of revenue source
     * @param amount Amount of revenue deposited
     * @param description Description of revenue source
     */
    function logRevenue(
        address source,
        uint256 amount,
        string calldata description
    ) external onlyAuthorizedLogger {
        require(source != address(0), "Invalid source address");
        require(amount > 0, "Invalid amount");
        require(bytes(description).length > 0, "Empty description");
        
        RevenueRecord memory newRevenue = RevenueRecord({
            source: source,
            amount: amount,
            timestamp: block.timestamp,
            blockNumber: block.number,
            description: description
        });
        
        uint256 revenueId = revenueDeposits.length;
        revenueDeposits.push(newRevenue);
        
        // Update statistics
        totalRevenueLogged += amount;
        
        emit RevenueLogged(
            revenueId,
            source,
            amount,
            description
        );
    }
    
    /**
     * @dev Authorize a logger address
     * @param logger Address to authorize
     */
    function authorizeLogger(address logger) external onlyOwner {
        require(logger != address(0), "Invalid address");
        require(!authorizedLoggers[logger], "Already authorized");
        
        authorizedLoggers[logger] = true;
        emit LoggerAuthorized(logger);
    }
    
    /**
     * @dev Revoke logger authorization
     * @param logger Address to revoke
     */
    function revokeLogger(address logger) external onlyOwner {
        require(authorizedLoggers[logger], "Not authorized");
        
        authorizedLoggers[logger] = false;
        emit LoggerRevoked(logger);
    }
    
    /**
     * @dev Get trade by ID
     * @param tradeId Trade ID to retrieve
     */
    function getTrade(uint256 tradeId) external view returns (TradeRecord memory) {
        require(tradeId < trades.length, "Invalid trade ID");
        return trades[tradeId];
    }
    
    /**
     * @dev Get revenue record by ID
     * @param revenueId Revenue ID to retrieve
     */
    function getRevenueRecord(uint256 revenueId) external view returns (RevenueRecord memory) {
        require(revenueId < revenueDeposits.length, "Invalid revenue ID");
        return revenueDeposits[revenueId];
    }
    
    /**
     * @dev Get trades for a specific trader
     * @param trader Trader address
     * @param offset Starting index
     * @param limit Maximum number of trades to return
     */
    function getTraderTrades(
        address trader,
        uint256 offset,
        uint256 limit
    ) external view returns (TradeRecord[] memory) {
        uint256[] memory tradeIds = traderToTrades[trader];
        require(offset < tradeIds.length, "Invalid offset");
        
        uint256 end = offset + limit;
        if (end > tradeIds.length) {
            end = tradeIds.length;
        }
        
        TradeRecord[] memory result = new TradeRecord[](end - offset);
        for (uint256 i = offset; i < end; i++) {
            result[i - offset] = trades[tradeIds[i]];
        }
        
        return result;
    }
    
    /**
     * @dev Get recent trades
     * @param limit Maximum number of trades to return
     */
    function getRecentTrades(uint256 limit) external view returns (TradeRecord[] memory) {
        uint256 totalTrades = trades.length;
        if (totalTrades == 0) {
            return new TradeRecord[](0);
        }
        
        uint256 start = totalTrades > limit ? totalTrades - limit : 0;
        TradeRecord[] memory result = new TradeRecord[](totalTrades - start);
        
        for (uint256 i = start; i < totalTrades; i++) {
            result[i - start] = trades[i];
        }
        
        return result;
    }
    
    /**
     * @dev Get audit trail statistics
     */
    function getAuditStats() external view returns (
        uint256 totalTrades,
        uint256 totalVolumeETHStat,
        uint256 totalVolumeBWSStat,
        uint256 totalRevenue,
        uint256 totalRevenueRecords,
        uint256 totalPurchases,
        uint256 totalEthSpent,
        uint256 totalTokensPurchased
    ) {
        totalTrades = totalTradesLogged;
        totalVolumeETHStat = totalVolumeETH;
        totalVolumeBWSStat = totalVolumeBWS;
        totalRevenue = totalRevenueLogged;
        totalRevenueRecords = revenueDeposits.length;

        // Calculate purchase-specific stats
        // Use purchases array as the primary source since executePurchase uses recordTokenPurchaseWithExchange
        totalPurchases = purchases.length;
        totalEthSpent = 0;
        totalTokensPurchased = 0;

        // Add stats from purchases array (primary record)
        for (uint256 i = 0; i < purchases.length; i++) {
            totalEthSpent += purchases[i].ethAmount;
            totalTokensPurchased += purchases[i].tokenAmount;
        }

        // If no purchases array records, fall back to trades array
        if (purchases.length == 0) {
            for (uint256 i = 0; i < trades.length; i++) {
                if (trades[i].isPurchase) {
                    totalPurchases++;
                    totalEthSpent += trades[i].ethAmount;
                    totalTokensPurchased += trades[i].tokenAmount;
                }
            }
        }
    }

    /**
     * @dev Pause the contract
     * @notice Only owner can pause
     */
    function pause() external onlyOwner {
        _pause();
    }

    /**
     * @dev Unpause the contract
     * @notice Only owner can unpause
     */
    function unpause() external onlyOwner {
        _unpause();
    }

    /**
     * @dev Record token purchase (alias for logTrade)
     * @param trader Address of the trader
     * @param tokenAmount Amount of BWS tokens
     * @param ethAmount Amount of ETH
     * @param price Token price
     */
    function recordTokenPurchase(
        address trader,
        uint256 tokenAmount,
        uint256 ethAmount,
        uint256 price
    ) external onlyAuthorizedLogger whenNotPaused {
        logTrade(trader, true, tokenAmount, ethAmount, price);
    }

    /**
     * @dev Record token purchase with exchange info
     * @param vault Address of the vault making the purchase
     * @param ethAmount Amount of ETH spent
     * @param tokenAmount Amount of BWS tokens purchased
     * @param exchange Exchange used for the purchase
     */
    function recordTokenPurchaseWithExchange(
        address vault,
        uint256 ethAmount,
        uint256 tokenAmount,
        string calldata exchange
    ) external onlyAuthorizedLogger whenNotPaused {
        require(vault != address(0), "Invalid vault address");
        require(ethAmount > 0, "Invalid ETH amount");
        require(tokenAmount > 0, "Invalid token amount");
        require(bytes(exchange).length > 0, "Empty exchange");

        // Store purchase record
        PurchaseRecord memory newPurchase = PurchaseRecord({
            vault: vault,
            ethAmount: ethAmount,
            tokenAmount: tokenAmount,
            exchange: exchange,
            timestamp: block.timestamp,
            blockNumber: block.number
        });

        purchases.push(newPurchase);

        emit TokenPurchaseRecorded(vault, ethAmount, tokenAmount, exchange);
    }

    /**
     * @dev Get total number of purchases
     */
    function getTotalPurchases() external view returns (uint256) {
        return purchases.length;
    }

    /**
     * @dev Get purchase record by index
     * @param index Index of the purchase
     */
    function getPurchaseRecord(uint256 index) external view returns (PurchaseRecord memory) {
        require(index < purchases.length, "Purchase index out of bounds");
        return purchases[index];
    }
}"
    },
    "contracts/interfaces/IAuditTrail.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

/**
 * @title IAuditTrail
 * @dev Interface for the audit trail contract
 */
interface IAuditTrail {
    /**
     * @dev Log a trade transaction
     * @param trader Address of the trader
     * @param isPurchase True for purchase, false for sale
     * @param tokenAmount Amount of BWS tokens
     * @param ethAmount Amount of ETH
     * @param price Token price at time of trade
     */
    function logTrade(
        address trader,
        bool isPurchase,
        uint256 tokenAmount,
        uint256 ethAmount,
        uint256 price
    ) external;
    
    /**
     * @dev Log revenue deposit
     * @param source Address of revenue source
     * @param amount Amount of revenue deposited
     * @param description Description of revenue source
     */
    function logRevenue(
        address source,
        uint256 amount,
        string calldata description
    ) external;
    
    /**
     * @dev Authorize a logger address
     * @param logger Address to authorize
     */
    function authorizeLogger(address logger) external;
    
    /**
     * @dev Revoke logger authorization
     * @param logger Address to revoke
     */
    function revokeLogger(address logger) external;

    /**
     * @dev Record token purchase with exchange info
     * @param vault Address of the vault making the purchase
     * @param ethAmount Amount of ETH spent
     * @param tokenAmount Amount of BWS tokens purchased
     * @param exchange Exchange used for the purchase
     */
    function recordTokenPurchaseWithExchange(
        address vault,
        uint256 ethAmount,
        uint256 tokenAmount,
        string calldata exchange
    ) external;
}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "evmVersion": "paris",
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}}

Tags:
Multisig, Multi-Signature, Factory|addr:0x2b4c39327eff9c2c324d010e11d12c9ce2ef815d|verified:true|block:23417422|tx:0xe28efd5f6bf5cacd571b9fbeb0f162ceea6ce959427cd245ecb911c2d3de3993|first_check:1758537763

Submitted on: 2025-09-22 12:42:43

Comments

Log in to comment.

No comments yet.