Contract 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xb65fc0e464a9cc071ddcd31c212e2cab6bb06d5b7ae6fb5c450dfe56462ee80bDecrease Positio...585842142023-02-06 18:43:203 hrs 47 mins ago0xe7fef163046efc052f8cfa49a5fa449a2468a3ee IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.0003275
0x605653ee0d116c2e323f9c3cfcde65fee90630affe64dcb22764338b0039a93fDecrease Positio...585539392023-02-06 16:18:536 hrs 11 mins ago0x09bf5c034616b80728db5d4141e0e6359d1f5b8f IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00025768
0x6a8fd7095951ebd12853d9e265a0a78091e7c1a52844ae7c9ec5a8972872f1b8Decrease Positio...585534692023-02-06 16:16:516 hrs 13 mins ago0x09bf5c034616b80728db5d4141e0e6359d1f5b8f IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00025768
0x6b05a5e31cab6ccc6eef439967b523ecc08a0dd016033b71eb2880a3de543d9eDecrease Positio...585443632023-02-06 15:37:486 hrs 52 mins ago0x09bf5c034616b80728db5d4141e0e6359d1f5b8f IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00021231
0x5a3a08453d374add9a295f9ca15799e755c80380896c11ddae3a7e1f122a7f8cDecrease Positio...585425902023-02-06 15:30:117 hrs ago0x09bf5c034616b80728db5d4141e0e6359d1f5b8f IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00020309
0x63d5f27513e9e3768df42f1805c1f63e5b2d55b8cbfe370f4bc6f594df21d141Decrease Positio...585408252023-02-06 15:22:367 hrs 8 mins ago0x0a4248df78ac355799f6e60e7bdba816eac729b6 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00025326
0x4061a192827710bf1133cf9cf72245a102f12a686f0be00bb14359bdf95da2c6Decrease Positio...585398012023-02-06 15:18:167 hrs 12 mins ago0x09bf5c034616b80728db5d4141e0e6359d1f5b8f IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00018973
0x4d7e8ecfed30aeccb346d1d62a1300da3b6504332dca03707b997a34241f86d4Increase Positio...585379312023-02-06 15:10:207 hrs 20 mins ago0x0a4248df78ac355799f6e60e7bdba816eac729b6 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890.004419716130632 ETH0.00034834
0xb1c434c025af2fc2d8afa9427be902d4e9f512d90c76d3cf65696367b083da5eSwap ETH To Toke...584947182023-02-06 11:56:0110 hrs 34 mins ago0x420220b72bbd307db8615e7aa0eadca399cf2fc0 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890.001 ETH0.00021374
0xe8dafd3d78871c731c41e568c0a56e68881f6001793de90df1e11ed815c9e0f0Swap584809392023-02-06 10:50:2311 hrs 40 mins ago0x7085c2ae0ed9966e5e2ace4187ce7214f2b7901a IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00016494
0x695031eb89ffef698a4f14eb6c4921a2b95d91ca835a0c39ad2d0caca994dee2Decrease Positio...584806752023-02-06 10:49:0911 hrs 41 mins ago0x7085c2ae0ed9966e5e2ace4187ce7214f2b7901a IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00012882
0xf5c2ed7fc7e65ad10268e68f81972af67911561b5e0c40abfc349c4b60c47c0eSwap ETH To Toke...584500102023-02-06 8:29:5314 hrs ago0x420220b72bbd307db8615e7aa0eadca399cf2fc0 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890.001 ETH0.00017884
0xf438168949aa9cad9554ff9b5d692735dd580413f39e2187a7e40968b281b5bbDecrease Positio...584474582023-02-06 8:18:4914 hrs 11 mins ago0x91f3be13569e134cbccd5bb33bd3eedd41cf71ba IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00035562
0xe386322b3658d7f242cc369aeb4255238ff3b3433f39bf19f8e3cede8c6b7f7dIncrease Positio...584469352023-02-06 8:16:3114 hrs 14 mins ago0x91f3be13569e134cbccd5bb33bd3eedd41cf71ba IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00039172
0x6c2c8c483ded443bc2593fdcb152d1d43ffcfde540bdb430d723672a5e579687Swap ETH To Toke...584454902023-02-06 8:10:1414 hrs 20 mins ago0x420220b72bbd307db8615e7aa0eadca399cf2fc0 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890.001 ETH0.00018805
0x47933f656b3d8040d5d2f3548944ca576f14fa2c9918f93f6a5a5e2fb9d83e8aSwap ETH To Toke...584450902023-02-06 8:08:2014 hrs 22 mins ago0x420220b72bbd307db8615e7aa0eadca399cf2fc0 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890.001 ETH0.00019184
0xd55fd0909b5ad1f3f26cce5915a4d1e6f4ee9037ab856f969df17df114d8ca74Swap584137272023-02-06 5:34:0316 hrs 56 mins ago0xeed6ce804e0cf9fa0425c03673c0385ed1e02070 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00017521
0x46d0127339f53092a7b01f138d1af250f945e1ba67ee48354df1676e9449e6ccIncrease Positio...583946792023-02-06 3:46:4118 hrs 43 mins ago0x7085c2ae0ed9966e5e2ace4187ce7214f2b7901a IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00015752
0x7c3ca77c9d0a2ca762d2b167377f7e022da88595e380d2c4f52655e5e57c357dDecrease Positio...583945222023-02-06 3:45:5218 hrs 44 mins ago0x7085c2ae0ed9966e5e2ace4187ce7214f2b7901a IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00014297
0x00d49a2f389f3f4c80f36f98b035986b64a92eb1030ace9bded4ddbe32acc18aIncrease Positio...583943972023-02-06 3:45:0818 hrs 45 mins ago0x7085c2ae0ed9966e5e2ace4187ce7214f2b7901a IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890.004 ETH0.00021954
0xcd957052766d9672f17748a328208faca6cfabd2e86f046130dc76d2d7627116Swap583899412023-02-06 3:21:4119 hrs 8 mins ago0xeed6ce804e0cf9fa0425c03673c0385ed1e02070 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00020983
0x3873d8907e38c9480cc6a680ff178ed8e0b5d182b62c8bc8549734e366882bcbSwap583777292023-02-06 2:21:2620 hrs 9 mins ago0x420220b72bbd307db8615e7aa0eadca399cf2fc0 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00021387
0x4a46ecd16ed0bd96d2ea4f2638bacc6f4bf26226ec71dc1337c522f61680aab3Decrease Positio...583578532023-02-06 0:16:3622 hrs 14 mins ago0xeed6ce804e0cf9fa0425c03673c0385ed1e02070 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.0001822
0x4c24fdb1b7daa47d372568bbd9e98abd12404986753d19d70df73458a554a283Increase Positio...583448052023-02-05 22:50:5523 hrs 39 mins ago0xeed6ce804e0cf9fa0425c03673c0385ed1e02070 IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890.01 ETH0.00051722
0xdc1daf62a2d2df89c195a6ade494559c36b460263208cf6a0e2b46e0247a6679Swap Tokens To E...581698102023-02-05 8:42:461 day 13 hrs ago0xc5dda6452579cee08a9dc8084147330f1019fd5d IN  0x434b5245f6fe54d0c9f881d55c2ba27fe7132d890 ETH0.00020526
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0xb65fc0e464a9cc071ddcd31c212e2cab6bb06d5b7ae6fb5c450dfe56462ee80b585842142023-02-06 18:43:203 hrs 47 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0xb65fc0e464a9cc071ddcd31c212e2cab6bb06d5b7ae6fb5c450dfe56462ee80b585842142023-02-06 18:43:203 hrs 47 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0xb65fc0e464a9cc071ddcd31c212e2cab6bb06d5b7ae6fb5c450dfe56462ee80b585842142023-02-06 18:43:203 hrs 47 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0xf28e261b89fc4479ee41044dd55f7a4053f9844a0 ETH
0xb65fc0e464a9cc071ddcd31c212e2cab6bb06d5b7ae6fb5c450dfe56462ee80b585842142023-02-06 18:43:203 hrs 47 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x605653ee0d116c2e323f9c3cfcde65fee90630affe64dcb22764338b0039a93f585539392023-02-06 16:18:536 hrs 11 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0xf28e261b89fc4479ee41044dd55f7a4053f9844a0 ETH
0x605653ee0d116c2e323f9c3cfcde65fee90630affe64dcb22764338b0039a93f585539392023-02-06 16:18:536 hrs 11 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x6a8fd7095951ebd12853d9e265a0a78091e7c1a52844ae7c9ec5a8972872f1b8585534692023-02-06 16:16:516 hrs 13 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0xf28e261b89fc4479ee41044dd55f7a4053f9844a0 ETH
0x6a8fd7095951ebd12853d9e265a0a78091e7c1a52844ae7c9ec5a8972872f1b8585534692023-02-06 16:16:516 hrs 13 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x6b05a5e31cab6ccc6eef439967b523ecc08a0dd016033b71eb2880a3de543d9e585443632023-02-06 15:37:486 hrs 52 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0xf28e261b89fc4479ee41044dd55f7a4053f9844a0 ETH
0x6b05a5e31cab6ccc6eef439967b523ecc08a0dd016033b71eb2880a3de543d9e585443632023-02-06 15:37:486 hrs 52 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x5a3a08453d374add9a295f9ca15799e755c80380896c11ddae3a7e1f122a7f8c585425902023-02-06 15:30:117 hrs ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0xf28e261b89fc4479ee41044dd55f7a4053f9844a0 ETH
0x5a3a08453d374add9a295f9ca15799e755c80380896c11ddae3a7e1f122a7f8c585425902023-02-06 15:30:117 hrs ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x63d5f27513e9e3768df42f1805c1f63e5b2d55b8cbfe370f4bc6f594df21d141585408252023-02-06 15:22:367 hrs 8 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x63d5f27513e9e3768df42f1805c1f63e5b2d55b8cbfe370f4bc6f594df21d141585408252023-02-06 15:22:367 hrs 8 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x63d5f27513e9e3768df42f1805c1f63e5b2d55b8cbfe370f4bc6f594df21d141585408252023-02-06 15:22:367 hrs 8 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0xf28e261b89fc4479ee41044dd55f7a4053f9844a0 ETH
0x63d5f27513e9e3768df42f1805c1f63e5b2d55b8cbfe370f4bc6f594df21d141585408252023-02-06 15:22:367 hrs 8 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x4061a192827710bf1133cf9cf72245a102f12a686f0be00bb14359bdf95da2c6585398012023-02-06 15:18:167 hrs 12 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0xf28e261b89fc4479ee41044dd55f7a4053f9844a0 ETH
0x4061a192827710bf1133cf9cf72245a102f12a686f0be00bb14359bdf95da2c6585398012023-02-06 15:18:167 hrs 12 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x4d7e8ecfed30aeccb346d1d62a1300da3b6504332dca03707b997a34241f86d4585379312023-02-06 15:10:207 hrs 20 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x4d7e8ecfed30aeccb346d1d62a1300da3b6504332dca03707b997a34241f86d4585379312023-02-06 15:10:207 hrs 20 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x4d7e8ecfed30aeccb346d1d62a1300da3b6504332dca03707b997a34241f86d4585379312023-02-06 15:10:207 hrs 20 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 handle.fi: fxUSD0 ETH
0x4d7e8ecfed30aeccb346d1d62a1300da3b6504332dca03707b997a34241f86d4585379312023-02-06 15:10:207 hrs 20 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x1785e8491e7e9d771b2a6e9e389c25265f06326a0 ETH
0x4d7e8ecfed30aeccb346d1d62a1300da3b6504332dca03707b997a34241f86d4585379312023-02-06 15:10:207 hrs 20 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x82af49447d8a07e3bd95bd0d56f35241523fbab10 ETH
0x4d7e8ecfed30aeccb346d1d62a1300da3b6504332dca03707b997a34241f86d4585379312023-02-06 15:10:207 hrs 20 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0x82af49447d8a07e3bd95bd0d56f35241523fbab10.004419716130632757 ETH
0x4d7e8ecfed30aeccb346d1d62a1300da3b6504332dca03707b997a34241f86d4585379312023-02-06 15:10:207 hrs 20 mins ago 0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89 0xf28e261b89fc4479ee41044dd55f7a4053f9844a0 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Router

