Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deposit/withdraw/claim accounting and sig #48

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
run: forge test --no-match-contract Arbi --fork-url https://rpc.ankr.com/eth

- name: Run arbitrum tests
run: forge test --mc Arbi --fork-url https://arb-mainnet.g.alchemy.com/v2/WyhayD-L2Ox60Yngd6nzQvDKWtsCoCne
run: forge test --mc Arbi --fork-url https://arb1.arbitrum.io/rpc
25 changes: 19 additions & 6 deletions src/balancer/BalancerLPStakingController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ contract BalancerLPStakingController is IController {
/// @notice withdraw(uint256)
bytes4 constant WITHDRAW = 0x2e1a7d4d;

/// @notice withdraw(uint256,address,bool)
bytes4 constant WITHDRAWCLAIM = 0x00ebf5dd;
/// @notice withdraw(uint256,bool)
bytes4 constant WITHDRAWCLAIM = 0x38d07436;

/// @notice claim_rewards()
bytes4 constant CLAIM = 0xe6f1daf2;
Expand All @@ -49,9 +49,9 @@ contract BalancerLPStakingController is IController {
bytes4 sig = bytes4(data);

if (sig == DEPOSIT) return canDeposit(target);
if (sig == DEPOSITCLAIM) return canDepositAndClaim(target);
if (sig == DEPOSITCLAIM) return canDepositAndClaim(target, data);
if (sig == WITHDRAW) return canWithdraw(target);
if (sig == WITHDRAWCLAIM) return canWithdrawAndClaim(target);
if (sig == WITHDRAWCLAIM) return canWithdrawAndClaim(target, data);
if (sig == CLAIM) return canClaim(target);

return (false, new address[](0), new address[](0));
Expand All @@ -69,11 +69,17 @@ contract BalancerLPStakingController is IController {
return (true, tokensIn, tokensOut);
}

function canDepositAndClaim(address target)
function canDepositAndClaim(address target, bytes calldata data)
internal
view
returns (bool, address[] memory, address[] memory)
{
(,,bool claim) = abi.decode(
data[4:], (uint256, address, bool)
);

if (!claim) return canDeposit(target);

address[] memory tokensIn = new address[](rewardsCount + 1);
address reward; uint i;
for (; i<rewardsCount; i++) {
Expand Down Expand Up @@ -103,11 +109,18 @@ contract BalancerLPStakingController is IController {
return (true, tokensIn, tokensOut);
}

function canWithdrawAndClaim(address target)
function canWithdrawAndClaim(address target, bytes calldata data)
internal
view
returns (bool, address[] memory, address[] memory)
{

(,bool claim) = abi.decode(
data[4:], (uint256, bool)
);

if (!claim) return canWithdraw(target);

address[] memory tokensIn = new address[](rewardsCount + 1);
address reward;
uint i;
Expand Down
19 changes: 15 additions & 4 deletions src/curve/CurveLPStakingController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ contract CurveLPStakingController is IController {
bytes4 sig = bytes4(data);

if (sig == DEPOSIT) return canDeposit(target);
if (sig == DEPOSITCLAIM) return canDepositAndClaim(target);
if (sig == DEPOSITCLAIM) return canDepositAndClaim(target, data);
if (sig == WITHDRAW) return canWithdraw(target);
if (sig == WITHDRAWCLAIM) return canWithdrawAndClaim(target);
if (sig == WITHDRAWCLAIM) return canWithdrawAndClaim(target, data);
if (sig == CLAIM) return canClaim(target);

return (false, new address[](0), new address[](0));
Expand All @@ -67,11 +67,16 @@ contract CurveLPStakingController is IController {
return (true, tokensIn, tokensOut);
}

function canDepositAndClaim(address target)
function canDepositAndClaim(address target, bytes calldata data)
internal
view
returns (bool, address[] memory, address[] memory)
{
(,,bool claim) = abi.decode(
data[4:], (uint256, address, bool)
);
if (!claim) return canDeposit(target);

uint count = IChildGauge(target).reward_count();

address[] memory tokensIn = new address[](count + 1);
Expand All @@ -98,11 +103,17 @@ contract CurveLPStakingController is IController {
return (true, tokensIn, tokensOut);
}

function canWithdrawAndClaim(address target)
function canWithdrawAndClaim(address target, bytes calldata data)
internal
view
returns (bool, address[] memory, address[] memory)
{
(,,bool claim) = abi.decode(
data[4:], (uint256, address, bool)
);

if (!claim) return canWithdraw(target);

uint count = IChildGauge(target).reward_count();

address[] memory tokensIn = new address[](count + 1);
Expand Down
41 changes: 25 additions & 16 deletions src/tests/BalancerLPStaking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract TestBalancerStakingArbi is TestBase {
assertTrue(!canCall);
}

function testCanDepositAndClaim() public {
function testCanDepositAndClaim(bool claim) public {
// Setup
controllerFacade.toggleTokenAllowance(gauge);
controllerFacade.toggleTokenAllowance(r1);
Expand All @@ -59,7 +59,7 @@ contract TestBalancerStakingArbi is TestBase {
bytes memory data = abi.encodeWithSelector(0x83df6747,
0,
address(0),
true
claim
);

// Test
Expand All @@ -68,11 +68,16 @@ contract TestBalancerStakingArbi is TestBase {

// Assert
assertTrue(canCall);
assertEq(tokensIn[0], r1);
assertEq(tokensIn[1], r2);
assertEq(tokensIn[2], gauge);
assertEq(tokensIn.length, 3);
assertEq(tokensOut[0], lp);
if (claim) {
assertEq(tokensIn[0], r1);
assertEq(tokensIn[1], r2);
assertEq(tokensIn[2], gauge);
assertEq(tokensIn.length, 3);
} else {
assertEq(tokensIn[0], gauge);
assertEq(tokensIn.length, 1);
}
}

function testCannotDepositAndClaim() public {
Expand All @@ -90,16 +95,15 @@ contract TestBalancerStakingArbi is TestBase {
assertTrue(!canCall);
}

function testCanWithdrawAndClaim() public {
function testCanWithdrawAndClaim(bool claim) public {
// Setup
controllerFacade.toggleTokenAllowance(lp);
controllerFacade.toggleTokenAllowance(r1);
controllerFacade.toggleTokenAllowance(r2);

bytes memory data = abi.encodeWithSelector(0x00ebf5dd,
bytes memory data = abi.encodeWithSelector(0x38d07436,
0,
address(0),
true
claim
);

// Test
Expand All @@ -108,17 +112,22 @@ contract TestBalancerStakingArbi is TestBase {

// Assert
assertTrue(canCall);
assertEq(tokensIn[0], r1);
assertEq(tokensIn[1], r2);
assertEq(tokensIn[2], lp);
assertEq(tokensIn.length, 3);
assertEq(tokensOut[0], gauge);

if (claim) {
assertEq(tokensIn[0], r1);
assertEq(tokensIn[1], r2);
assertEq(tokensIn[2], lp);
assertEq(tokensIn.length, 3);
} else {
assertEq(tokensIn[0], lp);
assertEq(tokensIn.length, 1);
}
}

function testCannotWithdrawAndClaim() public {
bytes memory data = abi.encodeWithSelector(0x00ebf5dd,
bytes memory data = abi.encodeWithSelector(0x38d07436,
0,
address(0),
true
);

Expand Down