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

Two-step change for governable values #515

Merged
merged 17 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion implementation/contracts/system/TBTCSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog {
uint128 private severelyUndercollateralizedThresholdPercent = 110; // percent
uint256[] lotSizesSatoshis = [10**5, 10**6, 10**7, 2 * 10**7, 5 * 10**7, 10**8]; // [0.001, 0.01, 0.1, 0.2, 0.5, 1.0] BTC

uint256 constant governanceTimeDelay = 1 hours;
uint256 constant governanceTimeDelay = 6 hours;

uint256 private signerFeeDivisorChangeInitiated;
uint256 private lotSizesChangeInitiated;
Expand Down
72 changes: 68 additions & 4 deletions implementation/test/TBTCSystemTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ describe("TBTCSystem", async function() {
await increaseTime(totalDelay.toNumber() - expectedRemaining)

const remaining = await tbtcSystem.geRemainingSignerFeeDivisorUpdateTime.call()
expect(remaining).to.eq.BN(expectedRemaining)
expect([expectedRemaining, expectedRemaining + 1]).to.include.toString(
nkuba marked this conversation as resolved.
Show resolved Hide resolved
remaining.toNumber(),
)
})
})

Expand Down Expand Up @@ -142,7 +144,9 @@ describe("TBTCSystem", async function() {
await increaseTime(totalDelay.toNumber() - expectedRemaining)

const remaining = await tbtcSystem.getRemainingLotSizesUpdateTime.call()
expect(remaining).to.eq.BN(expectedRemaining)
expect([expectedRemaining, expectedRemaining + 1]).to.include.toString(
remaining.toNumber(),
)
})
})

Expand Down Expand Up @@ -188,19 +192,35 @@ describe("TBTCSystem", async function() {
await increaseTime(totalDelay.toNumber() - expectedRemaining)

const remaining = await tbtcSystem.getRemainingCollateralizationUpdateTime.call()
expect(remaining).to.eq.BN(expectedRemaining)
expect([expectedRemaining, expectedRemaining + 1]).to.include.toString(
remaining.toNumber(),
)
})
})

describe("update signer fee", async () => {
describe("beginSignerFeeDivisorUpdate", async () => {
const newFee = new BN("201")
it("executes and fires SignerFeeDivisorUpdateStarted event", async () => {
nkuba marked this conversation as resolved.
Show resolved Hide resolved
receipt = await tbtcSystem.beginSignerFeeDivisorUpdate(new BN("200"))

expectEvent(receipt, "SignerFeeDivisorUpdateStarted", {
_signerFeeDivisor: new BN("200"),
})
})

it("overrides previous update and resets timer", async () => {
receipt = await tbtcSystem.beginSignerFeeDivisorUpdate(newFee)
const remainingTime = await tbtcSystem.geRemainingSignerFeeDivisorUpdateTime.call()
const totalDelay = await tbtcSystem.getGovernanceTimeDelay.call()

expectEvent(receipt, "SignerFeeDivisorUpdateStarted", {
_signerFeeDivisor: newFee,
})
expect([
remainingTime.toString(),
remainingTime.toString() - 1,
]).to.include(totalDelay.toString())
})

it("reverts if msg.sender != owner", async () => {
Expand Down Expand Up @@ -256,12 +276,35 @@ describe("TBTCSystem", async function() {
const lotSizes = [new BN(10 ** 8), new BN(10 ** 6)]
describe("beginLotSizesUpdate", async () => {
it("executes and emits a LotSizesUpdateStarted event", async () => {
const testSizes = [new BN(10 ** 8), new BN(10 ** 6)]
const block = await web3.eth.getBlock("latest")
const receipt = await tbtcSystem.beginLotSizesUpdate(testSizes)
expectEvent(receipt, "LotSizesUpdateStarted", {})
expect(receipt.logs[0].args[0][0]).to.eq.BN(testSizes[0])
expect(receipt.logs[0].args[0][1]).to.eq.BN(testSizes[1])
expect([
receipt.logs[0].args[1].toString(),
receipt.logs[0].args[1].toString() - 1,
]).to.include(block.timestamp.toString())
})

it("overrides previous update and resets timer", async () => {
const block = await web3.eth.getBlock("latest")
const receipt = await tbtcSystem.beginLotSizesUpdate(lotSizes)
const remainingTime = await tbtcSystem.getRemainingLotSizesUpdateTime.call()
const totalDelay = await tbtcSystem.getGovernanceTimeDelay.call()

expectEvent(receipt, "LotSizesUpdateStarted", {})
expect(receipt.logs[0].args[0][0]).to.eq.BN(lotSizes[0])
expect(receipt.logs[0].args[0][1]).to.eq.BN(lotSizes[1])
expect(receipt.logs[0].args[1]).to.eq.BN(block.timestamp)
expect([
receipt.logs[0].args[1].toString(),
receipt.logs[0].args[1].toString() - 1,
]).to.include(block.timestamp.toString())
expect([
remainingTime.toString(),
remainingTime.toString() - 1,
]).to.include(totalDelay.toString())
})

it("reverts if lot size array is empty", async () => {
Expand Down Expand Up @@ -320,17 +363,38 @@ describe("TBTCSystem", async function() {
const severelyUndercollateralizedPercent = new BN("120")
describe("beginCollateralizationThresholdsUpdate", async () => {
it("executes and fires CollateralizationThresholdsUpdateStarted event", async () => {
receipt = await tbtcSystem.beginCollateralizationThresholdsUpdate(
new BN("213"),
new BN("156"),
new BN("128"),
)

expectEvent(receipt, "CollateralizationThresholdsUpdateStarted", {
_initialCollateralizedPercent: new BN("213"),
_undercollateralizedThresholdPercent: new BN("156"),
_severelyUndercollateralizedThresholdPercent: new BN("128"),
})
})

it("overrides previous update and resets timer", async () => {
receipt = await tbtcSystem.beginCollateralizationThresholdsUpdate(
initialPercent,
undercollateralizedPercent,
severelyUndercollateralizedPercent,
)

const remainingTime = await tbtcSystem.getRemainingCollateralizationUpdateTime.call()
const totalDelay = await tbtcSystem.getGovernanceTimeDelay.call()

expectEvent(receipt, "CollateralizationThresholdsUpdateStarted", {
_initialCollateralizedPercent: initialPercent,
_undercollateralizedThresholdPercent: undercollateralizedPercent,
_severelyUndercollateralizedThresholdPercent: severelyUndercollateralizedPercent,
})
expect([
remainingTime.toString(),
remainingTime.toString() - 1,
]).to.include(totalDelay.toString())
})

it("reverts if Initial collateralized percent > 300", async () => {
Expand Down