good morning!!!!

Skip to content
Snippets Groups Projects
Commit 56a4c9f1 authored by jbarber13's avatar jbarber13
Browse files

capped rebase is ready

parent 63113022
Branches
No related tags found
No related merge requests found
...@@ -13,9 +13,6 @@ import "../../_external/openzeppelin/OwnableUpgradeable.sol"; ...@@ -13,9 +13,6 @@ import "../../_external/openzeppelin/OwnableUpgradeable.sol";
import "../../_external/openzeppelin/Initializable.sol"; import "../../_external/openzeppelin/Initializable.sol";
import "../../_external/openzeppelin/SafeERC20Upgradeable.sol"; import "../../_external/openzeppelin/SafeERC20Upgradeable.sol";
//testing
import "hardhat/console.sol";
/// @title Capped Rebase Token /// @title Capped Rebase Token
/// @notice handles all minting/burning of underlying rebasing token /// @notice handles all minting/burning of underlying rebasing token
/// @dev extends ierc20 upgradable /// @dev extends ierc20 upgradable
...@@ -98,8 +95,8 @@ contract CappedRebaseToken is Initializable, OwnableUpgradeable, ERC20Upgradeabl ...@@ -98,8 +95,8 @@ contract CappedRebaseToken is Initializable, OwnableUpgradeable, ERC20Upgradeabl
} }
///@notice because these tokens only exist in the vault, we can override balanceOf ///@notice because these tokens only exist in the vault, we can override balanceOf
/// and simply account in only the underlying balance and not worry about the wrapper balance /// and simply account in only the underlying balance and not worry about the wrapper balance.
/// to get the wrapper balance, we can plug the underlying balance into /// To get the wrapper balance, we can plug the underlying balance into
/// function underlyingToWrapper(<underlying balance>) /// function underlyingToWrapper(<underlying balance>)
function balanceOf(address account) public view override returns (uint256 balance) { function balanceOf(address account) public view override returns (uint256 balance) {
return _capped_to_underlying(super.balanceOf(account), _query_Underlying_Supply()); return _capped_to_underlying(super.balanceOf(account), _query_Underlying_Supply());
......
...@@ -53,7 +53,6 @@ describe("Testing CappedToken functions using aUSDC", () => { ...@@ -53,7 +53,6 @@ describe("Testing CappedToken functions using aUSDC", () => {
await expect(s.VaultController.connect(accounts[i]).mintVault()).to.not.reverted await expect(s.VaultController.connect(accounts[i]).mintVault()).to.not.reverted
const vaultId = await s.VaultController.vaultsMinted() const vaultId = await s.VaultController.vaultsMinted()
//deposit //deposit
await s.aUSDC.connect(accounts[i]).approve(s.CappedOAUSDC.address, s.aUSDCamount) await s.aUSDC.connect(accounts[i]).approve(s.CappedOAUSDC.address, s.aUSDCamount)
await s.CappedOAUSDC.connect(accounts[i]).deposit(s.aUSDCamount, vaultId) await s.CappedOAUSDC.connect(accounts[i]).deposit(s.aUSDCamount, vaultId)
...@@ -75,15 +74,23 @@ describe("Testing CappedToken functions using aUSDC", () => { ...@@ -75,15 +74,23 @@ describe("Testing CappedToken functions using aUSDC", () => {
caBalance = await s.CappedOAUSDC.balanceOf(s.BobVault.address) caBalance = await s.CappedOAUSDC.balanceOf(s.BobVault.address)
expect(caBalance).to.eq(0, "Bob's vault holds 0 capped aUSDC at the start") expect(caBalance).to.eq(0, "Bob's vault holds 0 capped aUSDC at the start")
//deposit 0
expect(s.CappedOAUSDC.connect(s.Bob).deposit(BN("0"), s.BobVaultID)).to.be.revertedWith("Cannon deposit 0")
//deposit too much
const excessiveDeposit = BN("1e36")
//temporarily set the cap to be high enough to allow for failing deposit to error correctly
await s.CappedOAUSDC.connect(s.Frank).setCap(excessiveDeposit.mul(2))
await s.aUSDC.connect(s.Bob).approve(s.CappedOAUSDC.address, excessiveDeposit)
expect(s.CappedOAUSDC.connect(s.Bob).deposit(excessiveDeposit, s.BobVaultID)).to.be.reverted
//return cap to expected amount
await s.CappedOAUSDC.connect(s.Frank).setCap(s.aUSDCcap)
await s.aUSDC.connect(s.Bob).approve(s.CappedOAUSDC.address, s.aUSDCamount) await s.aUSDC.connect(s.Bob).approve(s.CappedOAUSDC.address, s.aUSDCamount)
await s.CappedOAUSDC.connect(s.Bob).deposit(s.aUSDCamount, s.BobVaultID) await s.CappedOAUSDC.connect(s.Bob).deposit(s.aUSDCamount, s.BobVaultID)
caBalance = await s.aUSDC.balanceOf(s.Bob.address) caBalance = await s.aUSDC.balanceOf(s.Bob.address)
expect(caBalance.toNumber()).to.be.closeTo(0, 100, "Bob holds ~0 capped aUSDC after deposit") expect(caBalance.toNumber()).to.be.closeTo(0, 50, "Bob holds ~0 capped aUSDC after deposit")
//wrappedAmount = await s.CappedOAUSDC.balanceOf(s.BobVault.address)
//showBodyCyan("Resulting wrapped balance: ", await toNumber(wrappedAmount))
// expect(caBalance).to.eq(s.aUSDCamount, "Bob's vault received the capped aUSDC tokens")
}) })
...@@ -96,7 +103,7 @@ describe("Testing CappedToken functions using aUSDC", () => { ...@@ -96,7 +103,7 @@ describe("Testing CappedToken functions using aUSDC", () => {
const expected = await s.aUSDC.balanceOf(s.Carol.address) const expected = await s.aUSDC.balanceOf(s.Carol.address)
const reported = await s.CappedOAUSDC.balanceOf(s.BobVault.address) const reported = await s.CappedOAUSDC.balanceOf(s.BobVault.address)
expect(reported.toNumber()).to.be.closeTo(expected.toNumber(), 50, "Bob's appreciation has been recorded") expect(reported.toNumber()).to.be.closeTo(expected.toNumber(), 50, "Bob's appreciation has been recorded accurately")
}) })
...@@ -108,13 +115,18 @@ describe("Testing CappedToken functions using aUSDC", () => { ...@@ -108,13 +115,18 @@ describe("Testing CappedToken functions using aUSDC", () => {
const initialUnderlying = await s.aUSDC.balanceOf(s.CappedOAUSDC.address) const initialUnderlying = await s.aUSDC.balanceOf(s.CappedOAUSDC.address)
const initialSupply = await s.CappedOAUSDC.totalSupply() const initialSupply = await s.CappedOAUSDC.totalSupply()
//test failing withdraw cases
//withdraw more than is had
const excessiveWithdraw = BN("1e36")
expect(s.BobVault.connect(s.Bob).withdrawErc20(s.CappedOAUSDC.address, excessiveWithdraw)).to.be.revertedWith("ERC20: burn amount exceeds balance")
//withdraw some but not all //withdraw some but not all
await s.BobVault.connect(s.Bob).withdrawErc20(s.CappedOAUSDC.address, underlyingWithdrawAmount) await s.BobVault.connect(s.Bob).withdrawErc20(s.CappedOAUSDC.address, underlyingWithdrawAmount)
//verify //verify
//Bob should now have ~1/2 of the original input amount //Bob should now have ~1/2 of the original input amount
let balance = await s.aUSDC.balanceOf(s.Bob.address) let balance = await s.aUSDC.balanceOf(s.Bob.address)
expect(balance.toNumber()).to.be.closeTo(underlyingWithdrawAmount.toNumber(), 100, "Bob received the correct amount of underlying tokens") expect(balance.toNumber()).to.be.closeTo(underlyingWithdrawAmount.toNumber(), 10, "Bob received the correct amount of underlying tokens")
//remaining underlying for this test should now be initialUnderlying reduced by underlyingWithdrawAmount //remaining underlying for this test should now be initialUnderlying reduced by underlyingWithdrawAmount
balance = await s.aUSDC.balanceOf(s.CappedOAUSDC.address) balance = await s.aUSDC.balanceOf(s.CappedOAUSDC.address)
......
...@@ -163,7 +163,6 @@ describe("Liquidations", () => { ...@@ -163,7 +163,6 @@ describe("Liquidations", () => {
const expected = (liquidationValue.mul(s.LiquidationIncentive)).div(BN("1e18")) const expected = (liquidationValue.mul(s.LiquidationIncentive)).div(BN("1e18"))
expect(await toNumber(profit)).to.be.closeTo(await toNumber(expected), 0.1, "Expected profit achieved") expect(await toNumber(profit)).to.be.closeTo(await toNumber(expected), 0.1, "Expected profit achieved")
}) })
it("repay all", async () => { it("repay all", async () => {
...@@ -177,19 +176,18 @@ describe("Liquidations", () => { ...@@ -177,19 +176,18 @@ describe("Liquidations", () => {
expect(liab).to.eq(0, "Loan completely repaid") expect(liab).to.eq(0, "Loan completely repaid")
}) })
it("Withdraw after loan", async () => { it("Withdraw all after loan", async () => {
const vaultCappedOAUSDC = await s.CappedOAUSDC.balanceOf(s.BobVault.address) const vaultCappedOAUSDC = await s.CappedOAUSDC.balanceOf(s.BobVault.address)
await s.BobVault.connect(s.Bob).withdrawErc20(s.CappedOAUSDC.address, vaultCappedOAUSDC) await s.BobVault.connect(s.Bob).withdrawErc20(s.CappedOAUSDC.address, vaultCappedOAUSDC)
let balance = await s.aUSDC.balanceOf(s.BobVault.address) let balance = await s.CappedOAUSDC.balanceOf(s.BobVault.address)
expect(await toNumber(balance)).to.eq(0, "All aUSDC withdrawn") expect(balance.toNumber()).to.eq(0, "All CappedOAUSDC removed from vault")
balance = await s.CappedOAUSDC.balanceOf(s.BobVault.address)
expect(balance.toNumber()).to.be.closeTo(0, 10, "All CappedOAUSDC removed from vault")
balance = await s.aUSDC.balanceOf(s.Bob.address) balance = await s.aUSDC.balanceOf(s.Bob.address)
showBody(balance)
showBody(s.aUSDCamount.sub(T2L))
expect(await toNumber(balance)).to.be.closeTo(await toNumber(s.aUSDCamount.sub(T2L)), 2, "Bob received collateral - liquidated amount") expect(await toNumber(balance)).to.be.closeTo(await toNumber(s.aUSDCamount.sub(T2L)), 2, "Bob received collateral - liquidated amount")
}) })
}) })
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment