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

Sequential commit #569

Merged
merged 53 commits into from
Nov 21, 2023
Merged

Sequential commit #569

merged 53 commits into from
Nov 21, 2023

Conversation

zajck
Copy link
Member

@zajck zajck commented Feb 17, 2023

This PR introduces sequential commit into the protocol.
It also includes methods used for price discovery, since it's needed for tests (fulFilOrder, fulfilBuyOrder and fulfilSellOrder). This might not be in its final form and might be completely replaced, since at the end we expect to have the same price discovery methods shared between commitToOffer and sequentialCommitToOffer.

Changes:

  • added structs SequentialCommit and PriceDiscovery
  • added IBosonSequentialCommitHandler.sol which implements IERC721Receiver interface and has additional method sequentialCommitToOffer
  • added mock contract that acts as price discovery contract
  • created a PriceDiscoveryBase which:
    • handles WETH <> native token management
    • added price discovery internal methods fulFilOrder, fulfilBuyOrder and fulfilSellOrder
  • created SequentialCommitFacet with methods
    • sequentialCommitToOffer to handle sequential commits
    • onERC721Received to handle incoming boson vouchers
  • in contracts/protocol/facets/ExchangeHandlerFacet.sol
    • nonReentrant modifier was removed from onVoucherTransferred
  • in contracts/protocol/libs/FundsLib.sol
    • added releaseFundsToIntermediateSellers to handle funds at finalization time for all involved parties
    • refactored part of the code by adding increaseAvailableFundsAndEmitEvent
    • changed transferFundsToProtocol and transferFundsFromProtocol so they can work without _entityId
  • changed deploy script to support deployment of handlers with constructors

Note: this implementation works with the current royalties (one recipient, one percentage). Royalties will be changed in a separate PR and after it's approved, sequential commit will be adapted to work with them.

Removal of reentrancy guard on onVoucherTransferred

Reentrancy guard on onVoucherTransferred prevents voucher transfer during the sequential commit, therefore it was removed. It does not pose a threat to the protocol or vouchers, since it does not make any external calls and it's callable only by voucher contracts, which are under our control. The only reason why we had it here before was to prevent potential inconsistencies in the last field of VoucherTransferred. In an edge case scenario, executedBy can be incorrect - this happens if address1 submits metatransaction to redeem a voucher for offer with twins. If then of the twins executes a boson voucher transfer, onVoucherTransferred will still show address1 as executor and not twin contract address.
This is unlikely scenario with no real threat.
There are two alternative approaches that would allow keeping reentrancy guard on onVoucherTransferred. One is to modify vouchers to not invoke onVoucherTransferred when _to is protocol contract, but that would also require to modify transferFrom to not allow unsafe transfers to protocol. Another way would be to modify reentracy guard for this specific case, so it would allow 1 reenter during sequential commit and only to onVoucherTransferred.
However, both approaches are more complex.

