Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
make changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendan Chou committed Aug 6, 2018
1 parent a434b6b commit 12b2c24
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 111 deletions.
14 changes: 14 additions & 0 deletions contracts/lib/MathHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ library MathHelpers {
return 2 ** 256 - 1;
}

/**
* Calculates and returns the maximum value for a uint256 in solidity
*
* @return The maximum value for uint256
*/
function maxUint32(
)
internal
pure
returns (uint32)
{
return 2 ** 32 - 1;
}

/**
* Returns the number of bits in a uint256. That is, the lowest number, x, such that n >> x == 0
*
Expand Down
27 changes: 23 additions & 4 deletions contracts/margin/external/BucketLender/BucketLender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ contract BucketLender is
// ============ Events ============

event Deposit(
address beneficiary,
address indexed beneficiary,
uint256 bucket,
uint256 amount,
uint256 weight
);

event Withdraw(
address withdrawer,
address indexed withdrawer,
uint256 bucket,
uint256 weight,
uint256 owedTokenWithdrawn,
Expand Down Expand Up @@ -155,6 +155,7 @@ contract BucketLender is
*/
// Available Amount for each bucket
mapping(uint256 => uint256) public availableForBucket;

// Total Available Amount
uint256 public availableTotal;

Expand All @@ -165,6 +166,7 @@ contract BucketLender is
*/
// Outstanding Principal for each bucket
mapping(uint256 => uint256) public principalForBucket;

// Total Outstanding Principal
uint256 public principalTotal;

Expand All @@ -177,6 +179,7 @@ contract BucketLender is
*/
// Weight for each account in each bucket
mapping(uint256 => mapping(address => uint256)) public weightForBucketForAccount;

// Total Weight for each bucket
mapping(uint256 => uint256) public weightForBucket;

Expand Down Expand Up @@ -378,11 +381,11 @@ contract BucketLender is

// CHECK VALUES32
require(
loanOffering.callTimeLimit == CALL_TIMELIMIT,
loanOffering.callTimeLimit == MathHelpers.maxUint32(),
"BucketLender#verifyLoanOffering: loanOffering.callTimelimit is incorrect"
);
require(
loanOffering.maxDuration == MAX_DURATION,
loanOffering.maxDuration == MathHelpers.maxUint32(),
"BucketLender#verifyLoanOffering: loanOffering.maxDuration is incorrect"
);
assert(loanOffering.rates.interestRate == INTEREST_RATE);
Expand Down Expand Up @@ -432,6 +435,22 @@ contract BucketLender is
position.heldToken == HELD_TOKEN,
"BucketLender#receiveLoanOwnership: Position heldToken mismatch"
);
require(
position.maxDuration == MAX_DURATION,
"BucketLender#receiveLoanOwnership: Position maxDuration mismatch"
);
require(
position.callTimeLimit == CALL_TIMELIMIT,
"BucketLender#receiveLoanOwnership: Position callTimeLimit mismatch"
);
require(
position.interestRate == INTEREST_RATE,
"BucketLender#receiveLoanOwnership: Position interestRate mismatch"
);
require(
position.interestPeriod == INTEREST_PERIOD,
"BucketLender#receiveLoanOwnership: Position interestPeriod mismatch"
);
require(
Margin(DYDX_MARGIN).getPositionBalance(POSITION_ID) >= minHeldToken,
"BucketLender#receiveLoanOwnership: Not enough heldToken as collateral"
Expand Down
22 changes: 11 additions & 11 deletions contracts/margin/external/BucketLender/BucketLenderFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ contract BucketLenderFactory {

event BucketLenderCreated(
address indexed creator,
address at,
bytes32 positionId
bytes32 indexed positionId,
address at
);

// ============ State Variables ============
Expand Down Expand Up @@ -64,13 +64,13 @@ contract BucketLenderFactory {
* @param owedToken Address of the token being lent by the BucketLender
* @param parameters Values corresponding to:
*
* [0] = number of seconds per bucket
* [1] = interest rate
* [2] = interest period
* [3] = maximum loan duration
* [4] = margin-call timelimit
* [5] = numerator of minimum heldToken-per-owedToken
* [6] = denominator of minimum heldToken-per-owedToken
* [0] = number of seconds per bucket
* [1] = interest rate
* [2] = interest period
* [3] = maximum loan duration
* [4] = margin-call timelimit
* [5] = numerator of minimum heldToken-per-owedToken
* [6] = denominator of minimum heldToken-per-owedToken
*
* @param marginCallers Accounts that are permitted to margin-call positions (or cancel the margin call)
* @return The address of the new BucketLender contract
Expand Down Expand Up @@ -98,8 +98,8 @@ contract BucketLenderFactory {

emit BucketLenderCreated(
msg.sender,
newBucketLender,
positionId
positionId,
newBucketLender
);

return newBucketLender;
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ module.exports = {
ZERO: new BigNumber(0),
ONE_DAY_IN_SECONDS: new BigNumber(60 * 60 * 24),
ONE_YEAR_IN_SECONDS: new BigNumber(60 * 60 * 24 * 365),
ONES_127: new BigNumber("340282366920938463463374607431768211455"), // 2**128-1
ONES_255: new BigNumber(
MAX_UINT32: new BigNumber("4294967295"), // 2**32-1
MAX_UINT128: new BigNumber("340282366920938463463374607431768211455"), // 2**128-1
MAX_UINT256: new BigNumber(
"115792089237316195423570985008687907853269984665640564039457584007913129639935"), // 2**256-1
},
BYTES32: {
Expand Down
2 changes: 1 addition & 1 deletion test/margin/TestFractionMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const TestFractionMath = artifacts.require("TestFractionMath");
const { BIGNUMBERS } = require('../helpers/Constants');
const { expectAssertFailure } = require('../helpers/ExpectHelper');

const bn = BIGNUMBERS.ONES_127;
const bn = BIGNUMBERS.MAX_UINT128;

contract('FractionMath', function(_accounts) {
let contract;
Expand Down
2 changes: 1 addition & 1 deletion test/margin/TestMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ contract('InterestHelper', function(_accounts) {
describe('#maxUint256', () => {
it('gives the expected value', async () => {
const result = await contract.maxUint256.call();
expect(result).to.be.bignumber.equal(BIGNUMBERS.ONES_255);
expect(result).to.be.bignumber.equal(BIGNUMBERS.MAX_UINT256);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/margin/external/TestZeroExExchangeWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('ZeroExExchangeWrapper', () => {
expect(ZERO_EX_EXCHANGE).to.eq(ZeroExExchange.address);
expect(ZERO_EX_PROXY).to.eq(ZeroExProxy.address);
expect(ZRX).to.eq(FeeToken.address);
expect(zrxProxyAllowance).to.be.bignumber.eq(BIGNUMBERS.ONES_255);
expect(zrxProxyAllowance).to.be.bignumber.eq(BIGNUMBERS.MAX_UINT256);
});
});
});
Expand Down
Loading

0 comments on commit 12b2c24

Please sign in to comment.