diff --git a/addresses.json b/addresses.json index a4f058f..85203eb 100644 --- a/addresses.json +++ b/addresses.json @@ -1,5 +1,5 @@ { "BaseSepolia": { - "Marketplace": "0xEdeE6f1E0315d0872CF824A71BC9d5E3Ef5f0b10" + "Marketplace": "0xe250f5d46395E42c9955E16CAc6C9dacCdD3B7dB" } } \ No newline at end of file diff --git a/backend/config.yaml b/backend/config.yaml index 95e2dee..9f5bed7 100644 --- a/backend/config.yaml +++ b/backend/config.yaml @@ -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 diff --git a/contracts/IMarketplace.sol b/contracts/IMarketplace.sol index 5e6a5f8..f7791fe 100644 --- a/contracts/IMarketplace.sol +++ b/contracts/IMarketplace.sol @@ -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; @@ -119,8 +120,7 @@ interface IMarketplace { address device, address tenant, uint256 rentalDays, - uint256 prepaidRent, - string memory accessURI + uint256 prepaidRent ) external payable; function payRent( diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 4d6d5a3..fb3fca6 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -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 @@ -142,6 +143,8 @@ contract Marketplace is IMarketplace, ApplicationBase, Ownable { status: ListingStatus.Listing }); + _setAccessURI(device, accessURI); + emit List( msg.sender, device, @@ -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, @@ -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; diff --git a/contracts/access/ApplicationBase.sol b/contracts/access/ApplicationBase.sol index 86ef32f..32a861e 100644 --- a/contracts/access/ApplicationBase.sol +++ b/contracts/access/ApplicationBase.sol @@ -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, @@ -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) { @@ -114,7 +118,6 @@ abstract contract ApplicationBase is _mint(to, accessId); _accessesByDevice[device].push(accessId); _deviceByAccessId[accessId] = device; - _accessURIs[accessId] = accessURI; return accessId; } @@ -132,6 +135,5 @@ abstract contract ApplicationBase is } } delete _deviceByAccessId[accessId]; - delete _accessURIs[accessId]; } } diff --git a/script/Delist.s.sol b/script/Delist.s.sol index ff83494..aae64da 100644 --- a/script/Delist.s.sol +++ b/script/Delist.s.sol @@ -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 } diff --git a/script/EndLease.s.sol b/script/EndLease.s.sol index b68af43..3acee33 100644 --- a/script/EndLease.s.sol +++ b/script/EndLease.s.sol @@ -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 } diff --git a/script/List.s.sol b/script/List.s.sol index 6df753d..e7f3af1 100644 --- a/script/List.s.sol +++ b/script/List.s.sol @@ -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 { @@ -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(); } } diff --git a/script/Relist.s.sol b/script/Relist.s.sol index 05355d4..d33119f 100644 --- a/script/Relist.s.sol +++ b/script/Relist.s.sol @@ -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 diff --git a/script/Rent.s.sol b/script/Rent.s.sol index 96b5313..7c46abb 100644 --- a/script/Rent.s.sol +++ b/script/Rent.s.sol @@ -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(); } diff --git a/script/Withdraw.s.sol b/script/Withdraw.s.sol index d6f9c89..47bdc71 100644 --- a/script/Withdraw.s.sol +++ b/script/Withdraw.s.sol @@ -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 } diff --git a/test/Marketplace.t.sol b/test/Marketplace.t.sol index 1d0410a..f5a65ee 100644 --- a/test/Marketplace.t.sol +++ b/test/Marketplace.t.sol @@ -174,7 +174,8 @@ contract MarketplaceTest is Test { maxRentalDays, rentCurrency, dailyRent, - rentRecipient + rentRecipient, + "http://test.com" ); vm.stopPrank(); @@ -187,8 +188,7 @@ contract MarketplaceTest is Test { device, tenant, rentalDays, - prepaidRent, - "http://test.com" + prepaidRent ); return marketplace.getRentalInfo(device);