ETH Price: $3,317.08 (+1.76%)
Gas: 3 Gwei

Contract

0xbFAD1987608a38bfA0FE4c5510c1aF834aE21379
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x60a06040129286352021-07-30 18:40:091095 days ago1627670409IN
 Create: UniswapV2IndexExchangeAdapter
0 ETH0.0150123234

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
UniswapV2IndexExchangeAdapter

Compiler Version
v0.6.10+commit.00c0fcaf

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 3 : UniswapV2IndexExchangeAdapter.sol
/*
    Copyright 2021 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

import { BytesLib } from "external/contracts/uniswap/v3/lib/BytesLib.sol";
import { IIndexExchangeAdapter } from "../../../interfaces/IIndexExchangeAdapter.sol";


/**
 * @title UniswapV2IndexExchangeAdapter
 * @author Set Protocol
 *
 * A Uniswap Router02 exchange adapter that returns calldata for trading with GeneralIndexModule, allows encoding a trade with a fixed input quantity or
 * a fixed output quantity.
 *
 * CHANGELOG: 7/8/2021
 * - Update getTradeCalldata to allow for the intermediate token of the path to be passed in through the _data parameter
 */
contract UniswapV2IndexExchangeAdapter is IIndexExchangeAdapter {

    using BytesLib for bytes;

    /* ============ State Variables ============ */

    // Address of Uniswap V2 Router02 contract
    address public immutable router;
    // Uniswap router function string for swapping exact tokens for a minimum of receive tokens
    string internal constant SWAP_EXACT_TOKENS_FOR_TOKENS = "swapExactTokensForTokens(uint256,uint256,address[],address,uint256)";
    // Uniswap router function string for swapping tokens for an exact amount of receive tokens
    string internal constant SWAP_TOKENS_FOR_EXACT_TOKENS = "swapTokensForExactTokens(uint256,uint256,address[],address,uint256)";

    /* ============ Constructor ============ */

    /**
     * Set state variables
     *
     * @param _router       Address of Uniswap V2 Router02 contract
     */
    constructor(address _router) public {
        router = _router;
    }

    /* ============ External Getter Functions ============ */

    /**
     * Return calldata for trading Uniswap V2 Router02. Trade paths are created from input and output tokens, _isSendTokenFixed indicates whether
     * a fixed amount of token should be sold or an unfixed amount.
     *
     * Note: When _isSendTokenFixed is false, _sourceQuantity is defined as the max token quantity you are willing to trade, and
     * _destinationQuantity is the exact quantity of token you are receiving.
     *
     * @param  _sourceToken              Address of source token to be sold
     * @param  _destinationToken         Address of destination token to buy
     * @param  _destinationAddress       Address that assets should be transferred to
     * @param  _isSendTokenFixed         Boolean indicating if the send quantity is fixed, used to determine correct trade interface
     * @param  _sourceQuantity           Fixed/Max amount of source token to sell
     * @param  _destinationQuantity      Min/Fixed amount of destination token to buy
     * @param  _data                     Encoded address intermediary token in the trade path. If empty, path is the input and output tokens. 
                                         Note: only allows one intermediary asset
     *
     * @return address                   Target contract address
     * @return uint256                   Call value
     * @return bytes                     Trade calldata
     */
    function getTradeCalldata(
        address _sourceToken,
        address _destinationToken,
        address _destinationAddress,
        bool _isSendTokenFixed,
        uint256 _sourceQuantity,
        uint256 _destinationQuantity,
        bytes memory _data
    )
        external
        view
        override
        returns (address, uint256, bytes memory)
    {
        address[] memory path;

        if (_data.length == 0) {
            path = new address[](2);
            path[0] = _sourceToken;
            path[1] = _destinationToken;
        } else {
            address intermediateToken = _data.toAddress(0);
            path = new address[](3);
            path[0] = _sourceToken;
            path[1] = intermediateToken;
            path[2] = _destinationToken;
        }

        bytes memory callData = abi.encodeWithSignature(
            _isSendTokenFixed ? SWAP_EXACT_TOKENS_FOR_TOKENS : SWAP_TOKENS_FOR_EXACT_TOKENS,
            _isSendTokenFixed ? _sourceQuantity : _destinationQuantity,
            _isSendTokenFixed ? _destinationQuantity : _sourceQuantity,
            path,
            _destinationAddress,
            block.timestamp
        );
        return (router, 0, callData);
    }

    /**
     * Returns the address to approve source tokens to for trading. This is the Uniswap router address
     *
     * @return address             Address of the contract to approve tokens to
     */
    function getSpender() external view override returns (address) {
        return router;
    }
}

