// SPDX-License-Identifier: MIT pragma solidity 0.8.19; import { MagnetErc721aBase } from "../MagnetErc721aBase.sol"; /// @title MagnetErc721aCsrRecipientIsContract /// @dev register magnet erc721a contract as csr recipient interface ITurnstile { function register(address _recipient) external returns(uint256); function withdraw(uint256 _tokenId, address payable _recipient, uint256 _amount) external returns (uint256); function getTokenId(address _smartContract) external view returns (uint256); function balances(uint256 _tokenId) external view returns (uint256); } abstract contract MagnetErc721aCsrRecipientIsContract is MagnetErc721aBase { ITurnstile private immutable _turnstile; constructor(address _turnstileAddr) { _turnstile = ITurnstile(_turnstileAddr); _turnstile.register(address(this)); } function _releaseCsrFees() private { uint256 tokenId_ = _turnstile.getTokenId(address(this)); uint256 amount_ = _turnstile.balances(tokenId_); if(amount_ > 0) { address payable recipient_ = payable(address(this)); _turnstile.withdraw(tokenId_, recipient_, amount_); } } /// @notice to be called to release all csr fees accrued by this contract, fees will be added to contract balance function releaseCsrFees() external { _releaseCsrFees(); } /// @notice to be called to ditribute contract revenues to all payees - only callable by owner function releaseAll() public virtual override onlyOwner { _releaseCsrFees(); super.releaseAll(); } }