# KyberReserve

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

For the most updated information, please refer to:

* [**`Classic`**](https://docs.kyberswap.com/~/changes/1kQEhDNzHMDf7SwOE6Yu/liquidity-solutions/kyberswap-classic)
* [**`Elastic`**](https://docs.kyberswap.com/~/changes/1kQEhDNzHMDf7SwOE6Yu/liquidity-solutions/kyberswap-elastic)
* [**`Limit Order`**](https://docs.kyberswap.com/~/changes/1kQEhDNzHMDf7SwOE6Yu/kyberswap-solutions/limit-order)
* [**`Aggregator`**](https://docs.kyberswap.com/~/changes/1kQEhDNzHMDf7SwOE6Yu/kyberswap-solutions/kyberswap-aggregator)
  {% endhint %}

## contract KyberReserve

is [IKyberReserve](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-ikyberreserve.md), [Withdrawable](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-withdrawable.md), Utils\ imports ERC20Interface, Utils, [Withdrawable](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-withdrawable.md), [ConversionRatesInterface](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-conversionratesinterface.md), [SanityRatesInterface](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-sanityratesinterface.md), [IKyberReserve](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-ikyberreserve.md)

*Source*: [KyberReserve.sol](https://github.com/KyberNetwork/smart-contracts/blob/master/contracts/sol4/reserves/KyberReserve.sol)

The KyberReserve contract's role is to execute exchanges and provide rates for Kyber Network. The contract has no direct interaction with the end users (the only interaction with them is via the network platform). Its main interaction is with the reserve operator who manages the token inventory and feeds exchange rates every few minutes.

***

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

\<AUTOGENERATED\_TABLE\_OF\_CONTENTS>

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

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

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

Event for logging of ERC20 token deposits.

***

event **DepositToken**(ERC20 token, uint amount) | Parameter | Type | Description | | --------- |:-----:|:----------------------------:| | `token` | ERC20 | ERC20 token contract address | | `amount` | uint | ERC20 token amount in wei |

<br>

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

Event for logging new token wallet address

***

event **NewTokenWallet**(ERC20 token, address wallet) | Parameter | Type | Description | | --------- |:-----:|:-----------------------------------------------------------:| | `token` | ERC20 | ERC20 token contract address | | `wallet` | address | token wallet address |

<br>

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

Event for logging the setting of contract addresses.

***

event **SetContractAddresses**(address network, address rate, address sanity) | Parameter | Type | Description | | --------- |:-------:|:--------------------------------:| | `network` | address | KyberNetwork contract address | | `rate` | address | ConversionRates contract address | | `sanity` | address | SanityRates contract address |

<br>

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

Event for logging if trade is enabled for the reserve.

***

event **TradeEnabled**(bool enable) | Parameter | Type | Description | | --------- |:-----:|:-----------------------------------------------------------:| | `enable` | bool | `true` if reserve is enabled, otherwise `false` if disabled |

<br>

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

Event for logging of executed trades.

***

event **TradeExecute**(address indexed origin, address src, uint srcAmount, address destToken, uint destAmount, address destAddress) | Parameter | Type | Description | | --------------|:-------:|:----------------------------------------------:| | `origin` | address | sender's address | | `src` | address | source ERC20 token contract address | | `srcAmount` | uint | wei amount of source ERC20 tokens | | `destToken` | address | destination ERC20 token contract address | | `destAmount` | uint | wei amount of destination ERC20 tokens | | `destAddress` | address | recipient address for destination ERC20 tokens |

<br>

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

Event for logging of enabling or disabling of withdrawal address for token.

***

event **WithdrawAddressApproved**(ERC20 token, address addr, bool approve) | Parameter | Type | Description | | ----------|:-------:|:----------------------------------------------------------------------:| | `token` | ERC20 | ERC20 token contract address | | `addr` | address | withdrawal address | | `approve` | bool | `true` if address is enabled, otherwise `false` if address is disabled |

<br>

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

Event for logging of withdrawn funds when withdraw function is invoked.

***

event **WithdrawFunds**(ERC20 token, uint amount, address destination) | Parameter | Type | Description | | --------------|:-------:|:---------------------------------------:| | `token` | ERC20 | ERC20 token contract address | | `amount` | uint | wei amount of tokens that was withdrawn | | `destination` | address | recipient address of withdrawn funds |<br>

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

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

Contract constructor. Note that constructor methods are called exactly once during contract instantiation and cannot be called again.

***

function **KyberReserve**(address \_kyberNetwork, ConversionRatesInterface \_ratesContract, address \_admin) public | Parameter | Type | Description | | -----------------|:------------------------:|:--------------------------------:| | `_kyberNetwork` | address | KyberNetwork contract address | | `_ratesContract` | ConversionRatesInterface | ConversionRates contract address | | `_admin` | address | admin's wallet address |

<br>

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

Adds or deletes a reserve's withdrawal address to or from the network. Only admin can invoke.

***

function **approveWithdrawAddress**(ERC20 token, address addr, bool approve) public onlyAdmin | Parameter | Type | Description | | ----------|:-------:|:----------------------------------------------------------------------:| | `token` | ERC20 | ERC20 token contract address | | `addr` | address | withdrawal address | | `approve` | bool | `true` if address is enabled, otherwise `false` if address is disabled |

<br>

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

Disable trading for the reserve. Only alerter can invoke.

***

function **disableTrade**() public onlyAlerter returns (bool)\ **Returns:**\ `true` if trade is successfully disabled, otherwise `false`

<br>

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

Enables trading in the reserve. Only admin can invoke.

***

function **enableTrade**() public onlyAdmin returns (bool)\ **Returns:**\ `true` if trading is enabled, otherwise `false`<br>

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

Get the token balance of the reserve.

***

function **getBalance**(ERC20 token) public view returns (uint) | Parameter | Type | Description | | --------- |:-------:|:----------------------------:| | `token` | ERC20 | ERC20 token contract address | **Returns:**\ ERC20 token balance of the reserve in wei

<br>

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

Gets the conversion rate for a pair of tokens at block number.

***

function **getConversionRate**(ERC20 src, ERC20 dest, uint srcQty, uint blockNumber) public view returns (uint) | Parameter | Type | Description | | ------------- |:------:|:----------------------------------------:| | `src` | ERC20 | source ERC20 token contract address | | `dest` | ERC20 | destination ERC20 token contract address | | `srcQty` | uint | wei amount of source ERC20 token | | `blockNumber` | uint | current block height or block number | **Returns:**\ Current conversion rate of token pairs at block number

<br>

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

Get the calculated ERC20 token quantity in the destination wallet address.

***

function **getDestQty**(ERC20 src, ERC20 dest, uint srcQty, uint rate) public view returns (uint) | Parameter | Type | Description | | --------- |:-----:|:----------------------------------------:| | `src` | ERC20 | source ERC20 token contract address | | `dest` | ERC20 | destination ERC20 token contract address | | `srcQty` | uint | wei amount of source ERC20 token | | `rate` | uint | the conversion rate between src and dest | **Returns:**\ Calculated destination ERC20 token quantity in wei

<br>

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

Get the calculated ERC20 token quantity in the source wallet address.

***

function **getSrcQty**(ERC20 src, ERC20 dest, uint dstQty, uint rate) public view returns (uint) | Parameter | Type | Description | | --------- |:-----:|:----------------------------------------:| | `src` | ERC20 | source ERC20 token contract address | | `dest` | ERC20 | destination ERC20 token contract address | | `dstQty` | uint | wei amount of source ERC20 token | | `rate` | uint | the conversion rate between src and dest | **Returns:**\ Calculated source ERC20 token quantity in wei

<br>

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

Sets the contract addresses. Only admin can invoke.

***

function **setContracts**(address \_kyberNetwork, ConversionRatesInterface \_conversionRates, SanityRatesInterface \_sanity) public onlyAdmin | Parameter | Type | Description | | -------------------|:------------------------:|:----------------------------------------------:| | `_kyberNetwork` | address | KyberNetwork contract address | | `_conversionRates` | ConversionRatesInterface | ConversionRates contract address | | `_sanity` | SanityRatesInterface | SanityRates contract address | Modifiers: [onlyAdmin](https://docs.kyberswap.com/Legacy/api-abi/core-smart-contracts/api_abi-permissiongroups.md#onlyadmin)

<br>

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

Set the token wallet address to deposit / withdraw the specified token from / to. Only admin can invoke.

***

function **setTokenWallet**(ERC20 token, address wallet) public onlyAdmin | Parameter | Type | Description | | -------------------|:------------------------:|:----------------------------------------------:| | `token` | ERC20 | ERC20 token contract address | | `wallet` | address | wallet address |

<br>

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

Withdraw an ERC20 token from the reserve to the destination address. Only operator can invoke.

***

function **withdraw**(ERC20 token, uint amount, address destination) public onlyOperator returns (bool) | Parameter | Type | Description | | ------------- |:-------:|:----------------------------------------------:| | `token` | ERC20 | ERC20 token contract address | | `amount` | uint | ERC20 token amount in wei | | `destination` | address | recipient address for destination ERC20 tokens | **Returns:**\ `true` if the withdrawal was successful, otherwise `false` if unsuccessful
