Contract 0x515695578eECd92d7747897df7756967912E678a 2

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x4ae23e5a4d090ac64297093f9340e7929659c66f202ac66856468d47399c7ce30x60806040164220602022-06-23 18:06:0012 days 10 hrs ago0xcbd4e556fc24c83159defd1d1bbad66fd7d2c75c IN  Create: TraderJoeSwapper0 AVAX0.02147617525
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
TraderJoeSwapper

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 100 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 4 : TraderJoeSwapper.sol
//SPDX-License-Identifier: LICENSED

// Solidity files have to start with this pragma.
// It will be used by the Solidity compiler to validate its version.
pragma solidity ^0.7.0;
import "./traderjoe/interfaces/IJoePair.sol";
import "./traderjoe/libraries/JoeLibrary.sol";

contract TraderJoeSwapper {
  // factory address for AMM dex, normally we use spookyswap on fantom chain.
  address public factory;
  address public constant WAVAX = 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;
  address public constant USDC = 0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E;
  address public constant OKSE = 0xbc7B0223Dd16cbc679c0D04bA3F4530D76DFbA87;

  constructor(address _factory) {
    factory = _factory;
  }

  // **** SWAP ****
  // verified
  // requires the initial amount to have already been sent to the first pair
  function _swap(
    uint256[] memory amounts,
    address[] memory path,
    address _to
  ) external {
    for (uint256 i; i < path.length - 1; i++) {
      (address input, address output) = (path[i], path[i + 1]);
      (address token0, ) = JoeLibrary.sortTokens(input, output);
      uint256 amountOut = amounts[i + 1];
      (uint256 amount0Out, uint256 amount1Out) = input == token0
        ? (uint256(0), amountOut)
        : (amountOut, uint256(0));
      address to = i < path.length - 2
        ? JoeLibrary.pairFor(factory, output, path[i + 2])
        : _to;
      IJoePair(JoeLibrary.pairFor(factory, input, output)).swap(
        amount0Out,
        amount1Out,
        to,
        new bytes(0)
      );
    }
  }

  function getAmountsIn(
    uint256 amountOut,
    address[] memory path
  ) external view returns (uint256[] memory amounts) {
    return JoeLibrary.getAmountsIn(factory, amountOut, path);
  }

  function GetReceiverAddress(
    address[] memory path
  ) external view returns (address) {
    return JoeLibrary.pairFor(factory, path[0], path[1]);
  }

  function getOptimumPath(
    address token0,
    address token1
  ) external view returns (address[] memory path) {
    
    if (token0 == OKSE && token1 == USDC) {
      //OKSE-USDC pair
      path = new address[](3);
      path[0] = OKSE;
      path[1] = WAVAX;
      path[2] = USDC;
    } else {
      path = new address[](2);
      path[0] = token0;
      path[1] = token1;
    }
  }
}

File 2 of 4 : IJoePair.sol
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

interface IJoePair {
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
    event Transfer(address indexed from, address indexed to, uint256 value);

    function name() external pure returns (string memory);

    function symbol() external pure returns (string memory);

    function decimals() external pure returns (uint8);

    function totalSupply() external view returns (uint256);

    function balanceOf(address owner) external view returns (uint256);

    function allowance(address owner, address spender)
        external
        view
        returns (uint256);

    function approve(address spender, uint256 value) external returns (bool);

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

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

    function DOMAIN_SEPARATOR() external view returns (bytes32);

    function PERMIT_TYPEHASH() external pure returns (bytes32);

    function nonces(address owner) external view returns (uint256);

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    event Mint(address indexed sender, uint256 amount0, uint256 amount1);
    event Burn(
        address indexed sender,
        uint256 amount0,
        uint256 amount1,
        address indexed to
    );
    event Swap(
        address indexed sender,
        uint256 amount0In,
        uint256 amount1In,
        uint256 amount0Out,
        uint256 amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint256);

    function factory() external view returns (address);

    function token0() external view returns (address);

    function token1() external view returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 reserve0,
            uint112 reserve1,
            uint32 blockTimestampLast
        );

    function price0CumulativeLast() external view returns (uint256);

    function price1CumulativeLast() external view returns (uint256);

    function kLast() external view returns (uint256);

    function mint(address to) external returns (uint256 liquidity);

    function burn(address to)
        external
        returns (uint256 amount0, uint256 amount1);

    function swap(
        uint256 amount0Out,
        uint256 amount1Out,
        address to,
        bytes calldata data
    ) external;

    function skim(address to) external;

    function sync() external;

    function initialize(address, address) external;
}

