livepeer / protocol

Livepeer protocol
MIT License
154 stars 45 forks source link

bonding: Treasury rewards contribution #616

Closed victorges closed 1 year ago

victorges commented 1 year ago

What does this pull request do? Explain your changes. (required) This implements the behavior described in LIP-92, for a logic in BondingManager to send a percentage of rewards to a treasury contract. This treasury contract was implemented in #615.

It also supports a balance ceiling which, if reached, will automatically halt treasury contributions until either the ceiling or the cut rate parameters (or both) are updated again.

Changing the treasuryCutRate also takes place only on the next round, to safeguard againsts possible games about when to execute a transaction in a round.

Specific updates (required)

How did you test each of these updates (required)

Does this pull request close any open issues? Implements PRO-27

Checklist:

victorges commented 1 year ago

Btw, not sure what is wrong with the tests. If I run the unit tests by themselves they all work, but they are failing under coverage for some reason. I didn't make changes to the tests that are failing (RoundsManager). Any idea of what could be causing this?

Edit: Found out a flaky test that wasn't awaiting and fixed it later on

yondonfu commented 1 year ago

Btw, not sure what is wrong with the tests.

Not immediately sure, but looks like coverage tests actually started failing in https://github.com/livepeer/protocol/pull/615.

yarn test:coverage does result in failures locally as well so its not just a CI thing. I tried upgrading to latest hardhat & solidity-coverage locally, but still seeing failures with a couple different ones as well:

1) Rewards
       correctly calculates reward shares for delegators and transcoders:
     Error: Timeout of 100000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/yondonfu/Development/livepeer/protocol/test/integration/Rewards.js)
      at listOnTimeout (node:internal/timers:564:17)
      at processTimers (node:internal/timers:507:7)

  2) Minter
       migrateToNewMinter
         should transfer current token balance and current ETH balance to new minter:
     TypeError: vm.on is not a function
      at Function.fromEvent (node_modules/@defi-wonderland/smock/src/observable-vm.ts:42:8)
      at new ObservableVM (node_modules/@defi-wonderland/smock/src/observable-vm.ts:19:35)
      at new Sandbox (node_modules/@defi-wonderland/smock/src/sandbox.ts:36:15)
      at Function.create (node_modules/@defi-wonderland/smock/src/sandbox.ts:82:12)
      at async init (node_modules/@defi-wonderland/smock/src/index.ts:27:13)
      at async Object.fake (node_modules/@defi-wonderland/smock/src/index.ts:13:17)

  3) Minter
       trustedBurnTokens
         should burn tokens:
     TypeError: vm.on is not a function
      at Function.fromEvent (node_modules/@defi-wonderland/smock/src/observable-vm.ts:42:8)
      at new ObservableVM (node_modules/@defi-wonderland/smock/src/observable-vm.ts:19:35)
      at new Sandbox (node_modules/@defi-wonderland/smock/src/sandbox.ts:36:15)
      at Function.create (node_modules/@defi-wonderland/smock/src/sandbox.ts:82:12)
      at async init (node_modules/@defi-wonderland/smock/src/index.ts:27:13)
      at async Object.fake (node_modules/@defi-wonderland/smock/src/index.ts:13:17)

  4) PollCreator
       "before all" hook in "PollCreator":
     TypeError: vm.on is not a function
      at Function.fromEvent (node_modules/@defi-wonderland/smock/src/observable-vm.ts:42:8)
      at new ObservableVM (node_modules/@defi-wonderland/smock/src/observable-vm.ts:19:35)
      at new Sandbox (node_modules/@defi-wonderland/smock/src/sandbox.ts:36:15)
      at Function.create (node_modules/@defi-wonderland/smock/src/sandbox.ts:82:12)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async init (node_modules/@defi-wonderland/smock/src/index.ts:27:13)
      at async Object.fake (node_modules/@defi-wonderland/smock/src/index.ts:13:17)

  5) RoundsManager
       setRoundLength
         should set roundLength before lastRoundLengthUpdateRound and lastRoundLengthUpdateStartBlock when roundLength = 0:
     AssertionError: wrong lastRoundLengthUpdateRound: expected { Object (_hex, _isBigNumber) } to equal 8
      at /Users/yondonfu/Development/livepeer/protocol/test/unit/RoundsManager.js:94:13
      at step (test/unit/RoundsManager.js:52:23)
      at Object.next (test/unit/RoundsManager.js:33:53)
      at fulfilled (test/unit/RoundsManager.js:24:58)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at runNextTicks (node:internal/process/task_queues:64:3)
      at listOnTimeout (node:internal/timers:533:9)
      at processTimers (node:internal/timers:507:7)