generated from PoCInnovation/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #10 from PoCInnovation/refactor
Refactor codebase
- Loading branch information
Showing
31 changed files
with
1,507 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Forge lib | ||
/packages/dao/lib/@openzeppelin/ | ||
/packages/dao/lib/@superfluid-finance | ||
/packages/dao/lib/forge-std/ |
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,9 @@ | ||
[submodule "packages/dao/lib/forge-std"] | ||
path = packages/dao/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "packages/dao/lib/@openzeppelin"] | ||
path = packages/dao/lib/@openzeppelin | ||
url = https://github.com/openzeppelin/openzeppelin-contracts | ||
[submodule "packages/dao/lib/@superfluid-finance"] | ||
path = packages/dao/lib/@superfluid-finance | ||
url = https://github.com/superfluid-finance/protocol-monorepo |
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,14 @@ | ||
# Compiler files | ||
cache/ | ||
out/ | ||
|
||
# Ignores development broadcast logs | ||
!/broadcast | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
|
||
# Docs | ||
docs/ | ||
|
||
# Dotenv file | ||
.env |
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,12 @@ | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
remappings = [ | ||
"custom-supertokens/=lib/custom-supertokens/", | ||
"forge-std/=lib/forge-std/src/", | ||
"@openzeppelin/=lib/@openzeppelin/", | ||
"@superfluid-finance/=lib/@superfluid-finance/packages/", | ||
] | ||
auto_detect_remappings = true | ||
# See more config options https://github.com/foundry-rs/foundry/tree/master/config |
Submodule @openzeppelin
added at
fd81a9
Submodule @superfluid-finance
added at
9ba937
61 changes: 61 additions & 0 deletions
61
packages/dao/lib/custom-supertokens/BurnMintSuperToken.sol
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,61 @@ | ||
// SPDX-License-Identifier: AGPLv3 | ||
pragma solidity ^0.8.0; | ||
|
||
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; | ||
|
||
import {SuperTokenBase} from "./base/SuperTokenBase.sol"; | ||
|
||
/// @title Burnable and Mintable Pure Super Token | ||
/// @author jtriley.eth | ||
/// @notice This does not perform checks when burning | ||
contract BurnMintSuperToken is SuperTokenBase, AccessControl { | ||
/// @notice Minter Role | ||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
|
||
/// @notice Burner Role | ||
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); | ||
|
||
constructor() { | ||
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
} | ||
|
||
/// @notice Initializer, used AFTER factory upgrade | ||
/// @dev We MUST mint here, there is no other way to mint tokens | ||
/// @param factory Super Token factory for initialization | ||
/// @param name Name of Super Token | ||
/// @param symbol Symbol of Super Token | ||
/// @param initialSupply Initial token supply to pre-mint | ||
/// @param receiver Receiver of pre-mint | ||
/// @param userData Arbitrary user data for pre-mint | ||
function initialize( | ||
address factory, | ||
string memory name, | ||
string memory symbol, | ||
uint256 initialSupply, | ||
address receiver, | ||
bytes memory userData | ||
) external { | ||
_initialize(factory, name, symbol); | ||
_mint(receiver, initialSupply, userData); | ||
} | ||
|
||
/// @notice Mints tokens, only the owner may do this | ||
/// @param receiver Receiver of minted tokens | ||
/// @param amount Amount to mint | ||
function mint( | ||
address receiver, | ||
uint256 amount, | ||
bytes memory userData | ||
) external onlyRole(MINTER_ROLE) { | ||
_mint(receiver, amount, userData); | ||
} | ||
|
||
/// @notice Burns from message sender | ||
/// @param amount Amount to burn | ||
function burn(uint256 amount, bytes memory userData) | ||
external | ||
onlyRole(BURNER_ROLE) | ||
{ | ||
_burn(msg.sender, amount, userData); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/dao/lib/custom-supertokens/BurnableSuperToken.sol
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,36 @@ | ||
// SPDX-License-Identifier: AGPLv3 | ||
pragma solidity ^0.8.0; | ||
|
||
import {SuperTokenBase} from "./base/SuperTokenBase.sol"; | ||
|
||
/// @title Burnable Pure Super Token | ||
/// @author jtriley.eth | ||
/// @notice This does not perform checks when burning | ||
contract BurnableSuperToken is SuperTokenBase { | ||
|
||
/// @notice Initializer, used AFTER factory upgrade | ||
/// @dev We MUST mint here, there is no other way to mint tokens | ||
/// @param factory Super Token factory for initialization | ||
/// @param name Name of Super Token | ||
/// @param symbol Symbol of Super Token | ||
/// @param initialSupply Initial token supply to pre-mint | ||
/// @param receiver Receiver of pre-mint | ||
/// @param userData Arbitrary user data for pre-mint | ||
function initialize( | ||
address factory, | ||
string memory name, | ||
string memory symbol, | ||
uint256 initialSupply, | ||
address receiver, | ||
bytes memory userData | ||
) external { | ||
_initialize(factory, name, symbol); | ||
_mint(receiver, initialSupply, userData); | ||
} | ||
|
||
/// @notice Burns from message sender | ||
/// @param amount Amount to burn | ||
function burn(uint256 amount, bytes memory userData) external { | ||
_burn(msg.sender, amount, userData); | ||
} | ||
} |
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,49 @@ | ||
// SPDX-License-Identifier: AGPLv3 | ||
pragma solidity ^0.8.0; | ||
|
||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
import {SuperTokenBase} from "./base/SuperTokenBase.sol"; | ||
|
||
/// @title Capped (maximum supply limit) Mintable Pure Super Token. | ||
/// @author jtriley.eth | ||
/// @notice Mint permission set in initializer, transferrable | ||
contract CappedSuperToken is SuperTokenBase, Ownable { | ||
|
||
/// @notice Thrown when supply limit would be exceeded | ||
error SupplyCapped(); | ||
|
||
/// @notice supply cap | ||
/// @dev not `immutable` unless set in constructor, which isn't possible | ||
/// so omitting functions that could write this variable will suffice. | ||
uint256 public maxSupply; | ||
|
||
/// @notice Initializes the super token only once IF it does not exceed supply cap | ||
/// @param factory Super Token factory for initialization | ||
/// @param name Name of Super Token | ||
/// @param symbol Symbol of Super Token | ||
/// @param _maxSupply Immutable max supply | ||
function initialize( | ||
address factory, | ||
string memory name, | ||
string memory symbol, | ||
uint256 _maxSupply | ||
) external { | ||
_initialize(factory, name, symbol); | ||
maxSupply = _maxSupply; | ||
} | ||
|
||
/// @notice Mints tokens to recipient if caller is the mitner AND max supply will not be exceeded | ||
/// @param recipient address to which the tokens are minted | ||
/// @param amount amount of tokens to mint | ||
/// @param userData optional user data for IERC777Recipient callbacks | ||
function mint( | ||
address recipient, | ||
uint256 amount, | ||
bytes memory userData | ||
) public onlyOwner { | ||
if (_totalSupply() + amount > maxSupply) revert SupplyCapped(); | ||
// MintableSuperToken._mint(address,uint256,bytes) | ||
_mint(recipient, amount, userData); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/dao/lib/custom-supertokens/MaticBridgedSuperToken.sol
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,57 @@ | ||
// SPDX-License-Identifier: AGPLv3 | ||
pragma solidity ^0.8.0; | ||
|
||
import {SuperTokenBase, ISuperToken} from "./base/SuperTokenBase.sol"; | ||
import {IMaticBridgedSuperTokenCustom} from "./interfaces/IMaticBridgedSuperToken.sol"; | ||
|
||
import {ISuperfluid} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol"; | ||
|
||
/** | ||
* @title Pure Super Token controlled by the Polygon PoS Bridge | ||
* @author Superfluid | ||
* @dev Pure SuperToken with interfaces for the Polygon PoS bridge to mint and burn. | ||
* @dev See https://docs.polygon.technology/docs/develop/ethereum-matic/pos/mapping-assets/ | ||
*/ | ||
contract MaticBridgedSuperToken is SuperTokenBase, IMaticBridgedSuperTokenCustom { | ||
/// address of the bridge contract interacting with this token contract | ||
address public childChainManager; | ||
|
||
constructor(address childChainManager_) { | ||
childChainManager = childChainManager_; | ||
} | ||
|
||
/// @notice Initializes the super token | ||
/// @param factory Super Token factory for initialization | ||
/// @param name Name of Super Token | ||
/// @param symbol Symbol of Super Token | ||
function initialize( | ||
address factory, | ||
string memory name, | ||
string memory symbol | ||
) external { | ||
_initialize(factory, name, symbol); | ||
} | ||
|
||
/// @inheritdoc IMaticBridgedSuperTokenCustom | ||
function deposit(address user, bytes calldata depositData) external override { | ||
require(msg.sender == childChainManager, "MBST: no permission to deposit"); | ||
uint256 amount = abi.decode(depositData, (uint256)); | ||
ISuperToken(address(this)).selfMint(user, amount, new bytes(0)); | ||
} | ||
|
||
/// @inheritdoc IMaticBridgedSuperTokenCustom | ||
function withdraw(uint256 amount) external override { | ||
ISuperToken(address(this)).selfBurn(msg.sender, amount, new bytes(0)); | ||
} | ||
|
||
/// @inheritdoc IMaticBridgedSuperTokenCustom | ||
/// @notice allows Superfluid governance to update the childChainManager | ||
function updateChildChainManager(address newChildChainManager) external override { | ||
address host = ISuperToken(address(this)).getHost(); | ||
address gov = address(ISuperfluid(host).getGovernance()); | ||
require(msg.sender == gov, "MBST: only governance allowed"); | ||
|
||
childChainManager = newChildChainManager; | ||
emit ChildChainManagerChanged(newChildChainManager); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/dao/lib/custom-supertokens/MintableSuperToken.sol
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,27 @@ | ||
// SPDX-License-Identifier: AGPLv3 | ||
pragma solidity ^0.8.0; | ||
|
||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
import {SuperTokenBase} from "./base/SuperTokenBase.sol"; | ||
|
||
/// @title Mintable Pure Super Token | ||
/// @author jtriley.eth | ||
/// @notice Only the owner may mint | ||
contract MintableSuperToken is SuperTokenBase, Ownable { | ||
|
||
/// @notice Initializer, used AFTER factory upgrade | ||
/// @param factory Super token factory for initialization | ||
/// @param name Name of Super Token | ||
/// @param symbol Symbol of Super Token | ||
function initialize(address factory, string memory name, string memory symbol) external { | ||
_initialize(factory, name, symbol); | ||
} | ||
|
||
/// @notice Mints tokens, only the owner may do this | ||
/// @param receiver Receiver of minted tokens | ||
/// @param amount Amount to mint | ||
function mint(address receiver, uint256 amount, bytes memory userData) external onlyOwner { | ||
_mint(receiver, amount, userData); | ||
} | ||
} |
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,28 @@ | ||
// SPDX-License-Identifier: AGPLv3 | ||
pragma solidity ^0.8.0; | ||
|
||
import {SuperTokenBase} from "./base/SuperTokenBase.sol"; | ||
|
||
/// @title Minimal Pure Super Token | ||
/// @author jtriley.eth | ||
/// @notice Pre-minted supply. This is includes no custom logic. Used in `PureSuperTokenDeployer` | ||
contract PureSuperToken is SuperTokenBase { | ||
|
||
/// @dev Upgrades the super token with the factory, then initializes. | ||
/// @param factory super token factory for initialization | ||
/// @param name super token name | ||
/// @param symbol super token symbol | ||
/// @param receiver Receiver of pre-mint | ||
/// @param initialSupply Initial token supply to pre-mint | ||
function initialize( | ||
address factory, | ||
string memory name, | ||
string memory symbol, | ||
address receiver, | ||
uint256 initialSupply | ||
) external { | ||
_initialize(factory, name, symbol); | ||
_mint(receiver, initialSupply, ""); | ||
} | ||
|
||
} |
Oops, something went wrong.