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": {
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
"
},
"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/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/dsa-module/main.sol": {
"content": "//SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {VariablesBufferHelper} from "../../common/variables/variablesBufferHelper.sol";
import {Structs} from "../../common/variables/structs.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
contract DSAModule is VariablesBufferHelper {
/***********************************|
| EVENTS |
|__________________________________*/
// @notice emitted when spell function is called by auth
event LogDSASpell(
address indexed to,
bytes data,
uint256 value,
uint256 operation
);
// @notice emitted when addDSAAuth function is called by auth
event LogAddDSAAuthority(address indexed newAuthority);
/**
* @dev Admin Spell function
* @param to_ target address
* @param calldata_ function calldata
* @param value_ function msg.value
* @param operation_ .call or .delegate. (0 => .call, 1 => .delegateCall)
*/
function spell(
address to_,
bytes memory calldata_,
uint256 value_,
uint256 operation_
) external payable onlyAuth {
if (operation_ == 0) {
// .call
Address.functionCallWithValue(
to_,
calldata_,
value_,
"spell: .call failed"
);
} else if (operation_ == 1) {
// .delegateCall
Address.functionDelegateCall(
to_,
calldata_,
"spell: .delegateCall failed"
);
} else {
revert("no operation");
}
emit LogDSASpell(to_, calldata_, value_, operation_);
}
/**
* @dev Admin function to add auth on DSA
* @param auth_ new auth address for DSA
*/
function addDSAAuth(address auth_) external onlyAuth {
string[] memory targets_ = new string[](1);
bytes[] memory calldata_ = new bytes[](1);
targets_[0] = "AUTHORITY-A";
calldata_[0] = abi.encodeWithSignature("add(address)", auth_);
vaultDSA.cast(targets_, calldata_, address(this));
emit LogAddDSAAuthority(auth_);
}
}
"
}
},
"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:06
Comments
Log in to comment.
No comments yet.