Compiler Version
v0.6.12+commit.27d51765

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 11 : Router.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

import "../libraries/math/SafeMath.sol";
import "../libraries/token/IERC20.sol";
import "../libraries/token/SafeERC20.sol";
import "../libraries/utils/Address.sol";
import "../tokens/interfaces/IWETH.sol";
import "./interfaces/IVault.sol";
import "./interfaces/IVaultPriceFeed.sol";
import "./interfaces/IRouter.sol";
import "../rebates/IReferral.sol";

contract Router is IRouter {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;
    using Address for address payable;

    address public gov;

    // wrapped BNB / ETH
    address public immutable weth;
    address public immutable usdg;
    address public immutable vault;

    // Referral contract
    address public immutable referral;

    mapping(address => bool) public plugins;
    mapping(address => mapping(address => bool)) public approvedPlugins;

    event Swap(
        address account,
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 amountOut
    );

    modifier onlyGov() {
        require(msg.sender == gov, "Router: forbidden");
        _;
    }

    constructor(
        address _vault,
        address _usdg,
        address _weth,
        address _referral
    ) public {
        require(
            _vault != address(0) &&
                _usdg != address(0) &&
                _weth != address(0) &&
                _referral != address(0),
            "Addresses cannot be zero"
        );
        vault = _vault;
        usdg = _usdg;
        weth = _weth;
        referral = _referral;
        gov = msg.sender;
    }

    receive() external payable {
        require(msg.sender == weth, "Router: invalid sender");
    }

    function setGov(address _gov) external onlyGov {
        gov = _gov;
    }

    function addPlugin(address _plugin) external override onlyGov {
        plugins[_plugin] = true;
    }

    function removePlugin(address _plugin) external onlyGov {
        plugins[_plugin] = false;
    }

    function approvePlugin(address _plugin) external {
        approvedPlugins[msg.sender][_plugin] = true;
    }

    function denyPlugin(address _plugin) external {
        approvedPlugins[msg.sender][_plugin] = false;
    }

    function pluginTransfer(
        address _token,
        address _account,
        address _receiver,
        uint256 _amount
    ) external override {
        _validatePlugin(_account);
        IERC20(_token).safeTransferFrom(_account, _receiver, _amount);
    }

    function pluginIncreasePosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        uint256 _sizeDelta,
        bool _isLong
    ) external override {
        _validatePlugin(_account);
        IVault(vault).increasePosition(
            _account,
            _collateralToken,
            _indexToken,
            _sizeDelta,
            _isLong
        );
    }

    function pluginDecreasePosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address _receiver
    ) external override returns (uint256) {
        _validatePlugin(_account);
        return
            IVault(vault).decreasePosition(
                _account,
                _collateralToken,
                _indexToken,
                _collateralDelta,
                _sizeDelta,
                _isLong,
                _receiver
            );
    }

    function directPoolDeposit(address _token, uint256 _amount) external {
        IERC20(_token).safeTransferFrom(_sender(), vault, _amount);
        IVault(vault).directPoolDeposit(_token);
    }

    function swap(
        address[] memory _path,
        uint256 _amountIn,
        uint256 _minOut,
        address _receiver,
        bytes calldata signedQuoteData
    ) public override {
        swapWithReferrer(
            _path,
            _amountIn,
            _minOut,
            _receiver,
            signedQuoteData,
            address(0)
        );
    }

    function swapWithReferrer(
        address[] memory _path,
        uint256 _amountIn,
        uint256 _minOut,
        address _receiver,
        bytes calldata signedQuoteData,
        address referrer
    ) public override {
        _setReferral(referrer);
        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        IERC20(_path[0]).safeTransferFrom(_sender(), vault, _amountIn);
        uint256 amountOut = _swap(_path, _minOut, _receiver, _sender());
        emit Swap(
            msg.sender,
            _path[0],
            _path[_path.length - 1],
            _amountIn,
            amountOut
        );
    }

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

    function swapETHToTokensWithReferrer(
        address[] memory _path,
        uint256 _minOut,
        address _receiver,
        bytes calldata signedQuoteData,
        address referrer
    ) public payable {
        require(_path[0] == weth, "Router: invalid _path");

        _setReferral(referrer);
        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        _transferETHToVault();
        uint256 amountOut = _swap(_path, _minOut, _receiver, _sender());
        emit Swap(
            msg.sender,
            _path[0],
            _path[_path.length - 1],
            msg.value,
            amountOut
        );
    }

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

    function swapTokensToETHWithReferrer(
        address[] memory _path,
        uint256 _amountIn,
        uint256 _minOut,
        address payable _receiver,
        bytes calldata signedQuoteData,
        address referrer
    ) public {
        require(_path[_path.length - 1] == weth, "Router: invalid _path");

        _setReferral(referrer);
        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        IERC20(_path[0]).safeTransferFrom(_sender(), vault, _amountIn);
        uint256 amountOut = _swap(_path, _minOut, address(this), _sender());
        _transferOutETH(amountOut, _receiver);

        emit Swap(
            msg.sender,
            _path[0],
            _path[_path.length - 1],
            _amountIn,
            amountOut
        );
    }

    function increasePosition(
        address[] memory _path,
        address _indexToken,
        uint256 _amountIn,
        uint256 _minOut,
        uint256 _sizeDelta,
        bool _isLong,
        uint256 _price,
        bytes calldata signedQuoteData
    ) external {
        increasePositionWithReferrer(
            _path,
            _indexToken,
            _amountIn,
            _minOut,
            _sizeDelta,
            _isLong,
            _price,
            signedQuoteData,
            address(0)
        );
    }

    function increasePositionWithReferrer(
        address[] memory _path,
        address _indexToken,
        uint256 _amountIn,
        uint256 _minOut,
        uint256 _sizeDelta,
        bool _isLong,
        uint256 _price,
        bytes calldata signedQuoteData,
        address referrer
    ) public {
        _setReferral(referrer);
        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        if (_amountIn > 0) {
            IERC20(_path[0]).safeTransferFrom(_sender(), vault, _amountIn);
        }
        if (_path.length > 1 && _amountIn > 0) {
            uint256 amountOut = _swap(_path, _minOut, address(this), _sender());
            IERC20(_path[_path.length - 1]).safeTransfer(vault, amountOut);
        }
        _increasePosition(
            _path[_path.length - 1],
            _indexToken,
            _sizeDelta,
            _isLong,
            _price
        );
    }

    function increasePositionETH(
        address[] memory _path,
        address _indexToken,
        uint256 _minOut,
        uint256 _sizeDelta,
        bool _isLong,
        uint256 _price,
        bytes calldata signedQuoteData
    ) external payable {
        increasePositionETHWithReferrer(
            _path,
            _indexToken,
            _minOut,
            _sizeDelta,
            _isLong,
            _price,
            signedQuoteData,
            address(0)
        );
    }

    function increasePositionETHWithReferrer(
        address[] memory _path,
        address _indexToken,
        uint256 _minOut,
        uint256 _sizeDelta,
        bool _isLong,
        uint256 _price,
        bytes calldata signedQuoteData,
        address referrer
    ) public payable {
        require(_path[0] == weth, "Router: invalid _path");

        _setReferral(referrer);
        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        if (msg.value > 0) {
            _transferETHToVault();
        }
        if (_path.length > 1 && msg.value > 0) {
            uint256 amountOut = _swap(_path, _minOut, address(this), _sender());
            IERC20(_path[_path.length - 1]).safeTransfer(vault, amountOut);
        }
        _increasePosition(
            _path[_path.length - 1],
            _indexToken,
            _sizeDelta,
            _isLong,
            _price
        );
    }

    function decreasePosition(
        address _collateralToken,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address _receiver,
        uint256 _price,
        bytes calldata signedQuoteData
    ) external {
        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        _decreasePosition(
            _collateralToken,
            _indexToken,
            _collateralDelta,
            _sizeDelta,
            _isLong,
            _receiver,
            _price
        );
    }

    function decreasePositionETH(
        address _collateralToken,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address payable _receiver,
        uint256 _price,
        bytes calldata signedQuoteData
    ) external {
        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        uint256 amountOut = _decreasePosition(
            _collateralToken,
            _indexToken,
            _collateralDelta,
            _sizeDelta,
            _isLong,
            address(this),
            _price
        );
        _transferOutETH(amountOut, _receiver);
    }

    function decreasePositionAndSwap(
        address[] memory _path,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address _receiver,
        uint256 _price,
        uint256 _minOut,
        bytes calldata signedQuoteData
    ) public {
        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        uint256 amount = _decreasePosition(
            _path[0],
            _indexToken,
            _collateralDelta,
            _sizeDelta,
            _isLong,
            address(this),
            _price
        );
        IERC20(_path[0]).safeTransfer(vault, amount);
        _swap(_path, _minOut, _receiver, _sender());
    }

    function decreasePositionAndSwapETH(
        address[] memory _path,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address payable _receiver,
        uint256 _price,
        uint256 _minOut,
        bytes calldata signedQuoteData
    ) public {
        require(_path[_path.length - 1] == weth, "Router: invalid _path");

        IVaultPriceFeed(IVault(vault).priceFeed()).h2sofaApplySignedQuote(
            signedQuoteData
        );

        uint256 amount = _decreasePosition(
            _path[0],
            _indexToken,
            _collateralDelta,
            _sizeDelta,
            _isLong,
            address(this),
            _price
        );
        IERC20(_path[0]).safeTransfer(vault, amount);
        uint256 amountOut = _swap(_path, _minOut, address(this), _sender());
        _transferOutETH(amountOut, _receiver);
    }

    function _increasePosition(
        address _collateralToken,
        address _indexToken,
        uint256 _sizeDelta,
        bool _isLong,
        uint256 _price
    ) private {
        if (_isLong) {
            require(
                IVault(vault).getMaxPrice(_indexToken) <= _price,
                "Router: mark price higher than limit"
            );
        } else {
            require(
                IVault(vault).getMinPrice(_indexToken) >= _price,
                "Router: mark price lower than limit"
            );
        }

        IVault(vault).increasePosition(
            _sender(),
            _collateralToken,
            _indexToken,
            _sizeDelta,
            _isLong
        );
    }

    function _decreasePosition(
        address _collateralToken,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address _receiver,
        uint256 _price
    ) private returns (uint256) {
        if (_isLong) {
            require(
                IVault(vault).getMinPrice(_indexToken) >= _price,
                "Router: mark price lower than limit"
            );
        } else {
            require(
                IVault(vault).getMaxPrice(_indexToken) <= _price,
                "Router: mark price higher than limit"
            );
        }

        return
            IVault(vault).decreasePosition(
                _sender(),
                _collateralToken,
                _indexToken,
                _collateralDelta,
                _sizeDelta,
                _isLong,
                _receiver
            );
    }

    function _transferETHToVault() private {
        IWETH(weth).deposit{value: msg.value}();
        IERC20(weth).safeTransfer(vault, msg.value);
    }

    function _transferOutETH(uint256 _amountOut, address payable _receiver)
        private
    {
        IWETH(weth).withdraw(_amountOut);
        _receiver.sendValue(_amountOut);
    }

    function _swap(
        address[] memory _path,
        uint256 _minOut,
        address _receiver,
        address _rebateReceiver
    ) private returns (uint256) {
        if (_path.length == 2) {
            return
                _vaultSwap(
                    _path[0],
                    _path[1],
                    _minOut,
                    _receiver,
                    _rebateReceiver
                );
        }
        if (_path.length == 3) {
            uint256 midOut = _vaultSwap(
                _path[0],
                _path[1],
                0,
                address(this),
                _rebateReceiver
            );
            IERC20(_path[1]).safeTransfer(vault, midOut);
            return
                _vaultSwap(
                    _path[1],
                    _path[2],
                    _minOut,
                    _receiver,
                    _rebateReceiver
                );
        }

        revert("Router: invalid _path.length");
    }

    function _vaultSwap(
        address _tokenIn,
        address _tokenOut,
        uint256 _minOut,
        address _receiver,
        address _rebateReceiver
    ) private returns (uint256) {
        uint256 amountOut;

        if (_tokenOut == usdg) {
            // buyUSDG
            amountOut = IVault(vault).buyUSDG(_tokenIn, _receiver);
        } else if (_tokenIn == usdg) {
            // sellUSDG
            amountOut = IVault(vault).sellUSDG(_tokenOut, _receiver);
        } else {
            // swap
            amountOut = IVault(vault).swapWithRebateReceiver(
                _tokenIn,
                _tokenOut,
                _receiver,
                _rebateReceiver
            );
        }

        require(amountOut >= _minOut, "Router: insufficient amountOut");
        return amountOut;
    }

    function _sender() private view returns (address) {
        return msg.sender;
    }

    function _validatePlugin(address _account) private view {
        require(plugins[msg.sender], "Router: invalid plugin");
        require(
            approvedPlugins[_account][msg.sender],
            "Router: plugin not approved"
        );
    }

    function _setReferral(address referrer) private {
        IReferral(referral).setReferral(_sender(), referrer);
    }
}

