Skip to content

Commit

Permalink
Merge pull request #1 from RubiconDeFi/v1.1
Browse files Browse the repository at this point in the history
Rubicon v1.1.0
  • Loading branch information
bghughes authored May 16, 2022
2 parents c2538ac + f257638 commit 7093705
Show file tree
Hide file tree
Showing 19 changed files with 1,429 additions and 1,952 deletions.
Binary file modified contracts/.DS_Store
Binary file not shown.
16 changes: 12 additions & 4 deletions contracts/RubiconMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// This contract is a derivative work of the open-source work of Oasis DEX: https://github.com/OasisDEX/oasis

/// @title RubiconMarket.sol
/// @notice Please see the repository for this code at https://github.com/RubiconDeFi/rubicon_protocol;
/// @notice Please see the repository for this code at https://github.com/RubiconDeFi/rubicon-protocol-v1;

pragma solidity =0.7.6;

Expand Down Expand Up @@ -292,6 +292,7 @@ contract SimpleMarket is EventfulMarket, DSMath {
return false;
}

// Fee logic added on taker trades
uint256 fee = mul(spend, feeBPS) / 10000;
require(
_offer.buy_gem.transferFrom(msg.sender, feeTo, fee),
Expand Down Expand Up @@ -528,7 +529,9 @@ contract RubiconMarket is MatchingEvents, ExpiringMarket, DSNote {
/// @dev Below is variable to allow for a proxy-friendly constructor
bool public initialized;

/// @dev unused deprecated variable for applying a token distribution on top of a trade
bool public AqueductDistributionLive;
/// @dev unused deprecated variable for applying a token distribution of this token on top of a trade
address public AqueductAddress;

struct sortInfo {
Expand All @@ -546,16 +549,18 @@ contract RubiconMarket is MatchingEvents, ExpiringMarket, DSNote {

/// @dev Proxy-safe initialization of storage
function initialize(bool _live, address _feeTo) public {
// require(msg.sender == ___deployer____);
require(!initialized, "contract is already initialized");
AqueductDistributionLive = _live;

/// @notice The market fee recipient
feeTo = _feeTo;

owner = msg.sender;
emit LogSetOwner(msg.sender);

/// @notice The starting fee on taker trades in basis points
feeBPS = 20;

initialized = true;
matchingEnabled = true;
buyEnabled = true;
Expand Down Expand Up @@ -612,8 +617,9 @@ contract RubiconMarket is MatchingEvents, ExpiringMarket, DSNote {
) public override returns (uint256) {
require(!locked, "Reentrancy attempt");

function(uint256, ERC20, uint256, ERC20)
returns (uint256) fn = matchingEnabled ? _offeru : super.offer;

function(uint256, ERC20, uint256, ERC20) returns (uint256) fn
= matchingEnabled ? _offeru : super.offer;
return fn(pay_amt, pay_gem, buy_amt, buy_gem);
}

Expand Down Expand Up @@ -1227,6 +1233,7 @@ contract RubiconMarket is MatchingEvents, ExpiringMarket, DSNote {
return true;
}

/// @dev unused deprecated function for applying a token distribution on top of a trade
function setAqueductDistributionLive(bool live)
external
auth
Expand All @@ -1236,6 +1243,7 @@ contract RubiconMarket is MatchingEvents, ExpiringMarket, DSNote {
return true;
}

/// @dev unused deprecated variable for applying a token distribution on top of a trade
function setAqueductAddress(address _Aqueduct)
external
auth
Expand Down
36 changes: 20 additions & 16 deletions contracts/RubiconRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ pragma abicoder v2;
import "./RubiconMarket.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./libraries/ABDKMath64x64.sol";
import "./peripheral_contracts/WETH9.sol"; // @unsupported: ovm
import "./rubiconPools/BathToken.sol";
import "./libraries/TransferHelper.sol";
import "./interfaces/IBathToken.sol";

///@dev this contract is a high-level router that utilizes Rubicon smart contracts to provide
///@dev added convenience and functionality when interacting with the Rubicon protocol
Expand Down Expand Up @@ -106,9 +104,9 @@ contract RubiconRouter {
continue;
}
uint256 nextBestAsk = RubiconMarket(_RubiconMarketAddress)
.getWorseOffer(lastAsk);
.getWorseOffer(lastAsk);
uint256 nextBestBid = RubiconMarket(_RubiconMarketAddress)
.getWorseOffer(lastBid);
.getWorseOffer(lastBid);
(uint256 ask_pay_amt, , uint256 ask_buy_amt, ) = RubiconMarket(
_RubiconMarketAddress
).getOffer(nextBestAsk);
Expand Down Expand Up @@ -330,6 +328,8 @@ contract RubiconRouter {
uint256 max_fill_amount,
uint256 expectedMarketFeeBPS
) external payable returns (uint256 fill) {
address _weth = address(wethAddress);
uint256 _before = ERC20(_weth).balanceOf(address(this));
uint256 max_fill_withFee = max_fill_amount.add(
max_fill_amount.mul(expectedMarketFeeBPS).div(10000)
);
Expand All @@ -345,13 +345,16 @@ contract RubiconRouter {
ERC20(wethAddress),
max_fill_amount
);
if (max_fill_amount > fill) {
emit LogNote("returned fill", fill);
ERC20(buy_gem).transfer(msg.sender, buy_amt);

uint256 _after = ERC20(_weth).balanceOf(address(this));
uint256 delta = _after - _before;

// ERC20(pay_gem).transfer(msg.sender, max_fill_amount - fill);
// Return unspent coins to sender
if (delta > 0) {
WETH9(wethAddress).withdraw(delta);
msg.sender.transfer(delta);
}
ERC20(buy_gem).transfer(msg.sender, buy_amt);
return fill;
}

// Paying ERC20 to buy native ETH
Expand Down Expand Up @@ -454,7 +457,7 @@ contract RubiconRouter {
payable
returns (uint256 newShares)
{
IERC20 target = BathToken(targetPool).underlyingToken();
IERC20 target = IBathToken(targetPool).underlyingToken();
require(target == ERC20(wethAddress), "target pool not weth pool");
require(msg.value >= amount, "didnt send enough eth");

Expand All @@ -463,7 +466,7 @@ contract RubiconRouter {
}

WETH9(wethAddress).deposit{value: amount}();
newShares = BathToken(targetPool).deposit(amount);
newShares = IBathToken(targetPool).deposit(amount);
//Send back bathTokens to sender
ERC20(targetPool).transfer(msg.sender, newShares);
}
Expand All @@ -474,15 +477,16 @@ contract RubiconRouter {
payable
returns (uint256 withdrawnWETH)
{
IERC20 target = BathToken(targetPool).underlyingToken();
IERC20 target = IBathToken(targetPool).underlyingToken();
require(target == ERC20(wethAddress), "target pool not weth pool");
require(
BathToken(targetPool).balanceOf(msg.sender) >= shares,
IBathToken(targetPool).balanceOf(msg.sender) >= shares,
"don't own enough shares"
);
BathToken(targetPool).transferFrom(msg.sender, address(this), shares);
withdrawnWETH = BathToken(targetPool).withdraw(shares);
IBathToken(targetPool).transferFrom(msg.sender, address(this), shares);
withdrawnWETH = IBathToken(targetPool).withdraw(shares);
WETH9(wethAddress).withdraw(withdrawnWETH);

//Send back withdrawn native eth to sender
msg.sender.transfer(withdrawnWETH);
}
Expand Down
5 changes: 3 additions & 2 deletions contracts/interfaces/IBathHouse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ interface IBathHouse {

function initialized() external returns (bool);

function reserveRatio() external view returns (uint);
function reserveRatio() external view returns (uint256);

function tokenToBathToken(address erc20Address)
external view
external
view
returns (address bathTokenAddress);

function isApprovedStrategist(address wouldBeStrategist)
Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/IBathToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ interface IBathToken is IERC20 {

function setMarket(address newRubiconMarket) external;

function setBonusToken(address newBonusToken) external;

function setFeeBPS(uint256 _feeBPS) external;

function setFeeTo(address _feeTo) external;
Expand All @@ -53,6 +55,10 @@ interface IBathToken is IERC20 {

function deposit(uint256 amount) external returns (uint256 shares);

function deposit(uint256 assets, address receiver)
external
returns (uint256 shares);

function withdraw(uint256 shares) external returns (uint256 amount);

function DOMAIN_SEPARATOR() external view returns (bytes32);
Expand Down
14 changes: 14 additions & 0 deletions contracts/interfaces/IVestingWallet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.6;

interface IVestingWallet {
function beneficiary() external view returns (address);

function release(address token) external;

function vestedAmount(address token, uint64 timestamp)
external
view
returns (uint256);
}
Loading

0 comments on commit 7093705

Please sign in to comment.