From 785d5586faa0e8f4779344d3a9287083bf2d93ca Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Tue, 12 Nov 2024 23:11:14 -0700 Subject: [PATCH] chore: deploy auction --- script/DeployAuction.s.sol | 2 +- src/Auctions/Auction.sol | 2 +- src/Bases/Auctioneer/IBaseAuctioneer.sol | 6 +- src/swappers/AuctionSwapper.sol | 2 +- src/test/AuctionSwapper.t.sol | 81 ++++++++---------------- src/test/BaseAuctioneer.t.sol | 42 ++++-------- src/test/mocks/MockAuctionSwapper.sol | 13 ++-- 7 files changed, 54 insertions(+), 94 deletions(-) diff --git a/script/DeployAuction.s.sol b/script/DeployAuction.s.sol index 2de4f52..fbb31d8 100644 --- a/script/DeployAuction.s.sol +++ b/script/DeployAuction.s.sol @@ -10,7 +10,7 @@ contract DeployAuction is BaseScript { vm.startBroadcast(); // Get the bytecode - bytes memory bytecode = vm.getCode("DumperAuctionFactory.sol:DumperAuctionFactory"); + bytes memory bytecode = vm.getCode("AuctionFactory.sol:AuctionFactory"); bytes32 salt; diff --git a/src/Auctions/Auction.sol b/src/Auctions/Auction.sol index 23a6e35..416bcbf 100644 --- a/src/Auctions/Auction.sol +++ b/src/Auctions/Auction.sol @@ -29,7 +29,7 @@ contract Auction is Governance2Step, ReentrancyGuard { event AuctionDisabled(address indexed from, address indexed to); /// @notice Emitted when auction has been kicked. - event AuctionKicked(address from, uint256 available); + event AuctionKicked(address indexed from, uint256 available); /// @notice Emitted when the starting price is updated. event UpdatedStartingPrice(uint256 startingPrice); diff --git a/src/Bases/Auctioneer/IBaseAuctioneer.sol b/src/Bases/Auctioneer/IBaseAuctioneer.sol index 53d3564..a706f90 100644 --- a/src/Bases/Auctioneer/IBaseAuctioneer.sol +++ b/src/Bases/Auctioneer/IBaseAuctioneer.sol @@ -45,11 +45,11 @@ interface IBaseAuctioneer is IBaseHealthCheck { uint256 _timestamp ) external view returns (uint256); - function enableAuction(address _from) external; + function enable(address _from) external; - function disableAuction(address _from) external; + function disable(address _from) external; - function disableAuction(address _from, uint256 _index) external; + function disable(address _from, uint256 _index) external; function kick(address _from) external returns (uint256 available); diff --git a/src/swappers/AuctionSwapper.sol b/src/swappers/AuctionSwapper.sol index bd372d5..62e8b74 100644 --- a/src/swappers/AuctionSwapper.sol +++ b/src/swappers/AuctionSwapper.sol @@ -43,7 +43,7 @@ contract AuctionSwapper { /// @notice The pre-deployed Auction factory for cloning. address public constant auctionFactory = - 0xE6aB098E8582178A76DC80d55ca304d1Dec11AD8; + 0xa076c247AfA44f8F006CA7f21A4EF59f7e4dc605; /// @notice Address of the specific Auction this strategy uses. address public auction; diff --git a/src/test/AuctionSwapper.t.sol b/src/test/AuctionSwapper.t.sol index a6a4ce5..fb1242a 100644 --- a/src/test/AuctionSwapper.t.sol +++ b/src/test/AuctionSwapper.t.sol @@ -10,9 +10,6 @@ import {Auction, AuctionFactory} from "../Auctions/AuctionFactory.sol"; contract AuctionSwapperTest is Setup { using SafeERC20 for ERC20; - event PreTake(address token, uint256 amountToTake, uint256 amountToPay); - event PostTake(address token, uint256 amountTaken, uint256 amountPayed); - event DeployedNewAuction(address indexed auction, address indexed want); event AuctionEnabled(address indexed from, address indexed to); @@ -21,17 +18,11 @@ contract AuctionSwapperTest is Setup { event AuctionKicked(address indexed token, uint256 available); - event AuctionTaken( - address indexed token, - uint256 amountTaken, - uint256 amountLeft - ); - IMockAuctionSwapper public swapper; Auction public auction; AuctionFactory public auctionFactory = - AuctionFactory(0x4A14145C4977E18c719BB70E6FcBF8fBFF6F62d2); + AuctionFactory(0xa076c247AfA44f8F006CA7f21A4EF59f7e4dc605); uint256 public wantScaler; uint256 public fromScaler; @@ -55,6 +46,7 @@ contract AuctionSwapperTest is Setup { auction = Auction(swapper.auction()); assertNeq(address(auction), address(0)); + assertEq(swapper.kickable(from), 0); assertEq(auction.kickable(from), 0); assertEq(auction.getAmountNeeded(from, 1e18), 0); assertEq(auction.price(from), 0); @@ -68,8 +60,8 @@ contract AuctionSwapperTest is Setup { assertEq(auction.available(from), 0); // Kicking it reverts - vm.expectRevert("nothing to kick"); - auction.kick(from); + vm.expectRevert(); + swapper.kickAuction(from); // Can't re-enable vm.expectRevert("already enabled"); @@ -85,6 +77,7 @@ contract AuctionSwapperTest is Setup { auction = Auction(swapper.auction()); assertNeq(address(auction), address(0)); + assertEq(swapper.kickable(from), 0); assertEq(auction.kickable(from), 0); assertEq(auction.getAmountNeeded(from, 1e18), 0); assertEq(auction.price(from), 0); @@ -107,13 +100,14 @@ contract AuctionSwapperTest is Setup { swapper.enableAuction(secondFrom, address(asset)); assertEq(swapper.auction(), address(auction)); + assertEq(swapper.kickable(secondFrom), 0); assertEq(auction.kickable(secondFrom), 0); assertEq(auction.getAmountNeeded(secondFrom, 1e18), 0); assertEq(auction.price(secondFrom), 0); (_kicked, _scaler, _initialAvailable) = auction.auctions(secondFrom); assertEq(_kicked, 0); - assertEq(_scaler, 1e12); + assertEq(_scaler, 1); assertEq(_initialAvailable, 0); assertEq(auction.available(secondFrom), 0); } @@ -126,6 +120,7 @@ contract AuctionSwapperTest is Setup { auction = Auction(swapper.auction()); assertNeq(address(auction), address(0)); + assertEq(swapper.kickable(from), 0); assertEq(auction.kickable(from), 0); assertEq(auction.getAmountNeeded(from, 1e18), 0); assertEq(auction.price(from), 0); @@ -161,6 +156,7 @@ contract AuctionSwapperTest is Setup { auction = Auction(swapper.auction()); + assertEq(swapper.kickable(from), 0); assertEq(auction.kickable(from), 0); (uint64 _kicked, uint64 _scaler, uint128 _initialAvailable) = auction .auctions(from); @@ -171,20 +167,20 @@ contract AuctionSwapperTest is Setup { airdrop(ERC20(from), address(swapper), _amount); - assertEq(auction.kickable(from), _amount); - (, _kicked, _initialAvailable) = auction.auctions(from); + assertEq(swapper.kickable(from), _amount); + assertEq(auction.kickable(from), 0); + (_kicked, , _initialAvailable) = auction.auctions(from); assertEq(_kicked, 0); assertEq(_initialAvailable, 0); - vm.expectEmit(true, true, true, true, address(auction)); - emit AuctionKicked(from, _amount); - uint256 available = auction.kick(from); + uint256 available = swapper.kickAuction(from); assertEq(ERC20(from).balanceOf(address(swapper)), 0); assertEq(ERC20(from).balanceOf(address(auction)), _amount); + assertEq(swapper.kickable(from), 0); assertEq(auction.kickable(from), 0); - (, _kicked, _initialAvailable) = auction.auctions(from); + (_kicked, , _initialAvailable) = auction.auctions(from); assertEq(_kicked, block.timestamp); assertEq(_initialAvailable, _amount); uint256 startingPrice = ((auction.startingPrice() * @@ -224,12 +220,6 @@ contract AuctionSwapperTest is Setup { assertEq(auction.price(from), 0); assertEq(auction.getAmountNeeded(from, _amount), 0); - - // Can't kick a new one yet - vm.expectRevert("too soon"); - auction.kick(from); - - assertEq(auction.kickable(from), 0); } function test_takeAuction_default(uint256 _amount, uint16 _percent) public { @@ -247,9 +237,9 @@ contract AuctionSwapperTest is Setup { airdrop(ERC20(from), address(swapper), _amount); - auction.kick(from); + swapper.kickAuction(from); - assertEq(auction.kickable(from), 0); + assertEq(swapper.kickable(from), 0); (uint64 _kicked, uint64 _scaler, uint128 _initialAvailable) = auction .auctions(from); assertEq(_kicked, block.timestamp); @@ -271,13 +261,11 @@ contract AuctionSwapperTest is Setup { uint256 before = ERC20(from).balanceOf(address(this)); - vm.expectEmit(true, true, true, true, address(auction)); - emit AuctionTaken(from, toTake, left); uint256 amountTaken = auction.take(from, toTake); assertEq(amountTaken, toTake); - (, _kicked, _initialAvailable) = auction.auctions(from); + (_kicked, , _initialAvailable) = auction.auctions(from); assertEq(_initialAvailable, _amount); assertEq(auction.available(from), left); assertEq(ERC20(asset).balanceOf(address(this)), beforeAsset); @@ -300,7 +288,7 @@ contract AuctionSwapperTest is Setup { auction = Auction(swapper.auction()); - assertEq(auction.kickable(from), 0); + assertEq(swapper.kickable(from), 0); (uint64 _kicked, uint64 _scaler, uint128 _initialAvailable) = auction .auctions(from); @@ -312,25 +300,23 @@ contract AuctionSwapperTest is Setup { swapper.setUseDefault(false); - assertEq(auction.kickable(from), 0); + assertEq(swapper.kickable(from), 0); uint256 kickable = _amount / 10; swapper.setLetKick(kickable); - assertEq(auction.kickable(from), kickable); - (, _kicked, _initialAvailable) = auction.auctions(from); + assertEq(swapper.kickable(from), kickable); + (_kicked, , _initialAvailable) = auction.auctions(from); assertEq(_kicked, 0); assertEq(_initialAvailable, 0); - vm.expectEmit(true, true, true, true, address(auction)); - emit AuctionKicked(from, kickable); - uint256 available = auction.kick(from); + uint256 available = swapper.kickAuction(from); assertEq(ERC20(from).balanceOf(address(swapper)), _amount - kickable); assertEq(ERC20(from).balanceOf(address(auction)), kickable); - assertEq(auction.kickable(from), 0); - (, _kicked, _initialAvailable) = auction.auctions(from); + assertEq(swapper.kickable(from), 0); + (_kicked, , _initialAvailable) = auction.auctions(from); assertEq(_kicked, block.timestamp); assertEq(_initialAvailable, kickable); uint256 startingPrice = ((auction.startingPrice() * @@ -370,12 +356,6 @@ contract AuctionSwapperTest is Setup { assertEq(auction.price(from), 0); assertEq(auction.getAmountNeeded(from, kickable), 0); - - // Can't kick a new one yet - vm.expectRevert("too soon"); - auction.kick(from); - - assertEq(auction.kickable(from), 0); } function test_takeAuction_custom(uint256 _amount, uint16 _percent) public { @@ -395,14 +375,13 @@ contract AuctionSwapperTest is Setup { swapper.setUseDefault(false); - assertEq(auction.kickable(from), 0); + assertEq(swapper.kickable(from), 0); uint256 kickable = _amount / 10; swapper.setLetKick(kickable); - auction.kick(from); + swapper.kickAuction(from); - assertEq(auction.kickable(from), 0); (uint64 _kicked, uint64 _scaler, uint128 _initialAvailable) = auction .auctions(from); @@ -425,15 +404,11 @@ contract AuctionSwapperTest is Setup { uint256 before = ERC20(from).balanceOf(address(this)); - vm.expectEmit(true, true, true, true, address(swapper)); - emit PreTake(from, toTake, needed); - vm.expectEmit(true, true, true, true, address(swapper)); - emit PostTake(address(asset), toTake, needed); uint256 amountTaken = auction.take(from, toTake); assertEq(amountTaken, toTake); - (, _kicked, _initialAvailable) = auction.auctions(from); + (_kicked, , _initialAvailable) = auction.auctions(from); assertEq(_initialAvailable, _amount); assertEq(auction.available(from), left); assertEq(ERC20(asset).balanceOf(address(this)), beforeAsset); diff --git a/src/test/BaseAuctioneer.t.sol b/src/test/BaseAuctioneer.t.sol index 321d61a..8e0fafe 100644 --- a/src/test/BaseAuctioneer.t.sol +++ b/src/test/BaseAuctioneer.t.sol @@ -20,12 +20,6 @@ contract BaseAuctioneerTest is Setup { event AuctionKicked(address indexed from, uint256 available); - event AuctionTaken( - address indexed from, - uint256 amountTaken, - uint256 amountLeft - ); - IMockAuctioneer public auctioneer; uint256 public wantScaler; @@ -44,7 +38,7 @@ contract BaseAuctioneerTest is Setup { function test_enableAuction() public { address from = tokenAddrs["USDC"]; - auctioneer.enableAuction(from); + auctioneer.enable(from); assertEq(auctioneer.kickable(from), 0); assertEq(auctioneer.getAmountNeeded(from, 1e18), 0); @@ -64,13 +58,13 @@ contract BaseAuctioneerTest is Setup { // Can't re-enable vm.expectRevert("already enabled"); - auctioneer.enableAuction(from); + auctioneer.enable(from); } function test_enableSecondAuction() public { address from = tokenAddrs["USDC"]; - auctioneer.enableAuction(from); + auctioneer.enable(from); assertEq(auctioneer.kickable(from), 0); assertEq(auctioneer.getAmountNeeded(from, 1e18), 0); @@ -87,7 +81,7 @@ contract BaseAuctioneerTest is Setup { vm.expectEmit(true, true, true, true, address(auctioneer)); emit AuctionEnabled(secondFrom, address(asset)); - auctioneer.enableAuction(secondFrom); + auctioneer.enable(secondFrom); assertEq(auctioneer.kickable(secondFrom), 0); assertEq(auctioneer.getAmountNeeded(secondFrom, 1e18), 0); @@ -95,7 +89,7 @@ contract BaseAuctioneerTest is Setup { (_kicked, _scaler, _initialAvailable) = auctioneer.auctions(secondFrom); assertEq(_kicked, 0); - assertEq(_scaler, 1e12); + assertEq(_scaler, 1); assertEq(_initialAvailable, 0); assertEq(auctioneer.available(secondFrom), 0); } @@ -103,7 +97,7 @@ contract BaseAuctioneerTest is Setup { function test_disableAuction() public { address from = tokenAddrs["USDC"]; - auctioneer.enableAuction(from); + auctioneer.enable(from); assertEq(auctioneer.kickable(from), 0); assertEq(auctioneer.getAmountNeeded(from, 1e18), 0); @@ -118,7 +112,7 @@ contract BaseAuctioneerTest is Setup { vm.expectEmit(true, true, true, true, address(auctioneer)); emit AuctionDisabled(from, address(asset)); - auctioneer.disableAuction(from); + auctioneer.disable(from); (_kicked, _scaler, _initialAvailable) = auctioneer.auctions(from); @@ -136,23 +130,23 @@ contract BaseAuctioneerTest is Setup { fromScaler = WAD / 10 ** ERC20(from).decimals(); wantScaler = WAD / 10 ** ERC20(asset).decimals(); - auctioneer.enableAuction(from); + auctioneer.enable(from); assertEq(auctioneer.kickable(from), 0); (uint64 _kicked, uint64 _scaler, uint128 _initialAvailable) = auctioneer .auctions(from); assertEq(_kicked, 0); - assertEq(_scaler, 1e12); + assertEq(_scaler, 1e10); assertEq(_initialAvailable, 0); assertEq(auctioneer.available(from), 0); airdrop(ERC20(from), address(auctioneer), _amount); assertEq(auctioneer.kickable(from), _amount); - (, _kicked, _initialAvailable) = auctioneer.auctions(from); + (_kicked, , _initialAvailable) = auctioneer.auctions(from); assertEq(_kicked, 0); - assertEq(_initialAvailable, _amount); + assertEq(_initialAvailable, 0); vm.expectEmit(true, true, true, true, address(auctioneer)); emit AuctionKicked(from, _amount); @@ -162,7 +156,7 @@ contract BaseAuctioneerTest is Setup { assertEq(ERC20(from).balanceOf(address(auctioneer)), available); assertEq(auctioneer.kickable(from), 0); - (, _kicked, _initialAvailable) = auctioneer.auctions(from); + (_kicked, , _initialAvailable) = auctioneer.auctions(from); assertEq(_kicked, block.timestamp); assertEq(_initialAvailable, _amount); uint256 startingPrice = ((auctioneer.startingPrice() * @@ -202,12 +196,6 @@ contract BaseAuctioneerTest is Setup { assertEq(auctioneer.price(from), 0); assertEq(auctioneer.getAmountNeeded(from, _amount), 0); - - // Can't kick a new one yet - vm.expectRevert("too soon"); - auctioneer.kick(from); - - assertEq(auctioneer.kickable(from), 0); } function test_takeAuction_default(uint256 _amount, uint16 _percent) public { @@ -219,7 +207,7 @@ contract BaseAuctioneerTest is Setup { fromScaler = WAD / 10 ** ERC20(from).decimals(); wantScaler = WAD / 10 ** ERC20(asset).decimals(); - auctioneer.enableAuction(from); + auctioneer.enable(from); airdrop(ERC20(from), address(auctioneer), _amount); @@ -229,7 +217,7 @@ contract BaseAuctioneerTest is Setup { (uint64 _kicked, uint64 _scaler, uint128 _initialAvailable) = auctioneer .auctions(from); assertEq(_kicked, block.timestamp); - assertEq(_scaler, 1e12); + assertEq(_scaler, 1e10); assertEq(_initialAvailable, _amount); assertEq(ERC20(from).balanceOf(address(auctioneer)), _amount); @@ -246,8 +234,6 @@ contract BaseAuctioneerTest is Setup { uint256 before = ERC20(from).balanceOf(address(this)); - vm.expectEmit(true, true, true, true, address(auctioneer)); - emit AuctionTaken(from, toTake, left); uint256 amountTaken = auctioneer.take(from, toTake); assertEq(amountTaken, toTake); diff --git a/src/test/mocks/MockAuctionSwapper.sol b/src/test/mocks/MockAuctionSwapper.sol index 135c9c9..e6fe1f4 100644 --- a/src/test/mocks/MockAuctionSwapper.sol +++ b/src/test/mocks/MockAuctionSwapper.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.8.18; -import {AuctionSwapper, SafeERC20} from "../../swappers/AuctionSwapper.sol"; +import {AuctionSwapper, Auction, SafeERC20} from "../../swappers/AuctionSwapper.sol"; import {BaseStrategy, ERC20} from "@tokenized-strategy/BaseStrategy.sol"; contract MockAuctionSwapper is BaseStrategy, AuctionSwapper { @@ -41,11 +41,11 @@ contract MockAuctionSwapper is BaseStrategy, AuctionSwapper { return letKick; } - function kickAuction(address _token) internal returns (uint256) { + function kickAuction(address _token) external returns (uint256) { if (useDefault) return _kickAuction(_token); ERC20(_token).safeTransfer(auction, letKick); - return ERC20(_token).balanceOf(auction); + return Auction(auction).kick(_token); } function setUseDefault(bool _useDefault) external { @@ -61,10 +61,7 @@ import {IStrategy} from "@tokenized-strategy/interfaces/IStrategy.sol"; import {IAuctionSwapper} from "../../swappers/interfaces/IAuctionSwapper.sol"; interface IMockAuctionSwapper is IStrategy, IAuctionSwapper { - function enableAuction( - address _from, - address _to - ) external returns (bytes32); + function enableAuction(address _from, address _to) external; function disableAuction(address _from) external; @@ -77,4 +74,6 @@ interface IMockAuctionSwapper is IStrategy, IAuctionSwapper { function setLetKick(uint256 _letKick) external; function kickAuction(address _token) external returns (uint256); + + function kickable(address _token) external view returns (uint256); }