Skip to content

Commit

Permalink
feat: replace Tokens enum with uint256 (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Van0k authored Nov 26, 2024
1 parent ae093e2 commit b959c4b
Show file tree
Hide file tree
Showing 27 changed files with 771 additions and 2,782 deletions.
28 changes: 14 additions & 14 deletions contracts/test/config/MockCreditConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -34,7 +34,7 @@ contract MockCreditConfig is Test, IPoolV3DeployConfig {
uint128 public maxDebt;
uint256 public chainId;

Tokens public underlying;
uint256 public underlying;
bool public constant supportsQuotas = true;

PoolV3DeployParams _poolParams;
Expand All @@ -53,7 +53,7 @@ contract MockCreditConfig is Test, IPoolV3DeployConfig {
PoolQuotaLimit[] _quotaLimits;
CreditManagerV3DeployParams[] _creditManagers;

constructor(TokensTestSuite tokenTestSuite_, Tokens _underlying) {
constructor(TokensTestSuite tokenTestSuite_, uint256 _underlying) {
NetworkDetector nd = new NetworkDetector();
chainId = nd.chainId();

Expand Down Expand Up @@ -90,16 +90,16 @@ contract MockCreditConfig is Test, IPoolV3DeployConfig {
pushCollateralToken(_underlying, cp.collateralTokens);
}

function pushCollateralToken(Tokens _underlying, CollateralTokenHuman[] storage cth) private {
function pushCollateralToken(uint256 _underlying, CollateralTokenHuman[] storage cth) private {
CollateralTokenHuman[8] memory collateralTokenOpts = [
CollateralTokenHuman({token: Tokens.USDC, lt: 90_00}),
CollateralTokenHuman({token: Tokens.USDT, lt: 88_00}),
CollateralTokenHuman({token: Tokens.DAI, lt: 83_00}),
CollateralTokenHuman({token: Tokens.WETH, lt: 83_00}),
CollateralTokenHuman({token: Tokens.LINK, lt: 73_00}),
CollateralTokenHuman({token: Tokens.CRV, lt: 73_00}),
CollateralTokenHuman({token: Tokens.CVX, lt: 73_00}),
CollateralTokenHuman({token: Tokens.STETH, lt: 73_00})
CollateralTokenHuman({token: TOKEN_USDC, lt: 90_00}),
CollateralTokenHuman({token: TOKEN_USDT, lt: 88_00}),
CollateralTokenHuman({token: TOKEN_DAI, lt: 83_00}),
CollateralTokenHuman({token: TOKEN_WETH, lt: 83_00}),
CollateralTokenHuman({token: TOKEN_LINK, lt: 73_00}),
CollateralTokenHuman({token: TOKEN_CRV, lt: 73_00}),
CollateralTokenHuman({token: TOKEN_CVX, lt: 73_00}),
CollateralTokenHuman({token: TOKEN_STETH, lt: 73_00})
];

uint256 len = collateralTokenOpts.length;
Expand All @@ -111,9 +111,9 @@ contract MockCreditConfig is Test, IPoolV3DeployConfig {
}

function getAccountAmount() public view override returns (uint256) {
return (underlying == Tokens.DAI)
return (underlying == TOKEN_DAI)
? DAI_ACCOUNT_AMOUNT
: (underlying == Tokens.USDC) ? USDC_ACCOUNT_AMOUNT : WETH_ACCOUNT_AMOUNT;
: (underlying == TOKEN_USDC) ? USDC_ACCOUNT_AMOUNT : WETH_ACCOUNT_AMOUNT;
}

// GETTERS
Expand Down
36 changes: 15 additions & 21 deletions contracts/test/config/MockTokensData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
];

Expand Down
Loading

0 comments on commit b959c4b

Please sign in to comment.