owned this note
owned this note
Published
Linked with GitHub
## tx
```
property: 0x6587e7Aa0879bB54858f25643D099ED4Aa6a454A
from: 0x437abb18bccd9683eb1a696c5b9624dbc8599635
to: 0x2A4F7D691F3C5045D0A267eeeE18BD8A8c0A6C9B
amount: 40000000000000000000
```
---
## stack trace
https://github.com/dev-protocol/protocol-v2/blob/main/contracts/src/withdraw/Withdraw.sol
```solidity
function beforeBalanceChange(address _from, address _to) external override {
/**
* Validates the sender is Allocator contract.
*/
require(
IPropertyFactory(registry().registries("PropertyFactory"))
.isProperty(msg.sender),
"this is illegal address"
);
//// => true
/**
* Gets the cumulative sum of the transfer source's "before transfer" withdrawable reward amount and the cumulative sum of the maximum mint amount.
*/
(
uint256 amountFrom,
uint256 priceFrom,
uint256 priceCapFrom,
) = _calculateAmount(msg.sender, _from);
//// WIP: results = ??? (go to L73)
/**
* Gets the cumulative sum of the transfer destination's "before receive" withdrawable reward amount and the cumulative sum of the maximum mint amount.
*/
(
uint256 amountTo,
uint256 priceTo,
uint256 priceCapTo,
) = _calculateAmount(msg.sender, _to);
/**
* Updates the last cumulative sum of the maximum mint amount of the transfer source and destination.
*/
lastWithdrawnRewardPrice[msg.sender][_from] = priceFrom;
lastWithdrawnRewardPrice[msg.sender][_to] = priceTo;
lastWithdrawnRewardCapPrice[msg.sender][_from] = priceCapFrom;
lastWithdrawnRewardCapPrice[msg.sender][_to] = priceCapTo;
/**
* Gets the unwithdrawn reward amount of the transfer source and destination.
*/
uint256 pendFrom = pendingWithdrawal[msg.sender][_from];
uint256 pendTo = pendingWithdrawal[msg.sender][_to];
/**
* Adds the undrawn reward amount of the transfer source and destination.
*/
pendingWithdrawal[msg.sender][_from] = pendFrom + amountFrom;
pendingWithdrawal[msg.sender][_to] = pendTo + amountTo;
}
```
```solidity
//// when: _user = 0x437abb18bccd9683eb1a696c5b9624dbc8599635
function _calculateAmount(address _property, address _user)
private
view
returns (
uint256 _amount,
uint256 _price,
uint256 _cap,
uint256 _allReward
)
{
ILockup lockup = ILockup(registry().registries("Lockup"));
/**
* Gets the latest reward.
*/
(uint256 reward, uint256 cap) = lockup.calculateRewardAmount(_property);
//// reward = 65956119256292736154038906646514271
//// cap = 4476394927711333268596987657381053398
/**
* Gets the cumulative sum of the holder reward price recorded the last time you withdrew.
*/
uint256 allReward = _calculateAllReward(_property, _user, reward);
//// allReward = 7321129822096
uint256 capped = _calculateCapped(_property, _user, cap);
//// TODO: capped = ?
uint256 value = capped == 0 ? allReward : allReward <= capped
? allReward
: capped;
/**
* Returns the result after adjusted decimals to 10^18, and the latest cumulative sum of the holder reward price.
*/
return (value, reward, cap, allReward);
}
function _calculateAllReward(
address _property,
address _user,
uint256 _reward
) private view returns (uint256) {
/**
* Gets the cumulative sum of the holder reward price recorded the last time you withdrew.
*/
uint256 _lastReward = lastWithdrawnRewardPrice[_property][_user];
//// _lastReward = 0
IERC20 property = IERC20(_property);
uint256 balance = property.balanceOf(_user);
//// balance = 1110000088642002654718
uint256 totalSupply = property.totalSupply();
//// totalSupply = 10000000000000000000000000
uint256 unitPrice = ((_reward - _lastReward).mulBasis()) / totalSupply;
//// mulBasis = a * 1000000000000000000
//// unitPrice = 6595611925629273615403890664
return (unitPrice * balance).divBasis().divBasis();
//// => 7321129822096
}
function _calculateCapped(
address _property,
address _user,
uint256 _cap
) private view returns (uint256) {
/**
* Gets the cumulative sum of the holder reward price recorded the last time you withdrew.
*/
uint256 _lastRewardCap = lastWithdrawnRewardCapPrice[_property][_user];
//// _lastRewardCap = 173403893764629866348542430098209483187143
IERC20 property = IERC20(_property);
uint256 balance = property.balanceOf(_user);
uint256 totalSupply = property.totalSupply();
uint256 unitPriceCap = (_cap - _lastRewardCap) / totalSupply;
//// unitPriceCap =
return (unitPriceCap * balance).divBasis();
}
```
holdersPrice = 24365150479570506993
cumulativeHoldersRewardCap = 173405775795985874348076359110960551782663
lastCumulativeHoldersPriceCap = 24360116988683261356
889775841199064196030
901505772568059646138