# Quoter

{% embed url="<https://github.com/CoinQuoter/CoinQuoter_SmartContracts/blob/main/Quoter-Core/contracts/Quoter/QuoterProtocol.sol>" %}

### Contract info

**Contract name**: Quoter Protocol

**Contract addresses:**&#x20;

Harmony Mainnet: 0xFFFD451F62bE856E0cADdAc7c9a2e60aC5842C48

Binance Smart Chain Mainnet: 0x76540F7e38dFCdF3b39A501Bb7ef77c3705f4F17

Harmony Testnet: 0x028739801886AC60E0428e918e2bC9cA5D06399E

### Functions

#### balance

```solidity
function balance(address token) external view returns (uint256)
```

Returns balance of a token available for use in Quoter.

Parameters:

<table><thead><tr><th width="151.63288949701885">Name</th><th width="170.1948523163764">Type</th><th>Description</th></tr></thead><tbody><tr><td>token</td><td>address</td><td>Token address of a token to check balance of.</td></tr></tbody></table>

Returns:

| Type    | Description            |
| ------- | ---------------------- |
| uint256 | Balance of given token |

#### cancelOrderRFQ

```solidity
function cancelOrderRFQ(uint256 orderInfo) external override
```

Cancels order's quote.

Paramaters:

| Name      | Type    | Description                                |
| --------- | ------- | ------------------------------------------ |
| orderInfo | uint256 | Order info contains timestamp and order id |

#### createOrUpdateSession

```solidity
function createOrUpdateSession(address sessionKey, uint256 expirationTime)
        external
        returns (SessionStatus)
```

Creates or updates session that lets maker and taker to trade without signing messages through wallet.

Parameters:

| Name           | Type    | Description                               |
| -------------- | ------- | ----------------------------------------- |
| sessionKey     | address | Public key of a session                   |
| expirationTime | uint256 | Expiration time in unix seconds timestamp |

Returns:

<table><thead><tr><th width="191">Type</th><th>Description</th></tr></thead><tbody><tr><td>SessionStatus</td><td>One of the value from enum (created, updated) that indicates the status of session</td></tr></tbody></table>

#### depositToken

```solidity
function depositToken(address token, uint256 amount)
        external
        returns (uint256)
```

Deposits given token of frontend to the Quoter smart contract and stores the balance information.

| Name   | Type    | Description                                                                                                         |
| ------ | ------- | ------------------------------------------------------------------------------------------------------------------- |
| token  | address | Address of token to deposit, depositing wallet must give an allowance to the Quoter smart contract for given amount |
| amount | uint256 | Amount of tokens to deposit                                                                                         |

Returns:

| Type    | Description                             |
| ------- | --------------------------------------- |
| uint256 | The balance after depositing the tokens |

#### endSession

```solidity
function endSession() external;
```

Terminates active session

#### fillOrderRFQ

```solidity
function fillOrderRFQ(
        OrderRFQ memory order,
        bytes calldata signature,
        uint256 takingAmount,
        uint256 makingAmount
    ) external returns (OrderRFQAmounts memory amounts);
```

Fills order's quote, fully or partially (whichever is possible)

Parameters:

| Name         | Type     | Description                          |
| ------------ | -------- | ------------------------------------ |
| order        | OrderRFQ | Order quote to fill                  |
| signature    | bytes    | Signature to confirm quote ownership |
| takingAmount | uint256  | Taking amount                        |
| makingAmount | uint256  | Making amount                        |

Returns:

|         | Type            | Description                                |
| ------- | --------------- | ------------------------------------------ |
| amounts | OrderRFQAmounts | Amounts - filled taking and making amounts |

#### fillOrderRFQCallPeriphery

```solidity
function fillOrderRFQCallPeriphery(
        OrderRFQ memory order,
        bytes calldata signature,
        uint256 takingAmount,
        uint256 makingAmount,
        address receiver,
        bytes calldata data
    ) external returns (OrderRFQAmounts memory amounts, bytes memory result);
```

Fills order's quote, fully or partially (whichever is possible) and calls external contract function

Parameters:

| Name         | Type     | Description                                                                                                              |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| order        | OrderRFQ | Order quote to fill                                                                                                      |
| signature    | bytes    | Signature to confirm quote ownership                                                                                     |
| takingAmount | uint256  | Taking amount                                                                                                            |
| makingAmount | uint256  | Making amount                                                                                                            |
| receiver     | address  | Address of contract that will receive the call after successful validation of RFQ order and transfer from taker to maker |
| data         | bytes    | external call data                                                                                                       |

