Skip to content

Commit

Permalink
Support redeem staking
Browse files Browse the repository at this point in the history
kikakkz committed Mar 29, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 23486d4 commit 918d06e
Showing 3 changed files with 18 additions and 8 deletions.
9 changes: 9 additions & 0 deletions contracts/v0.1/OwnerActor.sol
Original file line number Diff line number Diff line change
@@ -103,6 +103,15 @@ contract OwnerActor is Controllable {
Miner.withdrawReward(_miner, _to, amount);
}

function redeem(uint256 amount) public {
address payable _to = payable(msg.sender);
uint256 staking = Miner.stakingOfBeneficiary(_miner, _to);
require(staking > amount, "Owner: insufficient funds - account");
require(address(this).balance > amount, "Owner: insufficient funds - contract");
_to.transfer(amount);
Miner.redeem(_miner, _to, amount);
}

function sendToWorker(uint256 amount) public onlyController {
require(_miner.exist, "Owner: there is no miner custodied");
uint64 worker = Miner._worker(_miner);
9 changes: 1 addition & 8 deletions contracts/v0.1/beneficiary/Beneficiary.sol
Original file line number Diff line number Diff line change
@@ -9,13 +9,6 @@ library Beneficiary {
address beneficiary;
uint8 percent;
uint256 balance;
}

/// @title Beneficiary caculated by deposited amount definition
/// @author web3eye.io
struct Amount {
address beneficiary;
uint256 amount;
uint256 balance;
uint256 staking;
}
}
8 changes: 8 additions & 0 deletions contracts/v0.1/miner/Miner.sol
Original file line number Diff line number Diff line change
@@ -163,6 +163,10 @@ library Miner {
miner.percentBeneficiaries[beneficiary].balance -= amount;
}

function redeem(_Miner storage miner, address beneficiary, uint256 amount) public {
miner.percentBeneficiaries[beneficiary].staking -= amount;
}

function accounting(_Miner storage miner, uint256 amount) public {
for (uint32 i = 0; i < miner.percentBeneficiaryAddresses.length; i++) {
Beneficiary.Percent memory beneficiary = miner.percentBeneficiaries[miner.percentBeneficiaryAddresses[i]];
@@ -182,6 +186,10 @@ library Miner {
return miner.percentBeneficiaries[beneficiary].balance;
}

function stakingOfBeneficiary(_Miner storage miner, address beneficiary) public view returns (uint256) {
return miner.percentBeneficiaries[beneficiary].staking;
}

function setWorker(_Miner storage miner, uint64 newWorkerActorId) public {
miner.worker = newWorkerActorId;
}

0 comments on commit 918d06e

Please sign in to comment.