LibWormhole

It provides functions for interacting with the Wormhole bridge in a decentralized exchange system.

WormhokeBridgeInData

FieldTypeDescription

recipientBridgeChainId

uint16

the receipient chain id as per wormhole standard.

updateSettings()

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

Input

FieldTypeDescription
wormholeBridgeSettings
WormholeBridgeSettings

struct WormholeBridgeSettings {
    address bridgeAddress;
}

normalize()

normalizes an amount from one decimal precision to another.

Input

FieldTypeDescription

fromDecimals

uint8

decimals of the source asset

toDecimals

uint8

decimals of the target asset

amount

uint256

amount that needs to be normalized

Output

FieldTypeDescription

amount

uint256

the normalized amount

denormalize()

denormalizes an amount from one decimal precision to another.

Input

FieldTypeDescription

fromDecimals

uint8

decimal of the source asset

toDecimals

uint8

decimal of the target asset

amount

uint256

amount that needs to be denormalized

Output

FieldTypeDescription

amount

uint256

the denormalized amount

getRecipientBridgeChainId

this function is responsible for extracting the recipient bridge chain ID from the provided bridge in payload.

Input

FieldTypeDescription

bridgeInPayload

bytes

Payload necessary for bridging in.

Output

FieldTypeDescription

recipientBridgeChainId

uint16

The receipient chain id fetched from the payload

bridgeIn

this function is responsible for executing the bridge-in operation using the Wormhole bridge. It performs dust management operations for token amounts, approves the spending of tokens, and calls the transferTokens function of the Wormhole bridge contract to initiate the token transfer. The recipient bridge chain ID, Magpie aggregator address, and timestamp-based nonce are provided as arguments to the transferTokens function.

Input

FieldTypeDescription

recipientNetworkId

uint16

The network identifier of the destination chain

bridgeArgs

BridgeArgs
struct BridgeArgs {
    BridgeType bridgeType;
    bytes payload;
}

amount

uint256

The amount that needs to be swapped

toAssetAddress

address

The final token that needs to be received

Output

FieldTypeDescription

tokenSequence

uint64

The sequence received after a successful bridging in

bridgeOut

this function is responsible for executing the bridge-out operation using the Wormhole bridge. It verifies the token sequence, extracts the amount of tokens from the payload, performs denormalization if necessary, and completes the transfer by calling the completeTransfer function of the Wormhole bridge contract.

Input

FieldTypeDescription

bridgeOutPayload

bytes

Payload contains data that is necessary for bridging out

transaction

Transaction

struct Transaction {
    DataTransferType dataTransferType;
    BridgeType bridgeType;
    uint16 recipientNetworkId;
    bytes32 fromAssetAddress;
    bytes32 toAssetAddress;
    bytes32 toAddress;
    bytes32 recipientAggregatorAddress;
    uint256 amountOutMin;
    uint256 swapOutGasFee;
}

Output

FieldTypeDescription

amount

uint256

The amount received after bridging out

Event:

event UpdateWormholeBridgeSettings(address indexed sender, 
WormholeBridgeSettings wormholeBridgeSettings);

Last updated