Merge pull request #107 from UniverseFinance/universe-connector

Universe Finance Connector
This commit is contained in:
Samyak Jain 2021-12-04 00:55:56 +05:30 committed by GitHub
commit af48702e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,20 @@
pragma solidity ^0.7.0;
contract Events {
event LogDeposit(
address indexed universeVault,
uint256 amountA,
uint256 amountB,
uint256 share0,
uint256 share1
);
event LogWithdraw(
address indexed universeVault,
uint256 amountA,
uint256 amountB,
uint256 share0,
uint256 share1
);
}

View File

@ -0,0 +1,43 @@
pragma solidity ^0.7.6;
import {TokenInterface} from "../../common/interfaces.sol";
import {DSMath} from "../../common/math.sol";
import {Basic} from "../../common/basic.sol";
import "./interface.sol";
abstract contract Helpers is DSMath, Basic {
IUniverseAdapter constant universeAdapter = IUniverseAdapter(0x876861Ad49f911442720cF97c9b3fCe4070F07d5);
function _deposit(
address universeVault,
uint256 amount0,
uint256 amount1
) internal returns(uint256, uint256){
return universeAdapter.depositProxy(universeVault, amount0, amount1);
}
function _withdraw(
address universeVault,
uint256 share0,
uint256 share1
) internal returns(uint256, uint256){
require(share0 > 0 || share1 > 0, "ZERO");
return IVaultV3(universeVault).withdraw(share0, share1);
}
function _approve(address universeVault, uint256 amount0, uint256 amount1) internal {
IVaultV3 universe = IVaultV3(universeVault);
TokenInterface token;
if (amount0 > 0) {
token = universe.token0();
token.approve(address(universeAdapter), amount0);
}
if (amount1 > 0) {
token = universe.token1();
token.approve(address(universeAdapter), amount1);
}
}
}

View File

@ -0,0 +1,24 @@
pragma solidity ^0.7.6;
import "../../common/interfaces.sol";
pragma abicoder v2;
interface IUniverseAdapter {
function depositProxy(
address universeVault,
uint256 amount0,
uint256 amount1
) external returns(uint256, uint256);
}
interface IVaultV3 {
function token0() external returns(TokenInterface);
function token1() external returns(TokenInterface);
function withdraw(uint256 share0, uint256 share1) external returns(uint256, uint256);
}

View File

@ -0,0 +1,63 @@
pragma solidity ^0.7.6;
pragma abicoder v2;
import {TokenInterface} from "../../common/interfaces.sol";
import {Helpers} from "./helpers.sol";
import {Events} from "./events.sol";
abstract contract UniverseFinanceConnect is Helpers, Events {
/**
* @notice Deposit in Universe Vault by Adapter
* @param universeVault Universe Official Vault Address
* @param amountA Amount of tokenA
* @param amountB Amount of tokenB
* @param getIds ID to retrieve amountA and amountB
*/
function deposit(
address universeVault,
uint256 amountA,
uint256 amountB,
uint256[] calldata getIds,
uint256[] calldata setIds
) external returns (string memory _eventName, bytes memory _eventParam){
amountA = getUint(getIds[0], amountA);
amountB = getUint(getIds[1], amountB);
_approve(universeVault, amountA, amountB);
(uint256 share0, uint256 share1) = _deposit(universeVault, amountA, amountB);
setUint(setIds[0], share0);
setUint(setIds[1], share1);
// EVENT
_eventName = "LogDeposit(address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(universeVault, amountA, amountB, share0, share1);
}
/**
* @notice Withdraw Token0 & Token1 From Universe Vault
* @param universeVault Universe Official Vault Address
* @param share0 Amount of uToken0.
* @param share1 Amount of uToken1.
* @param setIds stores the amount of output tokens
*/
function withdraw(
address universeVault,
uint256 share0,
uint256 share1,
uint256[] calldata getIds,
uint256[] calldata setIds
) external returns (string memory _eventName, bytes memory _eventParam){
share0 = getUint(getIds[0], share0);
share1 = getUint(getIds[1], share1);
(uint256 _amtA, uint256 _amtB) = _withdraw(universeVault, share0, share1);
setUint(setIds[0], _amtA);
setUint(setIds[1], _amtB);
// EVENT
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(universeVault, _amtA, _amtB, share0, share1);
}
}
contract ConnectV2UniverseFinance is UniverseFinanceConnect {
string public constant name = "UniverseFinance-v1";
}