ETH Price: $3,246.43 (-0.35%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Claim Collateral216736042025-01-21 14:57:232 days ago1737471443IN
MahaDAO: Borrower Operations
0 ETH0.0010054822.68648874
Open Trove195503222024-03-31 0:28:11298 days ago1711844891IN
MahaDAO: Borrower Operations
0.9 ETH0.0123938520.21311813
Open Trove195502922024-03-31 0:22:11298 days ago1711844531IN
MahaDAO: Borrower Operations
0.72 ETH0.0150397819.69220887
Open Trove194150792024-03-11 23:18:35317 days ago1710199115IN
MahaDAO: Borrower Operations
1.1 ETH0.0498713865.5534012
Open Trove193869952024-03-08 0:52:59321 days ago1709859179IN
MahaDAO: Borrower Operations
0.8 ETH0.0351012147.71267862
Claim Collateral192703822024-02-20 17:24:47338 days ago1708449887IN
MahaDAO: Borrower Operations
0 ETH0.0019692244.43098067
Open Trove191609082024-02-05 8:32:35353 days ago1707121955IN
MahaDAO: Borrower Operations
0.75 ETH0.0101346313.65943669
Withdraw Coll190684892024-01-23 9:31:11366 days ago1706002271IN
MahaDAO: Borrower Operations
0 ETH0.012847136.57381901
Repay ARTH190684722024-01-23 9:27:47366 days ago1706002067IN
MahaDAO: Borrower Operations
0 ETH0.0109270322.97569926
Withdraw ARTH190360922024-01-18 20:20:47371 days ago1705609247IN
MahaDAO: Borrower Operations
0 ETH0.0130225933.71343839
Add Coll190360872024-01-18 20:19:47371 days ago1705609187IN
MahaDAO: Borrower Operations
1 ETH0.0161273633.92364275
Withdraw ARTH190335522024-01-18 11:48:35371 days ago1705578515IN
MahaDAO: Borrower Operations
0 ETH0.0132148133.29682695
Add Coll190335472024-01-18 11:47:35371 days ago1705578455IN
MahaDAO: Borrower Operations
2 ETH0.0119531534.19895493
Open Trove190335322024-01-18 11:44:35371 days ago1705578275IN
MahaDAO: Borrower Operations
1 ETH0.0168679928.75661164
Open Trove190322872024-01-18 7:33:23371 days ago1705563203IN
MahaDAO: Borrower Operations
1 ETH0.0186800332.42521195
Open Trove190322532024-01-18 7:26:35371 days ago1705562795IN
MahaDAO: Borrower Operations
1 ETH0.0201654227.9531766
Close Trove177826262023-07-27 6:30:11546 days ago1690439411IN
MahaDAO: Borrower Operations
0 ETH0.0097928117.06085589
Withdraw Coll176885102023-07-14 1:42:47559 days ago1689298967IN
MahaDAO: Borrower Operations
0 ETH0.0118693620.64054841
Withdraw Coll173260262023-05-24 2:16:23610 days ago1684894583IN
MahaDAO: Borrower Operations
0 ETH0.0164684536.60934876
Repay ARTH172899462023-05-19 0:18:11615 days ago1684455491IN
MahaDAO: Borrower Operations
0 ETH0.0113724933.68539815
Add Coll172898802023-05-19 0:04:47615 days ago1684454687IN
MahaDAO: Borrower Operations
5 ETH0.0161541136.15271964
Open Trove171023912023-04-22 14:11:11642 days ago1682172671IN
MahaDAO: Borrower Operations
0.85 ETH0.0197278434.4091153
Withdraw Coll171016892023-04-22 11:48:59642 days ago1682164139IN
MahaDAO: Borrower Operations
0 ETH0.0156761531.42741653
Withdraw ARTH170727942023-04-18 9:50:47646 days ago1681811447IN
MahaDAO: Borrower Operations
0 ETH0.0173659333.60503357
Withdraw Coll170560982023-04-16 1:02:59648 days ago1681606979IN
MahaDAO: Borrower Operations
0 ETH0.0133334523.37525078
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
195503222024-03-31 0:28:11298 days ago1711844891
MahaDAO: Borrower Operations
0.9 ETH
195502922024-03-31 0:22:11298 days ago1711844531
MahaDAO: Borrower Operations
0.72 ETH
194150792024-03-11 23:18:35317 days ago1710199115
MahaDAO: Borrower Operations
1.1 ETH
193869952024-03-08 0:52:59321 days ago1709859179
MahaDAO: Borrower Operations
0.8 ETH
191609082024-02-05 8:32:35353 days ago1707121955
MahaDAO: Borrower Operations
0.75 ETH
190360872024-01-18 20:19:47371 days ago1705609187
MahaDAO: Borrower Operations
1 ETH
190335472024-01-18 11:47:35371 days ago1705578455
MahaDAO: Borrower Operations
2 ETH
190335322024-01-18 11:44:35371 days ago1705578275
MahaDAO: Borrower Operations
1 ETH
190322872024-01-18 7:33:23371 days ago1705563203
MahaDAO: Borrower Operations
1 ETH
190322532024-01-18 7:26:35371 days ago1705562795
MahaDAO: Borrower Operations
1 ETH
172898802023-05-19 0:04:47615 days ago1684454687
MahaDAO: Borrower Operations
5 ETH
171023912023-04-22 14:11:11642 days ago1682172671
MahaDAO: Borrower Operations
0.85 ETH
169748332023-04-04 10:06:35660 days ago1680602795
MahaDAO: Borrower Operations
0.001 ETH
169377232023-03-30 4:35:59665 days ago1680150959
MahaDAO: Borrower Operations
2.002 ETH
168651122023-03-19 23:46:11675 days ago1679269571
MahaDAO: Borrower Operations
1 ETH
168493452023-03-17 18:35:35678 days ago1679078135
MahaDAO: Borrower Operations
0.5 ETH
168270002023-03-14 15:11:47681 days ago1678806707
MahaDAO: Borrower Operations
1 ETH
168269792023-03-14 15:07:35681 days ago1678806455
MahaDAO: Borrower Operations
2.5 ETH
167944962023-03-10 1:28:23685 days ago1678411703
MahaDAO: Borrower Operations
2 ETH
167624612023-03-05 13:21:59690 days ago1678022519
MahaDAO: Borrower Operations
1.5 ETH
167624612023-03-05 13:21:59690 days ago1678022519
MahaDAO: Borrower Operations
1.5 ETH
165802862023-02-07 23:49:47715 days ago1675813787
MahaDAO: Borrower Operations
2 ETH
165338642023-02-01 12:07:35722 days ago1675253255
MahaDAO: Borrower Operations
1.8 ETH
165338642023-02-01 12:07:35722 days ago1675253255
MahaDAO: Borrower Operations
1.8 ETH
165288802023-01-31 19:24:47723 days ago1675193087
MahaDAO: Borrower Operations
16.004 ETH
View All Internal Transactions
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xF1b7f46e...e2B46CC8d
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
BorrowerOperations

Compiler Version
v0.8.0+commit.c7dfd78e

Optimization Enabled:
Yes with 100 runs

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

pragma solidity 0.8.0;

import "./Interfaces/IBorrowerOperations.sol";
import "./Interfaces/ITroveManager.sol";
import "./Interfaces/IARTHValuecoin.sol";
import "./Interfaces/ICollSurplusPool.sol";
import "./Interfaces/ISortedTroves.sol";
import "./Dependencies/LiquityBase.sol";
import "./Dependencies/SafeMath.sol";
import "./Dependencies/Ownable.sol";
import "./Dependencies/CheckContract.sol";

contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOperations {
    using SafeMath for uint256;
    string public constant NAME = "BorrowerOperations";

    // --- Connected contract declarations ---

    ITroveManager public troveManager;

    address stabilityPoolAddress;

    address gasPoolAddress;

    ICollSurplusPool collSurplusPool;

    IARTHValuecoin public arthToken;

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

    /* --- Variable container structs  ---

    Used to hold, return and assign variables inside a function, in order to avoid the error:
    "CompilerError: Stack too deep". */

    struct LocalVariables_adjustTrove {
        uint256 price;
        uint256 collChange;
        uint256 netDebtChange;
        bool isCollIncrease;
        uint256 debt;
        uint256 coll;
        uint256 oldICR;
        uint256 newICR;
        uint256 newTCR;
        uint256 ARTHFee;
        uint256 newDebt;
        uint256 newColl;
        uint256 stake;
    }

    struct LocalVariables_openTrove {
        uint256 price;
        uint256 ARTHFee;
        uint256 netDebt;
        uint256 compositeDebt;
        uint256 ICR;
        uint256 NICR;
        uint256 stake;
        uint256 arrayIndex;
    }

    struct ContractsCache {
        ITroveManager troveManager;
        IActivePool activePool;
        IARTHValuecoin arthToken;
    }

    mapping(address => bool) public frontEnds;

    // --- Dependency setters ---

    function setAddresses(
        address _troveManagerAddress,
        address _activePoolAddress,
        address _defaultPoolAddress,
        address _stabilityPoolAddress,
        address _gasPoolAddress,
        address _collSurplusPoolAddress,
        address _governanceAddress,
        address _sortedTrovesAddress,
        address _arthTokenAddress
    ) external override onlyOwner {
        checkContract(_troveManagerAddress);
        checkContract(_activePoolAddress);
        checkContract(_defaultPoolAddress);
        checkContract(_stabilityPoolAddress);
        checkContract(_gasPoolAddress);
        checkContract(_collSurplusPoolAddress);
        checkContract(_governanceAddress);
        checkContract(_sortedTrovesAddress);
        checkContract(_arthTokenAddress);

        troveManager = ITroveManager(_troveManagerAddress);
        activePool = IActivePool(_activePoolAddress);
        defaultPool = IDefaultPool(_defaultPoolAddress);
        stabilityPoolAddress = _stabilityPoolAddress;
        gasPoolAddress = _gasPoolAddress;
        collSurplusPool = ICollSurplusPool(_collSurplusPoolAddress);
        governance = IGovernance(_governanceAddress);
        sortedTroves = ISortedTroves(_sortedTrovesAddress);
        arthToken = IARTHValuecoin(_arthTokenAddress);

        emit TroveManagerAddressChanged(_troveManagerAddress);
        emit ActivePoolAddressChanged(_activePoolAddress);
        emit DefaultPoolAddressChanged(_defaultPoolAddress);
        emit StabilityPoolAddressChanged(_stabilityPoolAddress);
        emit GasPoolAddressChanged(_gasPoolAddress);
        emit CollSurplusPoolAddressChanged(_collSurplusPoolAddress);
        emit GovernanceAddressChanged(_governanceAddress);
        emit SortedTrovesAddressChanged(_sortedTrovesAddress);
        emit ARTHTokenAddressChanged(_arthTokenAddress);

        // This makes impossible to open a trove with zero withdrawn ARTH
        assert(MIN_NET_DEBT() > 0);

        // _renounceOwnership(); // renounce ownership after migration is done (openTroveFor)
    }

    // --- Borrower Trove Operations ---

    function registerFrontEnd() external override {
        _requireFrontEndNotRegistered(msg.sender);
        _requireTroveisNotActive(troveManager, msg.sender);
        frontEnds[msg.sender] = true;
        emit FrontEndRegistered(msg.sender, block.timestamp);
    }

    function openTrove(
        uint256 _maxFeePercentage,
        uint256 _ARTHAmount,
        address _upperHint,
        address _lowerHint
    ) external payable override {
        _openTrove(
            msg.sender,
            msg.sender,
            _maxFeePercentage,
            _ARTHAmount,
            _upperHint,
            _lowerHint,
            address(0)
        );
    }

    function openTrove(
        uint256 _maxFeePercentage,
        uint256 _ARTHAmount,
        address _upperHint,
        address _lowerHint,
        address _frontEndTag
    ) external payable override {
        _openTrove(
            msg.sender,
            msg.sender,
            _maxFeePercentage,
            _ARTHAmount,
            _upperHint,
            _lowerHint,
            _frontEndTag
        );
    }

    function openTroveFor(
        address _who,
        uint256 _maxFeePercentage,
        uint256 _ARTHAmount,
        address _upperHint,
        address _lowerHint,
        address _frontEndTag
    ) external payable onlyOwner {
        _openTrove(
            _who,
            msg.sender,
            _maxFeePercentage,
            _ARTHAmount,
            _upperHint,
            _lowerHint,
            _frontEndTag
        );
    }

    function _openTrove(
        address _who,
        address _arthRecipeint,
        uint256 _maxFeePercentage,
        uint256 _ARTHAmount,
        address _upperHint,
        address _lowerHint,
        address _frontEndTag
    ) internal {
        _requireFrontEndIsRegisteredOrZero(_frontEndTag);
        _requireFrontEndNotRegistered(_who);

        ContractsCache memory contractsCache = ContractsCache(troveManager, activePool, arthToken);
        LocalVariables_openTrove memory vars;

        vars.price = getPriceFeed().fetchPrice();
        bool isRecoveryMode = _checkRecoveryMode(vars.price);

        _requireValidMaxFeePercentage(_maxFeePercentage, isRecoveryMode);
        _requireTroveisNotActive(contractsCache.troveManager, _who);

        vars.ARTHFee;
        vars.netDebt = _ARTHAmount;

        if (!isRecoveryMode) {
            vars.ARTHFee = _triggerBorrowingFee(
                contractsCache.troveManager,
                contractsCache.arthToken,
                _ARTHAmount,
                _maxFeePercentage,
                _frontEndTag
            );
            vars.netDebt = vars.netDebt.add(vars.ARTHFee);
        }
        _requireAtLeastMinNetDebt(vars.netDebt);

        // ICR is based on the composite debt, i.e. the requested ARTH amount + ARTH borrowing fee + ARTH gas comp.
        vars.compositeDebt = _getCompositeDebt(vars.netDebt);
        assert(vars.compositeDebt > 0);

        vars.ICR = LiquityMath._computeCR(msg.value, vars.compositeDebt, vars.price);
        vars.NICR = LiquityMath._computeNominalCR(msg.value, vars.compositeDebt);

        if (isRecoveryMode) {
            _requireICRisAboveCCR(vars.ICR);
        } else {
            _requireICRisAboveMCR(vars.ICR);
            uint256 newTCR = _getNewTCRFromTroveChange(
                msg.value,
                true,
                vars.compositeDebt,
                true,
                vars.price
            ); // bools: coll increase, debt increase
            _requireNewTCRisAboveCCR(newTCR);
        }

        // Set the trove struct's properties
        contractsCache.troveManager.setTroveFrontEndTag(_who, _frontEndTag);
        contractsCache.troveManager.setTroveStatus(_who, 1);
        contractsCache.troveManager.increaseTroveColl(_who, msg.value);
        contractsCache.troveManager.increaseTroveDebt(_who, vars.compositeDebt);

        contractsCache.troveManager.updateTroveRewardSnapshots(_who);
        vars.stake = contractsCache.troveManager.updateStakeAndTotalStakes(_who);

        sortedTroves.insert(_who, vars.NICR, _upperHint, _lowerHint);
        vars.arrayIndex = contractsCache.troveManager.addTroveOwnerToArray(_who);
        emit TroveCreated(_who, vars.arrayIndex);

        // Move the ether to the Active Pool, and mint the ARTHAmount to the borrower
        _activePoolAddColl(contractsCache.activePool, msg.value);
        _withdrawARTH(
            contractsCache.activePool,
            contractsCache.arthToken,
            _arthRecipeint,
            _ARTHAmount,
            vars.netDebt
        );
        // Move the ARTH gas compensation to the Gas Pool
        _withdrawARTH(
            contractsCache.activePool,
            contractsCache.arthToken,
            gasPoolAddress,
            ARTH_GAS_COMPENSATION(),
            ARTH_GAS_COMPENSATION()
        );

        emit TroveUpdated(
            _who,
            vars.compositeDebt,
            msg.value,
            vars.stake,
            BorrowerOperation.openTrove
        );
        emit ARTHBorrowingFeePaid(_who, vars.ARTHFee);
    }

    // Send ETH as collateral to a trove
    function addColl(address _upperHint, address _lowerHint) external payable override {
        _adjustTrove(msg.sender, 0, 0, false, _upperHint, _lowerHint, 0);
    }

    // Send ETH as collateral to a trove. Called by only the Stability Pool.
    function moveETHGainToTrove(
        address _borrower,
        address _upperHint,
        address _lowerHint
    ) external payable override {
        _requireCallerIsStabilityPool();
        _adjustTrove(_borrower, 0, 0, false, _upperHint, _lowerHint, 0);
    }

    // Withdraw ETH collateral from a trove
    function withdrawColl(
        uint256 _collWithdrawal,
        address _upperHint,
        address _lowerHint
    ) external override {
        _adjustTrove(msg.sender, _collWithdrawal, 0, false, _upperHint, _lowerHint, 0);
    }

    // Withdraw ARTH tokens from a trove: mint new ARTH tokens to the owner, and increase the trove's debt accordingly
    function withdrawARTH(
        uint256 _maxFeePercentage,
        uint256 _ARTHAmount,
        address _upperHint,
        address _lowerHint
    ) external override {
        _adjustTrove(msg.sender, 0, _ARTHAmount, true, _upperHint, _lowerHint, _maxFeePercentage);
    }

    // Repay ARTH tokens to a Trove: Burn the repaid ARTH tokens, and reduce the trove's debt accordingly
    function repayARTH(
        uint256 _ARTHAmount,
        address _upperHint,
        address _lowerHint
    ) external override {
        _adjustTrove(msg.sender, 0, _ARTHAmount, false, _upperHint, _lowerHint, 0);
    }

    function adjustTrove(
        uint256 _maxFeePercentage,
        uint256 _collWithdrawal,
        uint256 _ARTHChange,
        bool _isDebtIncrease,
        address _upperHint,
        address _lowerHint
    ) external payable override {
        _adjustTrove(
            msg.sender,
            _collWithdrawal,
            _ARTHChange,
            _isDebtIncrease,
            _upperHint,
            _lowerHint,
            _maxFeePercentage
        );
    }

    /*
     * _adjustTrove(): Alongside a debt change, this function can perform either a collateral top-up or a collateral withdrawal.
     *
     * It therefore expects either a positive msg.value, or a positive _collWithdrawal argument.
     *
     * If both are positive, it will revert.
     */
    function _adjustTrove(
        address _borrower,
        uint256 _collWithdrawal,
        uint256 _ARTHChange,
        bool _isDebtIncrease,
        address _upperHint,
        address _lowerHint,
        uint256 _maxFeePercentage
    ) internal {
        ContractsCache memory contractsCache = ContractsCache(troveManager, activePool, arthToken);
        LocalVariables_adjustTrove memory vars;

        vars.price = getPriceFeed().fetchPrice();
        bool isRecoveryMode = _checkRecoveryMode(vars.price);

        if (_isDebtIncrease) {
            _requireValidMaxFeePercentage(_maxFeePercentage, isRecoveryMode);
            _requireNonZeroDebtChange(_ARTHChange);
        }
        _requireSingularCollChange(_collWithdrawal);
        _requireNonZeroAdjustment(_collWithdrawal, _ARTHChange);
        _requireTroveisActive(contractsCache.troveManager, _borrower);

        // Confirm the operation is either a borrower adjusting their own trove, or a pure ETH transfer from the Stability Pool to a trove
        assert(
            msg.sender == _borrower ||
                (msg.sender == stabilityPoolAddress && msg.value > 0 && _ARTHChange == 0)
        );

        contractsCache.troveManager.applyPendingRewards(_borrower);

        // Get the collChange based on whether or not ETH was sent in the transaction
        (vars.collChange, vars.isCollIncrease) = _getCollChange(msg.value, _collWithdrawal);

        vars.netDebtChange = _ARTHChange;

        // If the adjustment incorporates a debt increase and system is in Normal Mode, then trigger a borrowing fee
        if (_isDebtIncrease && !isRecoveryMode) {
            address frontEndTag = contractsCache.troveManager.getTroveFrontEnd(_borrower);
            vars.ARTHFee = _triggerBorrowingFee(
                contractsCache.troveManager,
                contractsCache.arthToken,
                _ARTHChange,
                _maxFeePercentage,
                frontEndTag
            );
            vars.netDebtChange = vars.netDebtChange.add(vars.ARTHFee); // The raw debt change includes the fee
        }

        vars.debt = contractsCache.troveManager.getTroveDebt(_borrower);
        vars.coll = contractsCache.troveManager.getTroveColl(_borrower);

        // Get the trove's old ICR before the adjustment, and what its new ICR will be after the adjustment
        vars.oldICR = LiquityMath._computeCR(vars.coll, vars.debt, vars.price);
        vars.newICR = _getNewICRFromTroveChange(
            vars.coll,
            vars.debt,
            vars.collChange,
            vars.isCollIncrease,
            vars.netDebtChange,
            _isDebtIncrease,
            vars.price
        );
        assert(_collWithdrawal <= vars.coll);

        // Check the adjustment satisfies all conditions for the current system mode
        _requireValidAdjustmentInCurrentMode(isRecoveryMode, _collWithdrawal, _isDebtIncrease, vars);

        // When the adjustment is a debt repayment, check it's a valid amount and that the caller has enough ARTH
        if (!_isDebtIncrease && _ARTHChange > 0) {
            _requireAtLeastMinNetDebt(_getNetDebt(vars.debt).sub(vars.netDebtChange));
            _requireValidARTHRepayment(vars.debt, vars.netDebtChange);
            _requireSufficientARTHBalance(contractsCache.arthToken, _borrower, vars.netDebtChange);
        }

        (vars.newColl, vars.newDebt) = _updateTroveFromAdjustment(
            contractsCache.troveManager,
            _borrower,
            vars.collChange,
            vars.isCollIncrease,
            vars.netDebtChange,
            _isDebtIncrease
        );
        vars.stake = contractsCache.troveManager.updateStakeAndTotalStakes(_borrower);

        // Re-insert trove in to the sorted list
        uint256 newNICR = _getNewNominalICRFromTroveChange(
            vars.coll,
            vars.debt,
            vars.collChange,
            vars.isCollIncrease,
            vars.netDebtChange,
            _isDebtIncrease
        );
        sortedTroves.reInsert(_borrower, newNICR, _upperHint, _lowerHint);

        emit TroveUpdated(
            _borrower,
            vars.newDebt,
            vars.newColl,
            vars.stake,
            BorrowerOperation.adjustTrove
        );
        emit ARTHBorrowingFeePaid(msg.sender, vars.ARTHFee);

        // Use the unmodified _ARTHChange here, as we don't send the fee to the user
        _moveTokensAndETHfromAdjustment(
            contractsCache.activePool,
            contractsCache.arthToken,
            msg.sender,
            vars.collChange,
            vars.isCollIncrease,
            _ARTHChange,
            _isDebtIncrease,
            vars.netDebtChange
        );
    }

    function closeTrove() external override {
        ITroveManager troveManagerCached = troveManager;
        IActivePool activePoolCached = activePool;
        IARTHValuecoin arthTokenCached = arthToken;

        _requireTroveisActive(troveManagerCached, msg.sender);
        uint256 price = getPriceFeed().fetchPrice();
        _requireNotInRecoveryMode(price);

        troveManagerCached.applyPendingRewards(msg.sender);

        uint256 coll = troveManagerCached.getTroveColl(msg.sender);
        uint256 debt = troveManagerCached.getTroveDebt(msg.sender);

        _requireSufficientARTHBalance(
            arthTokenCached,
            msg.sender,
            debt.sub(ARTH_GAS_COMPENSATION())
        );

        uint256 newTCR = _getNewTCRFromTroveChange(coll, false, debt, false, price);
        _requireNewTCRisAboveCCR(newTCR);

        troveManagerCached.removeStake(msg.sender);
        troveManagerCached.closeTrove(msg.sender);

        emit TroveUpdated(msg.sender, 0, 0, 0, BorrowerOperation.closeTrove);

        // Burn the repaid ARTH from the user's balance and the gas compensation from the Gas Pool
        _repayARTH(activePoolCached, arthTokenCached, msg.sender, debt.sub(ARTH_GAS_COMPENSATION()));
        _repayARTH(activePoolCached, arthTokenCached, gasPoolAddress, ARTH_GAS_COMPENSATION());

        // Send the collateral back to the user
        activePoolCached.sendETH(msg.sender, coll);
    }

    /**
     * Claim remaining collateral from a redemption or from a liquidation with ICR > MCR in Recovery Mode
     */
    function claimCollateral() external override {
        // send ETH from CollSurplus Pool to owner
        collSurplusPool.claimColl(msg.sender);
    }

    // --- Helper functions ---

    function _triggerBorrowingFee(
        ITroveManager _troveManager,
        IARTHValuecoin _arthToken,
        uint256 _ARTHAmount,
        uint256 _maxFeePercentage,
        address _frontEndTag
    ) internal returns (uint256) {
        _troveManager.decayBaseRateFromBorrowing(); // decay the baseRate state variable
        uint256 ARTHFee = _troveManager.getBorrowingFee(_ARTHAmount);

        _requireUserAcceptsFee(ARTHFee, _ARTHAmount, _maxFeePercentage);

        if (ARTHFee > 0) {
            uint256 feeForEcosystemFund = ARTHFee;

            // give 50% to ecosystem and frontend
            if (_frontEndTag != address(0)) {
                feeForEcosystemFund = ARTHFee.mul(50).div(100);
                uint256 _fee = ARTHFee.sub(feeForEcosystemFund);
                emit PaidARTHBorrowingFeeToFrontEnd(_frontEndTag, _fee);
                _arthToken.mint(_frontEndTag, _fee);
            }

            _sendFeeToEcosystemFund(_arthToken, feeForEcosystemFund);
        }

        return ARTHFee;
    }

    function _sendFeeToEcosystemFund(IARTHValuecoin _arthToken, uint256 _ARTHFee) internal {
        address ecosystemFund = governance.getFund();
        _arthToken.mint(ecosystemFund, _ARTHFee);
        emit PaidARTHBorrowingFeeToEcosystemFund(ecosystemFund, _ARTHFee);
    }

    function _getUSDValue(uint256 _coll, uint256 _price) internal pure returns (uint256) {
        uint256 usdValue = _price.mul(_coll).div(DECIMAL_PRECISION);

        return usdValue;
    }

    function _getCollChange(uint256 _collReceived, uint256 _requestedCollWithdrawal)
        internal
        pure
        returns (uint256 collChange, bool isCollIncrease)
    {
        if (_collReceived != 0) {
            collChange = _collReceived;
            isCollIncrease = true;
        } else {
            collChange = _requestedCollWithdrawal;
        }
    }

    // Update trove's coll and debt based on whether they increase or decrease
    function _updateTroveFromAdjustment(
        ITroveManager _troveManager,
        address _borrower,
        uint256 _collChange,
        bool _isCollIncrease,
        uint256 _debtChange,
        bool _isDebtIncrease
    ) internal returns (uint256, uint256) {
        uint256 newColl = (_isCollIncrease)
            ? _troveManager.increaseTroveColl(_borrower, _collChange)
            : _troveManager.decreaseTroveColl(_borrower, _collChange);
        uint256 newDebt = (_isDebtIncrease)
            ? _troveManager.increaseTroveDebt(_borrower, _debtChange)
            : _troveManager.decreaseTroveDebt(_borrower, _debtChange);

        return (newColl, newDebt);
    }

    function _moveTokensAndETHfromAdjustment(
        IActivePool _activePool,
        IARTHValuecoin _arthToken,
        address _borrower,
        uint256 _collChange,
        bool _isCollIncrease,
        uint256 _ARTHChange,
        bool _isDebtIncrease,
        uint256 _netDebtChange
    ) internal {
        if (_isDebtIncrease) {
            _withdrawARTH(_activePool, _arthToken, _borrower, _ARTHChange, _netDebtChange);
        } else {
            _repayARTH(_activePool, _arthToken, _borrower, _ARTHChange);
        }

        if (_isCollIncrease) {
            _activePoolAddColl(_activePool, _collChange);
        } else {
            _activePool.sendETH(_borrower, _collChange);
        }
    }

    // Send ETH to Active Pool and increase its recorded ETH balance
    function _activePoolAddColl(IActivePool _activePool, uint256 _amount) internal {
        (bool success, ) = address(_activePool).call{value: _amount}("");
        require(success, "BorrowerOps: Sending ETH to ActivePool failed");
    }

    // Issue the specified amount of ARTH to _account and increases the total active debt (_netDebtIncrease potentially includes a ARTHFee)
    function _withdrawARTH(
        IActivePool _activePool,
        IARTHValuecoin _arthToken,
        address _account,
        uint256 _ARTHAmount,
        uint256 _netDebtIncrease
    ) internal {
        require(
            _activePool.getARTHDebt() + _ARTHAmount <= governance.getMaxDebtCeiling(),
            "mint > max debt"
        );
        require(governance.getAllowMinting(), "!minting");
        _activePool.increaseARTHDebt(_netDebtIncrease);
        _arthToken.mint(_account, _ARTHAmount);
    }

    // Burn the specified amount of ARTH from _account and decreases the total active debt
    function _repayARTH(
        IActivePool _activePool,
        IARTHValuecoin _arthToken,
        address _account,
        uint256 _ARTH
    ) internal {
        _activePool.decreaseARTHDebt(_ARTH);
        _arthToken.burn(_account, _ARTH);
    }

    // --- 'Require' wrapper functions ---

    function _requireSingularCollChange(uint256 _collWithdrawal) internal view {
        require(
            msg.value == 0 || _collWithdrawal == 0,
            "BorrowerOperations: Cannot withdraw and add coll"
        );
    }

    function _requireCallerIsBorrower(address _borrower) internal view {
        require(
            msg.sender == _borrower,
            "BorrowerOps: Caller must be the borrower for a withdrawal"
        );
    }

    function _requireNonZeroAdjustment(uint256 _collWithdrawal, uint256 _ARTHChange) internal view {
        require(
            msg.value != 0 || _collWithdrawal != 0 || _ARTHChange != 0,
            "BorrowerOps: There must be either a collateral change or a debt change"
        );
    }

    function _requireTroveisActive(ITroveManager _troveManager, address _borrower) internal view {
        uint256 status = _troveManager.getTroveStatus(_borrower);
        require(status == 1, "BorrowerOps: Trove does not exist or is closed");
    }

    function _requireTroveisNotActive(ITroveManager _troveManager, address _borrower) internal view {
        uint256 status = _troveManager.getTroveStatus(_borrower);
        require(status != 1, "BorrowerOps: Trove is active");
    }

    function _requireNonZeroDebtChange(uint256 _ARTHChange) internal pure {
        require(_ARTHChange > 0, "BorrowerOps: Debt increase requires non-zero debtChange");
    }

    function _requireNotInRecoveryMode(uint256 _price) internal view {
        require(
            !_checkRecoveryMode(_price),
            "BorrowerOps: Operation not permitted during Recovery Mode"
        );
    }

    function _requireNoCollWithdrawal(uint256 _collWithdrawal) internal pure {
        require(
            _collWithdrawal == 0,
            "BorrowerOps: Collateral withdrawal not permitted Recovery Mode"
        );
    }

    function _requireValidAdjustmentInCurrentMode(
        bool _isRecoveryMode,
        uint256 _collWithdrawal,
        bool _isDebtIncrease,
        LocalVariables_adjustTrove memory _vars
    ) internal view {
        /*
         *In Recovery Mode, only allow:
         *
         * - Pure collateral top-up
         * - Pure debt repayment
         * - Collateral top-up with debt repayment
         * - A debt increase combined with a collateral top-up which makes the ICR >= 150% and improves the ICR (and by extension improves the TCR).
         *
         * In Normal Mode, ensure:
         *
         * - The new ICR is above MCR
         * - The adjustment won't pull the TCR below CCR
         */
        if (_isRecoveryMode) {
            _requireNoCollWithdrawal(_collWithdrawal);
            if (_isDebtIncrease) {
                _requireICRisAboveCCR(_vars.newICR);
                _requireNewICRisAboveOldICR(_vars.newICR, _vars.oldICR);
            }
        } else {
            // if Normal Mode
            _requireICRisAboveMCR(_vars.newICR);
            _vars.newTCR = _getNewTCRFromTroveChange(
                _vars.collChange,
                _vars.isCollIncrease,
                _vars.netDebtChange,
                _isDebtIncrease,
                _vars.price
            );
            _requireNewTCRisAboveCCR(_vars.newTCR);
        }
    }

    function _requireFrontEndNotRegistered(address _address) internal view {
        require(
            !frontEnds[_address],
            "BorrowerOperations: Must not already be a registered front end"
        );
    }

    function _requireFrontEndIsRegisteredOrZero(address _address) internal view {
        require(
            frontEnds[_address] || _address == address(0),
            "BorrowerOperations: Tag must be a registered front end, or the 0x0"
        );
    }

    function _requireICRisAboveMCR(uint256 _newICR) internal pure {
        require(
            _newICR >= MCR,
            "BorrowerOps: An operation that would result in ICR < MCR is not permitted"
        );
    }

    function _requireICRisAboveCCR(uint256 _newICR) internal pure {
        require(_newICR >= CCR, "BorrowerOps: Operation must leave trove with ICR >= CCR");
    }

    function _requireNewICRisAboveOldICR(uint256 _newICR, uint256 _oldICR) internal pure {
        require(
            _newICR >= _oldICR,
            "BorrowerOps: Cannot decrease your Trove's ICR in Recovery Mode"
        );
    }

    function _requireNewTCRisAboveCCR(uint256 _newTCR) internal pure {
        require(
            _newTCR >= CCR,
            "BorrowerOps: An operation that would result in TCR < CCR is not permitted"
        );
    }

    function _requireAtLeastMinNetDebt(uint256 _netDebt) internal view {
        require(
            _netDebt >= MIN_NET_DEBT(),
            "BorrowerOps: Trove's net debt must be greater than minimum"
        );
    }

    function _requireValidARTHRepayment(uint256 _currentDebt, uint256 _debtRepayment) internal view {
        require(
            _debtRepayment <= _currentDebt.sub(ARTH_GAS_COMPENSATION()),
            "BorrowerOps: Amount repaid must not be larger than the Trove's debt"
        );
    }

    function _requireCallerIsStabilityPool() internal view {
        require(msg.sender == stabilityPoolAddress, "BorrowerOps: Caller is not Stability Pool");
    }

    function _requireSufficientARTHBalance(
        IARTHValuecoin _arthToken,
        address _borrower,
        uint256 _debtRepayment
    ) internal view {
        require(
            _arthToken.balanceOf(_borrower) >= _debtRepayment,
            "BorrowerOps: Caller doesnt have enough ARTH to make repayment"
        );
    }

    function _requireValidMaxFeePercentage(uint256 _maxFeePercentage, bool _isRecoveryMode)
        internal
        view
    {
        if (_isRecoveryMode) {
            require(
                _maxFeePercentage <= DECIMAL_PRECISION,
                "Max fee percentage must less than or equal to 100%"
            );
        } else {
            require(
                _maxFeePercentage >= getBorrowingFeeFloor() &&
                    _maxFeePercentage <= DECIMAL_PRECISION,
                "Max fee percentage must be between 0.5% and 100%"
            );
        }
    }

    // --- ICR and TCR getters ---

    // Compute the new collateral ratio, considering the change in coll and debt. Assumes 0 pending rewards.
    function _getNewNominalICRFromTroveChange(
        uint256 _coll,
        uint256 _debt,
        uint256 _collChange,
        bool _isCollIncrease,
        uint256 _debtChange,
        bool _isDebtIncrease
    ) internal pure returns (uint256) {
        (uint256 newColl, uint256 newDebt) = _getNewTroveAmounts(
            _coll,
            _debt,
            _collChange,
            _isCollIncrease,
            _debtChange,
            _isDebtIncrease
        );

        uint256 newNICR = LiquityMath._computeNominalCR(newColl, newDebt);
        return newNICR;
    }

    // Compute the new collateral ratio, considering the change in coll and debt. Assumes 0 pending rewards.
    function _getNewICRFromTroveChange(
        uint256 _coll,
        uint256 _debt,
        uint256 _collChange,
        bool _isCollIncrease,
        uint256 _debtChange,
        bool _isDebtIncrease,
        uint256 _price
    ) internal pure returns (uint256) {
        (uint256 newColl, uint256 newDebt) = _getNewTroveAmounts(
            _coll,
            _debt,
            _collChange,
            _isCollIncrease,
            _debtChange,
            _isDebtIncrease
        );

        uint256 newICR = LiquityMath._computeCR(newColl, newDebt, _price);
        return newICR;
    }

    function _getNewTroveAmounts(
        uint256 _coll,
        uint256 _debt,
        uint256 _collChange,
        bool _isCollIncrease,
        uint256 _debtChange,
        bool _isDebtIncrease
    ) internal pure returns (uint256, uint256) {
        uint256 newColl = _coll;
        uint256 newDebt = _debt;

        newColl = _isCollIncrease ? _coll.add(_collChange) : _coll.sub(_collChange);
        newDebt = _isDebtIncrease ? _debt.add(_debtChange) : _debt.sub(_debtChange);

        return (newColl, newDebt);
    }

    function _getNewTCRFromTroveChange(
        uint256 _collChange,
        bool _isCollIncrease,
        uint256 _debtChange,
        bool _isDebtIncrease,
        uint256 _price
    ) internal view returns (uint256) {
        uint256 totalColl = getEntireSystemColl();
        uint256 totalDebt = getEntireSystemDebt();

        totalColl = _isCollIncrease ? totalColl.add(_collChange) : totalColl.sub(_collChange);
        totalDebt = _isDebtIncrease ? totalDebt.add(_debtChange) : totalDebt.sub(_debtChange);

        uint256 newTCR = LiquityMath._computeCR(totalColl, totalDebt, _price);
        return newTCR;
    }

    function getCompositeDebt(uint256 _debt) external view override returns (uint256) {
        return _getCompositeDebt(_debt);
    }

    function BORROWING_FEE_FLOOR() external view returns (uint256) {
        return getBorrowingFeeFloor();
    }
}

File 2 of 22 : IBorrowerOperations.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

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

    event TroveManagerAddressChanged(address _newTroveManagerAddress);
    event ActivePoolAddressChanged(address _activePoolAddress);
    event DefaultPoolAddressChanged(address _defaultPoolAddress);
    event StabilityPoolAddressChanged(address _stabilityPoolAddress);
    event GasPoolAddressChanged(address _gasPoolAddress);
    event CollSurplusPoolAddressChanged(address _collSurplusPoolAddress);
    event GovernanceAddressChanged(address _newGovernanceAddress);
    event SortedTrovesAddressChanged(address _sortedTrovesAddress);
    event ARTHTokenAddressChanged(address _arthTokenAddress);

    event TroveCreated(address indexed _borrower, uint256 arrayIndex);
    event TroveUpdated(
        address indexed _borrower,
        uint256 _debt,
        uint256 _coll,
        uint256 stake,
        BorrowerOperation operation
    );
    event ARTHBorrowingFeePaid(address indexed _borrower, uint256 _ARTHFee);
    event FrontEndRegistered(address indexed _frontend, uint256 timestamp);
    event PaidARTHBorrowingFeeToEcosystemFund(address indexed _ecosystemFund, uint256 _ARTHFee);
    event PaidARTHBorrowingFeeToFrontEnd(address indexed _frontEndTag, uint256 _ARTHFee);

    enum BorrowerOperation {
        openTrove,
        closeTrove,
        adjustTrove
    }

    // --- Functions ---

    function setAddresses(
        address _troveManagerAddress,
        address _activePoolAddress,
        address _defaultPoolAddress,
        address _stabilityPoolAddress,
        address _gasPoolAddress,
        address _collSurplusPoolAddress,
        address _governanceAddress,
        address _sortedTrovesAddress,
        address _arthTokenAddress
    ) external;

    function registerFrontEnd() external;

    function openTrove(
        uint256 _maxFee,
        uint256 _ARTHAmount,
        address _upperHint,
        address _lowerHint,
        address _frontEndTag
    ) external payable;

    function openTrove(
        uint256 _maxFee,
        uint256 _ARTHAmount,
        address _upperHint,
        address _lowerHint
    ) external payable;

    function addColl(address _upperHint, address _lowerHint) external payable;

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

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

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

    function repayARTH(
        uint256 _amount,
        address _upperHint,
        address _lowerHint
    ) external;

    function closeTrove() external;

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

    function claimCollateral() external;

    function getCompositeDebt(uint256 _debt) external view returns (uint256);
}

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

