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

Commit

Permalink
Merge pull request #476 from keep-network/courtesycall-term-interactions
Browse files Browse the repository at this point in the history
Update courtesy_call / at-term interactions

We have evolved from only using liquidation to terminate at-term Deposits.
instead, Deposits can now only be closed by redemption (unless
undercollateralized or fraud).
  • Loading branch information
Shadowfiend committed Feb 20, 2020
2 parents 3c80db0 + 7a8f565 commit 6344892
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 79 deletions.
8 changes: 0 additions & 8 deletions implementation/contracts/deposit/Deposit.sol
Expand Up @@ -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;
}
}
12 changes: 0 additions & 12 deletions implementation/contracts/deposit/DepositLiquidation.sol
Expand Up @@ -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();
Expand All @@ -313,15 +312,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;
}
}
59 changes: 0 additions & 59 deletions implementation/test/DepositLiquidationTest.js
Expand Up @@ -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)
Expand Down Expand Up @@ -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'
)
})
})
})

0 comments on commit 6344892

Please sign in to comment.