kopia lustrzana https://github.com/bugout-dev/dao
139 wiersze
4.8 KiB
Solidity
139 wiersze
4.8 KiB
Solidity
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
/**
|
|
* Authors: Moonstream Engineering (engineering@moonstream.to)
|
|
* GitHub: https://github.com/bugout-dev/dao
|
|
*
|
|
* This is an implementation of the Terminus decentralized authorization contract.
|
|
*
|
|
* Terminus users can create authorization pools. Each authorization pool has the following properties:
|
|
* 1. Controller: The address that controls the pool. Initially set to be the address of the pool creator.
|
|
* 2. Pool URI: Metadata URI for the authorization pool.
|
|
* 3. Pool capacity: The total number of tokens that can be minted in that authorization pool.
|
|
* 4. Pool supply: The number of tokens that have actually been minted in that authorization pool.
|
|
* 5. Transferable: A boolean value which denotes whether or not tokens from that pool can be transfered
|
|
* between addresses.
|
|
* 6. Burnable: A boolean value which denotes whether or not tokens from that pool can be burned.
|
|
*/
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
import "@openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
|
|
import "./ERC1155WithTerminusStorage.sol";
|
|
import "./LibTerminus.sol";
|
|
import "../diamond/libraries/LibDiamond.sol";
|
|
|
|
contract TerminusFacet is ERC1155WithTerminusStorage {
|
|
constructor() {}
|
|
|
|
function terminusController() external view returns (address) {
|
|
return LibTerminus.terminusStorage().controller;
|
|
}
|
|
|
|
function paymentToken() external view returns (address) {
|
|
return LibTerminus.terminusStorage().paymentToken;
|
|
}
|
|
|
|
function setPaymentToken(address newPaymentToken) external {
|
|
LibTerminus.enforceIsController();
|
|
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
|
|
ts.paymentToken = newPaymentToken;
|
|
}
|
|
|
|
function poolBasePrice() external view returns (uint256) {
|
|
return LibTerminus.terminusStorage().poolBasePrice;
|
|
}
|
|
|
|
function setPoolBasePrice(uint256 newBasePrice) external {
|
|
LibTerminus.enforceIsController();
|
|
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
|
|
ts.poolBasePrice = newBasePrice;
|
|
}
|
|
|
|
function _paymentTokenContract() internal view returns (IERC20) {
|
|
address paymentTokenAddress = LibTerminus
|
|
.terminusStorage()
|
|
.paymentToken;
|
|
require(
|
|
paymentTokenAddress != address(0),
|
|
"TerminusFacet: Payment token has not been set"
|
|
);
|
|
return IERC20(paymentTokenAddress);
|
|
}
|
|
|
|
function withdrawPayments(address toAddress, uint256 amount) external {
|
|
LibTerminus.enforceIsController();
|
|
require(
|
|
_msgSender() == toAddress,
|
|
"TerminusFacet: withdrawPayments -- Controller can only withdraw to self"
|
|
);
|
|
IERC20 paymentTokenContract = _paymentTokenContract();
|
|
paymentTokenContract.transfer(toAddress, amount);
|
|
}
|
|
|
|
function setURI(uint256 poolID, string memory poolURI) external {
|
|
LibTerminus.enforcePoolIsController(poolID, _msgSender());
|
|
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
|
|
ts.poolURI[poolID] = poolURI;
|
|
}
|
|
|
|
function totalPools() external view returns (uint256) {
|
|
return LibTerminus.terminusStorage().currentPoolID;
|
|
}
|
|
|
|
function terminusPoolController(uint256 poolID)
|
|
external
|
|
view
|
|
returns (address)
|
|
{
|
|
return LibTerminus.terminusStorage().poolController[poolID];
|
|
}
|
|
|
|
function terminusPoolCapacity(uint256 poolID)
|
|
external
|
|
view
|
|
returns (uint256)
|
|
{
|
|
return LibTerminus.terminusStorage().poolCapacity[poolID];
|
|
}
|
|
|
|
function createSimplePool(uint256 _capacity) external returns (uint256) {
|
|
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
|
|
uint256 requiredPayment = ts.poolBasePrice;
|
|
IERC20 paymentTokenContract = _paymentTokenContract();
|
|
require(
|
|
paymentTokenContract.allowance(_msgSender(), address(this)) >=
|
|
requiredPayment,
|
|
"TerminusFacet: createSimplePool -- Insufficient allowance on payment token"
|
|
);
|
|
paymentTokenContract.transferFrom(
|
|
msg.sender,
|
|
address(this),
|
|
requiredPayment
|
|
);
|
|
return LibTerminus.createSimplePool(_capacity);
|
|
}
|
|
|
|
function mint(
|
|
address to,
|
|
uint256 poolID,
|
|
uint256 amount,
|
|
bytes memory data
|
|
) external {
|
|
LibTerminus.enforcePoolIsController(poolID, msg.sender);
|
|
_mint(to, poolID, amount, data);
|
|
}
|
|
|
|
function mintBatch(
|
|
address to,
|
|
uint256[] memory poolIDs,
|
|
uint256[] memory amounts,
|
|
bytes memory data
|
|
) external {
|
|
for (uint256 i = 0; i < poolIDs.length; i++) {
|
|
LibTerminus.enforcePoolIsController(poolIDs[i], _msgSender());
|
|
}
|
|
_mintBatch(to, poolIDs, amounts, data);
|
|
}
|
|
}
|