Contract 0x559844b1Df66e247F83Ba58bc39fa488A1AF1093

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434cSwap Hlp Token T...282115772022-10-03 18:56:4816 hrs 10 mins ago0xa4f4406d3dc6482db1397d0ad260fd223c8f37fc IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00023367
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296fSwap Hlp Token T...282104122022-10-03 18:45:0416 hrs 21 mins ago0xa4f4406d3dc6482db1397d0ad260fd223c8f37fc IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00025196
0xbd23061c3f2e729f51207d44048bdfd7e400a9e5813658ec3e07774e763b2c42Swap Pegged Toke...272839842022-09-28 20:22:495 days 14 hrs ago0xeed6ce804e0cf9fa0425c03673c0385ed1e02070 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00021401
0x6ccae7baf4a9c9bb831b9e1e6c426b50bb9c7e04870712cfbea26f2fd4b814e2Swap Pegged Toke...270769232022-09-28 0:12:286 days 10 hrs ago0x91f3be13569e134cbccd5bb33bd3eedd41cf71ba IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00014915
0xef8d3049ab23f0ff84b23d0a0b0c0942e81f82e89de5f122b1ce53fc23166455Swap Pegged Toke...270768972022-09-28 0:12:106 days 10 hrs ago0x91f3be13569e134cbccd5bb33bd3eedd41cf71ba IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00016765
0x954648e49de9331be9961ed551be9963433889d880c17a3d4c452aa2f90932f6Swap Pegged Toke...270668982022-09-27 22:12:016 days 12 hrs ago0x91f3be13569e134cbccd5bb33bd3eedd41cf71ba IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00017494
0x5bb0a12c8afda1dc4bfdeb9e919ded62d80622e2969dc3b007fec13d6ffa7decSwap Hlp Token T...266906722022-09-26 1:40:068 days 9 hrs ago0x574bf8b0a1c0ea8fd152d5c2cc608ddcd513bf4d IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00011656
0x1b7d474ed814003f585d6068c14055c371f5cfcfd0b2efc57cab6cdca54f863aSwap Eth To Curv...260956432022-09-23 4:09:0911 days 6 hrs ago0xa65d3a4ebfe4952ca15ab983a20243e34227e11d IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.01 ETH0.00008364
0x5b16172c928fc2b2a0399e6aca5da8659f7ffabf9ab692772850e1fc8e43da02Swap Eth To Curv...260953042022-09-23 4:06:4111 days 7 hrs ago0xa65d3a4ebfe4952ca15ab983a20243e34227e11d IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.01 ETH0.00010462
0x40ad09e31bfdffcef8cc53456f0f7a4825086ecae73542e2276e56108d6dae78Swap Eth To Curv...260814082022-09-23 2:32:1811 days 8 hrs ago0xa65d3a4ebfe4952ca15ab983a20243e34227e11d IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.01 ETH0.00009925
0x42c77320af68c64b82c89efbbc123a75f6b65a386c04031f53aa854f8c1ce71aSwap Eth To Curv...260812022022-09-23 2:30:5311 days 8 hrs ago0xeed6ce804e0cf9fa0425c03673c0385ed1e02070 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.01 ETH0.00009756
0xc5d5c917d6ebae9b0a6c35dbf0665972ed8910e01ec6f57b55a8db6dfa26502dSwap Eth To Curv...249462942022-09-16 22:52:4217 days 12 hrs ago0x89daf53324596f9c6df523d3e690fad7c2ff5e82 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.05 ETH0.00014796
0xa5dd0f7ec9faff0e0aacb21abb76fe0104ccaf1b70eda14e70dafa09744d0d24Swap Eth To Curv...249462422022-09-16 22:51:5617 days 12 hrs ago0x89daf53324596f9c6df523d3e690fad7c2ff5e82 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.05 ETH0.00015127
0x58791e09dc3d1505c4d8cb94516be60441832b8649d5966d4e25443aafa44952Swap Eth To Curv...247457522022-09-15 13:22:3018 days 21 hrs ago0xa988d20d89b19d36d5739641a1017b80d6b0b419 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.00001 ETH0.00012652
0x171448ce8efc35de180ac344d59687e363c84f6bebedd46c04a2bb47ec61eed0Swap Eth To Curv...246593112022-09-14 22:17:3819 days 12 hrs ago0x06c6c199d8fb1d5f68daac1f1d9ad9f6cc23db8a IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.01 ETH0.00023056
0x03e3e7c1c3bab1d44ccdceed2965ed2b8ba95c583b01b3628dbdbcc72079f96cSwap Eth To Curv...246541732022-09-14 21:18:0919 days 13 hrs ago0x86c0c5a48dd7fe52095159918a02b1a6f48e2769 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.001 ETH0.00029657
0x28cc8c855855d83cf27f33cc941cf645690ef74ff977130e5b6532298818c47eSwap Eth To Curv...246541482022-09-14 21:17:4919 days 13 hrs ago0x86c0c5a48dd7fe52095159918a02b1a6f48e2769 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.001 ETH0.00029564
0x824598260a05c6ec9288357fcac830ec115ab541063f9b4d2e981d2c863a96b5Swap Eth To Curv...246533452022-09-14 21:04:1819 days 14 hrs ago0xe5c9b2fa9c9e5fc4fb7cbaa7ad3693e97955f43f IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.001 ETH0.00029905
0x6191be5e9c35fe2efb369718814d6df073ec5ba2d9784ff7c955fced45fc006aSwap Eth To Curv...246393222022-09-14 18:14:0519 days 16 hrs ago0x8e8d616580d9c786d13ddf1cd694200d888afc00 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930.001 ETH0.0001922
0x2b768f5c6ba027394b1a8a2ce7776227f486781f765fd113801b8b9aca624482Swap Hlp Token T...241872792022-09-12 5:11:1722 days 5 hrs ago0xeed6ce804e0cf9fa0425c03673c0385ed1e02070 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00012731
0xe084606accfbdf5c9643dd2f0e6143c63642e6488e30498c4906e9a6620f1896Swap Pegged Toke...236052922022-09-08 14:59:3525 days 20 hrs ago0x50b04bb49055f00e80fda852940f48edf55a6ad4 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00012176
0x00165ff77624615dc8a7c873cf97deba443aa479189c915f10afc1e44f903be6Set Hpsm231032712022-09-06 7:11:4228 days 3 hrs ago0x420220b72bbd307db8615e7aa0eadca399cf2fc0 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00001069
0x46447f64646947559899c2ff736ae529c8c53de275cf83869e6b588b24c8a386Swap Hlp Token T...230268112022-09-05 20:45:4128 days 14 hrs ago0xeed6ce804e0cf9fa0425c03673c0385ed1e02070 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00269307
0xe79ac8ad83be5acfdb820ef38bc7d0f095cfccf47851e323dc391444783a2997Swap Pegged Toke...229276642022-09-05 8:37:4929 days 2 hrs ago0xc871e14826586d22e4abddbf6741c941842fc8bf IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.0011826
0x5e02b0c541e5fa2db799c1378950b3e0b25a0d80a9aab25e99ab71f034b06f7bSwap Hlp Token T...228279312022-09-04 15:43:3329 days 19 hrs ago0xa052e533c4de9c8f2d680606868d20557ced2de9 IN  0x559844b1df66e247f83ba58bc39fa488a1af10930 ETH0.00171659
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af10930xd0dd5d76cf0fc06dabc48632735566dca241a35e0 ETH
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 handle.fi: fxUSD0 ETH
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xb17b674d9c5cb2e441f8e196a2f048a81355d0310 ETH
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 handle.fi: fxUSD0 ETH
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0x851abad9a78609ef44db07bfbbe55748731513a60 ETH
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0x1ae27d9068dadf10f611367332d162d184ed34140 ETH
0x3d1c3fdfc57d124f7359c9521064cd58b1a39350fbb0c1c4bb87d360a317434c282115772022-10-03 18:56:4816 hrs 10 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0x1ae27d9068dadf10f611367332d162d184ed34140 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af10930xd0dd5d76cf0fc06dabc48632735566dca241a35e0 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 handle.fi: fxUSD0 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xb17b674d9c5cb2e441f8e196a2f048a81355d0310 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 handle.fi: fxUSD0 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0x851abad9a78609ef44db07bfbbe55748731513a60 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 handle.fi: fxEUR0 ETH
0x95caf0d1a7a6dfc6d74e62305e646a6806e1313272d80889ccc3fb570d95296f282104122022-10-03 18:45:0416 hrs 21 mins ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 handle.fi: fxEUR0 ETH
0xbd23061c3f2e729f51207d44048bdfd7e400a9e5813658ec3e07774e763b2c42272839842022-09-28 20:22:495 days 14 hrs ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xd22a58f79e9481d1a88e00c343885a588b34b68b0 ETH
0xbd23061c3f2e729f51207d44048bdfd7e400a9e5813658ec3e07774e763b2c42272839842022-09-28 20:22:495 days 14 hrs ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xd22a58f79e9481d1a88e00c343885a588b34b68b0 ETH
0xbd23061c3f2e729f51207d44048bdfd7e400a9e5813658ec3e07774e763b2c42272839842022-09-28 20:22:495 days 14 hrs ago 0x559844b1df66e247f83ba58bc39fa488a1af10930xb0d2eb3c2ca3c6916fab8dcbf9d9c165649231ae0 ETH
0xbd23061c3f2e729f51207d44048bdfd7e400a9e5813658ec3e07774e763b2c42272839842022-09-28 20:22:495 days 14 hrs ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 handle.fi: fxEUR0 ETH
0xbd23061c3f2e729f51207d44048bdfd7e400a9e5813658ec3e07774e763b2c42272839842022-09-28 20:22:495 days 14 hrs ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0xb17b674d9c5cb2e441f8e196a2f048a81355d0310 ETH
0xbd23061c3f2e729f51207d44048bdfd7e400a9e5813658ec3e07774e763b2c42272839842022-09-28 20:22:495 days 14 hrs ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 handle.fi: fxEUR0 ETH
0xbd23061c3f2e729f51207d44048bdfd7e400a9e5813658ec3e07774e763b2c42272839842022-09-28 20:22:495 days 14 hrs ago 0x559844b1df66e247f83ba58bc39fa488a1af1093 0x69328f23a090e57378e3120f622ed0697f0e7ecf0 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
RouterHpsmHlpCurveV2

