Skip to content

Commit 477d405

Browse files
Reopen: Fix: tokenURI for old descriptors (#562)
* fix: name & description dependecy on tokenUriImage * deployed: fix * fix name & descrip dependecy on tokenUriImage & new implementation (#549) * fix: name & description dependecy on tokenUriImage * deployed: fix * deloyed on polygon/arbitrum * fix: legacy descriptor * fix: legacy descriptor * deploy fix: legacy descriptor --------- Co-authored-by: Shubham Kukreti <57281769+KukretiShubham@users.noreply.github.com>
1 parent f418a05 commit 477d405

File tree

5 files changed

+367
-23
lines changed

5 files changed

+367
-23
lines changed

.openzeppelin/polygon-mumbai.json

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,264 @@
14011401
}
14021402
}
14031403
}
1404+
},
1405+
"97cca0d6cf8b34e4951855f717569e9dbad4fea735abd437f0fe60ead091a458": {
1406+
"address": "0x1DD06Da669E411c8147AfcBAFa6B9a1146B11539",
1407+
"txHash": "0xcdaf1982ce5a6212e28e457351546d3fc01e8c8b6d24fc4facc545d019e0d0b4",
1408+
"layout": {
1409+
"solcVersion": "0.8.9",
1410+
"storage": [
1411+
{
1412+
"contract": "Initializable",
1413+
"label": "_initialized",
1414+
"type": "t_bool",
1415+
"src": "../@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:21"
1416+
},
1417+
{
1418+
"contract": "Initializable",
1419+
"label": "_initializing",
1420+
"type": "t_bool",
1421+
"src": "../@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:26"
1422+
},
1423+
{
1424+
"contract": "ContextUpgradeable",
1425+
"label": "__gap",
1426+
"type": "t_array(t_uint256)50_storage",
1427+
"src": "../@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:30"
1428+
},
1429+
{
1430+
"contract": "ERC165Upgradeable",
1431+
"label": "__gap",
1432+
"type": "t_array(t_uint256)50_storage",
1433+
"src": "../@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol:35"
1434+
},
1435+
{
1436+
"contract": "ERC721Upgradeable",
1437+
"label": "_name",
1438+
"type": "t_string_storage",
1439+
"src": "../@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol:24"
1440+
},
1441+
{
1442+
"contract": "ERC721Upgradeable",
1443+
"label": "_symbol",
1444+
"type": "t_string_storage",
1445+
"src": "../@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol:27"
1446+
},
1447+
{
1448+
"contract": "ERC721Upgradeable",
1449+
"label": "_owners",
1450+
"type": "t_mapping(t_uint256,t_address)",
1451+
"src": "../@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol:30"
1452+
},
1453+
{
1454+
"contract": "ERC721Upgradeable",
1455+
"label": "_balances",
1456+
"type": "t_mapping(t_address,t_uint256)",
1457+
"src": "../@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol:33"
1458+
},
1459+
{
1460+
"contract": "ERC721Upgradeable",
1461+
"label": "_tokenApprovals",
1462+
"type": "t_mapping(t_uint256,t_address)",
1463+
"src": "../@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol:36"
1464+
},
1465+
{
1466+
"contract": "ERC721Upgradeable",
1467+
"label": "_operatorApprovals",
1468+
"type": "t_mapping(t_address,t_mapping(t_address,t_bool))",
1469+
"src": "../@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol:39"
1470+
},
1471+
{
1472+
"contract": "ERC721Upgradeable",
1473+
"label": "__gap",
1474+
"type": "t_array(t_uint256)44_storage",
1475+
"src": "../@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol:418"
1476+
},
1477+
{
1478+
"contract": "InitializableUsingRegistry",
1479+
"label": "_registry",
1480+
"type": "t_address",
1481+
"src": "../project:/contracts/src/common/registry/InitializableUsingRegistry.sol:11"
1482+
},
1483+
{
1484+
"contract": "STokensManager",
1485+
"label": "tokenIdCounter",
1486+
"type": "t_struct(Counter)6513_storage",
1487+
"src": "../project:/contracts/src/s-token/STokensManager.sol:25"
1488+
},
1489+
{
1490+
"contract": "STokensManager",
1491+
"label": "bytesStorage",
1492+
"type": "t_mapping(t_bytes32,t_bytes_storage)",
1493+
"src": "../project:/contracts/src/s-token/STokensManager.sol:26"
1494+
},
1495+
{
1496+
"contract": "STokensManager",
1497+
"label": "tokenIdsMapOfProperty",
1498+
"type": "t_mapping(t_address,t_array(t_uint256)dyn_storage)",
1499+
"src": "../project:/contracts/src/s-token/STokensManager.sol:27"
1500+
},
1501+
{
1502+
"contract": "STokensManager",
1503+
"label": "tokenIdsMapOfOwner",
1504+
"type": "t_mapping(t_address,t_struct(UintSet)7325_storage)",
1505+
"src": "../project:/contracts/src/s-token/STokensManager.sol:28"
1506+
},
1507+
{
1508+
"contract": "STokensManager",
1509+
"label": "tokenUriImage",
1510+
"type": "t_mapping(t_uint256,t_string_storage)",
1511+
"src": "../project:/contracts/src/s-token/STokensManager.sol:29"
1512+
},
1513+
{
1514+
"contract": "STokensManager",
1515+
"label": "isFreezed",
1516+
"type": "t_mapping(t_uint256,t_bool)",
1517+
"src": "../project:/contracts/src/s-token/STokensManager.sol:30"
1518+
},
1519+
{
1520+
"contract": "STokensManager",
1521+
"label": "descriptorOf",
1522+
"type": "t_mapping(t_address,t_address)",
1523+
"src": "../project:/contracts/src/s-token/STokensManager.sol:31"
1524+
},
1525+
{
1526+
"contract": "STokensManager",
1527+
"label": "payloadOf",
1528+
"type": "t_mapping(t_uint256,t_bytes32)",
1529+
"src": "../project:/contracts/src/s-token/STokensManager.sol:32"
1530+
},
1531+
{
1532+
"contract": "STokensManager",
1533+
"label": "proxyAdmin",
1534+
"type": "t_address",
1535+
"src": "../project:/contracts/src/s-token/STokensManager.sol:33"
1536+
},
1537+
{
1538+
"contract": "STokensManager",
1539+
"label": "royaltyOf",
1540+
"type": "t_mapping(t_address,t_uint24)",
1541+
"src": "../project:/contracts/src/s-token/STokensManager.sol:35"
1542+
},
1543+
{
1544+
"contract": "STokensManager",
1545+
"label": "descriptorOfPropertyByPayload",
1546+
"type": "t_mapping(t_address,t_mapping(t_bytes32,t_address))",
1547+
"src": "../project:/contracts/src/s-token/STokensManager.sol:36"
1548+
}
1549+
],
1550+
"types": {
1551+
"t_struct(Counter)6513_storage": {
1552+
"label": "struct Counters.Counter",
1553+
"members": [
1554+
{
1555+
"label": "_value",
1556+
"type": "t_uint256"
1557+
}
1558+
]
1559+
},
1560+
"t_uint256": {
1561+
"label": "uint256"
1562+
},
1563+
"t_mapping(t_bytes32,t_bytes_storage)": {
1564+
"label": "mapping(bytes32 => bytes)"
1565+
},
1566+
"t_bytes32": {
1567+
"label": "bytes32"
1568+
},
1569+
"t_bytes_storage": {
1570+
"label": "bytes"
1571+
},
1572+
"t_mapping(t_address,t_array(t_uint256)dyn_storage)": {
1573+
"label": "mapping(address => uint256[])"
1574+
},
1575+
"t_address": {
1576+
"label": "address"
1577+
},
1578+
"t_array(t_uint256)dyn_storage": {
1579+
"label": "uint256[]"
1580+
},
1581+
"t_mapping(t_address,t_struct(UintSet)7325_storage)": {
1582+
"label": "mapping(address => struct EnumerableSet.UintSet)"
1583+
},
1584+
"t_struct(UintSet)7325_storage": {
1585+
"label": "struct EnumerableSet.UintSet",
1586+
"members": [
1587+
{
1588+
"label": "_inner",
1589+
"type": "t_struct(Set)6867_storage"
1590+
}
1591+
]
1592+
},
1593+
"t_struct(Set)6867_storage": {
1594+
"label": "struct EnumerableSet.Set",
1595+
"members": [
1596+
{
1597+
"label": "_values",
1598+
"type": "t_array(t_bytes32)dyn_storage"
1599+
},
1600+
{
1601+
"label": "_indexes",
1602+
"type": "t_mapping(t_bytes32,t_uint256)"
1603+
}
1604+
]
1605+
},
1606+
"t_array(t_bytes32)dyn_storage": {
1607+
"label": "bytes32[]"
1608+
},
1609+
"t_mapping(t_bytes32,t_uint256)": {
1610+
"label": "mapping(bytes32 => uint256)"
1611+
},
1612+
"t_mapping(t_uint256,t_string_storage)": {
1613+
"label": "mapping(uint256 => string)"
1614+
},
1615+
"t_string_storage": {
1616+
"label": "string"
1617+
},
1618+
"t_mapping(t_uint256,t_bool)": {
1619+
"label": "mapping(uint256 => bool)"
1620+
},
1621+
"t_bool": {
1622+
"label": "bool"
1623+
},
1624+
"t_mapping(t_address,t_address)": {
1625+
"label": "mapping(address => address)"
1626+
},
1627+
"t_mapping(t_uint256,t_bytes32)": {
1628+
"label": "mapping(uint256 => bytes32)"
1629+
},
1630+
"t_mapping(t_address,t_uint24)": {
1631+
"label": "mapping(address => uint24)"
1632+
},
1633+
"t_uint24": {
1634+
"label": "uint24"
1635+
},
1636+
"t_mapping(t_address,t_mapping(t_bytes32,t_address))": {
1637+
"label": "mapping(address => mapping(bytes32 => address))"
1638+
},
1639+
"t_mapping(t_bytes32,t_address)": {
1640+
"label": "mapping(bytes32 => address)"
1641+
},
1642+
"t_mapping(t_uint256,t_address)": {
1643+
"label": "mapping(uint256 => address)"
1644+
},
1645+
"t_mapping(t_address,t_uint256)": {
1646+
"label": "mapping(address => uint256)"
1647+
},
1648+
"t_mapping(t_address,t_mapping(t_address,t_bool))": {
1649+
"label": "mapping(address => mapping(address => bool))"
1650+
},
1651+
"t_mapping(t_address,t_bool)": {
1652+
"label": "mapping(address => bool)"
1653+
},
1654+
"t_array(t_uint256)44_storage": {
1655+
"label": "uint256[44]"
1656+
},
1657+
"t_array(t_uint256)50_storage": {
1658+
"label": "uint256[50]"
1659+
}
1660+
}
1661+
}
14041662
}
14051663
}
14061664
}

