Skip to content

Remove pause functions #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 4 additions & 47 deletions contracts/UFragments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ contract UFragments is ERC20Detailed, Ownable {
using SafeMathInt for int256;

event LogRebase(uint256 indexed epoch, uint256 totalSupply);
event LogRebasePaused(bool paused);
event LogTokenPaused(bool paused);
event LogMonetaryPolicyUpdated(address monetaryPolicy);

// Used for authentication
Expand All @@ -51,19 +49,8 @@ contract UFragments is ERC20Detailed, Ownable {
_;
}

// Precautionary emergency controls.
bool public rebasePaused;
bool public tokenPaused;

modifier whenRebaseNotPaused() {
require(!rebasePaused);
_;
}

modifier whenTokenNotPaused() {
require(!tokenPaused);
_;
}
bool private rebasePausedDeprecated;
bool private tokenPausedDeprecated;

modifier validRecipient(address to) {
require(to != address(0x0));
Expand Down Expand Up @@ -101,30 +88,6 @@ contract UFragments is ERC20Detailed, Ownable {
emit LogMonetaryPolicyUpdated(monetaryPolicy_);
}

/**
* @dev Pauses or unpauses the execution of rebase operations.
* @param paused Pauses rebase operations if this is true.
*/
function setRebasePaused(bool paused)
external
onlyOwner
{
rebasePaused = paused;
emit LogRebasePaused(paused);
}

/**
* @dev Pauses or unpauses execution of ERC-20 transactions.
* @param paused Pauses ERC-20 transactions if this is true.
*/
function setTokenPaused(bool paused)
external
onlyOwner
{
tokenPaused = paused;
emit LogTokenPaused(paused);
}

/**
* @dev Notifies Fragments contract about a new rebase cycle.
* @param supplyDelta The number of new fragment tokens to add into circulation via expansion.
Expand All @@ -133,7 +96,6 @@ contract UFragments is ERC20Detailed, Ownable {
function rebase(uint256 epoch, int256 supplyDelta)
external
onlyMonetaryPolicy
whenRebaseNotPaused
returns (uint256)
{
if (supplyDelta == 0) {
Expand Down Expand Up @@ -175,8 +137,8 @@ contract UFragments is ERC20Detailed, Ownable {
ERC20Detailed.initialize("Ampleforth", "AMPL", uint8(DECIMALS));
Ownable.initialize(owner_);

rebasePaused = false;
tokenPaused = false;
rebasePausedDeprecated = false;
tokenPausedDeprecated = false;
Comment on lines -178 to +141
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the initialize function should be removed entirely when deploying a new template (since it is never called)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know.

There could be a future where we do a separate non-upgrade deployment. Could be on Ethereum or an alternate chain that works with solidity tools. In that case, it'd be useful to have it there already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - in that case I would recommend keeping as a comment since you want to avoid deploying unreachable code


_totalSupply = INITIAL_FRAGMENTS_SUPPLY;
_gonBalances[owner_] = TOTAL_GONS;
Expand Down Expand Up @@ -217,7 +179,6 @@ contract UFragments is ERC20Detailed, Ownable {
function transfer(address to, uint256 value)
public
validRecipient(to)
whenTokenNotPaused
returns (bool)
{
uint256 gonValue = value.mul(_gonsPerFragment);
Expand Down Expand Up @@ -250,7 +211,6 @@ contract UFragments is ERC20Detailed, Ownable {
function transferFrom(address from, address to, uint256 value)
public
validRecipient(to)
whenTokenNotPaused
returns (bool)
{
_allowedFragments[from][msg.sender] = _allowedFragments[from][msg.sender].sub(value);
Expand All @@ -276,7 +236,6 @@ contract UFragments is ERC20Detailed, Ownable {
*/
function approve(address spender, uint256 value)
public
whenTokenNotPaused
returns (bool)
{
_allowedFragments[msg.sender][spender] = value;
Expand All @@ -293,7 +252,6 @@ contract UFragments is ERC20Detailed, Ownable {
*/
function increaseAllowance(address spender, uint256 addedValue)
public
whenTokenNotPaused
returns (bool)
{
_allowedFragments[msg.sender][spender] =
Expand All @@ -310,7 +268,6 @@ contract UFragments is ERC20Detailed, Ownable {
*/
function decreaseAllowance(address spender, uint256 subtractedValue)
public
whenTokenNotPaused
returns (bool)
{
uint256 oldValue = _allowedFragments[msg.sender][spender];
Expand Down
154 changes: 0 additions & 154 deletions test/unit/UFragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,160 +123,6 @@ contract('UFragments:setMonetaryPolicy:accessControl', function (accounts) {
});
});

contract('UFragments:PauseRebase', function (accounts) {
const policy = accounts[1];
const A = accounts[2];
const B = accounts[3];

before('setup UFragments contract', async function () {
await setupContracts();
await uFragments.setMonetaryPolicy(policy, {from: deployer});
r = await uFragments.setRebasePaused(true);
});

it('should emit pause event', async function () {
const log = r.logs[0];
expect(log).to.exist;
expect(log.event).to.eq('LogRebasePaused');
expect(log.args.paused).to.be.true;
});

it('should not allow calling rebase', async function () {
expect(
await chain.isEthException(uFragments.rebase(1, toUFrgDenomination(500), { from: policy }))
).to.be.true;
});

it('should allow calling transfer', async function () {
await uFragments.transfer(A, transferAmount, { from: deployer });
});

it('should allow calling approve', async function () {
await uFragments.approve(A, transferAmount, { from: deployer });
});

it('should allow calling allowance', async function () {
await uFragments.allowance.call(deployer, A);
});

it('should allow calling transferFrom', async function () {
await uFragments.transferFrom(deployer, B, transferAmount, {from: A});
});

it('should allow calling increaseAllowance', async function () {
await uFragments.increaseAllowance(A, transferAmount, {from: deployer});
});

it('should allow calling decreaseAllowance', async function () {
await uFragments.decreaseAllowance(A, 10, {from: deployer});
});

it('should allow calling balanceOf', async function () {
await uFragments.balanceOf.call(deployer);
});

it('should allow calling totalSupply', async function () {
await uFragments.totalSupply.call();
});
});

contract('UFragments:PauseRebase:accessControl', function (accounts) {
before('setup UFragments contract', setupContracts);

it('should be callable by owner', async function () {
expect(
await chain.isEthException(uFragments.setRebasePaused(true, { from: deployer }))
).to.be.false;
});

it('should NOT be callable by non-owner', async function () {
expect(
await chain.isEthException(uFragments.setRebasePaused(true, { from: user }))
).to.be.true;
});
});

contract('UFragments:PauseToken', function (accounts) {
const policy = accounts[1];
const A = accounts[2];
const B = accounts[3];

before('setup UFragments contract', async function () {
await setupContracts();
await uFragments.setMonetaryPolicy(policy, {from: deployer});
r = await uFragments.setTokenPaused(true);
});

it('should emit pause event', async function () {
const log = r.logs[0];
expect(log).to.exist;
expect(log.event).to.eq('LogTokenPaused');
expect(log.args.paused).to.be.true;
});

it('should allow calling rebase', async function () {
await uFragments.rebase(1, toUFrgDenomination(500), { from: policy });
});

it('should not allow calling transfer', async function () {
expect(
await chain.isEthException(uFragments.transfer(A, transferAmount, { from: deployer }))
).to.be.true;
});

it('should not allow calling approve', async function () {
expect(
await chain.isEthException(uFragments.approve(A, transferAmount, { from: deployer }))
).to.be.true;
});

it('should allow calling allowance', async function () {
await uFragments.allowance.call(deployer, A);
});

it('should not allow calling transferFrom', async function () {
expect(
await chain.isEthException(uFragments.transferFrom(deployer, B, transferAmount, {from: A}))
).to.be.true;
});

it('should not allow calling increaseAllowance', async function () {
expect(
await chain.isEthException(uFragments.increaseAllowance(A, transferAmount, {from: deployer}))
).to.be.true;
});

it('should not allow calling decreaseAllowance', async function () {
expect(
await chain.isEthException(uFragments.decreaseAllowance(A, transferAmount, {from: deployer}))
).to.be.true;
});

it('should allow calling balanceOf', async function () {
await uFragments.balanceOf.call(deployer);
});

it('should allow calling totalSupply', async function () {
await uFragments.totalSupply.call();
});
});

contract('UFragments:PauseToken:accessControl', function (accounts) {
before('setup UFragments contract', setupContracts);

it('should be callable by owner', async function () {
expect(
await chain.isEthException(uFragments.setTokenPaused(true, { from: deployer }))
).to.be.false;
});

it('should NOT be callable by non-owner', async function () {
expect(
await chain.isEthException(uFragments.setTokenPaused(true, { from: user }))
).to.be.true;
});
});

contract('UFragments:Rebase:accessControl', function (accounts) {
before('setup UFragments contract', async function () {
await setupContracts();
Expand Down