ETH Price: $3,616.34 (-2.88%)

Contract

0xaAACB8C39Bd5Acbb0A236112Df8d15411161e518
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Age:180D
Reset Filter

Transaction Hash
Method
Block
From
To

There are no matching entries

Update your filters to view other transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
TroveManagerHelpers

Compiler Version
v0.8.14+commit.80d49f37

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 33 : TroveManagerHelpers.sol
//SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "@openzeppelin/contracts/access/Ownable.sol";
import "./Interfaces/ITroveManagerHelpers.sol";
import "./Dependencies/DfrancBase.sol";
import "./Dependencies/CheckContract.sol";
import "./Dependencies/Initializable.sol";
import "./TroveManager.sol";

contract TroveManagerHelpers is
	DfrancBase,
	CheckContract,
	Initializable,
	ITroveManagerHelpers
{
	using SafeMath for uint256;
	string public constant NAME = "TroveManagerHelpers";

	// --- Connected contract declarations ---

	address public borrowerOperationsAddress;
	address public troveManagerAddress;

	IDCHFToken public dchfToken;

	// A doubly linked list of Troves, sorted by their sorted by their collateral ratios
	ISortedTroves public sortedTroves;

	// --- Data structures ---

	uint256 public constant SECONDS_IN_ONE_MINUTE = 60;
	/*
	 * Half-life of 12h. 12h = 720 min
	 * (1/2) = d^720 => d = (1/2)^(1/720)
	 */
	uint256 public constant MINUTE_DECAY_FACTOR = 999037758833783000;

	/*
	 * BETA: 18 digit decimal. Parameter by which to divide the redeemed fraction, in order to calc the new base rate from a redemption.
	 * Corresponds to (1 / ALPHA) in the white paper.
	 */
	uint256 public constant BETA = 2;

	mapping(address => uint256) public baseRate;

	// The timestamp of the latest fee operation (redemption or new DCHF issuance)
	mapping(address => uint256) public lastFeeOperationTime;

	mapping(address => mapping(address => Trove)) public Troves;

	mapping(address => uint256) public totalStakes;

	// Snapshot of the value of totalStakes, taken immediately after the latest liquidation
	mapping(address => uint256) public totalStakesSnapshot;

	// Snapshot of the total collateral across the ActivePool and DefaultPool, immediately after the latest liquidation.
	mapping(address => uint256) public totalCollateralSnapshot;

	/*
	 * L_ETH and L_DCHFDebt track the sums of accumulated liquidation rewards per unit staked. During its lifetime, each stake earns:
	 *
	 * An ETH gain of ( stake * [L_ETH - L_ETH(0)] )
	 * A DCHFDebt increase  of ( stake * [L_DCHFDebt - L_DCHFDebt(0)] )
	 *
	 * Where L_ETH(0) and L_DCHFDebt(0) are snapshots of L_ETH and L_DCHFDebt for the active Trove taken at the instant the stake was made
	 */
	mapping(address => uint256) public L_ASSETS;
	mapping(address => uint256) public L_DCHFDebts;

	// Map addresses with active troves to their RewardSnapshot
	mapping(address => mapping(address => RewardSnapshot)) private rewardSnapshots;

	// Array of all active trove addresses - used to to compute an approximate hint off-chain, for the sorted list insertion
	mapping(address => address[]) public TroveOwners;

	// Error trackers for the trove redistribution calculation
	mapping(address => uint256) public lastETHError_Redistribution;
	mapping(address => uint256) public lastDCHFDebtError_Redistribution;

	bool public isInitialized;

	// Internal Function and Modifier onlyBorrowerOperations
	// @dev This workaround was needed in order to reduce bytecode size

	function _onlyBOorTM() private view {
		require(
			msg.sender == borrowerOperationsAddress || msg.sender == troveManagerAddress,
			"WA"
		);
	}

	modifier onlyBOorTM() {
		_onlyBOorTM();
		_;
	}

	function _onlyBorrowerOperations() private view {
		require(msg.sender == borrowerOperationsAddress, "WA");
	}

	modifier onlyBorrowerOperations() {
		_onlyBorrowerOperations();
		_;
	}

	function _onlyTroveManager() private view {
		require(msg.sender == troveManagerAddress, "WA");
	}

	modifier onlyTroveManager() {
		_onlyTroveManager();
		_;
	}

	modifier troveIsActive(address _asset, address _borrower) {
		require(isTroveActive(_asset, _borrower), "IT");
		_;
	}

	// --- Dependency setter ---

	function setAddresses(
		address _borrowerOperationsAddress,
		address _dchfTokenAddress,
		address _sortedTrovesAddress,
		address _dfrancParamsAddress,
		address _troveManagerAddress
	) external initializer {
		require(!isInitialized, "AI");
		checkContract(_borrowerOperationsAddress);
		checkContract(_dchfTokenAddress);
		checkContract(_sortedTrovesAddress);
		checkContract(_dfrancParamsAddress);
		checkContract(_troveManagerAddress);
		isInitialized = true;

		borrowerOperationsAddress = _borrowerOperationsAddress;
		dchfToken = IDCHFToken(_dchfTokenAddress);
		sortedTroves = ISortedTroves(_sortedTrovesAddress);
		troveManagerAddress = _troveManagerAddress;

		setDfrancParameters(_dfrancParamsAddress);
	}

	// --- Helper functions ---

	// Return the nominal collateral ratio (ICR) of a given Trove, without the price. Takes a trove's pending coll and debt rewards from redistributions into account.
	function getNominalICR(address _asset, address _borrower)
		public
		view
		override
		returns (uint256)
	{
		(uint256 currentAsset, uint256 currentDCHFDebt) = _getCurrentTroveAmounts(
			_asset,
			_borrower
		);

		uint256 NICR = DfrancMath._computeNominalCR(currentAsset, currentDCHFDebt);
		return NICR;
	}

	// Return the current collateral ratio (ICR) of a given Trove. Takes a trove's pending coll and debt rewards from redistributions into account.
	function getCurrentICR(
		address _asset,
		address _borrower,
		uint256 _price
	) public view override returns (uint256) {
		(uint256 currentAsset, uint256 currentDCHFDebt) = _getCurrentTroveAmounts(
			_asset,
			_borrower
		);

		uint256 ICR = DfrancMath._computeCR(currentAsset, currentDCHFDebt, _price);
		return ICR;
	}

	function _getCurrentTroveAmounts(address _asset, address _borrower)
		internal
		view
		returns (uint256, uint256)
	{
		uint256 pendingAssetReward = getPendingAssetReward(_asset, _borrower);
		uint256 pendingDCHFDebtReward = getPendingDCHFDebtReward(_asset, _borrower);

		uint256 currentAsset = Troves[_borrower][_asset].coll.add(pendingAssetReward);
		uint256 currentDCHFDebt = Troves[_borrower][_asset].debt.add(pendingDCHFDebtReward);

		return (currentAsset, currentDCHFDebt);
	}

	function applyPendingRewards(address _asset, address _borrower)
		external
		override
		onlyBorrowerOperations
	{
		return
			_applyPendingRewards(
				_asset,
				dfrancParams.activePool(),
				dfrancParams.defaultPool(),
				_borrower
			);
	}

	function applyPendingRewards(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		address _borrower
	) external override onlyTroveManager {
		_applyPendingRewards(_asset, _activePool, _defaultPool, _borrower);
	}

	// Add the borrowers's coll and debt rewards earned from redistributions, to their Trove
	function _applyPendingRewards(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		address _borrower
	) internal {
		if (!hasPendingRewards(_asset, _borrower)) {
			return;
		}

		assert(isTroveActive(_asset, _borrower));

		// Compute pending rewards
		uint256 pendingAssetReward = getPendingAssetReward(_asset, _borrower);
		uint256 pendingDCHFDebtReward = getPendingDCHFDebtReward(_asset, _borrower);

		// Apply pending rewards to trove's state
		Troves[_borrower][_asset].coll = Troves[_borrower][_asset].coll.add(pendingAssetReward);
		Troves[_borrower][_asset].debt = Troves[_borrower][_asset].debt.add(pendingDCHFDebtReward);

		_updateTroveRewardSnapshots(_asset, _borrower);

		// Transfer from DefaultPool to ActivePool
		_movePendingTroveRewardsToActivePool(
			_asset,
			_activePool,
			_defaultPool,
			pendingDCHFDebtReward,
			pendingAssetReward
		);

		emit TroveUpdated(
			_asset,
			_borrower,
			Troves[_borrower][_asset].debt,
			Troves[_borrower][_asset].coll,
			Troves[_borrower][_asset].stake,
			TroveManagerOperation.applyPendingRewards
		);
	}

	// Update borrower's snapshots of L_ETH and L_DCHFDebt to reflect the current values
	function updateTroveRewardSnapshots(address _asset, address _borrower)
		external
		override
		onlyBorrowerOperations
	{
		return _updateTroveRewardSnapshots(_asset, _borrower);
	}

	function _updateTroveRewardSnapshots(address _asset, address _borrower) internal {
		rewardSnapshots[_borrower][_asset].asset = L_ASSETS[_asset];
		rewardSnapshots[_borrower][_asset].DCHFDebt = L_DCHFDebts[_asset];
		emit TroveSnapshotsUpdated(_asset, L_ASSETS[_asset], L_DCHFDebts[_asset]);
	}

	// Get the borrower's pending accumulated ETH reward, earned by their stake
	function getPendingAssetReward(address _asset, address _borrower)
		public
		view
		override
		returns (uint256)
	{
		uint256 snapshotAsset = rewardSnapshots[_borrower][_asset].asset;
		uint256 rewardPerUnitStaked = L_ASSETS[_asset].sub(snapshotAsset);

		if (rewardPerUnitStaked == 0 || !isTroveActive(_asset, _borrower)) {
			return 0;
		}

		uint256 stake = Troves[_borrower][_asset].stake;

		uint256 pendingAssetReward = stake.mul(rewardPerUnitStaked).div(DECIMAL_PRECISION);

		return pendingAssetReward;
	}

	// Get the borrower's pending accumulated DCHF reward, earned by their stake
	function getPendingDCHFDebtReward(address _asset, address _borrower)
		public
		view
		override
		returns (uint256)
	{
		uint256 snapshotDCHFDebt = rewardSnapshots[_borrower][_asset].DCHFDebt;
		uint256 rewardPerUnitStaked = L_DCHFDebts[_asset].sub(snapshotDCHFDebt);

		if (rewardPerUnitStaked == 0 || !isTroveActive(_asset, _borrower)) {
			return 0;
		}

		uint256 stake = Troves[_borrower][_asset].stake;

		uint256 pendingDCHFDebtReward = stake.mul(rewardPerUnitStaked).div(DECIMAL_PRECISION);

		return pendingDCHFDebtReward;
	}

	function hasPendingRewards(address _asset, address _borrower)
		public
		view
		override
		returns (bool)
	{
		if (!isTroveActive(_asset, _borrower)) {
			return false;
		}

		return (rewardSnapshots[_borrower][_asset].asset < L_ASSETS[_asset]);
	}

	function getEntireDebtAndColl(address _asset, address _borrower)
		public
		view
		override
		returns (
			uint256 debt,
			uint256 coll,
			uint256 pendingDCHFDebtReward,
			uint256 pendingAssetReward
		)
	{
		debt = Troves[_borrower][_asset].debt;
		coll = Troves[_borrower][_asset].coll;

		pendingDCHFDebtReward = getPendingDCHFDebtReward(_asset, _borrower);
		pendingAssetReward = getPendingAssetReward(_asset, _borrower);

		debt = debt.add(pendingDCHFDebtReward);
		coll = coll.add(pendingAssetReward);
	}

	function removeStake(address _asset, address _borrower) external override onlyBOorTM {
		return _removeStake(_asset, _borrower);
	}

	function _removeStake(address _asset, address _borrower) internal {
		//add access control
		uint256 stake = Troves[_borrower][_asset].stake;
		totalStakes[_asset] = totalStakes[_asset].sub(stake);
		Troves[_borrower][_asset].stake = 0;
	}

	function updateStakeAndTotalStakes(address _asset, address _borrower)
		external
		override
		onlyBOorTM
		returns (uint256)
	{
		return _updateStakeAndTotalStakes(_asset, _borrower);
	}

	// Update borrower's stake based on their latest collateral value
	function _updateStakeAndTotalStakes(address _asset, address _borrower)
		internal
		returns (uint256)
	{
		uint256 newStake = _computeNewStake(_asset, Troves[_borrower][_asset].coll);
		uint256 oldStake = Troves[_borrower][_asset].stake;
		Troves[_borrower][_asset].stake = newStake;

		totalStakes[_asset] = totalStakes[_asset].sub(oldStake).add(newStake);
		emit TotalStakesUpdated(_asset, totalStakes[_asset]);

		return newStake;
	}

	// Calculate a new stake based on the snapshots of the totalStakes and totalCollateral taken at the last liquidation
	function _computeNewStake(address _asset, uint256 _coll) internal view returns (uint256) {
		uint256 stake;
		if (totalCollateralSnapshot[_asset] == 0) {
			stake = _coll;
		} else {
			/*
			 * The following assert() holds true because:
			 * - The system always contains >= 1 trove
			 * - When we close or liquidate a trove, we redistribute the pending rewards, so if all troves were closed/liquidated,
			 * rewards would’ve been emptied and totalCollateralSnapshot would be zero too.
			 */
			assert(totalStakesSnapshot[_asset] > 0);
			stake = _coll.mul(totalStakesSnapshot[_asset]).div(totalCollateralSnapshot[_asset]);
		}
		return stake;
	}

	function redistributeDebtAndColl(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _debt,
		uint256 _coll
	) external override onlyTroveManager {
		_redistributeDebtAndColl(_asset, _activePool, _defaultPool, _debt, _coll);
	}

	function _redistributeDebtAndColl(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _debt,
		uint256 _coll
	) internal {
		if (_debt == 0) {
			return;
		}

		/*
		 * Add distributed coll and debt rewards-per-unit-staked to the running totals. Division uses a "feedback"
		 * error correction, to keep the cumulative error low in the running totals L_ETH and L_DCHFDebt:
		 *
		 * 1) Form numerators which compensate for the floor division errors that occurred the last time this
		 * function was called.
		 * 2) Calculate "per-unit-staked" ratios.
		 * 3) Multiply each ratio back by its denominator, to reveal the current floor division error.
		 * 4) Store these errors for use in the next correction when this function is called.
		 * 5) Note: static analysis tools complain about this "division before multiplication", however, it is intended.
		 */
		uint256 ETHNumerator = _coll.mul(DECIMAL_PRECISION).add(
			lastETHError_Redistribution[_asset]
		);
		uint256 DCHFDebtNumerator = _debt.mul(DECIMAL_PRECISION).add(
			lastDCHFDebtError_Redistribution[_asset]
		);

		// Get the per-unit-staked terms
		uint256 ETHRewardPerUnitStaked = ETHNumerator.div(totalStakes[_asset]);
		uint256 DCHFDebtRewardPerUnitStaked = DCHFDebtNumerator.div(totalStakes[_asset]);

		lastETHError_Redistribution[_asset] = ETHNumerator.sub(
			ETHRewardPerUnitStaked.mul(totalStakes[_asset])
		);
		lastDCHFDebtError_Redistribution[_asset] = DCHFDebtNumerator.sub(
			DCHFDebtRewardPerUnitStaked.mul(totalStakes[_asset])
		);

		// Add per-unit-staked terms to the running totals
		L_ASSETS[_asset] = L_ASSETS[_asset].add(ETHRewardPerUnitStaked);
		L_DCHFDebts[_asset] = L_DCHFDebts[_asset].add(DCHFDebtRewardPerUnitStaked);

		emit LTermsUpdated(_asset, L_ASSETS[_asset], L_DCHFDebts[_asset]);

		_activePool.decreaseDCHFDebt(_asset, _debt);
		_defaultPool.increaseDCHFDebt(_asset, _debt);
		_activePool.sendAsset(_asset, address(_defaultPool), _coll);
	}

	function closeTrove(address _asset, address _borrower)
		external
		override
		onlyBorrowerOperations
	{
		return _closeTrove(_asset, _borrower, Status.closedByOwner);
	}

	function closeTrove(
		address _asset,
		address _borrower,
		Status closedStatus
	) external override onlyTroveManager {
		_closeTrove(_asset, _borrower, closedStatus);
	}

	function _closeTrove(
		// access control
		address _asset,
		address _borrower,
		Status closedStatus
	) internal {
		assert(closedStatus != Status.nonExistent && closedStatus != Status.active);

		uint256 TroveOwnersArrayLength = TroveOwners[_asset].length;
		_requireMoreThanOneTroveInSystem(_asset, TroveOwnersArrayLength);

		Troves[_borrower][_asset].status = closedStatus;
		Troves[_borrower][_asset].coll = 0;
		Troves[_borrower][_asset].debt = 0;

		rewardSnapshots[_borrower][_asset].asset = 0;
		rewardSnapshots[_borrower][_asset].DCHFDebt = 0;

		_removeTroveOwner(_asset, _borrower, TroveOwnersArrayLength);
		sortedTroves.remove(_asset, _borrower);
	}

	function updateSystemSnapshots_excludeCollRemainder(
		address _asset,
		IActivePool _activePool,
		uint256 _collRemainder
	) external override onlyTroveManager {
		_updateSystemSnapshots_excludeCollRemainder(_asset, _activePool, _collRemainder);
	}

	function _updateSystemSnapshots_excludeCollRemainder(
		address _asset,
		IActivePool _activePool,
		uint256 _collRemainder
	) internal {
		totalStakesSnapshot[_asset] = totalStakes[_asset];

		uint256 activeColl = _activePool.getAssetBalance(_asset);
		uint256 liquidatedColl = dfrancParams.defaultPool().getAssetBalance(_asset);
		totalCollateralSnapshot[_asset] = activeColl.sub(_collRemainder).add(liquidatedColl);

		emit SystemSnapshotsUpdated(
			_asset,
			totalStakesSnapshot[_asset],
			totalCollateralSnapshot[_asset]
		);
	}

	function addTroveOwnerToArray(address _asset, address _borrower)
		external
		override
		onlyBorrowerOperations
		returns (uint256 index)
	{
		return _addTroveOwnerToArray(_asset, _borrower);
	}

	function _addTroveOwnerToArray(address _asset, address _borrower)
		internal
		returns (uint128 index)
	{
		TroveOwners[_asset].push(_borrower);

		index = uint128(TroveOwners[_asset].length.sub(1));
		Troves[_borrower][_asset].arrayIndex = index;

		return index;
	}

	function _removeTroveOwner(
		address _asset,
		address _borrower,
		uint256 TroveOwnersArrayLength
	) internal {
		Status troveStatus = Troves[_borrower][_asset].status;
		assert(troveStatus != Status.nonExistent && troveStatus != Status.active);

		uint128 index = Troves[_borrower][_asset].arrayIndex;
		uint256 length = TroveOwnersArrayLength;
		uint256 idxLast = length.sub(1);

		assert(index <= idxLast);

		address addressToMove = TroveOwners[_asset][idxLast];

		TroveOwners[_asset][index] = addressToMove;
		Troves[addressToMove][_asset].arrayIndex = index;
		emit TroveIndexUpdated(_asset, addressToMove, index);

		TroveOwners[_asset].pop();
	}

	function getTCR(address _asset, uint256 _price) external view override returns (uint256) {
		return _getTCR(_asset, _price);
	}

	function checkRecoveryMode(address _asset, uint256 _price)
		external
		view
		override
		returns (bool)
	{
		return _checkRecoveryMode(_asset, _price);
	}

	function _checkPotentialRecoveryMode(
		address _asset,
		uint256 _entireSystemColl,
		uint256 _entireSystemDebt,
		uint256 _price
	) public view override returns (bool) {
		uint256 TCR = DfrancMath._computeCR(_entireSystemColl, _entireSystemDebt, _price);

		return TCR < dfrancParams.CCR(_asset);
	}

	function updateBaseRateFromRedemption(
		address _asset,
		uint256 _ETHDrawn,
		uint256 _price,
		uint256 _totalDCHFSupply
	) external override onlyTroveManager returns (uint256) {
		return _updateBaseRateFromRedemption(_asset, _ETHDrawn, _price, _totalDCHFSupply);
	}

	function _updateBaseRateFromRedemption(
		address _asset,
		uint256 _ETHDrawn,
		uint256 _price,
		uint256 _totalDCHFSupply
	) internal returns (uint256) {
		uint256 decayedBaseRate = _calcDecayedBaseRate(_asset);

		uint256 redeemedDCHFFraction = _ETHDrawn.mul(_price).div(_totalDCHFSupply);

		uint256 newBaseRate = decayedBaseRate.add(redeemedDCHFFraction.div(BETA));
		newBaseRate = DfrancMath._min(newBaseRate, DECIMAL_PRECISION);
		assert(newBaseRate > 0);

		baseRate[_asset] = newBaseRate;
		emit BaseRateUpdated(_asset, newBaseRate);

		_updateLastFeeOpTime(_asset);

		return newBaseRate;
	}

	function getRedemptionRate(address _asset) public view override returns (uint256) {
		return _calcRedemptionRate(_asset, baseRate[_asset]);
	}

	function getRedemptionRateWithDecay(address _asset) public view override returns (uint256) {
		return _calcRedemptionRate(_asset, _calcDecayedBaseRate(_asset));
	}

	function _calcRedemptionRate(address _asset, uint256 _baseRate)
		internal
		view
		returns (uint256)
	{
		return
			DfrancMath._min(
				dfrancParams.REDEMPTION_FEE_FLOOR(_asset).add(_baseRate),
				DECIMAL_PRECISION
			);
	}

	function _getRedemptionFee(address _asset, uint256 _assetDraw)
		public
		view
		override
		returns (uint256)
	{
		return _calcRedemptionFee(getRedemptionRate(_asset), _assetDraw);
	}

	function getRedemptionFeeWithDecay(address _asset, uint256 _assetDraw)
		external
		view
		override
		returns (uint256)
	{
		return _calcRedemptionFee(getRedemptionRateWithDecay(_asset), _assetDraw);
	}

	function _calcRedemptionFee(uint256 _redemptionRate, uint256 _assetDraw)
		internal
		pure
		returns (uint256)
	{
		uint256 redemptionFee = _redemptionRate.mul(_assetDraw).div(DECIMAL_PRECISION);
		require(redemptionFee < _assetDraw, "FE");
		return redemptionFee;
	}

	function getBorrowingRate(address _asset) public view override returns (uint256) {
		return _calcBorrowingRate(_asset, baseRate[_asset]);
	}

	function getBorrowingRateWithDecay(address _asset) public view override returns (uint256) {
		return _calcBorrowingRate(_asset, _calcDecayedBaseRate(_asset));
	}

	function _calcBorrowingRate(address _asset, uint256 _baseRate)
		internal
		view
		returns (uint256)
	{
		return
			DfrancMath._min(
				dfrancParams.BORROWING_FEE_FLOOR(_asset).add(_baseRate),
				dfrancParams.MAX_BORROWING_FEE(_asset)
			);
	}

	function getBorrowingFee(address _asset, uint256 _DCHFDebt)
		external
		view
		override
		returns (uint256)
	{
		return _calcBorrowingFee(getBorrowingRate(_asset), _DCHFDebt);
	}

	function getBorrowingFeeWithDecay(address _asset, uint256 _DCHFDebt)
		external
		view
		returns (uint256)
	{
		return _calcBorrowingFee(getBorrowingRateWithDecay(_asset), _DCHFDebt);
	}

	function _calcBorrowingFee(uint256 _borrowingRate, uint256 _DCHFDebt)
		internal
		pure
		returns (uint256)
	{
		return _borrowingRate.mul(_DCHFDebt).div(DECIMAL_PRECISION);
	}

	function decayBaseRateFromBorrowing(address _asset)
		external
		override
		onlyBorrowerOperations
	{
		uint256 decayedBaseRate = _calcDecayedBaseRate(_asset);
		assert(decayedBaseRate <= DECIMAL_PRECISION);

		baseRate[_asset] = decayedBaseRate;
		emit BaseRateUpdated(_asset, decayedBaseRate);

		_updateLastFeeOpTime(_asset);
	}

	// Update the last fee operation time only if time passed >= decay interval. This prevents base rate griefing.
	function _updateLastFeeOpTime(address _asset) internal {
		uint256 timePassed = block.timestamp.sub(lastFeeOperationTime[_asset]);

		if (timePassed >= SECONDS_IN_ONE_MINUTE) {
			lastFeeOperationTime[_asset] = block.timestamp;
			emit LastFeeOpTimeUpdated(_asset, block.timestamp);
		}
	}

	function _calcDecayedBaseRate(address _asset) public view returns (uint256) {
		uint256 minutesPassed = _minutesPassedSinceLastFeeOp(_asset);
		uint256 decayFactor = DfrancMath._decPow(MINUTE_DECAY_FACTOR, minutesPassed);

		return baseRate[_asset].mul(decayFactor).div(DECIMAL_PRECISION);
	}

	function _minutesPassedSinceLastFeeOp(address _asset) internal view returns (uint256) {
		return (block.timestamp.sub(lastFeeOperationTime[_asset])).div(SECONDS_IN_ONE_MINUTE);
	}

	function _requireDCHFBalanceCoversRedemption(
		IDCHFToken _dchfToken,
		address _redeemer,
		uint256 _amount
	) public view override {
		require(_dchfToken.balanceOf(_redeemer) >= _amount, "RR");
	}

	function _requireMoreThanOneTroveInSystem(address _asset, uint256 TroveOwnersArrayLength)
		internal
		view
	{
		require(TroveOwnersArrayLength > 1 && sortedTroves.getSize(_asset) > 1, "OO");
	}

	function _requireAmountGreaterThanZero(uint256 _amount) public pure override {
		require(_amount > 0, "AG");
	}

	function _requireTCRoverMCR(address _asset, uint256 _price) external view override {
		require(_getTCR(_asset, _price) >= dfrancParams.MCR(_asset), "CR");
	}

	function _requireValidMaxFeePercentage(address _asset, uint256 _maxFeePercentage)
		public
		view
		override
	{
		require(
			_maxFeePercentage >= dfrancParams.REDEMPTION_FEE_FLOOR(_asset) &&
				_maxFeePercentage <= DECIMAL_PRECISION,
			"MF"
		);
	}

	function isTroveActive(address _asset, address _borrower)
		public
		view
		override
		returns (bool)
	{
		return this.getTroveStatus(_asset, _borrower) == uint256(Status.active);
	}

	// --- Trove owners getters ---

	function getTroveOwnersCount(address _asset) external view override returns (uint256) {
		return TroveOwners[_asset].length;
	}

	function getTroveFromTroveOwnersArray(address _asset, uint256 _index)
		external
		view
		override
		returns (address)
	{
		return TroveOwners[_asset][_index];
	}

	// --- Trove property getters ---

	function getTrove(address _asset, address _borrower)
		external
		view
		override
		returns (
			address,
			uint256,
			uint256,
			uint256,
			Status,
			uint128
		)
	{
		Trove memory _trove = Troves[_borrower][_asset];
		return (
			_trove.asset,
			_trove.debt,
			_trove.coll,
			_trove.stake,
			_trove.status,
			_trove.arrayIndex
		);
	}

	function getTroveStatus(address _asset, address _borrower)
		external
		view
		override
		returns (uint256)
	{
		return uint256(Troves[_borrower][_asset].status);
	}

	function getTroveStake(address _asset, address _borrower)
		external
		view
		override
		returns (uint256)
	{
		return Troves[_borrower][_asset].stake;
	}

	function getTroveDebt(address _asset, address _borrower)
		external
		view
		override
		returns (uint256)
	{
		return Troves[_borrower][_asset].debt;
	}

	function getTroveColl(address _asset, address _borrower)
		external
		view
		override
		returns (uint256)
	{
		return Troves[_borrower][_asset].coll;
	}

	// --- Trove property setters, called by TroveManager ---
	function setTroveDeptAndColl(
		address _asset,
		address _borrower,
		uint256 _debt,
		uint256 _coll
	) external override onlyTroveManager {
		Troves[_borrower][_asset].debt = _debt;
		Troves[_borrower][_asset].coll = _coll;
	}

	// --- Trove property setters, called by BorrowerOperations ---

	function setTroveStatus(
		address _asset,
		address _borrower,
		uint256 _num
	) external override onlyBorrowerOperations {
		Troves[_borrower][_asset].asset = _asset;
		Troves[_borrower][_asset].status = Status(_num);
	}

	function decreaseTroveColl(
		address _asset,
		address _borrower,
		uint256 _collDecrease
	) external override onlyBorrowerOperations returns (uint256) {
		uint256 newColl = Troves[_borrower][_asset].coll.sub(_collDecrease);
		Troves[_borrower][_asset].coll = newColl;
		return newColl;
	}

	function increaseTroveDebt(
		address _asset,
		address _borrower,
		uint256 _debtIncrease
	) external override onlyBorrowerOperations returns (uint256) {
		uint256 newDebt = Troves[_borrower][_asset].debt.add(_debtIncrease);
		Troves[_borrower][_asset].debt = newDebt;
		return newDebt;
	}

	function decreaseTroveDebt(
		address _asset,
		address _borrower,
		uint256 _debtDecrease
	) external override onlyBorrowerOperations returns (uint256) {
		uint256 newDebt = Troves[_borrower][_asset].debt.sub(_debtDecrease);
		Troves[_borrower][_asset].debt = newDebt;
		return newDebt;
	}

	function increaseTroveColl(
		address _asset,
		address _borrower,
		uint256 _collIncrease
	) external override onlyBorrowerOperations returns (uint256) {
		uint256 newColl = Troves[_borrower][_asset].coll.add(_collIncrease);
		Troves[_borrower][_asset].coll = newColl;
		return newColl;
	}

	function movePendingTroveRewardsToActivePool(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _DCHF,
		uint256 _amount
	) external override onlyTroveManager {
		_movePendingTroveRewardsToActivePool(_asset, _activePool, _defaultPool, _DCHF, _amount);
	}

	// Move a Trove's pending debt and collateral rewards from distributions, from the Default Pool to the Active Pool
	function _movePendingTroveRewardsToActivePool(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _DCHF,
		uint256 _amount
	) internal {
		_defaultPool.decreaseDCHFDebt(_asset, _DCHF);
		_activePool.increaseDCHFDebt(_asset, _DCHF);
		_defaultPool.sendAssetToActivePool(_asset, _amount);
	}

	function getRewardSnapshots(address _asset, address _troveOwner)
		external
		view
		override
		returns (uint256 asset, uint256 DCHFDebt)
	{
		RewardSnapshot memory _rewardSnapshot = rewardSnapshots[_asset][_troveOwner];
		return (_rewardSnapshot.asset, _rewardSnapshot.DCHFDebt);
	}
}

