erc20-limiter

ERC20 balance limit registry
Info | Log | Files | Refs | README

LimiterIndex.sol (1855B)


      1 pragma solidity ^0.8.0;
      2 
      3 // Author:	Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
      4 // SPDX-License-Identifier: AGPL-3.0-or-later
      5 // File-Version: 1
      6 // Description: Registry of allowed ERC20 balance limits per-token and per-holder.
      7 
      8 interface Limiter {
      9 	function limitOf(address,address) external view returns(uint256);
     10 	function setLimit(address,uint256) external;
     11 	function setLimitFor(address,address,uint256) external;
     12 }
     13 
     14 contract LimiterTokenRegistry {
     15 	address public owner;
     16 	Limiter limiter;
     17 	address holder;
     18 
     19 	// Implements EIP173
     20 	event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
     21 
     22 
     23 	constructor(address _holder, Limiter _limiter) {
     24 		owner = msg.sender;
     25 		holder = _holder;
     26 		limiter = _limiter;
     27 	}
     28 
     29 	function limitOf(address _token, address _holder) public view returns (uint256) {
     30 		return limiter.limitOf(_token, _holder);
     31 	}
     32 
     33 	function setLimit(address _token, uint256 _value) public {
     34 		setLimitFor(_token, msg.sender, _value);
     35 	}
     36 
     37 	function setLimitFor(address _token, address _holder, uint256 _value) public {
     38 		limiter.setLimitFor(_token, _holder, _value);
     39 	}
     40 
     41 	// Implements ACL
     42 	function have(address _token) public view returns(bool) {
     43 		return limiter.limitOf(_token, holder) > 0;
     44 	}
     45 
     46 	// Implements EIP173
     47 	function transferOwnership(address _newOwner) public returns (bool) {
     48 		address oldOwner;
     49 
     50 		require(msg.sender == owner);
     51 		oldOwner = owner;
     52 		owner = _newOwner;
     53 
     54 		emit OwnershipTransferred(oldOwner, owner);
     55 		return true;
     56 	}
     57 
     58 	function supportsInterface(bytes4 _sum) public pure returns (bool) {
     59 		if (_sum == 0x01ffc9a7) { // ERC165
     60 			return true;
     61 		}
     62 		if (_sum == 0x3ef25013) { // ACL
     63 			return true;
     64 		}
     65 		if (_sum == 0x23778613) { // TokenLimit
     66 			return true;
     67 		}
     68 		if (_sum == 0x9493f8b2) { // ERC173
     69 			return true;
     70 		}
     71 		return false;
     72 	}
     73 }