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
82 changes: 82 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var fs = require("fs");
const bre = require("@nomiclabs/buidler");

async function copyUSDxArtifacts() {
const USDxArtifacts = [
"Utils",
"ReentrancyGuard",
"DSValue",
"DSThing",
"DSNote",
"DSMath",
"DSGuardEvents",
"DSGuard",
"DSAuthority",
"DSAuthEvents",
"DSAuth",
"UpgradeabilityProxy",
"Proxy",
"DFProxy",
"AdminUpgradeabilityProxy",
"AddressUtils",
"DFUpgrader",
"IERC20Token",
"IERC20",
"IDSWrappedToken",
"IDSToken",
"ERC20SafeTransfer",
"DSWrappedToken",
"ERC20Events",
"ERC20",
"DSTokenBase",
"DSToken",
"DSStop",
"SafeMath",
"Collaterals_t",
"IDTokenController",
"IDToken",
"IDFStore",
"IDFPoolV2",
"IDFPool",
"IDFFunds",
"IDFCollateral",
"DFStore",
"DFPoolV2",
"DFPoolV1",
"DFPool",
"DFFunds",
"DFCollateral",
"iMedianizer",
"UniswapV2Library",
"Oracle",
"PriceFeed",
"Medianizer",
"DTokenController",
"DToken",
"Migrations",
"IDFProtocol",
"IDFEngine",
"DFSetting",
"DFProtocolView",
"DFProtocol",
"DFEngineV2",
"DFEngine",
];

USDxArtifacts.forEach((file) => {
fs.copyFileSync(
"./artifacts/" + file + ".json",
"./build/" + file + ".json"
);
});
}

module.exports = {
onCompileComplete: copyUSDxArtifacts,
skipFiles: ["library", "interface", "mock", "Migrations.sol", "USRProxy.sol"],

mocha: {
grep: "(Skipped in coverage)", // We have some cases need to be skipped
invert: true, // Run the grep's inverse set.
},
};
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ in an existing USR repo.

## Usage

### Build

Install buidler and plugins

```
Expand All @@ -37,12 +39,34 @@ Compile the USDx contracts for integration test:
npx buidler compile --config buidler.config.usdx.js
```

Run a local develop network with buidler EVM:

```
npx buidler node
```

Run a local node and a console:

```
npx buidler console
```

### Test

To run the tests:

```
npx buidler test
```

To run test coverage:

```
npx buidler coverage --temp build
```

### Deploy

To deploy contracts, need to set basic config parameters in `.env`:

