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
  • StargateBridgeInData
  • StargateBridgeOutData
  • ExecuteBridgeInArgs
  • updateSettings
  • decodeBridgeOutPayload
  • decodeBridgeInPayload
  • getMinAmountLD
  • encodeRecipientAddress
  • getLzTxObj
  • bridgeIn
  • executeBridgeIn
  • bridgeOut
  • addStargateBridgeAddresses():
  • addstargateBridgeV2Addresses():
  • Events:
  1. Developers
  2. Deprecated Magpie Contracts
  3. MagpieAggregator Diamond Proxy
  4. Bridge

LibStargate

This library is implementing a bridge for cross-chain communication using the Stargate protocol.

The code defines three structs:

StargateBridgeInData

contains the chain ID of the recipient on the other chain, the IDs of the source and destination pools, and the amount of fees to be paid.

struct StargateBridgeInData {
    uint16 layerZeroRecipientChainId;
    uint256 sourcePoolId;
    uint256 destPoolId;
    uint256 fee;
    uint256 gasLimit;
}
Field
Type
Description

This field is an unsigned 16-bit integer that represents the chain ID of the recipient on Layer 0. Layer 0 typically refers to the root blockchain or the main chain.

This field is a uint256 value that represents the ID or identifier of the source pool. The exact meaning and context of the pool ID may depend on the specific implementation or protocol using this struct.

This field is a uint256 value that represents the ID or identifier of the destination pool. Similarly to the source pool ID, the meaning and context of the destination pool ID depend on the specific implementation or protocol.

This field is a uint256 value that represents the fee associated with the bridge operation.

The amount of gas fees one needs to execute the transaction.

StargateBridgeOutData

contains the address of the sender's bridge contract, a nonce, and the ID of the sender's chain.

struct StargateBridgeOutData {
    bytes srcAddress;
    uint256 nonce;
    uint16 srcChainId;
}
Field
Type
Description

This field is of type bytes and represents the source address.

This field is of type uint256 and represents a nonce value. Nonce is commonly used as a security measure to prevent replay attacks or ensure transaction ordering.

This field is of type uint16 and represents the source chain ID. It identifies the chain from which the bridge-out operation originates.

ExecuteBridgeInArgs

this struct is used to encapsulate the necessary input arguments for executing a bridge operation in the context of a Stargate bridge system. The fields hold relevant information such as network ID, token details, router address, recipient address, and additional bridge-specific data

struct ExecuteBridgeInArgs {
    address routerAddress;
    uint256 amount;
    bytes recipientAddress;
    TransferKey transferKey;
    StargateBridgeInData bridgeInData;
    IStargateRouter.lzTxObj lzTxObj;
}
Field
Type
Description

This field is of type address and represents the address of the router

This field is of type uint256 and represents the amount being bridged in. It specifies the quantity of tokens or assets involved in the bridge-in operation.

This field is of type bytes and represents the recipient address. The encoding and interpretation of the recipient address may depend on the specific requirements or format of the bridge system or protocol.

LibStargate has the below functions:

updateSettings

updates the stargateSettings struct in the contract's AppStorage struct.

Input

Field
Type
Description

decodeBridgeOutPayload

decodes the bridgeOutPayload and returns the StargateBridgeOutData.

Input

Field
Type
Description

Payload consisting of data necessary for bridging out

Output

Field
Type
Description

decodeBridgeInPayload

decodes the bridgeInPayload and returns the StargateBridgeInData.

Input

Field
Type
Description

Payload consisting of data necessary for bridging in.

Output

Field
Type
Description

getMinAmountLD

returns the minimum amount of tokens that can be bridged.

Input

Field
Type
Description

The amount that needs to be swapped

Output

Field
Type
Description

The minimum amount out

encodeRecipientAddress

this function is responsible for converting a bytes32 Ethereum address into a 20-byte bytes representation, suitable for further processing or storage within the contract.

Input

Field
Type
Description

The recipient address in bytes32

Output

Field
Type
Description

The receipient address in bytes

getLzTxObj

this function is responsible for creating and returning a layerZero transaction object (lzTxObj) based on the provided sender address.

Input

Field
Type
Description

The address that initiated the transaction.

Output

Field
Type
Description

bridgeIn

this function facilitates the bridging of tokens from the caller's network to a recipient network. It sets the necessary parameters, including the recipient address, bridge input data, lazy transaction object, token sequence, amount, network ID, and router address, and then calls the executeBridgeIn function to execute the bridge operation.

Input

Field
Type
Description

The network identifier of the destination chain

The amount that needs to be swapped

The final token that needs to be received

Output

Field
Type
Description

The sequence received after a successful bridging in

executeBridgeIn

