Skip to content

Commit

Permalink
add animation_url property to the STokens metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
aggre committed Aug 5, 2024
1 parent 289c303 commit b0fc4e8
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 15 deletions.
17 changes: 17 additions & 0 deletions contracts/interface/ITokenURIDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ interface ITokenURIDescriptor {
bytes32 _payload
) external view returns (string memory);

/*
* @dev get animation_url from custom descriptor
* @param _tokenId token id
* @param _owner owner address
* @param _positions staking position
* @param _rewards rewards
* @param _payload token payload
* @return string image information
*/
function animationUrl(
uint256 _tokenId,
address _owner,
ISTokensManager.StakingPositions memory _positions,
ISTokensManager.Rewards memory _rewards,
bytes32 _payload
) external view returns (string memory);

/*
* @dev get name from custom descriptor
* @param _tokenId token id
Expand Down
40 changes: 33 additions & 7 deletions contracts/src/s-token/STokensDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,30 @@ contract STokensDescriptor {
}

function getTokenURI(
address _property,
uint256 _amount,
uint256 _cumulativeReward,
string memory _tokenUriImage,
string memory _tokenUriName,
string memory _tokenUriDescription,
bytes32 _payload
bytes memory _props
) internal pure returns (string memory) {
(
address _property,
uint256 _amount,
uint256 _cumulativeReward,
string memory _tokenUriImage,
string memory _tokenUriName,
string memory _tokenUriDescription,
string memory _tokenUriAnimationUrl,
bytes32 _payload
) = abi.decode(
_props,
(
address,
uint256,
uint256,
string,
string,
string,
string,
bytes32
)
);
string memory amount = _amount.decimalString(18);
string memory name = bytes(_tokenUriName).length == 0
? string(
Expand Down Expand Up @@ -244,6 +260,15 @@ contract STokensDescriptor {
)
)
: _tokenUriImage;
string memory animationUrl = bytes(_tokenUriAnimationUrl).length == 0
? string("")
: string(
abi.encodePacked(
// solhint-disable-next-line quotes
'", "animation_url":"',
_tokenUriAnimationUrl
)
);
return
string(
abi.encodePacked(
Expand All @@ -259,6 +284,7 @@ contract STokensDescriptor {
// solhint-disable-next-line quotes
'", "image": "',
image,
animationUrl,
// solhint-disable-next-line quotes
'", "attributes":',
attributes,
Expand Down
31 changes: 24 additions & 7 deletions contracts/src/s-token/STokensManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ contract STokensManager is
string memory _tokenUriImage = tokenUriImage[_tokenId];
string memory _tokenUriName;
string memory _tokenUriDescription;
string memory _tokenUriAnimationUrl;
address descriptor = descriptorOfPropertyByPayload[_positions.property][
_payload
] == address(0)
Expand Down Expand Up @@ -352,16 +353,32 @@ contract STokensManager is
} catch {
_tokenUriDescription = "";
}
try
ITokenURIDescriptor(descriptor).animationUrl(
_tokenId,
_owner,
_positions,
_rewardsArg,
_payload
)
returns (string memory _animation_url) {
_tokenUriAnimationUrl = _animation_url;
} catch {
_tokenUriAnimationUrl = "";
}
}
return
getTokenURI(
_positions.property,
_positions.amount,
_positions.cumulativeReward,
_tokenUriImage,
_tokenUriName,
_tokenUriDescription,
_payload
abi.encode(
_positions.property,
_positions.amount,
_positions.cumulativeReward,
_tokenUriImage,
_tokenUriName,
_tokenUriDescription,
_tokenUriAnimationUrl,
_payload
)
);
}

Expand Down
11 changes: 11 additions & 0 deletions contracts/test/stoken/TokenURIDescriptorCopyTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ contract TokenURIDescriptorCopyTest is ITokenURIDescriptor {
string public newName = "";
string public newDescription = "";
string public newImage = "dummy-string";
string public newAnimationUrl = "dummy-string";

function image(
uint256,
Expand All @@ -20,6 +21,16 @@ contract TokenURIDescriptorCopyTest is ITokenURIDescriptor {
return newImage;
}

function animationUrl(
uint256,
address,
ISTokensManager.StakingPositions memory,
ISTokensManager.Rewards memory,
bytes32
) external view override returns (string memory) {
return newAnimationUrl;
}

function onBeforeMint(
uint256 _tokenId,
address,
Expand Down
11 changes: 11 additions & 0 deletions contracts/test/stoken/TokenURIDescriptorTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ contract TokenURIDescriptorTest is ITokenURIDescriptor {
string public newName = "";
string public newDescription = "";
string public newImage = "dummy-string";
string public newAnimationUrl = "dummy-string";

function image(
uint256,
Expand All @@ -20,6 +21,16 @@ contract TokenURIDescriptorTest is ITokenURIDescriptor {
return newImage;
}

function animationUrl(
uint256,
address,
ISTokensManager.StakingPositions memory,
ISTokensManager.Rewards memory,
bytes32
) external view returns (string memory) {
return newAnimationUrl;
}

function onBeforeMint(
uint256 _tokenId,
address,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@
version "0.2.0"
resolved "https://codeload.github.com/trufflesuite/filecoin-signing-tools-js/tar.gz/2786fdb8a2b71bd1c7789c0701da41bb644a098f"
dependencies:
axios "^0.20.0"
axios "0.26.1"
base32-decode "^1.0.0"
base32-encode "^1.1.1"
bip32 "^2.0.5"
Expand Down

0 comments on commit b0fc4e8

Please sign in to comment.