Skip to content
Open
2 changes: 1 addition & 1 deletion .github/workflows/tests-pr.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to keep this nightly until foundry merges in the nightly random fix into stable ?

Copy link
Member Author

@DhairyaSethi DhairyaSethi Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tested and gas numbers are the same w nightly and stable

for now, we can:

  • nightly w seed
  • stable w/o seed

i am inclined towards the former (need to add back seed here after we reach consensus)

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Run Foundry setup
uses: bgd-labs/github-workflows/.github/actions/foundry-setup@main
with:
FOUNDRY_VERSION: stable
FOUNDRY_VERSION: nightly

- name: Run Forge size
uses: bgd-labs/github-workflows/.github/actions/foundry-size@main
Expand Down
4 changes: 2 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ optimizer_runs = 200
bytecode_hash = "none"
gas_snapshot_check = false
gas_limit = 1099511627776
dynamic_test_linking = true

[bind_json]
out = "tests/mocks/JsonBindings.sol"
Expand All @@ -22,10 +23,9 @@ lint_on_build = false

[profile.default.fuzz]
runs = 1000
seed = "0x640"

[profile.pr.fuzz]
runs = 5000
runs = 10000

[profile.ci.fuzz]
runs = 10000
Expand Down
16 changes: 8 additions & 8 deletions snapshots/SignatureGateway.Operations.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"borrowWithSig": "215893",
"repayWithSig": "189160",
"setSelfAsUserPositionManagerWithSig": "74858",
"setUsingAsCollateralWithSig": "85053",
"supplyWithSig": "153205",
"updateUserDynamicConfigWithSig": "62769",
"updateUserRiskPremiumWithSig": "61579",
"withdrawWithSig": "131713"
"borrowWithSig": "215857",
"repayWithSig": "189124",
"setSelfAsUserPositionManagerWithSig": "74822",
"setUsingAsCollateralWithSig": "85029",
"supplyWithSig": "153167",
"updateUserDynamicConfigWithSig": "62733",
"updateUserRiskPremiumWithSig": "61543",
"withdrawWithSig": "131684"
}
4 changes: 2 additions & 2 deletions snapshots/Spoke.Operations.ZeroRiskPremium.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"permitReserve + supply + enable collateral (multicall)": "160573",
"repay: full": "126382",
"repay: partial": "131271",
"setUserPositionManagerWithSig: disable": "44846",
"setUserPositionManagerWithSig: enable": "68875",
"setUserPositionManagerWithSig: disable": "44534",
"setUserPositionManagerWithSig: enable": "68563",
"supply + enable collateral (multicall)": "140624",
"supply: 0 borrows, collateral disabled": "123679",
"supply: 0 borrows, collateral enabled": "106601",
Expand Down
4 changes: 2 additions & 2 deletions snapshots/Spoke.Operations.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"permitReserve + supply + enable collateral (multicall)": "160573",
"repay: full": "120544",
"repay: partial": "139833",
"setUserPositionManagerWithSig: disable": "44846",
"setUserPositionManagerWithSig: enable": "68875",
"setUserPositionManagerWithSig: disable": "44534",
"setUserPositionManagerWithSig: enable": "68563",
"supply + enable collateral (multicall)": "140624",
"supply: 0 borrows, collateral disabled": "123679",
"supply: 0 borrows, collateral enabled": "106601",
Expand Down
2 changes: 1 addition & 1 deletion tests/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ abstract contract Base is Test {
);

uint256 restoredPremiumRay = (premiumAmountToRestore * WadRayMath.RAY).min(premiumDebtRay);
uint256 restoredShares = drawnDebtToRestore.rayDivDown(hub.getAssetDrawnIndex(reserveId));
uint256 restoredShares = drawnDebtToRestore.rayDivDown(hub.getAssetDrawnIndex(assetId));
uint256 riskPremium = _getUserLastRiskPremium(spoke, user);

