# LibDataTransfer

This is a Solidity smart contract library that provides functions related to data transfer between different blockchain networks or layers.&#x20;

### getOriginalPayload()

this function is responsible for extracting the original payload from the extended payload by slicing the `extendedPayload` from the 42nd byte to the end. It removes the extended part of the payload and returns the original payload.

**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">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>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>payload</td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>the original payload</td></tr></tbody></table>

### dataTransfer()

this function is responsible for executing data transfer operations based on the specified protocols. It increments the core sequence, creates a transfer key, generates the extended payload, and processes each protocol in `dataTransferInArgs.protocols`. Depending on the protocol's `dataTransferType`, either the Wormhole or LayerZero data transfer function is called. If an unrecognised `dataTransferType` is encountered, the function reverts with an error.

**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">dataTransferInArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">DataTransferInArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct DataTransferInArgs {
    DataTransferInProtocol protocol;
    TransferKey transferKey;
    bytes payload;
}

</code></pre></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">transferKey
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">TransferKey
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}
</code></pre></td></tr></tbody></table>

### getPayload()

this function is responsible for obtaining the transfer key and payload based on the specified data transfer type. Depending on the `dataTransferType` in `dataTransferOutArgs`, either the Wormhole or LayerZero library functions are called to obtain the payload.

**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">dataTransferOutArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">DataTransferOutArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct DataTransferOutArgs {
    DataTransferType dataTransferType;
    bytes payload;
}
</code></pre></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">transferKey
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">TransferKey
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}
</code></pre></td></tr><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>The data necessary for swapping.</td></tr></tbody></table>


---

# 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/libdatatransfer.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.