File 2 of 33 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../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.
 *
 * By default, the owner account will be the one that deploys the contract. 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;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _setOwner(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _setOwner(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 {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 3 of 33 : ITroveManagerHelpers.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;
import "./IDfrancBase.sol";
import "./IStabilityPool.sol";
import "./IDCHFToken.sol";
import "./IMONStaking.sol";
import "./ICollSurplusPool.sol";
import "./ISortedTroves.sol";
import "./IActivePool.sol";
import "./IDefaultPool.sol";
import "./IStabilityPoolManager.sol";

// Common interface for the Trove Manager.
interface ITroveManagerHelpers is IDfrancBase {
	enum Status {
		nonExistent,
		active,
		closedByOwner,
		closedByLiquidation,
		closedByRedemption
	}

	// Store the necessary data for a trove
	struct Trove {
		address asset;
		uint256 debt;
		uint256 coll;
		uint256 stake;
		Status status;
		uint128 arrayIndex;
	}

	/*
	 * --- Variable container structs for liquidations ---
	 *
	 * These structs are used to hold, return and assign variables inside the liquidation functions,
	 * in order to avoid the error: "CompilerError: Stack too deep".
	 **/

	struct LocalVariables_OuterLiquidationFunction {
		uint256 price;
		uint256 DCHFInStabPool;
		bool recoveryModeAtStart;
		uint256 liquidatedDebt;
		uint256 liquidatedColl;
	}

	struct LocalVariables_InnerSingleLiquidateFunction {
		uint256 collToLiquidate;
		uint256 pendingDebtReward;
		uint256 pendingCollReward;
	}

	struct LocalVariables_LiquidationSequence {
		uint256 remainingDCHFInStabPool;
		uint256 i;
		uint256 ICR;
		address user;
		bool backToNormalMode;
		uint256 entireSystemDebt;
		uint256 entireSystemColl;
	}

	struct LocalVariables_AssetBorrowerPrice {
		address _asset;
		address _borrower;
		uint256 _price;
	}

	struct LiquidationValues {
		uint256 entireTroveDebt;
		uint256 entireTroveColl;
		uint256 collGasCompensation;
		uint256 DCHFGasCompensation;
		uint256 debtToOffset;
		uint256 collToSendToSP;
		uint256 debtToRedistribute;
		uint256 collToRedistribute;
		uint256 collSurplus;
	}

	struct LiquidationTotals {
		uint256 totalCollInSequence;
		uint256 totalDebtInSequence;
		uint256 totalCollGasCompensation;
		uint256 totalDCHFGasCompensation;
		uint256 totalDebtToOffset;
		uint256 totalCollToSendToSP;
		uint256 totalDebtToRedistribute;
		uint256 totalCollToRedistribute;
		uint256 totalCollSurplus;
	}

	struct ContractsCache {
		IActivePool activePool;
		IDefaultPool defaultPool;
		IDCHFToken dchfToken;
		IMONStaking monStaking;
		ISortedTroves sortedTroves;
		ICollSurplusPool collSurplusPool;
		address gasPoolAddress;
	}
	// --- Variable container structs for redemptions ---

	struct RedemptionTotals {
		uint256 remainingDCHF;
		uint256 totalDCHFToRedeem;
		uint256 totalAssetDrawn;
		uint256 ETHFee;
		uint256 ETHToSendToRedeemer;
		uint256 decayedBaseRate;
		uint256 price;
		uint256 totalDCHFSupplyAtStart;
	}

	struct SingleRedemptionValues {
		uint256 DCHFLot;
		uint256 ETHLot;
		bool cancelledPartial;
	}

	// Object containing the ETH and DCHF snapshots for a given active trove
	struct RewardSnapshot {
		uint256 asset;
		uint256 DCHFDebt;
	}

	// --- Events ---

	event Liquidation(
		address indexed _asset,
		uint256 _liquidatedDebt,
		uint256 _liquidatedColl,
		uint256 _collGasCompensation,
		uint256 _DCHFGasCompensation
	);
	event Redemption(
		address indexed _asset,
		uint256 _attemptedDCHFAmount,
		uint256 _actualDCHFAmount,
		uint256 _AssetSent,
		uint256 _AssetFee
	);
	event TroveUpdated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		uint256 stake,
		uint8 operation
	);
	event TroveLiquidated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		uint8 operation
	);
	event BaseRateUpdated(address indexed _asset, uint256 _baseRate);
	event LastFeeOpTimeUpdated(address indexed _asset, uint256 _lastFeeOpTime);
	event TotalStakesUpdated(address indexed _asset, uint256 _newTotalStakes);
	event SystemSnapshotsUpdated(
		address indexed _asset,
		uint256 _totalStakesSnapshot,
		uint256 _totalCollateralSnapshot
	);
	event LTermsUpdated(address indexed _asset, uint256 _L_ETH, uint256 _L_DCHFDebt);
	event TroveSnapshotsUpdated(address indexed _asset, uint256 _L_ETH, uint256 _L_DCHFDebt);
	event TroveIndexUpdated(address indexed _asset, address _borrower, uint256 _newIndex);

	event TroveUpdated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		uint256 _stake,
		TroveManagerOperation _operation
	);
	event TroveLiquidated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		TroveManagerOperation _operation
	);

	enum TroveManagerOperation {
		applyPendingRewards,
		liquidateInNormalMode,
		liquidateInRecoveryMode,
		redeemCollateral
	}

	// Functions

	function addTroveOwnerToArray(address _asset, address _borrower)
		external
		returns (uint256 index);

	function applyPendingRewards(address _asset, address _borrower) external;

	function checkRecoveryMode(address _asset, uint256 _price) external returns (bool);

	function closeTrove(address _asset, address _borrower) external;

	function decayBaseRateFromBorrowing(address _asset) external;

	function decreaseTroveColl(
		address _asset,
		address _borrower,
		uint256 _collDecrease
	) external returns (uint256);

	function decreaseTroveDebt(
		address _asset,
		address _borrower,
		uint256 _collDecrease
	) external returns (uint256);

	function getBorrowingFee(address _asset, uint256 DCHFDebt) external view returns (uint256);

	function getBorrowingRateWithDecay(address _asset) external view returns (uint256);

	function getBorrowingRate(address _asset) external view returns (uint256);

	function getCurrentICR(
		address _asset,
		address _borrower,
		uint256 _price
	) external view returns (uint256);

	function getEntireDebtAndColl(address _asset, address _borrower)
		external
		view
		returns (
			uint256 debt,
			uint256 coll,
			uint256 pendingDCHFDebtReward,
			uint256 pendingAssetReward
		);

	function getNominalICR(address _asset, address _borrower) external view returns (uint256);

	function getPendingAssetReward(address _asset, address _borrower)
		external
		view
		returns (uint256);

	function getPendingDCHFDebtReward(address _asset, address _borrower)
		external
		view
		returns (uint256);

	function getRedemptionFeeWithDecay(address _asset, uint256 _assetDraw)
		external
		view
		returns (uint256);

	function getRedemptionRate(address _asset) external view returns (uint256);

	function getRedemptionRateWithDecay(address _asset) external view returns (uint256);

	function getTCR(address _asset, uint256 _price) external view returns (uint256);

	function getTroveColl(address _asset, address _borrower) external view returns (uint256);

	function getTroveDebt(address _asset, address _borrower) external view returns (uint256);

	function getTroveStake(address _asset, address _borrower) external view returns (uint256);

	function getTroveStatus(address _asset, address _borrower) external view returns (uint256);

	function hasPendingRewards(address _asset, address _borrower) external view returns (bool);

	function increaseTroveColl(
		address _asset,
		address _borrower,
		uint256 _collIncrease
	) external returns (uint256);

	function increaseTroveDebt(
		address _asset,
		address _borrower,
		uint256 _debtIncrease
	) external returns (uint256);

	function setTroveStatus(
		address _asset,
		address _borrower,
		uint256 num
	) external;

	function updateTroveRewardSnapshots(address _asset, address _borrower) external;

	function getBorrowingFeeWithDecay(address _asset, uint256 _DCHFDebt)
		external
		view
		returns (uint256);

	function getTroveOwnersCount(address _asset) external view returns (uint256);

	function getTroveFromTroveOwnersArray(address _asset, uint256 _index)
		external
		view
		returns (address);

	function setTroveDeptAndColl(
		address _asset,
		address _borrower,
		uint256 _debt,
		uint256 _coll
	) external;

	function isTroveActive(address _asset, address _borrower) external view returns (bool);

	function movePendingTroveRewardsToActivePool(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _DCHF,
		uint256 _amount
	) external;

	function removeStake(address _asset, address _borrower) external;

	function closeTrove(
		// access control
		address _asset,
		address _borrower,
		Status closedStatus
	) external;

	function redistributeDebtAndColl(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _debt,
		uint256 _coll
	) external;

	function updateSystemSnapshots_excludeCollRemainder(
		// access control
		address _asset,
		IActivePool _activePool,
		uint256 _collRemainder
	) external;

	function _checkPotentialRecoveryMode(
		// access control
		address _asset,
		uint256 _entireSystemColl,
		uint256 _entireSystemDebt,
		uint256 _price
	) external view returns (bool);

	function updateBaseRateFromRedemption(
		address _asset,
		uint256 _ETHDrawn,
		uint256 _price,
		uint256 _totalDCHFSupply
	) external returns (uint256);

	function updateStakeAndTotalStakes(address _asset, address _borrower)
		external
		returns (uint256);

	function _requireValidMaxFeePercentage(address _asset, uint256 _maxFeePercentage)
		external
		view;

	function _requireTCRoverMCR(address _asset, uint256 _price) external view;

	function _requireAmountGreaterThanZero(uint256 _amount) external pure;

	function _requireDCHFBalanceCoversRedemption(
		IDCHFToken _dchfToken,
		address _redeemer,
		uint256 _amount
	) external view;

	function applyPendingRewards(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		address _borrower
	) external;

	function _getRedemptionFee(address _asset, uint256 _assetDraw)
		external
		view
		returns (uint256);

	function getTrove(address _asset, address _borrower)
		external
		view
		returns (
			address,
			uint256,
			uint256,
			uint256,
			Status,
			uint128
		);

	function getRewardSnapshots(address _asset, address _troveOwner)
		external
		view
		returns (uint256 asset, uint256 DCHFDebt);
}

File 4 of 33 : DfrancBase.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

import "@openzeppelin/contracts/access/Ownable.sol";

import "./BaseMath.sol";
import "./DfrancMath.sol";
import "../Interfaces/IActivePool.sol";
import "../Interfaces/IDefaultPool.sol";
import "../Interfaces/IPriceFeed.sol";
import "../Interfaces/IDfrancBase.sol";

/*
 * Base contract for TroveManager, BorrowerOperations and StabilityPool. Contains global system constants and
 * common functions.
 */
contract DfrancBase is BaseMath, IDfrancBase, Ownable {
	using SafeMath for uint256;
	address public constant ETH_REF_ADDRESS = address(0);

	IDfrancParameters public override dfrancParams;

	function setDfrancParameters(address _vaultParams) public onlyOwner {
		dfrancParams = IDfrancParameters(_vaultParams);
		emit VaultParametersBaseChanged(_vaultParams);
	}

	// --- Gas compensation functions ---

	// Returns the composite debt (drawn debt + gas compensation) of a trove, for the purpose of ICR calculation
	function _getCompositeDebt(address _asset, uint256 _debt) internal view returns (uint256) {
		return _debt.add(dfrancParams.DCHF_GAS_COMPENSATION(_asset));
	}

	function _getNetDebt(address _asset, uint256 _debt) internal view returns (uint256) {
		return _debt.sub(dfrancParams.DCHF_GAS_COMPENSATION(_asset));
	}

	// Return the amount of ETH to be drawn from a trove's collateral and sent as gas compensation.
	function _getCollGasCompensation(address _asset, uint256 _entireColl)
		internal
		view
		returns (uint256)
	{
		return _entireColl / dfrancParams.PERCENT_DIVISOR(_asset);
	}

	function getEntireSystemColl(address _asset) public view returns (uint256 entireSystemColl) {
		uint256 activeColl = dfrancParams.activePool().getAssetBalance(_asset);
		uint256 liquidatedColl = dfrancParams.defaultPool().getAssetBalance(_asset);

		return activeColl.add(liquidatedColl);
	}

	function getEntireSystemDebt(address _asset) public view returns (uint256 entireSystemDebt) {
		uint256 activeDebt = dfrancParams.activePool().getDCHFDebt(_asset);
		uint256 closedDebt = dfrancParams.defaultPool().getDCHFDebt(_asset);

		return activeDebt.add(closedDebt);
	}

	function _getTCR(address _asset, uint256 _price) internal view returns (uint256 TCR) {
		uint256 entireSystemColl = getEntireSystemColl(_asset);
		uint256 entireSystemDebt = getEntireSystemDebt(_asset);

		TCR = DfrancMath._computeCR(entireSystemColl, entireSystemDebt, _price);

		return TCR;
	}

	function _checkRecoveryMode(address _asset, uint256 _price) internal view returns (bool) {
		uint256 TCR = _getTCR(_asset, _price);

		return TCR < dfrancParams.CCR(_asset);
	}

	function _requireUserAcceptsFee(
		uint256 _fee,
		uint256 _amount,
		uint256 _maxFeePercentage
	) internal view {
		uint256 feePercentage = _fee.mul(dfrancParams.DECIMAL_PRECISION()).div(_amount);
		require(feePercentage <= _maxFeePercentage, "FM");
	}
}

File 5 of 33 : CheckContract.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

contract CheckContract {
	function checkContract(address _account) internal view {
		require(_account != address(0), "Account cannot be zero address");

		uint256 size;
		assembly {
			size := extcodesize(_account)
		}
		require(size > 0, "Account code size cannot be zero");
	}
}

File 6 of 33 : Initializable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/utils/Address.sol";

abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
     */
    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);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
     * initialization step. This is essential to configure modules that are added through upgrades and that require
     * initialization.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initialized`
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initializing`
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

File 7 of 33 : TroveManager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "./Interfaces/ITroveManager.sol";
import "./Dependencies/DfrancBase.sol";
import "./Dependencies/CheckContract.sol";
import "./Dependencies/Initializable.sol";
import "./Interfaces/ITroveManagerHelpers.sol";

