Skip to content

Commit 20d677f

Browse files
committed
(feat) modify contracts based on requested changes
1 parent 25c7644 commit 20d677f

File tree

8 files changed

+26
-22
lines changed

8 files changed

+26
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Basket protocol establishes a decentralized ecosystem that trustlessly fulfi
1111
The Basket Protocol deconstructs the traditional asset management model into three functional roles, allowing for specialization, efficiency, and decentralization. Market participants can act in any or all capacities. Meanwhile, the protocol's registry capabilities facilitate the evaluation of and tracking of baskets as well as of the arrangers that created them.
1212

1313
- **Arranger**: "fund manager" in the traditional sense, that selects tokens and weights for basket contracts
14-
- **Market Maker**: accumulates ERC20 tokens for compiling into baskets and "minting" of basket tokens
14+
- **Supplier**: accumulates ERC20 tokens for compiling into baskets and "minting" of basket tokens
1515
- **Buyer**: the ultimate holder of the basket token, who owns and controls the basket tokens and the underlying ERC20 tokens they represent
1616

1717
## Basket Protocol Contract Suite
@@ -99,4 +99,4 @@ We welcome code contributions (via [pull requests](https://github.com/CoinAlpha/
9999
The Basket Protocol was created by [CoinAlpha](https://www.coinalpha.com). You can contact us at [[email protected]](mailto:[email protected]).
100100

101101
## License
102-
Code released under the [Apache-2.0 License](LICENSE).
102+
Code released under the [Apache-2.0 License](LICENSE).

config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ module.exports = {
55

66
// Fee amounts used for development and testing
77
TRANSACTION_FEE: 0.005 * 1e18, // Charge 0.5% transaction fee
8-
PRODUCTION_FEE: 0.3 * 1e18, // Charge 0.3 ETH of transaction per basket creation
9-
SWAPPABLE_PRODUCTION_FEE: 0.3 * 1e18, // Charge 0.5 ETH of transaction per basket creation
10-
ARRANGER_FEE: 0.01 * 1e18, // Charge 0.01 ETH of transaction per basket minted
8+
PRODUCTION_FEE: 0.3 * 1e18, // Charge 0.3 ETH per basket creation
9+
SWAPPABLE_PRODUCTION_FEE: 0.3 * 1e18, // Charge 0.5 ETH per basket creation
10+
ARRANGER_FEE: 0.01 * 1e18, // Charge 0.01 ETH per basket minted
1111
FEE_DECIMALS: 18,
1212

1313
// Zero address

contracts/Basket.sol

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ contract Basket is StandardToken {
7777
address _basketRegistryAddress,
7878
address _arranger,
7979
address _arrangerFeeRecipient,
80-
uint _arrangerFee // Amount of ETH charged per basket minted
80+
uint _arrangerFee // in wei, i.e. 1e18 = 1 ETH
8181
) public {
8282
require(_tokens.length > 0 && _tokens.length == _weights.length, "Constructor: invalid number of tokens and weights");
8383

@@ -102,13 +102,13 @@ contract Basket is StandardToken {
102102
for (uint i = 0; i < tokens.length; i++) {
103103
address t = tokens[i];
104104
uint w = weights[i];
105-
assert(ERC20(t).transferFrom(msg.sender, this, w.mul(_quantity).div(10 ** 18)));
105+
assert(ERC20(t).transferFrom(msg.sender, this, w.mul(_quantity).div(10 ** decimals)));
106106
}
107107

108-
// charging market makers a fee for every new basket minted
108+
// charging suppliers a fee for every new basket minted
109109
// skip fees if tokens are minted through swaps
110110
if (arrangerFee > 0) {
111-
require(msg.value >= arrangerFee.mul(_quantity).div(10 ** 18), "Insufficient ETH for arranger fee to bundle");
111+
require(msg.value >= arrangerFee.mul(_quantity).div(10 ** decimals), "Insufficient ETH for arranger fee to bundle");
112112
arrangerFeeRecipient.transfer(msg.value);
113113
} else {
114114
// prevent transfers of unnecessary ether into the contract
@@ -132,7 +132,7 @@ contract Basket is StandardToken {
132132
return true;
133133
}
134134

135-
/// @dev Convert basketTokens back to original tokens and transfer to swap contract and initiate swap
135+
/// @dev Convert basketTokens back to original tokens and transfer to specified recipient
136136
/// @param _quantity Quantity of basket tokens to swap
137137
/// @param _sender Address of transaction sender
138138
/// @param _recipient Address of token recipient
@@ -147,19 +147,19 @@ contract Basket is StandardToken {
147147
balances[_sender] = balances[_sender].sub(_quantity);
148148
totalSupply_ = totalSupply_.sub(_quantity);
149149

150-
// transfer tokens back to holder
150+
// transfer tokens back to _recipient
151151
for (uint i = 0; i < tokens.length; i++) {
152152
address t = tokens[i];
153153
uint w = weights[i];
154-
ERC20(t).transfer(_recipient, w.mul(_quantity).div(10 ** 18));
154+
ERC20(t).transfer(_recipient, w.mul(_quantity).div(10 ** decimals));
155155
}
156156

157157
basketRegistry.incrementBasketsBurned(_quantity, _sender);
158158
return true;
159159
}
160160

161161
/// @dev Allow holder to convert baskets to its underlying tokens and withdraw them individually
162-
/// @param _quantity quantity of tokens to withdraw
162+
/// @param _quantity quantity of tokens to burn
163163
/// @return success Operation successful
164164
function burn(uint _quantity) public returns (bool success) {
165165
balances[msg.sender] = balances[msg.sender].sub(_quantity);
@@ -169,7 +169,7 @@ contract Basket is StandardToken {
169169
for (uint i = 0; i < tokens.length; i++) {
170170
address t = tokens[i];
171171
uint w = weights[i];
172-
outstandingBalance[msg.sender][t] = outstandingBalance[msg.sender][t].add(w.mul(_quantity).div(10 ** 18));
172+
outstandingBalance[msg.sender][t] = outstandingBalance[msg.sender][t].add(w.mul(_quantity).div(10 ** decimals));
173173
}
174174

175175
basketRegistry.incrementBasketsBurned(_quantity, msg.sender);
@@ -182,6 +182,7 @@ contract Basket is StandardToken {
182182
function withdraw(address _token) public returns (bool success) {
183183
uint bal = outstandingBalance[msg.sender][_token];
184184
require(bal > 0);
185+
outstandingBalance[msg.sender][_token] = 0;
185186
assert(ERC20(_token).transfer(msg.sender, bal));
186187

187188
emit LogWithdraw(msg.sender, _token, bal);
@@ -192,6 +193,10 @@ contract Basket is StandardToken {
192193
/// @param _newRecipient New fee recipient
193194
/// @return success Operation successful
194195
function changeArrangerFeeRecipient(address _newRecipient) public onlyArranger returns (bool success) {
196+
require(
197+
_newRecipient != address(0) && _newRecipient != arrangerFeeRecipient,
198+
"New receipient can not be 0x0 or the same as the current recipient"
199+
);
195200
address oldRecipient = arrangerFeeRecipient;
196201
arrangerFeeRecipient = _newRecipient;
197202

contracts/BasketFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,5 @@ contract BasketFactory {
130130
}
131131

132132
/// @dev Fallback to reject any ether sent to contract
133-
function () public payable { revert("BasketFactory do not accept ETH transfers"); }
133+
function () public payable { revert("BasketFactory does not accept ETH transfers"); }
134134
}

contracts/BasketRegistry.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ contract BasketRegistry {
6767
_;
6868
}
6969
modifier onlyBasketFactory {
70-
require(basketFactoryMap[msg.sender] == true, "Only the basket factory can call this function");
70+
require(basketFactoryMap[msg.sender] == true, "Only a basket factory can call this function");
7171
_;
7272
}
7373

@@ -188,5 +188,5 @@ contract BasketRegistry {
188188
}
189189

190190
/// @dev Fallback to reject any ether sent to contract
191-
function () public payable { revert("BasketRegistry do not accept ETH transfers"); }
191+
function () public payable { revert("BasketRegistry does not accept ETH transfers"); }
192192
}

contracts/zeppelin/Pausable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.4.21;
1+
pragma solidity ^0.4.22;
22

33

44
import "./Ownable.sol";

test/2_basket_registry.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ contract('Basket Factory | Basket Registry', (accounts) => {
6969
// check addresses in both contracts have been set correctly
7070
const result = await basketRegistry.whitelistBasketFactory(INVALID_ADDRESS, { from: ADMINISTRATOR });
7171
const _basketFactoryExists = await basketRegistry.basketFactoryMap.call(INVALID_ADDRESS);
72-
console.log(_basketFactoryExists);
7372
assert.strictEqual(_basketFactoryExists, true, 'basket factory address not whitelisted');
7473
} catch (err) { assert.throw(`Failed to set basket factory in registry: ${err.toString()}`); }
7574
});

test/3_exchange_baskets.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ contract('Basket Escrow', (accounts) => {
498498
const escrowBalance = await basketAB.balanceOf(basketEscrow.address);
499499
const sellerBalance = await basketAB.balanceOf(MARKET_MAKER);
500500
assert.strictEqual(Number(escrowBalance), (initialEscrowBasketBal + amountBasketsToSell), 'escrow balance did not increase');
501-
assert.strictEqual(Number(sellerBalance), (initialMMBasketBal - amountBasketsToSell), 'market maker balance did not decrease');
501+
assert.strictEqual(Number(sellerBalance), (initialMMBasketBal - amountBasketsToSell), 'supplier balance did not decrease');
502502
} catch (err) { assert.throw(`Error sending ETH to escrow contract: ${err.toString()}`); }
503503
});
504504

@@ -547,12 +547,12 @@ contract('Basket Escrow', (accounts) => {
547547
} catch (err) { assert.throw(`Error creating buy order: ${err.toString()}`); }
548548
});
549549

550-
it('sends Baskets back to market maker', async () => {
550+
it('sends Baskets back to supplier', async () => {
551551
try {
552552
const escrowBalance = await basketAB.balanceOf(basketEscrow.address);
553553
const sellerBalance = await basketAB.balanceOf(MARKET_MAKER);
554554
assert.strictEqual(Number(escrowBalance), (initialEscrowBasketBal - amountBasketsToSell), 'escrow balance did not decrease');
555-
assert.strictEqual(Number(sellerBalance), (initialMMBasketBal + amountBasketsToSell), 'market maker balance did not increase');
555+
assert.strictEqual(Number(sellerBalance), (initialMMBasketBal + amountBasketsToSell), 'supplier balance did not increase');
556556
} catch (err) { assert.throw(`Error sending ETH to escrow contract: ${err.toString()}`); }
557557
});
558558

0 commit comments

Comments
 (0)