From 4bdb62314ec8d33c85d8d57a79c6bcdab2ab2158 Mon Sep 17 00:00:00 2001 From: NicholasDotSol Date: Thu, 20 Feb 2020 15:09:37 -0600 Subject: [PATCH 1/4] Remove notifyDepositExpiryCourtesyCall There is a dedicated redemption path that differentiates between at-term and courtesy call redemption. At-term deposits can only be terminated via a wilful redemption if they are sufficiently collateralized and not fraud. This function is a remnant of older times. --- .../contracts/deposit/DepositLiquidation.sol | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/implementation/contracts/deposit/DepositLiquidation.sol b/implementation/contracts/deposit/DepositLiquidation.sol index c86a6b4de..d178181e9 100644 --- a/implementation/contracts/deposit/DepositLiquidation.sol +++ b/implementation/contracts/deposit/DepositLiquidation.sol @@ -313,15 +313,4 @@ library DepositLiquidation { require(block.timestamp >= _d.courtesyCallInitiated + TBTCConstants.getCourtesyCallTimeout(), "Courtesy period has not elapsed"); startSignerAbortLiquidation(_d); } - - /// @notice Notifies the contract that its term limit has been reached - /// @dev This initiates a courtesy call - /// @param _d deposit storage pointer - function notifyDepositExpiryCourtesyCall(DepositUtils.Deposit storage _d) public { - require(_d.inActive(), "Deposit is not active"); - require(block.timestamp >= _d.fundedAt + TBTCConstants.getDepositTerm(), "Deposit term not elapsed"); - _d.setCourtesyCall(); - _d.logCourtesyCalled(); - _d.courtesyCallInitiated = block.timestamp; - } } From a0ba99746b9f7652a4c47742d3f241d385bb117e Mon Sep 17 00:00:00 2001 From: NicholasDotSol Date: Thu, 20 Feb 2020 15:13:51 -0600 Subject: [PATCH 2/4] allow exiting courtesy call while at-term Deposits should not be locked into COURTESY_CALL if thy are sufficiently collateralized. The redemption flow now motivates at-term redemption by the signers and will be the preferred exit path. Liquidation via courtesy-call when sufficiently collateralized is not preferable. --- implementation/contracts/deposit/DepositLiquidation.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/implementation/contracts/deposit/DepositLiquidation.sol b/implementation/contracts/deposit/DepositLiquidation.sol index d178181e9..4d41474a8 100644 --- a/implementation/contracts/deposit/DepositLiquidation.sol +++ b/implementation/contracts/deposit/DepositLiquidation.sol @@ -290,7 +290,6 @@ library DepositLiquidation { /// @param _d deposit storage pointer function exitCourtesyCall(DepositUtils.Deposit storage _d) public { require(_d.inCourtesyCall(), "Not currently in courtesy call"); - require(block.timestamp <= _d.fundedAt + TBTCConstants.getDepositTerm(), "Deposit is expiring"); require(getCollateralizationPercentage(_d) >= _d.undercollateralizedThresholdPercent, "Deposit is still undercollateralized"); _d.setActive(); _d.logExitedCourtesyCall(); From 8763352b7ddf358b568e2909a1055120b29c14b0 Mon Sep 17 00:00:00 2001 From: NicholasDotSol Date: Thu, 20 Feb 2020 15:16:40 -0600 Subject: [PATCH 3/4] Update Deposit.sol notifyDepositExpiryCourtesyCall was removed from depositLiquidation. remove it here too. --- implementation/contracts/deposit/Deposit.sol | 8 -------- 1 file changed, 8 deletions(-) diff --git a/implementation/contracts/deposit/Deposit.sol b/implementation/contracts/deposit/Deposit.sol index bb3b2f4f6..f55697fa0 100644 --- a/implementation/contracts/deposit/Deposit.sol +++ b/implementation/contracts/deposit/Deposit.sol @@ -437,12 +437,4 @@ contract Deposit is DepositFactoryAuthority { self.notifyCourtesyTimeout(); return true; } - - /// @notice Notifies the contract that its term limit has been reached - /// @dev This initiates a courtesy call - /// @return True if successful, otherwise revert - function notifyDepositExpiryCourtesyCall() public returns (bool) { - self.notifyDepositExpiryCourtesyCall(); - return true; - } } From 7a8f565b2c86cbfcd1ddb1bff53f015d7837761a Mon Sep 17 00:00:00 2001 From: NicholasDotSol Date: Thu, 20 Feb 2020 15:28:08 -0600 Subject: [PATCH 4/4] Updates liquidation tests - remove notifyDeposit- ExpiryCourtesyCall tests - remove at-term test for exitCourtesyCall --- implementation/test/DepositLiquidationTest.js | 59 ------------------- 1 file changed, 59 deletions(-) diff --git a/implementation/test/DepositLiquidationTest.js b/implementation/test/DepositLiquidationTest.js index 5e6498378..539095ec1 100644 --- a/implementation/test/DepositLiquidationTest.js +++ b/implementation/test/DepositLiquidationTest.js @@ -319,15 +319,6 @@ describe('DepositLiquidation', async function() { ) }) - it('reverts if the deposit term is expiring anyway', async () => { - await testDeposit.setUTXOInfo('0x' + '00'.repeat(8), 0, '0x' + '00'.repeat(36)) - - await expectRevert( - testDeposit.exitCourtesyCall(), - 'Deposit is expiring' - ) - }) - it('reverts if the deposit is still undercollateralized', async () => { await tbtcSystemStub.setOraclePrice(new BN('1000000000000', 10)) await ecdsaKeepStub.setBondAmount(0) @@ -455,54 +446,4 @@ describe('DepositLiquidation', async function() { expect(liquidationTime[0], 'liquidation timestamp not recorded').not.to.eq.BN(0) }) }) - - describe('notifyDepositExpiryCourtesyCall', async () => { - let timer - let fundedTime - - before(async () => { - timer = await tbtcConstants.getCourtesyCallTimeout.call() - }) - - beforeEach(async () => { - const block = await web3.eth.getBlock('latest') - const blockTimestamp = block.timestamp - fundedTime = blockTimestamp - timer.toNumber() - 1 // has expired - await testDeposit.setState(states.ACTIVE) - await testDeposit.setUTXOInfo('0x' + '00'.repeat(8), 0, '0x' + '00'.repeat(36)) - }) - - it('sets courtesy call state, stores the time, and logs CourtesyCalled', async () => { - const blockNumber = await web3.eth.getBlock('latest').number - - await testDeposit.notifyDepositExpiryCourtesyCall() - - const depositState = await testDeposit.getState.call() - expect(depositState).to.eq.BN(states.COURTESY_CALL) - - const liquidationTime = await testDeposit.getLiquidationAndCourtesyInitiated.call() - expect(liquidationTime[1]).not.to.eq.BN(0) - - const eventList = await tbtcSystemStub.getPastEvents('CourtesyCalled', { fromBlock: blockNumber, toBlock: 'latest' }) - expect(eventList.length).to.equal(1) - }) - - it('reverts if not in active', async () => { - await testDeposit.setState(states.START) - - await expectRevert( - testDeposit.notifyDepositExpiryCourtesyCall(), - 'Deposit is not active' - ) - }) - - it('reverts if deposit not yet expiring', async () => { - await testDeposit.setUTXOInfo('0x' + '00'.repeat(8), fundedTime * 5, '0x' + '00'.repeat(36)) - - await expectRevert( - testDeposit.notifyDepositExpiryCourtesyCall(), - 'Deposit term not elapsed' - ) - }) - }) })