contract TroveManager is DfrancBase, CheckContract, Initializable, ITroveManager {
	using SafeMath for uint256;
	string public constant NAME = "TroveManager";

	// --- Connected contract declarations ---

	ITroveManagerHelpers public troveManagerHelpers;

	IStabilityPoolManager public stabilityPoolManager;

	address gasPoolAddress;

	ICollSurplusPool collSurplusPool;

	IDCHFToken public override dchfToken;

	IMONStaking public override monStaking;

	// A doubly linked list of Troves, sorted by their sorted by their collateral ratios
	ISortedTroves public sortedTroves;

	// --- Data structures ---

	bool public isInitialized;

	mapping(address => bool) public redemptionWhitelist;
	bool public isRedemptionWhitelisted;

	// Internal Function and Modifier onlyBorrowerOperations
	// @dev This workaround was needed in order to reduce bytecode size

	modifier troveIsActive(address _asset, address _borrower) {
		require(troveManagerHelpers.isTroveActive(_asset, _borrower), "IT");
		_;
	}

	// --- Dependency setter ---

	function setAddresses(
		address _stabilityPoolManagerAddress,
		address _gasPoolAddress,
		address _collSurplusPoolAddress,
		address _dchfTokenAddress,
		address _sortedTrovesAddress,
		address _monStakingAddress,
		address _dfrancParamsAddress,
		address _troveManagerHelpersAddress
	) external override initializer {
		require(!isInitialized, "AI");
		checkContract(_stabilityPoolManagerAddress);
		checkContract(_gasPoolAddress);
		checkContract(_collSurplusPoolAddress);
		checkContract(_dchfTokenAddress);
		checkContract(_sortedTrovesAddress);
		checkContract(_monStakingAddress);
		checkContract(_dfrancParamsAddress);
		checkContract(_troveManagerHelpersAddress);
		isInitialized = true;

		stabilityPoolManager = IStabilityPoolManager(_stabilityPoolManagerAddress);
		gasPoolAddress = _gasPoolAddress;
		collSurplusPool = ICollSurplusPool(_collSurplusPoolAddress);
		dchfToken = IDCHFToken(_dchfTokenAddress);
		sortedTroves = ISortedTroves(_sortedTrovesAddress);
		monStaking = IMONStaking(_monStakingAddress);
		troveManagerHelpers = ITroveManagerHelpers(_troveManagerHelpersAddress);

		setDfrancParameters(_dfrancParamsAddress);
	}

	// --- Trove Getter functions ---

	function isContractTroveManager() public pure returns (bool) {
		return true;
	}

	// --- Trove Liquidation functions ---

	// Single liquidation function. Closes the trove if its ICR is lower than the minimum collateral ratio.
	function liquidate(address _asset, address _borrower)
		external
		override
		troveIsActive(_asset, _borrower)
	{
		address[] memory borrowers = new address[](1);
		borrowers[0] = _borrower;
		batchLiquidateTroves(_asset, borrowers);
	}

	// --- Inner single liquidation functions ---

	// Liquidate one trove, in Normal Mode.
	function _liquidateNormalMode(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		address _borrower,
		uint256 _DCHFInStabPool
	) internal returns (LiquidationValues memory singleLiquidation) {
		LocalVariables_InnerSingleLiquidateFunction memory vars;

		(
			singleLiquidation.entireTroveDebt,
			singleLiquidation.entireTroveColl,
			vars.pendingDebtReward,
			vars.pendingCollReward
		) = troveManagerHelpers.getEntireDebtAndColl(_asset, _borrower);

		troveManagerHelpers.movePendingTroveRewardsToActivePool(
			_asset,
			_activePool,
			_defaultPool,
			vars.pendingDebtReward,
			vars.pendingCollReward
		);
		troveManagerHelpers.removeStake(_asset, _borrower);

		singleLiquidation.collGasCompensation = _getCollGasCompensation(
			_asset,
			singleLiquidation.entireTroveColl
		);
		singleLiquidation.DCHFGasCompensation = dfrancParams.DCHF_GAS_COMPENSATION(_asset);
		uint256 collToLiquidate = singleLiquidation.entireTroveColl.sub(
			singleLiquidation.collGasCompensation
		);

		(
			singleLiquidation.debtToOffset,
			singleLiquidation.collToSendToSP,
			singleLiquidation.debtToRedistribute,
			singleLiquidation.collToRedistribute
		) = _getOffsetAndRedistributionVals(
			singleLiquidation.entireTroveDebt,
			collToLiquidate,
			_DCHFInStabPool
		);

		troveManagerHelpers.closeTrove(
			_asset,
			_borrower,
			ITroveManagerHelpers.Status.closedByLiquidation
		);
		emit TroveLiquidated(
			_asset,
			_borrower,
			singleLiquidation.entireTroveDebt,
			singleLiquidation.entireTroveColl,
			TroveManagerOperation.liquidateInNormalMode
		);
		emit TroveUpdated(_asset, _borrower, 0, 0, 0, TroveManagerOperation.liquidateInNormalMode);
		return singleLiquidation;
	}

	// Liquidate one trove, in Recovery Mode.
	function _liquidateRecoveryMode(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		address _borrower,
		uint256 _ICR,
		uint256 _DCHFInStabPool,
		uint256 _TCR,
		uint256 _price
	) internal returns (LiquidationValues memory singleLiquidation) {
		LocalVariables_InnerSingleLiquidateFunction memory vars;
		if (troveManagerHelpers.getTroveOwnersCount(_asset) <= 1) {
			return singleLiquidation;
		} // don't liquidate if last trove
		(
			singleLiquidation.entireTroveDebt,
			singleLiquidation.entireTroveColl,
			vars.pendingDebtReward,
			vars.pendingCollReward
		) = troveManagerHelpers.getEntireDebtAndColl(_asset, _borrower);

		singleLiquidation.collGasCompensation = _getCollGasCompensation(
			_asset,
			singleLiquidation.entireTroveColl
		);
		singleLiquidation.DCHFGasCompensation = dfrancParams.DCHF_GAS_COMPENSATION(_asset);
		vars.collToLiquidate = singleLiquidation.entireTroveColl.sub(
			singleLiquidation.collGasCompensation
		);

		// If ICR <= 100%, purely redistribute the Trove across all active Troves
		if (_ICR <= dfrancParams._100pct()) {
			troveManagerHelpers.movePendingTroveRewardsToActivePool(
				_asset,
				_activePool,
				_defaultPool,
				vars.pendingDebtReward,
				vars.pendingCollReward
			);
			troveManagerHelpers.removeStake(_asset, _borrower);

			singleLiquidation.debtToOffset = 0;
			singleLiquidation.collToSendToSP = 0;
			singleLiquidation.debtToRedistribute = singleLiquidation.entireTroveDebt;
			singleLiquidation.collToRedistribute = vars.collToLiquidate;

			troveManagerHelpers.closeTrove(
				_asset,
				_borrower,
				ITroveManagerHelpers.Status.closedByLiquidation
			);
			emit TroveLiquidated(
				_asset,
				_borrower,
				singleLiquidation.entireTroveDebt,
				singleLiquidation.entireTroveColl,
				TroveManagerOperation.liquidateInRecoveryMode
			);
			emit TroveUpdated(
				_asset,
				_borrower,
				0,
				0,
				0,
				TroveManagerOperation.liquidateInRecoveryMode
			);

			// If 100% < ICR < MCR, offset as much as possible, and redistribute the remainder
		} else if ((_ICR > dfrancParams._100pct()) && (_ICR < dfrancParams.MCR(_asset))) {
			troveManagerHelpers.movePendingTroveRewardsToActivePool(
				_asset,
				_activePool,
				_defaultPool,
				vars.pendingDebtReward,
				vars.pendingCollReward
			);
			troveManagerHelpers.removeStake(_asset, _borrower);

			(
				singleLiquidation.debtToOffset,
				singleLiquidation.collToSendToSP,
				singleLiquidation.debtToRedistribute,
				singleLiquidation.collToRedistribute
			) = _getOffsetAndRedistributionVals(
				singleLiquidation.entireTroveDebt,
				vars.collToLiquidate,
				_DCHFInStabPool
			);

			troveManagerHelpers.closeTrove(
				_asset,
				_borrower,
				ITroveManagerHelpers.Status.closedByLiquidation
			);
			emit TroveLiquidated(
				_asset,
				_borrower,
				singleLiquidation.entireTroveDebt,
				singleLiquidation.entireTroveColl,
				TroveManagerOperation.liquidateInRecoveryMode
			);
			emit TroveUpdated(
				_asset,
				_borrower,
				0,
				0,
				0,
				TroveManagerOperation.liquidateInRecoveryMode
			);
			/*
			 * If 110% <= ICR < current TCR (accounting for the preceding liquidations in the current sequence)
			 * and there is DCHF in the Stability Pool, only offset, with no redistribution,
			 * but at a capped rate of 1.1 and only if the whole debt can be liquidated.
			 * The remainder due to the capped rate will be claimable as collateral surplus.
			 */
		} else if (
			(_ICR >= dfrancParams.MCR(_asset)) &&
			(_ICR < _TCR) &&
			(singleLiquidation.entireTroveDebt <= _DCHFInStabPool)
		) {
			troveManagerHelpers.movePendingTroveRewardsToActivePool(
				_asset,
				_activePool,
				_defaultPool,
				vars.pendingDebtReward,
				vars.pendingCollReward
			);
			assert(_DCHFInStabPool != 0);

			troveManagerHelpers.removeStake(_asset, _borrower);
			singleLiquidation = _getCappedOffsetVals(
				_asset,
				singleLiquidation.entireTroveDebt,
				singleLiquidation.entireTroveColl,
				_price
			);

			troveManagerHelpers.closeTrove(
				_asset,
				_borrower,
				ITroveManagerHelpers.Status.closedByLiquidation
			);
			if (singleLiquidation.collSurplus > 0) {
				collSurplusPool.accountSurplus(_asset, _borrower, singleLiquidation.collSurplus);
			}

			emit TroveLiquidated(
				_asset,
				_borrower,
				singleLiquidation.entireTroveDebt,
				singleLiquidation.collToSendToSP,
				TroveManagerOperation.liquidateInRecoveryMode
			);
			emit TroveUpdated(
				_asset,
				_borrower,
				0,
				0,
				0,
				TroveManagerOperation.liquidateInRecoveryMode
			);
		} else {
			// if (_ICR >= MCR && ( _ICR >= _TCR || singleLiquidation.entireTroveDebt > _DCHFInStabPool))
			LiquidationValues memory zeroVals;
			return zeroVals;
		}

		return singleLiquidation;
	}

	/* In a full liquidation, returns the values for a trove's coll and debt to be offset, and coll and debt to be
	 * redistributed to active troves.
	 */
	function _getOffsetAndRedistributionVals(
		uint256 _debt,
		uint256 _coll,
		uint256 _DCHFInStabPool
	)
		internal
		pure
		returns (
			uint256 debtToOffset,
			uint256 collToSendToSP,
			uint256 debtToRedistribute,
			uint256 collToRedistribute
		)
	{
		if (_DCHFInStabPool > 0) {
			/*
			 * Offset as much debt & collateral as possible against the Stability Pool, and redistribute the remainder
			 * between all active troves.
			 *
			 *  If the trove's debt is larger than the deposited DCHF in the Stability Pool:
			 *
			 *  - Offset an amount of the trove's debt equal to the DCHF in the Stability Pool
			 *  - Send a fraction of the trove's collateral to the Stability Pool, equal to the fraction of its offset debt
			 *
			 */
			debtToOffset = DfrancMath._min(_debt, _DCHFInStabPool);
			collToSendToSP = _coll.mul(debtToOffset).div(_debt);
			debtToRedistribute = _debt.sub(debtToOffset);
			collToRedistribute = _coll.sub(collToSendToSP);
		} else {
			debtToOffset = 0;
			collToSendToSP = 0;
			debtToRedistribute = _debt;
			collToRedistribute = _coll;
		}
	}

	/*
	 *  Get its offset coll/debt and ETH gas comp, and close the trove.
	 */
	function _getCappedOffsetVals(
		address _asset,
		uint256 _entireTroveDebt,
		uint256 _entireTroveColl,
		uint256 _price
	) internal view returns (LiquidationValues memory singleLiquidation) {
		singleLiquidation.entireTroveDebt = _entireTroveDebt;
		singleLiquidation.entireTroveColl = _entireTroveColl;
		uint256 cappedCollPortion = _entireTroveDebt.mul(dfrancParams.MCR(_asset)).div(_price);

		singleLiquidation.collGasCompensation = _getCollGasCompensation(_asset, cappedCollPortion);
		singleLiquidation.DCHFGasCompensation = dfrancParams.DCHF_GAS_COMPENSATION(_asset);

		singleLiquidation.debtToOffset = _entireTroveDebt;
		singleLiquidation.collToSendToSP = cappedCollPortion.sub(
			singleLiquidation.collGasCompensation
		);
		singleLiquidation.collSurplus = _entireTroveColl.sub(cappedCollPortion);
		singleLiquidation.debtToRedistribute = 0;
		singleLiquidation.collToRedistribute = 0;
	}

	/*
	 * Liquidate a sequence of troves. Closes a maximum number of n under-collateralized Troves,
	 * starting from the one with the lowest collateral ratio in the system, and moving upwards
	 */
	function liquidateTroves(address _asset, uint256 _n) external override {
		ContractsCache memory contractsCache = ContractsCache(
			dfrancParams.activePool(),
			dfrancParams.defaultPool(),
			IDCHFToken(address(0)),
			IMONStaking(address(0)),
			sortedTroves,
			ICollSurplusPool(address(0)),
			address(0)
		);
		IStabilityPool stabilityPoolCached = stabilityPoolManager.getAssetStabilityPool(_asset);

		LocalVariables_OuterLiquidationFunction memory vars;

		LiquidationTotals memory totals;

		vars.price = dfrancParams.priceFeed().fetchPrice(_asset);
		vars.DCHFInStabPool = stabilityPoolCached.getTotalDCHFDeposits();
		vars.recoveryModeAtStart = troveManagerHelpers.checkRecoveryMode(_asset, vars.price);

		// Perform the appropriate liquidation sequence - tally the values, and obtain their totals
		if (vars.recoveryModeAtStart) {
			totals = _getTotalsFromLiquidateTrovesSequence_RecoveryMode(
				_asset,
				contractsCache,
				vars.price,
				vars.DCHFInStabPool,
				_n
			);
		} else {
			// if !vars.recoveryModeAtStart
			totals = _getTotalsFromLiquidateTrovesSequence_NormalMode(
				_asset,
				contractsCache.activePool,
				contractsCache.defaultPool,
				vars.price,
				vars.DCHFInStabPool,
				_n
			);
		}

		require(totals.totalDebtInSequence > 0, "0L");

		// Move liquidated ETH and DCHF to the appropriate pools
		stabilityPoolCached.offset(totals.totalDebtToOffset, totals.totalCollToSendToSP);
		troveManagerHelpers.redistributeDebtAndColl(
			_asset,
			contractsCache.activePool,
			contractsCache.defaultPool,
			totals.totalDebtToRedistribute,
			totals.totalCollToRedistribute
		);
		if (totals.totalCollSurplus > 0) {
			contractsCache.activePool.sendAsset(
				_asset,
				address(collSurplusPool),
				totals.totalCollSurplus
			);
		}

		// Update system snapshots
		troveManagerHelpers.updateSystemSnapshots_excludeCollRemainder(
			_asset,
			contractsCache.activePool,
			totals.totalCollGasCompensation
		);

		vars.liquidatedDebt = totals.totalDebtInSequence;
		vars.liquidatedColl = totals.totalCollInSequence.sub(totals.totalCollGasCompensation).sub(
			totals.totalCollSurplus
		);
		emit Liquidation(
			_asset,
			vars.liquidatedDebt,
			vars.liquidatedColl,
			totals.totalCollGasCompensation,
			totals.totalDCHFGasCompensation
		);

		// Send gas compensation to caller
		_sendGasCompensation(
			_asset,
			contractsCache.activePool,
			msg.sender,
			totals.totalDCHFGasCompensation,
			totals.totalCollGasCompensation
		);
	}

	/*
	 * This function is used when the liquidateTroves sequence starts during Recovery Mode. However, it
	 * handle the case where the system *leaves* Recovery Mode, part way through the liquidation sequence
	 */
	function _getTotalsFromLiquidateTrovesSequence_RecoveryMode(
		address _asset,
		ContractsCache memory _contractsCache,
		uint256 _price,
		uint256 _DCHFInStabPool,
		uint256 _n
	) internal returns (LiquidationTotals memory totals) {
		LocalVariables_AssetBorrowerPrice memory assetVars = LocalVariables_AssetBorrowerPrice(
			_asset,
			address(0),
			_price
		);

		LocalVariables_LiquidationSequence memory vars;
		LiquidationValues memory singleLiquidation;

		vars.remainingDCHFInStabPool = _DCHFInStabPool;
		vars.backToNormalMode = false;
		vars.entireSystemDebt = getEntireSystemDebt(assetVars._asset);
		vars.entireSystemColl = getEntireSystemColl(assetVars._asset);

		vars.user = _contractsCache.sortedTroves.getLast(assetVars._asset);
		address firstUser = _contractsCache.sortedTroves.getFirst(assetVars._asset);
		for (vars.i = 0; vars.i < _n && vars.user != firstUser; vars.i++) {
			// we need to cache it, because current user is likely going to be deleted
			address nextUser = _contractsCache.sortedTroves.getPrev(assetVars._asset, vars.user);

			vars.ICR = troveManagerHelpers.getCurrentICR(
				assetVars._asset,
				vars.user,
				assetVars._price
			);

			if (!vars.backToNormalMode) {
				// Break the loop if ICR is greater than MCR and Stability Pool is empty
				if (vars.ICR >= dfrancParams.MCR(_asset) && vars.remainingDCHFInStabPool == 0) {
					break;
				}

				uint256 TCR = DfrancMath._computeCR(
					vars.entireSystemColl,
					vars.entireSystemDebt,
					assetVars._price
				);

				singleLiquidation = _liquidateRecoveryMode(
					assetVars._asset,
					_contractsCache.activePool,
					_contractsCache.defaultPool,
					vars.user,
					vars.ICR,
					vars.remainingDCHFInStabPool,
					TCR,
					assetVars._price
				);

				// Update aggregate trackers
				vars.remainingDCHFInStabPool = vars.remainingDCHFInStabPool.sub(
					singleLiquidation.debtToOffset
				);
				vars.entireSystemDebt = vars.entireSystemDebt.sub(singleLiquidation.debtToOffset);
				vars.entireSystemColl = vars
					.entireSystemColl
					.sub(singleLiquidation.collToSendToSP)
					.sub(singleLiquidation.collGasCompensation)
					.sub(singleLiquidation.collSurplus);

				// Add liquidation values to their respective running totals
				totals = _addLiquidationValuesToTotals(totals, singleLiquidation);

				vars.backToNormalMode = !troveManagerHelpers._checkPotentialRecoveryMode(
					_asset,
					vars.entireSystemColl,
					vars.entireSystemDebt,
					assetVars._price
				);
			} else if (vars.backToNormalMode && vars.ICR < dfrancParams.MCR(_asset)) {
				singleLiquidation = _liquidateNormalMode(
					assetVars._asset,
					_contractsCache.activePool,
					_contractsCache.defaultPool,
					vars.user,
					vars.remainingDCHFInStabPool
				);

				vars.remainingDCHFInStabPool = vars.remainingDCHFInStabPool.sub(
					singleLiquidation.debtToOffset
				);

				// Add liquidation values to their respective running totals
				totals = _addLiquidationValuesToTotals(totals, singleLiquidation);
			} else break; // break if the loop reaches a Trove with ICR >= MCR

			vars.user = nextUser;
		}
	}

	function _getTotalsFromLiquidateTrovesSequence_NormalMode(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _price,
		uint256 _DCHFInStabPool,
		uint256 _n
	) internal returns (LiquidationTotals memory totals) {
		LocalVariables_LiquidationSequence memory vars;
		LiquidationValues memory singleLiquidation;
		ISortedTroves sortedTrovesCached = sortedTroves;

		vars.remainingDCHFInStabPool = _DCHFInStabPool;

		for (vars.i = 0; vars.i < _n; vars.i++) {
			vars.user = sortedTrovesCached.getLast(_asset);
			vars.ICR = troveManagerHelpers.getCurrentICR(_asset, vars.user, _price);

			if (vars.ICR < dfrancParams.MCR(_asset)) {
				singleLiquidation = _liquidateNormalMode(
					_asset,
					_activePool,
					_defaultPool,
					vars.user,
					vars.remainingDCHFInStabPool
				);

				vars.remainingDCHFInStabPool = vars.remainingDCHFInStabPool.sub(
					singleLiquidation.debtToOffset
				);

				// Add liquidation values to their respective running totals
				totals = _addLiquidationValuesToTotals(totals, singleLiquidation);
			} else break; // break if the loop reaches a Trove with ICR >= MCR
		}
	}

	/*
	 * Attempt to liquidate a custom list of troves provided by the caller.
	 */
	function batchLiquidateTroves(address _asset, address[] memory _troveArray) public override {
		require(_troveArray.length != 0, "CA");

		IActivePool activePoolCached = dfrancParams.activePool();
		IDefaultPool defaultPoolCached = dfrancParams.defaultPool();
		IStabilityPool stabilityPoolCached = stabilityPoolManager.getAssetStabilityPool(_asset);

		LocalVariables_OuterLiquidationFunction memory vars;
		LiquidationTotals memory totals;

		vars.DCHFInStabPool = stabilityPoolCached.getTotalDCHFDeposits();
		vars.price = dfrancParams.priceFeed().fetchPrice(_asset);

		vars.recoveryModeAtStart = _checkRecoveryMode(_asset, vars.price);

		// Perform the appropriate liquidation sequence - tally values and obtain their totals.
		if (vars.recoveryModeAtStart) {
			totals = _getTotalFromBatchLiquidate_RecoveryMode(
				_asset,
				activePoolCached,
				defaultPoolCached,
				vars.price,
				vars.DCHFInStabPool,
				_troveArray
			);
		} else {
			//  if !vars.recoveryModeAtStart
			totals = _getTotalsFromBatchLiquidate_NormalMode(
				_asset,
				activePoolCached,
				defaultPoolCached,
				vars.price,
				vars.DCHFInStabPool,
				_troveArray
			);
		}

		require(totals.totalDebtInSequence > 0, "0L");

		// Move liquidated ETH and DCHF to the appropriate pools
		stabilityPoolCached.offset(totals.totalDebtToOffset, totals.totalCollToSendToSP);
		troveManagerHelpers.redistributeDebtAndColl(
			_asset,
			activePoolCached,
			defaultPoolCached,
			totals.totalDebtToRedistribute,
			totals.totalCollToRedistribute
		);
		if (totals.totalCollSurplus > 0) {
			activePoolCached.sendAsset(_asset, address(collSurplusPool), totals.totalCollSurplus);
		}

		// Update system snapshots
		troveManagerHelpers.updateSystemSnapshots_excludeCollRemainder(
			_asset,
			activePoolCached,
			totals.totalCollGasCompensation
		);

		vars.liquidatedDebt = totals.totalDebtInSequence;
		vars.liquidatedColl = totals.totalCollInSequence.sub(totals.totalCollGasCompensation).sub(
			totals.totalCollSurplus
		);
		emit Liquidation(
			_asset,
			vars.liquidatedDebt,
			vars.liquidatedColl,
			totals.totalCollGasCompensation,
			totals.totalDCHFGasCompensation
		);

		// Send gas compensation to caller
		_sendGasCompensation(
			_asset,
			activePoolCached,
			msg.sender,
			totals.totalDCHFGasCompensation,
			totals.totalCollGasCompensation
		);
	}

	/*
	 * This function is used when the batch liquidation sequence starts during Recovery Mode. However, it
	 * handle the case where the system *leaves* Recovery Mode, part way through the liquidation sequence
	 */
	function _getTotalFromBatchLiquidate_RecoveryMode(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _price,
		uint256 _DCHFInStabPool,
		address[] memory _troveArray
	) internal returns (LiquidationTotals memory totals) {
		LocalVariables_LiquidationSequence memory vars;
		LiquidationValues memory singleLiquidation;

		vars.remainingDCHFInStabPool = _DCHFInStabPool;
		vars.backToNormalMode = false;
		vars.entireSystemDebt = getEntireSystemDebt(_asset);
		vars.entireSystemColl = getEntireSystemColl(_asset);

		for (vars.i = 0; vars.i < _troveArray.length; vars.i++) {
			vars.user = _troveArray[vars.i];
			// Skip non-active troves
			if (troveManagerHelpers.getTroveStatus(_asset, vars.user) != 1) {
				continue;
			}

			vars.ICR = troveManagerHelpers.getCurrentICR(_asset, vars.user, _price);

			if (!vars.backToNormalMode) {
				// Skip this trove if ICR is greater than MCR and Stability Pool is empty
				if (vars.ICR >= dfrancParams.MCR(_asset) && vars.remainingDCHFInStabPool == 0) {
					continue;
				}

				uint256 TCR = DfrancMath._computeCR(
					vars.entireSystemColl,
					vars.entireSystemDebt,
					_price
				);

				singleLiquidation = _liquidateRecoveryMode(
					_asset,
					_activePool,
					_defaultPool,
					vars.user,
					vars.ICR,
					vars.remainingDCHFInStabPool,
					TCR,
					_price
				);

				// Update aggregate trackers
				vars.remainingDCHFInStabPool = vars.remainingDCHFInStabPool.sub(
					singleLiquidation.debtToOffset
				);
				vars.entireSystemDebt = vars.entireSystemDebt.sub(singleLiquidation.debtToOffset);
				vars.entireSystemColl = vars
					.entireSystemColl
					.sub(singleLiquidation.collToSendToSP)
					.sub(singleLiquidation.collGasCompensation)
					.sub(singleLiquidation.collSurplus);

				// Add liquidation values to their respective running totals
				totals = _addLiquidationValuesToTotals(totals, singleLiquidation);

				vars.backToNormalMode = !troveManagerHelpers._checkPotentialRecoveryMode(
					_asset,
					vars.entireSystemColl,
					vars.entireSystemDebt,
					_price
				);
			} else if (vars.backToNormalMode && vars.ICR < dfrancParams.MCR(_asset)) {
				singleLiquidation = _liquidateNormalMode(
					_asset,
					_activePool,
					_defaultPool,
					vars.user,
					vars.remainingDCHFInStabPool
				);
				vars.remainingDCHFInStabPool = vars.remainingDCHFInStabPool.sub(
					singleLiquidation.debtToOffset
				);

				// Add liquidation values to their respective running totals
				totals = _addLiquidationValuesToTotals(totals, singleLiquidation);
			} else continue; // In Normal Mode skip troves with ICR >= MCR
		}
	}

	function _getTotalsFromBatchLiquidate_NormalMode(
		address _asset,
		IActivePool _activePool,
		IDefaultPool _defaultPool,
		uint256 _price,
		uint256 _DCHFInStabPool,
		address[] memory _troveArray
	) internal returns (LiquidationTotals memory totals) {
		LocalVariables_LiquidationSequence memory vars;
		LiquidationValues memory singleLiquidation;

		vars.remainingDCHFInStabPool = _DCHFInStabPool;

		for (vars.i = 0; vars.i < _troveArray.length; vars.i++) {
			vars.user = _troveArray[vars.i];
			vars.ICR = troveManagerHelpers.getCurrentICR(_asset, vars.user, _price);

			if (vars.ICR < dfrancParams.MCR(_asset)) {
				singleLiquidation = _liquidateNormalMode(
					_asset,
					_activePool,
					_defaultPool,
					vars.user,
					vars.remainingDCHFInStabPool
				);
				vars.remainingDCHFInStabPool = vars.remainingDCHFInStabPool.sub(
					singleLiquidation.debtToOffset
				);

				// Add liquidation values to their respective running totals
				totals = _addLiquidationValuesToTotals(totals, singleLiquidation);
			}
		}
	}

	// --- Liquidation helper functions ---

	function _addLiquidationValuesToTotals(
		LiquidationTotals memory oldTotals,
		LiquidationValues memory singleLiquidation
	) internal pure returns (LiquidationTotals memory newTotals) {
		// Tally all the values with their respective running totals
		newTotals.totalCollGasCompensation = oldTotals.totalCollGasCompensation.add(
			singleLiquidation.collGasCompensation
		);
		newTotals.totalDCHFGasCompensation = oldTotals.totalDCHFGasCompensation.add(
			singleLiquidation.DCHFGasCompensation
		);
		newTotals.totalDebtInSequence = oldTotals.totalDebtInSequence.add(
			singleLiquidation.entireTroveDebt
		);
		newTotals.totalCollInSequence = oldTotals.totalCollInSequence.add(
			singleLiquidation.entireTroveColl
		);
		newTotals.totalDebtToOffset = oldTotals.totalDebtToOffset.add(
			singleLiquidation.debtToOffset
		);
		newTotals.totalCollToSendToSP = oldTotals.totalCollToSendToSP.add(
			singleLiquidation.collToSendToSP
		);
		newTotals.totalDebtToRedistribute = oldTotals.totalDebtToRedistribute.add(
			singleLiquidation.debtToRedistribute
		);
		newTotals.totalCollToRedistribute = oldTotals.totalCollToRedistribute.add(
			singleLiquidation.collToRedistribute
		);
		newTotals.totalCollSurplus = oldTotals.totalCollSurplus.add(singleLiquidation.collSurplus);

		return newTotals;
	}

	function _sendGasCompensation(
		address _asset,
		IActivePool _activePool,
		address _liquidator,
		uint256 _DCHF,
		uint256 _ETH
	) internal {
		if (_DCHF > 0) {
			dchfToken.returnFromPool(gasPoolAddress, _liquidator, _DCHF);
		}

		if (_ETH > 0) {
			_activePool.sendAsset(_asset, _liquidator, _ETH);
		}
	}

	// --- Redemption functions ---

	// Redeem as much collateral as possible from _borrower's Trove in exchange for DCHF up to _maxDCHFamount
	function _redeemCollateralFromTrove(
		address _asset,
		ContractsCache memory _contractsCache,
		address _borrower,
		uint256 _maxDCHFamount,
		uint256 _price,
		address _upperPartialRedemptionHint,
		address _lowerPartialRedemptionHint,
		uint256 _partialRedemptionHintNICR
	) internal returns (SingleRedemptionValues memory singleRedemption) {
		LocalVariables_AssetBorrowerPrice memory vars = LocalVariables_AssetBorrowerPrice(
			_asset,
			_borrower,
			_price
		);

		// Determine the remaining amount (lot) to be redeemed, capped by the entire debt of the Trove minus the liquidation reserve
		singleRedemption.DCHFLot = DfrancMath._min(
			_maxDCHFamount,
			troveManagerHelpers.getTroveDebt(vars._asset, vars._borrower).sub(
				dfrancParams.DCHF_GAS_COMPENSATION(_asset)
			)
		);

		// Get the ETHLot of equivalent value in USD
		singleRedemption.ETHLot = singleRedemption.DCHFLot.mul(DECIMAL_PRECISION).div(_price);

		// Decrease the debt and collateral of the current Trove according to the DCHF lot and corresponding ETH to send
		uint256 newDebt = (troveManagerHelpers.getTroveDebt(vars._asset, vars._borrower)).sub(
			singleRedemption.DCHFLot
		);
		uint256 newColl = (troveManagerHelpers.getTroveColl(vars._asset, vars._borrower)).sub(
			singleRedemption.ETHLot
		);

		if (newDebt == dfrancParams.DCHF_GAS_COMPENSATION(_asset)) {
			// No debt left in the Trove (except for the liquidation reserve), therefore the trove gets closed
			troveManagerHelpers.removeStake(vars._asset, vars._borrower);
			troveManagerHelpers.closeTrove(
				vars._asset,
				vars._borrower,
				ITroveManagerHelpers.Status.closedByRedemption
			);
			_redeemCloseTrove(
				vars._asset,
				_contractsCache,
				vars._borrower,
				dfrancParams.DCHF_GAS_COMPENSATION(vars._asset),
				newColl
			);
			emit TroveUpdated(
				vars._asset,
				vars._borrower,
				0,
				0,
				0,
				TroveManagerOperation.redeemCollateral
			);
		} else {
			uint256 newNICR = DfrancMath._computeNominalCR(newColl, newDebt);

			/*
			 * If the provided hint is out of date, we bail since trying to reinsert without a good hint will almost
			 * certainly result in running out of gas.
			 *
			 * If the resultant net debt of the partial is less than the minimum, net debt we bail.
			 */
			if (
				newNICR != _partialRedemptionHintNICR ||
				_getNetDebt(vars._asset, newDebt) < dfrancParams.MIN_NET_DEBT(vars._asset)
			) {
				singleRedemption.cancelledPartial = true;
				return singleRedemption;
			}

			_contractsCache.sortedTroves.reInsert(
				vars._asset,
				vars._borrower,
				newNICR,
				_upperPartialRedemptionHint,
				_lowerPartialRedemptionHint
			);

			troveManagerHelpers.setTroveDeptAndColl(vars._asset, vars._borrower, newDebt, newColl);
			troveManagerHelpers.updateStakeAndTotalStakes(vars._asset, vars._borrower);

			emit TroveUpdated(
				vars._asset,
				vars._borrower,
				newDebt,
				newColl,
				troveManagerHelpers.getTroveStake(vars._asset, vars._borrower),
				TroveManagerOperation.redeemCollateral
			);
		}

		return singleRedemption;
	}

	/*
	 * Called when a full redemption occurs, and closes the trove.
	 * The redeemer swaps (debt - liquidation reserve) DCHF for (debt - liquidation reserve) worth of ETH, so the DCHF liquidation reserve left corresponds to the remaining debt.
	 * In order to close the trove, the DCHF liquidation reserve is burned, and the corresponding debt is removed from the active pool.
	 * The debt recorded on the trove's struct is zero'd elswhere, in _closeTrove.
	 * Any surplus ETH left in the trove, is sent to the Coll surplus pool, and can be later claimed by the borrower.
	 */
	function _redeemCloseTrove(
		address _asset,
		ContractsCache memory _contractsCache,
		address _borrower,
		uint256 _DCHF,
		uint256 _ETH
	) internal {
		_contractsCache.dchfToken.burn(gasPoolAddress, _DCHF);
		// Update Active Pool DCHF, and send ETH to account
		_contractsCache.activePool.decreaseDCHFDebt(_asset, _DCHF);

		// send ETH from Active Pool to CollSurplus Pool
		_contractsCache.collSurplusPool.accountSurplus(_asset, _borrower, _ETH);
		_contractsCache.activePool.sendAsset(
			_asset,
			address(_contractsCache.collSurplusPool),
			_ETH
		);
	}

	function _isValidFirstRedemptionHint(
		address _asset,
		ISortedTroves _sortedTroves,
		address _firstRedemptionHint,
		uint256 _price
	) internal view returns (bool) {
		if (
			_firstRedemptionHint == address(0) ||
			!_sortedTroves.contains(_asset, _firstRedemptionHint) ||
			troveManagerHelpers.getCurrentICR(_asset, _firstRedemptionHint, _price) <
			dfrancParams.MCR(_asset)
		) {
			return false;
		}

		address nextTrove = _sortedTroves.getNext(_asset, _firstRedemptionHint);
		return
			nextTrove == address(0) ||
			troveManagerHelpers.getCurrentICR(_asset, nextTrove, _price) < dfrancParams.MCR(_asset);
	}

	function setRedemptionWhitelistStatus(bool _status) external onlyOwner {
		isRedemptionWhitelisted = _status;
	}

	function addUserToWhitelistRedemption(address _user) external onlyOwner {
		redemptionWhitelist[_user] = true;
	}

	function removeUserFromWhitelistRedemption(address _user) external onlyOwner {
		delete redemptionWhitelist[_user];
	}

	/* Send _DCHFamount DCHF to the system and redeem the corresponding amount of collateral from as many Troves as are needed to fill the redemption
	 * request.  Applies pending rewards to a Trove before reducing its debt and coll.
	 *
	 * Note that if _amount is very large, this function can run out of gas, specially if traversed troves are small. This can be easily avoided by
	 * splitting the total _amount in appropriate chunks and calling the function multiple times.
	 *
	 * Param `_maxIterations` can also be provided, so the loop through Troves is capped (if it’s zero, it will be ignored).This makes it easier to
	 * avoid OOG for the frontend, as only knowing approximately the average cost of an iteration is enough, without needing to know the “topology”
	 * of the trove list. It also avoids the need to set the cap in stone in the contract, nor doing gas calculations, as both gas price and opcode
	 * costs can vary.
	 *
	 * All Troves that are redeemed from -- with the likely exception of the last one -- will end up with no debt left, therefore they will be closed.
	 * If the last Trove does have some remaining debt, it has a finite ICR, and the reinsertion could be anywhere in the list, therefore it requires a hint.
	 * A frontend should use getRedemptionHints() to calculate what the ICR of this Trove will be after redemption, and pass a hint for its position
	 * in the sortedTroves list along with the ICR value that the hint was found for.
	 *
	 * If another transaction modifies the list between calling getRedemptionHints() and passing the hints to redeemCollateral(), it
	 * is very likely that the last (partially) redeemed Trove would end up with a different ICR than what the hint is for. In this case the
	 * redemption will stop after the last completely redeemed Trove and the sender will keep the remaining DCHF amount, which they can attempt
	 * to redeem later.
	 */
	function redeemCollateral(
		address _asset,
		uint256 _DCHFamount,
		address _firstRedemptionHint,
		address _upperPartialRedemptionHint,
		address _lowerPartialRedemptionHint,
		uint256 _partialRedemptionHintNICR,
		uint256 _maxIterations,
		uint256 _maxFeePercentage
	) external override {
		if (isRedemptionWhitelisted) {
			require(redemptionWhitelist[msg.sender], "NW");
		}

		require(block.timestamp >= dfrancParams.redemptionBlock(_asset), "BR");

		ContractsCache memory contractsCache = ContractsCache(
			dfrancParams.activePool(),
			dfrancParams.defaultPool(),
			dchfToken,
			monStaking,
			sortedTroves,
			collSurplusPool,
			gasPoolAddress
		);
		RedemptionTotals memory totals;

		troveManagerHelpers._requireValidMaxFeePercentage(_asset, _maxFeePercentage);
		totals.price = dfrancParams.priceFeed().fetchPrice(_asset);
		troveManagerHelpers._requireTCRoverMCR(_asset, totals.price);
		troveManagerHelpers._requireAmountGreaterThanZero(_DCHFamount);
		troveManagerHelpers._requireDCHFBalanceCoversRedemption(
			contractsCache.dchfToken,
			msg.sender,
			_DCHFamount
		);

		totals.totalDCHFSupplyAtStart = getEntireSystemDebt(_asset);
		totals.remainingDCHF = _DCHFamount;
		address currentBorrower;

		if (
			_isValidFirstRedemptionHint(
				_asset,
				contractsCache.sortedTroves,
				_firstRedemptionHint,
				totals.price
			)
		) {
			currentBorrower = _firstRedemptionHint;
		} else {
			currentBorrower = contractsCache.sortedTroves.getLast(_asset);
			// Find the first trove with ICR >= MCR
			while (
				currentBorrower != address(0) &&
				troveManagerHelpers.getCurrentICR(_asset, currentBorrower, totals.price) <
				dfrancParams.MCR(_asset)
			) {
				currentBorrower = contractsCache.sortedTroves.getPrev(_asset, currentBorrower);
			}
		}

		// Loop through the Troves starting from the one with lowest collateral ratio until _amount of DCHF is exchanged for collateral
		if (_maxIterations == 0) {
			_maxIterations = type(uint256).max;
		}
		while (currentBorrower != address(0) && totals.remainingDCHF > 0 && _maxIterations > 0) {
			_maxIterations--;
			// Save the address of the Trove preceding the current one, before potentially modifying the list
			address nextUserToCheck = contractsCache.sortedTroves.getPrev(_asset, currentBorrower);

			troveManagerHelpers.applyPendingRewards(
				_asset,
				contractsCache.activePool,
				contractsCache.defaultPool,
				currentBorrower
			);

			SingleRedemptionValues memory singleRedemption = _redeemCollateralFromTrove(
				_asset,
				contractsCache,
				currentBorrower,
				totals.remainingDCHF,
				totals.price,
				_upperPartialRedemptionHint,
				_lowerPartialRedemptionHint,
				_partialRedemptionHintNICR
			);

			if (singleRedemption.cancelledPartial) break; // Partial redemption was cancelled (out-of-date hint, or new net debt < minimum), therefore we could not redeem from the last Trove

			totals.totalDCHFToRedeem = totals.totalDCHFToRedeem.add(singleRedemption.DCHFLot);
			totals.totalAssetDrawn = totals.totalAssetDrawn.add(singleRedemption.ETHLot);

			totals.remainingDCHF = totals.remainingDCHF.sub(singleRedemption.DCHFLot);
			currentBorrower = nextUserToCheck;
		}
		require(totals.totalAssetDrawn > 0, "UR");

		// Decay the baseRate due to time passed, and then increase it according to the size of this redemption.
		// Use the saved total DCHF supply value, from before it was reduced by the redemption.
		troveManagerHelpers.updateBaseRateFromRedemption(
			_asset,
			totals.totalAssetDrawn,
			totals.price,
			totals.totalDCHFSupplyAtStart
		);

		// Calculate the ETH fee
		totals.ETHFee = troveManagerHelpers._getRedemptionFee(_asset, totals.totalAssetDrawn);

		_requireUserAcceptsFee(totals.ETHFee, totals.totalAssetDrawn, _maxFeePercentage);

		// Send the ETH fee to the MON staking contract
		contractsCache.activePool.sendAsset(
			_asset,
			address(contractsCache.monStaking),
			totals.ETHFee
		);
		contractsCache.monStaking.increaseF_Asset(_asset, totals.ETHFee);

		totals.ETHToSendToRedeemer = totals.totalAssetDrawn.sub(totals.ETHFee);

		emit Redemption(
			_asset,
			_DCHFamount,
			totals.totalDCHFToRedeem,
			totals.totalAssetDrawn,
			totals.ETHFee
		);

		// Burn the total DCHF that is cancelled with debt, and send the redeemed ETH to msg.sender
		contractsCache.dchfToken.burn(msg.sender, totals.totalDCHFToRedeem);
		// Update Active Pool DCHF, and send ETH to account
		contractsCache.activePool.decreaseDCHFDebt(_asset, totals.totalDCHFToRedeem);
		contractsCache.activePool.sendAsset(_asset, msg.sender, totals.ETHToSendToRedeemer);
	}
}

