Skip to content

Commit 827157b

Browse files
committed
updating state mocks, incorperating dollar amount in euclidian distance calcs, starting adding tests for new state/setter/getter functions
1 parent ea81de4 commit 827157b

7 files changed

Lines changed: 119 additions & 2 deletions

File tree

protocol/contracts/dao/Auction.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ contract Auction is Comptroller {
7070
uint256 minMaturity = getCouponAuctionMinMaturity();
7171
uint256 maxMaturity = getCouponAuctionMaxMaturity();
7272
uint256 minYield = getCouponAuctionMinYield();
73-
uint256 maxYield = getCouponAuctionMaxYield();
73+
uint256 maxYield = getCouponAuctionMaxYield();
74+
uint256 minDollarAmount = getCouponAuctionMinDollarAmount();
75+
uint256 maxDollarAmount = getCouponAuctionMinDollarAmount();
7476

7577
// loop over bids and compute distance
7678
for (uint256 i = 0; i < getCouponAuctionBids(); i++) {
@@ -86,11 +88,16 @@ contract Auction is Comptroller {
8688
uint256 maturityRel = couponMaturityEpoch.div(
8789
maxMaturity.sub(minMaturity)
8890
);
91+
uint256 dollarRelMax = dollarAmount.div(
92+
maxDollarAmount.sub(minDollarAmount)
93+
);
94+
uint256 dollarRel = Decimal.one().sub(dollarRelMax).asUint256();
8995

9096
uint256 yieldRelSquared = Decimal.zero().add(yieldRel).pow(2).asUint256();
9197
uint256 maturityRelSquared = Decimal.zero().add(maturityRel).pow(2).asUint256();
98+
uint256 dollarRelSquared = Decimal.zero().add(dollarRel).pow(2).asUint256();
9299

93-
uint256 sumSquared = yieldRelSquared.add(maturityRelSquared);
100+
uint256 sumSquared = yieldRelSquared.add(maturityRelSquared).add(dollarRelSquared);
94101
uint256 distance = sqrt(sumSquared);
95102
getCouponBidderState(getCouponBidderStateIndex(i)).distance = distance;
96103
bids.push(getCouponBidderState(getCouponBidderStateIndex(i)));

protocol/contracts/dao/Getters.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ contract Getters is State {
239239
return _state.epochs[epoch()].auction.maxYield;
240240
}
241241

242+
function getCouponAuctionMinDollarAmount() internal view returns (uint256) {
243+
return _state.epochs[epoch()].auction.minDollarAmount;
244+
}
245+
246+
function getCouponAuctionMaxDollarAmount() internal view returns (uint256) {
247+
return _state.epochs[epoch()].auction.maxDollarAmount;
248+
}
249+
242250
/**
243251
* Governance
244252
*/

protocol/contracts/dao/Market.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ contract Market is Comptroller, Curve {
146146

147147
uint256 epoch = epoch().add(couponEpochExpiry);
148148
setCouponAuctionRelYield(maxCouponAmount.div(dollarAmount));
149+
setCouponAuctionRelDollarAmount(dollarAmount);
149150
setCouponAuctionRelMaturity(epoch);
150151
setCouponBidderState(msg.sender, epoch, dollarAmount, maxCouponAmount);
151152
setCouponBidderStateIndex(getCouponAuctionBids(), msg.sender);

protocol/contracts/dao/Setters.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ contract Setters is State, Getters {
156156
_state.epochs[epoch()].auction.maxMaturity = 0;
157157
_state.epochs[epoch()].auction.minYield = 1000000000000000000000000;
158158
_state.epochs[epoch()].auction.maxYield = 0;
159+
_state.epochs[epoch()].auction.minDollarAmount = 1000000000000000000000000;
160+
_state.epochs[epoch()].auction.maxDollarAmount = 0;
159161
}
160162

161163
function cancelCouponAuctionAtEpoch(uint256 epoch) internal {
@@ -198,13 +200,22 @@ contract Setters is State, Getters {
198200
_state.epochs[epoch()].auction.minYield = yield;
199201
}
200202
}
203+
201204
function setCouponAuctionRelMaturity(uint256 couponEpochExpiry) internal {
202205
if (couponEpochExpiry > _state.epochs[epoch()].auction.maxMaturity) {
203206
_state.epochs[epoch()].auction.maxMaturity = couponEpochExpiry;
204207
} else if (couponEpochExpiry < _state.epochs[epoch()].auction.minMaturity) {
205208
_state.epochs[epoch()].auction.minMaturity = couponEpochExpiry;
206209
}
207210
}
211+
212+
function setCouponAuctionRelDollarAmount(uint256 couponDollarAmount) internal {
213+
if (couponDollarAmount > _state.epochs[epoch()].auction.maxDollarAmount) {
214+
_state.epochs[epoch()].auction.maxDollarAmount = couponDollarAmount;
215+
} else if (couponDollarAmount < _state.epochs[epoch()].auction.minDollarAmount) {
216+
_state.epochs[epoch()].auction.minDollarAmount = couponDollarAmount;
217+
}
218+
}
208219

209220

210221
/**

protocol/contracts/dao/State.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ contract Epoch {
6969
uint256 maxMaturity;
7070
uint256 minYield;
7171
uint256 maxYield;
72+
uint256 minDollarAmount;
73+
uint256 maxDollarAmount;
7274
uint256 _totalBids;
7375
mapping(uint256 => address) couponBidder;
7476
mapping(address => CouponBidderState) couponBidderState;

protocol/contracts/mock/MockState.sol

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,49 @@ contract MockState is Setters {
119119
super.eliminateOutstandingCoupons(epoch);
120120
}
121121

122+
function initCouponAuctionE(address auction) external {
123+
super.initCouponAuction(auction);
124+
}
125+
126+
function cancelCouponAuctionAtEpochE(uint256 epoch) external {
127+
super.cancelCouponAuctionAtEpoch(epoch);
128+
}
129+
130+
function finishCouponAuctionAtEpochE(uint256 epoch) external {
131+
super.finishCouponAuctionAtEpoch(epoch);
132+
}
133+
134+
function setCouponBidderStateE(address bidder, uint256 couponEpochExpiry, uint256 dollarAmount, uint256 maxCouponAmount) external {
135+
super.setCouponBidderState(bidder, couponEpochExpiry, dollarAmount, maxCouponAmount);
136+
}
137+
138+
function setCouponBidderStateSelectedE(address bidder) external {
139+
super.setCouponBidderStateSelected(bidder);
140+
}
141+
142+
function setCouponBidderStateRejectedE(address bidder) external {
143+
super.setCouponBidderStateRejected(bidder);
144+
}
145+
146+
function setCouponBidderStateIndexE(uint256 index, address bidder) external {
147+
super.setCouponBidderStateIndex(index, bidder);
148+
}
149+
150+
function incrementCouponAuctionBidsE() external {
151+
super.incrementCouponAuctionBids();
152+
}
153+
154+
function setCouponAuctionRelYieldE(uint256 yield) external {
155+
super.setCouponAuctionRelYield(yield);
156+
}
157+
function setCouponAuctionRelMaturityE(uint256 couponEpochExpiry) external {
158+
super.setCouponAuctionRelMaturity(couponEpochExpiry);
159+
}
160+
161+
function setCouponAuctionRelDollarAmountE(uint256 couponDollarAmount) external {
162+
super.setCouponAuctionRelDollarAmount(couponDollarAmount);
163+
}
164+
122165
/**
123166
* Governance
124167
*/

protocol/test/dao/State.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,51 @@ describe('State', function () {
750750
});
751751
});
752752

753+
754+
describe('initCouponAuction', function () {
755+
describe('when called', function () {
756+
beforeEach('call', async function () {
757+
// need to create mock auction object and pass into this
758+
await this.setters.initCouponAuctionE(1);
759+
});
760+
761+
it('has auction set', async function () {
762+
// need to check that auction address exists, non zero and has all the other states initializd properly
763+
expect(await this.setters.getCouponAuctionAtEpoch(1)).to.be.bignumber.equal(new BN(91));
764+
});
765+
});
766+
});
767+
768+
describe('cancelCouponAuctionAtEpoch', function () {
769+
});
770+
771+
describe('finishCouponAuctionAtEpoch', function () {
772+
});
773+
774+
describe('setCouponBidderState', function () {
775+
});
776+
777+
describe('setCouponBidderStateSelected', function () {
778+
});
779+
780+
describe('setCouponBidderStateRejected', function () {
781+
});
782+
783+
describe('setCouponBidderStateIndex', function () {
784+
});
785+
786+
describe('incrementCouponAuctionBids', function () {
787+
});
788+
789+
describe('setCouponAuctionRelYield', function () {
790+
});
791+
792+
describe('setCouponAuctionRelMaturity', function () {
793+
});
794+
795+
describe('setCouponAuctionRelDollarAmount', function () {
796+
});
797+
753798
/**
754799
* Governance
755800
*/

0 commit comments

Comments
 (0)