File 2 of 11 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

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

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

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

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

        return c;
    }

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

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

        return c;
    }

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

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

File 3 of 11 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

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

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

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

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

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

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

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

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

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

pragma solidity 0.6.12;

import "./IERC20.sol";
import "../math/SafeMath.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 SafeMath for uint256;
    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'
        // solhint-disable-next-line max-line-length
        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).add(
            value
        );
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(
                token.approve.selector,
                spender,
                newAllowance
            )
        );
    }

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

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

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

File 5 of 11 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

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

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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.3._
     */
    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.3._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) private 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

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 6 of 11 : IWETH.sol
//SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

interface IWETH {
    function deposit() external payable;

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

    function withdraw(uint256) external;
}

File 7 of 11 : IVault.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

import "./IVaultUtils.sol";

interface IVault {
    function isInitialized() external view returns (bool);

    function isSwapEnabled() external view returns (bool);

    function isLeverageEnabled() external view returns (bool);

    function setVaultUtils(IVaultUtils _vaultUtils) external;

    function setError(uint256 _errorCode, string calldata _error) external;

    function router() external view returns (address);

    function usdg() external view returns (address);

    function gov() external view returns (address);

    function whitelistedTokenCount() external view returns (uint256);

    function maxLeverage() external view returns (uint256);

