erc20-limiter

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

Limiter.sol (1565B)


      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 contract Limiter {
      9 	address public owner;
     10 
     11 	mapping ( address => mapping ( address => uint256 ) ) limit;
     12 
     13 	// EIP173
     14 	event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
     15 
     16 	constructor() {
     17 		owner = msg.sender;
     18 	}
     19 
     20 	function limitOf(address _token, address _holder) public view returns (uint256) {
     21 		return limit[_token][_holder];
     22 	}
     23 
     24 	function setLimit(address _token, uint256 _value) public {
     25 		limit[_token][msg.sender] = _value;
     26 	}
     27 
     28 	function setLimitFor(address _token, address _holder, uint256 _value) public {
     29 		uint256 sz;
     30 		require(msg.sender == owner ||  msg.sender == _holder, 'ERR_AXX');
     31 		assembly {
     32 			sz := extcodesize(_holder)
     33 		}
     34 		require(sz > 0, 'ERR_ACCOUNT');
     35 		limit[_token][_holder] = _value;
     36 	}
     37 
     38 	// Implements EIP173
     39 	function transferOwnership(address _newOwner) public returns (bool) {
     40 		address oldOwner;
     41 
     42 		require(msg.sender == owner);
     43 		oldOwner = owner;
     44 		owner = _newOwner;
     45 
     46 		emit OwnershipTransferred(oldOwner, owner);
     47 		return true;
     48 	}
     49 
     50 	// Implements EIP165
     51 	function supportsInterface(bytes4 _sum) public pure returns (bool) {
     52 		if (_sum == 0x01ffc9a7) { // ERC165
     53 			return true;
     54 		}
     55 		if (_sum == 0x9493f8b2) { // ERC173
     56 			return true;
     57 		}
     58 		if (_sum == 0x23778613) { // TokenLimit
     59 			return true;
     60 		}
     61 		return false;
     62 	}
     63 }