Contract 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 2

Txn Hash Method
Block
From
To
Value [Txn Fee]
0xeda7727f59d4fdc98067f41fa12832aa886fc0d6048bee2d679f98f6efca21dcUpdate Magpie Si...225338252022-11-18 13:41:2480 days 7 mins ago0x0dd6f5db21e9cd83409f4df9e2f791748cf5359d IN  0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770 AVAX0.000725425
0x80d5cda684e98f20e704eddd5f39b7db5de3a45a30a95c2e94270aa0b730c735Update Amms223387102022-11-13 20:44:3684 days 17 hrs ago0x0dd6f5db21e9cd83409f4df9e2f791748cf5359d IN  0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770 AVAX0.00881667525
0x3c7d84ce454834747d46f8f6e45c8d336886179155fe8a7a28fb3b68f7eb0931Update Magpie Co...223386082022-11-13 20:41:0684 days 17 hrs ago0x0dd6f5db21e9cd83409f4df9e2f791748cf5359d IN  0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770 AVAX0.00115152525
0x4a07d354f32184bfed74477d568bf5283a0f7d66b183c8ad23710db3e4b561e0Update Magpie Si...223385682022-11-13 20:39:4484 days 17 hrs ago0x0dd6f5db21e9cd83409f4df9e2f791748cf5359d IN  0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770 AVAX0.001152925
0x3c94f54b3dc670d1d7c9b26666660f5282bf096547de70347877d3a6b3658b2c0x60806040223385542022-11-13 20:39:1084 days 17 hrs ago0x0dd6f5db21e9cd83409f4df9e2f791748cf5359d IN  Create: MagpieRouter0 AVAX0.06856852525
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x387f3f1c3e79872f8cef5b34e7b50f59cee226f6304942157d29ce9cff7cb433259092342023-02-06 13:20:1628 mins ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.00700086985771512 AVAX
0x387f3f1c3e79872f8cef5b34e7b50f59cee226f6304942157d29ce9cff7cb433259092342023-02-06 13:20:1628 mins ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.00700086985771512 AVAX
0x40bceaae3798aa06502a8541b0ca0a7e69d2a86f209b5128f90a513068283af8258767572023-02-05 19:00:5618 hrs 47 mins ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc5.003908540944729638 AVAX
0x40bceaae3798aa06502a8541b0ca0a7e69d2a86f209b5128f90a513068283af8258767572023-02-05 19:00:5618 hrs 47 mins ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1775.003908540944729638 AVAX
0x8d160682bf517b6b78ebb9a801be2cd4db3aa23d12377770b8ffda1ccb5fe186257805232023-02-03 13:01:223 days 47 mins ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.498534431502881118 AVAX
0x8d160682bf517b6b78ebb9a801be2cd4db3aa23d12377770b8ffda1ccb5fe186257805232023-02-03 13:01:223 days 47 mins ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.498534431502881118 AVAX
0x16f3b6ea7957870397f8ce4f4b2f344cd26241e7719eab5cb3e78721a604bcb2257756292023-02-03 10:15:003 days 3 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.002292788979706703 AVAX
0x16f3b6ea7957870397f8ce4f4b2f344cd26241e7719eab5cb3e78721a604bcb2257756292023-02-03 10:15:003 days 3 hrs ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.002292788979706703 AVAX
0x88271098891e9a6f7459be995144ff3dc66601c54a96b823411161347507abba257752702023-02-03 10:02:333 days 3 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc2.363897088928177315 AVAX
0x88271098891e9a6f7459be995144ff3dc66601c54a96b823411161347507abba257752702023-02-03 10:02:333 days 3 hrs ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1772.363897088928177315 AVAX
0x2855a8d553edb7cd1c69cf6cbb16c8c9c82540c9d548af08d69e43de797db468257737812023-02-03 9:12:083 days 4 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.094611286439381347 AVAX
0x2855a8d553edb7cd1c69cf6cbb16c8c9c82540c9d548af08d69e43de797db468257737812023-02-03 9:12:083 days 4 hrs ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.094611286439381347 AVAX
0xc5275a5568dd986c39cbec7bf58627e580f029865e16bd39d1bb1b400e762281257734562023-02-03 9:01:113 days 4 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.016702084227117743 AVAX
0xc5275a5568dd986c39cbec7bf58627e580f029865e16bd39d1bb1b400e762281257734562023-02-03 9:01:113 days 4 hrs ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.016702084227117743 AVAX
0x190db5a7121648c2d54585a4b84faa408e3c6be144e523cd5e315e803ac3fe58257734512023-02-03 9:01:013 days 4 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.408957783585551714 AVAX
0x190db5a7121648c2d54585a4b84faa408e3c6be144e523cd5e315e803ac3fe58257734512023-02-03 9:01:013 days 4 hrs ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.408957783585551714 AVAX
0xd6eaf0732fcb6675219714712a39281930e69db53e0e30ba9a4b705c56965799257335042023-02-02 10:43:184 days 3 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.135139669299228386 AVAX
0xd6eaf0732fcb6675219714712a39281930e69db53e0e30ba9a4b705c56965799257335042023-02-02 10:43:184 days 3 hrs ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.135139669299228386 AVAX
0xf7fd97cc55aacf6099dbab5a603806b3f29955440984e5b7a2c25ff0eb894b93256953712023-02-01 13:37:425 days 11 mins ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.080860693330204253 AVAX
0xf7fd97cc55aacf6099dbab5a603806b3f29955440984e5b7a2c25ff0eb894b93256953712023-02-01 13:37:425 days 11 mins ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.080860693330204253 AVAX
0xbca4a40a980e92d0a78fd5182dfba814dc598c35cbbf091a1bfa879ba58a6f67256899362023-02-01 10:35:575 days 3 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.114743236045121749 AVAX
0xbca4a40a980e92d0a78fd5182dfba814dc598c35cbbf091a1bfa879ba58a6f67256899362023-02-01 10:35:575 days 3 hrs ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.114743236045121749 AVAX
0x89786bc25a71e0a64f691aede3776658234ce8c48289ec0894ce35c68f4ce37c256899172023-02-01 10:35:185 days 3 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.114 AVAX
0x89786bc25a71e0a64f691aede3776658234ce8c48289ec0894ce35c68f4ce37c256899172023-02-01 10:35:185 days 3 hrs ago Wrapped AVAX 0x6c166dda5ec1a51100de803ccc5c74c6ce47b1770.114 AVAX
0xafced767f754c3e885da65af2f05b27afb0c38850c6b3505ff57651eed4389d1256657052023-01-31 21:05:345 days 16 hrs ago 0x6c166dda5ec1a51100de803ccc5c74c6ce47b177 0x6141143cf15d3327c17aac4b7bfb79a77a108fcc0.0882 AVAX
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
MagpieRouter

Compiler Version
v0.8.9+commit.e5eed63a

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 26 : MagpieRouter.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./interfaces/balancer-v2/IVault.sol";
import "./interfaces/uniswap-v2/IUniswapV2Router02.sol";
import "./interfaces/uniswap-v3/IUniswapV3Router.sol";
import "./interfaces/IMagpieCurveRouter.sol";
import "./lib/LibAsset.sol";
import "./lib/LibBytes.sol";
import "./lib/LibSwap.sol";
import "./interfaces/IWETH.sol";