Compiler Version
v0.8.7+commit.e28d00a7

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 26 : RouterHpsmHlpCurveV2.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./interfaces/IMetapoolFactory.sol";
import "./interfaces/IStableSwap.sol";
import "./interfaces/IRouter.sol";
import "./utils/HpsmUtils.sol";
import "./utils/HlpRouterUtils.sol";
import "./RouterHpsmHlpV2.sol";
import "./interfaces/IWETH.sol";

/**
 * This contract swaps a pegged token in the handle.fi Peg Stability Module (hPSM) to
 * a token in a specified handle curve metapool, via a token in the handle.fi
 * Liquidity Pool (hLP) if applicable.
 *
 * @dev safeApprove is intentionally not used, as since this contract should not store
 * funds between transactions, the approval race vulnerability does not apply.
 *
 *                ,.-"""-.,                       *
 *               /   ===   \                      *
 *              /  =======  \                     *
 *           __|  (o)   (0)  |__                  *
 *          / _|    .---.    |_ \                 *
 *         | /.----/ O O \----.\ |                *
 *          \/     |     |     \/                 *
 *          |                   |                 *
 *          |                   |                 *
 *          |                   |                 *
 *          _\   -.,_____,.-   /_                 *
 *      ,.-"  "-.,_________,.-"  "-.,             *
 *     /          |       |  ╭-╮     \            *
 *    |           l.     .l  ┃ ┃      |           *
 *    |            |     |   ┃ ╰━━╮   |           *
 *    l.           |     |   ┃ ╭╮ ┃  .l           *
 *     |           l.   .l   ┃ ┃┃ ┃  | \,         *
 *     l.           |   |    ╰-╯╰-╯ .l   \,       *
 *      |           |   |           |      \,     *
 *      l.          |   |          .l        |    *
 *       |          |   |          |         |    *
 *       |          |---|          |         |    *
 *       |          |   |          |         |    *
 *       /"-.,__,.-"\   /"-.,__,.-"\"-.,_,.-"\    *
 *      |            \ /            |         |   *
 *      |             |             |         |   *
 *       \__|__|__|__/ \__|__|__|__/ \_|__|__/    *
 */