File 8 of 33 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @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;
    }
}

File 9 of 33 : IDfrancBase.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;
import "./IDfrancParameters.sol";

interface IDfrancBase {
	event VaultParametersBaseChanged(address indexed newAddress);

	function dfrancParams() external view returns (IDfrancParameters);
}

File 10 of 33 : IStabilityPool.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "./IDeposit.sol";

interface IStabilityPool is IDeposit {
	// --- Events ---
	event StabilityPoolAssetBalanceUpdated(uint256 _newBalance);
	event StabilityPoolDCHFBalanceUpdated(uint256 _newBalance);

	event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
	event TroveManagerAddressChanged(address _newTroveManagerAddress);
	event DefaultPoolAddressChanged(address _newDefaultPoolAddress);
	event DCHFTokenAddressChanged(address _newDCHFTokenAddress);
	event SortedTrovesAddressChanged(address _newSortedTrovesAddress);
	event CommunityIssuanceAddressChanged(address _newCommunityIssuanceAddress);

	event P_Updated(uint256 _P);
	event S_Updated(uint256 _S, uint128 _epoch, uint128 _scale);
	event G_Updated(uint256 _G, uint128 _epoch, uint128 _scale);
	event EpochUpdated(uint128 _currentEpoch);
	event ScaleUpdated(uint128 _currentScale);

	event DepositSnapshotUpdated(address indexed _depositor, uint256 _P, uint256 _S, uint256 _G);
	event SystemSnapshotUpdated(uint256 _P, uint256 _G);
	event UserDepositChanged(address indexed _depositor, uint256 _newDeposit);
	event StakeChanged(uint256 _newSystemStake, address _depositor);

	event AssetGainWithdrawn(address indexed _depositor, uint256 _Asset, uint256 _DCHFLoss);
	event MONPaidToDepositor(address indexed _depositor, uint256 _MON);
	event AssetSent(address _to, uint256 _amount);

	// --- Functions ---

	function NAME() external view returns (string memory name);

	/*
	 * Called only once on init, to set addresses of other Dfranc contracts
	 * Callable only by owner, renounces ownership at the end
	 */
	function setAddresses(
		address _assetAddress,
		address _borrowerOperationsAddress,
		address _troveManagerAddress,
		address _troveManagerHelperAddress,
		address _dchfTokenAddress,
		address _sortedTrovesAddress,
		address _communityIssuanceAddress,
		address _dfrancParamsAddress
	) external;

	/*
	 * Initial checks:
	 * - Frontend is registered or zero address
	 * - Sender is not a registered frontend
	 * - _amount is not zero
	 * ---
	 * - Triggers a MON issuance, based on time passed since the last issuance. The MON issuance is shared between *all* depositors and front ends
	 * - Tags the deposit with the provided front end tag param, if it's a new deposit
	 * - Sends depositor's accumulated gains (MON, ETH) to depositor
	 * - Sends the tagged front end's accumulated MON gains to the tagged front end
	 * - Increases deposit and tagged front end's stake, and takes new snapshots for each.
	 */
	function provideToSP(uint256 _amount) external;

	/*
	 * Initial checks:
	 * - _amount is zero or there are no under collateralized troves left in the system
	 * - User has a non zero deposit
	 * ---
	 * - Triggers a MON issuance, based on time passed since the last issuance. The MON issuance is shared between *all* depositors and front ends
	 * - Removes the deposit's front end tag if it is a full withdrawal
	 * - Sends all depositor's accumulated gains (MON, ETH) to depositor
	 * - Sends the tagged front end's accumulated MON gains to the tagged front end
	 * - Decreases deposit and tagged front end's stake, and takes new snapshots for each.
	 *
	 * If _amount > userDeposit, the user withdraws all of their compounded deposit.
	 */
	function withdrawFromSP(uint256 _amount) external;

	/*
	 * Initial checks:
	 * - User has a non zero deposit
	 * - User has an open trove
	 * - User has some ETH gain
	 * ---
	 * - Triggers a MON issuance, based on time passed since the last issuance. The MON issuance is shared between *all* depositors and front ends
	 * - Sends all depositor's MON gain to  depositor
	 * - Sends all tagged front end's MON gain to the tagged front end
	 * - Transfers the depositor's entire ETH gain from the Stability Pool to the caller's trove
	 * - Leaves their compounded deposit in the Stability Pool
	 * - Updates snapshots for deposit and tagged front end stake
	 */
	function withdrawAssetGainToTrove(address _upperHint, address _lowerHint) external;

	/*
	 * Initial checks:
	 * - Caller is TroveManager
	 * ---
	 * Cancels out the specified debt against the DCHF contained in the Stability Pool (as far as possible)
	 * and transfers the Trove's ETH collateral from ActivePool to StabilityPool.
	 * Only called by liquidation functions in the TroveManager.
	 */
	function offset(uint256 _debt, uint256 _coll) external;