contract MagpieRouter is ReentrancyGuard, Ownable, IMagpieRouter {
    using LibSwap for IMagpieRouter.SwapArgs;
    using LibAsset for address;
    using LibBytes for bytes;
    address public magpieCoreAddress;
    address public magpieSimulatorAddress;

    mapping(uint16 => Amm) private amms;

    modifier onlyMagpieCoreOrSimulator() {
        require(msg.sender == magpieCoreAddress || msg.sender == magpieSimulatorAddress, "MagpieRouter: only MagpieCore or MagpieSimulator allowed");
        _;
    }

    function updateMagpieCore(address _magpieCoreAddress) external override onlyOwner {
        magpieCoreAddress = _magpieCoreAddress;
    }

    function updateMagpieSimulator(address _magpieSimulatorAddress) external override onlyOwner {
        magpieSimulatorAddress = _magpieSimulatorAddress;
    }

    function updateAmms(Amm[] calldata _amms) external override onlyOwner {
        require(_amms.length > 0, "MagpieRouter: invalid amms");
        for (uint256 i = 0; i < _amms.length; i++) {
            Amm memory amm = Amm({id: _amms[i].id, index: _amms[i].index, protocolIndex: _amms[i].protocolIndex});

            require(amm.id != address(0), "MagpieRouter: invalid amm address");
            require(amm.index > 0, "MagpieRouter: invalid amm index");
            require(amm.protocolIndex > 0, "MagpieRouter: invalid amm protocolIndex");

            amms[amm.index] = amm;
        }

        emit AmmsUpdated(_amms, msg.sender);
    }

    receive() external payable {}

    function withdraw(address weth, uint256 amount) external override onlyMagpieCoreOrSimulator {
        IWETH(weth).withdraw(amount);
        (bool success, ) = msg.sender.call{value: amount}(new bytes(0));
        require(success, "MagpieRouter: eth transfer failed");
    }

    function swap(SwapArgs memory swapArgs) external override onlyMagpieCoreOrSimulator returns (uint256[] memory amountOuts) {
        amountOuts = new uint256[](swapArgs.routes.length);
        address fromAssetAddress = swapArgs.getFromAssetAddress();
        address toAssetAddress = swapArgs.getToAssetAddress();
        uint256 startingBalance = toAssetAddress.getBalance();
        uint256 amountIn = swapArgs.getAmountIn();

        for (uint256 i = 0; i < swapArgs.routes.length; i++) {
            Route memory route = swapArgs.routes[i];
            Hop memory firstHop = route.hops[0];
            Hop memory lastHop = route.hops[route.hops.length - 1];
            require(fromAssetAddress == swapArgs.assets[firstHop.path[0]], "MagpieRouter: invalid fromAssetAddress");
            require(
                toAssetAddress == swapArgs.assets[lastHop.path[lastHop.path.length - 1]],
                "MagpieRouter: invalid toAssetAddress"
            );

            amountOuts[i] = _swapRoute(route, swapArgs.assets, swapArgs.deadline);
        }

        uint256 amountOut = 0;
        for (uint256 i = 0; i < amountOuts.length; i++) {
            amountOut += amountOuts[i];
        }

        if (fromAssetAddress == toAssetAddress) {
            startingBalance -= amountIn;
        }

        require(toAssetAddress.getBalance() == startingBalance + amountOut, "MagpieRouter: invalid amountOut");

        for (uint256 j = 0; j < swapArgs.assets.length; j++) {
            require(swapArgs.assets[j] != address(0), "MagpieRouter: invalid asset - address0");
        }

        require(amountOut >= swapArgs.amountOutMin, "MagpieRouter: insufficient output amount");

        if (msg.sender == magpieCoreAddress) {
            toAssetAddress.transfer(payable(msg.sender), amountOut);
        }
    }

    function _swapRoute(
        Route memory route,
        address[] memory assets,
        uint256 deadline
    ) private returns (uint256) {
        require(route.hops.length > 0, "MagpieRouter: invalid hop size");
        uint256 lastAmountOut = 0;

        for (uint256 i = 0; i < route.hops.length; i++) {
            uint256 amountIn = i == 0 ? route.amountIn : lastAmountOut;
            Hop memory hop = route.hops[i];
            address toAssetAddress = assets[hop.path[hop.path.length - 1]];
            uint256 beforeSwapBalance = toAssetAddress.getBalance();
            _swapHop(amountIn, hop, assets, deadline);
            uint256 afterSwapBalance = toAssetAddress.getBalance();
            lastAmountOut = afterSwapBalance - beforeSwapBalance;
        }

        return lastAmountOut;
    }

    function _swapHop(
        uint256 amountIn,
        Hop memory hop,
        address[] memory assets,
        uint256 deadline
    ) private {
        Amm memory amm = amms[hop.ammIndex];

        require(amm.id != address(0), "MagpieRouter: invalid amm");
        require(hop.path.length > 1, "MagpieRouter: invalid path size");
        address fromAssetAddress = assets[hop.path[0]];

        if (fromAssetAddress.getAllowance(address(this), amm.id) < amountIn) {
            fromAssetAddress.approve(amm.id, type(uint256).max);
        }

        if (amm.protocolIndex == 1) {
            _swapUniswapV2(amountIn, hop, assets, deadline);
        } else if (amm.protocolIndex == 2 || amm.protocolIndex == 3) {
            _swapBalancerV2(amountIn, hop, assets, deadline);
        } else if (amm.protocolIndex == 6) {
            _swapUniswapV3(amountIn, hop, assets, deadline);
        } else if (amm.protocolIndex == 4 || amm.protocolIndex == 5 || amm.protocolIndex == 7) {
            _swapCurve(amountIn, hop, assets);
        }
    }

    function _swapUniswapV2(
        uint256 amountIn,
        Hop memory hop,
        address[] memory assets,
        uint256 deadline
    ) private {
        Amm memory amm = amms[hop.ammIndex];
        address[] memory path = new address[](hop.path.length);
        for (uint256 i = 0; i < hop.path.length; i++) {
            path[i] = assets[hop.path[i]];
        }
        IUniswapV2Router02(amm.id).swapExactTokensForTokens(amountIn, 0, path, address(this), deadline);
    }

    function _swapUniswapV3(
        uint256 amountIn,
        Hop memory hop,
        address[] memory assets,
        uint256 deadline
    ) private {
        Amm memory amm = amms[hop.ammIndex];
        uint256 poolIdIndex = 0;
        bytes memory path;
        for (uint256 i = 0; i < hop.path.length; i++) {
            path = bytes.concat(path, abi.encodePacked(assets[hop.path[i]]));
            if (i < hop.path.length - 1) {
                path = bytes.concat(path, abi.encodePacked(hop.poolData.toUint24(poolIdIndex)));
                poolIdIndex += 3;
            }
        }
        require(hop.poolData.length == poolIdIndex, "MagpieRouter: poolData is invalid");

        IUniswapV3Router.ExactInputParams memory params = IUniswapV3Router.ExactInputParams(
            path,
            address(this),
            deadline,
            amountIn,
            0
        );
        IUniswapV3Router(amm.id).exactInput(params);
    }

    function _swapBalancerV2(
        uint256 amountIn,
        Hop memory hop,
        address[] memory assets,
        uint256 deadline
    ) private {
        Amm memory amm = amms[hop.ammIndex];
        IVault.BatchSwapStep[] memory swaps = new IVault.BatchSwapStep[](hop.path.length - 1);
        uint256 poolIdIndex = 0;
        IAsset[] memory balancerAssets = new IAsset[](hop.path.length);
        int256[] memory limits = new int256[](hop.path.length);
        for (uint256 i = 0; i < hop.path.length - 1; i++) {
            swaps[i] = IVault.BatchSwapStep({
                poolId: hop.poolData.toBytes32(poolIdIndex),
                assetInIndex: i,
                assetOutIndex: i + 1,
                amount: i == 0 ? amountIn : 0,
                userData: "0x"
            });
            poolIdIndex += 32;
            balancerAssets[i] = IAsset(assets[hop.path[i]]);
            limits[i] = i == 0 ? int256(amountIn) : int256(0);

            if (i == hop.path.length - 2) {
                balancerAssets[i + 1] = IAsset(assets[hop.path[i + 1]]);
                limits[i + 1] = int256(0);
            }
        }
        require(hop.poolData.length == poolIdIndex, "MagpieRouter: poolData is invalid");
        IVault.FundManagement memory funds = IVault.FundManagement({
            sender: address(this),
            fromInternalBalance: false,
            recipient: payable(address(this)),
            toInternalBalance: false
        });

        IVault(amm.id).batchSwap(IVault.SwapKind.GIVEN_IN, swaps, balancerAssets, funds, limits, deadline);
    }

    function _swapCurve(
        uint256 amountIn,
        Hop memory hop,
        address[] memory assets
    ) private {
        Amm memory amm = amms[hop.ammIndex];
        IMagpieCurveRouter(amm.id).exchange(
            IMagpieCurveRouter.ExchangeArgs({
                pool: hop.poolData.toAddress(0),
                from: assets[hop.path[0]],
                to: assets[hop.path[1]],
                amount: amountIn,
                expected: 0,
                receiver: address(this)
            })
        );
    }
}