Returns:

|         | Type            | Description                                |
| ------- | --------------- | ------------------------------------------ |
| amounts | OrderRFQAmounts | Amounts - filled taking and making amounts |

#### session

```solidity
function session(address owner)
        external
        view
        returns (
            address creator,
            address sessionKey,
            uint256 expirationTime,
            uint256 txCount
        );
```

Returns session data

Parameters:

| Name  | Type    | Description                           |
| ----- | ------- | ------------------------------------- |
| owner | address | Wallet address of the session's owner |

Returns:

| Name           | Type    | Description                                                           |
| -------------- | ------- | --------------------------------------------------------------------- |
| creator        | adress  | Wallet address of the session's owner                                 |
| sessionKey     | address | Session public key                                                    |
| expirationTime | uint256 | Session expiration unix timestamp, might be zero if it was terminated |
| txCount        | uint256 | Number of transactions made during session                            |

#### sessionExpirationTime

```solidity
function sessionExpirationTime(address owner)
        external
        view
        returns (uint256 expirationTime);
```

Returns expiration unix timestamp of given address session

Parameters:

| Name  | Type    | Description                           |
| ----- | ------- | ------------------------------------- |
| owner | address | Wallet address of the session's owner |

Returns:

| Name           | Type    | Description                                                           |
| -------------- | ------- | --------------------------------------------------------------------- |
| expirationTime | uint256 | Session expiration unix timestamp, might be zero if it was terminated |

#### setReferralBonus

```solidity
function setReferralBonus(uint256 bonus) external onlyOwner;
```

//Opis

Parameters:

| Name  | Type    | Description |
| ----- | ------- | ----------- |
| bonus | uint256 |             |

#### transferOwnership

```solidity
 function transferOwnership(address to)
        external
        onlyOwner
        returns (address oldOwner, address newOwner)
```

//Opis

Parameters:

| Name | Type    | Description                                   |
| ---- | ------- | --------------------------------------------- |
| to   | address | Address of wallet that will receive ownership |

Returns:

| Name     | Type    | Description               |
| -------- | ------- | ------------------------- |
| oldOwner | address | Address of previous owner |
| newOwner | address | Address of new owner      |

#### withdrawToken

```solidity
function withdrawToken(address token, uint256 amount) 
        external returns (uint256);
```

Withdraws given token of frontend from the Quoter contract

Parameters:

| Name   | Type    | Description                    |
| ------ | ------- | ------------------------------ |
| token  | address | Address of a token to withdraw |
| amount | uint256 | Amount of tokens to withdraw   |

Returns:

| Type    | Description                          |
| ------- | ------------------------------------ |
| uint256 | Balance after withdrawing the tokens |

### Events

#### OrderFilledRFQ

```solidity
event OrderFilledRFQ(bytes32 orderHash, uint256 takingAmount, uint256 makingAmount);
```

Event emmited when RFQ order was filled.

Parameters:

| Name         | Type    | Description       |
| ------------ | ------- | ----------------- |
| orderHash    | bytes32 | Hash of the order |
| takingAmount | uint256 | Taking amount     |
| makingAmount | uint256 | Making amount     |

#### OwnershipTransfered

//opis

Parameters:

| Name | Type    | Description |
| ---- | ------- | ----------- |
| from | address |             |
| to   | address |             |

#### SessionCreated

```solidity
event SessionCreated(
        address indexed creator,
        address indexed sessionKey,
        uint256 expirationTime
    );
```

Event emmited on successful session creation

Parameters:

<table><thead><tr><th width="190.33333333333331">Name</th><th width="217.34982770315122">Type</th><th>Description</th></tr></thead><tbody><tr><td>creator</td><td>address</td><td>Address of wallet creating the session</td></tr><tr><td>sessionKey</td><td>address</td><td>Public key of the session</td></tr><tr><td>expirationTime</td><td>uint256</td><td>Session expiration time in unix timestamp</td></tr></tbody></table>

#### SessionTerminated

```solidity
 event SessionTerminated(address indexed sender, address indexed sessionKey);
```

Event emmited on successful session termination

Parameters:

| Name       | Type    | Description                               |
| ---------- | ------- | ----------------------------------------- |
| sender     | address | Address of wallet terminating the session |
| sessionKey | address | Public key of the session                 |

#### SessionUpdated

```solidity
event SessionUpdated(
        address indexed sender,
        address indexed sessionKey,
        uint256 expirationTime
    );
```

