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

Support Auction Swaps #430

Merged
merged 22 commits into from
Dec 26, 2023
Merged

Support Auction Swaps #430

merged 22 commits into from
Dec 26, 2023

Conversation

crisdut
Copy link
Member

@crisdut crisdut commented Dec 7, 2023

Description
This PR intent supports sequential swaps and unifies the previous swap operations (now called "strategies").

Now, BMC have three ways to make swap operations:

  1. P2P: The strategy allows participants (sellers and buyers) to make swaps without a coordinator. The match engine used is FIFO, i.e., the first bid that arrives with the correct target price.
  2. Airdrop: The strategy allows participants (issuers) to make individual or collection airdrops. The airdrop respect the FIFO (First In First Out).
  3. Auction: The strategy allows participants (sellers) to make individual or collection offers. The match engine used is the highest price, i.e., after the offer expires (or finished by seller), the coordinator selects the highest price bid and executes. Then, the coordinator updates the next available offer with the new UTXO (in case of the collections). All offers of the collections are publish and allow to receive bids.
  4. HotSwap: The strategy allows participants (sellers and buyers) to make swaps without a coordinator. The main difference of the P2P is the sign condition. The sign condition is post-sign, i.e., the seller is the last to sign.

Also, It was necessary to carry out some refactorings to increase the maintainability of the swaps in BMC, according to the checklist below:

Sequential Swaps (epic)

  • Choose Swap Strategies
    • Add HotSwap instead of presig=false flag
    • Add P2P instead of presig=true flag
    • Add Auction to allow use coordinator
    • Refactor swap tests
  • Allow offer collections
    • Add internal_create_buyer_bid to allow reuse step
    • Add internal_create_seller_offer to allow reuse step
    • Allow vector of offers have the same bundle_id
    • Add create_auction_bid to allow create bid (sequential swaps)
    • Add create_auction_offers to allow create one or more offers (collections in sequential swaps context)
    • The create_auction_offers needs return all offers published in orderbook
  • Now Public Orders is first citizen
    • Allow change status orders in public orderbook
    • Use public orderbook to create rgb transfers
    • Use public orderbook to update participants orders(aka. my orders)
  • Match Engine based in swap strategies
    • P2P is always FIFO
    • Hotswap is always a seller decision
    • Auctions is always highest bid and timebox.
    • Airdrop is always FIFO
  • Remove potential exploits from Public Orders information
    • [Airdrop] Prevent malicious buyers broadcast transactions before the Auction ends
    • [Auction] Prevent malicious buyers broadcast transactions before the Auction ends
    • [HotSwap] Prevent malicious seller broadcast multiple transactions with same UTXO (always force batch operation)
    • [P2P] Prevent malicious buyer broadcast multiple transactions with same UTXO (block use)
    • [All] Storage tapret commits only DH (Diffie–Hellman) carbonado data
    • Create integration tests
  • Next Offer (aka. Sequential Offer)
    • Allow coordinator check and publish all transaction auctions (after offer finished)
    • Allow seller finish the offers and launch new offers with remaining assets
    • After confirmation of the previous offer transaction, update all subsequent offers with new UTXO
    • Cancel all bids for offer already filled (executed)
    • Prevents reuse of bitcoin utxos (force update dustless verification)
    • Create integration tests
    • Create integration tests (security)
  • Expose endpoints for Bitmask Server
    • Create/Remove Auction Offer
    • Create/Remove Auction Bid
    • Finish Auction Offers
    • Renew Auction Offers
    • Get Offer Collection
    • Get Bids by Offer Collection
  • Update Wasm API
    • Update Structs
    • Update Methods
    • Expose new Methods
    • Create wasm tests for seq. swaps

Closes #413
Closes #365
Closes #422

PS: I added #422 here because we can resolve all offers/bids in one "big" L1 transaction.

@crisdut crisdut added enhancement New feature or request help wanted Extra attention is needed rgb labels Dec 7, 2023
@crisdut crisdut added this to the 0.7.0 milestone Dec 7, 2023
@crisdut crisdut self-assigned this Dec 7, 2023
@crisdut crisdut marked this pull request as ready for review December 11, 2023 12:07
@josediegorobles
Copy link
Member

Hi, could you update the wasm api?

@crisdut
Copy link
Member Author

