add getMaxDestinationAmount calculation
This commit is contained in:
parent
64f937e151
commit
3a59696d94
|
@ -104,7 +104,7 @@ contract SwapProxy is Pausable, SafeToken {
|
|||
require(expectedRate > 0);
|
||||
uint slippagePercent = 100 - ((slippageRate * 100) / expectedRate);
|
||||
require(slippagePercent <= maxSlippage);
|
||||
uint maxDestinationAmount = (slippageRate / (10**18)) * msg.value;
|
||||
uint maxDestinationAmount = getMaxDestinationAmount(expectedRate, msg.value);
|
||||
uint amount = kyberProxy.trade.value(msg.value)(ETH, msg.value, token, address(this), maxDestinationAmount, slippageRate, vault);
|
||||
require(amount > 0);
|
||||
require(EIP20Interface(token).approve(address(liquidPledging), amount));
|
||||
|
@ -134,7 +134,7 @@ contract SwapProxy is Pausable, SafeToken {
|
|||
require(EIP20Interface(token).approve(address(kyberProxy), 0));
|
||||
require(EIP20Interface(token).approve(address(kyberProxy), amount));
|
||||
|
||||
uint maxDestinationAmount = (slippageRate / (10**18)) * amount;
|
||||
uint maxDestinationAmount = getMaxDestinationAmount(expectedRate, amount);
|
||||
uint receiverAmount = kyberProxy.trade(token, amount, receiverToken, address(this), maxDestinationAmount, slippageRate, vault);
|
||||
require(receiverAmount > 0);
|
||||
require(EIP20Interface(token).approve(address(liquidPledging), receiverAmount));
|
||||
|
@ -142,6 +142,11 @@ contract SwapProxy is Pausable, SafeToken {
|
|||
Swap(msg.sender, token, receiverToken, amount, receiverAmount);
|
||||
}
|
||||
|
||||
function getMaxDestinationAmount(uint expectedRate, uint amount) pure returns (uint256) {
|
||||
uint val = (expectedRate * amount) / 10**18;
|
||||
return val;
|
||||
}
|
||||
|
||||
function transferOut(address asset, address to, uint amount) public onlyOwner {
|
||||
Error err = doTransferOut(asset, to, amount);
|
||||
require(err == Error.NO_ERROR);
|
||||
|
|
Loading…
Reference in New Issue