LibBridge
provides functions for bridging assets into and out of a decentralized exchange system using either the Wormhole bridge or the Stargate bridge.
bridgeIn()
The purpose of this function is to provide a unified way to bridge assets into a decentralized exchange system using either the Wormhole or Stargate bridge, depending on the bridge type specified in the BridgeArgs
struct. This allows the decentralized exchange system to support multiple bridge types and switch between them as needed.
The function first checks the type of bridge specified in the BridgeArgs
struct. If it is Wormhole
, it calls the bridgeIn
function of the LibWormhole
library, passing in the necessary parameters. If it is Stargate
, it calls the bridgeIn
function of the LibStargate
library. If the specified bridge type is neither Wormhole
nor Stargate
, the function reverts and throws an InvalidBridgeType
error.
Input
recipientNetworkId
uint16
network identifier of the target chain
bridgeArgs
BridgeArgs
struct BridgeArgs {
BridgeType bridgeType;
bytes payload;
}
amount
uint256
the amount that needs to be swapped
toAssetAddress
address
the target asset
Output
tokenSequence
uint64
the sequence received after a successful bridgIn
bridgeOut()
Similar to the bridgeIn
function but handles withdrawals of assets instead. It takes in a BridgeArgs
struct that specifies the bridge type and the payload data for the bridge transaction. It also takes in a Transaction struct that contains information about the transaction being processed, such as the recipient address and the amount being withdrawn. Finally, it takes in a TransferKey
struct that contains information needed to validate the withdrawal transaction. The bridgeOut
function then delegates to the appropriate bridge implementation based on the bridge type specified in the BridgeArgs
struct. If the bridge type is BridgeType.Wormhole
, it calls the bridgeOut
function in LibWormhole
. If the bridge type is BridgeType.Stargate
, it calls the bridgeOut
function in LibStargate
.
Input
bridgeArgs
BridgeArgs
struct BridgeArgs {
BridgeType bridgeType;
bytes payload;
}
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;
}
Output
amount
uint256
The amount received after bridging out.
Last updated