Skip to content

Commit

Permalink
0.1.0 contract for ethberlin
Browse files Browse the repository at this point in the history
- deployed to rinkeby and kovan
- improved deploy-rdai truffle script
- added mint truffle script
  • Loading branch information
hellwolf committed Aug 24, 2019
1 parent 2339ee8 commit 94c9f23
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 51 deletions.
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2019 DECENTRAL.EE OÜ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions Makefile
@@ -0,0 +1,9 @@
NETWORK=rinkeby

build:
npx truffle build

deploy-rdai: build
npx truffle exec --network $(NETWORK) scripts/deploy-rdai.js

.PHONY: build deploy-rdai
12 changes: 10 additions & 2 deletions README.md
Expand Up @@ -215,10 +215,18 @@ TODO...
# Deployed Contracts

## Rinkeby
rDAI (latest): `0x46b7cc7dd18eC78d639f329f3Df0d8AE094cA8b6`

DAI: 0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa
cDAI: 0x6d7f0754ffeb405d23c51ce938289d4835be3b14
DaiCompoundAllocationStrategy (latest): [0x152b48c07322d56EcdeAdDF780a2c09b57b11F07](https://rinkeby.etherscan.io/address/0x152b48c07322d56EcdeAdDF780a2c09b57b11F07)
rDAI (latest): [0x4f3E18CEAbe50E64B37142c9655b3baB44eFF578](https://rinkeby.etherscan.io/address/0x4f3E18CEAbe50E64B37142c9655b3baB44eFF578)

## Kovan
rDAI (latest): `0x82679b504e783270A861711f72d5809feA6fC607`

DAI: 0xbF7A7169562078c96f0eC1A8aFD6aE50f12e5A99
cDAI: 0x0a1e4d0b5c71b955c0a5993023fc48ba6e380496
DaiCompoundAllocationStrategy (latest): [0xb4377efc05bd28be8e6510629538e54eba2d74e3](https://kovan.etherscan.io/address/0xb4377efc05bd28be8e6510629538e54eba2d74e3)
rDAI (latest): [0xea718e4602125407fafcb721b7d760ad9652dfe7](https://kovan.etherscan.io/address/0xea718e4602125407fafcb721b7d760ad9652dfe7)

## Mainnet

Expand Down
4 changes: 2 additions & 2 deletions contracts/CompoundAllocationStrategy.sol
Expand Up @@ -7,8 +7,8 @@ import {CErc20Interface} from "../compound/contracts/CErc20Interface.sol";

contract CompoundAllocationStrategy is IAllocationStrategy, Ownable {

CErc20Interface cToken;
IERC20 token;
CErc20Interface private cToken;
IERC20 private token;

constructor(CErc20Interface cToken_) public {
cToken = cToken_;
Expand Down
22 changes: 11 additions & 11 deletions contracts/RToken.sol
Expand Up @@ -121,14 +121,14 @@ contract RToken is IRToken, Ownable, ReentrancyGuard {
}

/// @dev IRToken.transferAll implementation
function transferAll(address dst) external returns (bool) {
function transferAll(address dst) external nonReentrant returns (bool) {
address src = msg.sender;
payInterestInternal(src);
return transferInternal(src, src, dst, accounts[src].rAmount);
}

/// @dev IRToken.transferAllFrom implementation
function transferAllFrom(address src, address dst) external returns (bool) {
function transferAllFrom(address src, address dst) external nonReentrant returns (bool) {
payInterestInternal(src);
payInterestInternal(dst);
return transferInternal(msg.sender, src, dst, accounts[src].rAmount);
Expand Down Expand Up @@ -199,15 +199,15 @@ contract RToken is IRToken, Ownable, ReentrancyGuard {
}

/// @dev IRToken.redeemAndTransfer implementation
function redeemAndTransfer(address redeemTo, uint256 redeemTokens) external returns (bool) {
function redeemAndTransfer(address redeemTo, uint256 redeemTokens) external nonReentrant returns (bool) {
address src = msg.sender;
payInterestInternal(src);
redeemInternal(redeemTo, redeemTokens);
return true;
}

/// @dev IRToken.redeemAndTransferAll implementation
function redeemAndTransferAll(address redeemTo) external returns (bool) {
function redeemAndTransferAll(address redeemTo) external nonReentrant returns (bool) {
address src = msg.sender;
payInterestInternal(src);
redeemInternal(redeemTo, accounts[src].rAmount);
Expand Down Expand Up @@ -351,27 +351,27 @@ contract RToken is IRToken, Ownable, ReentrancyGuard {
//

/// @dev Current saving strategy
IAllocationStrategy ias;
IAllocationStrategy private ias;

/// @dev Underlying token
IERC20 token;
IERC20 private token;

/// @dev Saving assets original amount
uint256 savingAssetOrignalAmount;
uint256 private savingAssetOrignalAmount;

/// @dev Saving asset original to internal amount conversion rate.
/// - It has 18 decimals
/// - It starts with value 1.
/// - Each strategy switching results a new conversion rate
uint256 savingAssetConversionRate = 10 ** 18;
uint256 private savingAssetConversionRate = 10 ** 18;

/// @dev Saving assets exchange rate with

/// @dev Approved token transfer amounts on behalf of others
mapping(address => mapping(address => uint256)) transferAllowances;
mapping(address => mapping(address => uint256)) private transferAllowances;

/// @dev Hat list
Hat[] hats;
Hat[] private hats;

/// @dev Account structure
struct Account {
Expand All @@ -396,7 +396,7 @@ contract RToken is IRToken, Ownable, ReentrancyGuard {
}

/// @dev Account mapping
mapping (address => Account) accounts;
mapping (address => Account) private accounts;

/**
* @dev Transfer `tokens` tokens from `src` to `dst` by `spender`
Expand Down
51 changes: 20 additions & 31 deletions scripts/deploy-rdai.js
@@ -1,42 +1,31 @@
module.exports = async (callback) => {
module.exports = async function (callback) {
try {
global.web3 = web3;

let network = await web3.eth.net.getNetworkType();
console.log("Current network:", network);

const { web3tx } = require("@decentral.ee/web3-test-helpers");
const CompoundAllocationStrategy = artifacts.require("CompoundAllocationStrategy");
const RToken = artifacts.require("RToken");

let network = await web3.eth.net.getNetworkType();

console.log("Current network:", network);

let cDAIAddress;
// Contract addresses: https://compound.finance/developers#enter-markets
if (network === "rinkeby") {
cDAIAddress = "0x6d7f0754ffeb405d23c51ce938289d4835be3b14";
} else if (network === "kovan") {
cDAIAddress = "0x0a1e4d0b5c71b955c0a5993023fc48ba6e380496";
} else if (network === "main") {
cDAIAddress = "0xf5dce57282a584d2746faf1593d3121fcac444dc";
}
const cDAI = await require("./get-cdai")(artifacts, network);

if (cDAIAddress) {
const compoundAS = await web3tx(CompoundAllocationStrategy.new, `CompoundAllocationStrategy.new cDAI ${cDAIAddress}`)(
cDAIAddress, {
gas: 1000000,
}
);
//const compoundAS = { address: "0xF07d4967ae1F600144b25f40f655f61De2A9c0Ad" };
const rToken = await web3tx(RToken.new, `RToken.new allocationStrategy ${compoundAS.address}`)(
compoundAS.address,
{
gas: 5000000,
}
);
console.log("rDai deployed at: ", rToken.address);
console.log("transfer ownership of compoundAS to new rDai", rToken.address);
await web3tx(compoundAS.transferOwnership, "compoundAS.transferOwnership")(rToken.address);
}
const compoundAS = await web3tx(CompoundAllocationStrategy.new, `CompoundAllocationStrategy.new cDAI ${cDAI.address}`)(
cDAI.address, {
gas: 1000000,
}
);
//const compoundAS = { address: "0xF07d4967ae1F600144b25f40f655f61De2A9c0Ad" };
const rToken = await web3tx(RToken.new, `RToken.new allocationStrategy ${compoundAS.address}`)(
compoundAS.address,
{
gas: 5000000,
}
);
console.log("rDai deployed at: ", rToken.address);
console.log("transfer ownership of compoundAS to new rDai", rToken.address);
await web3tx(compoundAS.transferOwnership, "compoundAS.transferOwnership")(rToken.address);
callback();
} catch (err) {
callback(err);
Expand Down
16 changes: 16 additions & 0 deletions scripts/get-cdai.js
@@ -0,0 +1,16 @@
module.exports = async function (artifacts, network) {
const IERC20 = artifacts.require("IERC20");

let cDAIAddress = "0x";

// Contract addresses: https://compound.finance/developers#enter-markets
if (network === "rinkeby") {
cDAIAddress = "0x6d7f0754ffeb405d23c51ce938289d4835be3b14";
} else if (network === "kovan") {
cDAIAddress = "0x0a1e4d0b5c71b955c0a5993023fc48ba6e380496";
} else if (network === "main") {
cDAIAddress = "0xf5dce57282a584d2746faf1593d3121fcac444dc";
}

return IERC20.at(cDAIAddress);
};
31 changes: 31 additions & 0 deletions scripts/mint.js
@@ -0,0 +1,31 @@
module.exports = async function (callback) {
try {
global.web3 = web3;

const { web3tx, toWad } = require("@decentral.ee/web3-test-helpers");

let network = await web3.eth.net.getNetworkType();
console.log("Current network:", network);

const IERC20 = artifacts.require("IERC20");
const RToken = artifacts.require("RToken");
const IAllocationStrategy = artifacts.require("IAllocationStrategy");

const rToken = await RToken.at(process.argv[6]);
const mintAmount = process.argv[7] || 10;
console.log("rToken address", rToken.address);
const minter = (await web3.eth.getAccounts())[0];
console.log("minter address", minter);
console.log("mint amount", mintAmount);
const underlying = await IERC20.at(
await (await IAllocationStrategy.at(
await rToken.getCurrentSavingStrategy.call()
)).underlying.call());
await web3tx(underlying.approve, "underlying.approve")(rToken.address, toWad(mintAmount));
await web3tx(rToken.mint, "rToken.mint")(toWad(mintAmount));

callback();
} catch (err) {
callback(err);
}
};
10 changes: 5 additions & 5 deletions truffle.js
Expand Up @@ -58,7 +58,7 @@ module.exports = {
process.env.RINKEBY_PROVIDER_URL,
0, //address_index
10, // num_addresses
false // shareNonce
true // shareNonce
),
network_id: 4, // Rinkeby's id
//gas: 7017622, //
Expand All @@ -73,7 +73,7 @@ module.exports = {
process.env.KOVAN_PROVIDER_URL,
0, //address_index
10, // num_addresses
false // shareNonce
true // shareNonce
),
network_id: 42, // Kovan's id
//gas: 7017622, //
Expand All @@ -88,7 +88,7 @@ module.exports = {
process.env.MAINNET_PROVIDER_URL,
0, //address_index
10, // num_addresses
false // shareNonce
true // shareNonce
),
network_id: 1, // mainnet's id
//gas: 7017622, //
Expand Down Expand Up @@ -135,14 +135,14 @@ module.exports = {
// Configure your compilers
compilers: {
solc: {
// version: "0.5.1", // Fetch exact version from solc-bin (default: truffle's version)
version: "0.5.11", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
settings: { // See the solidity docs for advice about optimization and evmVersion
optimizer: {
enabled: true,
runs: 200
},
evmVersion: "byzantium"
// evmVersion: "petersburg" use default
}
}
}
Expand Down

0 comments on commit 94c9f23

Please sign in to comment.