pragma solidity 0.8.0;

import "./ILiquityBase.sol";
import "./IStabilityPool.sol";
import "./IARTHValuecoin.sol";

// Common interface for the Trove Manager.
interface ITroveManager is ILiquityBase {
    // --- Events ---

    event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
    event ARTHTokenAddressChanged(address _newARTHTokenAddress);
    event ActivePoolAddressChanged(address _activePoolAddress);
    event DefaultPoolAddressChanged(address _defaultPoolAddress);
    event StabilityPoolAddressChanged(address _stabilityPoolAddress);
    event GasPoolAddressChanged(address _gasPoolAddress);
    event CollSurplusPoolAddressChanged(address _collSurplusPoolAddress);
    event SortedTrovesAddressChanged(address _sortedTrovesAddress);
    event GovernanceAddressChanged(address _governanceAddress);
    event WETHAddressChanged(address _wethAddress);

    event RewardSnapshotDetailsUpdated(address owner, address newOwner, uint256 timestamp);
    event TroveOwnersUpdated(address owner, address newOwner, uint256 idx, uint256 timestamp);
    event Liquidation(
        uint256 _liquidatedDebt,
        uint256 _liquidatedColl,
        uint256 _collGasCompensation,
        uint256 _ARTHGasCompensation
    );
    event Redemption(
        uint256 _attemptedARTHAmount,
        uint256 _actualARTHAmount,
        uint256 _ETHSent,
        uint256 _ETHFee
    );
    event TroveUpdated(
        address indexed _borrower,
        uint256 _debt,
        uint256 _coll,
        uint256 _stake,
        TroveManagerOperation _operation
    );
    event TroveLiquidated(
        address indexed _borrower,
        uint256 _debt,
        uint256 _coll,
        TroveManagerOperation _operation
    );
    event BaseRateUpdated(uint256 _baseRate);
    event LastFeeOpTimeUpdated(uint256 _lastFeeOpTime);
    event TotalStakesUpdated(uint256 _newTotalStakes);
    event SystemSnapshotsUpdated(uint256 _totalStakesSnapshot, uint256 _totalCollateralSnapshot);
    event LTermsUpdated(uint256 _L_ETH, uint256 _L_ARTHDebt);
    event TroveSnapshotsUpdated(uint256 _L_ETH, uint256 _L_ARTHDebt);
    event TroveIndexUpdated(address _borrower, uint256 _newIndex);