return
Expand Down
16 changes: 8 additions & 8 deletions tests/gas/Gateways.Operations.gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract SignatureGateway_Gas_Tests is SignatureGatewayBaseTest {
amount: 100e18,
onBehalfOf: alice,
nonce: gateway.nonces(alice, nonceKey),
deadline: _warpBeforeRandomDeadline()
deadline: vm.getBlockTimestamp() + 1
});
bytes memory signature = _sign(alicePk, _getTypedDataHash(gateway, p));
Utils.approve(spoke1, p.reserveId, alice, address(gateway), p.amount);
Expand All @@ -138,7 +138,7 @@ contract SignatureGateway_Gas_Tests is SignatureGatewayBaseTest {
amount: 100e18,
onBehalfOf: alice,
nonce: gateway.nonces(alice, nonceKey),
deadline: _warpBeforeRandomDeadline()
deadline: vm.getBlockTimestamp() + 1
});
bytes memory signature = _sign(alicePk, _getTypedDataHash(gateway, p));

Expand All @@ -156,7 +156,7 @@ contract SignatureGateway_Gas_Tests is SignatureGatewayBaseTest {
amount: 100e18,
onBehalfOf: alice,
nonce: gateway.nonces(alice, nonceKey),
deadline: _warpBeforeRandomDeadline()
deadline: vm.getBlockTimestamp() + 1
});
Utils.supplyCollateral(spoke1, p.reserveId, alice, p.amount * 4, alice);
Utils.borrow(spoke1, p.reserveId, alice, p.amount, alice);
Expand All @@ -173,7 +173,7 @@ contract SignatureGateway_Gas_Tests is SignatureGatewayBaseTest {
amount: 100e18,
onBehalfOf: alice,
nonce: gateway.nonces(alice, nonceKey),
deadline: _warpBeforeRandomDeadline()
deadline: vm.getBlockTimestamp() + 1
});
Utils.supplyCollateral(spoke1, p.reserveId, alice, p.amount * 10, alice);
Utils.borrow(spoke1, p.reserveId, alice, p.amount * 3, alice);
Expand All @@ -192,7 +192,7 @@ contract SignatureGateway_Gas_Tests is SignatureGatewayBaseTest {
useAsCollateral: true,
onBehalfOf: alice,
nonce: gateway.nonces(alice, nonceKey),
deadline: _warpBeforeRandomDeadline()
deadline: vm.getBlockTimestamp() + 1
});
Utils.supply(spoke1, p.reserveId, alice, 1e18, alice);
bytes memory signature = _sign(alicePk, _getTypedDataHash(gateway, p));
Expand All @@ -206,7 +206,7 @@ contract SignatureGateway_Gas_Tests is SignatureGatewayBaseTest {
spoke: address(spoke1),
user: alice,
nonce: gateway.nonces(alice, nonceKey),
deadline: _warpBeforeRandomDeadline()
deadline: vm.getBlockTimestamp() + 1
});
bytes memory signature = _sign(alicePk, _getTypedDataHash(gateway, p));

Expand All @@ -222,7 +222,7 @@ contract SignatureGateway_Gas_Tests is SignatureGatewayBaseTest {
spoke: address(spoke1),
user: alice,
nonce: gateway.nonces(alice, nonceKey),
deadline: _warpBeforeRandomDeadline()
deadline: vm.getBlockTimestamp() + 1
});
bytes memory signature = _sign(alicePk, _getTypedDataHash(gateway, p));

Expand All @@ -241,7 +241,7 @@ contract SignatureGateway_Gas_Tests is SignatureGatewayBaseTest {
user: alice,
approve: true,
nonce: spoke1.nonces(alice, nonceKey), // note: this typed sig is forwarded to spoke
deadline: _warpBeforeRandomDeadline()
deadline: vm.getBlockTimestamp() + 1
});
bytes memory signature = _sign(alicePk, _getTypedDataHash(spoke1, p));

Expand Down
8 changes: 4 additions & 4 deletions tests/gas/Spoke.Operations.gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ contract SpokeOperations_Gas_Tests is SpokeBase {
}

function test_setUserPositionManagerWithSig() public {
(address user, uint256 userPk) = makeAddrAndKey(string(vm.randomBytes(32)));
(address user, uint256 userPk) = makeAddrAndKey('user');
vm.label(user, 'user');
address positionManager = vm.randomAddress();
address positionManager = makeAddr('positionManager');
vm.prank(SPOKE_ADMIN);
spoke.updatePositionManager(positionManager, true);

uint192 nonceKey = _randomNonceKey();
uint192 nonceKey = 100;
vm.prank(user);
spoke.useNonce(nonceKey);

Expand All @@ -304,7 +304,7 @@ contract SpokeOperations_Gas_Tests is SpokeBase {
user: user,
approve: true,
nonce: spoke.nonces(user, nonceKey),
deadline: vm.randomUint(vm.getBlockTimestamp(), MAX_SKIP_TIME)
deadline: vm.getBlockTimestamp() + 1
});
(uint8 v, bytes32 r, bytes32 s) = vm.sign(userPk, _getTypedDataHash(spoke, params));
bytes memory signature = abi.encodePacked(r, s, v);
Expand Down
17 changes: 1 addition & 16 deletions tests/unit/Hub/Hub.Config.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract HubConfigTest is HubBase {
}

