// SPDX-License-Identifier: MIT pragma solidity 0.8.19; import "../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 { address private constant TURNSTILE_ADDR = 0xEcf044C5B4b867CFda001101c617eCd347095B44; ITurnstile private turnstile = ITurnstile(TURNSTILE_ADDR); constructor() { 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(); } }