Description:
Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/infinite-proxy/interfaces/IProxy.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
interface IProxy {
function setAdmin(address newAdmin_) external;
function setDummyImplementation(address newDummyImplementation_) external;
function addImplementation(
address implementation_,
bytes4[] calldata sigs_
) external;
function removeImplementation(address implementation_) external;
function getAdmin() external view returns (address);
function getDummyImplementation() external view returns (address);
function getImplementationSigs(
address impl_
) external view returns (bytes4[] memory);
function getSigsImplementation(bytes4 sig_) external view returns (address);
function readFromStorage(
bytes32 slot_
) external view returns (uint256 result_);
}
"
},
"contracts/vault/common/interfaces/IDSA.sol": {
"content": "//SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
interface IDSA {
function cast(
string[] calldata _targetNames,
bytes[] calldata _datas,
address _origin
) external payable returns (bytes32);
}
"
},
"contracts/vault/common/interfaces/IInstaIndex.sol": {
"content": "//SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
interface IInstaIndex {
function build(
address owner_,
uint256 accountVersion_,
address origin_
) external returns (address account_);
}
"
},
"contracts/vault/common/interfaces/IToken.sol": {
"content": "//SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
interface IToken {
function approve(address, uint256) external;
function transfer(address, uint) external;
function transferFrom(address, address, uint) external;
function deposit() external payable;
function withdraw(uint) external;
function balanceOf(address) external view returns (uint);
function decimals() external view returns (uint);
function totalSupply() external view returns (uint);
function allowance(
address owner,
address spender
) external view returns (uint256);
}
"
},
"contracts/vault/common/interfaces/IVaultV3.sol": {
"content": "//SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
interface IVaultV3 {
function readFromStorage(bytes32 slot_) external view returns (uint256 result_);
function getWithdrawFee(uint256 amount_) external view returns (uint256);
function getProtocolRatio(uint8 protocolId_) external view returns (uint256 ratio_);
function getNetAssets() external view returns (uint256 totalAssets_, uint256 totalDebt_, uint256 netAssets_, uint256 aggregatedRatio_);
function getTokenExchangeRate(address tokenAddress_) external view returns (uint256 exchangeRate_);
}
"
},
"contracts/vault/common/variables/constants.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
contract Constants {
address internal constant _TEAM_MULTISIG = 0x4F6F977aCDD1177DCD81aB83074855EcB9C2D49e;
address internal constant _INSTA_INDEX_ADDRESS = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
address internal constant _USDT_ADDRESS = 0xdAC17F958D2ee523a2206206994597C13D831ec7; // 6 decimals
}
"
},
"contracts/vault/common/variables/primaryHelpers.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {Constants} from "./constants.sol";
import {StorageVariables} from "./storageVariables.sol";
import {IProxy} from "../../../infinite-proxy/interfaces/IProxy.sol";
import {Structs} from "./structs.sol";
import {IVaultV3} from "../interfaces/IVaultV3.sol";
import {IToken} from "../interfaces/IToken.sol";
contract PrimaryHelpers is Constants, StorageVariables {
using Structs for Structs.AuthTypes;
/***********************************|
| ERRORS |
|__________________________________*/
error Helpers__UnsupportedProtocolId();
error Helpers__NotRebalancer();
error Helpers__NotPrimaryRebalancer();
error Helpers__Reentrant();
error Helpers__NotAuth();
error Helpers__InvalidAuthType();
error Helpers__NotEnoughSwapLimit();
function _auth(
Structs.AuthTypes authType_,
address account_
) internal view {
address admin_ = IProxy(address(this)).getAdmin();
if (authType_ == Structs.AuthTypes.Owner) {
if (admin_ != account_) {
revert Helpers__NotAuth();
}
} else if (authType_ == Structs.AuthTypes.SecondaryAuth) {
if (
secondaryAuth != account_ &&
admin_ != account_
) {
revert Helpers__NotAuth();
}
} else if (authType_ == Structs.AuthTypes.PrimaryRebalancer) {
if (!isPrimaryRebalancer[account_] && admin_ != account_) {
revert Helpers__NotAuth();
}
} else if (authType_ == Structs.AuthTypes.Rebalancer) {
if (
!isSecondaryRebalancer[account_] &&
!isPrimaryRebalancer[account_] &&
admin_ != account_
) {
revert Helpers__NotAuth();
}
} else {
revert Helpers__InvalidAuthType();
}
}
/***********************************|
| MODIFIERS |
|__________________________________*/
/// @notice reverts if msg.sender is not auth.
modifier onlyAuth() {
_auth(Structs.AuthTypes.Owner, msg.sender);
_;
}
/// @notice reverts if msg.sender is not secondaryAuth or auth
modifier onlySecondaryAuth() {
_auth(Structs.AuthTypes.SecondaryAuth, msg.sender);
_;
}
/// @notice reverts if msg.sender is not rebalancer or auth
modifier onlyRebalancer() {
_auth(Structs.AuthTypes.Rebalancer, msg.sender);
_;
}
/// @notice reverts if msg.sender is not primaryRebalancer or auth
modifier onlyPrimaryRebalancer() {
_auth(Structs.AuthTypes.PrimaryRebalancer, msg.sender);
_;
}
/**
* @dev reentrancy gaurd.
*/
modifier nonReentrant() {
if (_status == 2) revert Helpers__Reentrant();
_status = 2;
_;
_status = 1;
}
/// @notice Implements a method to read uint256 data from storage at a bytes32 storage slot key.
function readFromStorage(
bytes32 slot_
) public view returns (uint256 result_) {
assembly {
result_ := sload(slot_) // read value from the storage slot
}
}
function _getAmountInUsd(
address tokenAddress_,
uint256 amount_,
uint256 exchangeRate_
) internal view returns (uint256 amountInUsd_) {
uint256 tokenDecimals_ = IToken(tokenAddress_).decimals();
amountInUsd_ =
(amount_ * exchangeRate_) /
10 ** (2 * tokenDecimals_ - 6);
}
/// @notice Checks the available swap limit.
/// @return availableSwapLimit_ The available swap limit.
function checkAvailableSwapLimit()
public
view
returns (uint256 availableSwapLimit_)
{
uint256 timeElapsed_ = block.timestamp - lastSwapTimestamp;
availableSwapLimit_ = availableSwapLimit;
/// @dev If time has elapsed, calculate the refill.
if (timeElapsed_ > 0) {
uint256 refill_ = (timeElapsed_ * maxDailySwapLimit) /
(24 * 60 * 60);
availableSwapLimit_ += refill_;
availableSwapLimit_ = availableSwapLimit_ > maxDailySwapLimit
? maxDailySwapLimit
: availableSwapLimit_;
}
}
function _handleSwapLimitCheck(uint256 amount_) internal {
availableSwapLimit = checkAvailableSwapLimit();
if (availableSwapLimit < amount_) {
revert Helpers__NotEnoughSwapLimit();
}
availableSwapLimit -= amount_;
lastSwapTimestamp = block.timestamp;
}
}
"
},
"contracts/vault/common/variables/storageVariables.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {IDSA} from "../../common/interfaces/IDSA.sol";
import {Structs} from "../../common/variables/structs.sol";
contract StorageVariables {
using Structs for Structs.FluidVaultDetails;
/****************************************************************************|
| @notice Protocol IDs |
| // AAVE-V3 : 1 (SUSDe, USDe, USDC, USDT, GHO, USDS) |
| // FLUID-WSTUSR-USDC : 2 (wstUSR, USDC) |
| // FLUID-WSTUSR-USDT : 3 (wstUSR, USDT) |
| // FLUID-WSTUSR-GHO : 4 (wstUSR, GHO) |
| // FLUID-SUSDE-USDC : 5 (SUSDe, USDC) |
| // FLUID-SUSDE-USDT : 6 (SUSDe, USDT) |
| // FLUID-SUSDE-GHO : 7 (SUSDe, GHO) |
| // FLUID-syrupUSDC-USDC : 8 (syrupUSDC, USDC) |
| // FLUID-syrupUSDC-USDT : 9 (syrupUSDC, USDT) |
| // FLUID-syrupUSDC-GHO : 10 (syrupUSDC, GHO) |
|___________________________________________________________________________*/
/***********************************|
| STATE VARIABLES |
|__________________________________*/
// 1: open
// 2: closed
uint8 internal _status;
IDSA public vaultDSA;
/// @notice Secondary auth that only has the power to reduce max risk ratio.
address public secondaryAuth;
/// @notice Current exchange price.
uint256 public exchangePrice;
/// @notice Last timestamp the exchange price was updated
/// @dev This is used to calculate the rate of the vault
uint256 public lastExchangePriceUpdatedAt;
/// @notice Mapping to store allowed primary rebalancers
/// @dev Primary rebalancers are the ones that can perform swap related actions
/// Modifiable by auth
mapping(address => bool) public isPrimaryRebalancer;
/// @notice Mapping to store allowed secondary rebalancers
/// @dev Secondary rebalancers are the ones that can perform all rebalancer actions except swap related actions
/// Modifiable by auth
mapping(address => bool) public isSecondaryRebalancer;
// Mapping of protocol id => max risk ratio, scaled to use basis points. i.e. 1e4 = 100%, 1e2 = 1%
// 1: AAVE-V3
// 2: FLUID-WSTUSR-USDC
// 3: FLUID-WSTUSR-USDT
// 4: FLUID-WSTUSR-GHO
// 5: FLUID-SUSDE-USDC
// 6: FLUID-SUSDE-USDT
// 7: FLUID-SUSDE-GHO
mapping(uint8 => uint256) public maxRiskRatio;
// Max aggregated risk ratio of the vault that can be reached, scaled to use basis points. i.e. 1e4 = 100%, 1e2 = 1%
// i.e. 1e4 = 100%, 1e2 = 1%
uint256 public aggrMaxVaultRatio;
/// @notice withdraw fee is either amount in percentage or absolute minimum.
/// @dev This var defines the percentage in basis points. i.e. 1e4 = 100%, 1e2 = 1%
/// Modifiable by owner
uint256 public withdrawalFeePercentage;
/// @notice withdraw fee is either amount in percentage or absolute minimum. This var defines the absolute minimum
/// this number is given in decimals for the respective asset of the vault.
/// Modifiable by owner
uint256 public withdrawFeeAbsoluteMin; // in underlying base asset, i.e. USDT
// charge from the profits, scaled to use basis points. i.e. 1e4 = 100%, 1e2 = 1%
uint256 public revenueFeePercentage;
/// @notice Stores reserves for the vault (previously revenue)
/// @dev Reserves - also serve a purpose to cover unknown users losses
/// @dev Reserves can be negative if there is not enough revenue to cover the losses
int256 public reserves;
/// @notice Min APR for the vault. This is the minimum APR the vault must yield.
/// @dev Can be modified by the owner / secondary auth.
uint256 public minRate;
/// @notice Max APR for the vault. This is the maximum APR the vault can yield.
/// @dev Can be modified by the owner / secondary auth.
uint256 public maxRate;
/// @notice Revenue will be transffered to this address upon collection.
address public treasury;
///@notice Mapping to store fluid vault details
/// @dev Protocol ID => Fluid Vault Details (VaultAddress, NFTId)
/// 2: FLUID-WSTUSR-USDC
/// 3: FLUID-WSTUSR-USDT
/// 4: FLUID-WSTUSR-GHO
/// 5: FLUID-SUSDE-USDC
/// 6: FLUID-SUSDE-USDT
/// 7: FLUID-SUSDE-GHO
/// 8: FLUID-syrupUSDC-USDC
/// 9: FLUID-syrupUSDC-USDT
/// 10: FLUID-syrupUSDC-GHO
mapping(uint8 => Structs.FluidVaultDetails) public fluidVaultDetails;
/// @notice Daily swap limit of the vault.
/// @dev This is used to prevent abuse of the swap functionality.
/// @dev Team multisig can update this value.
uint256 public maxDailySwapLimit;
/// @notice Available swap limit of the vault.
/// @dev This is used to track the available swap limit of the vault.
uint256 public availableSwapLimit;
/// @notice Last timestamp the swap limit was recalculated.
uint256 public lastSwapTimestamp;
/// @notice Maximum loss in USD that can be incurred during a swap.
/// In Percentage, scaled to use the basis points. i.e. 1e4 = 100%, 1e2 = 1%
uint256 public maxSwapLossPercentage;
}
"
},
"contracts/vault/common/variables/structs.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
library Structs {
struct FluidVaultDetails {
address vaultAddress;
uint256 nftId;
}
enum AuthTypes {
Owner,
SecondaryAuth,
PrimaryRebalancer,
Rebalancer
}
}
"
},
"contracts/vault/common/variables/variablesBuffer.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
/// @title VariablesBuffer
/// @notice Allocates space of 151 slots to maintain storage
/// consistency with imported variables in VariablesPrimaryHelper.
contract VariablesBuffer {
uint[151] internal __buffergap;
}
"
},
"contracts/vault/common/variables/variablesBufferHelper.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
/// @title VariablesBufferHelper
/// @notice Buffer Helper for variables that imports all the primary
/// helpers from the storage slot 152.
import {VariablesBuffer} from "./variablesBuffer.sol";
import {PrimaryHelpers} from "./primaryHelpers.sol";
// Buffer & variables
contract VariablesBufferHelper is VariablesBuffer, PrimaryHelpers {}
"
},
"contracts/vault/modules/admin-module/events.sol": {
"content": "//SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
contract Events {
/// @notice Emitted when rebalancer is added or removed.
event LogUpdateRebalancer(
address indexed rebalancer,
bool indexed isPrimaryRebalancer,
bool indexed isRebalancer
);
/// @notice Emitted when vault's functionality is paused or resumed.
event LogChangeStatus(uint8 indexed status);
/// @notice Emitted when the revenue or withdrawal fee is updated.
event LogUpdateFees(
uint256 indexed revenueFeePercentage,
uint256 indexed withdrawalFeePercentage,
uint256 indexed withdrawFeeAbsoluteMin
);
/// @notice Emitted when the protocol's risk ratio is updated.
event LogUpdateMaxRiskRatio(uint8 indexed protocolId, uint256 newRiskRatio);
/// @notice Emitted whenever the address collecting the revenue is updated.
event LogUpdateTreasury(
address indexed oldTreasury,
address indexed newTreasury
);
/// @notice Emitted when secondary auth is updated.
event LogUpdateSecondaryAuth(
address indexed oldSecondaryAuth,
address indexed secondaryAuth
);
/// @notice Emitted when max vault ratio is updated.
event LogUpdateAggrMaxVaultRatio(
uint256 indexed oldAggrMaxVaultRatio,
uint256 indexed aggrMaxVaultRatio
);
/// @notice Emitted when fluid vault details are updated.
event LogUpdateFluidVaultDetails(
uint256 protocolId,
address indexed vaultAddress,
uint256 indexed nftId
);
/// @notice Emitted when rates are updated.
event LogUpdateRates(uint256 newMinRate, uint256 newMaxRate);
/// @notice Emitted when the daily swap limit is updated.
event LogUpdateMaxDailySwapLimit(
uint256 oldMaxDailySwapLimit,
uint256 newMaxDailySwapLimit
);
/// @notice Emitted when the maximum loss percentage is updated.
event LogUpdateMaxSwapLossPercentage(
uint256 oldMaxSwapLossPercentage,
uint256 newMaxSwapLossPercentage
);
}
"
},
"contracts/vault/modules/admin-module/main.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {IDSA} from "../../common/interfaces/IDSA.sol";
import {IInstaIndex} from "../../common/interfaces/IInstaIndex.sol";
import {Events} from "./events.sol";
import {Structs} from "../../common/variables/structs.sol";
import {VariablesBufferHelper} from "../../common/variables/variablesBufferHelper.sol";
contract AdminModule is VariablesBufferHelper, Events {
using Structs for Structs.FluidVaultDetails;
/***********************************|
| ERRORS |
|__________________________________*/
error AdminModule__AlreadyInitialized();
error AdminModule__NotAuth();
error AdminModule__NotSecondaryAuth();
error AdminModule__MoreThanMaxRatio();
error AdminModule__NotValidAddress();
error AdminModule__NotValidInputLength();
error AdminModule__NotValidRevenueFee();
error AdminModule__MinRateGreaterThanMaxRate();
/// @notice Vault owner and secondary wuth can update the secondary auth.
/// @param secondaryAuth_ New secondary auth to set.
function updateSecondaryAuth(
address secondaryAuth_
) public onlySecondaryAuth {
if (secondaryAuth_ == address(0)) {
revert AdminModule__NotValidAddress();
}
emit LogUpdateSecondaryAuth(secondaryAuth, secondaryAuth_);
secondaryAuth = secondaryAuth_;
}
/// @notice Auth can add or remove allowed rebalancers (primary or secondary)
/// @param rebalancer_ the address for the rebalancer to set the flag for
/// @param isPrimaryRebalancer_ flag for if rebalancer is primary or not
/// @param isRebalancer_ flag for if rebalancer is allowed or not
function updateRebalancer(
address rebalancer_,
bool isPrimaryRebalancer_,
bool isRebalancer_
) public onlySecondaryAuth {
if (isPrimaryRebalancer_) {
isPrimaryRebalancer[rebalancer_] = isRebalancer_;
} else {
isSecondaryRebalancer[rebalancer_] = isRebalancer_;
}
emit LogUpdateRebalancer(
rebalancer_,
isPrimaryRebalancer_,
isRebalancer_
);
}
/// @notice Auth can update the risk ratio for each protocol.
/// @param protocolId_ The Id of the protocol to update the risk ratio.
/// @param newRiskRatio_ New risk ratio of the protocol in terms of debt and collateral, scaled as per basis points. i.e 1e4 = 100%, 1e2 = 1%
/// Note Risk ratio is calculated in terms of Debt and Collateral to maintain a common
/// standard between protocols. (Risk ratio = debt / collateral).
function updateMaxRiskRatio(
uint8[] memory protocolId_,
uint256[] memory newRiskRatio_
) public onlyAuth {
uint256 length_ = protocolId_.length;
if (length_ != newRiskRatio_.length) {
revert AdminModule__NotValidInputLength();
}
/// @dev No condition to check if a ratio is valid (i.e. scaled to factor 4) since
/// a protocol's risk ratio might be set to 0 in case assets will only be supplied.
for (uint256 i_ = 0; i_ < length_; ++i_) {
maxRiskRatio[protocolId_[i_]] = newRiskRatio_[i_];
emit LogUpdateMaxRiskRatio(protocolId_[i_], newRiskRatio_[i_]);
}
}
/// @notice Secondary auth can lower the risk ratio of any protocol.
/// @param protocolId_ The Id of the protocol to reduce the risk ratio.
/// @param newRiskRatio_ New risk ratio of the protocol in terms of debt and collateral, scaled as per basis points. i.e 1e4 = 100%, 1e2 = 1%
/// Note Risk ratio is calculated in terms of Debt and Collateral to maintain a common
/// standard between protocols. (Risk ratio = debt / collateral).
function reduceMaxRiskRatio(
uint8[] memory protocolId_,
uint256[] memory newRiskRatio_
) public onlySecondaryAuth {
uint256 length_ = protocolId_.length;
if (length_ != newRiskRatio_.length) {
revert AdminModule__NotValidInputLength();
}
/// @dev No condition to check if a ratio is valid (i.e. scaled to factor 4) since
/// a protocol's risk ratio might be set to 0 in case assets will only be supplied.
for (uint256 i_ = 0; i_ < length_; ++i_) {
if (newRiskRatio_[i_] > maxRiskRatio[protocolId_[i_]]) {
revert AdminModule__MoreThanMaxRatio();
}
maxRiskRatio[protocolId_[i_]] = newRiskRatio_[i_];
emit LogUpdateMaxRiskRatio(protocolId_[i_], newRiskRatio_[i_]);
}
}
/// @notice Auth can update the max risk ratio set for the vault.
/// @param newAggrMaxVaultRatio_ New aggregated max ratio of the vault. Scaled as per basis points. i.e 1e4 = 100%, 1e2 = 1%
function updateAggrMaxVaultRatio(
uint256 newAggrMaxVaultRatio_
) public onlyAuth {
emit LogUpdateAggrMaxVaultRatio(
aggrMaxVaultRatio,
newAggrMaxVaultRatio_
);
aggrMaxVaultRatio = newAggrMaxVaultRatio_;
}
/// @notice Secondary auth can reduce the max risk ratio set for the vault.
/// @param newAggrMaxVaultRatio_ New aggregated max ratio of the vault. Scaled as per basis points. i.e 1e4 = 100%, 1e2 = 1%
function reduceAggrMaxVaultRatio(
uint256 newAggrMaxVaultRatio_
) public onlySecondaryAuth {
if (newAggrMaxVaultRatio_ > aggrMaxVaultRatio) {
revert AdminModule__MoreThanMaxRatio();
}
emit LogUpdateAggrMaxVaultRatio(
aggrMaxVaultRatio,
newAggrMaxVaultRatio_
);
aggrMaxVaultRatio = newAggrMaxVaultRatio_;
}
/// @notice Auth can pause or resume all functionality of the vault.
/// @param status_ New status of the vault.
/// Note status = 1 => Vault functions are enabled; status = 2 => Vault functions are paused.
function changeVaultStatus(uint8 status_) public onlySecondaryAuth {
_status = status_;
emit LogChangeStatus(status_);
}
/// @notice Auth can update the revenue and withdrawal fee percentage.
/// @param revenueFeePercent_ New revenue fee percentage, scaled as per basis points. i.e 1e4 = 100%, 1e2 = 1%
/// @param withdrawalFeePercent_ New withdrawal fee percentage, scaled as per basis points. i.e 1e4 = 100%, 1e2 = 1%
/// @param withdrawFeeAbsoluteMin_ New withdraw fee absolute. 1 USDT = 1e6, 0.01 USDT = 1e4
function updateFees(
uint256 revenueFeePercent_,
uint256 withdrawalFeePercent_,
uint256 withdrawFeeAbsoluteMin_
) public onlyAuth {
if (revenueFeePercentage > 1e6 || withdrawalFeePercentage > 1e6) {
revert AdminModule__NotValidRevenueFee();
}
revenueFeePercentage = revenueFeePercent_;
withdrawalFeePercentage = withdrawalFeePercent_;
withdrawFeeAbsoluteMin = withdrawFeeAbsoluteMin_;
emit LogUpdateFees(
revenueFeePercent_,
withdrawalFeePercent_,
withdrawFeeAbsoluteMin_
);
}
/// @notice Auth can update the address that collected revenue.
/// @param newTreasury_ Address that will collect the revenue.
function updateTreasury(address newTreasury_) public onlyAuth {
if (newTreasury_ == address(0)) {
revert AdminModule__NotValidAddress();
}
emit LogUpdateTreasury(treasury, newTreasury_);
treasury = newTreasury_;
}
/// @notice Secondary auth can update the fluid vault details.
/// @param protocolId_ The Id of the protocol to update the fluid vault details.
/// @param vaultAddress_ The address of the vault to update the fluid vault details.
/// @param nftId_ The NFT Id of the vault to update the fluid vault details.
function updateFluidVaultDetails(
uint8 protocolId_,
address vaultAddress_,
uint256 nftId_
) public onlySecondaryAuth {
fluidVaultDetails[protocolId_].vaultAddress = vaultAddress_;
fluidVaultDetails[protocolId_].nftId = nftId_;
emit LogUpdateFluidVaultDetails(protocolId_, vaultAddress_, nftId_);
}
/// @notice Secondary auth can update the min rate.
/// @param newMinRate_ The new min rate to set.
/// @param newMaxRate_ The new max rate to set.
function updateRates(
uint256 newMinRate_,
uint256 newMaxRate_
) public onlySecondaryAuth {
if (newMinRate_ > newMaxRate_)
revert AdminModule__MinRateGreaterThanMaxRate();
minRate = newMinRate_;
maxRate = newMaxRate_;
emit LogUpdateRates(minRate, maxRate);
}
/// @notice Auth can update the max daily swap limit.
/// @param newMaxDailySwapLimit_ The new max daily swap limit to set.
function updateMaxDailySwapLimit(
uint256 newMaxDailySwapLimit_
) public onlySecondaryAuth {
emit LogUpdateMaxDailySwapLimit(
maxDailySwapLimit,
newMaxDailySwapLimit_
);
maxDailySwapLimit = newMaxDailySwapLimit_;
availableSwapLimit = maxDailySwapLimit;
}
function updateMaxSwapLossPercentage(
uint256 newMaxSwapLossPercentage_
) public onlySecondaryAuth {
emit LogUpdateMaxSwapLossPercentage(
maxSwapLossPercentage,
newMaxSwapLossPercentage_
);
maxSwapLossPercentage = newMaxSwapLossPercentage_;
}
function initialize(
address secondaryAuth_,
address treasury_,
address primaryRebalancer_,
address secondaryRebalancer_,
Structs.FluidVaultDetails[] memory fluidVaultDetails_,
uint256[] memory maxRiskRatios_,
uint256 aggrMaxVaultRatio_,
uint256 revenueFeePercentage_,
uint256 withdrawalFeePercentage_,
uint256 withdrawFeeAbsoluteMin_,
uint256 minRate_,
uint256 maxRate_
) public onlyAuth {
// Check if the vault is already initialized.
if (_status != 0) {
revert AdminModule__AlreadyInitialized();
}
// Initialize Auths.
updateSecondaryAuth(secondaryAuth_);
updateRebalancer(primaryRebalancer_, true, true);
updateRebalancer(secondaryRebalancer_, false, true);
// Initialize exchange price to 1e6.
exchangePrice = 1e6;
lastExchangePriceUpdatedAt = block.timestamp;
// Initialize DSA.
address vaultDsaAddress_ = IInstaIndex(_INSTA_INDEX_ADDRESS).build(address(this), 2, address(this));
vaultDSA = IDSA(vaultDsaAddress_);
// Intialize fluid vault details. (Fluid vaults starts from protocolId 2)
for (uint8 i = 0; i < fluidVaultDetails_.length; i++) {
fluidVaultDetails[i + 2] = fluidVaultDetails_[i];
}
// Intialize max risk ratio for protocols.
uint length_ = maxRiskRatios_.length;
uint8[] memory protocolIds_ = new uint8[](length_);
for (uint8 i = 0; i < length_; i++) {
protocolIds_[i] = i + 1; // First protocol Id is 1.
}
// Initialize risk ratios, fees and rate parameters.
updateMaxRiskRatio(protocolIds_, maxRiskRatios_);
updateAggrMaxVaultRatio(aggrMaxVaultRatio_);
updateFees(revenueFeePercentage_, withdrawalFeePercentage_, withdrawFeeAbsoluteMin_);
updateRates(minRate_, maxRate_);
// Intialize Treasury.
updateTreasury(treasury_);
// Initialize swap parameters.
updateMaxDailySwapLimit(1000_000_000); // 1000 USDT
updateMaxSwapLossPercentage(10); // 0.1%
// Initialize _status as open.
changeVaultStatus(1);
}
}
"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
}
}
}}
Submitted on: 2025-10-30 14:08:05
Comments
Log in to comment.
No comments yet.