From 7151ec1ec95b639ab2996b0ea3742f5e2e3f73e3 Mon Sep 17 00:00:00 2001 From: rndquu Date: Mon, 2 Oct 2023 10:44:46 +0300 Subject: [PATCH 1/3] refactor: move UbiquiStick from UUPS test helper --- .../diamond/facets/BondingCurveFacet.t.sol | 18 ++++++++++++++++++ .../contracts/test/helpers/UUPSTestHelper.sol | 16 ---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol b/packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol index fa33ea2d4..98c4442c0 100644 --- a/packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol +++ b/packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol @@ -4,7 +4,9 @@ pragma solidity 0.8.19; import "../DiamondTestSetup.sol"; import "../../../src/dollar/libraries/Constants.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {MockERC20} from "../../../src/dollar/mocks/MockERC20.sol"; +import {ERC1155Ubiquity} from "../../../src/dollar/core/ERC1155Ubiquity.sol"; import "forge-std/Test.sol"; contract BondingCurveFacetTest is DiamondSetup { @@ -33,6 +35,22 @@ contract BondingCurveFacetTest is DiamondSetup { address(diamond) ); + // deploy UbiquiStick + bytes memory initData = abi.encodeWithSignature( + "__ERC1155Ubiquity_init(address,string)", + diamond, + "" + ); + ERC1967Proxy proxyUbiquiStick = new ERC1967Proxy( + address(new ERC1155Ubiquity()), + initData + ); + ERC1155Ubiquity ubiquiStick = ERC1155Ubiquity( + address(proxyUbiquiStick) + ); + + IManager.setUbiquistickAddress(address(ubiquiStick)); + vm.stopPrank(); } } diff --git a/packages/contracts/test/helpers/UUPSTestHelper.sol b/packages/contracts/test/helpers/UUPSTestHelper.sol index 696726e66..21769d096 100644 --- a/packages/contracts/test/helpers/UUPSTestHelper.sol +++ b/packages/contracts/test/helpers/UUPSTestHelper.sol @@ -8,7 +8,6 @@ import {UbiquityCreditToken} from "../../src/dollar/core/UbiquityCreditToken.sol import {StakingShare} from "../../src/dollar/core/StakingShare.sol"; import {CreditNft} from "../../src/dollar/core/CreditNft.sol"; import {ManagerFacet} from "../../src/dollar/facets/ManagerFacet.sol"; -import {ERC1155Ubiquity} from "../../src/dollar/core/ERC1155Ubiquity.sol"; import "../../src/dollar/libraries/Constants.sol"; import "forge-std/Test.sol"; @@ -27,7 +26,6 @@ contract UUPSTestHelper { UbiquityCreditToken creditToken; UbiquityDollarToken dollarToken; UbiquityGovernanceToken governanceToken; - ERC1155Ubiquity ubiquiStick; // proxies for core contracts ERC1967Proxy proxyCreditNft; @@ -88,22 +86,8 @@ contract UUPSTestHelper { address(proxyGovernanceToken) ); - // deploy UbiquiStick (not a core contract, not upgradeable) - // TODO: move from UUPSTestHelper to a more relevant place - initData = abi.encodeWithSignature( - "__ERC1155Ubiquity_init(address,string)", - diamond, - uri - ); - proxyUbiquiStick = new ERC1967Proxy( - address(new ERC1155Ubiquity()), - initData - ); - ubiquiStick = ERC1155Ubiquity(address(proxyUbiquiStick)); - // set addresses of the newly deployed contracts in the Diamond ManagerFacet managerFacet = ManagerFacet(diamond); - managerFacet.setUbiquistickAddress(address(ubiquiStick)); managerFacet.setStakingShareAddress(address(stakingShare)); managerFacet.setCreditTokenAddress(address(creditToken)); managerFacet.setDollarTokenAddress(address(dollarToken)); From 80a21d3c2541b18f312aeb57dfc3b86a8720b999 Mon Sep 17 00:00:00 2001 From: rndquu Date: Mon, 2 Oct 2023 11:05:42 +0300 Subject: [PATCH 2/3] fix: mint UbiquiStick in LibBondingCurve --- .../src/dollar/libraries/LibBondingCurve.sol | 6 +++--- .../test/diamond/facets/BondingCurveFacet.t.sol | 17 ++++------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/contracts/src/dollar/libraries/LibBondingCurve.sol b/packages/contracts/src/dollar/libraries/LibBondingCurve.sol index 65205c608..22544d998 100644 --- a/packages/contracts/src/dollar/libraries/LibBondingCurve.sol +++ b/packages/contracts/src/dollar/libraries/LibBondingCurve.sol @@ -5,6 +5,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import {LibAppStorage} from "./LibAppStorage.sol"; +import {UbiquiStick} from "../../ubiquistick/UbiquiStick.sol"; import "../../ubiquistick/interfaces/IUbiquiStick.sol"; import "../interfaces/IERC1155Ubiquity.sol"; import "./Constants.sol"; @@ -132,14 +133,13 @@ library LibBondingCurve { dollar.transferFrom(_recipient, address(this), _collateralDeposited); ss.poolBalance = ss.poolBalance + _collateralDeposited; - bytes memory tokReturned = toBytes(tokensReturned); ss.share[_recipient] += tokensReturned; ss.tokenIds += 1; - IERC1155Ubiquity bNFT = IERC1155Ubiquity( + UbiquiStick ubiquiStick = UbiquiStick( LibAppStorage.appStorage().ubiquiStickAddress ); - bNFT.mint(_recipient, ss.tokenIds, tokensReturned, tokReturned); + ubiquiStick.batchSafeMint(_recipient, tokensReturned); emit Deposit(_recipient, _collateralDeposited); } diff --git a/packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol b/packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol index 98c4442c0..9a6e64880 100644 --- a/packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol +++ b/packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {MockERC20} from "../../../src/dollar/mocks/MockERC20.sol"; import {ERC1155Ubiquity} from "../../../src/dollar/core/ERC1155Ubiquity.sol"; +import {UbiquiStick} from "../../../src/ubiquistick/UbiquiStick.sol"; import "forge-std/Test.sol"; contract BondingCurveFacetTest is DiamondSetup { @@ -30,25 +31,15 @@ contract BondingCurveFacetTest is DiamondSetup { super.setUp(); vm.startPrank(admin); + IAccessControl.grantRole( GOVERNANCE_TOKEN_MINTER_ROLE, address(diamond) ); // deploy UbiquiStick - bytes memory initData = abi.encodeWithSignature( - "__ERC1155Ubiquity_init(address,string)", - diamond, - "" - ); - ERC1967Proxy proxyUbiquiStick = new ERC1967Proxy( - address(new ERC1155Ubiquity()), - initData - ); - ERC1155Ubiquity ubiquiStick = ERC1155Ubiquity( - address(proxyUbiquiStick) - ); - + UbiquiStick ubiquiStick = new UbiquiStick(); + ubiquiStick.setMinter(address(diamond)); IManager.setUbiquistickAddress(address(ubiquiStick)); vm.stopPrank(); From d425427efac58a518bacf8c587aa3cea0f38fb4e Mon Sep 17 00:00:00 2001 From: rndquu Date: Mon, 2 Oct 2023 11:09:04 +0300 Subject: [PATCH 3/3] refactor: make ERC1155Ubiquity abstract --- packages/contracts/src/dollar/core/ERC1155Ubiquity.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol b/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol index 6f82fe3c1..6c211deb5 100644 --- a/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol +++ b/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol @@ -18,7 +18,7 @@ import "../../../src/dollar/utils/SafeAddArray.sol"; * - TotalSupply per id * - Ubiquity Manager access control */ -contract ERC1155Ubiquity is +abstract contract ERC1155Ubiquity is Initializable, ERC1155BurnableUpgradeable, ERC1155PausableUpgradeable, @@ -84,7 +84,7 @@ contract ERC1155Ubiquity is function __ERC1155Ubiquity_init( address _manager, string memory _uri - ) public initializer onlyInitializing { + ) internal onlyInitializing { // init base contracts __ERC1155_init(_uri); __ERC1155Burnable_init(); @@ -98,7 +98,7 @@ contract ERC1155Ubiquity is /// @param _manager Address of the manager of the contract function __ERC1155Ubiquity_init_unchained( address _manager - ) public initializer onlyInitializing { + ) internal onlyInitializing { accessControl = IAccessControl(_manager); }