Skip to content

Commit

Permalink
chore: deploy auction
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Nov 13, 2024
1 parent 6958548 commit 785d558
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 94 deletions.
2 changes: 1 addition & 1 deletion script/DeployAuction.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Auctions/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Bases/Auctioneer/IBaseAuctioneer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/swappers/AuctionSwapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
81 changes: 28 additions & 53 deletions src/test/AuctionSwapper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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() *
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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() *
Expand Down Expand Up @@ -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 {
Expand All @@ -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);

Expand All @@ -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);
Expand Down
Loading

0 comments on commit 785d558

Please sign in to comment.