File 2 of 3 : BytesLib.sol
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <[email protected]>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity 0.6.10;

library BytesLib {
    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    ) internal pure returns (bytes memory) {
        require(_length + 31 >= _length, "slice_overflow");
        require(_start + _length >= _start, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
                case 0 {
                    // Get a location of some free memory and store it in tempBytes as
                    // Solidity does for memory variables.
                    tempBytes := mload(0x40)

                    // The first word of the slice result is potentially a partial
                    // word read from the original array. To read it, we calculate
                    // the length of that partial word and start copying that many
                    // bytes into the array. The first word we copy will start with
                    // data we don't care about, but the last `lengthmod` bytes will
                    // land at the beginning of the contents of the new array. When
                    // we're done copying, we overwrite the full first word with
                    // the actual length of the slice.
                    let lengthmod := and(_length, 31)

                    // The multiplication in the next line is necessary
                    // because when slicing multiples of 32 bytes (lengthmod == 0)
                    // the following copy loop was copying the origin's length
                    // and then ending prematurely not copying everything it should.
                    let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                    let end := add(mc, _length)

                    for {
                        // The multiplication in the next line has the same exact purpose
                        // as the one above.
                        let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                    } lt(mc, end) {
                        mc := add(mc, 0x20)
                        cc := add(cc, 0x20)
                    } {
                        mstore(mc, mload(cc))
                    }

                    mstore(tempBytes, _length)

                    //update free-memory pointer
                    //allocating the array padded to 32 bytes like the compiler does now
                    mstore(0x40, and(add(mc, 31), not(31)))
                }
                //if we want a zero-length slice let's just return a zero-length array
                default {
                    tempBytes := mload(0x40)
                    //zero out the 32 bytes slice we are about to return
                    //we need to do it because Solidity does not garbage collect
                    mstore(tempBytes, 0)

                    mstore(0x40, add(tempBytes, 0x20))
                }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        require(_start + 20 >= _start, "toAddress_overflow");
        require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) {
        require(_start + 3 >= _start, "toUint24_overflow");
        require(_bytes.length >= _start + 3, "toUint24_outOfBounds");
        uint24 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x3), _start))
        }

        return tempUint;
    }
}

