From 97e62c862df480678a414cf1d81ff60f67556c9f Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Thu, 17 Oct 2019 14:13:42 -0400 Subject: [PATCH] make swap proxy pausable --- contracts/SwapProxy.sol | 8 +++--- contracts/common/Pausable.sol | 47 +++++++++++++++++++++++++++++++++++ embarkConfig/contracts.js | 3 ++- ropsten.chains.json | 4 +++ 4 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 contracts/common/Pausable.sol diff --git a/contracts/SwapProxy.sol b/contracts/SwapProxy.sol index ae7ca0e..5de9a3b 100644 --- a/contracts/SwapProxy.sol +++ b/contracts/SwapProxy.sol @@ -2,10 +2,10 @@ pragma solidity ^0.4.18; import "./LiquidPledging.sol"; import "./common/SafeToken.sol"; -import "./common/Ownable.sol"; +import "./common/Pausable.sol"; import "./IKyberSwap.sol"; -contract SwapProxy is Ownable, SafeToken { +contract SwapProxy is Pausable, SafeToken { address public ETH; address public vault; uint public maxSlippage; @@ -56,7 +56,7 @@ contract SwapProxy is Ownable, SafeToken { * @param idReceiver receiver of donation * @param token token to convert from ETH */ - function fundWithETH(uint64 idReceiver, address token) public payable { + function fundWithETH(uint64 idReceiver, address token) public payable whenNotPaused { require(msg.value > 0); uint expectedRate; @@ -80,7 +80,7 @@ contract SwapProxy is Ownable, SafeToken { * @param amount being sent * @param receiverToken token being converted to */ - function fundWithToken(uint64 idReceiver, address token, uint amount, address receiverToken) public { + function fundWithToken(uint64 idReceiver, address token, uint amount, address receiverToken) public whenNotPaused { Error err = doTransferIn(token, msg.sender, amount); require(err == Error.NO_ERROR); diff --git a/contracts/common/Pausable.sol b/contracts/common/Pausable.sol new file mode 100644 index 0000000..36e4fba --- /dev/null +++ b/contracts/common/Pausable.sol @@ -0,0 +1,47 @@ +pragma solidity ^0.4.18; + +import "./Ownable.sol"; + +/** + * @title Pausable + * @dev Makes contract functions pausable by the owner + */ +contract Pausable is Ownable { + + event Paused(); + event Unpaused(); + + bool public paused; + + function Pausable() internal { + paused = false; + } + + modifier whenNotPaused() { + require(!paused); + _; + } + + modifier whenPaused() { + require(paused); + _; + } + + /** + * @dev Disables contract functions marked with "whenNotPaused" and enables the use of functions marked with "whenPaused" + * Only the owner of the contract can invoke this function + */ + function pause() external onlyOwner whenNotPaused { + paused = true; + Paused(); + } + + /** + * @dev Enables contract functions marked with "whenNotPaused" and disables the use of functions marked with "whenPaused" + * Only the owner of the contract can invoke this function + */ + function unpause() external onlyOwner whenPaused { + paused = false; + Unpaused(); + } +} diff --git a/embarkConfig/contracts.js b/embarkConfig/contracts.js index f625c57..d73ef6e 100644 --- a/embarkConfig/contracts.js +++ b/embarkConfig/contracts.js @@ -180,11 +180,12 @@ module.exports = { address: "0x8aA3672a99C489E5Dc5dfDb40e607bE49970cbF7" }, SwapProxy: { + address: "0x46A30Bf6D0E438E7EeaabD6c4B5fEBf481267722", args: [ '$LiquidPledging', "0x818E6FECD516Ecc3849DAf6845e3EC868087B755", "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", - "0", + "0x0000000000000000000000000000000000000000", 20 ] } diff --git a/ropsten.chains.json b/ropsten.chains.json index 00c6353..de0b853 100644 --- a/ropsten.chains.json +++ b/ropsten.chains.json @@ -16,6 +16,10 @@ "0xa9bac214a330fe3f2048f91b805d227afa147021ef497936a65911400cc3bdd5": { "name": "SNT", "address": "0x8aA3672a99C489E5Dc5dfDb40e607bE49970cbF7" + }, + "0xb573e81b6da869674bb2d8448581ed758b9dbf7e72b0879087d49620167778d4": { + "name": "SwapProxy", + "address": "0x46A30Bf6D0E438E7EeaabD6c4B5fEBf481267722" } } }