diff --git a/contracts/test/config/MockCreditConfig.sol b/contracts/test/config/MockCreditConfig.sol index 6b833a81..0c151e20 100644 --- a/contracts/test/config/MockCreditConfig.sol +++ b/contracts/test/config/MockCreditConfig.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.17; import {TokensTestSuite} from "../suites/TokensTestSuite.sol"; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetector.sol"; import {Contracts} from "@gearbox-protocol/sdk-gov/contracts/SupportedContracts.sol"; import "forge-std/console.sol"; @@ -30,7 +30,7 @@ contract MockCreditConfig is Test, IPoolV3DeployConfig { string public name = "Diesel DAI v3"; uint256 public chainId; - Tokens public underlying = Tokens.DAI; + uint256 public underlying = TOKEN_DAI; bool public constant supportsQuotas = true; uint256 public constant getAccountAmount = DAI_ACCOUNT_AMOUNT; @@ -54,21 +54,21 @@ contract MockCreditConfig is Test, IPoolV3DeployConfig { NetworkDetector nd = new NetworkDetector(); chainId = nd.chainId(); - _gaugeRates.push(GaugeRate({token: Tokens.USDC, minRate: 1, maxRate: 10_000})); - _gaugeRates.push(GaugeRate({token: Tokens.USDT, minRate: 1, maxRate: 10_000})); - _gaugeRates.push(GaugeRate({token: Tokens.WETH, minRate: 1, maxRate: 10_000})); - _gaugeRates.push(GaugeRate({token: Tokens.LINK, minRate: 1, maxRate: 10_000})); - _gaugeRates.push(GaugeRate({token: Tokens.CRV, minRate: 1, maxRate: 10_000})); - _gaugeRates.push(GaugeRate({token: Tokens.CVX, minRate: 1, maxRate: 10_000})); - _gaugeRates.push(GaugeRate({token: Tokens.STETH, minRate: 1, maxRate: 10_000})); - - _quotaLimits.push(PoolQuotaLimit({token: Tokens.USDC, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); - _quotaLimits.push(PoolQuotaLimit({token: Tokens.USDT, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); - _quotaLimits.push(PoolQuotaLimit({token: Tokens.WETH, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); - _quotaLimits.push(PoolQuotaLimit({token: Tokens.LINK, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); - _quotaLimits.push(PoolQuotaLimit({token: Tokens.CRV, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); - _quotaLimits.push(PoolQuotaLimit({token: Tokens.CVX, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); - _quotaLimits.push(PoolQuotaLimit({token: Tokens.STETH, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); + _gaugeRates.push(GaugeRate({token: TOKEN_USDC, minRate: 1, maxRate: 10_000})); + _gaugeRates.push(GaugeRate({token: TOKEN_USDT, minRate: 1, maxRate: 10_000})); + _gaugeRates.push(GaugeRate({token: TOKEN_WETH, minRate: 1, maxRate: 10_000})); + _gaugeRates.push(GaugeRate({token: TOKEN_LINK, minRate: 1, maxRate: 10_000})); + _gaugeRates.push(GaugeRate({token: TOKEN_CRV, minRate: 1, maxRate: 10_000})); + _gaugeRates.push(GaugeRate({token: TOKEN_CVX, minRate: 1, maxRate: 10_000})); + _gaugeRates.push(GaugeRate({token: TOKEN_STETH, minRate: 1, maxRate: 10_000})); + + _quotaLimits.push(PoolQuotaLimit({token: TOKEN_USDC, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); + _quotaLimits.push(PoolQuotaLimit({token: TOKEN_USDT, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); + _quotaLimits.push(PoolQuotaLimit({token: TOKEN_WETH, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); + _quotaLimits.push(PoolQuotaLimit({token: TOKEN_LINK, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); + _quotaLimits.push(PoolQuotaLimit({token: TOKEN_CRV, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); + _quotaLimits.push(PoolQuotaLimit({token: TOKEN_CVX, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); + _quotaLimits.push(PoolQuotaLimit({token: TOKEN_STETH, quotaIncreaseFee: 0, limit: uint96(type(int96).max)})); CreditManagerV3DeployParams storage cp = _creditManagers.push(); @@ -87,13 +87,13 @@ contract MockCreditConfig is Test, IPoolV3DeployConfig { cp.name = "Mock Credit Manager DAI"; CollateralTokenHuman[] storage cts = cp.collateralTokens; - cts.push(CollateralTokenHuman({token: Tokens.USDC, lt: 90_00})); - cts.push(CollateralTokenHuman({token: Tokens.USDT, lt: 88_00})); - cts.push(CollateralTokenHuman({token: Tokens.WETH, lt: 83_00})); - cts.push(CollateralTokenHuman({token: Tokens.LINK, lt: 73_00})); - cts.push(CollateralTokenHuman({token: Tokens.CRV, lt: 73_00})); - cts.push(CollateralTokenHuman({token: Tokens.CVX, lt: 73_00})); - cts.push(CollateralTokenHuman({token: Tokens.STETH, lt: 73_00})); + cts.push(CollateralTokenHuman({token: TOKEN_USDC, lt: 90_00})); + cts.push(CollateralTokenHuman({token: TOKEN_USDT, lt: 88_00})); + cts.push(CollateralTokenHuman({token: TOKEN_WETH, lt: 83_00})); + cts.push(CollateralTokenHuman({token: TOKEN_LINK, lt: 73_00})); + cts.push(CollateralTokenHuman({token: TOKEN_CRV, lt: 73_00})); + cts.push(CollateralTokenHuman({token: TOKEN_CVX, lt: 73_00})); + cts.push(CollateralTokenHuman({token: TOKEN_STETH, lt: 73_00})); } function poolParams() external view override returns (PoolV3DeployParams memory) { diff --git a/contracts/test/config/MockTokensData.sol b/contracts/test/config/MockTokensData.sol index fb3c8c45..bf76a16d 100644 --- a/contracts/test/config/MockTokensData.sol +++ b/contracts/test/config/MockTokensData.sol @@ -3,52 +3,46 @@ // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import "../lib/constants.sol"; struct MockToken { - Tokens index; + uint256 index; string symbol; uint8 decimals; int256 price; - Tokens underlying; + uint256 underlying; } library MockTokensData { function getTokenData() internal pure returns (MockToken[] memory result) { MockToken[9] memory testTokensData = [ - MockToken({index: Tokens.DAI, symbol: "DAI", decimals: 18, price: 10 ** 8, underlying: Tokens.NO_TOKEN}), - MockToken({index: Tokens.USDC, symbol: "USDC", decimals: 6, price: 10 ** 8, underlying: Tokens.NO_TOKEN}), + MockToken({index: TOKEN_DAI, symbol: "DAI", decimals: 18, price: 10 ** 8, underlying: TOKEN_NO_TOKEN}), + MockToken({index: TOKEN_USDC, symbol: "USDC", decimals: 6, price: 10 ** 8, underlying: TOKEN_NO_TOKEN}), MockToken({ - index: Tokens.WETH, + index: TOKEN_WETH, symbol: "WETH", decimals: 18, price: int256(DAI_WETH_RATE) * 10 ** 8, - underlying: Tokens.NO_TOKEN + underlying: TOKEN_NO_TOKEN }), - MockToken({index: Tokens.LINK, symbol: "LINK", decimals: 18, price: 15 * 10 ** 8, underlying: Tokens.NO_TOKEN}), + MockToken({index: TOKEN_LINK, symbol: "LINK", decimals: 18, price: 15 * 10 ** 8, underlying: TOKEN_NO_TOKEN}), MockToken({ - index: Tokens.USDT, + index: TOKEN_USDT, symbol: "USDT", decimals: 18, price: 99 * 10 ** 7, // .99 for test purposes - underlying: Tokens.NO_TOKEN + underlying: TOKEN_NO_TOKEN }), + MockToken({index: TOKEN_STETH, symbol: "stETH", decimals: 18, price: 3300 * 10 ** 8, underlying: TOKEN_NO_TOKEN}), + MockToken({index: TOKEN_CRV, symbol: "CRV", decimals: 18, price: 14 * 10 ** 7, underlying: TOKEN_NO_TOKEN}), + MockToken({index: TOKEN_CVX, symbol: "CVX", decimals: 18, price: 7 * 10 ** 8, underlying: TOKEN_NO_TOKEN}), MockToken({ - index: Tokens.STETH, - symbol: "stETH", - decimals: 18, - price: 3300 * 10 ** 8, - underlying: Tokens.NO_TOKEN - }), - MockToken({index: Tokens.CRV, symbol: "CRV", decimals: 18, price: 14 * 10 ** 7, underlying: Tokens.NO_TOKEN}), - MockToken({index: Tokens.CVX, symbol: "CVX", decimals: 18, price: 7 * 10 ** 8, underlying: Tokens.NO_TOKEN}), - MockToken({ - index: Tokens.wstETH, + index: TOKEN_wstETH, symbol: "wstETH", decimals: 18, price: 3300 * 10 ** 8, - underlying: Tokens.NO_TOKEN + underlying: TOKEN_NO_TOKEN }) ]; diff --git a/contracts/test/gas/credit/CreditFacade.gas.t.sol b/contracts/test/gas/credit/CreditFacade.gas.t.sol index eedac9d7..0667c46a 100644 --- a/contracts/test/gas/credit/CreditFacade.gas.t.sol +++ b/contracts/test/gas/credit/CreditFacade.gas.t.sol @@ -14,7 +14,7 @@ import {IntegrationTestHelper} from "../../helpers/IntegrationTestHelper.sol"; import {AdapterMock} from "../../mocks/core/AdapterMock.sol"; // SUITES -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; contract CreditFacadeGasTest is IntegrationTestHelper { function _zeroAllLTs() internal { @@ -46,7 +46,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -74,7 +74,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }), MultiCall({target: address(adapterMock), callData: abi.encodeCall(AdapterMock.dumbCall, ())}) @@ -105,7 +105,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }), MultiCall({target: address(adapterMock), callData: abi.encodeCall(AdapterMock.dumbCall, ())}), @@ -131,8 +131,8 @@ contract CreditFacadeGasTest is IntegrationTestHelper { vm.prank(CONFIGURATOR); gauge.updateEpoch(); - tokenTestSuite.mint(Tokens.LINK, USER, LINK_ACCOUNT_AMOUNT); - tokenTestSuite.approve(Tokens.LINK, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_LINK, USER, LINK_ACCOUNT_AMOUNT); + tokenTestSuite.approve(TOKEN_LINK, USER, address(creditManager)); MultiCall[] memory calls = MultiCallBuilder.build( MultiCall({ @@ -142,28 +142,28 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.LINK), LINK_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_LINK), LINK_ACCOUNT_AMOUNT) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.WETH), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) + (tokenTestSuite.addressOf(TOKEN_WETH), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) ) }) ); @@ -185,8 +185,8 @@ contract CreditFacadeGasTest is IntegrationTestHelper { vm.prank(CONFIGURATOR); gauge.updateEpoch(); - tokenTestSuite.mint(Tokens.LINK, USER, LINK_ACCOUNT_AMOUNT); - tokenTestSuite.approve(Tokens.LINK, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_LINK, USER, LINK_ACCOUNT_AMOUNT); + tokenTestSuite.approve(TOKEN_LINK, USER, address(creditManager)); MultiCall[] memory calls = MultiCallBuilder.build( MultiCall({ @@ -196,14 +196,14 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.LINK), LINK_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_LINK), LINK_ACCOUNT_AMOUNT) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) ) }), MultiCall({target: address(adapterMock), callData: abi.encodeCall(AdapterMock.dumbCall, ())}) @@ -234,7 +234,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -274,7 +274,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -308,8 +308,8 @@ contract CreditFacadeGasTest is IntegrationTestHelper { vm.prank(CONFIGURATOR); gauge.updateEpoch(); - tokenTestSuite.mint(Tokens.LINK, USER, LINK_ACCOUNT_AMOUNT); - tokenTestSuite.approve(Tokens.LINK, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_LINK, USER, LINK_ACCOUNT_AMOUNT); + tokenTestSuite.approve(TOKEN_LINK, USER, address(creditManager)); MultiCall[] memory calls = MultiCallBuilder.build( MultiCall({ @@ -319,14 +319,14 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.LINK), LINK_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_LINK), LINK_ACCOUNT_AMOUNT) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) ) }) ); @@ -342,7 +342,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) ) }), MultiCall({ @@ -374,7 +374,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -409,7 +409,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -449,7 +449,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -457,8 +457,8 @@ contract CreditFacadeGasTest is IntegrationTestHelper { vm.prank(USER); address creditAccount = creditFacade.openCreditAccount(USER, calls, 0); - tokenTestSuite.burn(Tokens.DAI, creditAccount, DAI_ACCOUNT_AMOUNT * 2); - tokenTestSuite.mint(Tokens.LINK, creditAccount, LINK_ACCOUNT_AMOUNT * 3); + tokenTestSuite.burn(TOKEN_DAI, creditAccount, DAI_ACCOUNT_AMOUNT * 2); + tokenTestSuite.mint(TOKEN_LINK, creditAccount, LINK_ACCOUNT_AMOUNT * 3); calls = MultiCallBuilder.build( MultiCall({target: address(adapterMock), callData: abi.encodeCall(AdapterMock.dumbCall, ())}), @@ -466,7 +466,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(int256(LINK_ACCOUNT_AMOUNT * 3)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(int256(LINK_ACCOUNT_AMOUNT * 3)), 0) ) }) ); @@ -496,7 +496,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -539,7 +539,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -577,8 +577,8 @@ contract CreditFacadeGasTest is IntegrationTestHelper { /// @dev G:[FA-16]: closeCreditAccount with debt and two tokens function test_G_FA_16_closeCreditAccount_gas_estimate_3() public creditTest { tokenTestSuite.mint(underlying, USER, DAI_ACCOUNT_AMOUNT); - tokenTestSuite.mint(Tokens.LINK, USER, LINK_ACCOUNT_AMOUNT); - tokenTestSuite.approve(Tokens.LINK, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_LINK, USER, LINK_ACCOUNT_AMOUNT); + tokenTestSuite.approve(TOKEN_LINK, USER, address(creditManager)); MultiCall[] memory calls = MultiCallBuilder.build( MultiCall({ @@ -588,13 +588,13 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.LINK), LINK_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_LINK), LINK_ACCOUNT_AMOUNT) ) }) ); @@ -604,7 +604,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { vm.roll(block.number + 1); - address linkToken = tokenTestSuite.addressOf(Tokens.LINK); + address linkToken = tokenTestSuite.addressOf(TOKEN_LINK); uint256 gasBefore = gasleft(); @@ -649,7 +649,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -694,7 +694,7 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }) ); @@ -720,11 +720,11 @@ contract CreditFacadeGasTest is IntegrationTestHelper { /// @dev G:[FA-19]: liquidateCreditAccount with two tokens function test_G_FA_19_liquidateCreditAccount_gas_estimate_2() public creditTest { tokenTestSuite.mint(underlying, USER, DAI_ACCOUNT_AMOUNT); - tokenTestSuite.mint(Tokens.LINK, USER, LINK_ACCOUNT_AMOUNT); - tokenTestSuite.approve(Tokens.LINK, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_LINK, USER, LINK_ACCOUNT_AMOUNT); + tokenTestSuite.approve(TOKEN_LINK, USER, address(creditManager)); - tokenTestSuite.mint(Tokens.DAI, FRIEND, DAI_ACCOUNT_AMOUNT * 100); - tokenTestSuite.approve(Tokens.DAI, FRIEND, address(creditManager)); + tokenTestSuite.mint(TOKEN_DAI, FRIEND, DAI_ACCOUNT_AMOUNT * 100); + tokenTestSuite.approve(TOKEN_DAI, FRIEND, address(creditManager)); MultiCall[] memory calls = MultiCallBuilder.build( MultiCall({ @@ -734,13 +734,13 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.LINK), LINK_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_LINK), LINK_ACCOUNT_AMOUNT) ) }) ); @@ -769,11 +769,11 @@ contract CreditFacadeGasTest is IntegrationTestHelper { vm.prank(CONFIGURATOR); gauge.updateEpoch(); - tokenTestSuite.mint(Tokens.LINK, USER, LINK_ACCOUNT_AMOUNT); - tokenTestSuite.approve(Tokens.LINK, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_LINK, USER, LINK_ACCOUNT_AMOUNT); + tokenTestSuite.approve(TOKEN_LINK, USER, address(creditManager)); - tokenTestSuite.mint(Tokens.DAI, FRIEND, DAI_ACCOUNT_AMOUNT * 100); - tokenTestSuite.approve(Tokens.DAI, FRIEND, address(creditManager)); + tokenTestSuite.mint(TOKEN_DAI, FRIEND, DAI_ACCOUNT_AMOUNT * 100); + tokenTestSuite.approve(TOKEN_DAI, FRIEND, address(creditManager)); MultiCall[] memory calls = MultiCallBuilder.build( MultiCall({ @@ -783,14 +783,14 @@ contract CreditFacadeGasTest is IntegrationTestHelper { MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.LINK), LINK_ACCOUNT_AMOUNT) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_LINK), LINK_ACCOUNT_AMOUNT) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(int256(LINK_ACCOUNT_AMOUNT)), 0) ) }) ); diff --git a/contracts/test/helpers/BalanceHelper.sol b/contracts/test/helpers/BalanceHelper.sol index de62aca8..7228a8d7 100644 --- a/contracts/test/helpers/BalanceHelper.sol +++ b/contracts/test/helpers/BalanceHelper.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.17; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {TokensTestSuite} from "../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {BalanceEngine} from "./BalanceEngine.sol"; import "forge-std/Vm.sol"; @@ -149,18 +149,18 @@ contract BalanceHelper is BalanceEngine { _; } - function expectBalance(Tokens t, address holder, uint256 expectedBalance) internal withTokenSuite { + function expectBalance(uint256 t, address holder, uint256 expectedBalance) internal withTokenSuite { expectBalance(t, holder, expectedBalance, ""); } - function expectBalance(Tokens t, address holder, uint256 expectedBalance, string memory reason) + function expectBalance(uint256 t, address holder, uint256 expectedBalance, string memory reason) internal withTokenSuite { expectBalance(tokenTestSuite.addressOf(t), holder, expectedBalance, reason); } - function expectBalanceGe(Tokens t, address holder, uint256 minBalance, string memory reason) + function expectBalanceGe(uint256 t, address holder, uint256 minBalance, string memory reason) internal withTokenSuite { @@ -169,21 +169,21 @@ contract BalanceHelper is BalanceEngine { expectBalanceGe(tokenTestSuite.addressOf(t), holder, minBalance, reason); } - function expectBalanceLe(Tokens t, address holder, uint256 maxBalance, string memory reason) + function expectBalanceLe(uint256 t, address holder, uint256 maxBalance, string memory reason) internal withTokenSuite { expectBalanceLe(tokenTestSuite.addressOf(t), holder, maxBalance, reason); } - function expectAllowance(Tokens t, address owner, address spender, uint256 expectedAllowance) + function expectAllowance(uint256 t, address owner, address spender, uint256 expectedAllowance) internal withTokenSuite { expectAllowance(t, owner, spender, expectedAllowance, ""); } - function expectAllowance(Tokens t, address owner, address spender, uint256 expectedAllowance, string memory reason) + function expectAllowance(uint256 t, address owner, address spender, uint256 expectedAllowance, string memory reason) internal withTokenSuite { diff --git a/contracts/test/helpers/IntegrationTestHelper.sol b/contracts/test/helpers/IntegrationTestHelper.sol index d0134211..cd7b4b92 100644 --- a/contracts/test/helpers/IntegrationTestHelper.sol +++ b/contracts/test/helpers/IntegrationTestHelper.sol @@ -43,7 +43,7 @@ import {TestHelper} from "../lib/helper.sol"; import {ERC20Mock} from "../mocks/token/ERC20Mock.sol"; import {DegenNFTMock} from "../mocks/token/DegenNFTMock.sol"; import "../lib/constants.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {PriceFeedMock} from "../mocks/oracles/PriceFeedMock.sol"; import {BalanceHelper} from "./BalanceHelper.sol"; import {BotListV3} from "../../core/BotListV3.sol"; @@ -90,7 +90,7 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager { address public weth; bool public anyUnderlying = true; - Tokens public underlyingT = Tokens.DAI; + uint256 public underlyingT = TOKEN_DAI; address public underlying; @@ -154,7 +154,7 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager { _; } - modifier withUnderlying(Tokens t) { + modifier withUnderlying(uint256 t) { anyUnderlying = false; underlyingT = t; _; @@ -214,7 +214,7 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager { vm.deal(address(this), 100 * WAD); tokenTestSuite.topUpWETH{value: 100 * WAD}(); - weth = tokenTestSuite.addressOf(Tokens.WETH); + weth = tokenTestSuite.addressOf(TOKEN_WETH); vm.startPrank(CONFIGURATOR); GenesisFactory gp = new GenesisFactory(); @@ -379,7 +379,7 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager { } function _deployMockCreditAndPool() internal { - require(underlyingT == Tokens.DAI, "IntegrationTestHelper: Only DAI mock config is supported"); + require(underlyingT == TOKEN_DAI, "IntegrationTestHelper: Only DAI mock config is supported"); IPoolV3DeployConfig creditConfig = new MockCreditConfig(); _deployCreditAndPool(creditConfig); } @@ -614,15 +614,17 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager { } } - function expectTokenIsEnabled(address creditAccount, Tokens t, bool expectedState) internal { + function expectTokenIsEnabled(address creditAccount, uint256 t, bool expectedState) internal { expectTokenIsEnabled(creditAccount, t, expectedState, ""); } - function expectTokenIsEnabled(address creditAccount, Tokens t, bool expectedState, string memory reason) internal { + function expectTokenIsEnabled(address creditAccount, uint256 t, bool expectedState, string memory reason) + internal + { expectTokenIsEnabled(creditAccount, tokenTestSuite.addressOf(t), expectedState, reason); } - function addCollateral(Tokens t, uint256 amount) internal { + function addCollateral(uint256 t, uint256 amount) internal { tokenTestSuite.mint(t, USER, amount); tokenTestSuite.approve(t, USER, address(creditManager)); @@ -637,7 +639,7 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager { } function _checkForWETHTest(address tester) internal { - expectBalance(Tokens.WETH, tester, WETH_TEST_AMOUNT); + expectBalance(TOKEN_WETH, tester, WETH_TEST_AMOUNT); expectEthBalance(tester, 0); } @@ -652,10 +654,10 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager { IWETH(weth).deposit{value: tester.balance}(); } - IERC20(weth).transfer(address(this), tokenTestSuite.balanceOf(Tokens.WETH, tester)); + IERC20(weth).transfer(address(this), tokenTestSuite.balanceOf(TOKEN_WETH, tester)); vm.stopPrank(); - expectBalance(Tokens.WETH, tester, 0); + expectBalance(TOKEN_WETH, tester, 0); vm.deal(tester, WETH_TEST_AMOUNT); } diff --git a/contracts/test/integration/credit/CloseCreditAccount.int.sol b/contracts/test/integration/credit/CloseCreditAccount.int.sol index 7f59d693..08b448e3 100644 --- a/contracts/test/integration/credit/CloseCreditAccount.int.sol +++ b/contracts/test/integration/credit/CloseCreditAccount.int.sol @@ -37,7 +37,7 @@ import {BotMock} from "../../mocks/core/BotMock.sol"; // SUITES -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {IPoolV3} from "../../../interfaces/IPoolV3.sol"; @@ -92,7 +92,7 @@ contract CloseCreditAccountIntegrationTest is IntegrationTestHelper, ICreditFaca MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT / 2) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT / 2) ) }) ); @@ -196,7 +196,7 @@ contract CloseCreditAccountIntegrationTest is IntegrationTestHelper, ICreditFaca /// @dev I:[CCA-5]: closeCreditAccount returns account to the factory and removes owner function test_I_CCA_05_closeCreditAccount_returns_account_to_the_factory_and_removes_owner() public creditTest { - address daiToken = tokenTestSuite.addressOf(Tokens.DAI); + address daiToken = tokenTestSuite.addressOf(TOKEN_DAI); MultiCall[] memory calls = MultiCallBuilder.build( MultiCall({ target: address(creditFacade), diff --git a/contracts/test/integration/credit/CreditConfigurator.int.t.sol b/contracts/test/integration/credit/CreditConfigurator.int.t.sol index 70985abd..e28c1f5f 100644 --- a/contracts/test/integration/credit/CreditConfigurator.int.t.sol +++ b/contracts/test/integration/credit/CreditConfigurator.int.t.sol @@ -35,7 +35,7 @@ import {PhantomTokenMock} from "../../mocks/token/PhantomTokenMock.sol"; // SUITES import {TokensTestSuite} from "../../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {CollateralTokenHuman} from "../../interfaces/ICreditConfig.sol"; @@ -150,14 +150,14 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf ); CollateralTokenHuman[8] memory collateralTokenOpts = [ - CollateralTokenHuman({token: Tokens.DAI, lt: DEFAULT_UNDERLYING_LT}), - CollateralTokenHuman({token: Tokens.USDC, lt: 9000}), - CollateralTokenHuman({token: Tokens.USDT, lt: 8800}), - CollateralTokenHuman({token: Tokens.WETH, lt: 8300}), - CollateralTokenHuman({token: Tokens.LINK, lt: 7300}), - CollateralTokenHuman({token: Tokens.CRV, lt: 7300}), - CollateralTokenHuman({token: Tokens.CVX, lt: 7300}), - CollateralTokenHuman({token: Tokens.STETH, lt: 7300}) + CollateralTokenHuman({token: TOKEN_DAI, lt: DEFAULT_UNDERLYING_LT}), + CollateralTokenHuman({token: TOKEN_USDC, lt: 9000}), + CollateralTokenHuman({token: TOKEN_USDT, lt: 8800}), + CollateralTokenHuman({token: TOKEN_WETH, lt: 8300}), + CollateralTokenHuman({token: TOKEN_LINK, lt: 7300}), + CollateralTokenHuman({token: TOKEN_CRV, lt: 7300}), + CollateralTokenHuman({token: TOKEN_CVX, lt: 7300}), + CollateralTokenHuman({token: TOKEN_STETH, lt: 7300}) ]; uint256 len = collateralTokenOpts.length; @@ -286,7 +286,7 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf vm.expectRevert(PriceFeedDoesNotExistException.selector); creditConfigurator.addCollateralToken(unknownPricefeedToken, 9300); - address nonQuotedToken = tokenTestSuite.addressOf(Tokens.wstETH); + address nonQuotedToken = tokenTestSuite.addressOf(TOKEN_wstETH); vm.expectRevert(TokenIsNotQuotedException.selector); creditConfigurator.addCollateralToken(nonQuotedToken, 9300); @@ -302,7 +302,7 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf function test_I_CC_04_addCollateralToken_adds_new_token_to_creditManager_and_set_lt() public creditTest { uint256 tokensCountBefore = creditManager.collateralTokensCount(); - address newToken = tokenTestSuite.addressOf(Tokens.wstETH); + address newToken = tokenTestSuite.addressOf(TOKEN_wstETH); makeTokenQuoted(newToken, 1, uint96(type(int96).max)); vm.expectEmit(true, false, false, false); @@ -332,7 +332,7 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf vm.expectRevert(TokenNotAllowedException.selector); creditConfigurator.setLiquidationThreshold(underlying, 1); - address usdcToken = tokenTestSuite.addressOf(Tokens.USDC); + address usdcToken = tokenTestSuite.addressOf(TOKEN_USDC); uint16 maxAllowedLT = creditManager.liquidationThresholds(underlying); vm.expectRevert(IncorrectLiquidationThresholdException.selector); @@ -343,7 +343,7 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf /// @dev I:[CC-6]: setLiquidationThreshold sets liquidation threshold in creditManager function test_I_CC_06_setLiquidationThreshold_sets_liquidation_threshold_in_creditManager() public creditTest { - address usdcToken = tokenTestSuite.addressOf(Tokens.USDC); + address usdcToken = tokenTestSuite.addressOf(TOKEN_USDC); uint16 newLT = 24; vm.expectEmit(true, false, false, true); @@ -376,7 +376,7 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf /// @dev I:[CC-8]: allowToken works correctly function test_I_CC_08_allowToken_works_correctly() public creditTest { - address usdcToken = tokenTestSuite.addressOf(Tokens.USDC); + address usdcToken = tokenTestSuite.addressOf(TOKEN_USDC); uint256 forbiddenMask = creditFacade.forbiddenTokenMask(); vm.prank(CONFIGURATOR); @@ -398,7 +398,7 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf /// @dev I:[CC-9]: forbidToken works correctly function test_I_CC_09_forbidToken_works_correctly() public creditTest { - address usdcToken = tokenTestSuite.addressOf(Tokens.USDC); + address usdcToken = tokenTestSuite.addressOf(TOKEN_USDC); uint256 usdcMask = creditManager.getTokenMaskOrRevert(usdcToken); vm.expectEmit(true, false, false, false); @@ -657,7 +657,7 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf /// @dev I:[CC-18]: setFees updates LT for underlying or reverts function test_I_CC_18_setFees_updates_LT_for_underlying_or_reverts() public creditTest { - address usdc = tokenTestSuite.addressOf(Tokens.USDC); + address usdc = tokenTestSuite.addressOf(TOKEN_USDC); uint16 expectedLT = PERCENTAGE_FACTOR - DEFAULT_LIQUIDATION_PREMIUM - 2 * DEFAULT_FEE_LIQUIDATION; @@ -904,9 +904,9 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf creditConfigurator.addEmergencyLiquidator(DUMB_ADDRESS); creditConfigurator.addEmergencyLiquidator(DUMB_ADDRESS2); - address crvToken = tokenTestSuite.addressOf(Tokens.CRV); + address crvToken = tokenTestSuite.addressOf(TOKEN_CRV); uint256 crvMask = creditManager.getTokenMaskOrRevert(crvToken); - address cvxToken = tokenTestSuite.addressOf(Tokens.CVX); + address cvxToken = tokenTestSuite.addressOf(TOKEN_CVX); uint256 cvxMask = creditManager.getTokenMaskOrRevert(cvxToken); creditConfigurator.forbidToken(crvToken); @@ -1100,8 +1100,8 @@ contract CreditConfiguratorIntegrationTest is IntegrationTestHelper, ICreditConf /// @dev I:[CC-30] rampLiquidationThreshold works correctly function test_I_CC_30_rampLiquidationThreshold_works_correctly() public creditTest { - address dai = tokenTestSuite.addressOf(Tokens.DAI); - address usdc = tokenTestSuite.addressOf(Tokens.USDC); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); + address usdc = tokenTestSuite.addressOf(TOKEN_USDC); vm.expectRevert(TokenNotAllowedException.selector); vm.prank(CONFIGURATOR); diff --git a/contracts/test/integration/credit/ManageDebt.int.t.sol b/contracts/test/integration/credit/ManageDebt.int.t.sol index 5fae23ed..d9350b70 100644 --- a/contracts/test/integration/credit/ManageDebt.int.t.sol +++ b/contracts/test/integration/credit/ManageDebt.int.t.sol @@ -11,7 +11,7 @@ import {MultiCallBuilder} from "../../lib/MultiCallBuilder.sol"; // TESTS import "../../lib/constants.sol"; import {BOT_PERMISSIONS_SET_FLAG, PERCENTAGE_FACTOR} from "../../../libraries/Constants.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {IntegrationTestHelper} from "../../helpers/IntegrationTestHelper.sol"; // EXCEPTIONS @@ -83,7 +83,7 @@ contract ManegDebtIntegrationTest is IntegrationTestHelper, ICreditFacadeV3Event uint256 amount = maxDebt - DAI_ACCOUNT_AMOUNT + 1; - tokenTestSuite.mint(Tokens.DAI, address(pool), amount); + tokenTestSuite.mint(TOKEN_DAI, address(pool), amount); vm.expectRevert(BorrowAmountOutOfLimitsException.selector); @@ -125,7 +125,7 @@ contract ManegDebtIntegrationTest is IntegrationTestHelper, ICreditFacadeV3Event function test_I_MD_05_increaseDebt_reverts_with_forbidden_tokens() public creditTest { (address creditAccount,) = _openTestCreditAccount(); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address link = tokenTestSuite.addressOf(TOKEN_LINK); uint256 linkMask = creditManager.getTokenMaskOrRevert(link); vm.prank(USER); @@ -199,7 +199,7 @@ contract ManegDebtIntegrationTest is IntegrationTestHelper, ICreditFacadeV3Event uint256 amount = DAI_ACCOUNT_AMOUNT - minDebt + 1; - tokenTestSuite.mint(Tokens.DAI, address(pool), amount); + tokenTestSuite.mint(TOKEN_DAI, address(pool), amount); vm.expectRevert(BorrowAmountOutOfLimitsException.selector); @@ -217,7 +217,7 @@ contract ManegDebtIntegrationTest is IntegrationTestHelper, ICreditFacadeV3Event /// @dev I:[MD-8]: manageDebt correctly increases debt function test_I_MD_08_manageDebt_correctly_increases_debt(uint120 amount) public creditTest { - tokenTestSuite.mint(Tokens.DAI, INITIAL_LP, amount); + tokenTestSuite.mint(TOKEN_DAI, INITIAL_LP, amount); vm.assume(amount > 1); diff --git a/contracts/test/integration/credit/Multicall.int.t.sol b/contracts/test/integration/credit/Multicall.int.t.sol index 39ff0f01..b3cc3417 100644 --- a/contracts/test/integration/credit/Multicall.int.t.sol +++ b/contracts/test/integration/credit/Multicall.int.t.sol @@ -27,7 +27,7 @@ import "../../../interfaces/IExceptions.sol"; import {AdapterMock} from "../../mocks//core/AdapterMock.sol"; // SUITES -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; /// @title CreditFacadeTest /// @notice Designed for unit test purposes only @@ -106,12 +106,12 @@ contract MultiCallIntegrationTest is (, uint256 maxDebt) = creditFacade.debtLimits(); (address creditAccount,) = _openTestCreditAccount(); - expectTokenIsEnabled(creditAccount, Tokens.USDC, false); + expectTokenIsEnabled(creditAccount, TOKEN_USDC, false); - address usdcToken = tokenTestSuite.addressOf(Tokens.USDC); + address usdcToken = tokenTestSuite.addressOf(TOKEN_USDC); - tokenTestSuite.mint(Tokens.USDC, USER, 512); - tokenTestSuite.approve(Tokens.USDC, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_USDC, USER, 512); + tokenTestSuite.approve(TOKEN_USDC, USER, address(creditManager)); vm.expectCall( address(creditManager), @@ -140,8 +140,8 @@ contract MultiCallIntegrationTest is vm.prank(USER); creditFacade.multicall(creditAccount, calls); - expectBalance(Tokens.USDC, creditAccount, 512); - expectTokenIsEnabled(creditAccount, Tokens.USDC, true); + expectBalance(TOKEN_USDC, creditAccount, 512); + expectTokenIsEnabled(creditAccount, TOKEN_USDC, true); } /// @dev I:[MC-6]: multicall addCollateral and oncreaseDebt works with creditFacade calls as expected @@ -153,9 +153,9 @@ contract MultiCallIntegrationTest is (address creditAccount,) = _openTestCreditAccount(); vm.roll(block.number + 1); - address usdcToken = tokenTestSuite.addressOf(Tokens.USDC); - tokenTestSuite.mint(Tokens.USDC, USER, USDC_EXCHANGE_AMOUNT); - tokenTestSuite.approve(Tokens.USDC, USER, address(creditManager)); + address usdcToken = tokenTestSuite.addressOf(TOKEN_USDC); + tokenTestSuite.mint(TOKEN_USDC, USER, USDC_EXCHANGE_AMOUNT); + tokenTestSuite.approve(TOKEN_USDC, USER, address(creditManager)); uint256 usdcMask = creditManager.getTokenMaskOrRevert(usdcToken); @@ -224,9 +224,9 @@ contract MultiCallIntegrationTest is (address creditAccount,) = _openTestCreditAccount(); vm.roll(block.number + 1); - address usdcToken = tokenTestSuite.addressOf(Tokens.USDC); - tokenTestSuite.mint(Tokens.USDC, USER, USDC_EXCHANGE_AMOUNT); - tokenTestSuite.approve(Tokens.USDC, USER, address(creditManager)); + address usdcToken = tokenTestSuite.addressOf(TOKEN_USDC); + tokenTestSuite.mint(TOKEN_USDC, USER, USDC_EXCHANGE_AMOUNT); + tokenTestSuite.approve(TOKEN_USDC, USER, address(creditManager)); uint256 usdcMask = creditManager.getTokenMaskOrRevert(usdcToken); @@ -357,7 +357,7 @@ contract MultiCallIntegrationTest is uint256 expectedDAI = 1000; uint256 expectedLINK = 2000; - address tokenLINK = tokenTestSuite.addressOf(Tokens.LINK); + address tokenLINK = tokenTestSuite.addressOf(TOKEN_LINK); BalanceDelta[] memory expectedBalances = new BalanceDelta[](2); expectedBalances[0] = BalanceDelta({token: underlying, amount: int256(expectedDAI)}); @@ -365,11 +365,11 @@ contract MultiCallIntegrationTest is expectedBalances[1] = BalanceDelta({token: tokenLINK, amount: int256(expectedLINK)}); // TOKEN PREPARATION - tokenTestSuite.mint(Tokens.DAI, USER, expectedDAI * 3); - tokenTestSuite.mint(Tokens.LINK, USER, expectedLINK * 3); + tokenTestSuite.mint(TOKEN_DAI, USER, expectedDAI * 3); + tokenTestSuite.mint(TOKEN_LINK, USER, expectedLINK * 3); - tokenTestSuite.approve(Tokens.DAI, USER, address(creditManager)); - tokenTestSuite.approve(Tokens.LINK, USER, address(creditManager)); + tokenTestSuite.approve(TOKEN_DAI, USER, address(creditManager)); + tokenTestSuite.approve(TOKEN_LINK, USER, address(creditManager)); vm.prank(USER); creditFacade.multicall( @@ -467,7 +467,7 @@ contract MultiCallIntegrationTest is (address creditAccount,) = _openTestCreditAccount(); uint256[] memory collateralHints = new uint256[](1); - collateralHints[0] = creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(Tokens.USDC)); + collateralHints[0] = creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(TOKEN_USDC)); uint256 enabledTokensMap = creditManager.enabledTokensMaskOf(creditAccount); diff --git a/contracts/test/integration/credit/OpenCreditAccount.int.t.sol b/contracts/test/integration/credit/OpenCreditAccount.int.t.sol index 08cce1b8..1cccf28e 100644 --- a/contracts/test/integration/credit/OpenCreditAccount.int.t.sol +++ b/contracts/test/integration/credit/OpenCreditAccount.int.t.sol @@ -28,7 +28,7 @@ import {IntegrationTestHelper} from "../../helpers/IntegrationTestHelper.sol"; import "../../lib/constants.sol"; // SUITES -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; // EXCEPTIONS import "../../../interfaces/IExceptions.sol"; @@ -46,8 +46,8 @@ contract OpenCreditAccountIntegrationTest is IntegrationTestHelper, ICreditFacad uint256 cumulativeAtOpen = pool.baseInterestIndex(); // pool.setCumulativeIndexNow(cumulativeAtOpen); - tokenTestSuite.mint(Tokens.DAI, USER, DAI_ACCOUNT_AMOUNT); - tokenTestSuite.approve(Tokens.DAI, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_DAI, USER, DAI_ACCOUNT_AMOUNT); + tokenTestSuite.approve(TOKEN_DAI, USER, address(creditManager)); MultiCall[] memory calls = MultiCallBuilder.build( MultiCall({ @@ -57,7 +57,7 @@ contract OpenCreditAccountIntegrationTest is IntegrationTestHelper, ICreditFacad MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(Tokens.DAI), DAI_ACCOUNT_AMOUNT / 2) + ICreditFacadeV3Multicall.addCollateral, (tokenTestSuite.addressOf(TOKEN_DAI), DAI_ACCOUNT_AMOUNT / 2) ) }) ); @@ -71,7 +71,7 @@ contract OpenCreditAccountIntegrationTest is IntegrationTestHelper, ICreditFacad assertEq(debt, DAI_ACCOUNT_AMOUNT, "Incorrect borrowed amount set in CA"); assertEq(cumulativeIndexLastUpdate, cumulativeAtOpen, "Incorrect cumulativeIndexLastUpdate set in CA"); - expectBalance(Tokens.DAI, creditAccount, DAI_ACCOUNT_AMOUNT + DAI_ACCOUNT_AMOUNT / 2); + expectBalance(TOKEN_DAI, creditAccount, DAI_ACCOUNT_AMOUNT + DAI_ACCOUNT_AMOUNT / 2); // assertEq(pool.lendAmount(), DAI_ACCOUNT_AMOUNT, "Incorrect DAI_ACCOUNT_AMOUNT in Pool call"); // assertEq(pool.lendAccount(), creditAccount, "Incorrect credit account in lendCreditAccount call"); // assertEq(creditManager.creditAccounts(USER), creditAccount, "Credit account is not associated with user"); @@ -182,8 +182,8 @@ contract OpenCreditAccountIntegrationTest is IntegrationTestHelper, ICreditFacad /// @dev I:[OCA-6]: openCreditAccount runs operations in correct order function test_I_OCA_06_openCreditAccount_runs_operations_in_correct_order() public creditTest { - tokenTestSuite.mint(Tokens.DAI, USER, WAD); - tokenTestSuite.approve(Tokens.DAI, USER, address(creditManager)); + tokenTestSuite.mint(TOKEN_DAI, USER, WAD); + tokenTestSuite.approve(TOKEN_DAI, USER, address(creditManager)); uint256 snapshot = vm.snapshot(); vm.prank(address(creditManager)); @@ -244,7 +244,7 @@ contract OpenCreditAccountIntegrationTest is IntegrationTestHelper, ICreditFacad amount = bound(amount, 10000, DAI_ACCOUNT_AMOUNT); token1 = uint8(bound(token1, 2, creditManager.collateralTokensCount() - 1)); - tokenTestSuite.mint(Tokens.DAI, address(creditManager.pool()), type(uint96).max); + tokenTestSuite.mint(TOKEN_DAI, address(creditManager.pool()), type(uint96).max); vm.prank(CONFIGURATOR); creditConfigurator.setMaxDebtPerBlockMultiplier(type(uint8).max); @@ -352,7 +352,7 @@ contract OpenCreditAccountIntegrationTest is IntegrationTestHelper, ICreditFacad assertEq(debt, 0, "Incorrect borrowed amount set in CA"); - expectBalance(Tokens.DAI, creditAccount, 0); + expectBalance(TOKEN_DAI, creditAccount, 0); assertEq( creditManager.enabledTokensMaskOf(creditAccount), UNDERLYING_TOKEN_MASK, "Incorrect enabled token mask" diff --git a/contracts/test/integration/credit/Quotas.int.t.sol b/contracts/test/integration/credit/Quotas.int.t.sol index 2fe5ed10..323894f7 100644 --- a/contracts/test/integration/credit/Quotas.int.t.sol +++ b/contracts/test/integration/credit/Quotas.int.t.sol @@ -29,7 +29,7 @@ import "../../lib/constants.sol"; // SUITES -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {IntegrationTestHelper} from "../../helpers/IntegrationTestHelper.sol"; @@ -58,8 +58,8 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events /// @dev I:[CMQ-3]: updateQuotas works correctly function test_I_CMQ_03_updateQuotas_works_correctly() public creditTest { - _setQuotaParams(tokenTestSuite.addressOf(Tokens.LINK), 10_00, uint96(1_000_000 * WAD)); - _setQuotaParams(tokenTestSuite.addressOf(Tokens.USDT), 500, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_LINK), 10_00, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_USDT), 500, uint96(1_000_000 * WAD)); (address creditAccount,) = _openTestCreditAccount(); @@ -68,7 +68,7 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events assertEq(cumulativeQuotaInterest, 1, "SETUP: Cumulative quota interest was not updated correctly"); { - address link = tokenTestSuite.addressOf(Tokens.LINK); + address link = tokenTestSuite.addressOf(TOKEN_LINK); vm.expectRevert(CallerNotCreditFacadeException.selector); vm.prank(FRIEND); creditManager.updateQuota({ @@ -87,7 +87,7 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.LINK), 100_000, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_LINK), 100_000, 0) ) }) ); @@ -96,14 +96,14 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events address(poolQuotaKeeper), abi.encodeCall( IPoolQuotaKeeperV3.updateQuota, - (creditAccount, tokenTestSuite.addressOf(Tokens.LINK), 100_000, 0, maxQuota) + (creditAccount, tokenTestSuite.addressOf(TOKEN_LINK), 100_000, 0, maxQuota) ) ); vm.prank(USER); creditFacade.multicall(creditAccount, calls); - expectTokenIsEnabled(creditAccount, tokenTestSuite.addressOf(Tokens.LINK), true, "Incorrect tokensToEnble"); + expectTokenIsEnabled(creditAccount, tokenTestSuite.addressOf(TOKEN_LINK), true, "Incorrect tokensToEnble"); vm.warp(block.timestamp + 365 days); @@ -111,7 +111,7 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.LINK), -100_000, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_LINK), -100_000, 0) ) }) ); @@ -119,7 +119,7 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events vm.prank(USER); creditFacade.multicall(creditAccount, calls); - expectTokenIsEnabled(creditAccount, tokenTestSuite.addressOf(Tokens.LINK), false, "Incorrect tokensToEnble"); + expectTokenIsEnabled(creditAccount, tokenTestSuite.addressOf(TOKEN_LINK), false, "Incorrect tokensToEnble"); (,, cumulativeQuotaInterest,,,,,) = creditManager.creditAccountInfo(creditAccount); @@ -143,8 +143,8 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events /// @dev I:[CMQ-4]: Quotas are handled correctly on debt decrease: amount < quota interest case function test_I_CMQ_04_quotas_are_handled_correctly_at_repayment_partial_case() public creditTest { - _setQuotaParams(tokenTestSuite.addressOf(Tokens.LINK), 10_00, uint96(1_000_000 * WAD)); - _setQuotaParams(tokenTestSuite.addressOf(Tokens.USDT), 500, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_LINK), 10_00, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_USDT), 500, uint96(1_000_000 * WAD)); (address creditAccount,) = _openTestCreditAccount(); vm.roll(block.timestamp + 1); @@ -153,13 +153,13 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.LINK), 100_000, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_LINK), 100_000, 0) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.USDT), 200_000, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_USDT), 200_000, 0) ) }) ); @@ -204,8 +204,8 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events /// @dev I:[CMQ-5]: Quotas are handled correctly on debt decrease: amount >= quota interest case function test_I_CMQ_05_quotas_are_handled_correctly_at_repayment_full_case() public creditTest { - _setQuotaParams(tokenTestSuite.addressOf(Tokens.LINK), 1000, uint96(1_000_000 * WAD)); - _setQuotaParams(tokenTestSuite.addressOf(Tokens.USDT), 500, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_LINK), 1000, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_USDT), 500, uint96(1_000_000 * WAD)); (address creditAccount,) = _openTestCreditAccount(); vm.roll(block.timestamp + 1); @@ -214,13 +214,13 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.LINK), 100_000, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_LINK), 100_000, 0) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.USDT), 200_000, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_USDT), 200_000, 0) ) }) ); @@ -255,8 +255,8 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events /// @dev I:[CMQ-6]: Quotas are disabled on closing an account function test_I_CMQ_06_quotas_are_disabled_on_close_account_and_all_quota_fees_are_repaid() public creditTest { - _setQuotaParams(tokenTestSuite.addressOf(Tokens.LINK), 10_00, uint96(1_000_000 * WAD)); - _setQuotaParams(tokenTestSuite.addressOf(Tokens.USDT), 5_00, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_LINK), 10_00, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_USDT), 5_00, uint96(1_000_000 * WAD)); (address creditAccount,) = _openTestCreditAccount(); @@ -268,14 +268,14 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(uint96(100 * WAD)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(uint96(100 * WAD)), 0) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.USDT), int96(uint96(200 * WAD)), 0) + (tokenTestSuite.addressOf(TOKEN_USDT), int96(uint96(200 * WAD)), 0) ) }) ); @@ -296,9 +296,9 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events uint256 expectedQuotasInterest = (100 * WAD * 10_00 / PERCENTAGE_FACTOR + 200 * WAD * 5_00 / PERCENTAGE_FACTOR) * (PERCENTAGE_FACTOR + feeInterest) / PERCENTAGE_FACTOR; - tokenTestSuite.mint(Tokens.DAI, creditAccount, borrowedAmount); + tokenTestSuite.mint(TOKEN_DAI, creditAccount, borrowedAmount); - uint256 poolBalanceBefore = tokenTestSuite.balanceOf(Tokens.DAI, address(pool)); + uint256 poolBalanceBefore = tokenTestSuite.balanceOf(TOKEN_DAI, address(pool)); vm.startPrank(USER); creditFacade.closeCreditAccount( @@ -307,13 +307,13 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.LINK), type(int96).min, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_LINK), type(int96).min, 0) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.USDT), type(int96).min, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_USDT), type(int96).min, 0) ) }), MultiCall({ @@ -332,18 +332,18 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events vm.stopPrank(); expectBalance( - Tokens.DAI, + TOKEN_DAI, address(pool), poolBalanceBefore + borrowedAmount + interestAccured + expectedQuotasInterest, "Incorrect pool balance" ); (uint96 quota, uint192 cumulativeIndexLU) = - poolQuotaKeeper.getQuota(creditAccount, tokenTestSuite.addressOf(Tokens.LINK)); + poolQuotaKeeper.getQuota(creditAccount, tokenTestSuite.addressOf(TOKEN_LINK)); assertEq(uint256(quota), 0, "Quota was not set to 0"); - (quota, cumulativeIndexLU) = poolQuotaKeeper.getQuota(creditAccount, tokenTestSuite.addressOf(Tokens.USDT)); + (quota, cumulativeIndexLU) = poolQuotaKeeper.getQuota(creditAccount, tokenTestSuite.addressOf(TOKEN_USDT)); assertEq(uint256(quota), 0, "Quota was not set to 0"); } @@ -352,8 +352,8 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events public creditTest { - _setQuotaParams(tokenTestSuite.addressOf(Tokens.LINK), 10_00, uint96(100_000 * WAD)); - _setQuotaParams(tokenTestSuite.addressOf(Tokens.USDT), 5_00, uint96(100_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_LINK), 10_00, uint96(100_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_USDT), 5_00, uint96(100_000 * WAD)); quotaLink = uint96(bound(quotaLink, 1, uint96(type(int96).max))); quotaUsdt = uint96(bound(quotaUsdt, 1, uint96(type(int96).max))); @@ -367,13 +367,13 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.LINK), int96(quotaLink), 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_LINK), int96(quotaLink), 0) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.USDT), int96(quotaUsdt), 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_USDT), int96(quotaUsdt), 0) ) }) ); @@ -402,8 +402,8 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events /// @dev I:[CMQ-08]: Credit Manager zeroes limits on quoted tokens upon incurring a loss function test_I_CMQ_08_creditManager_triggers_limit_zeroing_on_loss() public creditTest { - _setQuotaParams(tokenTestSuite.addressOf(Tokens.LINK), type(uint16).max, uint96(1_000_000 * WAD)); - _setQuotaParams(tokenTestSuite.addressOf(Tokens.USDT), 500_00, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_LINK), type(uint16).max, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_USDT), 500_00, uint96(1_000_000 * WAD)); (address creditAccount,) = _openTestCreditAccount(); @@ -412,14 +412,14 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.LINK), int96(uint96(100_000 * WAD)), 0) + (tokenTestSuite.addressOf(TOKEN_LINK), int96(uint96(100_000 * WAD)), 0) ) }), MultiCall({ target: address(creditFacade), callData: abi.encodeCall( ICreditFacadeV3Multicall.updateQuota, - (tokenTestSuite.addressOf(Tokens.USDT), int96(uint96(200 * WAD)), 0) + (tokenTestSuite.addressOf(TOKEN_USDT), int96(uint96(200 * WAD)), 0) ) }) ); @@ -430,7 +430,7 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events vm.warp(block.timestamp + 365 days); vm.roll(block.number + 100); - address[2] memory quotedTokens = [tokenTestSuite.addressOf(Tokens.USDT), tokenTestSuite.addressOf(Tokens.LINK)]; + address[2] memory quotedTokens = [tokenTestSuite.addressOf(TOKEN_USDT), tokenTestSuite.addressOf(TOKEN_LINK)]; vm.prank(LIQUIDATOR); creditFacade.liquidateCreditAccount(creditAccount, FRIEND, new MultiCall[](0)); @@ -444,10 +444,10 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events /// @dev I:[CMQ-09]: positive updateQuotas reverts on zero debt function test_I_CMQ_09_updateQuotas_with_positive_value_reverts_on_zero_debt() public creditTest { - _setQuotaParams(tokenTestSuite.addressOf(Tokens.LINK), 10_00, uint96(1_000_000 * WAD)); + _setQuotaParams(tokenTestSuite.addressOf(TOKEN_LINK), 10_00, uint96(1_000_000 * WAD)); - tokenTestSuite.mint(Tokens.DAI, address(this), 1e18); - tokenTestSuite.approve(Tokens.DAI, address(this), address(creditManager), 1e18); + tokenTestSuite.mint(TOKEN_DAI, address(this), 1e18); + tokenTestSuite.approve(TOKEN_DAI, address(this), address(creditManager), 1e18); address creditAccount = _openCreditAccount(1e18, USER, 0, 0); // (, uint256 maxDebt) = creditFacade.debtLimits(); @@ -457,7 +457,7 @@ contract QuotasIntegrationTest is IntegrationTestHelper, ICreditManagerV3Events MultiCall({ target: address(creditFacade), callData: abi.encodeCall( - ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(Tokens.LINK), 100_000, 0) + ICreditFacadeV3Multicall.updateQuota, (tokenTestSuite.addressOf(TOKEN_LINK), 100_000, 0) ) }) ); diff --git a/contracts/test/interfaces/ICreditConfig.sol b/contracts/test/interfaces/ICreditConfig.sol index a9ac8767..349fff2e 100644 --- a/contracts/test/interfaces/ICreditConfig.sol +++ b/contracts/test/interfaces/ICreditConfig.sol @@ -3,7 +3,7 @@ // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {ITokenTestSuite} from "./ITokenTestSuite.sol"; import {Contracts} from "@gearbox-protocol/sdk-gov/contracts/SupportedContracts.sol"; @@ -36,34 +36,34 @@ struct BalancerPool { struct GenericSwapPair { Contracts router; - Tokens token0; - Tokens token1; + uint256 token0; + uint256 token1; } struct UniswapV3Pair { Contracts router; - Tokens token0; - Tokens token1; + uint256 token0; + uint256 token1; uint24 fee; } struct VelodromeV2Pool { - Tokens token0; - Tokens token1; + uint256 token0; + uint256 token1; bool stable; address factory; } struct PendlePair { address market; - Tokens inputToken; - Tokens pendleToken; + uint256 inputToken; + uint256 pendleToken; uint8 status; } struct MellowUnderlyingConfig { Contracts vault; - Tokens underlying; + uint256 underlying; } struct AdapterConfig { @@ -113,19 +113,19 @@ struct CreditManagerV3DeployParams { } struct GaugeRate { - Tokens token; + uint256 token; uint16 minRate; uint16 maxRate; } struct PoolQuotaLimit { - Tokens token; + uint256 token; uint16 quotaIncreaseFee; uint96 limit; } struct CollateralTokenHuman { - Tokens token; + uint256 token; uint16 lt; } @@ -135,7 +135,7 @@ interface IPoolV3DeployConfig { function name() external view returns (string memory); function chainId() external view returns (uint256); - function underlying() external view returns (Tokens); + function underlying() external view returns (uint256); function supportsQuotas() external view returns (bool); function poolParams() external view returns (PoolV3DeployParams memory); diff --git a/contracts/test/interfaces/ITokenTestSuite.sol b/contracts/test/interfaces/ITokenTestSuite.sol index cb3be43c..5c6971b5 100644 --- a/contracts/test/interfaces/ITokenTestSuite.sol +++ b/contracts/test/interfaces/ITokenTestSuite.sol @@ -10,19 +10,6 @@ interface ITokenTestSuite { function approve(address token, address holder, address targetContract, uint256 amount) external; - // function approve( - // Tokens t, - // address holder, - // address targetContract - // ) external; - - // function approve( - // Tokens t, - // address holder, - // address targetContract, - // uint256 amount - // ) external; - function topUpWETH() external payable; function topUpWETH(address onBehalfOf, uint256 value) external; @@ -32,10 +19,4 @@ interface ITokenTestSuite { function mint(address token, address to, uint256 amount) external; function burn(address token, address from, uint256 amount) external; - - // function mint( - // Tokens t, - // address to, - // uint256 amount - // ) external; } diff --git a/contracts/test/suites/TokensTestSuite.sol b/contracts/test/suites/TokensTestSuite.sol index 8a16ee5e..54977ea6 100644 --- a/contracts/test/suites/TokensTestSuite.sol +++ b/contracts/test/suites/TokensTestSuite.sol @@ -22,21 +22,21 @@ import "../lib/constants.sol"; import {TokensTestSuiteHelper} from "./TokensTestSuiteHelper.sol"; import {MockTokensData, MockToken} from "../config/MockTokensData.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {TokenData, TokensDataLive, TokenType} from "@gearbox-protocol/sdk-gov/contracts/TokensData.sol"; import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetector.sol"; contract TokensTestSuite is Test, TokensTestSuiteHelper { using SafeERC20 for IERC20; - mapping(Tokens => address) public addressOf; - mapping(Tokens => string) public symbols; - mapping(Tokens => uint256) public prices; - mapping(Tokens => address) public priceFeedsMap; + mapping(uint256 => address) public addressOf; + mapping(uint256 => string) public symbols; + mapping(uint256 => uint256) public prices; + mapping(uint256 => address) public priceFeedsMap; - mapping(Tokens => TokenType) public tokenTypes; + mapping(uint256 => TokenType) public tokenTypes; - mapping(address => Tokens) public tokenIndexes; + mapping(address => uint256) public tokenIndexes; uint256 public tokenCount; @@ -82,18 +82,18 @@ contract TokensTestSuite is Test, TokensTestSuiteHelper { } } } - wethToken = addressOf[Tokens.WETH]; + wethToken = addressOf[TOKEN_WETH]; } function addMockToken(MockToken memory token) internal { IERC20 t; - if (token.index == Tokens.WETH) { + if (token.index == TOKEN_WETH) { t = new WETHMock(); wethToken = address(t); - } else if (token.index == Tokens.USDC) { + } else if (token.index == TOKEN_USDC) { t = new ERC20BlacklistableMock(token.symbol, token.symbol, token.decimals); - } else if (token.index == Tokens.USDT) { + } else if (token.index == TOKEN_USDT) { t = new ERC20FeeMock(token.symbol, token.symbol, token.decimals); } else { t = new ERC20Mock(token.symbol, token.symbol, token.decimals); @@ -117,49 +117,53 @@ contract TokensTestSuite is Test, TokensTestSuiteHelper { return priceFeeds; } - function mint(Tokens t, address to, uint256 amount) public { + function mint(uint256 t, address to, uint256 amount) public { mint(addressOf[t], to, amount); } - function balanceOf(Tokens t, address holder) public view returns (uint256) { + function balanceOf(uint256 t, address holder) public view returns (uint256) { return balanceOf(addressOf[t], holder); } - function approve(Tokens t, address from, address spender) public { + function approve(uint256 t, address from, address spender) public { approve(addressOf[t], from, spender); } - function approve(Tokens t, address from, address spender, uint256 amount) public { + function approve(uint256 t, address from, address spender, uint256 amount) public { approve(addressOf[t], from, spender, amount); } - function allowance(Tokens t, address from, address spender) external view returns (uint256) { + function allowance(uint256 t, address from, address spender) external view returns (uint256) { return IERC20(addressOf[t]).allowance(from, spender); } - function burn(Tokens t, address from, uint256 amount) external { + function burn(uint256 t, address from, uint256 amount) external { burn(addressOf[t], from, amount); } - function listOf(Tokens t1) external view returns (address[] memory tokensList) { + function listOf(uint256 t1) external view returns (address[] memory tokensList) { tokensList = new address[](1); tokensList[0] = addressOf[t1]; } - function listOf(Tokens t1, Tokens t2) external view returns (address[] memory tokensList) { + function listOf(uint256 t1, uint256 t2) external view returns (address[] memory tokensList) { tokensList = new address[](2); tokensList[0] = addressOf[t1]; tokensList[1] = addressOf[t2]; } - function listOf(Tokens t1, Tokens t2, Tokens t3) external view returns (address[] memory tokensList) { + function listOf(uint256 t1, uint256 t2, uint256 t3) external view returns (address[] memory tokensList) { tokensList = new address[](3); tokensList[0] = addressOf[t1]; tokensList[1] = addressOf[t2]; tokensList[2] = addressOf[t3]; } - function listOf(Tokens t1, Tokens t2, Tokens t3, Tokens t4) external view returns (address[] memory tokensList) { + function listOf(uint256 t1, uint256 t2, uint256 t3, uint256 t4) + external + view + returns (address[] memory tokensList) + { tokensList = new address[](4); tokensList[0] = addressOf[t1]; tokensList[1] = addressOf[t2]; diff --git a/contracts/test/unit/core/GearStakingV3.unit.t.sol b/contracts/test/unit/core/GearStakingV3.unit.t.sol index 45493a1d..80ee2def 100644 --- a/contracts/test/unit/core/GearStakingV3.unit.t.sol +++ b/contracts/test/unit/core/GearStakingV3.unit.t.sol @@ -20,7 +20,7 @@ import {TargetContractMock} from "../../mocks/core/TargetContractMock.sol"; // SUITES import {TokensTestSuite} from "../../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; // EXCEPTIONS import "../../../interfaces/IExceptions.sol"; @@ -42,7 +42,7 @@ contract GearStakingV3UnitTest is Test, IGearStakingV3Events { tokenTestSuite = new TokensTestSuite(); - gearToken = tokenTestSuite.addressOf(Tokens.WETH); + gearToken = tokenTestSuite.addressOf(TOKEN_WETH); vm.prank(CONFIGURATOR); addressProvider.setAddress(AP_GEAR_TOKEN, gearToken, false); diff --git a/contracts/test/unit/credit/CreditFacadeV3.unit.t.sol b/contracts/test/unit/credit/CreditFacadeV3.unit.t.sol index 190bd703..3fbb11b0 100644 --- a/contracts/test/unit/credit/CreditFacadeV3.unit.t.sol +++ b/contracts/test/unit/credit/CreditFacadeV3.unit.t.sol @@ -63,7 +63,7 @@ import "../../../interfaces/IExceptions.sol"; // SUITES import {TokensTestSuite} from "../../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; uint16 constant REFERRAL_CODE = 23; @@ -131,7 +131,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve addressProvider = new AddressProviderV3ACLMock(); - addressProvider.setAddress(AP_WETH_TOKEN, tokenTestSuite.addressOf(Tokens.WETH), false); + addressProvider.setAddress(AP_WETH_TOKEN, tokenTestSuite.addressOf(TOKEN_WETH), false); botListMock = BotListMock(addressProvider.getAddressOrRevert(AP_BOT_LIST, 3_10)); @@ -139,7 +139,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve AddressProviderV3ACLMock(address(addressProvider)).addPausableAdmin(CONFIGURATOR); - PoolMock poolMock = new PoolMock(address(addressProvider), tokenTestSuite.addressOf(Tokens.DAI)); + PoolMock poolMock = new PoolMock(address(addressProvider), tokenTestSuite.addressOf(TOKEN_DAI)); treasury = makeAddr("TREASURY"); poolMock.setTreasury(treasury); @@ -170,7 +170,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve creditFacade = new CreditFacadeV3Harness( address(creditManagerMock), address(botListMock), - tokenTestSuite.addressOf(Tokens.WETH), + tokenTestSuite.addressOf(TOKEN_WETH), address(degenNFTMock), expirable ); @@ -181,10 +181,10 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve /// @dev U:[FA-1]: constructor sets correct values function test_U_FA_01_constructor_sets_correct_values() public allDegenNftCases allExpirableCases { assertEq(creditFacade.creditManager(), address(creditManagerMock), "Incorrect creditManager"); - assertEq(creditFacade.underlying(), tokenTestSuite.addressOf(Tokens.DAI), "Incorrect underlying"); + assertEq(creditFacade.underlying(), tokenTestSuite.addressOf(TOKEN_DAI), "Incorrect underlying"); assertEq(creditFacade.treasury(), treasury, "Incorrect treasury"); - assertEq(creditFacade.weth(), tokenTestSuite.addressOf(Tokens.WETH), "Incorrect weth token"); + assertEq(creditFacade.weth(), tokenTestSuite.addressOf(TOKEN_WETH), "Incorrect weth token"); assertEq(creditFacade.degenNFT(), address(degenNFTMock), "Incorrect degen NFT"); @@ -314,7 +314,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve creditFacade.setDebtLimits(1 ether, 9 ether, 9); vm.roll(block.number + 1); - address weth = tokenTestSuite.addressOf(Tokens.WETH); + address weth = tokenTestSuite.addressOf(TOKEN_WETH); vm.prank(USER); creditFacade.openCreditAccount{value: 1 ether}({ @@ -332,18 +332,18 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve referralCode: 0 }); - expectBalance({t: Tokens.WETH, holder: USER, expectedBalance: 1 ether}); + expectBalance({t: TOKEN_WETH, holder: USER, expectedBalance: 1 ether}); creditManagerMock.setBorrower(USER); vm.prank(USER); creditFacade.closeCreditAccount{value: 1 ether}({creditAccount: DUMB_ADDRESS, calls: new MultiCall[](0)}); - expectBalance({t: Tokens.WETH, holder: USER, expectedBalance: 2 ether}); + expectBalance({t: TOKEN_WETH, holder: USER, expectedBalance: 2 ether}); vm.prank(USER); creditFacade.multicall{value: 1 ether}({creditAccount: DUMB_ADDRESS, calls: new MultiCall[](0)}); - expectBalance({t: Tokens.WETH, holder: USER, expectedBalance: 3 ether}); + expectBalance({t: TOKEN_WETH, holder: USER, expectedBalance: 3 ether}); } // @@ -463,8 +463,8 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve address creditAccount = DUMB_ADDRESS; creditManagerMock.setBorrower(USER); - address dai = tokenTestSuite.addressOf(Tokens.DAI); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); + address link = tokenTestSuite.addressOf(TOKEN_LINK); creditManagerMock.addToken(link, 1 << 1); priceOracleMock.setPrice(dai, 1e8); @@ -522,8 +522,8 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve address creditAccount = DUMB_ADDRESS; creditManagerMock.setBorrower(USER); - address dai = tokenTestSuite.addressOf(Tokens.DAI); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); + address link = tokenTestSuite.addressOf(TOKEN_LINK); creditManagerMock.addToken(link, 1 << 1); priceOracleMock.setPrice(dai, 1e8); @@ -578,9 +578,9 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve address creditAccount = DUMB_ADDRESS; creditManagerMock.setBorrower(USER); - address usdc = tokenTestSuite.addressOf(Tokens.USDC); - address weth = tokenTestSuite.addressOf(Tokens.WETH); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address usdc = tokenTestSuite.addressOf(TOKEN_USDC); + address weth = tokenTestSuite.addressOf(TOKEN_WETH); + address link = tokenTestSuite.addressOf(TOKEN_LINK); creditManagerMock.addToken(usdc, 2); creditManagerMock.addToken(weth, 4); creditManagerMock.addToken(link, 8); @@ -629,8 +629,8 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve public notExpirableCase { - address dai = tokenTestSuite.addressOf(Tokens.DAI); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); + address link = tokenTestSuite.addressOf(TOKEN_LINK); uint256 linkMask = 4; creditManagerMock.addToken(link, linkMask); @@ -669,8 +669,8 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve /// @dev U:[FA-15]: `_calcPartialLiquidationPayments` works as expected function test_U_FA_15_calcPartialLiquidationPayments_works_as_expected() public notExpirableCase { - address dai = tokenTestSuite.addressOf(Tokens.DAI); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); + address link = tokenTestSuite.addressOf(TOKEN_LINK); priceOracleMock.setPrice(dai, 1e8); priceOracleMock.setPrice(link, 10e8); @@ -722,8 +722,8 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve address creditAccount = DUMB_ADDRESS; creditManagerMock.setBorrower(USER); - address dai = tokenTestSuite.addressOf(Tokens.DAI); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); + address link = tokenTestSuite.addressOf(TOKEN_LINK); creditManagerMock.addToken(link, 2); @@ -812,8 +812,8 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve address creditAccount = DUMB_ADDRESS; creditManagerMock.setBorrower(USER); - address dai = tokenTestSuite.addressOf(Tokens.DAI); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); + address link = tokenTestSuite.addressOf(TOKEN_LINK); creditManagerMock.addToken(link, 2); GeneralMock pDaiTarget = new GeneralMock(); @@ -1040,7 +1040,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve function test_U_FA_21_multicall_reverts_if_called_without_particaular_permission() public notExpirableCase { address creditAccount = DUMB_ADDRESS; - address token = tokenTestSuite.addressOf(Tokens.LINK); + address token = tokenTestSuite.addressOf(TOKEN_LINK); creditManagerMock.addToken(token, 1 << 4); vm.prank(CONFIGURATOR); @@ -1165,7 +1165,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve function test_U_FA_23_multicall_slippage_check_works_properly() public notExpirableCase { address creditAccount = DUMB_ADDRESS; - address link = tokenTestSuite.addressOf(Tokens.LINK); + address link = tokenTestSuite.addressOf(TOKEN_LINK); BalanceDelta[] memory expectedBalance = new BalanceDelta[](1); address acm = address(new AdapterCallMock()); @@ -1373,7 +1373,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve function test_U_FA_26A_multicall_addCollateral_works_properly() public notExpirableCase { address creditAccount = DUMB_ADDRESS; - address token = tokenTestSuite.addressOf(Tokens.LINK); + address token = tokenTestSuite.addressOf(TOKEN_LINK); uint256 amount = 12333345; vm.expectRevert(AmountCantBeZeroException.selector); @@ -1666,7 +1666,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve function test_U_FA_34_multicall_updateQuota_works_properly() public notExpirableCase { address creditAccount = DUMB_ADDRESS; - address underlying = tokenTestSuite.addressOf(Tokens.DAI); + address underlying = tokenTestSuite.addressOf(TOKEN_DAI); vm.expectRevert(TokenIsNotQuotedException.selector); creditFacade.multicallInt({ creditAccount: creditAccount, @@ -1685,7 +1685,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve vm.prank(CONFIGURATOR); creditFacade.setDebtLimits(0, maxDebt, type(uint8).max); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address link = tokenTestSuite.addressOf(TOKEN_LINK); uint256 maskToEnable = 1 << 4; uint256 maskToDisable = 1 << 7; @@ -1738,7 +1738,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve function test_U_FA_36_multicall_withdrawCollateral_works_properly() public notExpirableCase { address creditAccount = DUMB_ADDRESS; - address link = tokenTestSuite.addressOf(Tokens.LINK); + address link = tokenTestSuite.addressOf(TOKEN_LINK); uint256 amount = 100; @@ -2062,7 +2062,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve function test_U_FA_45_multicall_handles_forbidden_tokens_properly() public notExpirableCase { address creditAccount = DUMB_ADDRESS; - address link = tokenTestSuite.addressOf(Tokens.LINK); + address link = tokenTestSuite.addressOf(TOKEN_LINK); uint256 linkMask = 1 << 8; creditManagerMock.addToken(link, linkMask); @@ -2131,7 +2131,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve creditAccount: creditAccount, calls: MultiCallBuilder.build( MultiCall( - address(adapter), abi.encodeWithSignature("mint(uint8,address,uint256)", Tokens.LINK, creditAccount, 10) + address(adapter), abi.encodeWithSignature("mint(uint8,address,uint256)", TOKEN_LINK, creditAccount, 10) ) ), enabledTokensMask: linkMask, @@ -2243,7 +2243,7 @@ contract CreditFacadeV3UnitTest is TestHelper, BalanceHelper, ICreditFacadeV3Eve vm.prank(CONFIGURATOR); creditFacade.setTokenAllowance(DUMB_ADDRESS, AllowanceAction.ALLOW); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address link = tokenTestSuite.addressOf(TOKEN_LINK); uint256 mask = 1 << 8; creditManagerMock.addToken(link, mask); diff --git a/contracts/test/unit/credit/CreditManagerV3.unit.t.sol b/contracts/test/unit/credit/CreditManagerV3.unit.t.sol index 35175410..5f857736 100644 --- a/contracts/test/unit/credit/CreditManagerV3.unit.t.sol +++ b/contracts/test/unit/credit/CreditManagerV3.unit.t.sol @@ -46,7 +46,7 @@ import {ERC20Mock} from "../../mocks/token/ERC20Mock.sol"; import {CreditAccountMock, CreditAccountMockEvents} from "../../mocks/credit/CreditAccountMock.sol"; // SUITES import {TokensTestSuite} from "../../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; // EXCEPTIONS import "../../../interfaces/IExceptions.sol"; @@ -108,7 +108,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH tokenTestSuite = new TokensTestSuite(); tokenTestSuite.topUpWETH{value: 100 * WAD}(); - underlying = tokenTestSuite.addressOf(Tokens.DAI); + underlying = tokenTestSuite.addressOf(TOKEN_DAI); addressProvider = new AddressProviderV3ACLMock(); @@ -165,10 +165,10 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH } function _setUnderlying(bool underlyingIsFeeToken) internal { - uint256 oneUSDT = 10 ** _decimals(tokenTestSuite.addressOf(Tokens.USDT)); + uint256 oneUSDT = 10 ** _decimals(tokenTestSuite.addressOf(TOKEN_USDT)); isFeeToken = underlyingIsFeeToken; - underlying = tokenTestSuite.addressOf(underlyingIsFeeToken ? Tokens.USDT : Tokens.DAI); + underlying = tokenTestSuite.addressOf(underlyingIsFeeToken ? TOKEN_USDT : TOKEN_DAI); uint256 _tokenFee = underlyingIsFeeToken ? 20 : 0; uint256 _maxTokenFee = underlyingIsFeeToken ? 50 * oneUSDT : 0; @@ -199,7 +199,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH return IERC20Metadata(token).decimals(); } - function _addToken(Tokens token, uint16 lt) internal { + function _addToken(uint256 token, uint16 lt) internal { _addToken(tokenTestSuite.addressOf(token), lt); } @@ -226,7 +226,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH }); } - function _addQuotedToken(Tokens token, uint16 lt, uint96 quoted, uint128 outstandingInterest) internal { + function _addQuotedToken(uint256 token, uint16 lt, uint96 quoted, uint128 outstandingInterest) internal { _addQuotedToken({ token: tokenTestSuite.addressOf(token), lt: lt, @@ -252,7 +252,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH } } - function _getTokenMaskOrRevert(Tokens token) internal view returns (uint256) { + function _getTokenMaskOrRevert(uint256 token) internal view returns (uint256) { return creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(token)); } @@ -337,14 +337,14 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH assertEq(address(creditManager.pool()), address(poolMock), _testCaseErr("Incorrect pool")); - assertEq(creditManager.underlying(), tokenTestSuite.addressOf(Tokens.DAI), _testCaseErr("Incorrect underlying")); + assertEq(creditManager.underlying(), tokenTestSuite.addressOf(TOKEN_DAI), _testCaseErr("Incorrect underlying")); (address token,) = creditManager.collateralTokenByMask(UNDERLYING_TOKEN_MASK); - assertEq(token, tokenTestSuite.addressOf(Tokens.DAI), _testCaseErr("Incorrect underlying")); + assertEq(token, tokenTestSuite.addressOf(TOKEN_DAI), _testCaseErr("Incorrect underlying")); assertEq( - creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(Tokens.DAI)), + creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(TOKEN_DAI)), 1, _testCaseErr("Incorrect token mask for underlying token") ); @@ -660,23 +660,23 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH address[] memory hasQuotedTokens = new address[](2); - hasQuotedTokens[0] = tokenTestSuite.addressOf(Tokens.USDC); - hasQuotedTokens[1] = tokenTestSuite.addressOf(Tokens.LINK); + hasQuotedTokens[0] = tokenTestSuite.addressOf(TOKEN_USDC); + hasQuotedTokens[1] = tokenTestSuite.addressOf(TOKEN_LINK); priceOracleMock.setPrice(underlying, 10 ** 8); /// @notice sets price 2 USD for underlying - priceOracleMock.setPrice(tokenTestSuite.addressOf(Tokens.USDC), USDC_MULTIPLIER * 10 ** 8); + priceOracleMock.setPrice(tokenTestSuite.addressOf(TOKEN_USDC), USDC_MULTIPLIER * 10 ** 8); /// @notice sets price 4 USD for underlying - priceOracleMock.setPrice(tokenTestSuite.addressOf(Tokens.LINK), LINK_MULTIPLIER * 10 ** 8); + priceOracleMock.setPrice(tokenTestSuite.addressOf(TOKEN_LINK), LINK_MULTIPLIER * 10 ** 8); vm.startPrank(CONFIGURATOR); - creditManager.addToken(tokenTestSuite.addressOf(Tokens.USDC)); - creditManager.addToken(tokenTestSuite.addressOf(Tokens.LINK)); + creditManager.addToken(tokenTestSuite.addressOf(TOKEN_USDC)); + creditManager.addToken(tokenTestSuite.addressOf(TOKEN_LINK)); vm.stopPrank(); - uint256 LINK_TOKEN_MASK = creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(Tokens.LINK)); + uint256 LINK_TOKEN_MASK = creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(TOKEN_LINK)); LiquidateAccountTestCase[7] memory cases = [ LiquidateAccountTestCase({ @@ -845,11 +845,11 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH }); tokenTestSuite.mint(underlying, creditAccount, _case.underlyingBalance); - tokenTestSuite.mint(tokenTestSuite.addressOf(Tokens.USDC), creditAccount, _case.usdcBalance); - tokenTestSuite.mint(tokenTestSuite.addressOf(Tokens.LINK), creditAccount, _case.linkBalance); + tokenTestSuite.mint(tokenTestSuite.addressOf(TOKEN_USDC), creditAccount, _case.usdcBalance); + tokenTestSuite.mint(tokenTestSuite.addressOf(TOKEN_LINK), creditAccount, _case.linkBalance); // vm.startPrank(CONFIGURATOR); - // for (uint256 j; j < _case.quotedTokens.length; ++j) { + // for (uint256 j; j < _case.quotedTOKEN_length; ++j) { // creditManager.setQuotedMask( // creditManager.quotedTokensMask() | creditManager.getTokenMaskOrRevert(_case.quotedTokens[j]) // ); @@ -1167,13 +1167,13 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH tokenTestSuite.mint(underlying, creditAccount, _amountWithFee(DAI_ACCOUNT_AMOUNT)); address[] memory quotedTokens = new address[](2); - quotedTokens[0] = tokenTestSuite.addressOf(Tokens.LINK); - quotedTokens[1] = tokenTestSuite.addressOf(Tokens.USDC); + quotedTokens[0] = tokenTestSuite.addressOf(TOKEN_LINK); + quotedTokens[1] = tokenTestSuite.addressOf(TOKEN_USDC); - _addQuotedToken({token: Tokens.LINK, lt: 80_00, quoted: 10000, outstandingInterest: 0}); - _addQuotedToken({token: Tokens.USDC, lt: 80_00, quoted: 10000, outstandingInterest: 0}); + _addQuotedToken({token: TOKEN_LINK, lt: 80_00, quoted: 10000, outstandingInterest: 0}); + _addQuotedToken({token: TOKEN_USDC, lt: 80_00, quoted: 10000, outstandingInterest: 0}); - uint256 quotedTokensMask = _getTokenMaskOrRevert(Tokens.LINK) | _getTokenMaskOrRevert(Tokens.USDC); + uint256 quotedTokensMask = _getTokenMaskOrRevert(TOKEN_LINK) | _getTokenMaskOrRevert(TOKEN_USDC); //vm.prank(CONFIGURATOR); //creditManager.setQuotedMask(quotedTokensMask); @@ -1238,7 +1238,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH /// @dev U:[CM-13]: addCollateral works as expected function test_U_CM_13_addCollateral_works_as_expected() public creditManagerTest { address creditAccount = DUMB_ADDRESS; - address linkToken = tokenTestSuite.addressOf(Tokens.LINK); + address linkToken = tokenTestSuite.addressOf(TOKEN_LINK); uint256 amount = DAI_ACCOUNT_AMOUNT; @@ -1272,7 +1272,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH /// @dev U:[CM-14]: approveCreditAccount works as expected function test_U_CM_14_approveCreditAccount_works_as_expected() public creditManagerTest { address creditAccount = address(new CreditAccountMock()); - address linkToken = tokenTestSuite.addressOf(Tokens.LINK); + address linkToken = tokenTestSuite.addressOf(TOKEN_LINK); creditManager.setActiveCreditAccount(address(creditAccount)); @@ -1560,11 +1560,11 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH uint128 STETH_INTEREST = uint128(debt / 100); uint128 INITIAL_INTEREST = 500; - _addQuotedToken({token: Tokens.LINK, lt: 80_00, quoted: LINK_QUOTA, outstandingInterest: LINK_INTEREST}); - _addQuotedToken({token: Tokens.STETH, lt: 30_00, quoted: STETH_QUOTA, outstandingInterest: STETH_INTEREST}); + _addQuotedToken({token: TOKEN_LINK, lt: 80_00, quoted: LINK_QUOTA, outstandingInterest: LINK_INTEREST}); + _addQuotedToken({token: TOKEN_STETH, lt: 30_00, quoted: STETH_QUOTA, outstandingInterest: STETH_INTEREST}); - uint256 LINK_TOKEN_MASK = _getTokenMaskOrRevert({token: Tokens.LINK}); - uint256 STETH_TOKEN_MASK = _getTokenMaskOrRevert({token: Tokens.STETH}); + uint256 LINK_TOKEN_MASK = _getTokenMaskOrRevert({token: TOKEN_LINK}); + uint256 STETH_TOKEN_MASK = _getTokenMaskOrRevert({token: TOKEN_STETH}); vars.set("cumulativeIndexNow", RAY * 22 / 10); vars.set("cumulativeIndexLastUpdate", RAY * 21 / 10); @@ -1599,7 +1599,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH assertEq(collateralDebtData._poolQuotaKeeper, address(poolQuotaKeeperMock), "Incorrect _poolQuotaKeeper"); assertEq( - collateralDebtData.quotedTokens, tokenTestSuite.listOf(Tokens.LINK, Tokens.STETH), "Incorrect quotedTokens" + collateralDebtData.quotedTokens, tokenTestSuite.listOf(TOKEN_LINK, TOKEN_STETH), "Incorrect quotedTokens" ); assertEq( @@ -1654,7 +1654,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH vars.set("LINK_LT", 80_00); _addQuotedToken({ - token: Tokens.LINK, + token: TOKEN_LINK, lt: uint16(vars.get("LINK_LT")), quoted: uint96(vars.get("LINK_QUOTA")), outstandingInterest: uint128(vars.get("LINK_INTEREST")) @@ -1671,7 +1671,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH vars.set("LINK_PRICE", 4); priceOracleMock.setPrice({ - token: tokenTestSuite.addressOf(Tokens.LINK), + token: tokenTestSuite.addressOf(TOKEN_LINK), price: vars.get("LINK_PRICE") * (10 ** 8) }); @@ -1684,7 +1684,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH uint256 debt = DAI_ACCOUNT_AMOUNT; _collateralTestSetup(debt); - uint256 LINK_TOKEN_MASK = _getTokenMaskOrRevert({token: Tokens.LINK}); + uint256 LINK_TOKEN_MASK = _getTokenMaskOrRevert({token: TOKEN_LINK}); CollateralCalcTestCase[3] memory cases = [ CollateralCalcTestCase({ @@ -1737,7 +1737,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH }); tokenTestSuite.mint({token: underlying, to: creditAccount, amount: _case.underlyingBalance}); - tokenTestSuite.mint({t: Tokens.LINK, to: creditAccount, amount: _case.linkBalance}); + tokenTestSuite.mint({t: TOKEN_LINK, to: creditAccount, amount: _case.linkBalance}); CollateralDebtData memory collateralDebtData = creditManager.calcDebtAndCollateralFC({creditAccount: creditAccount, task: tasks[taskIndex]}); @@ -1786,14 +1786,14 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH function test_U_CM_24_getQuotedTokensData_works_correctly() public creditManagerTest { assertEq(creditManager.collateralTokensCount(), 1, "SETUP: incorrect tokens count"); - _addQuotedToken({token: Tokens.LINK, lt: 80_00, quoted: 10_000, outstandingInterest: 40_000}); - uint256 LINK_TOKEN_MASK = _getTokenMaskOrRevert({token: Tokens.LINK}); + _addQuotedToken({token: TOKEN_LINK, lt: 80_00, quoted: 10_000, outstandingInterest: 40_000}); + uint256 LINK_TOKEN_MASK = _getTokenMaskOrRevert({token: TOKEN_LINK}); - _addQuotedToken({token: Tokens.STETH, lt: 30_00, quoted: 20_000, outstandingInterest: 10_000}); - uint256 STETH_TOKEN_MASK = _getTokenMaskOrRevert({token: Tokens.STETH}); + _addQuotedToken({token: TOKEN_STETH, lt: 30_00, quoted: 20_000, outstandingInterest: 10_000}); + uint256 STETH_TOKEN_MASK = _getTokenMaskOrRevert({token: TOKEN_STETH}); - _addQuotedToken({token: Tokens.CVX, lt: 20_00, quoted: 100_000, outstandingInterest: 30_000}); - uint256 CVX_TOKEN_MASK = _getTokenMaskOrRevert({token: Tokens.CVX}); + _addQuotedToken({token: TOKEN_CVX, lt: 20_00, quoted: 100_000, outstandingInterest: 30_000}); + uint256 CVX_TOKEN_MASK = _getTokenMaskOrRevert({token: TOKEN_CVX}); GetQuotedTokenDataTestCase[4] memory cases = [ GetQuotedTokenDataTestCase({ @@ -1807,7 +1807,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH GetQuotedTokenDataTestCase({ name: "1 quoted token", enabledTokensMask: STETH_TOKEN_MASK, - expectedQuotaTokens: tokenTestSuite.listOf(Tokens.STETH), + expectedQuotaTokens: tokenTestSuite.listOf(TOKEN_STETH), expertedOutstandingQuotaInterest: 10_000, expectedQuotas: arrayOf(20_000, 0, 0), expectedLts: arrayOfU16(30_00, 0, 0) @@ -1815,7 +1815,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH GetQuotedTokenDataTestCase({ name: "2 quoted tokens", enabledTokensMask: STETH_TOKEN_MASK | LINK_TOKEN_MASK, - expectedQuotaTokens: tokenTestSuite.listOf(Tokens.LINK, Tokens.STETH), + expectedQuotaTokens: tokenTestSuite.listOf(TOKEN_LINK, TOKEN_STETH), expertedOutstandingQuotaInterest: 40_000 + 10_000, expectedQuotas: arrayOf(10_000, 20_000, 0), expectedLts: arrayOfU16(80_00, 30_00, 0) @@ -1823,7 +1823,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH GetQuotedTokenDataTestCase({ name: "3 quoted tokens", enabledTokensMask: STETH_TOKEN_MASK | LINK_TOKEN_MASK | CVX_TOKEN_MASK, - expectedQuotaTokens: tokenTestSuite.listOf(Tokens.LINK, Tokens.STETH, Tokens.CVX), + expectedQuotaTokens: tokenTestSuite.listOf(TOKEN_LINK, TOKEN_STETH, TOKEN_CVX), expertedOutstandingQuotaInterest: 40_000 + 10_000 + 30_000, expectedQuotas: arrayOf(10_000, 20_000, 100_000), expectedLts: arrayOfU16(80_00, 30_00, 20_00) @@ -1861,8 +1861,8 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH /// @dev U:[CM-25]: updateQuota works correctly function test_U_CM_25_updateQuota_works_correctly() public creditManagerTest { - _addToken(Tokens.LINK, 80_00); - uint256 LINK_TOKEN_MASK = _getTokenMaskOrRevert({token: Tokens.LINK}); + _addToken(TOKEN_LINK, 80_00); + uint256 LINK_TOKEN_MASK = _getTokenMaskOrRevert({token: TOKEN_LINK}); uint128 INITIAL_INTEREST = 123123; uint128 caInterestChange = 10323212323; @@ -1900,7 +1900,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH (uint256 tokensToEnable, uint256 tokensToDisable) = creditManager.updateQuota({ creditAccount: creditAccount, - token: tokenTestSuite.addressOf(Tokens.LINK), + token: tokenTestSuite.addressOf(TOKEN_LINK), quotaChange: 122, minQuota: 122, maxQuota: type(uint96).max @@ -1933,7 +1933,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH /// @dev U:[CM-26]: withdrawCollateral reverts for unknown token function test_U_CM_26_withdrawCollateral_reverts_for_unknown_token() public creditManagerTest { address creditAccount = DUMB_ADDRESS; - address linkToken = tokenTestSuite.addressOf(Tokens.LINK); + address linkToken = tokenTestSuite.addressOf(TOKEN_LINK); /// @notice check that it reverts on unknown token vm.expectRevert(TokenNotAllowedException.selector); creditManager.withdrawCollateral({creditAccount: creditAccount, token: linkToken, amount: 20000, to: USER}); @@ -2207,7 +2207,7 @@ contract CreditManagerV3UnitTest is TestHelper, ICreditManagerV3Events, BalanceH vm.revertTo(snapshot); /// @notice Non-underlying token case - address weth = tokenTestSuite.addressOf(Tokens.WETH); + address weth = tokenTestSuite.addressOf(TOKEN_WETH); creditManager.addToken(weth); diff --git a/contracts/test/unit/libraries/CollateralLogic.unit.t.sol b/contracts/test/unit/libraries/CollateralLogic.unit.t.sol index 5741d104..83f7daaf 100644 --- a/contracts/test/unit/libraries/CollateralLogic.unit.t.sol +++ b/contracts/test/unit/libraries/CollateralLogic.unit.t.sol @@ -11,7 +11,7 @@ import {TestHelper} from "../../lib/helper.sol"; import {PERCENTAGE_FACTOR} from "../../../libraries/Constants.sol"; import "../../lib/constants.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {CollateralLogicHelper, PRICE_ORACLE, B, Q} from "./CollateralLogicHelper.sol"; /// @title CollateralLogic unit test @@ -21,9 +21,9 @@ contract CollateralLogicUnitTest is TestHelper, CollateralLogicHelper { /// modifier withTokenSetup() { - setTokenParams({t: Tokens.DAI, lt: 95_00, price: 1}); - setTokenParams({t: Tokens.USDT, lt: 90_00, price: 1}); - setTokenParams({t: Tokens.LINK, lt: 75_00, price: 15}); + setTokenParams({t: TOKEN_DAI, lt: 95_00, price: 1}); + setTokenParams({t: TOKEN_USDT, lt: 90_00, price: 1}); + setTokenParams({t: TOKEN_LINK, lt: 75_00, price: 15}); _; } @@ -115,7 +115,7 @@ contract CollateralLogicUnitTest is TestHelper, CollateralLogicHelper { // expected behavior uint256 expectedTotalValueUSD; uint256 expectedTwvUSD; - Tokens[] expectedOrder; + uint256[] expectedOrder; } /// @dev U:[CLL-2]: calcCollateral works correctly @@ -123,41 +123,41 @@ contract CollateralLogicUnitTest is TestHelper, CollateralLogicHelper { CalcCollateralTestCase[4] memory cases = [ CalcCollateralTestCase({ name: "No target, one quoted token and underlying", - balances: arrayOf(B({t: Tokens.USDT, balance: 10_000}), B({t: Tokens.DAI, balance: 5_000})), - quotas: arrayOf(Q({t: Tokens.USDT, quota: 10_000})), + balances: arrayOf(B({t: TOKEN_USDT, balance: 10_000}), B({t: TOKEN_DAI, balance: 5_000})), + quotas: arrayOf(Q({t: TOKEN_USDT, quota: 10_000})), target: type(uint256).max, - expectedTotalValueUSD: 10_000 * prices[Tokens.USDT] + 5_000 * prices[Tokens.DAI], - expectedTwvUSD: 10_000 * prices[Tokens.USDT] * lts[Tokens.USDT] / PERCENTAGE_FACTOR - + 5_000 * prices[Tokens.DAI] * lts[Tokens.DAI] / PERCENTAGE_FACTOR, - expectedOrder: arrayOf(Tokens.USDT, Tokens.DAI) + expectedTotalValueUSD: 10_000 * prices[TOKEN_USDT] + 5_000 * prices[TOKEN_DAI], + expectedTwvUSD: 10_000 * prices[TOKEN_USDT] * lts[TOKEN_USDT] / PERCENTAGE_FACTOR + + 5_000 * prices[TOKEN_DAI] * lts[TOKEN_DAI] / PERCENTAGE_FACTOR, + expectedOrder: arrayOfTokens(TOKEN_USDT, TOKEN_DAI) }), CalcCollateralTestCase({ name: "No target, two quoted tokens", - balances: arrayOf(B({t: Tokens.USDT, balance: 10_000}), B({t: Tokens.LINK, balance: 1_000})), - quotas: arrayOf(Q({t: Tokens.USDT, quota: 10_000}), Q({t: Tokens.LINK, quota: 20_000})), + balances: arrayOf(B({t: TOKEN_USDT, balance: 10_000}), B({t: TOKEN_LINK, balance: 1_000})), + quotas: arrayOf(Q({t: TOKEN_USDT, quota: 10_000}), Q({t: TOKEN_LINK, quota: 20_000})), target: type(uint256).max, - expectedTotalValueUSD: 10_000 * prices[Tokens.USDT] + 1_000 * prices[Tokens.LINK], - expectedTwvUSD: 10_000 * prices[Tokens.USDT] * lts[Tokens.USDT] / PERCENTAGE_FACTOR - + 1_000 * prices[Tokens.LINK] * lts[Tokens.LINK] / PERCENTAGE_FACTOR, - expectedOrder: arrayOf(Tokens.USDT, Tokens.LINK, Tokens.DAI) + expectedTotalValueUSD: 10_000 * prices[TOKEN_USDT] + 1_000 * prices[TOKEN_LINK], + expectedTwvUSD: 10_000 * prices[TOKEN_USDT] * lts[TOKEN_USDT] / PERCENTAGE_FACTOR + + 1_000 * prices[TOKEN_LINK] * lts[TOKEN_LINK] / PERCENTAGE_FACTOR, + expectedOrder: arrayOfTokens(TOKEN_USDT, TOKEN_LINK, TOKEN_DAI) }), CalcCollateralTestCase({ name: "Finite target, one quoted token and underlying", - balances: arrayOf(B({t: Tokens.USDT, balance: 10_000}), B({t: Tokens.DAI, balance: 5_000})), - quotas: arrayOf(Q({t: Tokens.USDT, quota: 10_000})), - target: 8_000 * prices[Tokens.DAI], - expectedTotalValueUSD: 10_000 * prices[Tokens.USDT], - expectedTwvUSD: 10_000 * prices[Tokens.USDT] * lts[Tokens.USDT] / PERCENTAGE_FACTOR, - expectedOrder: arrayOf(Tokens.USDT) + balances: arrayOf(B({t: TOKEN_USDT, balance: 10_000}), B({t: TOKEN_DAI, balance: 5_000})), + quotas: arrayOf(Q({t: TOKEN_USDT, quota: 10_000})), + target: 8_000 * prices[TOKEN_DAI], + expectedTotalValueUSD: 10_000 * prices[TOKEN_USDT], + expectedTwvUSD: 10_000 * prices[TOKEN_USDT] * lts[TOKEN_USDT] / PERCENTAGE_FACTOR, + expectedOrder: arrayOfTokens(TOKEN_USDT) }), CalcCollateralTestCase({ name: "Finite target, two quoted tokens", - balances: arrayOf(B({t: Tokens.USDT, balance: 10_000}), B({t: Tokens.LINK, balance: 1_000})), - quotas: arrayOf(Q({t: Tokens.USDT, quota: 10_000}), Q({t: Tokens.LINK, quota: 20_000})), - target: 8_000 * prices[Tokens.DAI], - expectedTotalValueUSD: 10_000 * prices[Tokens.USDT], - expectedTwvUSD: 10_000 * prices[Tokens.USDT] * lts[Tokens.USDT] / PERCENTAGE_FACTOR, - expectedOrder: arrayOf(Tokens.USDT) + balances: arrayOf(B({t: TOKEN_USDT, balance: 10_000}), B({t: TOKEN_LINK, balance: 1_000})), + quotas: arrayOf(Q({t: TOKEN_USDT, quota: 10_000}), Q({t: TOKEN_LINK, quota: 20_000})), + target: 8_000 * prices[TOKEN_DAI], + expectedTotalValueUSD: 10_000 * prices[TOKEN_USDT], + expectedTwvUSD: 10_000 * prices[TOKEN_USDT] * lts[TOKEN_USDT] / PERCENTAGE_FACTOR, + expectedOrder: arrayOfTokens(TOKEN_USDT) }) ]; @@ -178,8 +178,8 @@ contract CollateralLogicUnitTest is TestHelper, CollateralLogicHelper { quotedTokens: quotedTokens, quotasPacked: quotasPacked, creditAccount: creditAccount, - underlying: addressOf[Tokens.DAI], - ltUnderlying: lts[Tokens.DAI], + underlying: addressOf[TOKEN_DAI], + ltUnderlying: lts[TOKEN_DAI], twvUSDTarget: _case.target, convertToUSDFn: _convertToUSD, priceOracle: PRICE_ORACLE diff --git a/contracts/test/unit/libraries/CollateralLogicHelper.sol b/contracts/test/unit/libraries/CollateralLogicHelper.sol index c62fdfa4..d52b9b60 100644 --- a/contracts/test/unit/libraries/CollateralLogicHelper.sol +++ b/contracts/test/unit/libraries/CollateralLogicHelper.sol @@ -3,7 +3,7 @@ // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {MockTokensData, MockToken} from "../../config/MockTokensData.sol"; import {CollateralLogic} from "../../../libraries/CollateralLogic.sol"; @@ -16,30 +16,30 @@ import "forge-std/console.sol"; address constant PRICE_ORACLE = DUMB_ADDRESS4; struct B { - Tokens t; + uint256 t; uint256 balance; } struct Q { - Tokens t; + uint256 t; uint256 quota; } contract CollateralLogicHelper is TestHelper { uint256 session; - mapping(Tokens => uint256) tokenMask; + mapping(uint256 => uint256) tokenMask; - mapping(uint256 => Tokens) tokenByMask; + mapping(uint256 => uint256) tokenByMask; - mapping(Tokens => address) addressOf; - mapping(Tokens => string) symbolOf; - mapping(address => Tokens) tokenOf; + mapping(uint256 => address) addressOf; + mapping(uint256 => string) symbolOf; + mapping(address => uint256) tokenOf; - mapping(Tokens => uint16) lts; + mapping(uint256 => uint16) lts; mapping(address => uint256) _prices; - mapping(Tokens => uint256) prices; + mapping(uint256 => uint256) prices; mapping(address => bool) revertIsPriceOracleCalled; @@ -69,8 +69,8 @@ contract CollateralLogicHelper is TestHelper { } function _collateralTokenByMask(uint256 _tokenMask, bool calcLT) internal view returns (address token, uint16 lt) { - Tokens t = tokenByMask[_tokenMask]; - if (t == Tokens.NO_TOKEN) { + uint256 t = tokenByMask[_tokenMask]; + if (t == TOKEN_NO_TOKEN) { console.log("Cant find token with mask"); console.log(_tokenMask); revert("Token not found"); @@ -83,7 +83,7 @@ contract CollateralLogicHelper is TestHelper { /// HELPERS /// @dev Deployes order token and store info - function deploy(Tokens t, string memory symbol, uint8 index) internal { + function deploy(uint256 t, string memory symbol, uint8 index) internal { address token = address(new OrderToken()); addressOf[t] = token; tokenOf[token] = t; @@ -97,7 +97,7 @@ contract CollateralLogicHelper is TestHelper { vm.label(addressOf[t], symbol); } - function setTokenParams(Tokens t, uint16 lt, uint256 price) internal { + function setTokenParams(uint256 t, uint16 lt, uint256 price) internal { lts[t] = lt; prices[t] = price; _prices[addressOf[t]] = price; @@ -108,8 +108,8 @@ contract CollateralLogicHelper is TestHelper { } function saveCallOrder() external view returns (uint256) { - Tokens currentToken = tokenOf[msg.sender]; - if (currentToken == Tokens.NO_TOKEN) { + uint256 currentToken = tokenOf[msg.sender]; + if (currentToken == TOKEN_NO_TOKEN) { revert("Incorrect tokens order"); } @@ -123,18 +123,18 @@ contract CollateralLogicHelper is TestHelper { } } - function expectTokensOrder(Tokens[] memory tokens, bool debug) internal { + function expectTokensOrder(uint256[] memory tokens, bool debug) internal { (bytes32[] memory reads,) = vm.accesses(address(this)); uint256 len = reads.length; - Tokens[] memory callOrder = new Tokens[](len); + uint256[] memory callOrder = new uint256[](len); uint256 j; for (uint256 i; i < len; ++i) { uint256 slot = uint256(reads[i]); - if (slot > 100 && slot <= (100 + uint256(type(Tokens).max))) { - callOrder[j] = Tokens(slot - 100); + if (slot > 100 && slot <= (100 + NUM_TOKENS)) { + callOrder[j] = slot - 100; ++j; } } @@ -170,17 +170,17 @@ contract CollateralLogicHelper is TestHelper { } } - function printTokens(Tokens[] memory tokens) internal view { + function printTokens(uint256[] memory tokens) internal view { uint256 len = tokens.length; for (uint256 i; i < len; ++i) { - Tokens t = Tokens(tokens[i]); - if (t == Tokens.NO_TOKEN) break; + uint256 t = tokens[i]; + if (t == TOKEN_NO_TOKEN) break; console.log(symbolOf[t]); } } - function getTokenMask(Tokens[] memory tokens) internal view returns (uint256 mask) { + function getTokenMask(uint256[] memory tokens) internal view returns (uint256 mask) { uint256 len = tokens.length; for (uint256 i; i < len; ++i) { mask |= tokenMask[tokens[i]]; @@ -212,38 +212,42 @@ contract CollateralLogicHelper is TestHelper { /// - function arrayOf(Tokens t1) internal pure returns (Tokens[] memory result) { - result = new Tokens[](1); + function arrayOfTokens(uint256 t1) internal pure returns (uint256[] memory result) { + result = new uint256[](1); result[0] = t1; } - function arrayOf(Tokens t1, Tokens t2) internal pure returns (Tokens[] memory result) { - result = new Tokens[](2); + function arrayOfTokens(uint256 t1, uint256 t2) internal pure returns (uint256[] memory result) { + result = new uint256[](2); result[0] = t1; result[1] = t2; } - function arrayOf(Tokens t1, Tokens t2, Tokens t3) internal pure returns (Tokens[] memory result) { - result = new Tokens[](3); + function arrayOfTokens(uint256 t1, uint256 t2, uint256 t3) internal pure returns (uint256[] memory result) { + result = new uint256[](3); result[0] = t1; result[1] = t2; result[2] = t3; } - function arrayOf(Tokens t1, Tokens t2, Tokens t3, Tokens t4) internal pure returns (Tokens[] memory result) { - result = new Tokens[](4); + function arrayOfTokens(uint256 t1, uint256 t2, uint256 t3, uint256 t4) + internal + pure + returns (uint256[] memory result) + { + result = new uint256[](4); result[0] = t1; result[1] = t2; result[2] = t3; result[3] = t4; } - function arrayOf(Tokens t1, Tokens t2, Tokens t3, Tokens t4, Tokens t5) + function arrayOfTokens(uint256 t1, uint256 t2, uint256 t3, uint256 t4, uint256 t5) internal pure - returns (Tokens[] memory result) + returns (uint256[] memory result) { - result = new Tokens[](5); + result = new uint256[](5); result[0] = t1; result[1] = t2; result[2] = t3; diff --git a/contracts/test/unit/libraries/CreditAccountHelper.unit.t.sol b/contracts/test/unit/libraries/CreditAccountHelper.unit.t.sol index 6733e5ab..e90e07fd 100644 --- a/contracts/test/unit/libraries/CreditAccountHelper.unit.t.sol +++ b/contracts/test/unit/libraries/CreditAccountHelper.unit.t.sol @@ -10,7 +10,7 @@ import {CreditAccountV3} from "../../../credit/CreditAccountV3.sol"; import {ERC20ApproveRestrictedRevert, ERC20ApproveRestrictedFalse} from "../../mocks/token/ERC20ApproveRestricted.sol"; import {TokensTestSuite} from "../../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {TestHelper} from "../../lib/helper.sol"; import {BalanceHelper} from "../../helpers/BalanceHelper.sol"; @@ -31,13 +31,13 @@ contract CreditAccountHelperUnitTest is TestHelper, BalanceHelper { /// @notice U:[CAH-1]: approveCreditAccount approves with desired allowance function test_U_CAH_01_safeApprove_approves_with_desired_allowance() public { // Case, when current allowance > Allowance_THRESHOLD - tokenTestSuite.approve(Tokens.DAI, creditAccount, DUMB_ADDRESS, 200); + tokenTestSuite.approve(TOKEN_DAI, creditAccount, DUMB_ADDRESS, 200); - address dai = tokenTestSuite.addressOf(Tokens.DAI); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); CreditAccountHelper.safeApprove(creditAccount, dai, DUMB_ADDRESS, DAI_EXCHANGE_AMOUNT); - expectAllowance(Tokens.DAI, creditAccount, DUMB_ADDRESS, DAI_EXCHANGE_AMOUNT); + expectAllowance(TOKEN_DAI, creditAccount, DUMB_ADDRESS, DAI_EXCHANGE_AMOUNT); } /// @dev U:[CAH-2]: approveCreditAccount works for ERC20 that revert if allowance > 0 before approve diff --git a/contracts/test/unit/pool/GaugeV3.unit.t.sol b/contracts/test/unit/pool/GaugeV3.unit.t.sol index 8323176c..7c9a8b15 100644 --- a/contracts/test/unit/pool/GaugeV3.unit.t.sol +++ b/contracts/test/unit/pool/GaugeV3.unit.t.sol @@ -21,7 +21,7 @@ import {AddressProviderV3ACLMock} from "../../mocks/core/AddressProviderV3ACLMoc // SUITES import {TokensTestSuite} from "../../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {TestHelper} from "../../lib/helper.sol"; // EXCEPTIONS @@ -46,7 +46,7 @@ contract GauageV3UnitTest is TestHelper, IGaugeV3Events { tokenTestSuite.topUpWETH{value: 100 * WAD}(); - underlying = tokenTestSuite.addressOf(Tokens.DAI); + underlying = tokenTestSuite.addressOf(TOKEN_DAI); vm.prank(CONFIGURATOR); addressProvider = new AddressProviderV3ACLMock(); diff --git a/contracts/test/unit/pool/PoolQuotaKeeperV3.unit.t.sol b/contracts/test/unit/pool/PoolQuotaKeeperV3.unit.t.sol index 559cd847..ab191fc5 100644 --- a/contracts/test/unit/pool/PoolQuotaKeeperV3.unit.t.sol +++ b/contracts/test/unit/pool/PoolQuotaKeeperV3.unit.t.sol @@ -19,7 +19,7 @@ import {PoolMock} from "../../mocks/pool/PoolMock.sol"; import {CreditManagerMock} from "../../mocks/credit/CreditManagerMock.sol"; import {TokensTestSuite} from "../../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {BalanceHelper} from "../../helpers/BalanceHelper.sol"; import {PoolQuotaKeeperV3} from "../../../pool/PoolQuotaKeeperV3.sol"; @@ -51,10 +51,10 @@ contract PoolQuotaKeeperV3UnitTest is TestHelper, BalanceHelper, IPoolQuotaKeepe CreditManagerMock creditManagerMock; function setUp() public { - _setUp(Tokens.DAI); + _setUp(TOKEN_DAI); } - function _setUp(Tokens t) public { + function _setUp(uint256 t) public { tokenTestSuite = new TokensTestSuite(); tokenTestSuite.topUpWETH{value: 100 * WAD}(); @@ -62,7 +62,7 @@ contract PoolQuotaKeeperV3UnitTest is TestHelper, BalanceHelper, IPoolQuotaKeepe underlying = tokenTestSuite.addressOf(t); addressProvider = new AddressProviderV3ACLMock(); - addressProvider.setAddress(AP_WETH_TOKEN, tokenTestSuite.addressOf(Tokens.WETH), false); + addressProvider.setAddress(AP_WETH_TOKEN, tokenTestSuite.addressOf(TOKEN_WETH), false); poolMock = new PoolMock(address(addressProvider), underlying); @@ -184,8 +184,8 @@ contract PoolQuotaKeeperV3UnitTest is TestHelper, BalanceHelper, IPoolQuotaKeepe /// @notice U:[PQK-7]: updateRates works as expected function test_U_PQK_07_updateRates_works_as_expected() public { - address DAI = tokenTestSuite.addressOf(Tokens.DAI); - address USDC = tokenTestSuite.addressOf(Tokens.USDC); + address DAI = tokenTestSuite.addressOf(TOKEN_DAI); + address USDC = tokenTestSuite.addressOf(TOKEN_USDC); uint16 DAI_QUOTA_RATE = 20_00; uint16 USDC_QUOTA_RATE = 45_00; @@ -281,7 +281,7 @@ contract PoolQuotaKeeperV3UnitTest is TestHelper, BalanceHelper, IPoolQuotaKeepe /// @notice U:[PQK-7B]: updateRates reverts on zero rate function test_U_PQK_07B_updateRates_reverts_on_zero_rate() public { - address dai = tokenTestSuite.addressOf(Tokens.DAI); + address dai = tokenTestSuite.addressOf(TOKEN_DAI); gaugeMock.addQuotaToken(dai, 0); @@ -409,7 +409,7 @@ contract PoolQuotaKeeperV3UnitTest is TestHelper, BalanceHelper, IPoolQuotaKeepe function test_U_PQK_14_updateQuotas_reverts_for_unregistered_token() public { pqk.addCreditManager(address(creditManagerMock)); - address link = tokenTestSuite.addressOf(Tokens.LINK); + address link = tokenTestSuite.addressOf(TOKEN_LINK); vm.expectRevert(TokenIsNotQuotedException.selector); vm.prank(address(creditManagerMock)); diff --git a/contracts/test/unit/pool/PoolV3.unit.t.sol b/contracts/test/unit/pool/PoolV3.unit.t.sol index d7e76afe..42fa47d7 100644 --- a/contracts/test/unit/pool/PoolV3.unit.t.sol +++ b/contracts/test/unit/pool/PoolV3.unit.t.sol @@ -16,7 +16,7 @@ import {IPoolQuotaKeeperV3} from "../../../interfaces/IPoolQuotaKeeperV3.sol"; import {IPoolV3Events} from "../../../interfaces/IPoolV3.sol"; import {TokensTestSuite} from "../../suites/TokensTestSuite.sol"; -import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; +import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol"; import {TestHelper} from "../../lib/helper.sol"; import { AddressProviderV3ACLMock, AP_TREASURY, NO_VERSION_CONTROL diff --git a/lib/@gearbox-protocol/sdk-gov b/lib/@gearbox-protocol/sdk-gov index a77aeed2..7c13707d 160000 --- a/lib/@gearbox-protocol/sdk-gov +++ b/lib/@gearbox-protocol/sdk-gov @@ -1 +1 @@ -Subproject commit a77aeed2ccc978c856fc941cc1583166d3b046c7 +Subproject commit 7c13707d584b3e7f394f732bdf5bdbe020283c59