Contract 0x477d189178011a16324947e9efdf9fb4747be57a

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x0bf19860f4078e96093c5caaac45a0b647175fd2023a4370a0da2da90e85ada80x60a0604024413122021-10-22 6:26:47401 days 18 hrs ago0x420220b72bbd307db8615e7aa0eadca399cf2fc0 IN  Create: PCT0 ETH0.084730951441 ETH
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x2f383f34ca86fe2dbbc4e1b229ef121e694c0bebe3b0b562917a51b2860df139405111772022-11-23 10:03:394 days 14 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x7086ee40bc2f9b4a9deab818a68bba30814ccc053160083b37e76268c9bc2ee1404942292022-11-23 8:47:404 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x704296ba27e11753c60c1427af85a777ae8f6b92913608078dbb380fb8f7da8c404932112022-11-23 8:42:584 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x5ba1a02ee7a7bb03502598f93c4e68988d043594c8a18401c39a021821681a17404930472022-11-23 8:42:154 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x27694071ae8a61bd91cabc5e6271098ae30095bd0be7f2b9a5c860609e4d8b2e404920242022-11-23 8:37:454 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x1d25db07aaa83e2c5ada23f584e426b83a36bbf0de8b48fdbafc7ddd84d9ffb1404901282022-11-23 8:29:124 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x5bf3f91fbb0aa10e2325eaf1587aeb4aec0f2595c6f03101f98d41de0623dcdc404237542022-11-23 2:58:364 days 21 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0xed530d1b479560bd12623b49399ddcd4906103a4e6bd9309e129f1c6eddd828d401479052022-11-22 5:21:395 days 19 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x725fa9ceb9c11f39d148c1baa90968589abb30a775a8f18d5b624d01d63157d6400382992022-11-21 19:35:306 days 5 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x725fa9ceb9c11f39d148c1baa90968589abb30a775a8f18d5b624d01d63157d6400382992022-11-21 19:35:306 days 5 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x14f0e10d7377daed707d9deae1da7de446257c990728f625747421b1bef50dc0399257902022-11-21 11:26:186 days 13 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x398dd78ed1666306095c20db48c59301b6a12b17fdd1ba73ab18fbc48d1aed90399127012022-11-21 10:30:046 days 14 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x0a8782996b1bcc0f9fc0887e31edc6bbcf4341c04df95bc37d35fceed1a35345399125632022-11-21 10:29:286 days 14 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x79e8fc69585983263a9173d8baf546f19a3af99c5511a7da8da6b0f4b9783d95399118882022-11-21 10:26:296 days 14 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x11689aefe772365ef40eef6d6f78fcb1fbd51f169c6c37616d775729b72f8a29399045622022-11-21 9:55:046 days 14 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x319734bfdb7169782e41791db7306473480ef69ab83668ee5ac51488a376cde9399031602022-11-21 9:49:126 days 14 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x49a25f026ae4292c4be06769eb15b3ba49eb19ad55a4a72cdcfede46521a645f399030152022-11-21 9:48:366 days 14 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x9767da239ee4e180985124a2a9cbc4ea7841a560020e232ea08ca569d89c38cc399029102022-11-21 9:48:096 days 15 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0xe9b672d9349a82aed9e9902c8ad836944b932617c7970167713279cdba0002f4398864992022-11-21 8:37:586 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0xadaaed7bcb930d908305611639dad488e5cf98f87f2ce753cedd6b947123ebf5398854402022-11-21 8:33:326 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x96404bbf3674bce4afdb778f6c16381cc3e317cf226d225181aa925afbd95849398853642022-11-21 8:33:136 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x9095bb8d79b8ff1e44dfc247443aa5f39207710fb21253ace421caaf47b5eac3398846192022-11-21 8:30:026 days 16 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0xb0d3a48dcb27e72c36db283e681160ea3bc83dc478678a0d62d6ce1f91a70ab5383796842022-11-15 19:53:1212 days 4 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0xeae3d1de31223233e8f7c3665e7a5a9e77a49bb524a43d6acb44f4565805506d378460812022-11-13 20:02:4514 days 4 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
0x7e2b037e44e1a0c111a1e204cfd81a0b55c522b9c97552a90f85883e0b2c5865374194952022-11-12 6:10:3915 days 18 hrs ago 0x1746d5ec61c65b965dc8b4d66f3bcdb3b7f49608 0x477d189178011a16324947e9efdf9fb4747be57a0 ETH
[ Download CSV Export 
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
PCT

Compiler Version
v0.8.3+commit.8d00100c

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 20 : PCT.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../interfaces/Bank/IHandle.sol";
import "../interfaces/Bank/ITreasury.sol";
import "../interfaces/Bank/IPCT.sol";
import "../interfaces/Bank/IPCTProtocolInterface.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./HandlePausable.sol";

/**
 * @dev Implements a scalable pool for keeping track of user collateral shares
        and an interface to interact with bridges to external investment
        protocols.
 */
contract PCT is
    IPCT,
    Initializable,
    UUPSUpgradeable,
    HandlePausable,
    OwnableUpgradeable,
    ReentrancyGuardUpgradeable
{
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    string internal constant notAnInterface = "PCT: not an interface";
    string internal constant accessDenied = "PCT: access denied";

    /** @dev The Handle contract interface */
    IHandle private handle;
    /** @dev The Treasury contract interface */
    ITreasury private treasury;

    /** @dev mapping(collateral => PCT pool data) */
    mapping(address => Pool) private pools;
    /** @dev Ratio of accrued interest sent to protocol, where 1 ETH = 100% */
    uint256 public override protocolFee;

    modifier validInterface(address collateralToken, address pia) {
        require(pools[collateralToken].protocolInterfaces[pia], notAnInterface);
        _;
    }

    /** @dev Proxy initialisation function */
    function initialize() public initializer {
        __Ownable_init();
        __ReentrancyGuard_init();
    }

    receive() external payable {}

    /**
     * @dev Setter for Handle contract reference
     * @param _handle The Handle contract address
     */
    function setHandleContract(address _handle) public override onlyOwner {
        handle = IHandle(_handle);
        treasury = ITreasury(handle.treasury());
    }

    /** @dev Getter for Handle contract address */
    function handleAddress() public view override returns (address) {
        return address(handle);
    }

    /**
     * @dev Stakes tokens
     * @param account The account to stake with
     * @param amount The amount to stake
     * @param fxToken The deposit fxToken
     * @param collateralToken The pool token address
     */
    function stake(
        address account,
        uint256 amount,
        address fxToken,
        address collateralToken
    ) external override notPaused nonReentrant returns (uint256 errorCode) {
        require(
            msg.sender == account || msg.sender == address(treasury),
            accessDenied
        );
        if (amount == 0) return 1;
        uint256 vaultCollateral =
            handle.getCollateralBalance(account, collateralToken, fxToken);
        // User must hold enough collateral.
        if (vaultCollateral < amount) return 2;
        // Transfer must not exceed per-user upper bound.
        uint256 maxDueToUpperBound =
            vaultCollateral.mul(handle.pctCollateralUpperBound()).div(1 ether);
        // Assert that current stake does not exceed max for vault.
        uint256 stake = balanceOfStake(account, fxToken, collateralToken);
        if (stake >= maxDueToUpperBound) return 3;
        // Calculate max stake remaining and cap amount if needed.
        uint256 maxStakeRemaining = maxDueToUpperBound.sub(stake);
        if (amount > maxStakeRemaining) amount = maxStakeRemaining;
        // Proceed with staking.
        Pool storage pool = pools[collateralToken];
        Deposit storage deposit = pool.deposits[account][fxToken];
        checkUpdateConfirmedDeposit(pool, deposit);
        // Withdraw existing collateral rewards, if any.
        _claimInterest(account, fxToken, collateralToken);
        // Update total deposits.
        pool.totalDeposits = pool.totalDeposits.add(amount);
        // Update deposit properties.
        deposit.amount_flagged = deposit.amount_flagged.add(amount);
        deposit.S = pool.S;
        deposit.N = pool.N.add(1);
        emit Stake(account, fxToken, collateralToken, amount);
        return 0;
    }

    /**
     * @dev Will do one of two things:
            1) Notifies PCT that staked collateral might no longer be
               available in Treasury if already invested.
            2) If the staked amount hasn't been invested yet,
               simply unstake it.
     * @param account The account to unstake with
     * @param amount The amount to unstake
     * @param fxToken The deposit fxToken
     * @param collateralToken The pool token address
     */
    function unstake(
        address account,
        uint256 amount,
        address fxToken,
        address collateralToken
    ) external override notPaused nonReentrant returns (uint256 errorCode) {
        require(
            msg.sender == account || msg.sender == address(treasury),
            accessDenied
        );
        uint256 stakedAmount =
            balanceOfStake(account, fxToken, collateralToken);
        if (amount > stakedAmount) amount = stakedAmount;
        if (amount == 0) return 1;
        Pool storage pool = pools[collateralToken];
        Deposit storage deposit = pool.deposits[account][fxToken];
        checkUpdateConfirmedDeposit(pool, deposit);
        // Withdraw existing collateral rewards, if any.
        _claimInterest(account, fxToken, collateralToken);
        // Accrue new interest from this point.
        deposit.S = pool.S;
        if (amount <= deposit.amount_flagged) {
            // Remove only flagged amount, which hasn't been invested yet.
            deposit.amount_flagged = deposit.amount_flagged.sub(amount);
            // Total deposits should only subtract flagged deposit, as
            // the confirmed deposit is subtracted during investment withdrawal.
            pool.totalDeposits = pool.totalDeposits.sub(amount);
        } else {
            uint256 unstakeConfirmed = amount.sub(deposit.amount_flagged);
            pool.totalDeposits = pool.totalDeposits.sub(deposit.amount_flagged);
            deposit.amount_flagged = 0;
            deposit.amount_confirmed = deposit.amount_confirmed.sub(
                unstakeConfirmed
            );
        }
        emit Unstake(account, fxToken, collateralToken, amount);
        return 0;
    }

    /**
     * @dev Claims interest from pool
     * @param fxToken The deposit fxToken
     * @param collateralToken The pool token address
     */
    function claimInterest(address fxToken, address collateralToken)
        external
        override
        notPaused
        nonReentrant
    {
        Pool storage pool = pools[collateralToken];
        Deposit storage deposit = pool.deposits[msg.sender][fxToken];
        checkUpdateConfirmedDeposit(pool, deposit);
        uint256 claimed = _claimInterest(msg.sender, fxToken, collateralToken);
        require(claimed > 0, "PCT: no claimable interest");
        // Update deposit S value so new interest is accrued from this point.
        deposit.S = pool.S;
    }

    /**
     * @dev Claims interest from pool
     * @param account The account to claim interest with
     * @param fxToken The deposit fxToken
     * @param collateralToken The pool token address
     */
    function _claimInterest(
        address account,
        address fxToken,
        address collateralToken
    ) private returns (uint256 claimed) {
        Pool storage pool = pools[collateralToken];
        Deposit storage deposit = pool.deposits[account][fxToken];
        // Withdraw all collateral rewards.
        claimed = _balanceOfClaimableInterest(pool, deposit);
        if (claimed == 0) return 0;
        // Reduce from total accrued.
        pool.totalAccrued = pool.totalAccrued.sub(claimed);
        // Increase collateral balance.
        handle.updateCollateralBalance(
            account,
            claimed,
            fxToken,
            collateralToken,
            true
        );
        emit ClaimInterest(account, collateralToken, claimed);
    }

    /**
     * @dev Sets a protocol interface as valid
     * @param collateralToken The pool token
     * @param pia The protocol interface address
     */
    function setProtocolInterface(address collateralToken, address pia)
        external
        override
        onlyOwner
    {
        IPCTProtocolInterface pi = IPCTProtocolInterface(pia);
        require(
            pi.investedToken() == collateralToken,
            "PCT: interface token mismatch"
        );
        Pool storage pool = pools[collateralToken];
        require(!pool.protocolInterfaces[pia], "PCT: interface already set");
        pool.protocolInterfaces[pia] = true;
        emit SetProtocolInterface(pia, collateralToken);
    }

    /**
     * @dev Removes a protocol interface
     * @param collateralToken The pool token
     * @param pia The protocol interface address
     */
    function unsetProtocolInterface(address collateralToken, address pia)
        external
        override
        onlyOwner
    {
        Pool storage pool = pools[collateralToken];
        require(pool.protocolInterfaces[pia], notAnInterface);
        pools[collateralToken].protocolInterfaces[pia] = false;
        emit UnsetProtocolInterface(pia, collateralToken);
    }

    /**
     * @dev Claims accrued interest from external protocol.
     * @param collateralToken The pool token
     * @param pia The protocol interface address
     */
    function claimProtocolInterest(address collateralToken, address pia)
        external
        override
        onlyOwner
        nonReentrant
        validInterface(collateralToken, pia)
    {
        uint256 balanceA = IERC20(collateralToken).balanceOf(address(treasury));
        IPCTProtocolInterface pi = IPCTProtocolInterface(pia);
        uint256 amount = pi.withdrawRewards();
        uint256 balanceB = IERC20(collateralToken).balanceOf(address(treasury));
        require(balanceB == balanceA.add(amount), "PCT: claim transfer failed");
        distributeInterest(collateralToken, amount);
        ensureUpperBoundLimit(pi, collateralToken);
        emit ProtocolClaimInterest(pia, collateralToken, amount);
    }

    /**
     * @dev Deposits funds into a protocol as an investment
     * @param collateralToken The collateral to deposit
     * @param pia The protocol interface address
     * @param ratio The ratio (0 to 1, 18 decimals) of available collateral
             to deposit into the protocol. 
     */
    function depositProtocolFunds(
        address collateralToken,
        address pia,
        uint256 ratio
    )
        external
        override
        onlyOwner
        nonReentrant
        validInterface(collateralToken, pia)
    {
        require(ratio > 0 && ratio <= 1 ether, "PCT: invalid ratio (0<R<=1)");
        Pool storage pool = pools[collateralToken];
        require(pool.totalDeposits > 0, "PCT: no funds available");
        uint256 amount = pool.totalDeposits.mul(ratio).div(1 ether);
        // Request withdraw via protocol interface, which will call returnFunds.
        IPCTProtocolInterface(pia).deposit(amount);
        // Increase investments; decrease deposits.
        pool.totalInvestments = pool.totalInvestments.add(amount);
        pool.protocolInvestments[pia] = pool.protocolInvestments[pia].add(
            amount
        );
        pool.totalDeposits = pool.totalDeposits.sub(amount);
        // Total amount staked during investment. Used to calculate shares.
        pool.totalDepositsAtInvestment = pool.totalDeposits.add(
            pool.totalInvestments
        );
        // Increase N to confirm recent deposits.
        pool.N = pool.N.add(1);
        emit ProtocolDepositFunds(pia, collateralToken, amount);
    }

    /**
     * @dev Withdraws invested funds from a protocol
     * @param collateralToken The collateral to withdraw
     * @param pia The protocol interface address
     * @param amount The amount of collateral to withdraw
     */
    function withdrawProtocolFunds(
        address collateralToken,
        address pia,
        uint256 amount
    ) external override onlyOwner nonReentrant {
        Pool storage pool = pools[collateralToken];
        uint256 currentInvestments = pool.protocolInvestments[pia];
        require(currentInvestments > 0, "PCT: not invested");
        IPCTProtocolInterface pi = IPCTProtocolInterface(pia);
        // Withdraw any unstaked collateral first.
        ensureUpperBoundLimit(pi, collateralToken);
        // Cap amount to totalInvestments.
        uint256 totalInvestments = pool.totalInvestments;
        if (amount > totalInvestments) amount = totalInvestments;
        // Request withdraw via protocol interface, which will call returnFunds.
        pi.withdraw(amount);
        // Decrease investments; increase deposits.
        pool.totalInvestments = totalInvestments.sub(amount);
        pool.protocolInvestments[pia] = currentInvestments.sub(amount);
        pool.totalDeposits = pool.totalDeposits.add(amount);
    }

    /**
     * @dev Requests funds from Treasury for a PCT protocol interface
     * @param collateralToken The pool token invested
     * @param requestedToken The token to request (protocol token or collateral token)
     * @param amount The amount of token to request
     */
    function requestTreasuryFunds(
        address collateralToken,
        address requestedToken,
        uint256 amount
    ) external override notPaused validInterface(collateralToken, msg.sender) {
        treasury.requestFundsPCT(requestedToken, amount);
        IERC20(requestedToken).safeTransfer(msg.sender, amount);
    }

    /**
     * @dev Returns funds to Treasury from a PCT protocol interface
     * @param collateralToken The pool token invested
     * @param returnedToken The token to return (protocol token or collateral)
     * @param amount The amount of token to send
     */
    function returnTreasuryFunds(
        address collateralToken,
        address returnedToken,
        uint256 amount
    ) external override notPaused validInterface(collateralToken, msg.sender) {
        IERC20(returnedToken).safeTransferFrom(
            msg.sender,
            address(treasury),
            amount
        );
        emit ProtocolReturnFunds(msg.sender, returnedToken, amount);
    }

    function setProtocolFee(uint256 ratio) external override onlyOwner {
        require(ratio <= 1 ether, "PCT: invalid ratio (0<=R<=1)");
        protocolFee = ratio;
    }

    /**
     * @dev Distributes interest for stakers
     * @param collateralToken The pool token
     * @param amount The amount to distribute
     */
    function distributeInterest(address collateralToken, uint256 amount)
        private
    {
        // Calculate and transfer fee.
        uint256 fee = amount.mul(protocolFee).div(1 ether);
        treasury.requestFundsPCT(collateralToken, fee);
        IERC20(collateralToken).safeTransfer(handle.FeeRecipient(), fee);
        amount = amount.sub(fee);
        // Distribute pool rewards.
        Pool storage pool = pools[collateralToken];
        uint256 deltaS =
            amount.mul(1 ether).div(pool.totalDepositsAtInvestment);
        pool.S = pool.S.add(deltaS);
        pool.totalAccrued = pool.totalAccrued.add(amount);
    }

    /**
     * @dev Checks the Treasury's collateral balance and total invested funds
            against maximum upper bound and withdraws from external protocol
            into Treasury if needed.
     * @param pi The PCT protocol interface
     * @param collateralToken The pool token address
     */
    function ensureUpperBoundLimit(
        IPCTProtocolInterface pi,
        address collateralToken
    ) private {
        Pool storage pool = pools[collateralToken];
        address pia = address(pi);
        uint256 totalInvested = pool.totalInvestments;
        uint256 totalFunds =
            IERC20(collateralToken).balanceOf(address(treasury)).add(
                totalInvested
            );
        uint256 upperBound = handle.pctCollateralUpperBound();
        uint256 maxInvestmentAmount = totalFunds.mul(upperBound).div(1 ether);
        if (totalInvested <= maxInvestmentAmount) return;
        // Upper bound limit has been exceeded; withdraw from external protocol.
        uint256 diff = totalInvested.sub(maxInvestmentAmount);
        assert(pool.protocolInvestments[pia] >= diff);
        pi.withdraw(diff);
        pool.totalInvestments = pool.totalInvestments.sub(diff);
        pool.protocolInvestments[pia] = pool.protocolInvestments[pia].sub(diff);
    }

    /**
     * @dev retrieves the total staked amount for account vault
     * @param account The address to fetch balance from
     * @param fxToken The deposit fxToken
     * @param collateralToken The pool token address
     */
    function balanceOfStake(
        address account,
        address fxToken,
        address collateralToken
    ) public view override returns (uint256 amount) {
        Deposit storage deposit =
            pools[collateralToken].deposits[account][fxToken];
        return deposit.amount_confirmed.add(deposit.amount_flagged);
    }

    /**
     * @dev Retrieves account's current claimable interest amount
     * @param account The address to fetch claimable interest from
     * @param fxToken The deposit fxToken
     * @param collateralToken The pool token address
     */
    function balanceOfClaimableInterest(
        address account,
        address fxToken,
        address collateralToken
    ) public view override returns (uint256 amount) {
        Pool storage pool = pools[collateralToken];
        Deposit storage deposit = pool.deposits[account][fxToken];
        return _balanceOfClaimableInterest(pool, deposit);
    }

    /**
     * @dev Getter for user's balance of claimable interest
     * @param pool The pool reference
     * @param deposit The deposit reference
     */
    function _balanceOfClaimableInterest(
        Pool storage pool,
        Deposit storage deposit
    ) private view returns (uint256 amount) {
        // Return zero if pool was not initialised.
        if (pool.S == 0) return 0;
        // It should be impossible for deposit.S > pool.S.
        uint256 deltaS = pool.S.sub(deposit.S);
        uint256 confirmedDeposit = getConfirmedDeposit(pool, deposit);
        amount = confirmedDeposit.mul(deltaS).div(1 ether);
        // Subtract 1 wei from total amount in case the final value
        // had a "decimal" >= 0.5 wei and was therefore rounded up.
        if (amount > 0) amount = amount - 1;
    }

    /**
     * @dev Checks whether the deposit has been confirmed
     * @param pool The pool reference
     * @param deposit The deposit reference
     */
    function getConfirmedDeposit(Pool storage pool, Deposit storage deposit)
        private
        view
        returns (uint256)
    {
        // If deposit N > pool N then flagged deposit has not been confirmed.
        return
            deposit.N <= pool.N
                ? deposit.amount_flagged.add(deposit.amount_confirmed)
                : deposit.amount_confirmed;
    }

    /**
     * @dev Checks whether the user deposit has been confirmed.
     * @param pool The pool reference
     * @param deposit The deposit reference
     */
    function checkUpdateConfirmedDeposit(
        Pool storage pool,
        Deposit storage deposit
    ) private {
        // If deposit N > pool N then deposit has not been confirmed.
        if (deposit.N > pool.N) return;
        // Add to confirmed and reset flagged.
        deposit.amount_confirmed = deposit.amount_confirmed.add(
            deposit.amount_flagged
        );
        deposit.amount_flagged = 0;
    }

    /**
     * @dev Getter for total pool deposit/stake
     * @param collateralToken The pool token
     */
    function getTotalDeposits(address collateralToken)
        external
        view
        override
        returns (uint256 amount)
    {
        return pools[collateralToken].totalDeposits;
    }

    /**
     * @dev Getter for total investments across all protocol interfaces
     * @param collateralToken The pool token
     */
    function getTotalInvestments(address collateralToken)
        external
        view
        override
        returns (uint256 amount)
    {
        return pools[collateralToken].totalInvestments;
    }

    /**
     * @dev Getter for total invested amounts per protocol interface
     * @param collateralToken The pool token
     * @param pia The protocol interface address
     */
    function getProtocolInvestments(address collateralToken, address pia)
        external
        view
        override
        returns (uint256 amount)
    {
        return pools[collateralToken].protocolInvestments[pia];
    }

    /**
     * @dev Getter for total pool accrued interest
     * @param collateralToken The pool token
     */
    function getTotalAccruedInterest(address collateralToken)
        external
        view
        override
        returns (uint256 amount)
    {
        return pools[collateralToken].totalAccrued;
    }

    /** @dev Protected UUPS upgrade authorization function */
    function _authorizeUpgrade(address) internal override onlyOwner {}
}

File 2 of 20 : Initializable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

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

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        require(_initializing || !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }
}

