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
Field | Type | Description |
---|---|---|
network identifier of the target chain | ||
the amount that needs to be swapped | ||
the target asset |
Output
Field | Type | Description |
---|---|---|
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
Field | Type | Description |
---|---|---|
Output
Field | Type | Description |
---|---|---|
The amount received after bridging out. |
Last updated