Event emitted on successful session update

Parameters:

| Name           | Type    | Description                                          |
| -------------- | ------- | ---------------------------------------------------- |
| sender         | address | <p>Address of wallet updating </p><p>the session</p> |
| sessionKey     | address | Public key of the session                            |
| expirationTime | uint256 | Session expiration time in unix timestamp            |

#### SplitTokenTransfered

```solidity
event SplitTokenTransfered(
        address indexed from,
        address indexed recipient,
        address indexed splitTo,
        address token, // Due to limitations only three event's arguments can be indexed
        uint256 splitPercentage,
        uint256 amount,
        uint256 balance
    );
```

Event emitted on successful transfer of fee token - split between contract owner and frontend

Parameters:

| Name            | Type    | Description                                                   |
| --------------- | ------- | ------------------------------------------------------------- |
| from            | address | Address of wallet that transfers token                        |
| recipient       | address | Address of first recipient                                    |
| splitTo         | address | Address of second recipient                                   |
| token           | address | Address of deposited token                                    |
| splitPercentage | uint256 | Percentage used to split amount between recipient and splitTo |
| amount          | uint256 | Desposit amount                                               |
| balance         | uint256 | Balance after fee token transfer                              |

#### TokenDeposited

```solidity
event TokenDeposited(
        address indexed sender,
        address indexed token,
        uint256 amount,
        uint256 balance
    );
```

Event emitted on successful deposit of token

| Name    | Type    | Description                            |
| ------- | ------- | -------------------------------------- |
| sender  | address | Address of wallet depositing the token |
| token   | address | Address of the deposited token         |
| amount  | uint256 | Deposit amount                         |
| balance | uint256 | Balance after deposit                  |

#### TokenTransferred

```solidity
event TokenTransfered(
        address indexed from,
        address indexed recipient,
        address indexed token,
        uint256 amount,
        uint256 balance
    );
```

Event emitted on successful transfer of token

Parameters:

| Name      | Type    | Description                             |
| --------- | ------- | --------------------------------------- |
| from      | address | Address of wallet transfering the token |
| recipient | address | Address of the token recipient          |
| token     | address | Address of the transfered token         |
| amount    | uint256 | Transfer amount                         |
| balance   | uint256 | Balance after transfer                  |

#### TokenWithdrawn

```solidity
event TokenWithdrawn(
        address indexed sender,
        address indexed token,
        uint256 amount,
        uint256 balance
    );
```

Event emitted on successful withdrawn of token

Parameters:

| Name    | Type    | Description                             |
| ------- | ------- | --------------------------------------- |
| sender  | address | Address of wallet withdrawing the token |
| token   | address | Address of the withdrawn token          |
| amount  | uint256 | Withdraw amount                         |
| balance | uint256 | Balance after withdraw                  |

### Models

#### **Session**

```solidity
struct Session {
        address creator;
        address sessionKey;
        uint256 expirationTime;
        uint256 txCount;
    }
```

Properties:

| Name           | Type    | Description                                                           |
| -------------- | ------- | --------------------------------------------------------------------- |
| creator        | adress  | Wallet address of the session's owner                                 |
| sessionKey     | address | Session public key                                                    |
| expirationTime | uint256 | Session expiration unix timestamp, might be zero if it was terminated |
| txCount        | uint256 | Number of transactions made during session                            |

#### **OrderRFQ**

```solidity
struct OrderRFQ {
        uint256 info;
        uint256 feeAmount;
        address takerAsset;
        address makerAsset;
        address feeTokenAddress;
        address frontendAddress;
        bytes takerAssetData;
        bytes makerAssetData;
    }
```

Properties:

| Name            | Type    | Description |
| --------------- | ------- | ----------- |
| info            | uint256 |             |
| feeAmount       | uint256 |             |
| takerAsset      | address |             |
| makerAsset      | address |             |
| feeTokenAddress | address |             |
| frontendAddress | address |             |
| takerAssetData  | bytes   |             |
| makerAssetData  | bytes   |             |

#### **OrderRQFAmounts**

```solidity
struct OrderRFQCallbackInfo {
        address takerAsset;
        address makerAsset;
        uint256 takingAmount;
        uint256 makingAmount;
    }
```

Properties:

| Name         | Type    | Description |
| ------------ | ------- | ----------- |
| takerAsset   | address |             |
| makerAsset   | address |             |
| takingAmount | uint256 |             |
| makingAmount | uint256 |             |
