Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purchase Orders #161

Open
wants to merge 7 commits into
base: openzeppelin-v5
Choose a base branch
from
Open

Purchase Orders #161

wants to merge 7 commits into from

Conversation

lekevicius
Copy link
Collaborator

Purchase Orders aim to solve potential ruggability of Orbs.

Problem: Orb could get abandoned at any point, even if there’s a pledge. If you purchase the Orb before its cooldown expires, then you might never get to ask a question (or claim the pledge, as it goes to the last invoker), despite paying for the Orb.

Solution: replacing immediate purchases with purchase orders while Orb is charging, holding these funds until Orb is invokable, and then executing the purchase. If the pledge is claimed, or Orb does not become invokable until an expiration date, then the order is cancelled, and funds are returned to the purchasers.

Additional mechanics:

  • Purchase Order can only be made if Keeper has enough funds to cover ownership until Orb is charged.
  • Subsequent purchase orders are more expense (each time price increases 1.2x), with the difference between last and current price going to the previous purchaser as compensation.
  • Instant purchases are still always allowed. UI will warn users about risks.
  • Changing price, relinquishing Orb or withdrawing funds is not permitted for the Keeper if there is a Purchase Order.
  • Foreclosure finalizes the Purchase Order, instead of running re-allocation.
  • Pledge claim cancels the Purchase Order.
  • Order can also be manually canceled after 2 invocation periods since it was made, if Orb is still not invokable.

@lekevicius lekevicius changed the base branch from main to openzeppelin-v5 April 30, 2024 17:45
Signed-off-by: Jonas Lekevicius <[email protected]>
onlyKeeperHeld(orbId)
onlyKeeperSolvent(orbId)
{
function purchase(uint256 orbId, uint256 newPrice_) external payable virtual onlyKeeperHeld(orbId) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this function also revert if there's a standing purchase order? (purchaseOrder[orbId].purchaser != address(0))?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, my thinking was to allow immediate risky purchase, if you don't want to to wait until Orb recharges, and accept the rug risk.

Immediate risky purchase is allowed before a purchase order, and in here it also compensates the purchase order maker. Can't see large pros or cons either way. Maybe will remove this feature to keep it simpler.

@t4t5
Copy link
Collaborator

t4t5 commented May 1, 2024

Overall lgtm, but we should probably add some tests!

@lekevicius
Copy link
Collaborator Author

There are no tests for the entire new system yet, will work on that once we feature-freeze. Not ideal, but main branch won't be merged until we have full test coverage.

lekevicius added 4 commits May 1, 2024 18:14
Signed-off-by: Jonas Lekevicius <[email protected]>
Signed-off-by: Jonas Lekevicius <[email protected]>
Signed-off-by: Jonas Lekevicius <[email protected]>
Signed-off-by: Jonas Lekevicius <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants