Skip to content

Commit

Permalink
docs: IPeriphery.sol created
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradeep-selva committed Sep 17, 2021
1 parent 5dbe204 commit 2c22b80
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
26 changes: 16 additions & 10 deletions contracts/Periphery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import '@uniswap/v3-periphery/contracts/interfaces/IQuoter.sol';
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
import "@uniswap/v3-periphery/contracts/interfaces/IQuoter.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";

import './interfaces/IVault.sol';
import "./interfaces/IPeriphery.sol";
import "./interfaces/IVault.sol";
import "./interfaces/IERC20Metadata.sol";
import "./libraries/LongMath.sol";

contract Periphery {
/// @title Periphery
contract Periphery is IPeriphery {
using SafeMath for uint256;
using LongMath for uint256;
using SafeERC20 for IERC20Metadata;
Expand All @@ -34,9 +36,8 @@ contract Periphery {
token1 = vault.token1();
}

/// @notice Calls IVault's deposit method and sends all money back to user after transactions
/// @param amountIn Value of token0 to be deposited
function vaultDeposit(uint256 amountIn) external minimumAmount(amountIn) {
/// @inheritdoc IPeriphery
function vaultDeposit(uint256 amountIn) external override minimumAmount(amountIn) {
// Calculate amount to swap based on tokens in vault
// token0 / token1 = k
// token0 + token1 = amountIn
Expand Down Expand Up @@ -86,7 +87,8 @@ contract Periphery {
token1.safeTransfer(msg.sender, _tokenBalance(token1));
}

function vaultWithdraw(uint256 shares) external minimumAmount(shares) {
/// @inheritdoc IPeriphery
function vaultWithdraw(uint256 shares) external override minimumAmount(shares) {
// transfer shares from msg.sender & withdraw
vault.safeTransferFrom(msg.sender, address(this), shares);
(uint256 amount0, uint256 amount1) = vault.withdraw(shares, 0, 0, address(this));
Expand Down Expand Up @@ -118,6 +120,10 @@ contract Periphery {
token1.safeTransfer(msg.sender, _tokenBalance(token1));
}

/**
* @notice Get the balance of a token in contract
* @param token token whose balance needs to be returned
*/
function _tokenBalance(IERC20Metadata token) internal view returns (uint256) {
return token.balanceOf(address(this));
}
Expand Down
26 changes: 26 additions & 0 deletions contracts/interfaces/IPeriphery.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.7.5;
pragma abicoder v2;

import "./IERC20Metadata.sol";

/**
* @title IPeriphery
* @notice A middle layer between user and Aastra Vault to process transactions
* @dev Provides an interface for Periphery
*/
interface IPeriphery {
/**
* @notice Calls IVault's deposit method and sends all money back to
* user after transactions
* @param amountIn Value of token0 to be deposited
*/
function vaultDeposit(uint256 amountIn) external;

/**
* @notice Calls vault's withdraw function in exchange for shares
* and transfers processed token0 value to msg.sender
* @param shares Value of shares in exhange for which tokens are withdrawn
*/
function vaultWithdraw(uint256 shares) external;
}

0 comments on commit 2c22b80

Please sign in to comment.