ETH Price: $3,393.97 (+1.39%)

Contract

0x6a9f9d6F5D672a9784c5E560a9648de6cbe2c548
 

Overview

ETH Balance

19.420282044243484535 ETH

Eth Value

$65,911.85 (@ $3,393.97/ETH)

Token Holdings

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Withdraw From SP214096452024-12-15 18:16:238 days ago1734286583IN
DeFi Franc: ETH Stability Pool
0 ETH0.0013838310.4613142
Withdraw From SP213073702024-12-01 11:29:5922 days ago1733052599IN
DeFi Franc: ETH Stability Pool
0 ETH0.0027093410.5
Withdraw From SP212898462024-11-29 0:42:4725 days ago1732840967IN
DeFi Franc: ETH Stability Pool
0 ETH0.00074695
Withdraw From SP212669642024-11-25 19:50:2328 days ago1732564223IN
DeFi Franc: ETH Stability Pool
0 ETH0.0022848117.27246843
Withdraw From SP212274252024-11-20 7:21:3533 days ago1732087295IN
DeFi Franc: ETH Stability Pool
0 ETH0.001077148.14288123
Withdraw From SP212102052024-11-17 21:46:1136 days ago1731879971IN
DeFi Franc: ETH Stability Pool
0 ETH0.0012562410.48689634
Withdraw From SP211306492024-11-06 19:18:1147 days ago1730920691IN
DeFi Franc: ETH Stability Pool
0 ETH0.0022057214.76575798
Withdraw From SP210443932024-10-25 18:22:1159 days ago1729880531IN
DeFi Franc: ETH Stability Pool
0 ETH0.0053646519.3643887
Withdraw From SP210443862024-10-25 18:20:4759 days ago1729880447IN
DeFi Franc: ETH Stability Pool
0 ETH0.0024764421.96928974
Withdraw From SP209551522024-10-13 7:25:1171 days ago1728804311IN
DeFi Franc: ETH Stability Pool
0 ETH0.001235419.33933469
Withdraw From SP207876152024-09-19 22:25:5995 days ago1726784759IN
DeFi Franc: ETH Stability Pool
0 ETH0.000967327.3126812
Provide To SP206768632024-09-04 11:16:47110 days ago1725448607IN
DeFi Franc: ETH Stability Pool
0 ETH0.000371342.02177464
Withdraw From SP206550842024-09-01 10:20:11113 days ago1725186011IN
DeFi Franc: ETH Stability Pool
0 ETH0.000139831.05711379
Withdraw From SP206363842024-08-29 19:39:35116 days ago1724960375IN
DeFi Franc: ETH Stability Pool
0 ETH0.000278252.10349366
Withdraw From SP206308172024-08-29 0:58:23117 days ago1724893103IN
DeFi Franc: ETH Stability Pool
0 ETH0.000276511.85106272
Provide To SP204669822024-08-06 3:56:23139 days ago1722916583IN
DeFi Franc: ETH Stability Pool
0 ETH0.000396462.15870375
Withdraw From SP204669412024-08-06 3:48:11139 days ago1722916091IN
DeFi Franc: ETH Stability Pool
0 ETH0.000278821.86654445
Withdraw From SP204043322024-07-28 10:04:47148 days ago1722161087IN
DeFi Franc: ETH Stability Pool
0 ETH0.000467541.81053661
Withdraw From SP203933692024-07-26 21:20:23150 days ago1722028823IN
DeFi Franc: ETH Stability Pool
0 ETH0.000299872.26692143
Withdraw From SP202262642024-07-03 13:25:11173 days ago1720013111IN
DeFi Franc: ETH Stability Pool
0 ETH0.0027049920.44882589
Withdraw From SP202041872024-06-30 11:24:59176 days ago1719746699IN
DeFi Franc: ETH Stability Pool
0 ETH0.000340522.57425815
Withdraw From SP201967732024-06-29 10:33:35177 days ago1719657215IN
DeFi Franc: ETH Stability Pool
0 ETH0.000299372.00413043
Withdraw From SP201459322024-06-22 8:04:11184 days ago1719043451IN
DeFi Franc: ETH Stability Pool
0 ETH0.000362082.73720531
Withdraw From SP201218472024-06-18 23:13:47188 days ago1718752427IN
DeFi Franc: ETH Stability Pool
0 ETH0.000602994.5584239
Withdraw From SP201058672024-06-16 17:32:59190 days ago1718559179IN
DeFi Franc: ETH Stability Pool
0 ETH0.000596234.50734772
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
214096452024-12-15 18:16:238 days ago1734286583
DeFi Franc: ETH Stability Pool
0.0162657 ETH
213073702024-12-01 11:29:5922 days ago1733052599
DeFi Franc: ETH Stability Pool
0.04048317 ETH
212898462024-11-29 0:42:4725 days ago1732840967
DeFi Franc: ETH Stability Pool
0.02609922 ETH
212669642024-11-25 19:50:2328 days ago1732564223
DeFi Franc: ETH Stability Pool
0.06339521 ETH
212274252024-11-20 7:21:3533 days ago1732087295
DeFi Franc: ETH Stability Pool
0.00559575 ETH
212102052024-11-17 21:46:1136 days ago1731879971
DeFi Franc: ETH Stability Pool
0.00790741 ETH
211306492024-11-06 19:18:1147 days ago1730920691
DeFi Franc: ETH Stability Pool
0.03446196 ETH
209551522024-10-13 7:25:1171 days ago1728804311
DeFi Franc: ETH Stability Pool
0.00603551 ETH
207876152024-09-19 22:25:5995 days ago1726784759
DeFi Franc: ETH Stability Pool
0.00346356 ETH
206550842024-09-01 10:20:11113 days ago1725186011
DeFi Franc: ETH Stability Pool
0.03813923 ETH
206363842024-08-29 19:39:35116 days ago1724960375
DeFi Franc: ETH Stability Pool
0.01752135 ETH
206308172024-08-29 0:58:23117 days ago1724893103
DeFi Franc: ETH Stability Pool
0.00413425 ETH
204669412024-08-06 3:48:11139 days ago1722916091
DeFi Franc: ETH Stability Pool
0.00782805 ETH
204043322024-07-28 10:04:47148 days ago1722161087
DeFi Franc: ETH Stability Pool
0.00375514 ETH
203933692024-07-26 21:20:23150 days ago1722028823
DeFi Franc: ETH Stability Pool
0.66450531 ETH
202262642024-07-03 13:25:11173 days ago1720013111
DeFi Franc: ETH Stability Pool
0.11454183 ETH
202041872024-06-30 11:24:59176 days ago1719746699
DeFi Franc: ETH Stability Pool
0.6652025 ETH
201967732024-06-29 10:33:35177 days ago1719657215
DeFi Franc: ETH Stability Pool
0.06229408 ETH
201459322024-06-22 8:04:11184 days ago1719043451
DeFi Franc: ETH Stability Pool
0.00252926 ETH
201218472024-06-18 23:13:47188 days ago1718752427
DeFi Franc: ETH Stability Pool
0.02421939 ETH
201058672024-06-16 17:32:59190 days ago1718559179
DeFi Franc: ETH Stability Pool
0.16373626 ETH
200989882024-06-15 18:29:23191 days ago1718476163
DeFi Franc: ETH Stability Pool
0.97185313 ETH
200595582024-06-10 6:11:47196 days ago1717999907
DeFi Franc: ETH Stability Pool
0.00000267 ETH
200477152024-06-08 14:29:59198 days ago1717856999
DeFi Franc: ETH Stability Pool
0.02477215 ETH
200346022024-06-06 18:33:59200 days ago1717698839
DeFi Franc: ETH Stability Pool
0.02946698 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StabilityPool

Compiler Version
v0.8.14+commit.80d49f37

Optimization Enabled:
Yes with 200 runs

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

pragma solidity ^0.8.14;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

import "./Interfaces/IBorrowerOperations.sol";
import "./Interfaces/IStabilityPool.sol";
import "./Interfaces/IBorrowerOperations.sol";
import "./Interfaces/ITroveManager.sol";
import "./Interfaces/ITroveManagerHelpers.sol";
import "./Interfaces/IDCHFToken.sol";
import "./Interfaces/ISortedTroves.sol";
import "./Interfaces/ICommunityIssuance.sol";
import "./Dependencies/DfrancBase.sol";
import "./Dependencies/DfrancSafeMath128.sol";
import "./Dependencies/CheckContract.sol";
import "./Dependencies/SafetyTransfer.sol";
import "./Dependencies/Initializable.sol";

