Skip to content
This repository was archived by the owner on Apr 1, 2021. It is now read-only.
Merged
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
36 changes: 34 additions & 2 deletions contracts/protocol-viewers/SetTokenViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";


import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { ISetToken } from "../interfaces/ISetToken.sol";


Expand All @@ -27,9 +28,22 @@ import { ISetToken } from "../interfaces/ISetToken.sol";
* @author Set Protocol
*
* SetTokenViewer enables batch queries of SetToken state.
*
* UPDATE:
* - Added getSetDetails functions
*/
contract SetTokenViewer {

struct SetDetails {
string name;
string symbol;
address manager;
address[] modules;
ISetToken.ModuleState[] moduleStatuses;
ISetToken.Position[] positions;
uint256 totalSupply;
}

function batchFetchManagers(ISetToken[] memory _setTokens) external view returns (address[] memory) {
address[] memory managers = new address[](_setTokens.length);

Expand All @@ -40,10 +54,10 @@ contract SetTokenViewer {
}

function batchFetchModuleStates(
ISetToken[] calldata _setTokens,
ISetToken[] memory _setTokens,
address[] calldata _modules
)
external
public
view
returns (ISetToken.ModuleState[][] memory)
{
Expand All @@ -57,4 +71,22 @@ contract SetTokenViewer {
}
return states;
}

function getSetDetails(
ISetToken _setToken,
address[] calldata _moduleList
) external view returns(SetDetails memory) {
ISetToken[] memory _setTokens = new ISetToken[](1);
_setTokens[0] = _setToken;

return SetDetails({
name: ERC20(address(_setToken)).name(),
symbol: ERC20(address(_setToken)).symbol(),
manager: _setToken.manager(),
modules: _setToken.getModules(),
moduleStatuses: batchFetchModuleStates(_setTokens, _moduleList)[0],
positions: _setToken.getPositions(),
totalSupply: _setToken.totalSupply()
});
}
}
107 changes: 107 additions & 0 deletions contracts/protocol/integration/UniswapV2ExchangeAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Copyright 2020 Yam Finance

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

/**
* @title UniswapV2TradeAdapter
* @author Yam Finance
*
* Exchange adapter for Uniswap V2 Router02 that encodes trade data
*/
contract UniswapV2ExchangeAdapter {

/* ============ State Variables ============ */

// Address of Uniswap V2 Router02 contract
address public immutable router;

/* ============ Constructor ============ */

/**
* Set state variables
*
* @param _router Address of Uniswap V2 Router02 contract
*/
constructor(address _router) public {
router = _router;
}

/* ============ External Getter Functions ============ */

/**
* Return calldata for Uniswap V2 Router02
*
* @param _sourceToken Address of source token to be sold
* @param _destinationToken Address of destination token to buy
* @param _destinationAddress Address that assets should be transferred to
* @param _sourceQuantity Amount of source token to sell
* @param _minDestinationQuantity Min amount of destination token to buy
* @param _data Arbitrary bytes containing trade call data
*
* @return address Target contract address
* @return uint256 Call value
* @return bytes Trade calldata
*/
function getTradeCalldata(
address _sourceToken,
address _destinationToken,
address _destinationAddress,
uint256 _sourceQuantity,
uint256 _minDestinationQuantity,
bytes memory _data
)
external
view
returns (address, uint256, bytes memory)
{
address[] memory path;

if(_data.length == 0){
path = new address[](2);
path[0] = _sourceToken;
path[1] = _destinationToken;
} else {
path = abi.decode(_data, (address[]));
}

bytes memory callData = abi.encodeWithSignature(
"swapExactTokensForTokens(uint256,uint256,address[],address,uint256)",
_sourceQuantity,
_minDestinationQuantity,
path,
_destinationAddress,
block.timestamp
);
return (router, 0, callData);
}

/**
* Returns the address to approve source tokens to for trading. This is the Uniswap router address
*
* @return address Address of the contract to approve tokens to
*/
function getSpender()
external
view
returns (address)
{
return router;
}
}
Loading