Skip to content

Commit 1588c7d

Browse files
committed
Latest deployments
1 parent cd6979c commit 1588c7d

File tree

66 files changed

+13264
-14207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+13264
-14207
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RAIR Smart Contracts
22
Source code and deployment scripts for RAIR smart contracts.
3-
Notice: classic-contracts are deprecated contracts, for deployment you'll need to modify the deployment scripts with your addresses.
3+
Notice: classic-contracts are deprecated
44

55
## Setup
66
Environment variables
@@ -59,7 +59,8 @@ Once all diamond facets are verified you'll need to connect them with the diamon
5959
### Setup calls
6060
| Functions | Description |
6161
| --- | --- |
62-
| Factory.changeToken(<erc20 address>, <price to deploy>) | Configure the factory to use tokens from the ERC20 to deploy |
63-
| Marketplace.updateTreasuryAddress(<treasury address>) | Set the address for the treasury fees |
64-
| Marketplace.updateTreasuryFee(<value>) | Percentage the treasury will receive on every mint |
65-
| Marketplace.grantRole(RESALE_ADMIN, <signer address>) | Approve an user address to generate resale hashes |
62+
| Factory.changeToken(ERC20 address, Price for deployment) | Configure the factory to use tokens from the ERC20 to deploy |
63+
| Factory.setSourceFacet(Facet source address) | Connect the factory to the main hub of diamond facets |
64+
| Marketplace.updateTreasuryAddress(Treasury address) | Set the address for the treasury fees |
65+
| Marketplace.updateTreasuryFee(Value) | Percentage the treasury will receive on every mint |
66+
| Marketplace.grantRole(RESALE_ADMIN, Signer address) | Approve an user address to generate resale hashes |

classic-contracts/deploy/tokenFactory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const {deployments} = require('hardhat');
1+
const {deployments, ethers} = require('hardhat');
22

