> For the complete documentation index, see [llms.txt](https://docs.kyberswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kyberswap.com/reference/legacy/api-abi/core-smart-contracts/kybermatchingengine.md).

# KyberMatchingEngine

{% hint style="warning" %}
You are referring to the **`Legacy`** version of KyberSwap docs.

For the most updated information, please refer to:

* [**`Classic`**](https://github.com/KyberNetwork/kyberswap-documentation/blob/main/reference/legacy/api-abi/core-smart-contracts/broken-reference/README.md)
* [**`Elastic`**](/reference/legacy/kyberswap-elastic.md)
* [**`Limit Order`**](broken://pages/DCqb2Gq8yk2f2UIjmGEs)
* [**`Aggregator`**](broken://pages/P4AAjSd0nrbC42bSddka)
  {% endhint %}

## contract KyberMatchingEngine

is [KyberHintHandler](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kyberhinthandler.md), [IKyberMatchingEngine](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-ikybermatchingengine), WithdrawableNoModifiers\ imports WithdrawableNoModifiers, [IKyberMatchingEngine](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-ikybermatchingengine), [IKyberNetwork](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-ikybernetwork.md), [KyberHintHandler](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kyberhinthandler.md), [IKyberStorage](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-ikyberstorage.md)

*Source*: [KyberMatchingEngine.sol](https://github.com/KyberNetwork/smart-contracts/blob/master/contracts/sol6/KyberMatchingEngine.sol)

***

### INDEX[​](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kybermatchingengine#index) <a href="#index" id="index"></a>

\<AUTOGENERATED\_TABLE\_OF\_CONTENTS>

### REFERENCE[​](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kybermatchingengine#reference) <a href="#reference" id="reference"></a>

#### Events[​](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kybermatchingengine#events) <a href="#events" id="events"></a>

#### `KyberStorageUpdated`[​](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kybermatchingengine#kyberstorageupdated) <a href="#kyberstorageupdated" id="kyberstorageupdated"></a>

Event logging the setting of the new KyberStorage contract address.

***

event **KyberStorageUpdated**(IKyberStorage newKyberStorage) | Parameter | Type | Description | | --------- |:-----:|:-----------:| | `newKyberStorage` | IKyberStorage | new KyberStorage contract address | Signature: 0xed8c790db7ddf303f576c18e6644ec19e7b39356088eeeeac11c95212c61f49a

\\

#### `KyberNetworkUpdated`[​](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kybermatchingengine#kybernetworkupdated) <a href="#kybernetworkupdated" id="kybernetworkupdated"></a>

Event logging the setting of the new KyberNetwork contract address.

***

event **KyberNetworkUpdated**(IKyberNetwork newKyberNetwork) | Parameter | Type | Description | | --------- |:-----:|:-----------:| | `newKyberNetwork` | IKyberNetwork | new KyberNetwork contract address | Signature: 0x18970d46ac8a7d7e0da90e1bebb0be3e87ffc7705fc09d3bba5373d59b7a12aa

\\

#### Functions[​](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kybermatchingengine#functions) <a href="#functions" id="functions"></a>

#### `getTradingReserves`[​](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-kybermatchingengine#gettradingreserves) <a href="#gettradingreserves" id="gettradingreserves"></a>

Returns trading reserves info for a trade.

***

function **getTradingReserves**(IERC20 src, IERC20 dest, bool isTokenToToken, bytes hint) external view override returns (bytes32\[] reserveIds, uint256\[] splitValuesBps, ProcessWithRate processWithRate) | Parameter | Type | Description | | --------- |:-----:|:-----------:| | `src` | IERC20 | source token address | | `dest` | IERC20 | destination token address | | `isTokenToToken` | bool | whether the trade is token -> token | | `hint` | bytes | encoded hint for reserve routing | **Returns:**\ reserveIds - array of 32-byte reserve IDs for the trade splitValuesBps - array of split values in BPS for the trade respective to reserveIds processWithRate - whether extra processing is required or not

\
\### \`getNegligibleRateDiffBps\` Returns the negligible rate difference in BPS. \_\_\_ function \_\_getNegligibleRateDiffBps\_\_() external view override returns (uint256)\ \*\*Returns:\*\*\ The negligible rate difference in BPS.\
\### \`doMatch\` Returns the indexes of the best rate from the rates array for token -> eth or eth -> token trade. \_\_\_ function \_\_doMatch\_\_(IERC20 src, IERC20 dest, uint256\[] srcAmounts, uint256\[] feesAccountedDestBps, uint256\[] rates) external view override returns (uint256\[] reserveIndexes) | Parameter | Type | Description | | --------- |:-----:|:-----------:| | \`src\` | IERC20 | source token address | | \`dest\` | IERC20 | destination token address | | \`srcAmounts\` | uint256\[] | array of srcAmounts after deducting fees: | | \`feesAccountedDestBps\` | uint256\[] | fees charged in BPS, to be deducted from calculated destAmount | | \`rates\` | uint256\[] | array of rates queried from reserves | \*\*Returns:\*\*\ reserveIndexes - array of the indexes most suited for the trade


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.kyberswap.com/reference/legacy/api-abi/core-smart-contracts/kybermatchingengine.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
