> For the complete documentation index, see [llms.txt](https://docs.fly.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fly.trade/developers/deprecated-magpie-contracts/magpieaggregator-diamond-proxy/libraries/libmagpieaggregator.md).

# LibMagpieAggregator

It defines a storage structure and utility functions for managing various settings and data in the Magpie Aggregator application.

```solidity
struct CurveSettings {
    address mainRegistry;
    address cryptoRegistry;
    address cryptoFactory;
}
```

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>mainRegistry
</code></pre></td><td><pre><code>address
</code></pre></td><td>Address of the main registry of the curve protocol.</td></tr><tr><td><pre><code>cryptoRegistry
</code></pre></td><td><pre><code>address
</code></pre></td><td>Address of the crypto registry of the curve protocol</td></tr><tr><td><pre><code>cryptoFactory
</code></pre></td><td><pre><code>address
</code></pre></td><td>Address of the crypto factory of the crypto factory</td></tr></tbody></table>

```solidity
struct Amm {
    uint8 protocolId;
    bytes4 selector;
    address addr;
}
```

<table><thead><tr><th>Field </th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>protocolId
</code></pre></td><td><pre><code>uint8
</code></pre></td><td>The protocol identifier provided by magpie team.</td></tr><tr><td><pre><code>selector
</code></pre></td><td><pre><code>bytes4
</code></pre></td><td>The function selector of the AMM.</td></tr><tr><td><pre><code>addr
</code></pre></td><td><pre><code>address
</code></pre></td><td>The address of the facet of the AMM.</td></tr></tbody></table>

```solidity
struct WormholeBridgeSettings {
    address bridgeAddress;
}
```

<table><thead><tr><th>Field </th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>bridgeAddress
</code></pre></td><td><pre><code>address
</code></pre></td><td>The wormhole token bridge address</td></tr></tbody></table>

```solidity
struct StargateSettings {
    address routerAddress;
}
```

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>routerAddress
</code></pre></td><td><pre><code>address
</code></pre></td><td>The stargate router address.</td></tr></tbody></table>

```solidity
struct WormholeSettings {
    address bridgeAddress;
    uint8 consistencyLevel;
}
```

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>bridgeAddress
</code></pre></td><td><pre><code>address
</code></pre></td><td>The wormhole core bridge address.</td></tr><tr><td><pre><code>consistencyLevel
</code></pre></td><td><pre><code>uint8
</code></pre></td><td>The level of finality the guardians will reach before signing the message</td></tr></tbody></table>

```solidity
struct LayerZeroSettings {
    address routerAddress;
}
```

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>routerAddress
</code></pre></td><td><pre><code>address
</code></pre></td><td>The router address of layer zero protocol</td></tr></tbody></table>

```solidity
struct CelerBridgeSettings {
    address messageBusAddress; 
}
```

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>messageBusAddress
</code></pre></td><td><pre><code>address
</code></pre></td><td>The message bus address of celer bridge</td></tr></tbody></table>

```solidity
struct AppStorage {
    address weth;
    uint16 networkId;
    mapping(uint16 => bytes32) magpieAggregatorAddresses;
    mapping(address => uint256) deposits;
    mapping(address => mapping(address => uint256)) depositsByUser;
    mapping(uint16 => mapping(bytes32 => mapping(uint64 => bool))) usedTransferKeys;
    uint64 swapSequence;
    // Pausable
    bool paused;
    // Reentrancy Guard
    bool guarded;
    // Amm
    mapping(uint16 => Amm) amms;
    // Curve Amm
    CurveSettings curveSettings;
    // Data Transfer
    mapping(uint16 => mapping(uint16 => mapping(bytes32 => mapping(uint64 => bytes)))) payloads;
    // Stargate Bridge
    StargateSettings stargateSettings;
    mapping(uint16 => bytes32) magpieStargateBridgeAddresses;
    // Wormhole Bridge
    WormholeBridgeSettings wormholeBridgeSettings;
    mapping(uint64 => uint64) wormholeTokenSequences;
    // Wormhole Data Transfer
    WormholeSettings wormholeSettings;
    mapping(uint16 => uint16) wormholeNetworkIds;
    mapping(uint64 => uint64) wormholeCoreSequences;
    // LayerZero Data Transfer
    LayerZeroSettings layerZeroSettings;
    mapping(uint16 => uint16) layerZeroChainIds;
    mapping(uint16 => uint16) layerZeroNetworkIds;
    address magpieRouterAddress;
    mapping(uint16 => mapping(bytes32 => mapping(uint64 => mapping(address => uint256)))) stargateDeposits;
    mapping(uint8 => bool) delegatedCalls;
    // Celer Bridge
    CelerBridgeSettings celerBridgeSettings;
    mapping(uint16 => uint64) celerChainIds;
    mapping(uint16 => mapping(bytes32 => mapping(uint64 => mapping(address => uint256)))) celerDeposits;
    mapping(uint16 => mapping(bytes32 => mapping(uint64 => address))) celerRefundAddresses;
    mapping(uint16 => bytes32) magpieCelerBridgeAddresses;
    mapping(uint16 => mapping(uint16 => mapping(bytes32 => mapping(uint64 => bytes32)))) payloadHashes;
    mapping(uint16 => bytes32) magpieStargateBridgeV2Addresses;
}
```

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>weth
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">address
</code></pre></td><td>Address of the Wrapped Ether (WETH) contract.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">networkId
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16
</code></pre></td><td>The network ID associated with the application.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">magpieAggregatorAddresses
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity"> mapping(uint16 => bytes32)
</code></pre></td><td>A mapping of network IDs to Magpie aggregator addresses.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">deposits
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(address => uint256)
</code></pre></td><td>Tracks the total deposits made by each user.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">depositsByUser
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(address => mapping(address => uint256))
</code></pre></td><td>Tracks the deposits made by each user for specific token addresses.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">usedTransferKeys
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => mapping(bytes32 => mapping(uint64 => bool)))
</code></pre></td><td>Tracks the usage status of transfer keys for specific network IDs, sender addresses, and swap sequences.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">swapSequence
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint64
</code></pre></td><td>A counter used for generating swap sequences.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">paused
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bool
</code></pre></td><td>A flag indicating whether the contract is paused or not.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">guarded
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bool
</code></pre></td><td>A flag indicating whether reentrancy guard is enabled or not.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">amms
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => Amm)
</code></pre></td><td>A mapping of network IDs to AMMs.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">curveSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">CurveSettings
</code></pre></td><td>Contains settings related to Curve AMMs.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">payloads
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => mapping(uint16 => mapping(bytes32 => mapping(uint64 => bytes))))
</code></pre></td><td>A mapping used for storing data transfer payloads.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">stargateSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">StargateSettings
</code></pre></td><td>Contains settings related to the Stargate bridge.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">magpieStargateBridgeAddresses
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => bytes32)
</code></pre></td><td>A mapping of network IDs to Magpie Stargate bridge addresses.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">wormholeBridgeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">WormholeBridgeSettings
</code></pre></td><td>Contains settings related to the Wormhole Token bridge.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">wormholeTokenSequences
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint64 => uint64)
</code></pre></td><td>Tracks the token sequences for the Wormhole bridge.</td></tr><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>Contains settings related to Wormhole data transfers.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">wormholeNetworkIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => uint16)
</code></pre></td><td>A mapping of network IDs for the Wormhole bridge.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">wormholeCoreSequences
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint64 => uint64)
</code></pre></td><td>Tracks the core sequences for the Wormhole bridge.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">layerZeroSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">LayerZeroSettings
</code></pre></td><td>Contains settings related to LayerZero data transfers.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">layerZeroChainIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => uint16)
</code></pre></td><td>A mapping of chain IDs for LayerZero data transfers.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">layerZeroNetworkIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity"> mapping(uint16 => uint16)
</code></pre></td><td>A mapping of network IDs for LayerZero data transfers.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">magpieRouterAddress
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">address
</code></pre></td><td>Address of the Magpie Router</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">stargateDeposits
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => mapping(bytes32 => mapping(uint64 => mapping(address => uint256))))
</code></pre></td><td>A mapping to show how much amount has been deposited why which address along with the message passed by the address and the networkId</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">delegatedCalls
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity"> mapping(uint8 => bool)
</code></pre></td><td>used to associate a boolean value (<code>bool</code>) with a single byte integer (<code>uint8</code>).</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">celerBridgeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">CelerBridgeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct CelerBridgeSettings {
    address messageBusAddress; // The message bus address of celer bridge
}
</code></pre></td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">celerChainIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => uint64)
</code></pre></td><td>A mapping of chain IDs for celer bridge transfers.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">celerDeposits
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => mapping(bytes32 => mapping(uint64 => mapping(address => uint256))))
</code></pre></td><td>A mapping of network Ids, data, chain Id, and address to the amount being deposited.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">celerRefundAddresses
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => mapping(bytes32 => mapping(uint64 => address)))
</code></pre></td><td>A mapping of network Ids, data, and chain id to the refund address.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">magpieCelerBridgeAddresses
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => bytes32)
</code></pre></td><td>A mapping of network ID to the magpie celer bridge  address in the form of bytes.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">payloadHashes
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => mapping(uint16 => mapping(bytes32 => mapping(uint64 => bytes32))))
</code></pre></td><td></td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">magpieStargateBridgeV2Addresses
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">mapping(uint16 => bytes32)
</code></pre></td><td>A mapping of network ID to the magpie stargate bridge  V2 address in the form of bytes.</td></tr></tbody></table>

### getStorage():

returns a reference to the `AppStorage` struct.

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
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">AppStorage
</code></pre></td><td><code>AppStorage</code> struct.</td></tr></tbody></table>