```
Expand All @@ -61,9 +85,3 @@ Deploy contracts at the testnet: Kovan.
```
truffle migrate --network kovan
```

Run a local develop network with buidler EVM:

```
npx buidler node
```
1 change: 1 addition & 0 deletions buidler.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
usePlugin("@nomiclabs/buidler-waffle");
usePlugin("@nomiclabs/buidler-truffle5");
usePlugin("buidler-gas-reporter");
usePlugin("solidity-coverage");

// This is a sample Buidler task. To learn how to create your own go to
// https://buidler.dev/guides/create-task.html
Expand Down
7 changes: 4 additions & 3 deletions contracts/USR.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ contract ERC20Exchangeable is
contract USR is Initializable, DSAuth, ERC20Exchangeable {
using SafeERC20 for IERC20;

IInterestProvider interestProvider;
IInterestProvider public interestProvider;

event NewInterestProvider(
address oldInterestProvider,
Expand Down Expand Up @@ -201,8 +201,9 @@ contract USR is Initializable, DSAuth, ERC20Exchangeable {
address _oldInterestProvider = address(interestProvider);

require(
_interestProvider != _oldInterestProvider,
"updateInterestProvider: same profit provider address."
_interestProvider != address(0) &&
_interestProvider != _oldInterestProvider,
"updateInterestProvider: interest provider can be not set to 0 or the current one."
);

interestProvider = IInterestProvider(_interestProvider);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"scripts": {
"test": "npx buidler test",
"coverage": "npx buidler coverage --temp build",
"format": "prettier --write contracts test"
},
"author": "",
Expand All @@ -22,6 +23,7 @@
"ethers": "^5.0.8",
"prettier": "^2.0.5",
"prettier-plugin-solidity": "^1.0.0-alpha.56",
"solidity-coverage": "^0.7.10",
"truffle-hdwallet-provider": "^1.0.17",
"web3": "^1.2.11"
},
Expand Down
149 changes: 149 additions & 0 deletions test/helpers/fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
const {createFixtureLoader} = require("ethereum-waffle");
const USDxV2deploy = require("../../USDx_1.0/test/helpers/USDxV2deploy.js");

const loadFixture = createFixtureLoader([], ethers.provider);

// USDx Contracts use web3 and truffle
async function deployUSDxContracts() {
accounts = await web3.eth.getAccounts();
let collaterals = new Array("PAX", "TUSD", "USDC");
var weights = new Array(1, 1, 8);
return await USDxV2deploy.contractsDeploy(accounts, collaterals, weights);
}

async function initialize(usr, usdx, protocol, interestProvider) {
const accounts = await web3.eth.getAccounts();

// There are many initialize due to inheritance, use the full typed signature
//console.log(usr.functions);
await usr.functions["initialize(address,address)"](
usdx.address,
interestProvider.address
);

// Mint some USDx
const amount = ethers.utils.parseEther("10000");
for (const account of accounts) {
// USDx contracts are truffle contracts
await protocol.oneClickMinting(0, amount, {from: account});
await usdx.approve(usr.address, ethers.constants.MaxUint256, {
from: account,
});
}
}

async function fixtureInterestProvider([wallet, other], provider) {
const [owner, ...accounts] = await ethers.getSigners();

const usdxContracts = await deployUSDxContracts();

const Funds = await ethers.getContractFactory("Funds");
const funds = await Funds.deploy();
await funds.deployed();

const InterestProvider = await ethers.getContractFactory("InterestProvider");
const interestProvider = await InterestProvider.deploy(
usdxContracts.usdxToken.address,
usdxContracts.store.address,
usdxContracts.poolV2.address,
funds.address
);
await interestProvider.deployed();

await funds.setAuthority(usdxContracts.guard.address);
await usdxContracts.guard.permitx(
interestProvider.address,
usdxContracts.poolV2.address
);
await usdxContracts.guard.permitx(interestProvider.address, funds.address);

return {usdxContracts, funds, interestProvider, owner, accounts};
}

async function fixtureUSRWithMockInterestProvider([wallet, other], provider) {
const [owner, ...accounts] = await ethers.getSigners();

const USDx = await ethers.getContractFactory("USDx");
const usdx = await USDx.deploy();
await usdx.deployed();

// console.log("USDx address:", usdx.address);

const MockInterestProvider = await ethers.getContractFactory(
"MockInterestProvider"
);

// let accounts[0] to act as funds
const [funds, ...others] = accounts;
// console.log("funds address:", funds._address);

const interestProvider = await MockInterestProvider.deploy(
usdx.address,
funds._address
);
await interestProvider.deployed();

// console.log("interestProvider address:", interestProvider.address);

await usdx
.connect(funds)
.approve(interestProvider.address, ethers.constants.MaxUint256);

const USR = await ethers.getContractFactory("USR");
const usr = await USR.deploy();
await usr.deployed();

await usr.functions["initialize(address,address)"](
usdx.address,
interestProvider.address
);

// Transfer some USDx
const amount = ethers.utils.parseEther("10000");

for (const account of others) {
await usdx.transfer(account._address, amount);
await usdx
.connect(account)
.approve(usr.address, ethers.constants.MaxUint256);
}

return {usdx, usr, interestProvider, funds};
}

async function fixtureUSRWithInterestProvider([wallet, other], provider) {
const [owner, ...accounts] = await ethers.getSigners();

const {usdxContracts, funds, interestProvider} = await loadFixture(
fixtureInterestProvider
);

const USR = await ethers.getContractFactory("USR");
const usr = await USR.deploy();
await usr.deployed();

await initialize(
usr,
usdxContracts.usdxToken,
usdxContracts.protocol,
interestProvider
);

// Provide some interest
await usdxContracts.usdxToken.transfer(
funds.address,
ethers.utils.parseEther("10000")
);

await interestProvider.setAuthority(usdxContracts.guard.address);
await usdxContracts.guard.permitx(usr.address, interestProvider.address);

return {usdxContracts, usr, interestProvider};
}

module.exports = {
loadFixture,
fixtureInterestProvider,
fixtureUSRWithInterestProvider,
fixtureUSRWithMockInterestProvider,
};
Loading