# AggregatorFacet

The `AggregatorFacet` contract serves as the implementation of the `IAggregator` interface. It provides functions for updating settings, performing swaps, managing deposits, retrieving payloads, and checking transfer key usage. The functions enforce necessary checks and interact with the underlying `LibAggregator` library to execute the operations.

### updateWeth()

The purpose of this function is to allow the contract owner to update the address of the WETH token used in the aggregator contract.

**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">weth
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">address
</code></pre></td><td>Address of wrapped native address (WETH for Ethereum, WMATIC for Polygon etc.)</td></tr></tbody></table>

### updateMagpieRouterAddress()

the `updateMagpieRouterAddress` function is a straightforward administrative function that allows the contract owner to update a critical component of the system, in this case, the address of the Magpie Router.

**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">magpieRouterAddress
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">address
</code></pre></td><td>This new address is  the updated address for the Magpie Router within the contract.</td></tr></tbody></table>

### updateNetworkId()

The purpose of this function is to allow the contract owner to update the network ID used in the aggregator contract.

**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">networkId
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16
</code></pre></td><td>networkId of the current chain in Magpie protocol, it is different from the actual networkId<br>ethereum: 1<br>polygon: 2<br>bsc: 3<br>avalanche: 4<br>arbitrum: 5 <br>optimism: 6<br></td></tr></tbody></table>

### addMagpieAggregatorAddresses()

The purpose of this function is to allow the contract owner to add Magpie aggregator addresses for multiple network IDs in the aggregator contract.

**Input**

<table><thead><tr><th width="311.3333333333333">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><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>networkIds of the networks we want to add</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">bytes32[]
</code></pre></td><td>Address of MagpieAggregator contracts on the specified chains/networks</td></tr></tbody></table>

### swapIn()

this function is responsible for executing a swap-in operation. It enforces various checks such as the deadline, pausing status, and custom guards.

**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">swapInArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">SwapInArgs
</code></pre></td><td>SwapInArgs is a struct, its explained <a href="/pages/GofltEY63pRiP44jn7UJ#swapinargs">here</a></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">amountOut
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint256
</code></pre></td><td>amountOut that you will receive after swapping tokens</td></tr></tbody></table>

### swapOut()

this function is responsible for executing a swap-out operation. It enforces various checks such as the deadline, pausing status, and custom guards.

**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">swapOutArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">SwapOutArgs
</code></pre></td><td>SwapOutArgs is a struct, its explained <a href="/pages/GofltEY63pRiP44jn7UJ#swapoutargs">here</a></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">amountOut
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint256
</code></pre></td><td>amountOut that you will receive after swapping tokens</td></tr></tbody></table>

### getDeposit()

The purpose of this function is to allow external callers to retrieve the deposit amount for a specific asset in the aggregator contract.

**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">assetAddress
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">address
</code></pre></td><td>Address of the token for which you want to query deposit</td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint256
</code></pre></td><td>It returns the amount of deposited assets </td></tr></tbody></table>

### withdraw()

The purpose of this function is to allow external callers to initiate the withdrawal of funds from the aggregator contract for a specific asset.

**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">assetAddress
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">address
</code></pre></td><td>Address of the token which will be withdrawn</td></tr></tbody></table>

### getDepositByUser()

The purpose of this function is to allow external callers to retrieve the deposit amount for a specific asset deposited by a specific user in the aggregator contract.

**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">assetAddress
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">address
</code></pre></td><td>the address of the asset whose deposited amount needs to be retrieved</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">senderAddress
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">address
</code></pre></td><td>the address of the user who has deposited the asset</td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>amount</td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint256
</code></pre></td><td>the deposited amount</td></tr></tbody></table>

### isTransferKeyUsed()

The purpose of this function is to allow external callers to check if a specific transfer key has been used in the aggregator contract.

**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">networkId
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16
</code></pre></td><td>the source network identifier provided by the magpie team for each bloackchain</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">senderAddress
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes32
</code></pre></td><td>the address of the user </td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">coreSequence
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint64
</code></pre></td><td>the sequence stored in our data base</td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bool
</code></pre></td><td>True if the key has been used false if not</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/developers/deprecated-magpie-contracts/magpieaggregator-diamond-proxy/aggregator/aggregatorfacet.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.
