Skip to content

Commit

Permalink
chore: add base chain tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KedziaPawel authored Dec 9, 2024
1 parent 108e423 commit fa6e659
Show file tree
Hide file tree
Showing 13 changed files with 500 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ETHEREUM_NODE_MAINNET=
ETHEREUM_NODE_POLYGON=
ETHEREUM_NODE_ARBITRUM=
ETHEREUM_NODE_BASE=

ETHERSCAN_API_KEY_MAINNET=
ETHERSCAN_API_KEY_POLYGON=
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ optimizer=false
mainnet = "${ETHEREUM_NODE_MAINNET}"
polygon = "${ETHEREUM_NODE_POLYGON}"
arbitrum = "${ETHEREUM_NODE_ARBITRUM}"
base = "${ETHEREUM_NODE_BASE}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY_MAINNET}", chain = "mainnet" }
Expand Down
104 changes: 100 additions & 4 deletions tests/bases/IntegrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ import {
Contracts as PersistentContracts,
getMainnetDeployment as getMainnetPersistentContracts,
getPolygonDeployment as getPolygonPersistentContracts,
getArbitrumDeployment as getArbitrumPersistentContracts
getArbitrumDeployment as getArbitrumPersistentContracts,
getBaseChainDeployment as getBaseChainPersistentContracts
} from "tests/utils/core/deployment/PersistentContracts.sol";
import {ReleaseConfig} from "tests/utils/core/deployment/DeploymentUtils.sol";
import {
Contracts as V4ReleaseContracts,
getMainnetDeployment as getV4MainnetReleaseContracts,
getPolygonDeployment as getV4PolygonReleaseContracts,
getArbitrumDeployment as getV4ArbitrumReleaseContracts
getArbitrumDeployment as getV4ArbitrumReleaseContracts,
getBaseChainDeployment as getV4BaseChainReleaseContracts
} from "tests/utils/core/deployment/V4ReleaseContracts.sol";
import {
Contracts as ReleaseContracts,
getMainnetDeployment as getMainnetReleaseContracts,
getPolygonDeployment as getPolygonReleaseContracts,
getArbitrumDeployment as getArbitrumReleaseContracts
getArbitrumDeployment as getArbitrumReleaseContracts,
getBaseChainDeployment as getBaseReleaseContracts
} from "tests/utils/core/deployment/V5ReleaseContracts.sol";

import {IERC20} from "tests/interfaces/external/IERC20.sol";
Expand Down Expand Up @@ -96,7 +99,7 @@ abstract contract IntegrationTest is CoreUtils {
}