File 3 of 20 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

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

    uint256 private _status;

    function __ReentrancyGuard_init() internal initializer {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal initializer {
        _status = _NOT_ENTERED;
    }

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

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

        _;

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

File 4 of 20 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal initializer {
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal initializer {
        _setOwner(_msgSender());
    }

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

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

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _setOwner(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
    uint256[49] private __gap;
}

File 5 of 20 : UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 *
 * _Available since v4.1._
 */
abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable {
    function __UUPSUpgradeable_init() internal initializer {
        __ERC1967Upgrade_init_unchained();
        __UUPSUpgradeable_init_unchained();
    }

    function __UUPSUpgradeable_init_unchained() internal initializer {
    }
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        require(address(this) != __self, "Function must be called through delegatecall");
        require(_getImplementation() == __self, "Function must be called through active proxy");
        _;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     */
    function upgradeTo(address newImplementation) external virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallSecure(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallSecure(newImplementation, data, true);
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeTo} and {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal override onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;
    uint256[50] private __gap;
}

File 6 of 20 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 7 of 20 : IHandle.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

pragma abicoder v2;

interface IHandle {
    struct Vault {
        // Collateral token address => balance
        mapping(address => uint256) collateralBalance;
        uint256 debt;
        // Collateral token address => R0
        mapping(address => uint256) R0;
    }

    struct CollateralData {
        uint256 mintCR;
        uint256 liquidationFee;
        uint256 interestRate;
    }

    event UpdateDebt(address indexed account, address indexed fxToken);

    event UpdateCollateral(
        address indexed account,
        address indexed fxToken,
        address indexed collateralToken
    );

    event ConfigureCollateralToken(address indexed collateralToken);

    event ConfigureFxToken(address indexed fxToken, bool removed);

    function setCollateralUpperBoundPCT(uint256 ratio) external;

    function setPaused(bool value) external;

    function setFxToken(address token) external;

    function removeFxToken(address token) external;

    function setCollateralToken(
        address token,
        uint256 mintCR,
        uint256 liquidationFee,
        uint256 interestRatePerMille
    ) external;

    function removeCollateralToken(address token) external;

    function getAllCollateralTypes()
        external
        view
        returns (address[] memory collateral);

    function getCollateralDetails(address collateral)
        external
        view
        returns (CollateralData memory);

    function WETH() external view returns (address);

    function treasury() external view returns (address payable);

    function comptroller() external view returns (address);

    function vaultLibrary() external view returns (address);

    function fxKeeperPool() external view returns (address);

    function pct() external view returns (address);

    function liquidator() external view returns (address);

    function interest() external view returns (address);

    function referral() external view returns (address);

    function forex() external view returns (address);

    function rewards() external view returns (address);

    function pctCollateralUpperBound() external view returns (uint256);

    function isFxTokenValid(address fxToken) external view returns (bool);

    function isCollateralValid(address collateral) external view returns (bool);

    function setComponents(address[] memory components) external;

    function updateDebtPosition(
        address account,
        uint256 amount,
        address fxToken,
        bool increase
    ) external;

    function updateCollateralBalance(
        address account,
        uint256 amount,
        address fxToken,
        address collateralToken,
        bool increase
    ) external;

    function setFeeRecipient(address feeRecipient) external;

    function setFees(
        uint256 withdrawFeePerMille,
        uint256 depositFeePerMille,
        uint256 mintFeePerMille,
        uint256 burnFeePerMille
    ) external;

    function getCollateralBalance(
        address account,
        address collateralType,
        address fxToken
    ) external view returns (uint256 balance);

    function getBalance(address account, address fxToken)
        external
        view
        returns (address[] memory collateral, uint256[] memory balances);

    function getDebt(address owner, address fxToken)
        external
        view
        returns (uint256 _debt);

    function getPrincipalDebt(address owner, address fxToken)
        external
        view
        returns (uint256 _debt);

    function getCollateralR0(
        address account,
        address fxToken,
        address collateral
    ) external view returns (uint256 R0);

    function getTokenPrice(address token) external view returns (uint256 quote);

    function setOracle(address fxToken, address oracle) external;

    function FeeRecipient() external view returns (address);

    function mintFeePerMille() external view returns (uint256);

    function burnFeePerMille() external view returns (uint256);

    function withdrawFeePerMille() external view returns (uint256);

    function depositFeePerMille() external view returns (uint256);

    function isPaused() external view returns (bool);
}

File 8 of 20 : ITreasury.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

interface ITreasury {
    function depositCollateral(
        address account,
        uint256 depositAmount,
        address collateralType,
        address fxToken,
        address referral
    ) external;

    function depositCollateralETH(
        address account,
        address fxToken,
        address referral
    ) external payable;

    function withdrawCollateral(
        address collateralToken,
        address to,
        uint256 amount,
        address fxToken
    ) external;

    function withdrawCollateralETH(
        address to,
        uint256 amount,
        address fxToken
    ) external;

    function withdrawCollateralFrom(
        address from,
        address collateralToken,
        address to,
        uint256 amount,
        address fxToken
    ) external;

    function forceWithdrawCollateral(
        address from,
        address collateralToken,
        address to,
        uint256 amount,
        address fxToken
    ) external;

    function forceWithdrawAnyCollateral(
        address from,
        address to,
        uint256 amount,
        address fxToken,
        bool requireFullAmount
    )
        external
        returns (
            address[] memory collateralTypes,
            uint256[] memory collateralAmounts
        );

    function requestFundsPCT(address token, uint256 amount) external;

    function setMaximumTotalDepositAllowed(uint256 value) external;
}

File 9 of 20 : IPCT.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;

interface IPCT {
    struct Pool {
        // account -> fxToken -> Deposit
        mapping(address => mapping(address => Deposit)) deposits;
        // Protocol interface address => whether protocol is valid
        mapping(address => bool) protocolInterfaces;
        // Protocol interface address => invested amount
        mapping(address => uint256) protocolInvestments;
        // Deposits that are either flagged (not confirmed) or confirmed and not invested.
        uint256 totalDeposits;
        // Total deposit amount during last investment round, including invested amount.
        uint256 totalDepositsAtInvestment;
        // Amount of deposits that have been invested (<= totalDepositsAtInvestment).
        uint256 totalInvestments;
        // Total accrued interest from investments.
        uint256 totalAccrued;
        // Current pool reward ratio over total deposits.
        uint256 S;
        // Current investment round number.
        uint256 N;
    }

    struct Deposit {
        uint256 amount_flagged;
        uint256 amount_confirmed;
        uint256 S;
        uint256 N;
    }

    event Stake(
        address indexed account,
        address indexed fxToken,
        address indexed collateralToken,
        uint256 amount
    );

    event Unstake(
        address indexed account,
        address indexed fxToken,
        address indexed collateralToken,
        uint256 amount
    );

    event ClaimInterest(
        address indexed acount,
        address indexed collateralToken,
        uint256 amount
    );

    event SetProtocolInterface(
        address indexed protocolInterfaceAddress,
        address indexed collateralToken
    );

    event UnsetProtocolInterface(
        address indexed protocolInterfaceAddress,
        address indexed collateralToken
    );

    event ProtocolClaimInterest(
        address indexed protocolInterfaceAddress,
        address indexed collateralToken,
        uint256 amount
    );

    event ProtocolReturnFunds(
        address indexed protocolInterfaceAddress,
        address indexed collateralToken,
        uint256 amount
    );

    event ProtocolDepositFunds(
        address indexed protocolInterfaceAddress,
        address indexed collateralToken,
        uint256 amount
    );

    function stake(
        address account,
        uint256 amount,
        address fxToken,
        address collateralToken
    ) external returns (uint256 errorCode);

    function unstake(
        address account,
        uint256 amount,
        address fxToken,
        address collateralToken
    ) external returns (uint256 errorCode);

    function claimInterest(address fxToken, address collateralToken) external;

    function setProtocolInterface(
        address collateralToken,
        address protocolInterfaceAddress
    ) external;

    function unsetProtocolInterface(
        address collateralToken,
        address protocolInterfaceAddress
    ) external;

    function claimProtocolInterest(
        address collateralToken,
        address protocolInterfaceAddress
    ) external;

    function depositProtocolFunds(
        address collateralToken,
        address protocolInterfaceAddress,
        uint256 ratio
    ) external;

    function withdrawProtocolFunds(
        address collateralToken,
        address protocolInterfaceAddress,
        uint256 amount
    ) external;

    function requestTreasuryFunds(
        address collateralToken,
        address requestedToken,
        uint256 amount
    ) external;

    function returnTreasuryFunds(
        address collateralToken,
        address returnedToken,
        uint256 amount
    ) external;

    function setProtocolFee(uint256 ratio) external;

    function protocolFee() external view returns (uint256);

    function balanceOfStake(
        address account,
        address fxToken,
        address collateralToken
    ) external view returns (uint256 amount);

    function balanceOfClaimableInterest(
        address account,
        address fxToken,
        address collateralToken
    ) external view returns (uint256 amount);

    function getTotalDeposits(address collateralToken)
        external
        view
        returns (uint256 amount);

    function getTotalInvestments(address collateralToken)
        external
        view
        returns (uint256 amount);

    function getProtocolInvestments(
        address collateralToken,
        address protocolInterfaceAddress
    ) external view returns (uint256 amount);

    function getTotalAccruedInterest(address collateralToken)
        external
        view
        returns (uint256 amount);
}

File 10 of 20 : IPCTProtocolInterface.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;

interface IPCTProtocolInterface {
    function investedToken() external view returns (address);

    function protocolToken() external view returns (address);

    function principal() external view returns (uint256);

    function deposit(uint256 amount) external;

    function withdraw(uint256 amount) external;

    function withdrawRewards() external returns (uint256);
}

File 11 of 20 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

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

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

File 12 of 20 : HandlePausable.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;

import "../interfaces/Bank/IHandle.sol";
import "../interfaces/Bank/IHandleComponent.sol";

abstract contract HandlePausable is IHandleComponent {
    function handleAddress() public view virtual override returns (address);

    modifier notPaused() {
        require(!IHandle(handleAddress()).isPaused(), "Paused");
        _;
    }
}

File 13 of 20 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal initializer {
        __Context_init_unchained();
    }

    function __Context_init_unchained() internal initializer {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
    uint256[50] private __gap;
}

File 14 of 20 : ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.2;

import "../beacon/IBeaconUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import "../utils/Initializable.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 *
 * @custom:oz-upgrades-unsafe-allow delegatecall
 */
abstract contract ERC1967UpgradeUpgradeable is Initializable {
    function __ERC1967Upgrade_init() internal initializer {
        __ERC1967Upgrade_init_unchained();
    }

    function __ERC1967Upgrade_init_unchained() internal initializer {
    }
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(
        address newImplementation,
        bytes memory data,
        bool forceCall
    ) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            _functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallSecure(
        address newImplementation,
        bytes memory data,
        bool forceCall
    ) internal {
        address oldImplementation = _getImplementation();

        // Initial upgrade and setup call
        _setImplementation(newImplementation);
        if (data.length > 0 || forceCall) {
            _functionDelegateCall(newImplementation, data);
        }

        // Perform rollback test if not already in progress
        StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT);
        if (!rollbackTesting.value) {
            // Trigger rollback using upgradeTo from the new implementation
            rollbackTesting.value = true;
            _functionDelegateCall(
                newImplementation,
                abi.encodeWithSignature("upgradeTo(address)", oldImplementation)
            );
            rollbackTesting.value = false;
            // Check rollback was effective
            require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
            // Finally reset to the new implementation and log the upgrade
            _upgradeTo(newImplementation);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Emitted when the beacon is upgraded.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(
        address newBeacon,
        bytes memory data,
        bool forceCall
    ) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
        }
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function _functionDelegateCall(address target, bytes memory data) private returns (bytes memory) {
        require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed");
    }
    uint256[50] private __gap;
}

File 15 of 20 : IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeaconUpgradeable {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

File 16 of 20 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

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

File 17 of 20 : StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
 */
library StorageSlotUpgradeable {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        assembly {
            r.slot := slot
        }
    }
}

File 18 of 20 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

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

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 19 of 20 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

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

File 20 of 20 : IHandleComponent.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;

interface IHandleComponent {
    function setHandleContract(address hanlde) external;

    function handleAddress() external view returns (address);
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"acount","type":"address"},{"indexed":true,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ClaimInterest","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":"protocolInterfaceAddress","type":"address"},{"indexed":true,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ProtocolClaimInterest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"protocolInterfaceAddress","type":"address"},{"indexed":true,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ProtocolDepositFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"protocolInterfaceAddress","type":"address"},{"indexed":true,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ProtocolReturnFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"protocolInterfaceAddress","type":"address"},{"indexed":true,"internalType":"address","name":"collateralToken","type":"address"}],"name":"SetProtocolInterface","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"fxToken","type":"address"},{"indexed":true,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Stake","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"protocolInterfaceAddress","type":"address"},{"indexed":true,"internalType":"address","name":"collateralToken","type":"address"}],"name":"UnsetProtocolInterface","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"fxToken","type":"address"},{"indexed":true,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unstake","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"fxToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"}],"name":"balanceOfClaimableInterest","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"fxToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"}],"name":"balanceOfStake","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"fxToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"}],"name":"claimInterest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"pia","type":"address"}],"name":"claimProtocolInterest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"pia","type":"address"},{"internalType":"uint256","name":"ratio","type":"uint256"}],"name":"depositProtocolFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"pia","type":"address"}],"name":"getProtocolInvestments","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"}],"name":"getTotalAccruedInterest","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"}],"name":"getTotalDeposits","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"}],"name":"getTotalInvestments","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"handleAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"requestedToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"requestTreasuryFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"returnedToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"returnTreasuryFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_handle","type":"address"}],"name":"setHandleContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"ratio","type":"uint256"}],"name":"setProtocolFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"pia","type":"address"}],"name":"setProtocolInterface","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"fxToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"}],"name":"stake","outputs":[{"internalType":"uint256","name":"errorCode","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"pia","type":"address"}],"name":"unsetProtocolInterface","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"fxToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"}],"name":"unstake","outputs":[{"internalType":"uint256","name":"errorCode","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"pia","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawProtocolFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a06040523060601b60805234801561001757600080fd5b5060805160601c61337e61004b600039600081816106be015281816106fe01528181610ccd0152610d0d015261337e6000f3fe6080604052600436106101855760003560e01c80636c43cf1d116100d15780638da5cb5b1161008a578063ba437c6811610064578063ba437c681461047b578063cb9bdef41461049b578063f12582ea146104d4578063f2fde38b146104f45761018c565b80638da5cb5b146104275780639b1c414f14610445578063b0e21e8a146104655761018c565b80636c43cf1d1461036b578063715018a61461038b57806371dfb89b146103a057806374bf578b146103c0578063787dce3d146103f25780638129fc1c146104125761018c565b80634b2c636b1161013e5780635aa347c7116101185780635aa347c7146102eb5780635b73ec001461030b5780635ba0e4261461032b578063618b4f881461034b5761018c565b80634b2c636b1461027f5780634f1ef2861461029f578063596999b2146102b25761018c565b80630251cfa1146101915780631855365d146101dd5780633659cfe6146101ff57806340cf49bd1461021f57806344381ed01461023f5780634a0e780e1461025f5761018c565b3661018c57005b600080fd5b34801561019d57600080fd5b506101ca6101ac366004612e2a565b6001600160a01b0316600090815260fd602052604090206003015490565b6040519081526020015b60405180910390f35b3480156101e957600080fd5b506101fd6101f8366004612ee4565b610514565b005b34801561020b57600080fd5b506101fd61021a366004612e2a565b6106b3565b34801561022b57600080fd5b506101ca61023a366004612e9a565b61077c565b34801561024b57600080fd5b506101ca61025a366004612e9a565b6107c8565b34801561026b57600080fd5b506101ca61027a366004612fe3565b610811565b34801561028b57600080fd5b506101fd61029a366004612e62565b610bbd565b6101fd6102ad366004612f24565b610cc2565b3480156102be57600080fd5b506101ca6102cd366004612e2a565b6001600160a01b0316600090815260fd602052604090206006015490565b3480156102f757600080fd5b506101ca610306366004612fe3565b610d7c565b34801561031757600080fd5b506101fd610326366004612ee4565b611008565b34801561033757600080fd5b506101fd610346366004612ee4565b61117f565b34801561035757600080fd5b506101ca610366366004612e62565b611482565b34801561037757600080fd5b506101fd610386366004612ee4565b6114b3565b34801561039757600080fd5b506101fd61164b565b3480156103ac57600080fd5b506101fd6103bb366004612e62565b611681565b3480156103cc57600080fd5b5060fb546001600160a01b03165b6040516001600160a01b0390911681526020016101d4565b3480156103fe57600080fd5b506101fd61040d366004613055565b611999565b34801561041e57600080fd5b506101fd611a20565b34801561043357600080fd5b506097546001600160a01b03166103da565b34801561045157600080fd5b506101fd610460366004612e2a565b611a9b565b34801561047157600080fd5b506101ca60fe5481565b34801561048757600080fd5b506101fd610496366004612e62565b611b74565b3480156104a757600080fd5b506101ca6104b6366004612e2a565b6001600160a01b0316600090815260fd602052604090206005015490565b3480156104e057600080fd5b506101fd6104ef366004612e62565b611ce4565b34801561050057600080fd5b506101fd61050f366004612e2a565b611eb7565b60fb546001600160a01b03166001600160a01b031663b187bd266040518163ffffffff1660e01b815260040160206040518083038186803b15801561055857600080fd5b505afa15801561056c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105909190613035565b156105b65760405162461bcd60e51b81526004016105ad906130d4565b60405180910390fd5b6001600160a01b038316600090815260fd6020908152604080832033808552600190910183529281902054815180830190925260158252745043543a206e6f7420616e20696e7465726661636560581b9282019290925285929160ff166106305760405162461bcd60e51b81526004016105ad91906130a1565b5060fc54604051638c6d4c4760e01b81526001600160a01b0386811660048301526024820186905290911690638c6d4c4790604401600060405180830381600087803b15801561067f57600080fd5b505af1158015610693573d6000803e3d6000fd5b506106ac925050506001600160a01b0385163385611f4f565b5050505050565b306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614156106fc5760405162461bcd60e51b81526004016105ad906130f4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031661072e611fb7565b6001600160a01b0316146107545760405162461bcd60e51b81526004016105ad90613140565b61075d81611fe5565b604080516000808252602082019092526107799183919061200f565b50565b6001600160a01b03808216600090815260fd60209081526040808320878516845282528083209386168352929052908120805460018201546107bd91612153565b9150505b9392505050565b6001600160a01b03808216600090815260fd6020908152604080832087851684528083528184209487168452939091528120909190610807828261215f565b9695505050505050565b600061082560fb546001600160a01b031690565b6001600160a01b031663b187bd266040518163ffffffff1660e01b815260040160206040518083038186803b15801561085d57600080fd5b505afa158015610871573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108959190613035565b156108b25760405162461bcd60e51b81526004016105ad906130d4565b600260c95414156108d55760405162461bcd60e51b81526004016105ad9061320f565b600260c955336001600160a01b03861614806108fb575060fc546001600160a01b031633145b604051806040016040528060128152602001711410d50e881858d8d95cdcc819195b9a595960721b815250906109445760405162461bcd60e51b81526004016105ad91906130a1565b508361095257506001610bb0565b60fb5460405163062315a960e51b81526001600160a01b03878116600483015284811660248301528581166044830152600092169063c462b5209060640160206040518083038186803b1580156109a857600080fd5b505afa1580156109bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109e0919061306d565b9050848110156109f4576002915050610bb0565b6000610a98670de0b6b3a7640000610a9260fb60009054906101000a90046001600160a01b03166001600160a01b03166301964f366040518163ffffffff1660e01b815260040160206040518083038186803b158015610a5357600080fd5b505afa158015610a67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a8b919061306d565b85906121d7565b906121e3565b90506000610aa788878761077c565b9050818110610abc5760039350505050610bb0565b6000610ac883836121ef565b905080881115610ad6578097505b6001600160a01b03808716600090815260fd602090815260408083208d85168452808352818420948c168452939091529020610b1282826121fb565b610b1d8b8a8a61222c565b506003820154610b2d908b612153565b60038301558054610b3e908b612153565b8155600782015460028201556008820154610b5a906001612153565b60038201556040518a81526001600160a01b03808a16918b8216918e16907fc5017594d2723c038bb216e5bcef3ac65910ade839c0e63253bf5b59efbf0fd79060200160405180910390a4600096505050505050505b600160c955949350505050565b6097546001600160a01b03163314610be75760405162461bcd60e51b81526004016105ad906131da565b6001600160a01b03808316600090815260fd6020908152604080832093851683526001840182529182902054825180840190935260158352745043543a206e6f7420616e20696e7465726661636560581b9183019190915260ff16610c5f5760405162461bcd60e51b81526004016105ad91906130a1565b506001600160a01b03808416600081815260fd602090815260408083209487168084526001909501909152808220805460ff19169055519192917f12a1456b63108a9a857cdff1cdd634e182a704f40f857e1ff35335912a1754199190a3505050565b306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161415610d0b5760405162461bcd60e51b81526004016105ad906130f4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316610d3d611fb7565b6001600160a01b031614610d635760405162461bcd60e51b81526004016105ad90613140565b610d6c82611fe5565b610d788282600161200f565b5050565b6000610d9060fb546001600160a01b031690565b6001600160a01b031663b187bd266040518163ffffffff1660e01b815260040160206040518083038186803b158015610dc857600080fd5b505afa158015610ddc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e009190613035565b15610e1d5760405162461bcd60e51b81526004016105ad906130d4565b600260c9541415610e405760405162461bcd60e51b81526004016105ad9061320f565b600260c955336001600160a01b0386161480610e66575060fc546001600160a01b031633145b604051806040016040528060128152602001711410d50e881858d8d95cdcc819195b9a595960721b81525090610eaf5760405162461bcd60e51b81526004016105ad91906130a1565b506000610ebd86858561077c565b905080851115610ecb578094505b84610eda576001915050610bb0565b6001600160a01b03808416600090815260fd602090815260408083208a851684528083528184209489168452939091529020610f1682826121fb565b610f2188878761222c565b506007820154600282015580548711610f5b578054610f4090886121ef565b81556003820154610f5190886121ef565b6003830155610f9e565b8054600090610f6b9089906121ef565b82546003850154919250610f7f91906121ef565b6003840155600082556001820154610f9790826121ef565b6001830155505b846001600160a01b0316866001600160a01b0316896001600160a01b03167f2cbcd809a4c90d11f8d12c4b6d09986b255ae1e68f54f076c145fbb2185904e18a604051610fed91815260200190565b60405180910390a45050600160c95550600095945050505050565b60fb546001600160a01b03166001600160a01b031663b187bd266040518163ffffffff1660e01b815260040160206040518083038186803b15801561104c57600080fd5b505afa158015611060573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110849190613035565b156110a15760405162461bcd60e51b81526004016105ad906130d4565b6001600160a01b038316600090815260fd6020908152604080832033808552600190910183529281902054815180830190925260158252745043543a206e6f7420616e20696e7465726661636560581b9282019290925285929160ff1661111b5760405162461bcd60e51b81526004016105ad91906130a1565b5060fc54611138906001600160a01b038681169133911686612364565b6040518381526001600160a01b0385169033907f2cb2d56694b14c7fc4a4f9b8fca65261b65dde83ded753b9b3856f02c01008ab9060200160405180910390a35050505050565b6097546001600160a01b031633146111a95760405162461bcd60e51b81526004016105ad906131da565b600260c95414156111cc5760405162461bcd60e51b81526004016105ad9061320f565b600260c9556001600160a01b03808416600090815260fd602090815260408083209386168352600190930181529082902054825180840190935260158352745043543a206e6f7420616e20696e7465726661636560581b918301919091528491849160ff1661124e5760405162461bcd60e51b81526004016105ad91906130a1565b506000831180156112675750670de0b6b3a76400008311155b6112b35760405162461bcd60e51b815260206004820152601b60248201527f5043543a20696e76616c696420726174696f2028303c523c3d3129000000000060448201526064016105ad565b6001600160a01b038516600090815260fd60205260409020600381015461131c5760405162461bcd60e51b815260206004820152601760248201527f5043543a206e6f2066756e647320617661696c61626c6500000000000000000060448201526064016105ad565b6000611341670de0b6b3a7640000610a928785600301546121d790919063ffffffff16565b60405163b6b55f2560e01b8152600481018290529091506001600160a01b0387169063b6b55f2590602401600060405180830381600087803b15801561138657600080fd5b505af115801561139a573d6000803e3d6000fd5b50505060058301546113ad915082612153565b60058301556001600160a01b03861660009081526002830160205260409020546113d79082612153565b6001600160a01b0387166000908152600284016020526040902055600382015461140190826121ef565b6003830181905560058301546114179190612153565b6004830155600882015461142c906001612153565b60088301556040518181526001600160a01b0380891691908816907fbc724c1675db759aec8fb95e946e8f501586936264e27a5dc29b45d89e4249bc9060200160405180910390a35050600160c9555050505050565b6001600160a01b03808316600090815260fd6020908152604080832093851683526002909301905220545b92915050565b6097546001600160a01b031633146114dd5760405162461bcd60e51b81526004016105ad906131da565b600260c95414156115005760405162461bcd60e51b81526004016105ad9061320f565b600260c98190556001600160a01b03808516600090815260fd60209081526040808320938716835293830190529190912054806115735760405162461bcd60e51b81526020600482015260116024820152701410d50e881b9bdd081a5b9d995cdd1959607a1b60448201526064016105ad565b8361157e81876123a2565b60058301548085111561158f578094505b604051632e1a7d4d60e01b8152600481018690526001600160a01b03831690632e1a7d4d90602401600060405180830381600087803b1580156115d157600080fd5b505af11580156115e5573d6000803e3d6000fd5b505050506115fc85826121ef90919063ffffffff16565b600585015561160b83866121ef565b6001600160a01b038716600090815260028601602052604090205560038401546116359086612153565b6003909401939093555050600160c95550505050565b6097546001600160a01b031633146116755760405162461bcd60e51b81526004016105ad906131da565b61167f6000612600565b565b6097546001600160a01b031633146116ab5760405162461bcd60e51b81526004016105ad906131da565b600260c95414156116ce5760405162461bcd60e51b81526004016105ad9061320f565b600260c9556001600160a01b03808316600090815260fd602090815260408083209385168352600190930181529082902054825180840190935260158352745043543a206e6f7420616e20696e7465726661636560581b918301919091528391839160ff166117505760405162461bcd60e51b81526004016105ad91906130a1565b5060fc546040516370a0823160e01b81526001600160a01b0391821660048201526000918616906370a082319060240160206040518083038186803b15801561179857600080fd5b505afa1580156117ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117d0919061306d565b905060008490506000816001600160a01b031663c7b8981c6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561181457600080fd5b505af1158015611828573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184c919061306d565b60fc546040516370a0823160e01b81526001600160a01b039182166004820152919250600091908916906370a082319060240160206040518083038186803b15801561189757600080fd5b505afa1580156118ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118cf919061306d565b90506118db8483612153565b81146119295760405162461bcd60e51b815260206004820152601a60248201527f5043543a20636c61696d207472616e73666572206661696c656400000000000060448201526064016105ad565b6119338883612652565b61193d83896123a2565b876001600160a01b0316876001600160a01b03167f78a5e2361351659984d3361f31888559465d0d960bf8f57970db9996608c29338460405161198291815260200190565b60405180910390a35050600160c955505050505050565b6097546001600160a01b031633146119c35760405162461bcd60e51b81526004016105ad906131da565b670de0b6b3a7640000811115611a1b5760405162461bcd60e51b815260206004820152601c60248201527f5043543a20696e76616c696420726174696f2028303c3d523c3d31290000000060448201526064016105ad565b60fe55565b600054610100900460ff1680611a39575060005460ff16155b611a555760405162461bcd60e51b81526004016105ad9061318c565b600054610100900460ff16158015611a77576000805461ffff19166101011790555b611a7f6127ed565b611a87612854565b8015610779576000805461ff001916905550565b6097546001600160a01b03163314611ac55760405162461bcd60e51b81526004016105ad906131da565b60fb80546001600160a01b0319166001600160a01b038316908117909155604080516361d027b360e01b815290516361d027b391600480820192602092909190829003018186803b158015611b1957600080fd5b505afa158015611b2d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b519190612e46565b60fc80546001600160a01b0319166001600160a01b039290921691909117905550565b60fb546001600160a01b03166001600160a01b031663b187bd266040518163ffffffff1660e01b815260040160206040518083038186803b158015611bb857600080fd5b505afa158015611bcc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf09190613035565b15611c0d5760405162461bcd60e51b81526004016105ad906130d4565b600260c9541415611c305760405162461bcd60e51b81526004016105ad9061320f565b600260c9556001600160a01b03808216600090815260fd602090815260408083203384528083528184209487168452939091529020611c6f82826121fb565b6000611c7c33868661222c565b905060008111611cce5760405162461bcd60e51b815260206004820152601a60248201527f5043543a206e6f20636c61696d61626c6520696e74657265737400000000000060448201526064016105ad565b506007909101546002909101555050600160c955565b6097546001600160a01b03163314611d0e5760405162461bcd60e51b81526004016105ad906131da565b6000819050826001600160a01b0316816001600160a01b031663fdd1c36f6040518163ffffffff1660e01b815260040160206040518083038186803b158015611d5657600080fd5b505afa158015611d6a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d8e9190612e46565b6001600160a01b031614611de45760405162461bcd60e51b815260206004820152601d60248201527f5043543a20696e7465726661636520746f6b656e206d69736d6174636800000060448201526064016105ad565b6001600160a01b03808416600090815260fd6020908152604080832093861683526001840190915290205460ff1615611e5f5760405162461bcd60e51b815260206004820152601a60248201527f5043543a20696e7465726661636520616c72656164792073657400000000000060448201526064016105ad565b6001600160a01b03808416600081815260018481016020526040808320805460ff191690921790915551928716927f3834fee568ad81cff3ba3707ea01952cad03aa1cb684c083de0fbfce1adbba449190a350505050565b6097546001600160a01b03163314611ee15760405162461bcd60e51b81526004016105ad906131da565b6001600160a01b038116611f465760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016105ad565b61077981612600565b6040516001600160a01b038316602482015260448101829052611fb290849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526128b3565b505050565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b6097546001600160a01b031633146107795760405162461bcd60e51b81526004016105ad906131da565b6000612019611fb7565b905061202484612985565b6000835111806120315750815b15612042576120408484612a2a565b505b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143805460ff166106ac57805460ff191660011781556040516001600160a01b03831660248201526120c190869060440160408051601f198184030181529190526020810180516001600160e01b0316631b2ce7f360e11b179052612a2a565b50805460ff191681556120d2611fb7565b6001600160a01b0316826001600160a01b03161461214a5760405162461bcd60e51b815260206004820152602f60248201527f45524331393637557067726164653a207570677261646520627265616b73206660448201526e75727468657220757067726164657360881b60648201526084016105ad565b6106ac85612b0c565b60006107c18284613246565b6000826007015460001415612176575060006114ad565b6000612193836002015485600701546121ef90919063ffffffff16565b905060006121a18585612b4c565b90506121b9670de0b6b3a7640000610a9283856121d7565b925082156121cf576121cc60018461329d565b92505b505092915050565b60006107c1828461327e565b60006107c1828461325e565b60006107c1828461329d565b81600801548160030154111561221057610d78565b8054600182015461222091612153565b60018201556000905550565b6001600160a01b03808216600090815260fd602090815260408083208785168452808352818420948716845293909152812090919061226b828261215f565b92508261227d576000925050506107c1565b600682015461228c90846121ef565b600683015560fb5460405163181e20a760e01b81526001600160a01b0388811660048301526024820186905287811660448301528681166064830152600160848301529091169063181e20a79060a401600060405180830381600087803b1580156122f657600080fd5b505af115801561230a573d6000803e3d6000fd5b50505050836001600160a01b0316866001600160a01b03167feba725fa451eb408a24432f4ad3fb91000f13659a84e831632133ea702ded0b18560405161235391815260200190565b60405180910390a350509392505050565b6040516001600160a01b038085166024830152831660448201526064810182905261239c9085906323b872dd60e01b90608401611f7b565b50505050565b6001600160a01b03818116600081815260fd6020526040808220600581015460fc5492516370a0823160e01b81529290951660048301529386939092916124449184916370a082319060240160206040518083038186803b15801561240657600080fd5b505afa15801561241a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061243e919061306d565b90612153565b9050600060fb60009054906101000a90046001600160a01b03166001600160a01b03166301964f366040518163ffffffff1660e01b815260040160206040518083038186803b15801561249657600080fd5b505afa1580156124aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124ce919061306d565b905060006124e8670de0b6b3a7640000610a9285856121d7565b90508084116124fc57505050505050610d78565b600061250885836121ef565b6001600160a01b038716600090815260028901602052604090205490915081111561254357634e487b7160e01b600052600160045260246000fd5b604051632e1a7d4d60e01b8152600481018290526001600160a01b038a1690632e1a7d4d90602401600060405180830381600087803b15801561258557600080fd5b505af1158015612599573d6000803e3d6000fd5b50505060058801546125ac9150826121ef565b60058801556001600160a01b03861660009081526002880160205260409020546125d690826121ef565b6001600160a01b039096166000908152600290970160205250506040909420929092555050505050565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000612675670de0b6b3a7640000610a9260fe54856121d790919063ffffffff16565b60fc54604051638c6d4c4760e01b81526001600160a01b03868116600483015260248201849052929350911690638c6d4c4790604401600060405180830381600087803b1580156126c557600080fd5b505af11580156126d9573d6000803e3d6000fd5b5050505061277760fb60009054906101000a90046001600160a01b03166001600160a01b031663ec94578e6040518163ffffffff1660e01b815260040160206040518083038186803b15801561272e57600080fd5b505afa158015612742573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127669190612e46565b6001600160a01b0385169083611f4f565b61278182826121ef565b6001600160a01b038416600090815260fd602052604081206004810154929450916127b890610a9286670de0b6b3a76400006121d7565b60078301549091506127ca9082612153565b600783015560068201546127de9085612153565b82600601819055505050505050565b600054610100900460ff1680612806575060005460ff16155b6128225760405162461bcd60e51b81526004016105ad9061318c565b600054610100900460ff16158015612844576000805461ffff19166101011790555b61284c612b78565b611a87612be2565b600054610100900460ff168061286d575060005460ff16155b6128895760405162461bcd60e51b81526004016105ad9061318c565b600054610100900460ff161580156128ab576000805461ffff19166101011790555b611a87612c42565b6000612908826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612cb29092919063ffffffff16565b805190915015611fb257808060200190518101906129269190613035565b611fb25760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016105ad565b803b6129e95760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084016105ad565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0392909216919091179055565b6060823b612a895760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084016105ad565b600080846001600160a01b031684604051612aa49190613085565b600060405180830381855af49150503d8060008114612adf576040519150601f19603f3d011682016040523d82523d6000602084013e612ae4565b606091505b50915091506121cc828260405180606001604052806027815260200161332260279139612cc9565b612b1581612985565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6000826008015482600301541115612b685781600101546107c1565b600182015482546107c191612153565b600054610100900460ff1680612b91575060005460ff16155b612bad5760405162461bcd60e51b81526004016105ad9061318c565b600054610100900460ff16158015611a87576000805461ffff19166101011790558015610779576000805461ff001916905550565b600054610100900460ff1680612bfb575060005460ff16155b612c175760405162461bcd60e51b81526004016105ad9061318c565b600054610100900460ff16158015612c39576000805461ffff19166101011790555b611a8733612600565b600054610100900460ff1680612c5b575060005460ff16155b612c775760405162461bcd60e51b81526004016105ad9061318c565b600054610100900460ff16158015612c99576000805461ffff19166101011790555b600160c9558015610779576000805461ff001916905550565b6060612cc18484600085612d02565b949350505050565b60608315612cd85750816107c1565b825115612ce85782518084602001fd5b8160405162461bcd60e51b81526004016105ad91906130a1565b606082471015612d635760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016105ad565b843b612db15760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016105ad565b600080866001600160a01b03168587604051612dcd9190613085565b60006040518083038185875af1925050503d8060008114612e0a576040519150601f19603f3d011682016040523d82523d6000602084013e612e0f565b606091505b5091509150612e1f828286612cc9565b979650505050505050565b600060208284031215612e3b578081fd5b81356107c18161330c565b600060208284031215612e57578081fd5b81516107c18161330c565b60008060408385031215612e74578081fd5b8235612e7f8161330c565b91506020830135612e8f8161330c565b809150509250929050565b600080600060608486031215612eae578081fd5b8335612eb98161330c565b92506020840135612ec98161330c565b91506040840135612ed98161330c565b809150509250925092565b600080600060608486031215612ef8578283fd5b8335612f038161330c565b92506020840135612f138161330c565b929592945050506040919091013590565b60008060408385031215612f36578182fd5b8235612f418161330c565b9150602083013567ffffffffffffffff80821115612f5d578283fd5b818501915085601f830112612f70578283fd5b813581811115612f8257612f826132f6565b604051601f8201601f19908116603f01168101908382118183101715612faa57612faa6132f6565b81604052828152886020848701011115612fc2578586fd5b82602086016020830137856020848301015280955050505050509250929050565b60008060008060808587031215612ff8578081fd5b84356130038161330c565b935060208501359250604085013561301a8161330c565b9150606085013561302a8161330c565b939692955090935050565b600060208284031215613046578081fd5b815180151581146107c1578182fd5b600060208284031215613066578081fd5b5035919050565b60006020828403121561307e578081fd5b5051919050565b600082516130978184602087016132b4565b9190910192915050565b60006020825282518060208401526130c08160408501602087016132b4565b601f01601f19169190910160400192915050565b60208082526006908201526514185d5cd95960d21b604082015260600190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60008219821115613259576132596132e0565b500190565b60008261327957634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615613298576132986132e0565b500290565b6000828210156132af576132af6132e0565b500390565b60005b838110156132cf5781810151838201526020016132b7565b8381111561239c5750506000910152565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461077957600080fdfe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212203a26656efe8a624eed82269cae5f4643c58bfd1bad16361683608984666be86864736f6c63430008030033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.