File 2 of 26 : IMagpieCurveRouter.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

interface IMagpieCurveRouter {
    struct ExchangeArgs {
        address pool;
        address from;
        address to;
        uint256 amount;
        uint256 expected;
        address receiver;
    }

    function exchange(ExchangeArgs calldata exchangeArgs) external returns (uint256 amountOut);
}

File 3 of 26 : LibSwap.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

import "../interfaces/IMagpieCore.sol";
import "../interfaces/IMagpieRouter.sol";
import "../interfaces/IWETH.sol";
import "./LibAssetUpgradeable.sol";

library LibSwap {
    using LibAssetUpgradeable for address;
    using LibSwap for IMagpieRouter.SwapArgs;

    function getFromAssetAddress(IMagpieRouter.SwapArgs memory self) internal pure returns (address) {
        return self.assets[self.routes[0].hops[0].path[0]];
    }

    function getToAssetAddress(IMagpieRouter.SwapArgs memory self) internal pure returns (address) {
        IMagpieRouter.Hop memory hop = self.routes[0].hops[self.routes[0].hops.length - 1];
        return self.assets[hop.path[hop.path.length - 1]];
    }

    function getAmountIn(IMagpieRouter.SwapArgs memory self) internal pure returns (uint256) {
        uint256 amountIn = 0;

        for (uint256 i = 0; i < self.routes.length; i++) {
            amountIn += self.routes[i].amountIn;
        }

        return amountIn;
    }
}

File 4 of 26 : LibAsset.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

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

library LibAsset {
    using LibAsset for address;

    address constant NATIVE_ASSETID = address(0);

    function isNative(address self) internal pure returns (bool) {
        return self == NATIVE_ASSETID;
    }

    function getBalance(address self) internal view returns (uint256) {
        return self.isNative() ? address(this).balance : IERC20(self).balanceOf(address(this));
    }

    function transferFrom(
        address self,
        address from,
        address to,
        uint256 amount
    ) internal {
        SafeERC20.safeTransferFrom(IERC20(self), from, to, amount);
    }

    function increaseAllowance(
        address self,
        address spender,
        uint256 amount
    ) internal {
        require(!self.isNative(), "LibAsset: Allowance can't be increased for native asset");
        SafeERC20.safeIncreaseAllowance(IERC20(self), spender, amount);
    }

    function decreaseAllowance(
        address self,
        address spender,
        uint256 amount
    ) internal {
        require(!self.isNative(), "LibAsset: Allowance can't be decreased for native asset");
        SafeERC20.safeDecreaseAllowance(IERC20(self), spender, amount);
    }

    function transfer(
        address self,
        address payable recipient,
        uint256 amount
    ) internal {
        self.isNative()
            ? Address.sendValue(recipient, amount)
            : SafeERC20.safeTransfer(IERC20(self), recipient, amount);
    }

    function approve(
        address self,
        address spender,
        uint256 amount
    ) internal {
        require(!self.isNative(), "LibAsset: Allowance can't be increased for native asset");
        SafeERC20.safeApprove(IERC20(self), spender, amount);
    }

    function getAllowance(
        address self,
        address owner,
        address spender
    ) internal view returns (uint256) {
        return IERC20(self).allowance(owner, spender);
    }
}

File 5 of 26 : LibBytes.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;
import "../interfaces/IMagpieBridge.sol";

library LibBytes {
    using LibBytes for bytes;

    function toAddress(bytes memory self, uint256 start) internal pure returns (address) {
        return address(uint160(uint256(self.toBytes32(start))));
    }

    function toBool(bytes memory self, uint256 start) internal pure returns (bool) {
        return self.toUint8(start) == 1 ? true : false;
    }

    function toUint8(bytes memory self, uint256 start) internal pure returns (uint8) {
        require(self.length >= start + 1, "LibBytes: toUint8 outOfBounds");
        uint8 tempUint;

        assembly {
            tempUint := mload(add(add(self, 0x1), start))
        }

        return tempUint;
    }

    function toUint16(bytes memory self, uint256 start) internal pure returns (uint16) {
        require(self.length >= start + 2, "LibBytes: toUint16 outOfBounds");
        uint16 tempUint;

        assembly {
            tempUint := mload(add(add(self, 0x2), start))
        }

        return tempUint;
    }

    function toUint24(bytes memory self, uint256 start) internal pure returns (uint24) {
        require(self.length >= start + 3, "LibBytes: toUint24 outOfBounds");
        uint24 tempUint;

        assembly {
            tempUint := mload(add(add(self, 0x3), start))
        }

        return tempUint;
    }

    function toUint64(bytes memory self, uint256 start) internal pure returns (uint64) {
        require(self.length >= start + 8, "LibBytes: toUint64 outOfBounds");
        uint64 tempUint;

        assembly {
            tempUint := mload(add(add(self, 0x8), start))
        }

        return tempUint;
    }

    function toUint256(bytes memory self, uint256 start) internal pure returns (uint256) {
        require(self.length >= start + 32, "LibBytes: toUint256 outOfBounds");
        uint256 tempUint;

        assembly {
            tempUint := mload(add(add(self, 0x20), start))
        }

        return tempUint;
    }

    function toBytes32(bytes memory self, uint256 start) internal pure returns (bytes32) {
        require(self.length >= start + 32, "LibBytes: toBytes32 outOfBounds");
        bytes32 tempBytes32;

        assembly {
            tempBytes32 := mload(add(add(self, 0x20), start))
        }

        return tempBytes32;
    }

    function toBridgeType(bytes memory self, uint256 start) internal pure returns (IMagpieBridge.BridgeType) {
        return self.toUint8(start) == 0 ? IMagpieBridge.BridgeType.Wormhole : IMagpieBridge.BridgeType.Stargate;
    }

    function parse(bytes memory self) internal pure returns (IMagpieBridge.ValidationOutPayload memory payload) {
        uint256 i = 0;

        payload.fromAssetAddress = self.toAddress(i);
        i += 32;

        payload.toAssetAddress = self.toAddress(i);
        i += 32;

        payload.to = self.toAddress(i);
        i += 32;

        payload.recipientCoreAddress = self.toAddress(i);
        i += 32;

        payload.senderAddress = self.toBytes32(i);
        i += 32;

        payload.amountOutMin = self.toUint256(i);
        i += 32;

        payload.swapOutGasFee = self.toUint256(i);
        i += 32;

        payload.amountIn = self.toUint256(i);
        i += 32;

        payload.tokenSequence = self.toUint64(i);
        i += 8;

        payload.senderIntermediaryDecimals = self.toUint8(i);
        i += 1;

        payload.senderNetworkId = self.toUint8(i);
        i += 1;

        payload.recipientNetworkId = self.toUint8(i);
        i += 1;

        payload.bridgeType = self.toBridgeType(i);
        i += 1;

        require(self.length == i, "LibBytes: payload is invalid");
    }

    function parseSgPayload(bytes memory self)
        internal
        pure
        returns (
            uint8 networkId,
            bytes32 senderAddress,
            uint64 coreSequence
        )
    {
        uint256 i = 0;
        networkId = self.toUint8(i);
        i += 1;
        senderAddress = self.toBytes32(i);
        i += 32;
        coreSequence = self.toUint64(i);
        i += 8;
        require(self.length == i, "LibBytes: payload is invalid");
    }
}

