Contract 0xf0bb2d7ba15b8860864a810e675a00f0fe828e06

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x2c768bc7a21b994764c127f5d18252553c63d35afdc128fd9667652f700831b5Unstake USDL41163552021-12-27 17:03:38397 days 22 mins ago0x55f5e03fcbe088eddba68b4657ade3243ac45009 IN  Lemma Finance: Lemma Router0 ETH0.000551173256 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e676662584Mint USDL Using ...37920712021-12-12 18:11:22411 days 23 hrs ago0xf99a7f0faf4e1ab3ad1ba4cab0f2737798150950 IN  Lemma Finance: Lemma Router0 ETH0.00182986753 ETH
0x47a8320471549c1ffc7f19f0f0af8b2f07a6f6594585eb8149bd9a34c2a260fcMint For Eth And...37840962021-12-12 12:50:02412 days 4 hrs ago0x43a60df4d280c1c6b10718ee95fca9f44ae189d6 IN  Lemma Finance: Lemma Router0.9 ETH0.000647995881 ETH
0xc7cc58ec5449b4004dd6ec85470913e026fee7a394e30f49faa7549419d369a9Unstake And Rede...37767102021-12-12 7:18:53412 days 10 hrs ago0x4e8efa766f63906b008a11e3bf4afa6e96892c5e IN  Lemma Finance: Lemma Router0 ETH0.00146321419 ETH
0x4a292f5eab7747fd917427dbb0e95cf01df7e6d2680db6502ae0d80b2ba5cb9bMint For Eth And...36216412021-12-06 16:15:24418 days 1 hr ago0x31c9e8711f59f6c913a7da95741de3539fe64bcd IN  Lemma Finance: Lemma Router0.4 ETH0.001395083367 ETH
0xb45631e67a5e087537f0ff25ce98bb16aa354890ab6de1c0a4b0a67a274a4709Stake USDL36187812021-12-06 14:17:24418 days 3 hrs ago0x43a60df4d280c1c6b10718ee95fca9f44ae189d6 IN  Lemma Finance: Lemma Router0 ETH0.000676790457 ETH
0x98ed07f1436cb83a5b99ea09f93060b1c8cba7ad11eb6f6de7cad65039a735caMint USDLETH36179642021-12-06 13:37:05418 days 3 hrs ago0x43a60df4d280c1c6b10718ee95fca9f44ae189d6 IN  Lemma Finance: Lemma Router2 ETH0.001192083675 ETH
0xdedd81b76f7f18e2cd7b6c8caee0b200f052fe221ed5610719860a44982d8c40Unstake And Rede...36174972021-12-06 13:18:13418 days 4 hrs ago0x5ee42438d0d8fc399c94ef3543665e993e847b49 IN  Lemma Finance: Lemma Router0 ETH0.002076877238 ETH
0x669688dded89279302e6a88d9a29178fa47774bd64fdfb8c07cdf78d015f136eStake USDL35760522021-12-05 0:06:21419 days 17 hrs ago0xcd43aad533e663b726dae4a08185e9db8ebc9f6f IN  Lemma Finance: Lemma Router0 ETH0.001277179055 ETH
0x0bf02c338860294be6a47c149c02d3a2238840dcb65fde030fbf7bfa5129745aMint USDL To Usi...35760152021-12-05 0:06:21419 days 17 hrs ago0xcd43aad533e663b726dae4a08185e9db8ebc9f6f IN  Lemma Finance: Lemma Router0 ETH0.002555603809 ETH
0x71b36cdfb5f8974fa589a4d6b96854ef4c8d2c9ab4c73696b8166490a9cd63ceMint For Eth And...35623392021-12-04 10:37:57420 days 6 hrs ago0x43a60df4d280c1c6b10718ee95fca9f44ae189d6 IN  Lemma Finance: Lemma Router0.5 ETH0.001688685607 ETH
0x457705b2b5cbd8e2acfbf03bf62c0eda616e05825f6ff87ceaa3a872f0957d57Unstake And Rede...35566922021-12-04 6:30:47420 days 10 hrs ago0x48f528ce86bec210bc5d1a5e0cd6d60eea801a8d IN  Lemma Finance: Lemma Router0 ETH0.001180744516 ETH
0x57c6e4b85bf7f0eb5a1cdbfd790ec33520658d8fa8176a8f51eb6cc802f8c1a7Mint For Eth And...35313552021-12-03 10:20:33421 days 7 hrs ago0xe0f61822b45bb03cdc581283287941517810d7ba IN  Lemma Finance: Lemma Router0.001 ETH0.001445813724 ETH
0x854f79790cff5a1416ce8fa7057fcdbccb4bf4e38728efefb18afcfdb23fa42cStake USDL35272422021-12-03 5:13:56421 days 12 hrs ago0x237ec64cc27196f6a4c16abdbb558b4c518400c2 IN  Lemma Finance: Lemma Router0 ETH0.001177744502 ETH
0x8b48812a085971702e0f51035eb986e0a2b937543c82854bf7d4b52748acd872Stake USDL35268422021-12-03 4:42:41421 days 12 hrs ago0xa1c7bd2e48f7f3922e201705f3491c841135f483 IN  Lemma Finance: Lemma Router0 ETH0.000745099979 ETH
0xbe6a8ca5c5673b47155c6d7fc349b884be2aa90607a61e88632eeaea783762e5Mint USDLETH35205092021-12-02 20:45:03421 days 20 hrs ago0xa1c7bd2e48f7f3922e201705f3491c841135f483 IN  Lemma Finance: Lemma Router0.7 ETH0.001351267659 ETH
0x52fcba0fd3cd6916c1c7c85f5a7ced374325baa9af222b20564611bb7dbc7e1dMint USDLETH35202612021-12-02 20:30:35421 days 20 hrs ago0x237ec64cc27196f6a4c16abdbb558b4c518400c2 IN  Lemma Finance: Lemma Router0.6 ETH0.001360762617 ETH
0xd29569542a4dde60fe3c1acef307f9b7eb45743ad2af4c997f3cfb5f46b9cbc4Unstake And Rede...35201822021-12-02 20:25:21421 days 21 hrs ago0xa1c7bd2e48f7f3922e201705f3491c841135f483 IN  Lemma Finance: Lemma Router0 ETH0.001214870062 ETH
0x979ae2e3ec5525ffefae081ace7cc7e63fd8f3269ff5cfaaea75f985d82a1553Mint Using Token...35120332021-12-02 12:20:57422 days 5 hrs ago0xa95d252193c0c433dbba11e9aa1cfc5481f4ac36 IN  Lemma Finance: Lemma Router0 ETH0.002119566884 ETH
0x349526df5acbbdcaa25e18148f5576121968d6d4ff894c0b90c2b9b2695a28e9Mint Using Token...35120112021-12-02 12:18:39422 days 5 hrs ago0xa95d252193c0c433dbba11e9aa1cfc5481f4ac36 IN  Lemma Finance: Lemma Router0 ETH0.002125575071 ETH
0x1a63cdee99f1354c9d70a721fabd5ed0a727fb12676507669d1044869391c775Mint Using Token...35119582021-12-02 12:13:22422 days 5 hrs ago0x716ec36be0dd20a5c22455cb37d4ca86ae134ebe IN  Lemma Finance: Lemma Router0 ETH0.002562160516 ETH
0x24178169c65bfd0102bc44e5b2ab5803c9becad0652aa7ed0785a015e250a4b9Mint Using Token...35119442021-12-02 12:12:19422 days 5 hrs ago0x716ec36be0dd20a5c22455cb37d4ca86ae134ebe IN  Lemma Finance: Lemma Router0 ETH0.001699909542 ETH
0x048e22da012c991c7e3ffba62f23b1feab154686e71e5eace7ab892b662ed908Mint For Eth And...35119432021-12-02 12:12:19422 days 5 hrs ago0xf05dee6573878712b35136078385977726148a60 IN  Lemma Finance: Lemma Router7 ETH0.001150781117 ETH
0x6397c1b6bccc142ad254e3b636b25a1e10718e1edbedd28e05f99aa98a5046e5Mint For Eth And...35119342021-12-02 12:11:07422 days 5 hrs ago0xf05dee6573878712b35136078385977726148a60 IN  Lemma Finance: Lemma Router10 ETH0.001585009237 ETH
0x07dc8d216034b225217009ed76d5878d63a64a44a0fd26c9b4d7d1c38f6623b8Mint For Eth And...35118962021-12-02 12:09:43422 days 5 hrs ago0x6e4e3b52986e46b4d656c49b8c18c742e311e354 IN  Lemma Finance: Lemma Router0.4 ETH0.001151091435 ETH
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x2c768bc7a21b994764c127f5d18252553c63d35afdc128fd9667652f700831b541163552021-12-27 17:03:38397 days 22 mins ago Lemma Finance: Lemma Router 0x566ea349158b610d1800cb9ec3072931140cbf030 ETH
0x2c768bc7a21b994764c127f5d18252553c63d35afdc128fd9667652f700831b541163552021-12-27 17:03:38397 days 22 mins ago Lemma Finance: Lemma Router 0x566ea349158b610d1800cb9ec3072931140cbf030 ETH
0x2c768bc7a21b994764c127f5d18252553c63d35afdc128fd9667652f700831b541163552021-12-27 17:03:38397 days 22 mins ago Lemma Finance: Lemma Router Lemma Finance: xUSDL0 ETH
0x2c768bc7a21b994764c127f5d18252553c63d35afdc128fd9667652f700831b541163552021-12-27 17:03:38397 days 22 mins ago Lemma Finance: Lemma Router Lemma Finance: xUSDL0 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x8b194beae1d3e0788a1a35173978001acdfba6680 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x8b194beae1d3e0788a1a35173978001acdfba6680 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x4426e7b8bc6fed829c9a310f896a8afbef044ac10 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x8b194beae1d3e0788a1a35173978001acdfba6680 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x88a1f17ed33bf295e277330760b5514e6a90985b0 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x4426e7b8bc6fed829c9a310f896a8afbef044ac10 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x1efb3f88bc88f03fd1804a5c53b7141bbef5ded80 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x1efb3f88bc88f03fd1804a5c53b7141bbef5ded80 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x1efb3f88bc88f03fd1804a5c53b7141bbef5ded80 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x1efb3f88bc88f03fd1804a5c53b7141bbef5ded80 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router SushiSwap: Router0 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x82af49447d8a07e3bd95bd0d56f35241523fbab10 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router SushiSwap: Router0 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x82af49447d8a07e3bd95bd0d56f35241523fbab10 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router Lemma Finance: USD Lemma0 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x82af49447d8a07e3bd95bd0d56f35241523fbab10 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0x3092ed676e1c59ee5ab6eb4bf19a11bca84d67bd0 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router Lemma Finance: USD Lemma0 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router SushiSwap: Router0 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0xb252ebbce1aead091c767463a242feb9e470d8d920a67f89c85449e67666258437920712021-12-12 18:11:22411 days 23 hrs ago Lemma Finance: Lemma Router 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
[ Download CSV Export 
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
LemmaRouter

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 10 : LemmaRouter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;
pragma abicoder v2;

import {Multicall} from '@uniswap/v3-periphery/contracts/base/Multicall.sol';
import {IWETH9} from '@uniswap/v3-periphery/contracts/interfaces/external/IWETH9.sol';
import {IUSDLemma} from './interfaces/IUSDLemma.sol';
import {IXUSDL} from './interfaces/IXUSDL.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {TransferHelper} from '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import {IPerpetualWrapper} from './interfaces/IPerpetualWrapper.sol';
import {IUniswapV2Router} from './interfaces/IUniswapV2Router.sol';

/**
    @title Periphery Contract to help with Lemma Contracts
    @author Lemma Finance
*/
contract LemmaRouter is Multicall {
    // ERC20 WETH token address
    IWETH9 public weth;
    // ERC20 USDL token address
    IUSDLemma public usdl;
    // ERC20 xUSDL token address
    IXUSDL public xusdl;
    address public routerSushiswap;

    /**
     * @dev Deploy Lemma Periphery Contract.
            Periphery Contract to help with Lemma Contracts
     * @param _weth WETH ERC20 contract address
     * @param _xusdl XUSDL ERC20 contract address
     * @param _routerSushiswap Sushiswap exchange router contract address
    */
    constructor(
        address _weth,
        address _xusdl,
        address _routerSushiswap
    ) {
        weth = IWETH9(_weth);
        xusdl = IXUSDL(_xusdl);
        usdl = IUSDLemma(address(xusdl.usdl()));
        routerSushiswap = _routerSushiswap;
        TransferHelper.safeApprove(_weth, address(usdl), type(uint256).max);
        TransferHelper.safeApprove(address(usdl), _xusdl, type(uint256).max);
    }

    // To receive ethereum from othre address to this periphery contract
    receive() external payable {}

    /**
     * @dev mint USDL token by depositing collateral and transfer USDL to toAddress
            collateral->USDL 
     * @notice before calling this function,
               user should have to approve this contract for collateral token
     * @param to address where minted usdl will transfer
     * @param amount user want to mint this number of USDL 
     * @param maxCollateralRequired Required collateral should be than than or equal to maxCollateralRequired
     * @param dexIndex Index of perpetual dex, where position will be opened
     * @param collateral collateral token address
    */
    function mintUSDLTo(
        address to,
        uint256 amount,
        uint256 maxCollateralRequired,
        uint256 dexIndex,
        IERC20 collateral
    ) public {
        uint256 collateralAmountRequired = IPerpetualWrapper(
            usdl.perpetualDEXWrappers(dexIndex, address(collateral))
        ).getCollateralAmountGivenUnderlyingAssetAmount(amount, true);
        TransferHelper.safeTransferFrom(
            address(collateral),
            msg.sender,
            address(this),
            collateralAmountRequired
        );

        usdl.depositTo(to, amount, dexIndex, maxCollateralRequired, collateral);
    }

    /**
     * @dev mint USDL token by depositing weth and transfer USDL to msg.sender
            collateral->USDL 
     * @notice before calling this function,
               user should have to approve this contract for collateral token
     * @param amount user want to mint this number of USDL 
     * @param maxCollateralRequired Required collateral should be less than than or equal to maxCollateralRequired
     * @param dexIndex Index of perpetual dex, where position will be opened
     * @param collateral collateral token address
    */
    function mintUSDL(
        uint256 amount,
        uint256 maxCollateralRequired,
        uint256 dexIndex,
        IERC20 collateral
    ) external {
        mintUSDLTo(
            msg.sender,
            amount,
            maxCollateralRequired,
            dexIndex,
            collateral
        );
    }

    /**
     * @dev mint USDL token by depositing weth, and transfer USDL to toAddress
            But before deposit weth, It first convert eth to weth by weth contract address
            ETH->WETH->USDL
     * @param to address where minted usdl will transfer
     * @param amount user want to mint this number of USDL 
     * @param dexIndex Index of perpetual dex, where position will be opened
    */
    function mintUSDLToETH(
        address to,
        uint256 amount,
        uint256 dexIndex
    ) public payable {
        weth.deposit{value: msg.value}();
        usdl.depositTo(to, amount, dexIndex, msg.value, weth);
        weth.withdraw(weth.balanceOf(address(this)));
        TransferHelper.safeTransferETH(msg.sender, address(this).balance);
    }

    /**
     * @dev mint USDL token by depositing weth, and transfer USDL to msg.sender
            But before deposit weth, It first convert eth to weth by weth contract address
            ETH->WETH->USDL
     * @param amount user want to mint this number of USDL 
     * @param dexIndex Index of perpetual dex, where position will be opened
    */
    function mintUSDLETH(uint256 amount, uint256 dexIndex) external payable {
        mintUSDLToETH(msg.sender, amount, dexIndex);
    }

    /**
     * @dev redeemUSDLTo method will burn USDL and will transfer collateral back to toAddress
            USDL->collateral
     * @notice before calling this function,
               user should have to approve this contract for usdl token     
     * @param to toAddress where collateral will transfer
     * @param amount amount of USDL want to redeem for collateral
     * @param minCollateralToGetBack collateralAmountToGetBack should be greater than equal to minCollateralToGetBack 
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param collateral collateral token address
    */
    function redeemUSDLTo(
        address to,
        uint256 amount,
        uint256 minCollateralToGetBack,
        uint256 dexIndex,
        IERC20 collateral
    ) public {
        //transfer usdl from user to this address
        TransferHelper.safeTransferFrom(
            address(usdl),
            msg.sender,
            address(this),
            amount
        );
        _redeemUSDL(to, amount, dexIndex, minCollateralToGetBack, collateral);
    }

    /**
     * @dev redeemUSDL method will burn USDL and will transfer collateral back to msg.sender
            USDL->collateral
     * @notice before calling this function,
               user should have to approve this contract for usdl token     
     * @param amount amount of USDL want to redeem for collateral
     * @param minCollateralToGetBack collateralAmountToGetBack should be greater than equal to minCollateralToGetBack 
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param collateral collateral token address
    */
    function redeemUSDL(
        uint256 amount,
        uint256 minCollateralToGetBack,
        uint256 dexIndex,
        IERC20 collateral
    ) external {
        redeemUSDLTo(
            msg.sender,
            amount,
            minCollateralToGetBack,
            dexIndex,
            collateral
        );
    }

    /**
     * @dev redeemUSDLToETH method will burn USDL and will transfer collateral back to toAddress
            But before withdraw eth, It first convert weth to eth by weth contract address
            USDL->WETH->ETH
            and then send collateral(eth) back to toAddress
     * @notice before calling this function,
               user should have to approve this contract for usdl token     
     * @param to toAddress where collateral will transfer
     * @param amount amount of USDL want to redeem for collateral
     * @param minCollateralToGetBack collateralAmountToGetBack should be greater than equal to minCollateralToGetBack 
     * @param dexIndex Index of perpetual dex, where position will be closed
    */
    function redeemUSDLToETH(
        address to,
        uint256 amount,
        uint256 minCollateralToGetBack,
        uint256 dexIndex
    ) public {
        TransferHelper.safeTransferFrom(
            address(usdl),
            msg.sender,
            address(this),
            amount
        );
        _redeemUSDL(
            address(this),
            amount,
            dexIndex,
            minCollateralToGetBack,
            weth
        );
        weth.withdraw(weth.balanceOf(address(this)));
        TransferHelper.safeTransferETH(to, address(this).balance);
    }

    /**
     * @dev redeemUSDLTo method will burn USDL and will transfer collateral back to msg.sender
            But before withdraw eth, It first convert weth to eeth by weth contract address
            and then send collateral(eth) back to msg.sender
            USDL->WETH->ETH
     * @notice before calling this function,
               user should have to approve this contract for usdl token     
     * @param amount amount of USDL want to redeem for collateral
     * @param minCollateralToGetBack collateralAmountToGetBack should be greater than equal to minCollateralToGetBack 
     * @param dexIndex Index of perpetual dex, where position will be closed
    */
    function redeemUSDLETH(
        uint256 amount,
        uint256 minCollateralToGetBack,
        uint256 dexIndex
    ) external {
        redeemUSDLToETH(msg.sender, amount, minCollateralToGetBack, dexIndex);
    }

    /**
     * @dev _redeemUSDL method will burn USDL and will transfer collateral back to toAddress
     * @notice This is the internal method. It will not call by any user
     * @param to toAddress where collateral will transfer
     * @param amount amount of USDL want to redeem for collateral
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param minCollateralToGetBack collateralAmountToGetBack should be greater than equal to minCollateralToGetBack
     * @param collateral collateral token address
     */
    function _redeemUSDL(
        address to,
        uint256 amount,
        uint256 dexIndex,
        uint256 minCollateralToGetBack,
        IERC20 collateral
    ) internal {
        usdl.withdrawTo(
            to,
            amount,
            dexIndex,
            minCollateralToGetBack,
            collateral
        );
    }

    /**
     * @dev swapCollateralForToken method use to swap collateral(eth) for token
     * @notice It is using sushiswap as a router to swap collateral to token.
               It is the internal method.
     * @param collateral collateral is from address to swap
     * @param token specified token is to address for swap
     * @param amountIn collateral amount input
    */
    function swapCollateralForToken(
        address collateral,
        address token,
        uint256 amountIn
    ) internal {
        require(amountIn > 0, 'Nothing to transfer');

        address[] memory path = new address[](2);
        path[0] = collateral;
        path[1] = token;

        uint256 amountOutMin = IUniswapV2Router(routerSushiswap).getAmountsOut(
            amountIn,
            path
        )[1];
        require(amountOutMin > 0, 'No token available');

        // Approve transfer to Sushiswap Router
        require(
            IERC20(collateral).approve(routerSushiswap, amountIn),
            'Approve failed'
        );

        IUniswapV2Router(routerSushiswap).swapExactTokensForTokens(
            amountIn,
            amountOutMin,
            path,
            msg.sender,
            block.timestamp
        );
    }

    /**
     * @dev mintUSDLToUsingToken is used to mint USDL for toAddress
            In this method user can use other tokens to mint usdl
            so tokens will transfer to collateral internally then it will mint usdl
            token->collateral->USDL
     * @notice before calling this function,
               user should have to approve this contract for specified token address   
     * @param token specified token address as collateral and will swap internally token to weth
     * @param tokenAmount is the amount of collateral
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param to transfer minted USDL to toAddress
     * @param amount amount of USDL want to mint
     * @param maxCollateralRequired Required collateral should be less than or equal to max maxCollateralRequired
     * @param dexIndex Index of perpetual dex, where position will be opened
     * @param collateral collateral token address
    */
    function mintUSDLToUsingToken(
        IERC20 token,
        uint256 tokenAmount,
        address[] memory swapActions,
        bytes[] memory swapDatas,
        address to,
        uint256 amount,
        uint256 maxCollateralRequired,
        uint256 dexIndex,
        IERC20 collateral
    ) public {
        TransferHelper.safeTransferFrom(
            address(token),
            msg.sender,
            address(this),
            tokenAmount
        );
        _swap(swapActions, swapDatas, amount, dexIndex, collateral);
        //swap token for collateral
        //mint USDL using the collateral
        usdl.depositTo(to, amount, dexIndex, maxCollateralRequired, collateral);
        //transfer the extra collateral back to user
        swapCollateralForToken(
            address(collateral),
            address(token),
            collateral.balanceOf(address(this))
        );
    }

    /**
     * @dev mintUSDLUsingToken isused to mint USDL for msg.sender
            In this method user can use other tokens to mint usdl
            so tokens will transfer to collateral internally then it will mint usdl
            token->collateral->USDL
     * @notice before calling this function,
               user should have to approve this contract for specified token address   
     * @param token specified token address as collateral and will swap internally token to weth
     * @param tokenAmount is the amount of collateral
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param amount amount of USDL want to mint
     * @param maxCollateralRequired Required collateral should be less than or equal to max maxCollateralRequired
     * @param dexIndex Index of perpetual dex, where position will be opened
     * @param collateral collateral token address
    */
    function mintUSDLUsingToken(
        IERC20 token,
        uint256 tokenAmount,
        address[] memory swapActions,
        bytes[] memory swapDatas,
        uint256 amount,
        uint256 maxCollateralRequired,
        uint256 dexIndex,
        IERC20 collateral
    ) external {
        TransferHelper.safeTransferFrom(
            address(token),
            msg.sender,
            address(this),
            tokenAmount
        );
        _swap(swapActions, swapDatas, amount, dexIndex, collateral);
        //swap token for collateral
        //mint USDL using the collateral
        usdl.depositTo(
            msg.sender,
            amount,
            dexIndex,
            maxCollateralRequired,
            collateral
        );
        //transfer the extra collateral back to user

        swapCollateralForToken(
            address(collateral),
            address(token),
            collateral.balanceOf(address(this))
        );
    }

    /**
     * @dev _swap method is used to swap token for collateral(token -> weth)
     * @notice it is using 1inch protocol to swap
               It is internal method 
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param amount amount of USDL want to mint
     * @param dexIndex Index of perpetual dex, where position will be opened or closed
     * @param collateral collateral token address
    */
    function _swap(
        address[] memory swapActions,
        bytes[] memory swapDatas,
        uint256 amount,
        uint256 dexIndex,
        IERC20 collateral
    ) internal {
        for (uint256 i; i < swapActions.length; i++) {
            require(
                swapActions[i] != address(xusdl),
                'cannot call xUSDL contract'
            );
            (bool success, ) = swapActions[i].call(swapDatas[i]);
            require(success, 'swap failed');
        }
        uint256 collateralAmountRequired = IPerpetualWrapper(
            usdl.perpetualDEXWrappers(dexIndex, address(collateral))
        ).getCollateralAmountGivenUnderlyingAssetAmount(amount, true);

        require(
            collateral.balanceOf(address(this)) >= collateralAmountRequired,
            'swapped amount is less than required'
        );
    }

    /**
     * @dev redeemUSDLToUsingToken is used to redeem USDL from 
            and get back its specied token as a collateral to toAddress
            USDL->collateral->token
     * @notice before calling this function,
               user should have to approve this contract for usdl token
     * @param token specified token address get back after collateral withdraw so will swap internally weth to token
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param to transfer specified tokens to toAddress
     * @param amount amount of USDL want to burn
     * @param minTokenAmount after swap weth to token. tokenAmount should be greater than or equal to minTokenAmount
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param collateral collateral token address
    */
    function redeemUSDLToUsingToken(
        IERC20 token,
        address[] memory swapActions,
        bytes[] memory swapDatas,
        address to,
        uint256 amount,
        uint256 minTokenAmount,
        uint256 dexIndex,
        IERC20 collateral
    ) external {
        TransferHelper.safeTransferFrom(
            address(usdl),
            msg.sender,
            address(this),
            amount
        );

        usdl.withdrawTo(address(this), amount, dexIndex, 0, collateral);

        _swapToToken(token, swapActions, swapDatas, minTokenAmount);

        TransferHelper.safeTransfer(
            address(token),
            to,
            token.balanceOf(address(this))
        );

        swapCollateralForToken(
            address(collateral),
            address(token),
            collateral.balanceOf(address(this))
        );
    }

    /**
     * @dev redeemUSDLUsingToken is used to redeem USDL from 
            and get back its specied token as a collateral to msg.sender
            USDL->collateral->token
     * @notice before calling this function,
               user should have to approve this contract for usdl token
     * @param token specified token address get back after collateral withdraw so will swap internally weth to token
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param amount amount of USDL want to burn
     * @param minTokenAmount after swap weth to token. tokenAmount should be greater than or equal to minTokenAmount
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param collateral collateral token address
    */
    function redeemUSDLUsingToken(
        IERC20 token,
        address[] memory swapActions,
        bytes[] memory swapDatas,
        uint256 amount,
        uint256 minTokenAmount,
        uint256 dexIndex,
        IERC20 collateral
    ) external {
        TransferHelper.safeTransferFrom(
            address(usdl),
            msg.sender,
            address(this),
            amount
        );

        usdl.withdrawTo(address(this), amount, dexIndex, 0, collateral);

        _swapToToken(token, swapActions, swapDatas, minTokenAmount);

        TransferHelper.safeTransfer(
            address(token),
            msg.sender,
            token.balanceOf(address(this))
        );

        swapCollateralForToken(
            address(collateral),
            address(token),
            collateral.balanceOf(address(this))
        );
    }

    /**
     * @dev _swapToToken is usedd to swap collateral(weth) to specified token
     * @notice It is using 1inch protocol to swap
               _swap to token is usedd when user will redeem USDL 
               and user wants its token as collateral instead weth 
     * @param token specified token address get back after swap weth to token
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param minTokenAmount after swap weth to token. tokenAmount should be greater than or equal to minTokenAmount
    */
    function _swapToToken(
        IERC20 token,
        address[] memory swapActions,
        bytes[] memory swapDatas,
        uint256 minTokenAmount
    ) internal {
        for (uint256 i; i < swapActions.length; i++) {
            require(
                swapActions[i] != address(xusdl),
                'cannot call xUSDL contract'
            );
            (bool success, ) = swapActions[i].call(swapDatas[i]);
            require(success, 'swap failed');
        }

        require(
            token.balanceOf(address(this)) >= minTokenAmount,
            'swapped amount is less than token amount required'
        );
    }

    /**
     * @dev stakeUSDL is used to stake USDL in xUSDL contract 
            and msg.sender will get xUSDL as share token
            USDL->xUSDL
     * @notice before calling this function,
               user should have to approve this contract for usdl token
     * @param amount amount od USDL token to stake
    */
    function stakeUSDL(uint256 amount) external {
        TransferHelper.safeTransferFrom(
            address(usdl),
            msg.sender,
            address(this),
            amount
        );
        _stakeUSDLTo(amount, msg.sender);
    }

    /**
     * @dev _stakeUSDLTo is used to stake USDL in xUSDL contract 
            and user address will get xUSDL as share token
            USDL->xUSDL
     * @notice by staking you will get extra USDL as a yield
               _stakeUSDLTo is the internal method
     * @param amount amount od USDL token to stake
     * @param user minted xUSDL tokens to user address
    */
    function _stakeUSDLTo(uint256 amount, address user) internal {
        xusdl.deposit(amount);
        TransferHelper.safeTransfer(
            address(xusdl),
            user,
            xusdl.balanceOf(address(this))
        );
    }

    /**
     * @dev unstakeUSDL is used to withdraw USDL by giving back xUSDL token to xUSDL contract
            and msg.sender address will get USDL token get back
            xUSDL->USDL
     * @notice before calling this function,
               msg.sender should have to approve this contract for xUSDL token
     * @param amount amount of xUSDL tokens to burn for withdraw USDL
    */
    function unstakeUSDL(uint256 amount) external {
        unstakeUSDLTo(msg.sender, amount);
    }

    /**
     * @dev unstakeUSDLTo is used to withdraw USDL by giving back xUSDL token to xUSDL contract
            and toAddress will get USDL token get back
            xUSDL->USDL
     * @notice before calling this function,
               msg.sender should have to approve this contract for xUSDL token
     * @param to transfer usdl to toAddress
     * @param amount amount of xUSDL tokens to burn for withdraw USDL
    */
    function unstakeUSDLTo(address to, uint256 amount) public {
        TransferHelper.safeTransferFrom(
            address(xusdl),
            msg.sender,
            address(this),
            amount
        );
        xusdl.withdrawTo(to, amount);
    }

    /**
     * @dev mint USDL token by depositing weth, and transfer USDL to address(this)
            But before deposit weth, It first convert eth to weth by weth contract address
            and once contract mint USDL it will stake USDL in xUSDL contract 
            and msg.sender address will get xUSDL as share token
            ETH->WETH->USDL->xUSDL
     * @notice msg.sender should have the eth in his wallet
     * @param amount the amount of collateral tokens
     * @param dexIndex Index of perpetual dex, where position will be opened
    */
    function mintForEthAndStake(uint256 amount, uint256 dexIndex)
        external
        payable
    {
        mintUSDLToETH(address(this), amount, dexIndex);
        _stakeUSDLTo(amount, msg.sender);
    }

    /**
     * @dev mint USDL token by depositing collateral(weth) and transfer USDL to this contract address
            and once contract mint USDL it will stake USDL in xUSDL contract 
            and msg.sender address will get xUSDL as share token
            collateral->USDL->xUSDL
     * @notice before calling this function,
               user should have to approve this contract for collateral token
     * @param amount the amount of collateral tokens
     * @param dexIndex Index of perpetual dex, where position will be opened
     * @param maxCollateralRequired Required collateral should be less than or equal to max maxCollateralRequired
     * @param collateral collateral token address
    */
    function mintAndStake(
        uint256 amount,
        uint256 dexIndex,
        uint256 maxCollateralRequired,
        IERC20 collateral
    ) external {
        mintUSDLTo(
            address(this),
            amount,
            maxCollateralRequired,
            dexIndex,
            collateral
        );
        _stakeUSDLTo(amount, msg.sender);
    }

    /**
     * @dev mintUsingTokenAndStake is mint USDL for address(this).
            In this method user can use other tokens to mint usdl,
            so tokens will transfer to collateral internally then it will mint usdl.
            and once contract mint USDL it will stake USDL in xUSDL contract 
            and msg.sender address will get xUSDL as share token
            token->collateral->USDL->xUSDL
     * @notice before calling this function,
               user should have to approve this contract for specified token address  
     * @param token specified token address as collateral and will swap internally token to weth
     * @param tokenAmount is the amount of collateral 
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param amount amount of USDL want to mint
     * @param maxCollateralRequired Required collateral should be less than or equal to max maxCollateralRequired
     * @param dexIndex Index of perpetual dex, where position will be opened
     * @param collateral collateral token address
    */
    function mintUsingTokenAndStake(
        IERC20 token,
        uint256 tokenAmount,
        address[] memory swapActions,
        bytes[] memory swapDatas,
        uint256 amount,
        uint256 maxCollateralRequired,
        uint256 dexIndex,
        IERC20 collateral
    ) external {
        mintUSDLToUsingToken(
            token,
            tokenAmount,
            swapActions,
            swapDatas,
            address(this),
            amount,
            maxCollateralRequired,
            dexIndex,
            collateral
        );
        _stakeUSDLTo(amount, msg.sender);
    }

    /**
     * @dev unstakeAndRedeemUSDLForEth is used to withdraw USDL by giving back xUSDL token to xUSDL contract
            and address(this) will get USDL token get back
            and once USDL token withdraw, then calling `usdl.withdrawTo` to withdraw weth collateral back
            and swap weth to eth by weth contract and transfer to msg.sender
            xUSDL->USDL->WETH->ETH
     * @notice before calling this function,
               msg.sender should have to approve this contract for xusdl address
     * @param amount the amount of xUSDL tokend to burn and withdraw USDL tokens
     * @param dexIndex Index of perpetual dex, where position will be closed
    */
    function unstakeAndRedeemUSDLForEth(
        uint256 amount,
        uint256 dexIndex,
        uint256 minETHToGetBack
    ) external {
        unstakeAndRedeemUSDLForEthTo(
            msg.sender,
            amount,
            dexIndex,
            minETHToGetBack
        );
    }

    /**
     * @dev unstakeAndRedeemUSDLForEthTo is used to withdraw USDL by giving back xUSDL token to xUSDL contract
            and address(this) will get USDL token get back
            and once USDL token withdraw, then calling `usdl.withdrawTo` to withdraw weth collateral back
            and swap weth to eth by weth contract and transfer toAddress
            xUSDL->USDL->WETH->ETH
     * @notice before calling this function,
               msg.sender should have to approve this contract for xusdl address
     * @param to transfer collateral(eth) to toAddress
     * @param amount the amount of xUSDL tokend to burn and withdraw USDL tokens
     * @param dexIndex Index of perpetual dex, where position will be closed
    */
    function unstakeAndRedeemUSDLForEthTo(
        address to,
        uint256 amount,
        uint256 dexIndex,
        uint256 minETHToGetBack
    ) public {
        TransferHelper.safeTransferFrom(
            address(xusdl),
            msg.sender,
            address(this),
            amount
        );
        xusdl.withdraw(amount);
        usdl.withdrawTo(
            address(this),
            usdl.balanceOf(address(this)),
            dexIndex,
            minETHToGetBack,
            weth
        );
        weth.withdraw(weth.balanceOf(address(this)));
        TransferHelper.safeTransferETH(to, address(this).balance);
    }

    /**
     * @dev unstakeAndRedeemUSDL is used to withdraw USDL by giving back xUSDL token to xUSDL contract
            and address(this) will get USDL token get back 
            and once USDL token withdraw, _redeemUSDL method will burn USDL and will transfer collateral back to msg.sender
            xUSDL->USDL->collateral
     * @notice before calling this function,
               msg.sender should have to approve this contract for xusdl address
     * @param amount the amount of xUSDL tokens to burn and withdraw USDL tokens
     * @param minCollateralToGetBack collateralAmountToGetBack should be greater than equal to minCollateralToGetBack 
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param collateral collateral token address
    */
    function unstakeAndRedeemUSDL(
        uint256 amount,
        uint256 minCollateralToGetBack,
        uint256 dexIndex,
        IERC20 collateral
    ) external {
        unstakeAndRedeemUSDLTo(
            msg.sender,
            amount,
            minCollateralToGetBack,
            dexIndex,
            collateral
        );
    }

    /**
     * @dev unstakeAndRedeemUSDL is used to withdraw USDL by giving back xUSDL token to xUSDL contract
            and address(this) will get USDL token get back 
            and once USDL token withdraw, _redeemUSDL method will burn USDL and will transfer collateral back toAddress
            xUSDL->USDL->collateral
     * @notice before calling this function,
               msg.sender should have to approve this contract for xusdl address
     * @param to transfer collateral to toAddress
     * @param amount the amount of xUSDL tokens to burn and withdraw USDL tokens
     * @param minCollateralToGetBack collateralAmountToGetBack should be greater than equal to minCollateralToGetBack 
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param collateral collateral token address
    */
    function unstakeAndRedeemUSDLTo(
        address to,
        uint256 amount,
        uint256 minCollateralToGetBack,
        uint256 dexIndex,
        IERC20 collateral
    ) public {
        TransferHelper.safeTransferFrom(
            address(xusdl),
            msg.sender,
            address(this),
            amount
        );
        xusdl.withdraw(amount);
        _redeemUSDL(
            to,
            usdl.balanceOf(address(this)),
            dexIndex,
            minCollateralToGetBack,
            collateral
        );
    }

    /**
     * @dev unstakeAndRedeemToken is used to withdraw USDL by giving back xUSDL token to xUSDL contract
            and address(this) will get USDL token get back 
            and once USDL token withdraw, then calling `usdl.withdrawTo` to withdraw weth collateral back
            and swap weth to specified token by _swapToToken and tranfer specified token to msg.sender
            xUSDL->USDL->collateral->token
     * @notice before calling this function,
               msg.sender should have to approve this contract for xusdl address
     * @param token specified token address get back after collateral withdraw so will swap internally weth to token
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param amount amount of xUSDL want to burn
     * @param minTokenAmount after swap weth to token. tokenAmount should be greater than or equal to minTokenAmount
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param collateral collateral token address
    */
    function unstakeAndRedeemToken(
        IERC20 token,
        address[] memory swapActions,
        bytes[] memory swapDatas,
        uint256 amount,
        uint256 minTokenAmount,
        uint256 dexIndex,
        IERC20 collateral
    ) external {
        unstakeAndRedeemToToken(
            token,
            swapActions,
            swapDatas,
            msg.sender,
            amount,
            minTokenAmount,
            dexIndex,
            collateral
        );
    }

    /**
     * @dev unstakeAndRedeemToToken is used to withdraw USDL by giving back xUSDL token to xUSDL contract
            and address(this) will get USDL token get back 
            and once USDL token withdraw, then calling `usdl.withdrawTo` to withdraw weth collateral back
            and swap weth to specified token by _swapToToken and tranfer specified token to toAddress
            xUSDL->USDL->collateral->token
     * @notice before calling this function,
               msg.sender should have to approve this contract for xusdl address
     * @param token specified token address get back after collateral withdraw so will swap internally weth to token
     * @param swapActions it is the contract address of dex aggregator of 1inch
     * @param swapDatas it is the function signature which needs to call
     * @param to transfer specified tokens to toAddress
     * @param amount amount of xUSDL want to burn
     * @param minTokenAmount after swap weth to token. tokenAmount should be greater than or equal to minTokenAmount
     * @param dexIndex Index of perpetual dex, where position will be closed
     * @param collateral collateral token address
    */
    function unstakeAndRedeemToToken(
        IERC20 token,
        address[] memory swapActions,
        bytes[] memory swapDatas,
        address to,
        uint256 amount,
        uint256 minTokenAmount,
        uint256 dexIndex,
        IERC20 collateral
    ) public {
        TransferHelper.safeTransferFrom(
            address(xusdl),
            msg.sender,
            address(this),
            amount
        );

        xusdl.withdraw(amount);

        usdl.withdrawTo(
            address(this),
            usdl.balanceOf(address(this)),
            dexIndex,
            0,
            collateral
        );

        _swapToToken(token, swapActions, swapDatas, minTokenAmount);

        TransferHelper.safeTransfer(
            address(token),
            to,
            token.balanceOf(address(this))
        );

        swapCollateralForToken(
            address(collateral),
            address(token),
            collateral.balanceOf(address(this))
        );
    }
}

File 2 of 10 : Multicall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../interfaces/IMulticall.sol';

/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall is IMulticall {
    /// @inheritdoc IMulticall
    function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(data[i]);

            if (!success) {
                // Next 5 lines from https://ethereum.stackexchange.com/a/83577
                if (result.length < 68) revert();
                assembly {
                    result := add(result, 0x04)
                }
                revert(abi.decode(result, (string)));
            }

            results[i] = result;
        }
    }
}