    function minProfitTime() external view returns (uint256);

    function hasDynamicFees() external view returns (bool);

    function fundingInterval() external view returns (uint256);

    function totalTokenWeights() external view returns (uint256);

    function inManagerMode() external view returns (bool);

    function inPrivateLiquidationMode() external view returns (bool);

    function maxGasPrice() external view returns (uint256);

    function approvedRouters(address _account, address _router)
        external
        view
        returns (bool);

    function isLiquidator(address _account) external view returns (bool);

    function isManager(address _account) external view returns (bool);

    function minProfitBasisPoints(address _token)
        external
        view
        returns (uint256);

    function tokenBalances(address _token) external view returns (uint256);

    function lastFundingTimes(address _token) external view returns (uint256);

    function setMaxLeverage(uint256 _maxLeverage) external;

    function setInManagerMode(bool _inManagerMode) external;

    function setManager(address _manager, bool _isManager) external;

    function setIsSwapEnabled(bool _isSwapEnabled) external;

    function setIsLeverageEnabled(bool _isLeverageEnabled) external;

    function setMaxGasPrice(uint256 _maxGasPrice) external;

    function setUsdgAmount(address _token, uint256 _amount) external;

    function setBufferAmount(address _token, uint256 _amount) external;

    function setMaxGlobalShortSize(address _token, uint256 _amount) external;

    function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode)
        external;

    function setLiquidator(address _liquidator, bool _isActive) external;

    function setFundingRate(
        uint256 _fundingInterval,
        uint256 _fundingRateFactor,
        uint256 _stableFundingRateFactor
    ) external;

    function setFees(
        uint256 _taxBasisPoints,
        uint256 _stableTaxBasisPoints,
        uint256 _mintBurnFeeBasisPoints,
        uint256 _swapFeeBasisPoints,
        uint256 _stableSwapFeeBasisPoints,
        uint256 _marginFeeBasisPoints,
        uint256 _liquidationFeeUsd,
        uint256 _minProfitTime,
        bool _hasDynamicFees
    ) external;

    function setTokenConfig(
        address _token,
        uint256 _tokenDecimals,
        uint256 _redemptionBps,
        uint256 _minProfitBps,
        uint256 _maxUsdgAmount,
        bool _isStable,
        bool _isShortable
    ) external;

    function setPriceFeed(address _priceFeed) external;

    function withdrawFees(address _token, address _receiver)
        external
        returns (uint256);

    function directPoolDeposit(address _token) external;

    function buyUSDG(address _token, address _receiver)
        external
        returns (uint256);

    function sellUSDG(address _token, address _receiver)
        external
        returns (uint256);

    function swap(
        address _tokenIn,
        address _tokenOut,
        address _receiver
    ) external returns (uint256);

    function swapWithRebateReceiver(
        address _tokenIn,
        address _tokenOut,
        address _receiver,
        address rebateReceiver
    ) external returns (uint256);

    function increasePosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        uint256 _sizeDelta,
        bool _isLong
    ) external;

    function decreasePosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address _receiver
    ) external returns (uint256);

    function tokenToUsdMin(address _token, uint256 _tokenAmount)
        external
        view
        returns (uint256);

    function priceFeed() external view returns (address);

    function fundingRateFactor() external view returns (uint256);

    function stableFundingRateFactor() external view returns (uint256);

    function cumulativeFundingRates(address _token)
        external
        view
        returns (uint256);

    function getNextFundingRate(address _token) external view returns (uint256);

    function liquidationFeeUsd() external view returns (uint256);

    function taxBasisPoints() external view returns (uint256);

    function stableTaxBasisPoints() external view returns (uint256);

    function mintBurnFeeBasisPoints() external view returns (uint256);

    function swapFeeBasisPoints() external view returns (uint256);

    function stableSwapFeeBasisPoints() external view returns (uint256);

    function marginFeeBasisPoints() external view returns (uint256);

    function allWhitelistedTokensLength() external view returns (uint256);

    function allWhitelistedTokens(uint256) external view returns (address);

    function whitelistedTokens(address _token) external view returns (bool);

    function stableTokens(address _token) external view returns (bool);

    function shortableTokens(address _token) external view returns (bool);

    function feeReserves(address _token) external view returns (uint256);

    function globalShortSizes(address _token) external view returns (uint256);

    function globalShortAveragePrices(address _token)
        external
        view
        returns (uint256);

    function maxGlobalShortSizes(address _token)
        external
        view
        returns (uint256);

    function tokenDecimals(address _token) external view returns (uint256);

    function tokenWeights(address _token) external view returns (uint256);

    function guaranteedUsd(address _token) external view returns (uint256);

    function poolAmounts(address _token) external view returns (uint256);

    function bufferAmounts(address _token) external view returns (uint256);

    function reservedAmounts(address _token) external view returns (uint256);

    function usdgAmounts(address _token) external view returns (uint256);

    function maxUsdgAmounts(address _token) external view returns (uint256);

    function getRedemptionAmount(address _token, uint256 _usdgAmount)
        external
        view
        returns (uint256);

    function getMaxPrice(address _token) external view returns (uint256);

    function getMinPrice(address _token) external view returns (uint256);

    function getPosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        bool _isLong
    )
        external
        view
        returns (
            uint256,
            uint256,
            uint256,
            uint256,
            uint256,
            uint256,
            bool,
            uint256
        );

    function vaultUtils() external view returns (IVaultUtils);

    function usdToTokenMax(address _token, uint256 _usdAmount)
        external
        view
        returns (uint256);

    function usdToTokenMin(address _token, uint256 _usdAmount)
        external
        view
        returns (uint256);

    function getPositionKey(
        address _account,
        address _collateralToken,
        address _indexToken,
        bool _isLong
    ) external pure returns (bytes32);
}

File 8 of 11 : IVaultPriceFeed.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

interface IVaultPriceFeed {
    function adjustmentBasisPoints(address _token)
        external
        view
        returns (uint256);

    function isAdjustmentAdditive(address _token) external view returns (bool);

    function setH2soQuoteLifetimeSeconds(uint256 value) external;

    function setAdjustment(
        address _token,
        bool _isAdditive,
        uint256 _adjustmentBps
    ) external;

    function setUseV2Pricing(bool _useV2Pricing) external;

    function setIsAmmEnabled(bool _isEnabled) external;

