Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "configurable-rights-pool"]
path = configurable-rights-pool
url = git@github.com:defidollar/configurable-rights-pool.git
branch = develop
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
# DefiDollar
DefiDollar (DUSD) is a stablecoin backed by [Curve Finance](https://www.curve.fi/) LP tokens.

See [blog post](https://medium.com/@atvanguard/a-curvy-defidollar-c249438c154a).
DefiDollar ($DUSD) DefiDollar $DUSD is a stablecoin that uses DeFi primitives to stay near the $1 mark.

---
### Development

1. Run Ganache

```
npm run compile
npm run ganache
```

2. Setup Balancer Deps
```
npm run setup:balancer
```

3. Compile and Migrate
```
npm run compile
npm run migrate
```

4. Run Tests
```
npm t
```
1 change: 1 addition & 0 deletions configurable-rights-pool
18 changes: 18 additions & 0 deletions contracts/common/mocks/MockAToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity 0.5.17;

import "./Reserve.sol";

contract MockAToken is Reserve {
constructor (string memory _name, string memory _symbol)
public
Reserve(_name, _symbol, 18)
{
}

function mint(address account, uint256 amount) public returns (bool) {
_mint(account, amount);
return true;
}

function redirectInterestStream(address) external {}
}
28 changes: 28 additions & 0 deletions contracts/interfaces/IAave.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pragma solidity 0.5.17;

interface aToken {
function redeem(uint256 _amount) external;
function transfer(address recipient, uint256 amount) external;
function transferFrom(address from, address to, uint256 amount) external;
function redirectInterestStream(address _to) external;
function redirectInterestStreamOf(address _from, address _to) external;
function allowInterestRedirectionTo(address _to) external;
}

interface LendingPool {
function deposit(address _reserve, uint256 _amount, uint16 _referralCode) external;
function getReserveData(address _reserve) external;
}

interface LendingPoolAddressesProvider {
function getLendingPool() external view returns (address);
function getLendingPoolCore() external view returns (address payable);
function getPriceOracle() external view returns (address);
}

interface PriceOracleGetter {
function getAssetPrice(address _asset) external view returns (uint256);
function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory);
function getSourceOfAsset(address _asset) external view returns(address);
function getFallbackOracle() external view returns(address);
}
84 changes: 84 additions & 0 deletions contracts/interfaces/IConfigurableRightsPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
pragma solidity 0.5.17;

interface IConfigurableRightsPool {
function joinPool(uint poolAmountout, uint[] calldata maxAmountsIn) external;
function exitPool(uint poolAmountIn, uint[] calldata minAmountsOut) external;
function getDenormalizedWeight(address token) external view returns (uint);
function getNormalizedWeight(address token) external view returns (uint);
}

interface IBPool {
function isBound(address token) external view returns(bool);
function getBalance(address token) external view returns (uint);
function rebind(address token, uint balance, uint denorm) external;
function setSwapFee(uint swapFee) external;
function bind(address token, uint balance, uint denorm) external;
function getDenormalizedWeight(address token) external view returns (uint);
function getNormalizedWeight(address token) external view returns (uint);
function getTotalDenormalizedWeight() external view returns (uint);
function setPublicSwap(bool public_) external;
function getCurrentTokens() external view returns (address[] memory tokens);
function calcPoolOutGivenSingleIn(
uint tokenBalanceIn,
uint tokenWeightIn,
uint poolSupply,
uint totalWeight,
uint tokenAmountIn,
uint swapFee
)
external pure
returns (uint poolAmountOut);

function calcSingleInGivenPoolOut(
uint tokenBalanceIn,
uint tokenWeightIn,
uint poolSupply,
uint totalWeight,
uint poolAmountOut,
uint swapFee
)
external pure
returns (uint tokenAmountIn);

function calcSingleOutGivenPoolIn(
uint tokenBalanceOut,
uint tokenWeightOut,
uint poolSupply,
uint totalWeight,
uint poolAmountIn,
uint swapFee
)
external pure
returns (uint tokenAmountOut);

function calcPoolInGivenSingleOut(
uint tokenBalanceOut,
uint tokenWeightOut,
uint poolSupply,
uint totalWeight,
uint tokenAmountOut,
uint swapFee
)
external pure
returns (uint poolAmountIn);

function swapExactAmountOut(
address tokenIn,
uint maxAmountIn,
address tokenOut,
uint tokenAmountOut,
uint maxPrice
)
external
returns (uint tokenAmountIn, uint spotPriceAfter);

function swapExactAmountIn(
address tokenIn,
uint tokenAmountIn,
address tokenOut,
uint minAmountOut,
uint maxPrice
)
external
returns (uint tokenAmountOut, uint spotPriceAfter);
}
1 change: 1 addition & 0 deletions contracts/interfaces/ICurve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface ICurve {
function balances(int128 i) external view returns(uint);
function get_virtual_price() external view returns(uint);
function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy) external;
function exchange_underlying(int128 i, int128 j, uint256 dx, uint256 min_dy) external;
// for tests
function mock_add_to_balance(uint[4] calldata amounts) external;
}
Expand Down
22 changes: 22 additions & 0 deletions contracts/peaks/dai-susd/Mocks/MockLendingPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pragma solidity 0.5.17;

import { LendingPool, aToken } from "../../../interfaces/IAave.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { MockAToken } from "../../../common/mocks/MockAToken.sol";
import { SafeERC20, SafeMath } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";

contract MockLendingPool is LendingPool {
using SafeERC20 for IERC20;
using SafeMath for uint;

mapping(address => address) public lendingPools;

// Deposit reserve => aToken
function deposit(address _reserve, uint256 _amount, uint16 /*_refferalCode*/) public {
// Transfer reserve
IERC20(_reserve).safeTransferFrom(msg.sender, address(this), _amount);
// Mint aToken
// MockAToken().mint(msg.sender, _amount);
}

}
33 changes: 33 additions & 0 deletions contracts/peaks/dai-susd/Mocks/MockPriceOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pragma solidity 0.5.17;

import { PriceOracleGetter } from "../../../interfaces/IAave.sol";

contract MockPriceOracle is PriceOracleGetter {

/**
Mock contract of Aave price oracle for reserve assets.

- Simulates Chainlink aggregator used by Aave
- Returns price of reserve asset in wei units
- DAI & sUSD = 0.0022.mul(1e18)
*/

mapping(address => uint256) public reservePrices;

function getAssetPrice(address _asset) public view returns (uint256) {
return reservePrices[_asset];
}

function getAssetPrices(address[] memory _assets) public view returns (uint256[] memory) {
uint256[] memory prices;
for (uint i = 0; i < _assets.length; i++) {
prices[i] = getAssetPrice(_assets[i]);
}
return prices;
}

function setAssetPrice(address _asset, uint256 _price) public {
reservePrices[_asset] = _price;
}

}
Loading