编译器
0.8.19+commit.7dd6d404
文件 1 的 10:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
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");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
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");
}
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);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
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);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
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);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
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 {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 2 的 10:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 10:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
文件 4 的 10:IERC20Permit.sol
pragma solidity ^0.8.0;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
文件 5 的 10:IVault.sol
pragma solidity 0.8.19;
interface IVault {
function totalDepositedAsset() external view returns (uint256);
function depositedAsset(address user) external view returns (uint256);
function getBorrowedOf(address user) external view returns (uint256);
function getPoolTotalCirculation() external view returns (uint256);
function getAsset() external view returns (address);
function burn(address onBehalfOf, uint256 amount) external;
function collateralAsset() external view returns (address);
function getAssetToUnderlyingRate() external view returns (uint256);
function isDepegged() external view returns (bool);
function getMarketRate() external view returns (uint256);
function getAssetPrice() external view returns (uint256);
function calculateRedemption(address provider, uint256 nusdAmount) external view returns (uint256 providerFee, uint256 protocolFee, uint256 nusdToProtocol, uint256 nusdToRepay, uint256 nusdToConvert, uint256 collateralReceived);
function getRedeemableAmount(address provider) external view returns (uint256);
function getCollateralRatio(address user) external view returns (uint256);
function getOriginationFee(uint256 amount) external view returns (uint256);
}
文件 6 的 10:Initializable.sol
pragma solidity ^0.8.2;
import "../../utils/Address.sol";
abstract contract Initializable {
uint8 private _initialized;
bool private _initializing;
event Initialized(uint8 version);
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
文件 7 的 10:IsnUSD.sol
pragma solidity 0.8.19;
interface IsnUSD {
event RewardsReceived(uint256 indexed amount, uint256 newVestingnUSDAmount);
event LockedAmountRedistributed(address indexed from, address indexed to, uint256 amount);
error InvalidAmount();
error InvalidToken();
error SlippageExceeded();
error MinSharesViolation();
error OperationNotAllowed();
error StillVesting();
error InvalidZeroAddress();
function transferInRewards(uint256 amount) external;
function rescueTokens(address token, uint256 amount, address to) external;
function getUnvestedAmount() external view returns (uint256);
}
文件 8 的 10:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 9 的 10:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
文件 10 的 10:UnstableConfigurator.sol
pragma solidity 0.8.19;
import "contracts/unstable/interfaces/IsnUSD.sol";
import "contracts/unstable/interfaces/IVault.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract UnstableConfigurator is Ownable {
using SafeERC20 for IERC20;
struct OriginationFeeConfig {
uint16 minOriginationFee;
uint16 maxOriginationFee;
}
struct RedemptionConfig {
bool enabled;
uint16 baseFee;
uint16 maxMultiplier;
uint16 maxCollateralRatio;
uint16 providerShare;
}
address[] vaults;
mapping(address => bool) public collateralEnabled;
address[] collaterals;
mapping(address => address) public zkOracleAddress;
mapping(address => bool) public vaultEnabled;
mapping(address => uint256) public mintVaultMaxSupply;
mapping(address => uint16) vaultBadCollateralRatio;
mapping(address => uint16) vaultSafeCollateralRatio;
mapping(address => uint16) public borrowApr;
mapping(address => uint16) public vaultKeeperRatio;
mapping(address => uint16) depegThreshold;
mapping(address => bool) public useMarketRate;
mapping(address => OriginationFeeConfig) public vaultOriginationFee;
mapping(address => RedemptionConfig) public vaultRedemptionConfig;
mapping(address => bool) public vaultMintPaused;
mapping(address => bool) public vaultBurnPaused;
mapping(address => bool) public rewardManager;
uint16 public flashloanFee;
uint16 public immutable defaultSafeCollateralRatio;
uint16 public immutable defaultBadCollateralRatioDistance;
OriginationFeeConfig public defaultOriginationFee;
RedemptionConfig public defaultRedemptionConfig;
uint16 public immutable defaultKeeperReward;
uint16 public immutable defaultDepegThreshold;
address public admin;
address public treasury;
IERC20 public nUSD;
IsnUSD public snUSD;
address public etherOracle;
event AdminChanged(address newAdmin);
event nUSDSet(address indexed nUSD);
event snUSDSet(address indexed newAddr);
event EtherOracleChanged(address newAddr);
event TreasuryChanged(address newTreasury);
event ZkOracleSet(address indexed vault, address zkOracle);
event ZkOracleChanged(address indexed vault, address zkOracle);
event VaultEnabled(address indexed vault);
event VaultMintPaused(address indexed vault, bool paused);
event VaultBurnPaused(address indexed vault, bool paused);
event DepegThresholdUpdated(address indexed vault, uint16 threshold);
event UseMarketRateChanged(address indexed vault, bool useMarketRate);
event MintVaultMaxSupplyChanged(address indexed vault, uint256 maxSupply);
event BadCollateralRatioChanged(address indexed vault, uint16 newRatio);
event SafeCollateralRatioChanged(address indexed vault, uint16 newRatio);
event BorrowAprChanged(address indexed vault, uint16 newApr);
event KeeperRewardChanged(address indexed vault, uint16 newReward);
event OriginationFeeChanged(address indexed vault, uint16 minOriginationFee, uint16 maxOriginationFee);
event RedemptionConfigChanged(address indexed vault, bool enabled, uint16 baseFee, uint16 maxMultiplier, uint16 maxCollateralRatio, uint16 providerShare);
event FeesDistributed(uint256 amount);
event FlashloanFeeUpdated(uint16 fee);
event TokensWithdrawn(address tokenAddress, address to, uint256 amount);
event RewardManagerSet(address managerAddress);
event RewardManagerRemoved(address managerAddress);
constructor(address _etherOracle) {
flashloanFee = 500;
defaultSafeCollateralRatio = 150_00;
defaultBadCollateralRatioDistance = 15_00;
defaultOriginationFee = OriginationFeeConfig(0, 1000);
defaultKeeperReward = 500;
defaultDepegThreshold = 300;
defaultRedemptionConfig = RedemptionConfig(true, 100, 3, 200_00, 75_00);
etherOracle = _etherOracle;
}
modifier onlyOwnerOrAdmin {
require(msg.sender == owner() || msg.sender == admin, "Only owner or admin can call this");
_;
}
function setAdmin(address _admin) external onlyOwner {
admin = _admin;
emit AdminChanged(_admin);
}
function setTreasury(address _treasury) external onlyOwner {
treasury = _treasury;
emit TreasuryChanged(_treasury);
}
function setRewardManager(address _rewardManager) external onlyOwner {
require(_rewardManager != address(0), "Reward manager cannot be the zero address");
if (!rewardManager[_rewardManager]) {
rewardManager[_rewardManager] = true;
emit RewardManagerSet(_rewardManager);
}
}
function removeRewardManager(address _rewardManager) external onlyOwner {
if (rewardManager[_rewardManager]) {
rewardManager[_rewardManager] = false;
emit RewardManagerRemoved(_rewardManager);
}
}
function setnUSD(address _nUSD) external onlyOwner {
if (address(nUSD) == address(0)) nUSD = IERC20(_nUSD);
emit nUSDSet(_nUSD);
}
function setsnUSD(address _snUSD) external onlyOwner {
if (address(snUSD) == address(0)) snUSD = IsnUSD(_snUSD);
IERC20(_snUSD).approve(address(nUSD), type(uint256).max);
emit snUSDSet(_snUSD);
}
function updateEtherOracle(address _etherOracle) external onlyOwner {
etherOracle = _etherOracle;
emit EtherOracleChanged(_etherOracle);
}
function setZkOracle(address collateral, address zkOracle) external onlyOwner {
require(zkOracleAddress[collateral] == address(0), "ZkOracle already set");
require(zkOracle != address(0), "ZkOracle cannot be zero address");
zkOracleAddress[collateral] = zkOracle;
emit ZkOracleSet(collateral, zkOracle);
}
function updateZkOracle(address collateral, address zkOracle) external onlyOwner {
require(zkOracle != address(0), "ZkOracle cannot be zero address");
zkOracleAddress[collateral] = zkOracle;
emit ZkOracleChanged(collateral, zkOracle);
}
function enableVault(address vault) external onlyOwner {
require(!vaultEnabled[vault], "Vault already enabled");
address collateral = IVault(vault).collateralAsset();
require(zkOracleAddress[collateral] != address(0), "Set zkOracle before activating vault");
require(IVault(vault).getAssetPrice() > 0, "Price oracle not working");
vaultEnabled[vault] = true;
vaults.push();
if(collateralEnabled[collateral] == false) {
collaterals.push(collateral);
collateralEnabled[collateral] = true;
}
emit VaultEnabled(vault);
}
function setVaultMintPaused(address vault, bool isActive) external onlyOwnerOrAdmin {
vaultMintPaused[vault] = isActive;
emit VaultMintPaused(vault, isActive);
}
function setVaultBurnPaused(address vault, bool isActive) external onlyOwnerOrAdmin {
vaultBurnPaused[vault] = isActive;
emit VaultBurnPaused(vault, isActive);
}
function setDepegThreshold(address vault, uint16 threshold) external onlyOwner {
require(threshold <= 20_00, "Threshold too high");
depegThreshold[vault] = threshold;
emit DepegThresholdUpdated(vault, threshold);
}
function setUseMarketRate(address vault, bool _useMarketRate) external onlyOwner {
if(_useMarketRate) {
require(IVault(vault).getMarketRate() > 0, "Invalid market rate");
}
useMarketRate[vault] = _useMarketRate;
emit UseMarketRateChanged(vault, _useMarketRate);
}
function setMintVaultMaxSupply(address vault, uint256 maxSupply) external onlyOwner {
mintVaultMaxSupply[vault] = maxSupply;
emit MintVaultMaxSupplyChanged(vault, maxSupply);
}
function setBadCollateralRatio(address vault, uint16 newRatio) external onlyOwner {
require(newRatio <= vaultSafeCollateralRatio[vault] - 10_00, "config too high");
require(newRatio >= 110_00 && newRatio <= 200_00, "config out of range");
vaultBadCollateralRatio[vault] = newRatio;
emit BadCollateralRatioChanged(vault, newRatio);
}
function setSafeCollateralRatio(address vault, uint16 newRatio) external onlyOwner {
require(newRatio >= vaultBadCollateralRatio[vault] + 10_00, "config too low");
require(newRatio >= 120_00, "config too low");
vaultSafeCollateralRatio[vault] = newRatio;
emit SafeCollateralRatioChanged(vault, newRatio);
}
function setBorrowApr(address vault, uint16 newApr) external onlyOwner {
require(newApr <= 1000_00, "Borrow APR cannot exceed 1000%");
borrowApr[vault] = newApr;
emit BorrowAprChanged(vault, newApr);
}
function setKeeperReward(address vault, uint16 newReward) external onlyOwner {
require(newReward <= 500, "Max Keeper reward is 5%");
vaultKeeperRatio[vault] = newReward;
emit KeeperRewardChanged(vault, newReward);
}
function setRedemptionFee(address vault, bool enabled, uint16 baseFee, uint16 maxMultiplier, uint16 maxCollateralRatio, uint16 providerShare) external onlyOwner {
require(baseFee <= 10_00, "Max Redemption Fee is 10%");
require(maxMultiplier <= 100_000, "Max multiplier is 10x");
require(maxCollateralRatio >= 150_00 && maxCollateralRatio <= 300_00, "Cr for max multiplier must be 150%-300%");
require(providerShare >= 50_00 && providerShare <= 100_00, "Provider share must be 50%-100%");
vaultRedemptionConfig[vault] = RedemptionConfig(enabled, baseFee, maxMultiplier, maxCollateralRatio, providerShare);
emit RedemptionConfigChanged(vault, enabled, baseFee, maxMultiplier, maxCollateralRatio, providerShare);
}
function setOriginationFee(address vault, uint16 minOriginationFee, uint16 maxOriginationFee) external onlyOwner {
require(minOriginationFee <= maxOriginationFee, "Min fee cannot exceed max fee");
require(maxOriginationFee <= 10_00, "Origination fee cannot exceed 10%");
vaultOriginationFee[vault] = OriginationFeeConfig(minOriginationFee, maxOriginationFee);
emit OriginationFeeChanged(vault, minOriginationFee, maxOriginationFee);
}
function setFlashloanFee(uint16 fee) external onlyOwner {
require(fee <= 100_00, "Fee cannot exceed 100%");
emit FlashloanFeeUpdated(fee);
flashloanFee = fee;
}
function withdrawTokens(address tokenAddress, address to, uint256 amount) external onlyOwner {
require(amount > IERC20(tokenAddress).balanceOf(address(this)), "Amount exceeds balance");
IERC20(tokenAddress).safeTransfer(to, amount);
emit TokensWithdrawn(tokenAddress, to, amount);
}
function distributeFees() external onlyOwnerOrAdmin {
uint256 nusdBalance = nUSD.balanceOf(address(this));
require(nusdBalance > 0, "No fees to distribute");
uint256 snUsdRewards = nusdBalance / 2;
snUSD.transferInRewards(snUsdRewards);
nUSD.transfer(treasury, nusdBalance - snUsdRewards);
emit FeesDistributed(nusdBalance);
}
function getAllVaults() external view returns (address[] memory) {
return vaults;
}
function getAllCollaterals() external view returns (address[] memory) {
return collaterals;
}
function getSafeCollateralRatio(address vault) public view returns (uint16) {
if (vaultSafeCollateralRatio[vault] == 0) return defaultSafeCollateralRatio;
return vaultSafeCollateralRatio[vault];
}
function getBadCollateralRatio(address vault) public view returns(uint16) {
if(vaultBadCollateralRatio[vault] == 0) return getSafeCollateralRatio(vault) - defaultBadCollateralRatioDistance;
return vaultBadCollateralRatio[vault];
}
function getOriginationFee(address vault) external view returns(uint256 minOriginationFee, uint256 maxOriginationFee) {
OriginationFeeConfig memory config = vaultOriginationFee[vault];
if(config.minOriginationFee == 0 && config.maxOriginationFee == 0) return (defaultOriginationFee.minOriginationFee, defaultOriginationFee.maxOriginationFee);
else return (config.minOriginationFee, config.maxOriginationFee);
}
function getRedemptionConfig(address vault) public view returns(RedemptionConfig memory) {
RedemptionConfig memory config = vaultRedemptionConfig[vault];
if(config.enabled == false && config.providerShare == 0 && config.baseFee == 0 && config.maxCollateralRatio == 0 && config.maxMultiplier == 0) {
return defaultRedemptionConfig;
}
else return config;
}
function getRedemptionFee(address vault, uint256 collateralRatio) external view returns(uint256 providerFee, uint256 protocolFee) {
require(vaultEnabled[vault], "Vault not enabled");
require(collateralRatio >= 100_00, "Cannot redeem when collateral ratio is below 100%");
RedemptionConfig memory config = getRedemptionConfig(vault);
require(collateralRatio <= config.maxCollateralRatio, "Cannot redeem collateral ratio above max");
uint16 badCollateralRatio = getBadCollateralRatio(vault);
uint16 safeCollateralRatio = getSafeCollateralRatio(vault);
uint16 providerShare = 80_00;
uint256 totalFee;
if(collateralRatio <= badCollateralRatio) {
totalFee = config.baseFee;
providerFee = 0;
protocolFee = totalFee;
}
else if(collateralRatio <= safeCollateralRatio) {
totalFee = config.baseFee;
providerFee = totalFee * providerShare * (collateralRatio-badCollateralRatio) / (safeCollateralRatio-badCollateralRatio) / 100_00;
}
else if(collateralRatio > config.maxCollateralRatio) {
totalFee = config.baseFee * config.maxMultiplier / 100_00;
providerFee = totalFee * providerShare / 100_00;
}
else {
totalFee = config.baseFee * (100_00 + (config.maxMultiplier-100_00) * (collateralRatio-safeCollateralRatio) / (config.maxCollateralRatio -safeCollateralRatio)) / 100_00;
providerFee = totalFee * providerShare / 100_00;
}
protocolFee = totalFee - providerFee;
}
function getDepegThreshold(address vault) external view returns(uint256) {
if(depegThreshold[vault] == 0) return defaultDepegThreshold;
return depegThreshold[vault];
}
function getKeeperReward(address vault) external view returns(uint256) {
if(vaultKeeperRatio[vault] == 0) return defaultKeeperReward;
return vaultKeeperRatio[vault];
}
function isRewardManager(address user) external view returns(bool) {
return rewardManager[user] || user == owner();
}
}
{
"compilationTarget": {
"contracts/unstable/configuration/UnstableConfigurator.sol": "UnstableConfigurator"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 9999
},
"remappings": [
":@chainlink/=node_modules/@chainlink/",
":@ensdomains/=node_modules/@ensdomains/",
":@eth-optimism/=node_modules/@eth-optimism/",
":@ethereum-waffle/=node_modules/@ethereum-waffle/",
":@layerzerolabs/=node_modules/@layerzerolabs/",
":@openzeppelin-3/=node_modules/@openzeppelin-3/",
":@openzeppelin/=node_modules/@openzeppelin/",
":@redstone-finance/=node_modules/@redstone-finance/",
":@uniswap/=node_modules/@uniswap/",
":erc721a/=node_modules/erc721a/",
":eth-gas-reporter/=node_modules/eth-gas-reporter/",
":forge-std/=lib/forge-std/src/",
":hardhat-deploy/=node_modules/hardhat-deploy/",
":hardhat/=node_modules/hardhat/"
]
}
[{"inputs":[{"internalType":"address","name":"_etherOracle","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint16","name":"newRatio","type":"uint16"}],"name":"BadCollateralRatioChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint16","name":"newApr","type":"uint16"}],"name":"BorrowAprChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint16","name":"threshold","type":"uint16"}],"name":"DepegThresholdUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newAddr","type":"address"}],"name":"EtherOracleChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FeesDistributed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"fee","type":"uint16"}],"name":"FlashloanFeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint16","name":"newReward","type":"uint16"}],"name":"KeeperRewardChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint256","name":"maxSupply","type":"uint256"}],"name":"MintVaultMaxSupplyChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint16","name":"minOriginationFee","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"maxOriginationFee","type":"uint16"}],"name":"OriginationFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"},{"indexed":false,"internalType":"uint16","name":"baseFee","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"maxMultiplier","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"maxCollateralRatio","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"providerShare","type":"uint16"}],"name":"RedemptionConfigChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"managerAddress","type":"address"}],"name":"RewardManagerRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"managerAddress","type":"address"}],"name":"RewardManagerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint16","name":"newRatio","type":"uint16"}],"name":"SafeCollateralRatioChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TokensWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newTreasury","type":"address"}],"name":"TreasuryChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"bool","name":"useMarketRate","type":"bool"}],"name":"UseMarketRateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"bool","name":"paused","type":"bool"}],"name":"VaultBurnPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"}],"name":"VaultEnabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"bool","name":"paused","type":"bool"}],"name":"VaultMintPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"address","name":"zkOracle","type":"address"}],"name":"ZkOracleChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"address","name":"zkOracle","type":"address"}],"name":"ZkOracleSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nUSD","type":"address"}],"name":"nUSDSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAddr","type":"address"}],"name":"snUSDSet","type":"event"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"borrowApr","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"collateralEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultBadCollateralRatioDistance","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultDepegThreshold","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultKeeperReward","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultOriginationFee","outputs":[{"internalType":"uint16","name":"minOriginationFee","type":"uint16"},{"internalType":"uint16","name":"maxOriginationFee","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultRedemptionConfig","outputs":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"uint16","name":"baseFee","type":"uint16"},{"internalType":"uint16","name":"maxMultiplier","type":"uint16"},{"internalType":"uint16","name":"maxCollateralRatio","type":"uint16"},{"internalType":"uint16","name":"providerShare","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultSafeCollateralRatio","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"distributeFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"enableVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"etherOracle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"flashloanFee","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllCollaterals","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllVaults","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getBadCollateralRatio","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getDepegThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getKeeperReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getOriginationFee","outputs":[{"internalType":"uint256","name":"minOriginationFee","type":"uint256"},{"internalType":"uint256","name":"maxOriginationFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getRedemptionConfig","outputs":[{"components":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"uint16","name":"baseFee","type":"uint16"},{"internalType":"uint16","name":"maxMultiplier","type":"uint16"},{"internalType":"uint16","name":"maxCollateralRatio","type":"uint16"},{"internalType":"uint16","name":"providerShare","type":"uint16"}],"internalType":"struct UnstableConfigurator.RedemptionConfig","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint256","name":"collateralRatio","type":"uint256"}],"name":"getRedemptionFee","outputs":[{"internalType":"uint256","name":"providerFee","type":"uint256"},{"internalType":"uint256","name":"protocolFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getSafeCollateralRatio","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isRewardManager","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"mintVaultMaxSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nUSD","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardManager","type":"address"}],"name":"removeRewardManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardManager","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_admin","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint16","name":"newRatio","type":"uint16"}],"name":"setBadCollateralRatio","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint16","name":"newApr","type":"uint16"}],"name":"setBorrowApr","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint16","name":"threshold","type":"uint16"}],"name":"setDepegThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"fee","type":"uint16"}],"name":"setFlashloanFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint16","name":"newReward","type":"uint16"}],"name":"setKeeperReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint256","name":"maxSupply","type":"uint256"}],"name":"setMintVaultMaxSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint16","name":"minOriginationFee","type":"uint16"},{"internalType":"uint16","name":"maxOriginationFee","type":"uint16"}],"name":"setOriginationFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"uint16","name":"baseFee","type":"uint16"},{"internalType":"uint16","name":"maxMultiplier","type":"uint16"},{"internalType":"uint16","name":"maxCollateralRatio","type":"uint16"},{"internalType":"uint16","name":"providerShare","type":"uint16"}],"name":"setRedemptionFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardManager","type":"address"}],"name":"setRewardManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint16","name":"newRatio","type":"uint16"}],"name":"setSafeCollateralRatio","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_treasury","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"bool","name":"_useMarketRate","type":"bool"}],"name":"setUseMarketRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"bool","name":"isActive","type":"bool"}],"name":"setVaultBurnPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"bool","name":"isActive","type":"bool"}],"name":"setVaultMintPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"address","name":"zkOracle","type":"address"}],"name":"setZkOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nUSD","type":"address"}],"name":"setnUSD","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_snUSD","type":"address"}],"name":"setsnUSD","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"snUSD","outputs":[{"internalType":"contract IsnUSD","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_etherOracle","type":"address"}],"name":"updateEtherOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"address","name":"zkOracle","type":"address"}],"name":"updateZkOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"useMarketRate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaultBurnPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaultEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaultKeeperRatio","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaultMintPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaultOriginationFee","outputs":[{"internalType":"uint16","name":"minOriginationFee","type":"uint16"},{"internalType":"uint16","name":"maxOriginationFee","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaultRedemptionConfig","outputs":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"uint16","name":"baseFee","type":"uint16"},{"internalType":"uint16","name":"maxMultiplier","type":"uint16"},{"internalType":"uint16","name":"maxCollateralRatio","type":"uint16"},{"internalType":"uint16","name":"providerShare","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"zkOracleAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]