Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
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
5 changes: 5 additions & 0 deletions contracts/core/extensions/CoreAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";
import { CoreState } from "../lib/CoreState.sol";
import { ITransferProxy } from "../interfaces/ITransferProxy.sol";
import { IVault } from "../interfaces/IVault.sol";
import { CoreOperationState } from "./CoreOperationState.sol";


/**
Expand All @@ -32,6 +33,7 @@ import { IVault } from "../interfaces/IVault.sol";
*/
contract CoreAccounting is
CoreState,
CoreOperationState,
ReentrancyGuard
{
// Use SafeMath library for all uint256 arithmetic
Expand All @@ -51,6 +53,7 @@ contract CoreAccounting is
)
external
nonReentrant
whenOperational
{
// Call internal deposit function
depositInternal(
Expand Down Expand Up @@ -96,6 +99,7 @@ contract CoreAccounting is
)
external
nonReentrant
whenOperational
{
// Call internal batch deposit function
batchDepositInternal(
Expand Down Expand Up @@ -144,6 +148,7 @@ contract CoreAccounting is
)
external
nonReentrant
whenOperational
{
IVault(state.vault).transferBalance(
_token,
Expand Down
3 changes: 3 additions & 0 deletions contracts/core/extensions/CoreIssuance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { CoreState } from "../lib/CoreState.sol";
import { ISetToken } from "../interfaces/ISetToken.sol";
import { ITransferProxy } from "../interfaces/ITransferProxy.sol";
import { IVault } from "../interfaces/IVault.sol";
import { CoreOperationState } from "./CoreOperationState.sol";


/**
Expand All @@ -32,6 +33,7 @@ import { IVault } from "../interfaces/IVault.sol";
*/
contract CoreIssuance is
CoreState,
CoreOperationState,
ReentrancyGuard
{
// Use SafeMath library for all uint256 arithmetic
Expand Down Expand Up @@ -59,6 +61,7 @@ contract CoreIssuance is
)
external
nonReentrant
whenOperational
{
issueInternal(
msg.sender,
Expand Down
95 changes: 95 additions & 0 deletions contracts/core/extensions/CoreOperationState.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2018 Set Labs Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity 0.4.25;

import { Ownable } from "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import { CoreState } from "../lib/CoreState.sol";


/**
* @title Core Operation State
* @author Set Protocol
*
* The CoreOperationState contract contains methods to alter state of variables that track
* Core dependency addresses.
*/
contract CoreOperationState is
Ownable,
CoreState
{

/* ============ Enum ============ */

/**
* Operational:
* All Accounting and Issuance related functions are available for usage during this stage
*
* Shut Down:
* Only functions which allow users to redeem and withdraw funds are allowed during this stage
*/
enum OperationState {
Operational,
ShutDown,
InvalidState
}

/* ============ Events ============ */

event OperationStateChanged(
uint8 _prevState,
uint8 _newState
);

/* ============ Modifiers ============ */

modifier whenOperational() {
require(
state.operationState == uint8(OperationState.Operational),
"CoreOperationalState.whenOperational: Function is in non-operational state."
);
_;
}

/* ============ External Functions ============ */

/**
* Updates the operation state of the protocol.
* Can only be called by owner of Core.
*
* @param _operationState Uint8 representing the current protocol operation state
*/
function setOperationState(
uint8 _operationState
)
external
onlyOwner
{
require(
_operationState < uint8(OperationState.InvalidState),
"CoreOperationalState.setOperationalState: Input is not a valid operation state"
);

emit OperationStateChanged(
state.operationState,
_operationState
);

state.operationState = _operationState;
}


}
4 changes: 2 additions & 2 deletions contracts/core/interfaces/ICoreAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ pragma solidity 0.4.25;


/**
* @title ICoreIssuance
* @title ICoreAccounting
* @author Set Protocol
*
* The ICoreIssuance Contract defines all the functions exposed in the CoreIssuance
* The ICoreAccounting Contract defines all the functions exposed in the CoreIssuance
* extension.
*/
contract ICoreAccounting {
Expand Down
16 changes: 16 additions & 0 deletions contracts/core/lib/CoreState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ contract CoreState {
/* ============ Structs ============ */

struct State {
// Protocol state of operation
uint8 operationState;

// Mapping of exchange enumeration to address
mapping(uint8 => address) exchanges;

Expand Down Expand Up @@ -72,6 +75,19 @@ contract CoreState {

/* ============ Public Getters ============ */

/**
* Return uint8 representing the operational state of the protocol
*
* @return uint8 Uint8 representing the operational state of the protocol
*/
function operationState()
public
view
returns(uint8)
{
return state.operationState;
}

/**
* Return address belonging to given exchangeId.
*
Expand Down
40 changes: 40 additions & 0 deletions test/contracts/core/extensions/coreAccounting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
DEPLOYED_TOKEN_QUANTITY,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
ZERO,
ONE,
} from '@utils/constants';
import { ERC20Wrapper } from '@utils/erc20Wrapper';
import { getWeb3 } from '@utils/web3Helper';
Expand Down Expand Up @@ -159,6 +160,19 @@ contract('CoreAccounting', accounts => {
await expectRevertError(subject());
});
});

describe('when the protocol is not in operational state', async () => {
beforeEach(async () => {
await coreWrapper.setOperationStateAsync(
core,
ONE,
);
});

it('should revert', async () => {
await expectRevertError(subject());
});
});
});

describe('#withdraw', async () => {
Expand Down Expand Up @@ -459,6 +473,19 @@ contract('CoreAccounting', accounts => {
expect(newOwnerBalance).to.be.bignumber.equal(existingOwnerVaultBalance.add(DEPLOYED_TOKEN_QUANTITY));
});
});

describe('when the protocol is not in operational state', async () => {
beforeEach(async () => {
await coreWrapper.setOperationStateAsync(
core,
ONE,
);
});

it('should revert', async () => {
await expectRevertError(subject());
});
});
});

describe('#batchWithdraw', async () => {
Expand Down Expand Up @@ -661,5 +688,18 @@ contract('CoreAccounting', accounts => {
await expectRevertError(subject());
});
});

describe('when the protocol is not in operational state', async () => {
beforeEach(async () => {
await coreWrapper.setOperationStateAsync(
core,
ONE,
);
});

it('should revert', async () => {
await expectRevertError(subject());
});
});
});
});
14 changes: 14 additions & 0 deletions test/contracts/core/extensions/coreIssuance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
DEFAULT_GAS,
DEPLOYED_TOKEN_QUANTITY,
ZERO,
ONE,
DEFAULT_UNIT_SHARES,
DEFAULT_REBALANCING_NATURAL_UNIT,
ONE_DAY_IN_SECONDS
Expand Down Expand Up @@ -359,6 +360,19 @@ contract('CoreIssuance', accounts => {
await assertTokenBalanceAsync(setToken, existingBalance.add(subjectQuantityToIssue), ownerAccount);
});
});

describe('when the protocol is not in operational state', async () => {
beforeEach(async () => {
await coreWrapper.setOperationStateAsync(
core,
ONE,
);
});

it('should revert', async () => {
await expectRevertError(subject());
});
});
});

describe('#issue: RebalancingToken', async () => {
Expand Down
Loading