contract RouterHpsmHlpCurveV2 is BaseRouter, HpsmUtils, HlpRouterUtils {
    using SafeERC20 for IERC20;

    /** @notice Address of the handle.fi RouterHpsmHlp */
    address public routerHpsmHlp;

    event ChangeRouterHpsmHlp(address indexed routerHpsmHlp);

    constructor(
        address _hpsm,
        address _routerHpsmHlp,
        address _hlpRouter
    ) HpsmUtils(_hpsm) HlpRouterUtils(_hlpRouter) {
        routerHpsmHlp = _routerHpsmHlp;
        emit ChangeRouterHpsmHlp(_routerHpsmHlp);
    }

    /** @notice Sets the address of the handle.fi RouterHpsmHlp */
    function setRouterHpsmHlp(address _routerHpsmHlp) external onlyOwner {
        require(routerHpsmHlp != _routerHpsmHlp, "Address already set");
        routerHpsmHlp = _routerHpsmHlp;
        emit ChangeRouterHpsmHlp(_routerHpsmHlp);
    }

    /**
     * @dev Wraps msg.value from ETH to WETH and transfers it to {receiver}
     * @param weth the Wrapped Ether contract to use
     */
    function _wrapETH(address weth) private {
        IWETH(weth).deposit{value: msg.value}();
    }

    /**
     * @notice Swaps tokens in a curve.fi metapool
     * @param from the token to be sent
     * @param to the token to be received
     * @param amount the amount of {from} to send
     * @param metapoolFactory curve.fi metapool factory (the factory that deployed {pool})
     * @param pool The metapool that has {from} and {to} as either tokens or underlying tokens
     * @return the amount of {to} received from the swap
     */
    function _curvePoolSwap(
        address from,
        address to,
        uint256 amount,
        address metapoolFactory,
        address pool
    ) private returns (uint256) {
        (
            int128 fromIndex,
            int128 toIndex,
            bool useUnderlying
        ) = IMetapoolFactory(metapoolFactory).get_coin_indices(pool, from, to);

        IERC20(from).approve(pool, amount);

        // min out is not handled here, which is why the last param is zero
        if (useUnderlying) {
            return
                IStableSwap(pool).exchange_underlying(
                    fromIndex,
                    toIndex,
                    amount,
                    0
                );
        }

        return IStableSwap(pool).exchange(fromIndex, toIndex, amount, 0);
    }

    /**
     * @notice swaps {peggedToken} for {curveToken}, using the hPSM and hLP (if applicable) as intermediate steps
     * @param peggedToken the pegged token in the hPSM to be sent
     * @param fxToken the token in the hPSM that is pegged against {peggedToken}
     * @param hlpToken the token received when swapping {fxToken} in the hLP
     * @dev if {fxToken} is the same as {hlpToken}, no swap between the two will occur
     * @param tokenOut the token received when swapping {hlpToken} in the curve.fi metapool.
     * This token will be sent to {receiver}
     * @param amountIn the amount of {peggedToken} to be sent
     * @param receiver the address that will receive {tokenOut} at the end of the transaction
     * @param minOut the minimum amount of {tokenOut} that will be sent to {receiver}
     * @dev If the amount out is less than {minOut}, the transaction will revert
     * @param metapoolFactory curve.fi metapool factory (the factory that deployed {pool})
     * @param pool The metapool that has {hlpToken} and {tokenOut} as either tokens or underlying tokens
     * @param signedQuoteData The signed quote data to be sent to the handle.fi fast oracles
     * @dev {signedQuoteData} is only required if {fxToken} is not the same as {hlpToken}
     */
    function swapPeggedTokenToCurveToken(
        address peggedToken,
        address fxToken,
        address hlpToken,
        address tokenOut,
        uint256 amountIn,
        address receiver,
        uint256 minOut,
        address metapoolFactory,
        address pool,
        bytes calldata signedQuoteData
    ) external {
        require(peggedToken != tokenOut, "Token in cannot be token out");
        require(amountIn > 0, "Amount in cannot be zero");

        _transferIn(peggedToken, amountIn); // transfer in funds

        if (fxToken == hlpToken) {
            // if fxToken and hlpToken are the same, only one swap in the
            // hpsm needs to be made
            _hpsmDeposit(peggedToken, fxToken, amountIn);
        } else {
            // use multi step router if fx token and hlp token are different
            IERC20(peggedToken).approve(routerHpsmHlp, amountIn);
            RouterHpsmHlpV2(routerHpsmHlp).swapPeggedTokenToHlpToken(
                peggedToken,
                fxToken,
                hlpToken,
                amountIn,
                0, // min out handled at end of function
                _self,
                signedQuoteData
            );
        }

        uint256 curveTokenAmountIn = _balanceOfSelf(hlpToken);
        _curvePoolSwap(
            hlpToken,
            tokenOut,
            curveTokenAmountIn,
            metapoolFactory,
            pool
        );

        uint256 amountOut = _balanceOfSelf(tokenOut);
        require(amountOut >= minOut, "Insufficient amount out");

        IERC20(tokenOut).safeTransfer(receiver, amountOut);
    }

    /**
     * @notice swaps {hlpToken} for {tokenOut}, using the hLP and curve.fi pools
     * @dev this immediately calls _swapHlpTokenToCurveToken, but transfers in the appropriate token first
     * @param hlpToken the token that will be swapped for {hlpCurveToken} in the hLP
     * @param hlpCurveToken the token that will be swapped for {tokenOut} in the curve.fi pool
     * @param tokenOut the token received when swapping {hlpCurveToken} in the curve.fi metapool.
     * This token will be sent to {receiver}
     * @param amountIn the amount of {hlpToken} to be sent
     * @param receiver the address that will receive {tokenOut} at the end of the transaction
     * @param minOut the minimum amount of {tokenOut} that will be sent to {receiver}
     * @dev If the amount out is less than {minOut}, the transaction will revert
     * @param metapoolFactory curve.fi metapool factory (the factory that deployed {pool})
     * @param pool The metapool that has {hlpCurveToken} and {tokenOut} as either tokens or underlying tokens
     * @param signedQuoteData The signed quote data to be sent to the handle.fi fast oracles
     */
    function swapHlpTokenToCurveToken(
        address hlpToken,
        address hlpCurveToken,
        address tokenOut,
        uint256 amountIn,
        address receiver,
        uint256 minOut,
        address metapoolFactory,
        address pool,
        bytes calldata signedQuoteData
    ) external {
        _transferIn(hlpToken, amountIn);
        _swapHlpTokenToCurveToken(
            hlpToken,
            hlpCurveToken,
            tokenOut,
            amountIn,
            receiver,
            minOut,
            metapoolFactory,
            pool,
            signedQuoteData
        );
    }

    /**
     * @dev this has the same documentation as swapHlpToCurveToken (the external
     * version of this function)
     */
    function _swapHlpTokenToCurveToken(
        address hlpToken,
        address hlpCurveToken,
        address tokenOut,
        uint256 amountIn,
        address receiver,
        uint256 minOut,
        address metapoolFactory,
        address pool,
        bytes calldata signedQuoteData
    ) private {
        require(hlpToken != hlpCurveToken, "Must use curve pool directly");
        require(hlpCurveToken != tokenOut, "Must use HlpRouter directly");
        require(amountIn > 0, "Amount in cannot be zero");

        address[] memory path = new address[](2);
        path[0] = hlpToken;
        path[1] = hlpCurveToken;

        // swap to valid curve token
        IERC20(hlpToken).approve(hlpRouter, amountIn);
        IRouter(hlpRouter).swap(
            path,
            amountIn,
            0, // min out handled later
            _self,
            signedQuoteData
        );

        // swap from hlpCurve token to tokenOut
        uint256 curveAmountIn = _balanceOfSelf(hlpCurveToken);

        require(curveAmountIn > 0, "No curve token received");

        _curvePoolSwap(
            hlpCurveToken,
            tokenOut,
            curveAmountIn,
            metapoolFactory,
            pool
        );

        uint256 amountOut = _balanceOfSelf(tokenOut);
        require(amountOut >= minOut, "Insufficient amount out");

        IERC20(tokenOut).safeTransfer(receiver, amountOut);
    }

    /**
     * @notice swaps ETH for {tokenOut} via WETH using the hLP and curve.fi pools
     * @dev amount in is the msg.value when calling this function
     * @param hlpCurveToken the token that will be swapped for {tokenOut} in the curve.fi pool
     * @param tokenOut the token received when swapping {hlpCurveToken} in the curve.fi metapool.
     * This token will be sent to {receiver}
     * @param receiver the address that will receive {tokenOut} at the end of the transaction
     * @param minOut the minimum amount of {tokenOut} that will be sent to {receiver}
     * @dev If the amount out is less than {minOut}, the transaction will revert
     * @param metapoolFactory curve.fi metapool factory (the factory that deployed {pool})
     * @param pool The metapool that has {hlpCurveToken} and {tokenOut} as either tokens or underlying tokens
     * @param signedQuoteData The signed quote data to be sent to the handle.fi fast oracles
     * @dev this still requires WETH to be approved to this contract, equal to the msg.value as this function is
     * just a wrapper
     */
    function swapEthToCurveToken(
        address hlpCurveToken,
        address tokenOut,
        address receiver,
        uint256 minOut,
        address metapoolFactory,
        address pool,
        bytes calldata signedQuoteData
    ) external payable {
        address weth = IRouter(hlpRouter).weth();
        _wrapETH(weth);

        _swapHlpTokenToCurveToken(
            weth,
            hlpCurveToken,
            tokenOut,
            msg.value,
            receiver,
            minOut,
            metapoolFactory,
            pool,
            signedQuoteData
        );
    }
}

File 2 of 26 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

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

File 3 of 26 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.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));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

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

File 4 of 26 : IMetapoolFactory.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.7;

/**
 * Documentation based on https://curve.readthedocs.io/factory-deployer.html
 */
interface IMetapoolFactory {
    /**
     * Convert coin addresses into indices for use with pool methods.
     *
     * Returns the index of _from, index of _to, and a boolean indicating
     * if the coins are considered underlying in the given pool.
     *
     * @dev Example:
     *      >>> factory.get_coin_indices(pool, token1, token2)
     *      (0, 2, true)
     *
     * Based on the above call, we know:
     *  - the index of the coin we are swapping out of is 2
     *  - the index of the coin we are swapping into is 1
     *  - the coins are considred underlying, so we must call exchange_underlying
     *
     * From this information we can perform a token swap:
     *      >>> swap = Contract('0xFD9f9784ac00432794c8D370d4910D2a3782324C')
     *      >>> swap.exchange_underlying(2, 1, 1e18, 0, {'from': alice})
     */
    function get_coin_indices(
        address pool,
        address _from,
        address _to
    )
        external
        view
        returns (
            int128,
            int128,
            bool
        );
}

File 5 of 26 : IStableSwap.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.7;

/**
 * Documentation based on https://curve.readthedocs.io/factory-pools.html
 */
interface IStableSwap {
    /**
     * Perform an exchange between two underlying coins.
     * Index values can be found using get_underlying_coins within the factory contract.
     *
     * @param i Index value of the underlying token to send.
     * @param j Index value of the underlying token to receive.
     * @param _dx: The amount of i being exchanged.
     * @param _min_dy: The minimum amount of j to receive. If the swap would result in
     * less, the  * transaction will revert.
     *
     * @return the amount of j received in the exchange.
     */
    function exchange(
        int128 i,
        int128 j,
        uint256 _dx,
        uint256 _min_dy
    ) external returns (uint256);