    enum TroveManagerOperation {
        applyPendingRewards,
        liquidateInNormalMode,
        liquidateInRecoveryMode,
        redeemCollateral
    }

    // --- Functions ---

    function setAddresses(
        address _borrowerOperationsAddress,
        address _activePoolAddress,
        address _defaultPoolAddress,
        address _stabilityPoolAddress,
        address _gasPoolAddress,
        address _collSurplusPoolAddress,
        address _governanceAddress,
        address _arthTokenAddress,
        address _sortedTrovesAddress
    ) external;

    function stabilityPool() external view returns (IStabilityPool);

    function arthToken() external view returns (IARTHValuecoin);

    function getTroveOwnersCount() external view returns (uint256);

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

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

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

    function liquidate(address _borrower) external;

    function liquidateTroves(uint256 _n) external;

    function batchLiquidateTroves(address[] calldata _troveArray) external;

    function redeemCollateral(
        uint256 _ARTHAmount,
        address _firstRedemptionHint,
        address _upperPartialRedemptionHint,
        address _lowerPartialRedemptionHint,
        uint256 _partialRedemptionHintNICR,
        uint256 _maxIterations,
        uint256 _maxFee
    ) external;

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

    function updateTroveRewardSnapshots(address _borrower) external;

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

    function applyPendingRewards(address _borrower) external;

