Skip to content

Commit

Permalink
test: add lido split integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
samparsky committed Aug 15, 2023
1 parent d4d903b commit 0e474a5
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/interfaces/ISplitMain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ interface ISplitMain {
address distributorAddress
) external;


/// @notice Distributes the ERC20 `token` balance for split `split`
/// @dev `accounts`, `percentAllocations`, and `distributorFee` are verified by hashing
/// & comparing to the hash in storage associated with split `split`
/// @dev pernicious ERC20s may cause overflow in this function inside
/// _scaleAmountByPercentage, but results do not affect ETH & other ERC20 balances
/// @param split Address of split to distribute balance for
/// @param token Address of ERC20 to distribute balance for
/// @param accounts Ordered, unique list of addresses with ownership in the split
/// @param percentAllocations Percent allocations associated with each address
/// @param distributorFee Keeper fee paid by split to cover gas costs of distribution
/// @param distributorAddress Address to pay `distributorFee` to
function distributeERC20(
address split,
ERC20 token,
address[] calldata accounts,
uint32[] calldata percentAllocations,
uint32 distributorFee,
address distributorAddress
) external;

/// @notice Withdraw ETH &/ ERC20 balances for account `account`
/// @param account Address to withdraw on behalf of
/// @param withdrawETH Withdraw all ETH if nonzero
Expand Down
1 change: 1 addition & 0 deletions src/test/lido/LidoSplitTestHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pragma solidity 0.8.17;
contract LidoSplitTestHelper {
address internal STETH_MAINNET_ADDRESS = address(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
address internal WSTETH_MAINNET_ADDRESS = address(0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0);
address internal RANDOM_stETH_ACCOUNT_ADDRESS = address(0x2bf3937b8BcccE4B65650F122Bb3f1976B937B2f);
}
87 changes: 87 additions & 0 deletions src/test/lido/integration/LidoSplitIntegrationTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "forge-std/Test.sol";
import {LidoSplitFactory, LidoSplit} from "src/lido/LidoSplitFactory.sol";
import {ERC20} from 'solmate/tokens/ERC20.sol';
import {LidoSplitTestHelper} from '../LidoSplitTestHelper.sol';
import {ISplitMain} from "src/interfaces/ISplitMain.sol";

contract LidoSplitIntegrationTest is LidoSplitTestHelper, Test {

LidoSplitFactory internal lidoSplitFactory;
LidoSplit internal lidoSplit;

address splitter;

address[] accounts;
uint32[] percentAllocations;

address internal SPLIT_MAIN_MAINNET = 0x2ed6c4B5dA6378c7897AC67Ba9e43102Feb694EE;

function setUp() public {
uint256 mainnetBlock = 17421005;
vm.createSelectFork(getChain("mainnet").rpcUrl, mainnetBlock);

lidoSplitFactory = new LidoSplitFactory(
ERC20(STETH_MAINNET_ADDRESS),
ERC20(WSTETH_MAINNET_ADDRESS)
);

accounts = new address[](2);
accounts[0] = makeAddr("accounts0");
accounts[1] = makeAddr("accounts1");

percentAllocations = new uint32[](2);
percentAllocations[0] = 400_000;
percentAllocations[1] = 600_000;

splitter = ISplitMain(SPLIT_MAIN_MAINNET).createSplit(
accounts,
percentAllocations,
0,
address(0)
);

lidoSplit = LidoSplit(
lidoSplitFactory.createSplit(
splitter
)
);

}

function test_CanDistribute() public {
vm.prank(RANDOM_stETH_ACCOUNT_ADDRESS);
ERC20(STETH_MAINNET_ADDRESS).transfer(address(lidoSplit), 100 ether);

lidoSplit.distribute();

ISplitMain(SPLIT_MAIN_MAINNET).distributeERC20(
splitter,
ERC20(WSTETH_MAINNET_ADDRESS),
accounts,
percentAllocations,
0,
address(0)
);

ERC20[] memory tokens = new ERC20[](1);
tokens[0] = ERC20(WSTETH_MAINNET_ADDRESS);

ISplitMain(SPLIT_MAIN_MAINNET).withdraw(accounts[0], 0, tokens);
ISplitMain(SPLIT_MAIN_MAINNET).withdraw(accounts[1], 0, tokens);

assertEq(
ERC20(WSTETH_MAINNET_ADDRESS).balanceOf(accounts[0]),
35483996363190140092,
"invalid account 0 balance"
);
assertEq(
ERC20(WSTETH_MAINNET_ADDRESS).balanceOf(accounts[1]),
53225994544785210138,
"invalid account 1 balance"
);
}
}

0 comments on commit 0e474a5

Please sign in to comment.