Skip to content

Commit b40e919

Browse files
author
Daniel Lima
committed
ON-787: PR fixes
1 parent b7d51b5 commit b40e919

File tree

3 files changed

+95
-47
lines changed

3 files changed

+95
-47
lines changed

contracts/OriumSftMarketplace.sol

+71-24
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,35 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
7474
bytes[] rolesData
7575
);
7676

77+
/**
78+
* @param nonce The nonce of the rental offer
79+
* @param tokenAddress The address of the contract of the SFT to rent
80+
* @param tokenId The tokenId of the SFT to rent
81+
* @param tokenAmount The amount of SFT to rent
82+
* @param commitmentId The commitmentId of the SFT to rent
83+
* @param lender The address of the user lending the SFT
84+
* @param borrower The address of the user renting the SFT
85+
* @param feeTokenAddress The address of the ERC20 token for rental fees
86+
* @param feeAmountPerSecond The amount of fee per second
87+
* @param deadline The deadline until when the rental offer is valid
88+
* @param roles The array of roles to be assigned to the borrower
89+
* @param rolesData The array of data for each role
90+
*/
91+
event RentalOfferCreated(
92+
uint256 indexed nonce,
93+
address indexed tokenAddress,
94+
uint256 indexed tokenId,
95+
uint256 tokenAmount,
96+
uint256 commitmentId,
97+
address lender,
98+
address borrower,
99+
address feeTokenAddress,
100+
uint256 feeAmountPerSecond,
101+
uint256 deadline,
102+
bytes32[] roles,
103+
bytes[] rolesData
104+
);
105+
77106
/**
78107
* @param lender The address of the lender
79108
* @param nonce The nonce of the rental offer
@@ -132,17 +161,48 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
132161
feeTokenAddress: _offer.feeTokenAddress,
133162
feeAmountPerSecond: _offer.feeAmountPerSecond,
134163
deadline: _offer.deadline,
135-
minDuration: 1,
164+
minDuration: 0,
136165
roles: _offer.roles,
137166
rolesData: _offer.rolesData
138167
});
139-
_createRentalOffer(_parsedOffer);
168+
uint256 _commitmentId = _createRentalOffer(_parsedOffer);
169+
170+
emit RentalOfferCreated(
171+
_offer.nonce,
172+
_offer.tokenAddress,
173+
_offer.tokenId,
174+
_offer.tokenAmount,
175+
_commitmentId,
176+
_offer.lender,
177+
_offer.borrower,
178+
_offer.feeTokenAddress,
179+
_offer.feeAmountPerSecond,
180+
_offer.deadline,
181+
_offer.roles,
182+
_offer.rolesData
183+
);
140184
}
141185

142186
function createRentalOffer(RentalOffer calldata _offer) external whenNotPaused {
143-
_createRentalOffer(_offer);
187+
uint256 _commitmentId = _createRentalOffer(_offer);
188+
189+
emit RentalOfferCreated(
190+
_offer.nonce,
191+
_offer.tokenAddress,
192+
_offer.tokenId,
193+
_offer.tokenAmount,
194+
_commitmentId,
195+
_offer.lender,
196+
_offer.borrower,
197+
_offer.feeTokenAddress,
198+
_offer.feeAmountPerSecond,
199+
_offer.deadline,
200+
_offer.minDuration,
201+
_offer.roles,
202+
_offer.rolesData
203+
);
144204
}
145-
function _createRentalOffer(RentalOffer memory _offer) internal {
205+
function _createRentalOffer(RentalOffer memory _offer) internal returns (uint256) {
146206
address _rolesRegistryAddress = IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).sftRolesRegistryOf(
147207
_offer.tokenAddress
148208
);
@@ -161,21 +221,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
161221
isCreated[LibOriumSftMarketplace.hashRentalOffer(_offer)] = true;
162222
commitmentIdToNonce[_rolesRegistryAddress][_offer.commitmentId] = _offer.nonce;
163223

164-
emit RentalOfferCreated(
165-
_offer.nonce,
166-
_offer.tokenAddress,
167-
_offer.tokenId,
168-
_offer.tokenAmount,
169-
_offer.commitmentId,
170-
_offer.lender,
171-
_offer.borrower,
172-
_offer.feeTokenAddress,
173-
_offer.feeAmountPerSecond,
174-
_offer.deadline,
175-
_offer.minDuration,
176-
_offer.roles,
177-
_offer.rolesData
178-
);
224+
return _offer.commitmentId;
179225
}
180226

181227
/**
@@ -208,10 +254,11 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
208254
_acceptRentalOffer(_parsedOffer, _duration);
209255
}
210256
function _acceptRentalOffer(RentalOffer memory _offer, uint64 _duration) internal {
211-
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOfferLegacy(_offer);
257+
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer);
212258
uint64 _expirationDate = uint64(block.timestamp + _duration);
213-
LibOriumSftMarketplace.validateAcceptRentalOffer(
214-
_offer,
259+
LibOriumSftMarketplace.validateAcceptRentalOffer(
260+
_offer.borrower,
261+
_offer.minDuration,
215262
isCreated[_offerHash],
216263
rentals[_offerHash].expirationDate,
217264
_duration,
@@ -267,7 +314,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
267314
_cancelRentalOffer(_parsedOffer);
268315
}
269316
function _cancelRentalOffer(RentalOffer memory _offer) internal {
270-
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOfferLegacy(_offer);
317+
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer);
271318
require(isCreated[_offerHash], "OriumSftMarketplace: Offer not created");
272319
require(msg.sender == _offer.lender, "OriumSftMarketplace: Only lender can cancel a rental offer");
273320
require(
@@ -320,7 +367,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
320367
}
321368

322369
function _endRental(RentalOffer memory _offer) internal {
323-
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOfferLegacy(_offer);
370+
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer);
324371

325372
require(isCreated[_offerHash], "OriumSftMarketplace: Offer not created");
326373
require(msg.sender == rentals[_offerHash].borrower, "OriumSftMarketplace: Only borrower can end a rental");

contracts/libraries/LibOriumSftMarketplace.sol

+8-19
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ library LibOriumSftMarketplace {
6464
* is only used for reading the hash from the storage.
6565
* @param _offer The rental offer struct to be hashed.
6666
*/
67-
function hashRentalOfferLegacy(RentalOffer memory _offer) external pure returns (bytes32) {
67+
function hashRentalOffer(RentalOffer memory _offer) external pure returns (bytes32) {
6868
return
6969
_offer.minDuration == 0
7070
? keccak256(
@@ -83,17 +83,7 @@ library LibOriumSftMarketplace {
8383
_offer.rolesData
8484
)
8585
)
86-
: hashRentalOffer(_offer);
87-
}
88-
89-
/**
90-
* @notice Gets the rental offer hash.
91-
* @dev This function is used to hash the rental offer struct in the current version.
92-
* is only used for writing the hash in the storage.
93-
* @param _offer The rental offer struct to be hashed.
94-
*/
95-
function hashRentalOffer(RentalOffer memory _offer) public pure returns (bytes32) {
96-
return keccak256(abi.encode(_offer));
86+
: keccak256(abi.encode(_offer));
9787
}
9888

9989
/**
@@ -277,27 +267,26 @@ library LibOriumSftMarketplace {
277267
}
278268

279269
function validateAcceptRentalOffer(
280-
RentalOffer memory _offer,
270+
address _borrower,
271+
uint64 _minDuration,
281272
bool _isCreated,
282-
uint64 _rentalExpirationDate,
273+
uint64 _previousRentalExpirationDate,
283274
uint64 _duration,
284275
uint256 _nonceDeadline,
285276
uint64 _expirationDate
286277
) external view {
287278
require(_isCreated, 'OriumSftMarketplace: Offer not created');
288-
require(_rentalExpirationDate <= block.timestamp, 'OriumSftMarketplace: This offer has an ongoing rental');
279+
require(_previousRentalExpirationDate <= block.timestamp, 'OriumSftMarketplace: This offer has an ongoing rental');
289280
require(
290-
_duration >= _offer.minDuration,
281+
_duration >= _minDuration,
291282
'OriumSftMarketplace: Duration is less than the offer minimum duration'
292283
);
293-
294284
require(
295285
_nonceDeadline > _expirationDate,
296286
'OriumSftMarketplace: expiration date is greater than offer deadline'
297287
);
298-
299288
require(
300-
address(0) == _offer.borrower || msg.sender == _offer.borrower,
289+
address(0) == _borrower || msg.sender == _borrower,
301290
'OriumSftMarketplace: Sender is not allowed to rent this SFT'
302291
);
303292
}

test/OriumSftMarketplace.test.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ describe('OriumSftMarketplace', () => {
128128
'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))'
129129
](rentalOffer),
130130
)
131-
.to.emit(marketplace, 'RentalOfferCreated')
131+
.to.emit(
132+
marketplace,
133+
'RentalOfferCreated(uint256,address,uint256,uint256,uint256,address,address,address,uint256,uint256,uint64,bytes32[],bytes[])',
134+
)
132135
.withArgs(
133136
rentalOffer.nonce,
134137
rentalOffer.tokenAddress,
@@ -167,7 +170,10 @@ describe('OriumSftMarketplace', () => {
167170
'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))'
168171
](rentalOffer),
169172
)
170-
.to.emit(marketplace, 'RentalOfferCreated')
173+
.to.emit(
174+
marketplace,
175+
'RentalOfferCreated(uint256,address,uint256,uint256,uint256,address,address,address,uint256,uint256,uint64,bytes32[],bytes[])',
176+
)
171177
.withArgs(
172178
rentalOffer.nonce,
173179
rentalOffer.tokenAddress,
@@ -204,7 +210,10 @@ describe('OriumSftMarketplace', () => {
204210
'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))'
205211
](rentalOffer),
206212
)
207-
.to.emit(marketplace, 'RentalOfferCreated')
213+
.to.emit(
214+
marketplace,
215+
'RentalOfferCreated(uint256,address,uint256,uint256,uint256,address,address,address,uint256,uint256,uint64,bytes32[],bytes[])',
216+
)
208217
.withArgs(
209218
rentalOffer.nonce,
210219
rentalOffer.tokenAddress,
@@ -417,7 +426,10 @@ describe('OriumSftMarketplace', () => {
417426
'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))'
418427
](rentalOffer),
419428
)
420-
.to.emit(marketplace, 'RentalOfferCreated')
429+
.to.emit(
430+
marketplace,
431+
'RentalOfferCreated(uint256,address,uint256,uint256,uint256,address,address,address,uint256,uint256,uint64,bytes32[],bytes[])',
432+
)
421433
.withArgs(
422434
rentalOffer.nonce,
423435
rentalOffer.tokenAddress,

0 commit comments

Comments
 (0)