Include threshold balance in constructor of BalanceThresholdFilter contract

This commit is contained in:
Greg Hysen
2018-12-04 16:15:35 -08:00
parent 58a382d9b6
commit 14c97b3ec3
4 changed files with 21 additions and 2 deletions

View File

@@ -26,10 +26,19 @@ import "./MixinBalanceThresholdFilterCore.sol";
contract BalanceThresholdFilter is MixinBalanceThresholdFilterCore { contract BalanceThresholdFilter is MixinBalanceThresholdFilterCore {
constructor(address exchange, address thresholdAsset) /// @dev Constructs BalanceThresholdFilter.
/// @param exchange Address of 0x exchange.
/// @param thresholdAsset The asset that must be held by makers/takers.
/// @param thresholdBalance The minimum balance of `thresholdAsset` that must be held by makers/takers.
constructor(
address exchange,
address thresholdAsset,
uint256 thresholdBalance
)
public public
{ {
EXCHANGE = IExchange(exchange); EXCHANGE = IExchange(exchange);
THRESHOLD_ASSET = IThresholdAsset(thresholdAsset); THRESHOLD_ASSET = IThresholdAsset(thresholdAsset);
THRESHOLD_BALANCE = thresholdBalance;
} }
} }

View File

@@ -263,6 +263,7 @@ contract MixinBalanceThresholdFilterCore is MBalanceThresholdFilterCore {
// Validate addresses // Validate addresses
let thresholdAssetAddress := sload(THRESHOLD_ASSET_slot) let thresholdAssetAddress := sload(THRESHOLD_ASSET_slot)
let thresholdBalance := sload(THRESHOLD_BALANCE_slot)
for {let addressToValidate := addressesToValidateElementPtr} lt(addressToValidate, addressesToValidateElementEndPtr) {addressToValidate := add(addressToValidate, 0x20)} { for {let addressToValidate := addressesToValidateElementPtr} lt(addressToValidate, addressesToValidateElementEndPtr) {addressToValidate := add(addressToValidate, 0x20)} {
// Construct calldata for `THRESHOLD_ASSET.balanceOf` // Construct calldata for `THRESHOLD_ASSET.balanceOf`
mstore(freeMemPtr, 0x70a0823100000000000000000000000000000000000000000000000000000000) mstore(freeMemPtr, 0x70a0823100000000000000000000000000000000000000000000000000000000)
@@ -294,7 +295,7 @@ contract MixinBalanceThresholdFilterCore is MBalanceThresholdFilterCore {
// Revert if balance not held // Revert if balance not held
let addressBalance := mload(freeMemPtr) let addressBalance := mload(freeMemPtr)
if eq(addressBalance, 0) { if lt(addressBalance, thresholdBalance) {
// Revert with `Error("AT_LEAST_ONE_ADDRESS_DOES_NOT_MEET_BALANCE_THRESHOLD")` // Revert with `Error("AT_LEAST_ONE_ADDRESS_DOES_NOT_MEET_BALANCE_THRESHOLD")`
mstore(0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000) mstore(0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000)
mstore(0x20, 0x0000002000000000000000000000000000000000000000000000000000000000) mstore(0x20, 0x0000002000000000000000000000000000000000000000000000000000000000)

View File

@@ -25,9 +25,16 @@ import "../interfaces/IThresholdAsset.sol";
contract MBalanceThresholdFilterCore { contract MBalanceThresholdFilterCore {
// Points to 0x exchange contract
IExchange internal EXCHANGE; IExchange internal EXCHANGE;
// The asset that must be held by makers/takers
IThresholdAsset internal THRESHOLD_ASSET; IThresholdAsset internal THRESHOLD_ASSET;
// The minimum balance of `THRESHOLD_ASSET` that must be held by makers/takers
uint256 internal THRESHOLD_BALANCE;
// Addresses that hold at least `THRESHOLD_BALANCE` of `THRESHOLD_ASSET`
event ValidatedAddresses ( event ValidatedAddresses (
address[] addresses address[] addresses
); );

View File

@@ -126,12 +126,14 @@ describe.only(ContractName.BalanceThresholdFilter, () => {
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(compliantMakerAddress)]; const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(compliantMakerAddress)];
orderFactory = new OrderFactory(privateKey, defaultOrderParams); orderFactory = new OrderFactory(privateKey, defaultOrderParams);
// Deploy Compliant Forwarder // Deploy Compliant Forwarder
const erc721BalanceThreshold = new BigNumber(1);
compliantForwarderInstance = await BalanceThresholdFilterContract.deployFrom0xArtifactAsync( compliantForwarderInstance = await BalanceThresholdFilterContract.deployFrom0xArtifactAsync(
artifacts.BalanceThresholdFilter, artifacts.BalanceThresholdFilter,
provider, provider,
txDefaults, txDefaults,
exchangeInstance.address, exchangeInstance.address,
yesTokenInstance.address, yesTokenInstance.address,
erc721BalanceThreshold
); );
/* /*
const compliantForwarderContract = new BalanceThresholdFilterContract( const compliantForwarderContract = new BalanceThresholdFilterContract(