contracts/src/s-token/STokensManager.sol

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -307,34 +307,51 @@ contract STokensManager is
307307
string memory _tokenUriDescription;
308308
address descriptor = descriptorOfPropertyByPayload[_positions.property][
309309
_payload
310-
];
311-
if (descriptor == address(0)) {
312-
descriptor = descriptorOf[_positions.property];
313-
}
310+
] == address(0)
311+
? descriptorOf[_positions.property]
312+
: descriptorOfPropertyByPayload[_positions.property][_payload];
314313
if (descriptor != address(0)) {
315314
if (bytes(_tokenUriImage).length == 0) {
316-
_tokenUriImage = ITokenURIDescriptor(descriptor).image(
315+
try
316+
ITokenURIDescriptor(descriptor).image(
317+
_tokenId,
318+
_owner,
319+
_positions,
320+
_rewardsArg,
321+
_payload
322+
)
323+
returns (string memory _image) {
324+
_tokenUriImage = _image;
325+
} catch {
326+
_tokenUriImage = "";
327+
}
328+
}
329+
try
330+
ITokenURIDescriptor(descriptor).name(
317331
_tokenId,
318332
_owner,
319333
_positions,
320334
_rewardsArg,
321335
_payload
322-
);
336+
)
337+
returns (string memory _name) {
338+
_tokenUriName = _name;
339+
} catch {
340+
_tokenUriName = "";
341+
}
342+
try
343+
ITokenURIDescriptor(descriptor).description(
344+
_tokenId,
345+
_owner,
346+
_positions,
347+
_rewardsArg,
348+
_payload
349+
)
350+
returns (string memory _description) {
351+
_tokenUriDescription = _description;
352+
} catch {
353+
_tokenUriDescription = "";
323354
}
324-
_tokenUriName = ITokenURIDescriptor(descriptor).name(
325-
_tokenId,
326-
_owner,
327-
_positions,
328-
_rewardsArg,
329-
_payload
330-
);
331-
_tokenUriDescription = ITokenURIDescriptor(descriptor).description(
332-
_tokenId,
333-
_owner,
334-
_positions,
335-
_rewardsArg,
336-
_payload
337-
);
338355
}
339356
return
340357
getTokenURI(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
pragma solidity =0.8.9;
3+
4+
import "../../interface/ISTokensManager.sol";
5+
6+
contract TokenURIDescriptorLegacyTest {
7+
mapping(uint256 => bytes32) public _dataOf;
8+
bool public shouldBe = true;
9+
string public newImage = "dummy-string";
10+
11+
function image(
12+
uint256,
13+
address,
14+
ISTokensManager.StakingPositions memory,
15+
ISTokensManager.Rewards memory,
16+
bytes32
17+
) external view returns (string memory) {
18+
return newImage;
19+
}
20+
21+
function onBeforeMint(
22+
uint256 _tokenId,
23+
address,
24+
ISTokensManager.StakingPositions memory,
25+
bytes32 _payload
26+
) external returns (bool) {
27+
_dataOf[_tokenId] = _payload;
28+
return shouldBe;
29+
}
30+
31+
function dataOf(uint256 _tokenId) external view returns (bytes32) {
32+
return _dataOf[_tokenId];
33+
}
34+
35+
function __shouldBe(bool _bool) public {
36+
shouldBe = _bool;
37+
}
38+
39+
function _setImageURI(string memory _imageURI) public {
40+
newImage = _imageURI;
41+
}
42+
}

0 commit comments

Comments
 (0)