Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

refactor cbor functions for market actor #198

Merged
merged 1 commit into from
Jan 31, 2023
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
106 changes: 26 additions & 80 deletions contracts/v0.8/MarketAPI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,7 @@ import "./utils/Actor.sol";
/// @author Zondax AG
library MarketAPI {
using BytesCBOR for bytes;
using DealIDCBOR for uint64;
using WithdrawBalanceCBOR for MarketTypes.WithdrawBalanceParams;
using WithdrawBalanceCBOR for MarketTypes.WithdrawBalanceReturn;
using GetBalanceCBOR for MarketTypes.GetBalanceReturn;
using GetDealDataCommitmentCBOR for MarketTypes.GetDealDataCommitmentReturn;
using GetDealClientCBOR for MarketTypes.GetDealClientReturn;
using GetDealProviderCBOR for MarketTypes.GetDealProviderReturn;
using GetDealLabelCBOR for MarketTypes.GetDealLabelReturn;
using GetDealTermCBOR for MarketTypes.GetDealTermReturn;
using GetDealEpochPriceCBOR for MarketTypes.GetDealEpochPriceReturn;
using GetDealClientCollateralCBOR for MarketTypes.GetDealClientCollateralReturn;
using GetDealProviderCollateralCBOR for MarketTypes.GetDealProviderCollateralReturn;
using GetDealVerifiedCBOR for MarketTypes.GetDealVerifiedReturn;
using GetDealActivationCBOR for MarketTypes.GetDealActivationReturn;
using PublishStorageDealsCBOR for MarketTypes.PublishStorageDealsParams;
using PublishStorageDealsCBOR for MarketTypes.PublishStorageDealsReturn;
using MarketCBOR for *;

/// @notice Deposits the received value into the balance held in escrow.
function addBalance(bytes memory provider_or_client) internal {
Expand All @@ -66,7 +51,7 @@ library MarketAPI {
/// @notice Attempt to withdraw the specified amount from the balance held in escrow.
/// @notice If less than the specified amount is available, yields the entire available balance.
function withdrawBalance(MarketTypes.WithdrawBalanceParams memory params) internal returns (MarketTypes.WithdrawBalanceReturn memory) {
bytes memory raw_request = params.serialize();
bytes memory raw_request = params.serializeWithdrawBalanceParams();

bytes memory raw_response = Actor.call(
MarketTypes.WithdrawBalanceMethodNum,
Expand All @@ -78,10 +63,7 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.WithdrawBalanceReturn memory response;
response.deserialize(result);

return response;
return result.deserializeWithdrawBalanceReturn();
}

/// @return the escrow balance and locked amount for an address.
Expand All @@ -98,16 +80,13 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetBalanceReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetBalanceReturn();
}

/// @return the data commitment and size of a deal proposal.
/// @notice This will be available after the deal is published (whether or not is is activated) and up until some undefined period after it is terminated.
function getDealDataCommitment(uint64 dealID) internal returns (MarketTypes.GetDealDataCommitmentReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealDataCommitmentMethodNum,
Expand All @@ -119,15 +98,12 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealDataCommitmentReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealDataCommitmentReturn();
}

/// @return the client of a deal proposal.
function getDealClient(uint64 dealID) internal returns (MarketTypes.GetDealClientReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealClientMethodNum,
Expand All @@ -139,15 +115,12 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealClientReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealClientReturn();
}

/// @return the provider of a deal proposal.
function getDealProvider(uint64 dealID) internal returns (MarketTypes.GetDealProviderReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealProviderMethodNum,
Expand All @@ -159,15 +132,12 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealProviderReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealProviderReturn();
}

/// @return the label of a deal proposal.
function getDealLabel(uint64 dealID) internal returns (MarketTypes.GetDealLabelReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealLabelMethodNum,
Expand All @@ -179,15 +149,12 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealLabelReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealLabelReturn();
}

/// @return the start epoch and duration (in epochs) of a deal proposal.
function getDealTerm(uint64 dealID) internal returns (MarketTypes.GetDealTermReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealTermMethodNum,
Expand All @@ -199,15 +166,12 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealTermReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealTermReturn();
}

/// @return the per-epoch price of a deal proposal.
function getDealTotalPrice(uint64 dealID) internal returns (MarketTypes.GetDealEpochPriceReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealEpochPriceMethodNum,
Expand All @@ -219,15 +183,12 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealEpochPriceReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealEpochPriceReturn();
}

/// @return the client collateral requirement for a deal proposal.
function getDealClientCollateral(uint64 dealID) internal returns (MarketTypes.GetDealClientCollateralReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealClientCollateralMethodNum,
Expand All @@ -239,15 +200,12 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealClientCollateralReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealClientCollateralReturn();
}

/// @return the provider collateral requirement for a deal proposal.
function getDealProviderCollateral(uint64 dealID) internal returns (MarketTypes.GetDealProviderCollateralReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealProviderCollateralMethodNum,
Expand All @@ -259,16 +217,13 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealProviderCollateralReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealProviderCollateralReturn();
}

/// @return the verified flag for a deal proposal.
/// @notice Note that the source of truth for verified allocations and claims is the verified registry actor.
function getDealVerified(uint64 dealID) internal returns (MarketTypes.GetDealVerifiedReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealVerifiedMethodNum,
Expand All @@ -280,17 +235,14 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealVerifiedReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealVerifiedReturn();
}

/// @notice Fetches activation state for a deal.
/// @notice This will be available from when the proposal is published until an undefined period after the deal finishes (either normally or by termination).
/// @return USR_NOT_FOUND if the deal doesn't exist (yet), or EX_DEAL_EXPIRED if the deal has been removed from state.
function getDealActivation(uint64 dealID) internal returns (MarketTypes.GetDealActivationReturn memory) {
bytes memory raw_request = dealID.serialize();
bytes memory raw_request = dealID.serializeDealID();

bytes memory raw_response = Actor.call(
MarketTypes.GetDealActivationMethodNum,
Expand All @@ -302,17 +254,14 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.GetDealActivationReturn memory response;
response.deserialize(result);

return response;
return result.deserializeGetDealActivationReturn();
}

/// @notice Publish a new set of storage deals (not yet included in a sector).
function publishStorageDeals(
MarketTypes.PublishStorageDealsParams memory params
) internal returns (MarketTypes.PublishStorageDealsReturn memory) {
bytes memory raw_request = params.serialize();
bytes memory raw_request = params.serializePublishStorageDealsParams();

bytes memory raw_response = Actor.call(
MarketTypes.PublishStorageDealsMethodNum,
Expand All @@ -324,9 +273,6 @@ library MarketAPI {

bytes memory result = Actor.readRespData(raw_response);

MarketTypes.PublishStorageDealsReturn memory response;
response.deserialize(result);

return response;
return result.deserializePublishStorageDealsReturn();
}
}
Loading