3-
module.exports = async ({getUnnamedAccounts}) => {
3+
module.exports = async ({accounts, getUnnamedAccounts}) => {
44
const {deploy} = deployments;
55
const [deployerAddress] = await getUnnamedAccounts();
66
console.log('Factory deployed at', (await deploy('RAIR_Token_Factory', {

diamond-contracts/contracts/Marketplace/Facets/ResalesFacet.sol

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ contract ResaleFacet is AccessControlAppStorageEnumerableMarket {
1717
bytes32 public constant RESALE_ADMIN = keccak256("RESALE_ADMIN");
1818

1919
event TokenSold(address erc721Address, address buyer, address seller, uint token, uint tokenPrice);
20+
event TokenOfferCreated(address erc721Address, address seller, uint token, uint tokenPrice, uint offerId);
2021

2122
modifier onlyOwnerOfContract(address erc721) {
2223
ResaleStorage.Layout storage data = ResaleStorage.layout();
@@ -110,22 +111,24 @@ contract ResaleFacet is AccessControlAppStorageEnumerableMarket {
110111
}
111112
}
112113

113-
function purchaseTokenOffer(
114+
function _sendToken(
114115
address erc721,
115-
address buyer,
116-
address seller,
117116
uint token,
117+
address seller,
118+
address buyer,
119+
uint tokenPrice
120+
) internal {
121+
IERC721(erc721).transferFrom(seller, buyer, token);
122+
emit TokenSold(erc721, buyer, seller, token, tokenPrice);
123+
}
124+
125+
function _distributeFees(
126+
address erc721,
118127
uint tokenPrice,
119128
address nodeAddress,
120-
bytes memory signature
121-
) public payable {
129+
address seller
130+
) internal {
122131
ResaleStorage.feeSplits[] storage royaltyData = ResaleStorage.layout().royaltySplits[erc721];
123-
bytes32 messageHash = generateResaleHash(erc721, buyer, seller, token, tokenPrice, nodeAddress);
124-
bytes32 ethSignedMessageHash = getSignedMessageHash(messageHash);
125-
require(
126-
hasRole(RESALE_ADMIN, recoverSigner(ethSignedMessageHash, signature)),
127-
"Resale: Invalid withdraw request"
128-
);
129132
require(tokenPrice <= msg.value, "Resale: Insufficient funds!");
130133
uint leftoverForSeller = tokenPrice;
131134
if (msg.value - tokenPrice > 0) {
@@ -151,7 +154,74 @@ contract ResaleFacet is AccessControlAppStorageEnumerableMarket {
151154
payable(address(seller)).transfer(leftoverForSeller);
152155
totalTransferred += leftoverForSeller;
153156
require(totalTransferred == tokenPrice, "Resale: Error transferring funds!");
154-
IERC721(erc721).transferFrom(seller, buyer, token);
155-
emit TokenSold(erc721, buyer, seller, token, tokenPrice);
157+
}
158+
159+
function createGasTokenOffer(
160+
address erc721,
161+
uint token,
162+
uint tokenPrice,
163+
address nodeAddress
164+
) public {
165+
require(
166+
IERC721(erc721).ownerOf(token) == msg.sender,
167+
"Resale: Not the current owner of the token"
168+
);
169+
ResaleStorage.resaleOffer storage newOffer = ResaleStorage.layout().resaleOffers.push();
170+
newOffer.erc721 = erc721;
171+
newOffer.seller = msg.sender;
172+
newOffer.token = token;
173+
newOffer.tokenPrice = tokenPrice;
174+
newOffer.nodeAddress = nodeAddress;
175+
emit TokenOfferCreated(
176+
erc721,
177+
msg.sender,
178+
token,
179+
tokenPrice,
180+
ResaleStorage.layout().resaleOffers.length - 1
181+
);
182+
}
183+
184+
function purchaseGasTokenOffer(
185+
uint offerIndex
186+
) public payable {
187+
ResaleStorage.resaleOffer storage offerData = ResaleStorage.layout().resaleOffers[offerIndex];
188+
require(
189+
offerData.buyer == address(0),
190+
"Resale: Offer already purchased"
191+
);
192+
_distributeFees(
193+
offerData.erc721,
194+
offerData.tokenPrice,
195+
offerData.nodeAddress,
196+
offerData.seller
197+
);
198+
_sendToken(
199+
offerData.erc721,
200+
offerData.token,
201+
offerData.seller,
202+
msg.sender,
203+
offerData.tokenPrice
204+
);
205+
offerData.buyer = msg.sender;
206+
}
207+
208+
function purchaseTokenOffer(
209+
address erc721,
210+
address buyer,
211+
address seller,
212+
uint token,
213+
uint tokenPrice,
214+
address nodeAddress,
215+
bytes memory signature
216+
) public payable {
217+
bytes32 messageHash = generateResaleHash(erc721, buyer, seller, token, tokenPrice, nodeAddress);
218+
bytes32 ethSignedMessageHash = getSignedMessageHash(messageHash);
219+
require(
220+
hasRole(RESALE_ADMIN, recoverSigner(ethSignedMessageHash, signature)),
221+
"Resale: Invalid withdraw request"
222+
);
223+
224+
_distributeFees(erc721, tokenPrice, nodeAddress, seller);
225+
_sendToken(erc721, token, seller, buyer, tokenPrice);
156226
}
157227
}

diamond-contracts/contracts/Marketplace/Storage/ResaleStorage.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ library ResaleStorage {
1010
uint percentage;
1111
}
1212

13+
struct resaleOffer {
14+
address erc721;
15+
address buyer;
16+
address seller;
17+
uint token;
18+
uint tokenPrice;
19+
address nodeAddress;
20+
}
21+
1322
struct Layout {
1423
mapping(address => feeSplits[]) royaltySplits;
1524
mapping(address => address) contractOwner;
1625
uint purchaseGracePeriod;
1726
uint decimalPow;
27+
resaleOffer[] resaleOffers;
1828
}
1929

2030
function layout() internal pure returns (Layout storage l) {

diamond-contracts/deployments/0x2105/ResaleFacet.json

Lines changed: 136 additions & 58 deletions
Large diffs are not rendered by default.

diamond-contracts/deployments/0x2105/solcInputs/f2691882dc4d8214978e57617b5436dc.json

Lines changed: 66 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)