contract StabilityPool is
	DfrancBase,
	CheckContract,
	ReentrancyGuard,
	Initializable,
	IStabilityPool
{
	using SafeMath for uint256;
	using DfrancSafeMath128 for uint128;
	using SafeERC20 for IERC20;

	string public constant NAME = "StabilityPool";
	bytes32 public constant STABILITY_POOL_NAME_BYTES =
		0xf704b47f65a99b2219b7213612db4be4a436cdf50624f4baca1373ef0de0aac7;

	IBorrowerOperations public borrowerOperations;

	ITroveManager public troveManager;

	ITroveManagerHelpers public troveManagerHelpers;

	IDCHFToken public dchfToken;

	// Needed to check if there are pending liquidations
	ISortedTroves public sortedTroves;

	ICommunityIssuance public communityIssuance;

	address internal assetAddress;

	uint256 internal assetBalance; // deposited ether tracker

	// Tracker for DCHF held in the pool. Changes when users deposit/withdraw, and when Trove debt is offset.
	uint256 internal totalDCHFDeposits;

	// --- Data structures ---

	struct Snapshots {
		uint256 S;
		uint256 P;
		uint256 G;
		uint128 scale;
		uint128 epoch;
	}

	mapping(address => uint256) public deposits; // depositor address -> Deposit struct
	mapping(address => Snapshots) public depositSnapshots; // depositor address -> snapshots struct

	uint256 public totalStakes;
	Snapshots public systemSnapshots;

	/*  Product 'P': Running product by which to multiply an initial deposit, in order to find the current compounded deposit,
	 * after a series of liquidations have occurred, each of which cancel some DCHF debt with the deposit.
	 *
	 * During its lifetime, a deposit's value evolves from d_t to d_t * P / P_t , where P_t
	 * is the snapshot of P taken at the instant the deposit was made. 18-digit decimal.
	 */
	uint256 public P;

	uint256 public constant SCALE_FACTOR = 1e9;

	// Each time the scale of P shifts by SCALE_FACTOR, the scale is incremented by 1
	uint128 public currentScale;

	// With each offset that fully empties the Pool, the epoch is incremented by 1
	uint128 public currentEpoch;

	/* ETH Gain sum 'S': During its lifetime, each deposit d_t earns an ETH gain of ( d_t * [S - S_t] )/P_t, where S_t
	 * is the depositor's snapshot of S taken at the time t when the deposit was made.
	 *
	 * The 'S' sums are stored in a nested mapping (epoch => scale => sum):
	 *
	 * - The inner mapping records the sum S at different scales
	 * - The outer mapping records the (scale => sum) mappings, for different epochs.
	 */
	mapping(uint128 => mapping(uint128 => uint256)) public epochToScaleToSum;

	/*
	 * Similarly, the sum 'G' is used to calculate MON gains. During it's lifetime, each deposit d_t earns a MON gain of
	 *  ( d_t * [G - G_t] )/P_t, where G_t is the depositor's snapshot of G taken at time t when  the deposit was made.
	 *
	 *  MON reward events occur are triggered by depositor operations (new deposit, topup, withdrawal), and liquidations.
	 *  In each case, the MON reward is issued (i.e. G is updated), before other state changes are made.
	 */
	mapping(uint128 => mapping(uint128 => uint256)) public epochToScaleToG;

	// Error tracker for the error correction in the MON issuance calculation
	uint256 public lastMONError;
	// Error trackers for the error correction in the offset calculation
	uint256 public lastAssetError_Offset;
	uint256 public lastDCHFLossError_Offset;

	bool public isInitialized;

	// --- Contract setters ---

	function getNameBytes() external pure override returns (bytes32) {
		return STABILITY_POOL_NAME_BYTES;
	}

	function getAssetType() external view override returns (address) {
		return assetAddress;
	}

	function setAddresses(
		address _assetAddress,
		address _borrowerOperationsAddress,
		address _troveManagerAddress,
		address _troveManagerHelpersAddress,
		address _dchfTokenAddress,
		address _sortedTrovesAddress,
		address _communityIssuanceAddress,
		address _dfrancParamsAddress
	) external initializer onlyOwner {
		require(!isInitialized, "Already initialized");
		checkContract(_borrowerOperationsAddress);
		checkContract(_troveManagerAddress);
		checkContract(_troveManagerHelpersAddress);
		checkContract(_dchfTokenAddress);
		checkContract(_sortedTrovesAddress);
		checkContract(_communityIssuanceAddress);
		checkContract(_dfrancParamsAddress);

		isInitialized = true;

		if (_assetAddress != ETH_REF_ADDRESS) {
			checkContract(_assetAddress);
		}

		assetAddress = _assetAddress;
		borrowerOperations = IBorrowerOperations(_borrowerOperationsAddress);
		troveManager = ITroveManager(_troveManagerAddress);
		troveManagerHelpers = ITroveManagerHelpers(_troveManagerHelpersAddress);
		dchfToken = IDCHFToken(_dchfTokenAddress);
		sortedTroves = ISortedTroves(_sortedTrovesAddress);
		communityIssuance = ICommunityIssuance(_communityIssuanceAddress);
		setDfrancParameters(_dfrancParamsAddress);

		P = DECIMAL_PRECISION;

		emit BorrowerOperationsAddressChanged(_borrowerOperationsAddress);
		emit TroveManagerAddressChanged(_troveManagerAddress);
		emit DCHFTokenAddressChanged(_dchfTokenAddress);
		emit SortedTrovesAddressChanged(_sortedTrovesAddress);
		emit CommunityIssuanceAddressChanged(_communityIssuanceAddress);
	}

	// --- Getters for public variables. Required by IPool interface ---

	function getAssetBalance() external view override returns (uint256) {
		return assetBalance;
	}

	function getTotalDCHFDeposits() external view override returns (uint256) {
		return totalDCHFDeposits;
	}

	// --- External Depositor Functions ---

	/*  provideToSP():
	 *
	 * - Triggers a MON issuance, based on time passed since the last issuance. The MON issuance is shared between *all* depositors
	 * - Sends depositor's accumulated gains (MON, ETH) to depositor
	 * - Increases deposit and system stake, and takes new snapshots for each.
	 */
	function provideToSP(uint256 _amount) external override nonReentrant {
		_requireNonZeroAmount(_amount);

		uint256 initialDeposit = deposits[msg.sender];

		ICommunityIssuance communityIssuanceCached = communityIssuance;
		_triggerMONIssuance(communityIssuanceCached);

		uint256 depositorAssetGain = getDepositorAssetGain(msg.sender);
		uint256 depositorAssetGainEther = getDepositorAssetGain1e18(msg.sender);

		uint256 compoundedDCHFDeposit = getCompoundedDCHFDeposit(msg.sender);
		uint256 DCHFLoss = initialDeposit.sub(compoundedDCHFDeposit); // Needed only for event log

		// First pay out any MON gains
		_payOutMONGains(communityIssuanceCached, msg.sender);

		// Update System stake
		uint256 compoundedStake = getCompoundedTotalStake();
		uint256 newStake = compoundedStake.add(_amount);
		_updateStakeAndSnapshots(newStake);
		emit StakeChanged(newStake, msg.sender);

		_sendDCHFtoStabilityPool(msg.sender, _amount);

		uint256 newDeposit = compoundedDCHFDeposit.add(_amount);
		_updateDepositAndSnapshots(msg.sender, newDeposit);

		emit UserDepositChanged(msg.sender, newDeposit);
		emit AssetGainWithdrawn(msg.sender, depositorAssetGain, DCHFLoss); // DCHF Loss required for event log

		_sendAssetGainToDepositor(depositorAssetGain, depositorAssetGainEther);
	}

	/*  withdrawFromSP():
	 *
	 * - Triggers a MON issuance, based on time passed since the last issuance. The MON issuance is shared between *all* depositors
	 * - Sends all depositor's accumulated gains (MON, ETH) to depositor
	 * - Decreases deposit and system stake, and takes new snapshots for each.
	 *
	 * If _amount > userDeposit, the user withdraws all of their compounded deposit.
	 */
	function withdrawFromSP(uint256 _amount) external override nonReentrant {
		if (_amount != 0) {
			_requireNoUnderCollateralizedTroves();
		}
		uint256 initialDeposit = deposits[msg.sender];
		_requireUserHasDeposit(initialDeposit);

		ICommunityIssuance communityIssuanceCached = communityIssuance;

		_triggerMONIssuance(communityIssuanceCached);

		uint256 depositorAssetGain = getDepositorAssetGain(msg.sender);
		uint256 depositorAssetGainEther = getDepositorAssetGain1e18(msg.sender);

		uint256 compoundedDCHFDeposit = getCompoundedDCHFDeposit(msg.sender);
		uint256 DCHFtoWithdraw = DfrancMath._min(_amount, compoundedDCHFDeposit);
		uint256 DCHFLoss = initialDeposit.sub(compoundedDCHFDeposit); // Needed only for event log

		// First pay out any MON gains
		_payOutMONGains(communityIssuanceCached, msg.sender);

		// Update System stake
		uint256 compoundedStake = getCompoundedTotalStake();
		uint256 newStake = compoundedStake.sub(DCHFtoWithdraw);
		_updateStakeAndSnapshots(newStake);
		emit StakeChanged(newStake, msg.sender);

		_sendDCHFToDepositor(msg.sender, DCHFtoWithdraw);

		// Update deposit
		uint256 newDeposit = compoundedDCHFDeposit.sub(DCHFtoWithdraw);
		_updateDepositAndSnapshots(msg.sender, newDeposit);
		emit UserDepositChanged(msg.sender, newDeposit);

		emit AssetGainWithdrawn(msg.sender, depositorAssetGain, DCHFLoss); // DCHF Loss required for event log

		_sendAssetGainToDepositor(depositorAssetGain, depositorAssetGainEther);
	}

	/* withdrawETHGainToTrove:
	 * - Triggers a MON issuance, based on time passed since the last issuance. The MON issuance is shared between *all* depositors
	 * - Sends all depositor's MON gain to  depositor
	 * - 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 system stake */
	function withdrawAssetGainToTrove(address _upperHint, address _lowerHint) external override {
		uint256 initialDeposit = deposits[msg.sender];
		_requireUserHasDeposit(initialDeposit);
		_requireUserHasTrove(msg.sender);
		_requireUserHasETHGain(msg.sender);

		ICommunityIssuance communityIssuanceCached = communityIssuance;

		_triggerMONIssuance(communityIssuanceCached);

		uint256 depositorAssetGain = getDepositorAssetGain1e18(msg.sender);

		uint256 compoundedDCHFDeposit = getCompoundedDCHFDeposit(msg.sender);
		uint256 DCHFLoss = initialDeposit.sub(compoundedDCHFDeposit); // Needed only for event log

		// First pay out any MON gains
		_payOutMONGains(communityIssuanceCached, msg.sender);

		// Update System stake
		uint256 compoundedSystemStake = getCompoundedTotalStake();
		_updateStakeAndSnapshots(compoundedSystemStake);
		emit StakeChanged(compoundedSystemStake, msg.sender);

		_updateDepositAndSnapshots(msg.sender, compoundedDCHFDeposit);

		/* Emit events before transferring ETH gain to Trove.
         This lets the event log make more sense (i.e. so it appears that first the ETH gain is withdrawn
        and then it is deposited into the Trove, not the other way around). */
		emit AssetGainWithdrawn(msg.sender, depositorAssetGain, DCHFLoss);
		emit UserDepositChanged(msg.sender, compoundedDCHFDeposit);

		assetBalance = assetBalance.sub(depositorAssetGain);
		emit StabilityPoolAssetBalanceUpdated(assetBalance);
		emit AssetSent(msg.sender, depositorAssetGain);

		borrowerOperations.moveETHGainToTrove{
			value: assetAddress == address(0) ? depositorAssetGain : 0
		}(assetAddress, depositorAssetGain, msg.sender, _upperHint, _lowerHint);
	}

	// --- MON issuance functions ---

	function _triggerMONIssuance(ICommunityIssuance _communityIssuance) internal {
		uint256 MONIssuance = _communityIssuance.issueMON();
		_updateG(MONIssuance);
	}

	function _updateG(uint256 _MONIssuance) internal {
		uint256 totalDCHF = totalDCHFDeposits; // cached to save an SLOAD
		/*
		 * When total deposits is 0, G is not updated. In this case, the MON issued can not be obtained by later
		 * depositors - it is missed out on, and remains in the balanceof the CommunityIssuance contract.
		 *
		 */
		if (totalDCHF == 0 || _MONIssuance == 0) {
			return;
		}

		uint256 MONPerUnitStaked;
		MONPerUnitStaked = _computeMONPerUnitStaked(_MONIssuance, totalDCHF);

		uint256 marginalMONGain = MONPerUnitStaked.mul(P);
		epochToScaleToG[currentEpoch][currentScale] = epochToScaleToG[currentEpoch][currentScale]
			.add(marginalMONGain);

		emit G_Updated(epochToScaleToG[currentEpoch][currentScale], currentEpoch, currentScale);
	}

	function _computeMONPerUnitStaked(uint256 _MONIssuance, uint256 _totalDCHFDeposits)
		internal
		returns (uint256)
	{
		/*
		 * Calculate the MON-per-unit staked.  Division uses a "feedback" error correction, to keep the
		 * cumulative error low in the running total G:
		 *
		 * 1) Form a numerator which compensates for the floor division error that occurred the last time this
		 * function was called.
		 * 2) Calculate "per-unit-staked" ratio.
		 * 3) Multiply the ratio back by its denominator, to reveal the current floor division error.
		 * 4) Store this error 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 MONNumerator = _MONIssuance.mul(DECIMAL_PRECISION).add(lastMONError);

		uint256 MONPerUnitStaked = MONNumerator.div(_totalDCHFDeposits);
		lastMONError = MONNumerator.sub(MONPerUnitStaked.mul(_totalDCHFDeposits));

		return MONPerUnitStaked;
	}

	// --- Liquidation functions ---

	/*
	 * 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 _debtToOffset, uint256 _collToAdd) external override {
		_requireCallerIsTroveManager();
		uint256 totalDCHF = totalDCHFDeposits; // cached to save an SLOAD
		if (totalDCHF == 0 || _debtToOffset == 0) {
			return;
		}

		_triggerMONIssuance(communityIssuance);

		(
			uint256 AssetGainPerUnitStaked,
			uint256 DCHFLossPerUnitStaked
		) = _computeRewardsPerUnitStaked(_collToAdd, _debtToOffset, totalDCHF);

		_updateRewardSumAndProduct(AssetGainPerUnitStaked, DCHFLossPerUnitStaked); // updates S and P

		_moveOffsetCollAndDebt(_collToAdd, _debtToOffset);
	}

	// --- Offset helper functions ---

	function _computeRewardsPerUnitStaked(
		uint256 _collToAdd,
		uint256 _debtToOffset,
		uint256 _totalDCHFDeposits
	) internal returns (uint256 AssetGainPerUnitStaked, uint256 DCHFLossPerUnitStaked) {
		/*
		 * Compute the DCHF and ETH rewards. Uses a "feedback" error correction, to keep
		 * the cumulative error in the P and S state variables low:
		 *
		 * 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 AssetNumerator = _collToAdd.mul(DECIMAL_PRECISION).add(lastAssetError_Offset);

		assert(_debtToOffset <= _totalDCHFDeposits);
		if (_debtToOffset == _totalDCHFDeposits) {
			DCHFLossPerUnitStaked = DECIMAL_PRECISION; // When the Pool depletes to 0, so does each deposit
			lastDCHFLossError_Offset = 0;
		} else {
			uint256 DCHFLossNumerator = _debtToOffset.mul(DECIMAL_PRECISION).sub(
				lastDCHFLossError_Offset
			);
			/*
			 * Add 1 to make error in quotient positive. We want "slightly too much" DCHF loss,
			 * which ensures the error in any given compoundedDCHFDeposit favors the Stability Pool.
			 */
			DCHFLossPerUnitStaked = (DCHFLossNumerator.div(_totalDCHFDeposits)).add(1);
			lastDCHFLossError_Offset = (DCHFLossPerUnitStaked.mul(_totalDCHFDeposits)).sub(
				DCHFLossNumerator
			);
		}

		AssetGainPerUnitStaked = AssetNumerator.div(_totalDCHFDeposits);
		lastAssetError_Offset = AssetNumerator.sub(AssetGainPerUnitStaked.mul(_totalDCHFDeposits));

		return (AssetGainPerUnitStaked, DCHFLossPerUnitStaked);
	}

	// Update the Stability Pool reward sum S and product P
	function _updateRewardSumAndProduct(
		uint256 _AssetGainPerUnitStaked,
		uint256 _DCHFLossPerUnitStaked
	) internal {
		uint256 currentP = P;
		uint256 newP;

		assert(_DCHFLossPerUnitStaked <= DECIMAL_PRECISION);
		/*
		 * The newProductFactor is the factor by which to change all deposits, due to the depletion of Stability Pool DCHF in the liquidation.
		 * We make the product factor 0 if there was a pool-emptying. Otherwise, it is (1 - DCHFLossPerUnitStaked)
		 */
		uint256 newProductFactor = uint256(DECIMAL_PRECISION).sub(_DCHFLossPerUnitStaked);

		uint128 currentScaleCached = currentScale;
		uint128 currentEpochCached = currentEpoch;
		uint256 currentS = epochToScaleToSum[currentEpochCached][currentScaleCached];

		/*
		 * Calculate the new S first, before we update P.
		 * The ETH gain for any given depositor from a liquidation depends on the value of their deposit
		 * (and the value of totalDeposits) prior to the Stability being depleted by the debt in the liquidation.
		 *
		 * Since S corresponds to ETH gain, and P to deposit loss, we update S first.
		 */
		uint256 marginalAssetGain = _AssetGainPerUnitStaked.mul(currentP);
		uint256 newS = currentS.add(marginalAssetGain);
		epochToScaleToSum[currentEpochCached][currentScaleCached] = newS;
		emit S_Updated(newS, currentEpochCached, currentScaleCached);

		// If the Stability Pool was emptied, increment the epoch, and reset the scale and product P
		if (newProductFactor == 0) {
			currentEpoch = currentEpochCached.add(1);
			emit EpochUpdated(currentEpoch);
			currentScale = 0;
			emit ScaleUpdated(currentScale);
			newP = DECIMAL_PRECISION;

			// If multiplying P by a non-zero product factor would reduce P below the scale boundary, increment the scale
		} else if (currentP.mul(newProductFactor).div(DECIMAL_PRECISION) < SCALE_FACTOR) {
			newP = currentP.mul(newProductFactor).mul(SCALE_FACTOR).div(DECIMAL_PRECISION);
			currentScale = currentScaleCached.add(1);
			emit ScaleUpdated(currentScale);
		} else {
			newP = currentP.mul(newProductFactor).div(DECIMAL_PRECISION);
		}

		assert(newP > 0);
		P = newP;

		emit P_Updated(newP);
	}

	function _moveOffsetCollAndDebt(uint256 _collToAdd, uint256 _debtToOffset) internal {
		IActivePool activePoolCached = dfrancParams.activePool();

		// Cancel the liquidated DCHF debt with the DCHF in the stability pool
		activePoolCached.decreaseDCHFDebt(assetAddress, _debtToOffset);
		_decreaseDCHF(_debtToOffset);

		// Burn the debt that was successfully offset
		dchfToken.burn(address(this), _debtToOffset);

		activePoolCached.sendAsset(assetAddress, address(this), _collToAdd);
	}

	function _decreaseDCHF(uint256 _amount) internal {
		uint256 newTotalDCHFDeposits = totalDCHFDeposits.sub(_amount);
		totalDCHFDeposits = newTotalDCHFDeposits;
		emit StabilityPoolDCHFBalanceUpdated(newTotalDCHFDeposits);
	}

	// --- Reward calculator functions for depositor ---

	/* Calculates the ETH gain earned by the deposit since its last snapshots were taken.
	 * Given by the formula:  E = d0 * (S - S(0))/P(0)
	 * where S(0) and P(0) are the depositor's snapshots of the sum S and product P, respectively.
	 * d0 is the last recorded deposit value.
	 */
	function getDepositorAssetGain(address _depositor) public view override returns (uint256) {
		uint256 initialDeposit = deposits[_depositor];

		if (initialDeposit == 0) {
			return 0;
		}

		Snapshots memory snapshots = depositSnapshots[_depositor];

		return
			SafetyTransfer.decimalsCorrection(
				assetAddress,
				_getAssetGainFromSnapshots(initialDeposit, snapshots)
			);
	}

	function getDepositorAssetGain1e18(address _depositor) public view returns (uint256) {
		uint256 initialDeposit = deposits[_depositor];

		if (initialDeposit == 0) {
			return 0;
		}

		Snapshots memory snapshots = depositSnapshots[_depositor];

		return _getAssetGainFromSnapshots(initialDeposit, snapshots);
	}

	function _getAssetGainFromSnapshots(uint256 initialDeposit, Snapshots memory snapshots)
		internal
		view
		returns (uint256)
	{
		/*
		 * Grab the sum 'S' from the epoch at which the stake was made. The ETH gain may span up to one scale change.
		 * If it does, the second portion of the ETH gain is scaled by 1e9.
		 * If the gain spans no scale change, the second portion will be 0.
		 */
		uint128 epochSnapshot = snapshots.epoch;
		uint128 scaleSnapshot = snapshots.scale;
		uint256 S_Snapshot = snapshots.S;
		uint256 P_Snapshot = snapshots.P;

		uint256 firstPortion = epochToScaleToSum[epochSnapshot][scaleSnapshot].sub(S_Snapshot);
		uint256 secondPortion = epochToScaleToSum[epochSnapshot][scaleSnapshot.add(1)].div(
			SCALE_FACTOR
		);

		uint256 AssetGain = initialDeposit
			.mul(firstPortion.add(secondPortion))
			.div(P_Snapshot)
			.div(DECIMAL_PRECISION);

		return AssetGain;
	}

	/*
	 * Calculate the MON gain earned by a deposit since its last snapshots were taken.
	 * Given by the formula:  MON = d0 * (G - G(0))/P(0)
	 * where G(0) and P(0) are the depositor's snapshots of the sum G and product P, respectively.
	 * d0 is the last recorded deposit value.
	 */
	function getDepositorMONGain(address _depositor) public view override returns (uint256) {
		uint256 initialDeposit = deposits[_depositor];
		if (initialDeposit == 0) {
			return 0;
		}

		Snapshots memory snapshots = depositSnapshots[_depositor];
		return _getMONGainFromSnapshots(initialDeposit, snapshots);
	}

	function _getMONGainFromSnapshots(uint256 initialStake, Snapshots memory snapshots)
		internal
		view
		returns (uint256)
	{
		/*
		 * Grab the sum 'G' from the epoch at which the stake was made. The MON gain may span up to one scale change.
		 * If it does, the second portion of the MON gain is scaled by 1e9.
		 * If the gain spans no scale change, the second portion will be 0.
		 */
		uint128 epochSnapshot = snapshots.epoch;
		uint128 scaleSnapshot = snapshots.scale;
		uint256 G_Snapshot = snapshots.G;
		uint256 P_Snapshot = snapshots.P;

		uint256 firstPortion = epochToScaleToG[epochSnapshot][scaleSnapshot].sub(G_Snapshot);
		uint256 secondPortion = epochToScaleToG[epochSnapshot][scaleSnapshot.add(1)].div(
			SCALE_FACTOR
		);

		uint256 MONGain = initialStake.mul(firstPortion.add(secondPortion)).div(P_Snapshot).div(
			DECIMAL_PRECISION
		);

		return MONGain;
	}

	// --- Compounded deposit and compounded System stake ---

	/*
	 * Return the user's compounded deposit. Given by the formula:  d = d0 * P/P(0)
	 * where P(0) is the depositor's snapshot of the product P, taken when they last updated their deposit.
	 */
	function getCompoundedDCHFDeposit(address _depositor)
		public
		view
		override
		returns (uint256)
	{
		uint256 initialDeposit = deposits[_depositor];
		if (initialDeposit == 0) {
			return 0;
		}

		return _getCompoundedStakeFromSnapshots(initialDeposit, depositSnapshots[_depositor]);
	}

	/*
	 * Return the system's compounded stake. Given by the formula:  D = D0 * P/P(0)
	 * where P(0) is the depositor's snapshot of the product P
	 *
	 * The system's compounded stake is equal to the sum of its depositors' compounded deposits.
	 */
	function getCompoundedTotalStake() public view override returns (uint256) {
		uint256 cachedStake = totalStakes;
		if (cachedStake == 0) {
			return 0;
		}

		return _getCompoundedStakeFromSnapshots(cachedStake, systemSnapshots);
	}

	// Internal function, used to calculcate compounded deposits and compounded stakes.
	function _getCompoundedStakeFromSnapshots(uint256 initialStake, Snapshots memory snapshots)
		internal
		view
		returns (uint256)
	{
		uint256 snapshot_P = snapshots.P;
		uint128 scaleSnapshot = snapshots.scale;
		uint128 epochSnapshot = snapshots.epoch;

		// If stake was made before a pool-emptying event, then it has been fully cancelled with debt -- so, return 0
		if (epochSnapshot < currentEpoch) {
			return 0;
		}

		uint256 compoundedStake;
		uint128 scaleDiff = currentScale.sub(scaleSnapshot);

		/* Compute the compounded stake. If a scale change in P was made during the stake's lifetime,
		 * account for it. If more than one scale change was made, then the stake has decreased by a factor of
		 * at least 1e-9 -- so return 0.
		 */
		if (scaleDiff == 0) {
			compoundedStake = initialStake.mul(P).div(snapshot_P);
		} else if (scaleDiff == 1) {
			compoundedStake = initialStake.mul(P).div(snapshot_P).div(SCALE_FACTOR);
		} else {
			compoundedStake = 0;
		}

		/*
		 * If compounded deposit is less than a billionth of the initial deposit, return 0.
		 *
		 * NOTE: originally, this line was in place to stop rounding errors making the deposit too large. However, the error
		 * corrections should ensure the error in P "favors the Pool", i.e. any given compounded deposit should slightly less
		 * than it's theoretical value.
		 *
		 * Thus it's unclear whether this line is still really needed.
		 */
		if (compoundedStake < initialStake.div(1e9)) {
			return 0;
		}

		return compoundedStake;
	}

	// --- Sender functions for DCHF deposit, ETH gains and MON gains ---

	// Transfer the DCHF tokens from the user to the Stability Pool's address, and update its recorded DCHF
	function _sendDCHFtoStabilityPool(address _address, uint256 _amount) internal {
		dchfToken.sendToPool(_address, address(this), _amount);
		uint256 newTotalDCHFDeposits = totalDCHFDeposits.add(_amount);
		totalDCHFDeposits = newTotalDCHFDeposits;
		emit StabilityPoolDCHFBalanceUpdated(newTotalDCHFDeposits);
	}

	function _sendAssetGainToDepositor(uint256 _amount, uint256 _amountEther) internal {
		if (_amount == 0) {
			return;
		}

		assetBalance = assetBalance.sub(_amountEther);

		if (assetAddress == ETH_REF_ADDRESS) {
			(bool success, ) = msg.sender.call{ value: _amountEther }("");
			require(success, "StabilityPool: sending ETH failed");
		} else {
			IERC20(assetAddress).safeTransfer(msg.sender, _amount);
		}

		emit StabilityPoolAssetBalanceUpdated(assetBalance);
		emit AssetSent(msg.sender, _amount);
	}

	// Send DCHF to user and decrease DCHF in Pool
	function _sendDCHFToDepositor(address _depositor, uint256 DCHFWithdrawal) internal {
		if (DCHFWithdrawal == 0) {
			return;
		}

		dchfToken.returnFromPool(address(this), _depositor, DCHFWithdrawal);
		_decreaseDCHF(DCHFWithdrawal);
	}

	// --- Stability Pool Deposit Functionality ---

	function _updateDepositAndSnapshots(address _depositor, uint256 _newValue) internal {
		deposits[_depositor] = _newValue;

		if (_newValue == 0) {
			delete depositSnapshots[_depositor];
			emit DepositSnapshotUpdated(_depositor, 0, 0, 0);
			return;
		}
		uint128 currentScaleCached = currentScale;
		uint128 currentEpochCached = currentEpoch;
		uint256 currentP = P;

		// Get S and G for the current epoch and current scale
		uint256 currentS = epochToScaleToSum[currentEpochCached][currentScaleCached];
		uint256 currentG = epochToScaleToG[currentEpochCached][currentScaleCached];

		Snapshots storage depositSnap = depositSnapshots[_depositor];

		// Record new snapshots of the latest running product P, sum S, and sum G, for the depositor
		depositSnap.P = currentP;
		depositSnap.S = currentS;
		depositSnap.G = currentG;
		depositSnap.scale = currentScaleCached;
		depositSnap.epoch = currentEpochCached;

		emit DepositSnapshotUpdated(_depositor, currentP, currentS, currentG);
	}

	function _updateStakeAndSnapshots(uint256 _newValue) internal {
		Snapshots storage snapshots = systemSnapshots;
		totalStakes = _newValue;

		uint128 currentScaleCached = currentScale;
		uint128 currentEpochCached = currentEpoch;
		uint256 currentP = P;

		// Get G for the current epoch and current scale
		uint256 currentG = epochToScaleToG[currentEpochCached][currentScaleCached];

		// Record new snapshots of the latest running product P and sum G for the system
		snapshots.P = currentP;
		snapshots.G = currentG;
		snapshots.scale = currentScaleCached;
		snapshots.epoch = currentEpochCached;

		emit SystemSnapshotUpdated(currentP, currentG);
	}

	function _payOutMONGains(ICommunityIssuance _communityIssuance, address _depositor)
		internal
	{
		// Pay out depositor's MON gain
		uint256 depositorMONGain = getDepositorMONGain(_depositor);
		_communityIssuance.sendMON(_depositor, depositorMONGain);
		emit MONPaidToDepositor(_depositor, depositorMONGain);
	}

	// --- 'require' functions ---

	function _requireCallerIsActivePool() internal view {
		require(
			msg.sender == address(dfrancParams.activePool()),
			"StabilityPool: Caller is not ActivePool"
		);
	}

	function _requireCallerIsTroveManager() internal view {
		require(
			msg.sender == address(troveManager) || msg.sender == address(troveManagerHelpers),
			"SortedTroves: Caller is not the TroveManager"
		);
	}

	function _requireNoUnderCollateralizedTroves() public {
		uint256 price = dfrancParams.priceFeed().fetchPrice(assetAddress);
		address lowestTrove = sortedTroves.getLast(assetAddress);
		uint256 ICR = troveManagerHelpers.getCurrentICR(assetAddress, lowestTrove, price);
		require(
			ICR >= dfrancParams.MCR(assetAddress),
			"StabilityPool: Cannot withdraw while there are troves with ICR < MCR"
		);
	}

	function _requireUserHasDeposit(uint256 _initialDeposit) internal pure {
		require(_initialDeposit > 0, "StabilityPool: User must have a non-zero deposit");
	}

	function _requireNonZeroAmount(uint256 _amount) internal pure {
		require(_amount > 0, "StabilityPool: Amount must be non-zero");
	}

	function _requireUserHasTrove(address _depositor) internal view {
		require(
			troveManagerHelpers.getTroveStatus(assetAddress, _depositor) == 1,
			"StabilityPool: caller must have an active trove to withdraw AssetGain to"
		);
	}

	function _requireUserHasETHGain(address _depositor) internal view {
		uint256 AssetGain = getDepositorAssetGain(_depositor);
		require(AssetGain > 0, "StabilityPool: caller must have non-zero ETH Gain");
	}

	// --- Fallback function ---

	function receivedERC20(address _asset, uint256 _amount) external override {
		_requireCallerIsActivePool();

		require(_asset == assetAddress, "Receiving the wrong asset in StabilityPool");

		if (assetAddress != ETH_REF_ADDRESS) {
			assetBalance = assetBalance.add(_amount);
			emit StabilityPoolAssetBalanceUpdated(assetBalance);
		}
	}

	receive() external payable {
		_requireCallerIsActivePool();
		assetBalance = assetBalance.add(msg.value);
		emit StabilityPoolAssetBalanceUpdated(assetBalance);
	}
}

