# Exchange Agent

Exchange Agent contract contains all the information and functions for which enables CoverCompared to take payment in multiple currencies even though our partners may take payments in limited forms.

### Get Token Amount For ETH

Using Uniswap TWAP oracles the  `getTokenAmountforETH` function calculates needed \_token amount for \_desiredAmount of ETH to be paid to buy cover

```c
function getTokenAmountForETH(address _token, 
    uint256 _desiredAmount)
```

#### Input variables :&#x20;

* \_token : refers to the token which is to be compared against ETH
* \_desiredAmount : desired ETH amount

### Get Needed Token Amount

Using Uniswap TWAP oracles the  `getNeededTokenAmount` function calculates needed \_token0 amount for \_desiredAmount of \_token1

```c
 function getNeededTokenAmount(
        address _token0,
        address _token1,
        uint256 _desiredAmount
    )
```

#### Input variables :&#x20;

* \_token0 : refers to the token which is to be compared
* \_token1 : refers to the token which is to be compared
* \_desiredAmount : desired token1 amount

### Swap Token with ETH

CoverCompared takes payment in a range of ERC20 tokens but our partners are limited and bound. Thus to forward the payment the `swapTokenWithETH` function is called after which the equivalent ETH is transferred to the partner.

```c
function swapTokenWithETH(
        address _token,
        uint256 _amount,
        uint256 _desiredAmount
    )
```

#### Input variables :&#x20;

* \_token : refers to the token which is to be compared against ETH
* *amount : \_token amount which user se*
* *desiredAmount : ETH amount which user desires to get instead of amount of \_token.*

### Swap Token with Token&#x20;

CoverCompared takes payment in a range of ERC20 tokens but our partners are limited and bound. Thus to forward the payment the `swapTokenToken` function is called after which the equivalent compliant ERC20 token is transferred.

```c
    function swapTokenWithToken(
        address _token0,
        address _token1,
        uint256 _amount,
        uint256 _desiredAmount
    )
```

#### Input variables :&#x20;

* \_token0 : refers to the token which is to be compared
* \_token1 : refers to the token which is to be compared
* \_amount : *token0 amount which user sends to get* token1
* *desiredAmount : token1 amount which user desires to get instead of \_amount of \_token0*

Note : When the total paid amout becomes equal to the loan amount, the status of the loan will be automatically changed to LOAN PAID.


---

# 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://www-covercompared.gitbook.io/docs/covercompared-dapp/defi-covers/exchange-agent.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.
