Skip to content

Commit

Permalink
Adds the context behaviour to MarketplaceTokenHoldersFacet.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesduncombe committed Feb 7, 2024
1 parent 6a33e98 commit 7f7f300
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions contracts/marketplace/MarketplaceTokenHoldersFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import "./lib/LibMarketplaceTokenHolders.sol";
import "../issuer/IssuerTopFacet.sol";
import "../interfaces/IERC20.sol";
import "../interfaces/ICustomErrors.sol";
import "../common/AHasContext.sol";
import "../common/AHasForwarder.sol";

/** @dev The Marketplace FAST balances facet.
*/
contract MarketplaceTokenHoldersFacet is AMarketplaceFacet {
contract MarketplaceTokenHoldersFacet is AMarketplaceFacet, AHasContext {
using LibAddressSet for LibAddressSet.Data;

/// AHasContext implementation.

function _isTrustedForwarder(address forwarder) internal view override(AHasContext) returns (bool) {
return AHasForwarder(address(this)).isTrustedForwarder(forwarder);
}

/** @dev The callback used when a balance changes on a FAST.
*/
function fastBalanceChanged(address account, uint256 balance) external {
Expand All @@ -21,20 +29,20 @@ contract MarketplaceTokenHoldersFacet is AMarketplaceFacet {
}

// Verify that the given address is in fact a registered FAST contract.
if (!IssuerTopFacet(LibMarketplace.data().issuer).isFastRegistered(msg.sender)) {
if (!IssuerTopFacet(LibMarketplace.data().issuer).isFastRegistered(_msgSender())) {
revert ICustomErrors.RequiresFastContractCaller();
}

// Get the storage pointer and balance of the token holder.
LibMarketplaceTokenHolders.Data storage s = LibMarketplaceTokenHolders.data();

// If this is a positive balance and it doesn't already exist in the set, add address.
if (balance > 0 && !s.fastHoldings[account].contains(msg.sender)) {
s.fastHoldings[account].add(msg.sender, false);
if (balance > 0 && !s.fastHoldings[account].contains(_msgSender())) {
s.fastHoldings[account].add(_msgSender(), false);
}
// If the balance is 0 and it exists in the set, remove it.
else if (balance == 0 && s.fastHoldings[account].contains(msg.sender)) {
s.fastHoldings[account].remove(msg.sender, false);
else if (balance == 0 && s.fastHoldings[account].contains(_msgSender())) {
s.fastHoldings[account].remove(_msgSender(), false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/marketplace/MarketplaceTokenHoldersFacet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("MarketplaceTokenHoldersFacet", () => {
issuer.isFastRegistered.returns(false);
});

describe("holdingsUpdated", () => {
describe("fastBalanceChanged", () => {
it("reverts if not called by a FAST contract", async () => {
// Trigger the holding update callback.
const subject = tokenHolders.fastBalanceChanged(alice.address, 0);
Expand Down

0 comments on commit 7f7f300

Please sign in to comment.