From 9105b898d6562008c4de8155e63cceb5f2d8183c Mon Sep 17 00:00:00 2001 From: pistomat Date: Wed, 6 Dec 2023 15:12:43 +0100 Subject: [PATCH] rename pairId to more general poolId --- .../logic/vm-integration/ethereum-solidity.md | 20 +++++------ evm/src/balancer-v2/BalancerV2SwapAdapter.sol | 30 ++++++++-------- evm/src/balancer-v2/manifest.yaml | 2 +- evm/src/interfaces/ISwapAdapter.sol | 34 +++++++++---------- evm/src/interfaces/ISwapAdapterTypes.sol | 8 ++--- evm/src/uniswap-v2/UniswapV2SwapAdapter.sol | 16 ++++----- evm/src/uniswap-v2/manifest.yaml | 2 +- evm/test/BalancerV2SwapAdapter.t.sol | 4 +-- 8 files changed, 58 insertions(+), 58 deletions(-) diff --git a/docs/logic/vm-integration/ethereum-solidity.md b/docs/logic/vm-integration/ethereum-solidity.md index 9e8926d..6f894e1 100644 --- a/docs/logic/vm-integration/ethereum-solidity.md +++ b/docs/logic/vm-integration/ethereum-solidity.md @@ -50,7 +50,7 @@ instances: # getTokens are not implemented. tests: instances: - - pair_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" + - pool_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" sell_token: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" buy_token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" block: 17000000 @@ -61,7 +61,7 @@ tests: #### Price (optional) -Calculates pair prices for specified amounts (optional). +Calculates pool prices for specified amounts (optional). The returned prices should include all protocol fees, in case the fee is dynamic, the returned price is expected to include the minimum fee. @@ -71,7 +71,7 @@ The method needs to be implemented as view as this is usually more efficient and ```solidity function price( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, uint256[] memory sellAmounts @@ -80,7 +80,7 @@ function price( #### Swap -Simulates swapping tokens on a given pair. +Simulates swapping tokens on a given pool. This function should be state modifying meaning it should actually execute the swap and change the state of the vm accordingly. @@ -90,7 +90,7 @@ The return type Trade, has a price attribute which should contain the value of p ```solidity function swap( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, OrderSide side, @@ -105,29 +105,29 @@ Retrieves the limits for each token. This method returns the maximum limits of a token that can be traded. The limit is reached when the change in the received amounts is zero or close to zero. If in doubt over estimate the limit. The swap function should not error with LimitExceeded if called with any amounts below the limit. ```solidity -function getLimits(bytes32 pairId, OrderSide side) +function getLimits(bytes32 poolId, OrderSide side) external returns (uint256[] memory); ``` #### getCapabilities -Retrieves the capabilities of the selected pair. +Retrieves the capabilities of the selected pool. ```solidity -function getCapabilities(bytes32 pairId, IERC20 sellToken, IERC20 buyToken) +function getCapabilities(bytes32 poolId, IERC20 sellToken, IERC20 buyToken) external returns (Capability[] memory); ``` #### getTokens (optional) -Retrieves the tokens for the given pair. +Retrieves the tokens for the given pool. _Mainly used for testing as this is redundant with the required substreams implementation._ ```solidity -function getTokens(bytes32 pairId) +function getTokens(bytes32 poolId) external returns (IERC20[] memory tokens); ``` diff --git a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol index d7b5c2f..f048771 100644 --- a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol +++ b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol @@ -22,21 +22,21 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { /// Also this function is not 'view' because Balancer V2 simulates the swap /// and /// then returns the amount diff in revert data. - /// @param pairId The ID of the trading pool. + /// @param poolId The ID of the trading pool. /// @param sellToken The token being sold. /// @param buyToken The token being bought. /// @param sellAmount The amount of tokens being sold. /// @return calculatedPrice The price of the buy token in terms of the sell /// as a Fraction struct. function priceSingle( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, uint256 sellAmount ) public returns (Fraction memory calculatedPrice) { IVault.BatchSwapStep[] memory swapSteps = new IVault.BatchSwapStep[](1); swapSteps[0] = IVault.BatchSwapStep({ - poolId: pairId, + poolId: poolId, assetInIndex: 0, assetOutIndex: 1, amount: sellAmount, @@ -65,14 +65,14 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { } function getSellAmount( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, uint256 buyAmount ) public returns (uint256 sellAmount) { IVault.BatchSwapStep[] memory swapSteps = new IVault.BatchSwapStep[](1); swapSteps[0] = IVault.BatchSwapStep({ - poolId: pairId, + poolId: poolId, assetInIndex: 0, assetOutIndex: 1, amount: buyAmount, @@ -98,14 +98,14 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { } function priceBatch( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, uint256[] memory specifiedAmounts ) external returns (Fraction[] memory calculatedPrices) { for (uint256 i = 0; i < specifiedAmounts.length; i++) { calculatedPrices[i] = - priceSingle(pairId, sellToken, buyToken, specifiedAmounts[i]); + priceSingle(poolId, sellToken, buyToken, specifiedAmounts[i]); } } @@ -119,7 +119,7 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { } function swap( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, OrderSide side, @@ -135,7 +135,7 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { } else { kind = IVault.SwapKind.GIVEN_OUT; sellAmount = - getSellAmount(pairId, sellToken, buyToken, specifiedAmount); + getSellAmount(poolId, sellToken, buyToken, specifiedAmount); limit = type(uint256).max; } @@ -145,7 +145,7 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { uint256 gasBefore = gasleft(); trade.calculatedAmount = vault.swap( IVault.SingleSwap({ - poolId: pairId, + poolId: poolId, kind: kind, assetIn: address(sellToken), assetOut: address(buyToken), @@ -162,10 +162,10 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { block.timestamp + SWAP_DEADLINE_SEC ); trade.gasUsed = gasBefore - gasleft(); - trade.price = priceSingle(pairId, sellToken, buyToken, specifiedAmount); + trade.price = priceSingle(poolId, sellToken, buyToken, specifiedAmount); } - function getLimits(bytes32 pairId, IERC20 sellToken, IERC20 buyToken) + function getLimits(bytes32 poolId, IERC20 sellToken, IERC20 buyToken) external view override @@ -173,7 +173,7 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { { limits = new uint256[](2); (IERC20[] memory tokens, uint256[] memory balances,) = - vault.getPoolTokens(pairId); + vault.getPoolTokens(poolId); for (uint256 i = 0; i < tokens.length; i++) { if (tokens[i] == sellToken) { @@ -196,13 +196,13 @@ contract BalancerV2SwapAdapter is ISwapAdapter, Test { capabilities[1] = Capability.BuyOrder; } - function getTokens(bytes32 pairId) + function getTokens(bytes32 poolId) external view override returns (IERC20[] memory tokens) { - (tokens,,) = vault.getPoolTokens(pairId); + (tokens,,) = vault.getPoolTokens(poolId); } /// @dev Balancer V2 does not support enumerating pools, they have to be diff --git a/evm/src/balancer-v2/manifest.yaml b/evm/src/balancer-v2/manifest.yaml index 822388d..0f985e9 100644 --- a/evm/src/balancer-v2/manifest.yaml +++ b/evm/src/balancer-v2/manifest.yaml @@ -27,7 +27,7 @@ instances: # getTokens are not implemented. tests: instances: - - pair_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" + - pool_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" sell_token: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" buy_token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" block: 17000000 diff --git a/evm/src/interfaces/ISwapAdapter.sol b/evm/src/interfaces/ISwapAdapter.sol index ed8b017..df1e131 100644 --- a/evm/src/interfaces/ISwapAdapter.sol +++ b/evm/src/interfaces/ISwapAdapter.sol @@ -6,18 +6,18 @@ import {ISwapAdapterTypes} from "src/interfaces/ISwapAdapterTypes.sol"; /// @title ISwapAdapter /// @dev Implement this interface to support propeller routing through your -/// pairs. Before implementing the interface we need to introduce three function -/// for a given pair: The swap(x), gas(x) and price(x) functions: The swap +/// pools. Before implementing the interface we need to introduce three function +/// for a given pool: The swap(x), gas(x) and price(x) functions: The swap /// function accepts some specified token amount x and returns the amount y a /// user can get by swapping x through the venue. The gas function simply /// returns the estimated gas cost given a specified amount x. Last but not /// least, the price function is the derivative of the swap function. It -/// represents the best possible price a user can get from a pair after swapping +/// represents the best possible price a user can get from a pool after swapping /// x of the specified token. During calls to swap and getLimits, the caller can /// be assumed to have the required sell or buy token balance as well as /// unlimited approvals to this contract. interface ISwapAdapter is ISwapAdapterTypes { - /// @notice Calculates pair prices for specified amounts (optional). + /// @notice Calculates pool prices for specified amounts (optional). /// @dev The returned prices should include all dex fees, in case the fee is /// dynamic, the returned price is expected to include the minimum fee. /// Ideally this method should be implemented, although it is optional as @@ -26,7 +26,7 @@ interface ISwapAdapter is ISwapAdapterTypes { /// calling it should revert using the `NotImplemented` error. The method /// needs to be implemented as view as this is usually more efficient and /// can be run in parallel. all. - /// @param pairId The ID of the trading pair. + /// @param poolId The ID of the trading pool. /// @param sellToken The token being sold. /// @param buyToken The token being bought. /// @param specifiedAmounts The specified amounts used for price @@ -34,14 +34,14 @@ interface ISwapAdapter is ISwapAdapterTypes { /// @return prices array of prices as fractions corresponding to the /// provided amounts. function price( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, uint256[] memory specifiedAmounts ) external view returns (Fraction[] memory prices); /** - * @notice Simulates swapping tokens on a given pair. + * @notice Simulates swapping tokens on a given pool. * @dev This function should be state modifying meaning it should actually * execute the swap and change the state of the evm accordingly. Please * include a gas usage estimate for each amount. This can be achieved e.g. @@ -50,7 +50,7 @@ interface ISwapAdapter is ISwapAdapterTypes { * this is optional, defined via `Capability.PriceFunction`, it is valid to * return a zero value for this price in that case it will be estimated * numerically. To return zero use Fraction(0, 1). - * @param pairId The ID of the trading pair. + * @param poolId The ID of the trading pool. * @param sellToken The token being sold. * @param buyToken The token being bought. * @param side The side of the trade (Sell or Buy). @@ -58,7 +58,7 @@ interface ISwapAdapter is ISwapAdapterTypes { * @return trade Trade struct representing the executed trade. */ function swap( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, OrderSide side, @@ -71,27 +71,27 @@ interface ISwapAdapter is ISwapAdapterTypes { /// close to zero. Overestimate if in doubt rather than underestimate. The /// swap function should not error with `LimitExceeded` if called with /// amounts below the limit. - /// @param pairId The ID of the trading pair. + /// @param poolId The ID of the trading pool. /// @param sellToken The token being sold. /// @param buyToken The token being bought. /// @return limits An array of limits. - function getLimits(bytes32 pairId, IERC20 sellToken, IERC20 buyToken) + function getLimits(bytes32 poolId, IERC20 sellToken, IERC20 buyToken) external returns (uint256[] memory limits); - /// @notice Retrieves the capabilities of the selected pair. - /// @param pairId The ID of the trading pair. + /// @notice Retrieves the capabilities of the selected pool. + /// @param poolId The ID of the trading pool. /// @return capabilities An array of Capability. - function getCapabilities(bytes32 pairId, IERC20 sellToken, IERC20 buyToken) + function getCapabilities(bytes32 poolId, IERC20 sellToken, IERC20 buyToken) external returns (Capability[] memory capabilities); - /// @notice Retrieves the tokens in the selected pair. + /// @notice Retrieves the tokens in the selected pool. /// @dev Mainly used for testing as this is redundant with the required /// substreams implementation. - /// @param pairId The ID of the trading pair. + /// @param poolId The ID of the trading pool. /// @return tokens An array of IERC20 contracts. - function getTokens(bytes32 pairId) + function getTokens(bytes32 poolId) external returns (IERC20[] memory tokens); diff --git a/evm/src/interfaces/ISwapAdapterTypes.sol b/evm/src/interfaces/ISwapAdapterTypes.sol index 81767e0..e3d7462 100644 --- a/evm/src/interfaces/ISwapAdapterTypes.sol +++ b/evm/src/interfaces/ISwapAdapterTypes.sol @@ -13,7 +13,7 @@ interface ISwapAdapterTypes { } /// @dev The Capability enum represents possible features of a trading - /// pair. + /// pool. enum Capability { Unset, // Support OrderSide.Sell values (required) @@ -24,10 +24,10 @@ interface ISwapAdapterTypes { PriceFunction, // Support tokens that charge a fee on transfer (optional) FeeOnTransfer, - // The pair does not suffer from price impact and maintains a constant + // The pool does not suffer from price impact and maintains a constant // price for increasingly larger specified amounts. (optional) ConstantPrice, - // Indicates that the pair does not read it's own token balances while + // Indicates that the pool does not read it's own token balances while // swapping. (optional) TokenBalanceIndependent, // Indicates that prices are returned scaled, else it is assumed prices @@ -49,7 +49,7 @@ interface ISwapAdapterTypes { uint256 calculatedAmount; // The amount of gas used in the trade. uint256 gasUsed; - // The price of the pair after the trade. For zero use Fraction(0, 1). + // The price of the pool after the trade. For zero use Fraction(0, 1). Fraction price; } diff --git a/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol b/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol index a413947..52d4771 100644 --- a/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol +++ b/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol @@ -13,13 +13,13 @@ contract UniswapV2SwapAdapter is ISwapAdapter { } function price( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, uint256[] memory specifiedAmounts ) external view override returns (Fraction[] memory prices) { prices = new Fraction[](specifiedAmounts.length); - IUniswapV2Pair pair = IUniswapV2Pair(address(bytes20(pairId))); + IUniswapV2Pair pair = IUniswapV2Pair(address(bytes20(poolId))); uint112 r0; uint112 r1; if (sellToken < buyToken) { @@ -51,7 +51,7 @@ contract UniswapV2SwapAdapter is ISwapAdapter { } function swap( - bytes32 pairId, + bytes32 poolId, IERC20 sellToken, IERC20 buyToken, OrderSide side, @@ -62,7 +62,7 @@ contract UniswapV2SwapAdapter is ISwapAdapter { // expected zero Fraction(0, 1) } - IUniswapV2Pair pair = IUniswapV2Pair(address(bytes20(pairId))); + IUniswapV2Pair pair = IUniswapV2Pair(address(bytes20(poolId))); uint112 r0; uint112 r1; bool zero2one = sellToken < buyToken; @@ -168,13 +168,13 @@ contract UniswapV2SwapAdapter is ISwapAdapter { amountIn = (numerator / denominator) + 1; } - function getLimits(bytes32 pairId, IERC20 sellToken, IERC20 buyToken) + function getLimits(bytes32 poolId, IERC20 sellToken, IERC20 buyToken) external view override returns (uint256[] memory limits) { - IUniswapV2Pair pair = IUniswapV2Pair(address(bytes20(pairId))); + IUniswapV2Pair pair = IUniswapV2Pair(address(bytes20(poolId))); limits = new uint256[](2); (uint256 r0, uint256 r1,) = pair.getReserves(); if (sellToken < buyToken) { @@ -198,14 +198,14 @@ contract UniswapV2SwapAdapter is ISwapAdapter { capabilities[2] = Capability.PriceFunction; } - function getTokens(bytes32 pairId) + function getTokens(bytes32 poolId) external view override returns (IERC20[] memory tokens) { tokens = new IERC20[](2); - IUniswapV2Pair pair = IUniswapV2Pair(address(bytes20(pairId))); + IUniswapV2Pair pair = IUniswapV2Pair(address(bytes20(poolId))); tokens[0] = IERC20(pair.token0()); tokens[1] = IERC20(pair.token1()); } diff --git a/evm/src/uniswap-v2/manifest.yaml b/evm/src/uniswap-v2/manifest.yaml index 5864481..a6f469c 100644 --- a/evm/src/uniswap-v2/manifest.yaml +++ b/evm/src/uniswap-v2/manifest.yaml @@ -27,7 +27,7 @@ instances: # getTokens are not implemented. tests: instances: - - pair_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" + - pool_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" sell_token: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" buy_token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" block: 17000000 diff --git a/evm/test/BalancerV2SwapAdapter.t.sol b/evm/test/BalancerV2SwapAdapter.t.sol index ccf3447..7fb4564 100644 --- a/evm/test/BalancerV2SwapAdapter.t.sol +++ b/evm/test/BalancerV2SwapAdapter.t.sol @@ -202,11 +202,11 @@ contract BalancerV2SwapAdapterTest is Test, ISwapAdapterTypes { assert(limits[1] > 0); } - function testGetCapabilitiesFuzz(bytes32 pair, address t0, address t1) + function testGetCapabilitiesFuzz(bytes32 pool, address t0, address t1) public { Capability[] memory res = - adapter.getCapabilities(pair, IERC20(t0), IERC20(t1)); + adapter.getCapabilities(pool, IERC20(t0), IERC20(t1)); assertEq(res.length, 2); assertEq(uint256(res[0]), uint256(Capability.SellOrder));