diff --git a/evm/lib/forge-std b/evm/lib/forge-std index f73c73d..e4aef94 160000 --- a/evm/lib/forge-std +++ b/evm/lib/forge-std @@ -1 +1 @@ -Subproject commit f73c73d2018eb6a111f35e4dae7b4f27401e9421 +Subproject commit e4aef94c1768803a16fe19f7ce8b65defd027cfd diff --git a/evm/lib/openzeppelin-contracts b/evm/lib/openzeppelin-contracts index 932fddf..11dc5e3 160000 --- a/evm/lib/openzeppelin-contracts +++ b/evm/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit 932fddf69a699a9a80fd2396fd1a2ab91cdda123 +Subproject commit 11dc5e3809ebe07d5405fe524385cbe4f890a08b diff --git a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol index 13b2f2d..e93702b 100644 --- a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol +++ b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol @@ -100,27 +100,19 @@ contract BalancerV2SwapAdapter is ISwapAdapter { sellAmount = uint256(assetDeltas[0]); } - function priceBatch( + function price( bytes32 poolId, address sellToken, address buyToken, uint256[] memory specifiedAmounts ) external returns (Fraction[] memory calculatedPrices) { + calculatedPrices = new Fraction[](specifiedAmounts.length); for (uint256 i = 0; i < specifiedAmounts.length; i++) { calculatedPrices[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( bytes32 poolId, address sellToken, @@ -196,9 +188,10 @@ contract BalancerV2SwapAdapter is ISwapAdapter { override returns (Capability[] memory capabilities) { - capabilities = new Capability[](2); + capabilities = new Capability[](3); capabilities[0] = Capability.SellOrder; capabilities[1] = Capability.BuyOrder; + capabilities[2] = Capability.PriceFunction; } function getTokens(bytes32 poolId) diff --git a/evm/src/interfaces/ISwapAdapter.sol b/evm/src/interfaces/ISwapAdapter.sol index 50fed77..ab3bacc 100644 --- a/evm/src/interfaces/ISwapAdapter.sol +++ b/evm/src/interfaces/ISwapAdapter.sol @@ -37,7 +37,7 @@ interface ISwapAdapter is ISwapAdapterTypes { address sellToken, address buyToken, uint256[] memory specifiedAmounts - ) external view returns (Fraction[] memory prices); + ) external returns (Fraction[] memory prices); /** * @notice Simulates swapping tokens on a given pool. diff --git a/evm/test/BalancerV2SwapAdapter.t.sol b/evm/test/BalancerV2SwapAdapter.t.sol index 06ccfe0..20f4f8d 100644 --- a/evm/test/BalancerV2SwapAdapter.t.sol +++ b/evm/test/BalancerV2SwapAdapter.t.sol @@ -40,14 +40,16 @@ contract BalancerV2SwapAdapterTest is Test, ISwapAdapterTypes { function testPrice() public { uint256[] memory amounts = new uint256[](2); - amounts[0] = 100; - amounts[1] = 200; - vm.expectRevert( - abi.encodeWithSelector( - NotImplemented.selector, "BalancerV2SwapAdapter.price" - ) - ); - adapter.price(B_80BAL_20WETH_POOL_ID, BAL, WETH, amounts); + amounts[0] = 1e18; + amounts[1] = 2e18; + + Fraction[] memory prices = + adapter.price(B_80BAL_20WETH_POOL_ID, BAL, WETH, amounts); + + for (uint256 i = 0; i < prices.length; i++) { + assertGt(prices[i].numerator, 0); + assertGt(prices[i].denominator, 0); + } } function testPriceSingleFuzz() public { @@ -206,9 +208,10 @@ contract BalancerV2SwapAdapterTest is Test, ISwapAdapterTypes { { 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[1]), uint256(Capability.BuyOrder)); + assertEq(uint256(res[2]), uint256(Capability.PriceFunction)); } function testGetTokens() public {