Merge pull request #28 from propeller-heads/lp/balancer-fixes

Fix balancer adapter
This commit is contained in:
Louise Poole
2024-04-16 17:32:10 +01:00
committed by GitHub
5 changed files with 19 additions and 23 deletions

View File

@@ -100,27 +100,19 @@ contract BalancerV2SwapAdapter is ISwapAdapter {
sellAmount = uint256(assetDeltas[0]); sellAmount = uint256(assetDeltas[0]);
} }
function priceBatch( function price(
bytes32 poolId, bytes32 poolId,
address sellToken, address sellToken,
address buyToken, address buyToken,
uint256[] memory specifiedAmounts uint256[] memory specifiedAmounts
) external returns (Fraction[] memory calculatedPrices) { ) external returns (Fraction[] memory calculatedPrices) {
calculatedPrices = new Fraction[](specifiedAmounts.length);
for (uint256 i = 0; i < specifiedAmounts.length; i++) { for (uint256 i = 0; i < specifiedAmounts.length; i++) {
calculatedPrices[i] = calculatedPrices[i] =
priceSingle(poolId, sellToken, buyToken, specifiedAmounts[i]); priceSingle(poolId, sellToken, buyToken, specifiedAmounts[i]);
} }
} }
function price(bytes32, address, address, uint256[] memory)
external
pure
override
returns (Fraction[] memory)
{
revert NotImplemented("BalancerV2SwapAdapter.price");
}
function swap( function swap(
bytes32 poolId, bytes32 poolId,
address sellToken, address sellToken,
@@ -196,9 +188,10 @@ contract BalancerV2SwapAdapter is ISwapAdapter {
override override
returns (Capability[] memory capabilities) returns (Capability[] memory capabilities)
{ {
capabilities = new Capability[](2); capabilities = new Capability[](3);
capabilities[0] = Capability.SellOrder; capabilities[0] = Capability.SellOrder;
capabilities[1] = Capability.BuyOrder; capabilities[1] = Capability.BuyOrder;
capabilities[2] = Capability.PriceFunction;
} }
function getTokens(bytes32 poolId) function getTokens(bytes32 poolId)

View File

@@ -37,7 +37,7 @@ interface ISwapAdapter is ISwapAdapterTypes {
address sellToken, address sellToken,
address buyToken, address buyToken,
uint256[] memory specifiedAmounts uint256[] memory specifiedAmounts
) external view returns (Fraction[] memory prices); ) external returns (Fraction[] memory prices);
/** /**
* @notice Simulates swapping tokens on a given pool. * @notice Simulates swapping tokens on a given pool.

View File

@@ -40,14 +40,16 @@ contract BalancerV2SwapAdapterTest is Test, ISwapAdapterTypes {
function testPrice() public { function testPrice() public {
uint256[] memory amounts = new uint256[](2); uint256[] memory amounts = new uint256[](2);
amounts[0] = 100; amounts[0] = 1e18;
amounts[1] = 200; amounts[1] = 2e18;
vm.expectRevert(
abi.encodeWithSelector( Fraction[] memory prices =
NotImplemented.selector, "BalancerV2SwapAdapter.price" adapter.price(B_80BAL_20WETH_POOL_ID, BAL, WETH, amounts);
)
); for (uint256 i = 0; i < prices.length; i++) {
adapter.price(B_80BAL_20WETH_POOL_ID, BAL, WETH, amounts); assertGt(prices[i].numerator, 0);
assertGt(prices[i].denominator, 0);
}
} }
function testPriceSingleFuzz() public { function testPriceSingleFuzz() public {
@@ -206,9 +208,10 @@ contract BalancerV2SwapAdapterTest is Test, ISwapAdapterTypes {
{ {
Capability[] memory res = adapter.getCapabilities(pool, t0, t1); Capability[] memory res = adapter.getCapabilities(pool, t0, t1);
assertEq(res.length, 2); assertEq(res.length, 3);
assertEq(uint256(res[0]), uint256(Capability.SellOrder)); assertEq(uint256(res[0]), uint256(Capability.SellOrder));
assertEq(uint256(res[1]), uint256(Capability.BuyOrder)); assertEq(uint256(res[1]), uint256(Capability.BuyOrder));
assertEq(uint256(res[2]), uint256(Capability.PriceFunction));
} }
function testGetTokens() public { function testGetTokens() public {