File 3 of 3 : IIndexExchangeAdapter.sol
/*
    Copyright 2021 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;

interface IIndexExchangeAdapter {
    function getSpender() external view returns(address);

    /**
     * Returns calldata for executing trade on given adapter's exchange when using the GeneralIndexModule.
     *
     * @param  _sourceToken              Address of source token to be sold
     * @param  _destinationToken         Address of destination token to buy
     * @param  _destinationAddress       Address that assets should be transferred to
     * @param  _isSendTokenFixed         Boolean indicating if the send quantity is fixed, used to determine correct trade interface
     * @param  _sourceQuantity           Fixed/Max amount of source token to sell
     * @param  _destinationQuantity      Min/Fixed amount of destination tokens to receive
     * @param  _data                     Arbitrary bytes that can be used to store exchange specific parameters or logic
     *
     * @return address                   Target contract address
     * @return uint256                   Call value
     * @return bytes                     Trade calldata
     */
    function getTradeCalldata(
        address _sourceToken,
        address _destinationToken,
        address _destinationAddress,
        bool _isSendTokenFixed,
        uint256 _sourceQuantity,
        uint256 _destinationQuantity,
        bytes memory _data
    )
        external
        view
        returns (address, uint256, bytes memory);
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_router","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"getSpender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_sourceToken","type":"address"},{"internalType":"address","name":"_destinationToken","type":"address"},{"internalType":"address","name":"_destinationAddress","type":"address"},{"internalType":"bool","name":"_isSendTokenFixed","type":"bool"},{"internalType":"uint256","name":"_sourceQuantity","type":"uint256"},{"internalType":"uint256","name":"_destinationQuantity","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"getTradeCalldata","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60a060405234801561001057600080fd5b5060405161079738038061079783398101604081905261002f91610044565b60601b6001600160601b031916608052610072565b600060208284031215610055578081fd5b81516001600160a01b038116811461006b578182fd5b9392505050565b60805160601c6106ff61009860003980609052806102bb52806102f352506106ff6000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063334fc28914610046578063e869b69b14610064578063f887ea4014610086575b600080fd5b61004e61008e565b60405161005b919061046e565b60405180910390f35b610077610072366004610377565b6100b2565b60405161005b93929190610482565b61004e6102f1565b7f000000000000000000000000000000000000000000000000000000000000000090565b6000806060808451600014156101435760408051600280825260608201835290916020830190803683370190505090508a816000815181106100f057fe5b60200260200101906001600160a01b031690816001600160a01b031681525050898160018151811061011e57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050610204565b6000610155868263ffffffff61031516565b60408051600380825260808201909252919250602082016060803683370190505091508b8260008151811061018657fe5b60200260200101906001600160a01b031690816001600160a01b03168152505080826001815181106101b457fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508a826002815181106101e257fe5b60200260200101906001600160a01b031690816001600160a01b031681525050505b6060886102295760405180608001604052806043815260200161068760439139610243565b604051806080016040528060438152602001610644604391395b8961024e5787610250565b885b8a61025b578961025d565b885b848d42604051602401610274959493929190610526565b60408051601f19818403018152908290529161028f91610452565b6040519081900390206020820180516001600160e01b03166001600160e01b03199092169190911790527f0000000000000000000000000000000000000000000000000000000000000000955060009450925050509750975097945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000818260140110156103435760405162461bcd60e51b815260040161033a906104fa565b60405180910390fd5b81601401835110156103675760405162461bcd60e51b815260040161033a906104cb565b500160200151600160601b900490565b600080600080600080600060e0888a031215610391578283fd5b873561039c8161061d565b965060208801356103ac8161061d565b955060408801356103bc8161061d565b945060608801356103cc81610635565b93506080880135925060a0880135915060c088013567ffffffffffffffff8111156103f5578182fd5b8089018a601f820112610406578283fd5b8035915061041b610416836105bd565b610596565b8281528b602084840101111561042f578384fd5b6104408360208301602085016105e1565b80935050505092959891949750929550565b600082516104648184602087016105ed565b9190910192915050565b6001600160a01b0391909116815260200190565b600060018060a01b03851682528360208301526060604083015282518060608401526104b58160808501602087016105ed565b601f01601f191691909101608001949350505050565b602080825260159082015274746f416464726573735f6f75744f66426f756e647360581b604082015260600190565b602080825260129082015271746f416464726573735f6f766572666c6f7760701b604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b818110156105755784516001600160a01b031683529383019391830191600101610550565b50506001600160a01b03969096166060850152505050608001529392505050565b60405181810167ffffffffffffffff811182821017156105b557600080fd5b604052919050565b600067ffffffffffffffff8211156105d3578081fd5b50601f01601f191660200190565b82818337506000910152565b60005b838110156106085781810151838201526020016105f0565b83811115610617576000848401525b50505050565b6001600160a01b038116811461063257600080fd5b50565b801515811461063257600080fdfe737761704578616374546f6b656e73466f72546f6b656e732875696e743235362c75696e743235362c616464726573735b5d2c616464726573732c75696e743235362973776170546f6b656e73466f724578616374546f6b656e732875696e743235362c75696e743235362c616464726573735b5d2c616464726573732c75696e7432353629a2646970667358221220fada31f6799066667dd5e49c1a48136ed15c1ec6edac5ff0c3b95c620151fa2564736f6c634300060a0033000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063334fc28914610046578063e869b69b14610064578063f887ea4014610086575b600080fd5b61004e61008e565b60405161005b919061046e565b60405180910390f35b610077610072366004610377565b6100b2565b60405161005b93929190610482565b61004e6102f1565b7f000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f90565b6000806060808451600014156101435760408051600280825260608201835290916020830190803683370190505090508a816000815181106100f057fe5b60200260200101906001600160a01b031690816001600160a01b031681525050898160018151811061011e57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050610204565b6000610155868263ffffffff61031516565b60408051600380825260808201909252919250602082016060803683370190505091508b8260008151811061018657fe5b60200260200101906001600160a01b031690816001600160a01b03168152505080826001815181106101b457fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508a826002815181106101e257fe5b60200260200101906001600160a01b031690816001600160a01b031681525050505b6060886102295760405180608001604052806043815260200161068760439139610243565b604051806080016040528060438152602001610644604391395b8961024e5787610250565b885b8a61025b578961025d565b885b848d42604051602401610274959493929190610526565b60408051601f19818403018152908290529161028f91610452565b6040519081900390206020820180516001600160e01b03166001600160e01b03199092169190911790527f000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f955060009450925050509750975097945050505050565b7f000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f81565b6000818260140110156103435760405162461bcd60e51b815260040161033a906104fa565b60405180910390fd5b81601401835110156103675760405162461bcd60e51b815260040161033a906104cb565b500160200151600160601b900490565b600080600080600080600060e0888a031215610391578283fd5b873561039c8161061d565b965060208801356103ac8161061d565b955060408801356103bc8161061d565b945060608801356103cc81610635565b93506080880135925060a0880135915060c088013567ffffffffffffffff8111156103f5578182fd5b8089018a601f820112610406578283fd5b8035915061041b610416836105bd565b610596565b8281528b602084840101111561042f578384fd5b6104408360208301602085016105e1565b80935050505092959891949750929550565b600082516104648184602087016105ed565b9190910192915050565b6001600160a01b0391909116815260200190565b600060018060a01b03851682528360208301526060604083015282518060608401526104b58160808501602087016105ed565b601f01601f191691909101608001949350505050565b602080825260159082015274746f416464726573735f6f75744f66426f756e647360581b604082015260600190565b602080825260129082015271746f416464726573735f6f766572666c6f7760701b604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b818110156105755784516001600160a01b031683529383019391830191600101610550565b50506001600160a01b03969096166060850152505050608001529392505050565b60405181810167ffffffffffffffff811182821017156105b557600080fd5b604052919050565b600067ffffffffffffffff8211156105d3578081fd5b50601f01601f191660200190565b82818337506000910152565b60005b838110156106085781810151838201526020016105f0565b83811115610617576000848401525b50505050565b6001600160a01b038116811461063257600080fd5b50565b801515811461063257600080fdfe737761704578616374546f6b656e73466f72546f6b656e732875696e743235362c75696e743235362c616464726573735b5d2c616464726573732c75696e743235362973776170546f6b656e73466f724578616374546f6b656e732875696e743235362c75696e743235362c616464726573735b5d2c616464726573732c75696e7432353629a2646970667358221220fada31f6799066667dd5e49c1a48136ed15c1ec6edac5ff0c3b95c620151fa2564736f6c634300060a0033

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

000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f

-----Decoded View---------------
Arg [0] : _router (address): 0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.