Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Expose collateralization functions and Keep address #590

Merged
merged 4 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions solidity/contracts/deposit/Deposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ contract Deposit is DepositFactoryAuthority {
require(msg.sender == self.keepAddress, "Deposit contract can only receive ETH from underlying keep");
}

/// @notice Get the keep contract address associated with the Deposit.
/// @dev The keep contract address is saved on Deposit initialization.
/// @return Address of the Keep contract.
function getKeepAddress() public view returns (address) {
return self.keepAddress;
}

/// @notice Get the integer representing the current state.
/// @dev We implement this because contracts don't handle foreign enums well.
/// see DepositStates for more info on states.
Expand Down Expand Up @@ -384,6 +391,39 @@ contract Deposit is DepositFactoryAuthority {
// LIQUIDATION
//

/// @notice Get the current collateralization level for this Deposit.
/// @dev This value represents the percentage of the backing BTC value the signers
/// currently must hold as bond.
/// @return The severe collateralization level for this deposit.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NicholasDotSol potential copypasta re: "severe"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is there a reason why getCollateralizationPercentage is uint256? Seems like we could return uint16 here too, just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NicholasDotSol potential copypasta re: "severe"?

yeah good catch, severe -> current

Also is there a reason why getCollateralizationPercentage is uint256? Seems like we could return uint16 here too, just curious.

There is no reason to move this to a smaller uint size. It makes sense for other collateralization values that take up storage since we can take advantage of bit-packing. But Since this value is calculated in memory, converting from and to uint types will just take additional gas

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good catch, severe -> current

also note that this is repeated below too.

There is no reason to move this to a smaller uint size. It makes sense for other collateralization values that take up storage since we can take advantage of bit-packing. But Since this value is calculated in memory, converting from and to uint types will just take additional gas

Alright, fair enough. Didn't know that there were gas costs for casting to lower types, thought everything was the same word-size in memory.

function getCollateralizationPercentage() public view returns (uint256) {
return self.getCollateralizationPercentage();
}

/// @notice Get the initial collateralization level for this Deposit.
/// @dev This value represents the percentage of the backing BTC value the signers hold initially.
/// @return The initial collateralization level for this deposit.
function getInitialCollateralizedPercent() public view returns (uint16) {
return self.initialCollateralizedPercent;
}

/// @notice Get the undercollateralization level for this Deposit.
/// @dev This collateralization level is semi-critical. If the collateralization level falls
/// below this percentage the Deposit can get courtesy-called. This value represents the percentage
/// of the backing BTC value the signers must hold as bond in order to not be undercollateralized.
/// @return The severe collateralization level for this deposit.
function getUndercollateralizedThresholdPercent() public view returns (uint16) {
return self.undercollateralizedThresholdPercent;
}

/// @notice Get the severe undercollateralization level for this Deposit.
/// @dev This collateralization level is critical. If the collateralization level falls
/// below this percentage the Deposit can get liquidated. This value represents the percentage
/// of the backing BTC value the signers must hold as bond in order to not be severely undercollateralized.
/// @return The severe collateralization level for this deposit.
function getSeverelyUndercollateralizedThresholdPercent() public view returns (uint16) {
return self.severelyUndercollateralizedThresholdPercent;
}

/// @notice Closes an auction and purchases the signer bonds. Payout to buyer, funder, then signers if not fraud.
/// @dev For interface, reading auctionValue will give a past value. the current is better.
/// @return True if successful, revert otherwise.
Expand Down
10 changes: 0 additions & 10 deletions solidity/contracts/test/deposit/TestDeposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,10 @@ contract TestDeposit is Deposit {
self.initialCollateralizedPercent = _initialCollateralizedPercent;
}

function getUndercollateralizedThresholdPercent() public view returns (uint16) { return self.undercollateralizedThresholdPercent; }

function setSeverelyUndercollateralizedThresholdPercent(uint16 _severelyUndercollateralizedThresholdPercent) public {
self.severelyUndercollateralizedThresholdPercent = _severelyUndercollateralizedThresholdPercent;
}

function getSeverelyUndercollateralizedThresholdPercent() public view returns (uint16) {
return self.severelyUndercollateralizedThresholdPercent;
}

function setLiquidationAndCourtesyInitated(
uint256 _liquidation,
uint256 _courtesy
Expand Down Expand Up @@ -123,10 +117,6 @@ contract TestDeposit is Deposit {
self.keepAddress = _keepAddress;
}

function getKeepAddress() public view returns (address) {
return self.keepAddress;
}

Shadowfiend marked this conversation as resolved.
Show resolved Hide resolved
function setSigningGroupRequestedAt(uint256 _signingGroupRequestedAt) public {
self.signingGroupRequestedAt = _signingGroupRequestedAt;
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/test/DepositUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ describe("DepositUtils", async function() {
it("returns correct base percentage", async () => {
const basePercentage = await testDeposit.getAuctionBasePercentage.call()

const initialCollateralization = await tbtcSystemStub.getInitialCollateralizedPercent()
const initialCollateralization = await testDeposit.getInitialCollateralizedPercent()

// 10000 to avoid losing value to truncating in solidity.
const expected = new BN(10000).div(initialCollateralization)
Expand Down