Skip to content

Commit

Permalink
fix: add accessURI in list params
Browse files Browse the repository at this point in the history
  • Loading branch information
CanvasL committed Aug 30, 2024
1 parent 3d072eb commit dd2b6f1
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion addresses.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"BaseSepolia": {
"Marketplace": "0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10"
"Marketplace": "0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB"
}
}
4 changes: 2 additions & 2 deletions backend/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ contracts:
BASE_SEPOLIA:
RPC: "wss://base-sepolia.g.alchemy.com/v2/_j5REyXi-XySkwLHp790Wvs9kBbxhUba"
Marketplace:
address: "0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10"
start_at: 14591456
address: "0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB"
start_at: 14616987
query_history: true
query_interval: 200000

Expand Down
6 changes: 3 additions & 3 deletions contracts/IMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ interface IMarketplace {
uint256 maxRentalDays,
address rentCurrency,
uint256 dailyRent,
address rentRecipient
address rentRecipient,
string memory accessURI
) external;

function delist(address device) external;
Expand All @@ -119,8 +120,7 @@ interface IMarketplace {
address device,
address tenant,
uint256 rentalDays,
uint256 prepaidRent,
string memory accessURI
uint256 prepaidRent
) external payable;

function payRent(
Expand Down
10 changes: 6 additions & 4 deletions contracts/Marketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ contract Marketplace is IMarketplace, ApplicationBase, Ownable {
uint256 maxRentalDays,
address rentCurrency,
uint256 dailyRent,
address rentRecipient
address rentRecipient,
string memory accessURI
) public onlyDeviceOwner(device) {
require(
_listings[device].status == ListingStatus.WithdrawnOrNotExist, // Never listed or withdrawn
Expand All @@ -142,6 +143,8 @@ contract Marketplace is IMarketplace, ApplicationBase, Ownable {
status: ListingStatus.Listing
});

_setAccessURI(device, accessURI);

emit List(
msg.sender,
device,
Expand Down Expand Up @@ -208,8 +211,7 @@ contract Marketplace is IMarketplace, ApplicationBase, Ownable {
address device,
address tenant,
uint256 rentalDays,
uint256 prepaidRent,
string memory accessURI
uint256 prepaidRent
) public payable {
require(
_rentals[device].status == RentalStatus.EndedOrNotExist,
Expand All @@ -229,7 +231,7 @@ contract Marketplace is IMarketplace, ApplicationBase, Ownable {
);

// grant access to tenant
uint256 accessId = _grantAccess(tenant, device, accessURI);
uint256 accessId = _grantAccess(tenant, device);

uint256 startTime = block.timestamp;
uint256 endTime = block.timestamp + rentalDays * 1 days;
Expand Down
14 changes: 8 additions & 6 deletions contracts/access/ApplicationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract contract ApplicationBase is
uint256 private _accessIdCount;
mapping(address => uint256[]) internal _accessesByDevice;
mapping(uint256 => address) internal _deviceByAccessId;
mapping(uint256 => string) internal _accessURIs;
mapping(address => string) internal _accessURIByDevice;

constructor(
address productFactory,
Expand Down Expand Up @@ -96,13 +96,17 @@ abstract contract ApplicationBase is
function tokenURI(
uint256 accessId
) public view override returns (string memory) {
return _accessURIs[accessId];
address device = _deviceByAccessId[accessId];
return _accessURIByDevice[device];
}

function _setAccessURI(address device, string memory accessURI) internal {
_accessURIByDevice[device] = accessURI;
}

function _grantAccess(
address to,
address device,
string memory accessURI
address device
) internal returns (uint256) {
uint256 balance = balanceOf(to);
for (uint256 i = 0; i < balance; ++i) {
Expand All @@ -114,7 +118,6 @@ abstract contract ApplicationBase is
_mint(to, accessId);
_accessesByDevice[device].push(accessId);
_deviceByAccessId[accessId] = device;
_accessURIs[accessId] = accessURI;
return accessId;
}

Expand All @@ -132,6 +135,5 @@ abstract contract ApplicationBase is
}
}
delete _deviceByAccessId[accessId];
delete _accessURIs[accessId];
}
}
2 changes: 1 addition & 1 deletion script/Delist.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract Delist is Script {
function setUp() public {
ownerPrivateKey = vm.envUint("PRIVATE_KEY");

marketplace = Marketplace(0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10);
marketplace = Marketplace(0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB);

device = 0x407156bB8154C5BFA8808125cA981dc257eCed54; // set your device here
}
Expand Down
2 changes: 1 addition & 1 deletion script/EndLease.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract EndLease is Script {
function setUp() public {
ownerPrivateKey = vm.envUint("PRIVATE_KEY");

marketplace = Marketplace(0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10);
marketplace = Marketplace(0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB);

device = 0x15A02419160FfdAF3a5d77Ea7e3812ebcC4ED8d5; // set your device here
}
Expand Down
10 changes: 6 additions & 4 deletions script/List.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ contract List is Script {
address rentCurrency;
uint256 dailyRent;
address rentRecipient;
string accessURI;

function setUp() public {
ownerPrivateKey = vm.envUint("PRIVATE_KEY");

marketplace = Marketplace(0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10);
marketplace = Marketplace(0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB);

device = 0xd34DfdE2bc41C7DaCBA160F10D61D4030971758C; // set your device here
device = 0x013e6d465077BD8b6EF99fAE5E953A4054070945; // set your device here
minRentalDays = 1; // set min rental days
maxRentalDays = 10; // set max rental days
maxRentalDays = 99; // set max rental days
rentCurrency = address(0); // only whitelisted currency, zero-address means eth(native token)
dailyRent = 4*1e14; // set daily rent
rentRecipient = vm.addr(ownerPrivateKey); // set rent receiver
accessURI = "http://";
}

function run() public {
Expand All @@ -38,7 +40,7 @@ contract List is Script {
address(marketplace),
tokenId
);
marketplace.list(device, minRentalDays, maxRentalDays, rentCurrency, dailyRent, rentRecipient);
marketplace.list(device, minRentalDays, maxRentalDays, rentCurrency, dailyRent, rentRecipient, accessURI);
vm.stopBroadcast();
}
}
2 changes: 1 addition & 1 deletion script/Relist.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract Relist is Script {
function setUp() public {
ownerPrivateKey = vm.envUint("PRIVATE_KEY");

marketplace = Marketplace(0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10);
marketplace = Marketplace(0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB);

device = 0x407156bB8154C5BFA8808125cA981dc257eCed54; // set your device here
minRentalDays = 2; // set min rental days
Expand Down
8 changes: 3 additions & 5 deletions script/Rent.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@ contract Rent is Script {
address tenant;
uint256 rentalDays;
uint256 prepaidRent;
string accessURI;

function setUp() public {
tenantPrivateKey = 0x0c6cd1d3bd57be803801f5250eeb8374a30ac11537746995ca3da2a90676da24;
marketplace = Marketplace(0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10);
marketplace = Marketplace(0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB);

device = 0xd34DfdE2bc41C7DaCBA160F10D61D4030971758C; // set your device here
tenant = vm.addr(tenantPrivateKey); // set tenant address, default is caller
rentalDays = marketplace.getListingInfo(device).minRentalDays; // set rental days, min value is min rental days set by device owner
prepaidRent = rentalDays * marketplace.getListingInfo(device).dailyRent; // set prepaid rent, min value is rentalDays * dailyRent set by device owner
accessURI = "http://";
}

function run() public {
vm.startBroadcast(tenantPrivateKey);
if (marketplace.getListingInfo(device).rentCurrency == marketplace.NATIVE_TOKEN()) {
marketplace.rent{value: prepaidRent}(device, tenant, rentalDays, prepaidRent, accessURI);
marketplace.rent{value: prepaidRent}(device, tenant, rentalDays, prepaidRent);
} else {
marketplace.rent(device, tenant, rentalDays, prepaidRent, accessURI);
marketplace.rent(device, tenant, rentalDays, prepaidRent);
}
vm.stopBroadcast();
}
Expand Down
2 changes: 1 addition & 1 deletion script/Withdraw.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract Withdraw is Script {
function setUp() public {
ownerPrivateKey = vm.envUint("PRIVATE_KEY");

marketplace = Marketplace(0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10);
marketplace = Marketplace(0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB);

device = 0x407156bB8154C5BFA8808125cA981dc257eCed54; // set your device here
}
Expand Down
6 changes: 3 additions & 3 deletions test/Marketplace.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ contract MarketplaceTest is Test {
maxRentalDays,
rentCurrency,
dailyRent,
rentRecipient
rentRecipient,
"http://test.com"
);
vm.stopPrank();

Expand All @@ -187,8 +188,7 @@ contract MarketplaceTest is Test {
device,
tenant,
rentalDays,
prepaidRent,
"http://test.com"
prepaidRent
);

return marketplace.getRentalInfo(device);
Expand Down

0 comments on commit dd2b6f1

Please sign in to comment.