Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-3406: Add new bytes parameter to swap #64

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
9 changes: 5 additions & 4 deletions evm/src/angle/AngleAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ contract AngleAdapter is ISwapAdapter {
address sellToken,
address buyToken,
OrderSide side,
uint256 specifiedAmount
uint256 specifiedAmount,
bytes32
) external returns (Trade memory trade) {
if (specifiedAmount == 0) {
return trade;
Expand Down Expand Up @@ -223,7 +224,7 @@ contract AngleAdapter is ISwapAdapter {

interface IAgToken is IERC20 {
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MINTER ROLE ONLY FUNCTIONS
MINTER ROLE ONLY FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

/// @notice Lets a whitelisted contract mint agTokens
Expand Down Expand Up @@ -254,7 +255,7 @@ interface IAgToken is IERC20 {
function burnSelf(uint256 amount, address burner) external;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TREASURY ONLY FUNCTIONS
TREASURY ONLY FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

/// @notice Adds a minter in the contract
Expand All @@ -274,7 +275,7 @@ interface IAgToken is IERC20 {
function setTreasury(address _treasury) external;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

/// @notice Checks whether an address has the right to mint agTokens
Expand Down
4 changes: 3 additions & 1 deletion evm/src/balancer-v2/BalancerV2SwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ contract BalancerV2SwapAdapter is ISwapAdapter {
address sellToken,
address buyToken,
OrderSide side,
uint256 specifiedAmount
uint256 specifiedAmount,
bytes32 data
) external override returns (Trade memory trade) {
uint256 sellAmount;
IVault.SwapKind kind;
bool reduceFee = abi.decode(abi.encodePacked(data), (bool));
PierreMkt marked this conversation as resolved.
Show resolved Hide resolved
uint256 limit; // TODO set this slippage limit properly
if (side == OrderSide.Sell) {
kind = IVault.SwapKind.GIVEN_IN;
Expand Down
3 changes: 2 additions & 1 deletion evm/src/etherfi/EtherfiAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ contract EtherfiAdapter is ISwapAdapter {
address sellToken,
address buyToken,
OrderSide side,
uint256 specifiedAmount
uint256 specifiedAmount,
bytes32
)
external
override
Expand Down
3 changes: 2 additions & 1 deletion evm/src/integral/IntegralSwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ contract IntegralSwapAdapter is ISwapAdapter {
address sellToken,
address buyToken,
OrderSide side,
uint256 specifiedAmount
uint256 specifiedAmount,
bytes32
) external override returns (Trade memory trade) {
if (specifiedAmount == 0) {
return trade;
Expand Down
4 changes: 3 additions & 1 deletion evm/src/interfaces/ISwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ interface ISwapAdapter is ISwapAdapterTypes {
* @param buyToken The token being bought.
* @param side The side of the trade (Sell or Buy).
* @param specifiedAmount The amount to be traded.
* @param data Additional arbitrary data for the swap.
* @return trade Trade struct representing the executed trade.
*/
function swap(
bytes32 poolId,
address sellToken,
address buyToken,
OrderSide side,
uint256 specifiedAmount
uint256 specifiedAmount,
bytes32 data
) external returns (Trade memory trade);

/// @notice Retrieves the limits for each token.
Expand Down
3 changes: 2 additions & 1 deletion evm/src/template/TemplateSwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ contract TemplateSwapAdapter is ISwapAdapter {
address sellToken,
address buyToken,
OrderSide side,
uint256 specifiedAmount
uint256 specifiedAmount,
bytes32
) external returns (Trade memory trade) {
revert NotImplemented("TemplateSwapAdapter.swap");
}
Expand Down
3 changes: 2 additions & 1 deletion evm/src/uniswap-v2/UniswapV2SwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ contract UniswapV2SwapAdapter is ISwapAdapter {
address sellToken,
address buyToken,
OrderSide side,
uint256 specifiedAmount
uint256 specifiedAmount,
bytes32
) external override returns (Trade memory trade) {
if (specifiedAmount == 0) {
return trade;
Expand Down
17 changes: 14 additions & 3 deletions evm/test/AdapterTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "src/libraries/FractionMath.sol";
contract AdapterTest is Test, ISwapAdapterTypes {
using FractionMath for Fraction;

bytes32 mockData;
uint256 constant pricePrecision = 10e24;
string[] public stringPctgs = ["0%", "0.1%", "50%", "100%"];

Expand Down Expand Up @@ -102,7 +103,7 @@ contract AdapterTest is Test, ISwapAdapterTypes {

console2.log("TEST: Swapping %d of %s", amounts[j], tokenIn);
trade = adapter.swap(
poolId, tokenIn, tokenOut, OrderSide.Sell, amounts[j]
poolId, tokenIn, tokenOut, OrderSide.Sell, amounts[j], mockData
);
uint256 executedPrice =
trade.calculatedAmount * pricePrecision / amounts[j];
Expand Down Expand Up @@ -191,7 +192,12 @@ contract AdapterTest is Test, ISwapAdapterTypes {
);
}
try adapter.swap(
poolId, tokenIn, tokenOut, OrderSide.Sell, aboveLimitArray[0]
poolId,
tokenIn,
tokenOut,
OrderSide.Sell,
aboveLimitArray[0],
mockData
) {
revert("Pool shouldn't be able to swap above the sell limit");
} catch Error(string memory s) {
Expand All @@ -217,7 +223,12 @@ contract AdapterTest is Test, ISwapAdapterTypes {

adapter.price(poolId, tokenIn, tokenOut, aboveLimitArray);
adapter.swap(
poolId, tokenIn, tokenOut, OrderSide.Sell, aboveLimitArray[0]
poolId,
tokenIn,
tokenOut,
OrderSide.Sell,
aboveLimitArray[0],
mockData
);
}

Expand Down
12 changes: 7 additions & 5 deletions evm/test/AngleAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
ITransmuter(0x00253582b2a3FE112feEC532221d9708c64cEFAb);

uint256 constant TEST_ITERATIONS = 100;
bytes32 mockData;

function setUp() public {
uint256 forkBlock = 18921770;
Expand Down Expand Up @@ -55,7 +56,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
uint256 agEUR_balance = agEUR.balanceOf(address(this));

Trade memory trade = adapter.swap(
pair, address(EURC), address(agEUR), side, specifiedAmount
pair, address(EURC), address(agEUR), side, specifiedAmount, mockData
);

if (trade.calculatedAmount > 0) {
Expand Down Expand Up @@ -106,7 +107,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
uint256 agEUR_balance = agEUR.balanceOf(address(this));

Trade memory trade = adapter.swap(
pair, address(agEUR), address(EURC), side, specifiedAmount
pair, address(agEUR), address(EURC), side, specifiedAmount, mockData
);

if (trade.calculatedAmount > 0) {
Expand Down Expand Up @@ -159,7 +160,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
agEUR.approve(address(adapter), type(uint256).max);
}
trades[i] = adapter.swap(
pair, address(agEUR), address(EURC), side, amounts[i]
pair, address(agEUR), address(EURC), side, amounts[i], mockData
);
vm.revertTo(beforeSwap);
}
Expand All @@ -178,19 +179,20 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {

function testGetCapabilitiesAngle(bytes32 pair, address t0, address t1)
public
view
{
Capability[] memory res = adapter.getCapabilities(pair, t0, t1);

assertEq(res.length, 2);
}

function testGetTokensAngle() public {
function testGetTokensAngle() public view {
address[] memory tokens = adapter.getTokens(bytes32(0));

assertGe(tokens.length, 2);
}

function testGetLimitsAngle() public {
function testGetLimitsAngle() public view {
bytes32 pair = bytes32(0);
uint256[] memory limits =
adapter.getLimits(pair, address(agEUR), address(EURC));
Expand Down
26 changes: 22 additions & 4 deletions evm/test/BalancerV2SwapAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {FractionMath} from "src/libraries/FractionMath.sol";
contract BalancerV2SwapAdapterTest is AdapterTest {
using FractionMath for Fraction;

bytes32 mockBoolData = bytes32(abi.encode(false));
IVault constant balancerV2Vault =
IVault(payable(0xBA12222222228d8Ba445958a75a0704d566BF2C8));
BalancerV2SwapAdapter adapter;
Expand Down Expand Up @@ -111,7 +112,12 @@ contract BalancerV2SwapAdapterTest is AdapterTest {
uint256 weth_balance = IERC20(WETH).balanceOf(address(this));

Trade memory trade = adapter.swap(
B_80BAL_20WETH_POOL_ID, BAL, WETH, side, specifiedAmount
B_80BAL_20WETH_POOL_ID,
BAL,
WETH,
side,
specifiedAmount,
mockBoolData
);

if (trade.calculatedAmount > 0) {
Expand Down Expand Up @@ -149,7 +155,12 @@ contract BalancerV2SwapAdapterTest is AdapterTest {
deal(BAL, address(this), amounts[i]);
IERC20(BAL).approve(address(adapter), amounts[i]);
trades[i] = adapter.swap(
B_80BAL_20WETH_POOL_ID, BAL, WETH, OrderSide.Sell, amounts[i]
B_80BAL_20WETH_POOL_ID,
BAL,
WETH,
OrderSide.Sell,
amounts[i],
mockBoolData
);

vm.revertTo(beforeSwap);
Expand Down Expand Up @@ -180,7 +191,12 @@ contract BalancerV2SwapAdapterTest is AdapterTest {
deal(BAL, address(this), amountIn);
IERC20(BAL).approve(address(adapter), amountIn);
trades[i] = adapter.swap(
B_80BAL_20WETH_POOL_ID, BAL, WETH, OrderSide.Buy, amounts[i]
B_80BAL_20WETH_POOL_ID,
BAL,
WETH,
OrderSide.Buy,
amounts[i],
mockBoolData
);

vm.revertTo(beforeSwap);
Expand All @@ -204,16 +220,18 @@ contract BalancerV2SwapAdapterTest is AdapterTest {

function testGetCapabilitiesFuzz(bytes32 pool, address t0, address t1)
public
view
{
Capability[] memory res = adapter.getCapabilities(pool, t0, t1);

assertEq(res.length, 4);
assertEq(uint256(res[0]), uint256(Capability.SellOrder));
assertEq(uint256(res[1]), uint256(Capability.BuyOrder));
assertEq(uint256(res[2]), uint256(Capability.PriceFunction));
assertEq(uint256(res[3]), uint256(Capability.HardLimits));
}

function testGetTokens() public {
function testGetTokens() public view {
address[] memory tokens = adapter.getTokens(B_80BAL_20WETH_POOL_ID);

assertEq(tokens[0], BAL);
Expand Down
Loading
Loading