Skip to content

Commit

Permalink
Explicit getters for token and config
Browse files Browse the repository at this point in the history
Implicit getters have slightly different semantics when
it comes to ABI encoding their results.
  • Loading branch information
markspanbroek committed Feb 6, 2024
1 parent fb17fb5 commit 6c9f797
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion contracts/FuzzMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ contract FuzzMarketplace is Marketplace {

function neverLoseFunds() public view {
uint256 total = _marketplaceTotals.received - _marketplaceTotals.sent;
assert(token.balanceOf(address(this)) >= total);
assert(token().balanceOf(address(this)) >= total);
}
}
32 changes: 20 additions & 12 deletions contracts/Marketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
using EnumerableSet for EnumerableSet.Bytes32Set;
using Requests for Request;

IERC20 public immutable token;
MarketplaceConfig public config;
IERC20 private immutable _token;
MarketplaceConfig private _config;

mapping(RequestId => Request) private _requests;
mapping(RequestId => RequestContext) private _requestContexts;
Expand Down Expand Up @@ -58,7 +58,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
IERC20 token_,
IGroth16Verifier verifier
) Proofs(configuration.proofs, verifier) {
token = token_;
_token = token_;

require(
configuration.collateral.repairRewardPercentage <= 100,
Expand All @@ -74,7 +74,15 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
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 {
Expand Down Expand Up @@ -198,13 +206,13 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
Slot storage slot = _slots[slotId];
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 *
config.collateral.slashPercentage) / 100;
_config.collateral.slashPercentage) / 100;
slot.currentCollateral -= slashedAmount;
if (
missingProofs(slotId) / config.collateral.slashCriterion >=
config.collateral.maxNumberOfSlashes
missingProofs(slotId) / _config.collateral.slashCriterion >=
_config.collateral.maxNumberOfSlashes
) {
// When the number of slashings is at or above the allowed amount,
// free the slot.
Expand Down Expand Up @@ -256,7 +264,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
slot.currentCollateral;
_marketplaceTotals.sent += amount;
slot.state = SlotState.Paid;
assert(token.transfer(slot.host, amount));
assert(_token.transfer(slot.host, amount));
}

function _payoutCancelledSlot(
Expand All @@ -270,7 +278,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
slot.currentCollateral;
_marketplaceTotals.sent += amount;
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.
Expand All @@ -292,7 +300,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {

uint256 amount = context.expiryFundsWithdraw;
_marketplaceTotals.sent += amount;
assert(token.transfer(msg.sender, amount));
assert(_token.transfer(msg.sender, amount));
}

function getActiveSlot(
Expand Down Expand Up @@ -387,7 +395,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {

function _transferFrom(address sender, uint256 amount) internal {
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);
Expand Down

0 comments on commit 6c9f797

Please sign in to comment.