Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit cadf640

Browse files
authored
Merge pull request #69 from SetProtocol/brian/aggregate_modifiers
Moved common modifiers to own contract. Extensions now inherit this …
2 parents f3411e1 + 271f910 commit cadf640

File tree

5 files changed

+83
-40
lines changed

5 files changed

+83
-40
lines changed

contracts/core/extensions/CoreAccounting.sol

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
pragma solidity 0.4.24;
1818

1919
import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";
20+
import { CoreModifiers } from "../lib/CoreSharedModifiers.sol";
2021
import { CoreState } from "../lib/CoreState.sol";
2122
import { ITransferProxy } from "../interfaces/ITransferProxy.sol";
2223
import { IVault } from "../interfaces/IVault.sol";
@@ -30,7 +31,8 @@ import { IVault } from "../interfaces/IVault.sol";
3031
* for storage of tokenized assets
3132
*/
3233
contract CoreAccounting is
33-
CoreState
34+
CoreState,
35+
CoreModifiers
3436
{
3537
// Use SafeMath library for all uint256 arithmetic
3638
using SafeMath for uint256;
@@ -66,14 +68,6 @@ contract CoreAccounting is
6668
_;
6769
}
6870

69-
modifier isPositiveQuantity(uint _quantity) {
70-
require(
71-
_quantity > 0,
72-
ZERO_QUANTITY
73-
);
74-
_;
75-
}
76-
7771
/* ============ Public Functions ============ */
7872

7973
/**

contracts/core/extensions/CoreFactory.sol

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
pragma solidity 0.4.24;
1818

1919
import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";
20+
import { CoreModifiers } from "../lib/CoreSharedModifiers.sol";
2021
import { CoreState } from "../lib/CoreState.sol";
2122
import { ISetFactory } from "../interfaces/ISetFactory.sol";
2223

@@ -28,7 +29,8 @@ import { ISetFactory } from "../interfaces/ISetFactory.sol";
2829
* The CoreCreate contract contains public set token operations
2930
*/
3031
contract CoreFactory is
31-
CoreState
32+
CoreState,
33+
CoreModifiers
3234
{
3335
// Use SafeMath library for all uint256 arithmetic
3436
using SafeMath for uint256;
@@ -49,15 +51,6 @@ contract CoreFactory is
4951
string _symbol
5052
);
5153

52-
/* ============ Modifiers ============ */
53-
54-
modifier isValidFactory(address _factoryAddress) {
55-
require(
56-
state.validFactories[_factoryAddress],
57-
INVALID_FACTORY
58-
);
59-
_;
60-
}
6154

6255
/* ============ Public Functions ============ */
6356

contracts/core/extensions/CoreInternal.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
pragma solidity 0.4.24;
1818

1919
import { Ownable } from "zeppelin-solidity/contracts/ownership/Ownable.sol";
20+
import { CoreModifiers } from "../lib/CoreSharedModifiers.sol";
2021
import { CoreState } from "../lib/CoreState.sol";
2122

2223

@@ -29,7 +30,8 @@ import { CoreState } from "../lib/CoreState.sol";
2930
*/
3031
contract CoreInternal is
3132
Ownable,
32-
CoreState
33+
CoreState,
34+
CoreModifiers
3335
{
3436
/* ============ Setter Functions ============ */
3537

@@ -87,6 +89,7 @@ contract CoreInternal is
8789
)
8890
external
8991
onlyOwner
92+
isValidFactory(_factoryAddress)
9093
{
9194
state.validFactories[_factoryAddress] = false;
9295
}
@@ -101,6 +104,7 @@ contract CoreInternal is
101104
)
102105
external
103106
onlyOwner
107+
isValidSet(_setAddress)
104108
{
105109
state.validSets[_setAddress] = false;
106110
}

contracts/core/extensions/CoreIssuance.sol

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
pragma solidity 0.4.24;
1818

1919
import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";
20+
import { CoreModifiers } from "../lib/CoreSharedModifiers.sol";
2021
import { CoreState } from "../lib/CoreState.sol";
2122
import { ISetToken } from "../interfaces/ISetToken.sol";
2223
import { ITransferProxy } from "../interfaces/ITransferProxy.sol";
@@ -30,7 +31,8 @@ import { IVault } from "../interfaces/IVault.sol";
3031
* The CoreIssuance contract contains public set token operations
3132
*/
3233
contract CoreIssuance is
33-
CoreState
34+
CoreState,
35+
CoreModifiers
3436
{
3537
// Use SafeMath library for all uint256 arithmetic
3638
using SafeMath for uint256;
@@ -60,23 +62,6 @@ contract CoreIssuance is
6062
_;
6163
}
6264

63-
modifier isPositive(uint _quantity) {
64-
require(
65-
_quantity > 0,
66-
ZERO_QUANTITY
67-
);
68-
_;
69-
}
70-
71-
// Verify set was created by core and is enabled
72-
modifier isValidSet(address _setAddress) {
73-
require(
74-
state.validSets[_setAddress],
75-
INVALID_SET
76-
);
77-
_;
78-
}
79-
8065
/* ============ Public Functions ============ */
8166

8267
/**
@@ -91,7 +76,7 @@ contract CoreIssuance is
9176
)
9277
public
9378
isValidSet(_setAddress)
94-
isPositive(_quantity)
79+
isPositiveQuantity(_quantity)
9580
isNaturalUnitMultiple(_quantity, _setAddress)
9681
{
9782
// Fetch set token components
@@ -172,7 +157,7 @@ contract CoreIssuance is
172157
)
173158
public
174159
isValidSet(_setAddress)
175-
isPositive(_quantity)
160+
isPositiveQuantity(_quantity)
176161
isNaturalUnitMultiple(_quantity, _setAddress)
177162
{
178163
// Burn the Set token (thereby decrementing the SetToken balance)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2018 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
pragma solidity 0.4.24;
18+
19+
import { CoreState } from "../lib/CoreState.sol";
20+
21+
/**
22+
* @title Core Shared Modifiers
23+
* @author Set Protocol
24+
*
25+
* The Core Shared Modifiers library contains the modifiers that are shared across the different
26+
* Core extensions.
27+
*/
28+
29+
contract CoreModifiers is
30+
CoreState
31+
{
32+
33+
/* ============ Constants ============ */
34+
35+
string constant ZERO_QUANTITY = "Quantity must be greater than zero.";
36+
string constant INVALID_SET = "Set token is disabled or does not exist.";
37+
string constant INVALID_FACTORY = "Factory is disabled or does not exist.";
38+
39+
/* ============ Modifiers ============ */
40+
41+
// Check that quantity submitted is greater than 0
42+
modifier isPositiveQuantity(uint _quantity) {
43+
require(
44+
_quantity > 0,
45+
ZERO_QUANTITY
46+
);
47+
_;
48+
}
49+
50+
// Verify Factory is linked to Core
51+
modifier isValidFactory(address _factoryAddress) {
52+
require(
53+
state.validFactories[_factoryAddress],
54+
INVALID_FACTORY
55+
);
56+
_;
57+
}
58+
59+
// Verify set was created by core and is enabled
60+
modifier isValidSet(address _setAddress) {
61+
require(
62+
state.validSets[_setAddress],
63+
INVALID_SET
64+
);
65+
_;
66+
}
67+
}

0 commit comments

Comments
 (0)