Explicit getters for token and config

Implicit getters have slightly different semantics when
it comes to ABI encoding their results.
This commit is contained in:
Mark Spanbroek 2024-02-06 08:49:41 +01:00 committed by markspanbroek
parent fb17fb5843
commit 6c9f797f40
2 changed files with 21 additions and 13 deletions

View File

@ -32,6 +32,6 @@ contract FuzzMarketplace is Marketplace {
function neverLoseFunds() public view { function neverLoseFunds() public view {
uint256 total = _marketplaceTotals.received - _marketplaceTotals.sent; uint256 total = _marketplaceTotals.received - _marketplaceTotals.sent;
assert(token.balanceOf(address(this)) >= total); assert(token().balanceOf(address(this)) >= total);
} }
} }

View File

@ -15,8 +15,8 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
using EnumerableSet for EnumerableSet.Bytes32Set; using EnumerableSet for EnumerableSet.Bytes32Set;
using Requests for Request; using Requests for Request;
IERC20 public immutable token; IERC20 private immutable _token;
MarketplaceConfig public config; MarketplaceConfig private _config;
mapping(RequestId => Request) private _requests; mapping(RequestId => Request) private _requests;
mapping(RequestId => RequestContext) private _requestContexts; mapping(RequestId => RequestContext) private _requestContexts;
@ -58,7 +58,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
IERC20 token_, IERC20 token_,
IGroth16Verifier verifier IGroth16Verifier verifier
) Proofs(configuration.proofs, verifier) { ) Proofs(configuration.proofs, verifier) {
token = token_; _token = token_;
require( require(
configuration.collateral.repairRewardPercentage <= 100, configuration.collateral.repairRewardPercentage <= 100,
@ -74,7 +74,15 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
100, 100,
"Maximum slashing exceeds 100%" "Maximum slashing exceeds 100%"
); );
config = configuration; _config = configuration;
}
function config() public view returns (MarketplaceConfig memory) {
return _config;
}
function token() public view returns (IERC20) {
return _token;
} }
function requestStorage(Request calldata request) public { function requestStorage(Request calldata request) public {
@ -198,13 +206,13 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
Slot storage slot = _slots[slotId]; Slot storage slot = _slots[slotId];
Request storage request = _requests[slot.requestId]; Request storage request = _requests[slot.requestId];
if (missingProofs(slotId) % config.collateral.slashCriterion == 0) { if (missingProofs(slotId) % _config.collateral.slashCriterion == 0) {
uint256 slashedAmount = (request.ask.collateral * uint256 slashedAmount = (request.ask.collateral *
config.collateral.slashPercentage) / 100; _config.collateral.slashPercentage) / 100;
slot.currentCollateral -= slashedAmount; slot.currentCollateral -= slashedAmount;
if ( if (
missingProofs(slotId) / config.collateral.slashCriterion >= missingProofs(slotId) / _config.collateral.slashCriterion >=
config.collateral.maxNumberOfSlashes _config.collateral.maxNumberOfSlashes
) { ) {
// When the number of slashings is at or above the allowed amount, // When the number of slashings is at or above the allowed amount,
// free the slot. // free the slot.
@ -256,7 +264,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
slot.currentCollateral; slot.currentCollateral;
_marketplaceTotals.sent += amount; _marketplaceTotals.sent += amount;
slot.state = SlotState.Paid; slot.state = SlotState.Paid;
assert(token.transfer(slot.host, amount)); assert(_token.transfer(slot.host, amount));
} }
function _payoutCancelledSlot( function _payoutCancelledSlot(
@ -270,7 +278,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
slot.currentCollateral; slot.currentCollateral;
_marketplaceTotals.sent += amount; _marketplaceTotals.sent += amount;
slot.state = SlotState.Paid; slot.state = SlotState.Paid;
assert(token.transfer(slot.host, amount)); assert(_token.transfer(slot.host, amount));
} }
/// @notice Withdraws storage request funds back to the client that deposited them. /// @notice Withdraws storage request funds back to the client that deposited them.
@ -292,7 +300,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
uint256 amount = context.expiryFundsWithdraw; uint256 amount = context.expiryFundsWithdraw;
_marketplaceTotals.sent += amount; _marketplaceTotals.sent += amount;
assert(token.transfer(msg.sender, amount)); assert(_token.transfer(msg.sender, amount));
} }
function getActiveSlot( function getActiveSlot(
@ -387,7 +395,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
function _transferFrom(address sender, uint256 amount) internal { function _transferFrom(address sender, uint256 amount) internal {
address receiver = address(this); address receiver = address(this);
require(token.transferFrom(sender, receiver, amount), "Transfer failed"); require(_token.transferFrom(sender, receiver, amount), "Transfer failed");
} }
event StorageRequested(RequestId requestId, Ask ask, uint256 expiry); event StorageRequested(RequestId requestId, Ask ask, uint256 expiry);