File 2 of 38 : 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 3 of 38 : 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 4 of 38 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 5 of 38 : IBorrowerOperations.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

// Common interface for the Trove Manager.
interface IBorrowerOperations {
	// --- Events ---

	event TroveManagerAddressChanged(address _newTroveManagerAddress);
	event StabilityPoolAddressChanged(address _stabilityPoolAddress);
	event GasPoolAddressChanged(address _gasPoolAddress);
	event CollSurplusPoolAddressChanged(address _collSurplusPoolAddress);
	event SortedTrovesAddressChanged(address _sortedTrovesAddress);
	event DCHFTokenAddressChanged(address _dchfTokenAddress);
	event MONStakingAddressChanged(address _MONStakingAddress);

	event TroveCreated(address indexed _asset, address indexed _borrower, uint256 arrayIndex);
	event TroveUpdated(
		address indexed _asset,
		address indexed _borrower,
		uint256 _debt,
		uint256 _coll,
		uint256 stake,
		uint8 operation
	);
	event DCHFBorrowingFeePaid(
		address indexed _asset,
		address indexed _borrower,
		uint256 _DCHFFee
	);

	// --- Functions ---

	function setAddresses(
		address _troveManagerAddress,
		address _troveManagerHelpersAddress,
		address _stabilityPoolAddress,
		address _gasPoolAddress,
		address _collSurplusPoolAddress,
		address _sortedTrovesAddress,
		address _dchfTokenAddress,
		address _MONStakingAddress,
		address _dfrancParamsAddress
	) external;

