Skip to content
Verified contractExactMIT

WrappedLand

Address0x5eba37eb6cffdd87f003ac617e469192827e599b
Balance

0 ETH

 

Transactions

87

 

Compiler

solc 0.8.20

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 200 runs
EVM version
shanghai
License
MIT
Match
Exactcreation code: no, runtime code: yes
Verified on Sourcify
Created in block
19,235,648

src/WrappedLand.sol

// https://farmland.build/
// https://twitter.com/landERC20721
// https://t.me/Land_Erc20721

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface Callable {
  function tokenCallback(
    address _from,
    uint256 _tokens,
    bytes calldata _data
  ) external returns (bool);
}

interface ILand {
  function balanceOf(address) external view returns (uint256);
  function allowance(address, address) external view returns (uint256);
  function isApprovedForAll(address, address) external view returns (bool);
  function transfer(address _to, uint256 _tokens) external returns (bool);
  function transferFrom(
    address _from,
    address _to,
    uint256 _tokens
  ) external returns (bool);
}

contract WrappedLand {
  uint256 private constant UINT_MAX = type(uint256).max;

  ILand public immutable land;

  string public constant name = "Wrapped Land";
  string public constant symbol = "wLAND";
  uint8 public constant decimals = 18;

  struct User {
    uint256 balance;
    mapping(address => uint256) allowance;
  }

  struct Info {
    mapping(address => User) users;
  }
  Info private info;

  event Transfer(address indexed from, address indexed to, uint256 tokens);
  event Approval(
    address indexed owner,
    address indexed spender,
    uint256 tokens
  );
  event Wrap(address indexed owner, uint256 tokens);
  event Unwrap(address indexed owner, uint256 tokens);

  constructor(address _land) {
    land = ILand(_land);
  }

  function wrap(uint256 _tokensOrTokenId) external {
    uint256 _balanceBefore = land.balanceOf(address(this));
    land.transferFrom(msg.sender, address(this), _tokensOrTokenId);
    uint256 _wrapped = land.balanceOf(address(this)) - _balanceBefore;
    require(_wrapped > 0);
    info.users[msg.sender].balance += _wrapped * 1e18;
    emit Transfer(address(0x0), msg.sender, _wrapped * 1e18);
    emit Wrap(msg.sender, _wrapped);
  }

  function unwrap(uint256 _tokens) external {
    require(_tokens > 0);
    require(balanceOf(msg.sender) >= _tokens * 1e18);
    info.users[msg.sender].balance -= _tokens * 1e18;
    land.transfer(msg.sender, _tokens);
    emit Transfer(msg.sender, address(0x0), _tokens * 1e18);
    emit Unwrap(msg.sender, _tokens);
  }

  function transfer(address _to, uint256 _tokens) external returns (bool) {
    return _transfer(msg.sender, _to, _tokens);
  }

  function approve(address _spender, uint256 _tokens) external returns (bool) {
    info.users[msg.sender].allowance[_spender] = _tokens;
    emit Approval(msg.sender, _spender, _tokens);
    return true;
  }

  function transferFrom(
    address _from,
    address _to,
    uint256 _tokens
  ) external returns (bool) {
    uint256 _allowance = allowance(_from, msg.sender);
    require(_allowance >= _tokens);
    if (_allowance != UINT_MAX) {
      info.users[_from].allowance[msg.sender] -= _tokens;
    }
    return _transfer(_from, _to, _tokens);
  }

  function transferAndCall(
    address _to,
    uint256 _tokens,
    bytes calldata _data
  ) external returns (bool) {
    _transfer(msg.sender, _to, _tokens);
    uint32 _size;
    assembly {
      _size := extcodesize(_to)
    }
    if (_size > 0) {
      require(Callable(_to).tokenCallback(msg.sender, _tokens, _data));
    }
    return true;
  }

  function totalSupply() public view returns (uint256) {
    return land.balanceOf(address(this)) * 1e18;
  }

  function balanceOf(address _user) public view returns (uint256) {
    return info.users[_user].balance;
  }

  function allowance(
    address _user,
    address _spender
  ) public view returns (uint256) {
    return info.users[_user].allowance[_spender];
  }

  function allInfoFor(
    address _user
  )
    external
    view
    returns (
      uint256 totalTokens,
      uint256 userLANDs,
      uint256 userAllowance,
      bool userApprovedForAll,
      uint256 userBalance
    )
  {
    totalTokens = totalSupply();
    userLANDs = land.balanceOf(_user);
    userAllowance = land.allowance(_user, address(this));
    userApprovedForAll = land.isApprovedForAll(_user, address(this));
    userBalance = balanceOf(_user);
  }

  function _transfer(
    address _from,
    address _to,
    uint256 _tokens
  ) internal returns (bool) {
    unchecked {
      require(balanceOf(_from) >= _tokens);
      info.users[_from].balance -= _tokens;
      info.users[_to].balance += _tokens;
      emit Transfer(_from, _to, _tokens);
      return true;
    }
  }
}
Compiler settingsShow
{
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "shanghai",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.