    /**
     * Performs an exchange between two tokens.
     * Index values can be found using the coins public getter method,
     * or get_coins within the factory contract.
     *
     * @param i Index value of the token to send.
     * @param j Index value of the token to receive.
     * @param _dx: The amount of i being exchanged.
     * @param _min_dy: The minimum amount of j to receive. If the swap would result in
     * less, the  * transaction will revert.
     *
     * @return the amount of j received in the exchange.
     */
    function exchange_underlying(
        int128 i,
        int128 j,
        uint256 _dx,
        uint256 _min_dy
    ) external returns (uint256);
}

File 6 of 26 : IRouter.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.7;

interface IRouter {
    function weth() external returns (address);

    function swap(
        address[] memory _path,
        uint256 _amountIn,
        uint256 _minOut,
        address _receiver,
        bytes calldata signedQuoteData
    ) external;

    function swapTokensToETH(
        address[] memory _path,
        uint256 _amountIn,
        uint256 _minOut,
        address payable _receiver,
        bytes calldata signedQuoteData
    ) external;

    function swapETHToTokens(
        address[] memory _path,
        uint256 _minOut,
        address _receiver,
        bytes calldata signedQuoteData
    ) external payable;
}

File 7 of 26 : HpsmUtils.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@handle-fi/handle-psm/contracts/hPSM.sol";

/*
 * @dev safeApprove is intentionally not used, as since this contract should not store
 * funds between transactions, the approval race vulnerability does not apply.
 */
abstract contract HpsmUtils is Ownable {
    using SafeERC20 for IERC20;

    address public hpsm;

    event ChangeHpsm(address newPsm);

    constructor(address _hpsm) {
        hpsm = _hpsm;
        emit ChangeHpsm(hpsm);
    }

    /** @notice Sets the peg stability module address*/
    function setHpsm(address _hpsm) external onlyOwner {
        require(hpsm != _hpsm, "Address already set");
        hpsm = _hpsm;
        emit ChangeHpsm(hpsm);
    }

    /**
     * @notice Deposits pegged token for fxToken in the hPSM
     * @param peggedToken the token to be deposited
     * @param fxToken the token to receive
     * @param amount the amount of {peggedToken} to deposit
     */
    function _hpsmDeposit(
        address peggedToken,
        address fxToken,
        uint256 amount
    ) internal {
        // approve hPSM for amount
        IERC20(peggedToken).approve(hpsm, amount);

        // deposit in hPSM
        hPSM(hpsm).deposit(fxToken, peggedToken, amount);
    }

    /**
     * @notice Withdraws peggedToken for fxToken in
     * @param fxToken the token to burn
     * @param peggedToken the token to receive
     * @param amount the amount of {fxToken} to burn
     */
    function _hpsmWithdraw(
        address fxToken,
        address peggedToken,
        uint256 amount
    ) internal {
        // No approval is needed as the hpsm can mint/burn fxtokens
        hPSM(hpsm).withdraw(fxToken, peggedToken, amount);
    }
}

File 8 of 26 : HlpRouterUtils.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@handle-fi/handle-psm/contracts/hPSM.sol";

abstract contract HlpRouterUtils is Ownable {
    address public hlpRouter;

    event ChangeHlpRouter(address newHlpRouter);

    constructor(address _hlpRouter) {
        hlpRouter = _hlpRouter;

        emit ChangeHlpRouter(_hlpRouter);
    }

    /** @notice Sets the router address */
    function setHlpRouter(address _hlpRouter) external onlyOwner {
        require(hlpRouter != _hlpRouter, "Address already set");
        hlpRouter = _hlpRouter;
        emit ChangeHlpRouter(hlpRouter);
    }
}

File 9 of 26 : RouterHpsmHlpV2.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@handle-fi/handle-psm/contracts/hPSM.sol";
import "./interfaces/IRouter.sol";
import "./utils/HlpRouterUtils.sol";
import "./utils/BaseRouter.sol";
import "./utils/HpsmUtils.sol";

/**
 * This contract:
 *     - swaps a pegged token in the handle.fi Peg Stability Module (hPSM) to
 *         a token (or ETH, if applicable) in the handle.fi Liquidity Pool (hLP)
 *     - swaps a token (or ETH) in the hLP for a pegged token in the hPSM
 *
 * @dev safeApprove is intentionally not used, as since this contract should not store
 * funds between transactions, the approval race vulnerability does not apply.
 *
 *                ,.-"""-.,                       *
 *               /   ===   \                      *
 *              /  =======  \                     *
 *           __|  (o)   (0)  |__                  *
 *          / _|    .---.    |_ \                 *
 *         | /.----/ O O \----.\ |                *
 *          \/     |     |     \/                 *
 *          |                   |                 *
 *          |                   |                 *
 *          |                   |                 *
 *          _\   -.,_____,.-   /_                 *
 *      ,.-"  "-.,_________,.-"  "-.,             *
 *     /          |       |  ╭-╮     \            *
 *    |           l.     .l  ┃ ┃      |           *
 *    |            |     |   ┃ ╰━━╮   |           *
 *    l.           |     |   ┃ ╭╮ ┃  .l           *
 *     |           l.   .l   ┃ ┃┃ ┃  | \,         *
 *     l.           |   |    ╰-╯╰-╯ .l   \,       *
 *      |           |   |           |      \,     *
 *      l.          |   |          .l        |    *
 *       |          |   |          |         |    *
 *       |          |---|          |         |    *
 *       |          |   |          |         |    *
 *       /"-.,__,.-"\   /"-.,__,.-"\"-.,_,.-"\    *
 *      |            \ /            |         |   *
 *      |             |             |         |   *
 *       \__|__|__|__/ \__|__|__|__/ \_|__|__/    *
 */