    function setIsSecondaryPriceEnabled(bool _isEnabled) external;

    function setSpreadBasisPoints(address _token, uint256 _spreadBasisPoints)
        external;

    function setSpreadThresholdBasisPoints(uint256 _spreadThresholdBasisPoints)
        external;

    function setFavorPrimaryPrice(bool _favorPrimaryPrice) external;

    function setPriceSampleSpace(uint256 _priceSampleSpace) external;

    function setMaxStrictPriceDeviation(uint256 _maxStrictPriceDeviation)
        external;

    function getPrice(
        address _token,
        bool _maximise,
        bool _includeAmmPrice,
        bool _useSwapPricing
    ) external view returns (uint256);

    function getAmmPrice(address _token) external view returns (uint256);

    function getPrimaryPrice(address _token, bool _maximise)
        external
        view
        returns (uint256);

    function setTokenConfig(
        address _token,
        address _priceFeed,
        uint256 _priceDecimals,
        bool _isStrictStable
    ) external;

    function h2sofaApplySignedQuote(bytes calldata signedQuoteData) external;
}

File 9 of 11 : IRouter.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

interface IRouter {
    function addPlugin(address _plugin) external;

    function pluginTransfer(
        address _token,
        address _account,
        address _receiver,
        uint256 _amount
    ) external;

    function pluginIncreasePosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        uint256 _sizeDelta,
        bool _isLong
    ) external;

    function pluginDecreasePosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address _receiver
    ) external returns (uint256);

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

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

File 10 of 11 : IReferral.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.6.12;

interface IReferral {
    function setReferral(address userAccount, address referralAccount) external;

    function getReferral(address userAccount) external view returns (address);
}

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

pragma solidity 0.6.12;

interface IVaultUtils {
    function updateCumulativeFundingRate(
        address _collateralToken,
        address _indexToken
    ) external returns (bool);

    function validateIncreasePosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        uint256 _sizeDelta,
        bool _isLong
    ) external view;

    function validateDecreasePosition(
        address _account,
        address _collateralToken,
        address _indexToken,
        uint256 _collateralDelta,
        uint256 _sizeDelta,
        bool _isLong,
        address _receiver
    ) external view;

    function validateLiquidation(
        address _account,
        address _collateralToken,
        address _indexToken,
        bool _isLong,
        bool _raise
    ) external view returns (uint256, uint256);

    function getEntryFundingRate(
        address _collateralToken,
        address _indexToken,
        bool _isLong
    ) external view returns (uint256);

    function getPositionFee(
        address _account,
        address _collateralToken,
        address _indexToken,
        bool _isLong,
        uint256 _sizeDelta
    ) external view returns (uint256);

    function getFundingFee(
        address _account,
        address _collateralToken,
        address _indexToken,
        bool _isLong,
        uint256 _size,
        uint256 _entryFundingRate
    ) external view returns (uint256);

    function getBuyUsdgFeeBasisPoints(address _token, uint256 _usdgAmount)
        external
        view
        returns (uint256);

    function getSellUsdgFeeBasisPoints(address _token, uint256 _usdgAmount)
        external
        view
        returns (uint256);

    function getSwapFeeBasisPoints(
        address _tokenIn,
        address _tokenOut,
        uint256 _usdgAmount
    ) external view returns (uint256);

    function getFeeBasisPoints(
        address _token,
        uint256 _usdgDelta,
        uint256 _feeBasisPoints,
        uint256 _taxBasisPoints,
        bool _increment
    ) external view returns (uint256);

    function getDelta(
        address _indexToken,
        uint256 _size,
        uint256 _averagePrice,
        bool _isLong,
        uint256 _lastIncreasedTime
    ) external view returns (bool, uint256);

    function getTargetUsdgAmount(address _token)
        external
        view
        returns (uint256);
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_usdg","type":"address"},{"internalType":"address","name":"_weth","type":"address"},{"internalType":"address","name":"_referral","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":false,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"Swap","type":"event"},{"inputs":[{"internalType":"address","name":"_plugin","type":"address"}],"name":"addPlugin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_plugin","type":"address"}],"name":"approvePlugin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"approvedPlugins","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_collateralToken","type":"address"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_collateralDelta","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"decreasePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_collateralDelta","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"decreasePositionAndSwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_collateralDelta","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"address payable","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"decreasePositionAndSwapETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_collateralToken","type":"address"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_collateralDelta","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"address payable","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"decreasePositionETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_plugin","type":"address"}],"name":"denyPlugin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"directPoolDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"gov","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"increasePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"increasePositionETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"},{"internalType":"address","name":"referrer","type":"address"}],"name":"increasePositionETHWithReferrer","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"},{"internalType":"address","name":"referrer","type":"address"}],"name":"increasePositionWithReferrer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"address","name":"_collateralToken","type":"address"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_collateralDelta","type":"uint256"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"pluginDecreasePosition","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"address","name":"_collateralToken","type":"address"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"uint256","name":"_sizeDelta","type":"uint256"},{"internalType":"bool","name":"_isLong","type":"bool"}],"name":"pluginIncreasePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_account","type":"address"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"pluginTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"plugins","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referral","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_plugin","type":"address"}],"name":"removePlugin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gov","type":"address"}],"name":"setGov","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"swapETHToTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"},{"internalType":"address","name":"referrer","type":"address"}],"name":"swapETHToTokensWithReferrer","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"address payable","name":"_receiver","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"}],"name":"swapTokensToETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"address payable","name":"_receiver","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"},{"internalType":"address","name":"referrer","type":"address"}],"name":"swapTokensToETHWithReferrer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_path","type":"address[]"},{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"bytes","name":"signedQuoteData","type":"bytes"},{"internalType":"address","name":"referrer","type":"address"}],"name":"swapWithReferrer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"usdg","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

