Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/oracles/UltraVaultOracle.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol";
import { IUltraVaultOracle, Price } from "src/interfaces/IUltraVaultOracle.sol";
import { IPriceSource } from "src/interfaces/IPriceSource.sol";
/// @title UltraVaultOracle
/// @notice Oracle for setting base/quote pair prices by permissioned entities
/// @dev Price safety and reliability handled by other contracts/infrastructure
contract UltraVaultOracle is Ownable2Step, IUltraVaultOracle {
///////////////
// Constants //
///////////////
string public constant name = "UltraVaultOracle";
uint256 public constant MIN_VESTING_TIME = 23 hours;
uint256 public constant MAX_VESTING_TIME = 7 days;
uint8 internal constant PRICE_FEED_DECIMALS = 18;
uint8 internal constant DEFAULT_DECIMALS = 18;
/////////////
// Storage //
/////////////
/// @dev Fetch price by [base][quote]
mapping(address => mapping(address => Price)) internal _prices;
/////////////////
// Constructor //
/////////////////
constructor(address _owner) Ownable(_owner) {}
/////////////////////
// Set Price Logic //
/////////////////////
function prices(
address base,
address quote
) external view returns (Price memory) {
return _prices[base][quote];
}
/// @notice Set base/quote pair price
/// @param base The base asset
/// @param quote The quote asset
/// @param price The price of the base in terms of the quote
function setPrice(
address base,
address quote,
uint256 price
) external onlyOwner {
_setPrice(base, quote, price);
}
/// @notice Set multiple base/quote pair prices
/// @param bases The base assets
/// @param quotes The quote assets
/// @param priceArray The prices of the bases in terms of the quotes
/// @dev Array lengths must match
function setPrices(
address[] memory bases,
address[] memory quotes,
uint256[] memory priceArray
) external onlyOwner {
_checkLength(bases.length, quotes.length);
_checkLength(bases.length, priceArray.length);
for (uint256 i = 0; i < bases.length; i++) {
_setPrice(bases[i], quotes[i], priceArray[i]);
}
}
function _setPrice(
address base,
address quote,
uint256 price
) internal {
_prices[base][quote] = Price({
price: price,
targetPrice: 0,
timestampForFullVesting: 0,
lastUpdatedTimestamp: block.timestamp
});
emit PriceUpdated(base, quote, price, price, 0);
}
//////////////////////////
// Vesting Price Update //
//////////////////////////
/// @notice Set base/quote pair price with gradual change
/// @param base The base asset
/// @param quote The quote asset
/// @param targetPrice The target price of the base in terms of the quote
/// @param vestingTime The time over which vesting would occur
function scheduleLinearPriceUpdate(
address base,
address quote,
uint256 targetPrice,
uint256 vestingTime
) external onlyOwner {
_scheduleLinearPriceUpdate(
base,
quote,
targetPrice,
vestingTime
);
}
/// @notice Set multiple base/quote pair prices with gradual changes
/// @param bases The base assets
/// @param quotes The quote assets
/// @param targetPrices The target prices of the bases in terms of the quotes
/// @param vestingTimes The times over which vesting would occur
/// @dev Array lengths must match
function scheduleLinearPricesUpdates(
address[] memory bases,
address[] memory quotes,
uint256[] memory targetPrices,
uint256[] memory vestingTimes
) external onlyOwner {
_checkLength(bases.length, quotes.length);
_checkLength(bases.length, targetPrices.length);
_checkLength(bases.length, vestingTimes.length);
for (uint256 i = 0; i < bases.length; i++) {
_scheduleLinearPriceUpdate(
bases[i],
quotes[i],
targetPrices[i],
vestingTimes[i]
);
}
}
function _scheduleLinearPriceUpdate(
address base,
address quote,
uint256 targetPrice,
uint256 vestingTime
) internal {
// We are scheduling updates at least over 23 hours for operator convenience
require(vestingTime >= MIN_VESTING_TIME && vestingTime <= MAX_VESTING_TIME, InvalidVestingTime(base, quote, vestingTime));
uint256 price = _getCurrentPrice(base, quote);
require(price != 0, ZeroVestingStartPrice(base, quote));
uint256 timestampForFullVesting = block.timestamp + vestingTime;
_prices[base][quote] = Price({
price: price,
targetPrice: targetPrice,
timestampForFullVesting: timestampForFullVesting,
lastUpdatedTimestamp: block.timestamp
});
emit PriceUpdated(
base,
quote,
price,
targetPrice,
timestampForFullVesting
);
}
///////////////////////
// Quote Calculation //
///////////////////////
/// @notice Get current price for base/quote pair
function getCurrentPrice(
address base,
address quote
) public view returns (uint256) {
return _getCurrentPrice(base, quote);
}
function _getCurrentPrice(
address base,
address quote
) internal view returns (uint256) {
Price memory price = _prices[base][quote];
if (price.timestampForFullVesting == 0) {
return price.price;
}
// The price if fully vested
if (block.timestamp >= price.timestampForFullVesting) {
return price.targetPrice;
}
bool increase = price.targetPrice >= price.price;
uint256 diff;
unchecked { diff = increase ? price.targetPrice - price.price : price.price - price.targetPrice; }
uint256 timeElapsed = block.timestamp - price.lastUpdatedTimestamp;
uint256 timeTotal = price.timestampForFullVesting - price.lastUpdatedTimestamp;
uint256 change = diff * timeElapsed / timeTotal;
return increase ? price.price + change : price.price - change;
}
/// @inheritdoc IPriceSource
function getQuote(
uint256 inAmount,
address base,
address quote
) external view returns (uint256) {
return _getQuote(inAmount, base, quote);
}
function _getQuote(
uint256 inAmount,
address base,
address quote
) internal view returns (uint256) {
uint256 price = _getCurrentPrice(base, quote);
require(price != 0, NoPriceData(base, quote));
// Assets decimals are within [6, 18], enforced by UltraVaultRateProvider
uint8 nominatorDecimals = _getDecimals(quote);
uint8 denominatorDecimals = _getDecimals(base) + PRICE_FEED_DECIMALS;
require(denominatorDecimals > nominatorDecimals, InvalidAssetsDecimals());
uint8 diff;
unchecked { diff = denominatorDecimals - nominatorDecimals; }
return inAmount * price / 10 ** diff;
}
///////////
// Utils //
///////////
/// @dev Check array lengths match
function _checkLength(uint256 lengthA, uint256 lengthB) internal pure {
require(lengthA == lengthB, InputLengthMismatch());
}
/// @notice Get asset decimals
/// @param asset Token address
/// @return The decimals of the asset
/// @dev Returns decimals if found, otherwise 18 (default)
function _getDecimals(address asset) internal view returns (uint8) {
(bool success, bytes memory data) =
address(asset).staticcall(abi.encodeCall(IERC20Metadata.decimals, ()));
return success && data.length == 32 ? abi.decode(data, (uint8)) : DEFAULT_DECIMALS;
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
"
},
"src/interfaces/IUltraVaultOracle.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0;
import { IPriceSource } from "./IPriceSource.sol";
/// @notice Price data for base/quote pair
/// @param price Current price
/// @param targetPrice Target price for gradual changes
/// @param timestampForFullVesting Target timestamp for full vesting
/// @param lastUpdatedTimestamp Last timestamp price was updated
struct Price {
uint256 price;
uint256 targetPrice;
uint256 timestampForFullVesting;
uint256 lastUpdatedTimestamp;
}
/// @title IUltraVaultOracle
/// @notice Interface for push-based price oracle
/// @dev Extends IPriceSource with price setting capabilities
interface IUltraVaultOracle is IPriceSource {
////////////
// Events //
////////////
event PriceUpdated(
address indexed base,
address indexed quote,
uint256 price,
uint256 targetPrice,
uint256 timestampForFullVesting
);
////////////
// Errors //
////////////
error NoPriceData(address base, address quote);
error InputLengthMismatch();
error InvalidVestingTime(address base, address quote, uint256 vestingTime);
error ZeroVestingStartPrice(address base, address quote);
error InvalidAssetsDecimals();
////////////////////
// View Functions //
////////////////////
/// @notice Get current price for base/quote pair
/// @param base The base asset
/// @param quote The quote asset
/// @return Current price of base in terms of quote
function getCurrentPrice(
address base,
address quote
) external view returns (uint256);
/// @notice Get price data for base/quote pair
/// @param base The base asset
/// @param quote The quote asset
/// @return Price data for the pair
function prices(
address base,
address quote
) external view returns (Price memory);
/////////////////////
// Write Functions //
/////////////////////
/// @notice Set base/quote pair price
/// @param base The base asset
/// @param quote The quote asset
/// @param price The price of the base in terms of the quote
function setPrice(
address base,
address quote,
uint256 price
) external;
/// @notice Set multiple base/quote pair prices
/// @param bases The base assets
/// @param quotes The quote assets
/// @param prices The prices of the bases in terms of the quotes
/// @dev Array lengths must match
function setPrices(
address[] memory bases,
address[] memory quotes,
uint256[] memory prices
) external;
/// @notice Set base/quote pair price with gradual change
/// @param base The base asset
/// @param quote The quote asset
/// @param targetPrice The target price of the base in terms of the quote
/// @param vestingTime The time over which vesting would occur
function scheduleLinearPriceUpdate(
address base,
address quote,
uint256 targetPrice,
uint256 vestingTime
) external;
/// @notice Set multiple base/quote pair prices with gradual changes
/// @param bases The base assets
/// @param quotes The quote assets
/// @param targetPrices The target prices of the bases in terms of the quotes
/// @param vestingTimes The times over which vesting would occur
/// @dev Array lengths must match
function scheduleLinearPricesUpdates(
address[] memory bases,
address[] memory quotes,
uint256[] memory targetPrices,
uint256[] memory vestingTimes
) external;
}
"
},
"src/interfaces/IPriceSource.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0;
interface IPriceSource {
/// @notice Get one-sided price quote
/// @param inAmount Amount of base token to convert
/// @param base Token being priced
/// @param quote Token used as unit of account
/// @return outAmount Amount of quote token equivalent to inAmount of base
/// @dev Assumes no price spread
function getQuote(
uint256 inAmount,
address base,
address quote
) external view returns (uint256 outAmount);
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
"
}
},
"settings": {
"remappings": [
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"solady/=lib/solady/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"ERC-7540/=lib/ERC-7540-Reference/src/",
"ERC-7540-Reference/=lib/ERC-7540-Reference/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/",
"solmate/=lib/ERC-7540-Reference/lib/solmate/src/"
],
"optimizer": {
"enabled": true,
"runs": 50
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false
}
}}
Submitted on: 2025-11-04 12:46:36
Comments
Log in to comment.
No comments yet.