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

Commit e319a3c

Browse files
authored
Merge pull request #66 from SetProtocol/alex/core_accounting
Core accounting extension
2 parents 85e03a6 + 242efba commit e319a3c

File tree

13 files changed

+227
-200
lines changed

13 files changed

+227
-200
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<p align="center">
44
<a href="https://circleci.com/gh/SetProtocol/set-protocol-contracts/tree/master">
5-
<img src="https://img.shields.io/circleci/project/github/SetProtocol/set-protocol-contracts.svg" />
5+
<img src="https://img.shields.io/circleci/project/github/SetProtocol/set-protocol-contracts/master.svg" />
66
</a>
77
<a href='https://coveralls.io/github/SetProtocol/set-protocol-contracts'>
88
<img src='https://coveralls.io/repos/github/SetProtocol/set-protocol-contracts/badge.svg?branch=master' alt='Coverage Status' />

contracts/core/Core.sol

Lines changed: 5 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@
1616

1717
pragma solidity 0.4.24;
1818

19-
import { Ownable } from "zeppelin-solidity/contracts/ownership/Ownable.sol";
20-
import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";
19+
import { CoreAccounting } from "./extensions/CoreAccounting.sol";
20+
import { CoreFactory } from "./extensions/CoreFactory.sol";
2121
import { CoreInternal } from "./extensions/CoreInternal.sol";
2222
import { CoreIssuance } from "./extensions/CoreIssuance.sol";
23-
import { CoreCreate } from "./extensions/CoreCreate.sol";
24-
import { CoreState } from "./lib/CoreState.sol";
25-
import { ISetFactory } from "./interfaces/ISetFactory.sol";
26-
import { ITransferProxy } from "./interfaces/ITransferProxy.sol";
27-
import { IVault } from "./interfaces/IVault.sol";
2823

2924

3025
/**
@@ -35,145 +30,8 @@ import { IVault } from "./interfaces/IVault.sol";
3530
* creating Sets, as well as all collateral flows throughout the system.
3631
*/
3732
contract Core is
33+
CoreAccounting,
3834
CoreIssuance,
3935
CoreInternal,
40-
CoreCreate
41-
{
42-
// Use SafeMath library for all uint256 arithmetic
43-
using SafeMath for uint256;
44-
45-
/* ============ Constants ============ */
46-
47-
string constant ADDRESSES_MISSING = "Addresses must not be empty.";
48-
string constant BATCH_INPUT_MISMATCH = "Addresses and quantities must be the same length.";
49-
string constant QUANTITES_MISSING = "Quantities must not be empty.";
50-
51-
/* ============ Modifiers ============ */
52-
53-
// Confirm that all inputs are valid for batch transactions
54-
modifier isValidBatchTransaction(address[] _tokenAddresses, uint[] _quantities) {
55-
// Confirm an empty _addresses array is not passed
56-
require(
57-
_tokenAddresses.length > 0,
58-
ADDRESSES_MISSING
59-
);
60-
61-
// Confirm an empty _quantities array is not passed
62-
require(
63-
_quantities.length > 0,
64-
QUANTITES_MISSING
65-
);
66-
67-
// Confirm there is one quantity for every token address
68-
require(
69-
_tokenAddresses.length == _quantities.length,
70-
BATCH_INPUT_MISMATCH
71-
);
72-
_;
73-
}
74-
75-
/* ============ No Constructor ============ */
76-
77-
/* ============ Public Functions ============ */
78-
79-
/**
80-
* Deposit multiple tokens to the vault. Quantities should be in the
81-
* order of the addresses of the tokens being deposited.
82-
*
83-
* @param _tokenAddresses Array of the addresses of the ERC20 tokens
84-
* @param _quantities Array of the number of tokens to deposit
85-
*/
86-
function batchDeposit(
87-
address[] _tokenAddresses,
88-
uint[] _quantities
89-
)
90-
public
91-
isValidBatchTransaction(_tokenAddresses, _quantities)
92-
{
93-
// For each token and quantity pair, run deposit function
94-
for (uint i = 0; i < _tokenAddresses.length; i++) {
95-
deposit(
96-
_tokenAddresses[i],
97-
_quantities[i]
98-
);
99-
}
100-
}
101-
102-
/**
103-
* Withdraw multiple tokens from the vault. Quantities should be in the
104-
* order of the addresses of the tokens being withdrawn.
105-
*
106-
* @param _tokenAddresses Array of the addresses of the ERC20 tokens
107-
* @param _quantities Array of the number of tokens to withdraw
108-
*/
109-
function batchWithdraw(
110-
address[] _tokenAddresses,
111-
uint[] _quantities
112-
)
113-
public
114-
isValidBatchTransaction(_tokenAddresses, _quantities)
115-
{
116-
// For each token and quantity pair, run withdraw function
117-
for (uint i = 0; i < _tokenAddresses.length; i++) {
118-
withdraw(
119-
_tokenAddresses[i],
120-
_quantities[i]
121-
);
122-
}
123-
}
124-
125-
/**
126-
* Deposit any quantity of tokens into the vault.
127-
*
128-
* @param _tokenAddress The address of the ERC20 token
129-
* @param _quantity The number of tokens to deposit
130-
*/
131-
function deposit(
132-
address _tokenAddress,
133-
uint _quantity
134-
)
135-
public
136-
isPositive(_quantity)
137-
{
138-
// Call TransferProxy contract to transfer user tokens to Vault
139-
ITransferProxy(state.transferProxyAddress).transferToVault(
140-
msg.sender,
141-
_tokenAddress,
142-
_quantity
143-
);
144-
145-
// Call Vault contract to attribute deposited tokens to user
146-
IVault(state.vaultAddress).incrementTokenOwner(
147-
msg.sender,
148-
_tokenAddress,
149-
_quantity
150-
);
151-
}
152-
153-
/**
154-
* Withdraw a quantity of tokens from the vault.
155-
*
156-
* @param _tokenAddress The address of the ERC20 token
157-
* @param _quantity The number of tokens to withdraw
158-
*/
159-
function withdraw(
160-
address _tokenAddress,
161-
uint _quantity
162-
)
163-
public
164-
{
165-
// Call Vault contract to deattribute tokens to user
166-
IVault(state.vaultAddress).decrementTokenOwner(
167-
msg.sender,
168-
_tokenAddress,
169-
_quantity
170-
);
171-
172-
// Call Vault to withdraw tokens from Vault to user
173-
IVault(state.vaultAddress).withdrawTo(
174-
_tokenAddress,
175-
msg.sender,
176-
_quantity
177-
);
178-
}
179-
}
36+
CoreFactory
37+
{}