File 6 of 26 : IWETH.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.5.0;

interface IWETH {
    function deposit() external payable;

    function transfer(address to, uint256 value) external returns (bool);

    function withdraw(uint256) external;
}

File 7 of 26 : IVault.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

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

import "./IAsset.sol";

interface IVault {
    enum SwapKind {
        GIVEN_IN,
        GIVEN_OUT
    }

    function swap(
        SingleSwap memory singleSwap,
        FundManagement memory funds,
        uint256 limit,
        uint256 deadline
    ) external payable returns (uint256);

    struct SingleSwap {
        bytes32 poolId;
        SwapKind kind;
        IAsset assetIn;
        IAsset assetOut;
        uint256 amount;
        bytes userData;
    }

    function batchSwap(
        SwapKind kind,
        BatchSwapStep[] memory swaps,
        IAsset[] memory assets,
        FundManagement memory funds,
        int256[] memory limits,
        uint256 deadline
    ) external payable returns (int256[] memory);

    struct BatchSwapStep {
        bytes32 poolId;
        uint256 assetInIndex;
        uint256 assetOutIndex;
        uint256 amount;
        bytes userData;
    }

    struct FundManagement {
        address sender;
        bool fromInternalBalance;
        address payable recipient;
        bool toInternalBalance;
    }

    function queryBatchSwap(
        SwapKind kind,
        BatchSwapStep[] memory swaps,
        IAsset[] memory assets,
        FundManagement memory funds
    ) external returns (int256[] memory assetDeltas);
}

File 8 of 26 : IUniswapV3Router.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.6.2;

interface IUniswapV3Router {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

File 9 of 26 : IUniswapV2Router02.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.6.2;

import "./IUniswapV2Router01.sol";

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountETH);

    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;

    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable;

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;
}

File 10 of 26 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

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

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

        _;

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

File 11 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 12 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 13 of 26 : IMagpieCore.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

import "./IMagpieRouter.sol";
import "./IMagpieBridge.sol";

interface IMagpieCore {
    struct Config {
        address weth;
        address pauserAddress;
        address magpieRouterAddress;
        address magpieBridgeAddress;
        address stargateAddress;
        address tokenBridgeAddress;
        address coreBridgeAddress;
        uint8 consistencyLevel;
        uint8 networkId;
    }

    struct SwapInArgs {
        IMagpieRouter.SwapArgs swapArgs;
        IMagpieBridge.ValidationInPayload payload;
        IMagpieBridge.BridgeType bridgeType;
    }

    struct SwapOutArgs {
        IMagpieRouter.SwapArgs swapArgs;
        IMagpieBridge.BridgeArgs bridgeArgs;
    }

    struct WrapSwapConfig {
        bool transferFromSender;
        bool prepareFromAsset;
        bool prepareToAsset;
        bool unwrapToAsset;
        bool swap;
    }

    function updateConfig(Config calldata config) external;

    function swap(IMagpieRouter.SwapArgs calldata args) external payable returns (uint256[] memory amountOuts);

    function swapIn(SwapInArgs calldata swapArgs)
        external
        payable
        returns (
            uint256[] memory amountOuts,
            uint256 depositAmount,
            uint64,
            uint64
        );

    function swapOut(SwapOutArgs calldata args) external returns (uint256[] memory amountOuts);

    function sgReceive(
        uint16 senderChainId,
        bytes memory magpieBridgeAddress,
        uint256 nonce,
        address assetAddress,
        uint256 amount,
        bytes memory payload
    ) external;

    event ConfigUpdated(Config config, address caller);

    event Swapped(IMagpieRouter.SwapArgs swapArgs, uint256[] amountOuts, address caller);

    event SwappedIn(
        SwapInArgs args,
        uint256[] amountOuts,
        uint256 depositAmount,
        uint8 receipientNetworkId,
        uint64 coreSequence,
        uint64 tokenSequence,
        bytes32 senderAddress,
        address caller
    );

    event SwappedOut(
        SwapOutArgs args,
        uint256[] amountOuts,
        uint8 senderNetworkId,
        uint64 coreSequence,
        bytes32 senderAddress,
        address caller
    );

    event GasFeeWithdraw(address indexed tokenAddress, address indexed owner, uint256 indexed amount);
}

File 14 of 26 : LibAssetUpgradeable.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";

library LibAssetUpgradeable {
    using LibAssetUpgradeable for address;

    address constant NATIVE_ASSETID = address(0);

    function isNative(address self) internal pure returns (bool) {
        return self == NATIVE_ASSETID;
    }

    function getBalance(address self) internal view returns (uint256) {
        return self.isNative() ? address(this).balance : IERC20Upgradeable(self).balanceOf(address(this));
    }

    function transferFrom(
        address self,
        address from,
        address to,
        uint256 amount
    ) internal {
        SafeERC20Upgradeable.safeTransferFrom(IERC20Upgradeable(self), from, to, amount);
    }

    function increaseAllowance(
        address self,
        address spender,
        uint256 amount
    ) internal {
        require(!self.isNative(), "LibAsset: Allowance can't be increased for native asset");
        SafeERC20Upgradeable.safeIncreaseAllowance(IERC20Upgradeable(self), spender, amount);
    }

    function decreaseAllowance(
        address self,
        address spender,
        uint256 amount
    ) internal {
        require(!self.isNative(), "LibAsset: Allowance can't be decreased for native asset");
        SafeERC20Upgradeable.safeDecreaseAllowance(IERC20Upgradeable(self), spender, amount);
    }

    function transfer(
        address self,
        address payable recipient,
        uint256 amount
    ) internal {
        self.isNative()
            ? AddressUpgradeable.sendValue(recipient, amount)
            : SafeERC20Upgradeable.safeTransfer(IERC20Upgradeable(self), recipient, amount);
    }

    function approve(
        address self,
        address spender,
        uint256 amount
    ) internal {
        require(!self.isNative(), "LibAsset: Allowance can't be increased for native asset");
        SafeERC20Upgradeable.safeApprove(IERC20Upgradeable(self), spender, amount);
    }

    function getAllowance(
        address self,
        address owner,
        address spender
    ) internal view returns (uint256) {
        return IERC20Upgradeable(self).allowance(owner, spender);
    }
}

