// Contract: SWP
// Target function: function make_swap(uint256 token_in,uint256 token_out) public
// SPDX-License-Identifier: UNLISCENSED

pragma solidity 0.8.4;

contract SWP {
    struct NFT_offer {
        address nft_address;
        uint256 token_id;
        address trader;
    }
    
    address constant JULIA = 0x6e845bE4ea601B4Dbe98ED1f52b371dca1Dbb2b6; // MAIN NET
    address nft_in  = JULIA;
    address nft_out = JULIA;

    mapping (address => mapping (uint256 => NFT_offer)) swap_offers;

    constructor () {}

    /*
      One has to approve this contract to use his/her `token_offered` before calling this
    */
    function offer_swap(uint256 token_offered, uint256 token_requested) public {
        uint8   verified = 0;
        uint256 j = 0;
        uint256 owned;
        while (verified < 1) {
            owned = IERC721Enumerable(nft_in).tokenOfOwnerByIndex(msg.sender, j);
            if (owned==token_offered) verified++;
            j++;
        }
        require(verified==1);
        require(IERC721Enumerable(nft_in).getApproved(token_offered)==address(this));
        swap_offers[nft_in][token_offered] = NFT_offer(nft_out, token_requested, msg.sender);
    }