# LibWormhole

Contains several functions for interacting with a Wormhole bridge, which is a cross-chain communication protocol that allows tokens and other data to be transferred between different blockchains.

### updateSettings()

updates the wormholeSettings variable in the AppStorage struct with the provided wormholeSettings input parameter. The new settings are emitted in an UpdateWormholeSettings event.

**Input**

<table><thead><tr><th width="216.99999999999997">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">wormholeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">WormholeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct WormholeSettings {
    address bridgeAddress;
    uint8 consistencyLevel;
}
</code></pre></td></tr></tbody></table>

### addWormholeNetworkIds()

adds multiple chainIds and networkIds to the wormholeNetworkIds mapping in AppStorage. The new mappings are emitted in an AddWormholeNetworkIds event.

**Input**

<table><thead><tr><th width="216.99999999999997">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">chainIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16[]
</code></pre></td><td>An array of wormhole chain identifiers</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">networkIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16[]
</code></pre></td><td>An array of network identifiers provided by magpie team.</td></tr></tbody></table>

### dataTransfer()

transfers data across the Wormhole bridge by calling the publishMessage function on a Wormhole core contract with a given payload, timestamp, and consistency level.

**Input**

<table><thead><tr><th width="216.99999999999997">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">payload
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>Payload that contains the data which will be transferred over the blockchains</td></tr></tbody></table>

### getPayload()

verifies and returns the payload of a Wormhole message. It uses the parseAndVerifyVM function on a Wormhole core contract to check the validity of the message, and then extracts and returns the payload of the message..

**Input**

<table><thead><tr><th width="252.99999999999997">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">dataTransferOutPayload
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>payload required for receiving the data</td></tr></tbody></table>

**Output**

<table><thead><tr><th width="255.99999999999997">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">extendedPayload
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>Payload + extra information like which data transfer type has been used</td></tr></tbody></table>

### getCoreSequence()

this function is responsible for retrieving the core sequence value from the `s.wormholeCoreSequences` mapping based on the provided `transferKeyCoreSequence`.

**Input**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">transferKeyCoreSequence
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint64
</code></pre></td><td>The core sequence provided by magpie for data transfer</td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">s.wormholeCoreSequences[transferKeyCoreSequence]
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint64
</code></pre></td><td>The sequence received by the wormhole core bridge.</td></tr></tbody></table>

### Events:

```solidity
event UpdateWormholeSettings(address indexed sender, WormholeSettings wormholeSettings);
```

```solidity
event AddWormholeNetworkIds(address indexed sender, uint16[] chainIds, uint16[] networkIds);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fly.trade/flycn/developers/deprecated-magpie-contracts/magpieaggregator-diamond-proxy/data-transfer/libwormhole.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