this function is responsible for executing the bridge-in operation by calling the swap function of the StargateRouter contract with the necessary arguments. It handles the transaction fee, source and destination pool IDs, sender address, amount, minimum acceptable amount, lazy transaction object, recipient address, and payload.

Input

Field
Type
Description

bridgeOut

this function is responsible for executing the bridge out operation. It decodes the payload, retrieves the sender address, and calls the withdraw function of the IMagpieStargateBridge contract to withdraw tokens based on the provided arguments. The deposited amount for the fromAssetAddress is reduced accordingly.

Input

Field
Type
Description

Payload consisting of data necessary for briding out.

Output

Field
Type
Description

The amount received after bridging out.

addStargateBridgeAddresses():

It updates the Magpie Stargate bridge addresses for specific network IDs within the application storage.

Input

Field
Type
Description

An array of unsigned 16-bit integers (uint16) representing network identifiers.

An array of bytes32 values representing Magpie Stargate Bridge addresses.

addstargateBridgeV2Addresses():

It updates the Magpie Stargate bridge addresses for specific network IDs within the application storage.

Input

Field
Type
Description

An array of unsigned 16-bit integers (uint16) representing network identifiers.

An array of bytes32 values representing Magpie Stargate Bridge addresses.

Events:

event UpdateStargateSettings(address indexed sender, StargateSettings stargateSettings);
event AddMagpieStargateBridgeAddresses(
        address indexed sender,
        uint16[] networkIds,
        bytes32[] magpieStargateBridgeAddresses
    );
event AddMagpieStargateBridgeV2Addresses(
        address indexed sender,
        uint16[] networkIds,
        bytes32[] magpieStargateBridgeAddresses
    );

Last updated 1 year ago

👩‍💻
layerZeroRecipientChainId
uint16
sourcePoolId
uint256
destPoolId
uint256
fee
uint256
gasLimit
uint256
srcAddress
bytes
nonce
uint256
srcChainId
uint16
routerAddress
address
amount
uint256
recipientAddress
bytes
transferKey
TransferKey
struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}
bridgeInData
StargateBridgeInData
struct StargateBridgeInData {
    uint16 layerZeroRecipientChainId;
    uint256 sourcePoolId;
    uint256 destPoolId;
    uint256 fee;
}
lzTxObj
IStargateRouter.lzTxObj
struct lzTxObj {
        uint256 dstGasForCall;
        uint256 dstNativeAmount;
        bytes dstNativeAddr;
    }
stargateSettings
StargateSettings
struct StargateSettings {
    address routerAddress;
}
bridgeOutPayload
bytes
bridgeOutData
StargateBridgeOutData
struct StargateBridgeOutData {
    bytes srcAddress;
    uint256 nonce;
    uint16 srcChainId;
}
bridgeInPayload
bytes
bridgeInData
StargateBridgeInData
struct StargateBridgeInData {
    uint16 layerZeroRecipientChainId;
    uint256 sourcePoolId;
    uint256 destPoolId;
    uint256 fee;
}
amount
uint256
bridgeInData
StargateBridgeInData
struct StargateBridgeInData {
    uint16 layerZeroRecipientChainId;
    uint256 sourcePoolId;
    uint256 destPoolId;
    uint256 fee;
}
swapObj.amount
uint256
recipientAddress
bytes32
encodedRecipientAddress
bytes
sender
address
lzTxObj
IStargateRouter.lzTxObj
struct lzTxObj {
        uint256 dstGasForCall;
        uint256 dstNativeAmount;
        bytes dstNativeAddr;
    }
recipientNetworkId
uint16
bridgeArgs
BridgeArgs
struct BridgeArgs {
    BridgeType bridgeType;
    bytes payload;
}
amount
uint256
toAssetAddress
address
tokenSequence
uint64
executeBridgeInArgs
ExecuteBridgeInArgs
struct ExecuteBridgeInArgs {
    address routerAddress;
    uint256 amount;
    bytes recipientAddress;
    TransferKey transferKey;
    StargateBridgeInData bridgeInData;
    IStargateRouter.lzTxObj lzTxObj;
}
bridgeOutPayload
bytes
transaction
Transaction
struct Transaction {
    DataTransferType dataTransferType;
    BridgeType bridgeType;
    uint16 recipientNetworkId;
    bytes32 fromAssetAddress;
    bytes32 toAssetAddress;
    bytes32 toAddress;
    bytes32 recipientAggregatorAddress;
    uint256 amountOutMin;
    uint256 swapOutGasFee;
}
transferKey
TransferKey
struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}
amount
uint256
networkIds
uint16[]
magpieStargateBridgeAddresses
bytes32[]
networkIds
uint16[]
magpieStargateBridgeAddresses
bytes32[]