File 3 of 10 : IWETH9.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

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

/// @title Interface for WETH9
interface IWETH9 is IERC20 {
    /// @notice Deposit ether to get wrapped ether
    function deposit() external payable;

    /// @notice Withdraw wrapped ether to get ether
    function withdraw(uint256) external;
}

File 4 of 10 : IUSDLemma.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

interface IUSDLemma is IERC20 {
    function depositTo(
        address to,
        uint256 amount,
        uint256 perpetualDEXIndex,
        uint256 maxCollateralRequired,
        IERC20 collateral
    ) external;

    function withdrawTo(
        address to,
        uint256 amount,
        uint256 perpetualDEXIndex,
        uint256 minCollateralToGetBack,
        IERC20 collateral
    ) external;

    function perpetualDEXWrappers(uint256 perpetualDEXIndex, address collateral)
        external
        view
        returns (address);
}

File 5 of 10 : IXUSDL.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

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

interface IXUSDL is IERC20 {
    
    function usdl() external view returns (IERC20); 

    /// @notice Balance of USDL in xUSDL contract
    /// @return Amount of USDL
    function balance() external view returns (uint256);

    /// @notice Minimum blocks user funds need to be locked in contract
    /// @return Minimum blocks for which USDL will be locked
    function MINIMUM_LOCK() external view returns (uint256);

