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

FieldTypeDescription

swapArgs

bytes memory

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;
}

SwapOutArgs

FieldTypeDescription

swapArgs

SwapArgs

struct SwapArgs {
    uint256 amountOutMin;
    uint256 deadline;
    uint256[] amountIns;
    bytes32[] hops;
    bytes addresses;
    bytes poolData;
}

bridgeArgs

BridgeArgs

struct BridgeArgs {
    BridgeType bridgeType;
    bytes payload;
}

dataTransferOutArgs

DataTransferOutArgs

struct DataTransferOutArgs {
    DataTransferType dataTransferType;
    bytes payload;
}

SwapOutVariables

FieldTypeDescription

fromAssetAddress

address

The address of the asset being swapped out.

toAssetAddress

address

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

toAddress

address

The address to which the swapped asset will be transferred.

transactionToAddress

address

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

bridgeAmount

uint256

The amount of the asset being swapped out.

amountIn

uint256

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

FieldTypeDescription

weth

address

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.

Input

FieldTypeDescription

magpieRouterAddress

address

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.

Input

FieldTypeDescription

networkId

uint16

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

FieldTypeDescription

networkIds

uint16[]

The network ID associated with the application.

magpieAggregatorAddresses

bytes32[]

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

FieldTypeDescription

swapInArgs

SwapInArgs

struct SwapInArgs {
    SwapArgs swapArgs;
    BridgeArgs bridgeArgs;
    DataTransferInProtocol dataTransferInProtocol;
    TransactionValidation transactionValidation;
}

Output

FieldTypeDescription

amountOut

uint256

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

FieldTypeDescription

swapOutArgs

SwapOutArgs

struct SwapOutArgs {
    SwapArgs swapArgs;
    BridgeArgs bridgeArgs;
    DataTransferOutArgs dataTransferOutArgs;
}

Output

FieldTypeDescription

amountOut

uint256

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

FieldTypeDescription

assetAddress

address

Address of the asset that will be deposited

Output

FieldTypeDescription

s.deposits[assetAddress]

uint256

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

FieldTypeDescription

assetAddress

address

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

FieldTypeDescription

assetAddress

address

Address of the asset that will be deposited

senderAddress

address

Address of the user who has deposited the asset

Output

FieldTypeDescription

s.depositsByUser[assetAddress][senderAddress]

uint256

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

FieldTypeDescription

networkId

uint16

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

senderAddress

bytes32

The address who initiated the transfer.

coreSequence

uint64

The magpie sequence for the current swap.

Output

FieldTypeDescription

s.usedTransferKeys[networkId][senderAddress][swapSequence]

bool

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:

FieldTypeDescription

bridgeInArgs

BridgeInArgs
struct BridgeInArgs {
    uint16 recipientNetworkId;
    BridgeArgs bridgeArgs;
    uint256 amount;
    address toAssetAddress;
    TransferKey transferKey;
}

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:

FieldTypeDescription

bridgeOutArgs

BridgeOutArgs
struct BridgeOutArgs {
    BridgeArgs bridgeArgs;
    Transaction transaction;
    TransferKey transferKey;
}

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:

FieldTypeDescription

dataTransferInArgs

DataTransferInArgs
struct DataTransferInArgs {
    DataTransferInProtocol protocol;
    TransferKey transferKey;
    bytes payload;
}

dataTransferOut():

Input:

FieldTypeDescription

dataTransferOutArgs

DataTransferOutArgs
struct DataTransferOutArgs {
    DataTransferType dataTransferType;
    bytes payload;
}

Output:

FieldTypeDescription

transferKey

TransferKey

struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}

payload

bytes

A string of bytes that contains transactional data.

Last updated