File 15 of 26 : IMagpieRouter.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

interface IMagpieRouter {
    struct Amm {
        address id;
        uint16 index;
        uint8 protocolIndex;
    }

    struct Hop {
        uint16 ammIndex;
        uint8[] path;
        bytes poolData;
    }

    struct Route {
        uint256 amountIn;
        Hop[] hops;
    }

    struct SwapArgs {
        Route[] routes;
        address[] assets;
        address payable to;
        uint256 amountOutMin;
        uint256 deadline;
    }

    function updateAmms(Amm[] calldata amms) external;

    function swap(SwapArgs memory swapArgs) external returns (uint256[] memory amountOuts);

    function updateMagpieCore(address _magpieCoreAddress) external;
    
    function updateMagpieSimulator(address _magpieSimulatorAddress) external;

    function withdraw(address weth, uint256 amount) external;

    event AmmsUpdated(Amm[] amms, address caller);
}

File 16 of 26 : IMagpieBridge.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

interface IMagpieBridge {
    enum BridgeType {
        Wormhole,
        Stargate
    }

    struct BridgeConfig {
        address stargateRouterAddress;
        address tokenBridgeAddress;
        address coreBridgeAddress;
        uint8 consistencyLevel;
        uint8 networkId;
    }

    struct BridgeArgs {
        bytes encodedVmBridge;
        bytes encodedVmCore;
        bytes senderStargateBridgeAddress;
        uint256 nonce;
        uint16 senderStargateChainId;
    }

    struct ValidationInPayload {
        bytes32 fromAssetAddress;
        bytes32 toAssetAddress;
        bytes32 to;
        bytes32 recipientCoreAddress;
        uint256 amountOutMin;
        uint256 layerZeroRecipientChainId;
        uint256 sourcePoolId;
        uint256 destPoolId;
        uint256 swapOutGasFee;
        uint16 recipientBridgeChainId;
        uint8 recipientNetworkId;
    }

    struct ValidationOutPayload {
        address fromAssetAddress;
        address toAssetAddress;
        address to;
        address recipientCoreAddress;
        bytes32 senderAddress;
        uint256 amountOutMin;
        uint256 swapOutGasFee;
        uint256 amountIn;
        uint64 tokenSequence;
        uint8 senderIntermediaryDecimals;
        uint8 senderNetworkId;
        uint8 recipientNetworkId;
        BridgeType bridgeType;
    }

    function updateConfig(BridgeConfig calldata _bridgeConfig) external;

    function bridgeIn(
        BridgeType bridgeType,
        ValidationInPayload memory payload,
        uint256 amount,
        address toAssetAddress,
        address refundAddress
    )
        external
        payable
        returns (
            uint256 depositAmount,
            uint64 coreSequence,
            uint64 tokenSequence
        );

    function getPayload(bytes memory encodedVm)
        external
        view
        returns (ValidationOutPayload memory payload, uint64 sequence);

    function bridgeOut(
        ValidationOutPayload memory payload,
        BridgeArgs memory bridgeArgs,
        uint64 tokenSequence,
        address assetAddress
    ) external returns (uint256 amount);

    function updateMagpieCore(address _magpieCoreAddress) external;

    function adjustAssetDecimals(
        address assetAddress,
        uint8 fromDecimals,
        uint256 amountIn
    ) external view returns (uint256 amount);
}

File 17 of 26 : AddressUpgradeable.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 AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [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 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 18 of 26 : IERC20Upgradeable.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 IERC20Upgradeable {
    /**
     * @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 19 of 26 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../extensions/draft-IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

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

    function safeTransferFrom(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20PermitUpgradeable 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(IERC20Upgradeable 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 20 of 26 : draft-IERC20PermitUpgradeable.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 IERC20PermitUpgradeable {
    /**
     * @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 21 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 22 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 23 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 24 of 26 : IAsset.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0 <0.9.0;

/**
 * @dev This is an empty interface used to represent either ERC20-conforming token contracts or ETH (using the zero
 * address sentinel value). We're just relying on the fact that `interface` can be used to declare new address-like
 * types.
 *
 * This concept is unrelated to a Pool's Asset Managers.
 */
interface IAsset {

}

File 25 of 26 : IUniswapV2Router01.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);

    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )
        external
        returns (
            uint256 amountA,
            uint256 amountB,
            uint256 liquidity
        );

    function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    )
        external
        payable
        returns (
            uint256 amountToken,
            uint256 amountETH,
            uint256 liquidity
        );

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);

    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETHWithPermit(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountToken, uint256 amountETH);

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactETHForTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function swapTokensForExactETH(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function quote(
        uint256 amountA,
        uint256 reserveA,
        uint256 reserveB
    ) external pure returns (uint256 amountB);

    function getAmountOut(
        uint256 amountIn,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountOut);

    function getAmountIn(
        uint256 amountOut,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountIn);

    function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts);

    function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts);
}

File 26 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;
    }
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"id","type":"address"},{"internalType":"uint16","name":"index","type":"uint16"},{"internalType":"uint8","name":"protocolIndex","type":"uint8"}],"indexed":false,"internalType":"struct IMagpieRouter.Amm[]","name":"amms","type":"tuple[]"},{"indexed":false,"internalType":"address","name":"caller","type":"address"}],"name":"AmmsUpdated","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":"magpieCoreAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"magpieSimulatorAddress","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":[{"components":[{"components":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"components":[{"internalType":"uint16","name":"ammIndex","type":"uint16"},{"internalType":"uint8[]","name":"path","type":"uint8[]"},{"internalType":"bytes","name":"poolData","type":"bytes"}],"internalType":"struct IMagpieRouter.Hop[]","name":"hops","type":"tuple[]"}],"internalType":"struct IMagpieRouter.Route[]","name":"routes","type":"tuple[]"},{"internalType":"address[]","name":"assets","type":"address[]"},{"internalType":"address payable","name":"to","type":"address"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct IMagpieRouter.SwapArgs","name":"swapArgs","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256[]","name":"amountOuts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"id","type":"address"},{"internalType":"uint16","name":"index","type":"uint16"},{"internalType":"uint8","name":"protocolIndex","type":"uint8"}],"internalType":"struct IMagpieRouter.Amm[]","name":"_amms","type":"tuple[]"}],"name":"updateAmms","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_magpieCoreAddress","type":"address"}],"name":"updateMagpieCore","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_magpieSimulatorAddress","type":"address"}],"name":"updateMagpieSimulator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"weth","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