	/*
	 * Returns the total amount of ETH held by the pool, accounted in an internal variable instead of `balance`,
	 * to exclude edge cases like ETH received from a self-destruct.
	 */
	function getAssetBalance() external view returns (uint256);

	/*
	 * Returns DCHF held in the pool. Changes when users deposit/withdraw, and when Trove debt is offset.
	 */
	function getTotalDCHFDeposits() external view returns (uint256);

	/*
	 * Calculates the ETH gain earned by the deposit since its last snapshots were taken.
	 */
	function getDepositorAssetGain(address _depositor) external view returns (uint256);

	/*
	 * Calculate the MON gain earned by a deposit since its last snapshots were taken.
	 * If not tagged with a front end, the depositor gets a 100% cut of what their deposit earned.
	 * Otherwise, their cut of the deposit's earnings is equal to the kickbackRate, set by the front end through
	 * which they made their deposit.
	 */
	function getDepositorMONGain(address _depositor) external view returns (uint256);

	/*
	 * Return the user's compounded deposit.
	 */
	function getCompoundedDCHFDeposit(address _depositor) external view returns (uint256);

	/*
	 * Return the front end's compounded stake.
	 *
	 * The front end's compounded stake is equal to the sum of its depositors' compounded deposits.
	 */
	function getCompoundedTotalStake() external view returns (uint256);

	function getNameBytes() external view returns (bytes32);

	function getAssetType() external view returns (address);

	/*
	 * Fallback function
	 * Only callable by Active Pool, it just accounts for ETH received
	 * receive() external payable;
	 */
}

File 11 of 33 : IDCHFToken.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;
import "../Dependencies/ERC20Permit.sol";
import "../Interfaces/IStabilityPoolManager.sol";

abstract contract IDCHFToken is ERC20Permit {
	// --- Events ---

	event StabilityPoolAddressChanged(address _newStabilityPoolAddress);

	event DCHFTokenBalanceUpdated(address _user, uint256 _amount);

	function emergencyStopMinting(address _asset, bool status) external virtual;

	function addTroveManager(address _troveManager) external virtual;

	function removeTroveManager(address _troveManager) external virtual;

	function addBorrowerOps(address _borrowerOps) external virtual;

	function removeBorrowerOps(address _borrowerOps) external virtual;

	function mint(
		address _asset,
		address _account,
		uint256 _amount
	) external virtual;

	function burn(address _account, uint256 _amount) external virtual;

	function sendToPool(
		address _sender,
		address poolAddress,
		uint256 _amount
	) external virtual;

	function returnFromPool(
		address poolAddress,
		address user,
		uint256 _amount
	) external virtual;
}

File 12 of 33 : IMONStaking.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

interface IMONStaking {
	// --- Events --

	event TreasuryAddressChanged(address _treausury);
	event SentToTreasury(address indexed _asset, uint256 _amount);
	event MONTokenAddressSet(address _MONTokenAddress);
	event DCHFTokenAddressSet(address _dchfTokenAddress);
	event TroveManagerAddressSet(address _troveManager);
	event BorrowerOperationsAddressSet(address _borrowerOperationsAddress);
	event ActivePoolAddressSet(address _activePoolAddress);

	event StakeChanged(address indexed staker, uint256 newStake);
	event StakingGainsAssetWithdrawn(
		address indexed staker,
		address indexed asset,
		uint256 AssetGain
	);
	event StakingGainsDCHFWithdrawn(address indexed staker, uint256 DCHFGain);
	event F_AssetUpdated(address indexed _asset, uint256 _F_ASSET);
	event F_DCHFUpdated(uint256 _F_DCHF);
	event TotalMONStakedUpdated(uint256 _totalMONStaked);
	event AssetSent(address indexed _asset, address indexed _account, uint256 _amount);
	event StakerSnapshotsUpdated(address _staker, uint256 _F_Asset, uint256 _F_DCHF);

	function monToken() external view returns (IERC20);

	// --- Functions ---

	function setAddresses(
		address _MONTokenAddress,
		address _dchfTokenAddress,
		address _troveManagerAddress,
		address _troveManagerHelpersAddress,
		address _borrowerOperationsAddress,
		address _activePoolAddress,
		address _treasury
	) external;

	function stake(uint256 _MONamount) external;

	function unstake(uint256 _MONamount) external;

	function increaseF_Asset(address _asset, uint256 _AssetFee) external;

	function increaseF_DCHF(uint256 _MONFee) external;

	function getPendingAssetGain(address _asset, address _user) external view returns (uint256);

	function getPendingDCHFGain(address _user) external view returns (uint256);
}

File 13 of 33 : ICollSurplusPool.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "./IDeposit.sol";

interface ICollSurplusPool is IDeposit {
	// --- Events ---

	event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
	event TroveManagerAddressChanged(address _newTroveManagerAddress);
	event ActivePoolAddressChanged(address _newActivePoolAddress);

	event CollBalanceUpdated(address indexed _account, uint256 _newBalance);
	event AssetSent(address _to, uint256 _amount);

	// --- Contract setters ---

	function setAddresses(
		address _borrowerOperationsAddress,
		address _troveManagerAddress,
		address _troveManagerHelpersAddress,
		address _activePoolAddress
	) external;

	function getAssetBalance(address _asset) external view returns (uint256);

	function getCollateral(address _asset, address _account) external view returns (uint256);

	function accountSurplus(
		address _asset,
		address _account,
		uint256 _amount
	) external;

	function claimColl(address _asset, address _account) external;
}

File 14 of 33 : ISortedTroves.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

// Common interface for the SortedTroves Doubly Linked List.
interface ISortedTroves {
	// --- Events ---

	event SortedTrovesAddressChanged(address _sortedDoublyLLAddress);
	event BorrowerOperationsAddressChanged(address _borrowerOperationsAddress);
	event NodeAdded(address indexed _asset, address _id, uint256 _NICR);
	event NodeRemoved(address indexed _asset, address _id);

	// --- Functions ---

	function setParams(
		address _TroveManagerAddress,
		address _troveManagerHelpersAddress,
		address _borrowerOperationsAddress
	) external;

	function insert(
		address _asset,
		address _id,
		uint256 _ICR,
		address _prevId,
		address _nextId
	) external;

	function remove(address _asset, address _id) external;

	function reInsert(
		address _asset,
		address _id,
		uint256 _newICR,
		address _prevId,
		address _nextId
	) external;

	function contains(address _asset, address _id) external view returns (bool);

	function isFull(address _asset) external view returns (bool);

	function isEmpty(address _asset) external view returns (bool);

	function getSize(address _asset) external view returns (uint256);

	function getMaxSize(address _asset) external view returns (uint256);

	function getFirst(address _asset) external view returns (address);

	function getLast(address _asset) external view returns (address);

	function getNext(address _asset, address _id) external view returns (address);

	function getPrev(address _asset, address _id) external view returns (address);

	function validInsertPosition(
		address _asset,
		uint256 _ICR,
		address _prevId,
		address _nextId
	) external view returns (bool);

	function findInsertPosition(
		address _asset,
		uint256 _ICR,
		address _prevId,
		address _nextId
	) external view returns (address, address);
}

File 15 of 33 : IActivePool.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;
import "./IPool.sol";

interface IActivePool is IPool {
	// --- Events ---
	event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
	event TroveManagerAddressChanged(address _newTroveManagerAddress);
	event ActivePoolDCHFDebtUpdated(address _asset, uint256 _DCHFDebt);
	event ActivePoolAssetBalanceUpdated(address _asset, uint256 _balance);

	// --- Functions ---
	function sendAsset(
		address _asset,
		address _account,
		uint256 _amount
	) external;
}

File 16 of 33 : IDefaultPool.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;
import "./IPool.sol";

interface IDefaultPool is IPool {
	// --- Events ---
	event TroveManagerAddressChanged(address _newTroveManagerAddress);
	event DefaultPoolDCHFDebtUpdated(address _asset, uint256 _DCHFDebt);
	event DefaultPoolAssetBalanceUpdated(address _asset, uint256 _balance);

	// --- Functions ---
	function sendAssetToActivePool(address _asset, uint256 _amount) external;
}

File 17 of 33 : IStabilityPoolManager.sol
pragma solidity ^0.8.14;

import "./IStabilityPool.sol";

interface IStabilityPoolManager {
	event StabilityPoolAdded(address asset, address stabilityPool);
	event StabilityPoolRemoved(address asset, address stabilityPool);

	function isStabilityPool(address stabilityPool) external view returns (bool);

	function addStabilityPool(address asset, address stabilityPool) external;

	function getAssetStabilityPool(address asset) external view returns (IStabilityPool);

	function unsafeGetAssetStabilityPool(address asset) external view returns (address);
}

File 18 of 33 : IDfrancParameters.sol
pragma solidity ^0.8.14;

import "./IActivePool.sol";
import "./IDefaultPool.sol";
import "./IPriceFeed.sol";
import "./IDfrancBase.sol";

interface IDfrancParameters {
	error SafeCheckError(
		string parameter,
		uint256 valueEntered,
		uint256 minValue,
		uint256 maxValue
	);

	event MCRChanged(uint256 oldMCR, uint256 newMCR);
	event CCRChanged(uint256 oldCCR, uint256 newCCR);
	event GasCompensationChanged(uint256 oldGasComp, uint256 newGasComp);
	event MinNetDebtChanged(uint256 oldMinNet, uint256 newMinNet);
	event PercentDivisorChanged(uint256 oldPercentDiv, uint256 newPercentDiv);
	event BorrowingFeeFloorChanged(uint256 oldBorrowingFloorFee, uint256 newBorrowingFloorFee);
	event MaxBorrowingFeeChanged(uint256 oldMaxBorrowingFee, uint256 newMaxBorrowingFee);
	event RedemptionFeeFloorChanged(
		uint256 oldRedemptionFeeFloor,
		uint256 newRedemptionFeeFloor
	);
	event RedemptionBlockRemoved(address _asset);
	event PriceFeedChanged(address indexed addr);

	function DECIMAL_PRECISION() external view returns (uint256);

	function _100pct() external view returns (uint256);

	// Minimum collateral ratio for individual troves
	function MCR(address _collateral) external view returns (uint256);

	// Critical system collateral ratio. If the system's total collateral ratio (TCR) falls below the CCR, Recovery Mode is triggered.
	function CCR(address _collateral) external view returns (uint256);

	function DCHF_GAS_COMPENSATION(address _collateral) external view returns (uint256);

	function MIN_NET_DEBT(address _collateral) external view returns (uint256);

	function PERCENT_DIVISOR(address _collateral) external view returns (uint256);

	function BORROWING_FEE_FLOOR(address _collateral) external view returns (uint256);

	function REDEMPTION_FEE_FLOOR(address _collateral) external view returns (uint256);

	function MAX_BORROWING_FEE(address _collateral) external view returns (uint256);

	function redemptionBlock(address _collateral) external view returns (uint256);

	function activePool() external view returns (IActivePool);

	function defaultPool() external view returns (IDefaultPool);

	function priceFeed() external view returns (IPriceFeed);

	function setAddresses(
		address _activePool,
		address _defaultPool,
		address _priceFeed,
		address _adminContract
	) external;

	function setPriceFeed(address _priceFeed) external;

	function setMCR(address _asset, uint256 newMCR) external;

	function setCCR(address _asset, uint256 newCCR) external;

	function sanitizeParameters(address _asset) external;

	function setAsDefault(address _asset) external;

	function setAsDefaultWithRemptionBlock(address _asset, uint256 blockInDays) external;

	function setDCHFGasCompensation(address _asset, uint256 gasCompensation) external;

	function setMinNetDebt(address _asset, uint256 minNetDebt) external;

	function setPercentDivisor(address _asset, uint256 precentDivisor) external;

	function setBorrowingFeeFloor(address _asset, uint256 borrowingFeeFloor) external;

	function setMaxBorrowingFee(address _asset, uint256 maxBorrowingFee) external;

	function setRedemptionFeeFloor(address _asset, uint256 redemptionFeeFloor) external;

	function removeRedemptionBlock(address _asset) external;
}

File 19 of 33 : IPriceFeed.sol
// SPDX-License-Identifier: MIT
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

pragma solidity ^0.8.14;

interface IPriceFeed {
	struct ChainlinkResponse {
		uint80 roundId;
		int256 answer;
		uint256 timestamp;
		bool success;
		uint8 decimals;
	}

	struct RegisterOracle {
		AggregatorV3Interface chainLinkOracle;
		AggregatorV3Interface chainLinkIndex;
		bool isRegistered;
	}

	enum Status {
		chainlinkWorking,
		chainlinkUntrusted
	}

	// --- Events ---
	event PriceFeedStatusChanged(Status newStatus);
	event LastGoodPriceUpdated(address indexed token, uint256 _lastGoodPrice);
	event LastGoodIndexUpdated(address indexed token, uint256 _lastGoodIndex);
	event RegisteredNewOracle(
		address token,
		address chainLinkAggregator,
		address chianLinkIndex
	);

	// --- Function ---
	function addOracle(
		address _token,
		address _chainlinkOracle,
		address _chainlinkIndexOracle
	) external;

	function fetchPrice(address _token) external returns (uint256);

	function getDirectPrice(address _asset) external returns (uint256);
}

File 20 of 33 : IPool.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "./IDeposit.sol";

// Common interface for the Pools.
interface IPool is IDeposit {
	// --- Events ---

	event AssetBalanceUpdated(uint256 _newBalance);
	event DCHFBalanceUpdated(uint256 _newBalance);
	event ActivePoolAddressChanged(address _newActivePoolAddress);
	event DefaultPoolAddressChanged(address _newDefaultPoolAddress);
	event AssetAddressChanged(address _assetAddress);
	event StabilityPoolAddressChanged(address _newStabilityPoolAddress);
	event AssetSent(address _to, address indexed _asset, uint256 _amount);

	// --- Functions ---

	function getAssetBalance(address _asset) external view returns (uint256);

	function getDCHFDebt(address _asset) external view returns (uint256);

	function increaseDCHFDebt(address _asset, uint256 _amount) external;

	function decreaseDCHFDebt(address _asset, uint256 _amount) external;
}

File 21 of 33 : IDeposit.sol
pragma solidity ^0.8.14;

interface IDeposit {
	function receivedERC20(address _asset, uint256 _amount) external;
}

File 22 of 33 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {

  function decimals()
    external
    view
    returns (
      uint8
    );

  function description()
    external
    view
    returns (
      string memory
    );

  function version()
    external
    view
    returns (
      uint256
    );

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  function getRoundData(
    uint80 _roundId
  )
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

}

File 23 of 33 : ERC20Permit.sol
pragma solidity ^0.8.14;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

interface IERC2612Permit {
	/**
	 * @dev Sets `amount` as the allowance of `spender` over `owner`'s tokens,
	 * given `owner`'s signed approval.
	 *
	 * IMPORTANT: The same issues {IERC20-approve} has related to transaction
	 * ordering also apply here.
	 *
	 * Emits an {Approval} event.
	 *
	 * Requirements:
	 *
	 * - `owner` cannot be the zero address.
	 * - `spender` cannot be the zero address.
	 * - `deadline` must be a timestamp in the future.
	 * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
	 * over the EIP712-formatted function arguments.
	 * - the signature must use ``owner``'s current nonce (see {nonces}).
	 *
	 * For more information on the signature format, see the
	 * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
	 * section].
	 */
	function permit(
		address owner,
		address spender,
		uint256 amount,
		uint256 deadline,
		uint8 v,
		bytes32 r,
		bytes32 s
	) external;

	/**
	 * @dev Returns the current ERC2612 nonce for `owner`. This value must be
	 * included whenever a signature is generated for {permit}.
	 *
	 * Every successful call to {permit} increases ``owner``'s nonce by one. This
	 * prevents a signature from being used multiple times.
	 */
	function nonces(address owner) external view returns (uint256);
}

abstract contract ERC20Permit is ERC20, IERC2612Permit {
	using Counters for Counters.Counter;

	mapping(address => Counters.Counter) private _nonces;

	// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
	bytes32 public constant PERMIT_TYPEHASH =
		0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;

	bytes32 public DOMAIN_SEPARATOR;

	constructor() {
		uint256 chainID;
		assembly {
			chainID := chainid()
		}

		DOMAIN_SEPARATOR = keccak256(
			abi.encode(
				keccak256(
					"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
				),
				keccak256(bytes(name())),
				keccak256(bytes("1")), // Version
				chainID,
				address(this)
			)
		);
	}

	/**
	 * @dev See {IERC2612Permit-permit}.
	 *
	 */
	function permit(
		address owner,
		address spender,
		uint256 amount,
		uint256 deadline,
		uint8 v,
		bytes32 r,
		bytes32 s
	) external virtual override {
		require(block.timestamp <= deadline, "Permit: expired deadline");

		bytes32 hashStruct = keccak256(
			abi.encode(PERMIT_TYPEHASH, owner, spender, amount, _nonces[owner].current(), deadline)
		);

		bytes32 _hash = keccak256(abi.encodePacked(uint16(0x1901), DOMAIN_SEPARATOR, hashStruct));

		address signer = ecrecover(_hash, v, r, s);
		require(signer != address(0) && signer == owner, "ERC20Permit: Invalid signature");

		_nonces[owner].increment();
		_approve(owner, spender, amount);
	}

	/**
	 * @dev See {IERC2612Permit-nonces}.
	 */
	function nonces(address owner) public view override returns (uint256) {
		return _nonces[owner].current();
	}

	function chainId() public view returns (uint256 chainID) {
		assembly {
			chainID := chainid()
		}
	}
}

File 24 of 33 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

File 25 of 33 : Counters.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

File 26 of 33 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @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);
}

File 27 of 33 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
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);
}

File 28 of 33 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
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));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        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 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    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");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 29 of 33 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 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 functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 30 of 33 : BaseMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

abstract contract BaseMath {
	uint256 public constant DECIMAL_PRECISION = 1 ether;
}

File 31 of 33 : DfrancMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

library DfrancMath {
	using SafeMath for uint256;

	uint256 internal constant DECIMAL_PRECISION = 1 ether;

	/* Precision for Nominal ICR (independent of price). Rationale for the value:
	 *
	 * - Making it “too high” could lead to overflows.
	 * - Making it “too low” could lead to an ICR equal to zero, due to truncation from Solidity floor division.
	 *
	 * This value of 1e20 is chosen for safety: the NICR will only overflow for numerator > ~1e39 ETH,
	 * and will only truncate to 0 if the denominator is at least 1e20 times greater than the numerator.
	 *
	 */
	uint256 internal constant NICR_PRECISION = 1e20;

	function _min(uint256 _a, uint256 _b) internal pure returns (uint256) {
		return (_a < _b) ? _a : _b;
	}

	function _max(uint256 _a, uint256 _b) internal pure returns (uint256) {
		return (_a >= _b) ? _a : _b;
	}

	/*
	 * Multiply two decimal numbers and use normal rounding rules:
	 * -round product up if 19'th mantissa digit >= 5
	 * -round product down if 19'th mantissa digit < 5
	 *
	 * Used only inside the exponentiation, _decPow().
	 */
	function decMul(uint256 x, uint256 y) internal pure returns (uint256 decProd) {
		uint256 prod_xy = x.mul(y);

		decProd = prod_xy.add(DECIMAL_PRECISION / 2).div(DECIMAL_PRECISION);
	}

	/*
	 * _decPow: Exponentiation function for 18-digit decimal base, and integer exponent n.
	 *
	 * Uses the efficient "exponentiation by squaring" algorithm. O(log(n)) complexity.
	 *
	 * Called by two functions that represent time in units of minutes:
	 * 1) TroveManager._calcDecayedBaseRate
	 * 2) CommunityIssuance._getCumulativeIssuanceFraction
	 *
	 * The exponent is capped to avoid reverting due to overflow. The cap 525600000 equals
	 * "minutes in 1000 years": 60 * 24 * 365 * 1000
	 *
	 * If a period of > 1000 years is ever used as an exponent in either of the above functions, the result will be
	 * negligibly different from just passing the cap, since:
	 *
	 * In function 1), the decayed base rate will be 0 for 1000 years or > 1000 years
	 * In function 2), the difference in tokens issued at 1000 years and any time > 1000 years, will be negligible
	 */
	function _decPow(uint256 _base, uint256 _minutes) internal pure returns (uint256) {
		if (_minutes > 525600000) {
			_minutes = 525600000;
		} // cap to avoid overflow

		if (_minutes == 0) {
			return DECIMAL_PRECISION;
		}

		uint256 y = DECIMAL_PRECISION;
		uint256 x = _base;
		uint256 n = _minutes;

		// Exponentiation-by-squaring
		while (n > 1) {
			if (n % 2 == 0) {
				x = decMul(x, x);
				n = n.div(2);
			} else {
				// if (n % 2 != 0)
				y = decMul(x, y);
				x = decMul(x, x);
				n = (n.sub(1)).div(2);
			}
		}

		return decMul(x, y);
	}

	function _getAbsoluteDifference(uint256 _a, uint256 _b) internal pure returns (uint256) {
		return (_a >= _b) ? _a.sub(_b) : _b.sub(_a);
	}

	function _computeNominalCR(uint256 _coll, uint256 _debt) internal pure returns (uint256) {
		if (_debt > 0) {
			return _coll.mul(NICR_PRECISION).div(_debt);
		}
		// Return the maximal value for uint256 if the Trove has a debt of 0. Represents "infinite" CR.
		else {
			// if (_debt == 0)
			return 2**256 - 1;
		}
	}

	function _computeCR(
		uint256 _coll,
		uint256 _debt,
		uint256 _price
	) internal pure returns (uint256) {
		if (_debt > 0) {

			return _coll.mul(_price).div(_debt);
		}
		// Return the maximal value for uint256 if the Trove has a debt of 0. Represents "infinite" CR.
		else {
			// if (_debt == 0)
			return type(uint256).max;
		}
	}
}

File 32 of 33 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

File 33 of 33 : ITroveManager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;
import "./IDfrancBase.sol";
import "./IStabilityPool.sol";
import "./IDCHFToken.sol";
import "./IMONStaking.sol";
import "./ICollSurplusPool.sol";
import "./ISortedTroves.sol";
import "./IActivePool.sol";
import "./IDefaultPool.sol";
import "./IStabilityPoolManager.sol";
import "./ITroveManagerHelpers.sol";

// Common interface for the Trove Manager.
interface ITroveManager is IDfrancBase {
	enum Status {
		nonExistent,
		active,
		closedByOwner,
		closedByLiquidation,
		closedByRedemption
	}

	// Store the necessary data for a trove
	struct Trove {
		address asset;
		uint256 debt;
		uint256 coll;
		uint256 stake;
		Status status;
		uint128 arrayIndex;
	}

	/*
	 * --- Variable container structs for liquidations ---
	 *
	 * These structs are used to hold, return and assign variables inside the liquidation functions,
	 * in order to avoid the error: "CompilerError: Stack too deep".
	 **/

	struct LocalVariables_OuterLiquidationFunction {
		uint256 price;
		uint256 DCHFInStabPool;
		bool recoveryModeAtStart;
		uint256 liquidatedDebt;
		uint256 liquidatedColl;
	}

