From 6a32b01bc8f1ca0d915d06b5d5340256d36f0ac1 Mon Sep 17 00:00:00 2001 From: kayibal Date: Wed, 2 Oct 2024 13:56:36 +0200 Subject: [PATCH] feat: Derivative and SamplePoint suggestions Adds derivatives and sample points suggestions to the sawp adapter interface. --- evm/src/interfaces/ISwapAdapter.sol | 44 ++++++++++++++++++++++++ evm/src/interfaces/ISwapAdapterTypes.sol | 8 ++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/evm/src/interfaces/ISwapAdapter.sol b/evm/src/interfaces/ISwapAdapter.sol index ab3bacc8..15cea599 100644 --- a/evm/src/interfaces/ISwapAdapter.sol +++ b/evm/src/interfaces/ISwapAdapter.sol @@ -39,6 +39,50 @@ interface ISwapAdapter is ISwapAdapterTypes { uint256[] memory specifiedAmounts ) external returns (Fraction[] memory prices); + /// @notice Calculates pool prices derivatives for specified amounts + /// (optional). + /// @dev TODO + /// @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 + /// calculation. + /// @return prices array of prices as fractions corresponding to the + /// provided amounts. + function priceDerivative( + bytes32 poolId, + address sellToken, + address buyToken, + uint256[] memory specifiedAmounts + ) external returns (Fraction[] memory prices); + + /// @notice Calculates second pool prices derivatives for specified amounts + /// (optional). + /// @dev TODO + /// @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 + /// calculation. + /// @return prices array of prices as fractions corresponding to the + /// provided amounts. + function priceSecondDerivative( + bytes32 poolId, + address sellToken, + address buyToken, + uint256[] memory specifiedAmounts + ) external returns (Fraction[] memory prices); + + /// @notice Suggests sample points on the price and derivative functions. + /// @dev TODO + /// @param poolId The ID of the trading pool. + /// @param sellToken The token being sold. + /// @param buyToken The token being bought. + /// @return array of sample points + function samplePoints(bytes32 poolId, address sellToken, address buyToken) + external + returns (uint256[] memory points); + /** * @notice Simulates swapping tokens on a given pool. * @dev This function should be state modifying, meaning it should actually diff --git a/evm/src/interfaces/ISwapAdapterTypes.sol b/evm/src/interfaces/ISwapAdapterTypes.sol index 323ac0a6..d03a932b 100644 --- a/evm/src/interfaces/ISwapAdapterTypes.sol +++ b/evm/src/interfaces/ISwapAdapterTypes.sol @@ -36,7 +36,13 @@ interface ISwapAdapterTypes { HardLimits, // Indicates whether the pool's price function can be called with // amountIn=0 to return the current price (optional) - MarginalPrice + MarginalPrice, + // Support evaluating the price derivative function (optional) + Derivatives, + // Support evaluating the second price derivative function (optional) + SecondDerivatives, + // Support evaluating the price sample point function (optional) + SamplePoints } /// @dev Representation used for rational numbers such as prices.