	function openTrove(
		address _asset,
		uint256 _tokenAmount,
		uint256 _maxFee,
		uint256 _DCHFamount,
		address _upperHint,
		address _lowerHint
	) external payable;

	function addColl(
		address _asset,
		uint256 _assetSent,
		address _upperHint,
		address _lowerHint
	) external payable;

	function moveETHGainToTrove(
		address _asset,
		uint256 _amountMoved,
		address _user,
		address _upperHint,
		address _lowerHint
	) external payable;

	function withdrawColl(
		address _asset,
		uint256 _amount,
		address _upperHint,
		address _lowerHint
	) external;

	function withdrawDCHF(
		address _asset,
		uint256 _maxFee,
		uint256 _amount,
		address _upperHint,
		address _lowerHint
	) external;

	function repayDCHF(
		address _asset,
		uint256 _amount,
		address _upperHint,
		address _lowerHint
	) external;

	function closeTrove(address _asset) external;

	function adjustTrove(
		address _asset,
		uint256 _assetSent,
		uint256 _maxFee,
		uint256 _collWithdrawal,
		uint256 _debtChange,
		bool isDebtIncrease,
		address _upperHint,
		address _lowerHint
	) external payable;

	function claimCollateral(address _asset) external;

	function getCompositeDebt(address _asset, uint256 _debt) external view returns (uint256);

	function isContractBorrowerOps() external pure returns (bool);
}

File 6 of 38 : 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 7 of 38 : 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;
}

File 8 of 38 : 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 9 of 38 : 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 10 of 38 : 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 11 of 38 : ICommunityIssuance.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

interface ICommunityIssuance {
	// --- Events ---

	event MONTokenAddressSet(address _MONTokenAddress);
	event StabilityPoolAddressSet(address _stabilityPoolAddress);
	event TotalMONIssuedUpdated(address indexed stabilityPool, uint256 _totalMONIssued);

	// --- Functions ---

	function setAddresses(
		address _MONTokenAddress,
		address _stabilityPoolAddress,
		address _adminContract
	) external;

	function issueMON() external returns (uint256);

	function sendMON(address _account, uint256 _MONamount) external;

	function addFundToStabilityPool(address _pool, uint256 _assignedSupply) external;

	function addFundToStabilityPoolFrom(
		address _pool,
		uint256 _assignedSupply,
		address _spender
	) external;

	function transferFundToAnotherStabilityPool(
		address _target,
		address _receiver,
		uint256 _quantity
	) external;

	function setWeeklyDfrancDistribution(address _stabilityPool, uint256 _weeklyReward) external;
}

File 12 of 38 : 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 13 of 38 : DfrancSafeMath128.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

// uint128 addition and subtraction, with overflow protection.

library DfrancSafeMath128 {
	function add(uint128 a, uint128 b) internal pure returns (uint128) {
		uint128 c = a + b;
		require(c >= a, "DfrancSafeMath128: addition overflow");

		return c;
	}

	function sub(uint128 a, uint128 b) internal pure returns (uint128) {
		require(b <= a, "DfrancSafeMath128: subtraction overflow");
		uint128 c = a - b;

		return c;
	}
}

File 14 of 38 : 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 15 of 38 : SafetyTransfer.sol
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./ERC20Decimals.sol";

library SafetyTransfer {
	using SafeMath for uint256;

	//_amount is in ether (1e18) and we want to convert it to the token decimal
	function decimalsCorrection(address _token, uint256 _amount)
		internal
		view
		returns (uint256)
	{
		if (_token == address(0)) return _amount;
		if (_amount == 0) return 0;

		uint8 decimals = ERC20Decimals(_token).decimals();
		if (decimals < 18) {
			return _amount.div(10**(18 - decimals));
		} else {
			return _amount.mul(10**(decimals - 18));
		}
	}
}

File 16 of 38 : 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 17 of 38 : 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 18 of 38 : 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 19 of 38 : IDeposit.sol
pragma solidity ^0.8.14;

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

File 20 of 38 : 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 21 of 38 : 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 22 of 38 : 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 23 of 38 : 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 24 of 38 : 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 25 of 38 : 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 26 of 38 : 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 27 of 38 : 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 28 of 38 : 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 29 of 38 : 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 30 of 38 : 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 31 of 38 : 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 32 of 38 : 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 33 of 38 : 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 34 of 38 : 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 35 of 38 : 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 36 of 38 : BaseMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

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

File 37 of 38 : 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 38 of 38 : ERC20Decimals.sol
pragma solidity ^0.8.14;

