Skip to content

Supports optional animation_url #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions contracts/interface/ITokenURIDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// solhint-disable-next-line compiler-version
pragma solidity ^0.8.0;

import "./ISTokensManager.sol";

Check warning on line 5 in contracts/interface/ITokenURIDescriptor.sol

View workflow job for this annotation

GitHub Actions / build (14.x)

global import of path ./ISTokensManager.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

interface ITokenURIDescriptor {
/*
Expand All @@ -22,6 +22,23 @@
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
10 changes: 10 additions & 0 deletions contracts/test/stoken/TokenURIDescriptorCopyTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ contract TokenURIDescriptorCopyTest is ITokenURIDescriptor {
return newImage;
}

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

function onBeforeMint(
uint256 _tokenId,
address,
Expand Down
15 changes: 15 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-animation-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 Expand Up @@ -50,6 +61,10 @@ contract TokenURIDescriptorTest is ITokenURIDescriptor {
newImage = _imageURI;
}

function _setAnimationUrl(string memory _animationUrl) public {
newAnimationUrl = _animationUrl;
}

function name(
uint256,
address,
Expand Down
46 changes: 41 additions & 5 deletions test/s-token/s-token-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Details = {
description: string
image: string
attributes: Attributes
animation_url?: string
}

contract('STokensManager', ([deployer, user]) => {
Expand Down Expand Up @@ -117,7 +118,8 @@ contract('STokensManager', ([deployer, user]) => {
amount: number | string,
cumulativeReward: number,
payload: string,
tokenUriImage = ''
tokenUriImage = '',
tokenUriAnimationUrl = ''
): void => {
const uriInfo = tokenUri.split(',')
expect(uriInfo.length).to.equal(2)
Expand All @@ -127,16 +129,20 @@ contract('STokensManager', ([deployer, user]) => {
name: string
description: string
image: string
animation_url: string
attributes: Attributes
}
const { name, description, image } = details
const { name, description, image, animation_url } = details
checkName(name, property, amount, cumulativeReward)
checkDescription(description, property)
checkAttributes(details.attributes, property, amount, payload)
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
tokenUriImage === ''
? checkImage(image, property)
: checkTokenImageUri(image, tokenUriImage)
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
tokenUriAnimationUrl !== '' &&
checkTokenAnimationUrl(animation_url, tokenUriAnimationUrl)
}

const getdetails = (tokenUri: string): Details => {
Expand All @@ -148,6 +154,7 @@ contract('STokensManager', ([deployer, user]) => {
name: string
description: string
image: string
animation_url?: string
attributes: Attributes
}
return details
Expand Down Expand Up @@ -187,6 +194,13 @@ contract('STokensManager', ([deployer, user]) => {
expect(image).to.equal(tokenUriImage)
}

const checkTokenAnimationUrl = (
animationUrl: string,
tokenUriAnimationUrl: string
): void => {
expect(animationUrl).to.equal(tokenUriAnimationUrl)
}

const checkAttributes = (
attributes: Attributes,
property: string,
Expand Down Expand Up @@ -273,7 +287,7 @@ contract('STokensManager', ([deployer, user]) => {
'ipfs://IPFS-CID'
)
})
it('get descriptor token uri; with custom name & description check', async () => {
it('get descriptor token uri; with custom name, animation_url & description check', async () => {
// @ts-ignore
await dev.lockup.depositToProperty(
property.address,
Expand All @@ -294,15 +308,37 @@ contract('STokensManager', ([deployer, user]) => {
10000,
0,
web3.utils.keccak256('ADDITIONAL_BYTES'),
'dummy-string'
'dummy-string',
'dummy-animation-string'
)
// This checks for custom name & description
await descriptor._setName('new-name')
await descriptor._setDescription('new-description')
await descriptor._setAnimationUrl('new-animation')
const recheckURI = await dev.sTokensManager.tokenURI(1)
const { name, description } = getdetails(recheckURI)
const { name, description, animation_url } = getdetails(recheckURI)
expect(name).to.equal('new-name')
expect(description).to.equal('new-description')
expect(animation_url).to.equal('new-animation')
})
it('returns tokenURI without animation_url if it is not set', async () => {
// @ts-ignore
await dev.lockup.depositToProperty(
property.address,
'10000',
web3.utils.keccak256('ADDITIONAL_BYTES')
)
await dev.sTokensManager.setTokenURIDescriptor(
property.address,
descriptor.address,
[web3.utils.keccak256('ADDITIONAL_BYTES')],
{ from: user }
)
await descriptor._setAnimationUrl('')
const { animation_url } = getdetails(
await dev.sTokensManager.tokenURI(1)
)
expect(animation_url).to.equal(undefined)
})
it('get token uri for legacy descriptors; without custom name & description', async () => {
// @ts-ignore
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
Loading