Skip to content

Commit

Permalink
refactor: withdrawTo -> reallocateTo
Browse files Browse the repository at this point in the history
  • Loading branch information
adhusson committed Feb 16, 2024
1 parent 811789e commit ef372d5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/PublicAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ contract PublicAllocator is IPublicAllocatorStaticTyping {
/* PUBLIC */

/// @inheritdoc IPublicAllocatorBase
function withdrawTo(Withdrawal[] calldata withdrawals, MarketParams calldata supplyMarketParams)
function reallocateTo(Withdrawal[] calldata withdrawals, MarketParams calldata supplyMarketParams)
external
payable
{
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IPublicAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface IPublicAllocatorBase {
/// @dev Will call MetaMorpho's `reallocate`.
/// @dev Checks that the public allocator constraints (flows, caps) are respected.
/// @dev Will revert if a withdrawal amount is larger than available liquidity.
function withdrawTo(Withdrawal[] calldata withdrawals, MarketParams calldata supplyMarketParams)
function reallocateTo(Withdrawal[] calldata withdrawals, MarketParams calldata supplyMarketParams)
external
payable;

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ library ErrorsLib {
/// @notice Thrown when the value is already set.
error AlreadySet();

/// @notice Thrown when there are duplicates with nonzero assets in `withdrawTo` arguments.
/// @notice Thrown when there are duplicates with nonzero assets in `reallocateTo` arguments.
error InconsistentWithdrawTo();

/// @notice Thrown when attempting to set max inflow/outflow above the MAX_SETTABLE_FLOW_CAP.
Expand Down
46 changes: 23 additions & 23 deletions test/PublicAllocatorTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract PublicAllocatorTest is IntegrationTest {
publicAllocator.setFlowCaps(flowCaps);
withdrawals.push(Withdrawal(idleParams, flow));
vm.expectRevert(stdError.arithmeticError);
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testReallocateCapZeroInflowByDefault(uint128 flow) public {
Expand All @@ -89,7 +89,7 @@ contract PublicAllocatorTest is IntegrationTest {
publicAllocator.setFlowCaps(flowCaps);
withdrawals.push(Withdrawal(idleParams, flow));
vm.expectRevert(stdError.arithmeticError);
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testConfigureFlowAccessFail(address sender) public {
Expand Down Expand Up @@ -212,7 +212,7 @@ contract PublicAllocatorTest is IntegrationTest {
emit EventsLib.PublicReallocateTo(sender, allMarkets[0].id(), 2 * flow);

vm.prank(sender);
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testReallocateNetting(uint128 flow) public {
Expand All @@ -224,11 +224,11 @@ contract PublicAllocatorTest is IntegrationTest {
publicAllocator.setFlowCaps(flowCaps);

withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);

delete withdrawals;
withdrawals.push(Withdrawal(allMarkets[0], flow));
publicAllocator.withdrawTo(withdrawals, idleParams);
publicAllocator.reallocateTo(withdrawals, idleParams);
}

function testReallocateReset(uint128 flow) public {
Expand All @@ -240,7 +240,7 @@ contract PublicAllocatorTest is IntegrationTest {
publicAllocator.setFlowCaps(flowCaps);

withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);

delete flowCaps;
flowCaps.push(FlowConfig(idleParams.id(), FlowCap(0, flow)));
Expand All @@ -251,7 +251,7 @@ contract PublicAllocatorTest is IntegrationTest {
delete withdrawals;

withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testFeeAmountSuccess(uint256 requiredFee) public {
Expand All @@ -261,7 +261,7 @@ contract PublicAllocatorTest is IntegrationTest {

vm.deal(address(this), requiredFee);

publicAllocator.withdrawTo{value: requiredFee}(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo{value: requiredFee}(withdrawals, allMarkets[0]);
}

function testFeeAmountFail(uint256 requiredFee, uint256 givenFee) public {
Expand All @@ -274,15 +274,15 @@ contract PublicAllocatorTest is IntegrationTest {
vm.deal(address(this), givenFee);
vm.expectRevert(ErrorsLib.IncorrectFee.selector);

publicAllocator.withdrawTo{value: givenFee}(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo{value: givenFee}(withdrawals, allMarkets[0]);
}

function testTransferFeeSuccess() public {
vm.prank(OWNER);
publicAllocator.setFee(0.001 ether);

publicAllocator.withdrawTo{value: 0.001 ether}(withdrawals, allMarkets[0]);
publicAllocator.withdrawTo{value: 0.001 ether}(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo{value: 0.001 ether}(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo{value: 0.001 ether}(withdrawals, allMarkets[0]);

uint256 before = address(this).balance;

Expand All @@ -296,7 +296,7 @@ contract PublicAllocatorTest is IntegrationTest {
vm.prank(OWNER);
publicAllocator.setFee(0.001 ether);

publicAllocator.withdrawTo{value: 0.001 ether}(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo{value: 0.001 ether}(withdrawals, allMarkets[0]);

CantReceive cr = new CantReceive();
vm.expectRevert("cannot receive");
Expand Down Expand Up @@ -326,15 +326,15 @@ contract PublicAllocatorTest is IntegrationTest {

// Should work at cap
withdrawals.push(Withdrawal(idleParams, uint128(cap)));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);

delete withdrawals;

// Should not work above cap
withdrawals.push(Withdrawal(idleParams, uint128(flow - cap)));

vm.expectRevert(abi.encodeWithSelector(ErrorsLib.PublicAllocatorSupplyCapExceeded.selector, allMarkets[0].id()));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testInflowStartsAboveCap(uint256 cap, uint128 flow) public {
Expand All @@ -349,7 +349,7 @@ contract PublicAllocatorTest is IntegrationTest {

// Set supply above future public allocator cap
withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);

// Set supply in market 0 > public allocation cap
supplyCaps.push(SupplyConfig(allMarkets[0].id(), cap));
Expand All @@ -360,7 +360,7 @@ contract PublicAllocatorTest is IntegrationTest {
withdrawals[0].amount = 1;

vm.expectRevert(abi.encodeWithSelector(ErrorsLib.PublicAllocatorSupplyCapExceeded.selector, allMarkets[0].id()));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testStrictOutflowStartsAboveCap(uint256 cap, uint128 flow, uint128 flow2) public {
Expand All @@ -376,7 +376,7 @@ contract PublicAllocatorTest is IntegrationTest {

// Set supply above future public allocator cap
withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);

// Set supply in market 0 > public allocation cap
supplyCaps.push(SupplyConfig(allMarkets[0].id(), cap));
Expand All @@ -388,7 +388,7 @@ contract PublicAllocatorTest is IntegrationTest {

withdrawals.push(Withdrawal(allMarkets[0], flow - flow2));

publicAllocator.withdrawTo(withdrawals, idleParams);
publicAllocator.reallocateTo(withdrawals, idleParams);
}

function testMaxOutNoOverflow(uint128 flow) public {
Expand All @@ -401,7 +401,7 @@ contract PublicAllocatorTest is IntegrationTest {
publicAllocator.setFlowCaps(flowCaps);

withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testMaxInNoOverflow(uint128 flow) public {
Expand All @@ -414,7 +414,7 @@ contract PublicAllocatorTest is IntegrationTest {
publicAllocator.setFlowCaps(flowCaps);

withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testReallocationReallocates(uint128 flow) public {
Expand All @@ -429,7 +429,7 @@ contract PublicAllocatorTest is IntegrationTest {
uint256 idleBefore = morpho.expectedSupplyAssets(idleParams, address(vault));
uint256 marketBefore = morpho.expectedSupplyAssets(allMarkets[0], address(vault));
withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
uint256 idleAfter = morpho.expectedSupplyAssets(idleParams, address(vault));
uint256 marketAfter = morpho.expectedSupplyAssets(allMarkets[0], address(vault));

Expand All @@ -449,7 +449,7 @@ contract PublicAllocatorTest is IntegrationTest {
withdrawals.push(Withdrawal(idleParams, 1e18));
withdrawals.push(Withdrawal(idleParams, 1e18));
vm.expectRevert(ErrorsLib.InconsistentWithdrawTo.selector);
publicAllocator.withdrawTo(withdrawals, allMarkets[0]);
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);
}

function testSupplyMarketInWithdrawals() public {
Expand All @@ -461,7 +461,7 @@ contract PublicAllocatorTest is IntegrationTest {

withdrawals.push(Withdrawal(idleParams, 1e18));
vm.expectRevert(ErrorsLib.InconsistentWithdrawTo.selector);
publicAllocator.withdrawTo(withdrawals, idleParams);
publicAllocator.reallocateTo(withdrawals, idleParams);
}

function testMaxFlowCapValue() public {
Expand Down

0 comments on commit ef372d5

Please sign in to comment.