    /// @notice Deposit and mint xUSDL in exchange of USDL
    /// @param amount of USDL to deposit
    /// @return Amount of xUSDL minted
    function deposit(uint256 amount) external returns (uint256);

    /// @notice Withdraw USDL and burn xUSDL
    /// @param shares of xUSDL to burn
    /// @return Amount of USDL withdrawn
    function withdraw(uint256 shares) external returns (uint256);

    /// @notice Withdraw USDL and burn xUSDL
    /// @param user address to withdraw usdl to
    /// @param shares of xUSDL to burn
    /// @return Amount of USDL withdrawn
    function withdrawTo(address user, uint256 shares) external returns (uint256);

    /// @notice Price per share in terms of USDL
    /// @return Price of 1 xUSDL in terms of USDL
    function pricePerShare() external view returns (uint256);

    /// @notice Block number after which user can withdraw USDL
    /// @return Block number after which user can withdraw USDL 
    function userUnlockBlock(address usr) external view returns (uint256);

    function updatePeriphery(address _periphery) external;

}

File 6 of 10 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

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

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

File 7 of 10 : TransferHelper.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

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

library TransferHelper {
    /// @notice Transfers tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) =
            token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }

    /// @notice Transfers tokens from msg.sender to a recipient
    /// @dev Errors with ST if transfer fails
    /// @param token The contract address of the token which will be transferred
    /// @param to The recipient of the transfer
    /// @param value The value of the transfer
    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
    }

    /// @notice Approves the stipulated contract to spend the given allowance in the given token
    /// @dev Errors with 'SA' if transfer fails
    /// @param token The contract address of the token to be approved
    /// @param to The target of the approval
    /// @param value The amount of the given token the target will be allowed to spend
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
    }

    /// @notice Transfers ETH to the recipient address
    /// @dev Fails with `STE`
    /// @param to The destination of the transfer
    /// @param value The value to be transferred
    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'STE');
    }
}