contract RouterHpsmHlpV2 is BaseRouter, HpsmUtils, HlpRouterUtils {
    using SafeERC20 for IERC20;

    constructor(address _hpsm, address _hlpRouter)
        HpsmUtils(_hpsm)
        HlpRouterUtils(_hlpRouter)
    {}

    /**
     * @notice Swaps a pegged token for a fx token.
     * @return the amount of fxToken available after swapping
     */
    function _swapPeggedTokenToFxToken(
        address peggedToken,
        address fxToken,
        uint256 amountIn
    ) internal returns (uint256) {
        // swap pegged token for fxToken
        _hpsmDeposit(peggedToken, fxToken, amountIn);
        // it is safe to use the balance here, as this contract should
        // not hold funds between calls
        return _balanceOfSelf(fxToken);
    }

    /**
     * @notice Swaps a fx token for a pegged token
     * @return the amount of pegged token available after swapping
     */
    function _swapFxTokenToPeggedToken(
        address fxToken,
        address peggedToken,
        uint256 amountIn
    ) internal returns (uint256) {
        // swap pegged token for fxToken
        _hpsmWithdraw(fxToken, peggedToken, amountIn);
        // it is safe to use the balance here, as this contract should
        // not hold funds between calls
        return _balanceOfSelf(peggedToken);
    }

    /**
     * @notice Swaps a pegged token for a hlpToken.
     * @dev this first swaps a pegged token for the fxToken it is pegged against,
     * then swaps the fxToken for the desired hlpToken using the hLP.
     */
    function swapPeggedTokenToHlpToken(
        address peggedToken,
        address fxToken,
        address tokenOut,
        uint256 amountIn,
        uint256 minOut,
        address receiver,
        bytes calldata signedQuoteData
    ) external {
        require(peggedToken != tokenOut, "Cannot convert to same token");
        require(fxToken != tokenOut, "Must use hPSM directly");

        _transferIn(peggedToken, amountIn);

        // swap pegged token to fx token
        uint256 fxTokenAmount = _swapPeggedTokenToFxToken(
            peggedToken,
            fxToken,
            amountIn
        );

        // approve router to access funds
        IERC20(fxToken).approve(hlpRouter, fxTokenAmount);

        address[] memory path = new address[](2);
        path[0] = fxToken;
        path[1] = tokenOut;

        // swap fx token to hlp token
        IRouter(hlpRouter).swap(
            path,
            fxTokenAmount,
            minOut,
            receiver,
            signedQuoteData
        );
    }

    /**
     * @notice Swaps a pegged token for a hlpToken.
     * @dev this first swaps a hlp token for the fx token in the hLP, then swaps
     * the fx token for the pegged token in the hPSM
     * @param hlpToken the token input
     * @param fxToken the intermediate step in the hPSM
     * @param tokenOut the pegged token in the hPSM, for the receiver to receive
     */
    function swapHlpTokenToPeggedToken(
        address hlpToken,
        address fxToken,
        address tokenOut,
        uint256 amountIn,
        uint256 minOut,
        address receiver,
        bytes calldata signedQuoteData
    ) external {
        require(hlpToken != tokenOut, "Cannot convert to same token");
        require(fxToken != tokenOut, "Must use HlpRouter directly");

        _transferIn(hlpToken, amountIn);

        // approve router to access funds
        IERC20(hlpToken).approve(hlpRouter, amountIn);

        address[] memory path = new address[](2);
        path[0] = hlpToken;
        path[1] = fxToken;

        // swap hlp token to fx token
        IRouter(hlpRouter).swap(
            path,
            amountIn,
            0, // no min out needed, will be handled when transferring out
            _self,
            signedQuoteData
        );

        uint256 tokenOutAmount = _swapFxTokenToPeggedToken(
            fxToken,
            tokenOut,
            _balanceOfSelf(fxToken)
        );

        require(tokenOutAmount >= minOut, "Insufficient amount out");
        IERC20(tokenOut).safeTransfer(receiver, tokenOutAmount);
    }

    /**
     * @notice Swaps a pegged token for ETH.
     * @dev this first swaps a pegged token for the fxToken it is pegged against,
     * then swaps the fxToken for ETH.
     */
    function swapPeggedTokenToEth(
        address peggedToken,
        address fxToken,
        uint256 amountIn,
        uint256 minOut,
        address payable receiver,
        bytes calldata signedQuoteData
    ) external {
        _transferIn(peggedToken, amountIn);

        // swap pegged token to fx token
        uint256 fxTokenAmount = _swapPeggedTokenToFxToken(
            peggedToken,
            fxToken,
            amountIn
        );

        // approve router to access funds
        IERC20(fxToken).approve(hlpRouter, fxTokenAmount);

        address[] memory path = new address[](2);
        path[0] = fxToken;
        path[1] = IRouter(hlpRouter).weth(); // router requires last element to be weth for eth swap

        // swap fx token to eth
        IRouter(hlpRouter).swapTokensToETH(
            path,
            fxTokenAmount,
            minOut,
            receiver,
            signedQuoteData
        );
    }

    /**
     * @notice Swaps a ETH for a pegged token.
     * @dev this first swaps eth for the fx token in the hLP, then swaps the fx token
     * for the pegged token in the hPSM
     * @param fxToken the intermediate step in the hPSM
     * @param tokenOut the pegged token in the hPSM, for the receiver to receive
     */
    function swapEthToPeggedToken(
        address fxToken,
        address tokenOut,
        uint256 minOut,
        address receiver,
        bytes calldata signedQuoteData
    ) external payable {
        require(fxToken != tokenOut, "Must use HlpRouter directly");
        require(msg.value > 0, "msg.value must not be zero");

        address[] memory path = new address[](2);
        path[0] = IRouter(hlpRouter).weth();
        path[1] = fxToken;

        // swap hlp token to fx token
        IRouter(hlpRouter).swapETHToTokens{value: msg.value}(
            path,
            0, // no min out needed, will be handled when transferring out
            _self,
            signedQuoteData
        );

        uint256 tokenOutAmount = _swapFxTokenToPeggedToken(
            fxToken,
            tokenOut,
            _balanceOfSelf(fxToken)
        );

        require(tokenOutAmount >= minOut, "Insufficient amount out");
        IERC20(tokenOut).safeTransfer(receiver, tokenOutAmount);
    }
}

File 10 of 26 : IWETH.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.7;

/// IWETH9.sol from https://arbiscan.io/address/0x8b194beae1d3e0788a1a35173978001acdfba668#code
interface IWETH {
    function deposit() external payable;

    function withdraw(uint256 _amount) external;
}

File 11 of 26 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 12 of 26 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 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
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 13 of 26 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        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 {
        _transferOwnership(address(0));
    }

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

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

File 14 of 26 : hPSM.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IHandle.sol";
import "./interfaces/fxToken.sol";

/*                                                *\
 *                ,.-"""-.,                       *
 *               /   ===   \                      *
 *              /  =======  \                     *
 *           __|  (o)   (0)  |__                  *
 *          / _|    .---.    |_ \                 *
 *         | /.----/ O O \----.\ |                *
 *          \/     |     |     \/                 *
 *          |                   |                 *
 *          |                   |                 *
 *          |                   |                 *
 *          _\   -.,_____,.-   /_                 *
 *      ,.-"  "-.,_________,.-"  "-.,             *
 *     /          |       |  ╭-╮     \            *
 *    |           l.     .l  ┃ ┃      |           *
 *    |            |     |   ┃ ╰━━╮   |           *
 *    l.           |     |   ┃ ╭╮ ┃  .l           *
 *     |           l.   .l   ┃ ┃┃ ┃  | \,         *
 *     l.           |   |    ╰-╯╰-╯ .l   \,       *
 *      |           |   |           |      \,     *
 *      l.          |   |          .l        |    *
 *       |          |   |          |         |    *
 *       |          |---|          |         |    *
 *       |          |   |          |         |    *
 *       /"-.,__,.-"\   /"-.,__,.-"\"-.,_,.-"\    *
 *      |            \ /            |         |   *
 *      |             |             |         |   *
 *       \__|__|__|__/ \__|__|__|__/ \_|__|__/    *
\*                                                 */

