Magpie Protocol
  • Magpie Protocol
    • What is Magpie solving?
      • What is DeFi?
    • Magpies Key Features
      • Use Cases
    • FLY
      • xFLY & FLY33
  • 📶Supported Networks
  • Guides
    • 📖Glossary of DeFi Terms
    • 👜Connect Wallet
    • 🔄On-Chain Swap
    • 🔀Cross-Chain Swap
    • 🔂Swap configuration
    • 🥚Magpie Boosts
    • 📒Transaction History
    • 💲Portfolio
  • Media Kit
  • 👩‍💻Developers
    • Magpie Contracts
      • MagpieCCTPBridge
      • MagpieCelerBridgeV2
      • MagpieRouterV3
      • MagpieStargateBridgeV3
      • LibAsset
      • LibBridge
      • LibRouter
    • Smart Contracts Audit
    • Deployments
    • API Reference
      • On chain swap
      • Cross chain swap
      • Requesting and Using API Key
Powered by GitBook
On this page
  • toAddress():
  • slice():
  • concat():
  1. Developers
  2. Deprecated Magpie Contracts
  3. MagpieAggregator Diamond Proxy
  4. Libraries

LibBytes

These utility functions provide convenient operations for manipulating byte arrays in Solidity.

toAddress():

This function is used to convert a portion of a byte array into an address. It takes in the byte array (self) and a starting index (start). It verifies that the byte array has enough bytes to read an address (20 bytes) starting from the specified index. Then, it uses assembly code to load the address from the specified location in memory and returns it.

Input:

Field
Type
Description

The bytes that contains the address.

The starting position to retrieve the address from the bytes.

Output:

Field
Type
Description

The retrieved address from the bytes.

slice():

This function is used to extract a slice of bytes from a byte array. It takes in the byte array (self), a starting index (start), and a length (length). It checks that the specified slice is within the bounds of the byte array. Then, it creates a new byte array (tempBytes) with a length equal to the specified slice length. It uses assembly code to copy the slice from the original byte array to the new byte array. Finally, it updates the length of the new byte array and returns it.

Input:

Field
Type
Description

The string of bytes that needs to be sliced

The starting position to begin slicing

The length of the byte

Output:

Field
Type
Description

The sliced byte

concat():

This function is used to concatenate two byte arrays. It takes in two byte arrays (self and postBytes). It creates a new byte array (tempBytes) with a length equal to the combined lengths of the two input byte arrays. It uses assembly code to copy the contents of the two byte arrays into the new byte array. Finally, it updates the length of the new byte array and returns it.

Input:

Field
Type
Description

The bytes that needs to be concatenated.

The bytes that needs to be concatenated.

Output:

Field
Type
Description

The concatenated bytes

Last updated 1 year ago

👩‍💻
self
bytes
start
uint256
tempAddress
address
self
bytes
start
uint256
length
uint256
tempBytes
bytes
self
bytes
postBytes
bytes
tempBytes
bytes