From 3425b8b123e31f14feffe4f01011668b5a1a3f82 Mon Sep 17 00:00:00 2001 From: kayibal Date: Mon, 6 Nov 2023 12:56:55 +0000 Subject: [PATCH] Renaming, cleanup and add manifest example. --- .../{IPairFunctions.sol => ISwapAdapter.sol} | 6 ++-- ...nctionsTypes.sol => ISwapAdapterTypes.sol} | 2 +- ...Functions.sol => UniswapV2SwapAdapter.sol} | 4 +-- evm/src/uniswap-v2/manifest.yaml | 36 +++++++++++++++++++ ...ction.t.sol => UniswapV2SwapAdapter.t.sol} | 10 +++--- 5 files changed, 47 insertions(+), 11 deletions(-) rename evm/interfaces/{IPairFunctions.sol => ISwapAdapter.sol} (97%) rename evm/interfaces/{IPairFunctionsTypes.sol => ISwapAdapterTypes.sol} (98%) rename evm/src/uniswap-v2/{UniswapV2PairFunctions.sol => UniswapV2SwapAdapter.sol} (99%) create mode 100644 evm/src/uniswap-v2/manifest.yaml rename evm/test/{UniswapV2PairFunction.t.sol => UniswapV2SwapAdapter.t.sol} (93%) diff --git a/evm/interfaces/IPairFunctions.sol b/evm/interfaces/ISwapAdapter.sol similarity index 97% rename from evm/interfaces/IPairFunctions.sol rename to evm/interfaces/ISwapAdapter.sol index 398cb05..9995783 100644 --- a/evm/interfaces/IPairFunctions.sol +++ b/evm/interfaces/ISwapAdapter.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.13; import "openzeppelin-contracts/contracts/interfaces/IERC20.sol"; -import "interfaces/IPairFunctionsTypes.sol"; +import "interfaces/ISwapAdapterTypes.sol"; -/// @title IPairFunctions +/// @title ISwapAdapterTypes /// @dev Implement this interface to support propeller routing through your pairs. /// @dev Before implementing the interface we need to introduce three function for a /// @dev given pair: The swap(x), gas(x) and price(x) functions: @@ -18,7 +18,7 @@ import "interfaces/IPairFunctionsTypes.sol"; /// @dev During calls to swap and getLimits, the caller can be assumed to /// @dev have the required sell or buy token balance as well as unlimited approvals /// @dev to this contract. -interface IPairFunctions is IPairFunctionTypes { +interface ISwapAdapter is ISwapAdapterTypes { /// @notice Calculates pair prices for specified amounts (optional). /// @dev The returned prices should include all dex fees, in case the fee /// @dev is dynamic, the returned price is expected to include the minimum fee. diff --git a/evm/interfaces/IPairFunctionsTypes.sol b/evm/interfaces/ISwapAdapterTypes.sol similarity index 98% rename from evm/interfaces/IPairFunctionsTypes.sol rename to evm/interfaces/ISwapAdapterTypes.sol index ec0c22f..abe5392 100644 --- a/evm/interfaces/IPairFunctionsTypes.sol +++ b/evm/interfaces/ISwapAdapterTypes.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.13; import "openzeppelin-contracts/contracts/interfaces/IERC20.sol"; -interface IPairFunctionTypes { +interface ISwapAdapterTypes { /// @dev The SwapSide enum represents possible sides of a trade: Sell or Buy. /// @dev E.g. if SwapSide is Sell, the sell amount is interpreted to be fixed. enum SwapSide { diff --git a/evm/src/uniswap-v2/UniswapV2PairFunctions.sol b/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol similarity index 99% rename from evm/src/uniswap-v2/UniswapV2PairFunctions.sol rename to evm/src/uniswap-v2/UniswapV2SwapAdapter.sol index b4f4dbb..d86c505 100644 --- a/evm/src/uniswap-v2/UniswapV2PairFunctions.sol +++ b/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity ^0.8.13; -import "interfaces/IPairFunctions.sol"; +import "interfaces/ISwapAdapter.sol"; -contract UniswapV2PairFunctions is IPairFunctions { +contract UniswapV2SwapAdapter is ISwapAdapter { IUniswapV2Factory immutable factory; constructor(address factory_) { diff --git a/evm/src/uniswap-v2/manifest.yaml b/evm/src/uniswap-v2/manifest.yaml new file mode 100644 index 0000000..63119f3 --- /dev/null +++ b/evm/src/uniswap-v2/manifest.yaml @@ -0,0 +1,36 @@ +# information about the author helps us reach out in case of issues. +author: + name: Propellerheads.xyz + email: alan@propellerheads.xyz + +# Protocol Constants +constants: + protocol_gas: 30000 + # minimum capabilities we can expect, individual pools may extend these + capabilities: + - SellSide + - BuySide + - PriceFunction + +# The file containing the adapter contract +contract: UniswapV2SwapAdapter.sol + +# Deployment instances used to generate chain specific bytecode. +instances: + - chain: + name: mainnet + id: 0 + arguments: + - "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f" + +# Specify some automatic test cases in case getPools and +# getTokens are not implemented. +tests: + instances: + - pair_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" + sell_token: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" + buy_token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" + block: 17000000 + chain: + id: 0 + name: mainnet diff --git a/evm/test/UniswapV2PairFunction.t.sol b/evm/test/UniswapV2SwapAdapter.t.sol similarity index 93% rename from evm/test/UniswapV2PairFunction.t.sol rename to evm/test/UniswapV2SwapAdapter.t.sol index 60f49b0..78ebe7f 100644 --- a/evm/test/UniswapV2PairFunction.t.sol +++ b/evm/test/UniswapV2SwapAdapter.t.sol @@ -3,11 +3,11 @@ pragma solidity ^0.8.13; import "forge-std/Test.sol"; import "openzeppelin-contracts/contracts/interfaces/IERC20.sol"; -import "src/uniswap-v2/UniswapV2PairFunctions.sol"; -import "interfaces/IPairFunctionsTypes.sol"; +import "src/uniswap-v2/UniswapV2SwapAdapter.sol"; +import "interfaces/ISwapAdapterTypes.sol"; -contract UniswapV2PairFunctionTest is Test, IPairFunctionTypes { - UniswapV2PairFunctions pairFunctions; +contract UniswapV2PairFunctionTest is Test, ISwapAdapterTypes { + UniswapV2SwapAdapter pairFunctions; IERC20 constant WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); IERC20 constant USDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); address constant USDC_WETH_PAIR = 0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc; @@ -16,7 +16,7 @@ contract UniswapV2PairFunctionTest is Test, IPairFunctionTypes { uint256 forkBlock = 17000000; vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock); pairFunctions = new - UniswapV2PairFunctions(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f); + UniswapV2SwapAdapter(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f); } function testPriceFuzz(uint256 amount0, uint256 amount1) public {