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

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
richardliang committed Feb 18, 2020
1 parent 966906f commit d5217a5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 51 deletions.
2 changes: 1 addition & 1 deletion contracts/core/interfaces/IAddressToAddressWhiteList.sol
Expand Up @@ -32,7 +32,7 @@ interface IAddressToAddressWhiteList {
* @param _key Address to check
* @return bool Whether passed in address is whitelisted
*/
function keysToValues(
function whitelist(
address _key
)
external
Expand Down
23 changes: 15 additions & 8 deletions contracts/core/modules/CTokenExchangeIssuanceModule.sol
Expand Up @@ -21,7 +21,7 @@ import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";

import { CommonMath } from "../../lib/CommonMath.sol";
import { CompoundUtils } from "../../lib/CompoundUtils.sol";
import { CTokenModuleCoreState } from "./lib/CTokenModuleCoreState.sol";
import { CTokenWhiteListed } from "./lib/CTokenWhiteListed.sol";
import { ERC20Wrapper } from "../../lib/ERC20Wrapper.sol";
import { ExchangeIssuanceLibrary } from "./lib/ExchangeIssuanceLibrary.sol";
import { ExchangeIssuanceModule } from "./ExchangeIssuanceModule.sol";
Expand All @@ -40,10 +40,15 @@ import { SetTokenLibrary } from "../lib/SetTokenLibrary.sol";
*/
contract CTokenExchangeIssuanceModule is
ExchangeIssuanceModule,
CTokenModuleCoreState
CTokenWhiteListed
{
using SafeMath for uint256;

/* ============ State Variables ============ */

// Address of transferProxy
address public transferProxy;

/* ============ Constructor ============ */

/**
Expand All @@ -65,11 +70,13 @@ contract CTokenExchangeIssuanceModule is
_core,
_vault
)
CTokenModuleCoreState(
CTokenWhiteListed(
_transferProxy,
_cTokenWhiteList
)
{}
{
transferProxy = _transferProxy;
}

/* ============ Public Functions ============ */

Expand Down Expand Up @@ -240,7 +247,7 @@ contract CTokenExchangeIssuanceModule is
uint256 currentComponentQuantity = _receiveTokenAmounts[i];

// If cToken, calculate required underlying tokens and transfer to module
address underlyingAddress = cTokenWhiteList.keysToValues(currentComponentAddress);
address underlyingAddress = cTokenWhiteList.whitelist(currentComponentAddress);
if (underlyingAddress != address(0)) {
ICToken cTokenInstance = ICToken(currentComponentAddress);

Expand Down Expand Up @@ -292,7 +299,7 @@ contract CTokenExchangeIssuanceModule is

// If cToken and balance of cToken in vault is less than required for issuing the Set
// transfer difference from user and mint cToken
address underlyingAddress = cTokenWhiteList.keysToValues(currentComponentAddress);
address underlyingAddress = cTokenWhiteList.whitelist(currentComponentAddress);
if (underlyingAddress != address(0) && currentComponentQuantity < requiredQuantity) {
// Calculate amount of remaining cTokens needed to issue Set
uint256 quantityToMint = requiredQuantity - currentComponentQuantity;
Expand Down Expand Up @@ -337,7 +344,7 @@ contract CTokenExchangeIssuanceModule is
uint256 currentComponentQuantity = _sendTokenAmounts[i];

// If cToken redeem cToken and replace send token and amounts with underlying
address underlyingAddress = cTokenWhiteList.keysToValues(currentComponentAddress);
address underlyingAddress = cTokenWhiteList.whitelist(currentComponentAddress);
if (underlyingAddress != address(0)) {
// Withdraw cToken send tokens from vault (owned by this contract) to the module and redeem cToken
redeemCToken(currentComponentAddress, currentComponentQuantity);
Expand Down Expand Up @@ -504,7 +511,7 @@ contract CTokenExchangeIssuanceModule is

// Remaining cTokens are redeemed to underlying and all tokens are sent to the caller
if (currentComponentQuantity > 0) {
address underlyingAddress = cTokenWhiteList.keysToValues(currentComponentAddress);
address underlyingAddress = cTokenWhiteList.whitelist(currentComponentAddress);
if (underlyingAddress != address(0)) {
// Withdraw cToken send tokens from vault (owned by this contract) to the module and redeem
redeemCToken(currentComponentAddress, currentComponentQuantity);
Expand Down
Expand Up @@ -21,6 +21,7 @@ import { ReentrancyGuard } from "openzeppelin-solidity/contracts/utils/Reentranc
import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";

import { CommonMath } from "../../lib/CommonMath.sol";
import { CTokenWhiteListed } from "./lib/CTokenWhiteListed.sol";
import { ExchangeIssuanceLibrary } from "./lib/ExchangeIssuanceLibrary.sol";
import { ERC20Wrapper } from "../../lib/ERC20Wrapper.sol";
import { IAddressToAddressWhiteList } from "../interfaces/IAddressToAddressWhiteList.sol";
Expand All @@ -43,15 +44,11 @@ import { RebalancingSetExchangeIssuanceModule } from "./RebalancingSetExchangeIs
* decentralized exchanges. If cToken, the module handles redeeming cToken during redemption process
*/
contract RebalancingSetCTokenExchangeIssuanceModule is
RebalancingSetExchangeIssuanceModule
RebalancingSetExchangeIssuanceModule,
CTokenWhiteListed
{
using SafeMath for uint256;

/* ============ State Variables ============ */

// Address and instance of AddressToAddressWhiteList
IAddressToAddressWhiteList public cTokenWhiteList;

/* ============ Constructor ============ */

/**
Expand Down Expand Up @@ -79,9 +76,11 @@ contract RebalancingSetCTokenExchangeIssuanceModule is
_wrappedEther,
_vault
)
{
cTokenWhiteList = _cTokenWhiteList;
}
CTokenWhiteListed(
address(_transferProxy),
_cTokenWhiteList
)
{}

/* ============ Private Functions ============ */

Expand All @@ -104,7 +103,7 @@ contract RebalancingSetCTokenExchangeIssuanceModule is
address currentComponentAddress = baseSetComponents[i];
uint256 currentComponentQuantity = ERC20Wrapper.balanceOf(baseSetComponents[i], address(this));

address underlyingAddress = cTokenWhiteList.keysToValues(currentComponentAddress);
address underlyingAddress = cTokenWhiteList.whitelist(currentComponentAddress);
if (underlyingAddress != address(0)) {
// Get balance of underlying
uint256 underlyingQuantity = ERC20Wrapper.balanceOf(
Expand Down
10 changes: 5 additions & 5 deletions contracts/core/modules/RebalancingSetCTokenIssuanceModule.sol
Expand Up @@ -21,7 +21,7 @@ import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";

import { CommonMath } from "../../lib/CommonMath.sol";
import { CompoundUtils } from "../../lib/CompoundUtils.sol";
import { CTokenModuleCoreState } from "./lib/CTokenModuleCoreState.sol";
import { CTokenWhiteListed } from "./lib/CTokenWhiteListed.sol";
import { ICToken } from "../interfaces/ICToken.sol";
import { IRebalancingSetToken } from "../interfaces/IRebalancingSetToken.sol";
import { ISetToken } from "../interfaces/ISetToken.sol";
Expand All @@ -40,7 +40,7 @@ import { RebalancingSetIssuanceModule } from "./RebalancingSetIssuanceModule.sol
*/
contract RebalancingSetCTokenIssuanceModule is
RebalancingSetIssuanceModule,
CTokenModuleCoreState
CTokenWhiteListed
{
using SafeMath for uint256;

Expand Down Expand Up @@ -69,7 +69,7 @@ contract RebalancingSetCTokenIssuanceModule is
_transferProxy,
_weth
)
CTokenModuleCoreState(
CTokenWhiteListed(
_transferProxy,
_cTokenWhiteList
)
Expand Down Expand Up @@ -352,7 +352,7 @@ contract RebalancingSetCTokenIssuanceModule is
uint256 currentComponentQuantity = _baseSetQuantity.div(baseSetNaturalUnit).mul(currentUnit);

// If cToken, calculate required underlying tokens and transfer to module
address underlyingAddress = cTokenWhiteList.keysToValues(currentComponentAddress);
address underlyingAddress = cTokenWhiteList.whitelist(currentComponentAddress);
if (underlyingAddress != address(0)) {
// Deposit underlying components and mint cToken
depositAndMintCToken(
Expand Down Expand Up @@ -481,7 +481,7 @@ contract RebalancingSetCTokenIssuanceModule is
);

// If cToken, calculate required underlying tokens and transfer to module
address underlyingAddress = cTokenWhiteList.keysToValues(currentComponentAddress);
address underlyingAddress = cTokenWhiteList.whitelist(currentComponentAddress);
if (underlyingAddress != address(0)) {
// Redeem underlying components send to user
redeemCTokenAndWithdraw(
Expand Down
Expand Up @@ -22,26 +22,23 @@ import { IAddressToAddressWhiteList } from "../../interfaces/IAddressToAddressWh


/**
* @title CTokenModuleCoreState
* @title CTokenWhiteListed
* @author Set Protocol
*
* The CTokenModuleCoreState library maintains Core-related state for modules that interact with cTokens.
* The CTokenWhiteListed library maintains cToken related state for modules that interact with cTokens.
*
*/
contract CTokenModuleCoreState {
contract CTokenWhiteListed {

/* ============ State Variables ============ */

// Address of transferProxy contract
address public transferProxy;

// Address and instance of AddressToAddressWhiteList contract
IAddressToAddressWhiteList public cTokenWhiteList;

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

/**
* Constructor function for CTokenModuleCoreState
* Constructor function for CTokenWhiteListed
*
* @param _transferProxy The address of TransferProxy
* @param _cTokenWhiteList The instance of cTokenWhiteList contract
Expand All @@ -52,9 +49,10 @@ contract CTokenModuleCoreState {
)
public
{
transferProxy = _transferProxy;
// Note: transferProxy is not committed here. Only used for token approvals
cTokenWhiteList = _cTokenWhiteList;

// Note: We do not expect there to be many validAddresses, so we won't hit gas limit
address[] memory cTokenAddresses = _cTokenWhiteList.validAddresses();

for (uint256 i = 0; i < cTokenAddresses.length; i++) {
Expand Down
22 changes: 11 additions & 11 deletions contracts/lib/AddressToAddressWhiteList.sol
Expand Up @@ -38,7 +38,7 @@ contract AddressToAddressWhiteList is
/* ============ State Variables ============ */

address[] public keys;
mapping(address => address) public keysToValues;
mapping(address => address) public whitelist;

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

Expand Down Expand Up @@ -80,7 +80,7 @@ contract AddressToAddressWhiteList is
address keyTypeAddressToAdd = _initialKeys[i];

keys.push(keyTypeAddressToAdd);
keysToValues[keyTypeAddressToAdd] = _initialValues[i];
whitelist[keyTypeAddressToAdd] = _initialValues[i];
}
}

Expand All @@ -101,12 +101,12 @@ contract AddressToAddressWhiteList is
timeLockUpgrade
{
require(
keysToValues[_key] == address(0),
whitelist[_key] == address(0),
"AddressToAddressWhiteList.addPair: Address pair already exists."
);

keys.push(_key);
keysToValues[_key] = _value;
whitelist[_key] = _value;

emit PairAdded(_key, _value);
}
Expand All @@ -122,15 +122,15 @@ contract AddressToAddressWhiteList is
external
onlyOwner
{
address valueTypeAddress = keysToValues[_key];
address valueTypeAddress = whitelist[_key];

require(
valueTypeAddress != address(0),
"AddressToAddressWhiteList.removePair: key type address is not current whitelisted."
);

keys = keys.remove(_key);
keysToValues[_key] = address(0);
whitelist[_key] = address(0);

emit PairRemoved(_key, valueTypeAddress);
}
Expand All @@ -150,12 +150,12 @@ contract AddressToAddressWhiteList is
timeLockUpgrade
{
require(
keysToValues[_key] != address(0),
whitelist[_key] != address(0),
"AddressToAddressWhiteList.editPair: Address pair must exist."
);

// Set new value type address for passed key type address
keysToValues[_key] = _value;
whitelist[_key] = _value;

emit PairAdded(
_key,
Expand Down Expand Up @@ -226,12 +226,12 @@ contract AddressToAddressWhiteList is
{
// Require key to have matching value type address
require(
keysToValues[_key] != address(0),
whitelist[_key] != address(0),
"AddressToAddressWhiteList.getValue: No value for that address."
);

// Return address associated with key
return keysToValues[_key];
return whitelist[_key];
}

/**
Expand All @@ -258,7 +258,7 @@ contract AddressToAddressWhiteList is

for (uint256 i = 0; i < arrayLength; i++) {
// Return false if key type address doesn't have matching value type address
if (keysToValues[_keys[i]] == address(0)) {
if (whitelist[_keys[i]] == address(0)) {
return false;
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/contracts/lib/addressToAddressWhiteList.spec.ts
Expand Up @@ -94,7 +94,7 @@ contract('AddressToAddressWhiteList', accounts => {
expect(addresses).to.deep.equal(subjectInitialKeyTypeAddresses);

subjectInitialKeyTypeAddresses.forEach(async (address, index) => {
const valueTypeAddress = await addressToAddressWhiteList.keysToValues.callAsync(address);
const valueTypeAddress = await addressToAddressWhiteList.whitelist.callAsync(address);
expect(valueTypeAddress).to.equal(subjectInitialValueTypeAddresses[index]);
});
});
Expand Down Expand Up @@ -151,12 +151,12 @@ contract('AddressToAddressWhiteList', accounts => {

it('adds the token address to the whitelist mapping with correct value type address', async () => {
const existingValueTypeAddress =
await addressToAddressWhiteList.keysToValues.callAsync(subjectKeyTypeToAdd);
await addressToAddressWhiteList.whitelist.callAsync(subjectKeyTypeToAdd);
expect(existingValueTypeAddress).to.equal(NULL_ADDRESS);

await subject();

const valueTypeAddress = await addressToAddressWhiteList.keysToValues.callAsync(subjectKeyTypeToAdd);
const valueTypeAddress = await addressToAddressWhiteList.whitelist.callAsync(subjectKeyTypeToAdd);
expect(valueTypeAddress).to.equal(subjectValueTypeToAdd);
});

Expand Down Expand Up @@ -224,12 +224,12 @@ contract('AddressToAddressWhiteList', accounts => {

it('updates the address in the whitelist mapping to null address', async () => {
const existingValueTypeAddress =
await addressToAddressWhiteList.keysToValues.callAsync(subjectKeyToRemove);
await addressToAddressWhiteList.whitelist.callAsync(subjectKeyToRemove);
expect(existingValueTypeAddress).to.equal(thirdValueTypeAddress);

await subject();

const valueTypeAddress = await addressToAddressWhiteList.keysToValues.callAsync(subjectKeyToRemove);
const valueTypeAddress = await addressToAddressWhiteList.whitelist.callAsync(subjectKeyToRemove);
expect(valueTypeAddress).to.equal(NULL_ADDRESS);
});

Expand Down Expand Up @@ -300,12 +300,12 @@ contract('AddressToAddressWhiteList', accounts => {

it('adds the token address to the whitelist mapping with correct value type address', async () => {
const existingValueTypeAddress =
await addressToAddressWhiteList.keysToValues.callAsync(subjectKeyTypeToAdd);
await addressToAddressWhiteList.whitelist.callAsync(subjectKeyTypeToAdd);
expect(existingValueTypeAddress).to.equal(secondValueTypeAddress);

await subject();

const valueTypeAddress = await addressToAddressWhiteList.keysToValues.callAsync(subjectKeyTypeToAdd);
const valueTypeAddress = await addressToAddressWhiteList.whitelist.callAsync(subjectKeyTypeToAdd);
expect(valueTypeAddress).to.equal(subjectValueTypeToAdd);
});

Expand Down

0 comments on commit d5217a5

Please sign in to comment.