Skip to content

Commit

Permalink
[NES-254] add adapter contract for pUSD
Browse files Browse the repository at this point in the history
  • Loading branch information
eyqs committed Nov 13, 2024
1 parent fffd022 commit 2131910
Showing 2 changed files with 81 additions and 6 deletions.
15 changes: 9 additions & 6 deletions nest/script/DeployNestContracts.s.sol
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import { NestStaking } from "../src/NestStaking.sol";
import { IComponentToken } from "../src/interfaces/IComponentToken.sol";
import { AggregateTokenProxy } from "../src/proxy/AggregateTokenProxy.sol";
import { NestStakingProxy } from "../src/proxy/NestStakingProxy.sol";
import { pUSD } from "../src/token/pUSD.sol";

// Concrete implementation of ComponentToken
contract ConcreteComponentToken is ComponentToken {
@@ -35,15 +36,17 @@ contract ConcreteComponentToken is ComponentToken {
contract DeployNestContracts is Script, Test {

address private constant NEST_ADMIN_ADDRESS = 0xb015762405De8fD24d29A6e0799c12e0Ea81c1Ff;
address private constant PUSD_ADDRESS = 0xe644F07B1316f28a7F134998e021eA9f7135F351;
address private constant USDT_ADDRESS = 0x2413b8C79Ce60045882559f63d308aE3DFE0903d;

function test() public { }

function run() external {
vm.startBroadcast(NEST_ADMIN_ADDRESS);

IComponentToken USDT = IComponentToken(USDT_ADDRESS);
// Deploy pUSD
pUSD pUSDToken = new pUSD();
ERC1967Proxy pUSDProxy =
new ERC1967Proxy(address(pUSDToken), abi.encodeCall(pUSD.initialize, (NEST_ADMIN_ADDRESS)));
console2.log("pUSDProxy deployed to:", address(pUSDProxy));

// Deploy ConcreteComponentToken
ConcreteComponentToken componentToken = new ConcreteComponentToken();
@@ -55,7 +58,7 @@ contract DeployNestContracts is Script, Test {
NEST_ADMIN_ADDRESS, // owner
"Banana", // name
"BAN", // symbol
IERC20(USDT_ADDRESS), // asset token
IERC20(address(pUSDProxy)), // asset token
false, // async deposit
false // async redeem
)
@@ -73,7 +76,7 @@ contract DeployNestContracts is Script, Test {
NEST_ADMIN_ADDRESS,
"Apple",
"AAPL",
IComponentToken(PUSD_ADDRESS),
IComponentToken(address(pUSDProxy)),
1e17, // ask price
1e17 // bid price
)
@@ -82,7 +85,7 @@ contract DeployNestContracts is Script, Test {
console2.log("AggregateTokenProxy deployed to:", address(aggregateTokenProxy));

// Add new component tokens
AggregateToken(address(aggregateTokenProxy)).addComponentToken(USDT);
AggregateToken(address(aggregateTokenProxy)).addComponentToken(IComponentToken(address(pUSDProxy)));
AggregateToken(address(aggregateTokenProxy)).addComponentToken(IComponentToken(address(componentTokenProxy)));

// Deploy NestStaking
72 changes: 72 additions & 0 deletions nest/src/token/pUSD.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

/**
* @title pUSD
* @author Eugene Y. Q. Shen, Alp Guneysel
* @notice Unified Plume USD stablecoin
*/
contract pUSD is Initializable, ERC20Upgradeable, AccessControlUpgradeable, UUPSUpgradeable {

// Constants

/// @notice Role for the admin of pUSD
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
/// @notice Role for the upgrader of pUSD
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");

// Initializer

/**
* @notice Prevent the implementation contract from being initialized or reinitialized
* @custom:oz-upgrades-unsafe-allow constructor
*/
constructor() {
_disableInitializers();
}

/**
* @notice Initialize pUSD
* @dev Give all roles to the admin address passed into the constructor
* @param owner_ Address of the owner of pUSD
*/
function initialize(
address owner_
) public initializer {
__ERC20_init("Plume USD", "pUSD");
__AccessControl_init();
__UUPSUpgradeable_init();

_grantRole(DEFAULT_ADMIN_ROLE, owner_);
_grantRole(ADMIN_ROLE, owner_);
_grantRole(UPGRADER_ROLE, owner_);
}

// Override Functions

/**
* @notice Revert when `msg.sender` is not authorized to upgrade the contract
* @param newImplementation Address of the new implementation
*/
function _authorizeUpgrade(
address newImplementation
) internal override onlyRole(UPGRADER_ROLE) { }

function decimals() public pure override returns (uint8) {
return 6;
}

function name() public pure override returns (string memory) {
return "Plume USD";
}

function symbol() public pure override returns (string memory) {
return "pUSD";
}

}

0 comments on commit 2131910

Please sign in to comment.