From 47c381bf0d6099c479a758033b1a79c18f273c9a Mon Sep 17 00:00:00 2001 From: 8ball030 <8baller@station.codes> Date: Sun, 13 Jul 2025 06:21:19 +0100 Subject: [PATCH 1/2] feat:test-eth-donated-to-vault --- src/DerolasAuction.sol | 22 +++++++++++++++++----- src/interfaces/IBalancerVaultAdmin.sol | 3 +++ test/DerolasAuction.t.sol | 13 +++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/DerolasAuction.sol b/src/DerolasAuction.sol index 1c16944..a8a3f91 100644 --- a/src/DerolasAuction.sol +++ b/src/DerolasAuction.sol @@ -136,13 +136,13 @@ contract DerolasAuction { owner = msg.sender; } - /// @dev Donates unclaimed rewards. + /// @dev Donates unclaimed rewards from the round prior to the claim round. /// @param claimRound Claim round. function _donateUnclaimedIncentiveTokens(uint256 claimRound) internal { - uint256 unclaimedAmount = roundPoints[claimRound].availableRewards - roundPoints[claimRound].totalClaimed; - if (unclaimedAmount < MINIMUM_BALANCE_DONATION_AMOUNT) { - return; - } + if (!_shouldDonateUnclaimedIncentives(claimRound)) return; + + uint256 unclaimedAmount = + roundPoints[claimRound - 1].availableRewards - roundPoints[claimRound - 1].totalClaimed; uint256[] memory amountsIn = new uint256[](assetsInPool); amountsIn[incentiveTokenIndex] = unclaimedAmount; @@ -158,6 +158,18 @@ contract DerolasAuction { emit UnclaimedIncentiveTokensDonated(unclaimedAmount); } + /// @dev Checks if unclaimed incentives should be donated. + /// @param claimRound Claim round. + /// @return True if unclaimed incentives should be donated, false otherwise. + function _shouldDonateUnclaimedIncentives(uint256 claimRound) internal view returns (bool) { + if (claimRound == 0) return false; // No previous round to sweep + uint256 sweepRound = claimRound - 1; + if (roundPoints[sweepRound].totalDonated == 0) return false; // No donations in the previous round + uint256 unclaimedAmount = roundPoints[sweepRound].availableRewards - roundPoints[sweepRound].totalClaimed; + if (unclaimedAmount < MINIMUM_BALANCE_DONATION_AMOUNT) return false; // Unclaimed amount is too small + return true; // Unclaimed incentives should be donated + } + /// @dev Donates collected contributions. function _donateEthContribution() internal { // we check the whole balance of the contract and donate it to the balancer pool diff --git a/src/interfaces/IBalancerVaultAdmin.sol b/src/interfaces/IBalancerVaultAdmin.sol index 8ba1cb7..4c36109 100644 --- a/src/interfaces/IBalancerVaultAdmin.sol +++ b/src/interfaces/IBalancerVaultAdmin.sol @@ -8,4 +8,7 @@ interface IBalancerVaultAdmin { /// @return minimumTradeAmount The minimum trade amount. /// This is used to ensure that trades do not occur below a certain threshold. function getMinimumTradeAmount() external view returns (uint256); + /// @dev Gets the balancer vault address. + /// @return balancerVault The address of the Balancer vault. + function vault() external view returns (address balancerVault); } diff --git a/test/DerolasAuction.t.sol b/test/DerolasAuction.t.sol index 5f8f4fd..687e2dd 100644 --- a/test/DerolasAuction.t.sol +++ b/test/DerolasAuction.t.sol @@ -24,6 +24,7 @@ contract TestDerolasAuctionContract is Test { // Test parameters address public whaleAddress = 0xC8F7030a4e25585624e2Fc792255a547255Cd77c; uint256 public topUpAmount = 2e18; // 2 Incentive Token + address public wethAddress = 0x4200000000000000000000000000000000000006; // WETH address on Base function setUp() public { c = new DerolasAuction( @@ -264,6 +265,18 @@ contract TestDerolasAuctionContract is Test { assertTrue(c.isRatioPass(updatedNonce, initialNonce, 0), "isRatioPass should return true after increment"); } + // Balancer donation tests. + function testBalancerEthDonation() public { + // Check that a donation can be made using Balancer's ETH donation method + this.testTopupIncentivesBalance(); // Ensure incentives are topped up + this.testDonateWithIncentives(); // Ensure a donation has been made + IBalancerVaultAdmin balancerVaultAdminContract = IBalancerVaultAdmin(balancerVaultAdmin); + uint256 initialBalance = IToken(wethAddress).balanceOf(balancerVaultAdminContract.vault()); + this.testCanEndRound(); // Ensure the round can be ended + uint256 finalBalance = IToken(wethAddress).balanceOf(balancerVaultAdminContract.vault()); + assertGt(finalBalance, initialBalance, "Final balance should be greater than initial balance after donation"); + } + // admin tests function testCanChangeOwner() public { // Check that the owner can change the contract owner From f04d8ca5326e2270d9645c02c6dc80ee33c8269a Mon Sep 17 00:00:00 2001 From: 8ball030 <8baller@station.codes> Date: Sun, 13 Jul 2025 07:48:12 +0100 Subject: [PATCH 2/2] feat:more-tests --- src/DerolasAuction.sol | 22 +++++----------------- test/DerolasAuction.t.sol | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/DerolasAuction.sol b/src/DerolasAuction.sol index a8a3f91..1c16944 100644 --- a/src/DerolasAuction.sol +++ b/src/DerolasAuction.sol @@ -136,13 +136,13 @@ contract DerolasAuction { owner = msg.sender; } - /// @dev Donates unclaimed rewards from the round prior to the claim round. + /// @dev Donates unclaimed rewards. /// @param claimRound Claim round. function _donateUnclaimedIncentiveTokens(uint256 claimRound) internal { - if (!_shouldDonateUnclaimedIncentives(claimRound)) return; - - uint256 unclaimedAmount = - roundPoints[claimRound - 1].availableRewards - roundPoints[claimRound - 1].totalClaimed; + uint256 unclaimedAmount = roundPoints[claimRound].availableRewards - roundPoints[claimRound].totalClaimed; + if (unclaimedAmount < MINIMUM_BALANCE_DONATION_AMOUNT) { + return; + } uint256[] memory amountsIn = new uint256[](assetsInPool); amountsIn[incentiveTokenIndex] = unclaimedAmount; @@ -158,18 +158,6 @@ contract DerolasAuction { emit UnclaimedIncentiveTokensDonated(unclaimedAmount); } - /// @dev Checks if unclaimed incentives should be donated. - /// @param claimRound Claim round. - /// @return True if unclaimed incentives should be donated, false otherwise. - function _shouldDonateUnclaimedIncentives(uint256 claimRound) internal view returns (bool) { - if (claimRound == 0) return false; // No previous round to sweep - uint256 sweepRound = claimRound - 1; - if (roundPoints[sweepRound].totalDonated == 0) return false; // No donations in the previous round - uint256 unclaimedAmount = roundPoints[sweepRound].availableRewards - roundPoints[sweepRound].totalClaimed; - if (unclaimedAmount < MINIMUM_BALANCE_DONATION_AMOUNT) return false; // Unclaimed amount is too small - return true; // Unclaimed incentives should be donated - } - /// @dev Donates collected contributions. function _donateEthContribution() internal { // we check the whole balance of the contract and donate it to the balancer pool diff --git a/test/DerolasAuction.t.sol b/test/DerolasAuction.t.sol index 687e2dd..7edb7cf 100644 --- a/test/DerolasAuction.t.sol +++ b/test/DerolasAuction.t.sol @@ -274,7 +274,25 @@ contract TestDerolasAuctionContract is Test { uint256 initialBalance = IToken(wethAddress).balanceOf(balancerVaultAdminContract.vault()); this.testCanEndRound(); // Ensure the round can be ended uint256 finalBalance = IToken(wethAddress).balanceOf(balancerVaultAdminContract.vault()); - assertGt(finalBalance, initialBalance, "Final balance should be greater than initial balance after donation"); + assertEq( + finalBalance, + initialBalance + minimumDonation, + "Final balance should be greater than initial balance after donation" + ); + } + + function testBalancerUnclaimedIncentiveDonation() public { + // Check that a donation can be made using Balancer's ETH donation method + IBalancerVaultAdmin balancerVaultAdminContract = IBalancerVaultAdmin(balancerVaultAdmin); + uint256 initialBalance = IToken(incentiveTokenAddress).balanceOf(balancerVaultAdminContract.vault()); + this.testTopupIncentivesBalance(); // Ensure incentives are topped up + this.testDonateWithIncentives(); // Ensure a donation has been made + this.testCanEndRound(); // Ensure the round can be ended + uint256 secondBalance = IToken(incentiveTokenAddress).balanceOf(balancerVaultAdminContract.vault()); + assertEq(secondBalance, initialBalance, "Vault balance equal to initial balance after 1st round"); + this.testCanEndRound(); // Ensure the round can be ended again + uint256 finalBalance = IToken(incentiveTokenAddress).balanceOf(balancerVaultAdminContract.vault()); + assertEq(finalBalance, initialBalance + availableRewards, "Final balance should include unclaimed"); } // admin tests