Skip to content

Commit

Permalink
avoid unnecessary external calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschwarz committed Dec 7, 2023
1 parent f8dc3cd commit b1b3137
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion contracts/ERC1155ThresholdMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract ERC1155ThresholdMech is ThresholdMech {
uint256[] memory tokenIds,
uint256[] memory minBalances,
uint256 minTotalBalance
) = this.threshold();
) = threshold();

uint256 balanceSum = 0;
for (uint256 i = 0; i < tokenIds.length; i++) {
Expand Down
7 changes: 3 additions & 4 deletions contracts/ERC1155TokenboundMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import "./base/TokenboundMech.sol";
*/
contract ERC1155TokenboundMech is TokenboundMech {
function isOperator(address signer) public view override returns (bool) {
(uint256 chainId, address tokenContract, uint256 tokenId) = this
.token();
(uint256 chainId, address tokenContract, uint256 tokenId) = token();
if (chainId != block.chainid) return false;
return IERC1155(tokenContract).balanceOf(signer, tokenId) > 0;
}
Expand All @@ -26,7 +25,7 @@ contract ERC1155TokenboundMech is TokenboundMech {
uint256 chainId,
address boundTokenContract,
uint256 boundTokenId
) = this.token();
) = token();

if (
chainId == block.chainid &&
Expand Down Expand Up @@ -56,7 +55,7 @@ contract ERC1155TokenboundMech is TokenboundMech {
uint256 chainId,
address boundTokenContract,
uint256 boundTokenId
) = this.token();
) = token();

if (chainId == block.chainid && msg.sender == boundTokenContract) {
// We block the transfer only if the sender has no balance left after the transfer.
Expand Down
2 changes: 1 addition & 1 deletion contracts/ERC20ThresholdMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract ERC20ThresholdMech is ThresholdMech {
}

function isOperator(address signer) public view override returns (bool) {
(address token, uint256 minBalance) = this.threshold();
(address token, uint256 minBalance) = threshold();

return IERC20(token).balanceOf(signer) >= minBalance;
}
Expand Down
5 changes: 2 additions & 3 deletions contracts/ERC721TokenboundMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import "./base/TokenboundMech.sol";
*/
contract ERC721TokenboundMech is TokenboundMech {
function isOperator(address signer) public view override returns (bool) {
(uint256 chainId, address tokenContract, uint256 tokenId) = this
.token();
(uint256 chainId, address tokenContract, uint256 tokenId) = token();
if (chainId != block.chainid) return false;
return
IERC721(tokenContract).ownerOf(tokenId) == signer &&
Expand All @@ -28,7 +27,7 @@ contract ERC721TokenboundMech is TokenboundMech {
uint256 chainId,
address boundTokenContract,
uint256 boundTokenId
) = this.token();
) = token();

if (
chainId == block.chainid &&
Expand Down
2 changes: 1 addition & 1 deletion contracts/base/TokenboundMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract contract TokenboundMech is Mech, IERC6551Account {
}

function token()
external
public
view
returns (uint256 chainId, address tokenContract, uint256 tokenId)
{
Expand Down

0 comments on commit b1b3137

Please sign in to comment.