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
  • SwapInArgs
  • SwapOutArgs
  • SwapOutVariables
  • updateWeth()
  • updateMagpieRouterAddress()
  • updateNetworkId()
  • addMagpieAggregatorAddresses()
  • swapIn()
  • swapOut()
  • getDeposit()
  • withdraw()
  • getDepositByUser()
  • isTransferKeyUsed()
  • bridgeIn():
  • bridgeOut():
  • dataTransferIn():
  • dataTransferOut():
  • Events:
  1. Developers
  2. Deprecated Magpie Contracts
  3. MagpieAggregator Diamond Proxy
  4. Aggregator

LibAggregator

The purpose of this library is to provide the core functionality for aggregating swap transactions and managing related operations within the Aggregator contract. The library has three structs.

SwapInArgs

Field
Type
Description

bytes memory

SwapOutArgs

Field
Type
Description

SwapOutVariables

Field
Type
Description

The address of the asset being swapped out.

The address of the asset to which the swap is being performed.

The address to which the swapped asset will be transferred.

The address to which any transaction fee associated with the swap will be sent.

The amount of the asset being swapped out.

The amount of the asset being swapped out.

updateWeth()

The purpose of this function is to allow the contract owner to update the address of the WETH token used in the aggregator contract.

Input

Field
Type
Description

Address of the Wrapped Ether (WETH) contract.

updateMagpieRouterAddress()

This function is responsible for updating the magpieRouterAddress variable within the contract's storage, allowing changes to be made to the address associated with the Magpie Router. Only contract owner can call this function.

Input

Field
Type
Description

The address of the magpie router.

updateNetworkId()

The purpose of this function is to allow the contract owner to update the network ID used in the aggregator contract. Only contract owner can call this function.

Input

Field
Type
Description

The network ID associated with the application.

addMagpieAggregatorAddresses()

The purpose of this function is to allow the contract owner to add Magpie aggregator addresses for multiple network IDs in the aggregator contract.

Input

Field
Type
Description

The network ID associated with the application.

The Magpie Diamond contract addresses for each of the networkIDs

swapIn()

This function allows for swapping assets into the contract using a bridge-in transaction. It facilitates interoperability between different networks and allows users to transfer assets from one network to another through the contract.

Input

Field
Type
Description

Output

Field
Type
Description

The amount received after swapping

swapOut()

This function allows for swapping out assets from the contract using a bridge-out transaction. It facilitates interoperability between different networks and allows users to transfer assets from the contract to another network through the bridge-out mechanism.

Input

Field
Type
Description

Output

Field
Type
Description

The amount received after swapping

getDeposit()

The purpose of this function is to allow external callers to retrieve the deposit amount for a specific asset in the aggregator contract.

Input

Field
Type
Description

Address of the asset that will be deposited

Output

Field
Type
Description

The deposited amount

withdraw()

This function provides a way for users to withdraw their deposited assets from the contract, ensuring that only the rightful owner can withdraw their funds.

Input

Field
Type
Description

The asset that will be withdrawn

getDepositByUser()

The purpose of this function is to allow external callers to retrieve the deposit amount for a specific asset deposited by a specific user in the aggregator contract.

Input

Field
Type
Description

Address of the asset that will be deposited

Address of the user who has deposited the asset

Output

Field
Type
Description

Deposited amount

isTransferKeyUsed()

The purpose of this function is to allow external callers to check if a specific transfer key has been used in the aggregator contract.

Input

Field
Type
Description

networkId of the current chain in Magpie protocol, it is different from the actual networkId ethereum: 1 polygon: 2 bsc: 3 avalanche: 4 arbitrum: 5 optimism: 6

The address who initiated the transfer.

The magpie sequence for the current swap.

Output

Field
Type
Description

Flag used to identify if the transfer key has been used for swapping or not.

bridgeIn():

This function is responsible for executing a delegatecall to a specific facet in the Diamond contract, passing the bridgeInArgs data as the input. The specific functionality and behavior of the called facet would depend on the implementation details defined in the facet contract associated with the given selector.

Input:

Field
Type
Description

bridgeOut():

his function is responsible for executing a delegatecall to a specific facet in the Diamond contract, passing the bridgeOutArgs data as the input. The specific functionality and behavior of the called facet would depend on the implementation details defined in the facet contract associated with the given selector. The function expects the delegatecall to return a single uint256 value, which is then returned by the function itself.

