🔌Self Execute Order

To retrieve a quote from the API that can be independently executed, set the gasless=false when retrieving a quote. In this case, Bebop will not handle the execution of the transaction. As such, gas fees will not be included in the quote.

Different pricing applies to self executed orders.

For a successful trade, ensure that the transaction is included on chain before the expiry in the quote response.

For use cases where validations are not required or are restrictive at quote time, the skip_validation=true flag can be passed. This will disable approvals, gas estimate and balance checks.

Partial Fills

In some scenarios, you may want to fill an order partially rather than fully. This can be done by adjusting the filledTakerAmount parameter in your transaction calldata. The quote response will return a partialFillOffset field which indicates how many 32-byte segments are in the calldata before reaching filledTakerAmount.

JavaScript

tx.data = tx.data.slice(0, 10 + partialFillOffset * 64) // Beginning of calldata up to offset
    + fillAmt.toString(16).padStart(64, "0") // Replace with partial fill amount in hex, padded to 64 chars
    + tx.data.slice(10 + partialFillOffset * 64 + 64); // Remaining calldata after filledTakerAmount

Python

tx["data"] = (
    tx["data"][: 10 + partialFillOffset * 64]
    + f"{fill_amt:x}".rjust(64, "0")
    + tx["data"][10 + partialFillOffset * 64 + 64 :]
)

Example - Sending a transaction

import axios from "axios";
import {ethers} from "ethers"; //ethers-v6

// Trade Info (Insert your values)
const privateKey = ""
const tokensAddressesSell = ["0x4200000000000000000000000000000000000006"] // WETH
const tokensSellAmounts = [ethers.parseEther("0.001")] // 0.001 WETH
const tokensAddressBuy = ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"] // USDC
const chain = {
    chainId: 8453,
    name: "base" // "polygon" | "ethereum" | "arbitrum" | "blast" | "optimism"
}
const provider = new ethers.JsonRpcProvider("https://mainnet.base.org")

// Getting quote and submitting it onchain
async function sendTx() {

    // Init you wallet
    let account = new ethers.Wallet(privateKey)

    // Get quote
    let quote = (await axios.get(`https://api.bebop.xyz/pmm/${chain.name}/v3/quote`, {
        params: {
            buy_tokens: tokensAddressBuy.toString(),
            sell_tokens: tokensAddressesSell.toString(),
            sell_amounts: tokensSellAmounts.toString(),
            taker_address: account.address,
            gasless: false
        }
    })).data
    console.log(quote)
    if (quote.error !== undefined) {
        return
    }

    // Send the transaction
    let txHash = await account.connect(provider).sendTransaction(quote.tx)
    console.log(txHash)
}

sendTx()

Last updated