Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a4dad49
Initial uniswap v2 amm adapter
Aug 14, 2021
671fa4a
First pass at tests for Uniswap V2 AMM Adapter
Aug 15, 2021
97823a9
Make sure the correct token addresses are used in the correct order
Aug 16, 2021
25e817b
Test for invalid pool
Aug 16, 2021
ca8a49c
Rename file to take into account the Uniswap version
Aug 16, 2021
cd7ded8
Re-write UniswapV2AmmAdapter so that it works correctly
Aug 18, 2021
0c7f502
Fix the < check
Aug 20, 2021
fb1e6a2
Test for token refund when required
Aug 21, 2021
9a4d30a
Re-write isValidPool for higher code coverage
Aug 21, 2021
a073df3
Avoid using low level functions
Aug 21, 2021
be15e85
Add more tests to cover all branches
Aug 23, 2021
790ed67
Allow liquidity addition with single asset
Aug 23, 2021
8444be3
Add support for removing liquidity to a single asset
Aug 23, 2021
5c497c4
Add some single asset tests for a set token
Aug 23, 2021
7b3bb0f
Optimize the swap amount when adding liquidity with a single asset
Aug 24, 2021
845503c
Implement some simplifications
Aug 25, 2021
ee95ddd
Re-use internal functions for better code coverage
Aug 25, 2021
16c93e8
Merge branch 'SetProtocol:master' into uniswapammadapter
Aug 26, 2021
40dff2f
Approve the correct liquidity size
Aug 26, 2021
2dc13ad
Implements updates requested in PR review
Aug 27, 2021
00e2e4b
Minor fix to a test
Aug 27, 2021
d21a281
Fix the AmmMock for the argument change
Aug 27, 2021
016660d
Updates for PR comments
Aug 28, 2021
07eec69
remove double approval
Aug 28, 2021
db2f5cf
Minor gas saving changes
Aug 30, 2021
49a576e
Updates to make the code more readable
Aug 30, 2021
f134a98
Remove empty lines
Aug 31, 2021
13ecfe2
Remove spaces
Aug 31, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion contracts/interfaces/IAmmAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pragma solidity 0.6.10;
interface IAmmAdapter {

function getProvideLiquidityCalldata(
address _setToken,
address _pool,
address[] calldata _components,
uint256[] calldata _maxTokensIn,
Expand All @@ -35,26 +36,29 @@ interface IAmmAdapter {
returns (address _target, uint256 _value, bytes memory _calldata);

function getProvideLiquiditySingleAssetCalldata(
address _setToken,
address _pool,
address _component,
uint256 _maxTokenIn,
uint256 _minLiquidity
) external view returns (address _target, uint256 _value, bytes memory _calldata);

function getRemoveLiquidityCalldata(
address _setToken,
address _pool,
address[] calldata _components,
uint256[] calldata _minTokensOut,
uint256 _liquidity
) external view returns (address _target, uint256 _value, bytes memory _calldata);

function getRemoveLiquiditySingleAssetCalldata(
address _setToken,
address _pool,
address _component,
uint256 _minTokenOut,
uint256 _liquidity
) external view returns (address _target, uint256 _value, bytes memory _calldata);

function getSpenderAddress(address _pool) external view returns(address);
function isValidPool(address _pool) external view returns(bool);
function isValidPool(address _pool, address[] memory _components) external view returns(bool);
}
26 changes: 19 additions & 7 deletions contracts/mocks/integrations/AmmAdapterMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ contract AmmAdapterMock is ERC20 {
/* ============ Adapter Functions ============ */

function getProvideLiquidityCalldata(
address /* _setToken */,
address _pool,
address[] calldata /* _components */,
address[] calldata _components,
uint256[] calldata _maxTokensIn,
uint256 _minLiquidity
)
external
view
returns (address _target, uint256 _value, bytes memory _calldata)
{
isValidPool(_pool);
isValidPool(_pool, _components);

// Check that components match the pool tokens

Expand All @@ -103,13 +104,18 @@ contract AmmAdapterMock is ERC20 {
}

function getProvideLiquiditySingleAssetCalldata(
address /* _setToken */,
address _pool,
address _component,
uint256 _maxTokenIn,
uint256 _minLiquidity
) external view returns (address _target, uint256 _value, bytes memory _calldata) {

address[] memory components = new address[](1);
components[0] = _component;

// This address must be the pool
isValidPool(_pool);
isValidPool(_pool, components);

bytes memory callData = abi.encodeWithSignature(
"joinswapPoolAmountOut(address,uint256,uint256)",
Expand All @@ -121,26 +127,32 @@ contract AmmAdapterMock is ERC20 {
}

function getRemoveLiquidityCalldata(
address /* _setToken */,
address _pool,
address[] calldata /* _components */,
address[] calldata _components,
uint256[] calldata _minTokensOut,
uint256 _liquidity
) external view returns (address _target, uint256 _value, bytes memory _calldata) {
// Validate the pool and components are legit?
isValidPool(_pool);
isValidPool(_pool, _components);

bytes memory callData = abi.encodeWithSignature("exitPool(uint256,uint256[])", _liquidity, _minTokensOut);
return (address(this), 0, callData);
}

function getRemoveLiquiditySingleAssetCalldata(
address /* _setToken */,
address _pool,
address _component,
uint256 _minTokenOut,
uint256 _liquidity
) external view returns (address _target, uint256 _value, bytes memory _calldata) {

address[] memory components = new address[](1);
components[0] = _component;

// Pool must be this address
isValidPool(_pool);
isValidPool(_pool, components);

bytes memory callData = abi.encodeWithSignature(
"exitswapPoolAmountIn(address,uint256,uint256)",
Expand All @@ -151,7 +163,7 @@ contract AmmAdapterMock is ERC20 {
return (address(this), 0, callData);
}

function isValidPool(address _pool) public view returns(bool) {
function isValidPool(address _pool,address[] memory /*_components*/) public view returns(bool) {
return _pool == address(this) || _pool == approvedToken;
}

Expand Down
Loading