Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.

SPDX-License-Identifier: Apache License, Version 2.0

*/

pragma solidity ^0.6.10;
Expand All @@ -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
**/
Expand All @@ -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.
*
Expand All @@ -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.
*/

Expand All @@ -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);

}

Expand All @@ -120,7 +133,13 @@ contract UniswapV2ExchangeAdapter {
*
*/

// YOUR CODE HERE
function getSpender()
external
view
returns (address)
{
return router;
}

}

1 change: 1 addition & 0 deletions utils/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 6 additions & 0 deletions utils/deploys/deployAdapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
CompoundWrapAdapter,
YearnWrapAdapter,
UniswapPairPriceAdapter,
UniswapV2ExchangeAdapter,
UniswapV2IndexExchangeAdapter,
UniswapV2TransferFeeExchangeAdapter,
ZeroExApiAdapter,
Expand All @@ -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";
Expand Down Expand Up @@ -77,6 +79,10 @@ export default class DeployAdapters {
return await new UniswapV2IndexExchangeAdapter__factory(this._deployerSigner).deploy(uniswapV2Router);
}

public async deployUniswapV2ExchangeAdapter(uniswapV2Router: Address): Promise<UniswapV2ExchangeAdapter> {
return await new UniswapV2ExchangeAdapter__factory(this._deployerSigner).deploy(uniswapV2Router);
}

public async deployAaveGovernanceAdapter(aaveProtoGovernance: Address, aaveToken: Address): Promise<AaveGovernanceAdapter> {
return await new AaveGovernanceAdapter__factory(this._deployerSigner).deploy(aaveProtoGovernance, aaveToken);
}
Expand Down