Skip to content

Commit 6bb940d

Browse files
authored
Merge pull request #417 from stabilitydao/revenue-router
🧑‍🔧 RevenueRouter 1.7.0: improve; fix warnings
2 parents 5289046 + 5137fb0 commit 6bb940d

21 files changed

+336
-389
lines changed

script/deploy-periphery/LiquidationBotUpdate.Sonic.s.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pragma solidity ^0.8.23;
33

44
import {Script} from "forge-std/Script.sol";
5-
import {Proxy} from "../../src/core/proxy/Proxy.sol";
65
import {LiquidationBot} from "../../src/periphery/LiquidationBot.sol";
76

87
contract DeployLiquidationBotUpdate is Script {

src/adapters/AlgebraAdapter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ contract AlgebraAdapter is Controllable, ICAmmAdapter {
8484
tokenIn == token0,
8585
int(amount),
8686
tokenIn == token0 ? UniswapV3MathLib.MIN_SQRT_RATIO : UniswapV3MathLib.MAX_SQRT_RATIO,
87-
abi.encode(SwapCallbackData(tokenIn, amount))
87+
abi.encode(SwapCallbackData({tokenIn: tokenIn, amount: amount}))
8888
);
8989

9090
uint priceAfter = getPrice(pool, tokenIn, tokenOut, amount);

src/adapters/AlgebraV4Adapter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ contract AlgebraV4Adapter is Controllable, ICAmmAdapter {
8787
tokenIn == token0,
8888
int(amount),
8989
tokenIn == token0 ? UniswapV3MathLib.MIN_SQRT_RATIO : UniswapV3MathLib.MAX_SQRT_RATIO,
90-
abi.encode(SwapCallbackData(tokenIn, amount))
90+
abi.encode(SwapCallbackData({tokenIn: tokenIn, amount: amount}))
9191
);
9292

9393
uint priceAfter = getPrice(pool, tokenIn, tokenOut, amount);

src/adapters/KyberAdapter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ contract KyberAdapter is Controllable, ICAmmAdapter {
8484
int(amount),
8585
tokenIn == token0,
8686
tokenIn == token0 ? UniswapV3MathLib.MIN_SQRT_RATIO : UniswapV3MathLib.MAX_SQRT_RATIO,
87-
abi.encode(SwapCallbackData(tokenIn, amount))
87+
abi.encode(SwapCallbackData({tokenIn: tokenIn, amount: amount}))
8888
);
8989

9090
uint priceAfter = getPrice(pool, tokenIn, tokenOut, amount);

src/adapters/PendleAdapter.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ contract PendleAdapter is Controllable, IAmmAdapter {
113113
// asset to PT
114114
if ((tokenIn == tokens[3] && tokenOut == tokens[1]) || (tokenIn == tokens[4] && tokenOut == tokens[1])) {
115115
// DefaultApprox means no off-chain preparation is involved, more gas consuming (~ 180k gas)
116-
ApproxParams memory defaultApprox = ApproxParams(0, type(uint).max, 0, 256, 1e14);
116+
ApproxParams memory defaultApprox =
117+
ApproxParams({guessMin: 0, guessMax: type(uint).max, guessOffchain: 0, maxIteration: 256, eps: 1e14});
117118
TokenInput memory input = TokenInput({
118119
tokenIn: tokenIn,
119120
netTokenIn: amount,

src/adapters/UniswapV3Adapter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ contract UniswapV3Adapter is Controllable, ICAmmAdapter {
8989
tokenIn == token0,
9090
int(amount),
9191
tokenIn == token0 ? UniswapV3MathLib.MIN_SQRT_RATIO : UniswapV3MathLib.MAX_SQRT_RATIO,
92-
abi.encode(SwapCallbackData(tokenIn, amount))
92+
abi.encode(SwapCallbackData({tokenIn: tokenIn, amount: amount}))
9393
);
9494

9595
uint priceAfter = getPrice(pool, tokenIn, tokenOut, amount);

src/adapters/libs/balancerv3/ReClammMath.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pragma solidity ^0.8.24;
44

55
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
6-
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
6+
//import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
77

88
//import {Rounding} from "../../../integrations/balancerv3/VaultTypes.sol";
99

src/core/Factory.sol

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ import {IStrategyLogic} from "../interfaces/IStrategyLogic.sol";
2525
/// Provides the opportunity to upgrade vaults and strategies.
2626
/// Changelog:
2727
/// 2.0.0: BREAKING CHANGES
28-
/// * Removed `setVaultConfig` from IFactory
29-
/// * Removed `setStrategyLogicConfig` from IFactory
30-
/// - These functions are no longer available in the ABI
31-
/// - Governance/Operator config is now managed via `setVaultImplementation`
32-
/// and `setStrategyImplementation`
33-
/// * Integrations and deployment scripts must be updated accordingly
28+
/// * Removed `setVaultConfig` from IFactory; added `setVaultImplementation`
29+
/// * Removed `setStrategyLogicConfig` from IFactory; added `setStrategyImplementation`
3430
/// 1.3.1: setStrategyImplementation added to interface
3531
/// 1.3.0: vault can be built only by admin; setVaultImplementation, setStrategyImplementation;
3632
/// remove setAliasName, getAliasName, whatToBuild; remove RVault and RMVault support
@@ -95,6 +91,7 @@ contract Factory is Controllable, ReentrancyGuardUpgradeable, IFactory {
9591
}
9692
}
9793

94+
/// @inheritdoc IFactory
9895
function setStrategyImplementation(string memory strategyId, address implementation) external onlyOperator {
9996
FactoryStorage storage $ = _getStorage();
10097
if (FactoryLib.setStrategyImplementation($, platform(), strategyId, implementation)) {

src/core/VaultPriceOracle.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ contract VaultPriceOracle is Controllable, IVaultPriceOracle {
6666
uint currentRoundId = $.vaultPrices[vault_].roundId == 0 ? 1 : $.vaultPrices[vault_].roundId;
6767
require(roundId_ == currentRoundId, IVaultPriceOracle.InvalidRoundId());
6868

69-
$.observations[vault_][currentRoundId][msg.sender] = Observation(price_, block.timestamp);
69+
$.observations[vault_][currentRoundId][msg.sender] = Observation({price: price_, timestamp: block.timestamp});
7070
emit PriceSubmitted(vault_, msg.sender, price_, currentRoundId);
7171

7272
if (_countSubmissions(vault_, currentRoundId) >= $.minQuorum) {
@@ -288,7 +288,7 @@ contract VaultPriceOracle is Controllable, IVaultPriceOracle {
288288
uint medianPrice = _getMedian(prices);
289289

290290
uint newRoundId = roundId_ + 1;
291-
$.vaultPrices[vault_] = AggregatedData(medianPrice, block.timestamp, newRoundId);
291+
$.vaultPrices[vault_] = AggregatedData({price: medianPrice, timestamp: block.timestamp, roundId: newRoundId});
292292
emit PriceUpdated(vault_, medianPrice, roundId_, block.timestamp);
293293
}
294294

src/interfaces/IRevenueRouter.sol

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.28;
33

4-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
4+
import {EnumerableMap, EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
55

66
interface IRevenueRouter {
77
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
@@ -19,6 +19,8 @@ interface IRevenueRouter {
1919
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
2020

2121
error WaitForNewPeriod();
22+
error IncorrectSetup();
23+
error CantProcessAction();
2224

2325
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
2426
/* DATA TYPES */
@@ -36,6 +38,9 @@ interface IRevenueRouter {
3638
Unit[] units;
3739
address[] aavePools;
3840
EnumerableSet.AddressSet vaultsAccumulated;
41+
EnumerableSet.AddressSet assetsAccumulated;
42+
EnumerableMap.AddressToUintMap minSwapAmount;
43+
EnumerableMap.AddressToUintMap maxSwapAmount;
3944
}
4045

4146
enum UnitType {
@@ -64,6 +69,15 @@ interface IRevenueRouter {
6469
/// @notice Setup Aave pool list
6570
function setAavePools(address[] calldata pools) external;
6671

72+
/// @notice Set min swap amounts for assets
73+
function setMinSwapAmounts(address[] calldata assets, uint[] calldata minAmounts) external;
74+
75+
/// @notice Set max swap amounts for assets
76+
function setMaxSwapAmounts(address[] calldata assets, uint[] calldata maxAmounts) external;
77+
78+
/// @notice Change revenue share for Vaults Unit
79+
function setXShare(uint newShare) external;
80+
6781
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
6882
/* USER ACTIONS */
6983
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
@@ -84,9 +98,15 @@ interface IRevenueRouter {
8498
/// @notice Claim units fees and swap to STBL
8599
function processUnitsRevenue() external;
86100

87-
/// @notice Withdraw assets from accumulated vaults and swap to STBL
101+
/// @notice Withdraw assets from accumulated vaults
88102
function processAccumulatedVaults(uint maxVaultsForWithdraw) external;
89103

104+
/// @notice Withdraw assets from accumulated vaults
105+
function processAccumulatedVaults(uint maxVaultsForWithdraw, uint maxWithdrawAmount) external;
106+
107+
/// @notice Distribute extracted accumulated assets amounts
108+
function processAccumulatedAssets(uint maxAssetsForProcess) external;
109+
90110
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
91111
/* VIEW FUNCTIONS */
92112
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
@@ -112,4 +132,7 @@ interface IRevenueRouter {
112132

113133
/// @notice Get vault addresses that contract hold on balance, but not withdrew yet
114134
function vaultsAccumulated() external view returns (address[] memory);
135+
136+
/// @notice Get assets that contract hold on balance
137+
function assetsAccumulated() external view returns (address[] memory);
115138
}

0 commit comments

Comments
 (0)