function test_hub_deploy_revertsWith_InvalidAddress() public {
vm.expectRevert(IHub.InvalidAddress.selector, address(hub1));
vm.expectRevert(IHub.InvalidAddress.selector);
new Hub(address(0));
}

Expand Down Expand Up @@ -685,21 +685,6 @@ contract HubConfigTest is HubBase {
assertEq(hub1.getSpokeAddedShares(assetId, newFeeReceiver), newFees);
}

/// Updates the fee receiver to an existing spoke of the hub1, so ends up with existing supplied shares plus accrued fees
function test_updateAssetConfig_fuzz_UseExistingSpokeAsFeeReceiver_revertsWith_SpokeAlreadyListed(
uint256 assetId
) public {
assetId = vm.randomUint(0, hub1.getAssetCount() - 1);
address newFeeReceiver = address(spoke1);

IHub.AssetConfig memory config = hub1.getAssetConfig(assetId);
config.feeReceiver = newFeeReceiver;

vm.expectRevert(IHub.SpokeAlreadyListed.selector, address(hub1));
vm.prank(HUB_ADMIN);
hub1.updateAssetConfig(assetId, config, new bytes(0));
}

/// Updates the fee receiver to an existing spoke of the hub1 which is already listed on the asset
function test_updateAssetConfig_UseExistingSpokeAndListedAsFeeReceiver_revertsWith_SpokeAlreadyListed()
public
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/Hub/Hub.RefreshPremium.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ contract HubRefreshPremiumTest is HubBase {
restoredPremiumRay: 0
});

if (borrowAmount > 0) {
// set max risk premium threshold to allow borrow to occur
_updateSpokeRiskPremiumThreshold(
hub1,
daiAssetId,
address(spoke1),
Constants.MAX_RISK_PREMIUM_THRESHOLD
);
Utils.supplyCollateral(spoke1, _daiReserveId(spoke1), bob, borrowAmount * 2, bob);
Utils.borrow(spoke1, _daiReserveId(spoke1), bob, borrowAmount, bob);
}

uint24 riskPremiumThreshold = vm
.randomUint(0, Constants.MAX_RISK_PREMIUM_THRESHOLD - 1)
.toUint24();
Expand All @@ -236,11 +248,6 @@ contract HubRefreshPremiumTest is HubBase {
}
_updateSpokeRiskPremiumThreshold(hub1, daiAssetId, address(spoke1), riskPremiumThreshold);

if (borrowAmount > 0) {
Utils.supplyCollateral(spoke1, _daiReserveId(spoke1), bob, borrowAmount * 2, bob);
Utils.borrow(spoke1, _daiReserveId(spoke1), bob, borrowAmount, bob);
}

