EYWA
  • Eywa v2
    • πŸ’₯Eywa v2: new era of Web3 interoperability
  • Eywa token
    • πŸ’ŽTokenomics Eywa/CrossCurve
    • πŸ“ˆEywa token utility
    • ⚑Eywa NFT Collection
      • Eywa NFT Bridge from Aurora to Arbitrum
      • Merge interface in the Arbitrum chain
      • EYWA NFT Manager interface
      • Dashboard interface
    • 🏒Eywa DAO
      • Overview of EYWA DAO
      • Voting
      • Obtaining veEYWA and Calculating the Boost
      • Staking
  • EYWA Ecosystem
    • πŸ’‘Vision
    • πŸ—ΊοΈProduct & EYWA token Roadmap
    • πŸ—οΈProducts
      • Eywa v1
        • Cross-chain Liquidity Protocol
          • Cross-chain DEX v1
          • Eywa Token Bridge
          • Gasless transactions
        • Cross-chain Data Protocol
          • Eywa CDP Introduction
          • Eywa Oracle Network
          • Data transfer flow
      • Eywa v2
        • πŸŒ‰Consensus Bridge
        • ⚑CrossCurve
    • πŸ›‘οΈSecurity audits
    • 🧠Team
    • πŸ¦„Project History
    • πŸ”—External Links
    • ❓FAQ
  • User documentation
    • πŸ’ΈEywa DEX
      • About EYWA Cross-chain DEX
      • Interface Eywa WebApp
      • How to trade
      • Slippage settings
      • Routing
      • Operation Interruption
        • Slippage condition
        • Data transfer error
    • 🏒DAO
      • EYWA Locker Interface
      • Working with the EYWA Locker contract in Arbiscan.
      • EYWA Vote Interface
      • EYWA Incentives Interface
    • πŸ”—Contracts addresses
      • Cross-chain Liquidity Protocol
        • CLP smart-contracts
        • Supported stablecoins
        • Addresses of Eywa stableswap pools
        • Addresses of s-tokens
        • Addresses of e-tokens
      • Cross-chain Data Protocol
        • Governance of Eywa Oracle network
        • Cross-chain messaging
  • DEVELOPER DOCUMENTATION
    • πŸ’»Guide for Developers
      • Technical Documentation for EYWA DAO Smart Contracts
        • EmissionManagerV1
        • EscrowManager
        • EscrowVoteManagerV1
        • GaugeFactoryV1
        • GaugeV1
        • IncentiveRewardsDistributor
        • ProposalManager
        • RebaseRewardsDistributorV1
        • RewardsDistributorFactoryV1
        • CalldataHelperV1
        • Treasury
        • DelegationManagerV1
        • DelegationConditionValidatorV1
        • LockHolderFactoryV1
        • LockHolderV1
  • Eywa Oracle Network - will be ENDED in April 2024
    • πŸ₯‡Validators token distribution
    • Incentivised PoA mainnet
      • General information
      • Application for participation in PoA mainnet
      • Requirements for PoA mainnet validators
      • Rewards for PoA mainnet
      • Instruction for node operators
    • FAQ
  • βš–οΈLEGAL INFORMATION
    • Terms of Service
    • Protocol Disclaimer
    • Cookies Policy
    • Risk of using Eywa
Powered by GitBook
On this page
  • Overview
  • Inherited Contracts and Interfaces
  • Constants and State Variables
  • Constructor
  • External Functions
  • Internal and Private Functions
  • Errors
  • Summary
  1. DEVELOPER DOCUMENTATION
  2. Guide for Developers
  3. Technical Documentation for EYWA DAO Smart Contracts

CalldataHelperV1

Overview

CalldataHelperV1 is an upgradeable contract that assists with decoding and slicing transaction calldata. It extracts critical parameters such as method-specific calldata, a target address, and a chain identifier from a given input. This functionality is useful in scenarios where cross-chain calls or proxy calls need to parse custom-encoded calldata.

By implementing ICalldataHelperV1, the CalldataHelperV1 contract ensures a standardized interface for:

  • Initializing ownership through an upgradeable pattern.

  • Decoding calldata to separate out function-specific parameters from overhead bytes (e.g., selectors).

  • Validating slicing operations to prevent out-of-bounds data reads.


