Merge pull request #28 from propeller-heads/lp/balancer-fixes
Fix balancer adapter
This commit is contained in:
Submodule evm/lib/forge-std updated: f73c73d201...e4aef94c17
Submodule evm/lib/openzeppelin-contracts updated: 932fddf69a...11dc5e3809
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user