Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/invariants #41

Merged
merged 19 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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: 2 additions & 2 deletions contracts/USM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ contract USM is IUSM, ERC20Permit, Delegable {

/**
* @notice Mint ETH for USM with checks and asset transfers. Uses msg.value as the ETH deposit.
* FUM needs to be funded before USM can be minted.
* @param ethIn Amount of wrapped Ether to use for minting USM.
* @return USM minted
*/
Expand All @@ -60,7 +61,6 @@ contract USM is IUSM, ERC20Permit, Delegable {
returns (uint)
{
// First calculate:
require(fum.totalSupply() > 0, "Fund before minting");
alcueca marked this conversation as resolved.
Show resolved Hide resolved
uint usmOut;
uint ethPoolGrowthFactor;
(usmOut, ethPoolGrowthFactor) = usmFromMint(ethIn);
Expand Down Expand Up @@ -184,7 +184,7 @@ contract USM is IUSM, ERC20Permit, Delegable {
function debtRatio() public view returns (uint) {
uint pool = ethPool();
if (pool == 0) {
return 0;
return MAX_DEBT_RATIO;
}
return totalSupply().wadDiv(ethToUsm(pool));
}
Expand Down
18 changes: 9 additions & 9 deletions test/02_USM_internal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require('chai').use(require('chai-as-promised')).should()

contract('USM - Internal functions', (accounts) => {
const [deployer, user1, user2, user3] = accounts
let mockToken
let usm

const price = new BN('25000000000')
const shift = new BN('8')
Expand All @@ -21,7 +21,7 @@ contract('USM - Internal functions', (accounts) => {
beforeEach(async () => {
oracle = await TestOracle.new(price, shift, { from: deployer })
weth = await WETH9.new({ from: deployer })
mockToken = await MockUSM.new(oracle.address, weth.address, { from: deployer })
usm = await MockUSM.new(oracle.address, weth.address, { from: deployer })
})

describe('deployment', async () => {
Expand All @@ -38,28 +38,28 @@ contract('USM - Internal functions', (accounts) => {

describe('functionality', async () => {
it('returns the oracle price in WAD', async () => {
let oraclePrice = (await mockToken.oraclePrice())
let oraclePrice = (await usm.oraclePrice())
oraclePrice.toString().should.equal(priceWAD.toString())
})

it('returns the value of eth in usm', async () => {
const oneEth = WAD
const equivalentUSM = oneEth.mul(priceWAD).div(WAD)
let usmAmount = (await mockToken.ethToUsm(oneEth))
let usmAmount = (await usm.ethToUsm(oneEth))
usmAmount.toString().should.equal(equivalentUSM.toString())
})

it('returns the value of usm in eth', async () => {
const oneUSM = WAD
const equivalentEth = oneUSM.mul(WAD).div(priceWAD)
let ethAmount = (await mockToken.usmToEth(oneUSM.toString()))
let ethAmount = (await usm.usmToEth(oneUSM.toString()))
ethAmount.toString().should.equal(equivalentEth.toString())
})

it('returns the debt ratio as zero', async () => {
const ZERO = new BN('0')
let debtRatio = (await mockToken.debtRatio())
debtRatio.toString().should.equal(ZERO.toString())
it('returns the debt ratio as MAX_DEBT_RATIO', async () => {
const MAX_DEBT_RATIO = await usm.MAX_DEBT_RATIO()
alcueca marked this conversation as resolved.
Show resolved Hide resolved
let debtRatio = (await usm.debtRatio())
debtRatio.toString().should.equal(MAX_DEBT_RATIO.toString())
})
})
})
5 changes: 4 additions & 1 deletion test/03_USM.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ contract('USM', (accounts) => {

describe("minting and burning", () => {
it("doesn't allow minting USM before minting FUM", async () => {
await expectRevert(usm.mint(user2, user1, oneEth, { from: user2 }), "Fund before minting")
await expectRevert(
usm.mint(user1, user1, oneEth, { from: user1 }),
"SafeMath: division by zero"
)
})

it("allows minting FUM", async () => {
Expand Down