Skip to content

Commit

Permalink
Remove console logs and resolve time based test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alsco77 committed Dec 10, 2020
1 parent 4c3adc1 commit 3d86ce3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
15 changes: 0 additions & 15 deletions contracts/masset/Masset.sol
@@ -1,9 +1,6 @@
pragma solidity 0.5.16;
pragma experimental ABIEncoderV2;

// TODO - remove
import { console } from "hardhat/console.sol";

// External
import { IForgeValidator } from "./forge-validator/IForgeValidator.sol";
import { IPlatformIntegration } from "../interfaces/IPlatformIntegration.sol";
Expand Down Expand Up @@ -185,7 +182,6 @@ contract Masset is
internal
returns (uint256 massetMinted)
{
console.log("\n~~ MINT ~~");
require(_recipient != address(0), "Must be a valid recipient");
require(_bAssetQuantity > 0, "Quantity must not be 0");

Expand Down Expand Up @@ -222,7 +218,6 @@ contract Masset is
internal
returns (uint256 massetMinted)
{
console.log("\n~~ MINT MULTI ~~");
require(_recipient != address(0), "Must be a valid recipient");
uint256 len = _bAssetQuantities.length;
require(len > 0 && len == _bAssets.length, "Input array mismatch");
Expand Down Expand Up @@ -282,7 +277,6 @@ contract Masset is
internal
returns (uint256 quantityDeposited, uint256 ratioedDeposit)
{
console.log("depositTokens: start");
// 1 - Send all to PI, using the opportunity to get the cache balance and net amount transferred
(uint256 transferred, uint256 cacheBal) = MassetHelpers.transferReturnBalance(msg.sender, _integrator, _bAsset, _quantity);

Expand All @@ -291,7 +285,6 @@ contract Masset is
// integrator == address(0) || address(this) and then keeping entirely in cache
// 2.1 - Deposit if xfer fees
if(_hasTxFee){
console.log("_depositTokens: hasTxFee");
uint256 deposited = IPlatformIntegration(_integrator).deposit(_bAsset, transferred, true);
quantityDeposited = StableMath.min(deposited, _quantity);
}
Expand All @@ -305,7 +298,6 @@ contract Masset is

uint256 relativeMaxCache = _maxCache.divRatioPrecisely(_bAssetRatio);

console.log("_depositTokens: cacheBal: %s vs relativeMaxCache: %s", cacheBal, relativeMaxCache);
if(cacheBal > relativeMaxCache){
uint256 delta = cacheBal.sub(relativeMaxCache.div(2));
IPlatformIntegration(_integrator).deposit(_bAsset, delta, false);
Expand Down Expand Up @@ -345,7 +337,6 @@ contract Masset is
nonReentrant
returns (uint256 output)
{
console.log("\n~~ SWAP ~~");
// Struct created to avoid Stack Too Deep errors. Minor gas cost increase.
SwapArgs memory args = SwapArgs(_input, _output, _recipient);
require(args.input != address(0) && args.output != address(0), "Invalid swap asset addresses");
Expand Down Expand Up @@ -572,7 +563,6 @@ contract Masset is
internal
returns (uint256 massetRedeemed)
{
console.log("\n~~ REDEEM ~~");
require(_recipient != address(0), "Must be a valid recipient");
uint256 bAssetCount = _bAssetQuantities.length;
require(bAssetCount > 0 && bAssetCount == _bAssets.length, "Input array mismatch");
Expand Down Expand Up @@ -742,34 +732,29 @@ contract Masset is
* @return amount Struct containing the desired output, output-fee, and the scaled fee
*/
function _withdrawTokens(WithdrawArgs memory args) internal returns (Amount memory amount) {
console.log("_withdrawTokens: q = args.quantity");
if(args.quantity > 0){

// 1. Deduct the redemption fee, if any, and log quantities
amount = _deductSwapFee(args.bAsset, args.quantity, args.feeRate, args.ratio);

// 2. If txFee then short circuit - there is no cache
if(args.hasTxFee){
console.log("_withdrawTokens: hasTxFee");
IPlatformIntegration(args.integrator).withdraw(args.recipient, args.bAsset, amount.net, amount.net, true);
}
// 3. Else, withdraw from either cache or main vault
else {
uint256 cacheBal = IERC20(args.bAsset).balanceOf(args.integrator);
// 3.1 - If balance b in cache, simply withdraw
if(cacheBal >= amount.net) {
console.log("_withdrawTokens: cacheBal >= net - '%s' > '%s'", cacheBal, amount.net);
IPlatformIntegration(args.integrator).withdrawRaw(args.recipient, args.bAsset, amount.net);
}
// 3.2 - Else reset the cache to X, or as far as possible
// - Withdraw X+b from platform
// - Send b to user
else {
console.log("_withdrawTokens: cacheBal < net - '%s' < '%s'", cacheBal, amount.net);
uint256 relativeMidCache = args.maxCache.divRatioPrecisely(args.ratio).div(2);
uint256 totalWithdrawal = StableMath.min(relativeMidCache.add(amount.net).sub(cacheBal), args.vaultBalance.sub(cacheBal));

console.log("_withdrawTokens: totalWithdrawal", totalWithdrawal);
IPlatformIntegration(args.integrator).withdraw(
args.recipient,
args.bAsset,
Expand Down
6 changes: 3 additions & 3 deletions test/savings/TestSavingsManager.spec.ts
Expand Up @@ -684,7 +684,7 @@ contract("SavingsManager", async (accounts) => {
});
});

it("should integrate with liquidator stream to allow collection and streaming of interest from mAsset", async () => {
it("should coexist with liquidator stream to allow simultaneous streaming", async () => {
// 0 1 2 3
// | - - - - - - | - - - - - - | - - - - - - |
// ^ ^ ^ ^ ^ ^ ^
Expand Down Expand Up @@ -762,7 +762,7 @@ contract("SavingsManager", async (accounts) => {
await savingsManager.collectAndStreamInterest(mUSD.address);
const s115 = await snapshotData();
expect(s115.yieldStream.end).bignumber.eq(s115.lastCollection.add(ONE_DAY));
assertBNClosePercent(s115.yieldStream.rate, total.div(ONE_DAY), "0.003");
assertBNClosePercent(s115.yieldStream.rate, total.div(ONE_DAY), "0.01");
await time.increase(ONE_DAY.muln(9).divn(2));
// @16
expectedInterest = s115.yieldStream.rate.mul(ONE_DAY);
Expand All @@ -788,7 +788,7 @@ contract("SavingsManager", async (accounts) => {
await savingsManager.collectAndStreamInterest(mUSD.address);
const s17 = await snapshotData();
assertBNClosePercent(s17.yieldStream.rate, platformInterest4.div(ONE_DAY), "0.01");
assertBNClose(ts17, s17.lastCollection, 5);
assertBNClose(ts17, s17.lastCollection, 10);
});
});
context("testing new mechanism", async () => {
Expand Down

0 comments on commit 3d86ce3

Please sign in to comment.