Skip to main content

Direct Swap Contract

The Direct Swap contract is a Plutarch-based smart contract enabling peer-to-peer trading, in a trustless manner, for the Cardano blockchain. Without the need for a trusted third party or a Decentralized Exchange (DEX), a user can put up for sell any bundle of Cardano native asset(s)(Tokens & NFTs) in exchange for any user-specified bundle of Tokens or NFTs. This highly flexible contract allows for the creation of a generic marketplace to buy & sell any combination of assets. The marketplace allows for Peer-to-Peer interaction and doesn't require Batchers.

tip

Common use cases

  • Peer-to-peer swaps
  • NFT/Token Marketplace
  • Derivatives/bonds Marketplace

Contract API Endpoints

Maestro's API enables developers to integrate seamlessly with this contract using the following 5 endpoints.

NameDescriptionEndpointState Transition
Create OrderCreate a new offer for direct swap/contracts/directSwap/createOfferStart => Open
Cancel OrderCancel an existing offer for direct swap/contracts/directSwap/cancelOfferOpen => Close
Fill OrderFill an existing offer for direct swap//contracts/directSwap/fillOfferOpen => Filled
Get All OffersGet all the existing offers for direct swap/contracts/directSwap/getAllOffersNone
Get User OfferGet all the existing offers for a specific user/contracts/directSwap/getOffers/:addressNone
note

Contract Auditor

Contract has been audited and is open-sourced here

info

Contract Fees

Direct Swap has a flat 2 ADA fee going towards contract author Anastasia Labs

Contract Interactions

Create a Direct Swap offer

A seller sends the assets he wishes to exchange, to the contract, thus locking the funds therein. This UTxO contains a datum which specifies the creator of the offer and the assets wished in return, toBuy indicates the price.

Fill a Direct Swap offer

A buyer interested in the offered assets initiates a transaction (with a PExecuteOffer redeemer) spending the locked UTxO, along with sending the toBuy assets to the creator. This condition is validated by the contract first before allowing the transaction to proceed further.

Cancel a Direct Swap offer

Seller can cancel his offer by initiating a transaction (with a PReclaim redeemer) and claim all the locked assets back.

Multiple offers matching eachother

A single transaction can fulfill multiple sell orders by matching it with valid buy orders. Whether all the buy orders in the tx are correct or not is validated only once at the tx level using the Zero ADA Withdrawal Trick from the Staking validator.