Implement adapter and test templates
This commit is contained in:
@@ -3,14 +3,13 @@ pragma experimental ABIEncoderV2;
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol";
|
||||
import "forge-std/Test.sol";
|
||||
|
||||
// Maximum Swap In/Out Ratio - 0.3
|
||||
// https://balancer.gitbook.io/balancer/core-concepts/protocol/limitations#v2-limits
|
||||
uint256 constant RESERVE_LIMIT_FACTOR = 4;
|
||||
uint256 constant SWAP_DEADLINE_SEC = 1000;
|
||||
|
||||
contract BalancerV2SwapAdapter is ISwapAdapter, Test {
|
||||
contract BalancerV2SwapAdapter is ISwapAdapter {
|
||||
IVault immutable vault;
|
||||
|
||||
constructor(address payable vault_) {
|
||||
|
||||
@@ -68,7 +68,7 @@ interface ISwapAdapter is ISwapAdapterTypes {
|
||||
/// @notice Retrieves the limits for each token.
|
||||
/// @dev Retrieve 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 or when the swap fails because of the pools restrictions.
|
||||
/// close to zero or when the swap fails because of the pools restrictions.
|
||||
/// Overestimate if in doubt rather than underestimate. The
|
||||
/// swap function should not error with `LimitExceeded` if called with
|
||||
/// amounts below the limit.
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
pragma experimental ABIEncoderV2;
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol";
|
||||
|
||||
/// @title TemplateSwapAdapter
|
||||
/// @dev This is a template for a swap adapter.
|
||||
/// Rename it to your own protocol's name and implement it according to the
|
||||
/// specification.
|
||||
contract TemplateSwapAdapter is ISwapAdapter {
|
||||
function price(
|
||||
bytes32 _poolId,
|
||||
IERC20 _sellToken,
|
||||
IERC20 _buyToken,
|
||||
uint256[] memory _specifiedAmounts
|
||||
) external view override returns (Fraction[] memory _prices) {
|
||||
revert NotImplemented("TemplateSwapAdapter.price");
|
||||
}
|
||||
|
||||
function swap(
|
||||
bytes32 poolId,
|
||||
IERC20 sellToken,
|
||||
IERC20 buyToken,
|
||||
OrderSide side,
|
||||
uint256 specifiedAmount
|
||||
) external returns (Trade memory trade) {
|
||||
revert NotImplemented("TemplateSwapAdapter.swap");
|
||||
}
|
||||
|
||||
function getLimits(bytes32 poolId, IERC20 sellToken, IERC20 buyToken)
|
||||
external
|
||||
returns (uint256[] memory limits)
|
||||
{
|
||||
revert NotImplemented("TemplateSwapAdapter.getLimits");
|
||||
}
|
||||
|
||||
function getCapabilities(bytes32 poolId, IERC20 sellToken, IERC20 buyToken)
|
||||
external
|
||||
returns (Capability[] memory capabilities)
|
||||
{
|
||||
revert NotImplemented("TemplateSwapAdapter.getCapabilities");
|
||||
}
|
||||
|
||||
function getTokens(bytes32 poolId)
|
||||
external
|
||||
returns (IERC20[] memory tokens)
|
||||
{
|
||||
revert NotImplemented("TemplateSwapAdapter.getTokens");
|
||||
}
|
||||
|
||||
function getPoolIds(uint256 offset, uint256 limit)
|
||||
external
|
||||
returns (bytes32[] memory ids)
|
||||
{
|
||||
revert NotImplemented("TemplateSwapAdapter.getPoolIds");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ pragma solidity ^0.8.13;
|
||||
|
||||
import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol";
|
||||
|
||||
// Uniswap handles arbirary amounts, but we limit the amount to 10x just in case
|
||||
// Uniswap handles arbirary amounts, but we limit the amount to 10x just in case
|
||||
uint256 constant RESERVE_LIMIT_FACTOR = 10;
|
||||
|
||||
contract UniswapV2SwapAdapter is ISwapAdapter {
|
||||
@@ -119,7 +119,8 @@ contract UniswapV2SwapAdapter is ISwapAdapter {
|
||||
return amountOut;
|
||||
}
|
||||
|
||||
/// @notice Given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
|
||||
/// @notice Given an input amount of an asset and pair reserves, returns the
|
||||
/// maximum output amount of the other asset
|
||||
/// @param amountIn The amount of the token being sold.
|
||||
/// @param reserveIn The reserve of the token being sold.
|
||||
/// @param reserveOut The reserve of the token being bought.
|
||||
@@ -173,7 +174,8 @@ contract UniswapV2SwapAdapter is ISwapAdapter {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/// @notice Given an output amount of an asset and pair reserves, returns a required input amount of the other asset
|
||||
/// @notice Given an output amount of an asset and pair reserves, returns a
|
||||
/// required input amount of the other asset
|
||||
/// @param amountOut The amount of the token being bought.
|
||||
/// @param reserveIn The reserve of the token being sold.
|
||||
/// @param reserveOut The reserve of the token being bought.
|
||||
|
||||
Reference in New Issue
Block a user