6101006040523480156200001257600080fd5b5060405162003e2838038062003e28833981810160405260808110156200003857600080fd5b50805160208201516040830151606090930151919290916001600160a01b038416158015906200007057506001600160a01b03831615155b80156200008557506001600160a01b03821615155b80156200009a57506001600160a01b03811615155b620000ec576040805162461bcd60e51b815260206004820152601860248201527f4164647265737365732063616e6e6f74206265207a65726f0000000000000000604482015290519081900360640190fd5b6001600160601b0319606094851b811660c05292841b831660a05290831b821660805290911b1660e052600080546001600160a01b0319163317905560805160601c60a05160601c60c05160601c60e05160601c613bf162000237600039806114e45280612ae35250806115a352806117e552806118ba52806119bf5280611af45280611c105280611d225280611e475280611ea15280611f2f5280611f56528061209452806121e1528061246f52806125aa52806126a1528061280852806129365280612a5e5280612abf5280612c205280612cde5280612eda5280612fb6528061308c52806131965280613272528061334852806134b752806135a4528061365c525080612a9b528061347d528061356a5250806101e1528061150852806119705280611ff952806123da52806126035280612b7e5280612bfc52806133e45250613bf16000f3fe6080604052600436106101d15760003560e01c8063877c7b8a116100f7578063cfad57a211610095578063e8d91a3a11610064578063e8d91a3a14611282578063f060febd1461133b578063f5b91b7b14611473578063fbfa77cf146114885761024e565b8063cfad57a214610fc3578063d8867fc814610ff6578063daffc8ec14611029578063e49b7329146111615761024e565b8063980a0578116100d1578063980a057814610d25578063a4d95b6414610e45578063cccc6e0514610e78578063cedd437514610f905761024e565b8063877c7b8a14610b7c57806390b64ad314610cb1578063956f285e14610cea5761024e565b806325ecda9a1161016f578063481e17e31161013e578063481e17e3146108565780634b12e6431461095b5780634f6970d9146109a25780636bb2529214610a5b5761024e565b806325ecda9a146106855780632662166b1461079b57806338c74dd91461080e5780633fc8cef3146108415761024e565b80631441a5a9116101ab5780631441a5a9146104c85780631b417cc8146104dd5780631b827878146105eb5780631f1dd176146106345761024e565b80630dde87fd1461025357806310a523161461036b57806312d43a51146104975761024e565b3661024e57336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461024c576040805162461bcd60e51b81526020600482015260166024820152752937baba32b91d1034b73b30b634b21039b2b73232b960511b604482015290519081900360640190fd5b005b600080fd5b34801561025f57600080fd5b5061024c600480360360a081101561027657600080fd5b810190602081018135600160201b81111561029057600080fd5b8201836020820111156102a257600080fd5b803590602001918460208302840111600160201b831117156102c357600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435956020860135956001600160a01b0360408201351695509193509150608081019060600135600160201b81111561032d57600080fd5b82018360208201111561033f57600080fd5b803590602001918460018302840111600160201b8311171561036057600080fd5b50909250905061149d565b34801561037757600080fd5b5061024c600480360361010081101561038f57600080fd5b810190602081018135600160201b8111156103a957600080fd5b8201836020820111156103bb57600080fd5b803590602001918460208302840111600160201b831117156103dc57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092956001600160a01b0385351695602086013595604081013595506060810135945060808101351515935060a081013592919060e081019060c00135600160201b81111561045957600080fd5b82018360208201111561046b57600080fd5b803590602001918460018302840111600160201b8311171561048c57600080fd5b5090925090506114b5565b3480156104a357600080fd5b506104ac6114d3565b604080516001600160a01b039092168252519081900360200190f35b3480156104d457600080fd5b506104ac6114e2565b61024c600480360360a08110156104f357600080fd5b810190602081018135600160201b81111561050d57600080fd5b82018360208201111561051f57600080fd5b803590602001918460208302840111600160201b8311171561054057600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435956001600160a01b0360208701351695919450925060608101915060400135600160201b8111156105a457600080fd5b8201836020820111156105b657600080fd5b803590602001918460018302840111600160201b831117156105d757600080fd5b9193509150356001600160a01b0316611506565b3480156105f757600080fd5b5061024c6004803603608081101561060e57600080fd5b506001600160a01b03813581169160208101358216916040820135169060600135611777565b34801561064057600080fd5b5061024c600480360360a081101561065757600080fd5b506001600160a01b03813581169160208101358216916040820135169060608101359060800135151561179b565b61024c600480360360e081101561069b57600080fd5b810190602081018135600160201b8111156106b557600080fd5b8201836020820111156106c757600080fd5b803590602001918460208302840111600160201b831117156106e857600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092956001600160a01b0385351695602086013595604081013595506060810135151594506080810135935060c081019060a00135600160201b81111561075d57600080fd5b82018360208201111561076f57600080fd5b803590602001918460018302840111600160201b8311171561079057600080fd5b509092509050611843565b3480156107a757600080fd5b506107fc600480360360e08110156107be57600080fd5b506001600160a01b0381358116916020810135821691604082013581169160608101359160808201359160a081013515159160c0909101351661185f565b60408051918252519081900360200190f35b34801561081a57600080fd5b5061024c6004803603602081101561083157600080fd5b50356001600160a01b031661193d565b34801561084d57600080fd5b506104ac61196e565b61024c6004803603608081101561086c57600080fd5b810190602081018135600160201b81111561088657600080fd5b82018360208201111561089857600080fd5b803590602001918460208302840111600160201b831117156108b957600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435956001600160a01b0360208701351695919450925060608101915060400135600160201b81111561091d57600080fd5b82018360208201111561092f57600080fd5b803590602001918460018302840111600160201b8311171561095057600080fd5b509092509050611992565b34801561096757600080fd5b5061098e6004803603602081101561097e57600080fd5b50356001600160a01b03166119a8565b604080519115158252519081900360200190f35b3480156109ae57600080fd5b5061024c60048036036101008110156109c657600080fd5b6001600160a01b0382358116926020810135821692604082013592606083013592608081013515159260a08201359092169160c08201359190810190610100810160e0820135600160201b811115610a1d57600080fd5b820183602082011115610a2f57600080fd5b803590602001918460018302840111600160201b83111715610a5057600080fd5b5090925090506119bd565b348015610a6757600080fd5b5061024c600480360360c0811015610a7e57600080fd5b810190602081018135600160201b811115610a9857600080fd5b820183602082011115610aaa57600080fd5b803590602001918460208302840111600160201b83111715610acb57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435956020860135956001600160a01b0360408201351695509193509150608081019060600135600160201b811115610b3557600080fd5b820183602082011115610b4757600080fd5b803590602001918460018302840111600160201b83111715610b6857600080fd5b9193509150356001600160a01b0316611ae9565b348015610b8857600080fd5b5061024c6004803603610120811015610ba057600080fd5b810190602081018135600160201b811115610bba57600080fd5b820183602082011115610bcc57600080fd5b803590602001918460208302840111600160201b83111715610bed57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092956001600160a01b0385351695602086013595604081013595506060810135945060808101351515935060a081013592919060e081019060c00135600160201b811115610c6a57600080fd5b820183602082011115610c7c57600080fd5b803590602001918460018302840111600160201b83111715610c9d57600080fd5b9193509150356001600160a01b0316611d17565b348015610cbd57600080fd5b5061024c60048036036040811015610cd457600080fd5b506001600160a01b038135169060200135611f17565b348015610cf657600080fd5b5061098e60048036036040811015610d0d57600080fd5b506001600160a01b0381358116916020013516611fd7565b61024c6004803603610100811015610d3c57600080fd5b810190602081018135600160201b811115610d5657600080fd5b820183602082011115610d6857600080fd5b803590602001918460208302840111600160201b83111715610d8957600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092956001600160a01b0385351695602086013595604081013595506060810135151594506080810135935060c081019060a00135600160201b811115610dfe57600080fd5b820183602082011115610e1057600080fd5b803590602001918460018302840111600160201b83111715610e3157600080fd5b9193509150356001600160a01b0316611ff7565b348015610e5157600080fd5b5061024c60048036036020811015610e6857600080fd5b50356001600160a01b0316612237565b348015610e8457600080fd5b5061024c600480360360a0811015610e9b57600080fd5b810190602081018135600160201b811115610eb557600080fd5b820183602082011115610ec757600080fd5b803590602001918460208302840111600160201b83111715610ee857600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435956020860135956001600160a01b0360408201351695509193509150608081019060600135600160201b811115610f5257600080fd5b820183602082011115610f6457600080fd5b803590602001918460018302840111600160201b83111715610f8557600080fd5b5090925090506122ab565b348015610f9c57600080fd5b5061024c60048036036020811015610fb357600080fd5b50356001600160a01b03166122bb565b348015610fcf57600080fd5b5061024c60048036036020811015610fe657600080fd5b50356001600160a01b03166122e9565b34801561100257600080fd5b5061024c6004803603602081101561101957600080fd5b50356001600160a01b031661235e565b34801561103557600080fd5b5061024c600480360361012081101561104d57600080fd5b810190602081018135600160201b81111561106757600080fd5b82018360208201111561107957600080fd5b803590602001918460208302840111600160201b8311171561109a57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092956001600160a01b038535811696602087013596604081013596506060810135151595506080810135909216935060a08201359260c08301359290919061010081019060e00135600160201b81111561112357600080fd5b82018360208201111561113557600080fd5b803590602001918460018302840111600160201b8311171561115657600080fd5b5090925090506123d8565b34801561116d57600080fd5b5061024c600480360360c081101561118457600080fd5b810190602081018135600160201b81111561119e57600080fd5b8201836020820111156111b057600080fd5b803590602001918460208302840111600160201b831117156111d157600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435956020860135956001600160a01b0360408201351695509193509150608081019060600135600160201b81111561123b57600080fd5b82018360208201111561124d57600080fd5b803590602001918460018302840111600160201b8311171561126e57600080fd5b9193509150356001600160a01b0316612601565b34801561128e57600080fd5b5061024c60048036036101008110156112a657600080fd5b6001600160a01b0382358116926020810135821692604082013592606083013592608081013515159260a08201359092169160c08201359190810190610100810160e0820135600160201b8111156112fd57600080fd5b82018360208201111561130f57600080fd5b803590602001918460018302840111600160201b8311171561133057600080fd5b509092509050612806565b34801561134757600080fd5b5061024c600480360361012081101561135f57600080fd5b810190602081018135600160201b81111561137957600080fd5b82018360208201111561138b57600080fd5b803590602001918460208302840111600160201b831117156113ac57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092956001600160a01b038535811696602087013596604081013596506060810135151595506080810135909216935060a08201359260c08301359290919061010081019060e00135600160201b81111561143557600080fd5b82018360208201111561144757600080fd5b803590602001918460018302840111600160201b8311171561146857600080fd5b509092509050612934565b34801561147f57600080fd5b506104ac612a99565b34801561149457600080fd5b506104ac612abd565b6114ad8686868686866000611ae9565b505050505050565b6114c88989898989898989896000611d17565b505050505050505050565b6000546001600160a01b031681565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168660008151811061153d57fe5b60200260200101516001600160a01b031614611598576040805162461bcd60e51b81526020600482015260156024820152740a4deeae8cae47440d2dcecc2d8d2c840bee0c2e8d605b1b604482015290519081900360640190fd5b6115a181612ae1565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156115fa57600080fd5b505afa15801561160e573d6000803e3d6000fd5b505050506040513d602081101561162457600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018590526001600160a01b03909216916329adf8ba91869186918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b15801561169a57600080fd5b505af11580156116ae573d6000803e3d6000fd5b505050506116ba612b7c565b60006116cf8787876116ca612c49565b612c4d565b90507fcd3829a3813dc3cdd188fd3d01dcf3268c16be2fdd2dd21d0665418816e46062338860008151811061170057fe5b60200260200101518960018b51038151811061171857fe5b6020026020010151348560405180866001600160a01b03168152602001856001600160a01b03168152602001846001600160a01b031681526020018381526020018281526020019550505050505060405180910390a150505050505050565b61178083612d9d565b6117956001600160a01b038516848484612e75565b50505050565b6117a485612d9d565b604080516348d91abf60e01b81526001600160a01b0387811660048301528681166024830152858116604483015260648201859052831515608483015291517f0000000000000000000000000000000000000000000000000000000000000000909216916348d91abf9160a48082019260009290919082900301818387803b15801561182f57600080fd5b505af11580156114c8573d6000803e3d6000fd5b61185588888888888888886000611ff7565b5050505050505050565b600061186a88612d9d565b6040805163082a084960e41b81526001600160a01b038a8116600483015289811660248301528881166044830152606482018890526084820187905285151560a483015284811660c483015291517f0000000000000000000000000000000000000000000000000000000000000000909216916382a084909160e4808201926020929091908290030181600087803b15801561190557600080fd5b505af1158015611919573d6000803e3d6000fd5b505050506040513d602081101561192f57600080fd5b505198975050505050505050565b3360009081526002602090815260408083206001600160a01b0394909416835292905220805460ff19166001179055565b7f000000000000000000000000000000000000000000000000000000000000000081565b6119a185858585856000611506565b5050505050565b60016020526000908152604090205460ff1681565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b158015611a1657600080fd5b505afa158015611a2a573d6000803e3d6000fd5b505050506040513d6020811015611a4057600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018490526001600160a01b03909216916329adf8ba91859185918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b158015611ab657600080fd5b505af1158015611aca573d6000803e3d6000fd5b50505050611add89898989898989612ecf565b50505050505050505050565b611af281612ae1565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b158015611b4b57600080fd5b505afa158015611b5f573d6000803e3d6000fd5b505050506040513d6020811015611b7557600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018590526001600160a01b03909216916329adf8ba91869186918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b158015611beb57600080fd5b505af1158015611bff573d6000803e3d6000fd5b50505050611c5e611c0e612c49565b7f0000000000000000000000000000000000000000000000000000000000000000888a600081518110611c3d57fe5b60200260200101516001600160a01b0316612e75909392919063ffffffff16565b6000611c6e8887876116ca612c49565b90507fcd3829a3813dc3cdd188fd3d01dcf3268c16be2fdd2dd21d0665418816e460623389600081518110611c9f57fe5b60200260200101518a60018c510381518110611cb757fe5b60200260200101518a8560405180866001600160a01b03168152602001856001600160a01b03168152602001846001600160a01b031681526020018381526020018281526020019550505050505060405180910390a15050505050505050565b611d2081612ae1565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b158015611d7957600080fd5b505afa158015611d8d573d6000803e3d6000fd5b505050506040513d6020811015611da357600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018590526001600160a01b03909216916329adf8ba91869186918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b158015611e1957600080fd5b505af1158015611e2d573d6000803e3d6000fd5b505050506000881115611e7457611e74611e45612c49565b7f00000000000000000000000000000000000000000000000000000000000000008a8d600081518110611c3d57fe5b60018a51118015611e855750600088115b15611ef3576000611e9a8b89306116ca612c49565b9050611ef17f0000000000000000000000000000000000000000000000000000000000000000828d60018f510381518110611ed157fe5b60200260200101516001600160a01b03166131369092919063ffffffff16565b505b611add8a60018c510381518110611f0657fe5b60200260200101518a88888861318d565b611f54611f22612c49565b6001600160a01b038416907f000000000000000000000000000000000000000000000000000000000000000084612e75565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635f7bc119836040518263ffffffff1660e01b815260040180826001600160a01b03168152602001915050600060405180830381600087803b158015611fc357600080fd5b505af11580156114ad573d6000803e3d6000fd5b600260209081526000928352604080842090915290825290205460ff1681565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168960008151811061202e57fe5b60200260200101516001600160a01b031614612089576040805162461bcd60e51b81526020600482015260156024820152740a4deeae8cae47440d2dcecc2d8d2c840bee0c2e8d605b1b604482015290519081900360640190fd5b61209281612ae1565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156120eb57600080fd5b505afa1580156120ff573d6000803e3d6000fd5b505050506040513d602081101561211557600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018590526001600160a01b03909216916329adf8ba91869186918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b15801561218b57600080fd5b505af115801561219f573d6000803e3d6000fd5b5050505060003411156121b4576121b4612b7c565b600189511180156121c55750600034115b156122135760006121da8a89306116ca612c49565b90506122117f0000000000000000000000000000000000000000000000000000000000000000828c60018e510381518110611ed157fe5b505b6114c88960018b51038151811061222657fe5b60200260200101518988888861318d565b6000546001600160a01b0316331461228a576040805162461bcd60e51b81526020600482015260116024820152702937baba32b91d103337b93134b23232b760791b604482015290519081900360640190fd5b6001600160a01b03166000908152600160205260409020805460ff19169055565b6114ad8686868686866000612601565b3360009081526002602090815260408083206001600160a01b0394909416835292905220805460ff19169055565b6000546001600160a01b0316331461233c576040805162461bcd60e51b81526020600482015260116024820152702937baba32b91d103337b93134b23232b760791b604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633146123b1576040805162461bcd60e51b81526020600482015260116024820152702937baba32b91d103337b93134b23232b760791b604482015290519081900360640190fd5b6001600160a01b03166000908152600160208190526040909120805460ff19169091179055565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168a60018c51038151811061241257fe5b60200260200101516001600160a01b03161461246d576040805162461bcd60e51b81526020600482015260156024820152740a4deeae8cae47440d2dcecc2d8d2c840bee0c2e8d605b1b604482015290519081900360640190fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156124c657600080fd5b505afa1580156124da573d6000803e3d6000fd5b505050506040513d60208110156124f057600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018490526001600160a01b03909216916329adf8ba91859185918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b15801561256657600080fd5b505af115801561257a573d6000803e3d6000fd5b5050505060006125a38b60008151811061259057fe5b60200260200101518b8b8b8b308b612ecf565b90506125d77f0000000000000000000000000000000000000000000000000000000000000000828d600081518110611ed157fe5b60006125e78c86306116ca612c49565b90506125f381886133e2565b505050505050505050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168760018951038151811061263b57fe5b60200260200101516001600160a01b031614612696576040805162461bcd60e51b81526020600482015260156024820152740a4deeae8cae47440d2dcecc2d8d2c840bee0c2e8d605b1b604482015290519081900360640190fd5b61269f81612ae1565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156126f857600080fd5b505afa15801561270c573d6000803e3d6000fd5b505050506040513d602081101561272257600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018590526001600160a01b03909216916329adf8ba91869186918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b15801561279857600080fd5b505af11580156127ac573d6000803e3d6000fd5b505050506127bb611c0e612c49565b60006127cb8887306116ca612c49565b90506127d781866133e2565b7fcd3829a3813dc3cdd188fd3d01dcf3268c16be2fdd2dd21d0665418816e460623389600081518110611c9f57fe5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b15801561285f57600080fd5b505afa158015612873573d6000803e3d6000fd5b505050506040513d602081101561288957600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018490526001600160a01b03909216916329adf8ba91859185918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b1580156128ff57600080fd5b505af1158015612913573d6000803e3d6000fd5b5050505060006129288a8a8a8a8a308a612ecf565b9050611add81866133e2565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b15801561298d57600080fd5b505afa1580156129a1573d6000803e3d6000fd5b505050506040513d60208110156129b757600080fd5b50516040516314d6fc5d60e11b8152602060048201908152602482018490526001600160a01b03909216916329adf8ba91859185918190604401848480828437600081840152601f19601f8201169050808301925050509350505050600060405180830381600087803b158015612a2d57600080fd5b505af1158015612a41573d6000803e3d6000fd5b505050506000612a578b60008151811061259057fe5b9050612a8b7f0000000000000000000000000000000000000000000000000000000000000000828d600081518110611ed157fe5b6125f38b85886116ca612c49565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637543e3f0612b18612c49565b836040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b0316815260200192505050600060405180830381600087803b158015612b6857600080fd5b505af11580156119a1573d6000803e3d6000fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b158015612bd757600080fd5b505af1158015612beb573d6000803e3d6000fd5b50612c479350506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001691507f0000000000000000000000000000000000000000000000000000000000000000905034613136565b565b3390565b6000845160021415612c9557612c8e85600081518110612c6957fe5b602002602001015186600181518110612c7e57fe5b6020026020010151868686613478565b9050612d95565b845160031415612d48576000612cd786600081518110612cb157fe5b602002602001015187600181518110612cc657fe5b602002602001015160003087613478565b9050612d0b7f00000000000000000000000000000000000000000000000000000000000000008288600181518110611ed157fe5b612d4086600181518110612d1b57fe5b602002602001015187600281518110612d3057fe5b6020026020010151878787613478565b915050612d95565b6040805162461bcd60e51b815260206004820152601c60248201527f526f757465723a20696e76616c6964205f706174682e6c656e67746800000000604482015290519081900360640190fd5b949350505050565b3360009081526001602052604090205460ff16612dfa576040805162461bcd60e51b81526020600482015260166024820152752937baba32b91d1034b73b30b634b21038363ab3b4b760511b604482015290519081900360640190fd5b6001600160a01b038116600090815260026020908152604080832033845290915290205460ff16612e72576040805162461bcd60e51b815260206004820152601b60248201527f526f757465723a20706c7567696e206e6f7420617070726f7665640000000000604482015290519081900360640190fd5b50565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052611795908590613735565b60008315612fb357817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166381a612d6896040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015612f4557600080fd5b505afa158015612f59573d6000803e3d6000fd5b505050506040513d6020811015612f6f57600080fd5b50511015612fae5760405162461bcd60e51b8152600401808060200182810382526023815260200180613b4b6023913960400191505060405180910390fd5b61308a565b817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e124e6d2896040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561302157600080fd5b505afa158015613035573d6000803e3d6000fd5b505050506040513d602081101561304b57600080fd5b5051111561308a5760405162461bcd60e51b8152600401808060200182810382526024815260200180613b986024913960400191505060405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166382a084906130c1612c49565b604080516001600160e01b031960e085901b1681526001600160a01b039283166004820152828d166024820152828c166044820152606481018b9052608481018a905288151560a482015291871660c48301525160e48083019260209291908290030181600087803b15801561190557600080fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052613188908490613735565b505050565b811561326f57807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e124e6d2866040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561320157600080fd5b505afa158015613215573d6000803e3d6000fd5b505050506040513d602081101561322b57600080fd5b5051111561326a5760405162461bcd60e51b8152600401808060200182810382526024815260200180613b986024913960400191505060405180910390fd5b613346565b807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166381a612d6866040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156132dd57600080fd5b505afa1580156132f1573d6000803e3d6000fd5b505050506040513d602081101561330757600080fd5b505110156133465760405162461bcd60e51b8152600401808060200182810382526023815260200180613b4b6023913960400191505060405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166348d91abf61337d612c49565b604080516001600160e01b031960e085901b1681526001600160a01b039283166004820152828a16602482015291881660448301526064820187905285151560848301525160a480830192600092919082900301818387803b15801561182f57600080fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632e1a7d4d836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561344857600080fd5b505af115801561345c573d6000803e3d6000fd5b50613474925050506001600160a01b038216836137e6565b5050565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316866001600160a01b03161415613568577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663817bb85788866040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b0316815260200192505050602060405180830381600087803b15801561353557600080fd5b505af1158015613549573d6000803e3d6000fd5b505050506040513d602081101561355f57600080fd5b505190506136d6565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316876001600160a01b03161415613622577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663711e619087866040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b0316815260200192505050602060405180830381600087803b15801561353557600080fd5b604080516324894b5960e01b81526001600160a01b03898116600483015288811660248301528681166044830152858116606483015291517f0000000000000000000000000000000000000000000000000000000000000000909216916324894b59916084808201926020929091908290030181600087803b1580156136a757600080fd5b505af11580156136bb573d6000803e3d6000fd5b505050506040513d60208110156136d157600080fd5b505190505b8481101561372b576040805162461bcd60e51b815260206004820152601e60248201527f526f757465723a20696e73756666696369656e7420616d6f756e744f75740000604482015290519081900360640190fd5b9695505050505050565b606061378a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166138cb9092919063ffffffff16565b805190915015613188578080602001905160208110156137a957600080fd5b50516131885760405162461bcd60e51b815260040180806020018281038252602a815260200180613b6e602a913960400191505060405180910390fd5b8047101561383b576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015290519081900360640190fd5b6040516000906001600160a01b0384169083908381818185875af1925050503d8060008114613886576040519150601f19603f3d011682016040523d82523d6000602084013e61388b565b606091505b50509050806131885760405162461bcd60e51b815260040180806020018281038252603a815260200180613aeb603a913960400191505060405180910390fd5b60606138da84846000856138e4565b90505b9392505050565b6060824710156139255760405162461bcd60e51b8152600401808060200182810382526026815260200180613b256026913960400191505060405180910390fd5b61392e85613a40565b61397f576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b602083106139be5780518252601f19909201916020918201910161399f565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613a20576040519150601f19603f3d011682016040523d82523d6000602084013e613a25565b606091505b5091509150613a35828286613a46565b979650505050505050565b3b151590565b60608315613a555750816138dd565b825115613a655782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613aaf578181015183820152602001613a97565b50505050905090810190601f168015613adc5780820380516001836020036101000a031916815260200191505b509250505060405180910390fdfe416464726573733a20756e61626c6520746f2073656e642076616c75652c20726563697069656e74206d61792068617665207265766572746564416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c526f757465723a206d61726b207072696365206c6f776572207468616e206c696d69745361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564526f757465723a206d61726b20707269636520686967686572207468616e206c696d6974a26469706673582212205be2c43f3031249fda20cf6f0ad02def5f44fa8a6ff077056d561214645b1c5464736f6c634300060c00330000000000000000000000001785e8491e7e9d771b2a6e9e389c25265f06326a000000000000000000000000823412ac2ffd566cfe35560a850efec81337e67f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000eababd4d5b4807b709e24ceb9ecea753d4a97ff5

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

0000000000000000000000001785e8491e7e9d771b2a6e9e389c25265f06326a000000000000000000000000823412ac2ffd566cfe35560a850efec81337e67f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000eababd4d5b4807b709e24ceb9ecea753d4a97ff5

-----Decoded View---------------
Arg [0] : _vault (address): 0x1785e8491e7e9d771b2a6e9e389c25265f06326a
Arg [1] : _usdg (address): 0x823412ac2ffd566cfe35560a850efec81337e67f
Arg [2] : _weth (address): 0x82af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [3] : _referral (address): 0xeababd4d5b4807b709e24ceb9ecea753d4a97ff5

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 0000000000000000000000001785e8491e7e9d771b2a6e9e389c25265f06326a
Arg [1] : 000000000000000000000000823412ac2ffd566cfe35560a850efec81337e67f
Arg [2] : 00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [3] : 000000000000000000000000eababd4d5b4807b709e24ceb9ecea753d4a97ff5


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.