generated from NomicFoundation/hardhat-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from gnosis/erc-6551
EIP-6551 compat
- Loading branch information
Showing
80 changed files
with
6,309 additions
and
3,777 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//SPDX-License-Identifier: LGPL-3.0 | ||
pragma solidity ^0.8.12; | ||
|
||
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; | ||
import "./base/ThresholdMech.sol"; | ||
import "./libraries/MinimalProxyStore.sol"; | ||
|
||
/** | ||
* @dev A Mech that is operated by any holder of a defined set of minimum ERC1155 token balances | ||
*/ | ||
contract ERC1155ThresholdMech is ThresholdMech { | ||
function threshold() | ||
public | ||
view | ||
returns ( | ||
address token, | ||
uint256[] memory tokenIds, | ||
uint256[] memory minBalances, | ||
uint256 minTotalBalance | ||
) | ||
{ | ||
return | ||
abi.decode( | ||
MinimalProxyStore.getContext(address(this)), | ||
(address, uint256[], uint256[], uint256) | ||
); | ||
} | ||
|
||
function isOperator(address signer) public view override returns (bool) { | ||
( | ||
address token, | ||
uint256[] memory tokenIds, | ||
uint256[] memory minBalances, | ||
uint256 minTotalBalance | ||
) = this.threshold(); | ||
|
||
uint256 balanceSum = 0; | ||
for (uint256 i = 0; i < tokenIds.length; i++) { | ||
uint256 balance = IERC1155(token).balanceOf(signer, tokenIds[i]); | ||
if (balance < minBalances[i]) { | ||
return false; | ||
} | ||
balanceSum += balance; | ||
} | ||
|
||
return balanceSum >= minTotalBalance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//SPDX-License-Identifier: LGPL-3.0 | ||
pragma solidity ^0.8.12; | ||
|
||
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; | ||
import "./base/TokenboundMech.sol"; | ||
|
||
/** | ||
* @dev A Mech that is operated by the holder of a designated ERC1155 token | ||
*/ | ||
contract ERC1155TokenboundMech is TokenboundMech { | ||
function isOperator(address signer) public view override returns (bool) { | ||
(uint256 chainId, address tokenContract, uint256 tokenId) = this | ||
.token(); | ||
if (chainId != block.chainid) return false; | ||
return IERC1155(tokenContract).balanceOf(signer, tokenId) > 0; | ||
} | ||
|
||
function onERC1155Received( | ||
address, | ||
address from, | ||
uint256 receivedTokenId, | ||
uint256, | ||
bytes calldata | ||
) external view override returns (bytes4) { | ||
( | ||
uint256 chainId, | ||
address boundTokenContract, | ||
uint256 boundTokenId | ||
) = this.token(); | ||
|
||
if ( | ||
chainId == block.chainid && | ||
msg.sender == boundTokenContract && | ||
receivedTokenId == boundTokenId | ||
) { | ||
// We block the transfer only if the sender has no balance left after the transfer. | ||
// Note: ERC-1155 prescribes that balances are updated BEFORE the call to onERC1155Received. | ||
if ( | ||
IERC1155(boundTokenContract).balanceOf(from, boundTokenId) == 0 | ||
) { | ||
revert OwnershipCycle(); | ||
} | ||
} | ||
|
||
return 0xf23a6e61; | ||
} | ||
|
||
function onERC1155BatchReceived( | ||
address, | ||
address from, | ||
uint256[] calldata ids, | ||
uint256[] calldata, | ||
bytes calldata | ||
) external view override returns (bytes4) { | ||
( | ||
uint256 chainId, | ||
address boundTokenContract, | ||
uint256 boundTokenId | ||
) = this.token(); | ||
|
||
if (chainId == block.chainid && msg.sender == boundTokenContract) { | ||
// We block the transfer only if the sender has no balance left after the transfer. | ||
// Note: ERC-1155 prescribes that balances are updated BEFORE the call to onERC1155BatchReceived. | ||
for (uint256 i = 0; i < ids.length; i++) { | ||
if (ids[i] == boundTokenId) { | ||
if ( | ||
IERC1155(boundTokenContract).balanceOf( | ||
from, | ||
boundTokenId | ||
) == 0 | ||
) { | ||
revert OwnershipCycle(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return 0xbc197c81; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//SPDX-License-Identifier: LGPL-3.0 | ||
pragma solidity ^0.8.12; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "./base/ThresholdMech.sol"; | ||
import "./libraries/MinimalProxyStore.sol"; | ||
|
||
/** | ||
* @dev A Mech that is operated by any holder of a minimum ERC20 token balance | ||
*/ | ||
contract ERC20ThresholdMech is ThresholdMech { | ||
function threshold() | ||
public | ||
view | ||
returns (address token, uint256 minBalance) | ||
{ | ||
return | ||
abi.decode( | ||
MinimalProxyStore.getContext(address(this)), | ||
(address, uint256) | ||
); | ||
} | ||
|
||
function isOperator(address signer) public view override returns (bool) { | ||
(address token, uint256 minBalance) = this.threshold(); | ||
|
||
return IERC20(token).balanceOf(signer) >= minBalance; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
e9cc900
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
mech – ./
mech-gnosis-guild.vercel.app
mech-git-main-gnosis-guild.vercel.app
mech-omega.vercel.app