diff --git a/smart-contracts/contracts/diamond/facets/Marketplace.sol b/smart-contracts/contracts/diamond/facets/Marketplace.sol index 7eb7e142..4e4a79d9 100644 --- a/smart-contracts/contracts/diamond/facets/Marketplace.sol +++ b/smart-contracts/contracts/diamond/facets/Marketplace.sol @@ -95,7 +95,7 @@ contract Marketplace is bytes32 bidId_ = getBidId(provider_, modelId_, nonce_); - addBid(bidId_, Bid(provider_, modelId_, pricePerSecond_, nonce_, uint128(block.timestamp), 0)); + setBid(bidId_, Bid(provider_, modelId_, pricePerSecond_, nonce_, uint128(block.timestamp), 0)); addProviderBid(provider_, bidId_); addModelBid(modelId_, bidId_); @@ -108,9 +108,9 @@ contract Marketplace is return bidId_; } - /// @dev passing bidId and bid storage to avoid double storage access function _deleteBid(bytes32 bidId_) private { Bid storage bid = getBid(bidId_); + bid.deletedAt = uint128(block.timestamp); removeProviderActiveBids(bid.provider, bidId_); diff --git a/smart-contracts/contracts/diamond/facets/ModelRegistry.sol b/smart-contracts/contracts/diamond/facets/ModelRegistry.sol index d81d03b8..7dc34c12 100644 --- a/smart-contracts/contracts/diamond/facets/ModelRegistry.sol +++ b/smart-contracts/contracts/diamond/facets/ModelRegistry.sol @@ -15,14 +15,14 @@ contract ModelRegistry is IModelRegistry, OwnableDiamondStorage, ModelStorage, B function __ModelRegistry_init() external initializer(MODEL_STORAGE_SLOT) {} - /// @notice Sets the minimum stake required for a model - function modelSetMinStake(uint256 modelMinimumStake_) external onlyOwner { - setModelMinimumStake(modelMinimumStake_); - emit ModelMinStakeUpdated(modelMinimumStake_); + function setModelMinimumStake(uint256 modelMinimumStake_) external onlyOwner { + _setModelMinimumStake(modelMinimumStake_); + emit ModelMinimumStakeSet(modelMinimumStake_); } /// @notice Registers or updates existing model function modelRegister( + // TODO: it is not secure (frontrunning) to take the modelId as key bytes32 modelId_, bytes32 ipfsCID_, uint256 fee_, @@ -31,17 +31,22 @@ contract ModelRegistry is IModelRegistry, OwnableDiamondStorage, ModelStorage, B string calldata name_, string[] calldata tags_ ) external { - if (!_ownerOrModelOwner(owner_)) { + if (!_isOwnerOrModelOwner(owner_)) { + // TODO: such that we cannon create a model with the owner as another address + // Do we need this check? revert NotOwnerOrModelOwner(); } Model memory model_ = models(modelId_); + // TODO: there is no way to decrease the stake uint256 newStake_ = model_.stake + addStake_; if (newStake_ < modelMinimumStake()) { revert StakeTooLow(); } - getToken().safeTransferFrom(_msgSender(), address(this), addStake_); + if (addStake_ > 0) { + getToken().safeTransferFrom(_msgSender(), address(this), addStake_); + } uint128 createdAt_ = model_.createdAt; if (createdAt_ == 0) { @@ -50,7 +55,7 @@ contract ModelRegistry is IModelRegistry, OwnableDiamondStorage, ModelStorage, B setModelActive(modelId_, true); createdAt_ = uint128(block.timestamp); } else { - if (!_ownerOrModelOwner(model_.owner)) { + if (!_isOwnerOrModelOwner(model_.owner)) { revert NotOwnerOrModelOwner(); } if (model_.isDeleted) { @@ -63,18 +68,15 @@ contract ModelRegistry is IModelRegistry, OwnableDiamondStorage, ModelStorage, B emit ModelRegisteredUpdated(owner_, modelId_); } - /// @notice Deregisters a model function modelDeregister(bytes32 modelId_) external { Model storage model = models(modelId_); if (!isModelExists(modelId_)) { revert ModelNotFound(); } - - if (!_ownerOrModelOwner(model.owner)) { + if (!_isOwnerOrModelOwner(model.owner)) { revert NotOwnerOrModelOwner(); } - if (!isModelActiveBidsEmpty(modelId_)) { revert ModelHasActiveBids(); } @@ -95,7 +97,7 @@ contract ModelRegistry is IModelRegistry, OwnableDiamondStorage, ModelStorage, B return models(modelId_).createdAt != 0; } - function _ownerOrModelOwner(address modelOwner_) internal view returns (bool) { + function _isOwnerOrModelOwner(address modelOwner_) internal view returns (bool) { return _msgSender() == owner() || _msgSender() == modelOwner_; } } diff --git a/smart-contracts/contracts/diamond/facets/ProviderRegistry.sol b/smart-contracts/contracts/diamond/facets/ProviderRegistry.sol index 158b116c..8ff515a7 100644 --- a/smart-contracts/contracts/diamond/facets/ProviderRegistry.sol +++ b/smart-contracts/contracts/diamond/facets/ProviderRegistry.sol @@ -27,6 +27,8 @@ contract ProviderRegistry is IProviderRegistry, OwnableDiamondStorage, ProviderS /// @param endpoint_ provider endpoint (host.com:1234) function providerRegister(address providerAddress_, uint256 amount_, string calldata endpoint_) external { if (!_ownerOrProvider(providerAddress_)) { + // TODO: such that we cannon create a provider with the owner as another address + // Do we need this check? revert NotOwnerOrProvider(); } @@ -36,7 +38,9 @@ contract ProviderRegistry is IProviderRegistry, OwnableDiamondStorage, ProviderS revert StakeTooLow(); } - getToken().safeTransferFrom(_msgSender(), address(this), amount_); + if (amount_ > 0) { + getToken().safeTransferFrom(_msgSender(), address(this), amount_); + } // if we add stake to an existing provider the limiter period is not reset uint128 createdAt_ = provider_.createdAt; @@ -73,11 +77,13 @@ contract ProviderRegistry is IProviderRegistry, OwnableDiamondStorage, ProviderS Provider storage provider = providers(provider_); uint256 withdrawable_ = _getWithdrawableStake(provider); - + provider.stake -= withdrawable_; provider.isDeleted = true; - getToken().safeTransfer(_msgSender(), withdrawable_); + if (withdrawable_ > 0) { + getToken().safeTransfer(_msgSender(), withdrawable_); + } emit ProviderDeregistered(provider_); } diff --git a/smart-contracts/contracts/diamond/facets/SessionRouter.sol b/smart-contracts/contracts/diamond/facets/SessionRouter.sol index 112f7c59..9f9b1ed4 100644 --- a/smart-contracts/contracts/diamond/facets/SessionRouter.sol +++ b/smart-contracts/contracts/diamond/facets/SessionRouter.sol @@ -54,6 +54,7 @@ contract SessionRouter is bytes calldata providerApproval_, bytes calldata signature_ ) external returns (bytes32) { + // should a user pass the bidId to compare with a providerApproval? bytes32 bidId_ = _extractProviderApproval(providerApproval_); Bid memory bid_ = getBid(bidId_); @@ -64,16 +65,17 @@ contract SessionRouter is if (!_isValidReceipt(bid_.provider, providerApproval_, signature_)) { revert ProviderSignatureMismatch(); } - if (isApproved(providerApproval_)) { + if (isApprovalUsed(providerApproval_)) { revert DuplicateApproval(); } - approve(providerApproval_); + setApprovalUsed(providerApproval_); uint256 endsAt_ = whenSessionEnds(amount_, bid_.pricePerSecond, block.timestamp); if (endsAt_ - block.timestamp < MIN_SESSION_DURATION) { revert SessionTooShort(); } + // do we need to specify the amount in id? bytes32 sessionId_ = getSessionId(_msgSender(), bid_.provider, amount_, incrementSessionNonce()); setSession( sessionId_, @@ -82,13 +84,13 @@ contract SessionRouter is user: _msgSender(), provider: bid_.provider, modelId: bid_.modelId, - bidID: bidId_, + bidId: bidId_, stake: amount_, pricePerSecond: bid_.pricePerSecond, closeoutReceipt: "", closeoutType: 0, providerWithdrawnAmount: 0, - openedAt: uint128(block.timestamp), + openedAt: block.timestamp, endsAt: endsAt_, closedAt: 0 }) @@ -132,7 +134,7 @@ contract SessionRouter is // update session record session.closeoutReceipt = receiptEncoded_; //TODO: remove that field in favor of tps and ttftMs - session.closedAt = uint128(block.timestamp); + session.closedAt = block.timestamp; // calculate provider withdraw uint256 providerWithdraw_; @@ -200,19 +202,18 @@ contract SessionRouter is // withdraw provider _rewardProvider(session, providerWithdraw_, false); - // withdraw user getToken().safeTransfer(session.user, userWithdraw_); } /// @notice allows provider to claim their funds function claimProviderBalance(bytes32 sessionId_, uint256 amountToWithdraw_) external { Session storage session = _getSession(sessionId_); - if (!_ownerOrProvider(session.provider)) { - revert NotOwnerOrProvider(); - } if (session.openedAt == 0) { revert SessionNotFound(); } + if (!_ownerOrProvider(session.provider)) { + revert NotOwnerOrProvider(); + } uint256 withdrawableAmount = _getProviderClaimableBalance(session); if (amountToWithdraw_ > withdrawableAmount) { @@ -224,6 +225,7 @@ contract SessionRouter is /// @notice deletes session from the history function deleteHistory(bytes32 sessionId_) external { + // Why do we need this function? Session storage session = _getSession(sessionId_); if (!_ownerOrUser(session.user)) { revert NotOwnerOrUser(); @@ -294,7 +296,7 @@ contract SessionRouter is /// @dev parameters should be the same as in Ethereum L1 Distribution contract /// @dev at address 0x47176B2Af9885dC6C4575d4eFd63895f7Aaa4790 /// @dev call 'Distribution.pools(3)' where '3' is a poolId - function setPoolConfig(uint256 index, Pool calldata pool) public onlyOwner { + function setPoolConfig(uint256 index, Pool calldata pool) external onlyOwner { if (index >= getPools().length) { revert PoolIndexOutOfBounds(); } diff --git a/smart-contracts/contracts/diamond/storages/BidStorage.sol b/smart-contracts/contracts/diamond/storages/BidStorage.sol index 0ba77927..8c418ace 100644 --- a/smart-contracts/contracts/diamond/storages/BidStorage.sol +++ b/smart-contracts/contracts/diamond/storages/BidStorage.sol @@ -92,7 +92,7 @@ contract BidStorage is IBidStorage { _getBidStorage().modelBids[modelId].push(bidId); } - function addBid(bytes32 bidId, Bid memory bid) internal { + function setBid(bytes32 bidId, Bid memory bid) internal { _getBidStorage().bids[bidId] = bid; } diff --git a/smart-contracts/contracts/diamond/storages/ModelStorage.sol b/smart-contracts/contracts/diamond/storages/ModelStorage.sol index 917f4639..22e8fc8f 100644 --- a/smart-contracts/contracts/diamond/storages/ModelStorage.sol +++ b/smart-contracts/contracts/diamond/storages/ModelStorage.sol @@ -37,8 +37,8 @@ contract ModelStorage is IModelStorage { _getModelStorage().models[modelId] = model; } - function setModelMinimumStake(uint256 _modelMinimumStake) internal { - _getModelStorage().modelMinimumStake = _modelMinimumStake; + function _setModelMinimumStake(uint256 modelMinimumStake_) internal { + _getModelStorage().modelMinimumStake = modelMinimumStake_; } function models(bytes32 id) internal view returns (Model storage) { diff --git a/smart-contracts/contracts/diamond/storages/SessionStorage.sol b/smart-contracts/contracts/diamond/storages/SessionStorage.sol index 590ad31a..1c469c1c 100644 --- a/smart-contracts/contracts/diamond/storages/SessionStorage.sol +++ b/smart-contracts/contracts/diamond/storages/SessionStorage.sol @@ -104,11 +104,11 @@ contract SessionStorage is ISessionStorage { return _getSessionStorage().sessionNonce++; } - function isApproved(bytes memory approval) internal view returns (bool) { + function isApprovalUsed(bytes memory approval) internal view returns (bool) { return _getSessionStorage().isApprovalUsed[approval]; } - function approve(bytes memory approval) internal { + function setApprovalUsed(bytes memory approval) internal { _getSessionStorage().isApprovalUsed[approval] = true; } diff --git a/smart-contracts/contracts/interfaces/facets/IModelRegistry.sol b/smart-contracts/contracts/interfaces/facets/IModelRegistry.sol index 3678c9e2..61cad56a 100644 --- a/smart-contracts/contracts/interfaces/facets/IModelRegistry.sol +++ b/smart-contracts/contracts/interfaces/facets/IModelRegistry.sol @@ -6,7 +6,7 @@ import {IModelStorage} from "../storage/IModelStorage.sol"; interface IModelRegistry is IModelStorage { event ModelRegisteredUpdated(address indexed owner, bytes32 indexed modelId); event ModelDeregistered(address indexed owner, bytes32 indexed modelId); - event ModelMinStakeUpdated(uint256 newStake); + event ModelMinimumStakeSet(uint256 newStake); error ModelNotFound(); error StakeTooLow(); @@ -15,7 +15,7 @@ interface IModelRegistry is IModelStorage { function __ModelRegistry_init() external; - function modelSetMinStake(uint256 modelMinimumStake_) external; + function setModelMinimumStake(uint256 modelMinimumStake_) external; function modelRegister( bytes32 modelId_, diff --git a/smart-contracts/contracts/interfaces/storage/ISessionStorage.sol b/smart-contracts/contracts/interfaces/storage/ISessionStorage.sol index 4aada91e..6843c89e 100644 --- a/smart-contracts/contracts/interfaces/storage/ISessionStorage.sol +++ b/smart-contracts/contracts/interfaces/storage/ISessionStorage.sol @@ -7,11 +7,11 @@ interface ISessionStorage { address user; address provider; bytes32 modelId; - bytes32 bidID; + bytes32 bidId; uint256 stake; uint256 pricePerSecond; bytes closeoutReceipt; - uint256 closeoutType; + uint256 closeoutType; // use enum ?? // amount of funds that was already withdrawn by provider (we allow to withdraw for the previous day) uint256 providerWithdrawnAmount; uint256 openedAt; diff --git a/smart-contracts/test/diamond/Marketplace.test.ts b/smart-contracts/test/diamond/Marketplace.test.ts index 130dce41..a651de42 100644 --- a/smart-contracts/test/diamond/Marketplace.test.ts +++ b/smart-contracts/test/diamond/Marketplace.test.ts @@ -138,7 +138,7 @@ describe('Marketplace', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; diff --git a/smart-contracts/test/diamond/ModelRegistry.test.ts b/smart-contracts/test/diamond/ModelRegistry.test.ts index 7c109e71..35445a75 100644 --- a/smart-contracts/test/diamond/ModelRegistry.test.ts +++ b/smart-contracts/test/diamond/ModelRegistry.test.ts @@ -138,7 +138,7 @@ describe('Model registry', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; @@ -270,7 +270,7 @@ describe('Model registry', () => { it('Should error when registering with insufficient stake', async () => { const minStake = 100n; - await modelRegistry.modelSetMinStake(minStake); + await modelRegistry.setModelMinimumStake(minStake); await expect( modelRegistry.modelRegister(randomBytes32(), randomBytes32(), 0n, 0n, OWNER, 'a', []), @@ -472,14 +472,14 @@ describe('Model registry', () => { describe('Min stake', () => { it('Should set min stake', async () => { const minStake = 100n; - await expect(modelRegistry.modelSetMinStake(minStake)) - .to.emit(modelRegistry, 'ModelMinStakeUpdated') + await expect(modelRegistry.setModelMinimumStake(minStake)) + .to.emit(modelRegistry, 'ModelMinimumStakeSet') .withArgs(minStake); expect(await modelRegistry.modelMinimumStake()).eq(minStake); }); it('Should error when not owner is setting min stake', async () => { - await expect(modelRegistry.connect(THIRD).modelSetMinStake(0)).to.revertedWith( + await expect(modelRegistry.connect(THIRD).setModelMinimumStake(0)).to.revertedWith( 'OwnableDiamondStorage: not an owner', ); }); diff --git a/smart-contracts/test/diamond/ProviderRegistry.test.ts b/smart-contracts/test/diamond/ProviderRegistry.test.ts index e14405dd..feac7070 100644 --- a/smart-contracts/test/diamond/ProviderRegistry.test.ts +++ b/smart-contracts/test/diamond/ProviderRegistry.test.ts @@ -136,7 +136,7 @@ describe('Provider registry', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; diff --git a/smart-contracts/test/diamond/SessionRouter/closeSession.test.ts b/smart-contracts/test/diamond/SessionRouter/closeSession.test.ts index 716c75b1..072c6b71 100644 --- a/smart-contracts/test/diamond/SessionRouter/closeSession.test.ts +++ b/smart-contracts/test/diamond/SessionRouter/closeSession.test.ts @@ -114,7 +114,7 @@ describe('Session closeout', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }, ] @@ -149,7 +149,7 @@ describe('Session closeout', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; @@ -253,7 +253,7 @@ describe('Session closeout', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }; @@ -265,7 +265,7 @@ describe('Session closeout', () => { it('should open short (<1D) session and close after expiration', async () => { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -298,7 +298,7 @@ describe('Session closeout', () => { it('should open short (<1D) session and close early', async () => { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -328,7 +328,7 @@ describe('Session closeout', () => { it('should open and close early with user report - dispute', async () => { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -377,7 +377,7 @@ describe('Session closeout', () => { it('should error when not a user trying to close', async () => { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -429,7 +429,7 @@ describe('Session closeout', () => { user: await SECOND.getAddress(), provider: expectedBid.providerAddr, modelId: expectedBid.modelId, - bidID: expectedBid.id, + bidId: expectedBid.id, stake: (totalCost * totalSupply) / todaysBudget, }; @@ -438,7 +438,7 @@ describe('Session closeout', () => { await MOR.connect(SECOND).approve(modelRegistry, expectedSession.stake); // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), expectedSession.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), expectedSession.bidId); const sessionId = await sessionRouter .connect(SECOND) .openSession.staticCall(expectedSession.stake, msg, signature); @@ -476,7 +476,7 @@ describe('Session closeout', () => { it('should error if session is already closed', async () => { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -494,7 +494,7 @@ describe('Session closeout', () => { }); it('should error when approval expired', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const ttl = await sessionRouter.SIGNATURE_TTL(); await setTime(Number((await getCurrentBlockTime()) + ttl) + 1); diff --git a/smart-contracts/test/diamond/SessionRouter/openSession.test.ts b/smart-contracts/test/diamond/SessionRouter/openSession.test.ts index 79cc78ed..8bd0b1f6 100644 --- a/smart-contracts/test/diamond/SessionRouter/openSession.test.ts +++ b/smart-contracts/test/diamond/SessionRouter/openSession.test.ts @@ -113,7 +113,7 @@ describe('session actions', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }, ] @@ -148,7 +148,7 @@ describe('session actions', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; @@ -160,7 +160,7 @@ describe('session actions', () => { async function openSession(session: any) { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -261,7 +261,7 @@ describe('session actions', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }; @@ -273,7 +273,7 @@ describe('session actions', () => { describe('positive cases', () => { it('should open session without error', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -281,7 +281,7 @@ describe('session actions', () => { }); it('should emit SessionOpened event', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await expect(sessionRouter.connect(SECOND).openSession(session.stake, msg, signature)) @@ -290,7 +290,7 @@ describe('session actions', () => { }); it('should verify session fields after opening', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -302,7 +302,7 @@ describe('session actions', () => { await resolveAddress(session.user), await resolveAddress(session.provider), session.modelId, - session.bidID, + session.bidId, session.stake, session.pricePerSecond, getHex(Buffer.from(''), 0), @@ -318,7 +318,7 @@ describe('session actions', () => { const srBefore = await MOR.balanceOf(sessionRouter); const userBefore = await MOR.balanceOf(SECOND); - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); const srAfter = await MOR.balanceOf(sessionRouter); @@ -332,9 +332,9 @@ describe('session actions', () => { await MOR.transfer(SECOND, session.stake * 2n); await MOR.connect(SECOND).approve(sessionRouter, session.stake * 2n); - const apprv1 = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const apprv1 = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await setTime(Number(await getCurrentBlockTime()) + 1); - const apprv2 = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const apprv2 = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await ethers.provider.send('evm_setAutomine', [false]); @@ -374,7 +374,7 @@ describe('session actions', () => { const stake = avail / 2n; - const approval = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const approval = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await sessionRouter.connect(SECOND).openSession(stake, approval.msg, approval.signature); const [avail2] = await sessionRouter.withdrawableUserStake(SECOND, 255); @@ -397,7 +397,7 @@ describe('session actions', () => { // reset allowance await MOR.connect(SECOND).approve(sessionRouter, 0n); - const approval = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const approval = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await sessionRouter.connect(SECOND).openSession(avail, approval.msg, approval.signature); const [avail2] = await sessionRouter.withdrawableUserStake(SECOND, 255); @@ -423,7 +423,7 @@ describe('session actions', () => { // reset allowance await MOR.connect(SECOND).approve(sessionRouter, allowancePart); - const approval = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const approval = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await sessionRouter.connect(SECOND).openSession(avail + allowancePart, approval.msg, approval.signature); // check all onHold used @@ -438,7 +438,7 @@ describe('session actions', () => { describe('negative cases', () => { it('should error when approval generated for a different user', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await THIRD.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await THIRD.getAddress(), session.bidId); await expect( sessionRouter.connect(SECOND).openSession(session.stake, msg, signature), @@ -446,7 +446,7 @@ describe('session actions', () => { }); it('should error when approval expired', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const ttl = await sessionRouter.SIGNATURE_TTL(); await setTime(Number((await getCurrentBlockTime()) + ttl) + 1); @@ -463,16 +463,16 @@ describe('session actions', () => { }); it('should error when bid is deleted', async () => { - await marketplace.connect(PROVIDER).deleteModelBid(session.bidID); + await marketplace.connect(PROVIDER).deleteModelBid(session.bidId); - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await expect( sessionRouter.connect(SECOND).openSession(session.stake, msg, signature), ).to.be.revertedWithCustomError(sessionRouter, 'BidNotFound'); }); it('should error when signature has invalid length', async () => { - const { msg } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await expect(sessionRouter.connect(SECOND).openSession(session.stake, msg, '0x00')).to.be.revertedWith( 'ECDSA: invalid signature length', @@ -480,7 +480,7 @@ describe('session actions', () => { }); it('should error when signature is invalid', async () => { - const { msg } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sig = randomBytes(65); await expect(sessionRouter.connect(SECOND).openSession(session.stake, msg, sig)).to.be.revertedWith( @@ -489,7 +489,7 @@ describe('session actions', () => { }); it('should error when opening two bids with same signature', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); await approveUserFunds(session.stake); @@ -500,16 +500,16 @@ describe('session actions', () => { }); it('should not error when opening two bids same time', async () => { - const appr1 = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const appr1 = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await sessionRouter.connect(SECOND).openSession(session.stake, appr1.msg, appr1.signature); await approveUserFunds(session.stake); - const appr2 = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const appr2 = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await sessionRouter.connect(SECOND).openSession(session.stake, appr2.msg, appr2.signature); }); it('should error with insufficient allowance', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await expect(sessionRouter.connect(SECOND).openSession(session.stake * 2n, msg, signature)).to.be.revertedWith( 'ERC20: insufficient allowance', ); @@ -519,14 +519,14 @@ describe('session actions', () => { const stake = (await MOR.balanceOf(SECOND)) + 1n; await MOR.connect(SECOND).approve(sessionRouter, stake); - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await expect(sessionRouter.connect(SECOND).openSession(stake, msg, signature)).to.be.revertedWith( 'ERC20: transfer amount exceeds balance', ); }); it('should error if session time too short', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); await expect(sessionRouter.connect(SECOND).openSession(0, msg, signature)).to.be.revertedWithCustomError( sessionRouter, 'SessionTooShort', @@ -534,7 +534,7 @@ describe('session actions', () => { }); it('should error if chainId is invalid', async () => { - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID, 1n); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId, 1n); await expect(sessionRouter.connect(SECOND).openSession(0, msg, signature)).to.be.revertedWithCustomError( sessionRouter, 'WrongChainId', @@ -547,7 +547,7 @@ describe('session actions', () => { const durationSeconds = HOUR; const stake = await getStake(durationSeconds, session.pricePerSecond); - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(stake, msg, signature); await sessionRouter.connect(SECOND).openSession(stake, msg, signature); @@ -565,7 +565,7 @@ describe('session actions', () => { const stake = await getStake(durationSeconds, session.pricePerSecond); await approveUserFunds(stake); - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(stake, msg, signature); await sessionRouter.connect(SECOND).openSession(stake, msg, signature); @@ -588,7 +588,7 @@ describe('session actions', () => { await approveUserFunds(stake); - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(stake, msg, signature); await sessionRouter.connect(SECOND).openSession(stake, msg, signature); diff --git a/smart-contracts/test/diamond/SessionRouter/readFunctions.test.ts b/smart-contracts/test/diamond/SessionRouter/readFunctions.test.ts index 5e5a5a8f..32055993 100644 --- a/smart-contracts/test/diamond/SessionRouter/readFunctions.test.ts +++ b/smart-contracts/test/diamond/SessionRouter/readFunctions.test.ts @@ -113,7 +113,7 @@ describe('Session router', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }, ] @@ -148,7 +148,7 @@ describe('Session router', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; @@ -252,7 +252,7 @@ describe('Session router', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }; @@ -311,7 +311,7 @@ describe('Session router', () => { describe('getProviderClaimableBalance', () => { it('should be correct for contract that closed early due to dispute [H-6]', async () => { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); diff --git a/smart-contracts/test/diamond/SessionRouter/stats.test.ts b/smart-contracts/test/diamond/SessionRouter/stats.test.ts index 325a0e87..850c6742 100644 --- a/smart-contracts/test/diamond/SessionRouter/stats.test.ts +++ b/smart-contracts/test/diamond/SessionRouter/stats.test.ts @@ -113,7 +113,7 @@ describe('Session router - stats tests', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }, ] @@ -148,7 +148,7 @@ describe('Session router - stats tests', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; @@ -251,7 +251,7 @@ describe('Session router - stats tests', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }; @@ -262,13 +262,13 @@ describe('Session router - stats tests', () => { }); it('should update provider-model stats', async () => { - await openCloseSession(session.bidID, HOUR, session.pricePerSecond, 100, 1000, true); + await openCloseSession(session.bidId, HOUR, session.pricePerSecond, 100, 1000, true); - await openCloseSession(session.bidID, HOUR, session.pricePerSecond, 150, 2000, true); + await openCloseSession(session.bidId, HOUR, session.pricePerSecond, 150, 2000, true); const [bidIds, bids, stats] = await sessionRouter.getActiveBidsRatingByModel(session.modelId, 0n, 100); - expect(bidIds).to.deep.equal([session.bidID]); + expect(bidIds).to.deep.equal([session.bidId]); expect(bids[0]).to.deep.equal([ await resolveAddress(bid.provider), bid.modelId, @@ -285,7 +285,7 @@ describe('Session router - stats tests', () => { }); async function openCloseSession( - bidID: string, + bidId: string, durationSeconds: bigint, pricePerSecond: bigint, tps: number, @@ -293,7 +293,7 @@ describe('Session router - stats tests', () => { success = true, ) { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), bidId); const stake = await getStake(durationSeconds, pricePerSecond); await MOR.transfer(SECOND, stake); diff --git a/smart-contracts/test/diamond/SessionRouter/userOnHold.test.ts b/smart-contracts/test/diamond/SessionRouter/userOnHold.test.ts index 88aea6c8..f6bb1121 100644 --- a/smart-contracts/test/diamond/SessionRouter/userOnHold.test.ts +++ b/smart-contracts/test/diamond/SessionRouter/userOnHold.test.ts @@ -114,7 +114,7 @@ describe('User on hold tests', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }, ] @@ -149,7 +149,7 @@ describe('User on hold tests', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; @@ -161,7 +161,7 @@ describe('User on hold tests', () => { async function openSession(session: any) { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -271,7 +271,7 @@ describe('User on hold tests', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }; let sessionId: string; diff --git a/smart-contracts/test/diamond/SessionRouter/writeFunctions.test.ts b/smart-contracts/test/diamond/SessionRouter/writeFunctions.test.ts index 67f4dc4f..34e1be37 100644 --- a/smart-contracts/test/diamond/SessionRouter/writeFunctions.test.ts +++ b/smart-contracts/test/diamond/SessionRouter/writeFunctions.test.ts @@ -114,7 +114,7 @@ describe('Session router', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }, ] @@ -149,7 +149,7 @@ describe('Session router', () => { user: SECOND, provider: bid.provider, modelId: bid.modelId, - bidID: bid.id, + bidId: bid.id, stake: (totalCost * totalSupply) / todaysBudget, }; @@ -161,7 +161,7 @@ describe('Session router', () => { async function openSession(session: any) { // open session - const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidID); + const { msg, signature } = await getProviderApproval(PROVIDER, await SECOND.getAddress(), session.bidId); const sessionId = await sessionRouter.connect(SECOND).openSession.staticCall(session.stake, msg, signature); await sessionRouter.connect(SECOND).openSession(session.stake, msg, signature); @@ -284,7 +284,7 @@ describe('Session router', () => { user: SignerWithAddress; provider: SignerWithAddress; modelId: any; - bidID: string; + bidId: string; stake: bigint; }; let sessionId: string;