Bakstag Developer Documentation
website·Indexed 30 days ago
https://bakstag-developers.vercel.appBakstag is a Decentralized Omnichain Over-The-Counter (OTC) Protocol for trustless P2P transactions. The documentation covers the offer lifecycle—including creation, acceptance, and cancellation—destination gas abstraction via LayerZero, protocol fee structures, and the shared decimal system for tokens with varying precisions across blockchains.
What's inside Bakstag
- Bakstag is a Decentralized Omnichain Over-The-Counter (OTC) Protocol designed to facilitate trustless peer-to-peer (P2P) transactions. It allows users to trade assets across any network and asset type without relying on a central authority or risking capital loss.
Use Destination Gas Abstraction to avoid holding destination native currency
Bakstag abstracts destination gas costs by including them in the LayerZero fee. Users pay this fee using the source native currency or ZRO tokens, eliminating the requirement to hold the native currency of the destination chain to complete a transaction.Understand the OTC Market Escrow mechanism
The Escrow is a smart contract managed by the OTC Market. It securely locks the source token amount upon offer creation. These tokens remain locked until one of two events occurs: the buyer accepts the offer (releasing tokens to the buyer) or the advertiser cancels the offer.Manage offer lifecycles with Refill and Cancel options
Advertisers can manage their offers using two primary actions:
- Refill: Instead of canceling an offer, advertisers can refill it to maintain liquidity.
- Cancel: Offers can be canceled on the destination chain, with support for canceling in batches.
Cancel a cross-chain offer
Cross-chain cancellation uses an ABA (source $\rightarrow$ destination $\rightarrow$ source) transaction pattern to ensure the offer is deleted on both chains and to prevent race conditions where an offer is accepted while being canceled.
The process involves:
- Cancel Offer Order: A message from the source chain to the destination chain to delete the offer.
- Offer Canceled: A confirmation message from the destination chain back to the source chain to trigger final deletion and asset refund on the source chain.
Manage the Offer lifecycle
The lifecycle of an offer consists of the following stages:
- Create: The advertiser defines parameters and locks the source amount in escrow on the source chain.
- Accept: Buyers interact with the smart contract on the destination chain to purchase the offer in whole or in part.
- Refill: (Optional) Advertisers can add more funds to an existing offer.
- Cancel: Once the offer is fully purchased (or if the advertiser chooses), it can be canceled to free storage and return rent (on Solana), allowing the advertiser to reuse the same parameters for a new offer.
Cancel a monochain offer
In a monochain scenario, the seller who created the offer can cancel it by invoking thecancelOffermethod. This process validates the offer's existence and the signer's authority, refunds the source tokens from escrow to the seller, and deletes the offer from the mapping.function cancelOffer( bytes32 _offerId, MessagingFee calldata _fee, bytes calldata _extraSendOptions ) external payable returns (MessagingReceipt memory msgReceipt);Accept an offer in Bakstag Protocol
To accept an offer, a buyer must initiate the process on the destination chain. The buyer purchases source chain tokens by paying with destination chain tokens. The process involves providing specific parameters, obtaining a quote for fees and token amounts, approving token transfers (if non-native), and executing the acceptance transaction.Manage source funds during offer creation
When callingcreateOffer, the source amount is transferred to an Escrow. These funds remain the property of the user, and the offer can be cancelled at any time to retrieve the funds, ensuring a non-custodial cross-chain asset trade.Create a new offer in the OTC Market
Creating an offer involves a four-step process: defining parameters, obtaining a quote for fees, approving token transfers, and executing the creation transaction. The source tokens are locked in an Escrow contract until the offer is either accepted by a buyer or cancelled by the advertiser. For cross-chain offers, the offer is stored on both the source and destination OTC Markets.Calculate minimum source token amounts based on destination token precision
The minimum amount of source token a buyer can purchase is constrained by the need for the destination token amount to be large enough to cover a 1% protocol fee. This minimum depends on the destination token's native precision and the exchange rate set by the seller.
- High Precision (18 decimals, e.g., ETH, ERC20): Generally allows the minimum source token amount of 1e-06 regardless of the exchange rate.
- Medium Precision (9 decimals, e.g., SOL, TON, JETTON): Imposes restrictions at low exchange rates. For example, at an exchange rate of 1e-06, the minimum source token amount increases to 0.1.
- Low Precision (6 decimals, e.g., TRX, SPL): Imposes the strictest restrictions. For example, at an exchange rate of 1e-06, the minimum source token amount must be 100.
Enable Native Drop for destination chain gas
Users can opt to receive a small native drop on the destination chain. This drop is intended to provide sufficient funds to cover approximately 3-4 transfers of destination tokens.