Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Mar 10, 2024
1 parent 1b49ebf commit 40f7c7f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
46 changes: 45 additions & 1 deletion test/integration/merkle-lockup/lt/claim/claim.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22 <0.9.0;

import { Arrays } from "@openzeppelin/contracts/utils/Arrays.sol";
import { Lockup, LockupTranched } from "@sablier/v2-core/src/types/DataTypes.sol";

import { Errors } from "src/libraries/Errors.sol";
import { MerkleLockup } from "src/types/DataTypes.sol";
import { ISablierV2MerkleLockupLT } from "src/interfaces/ISablierV2MerkleLockupLT.sol";

import { Merkle } from "../../../../utils/Murky.sol";
import { MerkleBuilder } from "../../../../utils/MerkleBuilder.sol";

import { MerkleLockup_Integration_Test } from "../../MerkleLockup.t.sol";

contract Claim_Integration_Test is MerkleLockup_Integration_Test {
contract Claim_Integration_Test is Merkle, MerkleLockup_Integration_Test {
using MerkleBuilder for uint256[];

function setUp() public virtual override {
MerkleLockup_Integration_Test.setUp();
}
Expand Down Expand Up @@ -129,4 +137,40 @@ contract Claim_Integration_Test is MerkleLockup_Integration_Test {
assertEq(actualStreamId, expectedStreamId, "invalid stream id");
assertEq(actualStream, expectedStream);
}

uint256[] public leaves = new uint256[](4);
bytes32 public merkleRoot;

function test_Claim_RoundingError() external {
uint128 claimAmount = 340_282_366_920_938_463_463_374_607_431_768_211_453;
uint256 aggregateAmount = 30_000e18 + uint256(claimAmount);

MerkleLockup.ConstructorParams memory baseParams = defaults.baseParams();

leaves = defaults.getLeaves();
leaves[0] = MerkleBuilder.computeLeaf(defaults.INDEX1(), users.recipient1, claimAmount);

MerkleBuilder.sortLeaves(leaves);
merkleRoot = getRoot(leaves.toBytes32());
baseParams.merkleRoot = merkleRoot;

uint256 leaf = MerkleBuilder.computeLeaf(defaults.INDEX1(), users.recipient1, claimAmount);
uint256 pos = Arrays.findUpperBound(leaves, leaf);
bytes32[] memory proof = getProof(leaves.toBytes32(), pos);

changePrank(users.admin);
deal({ token: address(dai), to: users.admin, give: aggregateAmount + 1_000_000e18 });

ISablierV2MerkleLockupLT _merkleLockupLT = merkleLockupFactory.createMerkleLockupLT(
baseParams, lockupTranched, defaults.tranchesWithPercentages(), aggregateAmount, defaults.RECIPIENTS_COUNT()
);

deal({ token: address(dai), to: address(_merkleLockupLT), give: aggregateAmount + 1_000_000e18 });

uint256 streamId = _merkleLockupLT.claim(defaults.INDEX1(), users.recipient1, claimAmount, proof);

LockupTranched.Tranche[] memory actualTranches = lockupTranched.getTranches(streamId);
LockupTranched.Tranche[] memory expectedTranches = defaults.tranches(claimAmount);
assertEq(actualTranches, expectedTranches);
}
}
4 changes: 4 additions & 0 deletions test/utils/Defaults.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ contract Defaults is Merkle {
MERKLE_ROOT = getRoot(LEAVES.toBytes32());
}

function getLeaves() public view returns (uint256[] memory) {
return LEAVES;
}

/*//////////////////////////////////////////////////////////////////////////
MERKLE-LOCKUP
//////////////////////////////////////////////////////////////////////////*/
Expand Down

0 comments on commit 40f7c7f

Please sign in to comment.