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

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

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

LibStargate has the below functions:

updateSettings

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

Input

decodeBridgeOutPayload

decodes the bridgeOutPayload and returns the StargateBridgeOutData.

Input

Output

decodeBridgeInPayload

decodes the bridgeInPayload and returns the StargateBridgeInData.

Input

Output

getMinAmountLD

returns the minimum amount of tokens that can be bridged.

Input

Output

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

Output

getLzTxObj

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

Input

Output

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

Output

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

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

Output

addStargateBridgeAddresses():

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

Input

addstargateBridgeV2Addresses():

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

Input

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