Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

I terminus #53

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ dmypy.json
.dao/
.secrets/
.vscode/

# MacOS
.DS_Store
14 changes: 14 additions & 0 deletions contracts/interfaces/IERC1155WithTerminusStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import "@openzeppelin-contracts/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol";

interface IERC1155WithTerminusStorage is IERC1155, IERC1155MetadataURI {
function isApprovedForPool(uint256 poolID, address operator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this interface. Might as well roll this into ITerminus.

external
view
returns (bool);

function approveForPool(uint256 poolID, address operator) external;
}
84 changes: 84 additions & 0 deletions contracts/interfaces/ITerminus.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;
import "./IERC1155WithTerminusStorage.sol";

interface ITerminus is IERC1155WithTerminusStorage {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather this was codegen'd instead of created manually.

event PoolMintBatch(
uint256 indexed id,
address indexed operator,
address from,
address[] toAddresses,
uint256[] amounts
);

function setController(address newController) external;

function poolMintBatch(
uint256 id,
address[] memory toAddresses,
uint256[] memory amounts
) external;

function terminusController() external view returns (address);

function paymentToken() external view returns (address);

function setPaymentToken(address newPaymentToken) external;

function poolBasePrice() external view returns (uint256);

function setPoolBasePrice(uint256 newBasePrice) external;

function withdrawPayments(address toAddress, uint256 amount) external;

function contractURI() external view returns (string memory);

function setContractURI(string memory _contractURI) external;

function setURI(uint256 poolID, string memory poolURI) external;

function totalPools() external view returns (uint256);

function setPoolController(uint256 poolID, address newController) external;

function terminusPoolController(uint256 poolID)
external
view
returns (address);

function terminusPoolCapacity(uint256 poolID)
external
view
returns (uint256);

function terminusPoolSupply(uint256 poolID) external view returns (uint256);

function createSimplePool(uint256 _capacity) external returns (uint256);

function createPoolV1(
uint256 _capacity,
bool _transferable,
bool _burnable
) external returns (uint256);

function mint(
address to,
uint256 poolID,
uint256 amount,
bytes memory data
) external;

function mintBatch(
address to,
uint256[] memory poolIDs,
uint256[] memory amounts,
bytes memory data
) external;

function burn(
address from,
uint256 poolID,
uint256 amount
) external;
}
21 changes: 9 additions & 12 deletions contracts/terminus/ERC1155WithTerminusStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@

pragma solidity ^0.8.9;

import "@openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol";
import "@openzeppelin-contracts/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol";
import "@openzeppelin-contracts/contracts/utils/Address.sol";
import "@openzeppelin-contracts/contracts/utils/Context.sol";
import "@openzeppelin-contracts/contracts/utils/introspection/ERC165.sol";
import "./LibTerminus.sol";
import "../interfaces/IERC1155WithTerminusStorage.sol";

contract ERC1155WithTerminusStorage is
Context,
ERC165,
IERC1155,
IERC1155MetadataURI
{
contract ERC1155WithTerminusStorage is Context, IERC1155WithTerminusStorage {
using Address for address;

constructor() {}
Expand All @@ -40,13 +33,13 @@ contract ERC1155WithTerminusStorage is
public
view
virtual
override(ERC165, IERC165)
override
returns (bool)
{
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
interfaceId == type(IERC1155WithTerminusStorage).interfaceId;
}

function uri(uint256 poolID)
Expand Down Expand Up @@ -138,12 +131,16 @@ contract ERC1155WithTerminusStorage is
function isApprovedForPool(uint256 poolID, address operator)
public
view
override
returns (bool)
{
return LibTerminus._isApprovedForPool(poolID, operator);
}

function approveForPool(uint256 poolID, address operator) external {
function approveForPool(uint256 poolID, address operator)
external
override
{
LibTerminus.enforcePoolIsController(poolID, _msgSender());
LibTerminus._approveForPool(poolID, operator);
}
Expand Down
13 changes: 3 additions & 10 deletions contracts/terminus/TerminusFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,15 @@ import "@openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "./ERC1155WithTerminusStorage.sol";
import "./LibTerminus.sol";
import "../diamond/libraries/LibDiamond.sol";
import "../interfaces/ITerminus.sol";

contract TerminusFacet is ERC1155WithTerminusStorage {
contract TerminusFacet is ITerminus, ERC1155WithTerminusStorage {
constructor() {
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
ts.controller = msg.sender;
}

event PoolMintBatch(
uint256 indexed id,
address indexed operator,
address from,
address[] toAddresses,
uint256[] amounts
);

function setController(address newController) external {
function setController(address newController) external override {
LibTerminus.enforceIsController();
LibTerminus.setController(newController);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/terminus/TerminusPermissions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import "@openzeppelin-contracts/contracts/access/Ownable.sol";
import "./TerminusFacet.sol";
import "../interfaces/ITerminus.sol";

pragma solidity ^0.8.9;

Expand All @@ -17,7 +17,7 @@ abstract contract TerminusPermissions {
uint256 poolId,
uint256 _amount
) internal view returns (bool) {
TerminusFacet terminus = TerminusFacet(terminusAddress);
ITerminus terminus = ITerminus(terminusAddress);
return terminus.balanceOf(msg.sender, poolId) >= _amount;
}

Expand All @@ -34,7 +34,7 @@ abstract contract TerminusPermissions {
_holdsPoolToken(terminusAddress, poolId, 1),
"TerminusPermissions.spendsPoolToken: Sender doens't hold pool tokens"
);
TerminusFacet terminusContract = TerminusFacet(terminusAddress);
ITerminus terminusContract = ITerminus(terminusAddress);
terminusContract.burn(msg.sender, poolId, 1);
_;
}
Expand Down
10 changes: 4 additions & 6 deletions contracts/terminus/controller/TerminusControllerFacet.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.9;
/**
* Authors: Moonstream Engineering (engineering@moonstream.to)
* GitHub: https://github.com/bugout-dev/dao
Expand All @@ -8,13 +8,11 @@
* with a ability to whitelist operators by using Terminus Pools
*/
import "@openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "../TerminusFacet.sol";
import "../../interfaces/ITerminus.sol";
import "../TerminusPermissions.sol";
import "./LibTerminusController.sol";
import "../TokenDrainerFacet.sol";

pragma solidity ^0.8.9;

// Permissions:
// - Contract owner can change _TERMINUS_MAIN_ADMIN_POOL_ID (+ all other operations?)
// - Holder of _TERMINUS_MAIN_ADMIN_POOL_ID can change poolControllerPoolID, create pool (+ pool operations?)
Expand Down Expand Up @@ -70,9 +68,9 @@ contract TerminusControllerFacet is TerminusPermissions, TokenDrainerFacet {
ts.terminusAddress = terminusAddress;
}

function terminusContract() internal view returns (TerminusFacet) {
function terminusContract() internal view returns (ITerminus) {
return
TerminusFacet(
ITerminus(
LibTerminusController
.terminusControllerStorage()
.terminusAddress
Expand Down