Skip to content

Commit

Permalink
yeah buddy
Browse files Browse the repository at this point in the history
  • Loading branch information
amr080 committed Oct 16, 2024
1 parent 78c6556 commit 50f563d
Show file tree
Hide file tree
Showing 9 changed files with 874 additions and 1,488 deletions.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
REPORT_GAS=true
ETHERSCAN_API_KEY=
COIN_MARKETCAP_API_KEY=
OWNER_ADDRESS=
OWNER_ADDRESS=0x7bB3296d7c34fEB9A5CF25245346367fA1488Caf
USDM_ADDRESS=
PROXY_ADDRESS=

# Sepolia
ALCHEMY_SEPOLIA_API_KEY=EFbf2dOirtDeoDTQjyzgPweqEltdtCKP
SEPOLIA_PRIVATE_KEY=80b5a4e62ffe7b466308e31a9d27be78c4ca7e33ff0a92cb1d342fa9e12641ed


# Goerli
ALCHEMY_GOERLI_API_KEY=
GOERLI_PRIVATE_KEY=

# # Mainnet
# MAINNET_PRIVATE_KEY=
# ALCHEMY_MAINNET_API_KEY=

41 changes: 21 additions & 20 deletions contracts/USDM.sol → contracts/USDX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {IERC20MetadataUpgradeable} from "@openzeppelin/contracts-upgradeable/tok
import {IERC20PermitUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol";

/**
* @title Mountain Protocol USD Contract
* @custom:security-contact security@mountainprotocol.com
* @title X Protocol USD Contract
* @custom:security-contact alex@alexandros-securities.com
* @author Alexander Reed, X Financial Technologies
*/
contract USDM is
contract USDX is
IERC20MetadataUpgradeable,
AccessControlUpgradeable,
PausableUpgradeable,
Expand Down Expand Up @@ -77,14 +78,14 @@ contract USDM is
// ERC2612 Errors
error ERC2612ExpiredDeadline(uint256 deadline, uint256 blockTimestamp);
error ERC2612InvalidSignature(address owner, address spender);
// USDM Errors
error USDMInvalidMintReceiver(address receiver);
error USDMInvalidBurnSender(address sender);
error USDMInsufficientBurnBalance(address sender, uint256 shares, uint256 sharesNeeded);
error USDMInvalidRewardMultiplier(uint256 rewardMultiplier);
error USDMBlockedSender(address sender);
error USDMInvalidBlockedAccount(address account);
error USDMPausedTransfers();
// USDX Errors
error USDXInvalidMintReceiver(address receiver);
error USDXInvalidBurnSender(address sender);
error USDXInsufficientBurnBalance(address sender, uint256 shares, uint256 sharesNeeded);
error USDXInvalidRewardMultiplier(uint256 rewardMultiplier);
error USDXBlockedSender(address sender);
error USDXInvalidBlockedAccount(address account);
error USDXPausedTransfers();

/**
* @notice Initializes the contract.
Expand Down Expand Up @@ -219,7 +220,7 @@ contract USDM is
*/
function _mint(address to, uint256 amount) private {
if (to == address(0)) {
revert USDMInvalidMintReceiver(to);
revert USDXInvalidMintReceiver(to);
}

_beforeTokenTransfer(address(0), to, amount);
Expand Down Expand Up @@ -262,7 +263,7 @@ contract USDM is
*/
function _burn(address account, uint256 amount) private {
if (account == address(0)) {
revert USDMInvalidBurnSender(account);
revert USDXInvalidBurnSender(account);
}

_beforeTokenTransfer(account, address(0), amount);
Expand All @@ -271,7 +272,7 @@ contract USDM is
uint256 accountShares = sharesOf(account);

if (accountShares < shares) {
revert USDMInsufficientBurnBalance(account, accountShares, shares);
revert USDXInsufficientBurnBalance(account, accountShares, shares);
}

unchecked {
Expand Down Expand Up @@ -311,13 +312,13 @@ contract USDM is
// Each blocklist check is an SLOAD, which is gas intensive.
// We only block sender not receiver, so we don't tax every user
if (isBlocked(from)) {
revert USDMBlockedSender(from);
revert USDXBlockedSender(from);
}
// Useful for scenarios such as preventing trades until the end of an evaluation
// period, or having an emergency switch for freezing all token transfers in the
// event of a large bug.
if (paused()) {
revert USDMPausedTransfers();
revert USDXPausedTransfers();
}
}

Expand Down Expand Up @@ -405,7 +406,7 @@ contract USDM is
*/
function _blockAccount(address account) private {
if (isBlocked(account)) {
revert USDMInvalidBlockedAccount(account);
revert USDXInvalidBlockedAccount(account);
}

_blocklist[account] = true;
Expand All @@ -418,7 +419,7 @@ contract USDM is
*/
function _unblockAccount(address account) private {
if (!isBlocked(account)) {
revert USDMInvalidBlockedAccount(account);
revert USDXInvalidBlockedAccount(account);
}

_blocklist[account] = false;
Expand Down Expand Up @@ -480,7 +481,7 @@ contract USDM is
*/
function _setRewardMultiplier(uint256 _rewardMultiplier) private {
if (_rewardMultiplier < _BASE) {
revert USDMInvalidRewardMultiplier(_rewardMultiplier);
revert USDXInvalidRewardMultiplier(_rewardMultiplier);
}

rewardMultiplier = _rewardMultiplier;
Expand All @@ -504,7 +505,7 @@ contract USDM is
*/
function addRewardMultiplier(uint256 _rewardMultiplierIncrement) external onlyRole(ORACLE_ROLE) {
if (_rewardMultiplierIncrement == 0) {
revert USDMInvalidRewardMultiplier(_rewardMultiplierIncrement);
revert USDXInvalidRewardMultiplier(_rewardMultiplierIncrement);
}

_setRewardMultiplier(rewardMultiplier + _rewardMultiplierIncrement);
Expand Down
42 changes: 21 additions & 21 deletions contracts/wUSDM.sol → contracts/wUSDX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {IERC20MetadataUpgradeable} from "@openzeppelin/contracts-upgradeable/tok
import {IERC20PermitUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol";

/**
* @dev USDM Interface.
* @dev USDX Interface.
*/
interface IUSDM is IERC20MetadataUpgradeable {
interface IUSDX is IERC20MetadataUpgradeable {
/**
* @dev Checks if the specified address is blocked.
*/
Expand All @@ -27,10 +27,10 @@ interface IUSDM is IERC20MetadataUpgradeable {
}

/**
* @title Wrapped Mountain Protocol USDM
* @custom:security-contact security@mountainprotocol.com
* @title Wrapped X Protocol USDX
* @custom:security-contact alex@alexandros-securities.com
*/
contract wUSDM is
contract wUSDX is
ERC4626Upgradeable,
AccessControlUpgradeable,
PausableUpgradeable,
Expand All @@ -40,7 +40,7 @@ contract wUSDM is
{
using CountersUpgradeable for CountersUpgradeable.Counter;

IUSDM public USDM;
IUSDX public USDX;

// Mapping of nonces per address
mapping(address account => CountersUpgradeable.Counter counter) private _nonces;
Expand All @@ -56,39 +56,39 @@ contract wUSDM is
error ERC2612ExpiredDeadline(uint256 deadline, uint256 blockTimestamp);
error ERC2612InvalidSignature(address owner, address spender);

// wUSDM Errors
error wUSDMBlockedSender(address sender);
error wUSDMPausedTransfers();
// wUSDX Errors
error wUSDXBlockedSender(address sender);
error wUSDXPausedTransfers();

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

/**
* @notice Initializes the ERC-4626 USDM Wrapper.
* @param _USDM The address of the USDM token to wrap.
* @notice Initializes the ERC-4626 USDX Wrapper.
* @param _USDX The address of the USDX token to wrap.
* @param owner The owner address.
*/
function initialize(IUSDM _USDM, address owner) external initializer {
USDM = _USDM;
function initialize(IUSDX _USDX, address owner) external initializer {
USDX = _USDX;

__ERC20_init("Wrapped Mountain Protocol USD", "wUSDM");
__ERC4626_init(_USDM);
__ERC20_init("Wrapped X Protocol USD", "wUSDX");
__ERC4626_init(_USDX);
__AccessControl_init();
__Pausable_init();
__UUPSUpgradeable_init();
__EIP712_init("Wrapped Mountain Protocol USD", "1");
__EIP712_init("Wrapped X Protocol USD", "1");

_grantRole(DEFAULT_ADMIN_ROLE, owner);
}

/**
* @notice We override paused to use the underlying paused state as well.
* @return Returns true if USDM or wUSDM is paused, and false otherwise.
* @return Returns true if USDX or wUSDX is paused, and false otherwise.
*/
function paused() public view override returns (bool) {
return USDM.paused() || super.paused();
return USDX.paused() || super.paused();
}

/**
Expand Down Expand Up @@ -122,15 +122,15 @@ contract wUSDM is
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
// Each blocklist check is an SLOAD, which is gas intensive.
// We only block sender not receiver, so we don't tax every user
if (USDM.isBlocked(from)) {
revert wUSDMBlockedSender(from);
if (USDX.isBlocked(from)) {
revert wUSDXBlockedSender(from);
}

// Useful for scenarios such as preventing trades until the end of an evaluation
// period, or having an emergency switch for freezing all token transfers in the
// event of a large bug.
if (paused()) {
revert wUSDMPausedTransfers();
revert wUSDXPausedTransfers();
}

super._beforeTokenTransfer(from, to, amount);
Expand Down
9 changes: 7 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
OZ_PLATFORM_KEY,
OZ_PLATFORM_SECRET,
GOERLI_PRIVATE_KEY,
SEPOLIA_PRIVATE_KEY,
} = process.env;

const isTestEnv = NODE_ENV === 'test';
Expand Down Expand Up @@ -56,17 +57,21 @@ const config: HardhatUserConfig = {
etherscan: ETHERSCAN_API_KEY ? etherscanConfig : {},
defaultNetwork: 'hardhat',
networks: {
ganache: {
url: 'http://127.0.0.1:7545',
chainId: 5777,
},
goerli: {
url: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_GOERLI_API_KEY}`,
chainId: 5,
// Only add account if the PK is provided
...(GOERLI_PRIVATE_KEY ? { accounts: [GOERLI_PRIVATE_KEY] } : {}),
},
sepolia: {
url: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_SEPOLIA_API_KEY}`,
url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_SEPOLIA_API_KEY}`,
chainId: 11155111,
// Only add account if the PK is provided
// ...(SEPOLIA_PRIVATE_KEY ? { accounts: [SEPOLIA_PRIVATE_KEY] } : {}),
...(SEPOLIA_PRIVATE_KEY ? { accounts: [SEPOLIA_PRIVATE_KEY] } : {}),
},
mainnet: {
url: `https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_MAINNET_API_KEY}`,
Expand Down
Loading

0 comments on commit 50f563d

Please sign in to comment.