contracts/core/SetTokenFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { Authorizable } from "../lib/Authorizable.sol";
2929
* called by Core
3030
*/
3131
contract SetTokenFactory
32-
is Authorizable
32+
is Authorizable
3333
{
3434
/* ============ State Variables ============ */
3535

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
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 { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";
20+
import { CoreState } from "../lib/CoreState.sol";
21+
import { ITransferProxy } from "../interfaces/ITransferProxy.sol";
22+
import { IVault } from "../interfaces/IVault.sol";
23+
24+
25+
/**
26+
* @title Core Accounting
27+
* @author Set Protocol
28+
*
29+
* The CoreAccounting contract interfaces with the vault and transfer transfer proxies
30+
* for storage of tokenized assets
31+
*/
32+
contract CoreAccounting is
33+
CoreState
34+
{
35+
// Use SafeMath library for all uint256 arithmetic
36+
using SafeMath for uint256;
37+
38+
/* ============ Constants ============ */
39+
40+
string constant ADDRESSES_MISSING = "Addresses must not be empty.";
41+
string constant BATCH_INPUT_MISMATCH = "Addresses and quantities must be the same length.";
42+
string constant QUANTITES_MISSING = "Quantities must not be empty.";
43+
string constant ZERO_QUANTITY = "Quantity must be greater than zero.";
44+
45+
/* ============ Modifiers ============ */
46+
47+
// Confirm that all inputs are valid for batch transactions
48+
modifier isValidBatchTransaction(address[] _tokenAddresses, uint[] _quantities) {
49+
// Confirm an empty _addresses array is not passed
50+
require(
51+
_tokenAddresses.length > 0,
52+
ADDRESSES_MISSING
53+
);
54+
55+
// Confirm an empty _quantities array is not passed
56+
require(
57+
_quantities.length > 0,
58+
QUANTITES_MISSING
59+
);
60+
61+
// Confirm there is one quantity for every token address
62+
require(
63+
_tokenAddresses.length == _quantities.length,
64+
BATCH_INPUT_MISMATCH
65+
);
66+
_;
67+
}
68+
69+
modifier isPositiveQuantity(uint _quantity) {
70+
require(
71+
_quantity > 0,
72+
ZERO_QUANTITY
73+
);
74+
_;
75+
}
76+
77+
/* ============ Public Functions ============ */
78+
79+
/**
80+
* Deposit multiple tokens to the vault. Quantities should be in the
81+
* order of the addresses of the tokens being deposited.
82+
*
83+
* @param _tokenAddresses Array of the addresses of the ERC20 tokens
84+
* @param _quantities Array of the number of tokens to deposit
85+
*/
86+
function batchDeposit(
87+
address[] _tokenAddresses,
88+
uint[] _quantities
89+
)
90+
public
91+
isValidBatchTransaction(_tokenAddresses, _quantities)
92+
{
93+
// For each token and quantity pair, run deposit function
94+
for (uint i = 0; i < _tokenAddresses.length; i++) {
95+
deposit(
96+
_tokenAddresses[i],
97+
_quantities[i]
98+
);
99+
}
100+
}
101+
102+
/**
103+
* Withdraw multiple tokens from the vault. Quantities should be in the
104+
* order of the addresses of the tokens being withdrawn.
105+
*
106+
* @param _tokenAddresses Array of the addresses of the ERC20 tokens
107+
* @param _quantities Array of the number of tokens to withdraw
108+
*/
109+
function batchWithdraw(
110+
address[] _tokenAddresses,
111+
uint[] _quantities
112+
)
113+
public
114+
isValidBatchTransaction(_tokenAddresses, _quantities)
115+
{
116+
// For each token and quantity pair, run withdraw function
117+
for (uint i = 0; i < _tokenAddresses.length; i++) {
118+
withdraw(
119+
_tokenAddresses[i],
120+
_quantities[i]
121+
);
122+
}
123+
}
124+
125+
/**
126+
* Deposit any quantity of tokens into the vault.
127+
*
128+
* @param _tokenAddress The address of the ERC20 token
129+
* @param _quantity The number of tokens to deposit
130+
*/
131+
function deposit(
132+
address _tokenAddress,
133+
uint _quantity
134+
)
135+
public
136+
isPositiveQuantity(_quantity)
137+
{
138+
// Call TransferProxy contract to transfer user tokens to Vault
139+
ITransferProxy(state.transferProxyAddress).transferToVault(
140+
msg.sender,
141+
_tokenAddress,
142+
_quantity
143+
);
144+
145+
// Call Vault contract to attribute deposited tokens to user
146+
IVault(state.vaultAddress).incrementTokenOwner(
147+
msg.sender,
148+
_tokenAddress,
149+
_quantity
150+
);
151+
}
152+
153+
/**
154+
* Withdraw a quantity of tokens from the vault.
155+
*
156+
* @param _tokenAddress The address of the ERC20 token
157+
* @param _quantity The number of tokens to withdraw
158+
*/
159+
function withdraw(
160+
address _tokenAddress,
161+
uint _quantity
162+
)
163+
public
164+
{
165+
// Call Vault contract to deattribute tokens to user
166+
IVault(state.vaultAddress).decrementTokenOwner(
167+
msg.sender,
168+
_tokenAddress,
169+
_quantity
170+
);
171+
172+
// Call Vault to withdraw tokens from Vault to user
173+
IVault(state.vaultAddress).withdrawTo(
174+
_tokenAddress,
175+
msg.sender,
176+
_quantity
177+
);
178+
}
179+
}

contracts/core/extensions/CoreCreate.sol renamed to contracts/core/extensions/CoreFactory.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import { ISetFactory } from "../interfaces/ISetFactory.sol";
2222

2323

2424
/**
25-
* @title Core Create
25+
* @title Core Factory
2626
* @author Set Protocol
27-
*x
27+
*
2828
* The CoreCreate contract contains public set token operations
2929
*/
30-
contract CoreCreate is
30+
contract CoreFactory is
3131
CoreState
3232
{
3333
// Use SafeMath library for all uint256 arithmetic

0 commit comments

Comments
 (0)