OriginProtocol / ousd-governance

OUSD Governance Portal and Contracts
11 stars 4 forks source link

Add OGNRewardsSource contract #408

Closed shahthepro closed 5 months ago

shahthepro commented 6 months ago

If you made a contract change, make sure to complete the checklist below before merging it in master.

Contract change checklist:

pandadefi commented 6 months ago

@shahthepro I have added my comments regarding the changes.

DanielVF commented 5 months ago

FixedRateRewardsSource

Requirements

The FixedRateRewardsSource works to provide a steady per block stream of incentives funds to the xOGN staking contract.

Rewards can be sent to the contract from any source (including incentives, as well as protocol buybacks), but will drip out at a rate that can be changed by the strategist.

In the event that not enough funds are in the dripper, what funds are there are given out, and the dripper is reset to start accruing max dripped funds again. In this way even if there are fewer funds than expected coming in, the contract will still hand out whatever funds it does get.

Deployment Considerations

There's a potential circular address dependency between this contract and the staking contract. Both need to know the address of the other. We've taken the simple route and made this contract us a mutable address for the staking contract, while the staking contract uses an immutable address for this.

If the contract is not initialized, collect rewards will revert because the message sender is not 0, preventing anything weird from happening.

This should be deployed into a proxy.

Internal State

config.lastCollected should never move downwards. This holds. It is always set to the current timestamp, which does not move down.

config.lastCollected should be set any time rewards are sent from the contract. It is.

We should not have resolution issues on config.ratePerSecond, since we can pay at a rate down to trillions of a penny's worth of yield per day.

Attack

Depending on how this contract is used, it could hold up to a month or two of incentives. This could be a substantial amount reward tokens. This contract does not hold any user funds.

Attackers could attempt to steal funds. However, Funds only transfer to the admin controlled rewards target.

Attackers could attempt to increase the number of rewards paid. However rewards paid can only be increased by donating to the contract (and only then if it does not have enough rewards)

A collectRewards should be called before changing the setRewardsPerSecond, if we care about accuracy, or if it has not been called in a long time. This ensures that the past is paid at the past rate.

Logic

Contract logic looks correct .

Tests

Flavor

There are a few tiny flavor changes I see, but we can leave the contract as is.

Overflow

No for loops

Proxy

Black magic

Dependencies

Deploy

Authentication

Cryptographic code

_No Crypto

Gas problems

External calls

Ethereum