diff --git a/contracts/protocol/integration/exchange/UniswapV2ExchangeAdapter.sol b/contracts/protocol/integration/exchange/UniswapV2ExchangeAdapter.sol index 757e557..46e7211 100644 --- a/contracts/protocol/integration/exchange/UniswapV2ExchangeAdapter.sol +++ b/contracts/protocol/integration/exchange/UniswapV2ExchangeAdapter.sol @@ -14,7 +14,7 @@ limitations under the License. SPDX-License-Identifier: Apache License, Version 2.0 - + */ pragma solidity ^0.6.10; @@ -24,21 +24,21 @@ pragma experimental "ABIEncoderV2"; contract UniswapV2ExchangeAdapter { /* ============= State Variable ============= */ - /** + /** * Address of Uniswap Exchange V2 Router Contract **/ /* * Write a state variable to store the address of the Uniswap Exchange V2 Router Contract */ - - - // YOUR CODE HERE + + + address public immutable router; /* ============= Constructor ============= */ - /** + /** * Set state variable * @param _router Address of Uniswap Exchange V2 Rounter Contract **/ @@ -48,12 +48,13 @@ contract UniswapV2ExchangeAdapter { */ - // YOUR CODE HERE - + constructor(address _router) public { + router = _router; + } /* ============ External Getter Functions ============ */ - + /** * Calculate UniSwap trade encoded calldata. To be invoked on the SetToken. * @@ -70,16 +71,22 @@ contract UniswapV2ExchangeAdapter { */ - /* - * Write getTradeCalldata function with the parameters / return values listed above. + /* + * Write getTradeCalldata function with the parameters / return values listed above. * The function will return 3 values: address of the uniswap router, 0 for Call value, trade calldata */ - function getTradeCalldata(/*YOUR CODE HERE*/) external view returns (/*YOUR CODE HERE*/) { + function getTradeCalldata( + address _sourceToken, + address _destinationToken, + address _destinationAddress, + uint256 _sourceQuantity, + uint256 _minDestinationQuantity, + bytes memory _data) external view returns (address, uint256, bytes memory) { - /* - * We have created a path for the address' of _sourceToken and _destinationToken + /* + * We have created a path for the address' of _sourceToken and _destinationToken * to be used in the function call to the uniswap contract. */ @@ -92,17 +99,23 @@ contract UniswapV2ExchangeAdapter { } else { path = abi.decode(_data, (address[])); } - - /* - * Create a bytes memory variable called 'callData' to store the abi.encodedWithSignature data from Uniswap function swapExactTokensForTokens. + + /* + * Create a bytes memory variable called 'callData' to store the abi.encodedWithSignature data from Uniswap function swapExactTokensForTokens. * Please see README.md resources for more details on the Uniswap function swapExactTokensForTokens. - */ + */ - // YOUR CODE HERE + bytes memory callData = abi.encodeWithSignature( + "swapExactTokensForTokens(uint256,uint256,address[],address,uint256)", + _sourceQuantity, + _minDestinationQuantity, + path, + _destinationAddress, + block.timestamp); - return (/*YOUR CODE HERE*/); + return (router, 0, callData); } @@ -120,7 +133,13 @@ contract UniswapV2ExchangeAdapter { * */ - // YOUR CODE HERE + function getSpender() + external + view + returns (address) + { + return router; + } } diff --git a/utils/contracts/index.ts b/utils/contracts/index.ts index 578c03a..a97767d 100644 --- a/utils/contracts/index.ts +++ b/utils/contracts/index.ts @@ -83,6 +83,7 @@ export { Uint256ArrayUtilsMock } from "../../typechain/Uint256ArrayUtilsMock"; export { Uni } from "../../typechain/Uni"; export { UniswapPairPriceAdapter } from "../../typechain/UniswapPairPriceAdapter"; export { UniswapV2IndexExchangeAdapter } from "../../typechain/UniswapV2IndexExchangeAdapter"; +export { UniswapV2ExchangeAdapter } from "../../typechain/UniswapV2ExchangeAdapter"; export { UniswapV2TransferFeeExchangeAdapter } from "../../typechain/UniswapV2TransferFeeExchangeAdapter"; export { UniswapV2Factory } from "../../typechain/UniswapV2Factory"; export { UniswapV2Pair } from "../../typechain/UniswapV2Pair"; diff --git a/utils/deploys/deployAdapters.ts b/utils/deploys/deployAdapters.ts index ef18a15..3e1fa7a 100644 --- a/utils/deploys/deployAdapters.ts +++ b/utils/deploys/deployAdapters.ts @@ -15,6 +15,7 @@ import { CompoundWrapAdapter, YearnWrapAdapter, UniswapPairPriceAdapter, + UniswapV2ExchangeAdapter, UniswapV2IndexExchangeAdapter, UniswapV2TransferFeeExchangeAdapter, ZeroExApiAdapter, @@ -40,6 +41,7 @@ import { AaveWrapAdapter__factory } from "../../typechain/factories/AaveWrapAdap import { CompoundWrapAdapter__factory } from "../../typechain/factories/CompoundWrapAdapter__factory"; import { YearnWrapAdapter__factory } from "../../typechain/factories/YearnWrapAdapter__factory"; import { UniswapPairPriceAdapter__factory } from "../../typechain/factories/UniswapPairPriceAdapter__factory"; +import { UniswapV2ExchangeAdapter__factory } from "../../typechain/factories/UniswapV2ExchangeAdapter__factory"; import { UniswapV2TransferFeeExchangeAdapter__factory } from "../../typechain/factories/UniswapV2TransferFeeExchangeAdapter__factory"; import { UniswapV2IndexExchangeAdapter__factory } from "../../typechain/factories/UniswapV2IndexExchangeAdapter__factory"; import { SynthetixExchangeAdapter__factory } from "../../typechain/factories/SynthetixExchangeAdapter__factory"; @@ -77,6 +79,10 @@ export default class DeployAdapters { return await new UniswapV2IndexExchangeAdapter__factory(this._deployerSigner).deploy(uniswapV2Router); } + public async deployUniswapV2ExchangeAdapter(uniswapV2Router: Address): Promise { + return await new UniswapV2ExchangeAdapter__factory(this._deployerSigner).deploy(uniswapV2Router); + } + public async deployAaveGovernanceAdapter(aaveProtoGovernance: Address, aaveToken: Address): Promise { return await new AaveGovernanceAdapter__factory(this._deployerSigner).deploy(aaveProtoGovernance, aaveToken); }