File 3 of 4 : JoeLibrary.sol
//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0;

import '../interfaces/IJoePair.sol';

import "./SafeMath.sol";

library JoeLibrary {
    using SafeMathJoe for uint256;

    // returns sorted token addresses, used to handle return values from pairs sorted in this order
    function sortTokens(address tokenA, address tokenB)
        internal
        pure
        returns (address token0, address token1)
    {
        require(tokenA != tokenB, "JoeLibrary: IDENTICAL_ADDRESSES");
        (token0, token1) = tokenA < tokenB
            ? (tokenA, tokenB)
            : (tokenB, tokenA);
        require(token0 != address(0), "JoeLibrary: ZERO_ADDRESS");
    }

    // calculates the CREATE2 address for a pair without making any external calls
    function pairFor(
        address factory,
        address tokenA,
        address tokenB
    ) internal pure returns (address pair) {
        (address token0, address token1) = sortTokens(tokenA, tokenB);
        pair = address(
            uint256(
                keccak256(
                    abi.encodePacked(
                        hex"ff",
                        factory,
                        keccak256(abi.encodePacked(token0, token1)),
                        hex"0bbca9af0511ad1a1da383135cf3a8d2ac620e549ef9f6ae3a4c33c2fed0af91"
                    )
                )
            )
        );
    }

    // fetches and sorts the reserves for a pair
    function getReserves(
        address factory,
        address tokenA,
        address tokenB
    ) internal view returns (uint256 reserveA, uint256 reserveB) {
        (address token0, ) = sortTokens(tokenA, tokenB);
        (uint256 reserve0, uint256 reserve1, ) = IJoePair(
            pairFor(factory, tokenA, tokenB)
        ).getReserves();
        (reserveA, reserveB) = tokenA == token0
            ? (reserve0, reserve1)
            : (reserve1, reserve0);
    }

    // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
    function quote(
        uint256 amountA,
        uint256 reserveA,
        uint256 reserveB
    ) internal pure returns (uint256 amountB) {
        require(amountA > 0, "JoeLibrary: INSUFFICIENT_AMOUNT");
        require(
            reserveA > 0 && reserveB > 0,
            "JoeLibrary: INSUFFICIENT_LIQUIDITY"
        );
        amountB = amountA.mul(reserveB) / reserveA;
    }

    // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
    function getAmountOut(
        uint256 amountIn,
        uint256 reserveIn,
        uint256 reserveOut
    ) internal pure returns (uint256 amountOut) {
        require(amountIn > 0, "JoeLibrary: INSUFFICIENT_INPUT_AMOUNT");
        require(
            reserveIn > 0 && reserveOut > 0,
            "JoeLibrary: INSUFFICIENT_LIQUIDITY"
        );
        uint256 amountInWithFee = amountIn.mul(997);
        uint256 numerator = amountInWithFee.mul(reserveOut);
        uint256 denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

    // given an output amount of an asset and pair reserves, returns a required input amount of the other asset
    function getAmountIn(
        uint256 amountOut,
        uint256 reserveIn,
        uint256 reserveOut
    ) internal pure returns (uint256 amountIn) {
        require(amountOut > 0, "JoeLibrary: INSUFFICIENT_OUTPUT_AMOUNT");
        require(
            reserveIn > 0 && reserveOut > 0,
            "JoeLibrary: INSUFFICIENT_LIQUIDITY"
        );
        uint256 numerator = reserveIn.mul(amountOut).mul(1000);
        uint256 denominator = reserveOut.sub(amountOut).mul(997);
        amountIn = (numerator / denominator).add(1);
    }

    // performs chained getAmountOut calculations on any number of pairs
    function getAmountsOut(
        address factory,
        uint256 amountIn,
        address[] memory path
    ) internal view returns (uint256[] memory amounts) {
        require(path.length >= 2, "JoeLibrary: INVALID_PATH");
        amounts = new uint256[](path.length);
        amounts[0] = amountIn;
        for (uint256 i; i < path.length - 1; i++) {
            (uint256 reserveIn, uint256 reserveOut) = getReserves(
                factory,
                path[i],
                path[i + 1]
            );
            amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
        }
    }

    // performs chained getAmountIn calculations on any number of pairs
    function getAmountsIn(
        address factory,
        uint256 amountOut,
        address[] memory path
    ) internal view returns (uint256[] memory amounts) {
        require(path.length >= 2, "JoeLibrary: INVALID_PATH");
        amounts = new uint256[](path.length);
        amounts[amounts.length - 1] = amountOut;
        for (uint256 i = path.length - 1; i > 0; i--) {
            (uint256 reserveIn, uint256 reserveOut) = getReserves(
                factory,
                path[i - 1],
                path[i]
            );
            amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
        }
    }
}

File 4 of 4 : SafeMath.sol
pragma solidity >=0.6.12;

// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)

library SafeMathJoe {
    function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x + y) >= x, "ds-math-add-overflow");
    }

    function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x - y) <= x, "ds-math-sub-underflow");
    }

    function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow");
    }
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"_factory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address[]","name":"path","type":"address[]"}],"name":"GetReceiverAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OKSE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"USDC","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WAVAX","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"_to","type":"address"}],"name":"_swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsIn","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"}],"name":"getOptimumPath","outputs":[{"internalType":"address[]","name":"path","type":"address[]"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50604051610e8a380380610e8a8339818101604052602081101561003357600080fd5b5051600080546001600160a01b039092166001600160a01b0319909216919091179055610e25806100656000396000f3fe608060405234801561001057600080fd5b50600436106100785760003560e01c806309bf19181461007d5780631f00ca741461013a5780636c3691d61461023257806373b295c21461026057806389a3027114610268578063c45a015514610270578063dffda16314610278578063f5901d4d14610280575b600080fd5b61011e6004803603602081101561009357600080fd5b810190602081018135600160201b8111156100ad57600080fd5b8201836020820111156100bf57600080fd5b803590602001918460208302840111600160201b831117156100e057600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506103b0945050505050565b604080516001600160a01b039092168252519081900360200190f35b6101e26004803603604081101561015057600080fd5b81359190810190604081016020820135600160201b81111561017157600080fd5b82018360208201111561018357600080fd5b803590602001918460208302840111600160201b831117156101a457600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506103f6945050505050565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561021e578181015183820152602001610206565b505050509050019250505060405180910390f35b6101e26004803603604081101561024857600080fd5b506001600160a01b0381358116916020013516610417565b61011e6105d4565b61011e6105ec565b61011e610604565b61011e610613565b6103ae6004803603606081101561029657600080fd5b810190602081018135600160201b8111156102b057600080fd5b8201836020820111156102c257600080fd5b803590602001918460208302840111600160201b831117156102e357600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561033257600080fd5b82018360208201111561034457600080fd5b803590602001918460208302840111600160201b8311171561036557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550505090356001600160a01b0316915061062b9050565b005b6000805482516103f0916001600160a01b031690849084906103ce57fe5b6020026020010151846001815181106103e357fe5b6020026020010151610838565b92915050565b600054606090610410906001600160a01b031684846108f8565b9392505050565b60606001600160a01b03831673bc7b0223dd16cbc679c0d04ba3f4530d76dfba8714801561046157506001600160a01b03821673b97ef9ef8734c71904d8002f8b6bc66dd9c48a6e145b156105525760408051600380825260808201909252906020820160608036833701905050905073bc7b0223dd16cbc679c0d04ba3f4530d76dfba87816000815181106104a957fe5b60200260200101906001600160a01b031690816001600160a01b03168152505073b31f66aa3c1e785363f0875a1b74e27b85fd66c7816001815181106104eb57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505073b97ef9ef8734c71904d8002f8b6bc66dd9c48a6e8160028151811061052d57fe5b60200260200101906001600160a01b031690816001600160a01b0316815250506103f0565b6040805160028082526060820183529091602083019080368337019050509050828160008151811061058057fe5b60200260200101906001600160a01b031690816001600160a01b03168152505081816001815181106105ae57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505092915050565b73b31f66aa3c1e785363f0875a1b74e27b85fd66c781565b73b97ef9ef8734c71904d8002f8b6bc66dd9c48a6e81565b6000546001600160a01b031681565b73bc7b0223dd16cbc679c0d04ba3f4530d76dfba8781565b60005b60018351038110156108325760008084838151811061064957fe5b602002602001015185846001018151811061066057fe5b60200260200101519150915060006106788383610a40565b509050600087856001018151811061068c57fe5b60200260200101519050600080836001600160a01b0316866001600160a01b0316146106ba578260006106be565b6000835b91509150600060028a510388106106d557886106f9565b6000548a516106f9916001600160a01b03169088908d9060028d019081106103e357fe5b600054909150610713906001600160a01b03168888610838565b6001600160a01b031663022c0d9f84848460006040519080825280601f01601f191660200182016040528015610750576020820181803683370190505b506040518563ffffffff1660e01b815260040180858152602001848152602001836001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b838110156107b85781810151838201526020016107a0565b50505050905090810190601f1680156107e55780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561080757600080fd5b505af115801561081b573d6000803e3d6000fd5b50506001909901985061062e975050505050505050565b50505050565b60008060006108478585610a40565b604080516bffffffffffffffffffffffff19606094851b811660208084019190915293851b81166034830152825160288184030181526048830184528051908501206001600160f81b031960688401529a90941b9093166069840152607d8301989098527f0bbca9af0511ad1a1da383135cf3a8d2ac620e549ef9f6ae3a4c33c2fed0af91609d808401919091528851808403909101815260bd909201909752805196019590952095945050505050565b606060028251101561094c576040805162461bcd60e51b8152602060048201526018602482015277094deca98d2c4e4c2e4f27440929cac82989288bea082a8960431b604482015290519081900360640190fd5b815167ffffffffffffffff8111801561096457600080fd5b5060405190808252806020026020018201604052801561098e578160200160208202803683370190505b50905082816001835103815181106109a257fe5b60209081029190910101528151600019015b8015610a38576000806109f1878660018603815181106109d057fe5b60200260200101518786815181106109e457fe5b6020026020010151610b2f565b91509150610a13848481518110610a0457fe5b60200260200101518383610bf6565b846001850381518110610a2257fe5b60209081029190910101525050600019016109b4565b509392505050565b600080826001600160a01b0316846001600160a01b03161415610aaa576040805162461bcd60e51b815260206004820152601f60248201527f4a6f654c6962726172793a204944454e544943414c5f41444452455353455300604482015290519081900360640190fd5b826001600160a01b0316846001600160a01b031610610aca578284610acd565b83835b90925090506001600160a01b038216610b28576040805162461bcd60e51b81526020600482015260186024820152774a6f654c6962726172793a205a45524f5f4144445245535360401b604482015290519081900360640190fd5b9250929050565b6000806000610b3e8585610a40565b509050600080610b4f888888610838565b6001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015610b8757600080fd5b505afa158015610b9b573d6000803e3d6000fd5b505050506040513d6060811015610bb157600080fd5b5080516020909101516001600160701b0391821693501690506001600160a01b0387811690841614610be4578082610be7565b81815b90999098509650505050505050565b6000808411610c365760405162461bcd60e51b8152600401808060200182810382526026815260200180610df36026913960400191505060405180910390fd5b600083118015610c465750600082115b610c815760405162461bcd60e51b8152600401808060200182810382526022815260200180610dd16022913960400191505060405180910390fd5b6000610c996103e8610c938688610cce565b90610cce565b90506000610cad6103e5610c938689610d31565b9050610cc46001828481610cbd57fe5b0490610d81565b9695505050505050565b6000811580610ce957505080820282828281610ce657fe5b04145b6103f0576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b808203828111156103f0576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b808201828110156103f0576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe4a6f654c6962726172793a20494e53554646494349454e545f4c49515549444954594a6f654c6962726172793a20494e53554646494349454e545f4f55545055545f414d4f554e54a164736f6c6343000706000a0000000000000000000000009ad6c38be94206ca50bb0d90783181662f0cfa10

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

0000000000000000000000009ad6c38be94206ca50bb0d90783181662f0cfa10

-----Decoded View---------------
Arg [0] : _factory (address): 0x9ad6c38be94206ca50bb0d90783181662f0cfa10

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000009ad6c38be94206ca50bb0d90783181662f0cfa10


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.