From 2c22b803ceffb4a2bf55267f288460ded10c1f14 Mon Sep 17 00:00:00 2001 From: pradeep-selva Date: Fri, 17 Sep 2021 19:36:04 +0530 Subject: [PATCH] docs: IPeriphery.sol created --- contracts/Periphery.sol | 26 ++++++++++++++++---------- contracts/interfaces/IPeriphery.sol | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 contracts/interfaces/IPeriphery.sol diff --git a/contracts/Periphery.sol b/contracts/Periphery.sol index 4cce641..ca7e905 100644 --- a/contracts/Periphery.sol +++ b/contracts/Periphery.sol @@ -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; @@ -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 @@ -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)); @@ -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)); } diff --git a/contracts/interfaces/IPeriphery.sol b/contracts/interfaces/IPeriphery.sol new file mode 100644 index 0000000..e0b80dd --- /dev/null +++ b/contracts/interfaces/IPeriphery.sol @@ -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; +} \ No newline at end of file