Skip to content

Commit

Permalink
Fixed metadata, added ERC1155Metadata InterfaceId support
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 committed Aug 4, 2023
1 parent b2b414f commit 40e6b56
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 31 deletions.
3 changes: 3 additions & 0 deletions protocol/contracts/beanstalk/init/InitDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ contract InitDiamond {
ds.supportedInterfaces[type(IERC165).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true;
ds.supportedInterfaces[0xd9b67a26] = true; // ERC1155
ds.supportedInterfaces[0x0e89341c] = true; // ERC1155Metadata


C.bean().approve(C.CURVE_BEAN_METAPOOL, type(uint256).max);
C.bean().approve(C.curveZapAddress(), type(uint256).max);
Expand Down
27 changes: 15 additions & 12 deletions protocol/contracts/beanstalk/metadata/MetadataFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
pragma solidity ^0.7.6;
pragma experimental ABIEncoderV2;

import {LibLegacyTokenSilo} from "contracts/libraries/Silo/LibLegacyTokenSilo.sol";
import "./MetadataImage.sol";
import "contracts/mocks/MockERC1155.sol";
import {LibBytes} from "contracts/libraries/LibBytes.sol";
import {LibTokenSilo} from "contracts/libraries/Silo/LibTokenSilo.sol";


/**
Expand All @@ -31,24 +33,25 @@ contract MetadataFacet is MetadataImage {
* Deposits are stored as a mapping of a uint256 to a Deposit struct.
* ERC20 deposits are represented by the concatination of the token address and the stem. (20 + 12 bytes).
*/
function uri(uint256 depositId) external view returns (string memory) {
function uri(uint256 depositId) public view returns (string memory) {
(address token, int96 stem) = LibBytes.unpackAddressAndStem(depositId);
int96 stemTip = LibTokenSilo.stemTipForToken(token);
require(token != address(0), "Silo: metadata does not exist");
bytes memory attributes = abi.encodePacked(
'\n\nToken Symbol: ', getTokenName(token),
'\nToken Address: ', LibStrings.toHexString(uint256(token), 20),
'\nId: ', depositId.toHexString(32),
'\nDeposit stem: ', int256(stem).toString(),
'\nDeposit inital stalk per BDV: ', uint256(LibTokenSilo.stalkIssuedPerBdv(token)).toString(),
'\nDeposit grown stalk per BDV": ', uint256(LibTokenSilo.stemTipForToken(token) - stem).toString(),
'\nDeposit seeds per BDV": ', uint256(LibLegacyTokenSilo.getSeedsPerToken(token)).toString(),
'\n\nDISCLAIMER: Due diligence is imperative when assessing this NFT. Opensea and other NFT marketplaces cache the svg output and thus, may require the user to refresh the metadata to properly show the correct values."'
'\\n\\nToken Symbol: ', getTokenName(token),
'\\nToken Address: ', LibStrings.toHexString(uint256(token), 20),
'\\nId: ', depositId.toHexString(32),
'\\nstem: ', int256(stem).toString(),
'\\ninital stalk per BDV: ', uint256(LibTokenSilo.stalkIssuedPerBdv(token)).toString(),
'\\ngrown stalk per BDV: ', uint256(stemTip - stem).toString(),
'\\nstalk grown per BDV per season: ', uint256(LibTokenSilo.stalkEarnedPerSeason(token)).toString(),
'\\n\\nDISCLAIMER: Due diligence is imperative when assessing this NFT. Opensea and other NFT marketplaces cache the svg output and thus, may require the user to refresh the metadata to properly show the correct values."'
);
return string(abi.encodePacked("data:application/json;base64,",LibBytes64.encode(abi.encodePacked(
'{',
'"name": "Beanstalk Deposit", "description": "A Beanstalk Deposit.',
'"name": "Beanstalk Silo Deposits", "description": "An ERC1155 representing an asset deposited in the Beanstalk Silo. Silo Deposits gain stalk and bean seignorage.',
attributes,
string(abi.encodePacked(', "image": "', imageURI(depositId), '"')),
string(abi.encodePacked(', "image": "', imageURI(token, stem, stemTip), '"')),
'}'
))
));
Expand Down
21 changes: 11 additions & 10 deletions protocol/contracts/beanstalk/metadata/MetadataImage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

pragma solidity ^0.7.6;
import "../AppStorage.sol";
import {LibTokenSilo} from "contracts/libraries/Silo/LibTokenSilo.sol";
import {LibBytes} from "contracts/libraries/LibBytes.sol";
import {LibBytes64} from "contracts/libraries/LibBytes64.sol";
import {LibStrings} from "contracts/libraries/LibStrings.sol";
import {C} from "../../C.sol";
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
import {C} from "../../C.sol";


/**
Expand All @@ -29,13 +27,16 @@ contract MetadataImage {
uint256 constant NUM_PLOTS = 21;
uint256 constant STALK_GROWTH = 2e2;

function imageURI(uint256 depositId) public view returns (string memory){
return string(abi.encodePacked("data:image/svg+xml;base64,", LibBytes64.encode(bytes(generateImage(depositId)))));
function imageURI(address token, int96 stem, int96 stemTip) public view returns (string memory){
return string(
abi.encodePacked(
"data:image/svg+xml;base64,",
LibBytes64.encode(bytes(generateImage(token, stem, stemTip)))
)
);
}

function generateImage(uint256 depositId) internal view returns (string memory) {
(address token, int96 stem) = LibBytes.unpackAddressAndStem(depositId);
int96 stemTip = LibTokenSilo.stemTipForToken(token);
function generateImage(address token, int96 stem, int96 stemTip) internal view returns (string memory) {
int96 grownStalkPerBdv = stemTip - stem;
return string(
abi.encodePacked(
Expand Down Expand Up @@ -628,14 +629,14 @@ contract MetadataImage {
'<text x="127" y="343" font-size="10" fill="White" text-anchor="middle" font-family="futura">',
'<tspan><animate attributeName="x" from="375" to="50" dur="10s" repeatCount="indefinite" />',
LibStrings.toHexString(token),
'</tspan></text>'
'</tspan></text>',
'<text x="127" y="343" font-size="10" fill="White" text-anchor="middle" font-family="futura">',
'<tspan><animate attributeName="x" from="50" to="-275" dur="10s" repeatCount="indefinite" />',
LibStrings.toHexString(token),
'</tspan></text>'
)
);
}
}

function intToStr(int256 x) internal pure returns (string memory) {
if(x < 0){
Expand Down
2 changes: 2 additions & 0 deletions protocol/contracts/mocks/mockFacets/MockSeasonFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ contract MockSeasonFacet is SeasonFacet {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();

ds.supportedInterfaces[type(IERC1155).interfaceId] = true;
ds.supportedInterfaces[0x0e89341c] = true;


uint32 currentSeason = s.season.current;

Expand Down
8 changes: 7 additions & 1 deletion protocol/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ module.exports = {
chainId: 31337,
url: "https://rpc.vnet.tenderly.co/devnet/silo-v3/3ed19e82-a81c-45e5-9b16-5e385aa74587",
timeout: 100000
}
},
goerli: {
chainId: 5,
url: process.env.GOERLI_RPC || "",
accounts: [process.env.GOERLI_PRIVATE_KEY],
timeout: 100000
},
},
etherscan: {
apiKey: process.env.ETHERSCAN_KEY
Expand Down
1 change: 1 addition & 0 deletions protocol/test/Silo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ describe('Silo', function () {

it("properly gives the correct ERC-165 identifier", async function () {
expect(await this.diamondLoupe.supportsInterface("0xd9b67a26")).to.eq(true);
expect(await this.diamondLoupe.supportsInterface("0x0e89341c")).to.eq(true);
});
});

Expand Down
4 changes: 2 additions & 2 deletions protocol/test/WellConvert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('Well Convert', function () {
expect(fromToken).to.be.equal(this.well.address)
expect(fromAmount).to.be.equal(to18('2000'))
expect(toToken).to.be.equal(BEAN)
expect(toAmount).to.be.equal('134564064605')
expect(toAmount).to.be.equal('134564064606')
})

it('convert equal to max', async function () {
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('Well Convert', function () {
[to18('2000')]
)
deposit = await this.beanstalk.getDeposit(owner.address, BEAN, '0')
expect(deposit[0]).to.be.equal('134564064605')
expect(deposit[0]).to.be.equal('134564064606')
})

it('reverts when USD oracle is broken', async function () {
Expand Down
2 changes: 1 addition & 1 deletion protocol/test/data/base64EncodedImageBean.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion protocol/test/data/base64EncodedImageBean3Crv.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion protocol/test/data/base64EncodedImageBeanEth.txt

Large diffs are not rendered by default.

Loading

0 comments on commit 40e6b56

Please sign in to comment.