diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 1d97a70..0000000 --- a/.gitmodules +++ /dev/null @@ -1,23 +0,0 @@ -[submodule "lib/forge-std"] - path = lib/forge-std - url = https://github.com/foundry-rs/forge-std - ignore = dirty -[submodule "lib/solidity-stringutils"] - path = lib/solidity-stringutils - url = https://github.com/Arachnid/solidity-stringutils - ignore = dirty -[submodule "lib/prb-math"] - path = lib/prb-math - url = https://github.com/PaulRBerg/prb-math - ignore = dirty -[submodule "lib/openzeppelin-contracts-upgradeable"] - path = lib/openzeppelin-contracts-upgradeable - url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable - version = v4.7.3 -[submodule "lib/openzeppelin-contracts"] - path = lib/openzeppelin-contracts - url = https://github.com/OpenZeppelin/openzeppelin-contracts - version = v4.7.3 -[submodule "lib/utils"] - path = lib/utils - url = https://github.com/AngleProtocol/utils diff --git a/.npmrc b/.npmrc deleted file mode 100644 index af66bba..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -@angleprotocol:registry=https://npm.pkg.github.com diff --git a/README.md b/README.md index 9f1dcfc..3281991 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,62 @@ -# Transmuter Angle - Transmuter +# Parallel - Parallelizer -[![Transmuter CI](https://github.com/AngleProtocol/angle-transmuter/actions/workflows/ci.yml/badge.svg)](https://github.com/AngleProtocol/angle-transmuter/actions) -[![Coverage](https://codecov.io/gh/AngleProtocol/angle-transmuter/branch/main/graph/badge.svg)](https://codecov.io/gh/AngleProtocol/angle-transmuter) +## What is Parallelizer? -## What is Transmuter? - -Transmuter is an autonomous and modular price stability module for decentralized stablecoin protocols. +**Parallelizer is friendly fork of Angle's Transmuter which is an autonomous and modular price stability module for +decentralized stablecoin protocols.** - It is conceived as a basket of different assets (normally stablecoins) backing a stablecoin and comes with guarantees on the maximum exposure the stablecoin can have to each asset in the basket. -- A stablecoin issued through the Transmuter system can be minted at oracle value from any of the assets with adaptive +- A stablecoin issued through the Parallelizer system can be minted at oracle value from any of the assets with adaptive fees, and it can be burnt for any of the assets in the backing with variable fees as well. It can also be redeemed at any time against a proportional amount of each asset in the backing. -Transmuter is compatible with other common mechanisms often used to issue stablecoins like collateralized-debt position -models. It is notably used as a standalone module within the Angle Protocol for EURA in parallel with the Borrowing -module. +Parallelizer is compatible with other common mechanisms often used to issue stablecoins like collateralized-debt +position models. --- ## Contracts Architecture 🏘️ -The Transmuter system relies on a [diamond proxy pattern](https://eips.ethereum.org/EIPS/eip-2535). There is as such -only one main contract (the `Transmuter` contract) which delegates calls to different facets each with their own +The Parallelizer system relies on a [diamond proxy pattern](https://eips.ethereum.org/EIPS/eip-2535). There is as such +only one main contract (the `Parallelizer` contract) which delegates calls to different facets each with their own implementation. The main facets of the system are: -- the [`Swapper`](./contracts/transmuter/facets/Swapper.sol) facet with the logic associated to the mint and burn +- the [`Swapper`](./contracts/parallelizer/facets/Swapper.sol) facet with the logic associated to the mint and burn functionalities of the system -- the [`Redeemer`](./contracts/transmuter/facets/Redeemer.sol) facet for redemptions -- the [`Getters`](./contracts/transmuter/facets/Getters.sol) facet with external getters for UIs and contracts built on - top of `Transmuter` -- the [`SettersGovernor`](./contracts/transmuter/facets/SettersGovernor.sol) facet protocols' governance can use to +- the [`Redeemer`](./contracts/parallelizer/facets/Redeemer.sol) facet for redemptions +- the [`Getters`](./contracts/parallelizer/facets/Getters.sol) facet with external getters for UIs and contracts built + on top of `Parallelizer` +- the [`SettersGovernor`](./contracts/parallelizer/facets/SettersGovernor.sol) facet protocols' governance can use to + update system parameters. +- the [`SettersGuardian`](./contracts/parallelizer/facets/SettersGuardian.sol) facet protocols' guardian can use to update system parameters. -- the [`SettersGuardian`](./contracts/transmuter/facets/SettersGuardian.sol) facet protocols' guardian can use to update - system parameters. -The storage parameters of the system are defined in the [`Storage`](./contracts/transmuter/Storage.sol) file. +The storage parameters of the system are defined in the [`Storage`](./contracts/parallelizer/Storage.sol) file. -The Transmuter system can come with optional [ERC4626](https://eips.ethereum.org/EIPS/eip-4626) +The Parallelizer system can come with optional [ERC4626](https://eips.ethereum.org/EIPS/eip-4626) [savings contracts](./contracts/savings/) which can be used to distribute a yield to the holders of the stablecoin -issued through the Transmuter. +issued through the Parallelizer. --- +## Changed with Angle's Transmuter + +Some changed has been made to the original Angle's Transmuter: + +- Move from foundry gitmodule to Js dependencies +- Move from Yarn to Bun +- Move from AccessControl logics to Openzeppelin's AccessManaged +- Move from TransparentUpgradeableProxy to UUPSUpdgradeableProxy +- Restrict function to only one role due to AccessManager/AccessManaged logic (that means that Governor must also got + Guardian role). +- Remove files that will not be used by Parallel (`SavingsVest.sol`, some `Configs/`, etc.) +- Renamed contracts (`AgToken` -> `TokenP`, `Transmuter` -> `Parallelizer`) + ## Documentation 📚 +### Angle documentation + - [Transmuter Whitepaper](https://docs.angle.money/overview/whitepapers) - [Angle Documentation](https://docs.angle.money) - [Angle Developers Documentation](https://developers.angle.money) @@ -53,7 +65,7 @@ issued through the Transmuter. ## Security ⛑️ -### Trust assumptions of the Transmuter system +### Trust assumptions of the Parallelizer system The governor role, which will be a multisig or an onchain governance, has all rights, including upgrading contracts, removing funds, changing the code, etc. @@ -76,26 +88,19 @@ shouldn't be able to extract funds from the system. ### Audits -The Transmuter and savings smart contracts have been audited by Code4rena, find the audit report +#### Angle audits + +The Angle's Transmuter and savings smart contracts have been audited by Code4rena, find the audit report [here](https://code4rena.com/reports/2023-06-angle). --- ### Bug Bounty -For contracts deployed for the Angle Protocol, a bug bounty is open on [Immunefi](https://immunefi.com) and -[Hats Finance](https://hats.finance). The rewards and scope of the Angle Immunefi are defined -[here](https://immunefi.com/bounty/angleprotocol/). - --- ## Deployment Addresses 🚦 -- Transmuter for EURA on Ethereum: - [0x00253582b2a3FE112feEC532221d9708c64cEFAb](https://etherscan.io/address/0x00253582b2a3FE112feEC532221d9708c64cEFAb) -- Transmuter for USDA on Ethereum: - [0x222222fD79264BBE280b4986F6FEfBC3524d0137](https://etherscan.io/address/0x222222fD79264BBE280b4986F6FEfBC3524d0137) - --- ## Development 🛠️ @@ -117,25 +122,12 @@ source /root/.zshrc foundryup ``` -To install the standard library: - -```bash -forge install foundry-rs/forge-std -``` - -To update libraries: - -```bash -forge update -``` - #### Install packages You can install all dependencies by running ```bash -yarn -forge i +bun install ``` ### Warning @@ -169,8 +161,8 @@ However, tests do not compile with via-ir, and to run coverage the optimizer nee and test purposes you can compile without optimizer. ```bash -yarn compile # with via-ir but without compiling tests files -yarn compile:dev # without optimizer +bun run compile # with via-ir but without compiling tests files +bun run compile:dev # without optimizer ``` ### Testing @@ -178,7 +170,7 @@ yarn compile:dev # without optimizer Here are examples of how to run the test suite: ```bash -yarn test +bun run test FOUNDRY_PROFILE=dev forge test -vvv --watch # To watch changing files FOUNDRY_PROFILE=dev forge test -vvv --match-path test/fuzz/Redeemer.test.sol FOUNDRY_PROFILE=dev forge test -vvv --match-test "testAbc*" @@ -199,29 +191,7 @@ FOUNDRY_PROFILE=dev forge test --list --json --match-test "testXXX*" There is an example script in the `scripts/foundry` folder. Then you can run: ```bash -yarn deploy --rpc-url -``` - ---- - -### Fork - -If you first want to test your deployments/scripts in fork mode. You should run: - -```bash -source .env -``` - -Then fork the network of your choice, by adding the associated script in the `package.json` - -```bash -yarn fork: -``` - -Finnaly run your script in fork mode: - -```bash -yarn deploy:fork +bun run deploy --rpc-url ``` --- @@ -231,7 +201,7 @@ yarn deploy:fork We recommend the use of this [vscode extension](ryanluker.vscode-coverage-gutters). ```bash -yarn coverage +bun run coverage ``` You'll need to install lcov `brew install lcov` to visualize the coverage report. @@ -241,7 +211,7 @@ You'll need to install lcov `brew install lcov` to visualize the coverage report ### Gas report ⛽️ ```bash -yarn gas +bun run gas ``` --- @@ -256,9 +226,9 @@ To get the dummy implementation, solution is to: - download the [repo](https://github.com/zdenham/diamond-etherscan/blob/main/README.md) and follow the instructions - upload the dummy implementation [here](./scripts/generated/DummyDiamondImplementation.sol) -- if the address used has ownership on the Transmuter contracts, run +- if the address used has ownership on the Parallelizer contracts, run [this script](./scripts/gnosis/VerifyProxyEtherscan.s.sol) to deploy the new dummy facet and add it to the whole - Transmuter system + Parallelizer system - go to Etherscan and point the `DiamondProxy` to the `DiamondEtherscanFacet` contract Every time a facet is updated with a new function or a change in interface, a new dummy implementation should be @@ -270,7 +240,7 @@ implementation. ### [Slither](https://github.com/crytic/slither) ```bash -yarn slither +bun run slither ``` --- @@ -294,6 +264,6 @@ The primary license for this repository is the Business Source License 1.1 (`BUS Minus the following exceptions: - [Interfaces](contracts/interfaces/) have a General Public License -- [Some libraries](contracts/transmuter/libraries/LibHelpers.sol) have a General Public License +- [Some libraries](contracts/parallelizer/libraries/LibHelpers.sol) have a General Public License Each of these files states their license type. diff --git a/contracts/helpers/BaseHarvester.sol b/contracts/helpers/BaseHarvester.sol index ddae3c9..6c16461 100644 --- a/contracts/helpers/BaseHarvester.sol +++ b/contracts/helpers/BaseHarvester.sol @@ -4,8 +4,8 @@ pragma solidity 0.8.28; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { AccessManaged } from "../utils/AccessManaged.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { ITransmuter } from "../interfaces/ITransmuter.sol"; -import { IAgToken } from "../interfaces/IAgToken.sol"; +import { IParallelizer } from "../interfaces/IParallelizer.sol"; +import { ITokenP } from "../interfaces/ITokenP.sol"; import "../utils/Errors.sol"; import "../interfaces/IHarvester.sol"; @@ -15,18 +15,21 @@ struct YieldBearingParams { address asset; // Target exposure to the collateral yield bearing asset used uint64 targetExposure; - // Maximum exposure within the Transmuter to the deposit asset + // Maximum exposure within the Parallelizer to the deposit asset uint64 maxExposure; - // Minimum exposure within the Transmuter to the deposit asset + // Minimum exposure within the Parallelizer to the deposit asset uint64 minExposure; - // Whether limit exposures should be overriden or read onchain through the Transmuter + // Whether limit exposures should be overriden or read onchain through the Parallelizer // This value should be 1 to override exposures or 2 if these shouldn't be overriden uint64 overrideExposures; } /// @title BaseHarvester -/// @author Angle Labs, Inc. -/// @dev Abstract contract for a harvester that aims at rebalancing a Transmuter +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev Abstract contract for a harvester that aims at rebalancing a Parallelizer +/// @dev This contract is a friendly fork of Angle's BaseHarvester contract: +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/helpers/BaseHarvester.sol abstract contract BaseHarvester is IHarvester, AccessManaged { using SafeERC20 for IERC20; @@ -58,11 +61,11 @@ abstract contract BaseHarvester is IHarvester, AccessManaged { VARIABLES //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ - /// @notice Reference to the `transmuter` implementation this contract aims at rebalancing - ITransmuter public immutable transmuter; - /// @notice AgToken handled by the `transmuter` of interest - IAgToken public immutable agToken; - /// @notice Max slippage when dealing with the Transmuter + /// @notice Reference to the `parallelizer` implementation this contract aims at rebalancing + IParallelizer public immutable parallelizer; + /// @notice TokenP handled by the `parallelizer` of interest + ITokenP public immutable tokenP; + /// @notice Max slippage when dealing with the Parallelizer uint96 public maxSlippage; /// @notice Data associated to a yield bearing asset mapping(address => YieldBearingParams) public yieldBearingData; @@ -83,14 +86,14 @@ abstract contract BaseHarvester is IHarvester, AccessManaged { constructor( uint96 initialMaxSlippage, address initialAuthority, - IAgToken definitiveAgToken, - ITransmuter definitiveTransmuter + ITokenP definitiveTokenP, + IParallelizer definitiveParallelizer ) AccessManaged(initialAuthority) { _setMaxSlippage(initialMaxSlippage); - agToken = definitiveAgToken; - transmuter = definitiveTransmuter; + tokenP = definitiveTokenP; + parallelizer = definitiveParallelizer; } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -102,9 +105,9 @@ abstract contract BaseHarvester is IHarvester, AccessManaged { * @param yieldBearingAsset address of the yieldBearingAsset * @param asset address of the asset * @param targetExposure target exposure to the yieldBearingAsset asset used - * @param minExposure minimum exposure within the Transmuter to the asset - * @param maxExposure maximum exposure within the Transmuter to the asset - * @param overrideExposures whether limit exposures should be overriden or read onchain through the Transmuter + * @param minExposure minimum exposure within the Parallelizer to the asset + * @param maxExposure maximum exposure within the Parallelizer to the asset + * @param overrideExposures whether limit exposures should be overriden or read onchain through the Parallelizer */ function setYieldBearingAssetData( address yieldBearingAsset, @@ -177,7 +180,7 @@ abstract contract BaseHarvester is IHarvester, AccessManaged { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /** - * @notice Compute the amount needed to rebalance the Transmuter + * @notice Compute the amount needed to rebalance the Parallelizer * @param yieldBearingAsset address of the yield bearing asset * @return increase whether the exposure should be increased * @return amount amount to be rebalanced @@ -199,8 +202,8 @@ abstract contract BaseHarvester is IHarvester, AccessManaged { returns (uint8 increase, uint256 amount) { (uint256 stablecoinsFromYieldBearingAsset, uint256 stablecoinsIssued) = - transmuter.getIssuedByCollateral(yieldBearingAsset); - (uint256 stablecoinsFromAsset,) = transmuter.getIssuedByCollateral(yieldBearingInfo.asset); + parallelizer.getIssuedByCollateral(yieldBearingAsset); + (uint256 stablecoinsFromAsset,) = parallelizer.getIssuedByCollateral(yieldBearingInfo.asset); uint256 targetExposureScaled = yieldBearingInfo.targetExposure * stablecoinsIssued; if (stablecoinsFromYieldBearingAsset * 1e9 > targetExposureScaled) { // Need to decrease exposure to yield bearing asset @@ -261,13 +264,13 @@ abstract contract BaseHarvester is IHarvester, AccessManaged { virtual { uint64[] memory xFeeMint; - (xFeeMint,) = transmuter.getCollateralMintFees(asset); + (xFeeMint,) = parallelizer.getCollateralMintFees(asset); uint256 length = xFeeMint.length; if (length <= 1) yieldBearingInfo.maxExposure = 1e9; else yieldBearingInfo.maxExposure = xFeeMint[length - 2]; uint64[] memory xFeeBurn; - (xFeeBurn,) = transmuter.getCollateralBurnFees(asset); + (xFeeBurn,) = parallelizer.getCollateralBurnFees(asset); length = xFeeBurn.length; if (length <= 1) yieldBearingInfo.minExposure = 0; else yieldBearingInfo.minExposure = xFeeBurn[length - 2]; diff --git a/contracts/helpers/GenericHarvester.sol b/contracts/helpers/GenericHarvester.sol index 6ad6103..f259696 100644 --- a/contracts/helpers/GenericHarvester.sol +++ b/contracts/helpers/GenericHarvester.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; @@ -10,8 +9,8 @@ import { IERC3156FlashBorrower } from "@openzeppelin/contracts/interfaces/IERC31 import { IERC3156FlashLender } from "@openzeppelin/contracts/interfaces/IERC3156FlashLender.sol"; import { RouterSwapper } from "@helpers/RouterSwapper.sol"; -import { ITransmuter } from "interfaces/ITransmuter.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { IParallelizer } from "interfaces/IParallelizer.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; import { IERC4626 } from "interfaces/external/IERC4626.sol"; import "utils/Constants.sol"; @@ -25,8 +24,11 @@ enum SwapType { } /// @title GenericHarvester -/// @author Angle Labs, Inc. -/// @dev Generic contract for anyone to permissionlessly adjust the reserves of Angle Transmuter +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev Generic contract for anyone to permissionlessly adjust the reserves of Angle Parallelizer +/// @dev This contract is a friendly fork of Angle's GenericHarvester contract: +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/helpers/GenericHarvester.sol contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper { using SafeCast for uint256; using SafeERC20 for IERC20; @@ -35,7 +37,7 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper /// @notice Angle stablecoin flashloan contract IERC3156FlashLender public immutable flashloan; - /// @notice Budget of AGToken available for each users + /// @notice Budget of tokenP available for each users mapping(address => uint256) public budget; /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -46,18 +48,18 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper uint96 initialMaxSlippage, address initialTokenTransferAddress, address initialSwapRouter, - IAgToken definitiveAgToken, - ITransmuter definitiveTransmuter, + ITokenP definitivetokenP, + IParallelizer definitiveParallelizer, address initialAuthority, IERC3156FlashLender definitiveFlashloan ) RouterSwapper(initialSwapRouter, initialTokenTransferAddress) - BaseHarvester(initialMaxSlippage, initialAuthority, definitiveAgToken, definitiveTransmuter) + BaseHarvester(initialMaxSlippage, initialAuthority, definitivetokenP, definitiveParallelizer) { if (address(definitiveFlashloan) == address(0)) revert ZeroAddress(); flashloan = definitiveFlashloan; - IERC20(agToken).approve(address(definitiveFlashloan), type(uint256).max); + IERC20(tokenP).approve(address(definitiveFlashloan), type(uint256).max); } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -66,24 +68,24 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper /** * @notice Add budget to be spent by the receiver during the flashloan - * @param amount amount of AGToken to add to the budget + * @param amount amount of tokenP to add to the budget * @param receiver address of the receiver */ function addBudget(uint256 amount, address receiver) public virtual { budget[receiver] += amount; - IERC20(agToken).safeTransferFrom(msg.sender, address(this), amount); + IERC20(tokenP).safeTransferFrom(msg.sender, address(this), amount); } /** * @notice Remove budget from the owner and send it to the receiver - * @param amount amount of AGToken to remove from the budget + * @param amount amount of tokenP to remove from the budget * @param receiver address of the receiver */ function removeBudget(uint256 amount, address receiver) public virtual { budget[msg.sender] -= amount; // Will revert if not enough funds - IERC20(agToken).safeTransfer(receiver, amount); + IERC20(tokenP).safeTransfer(receiver, amount); } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -92,11 +94,11 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper /// @notice Invests or divests from the yield asset associated to `yieldBearingAsset` based on the current exposure /// to this yieldBearingAsset - /// @dev This transaction either reduces the exposure to `yieldBearingAsset` in the Transmuter or frees up + /// @dev This transaction either reduces the exposure to `yieldBearingAsset` in the Parallelizer or frees up /// some yieldBearingAsset that can then be used for people looking to burn deposit tokens - /// @dev Due to potential transaction fees within the Transmuter, this function doesn't exactly bring + /// @dev Due to potential transaction fees within the Parallelizer, this function doesn't exactly bring /// `yieldBearingAsset` to the target exposure - /// @dev scale is a number between 0 and 1e9 that represents the proportion of the agToken to harvest, + /// @dev scale is a number between 0 and 1e9 that represents the proportion of the tokenP to harvest, /// it is used to lower the amount of the asset to harvest for example to have a lower slippage function harvest(address yieldBearingAsset, uint256 scale, bytes calldata extraData) public virtual { if (scale > 1e9) revert InvalidParam(); @@ -106,7 +108,7 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper if (amount == 0) revert ZeroAmount(); (SwapType swapType, bytes memory data) = abi.decode(extraData, (SwapType, bytes)); - try transmuter.updateOracle(yieldBearingInfo.asset) { } catch { } + try parallelizer.updateOracle(yieldBearingInfo.asset) { } catch { } adjustYieldExposure( amount, increase, yieldBearingAsset, yieldBearingInfo.asset, (amount * (1e9 - maxSlippage)) / 1e9, swapType, data ); @@ -115,8 +117,8 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper /// @notice Burns `amountStablecoins` for one yieldBearing asset, swap for asset then mints deposit tokens /// from the proceeds of the swap. /// @dev If `increase` is 1, then the system tries to increase its exposure to the yield bearing asset which means - /// burning agToken for the deposit asset, swapping for the yield bearing asset, then minting the agToken - /// @dev This function reverts if the second agToken mint gives less than `minAmountOut` of ag tokens + /// burning tokenP for the deposit asset, swapping for the yield bearing asset, then minting the tokenP + /// @dev This function reverts if the second tokenP mint gives less than `minAmountOut` of ag tokens /// @dev This function reverts if the swap slippage is higher than `maxSlippage` function adjustYieldExposure( uint256 amountStablecoins, @@ -132,7 +134,7 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper { flashloan.flashLoan( IERC3156FlashBorrower(address(this)), - address(agToken), + address(tokenP), amountStablecoins, abi.encode(msg.sender, increase, yieldBearingAsset, asset, minAmountOut, swapType, extraData) ); @@ -173,14 +175,15 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper tokenOut = asset; } } - uint256 amountOut = transmuter.swapExactInput(amount, 0, address(agToken), tokenIn, address(this), block.timestamp); + uint256 amountOut = + parallelizer.swapExactInput(amount, 0, address(tokenP), tokenIn, address(this), block.timestamp); // Swap to tokenIn amountOut = _swapToTokenOut(typeAction, tokenIn, tokenOut, amountOut, swapType, callData); - _adjustAllowance(tokenOut, address(transmuter), amountOut); + _adjustAllowance(tokenOut, address(parallelizer), amountOut); uint256 amountStableOut = - transmuter.swapExactInput(amountOut, minAmountOut, tokenOut, address(agToken), address(this), block.timestamp); + parallelizer.swapExactInput(amountOut, minAmountOut, tokenOut, address(tokenP), address(this), block.timestamp); if (amount > amountStableOut) { budget[sender] -= amount - amountStableOut; // Will revert if not enough funds } diff --git a/contracts/helpers/MultiBlockHarvester.sol b/contracts/helpers/MultiBlockHarvester.sol index ef6ff0a..cc4b450 100644 --- a/contracts/helpers/MultiBlockHarvester.sol +++ b/contracts/helpers/MultiBlockHarvester.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; @@ -7,16 +6,19 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { BaseHarvester, YieldBearingParams } from "./BaseHarvester.sol"; -import { ITransmuter } from "../interfaces/ITransmuter.sol"; -import { IAgToken } from "../interfaces/IAgToken.sol"; +import { IParallelizer } from "../interfaces/IParallelizer.sol"; +import { ITokenP } from "../interfaces/ITokenP.sol"; import { IPool } from "../interfaces/IPool.sol"; import "../utils/Errors.sol"; import "../utils/Constants.sol"; /// @title MultiBlockHarvester -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @dev Contract to harvest yield from multiple yield bearing assets in multiple blocks transactions +/// @dev This contract is a friendly fork of Angle's MultiBlockHarvester contract: +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/helpers/MultiBlockHarvester.sol contract MultiBlockHarvester is BaseHarvester { using SafeERC20 for IERC20; using Math for uint256; @@ -35,10 +37,10 @@ contract MultiBlockHarvester is BaseHarvester { constructor( uint96 initialMaxSlippage, address initialAuthority, - IAgToken definitiveAgToken, - ITransmuter definitiveTransmuter + ITokenP definitivetokenP, + IParallelizer definitiveParallelizer ) - BaseHarvester(initialMaxSlippage, initialAuthority, definitiveAgToken, definitiveTransmuter) + BaseHarvester(initialMaxSlippage, initialAuthority, definitivetokenP, definitiveParallelizer) { } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -70,7 +72,7 @@ contract MultiBlockHarvester is BaseHarvester { amount = (amount * scale) / 1e9; if (amount == 0) revert ZeroAmount(); - try transmuter.updateOracle(yieldBearingAsset) { } catch { } + try parallelizer.updateOracle(yieldBearingAsset) { } catch { } _rebalance(increase, yieldBearingAsset, yieldBearingInfo, amount); } @@ -79,10 +81,10 @@ contract MultiBlockHarvester is BaseHarvester { * @param yieldBearingAsset address of the yieldBearingAsset */ function finalizeRebalance(address yieldBearingAsset, uint256 balance) external onlyTrusted { - try transmuter.updateOracle(yieldBearingAsset) { } catch { } - _adjustAllowance(yieldBearingAsset, address(transmuter), balance); + try parallelizer.updateOracle(yieldBearingAsset) { } catch { } + _adjustAllowance(yieldBearingAsset, address(parallelizer), balance); uint256 amountOut = - transmuter.swapExactInput(balance, 0, yieldBearingAsset, address(agToken), address(this), block.timestamp); + parallelizer.swapExactInput(balance, 0, yieldBearingAsset, address(tokenP), address(this), block.timestamp); address depositAddress = yieldBearingAsset == XEVT ? yieldBearingToDepositAddress[yieldBearingAsset] : address(0); _checkSlippage(balance, amountOut, yieldBearingAsset, depositAddress, true); } @@ -99,25 +101,25 @@ contract MultiBlockHarvester is BaseHarvester { ) internal { - _adjustAllowance(address(agToken), address(transmuter), amount); + _adjustAllowance(address(tokenP), address(parallelizer), amount); address depositAddress = yieldBearingToDepositAddress[yieldBearingAsset]; if (typeAction == 1) { uint256 amountOut = - transmuter.swapExactInput(amount, 0, address(agToken), yieldBearingInfo.asset, address(this), block.timestamp); + parallelizer.swapExactInput(amount, 0, address(tokenP), yieldBearingInfo.asset, address(this), block.timestamp); if (yieldBearingAsset == XEVT) { _adjustAllowance(yieldBearingInfo.asset, address(depositAddress), amountOut); (uint256 shares,) = IPool(depositAddress).deposit(amountOut, address(this)); - _adjustAllowance(yieldBearingAsset, address(transmuter), shares); + _adjustAllowance(yieldBearingAsset, address(parallelizer), shares); amountOut = - transmuter.swapExactInput(shares, 0, yieldBearingAsset, address(agToken), address(this), block.timestamp); - _checkSlippage(amount, amountOut, address(agToken), depositAddress, false); + parallelizer.swapExactInput(shares, 0, yieldBearingAsset, address(tokenP), address(this), block.timestamp); + _checkSlippage(amount, amountOut, address(tokenP), depositAddress, false); } else if (yieldBearingAsset == USDM) { IERC20(yieldBearingInfo.asset).safeTransfer(depositAddress, amountOut); _checkSlippage(amount, amountOut, yieldBearingInfo.asset, depositAddress, false); } } else { uint256 amountOut = - transmuter.swapExactInput(amount, 0, address(agToken), yieldBearingAsset, address(this), block.timestamp); + parallelizer.swapExactInput(amount, 0, address(tokenP), yieldBearingAsset, address(this), block.timestamp); _checkSlippage(amount, amountOut, yieldBearingAsset, depositAddress, false); if (yieldBearingAsset == XEVT) { IPool(depositAddress).requestRedeem(amountOut); @@ -145,7 +147,7 @@ contract MultiBlockHarvester is BaseHarvester { amountIn = _scaleAmountBasedOnDecimals(IERC20Metadata(asset).decimals(), 18, amountIn, assetIn); uint256 result; - if (asset == USDC || asset == USDM || asset == EURC || asset == address(agToken)) { + if (asset == USDC || asset == USDM || asset == EURC || asset == address(tokenP)) { // Assume 1:1 ratio between stablecoins (, result) = amountIn.trySub(amountOut); } else if (asset == XEVT) { diff --git a/contracts/interfaces/IAccessControlManager.sol b/contracts/interfaces/IAccessControlManager.sol deleted file mode 100644 index 743e9bb..0000000 --- a/contracts/interfaces/IAccessControlManager.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 - -pragma solidity 0.8.28; - -/// @title IAccessControlManager -/// @author Angle Labs, Inc. -interface IAccessControlManager { - /// @notice Checks whether an address is governor of the Angle Protocol or not - /// @param admin Address to check - /// @return Whether the address has the `GOVERNOR_ROLE` or not - function isGovernor(address admin) external view returns (bool); - - /// @notice Checks whether an address is governor or a guardian of the Angle Protocol or not - /// @param admin Address to check - /// @return Whether the address has the `GUARDIAN_ROLE` or not - /// @dev Governance should make sure when adding a governor to also give this governor the guardian - /// role by calling the `addGovernor` function - function isGuardian(address admin) external view returns (bool); -} diff --git a/contracts/interfaces/IAccessManaged.sol b/contracts/interfaces/IAccessManaged.sol deleted file mode 100644 index 3bb4cc8..0000000 --- a/contracts/interfaces/IAccessManaged.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 - -pragma solidity 0.8.28; - -/// @title IAccessManaged -/// @author Angle Labs, Inc. -interface IAccessManaged { - /// @notice Checks whether an address is governor of the Angle Protocol or not - /// @param admin Address to check - /// @return Whether the address has the `GOVERNOR_ROLE` or not - function isGovernor(address admin) external view returns (bool); - - /// @notice Checks whether an address is governor or a guardian of the Angle Protocol or not - /// @param admin Address to check - /// @return Whether the address has the `GUARDIAN_ROLE` or not - /// @dev Governance should make sure when adding a governor to also give this governor the guardian - /// role by calling the `addGovernor` function - function isGuardian(address admin) external view returns (bool); - - /// @notice Checks whether a caller can call a function with a given selector - /// @param caller Caller address - /// @param data Calldata of the function to call - /// @return Whether the caller can call the function - function canCall(address caller, bytes calldata data) external view returns (bool); -} diff --git a/contracts/interfaces/IDiamondCut.sol b/contracts/interfaces/IDiamondCut.sol index 898701e..0452c12 100644 --- a/contracts/interfaces/IDiamondCut.sol +++ b/contracts/interfaces/IDiamondCut.sol @@ -1,13 +1,15 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; -import "../transmuter/Storage.sol"; +import "../parallelizer/Storage.sol"; /// @title IDiamondCut -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @dev Reference: EIP-2535 Diamonds /// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/interfaces/IDiamondCut.sol by mudgen +/// @dev This interface is a friendly fork of Angle's `IDiamondCut` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IDiamondCut.sol interface IDiamondCut { /// @notice Add/replace/remove any number of functions and optionally execute a function with delegatecall /// @param _diamondCut Contains the facet addresses and function selectors diff --git a/contracts/interfaces/IDiamondEtherscan.sol b/contracts/interfaces/IDiamondEtherscan.sol index 0aeec33..0295d5b 100644 --- a/contracts/interfaces/IDiamondEtherscan.sol +++ b/contracts/interfaces/IDiamondEtherscan.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; /// @title IDiamondEtherscan -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz interface IDiamondEtherscan { /// @notice Sets a dummy implementation with the same layout at the diamond proxy contract with all its facets function setDummyImplementation(address _implementation) external; diff --git a/contracts/interfaces/IDiamondLoupe.sol b/contracts/interfaces/IDiamondLoupe.sol index 6386a14..4e3a9da 100644 --- a/contracts/interfaces/IDiamondLoupe.sol +++ b/contracts/interfaces/IDiamondLoupe.sol @@ -1,14 +1,13 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; -import "../transmuter/Storage.sol"; +import "../parallelizer/Storage.sol"; /// @notice IDiamondLoupe -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @dev Reference: EIP-2535 Diamonds /// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/interfaces/IDiamondLoupe.sol by mudgen - interface IDiamondLoupe { /// @notice Gets all facet addresses and their four byte function selectors. /// @return facets_ Facet diff --git a/contracts/interfaces/IGetters.sol b/contracts/interfaces/IGetters.sol index 63e2b6d..7d44e4e 100644 --- a/contracts/interfaces/IGetters.sol +++ b/contracts/interfaces/IGetters.sol @@ -1,21 +1,23 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; -import "../transmuter/Storage.sol"; +import "../parallelizer/Storage.sol"; /// @title IGetters -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `IGetters` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IGetters.sol interface IGetters { /// @notice Checks whether a given `selector` is actually a valid selector corresponding to a function in one of /// the /// facets of the proxy function isValidSelector(bytes4 selector) external view returns (bool); - /// @notice Stablecoin minted by transmuter - function agToken() external view returns (IAgToken); + /// @notice Stablecoin minted by parallelizer + function tokenP() external view returns (ITokenP); /// @notice Returns the list of collateral assets supported by the system function getCollateralList() external view returns (address[] memory); @@ -38,15 +40,15 @@ interface IGetters { /// ratio when users come to redeem function getRedemptionFees() external view returns (uint64[] memory, int64[] memory); - /// @notice Returns the collateral ratio of Transmuter in base `10**9` and a rounded version of the total amount + /// @notice Returns the collateral ratio of Parallelizer in base `10**9` and a rounded version of the total amount /// of stablecoins issued function getCollateralRatio() external view returns (uint64 collatRatio, uint256 stablecoinsIssued); - /// @notice Returns the total amount of stablecoins issued through Transmuter + /// @notice Returns the total amount of stablecoins issued through Parallelizer function getTotalIssued() external view returns (uint256 stablecoinsIssued); /// @notice Returns the amount of stablecoins issued from `collateral` and the total amount of stablecoins issued - /// through Transmuter + /// through Parallelizer function getIssuedByCollateral(address collateral) external view diff --git a/contracts/interfaces/IHarvester.sol b/contracts/interfaces/IHarvester.sol index f2ebf6d..89868d8 100644 --- a/contracts/interfaces/IHarvester.sol +++ b/contracts/interfaces/IHarvester.sol @@ -1,7 +1,11 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; +/// @title IHarvester +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `IHarvester` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IHarvester.sol interface IHarvester { function setYieldBearingAssetData( address yieldBearingAsset, diff --git a/contracts/interfaces/IManager.sol b/contracts/interfaces/IManager.sol index 23c3b3e..2bc4f15 100644 --- a/contracts/interfaces/IManager.sol +++ b/contracts/interfaces/IManager.sol @@ -1,9 +1,11 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; /// @title IManager -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `IManager` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IManager.sol interface IManager { /// @notice Returns the amount of collateral managed by the Manager /// @return balances Balances of all the subCollaterals handled by the manager @@ -16,9 +18,9 @@ interface IManager { function invest(uint256 amount) external; /// @notice Sends `amount` of `collateral` to the `to` address - /// @dev Called when `agToken` are burnt and during redemptions + /// @dev Called when `tokenP` are burnt and during redemptions // @dev MUST revert if there are not funds enough available - /// @dev MUST be callable only by the transmuter + /// @dev MUST be callable only by the parallelizer function release(address asset, address to, uint256 amount) external; /// @notice Gives the maximum amount of collateral immediately available for a transfer diff --git a/contracts/interfaces/IParallelizer.sol b/contracts/interfaces/IParallelizer.sol new file mode 100644 index 0000000..5b59050 --- /dev/null +++ b/contracts/interfaces/IParallelizer.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity 0.8.28; + +import { IDiamondCut } from "./IDiamondCut.sol"; +import { IDiamondEtherscan } from "./IDiamondEtherscan.sol"; +import { IDiamondLoupe } from "./IDiamondLoupe.sol"; +import { IGetters } from "./IGetters.sol"; +import { IRedeemer } from "./IRedeemer.sol"; +import { IRewardHandler } from "./IRewardHandler.sol"; +import { ISettersGovernor, ISettersGuardian } from "./ISetters.sol"; +import { ISwapper } from "./ISwapper.sol"; + +/// @title IParallelizer +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `IParallelizer` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IParallelizer.sol +interface IParallelizer is + IDiamondCut, + IDiamondEtherscan, + IDiamondLoupe, + IGetters, + IRedeemer, + IRewardHandler, + ISettersGovernor, + ISettersGuardian, + ISwapper +{ } diff --git a/contracts/interfaces/ITransmuterOracle.sol b/contracts/interfaces/IParallelizerOracle.sol similarity index 70% rename from contracts/interfaces/ITransmuterOracle.sol rename to contracts/interfaces/IParallelizerOracle.sol index 130bf67..e15cfc7 100644 --- a/contracts/interfaces/ITransmuterOracle.sol +++ b/contracts/interfaces/IParallelizerOracle.sol @@ -1,10 +1,12 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; -/// @title ITransmuterOracle -/// @author Angle Labs, Inc. -interface ITransmuterOracle { +/// @title IParallelizerOracle +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `IParallelizerOracle` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IParallelizerOracle.sol +interface IParallelizerOracle { /// @notice Reads the oracle value for asset to use in a redemption to compute the collateral ratio function readRedemption() external view returns (uint256); diff --git a/contracts/interfaces/IPool.sol b/contracts/interfaces/IPool.sol index 3e2d8f7..5e2ffa7 100644 --- a/contracts/interfaces/IPool.sol +++ b/contracts/interfaces/IPool.sol @@ -1,7 +1,11 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; +/// @title IPool +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `IPool` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IPool.sol interface IPool { function deposit(uint256 assets, address lender) external returns (uint256 shares, uint256 transferInDayTimestamp); diff --git a/contracts/interfaces/IRedeemer.sol b/contracts/interfaces/IRedeemer.sol index db4b4c9..e841386 100644 --- a/contracts/interfaces/IRedeemer.sol +++ b/contracts/interfaces/IRedeemer.sol @@ -1,9 +1,11 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; /// @title IRedeemer -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `IRedeemer` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IRedeemer.sol interface IRedeemer { /// @notice Redeems `amount` of stablecoins from the system /// @param receiver Address which should be receiving the output tokens @@ -21,7 +23,7 @@ interface IRedeemer { returns (address[] memory tokens, uint256[] memory amounts); /// @notice Same as the redeem function above with the additional feature to specify a list of `forfeitTokens` for - /// which the Transmuter system will not try to do a transfer to `receiver`. + /// which the Parallelizer system will not try to do a transfer to `receiver`. function redeemWithForfeit( uint256 amount, address receiver, diff --git a/contracts/interfaces/IRewardHandler.sol b/contracts/interfaces/IRewardHandler.sol index 204ed73..60a3835 100644 --- a/contracts/interfaces/IRewardHandler.sol +++ b/contracts/interfaces/IRewardHandler.sol @@ -1,9 +1,11 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; /// @title IRewardHandler -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `IRewardHandler` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IRewardHandler.sol interface IRewardHandler { /// @notice Sells some external tokens through a 1inch call /// @param minAmountOut Minimum amount of the outToken to get diff --git a/contracts/interfaces/ISetters.sol b/contracts/interfaces/ISetters.sol index 4ad8105..668e63d 100644 --- a/contracts/interfaces/ISetters.sol +++ b/contracts/interfaces/ISetters.sol @@ -1,15 +1,17 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; -import "../transmuter/Storage.sol"; +import "../parallelizer/Storage.sol"; /// @title ISettersGovernor -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `ISettersGovernor` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/ISetters.sol interface ISettersGovernor { - /// @notice Recovers `amount` of `token` from the Transmuter contract + /// @notice Recovers `amount` of `token` from the Parallelizer contract function recoverERC20(address collateral, IERC20 token, address to, uint256 amount) external; /// @notice Sets a new access manager address @@ -47,7 +49,8 @@ interface ISettersGovernor { } /// @title ISettersGovernor -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz interface ISettersGuardian { /// @notice Changes the pause status for mint or burn transactions for `collateral` function togglePause(address collateral, ActionType action) external; diff --git a/contracts/interfaces/ISwapper.sol b/contracts/interfaces/ISwapper.sol index 82ac70c..941bdd0 100644 --- a/contracts/interfaces/ISwapper.sol +++ b/contracts/interfaces/ISwapper.sol @@ -1,9 +1,11 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; /// @title ISwapper -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This interface is a friendly fork of Angle's `ISwapper` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/ISwapper.sol interface ISwapper { /// @notice Swaps (that is to say mints or burns) an exact amount of `tokenIn` for an amount of `tokenOut` /// @param amountIn Amount of `tokenIn` to bring diff --git a/contracts/interfaces/IAgToken.sol b/contracts/interfaces/ITokenP.sol similarity index 83% rename from contracts/interfaces/IAgToken.sol rename to contracts/interfaces/ITokenP.sol index 6d343aa..0223c67 100644 --- a/contracts/interfaces/IAgToken.sol +++ b/contracts/interfaces/ITokenP.sol @@ -1,18 +1,20 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -/// @title IAgToken -/// @author Angle Labs, Inc. -/// @notice Interface for the stablecoins `AgToken` contracts -interface IAgToken is IERC20 { +/// @title ITokenP +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @notice Interface for the stablecoins `tokenP` contracts +/// @dev This interface is a friendly fork of Angle's `IAgToken` interface +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IAgToken.sol +interface ITokenP is IERC20 { /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// MINTER ROLE ONLY FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ - /// @notice Lets a whitelisted contract mint agTokens + /// @notice Lets a whitelisted contract mint tokenPs /// @param account Address to mint to /// @param amount Amount to mint function mint(address account, uint256 amount) external; @@ -29,7 +31,7 @@ interface IAgToken is IERC20 { /// @notice Burns `amount` tokens from a `burner` address /// @param amount Amount of tokens to burn /// @param burner Address to burn from - /// @dev This method is to be called by a contract with a minter right on the AgToken after being + /// @dev This method is to be called by a contract with a minter right on the tokenP after being /// requested to do so by an address willing to burn tokens from its address function burnSelf(uint256 amount, address burner) external; @@ -55,9 +57,9 @@ interface IAgToken is IERC20 { EXTERNAL FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ - /// @notice Checks whether an address has the right to mint agTokens + /// @notice Checks whether an address has the right to mint tokenPs /// @param minter Address for which the minting right should be checked - /// @return Whether the address has the right to mint agTokens or not + /// @return Whether the address has the right to mint tokenPs or not function isMinter(address minter) external view returns (bool); /// @notice Amount of decimals of the stablecoin diff --git a/contracts/interfaces/ITransmuter.sol b/contracts/interfaces/ITransmuter.sol deleted file mode 100644 index cac8ef0..0000000 --- a/contracts/interfaces/ITransmuter.sol +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 - -/* - * █ - ***** ▓▓▓ - * ▓▓▓▓▓▓▓ - * ///. ▓▓▓▓▓▓▓▓▓▓▓▓▓ - ***** //////// ▓▓▓▓▓▓▓ - * ///////////// ▓▓▓ - ▓▓ ////////////////// █ ▓▓ - ▓▓ ▓▓ /////////////////////// ▓▓ ▓▓ - ▓▓ ▓▓ //////////////////////////// ▓▓ ▓▓ - ▓▓ ▓▓ /////////▓▓▓///////▓▓▓///////// ▓▓ ▓▓ - ▓▓ ,////////////////////////////////////// ▓▓ ▓▓ - ▓▓ ////////////////////////////////////////// ▓▓ - ▓▓ //////////////////////▓▓▓▓///////////////////// - ,//////////////////////////////////////////////////// - .////////////////////////////////////////////////////////// - .//////////////////////////██.,//////////////////////////█ - .//////////////////////████..,./////////////////////██ - ...////////////////███████.....,.////////////////███ - ,.,////////////████████ ........,///////////████ - .,.,//////█████████ ,.......///////████ - ,..//████████ ........./████ - ..,██████ .....,███ - .██ ,.,█ - - - - ▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓ ▓▓▓▓▓▓▓▓▓▓ - ▓▓▓▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓ ▓▓ ▓▓▓▓ - ▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓ ▓▓▓▓▓ - ▓▓▓ ▓▓ ▓▓▓ ▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ -*/ - -pragma solidity 0.8.28; - -import { IDiamondCut } from "./IDiamondCut.sol"; -import { IDiamondEtherscan } from "./IDiamondEtherscan.sol"; -import { IDiamondLoupe } from "./IDiamondLoupe.sol"; -import { IGetters } from "./IGetters.sol"; -import { IRedeemer } from "./IRedeemer.sol"; -import { IRewardHandler } from "./IRewardHandler.sol"; -import { ISettersGovernor, ISettersGuardian } from "./ISetters.sol"; -import { ISwapper } from "./ISwapper.sol"; - -/// @title ITransmuter -/// @author Angle Labs, Inc. -interface ITransmuter is - IDiamondCut, - IDiamondEtherscan, - IDiamondLoupe, - IGetters, - IRedeemer, - IRewardHandler, - ISettersGovernor, - ISettersGuardian, - ISwapper -{ } diff --git a/contracts/interfaces/IXEVT.sol b/contracts/interfaces/IXEVT.sol deleted file mode 100644 index 8b5f00f..0000000 --- a/contracts/interfaces/IXEVT.sol +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.28; - -interface IXEVT { - function isAllowed(address) external returns (bool); -} diff --git a/contracts/transmuter/DiamondProxy.sol b/contracts/parallelizer/DiamondProxy.sol similarity index 97% rename from contracts/transmuter/DiamondProxy.sol rename to contracts/parallelizer/DiamondProxy.sol index 72a9be3..9405554 100644 --- a/contracts/transmuter/DiamondProxy.sol +++ b/contracts/parallelizer/DiamondProxy.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; import { LibDiamond } from "./libraries/LibDiamond.sol"; @@ -9,7 +8,8 @@ import "../utils/Errors.sol"; import "./Storage.sol"; /// @title DiamondProxy -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @notice Implementation of a Diamond Proxy /// @dev Reference: EIP-2535 Diamonds /// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/Diamond.sol by mudgen diff --git a/contracts/transmuter/Layout.sol b/contracts/parallelizer/Layout.sol similarity index 88% rename from contracts/transmuter/Layout.sol rename to contracts/parallelizer/Layout.sol index e4ef3b6..3550b83 100644 --- a/contracts/transmuter/Layout.sol +++ b/contracts/parallelizer/Layout.sol @@ -1,11 +1,10 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import "../utils/Constants.sol"; -import { DiamondStorage, TransmuterStorage, Collateral, FacetInfo, WhitelistType } from "./Storage.sol"; +import { DiamondStorage, ParallelizerStorage, Collateral, FacetInfo, WhitelistType } from "./Storage.sol"; -/// @notice Contract mimicking the overall storage layout of the transmuter system. +/// @notice Contract mimicking the overall storage layout of the parallelizer system. /// @dev Not meant to be deployed or used. The goals are: /// - To ensure the storage layout is well understood by everyone /// - To force test failures if the layout is changed @@ -24,7 +23,7 @@ contract Layout { // uint256(TRANSMUTER_STORAGE_POSITION) - 1 - uint256(IMPLEMENTATION_STORAGE_POSITION) uint256[63_285_583_310_056_702_947_905_333_115_721_520_886_117_326_369_500_905_343_566_708_717_130_208_881_920] private __gap2; - address public agToken; // slot 1 + address public tokenP; // slot 1 uint8 public isRedemptionLive; // slot 1 uint8 public nonReentrant; // slot 1 bool public consumingSchedule; // slot 1 @@ -37,7 +36,7 @@ contract Layout { mapping(address => uint256) public isTrusted; // slot 7 mapping(address => uint256) public isSellerTrusted; // slot 8 mapping(WhitelistType => mapping(address => uint256)) public isWhitelistedForType; // slot 9 - // uint256(TRANSMUTER_STORAGE_POSITION) - TransmuterStorage offset (9) - uint256(DIAMOND_STORAGE_POSITION) + // uint256(TRANSMUTER_STORAGE_POSITION) - ParallelizerStorage offset (9) - uint256(DIAMOND_STORAGE_POSITION) uint256[3_183_375_284_495_168_307_942_345_002_138_838_670_162_164_004_951_576_664_793_207_874_081_895_365_205] private __gap3; bytes4[] public selectors; // slot 1 diff --git a/contracts/transmuter/Storage.sol b/contracts/parallelizer/Storage.sol similarity index 97% rename from contracts/transmuter/Storage.sol rename to contracts/parallelizer/Storage.sol index d381c1c..c75d7fa 100644 --- a/contracts/transmuter/Storage.sol +++ b/contracts/parallelizer/Storage.sol @@ -1,10 +1,9 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IAccessManager } from "@openzeppelin/contracts/access/manager/IAccessManager.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ENUMS @@ -119,8 +118,8 @@ struct Collateral { uint256 stablecoinCap; // Cap on the amount of stablecoins that can be issued from this collateral } -struct TransmuterStorage { - IAgToken agToken; // agToken handled by the system +struct ParallelizerStorage { + ITokenP tokenP; // tokenP handled by the system uint8 isRedemptionLive; // If redemption is unpaused uint8 statusReentrant; // If call is reentrant or not bool consumingSchedule; // If the contract is consuming a scheduled operation diff --git a/contracts/transmuter/configs/ProductionTypes.sol b/contracts/parallelizer/configs/ProductionTypes.sol similarity index 99% rename from contracts/transmuter/configs/ProductionTypes.sol rename to contracts/parallelizer/configs/ProductionTypes.sol index 6dc7971..c09a41d 100644 --- a/contracts/transmuter/configs/ProductionTypes.sol +++ b/contracts/parallelizer/configs/ProductionTypes.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import "interfaces/external/chainlink/AggregatorV3Interface.sol"; diff --git a/contracts/transmuter/configs/ProductionUSD.sol b/contracts/parallelizer/configs/ProductionUSD.sol similarity index 92% rename from contracts/transmuter/configs/ProductionUSD.sol rename to contracts/parallelizer/configs/ProductionUSD.sol index 2d7526b..b9dbc92 100644 --- a/contracts/transmuter/configs/ProductionUSD.sol +++ b/contracts/parallelizer/configs/ProductionUSD.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import "./ProductionTypes.sol"; @@ -8,10 +7,10 @@ import "./ProductionTypes.sol"; contract ProductionUSD { // address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; - function initialize(IAccessManager _accessManager, address _agToken, address dummyImplementation) external { + function initialize(IAccessManager _accessManager, address _tokenP, address dummyImplementation) external { /* require(address(_accessControlManager) == 0x5bc6BEf80DA563EBf6Df6D6913513fa9A7ec89BE); - require(address(_agToken) == 0x0000206329b97DB379d5E1Bf586BbDB969C63274); + require(address(_tokenP) == 0x0000206329b97DB379d5E1Bf586BbDB969C63274); */ // Set Collaterals @@ -61,10 +60,10 @@ contract ProductionUSD { LibSetters.setAccessManager(_accessManager); - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); ts.statusReentrant = NOT_ENTERED; ts.normalizer = uint128(BASE_27); - ts.agToken = IAgToken(_agToken); + ts.tokenP = ITokenP(_tokenP); // Setup each collateral uint256 collateralsLength = collaterals.length; diff --git a/contracts/transmuter/configs/Test.sol b/contracts/parallelizer/configs/Test.sol similarity index 98% rename from contracts/transmuter/configs/Test.sol rename to contracts/parallelizer/configs/Test.sol index 185fa4a..b457256 100644 --- a/contracts/transmuter/configs/Test.sol +++ b/contracts/parallelizer/configs/Test.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import "interfaces/external/chainlink/AggregatorV3Interface.sol"; @@ -20,7 +19,7 @@ struct CollateralSetup { contract Test { function initialize( IAccessManager _accessManager, - address _agToken, + address _tokenP, CollateralSetup calldata eurA, CollateralSetup calldata eurB, CollateralSetup calldata eurY @@ -29,10 +28,10 @@ contract Test { { LibSetters.setAccessManager(_accessManager); - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); ts.statusReentrant = NOT_ENTERED; ts.normalizer = uint128(BASE_27); - ts.agToken = IAgToken(_agToken); + ts.tokenP = ITokenP(_tokenP); // Setup first collateral LibSetters.addCollateral(eurA.collateral); diff --git a/contracts/transmuter/facets/AccessManagedModifiers.sol b/contracts/parallelizer/facets/AccessManagedModifiers.sol similarity index 73% rename from contracts/transmuter/facets/AccessManagedModifiers.sol rename to contracts/parallelizer/facets/AccessManagedModifiers.sol index f596d0b..e66800a 100644 --- a/contracts/transmuter/facets/AccessManagedModifiers.sol +++ b/contracts/parallelizer/facets/AccessManagedModifiers.sol @@ -1,14 +1,17 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { LibDiamond } from "../libraries/LibDiamond.sol"; -import { LibStorage as s, TransmuterStorage } from "../libraries/LibStorage.sol"; +import { LibStorage as s, ParallelizerStorage } from "../libraries/LibStorage.sol"; import "../../utils/Errors.sol"; import "../../utils/Constants.sol"; /// @title AccessManagedModifiers -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This contract is a friendly fork of Angle's `AccessControlModifiers` contract +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/AccessControlModifiers.sol +/// update access logic to use OpenZeppelin's `AccessManaged` logic contract AccessManagedModifiers { /// @notice Checks whether the `msg.sender` can call a function with a given selector modifier restricted() { @@ -21,7 +24,7 @@ contract AccessManagedModifiers { /// Diamond Proxy system. The base implementation can be found here /// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol modifier nonReentrant() { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); // Reentrant protection // On the first call, `ts.statusReentrant` will be `NOT_ENTERED` if (ts.statusReentrant == ENTERED) revert ReentrantCall(); diff --git a/contracts/transmuter/facets/DiamondCut.sol b/contracts/parallelizer/facets/DiamondCut.sol similarity index 91% rename from contracts/transmuter/facets/DiamondCut.sol rename to contracts/parallelizer/facets/DiamondCut.sol index 3ebd50f..73b4de7 100644 --- a/contracts/transmuter/facets/DiamondCut.sol +++ b/contracts/parallelizer/facets/DiamondCut.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; import { IDiamondCut } from "interfaces/IDiamondCut.sol"; @@ -10,7 +9,8 @@ import { AccessManagedModifiers } from "./AccessManagedModifiers.sol"; import "../Storage.sol"; /// @title DiamondCut -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @dev Reference: EIP-2535 Diamonds /// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/facets/DiamondCutFacet.sol by mudgen contract DiamondCut is IDiamondCut, AccessManagedModifiers { diff --git a/contracts/transmuter/facets/DiamondEtherscan.sol b/contracts/parallelizer/facets/DiamondEtherscan.sol similarity index 99% rename from contracts/transmuter/facets/DiamondEtherscan.sol rename to contracts/parallelizer/facets/DiamondEtherscan.sol index b2deeb9..0c6fb82 100644 --- a/contracts/transmuter/facets/DiamondEtherscan.sol +++ b/contracts/parallelizer/facets/DiamondEtherscan.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; import { IDiamondEtherscan } from "interfaces/IDiamondEtherscan.sol"; diff --git a/contracts/transmuter/facets/DiamondLoupe.sol b/contracts/parallelizer/facets/DiamondLoupe.sol similarity index 98% rename from contracts/transmuter/facets/DiamondLoupe.sol rename to contracts/parallelizer/facets/DiamondLoupe.sol index 1f176e1..25a252d 100644 --- a/contracts/transmuter/facets/DiamondLoupe.sol +++ b/contracts/parallelizer/facets/DiamondLoupe.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; import { IDiamondLoupe } from "interfaces/IDiamondLoupe.sol"; @@ -9,7 +8,8 @@ import { LibStorage as s } from "../libraries/LibStorage.sol"; import "../Storage.sol"; /// @title DiamondLoupe -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @dev Reference: EIP-2535 Diamonds /// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/facets/DiamondLoupeFacet.sol by mudgen contract DiamondLoupe is IDiamondLoupe { diff --git a/contracts/transmuter/facets/Getters.sol b/contracts/parallelizer/facets/Getters.sol similarity index 92% rename from contracts/transmuter/facets/Getters.sol rename to contracts/parallelizer/facets/Getters.sol index 5c4d5e7..a1769a4 100644 --- a/contracts/transmuter/facets/Getters.sol +++ b/contracts/parallelizer/facets/Getters.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { IGetters } from "interfaces/IGetters.sol"; @@ -14,8 +13,11 @@ import "../../utils/Errors.sol"; import "../Storage.sol"; /// @title Getters -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @dev There may be duplicates in the info provided by the getters defined here +/// @dev This contract is a friendly fork of Angle's `Getters` contract +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/Getters.sol contract Getters is IGetters { /// @inheritdoc IGetters function isValidSelector(bytes4 selector) external view returns (bool) { @@ -23,8 +25,8 @@ contract Getters is IGetters { } /// @inheritdoc IGetters - function agToken() external view returns (IAgToken) { - return s.transmuterStorage().agToken; + function tokenP() external view returns (ITokenP) { + return s.transmuterStorage().tokenP; } /// @inheritdoc IGetters @@ -68,7 +70,7 @@ contract Getters is IGetters { view returns (uint64[] memory xRedemptionCurve, int64[] memory yRedemptionCurve) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); return (ts.xRedemptionCurve, ts.yRedemptionCurve); } @@ -78,7 +80,7 @@ contract Getters is IGetters { /// negligible amount of `stablecoinsIssued` so DoS attacks on redemptions which use this function /// become economically impossible function getCollateralRatio() external view returns (uint64 collatRatio, uint256 stablecoinsIssued) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); // Reentrant protection if (ts.statusReentrant == ENTERED) revert ReentrantCall(); @@ -91,7 +93,7 @@ contract Getters is IGetters { view returns (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); uint256 _normalizer = ts.normalizer; return ( (uint256(ts.collaterals[collateral].normalizedStables) * _normalizer) / BASE_27, @@ -101,7 +103,7 @@ contract Getters is IGetters { /// @inheritdoc IGetters function getTotalIssued() external view returns (uint256) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); return (uint256(ts.normalizedStables) * uint256(ts.normalizer)) / BASE_27; } diff --git a/contracts/transmuter/facets/Redeemer.sol b/contracts/parallelizer/facets/Redeemer.sol similarity index 95% rename from contracts/transmuter/facets/Redeemer.sol rename to contracts/parallelizer/facets/Redeemer.sol index c271259..a78083e 100644 --- a/contracts/transmuter/facets/Redeemer.sol +++ b/contracts/parallelizer/facets/Redeemer.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; @@ -7,7 +6,7 @@ import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; import { IRedeemer } from "interfaces/IRedeemer.sol"; import { AccessManagedModifiers } from "./AccessManagedModifiers.sol"; @@ -23,7 +22,10 @@ import "../../utils/Errors.sol"; import "../Storage.sol"; /// @title Redeemer -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This contract is a friendly fork of Angle's `Redeemer` contract +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/Redeemer.sol contract Redeemer is IRedeemer, AccessManagedModifiers { using SafeERC20 for IERC20; using Math for uint256; @@ -121,7 +123,7 @@ contract Redeemer is IRedeemer, AccessManagedModifiers { nonReentrant returns (address[] memory tokens, uint256[] memory amounts) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); if (ts.isRedemptionLive == 0) revert Paused(); if (block.timestamp > deadline) revert TooLate(); @@ -138,7 +140,7 @@ contract Redeemer is IRedeemer, AccessManagedModifiers { // of stablecoins issued from each collateral without having to loop through each of them _updateNormalizer(amount, false); - IAgToken(ts.agToken).burnSelf(amount, msg.sender); + ITokenP(ts.tokenP).burnSelf(amount, msg.sender); address[] memory collateralListMem = ts.collateralList; uint256 indexCollateral; @@ -168,7 +170,7 @@ contract Redeemer is IRedeemer, AccessManagedModifiers { view returns (address[] memory tokens, uint256[] memory balances, uint256[] memory subCollateralsTracker) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); uint64 collatRatio; uint256 stablecoinsIssued; (collatRatio, stablecoinsIssued, tokens, balances, subCollateralsTracker) = LibGetters.getCollateralRatio(); @@ -196,7 +198,7 @@ contract Redeemer is IRedeemer, AccessManagedModifiers { /// @notice Updates the `normalizer` variable used to track stablecoins issued from each asset and globally function _updateNormalizer(uint256 amount, bool increase) internal returns (uint256 newNormalizerValue) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); uint256 _normalizer = ts.normalizer; uint256 _normalizedStables = ts.normalizedStables; // In case of an increase, the update formula used is the simplified version of the formula below: diff --git a/contracts/transmuter/facets/RewardHandler.sol b/contracts/parallelizer/facets/RewardHandler.sol similarity index 89% rename from contracts/transmuter/facets/RewardHandler.sol rename to contracts/parallelizer/facets/RewardHandler.sol index bc72dfa..9ef751c 100644 --- a/contracts/transmuter/facets/RewardHandler.sol +++ b/contracts/parallelizer/facets/RewardHandler.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { IRewardHandler } from "interfaces/IRewardHandler.sol"; @@ -15,7 +14,10 @@ import "../../utils/Errors.sol"; import "../Storage.sol"; /// @title RewardHandler -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This contract is a friendly fork of Angle's `RewardHandler` contract +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/RewardHandler.sol contract RewardHandler is IRewardHandler { using SafeERC20 for IERC20; @@ -27,7 +29,7 @@ contract RewardHandler is IRewardHandler { /// @dev Only governance can set which tokens can be swapped through this function by passing a prior approval /// transaction to 1inch router for the token to be swapped function sellRewards(uint256 minAmountOut, bytes memory payload) external returns (uint256 amountOut) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); if (!LibDiamond.checkCanCall(msg.sender, msg.data) && ts.isSellerTrusted[msg.sender] == 0) revert NotTrusted(); address[] memory list = ts.collateralList; uint256 listLength = list.length; diff --git a/contracts/transmuter/facets/SettersGovernor.sol b/contracts/parallelizer/facets/SettersGovernor.sol similarity index 94% rename from contracts/transmuter/facets/SettersGovernor.sol rename to contracts/parallelizer/facets/SettersGovernor.sol index 6530dd6..8eb3d97 100644 --- a/contracts/transmuter/facets/SettersGovernor.sol +++ b/contracts/parallelizer/facets/SettersGovernor.sol @@ -1,11 +1,9 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import { IAccessControlManager } from "interfaces/IAccessControlManager.sol"; import { ISettersGovernor } from "interfaces/ISetters.sol"; import { LibManager } from "../libraries/LibManager.sol"; @@ -19,7 +17,10 @@ import "../../utils/Errors.sol"; import "../Storage.sol"; /// @title SettersGovernor -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This contract is a friendly fork of Angle's `SettersGovernor` contract +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/SettersGovernor.sol contract SettersGovernor is AccessManagedModifiers, ISettersGovernor { using SafeERC20 for IERC20; diff --git a/contracts/transmuter/facets/SettersGuardian.sol b/contracts/parallelizer/facets/SettersGuardian.sol similarity index 83% rename from contracts/transmuter/facets/SettersGuardian.sol rename to contracts/parallelizer/facets/SettersGuardian.sol index b823b6f..1399d97 100644 --- a/contracts/transmuter/facets/SettersGuardian.sol +++ b/contracts/parallelizer/facets/SettersGuardian.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { ISettersGuardian } from "interfaces/ISetters.sol"; @@ -10,7 +9,10 @@ import { AccessManagedModifiers } from "./AccessManagedModifiers.sol"; import "../Storage.sol"; /// @title SettersGuardian -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This contract is a friendly fork of Angle's `SettersGuardian` contract +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/SettersGuardian.sol contract SettersGuardian is AccessManagedModifiers, ISettersGuardian { /// @inheritdoc ISettersGuardian function togglePause(address collateral, ActionType pausedType) external restricted { diff --git a/contracts/transmuter/facets/Swapper.sol b/contracts/parallelizer/facets/Swapper.sol similarity index 96% rename from contracts/transmuter/facets/Swapper.sol rename to contracts/parallelizer/facets/Swapper.sol index fc3ae85..41d3e85 100644 --- a/contracts/transmuter/facets/Swapper.sol +++ b/contracts/parallelizer/facets/Swapper.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { Address } from "@openzeppelin/contracts/utils/Address.sol"; @@ -8,7 +7,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; import { ISwapper } from "interfaces/ISwapper.sol"; import { IPermit2, PermitTransferFrom } from "interfaces/external/permit2/IPermit2.sol"; import { SignatureTransferDetails, TokenPermissions } from "interfaces/external/permit2/IPermit2.sol"; @@ -38,7 +37,8 @@ struct LocalVariables { } /// @title Swapper -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @dev In all the functions of this contract, one of `tokenIn` or `tokenOut` must be the stablecoin, and /// one of `tokenOut` or `tokenIn` must be an accepted collateral. Depending on the `tokenIn` or `tokenOut` given, /// the functions will either handle a mint or a burn operation @@ -50,6 +50,8 @@ struct LocalVariables { /// @dev In case of a burn again, the swap functions will revert if the call concerns a collateral that requires a /// whitelist but the `to` address does not have it. The quote functions will not revert in this case. /// @dev Calling one of the swap functions in a burn case does not require any prior token approval +/// @dev This contract is a friendly fork of Angle's `Swapper` contract +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/Swapper.sol contract Swapper is ISwapper, AccessManagedModifiers { using SafeERC20 for IERC20; using SafeCast for uint256; @@ -162,7 +164,7 @@ contract Swapper is ISwapper, AccessManagedModifiers { /// @inheritdoc ISwapper function quoteIn(uint256 amountIn, address tokenIn, address tokenOut) external view returns (uint256 amountOut) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); (bool mint, Collateral storage collatInfo) = _getMintBurn(tokenIn, tokenOut, 0); if (mint) { amountOut = _quoteMintExactInput(collatInfo, amountIn); @@ -175,7 +177,7 @@ contract Swapper is ISwapper, AccessManagedModifiers { /// @inheritdoc ISwapper function quoteOut(uint256 amountOut, address tokenIn, address tokenOut) external view returns (uint256 amountIn) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); (bool mint, Collateral storage collatInfo) = _getMintBurn(tokenIn, tokenOut, 0); if (mint) { _checkHardCaps(collatInfo, amountOut, ts.normalizer); @@ -205,7 +207,7 @@ contract Swapper is ISwapper, AccessManagedModifiers { nonReentrant { if (amountIn > 0 && amountOut > 0) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); if (mint) { _checkHardCaps(collatInfo, amountOut, ts.normalizer); uint128 changeAmount = (amountOut.mulDiv(BASE_27, ts.normalizer, Math.Rounding.Ceil)).toUint128(); @@ -225,7 +227,7 @@ contract Swapper is ISwapper, AccessManagedModifiers { if (collatInfo.isManaged > 0) { LibManager.invest(amountIn, collatInfo.managerData.config); } - IAgToken(tokenOut).mint(to, amountOut); + ITokenP(tokenOut).mint(to, amountOut); } else { if (collatInfo.onlyWhitelisted > 0 && !LibWhitelist.checkWhitelist(collatInfo.whitelistData, to)) { revert NotWhitelisted(); @@ -235,7 +237,7 @@ contract Swapper is ISwapper, AccessManagedModifiers { // from this collateral collatInfo.normalizedStables = collatInfo.normalizedStables - uint216(changeAmount); ts.normalizedStables = ts.normalizedStables - changeAmount; - IAgToken(tokenIn).burnSelf(amountIn, msg.sender); + ITokenP(tokenIn).burnSelf(amountIn, msg.sender); if (collatInfo.isManaged > 0) { LibManager.release(tokenOut, to, amountOut, collatInfo.managerData.config); } else { @@ -309,7 +311,7 @@ contract Swapper is ISwapper, AccessManagedModifiers { } /// @notice Computes the fees to apply during a mint or burn operation - /// @dev This function leverages the mathematical computations of the appendix of the Transmuter whitepaper + /// @dev This function leverages the mathematical computations of the appendix of the Parallelizer whitepaper /// @dev Cost of the function is linear in the length of the `xFeeMint` or `xFeeBurn` array function _quoteFees( Collateral storage collatInfo, @@ -327,7 +329,7 @@ contract Swapper is ISwapper, AccessManagedModifiers { uint256 currentExposure; { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); uint256 normalizedStablesMem = ts.normalizedStables; // Handling the initialisation and constant fees if (normalizedStablesMem == 0 || n == 1) { @@ -510,13 +512,13 @@ contract Swapper is ISwapper, AccessManagedModifiers { returns (bool mint, Collateral storage collatInfo) { if (deadline != 0 && block.timestamp > deadline) revert TooLate(); - TransmuterStorage storage ts = s.transmuterStorage(); - address _agToken = address(ts.agToken); - if (tokenIn == _agToken) { + ParallelizerStorage storage ts = s.transmuterStorage(); + address _tokenP = address(ts.tokenP); + if (tokenIn == _tokenP) { collatInfo = ts.collaterals[tokenOut]; if (collatInfo.isBurnLive == 0) revert Paused(); mint = false; - } else if (tokenOut == _agToken) { + } else if (tokenOut == _tokenP) { collatInfo = ts.collaterals[tokenIn]; if (collatInfo.isMintLive == 0) revert Paused(); mint = true; @@ -535,10 +537,10 @@ contract Swapper is ISwapper, AccessManagedModifiers { returns (address tokenOut, Collateral storage collatInfo) { if (deadline != 0 && block.timestamp > deadline) revert TooLate(); - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); collatInfo = ts.collaterals[tokenIn]; if (collatInfo.isMintLive == 0) revert Paused(); - tokenOut = address(ts.agToken); + tokenOut = address(ts.tokenP); } /// @notice Builds a permit2 `permitTransferFrom` payload for a `tokenIn` transfer diff --git a/contracts/transmuter/libraries/LibDiamond.sol b/contracts/parallelizer/libraries/LibDiamond.sol similarity index 98% rename from contracts/transmuter/libraries/LibDiamond.sol rename to contracts/parallelizer/libraries/LibDiamond.sol index e205350..afa3098 100644 --- a/contracts/transmuter/libraries/LibDiamond.sol +++ b/contracts/parallelizer/libraries/LibDiamond.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; import { LibStorage as s } from "./LibStorage.sol"; @@ -11,7 +10,8 @@ import "../../utils/Constants.sol"; import "../Storage.sol"; /// @title LibDiamond -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @notice Helper library to deal with diamond proxies. /// @dev Reference: EIP-2535 Diamonds /// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/libraries/LibDiamond.sol by mudgen @@ -34,7 +34,7 @@ library LibDiamond { AuthorityUtils.canCallWithDelay(address(accessManager), caller, address(this), bytes4(data[0:4])); if (!immediate) { if (delay > 0) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); ts.consumingSchedule = true; accessManager.consumeScheduledOp(caller, data); ts.consumingSchedule = false; diff --git a/contracts/transmuter/libraries/LibDiamondEtherscan.sol b/contracts/parallelizer/libraries/LibDiamondEtherscan.sol similarity index 99% rename from contracts/transmuter/libraries/LibDiamondEtherscan.sol rename to contracts/parallelizer/libraries/LibDiamondEtherscan.sol index 6d20df1..dbcb046 100644 --- a/contracts/transmuter/libraries/LibDiamondEtherscan.sol +++ b/contracts/parallelizer/libraries/LibDiamondEtherscan.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; import { LibStorage as s } from "./LibStorage.sol"; diff --git a/contracts/transmuter/libraries/LibGetters.sol b/contracts/parallelizer/libraries/LibGetters.sol similarity index 93% rename from contracts/transmuter/libraries/LibGetters.sol rename to contracts/parallelizer/libraries/LibGetters.sol index 78874f5..447b0c2 100644 --- a/contracts/transmuter/libraries/LibGetters.sol +++ b/contracts/parallelizer/libraries/LibGetters.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; @@ -15,7 +14,10 @@ import "../../utils/Constants.sol"; import "../Storage.sol"; /// @title LibGetters -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This library is a friendly fork of Angle's `LibGetters` library +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibGetters.sol library LibGetters { using Math for uint256; using SafeCast for uint256; @@ -39,7 +41,7 @@ library LibGetters { uint256[] memory subCollateralsTracker ) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); uint256 totalCollateralization; address[] memory collateralList = ts.collateralList; uint256 collateralListLength = collateralList.length; diff --git a/contracts/transmuter/libraries/LibHelpers.sol b/contracts/parallelizer/libraries/LibHelpers.sol similarity index 93% rename from contracts/transmuter/libraries/LibHelpers.sol rename to contracts/parallelizer/libraries/LibHelpers.sol index 67f4701..55dbe27 100644 --- a/contracts/transmuter/libraries/LibHelpers.sol +++ b/contracts/parallelizer/libraries/LibHelpers.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; @@ -7,7 +6,10 @@ import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import "../Storage.sol"; /// @title LibHelpers -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This library is a friendly fork of Angle's `LibHelpers` library +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibHelpers.sol library LibHelpers { /// @notice Rebases the units of `amount` from `fromDecimals` to `toDecimals` function convertDecimalTo(uint256 amount, uint8 fromDecimals, uint8 toDecimals) internal pure returns (uint256) { diff --git a/contracts/transmuter/libraries/LibManager.sol b/contracts/parallelizer/libraries/LibManager.sol similarity index 92% rename from contracts/transmuter/libraries/LibManager.sol rename to contracts/parallelizer/libraries/LibManager.sol index 52ce8cf..c09b977 100644 --- a/contracts/transmuter/libraries/LibManager.sol +++ b/contracts/parallelizer/libraries/LibManager.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { IManager } from "interfaces/IManager.sol"; @@ -7,10 +6,13 @@ import { IManager } from "interfaces/IManager.sol"; import "../Storage.sol"; /// @title LibManager -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @dev Managed collateral assets may be handled through external smart contracts or directly through this library /// @dev There is no implementation at this point for a managed collateral handled through this library, and /// a new specific `ManagerType` would need to be added in this case +/// @dev This library is a friendly fork of Angle's `LibManager` library +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibManager.sol library LibManager { /// @notice Checks to which address managed funds must be transferred function transferRecipient(bytes memory config) internal view returns (address recipient) { diff --git a/contracts/transmuter/libraries/LibOracle.sol b/contracts/parallelizer/libraries/LibOracle.sol similarity index 94% rename from contracts/transmuter/libraries/LibOracle.sol rename to contracts/parallelizer/libraries/LibOracle.sol index fd79739..f227fc2 100644 --- a/contracts/transmuter/libraries/LibOracle.sol +++ b/contracts/parallelizer/libraries/LibOracle.sol @@ -1,8 +1,7 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; -import { ITransmuterOracle } from "interfaces/ITransmuterOracle.sol"; +import { IParallelizerOracle } from "interfaces/IParallelizerOracle.sol"; import { AggregatorV3Interface } from "interfaces/external/chainlink/AggregatorV3Interface.sol"; import { IMorphoOracle } from "interfaces/external/morpho/IMorphoOracle.sol"; import { IPyth, PythStructs } from "interfaces/external/pyth/IPyth.sol"; @@ -14,7 +13,10 @@ import "../../utils/Errors.sol"; import "../Storage.sol"; /// @title LibOracle -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This library is a friendly fork of Angle's `LibOracle` library +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibOracle.sol library LibOracle { /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ACTIONS SPECIFIC ORACLES @@ -26,7 +28,7 @@ library LibOracle { (OracleReadType oracleType, OracleReadType targetType, bytes memory oracleData, bytes memory targetData,) = _parseOracleConfig(oracleConfig); if (oracleType == OracleReadType.EXTERNAL) { - ITransmuterOracle externalOracle = abi.decode(oracleData, (ITransmuterOracle)); + IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle)); return externalOracle.readRedemption(); } else { (oracleValue,) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, 0); @@ -46,7 +48,7 @@ library LibOracle { bytes memory hyperparameters ) = _parseOracleConfig(oracleConfig); if (oracleType == OracleReadType.EXTERNAL) { - ITransmuterOracle externalOracle = abi.decode(oracleData, (ITransmuterOracle)); + IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle)); return externalOracle.readMint(); } @@ -69,7 +71,7 @@ library LibOracle { bytes memory hyperparameters ) = _parseOracleConfig(oracleConfig); if (oracleType == OracleReadType.EXTERNAL) { - ITransmuterOracle externalOracle = abi.decode(oracleData, (ITransmuterOracle)); + IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle)); return externalOracle.readBurn(); } (uint128 userDeviation, uint128 burnRatioDeviation) = abi.decode(hyperparameters, (uint128, uint128)); @@ -110,7 +112,7 @@ library LibOracle { view returns (uint256 minRatio, uint256 oracleValue) { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); minRatio = BASE_18; address[] memory collateralList = ts.collateralList; uint256 length = collateralList.length; @@ -275,7 +277,7 @@ library LibOracle { } function updateOracle(address collateral) internal { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); if (ts.collaterals[collateral].decimals == 0) revert NotCollateral(); ( diff --git a/contracts/transmuter/libraries/LibSetters.sol b/contracts/parallelizer/libraries/LibSetters.sol similarity index 94% rename from contracts/transmuter/libraries/LibSetters.sol rename to contracts/parallelizer/libraries/LibSetters.sol index 1d68bd8..48c5d73 100644 --- a/contracts/transmuter/libraries/LibSetters.sol +++ b/contracts/parallelizer/libraries/LibSetters.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; @@ -16,7 +15,10 @@ import "../../utils/Errors.sol"; import "../Storage.sol"; /// @title LibSetters -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This library is a friendly fork of Angle's `LibSetters` library +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibSetters.sol library LibSetters { using SafeCast for uint256; @@ -70,7 +72,7 @@ library LibSetters { /// @notice Internal version of `toggleTrusted` function toggleTrusted(address sender, TrustedType t) internal { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); uint256 trustedStatus; if (t == TrustedType.Updater) { trustedStatus = 1 - ts.isTrusted[sender]; @@ -84,7 +86,7 @@ library LibSetters { /// @notice Internal version of `addCollateral` function addCollateral(address collateral) internal { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); Collateral storage collatInfo = ts.collaterals[collateral]; if (collatInfo.decimals != 0) revert AlreadyAdded(); collatInfo.decimals = uint8(IERC20Metadata(collateral).decimals()); @@ -94,7 +96,7 @@ library LibSetters { /// @notice Internal version of `adjustStablecoins` function adjustStablecoins(address collateral, uint128 amount, bool increase) internal { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); Collateral storage collatInfo = ts.collaterals[collateral]; if (collatInfo.decimals == 0) revert NotCollateral(); uint128 normalizedAmount = ((amount * BASE_27) / ts.normalizer).toUint128(); @@ -110,7 +112,7 @@ library LibSetters { /// @notice Internal version of `revokeCollateral` function revokeCollateral(address collateral) internal { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); Collateral storage collatInfo = ts.collaterals[collateral]; if (collatInfo.decimals == 0 || collatInfo.normalizedStables > 0) revert NotCollateral(); uint8 isManaged = collatInfo.isManaged; @@ -172,7 +174,7 @@ library LibSetters { collatInfo.isBurnLive = isLive; } } else { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); isLive = 1 - ts.isRedemptionLive; ts.isRedemptionLive = isLive; } @@ -181,7 +183,7 @@ library LibSetters { /// @notice Internal version of `setFees` function setFees(address collateral, uint64[] memory xFee, int64[] memory yFee, bool mint) internal { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); Collateral storage collatInfo = ts.collaterals[collateral]; if (collatInfo.decimals == 0) revert NotCollateral(); checkFees(xFee, yFee, mint ? ActionType.Mint : ActionType.Burn); @@ -197,7 +199,7 @@ library LibSetters { /// @notice Internal version of `setRedemptionCurveParams` function setRedemptionCurveParams(uint64[] memory xFee, int64[] memory yFee) internal { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); LibSetters.checkFees(xFee, yFee, ActionType.Redeem); ts.xRedemptionCurve = xFee; ts.yRedemptionCurve = yFee; @@ -206,7 +208,7 @@ library LibSetters { /// @notice Internal version of `toggleWhitelist` function toggleWhitelist(WhitelistType whitelistType, address who) internal { - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); uint256 whitelistStatus = 1 - ts.isWhitelistedForType[whitelistType][who]; ts.isWhitelistedForType[whitelistType][who] = whitelistStatus; emit WhitelistStatusToggled(whitelistType, who, whitelistStatus); @@ -259,7 +261,7 @@ library LibSetters { // (from any collateral) and then burning cannot get more than their initial value if (yFee[0] < 0) { if (!LibDiamond.isGovernor(msg.sender)) revert NotGovernor(); // Only governor can set negative fees - TransmuterStorage storage ts = s.transmuterStorage(); + ParallelizerStorage storage ts = s.transmuterStorage(); address[] memory collateralListMem = ts.collateralList; uint256 length = collateralListMem.length; if (action == ActionType.Mint) { diff --git a/contracts/transmuter/libraries/LibStorage.sol b/contracts/parallelizer/libraries/LibStorage.sol similarity index 68% rename from contracts/transmuter/libraries/LibStorage.sol rename to contracts/parallelizer/libraries/LibStorage.sol index 65db27a..fc42764 100644 --- a/contracts/transmuter/libraries/LibStorage.sol +++ b/contracts/parallelizer/libraries/LibStorage.sol @@ -1,12 +1,14 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import "../../utils/Constants.sol"; -import { DiamondStorage, ImplementationStorage, TransmuterStorage } from "../Storage.sol"; +import { DiamondStorage, ImplementationStorage, ParallelizerStorage } from "../Storage.sol"; /// @title LibStorage -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This library is a friendly fork of Angle's `LibStorage` library +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibStorage.sol library LibStorage { /// @notice Returns the storage struct stored at the `DIAMOND_STORAGE_POSITION` slot /// @dev This struct handles the logic of the different facets used in the diamond proxy @@ -18,8 +20,8 @@ library LibStorage { } /// @notice Returns the storage struct stored at the `TRANSMUTER_STORAGE_POSITION` slot - /// @dev This struct handles the particular logic of the Transmuter system - function transmuterStorage() internal pure returns (TransmuterStorage storage ts) { + /// @dev This struct handles the particular logic of the Parallelizer system + function transmuterStorage() internal pure returns (ParallelizerStorage storage ts) { bytes32 position = TRANSMUTER_STORAGE_POSITION; assembly ("memory-safe") { ts.slot := position diff --git a/contracts/transmuter/libraries/LibWhitelist.sol b/contracts/parallelizer/libraries/LibWhitelist.sol similarity index 79% rename from contracts/transmuter/libraries/LibWhitelist.sol rename to contracts/parallelizer/libraries/LibWhitelist.sol index 5d3aee0..5753921 100644 --- a/contracts/transmuter/libraries/LibWhitelist.sol +++ b/contracts/parallelizer/libraries/LibWhitelist.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { IKeyringGuard } from "interfaces/external/keyring/IKeyringGuard.sol"; @@ -10,7 +9,10 @@ import "../../utils/Errors.sol"; import "../Storage.sol"; /// @title LibWhitelist -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This library is a friendly fork of Angle's `LibWhitelist` library +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibWhitelist.sol library LibWhitelist { /// @notice Checks whether `sender` is whitelisted for a collateral with `whitelistData` function checkWhitelist(bytes memory whitelistData, address sender) internal returns (bool) { diff --git a/contracts/savings/BaseSavings.sol b/contracts/savings/BaseSavings.sol index 3f3ac81..701c04f 100644 --- a/contracts/savings/BaseSavings.sol +++ b/contracts/savings/BaseSavings.sol @@ -1,38 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - -/* - * █ - ***** ▓▓▓ - * ▓▓▓▓▓▓▓ - * ///. ▓▓▓▓▓▓▓▓▓▓▓▓▓ - ***** //////// ▓▓▓▓▓▓▓ - * ///////////// ▓▓▓ - ▓▓ ////////////////// █ ▓▓ - ▓▓ ▓▓ /////////////////////// ▓▓ ▓▓ - ▓▓ ▓▓ //////////////////////////// ▓▓ ▓▓ - ▓▓ ▓▓ /////////▓▓▓///////▓▓▓///////// ▓▓ ▓▓ - ▓▓ ,////////////////////////////////////// ▓▓ ▓▓ - ▓▓ ////////////////////////////////////////// ▓▓ - ▓▓ //////////////////////▓▓▓▓///////////////////// - ,//////////////////////////////////////////////////// - .////////////////////////////////////////////////////////// - .//////////////////////////██.,//////////////////////////█ - .//////////////////////████..,./////////////////////██ - ...////////////////███████.....,.////////////////███ - ,.,////////////████████ ........,///////////████ - .,.,//////█████████ ,.......///////████ - ,..//████████ ........./████ - ..,██████ .....,███ - .██ ,.,█ - - - - ▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓ ▓▓▓▓▓▓▓▓▓▓ - ▓▓▓▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓ ▓▓ ▓▓▓▓ - ▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓ ▓▓▓▓▓ - ▓▓▓ ▓▓ ▓▓▓ ▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ -*/ - pragma solidity 0.8.28; import { ERC4626Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol"; @@ -42,7 +8,7 @@ import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/I import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; -import { IAgToken } from "contracts/interfaces/IAgToken.sol"; +import { ITokenP } from "contracts/interfaces/ITokenP.sol"; import { AccessManagedUpgradeable, IAccessManager } from "../utils/AccessManagedUpgradeable.sol"; @@ -50,17 +16,20 @@ import "../utils/Constants.sol"; import "../utils/Errors.sol"; /// @title BaseSavings -/// @author Angle Labs, Inc. -/// @notice Angle Savings contracts are contracts where users can deposit an `asset` and earn a yield on this asset +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @notice Parallel Savings contracts are contracts where users can deposit an `asset` and earn a yield on this asset /// when it is distributed -/// @dev These contracts are functional within the Transmuter system if they have mint right on `asset` and -/// if they are trusted by the Transmuter contract +/// @dev These contracts are functional within the Parallelizer system if they have mint right on `asset` and +/// if they are trusted by the Parallelizer contract /// @dev Implementations assume that `asset` is safe to interact with, on which there cannot be reentrancy attacks /// @dev The ERC4626 interface does not allow users to specify a slippage protection parameter for the main entry /// points /// (like `deposit`, `mint`, `redeem` or `withdraw`). Even though there should be no specific sandwiching -/// issue with current implementations, it is still recommended to interact with Angle Savings contracts +/// issue with current implementations, it is still recommended to interact with Parallel Savings contracts /// through a router that can implement such a protection. +/// @dev This contract is a friendly fork of Angle's Savings contract: +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/savings/BaseSavings.sol abstract contract BaseSavings is Initializable, AccessManagedUpgradeable, ERC4626Upgradeable, UUPSUpgradeable { /// @custom:oz-upgrades-unsafe-allow constructor constructor() { diff --git a/contracts/savings/Savings.sol b/contracts/savings/Savings.sol index 4ad2647..5d28c53 100644 --- a/contracts/savings/Savings.sol +++ b/contracts/savings/Savings.sol @@ -1,12 +1,14 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import "./BaseSavings.sol"; /// @title Savings -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz /// @notice In this implementation, assets in the contract increase in value following a `rate` chosen by governance +/// @dev This contract is a friendly fork of Angle's Savings contract: +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/savings/Savings.sol contract Savings is BaseSavings { using SafeERC20 for IERC20Metadata; using Math for uint256; @@ -96,14 +98,14 @@ contract Savings is BaseSavings { CONTRACT LOGIC //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ - /// @notice Accrues interest to this contract by minting agTokens + /// @notice Accrues interest to this contract by minting tokenPs function _accrue() internal returns (uint256 newTotalAssets) { uint256 currentBalance = super.totalAssets(); newTotalAssets = _computeUpdatedAssets(currentBalance, block.timestamp - lastUpdate); lastUpdate = uint40(block.timestamp); uint256 earned = newTotalAssets - currentBalance; if (earned > 0) { - IAgToken(asset()).mint(address(this), earned); + ITokenP(asset()).mint(address(this), earned); emit Accrued(earned); } } diff --git a/contracts/savings/nameable/SavingsNameable.sol b/contracts/savings/nameable/SavingsNameable.sol index 5ec6714..14ddbd6 100644 --- a/contracts/savings/nameable/SavingsNameable.sol +++ b/contracts/savings/nameable/SavingsNameable.sol @@ -1,11 +1,13 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import "../Savings.sol"; /// @title SavingsNameable -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev This contract is a friendly fork of Angle's SavingsNameable contract: +/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/savings/nameable/SavingsNameable.sol contract SavingsNameable is Savings { string internal __name; diff --git a/contracts/utils/AccessManaged.sol b/contracts/utils/AccessManaged.sol index c15cce2..a0f3fae 100644 --- a/contracts/utils/AccessManaged.sol +++ b/contracts/utils/AccessManaged.sol @@ -9,7 +9,11 @@ import { Context } from "@openzeppelin/contracts/utils/Context.sol"; import "../utils/Errors.sol"; /// @title AccessControl -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev Fork of OpenZeppelin's `AccessManaged` contract +/// updated to make _checkCanCall to return bool +/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/manager/AccessManaged.sol contract AccessManaged is Context, IAccessManaged { address private _authority; diff --git a/contracts/utils/AccessManagedUpgradeable.sol b/contracts/utils/AccessManagedUpgradeable.sol index bad705d..db19f90 100644 --- a/contracts/utils/AccessManagedUpgradeable.sol +++ b/contracts/utils/AccessManagedUpgradeable.sol @@ -8,14 +8,12 @@ import { IAccessManaged } from "@openzeppelin/contracts/access/manager/IAccessMa import { ContextUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -/** - * @dev This contract module makes available a {restricted} modifier. Functions decorated with this modifier will be - * permissioned according to an "authority": a contract like {AccessManager} that follows the {IAuthority} interface, - * implementing a policy that allows certain callers to access certain functions. - * - * IMPORTANT: The `restricted` modifier should never be used on `internal` functions, judiciously used in `public` - * functions, and ideally only used in `external` functions. See {restricted}. - */ +/// @title AccessControl +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz +/// @dev Fork of OpenZeppelin's `AccessManagedUpgradeable` contract +/// updated to make _checkCanCall to return bool +/// https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/contracts/access/manager/AccessManagedUpgradeable.sol abstract contract AccessManagedUpgradeable is Initializable, ContextUpgradeable, IAccessManaged { /// @custom:storage-location erc7201:openzeppelin.storage.AccessManaged struct AccessManagedStorage { diff --git a/contracts/utils/Constants.sol b/contracts/utils/Constants.sol index 428bbf8..57b0b7f 100644 --- a/contracts/utils/Constants.sol +++ b/contracts/utils/Constants.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; import { ICbETH } from "../interfaces/external/coinbase/ICbETH.sol"; @@ -15,8 +14,8 @@ import { IRETH } from "../interfaces/external/rocketPool/IRETH.sol"; /// @dev Equals `keccak256("diamond.standard.diamond.storage") - 1` bytes32 constant DIAMOND_STORAGE_POSITION = 0xc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131b; -/// @dev Storage position of `TransmuterStorage` structure -/// @dev Equals `keccak256("diamond.standard.transmuter.storage") - 1` +/// @dev Storage position of `ParallelizerStorage` structure +/// @dev Equals `keccak256("diamond.standard.parallelizer.storage") - 1` bytes32 constant TRANSMUTER_STORAGE_POSITION = 0xc1f2f38dde3351ac0a64934139e816326caa800303a1235dc53707d0de05d8bd; /// @dev Storage position of `ImplementationStorage` structure diff --git a/contracts/utils/Errors.sol b/contracts/utils/Errors.sol index c59b113..6471a2c 100644 --- a/contracts/utils/Errors.sol +++ b/contracts/utils/Errors.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BUSL-1.1 - pragma solidity 0.8.28; error AccessManagedUnauthorized(address caller); diff --git a/libs/helpers/CommonUtils.sol b/libs/helpers/CommonUtils.sol index 695ebaa..609eabb 100644 --- a/libs/helpers/CommonUtils.sol +++ b/libs/helpers/CommonUtils.sol @@ -9,292 +9,290 @@ import { JsonReader } from "./JsonReader.sol"; import { strings } from "@stringutils/strings.sol"; import { ContractType, Constants } from "@helpers/Constants.sol"; +/// @title CommonUtils +/// @author Angle Labs, Inc. +/// @dev This contract is a friendly fork of Angle's `CommonUtils` contract +/// https://github.com/AngleProtocol/utils/blob/main/src/CommonUtils.sol contract CommonUtils is CommonBase, JsonReader { - using strings for *; - - bytes32 private constant EUR_HASH = keccak256(abi.encodePacked("EUR")); - bytes32 private constant USD_HASH = keccak256(abi.encodePacked("USD")); - - function _getAllContracts(uint256 chainId) internal view returns (address[] memory) { - string memory json = readJsonFile(getPath()); - - // Get all keys at the chain level (these are the contract categories) - string memory chainPath = string.concat(".", vm.toString(chainId)); - string[] memory keys = vm.parseJsonKeys(json, chainPath); - - // Create dynamic arrays to store addresses - address[] memory addresses = new address[](100); // Initial size - uint256 count = 0; - - // Iterate through each key to collect addresses - for (uint256 i = 0; i < keys.length; i++) { - string memory key = keys[i]; - string memory fullPath = string.concat(chainPath, ".", key); - - // Try to parse as direct address - try vm.parseJsonAddress(json, fullPath) returns (address addr) { - if (addr != address(0)) { - addresses[count++] = addr; - } - } catch { - // If not a direct address, try to parse nested objects - try vm.parseJsonKeys(json, fullPath) returns (string[] memory subKeys) { - for (uint256 j = 0; j < subKeys.length; j++) { - string memory subPath = string.concat(fullPath, ".", subKeys[j]); - try vm.parseJsonAddress(json, subPath) returns (address addr) { - if (addr != address(0)) { - addresses[count++] = addr; - } - } catch { } - } - } catch { } - } - } + using strings for *; - // Create final array with exact size - address[] memory result = new address[](count); - for (uint256 i = 0; i < count; i++) { - result[i] = addresses[i]; - } + bytes32 private constant EUR_HASH = keccak256(abi.encodePacked("EUR")); + bytes32 private constant USD_HASH = keccak256(abi.encodePacked("USD")); - return result; - } - - function _getConnectedChains(string memory token) internal returns (uint256[] memory, address[] memory) { - uint256[] memory allChainIds = _getChainIds(); - uint256[] memory chainIds = new uint256[](0); - address[] memory contracts = new address[](0); - - for (uint256 i = 0; i < allChainIds.length; i++) { - address addr; - if (keccak256(abi.encodePacked(token)) == EUR_HASH) { - try this.chainToContract(allChainIds[i], ContractType.LZEURp) returns (address _addr) { - addr = _addr; - } catch { } - } else if (keccak256(abi.encodePacked(token)) == USD_HASH) { - try this.chainToContract(allChainIds[i], ContractType.LZUSDp) returns (address _addr) { - addr = _addr; - } catch { } - } - - if (addr != address(0)) { - assembly ("memory-safe") { - // Get the current length of the arrays - let oldLen := mload(chainIds) - let newLen := add(oldLen, 1) - - // Calculate new memory locations - let newChainIds := add(mload(0x40), 0x20) - let newContracts := add(newChainIds, mul(add(newLen, 1), 0x20)) - - // Store lengths - mstore(newChainIds, newLen) - mstore(newContracts, newLen) - - // Copy existing chainIds - let srcChainIds := add(chainIds, 0x20) - let destChainIds := add(newChainIds, 0x20) - for { let j := 0 } lt(j, oldLen) { j := add(j, 1) } { - mstore(add(destChainIds, mul(j, 0x20)), mload(add(srcChainIds, mul(j, 0x20)))) - } - - // Copy existing contracts - let srcContracts := add(contracts, 0x20) - let destContracts := add(newContracts, 0x20) - for { let j := 0 } lt(j, oldLen) { j := add(j, 1) } { - mstore(add(destContracts, mul(j, 0x20)), mload(add(srcContracts, mul(j, 0x20)))) - } - - // Add new elements - mstore(add(destChainIds, mul(oldLen, 0x20)), mload(add(allChainIds, add(0x20, mul(i, 0x20))))) - mstore(add(destContracts, mul(oldLen, 0x20)), addr) - - // Update free memory pointer - mstore(0x40, add(newContracts, mul(add(newLen, 1), 0x20))) - - // Update array pointers - chainIds := newChainIds - contracts := newContracts - } - } - } + function _getAllContracts(uint256 chainId) internal view returns (address[] memory) { + string memory json = readJsonFile(getPath()); - return (chainIds, contracts); - } + // Get all keys at the chain level (these are the contract categories) + string memory chainPath = string.concat(".", vm.toString(chainId)); + string[] memory keys = vm.parseJsonKeys(json, chainPath); - /// @notice Get all chains from the SDK - function _getChainIds() internal view returns (uint256[] memory) { - // Parse the entire JSON object first - string memory json = readJsonFile(getPath()); + // Create dynamic arrays to store addresses + address[] memory addresses = new address[](100); // Initial size + uint256 count = 0; - // Get the object keys (chain IDs) at the root level - string[] memory chainIds = vm.parseJsonKeys(json, "."); + // Iterate through each key to collect addresses + for (uint256 i = 0; i < keys.length; i++) { + string memory key = keys[i]; + string memory fullPath = string.concat(chainPath, ".", key); - // Convert string array of chain IDs to uint256 array - uint256[] memory result = new uint256[](chainIds.length); - for (uint256 i = 0; i < chainIds.length; i++) { - result[i] = vm.parseUint(chainIds[i]); + // Try to parse as direct address + try vm.parseJsonAddress(json, fullPath) returns (address addr) { + if (addr != address(0)) { + addresses[count++] = addr; } - - return result; + } catch { + // If not a direct address, try to parse nested objects + try vm.parseJsonKeys(json, fullPath) returns (string[] memory subKeys) { + for (uint256 j = 0; j < subKeys.length; j++) { + string memory subPath = string.concat(fullPath, ".", subKeys[j]); + try vm.parseJsonAddress(json, subPath) returns (address addr) { + if (addr != address(0)) { + addresses[count++] = addr; + } + } catch { } + } + } catch { } + } } - /// @notice Get all chains where a specific contract type is deployed - function _getChainIdsWithDeployedContract(ContractType contractType) - internal - view - returns (uint256[] memory deployedChains) - { - string memory json = readJsonFile(getPath()); - string[] memory chainIds = vm.parseJsonKeys(json, "."); - - // First count how many chains have the contract deployed - uint256 deployedCount = 0; - for (uint256 i = 0; i < chainIds.length; i++) { - try this.chainToContract(vm.parseUint(chainIds[i]), contractType) { - deployedCount++; - } catch { - continue; - } - } + // Create final array with exact size + address[] memory result = new address[](count); + for (uint256 i = 0; i < count; i++) { + result[i] = addresses[i]; + } - // Create array of exact size and populate it - deployedChains = new uint256[](deployedCount); - uint256 currentIndex = 0; - for (uint256 i = 0; i < chainIds.length; i++) { - try this.chainToContract(vm.parseUint(chainIds[i]), contractType) { - deployedChains[currentIndex] = vm.parseUint(chainIds[i]); - currentIndex++; - } catch { - continue; - } + return result; + } + + function _getConnectedChains(string memory token) internal returns (uint256[] memory, address[] memory) { + uint256[] memory allChainIds = _getChainIds(); + uint256[] memory chainIds = new uint256[](0); + address[] memory contracts = new address[](0); + + for (uint256 i = 0; i < allChainIds.length; i++) { + address addr; + if (keccak256(abi.encodePacked(token)) == EUR_HASH) { + try this.chainToContract(allChainIds[i], ContractType.LZEURp) returns (address _addr) { + addr = _addr; + } catch { } + } else if (keccak256(abi.encodePacked(token)) == USD_HASH) { + try this.chainToContract(allChainIds[i], ContractType.LZUSDp) returns (address _addr) { + addr = _addr; + } catch { } + } + + if (addr != address(0)) { + assembly ("memory-safe") { + // Get the current length of the arrays + let oldLen := mload(chainIds) + let newLen := add(oldLen, 1) + + // Calculate new memory locations + let newChainIds := add(mload(0x40), 0x20) + let newContracts := add(newChainIds, mul(add(newLen, 1), 0x20)) + + // Store lengths + mstore(newChainIds, newLen) + mstore(newContracts, newLen) + + // Copy existing chainIds + let srcChainIds := add(chainIds, 0x20) + let destChainIds := add(newChainIds, 0x20) + for { let j := 0 } lt(j, oldLen) { j := add(j, 1) } { + mstore(add(destChainIds, mul(j, 0x20)), mload(add(srcChainIds, mul(j, 0x20)))) + } + + // Copy existing contracts + let srcContracts := add(contracts, 0x20) + let destContracts := add(newContracts, 0x20) + for { let j := 0 } lt(j, oldLen) { j := add(j, 1) } { + mstore(add(destContracts, mul(j, 0x20)), mload(add(srcContracts, mul(j, 0x20)))) + } + + // Add new elements + mstore(add(destChainIds, mul(oldLen, 0x20)), mload(add(allChainIds, add(0x20, mul(i, 0x20))))) + mstore(add(destContracts, mul(oldLen, 0x20)), addr) + + // Update free memory pointer + mstore(0x40, add(newContracts, mul(add(newLen, 1), 0x20))) + + // Update array pointers + chainIds := newChainIds + contracts := newContracts } + } } - function chainToContract(uint256 chainId, ContractType name) external view returns (address) { - return _chainToContract(chainId, name); - } + return (chainIds, contracts); + } - function _chainToContract(uint256 chainId, ContractType name) internal view returns (address) { - return this.readAddress(chainId, _getContractPath(name)); - } + /// @notice Get all chains from the SDK + function _getChainIds() internal view returns (uint256[] memory) { + // Parse the entire JSON object first + string memory json = readJsonFile(getPath()); - /// @dev Helper function to get the JSON path for a contract type - function _getContractPath(ContractType name) internal pure returns (string memory) { - if (name == ContractType.EURp) { - return "EUR.token"; - } else if (name == ContractType.USDp) { - return "USD.token"; - } else if (name == ContractType.LZEURp) { - return "EUR.lzToken"; - } else if (name == ContractType.LZUSDp) { - return "USD.lzToken"; - } else if (name == ContractType.PRL) { - return "PRL"; - } else if (name == ContractType.sEURp) { - return "EUR.Savings"; - } else if (name == ContractType.sUSDp) { - return "USD.Savings"; - } else if (name == ContractType.Timelock) { - return "Timelock"; - } else if (name == ContractType.TransmuterEURp) { - return "EUR.Transmuter"; - } else if (name == ContractType.TransmuterUSDp) { - return "USD.Transmuter"; - } else if (name == ContractType.TreasuryEURp) { - return "EUR.Treasury"; - } else if (name == ContractType.TreasuryUSDp) { - return "USD.Treasury"; - } else if (name == ContractType.FlashLoan) { - return "FlashLoan"; - } else if (name == ContractType.MultiBlockHarvester) { - return "USD.MultiBlockHarvester"; - } else if (name == ContractType.GenericHarvester) { - return "USD.GenericHarvester"; - } else if (name == ContractType.Harvester) { - return "USD.Harvester"; - } else if (name == ContractType.Rebalancer) { - return "USD.Rebalancer"; - } else if (name == ContractType.MulticallWithFailure) { - return "MulticallWithFailure"; - } else if (name == ContractType.OracleNativeUSD) { - return "OracleNativeUSD"; - } else if (name == ContractType.Swapper) { - return "Swapper"; - } else if (name == ContractType.ProxyAdmin) { - return "ProxyAdmin"; - } else if (name == ContractType.DaoMultisig) { - return "DaoMultisig"; - } else if (name == ContractType.GuardianMultisig) { - return "GuardianMultisig"; - } else { - revert("contract not supported"); - } - } + // Get the object keys (chain IDs) at the root level + string[] memory chainIds = vm.parseJsonKeys(json, "."); - function _stringToUint(string memory s) internal pure returns (uint256) { - bytes memory b = bytes(s); - uint256 result = 0; - for (uint256 i = 0; i < b.length; i++) { - uint256 c = uint256(uint8(b[i])); - if (c >= 48 && c <= 57) { - result = result * 10 + (c - 48); - } - } - return result; + // Convert string array of chain IDs to uint256 array + uint256[] memory result = new uint256[](chainIds.length); + for (uint256 i = 0; i < chainIds.length; i++) { + result[i] = vm.parseUint(chainIds[i]); } - function _generateSelectors(string memory _facetName) internal returns (bytes4[] memory selectors) { - return _generateSelectors(_facetName, 3); + return result; + } + + /// @notice Get all chains where a specific contract type is deployed + function _getChainIdsWithDeployedContract(ContractType contractType) + internal + view + returns (uint256[] memory deployedChains) + { + string memory json = readJsonFile(getPath()); + string[] memory chainIds = vm.parseJsonKeys(json, "."); + + // First count how many chains have the contract deployed + uint256 deployedCount = 0; + for (uint256 i = 0; i < chainIds.length; i++) { + try this.chainToContract(vm.parseUint(chainIds[i]), contractType) { + deployedCount++; + } catch { + continue; + } } - function _generateSelectors( - string memory _facetName, - uint256 retries - ) - internal - returns (bytes4[] memory selectors) - { - //get string of contract methods - string[] memory cmd = new string[](4); - cmd[0] = "forge"; - cmd[1] = "inspect"; - cmd[2] = _facetName; - cmd[3] = "methods"; - bytes memory res = vm.ffi(cmd); - string memory st = string(res); - // if empty, try again - if (bytes(st).length == 0) { - if (retries != 0) { - return _generateSelectors(_facetName, retries - 1); - } - } - // convert to slice - strings.slice memory s = st.toSlice(); - - // define delimiters - strings.slice memory rowDelim = "\n".toSlice(); - // strings.slice memory partDelim = "|".toSlice(); - strings.slice memory spaceDelim = " ".toSlice(); - - // remove first line - s.split(rowDelim); - - // determine number of methods - uint256 count = s.count(rowDelim); - count = count > 2 ? (count - 1) / 2 : count; - selectors = new bytes4[](count); - // remove column headers and separator lines - s.split(rowDelim); - s.split(rowDelim); - - for (uint256 i = 0; i < selectors.length; ++i) { - strings.slice memory currentLine = s.split(rowDelim); - // isolate method by removing space around it - currentLine.split(spaceDelim); - selectors[i] = bytes4(currentLine.split(spaceDelim).keccak()); - s.split(rowDelim); - } - return selectors; + // Create array of exact size and populate it + deployedChains = new uint256[](deployedCount); + uint256 currentIndex = 0; + for (uint256 i = 0; i < chainIds.length; i++) { + try this.chainToContract(vm.parseUint(chainIds[i]), contractType) { + deployedChains[currentIndex] = vm.parseUint(chainIds[i]); + currentIndex++; + } catch { + continue; + } + } + } + + function chainToContract(uint256 chainId, ContractType name) external view returns (address) { + return _chainToContract(chainId, name); + } + + function _chainToContract(uint256 chainId, ContractType name) internal view returns (address) { + return this.readAddress(chainId, _getContractPath(name)); + } + + /// @dev Helper function to get the JSON path for a contract type + function _getContractPath(ContractType name) internal pure returns (string memory) { + if (name == ContractType.EURp) { + return "EUR.token"; + } else if (name == ContractType.USDp) { + return "USD.token"; + } else if (name == ContractType.LZEURp) { + return "EUR.lzToken"; + } else if (name == ContractType.LZUSDp) { + return "USD.lzToken"; + } else if (name == ContractType.PRL) { + return "PRL"; + } else if (name == ContractType.sEURp) { + return "EUR.Savings"; + } else if (name == ContractType.sUSDp) { + return "USD.Savings"; + } else if (name == ContractType.Timelock) { + return "Timelock"; + } else if (name == ContractType.ParallelizerEURp) { + return "EUR.Parallelizer"; + } else if (name == ContractType.ParallelizerUSDp) { + return "USD.Parallelizer"; + } else if (name == ContractType.TreasuryEURp) { + return "EUR.Treasury"; + } else if (name == ContractType.TreasuryUSDp) { + return "USD.Treasury"; + } else if (name == ContractType.FlashLoan) { + return "FlashLoan"; + } else if (name == ContractType.MultiBlockHarvester) { + return "USD.MultiBlockHarvester"; + } else if (name == ContractType.GenericHarvester) { + return "USD.GenericHarvester"; + } else if (name == ContractType.Harvester) { + return "USD.Harvester"; + } else if (name == ContractType.Rebalancer) { + return "USD.Rebalancer"; + } else if (name == ContractType.MulticallWithFailure) { + return "MulticallWithFailure"; + } else if (name == ContractType.OracleNativeUSD) { + return "OracleNativeUSD"; + } else if (name == ContractType.Swapper) { + return "Swapper"; + } else if (name == ContractType.ProxyAdmin) { + return "ProxyAdmin"; + } else if (name == ContractType.DaoMultisig) { + return "DaoMultisig"; + } else if (name == ContractType.GuardianMultisig) { + return "GuardianMultisig"; + } else { + revert("contract not supported"); + } + } + + function _stringToUint(string memory s) internal pure returns (uint256) { + bytes memory b = bytes(s); + uint256 result = 0; + for (uint256 i = 0; i < b.length; i++) { + uint256 c = uint256(uint8(b[i])); + if (c >= 48 && c <= 57) { + result = result * 10 + (c - 48); + } + } + return result; + } + + function _generateSelectors(string memory _facetName) internal returns (bytes4[] memory selectors) { + return _generateSelectors(_facetName, 3); + } + + function _generateSelectors(string memory _facetName, uint256 retries) internal returns (bytes4[] memory selectors) { + //get string of contract methods + string[] memory cmd = new string[](4); + cmd[0] = "forge"; + cmd[1] = "inspect"; + cmd[2] = _facetName; + cmd[3] = "methods"; + bytes memory res = vm.ffi(cmd); + string memory st = string(res); + // if empty, try again + if (bytes(st).length == 0) { + if (retries != 0) { + return _generateSelectors(_facetName, retries - 1); + } + } + // convert to slice + strings.slice memory s = st.toSlice(); + + // define delimiters + strings.slice memory rowDelim = "\n".toSlice(); + // strings.slice memory partDelim = "|".toSlice(); + strings.slice memory spaceDelim = " ".toSlice(); + + // remove first line + s.split(rowDelim); + + // determine number of methods + uint256 count = s.count(rowDelim); + count = count > 2 ? (count - 1) / 2 : count; + selectors = new bytes4[](count); + // remove column headers and separator lines + s.split(rowDelim); + s.split(rowDelim); + + for (uint256 i = 0; i < selectors.length; ++i) { + strings.slice memory currentLine = s.split(rowDelim); + // isolate method by removing space around it + currentLine.split(spaceDelim); + selectors[i] = bytes4(currentLine.split(spaceDelim).keccak()); + s.split(rowDelim); } + return selectors; + } } diff --git a/libs/helpers/Constants.sol b/libs/helpers/Constants.sol index d36c977..f8a8976 100644 --- a/libs/helpers/Constants.sol +++ b/libs/helpers/Constants.sol @@ -2,48 +2,46 @@ pragma solidity ^0.8.0; enum StablecoinType { - EUR, - USD + EUR, + USD } enum ContractType { - EURp, - USDp, - LZEURp, - LZUSDp, - PRL, - sEURp, - sUSDp, - Timelock, - DaoMultisig, - ProxyAdmin, - GuardianMultisig, - TransmuterEURp, - TransmuterUSDp, - TreasuryEURp, - TreasuryUSDp, - FlashLoan, - MultiBlockHarvester, - GenericHarvester, - Harvester, - Rebalancer, - MulticallWithFailure, - OracleNativeUSD, - Swapper + EURp, + USDp, + LZEURp, + LZUSDp, + PRL, + sEURp, + sUSDp, + Timelock, + DaoMultisig, + ProxyAdmin, + GuardianMultisig, + ParallelizerEURp, + ParallelizerUSDp, + TreasuryEURp, + TreasuryUSDp, + FlashLoan, + MultiBlockHarvester, + GenericHarvester, + Harvester, + Rebalancer, + MulticallWithFailure, + OracleNativeUSD, + Swapper } - library Constants { - uint256 constant CHAIN_FORK = 0; - uint256 constant CHAIN_ETHEREUM = 1; - uint256 constant CHAIN_ARBITRUM = 42161; - uint256 constant CHAIN_AVALANCHE = 43114; - uint256 constant CHAIN_POLYGON = 137; - uint256 constant CHAIN_FANTOM = 250; - uint256 constant CHAIN_BASE = 8453; - uint256 constant BASE_18 = 1e18; - uint256 constant BASE_9 = 1e9; + uint256 constant CHAIN_FORK = 0; + uint256 constant CHAIN_ETHEREUM = 1; + uint256 constant CHAIN_ARBITRUM = 42_161; + uint256 constant CHAIN_AVALANCHE = 43_114; + uint256 constant CHAIN_POLYGON = 137; + uint256 constant CHAIN_FANTOM = 250; + uint256 constant CHAIN_BASE = 8453; + uint256 constant BASE_18 = 1e18; + uint256 constant BASE_9 = 1e9; - address constant IMMUTABLE_CREATE2_FACTORY_ADDRESS = - 0x0000000000FFe8B47B3e2130213B802212439497; + address constant IMMUTABLE_CREATE2_FACTORY_ADDRESS = 0x0000000000FFe8B47B3e2130213B802212439497; } diff --git a/libs/helpers/JsonReader.sol b/libs/helpers/JsonReader.sol index af5c791..8268662 100644 --- a/libs/helpers/JsonReader.sol +++ b/libs/helpers/JsonReader.sol @@ -1,157 +1,113 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.17; -import {Script} from "@forge-std/Script.sol"; -import {stdJson} from "@forge-std/StdJson.sol"; -import {ContractType} from "./Constants.sol"; +import { Script } from "@forge-std/Script.sol"; +import { stdJson } from "@forge-std/StdJson.sol"; +import { ContractType } from "./Constants.sol"; +/// @title JsonReader +/// @author Angle Labs, Inc. +/// @dev This contract is a friendly fork of Angle's `JsonReader` contract +/// https://github.com/AngleProtocol/utils/blob/main/src/JsonReader.sol contract JsonReader is Script { - using stdJson for string; + using stdJson for string; - error FileNotFound(string path); - error ValueNotFound(string path, string key); - error ChainNotSupported(uint256 chainId); + error FileNotFound(string path); + error ValueNotFound(string path, string key); + error ChainNotSupported(uint256 chainId); - // Mapping of chain IDs to their names - mapping(uint256 => string) internal chainNames; + // Mapping of chain IDs to their names + mapping(uint256 => string) internal chainNames; - /// @notice Gets the network-specific config path - /// @return The full path to the network config file - function getPath() public view returns (string memory) { - string memory root = vm.projectRoot(); - return - string.concat( - root, - "/libs/helpers/registry/registry.json" - ); - } + /// @notice Gets the network-specific config path + /// @return The full path to the network config file + function getPath() public view returns (string memory) { + string memory root = vm.projectRoot(); + return string.concat(root, "/libs/helpers/registry/registry.json"); + } - /// @notice Reads an address value from the network's JSON file - /// @param chainId The chain ID - /// @param key The JSON key to read - /// @return The address value - function readAddress( - uint256 chainId, - string memory key - ) public view returns (address) { - string memory path = getPath(); - return - readAddressFromPath( - path, - string.concat(vm.toString(chainId), ".", key) - ); - } + /// @notice Reads an address value from the network's JSON file + /// @param chainId The chain ID + /// @param key The JSON key to read + /// @return The address value + function readAddress(uint256 chainId, string memory key) public view returns (address) { + string memory path = getPath(); + return readAddressFromPath(path, string.concat(vm.toString(chainId), ".", key)); + } - /// @notice Reads a string value from the network's JSON file - /// @param chainId The chain ID - /// @param key The JSON key to read - /// @return The string value - function readString( - uint256 chainId, - string memory key - ) public view returns (string memory) { - string memory path = getPath(); - return - readStringFromPath( - path, - string.concat(vm.toString(chainId), ".", key) - ); - } + /// @notice Reads a string value from the network's JSON file + /// @param chainId The chain ID + /// @param key The JSON key to read + /// @return The string value + function readString(uint256 chainId, string memory key) public view returns (string memory) { + string memory path = getPath(); + return readStringFromPath(path, string.concat(vm.toString(chainId), ".", key)); + } - /// @notice Reads a uint256 value from the network's JSON file - /// @param chainId The chain ID - /// @param key The JSON key to read - /// @return The uint256 value - function readUint( - uint256 chainId, - string memory key - ) public view returns (uint256) { - string memory path = getPath(); - return - readUintFromPath( - path, - string.concat(vm.toString(chainId), ".", key) - ); - } + /// @notice Reads a uint256 value from the network's JSON file + /// @param chainId The chain ID + /// @param key The JSON key to read + /// @return The uint256 value + function readUint(uint256 chainId, string memory key) public view returns (uint256) { + string memory path = getPath(); + return readUintFromPath(path, string.concat(vm.toString(chainId), ".", key)); + } - /// @notice Reads a string array from the network's JSON file - /// @param chainId The chain ID - /// @param key The JSON key to read - /// @return The string array - function readStringArray( - uint256 chainId, - string memory key - ) public view returns (string[] memory) { - string memory path = getPath(); - return - readStringArrayFromPath( - path, - string.concat(vm.toString(chainId), ".", key) - ); - } + /// @notice Reads a string array from the network's JSON file + /// @param chainId The chain ID + /// @param key The JSON key to read + /// @return The string array + function readStringArray(uint256 chainId, string memory key) public view returns (string[] memory) { + string memory path = getPath(); + return readStringArrayFromPath(path, string.concat(vm.toString(chainId), ".", key)); + } - // Direct path reading functions - function readAddressFromPath( - string memory path, - string memory key - ) public view returns (address) { - string memory json = readJsonFile(path); - bytes memory raw = json.parseRaw(string.concat(".", key)); - if (raw.length == 0) revert ValueNotFound(path, key); - return bytesToAddress(raw); - } + // Direct path reading functions + function readAddressFromPath(string memory path, string memory key) public view returns (address) { + string memory json = readJsonFile(path); + bytes memory raw = json.parseRaw(string.concat(".", key)); + if (raw.length == 0) revert ValueNotFound(path, key); + return bytesToAddress(raw); + } - function readStringFromPath( - string memory path, - string memory key - ) public view returns (string memory) { - string memory json = readJsonFile(path); - bytes memory raw = json.parseRaw(string.concat(".", key)); - if (raw.length == 0) revert ValueNotFound(path, key); - return string(raw); - } + function readStringFromPath(string memory path, string memory key) public view returns (string memory) { + string memory json = readJsonFile(path); + bytes memory raw = json.parseRaw(string.concat(".", key)); + if (raw.length == 0) revert ValueNotFound(path, key); + return string(raw); + } - function readUintFromPath( - string memory path, - string memory key - ) public view returns (uint256) { - string memory json = readJsonFile(path); - bytes memory raw = json.parseRaw(string.concat(".", key)); - if (raw.length == 0) revert ValueNotFound(path, key); - return abi.decode(raw, (uint256)); - } + function readUintFromPath(string memory path, string memory key) public view returns (uint256) { + string memory json = readJsonFile(path); + bytes memory raw = json.parseRaw(string.concat(".", key)); + if (raw.length == 0) revert ValueNotFound(path, key); + return abi.decode(raw, (uint256)); + } - function readStringArrayFromPath( - string memory path, - string memory key - ) public view returns (string[] memory) { - string memory json = readJsonFile(path); - bytes memory raw = json.parseRaw(string.concat(".", key)); - if (raw.length == 0) revert ValueNotFound(path, key); - return abi.decode(raw, (string[])); - } + function readStringArrayFromPath(string memory path, string memory key) public view returns (string[] memory) { + string memory json = readJsonFile(path); + bytes memory raw = json.parseRaw(string.concat(".", key)); + if (raw.length == 0) revert ValueNotFound(path, key); + return abi.decode(raw, (string[])); + } - /// @notice Reads a JSON file from the given path - /// @param path The path to the JSON file - /// @return The JSON content as a string - function readJsonFile( - string memory path - ) public view returns (string memory) { - try vm.readFile(path) returns (string memory json) { - return json; - } catch { - revert FileNotFound(path); - } + /// @notice Reads a JSON file from the given path + /// @param path The path to the JSON file + /// @return The JSON content as a string + function readJsonFile(string memory path) public view returns (string memory) { + try vm.readFile(path) returns (string memory json) { + return json; + } catch { + revert FileNotFound(path); } + } - /// @notice Utility function to convert bytes to address - /// @param bys Bytes to convert - /// @return addr Resulting address - function bytesToAddress( - bytes memory bys - ) private pure returns (address addr) { - assembly("memory-safe") { - addr := mload(add(bys, 32)) - } + /// @notice Utility function to convert bytes to address + /// @param bys Bytes to convert + /// @return addr Resulting address + function bytesToAddress(bytes memory bys) private pure returns (address addr) { + assembly ("memory-safe") { + addr := mload(add(bys, 32)) } + } } diff --git a/libs/helpers/RouterSwapper.sol b/libs/helpers/RouterSwapper.sol index ed2ead1..f8e3ef5 100644 --- a/libs/helpers/RouterSwapper.sol +++ b/libs/helpers/RouterSwapper.sol @@ -6,147 +6,151 @@ import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/Saf /// @title Swapper /// @author Angle Labs, Inc. /// @dev Abstract contract for swapping tokens using a router/aggregator +/// @dev This contract is a friendly fork of Angle's `RouterSwapper` contract +/// https://github.com/AngleProtocol/utils/blob/main/src/RouterSwapper.sol abstract contract RouterSwapper { - using SafeERC20 for IERC20; + using SafeERC20 for IERC20; - /*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// ERRORS //////////////////////////////////////////////////////////////*/ - error SwapError(); - error ZeroAddress(); + error SwapError(); + error ZeroAddress(); - /*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ - /** - * @notice Event emitted when the swap router is updated - */ - event SwapRouterUpdated(address newSwapRouter); - /** - * @notice Event emitted when the token proxy is updated - */ - event TokenTransferAddressUpdated(address newTokenTransferAddress); + /** + * @notice Event emitted when the swap router is updated + */ + event SwapRouterUpdated(address newSwapRouter); + /** + * @notice Event emitted when the token proxy is updated + */ + event TokenTransferAddressUpdated(address newTokenTransferAddress); - /*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// MODIFIERS //////////////////////////////////////////////////////////////*/ - modifier noZeroAddress(address targetAddress) { - if (targetAddress == address(0)) { - revert ZeroAddress(); - } - _; + modifier noZeroAddress(address targetAddress) { + if (targetAddress == address(0)) { + revert ZeroAddress(); } + _; + } - /*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// MUTABLE VARIABLES //////////////////////////////////////////////////////////////*/ - /** - * @notice address of the router/aggregator - */ - address public swapRouter; - /** - * @notice address to approve to transfer tokens to - */ - address public tokenTransferAddress; + /** + * @notice address of the router/aggregator + */ + address public swapRouter; + /** + * @notice address to approve to transfer tokens to + */ + address public tokenTransferAddress; - /*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ - constructor(address initialSwapRouter, address initialTokenTransferAddress) { - swapRouter = initialSwapRouter; - tokenTransferAddress = initialTokenTransferAddress; - } + constructor(address initialSwapRouter, address initialTokenTransferAddress) { + swapRouter = initialSwapRouter; + tokenTransferAddress = initialTokenTransferAddress; + } - /*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// ADMIN FUNCTIONS //////////////////////////////////////////////////////////////*/ - /** - * @notice Set the router/aggregator address - * @param newSwapRouter address of the new router/aggregator - */ - function setSwapRouter(address newSwapRouter) public virtual noZeroAddress(newSwapRouter) { - swapRouter = newSwapRouter; - - emit SwapRouterUpdated(newSwapRouter); - } - - /** - * @notice Set the token transfer address - * @param newTokenTransferAddress address of the new token transfer address - */ - function setTokenTransferAddress( - address newTokenTransferAddress - ) public virtual noZeroAddress(newTokenTransferAddress) { - tokenTransferAddress = newTokenTransferAddress; - - emit TokenTransferAddressUpdated(newTokenTransferAddress); - } - - /*////////////////////////////////////////////////////////////// + /** + * @notice Set the router/aggregator address + * @param newSwapRouter address of the new router/aggregator + */ + function setSwapRouter(address newSwapRouter) public virtual noZeroAddress(newSwapRouter) { + swapRouter = newSwapRouter; + + emit SwapRouterUpdated(newSwapRouter); + } + + /** + * @notice Set the token transfer address + * @param newTokenTransferAddress address of the new token transfer address + */ + function setTokenTransferAddress(address newTokenTransferAddress) + public + virtual + noZeroAddress(newTokenTransferAddress) + { + tokenTransferAddress = newTokenTransferAddress; + + emit TokenTransferAddressUpdated(newTokenTransferAddress); + } + + /*////////////////////////////////////////////////////////////// SWAP FUNCTIONS //////////////////////////////////////////////////////////////*/ - /** - * @notice Approve the router/aggregator to spend the token if needed - * @param token address of the token to approve - * @param spender address of the router/aggregator - * @param amount amount to approve - */ - function _approveTokenIfNeeded(address token, address spender, uint256 amount) internal { - uint256 allowance = IERC20(token).allowance(address(this), spender); - if (allowance < amount) { - IERC20(token).safeIncreaseAllowance(spender, amount - allowance); - } + /** + * @notice Approve the router/aggregator to spend the token if needed + * @param token address of the token to approve + * @param spender address of the router/aggregator + * @param amount amount to approve + */ + function _approveTokenIfNeeded(address token, address spender, uint256 amount) internal { + uint256 allowance = IERC20(token).allowance(address(this), spender); + if (allowance < amount) { + IERC20(token).safeIncreaseAllowance(spender, amount - allowance); } - - /** - * @notice Perform the swap using the router/aggregator - * @param callData bytes to call the router/aggregator - */ - function _performRouterSwap(bytes memory callData) internal { - (bool success, bytes memory retData) = swapRouter.call(callData); - - if (!success) { - if (retData.length != 0) { - assembly("memory-safe") { - revert(add(32, retData), mload(retData)) - } - } - revert SwapError(); + } + + /** + * @notice Perform the swap using the router/aggregator + * @param callData bytes to call the router/aggregator + */ + function _performRouterSwap(bytes memory callData) internal { + (bool success, bytes memory retData) = swapRouter.call(callData); + + if (!success) { + if (retData.length != 0) { + assembly ("memory-safe") { + revert(add(32, retData), mload(retData)) } + } + revert SwapError(); } - - /** - * @notice Swap tokens using the router/aggregator - * @param tokens array of tokens to swap - * @param callDatas array of bytes to call the router/aggregator - * @param amounts array of amounts to swap - */ - function _swapCalldata(address[] calldata tokens, bytes[] calldata callDatas, uint256[] calldata amounts) internal { - uint256 length = tokens.length; - for (uint256 i; i < length; ++i) { - _approveTokenIfNeeded(tokens[i], tokenTransferAddress, amounts[i]); - _performRouterSwap(callDatas[i]); - } + } + + /** + * @notice Swap tokens using the router/aggregator + * @param tokens array of tokens to swap + * @param callDatas array of bytes to call the router/aggregator + * @param amounts array of amounts to swap + */ + function _swapCalldata(address[] calldata tokens, bytes[] calldata callDatas, uint256[] calldata amounts) internal { + uint256 length = tokens.length; + for (uint256 i; i < length; ++i) { + _approveTokenIfNeeded(tokens[i], tokenTransferAddress, amounts[i]); + _performRouterSwap(callDatas[i]); } - - /** - * @notice Swap tokens using the router/aggregator - * @param tokens array of tokens to swap - * @param callDatas array of bytes to call the router/aggregator - * @param amounts array of amounts to swap - */ - function _swap(address[] memory tokens, bytes[] memory callDatas, uint256[] memory amounts) internal { - uint256 length = tokens.length; - for (uint256 i; i < length; ++i) { - _approveTokenIfNeeded(tokens[i], tokenTransferAddress, amounts[i]); - _performRouterSwap(callDatas[i]); - } + } + + /** + * @notice Swap tokens using the router/aggregator + * @param tokens array of tokens to swap + * @param callDatas array of bytes to call the router/aggregator + * @param amounts array of amounts to swap + */ + function _swap(address[] memory tokens, bytes[] memory callDatas, uint256[] memory amounts) internal { + uint256 length = tokens.length; + for (uint256 i; i < length; ++i) { + _approveTokenIfNeeded(tokens[i], tokenTransferAddress, amounts[i]); + _performRouterSwap(callDatas[i]); } + } } diff --git a/libs/stringutils/strings.sol b/libs/stringutils/strings.sol index e6810a2..9836b31 100644 --- a/libs/stringutils/strings.sol +++ b/libs/stringutils/strings.sol @@ -1,7 +1,9 @@ +pragma solidity ^0.8.0; /* * @title String & slice utility library for Solidity contracts. * @author Nick Johnson - * + * @dev This library is taken from + * https://github.com/Arachnid/solidity-stringutils/blob/master/src/strings.sol * @dev Functionality in this library is largely implemented using an * abstraction called a 'slice'. A slice represents a part of a string - * anything from the entire string to a single character, or even no @@ -34,123 +36,123 @@ * corresponding to the left and right parts of the string. */ -pragma solidity ^0.8.0; - -/// @dev This library is taken from https://github.com/Arachnid/solidity-stringutils/blob/master/src/strings.sol library strings { - struct slice { - uint _len; - uint _ptr; - } - - function memcpy(uint dest, uint src, uint length) private pure { - // Copy word-length chunks while possible - for(; length >= 32; length -= 32) { - assembly("memory-safe") { - mstore(dest, mload(src)) - } - dest += 32; - src += 32; - } + struct slice { + uint256 _len; + uint256 _ptr; + } + + function memcpy(uint256 dest, uint256 src, uint256 length) private pure { + // Copy word-length chunks while possible + for (; length >= 32; length -= 32) { + assembly ("memory-safe") { + mstore(dest, mload(src)) + } + dest += 32; + src += 32; + } - // Copy remaining bytes - uint mask = type(uint).max; - if (length > 0) { - mask = 256 ** (32 - length) - 1; - } - assembly ("memory-safe") { - let srcpart := and(mload(src), not(mask)) - let destpart := and(mload(dest), mask) - mstore(dest, or(destpart, srcpart)) - } + // Copy remaining bytes + uint256 mask = type(uint256).max; + if (length > 0) { + mask = 256 ** (32 - length) - 1; } + assembly ("memory-safe") { + let srcpart := and(mload(src), not(mask)) + let destpart := and(mload(dest), mask) + mstore(dest, or(destpart, srcpart)) + } + } - /* + /* * @dev Returns a slice containing the entire string. * @param self The string to make a slice from. * @return A newly allocated slice containing the entire string. */ - function toSlice(string memory self) internal pure returns (slice memory) { - uint ptr; - assembly ("memory-safe") { - ptr := add(self, 0x20) - } - return slice(bytes(self).length, ptr); + function toSlice(string memory self) internal pure returns (slice memory) { + uint256 ptr; + assembly ("memory-safe") { + ptr := add(self, 0x20) } + return slice(bytes(self).length, ptr); + } - /* + /* * @dev Returns the length of a null-terminated bytes32 string. * @param self The value to find the length of. * @return The length of the string, from 0 to 32. */ - function len(bytes32 self) internal pure returns (uint) { - uint ret; - if (self == 0) - return 0; - if (uint(self) & type(uint128).max == 0) { - ret += 16; - self = bytes32(uint(self) / 0x100000000000000000000000000000000); - } - if (uint(self) & type(uint64).max == 0) { - ret += 8; - self = bytes32(uint(self) / 0x10000000000000000); - } - if (uint(self) & type(uint32).max == 0) { - ret += 4; - self = bytes32(uint(self) / 0x100000000); - } - if (uint(self) & type(uint16).max == 0) { - ret += 2; - self = bytes32(uint(self) / 0x10000); - } - if (uint(self) & type(uint8).max == 0) { - ret += 1; - } - return 32 - ret; + function len(bytes32 self) internal pure returns (uint256) { + uint256 ret; + if (self == 0) { + return 0; + } + if (uint256(self) & type(uint128).max == 0) { + ret += 16; + self = bytes32(uint256(self) / 0x100000000000000000000000000000000); + } + if (uint256(self) & type(uint64).max == 0) { + ret += 8; + self = bytes32(uint256(self) / 0x10000000000000000); + } + if (uint256(self) & type(uint32).max == 0) { + ret += 4; + self = bytes32(uint256(self) / 0x100000000); + } + if (uint256(self) & type(uint16).max == 0) { + ret += 2; + self = bytes32(uint256(self) / 0x10000); } + if (uint256(self) & type(uint8).max == 0) { + ret += 1; + } + return 32 - ret; + } - /* + /* * @dev Returns a slice containing the entire bytes32, interpreted as a * null-terminated utf-8 string. * @param self The bytes32 value to convert to a slice. * @return A new slice containing the value of the input argument up to the * first null. */ - function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { - // Allocate space for `self` in memory, copy it there, and point ret at it - assembly ("memory-safe") { - let ptr := mload(0x40) - mstore(0x40, add(ptr, 0x20)) - mstore(ptr, self) - mstore(add(ret, 0x20), ptr) - } - ret._len = len(self); + function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { + // Allocate space for `self` in memory, copy it there, and point ret at it + assembly ("memory-safe") { + let ptr := mload(0x40) + mstore(0x40, add(ptr, 0x20)) + mstore(ptr, self) + mstore(add(ret, 0x20), ptr) } + ret._len = len(self); + } - /* + /* * @dev Returns a new slice containing the same data as the current slice. * @param self The slice to copy. * @return A new slice containing the same data as `self`. */ - function copy(slice memory self) internal pure returns (slice memory) { - return slice(self._len, self._ptr); - } + function copy(slice memory self) internal pure returns (slice memory) { + return slice(self._len, self._ptr); + } - /* + /* * @dev Copies a slice to a new string. * @param self The slice to copy. * @return A newly allocated string containing the slice's text. */ - function toString(slice memory self) internal pure returns (string memory) { - string memory ret = new string(self._len); - uint retptr; - assembly ("memory-safe") { retptr := add(ret, 32) } - - memcpy(retptr, self._ptr, self._len); - return ret; + function toString(slice memory self) internal pure returns (string memory) { + string memory ret = new string(self._len); + uint256 retptr; + assembly ("memory-safe") { + retptr := add(ret, 32) } - /* + memcpy(retptr, self._ptr, self._len); + return ret; + } + + /* * @dev Returns the length in runes of the slice. Note that this operation * takes time proportional to the length of the slice; avoid using it * in loops, and call `slice.empty()` if you only need to know whether @@ -158,39 +160,41 @@ library strings { * @param self The slice to operate on. * @return The length of the slice in runes. */ - function len(slice memory self) internal pure returns (uint l) { - // Starting at ptr-31 means the LSB will be the byte we care about - uint ptr = self._ptr - 31; - uint end = ptr + self._len; - for (l = 0; ptr < end; l++) { - uint8 b; - assembly ("memory-safe") { b := and(mload(ptr), 0xFF) } - if (b < 0x80) { - ptr += 1; - } else if(b < 0xE0) { - ptr += 2; - } else if(b < 0xF0) { - ptr += 3; - } else if(b < 0xF8) { - ptr += 4; - } else if(b < 0xFC) { - ptr += 5; - } else { - ptr += 6; - } - } + function len(slice memory self) internal pure returns (uint256 l) { + // Starting at ptr-31 means the LSB will be the byte we care about + uint256 ptr = self._ptr - 31; + uint256 end = ptr + self._len; + for (l = 0; ptr < end; l++) { + uint8 b; + assembly ("memory-safe") { + b := and(mload(ptr), 0xFF) + } + if (b < 0x80) { + ptr += 1; + } else if (b < 0xE0) { + ptr += 2; + } else if (b < 0xF0) { + ptr += 3; + } else if (b < 0xF8) { + ptr += 4; + } else if (b < 0xFC) { + ptr += 5; + } else { + ptr += 6; + } } + } - /* + /* * @dev Returns true if the slice is empty (has a length of 0). * @param self The slice to operate on. * @return True if the slice is empty, False otherwise. */ - function empty(slice memory self) internal pure returns (bool) { - return self._len == 0; - } + function empty(slice memory self) internal pure returns (bool) { + return self._len == 0; + } - /* + /* * @dev Returns a positive number if `other` comes lexicographically after * `self`, a negative number if it comes before, or zero if the * contents of the two slices are equal. Comparison is done per-rune, @@ -199,360 +203,408 @@ library strings { * @param other The second slice to compare. * @return The result of the comparison. */ - function compare(slice memory self, slice memory other) internal pure returns (int) { - uint shortest = self._len; - if (other._len < self._len) - shortest = other._len; - - uint selfptr = self._ptr; - uint otherptr = other._ptr; - for (uint idx = 0; idx < shortest; idx += 32) { - uint a; - uint b; - assembly ("memory-safe") { - a := mload(selfptr) - b := mload(otherptr) - } - if (a != b) { - // Mask out irrelevant bytes and check again - uint mask = type(uint).max; // 0xffff... - if(shortest < 32) { - mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); - } - unchecked { - uint diff = (a & mask) - (b & mask); - if (diff != 0) - return int(diff); - } - } - selfptr += 32; - otherptr += 32; - } - return int(self._len) - int(other._len); + function compare(slice memory self, slice memory other) internal pure returns (int256) { + uint256 shortest = self._len; + if (other._len < self._len) { + shortest = other._len; } - /* + uint256 selfptr = self._ptr; + uint256 otherptr = other._ptr; + for (uint256 idx = 0; idx < shortest; idx += 32) { + uint256 a; + uint256 b; + assembly ("memory-safe") { + a := mload(selfptr) + b := mload(otherptr) + } + if (a != b) { + // Mask out irrelevant bytes and check again + uint256 mask = type(uint256).max; // 0xffff... + if (shortest < 32) { + mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); + } + unchecked { + uint256 diff = (a & mask) - (b & mask); + if (diff != 0) { + return int256(diff); + } + } + } + selfptr += 32; + otherptr += 32; + } + return int256(self._len) - int256(other._len); + } + + /* * @dev Returns true if the two slices contain the same text. * @param self The first slice to compare. * @param self The second slice to compare. * @return True if the slices are equal, false otherwise. */ - function equals(slice memory self, slice memory other) internal pure returns (bool) { - return compare(self, other) == 0; - } + function equals(slice memory self, slice memory other) internal pure returns (bool) { + return compare(self, other) == 0; + } - /* + /* * @dev Extracts the first rune in the slice into `rune`, advancing the * slice to point to the next rune and returning `self`. * @param self The slice to operate on. * @param rune The slice that will contain the first rune. * @return `rune`. */ - function nextRune(slice memory self, slice memory rune) internal pure returns (slice memory) { - rune._ptr = self._ptr; + function nextRune(slice memory self, slice memory rune) internal pure returns (slice memory) { + rune._ptr = self._ptr; - if (self._len == 0) { - rune._len = 0; - return rune; - } - - uint l; - uint b; - // Load the first byte of the rune into the LSBs of b - assembly ("memory-safe") { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) } - if (b < 0x80) { - l = 1; - } else if(b < 0xE0) { - l = 2; - } else if(b < 0xF0) { - l = 3; - } else { - l = 4; - } + if (self._len == 0) { + rune._len = 0; + return rune; + } - // Check for truncated codepoints - if (l > self._len) { - rune._len = self._len; - self._ptr += self._len; - self._len = 0; - return rune; - } + uint256 l; + uint256 b; + // Load the first byte of the rune into the LSBs of b + assembly ("memory-safe") { + b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) + } + if (b < 0x80) { + l = 1; + } else if (b < 0xE0) { + l = 2; + } else if (b < 0xF0) { + l = 3; + } else { + l = 4; + } - self._ptr += l; - self._len -= l; - rune._len = l; - return rune; + // Check for truncated codepoints + if (l > self._len) { + rune._len = self._len; + self._ptr += self._len; + self._len = 0; + return rune; } - /* + self._ptr += l; + self._len -= l; + rune._len = l; + return rune; + } + + /* * @dev Returns the first rune in the slice, advancing the slice to point * to the next rune. * @param self The slice to operate on. * @return A slice containing only the first rune from `self`. */ - function nextRune(slice memory self) internal pure returns (slice memory ret) { - nextRune(self, ret); - } + function nextRune(slice memory self) internal pure returns (slice memory ret) { + nextRune(self, ret); + } - /* + /* * @dev Returns the number of the first codepoint in the slice. * @param self The slice to operate on. * @return The number of the first codepoint in the slice. */ - function ord(slice memory self) internal pure returns (uint ret) { - if (self._len == 0) { - return 0; - } + function ord(slice memory self) internal pure returns (uint256 ret) { + if (self._len == 0) { + return 0; + } - uint word; - uint length; - uint divisor = 2 ** 248; - - // Load the rune into the MSBs of b - assembly ("memory-safe") { word:= mload(mload(add(self, 32))) } - uint b = word / divisor; - if (b < 0x80) { - ret = b; - length = 1; - } else if(b < 0xE0) { - ret = b & 0x1F; - length = 2; - } else if(b < 0xF0) { - ret = b & 0x0F; - length = 3; - } else { - ret = b & 0x07; - length = 4; - } + uint256 word; + uint256 length; + uint256 divisor = 2 ** 248; - // Check for truncated codepoints - if (length > self._len) { - return 0; - } + // Load the rune into the MSBs of b + assembly ("memory-safe") { + word := mload(mload(add(self, 32))) + } + uint256 b = word / divisor; + if (b < 0x80) { + ret = b; + length = 1; + } else if (b < 0xE0) { + ret = b & 0x1F; + length = 2; + } else if (b < 0xF0) { + ret = b & 0x0F; + length = 3; + } else { + ret = b & 0x07; + length = 4; + } - for (uint i = 1; i < length; i++) { - divisor = divisor / 256; - b = (word / divisor) & 0xFF; - if (b & 0xC0 != 0x80) { - // Invalid UTF-8 sequence - return 0; - } - ret = (ret * 64) | (b & 0x3F); - } + // Check for truncated codepoints + if (length > self._len) { + return 0; + } - return ret; + for (uint256 i = 1; i < length; i++) { + divisor = divisor / 256; + b = (word / divisor) & 0xFF; + if (b & 0xC0 != 0x80) { + // Invalid UTF-8 sequence + return 0; + } + ret = (ret * 64) | (b & 0x3F); } - /* + return ret; + } + + /* * @dev Returns the keccak-256 hash of the slice. * @param self The slice to hash. * @return The hash of the slice. */ - function keccak(slice memory self) internal pure returns (bytes32 ret) { - assembly ("memory-safe") { - ret := keccak256(mload(add(self, 32)), mload(self)) - } + function keccak(slice memory self) internal pure returns (bytes32 ret) { + assembly ("memory-safe") { + ret := keccak256(mload(add(self, 32)), mload(self)) } + } - /* + /* * @dev Returns true if `self` starts with `needle`. * @param self The slice to operate on. * @param needle The slice to search for. * @return True if the slice starts with the provided text, false otherwise. */ - function startsWith(slice memory self, slice memory needle) internal pure returns (bool) { - if (self._len < needle._len) { - return false; - } + function startsWith(slice memory self, slice memory needle) internal pure returns (bool) { + if (self._len < needle._len) { + return false; + } - if (self._ptr == needle._ptr) { - return true; - } + if (self._ptr == needle._ptr) { + return true; + } - bool equal; - assembly ("memory-safe") { - let length := mload(needle) - let selfptr := mload(add(self, 0x20)) - let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) - } - return equal; + bool equal; + assembly ("memory-safe") { + let length := mload(needle) + let selfptr := mload(add(self, 0x20)) + let needleptr := mload(add(needle, 0x20)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } + return equal; + } - /* + /* * @dev If `self` starts with `needle`, `needle` is removed from the * beginning of `self`. Otherwise, `self` is unmodified. * @param self The slice to operate on. * @param needle The slice to search for. * @return `self` */ - function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) { - if (self._len < needle._len) { - return self; - } - - bool equal = true; - if (self._ptr != needle._ptr) { - assembly ("memory-safe") { - let length := mload(needle) - let selfptr := mload(add(self, 0x20)) - let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) - } - } + function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) { + if (self._len < needle._len) { + return self; + } - if (equal) { - self._len -= needle._len; - self._ptr += needle._len; - } + bool equal = true; + if (self._ptr != needle._ptr) { + assembly ("memory-safe") { + let length := mload(needle) + let selfptr := mload(add(self, 0x20)) + let needleptr := mload(add(needle, 0x20)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) + } + } - return self; + if (equal) { + self._len -= needle._len; + self._ptr += needle._len; } - /* + return self; + } + + /* * @dev Returns true if the slice ends with `needle`. * @param self The slice to operate on. * @param needle The slice to search for. * @return True if the slice starts with the provided text, false otherwise. */ - function endsWith(slice memory self, slice memory needle) internal pure returns (bool) { - if (self._len < needle._len) { - return false; - } - - uint selfptr = self._ptr + self._len - needle._len; + function endsWith(slice memory self, slice memory needle) internal pure returns (bool) { + if (self._len < needle._len) { + return false; + } - if (selfptr == needle._ptr) { - return true; - } + uint256 selfptr = self._ptr + self._len - needle._len; - bool equal; - assembly ("memory-safe") { - let length := mload(needle) - let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) - } + if (selfptr == needle._ptr) { + return true; + } - return equal; + bool equal; + assembly ("memory-safe") { + let length := mload(needle) + let needleptr := mload(add(needle, 0x20)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } - /* + return equal; + } + + /* * @dev If `self` ends with `needle`, `needle` is removed from the * end of `self`. Otherwise, `self` is unmodified. * @param self The slice to operate on. * @param needle The slice to search for. * @return `self` */ - function until(slice memory self, slice memory needle) internal pure returns (slice memory) { - if (self._len < needle._len) { - return self; - } + function until(slice memory self, slice memory needle) internal pure returns (slice memory) { + if (self._len < needle._len) { + return self; + } + + uint256 selfptr = self._ptr + self._len - needle._len; + bool equal = true; + if (selfptr != needle._ptr) { + assembly ("memory-safe") { + let length := mload(needle) + let needleptr := mload(add(needle, 0x20)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) + } + } + + if (equal) { + self._len -= needle._len; + } - uint selfptr = self._ptr + self._len - needle._len; - bool equal = true; - if (selfptr != needle._ptr) { - assembly ("memory-safe") { - let length := mload(needle) - let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) - } + return self; + } + + // Returns the memory address of the first byte of the first occurrence of + // `needle` in `self`, or the first byte after `self` if not found. + function findPtr( + uint256 selflen, + uint256 selfptr, + uint256 needlelen, + uint256 needleptr + ) + private + pure + returns (uint256) + { + uint256 ptr = selfptr; + uint256 idx; + + if (needlelen <= selflen) { + if (needlelen <= 32) { + bytes32 mask; + if (needlelen > 0) { + mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + } + + bytes32 needledata; + assembly ("memory-safe") { + needledata := and(mload(needleptr), mask) } - if (equal) { - self._len -= needle._len; + uint256 end = selfptr + selflen - needlelen; + bytes32 ptrdata; + assembly ("memory-safe") { + ptrdata := and(mload(ptr), mask) + } + + while (ptrdata != needledata) { + if (ptr >= end) { + return selfptr + selflen; + } + ptr++; + assembly ("memory-safe") { + ptrdata := and(mload(ptr), mask) + } + } + return ptr; + } else { + // For long needles, use hashing + bytes32 hash; + assembly ("memory-safe") { + hash := keccak256(needleptr, needlelen) } - return self; - } - - // Returns the memory address of the first byte of the first occurrence of - // `needle` in `self`, or the first byte after `self` if not found. - function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { - uint ptr = selfptr; - uint idx; - - if (needlelen <= selflen) { - if (needlelen <= 32) { - bytes32 mask; - if (needlelen > 0) { - mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); - } - - bytes32 needledata; - assembly ("memory-safe") { needledata := and(mload(needleptr), mask) } - - uint end = selfptr + selflen - needlelen; - bytes32 ptrdata; - assembly ("memory-safe") { ptrdata := and(mload(ptr), mask) } - - while (ptrdata != needledata) { - if (ptr >= end) - return selfptr + selflen; - ptr++; - assembly ("memory-safe") { ptrdata := and(mload(ptr), mask) } - } - return ptr; - } else { - // For long needles, use hashing - bytes32 hash; - assembly ("memory-safe") { hash := keccak256(needleptr, needlelen) } - - for (idx = 0; idx <= selflen - needlelen; idx++) { - bytes32 testHash; - assembly ("memory-safe") { testHash := keccak256(ptr, needlelen) } - if (hash == testHash) - return ptr; - ptr += 1; - } - } + for (idx = 0; idx <= selflen - needlelen; idx++) { + bytes32 testHash; + assembly ("memory-safe") { + testHash := keccak256(ptr, needlelen) + } + if (hash == testHash) { + return ptr; + } + ptr += 1; } - return selfptr + selflen; - } - - // Returns the memory address of the first byte after the last occurrence of - // `needle` in `self`, or the address of `self` if not found. - function rfindPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { - uint ptr; - - if (needlelen <= selflen) { - if (needlelen <= 32) { - bytes32 mask; - if (needlelen > 0) { - mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); - } - - bytes32 needledata; - assembly ("memory-safe") { needledata := and(mload(needleptr), mask) } - - ptr = selfptr + selflen - needlelen; - bytes32 ptrdata; - assembly ("memory-safe") { ptrdata := and(mload(ptr), mask) } - - while (ptrdata != needledata) { - if (ptr <= selfptr) - return selfptr; - ptr--; - assembly ("memory-safe") { ptrdata := and(mload(ptr), mask) } - } - return ptr + needlelen; - } else { - // For long needles, use hashing - bytes32 hash; - assembly ("memory-safe") { hash := keccak256(needleptr, needlelen) } - ptr = selfptr + (selflen - needlelen); - while (ptr >= selfptr) { - bytes32 testHash; - assembly ("memory-safe") { testHash := keccak256(ptr, needlelen) } - if (hash == testHash) - return ptr + needlelen; - ptr -= 1; - } - } + } + } + return selfptr + selflen; + } + + // Returns the memory address of the first byte after the last occurrence of + // `needle` in `self`, or the address of `self` if not found. + function rfindPtr( + uint256 selflen, + uint256 selfptr, + uint256 needlelen, + uint256 needleptr + ) + private + pure + returns (uint256) + { + uint256 ptr; + + if (needlelen <= selflen) { + if (needlelen <= 32) { + bytes32 mask; + if (needlelen > 0) { + mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + } + + bytes32 needledata; + assembly ("memory-safe") { + needledata := and(mload(needleptr), mask) } - return selfptr; + + ptr = selfptr + selflen - needlelen; + bytes32 ptrdata; + assembly ("memory-safe") { + ptrdata := and(mload(ptr), mask) + } + + while (ptrdata != needledata) { + if (ptr <= selfptr) { + return selfptr; + } + ptr--; + assembly ("memory-safe") { + ptrdata := and(mload(ptr), mask) + } + } + return ptr + needlelen; + } else { + // For long needles, use hashing + bytes32 hash; + assembly ("memory-safe") { + hash := keccak256(needleptr, needlelen) + } + ptr = selfptr + (selflen - needlelen); + while (ptr >= selfptr) { + bytes32 testHash; + assembly ("memory-safe") { + testHash := keccak256(ptr, needlelen) + } + if (hash == testHash) { + return ptr + needlelen; + } + ptr -= 1; + } + } } + return selfptr; + } - /* + /* * @dev Modifies `self` to contain everything from the first occurrence of * `needle` to the end of the slice. `self` is set to the empty slice * if `needle` is not found. @@ -560,14 +612,14 @@ library strings { * @param needle The text to search for. * @return `self`. */ - function find(slice memory self, slice memory needle) internal pure returns (slice memory) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); - self._len -= ptr - self._ptr; - self._ptr = ptr; - return self; - } - - /* + function find(slice memory self, slice memory needle) internal pure returns (slice memory) { + uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); + self._len -= ptr - self._ptr; + self._ptr = ptr; + return self; + } + + /* * @dev Modifies `self` to contain the part of the string from the start of * `self` to the end of the first occurrence of `needle`. If `needle` * is not found, `self` is set to the empty slice. @@ -575,13 +627,13 @@ library strings { * @param needle The text to search for. * @return `self`. */ - function rfind(slice memory self, slice memory needle) internal pure returns (slice memory) { - uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); - self._len = ptr - self._ptr; - return self; - } + function rfind(slice memory self, slice memory needle) internal pure returns (slice memory) { + uint256 ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); + self._len = ptr - self._ptr; + return self; + } - /* + /* * @dev Splits the slice, setting `self` to everything after the first * occurrence of `needle`, and `token` to everything before it. If * `needle` does not occur in `self`, `self` is set to the empty slice, @@ -591,21 +643,21 @@ library strings { * @param token An output parameter to which the first token is written. * @return `token`. */ - function split(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); - token._ptr = self._ptr; - token._len = ptr - self._ptr; - if (ptr == self._ptr + self._len) { - // Not found - self._len = 0; - } else { - self._len -= token._len + needle._len; - self._ptr = ptr + needle._len; - } - return token; + function split(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { + uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); + token._ptr = self._ptr; + token._len = ptr - self._ptr; + if (ptr == self._ptr + self._len) { + // Not found + self._len = 0; + } else { + self._len -= token._len + needle._len; + self._ptr = ptr + needle._len; } + return token; + } - /* + /* * @dev Splits the slice, setting `self` to everything after the first * occurrence of `needle`, and returning everything before it. If * `needle` does not occur in `self`, `self` is set to the empty slice, @@ -614,11 +666,11 @@ library strings { * @param needle The text to search for in `self`. * @return The part of `self` up to the first occurrence of `delim`. */ - function split(slice memory self, slice memory needle) internal pure returns (slice memory token) { - split(self, needle, token); - } + function split(slice memory self, slice memory needle) internal pure returns (slice memory token) { + split(self, needle, token); + } - /* + /* * @dev Splits the slice, setting `self` to everything before the last * occurrence of `needle`, and `token` to everything after it. If * `needle` does not occur in `self`, `self` is set to the empty slice, @@ -628,20 +680,20 @@ library strings { * @param token An output parameter to which the first token is written. * @return `token`. */ - function rsplit(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { - uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); - token._ptr = ptr; - token._len = self._len - (ptr - self._ptr); - if (ptr == self._ptr) { - // Not found - self._len = 0; - } else { - self._len -= token._len + needle._len; - } - return token; + function rsplit(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { + uint256 ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); + token._ptr = ptr; + token._len = self._len - (ptr - self._ptr); + if (ptr == self._ptr) { + // Not found + self._len = 0; + } else { + self._len -= token._len + needle._len; } + return token; + } - /* + /* * @dev Splits the slice, setting `self` to everything before the last * occurrence of `needle`, and returning everything after it. If * `needle` does not occur in `self`, `self` is set to the empty slice, @@ -650,51 +702,53 @@ library strings { * @param needle The text to search for in `self`. * @return The part of `self` after the last occurrence of `delim`. */ - function rsplit(slice memory self, slice memory needle) internal pure returns (slice memory token) { - rsplit(self, needle, token); - } + function rsplit(slice memory self, slice memory needle) internal pure returns (slice memory token) { + rsplit(self, needle, token); + } - /* + /* * @dev Counts the number of nonoverlapping occurrences of `needle` in `self`. * @param self The slice to search. * @param needle The text to search for in `self`. * @return The number of occurrences of `needle` found in `self`. */ - function count(slice memory self, slice memory needle) internal pure returns (uint cnt) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + needle._len; - while (ptr <= self._ptr + self._len) { - cnt++; - ptr = findPtr(self._len - (ptr - self._ptr), ptr, needle._len, needle._ptr) + needle._len; - } + function count(slice memory self, slice memory needle) internal pure returns (uint256 cnt) { + uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + needle._len; + while (ptr <= self._ptr + self._len) { + cnt++; + ptr = findPtr(self._len - (ptr - self._ptr), ptr, needle._len, needle._ptr) + needle._len; } + } - /* + /* * @dev Returns True if `self` contains `needle`. * @param self The slice to search. * @param needle The text to search for in `self`. * @return True if `needle` is found in `self`, false otherwise. */ - function contains(slice memory self, slice memory needle) internal pure returns (bool) { - return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr; - } + function contains(slice memory self, slice memory needle) internal pure returns (bool) { + return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr; + } - /* + /* * @dev Returns a newly allocated string containing the concatenation of * `self` and `other`. * @param self The first slice to concatenate. * @param other The second slice to concatenate. * @return The concatenation of the two strings. */ - function concat(slice memory self, slice memory other) internal pure returns (string memory) { - string memory ret = new string(self._len + other._len); - uint retptr; - assembly ("memory-safe") { retptr := add(ret, 32) } - memcpy(retptr, self._ptr, self._len); - memcpy(retptr + self._len, other._ptr, other._len); - return ret; + function concat(slice memory self, slice memory other) internal pure returns (string memory) { + string memory ret = new string(self._len + other._len); + uint256 retptr; + assembly ("memory-safe") { + retptr := add(ret, 32) } + memcpy(retptr, self._ptr, self._len); + memcpy(retptr + self._len, other._ptr, other._len); + return ret; + } - /* + /* * @dev Joins an array of slices, using `self` as a delimiter, returning a * newly allocated string. * @param self The delimiter to use. @@ -702,27 +756,31 @@ library strings { * @return A newly allocated string containing all the slices in `parts`, * joined with `self`. */ - function join(slice memory self, slice[] memory parts) internal pure returns (string memory) { - if (parts.length == 0) - return ""; - - uint length = self._len * (parts.length - 1); - for(uint i = 0; i < parts.length; i++) - length += parts[i]._len; - - string memory ret = new string(length); - uint retptr; - assembly ("memory-safe") { retptr := add(ret, 32) } - - for(uint i = 0; i < parts.length; i++) { - memcpy(retptr, parts[i]._ptr, parts[i]._len); - retptr += parts[i]._len; - if (i < parts.length - 1) { - memcpy(retptr, self._ptr, self._len); - retptr += self._len; - } - } + function join(slice memory self, slice[] memory parts) internal pure returns (string memory) { + if (parts.length == 0) { + return ""; + } - return ret; + uint256 length = self._len * (parts.length - 1); + for (uint256 i = 0; i < parts.length; i++) { + length += parts[i]._len; } + + string memory ret = new string(length); + uint256 retptr; + assembly ("memory-safe") { + retptr := add(ret, 32) + } + + for (uint256 i = 0; i < parts.length; i++) { + memcpy(retptr, parts[i]._ptr, parts[i]._len); + retptr += parts[i]._len; + if (i < parts.length - 1) { + memcpy(retptr, self._ptr, self._len); + retptr += self._len; + } + } + + return ret; + } } diff --git a/logo.svg b/logo.svg deleted file mode 100644 index ccd539a..0000000 --- a/logo.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/package.json b/package.json index ce1ce9b..94c84d1 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "angle-transmuter", + "name": "parallel-parallelizer", "version": "1.0.0", "description": "", "scripts": { @@ -23,10 +23,10 @@ "prettier:write": "prettier --write \"**/*.{json,md,yml}\" --ignore-path \".prettierignore\"" }, "keywords": [], - "author": "Angle Labs, Inc.", + "author": "Parallel Labs, Inc.", "license": "BUSL-1.1", "bugs": { - "url": "https://github.com/AngleProtocol/angle-transmuter/issues" + "url": "https://github.com/ParallelProtocol/parallel-parallelizer/issues" }, "devDependencies": { "forge-std": "github:foundry-rs/forge-std#v1.9.5", diff --git a/scripts/generated/DummyDiamondImplementation.sol b/scripts/generated/DummyDiamondImplementation.sol index 18310ec..fc16e95 100644 --- a/scripts/generated/DummyDiamondImplementation.sol +++ b/scripts/generated/DummyDiamondImplementation.sol @@ -55,7 +55,7 @@ contract DummyDiamondImplementation { function accessControlManager() external view returns (address) { } - function agToken() external view returns (address) { } + function tokenP() external view returns (address) { } function getCollateralBurnFees(address collateral) external diff --git a/scripts/generated/DummyDiamondImplementationSidechain.sol b/scripts/generated/DummyDiamondImplementationSidechain.sol index 62d2e31..ebc4645 100644 --- a/scripts/generated/DummyDiamondImplementationSidechain.sol +++ b/scripts/generated/DummyDiamondImplementationSidechain.sol @@ -56,7 +56,7 @@ contract DummyDiamondImplementation { function accessControlManager() external view returns (address) { } - function agToken() external view returns (address) { } + function tokenP() external view returns (address) { } function getCollateralBurnFees(address collateral) external diff --git a/tests/Fixture.sol b/tests/Fixture.sol index 65c6821..90beee4 100644 --- a/tests/Fixture.sol +++ b/tests/Fixture.sol @@ -8,8 +8,7 @@ import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; import { Constants, ContractType } from "@helpers/Constants.sol"; -import { IAccessControlManager } from "interfaces/IAccessControlManager.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; import { IManager } from "interfaces/IManager.sol"; import { AggregatorV3Interface } from "interfaces/external/chainlink/AggregatorV3Interface.sol"; @@ -19,14 +18,14 @@ import { MockAccessControlManager } from "./mock/MockAccessControlManager.sol"; import { MockChainlinkOracle } from "./mock/MockChainlinkOracle.sol"; import { MockTokenPermit } from "./mock/MockTokenPermit.sol"; -import { CollateralSetup, Test } from "contracts/transmuter/configs/Test.sol"; +import { CollateralSetup, Test } from "contracts/parallelizer/configs/Test.sol"; import "contracts/utils/Constants.sol"; import "contracts/utils/Errors.sol"; -import { ITransmuter, Transmuter } from "./utils/Transmuter.sol"; +import { IParallelizer, Parallelizer } from "./utils/Parallelizer.sol"; import { ConfigAccessManager } from "./utils/ConfigAccessManager.sol"; -contract Fixture is Transmuter, ConfigAccessManager { - IAgToken public agToken; +contract Fixture is Parallelizer, ConfigAccessManager { + ITokenP public tokenP; IERC20 public eurA; AggregatorV3Interface public oracleA; @@ -72,8 +71,8 @@ contract Fixture is Transmuter, ConfigAccessManager { deployAccessManager(governor, governor, guardian, governorAndGuardian); - // agToken - agToken = IAgToken(address(new MockTokenPermit("agEUR", "agEUR", 18))); + // tokenP + tokenP = ITokenP(address(new MockTokenPermit("agEUR", "agEUR", 18))); // Collaterals eurA = IERC20(address(new MockTokenPermit("EUR_A", "EUR_A", 6))); @@ -98,27 +97,27 @@ contract Fixture is Transmuter, ConfigAccessManager { config = address(new Test()); - deployTransmuter( + deployParallelizer( config, abi.encodeWithSelector( Test.initialize.selector, address(accessManager), - agToken, + tokenP, CollateralSetup(address(eurA), address(oracleA)), CollateralSetup(address(eurB), address(oracleB)), CollateralSetup(address(eurY), address(oracleY)) ) ); - vm.label(address(agToken), "AgToken"); - vm.label(address(transmuter), "Transmuter"); + vm.label(address(tokenP), "tokenP"); + vm.label(address(parallelizer), "Parallelizer"); vm.label(address(eurA), "eurA"); vm.label(address(eurB), "eurB"); vm.label(address(eurY), "eurY"); vm.startPrank(governor); - accessManager.setTargetFunctionRole(address(transmuter), getTransmuterGovernorSelectorAccess(), GOVERNOR_ROLE); - accessManager.setTargetFunctionRole(address(transmuter), getTransmuterGuardianSelectorAccess(), GUARDIAN_ROLE); + accessManager.setTargetFunctionRole(address(parallelizer), getParallelizerGovernorSelectorAccess(), GOVERNOR_ROLE); + accessManager.setTargetFunctionRole(address(parallelizer), getParallelizerGuardianSelectorAccess(), GUARDIAN_ROLE); vm.stopPrank(); } @@ -152,16 +151,16 @@ contract Fixture is Transmuter, ConfigAccessManager { function _mintExactOutput(address owner, address tokenIn, uint256 amountStable, uint256 estimatedAmountIn) internal { vm.startPrank(owner); deal(tokenIn, owner, estimatedAmountIn); - IERC20(tokenIn).approve(address(transmuter), type(uint256).max); - transmuter.swapExactOutput(amountStable, estimatedAmountIn, tokenIn, address(agToken), owner, block.timestamp * 2); + IERC20(tokenIn).approve(address(parallelizer), type(uint256).max); + parallelizer.swapExactOutput(amountStable, estimatedAmountIn, tokenIn, address(tokenP), owner, block.timestamp * 2); vm.stopPrank(); } function _mintExactInput(address owner, address tokenIn, uint256 amountIn, uint256 estimatedStable) internal { vm.startPrank(owner); deal(tokenIn, owner, amountIn); - IERC20(tokenIn).approve(address(transmuter), type(uint256).max); - transmuter.swapExactInput(amountIn, estimatedStable, tokenIn, address(agToken), owner, block.timestamp * 2); + IERC20(tokenIn).approve(address(parallelizer), type(uint256).max); + parallelizer.swapExactInput(amountIn, estimatedStable, tokenIn, address(tokenP), owner, block.timestamp * 2); vm.stopPrank(); } } diff --git a/tests/invariants/BasicInvariants.sol b/tests/invariants/BasicInvariants.sol index 212d293..409b5ca 100644 --- a/tests/invariants/BasicInvariants.sol +++ b/tests/invariants/BasicInvariants.sol @@ -9,7 +9,7 @@ import { AggregatorV3Interface } from "interfaces/external/chainlink/AggregatorV import { MockAccessControlManager } from "tests/mock/MockAccessControlManager.sol"; import "contracts/utils/Constants.sol"; -import { CollateralSetup, Fixture, ITransmuter, Test } from "../Fixture.sol"; +import { CollateralSetup, Fixture, IParallelizer, Test } from "../Fixture.sol"; import { Trader } from "./actors/Trader.t.sol"; import { Arbitrager } from "./actors/Arbitrager.t.sol"; import { Governance } from "./actors/Governance.t.sol"; @@ -21,7 +21,7 @@ contract BasicInvariants is Fixture { uint256 internal constant _NUM_TRADER = 2; uint256 internal constant _NUM_ARB = 2; - ITransmuter transmuterSplit; + IParallelizer transmuterSplit; Trader internal _traderHandler; Arbitrager internal _arbitragerHandler; @@ -34,14 +34,14 @@ contract BasicInvariants is Fixture { function setUp() public virtual override { super.setUp(); - // Deploy another transmuter to check the independant path property + // Deploy another parallelizer to check the independant path property config = address(new Test()); - transmuterSplit = deployReplicaTransmuter( + transmuterSplit = deployReplicaParallelizer( config, abi.encodeWithSelector( Test.initialize.selector, accessManager, - agToken, + tokenP, CollateralSetup(address(eurA), address(oracleA)), CollateralSetup(address(eurB), address(oracleB)), CollateralSetup(address(eurY), address(oracleY)) @@ -49,8 +49,12 @@ contract BasicInvariants is Fixture { ); vm.startPrank(governor); - accessManager.setTargetFunctionRole(address(transmuterSplit), getTransmuterGovernorSelectorAccess(), GOVERNOR_ROLE); - accessManager.setTargetFunctionRole(address(transmuterSplit), getTransmuterGuardianSelectorAccess(), GUARDIAN_ROLE); + accessManager.setTargetFunctionRole( + address(transmuterSplit), getParallelizerGovernorSelectorAccess(), GOVERNOR_ROLE + ); + accessManager.setTargetFunctionRole( + address(transmuterSplit), getParallelizerGuardianSelectorAccess(), GUARDIAN_ROLE + ); vm.stopPrank(); { @@ -66,7 +70,7 @@ contract BasicInvariants is Fixture { yFeeRedemption[2] = int64(int256((1e9 * 9) / 10)); yFeeRedemption[3] = int64(int256(1e9)); vm.startPrank(guardian); - transmuter.setRedemptionCurveParams(xFeeRedemption, yFeeRedemption); + parallelizer.setRedemptionCurveParams(xFeeRedemption, yFeeRedemption); transmuterSplit.setRedemptionCurveParams(xFeeRedemption, yFeeRedemption); vm.stopPrank(); } @@ -81,9 +85,9 @@ contract BasicInvariants is Fixture { _oracles.push(oracleB); _oracles.push(oracleY); - _traderHandler = new Trader(transmuter, transmuterSplit, _collaterals, _oracles, _NUM_TRADER); - _arbitragerHandler = new Arbitrager(transmuter, transmuterSplit, _collaterals, _oracles, _NUM_ARB); - _governanceHandler = new Governance(transmuter, transmuterSplit, _collaterals, _oracles); + _traderHandler = new Trader(parallelizer, transmuterSplit, _collaterals, _oracles, _NUM_TRADER); + _arbitragerHandler = new Arbitrager(parallelizer, transmuterSplit, _collaterals, _oracles, _NUM_ARB); + _governanceHandler = new Governance(parallelizer, transmuterSplit, _collaterals, _oracles); vm.startPrank(governor); accessManager.grantRole(GOVERNOR_ROLE, _governanceHandler.actors(0), 0); @@ -92,7 +96,7 @@ contract BasicInvariants is Fixture { vm.startPrank(guardian); // Label newly created addresses - vm.label(address(transmuterSplit), "TransmuterSplit"); + vm.label(address(transmuterSplit), "ParallelizerSplit"); for (uint256 i; i < _NUM_ARB; i++) { vm.label(_arbitragerHandler.actors(i), string.concat("Arbi ", Strings.toString(i))); } @@ -144,9 +148,9 @@ contract BasicInvariants is Fixture { console.log("-------------------"); console.log(""); - (uint256 issuedA, uint256 issued) = transmuter.getIssuedByCollateral(address(eurA)); - (uint256 issuedB,) = transmuter.getIssuedByCollateral(address(eurB)); - (uint256 issuedY,) = transmuter.getIssuedByCollateral(address(eurY)); + (uint256 issuedA, uint256 issued) = parallelizer.getIssuedByCollateral(address(eurA)); + (uint256 issuedB,) = parallelizer.getIssuedByCollateral(address(eurB)); + (uint256 issuedY,) = parallelizer.getIssuedByCollateral(address(eurY)); console.log("Issued A: ", issuedA); console.log("Issued B: ", issuedB); console.log("Issued Y: ", issuedY); @@ -154,22 +158,22 @@ contract BasicInvariants is Fixture { } function invariant_IssuedCoherent() public { - (uint256 issuedA, uint256 issued) = transmuter.getIssuedByCollateral(address(eurA)); - (uint256 issuedB,) = transmuter.getIssuedByCollateral(address(eurB)); - (uint256 issuedY,) = transmuter.getIssuedByCollateral(address(eurY)); + (uint256 issuedA, uint256 issued) = parallelizer.getIssuedByCollateral(address(eurA)); + (uint256 issuedB,) = parallelizer.getIssuedByCollateral(address(eurB)); + (uint256 issuedY,) = parallelizer.getIssuedByCollateral(address(eurY)); assertApproxEqAbs(issued, issuedA + issuedB + issuedY, 3 wei); } function invariant_Supply() public { - uint256 stablecoinIssued = transmuter.getTotalIssued(); + uint256 stablecoinIssued = parallelizer.getTotalIssued(); uint256 stablecoinIssuedSplit = transmuterSplit.getTotalIssued(); uint256 balance; for (uint256 i = 0; i < _traderHandler.nbrActor(); i++) { - balance += agToken.balanceOf(_traderHandler.actors(i)); + balance += tokenP.balanceOf(_traderHandler.actors(i)); } for (uint256 i = 0; i < _arbitragerHandler.nbrActor(); i++) { - balance += agToken.balanceOf(_arbitragerHandler.actors(i)); + balance += tokenP.balanceOf(_arbitragerHandler.actors(i)); } assertApproxEqAbs(stablecoinIssued + stablecoinIssuedSplit, balance, BASE_12); @@ -177,7 +181,7 @@ contract BasicInvariants is Fixture { function invariant_CollateralRatio() public { uint256 storedCollatRatio = _governanceHandler.collateralRatio(); - (uint64 collateralRatio,) = transmuter.getCollateralRatio(); + (uint64 collateralRatio,) = parallelizer.getCollateralRatio(); if (storedCollatRatio <= BASE_9) { assertGe(uint256(collateralRatio), storedCollatRatio); } @@ -194,7 +198,7 @@ contract BasicInvariants is Fixture { function invariant_RedeemCollateralRatio() public { uint256 storedCollatRatio = _governanceHandler.collateralRatio(); - (uint64 collateralRatio,) = transmuter.getCollateralRatio(); + (uint64 collateralRatio,) = parallelizer.getCollateralRatio(); if (storedCollatRatio <= BASE_9) assertGe(collateralRatio, storedCollatRatio); else assertGe(collateralRatio, BASE_9); @@ -202,17 +206,17 @@ contract BasicInvariants is Fixture { } function invariant_MintReflexivity() public { - uint256 stablecoinIssued = transmuter.getTotalIssued(); + uint256 stablecoinIssued = parallelizer.getTotalIssued(); uint256 stableAmount; { // source of randomness - (uint64 collateralRatio,) = transmuter.getCollateralRatio(); + (uint64 collateralRatio,) = parallelizer.getCollateralRatio(); uint256 multiplier = bound(collateralRatio, 1, 1e4); stableAmount = stablecoinIssued > BASE_18 ? (stablecoinIssued * multiplier) / 1e2 : BASE_18; } for (uint256 i; i < _collaterals.length; i++) { - uint256 amountIn = transmuter.quoteOut(stableAmount, _collaterals[i], address(agToken)); - uint256 reflexiveStableAmount = transmuter.quoteIn(amountIn, _collaterals[i], address(agToken)); + uint256 amountIn = parallelizer.quoteOut(stableAmount, _collaterals[i], address(tokenP)); + uint256 reflexiveStableAmount = parallelizer.quoteIn(amountIn, _collaterals[i], address(tokenP)); // If amountIn is small then do not check, as in the extreme case amountIn is null and // then reflexiveStableAmount is too if (amountIn < 10 ** (_decimals[i] - 2) || reflexiveStableAmount == 0) continue; @@ -221,18 +225,18 @@ contract BasicInvariants is Fixture { } function invariant_BurnReflexivity() public { - uint256 stablecoinIssued = transmuter.getTotalIssued(); + uint256 stablecoinIssued = parallelizer.getTotalIssued(); uint256 stableAmount; { // source of randomness - (uint64 collateralRatio,) = transmuter.getCollateralRatio(); + (uint64 collateralRatio,) = parallelizer.getCollateralRatio(); uint256 multiplier = bound(collateralRatio, 1, 1e2); stableAmount = (stablecoinIssued * multiplier) / 1e2; } if (stableAmount < 10 * BASE_18) return; for (uint256 i; i < _collaterals.length; i++) { - try transmuter.quoteIn(stableAmount, address(agToken), _collaterals[i]) returns (uint256 amountOut) { - uint256 reflexiveStableAmount = transmuter.quoteOut(amountOut, address(agToken), _collaterals[i]); + try parallelizer.quoteIn(stableAmount, address(tokenP), _collaterals[i]) returns (uint256 amountOut) { + uint256 reflexiveStableAmount = parallelizer.quoteOut(amountOut, address(tokenP), _collaterals[i]); // If amountOut is small then do not check, as in the extreme case amountIn is null and // then reflexiveStableAmount is too if (amountOut < 10 ** (_decimals[i] - 2) || reflexiveStableAmount == 0) continue; diff --git a/tests/invariants/PathIndeInvariants.t.sol b/tests/invariants/PathIndeInvariants.t.sol index cb42c76..1659e6d 100644 --- a/tests/invariants/PathIndeInvariants.t.sol +++ b/tests/invariants/PathIndeInvariants.t.sol @@ -9,7 +9,7 @@ import { AggregatorV3Interface } from "interfaces/external/chainlink/AggregatorV import { MockAccessControlManager } from "tests/mock/MockAccessControlManager.sol"; import "contracts/utils/Constants.sol"; -import { CollateralSetup, Fixture, ITransmuter, Test } from "../Fixture.sol"; +import { CollateralSetup, Fixture, IParallelizer, Test } from "../Fixture.sol"; import { TraderWithSplit } from "./actors/TraderWithSplit.t.sol"; import { ArbitragerWithSplit } from "./actors/ArbitragerWithSplit.t.sol"; import { Governance } from "./actors/Governance.t.sol"; @@ -21,7 +21,7 @@ contract PathIndeInvariants is Fixture { uint256 internal constant _NUM_TRADER = 2; uint256 internal constant _NUM_ARB = 2; - ITransmuter transmuterSplit; + IParallelizer transmuterSplit; TraderWithSplit internal _traderHandler; ArbitragerWithSplit internal _arbitragerHandler; @@ -34,14 +34,14 @@ contract PathIndeInvariants is Fixture { function setUp() public virtual override { super.setUp(); - // Deploy another transmuter to check the independant path property + // Deploy another parallelizer to check the independant path property config = address(new Test()); - transmuterSplit = deployReplicaTransmuter( + transmuterSplit = deployReplicaParallelizer( config, abi.encodeWithSelector( Test.initialize.selector, accessManager, - agToken, + tokenP, CollateralSetup(address(eurA), address(oracleA)), CollateralSetup(address(eurB), address(oracleB)), CollateralSetup(address(eurY), address(oracleY)) @@ -49,8 +49,12 @@ contract PathIndeInvariants is Fixture { ); vm.startPrank(governor); - accessManager.setTargetFunctionRole(address(transmuterSplit), getTransmuterGovernorSelectorAccess(), GOVERNOR_ROLE); - accessManager.setTargetFunctionRole(address(transmuterSplit), getTransmuterGuardianSelectorAccess(), GUARDIAN_ROLE); + accessManager.setTargetFunctionRole( + address(transmuterSplit), getParallelizerGovernorSelectorAccess(), GOVERNOR_ROLE + ); + accessManager.setTargetFunctionRole( + address(transmuterSplit), getParallelizerGuardianSelectorAccess(), GUARDIAN_ROLE + ); vm.stopPrank(); { @@ -66,7 +70,7 @@ contract PathIndeInvariants is Fixture { yFeeRedemption[2] = int64(int256((1e9 * 9) / 10)); yFeeRedemption[3] = int64(int256(1e9)); vm.startPrank(guardian); - transmuter.setRedemptionCurveParams(xFeeRedemption, yFeeRedemption); + parallelizer.setRedemptionCurveParams(xFeeRedemption, yFeeRedemption); transmuterSplit.setRedemptionCurveParams(xFeeRedemption, yFeeRedemption); vm.stopPrank(); } @@ -81,9 +85,9 @@ contract PathIndeInvariants is Fixture { _oracles.push(oracleB); _oracles.push(oracleY); - _traderHandler = new TraderWithSplit(transmuter, transmuterSplit, _collaterals, _oracles, _NUM_TRADER); - _arbitragerHandler = new ArbitragerWithSplit(transmuter, transmuterSplit, _collaterals, _oracles, _NUM_ARB); - _governanceHandler = new Governance(transmuter, transmuterSplit, _collaterals, _oracles); + _traderHandler = new TraderWithSplit(parallelizer, transmuterSplit, _collaterals, _oracles, _NUM_TRADER); + _arbitragerHandler = new ArbitragerWithSplit(parallelizer, transmuterSplit, _collaterals, _oracles, _NUM_ARB); + _governanceHandler = new Governance(parallelizer, transmuterSplit, _collaterals, _oracles); vm.startPrank(governor); accessManager.grantRole(GOVERNOR_ROLE, _governanceHandler.actors(0), 0); @@ -91,7 +95,7 @@ contract PathIndeInvariants is Fixture { vm.stopPrank(); // Label newly created addresses - vm.label(address(transmuterSplit), "TransmuterSplit"); + vm.label(address(transmuterSplit), "ParallelizerSplit"); for (uint256 i; i < _NUM_ARB; i++) { vm.label(_arbitragerHandler.actors(i), string.concat("Arbi ", Strings.toString(i))); } @@ -143,9 +147,9 @@ contract PathIndeInvariants is Fixture { console.log("-------------------"); console.log(""); - (uint256 issuedA, uint256 issued) = transmuter.getIssuedByCollateral(address(eurA)); - (uint256 issuedB,) = transmuter.getIssuedByCollateral(address(eurB)); - (uint256 issuedY,) = transmuter.getIssuedByCollateral(address(eurY)); + (uint256 issuedA, uint256 issued) = parallelizer.getIssuedByCollateral(address(eurA)); + (uint256 issuedB,) = parallelizer.getIssuedByCollateral(address(eurB)); + (uint256 issuedY,) = parallelizer.getIssuedByCollateral(address(eurY)); console.log("Issued A: ", issuedA); console.log("Issued B: ", issuedB); console.log("Issued Y: ", issuedY); @@ -153,17 +157,17 @@ contract PathIndeInvariants is Fixture { } function invariant_Supply() public { - uint256 stablecoinIssued = transmuter.getTotalIssued(); + uint256 stablecoinIssued = parallelizer.getTotalIssued(); uint256 stablecoinIssuedSplit = transmuterSplit.getTotalIssued(); - uint256 balance = agToken.balanceOf(sweeper); + uint256 balance = tokenP.balanceOf(sweeper); uint256 traderActors = _traderHandler.nbrActor(); uint256 arbitrageActors = _arbitragerHandler.nbrActor(); for (uint256 i = 0; i < traderActors; i++) { - balance += agToken.balanceOf(_traderHandler.actors(i)); + balance += tokenP.balanceOf(_traderHandler.actors(i)); } for (uint256 i = 0; i < arbitrageActors; i++) { - balance += agToken.balanceOf(_arbitragerHandler.actors(i)); + balance += tokenP.balanceOf(_arbitragerHandler.actors(i)); } assertApproxEqAbs(stablecoinIssued + stablecoinIssuedSplit, balance, BASE_12); @@ -171,7 +175,7 @@ contract PathIndeInvariants is Fixture { function invariant_CollateralRatio() public { uint256 storedCollatRatio = _governanceHandler.collateralRatio(); - (uint64 collateralRatio,) = transmuter.getCollateralRatio(); + (uint64 collateralRatio,) = parallelizer.getCollateralRatio(); if (storedCollatRatio <= BASE_9) { assertGe(uint256(collateralRatio), storedCollatRatio); } @@ -188,7 +192,7 @@ contract PathIndeInvariants is Fixture { function invariant_RedeemCollateralRatio() public { uint256 storedCollatRatio = _governanceHandler.collateralRatio(); - (uint64 collateralRatio,) = transmuter.getCollateralRatio(); + (uint64 collateralRatio,) = parallelizer.getCollateralRatio(); if (storedCollatRatio <= BASE_9) assertGe(collateralRatio, storedCollatRatio); else assertGe(collateralRatio, BASE_9); @@ -196,14 +200,14 @@ contract PathIndeInvariants is Fixture { } function invariant_PathIndependenceTotalSupply() public { - uint256 stablecoinIssued = transmuter.getTotalIssued(); + uint256 stablecoinIssued = parallelizer.getTotalIssued(); uint256 stablecoinIssuedSplit = transmuterSplit.getTotalIssued(); assertApproxEqRelDecimal(stablecoinIssued, stablecoinIssuedSplit, _MAX_PERCENTAGE_DEVIATION * 100, 18); } function invariant_PathIndependenceSubSupply() public { for (uint256 i; i < _collaterals.length; i++) { - (uint256 issuedPerCollat,) = transmuter.getIssuedByCollateral(_collaterals[i]); + (uint256 issuedPerCollat,) = parallelizer.getIssuedByCollateral(_collaterals[i]); (uint256 issuedPerCollatSplit,) = transmuterSplit.getIssuedByCollateral(_collaterals[i]); assertApproxEqRelDecimal(issuedPerCollat, issuedPerCollatSplit, _MAX_PERCENTAGE_DEVIATION * 500, 18); } @@ -211,14 +215,14 @@ contract PathIndeInvariants is Fixture { function invariant_PathIndependenceBalanceCollaterals() public { for (uint256 i; i < _collaterals.length; i++) { - uint256 balance = IERC20(_collaterals[i]).balanceOf(address(transmuter)); + uint256 balance = IERC20(_collaterals[i]).balanceOf(address(parallelizer)); uint256 balanceSplit = IERC20(_collaterals[i]).balanceOf(address(transmuterSplit)); assertApproxEqRelDecimal(balance, balanceSplit, _MAX_PERCENTAGE_DEVIATION * 500, 18); } } function invariant_PathIndependenceCollateralRatio() public { - (uint256 collateralRatio,) = transmuter.getCollateralRatio(); + (uint256 collateralRatio,) = parallelizer.getCollateralRatio(); (uint256 collateralRatioSplit,) = transmuterSplit.getCollateralRatio(); assertApproxEqRelDecimal(collateralRatio, collateralRatioSplit, _MAX_PERCENTAGE_DEVIATION * 100, 18); } diff --git a/tests/invariants/actors/Arbitrager.t.sol b/tests/invariants/actors/Arbitrager.t.sol index 9dff0d4..ccb75b9 100644 --- a/tests/invariants/actors/Arbitrager.t.sol +++ b/tests/invariants/actors/Arbitrager.t.sol @@ -2,19 +2,21 @@ pragma solidity 0.8.28; import "contracts/utils/Constants.sol"; -import { AggregatorV3Interface, BaseActor, IERC20, IERC20Metadata, ITransmuter, TestStorage } from "./BaseActor.t.sol"; -import { QuoteType } from "contracts/transmuter/Storage.sol"; +import { + AggregatorV3Interface, BaseActor, IERC20, IERC20Metadata, IParallelizer, TestStorage +} from "./BaseActor.t.sol"; +import { QuoteType } from "contracts/parallelizer/Storage.sol"; import { console } from "@forge-std/console.sol"; contract Arbitrager is BaseActor { constructor( - ITransmuter transmuter, - ITransmuter transmuterSplit, + IParallelizer parallelizer, + IParallelizer transmuterSplit, address[] memory collaterals, AggregatorV3Interface[] memory oracles, uint256 nbrTrader ) - BaseActor(nbrTrader, "Arb", transmuter, transmuterSplit, collaterals, oracles) + BaseActor(nbrTrader, "Arb", parallelizer, transmuterSplit, collaterals, oracles) { } function swap( @@ -35,7 +37,7 @@ contract Arbitrager is BaseActor { if ( (quoteType == QuoteType.BurnExactInput || quoteType == QuoteType.BurnExactOutput) - && agToken.balanceOf(_currentActor) == 0 + && tokenP.balanceOf(_currentActor) == 0 ) return (0, 0); TestStorage memory testS; @@ -46,28 +48,28 @@ contract Arbitrager is BaseActor { if (quoteType == QuoteType.MintExactInput) { console.log("Mint - Input"); testS.tokenIn = collateral; - testS.tokenOut = address(agToken); + testS.tokenOut = address(tokenP); testS.amountIn = amount * 10 ** IERC20Metadata(collateral).decimals(); testS.amountOut = _transmuter.quoteIn(testS.amountIn, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.BurnExactInput) { console.log("Burn - Input"); - testS.tokenIn = address(agToken); + testS.tokenIn = address(tokenP); testS.tokenOut = collateral; - testS.amountIn = bound(amount * BASE_18, 1, agToken.balanceOf(_currentActor)); + testS.amountIn = bound(amount * BASE_18, 1, tokenP.balanceOf(_currentActor)); testS.amountOut = _transmuter.quoteIn(testS.amountIn, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.MintExactOutput) { console.log("Mint - Output"); testS.tokenIn = collateral; - testS.tokenOut = address(agToken); + testS.tokenOut = address(tokenP); testS.amountOut = amount * BASE_18; testS.amountIn = _transmuter.quoteOut(testS.amountOut, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.BurnExactOutput) { console.log("Burn - Output"); - testS.tokenIn = address(agToken); + testS.tokenIn = address(tokenP); testS.tokenOut = collateral; testS.amountOut = amount * 10 ** IERC20Metadata(collateral).decimals(); testS.amountIn = _transmuter.quoteOut(testS.amountOut, testS.tokenIn, testS.tokenOut); - uint256 actorBalance = agToken.balanceOf(_currentActor); + uint256 actorBalance = tokenP.balanceOf(_currentActor); // we need to decrease the amountOut wanted if (actorBalance < testS.amountIn) { testS.amountIn = actorBalance; @@ -103,7 +105,7 @@ contract Arbitrager is BaseActor { IERC20(testS.tokenIn).approve(address(_transmuterSplit), testS.amountIn); // Memory previous balances - uint256 balanceAgToken = agToken.balanceOf(_currentActor); + uint256 balancetokenP = tokenP.balanceOf(_currentActor); uint256 balanceCollateral = IERC20(collateral).balanceOf(_currentActor); (uint64 prevCollateralRatio,) = _transmuter.getCollateralRatio(); @@ -120,7 +122,7 @@ contract Arbitrager is BaseActor { if (quoteType == QuoteType.MintExactInput || quoteType == QuoteType.MintExactOutput) { assertEq(IERC20(collateral).balanceOf(_currentActor), balanceCollateral - testS.amountIn); - assertEq(agToken.balanceOf(_currentActor), balanceAgToken + testS.amountOut); + assertEq(tokenP.balanceOf(_currentActor), balancetokenP + testS.amountOut); // if it is a mint and the previous collateral ratio was lower than it should always increase the // collateral ratio (uint64 collateralRatio,) = _transmuter.getCollateralRatio(); @@ -128,7 +130,7 @@ contract Arbitrager is BaseActor { else assertGe(collateralRatio, BASE_9); } else { assertEq(IERC20(collateral).balanceOf(_currentActor), balanceCollateral + testS.amountOut); - assertEq(agToken.balanceOf(_currentActor), balanceAgToken - testS.amountIn); + assertEq(tokenP.balanceOf(_currentActor), balancetokenP - testS.amountIn); // if it is a burn it should always increase the collateral ratio (uint64 collateralRatio,) = _transmuter.getCollateralRatio(); assertGe(collateralRatio, prevCollateralRatio); @@ -146,8 +148,8 @@ contract Arbitrager is BaseActor { useActor(actorIndex) countCall("redeem") { - uint256 balanceAgToken = agToken.balanceOf(_currentActor); - amount = bound(amount, 0, balanceAgToken); + uint256 balancetokenP = tokenP.balanceOf(_currentActor); + amount = bound(amount, 0, balancetokenP); if (amount == 0) return; address[] memory forfeitTokens; @@ -164,7 +166,7 @@ contract Arbitrager is BaseActor { } } - // Redeem on the true transmuter + // Redeem on the true parallelizer { uint256[] memory balanceTokens = new uint256[](_collaterals.length); for (uint256 i; i < balanceTokens.length; ++i) { @@ -187,8 +189,8 @@ contract Arbitrager is BaseActor { // if it is a burn it should always increase the collateral ratio (uint64 collateralRatio,) = _transmuter.getCollateralRatio(); assertGe(collateralRatio, prevCollateralRatio); - assertEq(agToken.balanceOf(_currentActor), balanceAgToken - amount); - balanceAgToken -= amount; + assertEq(tokenP.balanceOf(_currentActor), balancetokenP - amount); + balancetokenP -= amount; for (uint256 i; i < balanceTokens.length; ++i) { if (!isForfeitTokens[i]) { assertEq(IERC20(_collaterals[i]).balanceOf(_currentActor), balanceTokens[i] + redeemAmounts[i]); diff --git a/tests/invariants/actors/ArbitragerWithSplit.t.sol b/tests/invariants/actors/ArbitragerWithSplit.t.sol index db5f948..8e738f6 100644 --- a/tests/invariants/actors/ArbitragerWithSplit.t.sol +++ b/tests/invariants/actors/ArbitragerWithSplit.t.sol @@ -2,21 +2,23 @@ pragma solidity 0.8.28; import "contracts/utils/Constants.sol"; -import { AggregatorV3Interface, BaseActor, IERC20, IERC20Metadata, ITransmuter, TestStorage } from "./BaseActor.t.sol"; -import { QuoteType } from "contracts/transmuter/Storage.sol"; +import { + AggregatorV3Interface, BaseActor, IERC20, IERC20Metadata, IParallelizer, TestStorage +} from "./BaseActor.t.sol"; +import { QuoteType } from "contracts/parallelizer/Storage.sol"; import { console } from "@forge-std/console.sol"; contract ArbitragerWithSplit is BaseActor { bool public withForfeit; constructor( - ITransmuter transmuter, - ITransmuter transmuterSplit, + IParallelizer parallelizer, + IParallelizer transmuterSplit, address[] memory collaterals, AggregatorV3Interface[] memory oracles, uint256 nbrTrader ) - BaseActor(nbrTrader, "Arb", transmuter, transmuterSplit, collaterals, oracles) + BaseActor(nbrTrader, "Arb", parallelizer, transmuterSplit, collaterals, oracles) { } function swap( @@ -46,7 +48,7 @@ contract ArbitragerWithSplit is BaseActor { if ( (quoteType == QuoteType.BurnExactInput || quoteType == QuoteType.BurnExactOutput) - && agToken.balanceOf(_currentActor) == 0 + && tokenP.balanceOf(_currentActor) == 0 ) return (0, 0); TestStorage memory testS; @@ -57,30 +59,30 @@ contract ArbitragerWithSplit is BaseActor { if (quoteType == QuoteType.MintExactInput) { console.log("Mint - Input"); testS.tokenIn = collateral; - testS.tokenOut = address(agToken); + testS.tokenOut = address(tokenP); testS.amountIn = amount * 10 ** IERC20Metadata(collateral).decimals(); testS.amountOut = _transmuter.quoteIn(testS.amountIn, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.BurnExactInput) { console.log("Burn - Input"); - testS.tokenIn = address(agToken); + testS.tokenIn = address(tokenP); testS.tokenOut = collateral; - // divided by 2 because we need to do for both the transmuter and the replica - testS.amountIn = bound(amount * BASE_18, 1, agToken.balanceOf(_currentActor) / 2); + // divided by 2 because we need to do for both the parallelizer and the replica + testS.amountIn = bound(amount * BASE_18, 1, tokenP.balanceOf(_currentActor) / 2); testS.amountOut = _transmuter.quoteIn(testS.amountIn, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.MintExactOutput) { console.log("Mint - Output"); testS.tokenIn = collateral; - testS.tokenOut = address(agToken); + testS.tokenOut = address(tokenP); testS.amountOut = amount * BASE_18; testS.amountIn = _transmuter.quoteOut(testS.amountOut, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.BurnExactOutput) { console.log("Burn - Output"); - testS.tokenIn = address(agToken); + testS.tokenIn = address(tokenP); testS.tokenOut = collateral; testS.amountOut = amount * 10 ** IERC20Metadata(collateral).decimals(); testS.amountIn = _transmuter.quoteOut(testS.amountOut, testS.tokenIn, testS.tokenOut); - // divided by 2 because we need to do for both the transmuter and the replica - uint256 actorBalance = agToken.balanceOf(_currentActor) / 2; + // divided by 2 because we need to do for both the parallelizer and the replica + uint256 actorBalance = tokenP.balanceOf(_currentActor) / 2; // we need to decrease the amountOut wanted if (actorBalance < testS.amountIn) { testS.amountIn = actorBalance; @@ -121,7 +123,7 @@ contract ArbitragerWithSplit is BaseActor { testS.amountIn, testS.amountOut, testS.tokenIn, testS.tokenOut, _currentActor, block.timestamp + 1 hours ); // send the received tokens to the sweeper - // replicate on the other transmuter but split the orders + // replicate on the other parallelizer but split the orders { testS.amountInSplit1 = (testS.amountIn * splitProportion) / BASE_9; testS.amountOutSplit1 = _transmuterSplit.quoteIn(testS.amountInSplit1, testS.tokenIn, testS.tokenOut); @@ -149,7 +151,7 @@ contract ArbitragerWithSplit is BaseActor { _transmuter.swapExactOutput( testS.amountOut, testS.amountIn, testS.tokenIn, testS.tokenOut, _currentActor, block.timestamp + 1 hours ); - // replicate on the other transmuter but wplit the orders + // replicate on the other parallelizer but wplit the orders { testS.amountOutSplit1 = (testS.amountOut * splitProportion) / BASE_9; testS.amountInSplit1 = _transmuterSplit.quoteOut(testS.amountOutSplit1, testS.tokenIn, testS.tokenOut); @@ -157,7 +159,7 @@ contract ArbitragerWithSplit is BaseActor { // We can be missing either stablecoins or amountIn in the case of BurnExactOutput // and MintExactOutput respectively // Making revert the tx due to rounding errors. We increase balances have non reverting txs - uint256 actorBalance = agToken.balanceOf(_currentActor); + uint256 actorBalance = tokenP.balanceOf(_currentActor); if (quoteType == QuoteType.BurnExactOutput && actorBalance < testS.amountInSplit1) { testS.amountInSplit1 = actorBalance; testS.amountOutSplit1 = _transmuterSplit.quoteIn(testS.amountInSplit1, testS.tokenIn, testS.tokenOut); @@ -181,7 +183,7 @@ contract ArbitragerWithSplit is BaseActor { testS.amountOutSplit2 = testS.amountOut - testS.amountOutSplit1; testS.amountInSplit2 = _transmuterSplit.quoteOut(testS.amountOutSplit2, testS.tokenIn, testS.tokenOut); { - uint256 actorBalance = agToken.balanceOf(_currentActor); + uint256 actorBalance = tokenP.balanceOf(_currentActor); if (quoteType == QuoteType.BurnExactOutput && actorBalance < testS.amountInSplit2) { testS.amountInSplit2 = actorBalance; testS.amountOutSplit2 = _transmuterSplit.quoteIn(testS.amountInSplit2, testS.tokenIn, testS.tokenOut); @@ -217,13 +219,13 @@ contract ArbitragerWithSplit is BaseActor { useActor(actorIndex) countCall("redeem") { - uint256 balanceAgToken = agToken.balanceOf(_currentActor); - amount = bound(amount, 0, balanceAgToken / 2); + uint256 balancetokenP = tokenP.balanceOf(_currentActor); + amount = bound(amount, 0, balancetokenP / 2); splitProportion = bound(splitProportion, 1, BASE_9); if (amount == 0) return; address[] memory forfeitTokens; - // Redeem on the true transmuter + // Redeem on the true parallelizer { uint256[] memory balanceTokens = new uint256[](_collaterals.length); for (uint256 i; i < balanceTokens.length; ++i) { @@ -246,8 +248,8 @@ contract ArbitragerWithSplit is BaseActor { // if it is a burn it should always increase the collateral ratio (uint64 collateralRatio,) = _transmuter.getCollateralRatio(); assertGe(collateralRatio, prevCollateralRatio); - assertEq(agToken.balanceOf(_currentActor), balanceAgToken - amount); - balanceAgToken -= amount; + assertEq(tokenP.balanceOf(_currentActor), balancetokenP - amount); + balancetokenP -= amount; for (uint256 i; i < balanceTokens.length; ++i) { if (!isForfeitTokens[i]) { assertEq(IERC20(_collaterals[i]).balanceOf(_currentActor), balanceTokens[i] + redeemAmounts[i]); @@ -257,7 +259,7 @@ contract ArbitragerWithSplit is BaseActor { } } - // Redeem on the replica transmuter + // Redeem on the replica parallelizer { uint256[] memory balanceTokens = new uint256[](_collaterals.length); for (uint256 i; i < balanceTokens.length; ++i) { @@ -288,7 +290,7 @@ contract ArbitragerWithSplit is BaseActor { // if it is a burn it should always increase the collateral ratio (uint64 collateralRatio,) = _transmuterSplit.getCollateralRatio(); assertGe(collateralRatio, prevCollateralRatio); - assertEq(agToken.balanceOf(_currentActor), balanceAgToken - amount); + assertEq(tokenP.balanceOf(_currentActor), balancetokenP - amount); for (uint256 i; i < balanceTokens.length; ++i) { if (!isForfeitTokens[i]) { assertEq( diff --git a/tests/invariants/actors/BaseActor.t.sol b/tests/invariants/actors/BaseActor.t.sol index 4432afb..cbe4e78 100644 --- a/tests/invariants/actors/BaseActor.t.sol +++ b/tests/invariants/actors/BaseActor.t.sol @@ -6,8 +6,8 @@ import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/I //solhint-disable import { AggregatorV3Interface } from "interfaces/external/chainlink/AggregatorV3Interface.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; -import { ITransmuter } from "interfaces/ITransmuter.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; +import { IParallelizer } from "interfaces/IParallelizer.sol"; import { Test, stdMath, StdStorage, stdStorage } from "@forge-std/Test.sol"; import "contracts/utils/Constants.sol"; import "contracts/utils/Errors.sol"; @@ -38,9 +38,9 @@ contract BaseActor is Test { uint256 public nbrActor; address internal _currentActor; - IAgToken agToken; - ITransmuter internal _transmuter; - ITransmuter internal _transmuterSplit; + ITokenP tokenP; + IParallelizer internal _transmuter; + IParallelizer internal _transmuterSplit; address[] internal _collaterals; AggregatorV3Interface[] internal _oracles; uint256[] internal _maxTokenAmount; @@ -60,8 +60,8 @@ contract BaseActor is Test { constructor( uint256 _nbrActor, string memory actorType, - ITransmuter transmuter, - ITransmuter transmuterSplit, + IParallelizer parallelizer, + IParallelizer transmuterSplit, address[] memory collaterals, AggregatorV3Interface[] memory oracles ) { @@ -70,9 +70,9 @@ contract BaseActor is Test { actors.push(actor); } nbrActor = _nbrActor; - _transmuter = transmuter; + _transmuter = parallelizer; _transmuterSplit = transmuterSplit; - agToken = IAgToken(transmuter.agToken()); + tokenP = ITokenP(parallelizer.tokenP()); _collaterals = collaterals; _oracles = oracles; _maxTokenAmount.push(_maxAmountWithoutDecimals * 10 ** IERC20Metadata(_collaterals[0]).decimals()); diff --git a/tests/invariants/actors/Governance.t.sol b/tests/invariants/actors/Governance.t.sol index d723d7c..ed861e0 100644 --- a/tests/invariants/actors/Governance.t.sol +++ b/tests/invariants/actors/Governance.t.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.28; import "contracts/utils/Constants.sol"; -import { BaseActor, ITransmuter, AggregatorV3Interface, IERC20, IERC20Metadata } from "./BaseActor.t.sol"; +import { BaseActor, IParallelizer, AggregatorV3Interface, IERC20, IERC20Metadata } from "./BaseActor.t.sol"; import { MockChainlinkOracle } from "tests/mock/MockChainlinkOracle.sol"; import "../../utils/FunctionUtils.sol"; @@ -11,12 +11,12 @@ contract Governance is BaseActor, FunctionUtils { uint64 public collateralRatioSplit; constructor( - ITransmuter transmuter, - ITransmuter transmuterSplit, + IParallelizer parallelizer, + IParallelizer transmuterSplit, address[] memory collaterals, AggregatorV3Interface[] memory oracles ) - BaseActor(1, "Trader", transmuter, transmuterSplit, collaterals, oracles) + BaseActor(1, "Trader", parallelizer, transmuterSplit, collaterals, oracles) { } // Random oracle change of at most 1% diff --git a/tests/invariants/actors/Trader.t.sol b/tests/invariants/actors/Trader.t.sol index ee9e2f6..fc094d2 100644 --- a/tests/invariants/actors/Trader.t.sol +++ b/tests/invariants/actors/Trader.t.sol @@ -2,20 +2,22 @@ pragma solidity 0.8.28; import "contracts/utils/Constants.sol"; -import { AggregatorV3Interface, BaseActor, IERC20, IERC20Metadata, ITransmuter, TestStorage } from "./BaseActor.t.sol"; -import { QuoteType } from "contracts/transmuter/Storage.sol"; +import { + AggregatorV3Interface, BaseActor, IERC20, IERC20Metadata, IParallelizer, TestStorage +} from "./BaseActor.t.sol"; +import { QuoteType } from "contracts/parallelizer/Storage.sol"; import { console } from "@forge-std/console.sol"; contract Trader is BaseActor { constructor( - ITransmuter transmuter, - ITransmuter transmuterSplit, + IParallelizer parallelizer, + IParallelizer transmuterSplit, address[] memory collaterals, AggregatorV3Interface[] memory oracles, uint256 nbrTrader ) - BaseActor(nbrTrader, "Trader", transmuter, transmuterSplit, collaterals, oracles) + BaseActor(nbrTrader, "Trader", parallelizer, transmuterSplit, collaterals, oracles) { } function swap( @@ -36,7 +38,7 @@ contract Trader is BaseActor { if ( (quoteType == QuoteType.BurnExactInput || quoteType == QuoteType.BurnExactOutput) - && agToken.balanceOf(_currentActor) == 0 + && tokenP.balanceOf(_currentActor) == 0 ) return (0, 0); TestStorage memory testS; @@ -47,28 +49,28 @@ contract Trader is BaseActor { if (quoteType == QuoteType.MintExactInput) { console.log("Mint - Input"); testS.tokenIn = collateral; - testS.tokenOut = address(agToken); + testS.tokenOut = address(tokenP); testS.amountIn = amount * 10 ** IERC20Metadata(collateral).decimals(); testS.amountOut = _transmuter.quoteIn(testS.amountIn, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.BurnExactInput) { console.log("Burn - Input"); - testS.tokenIn = address(agToken); + testS.tokenIn = address(tokenP); testS.tokenOut = collateral; - testS.amountIn = bound(amount * BASE_18, 1, agToken.balanceOf(_currentActor)); + testS.amountIn = bound(amount * BASE_18, 1, tokenP.balanceOf(_currentActor)); testS.amountOut = _transmuter.quoteIn(testS.amountIn, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.MintExactOutput) { console.log("Mint - Output"); testS.tokenIn = collateral; - testS.tokenOut = address(agToken); + testS.tokenOut = address(tokenP); testS.amountOut = amount * BASE_18; testS.amountIn = _transmuter.quoteOut(testS.amountOut, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.BurnExactOutput) { console.log("Burn - Output"); - testS.tokenIn = address(agToken); + testS.tokenIn = address(tokenP); testS.tokenOut = collateral; testS.amountOut = amount * 10 ** IERC20Metadata(collateral).decimals(); testS.amountIn = _transmuter.quoteOut(testS.amountOut, testS.tokenIn, testS.tokenOut); - uint256 actorBalance = agToken.balanceOf(_currentActor); + uint256 actorBalance = tokenP.balanceOf(_currentActor); // we need to decrease the amountOut wanted if (actorBalance < testS.amountIn) { testS.amountIn = actorBalance; @@ -104,7 +106,7 @@ contract Trader is BaseActor { IERC20(testS.tokenIn).approve(address(_transmuterSplit), testS.amountIn); // Memory previous balances - uint256 balanceAgToken = agToken.balanceOf(_currentActor); + uint256 balanceTokenp = tokenP.balanceOf(_currentActor); uint256 balanceCollateral = IERC20(collateral).balanceOf(_currentActor); (uint64 prevCollateralRatio,) = _transmuter.getCollateralRatio(); @@ -121,7 +123,7 @@ contract Trader is BaseActor { if (quoteType == QuoteType.MintExactInput || quoteType == QuoteType.MintExactOutput) { assertEq(IERC20(collateral).balanceOf(_currentActor), balanceCollateral - testS.amountIn); - assertEq(agToken.balanceOf(_currentActor), balanceAgToken + testS.amountOut); + assertEq(tokenP.balanceOf(_currentActor), balanceTokenp + testS.amountOut); // if it is a mint and the previous collateral ratio was lower than it should always increase the // collateral ratio (uint64 collateralRatio,) = _transmuter.getCollateralRatio(); @@ -129,7 +131,7 @@ contract Trader is BaseActor { else assertGe(collateralRatio, BASE_9); } else { assertEq(IERC20(collateral).balanceOf(_currentActor), balanceCollateral + testS.amountOut); - assertEq(agToken.balanceOf(_currentActor), balanceAgToken - testS.amountIn); + assertEq(tokenP.balanceOf(_currentActor), balanceTokenp - testS.amountIn); // if it is a burn it should always increase the collateral ratio (uint64 collateralRatio,) = _transmuter.getCollateralRatio(); assertGe(collateralRatio, prevCollateralRatio); diff --git a/tests/invariants/actors/TraderWithSplit.t.sol b/tests/invariants/actors/TraderWithSplit.t.sol index 39d7e37..0a79069 100644 --- a/tests/invariants/actors/TraderWithSplit.t.sol +++ b/tests/invariants/actors/TraderWithSplit.t.sol @@ -2,20 +2,22 @@ pragma solidity 0.8.28; import "contracts/utils/Constants.sol"; -import { AggregatorV3Interface, BaseActor, IERC20, IERC20Metadata, ITransmuter, TestStorage } from "./BaseActor.t.sol"; -import { QuoteType } from "contracts/transmuter/Storage.sol"; +import { + AggregatorV3Interface, BaseActor, IERC20, IERC20Metadata, IParallelizer, TestStorage +} from "./BaseActor.t.sol"; +import { QuoteType } from "contracts/parallelizer/Storage.sol"; import { console } from "@forge-std/console.sol"; contract TraderWithSplit is BaseActor { constructor( - ITransmuter transmuter, - ITransmuter transmuterSplit, + IParallelizer parallelizer, + IParallelizer transmuterSplit, address[] memory collaterals, AggregatorV3Interface[] memory oracles, uint256 nbrTrader ) - BaseActor(nbrTrader, "Trader", transmuter, transmuterSplit, collaterals, oracles) + BaseActor(nbrTrader, "Trader", parallelizer, transmuterSplit, collaterals, oracles) { } function swap( @@ -45,7 +47,7 @@ contract TraderWithSplit is BaseActor { if ( (quoteType == QuoteType.BurnExactInput || quoteType == QuoteType.BurnExactOutput) - && agToken.balanceOf(_currentActor) == 0 + && tokenP.balanceOf(_currentActor) == 0 ) return (0, 0); TestStorage memory testS; @@ -56,30 +58,30 @@ contract TraderWithSplit is BaseActor { if (quoteType == QuoteType.MintExactInput) { console.log("Mint - Input"); testS.tokenIn = collateral; - testS.tokenOut = address(agToken); + testS.tokenOut = address(tokenP); testS.amountIn = amount * 10 ** IERC20Metadata(collateral).decimals(); testS.amountOut = _transmuter.quoteIn(testS.amountIn, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.BurnExactInput) { console.log("Burn - Input"); - testS.tokenIn = address(agToken); + testS.tokenIn = address(tokenP); testS.tokenOut = collateral; - // divided by 2 because we need to do for both the transmuter and the replica - testS.amountIn = bound(amount * BASE_18, 1, agToken.balanceOf(_currentActor) / 2); + // divided by 2 because we need to do for both the parallelizer and the replica + testS.amountIn = bound(amount * BASE_18, 1, tokenP.balanceOf(_currentActor) / 2); testS.amountOut = _transmuter.quoteIn(testS.amountIn, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.MintExactOutput) { console.log("Mint - Output"); testS.tokenIn = collateral; - testS.tokenOut = address(agToken); + testS.tokenOut = address(tokenP); testS.amountOut = amount * BASE_18; testS.amountIn = _transmuter.quoteOut(testS.amountOut, testS.tokenIn, testS.tokenOut); } else if (quoteType == QuoteType.BurnExactOutput) { console.log("Burn - Output"); - testS.tokenIn = address(agToken); + testS.tokenIn = address(tokenP); testS.tokenOut = collateral; testS.amountOut = amount * 10 ** IERC20Metadata(collateral).decimals(); testS.amountIn = _transmuter.quoteOut(testS.amountOut, testS.tokenIn, testS.tokenOut); - // divided by 2 because we need to do for both the transmuter and the replica - uint256 actorBalance = agToken.balanceOf(_currentActor) / 2; + // divided by 2 because we need to do for both the parallelizer and the replica + uint256 actorBalance = tokenP.balanceOf(_currentActor) / 2; // we need to decrease the amountOut wanted if (actorBalance < testS.amountIn) { testS.amountIn = actorBalance; @@ -120,7 +122,7 @@ contract TraderWithSplit is BaseActor { testS.amountIn, testS.amountOut, testS.tokenIn, testS.tokenOut, _currentActor, block.timestamp + 1 hours ); // send the received tokens to the sweeper - // replicate on the other transmuter but split the orders + // replicate on the other parallelizer but split the orders { testS.amountInSplit1 = (testS.amountIn * splitProportion) / BASE_9; testS.amountOutSplit1 = _transmuterSplit.quoteIn(testS.amountInSplit1, testS.tokenIn, testS.tokenOut); @@ -148,7 +150,7 @@ contract TraderWithSplit is BaseActor { _transmuter.swapExactOutput( testS.amountOut, testS.amountIn, testS.tokenIn, testS.tokenOut, _currentActor, block.timestamp + 1 hours ); - // replicate on the other transmuter but wplit the orders + // replicate on the other parallelizer but wplit the orders { testS.amountOutSplit1 = (testS.amountOut * splitProportion) / BASE_9; testS.amountInSplit1 = _transmuterSplit.quoteOut(testS.amountOutSplit1, testS.tokenIn, testS.tokenOut); @@ -156,7 +158,7 @@ contract TraderWithSplit is BaseActor { // We can be missing either stablecoins or amountIn in the case of BurnExactOutput and // MintExactOutput respectiveley // Making revert the tx due to rounding errors. We increase balances have non reverting txs - uint256 actorBalance = agToken.balanceOf(_currentActor); + uint256 actorBalance = tokenP.balanceOf(_currentActor); if (quoteType == QuoteType.BurnExactOutput && actorBalance < testS.amountInSplit1) { testS.amountInSplit1 = actorBalance; testS.amountOutSplit1 = _transmuterSplit.quoteIn(testS.amountInSplit1, testS.tokenIn, testS.tokenOut); @@ -180,7 +182,7 @@ contract TraderWithSplit is BaseActor { testS.amountOutSplit2 = testS.amountOut - testS.amountOutSplit1; testS.amountInSplit2 = _transmuterSplit.quoteOut(testS.amountOutSplit2, testS.tokenIn, testS.tokenOut); { - uint256 actorBalance = agToken.balanceOf(_currentActor); + uint256 actorBalance = tokenP.balanceOf(_currentActor); if (quoteType == QuoteType.BurnExactOutput && actorBalance < testS.amountInSplit2) { testS.amountInSplit2 = actorBalance; testS.amountOutSplit2 = _transmuterSplit.quoteIn(testS.amountInSplit2, testS.tokenIn, testS.tokenOut); diff --git a/tests/mock/MockAccessControlManager.sol b/tests/mock/MockAccessControlManager.sol index fecb5e5..9218d3b 100644 --- a/tests/mock/MockAccessControlManager.sol +++ b/tests/mock/MockAccessControlManager.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; contract MockAccessControlManager { diff --git a/tests/mock/MockChainlinkOracle.sol b/tests/mock/MockChainlinkOracle.sol index 8ae459d..66f60eb 100644 --- a/tests/mock/MockChainlinkOracle.sol +++ b/tests/mock/MockChainlinkOracle.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; interface MockAggregatorV3Interface { diff --git a/tests/mock/MockERC777.sol b/tests/mock/MockERC777.sol index d9ebb7e..e67ea6a 100644 --- a/tests/mock/MockERC777.sol +++ b/tests/mock/MockERC777.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/tests/mock/MockExternalOracle.sol b/tests/mock/MockExternalOracle.sol index 6bb1fb4..9a8e4b7 100644 --- a/tests/mock/MockExternalOracle.sol +++ b/tests/mock/MockExternalOracle.sol @@ -1,11 +1,10 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { AggregatorV3Interface } from "contracts/interfaces/external/chainlink/AggregatorV3Interface.sol"; -import { ITransmuterOracle } from "contracts/interfaces/ITransmuterOracle.sol"; +import { IParallelizerOracle } from "contracts/interfaces/IParallelizerOracle.sol"; -contract MockExternalOracle is ITransmuterOracle { +contract MockExternalOracle is IParallelizerOracle { AggregatorV3Interface feed; constructor(AggregatorV3Interface _feed) { diff --git a/tests/mock/MockFacets.sol b/tests/mock/MockFacets.sol index 4610e50..791f305 100644 --- a/tests/mock/MockFacets.sol +++ b/tests/mock/MockFacets.sol @@ -1,10 +1,9 @@ // SPDX-License-Identifier: MIT - pragma solidity 0.8.28; -import "contracts/transmuter/Storage.sol"; -import { LibDiamond } from "contracts/transmuter/libraries/LibDiamond.sol"; -import { LibStorage as s } from "contracts/transmuter/libraries/LibStorage.sol"; +import "contracts/parallelizer/Storage.sol"; +import { LibDiamond } from "contracts/parallelizer/libraries/LibDiamond.sol"; +import { LibStorage as s } from "contracts/parallelizer/libraries/LibStorage.sol"; import "contracts/utils/Errors.sol"; interface IMockFacet { diff --git a/tests/mock/MockKeyringGuard.sol b/tests/mock/MockKeyringGuard.sol index 05ce36f..24c8d11 100644 --- a/tests/mock/MockKeyringGuard.sol +++ b/tests/mock/MockKeyringGuard.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; contract MockKeyringGuard { diff --git a/tests/mock/MockLib.sol b/tests/mock/MockLib.sol index 47edb09..b39e17a 100644 --- a/tests/mock/MockLib.sol +++ b/tests/mock/MockLib.sol @@ -1,11 +1,10 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; -import { LibHelpers } from "../../contracts/transmuter/libraries/LibHelpers.sol"; -import { LibManager } from "../../contracts/transmuter/libraries/LibManager.sol"; -import { LibStorage } from "../../contracts/transmuter/libraries/LibStorage.sol"; -import { ImplementationStorage } from "../../contracts/transmuter/Storage.sol"; +import { LibHelpers } from "../../contracts/parallelizer/libraries/LibHelpers.sol"; +import { LibManager } from "../../contracts/parallelizer/libraries/LibManager.sol"; +import { LibStorage } from "../../contracts/parallelizer/libraries/LibStorage.sol"; +import { ImplementationStorage } from "../../contracts/parallelizer/Storage.sol"; contract MockLib { function convertDecimalTo(uint256 amount, uint8 fromDecimals, uint8 toDecimals) external pure returns (uint256) { diff --git a/tests/mock/MockManager.sol b/tests/mock/MockManager.sol index 46f43c2..b852b9e 100644 --- a/tests/mock/MockManager.sol +++ b/tests/mock/MockManager.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; @@ -7,8 +6,8 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "interfaces/IManager.sol"; -import { LibHelpers } from "../../contracts/transmuter/libraries/LibHelpers.sol"; -import { LibOracle, AggregatorV3Interface } from "../../contracts/transmuter/libraries/LibOracle.sol"; +import { LibHelpers } from "../../contracts/parallelizer/libraries/LibHelpers.sol"; +import { LibOracle, AggregatorV3Interface } from "../../contracts/parallelizer/libraries/LibOracle.sol"; import "../../contracts/utils/Constants.sol"; import "../../contracts/utils/Errors.sol"; diff --git a/tests/mock/MockMorphoOracle.sol b/tests/mock/MockMorphoOracle.sol index ba41904..7a7f80d 100644 --- a/tests/mock/MockMorphoOracle.sol +++ b/tests/mock/MockMorphoOracle.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { IMorphoOracle } from "contracts/interfaces/external/morpho/IMorphoOracle.sol"; diff --git a/tests/mock/MockOneInchRouter.sol b/tests/mock/MockOneInchRouter.sol index ce71758..307e134 100644 --- a/tests/mock/MockOneInchRouter.sol +++ b/tests/mock/MockOneInchRouter.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/tests/mock/MockPyth.sol b/tests/mock/MockPyth.sol index 85da1ba..b979f46 100644 --- a/tests/mock/MockPyth.sol +++ b/tests/mock/MockPyth.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import "interfaces/external/pyth/IPyth.sol"; diff --git a/tests/mock/MockReentrant.sol b/tests/mock/MockReentrant.sol index 2a0d52d..fb17189 100644 --- a/tests/mock/MockReentrant.sol +++ b/tests/mock/MockReentrant.sol @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; -import { ITransmuter, Transmuter } from "../utils/Transmuter.sol"; +import { IParallelizer, Parallelizer } from "../utils/Parallelizer.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; import { IERC1820Registry } from "./MockERC777.sol"; @@ -10,19 +9,19 @@ contract ReentrantRedeemGetCollateralRatio { bytes32 private constant _TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender"); bytes32 private constant _TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient"); - ITransmuter transmuter; + IParallelizer parallelizer; IERC1820Registry registry; - constructor(ITransmuter _transmuter, IERC1820Registry _registry) { - transmuter = _transmuter; + constructor(IParallelizer _transmuter, IERC1820Registry _registry) { + parallelizer = _transmuter; registry = _registry; } function testERC777Reentrancy(uint256 redeemAmount) public { uint256[] memory minAmountOuts; - (, uint256[] memory quoteAmounts) = transmuter.quoteRedemptionCurve(redeemAmount); + (, uint256[] memory quoteAmounts) = parallelizer.quoteRedemptionCurve(redeemAmount); minAmountOuts = new uint256[](quoteAmounts.length); - transmuter.redeem(redeemAmount, address(this), block.timestamp * 2, minAmountOuts); + parallelizer.redeem(redeemAmount, address(this), block.timestamp * 2, minAmountOuts); } function setInterfaceImplementer() public { @@ -36,7 +35,7 @@ contract ReentrantRedeemGetCollateralRatio { // reenter here if (from != address(0)) { // It should revert here - transmuter.getCollateralRatio(); + parallelizer.getCollateralRatio(); } } @@ -47,23 +46,23 @@ contract ReentrantRedeemSwap { bytes32 private constant _TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender"); bytes32 private constant _TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient"); - ITransmuter transmuter; + IParallelizer parallelizer; IERC1820Registry registry; - IERC20 agToken; + IERC20 tokenP; IERC20 collateral; - constructor(ITransmuter _transmuter, IERC1820Registry _registry, IERC20 _agToken, IERC20 _collateral) { - transmuter = _transmuter; + constructor(IParallelizer _transmuter, IERC1820Registry _registry, IERC20 _tokenP, IERC20 _collateral) { + parallelizer = _transmuter; registry = _registry; - agToken = _agToken; + tokenP = _tokenP; collateral = _collateral; } function testERC777Reentrancy(uint256 redeemAmount) public { uint256[] memory minAmountOuts; - (, uint256[] memory quoteAmounts) = transmuter.quoteRedemptionCurve(redeemAmount); + (, uint256[] memory quoteAmounts) = parallelizer.quoteRedemptionCurve(redeemAmount); minAmountOuts = new uint256[](quoteAmounts.length); - transmuter.redeem(redeemAmount, address(this), block.timestamp * 2, minAmountOuts); + parallelizer.redeem(redeemAmount, address(this), block.timestamp * 2, minAmountOuts); } function setInterfaceImplementer() public { @@ -77,7 +76,7 @@ contract ReentrantRedeemSwap { // reenter here if (from != address(0)) { // It should revert here - transmuter.swapExactInput(1e18, 0, address(collateral), address(agToken), address(this), block.timestamp * 2); + parallelizer.swapExactInput(1e18, 0, address(collateral), address(tokenP), address(this), block.timestamp * 2); } } diff --git a/tests/units/DiamondCut.t.sol b/tests/units/DiamondCut.t.sol index 027e5cf..837ece6 100644 --- a/tests/units/DiamondCut.t.sol +++ b/tests/units/DiamondCut.t.sol @@ -11,10 +11,10 @@ import { DiamondProxy } from "tests/mock/MockFacets.sol"; -import "contracts/transmuter/Storage.sol"; -import { Test } from "contracts/transmuter/configs/Test.sol"; -import { DiamondCut } from "contracts/transmuter/facets/DiamondCut.sol"; -import { LibDiamond } from "contracts/transmuter/libraries/LibDiamond.sol"; +import "contracts/parallelizer/Storage.sol"; +import { Test } from "contracts/parallelizer/configs/Test.sol"; +import { DiamondCut } from "contracts/parallelizer/facets/DiamondCut.sol"; +import { LibDiamond } from "contracts/parallelizer/libraries/LibDiamond.sol"; import "contracts/utils/Constants.sol"; import "contracts/utils/Errors.sol" as Errors; @@ -44,7 +44,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.diamondCut(facetCut, address(0x0), ""); + parallelizer.diamondCut(facetCut, address(0x0), ""); } function test_RevertWhen_NoSelectorsProvidedForFacetForCut() public { @@ -56,7 +56,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.NoSelectorsProvidedForFacetForCut.selector, pureFacet)); hoax(governor); - transmuter.diamondCut(facetCut, address(0x0), ""); + parallelizer.diamondCut(facetCut, address(0x0), ""); } function test_RevertWhen_IncorrectFacetCutAction() public { @@ -68,7 +68,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(bytes("")); // Reverts with a Panic code hoax(governor); - DiamondCutAux(address(transmuter)).diamondCut(facetCut, address(0x0), ""); + DiamondCutAux(address(parallelizer)).diamondCut(facetCut, address(0x0), ""); } function test_RevertWhen_InitializerHasNoCode() public { @@ -79,7 +79,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(Errors.ContractHasNoCode.selector); hoax(governor); - transmuter.diamondCut(facetCut, address(1), ""); + parallelizer.diamondCut(facetCut, address(1), ""); } function test_RevertWhen_InitializerRevert() public { @@ -96,7 +96,7 @@ contract Test_DiamondCut is Fixture { ); hoax(governor); - transmuter.diamondCut(facetCut, initializer, abi.encodeWithSelector(MockInitializer.initializeRevert.selector)); + parallelizer.diamondCut(facetCut, initializer, abi.encodeWithSelector(MockInitializer.initializeRevert.selector)); } function test_RevertWhen_InitializerRevertWithMessage() public { @@ -107,7 +107,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(MockInitializer.CustomError.selector); hoax(governor); - transmuter.diamondCut( + parallelizer.diamondCut( facetCut, initializer, abi.encodeWithSelector(MockInitializer.initializeRevertWithMessage.selector) ); } @@ -119,7 +119,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.CannotAddSelectorsToZeroAddress.selector, selectors)); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); + parallelizer.diamondCut(facetCut, address(0), ""); } function test_RevertWhen_AddAlreadyExistingSelector() public { @@ -128,7 +128,7 @@ contract Test_DiamondCut is Fixture { FacetCut({ facetAddress: address(pureFacet), action: FacetCutAction.Add, functionSelectors: selectors }); hoax(governor); - transmuter.diamondCut(facetCut, address(0x0), ""); + parallelizer.diamondCut(facetCut, address(0x0), ""); facetCut[0] = FacetCut({ facetAddress: address(writeFacet), action: FacetCutAction.Add, functionSelectors: selectors }); @@ -136,7 +136,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.CannotAddFunctionToDiamondThatAlreadyExists.selector, selectors[0])); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); + parallelizer.diamondCut(facetCut, address(0), ""); } function test_RevertWhen_ReplaceFromZeroAddress() public { @@ -146,7 +146,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.CannotReplaceFunctionsFromFacetWithZeroAddress.selector, selectors)); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); + parallelizer.diamondCut(facetCut, address(0), ""); } function test_RevertWhen_ReplaceImmutableFunction() public { @@ -176,7 +176,7 @@ contract Test_DiamondCut is Fixture { FacetCut({ facetAddress: address(pureFacet), action: FacetCutAction.Add, functionSelectors: selectors }); hoax(governor); - transmuter.diamondCut(facetCut, address(0x0), ""); + parallelizer.diamondCut(facetCut, address(0x0), ""); facetCut[0] = FacetCut({ facetAddress: address(pureFacet), action: FacetCutAction.Replace, functionSelectors: selectors }); @@ -186,7 +186,7 @@ contract Test_DiamondCut is Fixture { ); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); + parallelizer.diamondCut(facetCut, address(0), ""); } function test_RevertWhen_ReplaceFunctionThatDoesNotExists() public { @@ -197,7 +197,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.CannotReplaceFunctionThatDoesNotExists.selector, selectors[0])); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); + parallelizer.diamondCut(facetCut, address(0), ""); } function test_RevertWhen_RemoveFacetAddressMustBeZeroAddress() public { @@ -208,7 +208,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.RemoveFacetAddressMustBeZeroAddress.selector, pureFacet)); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); + parallelizer.diamondCut(facetCut, address(0), ""); } function test_RevertWhen_RemoveFunctionThatDoesNotExist() public { @@ -218,7 +218,7 @@ contract Test_DiamondCut is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.CannotRemoveFunctionThatDoesNotExist.selector, selectors[0])); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); + parallelizer.diamondCut(facetCut, address(0), ""); } function test_RevertWhen_RemoveImmutableFunction() public { @@ -245,14 +245,14 @@ contract Test_DiamondCut is Fixture { FacetCut({ facetAddress: address(pureFacet), action: FacetCutAction.Add, functionSelectors: selectors }); // Events - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibDiamond.DiamondCut(facetCut, address(0x0), ""); hoax(governor); - transmuter.diamondCut(facetCut, address(0x0), ""); + parallelizer.diamondCut(facetCut, address(0x0), ""); - assertEq(IMockFacet(address(transmuter)).newFunction(), 1); - assertEq(IMockFacet(address(transmuter)).newFunction2(), 2); + assertEq(IMockFacet(address(parallelizer)).newFunction(), 1); + assertEq(IMockFacet(address(parallelizer)).newFunction2(), 2); } function test_AddSimpleWriteFacet() public { @@ -261,14 +261,14 @@ contract Test_DiamondCut is Fixture { FacetCut({ facetAddress: address(writeFacet), action: FacetCutAction.Add, functionSelectors: selectors }); // Event - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibDiamond.DiamondCut(facetCut, address(0x0), ""); hoax(governor); - transmuter.diamondCut(facetCut, address(0x0), ""); + parallelizer.diamondCut(facetCut, address(0x0), ""); - assertEq(IMockFacet(address(transmuter)).newFunction(), 0); - assertEq(IMockFacet(address(transmuter)).newFunction2(), 1); + assertEq(IMockFacet(address(parallelizer)).newFunction(), 0); + assertEq(IMockFacet(address(parallelizer)).newFunction2(), 1); } function test_AddWriteFacetWithInitializer() public { @@ -277,14 +277,14 @@ contract Test_DiamondCut is Fixture { FacetCut({ facetAddress: address(writeFacet), action: FacetCutAction.Add, functionSelectors: selectors }); // Event - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibDiamond.DiamondCut(facetCut, initializer, abi.encodeWithSelector(MockInitializer.initialize.selector)); hoax(governor); - transmuter.diamondCut(facetCut, initializer, abi.encodeWithSelector(MockInitializer.initialize.selector)); + parallelizer.diamondCut(facetCut, initializer, abi.encodeWithSelector(MockInitializer.initialize.selector)); - assertEq(IMockFacet(address(transmuter)).newFunction(), 2); // 2 because of the initializer - assertEq(IMockFacet(address(transmuter)).newFunction2(), 1); + assertEq(IMockFacet(address(parallelizer)).newFunction(), 2); // 2 because of the initializer + assertEq(IMockFacet(address(parallelizer)).newFunction2(), 1); } function test_ReplaceReadWithWriteFacet() public { @@ -293,23 +293,23 @@ contract Test_DiamondCut is Fixture { FacetCut({ facetAddress: address(pureFacet), action: FacetCutAction.Add, functionSelectors: selectors }); hoax(governor); - transmuter.diamondCut(facetCut, address(0), "0x"); + parallelizer.diamondCut(facetCut, address(0), "0x"); - assertEq(IMockFacet(address(transmuter)).newFunction(), 1); - assertEq(IMockFacet(address(transmuter)).newFunction2(), 2); + assertEq(IMockFacet(address(parallelizer)).newFunction(), 1); + assertEq(IMockFacet(address(parallelizer)).newFunction2(), 2); facetCut[0] = FacetCut({ facetAddress: address(writeFacet), action: FacetCutAction.Replace, functionSelectors: selectors }); // Event - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibDiamond.DiamondCut(facetCut, address(0), "0x"); hoax(governor); - transmuter.diamondCut(facetCut, address(0), "0x"); + parallelizer.diamondCut(facetCut, address(0), "0x"); - assertEq(IMockFacet(address(transmuter)).newFunction(), 0); - assertEq(IMockFacet(address(transmuter)).newFunction2(), 1); + assertEq(IMockFacet(address(parallelizer)).newFunction(), 0); + assertEq(IMockFacet(address(parallelizer)).newFunction2(), 1); } function test_ReplaceWriteWithExtendedWriteFacet() public { @@ -318,10 +318,12 @@ contract Test_DiamondCut is Fixture { FacetCut({ facetAddress: address(writeFacet), action: FacetCutAction.Add, functionSelectors: selectors }); hoax(governor); - transmuter.diamondCut(facetCut, address(initializer), abi.encodeWithSelector(MockInitializer.initialize.selector)); + parallelizer.diamondCut( + facetCut, address(initializer), abi.encodeWithSelector(MockInitializer.initialize.selector) + ); - assertEq(IMockFacet(address(transmuter)).newFunction(), 2); // Slot 1 is 2 with the initializer - assertEq(IMockFacet(address(transmuter)).newFunction2(), 1); // Slot 1 is now 1 + assertEq(IMockFacet(address(parallelizer)).newFunction(), 2); // Slot 1 is 2 with the initializer + assertEq(IMockFacet(address(parallelizer)).newFunction2(), 1); // Slot 1 is now 1 facetCut[0] = FacetCut({ facetAddress: address(writeExpandedFacet), @@ -330,14 +332,14 @@ contract Test_DiamondCut is Fixture { }); // Event - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibDiamond.DiamondCut(facetCut, address(0), "0x"); hoax(governor); - transmuter.diamondCut(facetCut, address(0), "0x"); + parallelizer.diamondCut(facetCut, address(0), "0x"); - assertEq(IMockFacet(address(transmuter)).newFunction(), 1); // Slot 1 is still 2 - assertEq(IMockFacet(address(transmuter)).newFunction2(), 20); // Slot 2 is 20 + assertEq(IMockFacet(address(parallelizer)).newFunction(), 1); // Slot 1 is still 2 + assertEq(IMockFacet(address(parallelizer)).newFunction2(), 20); // Slot 2 is 20 } function test_RemoveWriteFacet() public { @@ -346,23 +348,25 @@ contract Test_DiamondCut is Fixture { FacetCut({ facetAddress: address(writeFacet), action: FacetCutAction.Add, functionSelectors: selectors }); hoax(governor); - transmuter.diamondCut(facetCut, address(initializer), abi.encodeWithSelector(MockInitializer.initialize.selector)); + parallelizer.diamondCut( + facetCut, address(initializer), abi.encodeWithSelector(MockInitializer.initialize.selector) + ); - assertEq(IMockFacet(address(transmuter)).newFunction(), 2); // Slot 1 is 2 with the initializer - assertEq(IMockFacet(address(transmuter)).newFunction2(), 1); // Slot 1 is now 1 + assertEq(IMockFacet(address(parallelizer)).newFunction(), 2); // Slot 1 is 2 with the initializer + assertEq(IMockFacet(address(parallelizer)).newFunction2(), 1); // Slot 1 is now 1 facetCut[0] = FacetCut({ facetAddress: address(0), action: FacetCutAction.Remove, functionSelectors: selectors }); // Event - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibDiamond.DiamondCut(facetCut, address(0), "0x"); hoax(governor); - transmuter.diamondCut(facetCut, address(0), "0x"); + parallelizer.diamondCut(facetCut, address(0), "0x"); vm.expectRevert(abi.encodeWithSelector(Errors.FunctionNotFound.selector, IMockFacet.newFunction.selector)); - IMockFacet(address(transmuter)).newFunction(); + IMockFacet(address(parallelizer)).newFunction(); vm.expectRevert(abi.encodeWithSelector(Errors.FunctionNotFound.selector, IMockFacet.newFunction2.selector)); - IMockFacet(address(transmuter)).newFunction2(); + IMockFacet(address(parallelizer)).newFunction2(); } } diff --git a/tests/units/DiamondLoupe.t.sol b/tests/units/DiamondLoupe.t.sol index b677a7d..ec6430d 100644 --- a/tests/units/DiamondLoupe.t.sol +++ b/tests/units/DiamondLoupe.t.sol @@ -4,9 +4,9 @@ pragma solidity 0.8.28; import { IMockFacet, MockPureFacet } from "tests/mock/MockFacets.sol"; -import "contracts/transmuter/Storage.sol"; -import { Test } from "contracts/transmuter/configs/Test.sol"; -import { DiamondCut } from "contracts/transmuter/facets/DiamondCut.sol"; +import "contracts/parallelizer/Storage.sol"; +import { Test } from "contracts/parallelizer/configs/Test.sol"; +import { DiamondCut } from "contracts/parallelizer/facets/DiamondCut.sol"; import "contracts/utils/Constants.sol"; import { Fixture } from "../Fixture.sol"; @@ -15,7 +15,7 @@ contract Test_DiamondLoupe is Fixture { address pureFacet = address(new MockPureFacet()); function test_Facets() public { - Facet[] memory facets = transmuter.facets(); + Facet[] memory facets = parallelizer.facets(); // DiamondCut, DiamondLoupe, Getters, Redeemer, RewardHandler, SettersGovernor, SettersGuardian , Swapper for (uint256 i; i < facetNames.length; ++i) { @@ -42,9 +42,9 @@ contract Test_DiamondLoupe is Fixture { FacetCut({ facetAddress: address(pureFacet), action: FacetCutAction.Add, functionSelectors: auxSelectors }); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); // Deploy only the first selector + parallelizer.diamondCut(facetCut, address(0), ""); // Deploy only the first selector - bytes4[] memory fetchedSelectors = transmuter.facetFunctionSelectors(pureFacet); + bytes4[] memory fetchedSelectors = parallelizer.facetFunctionSelectors(pureFacet); assertEq(fetchedSelectors.length, 1); // Check only the first selector is accessible assertEq(fetchedSelectors[0], selectors[0]); @@ -54,9 +54,9 @@ contract Test_DiamondLoupe is Fixture { FacetCut({ facetAddress: address(pureFacet), action: FacetCutAction.Add, functionSelectors: auxSelectors }); hoax(governor); - transmuter.diamondCut(facetCut, address(0), ""); // Deploy the second selector + parallelizer.diamondCut(facetCut, address(0), ""); // Deploy the second selector - fetchedSelectors = transmuter.facetFunctionSelectors(pureFacet); + fetchedSelectors = parallelizer.facetFunctionSelectors(pureFacet); assertEq(fetchedSelectors.length, 2); // Check only the first selector is accessible assertEq(fetchedSelectors[0], selectors[0]); @@ -64,7 +64,7 @@ contract Test_DiamondLoupe is Fixture { } function test_FacetAddresses() public { - address[] memory facetAddresses = transmuter.facetAddresses(); + address[] memory facetAddresses = parallelizer.facetAddresses(); for (uint256 i; i < facetAddresses.length; ++i) { assertEq(facetAddresses[i], facetAddressList[i]); } @@ -75,7 +75,7 @@ contract Test_DiamondLoupe is Fixture { bytes4[] memory selectors = _generateSelectors(facetNames[i]); for (uint256 j; j < selectors.length; ++j) { - assertEq(transmuter.facetAddress(selectors[j]), facetAddressList[i]); // Check all selectors are + assertEq(parallelizer.facetAddress(selectors[j]), facetAddressList[i]); // Check all selectors are // present } } diff --git a/tests/units/Layout.t.sol b/tests/units/Layout.t.sol index f6506a3..b3a4d15 100644 --- a/tests/units/Layout.t.sol +++ b/tests/units/Layout.t.sol @@ -2,16 +2,16 @@ pragma solidity 0.8.28; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; import { console } from "@forge-std/console.sol"; import { IMockFacet, MockPureFacet } from "tests/mock/MockFacets.sol"; -import { Layout } from "contracts/transmuter/Layout.sol"; -import "contracts/transmuter/Storage.sol"; -import { Test } from "contracts/transmuter/configs/Test.sol"; -import { DiamondCut } from "contracts/transmuter/facets/DiamondCut.sol"; +import { Layout } from "contracts/parallelizer/Layout.sol"; +import "contracts/parallelizer/Storage.sol"; +import { Test } from "contracts/parallelizer/configs/Test.sol"; +import { DiamondCut } from "contracts/parallelizer/facets/DiamondCut.sol"; import "contracts/utils/Constants.sol"; import { Fixture } from "../Fixture.sol"; @@ -21,28 +21,28 @@ contract Test_Layout is Fixture { function setUp() public override { super.setUp(); - layout = Layout(address(transmuter)); + layout = Layout(address(parallelizer)); } function test_Layout() public { - address agToken = address(transmuter.agToken()); - uint8 isRedemptionLive = transmuter.isPaused(address(0), ActionType.Redeem) ? 0 : 1; - uint256 stablecoinsIssued = transmuter.getTotalIssued(); - address[] memory collateralList = transmuter.getCollateralList(); - (uint64[] memory xRedemptionCurve, int64[] memory yRedemptionCurve) = transmuter.getRedemptionFees(); - Collateral memory collateral = transmuter.getCollateralInfo(collateralList[0]); + address tokenP = address(parallelizer.tokenP()); + uint8 isRedemptionLive = parallelizer.isPaused(address(0), ActionType.Redeem) ? 0 : 1; + uint256 stablecoinsIssued = parallelizer.getTotalIssued(); + address[] memory collateralList = parallelizer.getCollateralList(); + (uint64[] memory xRedemptionCurve, int64[] memory yRedemptionCurve) = parallelizer.getRedemptionFees(); + Collateral memory collateral = parallelizer.getCollateralInfo(collateralList[0]); hoax(governor); - transmuter.toggleTrusted(alice, TrustedType.Updater); + parallelizer.toggleTrusted(alice, TrustedType.Updater); hoax(governor); - transmuter.toggleTrusted(alice, TrustedType.Seller); - address accessManager = transmuter.accessManager(); + parallelizer.toggleTrusted(alice, TrustedType.Seller); + address accessManager = parallelizer.accessManager(); hoax(guardian); - transmuter.setDummyImplementation(address(alice)); - address implementation = transmuter.implementation(); + parallelizer.setDummyImplementation(address(alice)); + address implementation = parallelizer.implementation(); _etch(); - assertEq(layout.agToken(), agToken); + assertEq(layout.tokenP(), tokenP); assertEq(layout.isRedemptionLive(), isRedemptionLive); assertEq((layout.normalizedStables() * layout.normalizer()) / BASE_27, stablecoinsIssued); for (uint256 i; i < collateralList.length; i++) { @@ -79,7 +79,7 @@ contract Test_Layout is Fixture { assertEq(layout.isTrusted(bob), 0); assertEq(layout.isSellerTrusted(bob), 0); - bytes4[] memory selectors = _generateSelectors("ITransmuter"); + bytes4[] memory selectors = _generateSelectors("IParallelizer"); for (uint256 i = 0; i < selectors.length; ++i) { (address facetAddress, uint16 selectorPosition) = layout.selectorInfo(selectors[i]); assertNotEq(facetAddress, address(0)); diff --git a/tests/units/Libraries.t.sol b/tests/units/Libraries.t.sol index 66cbc73..3c27e2c 100644 --- a/tests/units/Libraries.t.sol +++ b/tests/units/Libraries.t.sol @@ -8,7 +8,7 @@ import { stdError } from "@forge-std/Test.sol"; import "tests/mock/MockManager.sol"; import { IERC20 } from "tests/mock/MockTokenPermit.sol"; import { MockLib } from "tests/mock/MockLib.sol"; -import "contracts/transmuter/Storage.sol"; +import "contracts/parallelizer/Storage.sol"; import "contracts/utils/Errors.sol" as Errors; diff --git a/tests/units/Transmuter.t.sol b/tests/units/Parallelizer.t.sol similarity index 66% rename from tests/units/Transmuter.t.sol rename to tests/units/Parallelizer.t.sol index 86f1f46..4e4c111 100644 --- a/tests/units/Transmuter.t.sol +++ b/tests/units/Parallelizer.t.sol @@ -4,26 +4,25 @@ pragma solidity 0.8.28; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; -import { IAccessControlManager } from "interfaces/IAccessControlManager.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; import { AggregatorV3Interface } from "interfaces/external/chainlink/AggregatorV3Interface.sol"; import { MockAccessControlManager } from "tests/mock/MockAccessControlManager.sol"; import { MockChainlinkOracle } from "tests/mock/MockChainlinkOracle.sol"; import { MockTokenPermit } from "tests/mock/MockTokenPermit.sol"; -import { Test } from "contracts/transmuter/configs/Test.sol"; -import { LibGetters } from "contracts/transmuter/libraries/LibGetters.sol"; -import "contracts/transmuter/Storage.sol"; +import { Test } from "contracts/parallelizer/configs/Test.sol"; +import { LibGetters } from "contracts/parallelizer/libraries/LibGetters.sol"; +import "contracts/parallelizer/Storage.sol"; import "contracts/utils/Constants.sol"; import "contracts/utils/Errors.sol"; import { Fixture } from "../Fixture.sol"; -contract TestTransmuter is Fixture { +contract TestParallelizer is Fixture { function test_FacetsHaveCorrectSelectors() public { for (uint256 i = 0; i < facetAddressList.length; ++i) { - bytes4[] memory fromLoupeFacet = transmuter.facetFunctionSelectors(facetAddressList[i]); + bytes4[] memory fromLoupeFacet = parallelizer.facetFunctionSelectors(facetAddressList[i]); bytes4[] memory fromGenSelectors = _generateSelectors(facetNames[i]); assertTrue(sameMembers(fromLoupeFacet, fromGenSelectors)); } @@ -33,23 +32,23 @@ contract TestTransmuter is Fixture { for (uint256 i = 0; i < facetAddressList.length; ++i) { bytes4[] memory fromGenSelectors = _generateSelectors(facetNames[i]); for (uint256 j = 0; j < fromGenSelectors.length; j++) { - assertEq(facetAddressList[i], transmuter.facetAddress(fromGenSelectors[j])); + assertEq(facetAddressList[i], parallelizer.facetAddress(fromGenSelectors[j])); } } } function test_InterfaceCorrectlyImplemented() public { - bytes4[] memory selectors = _generateSelectors("ITransmuter"); + bytes4[] memory selectors = _generateSelectors("IParallelizer"); for (uint256 i = 0; i < selectors.length; ++i) { - assertEq(transmuter.isValidSelector(selectors[i]), true); + assertEq(parallelizer.isValidSelector(selectors[i]), true); } } // Checks that all implemented selectors are in the interface function test_OnlyInterfaceIsImplemented() public { - bytes4[] memory interfaceSelectors = _generateSelectors("ITransmuter"); + bytes4[] memory interfaceSelectors = _generateSelectors("IParallelizer"); - Facet[] memory facets = transmuter.facets(); + Facet[] memory facets = parallelizer.facets(); for (uint256 i; i < facetNames.length; ++i) { for (uint256 j; j < facets[i].functionSelectors.length; ++j) { @@ -66,7 +65,7 @@ contract TestTransmuter is Fixture { } function test_QuoteInScenario() public { - uint256 quote = (transmuter.quoteIn(BASE_6, address(eurA), address(agToken))); + uint256 quote = (parallelizer.quoteIn(BASE_6, address(eurA), address(tokenP))); assertEq(quote, BASE_27 / (BASE_9 + BASE_9 / 99)); } @@ -74,14 +73,14 @@ contract TestTransmuter is Fixture { deal(address(eurA), alice, BASE_6); startHoax(alice); - eurA.approve(address(transmuter), BASE_6); - transmuter.swapExactInput(BASE_6, 0, address(eurA), address(agToken), alice, block.timestamp + 1 hours); + eurA.approve(address(parallelizer), BASE_6); + parallelizer.swapExactInput(BASE_6, 0, address(eurA), address(tokenP), alice, block.timestamp + 1 hours); - assertEq(agToken.balanceOf(alice), BASE_27 / (BASE_9 + BASE_9 / 99)); + assertEq(tokenP.balanceOf(alice), BASE_27 / (BASE_9 + BASE_9 / 99)); } function test_QuoteCollateralRatio() public { - transmuter.getCollateralRatio(); + parallelizer.getCollateralRatio(); assertEq(uint256(0), uint256(0)); } diff --git a/tests/units/TransmuterReentrant.sol b/tests/units/ParallelizerReentrant.sol similarity index 84% rename from tests/units/TransmuterReentrant.sol rename to tests/units/ParallelizerReentrant.sol index 3d85b27..c037e71 100644 --- a/tests/units/TransmuterReentrant.sol +++ b/tests/units/ParallelizerReentrant.sol @@ -7,8 +7,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { AccessManager, IAccessManaged } from "@openzeppelin/contracts/access/manager/AccessManager.sol"; -import { IAccessControlManager } from "interfaces/IAccessControlManager.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; import { AggregatorV3Interface } from "interfaces/external/chainlink/AggregatorV3Interface.sol"; import { MockAccessControlManager } from "../mock/MockAccessControlManager.sol"; @@ -17,19 +16,19 @@ import { MockERC777, IERC1820Registry } from "../mock/MockERC777.sol"; import { MockTokenPermit } from "../mock/MockTokenPermit.sol"; import { ReentrantRedeemGetCollateralRatio, ReentrantRedeemSwap } from "../mock/MockReentrant.sol"; -import { CollateralSetup, Test } from "contracts/transmuter/configs/Test.sol"; -import { LibGetters } from "contracts/transmuter/libraries/LibGetters.sol"; -import "contracts/transmuter/Storage.sol"; +import { CollateralSetup, Test } from "contracts/parallelizer/configs/Test.sol"; +import { LibGetters } from "contracts/parallelizer/libraries/LibGetters.sol"; +import "contracts/parallelizer/Storage.sol"; import "contracts/utils/Constants.sol"; import "contracts/utils/Errors.sol" as Errors; -import { ITransmuter, Transmuter } from "../utils/Transmuter.sol"; +import { IParallelizer, Parallelizer } from "../utils/Parallelizer.sol"; import { ConfigAccessManager } from "../utils/ConfigAccessManager.sol"; -contract TransmuterReentrantTest is Transmuter, ConfigAccessManager { +contract ParallelizerReentrantTest is Parallelizer, ConfigAccessManager { using SafeERC20 for IERC20; - IAgToken public agToken; + ITokenP public tokenP; IERC20 public eurA; AggregatorV3Interface public oracleA; @@ -93,8 +92,8 @@ contract TransmuterReentrantTest is Transmuter, ConfigAccessManager { deployAccessManager(governor, governor, guardian, governorAndGuardian); - // agToken - agToken = IAgToken(address(new MockTokenPermit("agEUR", "agEUR", 18))); + // tokenP + tokenP = ITokenP(address(new MockTokenPermit("agEUR", "agEUR", 18))); // Collaterals eurA = IERC20(address(new MockERC777("EUR_A", "EUR_A", 18))); @@ -111,24 +110,24 @@ contract TransmuterReentrantTest is Transmuter, ConfigAccessManager { // Config config = address(new Test()); - deployTransmuter( + deployParallelizer( config, abi.encodeWithSelector( Test.initialize.selector, accessManager, - agToken, + tokenP, CollateralSetup(address(eurA), address(oracleA)), CollateralSetup(address(eurB), address(oracleB)), CollateralSetup(address(eurY), address(oracleY)) ) ); vm.startPrank(governor); - accessManager.setTargetFunctionRole(address(transmuter), getTransmuterGovernorSelectorAccess(), GOVERNOR_ROLE); - accessManager.setTargetFunctionRole(address(transmuter), getTransmuterGuardianSelectorAccess(), GUARDIAN_ROLE); + accessManager.setTargetFunctionRole(address(parallelizer), getParallelizerGovernorSelectorAccess(), GOVERNOR_ROLE); + accessManager.setTargetFunctionRole(address(parallelizer), getParallelizerGuardianSelectorAccess(), GUARDIAN_ROLE); vm.stopPrank(); - vm.label(address(agToken), "AgToken"); - vm.label(address(transmuter), "Transmuter"); + vm.label(address(tokenP), "tokenP"); + vm.label(address(parallelizer), "Parallelizer"); vm.label(address(eurA), "eurA"); vm.label(address(eurB), "eurB"); vm.label(address(eurY), "eurY"); @@ -143,13 +142,13 @@ contract TransmuterReentrantTest is Transmuter, ConfigAccessManager { int64[] memory yFeeRedemption = new int64[](1); yFeeRedemption[0] = int64(int256(BASE_9)); vm.startPrank(guardian); - transmuter.setFees(address(eurA), xFeeMint, yFee, true); - transmuter.setFees(address(eurA), xFeeBurn, yFee, false); - transmuter.setFees(address(eurB), xFeeMint, yFee, true); - transmuter.setFees(address(eurB), xFeeBurn, yFee, false); - transmuter.setFees(address(eurY), xFeeMint, yFee, true); - transmuter.setFees(address(eurY), xFeeBurn, yFee, false); - transmuter.setRedemptionCurveParams(xFeeMint, yFeeRedemption); + parallelizer.setFees(address(eurA), xFeeMint, yFee, true); + parallelizer.setFees(address(eurA), xFeeBurn, yFee, false); + parallelizer.setFees(address(eurB), xFeeMint, yFee, true); + parallelizer.setFees(address(eurB), xFeeBurn, yFee, false); + parallelizer.setFees(address(eurY), xFeeMint, yFee, true); + parallelizer.setFees(address(eurY), xFeeBurn, yFee, false); + parallelizer.setRedemptionCurveParams(xFeeMint, yFeeRedemption); vm.stopPrank(); _collaterals.push(address(eurA)); @@ -165,13 +164,13 @@ contract TransmuterReentrantTest is Transmuter, ConfigAccessManager { // deploy all the reentrant contracts contractReentrantRedeemGetCollateralRatio = - new ReentrantRedeemGetCollateralRatio(ITransmuter(address(transmuter)), IERC1820Registry(address(registry))); + new ReentrantRedeemGetCollateralRatio(IParallelizer(address(parallelizer)), IERC1820Registry(address(registry))); contractReentrantRedeemGetCollateralRatio.setInterfaceImplementer(); contractReentrantRedeemSwap = new ReentrantRedeemSwap( - ITransmuter(address(transmuter)), + IParallelizer(address(parallelizer)), IERC1820Registry(address(registry)), - IERC20(address(agToken)), + IERC20(address(tokenP)), IERC20(address(eurB)) ); contractReentrantRedeemSwap.setInterfaceImplementer(); @@ -183,11 +182,11 @@ contract TransmuterReentrantTest is Transmuter, ConfigAccessManager { if (mintedStables == 0) return; vm.startPrank(alice); - uint256 amountBurnt = agToken.balanceOf(alice); - (, uint256[] memory quoteAmounts) = transmuter.quoteRedemptionCurve(amountBurnt); + uint256 amountBurnt = tokenP.balanceOf(alice); + (, uint256[] memory quoteAmounts) = parallelizer.quoteRedemptionCurve(amountBurnt); if (quoteAmounts[0] == 0) return; - agToken.transfer(address(contractReentrantRedeemGetCollateralRatio), amountBurnt); + tokenP.transfer(address(contractReentrantRedeemGetCollateralRatio), amountBurnt); vm.expectRevert(Errors.ReentrantCall.selector); contractReentrantRedeemGetCollateralRatio.testERC777Reentrancy(amountBurnt); vm.stopPrank(); @@ -199,11 +198,11 @@ contract TransmuterReentrantTest is Transmuter, ConfigAccessManager { if (mintedStables == 0) return; vm.startPrank(alice); - uint256 amountBurnt = agToken.balanceOf(alice); - (, uint256[] memory quoteAmounts) = transmuter.quoteRedemptionCurve(amountBurnt); + uint256 amountBurnt = tokenP.balanceOf(alice); + (, uint256[] memory quoteAmounts) = parallelizer.quoteRedemptionCurve(amountBurnt); if (quoteAmounts[0] == 0) return; - agToken.transfer(address(contractReentrantRedeemSwap), amountBurnt); + tokenP.transfer(address(contractReentrantRedeemSwap), amountBurnt); vm.expectRevert(Errors.ReentrantCall.selector); contractReentrantRedeemSwap.testERC777Reentrancy(amountBurnt); vm.stopPrank(); @@ -226,16 +225,16 @@ contract TransmuterReentrantTest is Transmuter, ConfigAccessManager { for (uint256 i; i < _collaterals.length; ++i) { initialAmounts[i] = bound(initialAmounts[i], 0, _maxTokenAmount[i]); deal(_collaterals[i], alice, initialAmounts[i]); - IERC20(_collaterals[i]).approve(address(transmuter), initialAmounts[i]); + IERC20(_collaterals[i]).approve(address(parallelizer), initialAmounts[i]); collateralMintedStables[i] = - transmuter.swapExactInput(initialAmounts[i], 0, _collaterals[i], address(agToken), alice, block.timestamp * 2); + parallelizer.swapExactInput(initialAmounts[i], 0, _collaterals[i], address(tokenP), alice, block.timestamp * 2); mintedStables += collateralMintedStables[i]; } // Send a proportion of these to another account user just to complexify the case transferProportion = bound(transferProportion, 0, BASE_9); - agToken.transfer(bob, (mintedStables * transferProportion) / BASE_9); + tokenP.transfer(bob, (mintedStables * transferProportion) / BASE_9); vm.stopPrank(); } } diff --git a/tests/units/Permit2.t.sol b/tests/units/Permit2.t.sol index 7994bb8..f7346b2 100644 --- a/tests/units/Permit2.t.sol +++ b/tests/units/Permit2.t.sol @@ -16,7 +16,7 @@ import "tests/mock/MockManager.sol"; import { IERC20 } from "tests/mock/MockTokenPermit.sol"; import { Permit2, SignatureVerification } from "tests/mock/Permit2.sol"; -import "contracts/transmuter/Storage.sol"; +import "contracts/parallelizer/Storage.sol"; import "contracts/utils/Errors.sol" as Errors; import "../Fixture.sol"; @@ -51,11 +51,11 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline }); - bytes memory sig = getPermitTransferSignature(permit, 2, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 2, DOMAIN_SEPARATOR, address(parallelizer)); vm.expectRevert(SignatureVerification.InvalidSigner.selector); startHoax(alice); - transmuter.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); + parallelizer.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); } function test_RevertWhen_SwapExactInputWithPermit_InvalidSender() public { @@ -69,11 +69,11 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); vm.expectRevert(SignatureVerification.InvalidSigner.selector); startHoax(bob); - transmuter.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); + parallelizer.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); } function test_RevertWhen_SwapExactInputWithPermit_InvalidDeadline() public { @@ -87,11 +87,11 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline - 1 }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); vm.expectRevert(SignatureVerification.InvalidSigner.selector); startHoax(bob); - transmuter.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); + parallelizer.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); } function test_RevertWhen_SwapExactInputWithPermit_InvalidNonce() public { @@ -105,11 +105,11 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline - 1 }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); vm.expectRevert(SignatureVerification.InvalidSigner.selector); startHoax(bob); - transmuter.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce + 1, sig)); + parallelizer.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce + 1, sig)); } function test_RevertWhen_SwapExactInputWithPermit_InvalidAmount() public { @@ -122,11 +122,11 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); vm.expectRevert(SignatureVerification.InvalidSigner.selector); startHoax(bob); - transmuter.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); + parallelizer.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); } function test_RevertWhen_SwapExactOutputWithPermit_InvalidAmount() public { @@ -143,11 +143,11 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); vm.expectRevert(SignatureVerification.InvalidSigner.selector); startHoax(alice); - transmuter.swapExactOutputWithPermit( + parallelizer.swapExactOutputWithPermit( amountOut, amountInMax, address(eurA), alice, deadline, abi.encode(nonce, sig) ); } @@ -163,14 +163,14 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); startHoax(alice); - transmuter.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); + parallelizer.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); - assertEq(agToken.balanceOf(alice), BASE_27 / (BASE_9 + BASE_9 / 99)); + assertEq(tokenP.balanceOf(alice), BASE_27 / (BASE_9 + BASE_9 / 99)); assertEq(eurA.balanceOf(alice), 0); - assertEq(eurA.balanceOf(address(transmuter)), BASE_6); + assertEq(eurA.balanceOf(address(parallelizer)), BASE_6); } function test_SwapExactOutputWithPermit() public { @@ -187,16 +187,16 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); startHoax(alice); - transmuter.swapExactOutputWithPermit( + parallelizer.swapExactOutputWithPermit( amountOut, amountInMax, address(eurA), alice, deadline, abi.encode(nonce, sig) ); - assertEq(agToken.balanceOf(alice), BASE_18); + assertEq(tokenP.balanceOf(alice), BASE_18); assertEq(eurA.balanceOf(alice), amountInMax - amountIn); - assertEq(eurA.balanceOf(address(transmuter)), amountIn); + assertEq(eurA.balanceOf(address(parallelizer)), amountIn); } function test_SwapExactInputWithPermitAndManager() public { @@ -210,7 +210,7 @@ contract Permit2Test is Fixture, FunctionUtils { manager.setSubCollaterals(data.subCollaterals, data.config); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); // Test deal(address(eurA), alice, BASE_6); @@ -223,12 +223,12 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); startHoax(alice); - transmuter.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); + parallelizer.swapExactInputWithPermit(BASE_6, 0, address(eurA), alice, deadline, abi.encode(nonce, sig)); - assertEq(agToken.balanceOf(alice), BASE_27 / (BASE_9 + BASE_9 / 99)); + assertEq(tokenP.balanceOf(alice), BASE_27 / (BASE_9 + BASE_9 / 99)); assertEq(eurA.balanceOf(alice), 0); assertEq(eurA.balanceOf(address(manager)), BASE_6); } @@ -244,7 +244,7 @@ contract Permit2Test is Fixture, FunctionUtils { manager.setSubCollaterals(data.subCollaterals, data.config); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); // Test uint256 amountOut = BASE_18; @@ -260,14 +260,14 @@ contract Permit2Test is Fixture, FunctionUtils { nonce: nonce, deadline: deadline }); - bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(transmuter)); + bytes memory sig = getPermitTransferSignature(permit, 1, DOMAIN_SEPARATOR, address(parallelizer)); startHoax(alice); - transmuter.swapExactOutputWithPermit( + parallelizer.swapExactOutputWithPermit( amountOut, amountInMax, address(eurA), alice, deadline, abi.encode(nonce, sig) ); - assertEq(agToken.balanceOf(alice), BASE_18); + assertEq(tokenP.balanceOf(alice), BASE_18); assertEq(eurA.balanceOf(alice), amountInMax - amountIn); assertEq(eurA.balanceOf(address(manager)), amountIn); } diff --git a/tests/units/RewardHandlerTest.t.sol b/tests/units/RewardHandlerTest.t.sol index 4039063..a6082b2 100644 --- a/tests/units/RewardHandlerTest.t.sol +++ b/tests/units/RewardHandlerTest.t.sol @@ -9,7 +9,7 @@ import { stdError } from "@forge-std/Test.sol"; import { MockOneInchRouter } from "tests/mock/MockOneInchRouter.sol"; import { MockTokenPermit } from "tests/mock/MockTokenPermit.sol"; -import "contracts/transmuter/Storage.sol"; +import "contracts/parallelizer/Storage.sol"; import "contracts/utils/Errors.sol" as Errors; import "../Fixture.sol"; @@ -36,7 +36,7 @@ contract RewardHandlerTest is Fixture { startHoax(alice); vm.expectRevert(Errors.NotTrusted.selector); bytes memory data; - transmuter.sellRewards(0, data); + parallelizer.sellRewards(0, data); } function test_RevertWhen_SellRewards_NoApproval() public { @@ -44,7 +44,7 @@ contract RewardHandlerTest is Fixture { bytes memory payload = abi.encodeWithSelector(MockOneInchRouter.swap.selector, 100, 100, address(tokenA), address(tokenB)); vm.expectRevert(); - transmuter.sellRewards(0, payload); + parallelizer.sellRewards(0, payload); vm.stopPrank(); } @@ -53,11 +53,11 @@ contract RewardHandlerTest is Fixture { abi.encodeWithSelector(MockOneInchRouter.swap.selector, 100, 100, address(tokenA), address(tokenB)); vm.startPrank(governor); - deal(address(tokenA), address(transmuter), 100); + deal(address(tokenA), address(parallelizer), 100); deal(address(tokenB), address(oneInch), 100); - transmuter.changeAllowance(tokenA, address(oneInch), 100); + parallelizer.changeAllowance(tokenA, address(oneInch), 100); vm.expectRevert(Errors.InvalidSwap.selector); - transmuter.sellRewards(0, payload); + parallelizer.sellRewards(0, payload); vm.stopPrank(); } @@ -66,11 +66,11 @@ contract RewardHandlerTest is Fixture { abi.encodeWithSelector(MockOneInchRouter.swap.selector, 100, 100, address(tokenA), address(tokenB)); vm.startPrank(governor); - deal(address(tokenA), address(transmuter), 100); + deal(address(tokenA), address(parallelizer), 100); deal(address(tokenB), address(oneInch), 100); - transmuter.changeAllowance(tokenA, address(oneInch), 100); + parallelizer.changeAllowance(tokenA, address(oneInch), 100); vm.expectRevert(Errors.TooSmallAmountOut.selector); - transmuter.sellRewards(1000, payload); + parallelizer.sellRewards(1000, payload); vm.stopPrank(); } @@ -79,12 +79,12 @@ contract RewardHandlerTest is Fixture { abi.encodeWithSelector(MockOneInchRouter.swap.selector, 100, 100, address(tokenA), address(tokenB)); vm.startPrank(governor); - deal(address(tokenA), address(transmuter), 100); + deal(address(tokenA), address(parallelizer), 100); deal(address(tokenB), address(oneInch), 100); - transmuter.changeAllowance(tokenA, address(oneInch), 100); + parallelizer.changeAllowance(tokenA, address(oneInch), 100); oneInch.setRevertStatuses(true, false); vm.expectRevert(Errors.OneInchSwapFailed.selector); - transmuter.sellRewards(0, payload); + parallelizer.sellRewards(0, payload); vm.stopPrank(); } @@ -93,12 +93,12 @@ contract RewardHandlerTest is Fixture { abi.encodeWithSelector(MockOneInchRouter.swap.selector, 100, 100, address(tokenA), address(tokenB)); vm.startPrank(governor); - deal(address(tokenA), address(transmuter), 100); + deal(address(tokenA), address(parallelizer), 100); deal(address(tokenB), address(oneInch), 100); - transmuter.changeAllowance(tokenA, address(oneInch), 100); + parallelizer.changeAllowance(tokenA, address(oneInch), 100); oneInch.setRevertStatuses(false, true); vm.expectRevert("wrong swap"); - transmuter.sellRewards(0, payload); + parallelizer.sellRewards(0, payload); vm.stopPrank(); } @@ -107,11 +107,11 @@ contract RewardHandlerTest is Fixture { abi.encodeWithSelector(MockOneInchRouter.swap.selector, 100, 100, address(eurA), address(eurB)); vm.startPrank(governor); - deal(address(eurA), address(transmuter), 100); + deal(address(eurA), address(parallelizer), 100); deal(address(eurB), address(oneInch), 100); - transmuter.changeAllowance(eurA, address(oneInch), 100); + parallelizer.changeAllowance(eurA, address(oneInch), 100); vm.expectRevert(Errors.InvalidSwap.selector); - transmuter.sellRewards(0, payload); + parallelizer.sellRewards(0, payload); vm.stopPrank(); } @@ -120,12 +120,12 @@ contract RewardHandlerTest is Fixture { abi.encodeWithSelector(MockOneInchRouter.swap.selector, 100, 100, address(tokenA), address(eurA)); vm.startPrank(governor); - deal(address(tokenA), address(transmuter), 100); + deal(address(tokenA), address(parallelizer), 100); deal(address(eurA), address(oneInch), 100); - transmuter.changeAllowance(tokenA, address(oneInch), 100); - vm.expectEmit(address(transmuter)); + parallelizer.changeAllowance(tokenA, address(oneInch), 100); + vm.expectEmit(address(parallelizer)); emit RewardsSoldFor(address(eurA), 100); - transmuter.sellRewards(0, payload); + parallelizer.sellRewards(0, payload); vm.stopPrank(); } @@ -133,16 +133,16 @@ contract RewardHandlerTest is Fixture { bytes memory payload = abi.encodeWithSelector(MockOneInchRouter.swap.selector, 100, 100, address(tokenA), address(eurA)); vm.startPrank(governor); - transmuter.toggleTrusted(alice, TrustedType.Seller); - transmuter.changeAllowance(tokenA, address(oneInch), 100); + parallelizer.toggleTrusted(alice, TrustedType.Seller); + parallelizer.changeAllowance(tokenA, address(oneInch), 100); vm.stopPrank(); - deal(address(tokenA), address(transmuter), 100); + deal(address(tokenA), address(parallelizer), 100); deal(address(eurA), address(oneInch), 100); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit RewardsSoldFor(address(eurA), 100); vm.prank(alice); - transmuter.sellRewards(0, payload); + parallelizer.sellRewards(0, payload); } } diff --git a/tests/units/Savings.t.sol b/tests/units/Savings.t.sol index 6f16660..251d9e2 100644 --- a/tests/units/Savings.t.sol +++ b/tests/units/Savings.t.sol @@ -19,7 +19,7 @@ contract SavingsNameableUpgradeTest is Fixture { function setUp() public override { super.setUp(); vm.startPrank(governor); - deal({ token: address(agToken), to: governor, give: 1e18 }); + deal({ token: address(tokenP), to: governor, give: 1e18 }); SavingsNameable savingsImpl = new SavingsNameable(); @@ -27,14 +27,14 @@ contract SavingsNameableUpgradeTest is Fixture { address futureProxyAddress = vm.computeCreateAddress(governor, vm.getNonce(governor)); // Pre-approve the future proxy address - agToken.approve(futureProxyAddress, 1e18); + tokenP.approve(futureProxyAddress, 1e18); saving = SavingsNameable( address( new ERC1967Proxy( address(savingsImpl), abi.encodeWithSelector( - savingsImpl.initialize.selector, accessManager, IERC20Metadata(address(agToken)), name, symbol, 1 + savingsImpl.initialize.selector, accessManager, IERC20Metadata(address(tokenP)), name, symbol, 1 ) ) ) diff --git a/tests/units/Setters.t.sol b/tests/units/Setters.t.sol index 64e1ba2..9086c01 100644 --- a/tests/units/Setters.t.sol +++ b/tests/units/Setters.t.sol @@ -7,10 +7,10 @@ import { stdError } from "@forge-std/Test.sol"; import "tests/mock/MockManager.sol"; import { MockKeyringGuard } from "tests/mock/MockKeyringGuard.sol"; -import "contracts/transmuter/Storage.sol"; -import { Test } from "contracts/transmuter/configs/Test.sol"; -import { DiamondCut } from "contracts/transmuter/facets/DiamondCut.sol"; -import { LibSetters } from "contracts/transmuter/libraries/LibSetters.sol"; +import "contracts/parallelizer/Storage.sol"; +import { Test } from "contracts/parallelizer/configs/Test.sol"; +import { DiamondCut } from "contracts/parallelizer/facets/DiamondCut.sol"; +import { LibSetters } from "contracts/parallelizer/libraries/LibSetters.sol"; import "contracts/utils/Constants.sol"; import "contracts/utils/Errors.sol" as Errors; @@ -20,69 +20,69 @@ contract Test_Setters_TogglePause is Fixture { function test_RevertWhen_NotGuardian() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, governor)); hoax(governor); - transmuter.togglePause(address(eurA), ActionType.Mint); + parallelizer.togglePause(address(eurA), ActionType.Mint); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.togglePause(address(eurA), ActionType.Mint); + parallelizer.togglePause(address(eurA), ActionType.Mint); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, bob)); hoax(bob); - transmuter.togglePause(address(eurA), ActionType.Mint); + parallelizer.togglePause(address(eurA), ActionType.Mint); } function test_RevertWhen_NotCollateral() public { vm.expectRevert(Errors.NotCollateral.selector); hoax(guardian); - transmuter.togglePause(address(agToken), ActionType.Mint); + parallelizer.togglePause(address(tokenP), ActionType.Mint); } function test_PauseMint() public { - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.PauseToggled(address(eurA), uint256(ActionType.Mint), true); hoax(guardian); - transmuter.togglePause(address(eurA), ActionType.Mint); + parallelizer.togglePause(address(eurA), ActionType.Mint); - assert(transmuter.isPaused(address(eurA), ActionType.Mint)); + assert(parallelizer.isPaused(address(eurA), ActionType.Mint)); vm.expectRevert(Errors.Paused.selector); - transmuter.swapExactInput(1 ether, 1 ether, address(eurA), address(agToken), alice, block.timestamp + 10); + parallelizer.swapExactInput(1 ether, 1 ether, address(eurA), address(tokenP), alice, block.timestamp + 10); vm.expectRevert(Errors.Paused.selector); - transmuter.swapExactOutput(1 ether, 1 ether, address(eurA), address(agToken), alice, block.timestamp + 10); + parallelizer.swapExactOutput(1 ether, 1 ether, address(eurA), address(tokenP), alice, block.timestamp + 10); } function test_PauseBurn() public { - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.PauseToggled(address(eurA), uint256(ActionType.Burn), true); hoax(guardian); - transmuter.togglePause(address(eurA), ActionType.Burn); + parallelizer.togglePause(address(eurA), ActionType.Burn); - assert(transmuter.isPaused(address(eurA), ActionType.Burn)); + assert(parallelizer.isPaused(address(eurA), ActionType.Burn)); vm.expectRevert(Errors.Paused.selector); - transmuter.swapExactInput(1 ether, 1 ether, address(agToken), address(eurA), alice, block.timestamp + 10); + parallelizer.swapExactInput(1 ether, 1 ether, address(tokenP), address(eurA), alice, block.timestamp + 10); vm.expectRevert(Errors.Paused.selector); - transmuter.swapExactOutput(1 ether, 1 ether, address(agToken), address(eurA), alice, block.timestamp + 10); + parallelizer.swapExactOutput(1 ether, 1 ether, address(tokenP), address(eurA), alice, block.timestamp + 10); } function test_PauseRedeem() public { - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.PauseToggled(address(eurA), uint256(ActionType.Redeem), true); hoax(guardian); - transmuter.togglePause(address(eurA), ActionType.Redeem); + parallelizer.togglePause(address(eurA), ActionType.Redeem); - assert(transmuter.isPaused(address(eurA), ActionType.Redeem)); + assert(parallelizer.isPaused(address(eurA), ActionType.Redeem)); vm.expectRevert(Errors.Paused.selector); - transmuter.redeem(1 ether, alice, block.timestamp + 10, new uint256[](3)); + parallelizer.redeem(1 ether, alice, block.timestamp + 10, new uint256[](3)); vm.expectRevert(Errors.Paused.selector); - transmuter.redeemWithForfeit(1 ether, alice, block.timestamp + 10, new uint256[](3), new address[](0)); + parallelizer.redeemWithForfeit(1 ether, alice, block.timestamp + 10, new uint256[](3), new address[](0)); } } @@ -93,15 +93,15 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, governor)); hoax(governor); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, bob)); hoax(bob); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); } function test_RevertWhen_NotCollateral() public { @@ -110,7 +110,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.NotCollateral.selector); hoax(guardian); - transmuter.setFees(address(agToken), xFee, yFee, true); + parallelizer.setFees(address(tokenP), xFee, yFee, true); } function test_RevertWhen_InvalidParamsLength0() public { @@ -119,7 +119,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); } function test_RevertWhen_InvalidParamsDifferentLength() public { @@ -128,7 +128,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); } function test_RevertWhen_InvalidParamsMint() public { @@ -139,21 +139,21 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); xFee[3] = uint64(BASE_9 - 1); xFee[0] = uint64(1); // xFee[0] != 0 vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); xFee[0] = 0; yFee[3] = int64(int256(BASE_12 + 1)); // yFee[n - 1] > BASE_12 vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); } function test_RevertWhen_InvalidParamsMintIncreases() public { @@ -170,7 +170,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); xFee[0] = 0; xFee[1] = uint64(BASE_9 / 10); @@ -182,7 +182,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); } function test_RevertWhen_OnlyGovernorWithGuardianRoleNegativeFees() public { @@ -198,7 +198,7 @@ contract Test_Setters_SetFees is Fixture { yFee[2] = int64(uint64(BASE_9 / 10)); hoax(governorAndGuardian); - transmuter.setFees(address(eurB), xFee, yFee, false); + parallelizer.setFees(address(eurB), xFee, yFee, false); xFee[0] = 0; xFee[1] = uint64(BASE_9 / 10); @@ -210,11 +210,11 @@ contract Test_Setters_SetFees is Fixture { hoax(governor); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, governor)); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); hoax(guardian); vm.expectRevert(abi.encodeWithSelector(Errors.NotGovernor.selector)); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); } function test_RevertWhen_InvalidNegativeFeesMint() public { @@ -230,7 +230,7 @@ contract Test_Setters_SetFees is Fixture { yFee[2] = int64(uint64(BASE_9 / 10)); hoax(governorAndGuardian); - transmuter.setFees(address(eurB), xFee, yFee, false); + parallelizer.setFees(address(eurB), xFee, yFee, false); xFee[0] = 0; xFee[1] = uint64(BASE_9 / 10); @@ -242,7 +242,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidNegativeFees.selector); hoax(governorAndGuardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); } function test_RevertWhen_InvalidParamsBurn() public { @@ -259,7 +259,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(governorAndGuardian); - transmuter.setFees(address(eurA), xFee, yFee, false); + parallelizer.setFees(address(eurA), xFee, yFee, false); xFee[0] = uint64(BASE_9); xFee[1] = uint64(BASE_9 / 10); @@ -271,7 +271,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(governorAndGuardian); - transmuter.setFees(address(eurA), xFee, yFee, false); + parallelizer.setFees(address(eurA), xFee, yFee, false); xFee[0] = uint64(BASE_9); xFee[1] = uint64(BASE_9 / 10); @@ -283,7 +283,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(governorAndGuardian); - transmuter.setFees(address(eurA), xFee, yFee, false); + parallelizer.setFees(address(eurA), xFee, yFee, false); } function test_RevertWhen_InvalidParamsBurnIncreases() public { @@ -300,7 +300,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(governorAndGuardian); - transmuter.setFees(address(eurA), xFee, yFee, false); + parallelizer.setFees(address(eurA), xFee, yFee, false); xFee[0] = uint64(BASE_9); xFee[1] = uint64(BASE_9 / 10); @@ -312,7 +312,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(governorAndGuardian); - transmuter.setFees(address(eurA), xFee, yFee, false); + parallelizer.setFees(address(eurA), xFee, yFee, false); } function test_RevertWhen_InvalidNegativeFeesBurn() public { @@ -328,7 +328,7 @@ contract Test_Setters_SetFees is Fixture { yFee[2] = int64(uint64((2 * BASE_9) / 10)); hoax(governorAndGuardian); - transmuter.setFees(address(eurB), xFee, yFee, true); + parallelizer.setFees(address(eurB), xFee, yFee, true); xFee[0] = uint64(BASE_9); xFee[1] = uint64(BASE_9 / 10); @@ -340,7 +340,7 @@ contract Test_Setters_SetFees is Fixture { vm.expectRevert(Errors.InvalidNegativeFees.selector); hoax(governorAndGuardian); - transmuter.setFees(address(eurA), xFee, yFee, false); + parallelizer.setFees(address(eurA), xFee, yFee, false); } function test_Mint() public { @@ -355,13 +355,13 @@ contract Test_Setters_SetFees is Fixture { yFee[1] = int64(uint64(BASE_9 / 10)); yFee[2] = int64(uint64((2 * BASE_9) / 10)); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.FeesSet(address(eurA), xFee, yFee, true); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, true); + parallelizer.setFees(address(eurA), xFee, yFee, true); - (uint64[] memory xFeeMint, int64[] memory yFeeMint) = transmuter.getCollateralMintFees(address(eurA)); + (uint64[] memory xFeeMint, int64[] memory yFeeMint) = parallelizer.getCollateralMintFees(address(eurA)); for (uint256 i = 0; i < 3; ++i) { assertEq(xFeeMint[i], xFee[i]); assertEq(yFeeMint[i], yFee[i]); @@ -380,13 +380,13 @@ contract Test_Setters_SetFees is Fixture { yFee[1] = int64(1); yFee[2] = int64(uint64(BASE_9 / 10)); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.FeesSet(address(eurA), xFee, yFee, false); hoax(guardian); - transmuter.setFees(address(eurA), xFee, yFee, false); + parallelizer.setFees(address(eurA), xFee, yFee, false); - (uint64[] memory xFeeBurn, int64[] memory yFeeBurn) = transmuter.getCollateralBurnFees(address(eurA)); + (uint64[] memory xFeeBurn, int64[] memory yFeeBurn) = parallelizer.getCollateralBurnFees(address(eurA)); for (uint256 i = 0; i < 3; ++i) { assertEq(xFeeBurn[i], xFee[i]); assertEq(yFeeBurn[i], yFee[i]); @@ -403,15 +403,15 @@ contract Test_Setters_SetRedemptionCurveParams is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, governor)); hoax(governor); - transmuter.setRedemptionCurveParams(xFee, yFee); + parallelizer.setRedemptionCurveParams(xFee, yFee); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setRedemptionCurveParams(xFee, yFee); + parallelizer.setRedemptionCurveParams(xFee, yFee); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, bob)); hoax(bob); - transmuter.setRedemptionCurveParams(xFee, yFee); + parallelizer.setRedemptionCurveParams(xFee, yFee); } function test_RevertWhen_InvalidParams() public { @@ -428,7 +428,7 @@ contract Test_Setters_SetRedemptionCurveParams is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setRedemptionCurveParams(xFee, yFee); + parallelizer.setRedemptionCurveParams(xFee, yFee); } function test_RevertWhen_InvalidParamsWhenDecreases() public { @@ -445,7 +445,7 @@ contract Test_Setters_SetRedemptionCurveParams is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setRedemptionCurveParams(xFee, yFee); + parallelizer.setRedemptionCurveParams(xFee, yFee); xFee[0] = uint64(0); xFee[1] = uint64(1); @@ -457,7 +457,7 @@ contract Test_Setters_SetRedemptionCurveParams is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setRedemptionCurveParams(xFee, yFee); + parallelizer.setRedemptionCurveParams(xFee, yFee); xFee[0] = uint64(0); xFee[1] = uint64(1); @@ -469,7 +469,7 @@ contract Test_Setters_SetRedemptionCurveParams is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(guardian); - transmuter.setRedemptionCurveParams(xFee, yFee); + parallelizer.setRedemptionCurveParams(xFee, yFee); } function test_Success() public { @@ -484,13 +484,13 @@ contract Test_Setters_SetRedemptionCurveParams is Fixture { yFee[1] = int64(2); yFee[2] = int64(3); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit RedemptionCurveParamsSet(xFee, yFee); hoax(guardian); - transmuter.setRedemptionCurveParams(xFee, yFee); + parallelizer.setRedemptionCurveParams(xFee, yFee); - (uint64[] memory xRedemptionCurve, int64[] memory yRedemptionCurve) = transmuter.getRedemptionFees(); + (uint64[] memory xRedemptionCurve, int64[] memory yRedemptionCurve) = parallelizer.getRedemptionFees(); for (uint256 i = 0; i < 3; ++i) { assertEq(xRedemptionCurve[i], xFee[i]); assertEq(yRedemptionCurve[i], yFee[i]); @@ -504,18 +504,18 @@ contract Test_Setters_RecoverERC20 is Fixture { function test_RevertWhen_NotGovernor() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.recoverERC20(address(agToken), agToken, alice, 1 ether); + parallelizer.recoverERC20(address(tokenP), tokenP, alice, 1 ether); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.recoverERC20(address(agToken), agToken, alice, 1 ether); + parallelizer.recoverERC20(address(tokenP), tokenP, alice, 1 ether); } function test_Success() public { - deal(address(eurA), address(transmuter), 1 ether); + deal(address(eurA), address(parallelizer), 1 ether); hoax(governor); - transmuter.recoverERC20(address(eurA), eurA, alice, 1 ether); + parallelizer.recoverERC20(address(eurA), eurA, alice, 1 ether); assertEq(eurA.balanceOf(alice), 1 ether); } @@ -530,19 +530,19 @@ contract Test_Setters_RecoverERC20 is Fixture { manager.setSubCollaterals(data.subCollaterals, data.config); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); deal(address(eurA), address(manager), 1 ether); hoax(governor); - transmuter.recoverERC20(address(eurA), eurA, alice, 1 ether); + parallelizer.recoverERC20(address(eurA), eurA, alice, 1 ether); assertEq(eurA.balanceOf(alice), 1 ether); deal(address(eurB), address(manager), 1 ether); hoax(governor); - transmuter.recoverERC20(address(eurA), eurB, alice, 1 ether); + parallelizer.recoverERC20(address(eurA), eurB, alice, 1 ether); assertEq(eurB.balanceOf(alice), 1 ether); } @@ -552,23 +552,23 @@ contract Test_Setters_SetAccessManager is Fixture { function test_RevertWhen_NonGovernor() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setAccessManager(alice); + parallelizer.setAccessManager(alice); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.setAccessManager(alice); + parallelizer.setAccessManager(alice); } function test_Success() public { - address oldAccessManager = address(transmuter.accessManager()); + address oldAccessManager = address(parallelizer.accessManager()); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.OwnershipTransferred(oldAccessManager, alice); hoax(governor); - transmuter.setAccessManager(alice); + parallelizer.setAccessManager(alice); - assertEq(transmuter.accessManager(), alice); + assertEq(parallelizer.accessManager(), alice); } } @@ -578,47 +578,47 @@ contract Test_Setters_ToggleTrusted is Fixture { function test_RevertWhen_NotGovernor() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.toggleTrusted(alice, TrustedType.Seller); + parallelizer.toggleTrusted(alice, TrustedType.Seller); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.toggleTrusted(alice, TrustedType.Seller); + parallelizer.toggleTrusted(alice, TrustedType.Seller); } function test_Seller() public { - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit TrustedToggled(alice, true, TrustedType.Seller); hoax(governor); - transmuter.toggleTrusted(alice, TrustedType.Seller); + parallelizer.toggleTrusted(alice, TrustedType.Seller); - assert(transmuter.isTrustedSeller(alice)); + assert(parallelizer.isTrustedSeller(alice)); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit TrustedToggled(alice, false, TrustedType.Seller); hoax(governor); - transmuter.toggleTrusted(alice, TrustedType.Seller); + parallelizer.toggleTrusted(alice, TrustedType.Seller); - assert(!transmuter.isTrustedSeller(alice)); + assert(!parallelizer.isTrustedSeller(alice)); } function test_Updater() public { - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit TrustedToggled(alice, true, TrustedType.Updater); hoax(governor); - transmuter.toggleTrusted(alice, TrustedType.Updater); + parallelizer.toggleTrusted(alice, TrustedType.Updater); - assert(transmuter.isTrusted(alice)); + assert(parallelizer.isTrusted(alice)); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit TrustedToggled(alice, false, TrustedType.Updater); hoax(governor); - transmuter.toggleTrusted(alice, TrustedType.Updater); + parallelizer.toggleTrusted(alice, TrustedType.Updater); - assert(!transmuter.isTrusted(alice)); + assert(!parallelizer.isTrusted(alice)); } } @@ -628,11 +628,11 @@ contract Test_Setters_SetWhitelistStatus is Fixture { bytes memory whitelistData = abi.encode(WhitelistType.BACKED, emptyData); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.setWhitelistStatus(address(eurA), 1, whitelistData); + parallelizer.setWhitelistStatus(address(eurA), 1, whitelistData); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setWhitelistStatus(address(eurA), 1, whitelistData); + parallelizer.setWhitelistStatus(address(eurA), 1, whitelistData); } function test_RevertWhen_NotCollateral() public { @@ -640,85 +640,85 @@ contract Test_Setters_SetWhitelistStatus is Fixture { bytes memory whitelistData = abi.encode(WhitelistType.BACKED, emptyData); vm.expectRevert(Errors.NotCollateral.selector); hoax(governor); - transmuter.setWhitelistStatus(address(this), 1, whitelistData); + parallelizer.setWhitelistStatus(address(this), 1, whitelistData); } function test_RevertWhen_InvalidWhitelistData() public { bytes memory whitelistData = abi.encode(3, 4); vm.expectRevert(); hoax(governor); - transmuter.setWhitelistStatus(address(this), 1, whitelistData); + parallelizer.setWhitelistStatus(address(this), 1, whitelistData); } function test_SetPositiveStatus() public { bytes memory emptyData; bytes memory whitelistData = abi.encode(WhitelistType.BACKED, emptyData); - assert(!transmuter.isWhitelistedCollateral(address(eurA))); - assertEq(transmuter.getCollateralWhitelistData(address(eurA)), emptyData); + assert(!parallelizer.isWhitelistedCollateral(address(eurA))); + assertEq(parallelizer.getCollateralWhitelistData(address(eurA)), emptyData); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.CollateralWhitelistStatusUpdated(address(eurA), whitelistData, 1); hoax(governor); - transmuter.setWhitelistStatus(address(eurA), 1, whitelistData); + parallelizer.setWhitelistStatus(address(eurA), 1, whitelistData); - assert(transmuter.isWhitelistedCollateral(address(eurA))); - assertEq(transmuter.getCollateralWhitelistData(address(eurA)), whitelistData); + assert(parallelizer.isWhitelistedCollateral(address(eurA))); + assertEq(parallelizer.getCollateralWhitelistData(address(eurA)), whitelistData); } function test_SetPositiveStatusThroughNonEmptyData() public { MockKeyringGuard keyringGuard = new MockKeyringGuard(); bytes memory whitelistData = abi.encode(WhitelistType.BACKED, abi.encode(address(0))); - assert(!transmuter.isWhitelistedCollateral(address(eurA))); + assert(!parallelizer.isWhitelistedCollateral(address(eurA))); bytes memory emptyData; - assertEq(transmuter.getCollateralWhitelistData(address(eurA)), emptyData); + assertEq(parallelizer.getCollateralWhitelistData(address(eurA)), emptyData); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.CollateralWhitelistStatusUpdated(address(eurA), whitelistData, 1); hoax(governor); - transmuter.setWhitelistStatus(address(eurA), 1, whitelistData); + parallelizer.setWhitelistStatus(address(eurA), 1, whitelistData); - assert(transmuter.isWhitelistedCollateral(address(eurA))); - assertEq(transmuter.getCollateralWhitelistData(address(eurA)), whitelistData); + assert(parallelizer.isWhitelistedCollateral(address(eurA))); + assertEq(parallelizer.getCollateralWhitelistData(address(eurA)), whitelistData); - assert(!transmuter.isWhitelistedForCollateral(address(eurA), address(bob))); + assert(!parallelizer.isWhitelistedForCollateral(address(eurA), address(bob))); whitelistData = abi.encode(WhitelistType.BACKED, abi.encode(address(keyringGuard))); hoax(governor); - transmuter.setWhitelistStatus(address(eurA), 1, whitelistData); - assertEq(transmuter.getCollateralWhitelistData(address(eurA)), whitelistData); - assert(transmuter.isWhitelistedCollateral(address(eurA))); + parallelizer.setWhitelistStatus(address(eurA), 1, whitelistData); + assertEq(parallelizer.getCollateralWhitelistData(address(eurA)), whitelistData); + assert(parallelizer.isWhitelistedCollateral(address(eurA))); keyringGuard.setAuthorized(address(bob), true); - assert(transmuter.isWhitelistedForCollateral(address(eurA), address(bob))); + assert(parallelizer.isWhitelistedForCollateral(address(eurA), address(bob))); keyringGuard.setAuthorized(address(bob), false); - assert(!transmuter.isWhitelistedForCollateral(address(eurA), address(bob))); + assert(!parallelizer.isWhitelistedForCollateral(address(eurA), address(bob))); } function test_SetNegativeStatus() public { bytes memory emptyData; bytes memory whitelistData = abi.encode(WhitelistType.BACKED, emptyData); - assert(!transmuter.isWhitelistedCollateral(address(eurA))); - assertEq(transmuter.getCollateralWhitelistData(address(eurA)), emptyData); + assert(!parallelizer.isWhitelistedCollateral(address(eurA))); + assertEq(parallelizer.getCollateralWhitelistData(address(eurA)), emptyData); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.CollateralWhitelistStatusUpdated(address(eurA), whitelistData, 1); hoax(governor); - transmuter.setWhitelistStatus(address(eurA), 1, whitelistData); + parallelizer.setWhitelistStatus(address(eurA), 1, whitelistData); - assert(transmuter.isWhitelistedCollateral(address(eurA))); - assertEq(transmuter.getCollateralWhitelistData(address(eurA)), whitelistData); + assert(parallelizer.isWhitelistedCollateral(address(eurA))); + assertEq(parallelizer.getCollateralWhitelistData(address(eurA)), whitelistData); bytes memory whitelistData2 = abi.encode(WhitelistType.BACKED, emptyData); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit LibSetters.CollateralWhitelistStatusUpdated(address(eurA), whitelistData2, 0); hoax(governor); - transmuter.setWhitelistStatus(address(eurA), 0, whitelistData2); + parallelizer.setWhitelistStatus(address(eurA), 0, whitelistData2); - assert(!transmuter.isWhitelistedCollateral(address(eurA))); - assertEq(transmuter.getCollateralWhitelistData(address(eurA)), whitelistData); + assert(!parallelizer.isWhitelistedCollateral(address(eurA))); + assertEq(parallelizer.getCollateralWhitelistData(address(eurA)), whitelistData); } } @@ -728,54 +728,54 @@ contract Test_Setters_ToggleWhitelist is Fixture { function test_RevertWhen_NonGuardian() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.toggleWhitelist(WhitelistType.BACKED, address(alice)); + parallelizer.toggleWhitelist(WhitelistType.BACKED, address(alice)); } function test_WhitelistSet() public { - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit WhitelistStatusToggled(WhitelistType.BACKED, address(alice), 1); hoax(guardian); - transmuter.toggleWhitelist(WhitelistType.BACKED, address(alice)); + parallelizer.toggleWhitelist(WhitelistType.BACKED, address(alice)); - assert(transmuter.isWhitelistedForType(WhitelistType.BACKED, address(alice))); + assert(parallelizer.isWhitelistedForType(WhitelistType.BACKED, address(alice))); } function test_WhitelistUnset() public { - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit WhitelistStatusToggled(WhitelistType.BACKED, address(alice), 1); hoax(guardian); - transmuter.toggleWhitelist(WhitelistType.BACKED, address(alice)); + parallelizer.toggleWhitelist(WhitelistType.BACKED, address(alice)); - assert(transmuter.isWhitelistedForType(WhitelistType.BACKED, address(alice))); + assert(parallelizer.isWhitelistedForType(WhitelistType.BACKED, address(alice))); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit WhitelistStatusToggled(WhitelistType.BACKED, address(alice), 0); hoax(guardian); - transmuter.toggleWhitelist(WhitelistType.BACKED, address(alice)); + parallelizer.toggleWhitelist(WhitelistType.BACKED, address(alice)); - assert(!transmuter.isWhitelistedForType(WhitelistType.BACKED, address(alice))); + assert(!parallelizer.isWhitelistedForType(WhitelistType.BACKED, address(alice))); } function test_WhitelistSetOnCollateral() public { - assert(transmuter.isWhitelistedForCollateral(address(eurA), address(alice))); - vm.expectEmit(address(transmuter)); + assert(parallelizer.isWhitelistedForCollateral(address(eurA), address(alice))); + vm.expectEmit(address(parallelizer)); emit WhitelistStatusToggled(WhitelistType.BACKED, address(alice), 1); hoax(guardian); - transmuter.toggleWhitelist(WhitelistType.BACKED, address(alice)); + parallelizer.toggleWhitelist(WhitelistType.BACKED, address(alice)); - assert(transmuter.isWhitelistedForType(WhitelistType.BACKED, address(alice))); - assert(transmuter.isWhitelistedForCollateral(address(eurA), address(alice))); + assert(parallelizer.isWhitelistedForType(WhitelistType.BACKED, address(alice))); + assert(parallelizer.isWhitelistedForCollateral(address(eurA), address(alice))); bytes memory emptyData; bytes memory whitelistData = abi.encode(WhitelistType.BACKED, emptyData); hoax(governor); - transmuter.setWhitelistStatus(address(eurA), 1, whitelistData); + parallelizer.setWhitelistStatus(address(eurA), 1, whitelistData); - assert(transmuter.isWhitelistedForCollateral(address(eurA), address(alice))); + assert(parallelizer.isWhitelistedForCollateral(address(eurA), address(alice))); hoax(guardian); - transmuter.toggleWhitelist(WhitelistType.BACKED, address(alice)); - assert(!transmuter.isWhitelistedForCollateral(address(eurA), address(alice))); + parallelizer.toggleWhitelist(WhitelistType.BACKED, address(alice)); + assert(!parallelizer.isWhitelistedForCollateral(address(eurA), address(alice))); } } @@ -784,21 +784,21 @@ contract Test_Setters_UpdateNormalizer is Fixture { function test_RevertWhen_NotTrusted() public { vm.expectRevert(Errors.NotTrusted.selector); - transmuter.updateNormalizer(1 ether, true); + parallelizer.updateNormalizer(1 ether, true); vm.expectRevert(Errors.NotTrusted.selector); hoax(alice); - transmuter.updateNormalizer(1 ether, true); + parallelizer.updateNormalizer(1 ether, true); vm.expectRevert(Errors.NotTrusted.selector); hoax(guardian); - transmuter.updateNormalizer(1 ether, true); + parallelizer.updateNormalizer(1 ether, true); } function test_RevertWhen_ZeroAmountNormalizedStables() public { vm.expectRevert(); // Should be a division by 0 hoax(governor); - transmuter.updateNormalizer(1, true); + parallelizer.updateNormalizer(1, true); } function test_RevertWhen_InvalidUpdate() public { @@ -807,26 +807,26 @@ contract Test_Setters_UpdateNormalizer is Fixture { vm.expectRevert(stdError.arithmeticError); // Should be an underflow hoax(governor); - transmuter.updateNormalizer(4 ether, false); + parallelizer.updateNormalizer(4 ether, false); } function test_UpdateByGovernor() public { _mintExactOutput(alice, address(eurA), 1 ether, 1 ether); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit NormalizerUpdated(2 * BASE_27); hoax(governor); - transmuter.updateNormalizer(1 ether, true); + parallelizer.updateNormalizer(1 ether, true); - (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurA)); + (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurA)); assertEq(stablecoinsFromCollateral, 2 ether); assertEq(stablecoinsIssued, 2 ether); uint256 normalizer = - uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; + uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; uint256 normalizedStables = - (uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; + (uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; assertEq(normalizer, 2 * BASE_27); assertEq(normalizedStables, 1 ether); } @@ -836,26 +836,26 @@ contract Test_Setters_UpdateNormalizer is Fixture { _mintExactOutput(alice, address(eurB), 1 ether, 1 ether); hoax(governor); - transmuter.toggleTrusted(alice, TrustedType.Updater); + parallelizer.toggleTrusted(alice, TrustedType.Updater); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit NormalizerUpdated(2 * BASE_27); hoax(alice); // Increase of 2 with 2 in the system -> x2 - transmuter.updateNormalizer(2 ether, true); + parallelizer.updateNormalizer(2 ether, true); - (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurA)); + (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurA)); assertEq(stablecoinsFromCollateral, 2 ether); assertEq(stablecoinsIssued, 4 ether); - (stablecoinsFromCollateral, stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurB)); + (stablecoinsFromCollateral, stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurB)); assertEq(stablecoinsFromCollateral, 2 ether); assertEq(stablecoinsIssued, 4 ether); uint256 normalizer = - uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; + uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; uint256 normalizedStables = - (uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; + (uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; assertEq(normalizer, 2 * BASE_27); // 2x increase via the function call assertEq(normalizedStables, 2 ether); } @@ -864,24 +864,24 @@ contract Test_Setters_UpdateNormalizer is Fixture { _mintExactOutput(alice, address(eurA), 1 ether, 1 ether); _mintExactOutput(alice, address(eurB), 1 ether, 1 ether); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit NormalizerUpdated(BASE_27 / 2); hoax(governor); // Decrease of 1 with 2 in the system -> /2 - transmuter.updateNormalizer(1 ether, false); + parallelizer.updateNormalizer(1 ether, false); - (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurA)); + (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurA)); assertEq(stablecoinsFromCollateral, 1 ether / 2); assertEq(stablecoinsIssued, 1 ether); - (stablecoinsFromCollateral, stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurB)); + (stablecoinsFromCollateral, stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurB)); assertEq(stablecoinsFromCollateral, 1 ether / 2); assertEq(stablecoinsIssued, 1 ether); uint256 normalizer = - uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; + uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; uint256 normalizedStables = - (uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; + (uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; assertEq(normalizer, BASE_27 / 2); assertEq(normalizedStables, 2 ether); } @@ -892,20 +892,20 @@ contract Test_Setters_UpdateNormalizer is Fixture { // normalizer -> 1e27, normalizedStables -> 2e18 hoax(governor); - transmuter.updateNormalizer(2 * (BASE_27 - 1 ether), true); + parallelizer.updateNormalizer(2 * (BASE_27 - 1 ether), true); // normalizer should do 1e27 -> 1e27 + 1e36 - 1e27 = 1e36 - (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurA)); + (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurA)); assertEq(stablecoinsFromCollateral, BASE_27); // 1e27 stable backed by eurA assertEq(stablecoinsIssued, 2 * BASE_27); - (stablecoinsFromCollateral, stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurB)); + (stablecoinsFromCollateral, stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurB)); assertEq(stablecoinsFromCollateral, BASE_27); // 1e27 stable backed by eurB assertEq(stablecoinsIssued, 2 * BASE_27); uint256 normalizer = - uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; + uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; uint256 normalizedStables = - (uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; + (uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; assertEq(normalizer, BASE_27); // RENORMALIZED assertEq(normalizedStables, 2 * BASE_27); } @@ -919,11 +919,11 @@ contract Test_Setters_SetCollateralManager is Fixture { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); } function test_RevertWhen_NotCollateral() public { @@ -931,7 +931,7 @@ contract Test_Setters_SetCollateralManager is Fixture { vm.expectRevert(Errors.NotCollateral.selector); hoax(governor); - transmuter.setCollateralManager(address(this), data); + parallelizer.setCollateralManager(address(this), data); } function test_RevertWhen_InvalidParams() public { @@ -943,7 +943,7 @@ contract Test_Setters_SetCollateralManager is Fixture { vm.expectRevert(Errors.InvalidParams.selector); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); } function test_AddManager() public { @@ -956,19 +956,19 @@ contract Test_Setters_SetCollateralManager is Fixture { }); (bool isManaged, IERC20[] memory fetchedSubCollaterals, bytes memory config) = - transmuter.getManagerData(address(eurA)); + parallelizer.getManagerData(address(eurA)); assertEq(isManaged, false); assertEq(fetchedSubCollaterals.length, 0); assertEq(config.length, 0); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit CollateralManagerSet(address(eurA), data); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); // Refetch storage to check the update - (isManaged, fetchedSubCollaterals, config) = transmuter.getManagerData(address(eurA)); + (isManaged, fetchedSubCollaterals, config) = parallelizer.getManagerData(address(eurA)); (, bytes memory aux) = abi.decode(config, (ManagerType, bytes)); address fetched = abi.decode(aux, (address)); @@ -986,14 +986,14 @@ contract Test_Setters_SetCollateralManager is Fixture { ManagerStorage({ subCollaterals: subCollaterals, config: abi.encode(ManagerType.EXTERNAL, abi.encode(manager)) }); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); data = ManagerStorage({ subCollaterals: new IERC20[](0), config: "" }); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); (bool isManaged, IERC20[] memory fetchedSubCollaterals, bytes memory config) = - transmuter.getManagerData(address(eurA)); + parallelizer.getManagerData(address(eurA)); assertEq(isManaged, false); assertEq(fetchedSubCollaterals.length, 0); assertEq(config.length, 0); @@ -1006,52 +1006,52 @@ contract Test_Setters_ChangeAllowance is Fixture { function test_RevertWhen_NotGovernor() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.changeAllowance(eurA, alice, 1 ether); + parallelizer.changeAllowance(eurA, alice, 1 ether); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.changeAllowance(eurA, alice, 1 ether); + parallelizer.changeAllowance(eurA, alice, 1 ether); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.changeAllowance(eurA, alice, 1 ether); + parallelizer.changeAllowance(eurA, alice, 1 ether); } function test_SafeIncreaseFrom0() public { vm.expectEmit(address(eurA)); - emit Approval(address(transmuter), alice, 1 ether); + emit Approval(address(parallelizer), alice, 1 ether); hoax(governor); - transmuter.changeAllowance(eurA, alice, 1 ether); + parallelizer.changeAllowance(eurA, alice, 1 ether); - assertEq(eurA.allowance(address(transmuter), alice), 1 ether); + assertEq(eurA.allowance(address(parallelizer), alice), 1 ether); } function test_SafeIncreaseFromNon0() public { hoax(governor); - transmuter.changeAllowance(eurA, alice, 1 ether); + parallelizer.changeAllowance(eurA, alice, 1 ether); vm.expectEmit(address(eurA)); - emit Approval(address(transmuter), alice, 2 ether); + emit Approval(address(parallelizer), alice, 2 ether); hoax(governor); - transmuter.changeAllowance(eurA, alice, 2 ether); + parallelizer.changeAllowance(eurA, alice, 2 ether); - assertEq(eurA.allowance(address(transmuter), alice), 2 ether); + assertEq(eurA.allowance(address(parallelizer), alice), 2 ether); } function test_SafeDecrease() public { hoax(governor); - transmuter.changeAllowance(eurA, alice, 1 ether); + parallelizer.changeAllowance(eurA, alice, 1 ether); vm.expectEmit(address(eurA)); - emit Approval(address(transmuter), alice, 0); + emit Approval(address(parallelizer), alice, 0); hoax(governor); - transmuter.changeAllowance(eurA, alice, 0); + parallelizer.changeAllowance(eurA, alice, 0); - assertEq(eurA.allowance(address(transmuter), alice), 0); + assertEq(eurA.allowance(address(parallelizer), alice), 0); } } @@ -1061,36 +1061,36 @@ contract Test_Setters_AddCollateral is Fixture { function test_RevertWhen_NotGovernor() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.addCollateral(address(eurA)); + parallelizer.addCollateral(address(eurA)); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.addCollateral(address(eurA)); + parallelizer.addCollateral(address(eurA)); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.addCollateral(address(eurA)); + parallelizer.addCollateral(address(eurA)); } function test_RevertWhen_AlreadyAdded() public { vm.expectRevert(Errors.AlreadyAdded.selector); hoax(governor); - transmuter.addCollateral(address(eurA)); + parallelizer.addCollateral(address(eurA)); } function test_Success() public { - uint256 length = transmuter.getCollateralList().length; + uint256 length = parallelizer.getCollateralList().length; - vm.expectEmit(address(transmuter)); - emit CollateralAdded(address(agToken)); + vm.expectEmit(address(parallelizer)); + emit CollateralAdded(address(tokenP)); hoax(governor); - transmuter.addCollateral(address(agToken)); + parallelizer.addCollateral(address(tokenP)); - address[] memory list = transmuter.getCollateralList(); + address[] memory list = parallelizer.getCollateralList(); assertEq(list.length, length + 1); - assertEq(address(agToken), list[list.length - 1]); - assertEq(transmuter.getCollateralDecimals(address(agToken)), agToken.decimals()); + assertEq(address(tokenP), list[list.length - 1]); + assertEq(parallelizer.getCollateralDecimals(address(tokenP)), tokenP.decimals()); } } @@ -1100,37 +1100,37 @@ contract Test_Setters_AdjustNormalizedStablecoins is Fixture { function test_RevertWhen_NotGovernor() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.adjustStablecoins(address(eurA), 1 ether, true); + parallelizer.adjustStablecoins(address(eurA), 1 ether, true); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.adjustStablecoins(address(eurA), 1 ether, true); + parallelizer.adjustStablecoins(address(eurA), 1 ether, true); } function test_RevertWhen_NotCollateral() public { vm.expectRevert(Errors.NotCollateral.selector); hoax(governor); - transmuter.adjustStablecoins(address(this), 1 ether, true); + parallelizer.adjustStablecoins(address(this), 1 ether, true); } function test_Decrease() public { _mintExactOutput(alice, address(eurA), 1 ether, 1 ether); _mintExactOutput(alice, address(eurB), 1 ether, 1 ether); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit ReservesAdjusted(address(eurA), 1 ether / 2, false); hoax(governor); - transmuter.adjustStablecoins(address(eurA), 1 ether / 2, false); + parallelizer.adjustStablecoins(address(eurA), 1 ether / 2, false); - (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurA)); + (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurA)); assertEq(stablecoinsFromCollateral, 1 ether / 2); assertEq(stablecoinsIssued, 3 ether / 2); uint256 normalizer = - uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; + uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; uint256 normalizedStables = - (uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; + (uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; assertEq(normalizer, BASE_27); assertEq(normalizedStables, 3 ether / 2); } @@ -1139,20 +1139,20 @@ contract Test_Setters_AdjustNormalizedStablecoins is Fixture { _mintExactOutput(alice, address(eurA), 1 ether, 1 ether); _mintExactOutput(alice, address(eurB), 1 ether, 1 ether); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit ReservesAdjusted(address(eurA), 1 ether / 2, true); hoax(governor); - transmuter.adjustStablecoins(address(eurA), 1 ether / 2, true); + parallelizer.adjustStablecoins(address(eurA), 1 ether / 2, true); - (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = transmuter.getIssuedByCollateral(address(eurA)); + (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = parallelizer.getIssuedByCollateral(address(eurA)); assertEq(stablecoinsFromCollateral, 3 ether / 2); assertEq(stablecoinsIssued, 5 ether / 2); uint256 normalizer = - uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; + uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) >> 128; uint256 normalizedStables = - (uint256(vm.load(address(transmuter), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; + (uint256(vm.load(address(parallelizer), bytes32(uint256(TRANSMUTER_STORAGE_POSITION) + 1))) << 128) >> 128; assertEq(normalizer, BASE_27); assertEq(normalizedStables, 5 ether / 2); } @@ -1164,17 +1164,17 @@ contract Test_Setters_RevokeCollateral is Fixture { function test_RevertWhen_NotGovernor() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.adjustStablecoins(address(eurA), 1 ether, true); + parallelizer.adjustStablecoins(address(eurA), 1 ether, true); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, guardian)); hoax(guardian); - transmuter.adjustStablecoins(address(eurA), 1 ether, true); + parallelizer.adjustStablecoins(address(eurA), 1 ether, true); } function test_RevertWhen_NotCollateral() public { vm.expectRevert(Errors.NotCollateral.selector); hoax(governor); - transmuter.adjustStablecoins(address(this), 1 ether, true); + parallelizer.adjustStablecoins(address(this), 1 ether, true); } function test_RevertWhen_StillBacked() public { @@ -1182,7 +1182,7 @@ contract Test_Setters_RevokeCollateral is Fixture { vm.expectRevert(Errors.NotCollateral.selector); hoax(governor); - transmuter.adjustStablecoins(address(this), 1 ether, true); + parallelizer.adjustStablecoins(address(this), 1 ether, true); } function test_RevertWhen_ManagerHasAssets() public { @@ -1195,55 +1195,55 @@ contract Test_Setters_RevokeCollateral is Fixture { manager.setSubCollaterals(data.subCollaterals, ""); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); deal(address(eurA), address(manager), 1 ether); vm.expectRevert(Errors.ManagerHasAssets.selector); hoax(governor); - transmuter.revokeCollateral(address(eurA)); + parallelizer.revokeCollateral(address(eurA)); } function test_Success() public { - address[] memory prevlist = transmuter.getCollateralList(); + address[] memory prevlist = parallelizer.getCollateralList(); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit CollateralRevoked(address(eurA)); hoax(governor); - transmuter.revokeCollateral(address(eurA)); + parallelizer.revokeCollateral(address(eurA)); - address[] memory list = transmuter.getCollateralList(); + address[] memory list = parallelizer.getCollateralList(); assertEq(list.length, prevlist.length - 1); for (uint256 i = 0; i < list.length; i++) { assertNotEq(address(list[i]), address(eurA)); } - assertEq(0, transmuter.getCollateralDecimals(address(eurA))); + assertEq(0, parallelizer.getCollateralDecimals(address(eurA))); - (uint64[] memory xFeeMint, int64[] memory yFeeMint) = transmuter.getCollateralMintFees(address(eurA)); + (uint64[] memory xFeeMint, int64[] memory yFeeMint) = parallelizer.getCollateralMintFees(address(eurA)); assertEq(0, xFeeMint.length); assertEq(0, yFeeMint.length); - (uint64[] memory xFeeBurn, int64[] memory yFeeBurn) = transmuter.getCollateralMintFees(address(eurA)); + (uint64[] memory xFeeBurn, int64[] memory yFeeBurn) = parallelizer.getCollateralMintFees(address(eurA)); assertEq(0, xFeeBurn.length); assertEq(0, yFeeBurn.length); vm.expectRevert(Errors.NotCollateral.selector); - transmuter.isPaused(address(eurA), ActionType.Mint); + parallelizer.isPaused(address(eurA), ActionType.Mint); vm.expectRevert(Errors.NotCollateral.selector); - transmuter.isPaused(address(eurA), ActionType.Burn); + parallelizer.isPaused(address(eurA), ActionType.Burn); vm.expectRevert(); - transmuter.getOracle(address(eurA)); + parallelizer.getOracle(address(eurA)); vm.expectRevert(); - transmuter.getOracleValues(address(eurA)); - (bool managed,,) = transmuter.getManagerData(address(eurA)); + parallelizer.getOracleValues(address(eurA)); + (bool managed,,) = parallelizer.getManagerData(address(eurA)); assert(!managed); - (uint256 issued,) = transmuter.getIssuedByCollateral(address(eurA)); + (uint256 issued,) = parallelizer.getIssuedByCollateral(address(eurA)); assertEq(0, issued); - assert(transmuter.isWhitelistedForCollateral(address(eurA), address(this))); + assert(parallelizer.isWhitelistedForCollateral(address(eurA), address(this))); } function test_SuccessWithManager() public { @@ -1256,28 +1256,28 @@ contract Test_Setters_RevokeCollateral is Fixture { manager.setSubCollaterals(data.subCollaterals, ""); hoax(governor); - transmuter.setCollateralManager(address(eurA), data); + parallelizer.setCollateralManager(address(eurA), data); - address[] memory prevlist = transmuter.getCollateralList(); + address[] memory prevlist = parallelizer.getCollateralList(); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit CollateralRevoked(address(eurA)); hoax(governor); - transmuter.revokeCollateral(address(eurA)); + parallelizer.revokeCollateral(address(eurA)); - address[] memory list = transmuter.getCollateralList(); + address[] memory list = parallelizer.getCollateralList(); assertEq(list.length, prevlist.length - 1); for (uint256 i = 0; i < list.length; i++) { assertNotEq(address(list[i]), address(eurA)); } - assertEq(0, transmuter.getCollateralDecimals(address(eurA))); + assertEq(0, parallelizer.getCollateralDecimals(address(eurA))); assertEq(0, eurA.balanceOf(address(manager))); - assertEq(0, eurA.balanceOf(address(transmuter))); + assertEq(0, eurA.balanceOf(address(parallelizer))); - (bool managed,,) = transmuter.getManagerData(address(eurA)); + (bool managed,,) = parallelizer.getManagerData(address(eurA)); assert(!managed); } } @@ -1288,17 +1288,17 @@ contract Test_Setters_DiamondEtherscan is Fixture { function test_RevertWhen_NotGuardian() public { vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, governor)); hoax(governor); - transmuter.setDummyImplementation(address(bob)); + parallelizer.setDummyImplementation(address(bob)); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setDummyImplementation(address(bob)); + parallelizer.setDummyImplementation(address(bob)); hoax(guardian); - vm.expectEmit(address(transmuter)); + vm.expectEmit(address(parallelizer)); emit Upgraded(address(bob)); - transmuter.setDummyImplementation(address(bob)); - assertEq(transmuter.implementation(), address(bob)); + parallelizer.setDummyImplementation(address(bob)); + assertEq(parallelizer.implementation(), address(bob)); } } @@ -1308,45 +1308,45 @@ contract Test_Setters_SetStablecoinCap is Fixture { function test_RevertWhen_NotGuardian() public { hoax(governor); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, governor)); - transmuter.setStablecoinCap(address(eurA), 1 ether); + parallelizer.setStablecoinCap(address(eurA), 1 ether); hoax(governor); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, governor)); - transmuter.setStablecoinCap(address(eurB), 1 ether); + parallelizer.setStablecoinCap(address(eurB), 1 ether); hoax(governor); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, governor)); - transmuter.setStablecoinCap(address(eurY), 1 ether); + parallelizer.setStablecoinCap(address(eurY), 1 ether); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setStablecoinCap(address(eurA), 1 ether); + parallelizer.setStablecoinCap(address(eurA), 1 ether); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setStablecoinCap(address(eurB), 1 ether); + parallelizer.setStablecoinCap(address(eurB), 1 ether); vm.expectRevert(abi.encodeWithSelector(Errors.AccessManagedUnauthorized.selector, alice)); hoax(alice); - transmuter.setStablecoinCap(address(eurY), 1 ether); + parallelizer.setStablecoinCap(address(eurY), 1 ether); } function test_RevertWhen_NotCollateral() public { vm.expectRevert(Errors.NotCollateral.selector); hoax(guardian); - transmuter.setStablecoinCap(address(agToken), 1 ether); + parallelizer.setStablecoinCap(address(tokenP), 1 ether); vm.expectRevert(Errors.NotCollateral.selector); hoax(guardian); - transmuter.setStablecoinCap(address(this), 1 ether); + parallelizer.setStablecoinCap(address(this), 1 ether); } function test_SetStablecoinCap_Success() public { hoax(guardian); - transmuter.setStablecoinCap(address(eurA), 1 ether); + parallelizer.setStablecoinCap(address(eurA), 1 ether); hoax(guardian); - transmuter.setStablecoinCap(address(eurB), 1 ether); + parallelizer.setStablecoinCap(address(eurB), 1 ether); hoax(guardian); - transmuter.setStablecoinCap(address(eurY), 1 ether); + parallelizer.setStablecoinCap(address(eurY), 1 ether); - assertEq(transmuter.getStablecoinCap(address(eurA)), 1 ether); - assertEq(transmuter.getStablecoinCap(address(eurB)), 1 ether); - assertEq(transmuter.getStablecoinCap(address(eurY)), 1 ether); + assertEq(parallelizer.getStablecoinCap(address(eurA)), 1 ether); + assertEq(parallelizer.getStablecoinCap(address(eurB)), 1 ether); + assertEq(parallelizer.getStablecoinCap(address(eurY)), 1 ether); } } diff --git a/tests/units/StablecoinCap.t.sol b/tests/units/StablecoinCap.t.sol index a1edbd0..9149a47 100644 --- a/tests/units/StablecoinCap.t.sol +++ b/tests/units/StablecoinCap.t.sol @@ -4,17 +4,16 @@ pragma solidity 0.8.28; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; -import { IAccessControlManager } from "interfaces/IAccessControlManager.sol"; -import { IAgToken } from "interfaces/IAgToken.sol"; +import { ITokenP } from "interfaces/ITokenP.sol"; import { AggregatorV3Interface } from "interfaces/external/chainlink/AggregatorV3Interface.sol"; import { MockAccessControlManager } from "tests/mock/MockAccessControlManager.sol"; import { MockChainlinkOracle } from "tests/mock/MockChainlinkOracle.sol"; import { MockTokenPermit } from "tests/mock/MockTokenPermit.sol"; -import { Test } from "contracts/transmuter/configs/Test.sol"; -import { LibGetters } from "contracts/transmuter/libraries/LibGetters.sol"; -import "contracts/transmuter/Storage.sol"; +import { Test } from "contracts/parallelizer/configs/Test.sol"; +import { LibGetters } from "contracts/parallelizer/libraries/LibGetters.sol"; +import "contracts/parallelizer/Storage.sol"; import "contracts/utils/Constants.sol"; import "contracts/utils/Errors.sol" as Errors; @@ -22,9 +21,9 @@ import { Fixture } from "../Fixture.sol"; contract StablecoinCapTest is Fixture { function test_GetStablecoinCap_Init_Success() public { - assertEq(transmuter.getStablecoinCap(address(eurA)), type(uint256).max); - assertEq(transmuter.getStablecoinCap(address(eurB)), type(uint256).max); - assertEq(transmuter.getStablecoinCap(address(eurY)), type(uint256).max); + assertEq(parallelizer.getStablecoinCap(address(eurA)), type(uint256).max); + assertEq(parallelizer.getStablecoinCap(address(eurB)), type(uint256).max); + assertEq(parallelizer.getStablecoinCap(address(eurY)), type(uint256).max); } function test_RevertWhen_SetStablecoinCap_TooLargeMint() public { @@ -33,14 +32,14 @@ contract StablecoinCapTest is Fixture { address collateral = address(eurA); vm.prank(guardian); - transmuter.setStablecoinCap(collateral, stablecoinCap); + parallelizer.setStablecoinCap(collateral, stablecoinCap); deal(collateral, bob, amount); startHoax(bob); - IERC20(collateral).approve(address(transmuter), amount); + IERC20(collateral).approve(address(parallelizer), amount); vm.expectRevert(Errors.InvalidSwap.selector); startHoax(bob); - transmuter.swapExactOutput(amount, type(uint256).max, collateral, address(agToken), bob, block.timestamp * 2); + parallelizer.swapExactOutput(amount, type(uint256).max, collateral, address(tokenP), bob, block.timestamp * 2); } function test_RevertWhen_SetStablecoinCap_SlightlyLargeMint() public { @@ -49,14 +48,14 @@ contract StablecoinCapTest is Fixture { address collateral = address(eurA); vm.prank(guardian); - transmuter.setStablecoinCap(collateral, stablecoinCap); + parallelizer.setStablecoinCap(collateral, stablecoinCap); deal(collateral, bob, amount); startHoax(bob); - IERC20(collateral).approve(address(transmuter), amount); + IERC20(collateral).approve(address(parallelizer), amount); vm.expectRevert(Errors.InvalidSwap.selector); startHoax(bob); - transmuter.swapExactOutput(amount, type(uint256).max, collateral, address(agToken), bob, block.timestamp * 2); + parallelizer.swapExactOutput(amount, type(uint256).max, collateral, address(tokenP), bob, block.timestamp * 2); } function test_SetStablecoinCap_Success() public { @@ -65,12 +64,12 @@ contract StablecoinCapTest is Fixture { address collateral = address(eurA); vm.prank(guardian); - transmuter.setStablecoinCap(collateral, stablecoinCap); + parallelizer.setStablecoinCap(collateral, stablecoinCap); deal(collateral, bob, amount); startHoax(bob); - IERC20(collateral).approve(address(transmuter), amount); + IERC20(collateral).approve(address(parallelizer), amount); startHoax(bob); - transmuter.swapExactOutput(amount, type(uint256).max, collateral, address(agToken), bob, block.timestamp * 2); + parallelizer.swapExactOutput(amount, type(uint256).max, collateral, address(tokenP), bob, block.timestamp * 2); } } diff --git a/tests/utils/ConfigAccessManager.sol b/tests/utils/ConfigAccessManager.sol index eebf8ff..2737fe9 100644 --- a/tests/utils/ConfigAccessManager.sol +++ b/tests/utils/ConfigAccessManager.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { AccessManager, IAccessManaged } from "@openzeppelin/contracts/access/manager/AccessManager.sol"; @@ -11,9 +10,9 @@ import { BaseSavings } from "contracts/savings/BaseSavings.sol"; import { BaseHarvester } from "contracts/helpers/BaseHarvester.sol"; import { MultiBlockHarvester } from "contracts/helpers/MultiBlockHarvester.sol"; import { GenericHarvester } from "contracts/helpers/GenericHarvester.sol"; -import { SettersGuardian } from "contracts/transmuter/facets/SettersGuardian.sol"; -import { SettersGovernor } from "contracts/transmuter/facets/SettersGovernor.sol"; -import { DiamondEtherscan } from "contracts/transmuter/facets/DiamondEtherscan.sol"; +import { SettersGuardian } from "contracts/parallelizer/facets/SettersGuardian.sol"; +import { SettersGovernor } from "contracts/parallelizer/facets/SettersGovernor.sol"; +import { DiamondEtherscan } from "contracts/parallelizer/facets/DiamondEtherscan.sol"; import "contracts/utils/Constants.sol"; import "./Helper.sol"; @@ -80,7 +79,7 @@ abstract contract ConfigAccessManager is Helper { return selectors; } - function getTransmuterGuardianSelectorAccess() internal pure returns (bytes4[] memory) { + function getParallelizerGuardianSelectorAccess() internal pure returns (bytes4[] memory) { bytes4[] memory selectors = new bytes4[](6); selectors[0] = SettersGuardian.togglePause.selector; selectors[1] = SettersGuardian.setFees.selector; @@ -91,7 +90,7 @@ abstract contract ConfigAccessManager is Helper { return selectors; } - function getTransmuterGovernorSelectorAccess() internal pure returns (bytes4[] memory) { + function getParallelizerGovernorSelectorAccess() internal pure returns (bytes4[] memory) { bytes4[] memory selectors = new bytes4[](11); selectors[0] = SettersGovernor.recoverERC20.selector; selectors[1] = SettersGovernor.setAccessManager.selector; diff --git a/tests/utils/FunctionUtils.sol b/tests/utils/FunctionUtils.sol index 673e367..916d54f 100644 --- a/tests/utils/FunctionUtils.sol +++ b/tests/utils/FunctionUtils.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-3.0 - pragma solidity 0.8.28; import { StdUtils } from "@forge-std/Test.sol"; import "contracts/utils/Constants.sol"; /// @title FunctionUtils -/// @author Angle Labs, Inc. +/// @author Cooper Labs +/// @custom:contact security@cooperlabs.xyz contract FunctionUtils is StdUtils { function _convertDecimalTo(uint256 amount, uint8 fromDecimals, uint8 toDecimals) internal pure returns (uint256) { if (fromDecimals > toDecimals) return amount / 10 ** (fromDecimals - toDecimals); diff --git a/tests/utils/Transmuter.sol b/tests/utils/Parallelizer.sol similarity index 62% rename from tests/utils/Transmuter.sol rename to tests/utils/Parallelizer.sol index 4c4116a..ef85009 100644 --- a/tests/utils/Transmuter.sol +++ b/tests/utils/Parallelizer.sol @@ -1,34 +1,34 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.28; -import { ITransmuter } from "interfaces/ITransmuter.sol"; - -import { DiamondProxy } from "contracts/transmuter/DiamondProxy.sol"; -import "contracts/transmuter/Storage.sol"; -import { DiamondCut } from "contracts/transmuter/facets/DiamondCut.sol"; -import { DiamondEtherscan } from "contracts/transmuter/facets/DiamondEtherscan.sol"; -import { DiamondLoupe } from "contracts/transmuter/facets/DiamondLoupe.sol"; -import { Getters } from "contracts/transmuter/facets/Getters.sol"; -import { Redeemer } from "contracts/transmuter/facets/Redeemer.sol"; -import { RewardHandler } from "contracts/transmuter/facets/RewardHandler.sol"; -import { SettersGovernor } from "contracts/transmuter/facets/SettersGovernor.sol"; -import { SettersGuardian } from "contracts/transmuter/facets/SettersGuardian.sol"; -import { Swapper } from "contracts/transmuter/facets/Swapper.sol"; +import { IParallelizer } from "interfaces/IParallelizer.sol"; + +import { DiamondProxy } from "contracts/parallelizer/DiamondProxy.sol"; +import "contracts/parallelizer/Storage.sol"; +import { DiamondCut } from "contracts/parallelizer/facets/DiamondCut.sol"; +import { DiamondEtherscan } from "contracts/parallelizer/facets/DiamondEtherscan.sol"; +import { DiamondLoupe } from "contracts/parallelizer/facets/DiamondLoupe.sol"; +import { Getters } from "contracts/parallelizer/facets/Getters.sol"; +import { Redeemer } from "contracts/parallelizer/facets/Redeemer.sol"; +import { RewardHandler } from "contracts/parallelizer/facets/RewardHandler.sol"; +import { SettersGovernor } from "contracts/parallelizer/facets/SettersGovernor.sol"; +import { SettersGuardian } from "contracts/parallelizer/facets/SettersGuardian.sol"; +import { Swapper } from "contracts/parallelizer/facets/Swapper.sol"; import "contracts/utils/Errors.sol"; import { DummyDiamondImplementation } from "scripts/generated/DummyDiamondImplementation.sol"; import "./Helper.sol"; import { console } from "@forge-std/console.sol"; -abstract contract Transmuter is Helper { +abstract contract Parallelizer is Helper { // Diamond - ITransmuter transmuter; + IParallelizer parallelizer; string[] facetNames; address[] facetAddressList; // @dev Deploys diamond and connects facets - function deployTransmuter(address _init, bytes memory _calldata) public virtual { + function deployParallelizer(address _init, bytes memory _calldata) public virtual { // Deploy every facet facetNames.push("DiamondCut"); facetAddressList.push(address(new DiamondCut())); @@ -70,17 +70,17 @@ abstract contract Transmuter is Helper { } // Deploy diamond - transmuter = ITransmuter(address(new DiamondProxy(cut, _init, _calldata))); + parallelizer = IParallelizer(address(new DiamondProxy(cut, _init, _calldata))); } // @dev Deploys diamond and connects facets - function deployReplicaTransmuter( + function deployReplicaParallelizer( address _init, bytes memory _calldata ) public virtual - returns (ITransmuter _transmuter) + returns (IParallelizer _transmuter) { // Build appropriate payload uint256 n = facetNames.length; @@ -94,7 +94,7 @@ abstract contract Transmuter is Helper { } // Deploy diamond - _transmuter = ITransmuter(address(new DiamondProxy(cut, _init, _calldata))); + _transmuter = IParallelizer(address(new DiamondProxy(cut, _init, _calldata))); return _transmuter; }