contract hPSM is Ownable {
    using SafeERC20 for ERC20;
    IHandle public handle;

    /** @dev This contract's address. */
    address private immutable self;
    /** @dev Transaction fee with 18 decimals. */
    uint256 public transactionFee;
    /** @dev Mapping from pegged token address to total deposit supported. */
    mapping(address => uint256) public collateralCap;
    /** @dev Mapping from pegged token address to accrued fee amount. */
    mapping(address => uint256) public accruedFees;
    /** @dev Mapping from fxToken to peg token address to whether the peg is set. */
    mapping(address => mapping(address => bool)) public isFxTokenPegged;
    /** @dev Mapping from fxToken to peg token to deposit amount. */
    mapping(address => mapping(address => uint256)) public fxTokenDeposits;
    /** @dev Whether deposits are paused. */
    bool public areDepositsPaused;

    event SetPauseDeposits(bool isPaused);

    event SetTransactionFee(uint256 fee);
    
    event SetMaximumTokenDeposit(address indexed token, uint256 amount);
    
    event SetFxTokenPeg(
        address indexed fxToken,
        address indexed peggedToken,
        bool isPegged
    );

    event Deposit(
        address indexed fxToken,
        address indexed peggedToken,
        address indexed account,
        uint256 amountIn,
        uint256 amountOut
    );
 
    event Withdraw(
        address indexed fxToken,
        address indexed peggedToken,
        address indexed account,
        uint256 amountIn,
        uint256 amountOut
    );

    constructor(IHandle _handle) {
        require(address(_handle) != address(0), "PSM: handle cannot be null");
        self = address(this);
        handle = _handle;
    }
    
    function collectAccruedFees(address collateralToken) external onlyOwner {
        uint256 amount = accruedFees[collateralToken];
        require(amount > 0, "PSM: no fee accrual");
        ERC20(collateralToken).transfer(msg.sender, amount);
        accruedFees[collateralToken] -= amount;
    }

    /** @dev Sets the transaction fee. */
    function setTransactionFee(uint256 fee) external onlyOwner {
        require(fee < 1 ether, "PSM: fee must be < 100%");
        transactionFee = fee;
        emit SetTransactionFee(transactionFee);
    }

    /** @dev Sets whether deposits are paused. */
    function setPausedDeposits(bool isPaused) external onlyOwner {
        areDepositsPaused = isPaused;
        emit SetPauseDeposits(isPaused);
    }

    /** @dev Configures a fxToken peg to a collateral token. */
    function setFxTokenPeg(
        address fxTokenAddress,
        address peggedTokenAddress,
        bool isPegged
    ) external onlyOwner {
        fxToken _fxToken = fxToken(fxTokenAddress);
        assert(isFxTokenPegged[fxTokenAddress][peggedTokenAddress] != isPegged);
        require(
            handle.isFxTokenValid(fxTokenAddress),
            "PSM: not a valid fxToken"
        );
        bytes32 operatorRole = _fxToken.OPERATOR_ROLE();
        require(
            !isPegged || _fxToken.hasRole(operatorRole, self),
            "PSM: not an fxToken operator"
        );
        require(
            !handle.isFxTokenValid(peggedTokenAddress),
            "PSM: not a valid peg token"
        );
        isFxTokenPegged[fxTokenAddress][peggedTokenAddress] = isPegged;
        if (!isPegged)
            _fxToken.renounceRole(operatorRole, self);
        emit SetFxTokenPeg(fxTokenAddress, peggedTokenAddress, isPegged);
    }

    /** @dev Sets the maximum total deposit for a pegged token. */
    function setCollateralCap(
        address peggedToken,
        uint256 capWithPeggedTokenDecimals
    ) external onlyOwner {
        collateralCap[peggedToken] = capWithPeggedTokenDecimals;
        emit SetMaximumTokenDeposit(peggedToken, capWithPeggedTokenDecimals);
    }

    /** @dev Receives a pegged token in exchange for minting fxToken for an account. */
    function deposit(
        address fxTokenAddress,
        address peggedTokenAddress,
        uint256 amount
    ) external {
        require(!areDepositsPaused, "PSM: deposits are paused");
        require(
            isFxTokenPegged[fxTokenAddress][peggedTokenAddress],
            "PSM: fxToken not pegged to peggedToken"
        );
        require(
            amount > 0,
            "PSM: amount must be > 0"
        );
        ERC20 peggedToken = ERC20(peggedTokenAddress);
        require(
            collateralCap[peggedTokenAddress] == 0 ||
                amount + peggedToken.balanceOf(self)
                    <= collateralCap[peggedTokenAddress],
            "PSM: collateral cap exceeded"
        );
        peggedToken.safeTransferFrom(
            msg.sender,
            self,
            amount
        );
        uint256 amountOutGross = calculateAmountForDecimalChange(
            peggedTokenAddress,
            fxTokenAddress,
            amount
        );
        uint256 amountOutNet = calculateAmountAfterFees(
          amountOutGross  
        );
        require(amountOutNet > 0, "PSM: prevented nil transfer");
        updateFeeForCollateral(
            peggedTokenAddress,
            amount,
            calculateAmountAfterFees(amount)
        );
        // Increase fxToken (input) amount from deposits.
        fxTokenDeposits[fxTokenAddress][peggedTokenAddress] += amount;
        fxToken(fxTokenAddress).mint(msg.sender, amountOutNet);
        emit Deposit(
            fxTokenAddress,
            peggedTokenAddress,
            msg.sender,
            amount,
            amountOutNet
        );
    }

    /** @dev Burns an account's fxToken balance in exchange for a pegged token. */
    function withdraw(
        address fxTokenAddress,
        address peggedTokenAddress,
        uint256 amount
    ) external {
        require(
            isFxTokenPegged[fxTokenAddress][peggedTokenAddress],
            "PSM: fxToken not pegged to peggedToken"
        );
        ERC20 peggedToken = ERC20(peggedTokenAddress);
        uint256 amountOutGross = calculateAmountForDecimalChange(
            fxTokenAddress,
            peggedTokenAddress,
            amount
        );
        // While deposits are paused:
        //  - users can still withdraw all the pegged token liquidity currently in the contract
        //  - once the pegged token liquidity runs out, users can no longer call withdraw
        require(
            !areDepositsPaused ||
                fxTokenDeposits[fxTokenAddress][peggedTokenAddress] >= amountOutGross,
            "PSM: paused + no liquidity"
        );
        require(
            peggedToken.balanceOf(self) >= amountOutGross,
            "PSM: contract lacks liquidity"
        );
        fxToken fxToken = fxToken(fxTokenAddress);
        require(
            fxToken.balanceOf(msg.sender) >= amount,
            "PSM: insufficient fx balance"
        );
        fxToken.burn(msg.sender, amount);
        uint256 amountOutNet = calculateAmountAfterFees(
            amountOutGross
        );
        require(amountOutNet > 0, "PSM: prevented nil transfer");
        updateFeeForCollateral(
            peggedTokenAddress,
            amountOutGross,
            amountOutNet
        );
        // Reduce fxToken (amount out, gross) amount from deposits.
        fxTokenDeposits[fxTokenAddress][peggedTokenAddress] -= amountOutGross;
        peggedToken.safeTransfer(msg.sender, amountOutNet);
        emit Withdraw(
            fxTokenAddress,
            peggedTokenAddress,
            msg.sender,
            amount,
            amountOutNet
        );
    }

    /** @dev Converts an input amount to after fees. */
    function calculateAmountAfterFees(uint256 amount) private returns (uint256) {
        return amount * (1 ether - transactionFee) / 1 ether;
    }

    function updateFeeForCollateral(
        address collateralToken,
        uint256 amountGross,
        uint256 amountNet
    ) private{
        if (amountNet == amountGross) return;
        assert(amountNet < amountGross);
        accruedFees[collateralToken] += amountGross - amountNet;
    }

    /** @dev Converts an amount to match a different decimal count. */
    function calculateAmountForDecimalChange(
        address tokenIn,
        address tokenOut,
        uint256 amountIn
    ) private returns (uint256) {
        uint256 decimalsIn = uint256(ERC20(tokenIn).decimals());
        uint256 decimalsOut = uint256(ERC20(tokenOut).decimals());
        if (decimalsIn == decimalsOut) return amountIn;
        uint256 decimalsDiff;
        if (decimalsIn > decimalsOut) {
            decimalsDiff = decimalsIn - decimalsOut;
            return amountIn / (10 ** decimalsDiff);
        }
        decimalsDiff = decimalsOut - decimalsIn;
        return amountIn * (10 ** decimalsDiff);
    }
}

File 15 of 26 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 16 of 26 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

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

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

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

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

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

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

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

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

File 17 of 26 : 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 18 of 26 : fxToken.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./IfxToken.sol";

/*                                                *\
 *                ,.-"""-.,                       *
 *               /   ===   \                      *
 *              /  =======  \                     *
 *           __|  (o)   (0)  |__                  *
 *          / _|    .---.    |_ \                 *
 *         | /.----/ O O \----.\ |                *
 *          \/     |     |     \/                 *
 *          |                   |                 *
 *          |                   |                 *
 *          |                   |                 *
 *          _\   -.,_____,.-   /_                 *
 *      ,.-"  "-.,_________,.-"  "-.,             *
 *     /          |       |  ╭-╮     \            *
 *    |           l.     .l  ┃ ┃      |           *
 *    |            |     |   ┃ ╰━━╮   |           *
 *    l.           |     |   ┃ ╭╮ ┃  .l           *
 *     |           l.   .l   ┃ ┃┃ ┃  | \,         *
 *     l.           |   |    ╰-╯╰-╯ .l   \,       *
 *      |           |   |           |      \,     *
 *      l.          |   |          .l        |    *
 *       |          |   |          |         |    *
 *       |          |---|          |         |    *
 *       |          |   |          |         |    *
 *       /"-.,__,.-"\   /"-.,__,.-"\"-.,_,.-"\    *
 *      |            \ /            |         |   *
 *      |             |             |         |   *
 *       \__|__|__|__/ \__|__|__|__/ \_|__|__/    *
\*                                                 */

contract fxToken is IfxToken, AccessControl, ERC20 {
    bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

    constructor(string memory name_, string memory symbol_)
        ERC20(name_, symbol_)
    {
        _setupRole(ADMIN_ROLE, msg.sender);
        _setRoleAdmin(OPERATOR_ROLE, ADMIN_ROLE);
        _setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
    }

    modifier onlyOperator() {
        require(
            hasRole(OPERATOR_ROLE, msg.sender) ||
                hasRole(ADMIN_ROLE, msg.sender),
            "fxToken: caller not an operator"
        );
        _;
    }

    function mint(address account, uint256 amount)
        external
        override
        onlyOperator
    {
        _mint(account, amount);
    }

    function burn(address account, uint256 amount)
        external
        override
        onlyOperator
    {
        _burn(account, amount);
    }
}