zajck and others added 17 commits January 25, 2023 08:36
Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 8.5.0 to 8.6.0.
- [Release notes](https://github.com/prettier/eslint-config-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md)
- [Commits](prettier/eslint-config-prettier@v8.5.0...v8.6.0)

---
updated-dependencies:
- dependency-name: eslint-config-prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Initalizer Facet documentation

* Apply suggestions from code review

Co-authored-by: Ana Julia Bittencourt  <[email protected]>

* Expand initialization description

* Review fixes

* upgrade configs

* Update docs/tasks.md

Co-authored-by: Ana Julia Bittencourt  <[email protected]>

Co-authored-by: Ana Julia Bittencourt  <[email protected]>
* operator->assistant

* remove console.log

* diagram update

* Revert assistant back to operator for ERC721/ERC1155
@zajck zajck force-pushed the sequential-commit-2 branch from 196bd83 to 3d9fb9f Compare February 20, 2023 15:56
Copy link
Member

@levalleux-ludo levalleux-ludo left a comment

Choose a reason for hiding this comment

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

Lots of questions (informative) + a few remarks.
The most important one is about taking into account the offer collection to retrieve the voucher contract

contracts/interfaces/IWETH9Like.sol Outdated Show resolved Hide resolved
contracts/mock/PriceDiscovery.sol Outdated Show resolved Hide resolved
contracts/protocol/bases/PriceDiscoveryBase.sol Outdated Show resolved Hide resolved
PriceDiscovery calldata _priceDiscovery,
uint256 _initialSellerId
) internal returns (uint256 actualPrice) {
IBosonVoucher bosonVoucher = IBosonVoucher(protocolLookups().cloneAddress[_initialSellerId]);
Copy link
Member

@levalleux-ludo levalleux-ludo Nov 3, 2023

Choose a reason for hiding this comment

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

idem above line 92

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

contracts/protocol/bases/PriceDiscoveryBase.sol Outdated Show resolved Hide resolved
contracts/protocol/facets/SequentialCommitHandlerFacet.sol Outdated Show resolved Hide resolved
contracts/protocol/libs/FundsLib.sol Show resolved Hide resolved
contracts/protocol/libs/FundsLib.sol Show resolved Hide resolved
test/protocol/FundsHandlerTest.js Outdated Show resolved Hide resolved
contracts/protocol/facets/SequentialCommitHandlerFacet.sol Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Nov 10, 2023

Coverage Status

coverage: 98.86% (-0.7%) from 99.559%
when pulling bc18cc3 on sequential-commit-2
into 9cc931b on main.

levalleux-ludo
levalleux-ludo previously approved these changes Nov 20, 2023
* AMM integration tests (WIP)

* Make hardhat task work with submodules which uses foundry

* Update hardhat config

* Fix diamond deploy

* Renaming folders

* Continue AMM POC

* Add price type to offer struct and continue sudoswap poc

* Fix interface ids

* Moving lssvm submodule

* Make boson voucher compatible with price discovery offers

* Continue POC work

* Finalize AMM POC

* Finalize sudoswap POC

* Seaport: Create offer with criteria (WIP)

* Seaport: advance order with criteria

* Move test files

* Fix sudoswap tests

* Fix seaport tests

* Make commitToOffer and commitToPriceDiscoveryOffer a single method

* Price discovery POC: auction

* Implement new voucher transfer and protocol communication design (WIP)

* Removing logs

* Fixing compile

* Finish new voucher transfer and protocol communication design

* SneakAuction (WIP)

* Supports bid commits that requires pre-holding the NFT

* Token id is mandatory on bid commits

* Continue work on PD

* Fix submodules hardhat compilation

* Finish refactor

* Remove SneakyAuction test and add Zora test

* Offer can't be price discovery and be transfer externally at the sime time

* Add new validations to fulfilBidOrder

* Decoupling bid function

* Add natspec comments

* Fix set committed

* Split commitToOffer and commitToPreMintedOffer

* Review changes

* Apply more review changes

* Owner must be priceDiscoveryContract when caller is not voucher owner

* Add some others verifications

* Fix Zora integration test without wrapper

* Fix stack too deep issue by enabling Yul via iR

* Split commitToPriceDiscovery in a new PriceDiscoveryFacet

* Add weth to protocol protocol addresses storage

* Fix interface ids

* Creating SudoswapWrraper

* Update SudoswapWrapper contract to allow wrapping multiple tokens at once and modify integration test accordingly

* Update SudoswapWrapper contract to allow wrapping by sender

* Continue SudoswapWrapper

* Finalise sudoswap wrapper poc

* Adding missing natspec comments

* Upgrade hardhat config and minors changes

* Fix pre-minted voucher transfer to check for offer price type and transaction origin

* update integration tests

* update inegration test - sudoswap

* Extend priceDiscovery struct

* deprecate commitToPremintedOffer

* Fix fundsHandler tests

* Fix metaTransactionsHandler tests

* Fix Offer domain script

* Fix sequentialCommitHandler tests

* review fixes 1st iter

* Correct resellerId in initial exchangeCosts for price discovery

* review fixes 2nd iter

* More minore fixes in tests/contracts

* PriceDiscoveryHandler unit tests

* onPremintedVoucherTransferred test + other minor fixes

* Zora wrapper (#598)

* initial wrapper

* Zora auction PoC

* code cleanup, add comments

* additional auction tests

* Review fixes

* Remove ownable

* review fixes

* wrapper tests

* custom mock auction

* handling wrapper another type of "Side"

* Improve wrapper handling

---------

Co-authored-by: zajck <[email protected]>
Co-authored-by: Klemen <[email protected]>
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Slither found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@zajck zajck merged commit d331983 into main Nov 21, 2023
11 checks passed
@zajck zajck deleted the sequential-commit-2 branch November 30, 2023 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v2.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants