Skip to content

Commit

Permalink
fix: smol fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
r0ohafza committed Jan 23, 2024
1 parent 4c15189 commit 362b55b
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 156 deletions.
2 changes: 1 addition & 1 deletion packages/splits-v2/src/SplitsWarehouse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ contract SplitsWarehouse is ERC6909X {
if (id == NATIVE_TOKEN_ID) {
return nativeTokenSymbol.toString();
}
return string.concat(METADATA_PREFIX_SYMBOL, IERC20(id.toAddress()).name());
return string.concat(METADATA_PREFIX_SYMBOL, IERC20(id.toAddress()).symbol());
}

/**
Expand Down
24 changes: 24 additions & 0 deletions packages/splits-v2/src/libraries/SplitV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ library SplitV2Lib {
}
}

function getDistributionsMem(
Split memory _split,
uint256 _amount
)
internal
pure
returns (uint256[] memory amounts, uint256 amountDistributed, uint256 distributorReward)
{
uint256 numOfRecipients = _split.recipients.length;
amounts = new uint256[](numOfRecipients);

distributorReward = _amount * _split.distributionIncentive / PERCENTAGE_SCALE;

_amount -= distributorReward;

for (uint256 i = 0; i < numOfRecipients;) {
amounts[i] = _amount * _split.allocations[i] / _split.totalAllocation;
amountDistributed += amounts[i];
unchecked {
++i;
}
}
}

function calculateDistributorReward(
uint16 _distributionIncentive,
uint256 _amount
Expand Down
48 changes: 28 additions & 20 deletions packages/splits-v2/src/splitters/SplitWalletV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,32 @@ contract SplitWalletV2 is Wallet {
*/
function distribute(SplitV2Lib.Split calldata _split, address _token, address _distributor) external pausable {
if (splitHash != _split.getHash()) revert InvalidSplit();
(uint256 _splitBalance, uint256 _warehouseBalance) = _getSplitBalance(_token);
(uint256 splitBalance, uint256 warehouseBalance) = _getSplitBalance(_token);

if (distributeByPush) {
if (_warehouseBalance > 1) {
if (warehouseBalance >= 2) {
_withdrawFromWarehouse(_token);
unchecked {
_warehouseBalance -= 1;
warehouseBalance -= 1;
}
} else if (warehouseBalance > 0) {
unchecked {
warehouseBalance -= 1;
}
_withdrawFromWarehouse(_token);
}
pushDistribute(_split, _token, _splitBalance + _warehouseBalance, _distributor);
pushDistribute(_split, _token, warehouseBalance + splitBalance, _distributor);
} else {
if (_splitBalance > 1) {
if (splitBalance >= 2) {
unchecked {
splitBalance -= 1;
}
_depositToWarehouse(_token, splitBalance);
} else if (splitBalance > 0) {
unchecked {
_splitBalance -= 1;
splitBalance -= 1;
}
_depositToWarehouse(_token, _splitBalance);
}
pullDistribute(_split, _token, _splitBalance + _warehouseBalance, _distributor);
pullDistribute(_split, _token, warehouseBalance + splitBalance, _distributor);
}
}

Expand Down Expand Up @@ -176,10 +184,10 @@ contract SplitWalletV2 is Wallet {
/**
* @notice Gets the total token balance of the split wallet and the warehouse
* @param _token the token to get the balance of
* @return _splitBalance the token balance in the split wallet
* @return _warehouseBalance the token balance in the warehouse of the split wallet
* @return splitBalance the token balance in the split wallet
* @return warehouseBalance the token balance in the warehouse of the split wallet
*/
function getSplitBalance(address _token) public view returns (uint256 _splitBalance, uint256 _warehouseBalance) {
function getSplitBalance(address _token) public view returns (uint256, uint256) {
return _getSplitBalance(_token);
}

Expand Down Expand Up @@ -228,13 +236,13 @@ contract SplitWalletV2 is Wallet {
}
}

function _getSplitBalance(address _token) private view returns (uint256 _splitBalance, uint256 _warehouseBalance) {
function _getSplitBalance(address _token) private view returns (uint256 splitBalance, uint256 warehouseBalance) {
if (_token == NATIVE) {
_splitBalance = address(this).balance;
_warehouseBalance = SPLITS_WAREHOUSE.balanceOf(address(this), _token.toUint256());
splitBalance = address(this).balance;
warehouseBalance = SPLITS_WAREHOUSE.balanceOf(address(this), _token.toUint256());
} else {
_splitBalance = IERC20(_token).balanceOf(address(this));
_warehouseBalance = SPLITS_WAREHOUSE.balanceOf(address(this), _token.toUint256());
splitBalance = IERC20(_token).balanceOf(address(this));
warehouseBalance = SPLITS_WAREHOUSE.balanceOf(address(this), _token.toUint256());
}
}

Expand Down Expand Up @@ -266,7 +274,7 @@ contract SplitWalletV2 is Wallet {
}
}

_distributor.safeTransferETH(distributorReward);
if (distributorReward > 0) _distributor.safeTransferETH(distributorReward);
} else {
for (uint256 i = 0; i < numOfRecipients;) {
allocatedAmount = _amount * _split.allocations[i] / _split.totalAllocation;
Expand All @@ -278,7 +286,7 @@ contract SplitWalletV2 is Wallet {
}
}

IERC20(_token).safeTransfer(_distributor, distributorReward);
if (distributorReward > 0) IERC20(_token).safeTransfer(_distributor, distributorReward);
}

emit SplitDistributed(_token, _distributor, amountDistributed, distributorReward, true);
Expand All @@ -295,7 +303,7 @@ contract SplitWalletV2 is Wallet {
{
(uint256[] memory amounts, uint256 amountDistributed, uint256 distibutorReward) =
_split.getDistributions(_amount);
SPLITS_WAREHOUSE.transfer(_distributor, _token.toUint256(), distibutorReward);
if (distibutorReward > 0) SPLITS_WAREHOUSE.transfer(_distributor, _token.toUint256(), distibutorReward);
SPLITS_WAREHOUSE.batchTransfer(_token, _split.recipients, amounts);
emit SplitDistributed(_token, _distributor, amountDistributed, distibutorReward, false);
}
Expand Down
Loading

0 comments on commit 362b55b

Please sign in to comment.