Skip to content

Commit

Permalink
remove gas bond
Browse files Browse the repository at this point in the history
  • Loading branch information
nuevoalex committed Jul 5, 2018
1 parent 0e9aeb3 commit 92abeca
Show file tree
Hide file tree
Showing 16 changed files with 7 additions and 173 deletions.
23 changes: 0 additions & 23 deletions source/contracts/libraries/math/RunningAverage.sol

This file was deleted.

15 changes: 0 additions & 15 deletions source/contracts/reporting/FeeWindow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'trading/ICash.sol';
import 'factories/MarketFactory.sol';
import 'reporting/Reporting.sol';
import 'libraries/math/SafeMathUint256.sol';
import 'libraries/math/RunningAverage.sol';
import 'reporting/IFeeWindow.sol';
import 'libraries/token/VariableSupplyToken.sol';
import 'reporting/IFeeToken.sol';
Expand All @@ -22,7 +21,6 @@ import 'factories/FeeTokenFactory.sol';

contract FeeWindow is DelegationTarget, VariableSupplyToken, Initializable, IFeeWindow {
using SafeMathUint256 for uint256;
using RunningAverage for RunningAverage.Data;

string constant public name = "Participation Token";
string constant public symbol = "PT";
Expand All @@ -34,7 +32,6 @@ contract FeeWindow is DelegationTarget, VariableSupplyToken, Initializable, IFee
uint256 private invalidMarketsCount;
uint256 private incorrectDesignatedReportMarketCount;
uint256 private designatedReportNoShows;
RunningAverage.Data private reportingGasPrice;
uint256 private totalWinningStake;
uint256 private totalStake;
IFeeToken private feeToken;
Expand All @@ -43,18 +40,10 @@ contract FeeWindow is DelegationTarget, VariableSupplyToken, Initializable, IFee
endInitialization();
universe = _universe;
startTime = _feeWindowId.mul(universe.getDisputeRoundDurationInSeconds());
// Initialize this to some reasonable value to handle the first market ever created without branching code
reportingGasPrice.record(Reporting.getDefaultReportingGasPrice());
feeToken = FeeTokenFactory(controller.lookup("FeeTokenFactory")).createFeeToken(controller, this);
return true;
}

function noteInitialReportingGasPrice() public onlyInGoodTimes afterInitialized returns (bool) {
require(universe.isContainerForReportingParticipant(IReportingParticipant(msg.sender)));
reportingGasPrice.record(tx.gasprice);
return true;
}

function onMarketFinalized() public onlyInGoodTimes afterInitialized returns (bool) {
IMarket _market = IMarket(msg.sender);
require(universe.isContainerForMarket(_market));
Expand Down Expand Up @@ -163,10 +152,6 @@ contract FeeWindow is DelegationTarget, VariableSupplyToken, Initializable, IFee
return _totalParticipationSupply.add(_totalFeeSupply);
}

function getAvgReportingGasPrice() public view returns (uint256) {
return reportingGasPrice.currentAverage();
}

function getTypeName() public afterInitialized view returns (bytes32) {
return "FeeWindow";
}
Expand Down
2 changes: 0 additions & 2 deletions source/contracts/reporting/IFeeWindow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import 'libraries/token/ERC20.sol';

