rename pairId to more general poolId
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user