	struct LocalVariables_InnerSingleLiquidateFunction {
		uint256 collToLiquidate;
		uint256 pendingDebtReward;
		uint256 pendingCollReward;
	}

	struct LocalVariables_LiquidationSequence {
		uint256 remainingDCHFInStabPool;
		uint256 i;
		uint256 ICR;
		address user;
		bool backToNormalMode;
		uint256 entireSystemDebt;
		uint256 entireSystemColl;
	}

	struct LocalVariables_AssetBorrowerPrice {
		address _asset;
		address _borrower;
		uint256 _price;
	}

	struct LiquidationValues {
		uint256 entireTroveDebt;
		uint256 entireTroveColl;
		uint256 collGasCompensation;
		uint256 DCHFGasCompensation;
		uint256 debtToOffset;
		uint256 collToSendToSP;
		uint256 debtToRedistribute;
		uint256 collToRedistribute;
		uint256 collSurplus;
	}

	struct LiquidationTotals {
		uint256 totalCollInSequence;
		uint256 totalDebtInSequence;
		uint256 totalCollGasCompensation;
		uint256 totalDCHFGasCompensation;
		uint256 totalDebtToOffset;
		uint256 totalCollToSendToSP;
		uint256 totalDebtToRedistribute;
		uint256 totalCollToRedistribute;
		uint256 totalCollSurplus;
	}

	struct ContractsCache {
		IActivePool activePool;
		IDefaultPool defaultPool;
		IDCHFToken dchfToken;
		IMONStaking monStaking;
		ISortedTroves sortedTroves;
		ICollSurplusPool collSurplusPool;
		address gasPoolAddress;
	}
	// --- Variable container structs for redemptions ---

	struct RedemptionTotals {
		uint256 remainingDCHF;
		uint256 totalDCHFToRedeem;
		uint256 totalAssetDrawn;
		uint256 ETHFee;
		uint256 ETHToSendToRedeemer;
		uint256 decayedBaseRate;
		uint256 price;
		uint256 totalDCHFSupplyAtStart;
	}

	struct SingleRedemptionValues {
		uint256 DCHFLot;
		uint256 ETHLot;
		bool cancelledPartial;
	}

	// --- Events ---

