From 24e9524c06418a6425f8dd182bd0416927cbbad8 Mon Sep 17 00:00:00 2001 From: "Eugene Y. Q. Shen" Date: Sat, 14 Sep 2024 10:31:25 -0700 Subject: [PATCH] [NES-190] add named Proxy contracts (#4) --- nest/script/DeployNestContracts.s.sol | 19 +++++++++++-------- nest/src/AggregateToken.sol | 10 +++++----- nest/src/proxies/AggregateTokenProxy.sol | 15 +++++++++++++++ nest/src/proxies/FakeComponentTokenProxy.sol | 15 +++++++++++++++ 4 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 nest/src/proxies/AggregateTokenProxy.sol create mode 100644 nest/src/proxies/FakeComponentTokenProxy.sol diff --git a/nest/script/DeployNestContracts.s.sol b/nest/script/DeployNestContracts.s.sol index 92a8856..5a68323 100644 --- a/nest/script/DeployNestContracts.s.sol +++ b/nest/script/DeployNestContracts.s.sol @@ -4,10 +4,11 @@ pragma solidity ^0.8.25; import "forge-std/Script.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { Upgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol"; import { AggregateToken } from "../src/AggregateToken.sol"; import { FakeComponentToken } from "../src/FakeComponentToken.sol"; +import { AggregateTokenProxy } from "../src/proxies/AggregateTokenProxy.sol"; +import { FakeComponentTokenProxy } from "../src/proxies/FakeComponentTokenProxy.sol"; contract DeployNestContracts is Script { @@ -17,23 +18,25 @@ contract DeployNestContracts is Script { function run() external { vm.startBroadcast(ARC_ADMIN_ADDRESS); - address fakeComponentTokenProxy = Upgrades.deployUUPSProxy( - "FakeComponentToken.sol", + FakeComponentToken fakeComponentToken = new FakeComponentToken(); + FakeComponentTokenProxy fakeComponentTokenProxy = new FakeComponentTokenProxy( + address(fakeComponentToken), abi.encodeCall( FakeComponentToken.initialize, (ARC_ADMIN_ADDRESS, "Banana", "BAN", IERC20(USDC_ADDRESS), 18) ) ); - console.log("FakeComponentToken deployed to:", fakeComponentTokenProxy); + console.log("FakeComponentTokenProxy deployed to:", address(fakeComponentTokenProxy)); - address aggregateTokenProxy = Upgrades.deployUUPSProxy( - "AggregateToken.sol", + AggregateToken aggregateToken = new AggregateToken(); + AggregateTokenProxy aggregateTokenProxy = new AggregateTokenProxy( + address(aggregateToken), abi.encodeCall( AggregateToken.initialize, ( ARC_ADMIN_ADDRESS, "Apple", "AAPL", - IERC20(USDC_ADDRESS), + USDC_ADDRESS, 18, 15e17, 12e17, @@ -41,7 +44,7 @@ contract DeployNestContracts is Script { ) ) ); - console.log("AggregateToken deployed to:", aggregateTokenProxy); + console.log("AggregateTokenProxy deployed to:", address(aggregateTokenProxy)); vm.stopBroadcast(); } diff --git a/nest/src/AggregateToken.sol b/nest/src/AggregateToken.sol index 7d6e6a4..63443f5 100644 --- a/nest/src/AggregateToken.sol +++ b/nest/src/AggregateToken.sol @@ -141,7 +141,7 @@ contract AggregateToken is * @param owner Address of the owner of the AggregateToken * @param name Name of the AggregateToken * @param symbol Symbol of the AggregateToken - * @param currencyToken CurrencyToken used to mint and burn the AggregateToken + * @param currencyAddress Address of the CurrencyToken used to mint and burn the AggregateToken * @param decimals_ Number of decimals of the AggregateToken * @param askPrice Price at which users can buy the AggregateToken using CurrencyToken, times the base * @param bidPrice Price at which users can sell the AggregateToken to receive CurrencyToken, times the base @@ -151,7 +151,7 @@ contract AggregateToken is address owner, string memory name, string memory symbol, - IERC20 currencyToken, + address currencyAddress, uint8 decimals_, uint256 askPrice, uint256 bidPrice, @@ -165,9 +165,9 @@ contract AggregateToken is _grantRole(UPGRADER_ROLE, owner); AggregateTokenStorage storage $ = _getAggregateTokenStorage(); - $.componentTokenMap[currencyToken] = true; - $.componentTokenList.push(currencyToken); - $.currencyToken = currencyToken; + $.componentTokenMap[IComponentToken(currencyAddress)] = true; + $.componentTokenList.push(IComponentToken(currencyAddress)); + $.currencyToken = IERC20(currencyAddress); $.decimals = decimals_; $.askPrice = askPrice; $.bidPrice = bidPrice; diff --git a/nest/src/proxies/AggregateTokenProxy.sol b/nest/src/proxies/AggregateTokenProxy.sol new file mode 100644 index 0000000..ca92d96 --- /dev/null +++ b/nest/src/proxies/AggregateTokenProxy.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.25; + +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; + +/** + * @title AggregateTokenProxy + * @author Eugene Y. Q. Shen + * @notice Proxy contract for the AggregateToken + */ +contract AggregateTokenProxy is ERC1967Proxy { + + constructor(address logic, bytes memory data) ERC1967Proxy(logic, data) { } + +} diff --git a/nest/src/proxies/FakeComponentTokenProxy.sol b/nest/src/proxies/FakeComponentTokenProxy.sol new file mode 100644 index 0000000..0d486f8 --- /dev/null +++ b/nest/src/proxies/FakeComponentTokenProxy.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.25; + +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; + +/** + * @title FakeComponentTokenProxy + * @author Eugene Y. Q. Shen + * @notice Proxy contract for the FakeComponentToken + */ +contract FakeComponentTokenProxy is ERC1967Proxy { + + constructor(address logic, bytes memory data) ERC1967Proxy(logic, data) { } + +}