Skip to content
This repository was archived by the owner on Dec 9, 2022. It is now read-only.

Commit 142a1e9

Browse files
authored
solidity docs for mock methods (#14)
* add docs. * remove stale method.
1 parent 51dab29 commit 142a1e9

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

contracts/v0.8/MarketAPI.sol

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@ pragma solidity >=0.4.25 <=0.8.15;
33

44
import "./types/MarketTypes.sol";
55

6+
/// @title This contract is a proxy to the singleton Storage Market actor (address: f05). Calling one of its methods will result in a cross-actor call being performed. However, in this mock library, no actual call is performed.
7+
/// @author Zondax AG
8+
/// @dev Methods prefixed with mock_ will not be available in the real library. These methods are merely used to set mock state. Note that this interface will likely break in the future as we align it
9+
// with that of the real library!
610
contract MarketAPI {
711
mapping(string => uint256) balances;
812
mapping(uint64 => MarketTypes.MockDeal) deals;
913

1014
constructor() {
11-
generate_deal_mocks();
15+
mock_generate_deals();
1216
}
1317

18+
/// Deposits the received value into the balance held in escrow.
19+
/// @dev Because this is a mock method, no real balance is being deducted from the caller, nor incremented in the Storage Market actor (f05).
1420
function add_balance(
1521
MarketTypes.AddBalanceParams memory params
1622
) public payable {
1723
balances[params.provider_or_client] += msg.value;
1824
}
1925

26+
/// Attempt to withdraw the specified amount from the balance held in escrow.
27+
/// If less than the specified amount is available, yields the entire available balance.
28+
/// @dev This method should be called by an approved address, but the mock does not check that the caller is an approved party.
29+
/// @dev Because this is a mock method, no real balance is deposited in the designated address, nor decremented from the Storage Market actor (f05).
2030
function withdraw_balance(
2131
MarketTypes.WithdrawBalanceParams memory params
2232
) public returns (MarketTypes.WithdrawBalanceReturn memory) {
@@ -31,6 +41,7 @@ contract MarketAPI {
3141
return MarketTypes.WithdrawBalanceReturn(tmp);
3242
}
3343

44+
/// Returns the escrow balance and locked amount for an address.
3445
function get_balance(
3546
string memory addr
3647
) public view returns (MarketTypes.GetBalanceReturn memory) {
@@ -39,7 +50,11 @@ contract MarketAPI {
3950
return MarketTypes.GetBalanceReturn(actualBalance, 0);
4051
}
4152

42-
// FIXME set data values correctly
53+
/// Returns the data commitment and size of a deal proposal.
54+
/// This will be available after the deal is published (whether or not is is activated)
55+
/// and up until some undefined period after it is terminated.
56+
/// FIXME set data values correctly, currently returning fixed data, feel free to adjust
57+
/// in your local mock.
4358
function get_deal_data_commitment(
4459
MarketTypes.GetDealDataCommitmentParams memory params
4560
) public view returns (MarketTypes.GetDealDataCommitmentReturn memory) {
@@ -52,6 +67,7 @@ contract MarketAPI {
5267
);
5368
}
5469

70+
/// Returns the client of a deal proposal.
5571
function get_deal_client(
5672
MarketTypes.GetDealClientParams memory params
5773
) public view returns (MarketTypes.GetDealClientReturn memory) {
@@ -60,6 +76,7 @@ contract MarketAPI {
6076
return MarketTypes.GetDealClientReturn(deals[params.id].client);
6177
}
6278

79+
/// Returns the provider of a deal proposal.
6380
function get_deal_provider(
6481
MarketTypes.GetDealProviderParams memory params
6582
) public view returns (MarketTypes.GetDealProviderReturn memory) {
@@ -68,6 +85,7 @@ contract MarketAPI {
6885
return MarketTypes.GetDealProviderReturn(deals[params.id].provider);
6986
}
7087

88+
/// Returns the label of a deal proposal.
7189
function get_deal_label(
7290
MarketTypes.GetDealLabelParams memory params
7391
) public view returns (MarketTypes.GetDealLabelReturn memory) {
@@ -76,6 +94,7 @@ contract MarketAPI {
7694
return MarketTypes.GetDealLabelReturn(deals[params.id].label);
7795
}
7896

97+
/// Returns the start epoch and duration (in epochs) of a deal proposal.
7998
function get_deal_term(
8099
MarketTypes.GetDealTermParams memory params
81100
) public view returns (MarketTypes.GetDealTermReturn memory) {
@@ -88,6 +107,8 @@ contract MarketAPI {
88107
);
89108
}
90109

110+
/// Returns the per-epoch price of a deal proposal.
111+
/// TODO renamed to get_deal_total_price in builtin-actors.
91112
function get_deal_epoch_price(
92113
MarketTypes.GetDealEpochPriceParams memory params
93114
) public view returns (MarketTypes.GetDealEpochPriceReturn memory) {
@@ -99,6 +120,7 @@ contract MarketAPI {
99120
);
100121
}
101122

123+
/// Returns the client collateral requirement for a deal proposal.
102124
function get_deal_client_collateral(
103125
MarketTypes.GetDealClientCollateralParams memory params
104126
) public view returns (MarketTypes.GetDealClientCollateralReturn memory) {
@@ -110,6 +132,7 @@ contract MarketAPI {
110132
);
111133
}
112134

135+
/// Returns the provider collateral requirement for a deal proposal.
113136
function get_deal_provider_collateral(
114137
MarketTypes.GetDealProviderCollateralParams memory params
115138
) public view returns (MarketTypes.GetDealProviderCollateralReturn memory) {
@@ -121,6 +144,9 @@ contract MarketAPI {
121144
);
122145
}
123146

147+
/// Returns the verified flag for a deal proposal.
148+
/// Note that the source of truth for verified allocations and claims is
149+
/// the verified registry actor.
124150
function get_deal_verified(
125151
MarketTypes.GetDealVerifiedParams memory params
126152
) public view returns (MarketTypes.GetDealVerifiedReturn memory) {
@@ -129,6 +155,11 @@ contract MarketAPI {
129155
return MarketTypes.GetDealVerifiedReturn(deals[params.id].verified);
130156
}
131157

158+
/// Fetches activation state for a deal.
159+
/// This will be available from when the proposal is published until an undefined period after
160+
/// the deal finishes (either normally or by termination).
161+
/// Returns USR_NOT_FOUND if the deal doesn't exist (yet), or EX_DEAL_EXPIRED if the deal
162+
/// has been removed from state.
132163
function get_deal_activation(
133164
MarketTypes.GetDealActivationParams memory params
134165
) public view returns (MarketTypes.GetDealActivationReturn memory) {
@@ -141,6 +172,8 @@ contract MarketAPI {
141172
);
142173
}
143174

175+
/// Publish a new set of storage deals (not yet included in a sector).
176+
/// TODO renamed to publish_storage_deals, taking a vector.
144177
function publish_deal(bytes memory raw_auth_params, address callee) public {
145178
// calls standard filecoin receiver on message authentication api method number
146179
(bool success, ) = callee.call(
@@ -154,7 +187,9 @@ contract MarketAPI {
154187
require(success, "client contract failed to authorize deal publish");
155188
}
156189

157-
function generate_deal_mocks() internal {
190+
/// Adds mock deal data to the internal state of this mock.
191+
/// @dev Feel free to adjust the data here to make it align with deals in your network.
192+
function mock_generate_deals() internal {
158193
MarketTypes.MockDeal memory deal_67;
159194
deal_67.id = 67;
160195
deal_67
@@ -174,7 +209,7 @@ contract MarketAPI {
174209

175210
deals[deal_67.id] = deal_67;
176211

177-
// As EVM smart contract has a limited capacity for size, we cannot set all deals directly here.
212+
// As EVM smart contract has a limited capacity for size (24KiB), we cannot set all deals directly here.
178213
// Please, take them from docs.
179214

180215
// Add or replace more deals here.

contracts/v0.8/MinerAPI.sol

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ pragma solidity >=0.4.25 <=0.8.15;
33

44
import "./types/MinerTypes.sol";
55

6-
/// @title Filecoin miner actor API for Solidity.
6+
/// @title This contract is a proxy to a built-in Miner actor. Calling one of its methods will result in a cross-actor call being performed. However, in this mock library, no actual call is performed.
77
/// @author Zondax AG
8-
/// @notice It is mock with specific scenarios based on the parameters used to call its methods. It is meant to serve as the first entry point, and be replaced seamlessly in the future by the real API implementation tath actually calls the filecoin actor.
9-
/// @dev Most of function calls are currently implemented using some kind of struct for parameters and returns.
8+
/// @dev Methods prefixed with mock_ will not be available in the real library. These methods are merely used to set mock state. Note that this interface will likely break in the future as we align it
9+
// with that of the real library!
1010
contract MinerAPI {
1111
string owner;
1212
bool isBeneficiarySet = false;
@@ -23,11 +23,15 @@ contract MinerAPI {
2323
sectorSizesBytes[CommonTypes.SectorSize._64GiB] = 2 * (32 << 30);
2424
}
2525

26+
/// (Mock method) Sets the owner of a Miner, which will be returned via get_owner().
2627
function mock_set_owner(string memory addr) public {
2728
require(bytes(owner).length == 0);
2829
owner = addr;
2930
}
3031

32+
/// Returns the owner address of a Miner.
33+
/// - Income and returned collateral are paid to this address
34+
/// - This address is also allowed to change the worker address for the miner
3135
function get_owner()
3236
public
3337
view
@@ -38,16 +42,24 @@ contract MinerAPI {
3842
return MinerTypes.GetOwnerReturn(owner);
3943
}
4044

45+
/// Proposes or confirms a change of owner address.
46+
/// If invoked by the current owner, proposes a new owner address for confirmation. If the proposed address is the
47+
/// current owner address, revokes any existing proposal.
48+
/// If invoked by the previously proposed address, with the same proposal, changes the current owner address to be
49+
/// that proposed address.
4150
function change_owner_address(string memory addr) public {
4251
owner = addr;
4352
}
4453

54+
/// Returns whether the provided address is "controlling".
55+
/// The "controlling" addresses are the Owner, the Worker, and all Control Addresses.
4556
function is_controlling_address(
4657
MinerTypes.IsControllingAddressParam memory params
4758
) public pure returns (MinerTypes.IsControllingAddressReturn memory) {
4859
return MinerTypes.IsControllingAddressReturn(false);
4960
}
5061

62+
/// Returns the miner's sector size.
5163
function get_sector_size()
5264
public
5365
view
@@ -59,6 +71,9 @@ contract MinerAPI {
5971
);
6072
}
6173

74+
/// Returns the available balance of this miner.
75+
/// This is calculated as actor balance - (vesting funds + pre-commit deposit + initial pledge requirement + fee debt)
76+
/// Can go negative if the miner is in IP debt.
6277
function get_available_balance()
6378
public
6479
pure
@@ -67,6 +82,7 @@ contract MinerAPI {
6782
return MinerTypes.GetAvailableBalanceReturn(10000000000000000000000);
6883
}
6984

85+
/// Returns the funds vesting in this miner as a list of (vesting_epoch, vesting_amount) tuples.
7086
function get_vesting_funds()
7187
public
7288
pure
@@ -82,6 +98,10 @@ contract MinerAPI {
8298
return MinerTypes.GetVestingFundsReturn(vesting_funds);
8399
}
84100

101+
/// Proposes or confirms a change of beneficiary address.
102+
/// A proposal must be submitted by the owner, and takes effect after approval of both the proposed beneficiary and current beneficiary,
103+
/// if applicable, any current beneficiary that has time and quota remaining.
104+
/// See FIP-0029, https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0029.md
85105
function change_beneficiary(
86106
MinerTypes.ChangeBeneficiaryParams memory params
87107
) public {
@@ -100,6 +120,9 @@ contract MinerAPI {
100120
}
101121
}
102122

123+
/// Retrieves the currently active and proposed beneficiary information.
124+
/// This method is for use by other actors (such as those acting as beneficiaries),
125+
/// and to abstract the state representation for clients.
103126
function get_beneficiary()
104127
public
105128
view
@@ -110,6 +133,4 @@ contract MinerAPI {
110133
CommonTypes.PendingBeneficiaryChange memory proposed;
111134
return MinerTypes.GetBeneficiaryReturn(activeBeneficiary, proposed);
112135
}
113-
114-
function get_sector_size_from_enum() internal returns (uint64) {}
115136
}

0 commit comments

Comments
 (0)