Inherited Contracts and Interfaces

  • UUPSUpgradeable (OpenZeppelin): Provides functions for upgrading this contract in a UUPS proxy setup, ensuring only the owner can authorize upgrades.

  • OwnableUpgradeable (OpenZeppelin): Implements ownership-related logic, allowing only the contract owner to perform certain actions.

  • ICalldataHelperV1: Declares the initialize and decode functions, as well as the InvalidSliceParameters error.


Constants and State Variables

This contract does not introduce new constants besides those inherited or implied from the interface. It also does not maintain any additional state variables beyond upgradeability and ownership structures provided by OpenZeppelin libraries.


Constructor

constructor() {
    _disableInitializers();
}
  • Description:

    • Disables initializers to ensure this upgradeable contract cannot be re-initialized after deployment, following best practices for UUPS proxy pattern.


External Functions

initialize(address owner_)

function initialize(address owner_) external initializer
  • Description:

    • Initializes the contract in an upgradeable context.

    • Sets up ownership by transferring ownership to the specified owner_.

    • Can only be called once due to the initializer modifier from OpenZeppelin.

  • Parameters:

    • owner_: The address of the contract owner.

  • Effects:

    • Calls __UUPSUpgradeable_init() and __Ownable_init(owner_), configuring the contract for UUPS upgradeability and ownership management.


decode(bytes calldata calldata_)

function decode(bytes calldata calldata_) external pure returns (
    bytes memory m_calldata,
    address m_target,
    uint64 m_chainId
)
  • Description:

    • Decodes the provided calldata to extract three main elements:

      1. m_calldata: The method-specific or function-specific bytes of calldata.

      2. m_target: The address the calldata is meant to target.

      3. m_chainId: The chain identifier for cross-chain or multi-chain scenarios.

    • Skips the first 4 bytes, typically used as a selector or prefix.

  • Parameters:

    • calldata_: The full calldata to decode, where the first 4 bytes are not part of the relevant data for extraction.

  • Return:

    • m_calldata: The extracted method calldata (bytes).

    • m_target: The extracted target address (address).

    • m_chainId: The extracted chain identifier (uint64).

  • Logic:

    • Calls the private _slice function to remove the first 4 bytes.

    • Uses abi.decode(...) with a tuple (bytes, address, uint64, address) to decode the relevant fields (although the last address is ignored in this particular decode pattern).


Internal and Private Functions

_authorizeUpgrade(address)

function _authorizeUpgrade(address) internal override onlyOwner
  • Description:

    • Restricts contract upgrades so that only the owner may authorize them, protecting upgrade logic from unauthorized calls.


_slice(bytes memory data_, uint256 start_, uint256 length_)

function _slice(
    bytes memory data_, 
    uint256 start_, 
    uint256 length_
) private pure returns (bytes memory result_)
  • Description:

    • Extracts a slice from data_ starting at offset start_ for length_ bytes.

    • Reverts with InvalidSliceParameters if out-of-bounds.

    • Used internally by decode to remove the first 4 bytes (or any other arbitrary slice).

  • Parameters:

    • data_: The original bytes array to slice.

    • start_: The offset in data_ to begin slicing.

    • length_: Number of bytes to copy into the new array.

  • Return:

    • result_: A newly allocated bytes array of size length_, containing the requested slice.

  • Errors:

    • InvalidSliceParameters(): Thrown if start_ + length_ exceeds the length of data_.


Errors

InvalidSliceParameters()

  • Description: Indicates that the requested slice exceeds the bounds of the original array (start_ + length_ > data_.length).


Summary

CalldataHelperV1 provides a lightweight, upgradeable solution for parsing transaction calldata and extracting specific parameters like function-specific calldata, target addresses, and chain IDs. It integrates with standard libraries for safe upgradeability (UUPSUpgradeable) and ownership control (OwnableUpgradeable), ensuring secure and maintainable deployment. By strictly enforcing slice parameter checks and skipping the initial 4 bytes, CalldataHelperV1 simplifies the process of handling custom-encoded transaction data in cross-chain or proxied contexts.

PreviousRewardsDistributorFactoryV1NextTreasury

Last updated 1 month ago

πŸ’»