Skip to content
Verified contractExactUNLICENSED

AtomicSwapperMainnet

Address0xdbdab211c8bd9f9eb0510df284115248bbb042cf
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
No
License
UNLICENSED
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,880,227
Creation transaction
0xfd1ea3a203…68156672c8

lpswap.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

interface IERC20 {
    function balanceOf(address) external view returns (uint256);
    function transfer(address, uint256) external returns (bool);
}

interface IUniswapV2Pair {
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
}

contract AtomicSwapperMainnet {
    address public immutable owner;

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Bukan pemilik");
        _;
    }

    function executeAtomicSwap(address token, address lp, uint256 amountIn) external onlyOwner {
        IERC20(token).transfer(lp, amountIn);

        address token0 = IUniswapV2Pair(lp).token0();
        uint256 amountOut;

        // Membungkus kalkulasi ke dalam block terpisah untuk membersihkan tumpukan memori (stack)
        {
            (uint112 reserve0, uint112 reserve1, ) = IUniswapV2Pair(lp).getReserves();

            uint256 saldoLPSekarang = IERC20(token).balanceOf(lp);
            uint256 reserveTokenAsli = (token == token0) ? uint256(reserve0) : uint256(reserve1);
            uint256 amountInBersih = saldoLPSekarang - reserveTokenAsli;

            uint256 reserveIn = (token == token0) ? uint256(reserve0) : uint256(reserve1);
            uint256 reserveOut = (token == token0) ? uint256(reserve1) : uint256(reserve0);
            
            uint256 amountInWithFee = amountInBersih * 9975;
            uint256 numerator = amountInWithFee * reserveOut;
            uint256 denominator = (reserveIn * 10000) + amountInWithFee;
            amountOut = (numerator / denominator) * 98 / 100; // Slippage 2%
        }

        // Eksekusi swap di luar block setelah variabel pembantu di atas dihapus dari stack
        IUniswapV2Pair(lp).swap(
            (token == token0) ? 0 : amountOut,
            (token == token0) ? amountOut : 0,
            owner,
            new bytes(0)
        );
    }

    function withdrawToken(address _token) external onlyOwner {
        uint256 bal = IERC20(_token).balanceOf(address(this));
        IERC20(_token).transfer(owner, bal);
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.