contract IFeeWindow is ITyped, ERC20 {
function initialize(IUniverse _universe, uint256 _feeWindowId) public returns (bool);
function noteInitialReportingGasPrice() public returns (bool);
function getUniverse() public view returns (IUniverse);
function getReputationToken() public view returns (IReputationToken);
function getStartTime() public view returns (uint256);
function getEndTime() public view returns (uint256);
function getNumMarkets() public view returns (uint256);
function getNumInvalidMarkets() public view returns (uint256);
function getNumIncorrectDesignatedReportMarkets() public view returns (uint256);
function getAvgReportingGasPrice() public view returns (uint256);
function getNumDesignatedReportNoShows() public view returns (uint256);
function getFeeToken() public view returns (IFeeToken);
function isActive() public view returns (bool);
Expand Down
1 change: 0 additions & 1 deletion source/contracts/reporting/IUniverse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ contract IUniverse is ITyped {
function getDisputeThresholdForFork() public view returns (uint256);
function getInitialReportMinValue() public view returns (uint256);
function calculateFloatingValue(uint256 _badMarkets, uint256 _totalMarkets, uint256 _targetDivisor, uint256 _previousValue, uint256 _defaultValue, uint256 _floor) public pure returns (uint256 _newValue);
function getOrCacheTargetReporterGasCosts() public returns (uint256);
function getOrCacheMarketCreationCost() public returns (uint256);
function getCurrentFeeWindow() public view returns (IFeeWindow);
function getOrCreateFeeWindowBefore(IFeeWindow _feeWindow) public returns (IFeeWindow);
Expand Down
1 change: 0 additions & 1 deletion source/contracts/reporting/InitialReporter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ contract InitialReporter is DelegationTarget, Ownable, BaseReportingParticipant,
payoutNumerators = _payoutNumerators;
size = reputationToken.balanceOf(this);
feeWindow = market.getFeeWindow();
feeWindow.noteInitialReportingGasPrice();
feeWindow.mintFeeTokens(size);
return true;
}
Expand Down
12 changes: 2 additions & 10 deletions source/contracts/reporting/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ contract Market is DelegationTarget, ITyped, Initializable, Ownable, IMarket {
uint256 private numOutcomes;
bytes32 private winningPayoutDistributionHash;
uint256 private validityBondAttoeth;
uint256 private reporterGasCostsFeeAttoeth;
IMailbox private marketCreatorMailbox;
uint256 private finalizationTime;

Expand Down Expand Up @@ -84,8 +83,8 @@ contract Market is DelegationTarget, ITyped, Initializable, Ownable, IMarket {
shareTokens.push(createShareToken(_outcome));
}
approveSpenders();
// If the value was not at least equal to the sum of these fees this will throw. The addition here cannot overflow as these fees are capped
uint256 _refund = msg.value.sub(reporterGasCostsFeeAttoeth + validityBondAttoeth);
// If the value was not at least equal to this fee this will throw. The addition here cannot overflow as these fees are capped
uint256 _refund = msg.value.sub(validityBondAttoeth);
if (_refund > 0) {
owner.transfer(_refund);
}
Expand All @@ -94,7 +93,6 @@ contract Market is DelegationTarget, ITyped, Initializable, Ownable, IMarket {

function assessFees() private onlyInGoodTimes returns (bool) {
require(getReputationToken().balanceOf(this) >= universe.getOrCacheDesignatedReportNoShowBond());
reporterGasCostsFeeAttoeth = universe.getOrCacheTargetReporterGasCosts();
validityBondAttoeth = universe.getOrCacheValidityBond();
return true;
}
Expand Down Expand Up @@ -230,10 +228,8 @@ contract Market is DelegationTarget, ITyped, Initializable, Ownable, IMarket {
// If the designated reporter showed up return the no show bond to the market creator. Otherwise it will be used as stake in the first report.
if (_reporter == _initialReporter.getDesignatedReporter()) {
require(_reputationToken.transfer(owner, _repBalance));
marketCreatorMailbox.depositEther.value(reporterGasCostsFeeAttoeth)();
} else {
require(_reputationToken.transfer(_initialReporter, _repBalance));
cash.depositEtherFor.value(reporterGasCostsFeeAttoeth)(_initialReporter);
}
return true;
}
Expand Down Expand Up @@ -470,10 +466,6 @@ contract Market is DelegationTarget, ITyped, Initializable, Ownable, IMarket {
return validityBondAttoeth;
}

function getReporterGasCostsFeeAttoeth() public view returns (uint256) {
return reporterGasCostsFeeAttoeth;
}

function derivePayoutDistributionHash(uint256[] _payoutNumerators, bool _invalid) public view returns (bytes32) {
uint256 _sum = 0;
uint256 _previousValue = _payoutNumerators[0];
Expand Down
6 changes: 0 additions & 6 deletions source/contracts/reporting/Reporting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ library Reporting {
uint256 private constant MAXIMUM_REPORTING_FEE_DIVISOR = 10000; // Minimum .01% fees
uint256 private constant MINIMUM_REPORTING_FEE_DIVISOR = 3; // Maximum 33.3~% fees. Note than anything less than a value of 2 here will likely result in bugs such as divide by 0 cases.

// NOTE: We need to maintain this cost to roughly match the gas cost of reporting. This was last updated 12/22/2017
uint256 private constant GAS_TO_REPORT = 1500000;
uint256 private constant DEFAULT_REPORTING_GAS_PRICE = 5000000000;

uint256 private constant TARGET_INVALID_MARKETS_DIVISOR = 100; // 1% of markets are expected to be invalid
uint256 private constant TARGET_INCORRECT_DESIGNATED_REPORT_MARKETS_DIVISOR = 100; // 1% of markets are expected to have an incorrect designate report
uint256 private constant TARGET_DESIGNATED_REPORT_NO_SHOWS_DIVISOR = 100; // 1% of markets are expected to have an incorrect designate report
Expand All @@ -31,8 +27,6 @@ library Reporting {
function getDisputeRoundDurationSeconds() internal pure returns (uint256) { return DISPUTE_ROUND_DURATION_SECONDS; }
function getClaimTradingProceedsWaitTime() internal pure returns (uint256) { return CLAIM_PROCEEDS_WAIT_TIME; }
function getForkDurationSeconds() internal pure returns (uint256) { return FORK_DURATION_SECONDS; }
function getGasToReport() internal pure returns (uint256) { return GAS_TO_REPORT; }
function getDefaultReportingGasPrice() internal pure returns (uint256) { return DEFAULT_REPORTING_GAS_PRICE; }
function getDefaultValidityBond() internal pure returns (uint256) { return DEFAULT_VALIDITY_BOND; }
function getValidityBondFloor() internal pure returns (uint256) { return VALIDITY_BOND_FLOOR; }
function getTargetInvalidMarketsDivisor() internal pure returns (uint256) { return TARGET_INVALID_MARKETS_DIVISOR; }
Expand Down
17 changes: 1 addition & 16 deletions source/contracts/reporting/Universe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,8 @@ contract Universe is DelegationTarget, ITyped, Initializable, IUniverse {
return _currentFeeDivisor;
}

function getOrCacheTargetReporterGasCosts() public onlyInGoodTimes returns (uint256) {
IFeeWindow _feeWindow = getOrCreateCurrentFeeWindow();
IFeeWindow _previousFeeWindow = getOrCreatePreviousFeeWindow();
uint256 _getGasToReport = targetReporterGasCosts[_feeWindow];
if (_getGasToReport != 0) {
return _getGasToReport;
}

uint256 _avgGasPrice = _previousFeeWindow.getAvgReportingGasPrice();
_getGasToReport = Reporting.getGasToReport();
// we double it to try and ensure we have more than enough rather than not enough
targetReporterGasCosts[_feeWindow] = _getGasToReport.mul(_avgGasPrice).mul(2);
return targetReporterGasCosts[_feeWindow];
}

function getOrCacheMarketCreationCost() public onlyInGoodTimes returns (uint256) {
return getOrCacheValidityBond().add(getOrCacheTargetReporterGasCosts());
return getOrCacheValidityBond();
}

function getInitialReportStakeSize() public onlyInGoodTimes returns (uint256) {
Expand Down
8 changes: 3 additions & 5 deletions tests/reporting/test_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ def test_initialReport_methods(localFixture, universe, market, cash, constants):
expectedRep = initialReporter.getStake()
owner = initialReporter.getOwner()

expectedGasBond = 2 * constants.GAS_TO_REPORT() * constants.DEFAULT_REPORTING_GAS_PRICE()
with EtherDelta(expectedGasBond, owner, localFixture.chain, "Initial reporter did not get the reporting gas cost bond"):
with TokenDelta(reputationToken, expectedRep, owner, "Redeeming didn't refund REP"):
assert initialReporter.redeem(owner)
with TokenDelta(reputationToken, expectedRep, owner, "Redeeming didn't refund REP"):
assert initialReporter.redeem(owner)

@mark.parametrize('rounds', [
2,
Expand Down Expand Up @@ -518,4 +516,4 @@ def localFixture(fixture, localSnapshot):

@fixture
def constants(localFixture, kitchenSinkSnapshot):
return localFixture.contracts['Constants']
return localFixture.contracts['Constants']
49 changes: 0 additions & 49 deletions tests/reporting/test_universe_fee_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,6 @@ def test_floating_amount_calculation(numWithCondition, targetWithConditionPerHun
newAmount = universe.calculateFloatingValue(numWithCondition, 100, targetDivisor, previousAmount, contractsFixture.contracts['Constants'].DEFAULT_VALIDITY_BOND(), ONE / 100)
assert newAmount == expectedValue

def test_default_target_reporter_gas_costs(contractsFixture, universe, market):
# The target reporter gas cost is an attempt to charge the market creator for the estimated cost of reporting that may occur for their market. With no previous fee window to base costs off of it assumes basic default values

targetReporterGasCosts = universe.getOrCacheTargetReporterGasCosts()
expectedTargetReporterGasCost = contractsFixture.contracts['Constants'].GAS_TO_REPORT()
expectedTargetReporterGasCost *= contractsFixture.contracts['Constants'].DEFAULT_REPORTING_GAS_PRICE()
expectedTargetReporterGasCost *= 2
assert targetReporterGasCosts == expectedTargetReporterGasCost

@mark.parametrize('numReports, gasPrice', [
(1, 1),
(2, 1),
(3, 1),
(3, 1),
(2, 10),
(2, 20),
(2, 100),
])
def test_initial_reporter_gas_costs(numReports, gasPrice, reportingFixture, universe, market, categoricalMarket, scalarMarket):
markets = [market, categoricalMarket, scalarMarket]

# We'll have the markets go to initial reporting
proceedToInitialReporting(reportingFixture, market)

for i in range(0, numReports):
curMarket = markets[i]
payoutNumerators = [0] * curMarket.getNumberOfOutcomes()
payoutNumerators[0] = curMarket.getNumTicks()
assert curMarket.doInitialReport(payoutNumerators, False, sender=tester.k1, gasprice=gasPrice)

# The target reporter gas cost is an attempt to charge the market creator for the estimated cost of reporting that may occur for their market. It will use the previous fee window's data to estimate costs if it is available
feeWindow = reportingFixture.applySignature('FeeWindow', market.getFeeWindow())

# Now we'll skip ahead in time and finalize the market
reportingFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
for i in range(0, numReports):
assert markets[i].finalize()

actualAvgGasPrice = feeWindow.getAvgReportingGasPrice()
expectedAvgReportingGasCost = (reportingFixture.contracts['Constants'].DEFAULT_REPORTING_GAS_PRICE() + gasPrice * numReports) / (numReports + 1)
assert actualAvgGasPrice == expectedAvgReportingGasCost

# Confirm our estimated gas cost is caluclated as expected
expectedTargetReporterGasCost = reportingFixture.contracts['Constants'].GAS_TO_REPORT()
expectedTargetReporterGasCost *= expectedAvgReportingGasCost
expectedTargetReporterGasCost *= 2
targetReporterGasCosts = universe.getOrCacheTargetReporterGasCosts()
assert targetReporterGasCosts == expectedTargetReporterGasCost

def test_reporter_fees(contractsFixture, universe, market):
defaultValue = 100
completeSets = contractsFixture.contracts['CompleteSets']
Expand Down
2 changes: 0 additions & 2 deletions tests/reporting/test_universe_redeem.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ def test_redeem_reporting_participants(kitchenSinkFixture, market, categoricalMa
expectedRep = long(winningDisputeCrowdsourcer2.getStake() + winningDisputeCrowdsourcer1.getStake())
expectedRep = long(expectedRep + expectedRep / 2)
expectedRep += long(initialReporter.getStake() + initialReporter.getStake() / 2)
expectedGasBond = 2 * constants.GAS_TO_REPORT() * constants.DEFAULT_REPORTING_GAS_PRICE()
with TokenDelta(reputationToken, expectedRep, tester.a0, "Redeeming didn't refund REP"):
with PrintGasUsed(kitchenSinkFixture, "Universe Redeem:", 0):
assert universe.redeemStake([initialReporter.address, winningDisputeCrowdsourcer1.address, winningDisputeCrowdsourcer2.address], [])

4 changes: 0 additions & 4 deletions tests/solidity_test_helpers/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ contract Constants {
uint256 public constant MAXIMUM_REPORTING_FEE_DIVISOR = Reporting.getMaximumReportingFeeDivisor();
uint256 public constant MINIMUM_REPORTING_FEE_DIVISOR = Reporting.getMinimumReportingFeeDivisor();

// NOTE: We need to maintain this cost to roughly match the gas cost of reporting. This was last updated 10/02/2017
uint256 public constant GAS_TO_REPORT = Reporting.getGasToReport();
uint256 public constant DEFAULT_REPORTING_GAS_PRICE = Reporting.getDefaultReportingGasPrice();

uint256 public constant TARGET_INVALID_MARKETS_DIVISOR = Reporting.getTargetInvalidMarketsDivisor();
uint256 public constant TARGET_INCORRECT_DESIGNATED_REPORT_MARKETS_DIVISOR = Reporting.getTargetIncorrectDesignatedReportMarketsDivisor();
uint256 public constant TARGET_DESIGNATED_REPORT_NO_SHOWS_DIVISOR = Reporting.getTargetDesignatedReportNoShowsDivisor();
Expand Down
18 changes: 0 additions & 18 deletions tests/solidity_test_helpers/MockFeeWindow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ contract MockFeeWindow is Initializable, MockVariableSupplyToken, IFeeWindow {
bool private setMigrateMarketInFromSiblingValue;
bool private setMigrateMarketInFromNiblingValue;
bool private setRemoveMarketValue;
bool private setNoteReportingGasPriceValue;
bool private setUpdateMarketPhaseValue;
IUniverse private universe;
IReputationToken private setReputationTokenValue;
Expand All @@ -23,7 +22,6 @@ contract MockFeeWindow is Initializable, MockVariableSupplyToken, IFeeWindow {
uint256 private setNumMarketsValue;
uint256 private setNumInvalidMarketsValue;
uint256 private setNumIncorrectDesignatedReportMarketsValue;
uint256 private setAvgReportingGasPriceValue;
IFeeWindow private setNextFeeWindowValue;
IFeeWindow private setPreviousFeeWindowValue;
uint256 private setNumDesignatedReportNoShowsValue;
Expand Down Expand Up @@ -70,10 +68,6 @@ contract MockFeeWindow is Initializable, MockVariableSupplyToken, IFeeWindow {
return setRemoveMarketValue;
}

function setNoteReportingGasPrice(bool _setNoteReportingGasPriceValue) public {
setNoteReportingGasPriceValue = _setNoteReportingGasPriceValue;
}

function getUpdateMarketPhaseCalled() public returns(bool) {
return setUpdateMarketPhaseValue;
}
Expand Down Expand Up @@ -110,10 +104,6 @@ contract MockFeeWindow is Initializable, MockVariableSupplyToken, IFeeWindow {
setNumIncorrectDesignatedReportMarketsValue = _setNumIncorrectDesignatedReportMarketsValue;
}

function setAvgReportingGasPrice(uint256 _setAvgReportingGasPriceValue) public {
setAvgReportingGasPriceValue = _setAvgReportingGasPriceValue;
}

function setNextFeeWindow(IFeeWindow _setNextFeeWindowValue) public {
setNextFeeWindowValue = _setNextFeeWindowValue;
}
Expand Down Expand Up @@ -227,10 +217,6 @@ contract MockFeeWindow is Initializable, MockVariableSupplyToken, IFeeWindow {
return true;
}

function noteReportingGasPrice(IMarket _market) public returns (bool) {
return setNoteReportingGasPriceValue;
}

function noteDesignatedReport() public returns (bool) {
setNoteDesignatedReportValue = true;
return true;
Expand Down Expand Up @@ -269,10 +255,6 @@ contract MockFeeWindow is Initializable, MockVariableSupplyToken, IFeeWindow {
return setNumIncorrectDesignatedReportMarketsValue;
}

function getAvgReportingGasPrice() public view returns (uint256) {
return setAvgReportingGasPriceValue;
}

function getOrCreateNextFeeWindow() public returns (IFeeWindow) {
return setNextFeeWindowValue;
}
Expand Down
Loading

0 comments on commit 92abeca

Please sign in to comment.