Skip to content

Commit 23df8db

Browse files
manhlx3006ilanDoronAnyhowclickayobuenavista
authored
Merge master to development (#603)
* update git ignore (#544) * Kyber Bancor bridge reserve (#546) * Shifted arbitrage check to FeeBurner * Shifted relevant tests from expectedRate to feeBurner * Modified failing test, as it requires less gas to fail * Removed redundan >0 rate check, test for feeBurner * Added test for src==dest token * Istanbul fix, zero rate handling * Arbitrage check shifted to FeeBurner (#433) * Shifted arbitrage check to FeeBurner * Shifted relevant tests from expectedRate to feeBurner * Modified failing test, as it requires less gas to fail * Removed redundan >0 rate check, test for feeBurner * Added test for src==dest token * Revert "Merge branch 'clicky/zero_rate' into development" This reverts commit 795d2f1, reversing changes made to 80af391. * Clicky/buidl integration (#459) * Pulling stuff from KN/clicky/buidl-integration branch * Pull changes from expected rate and fee burner * Update kyberNetwork test file * Update kyberNetwork.js * Merge Mike's PR on enhanced step functions (#458) * [WIP] Add new conversion rate contract with step function enhancement (#416) * [WIP] Add new conversion rate contract with step function enhancement * Add more tests to kyberReserve for testing new conversion rate contract * Add more tests for kybetNetwork with new conversion rate contract * Add verify qty and imbalance step function amounts must be increasing * Add case set qty and balance step func with only one or zero element * Check for qty step function all amounts are non negative * Update conversion rate contract and kyber network tests * Fallback to old logics when qty is 0 * Update new conversion rate with inherite from old one, update logics for some edge cases and tests * Fixed typo * Add check for empty step function before executing step function * Fix issue when qty is negative and greater than all step qty * Fix issue with executing step func with 0 as qty (#417) * Remove unnecessary tests in conversionRate2, add more cases to test for new execute step function * Fix issue with execute step func for 0 qty * expose getImbalance function in conversionRate2.sol file (#419) * Update conversion rate contract 2 with new logics for executing step function * Resolve some comments, change name new conversion rates contract to EnhancedStepFunctions * Remove qty step function, compress data for imbalance steps * Resolve solhint max line length * Avoid modifying function params in execute step func * Update comments for each test case of getting correct bps for step func * Update with some comments, add more tests * Add await keyword * Update some comments, fix some old tests in kyber reserve * Fix wrong calculate imbalance of token in reserve test * Change default max imbalance to return when overflow, fix some tests with missing await keyword * Blocking setting qty step function in new conversion rate * Update execute step func with blocking rate, remove updatedRateBlock in getImbalance * Remove redundant stepX value in last step * Add check data when encoding step func, using MAX_VAL as default for last step X * Add checking for max value of step X and tests * Add check for max bps adjustment, check max_imbalance value test * Fixed Failing Tests (#462) * Istanbul fix * Fixed failing tests as per Ilan's feedback * Fixed failing tests * Minor fixes * Minor fixes * Sync enhanced step functions test file * Reduce getDecimals call in findBestRateTokenToToken in network contract (#467) * Reduce getDecimals call in findBestRateTokenToToken in network contract * Fix new line end file * Remove some tests in utils3 * Avoid decimals call when calling handleFees on FeeBurner (#468) * Ilan/merge master (#460) * reserve deployment scripts (#233) * reserve deployment scripts * read valid block duration from config file. (#423) * Weth Reserve Implementation (#304) * Weth Reserve Implementation Includes testing. Also includes an addition in helper to make throw catching more neat. * Add weth reserve test * Add deploy script for oasis reserve * Organize folder structure and update WrapConversionRate.sol #441 && #452 (#453) * Organize folder structure according to issue #441 this includes organizing audit folder and organizing reserves. Remove multisig support from WrapConversionRate.sol according to issue #452 * enable admin to call transfer admin of base contract * enable wrapConversionRate to control all adminOnly functions in conversionRate (#461) * Ilan/modify wrap conversion rate (#466) * enable wrapConversionRate to control all adminOnly functions in conversionRate * enable wrap conversion rate to control all admin functions in conversion rate contract * set admin as msg.sender. to follow base contract logic * remove redundant test. adopt to chainge in admin logic * add CR LF * rename folders. (#469) * rename folders. (remove contract from folder name.) * reset package - lock * move new mock contracts to mock folder. * create web3 object * Upgraded to ganache-cli@istanbul * Removed header * Istanbul fix (#457) * Return zero rate for same src and dest token (#475) * Return zero rate for same src & dest token * Removed unnecessary tests * Echo fork choice, fix broken logic * Try committing new package-lock.json * Added more info * Bumped to node v12.13.0 * Update package fix npm (#474) * Update package fix npm * Update package-lock file * Remove unused packages * Removed eslint * Add colour for better readability of fork choice * Add spacing between example commands * Resolve package-lock conflict * Revert "Bumped to node v12.13.0" This reverts commit 85cb734. * Fixed conflicting files * Revert "Merge branch 'clicky/ganacheIstanbul' into development" This reverts commit 654a1c3, reversing changes made to 6c0a21c. * Upgrade to ganache-cli@istanbul for testing with Istanbul fork (#482) * Added colour and newline to fork choice * Add node and npm version used * Removed eslint * Removed eslint * Got latest changes from Mike's PR * added colour and newline to fork choice * Fix coloring (I hope) * Changed BG to make text stand out * handle zero qty in get rate permission less reserve (#472) * handle zero qty in get rate permission less reserve * undo wrong change * Increase gas limit for 1 test due to Istanbul (#487) * [455] Enable unlist orderbook permissionless reserve (#485) * Add comments in FeeBurner for KNC decimals (#489) * Revert "Arbitrage check shifted to FeeBurner" (#488) * Revert "Arbitrage check shifted to FeeBurner (#433)" This reverts commit 80af391. * reverse un needed test changes for kyber NEtwork * Zero Src Qty Handling (#483) * Initial commit for zero rate handling. Need to rewrite tests * Improved comment to code * Modified getConversionRate function to require srcAmt > 0 * Removed tests, added one * Updated contracts as per feedback * Updated comment in test file * Added fix to expectedRateSmallQty * Remove extra = * Add additional section to check network.getExpectedRate doesn't revert as well * Removed redundant tests due to zero rate handling in network contract (#494) * update solidity coverage version (#491) * Added new deployment script and input files (#495) * Ilan/add rates getter (#493) * update solidity coverage version * add getter function for rates * update getter API and return values, add tests * Clicky/rename compile file (#496) * renamed compileOutput.js to compileContracts.js, added more contracts for reserveDeployer * Renamed compileOutput -> compileContracts * Minor spelling edit * update addresses for deployment (#497) * remove multi sig support. add admin functionality (#498) * remove multi sig support. add admin functionality * refactor wrapper contracts, update tests * update tests according to PR comments, add one missing check * Add some comments * Revert "[455] Enable unlist orderbook permissionless reserve (#485)" (#504) This reverts commit 8b63c0e. * Fix deployment script after staging deployment (#505) * Added new deployment script and input files * Remove old file * Added contract instantiation if deployer script breaks halfway through * avoid query to uniswap with zero rate (#510) * avoid query to uniswap with zero rate * test situation where trade result is 0 * enable setting min record resultion in conversion rates using wrapper (#513) * enable setting min record resultion in conversion rates using wrapper * linting, and add missing test * fix uniswap bridge for small amounts src qty (1) (#518) * fix uniswap bridge for smal amounts src qty (1) * avoid reading fee twice * fix uniswap deployer script * Ilan/deployment helper (#516) * some deployment changes, and helper contract" " * add kyber uniswap bridge to compilation. remove wrap conversion rate * small fixes in deployer * Add CR LF * Ilan/merge master (#519) * update some packages. fix solc version to 0.4.18 (#503) * fixed FPR deployment script (#508) * add smartdec audit for APR * use correct package-lock * Ilan/master to development (#525) * Development to Master. Istanbul changes. buidl. (#471) * Shifted arbitrage check to FeeBurner * Shifted relevant tests from expectedRate to feeBurner * Modified failing test, as it requires less gas to fail * Removed redundan >0 rate check, test for feeBurner * Added test for src==dest token * Istanbul fix, zero rate handling * Arbitrage check shifted to FeeBurner (#433) * Shifted arbitrage check to FeeBurner * Shifted relevant tests from expectedRate to feeBurner * Modified failing test, as it requires less gas to fail * Removed redundan >0 rate check, test for feeBurner * Added test for src==dest token * Revert "Merge branch 'clicky/zero_rate' into development" This reverts commit 795d2f1, reversing changes made to 80af391. * Clicky/buidl integration (#459) * Pulling stuff from KN/clicky/buidl-integration branch * Pull changes from expected rate and fee burner * Update kyberNetwork test file * Update kyberNetwork.js * Merge Mike's PR on enhanced step functions (#458) * [WIP] Add new conversion rate contract with step function enhancement (#416) * [WIP] Add new conversion rate contract with step function enhancement * Add more tests to kyberReserve for testing new conversion rate contract * Add more tests for kybetNetwork with new conversion rate contract * Add verify qty and imbalance step function amounts must be increasing * Add case set qty and balance step func with only one or zero element * Check for qty step function all amounts are non negative * Update conversion rate contract and kyber network tests * Fallback to old logics when qty is 0 * Update new conversion rate with inherite from old one, update logics for some edge cases and tests * Fixed typo * Add check for empty step function before executing step function * Fix issue when qty is negative and greater than all step qty * Fix issue with executing step func with 0 as qty (#417) * Remove unnecessary tests in conversionRate2, add more cases to test for new execute step function * Fix issue with execute step func for 0 qty * expose getImbalance function in conversionRate2.sol file (#419) * Update conversion rate contract 2 with new logics for executing step function * Resolve some comments, change name new conversion rates contract to EnhancedStepFunctions * Remove qty step function, compress data for imbalance steps * Resolve solhint max line length * Avoid modifying function params in execute step func * Update comments for each test case of getting correct bps for step func * Update with some comments, add more tests * Add await keyword * Update some comments, fix some old tests in kyber reserve * Fix wrong calculate imbalance of token in reserve test * Change default max imbalance to return when overflow, fix some tests with missing await keyword * Blocking setting qty step function in new conversion rate * Update execute step func with blocking rate, remove updatedRateBlock in getImbalance * Remove redundant stepX value in last step * Add check data when encoding step func, using MAX_VAL as default for last step X * Add checking for max value of step X and tests * Add check for max bps adjustment, check max_imbalance value test * Fixed Failing Tests (#462) * Istanbul fix * Fixed failing tests as per Ilan's feedback * Fixed failing tests * Minor fixes * Minor fixes * Sync enhanced step functions test file * Reduce getDecimals call in findBestRateTokenToToken in network contract (#467) * Reduce getDecimals call in findBestRateTokenToToken in network contract * Fix new line end file * Remove some tests in utils3 * Avoid decimals call when calling handleFees on FeeBurner (#468) * Ilan/merge master (#460) * reserve deployment scripts (#233) * reserve deployment scripts * read valid block duration from config file. (#423) * Weth Reserve Implementation (#304) * Weth Reserve Implementation Includes testing. Also includes an addition in helper to make throw catching more neat. * Add weth reserve test * Add deploy script for oasis reserve * Organize folder structure and update WrapConversionRate.sol #441 && #452 (#453) * Organize folder structure according to issue #441 this includes organizing audit folder and organizing reserves. Remove multisig support from WrapConversionRate.sol according to issue #452 * enable admin to call transfer admin of base contract * enable wrapConversionRate to control all adminOnly functions in conversionRate (#461) * Ilan/modify wrap conversion rate (#466) * enable wrapConversionRate to control all adminOnly functions in conversionRate * enable wrap conversion rate to control all admin functions in conversion rate contract * set admin as msg.sender. to follow base contract logic * remove redundant test. adopt to chainge in admin logic * add CR LF * rename folders. (#469) * rename folders. (remove contract from folder name.) * reset package - lock * move new mock contracts to mock folder. * create web3 object * Upgraded to ganache-cli@istanbul * Removed header * Istanbul fix (#457) * Return zero rate for same src and dest token (#475) * Return zero rate for same src & dest token * Removed unnecessary tests * Echo fork choice, fix broken logic * Try committing new package-lock.json * Added more info * Bumped to node v12.13.0 * Update package fix npm (#474) * Update package fix npm * Update package-lock file * Remove unused packages * Removed eslint * Add colour for better readability of fork choice * Add spacing between example commands * Resolve package-lock conflict * Revert "Bumped to node v12.13.0" This reverts commit 85cb734. * Fixed conflicting files * Revert "Merge branch 'clicky/ganacheIstanbul' into development" This reverts commit 654a1c3, reversing changes made to 6c0a21c. * Upgrade to ganache-cli@istanbul for testing with Istanbul fork (#482) * Added colour and newline to fork choice * Add node and npm version used * Removed eslint * Removed eslint * Got latest changes from Mike's PR * added colour and newline to fork choice * Fix coloring (I hope) * Changed BG to make text stand out * handle zero qty in get rate permission less reserve (#472) * handle zero qty in get rate permission less reserve * undo wrong change * Increase gas limit for 1 test due to Istanbul (#487) * [455] Enable unlist orderbook permissionless reserve (#485) * Add comments in FeeBurner for KNC decimals (#489) * Revert "Arbitrage check shifted to FeeBurner" (#488) * Revert "Arbitrage check shifted to FeeBurner (#433)" This reverts commit 80af391. * reverse un needed test changes for kyber NEtwork * Zero Src Qty Handling (#483) * Initial commit for zero rate handling. Need to rewrite tests * Improved comment to code * Modified getConversionRate function to require srcAmt > 0 * Removed tests, added one * Updated contracts as per feedback * Updated comment in test file * Added fix to expectedRateSmallQty * Remove extra = * Add additional section to check network.getExpectedRate doesn't revert as well * Removed redundant tests due to zero rate handling in network contract (#494) * update solidity coverage version (#491) * Added new deployment script and input files (#495) * Ilan/add rates getter (#493) * update solidity coverage version * add getter function for rates * update getter API and return values, add tests * Clicky/rename compile file (#496) * renamed compileOutput.js to compileContracts.js, added more contracts for reserveDeployer * Renamed compileOutput -> compileContracts * Minor spelling edit * update addresses for deployment (#497) * remove multi sig support. add admin functionality (#498) * remove multi sig support. add admin functionality * refactor wrapper contracts, update tests * update tests according to PR comments, add one missing check * Add some comments * Revert "[455] Enable unlist orderbook permissionless reserve (#485)" (#504) This reverts commit 8b63c0e. * Fix deployment script after staging deployment (#505) * Added new deployment script and input files * Remove old file * Added contract instantiation if deployer script breaks halfway through * avoid query to uniswap with zero rate (#510) * avoid query to uniswap with zero rate * test situation where trade result is 0 * enable setting min record resultion in conversion rates using wrapper (#513) * enable setting min record resultion in conversion rates using wrapper * linting, and add missing test * fix uniswap bridge for small amounts src qty (1) (#518) * fix uniswap bridge for smal amounts src qty (1) * avoid reading fee twice * fix uniswap deployer script * Ilan/deployment helper (#516) * some deployment changes, and helper contract" " * add kyber uniswap bridge to compilation. remove wrap conversion rate * small fixes in deployer * Add CR LF * Ilan/merge master (#519) * update some packages. fix solc version to 0.4.18 (#503) * fixed FPR deployment script (#508) * add smartdec audit for APR * use correct package-lock * Add Eth2Dai reserve and test (#523) * [WIP] Eth2Dai Reserve enhancement (#449) * Add eth2dai contract * Update Eth2Dai reserve * Update Eth2DaiReserve contract and tests * Update trade function tests for eth2dai reserve * Make single test can run on its own * Separate source codes, add some v5 contracts * Update contracts fixed some review comments, remove some unused functions * Update eth2dai contract with enable/disable internal inventory for token * Add test for set internal inventory enable/disable * Put enable/disable internal inventory into internal inventory data * Add internal inventory tests * Change overlow to out of range * Update v5 contracts * Update file name and folder structure * Update folder structure * Fix can not find artifacts for WethTokenV5 * Update test folder structure * Remove KyberOasisReserve source code + test, change WethTokenV5 to WethToken (#524) * remove duplicate files and v5 example * Add KyberBancorReserve and test * Fix some tests for kyber bancor reserve * Add more tests for kyber bancor reserve * Remove default value for bnt and bancor eth token * Add end of file line * Update contracts from review comments * Fix contract and test based on comments * Return 0 for rate and revert in trade when srcQty is 0 * Remove v5 example test file' Co-authored-by: Desmond <[email protected]> Co-authored-by: Ilan Doron <[email protected]> * Update bancor bridge with new fixed path (#548) * Quick fixes to liquidityReserveDeployer.js script for deployment of APR (#556) * update web3 helpers (#560) * fix web3 contract compilation * add helper to read conversion rate set data * enable more user friendly usage * add script to deploy enhanced step functions contract. * update SetStepFunctionWrapper.sol add it to compileContracts.js * indent fix deploy * update according to review comments * fix function signature for setImbalanceStepFunction (#576) * fix function signature for setImbalanceStepFunction * rename enhanced steps to ConversionRateEnhancedSteps * rename enhanced steps * review changes * fix contract name, require correct addresses on ctor (#585) * Update conversion rate enhanced steps, and bancor bridge test Co-authored-by: Ilan Doron <[email protected]> Co-authored-by: Desmond <[email protected]> Co-authored-by: Anton Buenavista <[email protected]>
1 parent 743dd5e commit 23df8db

File tree

11 files changed

+862
-56
lines changed

11 files changed

+862
-56
lines changed

contracts/mock/MockEnhancedStepFunctions.sol renamed to contracts/mock/MockConversionRateEnhancedSteps.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
pragma solidity ^0.4.18;
22

3-
import "../reserves/fprConversionRate/EnhancedStepFunctions.sol";
3+
import "../reserves/fprConversionRate/ConversionRateEnhancedSteps.sol";
44

55

6-
contract MockEnhancedStepFunctions is EnhancedStepFunctions {
6+
contract MockConversionRateEnhancedSteps is ConversionRateEnhancedSteps {
77

8-
function MockEnhancedStepFunctions(address admin) EnhancedStepFunctions(admin) public {
8+
function MockConversionRateEnhancedSteps(address admin) ConversionRateEnhancedSteps(admin) public {
99

1010
}
1111

contracts/reserves/fprConversionRate/EnhancedStepFunctions.sol renamed to contracts/reserves/fprConversionRate/ConversionRateEnhancedSteps.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ pragma solidity 0.4.18;
22

33
import "./ConversionRates.sol";
44

5-
/// @title EnhancedStepFunctions contract - new ConversionRates contract with step function enhancement
5+
/// @title ConversionRateEnhancedSteps contract - new ConversionRates contract with step function enhancement
66
/// Removed qty step function overhead
77
/// Also fixed following issues:
88
/// https://github.com/KyberNetwork/smart-contracts/issues/291
99
/// https://github.com/KyberNetwork/smart-contracts/issues/241
1010
/// https://github.com/KyberNetwork/smart-contracts/issues/240
1111

1212

13-
contract EnhancedStepFunctions is ConversionRates {
13+
contract ConversionRateEnhancedSteps is ConversionRates {
1414

1515
uint constant internal MAX_STEPS_IN_FUNCTION = 16;
1616
int constant internal MAX_IMBALANCE = 2 ** 255 - 1;
@@ -19,7 +19,7 @@ contract EnhancedStepFunctions is ConversionRates {
1919
int128 constant internal MIN_STEP_VALUE = -1 * 2 ** 127;
2020
int constant internal MAX_BPS_ADJUSTMENT = 100 * 100;
2121

22-
function EnhancedStepFunctions(address _admin) public ConversionRates(_admin)
22+
function ConversionRateEnhancedSteps(address _admin) public ConversionRates(_admin)
2323
{ } // solhint-disable-line no-empty-blocks
2424

2525
// Blocking set qty step func as we won't use
@@ -171,8 +171,8 @@ contract EnhancedStepFunctions is ConversionRates {
171171

172172
// add imbalance overhead
173173
extraBps = executeStepFunction(
174-
tokenData[token].buyRateImbalanceStepFunction,
175-
totalImbalance,
174+
tokenData[token].buyRateImbalanceStepFunction,
175+
totalImbalance,
176176
totalImbalance + imbalanceQty
177177
);
178178
rate = addBps(rate, extraBps);
@@ -191,8 +191,8 @@ contract EnhancedStepFunctions is ConversionRates {
191191

192192
// add imbalance overhead
193193
extraBps = executeStepFunction(
194-
tokenData[token].sellRateImbalanceStepFunction,
195-
totalImbalance + imbalanceQty,
194+
tokenData[token].sellRateImbalanceStepFunction,
195+
totalImbalance + imbalanceQty,
196196
totalImbalance
197197
);
198198
rate = addBps(rate, extraBps);

contracts/wrappers/SetStepFunctionWrapper.sol

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ pragma solidity ^0.4.18;
33
import "../ERC20Interface.sol";
44
import "../Withdrawable.sol";
55

6+
67
interface SetStepFunctionInterface {
7-
function setImbalanceStepFunction(
8-
ERC20 token,
9-
int[] xBuy,
10-
int[] yBuy,
11-
int[] xSell,
12-
int[] ySell
13-
) public;
8+
function setImbalanceStepFunction(
9+
ERC20 token,
10+
int[] xBuy,
11+
int[] yBuy,
12+
int[] xSell,
13+
int[] ySell
14+
) public;
1415
}
1516

1617
contract SetStepFunctionWrapper is Withdrawable {
1718
SetStepFunctionInterface public rateContract;
1819
function SetStepFunctionWrapper(address admin, address operator) public {
20+
require(admin != address(0));
21+
require(operator != (address(0)));
22+
1923
addOperator(operator);
2024
transferAdminQuickly(admin);
2125
}
@@ -24,23 +28,34 @@ contract SetStepFunctionWrapper is Withdrawable {
2428
rateContract = _contract;
2529
}
2630

27-
function setImbalanceStepFunction(ERC20 token,
28-
int[] xBuy,
29-
int[] yBuy,
30-
int[] xSell,
31-
int[] ySell) public onlyOperator {
31+
function setImbalanceStepFunction(
32+
ERC20 token,
33+
int[] xBuy,
34+
int[] yBuy,
35+
int[] xSell,
36+
int[] ySell)
37+
public onlyOperator
38+
{
3239
uint i;
3340

34-
// check all x for buy are positive and y are negative
41+
// check all x for buy are positive
3542
for( i = 0 ; i < xBuy.length ; i++ ) {
36-
require(xBuy[i] >= 0 );
37-
require(yBuy[i] <= 0 );
43+
require(xBuy[i] >= 0 );
44+
}
45+
46+
// check all y for buy are negative
47+
for( i = 0 ; i < yBuy.length ; i++ ) {
48+
require(yBuy[i] <= 0 );
3849
}
3950

40-
// check all x for sell are negative and y are negative
51+
// check all x for sell are negative
4152
for( i = 0 ; i < xSell.length ; i++ ) {
42-
require(xSell[i] <= 0 );
43-
require(ySell[i] <= 0 );
53+
require(xSell[i] <= 0 );
54+
}
55+
56+
// check all y for sell are negative
57+
for( i = 0 ; i < ySell.length ; i++ ) {
58+
require(ySell[i] <= 0 );
4459
}
4560

4661
rateContract.setImbalanceStepFunction(token,xBuy,yBuy,xSell,ySell);

contractsV5/bridges/bancor/KyberBancorReserve.sol

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ contract KyberBancorReserve is IKyberReserve, Withdrawable, Utils {
1818
IBancorNetwork public bancorNetwork; // 0x0e936B11c2e7b601055e58c7E32417187aF4de4a
1919

2020
IERC20 public bancorEth; // 0xc0829421C1d260BD3cB3E0F06cfE2D52db2cE315
21+
IERC20 public bancorETHBNT; // 0xb1CD6e4153B2a390Cf00A6556b0fC1458C4A5533
2122
IERC20 public bancorToken; // 0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C
2223

2324
constructor(
2425
address _bancorNetwork,
2526
address _kyberNetwork,
2627
uint _feeBps,
2728
address _bancorEth,
29+
address _bancorETHBNT,
2830
address _bancorToken,
2931
address _admin
3032
)
@@ -33,13 +35,15 @@ contract KyberBancorReserve is IKyberReserve, Withdrawable, Utils {
3335
require(_bancorNetwork != address(0), "constructor: bancorNetwork address is missing");
3436
require(_kyberNetwork != address(0), "constructor: kyberNetwork address is missing");
3537
require(_bancorEth != address(0), "constructor: bancorEth address is missing");
38+
require(_bancorETHBNT != address(0), "constructor: bancorETHBNT address is missing");
3639
require(_bancorToken != address(0), "constructor: bancorToken address is missing");
3740
require(_admin != address(0), "constructor: admin address is missing");
3841
require(_feeBps < BPS, "constructor: fee is too big");
3942

4043
bancorNetwork = IBancorNetwork(_bancorNetwork);
4144
bancorToken = IERC20(_bancorToken);
4245
bancorEth = IERC20(_bancorEth);
46+
bancorETHBNT = IERC20(_bancorETHBNT);
4347

4448
kyberNetwork = _kyberNetwork;
4549
feeBps = _feeBps;
@@ -208,21 +212,19 @@ contract KyberBancorReserve is IKyberReserve, Withdrawable, Utils {
208212
}
209213

210214
function getConversionPath(IERC20 src, IERC20 dest) public view returns(IERC20[] memory path) {
211-
IERC20 bntToken = bancorToken;
212-
213-
if (src == bntToken) {
215+
if (src == bancorToken) {
214216
// trade from BNT to ETH
215217
path = new IERC20[](3);
216-
path[0] = bntToken;
217-
path[1] = bntToken;
218+
path[0] = bancorToken;
219+
path[1] = bancorETHBNT;
218220
path[2] = bancorEth;
219221
return path;
220-
} else if (dest == bntToken) {
222+
} else if (dest == bancorToken) {
221223
// trade from ETH to BNT
222224
path = new IERC20[](3);
223225
path[0] = bancorEth;
224-
path[1] = bntToken;
225-
path[2] = bntToken;
226+
path[1] = bancorETHBNT;
227+
path[2] = bancorToken;
226228
return path;
227229
}
228230
}

contractsV5/bridges/bancor/mock/MockBancorNetwork.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import "../../../UtilsV5.sol";
77
contract MockBancorNetwork is IBancorNetwork, Utils {
88

99
IERC20 public bancorETH;
10+
IERC20 public bancorETHBNT;
1011
IERC20 public bancorBNT;
1112

1213
uint public rateEthToBnt;
1314
uint public rateBntToETh;
1415

15-
constructor(address _bancorETH, address _bancorBNT) public {
16+
constructor(address _bancorETH, address _bancorETHBNT, address _bancorBNT) public {
1617
bancorETH = IERC20(_bancorETH);
1718
bancorBNT = IERC20(_bancorBNT);
19+
bancorETHBNT = IERC20(_bancorETHBNT);
1820
}
1921

2022
function() external payable { }
@@ -27,15 +29,15 @@ contract MockBancorNetwork is IBancorNetwork, Utils {
2729
function getReturnByPath(IERC20[] calldata _path, uint256 _amount) external view returns (uint256, uint256) {
2830
require(_amount > 0);
2931
if (_path.length != 3) { return (0, 0); }
30-
if (_path[0] == bancorBNT && _path[1] == bancorBNT && _path[2] == bancorETH) {
32+
if (_path[0] == bancorBNT && _path[1] == bancorETHBNT && _path[2] == bancorETH) {
3133
// rate btn to eth
3234
uint destAmount = calcDstQty(_amount, getDecimals(bancorBNT), ETH_DECIMALS, rateBntToETh);
3335
if (destAmount > address(this).balance) {
3436
return (0, 0);
3537
}
3638
return (destAmount, 0);
3739
}
38-
if (_path[0] == bancorETH && _path[1] == bancorBNT && _path[2] == bancorBNT) {
40+
if (_path[0] == bancorETH && _path[1] == bancorETHBNT && _path[2] == bancorBNT) {
3941
// rate eth to bnt
4042
uint destAmount = calcDstQty(_amount, ETH_DECIMALS, getDecimals(bancorBNT), rateEthToBnt);
4143
if (destAmount > bancorBNT.balanceOf(address(this))) {
@@ -55,7 +57,7 @@ contract MockBancorNetwork is IBancorNetwork, Utils {
5557
) external payable returns (uint256) {
5658
require(_path.length == 3);
5759
// trade eth to bnt
58-
require(_path[0] == bancorETH && _path[1] == bancorBNT && _path[2] == bancorBNT);
60+
require(_path[0] == bancorETH && _path[1] == bancorETHBNT && _path[2] == bancorBNT);
5961
require(msg.value == _amount && _amount > 0);
6062
require(rateEthToBnt > 0);
6163
uint destAmount = calcDstQty(_amount, ETH_DECIMALS, getDecimals(bancorBNT), rateEthToBnt);
@@ -74,7 +76,7 @@ contract MockBancorNetwork is IBancorNetwork, Utils {
7476
) external returns (uint256) {
7577
require(_path.length == 3);
7678
// trade eth to bnt
77-
require(_path[0] == bancorBNT && _path[1] == bancorBNT && _path[2] == bancorETH);
79+
require(_path[0] == bancorBNT && _path[1] == bancorETHBNT && _path[2] == bancorETH);
7880
// collect bnt
7981
require(_amount > 0);
8082
require(bancorBNT.transferFrom(msg.sender, address(this), _amount));

test/v4/enhancedStepFunctions.js renamed to test/v4/conversionRateEnhancedSteps.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

2-
//let ConversionRates = artifacts.require("./ConversionRates.sol");
3-
let MockEnhancedStepFunctions = artifacts.require("./mockContracts/MockEnhancedStepFunctions.sol");
2+
let MockConversionRateEnhancedSteps = artifacts.require("./mockContracts/MockConversionRateEnhancedSteps.sol");
43
let TestToken = artifacts.require("./mockContracts/TestToken.sol");
5-
let Wrapper = artifacts.require("./mockContracts/Wrapper.sol");
64

75
let Helper = require("./helper.js");
86
const BN = web3.utils.BN;
@@ -50,17 +48,17 @@ let comID_SellRateStpImbalanceParamY = 15;
5048

5149
let convRatesInst;
5250

53-
contract('EnhancedStepFunctions', function(accounts) {
51+
contract('ConversionRateEnhancedSteps', function(accounts) {
5452
it("should init globals", function() {
5553
admin = accounts[0];
5654
alerter = accounts[1];
5755
operator = accounts[2];
5856
reserveAddress = accounts[3];
5957
})
6058

61-
it("should init EnhancedStepFunctions Inst and set general parameters.", async function () {
59+
it("should init ConversionRateEnhancedSteps Inst and set general parameters.", async function () {
6260
//init contracts
63-
convRatesInst = await MockEnhancedStepFunctions.new(admin);
61+
convRatesInst = await MockConversionRateEnhancedSteps.new(admin);
6462

6563
//set pricing general parameters
6664
convRatesInst.setValidRateDurationInBlocks(validRateDurationInBlocks);

test/v5/kyberBancorReserve.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ contract('KyberBancorNetwork', function(accounts) {
4242
user = accounts[4];
4343

4444
bancorEthToken = await TestToken.new("BancorETH", "BETH", tokenDecimal);
45+
bancorETHBNTToken = await TestToken.new("BancorETHBNT", "BETHBNT", tokenDecimal);
4546
bancorBntToken = await TestToken.new("BancorBNT", "BBNT", tokenDecimal);
46-
bancorNetwork = await MockBancorNetwork.new(bancorEthToken.address, bancorBntToken.address);
47+
bancorNetwork = await MockBancorNetwork.new(bancorEthToken.address, bancorETHBNTToken.address, bancorBntToken.address);
4748
reserve = await KyberBancorReserve.new(
4849
bancorNetwork.address,
4950
network,
5051
feeBps,
5152
bancorEthToken.address,
53+
bancorETHBNTToken.address,
5254
bancorBntToken.address,
5355
admin
5456
);
@@ -142,12 +144,13 @@ contract('KyberBancorNetwork', function(accounts) {
142144

143145
it("Should test getConversionRate returns 0 when path is not correct", async function() {
144146
let testNewToken = await TestToken.new("Test token", "TST", tokenDecimal);
145-
let testBancorNetwork = await MockBancorNetwork.new(testNewToken.address, bancorBntToken.address);
147+
let testBancorNetwork = await MockBancorNetwork.new(testNewToken.address, bancorETHBNTToken.address, bancorBntToken.address);
146148
let testReserve = await KyberBancorReserve.new(
147149
testBancorNetwork.address,
148150
network,
149151
feeBps,
150152
bancorEthToken.address,
153+
bancorETHBNTToken.address,
151154
bancorBntToken.address,
152155
admin
153156
);
@@ -160,12 +163,13 @@ contract('KyberBancorNetwork', function(accounts) {
160163
rate = await testReserve.getConversionRate(bancorBntToken.address, ethAddress, amount, 0);
161164
Helper.assertEqual(rate, 0, "rate should be 0 as path is incorrect");
162165

163-
testBancorNetwork = await MockBancorNetwork.new(bancorEthToken.address, testNewToken.address);
166+
testBancorNetwork = await MockBancorNetwork.new(bancorEthToken.address, bancorETHBNTToken.address, testNewToken.address);
164167
testReserve = await KyberBancorReserve.new(
165168
testBancorNetwork.address,
166169
network,
167170
feeBps,
168171
bancorEthToken.address,
172+
bancorETHBNTToken.address,
169173
bancorBntToken.address,
170174
admin
171175
);
@@ -187,6 +191,7 @@ contract('KyberBancorNetwork', function(accounts) {
187191
network,
188192
feeBps,
189193
bancorEthToken.address,
194+
bancorETHBNTToken.address,
190195
bancorBntToken.address,
191196
admin
192197
);
@@ -200,6 +205,7 @@ contract('KyberBancorNetwork', function(accounts) {
200205
zeroAddress,
201206
feeBps,
202207
bancorEthToken.address,
208+
bancorETHBNTToken.address,
203209
bancorBntToken.address,
204210
admin
205211
);
@@ -213,6 +219,7 @@ contract('KyberBancorNetwork', function(accounts) {
213219
network,
214220
feeBps,
215221
zeroAddress,
222+
bancorETHBNTToken.address,
216223
bancorBntToken.address,
217224
admin
218225
);
@@ -227,6 +234,21 @@ contract('KyberBancorNetwork', function(accounts) {
227234
feeBps,
228235
bancorEthToken.address,
229236
zeroAddress,
237+
bancorBntToken.address,
238+
admin
239+
);
240+
assert(false, "throw was expected in line above.")
241+
} catch (e) {
242+
assert(Helper.isRevertErrorMessage(e), "expected throw but got: " + e);
243+
}
244+
try {
245+
_ = await KyberBancorReserve.new(
246+
bancorNetwork.address,
247+
network,
248+
feeBps,
249+
bancorEthToken.address,
250+
bancorETHBNTToken.address,
251+
zeroAddress,
230252
admin
231253
);
232254
assert(false, "throw was expected in line above.")
@@ -239,6 +261,7 @@ contract('KyberBancorNetwork', function(accounts) {
239261
network,
240262
feeBps,
241263
bancorEthToken.address,
264+
bancorETHBNTToken.address,
242265
bancorBntToken.address,
243266
zeroAddress
244267
);
@@ -251,6 +274,7 @@ contract('KyberBancorNetwork', function(accounts) {
251274
network,
252275
feeBps,
253276
bancorEthToken.address,
277+
bancorETHBNTToken.address,
254278
bancorBntToken.address,
255279
admin
256280
);

0 commit comments

Comments
 (0)