Input:

Field
Type
Description

dataTransferIn():

This function is responsible for executing a delegatecall to a specific facet in the Diamond contract, passing the dataTransferInArgs data as the input. The specific functionality and behavior of the called facet would depend on the implementation details defined in the facet contract associated with the given selector.

Input:

Field
Type
Description

dataTransferOut():

Input:

Field
Type
Description

Output:

Field
Type
Description

transferKey

payload

A string of bytes that contains transactional data.

Events:

event UpdateWeth(address indexed sender, address weth);
event UpdateMagpieRouterAddress(address indexed sender, address weth);
event UpdateNetworkId(address indexed sender, uint16 networkId);
event AddMagpieAggregatorAddresses(
        address indexed sender,
        uint16[] networkIds,
        bytes32[] magpieAggregatorAddresses
    );
event SwapIn(
        address indexed fromAddress,
        bytes32 indexed toAddress,
        address fromAssetAddress,
        address toAssetAddress,
        uint256 amountIn,
        uint256 amountOut,
        TransferKey transferKey,
        Transaction transaction
    );
event SwapOut(
        address indexed fromAddress,
        address indexed toAddress,
        address fromAssetAddress,
        address toAssetAddress,
        uint256 amountIn,
        uint256 amountOut,
        TransferKey transferKey,
        Transaction transaction
    );
 event Withdraw(address indexed sender, address indexed assetAddress, uint256 amount);

Last updated 1 year ago

👩‍💻
swapArgs
bridgeArgs
BridgeArgs
struct BridgeArgs {
    BridgeType bridgeType;
    bytes payload;
}
dataTransferInProtocol
DataTransferInProtocol
struct DataTransferInProtocol {
    uint16 networkId;
    DataTransferType dataTransferType;
    bytes payload;
}
transactionValidation
TransactionValidation
struct TransactionValidation {
    bytes32 fromAssetAddress;
    bytes32 toAssetAddress;
    bytes32 toAddress;
    uint256 amountOutMin;
    uint256 swapOutGasFee;
}
swapArgs
bytes memory
bridgeArgs
BridgeArgs
struct BridgeArgs {
    BridgeType bridgeType;
    bytes payload;
}
dataTransferOutArgs
DataTransferOutArgs
struct DataTransferOutArgs {
    DataTransferType dataTransferType;
    bytes payload;
}
fromAssetAddress
address
toAssetAddress
address
toAddress
address
transactionToAddress
address
bridgeAmount
uint256
amountIn
uint256
weth
address
magpieRouterAddress
address
networkId
uint16
networkIds
uint16[]
magpieAggregatorAddresses
bytes32[]
swapInArgs
SwapInArgs
struct SwapInArgs {
    SwapArgs swapArgs;
    BridgeArgs bridgeArgs;
    DataTransferInProtocol dataTransferInProtocol;
    TransactionValidation transactionValidation;
}
amountOut
uint256
swapOutArgs
SwapOutArgs
struct SwapOutArgs {
    SwapArgs swapArgs;
    BridgeArgs bridgeArgs;
    DataTransferOutArgs dataTransferOutArgs;
}
amountOut
uint256
assetAddress
address
s.deposits[assetAddress]
uint256
assetAddress
address
assetAddress
address
senderAddress
address
s.depositsByUser[assetAddress][senderAddress]
uint256
networkId
uint16
senderAddress
bytes32
coreSequence
uint64
s.usedTransferKeys[networkId][senderAddress][swapSequence]
bool
bridgeInArgs
BridgeInArgs
struct BridgeInArgs {
    uint16 recipientNetworkId;
    BridgeArgs bridgeArgs;
    uint256 amount;
    address toAssetAddress;
    TransferKey transferKey;
}
bridgeOutArgs
BridgeOutArgs
struct BridgeOutArgs {
    BridgeArgs bridgeArgs;
    Transaction transaction;
    TransferKey transferKey;
}
dataTransferInArgs
DataTransferInArgs
struct DataTransferInArgs {
    DataTransferInProtocol protocol;
    TransferKey transferKey;
    bytes payload;
}
dataTransferOutArgs
DataTransferOutArgs
struct DataTransferOutArgs {
    DataTransferType dataTransferType;
    bytes payload;
}
TransferKey
struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}
bytes