-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLPToken.sol
91 lines (79 loc) · 2.42 KB
/
LPToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {ERC721} from "./libraries/ERC721.sol";
import {Strings} from "./libraries/Strings.sol";
import {IMidasPair721} from "./interfaces/IMidasPair721.sol";
/// @title Midas LP Token
/// @author midaswap
/// @notice Non-fungible token which wraps the positions of LPs
contract LPToken is ERC721 {
string public name;
string public symbol;
using Strings for uint256;
using Strings for address;
// Factory address
address public immutable factory;
// Pair address
address public pair;
// Token X address
address public tokenX;
// Token Y address
address public tokenY;
// Maintain State of LPT contract
bool public initialized;
constructor(address _factory) {
factory = _factory;
initialized = false;
}
function initialize(
address _pair,
address _tokenX,
address _tokenY,
string calldata _name,
string calldata _symbol
) external virtual {
require(msg.sender == factory);
require(initialized == false);
pair = _pair;
tokenX = _tokenX;
tokenY = _tokenY;
name = _name;
symbol = _symbol;
initialized = true;
}
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
require(_ownerOf[tokenId] != address(0));
string memory baseURI = _baseURI();
return
bytes(baseURI).length > 0
? string(
abi.encodePacked(
baseURI,
tokenX.toHexString(),
"/",
tokenY.toHexString(),
"/",
tokenId.toString()
)
)
: "";
}
function mint(address to, uint256 tokenId) external virtual {
require(msg.sender == pair);
_mint(to, tokenId);
}
function burn(uint256 tokenId) external virtual {
require(msg.sender == pair);
_burn(tokenId);
}
function _baseURI() internal view virtual returns (string memory) {
return "npapi.midaswap.info/metadata/v1/";
}
function getReserves(
uint128 tokenId
) external view virtual returns (uint128 xReserves, uint128 yReserves) {
(xReserves, yReserves) = IMidasPair721(pair).getLpReserve(tokenId);
}
}