# 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`**](https://docs.kyberswap.com/reference/legacy/kyberswap-elastic)
* [**`Limit Order`**](https://docs.kyberswap.com/kyberswap-solutions/limit-order)
* [**`Aggregator`**](https://docs.kyberswap.com/kyberswap-solutions/kyberswap-aggregator)
  {% 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
