Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change of owner of the dividend contract #8096

Closed
Lordymine opened this issue Jan 8, 2024 · 6 comments
Closed

Change of owner of the dividend contract #8096

Lordymine opened this issue Jan 8, 2024 · 6 comments
Labels
bug If this is a PR, this PR fixes a bug. If this is an issue, this issue reports a bug.

Comments

@Lordymine
Copy link

Pull Request

No response

What happened?

I have a client who forked this dividend contract, but he did something that prevents him from changing the owner of this contract. I would like to know if you could help me change the owner of the dividend contract. My client has 560 BNBs stuck in the contract and he needs to redeem it, as the contract will be exchanged for another

Relevant log output

No response

@Lordymine Lordymine added the bug If this is a PR, this PR fixes a bug. If this is an issue, this issue reports a bug. label Jan 8, 2024
@Coretaker101
Copy link

Hmmmm

@Lordymine
Copy link
Author

The source code of the contract `// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

import "./ERC20.sol";
import "./SafeMath.sol";
import "./SafeMathUint.sol";
import "./SafeMathInt.sol";
import "./DividendPayingTokenInterface.sol";
import "./DividendPayingTokenOptionalInterface.sol";

/// @title Dividend-Paying Token
/// @author Roger Wu (https://github.com/roger-wu)
/// @dev A mintable ERC20 token that allows anyone to pay and distribute ether
/// to token holders as dividends and allows token holders to withdraw their dividends.
/// Reference: the source code of PoWH3D: https://etherscan.io/address/0xB3775fB83F7D12A36E0475aBdD1FCA35c091efBe#code
contract DividendPayingToken is ERC20, DividendPayingTokenInterface, DividendPayingTokenOptionalInterface {
using SafeMath for uint256;
using SafeMathUint for uint256;
using SafeMathInt for int256;

// With magnitude, we can properly distribute dividends even if the amount of received ether is small.
// For more discussion about choosing the value of magnitude,
// see #1726 (comment)
uint256 constant internal magnitude = 2**128;

uint256 internal magnifiedDividendPerShare;

// About dividendCorrection:
// If the token balance of a _user is never changed, the dividend of _user can be computed with:
// dividendOf(_user) = dividendPerShare * balanceOf(_user).
// When balanceOf(_user) is changed (via minting/burning/transferring tokens),
// dividendOf(_user) should not be changed,
// but the computed value of dividendPerShare * balanceOf(_user) is changed.
// To keep the dividendOf(_user) unchanged, we add a correction term:
// dividendOf(_user) = dividendPerShare * balanceOf(_user) + dividendCorrectionOf(_user),
// where dividendCorrectionOf(_user) is updated whenever balanceOf(_user) is changed:
// dividendCorrectionOf(_user) = dividendPerShare * (old balanceOf(_user)) - (new balanceOf(_user)).
// So now dividendOf(_user) returns the same value before and after balanceOf(_user) is changed.
mapping(address => int256) internal magnifiedDividendCorrections;
mapping(address => uint256) internal withdrawnDividends;

uint256 public totalDividendsDistributed;

constructor(string memory _name, string memory _symbol) public ERC20(_name, _symbol) {

}

/// @dev Distributes dividends whenever ether is paid to this contract.
receive() external payable {
distributeDividends();
}

/// @notice Distributes ether to token holders as dividends.
/// @dev It reverts if the total supply of tokens is 0.
/// It emits the DividendsDistributed event if the amount of received ether is greater than 0.
/// About undistributed ether:
/// In each distribution, there is a small amount of ether not distributed,
/// the magnified amount of which is
/// (msg.value * magnitude) % totalSupply().
/// With a well-chosen magnitude, the amount of undistributed ether
/// (de-magnified) in a distribution can be less than 1 wei.
/// We can actually keep track of the undistributed ether in a distribution
/// and try to distribute it in the next distribution,
/// but keeping track of such data on-chain costs much more than
/// the saved ether, so we don't do that.
function distributeDividends() public override payable {
require(totalSupply() > 0);

if (msg.value > 0) {
  magnifiedDividendPerShare = magnifiedDividendPerShare.add(
    (msg.value).mul(magnitude) / totalSupply()
  );
  emit DividendsDistributed(msg.sender, msg.value);

  totalDividendsDistributed = totalDividendsDistributed.add(msg.value);
}

}

/// @notice Withdraws the ether distributed to the sender.
/// @dev It emits a DividendWithdrawn event if the amount of withdrawn ether is greater than 0.
function withdrawDividend() public virtual override {
_withdrawDividendOfUser(msg.sender);
}

/// @notice Withdraws the ether distributed to the sender.
/// @dev It emits a DividendWithdrawn event if the amount of withdrawn ether is greater than 0.
function _withdrawDividendOfUser(address payable user) internal returns (uint256) {
uint256 _withdrawableDividend = withdrawableDividendOf(user);
if (_withdrawableDividend > 0) {
withdrawnDividends[user] = withdrawnDividends[user].add(_withdrawableDividend);
emit DividendWithdrawn(user, _withdrawableDividend);
(bool success,) = user.call{value: _withdrawableDividend, gas: 3000}("");

  if(!success) {
    withdrawnDividends[user] = withdrawnDividends[user].sub(_withdrawableDividend);
    return 0;
  }

  return _withdrawableDividend;
}

return 0;

}

/// @notice View the amount of dividend in wei that an address can withdraw.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that _owner can withdraw.
function dividendOf(address _owner) public view override returns(uint256) {
return withdrawableDividendOf(_owner);
}

/// @notice View the amount of dividend in wei that an address can withdraw.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that _owner can withdraw.
function withdrawableDividendOf(address _owner) public view override returns(uint256) {
return accumulativeDividendOf(_owner).sub(withdrawnDividends[_owner]);
}

/// @notice View the amount of dividend in wei that an address has withdrawn.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that _owner has withdrawn.
function withdrawnDividendOf(address _owner) public view override returns(uint256) {
return withdrawnDividends[_owner];
}

/// @notice View the amount of dividend in wei that an address has earned in total.
/// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
/// = (magnifiedDividendPerShare * balanceOf(_owner) + magnifiedDividendCorrections[_owner]) / magnitude
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that _owner has earned in total.
function accumulativeDividendOf(address _owner) public view override returns(uint256) {
return magnifiedDividendPerShare.mul(balanceOf(_owner)).toInt256Safe()
.add(magnifiedDividendCorrections[_owner]).toUint256Safe() / magnitude;
}

/// @dev Internal function that transfer tokens from one address to another.
/// Update magnifiedDividendCorrections to keep dividends unchanged.
/// @param from The address to transfer from.
/// @param to The address to transfer to.
/// @param value The amount to be transferred.
function _transfer(address from, address to, uint256 value) internal virtual override {
require(false);

int256 _magCorrection = magnifiedDividendPerShare.mul(value).toInt256Safe();
magnifiedDividendCorrections[from] = magnifiedDividendCorrections[from].add(_magCorrection);
magnifiedDividendCorrections[to] = magnifiedDividendCorrections[to].sub(_magCorrection);

}

/// @dev Internal function that mints tokens to an account.
/// Update magnifiedDividendCorrections to keep dividends unchanged.
/// @param account The account that will receive the created tokens.
/// @param value The amount that will be created.
function _mint(address account, uint256 value) internal override {
super._mint(account, value);

magnifiedDividendCorrections[account] = magnifiedDividendCorrections[account]
  .sub( (magnifiedDividendPerShare.mul(value)).toInt256Safe() );

}

/// @dev Internal function that burns an amount of the token of a given account.
/// Update magnifiedDividendCorrections to keep dividends unchanged.
/// @param account The account whose tokens will be burnt.
/// @param value The amount that will be burnt.
function _burn(address account, uint256 value) internal override {
super._burn(account, value);

magnifiedDividendCorrections[account] = magnifiedDividendCorrections[account]
  .add( (magnifiedDividendPerShare.mul(value)).toInt256Safe() );

}

function _setBalance(address account, uint256 newBalance) internal {
uint256 currentBalance = balanceOf(account);

if(newBalance > currentBalance) {
  uint256 mintAmount = newBalance.sub(currentBalance);
  _mint(account, mintAmount);
} else if(newBalance < currentBalance) {
  uint256 burnAmount = currentBalance.sub(newBalance);
  _burn(account, burnAmount);
}

}
}`

@Lordymine
Copy link
Author

@Coretaker101 my client removed the dividend contract from within the functions of the owner contract, the contro owner still remains the owner, but we are not able to withdraw the funds in bnb from this dividend contract to be able to send it to another contract

@Pandapip1
Copy link
Member

This is not the correct place to discuss this. It is unlikely that your client's funds are recoverable.

@Pandapip1 Pandapip1 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2024
@Lordymine
Copy link
Author

@Pandapip1 ok thx, sorry for this

@Lordymine
Copy link
Author

I was just looking for help from people more experienced than me, I don't want to steal the funds from the contract, my client owns the company that holds this contract, but he made a mistake when exchanging contracts, invalidating the dividend contract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If this is a PR, this PR fixes a bug. If this is an issue, this issue reports a bug.
Projects
None yet
Development

No branches or pull requests

3 participants