Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/v0.8/core/carstore/Carstore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,7 @@ contract Carstore is Initializable, UUPSUpgradeable, CarstoreBase {
uint64 _id,
uint64 _matchingId,
bool _matchingState
)
external
onlyRole(roles, RolesType.DATASWAP_CONTRACT)
onlyCarExist(this, _id)
onlyNotZero(_matchingId)
onlyCarReplicaExist(this, _id, _matchingId)
{
) external onlyRole(roles, RolesType.DATASWAP_CONTRACT) {
if (_matchingState) {
_emitRepicaEvent(
_id,
Expand All @@ -186,6 +180,24 @@ contract Carstore is Initializable, UUPSUpgradeable, CarstoreBase {
);
}
}
/// @dev Reports a failure in car replica storage.
/// @param _id The ID associated with the car replica.
/// @param _matchingId The ID of the matching process related to the storage failure.
function __reportCarReplicaStorageFailed(
uint64 _id,
uint64 _matchingId
)
external
onlyRole(roles, RolesType.DATASWAP_CONTRACT)
onlyCarReplicaState(
this,
_id,
_matchingId,
CarReplicaType.State.Matched
)
{
_emitRepicaEvent(_id, _matchingId, CarReplicaType.Event.StorageFailed);
}

function _checkCarReplicaDealState(
uint64 _id,
Expand All @@ -211,9 +223,6 @@ contract Carstore is Initializable, UUPSUpgradeable, CarstoreBase {
)
external
onlyRole(roles, RolesType.DATASWAP_CONTRACT)
onlyCarExist(this, _id)
onlyNotZero(_matchingId)
onlyCarReplicaExist(this, _id, _matchingId)
onlyCarReplicaState(this, _id, _matchingId, CarReplicaType.State.Stored)
{
_checkCarReplicaDealState(
Expand All @@ -240,9 +249,6 @@ contract Carstore is Initializable, UUPSUpgradeable, CarstoreBase {
)
external
onlyRole(roles, RolesType.DATASWAP_CONTRACT)
onlyCarExist(this, _id)
onlyNotZero(_matchingId)
onlyCarReplicaExist(this, _id, _matchingId)
onlyCarReplicaState(this, _id, _matchingId, CarReplicaType.State.Stored)
{
_checkCarReplicaDealState(
Expand Down
2 changes: 1 addition & 1 deletion src/v0.8/core/filplus/Filplus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {FinanceType} from "src/v0.8/types/FinanceType.sol";
contract Filplus is Initializable, UUPSUpgradeable, IFilplus, RolesModifiers {
using ArrayUint16LIB for uint16[];
using ArrayUint32LIB for uint32[];
IRoles private roles;
IRoles public roles;
// solhint-disable-next-line
address public GOVERNANCE_ADDRESS; //The address of the governance contract.

Expand Down
30 changes: 24 additions & 6 deletions src/v0.8/core/finance/escrow/EscrowDataTradingFee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ contract EscrowDataTradingFee is EscrowBase {
_datasetId
);

uint256 amount = __getRequirement(_datasetId,_destMatchingId,payer, _token);
uint256 amount = __getRequirement(
_datasetId,
_destMatchingId,
payer,
_token
);

FinanceType.PayeeInfo[] memory payees = new FinanceType.PayeeInfo[](1);
payees[0] = FinanceType.PayeeInfo(payer, amount);
Expand All @@ -194,8 +199,14 @@ contract EscrowDataTradingFee is EscrowBase {
uint64 _matchingId,
address _payer,
address _token
) public view override onlyRole(roles, RolesType.DATASWAP_CONTRACT) returns (uint256 amount) {
(, , uint256 current, uint256 total ) = roles.finance().getAccountEscrow(
)
public
view
override
onlyRole(roles, RolesType.DATASWAP_CONTRACT)
returns (uint256 amount)
{
(, , uint256 current, uint256 total) = roles.finance().getAccountEscrow(
_datasetId,
_matchingId,
_payer,
Expand All @@ -208,9 +219,16 @@ contract EscrowDataTradingFee is EscrowBase {
_matchingId,
_payer
);
} else if (_payer == roles.datasets().getDatasetMetadataSubmitter(_datasetId)) {
} else if (
_payer == roles.datasets().getDatasetMetadataSubmitter(_datasetId)
) {
if (total <= 0) {
amount = _getSubsidyAmount(_datasetId, _matchingId, _payer, _token);
amount = _getSubsidyAmount(
_datasetId,
_matchingId,
_payer,
_token
);
} else {
amount = total;
}
Expand Down Expand Up @@ -361,7 +379,7 @@ contract EscrowDataTradingFee is EscrowBase {
function _isEscrowRefund(uint64 _matchingId) internal view returns (bool) {
return
_matchingId != 0 &&
roles.storages().isStorageExpiration(_matchingId);
roles.storages().isStorageCompleted(_matchingId);
}

/// @dev Internal function to check if a parent account refund is applicable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ contract EscrowDatacapChunkLandCollateral is EscrowBase {
uint64 _matchingId,
address _payer,
address _token
) public view override onlyRole(roles, RolesType.DATASWAP_CONTRACT) returns (uint256 amount) {
)
public
view
override
onlyRole(roles, RolesType.DATASWAP_CONTRACT)
returns (uint256 amount)
{
(, , uint256 current, ) = roles.finance().getAccountEscrow(
_datasetId,
_matchingId,
Expand Down Expand Up @@ -141,7 +147,7 @@ contract EscrowDatacapChunkLandCollateral is EscrowBase {
uint64 _matchingId
) internal view override returns (bool refund) {
return ((_matchingId != 0 &&
roles.storages().isStorageExpiration(_matchingId)) ||
roles.storages().isStorageCompleted(_matchingId)) ||
roles.datasets().getDatasetState(_datasetId) ==
DatasetType.State.Rejected);
}
Expand All @@ -154,6 +160,6 @@ contract EscrowDatacapChunkLandCollateral is EscrowBase {
uint64 _matchingId
) internal view override returns (bool burn) {
return (_matchingId != 0 &&
roles.storages().isStorageExpiration(_matchingId));
roles.storages().isStorageCompleted(_matchingId));
}
}
11 changes: 11 additions & 0 deletions src/v0.8/interfaces/core/ICarstore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ interface ICarstore is ICarstoreReadOnly {
bool _matchingState
) external;

/// @dev Reports a failure in car replica storage.
/// @param _id The ID associated with the car replica.
/// @param _matchingId The ID of the matching process related to the storage failure.
function __reportCarReplicaStorageFailed(
uint64 _id,
uint64 _matchingId
) external;

/// @notice Report that storage deal for a replica has expired.
/// @dev This function allows reporting that the storage deal for a replica has expired.
/// @param _id Car ID associated with the replica.
Expand Down Expand Up @@ -265,4 +273,7 @@ interface ICarstore is ICarstoreReadOnly {
uint64 _datasetId,
uint16 _replicaCount
) external;
/// @notice Get the Roles contract.
/// @return Roles contract address.
function roles() external view returns (IRoles);
}
5 changes: 5 additions & 0 deletions src/v0.8/interfaces/core/IEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
pragma solidity ^0.8.21;

import {FinanceType} from "src/v0.8/types/FinanceType.sol";
import {IRoles} from "src/v0.8/interfaces/core/IRoles.sol";

/// @title IEscrow
/// @dev This IEscrow provides Escrow-related interface.
Expand Down Expand Up @@ -56,4 +57,8 @@ interface IEscrow {
address _owner,
address _token
) external view returns (uint256 amount);

/// @notice Get the Roles contract.
/// @return Roles contract address.
function roles() external view returns (IRoles);
}
6 changes: 5 additions & 1 deletion src/v0.8/interfaces/core/IFilplus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
pragma solidity ^0.8.21;

import {FinanceType} from "src/v0.8/types/FinanceType.sol";

import {IRoles} from "src/v0.8/interfaces/core/IRoles.sol";
/// @title IFilplus
interface IFilplus {
// Public getter function to access datasetRuleMaxReplicasInCountries
Expand Down Expand Up @@ -275,4 +275,8 @@ interface IFilplus {
function isCompliantRuleMaxReplicasPerSP(
uint16 _value
) external view returns (bool);

/// @notice Get the Roles contract.
/// @return Roles contract address.
function roles() external view returns (IRoles);
}
6 changes: 5 additions & 1 deletion src/v0.8/interfaces/core/IFinance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pragma solidity ^0.8.21;

import {FinanceType} from "src/v0.8/types/FinanceType.sol";
import {IBusinessFinanceStatistics} from "src/v0.8/interfaces/core/statistics/IBusinessFinanceStatistics.sol";

import {IRoles} from "src/v0.8/interfaces/core/IRoles.sol";
/// @title IPayment Interface
/// @notice This interface defines the payment-related functions within the system.
/// @notice instance example,type: mapping(uint256 => mapping(uint256 => mapping(address => mapping(address=>Account))));
Expand Down Expand Up @@ -196,4 +196,8 @@ interface IFinance is IBusinessFinanceStatistics {
address _token,
FinanceType.Type _type
) external view returns (bool);

/// @notice Get the Roles contract.
/// @return Roles contract address.
function roles() external view returns (IRoles);
}
13 changes: 12 additions & 1 deletion src/v0.8/interfaces/module/IStorages.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

pragma solidity ^0.8.21;

import {IRoles} from "src/v0.8/interfaces/core/IRoles.sol";
import {IStorageStatistics} from "src/v0.8/interfaces/core/statistics/IStorageStatistics.sol";

/// @title Interface for Matchedstores contract
Expand All @@ -35,6 +34,11 @@ interface IStorages is IStorageStatistics {
uint64[] memory _claimIds
) external;

/// @dev Completes the storage process for a given matching ID.
/// @param _matchingId The ID of the matching.
/// @param _ids An array of content identifiers of the matched data.
function completeStorage(uint64 _matchingId, uint64[] memory _ids) external;

/// @dev Gets the list of done cars in the matchedstore.
/// @param _matchingId The ID of the matching.
/// @return An array of content identifiers of the done cars.
Expand All @@ -59,6 +63,13 @@ interface IStorages is IStorageStatistics {
uint64 _matchingId
) external view returns (bool);

/// @dev Checks if the storage process is completed for a given matching ID.
/// @param _matchingId The ID of the matching.
/// @return A boolean indicating whether the storage process is completed or not.
function isStorageCompleted(
uint64 _matchingId
) external view returns (bool);

/// @dev Requests the allocation of matched datacap for a matching process.
/// @param _matchingId The ID of the matching process.
function requestAllocateDatacap(
Expand Down
64 changes: 64 additions & 0 deletions src/v0.8/module/storage/Storages.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,62 @@ contract Storages is
);
}

/// @dev Completes the storage process for a given matching ID.
/// @param _matchingId The ID of the matching.
function completeStorage(uint64 _matchingId, uint64[] memory _ids) public {
StorageType.Storage storage storage_ = storages[_matchingId];
(
uint64 datasetId,
uint64[] memory cars,
,
,
,
uint16 replicaIndex
) = roles.matchingsTarget().getMatchingTarget(_matchingId);

if (storage_.doneCars.length < cars.length) {
require(isStorageExpiration(_matchingId), "Storage is in progress");
require(
storage_.doneCars.length + _ids.length == cars.length,
"invalid cars number"
);

for (uint256 i = 0; i < _ids.length; i++) {
require(
CarReplicaType.State.Matched ==
roles.carstore().getCarReplicaState(
_ids[i],
_matchingId
),
"Invalid Replica State"
);
roles.carstore().__reportCarReplicaStorageFailed(
_ids[i],
_matchingId
);
uint64 carSize = roles.carstore().getCarSize(_ids[i]);
_addCanceled(datasetId, replicaIndex, _matchingId, carSize);
}
}

storage_.completed = true;

// Payment data trading fee
roles.finance().claimEscrow(
datasetId,
_matchingId,
FinanceType.FIL,
FinanceType.Type.EscrowDatacapChunkLandCollateral
);

roles.finance().claimEscrow(
datasetId,
_matchingId,
FinanceType.FIL,
FinanceType.Type.EscrowDataTradingFee
);
}

/// @dev Gets the list of done cars in the matchedstore.
function getStoredCars(
uint64 _matchingId
Expand Down Expand Up @@ -213,6 +269,14 @@ contract Storages is
}
}

/// @dev Checks if the storage process is completed for a given matching ID.
/// @param _matchingId The ID of the matching.
/// @return A boolean indicating whether the storage process is completed or not.
function isStorageCompleted(uint64 _matchingId) public view returns (bool) {
StorageType.Storage storage storage_ = storages[_matchingId];
return storage_.completed;
}

/// @dev Internal function to allocate matched datacap.
// solhint-disable-next-line
function _allocateDatacap(
Expand Down
1 change: 1 addition & 0 deletions src/v0.8/types/StorageType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ library StorageType {
/// @notice Struct representing a storage deal.
struct Storage {
uint64[] doneCars;
bool completed;
}
}
Loading