Universe Finance Connector

This commit is contained in:
Ibrahim 2021-11-15 18:29:08 +08:00
parent 07f8fd07ad
commit e197ebeb49
4 changed files with 126 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,31 @@
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 {
// TODO The vault is currently under audit and the address needs to be updated
IUniverseAdapter constant universeAdapter = IUniverseAdapter(0x0000000000000000000000000000000000000000);
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 IUniverseVaultV3(universeVault).withdraw(share0, share1);
}
}

View File

@ -0,0 +1,17 @@
pragma solidity ^0.7.6;
pragma abicoder v2;
interface IUniverseAdapter {
function depositProxy(
address universeVault,
uint256 amount0,
uint256 amount1
) external returns(uint256, uint256);
}
interface IUniverseVaultV3 {
function withdraw(uint256 share0, uint256 share1) external returns(uint256, uint256);
}

View File

@ -0,0 +1,58 @@
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 UniverseFinanceResolver 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
) external returns (string memory _eventName, bytes memory _eventParam){
amountA = getUint(getIds[0], amountA);
amountB = getUint(getIds[1], amountB);
(uint256 share0, uint256 share1) = _deposit(universeVault, amountA, amountB);
// 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 setIds
) external returns (string memory _eventName, bytes memory _eventParam){
(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 UniverseFinanceResolver {
string public constant name = "UniverseFinance-v1";
}