LogoLogo
  • CrossCurve MetaLayer
    • βš™οΈWhat is CrossCurve MetaLayer
      • CrossCurve Consensus bridge
      • CrossCurve Pools v2
    • πŸ—ΊοΈRoadmap
      • 2024
  • 🏒CrossCurve DAO
    • Overview of CrossCurve DAO
    • Voting
    • Obtaining veEYWA and Calculating the Boost
    • Staking mechanics
    • NFTs
      • CrossCurve DAO NFT
      • EYWA NFT Collection
  • πŸ’ΌEarn with CrossCurve
    • Staking in CrossCurve
    • Providing Liquidity to CrossCurve Pools
    • Voting for Incentives
  • πŸ“–user documentation
    • πŸ›ΈMigration to Sonic
      • Why are we moving to Sonic
      • Sonic Upgrade Stages
      • Liquidity transfer from Fantom to Sonic
      • Sonic Incentives on CrossCurve MetaLayer
    • πŸ”ƒSwap interface
      • How to trade
      • Slippage settings
      • Routing
    • 🌊Liquidity Interface
      • Easy mode
      • via Curve (Balanced)
      • Liquidity provision use cases
        • Deposit
          • Easy mode (Imbalanced)
          • via Curve (Balanced)
        • Withdraw
          • Easy mode (Imbalanced)
          • via Curve (Balanced)
        • Curve Knowledge Database
          • Balanced liquidity provision
          • Guide to transferring CRV from Fantom chain to Ethereum mainnet
          • Disclamer
    • 🏒DAO
      • Locker Interface
      • Vote Interface
      • Incentives Interface
      • Working with the EYWA Locker contract in Arbiscan.
    • 🌾Yield
      • Farms Interface
        • Staking liquidity and earning rewards
      • APR Calculator
      • EYWA pool via Convex
    • πŸ’ΌVesting
      • Claim portal interface
      • Early farming program interface
    • EYWA NFT
      • Bridge interface in the Aurora chain
      • Merge interface in the Arbitrum chain
      • EYWA NFT Manager interface
      • Dashboard interface
    • Leaderboard
    • ❄️Outdated
      • Early farming program
  • πŸ“–Developer documentation
    • Pools/asset contracts
      • Hubchain Pools and Assets
      • πŸ’±Supported tokens
    • πŸ”—CrossCurve smart contracts
    • πŸ’»Guide for Developers
      • Technical Documentation for CrossCurve DAO Smart Contracts
        • CalldataHelperV1
        • DelegationManagerV1
        • DelegationConditionValidatorV1
        • EmissionManagerV1
        • EscrowManager
        • EscrowVoteManagerV1
        • GaugeFactoryV1
        • GaugeV1
        • IncentiveRewardsDistributor
        • LockHolderFactoryV1
        • LockHolderV1
        • ProposalManager
        • RebaseRewardsDistributorV1
        • RewardsDistributorFactoryV1
        • Treasury
      • πŸ”ƒMake cross-chain swap
      • πŸ”¦Tracking cross-chain swap
      • πŸ“”Pusher API Reference
      • πŸ“Glossary
      • API Specification
  • πŸ“£About CrossCurve
    • πŸ›‘οΈSecurity audits
    • 🧠Team
    • Project History
    • Website
    • Telegram
    • Twitter
    • Medium
    • Discord
    • YouTube
    • LinkedIn
    • GitHub
Powered by GitBook
On this page
  • Overview
  • Inherited Contracts and Interfaces
  • Constants and State Variables
  • Constructor
  • External Functions
  • Internal and Private Functions
  • Errors
  • Summary
Export as PDF
  1. Developer documentation
  2. Guide for Developers
  3. Technical Documentation for CrossCurve 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.

PreviousTechnical Documentation for CrossCurve DAO Smart ContractsNextDelegationManagerV1

Last updated 1 month ago

πŸ“–
πŸ’»