Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ deployments
.DS_Store
.video.md
.article.md
contracts/stablecoins/README.md

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ This repo is dedicated to making minimal repos of existing defi primatives.
- `Staking.sol`: Based off [Synthetix](https://synthetix.io/)
- `RewardToken.sol`: Based off [Synthetix](https://synthetix.io/)
- `Exchange.sol` , `Factory.sol` , `Token.sol` : Based off [Uniswap v1](https://docs.uniswap.org/protocol/V1/introduction). The used pricing formula is documented [here](./docs/uniswap-v1/)
- `DecentralizedStableCoin`: Based off DAI/RAI
- `CentralizedStableCoin`: Based off USDC

### Uncompleted:
- `Options.sol`: Based off nothing

### Not a minimal contract:
- `Swap.sol`: Based off [Uniswap](https://uniswap.org/)
- `Swap.sol`: Based off [Uniswap](https://uniswap.org/) - shows how a smart contract can integrate with a Uniswap-like dex.

# Table Of Contents
- [Defi Minimal](#defi-minimal)
- [Completed minimal contracts:](#completed-minimal-contracts)
- [Completed (but unreviewed) minimal contracts:](#completed-but-unreviewed-minimal-contracts)
- [Uncompleted:](#uncompleted)
- [Not a minimal contract:](#not-a-minimal-contract)
- [Table Of Contents](#table-of-contents)
- [Getting Started](#getting-started)
- [Requirements](#requirements)
- [Quickstart](#quickstart)
Expand Down
40 changes: 26 additions & 14 deletions contracts/stablecoins/CentralizedStableCoin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@
// https://github.com/centrehq/centre-tokens/blob/master/contracts/v2/FiatTokenV2.sol
// https://github.com/centrehq/centre-tokens/blob/master/contracts/v1/FiatTokenV1.sol
// aka USDC

// This is considered an exogenous, centralized, anchored (pegged), fiat collateralized, low volitility coin

// Collateral: Exogenous
// Minting: Centralized
// Value: Anchored (Pegged to USD)
// Collateral Type: Fiat

// Also sometimes just refered to as "Fiat Collateralized Stablecoin"
// But maybe a better name would be "FiatCoin"

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

error CentralizedStablecoin__NotMinter();
error CentralizedStablecoin__AddressBlacklisted();
error CentralizedStablecoin__NotZeroAddress();
error CentralizedStablecoin__AmountMustBeMoreThanZero();
error CentralizedStablecoin__ExceededMinterAllowance();
error CentralizedStablecoin__BurnAmountExceedsBalance();
error CentralizedStableCoin__NotMinter();
error CentralizedStableCoin__AddressBlacklisted();
error CentralizedStableCoin__NotZeroAddress();
error CentralizedStableCoin__AmountMustBeMoreThanZero();
error CentralizedStableCoin__ExceededMinterAllowance();
error CentralizedStableCoin__BurnAmountExceedsBalance();

contract CentralizedStableCoin is ERC20Burnable, Ownable {
mapping(address => bool) internal s_blacklisted;
Expand All @@ -30,14 +41,14 @@ contract CentralizedStableCoin is ERC20Burnable, Ownable {
// Modifiers
modifier onlyMinters() {
if (!s_minters[msg.sender]) {
revert CentralizedStablecoin__NotMinter();
revert CentralizedStableCoin__NotMinter();
}
_;
}

modifier notBlacklisted(address addressToCheck) {
if (s_blacklisted[addressToCheck]) {
revert CentralizedStablecoin__AddressBlacklisted();
revert CentralizedStableCoin__AddressBlacklisted();
}
_;
}
Expand All @@ -54,27 +65,28 @@ contract CentralizedStableCoin is ERC20Burnable, Ownable {
returns (bool)
{
if (_to == address(0)) {
revert CentralizedStablecoin__NotZeroAddress();
revert CentralizedStableCoin__NotZeroAddress();
}
if (_amount <= 0) {
revert CentralizedStablecoin__AmountMustBeMoreThanZero();
revert CentralizedStableCoin__AmountMustBeMoreThanZero();
}

uint256 mintingAllowedAmount = s_minterAllowed[msg.sender];
if (_amount <= mintingAllowedAmount) {
revert CentralizedStablecoin__ExceededMinterAllowance();
if (_amount > mintingAllowedAmount) {
revert CentralizedStableCoin__ExceededMinterAllowance();
}
s_minterAllowed[msg.sender] = mintingAllowedAmount - _amount;
_mint(msg.sender, mintingAllowedAmount);
return true;
}

function burn(uint256 _amount) public override onlyMinters notBlacklisted(msg.sender) {
uint256 balance = balanceOf(msg.sender);
if (_amount <= 0) {
revert CentralizedStablecoin__AmountMustBeMoreThanZero();
revert CentralizedStableCoin__AmountMustBeMoreThanZero();
}
if (balance < _amount) {
revert CentralizedStablecoin__BurnAmountExceedsBalance();
revert CentralizedStableCoin__BurnAmountExceedsBalance();
}
_burn(msg.sender, _amount);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// https://blog.bitmex.com/wp-content/uploads/2018/06/A-Note-on-Cryptocurrency-Stabilisation-Seigniorage-Shares.pdf

// This would be similar to a UST/LUNA

// This is considered an Endogenous, Decentralized, Reflexive, Crypto Collateralized low volitility coin

// Collateral: Endogenous
// Minting: Decentralized
// Value: Reflexive
// Collateral Type: Crypto

// Sometimes just refered to as "Algorithmic Stablecoin"

// But maybe a better name would be EndoDrCCoin (EndoDocCoin?), or maybe like "RobertsCoin" or something after the Sam Roberts paper...
// We should fix the name as a community

pragma solidity ^0.8.7;

contract AlgorithmicStableCoin {

}

// To be created...
3 changes: 3 additions & 0 deletions contracts/stablecoins/endogenousIndexCoin/Fpi.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This would be similar to a FPI/FPIX

// To be created...
Loading