File 8 of 10 : IPerpetualWrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

interface IPerpetualWrapper {
    function open(uint256 amount) external;

    function close(uint256 amount) external;

    function getCollateralAmountGivenUnderlyingAssetAmount(uint256 amount, bool isShorting)
        external
        returns (uint256 collateralAmountRequired);

    function reBalance(
        address _reBalancer,
        int256 amount,
        bytes calldata data
    ) external returns (bool);

    function getAmountInCollateralDecimals(uint256 amount, bool roundUp) external view returns (uint256);
}

File 9 of 10 : IUniswapV2Router.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

interface IUniswapV2Router {
  function getAmountsOut(uint256 amountIn, address[] memory path)
    external
    view
    returns (uint256[] memory amounts);
  
  function swapExactTokensForTokens(
  
    //amount of tokens we are sending in
    uint256 amountIn,
    //the minimum amount of tokens we want out of the trade
    uint256 amountOutMin,
    //list of token addresses we are going to trade in.  this is necessary to calculate amounts
    address[] calldata path,
    //this is the address we are going to send the output tokens to
    address to,
    //the last time that the trade is valid for
    uint256 deadline
  ) external returns (uint256[] memory amounts);
}

File 10 of 10 : IMulticall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
interface IMulticall {
    /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
    /// @dev The `msg.value` should not be trusted for any method callable from multicall.
    /// @param data The encoded function data for each of the calls to make to this contract
    /// @return results The results from each of the calls passed in via data
    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"_weth","type":"address"},{"internalType":"address","name":"_xusdl","type":"address"},{"internalType":"address","name":"_routerSushiswap","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"uint256","name":"maxCollateralRequired","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"mintAndStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"}],"name":"mintForEthAndStake","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"maxCollateralRequired","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"mintUSDL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"}],"name":"mintUSDLETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"maxCollateralRequired","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"mintUSDLTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"}],"name":"mintUSDLToETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"internalType":"address[]","name":"swapActions","type":"address[]"},{"internalType":"bytes[]","name":"swapDatas","type":"bytes[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"maxCollateralRequired","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"mintUSDLToUsingToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"internalType":"address[]","name":"swapActions","type":"address[]"},{"internalType":"bytes[]","name":"swapDatas","type":"bytes[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"maxCollateralRequired","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"mintUSDLUsingToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"internalType":"address[]","name":"swapActions","type":"address[]"},{"internalType":"bytes[]","name":"swapDatas","type":"bytes[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"maxCollateralRequired","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"mintUsingTokenAndStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minCollateralToGetBack","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"redeemUSDL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minCollateralToGetBack","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"}],"name":"redeemUSDLETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minCollateralToGetBack","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"redeemUSDLTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minCollateralToGetBack","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"}],"name":"redeemUSDLToETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address[]","name":"swapActions","type":"address[]"},{"internalType":"bytes[]","name":"swapDatas","type":"bytes[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minTokenAmount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"redeemUSDLToUsingToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address[]","name":"swapActions","type":"address[]"},{"internalType":"bytes[]","name":"swapDatas","type":"bytes[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minTokenAmount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"redeemUSDLUsingToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"routerSushiswap","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stakeUSDL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address[]","name":"swapActions","type":"address[]"},{"internalType":"bytes[]","name":"swapDatas","type":"bytes[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minTokenAmount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"unstakeAndRedeemToToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address[]","name":"swapActions","type":"address[]"},{"internalType":"bytes[]","name":"swapDatas","type":"bytes[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minTokenAmount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"unstakeAndRedeemToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minCollateralToGetBack","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"unstakeAndRedeemUSDL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"uint256","name":"minETHToGetBack","type":"uint256"}],"name":"unstakeAndRedeemUSDLForEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"uint256","name":"minETHToGetBack","type":"uint256"}],"name":"unstakeAndRedeemUSDLForEthTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minCollateralToGetBack","type":"uint256"},{"internalType":"uint256","name":"dexIndex","type":"uint256"},{"internalType":"contract IERC20","name":"collateral","type":"address"}],"name":"unstakeAndRedeemUSDLTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unstakeUSDL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unstakeUSDLTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"usdl","outputs":[{"internalType":"contract IUSDLemma","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"xusdl","outputs":[{"internalType":"contract IXUSDL","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040523480156200001157600080fd5b50604051620030b5380380620030b58339810160408190526200003491620002aa565b600080546001600160a01b038086166001600160a01b031992831617909255600280548584169216919091179081905560408051637839b2c560e11b81529051919092169163f073658a916004808301926020929190829003018186803b1580156200009f57600080fd5b505afa158015620000b4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000da9190620002fd565b600180546001600160a01b03199081166001600160a01b03938416179182905560038054909116848416179055620001249185911660001962000154602090811b620014f717901c565b6001546200014b906001600160a01b03168360001962000154602090811b620014f717901c565b5050506200033c565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1781529251825160009485949389169392918291908083835b60208310620001d25780518252601f199092019160209182019101620001b1565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811462000236576040519150601f19603f3d011682016040523d82523d6000602084013e6200023b565b606091505b50915091508180156200026c5750805115806200026c57508080602001905160208110156200026957600080fd5b50515b620002a3576040805162461bcd60e51b8152602060048201526002602482015261534160f01b604482015290519081900360640190fd5b5050505050565b600080600060608486031215620002bf578283fd5b8351620002cc8162000323565b6020850151909350620002df8162000323565b6040850151909250620002f28162000323565b809150509250925092565b6000602082840312156200030f578081fd5b81516200031c8162000323565b9392505050565b6001600160a01b03811681146200033957600080fd5b50565b612d69806200034c6000396000f3fe6080604052600436106101c65760003560e01c80638f798e8a116100f7578063e18b186511610095578063ef5a7fb611610064578063ef5a7fb6146104cf578063f073658a146104e2578063f26ebaba146104f7578063f2c25a0414610517576101cd565b8063e18b18651461045a578063e20dde0b1461047a578063e87067a61461049a578063e8c3d001146104ba576101cd565b8063ac9650d8116100d1578063ac9650d8146103e7578063baf9aa9014610407578063cda4115a14610427578063dba9160c14610447576101cd565b80638f798e8a1461038757806391a63e0c146103a75780639e3e3555146103c7576101cd565b80633fc8cef3116101645780634ede79891161013e5780634ede79891461031257806363af710f146103325780637129a33a146103475780637950258414610367576101cd565b80633fc8cef3146102a757806341e99849146102d25780634b462284146102f2576101cd565b806326655b80116101a057806326655b80146102275780632b6e171b1461024757806336589122146102675780633ad8fa7d14610287576101cd565b80630e7ab924146101d257806322282137146101e7578063260aa35c14610207576101cd565b366101cd57005b600080fd5b6101e56101e036600461230e565b610537565b005b3480156101f357600080fd5b506101e561020236600461281c565b6106f2565b34801561021357600080fd5b506101e561022236600461237c565b610717565b34801561023357600080fd5b506101e56102423660046125a8565b61089a565b34801561025357600080fd5b506101e56102623660046122e3565b610a3e565b34801561027357600080fd5b506101e561028236600461264d565b610ada565b34801561029357600080fd5b506101e56102a23660046124f0565b610b99565b3480156102b357600080fd5b506102bc610c94565b6040516102c99190612973565b60405180910390f35b3480156102de57600080fd5b506101e56102ed36600461237c565b610ca3565b3480156102fe57600080fd5b506101e561030d36600461237c565b610dd3565b34801561031e57600080fd5b506101e561032d366004612342565b610df8565b34801561033e57600080fd5b506102bc610f13565b34801561035357600080fd5b506101e5610362366004612898565b610f22565b34801561037357600080fd5b506101e561038236600461281c565b610f2f565b34801561039357600080fd5b506101e56103a236600461270b565b610f39565b3480156103b357600080fd5b506101e56103c23660046125a8565b610fed565b3480156103d357600080fd5b506101e56103e236600461270b565b610ffd565b6103fa6103f53660046123d1565b611018565b6040516102c991906129d0565b34801561041357600080fd5b506101e5610422366004612898565b611161565b34801561043357600080fd5b506101e561044236600461286d565b611178565b6101e561045536600461284c565b611184565b34801561046657600080fd5b506101e5610475366004612898565b611193565b34801561048657600080fd5b506101e56104953660046124f0565b6111a0565b3480156104a657600080fd5b506101e56104b5366004612342565b6112e9565b3480156104c657600080fd5b506102bc6114ab565b6101e56104dd36600461284c565b6114ba565b3480156104ee57600080fd5b506102bc6114cf565b34801561050357600080fd5b506101e561051236600461286d565b6114de565b34801561052357600080fd5b506101e5610532366004612898565b6114ea565b60008054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561058557600080fd5b505af1158015610599573d6000803e3d6000fd5b50506001546000546040516318787a0f60e01b81526001600160a01b0392831695506318787a0f94506105db9350889288928892349290911690600401612987565b600060405180830381600087803b1580156105f557600080fd5b505af1158015610609573d6000803e3d6000fd5b50506000546040516370a0823160e01b81526001600160a01b039091169250632e1a7d4d915082906370a0823190610645903090600401612973565b60206040518083038186803b15801561065d57600080fd5b505afa158015610671573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106959190612834565b6040518263ffffffff1660e01b81526004016106b19190612bb5565b600060405180830381600087803b1580156106cb57600080fd5b505af11580156106df573d6000803e3d6000fd5b505050506106ed334761163e565b505050565b60015461070a906001600160a01b031633308461172d565b6107148133611885565b50565b600154604051633cd9561160e01b81526000916001600160a01b031690633cd956119061074a9086908690600401612bbe565b60206040518083038186803b15801561076257600080fd5b505afa158015610776573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079a91906122c0565b6001600160a01b03166392f72def8660016040518363ffffffff1660e01b81526004016107c8929190612bf6565b602060405180830381600087803b1580156107e257600080fd5b505af11580156107f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061081a9190612834565b90506108288233308461172d565b6001546040516318787a0f60e01b81526001600160a01b03909116906318787a0f90610860908990899088908a908990600401612987565b600060405180830381600087803b15801561087a57600080fd5b505af115801561088e573d6000803e3d6000fd5b50505050505050505050565b6001546108b2906001600160a01b031633308761172d565b60015460405163a9fae5fd60e01b81526001600160a01b039091169063a9fae5fd906108eb903090889087906000908890600401612987565b600060405180830381600087803b15801561090557600080fd5b505af1158015610919573d6000803e3d6000fd5b505050506109298787878661193e565b6109af8733896001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161095a9190612973565b60206040518083038186803b15801561097257600080fd5b505afa158015610986573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109aa9190612834565b611adf565b610a358188836001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016109e09190612973565b60206040518083038186803b1580156109f857600080fd5b505afa158015610a0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a309190612834565b611c26565b50505050505050565b600254610a56906001600160a01b031633308461172d565b60025460405163040b850f60e31b81526001600160a01b039091169063205c287890610a8890859085906004016129b7565b602060405180830381600087803b158015610aa257600080fd5b505af1158015610ab6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ed9190612834565b610ae68933308b61172d565b610af38787868585611ea1565b6001546040516318787a0f60e01b81526001600160a01b03909116906318787a0f90610b2b9088908890879089908890600401612987565b600060405180830381600087803b158015610b4557600080fd5b505af1158015610b59573d6000803e3d6000fd5b50505050610b8e818a836001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016109e09190612973565b505050505050505050565b600154610bb1906001600160a01b031633308761172d565b60015460405163a9fae5fd60e01b81526001600160a01b039091169063a9fae5fd90610bea903090889087906000908890600401612987565b600060405180830381600087803b158015610c0457600080fd5b505af1158015610c18573d6000803e3d6000fd5b50505050610c288888888661193e565b610c5988868a6001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161095a9190612973565b610c8a8189836001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016109e09190612973565b5050505050505050565b6000546001600160a01b031681565b600254610cbb906001600160a01b031633308761172d565b600254604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90610ceb908790600401612bb5565b602060405180830381600087803b158015610d0557600080fd5b505af1158015610d19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3d9190612834565b506001546040516370a0823160e01b8152610dcc9187916001600160a01b03909116906370a0823190610d74903090600401612973565b60206040518083038186803b158015610d8c57600080fd5b505afa158015610da0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dc49190612834565b848685612146565b5050505050565b600154610deb906001600160a01b031633308761172d565b610dcc8585848685612146565b600154610e10906001600160a01b031633308661172d565b600054610e2d9030908590849086906001600160a01b0316612146565b6000546040516370a0823160e01b81526001600160a01b0390911690632e1a7d4d9082906370a0823190610e65903090600401612973565b60206040518083038186803b158015610e7d57600080fd5b505afa158015610e91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb59190612834565b6040518263ffffffff1660e01b8152600401610ed19190612bb5565b600060405180830381600087803b158015610eeb57600080fd5b505af1158015610eff573d6000803e3d6000fd5b50505050610f0d844761163e565b50505050565b6003546001600160a01b031681565b610f0d3385858585610ca3565b6107143382610a3e565b610f458833308a61172d565b610f528686868585611ea1565b6001546040516318787a0f60e01b81526001600160a01b03909116906318787a0f90610f8a9033908890879089908890600401612987565b600060405180830381600087803b158015610fa457600080fd5b505af1158015610fb8573d6000803e3d6000fd5b50505050610c8a8189836001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016109e09190612973565b610a3587878733888888886111a0565b61100e888888883089898989610ada565b610c8a8433611885565b60608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106557816020015b60608152602001906001900390816110505790505b50905060005b8281101561115a576000803086868581811061108357fe5b90506020028101906110959190612c42565b6040516110a3929190612947565b600060405180830381855af49150503d80600081146110de576040519150601f19603f3d011682016040523d82523d6000602084013e6110e3565b606091505b509150915081611138576044815110156110fc57600080fd5b6004810190508080602001905181019061111691906127a9565b60405162461bcd60e51b815260040161112f9190612a30565b60405180910390fd5b8084848151811061114557fe5b6020908102919091010152505060010161106b565b5092915050565b61116e3085848685610717565b610f0d8433611885565b6106ed33848484610df8565b61118f338383610537565b5050565b610f0d3385858585610717565b6002546111b8906001600160a01b031633308761172d565b600254604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d906111e8908790600401612bb5565b602060405180830381600087803b15801561120257600080fd5b505af1158015611216573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061123a9190612834565b506001546040516370a0823160e01b81526001600160a01b039091169063a9fae5fd90309083906370a0823190611275908490600401612973565b60206040518083038186803b15801561128d57600080fd5b505afa1580156112a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112c59190612834565b856000866040518663ffffffff1660e01b8152600401610bea959493929190612987565b600254611301906001600160a01b031633308661172d565b600254604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90611331908690600401612bb5565b602060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113839190612834565b506001546040516370a0823160e01b81526001600160a01b039091169063a9fae5fd90309083906370a08231906113be908490600401612973565b60206040518083038186803b1580156113d657600080fd5b505afa1580156113ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061140e9190612834565b6000546040516001600160e01b031960e086901b168152611441939291889188916001600160a01b031690600401612987565b600060405180830381600087803b15801561145b57600080fd5b505af115801561146f573d6000803e3d6000fd5b50506000546040516370a0823160e01b81526001600160a01b039091169250632e1a7d4d915082906370a0823190610e65903090600401612973565b6002546001600160a01b031681565b6114c5308383610537565b61118f8233611885565b6001546001600160a01b031681565b6106ed338484846112e9565b610f0d3385858585610dd3565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1781529251825160009485949389169392918291908083835b602083106115735780518252601f199092019160209182019101611554565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146115d5576040519150601f19603f3d011682016040523d82523d6000602084013e6115da565b606091505b5091509150818015611608575080511580611608575080806020019051602081101561160557600080fd5b50515b610dcc576040805162461bcd60e51b8152602060048201526002602482015261534160f01b604482015290519081900360640190fd5b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b6020831061168a5780518252601f19909201916020918201910161166b565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146116ec576040519150601f19603f3d011682016040523d82523d6000602084013e6116f1565b606091505b50509050806106ed576040805162461bcd60e51b815260206004820152600360248201526253544560e81b604482015290519081900360640190fd5b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b178152925182516000948594938a169392918291908083835b602083106117b15780518252601f199092019160209182019101611792565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611813576040519150601f19603f3d011682016040523d82523d6000602084013e611818565b606091505b5091509150818015611846575080511580611846575080806020019051602081101561184357600080fd5b50515b61187d576040805162461bcd60e51b815260206004820152600360248201526229aa2360e91b604482015290519081900360640190fd5b505050505050565b60025460405163b6b55f2560e01b81526001600160a01b039091169063b6b55f25906118b5908590600401612bb5565b602060405180830381600087803b1580156118cf57600080fd5b505af11580156118e3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119079190612834565b506002546040516370a0823160e01b815261118f916001600160a01b031690839082906370a082319061095a903090600401612973565b60005b8351811015611a425760025484516001600160a01b039091169085908390811061196757fe5b60200260200101516001600160a01b031614156119965760405162461bcd60e51b815260040161112f90612a6f565b60008482815181106119a457fe5b60200260200101516001600160a01b03168483815181106119c157fe5b60200260200101516040516119d69190612957565b6000604051808303816000865af19150503d8060008114611a13576040519150601f19603f3d011682016040523d82523d6000602084013e611a18565b606091505b5050905080611a395760405162461bcd60e51b815260040161112f90612b90565b50600101611941565b506040516370a0823160e01b815281906001600160a01b038616906370a0823190611a71903090600401612973565b60206040518083038186803b158015611a8957600080fd5b505afa158015611a9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ac19190612834565b1015610f0d5760405162461bcd60e51b815260040161112f90612ace565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485949389169392918291908083835b60208310611b5b5780518252601f199092019160209182019101611b3c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611bbd576040519150601f19603f3d011682016040523d82523d6000602084013e611bc2565b606091505b5091509150818015611bf0575080511580611bf05750808060200190516020811015611bed57600080fd5b50515b610dcc576040805162461bcd60e51b815260206004820152600260248201526114d560f21b604482015290519081900360640190fd5b60008111611c465760405162461bcd60e51b815260040161112f90612b1f565b6040805160028082526060820183526000926020830190803683370190505090508381600081518110611c7557fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508281600181518110611ca357fe5b6001600160a01b03928316602091820292909201015260035460405163d06ca61f60e01b8152600092919091169063d06ca61f90611ce79086908690600401612bd5565b60006040518083038186803b158015611cff57600080fd5b505afa158015611d13573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611d3b9190810190612440565b600181518110611d4757fe5b6020026020010151905060008111611d715760405162461bcd60e51b815260040161112f90612a43565b60035460405163095ea7b360e01b81526001600160a01b038781169263095ea7b392611da5929091169087906004016129b7565b602060405180830381600087803b158015611dbf57600080fd5b505af1158015611dd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611df791906124d0565b611e135760405162461bcd60e51b815260040161112f90612aa6565b6003546040516338ed173960e01b81526001600160a01b03909116906338ed173990611e4b9086908590879033904290600401612c06565b600060405180830381600087803b158015611e6557600080fd5b505af1158015611e79573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261187d9190810190612440565b60005b8551811015611fa55760025486516001600160a01b0390911690879083908110611eca57fe5b60200260200101516001600160a01b03161415611ef95760405162461bcd60e51b815260040161112f90612a6f565b6000868281518110611f0757fe5b60200260200101516001600160a01b0316868381518110611f2457fe5b6020026020010151604051611f399190612957565b6000604051808303816000865af19150503d8060008114611f76576040519150601f19603f3d011682016040523d82523d6000602084013e611f7b565b606091505b5050905080611f9c5760405162461bcd60e51b815260040161112f90612b90565b50600101611ea4565b50600154604051633cd9561160e01b81526000916001600160a01b031690633cd9561190611fd99086908690600401612bbe565b60206040518083038186803b158015611ff157600080fd5b505afa158015612005573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061202991906122c0565b6001600160a01b03166392f72def8560016040518363ffffffff1660e01b8152600401612057929190612bf6565b602060405180830381600087803b15801561207157600080fd5b505af1158015612085573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120a99190612834565b905080826001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016120d89190612973565b60206040518083038186803b1580156120f057600080fd5b505afa158015612104573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121289190612834565b101561187d5760405162461bcd60e51b815260040161112f90612b4c565b60015460405163a9fae5fd60e01b81526001600160a01b039091169063a9fae5fd9061217e9088908890889088908890600401612987565b600060405180830381600087803b15801561219857600080fd5b505af1158015610b8e573d6000803e3d6000fd5b80356121b781612d1e565b919050565b600082601f8301126121cc578081fd5b813560206121e16121dc83612cb2565b612c8e565b82815281810190858301838502870184018810156121fd578586fd5b855b8581101561222457813561221281612d1e565b845292840192908401906001016121ff565b5090979650505050505050565b600082601f830112612241578081fd5b813560206122516121dc83612cb2565b82815281810190858301855b85811015612224578135880189603f820112612277578788fd5b8581013560406122896121dc83612cd0565b8281528c8284860101111561229c578a8bfd5b828285018a83013791820188018a905250855250928401929084019060010161225d565b6000602082840312156122d1578081fd5b81516122dc81612d1e565b9392505050565b600080604083850312156122f5578081fd5b823561230081612d1e565b946020939093013593505050565b600080600060608486031215612322578081fd5b833561232d81612d1e565b95602085013595506040909401359392505050565b60008060008060808587031215612357578081fd5b843561236281612d1e565b966020860135965060408601359560600135945092505050565b600080600080600060a08688031215612393578081fd5b853561239e81612d1e565b945060208601359350604086013592506060860135915060808601356123c381612d1e565b809150509295509295909350565b600080602083850312156123e3578182fd5b823567ffffffffffffffff808211156123fa578384fd5b818501915085601f83011261240d578384fd5b81358181111561241b578485fd5b866020808302850101111561242e578485fd5b60209290920196919550909350505050565b60006020808385031215612452578182fd5b825167ffffffffffffffff811115612468578283fd5b8301601f81018513612478578283fd5b80516124866121dc82612cb2565b81815283810190838501858402850186018910156124a2578687fd5b8694505b838510156124c45780518352600194909401939185019185016124a6565b50979650505050505050565b6000602082840312156124e1578081fd5b815180151581146122dc578182fd5b600080600080600080600080610100898b03121561250c578586fd5b883561251781612d1e565b9750602089013567ffffffffffffffff80821115612533578788fd5b61253f8c838d016121bc565b985060408b0135915080821115612554578788fd5b506125618b828c01612231565b965050606089013561257281612d1e565b94506080890135935060a0890135925060c0890135915060e089013561259781612d1e565b809150509295985092959890939650565b600080600080600080600060e0888a0312156125c2578081fd5b87356125cd81612d1e565b9650602088013567ffffffffffffffff808211156125e9578283fd5b6125f58b838c016121bc565b975060408a013591508082111561260a578283fd5b506126178a828b01612231565b955050606088013593506080880135925060a0880135915060c088013561263d81612d1e565b8091505092959891949750929550565b60008060008060008060008060006101208a8c03121561266b578283fd5b893561267681612d1e565b985060208a0135975060408a013567ffffffffffffffff80821115612699578485fd5b6126a58d838e016121bc565b985060608c01359150808211156126ba578485fd5b506126c78c828d01612231565b96505060808a01356126d881612d1e565b945060a08a0135935060c08a0135925060e08a013591506126fc6101008b016121ac565b90509295985092959850929598565b600080600080600080600080610100898b031215612727578182fd5b883561273281612d1e565b975060208901359650604089013567ffffffffffffffff80821115612755578384fd5b6127618c838d016121bc565b975060608b0135915080821115612776578384fd5b506127838b828c01612231565b9550506080890135935060a0890135925060c0890135915060e089013561259781612d1e565b6000602082840312156127ba578081fd5b815167ffffffffffffffff8111156127d0578182fd5b8201601f810184136127e0578182fd5b80516127ee6121dc82612cd0565b818152856020838501011115612802578384fd5b612813826020830160208601612cf2565b95945050505050565b60006020828403121561282d578081fd5b5035919050565b600060208284031215612845578081fd5b5051919050565b6000806040838503121561285e578182fd5b50508035926020909101359150565b600080600060608486031215612881578081fd5b505081359360208301359350604090920135919050565b600080600080608085870312156128ad578182fd5b84359350602085013592506040850135915060608501356128cd81612d1e565b939692955090935050565b6000815180845260208085019450808401835b838110156129105781516001600160a01b0316875295820195908201906001016128eb565b509495945050505050565b60008151808452612933816020860160208601612cf2565b601f01601f19169290920160200192915050565b6000828483379101908152919050565b60008251612969818460208701612cf2565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b039586168152602081019490945260408401929092526060830152909116608082015260a00190565b6001600160a01b03929092168252602082015260400190565b6000602080830181845280855180835260408601915060408482028701019250838701855b82811015612a2357603f19888603018452612a1185835161291b565b945092850192908501906001016129f5565b5092979650505050505050565b6000602082526122dc602083018461291b565b6020808252601290820152714e6f20746f6b656e20617661696c61626c6560701b604082015260600190565b6020808252601a908201527f63616e6e6f742063616c6c20785553444c20636f6e7472616374000000000000604082015260600190565b6020808252600e908201526d105c1c1c9bdd994819985a5b195960921b604082015260600190565b60208082526031908201527f7377617070656420616d6f756e74206973206c657373207468616e20746f6b656040820152701b88185b5bdd5b9d081c995c5d5a5c9959607a1b606082015260800190565b6020808252601390820152722737ba3434b733903a37903a3930b739b332b960691b604082015260600190565b60208082526024908201527f7377617070656420616d6f756e74206973206c657373207468616e20726571756040820152631a5c995960e21b606082015260800190565b6020808252600b908201526a1cddd85c0819985a5b195960aa1b604082015260600190565b90815260200190565b9182526001600160a01b0316602082015260400190565b600083825260406020830152612bee60408301846128d8565b949350505050565b9182521515602082015260400190565b600086825285602083015260a06040830152612c2560a08301866128d8565b6001600160a01b0394909416606083015250608001529392505050565b6000808335601e19843603018112612c58578283fd5b83018035915067ffffffffffffffff821115612c72578283fd5b602001915036819003821315612c8757600080fd5b9250929050565b60405181810167ffffffffffffffff81118282101715612caa57fe5b604052919050565b600067ffffffffffffffff821115612cc657fe5b5060209081020190565b600067ffffffffffffffff821115612ce457fe5b50601f01601f191660200190565b60005b83811015612d0d578181015183820152602001612cf5565b83811115610f0d5750506000910152565b6001600160a01b038116811461071457600080fdfea2646970667358221220d66505a6044712677845fdf280e3f25f9986cf6779312aa87a4832292a7d66a264736f6c6343000706003300000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000057c7e0d43c05bce429ce030132ca40f6fa5839d70000000000000000000000001b02da8cb0d097eb8d57a175b88c7d8b47997506

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

00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000057c7e0d43c05bce429ce030132ca40f6fa5839d70000000000000000000000001b02da8cb0d097eb8d57a175b88c7d8b47997506

-----Decoded View---------------
Arg [0] : _weth (address): 0x82af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [1] : _xusdl (address): 0x57c7e0d43c05bce429ce030132ca40f6fa5839d7
Arg [2] : _routerSushiswap (address): 0x1b02da8cb0d097eb8d57a175b88c7d8b47997506

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [1] : 00000000000000000000000057c7e0d43c05bce429ce030132ca40f6fa5839d7
Arg [2] : 0000000000000000000000001b02da8cb0d097eb8d57a175b88c7d8b47997506


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.