update SwapProxy to update key variables
proper slippage calc on token transfers
This commit is contained in:
parent
9e3ea27ee9
commit
8a3f77f251
|
@ -31,6 +31,43 @@ contract SwapProxy is Pausable, SafeToken {
|
||||||
maxSlippage = _maxSlippage;
|
maxSlippage = _maxSlippage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event SlippageUpdated(uint maxSlippage);
|
||||||
|
/**
|
||||||
|
* @param _maxSlippage most slippage as a percentage
|
||||||
|
*/
|
||||||
|
function updateSlippage(uint _maxSlippage) public onlyOwner {
|
||||||
|
require(_maxSlippage < 100);
|
||||||
|
maxSlippage = _maxSlippage;
|
||||||
|
SlippageUpdated(_maxSlippage);
|
||||||
|
}
|
||||||
|
|
||||||
|
event VaultUpdated(address vault);
|
||||||
|
/**
|
||||||
|
* @param _vault address that receives swap fees
|
||||||
|
*/
|
||||||
|
function updateVault(address _vault) public onlyOwner {
|
||||||
|
vault = _vault;
|
||||||
|
VaultUpdated(_vault);
|
||||||
|
}
|
||||||
|
|
||||||
|
event KyberUpdated(address kyber);
|
||||||
|
/**
|
||||||
|
* @param _kyberProxy Kyber Network Proxy address
|
||||||
|
*/
|
||||||
|
function updateKyber(address _kyberProxy) public onlyOwner {
|
||||||
|
kyberProxy = KyberNetworkProxy(_kyberProxy);
|
||||||
|
KyberUpdated(_kyberProxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
event LiquidPledgingUpdated(address liquidPledging);
|
||||||
|
/**
|
||||||
|
* @param _liquidPledging LiquidPledging Network Proxy address
|
||||||
|
*/
|
||||||
|
function updateLiquidPledging(address _liquidPledging) public onlyOwner {
|
||||||
|
liquidPledging = LiquidPledging(_liquidPledging);
|
||||||
|
LiquidPledgingUpdated(_liquidPledging);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Gets the conversion rate for the destToken given the srcQty.
|
* @notice Gets the conversion rate for the destToken given the srcQty.
|
||||||
* @param srcToken source token contract address
|
* @param srcToken source token contract address
|
||||||
|
@ -51,6 +88,8 @@ contract SwapProxy is Pausable, SafeToken {
|
||||||
return slippageRate;
|
return slippageRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event Swap(address sender, address srcToken, address destToken, uint srcAmount, uint destAmount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Funds a project in desired token using ETH
|
* @notice Funds a project in desired token using ETH
|
||||||
* @dev Requires a msg.value
|
* @dev Requires a msg.value
|
||||||
|
@ -70,8 +109,10 @@ contract SwapProxy is Pausable, SafeToken {
|
||||||
require(amount > 0);
|
require(amount > 0);
|
||||||
require(EIP20Interface(token).approve(address(liquidPledging), amount));
|
require(EIP20Interface(token).approve(address(liquidPledging), amount));
|
||||||
liquidPledging.addGiverAndDonate(idReceiver, token, amount);
|
liquidPledging.addGiverAndDonate(idReceiver, token, amount);
|
||||||
|
Swap(msg.sender, ETH, token, msg.value, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Funds a project in desired token using an ERC20 Token
|
* @notice Funds a project in desired token using an ERC20 Token
|
||||||
* @param idReceiver receiver of donation
|
* @param idReceiver receiver of donation
|
||||||
|
@ -87,7 +128,7 @@ contract SwapProxy is Pausable, SafeToken {
|
||||||
uint slippageRate;
|
uint slippageRate;
|
||||||
(expectedRate, slippageRate) = kyberProxy.getExpectedRate(token, receiverToken, amount);
|
(expectedRate, slippageRate) = kyberProxy.getExpectedRate(token, receiverToken, amount);
|
||||||
require(expectedRate > 0);
|
require(expectedRate > 0);
|
||||||
uint slippagePercent = (slippageRate * 100) / expectedRate;
|
uint slippagePercent = 100 - (slippageRate * 100) / expectedRate;
|
||||||
require(slippagePercent <= maxSlippage);
|
require(slippagePercent <= maxSlippage);
|
||||||
require(EIP20Interface(token).approve(address(kyberProxy), 0));
|
require(EIP20Interface(token).approve(address(kyberProxy), 0));
|
||||||
require(EIP20Interface(token).approve(address(kyberProxy), amount));
|
require(EIP20Interface(token).approve(address(kyberProxy), amount));
|
||||||
|
@ -97,6 +138,7 @@ contract SwapProxy is Pausable, SafeToken {
|
||||||
require(receiverAmount > 0);
|
require(receiverAmount > 0);
|
||||||
require(EIP20Interface(token).approve(address(liquidPledging), receiverAmount));
|
require(EIP20Interface(token).approve(address(liquidPledging), receiverAmount));
|
||||||
liquidPledging.addGiverAndDonate(idReceiver, receiverToken, receiverAmount);
|
liquidPledging.addGiverAndDonate(idReceiver, receiverToken, receiverAmount);
|
||||||
|
Swap(msg.sender, token, receiverToken, amount, receiverAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferOut(address asset, address to, uint amount) public onlyOwner {
|
function transferOut(address asset, address to, uint amount) public onlyOwner {
|
||||||
|
|
|
@ -184,7 +184,7 @@ module.exports = {
|
||||||
address: "0x8aA3672a99C489E5Dc5dfDb40e607bE49970cbF7"
|
address: "0x8aA3672a99C489E5Dc5dfDb40e607bE49970cbF7"
|
||||||
},
|
},
|
||||||
SwapProxy: {
|
SwapProxy: {
|
||||||
address: "0x46A30Bf6D0E438E7EeaabD6c4B5fEBf481267722",
|
address: "0x1B468F2a4CDaC05E5B2f432DA24F049201B74Aa2",
|
||||||
args: [
|
args: [
|
||||||
'$LiquidPledging',
|
'$LiquidPledging',
|
||||||
"0x818E6FECD516Ecc3849DAf6845e3EC868087B755",
|
"0x818E6FECD516Ecc3849DAf6845e3EC868087B755",
|
||||||
|
|
|
@ -24,6 +24,18 @@
|
||||||
"0xd9d749fb529af69819711faec78815efe4334ea74c7785ece18e3f276d845934": {
|
"0xd9d749fb529af69819711faec78815efe4334ea74c7785ece18e3f276d845934": {
|
||||||
"name": "DAI",
|
"name": "DAI",
|
||||||
"address": "0xaD6D458402F60fD3Bd25163575031ACDce07538D"
|
"address": "0xaD6D458402F60fD3Bd25163575031ACDce07538D"
|
||||||
|
},
|
||||||
|
"0xafe7338679d28b8279653439aa74f34791475ba797295e37336eecf436127480": {
|
||||||
|
"name": "SwapProxy",
|
||||||
|
"address": "0x2B45165e26f5d32fB75abE2fc7f8E7e5D506223b"
|
||||||
|
},
|
||||||
|
"0x2c4bdca5cbf721642f976ca0e83a902c8b88d9e7fd49f721263f145b908d08ef": {
|
||||||
|
"name": "SwapProxy",
|
||||||
|
"address": "0x2B45165e26f5d32fB75abE2fc7f8E7e5D506223b"
|
||||||
|
},
|
||||||
|
"0x17446ffed738afc7e8cab4b9f8b44f8fcabe07029419220d52b9fe9318f37b95": {
|
||||||
|
"name": "SwapProxy",
|
||||||
|
"address": "0x1B468F2a4CDaC05E5B2f432DA24F049201B74Aa2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue