Skip to content

Commit 2ca5401

Browse files
committed
Updated contracts and frontend create
1 parent d7a4534 commit 2ca5401

File tree

8 files changed

+238
-89
lines changed

8 files changed

+238
-89
lines changed

contracts/HouseformManager.sol

+31-22
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import './HouseformShare.sol';
99
contract HouseformManager is Ownable, ReentrancyGuard {
1010
struct Project {
1111
address payable builder;
12-
string name;
13-
string description;
14-
string image;
1512
uint currentAmount;
1613
uint goalAmount;
1714
uint saleAmount; // Amount at which the project is sold
@@ -32,21 +29,21 @@ contract HouseformManager is Ownable, ReentrancyGuard {
3229
mapping(address => uint) builderProjectCount;
3330

3431
event ProjectCreated(
35-
uint projectId,
36-
string name,
37-
string description,
38-
string image,
39-
uint goalAmount,
40-
uint expectedProfit,
41-
uint builderShares,
42-
uint totalShares,
43-
uint fundraisingDeadline
32+
uint _projectId,
33+
string _name,
34+
string _description,
35+
string _image,
36+
uint _goalAmount,
37+
uint _expectedProfit,
38+
uint _builderShares,
39+
uint _totalShares,
40+
uint _fundraisingDeadline
4441
);
45-
event BuildingStarted(uint projectId, uint buildingStartedOn);
46-
event BuildingCompleted(uint projectId, uint buildingCompletedOn, uint saleAmount);
47-
event SharesBought(address account, uint projectId, uint shares);
48-
event SharesRedeemed(address account, uint projectId, uint shares);
49-
event FundraisingCompleted(uint projectId, uint fundraisingCompletedOn);
42+
event BuildingStarted(uint _projectId, uint _buildingStartedOn);
43+
event BuildingCompleted(uint _projectId, uint _buildingCompletedOn, uint _saleAmount);
44+
event SharesBought(address _account, uint _projectId, uint _shares);
45+
event SharesRedeemed(address _account, uint _projectId, uint _shares);
46+
event FundraisingCompleted(uint _projectId, uint _fundraisingCompletedOn);
5047

5148
modifier projectExists(uint _projectId) {
5249
// NB: project ids are incremental indexes of projects array
@@ -105,13 +102,13 @@ contract HouseformManager is Ownable, ReentrancyGuard {
105102
}
106103

107104
function createProject(
108-
uint _goalAmount,
109105
string memory _name,
110106
string memory _description,
111107
string memory _image,
108+
uint _goalAmount,
109+
uint _expectedProfit,
112110
uint _builderShares,
113111
uint _totalShares,
114-
uint _expectedProfit,
115112
uint _fundraisingDeadline
116113
) external nonReentrant {
117114
// Validate inputs
@@ -126,9 +123,6 @@ contract HouseformManager is Ownable, ReentrancyGuard {
126123
projects.push(
127124
Project({
128125
builder: payable(msg.sender),
129-
name: _name,
130-
description: _description,
131-
image: _image,
132126
currentAmount: 0,
133127
goalAmount: _goalAmount,
134128
saleAmount: 0,
@@ -148,6 +142,8 @@ contract HouseformManager is Ownable, ReentrancyGuard {
148142
projectToBuilder[id] = msg.sender;
149143
builderProjectCount[msg.sender]++;
150144

145+
// Set id metadata
146+
shareContract.setMetadata(id, _name, _description, _image);
151147
// Mint initial shares to builder
152148
shareContract.mint(msg.sender, id, _builderShares, '');
153149

@@ -286,6 +282,19 @@ contract HouseformManager is Ownable, ReentrancyGuard {
286282
emit SharesRedeemed(msg.sender, _projectId, _shares);
287283
}
288284

285+
function getProjects() external view returns (Project[] memory) {
286+
Project[] memory projectsArray = new Project[](projects.length);
287+
for (uint i = 0; i < projects.length; i++) {
288+
projectsArray[i] = projects[i];
289+
}
290+
return projectsArray;
291+
}
292+
293+
function getProject(uint _projectId) external view returns (Project memory) {
294+
Project memory project = projects[_projectId];
295+
return project;
296+
}
297+
289298
function getShareCost(uint _projectId) public view returns (uint) {
290299
Project memory project = projects[_projectId];
291300
return project.goalAmount / project.totalShares;

contracts/HouseformShare.sol

+57-12
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,81 @@ pragma solidity ^0.8.20;
44
import '@klaytn/contracts/KIP/token/KIP37/KIP37.sol';
55
import '@klaytn/contracts/KIP/token/KIP37/extensions/KIP37Burnable.sol';
66
import '@klaytn/contracts/access/Ownable.sol';
7+
import '@klaytn/contracts/utils/Base64.sol';
78

89
// NB: The id of the token to be minted is the project id so that they can be easily referenced
910
contract HouseformShare is KIP37, KIP37Burnable, Ownable {
11+
struct Metadata {
12+
string name;
13+
string description;
14+
string image;
15+
}
16+
1017
string public name = 'HouseformShare';
1118
string public symbol = 'HS';
1219

20+
mapping(uint => Metadata) public idToMetadata;
21+
1322
constructor() KIP37('') {}
1423

15-
function mint(address account, uint256 id, uint256 amount, bytes memory data) public onlyOwner {
16-
_mint(account, id, amount, data);
24+
function setMetadata(
25+
uint _id,
26+
string memory _name,
27+
string memory _description,
28+
string memory _image
29+
) public onlyOwner {
30+
idToMetadata[_id] = Metadata({name: _name, description: _description, image: _image});
31+
}
32+
33+
function mint(address _account, uint256 _id, uint256 _amount, bytes memory _data) public onlyOwner {
34+
_mint(_account, _id, _amount, _data);
1735
}
1836

19-
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public onlyOwner {
20-
_mintBatch(to, ids, amounts, data);
37+
function mintBatch(
38+
address _to,
39+
uint256[] memory _ids,
40+
uint256[] memory _amounts,
41+
bytes memory _data
42+
) public onlyOwner {
43+
_mintBatch(_to, _ids, _amounts, _data);
2144
}
2245

23-
function burn(address account, uint256 id, uint256 amount) public override onlyOwner {
24-
_burn(account, id, amount);
46+
function burn(address _account, uint256 _id, uint256 _amount) public override onlyOwner {
47+
_burn(_account, _id, _amount);
2548
}
2649

27-
function burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) public override onlyOwner {
28-
_burnBatch(account, ids, amounts);
50+
function burnBatch(address _account, uint256[] memory _ids, uint256[] memory _amounts) public override onlyOwner {
51+
_burnBatch(_account, _ids, _amounts);
2952
}
3053

31-
function balanceOf(address owner, uint256 id) public view override returns (uint256) {
32-
return balanceOf(owner, id);
54+
function uri(uint256 _id) public view override returns (string memory) {
55+
Metadata memory metadata = idToMetadata[_id];
56+
// Return stringified data uri
57+
return
58+
string(
59+
abi.encodePacked(
60+
'data:application/json;base64,',
61+
Base64.encode(
62+
bytes(
63+
string(
64+
abi.encodePacked(
65+
'{ "name": "',
66+
metadata.name,
67+
'", "description": "',
68+
metadata.description,
69+
'", "image": "',
70+
metadata.image,
71+
'"}'
72+
)
73+
)
74+
)
75+
)
76+
)
77+
);
3378
}
3479

3580
// Override required by Solidity
36-
function supportsInterface(bytes4 interfaceId) public view override(KIP37, KIP37Burnable) returns (bool) {
37-
return super.supportsInterface(interfaceId);
81+
function supportsInterface(bytes4 _interfaceId) public view override(KIP37, KIP37Burnable) returns (bool) {
82+
return super.supportsInterface(_interfaceId);
3883
}
3984
}

hardhat.config.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ require('@nomicfoundation/hardhat-toolbox');
22
require('dotenv').config();
33

44
module.exports = {
5-
solidity: '0.8.20',
5+
solidity: {
6+
version: '0.8.20',
7+
settings: {
8+
optimizer: {
9+
enabled: true,
10+
runs: 2000,
11+
},
12+
},
13+
},
614
networks: {
715
baobab: {
816
url: process.env.HARDHAT_KLAYTN_BAOBAB_TESTNET_URL || '',

package-lock.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
"@openzeppelin/contracts": "^5.0.0",
1818
"@web3modal/wagmi": "^3.3.2",
1919
"antd": "^5.11.1",
20-
"next": "14.0.2",
2120
"dotenv": "^16.3.1",
21+
"next": "14.0.2",
2222
"react": "^18",
2323
"react-dom": "^18",
2424
"react-icons": "^4.11.0",
25-
"viem": "^1.19.3",
26-
"wagmi": "^1.4.7",
2725
"rxjs": "^7.8.1",
28-
"swr": "^2.2.4"
26+
"swr": "^2.2.4",
27+
"usehooks-ts": "^2.9.1",
28+
"viem": "^1.19.3",
29+
"wagmi": "^1.4.7"
2930
},
3031
"devDependencies": {
3132
"@svgr/webpack": "^8.1.0",

scripts/read.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const { ethers } = require('hardhat');
33
// Load env variables
44
require('dotenv').config();
55

6-
const managerContractAddress = '0x3a5CC2Be65e56d896f0D3adf427474c33239a1F9';
7-
const shareContractAddress = '0x873340073b531a2F76b8c0e7567A434f762Eae31';
6+
const managerContractAddress = '0x0d4eF3419af9a0FEE9cc7dBE3EAC4156399f457C';
7+
const shareContractAddress = '0x3ea99bEa8d5D1Cf76aF585ba207147C653297853';
88

99
async function main() {
1010
const managerContract = (await ethers.getContractFactory('HouseformManager')).attach(managerContractAddress);
@@ -13,6 +13,13 @@ async function main() {
1313
console.log(`Share contract address: ${await managerContract.shareContract()}`);
1414
console.log(`Share contract name: ${await shareContract.name()}`);
1515
console.log(`Share contract symbol: ${await shareContract.symbol()}`);
16+
17+
console.log(`Projects: ${await managerContract.getProjects()}`);
18+
//console.log(`Project metadata: ${await shareContract.uri(0)}`);
19+
20+
console.log(
21+
`Balance of project #0 shares: ${await shareContract.balanceOf('0x93840623bc378e9ee5334c0eE4608CF877dC68D3', 0)}`,
22+
);
1623
}
1724

1825
main().catch((error) => {

0 commit comments

Comments
 (0)