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
  • updateSettings()
  • addLayerZeroChainIds()
  • addLayerZeroNetworkIds()
  • decodeDataTransferInPayload()
  • encodeRemoteAndLocalAddresses()
  • dataTransfer()
  • getPayload()
  • registerPayload()
  • lzReceive()
  • Events:
  1. Developers
  2. Deprecated Magpie Contracts
  3. MagpieAggregator Diamond Proxy
  4. Data Transfer

LibLayerZero

The LibLayerZero library provides functions for updating Layer Zero settings, handling Layer Zero data transfers (in and out), decoding and encoding data transfer payloads, registering and retrieving extended payloads, and enforcing authorization for Layer Zero operations. It consist of two structs:

updateSettings()

updates the LayerZero settings of the Magpie aggregator contract by storing the given LayerZeroSettings struct in the storage of the aggregator contract.

Input

Field
Type
Description

addLayerZeroChainIds()

used to add a mapping of network IDs to chain IDs in LayerZero. Takes two arrays as input, networkIds and chainIds, where the i-th element of the networkIds array corresponds to the i-th element of the chainIds array.

Input

Field
Type
Description

An array of network identifiers provided by magpie team.

An array of layer zero blockchain identifiers

addLayerZeroNetworkIds()

used to add a mapping of chain IDs to network IDs in LayerZero. Takes two arrays as input, chainIds and networkIds, where the i-th element of the chainIds array corresponds to the i-th element of the networkIds array.

Input

Field
Type
Description

An array of layer zero blockchain identifiers

An array of network identifiers provided by magpie team.

decodeDataTransferInPayload()

takes a byte array as input and returns a LayerZeroDataTransferInData struct. This struct contains the fee that is required to be paid for the data transfer.

Input

Field
Type
Description

Payload required for transfering data from one chain to another

Output

Field
Type
Description

encodeRemoteAndLocalAddresses()

this function is responsible for encoding the remote and local addresses into a bytes array.

Input

Field
Type
Description

target address

source address

Output

Field
Type
Description

concatenated target and source address

dataTransfer()

responsible for transferring data using LayerZero. It takes two parameters as input: payload, which is the data that is to be transferred, and protocol, which is a DataTransferInProtocol struct that contains the payload and network ID.

Input

Field
Type
Description

Payload necessary for data transfer

getPayload()

takes a byte as input, which is the data transfer out payload, and returns the extended payload for the message using the sender network ID, sender address, and core sequence of the message.

Input

Field
Type
Description

Payload necessary for data transfer

Output

Field
Type
Description

Payload + extra information like which data transfer type has been used

registerPayload()

takes a TransferKey struct and a byte array as input and registers the extended payload for the message in the storage of the aggregator contract.

Input

Field
Type
Description

Payload + extra information like which data transfer type has been used

lzReceive()

is called when a message is received by the contract. It takes three parameters as input: senderChainId, which is the ID of the chain that sent the message, localAndRemoteAddresses, which is a byte array that contains the local and remote addresses of the sender, and extendedPayload, which is the extended payload for the message. This function validates the message and registers the extended payload for the message in the storage of the aggregator contract.

Input

Field
Type
Description

The layer zero chain identifier for the source chain

The address that will receive the data from layerzero

Payload + extra information like which data transfer type has been used

Events:

event UpdateLayerZeroSettings(address indexed sender, LayerZeroSettings layerZeroSettings);
event AddLayerZeroChainIds(address indexed sender, uint16[] networkIds, uint16[] chainIds);
event AddLayerZeroNetworkIds(address indexed sender, uint16[] chainIds, uint16[] networkIds);
event LzReceive(TransferKey transferKey, bytes payload);

Last updated 1 year ago

👩‍💻
layerZeroSettings
LayerZeroSettings
struct LayerZeroSettings {
    address routerAddress;
}
networkIds
uint16[]
chainIds
uint16[]
chainIds
uint16[]
networkIds
uint16[]
dataTransferInPayload
bytes
dataTransferInData
LayerZeroDataTransferInData
struct LayerZeroDataTransferInData {
    uint256 fee;
}
remoteAddress
bytes32
localAddress
address
encodedRemoteAndLocalAddresses
bytes
payload
bytes
protocol
DataTransferInProtocol
struct DataTransferInProtocol {
    uint16 networkId;
    DataTransferType dataTransferType;
    bytes payload;
}
dataTransferOutPayload
bytes
extendedPayload
bytes
transferKey
TransferKey
struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}
extendedPayload
bytes
senderChainId
uint16
localAndRemoteAddresses
bytes
extendedPayload
bytes