Skip to content

Commit

Permalink
Redo marketPause
Browse files Browse the repository at this point in the history
  • Loading branch information
Splidge committed Jun 15, 2021
1 parent 237fd5f commit 78b8eef
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 75 deletions.
8 changes: 1 addition & 7 deletions contracts/RCFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ contract RCFactory is Ownable, NativeMetaTransaction, IRCFactory {
bool public approvedAffilliatesOnly = true;
/// @dev if false, anyone can be an artist
bool public approvedArtistsOnly = true;
/// @dev if true, cards are burnt at the end of events for hidden markets to enforce scarcity
bool public override trapIfUnapproved = true;
/// @dev high level owner who can change the factory address
address public uberOwner;
/// @dev the maximum number of rent collections to perform in a single transaction
Expand Down Expand Up @@ -328,11 +326,6 @@ contract RCFactory is Ownable, NativeMetaTransaction, IRCFactory {
sponsorshipRequired = _amount;
}

/// @notice if true, Cards in unapproved markets can't be upgraded
function changeTrapCardsIfUnapproved() external onlyOwner {
trapIfUnapproved = !trapIfUnapproved;
}

/// @notice market opening time must be at least this many seconds in the future
/// @param _newAdvancedWarning the warning time to set in seconds
function setAdvancedWarning(uint32 _newAdvancedWarning) external onlyOwner {
Expand Down Expand Up @@ -388,6 +381,7 @@ contract RCFactory is Ownable, NativeMetaTransaction, IRCFactory {
IRCMarket _marketToApprove = IRCMarket(_market);
assert(_marketToApprove.isMarket());
isMarketApproved[_market] = !isMarketApproved[_market];
treasury.unPauseMarket(_market);
emit LogMarketApproved(_market, isMarketApproved[_market]);
}

Expand Down
11 changes: 7 additions & 4 deletions contracts/RCMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,12 @@ contract RCMarket is Initializable, NativeMetaTransaction, IRCMarket {
╚═════════════════════════════════╝*/

/// @notice send NFT to mainnet
/// @dev upgrades not possible if market not approved
/// @dev upgrades not possible if market paused
function upgradeCard(uint256 _card) external onlyTokenOwner(_card) {
_checkState(States.WITHDRAW);
require(
!factory.trapIfUnapproved() ||
factory.isMarketApproved(address(this)),
"Upgrade blocked"
!treasury.marketPaused(address(this)) && !treasury.globalPause(),
"Market is Paused"
);
uint256 _tokenId = _card + totalNftMintCount;
_transferCard(ownerOf(_card), address(this), _card); // contract becomes final resting place
Expand Down Expand Up @@ -494,6 +493,10 @@ contract RCMarket is Initializable, NativeMetaTransaction, IRCMarket {
function claimCard(uint256 _card) external {
_checkNotState(States.CLOSED);
_checkNotState(States.OPEN);
require(
!treasury.marketPaused(address(this)) && !treasury.globalPause(),
"Market is Paused"
);
require(!userAlreadyClaimed[_card][msgSender()], "Already claimed");
userAlreadyClaimed[_card][msgSender()] = true;
require(longestOwner[_card] == msgSender(), "Not longest owner");
Expand Down
24 changes: 21 additions & 3 deletions contracts/RCTreasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ contract RCTreasury is Ownable, NativeMetaTransaction, IRCTreasury {
bool public override globalPause;
/// @dev if true, cannot rent any cards for specific market
mapping(address => bool) public override marketPaused;
/// @dev if true, owner has locked the market pause
mapping(address => bool) public override lockMarketPaused;

/*╔═════════════════════════════════╗
║ UBER OWNER ║
Expand Down Expand Up @@ -150,6 +152,8 @@ contract RCTreasury is Ownable, NativeMetaTransaction, IRCTreasury {
/// @dev so only markets can move funds from deposits to marketPots and vice versa
function addMarket(address _newMarket) external override {
require(msgSender() == factoryAddress, "Not factory");
// default to paused
marketPaused[_newMarket] = true;
isMarket[_newMarket] = true;
}

Expand Down Expand Up @@ -190,10 +194,24 @@ contract RCTreasury is Ownable, NativeMetaTransaction, IRCTreasury {
emit LogGlobalPause(globalPause);
}

/// @notice if true, cannot make a new rental for a specific market
function changePauseMarket(address _market) external override onlyOwner {
/// @notice if true, cannot make a new rental, or claim the NFT for a specific market
function changePauseMarket(address _market, bool _paused)
external
override
onlyOwner
{
require(isMarket[_market], "This isn't a market");
marketPaused[_market] = _paused;
lockMarketPaused[_market] = marketPaused[_market];
emit LogMarketPaused(_market, marketPaused[_market]);
}

/// @notice allow governance to approve and un pause the market if the owner hasn't paused it
function unPauseMarket(address _market) external override {
require(msgSender() == factoryAddress, "Not factory");
require(isMarket[_market], "This isn't a market");
marketPaused[_market] = !marketPaused[_market];
require(!lockMarketPaused[_market], "Owner has paused market");
marketPaused[_market] = false;
emit LogMarketPaused(_market, marketPaused[_market]);
}

Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/IRCFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ interface IRCFactory {

function minimumPriceIncreasePercent() external returns (uint256);

function trapIfUnapproved() external returns (bool);

function isMarketApproved(address) external returns (bool);

function maxRentIterations() external returns (uint256);
Expand Down
6 changes: 5 additions & 1 deletion contracts/interfaces/IRCTreasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ interface IRCTreasury {

function marketPaused(address) external view returns (bool);

function lockMarketPaused(address _market) external view returns (bool);

function unPauseMarket(address _market) external;

function uberOwner() external view returns (address);

function addMarket(address) external;
Expand All @@ -48,7 +52,7 @@ interface IRCTreasury {

function changeGlobalPause() external;

function changePauseMarket(address _market) external;
function changePauseMarket(address _market, bool _paused) external;

function setFactoryAddress(address _newFactory) external;

Expand Down
55 changes: 4 additions & 51 deletions test/OldTests/testsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ contract('TestFactory', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
});

async function createMarketWithArtistSet() {
Expand Down Expand Up @@ -150,6 +151,7 @@ contract('TestFactory', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(mode);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand All @@ -176,6 +178,7 @@ contract('TestFactory', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(mode);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down Expand Up @@ -346,6 +349,7 @@ contract('TestFactory', (accounts) => {


it('test changeMarketApproval', async () => {
await rcfactory.changeMarketApproval(realitycards.address);
// first, check that recent market is hidden
var hidden = await rcfactory.isMarketApproved.call(realitycards.address);
assert.equal(hidden, false);
Expand All @@ -360,47 +364,6 @@ contract('TestFactory', (accounts) => {
await rcfactory.changeMarketApproval(realitycards.address, { from: user1 });
hidden = await rcfactory.isMarketApproved.call(realitycards.address);
assert.equal(hidden, false);
await depositDai(100, user0);
for (i = 0; i < 10; i++) {
await newRental(1, i, user0);
}
await time.increase(time.duration.minutes(1));
await realitycards.collectRentAllCards();
await realitio.setResult(2);
await time.increase(time.duration.years(1));
await realitycards.lockMarket();
await realitycards.getWinnerFromOracle();
// await realitycards.determineWinner();
for (i = 0; i < 10; i++) {
await realitycards.claimCard(i, { from: user0 });
}
for (i = 0; i < 10; i++) {
await expectRevert(realitycards.upgradeCard(i), "Upgrade blocked");
}
// new market, dont approve it, but switch changeTrapCardsIfUnapproved to false
realitycards2 = await createMarketWithArtistSet();
await depositDai(100, user0);
for (i = 0; i < 10; i++) {
await newRentalCustomContract(realitycards2, 1, i, user0);
}
await time.increase(time.duration.minutes(1));
await realitycards2.collectRentAllCards();
hidden = await rcfactory.isMarketApproved.call(realitycards2.address);
assert.equal(hidden, false);
await rcfactory.changeTrapCardsIfUnapproved();
var trapIfUnapproved = await rcfactory.trapIfUnapproved.call();
assert.equal(trapIfUnapproved, false);
await time.increase(time.duration.years(1));
await realitycards2.lockMarket();
await realitycards2.getWinnerFromOracle();
// await realitycards2.determineWinner();
for (i = 0; i < 10; i++) {
await realitycards2.claimCard(i, { from: user0 });
}
for (i = 0; i < 10; i++) {
await realitycards2.upgradeCard(i);
}
await time.increase(time.duration.minutes(10));
});


Expand Down Expand Up @@ -485,16 +448,6 @@ contract('TestFactory', (accounts) => {
await expectRevert(rcfactory.changeCardAffiliateApproval(user4, { from: user2 }), "Not approved");
});

it('test changeTrapCardsIfUnapproved', async () => {
// check the value
assert.equal(await rcfactory.trapIfUnapproved(), true);
// change it
await rcfactory.changeTrapCardsIfUnapproved();
//check it again
assert.equal(await rcfactory.trapIfUnapproved(), false);
// change it back
await rcfactory.changeTrapCardsIfUnapproved();
});
it('test getAllMarkets', async () => {
// check the value
var marketArray = await rcfactory.getAllMarkets(0);
Expand Down
6 changes: 6 additions & 0 deletions test/OldTests/testsFullFlowInvalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ contract('TestFullFlowInvalid', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
});

async function createMarketWithArtistSet() {
Expand Down Expand Up @@ -124,6 +125,7 @@ contract('TestFullFlowInvalid', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand All @@ -150,6 +152,7 @@ contract('TestFullFlowInvalid', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(mode);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down Expand Up @@ -182,6 +185,7 @@ contract('TestFullFlowInvalid', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down Expand Up @@ -210,6 +214,7 @@ contract('TestFullFlowInvalid', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(mode);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down Expand Up @@ -244,6 +249,7 @@ contract('TestFullFlowInvalid', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down
8 changes: 8 additions & 0 deletions test/OldTests/testsFullFlowValid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
const { current } = require("@openzeppelin/test-helpers/src/balance");
const { initial } = require("underscore");
const { ZERO_ADDRESS } = require('@openzeppelin/test-helpers/src/constants');
const { factory } = require("typescript");

// main contracts
var RCFactory = artifacts.require("./RCFactory.sol");
Expand Down Expand Up @@ -118,6 +119,7 @@ contract("TestFullFlowValid", (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
});

async function createMarketWithArtistSet() {
Expand Down Expand Up @@ -145,6 +147,7 @@ contract("TestFullFlowValid", (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand All @@ -171,6 +174,7 @@ contract("TestFullFlowValid", (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(mode);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down Expand Up @@ -224,6 +228,7 @@ contract("TestFullFlowValid", (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down Expand Up @@ -252,6 +257,7 @@ contract("TestFullFlowValid", (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(mode);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down Expand Up @@ -307,6 +313,7 @@ contract("TestFullFlowValid", (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down Expand Up @@ -368,6 +375,7 @@ contract("TestFullFlowValid", (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down
2 changes: 2 additions & 0 deletions test/OldTests/testsFundamentals.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ contract('TestFundamentals', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
});

async function createMarketWithArtistSet() {
Expand Down Expand Up @@ -124,6 +125,7 @@ contract('TestFundamentals', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down
2 changes: 2 additions & 0 deletions test/OldTests/testsNftHubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ contract('TestNftHubs', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
});

async function createMarketWithArtistSet() {
Expand Down Expand Up @@ -124,6 +125,7 @@ contract('TestNftHubs', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards2 = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
return realitycards2;
}

Expand Down
1 change: 1 addition & 0 deletions test/OldTests/testsOrderbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ contract('TestOrderbook', (accounts) => {
);
var marketAddress = await rcfactory.getMostRecentMarket.call(0);
realitycards = await RCMarket.at(marketAddress);
await rcfactory.changeMarketApproval(marketAddress);
});

async function createMarketWithArtistSet() {
Expand Down
Loading

0 comments on commit 78b8eef

Please sign in to comment.