Skip to content

Commit 595d0f9

Browse files
committed
fix: review
1 parent d637fe3 commit 595d0f9

File tree

9 files changed

+102
-103
lines changed

9 files changed

+102
-103
lines changed

src/Bases/convertors/BaseConvertor.sol

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ contract BaseConvertor is BaseHealthCheck {
4040
IMerklDistributor(0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae);
4141

4242
/// @notice Token converted to/from strategy `asset`.
43-
ERC20 public immutable want;
43+
ERC20 public immutable WANT;
4444

4545
/// @notice Auction selling `asset` into `want`.
46-
Auction public immutable sellAssetAuction;
46+
Auction public immutable SELL_ASSET_AUCTION;
4747

4848
/// @notice Auction selling `want` into `asset`.
49-
Auction public immutable buyAssetAuction;
49+
Auction public immutable BUY_ASSET_AUCTION;
5050

5151
/// @notice Morpho-style oracle with answer = asset per want, scaled 1e36.
5252
address public oracle;
@@ -75,7 +75,7 @@ contract BaseConvertor is BaseHealthCheck {
7575
address _want,
7676
address _oracle
7777
) BaseHealthCheck(_asset, _name) {
78-
want = ERC20(_want);
78+
WANT = ERC20(_want);
7979

8080
AuctionFactory factory = AuctionFactory(
8181
0xbA7FCb508c7195eE5AE823F37eE2c11D7ED52F8e
@@ -87,16 +87,18 @@ contract BaseConvertor is BaseHealthCheck {
8787
_sellAssetAuction.enable(_asset);
8888
_sellAssetAuction.setStepDecayRate(1);
8989
_sellAssetAuction.setGovernanceOnlyKick(true);
90-
sellAssetAuction = _sellAssetAuction;
90+
SELL_ASSET_AUCTION = _sellAssetAuction;
9191

9292
Auction _buyAssetAuction = Auction(
9393
factory.createNewAuction(_asset, address(this), address(this))
9494
);
9595
_buyAssetAuction.enable(_want);
9696
_buyAssetAuction.setStepDecayRate(1);
9797
_buyAssetAuction.setGovernanceOnlyKick(true);
98-
buyAssetAuction = _buyAssetAuction;
98+
BUY_ASSET_AUCTION = _buyAssetAuction;
9999

100+
// We store the default decay rate in case a custom one
101+
// is ever used for a specific auction we can reset it to the default.
100102
decayRate = 1;
101103

102104
_setStartingPriceBps(uint16(MAX_BPS + 10));
@@ -130,6 +132,8 @@ contract BaseConvertor is BaseHealthCheck {
130132
_setStartingPriceBps(_startingPriceBps);
131133
}
132134

135+
/// @notice Set the default decay rate used for want/asset auctions.
136+
/// Reward token auctions always use DEFAULT_AUCTION_DECAY_RATE.
133137
function setDecayRate(uint256 _decayRate) external onlyManagement {
134138
_setDecayRate(_decayRate);
135139
}
@@ -144,14 +148,6 @@ contract BaseConvertor is BaseHealthCheck {
144148
_setMaxGasPriceToTend(_maxGasPriceToTend);
145149
}
146150

147-
/// @notice Management passthrough to set auction step decay rate.
148-
function setAuctionStepDecayRate(
149-
address _from,
150-
uint256 _stepDecayRate
151-
) external onlyManagement {
152-
_auctionForToken(_from).setStepDecayRate(_stepDecayRate);
153-
}
154-
155151
/// @notice Management passthrough to set auction step duration.
156152
function setAuctionStepDuration(
157153
address _from,
@@ -182,23 +178,25 @@ contract BaseConvertor is BaseHealthCheck {
182178
}
183179

184180
function _kickAuction(address _from) internal virtual returns (uint256) {
185-
if (_from == address(asset)) {
186-
return _kickConfiguredAuction(sellAssetAuction, _from);
181+
if (_from == address(WANT)) {
182+
return _kickConfiguredAuction(BUY_ASSET_AUCTION, _from);
187183
}
188-
return _kickConfiguredAuction(buyAssetAuction, _from);
184+
return _kickConfiguredAuction(SELL_ASSET_AUCTION, _from);
189185
}
190186

191187
function kickable(address _from) public view virtual returns (uint256) {
192-
if (_from == address(asset)) {
193-
return _kickableFromAuction(sellAssetAuction, _from);
188+
if (_from == address(WANT)) {
189+
return _kickableFromAuction(BUY_ASSET_AUCTION, _from);
194190
}
195-
return _kickableFromAuction(buyAssetAuction, _from);
191+
return _kickableFromAuction(SELL_ASSET_AUCTION, _from);
196192
}
197193

194+
/// @notice We use trigger to go from asset -> want.
195+
/// We cannot assume loose want should be converted, so it does not go back.
198196
function auctionTrigger(
199197
address _from
200198
) external view returns (bool shouldKick, bytes memory data) {
201-
if (_from == address(want)) return (false, bytes("want"));
199+
if (_from == address(WANT)) return (false, bytes("want"));
202200

203201
if (!(_isBaseFeeAcceptable())) return (false, bytes("base fee"));
204202

@@ -247,15 +245,15 @@ contract BaseConvertor is BaseHealthCheck {
247245
}
248246

249247
function balanceOfWant() public view virtual returns (uint256) {
250-
return want.balanceOf(address(this));
248+
return WANT.balanceOf(address(this));
251249
}
252250

253251
function balanceOfAssetInAuction() public view virtual returns (uint256) {
254-
return asset.balanceOf(address(sellAssetAuction));
252+
return asset.balanceOf(address(SELL_ASSET_AUCTION));
255253
}
256254

257255
function balanceOfWantInAuction() public view virtual returns (uint256) {
258-
return want.balanceOf(address(buyAssetAuction));
256+
return WANT.balanceOf(address(BUY_ASSET_AUCTION));
259257
}
260258

261259
function availableWithdrawLimit(
@@ -272,6 +270,10 @@ contract BaseConvertor is BaseHealthCheck {
272270
require(_oracle != address(0), "ZERO ADDRESS");
273271

274272
oracle = _oracle;
273+
274+
// Call _oraclePrice() to ensure the oracle is valid.
275+
_oraclePrice();
276+
275277
emit OracleSet(_oracle);
276278
}
277279

@@ -337,7 +339,6 @@ contract BaseConvertor is BaseHealthCheck {
337339
}
338340

339341
_available = _kickableFromAuction(_auction, _from);
340-
if (_available < minAmountToSell) return 0;
341342

342343
_setAuctionPricing(_auction, _from, _available);
343344

@@ -385,8 +386,8 @@ contract BaseConvertor is BaseHealthCheck {
385386
function _auctionForToken(
386387
address _from
387388
) internal view returns (Auction _auction) {
388-
if (_from == address(asset)) return sellAssetAuction;
389-
return buyAssetAuction;
389+
if (_from == address(WANT)) return BUY_ASSET_AUCTION;
390+
return SELL_ASSET_AUCTION;
390391
}
391392

392393
function _oraclePrice() internal view virtual returns (uint256 _price) {
@@ -407,7 +408,8 @@ contract BaseConvertor is BaseHealthCheck {
407408
uint256 _stepDecayRate
408409
)
409410
{
410-
if (_from != address(asset) && _from != address(want)) {
411+
// If non want/asset tokens, use the default auction pricing.
412+
if (_from != address(asset) && _from != address(WANT)) {
411413
return (
412414
DEFAULT_AUCTION_STARTING_PRICE,
413415
0,
@@ -424,6 +426,7 @@ contract BaseConvertor is BaseHealthCheck {
424426
Math.Rounding.Up
425427
);
426428

429+
// Auction starting price is a lot size, so we need to adjust for amount.
427430
_startingPrice = Math.mulDiv(
428431
_amount,
429432
startUnitPrice,
@@ -446,10 +449,10 @@ contract BaseConvertor is BaseHealthCheck {
446449
if (_from == address(asset)) {
447450
uint256 oneAsset = 10 ** asset.decimals();
448451
uint256 quoteWant = _quoteWantFromAsset(oneAsset);
449-
return Math.mulDiv(quoteWant, 1e18, 10 ** want.decimals());
452+
return Math.mulDiv(quoteWant, 1e18, 10 ** WANT.decimals());
450453
}
451454

452-
uint256 oneWant = 10 ** want.decimals();
455+
uint256 oneWant = 10 ** WANT.decimals();
453456
uint256 quoteAsset = _quoteAssetFromWant(oneWant);
454457
return Math.mulDiv(quoteAsset, 1e18, 10 ** asset.decimals());
455458
}

src/Bases/convertors/BaseConvertor4626.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ contract BaseConvertor4626 is BaseConvertor {
2222
address _asset,
2323
string memory _name,
2424
address _want,
25-
address _vault,
26-
address _oracle
25+
address _oracle,
26+
address _vault
2727
) BaseConvertor(_asset, _name, _want, _oracle) {
2828
vault = IERC4626(_vault);
2929
require(vault.asset() == _want, "wrong vault");
3030

31-
want.forceApprove(_vault, type(uint256).max);
31+
WANT.forceApprove(_vault, type(uint256).max);
3232
}
3333

3434
/*//////////////////////////////////////////////////////////////
@@ -43,7 +43,7 @@ contract BaseConvertor4626 is BaseConvertor {
4343
function freeWant(uint256 _wantAmount) external onlyKeepers {
4444
uint256 freedWant = _freeWantFromVault(_wantAmount);
4545
if (freedWant > 0) {
46-
_kickConfiguredAuction(buyAssetAuction, address(want));
46+
_kickConfiguredAuction(BUY_ASSET_AUCTION, address(WANT));
4747
}
4848
}
4949

@@ -122,7 +122,7 @@ contract BaseConvertor4626 is BaseConvertor {
122122
function _emergencyWithdraw(uint256 _amount) internal virtual override {
123123
uint256 wantAmount = _quoteWantFromAsset(_amount);
124124
_freeWantFromVault(wantAmount);
125-
_kickConfiguredAuction(buyAssetAuction, address(want));
125+
_kickConfiguredAuction(BUY_ASSET_AUCTION, address(WANT));
126126
}
127127

128128
/*//////////////////////////////////////////////////////////////

src/Bases/convertors/Convertor4626Factory.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ contract Convertor4626Factory {
3939
address _asset,
4040
string calldata _name,
4141
address _want,
42-
address _vault,
43-
address _oracle
42+
address _oracle,
43+
address _vault
4444
) external returns (address) {
4545
address deployed = deployments4626[_asset][_want][_vault];
4646
if (deployed != address(0)) revert AlreadyDeployed(deployed);
4747

4848
IBaseConvertor4626 _newConvertor = IBaseConvertor4626(
4949
address(
50-
new BaseConvertor4626(_asset, _name, _want, _vault, _oracle)
50+
new BaseConvertor4626(_asset, _name, _want, _oracle, _vault)
5151
)
5252
);
5353

@@ -75,7 +75,7 @@ contract Convertor4626Factory {
7575
) external view returns (bool) {
7676
IBaseConvertor4626 convertor = IBaseConvertor4626(_strategy);
7777
return
78-
deployments4626[convertor.asset()][convertor.want()][
78+
deployments4626[convertor.asset()][convertor.WANT()][
7979
convertor.vault()
8080
] == _strategy;
8181
}

src/Bases/convertors/ConvertorFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ contract ConvertorFactory {
6868
address _strategy
6969
) external view returns (bool) {
7070
IBaseConvertor convertor = IBaseConvertor(_strategy);
71-
return deployments[convertor.asset()][convertor.want()] == _strategy;
71+
return deployments[convertor.asset()][convertor.WANT()] == _strategy;
7272
}
7373

7474
function _configureStrategy(IBaseConvertor _strategy) internal {

src/Bases/convertors/IBaseConvertor.sol

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ pragma solidity >=0.8.18;
44
import {IBaseHealthCheck} from "../HealthCheck/IBaseHealthCheck.sol";
55

66
interface IBaseConvertor is IBaseHealthCheck {
7-
function want() external view returns (address);
7+
function WANT() external view returns (address);
88

9-
function sellAssetAuction() external view returns (address);
9+
function SELL_ASSET_AUCTION() external view returns (address);
1010

11-
function buyAssetAuction() external view returns (address);
11+
function BUY_ASSET_AUCTION() external view returns (address);
1212

1313
function oracle() external view returns (address);
1414

@@ -38,11 +38,6 @@ interface IBaseConvertor is IBaseHealthCheck {
3838

3939
function setMaxGasPriceToTend(uint256 _maxGasPriceToTend) external;
4040

41-
function setAuctionStepDecayRate(
42-
address _from,
43-
uint256 _stepDecayRate
44-
) external;
45-
4641
function setAuctionStepDuration(
4742
address _from,
4843
uint256 _stepDuration

0 commit comments

Comments
 (0)