File 19 of 26 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 20 of 26 : AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 21 of 26 : IfxToken.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IfxToken is IERC20 {
    function mint(address account, uint256 amount) external;

    function burn(address account, uint256 amount) external;
}

File 22 of 26 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

File 23 of 26 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

File 24 of 26 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 25 of 26 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 26 of 26 : BaseRouter.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.7;

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

abstract contract BaseRouter {
    using SafeERC20 for IERC20;

    address internal immutable _self;

    constructor() {
        _self = address(this);
    }

    /** @notice Transfers in an ERC20 token */
    function _transferIn(address token, uint256 amount) internal {
        IERC20(token).safeTransferFrom(msg.sender, _self, amount);
    }

    /** @return the {token} balance of this contract */
    function _balanceOfSelf(address token) internal view returns (uint256) {
        return IERC20(token).balanceOf(_self);
    }
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"_hpsm","type":"address"},{"internalType":"address","name":"_routerHpsmHlp","type":"address"},{"internalType":"address","name":"_hlpRouter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newHlpRouter","type":"address"}],"name":"ChangeHlpRouter","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newPsm","type":"address"}],"name":"ChangeHpsm","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"routerHpsmHlp","type":"address"}],"name":"ChangeRouterHpsmHlp","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"},{"inputs":[],"name":"hlpRouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hpsm","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"routerHpsmHlp","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_hlpRouter","type":"address"}],"name":"setHlpRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_hpsm","type":"address"}],"name":"setHpsm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_routerHpsmHlp","type":"address"}],"name":"setRouterHpsmHlp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"hlpCurveToken","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"minOut","type":"uint256"},{"internalType":"address","name":"metapoolFactory","type":"address"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"swapEthToCurveToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"hlpToken","type":"address"},{"internalType":"address","name":"hlpCurveToken","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"minOut","type":"uint256"},{"internalType":"address","name":"metapoolFactory","type":"address"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"swapHlpTokenToCurveToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"peggedToken","type":"address"},{"internalType":"address","name":"fxToken","type":"address"},{"internalType":"address","name":"hlpToken","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"minOut","type":"uint256"},{"internalType":"address","name":"metapoolFactory","type":"address"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"swapPeggedTokenToCurveToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60a06040523480156200001157600080fd5b5060405162001af338038062001af38339810160408190526200003491620001a9565b3060601b608052808362000048336200013c565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527fa42db62e6a6fb46d8d03431106cca836fa4c9e4d41105d56dcd444dc85d340279060200160405180910390a150600280546001600160a01b0319166001600160a01b0383169081179091556040519081527f5925f04423116cdea53e5558436f8d05707fad7bd8206910ad09925cd5fec19a9060200160405180910390a150600380546001600160a01b0319166001600160a01b0384169081179091556040517f8108e6dae0c82a8b5f80c241b07f9d8ce44b800447c82ac24935189c637129dd90600090a2505050620001f3565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b0381168114620001a457600080fd5b919050565b600080600060608486031215620001bf57600080fd5b620001ca846200018c565b9250620001da602085016200018c565b9150620001ea604085016200018c565b90509250925092565b60805160601c6118cc62000227600039600081816103d0015281816107be015281816108f80152610f3501526118cc6000f3fe6080604052600436106100a75760003560e01c8063b7207e1411610064578063b7207e141461017d578063ba40e98b1461019d578063c7b65d34146101bd578063d890a33c146101dd578063f2fde38b146101fd578063fb6174e21461021d57600080fd5b80633d2ac218146100ac5780636b60bba8146100e8578063715018a61461010a5780638da5cb5b1461011f578063aa2a4e991461013d578063afa9d1861461015d575b600080fd5b3480156100b857600080fd5b506001546100cc906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b3480156100f457600080fd5b50610108610103366004611408565b610230565b005b34801561011657600080fd5b506101086104c4565b34801561012b57600080fd5b506000546001600160a01b03166100cc565b34801561014957600080fd5b5061010861015836600461158b565b6104d8565b34801561016957600080fd5b506003546100cc906001600160a01b031681565b34801561018957600080fd5b506101086101983660046113ce565b610500565b3480156101a957600080fd5b506101086101b83660046113ce565b61058b565b3480156101c957600080fd5b506101086101d83660046113ce565b61060f565b3480156101e957600080fd5b506002546100cc906001600160a01b031681565b34801561020957600080fd5b506101086102183660046113ce565b61068f565b61010861022b3660046114e1565b610708565b876001600160a01b03168b6001600160a01b031614156102975760405162461bcd60e51b815260206004820152601c60248201527f546f6b656e20696e2063616e6e6f7420626520746f6b656e206f75740000000060448201526064015b60405180910390fd5b600087116102e25760405162461bcd60e51b8152602060048201526018602482015277416d6f756e7420696e2063616e6e6f74206265207a65726f60401b604482015260640161028e565b6102ec8b886107ae565b886001600160a01b03168a6001600160a01b03161415610316576103118b8b896107e7565b61042f565b60035460405163095ea7b360e01b81526001600160a01b03918216600482015260248101899052908c169063095ea7b390604401602060405180830381600087803b15801561036457600080fd5b505af1158015610378573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039c9190611656565b5060035460405163f12b70d360e01b81526001600160a01b039091169063f12b70d3906103fc908e908e908e908d906000907f0000000000000000000000000000000000000000000000000000000000000000908b908b90600401611712565b600060405180830381600087803b15801561041657600080fd5b505af115801561042a573d6000803e3d6000fd5b505050505b600061043a8a6108e1565b90506104498a8a838888610984565b5060006104558a6108e1565b9050868110156104a15760405162461bcd60e51b8152602060048201526017602482015276125b9cdd59999a58da595b9d08185b5bdd5b9d081bdd5d604a1b604482015260640161028e565b6104b56001600160a01b038b168983610be7565b50505050505050505050505050565b6104cc610c4f565b6104d66000610ca9565b565b6104e28a886107ae565b6104f48a8a8a8a8a8a8a8a8a8a610cf9565b50505050505050505050565b610508610c4f565b6002546001600160a01b03828116911614156105365760405162461bcd60e51b815260040161028e90611812565b600280546001600160a01b0319166001600160a01b0383169081179091556040519081527f5925f04423116cdea53e5558436f8d05707fad7bd8206910ad09925cd5fec19a906020015b60405180910390a150565b610593610c4f565b6001546001600160a01b03828116911614156105c15760405162461bcd60e51b815260040161028e90611812565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527fa42db62e6a6fb46d8d03431106cca836fa4c9e4d41105d56dcd444dc85d3402790602001610580565b610617610c4f565b6003546001600160a01b03828116911614156106455760405162461bcd60e51b815260040161028e90611812565b600380546001600160a01b0319166001600160a01b0383169081179091556040517f8108e6dae0c82a8b5f80c241b07f9d8ce44b800447c82ac24935189c637129dd90600090a250565b610697610c4f565b6001600160a01b0381166106fc5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161028e565b61070581610ca9565b50565b60025460408051633fc8cef360e01b815290516000926001600160a01b031691633fc8cef391600480830192602092919082900301818787803b15801561074e57600080fd5b505af1158015610762573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078691906113eb565b905061079181611069565b6107a3818a8a348b8b8b8b8b8b610cf9565b505050505050505050565b6107e36001600160a01b038316337f0000000000000000000000000000000000000000000000000000000000000000846110c0565b5050565b60015460405163095ea7b360e01b81526001600160a01b039182166004820152602481018390529084169063095ea7b390604401602060405180830381600087803b15801561083557600080fd5b505af1158015610849573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061086d9190611656565b50600154604051638340f54960e01b81526001600160a01b03848116600483015285811660248301526044820184905290911690638340f54990606401600060405180830381600087803b1580156108c457600080fd5b505af11580156108d8573d6000803e3d6000fd5b50505050505050565b6040516370a0823160e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166004830152600091908316906370a082319060240160206040518083038186803b15801561094657600080fd5b505afa15801561095a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061097e91906116b4565b92915050565b60405163eb85226d60e01b81526001600160a01b0382811660048301528681166024830152858116604483015260009182918291829187169063eb85226d9060640160606040518083038186803b1580156109de57600080fd5b505afa1580156109f2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a169190611671565b60405163095ea7b360e01b81526001600160a01b038981166004830152602482018c90529396509194509250908a169063095ea7b390604401602060405180830381600087803b158015610a6957600080fd5b505af1158015610a7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aa19190611656565b508015610b4557604051635320bf6b60e11b8152600f84810b600483015283900b602482015260448101889052600060648201526001600160a01b0386169063a6417ed690608401602060405180830381600087803b158015610b0357600080fd5b505af1158015610b17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3b91906116b4565b9350505050610bde565b604051630f7c084960e21b8152600f84810b600483015283900b602482015260448101889052600060648201526001600160a01b03861690633df0212490608401602060405180830381600087803b158015610ba057600080fd5b505af1158015610bb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bd891906116b4565b93505050505b95945050505050565b6040516001600160a01b038316602482015260448101829052610c4a90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526110fe565b505050565b6000546001600160a01b031633146104d65760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161028e565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b886001600160a01b03168a6001600160a01b03161415610d5b5760405162461bcd60e51b815260206004820152601c60248201527f4d7573742075736520637572766520706f6f6c206469726563746c7900000000604482015260640161028e565b876001600160a01b0316896001600160a01b03161415610dbd5760405162461bcd60e51b815260206004820152601b60248201527f4d7573742075736520486c70526f75746572206469726563746c790000000000604482015260640161028e565b60008711610e085760405162461bcd60e51b8152602060048201526018602482015277416d6f756e7420696e2063616e6e6f74206265207a65726f60401b604482015260640161028e565b6040805160028082526060820183526000926020830190803683370190505090508a81600081518110610e3d57610e3d61186b565b60200260200101906001600160a01b031690816001600160a01b0316815250508981600181518110610e7157610e7161186b565b6001600160a01b03928316602091820292909201015260025460405163095ea7b360e01b81529082166004820152602481018a9052908c169063095ea7b390604401602060405180830381600087803b158015610ecd57600080fd5b505af1158015610ee1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f059190611656565b50600254604051630dde87fd60e01b81526001600160a01b0390911690630dde87fd90610f619084908c906000907f0000000000000000000000000000000000000000000000000000000000000000908a908a9060040161176b565b600060405180830381600087803b158015610f7b57600080fd5b505af1158015610f8f573d6000803e3d6000fd5b505050506000610f9e8b6108e1565b905060008111610ff05760405162461bcd60e51b815260206004820152601760248201527f4e6f20637572766520746f6b656e207265636569766564000000000000000000604482015260640161028e565b610ffd8b8b838989610984565b5060006110098b6108e1565b9050878110156110555760405162461bcd60e51b8152602060048201526017602482015276125b9cdd59999a58da595b9d08185b5bdd5b9d081bdd5d604a1b604482015260640161028e565b6104b56001600160a01b038c168a83610be7565b806001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b1580156110a457600080fd5b505af11580156110b8573d6000803e3d6000fd5b505050505050565b6040516001600160a01b03808516602483015283166044820152606481018290526110f89085906323b872dd60e01b90608401610c13565b50505050565b6000611153826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166111d09092919063ffffffff16565b805190915015610c4a57808060200190518101906111719190611656565b610c4a5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161028e565b60606111df84846000856111e9565b90505b9392505050565b60608247101561124a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161028e565b6001600160a01b0385163b6112a15760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161028e565b600080866001600160a01b031685876040516112bd91906116f6565b60006040518083038185875af1925050503d80600081146112fa576040519150601f19603f3d011682016040523d82523d6000602084013e6112ff565b606091505b509150915061130f82828661131a565b979650505050505050565b606083156113295750816111e2565b8251156113395782518084602001fd5b8160405162461bcd60e51b815260040161028e91906117df565b803561135e81611881565b919050565b8051801515811461135e57600080fd5b60008083601f84011261138557600080fd5b50813567ffffffffffffffff81111561139d57600080fd5b6020830191508360208285010111156113b557600080fd5b9250929050565b8051600f81900b811461135e57600080fd5b6000602082840312156113e057600080fd5b81356111e281611881565b6000602082840312156113fd57600080fd5b81516111e281611881565b60008060008060008060008060008060006101408c8e03121561142a57600080fd5b8b3561143581611881565b9a5060208c013561144581611881565b995060408c013561145581611881565b985060608c013561146581611881565b975060808c0135965061147a60a08d01611353565b955060c08c0135945061148f60e08d01611353565b935061149e6101008d01611353565b92506101208c013567ffffffffffffffff8111156114bb57600080fd5b6114c78e828f01611373565b915080935050809150509295989b509295989b9093969950565b60008060008060008060008060e0898b0312156114fd57600080fd5b883561150881611881565b9750602089013561151881611881565b9650604089013561152881611881565b955060608901359450608089013561153f81611881565b935060a089013561154f81611881565b925060c089013567ffffffffffffffff81111561156b57600080fd5b6115778b828c01611373565b999c989b5096995094979396929594505050565b6000806000806000806000806000806101208b8d0312156115ab57600080fd5b8a356115b681611881565b995060208b01356115c681611881565b985060408b01356115d681611881565b975060608b0135965060808b01356115ed81611881565b955060a08b0135945060c08b013561160481611881565b935060e08b013561161481611881565b92506101008b013567ffffffffffffffff81111561163157600080fd5b61163d8d828e01611373565b915080935050809150509295989b9194979a5092959850565b60006020828403121561166857600080fd5b6111e282611363565b60008060006060848603121561168657600080fd5b61168f846113bc565b925061169d602085016113bc565b91506116ab60408501611363565b90509250925092565b6000602082840312156116c657600080fd5b5051919050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6000825161170881846020870161183f565b9190910192915050565b6001600160a01b038981168252888116602083015287811660408301526060820187905260808201869052841660a082015260e060c0820181905260009061175d90830184866116cd565b9a9950505050505050505050565b60a0808252875190820181905260009060209060c0840190828b01845b828110156117ad5781516001600160a01b031684529284019290840190600101611788565b505050838201899052604084018890526001600160a01b0387166060850152838103608085015261175d8186886116cd565b60208152600082518060208401526117fe81604085016020870161183f565b601f01601f19169190910160400192915050565b6020808252601390820152721059191c995cdcc8185b1c9958591e481cd95d606a1b604082015260600190565b60005b8381101561185a578181015183820152602001611842565b838111156110f85750506000910152565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b038116811461070557600080fdfea2646970667358221220cf05ac6f698380f2f1420b12765caacb99ae8d62829f84438d4c59395fb2e66e64736f6c63430008070033000000000000000000000000a2b81201f92b2f3081e9e2900cf01942e0bcced300000000000000000000000069328f23a090e57378e3120f622ed0697f0e7ecf000000000000000000000000851abad9a78609ef44db07bfbbe55748731513a6

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000a2b81201f92b2f3081e9e2900cf01942e0bcced300000000000000000000000069328f23a090e57378e3120f622ed0697f0e7ecf000000000000000000000000851abad9a78609ef44db07bfbbe55748731513a6

-----Decoded View---------------
Arg [0] : _hpsm (address): 0xa2b81201f92b2f3081e9e2900cf01942e0bcced3
Arg [1] : _routerHpsmHlp (address): 0x69328f23a090e57378e3120f622ed0697f0e7ecf
Arg [2] : _hlpRouter (address): 0x851abad9a78609ef44db07bfbbe55748731513a6

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000a2b81201f92b2f3081e9e2900cf01942e0bcced3
Arg [1] : 00000000000000000000000069328f23a090e57378e3120f622ed0697f0e7ecf
Arg [2] : 000000000000000000000000851abad9a78609ef44db07bfbbe55748731513a6


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.