Skip to content

Commit

Permalink
fix: tokens enum fix (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Van0k authored Nov 26, 2024
1 parent f196c7c commit 4454ba7
Show file tree
Hide file tree
Showing 29 changed files with 351 additions and 285 deletions.
9 changes: 9 additions & 0 deletions config_scripts/test_daiMainnetScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {
PoolV3CoreConfigurator,
testDaiConfigMainnet,
} from "@gearbox-protocol/sdk-gov";

const poolCfg = PoolV3CoreConfigurator.new(testDaiConfigMainnet);
console.error(poolCfg.toString());

console.log(poolCfg.deployConfig());
26 changes: 12 additions & 14 deletions contracts/test/config/TEST_DAI_Mainnet_config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.17;

import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import {Contracts} from "@gearbox-protocol/sdk-gov/contracts/SupportedContracts.sol";
import {
LinearIRMV3DeployParams,
Expand All @@ -24,7 +24,7 @@ import {
contract CONFIG_MAINNET_DAI_TEST_V3 is IPoolV3DeployConfig {
string public constant id = "mainnet-dai-test-v3";
uint256 public constant chainId = 1;
Tokens public constant underlying = Tokens.DAI;
uint256 public constant underlying = TOKEN_DAI;
bool public constant supportsQuotas = true;
uint256 public constant getAccountAmount = 100_000_000_000_000_000_000_000;

Expand Down Expand Up @@ -52,16 +52,16 @@ contract CONFIG_MAINNET_DAI_TEST_V3 is IPoolV3DeployConfig {
CreditManagerV3DeployParams[] _creditManagers;

constructor() {
_gaugeRates.push(GaugeRate({token: Tokens.USDS, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: Tokens.stkUSDS, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: Tokens.SKY, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_USDS, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_stkUSDS, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_SKY, minRate: 4, maxRate: 1_500}));
_quotaLimits.push(
PoolQuotaLimit({token: Tokens.USDS, quotaIncreaseFee: 1, limit: 10_000_000_000_000_000_000_000_000})
PoolQuotaLimit({token: TOKEN_USDS, quotaIncreaseFee: 1, limit: 10_000_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: Tokens.stkUSDS, quotaIncreaseFee: 1, limit: 10_000_000_000_000_000_000_000_000})
PoolQuotaLimit({token: TOKEN_stkUSDS, quotaIncreaseFee: 1, limit: 10_000_000_000_000_000_000_000_000})
);
_quotaLimits.push(PoolQuotaLimit({token: Tokens.SKY, quotaIncreaseFee: 1, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_SKY, quotaIncreaseFee: 1, limit: 0}));

{
/// CREDIT_MANAGER_0
Expand All @@ -81,20 +81,18 @@ contract CONFIG_MAINNET_DAI_TEST_V3 is IPoolV3DeployConfig {
cp.name = "Test Credit Manager";

CollateralTokenHuman[] storage cts = cp.collateralTokens;
cts.push(CollateralTokenHuman({token: Tokens.USDS, lt: 9_000}));
cts.push(CollateralTokenHuman({token: TOKEN_USDS, lt: 9_000}));

cts.push(CollateralTokenHuman({token: Tokens.stkUSDS, lt: 9_000}));
cts.push(CollateralTokenHuman({token: TOKEN_stkUSDS, lt: 9_000}));

cts.push(CollateralTokenHuman({token: Tokens.SKY, lt: 0}));
cts.push(CollateralTokenHuman({token: TOKEN_SKY, lt: 0}));
Contracts[] storage cs = cp.contracts;
cs.push(Contracts.DAI_USDS);
cs.push(Contracts.SKY_STAKING_REWARDS);
cs.push(Contracts.UNISWAP_V2_ROUTER);
{
GenericSwapPair[] storage gsp = cp.adapterConfig.genericSwapPairs;
gsp.push(
GenericSwapPair({router: Contracts.UNISWAP_V2_ROUTER, token0: Tokens.SKY, token1: Tokens.USDS})
);
gsp.push(GenericSwapPair({router: Contracts.UNISWAP_V2_ROUTER, token0: TOKEN_SKY, token1: TOKEN_USDS}));
}
}
}
Expand Down
165 changes: 142 additions & 23 deletions contracts/test/config/TEST_WETH_Mainnet_config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.17;

import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import {Contracts} from "@gearbox-protocol/sdk-gov/contracts/SupportedContracts.sol";
import {
LinearIRMV3DeployParams,
Expand All @@ -24,7 +24,7 @@ import {
contract CONFIG_MAINNET_WETH_TEST_V3 is IPoolV3DeployConfig {
string public constant id = "mainnet-weth-test-v3";
uint256 public constant chainId = 1;
Tokens public constant underlying = Tokens.WETH;
uint256 public constant underlying = TOKEN_WETH;
bool public constant supportsQuotas = true;
uint256 public constant getAccountAmount = 50_000_000_000_000_000_000;

Expand Down Expand Up @@ -52,27 +52,67 @@ contract CONFIG_MAINNET_WETH_TEST_V3 is IPoolV3DeployConfig {
CreditManagerV3DeployParams[] _creditManagers;

constructor() {
_gaugeRates.push(GaugeRate({token: Tokens.steCRV, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: Tokens.STETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: Tokens.wstETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: Tokens.steakLRT, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: Tokens.rsETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: Tokens.PT_rsETH_26SEP2024, minRate: 4, maxRate: 1_500}));
_quotaLimits.push(PoolQuotaLimit({token: Tokens.steCRV, quotaIncreaseFee: 0, limit: 0}));
_gaugeRates.push(GaugeRate({token: TOKEN_LDO, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_CRV, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_CVX, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_steCRV, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_cvxsteCRV, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_rsETH_WETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_trenSTETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_Re7LRT, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_rstETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_amphrETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_STETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_stkcvxsteCRV, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_wstETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_steakLRT, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_rsETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_PT_rsETH_26SEP2024, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_USDC, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_WBTC, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_pufETHwstE, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_pufETH, minRate: 4, maxRate: 1_500}));
_gaugeRates.push(GaugeRate({token: TOKEN_zpufETH, minRate: 4, maxRate: 1_500}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_LDO, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_CRV, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_CVX, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_steCRV, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_cvxsteCRV, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_rsETH_WETH, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_trenSTETH, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_Re7LRT, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_rstETH, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_amphrETH, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(
PoolQuotaLimit({token: Tokens.STETH, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
PoolQuotaLimit({token: TOKEN_STETH, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: Tokens.wstETH, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
PoolQuotaLimit({token: TOKEN_stkcvxsteCRV, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: Tokens.steakLRT, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
PoolQuotaLimit({token: TOKEN_wstETH, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: Tokens.rsETH, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
PoolQuotaLimit({token: TOKEN_steakLRT, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: Tokens.PT_rsETH_26SEP2024, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
PoolQuotaLimit({token: TOKEN_rsETH, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: TOKEN_PT_rsETH_26SEP2024, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: TOKEN_USDC, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: TOKEN_WBTC, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(PoolQuotaLimit({token: TOKEN_pufETHwstE, quotaIncreaseFee: 0, limit: 0}));
_quotaLimits.push(
PoolQuotaLimit({token: TOKEN_pufETH, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);
_quotaLimits.push(
PoolQuotaLimit({token: TOKEN_zpufETH, quotaIncreaseFee: 0, limit: 4_000_000_000_000_000_000_000})
);

{
Expand All @@ -90,27 +130,102 @@ contract CONFIG_MAINNET_WETH_TEST_V3 is IPoolV3DeployConfig {
cp.expirable = false;
cp.skipInit = false;
cp.poolLimit = 5_000_000_000_000_000_000_000;
cp.name = "Test Credit Manager";

CollateralTokenHuman[] storage cts = cp.collateralTokens;
cts.push(CollateralTokenHuman({token: Tokens.STETH, lt: 9_000}));
cts.push(CollateralTokenHuman({token: TOKEN_USDC, lt: 9_000}));

cts.push(CollateralTokenHuman({token: TOKEN_WBTC, lt: 9_000}));

cts.push(CollateralTokenHuman({token: TOKEN_STETH, lt: 9_000}));

cts.push(CollateralTokenHuman({token: TOKEN_wstETH, lt: 9_000}));

cts.push(CollateralTokenHuman({token: TOKEN_steakLRT, lt: 9_000}));

cts.push(CollateralTokenHuman({token: Tokens.wstETH, lt: 9_000}));
cts.push(CollateralTokenHuman({token: TOKEN_rsETH, lt: 9_000}));

cts.push(CollateralTokenHuman({token: Tokens.steakLRT, lt: 9_000}));
cts.push(CollateralTokenHuman({token: TOKEN_PT_rsETH_26SEP2024, lt: 9_000}));

cts.push(CollateralTokenHuman({token: Tokens.rsETH, lt: 9_000}));
cts.push(CollateralTokenHuman({token: TOKEN_stkcvxsteCRV, lt: 9_000}));

cts.push(CollateralTokenHuman({token: Tokens.PT_rsETH_26SEP2024, lt: 9_000}));
cts.push(CollateralTokenHuman({token: TOKEN_pufETH, lt: 9_000}));

cts.push(CollateralTokenHuman({token: Tokens.steCRV, lt: 0}));
cts.push(CollateralTokenHuman({token: TOKEN_zpufETH, lt: 9_000}));

cts.push(CollateralTokenHuman({token: TOKEN_steCRV, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_cvxsteCRV, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_rsETH_WETH, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_trenSTETH, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_Re7LRT, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_rstETH, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_amphrETH, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_LDO, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_CRV, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_CVX, lt: 0}));

cts.push(CollateralTokenHuman({token: TOKEN_pufETHwstE, lt: 0}));
Contracts[] storage cs = cp.contracts;
cs.push(Contracts.UNISWAP_V3_ROUTER);
{
UniswapV3Pair[] storage uv3p = cp.adapterConfig.uniswapV3Pairs;
uv3p.push(
UniswapV3Pair({
router: Contracts.UNISWAP_V3_ROUTER,
token0: TOKEN_WETH,
token1: TOKEN_WBTC,
fee: 3000
})
);
uv3p.push(
UniswapV3Pair({
router: Contracts.UNISWAP_V3_ROUTER,
token0: TOKEN_WETH,
token1: TOKEN_USDC,
fee: 500
})
);
uv3p.push(
UniswapV3Pair({
router: Contracts.UNISWAP_V3_ROUTER,
token0: TOKEN_WETH,
token1: TOKEN_CRV,
fee: 3000
})
);
uv3p.push(
UniswapV3Pair({
router: Contracts.UNISWAP_V3_ROUTER,
token0: TOKEN_WETH,
token1: TOKEN_CRV,
fee: 10000
})
);
uv3p.push(
UniswapV3Pair({
router: Contracts.UNISWAP_V3_ROUTER,
token0: TOKEN_WETH,
token1: TOKEN_CVX,
fee: 10000
})
);
}
cs.push(Contracts.PENDLE_ROUTER);
PendlePair[] storage pendp = cp.adapterConfig.pendlePairs;
pendp.push(
PendlePair({
market: 0x6b4740722e46048874d84306B2877600ABCea3Ae,
inputToken: Tokens.rsETH,
pendleToken: Tokens.PT_rsETH_26SEP2024,
inputToken: TOKEN_rsETH,
pendleToken: TOKEN_PT_rsETH_26SEP2024,
status: 1
})
);
Expand All @@ -127,10 +242,14 @@ contract CONFIG_MAINNET_WETH_TEST_V3 is IPoolV3DeployConfig {
cs.push(Contracts.MELLOW_STEAKHOUSE_VAULT);
{
MellowUnderlyingConfig[] storage mu = cp.adapterConfig.mellowUnderlyings;
mu.push(MellowUnderlyingConfig({vault: Contracts.MELLOW_STEAKHOUSE_VAULT, underlying: Tokens.wstETH}));
mu.push(MellowUnderlyingConfig({vault: Contracts.MELLOW_STEAKHOUSE_VAULT, underlying: TOKEN_wstETH}));
}
cs.push(Contracts.LIDO_WSTETH);
cs.push(Contracts.CURVE_STETH_GATEWAY);
cs.push(Contracts.CURVE_PUFETH_WSTETH_POOL);
cs.push(Contracts.CONVEX_BOOSTER);
cs.push(Contracts.CONVEX_STECRV_POOL);
cs.push(Contracts.ZIRCUIT_POOL);
}
}

Expand Down
16 changes: 8 additions & 8 deletions contracts/test/helpers/BalanceComparator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// (c) Gearbox Foundation, 2023.
pragma solidity ^0.8.10;

import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand All @@ -14,7 +14,7 @@ import {TokensTestSuite} from "@gearbox-protocol/core-v3/contracts/test/suites/T

struct BalanceBackup {
string stage;
Tokens token;
uint256 token;
uint256 balance;
}

Expand All @@ -24,13 +24,13 @@ contract BalanceComparator is Test {
error StageNotAllowed(string);

TokensTestSuite public tokenTestSuite;
Tokens[] public tokensToTrack;
mapping(string => mapping(Tokens => mapping(address => uint256))) savedBalances;
uint256[] public tokensToTrack;
mapping(string => mapping(uint256 => mapping(address => uint256))) savedBalances;

string[] public stages;
mapping(string => bool) _allowedStages;

constructor(string[] memory _stages, Tokens[] memory _tokensToTrack, TokensTestSuite _tokenTestSuite) {
constructor(string[] memory _stages, uint256[] memory _tokensToTrack, TokensTestSuite _tokenTestSuite) {
tokenTestSuite = _tokenTestSuite;
uint256 len = _tokensToTrack.length;
unchecked {
Expand All @@ -53,7 +53,7 @@ contract BalanceComparator is Test {
uint256 len = tokensToTrack.length;
unchecked {
for (uint256 i; i < len; ++i) {
Tokens t = tokensToTrack[i];
uint256 t = tokensToTrack[i];
uint256 balance = IERC20(tokenTestSuite.addressOf(t)).balanceOf(holder);
savedBalances[stage][t][holder] = balance;
}
Expand All @@ -68,7 +68,7 @@ contract BalanceComparator is Test {

for (uint256 j; j < lenStages; ++j) {
for (uint256 i; i < len; ++i) {
Tokens t = tokensToTrack[i];
uint256 t = tokensToTrack[i];
string memory stage = stages[j];

result[i + j * len] =
Expand Down Expand Up @@ -97,7 +97,7 @@ contract BalanceComparator is Test {
unchecked {
for (uint256 j; j < lenStages; ++j) {
for (uint256 i; i < len; ++i) {
Tokens t = tokensToTrack[i];
uint256 t = tokensToTrack[i];
string memory stage = stages[j];

if (expectedError == 0) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/helpers/BalanceHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pragma solidity ^0.8.10;

import {TokensTestSuite} from "@gearbox-protocol/core-v3/contracts/test/suites/TokensTestSuite.sol";
import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";

import {BalanceEngine} from "@gearbox-protocol/core-v3/contracts/test/helpers/BalanceEngine.sol";

Expand Down
4 changes: 2 additions & 2 deletions contracts/test/helpers/CreditFacadeTestHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ pragma solidity ^0.8.17;
import {TokensTestSuite} from "@gearbox-protocol/core-v3/contracts/test/suites/TokensTestSuite.sol";

import {PriceFeedMock} from "@gearbox-protocol/core-v3/contracts/test/mocks/oracles/PriceFeedMock.sol";
import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";

import {IntegrationTestHelper} from "@gearbox-protocol/core-v3/contracts/test/helpers/IntegrationTestHelper.sol";

import "../lib/constants.sol";

contract CreditFacadeTestHelper is IntegrationTestHelper {
function addCollateral(address, /*creditAccount*/ Tokens t, uint256 amount) internal {
function addCollateral(address, /*creditAccount*/ uint256 t, uint256 amount) internal {
tokenTestSuite.mint(t, USER, amount);
tokenTestSuite.approve(t, USER, address(creditManager));

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/live/Env.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.17;

import {LiveTestHelper} from "../suites/LiveTestHelper.sol";

import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";
import "forge-std/console.sol";

contract Live_LidoEquivalenceTest is LiveTestHelper {
Expand Down
Loading

0 comments on commit 4454ba7

Please sign in to comment.