Skip to content

Commit

Permalink
Merge branch 'fix/eth-gov-pools' of https://github.com/beefyfinance/b…
Browse files Browse the repository at this point in the history
…eefy-contracts into fix/eth-gov-pools
  • Loading branch information
kexleyBeefy committed Oct 11, 2023
2 parents 1de29ea + 410ab74 commit f9b334f
Show file tree
Hide file tree
Showing 13 changed files with 808 additions and 72 deletions.
19 changes: 19 additions & 0 deletions contracts/BIFI/interfaces/curve/ICurveRouterV1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

struct CurveRoute {
address[11] route;
uint256[5][5] swapParams;
uint minAmount;
}

interface ICurveRouterV1 {

function exchange(
address[11] calldata _route,
uint[5][5] calldata _swap_params,
uint _amount,
uint _expected
) external returns(uint);
}
22 changes: 22 additions & 0 deletions contracts/BIFI/strategies/Balancer/BalancerActionsLib.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin-4/contracts/token/ERC20/IERC20.sol";
import "../../interfaces/beethovenx/IBalancerVault.sol";
import "./BeefyBalancerStructs.sol";

Expand All @@ -18,6 +19,27 @@ library BalancerActionsLib {
IBalancerVault(_vault).joinPool(_poolId, address(this), address(this), request);
}

function multiJoin(address _vault, address _want, bytes32 _poolId, address _token0In, address _token1In, uint256 _amount0In, uint256 _amount1In) internal {
(address[] memory lpTokens,uint256[] memory balances,) = IBalancerVault(_vault).getPoolTokens(_poolId);
uint256 supply = IERC20(_want).totalSupply();
uint256[] memory amounts = new uint256[](lpTokens.length);
for (uint256 i = 0; i < amounts.length;) {
if (lpTokens[i] == _token0In) amounts[i] = _amount0In;
else if (lpTokens[i] == _token1In) amounts[i] = _amount1In;
else amounts[i] = 0;
unchecked { ++i; }
}

uint256 bpt0 = (amounts[0] * supply / balances[0]) - 100;
uint256 bpt1 = (amounts[1] * supply / balances[1]) - 100;

uint256 bptOut = bpt0 > bpt1 ? bpt1 : bpt0;
bytes memory userData = abi.encode(3, bptOut);

IBalancerVault.JoinPoolRequest memory request = IBalancerVault.JoinPoolRequest(lpTokens, amounts, userData, false);
IBalancerVault(_vault).joinPool(_poolId, address(this), address(this), request);
}

function buildSwapStructArray(BeefyBalancerStructs.BatchSwapStruct[] memory _route, uint256 _amountIn) internal pure returns (IBalancerVault.BatchSwapStep[] memory) {
IBalancerVault.BatchSwapStep[] memory swaps = new IBalancerVault.BatchSwapStep[](_route.length);
for (uint i; i < _route.length;) {
Expand Down
Loading

0 comments on commit f9b334f

Please sign in to comment.