    function getPendingETHReward(address _borrower) external view returns (uint256);

    function getPendingARTHDebtReward(address _borrower) external view returns (uint256);

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

    function getEntireDebtAndColl(address _borrower)
        external
        view
        returns (
            uint256 debt,
            uint256 coll,
            uint256 pendingARTHDebtReward,
            uint256 pendingETHReward
        );

    function closeTrove(address _borrower) external;

    function removeStake(address _borrower) external;

    function getRedemptionRate() external view returns (uint256);

    function getRedemptionRateWithDecay() external view returns (uint256);

    function getRedemptionFeeWithDecay(uint256 _ETHDrawn) external view returns (uint256);

    function getBorrowingRate() external view returns (uint256);

    function getBorrowingRateWithDecay() external view returns (uint256);

    function getBorrowingFee(uint256 ARTHDebt) external view returns (uint256);

    function getBorrowingFeeWithDecay(uint256 _ARTHDebt) external view returns (uint256);

    function decayBaseRateFromBorrowing() external;

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

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

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

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

    function setTroveStatus(address _borrower, uint256 num) external;

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

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

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

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

    function getTCR(uint256 _price) external view returns (uint256);

    function checkRecoveryMode(uint256 _price) external view returns (bool);

    function getTroveFrontEnd(address _borrower) external view returns (address);

    function setTroveFrontEndTag(address _borrower, address _frontEndTag) external;
}

File 4 of 22 : IARTHValuecoin.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

import "../Interfaces/IERC20.sol";
import "../Interfaces/IERC2612.sol";

interface IARTHValuecoin is IERC20, IERC2612 {
    // --- Events ---
    event BorrowerOperationsAddressToggled(
        address borrowerOperations,
        bool oldFlag,
        bool newFlag,
        uint256 timestamp
    );
    event TroveManagerToggled(address troveManager, bool oldFlag, bool newFlag, uint256 timestamp);
    event StabilityPoolToggled(address stabilityPool, bool oldFlag, bool newFlag, uint256 timestamp);
    event TroveManagerAddressChanged(address _troveManagerAddress);
    event StabilityPoolAddressChanged(address _newStabilityPoolAddress);
    event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
    event ARTHTokenBalanceUpdated(address _user, uint256 _amount);

    // --- Functions ---

    function mint(address _account, uint256 _amount) external;

    function burn(address _account, uint256 _amount) external;

    function toggleBorrowerOperations(address borrowerOperations) external;

    function toggleTroveManager(address troveManager) external;

    function toggleStabilityPool(address stabilityPool) external;

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

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

File 5 of 22 : ICollSurplusPool.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

interface ICollSurplusPool {
    // --- Events ---

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

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

    // --- Contract setters ---

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

    function getETH() external view returns (uint256);

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

    function accountSurplus(address _account, uint256 _amount) external;

    function claimColl(address _account) external;
}

File 6 of 22 : ISortedTroves.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

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

    event TroveManagerAddressChanged(address _troveManagerAddress);
    event SortedTrovesAddressChanged(address _sortedDoublyLLAddress);
    event BorrowerOperationsAddressChanged(address _borrowerOperationsAddress);
    event NodeAdded(address _id, uint256 _NICR);
    event NodeRemoved(address _id);

    // --- Functions ---

    function setParams(
        uint256 _size,
        address _TroveManagerAddress,
        address _borrowerOperationsAddress
    ) external;

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

    function remove(address _id) external;

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

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

    function isFull() external view returns (bool);

    function isEmpty() external view returns (bool);

    function getSize() external view returns (uint256);

    function getMaxSize() external view returns (uint256);

    function getFirst() external view returns (address);

