Source Code
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
DebtController
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 100000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./IDebtController.sol";
contract DebtController is Ownable, IDebtController {
error InvalidValue();
uint256 public constant LEVERAGE_DENOMINATOR = 100;
uint256 public constant APY_DENOMINATOR = 100;
uint256 public maxApy; // 300% APR will be 300
uint256 public maxLeverage; // e.g. 3x leverage = 300
uint256 public liquidationThreshold;
/// @dev creates a new DebtController
/// @param _maxApy the max apy
/// @param _maxLeverage the max leverage
constructor(uint256 _maxApy, uint256 _maxLeverage) Ownable(msg.sender) {
maxApy = _maxApy;
maxLeverage = _maxLeverage;
// liquidationThreshold = _liquidationThreshold;
}
/// @inheritdoc IDebtController
function computeMaxInterest(
address,
uint256 _principal,
uint256 _lastFundingTimestamp
) public view returns(uint256 maxInterestToPay) {
uint256 secondsSince = block.timestamp - _lastFundingTimestamp;
maxInterestToPay = _principal * maxApy * secondsSince / (APY_DENOMINATOR * (365 days));
}
/// @inheritdoc IDebtController
function computeMaxPrincipal(
address,
address,
uint256 _downPayment
) external view returns (uint256 maxPrincipal) {
maxPrincipal = _downPayment * (maxLeverage - LEVERAGE_DENOMINATOR) / LEVERAGE_DENOMINATOR;
}
/// @dev sets the maximum leverage
/// @param _maxLeverage the max leverage
function setMaxLeverage(uint256 _maxLeverage) external onlyOwner {
if (_maxLeverage == 0) revert InvalidValue();
if (_maxLeverage > 100 * LEVERAGE_DENOMINATOR) revert InvalidValue(); // 100x leverage
maxLeverage = _maxLeverage;
}
/// @dev sets the maximum apy
/// @param _maxApy the max APY
function setMaxDailyAPY(uint256 _maxApy) external onlyOwner {
if (_maxApy == 0) revert InvalidValue();
if (_maxApy > 1000 * APY_DENOMINATOR) revert InvalidValue(); // 1000% APR
maxApy = _maxApy;
}
/// @dev sets the liquidation threshold
/// @param _liquidationThreshold the liquidation threshold
function setLiquidationThreshold(uint256 _liquidationThreshold) external onlyOwner {
if (_liquidationThreshold == 0) revert InvalidValue();
liquidationThreshold = _liquidationThreshold;
}
}// 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);
}
}// 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;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
interface IDebtController {
/// @dev Computes the maximum interest
/// @param _tokenAddress the token address
/// @param _principal the principal borrowed
/// @param _lastFundingTimestamp the timestamp where the loan was last funded
/// @return maxInterest the maximum interest amount to pay for the loan
function computeMaxInterest(
address _tokenAddress,
uint256 _principal,
uint256 _lastFundingTimestamp
) external view returns(uint256 maxInterest);
/// @dev Computes the maximum principal
/// @param _collateralToken the collateral token address
/// @param _principalToken the principal token address
/// @param _downPayment the down payment the trader is paying
/// @return maxPrincipal the maximum principal allowed to be borrowed
function computeMaxPrincipal(
address _collateralToken,
address _principalToken,
uint256 _downPayment
) external view returns (uint256 maxPrincipal);
// function computeLiquidationThreshold(
// address _collateralToken,
// address _principalToken,
// uint256 _collateralAmount
// ) external view returns (uint256 liquidationThreshold);
}{
"optimizer": {
"enabled": true,
"runs": 100000
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"uint256","name":"_maxApy","type":"uint256"},{"internalType":"uint256","name":"_maxLeverage","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidValue","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"APY_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LEVERAGE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"_principal","type":"uint256"},{"internalType":"uint256","name":"_lastFundingTimestamp","type":"uint256"}],"name":"computeMaxInterest","outputs":[{"internalType":"uint256","name":"maxInterestToPay","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"_downPayment","type":"uint256"}],"name":"computeMaxPrincipal","outputs":[{"internalType":"uint256","name":"maxPrincipal","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidationThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxApy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLeverage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_liquidationThreshold","type":"uint256"}],"name":"setLiquidationThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxApy","type":"uint256"}],"name":"setMaxDailyAPY","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxLeverage","type":"uint256"}],"name":"setMaxLeverage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b5060405161076d38038061076d83398101604081905261002f916100bd565b338061005557604051631e4fbdf760e01b81526000600482015260240160405180910390fd5b61005e8161006d565b506001919091556002556100e1565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080604083850312156100d057600080fd5b505080516020909101519092909150565b61067d806100f06000396000f3fe608060405234801561001057600080fd5b50600436106100df5760003560e01c80639f54227a1161008c578063d3127e6311610066578063d3127e631461017c578063e0700c901461018f578063f2fde38b146101a2578063f3482ee6146101b557600080fd5b80639f54227a1461014d578063ae3302c214610160578063d0b0c8161461016957600080fd5b8063715018a6116100bd578063715018a61461011d57806382f17f66146101155780638da5cb5b1461012557600080fd5b806314cb8815146100e45780634031234c146100f95780636e33bfbe14610115575b600080fd5b6100f76100f23660046104da565b6101be565b005b61010260035481565b6040519081526020015b60405180910390f35b610102606481565b6100f761024b565b60005460405173ffffffffffffffffffffffffffffffffffffffff909116815260200161010c565b61010261015b36600461051c565b61025f565b61010260025481565b6100f76101773660046104da565b61028d565b6100f761018a3660046104da565b6102d4565b61010261019d366004610558565b61035f565b6100f76101b036600461058b565b6103a9565b61010260015481565b6101c6610412565b80600003610200576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61020d60646103e86105dc565b811115610246576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600155565b610253610412565b61025d6000610465565b565b600060648060025461027191906105f9565b61027b90846105dc565b610285919061060c565b949350505050565b610295610412565b806000036102cf576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600355565b6102dc610412565b80600003610316576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6103216064806105dc565b81111561035a576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600255565b60008061036c83426105f9565b905061037d60646301e133806105dc565b816001548661038c91906105dc565b61039691906105dc565b6103a0919061060c565b95945050505050565b6103b1610412565b73ffffffffffffffffffffffffffffffffffffffff8116610406576040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600060048201526024015b60405180910390fd5b61040f81610465565b50565b60005473ffffffffffffffffffffffffffffffffffffffff16331461025d576040517f118cdaa70000000000000000000000000000000000000000000000000000000081523360048201526024016103fd565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156104ec57600080fd5b5035919050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461051757600080fd5b919050565b60008060006060848603121561053157600080fd5b61053a846104f3565b9250610548602085016104f3565b9150604084013590509250925092565b60008060006060848603121561056d57600080fd5b610576846104f3565b95602085013595506040909401359392505050565b60006020828403121561059d57600080fd5b6105a6826104f3565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b80820281158282048414176105f3576105f36105ad565b92915050565b818103818111156105f3576105f36105ad565b600082610642577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b50049056fea2646970667358221220a442853de5366a6b5d4581ce8c1c5c876432dae4926146fdf7b1a76bd399ca4564736f6c63430008170033000000000000000000000000000000000000000000000000000000000000012c00000000000000000000000000000000000000000000000000000000000001f4
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100df5760003560e01c80639f54227a1161008c578063d3127e6311610066578063d3127e631461017c578063e0700c901461018f578063f2fde38b146101a2578063f3482ee6146101b557600080fd5b80639f54227a1461014d578063ae3302c214610160578063d0b0c8161461016957600080fd5b8063715018a6116100bd578063715018a61461011d57806382f17f66146101155780638da5cb5b1461012557600080fd5b806314cb8815146100e45780634031234c146100f95780636e33bfbe14610115575b600080fd5b6100f76100f23660046104da565b6101be565b005b61010260035481565b6040519081526020015b60405180910390f35b610102606481565b6100f761024b565b60005460405173ffffffffffffffffffffffffffffffffffffffff909116815260200161010c565b61010261015b36600461051c565b61025f565b61010260025481565b6100f76101773660046104da565b61028d565b6100f761018a3660046104da565b6102d4565b61010261019d366004610558565b61035f565b6100f76101b036600461058b565b6103a9565b61010260015481565b6101c6610412565b80600003610200576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61020d60646103e86105dc565b811115610246576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600155565b610253610412565b61025d6000610465565b565b600060648060025461027191906105f9565b61027b90846105dc565b610285919061060c565b949350505050565b610295610412565b806000036102cf576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600355565b6102dc610412565b80600003610316576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6103216064806105dc565b81111561035a576040517faa7feadc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600255565b60008061036c83426105f9565b905061037d60646301e133806105dc565b816001548661038c91906105dc565b61039691906105dc565b6103a0919061060c565b95945050505050565b6103b1610412565b73ffffffffffffffffffffffffffffffffffffffff8116610406576040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600060048201526024015b60405180910390fd5b61040f81610465565b50565b60005473ffffffffffffffffffffffffffffffffffffffff16331461025d576040517f118cdaa70000000000000000000000000000000000000000000000000000000081523360048201526024016103fd565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156104ec57600080fd5b5035919050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461051757600080fd5b919050565b60008060006060848603121561053157600080fd5b61053a846104f3565b9250610548602085016104f3565b9150604084013590509250925092565b60008060006060848603121561056d57600080fd5b610576846104f3565b95602085013595506040909401359392505050565b60006020828403121561059d57600080fd5b6105a6826104f3565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b80820281158282048414176105f3576105f36105ad565b92915050565b818103818111156105f3576105f36105ad565b600082610642577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b50049056fea2646970667358221220a442853de5366a6b5d4581ce8c1c5c876432dae4926146fdf7b1a76bd399ca4564736f6c63430008170033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000000000000000012c00000000000000000000000000000000000000000000000000000000000001f4
-----Decoded View---------------
Arg [0] : _maxApy (uint256): 300
Arg [1] : _maxLeverage (uint256): 500
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000000000000000000000000000000000000000012c
Arg [1] : 00000000000000000000000000000000000000000000000000000000000001f4
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.