function setUpLiveArbitrumEnvironment(uint256 _forkBlock) internal {
vm.createSelectFork("polygon", _forkBlock);
vm.createSelectFork("arbitrum", _forkBlock);

core.persistent = getArbitrumPersistentContracts();
v4ReleaseContracts = getV4ArbitrumReleaseContracts();
Expand All @@ -105,6 +108,16 @@ abstract contract IntegrationTest is CoreUtils {
// core.release = getArbitrumReleaseContracts();
}

function setUpLiveBaseChainEnvironment(uint256 _forkBlock) internal {
vm.createSelectFork("base", _forkBlock);

core.persistent = getBaseChainPersistentContracts();
v4ReleaseContracts = getV4BaseChainReleaseContracts();

// No v5 release live
// core.release = getBaseReleaseContracts();
}

// Partially-live deployments (persistent layer only)

function setUpLiveMainnetEnvironmentWithNewRelease(uint256 _forkBlock) internal {
Expand All @@ -131,6 +144,14 @@ abstract contract IntegrationTest is CoreUtils {
__setUpEnvironment({_config: getDefaultArbitrumConfig(), _persistentContractsAlreadySet: true});
}

function setUpLiveBaseChainEnvironmentWithNewRelease(uint256 _forkBlock) internal {
vm.createSelectFork("base", _forkBlock);

core.persistent = getBaseChainPersistentContracts();

__setUpEnvironment({_config: getDefaultBaseChainConfig(), _persistentContractsAlreadySet: true});
}

// New deployments
function setUpNetworkEnvironment(uint256 _chainId) internal {
if (_chainId == ETHEREUM_CHAIN_ID) {
Expand All @@ -139,6 +160,8 @@ abstract contract IntegrationTest is CoreUtils {
setUpPolygonEnvironment();
} else if (_chainId == ARBITRUM_CHAIN_ID) {
setUpArbitrumEnvironment();
} else if (_chainId == BASE_CHAIN_ID) {
setUpBaseChainEnvironment();
} else {
revert("setUpNetworkEnvironment: Unsupported network");
}
Expand All @@ -151,6 +174,8 @@ abstract contract IntegrationTest is CoreUtils {
setUpPolygonEnvironment(_forkBlock);
} else if (_chainId == ARBITRUM_CHAIN_ID) {
setUpArbitrumEnvironment(_forkBlock);
} else if (_chainId == BASE_CHAIN_ID) {
setUpBaseChainEnvironment(_forkBlock);
} else {
revert("setUpNetworkEnvironment: Unsupported network");
}
Expand All @@ -168,6 +193,10 @@ abstract contract IntegrationTest is CoreUtils {
setUpArbitrumEnvironment(ARBITRUM_BLOCK_LATEST);
}

function setUpBaseChainEnvironment() internal {
setUpBaseChainEnvironment(BASE_BLOCK_LATEST);
}

function setUpMainnetEnvironment(uint256 _forkBlock) internal {
vm.createSelectFork({urlOrAlias: "mainnet", blockNumber: _forkBlock});

Expand Down Expand Up @@ -361,6 +390,49 @@ abstract contract IntegrationTest is CoreUtils {
__addCorePrimitives(corePrimitives);
}

function setUpBaseChainEnvironment(uint256 _forkBlock) internal {
vm.createSelectFork("base", _forkBlock);

v4ReleaseContracts = getV4BaseChainReleaseContracts();

ReleaseConfig memory config = getDefaultBaseChainConfig();

__setUpEnvironment({_config: config, _persistentContractsAlreadySet: false});

// Deploy minimal asset universe

// Treat WETH specially and directly add to coreTokens storage (does not require an aggregator)
symbolToCoreToken["WETH"] = IERC20(wethToken);
tokenToIsCore[IERC20(wethToken)] = true;

address simulatedUsdAddress = address(deployUsdEthSimulatedAggregator(config.chainlinkEthUsdAggregatorAddress));

CorePrimitiveInput[] memory corePrimitives = new CorePrimitiveInput[](2);
// TODO: ucomment this when the real MLN aggregator address is available
// System primitives
// corePrimitives[0] = CorePrimitiveInput({
// symbol: "MLN",
// assetAddress: BASE_MLN,
// aggregatorAddress: BASE_MLN_ETH_AGGREGATOR,
// rateAsset: IChainlinkPriceFeedMixinProd.RateAsset.ETH
// });
// Extra primitives
corePrimitives[0] = CorePrimitiveInput({
symbol: "USD",
assetAddress: simulatedUsdAddress,
aggregatorAddress: simulatedUsdAddress,
rateAsset: IChainlinkPriceFeedMixinProd.RateAsset.ETH
});
corePrimitives[1] = CorePrimitiveInput({
symbol: "USDC",
assetAddress: BASE_USDC,
aggregatorAddress: BASE_USDC_USD_AGGREGATOR,
rateAsset: IChainlinkPriceFeedMixinProd.RateAsset.USD
});

__addCorePrimitives(corePrimitives);
}

function setUpStandaloneEnvironment() internal {
// Warp beyond Chainlink aggregator staleness threshold
uint256 chainlinkStaleRateThreshold = 3650 days;
Expand Down Expand Up @@ -546,6 +618,30 @@ abstract contract IntegrationTest is CoreUtils {
});
}

function getDefaultBaseChainConfig() internal returns (ReleaseConfig memory) {
address mlnBurner = makeAddr("MlnBurner");

return ReleaseConfig({
// Chainlink
chainlinkEthUsdAggregatorAddress: BASE_ETH_USD_AGGREGATOR,
chainlinkStaleRateThreshold: 3650 days,
// Tokens
mlnTokenAddress: BASE_MLN,
wethTokenAddress: BASE_WETH,
wrappedNativeTokenAddress: BASE_WETH,
// Gas relayer
gasRelayDepositCooldown: 1 days,
gasRelayDepositMaxTotal: 1 ether,
gasRelayFeeMaxPercent: 10,
gasRelayHubAddress: address(0), // TODO: lookup real value
gasRelayRelayFeeMaxBase: 0,
gasRelayTrustedForwarderAddress: address(0), // TODO: lookup real value
// Vault settings
vaultMlnBurner: mlnBurner,
vaultPositionsLimit: 20
});
}

// ASSET UNIVERSE

/// @dev Keep private to avoid accidental use
Expand Down
20 changes: 19 additions & 1 deletion tests/tests/protocols/aave/AaveV3Adapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
POLYGON_POOL_ADDRESS,
POLYGON_POOL_ADDRESS_PROVIDER,
ARBITRUM_POOL_ADDRESS,
ARBITRUM_POOL_ADDRESS_PROVIDER
ARBITRUM_POOL_ADDRESS_PROVIDER,
BASE_POOL_ADDRESS,
BASE_POOL_ADDRESS_PROVIDER
} from "./AaveV3Constants.sol";

abstract contract AaveV3AdapterTest is AaveAdapterTest, AaveV3Utils {
Expand Down Expand Up @@ -132,3 +134,19 @@ contract AaveV3AdapterTestArbitrum is AaveV3AdapterTest {
super.setUp();
}
}

contract AaveV3AdapterTestBaseChain is AaveV3AdapterTest {
function setUp() public override {
lendingPool = BASE_POOL_ADDRESS;
lendingPoolAddressProvider = BASE_POOL_ADDRESS_PROVIDER;

setUpBaseChainEnvironment();

regular18DecimalUnderlying = IERC20(BASE_WETH);
non18DecimalUnderlying = IERC20(BASE_USDC);

__registerTokensAndATokensForThem(toArray(address(regular18DecimalUnderlying), address(non18DecimalUnderlying)));

super.setUp();
}
}
6 changes: 6 additions & 0 deletions tests/tests/protocols/aave/AaveV3Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ address constant ARBITRUM_POOL_ADDRESS = 0x794a61358D6845594F94dc1DB02A252b5b481
address constant ARBITRUM_POOL_ADDRESS_PROVIDER = 0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb;
address constant ARBITRUM_PROTOCOL_DATA_PROVIDER = 0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654;
address constant ARBITRUM_REWARDS_CONTROLLER = 0x0C501fB73808e1BD73cBDdd0c99237bbc481Bb58;

// Base
address constant BASE_POOL_ADDRESS = 0xA238Dd80C259a72e81d7e4664a9801593F98d1c5;
address constant BASE_POOL_ADDRESS_PROVIDER = 0xe20fCBdBfFC4Dd138cE8b2E6FBb6CB49777ad64D;
address constant BASE_PROTOCOL_DATA_PROVIDER = 0xd82a47fdebB5bf5329b09441C3DaB4b5df2153Ad;
address constant BASE_REWARDS_CONTROLLER = 0xf9cc4F0D883F1a1eb2c253bdb46c254Ca51E1F44;
Loading

0 comments on commit fa6e659

Please sign in to comment.