    function getLast() external view returns (address);

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

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

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

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

File 7 of 22 : LiquityBase.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

import "./BaseMath.sol";
import "./LiquityMath.sol";
import "../Interfaces/IActivePool.sol";
import "../Interfaces/IDefaultPool.sol";
import "../Interfaces/IPriceFeed.sol";
import "../Interfaces/ILiquityBase.sol";
import "../Interfaces/IGovernance.sol";

/*
 * Base contract for TroveManager, BorrowerOperations and StabilityPool. Contains global system constants and
 * common functions.
 */
contract LiquityBase is BaseMath, ILiquityBase {
    using SafeMath for uint256;

    uint256 public constant _100pct = 1000000000000000000; // 1e18 == 100%

    // Minimum collateral ratio for individual troves
    uint256 public constant MCR = 1100000000000000000; // 110%

    // Critical system collateral ratio. If the system's total collateral ratio (TCR) falls below the CCR, Recovery Mode is triggered.
    uint256 public constant CCR = 1500000000000000000; // 150%

    uint256 MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

    uint256 public PERCENT_DIVISOR = 200; // dividing by 200 yields 0.5%

    IActivePool public activePool;
    IDefaultPool public defaultPool;
    IGovernance public governance;

    // --- Gas compensation functions ---

    function getBorrowingFeeFloor() public view returns (uint256) {
        return governance.getBorrowingFeeFloor();
    }

    function getRedemptionFeeFloor() public view returns (uint256) {
        return governance.getRedemptionFeeFloor();
    }

    function getMaxBorrowingFee() public view returns (uint256) {
        return governance.getMaxBorrowingFee();
    }

    function getPriceFeed() public view override returns (IPriceFeed) {
        return governance.getPriceFeed();
    }

    function fetchPriceFeedPrice() public returns (uint256) {
        return governance.getPriceFeed().fetchPrice();
    }

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

    function _getNetDebt(uint256 _debt) internal view returns (uint256) {
        return _debt.sub(ARTH_GAS_COMPENSATION());
    }

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

    function getEntireSystemColl() public view returns (uint256 entireSystemColl) {
        uint256 activeColl = activePool.getETH();
        uint256 liquidatedColl = defaultPool.getETH();
        return activeColl.add(liquidatedColl);
    }

    function getEntireSystemDebt() public view returns (uint256 entireSystemDebt) {
        uint256 activeDebt = activePool.getARTHDebt();
        uint256 closedDebt = defaultPool.getARTHDebt();
        return activeDebt.add(closedDebt);
    }

    function ARTH_GAS_COMPENSATION() public view returns (uint256) {
        return governance.getGasCompensation();
    }

    function MIN_NET_DEBT() public view returns (uint256) {
        return governance.getMinNetDebt();
    }

    function _getTCR(uint256 _price) internal view returns (uint256 TCR) {
        uint256 entireSystemColl = getEntireSystemColl();
        uint256 entireSystemDebt = getEntireSystemDebt();
        TCR = LiquityMath._computeCR(entireSystemColl, entireSystemDebt, _price);
        return TCR;
    }

    function _checkRecoveryMode(uint256 _price) internal view returns (bool) {
        uint256 TCR = _getTCR(_price);
        return TCR < CCR;
    }

    function _requireUserAcceptsFee(
        uint256 _fee,
        uint256 _amount,
        uint256 _maxFeePercentage
    ) internal pure {
        uint256 feePercentage = _fee.mul(DECIMAL_PRECISION).div(_amount);
        require(feePercentage <= _maxFeePercentage, "Fee exceeded provided maximum");
    }
}

File 8 of 22 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

/**
 * Based on OpenZeppelin's SafeMath:
 * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol
 *
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @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) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @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 sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     *
     * _Available since v2.4.0._
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

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

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts 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.
     *
     * _Available since v2.4.0._
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts 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 mod(a, b, "SafeMath: modulo by zero");
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message 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.
     *
     * _Available since v2.4.0._
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}

File 9 of 22 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

/**
 * Based on OpenZeppelin's Ownable contract:
 * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.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.
 *
 * 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.
 */
contract Ownable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _owner = msg.sender;
        emit OwnershipTransferred(address(0), msg.sender);
    }

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

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

    /**
     * @dev Returns true if the caller is the current owner.
     */
    function isOwner() public view returns (bool) {
        return msg.sender == _owner;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     *
     * NOTE: This function is not safe, as it doesn’t check owner is calling it.
     * Make sure you check it before calling it.
     */
    function _renounceOwnership() internal {
        emit OwnershipTransferred(_owner, address(0));
        _owner = 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");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 10 of 22 : CheckContract.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

contract CheckContract {
    /**
     * Check that the account is an already deployed non-destroyed contract.
     * See: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Address.sol#L12
     */
    function checkContract(address _account) internal view {
        require(_account != address(0), "Account cannot be zero address");

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            size := extcodesize(_account)
        }
        require(size > 0, "Account code size cannot be zero");
    }
}

File 11 of 22 : ILiquityBase.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

import "./IPriceFeed.sol";
import "./IGovernance.sol";

interface ILiquityBase {
    // function governance() external view returns (IGovernance);

    function getPriceFeed() external view returns (IPriceFeed);
}

File 12 of 22 : IStabilityPool.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

/*
 * The Stability Pool holds ARTH tokens deposited by Stability Pool depositors.
 *
 * When a trove is liquidated, then depending on system conditions, some of its ARTH debt gets offset with
 * ARTH in the Stability Pool:  that is, the offset debt evaporates, and an equal amount of ARTH tokens in the Stability Pool is burned.
 *
 * Thus, a liquidation causes each depositor to receive a ARTH loss, in proportion to their deposit as a share of total deposits.
 * They also receive an ETH gain, as the ETH collateral of the liquidated trove is distributed among Stability depositors,
 * in the same proportion.
 *
 * When a liquidation occurs, it depletes every deposit by the same fraction: for example, a liquidation that depletes 40%
 * of the total ARTH in the Stability Pool, depletes 40% of each deposit.
 *
 * A deposit that has experienced a series of liquidations is termed a "compounded deposit": each liquidation depletes the deposit,
 * multiplying it by some factor in range ]0,1[
 *
 * Please see the implementation spec in the proof document, which closely follows on from the compounded deposit / ETH gain derivations:
 * https://github.com/liquity/liquity/blob/master/papers/Scalable_Reward_Distribution_with_Compounding_Stakes.pdf
 *
 * --- MAHA ISSUANCE TO STABILITY POOL DEPOSITORS ---
 *
 * An MAHA issuance event occurs at every deposit operation, and every liquidation.
 *
 * Each deposit is tagged with the address of the front end through which it was made.
 *
 * All deposits earn a share of the issued MAHA in proportion to the deposit as a share of total deposits. The MAHA earned
 * by a given deposit, is split between the depositor and the front end through which the deposit was made, based on the front end's kickbackRate.
 *
 * Please see the system Readme for an overview:
 * https://github.com/liquity/dev/blob/main/README.md#maha-issuance-to-stability-providers
 */
interface IStabilityPool {
    // --- Events ---

    event StabilityPoolETHBalanceUpdated(uint256 _newBalance);
    event StabilityPoolARTHBalanceUpdated(uint256 _newBalance);

    event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
    event TroveManagerAddressChanged(address _newTroveManagerAddress);
    event ActivePoolAddressChanged(address _newActivePoolAddress);
    event DefaultPoolAddressChanged(address _newDefaultPoolAddress);
    event ARTHTokenAddressChanged(address _newARTHTokenAddress);
    event SortedTrovesAddressChanged(address _newSortedTrovesAddress);
    event GovernanceAddressChanged(address _newGovernanceAddress);
    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 FrontEndRegistered(address indexed _frontEnd, uint256 _kickbackRate);
    event FrontEndTagSet(address indexed _depositor, address indexed _frontEnd);

    event DepositSnapshotUpdated(address indexed _depositor, uint256 _P, uint256 _S, uint256 _G);
    event FrontEndSnapshotUpdated(address indexed _frontEnd, uint256 _P, uint256 _G);
    event UserDepositChanged(address indexed _depositor, uint256 _newDeposit);
    event FrontEndStakeChanged(
        address indexed _frontEnd,
        uint256 _newFrontEndStake,
        address _depositor
    );

    event ETHGainWithdrawn(address indexed _depositor, uint256 _ETH, uint256 _ARTHLoss);
    event MAHAPaidToDepositor(address indexed _depositor, uint256 _MAHA);
    event MAHAPaidToFrontEnd(address indexed _frontEnd, uint256 _MAHA);
    event EtherSent(address _to, uint256 _amount);

    // --- Functions ---

    /*
     * Called only once on init, to set addresses of other Liquity contracts
     * Callable only by owner, renounces ownership at the end
     */
    function setAddresses(
        address _borrowerOperationsAddress,
        address _troveManagerAddress,
        address _activePoolAddress,
        address _arthTokenAddress,
        address _sortedTrovesAddress,
        address _governanceAddress,
        address _communityIssuanceAddress
    ) external;

    /*
     * Initial checks:
     * - Frontend is registered or zero address
     * - Sender is not a registered frontend
     * - _amount is not zero
     * ---
     * - Triggers a MAHA issuance, based on time passed since the last issuance. The MAHA 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 (MAHA, ETH) to depositor
     * - Sends the tagged front end's accumulated MAHA gains to the tagged front end
     * - Increases deposit and tagged front end's stake, and takes new snapshots for each.
     */
    function provideToSP(uint256 _amount, address _frontEndTag) 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 MAHA issuance, based on time passed since the last issuance. The MAHA 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 (MAHA, ETH) to depositor
     * - Sends the tagged front end's accumulated MAHA 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 MAHA issuance, based on time passed since the last issuance. The MAHA issuance is shared between *all* depositors and front ends
     * - Sends all depositor's MAHA gain to  depositor
     * - Sends all tagged front end's MAHA 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 withdrawETHGainToTrove(address _upperHint, address _lowerHint) external;

    /*
     * Initial checks:
     * - Frontend (sender) not already registered
     * - User (sender) has no deposit
     * - _kickbackRate is in the range [0, 100%]
     * ---
     * Front end makes a one-time selection of kickback rate upon registering
     */
    function registerFrontEnd(uint256 _kickbackRate) external;

    /*
     * Initial checks:
     * - Caller is TroveManager
     * ---
     * Cancels out the specified debt against the ARTH 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 getETH() external view returns (uint256);

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

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

    /*
     * Calculate the MAHA 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 getDepositorMAHAGain(address _depositor) external view returns (uint256);

    /*
     * Return the MAHA gain earned by the front end.
     */
    function getFrontEndMAHAGain(address _frontEnd) external view returns (uint256);

    /*
     * Return the user's compounded deposit.
     */
    function getCompoundedARTHDeposit(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 getCompoundedFrontEndStake(address _frontEnd) external view returns (uint256);

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

File 13 of 22 : IPriceFeed.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

interface IPriceFeed {
    // --- Events ---
    event LastGoodPriceUpdated(uint256 _lastGoodPrice);

    // --- Function ---
    function fetchPrice() external returns (uint256);
}

File 14 of 22 : IGovernance.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

import "./IPriceFeed.sol";
import "../Interfaces/IERC20.sol";
import "../Interfaces/IOracle.sol";

interface IGovernance {
    event AllowMintingChanged(bool oldFlag, bool newFlag, uint256 timestamp);
    event BorrowingFeeFloorChanged(uint256 oldValue, uint256 newValue, uint256 timestamp);
    event FundAddressChanged(address oldAddress, address newAddress, uint256 timestamp);
    event MaxBorrowingFeeChanged(uint256 oldValue, uint256 newValue, uint256 timestamp);
    event MAHAChanged(address oldAddress, address newAddress, uint256 timestamp);
    event MaxDebtCeilingChanged(uint256 oldValue, uint256 newValue, uint256 timestamp);
    event PriceFeedChanged(address oldAddress, address newAddress, uint256 timestamp);
    event RedemptionFeeFloorChanged(uint256 oldValue, uint256 newValue, uint256 timestamp);
    event SentToFund(address token, uint256 amount, uint256 timestamp, string reason);

    function getAllowMinting() external view returns (bool);

    function getBorrowingFeeFloor() external view returns (uint256);

    function getDeploymentStartTime() external view returns (uint256);

    function getFund() external view returns (address);

    function getMAHA() external view returns (IERC20);

    function getGasCompensation() external view returns (uint256);

    function getMaxBorrowingFee() external view returns (uint256);

    function getMaxDebtCeiling() external view returns (uint256);

    function getMinNetDebt() external view returns (uint256);

    function getPriceFeed() external view returns (IPriceFeed);

    function getRedemptionFeeFloor() external view returns (uint256);
}

File 15 of 22 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

/**
 * Based on the OpenZeppelin IER20 interface:
 * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol
 *
 * @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);

    function increaseAllowance(address spender, uint256 addedValue) external returns (bool);

    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);

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

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

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

    function decimals() external view returns (uint8);

    /**
     * @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 16 of 22 : IOracle.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

interface IOracle {
    function getPrice() external view returns (uint256);

    function getDecimalPercision() external view returns (uint256);
}

File 17 of 22 : IERC2612.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

/**
 * @dev Interface of the ERC2612 standard as defined in the EIP.
 *
 * Adds the {permit} method, which can be used to change one's
 * {IERC20-allowance} without having to send a transaction, by signing a
 * message. This allows users to spend tokens without having to hold Ether.
 *
 * See https://eips.ethereum.org/EIPS/eip-2612.
 *
 * Code adapted from https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2237/
 */
interface IERC2612 {
    /**
     * @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.
     *
     * `owner` can limit the time a Permit is valid for by setting `deadline` to
     * a value in the near future. The deadline argument can be set to uint(-1) to
     * create Permits that effectively never expire.
     */
    function nonces(address owner) external view returns (uint256);

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

    function permitTypeHash() external view returns (bytes32);

    function domainSeparator() external view returns (bytes32);
}

File 18 of 22 : BaseMath.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;

contract BaseMath {
    uint256 public constant DECIMAL_PRECISION = 1e18;
}

File 19 of 22 : LiquityMath.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

import "./SafeMath.sol";

library LiquityMath {
    using SafeMath for uint256;

    uint256 internal constant DECIMAL_PRECISION = 1e18;

    /* 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) {
            uint256 newCollRatio = _coll.mul(_price).div(_debt);

            return newCollRatio;
        }
        // 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;
        }
    }
}

File 20 of 22 : IActivePool.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

import "./IPool.sol";

interface IActivePool is IPool {
    // --- Events ---
    event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
    event TroveManagerAddressChanged(address _newTroveManagerAddress);
    event ActivePoolARTHDebtUpdated(uint256 _ARTHDebt);
    event ActivePoolETHBalanceUpdated(uint256 _ETH);

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

File 21 of 22 : IDefaultPool.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

import "./IPool.sol";

interface IDefaultPool is IPool {
    // --- Events ---
    event TroveManagerAddressChanged(address _newTroveManagerAddress);
    event DefaultPoolARTHDebtUpdated(uint256 _ARTHDebt);
    event DefaultPoolETHBalanceUpdated(uint256 _ETH);

    // --- Functions ---
    function sendETHToActivePool(uint256 _amount) external;
}

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

pragma solidity 0.8.0;

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

    event ETHBalanceUpdated(uint256 _newBalance);
    event ARTHBalanceUpdated(uint256 _newBalance);
    event ActivePoolAddressChanged(address _newActivePoolAddress);
    event DefaultPoolAddressChanged(address _newDefaultPoolAddress);
    event StabilityPoolAddressChanged(address _newStabilityPoolAddress);
    event EtherSent(address _to, uint256 _amount);

    // --- Functions ---

    function getETH() external view returns (uint256);

    function getARTHDebt() external view returns (uint256);

    function increaseARTHDebt(uint256 _amount) external;

    function decreaseARTHDebt(uint256 _amount) external;
}

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

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"_ARTHFee","type":"uint256"}],"name":"ARTHBorrowingFeePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_arthTokenAddress","type":"address"}],"name":"ARTHTokenAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_activePoolAddress","type":"address"}],"name":"ActivePoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_collSurplusPoolAddress","type":"address"}],"name":"CollSurplusPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_defaultPoolAddress","type":"address"}],"name":"DefaultPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_frontend","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"FrontEndRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_gasPoolAddress","type":"address"}],"name":"GasPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newGovernanceAddress","type":"address"}],"name":"GovernanceAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_ecosystemFund","type":"address"},{"indexed":false,"internalType":"uint256","name":"_ARTHFee","type":"uint256"}],"name":"PaidARTHBorrowingFeeToEcosystemFund","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_frontEndTag","type":"address"},{"indexed":false,"internalType":"uint256","name":"_ARTHFee","type":"uint256"}],"name":"PaidARTHBorrowingFeeToFrontEnd","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_sortedTrovesAddress","type":"address"}],"name":"SortedTrovesAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_stabilityPoolAddress","type":"address"}],"name":"StabilityPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"arrayIndex","type":"uint256"}],"name":"TroveCreated","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":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"_debt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_coll","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stake","type":"uint256"},{"indexed":false,"internalType":"enum IBorrowerOperations.BorrowerOperation","name":"operation","type":"uint8"}],"name":"TroveUpdated","type":"event"},{"inputs":[],"name":"ARTH_GAS_COMPENSATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BORROWING_FEE_FLOOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CCR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DECIMAL_PRECISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MCR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_NET_DEBT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NAME","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERCENT_DIVISOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_100pct","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"activePool","outputs":[{"internalType":"contract IActivePool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"}],"name":"addColl","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"},{"internalType":"uint256","name":"_collWithdrawal","type":"uint256"},{"internalType":"uint256","name":"_ARTHChange","type":"uint256"},{"internalType":"bool","name":"_isDebtIncrease","type":"bool"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"}],"name":"adjustTrove","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"arthToken","outputs":[{"internalType":"contract IARTHValuecoin","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"closeTrove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"defaultPool","outputs":[{"internalType":"contract IDefaultPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fetchPriceFeedPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"frontEnds","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBorrowingFeeFloor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_debt","type":"uint256"}],"name":"getCompositeDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEntireSystemColl","outputs":[{"internalType":"uint256","name":"entireSystemColl","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEntireSystemDebt","outputs":[{"internalType":"uint256","name":"entireSystemDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxBorrowingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPriceFeed","outputs":[{"internalType":"contract IPriceFeed","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRedemptionFeeFloor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governance","outputs":[{"internalType":"contract IGovernance","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"}],"name":"moveETHGainToTrove","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"},{"internalType":"uint256","name":"_ARTHAmount","type":"uint256"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"},{"internalType":"address","name":"_frontEndTag","type":"address"}],"name":"openTrove","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"},{"internalType":"uint256","name":"_ARTHAmount","type":"uint256"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"}],"name":"openTrove","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_who","type":"address"},{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"},{"internalType":"uint256","name":"_ARTHAmount","type":"uint256"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"},{"internalType":"address","name":"_frontEndTag","type":"address"}],"name":"openTroveFor","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registerFrontEnd","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_ARTHAmount","type":"uint256"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"}],"name":"repayARTH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_troveManagerAddress","type":"address"},{"internalType":"address","name":"_activePoolAddress","type":"address"},{"internalType":"address","name":"_defaultPoolAddress","type":"address"},{"internalType":"address","name":"_stabilityPoolAddress","type":"address"},{"internalType":"address","name":"_gasPoolAddress","type":"address"},{"internalType":"address","name":"_collSurplusPoolAddress","type":"address"},{"internalType":"address","name":"_governanceAddress","type":"address"},{"internalType":"address","name":"_sortedTrovesAddress","type":"address"},{"internalType":"address","name":"_arthTokenAddress","type":"address"}],"name":"setAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sortedTroves","outputs":[{"internalType":"contract ISortedTroves","name":"","type":"address"}],"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":[{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"},{"internalType":"uint256","name":"_ARTHAmount","type":"uint256"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"}],"name":"withdrawARTH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_collWithdrawal","type":"uint256"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"}],"name":"withdrawColl","outputs":[],"stateMutability":"nonpayable","type":"function"}]

Deployed Bytecode

0x60806040526004361061023b5760003560e01c80637f7dde4a1161012e578063ae918754116100ab578063ed02ba301161006f578063ed02ba301461056b578063f2fde38b1461058b578063f3e86560146105ab578063f92d3433146105be578063ff092e69146105d35761023b565b8063ae91875414610506578063c6a6cf201461051b578063dd6807f31461052e578063deb9875814610543578063ea9638bf146105585761023b565b80638f32d59b116100f25780638f32d59b1461048d5780639e87a5cd146104af578063a20baee6146103e7578063a3f4df7e146104c4578063a7bfff97146104e65761023b565b80637f7dde4a14610426578063860665b31461043b578063887105d31461044e5780638abf30b3146104635780638da5cb5b146104785761023b565b80635aa6e675116101bc57806368647db11161018057806368647db1146103bf5780636f0b0c1c146103d257806372fe25aa146103e7578063794e5724146103fc578063795d26c3146104115761023b565b80635aa6e6751461034d5780635adf9f02146103625780635e9e321214610377578063604c6e441461038c578063662720441461039f5761023b565b80633d83908a116102035780633d83908a146102ce5780634870dd9a146102e35780634ff81443146102f85780635530273c146103185780635733d58f146103385761023b565b80630e704d50146102405780631bf43555146102575780631f0eff5a1461028257806330fa253e146102975780633cc74225146102ac575b600080fd5b34801561024c57600080fd5b506102556105f3565b005b34801561026357600080fd5b5061026c6109cb565b60405161027991906142c6565b60405180910390f35b34801561028e57600080fd5b5061026c610a58565b3480156102a357600080fd5b50610255610b2e565b3480156102b857600080fd5b506102c1610ba1565b60405161027991906138f3565b3480156102da57600080fd5b506102c1610bb0565b3480156102ef57600080fd5b5061026c610bbf565b34801561030457600080fd5b5061026c610313366004613799565b610bc5565b34801561032457600080fd5b506102556103333660046137c9565b610bd6565b34801561034457600080fd5b5061026c610bec565b34801561035957600080fd5b506102c1610bf8565b34801561036e57600080fd5b506102c1610c07565b34801561038357600080fd5b5061026c610c16565b61025561039a366004613838565b610c66565b3480156103ab57600080fd5b506102556103ba366004613653565b610c7c565b6102556103cd3660046135d1565b610fa0565b3480156103de57600080fd5b50610255610fb6565b3480156103f357600080fd5b5061026c61101a565b34801561040857600080fd5b5061026c611026565b34801561041d57600080fd5b5061026c611032565b34801561043257600080fd5b506102c1611158565b6102556104493660046137ef565b611167565b34801561045a57600080fd5b5061026c611177565b34801561046f57600080fd5b5061026c611252565b34801561048457600080fd5b506102c16112a2565b34801561049957600080fd5b506104a26112b1565b6040516102799190613965565b3480156104bb57600080fd5b506102c16112c2565b3480156104d057600080fd5b506104d961134a565b6040516102799190613992565b3480156104f257600080fd5b506104a2610501366004613599565b611378565b34801561051257600080fd5b506102c161138d565b610255610529366004613896565b61139c565b34801561053a57600080fd5b5061026c6113b3565b34801561054f57600080fd5b5061026c611403565b610255610566366004613609565b611453565b34801561057757600080fd5b506102556105863660046137ef565b61146d565b34801561059757600080fd5b506102556105a6366004613599565b61147e565b6102556105b936600461370e565b6114d4565b3480156105ca57600080fd5b5061026c611507565b3480156105df57600080fd5b506102556105ee3660046137c9565b611511565b600654600254600a546001600160a01b039283169291821691166106178333611523565b60006106216112c2565b6001600160a01b0316630fdb11cf6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561065b57600080fd5b505af115801561066f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061069391906137b1565b905061069e816115c4565b604051630b07655760e01b81526001600160a01b03851690630b076557906106ca9033906004016138f3565b600060405180830381600087803b1580156106e457600080fd5b505af11580156106f8573d6000803e3d6000fd5b50506040516309019aaf60e31b8152600092506001600160a01b038716915063480cd5789061072b9033906004016138f3565b60206040518083038186803b15801561074357600080fd5b505afa158015610757573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061077b91906137b1565b90506000856001600160a01b031663d66a2553336040518263ffffffff1660e01b81526004016107ab91906138f3565b60206040518083038186803b1580156107c357600080fd5b505afa1580156107d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107fb91906137b1565b9050610819843361081461080d611403565b85906115ea565b611633565b600061082a836000846000886116cf565b905061083581611744565b604051631fc5750960e31b81526001600160a01b0388169063fe2ba848906108619033906004016138f3565b600060405180830381600087803b15801561087b57600080fd5b505af115801561088f573d6000803e3d6000fd5b50506040516365e89c5760e11b81526001600160a01b038a16925063cbd138ae91506108bf9033906004016138f3565b600060405180830381600087803b1580156108d957600080fd5b505af11580156108ed573d6000803e3d6000fd5b50505050336001600160a01b0316600080516020614377833981519152600080600060016040516109219493929190613970565b60405180910390a261094686863361094161093a611403565b87906115ea565b61176c565b60085461096290879087906001600160a01b0316610941611403565b6040516364a197f360e01b81526001600160a01b038716906364a197f3906109909033908790600401613921565b600060405180830381600087803b1580156109aa57600080fd5b505af11580156109be573d6000803e3d6000fd5b5050505050505050505050565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663c4dc70d36040518163ffffffff1660e01b815260040160206040518083038186803b158015610a1b57600080fd5b505afa158015610a2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5391906137b1565b905090565b6000600460009054906101000a90046001600160a01b03166001600160a01b0316639e87a5cd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610aa857600080fd5b505afa158015610abc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae091906135b5565b6001600160a01b0316630fdb11cf6040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610b1a57600080fd5b505af1158015610a2f573d6000803e3d6000fd5b610b3733611830565b600654610b4d906001600160a01b031633611869565b336000818152600c602052604090819020805460ff19166001179055517f19bc932fb9e16a8b5a1e41be9f4c2de59d5ddd7567b8b81405f532ca00a9880e90610b979042906142c6565b60405180910390a2565b6003546001600160a01b031681565b6006546001600160a01b031681565b60015481565b6000610bd08261190b565b92915050565b610be733846000808686600061191f565b505050565b6714d1120d7b16000081565b6004546001600160a01b031681565b600a546001600160a01b031681565b6000600460009054906101000a90046001600160a01b03166001600160a01b0316635e9e32126040518163ffffffff1660e01b815260040160206040518083038186803b158015610a1b57600080fd5b610c7533338787878787611f76565b5050505050565b610c846112b1565b610ca95760405162461bcd60e51b8152600401610ca090613e64565b60405180910390fd5b610cb289612624565b610cbb88612624565b610cc487612624565b610ccd86612624565b610cd685612624565b610cdf84612624565b610ce883612624565b610cf182612624565b610cfa81612624565b600680546001600160a01b03199081166001600160a01b038c8116919091179092556002805482168b84161790556003805482168a8416179055600780548216898416179055600880548216888416179055600980548216878416179055600480548216868416179055600b80548216858416179055600a80549091169183169190911790556040517f143219c9e69b09e07e095fcc889b43d8f46ca892bba65f08dc3a0050869a567890610db0908b906138f3565b60405180910390a17f78f058b189175430c48dc02699e3a0031ea4ff781536dc2fab847de4babdd88288604051610de791906138f3565b60405180910390a17f5ee0cae2f063ed938bb55046f6a932fb6ae792bf43624806bb90abe68a50be9b87604051610e1e91906138f3565b60405180910390a17f82966d27eea39b038ee0fa30cd16532bb24f6e65d31cb58fb227aa5766cdcc7f86604051610e5591906138f3565b60405180910390a17fcfb07d791fcafc032b35837b50eb84b74df518cf4cc287e8084f47630fa70fa085604051610e8c91906138f3565b60405180910390a17fe67f36a6e961157d6eff83b91f3af5a62131ceb6f04954ef74f51c1c05e7f88d84604051610ec391906138f3565b60405180910390a17fa29a633a0eef2d1151c7c3b24a4f75c7c7a3b8a7eee6b54f75b7b168f1c87fec83604051610efa91906138f3565b60405180910390a17f65f4cf077bc01e4742eb5ad98326f6e95b63548ea24b17f8d5e823111fe7880082604051610f3191906138f3565b60405180910390a17fee2dd37297bcc1fafd4464593925da4b21410aced67b01f488a50a817773615b81604051610f6891906138f3565b60405180910390a16000610f7a6109cb565b11610f9557634e487b7160e01b600052600160045260246000fd5b505050505050505050565b610fb23360008060008686600061191f565b5050565b60095460405163b32beb5b60e01b81526001600160a01b039091169063b32beb5b90610fe69033906004016138f3565b600060405180830381600087803b15801561100057600080fd5b505af1158015611014573d6000803e3d6000fd5b50505050565b670de0b6b3a764000081565b670f43fc2c04ee000081565b600080600260009054906101000a90046001600160a01b03166001600160a01b03166372cc6c4a6040518163ffffffff1660e01b815260040160206040518083038186803b15801561108357600080fd5b505afa158015611097573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110bb91906137b1565b90506000600360009054906101000a90046001600160a01b03166001600160a01b03166372cc6c4a6040518163ffffffff1660e01b815260040160206040518083038186803b15801561110d57600080fd5b505afa158015611121573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114591906137b1565b90506111518282612669565b9250505090565b6002546001600160a01b031681565b6110143333868686866000611f76565b600080600260009054906101000a90046001600160a01b03166001600160a01b03166314f6c3be6040518163ffffffff1660e01b815260040160206040518083038186803b1580156111c857600080fd5b505afa1580156111dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061120091906137b1565b90506000600360009054906101000a90046001600160a01b03166001600160a01b03166314f6c3be6040518163ffffffff1660e01b815260040160206040518083038186803b15801561110d57600080fd5b6000600460009054906101000a90046001600160a01b03166001600160a01b0316638abf30b36040518163ffffffff1660e01b815260040160206040518083038186803b158015610a1b57600080fd5b6005546001600160a01b031690565b6005546001600160a01b0316331490565b6000600460009054906101000a90046001600160a01b03166001600160a01b0316639e87a5cd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561131257600080fd5b505afa158015611326573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5391906135b5565b60405180604001604052806012815260200171426f72726f7765724f7065726174696f6e7360701b81525081565b600c6020526000908152604090205460ff1681565b600b546001600160a01b031681565b6113ab3386868686868c61191f565b505050505050565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663dd6807f36040518163ffffffff1660e01b815260040160206040518083038186803b158015610a1b57600080fd5b6000600460009054906101000a90046001600160a01b03166001600160a01b031663695b2e346040518163ffffffff1660e01b815260040160206040518083038186803b158015610a1b57600080fd5b61145b612698565b610be78360008060008686600061191f565b61101433600085600186868a61191f565b6114866112b1565b6114a25760405162461bcd60e51b8152600401610ca090613e64565b6001600160a01b0381166114c85760405162461bcd60e51b8152600401610ca090613ada565b6114d1816126c4565b50565b6114dc6112b1565b6114f85760405162461bcd60e51b8152600401610ca090613e64565b6113ab86338787878787611f76565b6000610a53610c16565b610be73360008560008686600061191f565b6040516321e3780160e01b81526000906001600160a01b038416906321e37801906115529085906004016138f3565b60206040518083038186803b15801561156a57600080fd5b505afa15801561157e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115a291906137b1565b905080600114610be75760405162461bcd60e51b8152600401610ca090613e99565b6115cd81612716565b156114d15760405162461bcd60e51b8152600401610ca090613ba7565b600061162c83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612733565b9392505050565b6040516370a0823160e01b815281906001600160a01b038516906370a08231906116619086906004016138f3565b60206040518083038186803b15801561167957600080fd5b505afa15801561168d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116b191906137b1565b1015610be75760405162461bcd60e51b8152600401610ca0906139e5565b6000806116da611177565b905060006116e6611032565b9050866116fc576116f782896115ea565b611706565b6117068289612669565b91508461171c5761171781876115ea565b611726565b6117268187612669565b90506000611735838387612764565b93505050505b95945050505050565b6714d1120d7b1600008110156114d15760405162461bcd60e51b8152600401610ca090613df5565b604051631c4ebc8560e21b81526001600160a01b0385169063713af214906117989084906004016142c6565b600060405180830381600087803b1580156117b257600080fd5b505af11580156117c6573d6000803e3d6000fd5b5050604051632770a7eb60e21b81526001600160a01b0386169250639dc29fac91506117f89085908590600401613921565b600060405180830381600087803b15801561181257600080fd5b505af1158015611826573d6000803e3d6000fd5b5050505050505050565b6001600160a01b0381166000908152600c602052604090205460ff16156114d15760405162461bcd60e51b8152600401610ca090613ee7565b6040516321e3780160e01b81526000906001600160a01b038416906321e37801906118989085906004016138f3565b60206040518083038186803b1580156118b057600080fd5b505afa1580156118c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118e891906137b1565b90508060011415610be75760405162461bcd60e51b8152600401610ca0906141a4565b6000610bd0611918611403565b8390612669565b604080516060810182526006546001600160a01b03908116825260025481166020830152600a5416918101919091526119566134ea565b61195e6112c2565b6001600160a01b0316630fdb11cf6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561199857600080fd5b505af11580156119ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119d091906137b1565b8082526000906119df90612716565b905086156119fa576119f18482612794565b6119fa88612802565b611a0389612822565b611a0d8989612849565b8251611a19908b611523565b336001600160a01b038b161480611a4f57506007546001600160a01b031633148015611a455750600034115b8015611a4f575087155b611a6957634e487b7160e01b600052600160045260246000fd5b8251604051630b07655760e01b81526001600160a01b0390911690630b07655790611a98908d906004016138f3565b600060405180830381600087803b158015611ab257600080fd5b505af1158015611ac6573d6000803e3d6000fd5b50505050611ad4348a61287c565b15156060840152602083015260408201889052868015611af2575080155b15611bab57825160405163309e8ebb60e01b81526000916001600160a01b03169063309e8ebb90611b27908e906004016138f3565b60206040518083038186803b158015611b3f57600080fd5b505afa158015611b53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b7791906135b5565b9050611b8e846000015185604001518b888561289b565b61012084018190526040840151611ba491612669565b6040840152505b825160405163d66a255360e01b81526001600160a01b039091169063d66a255390611bda908d906004016138f3565b60206040518083038186803b158015611bf257600080fd5b505afa158015611c06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c2a91906137b1565b608083015282516040516309019aaf60e31b81526001600160a01b039091169063480cd57890611c5e908d906004016138f3565b60206040518083038186803b158015611c7657600080fd5b505afa158015611c8a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cae91906137b1565b60a0830181905260808301518351611cc7929190612764565b8260c0018181525050611cf78260a0015183608001518460200151856060015186604001518c8860000151612a6b565b60e083015260a0820151891115611d1e57634e487b7160e01b600052600160045260246000fd5b611d2a818a8985612a9e565b86158015611d385750600088115b15611d8557611d60611d5b8360400151611d558560800151612b12565b906115ea565b612b26565b611d7282608001518360400151612b4d565b611d8583604001518b8460400151611633565b611da383600001518b8460200151856060015186604001518c612b77565b6101408401526101608301528251604051630c7940bd60e11b81526001600160a01b03909116906318f2817a90611dde908d906004016138f3565b602060405180830381600087803b158015611df857600080fd5b505af1158015611e0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e3091906137b1565b826101800181815250506000611e5e8360a0015184608001518560200151866060015187604001518d612da5565b600b5460405163015f109360e51b81529192506001600160a01b031690632be2126090611e95908e9085908c908c9060040161393a565b600060405180830381600087803b158015611eaf57600080fd5b505af1158015611ec3573d6000803e3d6000fd5b505050508a6001600160a01b03166000805160206143778339815191528461014001518561016001518661018001516002604051611f049493929190613970565b60405180910390a2336001600160a01b03167f326c11ff2ef4a04ee98a255113c7289b3a3824737f9980376eedbdeaa48f2fc5846101200151604051611f4a91906142c6565b60405180910390a26109be8460200151856040015133866020015187606001518e8e8a60400151612dd6565b611f7f81612e79565b611f8887611830565b604080516060810182526006546001600160a01b03908116825260025481166020830152600a541691810191909152611fbf613554565b611fc76112c2565b6001600160a01b0316630fdb11cf6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561200157600080fd5b505af1158015612015573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061203991906137b1565b80825260009061204890612716565b90506120548882612794565b8251612060908b611869565b604082018790528061209c5761208183600001518460400151898b8861289b565b60208301819052604083015161209691612669565b60408301525b6120a98260400151612b26565b6120b6826040015161190b565b606083018190526120d757634e487b7160e01b600052600160045260246000fd5b6120ea3483606001518460000151612764565b608083015260608201516120ff903490612ec3565b60a0830152801561211c576121178260800151612ef2565b61214f565b6121298260800151612f1a565b60006121423460018560600151600187600001516116cf565b905061214d81611744565b505b8251604051621e91c760e11b81526001600160a01b0390911690623d238e9061217e908d908890600401613907565b600060405180830381600087803b15801561219857600080fd5b505af11580156121ac573d6000803e3d6000fd5b50508451604051635d6b480f60e01b81526001600160a01b039091169250635d6b480f91506121e2908d90600190600401613921565b600060405180830381600087803b1580156121fc57600080fd5b505af1158015612210573d6000803e3d6000fd5b505084516040516372423c1760e01b81526001600160a01b0390911692506372423c179150612245908d903490600401613921565b602060405180830381600087803b15801561225f57600080fd5b505af1158015612273573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061229791906137b1565b5082516060830151604051639976cf4560e01b81526001600160a01b0390921691639976cf45916122cd918e9190600401613921565b602060405180830381600087803b1580156122e757600080fd5b505af11580156122fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231f91906137b1565b5082516040516382fe3eb960e01b81526001600160a01b03909116906382fe3eb99061234f908d906004016138f3565b600060405180830381600087803b15801561236957600080fd5b505af115801561237d573d6000803e3d6000fd5b50508451604051630c7940bd60e11b81526001600160a01b0390911692506318f2817a91506123b0908d906004016138f3565b602060405180830381600087803b1580156123ca57600080fd5b505af11580156123de573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061240291906137b1565b60c0830152600b5460a08301516040516346f7cf8760e01b81526001600160a01b03909216916346f7cf8791612441918e91908b908b9060040161393a565b600060405180830381600087803b15801561245b57600080fd5b505af115801561246f573d6000803e3d6000fd5b505084516040516315d549f160e01b81526001600160a01b0390911692506315d549f191506124a2908d906004016138f3565b602060405180830381600087803b1580156124bc57600080fd5b505af11580156124d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124f491906137b1565b60e083018190526040516001600160a01b038c16917f59cfd0cd754bc5748b6770e94a4ffa5f678d885cb899dcfadc5734edb97c67ab9161253591906142c6565b60405180910390a261254b836020015134612f42565b612564836020015184604001518b8a8660400151612fbe565b602083015160408401516008546125959291906001600160a01b0316612588611403565b612590611403565b612fbe565b896001600160a01b03166000805160206143778339815191528360600151348560c0015160006040516125cb9493929190613970565b60405180910390a2896001600160a01b03167f326c11ff2ef4a04ee98a255113c7289b3a3824737f9980376eedbdeaa48f2fc5836020015160405161261091906142c6565b60405180910390a250505050505050505050565b6001600160a01b03811661264a5760405162461bcd60e51b8152600401610ca090613cbf565b803b80610fb25760405162461bcd60e51b8152600401610ca09061406d565b60008061267683856142cf565b90508381101561162c5760405162461bcd60e51b8152600401610ca090613b20565b6007546001600160a01b031633146126c25760405162461bcd60e51b8152600401610ca09061410b565b565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008061272283613222565b6714d1120d7b160000119392505050565b600081848411156127575760405162461bcd60e51b8152600401610ca09190613992565b50600061173b8486614326565b6000821561278b5760006127828461277c878661324e565b90613293565b915061162c9050565b5060001961162c565b80156127c757670de0b6b3a76400008211156127c25760405162461bcd60e51b8152600401610ca090613cf6565b610fb2565b6127cf610c16565b82101580156127e65750670de0b6b3a76400008211155b610fb25760405162461bcd60e51b8152600401610ca090614154565b600081116114d15760405162461bcd60e51b8152600401610ca0906141db565b34158061282d575080155b6114d15760405162461bcd60e51b8152600401610ca090613b57565b3415158061285657508115155b8061286057508015155b610fb25760405162461bcd60e51b8152600401610ca090613d48565b600080831561289057508290506001612894565b8291505b9250929050565b6000856001600160a01b0316635dba4c4a6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156128d857600080fd5b505af11580156128ec573d6000803e3d6000fd5b5050604051630631203b60e41b8152600092506001600160a01b038916915063631203b09061291f9088906004016142c6565b60206040518083038186803b15801561293757600080fd5b505afa15801561294b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061296f91906137b1565b905061297c8186866132d5565b8015612a6157806001600160a01b03841615612a55576129a2606461277c84603261324e565b905060006129b083836115ea565b9050846001600160a01b03167ffed03c45e8151e65ee9a346a9b86ae77f8cf7308cfaa694f9bf25f658bdf590b826040516129eb91906142c6565b60405180910390a26040516340c10f1960e01b81526001600160a01b038916906340c10f1990612a219088908590600401613921565b600060405180830381600087803b158015612a3b57600080fd5b505af1158015612a4f573d6000803e3d6000fd5b50505050505b612a5f878261330f565b505b9695505050505050565b6000806000612a7e8a8a8a8a8a8a613440565b915091506000612a8f838387612764565b9b9a5050505050505050505050565b8315612ad757612aad8361347e565b8115612ad257612ac08160e00151612ef2565b612ad28160e001518260c0015161349c565b611014565b612ae48160e00151612f1a565b612b018160200151826060015183604001518585600001516116cf565b610100820181905261101490611744565b6000610bd0612b1f611403565b83906115ea565b612b2e6109cb565b8110156114d15760405162461bcd60e51b8152600401610ca090614010565b612b58612b1f611403565b811115610fb25760405162461bcd60e51b8152600401610ca0906140a2565b600080600085612c065760405163d3d6f84360e01b81526001600160a01b038a169063d3d6f84390612baf908b908b90600401613921565b602060405180830381600087803b158015612bc957600080fd5b505af1158015612bdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c0191906137b1565b612c86565b6040516372423c1760e01b81526001600160a01b038a16906372423c1790612c34908b908b90600401613921565b602060405180830381600087803b158015612c4e57600080fd5b505af1158015612c62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c8691906137b1565b9050600084612d1457604051630930874960e11b81526001600160a01b038b16906312610e9290612cbd908c908a90600401613921565b602060405180830381600087803b158015612cd757600080fd5b505af1158015612ceb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d0f91906137b1565b612d94565b604051639976cf4560e01b81526001600160a01b038b1690639976cf4590612d42908c908a90600401613921565b602060405180830381600087803b158015612d5c57600080fd5b505af1158015612d70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d9491906137b1565b919a91995090975050505050505050565b6000806000612db8898989898989613440565b915091506000612dc88383612ec3565b9a9950505050505050505050565b8115612dee57612de98888888685612fbe565b612dfa565b612dfa8888888661176c565b8315612e0f57612e0a8886612f42565b611826565b6040516364a197f360e01b81526001600160a01b038916906364a197f390612e3d9089908990600401613921565b600060405180830381600087803b158015612e5757600080fd5b505af1158015612e6b573d6000803e3d6000fd5b505050505050505050505050565b6001600160a01b0381166000908152600c602052604090205460ff1680612ea757506001600160a01b038116155b6114d15760405162461bcd60e51b8152600401610ca090613c00565b60008115612ee957612ee28261277c8568056bc75e2d6310000061324e565b9050610bd0565b50600019610bd0565b6714d1120d7b1600008110156114d15760405162461bcd60e51b8152600401610ca090613c68565b670f43fc2c04ee00008110156114d15760405162461bcd60e51b8152600401610ca090613fa1565b6000826001600160a01b031682604051612f5b906138f0565b60006040518083038185875af1925050503d8060008114612f98576040519150601f19603f3d011682016040523d82523d6000602084013e612f9d565b606091505b5050905080610be75760405162461bcd60e51b8152600401610ca090613a6b565b6004805460408051635e71c0bb60e11b815290516001600160a01b039092169263bce38176928282019260209290829003018186803b15801561300057600080fd5b505afa158015613014573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061303891906137b1565b82866001600160a01b03166372cc6c4a6040518163ffffffff1660e01b815260040160206040518083038186803b15801561307257600080fd5b505afa158015613086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130aa91906137b1565b6130b491906142cf565b11156130d25760405162461bcd60e51b8152600401610ca090613a42565b600480546040805163411cb36360e01b815290516001600160a01b039092169263411cb363928282019260209290829003018186803b15801561311457600080fd5b505afa158015613128573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061314c919061377d565b6131685760405162461bcd60e51b8152600401610ca090613ab8565b604051631fe2964960e11b81526001600160a01b03861690633fc52c92906131949084906004016142c6565b600060405180830381600087803b1580156131ae57600080fd5b505af11580156131c2573d6000803e3d6000fd5b50506040516340c10f1960e01b81526001600160a01b03871692506340c10f1991506131f49086908690600401613921565b600060405180830381600087803b15801561320e57600080fd5b505af1158015610f95573d6000803e3d6000fd5b60008061322d611177565b90506000613239611032565b9050613246828286612764565b949350505050565b60008261325d57506000610bd0565b60006132698385614307565b90508261327685836142e7565b1461162c5760405162461bcd60e51b8152600401610ca090613db4565b600061162c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506134bc565b60006132ed8361277c86670de0b6b3a764000061324e565b9050818111156110145760405162461bcd60e51b8152600401610ca09061428f565b6000600460009054906101000a90046001600160a01b03166001600160a01b0316638edd6eb66040518163ffffffff1660e01b815260040160206040518083038186803b15801561335f57600080fd5b505afa158015613373573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061339791906135b5565b6040516340c10f1960e01b81529091506001600160a01b038416906340c10f19906133c89084908690600401613921565b600060405180830381600087803b1580156133e257600080fd5b505af11580156133f6573d6000803e3d6000fd5b50505050806001600160a01b03167f50bd35d55fd6cbd52adfe7fbaadf510d3ce0257068bb691cc5bad531a46de35f8360405161343391906142c6565b60405180910390a2505050565b600080878786613459576134548a896115ea565b613463565b6134638a89612669565b91508461347457612d0f89876115ea565b612d948987612669565b80156114d15760405162461bcd60e51b8152600401610ca090613f44565b80821015610fb25760405162461bcd60e51b8152600401610ca090614232565b600081836134dd5760405162461bcd60e51b8152600401610ca09190613992565b50600061173b84866142e7565b604051806101a001604052806000815260200160008152602001600081526020016000151581526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b60405180610100016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6000602082840312156135aa578081fd5b813561162c81614353565b6000602082840312156135c6578081fd5b815161162c81614353565b600080604083850312156135e3578081fd5b82356135ee81614353565b915060208301356135fe81614353565b809150509250929050565b60008060006060848603121561361d578081fd5b833561362881614353565b9250602084013561363881614353565b9150604084013561364881614353565b809150509250925092565b60008060008060008060008060006101208a8c031215613671578485fd5b893561367c81614353565b985060208a013561368c81614353565b975060408a013561369c81614353565b965060608a01356136ac81614353565b955060808a01356136bc81614353565b945060a08a01356136cc81614353565b935060c08a01356136dc81614353565b925060e08a01356136ec81614353565b91506101008a01356136fd81614353565b809150509295985092959850929598565b60008060008060008060c08789031215613726578182fd5b863561373181614353565b95506020870135945060408701359350606087013561374f81614353565b9250608087013561375f81614353565b915060a087013561376f81614353565b809150509295509295509295565b60006020828403121561378e578081fd5b815161162c81614368565b6000602082840312156137aa578081fd5b5035919050565b6000602082840312156137c2578081fd5b5051919050565b6000806000606084860312156137dd578283fd5b83359250602084013561363881614353565b60008060008060808587031215613804578384fd5b8435935060208501359250604085013561381d81614353565b9150606085013561382d81614353565b939692955090935050565b600080600080600060a0868803121561384f578283fd5b8535945060208601359350604086013561386881614353565b9250606086013561387881614353565b9150608086013561388881614353565b809150509295509295909350565b60008060008060008060c087890312156138ae578384fd5b863595506020870135945060408701359350606087013561374f81614368565b600381106138ec57634e487b7160e01b600052602160045260246000fd5b9052565b90565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03948516815260208101939093529083166040830152909116606082015260800190565b901515815260200190565b84815260208101849052604081018390526080810161173b60608301846138ce565b6000602080835283518082850152825b818110156139be578581018301518582016040015282016139a2565b818111156139cf5783604083870101525b50601f01601f1916929092016040019392505050565b6020808252603d908201527f426f72726f7765724f70733a2043616c6c657220646f65736e7420686176652060408201527f656e6f756768204152544820746f206d616b652072657061796d656e74000000606082015260800190565b6020808252600f908201526e1b5a5b9d080f881b585e081919589d608a1b604082015260600190565b6020808252602d908201527f426f72726f7765724f70733a2053656e64696e672045544820746f204163746960408201526c1d99541bdbdb0819985a5b1959609a1b606082015260800190565b602080825260089082015267216d696e74696e6760c01b604082015260600190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b60208082526030908201527f426f72726f7765724f7065726174696f6e733a2043616e6e6f7420776974686460408201526f1c985dc8185b99081859190818dbdb1b60821b606082015260800190565b60208082526039908201527f426f72726f7765724f70733a204f7065726174696f6e206e6f74207065726d696040820152787474656420647572696e67205265636f76657279204d6f646560381b606082015260800190565b60208082526042908201527f426f72726f7765724f7065726174696f6e733a20546167206d7573742062652060408201527f6120726567697374657265642066726f6e7420656e642c206f72207468652030606082015261078360f41b608082015260a00190565b60208082526037908201527f426f72726f7765724f70733a204f7065726174696f6e206d757374206c65617660408201527632903a3937bb32903bb4ba341024a1a9101f1e9021a1a960491b606082015260800190565b6020808252601e908201527f4163636f756e742063616e6e6f74206265207a65726f20616464726573730000604082015260600190565b60208082526032908201527f4d6178206665652070657263656e74616765206d757374206c657373207468616040820152716e206f7220657175616c20746f203130302560701b606082015260800190565b60208082526046908201527f426f72726f7765724f70733a205468657265206d75737420626520656974686560408201527f72206120636f6c6c61746572616c206368616e6765206f7220612064656274206060820152656368616e676560d01b608082015260a00190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526049908201527f426f72726f7765724f70733a20416e206f7065726174696f6e2074686174207760408201527f6f756c6420726573756c7420696e20544352203c20434352206973206e6f74206060820152681c195c9b5a5d1d195960ba1b608082015260a00190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252602e908201527f426f72726f7765724f70733a2054726f766520646f6573206e6f74206578697360408201526d1d081bdc881a5cc818db1bdcd95960921b606082015260800190565b6020808252603e908201527f426f72726f7765724f7065726174696f6e733a204d757374206e6f7420616c7260408201527f65616479206265206120726567697374657265642066726f6e7420656e640000606082015260800190565b6020808252603e908201527f426f72726f7765724f70733a20436f6c6c61746572616c20776974686472617760408201527f616c206e6f74207065726d6974746564205265636f76657279204d6f64650000606082015260800190565b60208082526049908201527f426f72726f7765724f70733a20416e206f7065726174696f6e2074686174207760408201527f6f756c6420726573756c7420696e20494352203c204d4352206973206e6f74206060820152681c195c9b5a5d1d195960ba1b608082015260a00190565b6020808252603a908201527f426f72726f7765724f70733a2054726f76652773206e65742064656274206d7560408201527f73742062652067726561746572207468616e206d696e696d756d000000000000606082015260800190565b6020808252818101527f4163636f756e7420636f64652073697a652063616e6e6f74206265207a65726f604082015260600190565b60208082526043908201527f426f72726f7765724f70733a20416d6f756e7420726570616964206d7573742060408201527f6e6f74206265206c6172676572207468616e207468652054726f76652773206460608201526219589d60ea1b608082015260a00190565b60208082526029908201527f426f72726f7765724f70733a2043616c6c6572206973206e6f742053746162696040820152681b1a5d1e48141bdbdb60ba1b606082015260800190565b60208082526030908201527f4d6178206665652070657263656e74616765206d75737420626520626574776560408201526f656e20302e352520616e64203130302560801b606082015260800190565b6020808252601c908201527f426f72726f7765724f70733a2054726f76652069732061637469766500000000604082015260600190565b60208082526037908201527f426f72726f7765724f70733a204465627420696e637265617365207265717569604082015276726573206e6f6e2d7a65726f20646562744368616e676560481b606082015260800190565b6020808252603e908201527f426f72726f7765724f70733a2043616e6e6f7420646563726561736520796f7560408201527f722054726f766527732049435220696e205265636f76657279204d6f64650000606082015260800190565b6020808252601d908201527f4665652065786365656465642070726f7669646564206d6178696d756d000000604082015260600190565b90815260200190565b600082198211156142e2576142e261433d565b500190565b60008261430257634e487b7160e01b81526012600452602481fd5b500490565b60008160001904831182151516156143215761432161433d565b500290565b6000828210156143385761433861433d565b500390565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146114d157600080fd5b80151581146114d157600080fdfec3770d654ed33aeea6bf11ac8ef05d02a6a04ed4686dd2f624d853bbec43cc8ba264697066735822122068382eeecb9a987cc61879bb25c86fa7224d559474f3d9f4453a30e903304ae464736f6c63430008000033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

OVERVIEW

A helper contract that handles opening, adjusting and closing loans

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.