	event Liquidation(
		address indexed _asset,
		uint256 _liquidatedDebt,
		uint256 _liquidatedColl,
		uint256 _collGasCompensation,
		uint256 _DCHFGasCompensation
	);
	event Redemption(
		address indexed _asset,
		uint256 _attemptedDCHFAmount,
		uint256 _actualDCHFAmount,
		uint256 _AssetSent,
		uint256 _AssetFee
	);
	event TroveUpdated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		uint256 stake,
		uint8 operation
	);
	event TroveLiquidated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		uint8 operation
	);
	event BaseRateUpdated(address indexed _asset, uint256 _baseRate);
	event LastFeeOpTimeUpdated(address indexed _asset, uint256 _lastFeeOpTime);
	event TotalStakesUpdated(address indexed _asset, uint256 _newTotalStakes);
	event SystemSnapshotsUpdated(
		address indexed _asset,
		uint256 _totalStakesSnapshot,
		uint256 _totalCollateralSnapshot
	);
	event LTermsUpdated(address indexed _asset, uint256 _L_ETH, uint256 _L_DCHFDebt);
	event TroveSnapshotsUpdated(address indexed _asset, uint256 _L_ETH, uint256 _L_DCHFDebt);
	event TroveIndexUpdated(address indexed _asset, address _borrower, uint256 _newIndex);

	event TroveUpdated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		uint256 _stake,
		TroveManagerOperation _operation
	);
	event TroveLiquidated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		TroveManagerOperation _operation
	);

	enum TroveManagerOperation {
		applyPendingRewards,
		liquidateInNormalMode,
		liquidateInRecoveryMode,
		redeemCollateral
	}

	// --- Functions ---
	function isContractTroveManager() external pure returns (bool);

	function troveManagerHelpers() external view returns (ITroveManagerHelpers);

	function setAddresses(
		address _stabilityPoolManagerAddress,
		address _gasPoolAddress,
		address _collSurplusPoolAddress,
		address _dchfTokenAddress,
		address _sortedTrovesAddress,
		address _monStakingAddress,
		address _dfrancParamsAddress,
		address _troveManagerHelpersAddress
	) external;

	function stabilityPoolManager() external view returns (IStabilityPoolManager);

	function dchfToken() external view returns (IDCHFToken);

	function monStaking() external view returns (IMONStaking);

	function liquidate(address _asset, address borrower) external;

	function liquidateTroves(address _asset, uint256 _n) external;

	function batchLiquidateTroves(address _asset, address[] memory _troveArray) external;

	function redeemCollateral(
		address _asset,
		uint256 _DCHFamount,
		address _firstRedemptionHint,
		address _upperPartialRedemptionHint,
		address _lowerPartialRedemptionHint,
		uint256 _partialRedemptionHintNICR,
		uint256 _maxIterations,
		uint256 _maxFee
	) external;
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_baseRate","type":"uint256"}],"name":"BaseRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_L_ETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_L_DCHFDebt","type":"uint256"}],"name":"LTermsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_lastFeeOpTime","type":"uint256"}],"name":"LastFeeOpTimeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_liquidatedDebt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_liquidatedColl","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_collGasCompensation","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_DCHFGasCompensation","type":"uint256"}],"name":"Liquidation","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":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_attemptedDCHFAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_actualDCHFAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_AssetSent","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_AssetFee","type":"uint256"}],"name":"Redemption","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_totalStakesSnapshot","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_totalCollateralSnapshot","type":"uint256"}],"name":"SystemSnapshotsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_newTotalStakes","type":"uint256"}],"name":"TotalStakesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"_newIndex","type":"uint256"}],"name":"TroveIndexUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"_debt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_coll","type":"uint256"},{"indexed":false,"internalType":"uint8","name":"operation","type":"uint8"}],"name":"TroveLiquidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_L_ETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_L_DCHFDebt","type":"uint256"}],"name":"TroveSnapshotsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_asset","type":"address"},{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"_debt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_coll","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stake","type":"uint256"},{"indexed":false,"internalType":"uint8","name":"operation","type":"uint8"}],"name":"TroveUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAddress","type":"address"}],"name":"VaultParametersBaseChanged","type":"event"},{"inputs":[],"name":"BETA","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DECIMAL_PRECISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ETH_REF_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"L_ASSETS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"L_DCHFDebts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINUTE_DECAY_FACTOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NAME","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SECONDS_IN_ONE_MINUTE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"TroveOwners","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"Troves","outputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"debt","type":"uint256"},{"internalType":"uint256","name":"coll","type":"uint256"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"enum ITroveManagerHelpers.Status","name":"status","type":"uint8"},{"internalType":"uint128","name":"arrayIndex","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"_calcDecayedBaseRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_entireSystemColl","type":"uint256"},{"internalType":"uint256","name":"_entireSystemDebt","type":"uint256"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"_checkPotentialRecoveryMode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_assetDraw","type":"uint256"}],"name":"_getRedemptionFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"_requireAmountGreaterThanZero","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"contract IDCHFToken","name":"_dchfToken","type":"address"},{"internalType":"address","name":"_redeemer","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"_requireDCHFBalanceCoversRedemption","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"_requireTCRoverMCR","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"}],"name":"_requireValidMaxFeePercentage","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"addTroveOwnerToArray","outputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"contract IActivePool","name":"_activePool","type":"address"},{"internalType":"contract IDefaultPool","name":"_defaultPool","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"applyPendingRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"applyPendingRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"baseRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowerOperationsAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"checkRecoveryMode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"closeTrove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"enum ITroveManagerHelpers.Status","name":"closedStatus","type":"uint8"}],"name":"closeTrove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"dchfToken","outputs":[{"internalType":"contract IDCHFToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"decayBaseRateFromBorrowing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_collDecrease","type":"uint256"}],"name":"decreaseTroveColl","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_debtDecrease","type":"uint256"}],"name":"decreaseTroveDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"dfrancParams","outputs":[{"internalType":"contract IDfrancParameters","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_DCHFDebt","type":"uint256"}],"name":"getBorrowingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_DCHFDebt","type":"uint256"}],"name":"getBorrowingFeeWithDecay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"getBorrowingRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"getBorrowingRateWithDecay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"getCurrentICR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getEntireDebtAndColl","outputs":[{"internalType":"uint256","name":"debt","type":"uint256"},{"internalType":"uint256","name":"coll","type":"uint256"},{"internalType":"uint256","name":"pendingDCHFDebtReward","type":"uint256"},{"internalType":"uint256","name":"pendingAssetReward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"getEntireSystemColl","outputs":[{"internalType":"uint256","name":"entireSystemColl","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"getEntireSystemDebt","outputs":[{"internalType":"uint256","name":"entireSystemDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getNominalICR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getPendingAssetReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getPendingDCHFDebtReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_assetDraw","type":"uint256"}],"name":"getRedemptionFeeWithDecay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"getRedemptionRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"getRedemptionRateWithDecay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_troveOwner","type":"address"}],"name":"getRewardSnapshots","outputs":[{"internalType":"uint256","name":"asset","type":"uint256"},{"internalType":"uint256","name":"DCHFDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"getTCR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getTrove","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"enum ITroveManagerHelpers.Status","name":"","type":"uint8"},{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getTroveColl","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getTroveDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getTroveFromTroveOwnersArray","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"getTroveOwnersCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getTroveStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"getTroveStatus","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"hasPendingRewards","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_collIncrease","type":"uint256"}],"name":"increaseTroveColl","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_debtIncrease","type":"uint256"}],"name":"increaseTroveDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"isTroveActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastDCHFDebtError_Redistribution","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastETHError_Redistribution","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastFeeOperationTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"contract IActivePool","name":"_activePool","type":"address"},{"internalType":"contract IDefaultPool","name":"_defaultPool","type":"address"},{"internalType":"uint256","name":"_DCHF","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"movePendingTroveRewardsToActivePool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"contract IActivePool","name":"_activePool","type":"address"},{"internalType":"contract IDefaultPool","name":"_defaultPool","type":"address"},{"internalType":"uint256","name":"_debt","type":"uint256"},{"internalType":"uint256","name":"_coll","type":"uint256"}],"name":"redistributeDebtAndColl","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"removeStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_borrowerOperationsAddress","type":"address"},{"internalType":"address","name":"_dchfTokenAddress","type":"address"},{"internalType":"address","name":"_sortedTrovesAddress","type":"address"},{"internalType":"address","name":"_dfrancParamsAddress","type":"address"},{"internalType":"address","name":"_troveManagerAddress","type":"address"}],"name":"setAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vaultParams","type":"address"}],"name":"setDfrancParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_debt","type":"uint256"},{"internalType":"uint256","name":"_coll","type":"uint256"}],"name":"setTroveDeptAndColl","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_num","type":"uint256"}],"name":"setTroveStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sortedTroves","outputs":[{"internalType":"contract ISortedTroves","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalCollateralSnapshot","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalStakes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalStakesSnapshot","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"troveManagerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_ETHDrawn","type":"uint256"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"uint256","name":"_totalDCHFSupply","type":"uint256"}],"name":"updateBaseRateFromRedemption","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"updateStakeAndTotalStakes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"contract IActivePool","name":"_activePool","type":"address"},{"internalType":"uint256","name":"_collRemainder","type":"uint256"}],"name":"updateSystemSnapshots_excludeCollRemainder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"updateTroveRewardSnapshots","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b506200001d3362000023565b62000073565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b613bd580620000836000396000f3fe608060405234801561001057600080fd5b50600436106104805760003560e01c806390ec230111610257578063d201d32811610146578063eaac27e5116100c3578063f7fe1e1311610087578063f7fe1e1314610bd0578063f836e58a14610be3578063fb166d9c14610c4b578063fb4e863c14610c5e578063fe4b0df614610c7157600080fd5b8063eaac27e514610b47578063eeb20c6214610b5a578063ef268cfe14610b6d578063f2fde38b14610b80578063f3e2c60814610b9357600080fd5b8063deb0727a1161010a578063deb0727a14610adb578063df349ed514610aee578063df4fb9ef14610b0e578063e823c24914610b21578063e90f42ba14610b3457600080fd5b8063d201d32814610a45578063d8e6951814610a58578063dbe9f91914610a6b578063dc3fe76f14610a7e578063de66583514610abb57600080fd5b8063ae918754116101d4578063be16a09611610198578063be16a096146109ea578063c5d75f7b146109fd578063c6ad840314610a10578063c7a1bbdb14610a23578063c7b5548114610a3657600080fd5b8063ae9187541461097e578063af3700dc14610991578063b1eafaab146109b1578063b6d3b047146109c4578063b7f8cf9b146109d757600080fd5b8063a263757f1161021b578063a263757f146108e6578063a3abe098146108f9578063a3f4df7e1461090c578063a5eb60501461094b578063ac3e45b11461096b57600080fd5b806390ec23011461088b57806399f2f6c61461089e5780639e86d0c4146108b1578063a11285f8146108c4578063a20baee6146108d757600080fd5b80635a4d28bb116103735780637e7227cd116102f05780638463b16a116102b45780638463b16a1461082e5780638a25363c146108415780638a490ebf146108545780638abad92b146108675780638da5cb5b1461087a57600080fd5b80637e7227cd146107515780637f258d50146107765780637fe6d5ca146107db57806382569c2c146107fb5780638424ce771461081b57600080fd5b806361ec893d1161033757806361ec893d146107135780636d5d44b81461071b578063715018a61461072e57806372141e631461073657806374927c091461073e57600080fd5b80635a4d28bb146106a75780635c6944e8146106ba5780635dd68acd146106da5780635f548614146106ed578063614d12091461070057600080fd5b80632fae7700116104015780633d36cc95116103c55780633d36cc951461063257806340c315d214610645578063411072101461066e578063459783661461068157806349fe88581461069457600080fd5b80632fae7700146105a0578063305a5369146105b357806331f4bceb146105f0578063392e53cd1461060557806339863c6d1461061257600080fd5b80631f12cc41116104485780631f12cc41146104fc578063230195241461051c57806326f7a0d41461054757806327d04b351461057a5780632dcfca601461058d57600080fd5b8063071a7541146104855780630e0d7bfe146104a05780631400de71146104b357806315937cb0146104c65780631f075905146104e9575b600080fd5b61048d600281565b6040519081526020015b60405180910390f35b61048d6104ae36600461366c565b610c84565b61048d6104c13660046136a5565b610caa565b6104d96104d43660046136c2565b610cbe565b6040519015158152602001610497565b61048d6104f73660046136fd565b610d46565b61048d61050a3660046136a5565b60076020526000908152604090205481565b60045461052f906001600160a01b031681565b6040516001600160a01b039091168152602001610497565b61055a61055536600461366c565b610d61565b604080519485526020850193909352918301526060820152608001610497565b61048d6105883660046136a5565b610dcf565b6104d961059b36600461366c565b610fb1565b61048d6105ae366004613729565b611002565b61048d6105c136600461366c565b6001600160a01b0380821660009081526008602090815260408083209386168352929052206002015492915050565b6106036105fe36600461376a565b611076565b005b6012546104d99060ff1681565b61048d6106203660046136a5565b60116020526000908152604090205481565b61048d6106403660046136a5565b611090565b61048d6106533660046136a5565b6001600160a01b03166000908152600f602052604090205490565b61048d61067c3660046136fd565b6110a4565b61048d61068f366004613729565b6110b2565b61048d6106a23660046136fd565b6110f1565b60035461052f906001600160a01b031681565b61048d6106c83660046136a5565b60066020526000908152604090205481565b6106036106e83660046137c6565b6110fd565b6106036106fb36600461366c565b6112ec565b61048d61070e36600461366c565b611304565b61048d603c81565b6106036107293660046136a5565b611344565b6106036113cf565b61052f600081565b6104d961074c36600461366c565b611405565b61076461075f36600461366c565b611481565b6040516104979695949392919061384d565b61076461078436600461366c565b6008602090815260009283526040808420909152908252902080546001820154600283015460038401546004909401546001600160a01b0390931693919290919060ff81169061010090046001600160801b031686565b61048d6107e93660046136a5565b600d6020526000908152604090205481565b61048d6108093660046136a5565b600c6020526000908152604090205481565b61052f6108293660046136fd565b611562565b61048d61083c366004613729565b6115a8565b61060361084f366004613729565b61161c565b6104d96108623660046136fd565b6116c2565b61048d6108753660046136fd565b6116ce565b6000546001600160a01b031661052f565b61048d61089936600461366c565b6116e2565b6106036108ac3660046138a2565b61170b565b61048d6108bf3660046136a5565b611727565b6106036108d23660046136fd565b6118b8565b61048d670de0b6b3a764000081565b6106036108f43660046136a5565b611963565b61048d6109073660046136fd565b6119d7565b61093e6040518060400160405280601381526020017254726f76654d616e6167657248656c7065727360681b81525081565b60405161049791906138fd565b61048d6109593660046136a5565b60106020526000908152604090205481565b610603610979366004613729565b6119e5565b60055461052f906001600160a01b031681565b61048d61099f3660046136a5565b600a6020526000908152604090205481565b61048d6109bf366004613729565b611a8a565b61048d6109d23660046136a5565b611ab5565b60025461052f906001600160a01b031681565b61048d6109f836600461366c565b611ad9565b61048d610a0b3660046136c2565b611b87565b61048d610a1e3660046136a5565b611ba6565b610603610a3136600461366c565b611bfc565b61048d670ddd4b8c6c7d70d881565b61048d610a533660046136a5565b611c0e565b610603610a663660046138a2565b611c32565b61048d610a7936600461366c565b611c47565b61048d610a8c36600461366c565b6001600160a01b0380821660009081526008602090815260408083209386168352929052206003015492915050565b61048d610ac93660046136a5565b600b6020526000908152604090205481565b610603610ae9366004613729565b611c5b565b61048d610afc3660046136a5565b60096020526000908152604090205481565b610603610b1c36600461366c565b611c6e565b610603610b2f366004613952565b611d6e565b60015461052f906001600160a01b031681565b61048d610b5536600461366c565b611da6565b61052f610b683660046136fd565b611de9565b610603610b7b36600461396b565b611e21565b610603610b8e3660046136a5565b611e63565b61048d610ba136600461366c565b6001600160a01b0380821660009081526008602090815260408083209386168352929052206001015492915050565b610603610bde3660046139b1565b611efb565b610c36610bf136600461366c565b6001600160a01b039182166000908152600e60209081526040808320939094168252918252829020825180840190935280548084526001909101549290910182905291565b60408051928352602083019190915201610497565b610603610c593660046136fd565b611f0e565b610603610c6c36600461366c565b611fc4565b61048d610c7f366004613729565b611fd6565b6000610c8e612015565b610c98838361203f565b6001600160801b031690505b92915050565b6000610ca482610cb984611ba6565b6120de565b600080610ccc8585856121d1565b600154604051631f6a526d60e11b81526001600160a01b038981166004830152929350911690633ed4a4da90602401602060405180830381865afa158015610d18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3c9190613a00565b1195945050505050565b6000610d5a610d5484611c0e565b836121f7565b9392505050565b6001600160a01b03818116600090815260086020908152604080832093861683529290529081206001810154600290910154909180610da08686611da6565b9150610dac8686611ad9565b9050610db88483612246565b9350610dc48382612246565b925092959194509250565b600080600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e499190613a19565b60405163d1234da760e01b81526001600160a01b038581166004830152919091169063d1234da790602401602060405180830381865afa158015610e91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb59190613a00565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f309190613a19565b60405163d1234da760e01b81526001600160a01b038681166004830152919091169063d1234da7906024015b602060405180830381865afa158015610f79573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f9d9190613a00565b9050610fa98282612246565b949350505050565b6000610fbd8383611405565b610fc957506000610ca4565b506001600160a01b038083166000818152600c60209081526040808320549486168352600e825280832093835292905220541092915050565b600061100c612015565b6001600160a01b0380841660009081526008602090815260408083209388168352929052908120600201546110419084612252565b6001600160a01b038086166000908152600860209081526040808320938a168352929052206002018190559150509392505050565b61107e61225e565b61108a84848484612288565b50505050565b6000610ca48261109f84611ba6565b6123f5565b6000610d5a610d5484611090565b60006110bc612015565b6001600160a01b0380841660009081526008602090815260408083209388168352929052908120600201546110419084612246565b6000610d5a8383612440565b600154600160a81b900460ff1615808015611123575060018054600160a01b900460ff16105b806111435750303b158015611143575060018054600160a01b900460ff16145b6111ab5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6001805460ff60a01b1916600160a01b17905580156111d8576001805460ff60a81b1916600160a81b1790555b60125460ff16156112105760405162461bcd60e51b8152602060048201526002602482015261414960f01b60448201526064016111a2565b61121986612466565b61122285612466565b61122b84612466565b61123483612466565b61123d82612466565b6012805460ff19166001179055600280546001600160a01b038089166001600160a01b0319928316179092556004805488841690831617905560058054878416908316179055600380549285169290911691909117905561129d83611963565b80156112e4576001805460ff60a81b191681556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6112f4612015565b6113008282600261250b565b5050565b6001600160a01b038082166000908152600860209081526040808320938616835292905290812060049081015460ff1690811115610d5a57610d5a613837565b61134c612015565b600061135782611ba6565b9050670de0b6b3a764000081111561137157611371613a36565b6001600160a01b03821660008181526006602052604090819020839055517f2f992d01b594c040f05262961e43f8311e780be5fee3deb4c57880dd6374d12d906113be9084815260200190565b60405180910390a261130082612683565b6000546001600160a01b031633146113f95760405162461bcd60e51b81526004016111a290613a4c565b6114036000612707565b565b6000600160405163614d120960e01b81526001600160a01b03808616600483015284166024820152309063614d120990604401602060405180830381865afa158015611455573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114799190613a00565b149392505050565b6001600160a01b03808216600090815260086020908152604080832086851684528252808320815160c081018352815490951685526001810154928501929092526002820154908401526003810154606084015260048082015492938493849384938493849384939192608084019160ff169081111561150357611503613837565b600481111561151457611514613837565b81526004919091015461010090046001600160801b031660209182015281519082015160408301516060840151608085015160a090950151939e929d50909b50995091975095509350505050565b6001600160a01b0382166000908152600f6020526040812080548390811061158c5761158c613a81565b6000918252602090912001546001600160a01b03169392505050565b60006115b2612015565b6001600160a01b0380841660009081526008602090815260408083209388168352929052908120600101546115e79084612252565b6001600160a01b038086166000908152600860209081526040808320938a168352929052206001018190559150509392505050565b611624612015565b6001600160a01b03808316600090815260086020908152604080832093871680845293909152902080546001600160a01b031916909117905580600481111561166f5761166f613837565b6001600160a01b03808416600090815260086020908152604080832093881683529290522060049081018054909160ff199091169060019084908111156116b8576116b8613837565b0217905550505050565b6000610d5a8383612757565b6000610d5a6116dc84610caa565b836127dc565b60008060006116f185856127f4565b9150915060006117018383612892565b9695505050505050565b61171361225e565b61172085858585856128c1565b5050505050565b600080600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561177d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a19190613a19565b604051635373433f60e01b81526001600160a01b0385811660048301529190911690635373433f90602401602060405180830381865afa1580156117e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180d9190613a00565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015611864573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118889190613a19565b604051635373433f60e01b81526001600160a01b0386811660048301529190911690635373433f90602401610f5c565b6001546040516305f8cff960e01b81526001600160a01b038481166004830152909116906305f8cff990602401602060405180830381865afa158015611902573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119269190613a00565b6119308383612440565b10156113005760405162461bcd60e51b815260206004820152600260248201526121a960f11b60448201526064016111a2565b6000546001600160a01b0316331461198d5760405162461bcd60e51b81526004016111a290613a4c565b600180546001600160a01b0319166001600160a01b0383169081179091556040517f98c5e303d085e26fdf8af6a41184b0937ed01142ae7fdfa02dcc87e7079c325390600090a250565b6000610d5a6116dc84611ab5565b6040516370a0823160e01b81526001600160a01b0383811660048301528291908516906370a0823190602401602060405180830381865afa158015611a2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a529190613a00565b1015611a855760405162461bcd60e51b8152602060048201526002602482015261292960f11b60448201526064016111a2565b505050565b6000806000611a9986866127f4565b915091506000611aaa8383876121d1565b979650505050505050565b6001600160a01b038116600090815260066020526040812054610ca49083906120de565b6001600160a01b038082166000908152600e60209081526040808320938616835292815282822054600c909152918120549091908290611b199083612252565b9050801580611b2f5750611b2d8585611405565b155b15611b3f57600092505050610ca4565b6001600160a01b03808516600090815260086020908152604080832093891683529290529081206003015490611aaa670de0b6b3a7640000611b818486612bdf565b90612beb565b6000611b9161225e565b611b9d85858585612bf7565b95945050505050565b600080611bb283612cb2565b90506000611bc8670ddd4b8c6c7d70d883612cdd565b6001600160a01b038516600090815260066020526040902054909150610fa990670de0b6b3a764000090611b819084612bdf565b611c04612015565b6113008282612d81565b6001600160a01b038116600090815260066020526040812054610ca49083906123f5565b611c3a61225e565b6117208585858585612dff565b6000611c51612f2c565b610d5a8383612f6b565b611c6361225e565b611a8583838361304e565b611c76612015565b61130082600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ccd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cf19190613a19565b600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d689190613a19565b84612288565b60008111611da35760405162461bcd60e51b8152602060048201526002602482015261414760f01b60448201526064016111a2565b50565b6001600160a01b038082166000908152600e60209081526040808320938616835292815282822060010154600d909152918120549091908290611b199083612252565b600f6020528160005260406000208181548110611e0557600080fd5b6000918252602090912001546001600160a01b03169150829050565b611e2961225e565b6001600160a01b03928316600090815260086020908152604080832096909516825294909452919092206001810192909255600290910155565b6000546001600160a01b03163314611e8d5760405162461bcd60e51b81526004016111a290613a4c565b6001600160a01b038116611ef25760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016111a2565b611da381612707565b611f0361225e565b611a8583838361250b565b600154604051635c197b9960e01b81526001600160a01b03848116600483015290911690635c197b9990602401602060405180830381865afa158015611f58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f7c9190613a00565b8110158015611f935750670de0b6b3a76400008111155b6113005760405162461bcd60e51b815260206004820152600260248201526126a360f11b60448201526064016111a2565b611fcc612f2c565b6113008282613238565b6000611fe0612015565b6001600160a01b0380841660009081526008602090815260408083209388168352929052908120600101546115e79084612246565b6002546001600160a01b031633146114035760405162461bcd60e51b81526004016111a290613a97565b6001600160a01b038281166000818152600f6020908152604082208054600180820183558285529284200180546001600160a01b03191695871695909517909455918152915461208e91612252565b6001600160a01b03808416600090815260086020908152604080832093881683529290522060040180546001600160801b03831661010002610100600160881b0319909116179055905092915050565b600154604051631108308b60e31b81526001600160a01b038481166004830152600092610d5a9261215e92869216906388418458906024015b602060405180830381865afa158015612134573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121589190613a00565b90612246565b60015460405163098e8fa760e01b81526001600160a01b0387811660048301529091169063098e8fa790602401602060405180830381865afa1580156121a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121cc9190613a00565b6132b2565b600082156121ee576121e783611b818685612bdf565b9050610d5a565b50600019610d5a565b600080612210670de0b6b3a7640000611b818686612bdf565b9050828110610d5a5760405162461bcd60e51b8152602060048201526002602482015261464560f01b60448201526064016111a2565b6000610d5a8284613ac9565b6000610d5a8284613ae1565b6003546001600160a01b031633146114035760405162461bcd60e51b81526004016111a290613a97565b6122928482610fb1565b1561108a576122a18482611405565b6122ad576122ad613a36565b60006122b98583611ad9565b905060006122c78684611da6565b6001600160a01b038085166000908152600860209081526040808320938b16835292905220600201549091506122fd9083612246565b6001600160a01b038481166000908152600860209081526040808320938b168352929052206002810191909155600101546123389082612246565b6001600160a01b038085166000908152600860209081526040808320938b168352929052206001015561236b8684612d81565b6123788686868486612dff565b6001600160a01b038381166000818152600860209081526040808320948b16808452949091528082206001810154600282015460039092015492519495947f100d2512a463b515ea8d03a69afbcc791f1bd9139132e820631bec236f524ec1946123e59492939291613af8565b60405180910390a3505050505050565b600154604051635c197b9960e01b81526001600160a01b038481166004830152600092610d5a926124329286921690635c197b9990602401612117565b670de0b6b3a76400006132b2565b60008061244c84611727565b9050600061245985610dcf565b9050611b9d8282866121d1565b6001600160a01b0381166124bc5760405162461bcd60e51b815260206004820152601e60248201527f4163636f756e742063616e6e6f74206265207a65726f2061646472657373000060448201526064016111a2565b803b806113005760405162461bcd60e51b815260206004820181905260248201527f4163636f756e7420636f64652073697a652063616e6e6f74206265207a65726f60448201526064016111a2565b600081600481111561251f5761251f613837565b1415801561253f5750600181600481111561253c5761253c613837565b14155b61254b5761254b613a36565b6001600160a01b0383166000908152600f602052604090205461256e84826132c8565b6001600160a01b03808416600090815260086020908152604080832093881683529290522060049081018054849260ff199091169060019084908111156125b7576125b7613837565b02179055506001600160a01b038381166000818152600860209081526040808320948916808452948252808320600281018490556001908101849055938352600e82528083209483529390529182208281550155612616848483613375565b600554604051637f7c149160e01b81526001600160a01b038681166004830152858116602483015290911690637f7c149190604401600060405180830381600087803b15801561266557600080fd5b505af1158015612679573d6000803e3d6000fd5b5050505050505050565b6001600160a01b0381166000908152600760205260408120546126a7904290612252565b9050603c8110611300576001600160a01b038216600081815260076020908152604091829020429081905591519182527f4b1a24436e474bd20ff461d446818e19b145a1ff52f698dec751807684621acc91015b60405180910390a25050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000806127648484612440565b600154604051631f6a526d60e11b81526001600160a01b038781166004830152929350911690633ed4a4da90602401602060405180830381865afa1580156127b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127d49190613a00565b119392505050565b6000610d5a670de0b6b3a7640000611b818585612bdf565b60008060006128038585611ad9565b905060006128118686611da6565b6001600160a01b038087166000908152600860209081526040808320938b168352929052908120600201549192509061284a9084612246565b6001600160a01b038088166000908152600860209081526040808320938c16835292905290812060010154919250906128839084612246565b91989197509095505050505050565b600081156128b8576128b182611b818568056bc75e2d63100000612bdf565b9050610ca4565b50600019610ca4565b8115611720576001600160a01b0385166000908152601060205260408120546128f69061215884670de0b6b3a7640000612bdf565b6001600160a01b038716600090815260116020526040812054919250906129299061215886670de0b6b3a7640000612bdf565b6001600160a01b03881660009081526009602052604081205491925090612951908490612beb565b6001600160a01b03891660009081526009602052604081205491925090612979908490612beb565b6001600160a01b038a166000908152600960205260409020549091506129ab906129a4908490612bdf565b8590612252565b6001600160a01b038a166000908152601060209081526040808320939093556009905220546129e6906129df908390612bdf565b8490612252565b6001600160a01b038a16600090815260116020908152604080832093909355600c90522054612a159083612246565b6001600160a01b038a166000908152600c6020908152604080832093909355600d90522054612a449082612246565b6001600160a01b038a166000818152600d60208181526040808420869055600c82529283902054918152825191825281019390935290917f6f63d00bdf85957664165c9e20900aabd5a17378cb5c0955ce760e48a6ae48c7910160405180910390a260405163fb24e5f760e01b81526001600160a01b038a811660048301526024820188905289169063fb24e5f790604401600060405180830381600087803b158015612af057600080fd5b505af1158015612b04573d6000803e3d6000fd5b50506040516306df996d60e41b81526001600160a01b038c81166004830152602482018a90528a169250636df996d09150604401600060405180830381600087803b158015612b5257600080fd5b505af1158015612b66573d6000803e3d6000fd5b50506040516347878f1560e01b81526001600160a01b038c811660048301528a81166024830152604482018990528b1692506347878f159150606401600060405180830381600087803b158015612bbc57600080fd5b505af1158015612bd0573d6000803e3d6000fd5b50505050505050505050505050565b6000610d5a8284613b2c565b6000610d5a8284613b61565b600080612c0386611ba6565b90506000612c1584611b818888612bdf565b90506000612c2e612c27836002612beb565b8490612246565b9050612c4281670de0b6b3a76400006132b2565b905060008111612c5457612c54613a36565b6001600160a01b03881660008181526006602052604090819020839055517f2f992d01b594c040f05262961e43f8311e780be5fee3deb4c57880dd6374d12d90612ca19084815260200190565b60405180910390a2611aaa88612683565b6001600160a01b038116600090815260076020526040812054610ca490603c90611b81904290612252565b6000631f540500821115612cf357631f54050091505b81600003612d0a5750670de0b6b3a7640000610ca4565b670de0b6b3a764000083835b6001811115612d7757612d2a600282613b75565b600003612d4f57612d3b82836135ac565b9150612d48816002612beb565b9050612d16565b612d5982846135ac565b9250612d6582836135ac565b9150612d486002611b81836001612252565b61170182846135ac565b6001600160a01b038281166000818152600c6020908152604080832080549587168452600e83528184208585528352818420958655600d835292819020546001909501859055915482519081529081019390935290917fc3d426bcfc672bd74f6fae61c225e06f556f80dad48af8a4631b295030a7ad3d91016126fb565b60405163fb24e5f760e01b81526001600160a01b0386811660048301526024820184905284169063fb24e5f790604401600060405180830381600087803b158015612e4957600080fd5b505af1158015612e5d573d6000803e3d6000fd5b50506040516306df996d60e41b81526001600160a01b0388811660048301526024820186905287169250636df996d09150604401600060405180830381600087803b158015612eab57600080fd5b505af1158015612ebf573d6000803e3d6000fd5b505060405163053f8cf960e31b81526001600160a01b03888116600483015260248201859052861692506329fc67c89150604401600060405180830381600087803b158015612f0d57600080fd5b505af1158015612f21573d6000803e3d6000fd5b505050505050505050565b6002546001600160a01b0316331480612f4f57506003546001600160a01b031633145b6114035760405162461bcd60e51b81526004016111a290613a97565b6001600160a01b0380821660009081526008602090815260408083209386168352929052908120600201548190612fa39085906135d5565b6001600160a01b038481166000908152600860209081526040808320938916835292815282822060030180549085905560099091529190205491925090612ff09083906121589084612252565b6001600160a01b038616600081815260096020526040908190208390555190917fd5630907014190fb9340da1cf427c96f094dabfbf73d25506e4b0cda9e3a4ca09161303e91815260200190565b60405180910390a2509392505050565b6001600160a01b03838116600081815260096020908152604080832054600a9092528083209190915551635373433f60e01b8152600481019290925291841690635373433f90602401602060405180830381865afa1580156130b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130d89190613a00565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa15801561312f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131539190613a19565b604051635373433f60e01b81526001600160a01b0387811660048301529190911690635373433f90602401602060405180830381865afa15801561319b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131bf9190613a00565b90506131cf816121588486612252565b6001600160a01b0386166000818152600b60208181526040808420869055600a82529283902054918152825191825281019390935290917f9ea5863ffc9d961d6c6bb67235c553dfbdbcc8fe12671cdba8887a50501efbaf910160405180910390a25050505050565b6001600160a01b0380821660009081526008602090815260408083209386168352928152828220600301546009909152919020546132769082612252565b6001600160a01b039384166000818152600960209081526040808320949094559490951685526008845281852090855290925250812060030155565b60008183106132c15781610d5a565b5090919050565b600181118015613344575060055460405163504f167160e01b81526001600160a01b038481166004830152600192169063504f167190602401602060405180830381865afa15801561331e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133429190613a00565b115b6113005760405162461bcd60e51b81526020600482015260026024820152614f4f60f01b60448201526064016111a2565b6001600160a01b03808316600090815260086020908152604080832093871683529290529081206004015460ff16908160048111156133b6576133b6613837565b141580156133d6575060018160048111156133d3576133d3613837565b14155b6133e2576133e2613a36565b6001600160a01b03838116600090815260086020908152604080832093881683529290529081206004015461010090046001600160801b0316908390613429826001612252565b905080836001600160801b0316111561344457613444613a36565b6001600160a01b0387166000908152600f6020526040812080548390811061346e5761346e613a81565b60009182526020808320909101546001600160a01b038b81168452600f909252604090922080549190921692508291906001600160801b0387169081106134b7576134b7613a81565b600091825260208083209190910180546001600160a01b0319166001600160a01b03948516179055838316808352600882526040808420948d16808552948352928390206004018054610100600160881b0319166101006001600160801b038b16908102919091179091558351918252918101919091527f596c08527bf037a7d30b01f257c1ba24ebd2a664cde69f8315accfee1199c668910160405180910390a26001600160a01b0388166000908152600f6020526040902080548061358057613580613b89565b600082815260209020810160001990810180546001600160a01b03191690550190555050505050505050565b6000806135b98484612bdf565b9050610fa9670de0b6b3a7640000611b81612c27600283613b61565b6001600160a01b0382166000908152600b6020526040812054819081036135fd575081610d5a565b6001600160a01b0384166000908152600a602052604090205461362257613622613a36565b6001600160a01b0384166000908152600b6020908152604080832054600a90925290912054610fa99190611b81908690612bdf565b6001600160a01b0381168114611da357600080fd5b6000806040838503121561367f57600080fd5b823561368a81613657565b9150602083013561369a81613657565b809150509250929050565b6000602082840312156136b757600080fd5b8135610d5a81613657565b600080600080608085870312156136d857600080fd5b84356136e381613657565b966020860135965060408601359560600135945092505050565b6000806040838503121561371057600080fd5b823561371b81613657565b946020939093013593505050565b60008060006060848603121561373e57600080fd5b833561374981613657565b9250602084013561375981613657565b929592945050506040919091013590565b6000806000806080858703121561378057600080fd5b843561378b81613657565b9350602085013561379b81613657565b925060408501356137ab81613657565b915060608501356137bb81613657565b939692955090935050565b600080600080600060a086880312156137de57600080fd5b85356137e981613657565b945060208601356137f981613657565b9350604086013561380981613657565b9250606086013561381981613657565b9150608086013561382981613657565b809150509295509295909350565b634e487b7160e01b600052602160045260246000fd5b6001600160a01b038716815260208101869052604081018590526060810184905260c081016005841061388257613882613837565b8360808301526001600160801b03831660a0830152979650505050505050565b600080600080600060a086880312156138ba57600080fd5b85356138c581613657565b945060208601356138d581613657565b935060408601356138e581613657565b94979396509394606081013594506080013592915050565b600060208083528351808285015260005b8181101561392a5785810183015185820160400152820161390e565b8181111561393c576000604083870101525b50601f01601f1916929092016040019392505050565b60006020828403121561396457600080fd5b5035919050565b6000806000806080858703121561398157600080fd5b843561398c81613657565b9350602085013561399c81613657565b93969395505050506040820135916060013590565b6000806000606084860312156139c657600080fd5b83356139d181613657565b925060208401356139e181613657565b91506040840135600581106139f557600080fd5b809150509250925092565b600060208284031215613a1257600080fd5b5051919050565b600060208284031215613a2b57600080fd5b8151610d5a81613657565b634e487b7160e01b600052600160045260246000fd5b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052603260045260246000fd5b602080825260029082015261574160f01b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b60008219821115613adc57613adc613ab3565b500190565b600082821015613af357613af3613ab3565b500390565b84815260208101849052604081018390526080810160048310613b1d57613b1d613837565b82606083015295945050505050565b6000816000190483118215151615613b4657613b46613ab3565b500290565b634e487b7160e01b600052601260045260246000fd5b600082613b7057613b70613b4b565b500490565b600082613b8457613b84613b4b565b500690565b634e487b7160e01b600052603160045260246000fdfea2646970667358221220fe87936c38615770fb01bfa98eb3ce179025a46d083131b49f8e294bc47a51fe64736f6c634300080e0033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106104805760003560e01c806390ec230111610257578063d201d32811610146578063eaac27e5116100c3578063f7fe1e1311610087578063f7fe1e1314610bd0578063f836e58a14610be3578063fb166d9c14610c4b578063fb4e863c14610c5e578063fe4b0df614610c7157600080fd5b8063eaac27e514610b47578063eeb20c6214610b5a578063ef268cfe14610b6d578063f2fde38b14610b80578063f3e2c60814610b9357600080fd5b8063deb0727a1161010a578063deb0727a14610adb578063df349ed514610aee578063df4fb9ef14610b0e578063e823c24914610b21578063e90f42ba14610b3457600080fd5b8063d201d32814610a45578063d8e6951814610a58578063dbe9f91914610a6b578063dc3fe76f14610a7e578063de66583514610abb57600080fd5b8063ae918754116101d4578063be16a09611610198578063be16a096146109ea578063c5d75f7b146109fd578063c6ad840314610a10578063c7a1bbdb14610a23578063c7b5548114610a3657600080fd5b8063ae9187541461097e578063af3700dc14610991578063b1eafaab146109b1578063b6d3b047146109c4578063b7f8cf9b146109d757600080fd5b8063a263757f1161021b578063a263757f146108e6578063a3abe098146108f9578063a3f4df7e1461090c578063a5eb60501461094b578063ac3e45b11461096b57600080fd5b806390ec23011461088b57806399f2f6c61461089e5780639e86d0c4146108b1578063a11285f8146108c4578063a20baee6146108d757600080fd5b80635a4d28bb116103735780637e7227cd116102f05780638463b16a116102b45780638463b16a1461082e5780638a25363c146108415780638a490ebf146108545780638abad92b146108675780638da5cb5b1461087a57600080fd5b80637e7227cd146107515780637f258d50146107765780637fe6d5ca146107db57806382569c2c146107fb5780638424ce771461081b57600080fd5b806361ec893d1161033757806361ec893d146107135780636d5d44b81461071b578063715018a61461072e57806372141e631461073657806374927c091461073e57600080fd5b80635a4d28bb146106a75780635c6944e8146106ba5780635dd68acd146106da5780635f548614146106ed578063614d12091461070057600080fd5b80632fae7700116104015780633d36cc95116103c55780633d36cc951461063257806340c315d214610645578063411072101461066e578063459783661461068157806349fe88581461069457600080fd5b80632fae7700146105a0578063305a5369146105b357806331f4bceb146105f0578063392e53cd1461060557806339863c6d1461061257600080fd5b80631f12cc41116104485780631f12cc41146104fc578063230195241461051c57806326f7a0d41461054757806327d04b351461057a5780632dcfca601461058d57600080fd5b8063071a7541146104855780630e0d7bfe146104a05780631400de71146104b357806315937cb0146104c65780631f075905146104e9575b600080fd5b61048d600281565b6040519081526020015b60405180910390f35b61048d6104ae36600461366c565b610c84565b61048d6104c13660046136a5565b610caa565b6104d96104d43660046136c2565b610cbe565b6040519015158152602001610497565b61048d6104f73660046136fd565b610d46565b61048d61050a3660046136a5565b60076020526000908152604090205481565b60045461052f906001600160a01b031681565b6040516001600160a01b039091168152602001610497565b61055a61055536600461366c565b610d61565b604080519485526020850193909352918301526060820152608001610497565b61048d6105883660046136a5565b610dcf565b6104d961059b36600461366c565b610fb1565b61048d6105ae366004613729565b611002565b61048d6105c136600461366c565b6001600160a01b0380821660009081526008602090815260408083209386168352929052206002015492915050565b6106036105fe36600461376a565b611076565b005b6012546104d99060ff1681565b61048d6106203660046136a5565b60116020526000908152604090205481565b61048d6106403660046136a5565b611090565b61048d6106533660046136a5565b6001600160a01b03166000908152600f602052604090205490565b61048d61067c3660046136fd565b6110a4565b61048d61068f366004613729565b6110b2565b61048d6106a23660046136fd565b6110f1565b60035461052f906001600160a01b031681565b61048d6106c83660046136a5565b60066020526000908152604090205481565b6106036106e83660046137c6565b6110fd565b6106036106fb36600461366c565b6112ec565b61048d61070e36600461366c565b611304565b61048d603c81565b6106036107293660046136a5565b611344565b6106036113cf565b61052f600081565b6104d961074c36600461366c565b611405565b61076461075f36600461366c565b611481565b6040516104979695949392919061384d565b61076461078436600461366c565b6008602090815260009283526040808420909152908252902080546001820154600283015460038401546004909401546001600160a01b0390931693919290919060ff81169061010090046001600160801b031686565b61048d6107e93660046136a5565b600d6020526000908152604090205481565b61048d6108093660046136a5565b600c6020526000908152604090205481565b61052f6108293660046136fd565b611562565b61048d61083c366004613729565b6115a8565b61060361084f366004613729565b61161c565b6104d96108623660046136fd565b6116c2565b61048d6108753660046136fd565b6116ce565b6000546001600160a01b031661052f565b61048d61089936600461366c565b6116e2565b6106036108ac3660046138a2565b61170b565b61048d6108bf3660046136a5565b611727565b6106036108d23660046136fd565b6118b8565b61048d670de0b6b3a764000081565b6106036108f43660046136a5565b611963565b61048d6109073660046136fd565b6119d7565b61093e6040518060400160405280601381526020017254726f76654d616e6167657248656c7065727360681b81525081565b60405161049791906138fd565b61048d6109593660046136a5565b60106020526000908152604090205481565b610603610979366004613729565b6119e5565b60055461052f906001600160a01b031681565b61048d61099f3660046136a5565b600a6020526000908152604090205481565b61048d6109bf366004613729565b611a8a565b61048d6109d23660046136a5565b611ab5565b60025461052f906001600160a01b031681565b61048d6109f836600461366c565b611ad9565b61048d610a0b3660046136c2565b611b87565b61048d610a1e3660046136a5565b611ba6565b610603610a3136600461366c565b611bfc565b61048d670ddd4b8c6c7d70d881565b61048d610a533660046136a5565b611c0e565b610603610a663660046138a2565b611c32565b61048d610a7936600461366c565b611c47565b61048d610a8c36600461366c565b6001600160a01b0380821660009081526008602090815260408083209386168352929052206003015492915050565b61048d610ac93660046136a5565b600b6020526000908152604090205481565b610603610ae9366004613729565b611c5b565b61048d610afc3660046136a5565b60096020526000908152604090205481565b610603610b1c36600461366c565b611c6e565b610603610b2f366004613952565b611d6e565b60015461052f906001600160a01b031681565b61048d610b5536600461366c565b611da6565b61052f610b683660046136fd565b611de9565b610603610b7b36600461396b565b611e21565b610603610b8e3660046136a5565b611e63565b61048d610ba136600461366c565b6001600160a01b0380821660009081526008602090815260408083209386168352929052206001015492915050565b610603610bde3660046139b1565b611efb565b610c36610bf136600461366c565b6001600160a01b039182166000908152600e60209081526040808320939094168252918252829020825180840190935280548084526001909101549290910182905291565b60408051928352602083019190915201610497565b610603610c593660046136fd565b611f0e565b610603610c6c36600461366c565b611fc4565b61048d610c7f366004613729565b611fd6565b6000610c8e612015565b610c98838361203f565b6001600160801b031690505b92915050565b6000610ca482610cb984611ba6565b6120de565b600080610ccc8585856121d1565b600154604051631f6a526d60e11b81526001600160a01b038981166004830152929350911690633ed4a4da90602401602060405180830381865afa158015610d18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3c9190613a00565b1195945050505050565b6000610d5a610d5484611c0e565b836121f7565b9392505050565b6001600160a01b03818116600090815260086020908152604080832093861683529290529081206001810154600290910154909180610da08686611da6565b9150610dac8686611ad9565b9050610db88483612246565b9350610dc48382612246565b925092959194509250565b600080600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e499190613a19565b60405163d1234da760e01b81526001600160a01b038581166004830152919091169063d1234da790602401602060405180830381865afa158015610e91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb59190613a00565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f309190613a19565b60405163d1234da760e01b81526001600160a01b038681166004830152919091169063d1234da7906024015b602060405180830381865afa158015610f79573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f9d9190613a00565b9050610fa98282612246565b949350505050565b6000610fbd8383611405565b610fc957506000610ca4565b506001600160a01b038083166000818152600c60209081526040808320549486168352600e825280832093835292905220541092915050565b600061100c612015565b6001600160a01b0380841660009081526008602090815260408083209388168352929052908120600201546110419084612252565b6001600160a01b038086166000908152600860209081526040808320938a168352929052206002018190559150509392505050565b61107e61225e565b61108a84848484612288565b50505050565b6000610ca48261109f84611ba6565b6123f5565b6000610d5a610d5484611090565b60006110bc612015565b6001600160a01b0380841660009081526008602090815260408083209388168352929052908120600201546110419084612246565b6000610d5a8383612440565b600154600160a81b900460ff1615808015611123575060018054600160a01b900460ff16105b806111435750303b158015611143575060018054600160a01b900460ff16145b6111ab5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6001805460ff60a01b1916600160a01b17905580156111d8576001805460ff60a81b1916600160a81b1790555b60125460ff16156112105760405162461bcd60e51b8152602060048201526002602482015261414960f01b60448201526064016111a2565b61121986612466565b61122285612466565b61122b84612466565b61123483612466565b61123d82612466565b6012805460ff19166001179055600280546001600160a01b038089166001600160a01b0319928316179092556004805488841690831617905560058054878416908316179055600380549285169290911691909117905561129d83611963565b80156112e4576001805460ff60a81b191681556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6112f4612015565b6113008282600261250b565b5050565b6001600160a01b038082166000908152600860209081526040808320938616835292905290812060049081015460ff1690811115610d5a57610d5a613837565b61134c612015565b600061135782611ba6565b9050670de0b6b3a764000081111561137157611371613a36565b6001600160a01b03821660008181526006602052604090819020839055517f2f992d01b594c040f05262961e43f8311e780be5fee3deb4c57880dd6374d12d906113be9084815260200190565b60405180910390a261130082612683565b6000546001600160a01b031633146113f95760405162461bcd60e51b81526004016111a290613a4c565b6114036000612707565b565b6000600160405163614d120960e01b81526001600160a01b03808616600483015284166024820152309063614d120990604401602060405180830381865afa158015611455573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114799190613a00565b149392505050565b6001600160a01b03808216600090815260086020908152604080832086851684528252808320815160c081018352815490951685526001810154928501929092526002820154908401526003810154606084015260048082015492938493849384938493849384939192608084019160ff169081111561150357611503613837565b600481111561151457611514613837565b81526004919091015461010090046001600160801b031660209182015281519082015160408301516060840151608085015160a090950151939e929d50909b50995091975095509350505050565b6001600160a01b0382166000908152600f6020526040812080548390811061158c5761158c613a81565b6000918252602090912001546001600160a01b03169392505050565b60006115b2612015565b6001600160a01b0380841660009081526008602090815260408083209388168352929052908120600101546115e79084612252565b6001600160a01b038086166000908152600860209081526040808320938a168352929052206001018190559150509392505050565b611624612015565b6001600160a01b03808316600090815260086020908152604080832093871680845293909152902080546001600160a01b031916909117905580600481111561166f5761166f613837565b6001600160a01b03808416600090815260086020908152604080832093881683529290522060049081018054909160ff199091169060019084908111156116b8576116b8613837565b0217905550505050565b6000610d5a8383612757565b6000610d5a6116dc84610caa565b836127dc565b60008060006116f185856127f4565b9150915060006117018383612892565b9695505050505050565b61171361225e565b61172085858585856128c1565b5050505050565b600080600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561177d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a19190613a19565b604051635373433f60e01b81526001600160a01b0385811660048301529190911690635373433f90602401602060405180830381865afa1580156117e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180d9190613a00565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015611864573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118889190613a19565b604051635373433f60e01b81526001600160a01b0386811660048301529190911690635373433f90602401610f5c565b6001546040516305f8cff960e01b81526001600160a01b038481166004830152909116906305f8cff990602401602060405180830381865afa158015611902573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119269190613a00565b6119308383612440565b10156113005760405162461bcd60e51b815260206004820152600260248201526121a960f11b60448201526064016111a2565b6000546001600160a01b0316331461198d5760405162461bcd60e51b81526004016111a290613a4c565b600180546001600160a01b0319166001600160a01b0383169081179091556040517f98c5e303d085e26fdf8af6a41184b0937ed01142ae7fdfa02dcc87e7079c325390600090a250565b6000610d5a6116dc84611ab5565b6040516370a0823160e01b81526001600160a01b0383811660048301528291908516906370a0823190602401602060405180830381865afa158015611a2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a529190613a00565b1015611a855760405162461bcd60e51b8152602060048201526002602482015261292960f11b60448201526064016111a2565b505050565b6000806000611a9986866127f4565b915091506000611aaa8383876121d1565b979650505050505050565b6001600160a01b038116600090815260066020526040812054610ca49083906120de565b6001600160a01b038082166000908152600e60209081526040808320938616835292815282822054600c909152918120549091908290611b199083612252565b9050801580611b2f5750611b2d8585611405565b155b15611b3f57600092505050610ca4565b6001600160a01b03808516600090815260086020908152604080832093891683529290529081206003015490611aaa670de0b6b3a7640000611b818486612bdf565b90612beb565b6000611b9161225e565b611b9d85858585612bf7565b95945050505050565b600080611bb283612cb2565b90506000611bc8670ddd4b8c6c7d70d883612cdd565b6001600160a01b038516600090815260066020526040902054909150610fa990670de0b6b3a764000090611b819084612bdf565b611c04612015565b6113008282612d81565b6001600160a01b038116600090815260066020526040812054610ca49083906123f5565b611c3a61225e565b6117208585858585612dff565b6000611c51612f2c565b610d5a8383612f6b565b611c6361225e565b611a8583838361304e565b611c76612015565b61130082600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ccd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cf19190613a19565b600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d689190613a19565b84612288565b60008111611da35760405162461bcd60e51b8152602060048201526002602482015261414760f01b60448201526064016111a2565b50565b6001600160a01b038082166000908152600e60209081526040808320938616835292815282822060010154600d909152918120549091908290611b199083612252565b600f6020528160005260406000208181548110611e0557600080fd5b6000918252602090912001546001600160a01b03169150829050565b611e2961225e565b6001600160a01b03928316600090815260086020908152604080832096909516825294909452919092206001810192909255600290910155565b6000546001600160a01b03163314611e8d5760405162461bcd60e51b81526004016111a290613a4c565b6001600160a01b038116611ef25760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016111a2565b611da381612707565b611f0361225e565b611a8583838361250b565b600154604051635c197b9960e01b81526001600160a01b03848116600483015290911690635c197b9990602401602060405180830381865afa158015611f58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f7c9190613a00565b8110158015611f935750670de0b6b3a76400008111155b6113005760405162461bcd60e51b815260206004820152600260248201526126a360f11b60448201526064016111a2565b611fcc612f2c565b6113008282613238565b6000611fe0612015565b6001600160a01b0380841660009081526008602090815260408083209388168352929052908120600101546115e79084612246565b6002546001600160a01b031633146114035760405162461bcd60e51b81526004016111a290613a97565b6001600160a01b038281166000818152600f6020908152604082208054600180820183558285529284200180546001600160a01b03191695871695909517909455918152915461208e91612252565b6001600160a01b03808416600090815260086020908152604080832093881683529290522060040180546001600160801b03831661010002610100600160881b0319909116179055905092915050565b600154604051631108308b60e31b81526001600160a01b038481166004830152600092610d5a9261215e92869216906388418458906024015b602060405180830381865afa158015612134573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121589190613a00565b90612246565b60015460405163098e8fa760e01b81526001600160a01b0387811660048301529091169063098e8fa790602401602060405180830381865afa1580156121a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121cc9190613a00565b6132b2565b600082156121ee576121e783611b818685612bdf565b9050610d5a565b50600019610d5a565b600080612210670de0b6b3a7640000611b818686612bdf565b9050828110610d5a5760405162461bcd60e51b8152602060048201526002602482015261464560f01b60448201526064016111a2565b6000610d5a8284613ac9565b6000610d5a8284613ae1565b6003546001600160a01b031633146114035760405162461bcd60e51b81526004016111a290613a97565b6122928482610fb1565b1561108a576122a18482611405565b6122ad576122ad613a36565b60006122b98583611ad9565b905060006122c78684611da6565b6001600160a01b038085166000908152600860209081526040808320938b16835292905220600201549091506122fd9083612246565b6001600160a01b038481166000908152600860209081526040808320938b168352929052206002810191909155600101546123389082612246565b6001600160a01b038085166000908152600860209081526040808320938b168352929052206001015561236b8684612d81565b6123788686868486612dff565b6001600160a01b038381166000818152600860209081526040808320948b16808452949091528082206001810154600282015460039092015492519495947f100d2512a463b515ea8d03a69afbcc791f1bd9139132e820631bec236f524ec1946123e59492939291613af8565b60405180910390a3505050505050565b600154604051635c197b9960e01b81526001600160a01b038481166004830152600092610d5a926124329286921690635c197b9990602401612117565b670de0b6b3a76400006132b2565b60008061244c84611727565b9050600061245985610dcf565b9050611b9d8282866121d1565b6001600160a01b0381166124bc5760405162461bcd60e51b815260206004820152601e60248201527f4163636f756e742063616e6e6f74206265207a65726f2061646472657373000060448201526064016111a2565b803b806113005760405162461bcd60e51b815260206004820181905260248201527f4163636f756e7420636f64652073697a652063616e6e6f74206265207a65726f60448201526064016111a2565b600081600481111561251f5761251f613837565b1415801561253f5750600181600481111561253c5761253c613837565b14155b61254b5761254b613a36565b6001600160a01b0383166000908152600f602052604090205461256e84826132c8565b6001600160a01b03808416600090815260086020908152604080832093881683529290522060049081018054849260ff199091169060019084908111156125b7576125b7613837565b02179055506001600160a01b038381166000818152600860209081526040808320948916808452948252808320600281018490556001908101849055938352600e82528083209483529390529182208281550155612616848483613375565b600554604051637f7c149160e01b81526001600160a01b038681166004830152858116602483015290911690637f7c149190604401600060405180830381600087803b15801561266557600080fd5b505af1158015612679573d6000803e3d6000fd5b5050505050505050565b6001600160a01b0381166000908152600760205260408120546126a7904290612252565b9050603c8110611300576001600160a01b038216600081815260076020908152604091829020429081905591519182527f4b1a24436e474bd20ff461d446818e19b145a1ff52f698dec751807684621acc91015b60405180910390a25050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000806127648484612440565b600154604051631f6a526d60e11b81526001600160a01b038781166004830152929350911690633ed4a4da90602401602060405180830381865afa1580156127b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127d49190613a00565b119392505050565b6000610d5a670de0b6b3a7640000611b818585612bdf565b60008060006128038585611ad9565b905060006128118686611da6565b6001600160a01b038087166000908152600860209081526040808320938b168352929052908120600201549192509061284a9084612246565b6001600160a01b038088166000908152600860209081526040808320938c16835292905290812060010154919250906128839084612246565b91989197509095505050505050565b600081156128b8576128b182611b818568056bc75e2d63100000612bdf565b9050610ca4565b50600019610ca4565b8115611720576001600160a01b0385166000908152601060205260408120546128f69061215884670de0b6b3a7640000612bdf565b6001600160a01b038716600090815260116020526040812054919250906129299061215886670de0b6b3a7640000612bdf565b6001600160a01b03881660009081526009602052604081205491925090612951908490612beb565b6001600160a01b03891660009081526009602052604081205491925090612979908490612beb565b6001600160a01b038a166000908152600960205260409020549091506129ab906129a4908490612bdf565b8590612252565b6001600160a01b038a166000908152601060209081526040808320939093556009905220546129e6906129df908390612bdf565b8490612252565b6001600160a01b038a16600090815260116020908152604080832093909355600c90522054612a159083612246565b6001600160a01b038a166000908152600c6020908152604080832093909355600d90522054612a449082612246565b6001600160a01b038a166000818152600d60208181526040808420869055600c82529283902054918152825191825281019390935290917f6f63d00bdf85957664165c9e20900aabd5a17378cb5c0955ce760e48a6ae48c7910160405180910390a260405163fb24e5f760e01b81526001600160a01b038a811660048301526024820188905289169063fb24e5f790604401600060405180830381600087803b158015612af057600080fd5b505af1158015612b04573d6000803e3d6000fd5b50506040516306df996d60e41b81526001600160a01b038c81166004830152602482018a90528a169250636df996d09150604401600060405180830381600087803b158015612b5257600080fd5b505af1158015612b66573d6000803e3d6000fd5b50506040516347878f1560e01b81526001600160a01b038c811660048301528a81166024830152604482018990528b1692506347878f159150606401600060405180830381600087803b158015612bbc57600080fd5b505af1158015612bd0573d6000803e3d6000fd5b50505050505050505050505050565b6000610d5a8284613b2c565b6000610d5a8284613b61565b600080612c0386611ba6565b90506000612c1584611b818888612bdf565b90506000612c2e612c27836002612beb565b8490612246565b9050612c4281670de0b6b3a76400006132b2565b905060008111612c5457612c54613a36565b6001600160a01b03881660008181526006602052604090819020839055517f2f992d01b594c040f05262961e43f8311e780be5fee3deb4c57880dd6374d12d90612ca19084815260200190565b60405180910390a2611aaa88612683565b6001600160a01b038116600090815260076020526040812054610ca490603c90611b81904290612252565b6000631f540500821115612cf357631f54050091505b81600003612d0a5750670de0b6b3a7640000610ca4565b670de0b6b3a764000083835b6001811115612d7757612d2a600282613b75565b600003612d4f57612d3b82836135ac565b9150612d48816002612beb565b9050612d16565b612d5982846135ac565b9250612d6582836135ac565b9150612d486002611b81836001612252565b61170182846135ac565b6001600160a01b038281166000818152600c6020908152604080832080549587168452600e83528184208585528352818420958655600d835292819020546001909501859055915482519081529081019390935290917fc3d426bcfc672bd74f6fae61c225e06f556f80dad48af8a4631b295030a7ad3d91016126fb565b60405163fb24e5f760e01b81526001600160a01b0386811660048301526024820184905284169063fb24e5f790604401600060405180830381600087803b158015612e4957600080fd5b505af1158015612e5d573d6000803e3d6000fd5b50506040516306df996d60e41b81526001600160a01b0388811660048301526024820186905287169250636df996d09150604401600060405180830381600087803b158015612eab57600080fd5b505af1158015612ebf573d6000803e3d6000fd5b505060405163053f8cf960e31b81526001600160a01b03888116600483015260248201859052861692506329fc67c89150604401600060405180830381600087803b158015612f0d57600080fd5b505af1158015612f21573d6000803e3d6000fd5b505050505050505050565b6002546001600160a01b0316331480612f4f57506003546001600160a01b031633145b6114035760405162461bcd60e51b81526004016111a290613a97565b6001600160a01b0380821660009081526008602090815260408083209386168352929052908120600201548190612fa39085906135d5565b6001600160a01b038481166000908152600860209081526040808320938916835292815282822060030180549085905560099091529190205491925090612ff09083906121589084612252565b6001600160a01b038616600081815260096020526040908190208390555190917fd5630907014190fb9340da1cf427c96f094dabfbf73d25506e4b0cda9e3a4ca09161303e91815260200190565b60405180910390a2509392505050565b6001600160a01b03838116600081815260096020908152604080832054600a9092528083209190915551635373433f60e01b8152600481019290925291841690635373433f90602401602060405180830381865afa1580156130b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130d89190613a00565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa15801561312f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131539190613a19565b604051635373433f60e01b81526001600160a01b0387811660048301529190911690635373433f90602401602060405180830381865afa15801561319b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131bf9190613a00565b90506131cf816121588486612252565b6001600160a01b0386166000818152600b60208181526040808420869055600a82529283902054918152825191825281019390935290917f9ea5863ffc9d961d6c6bb67235c553dfbdbcc8fe12671cdba8887a50501efbaf910160405180910390a25050505050565b6001600160a01b0380821660009081526008602090815260408083209386168352928152828220600301546009909152919020546132769082612252565b6001600160a01b039384166000818152600960209081526040808320949094559490951685526008845281852090855290925250812060030155565b60008183106132c15781610d5a565b5090919050565b600181118015613344575060055460405163504f167160e01b81526001600160a01b038481166004830152600192169063504f167190602401602060405180830381865afa15801561331e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133429190613a00565b115b6113005760405162461bcd60e51b81526020600482015260026024820152614f4f60f01b60448201526064016111a2565b6001600160a01b03808316600090815260086020908152604080832093871683529290529081206004015460ff16908160048111156133b6576133b6613837565b141580156133d6575060018160048111156133d3576133d3613837565b14155b6133e2576133e2613a36565b6001600160a01b03838116600090815260086020908152604080832093881683529290529081206004015461010090046001600160801b0316908390613429826001612252565b905080836001600160801b0316111561344457613444613a36565b6001600160a01b0387166000908152600f6020526040812080548390811061346e5761346e613a81565b60009182526020808320909101546001600160a01b038b81168452600f909252604090922080549190921692508291906001600160801b0387169081106134b7576134b7613a81565b600091825260208083209190910180546001600160a01b0319166001600160a01b03948516179055838316808352600882526040808420948d16808552948352928390206004018054610100600160881b0319166101006001600160801b038b16908102919091179091558351918252918101919091527f596c08527bf037a7d30b01f257c1ba24ebd2a664cde69f8315accfee1199c668910160405180910390a26001600160a01b0388166000908152600f6020526040902080548061358057613580613b89565b600082815260209020810160001990810180546001600160a01b03191690550190555050505050505050565b6000806135b98484612bdf565b9050610fa9670de0b6b3a7640000611b81612c27600283613b61565b6001600160a01b0382166000908152600b6020526040812054819081036135fd575081610d5a565b6001600160a01b0384166000908152600a602052604090205461362257613622613a36565b6001600160a01b0384166000908152600b6020908152604080832054600a90925290912054610fa99190611b81908690612bdf565b6001600160a01b0381168114611da357600080fd5b6000806040838503121561367f57600080fd5b823561368a81613657565b9150602083013561369a81613657565b809150509250929050565b6000602082840312156136b757600080fd5b8135610d5a81613657565b600080600080608085870312156136d857600080fd5b84356136e381613657565b966020860135965060408601359560600135945092505050565b6000806040838503121561371057600080fd5b823561371b81613657565b946020939093013593505050565b60008060006060848603121561373e57600080fd5b833561374981613657565b9250602084013561375981613657565b929592945050506040919091013590565b6000806000806080858703121561378057600080fd5b843561378b81613657565b9350602085013561379b81613657565b925060408501356137ab81613657565b915060608501356137bb81613657565b939692955090935050565b600080600080600060a086880312156137de57600080fd5b85356137e981613657565b945060208601356137f981613657565b9350604086013561380981613657565b9250606086013561381981613657565b9150608086013561382981613657565b809150509295509295909350565b634e487b7160e01b600052602160045260246000fd5b6001600160a01b038716815260208101869052604081018590526060810184905260c081016005841061388257613882613837565b8360808301526001600160801b03831660a0830152979650505050505050565b600080600080600060a086880312156138ba57600080fd5b85356138c581613657565b945060208601356138d581613657565b935060408601356138e581613657565b94979396509394606081013594506080013592915050565b600060208083528351808285015260005b8181101561392a5785810183015185820160400152820161390e565b8181111561393c576000604083870101525b50601f01601f1916929092016040019392505050565b60006020828403121561396457600080fd5b5035919050565b6000806000806080858703121561398157600080fd5b843561398c81613657565b9350602085013561399c81613657565b93969395505050506040820135916060013590565b6000806000606084860312156139c657600080fd5b83356139d181613657565b925060208401356139e181613657565b91506040840135600581106139f557600080fd5b809150509250925092565b600060208284031215613a1257600080fd5b5051919050565b600060208284031215613a2b57600080fd5b8151610d5a81613657565b634e487b7160e01b600052600160045260246000fd5b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052603260045260246000fd5b602080825260029082015261574160f01b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b60008219821115613adc57613adc613ab3565b500190565b600082821015613af357613af3613ab3565b500390565b84815260208101849052604081018390526080810160048310613b1d57613b1d613837565b82606083015295945050505050565b6000816000190483118215151615613b4657613b46613ab3565b500290565b634e487b7160e01b600052601260045260246000fd5b600082613b7057613b70613b4b565b500490565b600082613b8457613b84613b4b565b500690565b634e487b7160e01b600052603160045260246000fdfea2646970667358221220fe87936c38615770fb01bfa98eb3ce179025a46d083131b49f8e294bc47a51fe64736f6c634300080e0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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.