interface ERC20Decimals {
	function decimals() external view returns (uint8);
}

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":"_depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"_Asset","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_DCHFLoss","type":"uint256"}],"name":"AssetGainWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"AssetSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newBorrowerOperationsAddress","type":"address"}],"name":"BorrowerOperationsAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newCommunityIssuanceAddress","type":"address"}],"name":"CommunityIssuanceAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newDCHFTokenAddress","type":"address"}],"name":"DCHFTokenAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newDefaultPoolAddress","type":"address"}],"name":"DefaultPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"_P","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_S","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_G","type":"uint256"}],"name":"DepositSnapshotUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"_currentEpoch","type":"uint128"}],"name":"EpochUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_G","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"_epoch","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"_scale","type":"uint128"}],"name":"G_Updated","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":"_depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"_MON","type":"uint256"}],"name":"MONPaidToDepositor","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":false,"internalType":"uint256","name":"_P","type":"uint256"}],"name":"P_Updated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_S","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"_epoch","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"_scale","type":"uint128"}],"name":"S_Updated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"_currentScale","type":"uint128"}],"name":"ScaleUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newSortedTrovesAddress","type":"address"}],"name":"SortedTrovesAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_newBalance","type":"uint256"}],"name":"StabilityPoolAssetBalanceUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_newBalance","type":"uint256"}],"name":"StabilityPoolDCHFBalanceUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_newSystemStake","type":"uint256"},{"indexed":false,"internalType":"address","name":"_depositor","type":"address"}],"name":"StakeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_P","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_G","type":"uint256"}],"name":"SystemSnapshotUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newTroveManagerAddress","type":"address"}],"name":"TroveManagerAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"_newDeposit","type":"uint256"}],"name":"UserDepositChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAddress","type":"address"}],"name":"VaultParametersBaseChanged","type":"event"},{"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":[],"name":"NAME","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"P","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SCALE_FACTOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STABILITY_POOL_NAME_BYTES","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_requireNoUnderCollateralizedTroves","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"borrowerOperations","outputs":[{"internalType":"contract IBorrowerOperations","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"communityIssuance","outputs":[{"internalType":"contract ICommunityIssuance","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentEpoch","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentScale","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dchfToken","outputs":[{"internalType":"contract IDCHFToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"depositSnapshots","outputs":[{"internalType":"uint256","name":"S","type":"uint256"},{"internalType":"uint256","name":"P","type":"uint256"},{"internalType":"uint256","name":"G","type":"uint256"},{"internalType":"uint128","name":"scale","type":"uint128"},{"internalType":"uint128","name":"epoch","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"deposits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dfrancParams","outputs":[{"internalType":"contract IDfrancParameters","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"","type":"uint128"},{"internalType":"uint128","name":"","type":"uint128"}],"name":"epochToScaleToG","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"","type":"uint128"},{"internalType":"uint128","name":"","type":"uint128"}],"name":"epochToScaleToSum","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAssetBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAssetType","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_depositor","type":"address"}],"name":"getCompoundedDCHFDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCompoundedTotalStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_depositor","type":"address"}],"name":"getDepositorAssetGain","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_depositor","type":"address"}],"name":"getDepositorAssetGain1e18","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_depositor","type":"address"}],"name":"getDepositorMONGain","outputs":[{"internalType":"uint256","name":"","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":[],"name":"getNameBytes","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getTotalDCHFDeposits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastAssetError_Offset","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastDCHFLossError_Offset","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastMONError","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_debtToOffset","type":"uint256"},{"internalType":"uint256","name":"_collToAdd","type":"uint256"}],"name":"offset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"provideToSP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"receivedERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_assetAddress","type":"address"},{"internalType":"address","name":"_borrowerOperationsAddress","type":"address"},{"internalType":"address","name":"_troveManagerAddress","type":"address"},{"internalType":"address","name":"_troveManagerHelpersAddress","type":"address"},{"internalType":"address","name":"_dchfTokenAddress","type":"address"},{"internalType":"address","name":"_sortedTrovesAddress","type":"address"},{"internalType":"address","name":"_communityIssuanceAddress","type":"address"},{"internalType":"address","name":"_dfrancParamsAddress","type":"address"}],"name":"setAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vaultParams","type":"address"}],"name":"setDfrancParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sortedTroves","outputs":[{"internalType":"contract ISortedTroves","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"systemSnapshots","outputs":[{"internalType":"uint256","name":"S","type":"uint256"},{"internalType":"uint256","name":"P","type":"uint256"},{"internalType":"uint256","name":"G","type":"uint256"},{"internalType":"uint128","name":"scale","type":"uint128"},{"internalType":"uint128","name":"epoch","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalStakes","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":"troveManager","outputs":[{"internalType":"contract ITroveManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"troveManagerHelpers","outputs":[{"internalType":"contract ITroveManagerHelpers","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"}],"name":"withdrawAssetGainToTrove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawFromSP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040523480156200001157600080fd5b506200001d3362000028565b600160025562000078565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b613c2080620000886000396000f3fe60806040526004361061028c5760003560e01c8063896317b81161015a578063ae918754116100c1578063d733cfd01161007a578063d733cfd0146108b2578063e90f42ba146108d2578063eb16f004146108f2578063f2fde38b14610912578063f8832ae314610932578063fc7e286d1461096957600080fd5b8063ae9187541461080f578063ba22f7cb1461082f578063bf9befb11461084f578063c2eeb95814610865578063ce4b5bbe14610885578063d46c56461461089d57600080fd5b8063a263757f11610113578063a263757f1461071f578063a3f4df7e1461073f578063a4e59ac814610785578063a8e10e39146107a5578063a9419ca3146107d9578063ab135249146107f957600080fd5b8063896317b8146106715780638b8fbd921461068f5780638da5cb5b146106a557806395fb16bb146106c35780639e86d0c4146106e3578063a20baee61461070357600080fd5b8063392e53cd116101fe57806376671808116101b7578063766718081461051457806377553ad41461055357806378c77a241461057957806382e0a5741461059957806386da0824146105d1578063891268881461065b57600080fd5b8063392e53cd146104605780633d83908a1461048a578063410381c4146104aa5780637087d168146104ca578063715018a6146104ea57806372141e63146104ff57600080fd5b806327d04b351161025057806327d04b351461037e57806328a0a04d1461039e5780632d42b52b146103d65780632e54bf95146103eb578063335525ad1461040d5780633470a4a21461042d57600080fd5b80630fe3e1b7146102d3578063174b557914610306578063183b31591461031c5780631de6428314610331578063230195241461034657600080fd5b366102ce57610299610996565b600a546102a69034610a84565b600a819055604051908152600080516020613bcb8339815191529060200160405180910390a1005b600080fd5b3480156102df57600080fd5b506102f36102ee3660046136bd565b610a99565b6040519081526020015b60405180910390f35b34801561031257600080fd5b506102f360195481565b34801561032857600080fd5b50600a546102f3565b34801561033d57600080fd5b506102f3610b38565b34801561035257600080fd5b50600654610366906001600160a01b031681565b6040516001600160a01b0390911681526020016102fd565b34801561038a57600080fd5b506102f36103993660046136bd565b610ba0565b3480156103aa57600080fd5b506102f36103b93660046136f6565b601560209081526000928352604080842090915290825290205481565b3480156103e257600080fd5b50600b546102f3565b3480156103f757600080fd5b5061040b610406366004613729565b610d7a565b005b34801561041957600080fd5b5061040b610428366004613742565b610f61565b34801561043957600080fd5b507ff704b47f65a99b2219b7213612db4be4a436cdf50624f4baca1373ef0de0aac76102f3565b34801561046c57600080fd5b50601a5461047a9060ff1681565b60405190151581526020016102fd565b34801561049657600080fd5b50600454610366906001600160a01b031681565b3480156104b657600080fd5b506102f36104c53660046136bd565b610fc3565b3480156104d657600080fd5b506102f36104e53660046136bd565b61105a565b3480156104f657600080fd5b5061040b6110f9565b34801561050b57600080fd5b50610366600081565b34801561052057600080fd5b5060145461053b90600160801b90046001600160801b031681565b6040516001600160801b0390911681526020016102fd565b34801561055f57600080fd5b50600354610366906201000090046001600160a01b031681565b34801561058557600080fd5b5061040b610594366004613729565b61112d565b3480156105a557600080fd5b506102f36105b43660046136f6565b601660209081526000928352604080842090915290825290205481565b3480156105dd57600080fd5b506106276105ec3660046136bd565b600d602052600090815260409020805460018201546002830154600390930154919290916001600160801b0380821691600160801b90041685565b604080519586526020860194909452928401919091526001600160801b03908116606084015216608082015260a0016102fd565b34801561066757600080fd5b506102f360175481565b34801561067d57600080fd5b506009546001600160a01b0316610366565b34801561069b57600080fd5b506102f360135481565b3480156106b157600080fd5b506000546001600160a01b0316610366565b3480156106cf57600080fd5b50600854610366906001600160a01b031681565b3480156106ef57600080fd5b506102f36106fe3660046136bd565b6112f7565b34801561070f57600080fd5b506102f3670de0b6b3a764000081565b34801561072b57600080fd5b5061040b61073a3660046136bd565b611488565b34801561074b57600080fd5b506107786040518060400160405280600d81526020016c14dd18589a5b1a5d1e541bdbdb609a1b81525081565b6040516102fd9190613794565b34801561079157600080fd5b5060145461053b906001600160801b031681565b3480156107b157600080fd5b506102f37ff704b47f65a99b2219b7213612db4be4a436cdf50624f4baca1373ef0de0aac781565b3480156107e557600080fd5b50600554610366906001600160a01b031681565b34801561080557600080fd5b506102f360185481565b34801561081b57600080fd5b50600754610366906001600160a01b031681565b34801561083b57600080fd5b506102f361084a3660046136bd565b6114fc565b34801561085b57600080fd5b506102f3600e5481565b34801561087157600080fd5b5061040b6108803660046137c7565b6115a3565b34801561089157600080fd5b506102f3633b9aca0081565b3480156108a957600080fd5b5061040b6117f8565b3480156108be57600080fd5b5061040b6108cd366004613800565b611ac4565b3480156108de57600080fd5b50600154610366906001600160a01b031681565b3480156108fe57600080fd5b5061040b61090d3660046138a9565b611e6a565b34801561091e57600080fd5b5061040b61092d3660046136bd565b611f2c565b34801561093e57600080fd5b50600f54601054601154601254610627939291906001600160801b0380821691600160801b90041685565b34801561097557600080fd5b506102f36109843660046136bd565b600c6020526000908152604090205481565b600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109e9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a0d91906138d5565b6001600160a01b0316336001600160a01b031614610a825760405162461bcd60e51b815260206004820152602760248201527f53746162696c697479506f6f6c3a2043616c6c6572206973206e6f74204163746044820152661a5d99541bdbdb60ca1b60648201526084015b60405180910390fd5b565b6000610a908284613908565b90505b92915050565b6001600160a01b0381166000908152600c6020526040812054808203610ac25750600092915050565b6001600160a01b0383166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003909101546001600160801b038082166060840152600160801b909104166080820152610b308282611fc7565b949350505050565b600e54600090808203610b4d57600091505090565b6040805160a081018252600f5481526010546020820152601154918101919091526012546001600160801b038082166060840152600160801b909104166080820152610b9a9082906120a0565b91505090565b600080600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1a91906138d5565b60405163d1234da760e01b81526001600160a01b038581166004830152919091169063d1234da790602401602060405180830381865afa158015610c62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c869190613920565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0191906138d5565b60405163d1234da760e01b81526001600160a01b038681166004830152919091169063d1234da7906024015b602060405180830381865afa158015610d4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6e9190613920565b9050610b308282610a84565b6002805403610dcb5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610a79565b600280558015610ddd57610ddd6117f8565b336000908152600c6020526040902054610df681612192565b6008546001600160a01b0316610e0b816121fb565b6000610e16336114fc565b90506000610e2333610a99565b90506000610e303361105a565b90506000610e3e878361226c565b90506000610e4c8784612282565b9050610e58863361228e565b6000610e62610b38565b90506000610e708285612282565b9050610e7b81612347565b604080518281523360208201527f02a5b2bd0f6030e3d5dfb2ee2b5bcf058fe8526dabf91b58b2d5d53d0f02dc04910160405180910390a1610ebd33856123de565b6000610ec98686612282565b9050610ed53382612459565b60405181815233907fbce78369dccab09eec1986f4d409ab09ffbb47d65423e5148fcf98411c5111c99060200160405180910390a2604080518981526020810186905233917f3807eb27e116be27b5a2c63478a4f4029945291386db0b94d494102430cab67c910160405180910390a2610f4f88886125b9565b50506001600255505050505050505050565b610f69612703565b600b54801580610f77575082155b15610f8157505050565b600854610f96906001600160a01b03166121fb565b600080610fa4848685612787565b91509150610fb28282612855565b610fbc8486612b2a565b5050505050565b6001600160a01b0381166000908152600c6020526040812054808203610fec5750600092915050565b6001600160a01b0383166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003909101546001600160801b038082166060840152600160801b909104166080820152610b308282612cd8565b6001600160a01b0381166000908152600c60205260408120548082036110835750600092915050565b6001600160a01b0383166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003909101546001600160801b038082166060840152600160801b9091041660808201526110f29082906120a0565b9392505050565b6000546001600160a01b031633146111235760405162461bcd60e51b8152600401610a7990613939565b610a826000612d58565b600280540361117e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610a79565b6002805561118b81612da8565b336000908152600c60205260409020546008546001600160a01b03166111b0816121fb565b60006111bb336114fc565b905060006111c833610a99565b905060006111d53361105a565b905060006111e38683612282565b90506111ef853361228e565b60006111f9610b38565b90506000611207828a610a84565b905061121281612347565b604080518281523360208201527f02a5b2bd0f6030e3d5dfb2ee2b5bcf058fe8526dabf91b58b2d5d53d0f02dc04910160405180910390a1611254338a612e07565b6000611260858b610a84565b905061126c3382612459565b60405181815233907fbce78369dccab09eec1986f4d409ab09ffbb47d65423e5148fcf98411c5111c99060200160405180910390a2604080518881526020810186905233917f3807eb27e116be27b5a2c63478a4f4029945291386db0b94d494102430cab67c910160405180910390a26112e687876125b9565b505060016002555050505050505050565b600080600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561134d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137191906138d5565b604051635373433f60e01b81526001600160a01b0385811660048301529190911690635373433f90602401602060405180830381865afa1580156113b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113dd9190613920565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015611434573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061145891906138d5565b604051635373433f60e01b81526001600160a01b0386811660048301529190911690635373433f90602401610d2d565b6000546001600160a01b031633146114b25760405162461bcd60e51b8152600401610a7990613939565b600180546001600160a01b0319166001600160a01b0383169081179091556040517f98c5e303d085e26fdf8af6a41184b0937ed01142ae7fdfa02dcc87e7079c325390600090a250565b6001600160a01b0381166000908152600c60205260408120548082036115255750600092915050565b6001600160a01b038084166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003909101546001600160801b038082166060840152600160801b9091041660808201526009549091610b30911661159e8484611fc7565b612ebd565b336000908152600c60205260409020546115bc81612192565b6115c533612f9e565b6115ce3361309c565b6008546001600160a01b03166115e3816121fb565b60006115ee33610a99565b905060006115fb3361105a565b905060006116098583612282565b9050611615843361228e565b600061161f610b38565b905061162a81612347565b604080518281523360208201527f02a5b2bd0f6030e3d5dfb2ee2b5bcf058fe8526dabf91b58b2d5d53d0f02dc04910160405180910390a161166c3384612459565b604080518581526020810184905233917f3807eb27e116be27b5a2c63478a4f4029945291386db0b94d494102430cab67c910160405180910390a260405183815233907fbce78369dccab09eec1986f4d409ab09ffbb47d65423e5148fcf98411c5111c99060200160405180910390a2600a546116e99085612282565b600a819055604051908152600080516020613bcb8339815191529060200160405180910390a160408051338152602081018690527fc4dfa259771b0ed50b100eaf04734dad1b094a866d9d285c59180cde3f3f45e8910160405180910390a16003546009546001600160a01b036201000090920482169163501414f5911615611773576000611775565b855b60095460405160e084901b6001600160e01b03191681526001600160a01b039182166004820152602481018990523360448201528c82166064820152908b16608482015260a4016000604051808303818588803b1580156117d557600080fd5b505af11580156117e9573d6000803e3d6000fd5b50505050505050505050505050565b60015460408051633a0df78d60e11b815290516000926001600160a01b03169163741bef1a9160048083019260209291908290030181865afa158015611842573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061186691906138d5565b600954604051635670bcc760e11b81526001600160a01b03918216600482015291169063ace1798e906024016020604051808303816000875af11580156118b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d59190613920565b600754600954604051637608271560e01b81526001600160a01b039182166004820152929350600092911690637608271590602401602060405180830381865afa158015611927573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061194b91906138d5565b60055460095460405163b1eafaab60e01b81529293506000926001600160a01b039283169263b1eafaab92611989929116908690889060040161396e565b602060405180830381865afa1580156119a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ca9190613920565b6001546009546040516305f8cff960e01b81526001600160a01b03918216600482015292935016906305f8cff990602401602060405180830381865afa158015611a18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a3c9190613920565b811015611abf5760405162461bcd60e51b8152602060048201526044602482018190527f53746162696c697479506f6f6c3a2043616e6e6f742077697468647261772077908201527f68696c65207468657265206172652074726f766573207769746820494352203c6064820152631026a1a960e11b608482015260a401610a79565b505050565b600354610100900460ff1615808015611ae45750600354600160ff909116105b80611afe5750303b158015611afe575060035460ff166001145b611b615760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610a79565b6003805460ff191660011790558015611b84576003805461ff0019166101001790555b6000546001600160a01b03163314611bae5760405162461bcd60e51b8152600401610a7990613939565b601a5460ff1615611bf75760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610a79565b611c0088613113565b611c0987613113565b611c1286613113565b611c1b85613113565b611c2484613113565b611c2d83613113565b611c3682613113565b601a805460ff191660011790556001600160a01b03891615611c5b57611c5b89613113565b600980546001600160a01b03199081166001600160a01b038c8116919091179092556003805462010000600160b01b031916620100008c8516021790556004805482168a841617905560058054821689841617905560068054821688841617905560078054821687841617905560088054909116918516919091179055611ce182611488565b670de0b6b3a76400006013556040516001600160a01b03891681527f3ca631ffcd2a9b5d9ae18543fc82f58eb4ca33af9e6ab01b7a8e95331e6ed9859060200160405180910390a16040516001600160a01b03881681527f143219c9e69b09e07e095fcc889b43d8f46ca892bba65f08dc3a0050869a56789060200160405180910390a16040516001600160a01b03861681527ff165f2d7729f02833c6f7dea7d6f0f9c4a505f5557516f4daca827f9637c67909060200160405180910390a16040516001600160a01b03851681527f65f4cf077bc01e4742eb5ad98326f6e95b63548ea24b17f8d5e823111fe788009060200160405180910390a16040516001600160a01b03841681527f3055265812fb8447b9ada4a5d804ec43bd528ec40e89c952bbc7b85dc5ac68119060200160405180910390a18015611e5f576003805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050505050565b611e72610996565b6009546001600160a01b03838116911614611ee25760405162461bcd60e51b815260206004820152602a60248201527f526563656976696e67207468652077726f6e6720617373657420696e20537461604482015269189a5b1a5d1e541bdbdb60b21b6064820152608401610a79565b6009546001600160a01b031615611f2857600a54611f009082610a84565b600a819055604051908152600080516020613bcb833981519152906020015b60405180910390a15b5050565b6000546001600160a01b03163314611f565760405162461bcd60e51b8152600401610a7990613939565b6001600160a01b038116611fbb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610a79565b611fc481612d58565b50565b6080810151606082015182516020808501516001600160801b0380861660009081526015845260408082209287168252919093528220549194939291859061200f9084612282565b6001600160801b0380871660009081526015602052604081209293509161206691633b9aca0091908490612046908a1660016131b8565b6001600160801b0316815260208101919091526040016000205490613235565b90506000612092670de0b6b3a764000061208c86816120858888610a84565b8f90613241565b90613235565b9a9950505050505050505050565b6020810151606082015160808301516014546000939291906001600160801b03600160801b909104811690821610156120df5760009350505050610a93565b60145460009081906120fa906001600160801b03168561324d565b9050806001600160801b031660000361212d576121268561208c6013548b61324190919063ffffffff16565b9150612164565b806001600160801b031660010361215f57612126633b9aca0061208c8761208c6013548d61324190919063ffffffff16565b600091505b61217288633b9aca00613235565b82101561218757600095505050505050610a93565b509695505050505050565b60008111611fc45760405162461bcd60e51b815260206004820152603060248201527f53746162696c697479506f6f6c3a2055736572206d757374206861766520612060448201526f1b9bdb8b5e995c9bc819195c1bdcda5d60821b6064820152608401610a79565b6000816001600160a01b03166349f3fcf56040518163ffffffff1660e01b81526004016020604051808303816000875af115801561223d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122619190613920565b9050611f28816132cd565b600081831061227b5781610a90565b5090919050565b6000610a908284613992565b600061229982610fc3565b604051636a83421560e01b81526001600160a01b0384811660048301526024820183905291925090841690636a83421590604401600060405180830381600087803b1580156122e757600080fd5b505af11580156122fb573d6000803e3d6000fd5b50505050816001600160a01b03167ff188df7686d1604b5a12cf902ea07797ccd4b180c02d07e2f1cefc287b1f6a448260405161233a91815260200190565b60405180910390a2505050565b600e8190556014546013546001600160801b03600160801b808404821660008181526016602090815260408083209590971680835294815290869020546010869055601181905592820284176012558551858152908101839052600f95939491939192917fb9388978b54026c51c20e3972ba5ed79bca3fc98beb4d005b4ae633b14db9718910160405180910390a1505050505050565b806000036123ea575050565b600654604051631062c15f60e11b81526001600160a01b03909116906320c582be9061241e9030908690869060040161396e565b600060405180830381600087803b15801561243857600080fd5b505af115801561244c573d6000803e3d6000fd5b50505050611f28816133de565b6001600160a01b0382166000908152600c602052604081208290558190036124ef576001600160a01b0382166000818152600d60209081526040808320838155600181018490556002810184905560030183905580518381529182018390528101919091527f2d6cc0bcdf72c9486f6451bde6b80f44066f4558f77f44dbfedbe7d8b295225a9060600160405180910390a25050565b6014546013546001600160801b03600160801b808404821660008181526015602090815260408083209590971680835294815286822054838352601682528783208684528252878320546001600160a01b038b16808552600d845293899020600181018990558281556002810182905595850287176003870155885188815292830182905297820188905294969295949391907f2d6cc0bcdf72c9486f6451bde6b80f44066f4558f77f44dbfedbe7d8b295225a9060600160405180910390a25050505050505050565b816000036125c5575050565b600a546125d29082612282565b600a556009546001600160a01b031661268d57604051600090339083908381818185875af1925050503d8060008114612627576040519150601f19603f3d011682016040523d82523d6000602084013e61262c565b606091505b50509050806126875760405162461bcd60e51b815260206004820152602160248201527f53746162696c697479506f6f6c3a2073656e64696e6720455448206661696c656044820152601960fa1b6064820152608401610a79565b506126a4565b6009546126a4906001600160a01b03163384613426565b600080516020613bcb833981519152600a546040516126c591815260200190565b60405180910390a160408051338152602081018490527fc4dfa259771b0ed50b100eaf04734dad1b094a866d9d285c59180cde3f3f45e89101611f1f565b6004546001600160a01b031633148061272657506005546001600160a01b031633145b610a825760405162461bcd60e51b815260206004820152602c60248201527f536f7274656454726f7665733a2043616c6c6572206973206e6f74207468652060448201526b2a3937bb32a6b0b730b3b2b960a11b6064820152608401610a79565b60008060006127b36018546127ad670de0b6b3a76400008961324190919063ffffffff16565b90610a84565b9050838511156127c5576127c56139a9565b8385036127e1576000601955670de0b6b3a76400009150612829565b601954600090612803906127fd88670de0b6b3a7640000613241565b90612282565b905061281460016127ad8388613235565b9250612824816127fd8588613241565b601955505b6128338185613235565b92506128496128428486613241565b8290612282565b60185550935093915050565b6013546000670de0b6b3a7640000831115612872576128726139a9565b6000612886670de0b6b3a764000085612282565b6014546001600160801b03600160801b8204811660008181526015602090815260408083209490951680835293905292832054939450909290916128ca8988613241565b905060006128d88383610a84565b6001600160801b038581166000818152601560209081526040808320948b16808452948252918290208590558151858152908101929092528101919091529091507fe12e2cd2c9afa8069203ca07e7eff1edce4a075686d0736a8e7e0d593597b2079060600160405180910390a185600003612a0b576129626001600160801b03851660016131b8565b601480546001600160801b03908116600160801b93821684021791829055604051929091041681527fb50f0f59e7cb5b421dc77581c3a9919e3806e076e5fa78a874c3f120cb7d874d9060200160405180910390a1601480546001600160801b0319169055604051600081527f1f9dfc70cd666adb18a39d60a797518f7b4febf4b6e24ef37d44f6e1e7219fbe9060200160405180910390a1670de0b6b3a76400009650612ad6565b633b9aca00612a26670de0b6b3a764000061208c8b8a613241565b1015612abd57612a50670de0b6b3a764000061208c633b9aca00612a4a8c8b613241565b90613241565b9650612a666001600160801b03861660016131b8565b601480546001600160801b0319166001600160801b039290921691821790556040519081527f1f9dfc70cd666adb18a39d60a797518f7b4febf4b6e24ef37d44f6e1e7219fbe9060200160405180910390a1612ad6565b612ad3670de0b6b3a764000061208c8a89613241565b96505b60008711612ae657612ae66139a9565b60138790556040518781527fc1a9618cb59ebca77cbdbc2949f126823c407ff13edb285fd0262519a9c18e8c9060200160405180910390a150505050505050505050565b60015460408051633fbeef2560e11b815290516000926001600160a01b031691637f7dde4a9160048083019260209291908290030181865afa158015612b74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b9891906138d5565b60095460405163fb24e5f760e01b81526001600160a01b0391821660048201526024810185905291925082169063fb24e5f790604401600060405180830381600087803b158015612be857600080fd5b505af1158015612bfc573d6000803e3d6000fd5b50505050612c09826133de565b600654604051632770a7eb60e21b8152306004820152602481018490526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b158015612c5557600080fd5b505af1158015612c69573d6000803e3d6000fd5b50506009546040516347878f1560e01b81526001600160a01b0380861694506347878f159350612ca19216903090889060040161396e565b600060405180830381600087803b158015612cbb57600080fd5b505af1158015612ccf573d6000803e3d6000fd5b50505050505050565b608081015160608201516040808401516020808601516001600160801b03808716600090815260168452858120918716815292529281205490949392908590612d219084612282565b6001600160801b0380871660009081526016602052604081209293509161206691633b9aca0091908490612046908a1660016131b8565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60008111611fc45760405162461bcd60e51b815260206004820152602660248201527f53746162696c697479506f6f6c3a20416d6f756e74206d757374206265206e6f6044820152656e2d7a65726f60d01b6064820152608401610a79565b600654604051632ee65eeb60e21b81526001600160a01b039091169063bb997bac90612e3b9085903090869060040161396e565b600060405180830381600087803b158015612e5557600080fd5b505af1158015612e69573d6000803e3d6000fd5b5050600b5460009250612e7d915083610a84565b600b8190556040518181529091507fe44ae3e449fe8ef1db6bee9206641d83bce427602b867fee92db3fb817e2c17b9060200160405180910390a1505050565b60006001600160a01b038316612ed4575080610a93565b81600003612ee457506000610a93565b6000836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f24573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f4891906139bf565b905060128160ff161015612f7e57612f76612f648260126139e2565b612f6f90600a613ae9565b8490613235565b915050610a93565b612f76612f8c6012836139e2565b612f9790600a613ae9565b8490613241565b60055460095460405163614d120960e01b81526001600160a01b039182166004820152838216602482015291169063614d120990604401602060405180830381865afa158015612ff2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130169190613920565b600114611fc45760405162461bcd60e51b815260206004820152604860248201527f53746162696c697479506f6f6c3a2063616c6c6572206d75737420686176652060448201527f616e206163746976652074726f766520746f2077697468647261772041737365606482015267744761696e20746f60c01b608482015260a401610a79565b60006130a7826114fc565b905060008111611f285760405162461bcd60e51b815260206004820152603160248201527f53746162696c697479506f6f6c3a2063616c6c6572206d7573742068617665206044820152703737b716bd32b9379022aa241023b0b4b760791b6064820152608401610a79565b6001600160a01b0381166131695760405162461bcd60e51b815260206004820152601e60248201527f4163636f756e742063616e6e6f74206265207a65726f206164647265737300006044820152606401610a79565b803b80611f285760405162461bcd60e51b815260206004820181905260248201527f4163636f756e7420636f64652073697a652063616e6e6f74206265207a65726f6044820152606401610a79565b6000806131c58385613af8565b9050836001600160801b0316816001600160801b03161015610a905760405162461bcd60e51b8152602060048201526024808201527f446672616e63536166654d6174683132383a206164646974696f6e206f766572604482015263666c6f7760e01b6064820152608401610a79565b6000610a908284613b23565b6000610a908284613b45565b6000826001600160801b0316826001600160801b031611156132c15760405162461bcd60e51b815260206004820152602760248201527f446672616e63536166654d6174683132383a207375627472616374696f6e206f604482015266766572666c6f7760c81b6064820152608401610a79565b6000610b308385613b64565b600b548015806132db575081155b156132e4575050565b60006132f08383613478565b905060006133096013548361324190919063ffffffff16565b6014546001600160801b03600160801b8204811660009081526016602090815260408083209390941682529190915220549091506133479082610a84565b60148054600160801b8082046001600160801b0390811660009081526016602081815260408084209685168452958152858320979097559454928304821680825294865283812092909116808252918552829020548251908152938401929092528201527f2d6127771b164a9cc8827d24b5955db2a77e7a81dac389107ebb8bce9fb649689060600160405180910390a150505050565b600b546000906133ee9083612282565b600b8190556040518181529091507fe44ae3e449fe8ef1db6bee9206641d83bce427602b867fee92db3fb817e2c17b90602001611f1f565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052611abf9084906134cb565b60008061349c6017546127ad670de0b6b3a76400008761324190919063ffffffff16565b905060006134aa8285613235565b90506134c06134b98286613241565b8390612282565b601755949350505050565b6000613520826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661359d9092919063ffffffff16565b805190915015611abf578080602001905181019061353e9190613b8c565b611abf5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a79565b6060610b30848460008585843b6135f65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a79565b600080866001600160a01b031685876040516136129190613bae565b60006040518083038185875af1925050503d806000811461364f576040519150601f19603f3d011682016040523d82523d6000602084013e613654565b606091505b509150915061366482828661366f565b979650505050505050565b6060831561367e5750816110f2565b82511561368e5782518084602001fd5b8160405162461bcd60e51b8152600401610a799190613794565b6001600160a01b0381168114611fc457600080fd5b6000602082840312156136cf57600080fd5b8135610a90816136a8565b80356001600160801b03811681146136f157600080fd5b919050565b6000806040838503121561370957600080fd5b613712836136da565b9150613720602084016136da565b90509250929050565b60006020828403121561373b57600080fd5b5035919050565b6000806040838503121561375557600080fd5b50508035926020909101359150565b60005b8381101561377f578181015183820152602001613767565b8381111561378e576000848401525b50505050565b60208152600082518060208401526137b3816040850160208701613764565b601f01601f19169190910160400192915050565b600080604083850312156137da57600080fd5b82356137e5816136a8565b915060208301356137f5816136a8565b809150509250929050565b600080600080600080600080610100898b03121561381d57600080fd5b8835613828816136a8565b97506020890135613838816136a8565b96506040890135613848816136a8565b95506060890135613858816136a8565b94506080890135613868816136a8565b935060a0890135613878816136a8565b925060c0890135613888816136a8565b915060e0890135613898816136a8565b809150509295985092959890939650565b600080604083850312156138bc57600080fd5b82356138c7816136a8565b946020939093013593505050565b6000602082840312156138e757600080fd5b8151610a90816136a8565b634e487b7160e01b600052601160045260246000fd5b6000821982111561391b5761391b6138f2565b500190565b60006020828403121561393257600080fd5b5051919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6000828210156139a4576139a46138f2565b500390565b634e487b7160e01b600052600160045260246000fd5b6000602082840312156139d157600080fd5b815160ff81168114610a9057600080fd5b600060ff821660ff8416808210156139fc576139fc6138f2565b90039392505050565b600181815b80851115613a40578160001904821115613a2657613a266138f2565b80851615613a3357918102915b93841c9390800290613a0a565b509250929050565b600082613a5757506001610a93565b81613a6457506000610a93565b8160018114613a7a5760028114613a8457613aa0565b6001915050610a93565b60ff841115613a9557613a956138f2565b50506001821b610a93565b5060208310610133831016604e8410600b8410161715613ac3575081810a610a93565b613acd8383613a05565b8060001904821115613ae157613ae16138f2565b029392505050565b6000610a9060ff841683613a48565b60006001600160801b03808316818516808303821115613b1a57613b1a6138f2565b01949350505050565b600082613b4057634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615613b5f57613b5f6138f2565b500290565b60006001600160801b0383811690831681811015613b8457613b846138f2565b039392505050565b600060208284031215613b9e57600080fd5b81518015158114610a9057600080fd5b60008251613bc0818460208701613764565b919091019291505056feda08342aeb056fbb00fd5a62a4033b8f6496e358fd964a431042595d762afbafa2646970667358221220d93b4e450b3d7a7dc910d0b0287ae36b370c65b208fb24240344e5e74fc018bf64736f6c634300080e0033

Deployed Bytecode

0x60806040526004361061028c5760003560e01c8063896317b81161015a578063ae918754116100c1578063d733cfd01161007a578063d733cfd0146108b2578063e90f42ba146108d2578063eb16f004146108f2578063f2fde38b14610912578063f8832ae314610932578063fc7e286d1461096957600080fd5b8063ae9187541461080f578063ba22f7cb1461082f578063bf9befb11461084f578063c2eeb95814610865578063ce4b5bbe14610885578063d46c56461461089d57600080fd5b8063a263757f11610113578063a263757f1461071f578063a3f4df7e1461073f578063a4e59ac814610785578063a8e10e39146107a5578063a9419ca3146107d9578063ab135249146107f957600080fd5b8063896317b8146106715780638b8fbd921461068f5780638da5cb5b146106a557806395fb16bb146106c35780639e86d0c4146106e3578063a20baee61461070357600080fd5b8063392e53cd116101fe57806376671808116101b7578063766718081461051457806377553ad41461055357806378c77a241461057957806382e0a5741461059957806386da0824146105d1578063891268881461065b57600080fd5b8063392e53cd146104605780633d83908a1461048a578063410381c4146104aa5780637087d168146104ca578063715018a6146104ea57806372141e63146104ff57600080fd5b806327d04b351161025057806327d04b351461037e57806328a0a04d1461039e5780632d42b52b146103d65780632e54bf95146103eb578063335525ad1461040d5780633470a4a21461042d57600080fd5b80630fe3e1b7146102d3578063174b557914610306578063183b31591461031c5780631de6428314610331578063230195241461034657600080fd5b366102ce57610299610996565b600a546102a69034610a84565b600a819055604051908152600080516020613bcb8339815191529060200160405180910390a1005b600080fd5b3480156102df57600080fd5b506102f36102ee3660046136bd565b610a99565b6040519081526020015b60405180910390f35b34801561031257600080fd5b506102f360195481565b34801561032857600080fd5b50600a546102f3565b34801561033d57600080fd5b506102f3610b38565b34801561035257600080fd5b50600654610366906001600160a01b031681565b6040516001600160a01b0390911681526020016102fd565b34801561038a57600080fd5b506102f36103993660046136bd565b610ba0565b3480156103aa57600080fd5b506102f36103b93660046136f6565b601560209081526000928352604080842090915290825290205481565b3480156103e257600080fd5b50600b546102f3565b3480156103f757600080fd5b5061040b610406366004613729565b610d7a565b005b34801561041957600080fd5b5061040b610428366004613742565b610f61565b34801561043957600080fd5b507ff704b47f65a99b2219b7213612db4be4a436cdf50624f4baca1373ef0de0aac76102f3565b34801561046c57600080fd5b50601a5461047a9060ff1681565b60405190151581526020016102fd565b34801561049657600080fd5b50600454610366906001600160a01b031681565b3480156104b657600080fd5b506102f36104c53660046136bd565b610fc3565b3480156104d657600080fd5b506102f36104e53660046136bd565b61105a565b3480156104f657600080fd5b5061040b6110f9565b34801561050b57600080fd5b50610366600081565b34801561052057600080fd5b5060145461053b90600160801b90046001600160801b031681565b6040516001600160801b0390911681526020016102fd565b34801561055f57600080fd5b50600354610366906201000090046001600160a01b031681565b34801561058557600080fd5b5061040b610594366004613729565b61112d565b3480156105a557600080fd5b506102f36105b43660046136f6565b601660209081526000928352604080842090915290825290205481565b3480156105dd57600080fd5b506106276105ec3660046136bd565b600d602052600090815260409020805460018201546002830154600390930154919290916001600160801b0380821691600160801b90041685565b604080519586526020860194909452928401919091526001600160801b03908116606084015216608082015260a0016102fd565b34801561066757600080fd5b506102f360175481565b34801561067d57600080fd5b506009546001600160a01b0316610366565b34801561069b57600080fd5b506102f360135481565b3480156106b157600080fd5b506000546001600160a01b0316610366565b3480156106cf57600080fd5b50600854610366906001600160a01b031681565b3480156106ef57600080fd5b506102f36106fe3660046136bd565b6112f7565b34801561070f57600080fd5b506102f3670de0b6b3a764000081565b34801561072b57600080fd5b5061040b61073a3660046136bd565b611488565b34801561074b57600080fd5b506107786040518060400160405280600d81526020016c14dd18589a5b1a5d1e541bdbdb609a1b81525081565b6040516102fd9190613794565b34801561079157600080fd5b5060145461053b906001600160801b031681565b3480156107b157600080fd5b506102f37ff704b47f65a99b2219b7213612db4be4a436cdf50624f4baca1373ef0de0aac781565b3480156107e557600080fd5b50600554610366906001600160a01b031681565b34801561080557600080fd5b506102f360185481565b34801561081b57600080fd5b50600754610366906001600160a01b031681565b34801561083b57600080fd5b506102f361084a3660046136bd565b6114fc565b34801561085b57600080fd5b506102f3600e5481565b34801561087157600080fd5b5061040b6108803660046137c7565b6115a3565b34801561089157600080fd5b506102f3633b9aca0081565b3480156108a957600080fd5b5061040b6117f8565b3480156108be57600080fd5b5061040b6108cd366004613800565b611ac4565b3480156108de57600080fd5b50600154610366906001600160a01b031681565b3480156108fe57600080fd5b5061040b61090d3660046138a9565b611e6a565b34801561091e57600080fd5b5061040b61092d3660046136bd565b611f2c565b34801561093e57600080fd5b50600f54601054601154601254610627939291906001600160801b0380821691600160801b90041685565b34801561097557600080fd5b506102f36109843660046136bd565b600c6020526000908152604090205481565b600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109e9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a0d91906138d5565b6001600160a01b0316336001600160a01b031614610a825760405162461bcd60e51b815260206004820152602760248201527f53746162696c697479506f6f6c3a2043616c6c6572206973206e6f74204163746044820152661a5d99541bdbdb60ca1b60648201526084015b60405180910390fd5b565b6000610a908284613908565b90505b92915050565b6001600160a01b0381166000908152600c6020526040812054808203610ac25750600092915050565b6001600160a01b0383166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003909101546001600160801b038082166060840152600160801b909104166080820152610b308282611fc7565b949350505050565b600e54600090808203610b4d57600091505090565b6040805160a081018252600f5481526010546020820152601154918101919091526012546001600160801b038082166060840152600160801b909104166080820152610b9a9082906120a0565b91505090565b600080600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1a91906138d5565b60405163d1234da760e01b81526001600160a01b038581166004830152919091169063d1234da790602401602060405180830381865afa158015610c62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c869190613920565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0191906138d5565b60405163d1234da760e01b81526001600160a01b038681166004830152919091169063d1234da7906024015b602060405180830381865afa158015610d4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6e9190613920565b9050610b308282610a84565b6002805403610dcb5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610a79565b600280558015610ddd57610ddd6117f8565b336000908152600c6020526040902054610df681612192565b6008546001600160a01b0316610e0b816121fb565b6000610e16336114fc565b90506000610e2333610a99565b90506000610e303361105a565b90506000610e3e878361226c565b90506000610e4c8784612282565b9050610e58863361228e565b6000610e62610b38565b90506000610e708285612282565b9050610e7b81612347565b604080518281523360208201527f02a5b2bd0f6030e3d5dfb2ee2b5bcf058fe8526dabf91b58b2d5d53d0f02dc04910160405180910390a1610ebd33856123de565b6000610ec98686612282565b9050610ed53382612459565b60405181815233907fbce78369dccab09eec1986f4d409ab09ffbb47d65423e5148fcf98411c5111c99060200160405180910390a2604080518981526020810186905233917f3807eb27e116be27b5a2c63478a4f4029945291386db0b94d494102430cab67c910160405180910390a2610f4f88886125b9565b50506001600255505050505050505050565b610f69612703565b600b54801580610f77575082155b15610f8157505050565b600854610f96906001600160a01b03166121fb565b600080610fa4848685612787565b91509150610fb28282612855565b610fbc8486612b2a565b5050505050565b6001600160a01b0381166000908152600c6020526040812054808203610fec5750600092915050565b6001600160a01b0383166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003909101546001600160801b038082166060840152600160801b909104166080820152610b308282612cd8565b6001600160a01b0381166000908152600c60205260408120548082036110835750600092915050565b6001600160a01b0383166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003909101546001600160801b038082166060840152600160801b9091041660808201526110f29082906120a0565b9392505050565b6000546001600160a01b031633146111235760405162461bcd60e51b8152600401610a7990613939565b610a826000612d58565b600280540361117e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610a79565b6002805561118b81612da8565b336000908152600c60205260409020546008546001600160a01b03166111b0816121fb565b60006111bb336114fc565b905060006111c833610a99565b905060006111d53361105a565b905060006111e38683612282565b90506111ef853361228e565b60006111f9610b38565b90506000611207828a610a84565b905061121281612347565b604080518281523360208201527f02a5b2bd0f6030e3d5dfb2ee2b5bcf058fe8526dabf91b58b2d5d53d0f02dc04910160405180910390a1611254338a612e07565b6000611260858b610a84565b905061126c3382612459565b60405181815233907fbce78369dccab09eec1986f4d409ab09ffbb47d65423e5148fcf98411c5111c99060200160405180910390a2604080518881526020810186905233917f3807eb27e116be27b5a2c63478a4f4029945291386db0b94d494102430cab67c910160405180910390a26112e687876125b9565b505060016002555050505050505050565b600080600160009054906101000a90046001600160a01b03166001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561134d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137191906138d5565b604051635373433f60e01b81526001600160a01b0385811660048301529190911690635373433f90602401602060405180830381865afa1580156113b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113dd9190613920565b90506000600160009054906101000a90046001600160a01b03166001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015611434573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061145891906138d5565b604051635373433f60e01b81526001600160a01b0386811660048301529190911690635373433f90602401610d2d565b6000546001600160a01b031633146114b25760405162461bcd60e51b8152600401610a7990613939565b600180546001600160a01b0319166001600160a01b0383169081179091556040517f98c5e303d085e26fdf8af6a41184b0937ed01142ae7fdfa02dcc87e7079c325390600090a250565b6001600160a01b0381166000908152600c60205260408120548082036115255750600092915050565b6001600160a01b038084166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003909101546001600160801b038082166060840152600160801b9091041660808201526009549091610b30911661159e8484611fc7565b612ebd565b336000908152600c60205260409020546115bc81612192565b6115c533612f9e565b6115ce3361309c565b6008546001600160a01b03166115e3816121fb565b60006115ee33610a99565b905060006115fb3361105a565b905060006116098583612282565b9050611615843361228e565b600061161f610b38565b905061162a81612347565b604080518281523360208201527f02a5b2bd0f6030e3d5dfb2ee2b5bcf058fe8526dabf91b58b2d5d53d0f02dc04910160405180910390a161166c3384612459565b604080518581526020810184905233917f3807eb27e116be27b5a2c63478a4f4029945291386db0b94d494102430cab67c910160405180910390a260405183815233907fbce78369dccab09eec1986f4d409ab09ffbb47d65423e5148fcf98411c5111c99060200160405180910390a2600a546116e99085612282565b600a819055604051908152600080516020613bcb8339815191529060200160405180910390a160408051338152602081018690527fc4dfa259771b0ed50b100eaf04734dad1b094a866d9d285c59180cde3f3f45e8910160405180910390a16003546009546001600160a01b036201000090920482169163501414f5911615611773576000611775565b855b60095460405160e084901b6001600160e01b03191681526001600160a01b039182166004820152602481018990523360448201528c82166064820152908b16608482015260a4016000604051808303818588803b1580156117d557600080fd5b505af11580156117e9573d6000803e3d6000fd5b50505050505050505050505050565b60015460408051633a0df78d60e11b815290516000926001600160a01b03169163741bef1a9160048083019260209291908290030181865afa158015611842573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061186691906138d5565b600954604051635670bcc760e11b81526001600160a01b03918216600482015291169063ace1798e906024016020604051808303816000875af11580156118b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d59190613920565b600754600954604051637608271560e01b81526001600160a01b039182166004820152929350600092911690637608271590602401602060405180830381865afa158015611927573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061194b91906138d5565b60055460095460405163b1eafaab60e01b81529293506000926001600160a01b039283169263b1eafaab92611989929116908690889060040161396e565b602060405180830381865afa1580156119a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ca9190613920565b6001546009546040516305f8cff960e01b81526001600160a01b03918216600482015292935016906305f8cff990602401602060405180830381865afa158015611a18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a3c9190613920565b811015611abf5760405162461bcd60e51b8152602060048201526044602482018190527f53746162696c697479506f6f6c3a2043616e6e6f742077697468647261772077908201527f68696c65207468657265206172652074726f766573207769746820494352203c6064820152631026a1a960e11b608482015260a401610a79565b505050565b600354610100900460ff1615808015611ae45750600354600160ff909116105b80611afe5750303b158015611afe575060035460ff166001145b611b615760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610a79565b6003805460ff191660011790558015611b84576003805461ff0019166101001790555b6000546001600160a01b03163314611bae5760405162461bcd60e51b8152600401610a7990613939565b601a5460ff1615611bf75760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610a79565b611c0088613113565b611c0987613113565b611c1286613113565b611c1b85613113565b611c2484613113565b611c2d83613113565b611c3682613113565b601a805460ff191660011790556001600160a01b03891615611c5b57611c5b89613113565b600980546001600160a01b03199081166001600160a01b038c8116919091179092556003805462010000600160b01b031916620100008c8516021790556004805482168a841617905560058054821689841617905560068054821688841617905560078054821687841617905560088054909116918516919091179055611ce182611488565b670de0b6b3a76400006013556040516001600160a01b03891681527f3ca631ffcd2a9b5d9ae18543fc82f58eb4ca33af9e6ab01b7a8e95331e6ed9859060200160405180910390a16040516001600160a01b03881681527f143219c9e69b09e07e095fcc889b43d8f46ca892bba65f08dc3a0050869a56789060200160405180910390a16040516001600160a01b03861681527ff165f2d7729f02833c6f7dea7d6f0f9c4a505f5557516f4daca827f9637c67909060200160405180910390a16040516001600160a01b03851681527f65f4cf077bc01e4742eb5ad98326f6e95b63548ea24b17f8d5e823111fe788009060200160405180910390a16040516001600160a01b03841681527f3055265812fb8447b9ada4a5d804ec43bd528ec40e89c952bbc7b85dc5ac68119060200160405180910390a18015611e5f576003805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050505050565b611e72610996565b6009546001600160a01b03838116911614611ee25760405162461bcd60e51b815260206004820152602a60248201527f526563656976696e67207468652077726f6e6720617373657420696e20537461604482015269189a5b1a5d1e541bdbdb60b21b6064820152608401610a79565b6009546001600160a01b031615611f2857600a54611f009082610a84565b600a819055604051908152600080516020613bcb833981519152906020015b60405180910390a15b5050565b6000546001600160a01b03163314611f565760405162461bcd60e51b8152600401610a7990613939565b6001600160a01b038116611fbb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610a79565b611fc481612d58565b50565b6080810151606082015182516020808501516001600160801b0380861660009081526015845260408082209287168252919093528220549194939291859061200f9084612282565b6001600160801b0380871660009081526015602052604081209293509161206691633b9aca0091908490612046908a1660016131b8565b6001600160801b0316815260208101919091526040016000205490613235565b90506000612092670de0b6b3a764000061208c86816120858888610a84565b8f90613241565b90613235565b9a9950505050505050505050565b6020810151606082015160808301516014546000939291906001600160801b03600160801b909104811690821610156120df5760009350505050610a93565b60145460009081906120fa906001600160801b03168561324d565b9050806001600160801b031660000361212d576121268561208c6013548b61324190919063ffffffff16565b9150612164565b806001600160801b031660010361215f57612126633b9aca0061208c8761208c6013548d61324190919063ffffffff16565b600091505b61217288633b9aca00613235565b82101561218757600095505050505050610a93565b509695505050505050565b60008111611fc45760405162461bcd60e51b815260206004820152603060248201527f53746162696c697479506f6f6c3a2055736572206d757374206861766520612060448201526f1b9bdb8b5e995c9bc819195c1bdcda5d60821b6064820152608401610a79565b6000816001600160a01b03166349f3fcf56040518163ffffffff1660e01b81526004016020604051808303816000875af115801561223d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122619190613920565b9050611f28816132cd565b600081831061227b5781610a90565b5090919050565b6000610a908284613992565b600061229982610fc3565b604051636a83421560e01b81526001600160a01b0384811660048301526024820183905291925090841690636a83421590604401600060405180830381600087803b1580156122e757600080fd5b505af11580156122fb573d6000803e3d6000fd5b50505050816001600160a01b03167ff188df7686d1604b5a12cf902ea07797ccd4b180c02d07e2f1cefc287b1f6a448260405161233a91815260200190565b60405180910390a2505050565b600e8190556014546013546001600160801b03600160801b808404821660008181526016602090815260408083209590971680835294815290869020546010869055601181905592820284176012558551858152908101839052600f95939491939192917fb9388978b54026c51c20e3972ba5ed79bca3fc98beb4d005b4ae633b14db9718910160405180910390a1505050505050565b806000036123ea575050565b600654604051631062c15f60e11b81526001600160a01b03909116906320c582be9061241e9030908690869060040161396e565b600060405180830381600087803b15801561243857600080fd5b505af115801561244c573d6000803e3d6000fd5b50505050611f28816133de565b6001600160a01b0382166000908152600c602052604081208290558190036124ef576001600160a01b0382166000818152600d60209081526040808320838155600181018490556002810184905560030183905580518381529182018390528101919091527f2d6cc0bcdf72c9486f6451bde6b80f44066f4558f77f44dbfedbe7d8b295225a9060600160405180910390a25050565b6014546013546001600160801b03600160801b808404821660008181526015602090815260408083209590971680835294815286822054838352601682528783208684528252878320546001600160a01b038b16808552600d845293899020600181018990558281556002810182905595850287176003870155885188815292830182905297820188905294969295949391907f2d6cc0bcdf72c9486f6451bde6b80f44066f4558f77f44dbfedbe7d8b295225a9060600160405180910390a25050505050505050565b816000036125c5575050565b600a546125d29082612282565b600a556009546001600160a01b031661268d57604051600090339083908381818185875af1925050503d8060008114612627576040519150601f19603f3d011682016040523d82523d6000602084013e61262c565b606091505b50509050806126875760405162461bcd60e51b815260206004820152602160248201527f53746162696c697479506f6f6c3a2073656e64696e6720455448206661696c656044820152601960fa1b6064820152608401610a79565b506126a4565b6009546126a4906001600160a01b03163384613426565b600080516020613bcb833981519152600a546040516126c591815260200190565b60405180910390a160408051338152602081018490527fc4dfa259771b0ed50b100eaf04734dad1b094a866d9d285c59180cde3f3f45e89101611f1f565b6004546001600160a01b031633148061272657506005546001600160a01b031633145b610a825760405162461bcd60e51b815260206004820152602c60248201527f536f7274656454726f7665733a2043616c6c6572206973206e6f74207468652060448201526b2a3937bb32a6b0b730b3b2b960a11b6064820152608401610a79565b60008060006127b36018546127ad670de0b6b3a76400008961324190919063ffffffff16565b90610a84565b9050838511156127c5576127c56139a9565b8385036127e1576000601955670de0b6b3a76400009150612829565b601954600090612803906127fd88670de0b6b3a7640000613241565b90612282565b905061281460016127ad8388613235565b9250612824816127fd8588613241565b601955505b6128338185613235565b92506128496128428486613241565b8290612282565b60185550935093915050565b6013546000670de0b6b3a7640000831115612872576128726139a9565b6000612886670de0b6b3a764000085612282565b6014546001600160801b03600160801b8204811660008181526015602090815260408083209490951680835293905292832054939450909290916128ca8988613241565b905060006128d88383610a84565b6001600160801b038581166000818152601560209081526040808320948b16808452948252918290208590558151858152908101929092528101919091529091507fe12e2cd2c9afa8069203ca07e7eff1edce4a075686d0736a8e7e0d593597b2079060600160405180910390a185600003612a0b576129626001600160801b03851660016131b8565b601480546001600160801b03908116600160801b93821684021791829055604051929091041681527fb50f0f59e7cb5b421dc77581c3a9919e3806e076e5fa78a874c3f120cb7d874d9060200160405180910390a1601480546001600160801b0319169055604051600081527f1f9dfc70cd666adb18a39d60a797518f7b4febf4b6e24ef37d44f6e1e7219fbe9060200160405180910390a1670de0b6b3a76400009650612ad6565b633b9aca00612a26670de0b6b3a764000061208c8b8a613241565b1015612abd57612a50670de0b6b3a764000061208c633b9aca00612a4a8c8b613241565b90613241565b9650612a666001600160801b03861660016131b8565b601480546001600160801b0319166001600160801b039290921691821790556040519081527f1f9dfc70cd666adb18a39d60a797518f7b4febf4b6e24ef37d44f6e1e7219fbe9060200160405180910390a1612ad6565b612ad3670de0b6b3a764000061208c8a89613241565b96505b60008711612ae657612ae66139a9565b60138790556040518781527fc1a9618cb59ebca77cbdbc2949f126823c407ff13edb285fd0262519a9c18e8c9060200160405180910390a150505050505050505050565b60015460408051633fbeef2560e11b815290516000926001600160a01b031691637f7dde4a9160048083019260209291908290030181865afa158015612b74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b9891906138d5565b60095460405163fb24e5f760e01b81526001600160a01b0391821660048201526024810185905291925082169063fb24e5f790604401600060405180830381600087803b158015612be857600080fd5b505af1158015612bfc573d6000803e3d6000fd5b50505050612c09826133de565b600654604051632770a7eb60e21b8152306004820152602481018490526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b158015612c5557600080fd5b505af1158015612c69573d6000803e3d6000fd5b50506009546040516347878f1560e01b81526001600160a01b0380861694506347878f159350612ca19216903090889060040161396e565b600060405180830381600087803b158015612cbb57600080fd5b505af1158015612ccf573d6000803e3d6000fd5b50505050505050565b608081015160608201516040808401516020808601516001600160801b03808716600090815260168452858120918716815292529281205490949392908590612d219084612282565b6001600160801b0380871660009081526016602052604081209293509161206691633b9aca0091908490612046908a1660016131b8565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60008111611fc45760405162461bcd60e51b815260206004820152602660248201527f53746162696c697479506f6f6c3a20416d6f756e74206d757374206265206e6f6044820152656e2d7a65726f60d01b6064820152608401610a79565b600654604051632ee65eeb60e21b81526001600160a01b039091169063bb997bac90612e3b9085903090869060040161396e565b600060405180830381600087803b158015612e5557600080fd5b505af1158015612e69573d6000803e3d6000fd5b5050600b5460009250612e7d915083610a84565b600b8190556040518181529091507fe44ae3e449fe8ef1db6bee9206641d83bce427602b867fee92db3fb817e2c17b9060200160405180910390a1505050565b60006001600160a01b038316612ed4575080610a93565b81600003612ee457506000610a93565b6000836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f24573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f4891906139bf565b905060128160ff161015612f7e57612f76612f648260126139e2565b612f6f90600a613ae9565b8490613235565b915050610a93565b612f76612f8c6012836139e2565b612f9790600a613ae9565b8490613241565b60055460095460405163614d120960e01b81526001600160a01b039182166004820152838216602482015291169063614d120990604401602060405180830381865afa158015612ff2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130169190613920565b600114611fc45760405162461bcd60e51b815260206004820152604860248201527f53746162696c697479506f6f6c3a2063616c6c6572206d75737420686176652060448201527f616e206163746976652074726f766520746f2077697468647261772041737365606482015267744761696e20746f60c01b608482015260a401610a79565b60006130a7826114fc565b905060008111611f285760405162461bcd60e51b815260206004820152603160248201527f53746162696c697479506f6f6c3a2063616c6c6572206d7573742068617665206044820152703737b716bd32b9379022aa241023b0b4b760791b6064820152608401610a79565b6001600160a01b0381166131695760405162461bcd60e51b815260206004820152601e60248201527f4163636f756e742063616e6e6f74206265207a65726f206164647265737300006044820152606401610a79565b803b80611f285760405162461bcd60e51b815260206004820181905260248201527f4163636f756e7420636f64652073697a652063616e6e6f74206265207a65726f6044820152606401610a79565b6000806131c58385613af8565b9050836001600160801b0316816001600160801b03161015610a905760405162461bcd60e51b8152602060048201526024808201527f446672616e63536166654d6174683132383a206164646974696f6e206f766572604482015263666c6f7760e01b6064820152608401610a79565b6000610a908284613b23565b6000610a908284613b45565b6000826001600160801b0316826001600160801b031611156132c15760405162461bcd60e51b815260206004820152602760248201527f446672616e63536166654d6174683132383a207375627472616374696f6e206f604482015266766572666c6f7760c81b6064820152608401610a79565b6000610b308385613b64565b600b548015806132db575081155b156132e4575050565b60006132f08383613478565b905060006133096013548361324190919063ffffffff16565b6014546001600160801b03600160801b8204811660009081526016602090815260408083209390941682529190915220549091506133479082610a84565b60148054600160801b8082046001600160801b0390811660009081526016602081815260408084209685168452958152858320979097559454928304821680825294865283812092909116808252918552829020548251908152938401929092528201527f2d6127771b164a9cc8827d24b5955db2a77e7a81dac389107ebb8bce9fb649689060600160405180910390a150505050565b600b546000906133ee9083612282565b600b8190556040518181529091507fe44ae3e449fe8ef1db6bee9206641d83bce427602b867fee92db3fb817e2c17b90602001611f1f565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052611abf9084906134cb565b60008061349c6017546127ad670de0b6b3a76400008761324190919063ffffffff16565b905060006134aa8285613235565b90506134c06134b98286613241565b8390612282565b601755949350505050565b6000613520826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661359d9092919063ffffffff16565b805190915015611abf578080602001905181019061353e9190613b8c565b611abf5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a79565b6060610b30848460008585843b6135f65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a79565b600080866001600160a01b031685876040516136129190613bae565b60006040518083038185875af1925050503d806000811461364f576040519150601f19603f3d011682016040523d82523d6000602084013e613654565b606091505b509150915061366482828661366f565b979650505050505050565b6060831561367e5750816110f2565b82511561368e5782518084602001fd5b8160405162461bcd60e51b8152600401610a799190613794565b6001600160a01b0381168114611fc457600080fd5b6000602082840312156136cf57600080fd5b8135610a90816136a8565b80356001600160801b03811681146136f157600080fd5b919050565b6000806040838503121561370957600080fd5b613712836136da565b9150613720602084016136da565b90509250929050565b60006020828403121561373b57600080fd5b5035919050565b6000806040838503121561375557600080fd5b50508035926020909101359150565b60005b8381101561377f578181015183820152602001613767565b8381111561378e576000848401525b50505050565b60208152600082518060208401526137b3816040850160208701613764565b601f01601f19169190910160400192915050565b600080604083850312156137da57600080fd5b82356137e5816136a8565b915060208301356137f5816136a8565b809150509250929050565b600080600080600080600080610100898b03121561381d57600080fd5b8835613828816136a8565b97506020890135613838816136a8565b96506040890135613848816136a8565b95506060890135613858816136a8565b94506080890135613868816136a8565b935060a0890135613878816136a8565b925060c0890135613888816136a8565b915060e0890135613898816136a8565b809150509295985092959890939650565b600080604083850312156138bc57600080fd5b82356138c7816136a8565b946020939093013593505050565b6000602082840312156138e757600080fd5b8151610a90816136a8565b634e487b7160e01b600052601160045260246000fd5b6000821982111561391b5761391b6138f2565b500190565b60006020828403121561393257600080fd5b5051919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6000828210156139a4576139a46138f2565b500390565b634e487b7160e01b600052600160045260246000fd5b6000602082840312156139d157600080fd5b815160ff81168114610a9057600080fd5b600060ff821660ff8416808210156139fc576139fc6138f2565b90039392505050565b600181815b80851115613a40578160001904821115613a2657613a266138f2565b80851615613a3357918102915b93841c9390800290613a0a565b509250929050565b600082613a5757506001610a93565b81613a6457506000610a93565b8160018114613a7a5760028114613a8457613aa0565b6001915050610a93565b60ff841115613a9557613a956138f2565b50506001821b610a93565b5060208310610133831016604e8410600b8410161715613ac3575081810a610a93565b613acd8383613a05565b8060001904821115613ae157613ae16138f2565b029392505050565b6000610a9060ff841683613a48565b60006001600160801b03808316818516808303821115613b1a57613b1a6138f2565b01949350505050565b600082613b4057634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615613b5f57613b5f6138f2565b500290565b60006001600160801b0383811690831681811015613b8457613b846138f2565b039392505050565b600060208284031215613b9e57600080fd5b81518015158114610a9057600080fd5b60008251613bc0818460208701613764565b919091019291505056feda08342aeb056fbb00fd5a62a4033b8f6496e358fd964a431042595d762afbafa2646970667358221220d93b4e450b3d7a7dc910d0b0287ae36b370c65b208fb24240344e5e74fc018bf64736f6c634300080e0033

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
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.