// Contract: SWP
// Target function: function make_swap(uint256 token_you_give, uint256 token_you_get) public
// SPDX-License-Identifier: UNLISCENSED

pragma solidity 0.8.4;

// Version 0.2

contract SWP {
    struct NFT_offer {
        address nft_address;
        uint256 token_id;
        address trader;
    }
    
    //address constant JULIA = 0xdd665AFF8C98ee39e4D581caB1e48A1DbE8B055d; // TEST NET
    address constant JULIA = 0x6e845bE4ea601B4Dbe98ED1f52b371dca1Dbb2b6;
    address constant nft_in  = JULIA;
    address constant nft_out = JULIA;

    mapping (address => mapping (uint256 => NFT_offer)) swap_offers;

    event OfferMade(uint256 offered, uint256 requested, address trader);

    constructor () {}

    /*
      One has to approve this contract to use his/her `token_offered` before calling the function
    */
    function offer_swap(uint256 token_offered, uint256 token_requested) public {
        require(IERC721Enumerable(nft_in).ownerOf(token_offered)==msg.sender);
        require(IERC721Enumerable(nft_in).getApproved(token_offered)==address(this) || IERC721Enumerable(nft_in).isApprovedForAll(msg.sender, address(this)) );
        swap_offers[nft_in][token_offered] = NFT_offer(nft_out, token_requested, msg.sender);
        emit OfferMade(token_offered, token_requested, msg.sender);
    }