crisdut commented Dec 11, 2023

Hi, could you update the wasm api?

Yes, I think I finishing it today.

@crisdut
Copy link
Member Author

crisdut commented Dec 11, 2023

Prevents reuse of bitcoin utxos (force update dustless verification)

Suppose we have a seller who wanted to sell 5 items and wants to sell via sequential swap. Throughout operations, the UTXO related to assets may decrease to smaller fractions until it turns to dust. As the seller no longer changes the PSBTs after the start of the auctions (the coordinator manages it), I thought about making a "minimum satoshis for operation" rule for the RGB20 and RGB21 wallets, what do you think?

Copy link
Member

@cryptoquick cryptoquick left a comment

Choose a reason for hiding this comment

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

Really good work on this! I like the clarification on some of the terminology, like server -> marketplace and presig -> strategy. Also, good catch on realizing we're using PSBTv0. As you might know, there's no PSBTv1... Only v0 and v2.

I just have one issue with code organization in carbonado.rs... It's really making that file quite a bit more complex than it should be. If I had to guess, that logic is being put in the wrong place. Do you agree?

@@ -78,6 +83,43 @@ mod server {
Ok((filepath, body))
}

pub async fn auctions_store(
Copy link
Member

Choose a reason for hiding this comment

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

Is there any way to abstract this out so it's not in src/carbonado.rs methods? Ideally this file would be cleaner and simpler, more focused and have less duplication.

Copy link
Member Author

@crisdut crisdut Dec 12, 2023

Choose a reason for hiding this comment

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

I believe so, but I feel like it will lose some of its purpose. I centralized in this file all the calls that are sometimes made by the client and sometimes made by the server.

But yes, I can carry out another separation.

@crisdut
Copy link
Member Author

crisdut commented Dec 12, 2023

Prevents reuse of bitcoin utxos (force update dustless verification)

Suppose we have a seller who wanted to sell 5 items and wants to sell via sequential swap. Throughout operations, the UTXO related to assets may decrease to smaller fractions until it turns to dust. As the seller no longer changes the PSBTs after the start of the auctions (the coordinator manages it), I thought about making a "minimum satoshis for operation" rule for the RGB20 and RGB21 wallets, what do you think?

What do you guys think, @cryptoquick and @josediegorobles ?

@cryptoquick
Copy link
Member

@crisdut We should always have an input from the buyer for paying fees and paying for the dust output.

Also, there's no way to batch transfers with auctions because they're separate PSBTs, correct? That's fine so long as multiple sequences can be spent within the same block.

@crisdut crisdut changed the title Support Sequential Swaps Support Auction Swaps Dec 14, 2023
josediegorobles and others added 3 commits December 14, 2023 01:57
* Update struts in typescript

* Camel Case

* Update structs

* Live metrics (#435)

* Switch to in-memory metrics.

* Metrics fixes.

* Also write metrics to disk as a backup.

* Disable LN swaps tests since these often fail. (#437)

* Update struct rgbofferresponse

* Update lib/web/rgb.ts

Co-authored-by: Armando CD <crisdut@users.noreply.github.com>

---------

Co-authored-by: Hunter Beast <hunter@cryptoquick.com>
Co-authored-by: Armando CD <crisdut@users.noreply.github.com>
Copy link
Member

@josediegorobles josediegorobles left a comment

Choose a reason for hiding this comment

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

LGTM

josediegorobles and others added 5 commits December 20, 2023 23:56
* Fix structs

* Add methods to web.rs and update rgb.ts

* Update web.rs

Co-authored-by: Armando CD <crisdut@users.noreply.github.com>

* Update rgb.ts

Co-authored-by: Armando CD <crisdut@users.noreply.github.com>

* Update rgb.ts

Co-authored-by: Armando CD <crisdut@users.noreply.github.com>

---------

Co-authored-by: Jose Diego Robles Pardo <jdrobpar@Joses-Laptop.local>
Co-authored-by: Armando CD <crisdut@users.noreply.github.com>
@crisdut crisdut merged commit 11edf38 into development Dec 26, 2023
4 of 5 checks passed
@cryptoquick cryptoquick deleted the CD/seq branch February 3, 2024 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed rgb
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sequential Swaps L1 Transaction Batching Sequential Swaps replace Esplora::broadcast with direct request
3 participants