Skip to content

Commit

Permalink
Prepare vesting funds then get it's string
Browse files Browse the repository at this point in the history
kikakkz committed Apr 2, 2023
1 parent 9230d14 commit e7f224b
Showing 4 changed files with 33 additions and 49 deletions.
8 changes: 7 additions & 1 deletion contracts/v0.1/OwnerActor.sol
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import "./send/Send.sol";
/// @notice Owner actor implementation of Filecoin miner
contract OwnerActor is Controllable {
Miner._Miner private _miner;
event VestingFunds(string vestingFunds);

constructor() {
}
@@ -138,7 +139,12 @@ contract OwnerActor is Controllable {
Miner.setPercentBeneficiary(_miner, percentBeneficiary);
}

function getVestingFunds() public onlyController returns (string memory) {
function prepareVestingFunds() public onlyController {
require(_miner.exist, "Owner: there is no miner custodied");
Miner.prepareVestingFunds(_miner);
}

function getVestingFunds() public view returns (string memory) {
require(_miner.exist, "Owner: there is no miner custodied");
return Miner.getVestingFunds(_miner);
}
13 changes: 10 additions & 3 deletions contracts/v0.1/miner/Miner.sol
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ library Miner {

uint256 vestingAmount;
CommonTypes.ChainEpoch vestingEndEpoch;
MinerTypes.VestingFunds[] vestingFunds;

bool exist;
}
@@ -134,10 +135,16 @@ library Miner {
MinerAPI.changeOwnerAddress(actorId, addr);
}

function getVestingFunds(_Miner storage miner) public returns (string memory) {
function prepareVestingFunds(_Miner storage miner) public {
CommonTypes.FilActorId actorId = CommonTypes.FilActorId.wrap(miner.minerId);
MinerTypes.GetVestingFundsReturn memory vestings = MinerAPI.getVestingFunds(actorId);
return String.vestingFundsToString(vestings.vesting_funds);
MinerTypes.GetVestingFundsReturn memory vestingFunds = MinerAPI.getVestingFunds(actorId);
for (uint32 i = 0; i < vestingFunds.vesting_funds.length; i++) {
miner.vestingFunds.push(vestingFunds.vesting_funds[i]);
}
}

function getVestingFunds(_Miner storage miner) public view returns (string memory) {
return String.vestingFundsToString(miner.vestingFunds);
}

function withdraw(_Miner storage miner) public returns (uint256) {
31 changes: 16 additions & 15 deletions contracts/v0.1/miner/String.sol
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import "https://github.com/Zondax/filecoin-solidity/blob/master/contracts/v0.8/u
import "https://github.com/Zondax/filecoin-solidity/blob/master/contracts/v0.8/types/CommonTypes.sol";
import "../fvm/Types.sol";
import "../beneficiary/Beneficiary.sol";
import "../utils/Uint2Str.sol";
import "./Miner.sol";

library String {
@@ -24,13 +23,13 @@ library String {
percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes(Strings.toHexString(uint256(uint160(value.beneficiary)), 20))));

percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes("\",\"Percent\":")));
percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes(Uint2Str.toString(value.percent))));
percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes(Strings.toString(value.percent))));

percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes(",\"Balance\":\"")));
percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes(Uint2Str.toString(value.balance))));
percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes(Strings.toString(value.balance))));

percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes("\",\"Staking\":\"")));
percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes(Uint2Str.toString(value.staking))));
percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes(Strings.toString(value.staking))));

percentBeneficiary = string(bytes.concat(bytes(percentBeneficiary), bytes("\"}")));
}
@@ -39,10 +38,10 @@ library String {
string memory minerStr = "{";

minerStr = string(bytes.concat(bytes(minerStr), bytes("\"MinerID\":\"t0")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(miner.minerId))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(miner.minerId))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"CustodyOwner\":\"")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(miner.custodyOwner))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(miner.custodyOwner))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"WindowPoStProofType\":\"")));
if (miner.windowPoStProofType == FvmTypes.RegisteredPoStProof.StackedDRGWindow32GiBV1) {
@@ -54,25 +53,25 @@ library String {
}

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"InitialCollateral\":\"")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(miner.initialCollateral))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(miner.initialCollateral))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"InitialVesting\":\"")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(miner.initialVesting))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(miner.initialVesting))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"InitialAvailable\":\"")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(uint256(miner.initialAvailable)))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(uint256(miner.initialAvailable)))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"Worker\":\"t0")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(uint256(miner.worker)))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(uint256(miner.worker)))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"PostControl\":\"t0")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(uint256(miner.postControl)))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(uint256(miner.postControl)))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"InitialCollateral\":\"")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(miner.initialRawPower))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(miner.initialRawPower))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"InitialAdjPower\":\"")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Uint2Str.toString(miner.initialAdjPower))));
minerStr = string(bytes.concat(bytes(minerStr), bytes(Strings.toString(miner.initialAdjPower))));

minerStr = string(bytes.concat(bytes(minerStr), bytes("\",\"PercentBeneficiaries\":")));
minerStr = string(bytes.concat(bytes(minerStr), bytes(percentBeneficiary)));
@@ -82,7 +81,7 @@ library String {
return minerStr;
}

function vestingFundsToString(MinerTypes.VestingFunds[] memory vestingFunds) public view returns (string memory) {
function vestingFundsToString(MinerTypes.VestingFunds[] memory vestingFunds) public pure returns (string memory) {
string memory vestingFundsStr = "[";

for (uint32 i = 0; i < vestingFunds.length; i++) {
@@ -96,10 +95,12 @@ library String {
int256 epoch = CommonTypes.ChainEpoch.unwrap(vesting.epoch);
vestingFundsStr = string(bytes.concat(bytes(vestingFundsStr), bytes(Strings.toString(epoch))));

/*
vestingFundsStr = string(bytes.concat(bytes(vestingFundsStr), bytes("\",\"Amount\":")));
(uint256 amount, bool converted) = BigInts.toUint256(vesting.amount);
require(converted, "String: convert error");
vestingFundsStr = string(bytes.concat(bytes(vestingFundsStr), bytes(Uint2Str.toString(amount))));
vestingFundsStr = string(bytes.concat(bytes(vestingFundsStr), bytes(Strings.toString(amount))));
*/

vestingFundsStr = string(bytes.concat(bytes(vestingFundsStr), bytes("\"}")));
}
30 changes: 0 additions & 30 deletions contracts/v0.1/utils/Uint2Str.sol

This file was deleted.

0 comments on commit e7f224b

Please sign in to comment.