608060405234801561001057600080fd5b50600160005561001f33610024565b610076565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b612fcb80620000866000396000f3fe6080604052600436106100955760003560e01c8063af6e524d11610059578063af6e524d14610153578063b379c07514610173578063b7479f7214610193578063f2fde38b146101c0578063f3fef3a3146101e057600080fd5b806303f97140146100a157806362f8e621146100c3578063715018a61461010057806375e100d7146101155780638da5cb5b1461013557600080fd5b3661009c57005b600080fd5b3480156100ad57600080fd5b506100c16100bc366004612389565b610200565b005b3480156100cf57600080fd5b506003546100e3906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561010c57600080fd5b506100c16104e6565b34801561012157600080fd5b506100c1610130366004612412565b6104fa565b34801561014157600080fd5b506001546001600160a01b03166100e3565b34801561015f57600080fd5b506100c161016e366004612412565b610524565b34801561017f57600080fd5b506002546100e3906001600160a01b031681565b34801561019f57600080fd5b506101b36101ae36600461261a565b61054e565b6040516100f79190612967565b3480156101cc57600080fd5b506100c16101db366004612412565b610a64565b3480156101ec57600080fd5b506100c16101fb3660046129ab565b610add565b610208610c38565b8061025a5760405162461bcd60e51b815260206004820152601a60248201527f4d6167706965526f757465723a20696e76616c696420616d6d7300000000000060448201526064015b60405180910390fd5b60005b818110156104a65760006040518060600160405280858585818110610284576102846129d7565b61029a9260206060909202019081019150612412565b6001600160a01b031681526020018585858181106102ba576102ba6129d7565b90506060020160200160208101906102d291906129ed565b61ffff1681526020018585858181106102ed576102ed6129d7565b90506060020160400160208101906103059190612a08565b60ff16905280519091506001600160a01b031661036e5760405162461bcd60e51b815260206004820152602160248201527f4d6167706965526f757465723a20696e76616c696420616d6d206164647265736044820152607360f81b6064820152608401610251565b6000816020015161ffff16116103c65760405162461bcd60e51b815260206004820152601f60248201527f4d6167706965526f757465723a20696e76616c696420616d6d20696e646578006044820152606401610251565b6000816040015160ff161161042d5760405162461bcd60e51b815260206004820152602760248201527f4d6167706965526f757465723a20696e76616c696420616d6d2070726f746f636044820152660ded892dcc8caf60cb1b6064820152608401610251565b6020808201805161ffff90811660009081526004909352604092839020845181549351949095015160ff16600160b01b0260ff60b01b1994909216600160a01b026001600160b01b03199093166001600160a01b039095169490941791909117919091161790558061049e81612a39565b91505061025d565b507f5871e0ebf9bc7f5e2e7c1c92aa6a76948cb35986ed1b8147f3fcc813bbe777cf8282336040516104da93929190612a54565b60405180910390a15050565b6104ee610c38565b6104f86000610c92565b565b610502610c38565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b61052c610c38565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b6002546060906001600160a01b031633148061057457506003546001600160a01b031633145b6105905760405162461bcd60e51b815260040161025190612ae1565b8151516001600160401b038111156105aa576105aa61242f565b6040519080825280602002602001820160405280156105d3578160200160208202803683370190505b50905060006105e183610ce4565b905060006105ee84610d68565b90506000610604826001600160a01b0316610e2f565b9050600061061186610ec4565b905060005b86515181101561084457600087600001518281518110610638576106386129d7565b602002602001015190506000816020015160008151811061065b5761065b6129d7565b6020026020010151905060008260200151600184602001515161067e9190612b3e565b8151811061068e5761068e6129d7565b60200260200101519050896020015182602001516000815181106106b4576106b46129d7565b602002602001015160ff16815181106106cf576106cf6129d7565b60200260200101516001600160a01b0316886001600160a01b0316146107465760405162461bcd60e51b815260206004820152602660248201527f4d6167706965526f757465723a20696e76616c69642066726f6d41737365744160448201526564647265737360d01b6064820152608401610251565b6020808b015190820151805161075e90600190612b3e565b8151811061076e5761076e6129d7565b602002602001015160ff1681518110610789576107896129d7565b60200260200101516001600160a01b0316876001600160a01b0316146107fd5760405162461bcd60e51b8152602060048201526024808201527f4d6167706965526f757465723a20696e76616c696420746f41737365744164646044820152637265737360e01b6064820152608401610251565b610810838b602001518c60800151610f19565b898581518110610822576108226129d7565b602002602001018181525050505050808061083c90612a39565b915050610616565b506000805b865181101561088b57868181518110610864576108646129d7565b6020026020010151826108779190612b55565b91508061088381612a39565b915050610849565b50836001600160a01b0316856001600160a01b031614156108b3576108b08284612b3e565b92505b6108bd8184612b55565b6108cf856001600160a01b0316610e2f565b1461091c5760405162461bcd60e51b815260206004820152601f60248201527f4d6167706965526f757465723a20696e76616c696420616d6f756e744f7574006044820152606401610251565b60005b8760200151518110156109cd5760006001600160a01b03168860200151828151811061094d5761094d6129d7565b60200260200101516001600160a01b031614156109bb5760405162461bcd60e51b815260206004820152602660248201527f4d6167706965526f757465723a20696e76616c6964206173736574202d20616460448201526506472657373360d41b6064820152608401610251565b806109c581612a39565b91505061091f565b508660600151811015610a335760405162461bcd60e51b815260206004820152602860248201527f4d6167706965526f757465723a20696e73756666696369656e74206f757470756044820152671d08185b5bdd5b9d60c21b6064820152608401610251565b6002546001600160a01b0316331415610a5a57610a5a6001600160a01b038516338361106b565b5050505050919050565b610a6c610c38565b6001600160a01b038116610ad15760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610251565b610ada81610c92565b50565b6002546001600160a01b0316331480610b0057506003546001600160a01b031633145b610b1c5760405162461bcd60e51b815260040161025190612ae1565b604051632e1a7d4d60e01b8152600481018290526001600160a01b03831690632e1a7d4d90602401600060405180830381600087803b158015610b5e57600080fd5b505af1158015610b72573d6000803e3d6000fd5b5050604080516000808252602082019283905293503392508491610b969190612b9d565b60006040518083038185875af1925050503d8060008114610bd3576040519150601f19603f3d011682016040523d82523d6000602084013e610bd8565b606091505b5050905080610c335760405162461bcd60e51b815260206004820152602160248201527f4d6167706965526f757465723a20657468207472616e73666572206661696c656044820152601960fa1b6064820152608401610251565b505050565b6001546001600160a01b031633146104f85760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610251565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600081602001518260000151600081518110610d0257610d026129d7565b602002602001015160200151600081518110610d2057610d206129d7565b602002602001015160200151600081518110610d3e57610d3e6129d7565b602002602001015160ff1681518110610d5957610d596129d7565b60200260200101519050919050565b6000808260000151600081518110610d8257610d826129d7565b60200260200101516020015160018460000151600081518110610da757610da76129d7565b60200260200101516020015151610dbe9190612b3e565b81518110610dce57610dce6129d7565b60200260200101519050826020015181602001516001836020015151610df49190612b3e565b81518110610e0457610e046129d7565b602002602001015160ff1681518110610e1f57610e1f6129d7565b6020026020010151915050919050565b60006001600160a01b03821615610ebc576040516370a0823160e01b81523060048201526001600160a01b038316906370a082319060240160206040518083038186803b158015610e7f57600080fd5b505afa158015610e93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb79190612bb9565b610ebe565b475b92915050565b600080805b835151811015610f12578351805182908110610ee757610ee76129d7565b60200260200101516000015182610efe9190612b55565b915080610f0a81612a39565b915050610ec9565b5092915050565b60008084602001515111610f6f5760405162461bcd60e51b815260206004820152601e60248201527f4d6167706965526f757465723a20696e76616c696420686f702073697a6500006044820152606401610251565b6000805b8560200151518110156110605760008115610f8e5782610f91565b86515b9050600087602001518381518110610fab57610fab6129d7565b6020026020010151905060008782602001516001846020015151610fcf9190612b3e565b81518110610fdf57610fdf6129d7565b602002602001015160ff1681518110610ffa57610ffa6129d7565b602002602001015190506000611018826001600160a01b0316610e2f565b905061102684848b8b61108f565b600061103a836001600160a01b0316610e2f565b90506110468282612b3e565b96505050505050808061105890612a39565b915050610f73565b5090505b9392505050565b6001600160a01b0383161561108557610c338383836112b8565b610c33828261131b565b825161ffff908116600090815260046020908152604091829020825160608101845290546001600160a01b038116808352600160a01b820490951692820192909252600160b01b90910460ff1691810191909152906111305760405162461bcd60e51b815260206004820152601960248201527f4d6167706965526f757465723a20696e76616c696420616d6d000000000000006044820152606401610251565b6001846020015151116111855760405162461bcd60e51b815260206004820152601f60248201527f4d6167706965526f757465723a20696e76616c696420706174682073697a65006044820152606401610251565b600083856020015160008151811061119f5761119f6129d7565b602002602001015160ff16815181106111ba576111ba6129d7565b60200260200101519050856111e7308460000151846001600160a01b03166114349092919063ffffffff16565b1015611206578151611206906001600160a01b038316906000196114c1565b816040015160ff16600114156112275761122286868686611548565b6112b0565b816040015160ff16600214806112445750816040015160ff166003145b1561125557611222868686866116f9565b816040015160ff16600614156112715761122286868686611b69565b816040015160ff166004148061128e5750816040015160ff166005145b806112a05750816040015160ff166007145b156112b0576112b0868686611dcf565b505050505050565b6040516001600160a01b038316602482015260448101829052610c3390849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611fa7565b8047101561136b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610251565b6000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146113b8576040519150601f19603f3d011682016040523d82523d6000602084013e6113bd565b606091505b5050905080610c335760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610251565b604051636eb1769f60e11b81526001600160a01b03838116600483015282811660248301526000919085169063dd62ed3e9060440160206040518083038186803b15801561148157600080fd5b505afa158015611495573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114b99190612bb9565b949350505050565b6001600160a01b03831661153d5760405162461bcd60e51b815260206004820152603760248201527f4c696241737365743a20416c6c6f77616e63652063616e277420626520696e6360448201527f72656173656420666f72206e61746976652061737365740000000000000000006064820152608401610251565b610c33838383612079565b825161ffff9081166000908152600460209081526040808320815160608101835290546001600160a01b0381168252600160a01b810490951681840152600160b01b90940460ff1690840152850151516001600160401b038111156115af576115af61242f565b6040519080825280602002602001820160405280156115d8578160200160208202803683370190505b50905060005b856020015151811015611661578486602001518281518110611602576116026129d7565b602002602001015160ff168151811061161d5761161d6129d7565b6020026020010151828281518110611637576116376129d7565b6001600160a01b03909216602092830291909101909101528061165981612a39565b9150506115de565b5081516040516338ed173960e01b81526001600160a01b03909116906338ed17399061169a908990600090869030908a90600401612bd2565b600060405180830381600087803b1580156116b457600080fd5b505af11580156116c8573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526116f09190810190612c43565b50505050505050565b825161ffff9081166000908152600460209081526040808320815160608101835290546001600160a01b0381168252600160a01b810490951681840152600160b01b90940460ff16908401528501515161175590600190612b3e565b6001600160401b0381111561176c5761176c61242f565b6040519080825280602002602001820160405280156117d257816020015b6117bf6040518060a0016040528060008019168152602001600081526020016000815260200160008152602001606081525090565b81526020019060019003908161178a5790505b5090506000808660200151516001600160401b038111156117f5576117f561242f565b60405190808252806020026020018201604052801561181e578160200160208202803683370190505b50905060008760200151516001600160401b038111156118405761184061242f565b604051908082528060200260200182016040528015611869578160200160208202803683370190505b50905060005b60018960200151516118819190612b3e565b811015611a86576040518060a001604052806118aa868c6040015161219d90919063ffffffff16565b8152602081018390526040016118c1836001612b55565b815260200182156118d35760006118d5565b8b5b815260200160405180604001604052806002815260200161060f60f31b81525081525085828151811061190a5761190a6129d7565b60200260200101819052506020846119229190612b55565b9350878960200151828151811061193b5761193b6129d7565b602002602001015160ff1681518110611956576119566129d7565b6020026020010151838281518110611970576119706129d7565b6001600160a01b03909216602092830291909101909101528015611995576000611997565b895b8282815181106119a9576119a96129d7565b60200260200101818152505060028960200151516119c79190612b3e565b811415611a7457602089015188906119e0836001612b55565b815181106119f0576119f06129d7565b602002602001015160ff1681518110611a0b57611a0b6129d7565b602002602001015183826001611a219190612b55565b81518110611a3157611a316129d7565b6001600160a01b0390921660209283029190910190910152600082611a57836001612b55565b81518110611a6757611a676129d7565b6020026020010181815250505b80611a7e81612a39565b91505061186f565b508288604001515114611aab5760405162461bcd60e51b815260040161025190612cc8565b604080516080810182523080825260006020830181905282840191909152606082018190528751925163945bcec960e01b815291926001600160a01b03169163945bcec991611b069189908890879089908f90600401612da9565b600060405180830381600087803b158015611b2057600080fd5b505af1158015611b34573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611b5c9190810190612c43565b5050505050505050505050565b825161ffff908116600090815260046020908152604080832081516060808201845291546001600160a01b0381168252600160a01b810490961693810193909352600160b01b90940460ff169082015291815b866020015151811015611cf857818688602001518381518110611be157611be16129d7565b602002602001015160ff1681518110611bfc57611bfc6129d7565b6020026020010151604051602001611c2c919060609190911b6bffffffffffffffffffffffff1916815260140190565b60408051601f1981840301815290829052611c4a9291602001612ed9565b60405160208183030381529060405291506001876020015151611c6d9190612b3e565b811015611ce65760408701518290611c859085612203565b604051602001611ca8919060e89190911b6001600160e81b031916815260030190565b60408051601f1981840301815290829052611cc69291602001612ed9565b60408051601f198184030181529190529150611ce3600384612b55565b92505b80611cf081612a39565b915050611bbc565b508186604001515114611d1d5760405162461bcd60e51b815260040161025190612cc8565b6040805160a08101825282815230602082015280820186905260608101899052600060808201528451915163c04b8d5960e01b815290916001600160a01b03169063c04b8d5990611d72908490600401612f08565b602060405180830381600087803b158015611d8c57600080fd5b505af1158015611da0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dc49190612bb9565b505050505050505050565b815161ffff9081166000908152600460209081526040808320815160608101835290546001600160a01b038116808352600160a01b820490961693820193909352600160b01b90920460ff1682820152805160c0810182529086015191939263c84627b8928291611e409190612269565b6001600160a01b03168152602001858760200151600081518110611e6657611e666129d7565b602002602001015160ff1681518110611e8157611e816129d7565b60200260200101516001600160a01b03168152602001858760200151600181518110611eaf57611eaf6129d7565b602002602001015160ff1681518110611eca57611eca6129d7565b6020908102919091018101516001600160a01b0390811683528282018a905260006040808501919091523060609485015280516001600160e01b031960e088901b1681528551831660048201529285015182166024840152840151811660448301529183015160648201526080830151608482015260a0909201511660a482015260c401602060405180830381600087803b158015611f6857600080fd5b505af1158015611f7c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fa09190612bb9565b5050505050565b6000611ffc826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166122759092919063ffffffff16565b805190915015610c33578080602001905181019061201a9190612f60565b610c335760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610251565b8015806121025750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b1580156120c857600080fd5b505afa1580156120dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121009190612bb9565b155b61216d5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610251565b6040516001600160a01b038316602482015260448101829052610c3390849063095ea7b360e01b906064016112e4565b60006121aa826020612b55565b835110156121fa5760405162461bcd60e51b815260206004820152601f60248201527f4c696242797465733a20746f42797465733332206f75744f66426f756e6473006044820152606401610251565b50016020015190565b6000612210826003612b55565b835110156122605760405162461bcd60e51b815260206004820152601e60248201527f4c696242797465733a20746f55696e743234206f75744f66426f756e647300006044820152606401610251565b50016003015190565b6000611064838361219d565b60606114b98484600085856001600160a01b0385163b6122d75760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610251565b600080866001600160a01b031685876040516122f39190612b9d565b60006040518083038185875af1925050503d8060008114612330576040519150601f19603f3d011682016040523d82523d6000602084013e612335565b606091505b5091509150612345828286612350565b979650505050505050565b6060831561235f575081611064565b82511561236f5782518084602001fd5b8160405162461bcd60e51b81526004016102519190612f82565b6000806020838503121561239c57600080fd5b82356001600160401b03808211156123b357600080fd5b818501915085601f8301126123c757600080fd5b8135818111156123d657600080fd5b8660206060830285010111156123eb57600080fd5b60209290920196919550909350505050565b6001600160a01b0381168114610ada57600080fd5b60006020828403121561242457600080fd5b8135611064816123fd565b634e487b7160e01b600052604160045260246000fd5b60405160a081016001600160401b03811182821017156124675761246761242f565b60405290565b604080519081016001600160401b03811182821017156124675761246761242f565b604051606081016001600160401b03811182821017156124675761246761242f565b604051601f8201601f191681016001600160401b03811182821017156124d9576124d961242f565b604052919050565b60006001600160401b038211156124fa576124fa61242f565b5060051b60200190565b803561ffff8116811461251657600080fd5b919050565b803560ff8116811461251657600080fd5b600082601f83011261253d57600080fd5b81356001600160401b038111156125565761255661242f565b612569601f8201601f19166020016124b1565b81815284602083860101111561257e57600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f8301126125ac57600080fd5b813560206125c16125bc836124e1565b6124b1565b82815260059290921b840181019181810190868411156125e057600080fd5b8286015b848110156126045780356125f7816123fd565b83529183019183016125e4565b509695505050505050565b8035612516816123fd565b60006020828403121561262c57600080fd5b6001600160401b038235111561264157600080fd5b60a0823583018403121561265457600080fd5b61265c612445565b6001600160401b038335840135111561267457600080fd5b82358301803501601f01841361268957600080fd5b61269c6125bc84358501803501356124e1565b8335840180350180358083526020808401939260059290921b909101018610156126c557600080fd5b843585018035016020015b85358601803501803560051b016020018110156128fd576001600160401b03813511156126fc57600080fd5b6040863587018035018235018803601f1901121561271957600080fd5b61272161246d565b86358701803501823501602081013582526001600160401b03604090910135111561274b57600080fd5b86358701803501823501604081013501603f8101891361276a57600080fd5b61277a6125bc60208301356124e1565b602082810135808352908201919060051b83016040018b101561279c57600080fd5b604083015b6040602085013560051b8501018110156128e4576001600160401b03813511156127ca57600080fd5b6060813585018d03603f190112156127e157600080fd5b6127e961248f565b6127f860408335870101612504565b81526001600160401b036060833587010135111561281557600080fd5b81358501606081013501605f81018e1361282e57600080fd5b61283e6125bc60408301356124e1565b80604083013582526020820191508f60406020604086013560051b86010101111561286857600080fd5b606083015b6060604085013560051b8501018110156128985761288a8161251b565b83526020928301920161286d565b50602084015250506001600160401b03823586016080013511156128bb57600080fd5b6128d18d8335870160808101350160400161252c565b60408201528352602092830192016127a1565b50602084810191909152928652505092830192016126d0565b508252506001600160401b038335840160200135111561291c57600080fd5b61292f848435850160208101350161259b565b60208201526129436040843585010161260f565b60408201528235909201606081810135908401526080908101359083015250919050565b6020808252825182820181905260009190848201906040850190845b8181101561299f57835183529284019291840191600101612983565b50909695505050505050565b600080604083850312156129be57600080fd5b82356129c9816123fd565b946020939093013593505050565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156129ff57600080fd5b61106482612504565b600060208284031215612a1a57600080fd5b6110648261251b565b634e487b7160e01b600052601160045260246000fd5b6000600019821415612a4d57612a4d612a23565b5060010190565b6040808252818101849052600090606080840187845b88811015612abf578135612a7d816123fd565b6001600160a01b03168352602061ffff612a98848301612504565b169084015260ff612aaa83870161251b565b16838601529183019190830190600101612a6a565b50506001600160a01b0395909516602094909401939093525091949350505050565b60208082526038908201527f4d6167706965526f757465723a206f6e6c79204d6167706965436f7265206f7260408201527f204d616770696553696d756c61746f7220616c6c6f7765640000000000000000606082015260800190565b600082821015612b5057612b50612a23565b500390565b60008219821115612b6857612b68612a23565b500190565b60005b83811015612b88578181015183820152602001612b70565b83811115612b97576000848401525b50505050565b60008251612baf818460208701612b6d565b9190910192915050565b600060208284031215612bcb57600080fd5b5051919050565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b81811015612c225784516001600160a01b031683529383019391830191600101612bfd565b50506001600160a01b03969096166060850152505050608001529392505050565b60006020808385031215612c5657600080fd5b82516001600160401b03811115612c6c57600080fd5b8301601f81018513612c7d57600080fd5b8051612c8b6125bc826124e1565b81815260059190911b82018301908381019087831115612caa57600080fd5b928401925b8284101561234557835182529284019290840190612caf565b60208082526021908201527f4d6167706965526f757465723a20706f6f6c4461746120697320696e76616c696040820152601960fa1b606082015260800190565b60008151808452612d21816020860160208601612b6d565b601f01601f19169290920160200192915050565b600081518084526020808501945080840160005b83811015612d6e5781516001600160a01b031687529582019590820190600101612d49565b509495945050505050565b600081518084526020808501945080840160005b83811015612d6e57815187529582019590820190600101612d8d565b600061012080830160028a10612dcf57634e487b7160e01b600052602160045260246000fd5b89845260208085019290925288519081905261014080850192600583901b8601909101918a820160005b82811015612e5c5787850361013f190186528151805186528481015185870152604080820151908701526060808201519087015260809081015160a091870182905290612e4881880183612d09565b978601979650505090830190600101612df9565b505050508381036040850152612e728189612d35565b915050612eb2606084018780516001600160a01b039081168352602080830151151590840152604080830151909116908301526060908101511515910152565b82810360e0840152612ec48186612d79565b91505082610100830152979650505050505050565b60008351612eeb818460208801612b6d565b835190830190612eff818360208801612b6d565b01949350505050565b602081526000825160a06020840152612f2460c0840182612d09565b905060018060a01b0360208501511660408401526040840151606084015260608401516080840152608084015160a08401528091505092915050565b600060208284031215612f7257600080fd5b8151801515811461106457600080fd5b6020815260006110646020830184612d0956fea26469706673582212200791d5c93a7778af5c358729b0e67a7ff9a23919205035224efbf4d7e5ea4d3e64736f6c63430008090033

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.