PremiumDataLocal memory premiumDataBefore = _loadAssetPremiumData(hub1, daiAssetId);
(, uint256 premiumBefore) = hub1.getAssetOwed(daiAssetId);
bool reverting;
Expand Down Expand Up @@ -381,7 +388,6 @@ contract HubRefreshPremiumTest is HubBase {
Utils.supplyCollateral(spoke1, _daiReserveId(spoke1), bob, MAX_SUPPLY_AMOUNT, bob);
Utils.borrow(spoke1, _daiReserveId(spoke1), bob, borrowAmount, bob);
skip(skipTime);
Utils.borrow(spoke1, _daiReserveId(spoke1), bob, 1e18, bob);

IHub.Asset memory asset = hub1.getAsset(assetId);
PremiumDataLocal memory premiumDataBefore = _loadAssetPremiumData(hub1, assetId);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Hub/Hub.ReportDeficit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ contract HubReportDeficitTest is HubBase {
);

uint256 drawnDeficit = vm.randomUint(0, drawn);
uint256 premiumDeficitRay = vm.randomUint(spokePremiumRay + 1, UINT256_MAX);
uint256 premiumDeficitRay = vm.randomUint(spokePremiumRay + 1, 2 ** 255 - 1);

vm.expectRevert(
abi.encodeWithSelector(IHub.SurplusPremiumRayDeficitReported.selector, spokePremiumRay)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Hub/Hub.Sweep.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract HubSweepTest is HubBase {
abi.encodeWithSelector(IHub.InsufficientLiquidity.selector, initialLiquidity - swept)
);
vm.prank(address(spoke1));
hub1.remove(daiAssetId, swept + 1, alice);
hub1.remove(daiAssetId, initialLiquidity - swept + 1, alice);
}

function test_sweep_does_not_impact_utilization(uint256 supplyAmount, uint256 drawAmount) public {
Expand Down
28 changes: 21 additions & 7 deletions tests/unit/HubConfigurator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ contract HubConfiguratorTest is HubBase {
function setUp() public virtual override {
super.setUp();
hubConfigurator = new HubConfigurator(HUB_CONFIGURATOR_ADMIN);
IAccessManager accessManager = IAccessManager(hub1.authority());
// Grant hubConfigurator hub admin role with 0 delay
vm.prank(ADMIN);
accessManager.grantRole(Roles.HUB_ADMIN_ROLE, address(hubConfigurator), 0);
vm.startPrank(ADMIN);
IAccessManager(hub1.authority()).grantRole(Roles.HUB_ADMIN_ROLE, address(hubConfigurator), 0);
vm.stopPrank();
_assetId = daiAssetId;
_encodedIrData = abi.encode(
IAssetInterestRateStrategy.InterestRateData({
Expand Down Expand Up @@ -104,7 +104,12 @@ contract HubConfiguratorTest is HubBase {
}

function test_addAsset_revertsWith_InvalidAddress_underlying() public {
uint8 decimals = uint8(vm.randomUint(0, Constants.MAX_ALLOWED_UNDERLYING_DECIMALS));
uint8 decimals = uint8(
vm.randomUint(
Constants.MIN_ALLOWED_UNDERLYING_DECIMALS,
Constants.MAX_ALLOWED_UNDERLYING_DECIMALS
)
);
address feeReceiver = makeAddr('newFeeReceiver');
address interestRateStrategy = makeAddr('newIrStrategy');
uint256 liquidityFee = vm.randomUint(0, PercentageMath.PERCENTAGE_FACTOR);
Expand All @@ -124,7 +129,12 @@ contract HubConfiguratorTest is HubBase {

function test_addAsset_revertsWith_InvalidAddress_irStrategy() public {
address underlying = makeAddr('newUnderlying');
uint8 decimals = uint8(vm.randomUint(0, Constants.MAX_ALLOWED_UNDERLYING_DECIMALS));
uint8 decimals = uint8(
vm.randomUint(
Constants.MIN_ALLOWED_UNDERLYING_DECIMALS,
Constants.MAX_ALLOWED_UNDERLYING_DECIMALS
)
);
address feeReceiver = makeAddr('newFeeReceiver');
uint256 liquidityFee = vm.randomUint(0, PercentageMath.PERCENTAGE_FACTOR);

Expand All @@ -135,7 +145,12 @@ contract HubConfiguratorTest is HubBase {

function test_addAsset_revertsWith_InvalidLiquidityFee() public {
address underlying = makeAddr('newUnderlying');
uint8 decimals = uint8(vm.randomUint(0, Constants.MAX_ALLOWED_UNDERLYING_DECIMALS));
uint8 decimals = uint8(
vm.randomUint(
Constants.MIN_ALLOWED_UNDERLYING_DECIMALS,
Constants.MAX_ALLOWED_UNDERLYING_DECIMALS
)
);
address feeReceiver = makeAddr('newFeeReceiver');
address interestRateStrategy = address(new AssetInterestRateStrategy(address(hub1)));
uint256 liquidityFee = vm.randomUint(PercentageMath.PERCENTAGE_FACTOR + 1, type(uint16).max);
Expand Down Expand Up @@ -319,7 +334,6 @@ contract HubConfiguratorTest is HubBase {
}

function test_updateFeeReceiver_revertsWith_SpokeAlreadyListed() public {
_assetId = vm.randomUint(0, hub1.getAssetCount() - 1);
assertTrue(hub1.isSpokeListed(_assetId, address(spoke1)));

// set feeReceiver as an existing spoke
Expand Down
Loading
Loading