-
Notifications
You must be signed in to change notification settings - Fork 2
/
URIInfo.sol
106 lines (95 loc) · 3.19 KB
/
URIInfo.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.7;
import '@openzeppelin/contracts/utils/Strings.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/utils/Strings.sol';
import './HexStrings.sol';
library URIInfo {
using HexStrings for uint256;
function generateURIName(address liquidityToken)
internal
view
returns (string memory)
{
string memory name = 'Ethereum';
string memory symbol = 'ETH';
if (liquidityToken != address(0)) {
name = ERC20(liquidityToken).name();
symbol = ERC20(liquidityToken).symbol();
}
return
string(
abi.encodePacked(
'MetalSwap - ',
escapeQuotes(name),
' - ',
escapeQuotes(symbol)
)
);
}
function generateURIDescription(
address liquidityToken,
address liquidityPool,
address currentOwner,
uint256 tokenId,
uint256 currentLiquidity
) internal view returns (string memory) {
string memory symbol = 'ETH';
if (liquidityToken != address(0)) {
symbol = ERC20(liquidityToken).symbol();
}
return
string(
abi.encodePacked(
'This NFT represents a liquidity position in the ',
escapeQuotes(symbol),
' MetalSwap liquidity pool. ',
'The owner of this NFT can modify or redeem the position.\\n',
'\\nCurrent owner: ',
addressToString(currentOwner),
'\\nCurrent liquidity: ',
Strings.toString(currentLiquidity),
'\\nPool Address: ',
addressToString(liquidityPool),
'\\nToken ID: ',
Strings.toString(tokenId),
'\\n\\n',
unicode'⚠️ DISCLAIMER: Due diligence is imperative when assessing this NFT. Make sure token address match the expected tokens, as token symbols may be imitated.'
)
);
}
function escapeQuotes(string memory symbol)
internal
pure
returns (string memory)
{
bytes memory symbolBytes = bytes(symbol);
uint8 quotesCount = 0;
for (uint8 i = 0; i < symbolBytes.length; i++) {
if (symbolBytes[i] == '"') {
quotesCount++;
}
}
if (quotesCount > 0) {
bytes memory escapedBytes = new bytes(
symbolBytes.length + (quotesCount)
);
uint256 index;
for (uint8 i = 0; i < symbolBytes.length; i++) {
if (symbolBytes[i] == '"') {
escapedBytes[index++] = '\\';
}
escapedBytes[index++] = symbolBytes[i];
}
return string(escapedBytes);
}
return symbol;
}
function addressToString(address addr)
internal
pure
returns (string memory)
{
return (uint256(uint160(addr))).toHexString(20);
}
}