Skip to content

Commit 55de92e

Browse files
authored
feat: add uri for any permanent id (#37)
1 parent 89f8a01 commit 55de92e

8 files changed

+38
-12
lines changed

contracts/core/SharesERC1155.sol

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IShare } from "../interface/IShare.sol";
1111
contract SharesERC1155 is ERC1155Supply, Ownable, IShare {
1212
address public _FACTORY_;
1313
string private _baseURI;
14+
mapping(uint256 => string) public tokenURIs;
1415

1516
event Mint(address indexed user, uint256 indexed id, uint256 amount);
1617
event Burn(address indexed user, uint256 indexed id, uint256 amount);
@@ -32,6 +33,10 @@ contract SharesERC1155 is ERC1155Supply, Ownable, IShare {
3233
_baseURI = newURI;
3334
}
3435

36+
function setTokenURI(uint256 tokenId, string memory tokenURI) public onlyFactory {
37+
tokenURIs[tokenId] = tokenURI;
38+
}
39+
3540
function shareMint(address to, uint256 id, uint256 amount) public onlyFactory {
3641
_mint(to, id, amount, "");
3742
emit Mint(to, id, amount);

contracts/core/SharesFactoryV1.sol

+7-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ contract SharesFactoryV1 is Ownable2Step, ReentrancyGuard {
4848
event ClaimYield(uint256 amount, address indexed to);
4949
event SetCurve(uint8 indexed curveType);
5050
event SetFee(uint256 indexed feePercent, string feeType);
51-
event Mint(uint256 indexed id, address indexed creator, uint8 indexed curveType);
51+
event Mint(uint256 indexed id, address indexed creator, uint8 indexed curveType, string uri);
5252
event Buy(uint256 indexed id, address indexed buyer, uint32 quantity, uint256 totalPrice);
5353
event Sell(uint256 indexed id, address indexed seller, uint32 quantity, uint256 totalPrice);
5454

@@ -182,24 +182,26 @@ contract SharesFactoryV1 is Ownable2Step, ReentrancyGuard {
182182
* @notice Mint a share and buy it in one transaction.
183183
* @param curveType The type of the curve.
184184
* @param quantity The quantity of shares.
185+
* @param uri The URI of the share. Arweave, IPFS or any permanent id.
185186
* @param referral The address of the referral fee recipient.
186187
*/
187-
function mintAndBuyShare(uint8 curveType, uint32 quantity, address referral) public payable {
188-
mintShare(curveType);
188+
function mintAndBuyShare(uint8 curveType, uint32 quantity, string memory uri, address referral) public payable {
189+
mintShare(curveType, uri);
189190
buyShare(shareIndex - 1, quantity, referral);
190191
}
191192

192193
/**
193194
* @notice Mint a share with an auto-incremented ID.
194195
* @dev The share ID is identical to the ERC1155 ID.
195196
*/
196-
function mintShare(uint8 curveType) public {
197+
function mintShare(uint8 curveType, string memory uri) public {
197198
require(curvesMap[curveType].exists, "Invalid curveType");
198199

199200
Share memory newShare = Share({ creator: msg.sender, curveType: curveType });
200201
sharesMap[shareIndex] = newShare;
202+
IShare(ERC1155).setTokenURI(shareIndex, uri);
201203

202-
emit Mint(shareIndex, msg.sender, curveType);
204+
emit Mint(shareIndex, msg.sender, curveType, uri);
203205

204206
shareIndex++;
205207
}

contracts/interface/IShare.sol

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
pragma solidity 0.8.25;
44

55
interface IShare {
6+
function setTokenURI(uint256 tokenId, string memory tokenURI) external;
7+
68
function shareMint(address to, uint256 id, uint256 amount) external;
79

810
function shareBurn(address from, uint256 id, uint256 amount) external;

test/integration/BaseIntegrationTest.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ contract BaseIntegrationTest is Test {
132132
vm.deal(LONG_TERM_TRADER, 100 ether);
133133

134134
vm.prank(DAILY_TRADER);
135-
sharesFactory.mintShare(DEFAULT_CURVE_TYPE);
135+
sharesFactory.mintShare(DEFAULT_CURVE_TYPE, '');
136136
uint256 shareId = sharesFactory.shareIndex() - 1;
137137

138138
for (uint32 i = 0; i < tradeCount; i++) {

test/integration/IncomeSimulator.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ contract IncomeSimulator is BaseIntegrationTest, LogUtil {
216216

217217
// mint shares
218218
vm.prank(FACTORY_OWNER);
219-
sharesFactory.mintShare(curveType);
219+
sharesFactory.mintShare(curveType, '');
220220

221221
// record start balance
222222
uint256 founderBalanceBefore = aWETH.balanceOf(address(SHARES_FOUNDER));

test/integration/handlers/BoundedIntegrationContextHandler.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ contract BoundedIntegrationContextHandler is StdUtils {
5656
uint256 shareId = 0;
5757

5858
vm.prank(factoryOwner);
59-
sharesFactory.mintShare(0);
59+
sharesFactory.mintShare(0, '');
6060

6161
vm.prank(TRADER);
6262

test/unit/SharesERC1155.t.sol

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ contract ERC1155Tests is BaseTest {
3737
assertEq(userBal, 10);
3838
}
3939

40+
function test_setTokenURI() public {
41+
vm.expectRevert(bytes("Caller is not the factory"));
42+
sharesNFT.setTokenURI(0, "https://vv.com/0");
43+
44+
vm.prank(address(sharesFactory));
45+
sharesNFT.setTokenURI(0, "https://vv.com/0");
46+
47+
string memory tokenURI = sharesNFT.tokenURIs(0);
48+
assertEq(tokenURI, "https://vv.com/0");
49+
}
50+
4051
function test_shareMint() public {
4152
vm.prank(address(sharesFactory));
4253
sharesNFT.shareMint(addrUser, 0, 10);

test/unit/SharesFactory.t.sol

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { IYieldAggregator } from "contracts/interface/IYieldAggregator.sol";
88
import { BaseTest } from "../BaseTest.t.sol";
99

1010
contract SharesFactoryTests is BaseTest {
11+
string private constant URI = "https://vv.com/uri/";
12+
1113
function setUp() public {
1214
createFactory();
1315
_setUpShare();
@@ -19,7 +21,7 @@ contract SharesFactoryTests is BaseTest {
1921

2022
// Alice mint & buy 1 share with 0 id
2123
vm.prank(addrAlice);
22-
sharesFactory.mintShare(defaultCurveType);
24+
sharesFactory.mintShare(defaultCurveType, URI);
2325
_buyShare(addrAlice, 0, 1, referralReceiver);
2426

2527
// Bob mintAndBuy 1 share with 1 id
@@ -39,16 +41,18 @@ contract SharesFactoryTests is BaseTest {
3941

4042
function test_mintShare() public {
4143
vm.prank(addrAlice);
42-
sharesFactory.mintShare(defaultCurveType);
44+
sharesFactory.mintShare(defaultCurveType, URI);
4345

4446
uint256 shareIndex = sharesFactory.shareIndex();
4547
(address creator, uint8 curveType) = sharesFactory.getShare(shareIndex - 1);
48+
string memory tokenURI = sharesNFT.tokenURIs(shareIndex - 1);
4649

4750
assertEq(creator, addrAlice);
4851
assertEq(curveType, defaultCurveType);
52+
assertEq(tokenURI, URI);
4953

5054
vm.expectRevert(bytes("Invalid curveType"));
51-
sharesFactory.mintShare(99);
55+
sharesFactory.mintShare(99, URI);
5256
}
5357

5458
function test_minAndBuyShare() public {
@@ -59,10 +63,12 @@ contract SharesFactoryTests is BaseTest {
5963
uint256 shareId = sharesFactory.shareIndex() - 1;
6064
uint256 bobShareBal = sharesNFT.shareBalanceOf(addrBob, shareId);
6165
(address creator, uint8 curveType) = sharesFactory.getShare(shareId);
66+
string memory tokenURI = sharesNFT.tokenURIs(shareId);
6267

6368
assertEq(creator, addrBob);
6469
assertEq(curveType, defaultCurveType);
6570
assertEq(bobShareBal, 99);
71+
assertEq(tokenURI, URI);
6672
}
6773

6874
function test_buyShares() public {
@@ -534,7 +540,7 @@ contract SharesFactoryTests is BaseTest {
534540
uint256 buyPrice = sharesFactory.getSubTotal(0, quantity, curveType);
535541

536542
vm.prank(address(sender));
537-
sharesFactory.mintAndBuyShare{ value: buyPrice * 110 / 100 }(curveType, quantity, referral);
543+
sharesFactory.mintAndBuyShare{ value: buyPrice * 110 / 100 }(curveType, quantity, URI, referral);
538544
}
539545

540546
function _buyShare(address sender, uint256 shareId, uint32 quantity, address referral) internal {

0 commit comments

Comments
 (0)