CryndexSavings.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "@openzeppelin/contracts/interfaces/IERC1363Receiver.sol";
struct InterestRate {
uint112 rate;
uint256 timestamp;
}
/// @title ICryndexSavings - Interface for the CryndexSavings contract
/// @notice Defines the external API for a savings contract where accounts deposit assets to earn interest
interface ICryndexSavings is IERC1363Receiver {
/// @notice Emitted when an account deposits tokens into the contract
/// @param account The account depositing tokens
/// @param asset The address of the asset
/// @param amount The amount of tokens deposited
/// @param timestamp The block timestamp of the swap event
event Deposit(
address account,
address asset,
uint256 amount,
uint256 timestamp
);
/// @notice Emitted when an account withdraws tokens from the contract
/// @param account The account withdrawing tokens
/// @param asset The address of the asset
/// @param amount The amount of tokens withdrawn
/// @param timestamp The block timestamp of the swap event
event Withdraw(
address account,
address asset,
uint256 amount,
uint256 timestamp
);
/// @notice Calculates the combined balance of all accounts for a given asset
/// @param asset The address of the asset
/// @return The balance of an asset held by the contract
function totalSavingsBalance(address asset) external view returns (uint256);
/// @notice Returns the balance for an account and asset
/// @param account The address of the account to query
/// @param asset The address of the asset to check
/// @return The balance of the account
function balanceOf(
address account,
address asset
) external view returns (uint256);
/// @notice Allows the governor to add new factories
/// @param factory The address of the new factory
function addFactory(address factory) external;
/// @notice Allows a factory to add new assets
/// @param asset The address of the new asset
/// @param rate The initial savings rate of the asset
function addAsset(address asset, uint112 rate) external;
/// @notice Adds a new savings rate for a specific asset, only callable by the governor
/// @param asset The asset for which the savings rate applies (e.g., an ERC20 token address)
/// @param rate The savings rate (scaled by 1e18, e.g., 1e18 = 1%)
function setSavingsRate(address asset, uint112 rate) external;
/// @notice Returns the savings rate for a specific asset at a given index
/// @param asset The address of the asset to query
/// @param idx The index of the savings rate to retrieve
/// @return Tuple containing (InterestRate struct, index)
function getSavingsRate(
address asset,
uint256 idx
) external view returns (InterestRate memory);
/// @notice Returns the current savings rate for a specific asset
/// @param asset The address of the asset to query
/// @return rate The current savings rate and its timestamp as an InterestRate struct
/// @return idx The index of the current savings rate
function getCurrentSavingsRate(
address asset
) external view returns (InterestRate memory, uint256);
/// @notice Allows an account to withdraw their savings
/// @param asset The address of the asset they wish to withdraw
/// @param amount The amount of tokens to withdraw
function withdraw(address asset, uint256 amount) external;
/// @notice Toggles whether or not the savings contract is accepting deposits
/// @return The new state of accepting deposits
function toggleAcceptingDeposits() external returns(bool);
}
Last updated